Resolve conflict AVB rollback index location

Add an `--avb-resolve-rollback-index-location-conflict`
option in merge_target_files. When this option is set,
the merge tool will resolve conflicting index locations
by assigning the smallest unused index location.

This is to support merging system and vendor target files
from two different targets. In this case, the two target
files may have conflict rollback index location because
they were built independently.

Test: atest releasetools_test
Test: validate_target_files *-target_files-*.zip
Test: merge_target_files &&
        add_img_to_target_files &&
        img_from_target_files &&
        flash device
Bug: 300604688
Change-Id: Ibd18ef2a9f3784157fe17966f5364c3c81c9bd9f
This commit is contained in:
Dennis Song
2023-10-02 04:31:34 +00:00
parent d61f2efdbb
commit 4aae62ee77
5 changed files with 131 additions and 36 deletions

View File

@@ -42,6 +42,10 @@ Usage: add_img_to_target_files [flag] target_files
--is_signing
Skip building & adding the images for "userdata" and "cache" if we
are signing the target files.
--avb-resolve-rollback-index-location-conflict
If provided, resolve the conflict AVB rollback index location when
necessary.
"""
from __future__ import print_function
@@ -81,6 +85,7 @@ OPTIONS.add_missing = False
OPTIONS.rebuild_recovery = False
OPTIONS.replace_updated_files_list = []
OPTIONS.is_signing = False
OPTIONS.avb_resolve_rollback_index_location_conflict = False
def ParseAvbFooter(img_path) -> avbtool.AvbFooter:
@@ -682,7 +687,8 @@ def AddVBMeta(output_zip, partitions, name, needed_partitions):
logger.info("%s.img already exists; not rebuilding...", name)
return img.name
common.BuildVBMeta(img.name, partitions, name, needed_partitions)
common.BuildVBMeta(img.name, partitions, name, needed_partitions,
OPTIONS.avb_resolve_rollback_index_location_conflict)
img.Write()
return img.name
@@ -1224,6 +1230,8 @@ def main(argv):
" please switch to AVB")
elif o == "--is_signing":
OPTIONS.is_signing = True
elif o == "--avb_resolve_rollback_index_location_conflict":
OPTIONS.avb_resolve_rollback_index_location_conflict = True
else:
return False
return True
@@ -1233,7 +1241,8 @@ def main(argv):
extra_long_opts=["add_missing", "rebuild_recovery",
"replace_verity_public_key=",
"replace_verity_private_key=",
"is_signing"],
"is_signing",
"avb_resolve_rollback_index_location_conflict"],
extra_option_handler=option_handler)
if len(args) != 1: