整體來說環境搭建還是比較簡單的,我用的是wsl的ubuntu 18.04,直接下載了duo-buildroot-sdk-20230616.zip這個基于buildroot的SDK,然后確保安裝了cmake、device-tree-compiler、ninja、mtools、genext2fs等工具,原則上就是報錯缺什么就裝什么。
通過命令unzip duo-buildroot-sdk-20230616.zip -d ~/work/milkv/duo
解壓duo-buildroot-sdk-20230616.zip到~/work/milkv/duo
文件夾里面。
然后通過運行build_milkv.sh進行編譯和構建鏡像,build_milv.sh腳本的內容如下:
#!/bin/bash
MILKV_BOARD_ARRAY=
MILKV_BOARD_ARRAY_LEN=
MILKV_BOARD=
MILKV_BOARD_CONFIG=
MILKV_BOARD_DIR=milkv
function print_info()
{
printf "e[1;32m%se[0mn" "$1"
}
function print_err()
{
printf "e[1;31mError: %se[0mn" "$1"
}
# 自動檢測并下載工具集
function get_toolchain()
{
if [ ! -d host-tools ]; then
print_info "Toolchain does not exist, download it now..."
toolchain_url="https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz"
echo "toolchain_url: ${toolchain_url}"
toolchain_file=${toolchain_url##*/}
echo "toolchain_file: ${toolchain_file}"
wget ${toolchain_url} -O ${toolchain_file}
if [ $? -ne 0 ]; then
print_err "Failed to download ${toolchain_url} !"
exit 1
fi
if [ ! -f ${toolchain_file} ]; then
print_err "${toolchain_file} not found!"
exit 1
fi
print_info "Extracting ${toolchain_file}..."
tar -xf ${toolchain_file}
if [ $? -ne 0 ]; then
print_err "Extract ${toolchain_file} failed!"
exit 1
fi
[ -f ${toolchain_file} ] && rm -rf ${toolchain_file}
fi
}
# 這里得到了支持的板子MILKV_BOARD_ARRAY=milkv-duo
function get_available_board()
{
MILKV_BOARD_ARRAY=( $(cd ${MILKV_BOARD_DIR}/; ls boardconfig*.sh | sort | awk -F"[-.]" -v OFS='-' '{print $2, $3}') )
#echo ${MILKV_BOARD_ARRAY[@]}
MILKV_BOARD_ARRAY_LEN=${#MILKV_BOARD_ARRAY[@]}
if [ $MILKV_BOARD_ARRAY_LEN -eq 0 ]; then
echo "No available board config"
exit 1
fi
#echo ${MILKV_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/n/. /"
}
function choose_milkv_board()
{
# TODO
echo "choose"
}
function prepare_env()
{
source ${MILKV_BOARD_CONFIG}
source build/${MV_BUILD_ENV} > /dev/null 2>&1
defconfig ${MV_BOARD_LINK} > /dev/null 2>&1
echo "OUTPUT_DIR: ${OUTPUT_DIR}" # @build/milkvsetup.sh
}
# 執行編譯
function milkv_duo_build()
{
# clean old img
old_image_count=`ls ${OUTPUT_DIR}/*.img* | wc -l`
if [ ${old_image_count} -ge 0 ]; then
pushd ${OUTPUT_DIR}
rm -rf *.img*
popd
fi
# 不需要重新編譯的時候可以把clean_all注釋掉,否則每次都會重新編譯
clean_all
build_all
if [ $? -eq 0 ]; then
print_info "Build board ${MILKV_BOARD} success!"
else
print_err "Build board ${MILKV_BOARD} failed!"
exit 1
fi
}
# 打包鏡像
function milkv_duo_pack()
{
pack_sd_image
[ ! -d out ] && mkdir out
image_count=`ls ${OUTPUT_DIR}/*.img | wc -l`
if [ ${image_count} -ge 0 ]; then
mv ${OUTPUT_DIR}/*.img out/
# rename milkv-duo.img file with time
pushd out
for img in *.img
do
if [ "${img}" == "${MILKV_BOARD}.img" ]; then
mv $img ${MILKV_BOARD}-`date +%Y%m%d-%H%M`.img
fi
done
popd
# show latest img
latest_img=`ls -t out/*.img | head -n1`
if [ -z "${latest_img// }" ]; then
print_err "Gen image failed!"
else
print_info "Gen image successful: ${latest_img}"
fi
else
print_err "Create sd img failed!"
exit 1
fi
}
get_toolchain
get_available_board
if [ $MILKV_BOARD_ARRAY_LEN -eq 1 ]; then
# Only one board
print_info "Ready to build: ${MILKV_BOARD_ARRAY[0]}"
MILKV_BOARD=${MILKV_BOARD_ARRAY[0]}
else
# no arg
if [ $# -lt 1 ]; then
choose_milkv_board || exit 0
fi
# with board name
if [ $# -ge 1 ]; then
if [[ ${MILKV_BOARD_ARRAY[@]} =~ (^|[[:space:]])"${1}"($|[[:space:]]) ]]; then
MILKV_BOARD=${1}
echo "$MILKV_BOARD"
else
print_err "${1} not supported!"
echo "Available boards: [ ${MILKV_BOARD_ARRAY[@]} ]"
exit 1
fi
fi
fi
if [ -z "${MILKV_BOARD// }" ]; then
print_err "No board specified!"
exit 1
fi
export MILKV_BOARD="${MILKV_BOARD}"
MILKV_BOARD_CONFIG=${MILKV_BOARD_DIR}/boardconfig-${MILKV_BOARD}.sh
if [ ! -f ${MILKV_BOARD_CONFIG} ]; then
print_err "${MILKV_BOARD_CONFIG} not found!"
exit 1
fi
prepare_env
milkv_duo_build
milkv_duo_pack
腳本加了一些簡單的注釋,大體邏輯就是
- 檢測并下載工具集;
- 選擇板子;
- 根據板子到處環境;
- 執行編譯;
- 構建鏡像;
最后腳本執行完成會輸出一個構建img成功的信息,如下圖綠色的內容,時間戳會根據構建時間而不一樣。
內核開發環境可以用了,可以學習內核代碼了,可以通過Windows下的vscode進行編輯然后在vscode終端里面進行編譯。
如果編譯過程遇到類似'Your PATH contains spaces, TABs, and/or newline (n) characters.'的錯誤,是因為WSL默認會自動添加Windows環境變量到wsl中,可以通過關閉自動添加,或是重新設置PATH來解決。我是選擇重新設置環境變量,即將帶空格的windows環境變量刪除,因為我需要使用windows下的vscode,如果關閉自動添加,就用不了windows下的軟件了。
-
硬件設計
+關注
關注
18文章
399瀏覽量
44627 -
開發板
+關注
關注
25文章
5110瀏覽量
97895 -
編譯
+關注
關注
0文章
661瀏覽量
32951 -
SDK
+關注
關注
3文章
1044瀏覽量
46113 -
環境搭建
+關注
關注
0文章
54瀏覽量
9068 -
Milk-V Duo
+關注
關注
2文章
28瀏覽量
214
發布評論請先 登錄
相關推薦
評論