Skip to content

Commit

Permalink
[bsp/cvitek] Update packaging method
Browse files Browse the repository at this point in the history
Use pre-build files to reduce compilation time

Signed-off-by: flyingcys <[email protected]>
  • Loading branch information
flyingcys committed Sep 20, 2024
1 parent 8790649 commit 7df04a0
Show file tree
Hide file tree
Showing 65 changed files with 1,311 additions and 123 deletions.
54 changes: 19 additions & 35 deletions bsp/cvitek/board_env.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
#!/bin/bash

function get_board_type()
function check_board()
{
BOARD_CONFIG=("CONFIG_BOARD_TYPE_MILKV_DUO" "CONFIG_BOARD_TYPE_MILKV_DUO_SPINOR" "CONFIG_BOARD_TYPE_MILKV_DUO_SPINAND" "CONFIG_BOARD_TYPE_MILKV_DUO256M" "CONFIG_BOARD_TYPE_MILKV_DUO256M_SPINOR" "CONFIG_BOARD_TYPE_MILKV_DUO256M_SPINAND" "CONFIG_BOARD_TYPE_MILKV_DUOS")
BOARD_VALUE=("milkv-duo" "milkv-duo-spinor" "milkv-duo-spinand" "milkv-duo256m" "milkv-duo256m-spinor" "milkv-duo256m-spinand" "milkv-duos-sd")
STORAGE_VAUE=("sd" "spinor" "spinand" "sd" "spinor" "spinand" "sd")
local config_file=$1/.config

for ((i=0;i<${#BOARD_CONFIG[@]};i++))
do
config_value=$(grep -w "${BOARD_CONFIG[i]}" ${PROJECT_PATH}/.config | cut -d= -f2)
if [ "$config_value" == "y" ]; then
BOARD_TYPE=${BOARD_VALUE[i]}
STORAGE_TYPE=${STORAGE_VAUE[i]}
break
fi
done
export BOARD_TYPE=${BOARD_TYPE}
export STORAGE_TYPE=${STORAGE_TYPE}
}
board_type=$(grep -E '^CONFIG_BOARD_TYPE_.*=y' "$config_file" | sed 's/CONFIG_BOARD_TYPE_//;s/=y$//')

function check_bootloader()
{
restult=$(curl -m 10 -s http://www.ip-api.com/json)
COUNTRY=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
echo "Country: $COUNTRY"

if [ "$COUNTRY" == "China" ]; then
BOOTLOADER_URL=https://gitee.com/flyingcys/cvitek_bootloader
else
BOOTLOADER_URL=https://github.com/flyingcys/cvitek_bootloader
if [ -z "$board_type" ]; then
echo "No board type found in the config file."
return 1
fi

if [ ! -d cvitek_bootloader ]; then
echo "cvitek_bootloader not exist, clone it from ${BOOTLOADER_URL}"
git clone ${BOOTLOADER_URL}
BOARD_TYPE=$(echo "$board_type" | tr '[:upper:]' '[:lower:]')
STORAGE_TYPE="${BOARD_TYPE##*_}"

soc_type=$(grep -E '^CONFIG_SOC_TYPE_.*=y' "$config_file" | sed 's/CONFIG_SOC_TYPE_//;s/=y$//')
if [ -z "$soc_type" ]; then
echo "No soc type found in the config file."
return 1
fi

if [ $? -ne 0 ]; then
echo "Failed to clone ${BOOTLOADER_URL} !"
exit 1
fi
fi
}
SOC_TYPE=$(echo "$soc_type" | tr '[:upper:]' '[:lower:]')

export BOARD_TYPE STORAGE_TYPE SOC_TYPE

return 0
}
8 changes: 6 additions & 2 deletions bsp/cvitek/c906_little/.config
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ CONFIG_ARCH_RISCV=y
CONFIG_ARCH_RISCV_FPU=y
CONFIG_ARCH_RISCV_FPU_D=y
CONFIG_ARCH_RISCV64=y
CONFIG_ARCH_USING_NEW_CTX_SWITCH=y

#
# RT-Thread Components
Expand Down Expand Up @@ -934,6 +935,7 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_PKG_USING_ARDUINO_MSGQ_C_CPP_DEMO is not set
# CONFIG_PKG_USING_ARDUINO_SKETCH_LOADER_DEMO is not set
# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
# CONFIG_PKG_USING_ARDUINO_RTDUINO_SENSORFUSION_SHIELD is not set
# CONFIG_PKG_USING_ARDUINO_NINEINONE_SENSOR_SHIELD is not set
# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
# CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
Expand Down Expand Up @@ -1175,6 +1177,7 @@ CONFIG_BSP_UART_IRQ_BASE=30
# CONFIG_BSP_USING_ADC is not set
# CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_WDT is not set
# CONFIG_BSP_USING_TIMER is not set
# CONFIG_BSP_USING_PWM is not set
# CONFIG_BSP_USING_RTC is not set
# end of General Drivers Configuration
Expand All @@ -1186,7 +1189,8 @@ CONFIG_BSP_TIMER_CLK_FREQ=25000000
CONFIG_BSP_GPIO_IRQ_BASE=41
CONFIG_BSP_SYS_GPIO_IRQ_BASE=47
CONFIG_SOC_TYPE_SG2002=y
# CONFIG_BOARD_TYPE_MILKV_DUO is not set
# CONFIG_BOARD_TYPE_MILKV_DUO_SD is not set
# CONFIG_BOARD_TYPE_MILKV_DUO_SPINOR is not set
CONFIG_BOARD_TYPE_MILKV_DUO256M=y
CONFIG_BOARD_TYPE_MILKV_DUO256M_SD=y
# CONFIG_BOARD_TYPE_MILKV_DUO256M_SPINOR is not set
# CONFIG_BOARD_TYPE_MILKV_DUOS_SD is not set
14 changes: 7 additions & 7 deletions bsp/cvitek/c906_little/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ config SOC_TYPE_SG2002

choice
prompt "Board Type"
default BOARD_TYPE_MILKV_DUO256M
default BOARD_TYPE_MILKV_DUO256M_SD

config BOARD_TYPE_MILKV_DUO
config BOARD_TYPE_MILKV_DUO_SD
select SOC_TYPE_CV180X
bool "milkv-duo"
bool "milkv-duo-sd"

config BOARD_TYPE_MILKV_DUO_SPINOR
select SOC_TYPE_CV180X
bool "milkv-duo-spinor"

config BOARD_TYPE_MILKV_DUO256M
config BOARD_TYPE_MILKV_DUO256M_SD
select SOC_TYPE_SG2002
bool "milkv-duo256m"
bool "milkv-duo256m-sd"

config BOARD_TYPE_MILKV_DUO256M_SPINOR
select SOC_TYPE_SG2002
bool "milkv-duo256m-spinor"

config BOARD_TYPE_MILKV_DUOS
config BOARD_TYPE_MILKV_DUOS_SD
select SOC_TYPE_SG2000
bool "milkv-duos"
bool "milkv-duos-sd"

endchoice
2 changes: 1 addition & 1 deletion bsp/cvitek/c906_little/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
# include libraries
objs.extend(SConscript(drivers_path_prefix + '/SConscript', variant_dir='build/drivers', duplicate=0))

if GetDepend('BOARD_TYPE_MILKV_DUO256M') or GetDepend('BOARD_TYPE_MILKV_DUOS'):
if GetDepend('BOARD_TYPE_MILKV_DUO256M_SD') or GetDepend('BOARD_TYPE_MILKV_DUOS_SD'):
env['LINKFLAGS'] = env['LINKFLAGS'].replace('cv180x_lscript.ld', 'cv181x_lscript.ld')
env['LINKFLAGS'] = env['LINKFLAGS'].replace('-L board/script/cv180x', '-L board/script/cv181x')

Expand Down
3 changes: 2 additions & 1 deletion bsp/cvitek/c906_little/rtconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define ARCH_RISCV_FPU
#define ARCH_RISCV_FPU_D
#define ARCH_RISCV64
#define ARCH_USING_NEW_CTX_SWITCH

/* RT-Thread Components */

Expand Down Expand Up @@ -335,6 +336,6 @@
#define BSP_GPIO_IRQ_BASE 41
#define BSP_SYS_GPIO_IRQ_BASE 47
#define SOC_TYPE_SG2002
#define BOARD_TYPE_MILKV_DUO256M
#define BOARD_TYPE_MILKV_DUO256M_SD

#endif
83 changes: 53 additions & 30 deletions bsp/cvitek/combine-fip.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

PROJECT_PATH=$1
IMAGE_NAME=$2
Expand All @@ -8,42 +9,64 @@ if [ -z "$PROJECT_PATH" ] || [ -z "$IMAGE_NAME" ]; then
exit 1
fi

function do_combine()
{
local PROJECT_PATH=$1
local IMAGE_NAME=$2

BLCP_IMG_RUNADDR=0x05200200
BLCP_PARAM_LOADADDR=0
NAND_INFO=00000000
NOR_INFO='FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
FIP_COMPRESS=lzma

BUILD_PLAT=${ROOT_PATH}/pre-build/fsbl/build/${SOC_TYPE}

CHIP_CONF_PATH=${BUILD_PLAT}/chip_conf.bin
DDR_PARAM_TEST_PATH=${ROOT_PATH}/pre-build/fsbl/test/ddr_param.bin
BLCP_PATH=${ROOT_PATH}/pre-build/fsbl/test/empty.bin

MONITOR_PATH=${ROOT_PATH}/pre-build/opensbi/${BOARD_TYPE}/fw_dynamic.bin
LOADER_2ND_PATH=${ROOT_PATH}/pre-build/u-boot-2021.10/${BOARD_TYPE}/u-boot-raw.bin

BLCP_2ND_PATH=$PROJECT_PATH/$IMAGE_NAME

echo "Combining fip.bin..."
. ./pre-build/fsbl/build/${SOC_TYPE}/blmacros.env && \
python3 ./pre-build/fsbl/plat/fiptool.py -v genfip \
${ROOT_PATH}/output/${BOARD_TYPE}/fip.bin \
--MONITOR_RUNADDR="${MONITOR_RUNADDR}" \
--BLCP_2ND_RUNADDR="${BLCP_2ND_RUNADDR}" \
--CHIP_CONF=${CHIP_CONF_PATH} \
--NOR_INFO=${NOR_INFO} \
--NAND_INFO=${NAND_INFO} \
--BL2=${BUILD_PLAT}/bl2.bin \
--BLCP_IMG_RUNADDR=${BLCP_IMG_RUNADDR} \
--BLCP_PARAM_LOADADDR=${BLCP_PARAM_LOADADDR} \
--BLCP=${BLCP_PATH} \
--DDR_PARAM=${DDR_PARAM_TEST_PATH} \
--BLCP_2ND=${BLCP_2ND_PATH} \
--MONITOR=${MONITOR_PATH} \
--LOADER_2ND=${LOADER_2ND_PATH} \
--compress=${FIP_COMPRESS}
}

ROOT_PATH=$(pwd)
echo $ROOT_PATH

. board_env.sh

get_board_type
echo "board_type: ${BOARD_TYPE}"

check_bootloader || exit 0

export BLCP_2ND_PATH=${PROJECT_PATH}/${IMAGE_NAME}

pushd cvitek_bootloader

. env.sh

get_build_board ${BOARD_TYPE}

echo "board: ${MV_BOARD_LINK}"

if [ ! -d opensbi/build/platform/generic ] || [ ! -d fsbl/build/${MV_BOARD_LINK} ] || [ ! -d u-boot-2021.10/build/${MV_BOARD_LINK} ]; then
do_build

CHIP_ARCH_L=$(echo $CHIP_ARCH | tr '[:upper:]' '[:lower:]')
cp -rf build/output/${MV_BOARD_LINK}/cvi_board_memmap.ld ${ROOT_PATH}/c906_little/board/script/${CHIP_ARCH_L}
if check_board ${PROJECT_PATH} ; then
echo "board type: ${BOARD_TYPE}"
echo "storage type: ${STORAGE_TYPE}"
else
echo "Build already done, skip build"

do_combine

if [ $? -ne 0 ]; then
do_build
fi
echo "board type not found"
exit 1
fi

popd
mkdir -p output/${BOARD_TYPE}
do_combine $PROJECT_PATH $IMAGE_NAME

echo "=== Done fip combine for ${BOARD_TYPE} successfully! ==="

mkdir -p output/${MV_BOARD}
cp -rf cvitek_bootloader/install/soc_${MV_BOARD_LINK}/fip.bin output/${MV_BOARD}/fip.bin
exit 0
6 changes: 3 additions & 3 deletions bsp/cvitek/cv18xx_aarch64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ config SOC_TYPE_SG2002

choice
prompt "Board Type"
default BOARD_TYPE_MILKV_DUO256M
default BOARD_TYPE_MILKV_DUO256M_SD

config BOARD_TYPE_MILKV_DUO256M
config BOARD_TYPE_MILKV_DUO256M_SD
select SOC_TYPE_SG2002
bool "milkv-duo256m"
bool "milkv-duo256m-sd"

config BOARD_TYPE_MILKV_DUO256M_SPINOR
select SOC_TYPE_SG2002
Expand Down
35 changes: 32 additions & 3 deletions bsp/cvitek/cv18xx_risc-v/.config
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CONFIG_ARCH_RISCV=y
CONFIG_ARCH_RISCV_FPU=y
CONFIG_ARCH_RISCV_FPU_D=y
CONFIG_ARCH_RISCV64=y
CONFIG_ARCH_USING_NEW_CTX_SWITCH=y
CONFIG_ARCH_USING_RISCV_COMMON64=y

#
Expand Down Expand Up @@ -431,6 +432,7 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_FREEMODBUS is not set
# CONFIG_PKG_USING_NANOPB is not set
# CONFIG_PKG_USING_WIFI_HOST_DRIVER is not set

#
# Wi-Fi
Expand Down Expand Up @@ -535,6 +537,7 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_ZEPHYR_POLLING is not set
# CONFIG_PKG_USING_MATTER_ADAPTATION_LAYER is not set
# CONFIG_PKG_USING_LHC_MODBUS is not set
# CONFIG_PKG_USING_QMODBUS is not set
# end of IoT - internet of things

#
Expand Down Expand Up @@ -562,6 +565,7 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_PARSON is not set
# CONFIG_PKG_USING_RYAN_JSON is not set
# end of JSON: JavaScript Object Notation, a lightweight data-interchange format

#
Expand Down Expand Up @@ -680,6 +684,8 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
# end of enhanced kernel services

# CONFIG_PKG_USING_AUNITY is not set

#
# acceleration: Assembly language or algorithmic acceleration packages
#
Expand Down Expand Up @@ -770,11 +776,29 @@ CONFIG_RT_USING_ADT_REF=y
#
# STM32 HAL & SDK Drivers
#
# CONFIG_PKG_USING_STM32L4XX_HAL_DRIVER is not set
# CONFIG_PKG_USING_STM32F4_HAL_DRIVER is not set
# CONFIG_PKG_USING_STM32F4_CMSIS_DRIVER is not set
# CONFIG_PKG_USING_STM32L4_HAL_DRIVER is not set
# CONFIG_PKG_USING_STM32L4_CMSIS_DRIVER is not set
# CONFIG_PKG_USING_STM32WB55_SDK is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# end of STM32 HAL & SDK Drivers

#
# Infineon HAL Packages
#
# CONFIG_PKG_USING_INFINEON_CAT1CM0P is not set
# CONFIG_PKG_USING_INFINEON_CMSIS is not set
# CONFIG_PKG_USING_INFINEON_CORE_LIB is not set
# CONFIG_PKG_USING_INFINEON_MTB_HAL_CAT1 is not set
# CONFIG_PKG_USING_INFINEON_MTB_PDL_CAT1 is not set
# CONFIG_PKG_USING_INFINEON_RETARGET_IO is not set
# CONFIG_PKG_USING_INFINEON_CAPSENSE is not set
# CONFIG_PKG_USING_INFINEON_CSDIDAC is not set
# CONFIG_PKG_USING_INFINEON_SERIAL_FLASH is not set
# CONFIG_PKG_USING_INFINEON_USBDEV is not set
# end of Infineon HAL Packages

# CONFIG_PKG_USING_BLUETRUM_SDK is not set
# CONFIG_PKG_USING_EMBARC_BSP is not set
# CONFIG_PKG_USING_ESP_IDF is not set
Expand Down Expand Up @@ -948,6 +972,7 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_SYSTEM_RUN_LED is not set
# CONFIG_PKG_USING_BT_MX01 is not set
# CONFIG_PKG_USING_RGPOWER is not set
# CONFIG_PKG_USING_BT_MX02 is not set
# CONFIG_PKG_USING_SPI_TOOLS is not set
# end of peripheral libraries and drivers

Expand All @@ -969,6 +994,7 @@ CONFIG_RT_USING_ADT_REF=y
#
# Signal Processing and Control Algorithm Packages
#
# CONFIG_PKG_USING_APID is not set
# CONFIG_PKG_USING_FIRE_PID_CURVE is not set
# CONFIG_PKG_USING_QPID is not set
# CONFIG_PKG_USING_UKAL is not set
Expand Down Expand Up @@ -1056,6 +1082,7 @@ CONFIG_RT_USING_ADT_REF=y
# CONFIG_PKG_USING_ARDUINO_MSGQ_C_CPP_DEMO is not set
# CONFIG_PKG_USING_ARDUINO_SKETCH_LOADER_DEMO is not set
# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
# CONFIG_PKG_USING_ARDUINO_RTDUINO_SENSORFUSION_SHIELD is not set
# CONFIG_PKG_USING_ARDUINO_NINEINONE_SENSOR_SHIELD is not set
# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
# CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
Expand Down Expand Up @@ -1297,6 +1324,7 @@ CONFIG_BSP_UART_IRQ_BASE=44
# CONFIG_BSP_USING_ADC is not set
# CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_WDT is not set
# CONFIG_BSP_USING_TIMER is not set
# CONFIG_BSP_USING_PWM is not set
# CONFIG_BSP_USING_RTC is not set
# CONFIG_BSP_USING_SDH is not set
Expand All @@ -1310,9 +1338,10 @@ CONFIG_BSP_GPIO_IRQ_BASE=60
CONFIG_BSP_SYS_GPIO_IRQ_BASE=70
CONFIG___STACKSIZE__=8192
CONFIG_SOC_TYPE_SG2002=y
# CONFIG_BOARD_TYPE_MILKV_DUO is not set
# CONFIG_BOARD_TYPE_MILKV_DUO_SD is not set
# CONFIG_BOARD_TYPE_MILKV_DUO_SPINOR is not set
CONFIG_BOARD_TYPE_MILKV_DUO256M=y
CONFIG_BOARD_TYPE_MILKV_DUO256M_SD=y
# CONFIG_BOARD_TYPE_MILKV_DUO256M_SPINOR is not set
# CONFIG_BOARD_TYPE_MILKV_DUOS_SD is not set
CONFIG_BSP_ROOTFS_TYPE_ROMFS=y
# CONFIG_BSP_ROOTFS_TYPE_CROMFS is not set
Loading

0 comments on commit 7df04a0

Please sign in to comment.