diff --git a/core/Makefile b/core/Makefile index 2db3a2e738..ac8129abdb 100644 --- a/core/Makefile +++ b/core/Makefile @@ -7138,6 +7138,7 @@ PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \ $(OTA_FROM_TARGET_FILES) \ --verbose \ --path $(HOST_OUT) \ + --backup=$(backuptool) \ $(if $(OEM_OTA_CONFIG), --oem_settings $(OEM_OTA_CONFIG)) \ $(if $(BOOT_VAR_OTA_CONFIG), --boot_variable_file $(BOOT_VAR_OTA_CONFIG)) \ $(2) \ @@ -7155,6 +7156,16 @@ INTERNAL_OTA_METADATA := $(PRODUCT_OUT)/ota_metadata $(call declare-0p-target,$(INTERNAL_OTA_METADATA)) +ifeq ($(TARGET_BUILD_VARIANT),user) + $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := false +else +ifneq ($(CUSTOM_BUILD),) + $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := true +else + $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := false +endif +endif + $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR) $(INTERNAL_OTA_PACKAGE_TARGET): .KATI_IMPLICIT_OUTPUTS := $(INTERNAL_OTA_METADATA) $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_DIR) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES) diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py index e02b2aedb9..40f85ea721 100644 --- a/tools/releasetools/edify_generator.py +++ b/tools/releasetools/edify_generator.py @@ -156,6 +156,20 @@ class EdifyGenerator(object): ");") self.script.append(self.WordWrap(cmd)) + def RunBackup(self, command, mount_point, dynamic=False): + systemEntry = self.fstab[mount_point] + if dynamic: + for p in ["vendor", "product", "system_ext"]: + fstabEntry = self.fstab.get("/"+p, None) + if fstabEntry: + self.script.append('map_partition("%s");' % (fstabEntry.device,)) + + self.script.append(('run_program("/tmp/install/bin/backuptool.sh", "%s", map_partition("%s"), "%s");' % ( + command, systemEntry.device, systemEntry.fs_type))) + else: + self.script.append(('run_program("/tmp/install/bin/backuptool.sh", "%s", "%s", "%s");' % ( + command, systemEntry.device, systemEntry.fs_type))) + def ShowProgress(self, frac, dur): """Update the progress bar, advancing it over 'frac' over the next 'dur' seconds. 'dur' may be zero to advance it via SetProgress @@ -248,6 +262,12 @@ class EdifyGenerator(object): p.mount_point, mount_flags)) self.mounts.add(p.mount_point) + def Unmount(self, mount_point): + """Unmount the partition with the given mount_point.""" + if mount_point in self.mounts: + self.mounts.remove(mount_point) + self.script.append('unmount("%s");' % (mount_point,)) + def UnpackPackageDir(self, src, dst): """Unpack a given directory from the OTA package into the given destination directory.""" diff --git a/tools/releasetools/non_ab_ota.py b/tools/releasetools/non_ab_ota.py index 4b8c20fc59..c1a7c00341 100644 --- a/tools/releasetools/non_ab_ota.py +++ b/tools/releasetools/non_ab_ota.py @@ -221,6 +221,14 @@ else if get_stage("%(bcb_dev)s") == "3/3" then script.SetPermissionsRecursive("/tmp/install", 0, 0, 0o755, 0o644, None, None) script.SetPermissionsRecursive("/tmp/install/bin", 0, 0, 0o755, 0o755, None, None) + if target_info.get("system_root_image") == "true": + sysmount = "/" + else: + sysmount = "/system" + + if OPTIONS.backuptool: + script.RunBackup("backup", sysmount, target_info.get('use_dynamic_partitions') == "true") + # All other partitions as well as the data wipe use 10% of the progress, and # the update of the system partition takes the remaining progress. system_progress = 0.9 - (len(block_diff_dict) - 1) * 0.1 @@ -254,6 +262,10 @@ else if get_stage("%(bcb_dev)s") == "3/3" then device_specific.FullOTA_PostValidate() + if OPTIONS.backuptool: + script.ShowProgress(0.02, 10) + script.RunBackup("restore", sysmount, target_info.get('use_dynamic_partitions') == "true") + script.WriteRawImage("/boot", "boot.img") script.ShowProgress(0.1, 10) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 6446e1ff59..2e82684ad2 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -268,6 +268,9 @@ A/B OTA specific options --full_ota_partitions Specify list of partitions should be updated in full OTA fashion, even if an incremental OTA is about to be generated + --backup + Enable or disable the execution of backuptool.sh. + Disabled by default. """ from __future__ import print_function @@ -342,6 +345,7 @@ OPTIONS.max_threads = None OPTIONS.vabc_cow_version = None OPTIONS.compression_factor = None OPTIONS.full_ota_partitions = None +OPTIONS.backuptool = False POSTINSTALL_CONFIG = 'META/postinstall_config.txt' @@ -1336,6 +1340,8 @@ def main(argv): elif o == "--full_ota_partitions": OPTIONS.full_ota_partitions = set( a.strip().strip("\"").strip("'").split(",")) + elif o == "--backup": + OPTIONS.backuptool = True else: return False return True @@ -1387,6 +1393,7 @@ def main(argv): "vabc_cow_version=", "compression_factor=", "full_ota_partitions=", + "backup=", ], extra_option_handler=[option_handler, payload_signer.signer_options]) common.InitLogging()