本文主要是介绍集成构建流程之根文件系统Buidroot,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
编译流程
单板信息
#---- device/milkv-duos-sd/boardconfig.sh
export MV_BOARD=milkv-duos-sd
export MV_BOARD_CPU=cv1813h
export MV_VENDOR=milkv
export MV_BUILD_ENV=milkvsetup.sh
export MV_BOARD_LINK=cv1813h_milkv_duos_sd
通用编译脚本:build.sh
#---- build.sh
...
get_available_board # 查看device目录下支持的单板MILKV_BOARD_ARRAY=( $(find device ... # 收集所有单板到数组MILKV_BOARD_ARRAY中...if [ $# -ge 1 ]; thenif [ "$1" = "lunch" ]; then # 脚本参数为lunch时,执行lunch动作choose_board || exit 0 ...read -p "Which would you like: " index # 手动选择目标单板if [[ -n $index && $index =~ ^[0-9]+$ && $index -ge 1 && $index -le $MILKV_BOARD_ARRAY_LEN ]]; thenMILKV_BOARD="${MILKV_BOARD_ARRAY[$((index - 1))]}" # 确认目标单板elseif [[ ${MILKV_BOARD_ARRAY[@]} =~ (^|[[:space:]])"${1}"($|[[:space:]]) ]]; then # 检索数据MILKV_BOARD_ARRAY,查找匹配的单板MILKV_BOARD=${1} # 确认目标单板
... # 其他参数检查MILKV_BOARD_CONFIG=device/${MILKV_BOARD}/boardconfig.sh # 单板配置文件get_toolchainif [ ! -d host-tools ]; then # 如果不存在host-tools目录,下载相关工具链toolchain_url="https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz"wget ${toolchain_url} -O ${toolchain_file}export MILKV_BOARD="${MILKV_BOARD}"prepare_envsource ${MILKV_BOARD_CONFIG} # 加载单板配置脚本,Duo S为:device/milkv-duos-sd/boardconfig.shsource build/${MV_BUILD_ENV} > /dev/null 2>&1 # 加载环境变量配置脚本: build/milkvsetup.shdefconfig ${MV_BOARD_LINK} > /dev/null 2>&1 # 加载单板配置文件,Duo S为:build/boards/cv181x/cv1813h_milkv_duos_sd/cv1813h_milkv_duos_sd_defconfig# 含Buildroot相关信息,文件:build/common_functions.sh
build_info
milkv_build # 编译过程clean_allbuild_all # 完整编译
milkv_pack
通用shell函数定义脚本
#---- build/common_functions.sh
function defconfig() # defconfig依据单板配置文件推导出.config文件board=$1chip_arch=`"${BUILD_PATH}/scripts/boards_scan.py" --get-chip-arch --board_name ${board}`# if input is chip series, then list boards by chip seriesif [ "${chip_arch}" != "" ]; then_call_kconfig_script "${FUNCNAME[0]}" "${BUILD_PATH}/boards/${chip_arch}/${board}/${board}_defconfig"script=$1shift cd $BUILD_PATH || return${BUILD_PATH}/scripts/${script}.py $@ # 生成.config文件,对Duo S为:build/scripts/defconfig.py build/.../cv1813h_milkv_duos_sd_defconfig cvi_setup_env || return $? # Buildroot配置,文件:build/milkvsetup.shfunction pack_rootfs # 打包根文件系统,含根文件系统Buildroot的编译...cd "$BUILD_PATH" || returnmake rootfs # 执行make操作,编译Buildroot,查看文件:build/Makefile
通用环境变量配置脚本
#---- build/milkvsetup.sh
function cvi_setup_env() # 环境变量设置,截取Buidroot相关...# buildroot configexport BR_DIR="$TOP_DIR"/buildroot-2021.05export BR_BOARD=${MV_BOARD}_${SDK_VER}export BR_OVERLAY_DIR=${BR_DIR}/board/${MV_VENDOR}/${MV_BOARD}/overlayexport BR_DEFCONFIG=${BR_BOARD}_defconfig # Buildroot配置文件export BR_ROOTFS_DIR="$OUTPUT_DIR"/tmp-rootfsexport BR_MV_VENDOR_DIR=${BR_DIR}/board/${MV_VENDOR} function build_all() # 完整编译build_uboot || return $?build_kernel || return $?build_osdrv || return $?build_middleware || return $?pack_access_guard_turnkey_app || return $?pack_ipc_turnkey_app || return $?pack_boot || return $?pack_cfg || return $?pack_rootfs || return $? # 打包根文件系统pack_datapack_system || return $?copy_toolspack_upgrade
执行make,Makefile文件为:build/Makefile
#---- build/Makefile
...
br-rootfs-pack: export TARGET_OUTPUT_DIR=$(BR_DIR)/output/$(BR_BOARD)
br-rootfs-pack:$(call print_target)${Q}$(MAKE) -C $(BR_DIR) $(BR_DEFCONFIG) BR2_TOOLCHAIN_EXTERNAL_PATH=$(CROSS_COMPILE_PATH) // 配置文件,Duo S为:milkv-duos-sd_musl_riscv64_defconfig${Q}$(BR_DIR)/utils/brmake -j${NPROC} -C $(BR_DIR) // brmake工具执行编译...
这篇关于集成构建流程之根文件系统Buidroot的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!