继上篇博客,详细的分析顶层目录下的mkconfig文件
APPEND=no # Default: Create new config file
BOARD_NAME="" # Name to print in make output
TARGETS=""
arch=""
cpu=""
board=""
vendor=""
soc=""
options=""
以上这些是定义一些变量,并初始化
if [ $# -eq 2-a "$1"="−A" ] ; then
# Automatic mode
line=`egrep -i"^[[:space:]]*${2}[[:space:]]" boards.cfg` || {
echo "make: *** No ruleto make target \`$2_config'. Stop.">&2
exit 1
}
$#表示参数个数,-eq相当于c语言的==,-a相当于c语言的&&,$1表示第一个参数内容,所以if语句的意思就是如果传进来的参数个数为2个,并且第一个参数为“-A”,就执行then部分,then部分为在boards.cfg文件里面寻找第二个参数($2),如果找到了,就继续往下执行,如果没有找到,就打印make: *** No ruleto make target \`$2_config',并且退出。
while [ $# -gt 0 ]; do
case "$1" in
--) shift ; break ;;
-a) shift ; APPEND=yes ;;
-n) shift ;BOARD_NAME="${1%_config}" ; shift ;;
-t) shift ; TARGETS="`echo $1 |sed 's:_: :g'` ${TARGETS}" ; shift ;;
*) break ;;
esac
done
while语句里面的-gt相当于c里面的“>”,就是当参数个数大于0(此处的参数是指从board.cfg里面读出来的),如果第一个参数为case in语句列表里面的,就执行相应的操作。
[ $# -lt 4 ]&& exit 1
[ $# -gt 7 ]&& exit 1
当参数个数小于4或大于7个就退出(-lt相当于c语言的“<”)
CONFIG_NAME="${1%_config}"
${1%_config}是配置命令makexxx_config里面的xxx,用make smdk4412_config举例,CONFIG_NAME=smdk4412
["${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
#BOARD_NAME =smdk4412
arch="$2"
cpu="$3"
让第二个参数赋给变量arch,第三个参数赋给变量cpu,用下面的内容举例
smdk4412 arm armv7 smdk4212 samsung exynos
$1 $2 $3 $4 $5 $6
可知arch=arm cpu=armv7
if [ "$4" = "-" ] ; then
board=${BOARD_NAME}
else
board="$4"
fi
如果第四个参数为“-”,board=${BOARD_NAME},否则,board就是第四个参数,按照上面的例子,可知,board=smdk4212
[ $# -gt 4 ] && [ "$5" !="-" ] && vendor="$5"
[ $# -gt 5 ] && [ "$6" !="-" ] && soc="$6"
[ $# -gt 6 ] && [ "$7" !="-" ] && {
tmp="${7%:*}"
if ["$tmp" ] ; then
CONFIG_NAME="$tmp"
fi
if ["${tmp}" != "$7" ] ; then
options=${7#*:}
TARGETS="`echo${options} | sed 's:,: :g'` ${TARGETS}"
fi
}
如果参数个数大于5并且第五个参数和第六个参数都不是“-”就让vendor变量为第五个参数,soc变量为第六个变量,根据上面的例子,可知vendor=samsung soc=exynos,如果参数个数大于六个并且第七个参数不为“-”,就执行下面大括号里面的内容,因例子不符合这部分,故不予以分析。
if [ "${ARCH}" -a "${ARCH}" !="${arch}" ]; then
echo"Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}"1>&2
exit 1
fi
如果ARCH变量不为空,并且ARCH内容不等于arch内容,就输出failed内容,显然ARCH没有被赋值过,所以if条件不成立
if [ "$options" ] ; then
echo"Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options:${options}"
else
echo "Configuringfor ${BOARD_NAME} board..."
fi
到此时为止,option为空,所以这里输出“Configuring for smdk4412 board…”,表示配置成功
if [ "$SRCTREE" != "$OBJTREE" ] ;then
mkdir -p${OBJTREE}/include
mkdir -p${OBJTREE}/include2
cd${OBJTREE}/include2
rm -f asm
ln -s${SRCTREE}/arch/${arch}/include/asm asm
LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/
cd ../include
rm -f asm
ln -s${SRCTREE}/arch/${arch}/include/asm asm
else
cd ./include
rm -f asm
ln -s../arch/${arch}/include/asm asm
fi
因为这里SRCTREE和OBJTREE变量都为空,所以执行else部分,即进入inlcude目录下,删除该目录下现有的asm目录,建立新的asm目录,并创建了一个软连接,让asm指向/arch/arm/inlcue/asm目录(因为$(arch)=arm)
rm -f asm/arch
if [ -z "${soc}" ] ; then
ln -s${LNPREFIX}arch-${cpu} asm/arch
else
ln -s${LNPREFIX}arch-${soc} asm/arch
fi
删除asm/arch目录,并判断soc是否为空(此处不为空soc=exynos),并新建asm/arch目录,让他指向arch-exynos目录
if [ "${arch}" = "arm" ] ; then
rm -f asm/proc
ln -s${LNPREFIX}proc-armv asm/proc
fi
删除现有的asm/proc目录,并新建asm/proc目录,指向proc-armv目录
echo "ARCH = ${arch}" > config.mk
echo "CPU = ${cpu}" >>config.mk
echo "BOARD = ${board}" >> config.mk
[ "${vendor}" ] && echo "VENDOR= ${vendor}" >> config.mk
[ "${soc}" ] && echo "SOC =${soc}" >> config.mk
新建一个config.mk文件,并在里面添加如下内容
ARCH = arm
CPU = armv7
BOARD= smdk4212
VENDOR = Samsung
SOC = exynos
XXX > config.mk表示新建一个config.mk文件,并将xxx添加到该文件中,xxx>> config.mk表示将xxx追加到config.mk文件中
if [ -z "${vendor}" ] ; then
BOARDDIR=${board}
else
BOARDDIR=${vendor}/${board}
Fi
因为vendor变量不为空,所以执行else部分,及BOARDDIR=Samsung/smdk4212
if [ "$APPEND" = "yes" ] # Append to existing config file
then
echo >>config.h
else
> config.h # Create new config file
Fi
因为APPEND=no,所以执行else部分语句,新建一个config.h文件
echo "echo "/* Automatically generated - donot edit */" >>config.h
for i in ${TARGETS} ; do
i="`echo${i} | sed '/=/ {s/=/\t/;q } ; { s/$/\t1/ }'`"
echo"#define CONFIG_${i}" >>config.h ;
done
在config.h里添加/* Automatically generated - do not edit*/,因为TARGETS为空,所以for循环不会被执行
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_defaults.h>
#include <configs/${CONFIG_NAME}.h>
#include <asm/config.h>
EOF
cat << EOF>> config.h 表示将如下内容追加到config.h中,直到出现EOF为止,
即config.h里面的内容再增加:
#include <config_defaults.h>
#include<configs/smdk4412.h>
#include<asm/config.h>
exit 0
退出结束
总结:配置过程总共做了三件事
1、在include目录下创建config.mk文件,里面的内容为
ARCH = arm
CPU = armv7
BOARD= smdk4212
VENDOR = Samsung
SOC =exynos
2、创建三个软连接
Include/asm->arch/arm/include/asm
Include/asm/arch->include/arch-exynos
Include/asm/proc->include/proc-armv
3、新建config.h文件,里面内容如下:
/*Automatically generated - do not edit */
#include<config_defaults.h>
#include <configs/smdk4412.h>
#include <asm/config.h>