Android系統Recovery工作原理之使用update.zip升級過程分析(九)—updater-script指令碼文法簡介以及執行流程

來源:互聯網
上載者:User

               Android系統Recovery工作原理之使用update.zip升級過程分析(九)---updater-script指令碼文法簡介以及執行流程



          目前update-script指令碼格式是edify,其與amend有何區別,暫不討論,我們只分析其中主要的文法,以及指令碼的流程式控制制。

一、update-script指令碼文法簡介:

        我們順著所產生的指令碼來看其中主要涉及的文法。

        1.assert(condition):如果condition參數的計算結果為False,則停止指令碼執行,否則繼續執行指令碼。

        2.show_progress(frac,sec):frac表示進度完成的數值,sec表示整個過程的總秒數。主要用與顯示UI上的進度條。

        3.format(fs_type,partition_type,location):fs_type,檔案系統類型,取值一般為“yaffs2”或“ext4”。Partition_type,分區類型,一般取值為“MTD”或則“EMMC”。主要用于格式化為指定的檔案系統。案例如下:format(”yaffs2”,”MTD”,”system”)。

        4.mount(fs_type,partition_type,location,mount_point):前兩個參數同上,location要掛載的裝置,mount_point掛載點。作用:掛載一個檔案系統到指定的掛載點。

        5.package_extract_dir(src_path,destination_path):src_path,要提取的目錄,destination_path目標目錄。作用:從升級包內,提取目錄到指定的位置。樣本:package_extract_dir(“system”,”/system”)。

        6.symlink(target,src1,src2,……,srcN):target,字串類型,是符號串連的目標。SrcX代表要建立的符號串連的目標點。樣本:symlink(“toolbox”,”/system/bin/ps”),建立指向toolbox符號串連/system/bin/ps,值得注意的是,在建立新的符號串連之前,要斷開已經存在的符號串連。

        7.set_perm(uid,gid,mode,file1,file2,……,fileN):作用是設定單個檔案或則一系列檔案的許可權,最少要指定一個檔案。

        8.set_perm_recursive(uid,gid,mode,dir1,dir2,……,dirN):作用同上,但是這裡同時改變的是一個或多個目錄及其檔案的許可權。

        9.package_extract_file(srcfile_path,desfile_paht):srcfile_path,要提取的檔案,desfile_path,提取檔案的目標位置。樣本:package_extract_file(“boot.img”,”/tmp/boot.img”)將升級包中的boot.img檔案拷貝到記憶體檔案系統的/tmp下。

      10.write_raw_image(src-image,partition):src-image源鏡像檔案,partition,目標資料分割。作用:將鏡像寫入目標資料分割。樣本:write_raw_image(“/tmp/boot.img”,”boot”)將boot.img鏡像寫入到系統的boot分區。

      11.getprop(key):通過指定key的值來擷取對應的屬性資訊。樣本:getprop(“ro.product.device”)擷取ro.product.device的屬性值。

二、updater-script指令碼執行流程分析:

          先看一下在測試過程中用命令make otapackage產生的升級指令碼如下:

