Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4cfca53 authored by Tao Bao's avatar Tao Bao
Browse files

releasetools: Add two new entries to metadata.

Add "ota-required-cache" into the metadata file in an OTA package,
which shows the minimum free space on /cache to apply the update.

Add "ota-type" into the metadata file, which shows the OTA type for
this package (i.e. one of FILE, BLOCK and AB).

Also add the cache free space check into updater-script when generating
block-based incremental OTAs (we only had such lines for file-based
incrementals before).

Bug: 26731903
Change-Id: Id6ff0fc4cdfb1443636b0b3800b0f8bddb5bb1d0
(cherry picked from commit d8d14bec)
parent ebadc3bd
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -271,6 +271,7 @@ class BlockImageDiff(object):
    self.transfers = []
    self.transfers = []
    self.src_basenames = {}
    self.src_basenames = {}
    self.src_numpatterns = {}
    self.src_numpatterns = {}
    self._max_stashed_size = 0


    assert version in (1, 2, 3, 4)
    assert version in (1, 2, 3, 4)


@@ -288,6 +289,10 @@ class BlockImageDiff(object):
    self.AssertPartition(src.care_map, src.file_map.values())
    self.AssertPartition(src.care_map, src.file_map.values())
    self.AssertPartition(tgt.care_map, tgt.file_map.values())
    self.AssertPartition(tgt.care_map, tgt.file_map.values())


  @property
  def max_stashed_size(self):
    return self._max_stashed_size

  def Compute(self, prefix):
  def Compute(self, prefix):
    # When looking for a source file to use as the diff input for a
    # When looking for a source file to use as the diff input for a
    # target file, we try:
    # target file, we try:
@@ -558,17 +563,17 @@ class BlockImageDiff(object):
        f.write(i)
        f.write(i)


    if self.version >= 2:
    if self.version >= 2:
      max_stashed_size = max_stashed_blocks * self.tgt.blocksize
      self._max_stashed_size = max_stashed_blocks * self.tgt.blocksize
      OPTIONS = common.OPTIONS
      OPTIONS = common.OPTIONS
      if OPTIONS.cache_size is not None:
      if OPTIONS.cache_size is not None:
        max_allowed = OPTIONS.cache_size * OPTIONS.stash_threshold
        max_allowed = OPTIONS.cache_size * OPTIONS.stash_threshold
        print("max stashed blocks: %d  (%d bytes), "
        print("max stashed blocks: %d  (%d bytes), "
              "limit: %d bytes (%.2f%%)\n" % (
              "limit: %d bytes (%.2f%%)\n" % (
              max_stashed_blocks, max_stashed_size, max_allowed,
              max_stashed_blocks, self._max_stashed_size, max_allowed,
              max_stashed_size * 100.0 / max_allowed))
              self._max_stashed_size * 100.0 / max_allowed))
      else:
      else:
        print("max stashed blocks: %d  (%d bytes), limit: <unknown>\n" % (
        print("max stashed blocks: %d  (%d bytes), limit: <unknown>\n" % (
              max_stashed_blocks, max_stashed_size))
              max_stashed_blocks, self._max_stashed_size))


  def ReviseStashSize(self):
  def ReviseStashSize(self):
    print("Revising stash size...")
    print("Revising stash size...")
+5 −1
Original line number Original line Diff line number Diff line
@@ -30,7 +30,6 @@ import time
import zipfile
import zipfile


import blockimgdiff
import blockimgdiff
import rangelib


from hashlib import sha1 as sha1
from hashlib import sha1 as sha1


@@ -1255,6 +1254,7 @@ class BlockDifference(object):
    OPTIONS.tempfiles.append(tmpdir)
    OPTIONS.tempfiles.append(tmpdir)
    self.path = os.path.join(tmpdir, partition)
    self.path = os.path.join(tmpdir, partition)
    b.Compute(self.path)
    b.Compute(self.path)
    self._required_cache = b.max_stashed_size


    if src is None:
    if src is None:
      _, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict)
      _, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict)
