summaryrefslogtreecommitdiffstats
path: root/tools/releasetools/common.py
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-03-12 12:32:37 -0700
committerTao Bao <tbao@google.com>2015-03-12 13:47:04 -0700
commitdaebaa6ed3fbf4e7943e6c8290ec6b9233b542e9 (patch)
tree0caf7040e82af7f40c5d79e195f5dfff24eaea7b /tools/releasetools/common.py
parent3c242c5ddb8b867b916875c8e05c260a9d8571b6 (diff)
downloadbuild-daebaa6ed3fbf4e7943e6c8290ec6b9233b542e9.zip
build-daebaa6ed3fbf4e7943e6c8290ec6b9233b542e9.tar.gz
build-daebaa6ed3fbf4e7943e6c8290ec6b9233b542e9.tar.bz2
Restrict the verification in block-based incremental OTAs
BlockImageDiff has three versions. Only the incremental OTAs generated with the latest version (3) can be re-applied to the system that's already on the target build. Otherwise, operations like move will make unconditional changes and damage the system. During the verification phase, abort the OTA update if BlockImageDiff is less than 3 and it doesn't match the checksum of the source build. Change-Id: I3a776495b69e1d174fcb01b10e40c0e912914fd8
Diffstat (limited to 'tools/releasetools/common.py')
-rw-r--r--tools/releasetools/common.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 8941f89..a596c26 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -1024,20 +1024,22 @@ def ComputeDifferences(diffs):
class BlockDifference:
- def __init__(self, partition, tgt, src=None, check_first_block=False):
+ def __init__(self, partition, tgt, src=None, check_first_block=False, version=None):
self.tgt = tgt
self.src = src
self.partition = partition
self.check_first_block = check_first_block
- version = 1
- if OPTIONS.info_dict:
- version = max(
- int(i) for i in
- OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+ if version is None:
+ version = 1
+ if OPTIONS.info_dict:
+ version = max(
+ int(i) for i in
+ OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+ self.version = version
b = blockimgdiff.BlockImageDiff(tgt, src, threads=OPTIONS.worker_threads,
- version=version)
+ version=self.version)
tmpdir = tempfile.mkdtemp()
OPTIONS.tempfiles.append(tmpdir)
self.path = os.path.join(tmpdir, partition)
@@ -1066,12 +1068,19 @@ class BlockDifference:
(self.device, self.src.care_map.to_string_raw(),
self.src.TotalSha1()))
script.Print("Verified %s image..." % (self.partition,))
- script.AppendExtra(('else\n'
- ' (range_sha1("%s", "%s") == "%s") ||\n'
- ' abort("%s partition has unexpected contents");\n'
- 'endif;') %
- (self.device, self.tgt.care_map.to_string_raw(),
- self.tgt.TotalSha1(), self.partition))
+ # Abort the OTA update if it doesn't support resumable OTA (i.e. version<3)
+ # and the checksum doesn't match the one in the source partition.
+ if self.version < 3:
+ script.AppendExtra(('else\n'
+ ' abort("%s partition has unexpected contents");\n'
+ 'endif;') % (self.partition))
+ else:
+ script.AppendExtra(('else\n'
+ ' (range_sha1("%s", "%s") == "%s") ||\n'
+ ' abort("%s partition has unexpected contents");\n'
+ 'endif;') %
+ (self.device, self.tgt.care_map.to_string_raw(),
+ self.tgt.TotalSha1(), self.partition))
def _WriteUpdate(self, script, output_zip):
partition = self.partition