Merge "releasetools: Clean up the use of partition_size."

This commit is contained in:
Tao Bao
2018-10-01 04:22:05 +00:00
committed by Gerrit Code Review
4 changed files with 52 additions and 63 deletions

View File

@@ -112,12 +112,12 @@ def GetCareMap(which, imgname):
simg = sparse_img.SparseImage(imgname) simg = sparse_img.SparseImage(imgname)
care_map_ranges = simg.care_map care_map_ranges = simg.care_map
key = which + "_adjusted_partition_size" key = which + "_image_blocks"
adjusted_blocks = OPTIONS.info_dict.get(key) image_blocks = OPTIONS.info_dict.get(key)
if adjusted_blocks: if image_blocks:
assert adjusted_blocks > 0, "blocks should be positive for " + which assert image_blocks > 0, "blocks for {} must be positive".format(which)
care_map_ranges = care_map_ranges.intersect(rangelib.RangeSet( care_map_ranges = care_map_ranges.intersect(
"0-%d" % (adjusted_blocks,))) rangelib.RangeSet("0-{}".format(image_blocks)))
return [which, care_map_ranges.to_string_raw()] return [which, care_map_ranges.to_string_raw()]
@@ -316,18 +316,18 @@ def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
if block_list: if block_list:
block_list.Write() block_list.Write()
# Set the 'adjusted_partition_size' that excludes the verity blocks of the # Set the '_image_blocks' that excludes the verity metadata blocks of the
# given image. When avb is enabled, this size is the max image size returned # given image. When AVB is enabled, this size is the max image size returned
# by the avb tool. # by the AVB tool.
is_verity_partition = "verity_block_device" in image_props is_verity_partition = "verity_block_device" in image_props
verity_supported = (image_props.get("verity") == "true" or verity_supported = (image_props.get("verity") == "true" or
image_props.get("avb_enable") == "true") image_props.get("avb_enable") == "true")
is_avb_enable = image_props.get("avb_hashtree_enable") == "true" is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
if verity_supported and (is_verity_partition or is_avb_enable): if verity_supported and (is_verity_partition or is_avb_enable):
adjusted_blocks_value = image_props.get("partition_size") image_size = image_props.get("image_size")
if adjusted_blocks_value: if image_size:
adjusted_blocks_key = what + "_adjusted_partition_size" image_blocks_key = what + "_image_blocks"
info_dict[adjusted_blocks_key] = int(adjusted_blocks_value)/4096 - 1 info_dict[image_blocks_key] = int(image_size) / 4096 - 1
def AddUserdata(output_zip): def AddUserdata(output_zip):

View File

