OSDN Git Service

explicitly check the superblock for differences
authorDoug Zongker <dougz@google.com>
Thu, 11 Sep 2014 16:34:56 +0000 (09:34 -0700)
committerDoug Zongker <dougz@google.com>
Thu, 11 Sep 2014 16:52:04 +0000 (09:52 -0700)
When generating incrementals for the system and vendor partitions,
check the first block (which contains the superblock) of the partition
to see if it's what we expect.  If this check fails, give an explicit
log message about the partition having been remounted R/W (the most
likely explanation) and the need to flash to get OTAs working again.

Bug: 17393999
Change-Id: I2093807cbc2ec87c8b29ac46365f91f59b15c2ae

tools/releasetools/common.py
tools/releasetools/ota_from_target_files

index 2f62630..96075a9 100644 (file)
@@ -30,6 +30,7 @@ import time
 import zipfile
 
 import blockimgdiff
+from rangelib import *
 
 try:
   from hashlib import sha1 as sha1
@@ -1023,10 +1024,11 @@ def ComputeDifferences(diffs):
 
 
 class BlockDifference:
-  def __init__(self, partition, tgt, src=None):
+  def __init__(self, partition, tgt, src=None, check_first_block=False):
     self.tgt = tgt
     self.src = src
     self.partition = partition
+    self.check_first_block = check_first_block
 
     version = 1
     if OPTIONS.info_dict:
@@ -1050,6 +1052,9 @@ class BlockDifference:
       self._WriteUpdate(script, output_zip)
 
     else:
+      if self.check_first_block:
+        self._CheckFirstBlock(script)
+
       script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' %
                          (self.device, self.src.care_map.to_string_raw(),
                           self.src.TotalSha1()))
@@ -1079,6 +1084,18 @@ class BlockDifference:
             (self.device, partition, partition, partition))
     script.AppendExtra(script._WordWrap(call))
 
+  def _CheckFirstBlock(self, script):
+    r = RangeSet((0, 1))
+    h = sha1()
+    for data in self.src.ReadRangeSet(r):
+      h.update(data)
+    h = h.hexdigest()
+
+    script.AppendExtra(('(range_sha1("%s", "%s") == "%s") || '
+                        'abort("%s has been remounted R/W; '
+                        'reflash device to reenable OTA updates");')
+                       % (self.device, r.to_string_raw(), h, self.device))
+
 
 DataImage = blockimgdiff.DataImage
 
index 8b7342b..6f34450 100755 (executable)
@@ -731,14 +731,16 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
 
   system_src = GetImage("system", OPTIONS.source_tmp, OPTIONS.source_info_dict)
   system_tgt = GetImage("system", OPTIONS.target_tmp, OPTIONS.target_info_dict)
-  system_diff = common.BlockDifference("system", system_tgt, system_src)
+  system_diff = common.BlockDifference("system", system_tgt, system_src,
+                                       check_first_block=True)
 
   if HasVendorPartition(target_zip):
     if not HasVendorPartition(source_zip):
       raise RuntimeError("can't generate incremental that adds /vendor")
     vendor_src = GetImage("vendor", OPTIONS.source_tmp, OPTIONS.source_info_dict)
     vendor_tgt = GetImage("vendor", OPTIONS.target_tmp, OPTIONS.target_info_dict)
-    vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src)
+    vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src,
+                                         check_first_block=True)
   else:
     vendor_diff = None