Looking for some technical information about the boot process - Android Q&A, Help & Troubleshooting

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

r.darwish said:
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
Click to expand...
Click to collapse
1.A recovery could have been packaged in the zip (i use zips to install recoveries too).
2.Im not sure about this but it could be that your bootloader got messed up and didn know what to load.
3.I think this is possible since recovery loads itself into ram and works from there allowing the partition to be changed.
4. I don't know about this one
Also the recovery has it's own kernel it doesn't share it with the rom one(ex. if touch doesnt work in a rom due to its kernel it can work in recovery)
Sent from my LG-P350 using xda premium

nerot said:
1.A recovery could have been packaged in the zip (i use zips to install recoveries too).
2.Im not sure about this but it could be that your bootloader got messed up and didn know what to load.
3.I think this is possible since recovery loads itself into ram and works from there allowing the partition to be changed.
4. I don't know about this one
Also the recovery has it's own kernel it doesn't share it with the rom one(ex. if touch doesnt work in a rom due to its kernel it can work in recovery)
Sent from my LG-P350 using xda premium
Click to expand...
Click to collapse
Thank you for the answer
Maybe someone can confirm if Cyanogenmod is shipped with a recovery software?

r.darwish said:
Thank you for the answer
Maybe someone can confirm if Cyanogenmod is shipped with a recovery software?
Click to expand...
Click to collapse
Official builds do not contain the recovery.
Sent from my LG-P350 using xda premium

oneovo establish
I used official builds for both 10 and 7.

Related

[Q] Recovery img flashing (Stock 2.1 rom)

