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

Commit c8b4e849 authored by Doug Zongker's avatar Doug Zongker
Browse files

full support for OTA of vendor partitions

Make vendor partition a first-class member of the OTA system (for
target_files that contain a VENDOR/ subdirectory).

Build vendor images in a way that is compatible with block-based OTA.
Support updating the vendor partition in both full and incremental,
block and file OTAs.  In most cases this is handled by refactoring the
existing code to handle the system partition to handle either, and
then calling it twice.

Currently we don't support incremental OTAs from a target-files
without a VENDOR subdirectory to one with one, or vice versa.  To add
or remove a vendor partition a full OTA will need to be done.

Bug: 15544685
Change-Id: I9cb9a1267060bd9683a9bea19b43a26b5a43800d
parent 4b445e89
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1335,8 +1335,10 @@ endif
	$(hide) ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
	@# Zip everything up, preserving symlinks
	$(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
	@# Run fs_config on all the system, boot ramdisk, and recovery ramdisk files in the zip, and save the output
	@# Run fs_config on all the system, vendor, boot ramdisk,
	@# and recovery ramdisk files in the zip, and save the output
	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM/" } /^SYSTEM\// {print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/filesystem_config.txt
	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="VENDOR/" } /^VENDOR\// {print "vendor/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/vendor_filesystem_config.txt
	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt
	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt
	$(hide) (cd $(zip_root) && zip -q ../$(notdir $@) META/*filesystem_config.txt)
+2 −2
Original line number Diff line number Diff line
@@ -1008,14 +1008,14 @@ def XZ(path):
  p.communicate()
  assert p.returncode == 0, "Couldn't compress patch"

def MakeSystemPatch(source_file, target_file):
def MakePartitionPatch(source_file, target_file, partition):
  with tempfile.NamedTemporaryFile() as output_file:
    XDelta3(source_file.name, target_file.name, output_file.name)
    XZ(output_file.name)
    with open(output_file.name + ".xz") as patch_file:
      patch_data = patch_file.read()
      os.unlink(patch_file.name)
      return File("system.muimg.p", patch_data)
      return File(partition + ".muimg.p", patch_data)

def MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img,
                      info_dict=None):
+3 −4
Original line number Diff line number Diff line
@@ -203,11 +203,10 @@ class EdifyGenerator(object):
                          p.device, p.length, p.mount_point))

  def WipeBlockDevice(self, partition):
    if partition != "/system":
      raise ValueError(("WipeBlockDevice currently only works "
                        "on /system, not %s\n") % (partition,))
    if partition not in ("/system", "/vendor"):
      raise ValueError(("WipeBlockDevice doesn't work on %s\n") % (partition,))
    fstab = self.info.get("fstab", None)
    size = self.info.get("system_size", None)
    size = self.info.get(partition.lstrip("/") + "_size", None)
    device = fstab[partition].device

    self.script.append('wipe_block_device("%s", %s);' % (device, size))
+40 −50
Original line number Diff line number Diff line
@@ -59,9 +59,21 @@ def AddSystem(output_zip, sparse=True):
  data = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse)
  common.ZipWriteStr(output_zip, "system.img", data)


def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
  print "creating system.img..."
  return CreateImage(input_dir, info_dict, "system",
                     sparse=sparse, map_file=map_file)

def AddVendor(output_zip, sparse=True):
  data = BuildVendor(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse)
  common.ZipWriteStr(output_zip, "vendor.img", data)

def BuildVendor(input_dir, info_dict, sparse=True, map_file=None):
  return CreateImage(input_dir, info_dict, "vendor",
                     sparse=sparse, map_file=map_file)


def CreateImage(input_dir, info_dict, what, sparse=True, map_file=None):
  print "creating " + what + ".img..."

  img = tempfile.NamedTemporaryFile()

@@ -69,8 +81,8 @@ def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
  # mkyaffs2image.  It wants "system" but we have a directory named
  # "SYSTEM", so create a symlink.
  try:
    os.symlink(os.path.join(input_dir, "SYSTEM"),
               os.path.join(input_dir, "system"))
    os.symlink(os.path.join(input_dir, what.upper()),
               os.path.join(input_dir, what))
  except OSError, e:
      # bogus error on my mac version?
      #   File "./build/tools/releasetools/img_from_target_files", line 86, in AddSystem
@@ -79,22 +91,28 @@ def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
    if (e.errno == errno.EEXIST):
      pass

  image_props = build_image.ImagePropFromGlobalDict(info_dict, "system")
  image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
  fstab = info_dict["fstab"]
  if fstab:
    image_props["fs_type" ] = fstab["/system"].fs_type
    image_props["fs_type" ] = fstab["/" + what].fs_type

  if what == "system":
    fs_config_prefix = ""
  else:
    fs_config_prefix = what + "_"

  fs_config = os.path.join(input_dir, "META/filesystem_config.txt")
  fs_config = os.path.join(
      input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
  if not os.path.exists(fs_config): fs_config = None

  fc_config = os.path.join(input_dir, "BOOT/RAMDISK/file_contexts")
  if not os.path.exists(fc_config): fc_config = None

  succ = build_image.BuildImage(os.path.join(input_dir, "system"),
  succ = build_image.BuildImage(os.path.join(input_dir, what),
                                image_props, img.name,
                                fs_config=fs_config,
                                fc_config=fc_config)
  assert succ, "build system.img image failed"
  assert succ, "build " + what + ".img image failed"

  mapdata = None

@@ -104,7 +122,7 @@ def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
  else:
    success, name = build_image.UnsparseImage(img.name, replace=False)
    if not success:
      assert False, "unsparsing system.img failed"
      assert False, "unsparsing " + what + ".img failed"

    if map_file:
      mmap = tempfile.NamedTemporaryFile()
@@ -131,45 +149,6 @@ def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
    return mapdata, data


def AddVendor(output_zip):
  """Turn the contents of VENDOR into vendor.img and store it in
  output_zip."""

  image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
                                                    "vendor")
  # The build system has to explicitly request for vendor.img.
  if "fs_type" not in image_props:
    return

  print "creating vendor.img..."

  img = tempfile.NamedTemporaryFile()

  # The name of the directory it is making an image out of matters to
  # mkyaffs2image.  It wants "vendor" but we have a directory named
  # "VENDOR", so create a symlink or an empty directory if VENDOR does not
  # exist.
  if not os.path.exists(os.path.join(OPTIONS.input_tmp, "vendor")):
    if os.path.exists(os.path.join(OPTIONS.input_tmp, "VENDOR")):
      os.symlink(os.path.join(OPTIONS.input_tmp, "VENDOR"),
                 os.path.join(OPTIONS.input_tmp, "vendor"))
    else:
      os.mkdir(os.path.join(OPTIONS.input_tmp, "vendor"))

  img = tempfile.NamedTemporaryFile()

  fstab = OPTIONS.info_dict["fstab"]
  if fstab:
    image_props["fs_type" ] = fstab["/vendor"].fs_type
  succ = build_image.BuildImage(os.path.join(OPTIONS.input_tmp, "vendor"),
                                image_props, img.name)
  assert succ, "build vendor.img image failed"

  common.CheckSize(img.name, "vendor.img", OPTIONS.info_dict)
  output_zip.write(img.name, "vendor.img")
  img.close()


def AddUserdata(output_zip):
  """Create an empty userdata image and store it in output_zip."""

@@ -287,10 +266,21 @@ def main(argv):
  if recovery_image:
    recovery_image.AddToZip(output_zip)

  def banner(s):
    print "\n\n++++ " + s + " ++++\n\n"

  if not bootable_only:
    banner("AddSystem")
    AddSystem(output_zip)
    try:
      input_zip.getinfo("VENDOR/")
      banner("AddVendor")
      AddVendor(output_zip)
    except KeyError:
      pass   # no vendor partition for this device
    banner("AddUserdata")
    AddUserdata(output_zip)
    banner("AddCache")
    AddCache(output_zip)
    CopyInfo(output_zip)

+339 −216

File changed.

Preview size limit exceeded, changes collapsed.