在最新的Android 版本上如何新增一个分区呢?总的来说,细节是比较复杂的,由于新的版本上
增加Image签名,Verify,动态分区等功能概念,所以还是有很多细节需要处理。大的原则上是:
1、增加分区表,不同平台方法不一样;高通通过修改xml,MTK通过修改Excel文件
2、是否是纯数据分区,是否需要Signed。这个比较关键,因为脚本build_image.py执行不同
3、配置mount节点,分区权限
4、下载工具能否正常下载
用MTK举例,列举如下关键文件:
1. build_image.py build/make/tools/releasetools/common.py: makeint("userdata_size")
2. build/make/core/Makfile device/mediatek/build/build/tools/ptgen/MT6771/ptgen.pl:
3. Sign.py SignTool.py
4. mkuserimg_mke2fs.sh
mke2fs对应的源码:external/e2fsprogs/misc/mke2fs.c
e2fsdroid对应的源码 : external/e2fsprogs/contrib/android/e2fsdroid.c
mke2fs -L data -E android_sparse -t ext4 -b 4096
out/target/product/kxx_bsp/userdata.img 786432
5. device/mediatek/mt6771/factory_init.rc
6. system/sepolicy/private/file_contexts
7. device/mediatek/sepolicy/basic/non_plat/file_contexts:/dev/block/platform/mtk-\b(msdc|ufs)\b\.0/[0-9]+\.\b(msdc0|ufs0)\b/by-name/userdata
8. system/sepolicy/private/file_contexts:/data(/.*)? u:object_r:system_data_file:s0
9. vendor/mediatek/proprietary/hardware/fstab/mt6771/fstab.in:DEVPATH(userdata) /data
注意,如下两种不同类型分区,挂载的权限是不一样的;data可以读写,而vendor只有read only
#define FSMGR_FLAG_SYSTEM wait,slotselect,verify,recoveryonly
#define FS_FLAG_DATA noatime,nosuid,nodev,discard,noflush_merge
DEVPATH(userdata) /data __MTK_DATAIMG_FSTYPE FS_FLAG_DATA FSMGR_FLAG_DATA
DEVPATH(vendor) /vendor __MTK_VNDIMG_FSTYPE ro FSMGR_FLAG_SYSTEM
10. device/mediatek/mt6771/factory_init.rc: mount ext4 /dev/block/platform/bootdevice/by-name/userdata
#############################
# Data files
#
# NOTE: When modifying existing label rules, changes may also need to
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
#############################
# OEM and ODM files
#
/(odm|vendor/odm)(/.*)? u:object_r:vendor_file:s0
Log: size要注意 * block size
'mkuserimg_mke2fs.sh', '-s', 'out/target/product/k71v1_64_bsp/data', 'out/target/product/k71v1_64_bsp/userdata.img', 'ext4', 'data', '3221225472', '-D', 'out/target/product/k71v1_64_bsp/system', '-L', 'data',