@@ -373,7 +373,7 @@ def MakeVerityEnabledImage(out_file, fec_supported, prop_dict):
True on success, False otherwise. True on success, False otherwise.
""" """
# get properties # get properties
image_size = int(prop_dict["partition_size"]) image_size = int(prop_dict["image_size"])
block_dev = prop_dict["verity_block_device"] block_dev = prop_dict["verity_block_device"]
signer_key = prop_dict["verity_key"] + ".pk8" signer_key = prop_dict["verity_key"] + ".pk8"
if OPTIONS.verity_signer_path is not None: if OPTIONS.verity_signer_path is not None:
@@ -404,10 +404,10 @@ def MakeVerityEnabledImage(out_file, fec_supported, prop_dict):
return False return False
# build the full verified image # build the full verified image
target_size = int(prop_dict["original_partition_size"]) partition_size = int(prop_dict["partition_size"])
verity_size = int(prop_dict["verity_size"]) verity_size = int(prop_dict["verity_size"])
padding_size = target_size - image_size - verity_size padding_size = partition_size - image_size - verity_size
assert padding_size >= 0 assert padding_size >= 0
if not BuildVerifiedImage(out_file, if not BuildVerifiedImage(out_file,
@@ -564,25 +564,25 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if OPTIONS.verbose: if OPTIONS.verbose:
print("Allocating %d MB for %s." % (size // BYTES_IN_MB, out_file)) print("Allocating %d MB for %s." % (size // BYTES_IN_MB, out_file))
# Adjust the partition size to make room for the hashes if this is to be prop_dict["image_size"] = prop_dict["partition_size"]
# verified.
# Adjust the image size to make room for the hashes if this is to be verified.
if verity_supported and is_verity_partition: if verity_supported and is_verity_partition:
partition_size = int(prop_dict.get("partition_size")) partition_size = int(prop_dict.get("partition_size"))
(adjusted_size, verity_size) = AdjustPartitionSizeForVerity( image_size, verity_size = AdjustPartitionSizeForVerity(
partition_size, verity_fec_supported) partition_size, verity_fec_supported)
if not adjusted_size: if not image_size:
return False return False
prop_dict["partition_size"] = str(adjusted_size) prop_dict["image_size"] = str(image_size)
prop_dict["original_partition_size"] = str(partition_size)
prop_dict["verity_size"] = str(verity_size) prop_dict["verity_size"] = str(verity_size)
# Adjust partition size for AVB hash footer or AVB hashtree footer.
avb_footer_type = '' avb_footer_type = ''
if prop_dict.get("avb_hash_enable") == "true": if prop_dict.get("avb_hash_enable") == "true":
avb_footer_type = 'hash' avb_footer_type = 'hash'
elif prop_dict.get("avb_hashtree_enable") == "true": elif prop_dict.get("avb_hashtree_enable") == "true":
avb_footer_type = 'hashtree' avb_footer_type = 'hashtree'
# Adjust the image size for AVB hash footer or AVB hashtree footer.
if avb_footer_type: if avb_footer_type:
avbtool = prop_dict["avb_avbtool"] avbtool = prop_dict["avb_avbtool"]
partition_size = prop_dict["partition_size"] partition_size = prop_dict["partition_size"]
@@ -593,8 +593,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if max_image_size <= 0: if max_image_size <= 0:
print("AVBCalcMaxImageSize is <= 0: %d" % max_image_size) print("AVBCalcMaxImageSize is <= 0: %d" % max_image_size)
return False return False
prop_dict["partition_size"] = str(max_image_size) prop_dict["image_size"] = str(max_image_size)
prop_dict["original_partition_size"] = partition_size
if fs_type.startswith("ext"): if fs_type.startswith("ext"):
build_command = [prop_dict["ext_mkuserimg"]] build_command = [prop_dict["ext_mkuserimg"]]
@@ -603,7 +602,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
run_e2fsck = True run_e2fsck = True
build_command.extend([in_dir, out_file, fs_type, build_command.extend([in_dir, out_file, fs_type,
prop_dict["mount_point"]]) prop_dict["mount_point"]])
build_command.append(prop_dict["partition_size"]) build_command.append(prop_dict["image_size"])
if "journal_size" in prop_dict: if "journal_size" in prop_dict:
build_command.extend(["-j", prop_dict["journal_size"]]) build_command.extend(["-j", prop_dict["journal_size"]])
if "timestamp" in prop_dict: if "timestamp" in prop_dict:
@@ -662,7 +661,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
build_command.extend(["-a"]) build_command.extend(["-a"])
elif fs_type.startswith("f2fs"): elif fs_type.startswith("f2fs"):
build_command = ["mkf2fsuserimg.sh"] build_command = ["mkf2fsuserimg.sh"]
build_command.extend([out_file, prop_dict["partition_size"]]) build_command.extend([out_file, prop_dict["image_size"]])
if fs_config: if fs_config:
build_command.extend(["-C", fs_config]) build_command.extend(["-C", fs_config])
build_command.extend(["-f", in_dir]) build_command.extend(["-f", in_dir])
@@ -691,18 +690,13 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
in_dir, du_str, in_dir, du_str,
int(prop_dict.get("partition_reserved_size", 0)), int(prop_dict.get("partition_reserved_size", 0)),
int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB)) int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB))
if "original_partition_size" in prop_dict: print(
print( "The max image size for filsystem files is {} bytes ({} MB), out of a "
"The max size for filsystem files is {} bytes ({} MB), out of a " "total partition size of {} bytes ({} MB).".format(
"total image size of {} bytes ({} MB).".format( int(prop_dict["image_size"]),
int(prop_dict["partition_size"]), int(prop_dict["image_size"]) // BYTES_IN_MB,
int(prop_dict["partition_size"]) // BYTES_IN_MB, int(prop_dict["partition_size"]),
int(prop_dict["original_partition_size"]), int(prop_dict["partition_size"]) // BYTES_IN_MB))
int(prop_dict["original_partition_size"]) // BYTES_IN_MB))
else:
print("The max image size is {} bytes ({} MB).".format(
int(prop_dict["partition_size"]),
int(prop_dict["partition_size"]) // BYTES_IN_MB))
return False return False
# Check if there's enough headroom space available for ext4 image. # Check if there's enough headroom space available for ext4 image.
@@ -712,14 +706,14 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if not fs_spans_partition: if not fs_spans_partition:
mount_point = prop_dict.get("mount_point") mount_point = prop_dict.get("mount_point")
partition_size = int(prop_dict.get("partition_size")) image_size = int(prop_dict["image_size"])
image_size = GetSimgSize(out_file) sparse_image_size = GetSimgSize(out_file)
if image_size > partition_size: if sparse_image_size > image_size:
print("Error: %s image size of %d is larger than partition size of " print("Error: %s image size of %d is larger than partition size of "
"%d" % (mount_point, image_size, partition_size)) "%d" % (mount_point, sparse_image_size, image_size))
return False return False
if verity_supported and is_verity_partition: if verity_supported and is_verity_partition:
ZeroPadSimg(out_file, partition_size - image_size) ZeroPadSimg(out_file, image_size - sparse_image_size)
# Create the verified image if this is to be verified. # Create the verified image if this is to be verified.
if verity_supported and is_verity_partition: if verity_supported and is_verity_partition:
@@ -729,7 +723,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
# Add AVB HASH or HASHTREE footer (metadata). # Add AVB HASH or HASHTREE footer (metadata).
if avb_footer_type: if avb_footer_type:
avbtool = prop_dict["avb_avbtool"] avbtool = prop_dict["avb_avbtool"]
original_partition_size = prop_dict["original_partition_size"] partition_size = prop_dict["partition_size"]
partition_name = prop_dict["partition_name"] partition_name = prop_dict["partition_name"]
# key_path and algorithm are only available when chain partition is used. # key_path and algorithm are only available when chain partition is used.
key_path = prop_dict.get("avb_key_path") key_path = prop_dict.get("avb_key_path")
@@ -738,7 +732,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
# avb_add_hash_footer_args or avb_add_hashtree_footer_args # avb_add_hash_footer_args or avb_add_hashtree_footer_args
additional_args = prop_dict["avb_add_" + avb_footer_type + "_footer_args"] additional_args = prop_dict["avb_add_" + avb_footer_type + "_footer_args"]
if not AVBAddFooter(out_file, avbtool, avb_footer_type, if not AVBAddFooter(out_file, avbtool, avb_footer_type,
original_partition_size, partition_name, key_path, partition_size, partition_name, key_path,
algorithm, salt, additional_args): algorithm, salt, additional_args):
return False return False
@@ -988,23 +982,18 @@ def GlobalDictFromImageProp(image_prop, mount_point):
return True return True
return False return False
if "original_partition_size" in image_prop:
size_property = "original_partition_size"
else:
size_property = "partition_size"
if mount_point == "system": if mount_point == "system":
copy_prop(size_property, "system_size") copy_prop("partition_size", "system_size")
elif mount_point == "system_other": elif mount_point == "system_other":
copy_prop(size_property, "system_size") copy_prop("partition_size", "system_size")
elif mount_point == "vendor": elif mount_point == "vendor":
copy_prop(size_property, "vendor_size") copy_prop("partition_size", "vendor_size")
elif mount_point == "odm": elif mount_point == "odm":
copy_prop(size_property, "odm_size") copy_prop("partition_size", "odm_size")
elif mount_point == "product": elif mount_point == "product":
copy_prop(size_property, "product_size") copy_prop("partition_size", "product_size")
elif mount_point == "product_services": elif mount_point == "product_services":
copy_prop(size_property, "product_services_size") copy_prop("partition_size", "product_services_size")
return d return d

View File

@@ -369,7 +369,7 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
(0xCAC3, 4), (0xCAC3, 4),
(0xCAC1, 6)]) (0xCAC1, 6)])
OPTIONS.info_dict = { OPTIONS.info_dict = {
'system_adjusted_partition_size' : 12, 'system_image_blocks' : 12,
} }
name, care_map = GetCareMap('system', sparse_image) name, care_map = GetCareMap('system', sparse_image)
self.assertEqual('system', name) self.assertEqual('system', name)
@@ -384,6 +384,6 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
(0xCAC3, 4), (0xCAC3, 4),
(0xCAC1, 6)]) (0xCAC1, 6)])
OPTIONS.info_dict = { OPTIONS.info_dict = {
'system_adjusted_partition_size' : -12, 'system_image_blocks' : -12,
} }
self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image) self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image)

