MT6762 Android 8.1 打开custom分区,挂载custom分区,OTA升级custom分区

MT6762 Android 8.1 打开custom分区,挂载custom分区,OTA升级custom分区

  • 1.打开custom分区
  • 2.挂载custom分区
  • 3.OTA升级custom分区

1.打开custom分区

MTK的 Android 8.1 代码实际是支持custom分区的,只是默认是关闭的,修改 ProjectConfig.mk 的 “MTK_CIP_SUPPORT = yes” 可以打开custom分区。
打开选项之后,重新编译系统,会看到生成“custom.img”文件,并且out目录下会生成“custom”目录,如下图:
MT6762 Android 8.1 打开custom分区,挂载custom分区,OTA升级custom分区_第1张图片
如果需要修改custom分区的大小,修改文件:
device/mediatek/build/build/tools/ptgen/MT6765/partition_table_MT6765.xls
如图:
MT6762 Android 8.1 打开custom分区,挂载custom分区,OTA升级custom分区_第2张图片
具体修改哪一个表格里面的custom,根据系统配置而定!

2.挂载custom分区

如果需要挂载custom分区,修改文件:
vendor/mediatek/proprietary/hardware/fstab/mt6765/fstab.in
在适当的位置,增加:
DEVPATH(custom) /custom ext4 FS_FLAG_DISCARD FSMGR_FLAG_CHK

如果需要修改/custom挂载点的目录权限,可以在init.rc的适当位置增加类似:
chown system system /custom
chmod 0775 /custom

3.OTA升级custom分区

OTA升级是没有包含custom分区的,需要修改对应脚本文件!

首先在 BoardConfig.mk 文件增加如下一行变量赋值,后面Makefile文件需要用到:
BOARD_CUSTOMIMAGE_FILE_SYSTEM_TYPE := ext4

然后修改源码 build 目录下,下列4个文件,这些修改,主要参考的是“cache”和“vendor”分区相应功能的脚本,具体实现,可以自己分析相关编译脚本:

