#!/bin/bash
set -e #用于指此脚本里执行的命令返回值非0时,终止当前脚本的执行.
/*
➜ a40i_linux ls -l tools/build/mkcommon.sh
-rwxrwxr-x 1 jalyn jalyn 4977 1月 17 14:13 tools/build/mkcommon.sh
*/
if [ -x "tools/build/mkcommon.sh" ]; then
tools/build/mkcommon.sh $@
else
buildroot/scripts/mkcommon.sh $@
fi
执行:tools/build/mkcommon.sh
#!/bin/bash
export LC_ALL=C
#$0表示第0个参数,即是"tools/build/mkcommon.sh"
#dirname命令用于获取路径, `dirname $0`获取得到"tools/build"
BR_SCRIPTS_DIR=`dirname $0`
BUILD_CONFIG=.buildconfig
SKIP_BR=0
...
if [ -z "`echo ${LICHEE_CHIP} | grep "sun5[0-9]i"`" \
-a "x$1" != "xconfig" ]; then \
cd ${LICHEE_TOP_DIR}
buildroot/scripts/mkcommon.sh $@
exit $?
else
SKIP_BR=1;
fi
...
然后执行了:buildroot/scripts/mkcommon.sh $@
$@:lichee所在路径。
buildroot/scripts/mkcommon.sh:
BR_SCRIPTS_DIR=`dirname $0` #$0表示第0个参数,即是"buildroot/scripts/mkcommon.sh"
#dirname命令用于获取路径, `dirname $0`获取得到"buildroot/scripts"
# source shflags
. ${BR_SCRIPTS_DIR}/shflags/shflags
[ -f .buildconfig ] && . .buildconfig #如有.buildconfig文件,则导出里面的变量. 此文件是由"./build.sh config"生成的.
. ${BR_SCRIPTS_DIR}/mkcmd.sh #导出脚本里的下面function命令,以便在当前脚本里可以调用访问.
/*
mkboot build boot
mkbr build buildroot
mkkernel build kernel
mkrootfs build rootfs for linux, dragonboard
mklichee build total lichee
mkclean clean current board output
mkdistclean clean entires output
mkpack pack firmware for lichee
mkhelp show this message
*/
[ -f .buildconfig ] && . .buildconfig #如有.buildconfig文件,则导出下面的环境变量. 此文件用于指定编译的目标平台
if [ "x$1" = "xconfig" ] ; then #执行"./build.sh config"时触发
. ${BR_SCRIPTS_DIR}/mksetup.sh #出现选择界面
exit $?
elif [ "x$1" = "xpack" ] ; then #执行"./build.sh pack"时触发
init_defconf #init_defconf命令是由buildroot/scripts/mkcmd.sh里提供的
mkpack #mkpack命令是由buildroot/scripts/mkcmd.sh里提供的
exit $?
elif [ "x$1" = "xpack_debug" ] ; then #执行"./build.sh pack_debug"时触发
init_defconf
mkpack -d card0
exit $?
elif [ "x$1" = "xpack_dump" ] ; then #执行"./build.sh pack_dump"时触发
init_defconf
mkpack -m dump
exit $?
elif [ "x$1" = "xpack_secure" ] ; then #执行"./build.sh pack_secure"时触发
init_defconf
mkpack -s secure
exit $?
......
......
elif [ $# -eq 0 ] ; then #执行"./build.sh"没任何参数时触发
init_defconf #命令是由buildroot/scripts/mkcmd.sh里提供的
mklichee #命令是由buildroot/scripts/mkcmd.sh里提供的
exit $?
fi
以build.sh重点分析,mklichee:
function mklichee()
{
mk_info "----------------------------------------"
mk_info "build lichee ..."
mk_info "chip: $LICHEE_CHIP"
mk_info "platform: $LICHEE_PLATFORM"
mk_info "kernel: $LICHEE_KERN_VER"
mk_info "board: $LICHEE_BOARD"
mk_info "output: out/${LICHEE_CHIP}/${LICHEE_PLATFORM}/${LICHEE_BOARD}"
mk_info "----------------------------------------"
check_env
mkbr && mkkernel && mkrootfs #编译Buildroot 、kernel、rootfs
[ $? -ne 0 ] && return 1
mk_info "----------------------------------------"
mk_info "build lichee OK."
mk_info "----------------------------------------"
}
-
mkbr 编译buildroot
#PATH: buildroot/scripts/mkcmd.sh
function mkbr()
{
mk_info "build buildroot ..."
local build_script="scripts/build.sh"
(cd ${LICHEE_BR_DIR} && [ -x ${build_script} ] && ./${build_script})
[ $? -ne 0 ] && mk_error "build buildroot Failed" && return 1
mk_info "build buildroot OK."
}
buildroot/scripts/build.sh -> mkbr
a) build_buildroot:
build_buildroot()
{
if [ ! -f ${LICHEE_BR_OUT}/.config ] ; then
printf "\nUsing default config ...\n\n"
make O=${LICHEE_BR_OUT} -C ${LICHEE_BR_DIR} ${LICHEE_BR_DEFCONF}
fi
make O=${LICHEE_BR_OUT} -C ${LICHEE_BR_DIR} LICHEE_GEN_ROOTFS=n \
BR2_JLEVEL=${LICHEE_JLEVEL}
}
网友评论