一、制作ext4格式的vendor.img
使用simg2img工具直接将现有的vendor.img转换成ext4格式的vendor.disk即可
./out/host/linux-x86/bin/simg2img out/target/product/ribeye/vendor.img vendor.disk
然后就可以直接挂载到新增分区对应的目录: mount vendor.disk /vendor_private
另外也可以手动创建一个空的磁盘文件用于挂载:
(1).创建一个800M大小的虚拟磁盘
dd if=/dev/zero of=vendor.disk bs=1024 count=819200
(2).loop虚拟磁盘vendor.disk
busybox losetup /dev/block/loop7 vendor.disk
(3).对虚拟磁盘进行格式化
busybox mkfs.ext4 /dev/block/loop7
(4).挂载虚拟磁盘到/vendor_private文件夹
mount -o loop -t ext4 /dev/block/loop7 /vendor_private
二、新增分区vendor_private并挂载
(1)在根目录下创建vendor_private目录
diff --git a/rootdir/Android.mk b/rootdir/Android.mk index 99d8f9a83..c9b302e27 100644 --- a/rootdir/Android.mk +++ b/rootdir/Android.mk @@ -128,6 +128,10 @@ LOCAL_POST_INSTALL_CMD += ; ln -sf /vendor/odm/overlay $(TARGET_ROOT_OUT)/odm/ov LOCAL_POST_INSTALL_CMD += ; ln -sf /vendor/odm/priv-app $(TARGET_ROOT_OUT)/odm/priv-app LOCAL_POST_INSTALL_CMD += ; ln -sf /vendor/odm/usr $(TARGET_ROOT_OUT)/odm/usr +LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/vendor_private # For /vendor_dlkm partition. LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/vendor_dlkm
(2)给vendor_private添加权限
diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts index 4df1488..7e02f88 100644 --- a/sepolicy/private/file_contexts +++ b/sepolicy/private/file_contexts @@ -3,3 +3,9 @@ # All Rockchip configs /data/misc/cfg_rockchip(/.*)? u:object_r:rockchip_config_data_file:s0 +/vendor_private(/.*)? u:object_r:cache_file:s0
(3)在fstab下添加新分区,挂载为ext4文件系统
在源码配置好编译环境之后,通过该指令找到当前工程使用的stab的模板文件:get_build_var PRODUCT_FSTAB_TEMPLATE
例如:device/rockchip/common/scripts/fstab_tools/fstab.in
+/dev/block/by-name/vendor_private /vendor_private ext4 noatime,nodiratime,nosuid,nodev,noauto_da_alloc,discard wait,check
(4)在parameter里面添加vendor_private分区
diff --git a/device/rockchip/rk3588/ribeye/BoardConfig.mk b/device/rockchip/rk3588/ribeye/BoardConfig.mk index 61980dc2..5dc04219 100755 --- a/device/rockchip/rk3588/ribeye/BoardConfig.mk +++ b/device/rockchip/rk3588/ribeye/BoardConfig.mk @@ -81,3 +81,8 @@ ifeq ($(BUILD_WITH_KERNEL_MEMORY_DEBUG), true) PRODUCT_KERNEL_CONFIG += dten_memdbg.config endif endif +BOARD_WITH_PRIVATE_PARTITIONS := vendor_private:800M
如果要添加多个分区则用逗号分隔:BOARD_WITH_PRIVATE_PARTITIONS := vendor_private:800M,data_private:1024M
(5)在RebuildParameter.mk中添加BOARD_WITH_PRIVATE_PARTITIONS
diff --git a/build/rockchip/RebuildParameter.mk b/build/rockchip/RebuildParameter.mk index 4e120e0..c6bd46d 100644 --- a/build/rockchip/RebuildParameter.mk +++ b/build/rockchip/RebuildParameter.mk @@ -42,6 +42,11 @@ ifdef BOARD_USERDATAIMAGE_PARTITION_SIZE partition_list := $(partition_list),data:$(BOARD_USERDATAIMAGE_PARTITION_SIZE) endif +ifneq ($(strip $(BOARD_WITH_PRIVATE_PARTITIONS )), ) +partition_list := $(partition_list),$(BOARD_WITH_PRIVATE_PARTITIONS) +endif
通过以上步骤编译的固件就是新增了一个vendor_private分区,并且挂载到了创建的vendor_private目录,查看目录内容就是分区上的内容。
查看有哪些分区:ls -l /dev/block/by-name/
total 0 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 backup -> /dev/block/mmcblk0p9 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 baseparameter -> /dev/block/mmcblk0p12 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 boot -> /dev/block/mmcblk0p7 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 cache -> /dev/block/mmcblk0p10 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 dtbo -> /dev/block/mmcblk0p5 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 metadata -> /dev/block/mmcblk0p11 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 misc -> /dev/block/mmcblk0p4 lrwxrwxrwx 1 root root 18 2023-05-04 03:26 mmcblk0 -> /dev/block/mmcblk0 lrwxrwxrwx 1 root root 23 2023-05-04 03:26 mmcblk0boot0 -> /dev/block/mmcblk0boot0 lrwxrwxrwx 1 root root 23 2023-05-04 03:26 mmcblk0boot1 -> /dev/block/mmcblk0boot1 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 recovery -> /dev/block/mmcblk0p8 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 security -> /dev/block/mmcblk0p1 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 super -> /dev/block/mmcblk0p13 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 trust -> /dev/block/mmcblk0p3 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 uboot -> /dev/block/mmcblk0p2 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 userdata -> /dev/block/mmcblk0p17 lrwxrwxrwx 1 root root 20 2023-05-04 03:26 vbmeta -> /dev/block/mmcblk0p6 lrwxrwxrwx 1 root root 21 2023-05-04 03:26 vendor_private -> /dev/block/mmcblk0p16
并可通过 cat /proc/partitions 查看当前所有分区的大小。
三、编译阶段打包文件系统到新增分区
分区需要有文件系统才能进行挂载,所以在新建分区后需要烧写一个带ext4文件系统的img到新建分区中,可以通过芯片厂商的工具进行手动分区烧录。
以下是修改源码的编译脚本,实现直接打包文件系统到主固件的对应分区:
(1)修改device/rockchip/common/mkimage.sh (注:需要更新到源码根目录下),将源码vendor/private/vendor_private.img 拷贝到 Image/ 目录下
diff --git a/mkimage.sh b/mkimage.sh index 69b733e..417744e 100755 --- a/mkimage.sh +++ b/mkimage.sh @@ -254,4 +254,12 @@ if [ $IS_EBOOK == "true" ]; then fi fi +cp vendor/private/vendor_private.img $IMAGE_PATH/vendor_private.img
(2)修改打包配置文件(包含需要打包的img路径):RKTools/linux/Linux_Pack_Firmware/rockdev/package-file
diff --git a/linux/Linux_Pack_Firmware/rockdev/package-file b/linux/Linux_Pack_Firmware/rockdev/package-file index 98ffc9f..e1527fc 100755 --- a/linux/Linux_Pack_Firmware/rockdev/package-file +++ b/linux/Linux_Pack_Firmware/rockdev/package-file @@ -13,6 +13,9 @@ vbmeta Image/vbmeta.img recovery Image/recovery.img baseparameter Image/baseparameter.img super Image/super.img +vendor_private Image/vendor_private.img
再编译生成的update.img就会发现大一些,说明已经编译打包Image/vendor_private.img 到对应的 vendor_private分区。
注:RKTools/linux/Linux_Pack_Firmware/rockdev/gen-package-file.sh 打包脚本会过滤.img的后缀,所以新增的私有img无论何种格式直接.img作为后置命名或者就得改脚本了。
标签:ext4,vendor,img,dev,private,root,block From: https://www.cnblogs.com/blogs-of-lxl/p/17371611.html