MTK 平台增加分区流程 及 注意事项

1、修改分区大小:

android/vendor/mediatek/proprietary/tools/ptgen/MTxxxx/partition_table_emmc_ab.csv
+carrier,EXT4,51200,,EMMC_USER,,N,N,NONE,N,N,Y,,Y,,AUTO


2、使用宏控控制分区是否增加,以增加carrier分区为例

    2.1增加宏开关:

    android/device/xxx/L400/ProjectConfig.mk
        FEATURE_CARRIER_PARTITION_SUPPORT = yes  
    android/vendor/mediatek/proprietary/tools/ptgen/common/CommonArg.py
        arg_name_list = [
            # xxx BEGIN
            'FEATURE_CARRIER_PARTITION_SUPPORT', 'xxx_PRJ_DIR',
            # xxx END
    android/vendor/mediatek/proprietary/tools/ptgen/ptgen.mk
        MTK_PTGEN_COMMAND := \
            FEATURE_CARRIER_PARTITION_SUPPORT=${FEATURE_CARRIER_PARTITION_SUPPORT} 
            
    --- a/mediatek/proprietary/tools/ptgen/common/DeleteRule.py
    +++ b/mediatek/proprietary/tools/ptgen/common/DeleteRule.py
    @@ -14,6 +14,11 @@ def initRule(ArgList, storage_type):
         or (ArgList.argGet('MTK_EMMC_SUPPORT') != "yes" and ArgList.argGet('MTK_UFS_SUPPORT') != "yes" and ArgList.argGet('MTK_FAT_ON_NAND') != "yes")),
         '^custom$' : (ArgList.argGet('MTK_CIP_SUPPORT') != "yes"),
         '^persist$': ArgList.argGet('MTK_PERSIST_PARTITION_SUPPORT') != "yes",
    +    # xxx BEGIN
    +    '^carrier$': ArgList.argGet('FEATURE_CARRIER_PARTITION_SUPPORT') != "yes",
    +    # xxx END            

    2.2 增加sepolicy 路径及对应selinux 权限:

    这些规则是在添加新分区其它工作就绪后,抓取开机 uart log 中影响开机的 selinux 权限问题而添加的
    
    android/device/xxx/L400/BoardConfig.mk 
        BOARD_SEPOLICY_DIRS += device/xxx/L400/sepolicy/non_plat
            
    diff --git a/sepolicy/non_plat/device.te b/sepolicy/non_plat/device.te
    new file mode 100644
    index 0000000..e94af6b
    --- /dev/null
    +++ b/sepolicy/non_plat/device.te
    @@ -0,0 +1,2 @@
    +type carrier_block_device, dev_type;
    diff --git a/sepolicy/non_plat/e2fs.te b/sepolicy/non_plat/e2fs.te
    new file mode 100644
    index 0000000..ac7231d
    --- /dev/null
    +++ b/sepolicy/non_plat/e2fs.te
    @@ -0,0 +1,8 @@
    +allow e2fs carrier_block_device:blk_file rw_file_perms;
    +allowxperm e2fs carrier_block_device:blk_file ioctl {
    +  BLKDISCARD BLKPBSZGET BLKDISCARDZEROES BLKROGET
    +};
    diff --git a/sepolicy/non_plat/file.te b/sepolicy/non_plat/file.te
    new file mode 100644
    index 0000000..71a714a
    --- /dev/null
    +++ b/sepolicy/non_plat/file.te
    @@ -0,0 +1,3 @@
    +type carrier_file, file_type;
    +
    diff --git a/sepolicy/non_plat/file_contexts b/sepolicy/non_plat/file_contexts
    new file mode 100644
    index 0000000..8a5ea3c
    --- /dev/null
    +++ b/sepolicy/non_plat/file_contexts
    @@ -0,0 +1,6 @@
    +/dev/block/by-name/carrier                       u:object_r:carrier_block_device:s0
    +/carrier(/.*)?                                   u:object_r:carrier_file:s0
    +/mnt/carrier(/.*)?                               u:object_r:carrier_file:s0
    diff --git a/sepolicy/non_plat/fsck.te b/sepolicy/non_plat/fsck.te
    new file mode 100644
    index 0000000..72e6420
    --- /dev/null
    +++ b/sepolicy/non_plat/fsck.te
    @@ -0,0 +1,2 @@
    +allow fsck carrier_block_device:blk_file rw_file_perms;
    diff --git a/sepolicy/non_plat/init.te b/sepolicy/non_plat/init.te
    new file mode 100644
    index 0000000..f5ebc8a
    --- /dev/null
    +++ b/sepolicy/non_plat/init.te
    @@ -0,0 +1,2 @@
    +allow init carrier_file:dir mounton;
    diff --git a/sepolicy/non_plat/vold.te b/sepolicy/non_plat/vold.te
    new file mode 100644
    index 0000000..fea5dd4
    --- /dev/null
    +++ b/sepolicy/non_plat/vold.te
    @@ -0,0 +1,3 @@
    +allow vold carrier_file:dir r_dir_perms;
    +

    2.3 修改文件节点owner和group

    android/device/xxx/L400/init.project.rc
        # xxx BEGIN
        wait /dev/block/by-name/carrier
        chown system system /mnt/carrier
        chmod 0771 /mnt/carrier
        restorecon_recursive /mnt/carrier
        # xxx END


