am 708c4623: Merge "Add post-install verification for BBOTAs"

* commit '708c462311afd63592a3adcc0e47c0c850b73444':
  Add post-install verification for BBOTAs
This commit is contained in:
Tao Bao 2015-06-02 18:14:40 +00:00 committed by Android Git Automerger
commit 2e30a5e853
4 changed files with 36 additions and 9 deletions

View file

@ -74,7 +74,7 @@ class Image(object):
def ReadRangeSet(self, ranges): def ReadRangeSet(self, ranges):
raise NotImplementedError raise NotImplementedError
def TotalSha1(self): def TotalSha1(self, include_clobbered_blocks=False):
raise NotImplementedError raise NotImplementedError
@ -87,7 +87,10 @@ class EmptyImage(Image):
file_map = {} file_map = {}
def ReadRangeSet(self, ranges): def ReadRangeSet(self, ranges):
return () return ()
def TotalSha1(self): def TotalSha1(self, include_clobbered_blocks=False):
# EmptyImage always carries empty clobbered_blocks, so
# include_clobbered_blocks can be ignored.
assert self.clobbered_blocks.size() == 0
return sha1().hexdigest() return sha1().hexdigest()
@ -136,8 +139,9 @@ class DataImage(Image):
def ReadRangeSet(self, ranges): def ReadRangeSet(self, ranges):
return [self.data[s*self.blocksize:e*self.blocksize] for (s, e) in ranges] return [self.data[s*self.blocksize:e*self.blocksize] for (s, e) in ranges]
def TotalSha1(self): def TotalSha1(self, include_clobbered_blocks=False):
# DataImage always carries empty clobbered_blocks. # DataImage always carries empty clobbered_blocks, so
# include_clobbered_blocks can be ignored.
assert self.clobbered_blocks.size() == 0 assert self.clobbered_blocks.size() == 0
return sha1(self.data).hexdigest() return sha1(self.data).hexdigest()
@ -201,7 +205,8 @@ class Transfer(object):
# #
# TotalSha1(): a function that returns (as a hex string) the SHA-1 # TotalSha1(): a function that returns (as a hex string) the SHA-1
# hash of all the data in the image (ie, all the blocks in the # hash of all the data in the image (ie, all the blocks in the
# care_map minus clobbered_blocks). # care_map minus clobbered_blocks, or including the clobbered
# blocks if include_clobbered_blocks is True).
# #
# When creating a BlockImageDiff, the src image may be None, in which # When creating a BlockImageDiff, the src image may be None, in which
# case the list of transfers produced will never read from the # case the list of transfers produced will never read from the

View file

@ -1182,6 +1182,7 @@ class BlockDifference(object):
if progress: if progress:
script.ShowProgress(progress, 0) script.ShowProgress(progress, 0)
self._WriteUpdate(script, output_zip) self._WriteUpdate(script, output_zip)
self._WritePostInstallVerifyScript(script)
def WriteVerifyScript(self, script): def WriteVerifyScript(self, script):
partition = self.partition partition = self.partition
@ -1220,6 +1221,21 @@ class BlockDifference(object):
script.AppendExtra(('abort("%s partition has unexpected contents");\n' script.AppendExtra(('abort("%s partition has unexpected contents");\n'
'endif;') % (partition,)) 'endif;') % (partition,))
def _WritePostInstallVerifyScript(self, script):
partition = self.partition
script.Print('Verifying the updated %s image...' % (partition,))
# Unlike pre-install verification, clobbered_blocks should not be ignored.
ranges = self.tgt.care_map
ranges_str = ranges.to_string_raw()
script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % (
self.device, ranges_str,
self.tgt.TotalSha1(include_clobbered_blocks=True)))
script.Print('Verified the updated %s image.' % (partition,))
script.AppendExtra(
'else\n'
' abort("%s partition has unexpected contents after OTA update");\n'
'endif;' % (partition,))
def _WriteUpdate(self, script, output_zip): def _WriteUpdate(self, script, output_zip):
ZipWrite(output_zip, ZipWrite(output_zip,
'{}.transfer.list'.format(self.path), '{}.transfer.list'.format(self.path),

View file

@ -917,6 +917,7 @@ else
system_diff.WriteScript(script, output_zip, system_diff.WriteScript(script, output_zip,
progress=0.8 if vendor_diff else 0.9) progress=0.8 if vendor_diff else 0.9)
if vendor_diff: if vendor_diff:
vendor_diff.WriteScript(script, output_zip, progress=0.1) vendor_diff.WriteScript(script, output_zip, progress=0.1)

View file

@ -118,11 +118,16 @@ class SparseImage(object):
def ReadRangeSet(self, ranges): def ReadRangeSet(self, ranges):
return [d for d in self._GetRangeData(ranges)] return [d for d in self._GetRangeData(ranges)]
def TotalSha1(self): def TotalSha1(self, include_clobbered_blocks=False):
"""Return the SHA-1 hash of all data in the 'care' regions but not in """Return the SHA-1 hash of all data in the 'care' regions.
clobbered_blocks of this image."""
If include_clobbered_blocks is True, it returns the hash including the
clobbered_blocks."""
ranges = self.care_map
if not include_clobbered_blocks:
ranges.subtract(self.clobbered_blocks)
h = sha1() h = sha1()
for d in self._GetRangeData(self.care_map.subtract(self.clobbered_blocks)): for d in self._GetRangeData(ranges):
h.update(d) h.update(d)
return h.hexdigest() return h.hexdigest()