RK3588 Android12 编译打包私有ext4格式vendor.img并挂载到新增vendor_private分区
一、制作可直接挂载的文件系统
使用simg2img工具直接将现有的vendor.img转换成可直接挂载的ext2格式,命名为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)mkupdate.sh 会通过gen-package-file.sh生成打包配置文件: RKTools/linux/Linux_Pack_Firmware/rockdev/package-file-tmp
./gen-package-file.sh $IMAGE_PATH > $PACKAGE_FILE
再通过工具根据 package-file-tmp 配置文件,打包成update.img.
./afptool -pack ./ $IMAGE_PATH/update.img $PACKAGE_FILE || pause
./rkImageMaker ${vendor_id_map[$PLATFORM]} $IMAGE_PATH/MiniLoaderAll.bin $IMAGE_PATH/update.img update.img -os_type:androidos || pause
具体看下gen-package-file.sh的实现,实现逻辑是过滤rockdev/Image-”产品名"目录下的 XXX.img 匹配从parameter.txt解析获得的对应XXX分区列表,并生成package-file-tmp,如果没有对应XXX.img就会用去除_后缀默认命名的img.
#!/bin/bash # Use: ./gen-package-file.sh IMAGE_PATH to genernate package-file IMAGE_PATH=$1 readonly HEADER="# NAME\tRelative path\n#\n##HWDEF\tHWDEF\npackage-file\tpackage-file\nbootloader\t$IMAGE_PATH/MiniLoaderAll.bin\nparameter\t$IMAGE_PATH/parameter.txt" readonly FOOTER="# 要写入backup分区的文件就是自身(update.img)\n# SELF 是关键字,表示升级文件(update.img)自身\n# 在生成升级文件时,不加入SELF文件的内容,但在头部信息中有记录\n# 在解包升级文件时,不解包SELF文件的内容。\nbackup RESERVED\n#update-script update-script\n#recover-script recover-script" readonly PARTITION_TABLE_FILE=$IMAGE_PATH/parameter.txt partitions_array=(`cat ${PARTITION_TABLE_FILE} |awk '/^CMDLINE/' |grep -Eo "[^(]*[)$]" |sed 's/.$//'|grep -v "userdata"`) find_all_of_partitions() { for partition in "${partitions_array[@]}" do if [ -f "$IMAGE_PATH/$partition.img" ]; then echo -e "$partition\t$IMAGE_PATH/$partition.img" elif [ -f "$IMAGE_PATH/${partition%%_*}.img" ]; then echo -e "$partition\t$IMAGE_PATH/${partition%%_*}.img" fi done } echo -e $HEADER find_all_of_partitions echo -e $FOOTER
如果以上打包流程正确,会看到package-file-tmp中有新增分区及对应img配置项:
vendor_private Image/vendor_private.img
查看最终生成的update.img就会发现大一些,说明已经编译打包Image/vendor_private.img 到对应的 vendor_private分区,再烧录固件系统启动后查看分区内容是否正常。
posted on 2023-05-04 16:12 sheldon_blogs 阅读(700) 评论(0) 编辑 收藏 举报