Merge "releasetools: Only verify the blocks to be touched."

This commit is contained in:
Treehugger Robot 2016-04-14 00:53:39 +00:00 committed by Gerrit Code Review
commit 08d2a64505
3 changed files with 26 additions and 6 deletions

View File

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

View File

@ -1425,6 +1425,8 @@ class BlockDifference(object):
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 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: if src is None:
_, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict) _, self.device = GetTypeAndDevice("/" + partition, OPTIONS.info_dict)
@ -1468,26 +1470,31 @@ class BlockDifference(object):
self.device)) self.device))
script.AppendExtra("") script.AppendExtra("")
def WriteVerifyScript(self, script): def WriteVerifyScript(self, script, touched_blocks_only=False):
partition = self.partition partition = self.partition
if not self.src: if not self.src:
script.Print("Image %s will be patched unconditionally." % (partition,)) script.Print("Image %s will be patched unconditionally." % (partition,))
else: 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() ranges_str = ranges.to_string_raw()
if self.version >= 4: if self.version >= 4:
script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || ' script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || '
'block_image_verify("%s", ' 'block_image_verify("%s", '
'package_extract_file("%s.transfer.list"), ' 'package_extract_file("%s.transfer.list"), '
'"%s.new.dat", "%s.patch.dat")) then') % ( '"%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)) self.device, partition, partition, partition))
elif self.version == 3: elif self.version == 3:
script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || ' script.AppendExtra(('if (range_sha1("%s", "%s") == "%s" || '
'block_image_verify("%s", ' 'block_image_verify("%s", '
'package_extract_file("%s.transfer.list"), ' 'package_extract_file("%s.transfer.list"), '
'"%s.new.dat", "%s.patch.dat")) then') % ( '"%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)) self.device, partition, partition, partition))
else: else:
script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % ( script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % (

View File

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