首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

[转]Android Recovery方式

2012-09-09 
[转]Android Recovery模式http://blogold.chinaunix.net/u/14459/showart_1911144.html?(muddogxp?原创,转

[转]Android Recovery模式

http://blogold.chinaunix.net/u/14459/showart_1911144.html

?

(muddogxp?原创,转载请注明)

Recovery简介

Android利用Recovery模式,进行恢复出厂设置,OTA升级,patch升级及firmware升级。

升级一般通过运行升级包中的META-INF/com/google/android/update-script脚本来执行自定义升级,脚本中是一组recovery系统能识别的UI控制,文件系统操作命令,例如write_raw_image(写FLASH分区),copy_dir(复制目录)。该包一般被下载至SDCARD和CACHE分区下。如果对该包内容感兴趣,可以从http://forum.xda-developers.com/showthread.php?t=442480下载JF升级包来看看。

升级中还涉及到包的数字签名,签名方式和普通JAR文件签名差不错。公钥会被硬编译入recovery,编译时生成在:out/target/product/XX/obj/PACKAGING/ota_keys_inc_intermediates/keys.inc

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 to get original SHA digest, then compare to digest of CERT.sf ]

verifyManifest() [ Get manifest SHA1-Digest from CERT.sf. Then do 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 ]

parseAmendScript():amend.c [ call yyparse() to parse to command ]

exeCommandList():install.c

exeCommand():execute.c [ call command hook function ]

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) do 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 CACHE partition, and write update-hboot/radio command to MISC partition for bootloader message to let bootloader update itself after reboot ]

set_bootloader_message()

write_update_for_bootloader():bootloader.c [ write firmware image into CACHE partition with update_header, busyimage and failimage ]

finish_recovery():recovery.c [ clear the recovery command and prepare to boot a (hopefully working) system, copy our log file to cache as well (for the system to read), and record any intent we were asked to communicate back to the system. ]

reboot()


adb shell "echo "--update_package=SDCARD:update.zip" >> /cache/recovery/command"

adb shell sync

adb reboot recovery

?

热点排行