From 5d2b56b1298b31df328c91e93949edfe23e8ea26 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 26 Jun 2020 11:37:28 -0400 Subject: [PATCH] Fix validate_target_files for target files modified by add_img_to_target_files.py See bug description: "When resigning images, the validate_target_files.py can be used to verify the images using avbtool. The script will use the vbmeta.img to achieve this, and all relevant images need to be in the IMAGES folder. However, due to changes on add_img_to_target_files.py and specifically the commit 5277d1015, some images (e.g. acpio.img and tos.img) are no longer copied from RADIO to the IMAGES folder. This causes an error on validate_target_files.py indicating that it cannot find image such as IMAGES/acpio.img." This CL fixes this by symlink images under RADIO directory to IMAGES directory before invoking avbtool. Bug: 159299583 Test: python3 -m unittest test_validate_target_files Change-Id: I5769ee2ab5230d2a3a7cef10706dcc5788e654f8 --- tools/releasetools/validate_target_files.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/releasetools/validate_target_files.py b/tools/releasetools/validate_target_files.py index 69be5119ab..30bed8de3d 100755 --- a/tools/releasetools/validate_target_files.py +++ b/tools/releasetools/validate_target_files.py @@ -236,6 +236,15 @@ def ValidateInstallRecoveryScript(input_tmp, info_dict): logging.info('Done checking %s', script_path) +# Symlink files in `src` to `dst`, if the files do not +# already exists in `dst` directory. +def symlinkIfNotExists(src, dst): + if not os.path.isdir(src): + return + for filename in os.listdir(src): + if os.path.exists(os.path.join(dst, filename)): + continue + os.symlink(os.path.join(src, filename), os.path.join(dst, filename)) def ValidateVerifiedBootImages(input_tmp, info_dict, options): """Validates the Verified Boot related images. @@ -257,6 +266,12 @@ def ValidateVerifiedBootImages(input_tmp, info_dict, options): Raises: AssertionError: On any verification failure. """ + # See bug 159299583 + # After commit 5277d1015, some images (e.g. acpio.img and tos.img) are no + # longer copied from RADIO to the IMAGES folder. But avbtool assumes that + # images are in IMAGES folder. So we symlink them. + symlinkIfNotExists(os.path.join(input_tmp, "RADIO"), + os.path.join(input_tmp, "IMAGES")) # Verified boot 1.0 (images signed with boot_signer and verity_signer). if info_dict.get('boot_signer') == 'true': logging.info('Verifying Verified Boot images...')