u-bootMakefile--makexxx_config

浏览:
字体:
发布时间:2013-12-20 16:18:44
来源:

[Author: Bo Shen <voice.shen@gmail.com>]

[u-boot: 2014.01-rc1]

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

举例:make sama5d3xek_nandflash_config

764 #########################################################################765 766 unconfig:767         @rm -f $(obj)include/config.h $(obj)include/config.mk /768                 $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp /769                 $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep /770                 $(obj)include/spl-autoconf.mk /771                 $(obj)include/tpl-autoconf.mk772 773 %_config::      unconfig774         @$(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脚本。

 24 if [ /( $# -eq 2 /) -a /( "$1" = "-A" /) ] ; then 25         # Automatic mode 26         line=`awk '($0 !~ /^#/ && $7 ~ /^'"$2"'$/) { print $1, $2, $3, $4, $5, $6, $7, $8 }' boards.cfg` 27         if [ -z "$line" ] ; then 28                 echo "make: *** No rule to make target /`$2_config'.  Stop." >&2 29                 exit 1 30         fi 31  32         set ${line} 33         # add default board name if needed 34         [ $# = 3 ] && set ${line} ${1} 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}

 37 while [ $# -gt 0 ] ; do 38         case "$1" in 39         --) shift ; break ;; 40         -a) shift ; APPEND=yes ;; 41         -n) shift ; BOARD_NAME="${7%_config}" ; shift ;; 42         -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;; 43         *)  break ;; 44         esac 45 done
 47 [ $# -lt 7 ] && exit 1 48 [ $# -gt 8 ] && exit 1
如果,参数个数小于7或者大于8则都退出。即参数个数只能是7或者8.
 55 arch="$2" 56 cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'` 57 spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'` 58 if [ "$6" = "-" ] ; then 59         board=${BOARD_NAME} 60 else 61         board="$6" 62 fi 63 [ "$5" != "-" ] && vendor="$5" 64 [ "$4" != "-" ] && soc="$4" 65 [ $# -gt 7 ] && [ "$8" != "-" ] && { 66         # check if we have a board config name in the options field 67         # the options field mave have a board config name and a list 68         # of options, both separated by a colon (':'); the options are 69         # separated by commas (','). 70         # 71         # Check for board name 72         tmp="${8%:*}" 73         if [ "$tmp" ] ; then 74                 CONFIG_NAME="$tmp" 75         fi 76         # Check if we only have a colon... 77         if [ "${tmp}" != "$8" ] ; then 78                 options=${8#*:} 79                 TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}" 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文件。

123 #124 # Create include file for Make125 #126 ( echo "ARCH   = ${arch}"127     if [ ! -z "$spl_cpu" ] ; then128         echo 'ifeq ($(CONFIG_SPL_BUILD),y)'129         echo "CPU    = ${spl_cpu}"130         echo "else"131         echo "CPU    = ${cpu}"132         echo "endif"133     else134         echo "CPU    = ${cpu}"135     fi136     echo "BOARD  = ${board}"137 138     [ "${vendor}" ] && echo "VENDOR = ${vendor}"139     [ "${soc}"    ] && echo "SOC    = ${soc}"140     exit 0 ) > config.mk创建config.h文件
149 #150 # Create board specific header file151 #152 if [ "$APPEND" = "yes" ]        # Append to existing config file153 then154         echo >> config.h155 else156         > config.h              # Create new config file157 fi158 echo "/* Automatically generated - do not edit */" >>config.h159 160 for i in ${TARGETS} ; do161         i="`echo ${i} | sed '/=/ {s/=/  /;q; } ; { s/$/ 1/; }'`"162         echo "#define CONFIG_${i}" >>config.h ;163 done164 165 echo "#define CONFIG_SYS_ARCH  /"${arch}/""  >> config.h166 echo "#define CONFIG_SYS_CPU   /"${cpu}/""   >> config.h167 echo "#define CONFIG_SYS_BOARD /"${board}/"" >> config.h168 169 [ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR /"${vendor}/"" >> config.h170 171 [ "${soc}"    ] && echo "#define CONFIG_SYS_SOC    /"${soc}/""    >> config.h172 173 cat << EOF >> config.h174 #define CONFIG_BOARDDIR board/$BOARDDIR175 #include <config_cmd_defaults.h>176 #include <config_defaults.h>177 #include <configs/${CONFIG_NAME}.h>178 #include <asm/config.h>179 #include <config_fallbacks.h>180 #include <config_uncmd_spl.h>181 EOF
>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();