How to guarantee Android auto-boot on power-up?

Started by kbro, February 03, 2014, 01:10:27 PM

Previous topic - Next topic

kbro

If I shut down my Android A20-4GB using the UI (press power button for ~2 secs, select "Power off", untick "Quick Boot Mode next time", click "OK") and disconnect the power (12V into the barrel connector), then when I reconnect the power the board often doesn't boot straight away - I have to press the power button for 2 seconds to get it to go.  I get the same problem if I shut down the tablet using "reboot -p" from the command shell.

I don't get consistent behaviour - sometimes the board boots when power is applied, sometimes it doesn't.  I want to use the A20 for an unattended embedded application, so is there a way to guarantee consistently that it does boot on power-up?

Thanks
Kevin

PS I've seen the bit in the A20 user manual about Android entering battery save mode if "Quick Boot" isn't selected.  Is that likely to be the problem, as I don't have a battery connected.

Also, I have tried setting "Quick Boot next time", but when I've done that the A20 often comes up with Airplane mode switched on.

dave-at-axon

#1
This is something I am working on too but I will have the battery and so far there is no consistency either.

As you are on external power only, have you checked to see what SCRIPT.BIN is set for in the [target] settings.

At the end after the clock and voltage settings there is a power_start setting. On my board this was set for 0 so this stopped it powering up on applying DC power.

[target]
boot_clock = 912
dcdc2_vol = 1400
dcdc3_vol = 1250
ldo2_vol = 3000
ldo3_vol = 2800
ldo4_vol = 2800
power_start = 0

You'll need to mount the nanda partition to get access to and change this. You'll also need something to convert the binary file to fex format.

You'll need to get a script to bin and bin to script tool. Sunxi tools have these.

I use a read.bat file with the following to mount the partition and then pull down the file with adb (I assume you have the Android development system on your PC?)


adb shell mkdir /mnt/sdcard/kernel
adb shell mount -t vfat /dev/block/nanda /mnt/sdcard/kernel
adb pull /mnt/sdcard/kernel/script.bin


After I convert and edit and convert back, I use this write.bat file to push it back to the device.


adb push script.bin /mnt/sdcard/kernel
adb shell sync
adb shell umount /mnt/sdcard/kernel


Might be worth a test to see if this works for you.

Post back and let me know if this idea works.

kbro

That's fantastic!  Thanks for the prompt response.  I've had a hack with script.bin files before, so I know about remounting the nanda partition, and I've built fex2bin and bin2fex already.  I'll give it a try and let you know how I get on.

kbro

I tried changing power_start as you suggested but it didn't help - I still have to press the power button after plugging in the DC power supply.

Before I made the change to script.bin I noticed that the A20 does boot immediately on restoration of DC power if I do a forced shutdown by pressing and holding the power button, or by unceremoniously yanking out the power cable while the board is running (yep - I know this can corrupt the filesystem!)

dave-at-axon

It must be in the Android code and if I can get the damn source to compile and run, I will track this down.

I too want to use this in a remote location and need it to auto power up. I am currently experimenting with using either a small microcontroller to control the power button on the board or doing this in software.

I have battery backup and after allowing the battery to deplete down to zero the system auto powers off when the battery gets too low. It won't normally happen in real life as I will monitor for this and in the event of lost power, I will send a message to the server to indicate this, wait for a preset time and if still no power, I will tell the system to power down.

The issue is that on re-applying the power is that it does not switch back on. Well, it does sort of as the 3V3 and 5V rails are present but Android is in a dormant state. I am working on code to see if I can detect this as I have an application that gets started on boot up and if this detects the system is off, it powers it back up using wake locks.

That might be an idea for your application? Are you developing the software for the system?

Have a look at the android.permission.RECEIVE_BOOT_COMPLETED permission. When this fires, you can tell it to run and intent that can check for power off? Not sure yet if this works. It's something I am working on.

kbro

