android OTA修改

来源:互联网 发布:知乎 搞笑的段子 编辑:程序博客网 时间:2024/06/05 17:29
[cpp] view plaincopyprint?
  1. def WriteFullOTAPackage(input_zip, output_zip):  
  2.   # TODO: how to determine this?  We don't know what version it will  
  3.   # be installed on top of.  For now, we expect the API just won't  
  4.   # change very often.  
  5.   script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)  
  6.   
  7.   metadata = {"post-build": GetBuildProp("ro.build.fingerprint",  
  8.                                          OPTIONS.info_dict),  
  9.               "pre-device": GetBuildProp("ro.product.device",  
  10.                                          OPTIONS.info_dict),  
  11.               "post-timestamp": GetBuildProp("ro.build.date.utc",  
  12.                                              OPTIONS.info_dict),  
  13.               }  
  14.   
  15.   device_specific = common.DeviceSpecificParams(  
  16.       input_zip=input_zip,  
  17.       input_version=OPTIONS.info_dict["recovery_api_version"],  
  18.       output_zip=output_zip,  
  19.       script=script,  
  20.       input_tmp=OPTIONS.input_tmp,  
  21.       metadata=metadata,  
  22.       info_dict=OPTIONS.info_dict)  
  23.   
  24.   if not OPTIONS.omit_prereq:  
  25.     ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)  
  26.     script.AssertOlderBuild(ts)  
  27.   
  28.   AppendAssertions(script, OPTIONS.info_dict)  
  29.   device_specific.FullOTA_Assertions()  
  30.   device_specific.FullOTA_InstallBegin()  
  31.   
  32.   script.ShowProgress(0.5, 0)  
  33.   device_specific.Install_Parameter()  
  34.   
  35.   if OPTIONS.wipe_user_data:  
  36.     script.FormatPartition("/data")  
  37.   
  38.   if "selinux_fc" in OPTIONS.info_dict:  
  39.     WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)  
  40.   
  41.   script.FormatPartition("/system")  
  42.   script.Mount("/system")  
  43.   script.UnpackPackageDir("recovery""/system")  
  44.   script.UnpackPackageDir("system""/system")  
  45.   
  46.   symlinks = CopySystemFiles(input_zip, output_zip)  
  47.   script.MakeSymlinks(symlinks)  
  48.   
  49.   boot_img = common.GetBootableImage("boot.img""boot.img",  
  50.                                      OPTIONS.input_tmp, "BOOT")  
  51.   recovery_img = common.GetBootableImage("recovery.img""recovery.img",  
  52.                                          OPTIONS.input_tmp, "RECOVERY")  
  53.   MakeRecoveryPatch(OPTIONS.input_tmp, output_zip, recovery_img, boot_img)  
  54.   
  55.   Item.GetMetadata(input_zip)  
  56.   Item.Get("system").SetPermissions(script)  
  57.   
  58.   common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)  
  59.   common.ZipWriteStr(output_zip, "boot.img", boot_img.data)  
  60.   script.ShowProgress(0.2, 0)  
  61.   
  62.   script.ShowProgress(0.2, 10)  
  63.   script.WriteRawImage("/boot""boot.img")  
  64.   
  65.   script.ShowProgress(0.1, 0)  
  66.   device_specific.FullOTA_InstallEnd()  
  67.   
  68.   if OPTIONS.extra_script is not None:  
  69.     script.AppendExtra(OPTIONS.extra_script)  
  70.   
  71.   script.UnmountAll()  
  72.   script.AddToZip(input_zip, output_zip)  
  73.   WriteMetadata(metadata, output_zip)  

如果想把recovery.img全部烧录而不产生差分包

# MakeRecoveryPatch(OPTIONS.input_tmp, output_zip, recovery_img, boot_img)//

common.CheckSize(recovery_img.data, "recovery.img", OPTIONS.info_dict)

common.ZipWriteStr(output_zip, "recovery.img", recovery_img.data)