diff --git a/make/core/Makefile b/make/core/Makefile
index bcb6338..81d5822 100755
--- a/make/core/Makefile
+++ b/make/core/Makefile
@@ -1015,6 +1015,8 @@ $(if $(BOARD_FLASH_LOGICAL_BLOCK_SIZE), $(hide) echo "flash_logical_block_size=$
 $(if $(BOARD_FLASH_ERASE_BLOCK_SIZE), $(hide) echo "flash_erase_block_size=$(BOARD_FLASH_ERASE_BLOCK_SIZE)" >> $(1))
 $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
 $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
+$(if $(BOARD_CUSTOMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "custom_fs_type=$(BOARD_CUSTOMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
+$(if $(BOARD_CUSTOMIMAGE_PARTITION_SIZE),$(hide) echo "custom_size=$(BOARD_CUSTOMIMAGE_PARTITION_SIZE)" >> $(1))
 $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
 $(if $(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT),$(hide) echo "vendor_extfs_inode_count=$(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT)" >> $(1))
 $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
@@ -2343,6 +2345,8 @@ ifeq ($(AB_OTA_UPDATER),true)
   endif
 endif
 
+BUILT_OUT_CUSTOM := $(PRODUCT_OUT)/custom
+
 # Run fs_config while creating the target files package
 # $1: root directory
 # $2: add prefix
@@ -2356,6 +2360,7 @@ $(BUILT_TARGET_FILES_PACKAGE): \
                $(INSTALLED_BOOTIMAGE_TARGET) \
                $(INSTALLED_RADIOIMAGE_TARGET) \
                $(INSTALLED_RECOVERYIMAGE_TARGET) \
+               $(INSTALLED_CUSTOMIMAGE_TARGET) \
                $(FULL_SYSTEMIMAGE_DEPS) \
                $(INSTALLED_USERDATAIMAGE_TARGET) \
                $(INSTALLED_CACHEIMAGE_TARGET) \
@@ -2438,6 +2443,9 @@ endif # BOARD_USES_RECOVERY_AS_BOOT
        @# Contents of the system image
        $(hide) $(call package_files-copy-root, \
                $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
+       @# Contents of the custom image
+       $(hide) $(call package_files-copy-root, \
+               $(BUILT_OUT_CUSTOM),$(zip_root)/CUSTOM)
        @# Contents of the data image
        $(hide) $(call package_files-copy-root, \
                $(TARGET_OUT_DATA),$(zip_root)/DATA)
@@ -2630,6 +2638,7 @@ endif # BOARD_PREBUILT_DTBOIMAGE
 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
        $(hide) $(call fs_config,$(zip_root)/VENDOR,vendor/) > $(zip_root)/META/vendor_filesystem_config.txt
 endif
+       $(hide) $(call fs_config,$(zip_root)/CUSTOM,custom/) > $(zip_root)/META/costom_filesystem_config.txt
 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
        $(hide) $(call fs_config,$(zip_root)/ROOT,) > $(zip_root)/META/root_filesystem_config.txt
 endif
diff --git a/make/tools/releasetools/add_img_to_target_files.py b/make/tools/releasetools/add_img_to_target_files.py
index 56d990b..8d5f24d 100755
--- a/make/tools/releasetools/add_img_to_target_files.py
+++ b/make/tools/releasetools/add_img_to_target_files.py
@@ -174,6 +174,19 @@ def AddVendor(output_zip, prefix="IMAGES/"):
               block_list=block_list)
   return img.name
 
+def AddCustom(output_zip, prefix="IMAGES/"):
+  """Turn the contents of CUSTOM into a custom image and store in it
+  output_zip."""
+
+  img = OutputFile(output_zip, OPTIONS.input_tmp, prefix, "custom.img")
+  if os.path.exists(img.input_name):
+    print("custom.img already exists in %s, no need to rebuild..." % (prefix,))
+    return img.input_name
+
+  block_list = OutputFile(output_zip, OPTIONS.input_tmp, prefix, "custom.map")
+  CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "custom", img,
+              block_list=block_list)
+  return img.name
 
 def AddDtbo(output_zip, prefix="IMAGES/"):
   """Adds the DTBO image.
@@ -550,6 +563,9 @@ def AddImagesToTargetFiles(filename):
   has_vendor = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "VENDOR")) or
                 os.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES",
                                             "vendor.img")))
+  has_custom = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "CUSTOM")) or
+                os.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES",
+                                            "custom.img")))
   has_system_other = os.path.isdir(os.path.join(OPTIONS.input_tmp,
                                                 "SYSTEM_OTHER"))
 
@@ -637,6 +653,11 @@ def AddImagesToTargetFiles(filename):
     banner("vendor")
     partitions['vendor'] = vendor_img_path = AddVendor(output_zip)
 
+  custom_img_path = None
+  if has_custom:
+    banner("custom")
+    partitions['custom'] = custom_img_path = AddCustom(output_zip)
+
   if has_system_other:
     banner("system_other")
     AddSystemOther(output_zip)
diff --git a/make/tools/releasetools/build_image.py b/make/tools/releasetools/build_image.py
index ccfa35f..e17a99d 100755
--- a/make/tools/releasetools/build_image.py
+++ b/make/tools/releasetools/build_image.py
@@ -703,6 +703,9 @@ def ImagePropFromGlobalDict(glob_dict, mount_point):
   elif mount_point == "cache":
     copy_prop("cache_fs_type", "fs_type")
     copy_prop("cache_size", "partition_size")
+  elif mount_point == "custom":
+    copy_prop("custom_fs_type", "fs_type")
+    copy_prop("custom_size", "partition_size")
   elif mount_point == "vendor":
     copy_prop("avb_vendor_hashtree_enable", "avb_hashtree_enable")
     copy_prop("avb_vendor_add_hashtree_footer_args",
@@ -770,6 +773,8 @@ def main(argv):
       mount_point = "data"
     elif image_filename == "cache.img":
       mount_point = "cache"
+    elif image_filename == "custom.img":
+      mount_point = "custom"
     elif image_filename == "vendor.img":
       mount_point = "vendor"
     elif image_filename == "oem.img":
diff --git a/make/tools/releasetools/ota_from_target_files.py b/make/tools/releasetools/ota_from_target_files.py
index 57c4735..81b7603 100755
--- a/make/tools/releasetools/ota_from_target_files.py
+++ b/make/tools/releasetools/ota_from_target_files.py
@@ -274,6 +274,12 @@ def HasVendorPartition(target_files_zip):
   except KeyError:
     return False
 
+def HasCustomPartition(target_files_zip):
+  try:
+    target_files_zip.getinfo("CUSTOM/")
+    return True
+  except KeyError:
+    return False
 
 def GetOemProperty(name, oem_props, oem_dict, info_dict):
   if oem_props is not None and name in oem_props:
@@ -298,7 +304,7 @@ def GetImage(which, tmpdir):
   map must already exist in tmpdir.
   """
 
-  assert which in ("system", "vendor")
+  assert which in ("system", "vendor", "custom")
 
   path = os.path.join(tmpdir, "IMAGES", which + ".img")
   mappath = os.path.join(tmpdir, "IMAGES", which + ".map")
@@ -499,6 +505,13 @@ else if get_stage("%(bcb_dev)s") == "3/3" then
     vendor_diff = common.BlockDifference("vendor", vendor_tgt)
     vendor_diff.WriteScript(script, output_zip)
 
+  if HasCustomPartition(input_zip):
+
+    custom_tgt = GetImage("custom", OPTIONS.input_tmp)
+    custom_tgt.ResetFileMap()
+    custom_diff = common.BlockDifference("custom", custom_tgt)
+    custom_diff.WriteScript(script, output_zip)
+
   common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)
   common.ZipWriteStr(output_zip, "boot.img", boot_img.data)

你可能感兴趣的:(技术随笔)