the role of recovery
Android uses recovery mode, to restore the factory settings, full-scale package OTA upgrade, incremental package upgrade.
An upgrade typically performs a custom upgrade by running the Meta-inf/com/google/android/update-script script in the upgrade package, which is a set of UI controls that the recovery system can recognize, file system operations commands, such as Write_raw _image (write Flash partition), Copy_dir (copy directory). The package is generally downloaded to the SDcard and cache partitions.
The upgrade also involves the digital signature of the package, the signature method and the normal jar file signature difference is good. The public key is hard-compiled into recovery, which is generated at compile time: out/target/product/xx/obj/packaging/ota_keys_inc_intermediates/keys.inc
First, the overall flow of recovery is described, and the flowchart draws the behavior flow of the system from the start loading bootloader.
Bootloader Normal start, there are three ways, according to BCB (Bootloader Control Block) in the command classification:
other systems and documents related to recovery
The Recovery tool deals with the main system through three files on the NAND cache partition. The main system (including factory reset and OTA upgrade) can write the required commands to the recovery and read the log and intent in the recovery process.
-
/cache/recovery/command:recovery command, written by the main system. All commands are as follows:
-
--send_intent=anystring-write the text out to Recovery.intent
-
--update_package=root:path-verify Install an OTA package file
-
--wipe_data-erase user data (and cache), then reboot
-
--wipe_cache-wipe cache (but not user data) and then reboot
-
/cache/recovery/log:recovery process logs, read out by the main system
-
/cache/recovery/intent:recovery output of Intent
- Misc Partition Content
Bootloader Control Block (BCB) stores recovery Bootloader message. The structure is as follows:
struct Bootloader_message {
Char command[32];
Char recovery[1024];
};
-
command can have the following two values
"Boot-recovery": Mark recovery in progress, or instruct bootloader to enter recovery mode
"Update-hboot/radio": Indicates bootloader update firmware
-
Recovery content
"recovery\n
<recovery command>\n
<recovery command>"
Where recovery command is Cache:/recovery/command
Two recovery case
- factory Reset (Restore factory settings)
-
user selects "factory reset"
-
Setup system writes the "--wipe_data" command to/cache/recovery/command
-
system restarts and enters recover mode (/ Sbin/recovery)
-
get_args () write "Boot-recovery" and "--wipe_data" to BCB
-
erase_root () format (erase) data partition
-
erase_root () format (erase) cache partition
-
finish_recovery () erase BCB
-
restart system
- Ota INSTALL (OTA upgrade)
-
Upgrade system Download OTA package to/cache/some-filename.zip
-
Upgrade system Write Recovery command "--update_package=cache:some-filename.zip"
-
Reboot, and enter recovery mode
-
Get_args () will "Boot-recovery" and "--update_package= ..." Write BCB
-
Install_package () for upgrade
-
Finish_recovery () Erase BCB
-
* * If installation package fails * * prompt_and_wait () Wait for user action, select Alt+s or alt+w upgrade or restore factory settings
-
Main () Call Maybe_install_firmware_update ()
-
If there is a hboot/radio in the package firmware continue, otherwise return
-
Write "Boot-recovery" and "--wipe_cache" to BCB
-
Writes firmware image to the cache partition
-
Write "Update-radio/hboot" and "--wipe_cache" to BCB
-
Rebooting the system
-
bootloader Self Update firmware
-
Bootloader write "Boot-recovery" to BCB
-
Erase_root () Erase cache partition
-
Clear BCB
-
Main () call reboot () reboot system
English documents for the recovery mode process
/init→init.rc→/sbin/recovery→
Main (): RECOVERY.C
-
ui_init (): Ui.c [UI Initialize]
-
gr_init (): MINUI/GRAPHICS.C [Set Tty0 to graphic mode, open fb0]
-
ev_init (): MINUI/EVENTS.C [open/dev/input/event*]
-
res_create_surface:minui/resource.c [create surfaces for all bitmaps used later, Include icons, BMPs]
-
Create 2 Threads:progress/input_thread [create progress Show and input event handler thread]
-
Get_args (): recovery.c
-
Get_bootloader_message (): bootloader.c [Read mtdblock0 (Misc partition) 2nd page for CommandLine]
-
Check if NAND misc partition has a boot message. If Yes, fill argc/argv.
-
If No, get arguments from/cache/recovery/command, and fill argc/argv.
-
Set_bootloader_message (): bootloader.c [set bootloader message back to Mtdblock0]
-
Parser argv[] filled above
-
register_update_commands (): COMMANDS.C [ Register all commands with name and hook function]
-
Install_package ():
-
Translate_root_path (): roots.c ["System:lib" and turns it into a string like "/system/lib", translate the Updater.zip path ]
-
Mzopenziparchive (): zip.c [Open Updater.zip file (uncompass)]
-
Handle_update_package (): INSTALL.C
-
Verify_jar_signature (): verifier.c [Verify signature with Keys.inc key, verify manifest and zip package archive]
-
VerifySignature () [Verify the Signature file:cert.sf/rsa.]
-
Digestentry (): verifier.c [Get SHA-1 Digest of CERT.SF file]
-
Rsa_verify (Public key:keys.inc, Signature:CERT.rsa, cert.sf ' s Digest): LIBC/RSA.C [Verify a 2048 bit RSA PKCS1.5 signature Against an expected SHA-1 hash. Use public key to decrypt the Cert.rsa-get original SHA Digest, then compare to digest of CERT.SF]
-
Verifymanifest () [Get manifest sha1-digest from CERT.SF. Then does digest to MANIFEST. Mf. Compare them]
-
Verifyarchive () [Verify all the files in Update.zip with digest listed in MANIFEST. MF]
-
Find_update_script (): install.c [Find meta-inf/com/google/android/update-script Updater Script]
-
Handle_update_script (): install.c [Read cmds from script file, and do parser, exec]
-
Erase Data/cache Partition
-
prompt_and_wait (): recovery.c [Wait for User input:1) Reboot 2) Update.zip 3) wipe data]
-
ui_key_xxx get alt+x keys
-
1" does nothing
-
2) install_package (' SDCARD:update.zip ')
-
3) Erase_root () →format_root_device () DATA/ CACHE
-
may_install_firmware_update (): firmware.c [Remember_firmware_update () is called by Write_hboot/radio_image command, it stores the bootloader image to CA CHE partition, and write Update-hboot/radio command to MISC partition for bootloader message to let bootloader update Itse LF after reboot]
-
set_ Bootloader_message ()
-
Write_update_for_bootloader (): bootloader.c [write firmware image to CACHE partition with Update_header, Busyimage and F Ailimage]
-
Finish_recovery (): recovery.c [clear the Recovery command and prepare to boot a (hopefully working) system, copy our log f Ile to cache as well (for the system to read), and record any intent we were asked to communicate back to the system. ]
-
Reboot ()
Android Recovery Analysis