3、mount 设备

android/vendor/mediatek/proprietary/hardware/fstab/Android.mk
    ifeq ($(strip $(FEATURE_CARRIER_PARTITION_SUPPORT)),yes)
    __CFLAGS += -D__CARRIER_PARTITION_SUPPORT
    endif
android/vendor/mediatek/proprietary/hardware/fstab/mtxxxx/fstab.in
    #ifdef __CARRIER_PARTITION_SUPPORT
    DEVPATH(carrier)    /mnt/carrier            ext4   FS_FLAG_DISCARD FSMGR_FLAG_FMT
    #endif


4、创建软连接

android/system/core/rootdir/Android.mk
    # xxx BEGIN
    ifeq ($(FEATURE_CARRIER_PARTITION_SUPPORT), yes)
      LOCAL_POST_INSTALL_CMD += ; ln -sf /mnt/carrier $(TARGET_ROOT_OUT)/carrier
    endif
    # xxx END


注意点:


1、修改分区lk大小  一定要保证lk_a  lk_b大小都修改,否则会在ota升级时报错:

03-27 06:15:00.581  1192  1192 I update_engine: [INFO:partition_writer.cc(181)] Applying 3 operations to partition "lk"
03-27 06:15:00.657  1192  1192 E update_engine: [ERROR:cached_file_descriptor.cc(90)] Failed to flush cached data!: No space left on device (28)
03-27 06:15:00.659  1192  1192 E update_engine: [ERROR:extent_writer.cc(51)] fd_->Seek(offset, SEEK_SET) != static_cast<off64_t>(-1) failed: No space left on device
03-27 06:15:00.661  1192  1192 E update_engine: [ERROR:file_descriptor_utils.cc(66)] writer->Write(buf.data(), read_blocks * block_size) failed.
03-27 06:15:00.664  1192  1192 E update_engine: [ERROR:delta_performer.cc(195)] Failed to perform SOURCE_COPY operation 28, which is the operation 1 in partition "lk"
03-27 06:15:00.666  1192  1192 E update_engine: [ERROR:download_action.cc(226)] Error ErrorCode::kDownloadOperationExecutionError (28) in DeltaPerformer's Write method when processing the received payload -- Terminating processing
03-27 06:15:00.695  1192  1192 E update_engine: [ERROR:cached_file_descriptor.cc(90)] Failed to flush cached data!: No space left on device (28)
03-27 06:15:00.701  1192  1192 E update_engine: [ERROR:cached_file_descriptor.cc(90)] Failed to flush cached data!: No space left on device (28)
03-27 06:15:00.703  1192  1192 E update_engine: [ERROR:partition_writer.cc(280)] Error closing target partition: No space left on device (28)


