Commit a0ad45b7 authored by carbon's avatar carbon

build.sh supports choosing boards

parent 38312619
...@@ -4,9 +4,12 @@ MILKV_BOARD_ARRAY= ...@@ -4,9 +4,12 @@ MILKV_BOARD_ARRAY=
MILKV_BOARD_ARRAY_LEN= MILKV_BOARD_ARRAY_LEN=
MILKV_BOARD= MILKV_BOARD=
MILKV_BOARD_CONFIG= MILKV_BOARD_CONFIG=
MILKV_IMAGE_CONFIG=
MILKV_DEFAULT_BOARD=milkv-duo
MILKV_BOARD_DIR=milkv TOP_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
#echo "TOP_DIR: ${TOP_DIR}"
cd ${TOP_DIR}
function print_info() function print_info()
{ {
...@@ -53,22 +56,39 @@ function get_toolchain() ...@@ -53,22 +56,39 @@ function get_toolchain()
function get_available_board() function get_available_board()
{ {
MILKV_BOARD_ARRAY=( $(cd ${MILKV_BOARD_DIR}/; ls boardconfig*.sh | sort | awk -F"[-.]" -v OFS='-' '{print $2, $3}') ) MILKV_BOARD_ARRAY=( $(find device -mindepth 1 -maxdepth 1 -type d -print ! -name "." | awk -F/ '{ print $NF }' | sort) )
#echo ${MILKV_BOARD_ARRAY[@]} #echo ${MILKV_BOARD_ARRAY[@]}
MILKV_BOARD_ARRAY_LEN=${#MILKV_BOARD_ARRAY[@]} MILKV_BOARD_ARRAY_LEN=${#MILKV_BOARD_ARRAY[@]}
if [ $MILKV_BOARD_ARRAY_LEN -eq 0 ]; then if [ $MILKV_BOARD_ARRAY_LEN -eq 0 ]; then
echo "No available board config" echo "No available config"
exit 1 exit 1
fi fi
#echo ${MILKV_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/\n/. /" #echo ${MILKV_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/\n/. /"
} }
function choose_milkv_board() function choose_board()
{ {
# TODO echo "Select a target to build:"
echo "choose"
echo ${MILKV_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/\n/. /"
local index
read -p "Which would you like: " index
if [[ -z $index ]]; then
echo "Nothing selected."
exit 0
fi
if [[ -n $index && $index =~ ^[0-9]+$ && $index -ge 1 && $index -le $MILKV_BOARD_ARRAY_LEN ]]; then
MILKV_BOARD="${MILKV_BOARD_ARRAY[$((index - 1))]}"
#echo "index: $index, Board: $MILKV_BOARD"
else
print_err "Invalid input!"
exit 1
fi
} }
function prepare_env() function prepare_env()
...@@ -81,7 +101,7 @@ function prepare_env() ...@@ -81,7 +101,7 @@ function prepare_env()
echo "OUTPUT_DIR: ${OUTPUT_DIR}" # @build/milkvsetup.sh echo "OUTPUT_DIR: ${OUTPUT_DIR}" # @build/milkvsetup.sh
} }
function milkv_duo_build() function milkv_build()
{ {
# clean old img # clean old img
old_image_count=`ls ${OUTPUT_DIR}/*.img* | wc -l` old_image_count=`ls ${OUTPUT_DIR}/*.img* | wc -l`
...@@ -101,7 +121,7 @@ function milkv_duo_build() ...@@ -101,7 +121,7 @@ function milkv_duo_build()
fi fi
} }
function milkv_duo_pack() function milkv_pack()
{ {
pack_sd_image pack_sd_image
...@@ -134,31 +154,42 @@ function milkv_duo_pack() ...@@ -134,31 +154,42 @@ function milkv_duo_pack()
fi fi
} }
get_toolchain function build_info()
{
print_info "Target Board: ${MILKV_BOARD}"
print_info "Target Board Config: ${MILKV_BOARD_CONFIG}"
print_info "Target Image Config: ${MILKV_IMAGE_CONFIG}"
}
get_available_board get_available_board
if [ $MILKV_BOARD_ARRAY_LEN -eq 1 ]; then function build_usage()
# Only one board {
print_info "Ready to build: ${MILKV_BOARD_ARRAY[0]}" echo "Usage:"
MILKV_BOARD=${MILKV_BOARD_ARRAY[0]} echo "${BASH_SOURCE[0]} - Show this menu"
else echo "${BASH_SOURCE[0]} lunch - Select a board to build"
# no arg echo "${BASH_SOURCE[0]} [board] - Build [board] directly, supported boards as follows:"
if [ $# -lt 1 ]; then
choose_milkv_board || exit 0
fi
# with board name for board in "${MILKV_BOARD_ARRAY[@]}"; do
if [ $# -ge 1 ]; then print_info "$board"
done
}
if [ $# -ge 1 ]; then
if [ "$1" = "lunch" ]; then
choose_board || exit 0
else
if [[ ${MILKV_BOARD_ARRAY[@]} =~ (^|[[:space:]])"${1}"($|[[:space:]]) ]]; then if [[ ${MILKV_BOARD_ARRAY[@]} =~ (^|[[:space:]])"${1}"($|[[:space:]]) ]]; then
MILKV_BOARD=${1} MILKV_BOARD=${1}
echo "$MILKV_BOARD" #echo "$MILKV_BOARD"
else else
print_err "${1} not supported!" print_err "${1} not supported!"
echo "Available boards: [ ${MILKV_BOARD_ARRAY[@]} ]" echo "Available boards: [ ${MILKV_BOARD_ARRAY[@]} ]"
exit 1 exit 1
fi fi
fi fi
else
build_usage && exit 0
fi fi
if [ -z "${MILKV_BOARD// }" ]; then if [ -z "${MILKV_BOARD// }" ]; then
...@@ -166,17 +197,26 @@ if [ -z "${MILKV_BOARD// }" ]; then ...@@ -166,17 +197,26 @@ if [ -z "${MILKV_BOARD// }" ]; then
exit 1 exit 1
fi fi
export MILKV_BOARD="${MILKV_BOARD}" MILKV_BOARD_CONFIG=device/${MILKV_BOARD}/boardconfig.sh
MILKV_IMAGE_CONFIG=device/${MILKV_BOARD}/genimage.cfg
MILKV_BOARD_CONFIG=${MILKV_BOARD_DIR}/boardconfig-${MILKV_BOARD}.sh
if [ ! -f ${MILKV_BOARD_CONFIG} ]; then if [ ! -f ${MILKV_BOARD_CONFIG} ]; then
print_err "${MILKV_BOARD_CONFIG} not found!" print_err "${MILKV_BOARD_CONFIG} not found!"
exit 1 exit 1
fi fi
prepare_env if [ ! -f ${MILKV_IMAGE_CONFIG} ]; then
print_err "${MILKV_IMAGE_CONFIG} not found!"
exit 1
fi
get_toolchain
build_info
milkv_duo_build export MILKV_BOARD="${MILKV_BOARD}"
milkv_duo_pack
prepare_env
milkv_build
milkv_pack
...@@ -577,7 +577,7 @@ endif ...@@ -577,7 +577,7 @@ endif
# copy milkv overlay files # copy milkv overlay files
ifeq ($(MV_VENDOR), milkv) ifeq ($(MV_VENDOR), milkv)
${Q}cp -arf $(TOP_DIR)/$(MV_VENDOR)/overlay/* $(BR_ROOTFS_DIR)/ ${Q}cp -arf $(TOP_DIR)/device/$(MV_BOARD)/overlay/* $(BR_ROOTFS_DIR)/
endif endif
# strip # strip
${Q}find $(BR_ROOTFS_DIR) -name "*.ko" -type f -printf 'striping %p\n' -exec $(CROSS_COMPILE_KERNEL)strip --strip-unneeded {} \; ${Q}find $(BR_ROOTFS_DIR) -name "*.ko" -type f -printf 'striping %p\n' -exec $(CROSS_COMPILE_KERNEL)strip --strip-unneeded {} \;
...@@ -621,7 +621,7 @@ else ...@@ -621,7 +621,7 @@ else
${Q}ln -s $(OUTPUT_DIR)/rootfs $(OUTPUT_DIR)/fs ${Q}ln -s $(OUTPUT_DIR)/rootfs $(OUTPUT_DIR)/fs
endif endif
ifeq ($(MV_VENDOR), milkv) ifeq ($(MV_VENDOR), milkv)
$(TOP_DIR)/$(MV_VENDOR)/gen_burn_image_sd.sh $(OUTPUT_DIR) $(TOP_DIR)/device/gen_burn_image_sd.sh $(OUTPUT_DIR)
else else
$(COMMON_TOOLS_PATH)/sd_tools/sd_gen_burn_image.sh $(OUTPUT_DIR) $(COMMON_TOOLS_PATH)/sd_tools/sd_gen_burn_image.sh $(OUTPUT_DIR)
endif endif
......
...@@ -550,9 +550,13 @@ function cvi_setup_env() ...@@ -550,9 +550,13 @@ function cvi_setup_env()
export SYSTEM_OUT_DIR export SYSTEM_OUT_DIR
export CROSS_COMPILE_PATH export CROSS_COMPILE_PATH
# buildroot config # buildroot config
if [ -z "${MV_BOARD// }" ]; then
print_error "No MV_BOARD specified!"
return 1
fi
export BR_DIR="$TOP_DIR"/buildroot-2021.05 export BR_DIR="$TOP_DIR"/buildroot-2021.05
export BR_BOARD=milkv_duo_${SDK_VER} export BR_BOARD=${MV_BOARD}_${SDK_VER}
export BR_OVERLAY_DIR=${BR_DIR}/board/milkv/duo/overlay export BR_OVERLAY_DIR=${BR_DIR}/board/${MV_VENDOR}/${MV_BOARD}/overlay
export BR_DEFCONFIG=${BR_BOARD}_defconfig export BR_DEFCONFIG=${BR_BOARD}_defconfig
export BR_ROOTFS_DIR="$OUTPUT_DIR"/tmp-rootfs export BR_ROOTFS_DIR="$OUTPUT_DIR"/tmp-rootfs
} }
......
...@@ -59,7 +59,7 @@ BR2_BZCAT="bzcat" ...@@ -59,7 +59,7 @@ BR2_BZCAT="bzcat"
BR2_XZCAT="xzcat" BR2_XZCAT="xzcat"
BR2_LZCAT="lzip -d -c" BR2_LZCAT="lzip -d -c"
BR2_TAR_OPTIONS="" BR2_TAR_OPTIONS=""
BR2_DEFCONFIG="./configs/milkv_duo_musl_riscv64_defconfig" BR2_DEFCONFIG="./configs/milkv-duo_musl_riscv64_defconfig"
BR2_DL_DIR="$(TOPDIR)/dl" BR2_DL_DIR="$(TOPDIR)/dl"
BR2_HOST_DIR="$(BASE_DIR)/host" BR2_HOST_DIR="$(BASE_DIR)/host"
...@@ -203,7 +203,7 @@ BR2_TOOLCHAIN_HAS_ATOMIC=y ...@@ -203,7 +203,7 @@ BR2_TOOLCHAIN_HAS_ATOMIC=y
BR2_ROOTFS_SKELETON_DEFAULT=y BR2_ROOTFS_SKELETON_DEFAULT=y
# BR2_ROOTFS_SKELETON_CUSTOM is not set # BR2_ROOTFS_SKELETON_CUSTOM is not set
BR2_TARGET_GENERIC_HOSTNAME="milkv-duo" BR2_TARGET_GENERIC_HOSTNAME="milkv-duo"
BR2_TARGET_GENERIC_ISSUE="Welcome to Milk-V" BR2_TARGET_GENERIC_ISSUE="Welcome to Milk-V Duo"
BR2_TARGET_GENERIC_PASSWD_SHA256=y BR2_TARGET_GENERIC_PASSWD_SHA256=y
# BR2_TARGET_GENERIC_PASSWD_SHA512 is not set # BR2_TARGET_GENERIC_PASSWD_SHA512 is not set
BR2_TARGET_GENERIC_PASSWD_METHOD="sha-256" BR2_TARGET_GENERIC_PASSWD_METHOD="sha-256"
...@@ -249,7 +249,7 @@ BR2_ENABLE_LOCALE_WHITELIST="C en_US" ...@@ -249,7 +249,7 @@ BR2_ENABLE_LOCALE_WHITELIST="C en_US"
# BR2_SYSTEM_ENABLE_NLS is not set # BR2_SYSTEM_ENABLE_NLS is not set
# BR2_TARGET_TZ_INFO is not set # BR2_TARGET_TZ_INFO is not set
BR2_ROOTFS_USERS_TABLES="" BR2_ROOTFS_USERS_TABLES=""
BR2_ROOTFS_OVERLAY="board/milkv/duo/overlay" BR2_ROOTFS_OVERLAY="board/milkv/milkv-duo/overlay"
BR2_ROOTFS_POST_BUILD_SCRIPT="" BR2_ROOTFS_POST_BUILD_SCRIPT=""
BR2_ROOTFS_POST_FAKEROOT_SCRIPT="" BR2_ROOTFS_POST_FAKEROOT_SCRIPT=""
BR2_ROOTFS_POST_IMAGE_SCRIPT="" BR2_ROOTFS_POST_IMAGE_SCRIPT=""
......
...@@ -34,11 +34,11 @@ pushd ${output_dir} ...@@ -34,11 +34,11 @@ pushd ${output_dir}
[ -d tmp ] && rm -rf tmp [ -d tmp ] && rm -rf tmp
genimage --config ${TOP_DIR}/milkv/genimage-${MILKV_BOARD}.cfg --rootpath fs/ --inputpath ${PWD} --outputpath ${PWD} genimage --config ${TOP_DIR}/device/${MV_BOARD}/genimage.cfg --rootpath fs/ --inputpath ${PWD} --outputpath ${PWD}
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "gnimage for ${MILKV_BOARD} success!" echo "gnimage for ${MV_BOARD} success!"
else else
echo "gnimage for ${MILKV_BOARD} failed!" echo "gnimage for ${MV_BOARD} failed!"
fi fi
popd popd
#!/bin/bash #!/bin/bash
export MV_BOARD=milkv-duo
export MV_BOARD_CPU=cv1800b export MV_BOARD_CPU=cv1800b
export MV_VENDOR=milkv export MV_VENDOR=milkv
export MV_BUILD_ENV=milkvsetup.sh export MV_BUILD_ENV=milkvsetup.sh
......
#!/bin/sh
LED_PIN=440
LED_GPIO=/sys/class/gpio/gpio${LED_PIN}
if test -d ${LED_GPIO}; then
echo "PIN ${LED_PIN} already exported"
else
echo ${LED_PIN} > /sys/class/gpio/export
fi
echo out > ${LED_GPIO}/direction
while true; do
echo 0 > ${LED_GPIO}/value
sleep 0.5
echo 1 > ${LED_GPIO}/value
sleep 0.5
done
#!/bin/sh
LED_GPIO=/sys/class/gpio/gpio440
if test -d $LED_GPIO; then
echo "GPIO440 already exported"
else
echo 440 > /sys/class/gpio/export
fi
echo out > $LED_GPIO/direction
while true; do
echo 0 > $LED_GPIO/value
sleep 0.5
echo 1 > $LED_GPIO/value
sleep 0.5
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment