西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁硬件相關(guān)手機(jī)技術(shù) → Android recovery 模式 中英文對照

Android recovery 模式 中英文對照

相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時(shí)間:2011/2/3 13:10:58字體大。A-A+

作者:佚名點(diǎn)擊:6723次評論:0次標(biāo)簽: Android

  • 類型:源碼相關(guān)大。23.6M語言:中文 評分:9.1
  • 標(biāo)簽:
立即下載

Recovery簡介
Android利用Recovery模式,進(jìn)行恢復(fù)出廠設(shè)置,OTA升級,patch升級及firmware升級。
升級一般通過運(yùn)行升級包中的META-INF/com/google/android/update-script腳本來執(zhí)行自定義升級,腳本中是一組recovery系統(tǒng)能識(shí)別的UI控制,文件系統(tǒng)操作命令,例如write_raw_image(寫FLASH分區(qū)),copy_dir(復(fù)制目錄)。該包一般被下載至SDCARD和CACHE分區(qū)下。如果對該包內(nèi)容感興趣,可以從http://forum.xda-developers.com/showthread.php?t=442480下載JF升級包來看看。
升級中還涉及到包的數(shù)字簽名,簽名方式和普通JAR文件簽名差不錯(cuò)。公鑰會(huì)被硬編譯入recovery,編譯時(shí)生成在:out/target/product/XX/obj/PACKAGING/ota_keys_inc_intermediates/keys.inc
G1中的三種啟動(dòng)模式
        MAGIC KEY:


  • camera +
            power:bootloader模式,ADP里則可以使用fastboot模式
           

  • home + power:recovery模式
           

  • 正常啟動(dòng)


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


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

  • command ==
            'update-radio/hboot' → 更新firmware(bootloader)
           

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


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

  • CACHE分區(qū)文件


 

    Recovery
            工具通過NAND
            cache分區(qū)上的三個(gè)文件和主系統(tǒng)打交道。主系統(tǒng)(包括恢復(fù)出廠設(shè)置和OTA升級)可以寫入recovery所需的命令,讀出recovery過程中的LOG和intent。
    • /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/log:recovery過程日志,由主系統(tǒng)讀出
                     
    • /cache/recovery/intent:recovery輸出的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
                     
      \n
                     

                     
      其中recovery
                      command為CACHE:/recovery/command命令
             


兩種Recovery
Case

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


 

  • 用戶選擇“恢復(fù)出廠設(shè)置”
           
  • 設(shè)置系統(tǒng)將"--wipe_data"命令寫入/cache/recovery/command
           
  • 系統(tǒng)重啟,并進(jìn)入recover模式(/sbin/recovery)
           
  • get_args()
            將
            "boot-recovery"和"--wipe_data"寫入BCB
           
  • erase_root()
            格式化(擦除)DATA分區(qū)
           
  • erase_root()
            格式化(擦除)CACHE分區(qū)
           
  • finish_recovery()
            擦除BCB
           
  • 重啟系統(tǒng)

    • OTA
              INSTALL(OTA升級)

  • 升級系統(tǒng)下載
            OTA包到/cache/some-filename.zip
           
  • 升級系統(tǒng)寫入recovery命令"--update_package=CACHE:some-filename.zip"
           
  • 重啟,并進(jìn)入recovery模式
           
  • get_args()
            將"boot-recovery"
            和
            "--update_package=..."
            寫入BCB
           
  • install_package()
            作升級
           
  • finish_recovery()
            擦除 BCB
           
  • **
            如果安裝包失敗 **
            prompt_and_wait() 等待用戶操作,選擇ALT+S或ALT+W
            升級或恢復(fù)出廠設(shè)置
           
  • main()
            調(diào)用
            maybe_install_firmware_update()
           
  • 如果包里有hboot/radio的firmware則繼續(xù),否則返回
                   

  •                 "boot-recovery"
                    和 "--wipe_cache"
                    寫入BCB
                   

  •                 firmware image寫入cache分區(qū)
                   

  •                 "update-radio/hboot"
                    和 "--wipe_cache"
                    寫入BCB
                   
  • 重啟系統(tǒng)
                   
  • bootloader自身更新firmware
                   
  • bootloader
                    將 "boot-recovery"
                    寫入BCB
                   
  • erase_root()
                    擦除CACHE分區(qū)
                   
  • 清除
                    BCB
           
           
  • 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后的行為流程。

    Click here to open new window
