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

Unverified Commit 30e43f85 authored by Chris Soyars's avatar Chris Soyars Committed by Michael Bestas
Browse files

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
parent 133e734e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -1945,6 +1945,16 @@ else
    OTA_FROM_TARGET_SCRIPT := $(TARGET_RELEASETOOL_OTA_FROM_TARGET_SCRIPT)
endif

ifeq ($(WITH_GMS),true)
    $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := false
else
ifneq ($(CM_BUILD),)
    $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := true
else
    $(INTERNAL_OTA_PACKAGE_TARGET): backuptool := false
endif
endif

$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
	@echo "Package OTA: $@"
	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
@@ -1952,6 +1962,7 @@ $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
	   --block \
	   -p $(HOST_OUT) \
	   -k $(KEY_CERT_PAIR) \
	   --backup=$(backuptool) \
	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
	   $(BUILT_TARGET_FILES_PACKAGE) $@

+1 −0
Original line number Diff line number Diff line
@@ -529,6 +529,7 @@ else
MKBOOTIMG := $(BOARD_CUSTOM_MKBOOTIMG)
endif
APICHECK := $(HOST_OUT_EXECUTABLES)/apicheck$(HOST_EXECUTABLE_SUFFIX)
MKIMAGE :=  $(HOST_OUT_EXECUTABLES)/mkimage$(HOST_EXECUTABLE_SUFFIX)
FS_GET_STATS := $(HOST_OUT_EXECUTABLES)/fs_get_stats$(HOST_EXECUTABLE_SUFFIX)
MAKE_EXT4FS := $(HOST_OUT_EXECUTABLES)/make_ext4fs$(HOST_EXECUTABLE_SUFFIX)
BLK_ALLOC_TO_BASE_FS := $(HOST_OUT_EXECUTABLES)/blk_alloc_to_base_fs$(HOST_EXECUTABLE_SUFFIX)
+16 −0
Original line number Diff line number Diff line
@@ -146,6 +146,16 @@ class EdifyGenerator(object):
           ");")
    self.script.append(self.WordWrap(cmd))

  def RunBackup(self, command):
    self.script.append('package_extract_file("system/bin/backuptool.sh", "/tmp/backuptool.sh");')
    self.script.append('package_extract_file("system/bin/backuptool.functions", "/tmp/backuptool.functions");')
    self.script.append('set_perm(0, 0, 0777, "/tmp/backuptool.sh");')
    self.script.append('set_perm(0, 0, 0644, "/tmp/backuptool.functions");')
    self.script.append(('run_program("/tmp/backuptool.sh", "%s");' % command))
    if command == "restore":
        self.script.append('delete("/system/bin/backuptool.sh");')
        self.script.append('delete("/system/bin/backuptool.functions");')

  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
@@ -217,6 +227,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."""
+17 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ Usage: ota_from_target_files [flags] input_target_files output_ota_package

  --payload_signer_args <args>
      Specify the arguments needed for payload signer.

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

import sys
@@ -174,6 +178,7 @@ OPTIONS.gen_verify = False
OPTIONS.log_diff = None
OPTIONS.payload_signer = None
OPTIONS.payload_signer_args = []
OPTIONS.backuptool = False

def MostPopularKey(d, default):
  """Given a dict, return the key corresponding to the largest
@@ -629,6 +634,11 @@ else if get_stage("%(bcb_dev)s") == "3/3" then

  device_specific.FullOTA_InstallBegin()

  if OPTIONS.backuptool:
    script.Mount("/system")
    script.RunBackup("backup")
    script.Unmount("/system")

  system_progress = 0.75

  if OPTIONS.wipe_user_data:
@@ -702,6 +712,10 @@ else if get_stage("%(bcb_dev)s") == "3/3" then
  common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)
  common.ZipWriteStr(output_zip, "boot.img", boot_img.data)

  if OPTIONS.backuptool:
    script.ShowProgress(0.02, 10)
    script.RunBackup("restore")

  script.ShowProgress(0.05, 5)
  script.WriteRawImage("/boot", "boot.img")

@@ -1949,6 +1963,8 @@ def main(argv):
      OPTIONS.payload_signer = a
    elif o == "--payload_signer_args":
      OPTIONS.payload_signer_args = shlex.split(a)
    elif o in ("--backup"):
      OPTIONS.backuptool = bool(a.lower() == 'true')
    else:
      return False
    return True
@@ -1980,6 +1996,7 @@ def main(argv):
                                 "log_diff=",
                                 "payload_signer=",
                                 "payload_signer_args=",
                                 "backup=",
                             ], extra_option_handler=option_handler)

  if len(args) != 2: