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

Commit 5fad2039 authored by Doug Zongker's avatar Doug Zongker
Browse files

handle don't care regions in the system image

The system partitions has regions that we shouldn't write and can't
depend on the contents of.  Adds a new script to generate a map of
these regions (using the sparse image as input), and include the map
in the package zip so it can be used when writing or patching the
system partition.

Also fixes a bug where the wrong SELinux file contexts are used when
generating incrementals.

Change-Id: Iaca5b967a3b7d1df843c7c21becc19b3f1633dad
parent 7676dbe0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1135,7 +1135,8 @@ DISTTOOLS := $(HOST_OUT_EXECUTABLES)/minigzip \
	  $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
	  $(HOST_OUT_EXECUTABLES)/make_ext4fs \
	  $(HOST_OUT_EXECUTABLES)/simg2img \
	  $(HOST_OUT_EXECUTABLES)/e2fsck
	  $(HOST_OUT_EXECUTABLES)/e2fsck \
	  $(HOST_OUT_EXECUTABLES)/xdelta3

OTATOOLS := $(DISTTOOLS) \
	  $(HOST_OUT_EXECUTABLES)/aapt
+9 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import sys
import commands
import shutil

import simg_map

def RunCommand(cmd):
  """ Echo and run the given command

@@ -146,6 +148,13 @@ def UnsparseImage(sparse_image_path, replace=True):
    return False, None
  return True, unsparse_image_path

def MappedUnsparseImage(sparse_image_path, unsparse_image_path,
                        map_path, mapped_unsparse_image_path):
  if simg_map.ComputeMap(sparse_image_path, unsparse_image_path,
                         map_path, mapped_unsparse_image_path):
    return False
  return True

def MakeVerityEnabledImage(out_file, prop_dict):
  """Creates an image that is verifiable using dm-verity.

+1 −1
Original line number Diff line number Diff line
@@ -1015,7 +1015,7 @@ def MakeSystemPatch(source_file, target_file):
    with open(output_file.name + ".xz") as patch_file:
      patch_data = patch_file.read()
      os.unlink(patch_file.name)
      return File("system.img.p", patch_data)
      return File("system.muimg.p", patch_data)

def MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img,
                      info_dict=None):
+23 −6
Original line number Diff line number Diff line
@@ -190,6 +190,16 @@ class EdifyGenerator(object):
                         (p.fs_type, common.PARTITION_TYPES[p.fs_type],
                          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,))
    fstab = self.info.get("fstab", None)
    size = self.info.get("system_size", None)
    device = fstab[partition].device

    self.script.append('wipe_block_device("%s", %s);' % (device, size))

  def DeleteFiles(self, file_list):
    """Delete all files in file_list."""
    if not file_list: return
@@ -224,7 +234,7 @@ class EdifyGenerator(object):
    cmd = "".join(cmd)
    self.script.append(self._WordWrap(cmd))

  def WriteRawImage(self, mount_point, fn):
  def WriteRawImage(self, mount_point, fn, mapfn=None):
    """Write the given package file into the partition for the given
    mount point."""

@@ -238,6 +248,11 @@ class EdifyGenerator(object):
            'write_raw_image(package_extract_file("%(fn)s"), "%(device)s");'
            % args)
      elif partition_type == "EMMC":
        if mapfn:
          args["map"] = mapfn
          self.script.append(
              'package_extract_file("%(fn)s", "%(device)s", "%(map)s");' % args)
        else:
          self.script.append(
              'package_extract_file("%(fn)s", "%(device)s");' % args)
      else:
@@ -309,7 +324,9 @@ class EdifyGenerator(object):
    common.ZipWriteStr(output_zip, "META-INF/com/google/android/update-binary",
                       data, perms=0755)

  def Syspatch(self, filename, size, target_sha, source_sha, patchfile):
  def Syspatch(self, filename, target_mapfile, target_sha,
               source_mapfile, source_sha, patchfile):
    """Applies a compressed binary patch to a block device."""
    call = 'syspatch("%s", "%s", "%s", "%s", "%s");'
    self.script.append(call % (filename, size, target_sha, source_sha, patchfile))
    call = 'syspatch("%s", "%s", "%s", "%s", "%s", "%s");'
    self.script.append(call % (filename, target_mapfile, target_sha,
                               source_mapfile, source_sha, patchfile))
+21 −2
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ def AddSystem(output_zip, sparse=True):
  common.ZipWriteStr(output_zip, "system.img", data)


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

  img = tempfile.NamedTemporaryFile()
@@ -87,6 +87,8 @@ def BuildSystem(input_dir, info_dict, sparse=True):
                                image_props, img.name)
  assert succ, "build system.img image failed"

  mapdata = None

  if sparse:
    img.seek(os.SEEK_SET, 0)
    data = img.read()
@@ -95,13 +97,30 @@ def BuildSystem(input_dir, info_dict, sparse=True):
    success, name = build_image.UnsparseImage(img.name, replace=False)
    if not success:
      assert False, "unsparsing system.img failed"

    if map_file:
      mmap = tempfile.NamedTemporaryFile()
      mimg = tempfile.NamedTemporaryFile(delete=False)
      success = build_image.MappedUnsparseImage(
          img.name, name, mmap.name, mimg.name)
      if not success:
        assert False, "creating sparse map failed"
      os.unlink(name)
      name = mimg.name

      with open(mmap.name) as f:
        mapdata = f.read()

    try:
      with open(name) as f:
        data = f.read()
    finally:
      os.unlink(name)

  if mapdata is None:
    return data
  else:
    return mapdata, data


def AddVendor(output_zip):
Loading