diff options
author | Tao Bao <tbao@google.com> | 2016-02-04 14:26:02 -0800 |
---|---|---|
committer | Tao Bao <tbao@google.com> | 2016-02-08 11:00:27 -0800 |
commit | d8d14bec0d9fb604060634729b4a09c7898d0c9a (patch) | |
tree | 522198b62da99c8e1a133e154864b1929fbd0880 | |
parent | db82f72752532bf2b98103171b3d7cd8405b88e4 (diff) | |
download | build-d8d14bec0d9fb604060634729b4a09c7898d0c9a.tar.gz |
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
-rw-r--r-- | tools/releasetools/blockimgdiff.py | 13 | ||||
-rw-r--r-- | tools/releasetools/common.py | 6 | ||||
-rw-r--r-- | tools/releasetools/edify_generator.py | 7 | ||||
-rwxr-xr-x | tools/releasetools/ota_from_target_files.py | 42 |
4 files changed, 54 insertions, 14 deletions
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py index 1d338eebc3..bf6a57d365 100644 --- a/tools/releasetools/blockimgdiff.py +++ b/tools/releasetools/blockimgdiff.py @@ -251,6 +251,7 @@ class BlockImageDiff(object): self.transfers = [] self.src_basenames = {} self.src_numpatterns = {} + self._max_stashed_size = 0 assert version in (1, 2, 3, 4) @@ -268,6 +269,10 @@ class BlockImageDiff(object): self.AssertPartition(src.care_map, src.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): # When looking for a source file to use as the diff input for a # target file, we try: @@ -538,17 +543,17 @@ class BlockImageDiff(object): f.write(i) 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 if OPTIONS.cache_size is not None: max_allowed = OPTIONS.cache_size * OPTIONS.stash_threshold print("max stashed blocks: %d (%d bytes), " "limit: %d bytes (%.2f%%)\n" % ( - max_stashed_blocks, max_stashed_size, max_allowed, - max_stashed_size * 100.0 / max_allowed)) + max_stashed_blocks, self._max_stashed_size, max_allowed, + self._max_stashed_size * 100.0 / max_allowed)) else: 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): print("Revising stash size...") diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 95aeb62687..403c67da06 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -30,7 +30,6 @@ import time import zipfile import blockimgdiff -import rangelib from hashlib import sha1 as sha1 @@ -1255,6 +1254,7 @@ class BlockDifference(object): OPTIONS.tempfiles.append(tmpdir) self.path = os.path.join(tmpdir, partition) b.Compute(self.path) + self._required_cache = b.max_stashed_size if src is None: _, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict) @@ -1262,6 +1262,10 @@ class BlockDifference(object): _, self.device = GetTypeAndDevice("/" + partition, OPTIONS.source_info_dict) + @property + def required_cache(self): + return self._required_cache + def WriteScript(self, script, output_zip, progress=None): if not self.src: # write the output unconditionally diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py index d923cc813d..f57360a849 100644 --- a/tools/releasetools/edify_generator.py +++ b/tools/releasetools/edify_generator.py @@ -23,6 +23,7 @@ class EdifyGenerator(object): def __init__(self, version, info, fstab=None): self.script = [] self.mounts = set() + self._required_cache = 0 self.version = version self.info = info if fstab is None: @@ -38,6 +39,11 @@ class EdifyGenerator(object): x.mounts = self.mounts return x + @property + def required_cache(self): + """Return the minimum cache size to apply the update.""" + return self._required_cache + @staticmethod def WordWrap(cmd, linelen=80): """'cmd' should be a function call with null characters after each @@ -171,6 +177,7 @@ class EdifyGenerator(object): def CacheFreeSpaceCheck(self, amount): """Check that there's at least 'amount' space that can be made available on /cache.""" + self._required_cache = max(self._required_cache, amount) self.script.append(('apply_patch_space(%d) || abort("Not enough free space ' 'on /cache to apply patches.");') % (amount,)) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index ed300a7c74..bea33a3916 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -542,6 +542,8 @@ def WriteFullOTAPackage(input_zip, output_zip): has_recovery_patch = HasRecoveryPatch(input_zip) block_based = OPTIONS.block_based and has_recovery_patch + metadata["ota-type"] = "BLOCK" if block_based else "FILE" + if not OPTIONS.omit_prereq: ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict) ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict) @@ -697,6 +699,8 @@ endif; endif; """ % bcb_dev) script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary) + + metadata["ota-required-cache"] = str(script.required_cache) WriteMetadata(metadata, output_zip) @@ -773,6 +777,7 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip): OPTIONS.source_info_dict), "post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.target_info_dict), + "ota-type": "BLOCK", } device_specific = common.DeviceSpecificParams( @@ -815,7 +820,7 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip): # Check first block of system partition for remount R/W only if # disk type is ext4 system_partition = OPTIONS.source_info_dict["fstab"]["/system"] - check_first_block = system_partition.fs_type=="ext4" + check_first_block = system_partition.fs_type == "ext4" system_diff = common.BlockDifference("system", system_tgt, system_src, check_first_block, version=blockimgdiff_version) @@ -831,7 +836,7 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip): # Check first block of vendor partition for remount R/W only if # disk type is ext4 vendor_partition = OPTIONS.source_info_dict["fstab"]["/vendor"] - check_first_block = vendor_partition.fs_type=="ext4" + check_first_block = vendor_partition.fs_type == "ext4" vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src, check_first_block, version=blockimgdiff_version) @@ -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.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: boot_type, boot_device = common.GetTypeAndDevice( "/boot", OPTIONS.source_info_dict) @@ -930,6 +942,10 @@ else if get_stage("%(bcb_dev)s") != "3/3" then (boot_type, boot_device, source_boot.size, source_boot.sha1, target_boot.size, target_boot.sha1)) + size.append(target_boot.size) + + if size: + script.CacheFreeSpaceCheck(max(size)) device_specific.IncrementalOTA_VerifyEnd() @@ -1003,6 +1019,7 @@ endif; script.SetProgress(1) script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary) + metadata["ota-required-cache"] = str(script.required_cache) WriteMetadata(metadata, output_zip) @@ -1076,6 +1093,7 @@ def WriteVerifyPackage(input_zip, output_zip): script.SetProgress(1.0) script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary) + metadata["ota-required-cache"] = str(script.required_cache) WriteMetadata(metadata, output_zip) @@ -1119,6 +1137,8 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file, "pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict, 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: @@ -1374,6 +1394,7 @@ def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip): OPTIONS.source_info_dict), "post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.target_info_dict), + "ota-type": "FILE", } device_specific = common.DeviceSpecificParams( @@ -1487,6 +1508,13 @@ else if get_stage("%(bcb_dev)s") != "3/3" then if vendor_diff: 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: d = common.Difference(target_boot, source_boot) _, _, d = d.ComputePatch() @@ -1503,14 +1531,9 @@ else if get_stage("%(bcb_dev)s") != "3/3" then source_boot.size, source_boot.sha1, target_boot.size, target_boot.sha1)) so_far += source_boot.size + size.append(target_boot.size) - 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: + if size: script.CacheFreeSpaceCheck(max(size)) device_specific.IncrementalOTA_VerifyEnd() @@ -1723,6 +1746,7 @@ endif; vendor_diff.EmitExplicitTargetVerification(script) script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary) + metadata["ota-required-cache"] = str(script.required_cache) WriteMetadata(metadata, output_zip) |