Add options to sign the prebuilt custom images.
The custom images are any images owned by OEMs and SoCs, oem images mounted on /oem is an example. The oem images can be used to customize devices for different carriers, like wallpaper, ringtones, and carrier-specific apks. OEMs can generate multiple oem images, like oem.img, oem-carrier1.img and oem-carrier2.img and flash different oem images for different carriers. The oem images are only one case, OEMs and SoCs can add more custom images and mount them to custom partitions. This change enables custom images to be vbmeta.img chained partitions. The following configuration in BoardConfig.mk is an exmaple. It has two custom partitions: oem and test. They will be signed by different keys. And they will be chained by vbmeta.img. The custom images here are prebuilts, which can be built by `make custom_images` separately. BOARD_AVB_<CUSTOM_PARTITION>_IMAGE_LIST should include all custom images to apply AVB signing. And to every custom partition, one image whose name is partition name must be added in its BOARD_AVB_<CUSTOM_PARTITION>_IMAGE_LIST. BOARD_CUSTOMIMAGES_PARTITION_LIST := oem test BOARD_AVB_OEM_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem BOARD_AVB_OEM_ALGORITHM := SHA256_RSA4096 BOARD_AVB_OEM_ADD_HASHTREE_FOOTER_ARGS := BOARD_AVB_OEM_ROLLBACK_INDEX_LOCATION := 1 BOARD_AVB_OEM_PARTITION_SIZE := 5242880 BOARD_AVB_OEM_IMAGE_LIST := \ device/xxxx/yyyy/oem/oem.img \ device/xxxx/yyyy/oem/oem1.img BOARD_AVB_TEST_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem BOARD_AVB_TEST_ALGORITHM := SHA256_RSA2048 BOARD_AVB_TEST_ADD_HASHTREE_FOOTER_ARGS := BOARD_AVB_TEST_ROLLBACK_INDEX_LOCATION := 2 BOARD_AVB_TEST_PARTITION_SIZE := 10485760 BOARD_AVB_TEST_IMAGE_LIST := \ device/xxxx/yyyy/test/test.img \ device/xxxx/yyyy/test/test1.img To resign the custom images in the target zip file, the avb_extra_custom_image_key, avb_extra_custom_image_algorithms and avb_extra_custom_image_extra_args options are added to the sign_target_files_apks tool too. The following test cases list some examples about how to use them. BUG: 154171021 Test: 1) "atest --host releasetools_test releasetools_py3_test -c" 2) Build images by 'make dist', sign and validate target files. a) Test on dist w/ chained vbmeta_system and ome custom images sign_target_files_apks -d certs \ --avb_extra_custom_image_key oem=oem_rsa4096.pem \ --avb_extra_custom_image_algorithm oem=SHA256_RSA4096 \ xxx-target_xxx.zip signed.zip validate_target_files.py signed.zip Flash image and boot up. Verify the oem images and vbmeta images in OUT and target zips by avbtool. b) Test on dist w/ chained vbmeta_system and oem and test custom images sign_target_files_apks -d certs \ --avb_extra_custom_image_key oem=oem_rsa4096.pem \ --avb_extra_custom_image_algorithm oem=SHA256_RSA4096 \ --avb_extra_custom_image_extra_args oem=--do_not_generate_fec \ --avb_extra_custom_image_key test=test_rsa4096.pem \ --avb_extra_custom_image_algorithm test=SHA256_RSA4096 \ xxx-target_xxx.zip signed.zip validate_target_files.py signed.zip Verify the oem, test images and vbmeta images in OUT and target zips by avbtool. c) Test on dist w/o chained partition. sign_target_files_apks -d certs xxx-target_xxx.zip signed.zip validate_target_files.py signed.zip Flash image and boot up. Verify the vbmeta images in OUT and target zips by avbtool. Change-Id: Ifccfee5e8909697eef6ccda0cc352fa16a9f6db6 Merged-In: Ifccfee5e8909697eef6ccda0cc352fa16a9f6db6
This commit is contained in:
@@ -60,6 +60,7 @@ import build_super_image
|
||||
import common
|
||||
import rangelib
|
||||
import sparse_img
|
||||
import verity_utils
|
||||
|
||||
if sys.hexversion < 0x02070000:
|
||||
print("Python 2.7 or newer is required.", file=sys.stderr)
|
||||
@@ -312,6 +313,56 @@ def AddDtbo(output_zip):
|
||||
img.Write()
|
||||
return img.name
|
||||
|
||||
def AddCustomImages(output_zip, partition_name):
|
||||
"""Adds and signs custom images in IMAGES/.
|
||||
|
||||
Args:
|
||||
output_zip: The output zip file (needs to be already open), or None to
|
||||
write images to OPTIONS.input_tmp/.
|
||||
|
||||
Uses the image under IMAGES/ if it already exists. Otherwise looks for the
|
||||
image under PREBUILT_IMAGES/, signs it as needed, and returns the image name.
|
||||
|
||||
Raises:
|
||||
AssertionError: If image can't be found.
|
||||
"""
|
||||
|
||||
partition_size = OPTIONS.info_dict.get(
|
||||
"avb_{}_partition_size".format(partition_name))
|
||||
key_path = OPTIONS.info_dict.get("avb_{}_key_path".format(partition_name))
|
||||
algorithm = OPTIONS.info_dict.get("avb_{}_algorithm".format(partition_name))
|
||||
extra_args = OPTIONS.info_dict.get(
|
||||
"avb_{}_add_hashtree_footer_args".format(partition_name))
|
||||
partition_size = OPTIONS.info_dict.get(
|
||||
"avb_{}_partition_size".format(partition_name))
|
||||
|
||||
builder = verity_utils.CreateCustomImageBuilder(
|
||||
OPTIONS.info_dict, partition_name, partition_size,
|
||||
key_path, algorithm, extra_args)
|
||||
|
||||
for img_name in OPTIONS.info_dict.get(
|
||||
"avb_{}_image_list".format(partition_name)).split():
|
||||
custom_image = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", img_name)
|
||||
if os.path.exists(custom_image.name):
|
||||
continue
|
||||
|
||||
custom_image_prebuilt_path = os.path.join(
|
||||
OPTIONS.input_tmp, "PREBUILT_IMAGES", img_name)
|
||||
assert os.path.exists(custom_image_prebuilt_path), \
|
||||
"Failed to find %s at %s" % (img_name, custom_image_prebuilt_path)
|
||||
|
||||
shutil.copy(custom_image_prebuilt_path, custom_image.name)
|
||||
|
||||
if builder is not None:
|
||||
builder.Build(custom_image.name)
|
||||
|
||||
custom_image.Write()
|
||||
|
||||
default = os.path.join(OPTIONS.input_tmp, "IMAGES", partition_name + ".img")
|
||||
assert os.path.exists(default), \
|
||||
"There should be one %s.img" % (partition_name)
|
||||
return default
|
||||
|
||||
|
||||
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
|
||||
logger.info("creating %s.img...", what)
|
||||
@@ -411,8 +462,9 @@ def AddVBMeta(output_zip, partitions, name, needed_partitions):
|
||||
Args:
|
||||
output_zip: The output zip file, which needs to be already open.
|
||||
partitions: A dict that's keyed by partition names with image paths as
|
||||
values. Only valid partition names are accepted, as listed in
|
||||
common.AVB_PARTITIONS.
|
||||
values. Only valid partition names are accepted, as partitions listed
|
||||
in common.AVB_PARTITIONS and custom partitions listed in
|
||||
OPTIONS.info_dict.get("avb_custom_images_partition_list")
|
||||
name: Name of the VBMeta partition, e.g. 'vbmeta', 'vbmeta_system'.
|
||||
needed_partitions: Partitions whose descriptors should be included into the
|
||||
generated VBMeta image.
|
||||
@@ -829,11 +881,20 @@ def AddImagesToTargetFiles(filename):
|
||||
banner("dtbo")
|
||||
partitions['dtbo'] = AddDtbo(output_zip)
|
||||
|
||||
# Custom images.
|
||||
custom_partitions = OPTIONS.info_dict.get(
|
||||
"avb_custom_images_partition_list", "").strip().split()
|
||||
for partition_name in custom_partitions:
|
||||
partition_name = partition_name.strip()
|
||||
banner("custom images for " + partition_name)
|
||||
partitions[partition_name] = AddCustomImages(output_zip, partition_name)
|
||||
|
||||
if OPTIONS.info_dict.get("avb_enable") == "true":
|
||||
# vbmeta_partitions includes the partitions that should be included into
|
||||
# top-level vbmeta.img, which are the ones that are not included in any
|
||||
# chained VBMeta image plus the chained VBMeta images themselves.
|
||||
vbmeta_partitions = common.AVB_PARTITIONS[:]
|
||||
# Currently custom_partitions are all chained to VBMeta image.
|
||||
vbmeta_partitions = common.AVB_PARTITIONS[:] + tuple(custom_partitions)
|
||||
|
||||
vbmeta_system = OPTIONS.info_dict.get("avb_vbmeta_system", "").strip()
|
||||
if vbmeta_system:
|
||||
|
Reference in New Issue
Block a user