RK3568开发笔记-SDK文件系统分区添加

目录

前言

一、分区文件

二、板级配置文件修改

二、分区文件添加

三、分区文件打包

四、rk356x-package-file文件修改

五、buildroot分区挂载表修改

六、编译

总结


前言

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

一、分区文件

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

FIRMWARE_VER: 1.0
MACHINE_MODEL: RK3568
MACHINE_ID: 007
MANUFACTURER: RK3568
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 0xffffffff
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
CMDLINE: 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路径中,对添加分区格式以及分区文件目录进行定义,具体如下图所示:

RK3568开发笔记-SDK文件系统分区添加_第1张图片

二、分区文件添加

分区文件路径在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根目录下:

RK3568开发笔记-SDK文件系统分区添加_第2张图片

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

RK3568开发笔记-SDK文件系统分区添加_第3张图片

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

#!/bin/bash

set -e

SCRIPT_DIR=$(dirname $(realpath $BASH_SOURCE))
TOP_DIR=$(realpath $SCRIPT_DIR/../../..)
cd $TOP_DIR

function 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_all

source $TOP_DIR/device/rockchip/.BoardConfig.mk
ROCKDEV=$TOP_DIR/rockdev
PARAMETER=$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_PARAMETER
if [ "${RK_OEM_DIR}x" != "x" ];then
        OEM_DIR=$TOP_DIR/device/rockchip/oem/$RK_OEM_DIR
else
        OEM_DIR=
fi

#add by liub
SCONF_DIR=$TOP_DIR/device/rockchip/sconf/$RK_SCONF_DIR

USER_DATA_DIR=$TOP_DIR/device/rockchip/userdata/$RK_USERDATA_DIR
MISC_IMG=$TOP_DIR/device/rockchip/rockimg/$RK_MISC
ROOTFS_IMG=$TOP_DIR/$RK_ROOTFS_IMG
ROOTFS_IMG_SOURCE=$TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE
RAMBOOT_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img
RECOVERY_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RECOVERY/images/recovery.img
if which fakeroot; then
FAKEROOT_TOOL="`which fakeroot`"
else
        echo -e "Install fakeroot First."
        echo -e "  sudo apt-get install fakeroot"
        exit -1
fi

#add by liub
SCONF_FAKEROOT_SCRIPT=$ROCKDEV/sconf.fs

OEM_FAKEROOT_SCRIPT=$ROCKDEV/oem.fs
USERDATA_FAKEROOT_SCRIPT=$ROCKDEV/userdata.fs
TRUST_IMG=$TOP_DIR/u-boot/trust.img
UBOOT_IMG=$TOP_DIR/u-boot/uboot.img
BOOT_IMG=$TOP_DIR/kernel/$RK_BOOT_IMG
LOADER=$TOP_DIR/u-boot/*_loader_v*.bin
SPL=$TOP_DIR/u-boot/*_loader_spl.bin
#SPINOR_LOADER=$TOP_DIR/u-boot/*_loader_spinor_v*.bin
MKIMAGE=$SCRIPT_DIR/mk-image.sh
mkdir -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
        fi
fi

# NOT support the grow partition
get_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 < $PARAMETER

        if [ -z $partitions ]
        then
                echo -e "\e[31m $PARAMETER parse no find string \"$PARTITIONS_PREFIX\" or The last line is not empty or other reason\e[0m"
                return
        fi

        PART_NAME_NEED_TO_CHECK=""
        IFS=,
        for part in $partitions;
        do
                part_size=`echo $part | cut -d '@' -f1`
                part_name=`echo $part | cut -d '(' -f2|cut -d ')' -f1`

                [[ $part_size =~ "-" ]] && continue

                part_size=$(($part_size))
                part_size_bytes=$[$part_size*512]

                case $part_name in
                        uboot|uboot_[ab])
                                uboot_part_size_bytes=$part_size_bytes
                                PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
                        ;;
                        boot|boot_[ab])
                                boot_part_size_bytes=$part_size_bytes
                                PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
                        ;;
                        recovery)
                                recovery_part_size_bytes=$part_size_bytes
                                PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
                        ;;
                        rootfs|system_[ab])
                                rootfs_part_size_bytes=$part_size_bytes
                                PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
                        ;;
                        oem)
                                oem_part_size_bytes=$part_size_bytes
                                PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
                        ;;
                esac
        done
}

check_partition_size() {

        while true
        do
                part_name=${PART_NAME_NEED_TO_CHECK##*:}
                case $part_name in
                        uboot|uboot_[ab])
                                uboot_img=`realpath $ROCKDEV/uboot.img`
                                if [ $uboot_part_size_bytes -lt `du -b $uboot_img | awk '{print $1}'` ]
                                then
                                        echo -e "\e[31m error: uboot image size exceed parameter! \e[0m"
                                        return -1
                                fi
                        ;;
                        boot|boot_[ab])
                                boot_img=`realpath $ROCKDEV/boot.img`
                                if [ $boot_part_size_bytes -lt `du -b $boot_img | awk '{print $1}'` ]
                                then
                                        echo -e "\e[31m error: boot image size exceed parameter! \e[0m"
                                        return -1
                                fi
                        ;;
                        recovery)
                                if [ -f $RECOVERY_IMG ]
                                then
                                        if [ $recovery_part_size_bytes -lt `du -b $RECOVERY_IMG | awk '{print $1}'` ]
                                        then
                                                echo -e "\e[31m error: recovery image size exceed parameter! \e[0m"
                                                return -1
                                        fi
                                fi
                        ;;
                        rootfs|system_[ab])
                                rootfs_img=`realpath $ROCKDEV/rootfs.img`
                                if [ -f $rootfs_img ]
                                then
                                        if [ $rootfs_part_size_bytes -lt `du -bD $rootfs_img | awk '{print $1}'` ]
                                        then
                                                echo -e "\e[31m error: rootfs image size exceed parameter! \e[0m"
                                                return -1
                                        fi
                                fi
                        ;;
                esac
                PART_NAME_NEED_TO_CHECK=${PART_NAME_NEED_TO_CHECK%:*}
                if [ -z "$PART_NAME_NEED_TO_CHECK" ]; then
                        break
                fi
        done
}

if [ $RK_ROOTFS_IMG ]
then
        if [ -f $ROOTFS_IMG ]
        then
                echo -n "create rootfs.img..."
                ln -rsf $ROOTFS_IMG $ROCKDEV/rootfs.img
                echo "done."
        else
                echo "warning: $ROOTFS_IMG not found!"
                if [ -f $ROOTFS_IMG_SOURCE ];then
                        echo "Fallback to $ROOTFS_IMG_SOURCE"
                        ln -rsf $ROOTFS_IMG_SOURCE $ROCKDEV/rootfs.img
                fi
        fi
fi

if [ -f $PARAMETER ]
then
        echo -n "create parameter..."
        ln -rsf $PARAMETER $ROCKDEV/parameter.txt
        echo "done."
else
        echo -e "\e[31m error: $PARAMETER not found! \e[0m"
        exit -1
fi

get_partition_size

if [ $RK_CFG_RECOVERY ]
then
        if [ -f $RECOVERY_IMG ]
        then
                echo -n "create recovery.img..."
                ln -rsf $RECOVERY_IMG $ROCKDEV/recovery.img
                echo "done."
        else
                echo "warning: $RECOVERY_IMG not found!"
        fi
fi

if [ $RK_MISC ]
then
        if [ -f $MISC_IMG ]
        then
                echo -n "create misc.img..."
                ln -rsf $MISC_IMG $ROCKDEV/misc.img
                echo "done."
        else
                echo "warning: $MISC_IMG not found!"
        fi
fi

if [ "${RK_OEM_BUILDIN_BUILDROOT}x" != "YESx" ]
then
        if [ -d "$OEM_DIR" ]
        then
                echo "#!/bin/sh" > $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!"
        fi
else
        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
        fi
fi

if [ $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!"
        fi
fi

#add by liub
if [ $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!"
        fi
fi

if [ -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"
fi

if [ "$RK_UBOOT_FORMAT_TYPE" = "fit" ]; then
        rm -f $ROCKDEV/trust.img
        echo "uboot fotmat type is fit, so ignore trust.img..."
else
if [ -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"
fi
fi

if [ -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 || true
fi

#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
#fi

if [ $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!"
        fi
fi

if [ $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!"
        fi
fi

if [ "$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!"
        fi
fi

check_partition_size

echo -e "\e[36m Image: image in rockdev is ready \e[0m

 

四、rk356x-package-file文件修改

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

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

RK3568开发笔记-SDK文件系统分区添加_第4张图片

五、buildroot分区挂载表修改

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

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

RK3568开发笔记-SDK文件系统分区添加_第5张图片

 

六、编译

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

RK3568开发笔记-SDK文件系统分区添加_第6张图片新增sconf分区如下图所示:

RK3568开发笔记-SDK文件系统分区添加_第7张图片


总结

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

你可能感兴趣的:(RK3568开发笔记,c语言,架构)