Moving recovery resources from /system to /vendor
This change is part of a topic that moves the recovery resources from the
system partition to the vendor partition, if it exists, or the vendor directory
on the system partition otherwise. The recovery resources are moving from the
system image to the vendor partition so that a single system image may be used
with either an A/B or a non-A/B vendor image. The topic removes a delta in the
system image that prevented such reuse in the past.
The recovery resources that are moving are involved with updating the recovery
partition after an update. In a non-A/B configuration, the system boots from
the recovery partition, updates the other partitions (system, vendor, etc.)
Then, the next time the system boots normally, a script updates the recovery
partition (if necessary). This script, the executables it invokes, and the data
files that it uses were previously on the system partition. The resources that
are moving include the following.
* install-recovery.sh
* applypatch
* recovery-resource.dat (if present)
* recovery-from-boot.p (if present)
This change includes the platform build system and release tools changes to
move the recovery resources from system to vendor (or /system/vendor). The
release tools need to know where to generate the recovery patch, and they
discover this from misc_info.txt variable board_uses_vendorimage, which the
platform build system generates.
We remove applypatch from PRODUCT_PACKAGES, but it is added back as a required
module in target/product/base_vendor.mk.
Several release tools rely on the misc_info.txt board_uses_vendorimage variable
to know how to generate and detect the recovery patch.
This change partially removes the --rebuild_recovery flag from the
merge_target_files.py script. The flag will be fully removed in a follow-on
change.
Bug: 68319577
Test: Ensure that recovery partition is updated correctly.
Change-Id: Ia4045bd67ffb3d899efa8d20dab4c4299b87ee5f
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index a5816bc..1a1f6fd 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -165,9 +165,12 @@
else:
common.ZipWrite(output_zip, output_file, arc_name)
- if (OPTIONS.rebuild_recovery and recovery_img is not None and
- boot_img is not None):
- logger.info("Building new recovery patch")
+ board_uses_vendorimage = OPTIONS.info_dict.get(
+ "board_uses_vendorimage") == "true"
+
+ if (OPTIONS.rebuild_recovery and not board_uses_vendorimage and
+ recovery_img is not None and boot_img is not None):
+ logger.info("Building new recovery patch on system at system/vendor")
common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,
boot_img, info_dict=OPTIONS.info_dict)
@@ -190,7 +193,7 @@
CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "system_other", img)
-def AddVendor(output_zip):
+def AddVendor(output_zip, recovery_img=None, boot_img=None):
"""Turn the contents of VENDOR into a vendor image and store in it
output_zip."""
@@ -199,6 +202,27 @@
logger.info("vendor.img already exists; no need to rebuild...")
return img.name
+ def output_sink(fn, data):
+ ofile = open(os.path.join(OPTIONS.input_tmp, "VENDOR", fn), "w")
+ ofile.write(data)
+ ofile.close()
+
+ if output_zip:
+ arc_name = "VENDOR/" + fn
+ if arc_name in output_zip.namelist():
+ OPTIONS.replace_updated_files_list.append(arc_name)
+ else:
+ common.ZipWrite(output_zip, ofile.name, arc_name)
+
+ board_uses_vendorimage = OPTIONS.info_dict.get(
+ "board_uses_vendorimage") == "true"
+
+ if (OPTIONS.rebuild_recovery and board_uses_vendorimage and
+ recovery_img is not None and boot_img is not None):
+ logger.info("Building new recovery patch on vendor")
+ common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,
+ boot_img, info_dict=OPTIONS.info_dict)
+
block_list = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.map")
CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "vendor", img,
block_list=block_list)
@@ -781,7 +805,8 @@
if has_vendor:
banner("vendor")
- partitions['vendor'] = AddVendor(output_zip)
+ partitions['vendor'] = AddVendor(
+ output_zip, recovery_img=recovery_image, boot_img=boot_image)
if has_product:
banner("product")
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 974d4b0..04c721d 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -2535,13 +2535,25 @@
info_dict = OPTIONS.info_dict
full_recovery_image = info_dict.get("full_recovery_image") == "true"
+ board_uses_vendorimage = info_dict.get("board_uses_vendorimage") == "true"
+
+ if board_uses_vendorimage:
+ # In this case, the output sink is rooted at VENDOR
+ recovery_img_path = "etc/recovery.img"
+ recovery_resource_dat_path = "VENDOR/etc/recovery-resource.dat"
+ sh_dir = "bin"
+ else:
+ # In this case the output sink is rooted at SYSTEM
+ recovery_img_path = "vendor/etc/recovery.img"
+ recovery_resource_dat_path = "SYSTEM/vendor/etc/recovery-resource.dat"
+ sh_dir = "vendor/bin"
if full_recovery_image:
- output_sink("etc/recovery.img", recovery_img.data)
+ output_sink(recovery_img_path, recovery_img.data)
else:
system_root_image = info_dict.get("system_root_image") == "true"
- path = os.path.join(input_dir, "SYSTEM", "etc", "recovery-resource.dat")
+ path = os.path.join(input_dir, recovery_resource_dat_path)
# With system-root-image, boot and recovery images will have mismatching
# entries (only recovery has the ramdisk entry) (Bug: 72731506). Use bsdiff
# to handle such a case.
@@ -2554,7 +2566,7 @@
if os.path.exists(path):
diff_program.append("-b")
diff_program.append(path)
- bonus_args = "--bonus /system/etc/recovery-resource.dat"
+ bonus_args = "--bonus /vendor/etc/recovery-resource.dat"
else:
bonus_args = ""
@@ -2571,10 +2583,16 @@
return
if full_recovery_image:
- sh = """#!/system/bin/sh
+
+ # Note that we use /vendor to refer to the recovery resources. This will
+ # work for a separate vendor partition mounted at /vendor or a
+ # /system/vendor subdirectory on the system partition, for which init will
+ # create a symlink from /vendor to /system/vendor.
+
+ sh = """#!/vendor/bin/sh
if ! applypatch --check %(type)s:%(device)s:%(size)d:%(sha1)s; then
applypatch \\
- --flash /system/etc/recovery.img \\
+ --flash /vendor/etc/recovery.img \\
--target %(type)s:%(device)s:%(size)d:%(sha1)s && \\
log -t recovery "Installing new recovery image: succeeded" || \\
log -t recovery "Installing new recovery image: failed"
@@ -2586,10 +2604,10 @@
'sha1': recovery_img.sha1,
'size': recovery_img.size}
else:
- sh = """#!/system/bin/sh
+ sh = """#!/vendor/bin/sh
if ! applypatch --check %(recovery_type)s:%(recovery_device)s:%(recovery_size)d:%(recovery_sha1)s; then
applypatch %(bonus_args)s \\
- --patch /system/recovery-from-boot.p \\
+ --patch /vendor/recovery-from-boot.p \\
--source %(boot_type)s:%(boot_device)s:%(boot_size)d:%(boot_sha1)s \\
--target %(recovery_type)s:%(recovery_device)s:%(recovery_size)d:%(recovery_sha1)s && \\
log -t recovery "Installing new recovery image: succeeded" || \\
@@ -2607,9 +2625,9 @@
'recovery_device': recovery_device,
'bonus_args': bonus_args}
- # The install script location moved from /system/etc to /system/bin
- # in the L release.
- sh_location = "bin/install-recovery.sh"
+ # The install script location moved from /system/etc to /system/bin in the L
+ # release. In the R release it is in VENDOR/bin or SYSTEM/vendor/bin.
+ sh_location = os.path.join(sh_dir, "install-recovery.sh")
logger.info("putting script in %s", sh_location)
diff --git a/tools/releasetools/make_recovery_patch.py b/tools/releasetools/make_recovery_patch.py
index 725b355..1497d69 100644
--- a/tools/releasetools/make_recovery_patch.py
+++ b/tools/releasetools/make_recovery_patch.py
@@ -47,8 +47,17 @@
if not recovery_img or not boot_img:
sys.exit(0)
+ board_uses_vendorimage = OPTIONS.info_dict.get(
+ "board_uses_vendorimage") == "true"
+
+ if board_uses_vendorimage:
+ target_files_dir = "VENDOR"
+ else:
+ target_files_dir = "SYSTEM"
+
def output_sink(fn, data):
- with open(os.path.join(output_dir, "SYSTEM", *fn.split("/")), "wb") as f:
+ with open(os.path.join(output_dir, target_files_dir,
+ *fn.split("/")), "wb") as f:
f.write(data)
common.MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img)
diff --git a/tools/releasetools/merge_target_files.py b/tools/releasetools/merge_target_files.py
index ba70986..544f996 100755
--- a/tools/releasetools/merge_target_files.py
+++ b/tools/releasetools/merge_target_files.py
@@ -68,8 +68,7 @@
files package and saves it at this path.
--rebuild_recovery
- Rebuild the recovery patch used by non-A/B devices and write it to the
- system image.
+ Deprecated; does nothing.
--keep-tmp
Keep tempoary files for debugging purposes.
@@ -106,6 +105,7 @@
OPTIONS.output_ota = None
OPTIONS.output_img = None
OPTIONS.output_super_empty = None
+# TODO(b/132730255): Remove this option.
OPTIONS.rebuild_recovery = False
OPTIONS.keep_tmp = False
@@ -372,32 +372,6 @@
write_sorted_data(data=output_ab_partitions, path=output_ab_partitions_txt)
-def append_recovery_to_filesystem_config(output_target_files_temp_dir):
- """Performs special processing for META/filesystem_config.txt.
-
- This function appends recovery information to META/filesystem_config.txt so
- that recovery patch regeneration will succeed.
-
- Args:
- output_target_files_temp_dir: The name of a directory that will be used to
- create the output target files package after all the special cases are
- processed. We find filesystem_config.txt here.
- """
-
- filesystem_config_txt = os.path.join(output_target_files_temp_dir, 'META',
- 'filesystem_config.txt')
-
- with open(filesystem_config_txt, 'a') as f:
- # TODO(bpeckham) this data is hard coded. It should be generated
- # programmatically.
- f.write('system/bin/install-recovery.sh 0 0 750 '
- 'selabel=u:object_r:install_recovery_exec:s0 capabilities=0x0\n')
- f.write('system/recovery-from-boot.p 0 0 644 '
- 'selabel=u:object_r:system_file:s0 capabilities=0x0\n')
- f.write('system/etc/recovery.img 0 0 440 '
- 'selabel=u:object_r:install_recovery_exec:s0 capabilities=0x0\n')
-
-
def process_misc_info_txt(framework_target_files_temp_dir,
vendor_target_files_temp_dir,
output_target_files_temp_dir,
@@ -594,7 +568,7 @@
def process_special_cases(framework_target_files_temp_dir,
vendor_target_files_temp_dir,
output_target_files_temp_dir,
- framework_misc_info_keys, rebuild_recovery):
+ framework_misc_info_keys):
"""Performs special-case processing for certain target files items.
Certain files in the output target files package require special-case
@@ -611,8 +585,6 @@
framework_misc_info_keys: A list of keys to obtain from the framework
instance of META/misc_info.txt. The remaining keys from the vendor
instance.
- rebuild_recovery: If true, rebuild the recovery patch used by non-A/B
- devices and write it to the system image.
"""
if 'ab_update' in framework_misc_info_keys:
@@ -621,10 +593,6 @@
vendor_target_files_temp_dir=vendor_target_files_temp_dir,
output_target_files_temp_dir=output_target_files_temp_dir)
- if rebuild_recovery:
- append_recovery_to_filesystem_config(
- output_target_files_temp_dir=output_target_files_temp_dir)
-
copy_file_contexts(
framework_target_files_dir=framework_target_files_temp_dir,
vendor_target_files_dir=vendor_target_files_temp_dir,
@@ -757,8 +725,7 @@
framework_target_files_temp_dir=framework_target_files_temp_dir,
vendor_target_files_temp_dir=vendor_target_files_temp_dir,
output_target_files_temp_dir=output_target_files_temp_dir,
- framework_misc_info_keys=framework_misc_info_keys,
- rebuild_recovery=rebuild_recovery)
+ framework_misc_info_keys=framework_misc_info_keys)
return output_target_files_temp_dir
@@ -779,6 +746,7 @@
add_img_args = ['--verbose']
add_img_args.append('--add_missing')
+ # TODO(b/132730255): Remove this if statement.
if rebuild_recovery:
add_img_args.append('--rebuild_recovery')
add_img_args.append(target_files_dir)
@@ -1016,7 +984,7 @@
OPTIONS.output_img = a
elif o == '--output-super-empty':
OPTIONS.output_super_empty = a
- elif o == '--rebuild_recovery':
+ elif o == '--rebuild_recovery': # TODO(b/132730255): Warn
OPTIONS.rebuild_recovery = True
elif o == '--keep-tmp':
OPTIONS.keep_tmp = True
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index de947f3..3fc3c22 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -731,10 +731,19 @@
script.WriteRawImage("/boot", "recovery.img")
-def HasRecoveryPatch(target_files_zip):
+def HasRecoveryPatch(target_files_zip, info_dict):
+ board_uses_vendorimage = info_dict.get("board_uses_vendorimage") == "true"
+
+ if board_uses_vendorimage:
+ target_files_dir = "VENDOR"
+ else:
+ target_files_dir = "SYSTEM/vendor"
+
+ patch = "%s/recovery-from-boot.p" % target_files_dir
+ img = "%s/etc/recovery.img" %target_files_dir
+
namelist = [name for name in target_files_zip.namelist()]
- return ("SYSTEM/recovery-from-boot.p" in namelist or
- "SYSTEM/etc/recovery.img" in namelist)
+ return (patch in namelist or img in namelist)
def HasPartition(target_files_zip, partition):
@@ -925,7 +934,7 @@
metadata=metadata,
info_dict=OPTIONS.info_dict)
- assert HasRecoveryPatch(input_zip)
+ assert HasRecoveryPatch(input_zip, info_dict=OPTIONS.info_dict)
# Assertions (e.g. downgrade check, device properties check).
ts = target_info.GetBuildProp("ro.build.date.utc")
diff --git a/tools/releasetools/validate_target_files.py b/tools/releasetools/validate_target_files.py
index c299a48..a5e1930 100755
--- a/tools/releasetools/validate_target_files.py
+++ b/tools/releasetools/validate_target_files.py
@@ -138,7 +138,7 @@
1. full recovery:
...
if ! applypatch --check type:device:size:sha1; then
- applypatch --flash /system/etc/recovery.img \\
+ applypatch --flash /vendor/etc/recovery.img \\
type:device:size:sha1 && \\
...
@@ -146,18 +146,26 @@
...
if ! applypatch --check type:recovery_device:recovery_size:recovery_sha1; then
applypatch [--bonus bonus_args] \\
- --patch /system/recovery-from-boot.p \\
+ --patch /vendor/recovery-from-boot.p \\
--source type:boot_device:boot_size:boot_sha1 \\
--target type:recovery_device:recovery_size:recovery_sha1 && \\
...
- For full recovery, we want to calculate the SHA-1 of /system/etc/recovery.img
+ For full recovery, we want to calculate the SHA-1 of /vendor/etc/recovery.img
and compare it against the one embedded in the script. While for recovery
from boot, we want to check the SHA-1 for both recovery.img and boot.img
under IMAGES/.
"""
- script_path = 'SYSTEM/bin/install-recovery.sh'
+ board_uses_vendorimage = info_dict.get("board_uses_vendorimage") == "true"
+
+ if board_uses_vendorimage:
+ script_path = 'VENDOR/bin/install-recovery.sh'
+ recovery_img = 'VENDOR/etc/recovery.img'
+ else:
+ script_path = 'SYSTEM/vendor/bin/install-recovery.sh'
+ recovery_img = 'SYSTEM/vendor/etc/recovery.img'
+
if not os.path.exists(os.path.join(input_tmp, script_path)):
logging.info('%s does not exist in input_tmp', script_path)
return
@@ -188,7 +196,7 @@
# Validate the SHA-1 of the recovery image.
recovery_sha1 = flash_partition.split(':')[3]
ValidateFileAgainstSha1(
- input_tmp, 'recovery.img', 'SYSTEM/etc/recovery.img', recovery_sha1)
+ input_tmp, 'recovery.img', recovery_img, recovery_sha1)
else:
assert len(lines) == 11, "Invalid line count: {}".format(lines)