script.WriteRawImage("/recovery", "recovery.img")

[cpp] view plaincopyprint?
  1. def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):  
  2.   source_version = OPTIONS.source_info_dict["recovery_api_version"]  
  3.   target_version = OPTIONS.target_info_dict["recovery_api_version"]  
  4.   
  5.   if source_version == 0:  
  6.     print ("WARNING: generating edify script for a source that "  
  7.            "can't install it.")  
  8.   script = edify_generator.EdifyGenerator(source_version,  
  9.                                           OPTIONS.target_info_dict)  
  10.   
  11.   metadata = {"pre-device": GetBuildProp("ro.product.device",  
  12.                                          OPTIONS.source_info_dict),  
  13.               "post-timestamp": GetBuildProp("ro.build.date.utc",  
  14.                                              OPTIONS.target_info_dict),  
  15.               }  
  16.   
  17.   device_specific = common.DeviceSpecificParams(  
  18.       source_zip=source_zip,  
  19.       source_version=source_version,  
  20.       target_zip=target_zip,  
  21.       target_version=target_version,  
  22.       output_zip=output_zip,  
  23.       script=script,  
  24.       metadata=metadata,  
  25.       info_dict=OPTIONS.info_dict)  
  26.   
  27.   print "Loading target..."  
  28.   target_data = LoadSystemFiles(target_zip)  
  29.   print "Loading source..."  
  30.   source_data = LoadSystemFiles(source_zip)  
  31.   
  32.   verbatim_targets = []  
  33.   patch_list = []  
  34.   diffs = []  
  35.   largest_source_size = 0  
  36.   for fn in sorted(target_data.keys()):  
  37.     tf = target_data[fn]  
  38.     assert fn == tf.name  
  39.     sf = source_data.get(fn, None)  
  40.   
  41.     if sf is None or fn in OPTIONS.require_verbatim:  
  42.       # This file should be included verbatim  
  43.       if fn in OPTIONS.prohibit_verbatim:  
  44.         raise common.ExternalError("\"%s\" must be sent verbatim" % (fn,))  
  45.       print "send", fn, "verbatim"  
  46.       tf.AddToZip(output_zip)  
  47.       verbatim_targets.append((fn, tf.size))  
  48.     elif tf.sha1 != sf.sha1:  
  49.       # File is different; consider sending as a patch  
  50.       diffs.append(common.Difference(tf, sf))  
  51.     else:  
  52.       # Target file identical to source.  
  53.       pass  
  54.   
  55.   common.ComputeDifferences(diffs)  
  56.   
  57.   for diff in diffs:  
  58.     tf, sf, d = diff.GetPatch()  
  59.     if d is None or len(d) > tf.size * OPTIONS.patch_threshold:  
  60.       # patch is almost as big as the file; don't bother patching  
  61.       tf.AddToZip(output_zip)  
  62.       verbatim_targets.append((tf.name, tf.size))  
  63.     else:  
  64.       common.ZipWriteStr(output_zip, "patch/" + tf.name + ".p", d)  
  65.       patch_list.append((tf.name, tf, sf, tf.size, common.sha1(d).hexdigest()))  
  66.       largest_source_size = max(largest_source_size, sf.size)  
  67.   
  68.   source_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.source_info_dict)  
  69.   target_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.target_info_dict)  
  70.   metadata["pre-build"] = source_fp  
  71.   metadata["post-build"] = target_fp  
  72.   
  73.   script.Mount("/system")  
  74.   script.AssertSomeFingerprint(source_fp, target_fp)  
  75.   
  76.   source_boot = common.GetBootableImage(  
  77.       "/tmp/boot.img""boot.img", OPTIONS.source_tmp, "BOOT",  
  78.       OPTIONS.source_info_dict)  
  79.   target_boot = common.GetBootableImage(  
  80.       "/tmp/boot.img""boot.img", OPTIONS.target_tmp, "BOOT")  
  81.   updating_boot = (source_boot.data != target_boot.data)  
  82.   
  83.   source_recovery = common.GetBootableImage(  
  84.       "/tmp/recovery.img""recovery.img", OPTIONS.source_tmp, "RECOVERY",  
  85.       OPTIONS.source_info_dict)  
  86.   target_recovery = common.GetBootableImage(  
  87.       "/tmp/recovery.img""recovery.img", OPTIONS.target_tmp, "RECOVERY")  
  88.   updating_recovery = (source_recovery.data != target_recovery.data)  
  89.   
  90.   # Here's how we divide up the progress bar:  
  91.   #  0.1 for verifying the start state (PatchCheck calls)  
  92.   #  0.8 for applying patches (ApplyPatch calls)  
  93.   #  0.1 for unpacking verbatim files, symlinking, and doing the  
  94.   #      device-specific commands.  
  95.   
  96.   AppendAssertions(script, OPTIONS.target_info_dict)  
  97.   device_specific.IncrementalOTA_Assertions()  
  98.   
  99.   script.Print("Verifying current system...")  
  100.   
  101.   device_specific.IncrementalOTA_VerifyBegin()  
  102.   
  103.   script.ShowProgress(0.1, 0)  
  104.   total_verify_size = float(sum([i[2].size for i in patch_list]) + 1)  
  105.   if updating_boot:  
  106.     total_verify_size += source_boot.size  
  107.   so_far = 0  
  108.   
  109.   for fn, tf, sf, size, patch_sha in patch_list:  
  110.     script.PatchCheck("/"+fn, tf.sha1, sf.sha1)  
  111.     so_far += sf.size  
  112.     script.SetProgress(so_far / total_verify_size)  
  113.   
  114.   if updating_boot:  
  115.     d = common.Difference(target_boot, source_boot)  
  116.     _, _, d = d.ComputePatch()  
  117.     print "boot      target: %d  source: %d  diff: %d" % (  
  118.         target_boot.size, source_boot.size, len(d))  
  119.   
  120.     common.ZipWriteStr(output_zip, "patch/boot.img.p", d)  
  121.   
  122.     boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)  
  123.   
  124.     script.PatchCheck("%s:%s:%d:%s:%d:%s" %  
  125.                       (boot_type, boot_device,  
  126.                        source_boot.size, source_boot.sha1,  
  127.                        target_boot.size, target_boot.sha1))  
  128.     so_far += source_boot.size  
  129.     script.SetProgress(so_far / total_verify_size)  
  130.   
  131.   if patch_list or updating_recovery or updating_boot:  
  132.     script.CacheFreeSpaceCheck(largest_source_size)  
  133.   
  134.   device_specific.IncrementalOTA_VerifyEnd()  
  135.   
  136.   script.Comment("---- start making changes here ----")  
  137.   
  138.   device_specific.IncrementalOTA_InstallBegin()  
  139.   
  140.   if OPTIONS.wipe_user_data:  
  141.     script.Print("Erasing user data...")  
  142.     script.FormatPartition("/data")  
  143.   
  144.   script.Print("Removing unneeded files...")  
  145.   script.DeleteFiles(["/"+i[0] for i in verbatim_targets] +  
  146.                      ["/"+i for i in sorted(source_data)  
  147.                             if i not in target_data] +  
  148.                      ["/system/recovery.img"])  
  149.   
  150.   script.ShowProgress(0.8, 0)  
  151.   total_patch_size = float(sum([i[1].size for i in patch_list]) + 1)  
  152.   if updating_boot:  
  153.     total_patch_size += target_boot.size  
  154.   so_far = 0  
  155.   
  156.   script.Print("Patching system files...")  
  157.   deferred_patch_list = []  
  158.   for item in patch_list:  
  159.     fn, tf, sf, size, _ = item  
  160.     if tf.name == "system/build.prop":  
  161.       deferred_patch_list.append(item)  
  162.       continue  
  163.     script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")  
  164.     so_far += tf.size  
  165.     script.SetProgress(so_far / total_patch_size)  
  166.   
  167.   if updating_boot:  
  168.     # Produce the boot image by applying a patch to the current  
  169.     # contents of the boot partition, and write it back to the  
  170.     # partition.  
  171.     script.Print("Patching boot image...")  
  172.     script.ApplyPatch("%s:%s:%d:%s:%d:%s"  
  173.                       % (boot_type, boot_device,  
  174.                          source_boot.size, source_boot.sha1,  
  175.                          target_boot.size, target_boot.sha1),  
  176.                       "-",  
  177.                       target_boot.size, target_boot.sha1,  
  178.                       source_boot.sha1, "patch/boot.img.p")  
  179.     so_far += target_boot.size  
  180.     script.SetProgress(so_far / total_patch_size)  
  181.     print "boot image changed; including."  
  182.   else:  
  183.     print "boot image unchanged; skipping."  
  184.   
  185.   if updating_recovery:  
  186.     # Recovery is generated as a patch using both the boot image  
  187.     # (which contains the same linux kernel as recovery) and the file  
  188.     # /system/etc/recovery-resource.dat (which contains all the images  
  189.     # used in the recovery UI) as sources.  This lets us minimize the  
  190.     # size of the patch, which must be included in every OTA package.  
  191.     #  
  192.     # For older builds where recovery-resource.dat is not present, we  
  193.     # use only the boot image as the source.  
  194.   
  195.     MakeRecoveryPatch(OPTIONS.target_tmp, output_zip,  
  196.                       target_recovery, target_boot)  
  197.     script.DeleteFiles(["/system/recovery-from-boot.p",  
  198.                         "/system/etc/install-recovery.sh"])  
  199.     print "recovery image changed; including as patch from boot."  
  200.   else:  
  201.     print "recovery image unchanged; skipping."  
  202.   
  203.   script.ShowProgress(0.1, 10)  
  204.   
  205.   target_symlinks = CopySystemFiles(target_zip, None)  
  206.   
  207.   target_symlinks_d = dict([(i[1], i[0]) for i in target_symlinks])  
  208.   temp_script = script.MakeTemporary()  
  209.   Item.GetMetadata(target_zip)  
  210.   Item.Get("system").SetPermissions(temp_script)  
  211.   
  212.   # Note that this call will mess up the tree of Items, so make sure  
  213.   # we're done with it.  
  214.   source_symlinks = CopySystemFiles(source_zip, None)  
  215.   source_symlinks_d = dict([(i[1], i[0]) for i in source_symlinks])  
  216.   
  217.   # Delete all the symlinks in source that aren't in target.  This  
  218.   # needs to happen before verbatim files are unpacked, in case a  
  219.   # symlink in the source is replaced by a real file in the target.  
  220.   to_delete = []  
  221.   for dest, link in source_symlinks:  
  222.     if link not in target_symlinks_d:  
  223.       to_delete.append(link)  
  224.   script.DeleteFiles(to_delete)  
  225.   
  226.   if verbatim_targets:  
  227.     script.Print("Unpacking new files...")  
  228.     script.UnpackPackageDir("system""/system")  
  229.   
  230.   if updating_recovery:  
  231.     script.Print("Unpacking new recovery...")  
  232.     script.UnpackPackageDir("recovery""/system")  
  233.   
  234.   script.Print("Symlinks and permissions...")  
  235.   
  236.   # Create all the symlinks that don't already exist, or point to  
  237.   # somewhere different than what we want.  Delete each symlink before  
  238.   # creating it, since the 'symlink' command won't overwrite.  
  239.   to_create = []  
  240.   for dest, link in target_symlinks:  
  241.     if link in source_symlinks_d:  
  242.       if dest != source_symlinks_d[link]:  
  243.         to_create.append((dest, link))  
  244.     else:  
  245.       to_create.append((dest, link))  
  246.   script.DeleteFiles([i[1] for i in to_create])  
  247.   script.MakeSymlinks(to_create)  
  248.   
  249.   # Now that the symlinks are created, we can set all the  
  250.   # permissions.  
  251.   script.AppendScript(temp_script)  
  252.   
  253.   # Do device-specific installation (eg, write radio image).  
  254.   device_specific.IncrementalOTA_InstallEnd()  
  255.   
  256.   if OPTIONS.extra_script is not None:  
  257.     script.AppendExtra(OPTIONS.extra_script)  
  258.   
  259.   # Patch the build.prop file last, so if something fails but the  
  260.   # device can still come up, it appears to be the old build and will  
  261.   # get set the OTA package again to retry.  
  262.   script.Print("Patching remaining system files...")  
  263.   for item in deferred_patch_list:  
  264.     fn, tf, sf, size, _ = item  
  265.     script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")  
  266.   script.SetPermissions("/system/build.prop", 0, 0, 0644)  
  267.   
  268.   script.AddToZip(target_zip, output_zip)  
  269.   WriteMetadata(metadata, output_zip)  

