Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16a73897 authored by Shashikant Baviskar's avatar Shashikant Baviskar Committed by Tianjie Xu
Browse files

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
parent fc58ed2f
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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)