assert(!less_than_int(1331176658, getprop("ro.build.date.utc")));assert(getprop("ro.product.device") == "tcc8800" ||       getprop("ro.build.product") == "tcc8800");show_progress(0.500000, 0);format("yaffs2", "MTD", "system");mount("yaffs2", "MTD", "system", "/system");package_extract_dir("recovery", "/system");package_extract_dir("system", "/system");symlink("busybox", "/system/bin/cp", "/system/bin/grep",        "/system/bin/tar", "/system/bin/unzip",        "/system/bin/vi");symlink("toolbox", "/system/bin/cat", "/system/bin/chmod",        "/system/bin/chown", "/system/bin/cmp", "/system/bin/date",        "/system/bin/dd", "/system/bin/df", "/system/bin/dmesg",        "/system/bin/getevent", "/system/bin/getprop", "/system/bin/hd",        "/system/bin/id", "/system/bin/ifconfig", "/system/bin/iftop",        "/system/bin/insmod", "/system/bin/ioctl", "/system/bin/ionice",        "/system/bin/kill", "/system/bin/ln", "/system/bin/log",        "/system/bin/ls", "/system/bin/lsmod", "/system/bin/lsof",        "/system/bin/mkdir", "/system/bin/mount", "/system/bin/mv",        "/system/bin/nandread", "/system/bin/netstat",        "/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",        "/system/bin/ps", "/system/bin/reboot", "/system/bin/renice",        "/system/bin/rm", "/system/bin/rmdir", "/system/bin/rmmod",        "/system/bin/route", "/system/bin/schedtop", "/system/bin/sendevent",        "/system/bin/setconsole", "/system/bin/setprop", "/system/bin/sleep",        "/system/bin/smd", "/system/bin/start", "/system/bin/stop",        "/system/bin/sync", "/system/bin/top", "/system/bin/umount",        "/system/bin/uptime", "/system/bin/vmstat", "/system/bin/watchprops",        "/system/bin/wipe");set_perm_recursive(0, 0, 0755, 0644, "/system");set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");set_perm(0, 3003, 02750, "/system/bin/netcfg");set_perm(0, 3004, 02755, "/system/bin/ping");set_perm(0, 2000, 06750, "/system/bin/run-as");set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");set_perm(0, 0, 0755, "/system/etc/bluetooth");set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pairing.conf");set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");set_perm(0, 0, 0544, "/system/etc/install-recovery.sh");set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");set_perm(0, 0, 06755, "/system/xbin/librank");set_perm(0, 0, 06755, "/system/xbin/procmem");set_perm(0, 0, 06755, "/system/xbin/procrank");set_perm(0, 0, 06755, "/system/xbin/su");set_perm(0, 0, 06755, "/system/xbin/tcpdump");show_progress(0.200000, 0);show_progress(0.200000, 10);assert(package_extract_file("boot.img", "/tmp/boot.img"),       write_raw_image("/tmp/boot.img", "boot"),       delete("/tmp/boot.img"));show_progress(0.100000, 0);unmount("/system");

          下面分析下這個指令碼的執行過程:

         ①比較時間戳記:如果升級包較舊則終止指令碼的執行。

         ②匹配裝置資訊:如果和當前的裝置資訊不一致,則停止指令碼的執行。

         ③顯示進度條:如果以上兩步匹配則開始顯示升級進度條。

         ④格式化system分區並掛載。

         ⑤提取包中的recovery以及system目錄下的內容到系統的/system下。

         ⑥為/system/bin/下的命令檔案建立符號串連。

         ⑦設定/system/下目錄以及檔案的屬性。

         ⑧將包中的boot.img提取到/tmp/boot.img。

         ⑨將/tmp/boot.img鏡像檔案寫入到boot分區。

         ⑩完成後卸載/system。

         以上就是updater-script指令碼中的文法,及其執行的具體過程。通過分析其執行流程,我們可以發現在執行過程中,並未將升級包另外解壓到一個地方,而是需要什麼提取什麼。值得主要的是在提取recovery和system目錄中的內容時,一併放在了/system/下。在操作的過程中,並未刪除或改變update.zip包中的任何內容。在實際的更新完成後,我們的update.zip包確實還存在於原來的位置。


三、總結

        以上的九篇著重分析了Android系統中Recovery模式中的一種,即我們做好的update.zip包在系統更新時所走過的流程。其核心部分就是Recovery服務的工作原理。其他兩種FACTORY RESET、ENCRYPTED FILE SYSTEM ENABLE/DISABLE與OTA INSTALL是相通的。重點是要理解Recovery服務的工作原理。另外詳細分析其升級過程,對於我們在實際升級時,可以根據我們的需要做出相應的修改。

         不足之處,請大家不吝指正!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.