|
| 1 | +From 105e08518e96424d9a8deaead77290baea906f42 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Zhaofeng Li < [email protected]> |
| 3 | +Date: Sat, 6 Nov 2021 12:48:25 -0700 |
| 4 | +Subject: [PATCH] Add option to include prebuilt images when signing target |
| 5 | + files. |
| 6 | + |
| 7 | +Adapted from original CL from Greg Ross < [email protected]>: |
| 8 | +https://review.lineageos.org/c/LineageOS/android_build/+/277134 |
| 9 | + |
| 10 | +When producing a signed build using sign_target_files_apks.py and a prebuilt |
| 11 | +vendor.img (or other prebuilt images that are to be included in the final zip) |
| 12 | +sign_target_files_apks.py must be told to include the prebuilt images or they |
| 13 | +will not be included in the final file. |
| 14 | + |
| 15 | +The build process uses the make configuration statements |
| 16 | +BOARD_PREBUILT_VENDORIMAGE and AB_OTA_PARTITIONS to inform the build process |
| 17 | +to add the image files, however since sign_target_files_apks.py is not part |
| 18 | +of the make system, it does not know about these configuration settings. |
| 19 | + |
| 20 | +This patch therefore adds a new command line option to the |
| 21 | +sign_target_files_apks.py script to allow the user to add one or more images |
| 22 | +to the signed-target_files.zip that is produced. |
| 23 | + |
| 24 | +The command line option has the following format: |
| 25 | + |
| 26 | + --prebuilt_image <path to prebuilt image> |
| 27 | + Specify a path to a prebuilt image file, to be added to the |
| 28 | + signed_target-files.zip. This option may be repeated to add multiple |
| 29 | + images. |
| 30 | + |
| 31 | +Change-Id: Id906b2e32797f95b0ee47859036ba31ea7975b64 |
| 32 | +--- |
| 33 | + tools/releasetools/sign_target_files_apks.py | 30 ++++++++++++++++++++ |
| 34 | + 1 file changed, 30 insertions(+) |
| 35 | + |
| 36 | +diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py |
| 37 | +index 0842af9018..b160a21c67 100755 |
| 38 | +--- a/tools/releasetools/sign_target_files_apks.py |
| 39 | ++++ b/tools/releasetools/sign_target_files_apks.py |
| 40 | +@@ -136,6 +136,11 @@ Usage: sign_target_files_apks [flags] input_target_files output_target_files |
| 41 | + |
| 42 | + --android_jar_path <path> |
| 43 | + Path to the android.jar to repack the apex file. |
| 44 | ++ |
| 45 | ++ --prebuilt_image <path to prebuilt image> |
| 46 | ++ Specify a path to a prebuilt image file, to be added to the |
| 47 | ++ signed_target-files.zip. This option may be repeated to add multiple |
| 48 | ++ images. |
| 49 | + """ |
| 50 | + |
| 51 | + from __future__ import print_function |
| 52 | +@@ -173,6 +178,7 @@ OPTIONS = common.OPTIONS |
| 53 | + |
| 54 | + OPTIONS.extra_apks = {} |
| 55 | + OPTIONS.extra_apex_payload_keys = {} |
| 56 | ++OPTIONS.prebuilt_images = [] |
| 57 | + OPTIONS.skip_apks_with_path_prefix = set() |
| 58 | + OPTIONS.key_map = {} |
| 59 | + OPTIONS.rebuild_recovery = False |
| 60 | +@@ -1190,6 +1196,8 @@ def main(argv): |
| 61 | + names = names.split(",") |
| 62 | + for n in names: |
| 63 | + OPTIONS.extra_apks[n] = key |
| 64 | ++ elif o == "--prebuilt_image": |
| 65 | ++ OPTIONS.prebuilt_images.append(a) |
| 66 | + elif o == "--extra_apex_payload_key": |
| 67 | + apex_name, key = a.split("=") |
| 68 | + OPTIONS.extra_apex_payload_keys[apex_name] = key |
| 69 | +@@ -1339,6 +1347,7 @@ def main(argv): |
| 70 | + "gki_signing_key=", |
| 71 | + "gki_signing_algorithm=", |
| 72 | + "gki_signing_extra_args=", |
| 73 | ++ "prebuilt_image=", |
| 74 | + ], |
| 75 | + extra_option_handler=option_handler) |
| 76 | + |
| 77 | +@@ -1381,6 +1390,23 @@ def main(argv): |
| 78 | + platform_api_level, codename_to_api_level_map, |
| 79 | + compressed_extension) |
| 80 | + |
| 81 | ++ if OPTIONS.prebuilt_images: |
| 82 | ++ # Ugly Nix-specific HACK: The source file may be read-only |
| 83 | ++ # ZipWrite really, really wants to chmod the file :( |
| 84 | ++ # Delete all lines containing HACK |
| 85 | ++ tempdir = tempfile.mkdtemp() # HACK |
| 86 | ++ |
| 87 | ++ for prebuilt_image in OPTIONS.prebuilt_images: |
| 88 | ++ image_name = os.path.basename(prebuilt_image) |
| 89 | ++ |
| 90 | ++ temp = os.path.join(tempdir, image_name) # HACK |
| 91 | ++ shutil.copy(prebuilt_image, temp) # HACK |
| 92 | ++ prebuilt_image = temp # HACK |
| 93 | ++ |
| 94 | ++ common.ZipWrite(output_zip, prebuilt_image, os.path.join("IMAGES/", image_name)) |
| 95 | ++ |
| 96 | ++ shutil.rmtree(tempdir) # HACK |
| 97 | ++ |
| 98 | + common.ZipClose(input_zip) |
| 99 | + common.ZipClose(output_zip) |
| 100 | + |
| 101 | +@@ -1390,6 +1416,10 @@ def main(argv): |
| 102 | + # recovery patch is guaranteed to be regenerated there. |
| 103 | + if OPTIONS.rebuild_recovery: |
| 104 | + new_args.append("--rebuild_recovery") |
| 105 | ++ |
| 106 | ++ if OPTIONS.prebuilt_images: |
| 107 | ++ new_args.append("--add_missing") |
| 108 | ++ |
| 109 | + new_args.append(args[1]) |
| 110 | + add_img_to_target_files.main(new_args) |
| 111 | + |
| 112 | +-- |
| 113 | +2.33.0 |
| 114 | + |
0 commit comments