Android11.0(R) MTK平台添加新分区

文摘 Android MediaTek 2021-09-19 阅读:542

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

1.png

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 分区如图

2.png

————————————————
版权声明:本文为CSDN博主「cczhengv」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u012932409/article/details/120306037



0条评论

© 2021 芯缘异码. Powered by Typecho