u-boot Makefile -- make xxx_config

当我们执行:make xxx_config, 其做了什么工作呢?下面具体分析:

举例:make sama5d3xek_nandflash_config

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 764 #########################################################################  
  2. 765   
  3. 766 unconfig:  
  4. 767         @rm -f $(obj)include/config.h $(obj)include/config.mk \  
  5. 768                 $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \  
  6. 769                 $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep \  
  7. 770                 $(obj)include/spl-autoconf.mk \  
  8. 771                 $(obj)include/tpl-autoconf.mk  
  9. 772   
  10. 773 %_config::      unconfig  
  11. 774         @$(MKCONFIG) -A $(@:_config=)  

773:make程序会进行通配,执行此行。首先进行unconfig操作。进行一些文件删除。

774:$(MKCONFIG)是在109@Makefile赋值。"MKCONFIG        := $(SRCTREE)/mkconfig" 其相当于执行:mkconfig -A sama5d3xek_nandflash

注:$(@:_config=) 的作用就是将sama5d3xek_nandflash_config中的_config用空替换。

下面具体分析mkconfig -A samad3xek_nand做了什么工作。

mkconfig是一个shell脚本。

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 24 if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then  
  2. 25         # Automatic mode  
  3. 26         line=`awk '($0 !~ /^#/ && $7 ~ /^'"$2"'$/) { print $1, $2, $3, $4, $5, $6, $7, $8 }' boards.cfg`  
  4. 27         if [ -z "$line" ] ; then  
  5. 28                 echo "make: *** No rule to make target \`$2_config'.  Stop." >&2  
  6. 29                 exit 1  
  7. 30         fi  
  8. 31   
  9. 32         set ${line}  
  10. 33         # add default board name if needed  
  11. 34         [ $# = 3 ] && set ${line} ${1}  
  12. 35 fi  
24: 判断mkconfig的参数个数是否为2,并且第一个参数为“-A”。在此例子中,参数个数为2, 并且第一个参数为“-A”,所以条件成立,执行下面代码。

26:通过awk命令从boards.cfg文件中查找第二个参数,如果找到打印1~8参数(空格区分),最后赋值给line变量。

line=Active arm armv7 at91 atmel sama5d3xek sama5d3xek_nandflash sama5d3xek:SAMA5D3,SYS_USE_NANDFLASH

32:通过set命令,设置mkconfig新的参数。

34:判断$#(参数个数)是否为3, 如果是,set ${line} ${1}

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 37 while [ $# -gt 0 ] ; do  
  2. 38         case "$1" in  
  3. 39         --) shift ; break ;;  
  4. 40         -a) shift ; APPEND=yes ;;  
  5. 41         -n) shift ; BOARD_NAME="${7%_config}" ; shift ;;  
  6. 42         -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;  
  7. 43         *)  break ;;  
  8. 44         esac  
  9. 45 done  

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 47 [ $# -lt 7 ] && exit 1  
  2. 48 [ $# -gt 8 ] && exit 1  
如果,参数个数小于7或者大于8则都退出。即参数个数只能是7或者8.

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 55 arch="$2"  
  2. 56 cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`  
  3. 57 spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`  
  4. 58 if [ "$6" = "-" ] ; then  
  5. 59         board=${BOARD_NAME}  
  6. 60 else  
  7. 61         board="$6"  
  8. 62 fi  
  9. 63 [ "$5" != "-" ] && vendor="$5"  
  10. 64 [ "$4" != "-" ] && soc="$4"  
  11. 65 [ $# -gt 7 ] && [ "$8" != "-" ] && {  
  12. 66         # check if we have a board config name in the options field  
  13. 67         # the options field mave have a board config name and a list  
  14. 68         # of options, both separated by a colon (':'); the options are  
  15. 69         # separated by commas (',').  
  16. 70         #  
  17. 71         # Check for board name  
  18. 72         tmp="${8%:*}"  
  19. 73         if [ "$tmp" ] ; then  
  20. 74                 CONFIG_NAME="$tmp"  
  21. 75         fi  
  22. 76         # Check if we only have a colon...  
  23. 77         if [ "${tmp}" != "$8" ] ; then  
  24. 78                 options=${8#*:}  
  25. 79                 TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"  
  26. 80         f  
55: arch=$2 (在这个例子中,为: arm)

56: cpu=armv7

57: spl_cpu=NULL

58~62: 判断$6是否为“-", 不是则用$6 (sama5d3xek)

63: vendor=atmel

64: soc=at91

65~81: 分析参数8.

创建config.mk文件。

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 123 #  
  2. 124 # Create include file for Make  
  3. 125 #  
  4. 126 ( echo "ARCH   = ${arch}"  
  5. 127     if [ ! -z "$spl_cpu" ] ; then  
  6. 128         echo 'ifeq ($(CONFIG_SPL_BUILD),y)'  
  7. 129         echo "CPU    = ${spl_cpu}"  
  8. 130         echo "else"  
  9. 131         echo "CPU    = ${cpu}"  
  10. 132         echo "endif"  
  11. 133     else  
  12. 134         echo "CPU    = ${cpu}"  
  13. 135     fi  
  14. 136     echo "BOARD  = ${board}"  
  15. 137   
  16. 138     [ "${vendor}" ] && echo "VENDOR = ${vendor}"  
  17. 139     [ "${soc}"    ] && echo "SOC    = ${soc}"  
  18. 140     exit 0 ) > config.mk  

创建config.h文件

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 149 #  
  2. 150 # Create board specific header file  
  3. 151 #  
  4. 152 if [ "$APPEND" = "yes" ]        # Append to existing config file  
  5. 153 then  
  6. 154         echo >> config.h  
  7. 155 else  
  8. 156         > config.h              # Create new config file  
  9. 157 fi  
  10. 158 echo "/* Automatically generated - do not edit */" >>config.h  
  11. 159   
  12. 160 for i in ${TARGETS} ; do  
  13. 161         i="`echo ${i} | sed '/=/ {s/=/  /;q; } ; { s/$/ 1/; }'`"  
  14. 162         echo "#define CONFIG_${i}" >>config.h ;  
  15. 163 done  
  16. 164   
  17. 165 echo "#define CONFIG_SYS_ARCH  \"${arch}\""  >> config.h  
  18. 166 echo "#define CONFIG_SYS_CPU   \"${cpu}\""   >> config.h  
  19. 167 echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h  
  20. 168   
  21. 169 [ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h  
  22. 170   
  23. 171 [ "${soc}"    ] && echo "#define CONFIG_SYS_SOC    \"${soc}\""    >> config.h  
  24. 172   
  25. 173 cat << EOF >> config.h  
  26. 174 #define CONFIG_BOARDDIR board/$BOARDDIR  
  27. 175 #include <config_cmd_defaults.h>  
  28. 176 #include <config_defaults.h>  
  29. 177 #include <configs/${CONFIG_NAME}.h>  
  30. 178 #include <asm/config.h>  
  31. 179 #include <config_fallbacks.h>  
  32. 180 #include <config_uncmd_spl.h>  
  33. 181 EOF  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值