Hi,
Due to HTC's special touches, the recovery image doesnt stay flashed, and on normal boot its flashed over (meaning if i try to go to recovery after a normal boot, i get the red triangle stuff, and have to pull the battery). I was wondering if this would potentially cause troubles if i was trying to flash a custom ROM from recovery? in other notes, i do find sometimes i have to pull the battery 4 or 5 times to get it to normally boot (thats without holding the buttons >.>).
Thanks in advance.
HTC HERO recovery image flashing problems
I am having exactly the same problem!
I did a quite a bit of research on how to root, backup and flash my HERO and every guide I found describes the process using Universal AndRoot + Rom Manager and it seems there should be no problems. I already rooted my phone successfully, installed Rom Manager and flashed either ClockworkMod 2.5.0.1 or RA Recovery 1.7.0.1 which are able to boot but only once. The next time I reboot I get the red triangle warning and it loads into stock recovery (by pressing vol_up + powroff buttons), so the custom recovery lasts only one boot cycle. I was able to backup but I don't want to risk to wipe and flash since there is a chance it might stuck in the bootscreen loop afterwards and I won't be able to do anything.
There is a thing with s-off and SPrecovery which helps to resolve the problem but it doesn't look like there is anything for HERO.
Any help would be appreciated.
ps I tried to manually flash recovery from inside the phone and from windows command line with the same result.
forum.cyanogenmod.com/topic/8182-how-to-root-your-hero
posted some similar comments over there, and the only init script that i can find when in recovery.
Yeah I posted my question there too.
I was able to find some information about the issue (he is talking about Villain ROM but I think it doesn't really matter):
pulser_g2:
Repeat the process again, as I think stock ROMs try and overwrite the recovery each time they boot. When you finish the process, immediately nandroid and flash VR12. That will then flash a new recovery, AmonRA 1.6.2a, and you will be sorted
Click to expand...
Click to collapse
So it looks like we should just go ahead and flash a custom rom which, in theory, will eliminate the problem.
yeah was tempted to just flash, but sending duck my system img for him to dissect anyway.
yeah worked fine, running cm6.1 now
Yeah once you root you have to flash a custom rom before reboot or u loose the root
I learnt it after lots of reboots and re roots.
but now I wanted to know if I could save the original rom which i have as nand backup to make as an update.zip like custom rom for safe keepimg
I flashed CM6.1 -based TastyFroyo 1.2 and I can confirm custom recovery stays flashed now.

[Q]Three-Button Recovery

For those of us using CM7 and other MTD roms, it's common knowledge that three-button recovery is useless to us after that first install from CWM4fixed. Try to use it again and you get the obvious mounting errors since it's hard-wired to boot to that BML recovery partition. Yep, of course you can only use the reboot menu or ADB to boot to the new MTD-based recovery partition that was created during that first CM7 install if you want to do anything.
I had a bootloop between CM7 nightlies tonight that has me questioning that logic, because, just for kicks before the inevitable Odin session, I interrupted the boot loop with three-button and (to my increasing disbelief) from BML recovery successfully reinstalled and booted CM7, rebooted to MTD recovery, and did a full nandroid restore. No Odin required. Unless I'm missing something though, this actually makes perfect sense.
When we use CWM4fixed to install CM7 over a BML rom, the CM7 install runs within that recovery and installs the new MTD recovery to a separate partition. This is why we're left with 2 different recoveries afterwards. But here's the catch: sure, the BML recovery can't interact with our new MTD file system, but the SD card holding our zips is still FAT32 and should thus remain readable by either recovery. Assuming I understand all of this correctly, what does this mean to us?
Simple: say you get a boot loop but there isn't a desktop with Odin or ADB handy. As long as you have a working SD card with an uncorrupted CM7 install zip and can access CWM4fixed via three-button, you should be able to get CM7 back up and running rather painlessly.
So here's my question: Am I correct? I've done it myself on my Fascinate, but that could have been a fluke and I'm mistakenly applying logic here that simply doesn't belong. It just seems to make sense though in retrospect. If this does in fact hold true, we've been avoiding a potentially useful and time-saving fix this whole time. If not, then this whole thing just makes me look stupid.
Jazz848 said:
For those of us using CM7 and other MTD roms, it's common knowledge that three-button recovery is useless to us after that first install from CWM4fixed. Try to use it again and you get the obvious mounting errors since it's hard-wired to boot to that BML recovery partition. Yep, of course you can only use the reboot menu or ADB to boot to the new MTD-based recovery partition that was created during that first CM7 install if you want to do anything.
I had a bootloop between CM7 nightlies tonight that has me questioning that logic, because, just for kicks before the inevitable Odin session, I interrupted the boot loop with three-button and (to my increasing disbelief) from BML recovery successfully reinstalled and booted CM7, rebooted to MTD recovery, and did a full nandroid restore. No Odin required. Unless I'm missing something though, this actually makes perfect sense.
When we use CWM4fixed to install CM7 over a BML rom, the CM7 install runs within that recovery and installs the new MTD recovery to a separate partition. This is why we're left with 2 different recoveries afterwards. But here's the catch: sure, the BML recovery can't interact with our new MTD file system, but the SD card holding our zips is still FAT32 and should thus remain readable by either recovery. Assuming I understand all of this correctly, what does this mean to us?
Simple: say you get a boot loop but there isn't a desktop with Odin or ADB handy. As long as you have a working SD card with an uncorrupted CM7 install zip and can access CWM4fixed via three-button, you should be able to get CM7 back up and running rather painlessly.
So here's my question: Am I correct? I've done it myself on my Fascinate, but that could have been a fluke and I'm mistakenly applying logic here that simply doesn't belong. It just seems to make sense though in retrospect. If this does in fact hold true, we've been avoiding a potentially useful and time-saving fix this whole time. If not, then this whole thing just makes me look stupid.
Click to expand...
Click to collapse
Whatever works for you man, but you know the saying "better to be safe than odining"
Sent from my SCH-I500 using XDA App

ARRGGGG!! How do you do NANDROID backup?

I installed TWRP on my phone, and went into Bootloader an hit RECOVERY so I can get to the program (the first time I did this it brought me to the TMRWP program). THIS time, it completely wiped my friggin' phone... after I sat there like 4 hours re-setting up everything PERFECTLY how I wanted it.
What's weird is it kept ALL my apps that I converted to SYSTEM APPS, but all my user stuff is gone.
Lesson learned... Don't click recovery from Bootloader.
That has yet to happen to me with any recovery and 3 devices currently with twrp. Might be a step missed with the install or maybe you left a bootloader update zip and ran it when you rebooted? Or it can be a bug as going to recovery from bootloader via a cold start is how to get there traditionally. I would email teamwin and try to sort it out or redo the recovery install, making sure to check the md5 of the file after you download it.
Sent from my Transformer TF101 using Tapatalk 2
Your supposed to click recovery at bootloader. Thats where you do backup, restore and flash new roms.
HTC Sensation z710e
ICS 4.0.3
Sense version 4.0
Software Sense-o-maniac v1.3
Kernel. 3.0.30 Bricked
Radio 11.68.3504
That's what I thought too. If I'm not mistaking, I flashed the new firmware after I did the TWRP, so maybe that screwed it up somehow. I take it TWRP must be the LAST image you flash? Only flashes I remember doing were:
Customize bootloader screen
TWRP.
firmware update
Do I need to re-flash the new firmware before re-flashing TWRP, or is the firmware going to remain no matter what I do from this point on?
Just adb flash recovery. Put the recovery image in your platform tools folder. Adb reboot bootloader. when you are rebooted adb flash recovery recovery.img.
Or use one of the many tools made to do that on our forums
Sent from my ADR6425LVW using xda premium
Well I went ahead and used the GOO Manager to flash TWRP again, and this time it worked fine. I'm going to re-setup my phone again then before I customize it back like I had it, going to try to get to recovery and see if it works.
With it now being installed, does that mean I can't flash anything directly from SD Card or modify the bootloader anymore without it causing problems?
What I mean, moreso, is... if I ever put factory reset. will it reload the factory rom + keep the newest firmware I installed (etc.) or do I nee to back up the phone with TWRP and recover from that when I want to load it back?
Factory reset just puts things back to the way they were without the stuff in the data partition or any user apps or settings. This means that say you flash a custom rom, it will reset to as if that custom rom was freshly installed since the custom rom has replaced the factory rom in the /system/ parition and anything else related to it.
With that said it is usually a good practice after rooting a fresh device to do the nandroid and then transfer it to a computer before you do anything else. Note that while you probably won't be switching recoveries a lot, that nandroid backups generally work only with the recovery that generated them so don't get them mixed up.

No OS installed! Are you sure you wish to reboot?

Hi all
How exciting it is to see that so many people are so involved in improving or fixing their mobile devices.
I got some sort of a virus on my Samsung Galaxy S3 so decided to try to wipe it clean and load a more up-to-date version of Android on it. It had 4.3.?. On a Windows 7 PC, I downloaded the Skipsoft Unified Android Toolkit (version 1.4.5). I think now I didn't need to but probably succeeded in rooting my S3 with Kingo ROOT.
Next, using the toolkit and Odin, I think I succeeded in flashing the recovery-twrp-2.7.1.0-i9300.tar custom recovery.
My phone would only boot up with the stock Android.
I took me a while before I learnt about entering the recovery mode by holding the volume up, home and power-on buttons simulateously.
In the recovery mode, I used Wipe, Advanced, ticked all of the boxes and wiped everything on the phone.
Then, using the toolkit and Odin again, I flashed the same recovery-twrp-2.7.1.0-i9300.tar custom recovery I'd flashed before.
I still can't boot my phone. If I choose Reboot from twrp (v2.7.1.0) and then either System or Recovery, I just get, "No OS installed! Are you sure you wish to reboot?"
I can still enter either download or recovery modes but the latter is something of a hit and miss affair.
Using File Manager in the twrp I can see lots of files and directories so guess I managed to flash something.
Also, using Terminal Command I see that my prompt is a "#"so think I'm still rooted.
I know something about Unix and programming mainframe computers but am not an expert with mobile devices. I'd be so grateful if someone could please advise me as to what to do?
Mike
You wiped system partition ;-;
If you want stock rom you need to flash the stock rom by odin.
I recommend you to install a custom rom like Temasek or CM13, it's real easy just flash the zip.
Haha yes^ this guy is right
You might have to flash stock rom if you somehow wiped efs, most of the time custom roms doesn't include efs with them
Turga said:
You wiped system partition ;-;
If you want stock rom you need to flash the stock rom by odin.
I recommend you to install a custom rom like Temasek or CM13, it's real easy just flash the zip.
Click to expand...
Click to collapse
Thanks for your response, Turga and snkmv, below. I didn't know what efs was so looked it up on the net and found this worrying but expert explanation from ryanrazer and Rukbat in androidcentral ( http://forums.androidcentral.com/as...erstanding-cwm-backups-efs-partition-etc.html )
In twrp's recovery mode on my phone and using File Manager, I see that the directory /efs is empty (all files are shown in File Manager, right, including invisible files?)
I'd prefer to try to flash a custom ROM which includes efs rather than the stock ROM. Do Temasek or CM13 include efs or does another, reliable custom ROM?
Thanks again folks
Mike

Samsung S3 error on installing custom rom and now can't run my backup

Hi,
I have a samsung S3 and I want to update it to lollipop or above as my nexus 5 has started randomly rebooting and I need a phone to use whilst I sort a replacement.
I have been following this guide: wccftech.com/install-aosp-android-5-1-1-lollipop-on-galaxy-s3/ as I'm a bit of a noob when it comes to this custom rom business.
I have rooted the device and installed clockworkmod recovery v6.0.1.2. and copied over the rom and the gapps file to my phone.
I then booted into recovery mode and made a backup of the current setup.
I then did the factory reset and the cache wipe(s) and installed the new zip for lollipop and then the gapps.
This is where I received an error "E: Error in /sdcard/0/0/0/Download/gapps-lp-20150314.zip (status 7) installation aborted".
I figured that I should restore to my backup now but when I press it, the app says that files can't be found.
I can see that the files that I backed up do exist but they appear to have been dumped inside a new directory called /0/0/0 (I think this has got three levels because I've tried this a few times).
Now I can't boot into an OS to get any other roms on the phone and I can't edit the files on there (I googled and saw a possible fix for the gapp status 7) and I can't get clockworkmod to recognise an external SD card so I can copy over a new rom or file to try (I have googled and it's suggested the FAT32 is the format for this phone and my size of SD card (16GB)).
Can anyone offer me some advice on how to get out of this situation?
Thanks
Sounds like you're at a place where you should start exploring using your computer instead of a recovery in order to fix your system.
I recommend using the PC software Odin and installing a stock ROM of your device. (Or perhaps using fastboot)
There's plenty of guides on how to use Odin both here on XDA and on the rest of the internet if you just look around a bit
EDIT: This link contains a (possible) fix for your problem.
http://forum.xda-developers.com/showthread.php?t=2522762
Don't use cwm as it is an outdated recovery. Use twrp instead.
Sgt.Mindfudge said:
Sounds like you're at a place where you should start exploring using your computer instead of a recovery in order to fix your system.
I recommend using the PC software Odin and installing a stock ROM of your device. (Or perhaps using fastboot)
There's plenty of guides on how to use Odin both here on XDA and on the rest of the internet if you just look around a bit
EDIT: This link contains a (possible) fix for your problem.
http://forum.xda-developers.com/showthread.php?t=2522762
Click to expand...
Click to collapse
I had a look at the link you suggested and it's one of the suggestions that had come up whilst I was googling for a fix. Unfortunately, I don't have any way to get the updated script onto the phone as the phone isn't picked up by my pc whilst it's in this state, and I can't get the recovery tool to recognise the sd card so I can't put it on there either.
I'll take a look at the stock rom or fastboot option and see if I can get back into the phone. Maybe then I can apply the fix in the suggested post.
Thanks
audit13 said:
Don't use cwm as it is an outdated recovery. Use twrp instead.
Click to expand...
Click to collapse
I'll see if I can install twrp through odin.
Thanks for your help
If the phone works in download mode, try to flash a stock rom too.
Update - fixed
Hi all, just wanted to let you know that I fixed the device with the combined advice from here:
I installed TWRP after holding the volume down + power + home buttons and then pressing volume up when the message appears (I can't remember what this mode is called). I then flashed the device with the TWRP image.
After this I rebooted into the TWRP recovery mode (Volume up + home + power and then release power button when the samsung logo appears).
At this point, the device appeared on my windows machine so I could upload a new image to the internal memory.
I decided to copy on CM13 and GApps.
I then wiped the cache, system, data, and davik cache using TWRP, then I installed CM13 and GApps.
After a reboot the device came back up as a new install.
Hopefully that information may be useful to somebody.
Thanks for all your help

Categories

Resources