bsp: cvitek: use rttpkgtool to replace cvitek_bootloader

Originally, for riscv big and little cores under bsp/cvitek,
after generating rtthread.bin, the cvitek_bootloader tool
would be used to package it and generate fip.bin and boot.sd
files that can be burned into sdcard. However, the
cvitek_bootloader tool repository is relatively large, and
it compiles and generates firmware such as fsbl, opensbi and
uboot from the source code level. And when using it, it
needs to be downloaded to the bsp/cvitek directory, which
will introduce pollution to source files in the RTT repository
under the original working path.

The new solution uses rttpkgtool, which is similar to
cvitek_bootloader, but it uses prebuilt firmware, so it is
very small and does not introduce pollution to the source file.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
This commit is contained in:
Chen Wang 2025-01-16 15:45:44 +08:00 committed by Rbb666
parent 2a18d6873b
commit 7e0acaa254
5 changed files with 125 additions and 6 deletions

View File

@ -1,5 +1,3 @@
cvitek_bootloader
fip.bin
boot.sd
output
rttpkgtool/
output/
Image.lzma

68
bsp/cvitek/build.sh Executable file
View File

@ -0,0 +1,68 @@
#!/bin/bash
source ./tools.sh
function usage() {
echo "Usage:"
echo " ./build.sh [-h|-l|-b]"
echo " -h: display usage"
echo " -l: build c906L"
echo " -b: build c906B"
}
function build_c906b() {
echo "build_c906b"
BOARD_TYPE=`get_board_type $BSP_PATH/cv18xx_risc-v`
echo "BOARD_TYPE: $BOARD_TYPE"
DPT_PATH_KERNEL=$BSP_PATH/../../ DPT_BOARD_TYPE=$BOARD_TYPE DPT_PATH_OUTPUT=$BSP_PATH/output ./rttpkgtool/script/mkpkg.sh -b
}
function build_c906l() {
echo "build_c906l"
BOARD_TYPE=`get_board_type $BSP_PATH/c906_little`
echo "BOARD_TYPE: $BOARD_TYPE"
DPT_PATH_KERNEL=$BSP_PATH/../../ DPT_BOARD_TYPE=$BOARD_TYPE DPT_PATH_OUTPUT=$BSP_PATH/output ./rttpkgtool/script/mkpkg.sh -l
}
while getopts ":hbl" opt
do
case $opt in
h)
O_HELP=y
;;
b)
O_MAKE_BIG=y
;;
l)
O_MAKE_LITTLE=y
;;
?)
echo "Unrecognized parameter."
usage
exit 1
;;
esac
done
if [ "$O_HELP" = "y" ]; then
usage
exit 0
fi
BSP_PATH=$(realpath $(dirname $0))
echo "BSP_PATH: $BSP_PATH"
download_rttpkgtool $BSP_PATH
if [ "$O_MAKE_BIG" = "y" ]; then
build_c906b
fi
if [ "$O_MAKE_LITTLE" = "y" ]; then
build_c906l
fi

View File

@ -64,4 +64,4 @@ if PLATFORM == 'gcc':
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
POST_ACTION += 'cd .. && bash combine-fip.sh ' + os.getcwd() + ' rtthread.bin' + ' \n'
POST_ACTION += 'cd .. && bash ./build.sh -l' + ' \n'

View File

@ -57,4 +57,4 @@ if PLATFORM == 'gcc':
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtthread.asm\n'
POST_ACTION = OBJCPY + ' -O binary $TARGET Image \n' + SIZE + ' $TARGET \n'
POST_ACTION += 'cd .. && bash mksdimg.sh ' + os.getcwd() + ' Image \n'
POST_ACTION += 'cd .. && bash ./build.sh -b' + ' \n'

53
bsp/cvitek/tools.sh Normal file
View File

@ -0,0 +1,53 @@
# NOTE: Don't execute this script directly. It should be sourced by another script.
# Description: This script contains utility functions.
function get_board_type()
{
local project_path=$1
local supported_board_configs=("CONFIG_BOARD_TYPE_MILKV_DUO" "CONFIG_BOARD_TYPE_MILKV_DUO256M" "CONFIG_BOARD_TYPE_MILKV_DUOS")
local supported_board_types=("duo" "duo256m" "duos")
local board_type="N/A"
for ((i=0; i< ${#supported_board_configs[@]}; i++))
do
config_value=$(grep -w "${supported_board_configs[i]}" ${project_path}/.config | cut -d= -f2)
if [ "$config_value" == "y" ]; then
board_type=${supported_board_types[i]}
break
fi
done
echo ${board_type}
}
function download_rttpkgtool()
{
local project_path=$1
local restult=$(curl -m 10 -s http://www.ip-api.com/json)
local country=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
#echo "Country: $country"
if [ "$country" == "China" ]; then
local url_rttpkgtool="https://gitee.com/unicornx/rttpkgtool.git"
else
local url_rttpkgtool="https://github.com/plctlab/rttpkgtool.git"
fi
#echo "rttpkgtool URL: ${url_rttpkgtool}"
if [ ! -d ${project_path}/rttpkgtool ]; then
echo "rttpkgtool does not exist, clone it from ${url_rttpkgtool}"
git clone ${url_rttpkgtool} ${project_path}/rttpkgtool
if [ $? -ne 0 ]; then
echo "Failed to clone ${url_rttpkgtool} !"
exit 1
fi
else
echo "rttpkgtool already exists"
pushd ${project_path}/rttpkgtool
git checkout main
git pull
popd
fi
}