• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Looking for some technical information about the boot process

reish

Lurker
Sep 30, 2012
1
0
I just tried to flash a ROM and it ended up strangly. As a disclaimer: this is not a "MY PHONE IS BROKEN PLZ HELP ME!" post. I managed to get around this somehow, but I want to realize what technically happened in order to deepen my knowlage about the Android boot process. I come from a background of a Linux PC developer, but I didn't develop anything for Android yet.

So this is the boot process as I understand it, please correct me where I'm wrong:

When you turn on the device, the first thing that happens is that the CPU executes the Radio. The Radio allows the software to preform basic communication with the hardware, and is similar to the PC's BIOS. The Radio can be replaced, but if replaced with a problematic Radio, there's nothing you can do with home equipment to restore it (meaning a full brick).

Once loaded, the Radio executes the boot loader from the flash memory. The boot loader is like GRUB on a PC Linux system. It is the one that traps magic keys like "Volume up + Home" and decides, whether to boot the ROM, the recovery console or just "boot itself".

Both the ROM and the recovery software reside in differents partitions, and the bootloader chooses which partition to boot from.

In normal boot, the bootloader chooses to load the Linux kernel from the system partition and pass the execution to it. The Linux kernel loads Java, which loads the launcher, etc etc...
As I understand, a normal boot process doesn't involve the recovery software at all, and each ROM comes with its own custom-compiled Linux kernel.

The recovery software is like another operating system, which allows you replace the operating system in the system partition (AKA the ROM). Is the recovery software based on the Linux kernel too, or is it an independed software written in C/Assembly? If it is based on the Linux kernel, does it share a kernel with the ROM, or does it have its own version of the Linux kernel?

Now, this is what happened when I tried to flash Cyanogenmod 10 into a Galaxy S device running Cyanogenmod 7. I booted into recovery, backed up and wiped. To my understanding, backup means creating images of the system and data partition, storing these image files in the SD card and sign them with MD5.
When I tried to install the ROM, it warned me that my current partition layout won't fit to the new ROM, and I need to install again to confirm.
Now, when installing an OS in a PC, you can alter the partitions because the OS installation runs from a CD or a DOK, but if the recovery software runs from the disk too, how can it alter the partition table?

Anyways, once I confirmed, the phoned crashed and entered a boot loop. As I understood, flashing a ROM doesn't do anything to the recovery partition, so in any case I can always boot back to recovery and restore the backup. I was probably wrong, because when I tried to boot into recovery I found out that I have a different recovery software (The previous one had the Clockwork icon and a black background, and the new one had gray background and the Android Logo. I tried to restore the backup using the new recovery software but it failed, complaining that it can't format the system partition and that there's a problem with "MTD" (What's that?). I tried to reformat the system partition from the recovery software, but doing so caused it just to return to the main recovery screen without preforming anything or complaining about errors. Same thing when I tried to preform factory reset.

After some failed attemps, what I tried is to flash the old CM7 ROM, not from a backup, but from a clean zip. The recovery console claimed that it succeeded, but it did it too fast to be true, and there were almost no prompts beside the one that says that it succeeded.

I tried to restart, and got into a boot-loop again. This time, however, in each boot I could see my prevoius Clockwork recovery software for a second before the phone restarted again. I booted again into recovery mode to find my previous old recovery software. I tried to restore the backup and it succeeded. Now, I don't really understand what happened:

1. How come flashing ROMs changed the recovery software? I though that I zip containing a ROM contains only a ROM (A Linux kernel, Java JVM etc etc...), not a recovery software.
2. After I tried to flash CM7 back I could see the recovery screen in the boot-loop. Why did I see that screen if I didn't choose explicitly to boot into recovery?
3. How can the recovery software change the partition layout of the memory that it resides on by itself?
4. How come that the previous recovery software managed to restore that backup? As I understood, I ruined the partition layout, so what magic did the old recovery software that the new one couldn't do?

Thanks for the help :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones