目录

前言

一、分区文件

二、板级配置文件修改

二、分区文件添加

三、分区文件打包

四、rk356x-package-file文件修改

五、buildroot分区挂载表修改

六、编译

总结


前言

本文档主要介绍如何在瑞芯微官方SDK基础上修改分区大小以及添加分区操作,以下部分主要介绍在buildroot文件系统添加分区的操作步骤。

一、分区文件

RK3568 SDK分区文件在/rk356x_linux_220118/device/rockchip/rk356x目录下,以下主要以parameter-buildroot.txt为示例来进行说明:

FIRMWARE_VER: 1.0MACHINE_MODEL: RK3568MACHINE_ID: 007MANUFACTURER: RK3568MAGIC: 0x5041524BATAG: 0x00200800MACHINE: 0xffffffffCHECK_MASK: 0x80PWR_HLD: 0,0,A,0,1TYPE: GPTCMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00010000@0x00008000(boot),0x00010000@0x00018000(recovery),0x00010000@0x00028000(backup),0x00100000@0x00038000(rootfs),0x00100000@0x00138000(oem),0x00010000@0x00238000(sconf),-@0x00248000(userdata:grow)uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

其中CMDLINE属性是我们关注的地方,以uboot为例,0x00002000@0x00004000(uboot)中0x00004000为uboot分区的起始位置,0x00002000为分区的大小,以此类推,其中分区大小可以根据项目具体使用情况进行调整,现在对配置分区进行一个说明(其中sconf、userdata为在厂家sdk基础上增加的分区):

uboot 分区:供 uboot 编译出来的 uboot.img misc 分区:供 misc.img ,给 recovery 使用。 boot 分区:供 kernel 编译出来的 boot.img recovery 分区:供 recovery 编译出的 recovery.img backup 分区:预留,暂时没有用,后续跟 Android 一样作为 recovery backup 使用。 rootfs 分区:供 buildroot debian yocto 编出来的 rootfs.img oem 分区:给厂家使用,存放厂家的 APP 或数据。挂载在 /oem 目录。 sconf分区:配置分区–增加分区 userdata分区:数据分区-增加分区 下面主要介绍sconf、userdata分区的添加方法。

二、板级配置文件修改

板级配置文件在sdk/rk356x_linux_220118/device/rockchip/rk356x路径中,对添加分区格式以及分区文件目录进行定义,具体如下图所示:

二、分区文件添加

分区文件路径在sdk/rk356x_linux_220118/device/rockchip/路径下,根据板级配置文件制定,具体分区路径如下所示:

sconf配置分区

/rk356x_linux_220118/device/rockchip/sconf/sconf_r300

userdata数据分区

/rk356x_linux_220118/device/rockchip/userdata/userdata_empty

分区文件夹里面内容根据自己需求自行添加即可!

三、分区文件打包

分区文件打包需要修改mkfirmware.sh脚本文件,该文件在sdk根目录下:

添加修改部分如下图所示:

修改之后脚本内容如下所示:

