diff --git a/bsp/cvitek/.gitignore b/bsp/cvitek/.gitignore index c4ea9348dd..adb46db0ab 100755 --- a/bsp/cvitek/.gitignore +++ b/bsp/cvitek/.gitignore @@ -1,5 +1,3 @@ -cvitek_bootloader -fip.bin -boot.sd -output +rttpkgtool/ +output/ Image.lzma \ No newline at end of file diff --git a/bsp/cvitek/build.sh b/bsp/cvitek/build.sh new file mode 100755 index 0000000000..c163ccc738 --- /dev/null +++ b/bsp/cvitek/build.sh @@ -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 + diff --git a/bsp/cvitek/c906_little/rtconfig.py b/bsp/cvitek/c906_little/rtconfig.py index 50c32d5561..9d139d9e94 100755 --- a/bsp/cvitek/c906_little/rtconfig.py +++ b/bsp/cvitek/c906_little/rtconfig.py @@ -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' \ No newline at end of file +POST_ACTION += 'cd .. && bash ./build.sh -l' + ' \n' \ No newline at end of file diff --git a/bsp/cvitek/cv18xx_risc-v/rtconfig.py b/bsp/cvitek/cv18xx_risc-v/rtconfig.py index 8137d1d922..91ccaa795b 100755 --- a/bsp/cvitek/cv18xx_risc-v/rtconfig.py +++ b/bsp/cvitek/cv18xx_risc-v/rtconfig.py @@ -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' diff --git a/bsp/cvitek/tools.sh b/bsp/cvitek/tools.sh new file mode 100644 index 0000000000..d022e2a8ca --- /dev/null +++ b/bsp/cvitek/tools.sh @@ -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 +} \ No newline at end of file