2、 6879 6835 平台注意mrdump分区 在user版本会去除,此时要注意:

mrdump,Raw data,33554432,,EMMC_USER,UFS_LU2,,Y,N,NONE,N,N,N,,N,,RESERVED,,"eq(TARGET_BUILD_VARIANT,user)"

3、需注意mrdump分区大小  33554432K = 32G

4、分区实际 size 跟分区表中 Size_KB 不同:

    1).请仔细确认是否某个路径下的 BoardConfig.mk 有重新定义分区 size;
    2).或者由于对齐需要,对 Size_KB 有做调整。如:8M 对齐。


添加分区注意事项(checklist):

1、xxx定制所增加的carrier分区是否在最终的软件包scat/rawprogram文件中
2、对于a/b系统,所修改的分区是否全部都有修改到,比如修改了lk_a的大小,对应的lk_b的大小也一定要有修改到
3、对应分区的selinux label是否有修改过来,命令:ls -alZ /mnt
    drwxrwx--x  2 system system   u:object_r:tmpfs:s0              40 2024-04-07 04:07 carrier
    要确认把tmpfs改成需要的值:
    drwxrwx--x  3 system system           u:object_r:carrier_file:s0           4096 2010-01-01 08:00 carrier
4、lpdump 查看super分区layout,确认总大小是自己的期望值并计算剩余空间确保剩余super剩余空间在500M左右(注意要先导入gms包)
    用如下命令计算的:
    adb shell pm list packages -f  | grep "google" | awk -F ":" '{print $2}' | awk -F "=" '{print $1}' | xargs -i adb shell dirname {} | grep -v "overlay" | xargs -i adb shell du -s -k {}

5、 进入设置->存储查看总大小是否符合项目定义
6、 userdata分区 75%以上 
7、 查看根目录下的软链接是否生效
    LOCAL_POST_INSTALL_CMD += ; ln -sf /mnt/carrier $(TARGET_ROOT_OUT)/carrier
8、 MTK 异常分区mrdump 检查:
    1)、MTK默认user版本去除此分区,userdebug版本升级到user版本时提示要formate,user版本也要保留此分区
    2)、MTK默认此分区大小是32G 并且会占用存储总空间,导致设置->存储显示异常


9、更改super分区大小后fota升级问题:(分区由6G改为4.5G后出现的问题)
    05-05 16:27:51.382  1756  1756 E update_engine: [ERROR:builder.cpp(1047)] [liblp] Device size does not match (got 4831838208, expected 6442450944)
    05-05 16:27:51.389  1756  1756 E update_engine: [ERROR:builder.cpp(1047)] [liblp] Device size does not match (got 4831838208, expected 6442450944)

    需要更改配置文件:
    BOARD_SUPER_PARTITION_SIZE := 6442450944
    BOARD_QTI_DYNAMIC_PARTITIONS_SIZE := 6438256640

动态分区super 分区计算剩余空间

# lpdump
Slot 0:
Metadata version: 10.2
Metadata size: 976 bytes
Metadata max size: 65536 bytes
Metadata slot count: 3
Header flags: virtual_ab_device
Partition table:
------------------------
  Name: product_a
  Group: main_a
  Attributes: readonly
  Extents:
    0 .. 4902207 linear super 2048
------------------------
  Name: product_b
  Group: main_b
  Attributes: readonly
  Extents:
------------------------
  Name: system_a
  Group: main_a
  Attributes: readonly
  Extents:
    0 .. 4117463 linear super 4904960
------------------------
  Name: system_b
  Group: main_b
  Attributes: readonly
  Extents:
------------------------
  Name: system_ext_a
  Group: main_a
  Attributes: readonly
  Extents:
    0 .. 1536831 linear super 9023488
------------------------
  Name: system_ext_b
  Group: main_b
  Attributes: readonly
  Extents:
------------------------
  Name: vendor_a
  Group: main_a
  Attributes: readonly
  Extents:
    0 .. 946263 linear super 10561536