#!/bin/bashset -eSCRIPT_DIR=$(dirname $(realpath $BASH_SOURCE))TOP_DIR=$(realpath $SCRIPT_DIR/../../..)cd $TOP_DIRfunction unset_board_config_all(){        local tmp_file=`mktemp`        grep -o "^export.*RK_.*=" `find $TOP_DIR/device/rockchip -name "Board*.mk" -type f` -h | sort | uniq > $tmp_file        source $tmp_file        rm -f $tmp_file}unset_board_config_allsource $TOP_DIR/device/rockchip/.BoardConfig.mkROCKDEV=$TOP_DIR/rockdevPARAMETER=$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_PARAMETERif [ "${RK_OEM_DIR}x" != "x" ];then        OEM_DIR=$TOP_DIR/device/rockchip/oem/$RK_OEM_DIRelse        OEM_DIR=fi#add by liubSCONF_DIR=$TOP_DIR/device/rockchip/sconf/$RK_SCONF_DIRUSER_DATA_DIR=$TOP_DIR/device/rockchip/userdata/$RK_USERDATA_DIRMISC_IMG=$TOP_DIR/device/rockchip/rockimg/$RK_MISCROOTFS_IMG=$TOP_DIR/$RK_ROOTFS_IMGROOTFS_IMG_SOURCE=$TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPERAMBOOT_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.imgRECOVERY_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RECOVERY/images/recovery.imgif which fakeroot; thenFAKEROOT_TOOL="`which fakeroot`"else        echo -e "Install fakeroot First."        echo -e "  sudo apt-get install fakeroot"        exit -1fi#add by liubSCONF_FAKEROOT_SCRIPT=$ROCKDEV/sconf.fsOEM_FAKEROOT_SCRIPT=$ROCKDEV/oem.fsUSERDATA_FAKEROOT_SCRIPT=$ROCKDEV/userdata.fsTRUST_IMG=$TOP_DIR/u-boot/trust.imgUBOOT_IMG=$TOP_DIR/u-boot/uboot.imgBOOT_IMG=$TOP_DIR/kernel/$RK_BOOT_IMGLOADER=$TOP_DIR/u-boot/*_loader_v*.binSPL=$TOP_DIR/u-boot/*_loader_spl.bin#SPINOR_LOADER=$TOP_DIR/u-boot/*_loader_spinor_v*.binMKIMAGE=$SCRIPT_DIR/mk-image.shmkdir -p $ROCKDEV# Require buildroot host tools to do image packing.if [ ! -d "$TARGET_OUTPUT_DIR" ]; then    echo "Source buildroot/build/envsetup.sh"        if [ "${RK_CFG_RAMBOOT}x" != "x" ];then                source $TOP_DIR/buildroot/build/envsetup.sh $RK_CFG_RAMBOOT        fi        if [ "${RK_CFG_BUILDROOT}x" != "x" ];then                source $TOP_DIR/buildroot/build/envsetup.sh $RK_CFG_BUILDROOT        fifi# NOT support the grow partitionget_partition_size() {        echo $PARAMETER        PARTITIONS_PREFIX=`echo -n "CMDLINE: mtdparts=rk29xxnand:"`        while read line        do                if [[ $line =~ $PARTITIONS_PREFIX ]]                then                        partitions=`echo $line | sed "s/$PARTITIONS_PREFIX//g"`                        echo $partitions                        break                fi        done  $OEM_FAKEROOT_SCRIPT                echo "set -e" >> $OEM_FAKEROOT_SCRIPT                if [ -d $OEM_DIR/www ]; then                        echo "chown -R www-data:www-data $OEM_DIR/www" >> $OEM_FAKEROOT_SCRIPT                fi                if [ "$RK_OEM_FS_TYPE" = "ubi" ]; then                        echo "$MKIMAGE $OEM_DIR $ROCKDEV/oem.img $RK_OEM_FS_TYPE ${RK_OEM_PARTITION_SIZE:-$oem_part_size_bytes} oem $RK_UBI_PAGE_SIZE $RK_UBI_BLOCK_SIZE"  >> $OEM_FAKEROOT_SCRIPT                else                        echo "$MKIMAGE $OEM_DIR $ROCKDEV/oem.img $RK_OEM_FS_TYPE"  >> $OEM_FAKEROOT_SCRIPT                fi                chmod a+x $OEM_FAKEROOT_SCRIPT                $FAKEROOT_TOOL -- $OEM_FAKEROOT_SCRIPT                rm -f $OEM_FAKEROOT_SCRIPT        else                echo "warning: $OEM_DIR  not found!"        fielse        if [ -f "$TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/oem.img" ]; then                ln -sfr $TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/oem.img $ROCKDEV/oem.img        fifiif [ $RK_USERDATA_DIR ]then        if [ -d "$USER_DATA_DIR" ]        then                echo "#!/bin/sh" > $USERDATA_FAKEROOT_SCRIPT                echo "set -e" >> $USERDATA_FAKEROOT_SCRIPT                if [ "$RK_USERDATA_FS_TYPE" = "ubi" ]; then                        echo "$MKIMAGE $USER_DATA_DIR $ROCKDEV/userdata.img $RK_USERDATA_FS_TYPE $RK_USERDATA_PARTITION_SIZE userdata $RK_UBI_PAGE_SIZE $RK_UBI_BLOCK_SIZE"  >> $USERDATA_FAKEROOT_SCRIPT                else                        echo "$MKIMAGE $USER_DATA_DIR $ROCKDEV/userdata.img $RK_USERDATA_FS_TYPE"  >> $USERDATA_FAKEROOT_SCRIPT                fi                chmod a+x $USERDATA_FAKEROOT_SCRIPT                $FAKEROOT_TOOL -- $USERDATA_FAKEROOT_SCRIPT                rm -f $USERDATA_FAKEROOT_SCRIPT        else                echo "warning: $USER_DATA_DIR not found!"        fifi#add by liubif [ $RK_SCONF_DIR ]then        if [ -d "$SCONF_DIR" ]        then                echo "#!/bin/sh" > $SCONF_FAKEROOT_SCRIPT                echo "set -e" >> $SCONF_FAKEROOT_SCRIPT                if [ "$RK_SCONF_FS_TYPE" = "ubi" ]; then                        echo "$MKIMAGE $SCONF_DIR $ROCKDEV/sconf.img $RK_SCONF_FS_TYPE $RK_SCONF_PARTITION_SIZE sconf $RK_UBI_PAGE_SIZE $RK_UBI_BLOCK_SIZE"  >> $SCONF_FAKEROOT_SCRIPT                else                        echo "$MKIMAGE $SCONF_DIR $ROCKDEV/sconf.img $RK_SCONF_FS_TYPE"  >> $SCONF_FAKEROOT_SCRIPT                fi                chmod a+x $SCONF_FAKEROOT_SCRIPT                $FAKEROOT_TOOL -- $SCONF_FAKEROOT_SCRIPT                rm -f $SCONF_FAKEROOT_SCRIPT        else                echo "warning: $SCONF_DIR not found!"        fifiif [ -f $UBOOT_IMG ]then        echo -n "create uboot.img..."        ln -rsf $UBOOT_IMG $ROCKDEV/uboot.img        echo "done."else        echo -e "\e[31m error: $UBOOT_IMG not found! \e[0m"fiif [ "$RK_UBOOT_FORMAT_TYPE" = "fit" ]; then        rm -f $ROCKDEV/trust.img        echo "uboot fotmat type is fit, so ignore trust.img..."elseif [ -f $TRUST_IMG ]then        echo -n "create trust.img..."        ln -rsf $TRUST_IMG $ROCKDEV/trust.img        echo "done."else        echo -e "\e[31m error: $TRUST_IMG not found! \e[0m"fifiif [ -f $LOADER ]then        echo -n "create loader..."        ln -rsf $LOADER $ROCKDEV/MiniLoaderAll.bin        echo "done."elif [ -f $SPL ]then        echo -n "create spl..."        ln -rsf $SPL $ROCKDEV/MiniLoaderAll.bin        echo "done."else        echo -e "\e[31m error: $LOADER not found,or there are multiple loaders! \e[0m"        rm $LOADER || truefi#if [ -f $SPINOR_LOADER ]#then#        echo -n "create spinor loader..."#        ln -rsf $SPINOR_LOADER $ROCKDEV/MiniLoaderAll_SpiNor.bin#        echo "done."#else#       rm $SPINOR_LOADER_PATH 2>/dev/null#fiif [ $RK_BOOT_IMG ]then        if [ -f $BOOT_IMG ]        then                echo -n "create boot.img..."                ln -rsf $BOOT_IMG $ROCKDEV/boot.img                echo "done."        else                echo "warning: $BOOT_IMG not found!"        fifiif [ $RK_CFG_RAMBOOT ]then        if [ -f $RAMBOOT_IMG ]        then                echo -n "create boot.img..."                ln -rsf $RAMBOOT_IMG $ROCKDEV/boot.img                echo "done."        else                echo "warning: $RAMBOOT_IMG not found!"        fifiif [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then        if [ -f $TOP_DIR/u-boot/boot.img ]        then                echo -n "Enable ramdisk security bootup, create boot.img..."                ln -rsf $TOP_DIR/u-boot/boot.img $ROCKDEV/boot.img                echo "done."        else                echo "warning: $TOP_DIR/u-boot/boot.img  not found!"        fificheck_partition_sizeecho -e "\e[36m Image: image in rockdev is ready \e[0m

四、rk356x-package-file文件修改

添加配置分区信息,在打包脚本在SDK

/rk356x_linux_220118/tools/linux/Linux_Pack_Firmware/rockdev路径下,具体修改如下图所示:

五、buildroot分区挂载表修改

在buildroot问下系统下修改系统挂载分区文件,在系统启动之后自动将sconf分区挂载到系统目录下,修改文件系统fstab文件,使用fs-overlay将修改文件上传到文件系统目录下,路径如下所示:

/rk356x_linux_220118/buildroot/board/rockchip/rk356x/fs-overlay-r300/etc/fstab,修改添加内容如下所示:

六、编译

./build.sh 使能板级配置文件,会在sdk根目录rockdev目录下产生配置分区img文件-sconf.img,此时sconf.img已经自动打包到系统固件update.img中,直接使用usb下载即可。

新增sconf分区如下图所示:


总结

以上为本人亲自试验总结出来的方法,希望对在rk3568 文件系统中添加修改分区提供参考!