From 40ef35b9e916163bc408d6d9945f92f012885d33 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Tue, 10 Nov 2015 19:21:34 -0800 Subject: [PATCH] Allow building recovery as boot. With BOARD_USES_RECOVERY_AS_BOOT = true, we skip building the non-ramdisk boot.img but building the recovery image as boot.img. It contains recovery's ramdisk (e.g. with /sbin/recovery). It depends on the bootloader parameter (skip_initramfs) to determine the actual mode to boot into. Change-Id: Id6e2d0a2b94383944ca8f35bba688c6401745622 (cherry picked from commit d80bef2b9e7aa5f92ab017247442798f47736566) --- core/Makefile | 85 ++++++++++++++++----- tools/releasetools/common.py | 7 +- tools/releasetools/ota_from_target_files.py | 13 +++- 3 files changed, 83 insertions(+), 22 deletions(-) diff --git a/core/Makefile b/core/Makefile index 18e01f98e..19b70a834 100644 --- a/core/Makefile +++ b/core/Makefile @@ -517,6 +517,15 @@ endif INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img +# BOARD_USES_RECOVERY_AS_BOOT = true must have BOARD_BUILD_SYSTEM_ROOT_IMAGE = true. +ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) +ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true) + $(error BOARD_BUILD_SYSTEM_ROOT_IMAGE must be enabled for BOARD_USES_RECOVERY_AS_BOOT.) +endif +endif + +# We build recovery as boot image if BOARD_USES_RECOVERY_AS_BOOT is true. +ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true) ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true) $(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore) else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)) # TARGET_BOOTIMAGE_USE_EXT2 != true @@ -563,6 +572,7 @@ bootimage-nodeps: $(MKBOOTIMG) $(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE)) endif # TARGET_BOOTIMAGE_USE_EXT2 +endif # BOARD_USES_RECOVERY_AS_BOOT else # TARGET_NO_KERNEL # HACK: The top-level targets depend on the bootimage. Not all targets @@ -781,6 +791,8 @@ $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_ $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1)) $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(FUTILITY)" >> $(1)) $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1)) +$(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\ + $(hide) echo "recovery_as_boot=true" >> $(1)) $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\ $(hide) echo "system_root_image=true" >> $(1);\ echo "ramdisk_dir=$(TARGET_ROOT_OUT)" >> $(1)) @@ -790,7 +802,8 @@ endef # ----------------------------------------------------------------- # Recovery image -ifdef INSTALLED_RECOVERYIMAGE_TARGET +# Recovery image exists if we are building recovery, or building recovery as boot. +ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT))) INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \ $(ALL_DEFAULT_INSTALLED_MODULES)) @@ -840,12 +853,22 @@ else recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab)) endif -ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true) +# Prior to A/B update, we used to have: +# boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img. +# recovery-resource.dat is needed only if we carry a patch of the boot and +# recovery images and invoke install-recovery.sh on the first boot post an +# OTA update. +# +# We no longer need that if one of the following conditions holds: +# a) We carry a full copy of the recovery image +# (BOARD_USES_FULL_RECOVERY_IMAGE = true); +# b) We build a single image that contains boot and recovery both +# (BOARD_USES_RECOVERY_AS_BOOT = true). + +ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT))) # Named '.dat' so we don't attempt to use imgdiff for patching it. RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat else -# We carry a full copy of the recovery image. recovery-resource.dat is no -# longer needed. RECOVERY_RESOURCE_ZIP := endif @@ -929,10 +952,25 @@ define build-recoveryimage-target $(BOOT_SIGNER) /recovery $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)) $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \ $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1)) - $(hide) $(call assert-max-image-size,$(1),$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)) + $(if $(filter true,BOARD_USES_RECOVERY_AS_BOOT), \ + $(hide) $(call assert-max-image-size,$(1),$(BOARD_BOOTIMAGE_PARTITION_SIZE)), \ + $(hide) $(call assert-max-image-size,$(1),$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))) @echo ----- Made recovery image: $(1) -------- endef +ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) +$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \ + $(INSTALLED_RAMDISK_TARGET) \ + $(INTERNAL_RECOVERYIMAGE_FILES) \ + $(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \ + $(INSTALLED_2NDBOOTLOADER_TARGET) \ + $(recovery_build_prop) $(recovery_resource_deps) \ + $(recovery_fstab) \ + $(RECOVERY_INSTALL_OTA_KEYS) + $(call pretty,"Target boot image from recovery: $@") + $(call build-recoveryimage-target, $@) +endif + $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \ $(INSTALLED_RAMDISK_TARGET) \ $(INSTALLED_BOOTIMAGE_TARGET) \ @@ -944,7 +982,7 @@ $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \ $(RECOVERY_INSTALL_OTA_KEYS) $(call build-recoveryimage-target, $@) -ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true) +ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT))) $(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME) $(hide) mkdir -p $(dir $@) $(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@ @@ -1482,6 +1520,13 @@ ifneq ($(AB_OTA_UPDATER),true) $(BUILT_TARGET_FILES_PACKAGE): $(built_ota_tools) endif +# If we are using recovery as boot, output recovery files to BOOT/. +ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) +$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT +else +$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY +endif + # Depending on the various images guarantees that the underlying # directories are up-to-date. $(BUILT_TARGET_FILES_PACKAGE): \ @@ -1500,28 +1545,28 @@ $(BUILT_TARGET_FILES_PACKAGE): \ @echo "Package target files: $@" $(hide) rm -rf $@ $(zip_root) $(hide) mkdir -p $(dir $@) $(zip_root) -ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),) +ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT))) @# Components of the recovery image - $(hide) mkdir -p $(zip_root)/RECOVERY + $(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT) $(hide) $(call package_files-copy-root, \ - $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK) + $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK) ifdef INSTALLED_KERNEL_TARGET - $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/RECOVERY/kernel + $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel endif ifdef INSTALLED_2NDBOOTLOADER_TARGET $(hide) $(ACP) \ - $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second + $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second endif ifdef BOARD_KERNEL_CMDLINE - $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline + $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline endif ifdef BOARD_KERNEL_BASE - $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base + $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base endif ifdef BOARD_KERNEL_PAGESIZE - $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/RECOVERY/pagesize -endif + $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize endif +endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true @# Components of the boot image $(hide) mkdir -p $(zip_root)/BOOT ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true) @@ -1532,6 +1577,8 @@ else $(hide) $(call package_files-copy-root, \ $(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK) endif + @# If we are using recovery as boot, this is already done when processing recovery. +ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true) ifdef INSTALLED_KERNEL_TARGET $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel endif @@ -1548,6 +1595,7 @@ endif ifdef BOARD_KERNEL_PAGESIZE $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize endif +endif # BOARD_USES_RECOVERY_AS_BOOT $(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\ mkdir -p $(zip_root)/RADIO; \ $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));) @@ -1586,6 +1634,9 @@ endif ifdef BOARD_BOOTIMAGE_PARTITION_SIZE $(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt endif +ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),) + $(hide) echo "recovery_as_boot=$(BOARD_USES_RECOVERY_AS_BOOT)" >> $(zip_root)/META/misc_info.txt +endif ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),) $(hide) echo "no_recovery=true" >> $(zip_root)/META/misc_info.txt endif @@ -1638,6 +1689,7 @@ ifeq ($(AB_OTA_UPDATER),true) done @# Include the build type in META/misc_info.txt so the server can easily differentiate production builds. $(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $(zip_root)/META/misc_info.txt + $(hide) echo "ab_update=true" >> $(zip_root)/META/misc_info.txt ifdef OSRELEASED_DIRECTORY $(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt $(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt @@ -1655,9 +1707,8 @@ endif $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="VENDOR/" } /^VENDOR\// {print "vendor/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/vendor_filesystem_config.txt ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true) $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="ROOT/" } /^ROOT\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/root_filesystem_config.txt -else - $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt endif + $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),) $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt endif diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index ee0cdf97a..aaf51e986 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -494,8 +494,11 @@ def GetBootableImage(name, prebuilt_name, unpack_dir, tree_subdir, info_dict = OPTIONS.info_dict # With system_root_image == "true", we don't pack ramdisk into the boot image. - has_ramdisk = (info_dict.get("system_root_image", None) != "true" or - prebuilt_name != "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 + prebuilt_name != "boot.img" or + info_dict.get("recovery_as_boot") == "true") fs_config = "META/" + tree_subdir.lower() + "_filesystem_config.txt" data = _BuildBootableImage(os.path.join(unpack_dir, tree_subdir), diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 5259ede59..a76eaa987 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -1703,7 +1703,9 @@ def main(argv): if OPTIONS.device_specific is not None: OPTIONS.device_specific = os.path.abspath(OPTIONS.device_specific) - if OPTIONS.info_dict.get("no_recovery") == "true": + ab_update = OPTIONS.info_dict.get("ab_update") == "true" + + if OPTIONS.info_dict.get("no_recovery") == "true" and not ab_update: raise common.ExternalError( "--- target build has specified no recovery ---") @@ -1725,8 +1727,9 @@ def main(argv): output_zip = zipfile.ZipFile(temp_zip_file, "w", compression=zipfile.ZIP_DEFLATED) + # Non A/B OTAs rely on /cache partition to store temporary files. cache_size = OPTIONS.info_dict.get("cache_size", None) - if cache_size is None: + if cache_size is None and not ab_update: print "--- can't determine the cache partition size ---" OPTIONS.cache_size = cache_size @@ -1736,7 +1739,11 @@ def main(argv): # Generate a full OTA. elif OPTIONS.incremental_source is None: - WriteFullOTAPackage(input_zip, output_zip) + if ab_update: + # TODO: Pending for b/25715402. + pass + else: + WriteFullOTAPackage(input_zip, output_zip) # Generate an incremental OTA. It will fall back to generate a full OTA on # failure unless no_fallback_to_full is specified.