难得五一没啥安排,闲的无聊,开始移植u-boot-2012.10,与大家分享哈。首先分析u-boot-2012.10,看它与以前的u-boot-1.1.6有啥不同,分析u-boot建Source Insight工程不再详述。这里以TQ2440为例,配置过程分析,从Makefile开始。
一·、分析u-boot根目录下的Makefile
往往在编译u-boot之前,会配置相应单板。eg:make smdk2410_config,打开Makefile,找不到smdk2410_config,只看到746:smdk6400_config。
change@change:~$ cd Si/TQ2440/u-boot-2012.10/
change@change:~/Si/TQ2440/u-boot-2012.10$ ls
api boards.cfg COPYING doc examples lib Makefile net rules.mk test
arch common CREDITS drivers fs MAINTAINERS mkconfig post snapshot.commit tools
board config.mk disk dts include MAKEALL nand_spl README spl
change@change:~/Si/TQ2440/u-boot-2012.10$ grep "smdk2410" * -nR
arch/arm/include/asm/mach-types.h:1646:# define machine_is_smdk2410() (machine_arch_type == MACH_TYPE_SMDK2410)
arch/arm/include/asm/mach-types.h:1648:# define machine_is_smdk2410() (0)
board/samsung/smdk2410/Makefile:28:COBJS := smdk2410.o
boards.cfg:72:smdk2410 arm arm920t - samsung s3c24x0
MAINTAINERS:771: smdk2410 ARM920T
找到了,在根目录下的board.cfg,还是回到Makefile找boards.cfg:718
sinclude $(obj).boards.depend
$(obj).boards.depend: boards.cfg
@awk '(NF && $$1 !~ /^#/) { print $$1 ": " $$1 "_config; $$(MAKE)" }' $< > $@
.boards.depend是个隐藏文件,在根目录下ctrl + h,配置之前没有,配置后就生成了.boards.depend30:smdk:smdk2410_config;$(MAKE)。这里应该是读取根目录下的boards.cfg,生成单板相关依赖文件.boards.depend。
根据这些线索开始分析:
change@change:~/Si/TQ2440/u-boot-2012.10$ make smdk2410_config
Configuring for smdk2410 board...
/Makefile:715
%_config:: unconfig
@$(MKCONFIG) -A $(@:_config=)
%_config:: unconfig,其中%是通配符,会执行MKCONFIG。在Makefile113:MKCONFIG:= $(SRCTREE)/mkconfig,及执行根目录下的mkconfig。 $(:_config=)等于空相当于没有, make smdk2410_config 相当于执行mkconfig -A smdk2410,即开始执行根目录下的mkconfig
二、分析u-boot根目录下的mkconfig
mkconfig -A smdk2410 //$1=-A$2=smdk2410
if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then//满足条件
line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg`//在boards.cfg中grep smdk2410,知道boards.cfg确实有单板smdk2410,下面echo不会执行
echo "make: *** No rule to make target \`$2_config'. Stop." >&2
set ${line} //在这里设定参数,可以做个试验在这加几个打印语句echo $1;echo $2;echo $3;echo $4;echo $5;echo $6
change@change:~/Si/TQ2440/u-boot-2012.10$ make smdk2410_config
smdk2410
arm
arm920t
-
samsung
s3c24x0
Configuring for smdk2410 board...
OK现在参数明确了$1=smdk2410,$2=arm,$3=arm920t,$4=NULL,$5=samsung,$6=s3c24x0,接着分析配置,就跟以前的u-boot差不多了,我直接把执行的语句列出
CONFIG_NAME="${1%_config}" //CONFIG_NAME=smdk2410_config
arch="$2" //arch=arm
cpu=`echo $3...‘ //cpu=arm920t
if [ "$4" = "-" ] ; then
board=${BOARD_NAME}//board=smdk2410
[ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6" //soc=s3c24x0
echo "Configuring for ${BOARD_NAME} board..." //对于配置输出的Configuring for smdk2410 board...
# Create link to architecture specific headers
cd ./include
rm -f asm
ln -s ../arch/${arch}/include/asm asm
rm -f asm/arch
ln -s ${LNPREFIX}arch-${cpu} asm/arch
if [ "${arch}" = "arm" ] ; then
rm -f asm/proc
ln -s ${LNPREFIX}proc-armv asm/proc
# Create include file for Make
( echo "ARCH = ${arch}"
if [ ! -z "$spl_cpu" ] ; then
echo 'ifeq ($(CONFIG_SPL_BUILD),y)'
echo "CPU = ${spl_cpu}"
echo "else"
echo "CPU = ${cpu}"
echo "endif"
else
echo "CPU = ${cpu}" //CPU=arm920t
fi
echo "BOARD = ${board}"
[ "${vendor}" ] && echo "VENDOR = ${vendor}"
[ "${soc}" ] && echo "SOC = ${soc}"
exit 0 ) > config.mk //将上面信息创建到/include/config.mk,可以看到如下:
change@change:~/Si/TQ2440/u-boot-2012.10/include$ cat config.mk
ARCH = arm
CPU = arm920t
BOARD = smdk2410
VENDOR = samsung
SOC = s3c24x0
# Create board specific header file
if [ "$APPEND" = "yes" ] # Append to existing config file
then
echo >> config.h
else
> config.h # Create new config file //APPEND" = no,创建/include/config.h
fi
echo "/* Automatically generated - do not edit */" >>config.h//加内容到config.h
for i in ${TARGETS} ; do //TARGETS=“”,不执行
i="`echo ${i} | sed '/=/ {s/=//;q; } ; { s/$/1/; }'`"
echo "#define CONFIG_${i}" >>config.h ;
done
echo "#define CONFIG_SYS_ARCH \"${arch}\"" >> config.h //加内容到config.h:#define CONFIG_SYS_ARCH "arm"下面也是如此
echo "#define CONFIG_SYS_CPU \"${cpu}\"" >> config.h//#define CONFIG_SYS_CPU "arm920t"
echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h//#define CONFIG_SYS_BOARD "smdk2410"
[ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h//#define CONFIG_SYS_VENDOR "samsung"
[ "${soc}" ] && echo "#define CONFIG_SYS_SOC \"${soc}\"" >> config.h//#define CONFIG_SYS_SOC "s3c24x0"
cat << EOF >> config.h //加以下内容到config.h
#define CONFIG_BOARDDIR board/$BOARDDIR //#define CONFIG_BOARDDIR board/samsung/smdk2410
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/${CONFIG_NAME}.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
EOF
exit 0
分析结果:
1.读取boards.cfg,生成单板相关依赖文件.boards.depend
2.mkconfig -A smdk2410,执行根目录下mkconfig,在boards.cfg中搜索单板
3.在/include目录下生成config.mk、config.h,内容如下:
change@change:~/Si/TQ2440/u-boot-2012.10$ cat include/config.mk
ARCH = arm
CPU = arm920t
BOARD = smdk2410
VENDOR = samsung
SOC = s3c24x0
change@change:~/Si/TQ2440/u-boot-2012.10$ cat include/config.h
/* Automatically generated - do not edit */
#define CONFIG_SYS_ARCH "arm"
#define CONFIG_SYS_CPU "arm920t"
#define CONFIG_SYS_BOARD "smdk2410"
#define CONFIG_SYS_VENDOR "samsung"
#define CONFIG_SYS_SOC "s3c24x0"
#define CONFIG_BOARDDIR board/samsung/smdk2410
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/smdk2410.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
change@change:~/Si/TQ2440/u-boot-2012.10$
花了不少时间,配置过程总算分析完成。编译过程以后再分析吧,分析这些东东太累了,比移植u-boot还要累。
原作者:http://blog.csdn.net/u010216127/article/details/8869129?reload