Merge "releasetools: Only verify the blocks to be touched." into nyc-dev

This commit is contained in:
Tao Bao 2016-04-13 23:59:36 +00:00 committed by Android (Google) Code Review
commit 21528c5e05
3 changed files with 26 additions and 6 deletions

View file

@ -272,6 +272,8 @@ class BlockImageDiff(object):
self.src_basenames = {}
self.src_numpatterns = {}
self._max_stashed_size = 0
self.touched_src_ranges = RangeSet()
self.touched_src_sha1 = None
assert version in (1, 2, 3, 4)
@ -373,6 +375,7 @@ class BlockImageDiff(object):
else:
stashes[sh] = 1
stashed_blocks += sr.size()
self.touched_src_ranges = self.touched_src_ranges.union(sr)
out.append("stash %s %s\n" % (sh, sr.to_string_raw()))
if stashed_blocks > max_stashed_blocks:
@ -479,6 +482,9 @@ class BlockImageDiff(object):
if temp_stash_usage > max_stashed_blocks:
max_stashed_blocks = temp_stash_usage
self.touched_src_ranges = self.touched_src_ranges.union(
xf.src_ranges)
out.append("%s %s %s %s\n" % (
xf.style,
self.HashBlocks(self.tgt, xf.tgt_ranges),
@ -502,6 +508,9 @@ class BlockImageDiff(object):
if temp_stash_usage > max_stashed_blocks:
max_stashed_blocks = temp_stash_usage
self.touched_src_ranges = self.touched_src_ranges.union(
xf.src_ranges)
out.append("%s %d %d %s %s %s %s\n" % (
xf.style,
xf.patch_start, xf.patch_len,
@ -537,6 +546,10 @@ class BlockImageDiff(object):
self.tgt.blocksize, max_allowed, cache_size,
stash_threshold)
if self.version >= 3:
self.touched_src_sha1 = self.HashBlocks(
self.src, self.touched_src_ranges)
# Zero out extended blocks as a workaround for bug 20881595.
if self.tgt.extended:
out.append("zero %s\n" % (self.tgt.extended.to_string_raw(),))

View file

@ -1314,6 +1314,8 @@ class BlockDifference(object):
self.path = os.path.join(tmpdir, partition)
b.Compute(self.path)
self._required_cache = b.max_stashed_size
self.touched_src_ranges = b.touched_src_ranges
self.touched_src_sha1 = b.touched_src_sha1
if src is None:
_, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict)
@ -1357,26 +1359,31 @@ class BlockDifference(object):
self.device))
script.AppendExtra("")
def WriteVerifyScript(self, script):
def WriteVerifyScript(self, script, touched_blocks_only=False):
partition = self.partition
if not self.src:
script.Print("Image %s will be patched unconditionally." % (partition,))
else:
ranges = self.src.care_map.subtract(self.src.clobbered_blocks)
if touched_blocks_only and self.version >= 3:
ranges = self.touched_src_ranges
expected_sha1 = self.touched_src_sha1
else:
ranges = self.src.care_map.subtract(self.src.clobbered_blocks)
expected_sha1 = self.src.TotalSha1()
ranges_str = ranges.to_string_raw()
if self.version >= 4:
script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || '
'block_image_verify("%s", '
'package_extract_file("%s.transfer.list"), '
'"%s.new.dat", "%s.patch.dat")) then') % (
self.device, ranges_str, self.src.TotalSha1(),
self.device, ranges_str, expected_sha1,
self.device, partition, partition, partition))
elif self.version == 3:
script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || '
'block_image_verify("%s", '
'package_extract_file("%s.transfer.list"), '
'"%s.new.dat", "%s.patch.dat")) then') % (
self.device, ranges_str, self.src.TotalSha1(),
self.device, ranges_str, expected_sha1,
self.device, partition, partition, partition))
else:
script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % (

View file

@ -996,9 +996,9 @@ else
""" % bcb_dev)
# Verify the existing partitions.
system_diff.WriteVerifyScript(script)
system_diff.WriteVerifyScript(script, touched_blocks_only=True)
if vendor_diff:
vendor_diff.WriteVerifyScript(script)
vendor_diff.WriteVerifyScript(script, touched_blocks_only=True)
script.Comment("---- start making changes here ----")