uboot编译学习----执行完make TQ2440_config后,在mkconfig 中

来源:互联网 发布:全国数学建模大赛知乎 编辑:程序博客网 时间:2024/06/06 06:57
转载参考博客:http://www.cnblogs.com/heaad/archive/2010/07/17/1779806.html

上篇博客讲到   ./mkconfig TQ2440 arm arm920t TQ2440 samsung s3c24x0  

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

[cpp] view plaincopyprint?
  1. TQ2440:Target(目标板型号)  
  2. arm:Architecture (目标板的CPU架构)  
  3. arm920t:CPU (具体使用的CPU型号)  
  4. TQ2440:Board  
  5. samsung:VENDOR(生产厂家名)  
  6. s3c24x0:SOC  


下面再来看看mkconfig脚本到底做了什么。

1)确定开发板名称BOARD_NAME

mkconfig脚本中有如下代码:

[cpp] view plaincopyprint?
  1. APPEND=no      # no表示创建新的配置文件,yes表示追加到配置文件中  
  2. BOARD_NAME="" # Name to print in make output  
  3. TARGETS=""  
  4. while [ $# -gt 0 ] ; do  
  5.     case "$1" in  
  6.     --) shift ; break ;;  
  7.     -a) shift ; APPEND=yes ;;  
  8.     -n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;  
  9.     -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;  
  10.     *)  break ;;  
  11.     esac  
  12. done  
  13. "${BOARD_NAME}" ] || BOARD_NAME="$1"   

环境变量$#表示传递给脚本的参数个数,这里的命令有6个参数,因此$#shift的作用是使$1=$2$2=$3$3=$4….,而原来的$1将丢失。因此while循环的作用是,依次处理传递给mkconfig脚本的选项。由于我们并没有传递给mkconfig任何的选项,因此while循环中的代码不起作用。

最后将BOARD_NAME的值设置为$1的值,在这里就是“TQ2440”

2)检查参数合法性

[cpp] view plaincopyprint?
  1. [ $# -lt 4 ] && exit 1  
  2. [ $# -gt 6 ] && exit 1  
上面代码的作用是检查参数个数和参数是否正确,参数个数少于4个或多于6个都被认为是错误的。

3)创建到目标板相关的目录的链接

[cpp] view plaincopyprint?
  1. #   
  2. # Create link to architecture specific headers  
  3. #   
  4. if [ "$SRCTREE" != "$OBJTREE" ] ; then         #若编译目标输出到外部目录,则下面的代码有效  
  5.        mkdir -p ${OBJTREE}/include  
  6.        mkdir -p ${OBJTREE}/include2  
  7.        cd ${OBJTREE}/include2  
  8.        rm -f asm  
  9.        ln -s ${SRCTREE}/include/asm-$2 asm  
  10.        LNPREFIX="http://www.cnblogs.com/include2/asm/"  
  11.        cd ../include  
  12.        rm -rf asm-$2  
  13.        rm -f asm  
  14.        mkdir asm-$2  
  15.        ln -s asm-$2 asm  
  16. else                
  17.        cd ./include  
  18.        rm -f asm  
  19.        ln -s asm-$2 asm  
  20. fi  

若将目标文件设定为输出到源文件所在目录,则以上代码在include目录下建立了到asm-arm目录的符号链接asm

其中的ln -s asm-$2 asmln -s asm-arm asm 

[cpp] view plaincopyprint?
  1. rm -f asm-$2/arch  
  2. if [ -z "$6" -o "$6" = "NULL" ] ; then  
  3.        ln -s ${LNPREFIX}arch-$3 asm-$2/arch  
  4. else  
  5.        ln -s ${LNPREFIX}arch-$6 asm-$2/arch  
  6. fi  

建立符号链接include/asm-arm/arch ,若$6SOC)为空,则使其链接到include/asm-arm/arch-arm920t目录,

否则就使其链接到include/asm-arm/arch-s3c24x0目录。

(事实上include/asm-arm/arch-arm920t并不存在,因此$6是不能为空的,否则会编译失败).

