Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 826ba325 authored by Chris Soyars's avatar Chris Soyars Committed by Michael Bestas
Browse files

releasetools: squash backuptool support

This is a squash of the following commits:

Author: Chris Soyars <ctso@ctso.me>
Date:   Thu Dec 23 00:44:33 2010 +0100
    Add otapackage support for backuptool

    Change-Id: I512554c579d444067cd3ccbb0e6946a5eb6bc964a

    Modular backuptool.sh.  Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts.

    * Copy backuptool.functions alongside backuptool.sh.
    * Delete both from /system/bin as they are not useful there.

    Patch Series
    ============
    http://review.cyanogenmod.com/#change,13265
    CyanogenMod/android_build
      * edify generator
    http://review.cyanogenmod.com/#change,13266
    CyanogenMod/android_system_core
      * permissions on /system/addon.d
    http://review.cyanogenmod.com/#change,13267


    CyanogenMod/android_vendor_cm
      * 50-cm.sh reference backup script
      * modular backuptool.sh
      * support backuptool.functions used by /system/addon.d/*.sh scripts

    Change-Id: I26b4907d28f49c69627699d2accd2f0fa2d1b112

    update ota_from_target_files to handle mounting/unmounting for backupscript

    backupscript should not be mounting/unmounting itself as it makes other
    scripts have unexpected results (such as modelid_cfg, which expects /system
    to be mounted)

    instead have the ota script handle the mounting/unmounting

    Change-Id: I94511f4147c624d975cb3ecbeaa8b0e98f63437c

    build: Don't run backuptool on GMS builds

    Change-Id: I5dde27f9d16b88049171db9805221d92e67f3e5d

Author: Tom Marshall <tdm@cyngn.com>
Date:   Wed Apr 9 16:14:07 2014 -0700
    build: edify: use set_metadata for backuptool

    Also use saner permissions on backuptool.sh

    Change-Id: I50742b51867aa358f5924b8dc208833092a35bd9

Author: Ricardo Cerqueira <ricardo@cyngn.com>
Date:   Wed Nov 5 18:16:43 2014 +0000
    ota: Include copies of the recovery scripts even if shipping in block mode

Author: Ricardo Cerqueira <ricardo@cyngn.com>
Date:   Wed Nov 5 19:58:59 2014 +0000
    ota: Fix recovery-script cleanups in block mode

    Change-Id: Iadb480f8062cfb7a0e6c9024e32ac0d71a7481d7

Author: Arian <arian.kulmer@web.de>
Date:   Wed Jun 17 12:35:16 2020 +0200
    build: Disable backuptool on user instead of GMS builds

    * Backuptool is not exclusively used for GApps but
      also used by other things (i.e. Magisk), hence
      it shouldn't be disabled on all GMS builds.

    Change-Id: Ia95c6fed21d7bed5e2e0610aa94264edc1d02c80

Author: Davide Garberi <dade.garberi@gmail.com>
Date:   Tue Sep 24 18:45:17 2019 +0200
    releasetools: Move system mount handling to backuptool

    * This allows the ROM to be flashed on any recovery, whether it mounts
      system to /system, /system_root or /mnt/system like Q recovery

    * Remove any type of system mount with static paths from updater-script
      to figure out the path dinamically through backuptool

    Change-Id: I7b33726305cb6f3eec146d26135f0081002a25dc

Author: Jesse Chan <jc@lineageos.org>
Date:   Fri Jun 12 21:53:18 2020 +0800
    releasetools: support dynamic partitions for backuptool

    Change-Id: I4a04e52f64e307a9852d786aabf17975a020b4b8
    Signed-off-by: default avatarJesse Chan <jc@lineageos.org>

Author: Jesse Chan <jc@lineageos.org>
Date:   Tue Jul 7 23:50:10 2020 +0800

    backuptool: do not unmap dynamic partition after finished

    Keep partitions mapped so users can install addons.

    Change-Id: Ic70621986bf136775e686dc8cc690ce076485907
    Signed-off-by: default avatarJesse Chan <jc@lineageos.org>

Author: Alessandro Astone <ales.astone@gmail.com>
Date:   Mon Apr 12 18:40:10 2021 +0200

    backuptool: Map extra dynamic partitions for Addon.d V3

    Change-Id: Ia8fa1963c722c5aa2987b947e4e919e19909a9a8

Change-Id: I2401d334d8e16d18d3770b339ec2c787dd8e477c
parent 8b3f7c0b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -6386,6 +6386,7 @@ PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
        --verbose \
        --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \
        --path $(HOST_OUT) \
        --backup=$(backuptool) \
        $(if $(OEM_OTA_CONFIG), --oem_settings $(OEM_OTA_CONFIG)) \
        $(2) \
        $(BUILT_TARGET_FILES_PACKAGE) $(1)
@@ -6402,6 +6403,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 ($(LINEAGE_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_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES)
+20 −0
Original line number Diff line number Diff line
@@ -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."""
+12 −0
Original line number Diff line number Diff line
@@ -220,6 +220,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
@@ -253,6 +261,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)
+8 −0
Original line number Diff line number Diff line
@@ -251,6 +251,10 @@ A/B OTA specific options

  --max_threads
      Specify max number of threads allowed when generating A/B OTA

  --backup <boolean>
      Enable or disable the execution of backuptool.sh.
      Disabled by default.
"""

from __future__ import print_function
@@ -325,6 +329,7 @@ OPTIONS.enable_lz4diff = False
OPTIONS.vabc_compression_param = None
OPTIONS.security_patch_level = None
OPTIONS.max_threads = None
OPTIONS.backuptool = False


POSTINSTALL_CONFIG = 'META/postinstall_config.txt'
@@ -1225,6 +1230,8 @@ def main(argv):
      else:
        raise ValueError("Cannot parse value %r for option %r - only "
                         "integers are allowed." % (a, o))
    elif o == "--backup":
      OPTIONS.backuptool = True
    else:
      return False
    return True
@@ -1277,6 +1284,7 @@ def main(argv):
                                 "vabc_compression_param=",
                                 "security_patch_level=",
                                 "max_threads=",
                                 "backup=",
                             ], extra_option_handler=option_handler)
  common.InitLogging()