releasetools: Disable using imgdiff for squashfs.

We use imgdiff to handle files in zip format (e.g. jar/zip/apk) for
higher compression ratio.

For system/vendor in squashfs, a) all files are compressed in LZ4
format; b) we use 4096-byte block size in their sparse images, but the
files in squashfs may not be laid out as 4K-aligned. So the blocks for
a given file as listed in block map may not form a valid zip file, which
may fail the patch generation with imgdiff.

Disable using imgdiff for squashfs images, and use bsdiff instead.

Bug: 22322817
Change-Id: Ie76aa4cece5c9d38cb1d1a34c505a4a8f37512d3
(cherry picked from commit 293fd135c7)
This commit is contained in:
Tao Bao
2016-06-11 12:19:23 -07:00
parent 8a09095c34
commit b6568cd4be
3 changed files with 19 additions and 6 deletions

View File

@@ -261,7 +261,8 @@ class HeapItem(object):
# original image. # original image.
class BlockImageDiff(object): class BlockImageDiff(object):
def __init__(self, tgt, src=None, threads=None, version=4): def __init__(self, tgt, src=None, threads=None, version=4,
disable_imgdiff=False):
if threads is None: if threads is None:
threads = multiprocessing.cpu_count() // 2 threads = multiprocessing.cpu_count() // 2
if threads == 0: if threads == 0:
@@ -274,6 +275,7 @@ class BlockImageDiff(object):
self._max_stashed_size = 0 self._max_stashed_size = 0
self.touched_src_ranges = RangeSet() self.touched_src_ranges = RangeSet()
self.touched_src_sha1 = None self.touched_src_sha1 = None
self.disable_imgdiff = disable_imgdiff
assert version in (1, 2, 3, 4) assert version in (1, 2, 3, 4)
@@ -704,6 +706,7 @@ class BlockImageDiff(object):
# produces significantly smaller patches than bsdiff). # produces significantly smaller patches than bsdiff).
# This is permissible if: # This is permissible if:
# #
# - imgdiff is not disabled, and
# - the source and target files are monotonic (ie, the # - the source and target files are monotonic (ie, the
# data is stored with blocks in increasing order), and # data is stored with blocks in increasing order), and
# - we haven't removed any blocks from the source set. # - we haven't removed any blocks from the source set.
@@ -713,7 +716,7 @@ class BlockImageDiff(object):
# zip file (plus possibly extra zeros in the last block), # zip file (plus possibly extra zeros in the last block),
# which is what imgdiff needs to operate. (imgdiff is # which is what imgdiff needs to operate. (imgdiff is
# fine with extra zeros at the end of the file.) # fine with extra zeros at the end of the file.)
imgdiff = (xf.intact and imgdiff = (not self.disable_imgdiff and xf.intact and
xf.tgt_name.split(".")[-1].lower() xf.tgt_name.split(".")[-1].lower()
in ("apk", "jar", "zip")) in ("apk", "jar", "zip"))
xf.style = "imgdiff" if imgdiff else "bsdiff" xf.style = "imgdiff" if imgdiff else "bsdiff"

View File

@@ -1392,11 +1392,12 @@ def ComputeDifferences(diffs):
class BlockDifference(object): class BlockDifference(object):
def __init__(self, partition, tgt, src=None, check_first_block=False, def __init__(self, partition, tgt, src=None, check_first_block=False,
version=None): version=None, disable_imgdiff=False):
self.tgt = tgt self.tgt = tgt
self.src = src self.src = src
self.partition = partition self.partition = partition
self.check_first_block = check_first_block self.check_first_block = check_first_block
self.disable_imgdiff = disable_imgdiff
if version is None: if version is None:
version = 1 version = 1
@@ -1407,7 +1408,8 @@ class BlockDifference(object):
self.version = version self.version = version
b = blockimgdiff.BlockImageDiff(tgt, src, threads=OPTIONS.worker_threads, b = blockimgdiff.BlockImageDiff(tgt, src, threads=OPTIONS.worker_threads,
version=self.version) version=self.version,
disable_imgdiff=self.disable_imgdiff)
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
OPTIONS.tempfiles.append(tmpdir) OPTIONS.tempfiles.append(tmpdir)
self.path = os.path.join(tmpdir, partition) self.path = os.path.join(tmpdir, partition)

View File

@@ -866,9 +866,15 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
# disk type is ext4 # disk type is ext4
system_partition = OPTIONS.source_info_dict["fstab"]["/system"] system_partition = OPTIONS.source_info_dict["fstab"]["/system"]
check_first_block = system_partition.fs_type == "ext4" check_first_block = system_partition.fs_type == "ext4"
# Disable using imgdiff for squashfs. 'imgdiff -z' expects input files to be
# in zip formats. However with squashfs, a) all files are compressed in LZ4;
# b) the blocks listed in block map may not contain all the bytes for a given
# file (because they're rounded to be 4K-aligned).
disable_imgdiff = system_partition.fs_type == "squashfs"
system_diff = common.BlockDifference("system", system_tgt, system_src, system_diff = common.BlockDifference("system", system_tgt, system_src,
check_first_block, check_first_block,
version=blockimgdiff_version) version=blockimgdiff_version,
disable_imgdiff=disable_imgdiff)
if HasVendorPartition(target_zip): if HasVendorPartition(target_zip):
if not HasVendorPartition(source_zip): if not HasVendorPartition(source_zip):
@@ -882,9 +888,11 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
# disk type is ext4 # disk type is ext4
vendor_partition = OPTIONS.source_info_dict["fstab"]["/vendor"] vendor_partition = OPTIONS.source_info_dict["fstab"]["/vendor"]
check_first_block = vendor_partition.fs_type == "ext4" check_first_block = vendor_partition.fs_type == "ext4"
disable_imgdiff = vendor_partition.fs_type == "squashfs"
vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src, vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src,
check_first_block, check_first_block,
version=blockimgdiff_version) version=blockimgdiff_version,
disable_imgdiff=disable_imgdiff)
else: else:
vendor_diff = None vendor_diff = None