差分包把recovery.img完全烧录,而不产生差分,修改地方
[cpp] view plaincopyprint?
  1. #if updating_boot:  
  2.   #  total_verify_size += source_boot.size  
  3.   #  d = common.Difference(target_boot, source_boot)  
  4.   #  _, _, d = d.ComputePatch()  
  5.   #  print "boot      target: %d  source: %d  diff: %d" % (  
  6.   #      target_boot.size, source_boot.size, len(d))  
  7.   #  common.ZipWriteStr(output_zip, "patch/boot.img.p", d)  
  8.   #  boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)  
  9.   #  script.PatchCheck("%s:%s:%d:%s:%d:%s" %  
  10.   #                    (boot_type, boot_device,  
  11.   #                     source_boot.size, source_boot.sha1,  
  12.   #                     target_boot.size, target_boot.sha1))  
  13.   #  so_far += source_boot.size  
  14.   #  script.SetProgress(so_far / total_verify_size)  
  15.     boot_img = common.GetBootableImage("boot.img""boot.img",  
  16.                                      OPTIONS.input_tmp, "BOOT")                                
  17.     common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)  
  18.     common.ZipWriteStr(output_zip, "boot.img", boot_img.data)  
  19.   
  20.   if updating_recovery:  
  21.     recovery_img = common.GetBootableImage("recovery.img""recovery.img",  
  22.                                      OPTIONS.input_tmp, "RECOVERY")                                
  23.     common.CheckSize(recovery_img.data, "recovery.img", OPTIONS.info_dict)  
  24.     common.ZipWriteStr(output_zip, "recovery.img", recovery_img.data)  