I think that, especially because you have a battery in play (which I want too!) that you'll have to do something with a microcontroller to "press" the power button.  We currently have 2 previous projects based on android tablets, and in each case we've had to do something with a microcontroller that closes a relay for a couple of seconds on detection of the external DC power source in order to "press the button".  I was hoping to avoid it this time :-(

How are you planning to incorporate the microcontroller?  Will you have to remove the POWER button from the A20 board, or are there some handy pins that you can connect to so you avoid taking a soldering iron to it?

dave-at-axon

There is no external connection :( so it will have to be soldered. It's the only soldering needed and just one wire as I already have a motherboard that this sits on top of to handle the analog and digital IO on.

If the test I do next week (away tomorrow for a business trip) works with the BOOTCOMPLETE code, I'll let you know what I did to make it work.

kbro

Am I right in saying the one-wire solder is to connect the relay to the R70 side of PWR_BUT - and connect the other side of the relay to GND elsewhere on your addon board?

kbro

@dave-at-axon have you seen this ... https://www.olimex.com/forum/index.php?topic=1091.msg6448

which mentions this ... https://www.olimex.com/forum/index.php?topic=868.msg5585#msg5585

The latter post is talking about 4.1.1 on A13, and says
Quote
In fex file when power_start is 0 to start android you have to hold power button. Also when you try to reboot the system it instead shuts down. And when battery is plugged  adapter power doesn't start android.

But when power_start option is 1 reboot works ok and also it doesn't matter if there is battery, adapter power always start android.
So power_start = 1 reportedly works on 4.1.1, and I've seen reports saying it works on 4.0.3 too.  Maybe you have to have it set before doing the shutdown in order for it to take effect on powerup.

Are you using an A20 with NAND or SD card?  I have a sneaking suspicion that script.bin works differently on NAND devices, though I haven't found anyone to confirm that suspicion one way of the other. If you are using NAND, why not try setting up an SD card instead?  I'll have a go later.

dave-at-axon

Thanks for the information.

I have tried this and with 4.2 is still won't boot up using NAND.

I'll try the SD idea later today and see if that works.

kbro

I did some testing last night with my A20 with NAND...

I disconnect the battery, pressed the PWR_BUT for a couple is seconds, selected Shutdown from the popup menu and set Quick Boot Mode before OKaying the shutdown, then removed DC power when shutdown had completed. When I reapplied DC power the A20 consistently booted fully straight away as far as the lock screen. However, more often than not Airplane Mode was enabled, and on a couple of occasions so was Silent Mode.

With Quick Boot Mode disabled on powerdown, and no battery connected, the same powerdown/restart sequence always left the A20 needing the power button to be pressed to complete boot.

With the battery connected and Quick Boot Mode enabled, the same shutdown/restart sequence consistently left the A20 booting as far as "charging" - a short press of the power button brought up the green battery icon and a long press caused boot up to complete.

The setting of power_start in script.bin had no effect on any of this behaviour.

dave-at-axon

I've been looking at the script.bin issue. I am convinced that the system only ever reads this on the first boot after you re-flash the device and then creates another file to use to boot the system with. This would certainly fit the case of no changes to the script.bin file making any difference to the system.

I am going through the source now to find out where script.bin is processed.

kbro

That sounds like a way forward if it's true - though it sounds like a bit of a chore - we'd have to chop a modified script.bin into the IMG file prior to flashing.  Or do it properly and build our own IMG file from the SDK.  Less painful than soldering a relay to a few hundred boards though!

kbro

Have you discovered http://linux-sunxi.org/A31_EVB - it's a well-documented script.fex for the A31 - interestingly it puts power_start in the [pmu_para] section rather than [target].

I tried that last night and it made no difference :-)

dave-at-axon

Quote from: kbro on February 10, 2014, 01:24:45 PM
Less painful than soldering a relay to a few hundred boards though!

You don't need a relay. A simple NPN transistor and 1 resistor on the base will do the job. Much cheaper than a relay. I'll put a second resistor on the base though to ensure that the transistor is off as the processor powers up.


Doing a little testing tonight and I see on the serial output the following when I plug in power whilst on battery. I had done a shutdown but no quick boot. In fact it's the same for quick boot.


power_start=0x00000000
power trigger
power start detect
power enter detect
.
.
.
enter standby


That first entry is curious. This indicates that the entry in the script.bin is not being read as we have set to 1.

The code that reads this is in lichee/linux-3.4/drivers/power/axp_power/axp-mfd.c at line 345

This would confirm our suspicions that the change to the script.bin is not being accepted. :(