releasetools: Fix the size check for AVB images.

When generating full OTAs for AVB-enabled targets, it fails the size
assertion for boot.img.

  ERROR: boot size (31457280) is 100.00% of limit (31457280)

The size assumption is no longer true for AVB-signed images, because
the actual image size should be always identical to the limit.

Bug: 67841177
Test: Enable AVB on bullhead. `m dist`.
Change-Id: I9bd432ccd88094628eb71308554839549eccb6d9
This commit is contained in:
Tao Bao
2017-11-14 11:27:32 -08:00
parent 5d60cd2d3e
commit 9dd909e6db

View File

@@ -75,6 +75,11 @@ OPTIONS = Options()
# Values for "certificate" in apkcerts that mean special things. # Values for "certificate" in apkcerts that mean special things.
SPECIAL_CERT_STRINGS = ("PRESIGNED", "EXTERNAL") SPECIAL_CERT_STRINGS = ("PRESIGNED", "EXTERNAL")
# The partitions allowed to be signed by AVB (Android verified boot 2.0).
AVB_PARTITIONS = ('boot', 'recovery', 'system', 'vendor', 'dtbo')
class ErrorCode(object): class ErrorCode(object):
"""Define error_codes for failures that happen during the actual """Define error_codes for failures that happen during the actual
update package installation. update package installation.
@@ -727,10 +732,18 @@ def SignFile(input_name, output_name, key, password, min_api_level=None,
def CheckSize(data, target, info_dict): def CheckSize(data, target, info_dict):
"""Check the data string passed against the max size limit, if """Checks the data string passed against the max size limit.
any, for the given target. Raise exception if the data is too big.
Print a warning if the data is nearing the maximum size."""
For non-AVB images, raise exception if the data is too big. Print a warning
if the data is nearing the maximum size.
For AVB images, the actual image size should be identical to the limit.
Args:
data: A string that contains all the data for the partition.
target: The partition name. The ".img" suffix is optional.
info_dict: The dict to be looked up for relevant info.
"""
if target.endswith(".img"): if target.endswith(".img"):
target = target[:-4] target = target[:-4]
mount_point = "/" + target mount_point = "/" + target
@@ -750,14 +763,22 @@ def CheckSize(data, target, info_dict):
return return
size = len(data) size = len(data)
pct = float(size) * 100.0 / limit # target could be 'userdata' or 'cache'. They should follow the non-AVB image
msg = "%s size (%d) is %.2f%% of limit (%d)" % (target, size, pct, limit) # path.
if pct >= 99.0: if info_dict.get("avb_enable") == "true" and target in AVB_PARTITIONS:
raise ExternalError(msg) if size != limit:
elif pct >= 95.0: raise ExternalError(
print("\n WARNING: %s\n" % (msg,)) "Mismatching image size for %s: expected %d actual %d" % (
elif OPTIONS.verbose: target, limit, size))
print(" ", msg) else:
pct = float(size) * 100.0 / limit
msg = "%s size (%d) is %.2f%% of limit (%d)" % (target, size, pct, limit)
if pct >= 99.0:
raise ExternalError(msg)
elif pct >= 95.0:
print("\n WARNING: %s\n" % (msg,))
elif OPTIONS.verbose:
print(" ", msg)
def ReadApkCerts(tf_zip): def ReadApkCerts(tf_zip):