mtk 平台增加一个新分区test,修改文件列表如下
modified: device/mediatek/mt6765/init.mt6765.rc modified: device/mediatek/mt6765/sepolicy/basic/device.te modified: device/mediatek/mt6765/sepolicy/basic/file_contexts modified: device/mediatek/mt6765/ueventd.mt6765.emmc.rc modified: device/mediatek/sepolicy/basic/non_plat/fsck.te modified: device/mediatek/sepolicy/basic/non_plat/init.te modified: vendor/mediatek/proprietary/hardware/fstab/mt6765/fstab.in.mt6765 modified: vendor/mediatek/proprietary/tools/ptgen/MT6765/partition_table_emmc_ab.csv
1、分区表中添加分区参数(配置分区文件格式、大小、对应img名称等)
配置表格式后缀为.csv,通过在 device 目录下搜索,找到目标平台文件夹下的配置表
vendor/mediatek/proprietary/tools/ptgen/MT6765/partition_table_emmc_ab.csv
2、修改 fstab 文件添加分区的挂载和系统启动时挂载权限
device/mediatek/mt6765/init.mt6765.rc
mkdir /mnt/cd-rom 0000 system system +# Create test mount pointer + mkdir /test 0711 system system + # change lk_env permission chown root system /proc/lk_env chmod 0660 /proc/lk_env
vendor/mediatek/proprietary/hardware/fstab/mt6765/fstab.in.mt6765
DEVPATH(nvdata) /mnt/vendor/nvdata ext4 FS_FLAG_COMMIT FSMGR_FLAG_FMT DEVPATH(nvcfg) /mnt/vendor/nvcfg ext4 FS_FLAG_COMMIT FSMGR_FLAG_FMT +DEVPATH(test) /test ext4 FS_FLAG_DISCARD FSMGR_FLAG_FMT
3、添加分区权限规则
device/mediatek/mt6765/ueventd.mt6765.emmc.rc
/dev/block/platform/bootdevice/by-name/md1img_a 0640 root system /dev/block/platform/bootdevice/by-name/md1img_b 0640 root system /dev/block/platform/bootdevice/by-name/md1dsp 0660 root system +/dev/block/platform/bootdevice/by-name/test 0640 root system
4、添加挂载分区的selinux权限
device/mediatek/mt6765/sepolicy/basic/device.te
type gps_emi_device, dev_type; +type test_block_device, dev_type;
device/mediatek/mt6765/sepolicy/basic/file_contexts
/dev/gps_emi(/.*)? u:object_r:gps_emi_device:s0 +/dev/block/platform/mtk-msdc\.0/[0-9]+\.msdc0/by-name/test u:object_r:test_block_device:s0
device/mediatek/sepolicy/basic/non_plat/init.te
allow init para_block_device:blk_file w_file_perms; +allow init test_block_device:blk_file rw_file_perms;
device/mediatek/sepolicy/basic/non_plat/fsck.te
allow fsck oem_block_device:blk_file rw_file_perms; +allow fsck test_block_device:blk_file rw_file_perms;
5、其它
本来弄完这些步骤后就能看到 /dev/block/by-name/test 分区节点了
后来又尝试了下和 Q 版本一样增加编译 test.img 规则代码,最终不成功
一直卡在最后一步生成 system.img 报错信息如下
FAILED: out/target/product/65gt/test.img /bin/bash -c "(mkdir -p out/target/product/65gt/test ) && (mkdir -p out/target/product/65gt/obj/PACKAGING/test_intermediates && rm -rf out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"test_fs_type=ext4\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"test_size=8388608\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"test_selinux_fc=out/target/product/65gt/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"ext_mkuserimg=mkuserimg_mke2fs\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"fs_type=ext4\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"extfs_sparse_flag=-s\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"squashfs_sparse_flag=-s\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"f2fs_sparse_flag=-S\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"system_verity_block_device=/dev/block/by-name/system\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"vendor_verity_block_device=/dev/block/by-name/vendor\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_avbtool=avbtool\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_add_hashtree_footer_args=--hash_algorithm sha256 --prop com.android.build.system.fingerprint:\$(cat out/target/product/65gt/build_fingerprint.txt) --prop com.android.build.system.os_version:11 --prop com.android.build.system.security_patch:2021-07-05\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_other_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_other_add_hashtree_footer_args=--rollback_index 1625443200\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_other_key_path=device/mediatek/system/common/oem_prvk.pem\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_other_algorithm=SHA256_RSA2048\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_vendor_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_vendor_add_hashtree_footer_args=--hash_algorithm sha256 --prop com.android.build.vendor.fingerprint:\$(cat out/target/product/65gt/build_fingerprint.txt) --prop com.android.build.vendor.os_version:11 --prop com.android.build.vendor.security_patch:2021-07-05\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_product_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_product_add_hashtree_footer_args=--hash_algorithm sha256 --prop com.android.build.product.fingerprint:\$(cat out/target/product/65gt/build_fingerprint.txt) --prop com.android.build.product.os_version:11 --prop com.android.build.product.security_patch:2021-07-05\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_ext_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_system_ext_add_hashtree_footer_args=--prop com.android.build.system_ext.fingerprint:\$(cat out/target/product/65gt/build_fingerprint.txt) --prop com.android.build.system_ext.os_version:11 --prop com.android.build.system_ext.security_patch:2021-07-05\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_odm_hashtree_enable=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"avb_odm_add_hashtree_footer_args=--hash_algorithm sha256 --prop com.android.build.odm.fingerprint:\$(cat out/target/product/65gt/build_fingerprint.txt) --prop com.android.build.odm.os_version:11\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"recovery_as_boot=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"root_dir=out/target/product/65gt/root\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"use_dynamic_partition_size=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (echo \"skip_fsck=true\" >> out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt ) && (PATH=out/host/linux-x86/bin/:system/extras/ext4_utils/:\$PATH out/host/linux-x86/bin/build_image out/target/product/65gt/test out/target/product/65gt/obj/PACKAGING/test_intermediates/test_image_info.txt out/target/product/65gt/test.img out/target/product/65gt/system ) && (size=\$(for i in out/target/product/65gt/test.img; do stat -c \"%s\" \"\$i\" | tr -d '\\n'; echo +; done; echo 0); total=\$(( \$( echo \"\$size\" ) )); printname=\$(echo -n \"out/target/product/65gt/test.img\" | tr \" \" +); maxsize=\$((8388608)); if [ \"\$total\" -gt \"\$maxsize\" ]; then echo \"error: \$printname too large (\$total > \$maxsize)\"; false; elif [ \"\$total\" -gt \$((maxsize - 32768)) ]; then echo \"WARNING: \$printname approaching size limit (\$total now; limit \$maxsize)\"; fi )" 2020-08-14 09:56:25 - build_image.py - ERROR : Failed to build out/target/product/65gt/test.img from out/target/product/65gt/test Out of space? Out of inodes? The tree size of out/target/product/65gt/test is 4096 bytes (0 MB), with reserved space of 0 bytes (0 MB). The max image size for filesystem files is 8388608 bytes (8 MB), out of a total partition size of 8388608 bytes (8 MB). Traceback (most recent call last): File "/linux/alps/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 174, in _run_module_as_main File "/linux/alps/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 72, in _run_code File "/linux/alps/out/host/linux-x86/bin/build_image/__main__.py", line 12, in <module> File "/linux/alps/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 174, in _run_module_as_main File "/linux/alps/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 72, in _run_code File "/linux/alps/out/host/linux-x86/bin/build_image/build_image.py", line 821, in <module> File "/linux/alps/out/host/linux-x86/bin/build_image/build_image.py", line 813, in main File "/linux/alps/out/host/linux-x86/bin/build_image/build_image.py", line 488, in BuildImage File "/linux/alps/out/host/linux-x86/bin/build_image/build_image.py", line 345, in BuildImageMkfs File "/linux/alps/out/host/linux-x86/bin/build_image/common.py", line 281, in RunAndCheckOutput common.ExternalError: Failed to run command '['mkuserimg_mke2fs', '-s', 'out/target/product/65gt/test', 'out/target/product/65gt/test.img', 'ext4', 'test', '8388608', '-D', 'out/target/product/65gt/system', '-L', 'test', '--inode_size', '256', 'out/target/product/65gt/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin']' (exit code 4): 09:56:21 mkuserimg_mke2fs.py INFO: Env: {'MKE2FS_CONFIG': '/linux/alps/out/soong/.temp/tmpCm0ao_'} 09:56:21 mkuserimg_mke2fs.py INFO: Running: mke2fs -L test -I 256 -M /test -E android_sparse -t ext4 -b 4096 out/target/product/65gt/test.img 2048 09:56:23 mkuserimg_mke2fs.py INFO: Env: {} 09:56:23 mkuserimg_mke2fs.py INFO: Running: e2fsdroid -p out/target/product/65gt/system -S out/target/product/65gt/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin -f out/target/product/65gt/test -a /test out/target/product/65gt/test.img 09:56:25 mkuserimg_mke2fs.py ERROR: Failed to run e2fsdroid_cmd: set_selinux_xattr: No such file or directory searching for label "/test" e2fsdroid: No such file or directory while configuring the file system mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 2048 4k blocks and 2048 inodes Allocating group tables: 0/1 done Writing inode tables: 0/1 done Creating journal (1024 blocks): done Writing superblocks and filesystem accounting information: 0/1 done set_selinux_xattr: No such file or directory searching for label "/test" e2fsdroid: No such file or directory while configuring the file system
应该是和 R 版本启用了 V-AB 分区有关系
最终烧写后 adb shell 查看新加 test 分区如图
6、更新一波
咳咳,此更新来自遥远的2089年,先整个图证明下
test.img 成功编译,并且烧录后根节点存在 /test
此次修改文件列表如下
modified: build/make/core/Makefile modified: build/make/core/board_config.mk modified: build/make/core/config.mk modified: build/make/core/envsetup.mk modified: build/make/core/main.mk modified: build/make/tools/releasetools/build_image.py modified: build/make/tools/releasetools/common.py modified: device/mediatek/mt6765/sepolicy/basic/device.te modified: device/mediatek/mt6765/sepolicy/basic/file_contexts modified: device/mediateksample/k65v1_64_bsp/BoardConfig.mk modified: system/core/rootdir/Android.mk modified: vendor/mediatek/proprietary/tools/ptgen/MT6765/partition_table_emmc_ab.csv
6.1、增加 test.img 对应编译代码
build/make/core/Makefile
$(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(1) $(if $(BOARD_TESTIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "test_fs_type=$(BOARD_TESTIMAGE_FILE_SYSTEM_TYPE)" >> $(1)) $(if $(BOARD_TESTIMAGE_PARTITION_SIZE),$(hide) echo "test_size=$(BOARD_TESTIMAGE_PARTITION_SIZE)" >> $(1)) $(hide) echo "test_selinux_fc=$(SELINUX_FC)" >> $(1) $(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1)) .............. # test image ------------------------------------------------------ # INTERNAL_TESTIMAGE_FILES := \ $(filter $(TARGET_OUT_TEST)/%,$(ALL_DEFAULT_INSTALLED_MODULES)) testimage_intermediates := \ $(call intermediates-dir-for,PACKAGING,test) BUILT_TESTIMAGE_TARGET := $(PRODUCT_OUT)/test.img define build-testimage-target $(call pretty,"Target test fs image: $(INSTALLED_TESTIMAGE_TARGET)") @mkdir -p $(TARGET_OUT_TEST) @mkdir -p $(testimage_intermediates) && rm -rf $(testimage_intermediates)/test_image_info.txt $(call generate-userimage-prop-dictionary, $(testimage_intermediates)/test_image_info.txt,skip_fsck=true) $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \ ./build/tools/releasetools/build_image.py \ $(TARGET_OUT_TEST) $(testimage_intermediates)/test_image_info.txt $(INSTALLED_TESTIMAGE_TARGET) $(TARGET_OUT) $(hide) $(call assert-max-image-size,$(INSTALLED_TESTIMAGE_TARGET),$(BOARD_TESTIMAGE_PARTITION_SIZE)) endef # We just build this directly to the install location. INSTALLED_TESTIMAGE_TARGET := $(BUILT_TESTIMAGE_TARGET) $(INSTALLED_TESTIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_TESTIMAGE_FILES) $(build-testimage-target) .PHONY: testimage-nodeps testimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS) $(build-testimage-target) # ----------------------------------------------------------------- # data partition image INTERNAL_USERDATAIMAGE_FILES := \ $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
build/make/core/board_config.mk
@@ -72,6 +72,7 @@ _board_strip_readonly_list += \ BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE \ BOARD_ODMIMAGE_PARTITION_SIZE \ BOARD_ODMIMAGE_FILE_SYSTEM_TYPE \ + BOARD_TESTIMAGE_PARTITION_SIZE \
build/make/core/config.mk
@@ -1213,6 +1213,7 @@ dont_bother_goals := out \ snod systemimage-nodeps \ userdataimage-nodeps \ cacheimage-nodeps \ + testimage-nodeps \ bptimage-nodeps \ vnod vendorimage-nodeps \ pnod productimage-nodeps \
build/make/core/envsetup.mk
@@ -580,6 +580,7 @@ $(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_METRIC_TESTS := $(TARGET_OUT_DATA $(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_METRIC_TESTS \ TARGET_OUT_CACHE := $(PRODUCT_OUT)/cache +TARGET_OUT_TEST := $(PRODUCT_OUT)/test .KATI_READONLY := TARGET_OUT_CACHE
build/make/core/main.mk
@@ -1394,6 +1394,9 @@ endif .PHONY: cacheimage cacheimage: $(INSTALLED_CACHEIMAGE_TARGET) +.PHONY: testimage +testimage: $(INSTALLED_TESTIMAGE_TARGET) + .PHONY: bptimage bptimage: $(INSTALLED_BPTIMAGE_TARGET) @@ -1449,6 +1452,7 @@ droidcore: $(filter $(HOST_OUT_ROOT)/%,$(modules_to_install)) \ $(INSTALLED_VBMETAIMAGE_TARGET) \ $(INSTALLED_USERDATAIMAGE_TARGET) \ $(INSTALLED_CACHEIMAGE_TARGET) \ + $(INSTALLED_TESTIMAGE_TARGET) \ $(INSTALLED_BPTIMAGE_TARGET) \ $(INSTALLED_VENDORIMAGE_TARGET) \ $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) \
build/make/tools/releasetools/build_image.py
@@ -614,6 +614,10 @@ def ImagePropFromGlobalDict(glob_dict, mount_point): copy_prop("cache_fs_type", "fs_type") copy_prop("cache_size", "partition_size") copy_prop("cache_selinux_fc", "selinux_fc") + elif mount_point == "test": + copy_prop("test_fs_type", "fs_type") + copy_prop("test_size", "partition_size") + copy_prop("test_selinux_fc", "selinux_fc") elif mount_point == "vendor": copy_prop("avb_vendor_hashtree_enable", "avb_hashtree_enable") copy_prop("avb_vendor_add_hashtree_footer_args", @@ -787,6 +791,8 @@ def main(argv): mount_point = "data" elif image_filename == "cache.img": mount_point = "cache" + elif image_filename == "test.img": + mount_point = "test" elif image_filename == "vendor.img": mount_point = "vendor" elif image_filename == "odm.img":
build/make/tools/releasetools/common.py
makeint("vendor_size") makeint("userdata_size") makeint("cache_size") + makeint("test_size") makeint("recovery_size") makeint("fstab_version")
device/mediateksample/k65v1_64_bsp/BoardConfig.mk
BOARD_VENDOR_RAMDISK_KERNEL_MODULES += # For Wifi BOARD_VENDOR_RAMDISK_KERNEL_MODULES += + +BOARD_TESTIMAGE_FILE_SYSTEM_TYPE := ext4 +# BOARD_TESTIMAGE_PARTITION_SIZE := 0
system/core/rootdir/Android.mk
@@ -125,6 +125,7 @@ ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE else LOCAL_POST_INSTALL_CMD += ; ln -sf /data/cache $(TARGET_ROOT_OUT)/cache endif +LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/test ifdef BOARD_ROOT_EXTRA_SYMLINKS
device/mediatek/mt6765/sepolicy/basic/device.te
type gps_emi_device, dev_type; +type test_file, dev_type;
device/mediatek/mt6765/sepolicy/basic/file_contexts
/dev/gps_emi(/.*)? u:object_r:gps_emi_device:s0 +# Label +/test(/.*)? u:object_r:test_file:s0
6.2、test.img 编译排错分析
错误一、 Not enough space to build proposed filesystem while setting up superblock
ERROR : Failed to build out/target/product/65gt/test.img from out/target/product/65gt/test
Out of space? Out of inodes? The tree size of out/target/product/65gt/test is 8192 bytes (0 MB), with reserved space of 0 bytes (0 MB).
The max image size for filesystem files is 20480 bytes (0 MB), out of a total partition size of 20480 bytes (0 MB)
这个问题我一直是以为分区大小太小,每次我修改 BOARD_TESTIMAGE_PARTITION_SIZE 的值,对应报错 log 中 bytes 就是其对应值
后来我研究了下流程,看了 odm 发现仅仅只是定义 BOARD_ODMIMAGE_PARTITION_SIZE,并未赋值
那就在同样的地方定义 BOARD_TESTIMAGE_PARTITION_SIZE ,再次编译未在报错
错误二、 ERROR: Failed to run e2fsdroid_cmd: set_selinux_xattr: No such file or directory searching for label “/test”
这个问题也是最一早就发现的,一开始没解决。后来找了找根据这篇
https://forum.xda-developers.com/t/android-los17-build-on-gcloud.4088065/
中提到解决办法增加 /test 规则最终解决。
6.3、烧写工具加载指定 img 文件路径
还是回到最初的 partition_table_emmc_ab.csv
一开始没注意这里面需要直接指定是否 DownLoad 和 对应 img,对照了 usedata.img 照抄就行
编译成功后,烧写工具中就自动加载 test.img
这个文件也挺有迷惑性,vendor\mediatek\proprietary\tools\ptgen\MT6765\emmc.yaml
里面配置和烧写对应规则及其相似。