View File

@@ -116,13 +116,13 @@ class ValidateTargetFilesTest(unittest.TestCase):
def _generate_system_image(self, output_file): def _generate_system_image(self, output_file):
verity_fec = True verity_fec = True
partition_size = 1024 * 1024 partition_size = 1024 * 1024
adjusted_size, verity_size = build_image.AdjustPartitionSizeForVerity( image_size, verity_size = build_image.AdjustPartitionSizeForVerity(
partition_size, verity_fec) partition_size, verity_fec)
# Use an empty root directory. # Use an empty root directory.
system_root = common.MakeTempDir() system_root = common.MakeTempDir()
cmd = ['mkuserimg_mke2fs', '-s', system_root, output_file, 'ext4', cmd = ['mkuserimg_mke2fs', '-s', system_root, output_file, 'ext4',
'/system', str(adjusted_size), '-j', '0'] '/system', str(image_size), '-j', '0']
proc = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) proc = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdoutdata, _ = proc.communicate() stdoutdata, _ = proc.communicate()
self.assertEqual( self.assertEqual(
@@ -132,8 +132,8 @@ class ValidateTargetFilesTest(unittest.TestCase):
# Append the verity metadata. # Append the verity metadata.
prop_dict = { prop_dict = {
'original_partition_size' : str(partition_size), 'partition_size' : str(partition_size),
'partition_size' : str(adjusted_size), 'image_size' : str(image_size),
'verity_block_device' : '/dev/block/system', 'verity_block_device' : '/dev/block/system',
'verity_key' : os.path.join(self.testdata_dir, 'testkey'), 'verity_key' : os.path.join(self.testdata_dir, 'testkey'),
'verity_signer_cmd' : 'verity_signer', 'verity_signer_cmd' : 'verity_signer',