MT6762 Android 8.1 打開custom分區,掛載custom分區,OTA升級custom分區

MT6762 Android 8.1 打開custom分區,掛載custom分區,OTA升級custom分區

1.打開custom分區

MTK的 Android 8.1 代碼實際是支持custom分區的,只是默認是關閉的,修改 ProjectConfig.mk 的 “MTK_CIP_SUPPORT = yes” 可以打開custom分區。
打開選項之後,重新編譯系統,會看到生成“custom.img”文件,並且out目錄下會生成“custom”目錄,如下圖:
在這裏插入圖片描述
如果需要修改custom分區的大小,修改文件:
device/mediatek/build/build/tools/ptgen/MT6765/partition_table_MT6765.xls
如圖:
在這裏插入圖片描述
具體修改哪一個表格裏面的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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章