一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

Android recovery 系統(tǒng)

 waston 2010-08-05

Android Recovery模式

(muddogxp 原創(chuàng),轉(zhuǎn)載請注明)


Recovery簡介

Android利用Recovery模式,進(jìn)行恢復(fù)出廠設(shè)置,OTA升級(jí),patch升級(jí)及firmware升級(jí)。

升級(jí)一般通過運(yùn)行升級(jí)包中的META-INF/com/google/android/update-script腳本來執(zhí)行自定義升級(jí),腳本中是一組recovery系統(tǒng)能識(shí)別的UI控制,文件系統(tǒng)操作命令,例如write_raw_image(寫FLASH分區(qū)),copy_dir(復(fù)制目錄)。該包一般被下載至SDCARDCACHE分區(qū)下。如果對該包內(nèi)容感興趣,可以從http://forum./showthread.php?t=442480下載JF升級(jí)包來看看。

升級(jí)中還涉及到包的數(shù)字簽名,簽名方式和普通JAR文件簽名差不錯(cuò)。公鑰會(huì)被硬編譯入recovery,編譯時(shí)生成在:out/target/product/XX/obj/PACKAGING/ota_keys_inc_intermediates/keys.inc

G1中的三種啟動(dòng)模式

MAGIC KEY:

  • camera + powerbootloader模式,ADP里則可以使用fastboot模式

  • home + powerrecovery模式

  • 正常啟動(dòng)

Bootloader正常啟動(dòng),又有三種方式,按照BCBBootloader Control Block, 下節(jié)介紹)中的command分類:

  • command == 'boot-recovery' → 啟動(dòng)recovery.img。recovery模式

  • command == 'update-radio/hboot' → 更新firmwarebootloader)

  • 其他 → 啟動(dòng)boot.img

Recovery涉及到的其他系統(tǒng)及文件

  • CACHE分區(qū)文件

    Recovery 工具通過NAND cache分區(qū)上的三個(gè)文件和主系統(tǒng)打交道。主系統(tǒng)(包括恢復(fù)出廠設(shè)置和OTA升級(jí))可以寫入recovery所需的命令,讀出recovery過程中的LOGintent

    • /cache/recovery/command: recovery命令,由主系統(tǒng)寫入。所有命令如下:

      • --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), then reboot

    • /cache/recovery/logrecovery過程日志,由主系統(tǒng)讀出

    • /cache/recovery/intentrecovery輸出的intent

  • MISC分區(qū)內(nèi)容

    Bootloader Control Block (BCB) 存放recovery bootloader message。結(jié)構(gòu)如下:

    struct bootloader_message {

      char command[32];

      char status[32]; // 未知用途

      char recovery[1024];

    };

    • command可以有以下兩個(gè)值

      boot-recovery”:標(biāo)示recovery正在進(jìn)行,或指示bootloader應(yīng)該進(jìn)入recovery mode

      update-hboot/radio”:指示bootloader更新firmware

    • recovery內(nèi)容

      recovery\n

      <recovery command>\n

      <recovery command>

      其中recovery commandCACHE:/recovery/command命令


兩種Recovery Case

  • FACTORY RESET(恢復(fù)出廠設(shè)置)

  1. 用戶選擇“恢復(fù)出廠設(shè)置”

  2. 設(shè)置系統(tǒng)將"--wipe_data"命令寫入/cache/recovery/command

  3. 系統(tǒng)重啟,并進(jìn)入recover模式(/sbin/recovery

  4. get_args() 將 "boot-recovery""--wipe_data"寫入BCB

  5. erase_root() 格式化(擦除)DATA分區(qū)

  6. erase_root() 格式化(擦除)CACHE分區(qū)

  7. finish_recovery() 擦除BCB

  8. 重啟系統(tǒng)

  • OTA INSTALLOTA升級(jí))

  1. 升級(jí)系統(tǒng)下載 OTA包到/cache/some-filename.zip

  2. 升級(jí)系統(tǒng)寫入recovery命令"--update_package=CACHE:some-filename.zip"

  3. 重啟,并進(jìn)入recovery模式

  4. get_args() "boot-recovery" 和 "--update_package=..." 寫入BCB

  5. install_package() 作升級(jí)

  6. finish_recovery() 擦除 BCB

  7. ** 如果安裝包失敗 ** prompt_and_wait() 等待用戶操作,選擇ALT+SALT+W 升級(jí)或恢復(fù)出廠設(shè)置

  8. main() 調(diào)用 maybe_install_firmware_update()

    1. 如果包里有hboot/radiofirmware則繼續(xù),否則返回

    2. 將 "boot-recovery" 和 "--wipe_cache" 寫入BCB

    3. 將 firmware image寫入cache分區(qū)

    4. 將 "update-radio/hboot" 和 "--wipe_cache" 寫入BCB

    5. 重啟系統(tǒng)

    6. bootloader自身更新firmware

    7. bootloader 將 "boot-recovery" 寫入BCB

    8. erase_root() 擦除CACHE分區(qū)

    9. 清除 BCB

  9. main() 調(diào)用 reboot() 重啟系統(tǒng)


Recovery模式流程


/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 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 ]

    • registerCommand():commands.c

      • Register command with name, hook, type, cookie.

      • Commands, e.g: assert, delete, copy_dir, symlink, write_raw_image.

    • registerFunction():commands.c

      • Register function with name, hook, cookie.

      • Function, e.g: get_mark, matches, getprop, file_contains

  • 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 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()


Recovery模式流程圖

以下流程圖繪制了系統(tǒng)從啟動(dòng)加載bootloader后的行為流程。





 原文地址 http://blog./u/14459/showart_1911144.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請遵守用戶 評(píng)論公約

    類似文章 更多

    久热香蕉精品视频在线播放| 国产精品美女午夜视频| 久久热中文字幕在线视频| 久久精品a毛片看国产成人| 日韩日韩日韩日韩在线| 色偷偷亚洲女人天堂观看| 在线视频三区日本精品| 东京热加勒比一区二区三区| 午夜精品麻豆视频91| 国产精品成人一区二区三区夜夜夜| 久久大香蕉精品在线观看| 好吊一区二区三区在线看| 久久这里只精品免费福利| 久久国产人妻一区二区免费| 久久机热频这里只精品| 亚洲中文字幕人妻系列| 国产精品推荐在线一区| 中国美女偷拍福利视频| 色婷婷在线视频免费播放| 九九热在线视频观看最新| 人妻熟女欲求不满一区二区| 亚洲精品福利视频在线观看| 精品国模一区二区三区欧美| 国产一区二区三区午夜精品| 在线观看那种视频你懂的| 99久久精品午夜一区二区| 亚洲成人久久精品国产| 国产老熟女超碰一区二区三区| 果冻传媒精选麻豆白晶晶| 99视频精品免费视频播放| 一本久道久久综合中文字幕| 日本av在线不卡一区| 国产毛片av一区二区三区小说| 国产精品视频一区二区秋霞| 欧美精品一区二区三区白虎| 日韩三级黄色大片免费观看| 亚洲精品欧美精品日韩精品| 久久福利视频视频一区二区| 日韩一级一片内射视频4k| 亚洲黄片在线免费小视频| 国产精品福利一二三区|