/home/simba/update_zip |-- boot.img |-- Manifest.xml |-- META-INF | |-- CERT.RSA | |-- CERT.SF | |-- com | | |-- android | | | `-- metadata | | `-- google | | `-- android | | |-- update-binary | | `-- updater-script | `-- MANIFEST.MF |-- recovery | |-- etc | | `-- install-recovery.sh | `-- recovery-from-boot.p `-- system |-- app |-- bin |-- build.prop |-- etc |-- fonts |-- framework |-- lib |-- media |-- usr `-- xbin 66 directories, 1025 files
-------- /etc/recovery.fstab ----------- /boot emmc /dev/block/mmcblk0p1 /sdcard vfat /dev/block/mmcblk0p4 /recovery emmc /dev/block/mmcblk0p2 /system ext4 /dev/block/mmcblk0p5 /cache ext4 /dev/block/mmcblk0p6 /data ext4 /dev/block/mmcblk0p7 /misc emmc /dev/block/mmcblk0p9 --------------------------------------------
--------- updater-script ---------------- .... //省略若干 format("ext4", "EMMC", "/dev/block/mmcblk0p5", "0"); mount("ext4", "EMMC", "/dev/block/mmcblk0p5", "/system"); //挂载system分区。这里有"/dev/block/mmcblk0p5"和"/system"的对应关系,来源于前文提到的recovery.fstab。 package_extract_dir("recovery", "/system"); //将zip包中的recovery目录解压到系统/system目录,将来升级recovery分区时使用(install-recovery.sh,recovery-from-boot.p) package_extract_dir("system", "/system"); //将zip包中的system目录解压到系统/system目录,完成system分区的升级 ...... //省略若干 symlink("mksh", "/system/bin/sh"); symlink("toolbox", "/system/bin/cat", ....); //创建软链接,省略若干 retouch_binaries("/system/lib/libbluedroid.so", .....); //再摸一下各种动态库,省略若干 set_perm_recursive(0, 0, 0755, 0644, "/system"); ...... //修改权限,省略若干 show_progress(0.200000, 0); //显示升级进度 ...... //修改权限,省略若干 package_extract_file("boot.img", "/dev/block/mmcblk0p1"); //将boot.img解压到相应block设备,完成boot分区的升级。boot分区包含了kernel + ramdisk show_progress(0.100000, 0); unmount("/system"); //卸载system分区 ---------------------------------------------
----- /init.rc ------ ... service flash_recovery /system/etc/install-recovery.sh class main oneshot ... --------------------
------- /system/etc/install-recovery.sh ---- #!/system/bin/sh log -t recovery "Before sha1.... Simba...." if ! applypatch -c EMMC:/dev/block/mmcblk0p2:4642816:c125924fef5a1351c9041ac9e1d6fd1f9738ff77; then log -t recovery "Installing new recovery image__From Simba..." applypatch EMMC:/dev/block/mmcblk0p1:3870720:aee24fadd281e9e2bd4883ee9962a86fc345dcab EMMC:/dev/block/mmcblk0p2 c125924fef5a1351c9041ac9e1d6fd1f9738ff77 4642816 aee24fadd281e9e2bd4883ee9962a86fc345dcab:/system/recovery-from-boot.p else log -t recovery "Recovery image already installed__From Simba..." fi -------------------------------------------
执行 make otapackage命令时,编译脚本比较boot.img和recovery.img得出patch文件recovery-from-boot.p。
recovery-from-boot.p也是在recovery模式中updater-script解压到system目录的。
install-recovery.sh脚本就是使用这个patch加上boot分区,更新recovery分区。
应用patch前,install-recovery.sh会计算当前recovery分区的sha1。
若计算结果与脚本中记录的相同(c125924fef5a1351c9041ac9e1d6fd1f9738ff77),说明已经更新过了,不再操作。