同理,如果要把boot.img全部烧录而不产生差分包。修改
[cpp] view plaincopyprint?
  1. #if updating_boot:  
  2.   #  total_patch_size += target_boot.size  
  3.     #script.ApplyPatch("%s:%s:%d:%s:%d:%s"  
  4.     #                  % (boot_type, boot_device,  
  5.     #                     source_boot.size, source_boot.sha1,  
  6.     #                     target_boot.size, target_boot.sha1),  
  7.     #                  "-",  
  8.     #                  target_boot.size, target_boot.sha1,  
  9.     #                  source_boot.sha1, "patch/boot.img.p")  
  10.     #so_far += target_boot.size  
  11.       
  12.     script.WriteRawImage("/boot""boot.img")  
  13.     #script.SetProgress(so_far / total_patch_size)  
  14.     # MakeRecoveryPatch(OPTIONS.target_tmp, output_zip,  
  15.     #                  target_recovery, target_boot)  
  16.     # script.DeleteFiles(["/system/recovery-from-boot.p",  
  17.     #                    "/system/etc/install-recovery.sh"])  
  18.     # print "recovery image changed; including as patch from boot."  
  19.     script.Print("Patching recovery image...")  
  20.     script.WriteRawImage("/recovery""recovery.img")  

0 0
原创粉丝点击