releasetools: Clean up the use of partition_size.

Unless using dynamic partitions, `partition_size` should be a fixed
value that equals to the partition size in BoardConfig. It should stay
the same when building an image for that partition. Only the actual
image size that's used to hold the filesystem could be adjusted. This CL
cleans up the uses of `partition_size` and `image_size` to better
reflect such logic.

With dynamic partitions, the only thing that changes is the need to
compute `partition_size` upfront. Once that's done, `partition_size`
should remain unchanged.

Test: `m dist`
Test: `python -m unittest test_add_img_to_target_files`
Test: `python -m unittest test_validate_target_files`
Change-Id: Idedb3e018c95e8f63dc4d9c423be27f30ebb584f
This commit is contained in:
Tao Bao
2018-09-27 15:31:11 -07:00
parent 2f12a56593
commit 35f4ebc957
4 changed files with 52 additions and 63 deletions

View File

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