From 380d9e445c016adf384973ffba92a3fefd53f86a Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Thu, 4 Nov 2021 19:01:19 +0000 Subject: [PATCH 1/2] Build a new init_boot.img that contains the boot ramdisk This ramdisk used to be in boot.img, and is now placed into this new init_boot.img instead. This new image is used for a new init parition to seperate Android platform artifacts from the kernel artifacts in boot.img. Test: boot Cuttlefish Bug: 203698939 Change-Id: Iaaf82486259979ab728730ce72a4e847ae005c18 --- core/Makefile | 95 ++++++++++++++++++++++++++++++++++++++++++-- core/board_config.mk | 28 +++++++++++++ core/main.mk | 4 ++ core/product.mk | 1 + 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/core/Makefile b/core/Makefile index a580ac8615..09efca5e35 100644 --- a/core/Makefile +++ b/core/Makefile @@ -908,8 +908,14 @@ ifneq ($(strip $(TARGET_NO_KERNEL)),true) INTERNAL_BOOTIMAGE_ARGS := \ $(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) +INTERNAL_INIT_BOOT_IMAGE_ARGS := + ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true) -INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET) + ifneq ($(BUILDING_INIT_BOOT_IMAGE),true) + INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET) + else + INTERNAL_INIT_BOOT_IMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET) + endif endif ifndef BUILDING_VENDOR_BOOT_IMAGE @@ -1088,6 +1094,58 @@ endif # my_installed_prebuilt_gki_apex not defined my_apex_extracted_boot_image := my_installed_prebuilt_gki_apex := +# ----------------------------------------------------------------- +# init boot image +ifeq ($(BUILDING_INIT_BOOT_IMAGE),true) + +INSTALLED_INIT_BOOT_IMAGE_TARGET := $(PRODUCT_OUT)/init_boot.img +$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_RAMDISK_TARGET) + +ifdef BOARD_KERNEL_PAGESIZE + INTERNAL_INIT_BOOT_IMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE) +endif + +ifeq ($(BOARD_AVB_ENABLE),true) +$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_INIT_BOOT_IMAGE_KEY_PATH) + $(call pretty,"Target init_boot image: $@") + $(MKBOOTIMG) $(INTERNAL_INIT_BOOT_IMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_INIT_ARGS) --output $@ + $(call assert-max-image-size,$@,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)) + $(AVBTOOL) add_hash_footer \ + --image $@ \ + --partition_size $(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE) \ + --partition_name init_boot $(INTERNAL_AVB_INIT_BOOT_SIGNING_ARGS) \ + $(BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS) +else +$(INSTALLED_INIT_BOOT_IMAGE_TARGET): + $(call pretty,"Target init_boot image: $@") + $(MKBOOTIMG) $(INTERNAL_INIT_BOOT_IMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_INIT_ARGS) --output $@ + $(call assert-max-image-size,$@,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)) +endif + +else # BUILDING_INIT_BOOT_IMAGE is not true + +ifdef BOARD_PREBUILT_INIT_BOOT_IMAGE +INTERNAL_PREBUILT_INIT_BOOT_IMAGE := $(BOARD_PREBUILT_INIT_BOOT_IMAGE) +INSTALLED_INIT_BOOT_IMAGE_TARGET := $(PRODUCT_OUT)/init_boot.img + +ifeq ($(BOARD_AVB_ENABLE),true) +$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $(AVBTOOL) $(BOARD_AVB_INIT_BOOT_KEY_PATH) + cp $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $@ + $(AVBTOOL) add_hash_footer \ + --image $@ \ + --partition_size $(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE) \ + --partition_name boot $(INTERNAL_AVB_INIT_BOOT_SIGNING_ARGS) \ + $(BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS) +else +$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) + cp $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $@ +endif # BOARD_AVB_ENABLE + +else # BOARD_PREBUILT_INIT_BOOT_IMAGE not defined +INSTALLED_INIT_BOOT_IMAGE_TARGET := +endif # BOARD_PREBUILT_INIT_BOOT_IMAGE + +endif # BUILDING_INIT_BOOT_IMAGE is not true # ----------------------------------------------------------------- # vendor boot image ifeq ($(BUILDING_VENDOR_BOOT_IMAGE),true) @@ -3621,9 +3679,13 @@ BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \ --prop com.android.build.pvmfw.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) # The following vendor- and odm-specific images needs explicit SPL set per board. +# TODO(b/210875415) Is this security_patch property used? Should it be removed from +# boot.img when there is no platform ramdisk included in it? ifdef BOOT_SECURITY_PATCH BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \ --prop com.android.build.boot.security_patch:$(BOOT_SECURITY_PATCH) +BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS += \ + --prop com.android.build.init_boot.security_patch:$(BOOT_SECURITY_PATCH) endif ifdef VENDOR_SECURITY_PATCH @@ -3652,6 +3714,7 @@ BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \ endif BOOT_FOOTER_ARGS := BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS +INIT_BOOT_FOOTER_ARGS := BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS VENDOR_BOOT_FOOTER_ARGS := BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS DTBO_FOOTER_ARGS := BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS PVMFW_FOOTER_ARGS := BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS @@ -3735,6 +3798,10 @@ ifdef INSTALLED_BOOTIMAGE_TARGET $(eval $(call check-and-set-avb-args,boot)) endif +ifdef INSTALLED_INIT_BOOT_IMAGE_TARGET +$(eval $(call check-and-set-avb-args,init_boot)) +endif + ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET $(eval $(call check-and-set-avb-args,vendor_boot)) endif @@ -3831,6 +3898,9 @@ define extract-avb-chain-public-keys $(if $(BOARD_AVB_BOOT_KEY_PATH),\ $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_BOOT_KEY_PATH) \ --output $(1)/boot.avbpubkey) + $(if $(BOARD_AVB_INIT_BOOT_KEY_PATH),\ + $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_INIT_BOOT_KEY_PATH) \ + --output $(1)/init_boot.avbpubkey) $(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),\ $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_BOOT_KEY_PATH) \ --output $(1)/vendor_boot.avbpubkey) @@ -3934,6 +4004,7 @@ $(INSTALLED_VBMETAIMAGE_TARGET): PRIVATE_AVB_VBMETA_SIGNING_ARGS := \ $(INSTALLED_VBMETAIMAGE_TARGET): \ $(AVBTOOL) \ $(INSTALLED_BOOTIMAGE_TARGET) \ + $(INSTALLED_INIT_BOOT_IMAGE_TARGET) \ $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) \ $(INSTALLED_SYSTEMIMAGE_TARGET) \ $(INSTALLED_VENDORIMAGE_TARGET) \ @@ -4505,6 +4576,10 @@ ifeq ($(INSTALLED_BOOTIMAGE_TARGET),) else echo "boot_images=$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(notdir $(b)))" >> $@ endif +ifneq ($(INSTALLED_INIT_BOOT_IMAGE_TARGET),) + $(hide) echo "init_boot=true" >> $@ + $(hide) echo "init_boot_size=$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)" >> $@ +endif ifeq ($(BOARD_RAMDISK_USE_LZ4),true) echo "lz4_ramdisks=true" >> $@ endif @@ -4538,6 +4613,7 @@ endif $(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $@ $(hide) echo 'recovery_mkbootimg_args=$(BOARD_RECOVERY_MKBOOTIMG_ARGS)' >> $@ $(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $@ + $(hide) echo 'mkbootimg_init_args=$(BOARD_MKBOOTIMG_INIT_ARGS)' >> $@ ifdef BOARD_GKI_SIGNING_KEY_PATH $(hide) echo 'gki_signing_key_path=$(BOARD_GKI_SIGNING_KEY_PATH)' >> $@ $(hide) echo 'gki_signing_algorithm=$(BOARD_GKI_SIGNING_ALGORITHM)' >> $@ @@ -4915,9 +4991,10 @@ else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) endif -ifdef BUILDING_BOOT_IMAGE +ifneq (,$(BUILDING_BOOT_IMAGE)$(BUILDING_INIT_BOOT_IMAGE)) $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_RAMDISK_FILES) -endif +endif # BUILDING_BOOT_IMAGE != "" || BUILDING_INIT_BOOT_IMAGE != "" + ifneq (,$(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES))) $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_BOOTIMAGE_TARGET) endif @@ -5239,6 +5316,10 @@ ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE $(hide) mkdir -p $(zip_root)/IMAGES $(hide) cp $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) $(zip_root)/IMAGES/ endif +ifdef BOARD_PREBUILT_INIT_BOOT_IMAGE + $(hide) mkdir -p $(zip_root)/IMAGES + $(hide) cp $(INSTALLED_INIT_BOOT_IMAGE_TARGET) $(zip_root)/IMAGES/ +endif ifndef BOARD_PREBUILT_BOOTIMAGE ifneq (,$(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES))) ifdef INSTALLED_BOOTIMAGE_TARGET @@ -5316,6 +5397,13 @@ ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) @# BOOT/RAMDISK exists and contains the ramdisk for recovery if using BOARD_USES_RECOVERY_AS_BOOT. $(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt endif +ifdef BUILDING_INIT_BOOT_IMAGE + $(hide) $(call package_files-copy-root, $(TARGET_RAMDISK_OUT),$(zip_root)/INIT_BOOT/RAMDISK) + $(hide) $(call fs_config,$(zip_root)/INIT_BOOT/RAMDISK,) > $(zip_root)/META/init_boot_filesystem_config.txt +ifdef BOARD_KERNEL_PAGESIZE + $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/INIT_BOOT/pagesize +endif # BOARD_KERNEL_PAGESIZE +endif # BUILDING_INIT_BOOT_IMAGE ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),) $(call fs_config,$(zip_root)/VENDOR_BOOT/RAMDISK,) > $(zip_root)/META/vendor_boot_filesystem_config.txt endif @@ -5629,6 +5717,7 @@ $(PROGUARD_USAGE_ZIP): \ $(INSTALLED_SYSTEMIMAGE_TARGET) \ $(INSTALLED_RAMDISK_TARGET) \ $(INSTALLED_BOOTIMAGE_TARGET) \ + $(INSTALLED_INIT_BOOT_IMAGE_TARGET) \ $(INSTALLED_USERDATAIMAGE_TARGET) \ $(INSTALLED_VENDORIMAGE_TARGET) \ $(INSTALLED_PRODUCTIMAGE_TARGET) \ diff --git a/core/board_config.mk b/core/board_config.mk index 6bbb3a0eee..95cbe3d299 100644 --- a/core/board_config.mk +++ b/core/board_config.mk @@ -65,6 +65,7 @@ _board_strip_readonly_list += TARGET_ARCH_SUITE # File system variables _board_strip_readonly_list += BOARD_FLASH_BLOCK_SIZE _board_strip_readonly_list += BOARD_BOOTIMAGE_PARTITION_SIZE +_board_strip_readonly_list += BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE _board_strip_readonly_list += BOARD_RECOVERYIMAGE_PARTITION_SIZE _board_strip_readonly_list += BOARD_SYSTEMIMAGE_PARTITION_SIZE _board_strip_readonly_list += BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE @@ -122,6 +123,9 @@ _board_strip_readonly_list += BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT _board_strip_readonly_list += BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT _board_strip_readonly_list += BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES +# Prebuilt image variables +_board_strip_readonly_list += BOARD_PREBUILT_INIT_BOOT_IMAGE + # Defines the list of logical vendor ramdisk names to build or include in vendor_boot. _board_strip_readonly_list += BOARD_VENDOR_RAMDISK_FRAGMENTS @@ -461,6 +465,25 @@ else ifeq ($(PRODUCT_BUILD_BOOT_IMAGE),true) endif .KATI_READONLY := BUILDING_BOOT_IMAGE +# Are we building an init boot image +BUILDING_INIT_BOOT_IMAGE := +ifeq ($(PRODUCT_BUILD_INIT_BOOT_IMAGE),) + ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) + BUILDING_INIT_BOOT_IMAGE := + else ifdef BOARD_PREBUILT_INIT_BOOT_IMAGE + BUILDING_INIT_BOOT_IMAGE := + else ifdef BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE + BUILDING_INIT_BOOT_IMAGE := true + endif +else ifeq ($(PRODUCT_BUILD_INIT_BOOT_IMAGE),true) + ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) + $(error PRODUCT_BUILD_INIT_BOOT_IMAGE is true, but so is BOARD_USES_RECOVERY_AS_BOOT. Use only one option.) + else + BUILDING_INIT_BOOT_IMAGE := true + endif +endif +.KATI_READONLY := BUILDING_INIT_BOOT_IMAGE + # Are we building a recovery image BUILDING_RECOVERY_IMAGE := ifeq ($(PRODUCT_BUILD_RECOVERY_IMAGE),) @@ -569,6 +592,11 @@ else ifndef _has_boot_img_artifact $(warning PRODUCT_BUILD_DEBUG_BOOT_IMAGE is true, but we're not building a boot image. \ Skip building the debug boot image.) endif +else ifdef BUILDING_INIT_BOOT_IMAGE + ifeq ($(PRODUCT_BUILD_DEBUG_BOOT_IMAGE),true) + $(warning PRODUCT_BUILD_DEBUG_BOOT_IMAGE is true, but we don't have a ramdisk in the boot image. \ + Skip building the debug boot image.) + endif else ifeq ($(PRODUCT_BUILD_DEBUG_BOOT_IMAGE),) BUILDING_DEBUG_BOOT_IMAGE := true diff --git a/core/main.mk b/core/main.mk index f7cf8de98e..d17f0cbe5b 100644 --- a/core/main.mk +++ b/core/main.mk @@ -1603,6 +1603,9 @@ superimage_empty: $(INSTALLED_SUPERIMAGE_EMPTY_TARGET) .PHONY: bootimage bootimage: $(INSTALLED_BOOTIMAGE_TARGET) +.PHONY: initbootimage +bootimage: $(INSTALLED_INIT_BOOT_IMAGE_TARGET) + ifeq (true,$(PRODUCT_EXPORT_BOOT_IMAGE_TO_DIST)) $(call dist-for-goals, bootimage, $(INSTALLED_BOOTIMAGE_TARGET)) endif @@ -1629,6 +1632,7 @@ droidcore-unbundled: $(filter $(HOST_OUT_ROOT)/%,$(modules_to_install)) \ $(INSTALLED_SYSTEMIMAGE_TARGET) \ $(INSTALLED_RAMDISK_TARGET) \ $(INSTALLED_BOOTIMAGE_TARGET) \ + $(INSTALLED_INIT_BOOT_IMAGE_TARGET) \ $(INSTALLED_RADIOIMAGE_TARGET) \ $(INSTALLED_DEBUG_RAMDISK_TARGET) \ $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) \ diff --git a/core/product.mk b/core/product.mk index 31b1bebf11..04c59ff303 100644 --- a/core/product.mk +++ b/core/product.mk @@ -395,6 +395,7 @@ _product_single_value_vars += PRODUCT_BUILD_RAMDISK_IMAGE _product_single_value_vars += PRODUCT_BUILD_USERDATA_IMAGE _product_single_value_vars += PRODUCT_BUILD_RECOVERY_IMAGE _product_single_value_vars += PRODUCT_BUILD_BOOT_IMAGE +_product_single_value_vars += PRODUCT_BUILD_INIT_BOOT_IMAGE _product_single_value_vars += PRODUCT_BUILD_DEBUG_BOOT_IMAGE _product_single_value_vars += PRODUCT_BUILD_VENDOR_BOOT_IMAGE _product_single_value_vars += PRODUCT_BUILD_DEBUG_VENDOR_BOOT_IMAGE From afdd7c74bc7f228b63b0bdec61a524060933e7c9 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Mon, 13 Dec 2021 22:04:08 +0000 Subject: [PATCH 2/2] Update releasetools for new init_boot.img This new init_boot.img contains the ramdisk that used to reside in the boot.img file. Test: set BOARD_PREBUILT_INIT_BOOT_IMAGE to an external init_boot.img - Check that "m" pulls in the init_boot.img to out/target/product/vsoc_x86_64/ - Check that "m dist" adds the init_boot.img to aosp_cf_x86_64_phone-img-eng.devinmoore.zip Test: atest --host releasetools_test Bug: 203698939 Change-Id: If7ef2cf093e5e525529c7c44333c0f40f6ba0764 --- tools/releasetools/add_img_to_target_files.py | 12 ++++++++++ tools/releasetools/common.py | 23 ++++++++++++------- tools/releasetools/img_from_target_files.py | 2 +- tools/releasetools/sign_target_files_apks.py | 1 + .../test_sign_target_files_apks.py | 6 +++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 2a4b56ba85..0c39827414 100644 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -759,6 +759,7 @@ def AddImagesToTargetFiles(filename): has_recovery = OPTIONS.info_dict.get("no_recovery") != "true" has_boot = OPTIONS.info_dict.get("no_boot") != "true" + has_init_boot = OPTIONS.info_dict.get("init_boot") == "true" has_vendor_boot = OPTIONS.info_dict.get("vendor_boot") == "true" # {vendor,odm,product,system_ext,vendor_dlkm,odm_dlkm, system, system_other}.img @@ -819,6 +820,17 @@ def AddImagesToTargetFiles(filename): if output_zip: boot_image.AddToZip(output_zip) + if has_init_boot: + banner("init_boot") + init_boot_image = common.GetBootableImage( + "IMAGES/init_boot.img", "init_boot.img", OPTIONS.input_tmp, "INIT_BOOT") + if init_boot_image: + partitions['init_boot'] = os.path.join(OPTIONS.input_tmp, "IMAGES", "init_boot.img") + if not os.path.exists(partitions['init_boot']): + init_boot_image.WriteToDir(OPTIONS.input_tmp) + if output_zip: + init_boot_image.AddToZip(output_zip) + if has_vendor_boot: banner("vendor_boot") vendor_boot_image = common.GetVendorBootImage( diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 64ac95aaff..6ec1b94687 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -111,7 +111,7 @@ SPECIAL_CERT_STRINGS = ("PRESIGNED", "EXTERNAL") # descriptor into vbmeta.img. When adding a new entry here, the # AVB_FOOTER_ARGS_BY_PARTITION in sign_target_files_apks need to be updated # accordingly. -AVB_PARTITIONS = ('boot', 'dtbo', 'odm', 'product', 'pvmfw', 'recovery', +AVB_PARTITIONS = ('boot', 'init_boot', 'dtbo', 'odm', 'product', 'pvmfw', 'recovery', 'system', 'system_ext', 'vendor', 'vendor_boot', 'vendor_dlkm', 'odm_dlkm') @@ -130,7 +130,7 @@ PARTITIONS_WITH_CARE_MAP = [ ] # Partitions with a build.prop file -PARTITIONS_WITH_BUILD_PROP = PARTITIONS_WITH_CARE_MAP + ['boot'] +PARTITIONS_WITH_BUILD_PROP = PARTITIONS_WITH_CARE_MAP + ['boot', 'init_boot'] # See sysprop.mk. If file is moved, add new search paths here; don't remove # existing search paths. @@ -935,9 +935,9 @@ class PartitionBuildProps(object): def FromInputFile(input_file, name, placeholder_values=None, ramdisk_format=RamdiskFormat.LZ4): """Loads the build.prop file and builds the attributes.""" - if name == "boot": + if name in ("boot", "init_boot"): data = PartitionBuildProps._ReadBootPropFile( - input_file, ramdisk_format=ramdisk_format) + input_file, name, ramdisk_format=ramdisk_format) else: data = PartitionBuildProps._ReadPartitionPropFile(input_file, name) @@ -946,15 +946,16 @@ class PartitionBuildProps(object): return props @staticmethod - def _ReadBootPropFile(input_file, ramdisk_format): + def _ReadBootPropFile(input_file, partition_name, ramdisk_format): """ Read build.prop for boot image from input_file. Return empty string if not found. """ + image_path = 'IMAGES/' + partition_name + '.img' try: - boot_img = ExtractFromInputFile(input_file, 'IMAGES/boot.img') + boot_img = ExtractFromInputFile(input_file, image_path) except KeyError: - logger.warning('Failed to read IMAGES/boot.img') + logger.warning('Failed to read %s', image_path) return '' prop_file = GetBootImageBuildProp(boot_img, ramdisk_format=ramdisk_format) if prop_file is None: @@ -1539,6 +1540,8 @@ def _BuildBootableImage(image_name, sourcedir, fs_config_file, info_dict=None, logger.info("Excluded kernel binary from recovery image.") else: kernel = "kernel" + elif partition_name == "init_boot": + pass else: kernel = image_name.replace("boot", "kernel") kernel = kernel.replace(".img", "") @@ -1593,6 +1596,8 @@ def _BuildBootableImage(image_name, sourcedir, fs_config_file, info_dict=None, # Fall back to "mkbootimg_args" for recovery image # in case "recovery_mkbootimg_args" is not set. args = info_dict.get("mkbootimg_args") + elif partition_name == "init_boot": + args = info_dict.get("mkbootimg_init_args") else: args = info_dict.get("mkbootimg_args") if args and args.strip(): @@ -1752,9 +1757,11 @@ def GetBootableImage(name, prebuilt_name, unpack_dir, tree_subdir, logger.info("building image from target_files %s...", tree_subdir) # With system_root_image == "true", we don't pack ramdisk into the boot image. + # With init_boot == "true", we don't pack the ramdisk into boot.img. # Unless "recovery_as_boot" is specified, in which case we carry the ramdisk # for recovery. - has_ramdisk = (info_dict.get("system_root_image") != "true" or + has_ramdisk = ((info_dict.get("system_root_image") != "true" and + info_dict.get("init_boot") != "true") or prebuilt_name != "boot.img" or info_dict.get("recovery_as_boot") == "true") diff --git a/tools/releasetools/img_from_target_files.py b/tools/releasetools/img_from_target_files.py index cbb51e1788..0b2b1870c1 100755 --- a/tools/releasetools/img_from_target_files.py +++ b/tools/releasetools/img_from_target_files.py @@ -124,7 +124,7 @@ def EntriesForUserImages(input_file): for image_path in [name for name in namelist if name.startswith('IMAGES/')]: image = os.path.basename(image_path) - if OPTIONS.bootable_only and image not in('boot.img', 'recovery.img', 'bootloader'): + if OPTIONS.bootable_only and image not in('boot.img', 'recovery.img', 'bootloader', 'init_boot.img'): continue if not image.endswith('.img') and image != 'bootloader': continue diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py index 562698096a..8b837b8ed9 100755 --- a/tools/releasetools/sign_target_files_apks.py +++ b/tools/releasetools/sign_target_files_apks.py @@ -201,6 +201,7 @@ OPTIONS.allow_gsi_debug_sepolicy = False AVB_FOOTER_ARGS_BY_PARTITION = { 'boot': 'avb_boot_add_hash_footer_args', + 'init_boot': 'avb_init_boot_add_hash_footer_args', 'dtbo': 'avb_dtbo_add_hash_footer_args', 'product': 'avb_product_add_hashtree_footer_args', 'recovery': 'avb_recovery_add_hash_footer_args', diff --git a/tools/releasetools/test_sign_target_files_apks.py b/tools/releasetools/test_sign_target_files_apks.py index 92dca9aee0..0f13add290 100644 --- a/tools/releasetools/test_sign_target_files_apks.py +++ b/tools/releasetools/test_sign_target_files_apks.py @@ -62,6 +62,9 @@ name="apex.apexd_test_different_app.apex" public_key="system/apex/apexd/apexd_te 'avb_boot_add_hash_footer_args': ('--prop com.android.build.boot.os_version:R ' '--prop com.android.build.boot.security_patch:2019-09-05'), + 'avb_init_boot_add_hash_footer_args': + ('--prop com.android.build.boot.os_version:R ' + '--prop com.android.build.boot.security_patch:2019-09-05'), 'avb_system_add_hashtree_footer_args': ('--prop com.android.build.system.os_version:R ' '--prop com.android.build.system.security_patch:2019-09-05 ' @@ -77,6 +80,9 @@ name="apex.apexd_test_different_app.apex" public_key="system/apex/apexd/apexd_te 'avb_boot_add_hash_footer_args': ('--prop com.android.build.boot.os_version:R ' '--prop com.android.build.boot.security_patch:2019-09-05'), + 'avb_init_boot_add_hash_footer_args': + ('--prop com.android.build.boot.os_version:R ' + '--prop com.android.build.boot.security_patch:2019-09-05'), 'avb_system_add_hashtree_footer_args': ('--prop com.android.build.system.os_version:R ' '--prop com.android.build.system.security_patch:2019-09-05 '