我们来看下增量升级包流程:
为了能够详细一点说明我这边是弄了几个不同的文件替换然后很好的分析,增量升级包制作要手动执行脚本
例如: ./build/tools/releasetools/ota_from_target_files -v -n -i /home/yexiang/MSTAR_Android/yx_bak/aosp_ponkan32-target_files-ANMI-02.70.020.04.01.BIONIC.C2_A.zip /home/yexiang/MSTAR_Android/yx_bak/aosp_ponkan32-target_files-ANMI-02.70.020.04.01.BIONIC.C2_B.zip /home/yexiang/MSTAR_Android/yx_bak/updata_ota.zip
也就是根据2个完整的包中找到不同的地方进行比较做出脚本
<< 增量升级函数分析 >>
WriteIncrementalOTAPackage(target_zip, source_zip, output_zip)
Make ota package with tv: ['tvservice', 'tvcustomer', 'tvdatabase']
unzipping target target-files...
// 首先,我们获得脚本生成器,他们的实现见脚本:edify_generator.py
// 其实script就是一个EdifyGenerator类的实例
script = edify_generator.EdifyGenerator(source_version,
OPTIONS.target_info_dict)
// 获得一些环境变量,来自android 环境变量,即将准备写入到 META-INF/com/android/metadata文件中
metadata = {"pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
OPTIONS.source_info_dict),
"post-timestamp": GetBuildProp("ro.build.date.utc",
OPTIONS.target_info_dict),
}
// 设备相关参数
device_specific = common.DeviceSpecificParams(
source_zip=source_zip,
source_version=source_version,
target_zip=target_zip,
target_version=target_version,
output_zip=output_zip,
script=script,
metadata=metadata,
info_dict=OPTIONS.info_dict)
// Loading target...
// Loading source...
// 如果system 源和目不同,那么就打印 print "send", fn, "verbatim"这样的信息
例如
//send system/bin/chat verbatim
//send system/bin/lsusb verbatim
//send system/bin/usb_modeswitch verbatim
//send system/lib/libusb.so verbatim
// 返回的system_diff是一个类
system_diff = FileDifference("system", source_zip, target_zip, output_zip)
// mount("ext4", "EMMC", "/dev/block/platform/mstar_mci.0/by-name/system", "/system", "max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc");
script.Mount("/system", recovery_mount_options)
// 暂时没用 vendor 目录,所以 vendor_diff = None
if HasVendorPartition(target_zip):
vendor_diff = FileDifference("vendor", source_zip, target_zip, output_zip)
script.Mount("/vendor", recovery_mount_options)
else:
vendor_diff = None
def CalculateFingerprint(oem_props, oem_dict, info_dict):
if oem_props is None:
return GetBuildProp("ro.build.fingerprint", info_dict)
return "%s/%s/%s:%s" % (
GetOemProperty("ro.product.brand", oem_props, oem_dict, info_dict),
GetOemProperty("ro.product.name", oem_props, oem_dict, info_dict),
GetOemProperty("ro.product.device", oem_props, oem_dict, info_dict),
GetBuildProp("ro.build.thumbprint", info_dict))
//ro.build.fingerprint=MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys
// ro.product.brand=MStar
// ro.product.name=aosp_ponkan32
// ro.product.device=ponkan
// ro.build.thumbprint 没定义
target_fp = CalculateFingerprint(oem_props, oem_dict, OPTIONS.target_info_dict)
source_fp = CalculateFingerprint(oem_props, oem_dict, OPTIONS.source_info_dict)
// 写入脚本下面语句判断
// 两个target files 目录中的系统指纹信息进行对比 (若更新包中新旧版本的系统指纹与当前手机中的系统指纹不一致就会执行中止语句)
// getprop("ro.build.fingerprint") == "MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys" ||
// getprop("ro.build.fingerprint") == "MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys" ||
// abort("Package expects build fingerprint of MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys or MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys; this device has " + getprop("ro.build.fingerprint") + ".");
if oem_props is None:
script.AssertSomeFingerprint(source_fp, target_fp)
else:
script.AssertSomeThumbprint(
GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
// 准备写入metadata文件中
// post-build=MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys
// post-timestamp=1498615328
// pre-build=MStar/aosp_ponkan32/ponkan:5.1.1/LMY47V/ANMI-02.70.020.04.01.BIONIC.C2:userdebug/test-keys
// pre-device=ponkan
metadata["pre-build"] = source_fp
metadata["post-build"] = target_fp
// OTA_WITH_TVCONFIG := 0 不执行
# tvconfig
updating_tvconfig = False
update_tvconfig_list = []
update_tvconfig_delete_list = []
if OPTIONS.ota_with_tvconfig == 1:
if ComparePartitionImage("TVCONFIG/", "tvconfig.img", OPTIONS.source_tmp, OPTIONS.target_tmp):
updating_tvconfig = True
elif OPTIONS.ota_with_tvconfig == 2:
for cus in OPTIONS.ota_tvconfig_image_list:
if ComparePartitionFiles("TVCONFIG/", cus, OPTIONS.source_tmp, OPTIONS.target_tmp):
updating_tvconfig = True
update_tvconfig_list.append(cus)
for cus in OPTIONS.ota_tvconfig_delete_list:
updating_tvconfig = True
update_tvconfig_delete_list.append(cus)
// OTA_WITH_MBOOT = 1 定义执行 ,会比较 MBOOT下的bfe_app.bin 和 bfe_boot.bin 两个文件
// 如果不同 enable_mboot = True , enable_pm = True, 并且会打印 print "The (%s) is different!\n" % (file_name_mboot,)
// 如果相同
// if enable_pm == False :
// print "The pm image is same!\n"
// if enable_mboot == False:
// print "The mboot image is same!\n"
// The pm image is same!
// The mboot image is same!
# mboot/pm
updating_mboot = False
enable_pm = False
enable_mboot = False
if OPTIONS.ota_with_mboot != '0':
updating_mboot, enable_pm, enable_mboot = CompareMBootImage(OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_RELOAD_ENV = 1 定义执行
# env
updating_env = False
if OPTIONS.ota_reload_env == '1':
updating_env = True
// OTA_WITH_TV := 1 执行
// 循环判断3个image是否不同,如果不同打印出来 ,否则打印出3个都相同
// All tv images are same!
if (source_file.data != target_file.data):
print "The tv image (%s) is different!\n" % (file_name,)
return True
# tvservice/tvuserdata/tvcustomer
updating_tv = False
update_tv_list = []
if OPTIONS.ota_with_tv == 1:
updating_tv = CompareTVImages(OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_WITH_TEE := 0 不执行
# tee
updating_tee = False
if OPTIONS.ota_with_tee == 'true':
updating_tee = CompareTEEImage(OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_WITH_RTPM := fase 不执行
# RTPM
updating_rtpm = False
if OPTIONS.ota_with_rtpm == 'true':
updating_rtpm = ComparePartitionImage("RTPM/", "RT_PM.bin", OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_WITH_URSA := 0 不执行
# URSA
updating_ursa = False
if OPTIONS.ota_with_ursa == '1':
updating_ursa = ComparePartitionImage("URSA/", "ursa.bin", OPTIONS.source_tmp, OPTIONS.target_tmp)
elif OPTIONS.ota_with_ursa == '2':
updating_ursa = ComparePartitionImage("URSA/", "ursa_ap.bin", OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_WITH_RAPTORS 没定义 = false
# RAPTORS
updating_raptors = False
if OPTIONS.ota_with_raptors == 'true':
updating_raptors = ComparePartitionImage("RAPTORS/", "raptors.bin", OPTIONS.source_tmp, OPTIONS.target_tmp)
// OTA_WITH_DTB = true 定义执行
// 如果不同 print "The (%s) is different!\n" % (file_name,) 返回 True ,
// 相同 print "The (%s) is same!\n" % (file_name,) ,返回False
// The (dtb.bin) is same!
# DTB
updating_dtb = False
if OPTIONS.ota_with_dtb == 'true':
updating_dtb = ComparePartitionImage("DTB/", "dtb.bin", OPTIONS.source_tmp, OPTIONS.target_tmp)
//从源-目 两个target file 目录中的BOOT 和 RECOVERY 中都生成 boot.img 和 recovery.img 然后
//通过判断是否进行比较赋予 updating_boot 和 updating_recovery 这两个标志位
/*
building image from target_files BOOT...
running: mkbootfs -f /tmp/targetfiles-6qcj6Z/META/boot_filesystem_config.txt /tmp/targetfiles-6qcj6Z/BOOT/RAMDISK
running: minigzip
running: mkbootimg --kernel /tmp/targetfiles-6qcj6Z/BOOT/kernel --base 0x20200000 --ramdisk /tmp/tmp75epsm --output /tmp/tmphzyJcG
building image from target_files BOOT...
running: mkbootfs -f /tmp/targetfiles-YOmxHj/META/boot_filesystem_config.txt /tmp/targetfiles-YOmxHj/BOOT/RAMDISK
running: minigzip
running: mkbootimg --kernel /tmp/targetfiles-YOmxHj/BOOT/kernel --base 0x20200000 --ramdisk /tmp/tmpd5FOFD --output /tmp/tmp_FqjXx
building image from target_files RECOVERY...
running: mkbootfs -f /tmp/targetfiles-6qcj6Z/META/recovery_filesystem_config.txt /tmp/targetfiles-6qcj6Z/RECOVERY/RAMDISK
running: minigzip
running: mkbootimg --kernel /tmp/targetfiles-6qcj6Z/RECOVERY/kernel --base 0x20200000 --ramdisk /tmp/tmpM5OJ0k --output /tmp/tmpUmqcbO
building image from target_files RECOVERY...
running: mkbootfs -f /tmp/targetfiles-YOmxHj/META/recovery_filesystem_config.txt /tmp/targetfiles-YOmxHj/RECOVERY/RAMDISK
running: minigzip
running: mkbootimg --kernel /tmp/targetfiles-YOmxHj/RECOVERY/kernel --base 0x20200000 --ramdisk /tmp/tmpIHw6F2 --output /tmp/tmp5UQ1zv
*/
source_boot = common.GetBootableImage(
"/tmp/boot.img", "boot.img", OPTIONS.source_tmp, "BOOT",
OPTIONS.source_info_dict)
target_boot = common.GetBootableImage(
"/tmp/boot.img", "boot.img", OPTIONS.target_tmp, "BOOT")
updating_boot = (not OPTIONS.two_step and
(source_boot.data != target_boot.data))
source_recovery = common.GetBootableImage(
"/tmp/recovery.img", "recovery.img", OPTIONS.source_tmp, "RECOVERY",
OPTIONS.source_info_dict)
target_recovery = common.GetBootableImage(
"/tmp/recovery.img", "recovery.img", OPTIONS.target_tmp, "RECOVERY")
updating_recovery = (source_recovery.data != target_recovery.data)
// BUILD_WITH_SECURE_BOOT := true
// BUILD_WITH_SECURE_MERGE := true
// 如果boot 和 recovery 不同,那么签名目的包中做出的boot img 或者 recovery img
//签名处理 boot.img 和 recovery.img
running: alignment.exe /tmp/tmpD0K7jy
running: SubSecureInfoGen.exe /tmp/tmpiMdoy0 /tmp/tmpD0K7jy device/mstar/ponkan/security/RSAimage_priv.txt device/mstar/ponkan/security/RSAimage_pub.txt 0 8 1 2097152 0 /home/yexiang/MSTAR_Android/C2_ANDB_ADTH_Android_1230_Release/out/host/linux-x86/bin
running: aescrypt2.exe 0 /tmp/tmpD0K7jy /tmp/tmp2pHdgi device/mstar/ponkan/security/AESboot.bin
running: alignment.exe /tmp/tmpsrnsgw
running: SubSecureInfoGen.exe /tmp/tmpnJRhS0 /tmp/tmpsrnsgw device/mstar/ponkan/security/RSAimage_priv.txt device/mstar/ponkan/security/RSAimage_pub.txt 0 8 1 2097152 0 /home/yexiang/MSTAR_Android/C2_ANDB_ADTH_Android_1230_Release/out/host/linux-x86/bin
running: aescrypt2.exe 0 /tmp/tmpsrnsgw /tmp/tmpeWyRR9 device/mstar/ponkan/security/AESboot.bin
if OPTIONS.ota_with_secure_boot == "true":
if updating_boot:
if OPTIONS.ota_with_secure_merge == "true":
target_boot = SecurityImage(target_boot)
else:
secure_info_boot,target_boot = SecurityImage(target_boot)
common.ZipWriteStr(output_zip, "secure/secure_info_boot.bin", secure_info_boot)
if updating_recovery:
if OPTIONS.ota_with_secure_merge == "true":
target_recovery = SecurityImage(target_recovery)
else:
secure_info_recovery,target_recovery = SecurityImage(target_recovery)
common.ZipWriteStr(output_zip, "recovery/secure_info_recovery.bin", secure_info_recovery)
//脚本中加上判断
//getprop("ro.product.device") == "ponkan" || abort("This package is for \"ponkan\" devices; this is a \"" + getprop("ro.product.device") + "\".");
//和上面的判断和在一起
AppendAssertions(script, OPTIONS.target_info_dict, oem_dict)
// ui_print("Start to upgrade partition");
script.Print("Start to upgrade partition")
// Callback, 用于调用设备相关代码。调用时机为即将开始升级
device_specific.FullOTA_Assertions()
// False 不执行 OPTIONS.two_step步骤
if OPTIONS.two_step:
if not OPTIONS.info_dict.get("multistage_support", None):
assert False, "two-step packages not supported by this build"
fs = OPTIONS.info_dict["fstab"]["/misc"]
assert fs.fs_type.upper() == "EMMC", \
"two-step packages only supported on devices with EMMC /misc partitions"
bcb_dev = {"bcb_dev": fs.device}
common.ZipWriteStr(output_zip, "recovery.img", target_recovery.data)
script.AppendExtra("""
if get_stage("%(bcb_dev)s") == "2/3" then
""" % bcb_dev)
script.AppendExtra("sleep(20);\n");
script.WriteRawImage("/recovery", "recovery.img")
script.AppendExtra("""
set_stage("%(bcb_dev)s", "3/3");
reboot_now("%(bcb_dev)s", "recovery");
else if get_stage("%(bcb_dev)s") != "3/3" then
""" % bcb_dev)
// ui_print("Verifying current system...");
script.Print("Verifying current system...")
device_specific.IncrementalOTA_VerifyBegin() 《----》
// show_progress(0.100000, 0);
script.ShowProgress(0.1, 0)
//脚本中生成这样的命令
//apply_patch_check("/system/bin/recovery", "8fcfc349f5bd0a9b97a5bcbc4e0b4dc2116e310a", "cbfaf4fcccf95a86273d53a2a952db76fee23002") || abort("\"/system/bin/recovery\" has unexpected contents.");
//apply_patch_check("/system/bin/updater", "0b2a4a3f043991d5b76bad146596eb45d26e4048", "deadee6d1253b7f621e26b528e1a12ca3cc6d3be") || abort("\"/system/bin/updater\" has unexpected contents.");
//apply_patch_check("/system/bin/verifier_test", "9600f0a35254b178522f0ea0a2dab026f3f04176", "62c830a481a3e9419602d7c3667f5c65a9fe87a4") || abort("\"/system/bin/verifier_test\" has unexpected contents.");
//apply_patch_check("/system/etc/recovery-resource.dat", "72eb7b8809bb36fef1f8780bcd0d30fc35d234ba", "2b2414116b08c605845184dd8e03d76549432390") || abort("\"/system/etc/recovery-resource.dat\" has unexpected contents.");
//apply_patch_check("/system/lib/libcurl.so", "5ef3690c56b16ac4d065b38e717ec251c7c6b414", "3b103017aa1ac4cc3e458dcc713dad4489737ab5") || abort("\"/system/lib/libcurl.so\" has unexpected contents.");
//apply_patch_check("/system/lib/libmss.so", "fbbdf9facad01c0f3fdf9bce795c54c7d389c8d3", "43818c8042c56da3d5ee2dee5c45678db5a28ba1") || abort("\"/system/lib/libmss.so\" has unexpected contents.");
so_far = system_diff.EmitVerification(script)
// vendor_diff = False 不执行
if vendor_diff:
so_far += vendor_diff.EmitVerification(script)
size = []
if system_diff.patch_list: size.append(system_diff.largest_source_size)
// vendor_diff = False 不执行
if vendor_diff:
if vendor_diff.patch_list: size.append(vendor_diff.largest_source_size)
device_specific.IncrementalOTA_VerifyEnd() 《----》
// False 不执行 OPTIONS.two_step步骤
if OPTIONS.two_step:
script.WriteRawImage("/boot", "recovery.img")
script.AppendExtra("""
set_stage("%(bcb_dev)s", "2/3");
reboot_now("%(bcb_dev)s", "");
else
""" % bcb_dev)
// # ---- start making changes here ----
script.Comment("---- start making changes here ----")
device_specific.IncrementalOTA_InstallBegin() 《----》
// False 不执行 OPTIONS.two_step步骤
if OPTIONS.two_step:
common.ZipWriteStr(output_zip, "boot.img", target_boot.data)
script.WriteRawImage("/boot", "boot.img")
print "writing full boot image (forced by two-step mode)"
// ui_print("Removing unneeded files...");
script.Print("Removing unneeded files...")
//在脚本中添加
delete("/system/bin/chat", "/system/bin/lsusb",
"/system/bin/usb_modeswitch", "/system/lib/libusb.so",
"/system/recovery.img");
// ("/system/recovery.img",) 相当于手动加入进去
system_diff.RemoveUnneededFiles(script, ("/system/recovery.img",))
// vendor_diff = False 不执行
if vendor_diff:
vendor_diff.RemoveUnneededFiles(script)
// show_progress(0.800000, 0);
script.ShowProgress(0.8, 0)
total_patch_size = 1.0 + system_diff.TotalPatchSize()
// vendor_diff = False 不执行
if vendor_diff:
total_patch_size += vendor_diff.TotalPatchSize()
// ui_print("Patching system files...");
script.Print("Patching system files...")
/* 脚本中添加
apply_patch("/system/bin/recovery", "-",
8fcfc349f5bd0a9b97a5bcbc4e0b4dc2116e310a, 256184,
cbfaf4fcccf95a86273d53a2a952db76fee23002, package_extract_file("patch/system/bin/recovery.p"));
set_progress(0.093098);
apply_patch("/system/bin/updater", "-",
0b2a4a3f043991d5b76bad146596eb45d26e4048, 604848,
deadee6d1253b7f621e26b528e1a12ca3cc6d3be, package_extract_file("patch/system/bin/updater.p"));
set_progress(0.312900);
apply_patch("/system/bin/verifier_test", "-",
9600f0a35254b178522f0ea0a2dab026f3f04176, 179032,
62c830a481a3e9419602d7c3667f5c65a9fe87a4, package_extract_file("patch/system/bin/verifier_test.p"));
set_progress(0.377960);
apply_patch("/system/etc/recovery-resource.dat", "-",
72eb7b8809bb36fef1f8780bcd0d30fc35d234ba, 636852,
2b2414116b08c605845184dd8e03d76549432390, package_extract_file("patch/system/etc/recovery-resource.dat.p"));
set_progress(0.609393);
apply_patch("/system/lib/libcurl.so", "-",
5ef3690c56b16ac4d065b38e717ec251c7c6b414, 259444,
3b103017aa1ac4cc3e458dcc713dad4489737ab5, package_extract_file("patch/system/lib/libcurl.so.p"));
set_progress(0.703675);
apply_patch("/system/lib/libmss.so", "-",
fbbdf9facad01c0f3fdf9bce795c54c7d389c8d3, 968524,
43818c8042c56da3d5ee2dee5c45678db5a28ba1, package_extract_file("patch/system/lib/libmss.so.p"));
set_progress(1.055638);
*/
so_far = system_diff.EmitPatches(script, total_patch_size, 0)
// vendor_diff = False 不执行
if vendor_diff:
script.Print("Patching vendor files...")
so_far = vendor_diff.EmitPatches(script, total_patch_size, so_far)
system_items = ItemSet("system", "META/filesystem_config.txt")
// vendor_diff = False 不执行
if vendor_diff:
vendor_items = ItemSet("vendor", "META/vendor_filesystem_config.txt")
// 如果boot image不同那么需要执行
if updating_boot:
common.ZipWriteStr(output_zip, "boot.img", target_boot.data)
// ui_print("Updating boot image...");
script.Print("Updating boot image...")
script.WriteRawImage("/boot", "boot.img") //写到升级包中的 boot/boot.img
print "boot image changed; including."
else:
print "boot image unchanged; skipping."
// 如果recovery image不同那么需要执行
if updating_recovery:
// 删除 /system/etc/install-recovery.sh和/system/recovery.img
script.DeleteFiles(["/system/recovery.img","/system/etc/install-recovery.sh"])
// 不执行
if OPTIONS.ota_with_secure_boot == "true" and OPTIONS.ota_with_secure_merge != "true":
script.DeleteFiles(["/system/update_recovery_sign"])
print "recovery image changed; including."
else:
print "recovery image unchanged; skipping."
// show_progress(0.1, 10);
script.ShowProgress(0.100000, 10)
//如果 tvconfig 有变化执行
if updating_tvconfig:
if OPTIONS.ota_with_tvconfig == 1:
tvconfig_image = UpdatePartitionImage("TVCONFIG/", "tvconfig.img", target_zip, output_zip)
UpdateScriptForPartition(script, "/tvconfig", tvconfig_image)
print "tvconfig image changed; including tvconfig images to update"
elif OPTIONS.ota_with_tvconfig == 2:
script.Mount("/tvconfig")
for cus in update_tvconfig_list:
script.UnpackPackageDir(cus, "/tvconfig")
symlinks = CopyPartitionFiles("TVCONFIG/", cus, target_zip, output_zip, None)
script.MakeSymlinks(symlinks)
for cusdel in update_tvconfig_delete_list:
delete_tvconfig_files_list = []
strlength = len(cusdel)
if strlength == 0:
continue
DeletePartitionFiles(delete_tvconfig_files_list, "TVCONFIG_DEL/", cusdel, target_zip, output_zip, None)
for del_name in delete_tvconfig_files_list:
script.DeletePartitionFile("/tvconfig", del_name)
print "tvconfig changed; including tvconfig files to update"
else:
print "tvconfig unchanged; skipping."
//如果 3个 tv*.img 有变化执行
if updating_tv:
if OPTIONS.ota_with_tv == 1:
tv_images = CopyTVImages(target_zip, output_zip)
UpdateScriptForTV(script, tv_images)
print "tv image changed; including tv images to update"
elif OPTIONS.ota_with_tv == 2:
# If tv images are different, they should be update
for tv in update_tv_list:
script.FormatPartition("/" + tv)
script.Mount("/" + tv)
script.UnpackPackageDir(tv, "/" + tv)
symlinks = CopyTVFiles(tv, target_zip, output_zip)
script.MakeSymlinks(symlinks)
SetTVPermissions(script, tv)
print "tv changed; including tv files to update"
else:
print "tv unchanged; skipping."
// 暂时不执行
if updating_tee:
# If the tee image is different, it should be update
tee_image, nuttx_image = CopyTEEImage(target_zip, output_zip)
UpdateScriptForTEE(script, tee_image, nuttx_image)
else:
print "tee image unchanged; skipping."
// 暂时不执行
if updating_rtpm:
# If the rtpm image is different, it should be update
rtpm_image = UpdatePartitionImage("RTPM/", "RT_PM.bin", input_zip, output_zip)
script.WriteRawImage("/RTPM", rtpm_image)
print "rtpm image changed; including rtpm image to update"
else:
print "rtpm image unchanged; skipping."
// 如果UBOOT有变化执行
if updating_mboot:
# If the mboot image is different, it should be update
pm_image, mboot_image, mboot_rom_image = CopyMBootImage(target_zip, enable_pm, enable_mboot, output_zip)
UpdateScriptForMBoot(script, pm_image, mboot_image, mboot_rom_image)
print "mboot image changed; including mboot image to update"
else:
print "mboot image unchanged; skipping."
// 暂时不执行
if updating_ursa:
# If the ursa image is different, it should be update
ursa_file_name = "ursa.bin"
if OPTIONS.ota_with_ursa == 2:
ursa_file_name = "ursa_ap.bin"
ursa_file_name = UpdatePartitionImage("URSA/", ursa_file_name, input_zip, output_zip)
ursa_tmp_path = "/tmp/" + ursa_file_name
script.UnpackPackageFile(ursa_file_name, ursa_tmp_path)
script.UpdateUrsa(ursa_tmp_path)
print "ursa image changed; including ursa image to update"
else:
print "ursa image unchanged; skipping."
// 暂时不执行
if updating_raptors:
# If the raptors image is different, it should be update
UpdatePartitionImage("RAPTORS/", "raptors.bin", target_zip, output_zip)
script.UnpackPackageFile("raptors.bin", "/tmp/raptors.bin")
script.UpdateRaptors()
print "raptors image changed; including raptors images to update"
else:
print "raptors unchanged; skipping."
// 如果dtb有变化执行
if updating_dtb:
# If the dtb image is different, it should be update
dtb_image = UpdatePartitionImage("DTB/", "dtb.bin", input_zip, output_zip)
script.WriteRawImage("/dtb", dtb_image) //写到升级包中的 dtb/dtb.bin
print "dtb image changed; including dtb image to update"
else:
print "dtb image unchanged; skipping."
// 定义了执行
// ui_print("Reloading the environment variable in misc partition...");
// reload_panel();
// reload_env();
if updating_env:
UpdateScriptForReloadEnv(script)
target_symlinks = CopyPartitionFiles(system_items, target_zip, None)
if vendor_diff:
target_symlinks.extend(CopyPartitionFiles(vendor_items, target_zip, None))
// 读取输入包中的filesystem_config.txt读取 所有的 system 目录下的各文件权限信息
// selabel=u:object_r:system_file:s0 capabilities=0x0 这些保存起来到 self.ITEMS 去设置属性
// 这里分2个部分,一个是目录权限,一个是文件权限 ,例如脚本中的片段
// set_metadata_recursive("/system", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0644, "capabilities", 0x0, "selabel", "u:object_r:system_file:s0");
// set_metadata_recursive("/system/bin", "uid", 0, "gid", 2000, "dmode", 0755, "fmode", 0755, "capabilities", 0x0, "selabel", "u:object_r:system_file:s0");
// set_metadata("/system/bin/accel87", "uid", 0, "gid", 2000, "mode", 0755, "capabilities", 0x0, "selabel", "u:object_r:systemserver_exec:s0");
// set_metadata("/system/bin/app_process32", "uid", 0, "gid", 2000, "mode", 0755, "capabilities", 0x0, "selabel", "u:object_r:zygote_exec:s0");
// set_metadata("/system/bin/bootanimation", "uid", 0, "gid", 2000, "mode", 0755, "capabilities", 0x0, "selabel", "u:object_r:bootanim_exec:s0");
temp_script = script.MakeTemporary()
system_items.GetMetadata(target_zip)
system_items.Get("system").SetPermissions(temp_script)
// vendor_diff = False 不执行
if vendor_diff:
vendor_items.GetMetadata(target_zip)
vendor_items.Get("vendor").SetPermissions(temp_script)
# Note that this call will mess up the trees of Items, so make sure
# we're done with them.
source_symlinks = CopyPartitionFiles(system_items, source_zip, None)
if vendor_diff:
source_symlinks.extend(CopyPartitionFiles(vendor_items, source_zip, None))
target_symlinks_d = dict([(i[1], i[0]) for i in target_symlinks])
source_symlinks_d = dict([(i[1], i[0]) for i in source_symlinks])
# Delete all the symlinks in source that aren't in target. This
# needs to happen before verbatim files are unpacked, in case a
# symlink in the source is replaced by a real file in the target.
to_delete = []
for dest, link in source_symlinks:
if link not in target_symlinks_d:
to_delete.append(link)
script.DeleteFiles(to_delete)
// 如果system目录下有变化
if system_diff.verbatim_targets:
// ui_print("Unpacking new system files...");
script.Print("Unpacking new system files...")
// package_extract_dir("system", "/system");
script.UnpackPackageDir("system", "/system")
// 没定义不执行
if vendor_diff and vendor_diff.verbatim_targets:
script.Print("Unpacking new vendor files...")
script.UnpackPackageDir("vendor", "/vendor")
// 如果recovery image不同那么需要执行
if updating_recovery:
// ui_print("Unpacking new recovery...");
script.Print("Unpacking new recovery...")
// package_extract_dir("recovery", "/system");
script.UnpackPackageDir("recovery", "/system")
// 这一步就是把签名后的 recovery.img 写到输出包的 recovery/recovery.img
// 并且生成一个脚本install-recovery.sh (recovery/bin/install-recovery.sh)
// 然后脚本中添加设置/system/bin/install-recovery.sh 和 /system/recovery.img 权限
// set_metadata("/system/bin/install-recovery.sh", "uid", 0, "gid", 0, "mode", 0750, "capabilities", 0x0, "selabel", "u:object_r:install_recovery_exec:s0");
// set_metadata("/system/recovery.img", "uid", 0, "gid", 0, "mode", 0540, "capabilities", 0x0);