CTRL+Mouse wheel to zoom in/out

                   
  •  

     WIPE 清除手機(jī)的信息 就是格式化 然后你在刷你喜歡的ROM。

    5、Wipe——清除
    5-1、Wipe data/factory reset——清除內(nèi)存數(shù)據(jù)和緩存數(shù)據(jù)
    5-2、Wipe Dalvik-cache——清除緩存數(shù)據(jù) + ext 分區(qū)內(nèi)數(shù)據(jù)
    5-3、Wipe SD:ext partition——只清除ext 分區(qū)內(nèi)數(shù)據(jù)
    5-4、Wipe battery stats——清除電池?cái)?shù)據(jù)
    5-5、Wipe rotate settings——清除傳感器內(nèi)設(shè)置的數(shù)據(jù)

    分區(qū)
    6、Partition sdcard——分區(qū)sd 卡
    6-1、Partition SD——自動(dòng)為sd 卡分區(qū)
    6-2、Repair SD:ext——修復(fù)ext 分區(qū)
    6-3、SD:ext2 to ext3——將ext2 分區(qū)轉(zhuǎn)換為ext3 分區(qū)(推薦)
    6-4、SD:ext3 to ext4——將ext3 分區(qū)轉(zhuǎn)換為ext4 分區(qū)(C4 卡不推薦,C6 卡推薦)

    想多了解 請看下面:

    1、Reboot system now——重啟

    2、USB-MS toggle——在recovery 模式下直接連接USB,讀取你的sd卡,這個(gè)非常方便。刷不成的話你還可以往sd卡拷貝別的ROM 進(jìn)行補(bǔ)救,按小房子退出該模式。非常棒的功能,最近才發(fā)現(xiàn)的。2010.05.27.

    3、Backup/Restore——備份和還原
    3-1、Nand backup——Nand 備份
    3-2、Nand + ext backup——Nand 備份(系統(tǒng)和ext 分區(qū)一同備份)
    3-3、Nand restore——還原(就是還原3-1、3-2 的最后一次備份)
    3-4、BART backup——BART 備份 (包括系統(tǒng)和ext 分區(qū))
    3-5、BART restore——還原最后一次的BART備份

    Nand 備份類似于系統(tǒng)的備份 而BART 則像是PC 上ghost 的備份。
    Nand 備份 它不會(huì)備份ext 分區(qū)(就是第二分區(qū) 沒有分區(qū)的可以不管這個(gè))
    所以你的如果app2sd 了 那么裝在第二分區(qū)的程序用Nand 恢復(fù)是辦不到的
    BAR T則可以備份到ext 分區(qū) 用BART 恢復(fù)則可以恢復(fù)整個(gè)系統(tǒng) 可以使它和你備份前一模一樣,不會(huì)有一點(diǎn)文件信息的丟失(包括聯(lián)系人、短信、圖片、影音等,所以如果你裝的東西比較多,那么備份和恢復(fù)會(huì)比較慢)

    4、Flash zip from sdcard——從sd卡根目錄的.zip ROM 刷機(jī)包刷機(jī)

    5、Wipe——清除
    5-1、Wipe data/factory reset——清除內(nèi)存數(shù)據(jù)和緩存數(shù)據(jù)
    5-2、Wipe Dalvik-cache——清除緩存數(shù)據(jù) + ext 分區(qū)內(nèi)數(shù)據(jù)
    5-3、Wipe SD:ext partition——只清除ext 分區(qū)內(nèi)數(shù)據(jù)
    5-4、Wipe battery stats——清除電池?cái)?shù)據(jù)
    5-5、Wipe rotate settings——清除傳感器內(nèi)設(shè)置的數(shù)據(jù)

    6、Partition sdcard——分區(qū)sd 卡
    6-1、Partition SD——自動(dòng)為sd 卡分區(qū)
    6-2、Repair SD:ext——修復(fù)ext 分區(qū)
    6-3、SD:ext2 to ext3——將ext2 分區(qū)轉(zhuǎn)換為ext3 分區(qū)(推薦)
    6-4、SD:ext3 to ext4——將ext3 分區(qū)轉(zhuǎn)換為ext4 分區(qū)(C4 卡不推薦,C6 卡推薦)

    7、Other——其它
    7-1、Fix apk uid mismatches——修復(fù)apk 程序
    7-2、Move apps+dalv to SD——移動(dòng)程序和虛擬緩存到sd 卡(這個(gè)可不是 app2sd)
    7-3、Move recovery.log to SD——移動(dòng)刷機(jī)日志文件到sd 卡(執(zhí)行此操作后,sd 卡根目錄會(huì)出現(xiàn)一個(gè)“recovery.log” 文件 即為刷機(jī)日志文件)

    8、Power off——關(guān)機(jī)

      相關(guān)評論

      閱讀本文后您有什么感想? 已有人給出評價(jià)!

      • 8 喜歡喜歡
      • 3 頂
      • 1 難過難過
      • 5 囧
      • 3 圍觀圍觀
      • 2 無聊無聊

      熱門評論

      最新評論

      第 1 樓 廣東深圳電信 網(wǎng)友 客人 發(fā)表于: 2011/3/16 14:43:03
      很實(shí)用,謝謝

      支持( 0 ) 蓋樓(回復(fù))

      發(fā)表評論 查看所有評論(0)

      昵稱:
      表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
      字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)