aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-05-05 03:01:29 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-05-05 03:01:29 +0000
commit88d2497bd7fbc5b76083c69e2071036c23cc137b (patch)
tree15608f8e7be07988d122e4adac306fd47e2eb91f
parent67ab63058f1a8d17006d7b7c5caef0197f935304 (diff)
parente97026b0a50301c6f7b7e7bcb5522171967074bf (diff)
downloadbuild-88d2497bd7fbc5b76083c69e2071036c23cc137b.tar.gz
Merge changes from topic "cf-avb-q" into android10-gsi
* changes: releasetools: Skip on empty care_map. releasetools: GetCareMap supports non-sparse image.
-rwxr-xr-xtools/releasetools/add_img_to_target_files.py39
-rw-r--r--tools/releasetools/test_add_img_to_target_files.py61
2 files changed, 84 insertions, 16 deletions
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index f2b9afa657..ddef9db281 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -114,22 +114,33 @@ def GetCareMap(which, imgname):
Returns:
(which, care_map_ranges): care_map_ranges is the raw string of the care_map
- RangeSet.
+ RangeSet; or None.
"""
assert which in common.PARTITIONS_WITH_CARE_MAP
- simg = sparse_img.SparseImage(imgname)
- care_map_ranges = simg.care_map
- 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(
+ # which + "_image_size" contains the size that the actual filesystem image
+ # resides in, which is all that needs to be verified. The additional blocks in
+ # the image file contain verity metadata, by reading which would trigger
+ # invalid reads.
+ image_size = OPTIONS.info_dict.get(which + "_image_size")
+ if not image_size:
+ return None
+
+ image_blocks = int(image_size) / 4096 - 1
+ assert image_blocks > 0, "blocks for {} must be positive".format(which)
+
+ # For sparse images, we will only check the blocks that are listed in the care
+ # map, i.e. the ones with meaningful data.
+ if "extfs_sparse_flag" in OPTIONS.info_dict:
+ simg = sparse_img.SparseImage(imgname)
+ care_map_ranges = simg.care_map.intersect(
rangelib.RangeSet("0-{}".format(image_blocks)))
+ # Otherwise for non-sparse images, we read all the blocks in the filesystem
+ # image.
+ else:
+ care_map_ranges = rangelib.RangeSet("0-{}".format(image_blocks))
+
return [which, care_map_ranges.to_string_raw()]
@@ -583,7 +594,11 @@ def AddCareMapForAbOta(output_zip, ab_partitions, image_paths):
OPTIONS.info_dict.get(avb_hashtree_enable) == "true"):
image_path = image_paths[partition]
assert os.path.exists(image_path)
- care_map_list += GetCareMap(partition, image_path)
+
+ care_map = GetCareMap(partition, image_path)
+ if not care_map:
+ continue
+ care_map_list += care_map
# adds fingerprint field to the care_map
build_props = OPTIONS.info_dict.get(partition + ".build.prop", {})
diff --git a/tools/releasetools/test_add_img_to_target_files.py b/tools/releasetools/test_add_img_to_target_files.py
index 482f86c7cd..392ba9173b 100644
--- a/tools/releasetools/test_add_img_to_target_files.py
+++ b/tools/releasetools/test_add_img_to_target_files.py
@@ -135,6 +135,9 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
def _test_AddCareMapForAbOta():
"""Helper function to set up the test for test_AddCareMapForAbOta()."""
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
+ 'system_image_size' : 65536,
+ 'vendor_image_size' : 40960,
'system_verity_block_device': '/dev/block/system',
'vendor_verity_block_device': '/dev/block/vendor',
'system.build.prop': {
@@ -143,7 +146,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
},
'vendor.build.prop': {
'ro.vendor.build.fingerprint': 'google/sailfish/678:user/dev-keys',
- }
+ },
}
# Prepare the META/ folder.
@@ -154,9 +157,9 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
system_image = test_utils.construct_sparse_image([
(0xCAC1, 6),
(0xCAC3, 4),
- (0xCAC1, 6)])
+ (0xCAC1, 8)])
vendor_image = test_utils.construct_sparse_image([
- (0xCAC2, 10)])
+ (0xCAC2, 12)])
image_paths = {
'system' : system_image,
@@ -200,6 +203,9 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
"""Tests the case for device using AVB."""
image_paths = self._test_AddCareMapForAbOta()
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
+ 'system_image_size' : 65536,
+ 'vendor_image_size' : 40960,
'avb_system_hashtree_enable' : 'true',
'avb_vendor_hashtree_enable' : 'true',
'system.build.prop': {
@@ -227,6 +233,9 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
"""Tests the case for partitions without fingerprint."""
image_paths = self._test_AddCareMapForAbOta()
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
+ 'system_image_size' : 65536,
+ 'vendor_image_size' : 40960,
'system_verity_block_device': '/dev/block/system',
'vendor_verity_block_device': '/dev/block/vendor',
}
@@ -244,6 +253,9 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
"""Tests the case for partitions with thumbprint."""
image_paths = self._test_AddCareMapForAbOta()
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
+ 'system_image_size' : 65536,
+ 'vendor_image_size' : 40960,
'system_verity_block_device': '/dev/block/system',
'vendor_verity_block_device': '/dev/block/vendor',
'system.build.prop': {
@@ -251,7 +263,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
},
'vendor.build.prop' : {
'ro.vendor.build.thumbprint': 'google/sailfish/456:user/dev-keys',
- }
+ },
}
AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
@@ -266,6 +278,35 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
self._verifyCareMap(expected, care_map_file)
+ @test_utils.SkipIfExternalToolsUnavailable()
+ def test_AddCareMapForAbOta_skipPartition(self):
+ image_paths = self._test_AddCareMapForAbOta()
+
+ # Remove vendor_image_size to invalidate the care_map for vendor.img.
+ del OPTIONS.info_dict['vendor_image_size']
+
+ AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
+
+ care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
+ expected = ['system', RangeSet("0-5 10-15").to_string_raw(),
+ "ro.system.build.fingerprint",
+ "google/sailfish/12345:user/dev-keys"]
+
+ self._verifyCareMap(expected, care_map_file)
+
+ @test_utils.SkipIfExternalToolsUnavailable()
+ def test_AddCareMapForAbOta_skipAllPartitions(self):
+ image_paths = self._test_AddCareMapForAbOta()
+
+ # Remove the image_size properties for all the partitions.
+ del OPTIONS.info_dict['system_image_size']
+ del OPTIONS.info_dict['vendor_image_size']
+
+ AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
+
+ self.assertFalse(
+ os.path.exists(os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')))
+
def test_AddCareMapForAbOta_verityNotEnabled(self):
"""No care_map.pb should be generated if verity not enabled."""
image_paths = self._test_AddCareMapForAbOta()
@@ -362,6 +403,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
(0xCAC3, 4),
(0xCAC1, 6)])
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
'system_image_size' : 53248,
}
name, care_map = GetCareMap('system', sparse_image)
@@ -377,6 +419,17 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
(0xCAC3, 4),
(0xCAC1, 6)])
OPTIONS.info_dict = {
+ 'extfs_sparse_flag' : '-s',
'system_image_size' : -45056,
}
self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image)
+
+ def test_GetCareMap_nonSparseImage(self):
+ OPTIONS.info_dict = {
+ 'system_image_size' : 53248,
+ }
+ # 'foo' is the image filename, which is expected to be not used by
+ # GetCareMap().
+ name, care_map = GetCareMap('system', 'foo')
+ self.assertEqual('system', name)
+ self.assertEqual(RangeSet("0-12").to_string_raw(), care_map)