u-boot2011.09之mkconfig之简析

#!/bin/sh -e

# Script to create header files and links to configure

# U-Boot for a specific board.

#

# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]

#

# (C) 2002-2010 DENX Software Engineering, Wolfgang Denk <wd@denx.de>

#

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 rule to make target \`$2_config'.  Stop." >&2

exit 1

}

set ${line}

# add default board name if needed

[ $# = 3 ] && set ${line} ${1}

elif [ "${MAKEFLAGS+set}${MAKELEVEL+set}" = "setset" ] ; then

# only warn when using a config target in the Makefile

cat <<-EOF

warning: Please migrate to boards.cfg.  Failure to do so will

         mean removal of your board in the next release.

EOF

sleep 5

fi

********************************我是分割线*************************************

在顶层Makefile中有,

%_config:: unconfig

@$(MKCONFIG) -A $(@:_config=)

我们配置u-boot板级信息时需要用 make smdkc100_config,这里用@代替smdkc100,然后把_config置为空,实际上就是执行了 mkconfig -A smdkc100,给mkconfig传递了两个参数:-Asmdk100

参数传递进mkconfig后,先进行判断,if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; 参数个数是否等于2及第一个参数是否为-A,这里完全满足。然后根据第二个参数,也就是smdkc100查找顶层目录的boards.cfg,如果没有对应的板级信息,会打印出错误。

这里line是根据smdkc100遍历boards.cfg得到"smdkc100 arm armv7 smdkc100 samsung s5pc1xx",我们可以用echo $line便一目了然。

*******************************************************************************

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

********************************我是分割线*************************************

这里判断参数个数是否大于零,我们这里参数明显多于零,所以继续执行。由于我们的$1"-A",所以直接退出,继续下面执行。

*******************************************************************************

[ $# -lt 4 ] && exit 1

[ $# -gt 7 ] && exit 1

********************************我是分割线*************************************

我们得到六个参数:"smdkc100 arm armv7 smdkc100 samsung s5pc1xx",所以不会退出

*******************************************************************************

# Strip all options and/or _config suffixes

CONFIG_NAME="${1%_config}"

[ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"

arch="$2"

cpu="$3"

if [ "$4" = "-" ] ; then

board=${BOARD_NAME}

else

board="$4"

echo $BOARD_NAME

fi

********************************我是分割线*************************************

这里得到CONFIG_NAMEsmdkc100

BOARD_NAMEsmdkc100

arch="$2"arm

cpu="$3"armv7

board="$4"smdkc100 

*******************************************************************************

[ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"

[ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6"

[ $# -gt 6 ] && [ "$7" != "-" ] && {

# check if we have a board config name in the options field

# the options field mave have a board config name and a list

# of options, both separated by a colon (':'); the options are

# separated by commas (',').

#

# Check for board name

tmp="${7%:*}"

if [ "$tmp" ] ; then

CONFIG_NAME="$tmp"

fi

# Check if we only have a colon...

if [ "${tmp}" != "$7" ] ; then

options=${7#*:}

TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"

fi

}

********************************我是分割线*************************************

vendor="$5"samsung 

soc="$6"s5pc1xx

我们这里没有$7,这里的$7主要是来做开发板配置信息检查的,这里我们暂时不用关心。

*******************************************************************************

if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then

echo "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2

exit 1

Fi

********************************我是分割线*************************************

这里ARCH不为空并且ARCHarch值都是arm,所以下面不这句话不打印,继续执行

*******************************************************************************

if [ "$options" ] ; then

echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"

else

echo "Configuring for ${BOARD_NAME} board..."

fi

********************************我是分割线*************************************

虽然我们这里没有取出options的值,但是options的值不为空,所以会打印信息:

Configuring for smdkc100 board...

*******************************************************************************

#

# Create link to architecture specific headers

#

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

mkdir -p asm

else

cd ./include

rm -f asm

ln -s ../arch/${arch}/include/asm asm

fi

********************************我是分割线*************************************

判断是否在源代码目录下编译Uboot,不是就执行下面,else就是表示是在源代码目录编译,并根据arch的值建立软链接asm,链接到arch/arm/include/asm

*******************************************************************************

rm -f asm/arch

if [ -z "${soc}" ] ; then

ln -s ${LNPREFIX}arch-${cpu} asm/arch

else

ln -s ${LNPREFIX}arch-${soc} asm/arch

fi

********************************我是分割线*************************************

这里判断soc是否有值,在arch/arm/include/asm建立软链接,arch -> arch-s5pc1xx

*******************************************************************************

if [ "${arch}" = "arm" ] ; then

rm -f asm/proc

ln -s ${LNPREFIX}proc-armv asm/proc

fi

********************************我是分割线*************************************

同上,proc -> proc-armv

*******************************************************************************

#

# Create include file for Make

#

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

********************************我是分割线*************************************

include目录下生成 config.mk,内容如下:

ARCH   = arm

CPU    = armv7

BOARD  = smdkc100

VENDOR = samsung

SOC    = s5pc1xx

*******************************************************************************

# Assign board directory to BOARDIR variable

if [ -z "${vendor}" ] ; then

    BOARDDIR=${board}

else

    BOARDDIR=${vendor}/${board}

fi

********************************我是分割线*************************************

BOARDDIR值为samsung/smdkc100

*******************************************************************************

#

# Create board specific header file

#

if [ "$APPEND" = "yes" ] # Append to existing config file

then

echo >> config.h

else

> config.h # Create new config file

fi

********************************我是分割线*************************************

APPEND值为no,所以建空文件config.h

*******************************************************************************

echo "/* Automatically generated - do not edit */" >>config.h

for i in ${TARGETS} ; do

i="`echo ${i} | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'`"

echo "#define CONFIG_${i}" >>config.h ;

done

cat << EOF >> config.h

#define CONFIG_BOARDDIR board/$BOARDDIR

#include <config_cmd_defaults.h>

#include <config_defaults.h>

#include <configs/${CONFIG_NAME}.h>

#include <asm/config.h>

EOF

********************************我是分割线*************************************

config.h追加信息,内容如下:

/* Automatically generated - do not edit */

#define CONFIG_BOARDDIR board/samsung/smdkc100

#include <config_cmd_defaults.h>

#include <config_defaults.h>

#include <configs/smdkc100.h>

#include <asm/config.h>

*******************************************************************************

exit 0

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值