Code improvement to adjusted the blocks size for care_map file

Bug: 123931528
Test: python -m unittest test_add_img_to_target_files
Change-Id: I589bc9681bccfa07588cab94f53f69d637d6f0f9
This commit is contained in:
Shashikant Baviskar
2019-02-07 10:57:21 +09:00
committed by Tianjie Xu
parent fc58ed2fb7
commit 16a73897c3
2 changed files with 11 additions and 10 deletions

View File

@@ -119,9 +119,12 @@ def GetCareMap(which, imgname):
simg = sparse_img.SparseImage(imgname)
care_map_ranges = simg.care_map
key = which + "_image_blocks"
image_blocks = OPTIONS.info_dict.get(key)
if image_blocks:
size_key = which + "_image_size"
image_size = OPTIONS.info_dict.get(size_key)
if image_size:
# 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
image_blocks = int(image_size) / 4096 - 1
assert image_blocks > 0, "blocks for {} must be positive".format(which)
care_map_ranges = care_map_ranges.intersect(
rangelib.RangeSet("0-{}".format(image_blocks)))
@@ -319,9 +322,7 @@ def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
if block_list:
block_list.Write()
# 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.
# Set the '_image_size' for given image size.
is_verity_partition = "verity_block_device" in image_props
verity_supported = (image_props.get("verity") == "true" or
image_props.get("avb_enable") == "true")
@@ -329,8 +330,8 @@ def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
if verity_supported and (is_verity_partition or is_avb_enable):
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
image_size_key = what + "_image_size"
info_dict[image_size_key] = int(image_size)
use_dynamic_size = (
info_dict.get("use_dynamic_partition_size") == "true" and

View File

@@ -362,7 +362,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
(0xCAC3, 4),
(0xCAC1, 6)])
OPTIONS.info_dict = {
'system_image_blocks' : 12,
'system_image_size' : 53248,
}
name, care_map = GetCareMap('system', sparse_image)
self.assertEqual('system', name)
@@ -377,6 +377,6 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
(0xCAC3, 4),
(0xCAC1, 6)])
OPTIONS.info_dict = {
'system_image_blocks' : -12,
'system_image_size' : -45056,
}
self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image)