------------------------
  Name: vendor_b
  Group: main_b
  Attributes: readonly
  Extents:
------------------------
Super partition layout:
------------------------
super: 2048 .. 4904256: product_a (4902208 sectors)
super: 4904960 .. 9022424: system_a (4117464 sectors)
super: 9023488 .. 10560320: system_ext_a (1536832 sectors)
super: 10561536 .. 11507800: vendor_a (946264 sectors)
------------------------
Block device table:
------------------------
  Partition name: super
  First sector: 2048
  Size: 8792064000 bytes
  Flags: none
------------------------
Group table:
------------------------
  Name: default
  Maximum size: 0 bytes
  Flags: none
------------------------
  Name: main_a
  Maximum size: 8789966848 bytes
  Flags: none
------------------------
  Name: main_b
  Maximum size: 8789966848 bytes
  Flags: none
------------------------


super left space : (8792064000 - (4902208 + 4117464 + 1536832 + 946264)*512 )/1024/1024/1024.0 = 2.703125 G


如何查看分区大小(block数目,需*512 ):

adb shell cat sys/class/mmc_host/mmc0/mmc0:0001/block/mmcblk0/size

附 ptgen 编译过程log:


[FAQ28494] ptgen 脚本 与 scatter.txt 生成
https://online.mediatek.com/FAQ#/SW/FAQ28494

首先  打开的是 分区表的 目录  :   
从 R  版本 开始 : vendor/mediatek/proprietary/tools/ptgen
Q版本及之前: device/mediatek/build/build/tools/ptgen
   这个目录下 很多的platform ,common , utils,并且包含着一些与 OTA 相关的脚本文件。
1. 先找到 项目中如何找到对应的分区表:project 找到了对应的 ptgen.mk 
2. 了解 common 下 的 ptgen.mk
 包含了 storage 的类型支持,  feature 对应的 partition 是否开关,这些都会读取 ProjectConfig.mk 的设定来进行选择,也可以确定使用哪个 Platform 中的分区表。
在ptgen.mk 还有一个关键信息:default_ptgen.py  ,程序会根据 ProjectConfig.mk的配置来进行生成ptgen。
进入default_ptgen.py 首先看 main 函数123...Com
 a.  开始走默认的flow ,选择 EMMC 或 UFS 是否support 来生成对应的  
function name     Desciptor     path(vendor/mediatek/proprietary/tool/ptgen)
DefaultFlow     
定义EMMC 或 UFS 是否support,来生成对应的 scatter.txt 依据AlignPartList ,分区是否进行对齐
    common/deafult_ptgen.py run_flow     
计算 AlignPartList 对齐 下载文件提取 生成scatter文件
生成 GPT 文件 common/deafult_ptgen.py
从log 的角度看,在编译的初期,就会根据BoardConfig.mk  和 ProjectConfig.mk 中的信息,进行生成scatter.txt文件。

以下log是 编译过程中log:
开始ptgen脚本
[ptgen-py] !!!!!!!!!!!!!!!!!!! start !!!!!!!!!!!!!!!!!!!
[ptgen-py] *******************Arguments*********************

针对MTK_PTGEN_COMMAND中的配置进行赋值(ProjectConfig.mk)
[ptgen-py] MTK_PLATFORM = MT6765
[ptgen-py] TARGET_COPY_OUT_ODM_DLKM = ||ODM_DLKM-PATH-PH||
[ptgen-py] MTK_COMBO_NAND_SUPPORT = 
[ptgen-py] TARGET_BUILD_VARIANT = userdebug
[ptgen-py] MTK_DPM_SUPPORT = 
[ptgen-py] MTK_TINYSYS_SCP_SUPPORT = yes
[ptgen-py] MTK_AUDIODSP_SUPPORT = 
 
分区表的路径打印(根据MTK_AB_OTA_UPDATER  选择 AB 分区的分区表)
[ptgen-py] MTK_AB_OTA_UPDATER = yes
[ptgen-py] layout_path = vendor/mediatek/proprietary/tools/ptgen/MT6765/partition_table_emmc_ab.csv
[ptgen-py] SHEET_NAME = emmc_ab
[ptgen-py] *******************Arguments*********************
[ptgen-py] partition layout file path : vendor/mediatek/proprietary/tools/ptgen/MT6765/partition_table_emmc_ab.csv

