本文在上文基础上进行分析,http://blog.csdn.net/qq_33160790/article/details/53867013
1.在u-boot-1.1.6下找到Makefile
2.分析$make 100ask24x0_config
打开Makefile文件,搜索100ask24x0_config可找到:
100ask24x0_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
●查找MKCONFIG可找到:
MKCONFIG := $(SRCTREE)/mkconfig
SRCTREE为源文件树,所以MKCONFIG为u-boot-1.1.6/mkconfig
●@:_config=这里使用了Makefile中的替换引用规则,@为100ask24x0_config,这句话表明把_config替换为空。
所以执行make 100ask24x0_config相当于执行
mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
3.接下来分析mkconfig,mkconfig源码:
1.在u-boot-1.1.6下找到Makefile
2.分析$make 100ask24x0_config
打开Makefile文件,搜索100ask24x0_config可找到:
100ask24x0_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
●查找MKCONFIG可找到:
MKCONFIG := $(SRCTREE)/mkconfig
SRCTREE为源文件树,所以MKCONFIG为u-boot-1.1.6/mkconfig
●@:_config=这里使用了Makefile中的替换引用规则,@为100ask24x0_config,这句话表明把_config替换为空。
所以执行make 100ask24x0_config相当于执行
mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
3.接下来分析mkconfig,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-2006 DENX Software Engineering, Wolfgang Denk <wd@denx.de>
#
APPEND=no # Default: Create new config file
BOARD_NAME="" # Name to print in make output
while [ $# -gt 0 ] ; do
case "$1" in
--) shift ; break ;;
-a) shift ; APPEND=yes ;;
-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
*) break ;;
esac
done
[ "${BOARD_NAME}" ] || BOARD_NAME="$1"
[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1
echo "Configuring for ${BOARD_NAME} 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}/include/asm-$2 asm
LNPREFIX="../../include2/asm/"
cd ../include
rm -rf asm-$2
rm -f asm
mkdir asm-$2
ln -s asm-$2 asm
else
cd ./include
rm -f asm
ln -s asm-$2 asm
fi
rm -f asm-$2/arch
if [ -z "$6" -o "$6" = "NULL" ] ; then
ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
ln -s ${LNPREFIX}arch-$6 asm-$2/arch
fi
if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc
fi
#
# Create include file for Make
#
echo "ARCH = $2" > config.mk
echo "CPU = $3" >> config.mk
echo "BOARD = $4" >> config.mk
[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
#
# 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
echo "/* Automatically generated - do not edit */" >>config.h
echo "#include <configs/$1.h>" >>config.h
exit 0
APPEND=no # Default: Create new config file
BOARD_NAME="" # Name to print in make output
TARGETS=""
TARGETS=""
# 下面一段代码不执行(while---done),由于./mkconfig arm arm920t gec2440 samsung s3c24x0没有--、-a、
# -n、-t
# -n、-t
while [ $# -gt 0 ] ; do 判断传入参数是否大于0, 是则执行. 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
-a) shift ; APPEND=yes ;;
-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
-t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
*) break ;; esac done
# 为来方便理解,这里用一个类似C语法表示:
#while(xxx
#{
# switch "$1" {
# case --: shift ; break ;
# case -a: shift ; APPEND=yes ;
# case -n: shift ; BOARD_NAME="${1%%_config}" ; shift ;
# case -t: shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;
# default : break ;
#while(xxx
#{
# switch "$1" {
# case --: shift ; break ;
# case -a: shift ; APPEND=yes ;
# case -n: shift ; BOARD_NAME="${1%%_config}" ; shift ;
# case -t: shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;
# default : break ;
# }
#}
#
# 备注: $# 参数个数 $1 第一个参数
#
# 备注: $# 参数个数 $1 第一个参数
[ "${BOARD_NAME}" ] || BOARD_NAME="$1"
# 如果BOARD_NAME 没有定义就不执行,定义了就执行 BOARD_NAME="$1"
[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1
[ $# -gt 6 ] && exit 1
# "-lt"表示小于,"-gt" 表示大于 , 如果参数个数小于4 个 ,返回状态值为1,退出
# 如果参数个数大于6个,返回状态值为1, 退出
# 这里我们的参数为6个,既不大于6个也不小于4个,这里不退出
# 如果参数个数大于6个,返回状态值为1, 退出
# 这里我们的参数为6个,既不大于6个也不小于4个,这里不退出
#判断设备体系:
if [ "${ARCH}" -a "${ARCH}" != "$2" ]; then
echo "Failed: \$ARCH=${ARCH}, should be '$2' for ${BOARD_NAME}" 1>&2
exit 1
fi
# “-a” 是同时的意思 , 这里的意思是: ARCH已经赋值了,同时ARCH又不等于$2,就大于错误体现信息.
# 结果: ARCH 赋值要与 $2 相同
# 操作方法:编译uboot 时传入: make ARCH=arm
# “-a” 是同时的意思 , 这里的意思是: ARCH已经赋值了,同时ARCH又不等于$2,就大于错误体现信息.
# 结果: ARCH 赋值要与 $2 相同
# 操作方法:编译uboot 时传入: make ARCH=arm
echo "Configuring for ${BOARD_NAME} board..."
# 操作成功:出现提示: Configuring for hzb2440 board...
#
# Create link to architecture specific headers
#
#判断是否在源代码目录下编译Uboot , 是的话, 直接跳到else 处执行 , if 内的不执行.
if [ "$SRCTREE" != "$OBJTREE" ] ; then
mkdir -p ${OBJTREE}/include
mkdir -p ${OBJTREE}/include2
cd ${OBJTREE}/include2
rm -f asm ln -s ${SRCTREE}/include/asm-$2 asm
LNPREFIX="../../include2/asm/"
cd ../include
rm -rf asm-$2
rm -f asm
mkdir asm-$2
ln -s asm-$2 asm
else
cd ./include // 打开源代码目录下的 include rm -f asm //删除原来的asm目录 ln -s asm-$2 asm // 创建新的链接目录 ----> asm 链接到 asm-arm , 相当于 ln -s include/asm-arm asm
fi
rm -f asm-$2/arch //删除原有asm-$2/arch临时目录
if [ -z "$6" -o "$6" = "NULL" ] ; then
ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
ln -s ${LNPREFIX}arch-$6 asm-$2/arch //ln -s include/arch-s3c24x0 include/asm-arm/arch
fi
# “-z” 为空的意思 , “-o” 或者的意思 if [ -z "$6" -o "$6" = "NULL" ] 这里是判断"$6"是否为空或者赋值为NULL
# 这里执行 else 下的语句 ln -s ${LNPREFIX}arch-$6 asm-$2/arch 生成新的体系链接文件, 将前面删掉的链接文 # 件生成回来
# 结果: arch-s3c24x0 === 》 asm-arm/arch
if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc //删除include/asm-arm/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc //ln -s include/proc-arm asm-arm/pro
fi
#
# Create include file for Make
#
echo "ARCH = $2" > config.mk //ARCH=arm,放入include/config.mk
echo "CPU = $3" >> config.mk //CPU=arm920t,放入includde/config.mk
echo "BOARD = $4" >> config.mk //BOARD=hzb2440,放入include/config.mk
# 将体系、cpu 、板子信息写入config.mk 文件
[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
# VERDOR=samaung,放入include/config.mk
[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
# SOC=s3c24x0,放入include/config.mk
# 将板子相关的信息一起写入config.mk
# Create link to architecture specific headers
#
#判断是否在源代码目录下编译Uboot , 是的话, 直接跳到else 处执行 , if 内的不执行.
if [ "$SRCTREE" != "$OBJTREE" ] ; then
mkdir -p ${OBJTREE}/include
mkdir -p ${OBJTREE}/include2
cd ${OBJTREE}/include2
rm -f asm ln -s ${SRCTREE}/include/asm-$2 asm
LNPREFIX="../../include2/asm/"
cd ../include
rm -rf asm-$2
rm -f asm
mkdir asm-$2
ln -s asm-$2 asm
else
cd ./include // 打开源代码目录下的 include rm -f asm //删除原来的asm目录 ln -s asm-$2 asm // 创建新的链接目录 ----> asm 链接到 asm-arm , 相当于 ln -s include/asm-arm asm
fi
rm -f asm-$2/arch //删除原有asm-$2/arch临时目录
if [ -z "$6" -o "$6" = "NULL" ] ; then
ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
ln -s ${LNPREFIX}arch-$6 asm-$2/arch //ln -s include/arch-s3c24x0 include/asm-arm/arch
fi
# “-z” 为空的意思 , “-o” 或者的意思 if [ -z "$6" -o "$6" = "NULL" ] 这里是判断"$6"是否为空或者赋值为NULL
# 这里执行 else 下的语句 ln -s ${LNPREFIX}arch-$6 asm-$2/arch 生成新的体系链接文件, 将前面删掉的链接文 # 件生成回来
# 结果: arch-s3c24x0 === 》 asm-arm/arch
if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc //删除include/asm-arm/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc //ln -s include/proc-arm asm-arm/pro
fi
#
# Create include file for Make
#
echo "ARCH = $2" > config.mk //ARCH=arm,放入include/config.mk
echo "CPU = $3" >> config.mk //CPU=arm920t,放入includde/config.mk
echo "BOARD = $4" >> config.mk //BOARD=hzb2440,放入include/config.mk
# 将体系、cpu 、板子信息写入config.mk 文件
[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
# VERDOR=samaung,放入include/config.mk
[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
# SOC=s3c24x0,放入include/config.mk
# 将板子相关的信息一起写入config.mk
#
# Create board specific header file
#
if [ "$APPEND" = "yes" ] # Append to existing config file 由第一行知道,APPEND=no
then
echo >> config.h
else > config.h # Create new config file 产生config.h文件,位于include目录下
fi
echo "/* Automatically generated - do not edit */" >>config.h
for i in ${TARGETS} ; do
echo "#define CONFIG_MK_${i} 1" >>config.h ;
# 将"#define CONFIG_MK_${i} 1加入上面产生的config.h文件
done
echo "#include <configs/$1.h>" >>config.h
#config.h文件包含头文件"#include <configs/hzb2440.h>
echo "#include <asm/config.h>" >>config.h
#config.h文件包含头文件"#include <asm/config.h>
exit 0
结果:生成config.h ,然后写入
#include <configs/hzb2440.h> ---> 得出编译最终uboot依赖的头文件configs/100ask24x0.h #include <asm/config.h>
# Create board specific header file
#
if [ "$APPEND" = "yes" ] # Append to existing config file 由第一行知道,APPEND=no
then
echo >> config.h
else > config.h # Create new config file 产生config.h文件,位于include目录下
fi
echo "/* Automatically generated - do not edit */" >>config.h
for i in ${TARGETS} ; do
echo "#define CONFIG_MK_${i} 1" >>config.h ;
# 将"#define CONFIG_MK_${i} 1加入上面产生的config.h文件
done
echo "#include <configs/$1.h>" >>config.h
#config.h文件包含头文件"#include <configs/hzb2440.h>
echo "#include <asm/config.h>" >>config.h
#config.h文件包含头文件"#include <asm/config.h>
exit 0
结果:生成config.h ,然后写入
#include <configs/hzb2440.h> ---> 得出编译最终uboot依赖的头文件configs/100ask24x0.h #include <asm/config.h>
4.总结mkconfig作用:
●使开发板名称BOARD_NAME等于$1。
●创建到平台/开发板相关的头文件的链接
ln -s asm-$2 asm
ln -s arch-$6 asm-$2/arch
ln -s proc-armv asm-$2/proc (如果$2不是arm的话,没有此行)
●创建顶层Makefile包含的文件include/config.mk,如下所示
ARCH=$2
CPU=$3
BOARD=$4
VENDOR=$5($5为空或者是NULL,则无)
SOC=$6($6为空,或者是NULL,则无)
●创建开发板相关的头文件include/comfig.h,如下:
/*Automatically generated -do not edit*/
#include<configs/$1.h>