[cpp] view plaincopyprint?
  1. if [ "$2" = "arm" ] ; then  
  2.        rm -f asm-$2/proc  
  3.        ln -s ${LNPREFIX}proc-armv asm-$2/proc  
  4. fi  

若目标板是arm架构,则上面的代码将建立符号连接include/asm-arm/proc,使其链接到目录proc-armv目录。

建立以上的链接的好处编译U-Boot时直接进入链接文件指向的目录进行编译,而不必根据不同开发板来选择不同目录。

4)构建include/config.mk文件

[cpp] view plaincopyprint?
  1. #   
  2. # Create include file for Make   
  3. #   
  4. echo "ARCH   = $2" >  config.mk  
  5. echo "CPU    = $3" >> config.mk  
  6. echo "BOARD  = $4" >> config.mk  
  7. "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk  
  8. "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk  
 上面代码将会把如下内容写入文件inlcude/config.mk文件:
[cpp] view plaincopyprint?
  1. ARCH   = arm  
  2. CPU    = arm920t  
  3. BOARD  = TQ2440  
  4. VENDOR = samsung  
  5. SOC    = s3c24x0  

5)指定开发板代码所在目录

[cpp] view plaincopyprint?
  1. # Assign board directory to BOARDIR variable  
  2. if [ -z "$5" -o "$5" = "NULL" ] ; then  
  3.     BOARDDIR=$4  
  4. else  
  5.     BOARDDIR=$5/$4  
  6. fi  
 以上代码指定board目录下的一个目录为当前开发板专有代码的目录。

$5VENDOR)为空则BOARDDIR设置为$4BOARD),否则设置为$5/$4VENDOR/BOARD)。

在这里由于$5不为空,因此BOARDDIR被设置为samsung/TQ2440 

6)构建include/config.h文件

[cpp] view plaincopyprint?
  1. #   
  2. # Create board specific header file   
  3. #   
  4. if [ "$APPEND" = "yes" ] # Append to existing config file  
  5. then  
  6.        echo >> config.h  
  7. else  
  8.        > config.h            # Create new config file  
  9. fi  
  10. echo "/* Automatically generated - do not edit */" >>config.h  
  11. for i in ${TARGETS} ; do  
  12.        echo "#define CONFIG_MK_${i} 1" >>config.h ;  
  13. done   
  14. cat << EOF >> config.h  
  15. #define CONFIG_BOARDDIR board/$BOARDDIR  
  16. #include <config_defaults.h>   
  17. #include <configs/$1.h>   
  18. #include <asm/config.h>   
  19. EOF  
  20. exit 0  

这里的“cat << EOF >> config.h”表示将输入的内容追加到config.h中,直到出现“EOF”这样的标识为止。


若APPEND为no,则创建新的include/config.h文件。

若APPEND为yes,则将新的配置内容追加到include/config.h文件后面。

由于APPEND的值保持“no”,

因此config.h被创建了,并添加了如下的内容:

[cpp] view plaincopyprint?
  1. /* Automatically generated - do not edit */  
  2.   
  3. #define CONFIG_BOARDDIR board/samsung/TQ2440  
  4.   
  5. #include <config_defaults.h>  
  6.   
  7. #include <configs/TQ2440.h>  
  8.   
  9. #include <asm/config.h>  

总结:

 下面总结命令make TQ2440_config执行的结果(仅针对编译目标输出到源代码目录的情况):

(1)    创建到目标板相关的文件的链接

[cpp] view plaincopyprint?
  1. ln -s asm-arm asm  
  2. ln -s arch-s3c24x0 asm-arm/arch  
  3. ln -s proc-armv asm-arm/proc  

(2)    创建include/config.mk文件,内容如下所示:

[cpp] view plaincopyprint?
  1. ARCH   = arm  
  2. CPU    = arm920t  
  3. BOARD  = TQ2440  
  4. VENDOR = samsung  
  5. SOC    = s3c24x0  

(3)    创建与目标板相关的文件include/config.h,如下所示:

[cpp] view plaincopyprint?
  1.  /* Automatically generated - do not edit */  
  2. #define CONFIG_BOARDDIR board/samsung/TQ2440  
  3. #include <config_defaults.h>  
  4. #include <configs/TQ2440.h>   
0 0
原创粉丝点击