根据deleteRule 来确定是否用该分区(runDelRule)
[ptgen-py] frp has deleteRule: ne(MTK_FACTORY_RESET_PROTECTION_SUPPORT,yes) is False
[ptgen-py] md_udc has deleteRule: ne(MTK_BOARD_USES_METADATA_PARTITION,true) is False
[ptgen-py] persist has deleteRule: ne(MTK_PERSIST_PARTITION_SUPPORT,yes) is True
[ptgen-py] efuse has deleteRule: ne(MTK_EFUSE_WRITER_SUPPORT,yes) is True
[ptgen-py] md1dsp_a has deleteRule: eq(MTK_SINGLE_BIN_MODEM_SUPPORT,yes) is True
[ptgen-py] spmfw_a has deleteRule: ne(SPM_FW_USE_PARTITION,yes) is False
[ptgen-py] scp_a has deleteRule: ne(MTK_TINYSYS_SCP_SUPPORT,yes) is False
[ptgen-py] sspm_a has deleteRule: ne(MTK_TINYSYS_SSPM_SUPPORT,yes) is False
[ptgen-py] vendor_boot_a has deleteRule: le(PRODUCT_SHIPPING_API_LEVEL,30) is False
[ptgen-py] tee_a has deleteRule: ne(MTK_ATF_SUPPORT,yes) and ne(MTK_TEE_SUPPORT,yes) is False
[ptgen-py] odm_a has deleteRule: ne(TARGET_COPY_OUT_ODM,odm) is True
[ptgen-py] vbmeta_a has deleteRule: ne(MTK_BOARD_AVB_ENABLE,true) is False

....

计算需要对齐的分区地址(runCalAddr)
ptgen-py] BoardConfig File exists: /worktmp/cas_personal/mtk27529/alps-mp-s0.mp1--2022_02_24_02_00/alps-mp-s0_mp1--2022_02_24_02_00/merged/device/mediateksample/k62v1_64_bsp/BoardConfig.mk
[ptgen-py] Need adjust start address for seccfg, because it is 0x522000 now.pad size is 0x2de000, and pre part [protect2]size is 0xade000 
[ptgen-py] Need adjust start address for sec1, because it is 0x80000 now.pad size is 0x780000, and pre part [seccfg]size is 0x800000 
[ptgen-py] Need adjust start address for md1img_a, because it is 0x500000 now.pad size is 0x300000, and pre part [logo]size is 0xb00000 
[ptgen-py] Need adjust start address for md1img_b, because it is 0x500000 now.pad size is 0x300000, and pre part [vbmeta_vendor_a]size is 0xb00000 
[ptgen-py] Need adjust start address for super, because it is 0x500000 now.pad size is 0x300000, and pre part [tee_b]size is 0x800000 

生成分区表(genfile_scatter)
[ptgen-py] Gen ymal file in Path out/target/product/k62v1_64_bsp/obj/PTGEN/../../MT6765_Android_scatter.txt
[ptgen-py] Gen xml file in Path out/target/product/k62v1_64_bsp/obj/PTGEN/../../MT6765_Android_scatter.xml
[ptgen-py] Gen partition_size.mk file in Path out/target/product/k62v1_64_bsp/obj/PTGEN/partition_size.mk

根据super分区设定的大小,对动态分区进行设置大小
[ptgen-py] main group size candi:
[ptgen-py] parts_sum := 4328521728
[ptgen-py] group_limit := 4292870144
[ptgen-py] final selected 4292870144

完成分区表设定,进行编译
[ptgen-py] Gen PGPT in Path out/target/product/k62v1_64_bsp/obj/PTGEN/../../PGPT_EMMC
[ptgen-py] !!!!!!!!!!!!!!!!!!! end !!!!!!!!!!!!!!!!!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值