Support regenerating partition table with bpttool in sign_target_files_apks
For Android Things targets (or any other target which has
BOARD_BPT_INPUT_FILES defined), add_img_to_target_files will generate a
partition-table.img using bpttool. It also adds the final combined .bpt
definition file into target-files in IMAGES/partition-table.bpt.
When we're signing using sign_target_files_apks, add_img_to_target_files
needs to regenerate the partition table, but META/misc_info.txt still
contains the original list of bpt input files from the build that aren't
available. This change extracts the final bpt from the input
target-files, adds it to META/ in the output target-files, and then
updates the board_bpt_input_files property to point to it.
Bug: 72837107
Test: Local sign_target_files_apks run of locally built target-files
Change-Id: Id79125208f31c78b1ac2079172f9c91a9203849b
diff --git a/core/Makefile b/core/Makefile
index 706b371..781bc27 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2352,6 +2352,7 @@
$(HOST_OUT_EXECUTABLES)/delta_generator \
$(AVBTOOL) \
$(BLK_ALLOC_TO_BASE_FS) \
+ $(BPTTOOL) \
$(BROTLI) \
$(BUILD_VERITY_METADATA) \
$(BUILD_VERITY_TREE)
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 14d0ca4..1deb031 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -222,6 +222,15 @@
vendor_base_fs_file,))
del d["vendor_base_fs_file"]
+ # If board_bpt_input_files property is defined then bpttool is being used to
+ # generate the partition table. When signing target-files, the combined
+ # partition table definition is copied into META/partition-table.bpt since
+ # the original input files aren't available.
+ if "board_bpt_input_files" in d:
+ board_bpt_input_files = os.path.join(input_dir, "META", "partition-table.bpt")
+ if os.path.exists(board_bpt_input_files):
+ d["board_bpt_input_files"] = board_bpt_input_files
+
def makeint(key):
if key in d:
d[key] = int(d[key], 0)
diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py
index fa62c8f..5369702 100755
--- a/tools/releasetools/sign_target_files_apks.py
+++ b/tools/releasetools/sign_target_files_apks.py
@@ -248,6 +248,15 @@
system_root_image = misc_info.get("system_root_image") == "true"
for info in input_tf_zip.infolist():
+ # If it exists, copy bpt partition table definition into META/ to use when
+ # recreating partition table.
+ if (info.filename == "IMAGES/partition-table.bpt"):
+ data = input_tf_zip.read(info.filename)
+ out_info = copy.copy(info)
+ out_info.filename = "META/partition-table.bpt"
+ common.ZipWriteStr(output_tf_zip, out_info, data)
+
+ # Skip all other files in IMAGES/
if info.filename.startswith("IMAGES/"):
continue