OSDN Git Service

build: Create a oem image when BOARD_OEMIMAGE_FILE_SYSTEM_TYPE is defined
authorDiogo Ferreira <diogo@underdev.org>
Fri, 4 Sep 2015 10:59:13 +0000 (11:59 +0100)
committerSteve Kondik <steve@cyngn.com>
Sun, 4 Sep 2016 04:47:36 +0000 (21:47 -0700)
This adds the capability of generating a OEM image with the build
and adding it to target files when BOARD_OEMIMAGE_FILE_SYSTEM_TYPE
is set.

Change-Id: I6c596d58d9d5ece1a261d953eeb8c60eac30e642
Ticket: CYNGNOS-936

core/Makefile
core/tasks/oem_image.mk
tools/releasetools/add_img_to_target_files.py
tools/releasetools/img_from_target_files.py

index ed47896..eb8efab 100644 (file)
@@ -1774,6 +1774,7 @@ endif
 
 # Depending on the various images guarantees that the underlying
 # directories are up-to-date.
+include $(BUILD_SYSTEM)/tasks/oem_image.mk
 $(BUILT_TARGET_FILES_PACKAGE): \
                $(INSTALLED_BOOTIMAGE_TARGET) \
                $(INSTALLED_RADIOIMAGE_TARGET) \
@@ -1782,6 +1783,7 @@ $(BUILT_TARGET_FILES_PACKAGE): \
                $(INSTALLED_USERDATAIMAGE_TARGET) \
                $(INSTALLED_CACHEIMAGE_TARGET) \
                $(INSTALLED_VENDORIMAGE_TARGET) \
+               $(INSTALLED_OEMIMAGE_TARGET) \
                $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
                $(SELINUX_FC) \
                $(APKCERTS_FILE) \
@@ -1895,6 +1897,11 @@ ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
        $(hide) $(call package_files-copy-root, \
                $(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
 endif
+ifdef BOARD_OEMIMAGE_FILE_SYSTEM_TYPE
+       @# Contents of the oem image
+       $(call package_files-copy-root, \
+               $(TARGET_OUT_OEM),$(zip_root)/OEM)
+endif
        @# Extra contents of the OTA package
        $(hide) mkdir -p $(zip_root)/OTA
        $(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
index 32d56a7..8a06670 100644 (file)
 #
 
 # We build oem.img only if it's asked for.
+skip_oem_image := true
 ifneq ($(filter $(MAKECMDGOALS),oem_image),)
+    skip_oem_image := false
+endif
+
+ifneq ($(BOARD_OEMIMAGE_FILE_SYSTEM_TYPE),)
+    skip_oem_image := false
+endif
+
+ifneq ($(skip_oem_image),true)
 ifndef BOARD_OEMIMAGE_PARTITION_SIZE
 $(error BOARD_OEMIMAGE_PARTITION_SIZE is not set.)
 endif
@@ -43,4 +52,4 @@ $(INSTALLED_OEMIMAGE_TARGET) : $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_OEMIMAGE_F
 oem_image : $(INSTALLED_OEMIMAGE_TARGET)
 $(call dist-for-goals, oem_image, $(INSTALLED_OEMIMAGE_TARGET))
 
-endif  # oem_image in $(MAKECMDGOALS)
+endif
index 0f7ac36..04fa822 100755 (executable)
@@ -99,6 +99,29 @@ def BuildVendor(input_dir, info_dict, block_list=None):
   file containing it."""
   return CreateImage(input_dir, info_dict, "vendor", block_list=block_list)
 
+def AddOem(output_zip, prefix="IMAGES/"):
+  """Turn the contents of OEM into a oem image and store in it
+  output_zip."""
+
+  prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "oem.img")
+  if os.path.exists(prebuilt_path):
+    print "oem.img already exists in %s, no need to rebuild..." % (prefix,)
+    return
+
+  block_list = common.MakeTempFile(prefix="oem-blocklist-", suffix=".map")
+  imgname = BuildOem(OPTIONS.input_tmp, OPTIONS.info_dict,
+                     block_list=block_list)
+  with open(imgname, "rb") as f:
+    common.ZipWriteStr(output_zip, prefix + "oem.img", f.read())
+  with open(block_list, "rb") as f:
+    common.ZipWriteStr(output_zip, prefix + "oem.map", f.read())
+
+
+def BuildOem(input_dir, info_dict, block_list=None):
+  """Build the (sparse) oem image and return the name of a temp
+  file containing it."""
+  return CreateImage(input_dir, info_dict, "oem", block_list=block_list)
+
 
 def CreateImage(input_dir, info_dict, what, block_list=None):
   print "creating " + what + ".img..."
@@ -315,6 +338,12 @@ def AddImagesToTargetFiles(filename):
   except KeyError:
     has_vendor = False
 
+  try:
+    input_zip.getinfo("OEM/")
+    has_oem = True
+  except KeyError:
+    has_oem = False
+
   OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp)
 
   common.ZipClose(input_zip)
@@ -367,6 +396,10 @@ def AddImagesToTargetFiles(filename):
   AddUserdataExtra(output_zip)
   banner("cache")
   AddCache(output_zip)
+  if has_oem:
+    banner("oem")
+    AddOem(output_zip)
+
 
   # For devices using A/B update, copy over images from RADIO/ to IMAGES/ and
   # make sure we have all the needed images ready under IMAGES/.
index f12fecb..832be7c 100755 (executable)
@@ -152,6 +152,12 @@ def main(argv):
         add_img_to_target_files.AddUserdataExtra(output_zip, prefix="")
         banner("AddCache")
         add_img_to_target_files.AddCache(output_zip, prefix="")
+        try:
+          input_zip.getinfo("OEM/")
+          banner("AddOem")
+          add_img_to_target_files.AddOem(output_zip, prefix="")
+        except KeyError:
+          pass   # no oem partition for this device
 
   finally:
     print "cleaning up..."