美文网首页
WriteIncrementalOTAPackage制作OTA包

WriteIncrementalOTAPackage制作OTA包

作者: 迷茫的天蝎 | 来源:发表于2017-01-04 10:37 被阅读0次
def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
  target_has_recovery_patch = HasRecoveryPatch(target_zip)  //检查目标文件包是否存在SYSTEM/recovery-from-boot.p
  source_has_recovery_patch = HasRecoveryPatch(source_zip)  //检查源文件包是否存在SYSTEM/recovery-from-boot.p

  if (OPTIONS.block_based and
      target_has_recovery_patch and
      source_has_recovery_patch):
    //如果传入参数指定了使用块模式制作OTA,则调用WriteBlockIncrementalOTAPackage进行制作
    return WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip)

  //获取源文件包和目标文件包的recovery_api_version
  source_version = OPTIONS.source_info_dict["recovery_api_version"]
  target_version = OPTIONS.target_info_dict["recovery_api_version"]

  //如果source_version等于0,则生成一个不能进行安装的updater-script脚本,这个脚本是由edify_generator模块生成的
  if source_version == 0:
    print ("WARNING: generating edify script for a source that "
           "can't install it.")
  script = edify_generator.EdifyGenerator(
      source_version, OPTIONS.target_info_dict,
      fstab=OPTIONS.source_info_dict["fstab"])

  oem_props = OPTIONS.info_dict.get("oem_fingerprint_properties")
  recovery_mount_options = OPTIONS.source_info_dict.get(
      "recovery_mount_options")
  oem_dict = None
  if oem_props is not None and len(oem_props) > 0:
    if OPTIONS.oem_source is None:
      raise common.ExternalError("OEM source required for this build")
    script.Mount("/oem", recovery_mount_options)
    oem_dict = common.LoadDictionaryFromLines(
        open(OPTIONS.oem_source).readlines())
  //创建一个元数据字典来存储一些相关的值
  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
  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.source_info_dict)
  //比较system分区的差异
  system_diff = FileDifference("system", source_zip, target_zip, output_zip)


FileDifference类的初始化函数

class FileDifference(object):
  def __init__(self, partition, source_zip, target_zip, output_zip):
    self.deferred_patch_list = None
    //读取目标文件包中system分区的文件,保存这些文件的信息
    print "Loading target..."
    self.target_data = target_data = LoadPartitionFiles(target_zip, partition)
    //读取源文件包中system分区的文件,保存这些文件的信息
    print "Loading source..."
    self.source_data = source_data = LoadPartitionFiles(source_zip, partition)

    self.verbatim_targets = verbatim_targets = []
    self.patch_list = patch_list = []
    diffs = []
    self.renames = renames = {}
    known_paths = set()
    largest_source_size = 0

    matching_file_cache = {}
    for fn, sf in source_data.items():
      assert fn == sf.name
      matching_file_cache["path:" + fn] = sf
      if fn in target_data.keys():
        AddToKnownPaths(fn, known_paths)
      # Only allow eligibility for filename/sha matching
      # if there isn't a perfect path match.
      if target_data.get(sf.name) is None:
        matching_file_cache["file:" + fn.split("/")[-1]] = sf
        matching_file_cache["sha:" + sf.sha1] = sf
    //比较源文件包和目标文件包的路径结构,找出经过重命名的文件
    for fn in sorted(target_data.keys()):
      tf = target_data[fn]
      assert fn == tf.name
      sf = ClosestFileMatch(tf, matching_file_cache, renames)
      if sf is not None and sf.name != tf.name:
        print "File has moved from " + sf.name + " to " + tf.name
        renames[sf.name] = tf

      if sf is None or fn in OPTIONS.require_verbatim:
        # This file should be included verbatim
        if fn in OPTIONS.prohibit_verbatim:
          raise common.ExternalError("\"%s\" must be sent verbatim" % (fn,))
        print "send", fn, "verbatim"
        tf.AddToZip(output_zip)
        verbatim_targets.append((fn, tf.size, tf.sha1))
        if fn in target_data.keys():
          AddToKnownPaths(fn, known_paths)
      elif tf.sha1 != sf.sha1:
        # File is different; consider sending as a patch
        diffs.append(common.Difference(tf, sf))      //将需要比较差异的文件保存起来
      else:
        # Target file data identical to source (may still be renamed)
        pass

    common.ComputeDifferences(diffs)

    for diff in diffs:
      tf, sf, d = diff.GetPatch()
      path = "/".join(tf.name.split("/")[:-1])
      if d is None or len(d) > tf.size * OPTIONS.patch_threshold or \
          path not in known_paths:
        # patch is almost as big as the file; don't bother patching
        # or a patch + rename cannot take place due to the target
        # directory not existing
        tf.AddToZip(output_zip)
        verbatim_targets.append((tf.name, tf.size, tf.sha1))
        if sf.name in renames:
          del renames[sf.name]
        AddToKnownPaths(tf.name, known_paths)
      else:
        common.ZipWriteStr(output_zip, "patch/" + sf.name + ".p", d)
        patch_list.append((tf, sf, tf.size, common.sha1(d).hexdigest()))
        largest_source_size = max(largest_source_size, sf.size)

    self.largest_source_size = largest_source_size

相关文章

  • WriteIncrementalOTAPackage制作OTA包

    FileDifference类的初始化函数

  • device ota 升级

    制作ota 包,请参考:ota包的制作 目的是device 获取ota package 能进行升级,本文主要介绍从...

  • Android下制作OTA包及验证

    当我们拿到一份Android源码后,要如何制作OTA升级包(实质上是Recovery升级的ZIP包,OTA升级是基...

  • OTA制作

    OTA的制作流程是从ota_from_target_files开始的,ota_from_target_files模...

  • OTA线刷以及增量升级

    安卓官方OTA文档 一、制作OTA全量包 该文章的基础建立在已经搭建好aosp环境的基础上,未搭建好的可以看AOS...

  • ota 原理流程

    本文主要介绍基本原理,源码,制作ota 1 ota 基本原理 OTA(Over-the-Air Technolog...

  • OTA编译脚本

    OTA包编译脚本位于build/tools/releasetools/ota_from_target_files,...

  • 制作OTA包时遇到Python脚本报错

    昨天在制作OTA包时,遇到Python脚本提示如下错误: 根据错误提示定位到具体的脚本发现,Python脚本第13...

  • Android带AB分区的本地升级

    升级包文件组成 编译出来的ota升级包是个zip包: merged-xxxx-ota.zip 解压后,目录结构如下...

  • Android7.1.2系统OTA升级

    本文介绍的是Android系统OTA升级,主要介绍升级包的制作和Android代码中如何实现系统的升级。文章中的升...

网友评论

      本文标题:WriteIncrementalOTAPackage制作OTA包

      本文链接:https://www.haomeiwen.com/subject/ortspttx.html