[General Questions and Answers] TuxDude:
I bought an Android head unit (from a Chinese seller) for my car which I've been trying to port TWRP recovery to. I got no source code whatsoever with the board, so all the reverse engineering that I've done so far is just my own black box (rather grey I guess) experimenting.

The board luckily runs an engineering build of AOSP 4.4.2, so I've locally set up trees to build AOSP as well as OmniROM and have been building binaries from the tree and side-loading using adb to test things out.

Also I have a full firmware flash setup on my SD card, so if I break anything, I can easily go back to where I was before by just booting with the SD card, and this has been a God-send. :)

Before trying the full TWRP, I wanted to try to play with the stock recovery first to ensure I can reboot between the main image and recovery easily, which is where I seem to have stumbled upon an issue.

Now to the actual issue I'm facing:

If I issue an 'adb reboot recovery' command, libcutils.so seems to write "boot-recovery" string into the /misc partition which seems to trick the bootloader to boot into recovery. The stock recovery that came with the board just reboots immediately after few seconds and goes back into booting Android again.

I hacked the recovery rootfs not to start the recovery service, which seems to stop the reboot, but now my board is stuck in a recovery-boot-loop. In other words, if I issue a reboot command from the adb within recovery, the board reboots but again into recovery.

I've also tried using dd to wipe out the "misc" partition and reboot, but somehow the boot loader boots the board back into the same recovery, and I see the "boot-recovery" string in the /misc partition again. How did this string get back here ?

I've tried to understand the Allwinner boot process and this seems to be the sequence:

BROM -> boot0 -> boot1 -> boot.axf -> uboot -> Android Kernel

I've looked at the contents of my nanda partition which has the bootloader on a vfat partition, and I found only few files in there, which I'm not sure but did not look like they stored any information on which partition to boot.

I also looked at the env partition (nandb), this seems to be just a list of environment variables for u-boot. Although it contains the commands for booting the main image and the recovery, I did not find any setting which controlled which boot command is to be executed at any given point.

So, any one have any clue whatsoever on how boot.axf decides whether to boot the main image or recovery ?

Thanks!

UPDATE:

Here is the partition table info:

~ # ls -l /dev/block/by-name/

lrwxrwxrwx root root 2000-01-01 00:00 UDISK -> /dev/block/nandi

lrwxrwxrwx root root 2000-01-01 00:00 boot -> /dev/block/nandc

lrwxrwxrwx root root 2000-01-01 00:00 bootloader -> /dev/block/nanda

lrwxrwxrwx root root 2000-01-01 00:00 cache -> /dev/block/nandg

lrwxrwxrwx root root 2000-01-01 00:00 env -> /dev/block/nandb

lrwxrwxrwx root root 2000-01-01 00:00 misc -> /dev/block/nande

lrwxrwxrwx root root 2000-01-01 00:00 persist -> /dev/block/nandh

lrwxrwxrwx root root 2000-01-01 00:00 recovery -> /dev/block/nandf

lrwxrwxrwx root root 2000-01-01 00:00 system -> /dev/block/nandd