@@ -1262,6 +1262,10 @@ class BlockDifference(object):
      _, self.device = GetTypeAndDevice("/" + partition,
      _, self.device = GetTypeAndDevice("/" + partition,
                                        OPTIONS.source_info_dict)
                                        OPTIONS.source_info_dict)


  @property
  def required_cache(self):
    return self._required_cache

  def WriteScript(self, script, output_zip, progress=None):
  def WriteScript(self, script, output_zip, progress=None):
    if not self.src:
    if not self.src:
      # write the output unconditionally
      # write the output unconditionally
+7 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ class EdifyGenerator(object):
  def __init__(self, version, info, fstab=None):
  def __init__(self, version, info, fstab=None):
    self.script = []
    self.script = []
    self.mounts = set()
    self.mounts = set()
    self._required_cache = 0
    self.version = version
    self.version = version
    self.info = info
    self.info = info
    if fstab is None:
    if fstab is None:
@@ -38,6 +39,11 @@ class EdifyGenerator(object):
    x.mounts = self.mounts
    x.mounts = self.mounts
    return x
    return x


  @property
  def required_cache(self):
    """Return the minimum cache size to apply the update."""
    return self._required_cache

  @staticmethod
  @staticmethod
  def WordWrap(cmd, linelen=80):
  def WordWrap(cmd, linelen=80):
    """'cmd' should be a function call with null characters after each
    """'cmd' should be a function call with null characters after each
@@ -171,6 +177,7 @@ class EdifyGenerator(object):
  def CacheFreeSpaceCheck(self, amount):
  def CacheFreeSpaceCheck(self, amount):
    """Check that there's at least 'amount' space that can be made
    """Check that there's at least 'amount' space that can be made
    available on /cache."""
    available on /cache."""
    self._required_cache = max(self._required_cache, amount)
    self.script.append(('apply_patch_space(%d) || abort("Not enough free space '
    self.script.append(('apply_patch_space(%d) || abort("Not enough free space '
                        'on /cache to apply patches.");') % (amount,))
                        'on /cache to apply patches.");') % (amount,))


+33 −9
Original line number Original line Diff line number Diff line
@@ -542,6 +542,8 @@ def WriteFullOTAPackage(input_zip, output_zip):
  has_recovery_patch = HasRecoveryPatch(input_zip)
  has_recovery_patch = HasRecoveryPatch(input_zip)
  block_based = OPTIONS.block_based and has_recovery_patch
  block_based = OPTIONS.block_based and has_recovery_patch


  metadata["ota-type"] = "BLOCK" if block_based else "FILE"

  if not OPTIONS.omit_prereq:
  if not OPTIONS.omit_prereq:
    ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)
    ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)
    ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)
    ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)
@@ -697,6 +699,8 @@ endif;
endif;
endif;
""" % bcb_dev)
""" % bcb_dev)
  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)

  metadata["ota-required-cache"] = str(script.required_cache)
  WriteMetadata(metadata, output_zip)
  WriteMetadata(metadata, output_zip)




@@ -773,6 +777,7 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
                                   OPTIONS.source_info_dict),
                                   OPTIONS.source_info_dict),
      "post-timestamp": GetBuildProp("ro.build.date.utc",
      "post-timestamp": GetBuildProp("ro.build.date.utc",
                                     OPTIONS.target_info_dict),
                                     OPTIONS.target_info_dict),
      "ota-type": "BLOCK",
  }
  }


  device_specific = common.DeviceSpecificParams(
  device_specific = common.DeviceSpecificParams(
@@ -910,6 +915,13 @@ else if get_stage("%(bcb_dev)s") != "3/3" then
          GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
          GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
          GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
          GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))


  # Check the required cache size (i.e. stashed blocks).
  size = []
  if system_diff:
    size.append(system_diff.required_cache)
  if vendor_diff:
    size.append(vendor_diff.required_cache)

  if updating_boot:
  if updating_boot:
    boot_type, boot_device = common.GetTypeAndDevice(
    boot_type, boot_device = common.GetTypeAndDevice(
        "/boot", OPTIONS.source_info_dict)
        "/boot", OPTIONS.source_info_dict)
