From 97a6690a230bfff7501dc032a8853b41a9f534f0 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 4 Jun 2019 16:26:45 -0700 Subject: [PATCH] Rebuild recovery-from-boot patch when calling add_img_to_target_files. When using Verified Boot 2.0, releasetools specifies a salt value based on build fingerprint, so that to give idempotent images. However, the change that removed static `ro.build.fingerprint` [1] broke the behavior, as common.LoadInfoDict still relies on fingerprints. Without a fixed salt, the first call to make_recovery_patch.py and the second one (which writes IMAGES/{boot,recovery}.img) will see different images, which leads to install-recovery.sh failure. Note that currently there's a dependency that requires getting bootable images through two separate calls. make_recovery_patch.py has to happen first to get (placeholder) files in the system image. We then generate canned fs_config files, and finally use add_img_to_target_files.py to write the images. This CL adds a quick workaround to force rebuilding the recovery-from-boot patch while calling add_img_to_target_files.py. [1] https://android-review.googlesource.com/c/platform/build/+/892933 Bug: 134123803 Bug: 134525174 Test: TreeHugger Test: Build a non-A/B target that uses AVB. Run validate_target_files.py on the generated target_files.zip. Change-Id: I5859e30be63bfd54398cf41fd2d907f15285f560 Merged-In: I5859e30be63bfd54398cf41fd2d907f15285f560 (cherry picked from commit 4978fa99d17de70b09472a4c41c8fe610364fbbb) --- core/Makefile | 3 ++- tools/releasetools/add_img_to_target_files.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/Makefile b/core/Makefile index d9a0fc1084..4611fb388d 100644 --- a/core/Makefile +++ b/core/Makefile @@ -4175,8 +4175,9 @@ ifneq ($(BOARD_SUPER_PARTITION_GROUPS),) $(if $(_group_partition_list), \ echo "$(group)_partition_list=$(_group_partition_list)" >> $(zip_root)/META/dynamic_partitions_info.txt;)) endif # BOARD_SUPER_PARTITION_GROUPS + @# TODO(b/134525174): Remove `-r` after addressing the issue with recovery patch generation. $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \ - build/make/tools/releasetools/add_img_to_target_files -a -v -p $(HOST_OUT) $(zip_root) + build/make/tools/releasetools/add_img_to_target_files -a -r -v -p $(HOST_OUT) $(zip_root) @# Zip everything up, preserving symlinks and placing META/ files first to @# help early validation of the .zip file while uploading it. $(hide) find $(zip_root)/META | sort >$@.list diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 10aecf9216..1090d57194 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -28,7 +28,8 @@ Usage: add_img_to_target_files [flag] target_files -r (--rebuild_recovery) Rebuild the recovery patch and write it to the system image. Only - meaningful when system image needs to be rebuilt. + meaningful when system image needs to be rebuilt and there're separate + boot / recovery images. --replace_verity_private_key Replace the private key used for verity signing. (same as the option @@ -153,7 +154,8 @@ def AddSystem(output_zip, recovery_img=None, boot_img=None): else: common.ZipWrite(output_zip, ofile.name, arc_name) - if OPTIONS.rebuild_recovery: + if (OPTIONS.rebuild_recovery and recovery_img is not None and + boot_img is not None): logger.info("Building new recovery patch") common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img, boot_img, info_dict=OPTIONS.info_dict)