@@ -930,6 +942,10 @@ else if get_stage("%(bcb_dev)s") != "3/3" then
                        (boot_type, boot_device,
                        (boot_type, boot_device,
                         source_boot.size, source_boot.sha1,
                         source_boot.size, source_boot.sha1,
                         target_boot.size, target_boot.sha1))
                         target_boot.size, target_boot.sha1))
      size.append(target_boot.size)

  if size:
    script.CacheFreeSpaceCheck(max(size))


  device_specific.IncrementalOTA_VerifyEnd()
  device_specific.IncrementalOTA_VerifyEnd()


@@ -1003,6 +1019,7 @@ endif;


  script.SetProgress(1)
  script.SetProgress(1)
  script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)
  script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)
  metadata["ota-required-cache"] = str(script.required_cache)
  WriteMetadata(metadata, output_zip)
  WriteMetadata(metadata, output_zip)




@@ -1076,6 +1093,7 @@ def WriteVerifyPackage(input_zip, output_zip):


  script.SetProgress(1.0)
  script.SetProgress(1.0)
  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
  metadata["ota-required-cache"] = str(script.required_cache)
  WriteMetadata(metadata, output_zip)
  WriteMetadata(metadata, output_zip)




@@ -1119,6 +1137,8 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file,
      "pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
      "pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
                                   OPTIONS.info_dict),
                                   OPTIONS.info_dict),
      "post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.info_dict),
      "post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.info_dict),
      "ota-required-cache": "0",
      "ota-type": "AB",
  }
  }


  if source_file is not None:
  if source_file is not None:
@@ -1374,6 +1394,7 @@ def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
                                   OPTIONS.source_info_dict),
                                   OPTIONS.source_info_dict),
      "post-timestamp": GetBuildProp("ro.build.date.utc",
      "post-timestamp": GetBuildProp("ro.build.date.utc",
                                     OPTIONS.target_info_dict),
                                     OPTIONS.target_info_dict),
      "ota-type": "FILE",
  }
  }


  device_specific = common.DeviceSpecificParams(
  device_specific = common.DeviceSpecificParams(
@@ -1487,6 +1508,13 @@ else if get_stage("%(bcb_dev)s") != "3/3" then
  if vendor_diff:
  if vendor_diff:
    so_far += vendor_diff.EmitVerification(script)
    so_far += vendor_diff.EmitVerification(script)


  size = []
  if system_diff.patch_list:
    size.append(system_diff.largest_source_size)
  if vendor_diff:
    if vendor_diff.patch_list:
      size.append(vendor_diff.largest_source_size)

  if updating_boot:
  if updating_boot:
    d = common.Difference(target_boot, source_boot)
    d = common.Difference(target_boot, source_boot)
    _, _, d = d.ComputePatch()
    _, _, d = d.ComputePatch()
@@ -1503,14 +1531,9 @@ else if get_stage("%(bcb_dev)s") != "3/3" then
                       source_boot.size, source_boot.sha1,
                       source_boot.size, source_boot.sha1,
                       target_boot.size, target_boot.sha1))
                       target_boot.size, target_boot.sha1))
    so_far += source_boot.size
    so_far += source_boot.size
    size.append(target_boot.size)


  size = []
  if size:
  if system_diff.patch_list:
    size.append(system_diff.largest_source_size)
  if vendor_diff:
    if vendor_diff.patch_list:
      size.append(vendor_diff.largest_source_size)
  if size or updating_recovery or updating_boot:
    script.CacheFreeSpaceCheck(max(size))
    script.CacheFreeSpaceCheck(max(size))


  device_specific.IncrementalOTA_VerifyEnd()
  device_specific.IncrementalOTA_VerifyEnd()
@@ -1723,6 +1746,7 @@ endif;
    vendor_diff.EmitExplicitTargetVerification(script)
    vendor_diff.EmitExplicitTargetVerification(script)
  script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)
  script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)


  metadata["ota-required-cache"] = str(script.required_cache)
  WriteMetadata(metadata, output_zip)
  WriteMetadata(metadata, output_zip)