码迷,mamicode.com
首页 > 其他好文 > 详细

u-boot根目录下mkconfig文件学习笔记

时间:2015-03-12 11:42:57      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:linux   u-boot   mkconfig   

编译ZedBoard的u-boot.elf(ssbl)中知道了编译u-boot的步骤,以及u-boot下载地址,这里使用2014.4版本。由于现在使用的是zc702开发板,所以应该使用如下命令编译u-boot:

1、make zynq_zc70x_config

2、make


其中第1条命令和第2条命令都会执行根目录下的Makefile文件,但是在Makefile文件中会判断make命令后是否跟了带_config的参数。如果带了,就会执行mkconfig -A zynq_zc70x这条命令。否则就执行生成u-boot.bin的那一大段命令。


这里mkconfig做了几件事:

1、从boards.cfg中获取目标板参数,并将参数传给8个变量。

2、./arch/arm/include/asm下进行一些文件夹链接。

3、在./include/目录下生成config.mk和config.h文件。

 

 

#!/bin/sh -e

# Script to createheader files and links to configure

# U-Boot for aspecific board.

#

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

#

# (C) 2002-2013DENX Software Engineering, Wolfgang Denk <wd@denx.de>

#

#SPDX-License-Identifier:       GPL-2.0+

#

APPEND=no  # Default: Create new config file

BOARD_NAME=""      # Name to print in make output

TARGETS=""

 

arch=""

cpu=""

board=""

vendor=""

soc=""

options=""


#我们执行的命令是mkconfig  –A zynq_zc70x,所以$#值为2,$1值为-A,以下条件满足

if [ \( $# -eq 2\) -a \( "$1" = "-A" \) ] ; then  

       # Automatic mode

       line=`awk ‘($0 !~ /^#/ && $7 ~/^‘"$2"‘$/) { print $1, $2, $3, $4, $5, $6, $7, $8 }‘$srctree/boards.cfg`      #board.cfg中找到zynq_zc70x对应的那行,并将整行值付给line

       if [ -z "$line" ] ; then     #line变量为null 表示没有在boards.cfg中找到目标板信息

              echo "make: *** No rule tomake target \`$2_config‘.  Stop.">&2

              exit 1

       fi

 

       set ${line}   #set用于在脚本内部给出其运行参数,所以这个时候脚本运行参数就变为line的值:Active   arm     armv7   zynq     xilinx     zynq   zynq_zc70x   -    


       # add default board name if needed

       [ $# = 3 ] && set ${line} ${1}

fi

 #由于我们并没有传递给mkconfig任何的选项,因此while循环中的代码不起作用。

while [ $# -gt0 ] ; do 

       case "$1" in

       --) shift ; break ;;

       -a) shift ; APPEND=yes ;;

       -n) shift ;BOARD_NAME="${7%_config}" ; shift ;;

       -t) shift ; TARGETS="`echo $1 | sed‘s:_: :g‘` ${TARGETS}" ; shift ;;

       *) break ;;

       esac

done

 

#参数个数小于7或者大于8退出,现在参数为8,不退出

[ $# -lt 7 ]&& exit 1

[ $# -gt 8 ]&& exit 1


 #${7%_config}的意思是 如果$7以 _config 后缀结束的话,则要去掉 _config后缀。由于现在$7=zynq_zc70x,所以CONFIG_NAME就等zynq_zc70x

# Strip alloptions and/or _config suffixes

CONFIG_NAME="${7%_config}"  

 

[ "${BOARD_NAME}"] || BOARD_NAME="${7%_config}"    #BOARD_NAME为空,所以此时BOARD_NAME也等于zynq_zc70x

 

arch="$2"   #arch=arm

cpu=`echo $3 | awk‘BEGIN {FS = ":"} ; {print $1}‘`  #cpu=armv7

spl_cpu=`echo $3 |awk ‘BEGIN {FS = ":"} ; {print $2}‘`  #spl_cpu=armv7

 

if ["$cpu" = "-" ] ; then

       cpu=

fi

 

[ "$6"!= "-" ] && board="$6"  #board=zynq

[ "$5"!= "-" ] && vendor="$5"  #vendor=xilinx

[ "$4"!= "-" ] && soc="$4"      #soc=zynq

#$8”-“,不执行代码

[ $# -gt 7 ]&& [ "$8" != "-" ] && {

       # check if we have a board config name inthe options field

       # the options field mave have a boardconfig name and a list

       # of options, both separated by a colon(‘:‘); the options are

       # separated by commas (‘,‘).

       #

       # Check for board name

       tmp="${8%:*}"

       if [ "$tmp" ] ; then

              CONFIG_NAME="$tmp"

       fi

       # Check if we only have a colon...

       if [ "${tmp}" != "$8"] ; then

              options=${8#*:}

              TARGETS="`echo ${options} |sed ‘s:,: :g‘` ${TARGETS}"

       fi

}

   

#如果ARCH已经有值了,那么就检测ARCH和arch是否匹配了。(现在ARCH就为arch)

if ["${ARCH}" -a "${ARCH}" != "${arch}" ]; then

       echo "Failed: \$ARCH=${ARCH}, shouldbe ‘${arch}‘ for ${BOARD_NAME}" 1>&2

       exit 1

fi

 

#

# Test aboveneeded aarch64, now we need arm

#

if ["${arch}" = "aarch64" ]; then

       arch="arm"

fi


#此时options为空,所以输出Configuringfor zynq_zc70x board…

if ["$options" ] ; then

       echo "Configuring for ${BOARD_NAME}- Board: ${CONFIG_NAME}, Options: ${options}"

else

       echo "Configuring for ${BOARD_NAME}board..."

fi

 

#以下操作主要是创建一些文件夹链接

#KBUILD_SRC、objtree、srctree的路径值都是在Makefile中执行mkconfig -A zynq_zc70x命令之前设置好的。

#KBUILD_SRC为空,objtree、srctree为根目录路径

#

# Create link toarchitecture specific headers

#

if [ -n "$KBUILD_SRC" ] ; then     #KBUILD_SRC为空,所以进入else语句

       mkdir -p ${objtree}/include     

       LNPREFIX=${srctree}/arch/${arch}/include/asm/

       cd ${objtree}/include    

       mkdir -p asm

else

       cd arch/${arch}/include   #进入./arch/arm/include目录

fi

 

rm -f asm/arch   #直接删除当前目录下asm/arch目录

 

if ["${soc}" ] ; then     #soc为zynq,进入if分支

       ln -s ${LNPREFIX}arch-${soc} asm/arch    #将asm/arch链接为arch-zynq目录,LNPREFIX=””

elif ["${cpu}" ] ; then

       ln -s ${LNPREFIX}arch-${cpu} asm/arch

fi

 

if [ -z"$KBUILD_SRC" ] ; then  #KBUILD_SRC为空,进入根目录下include目录

       cd ${srctree}/include

fi

 

#

# Create includefile for Make

###################################################

执行如下代码后,在根目录include目录下创建config.mk文件并写入:

ARCH   = arm

CPU    = armv7

BOARD  = zynq

VENDOR =xilinx

SOC    = zynq

 ###################################################

( 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}"

    fi

    echo "BOARD  = ${board}"

 

    [ "${vendor}" ] && echo"VENDOR = ${vendor}"

    [ "${soc}"    ] && echo "SOC    = ${soc}"

    exit 0 ) >config.mk

 

# Assign boarddirectory to BOARDIR variable

if [ -z"${vendor}" ] ; then    #vendor不为空,进入else分支

    BOARDDIR=${board}

else

    BOARDDIR=${vendor}/${board}   #BOARDDIR=xilinx/zynq

fi

 

#

# Create boardspecific header file

#####################################################

执行以下代码后,在根目录include目录下创建config.h文件并写入:

/*Automatically generated - do not edit */

#defineCONFIG_SYS_ARCH  "arm"

#define CONFIG_SYS_CPU   "armv7"

#defineCONFIG_SYS_BOARD "zynq"

#defineCONFIG_SYS_VENDOR "xilinx"

#defineCONFIG_SYS_SOC    "zynq"

#defineCONFIG_BOARDDIR board/xilinx/zynq

#include<config_cmd_defaults.h>

#include<config_defaults.h>

#include<configs/zynq_zc70x.h>

#include<asm/config.h>

#include<config_fallbacks.h>

#include<config_uncmd_spl.h>

 #####################################################

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

 

for i in${TARGETS} ; do

       i="`echo ${i} | sed ‘/=/ {s/=/    /;q; } ; { s/$/  1/; }‘`"

       echo "#define CONFIG_${i}">>config.h ;

done

 

echo "#defineCONFIG_SYS_ARCH \"${arch}\"" >> config.h

echo "#defineCONFIG_SYS_CPU   \"${cpu}\""   >> config.h

echo "#defineCONFIG_SYS_BOARD \"${board}\"" >> config.h

 

["${vendor}" ] && echo "#define CONFIG_SYS_VENDOR\"${vendor}\"" >> config.h

 

["${soc}"    ] && echo"#define CONFIG_SYS_SOC   \"${soc}\""   >> config.h

 

["${board}"  ] && echo"#define CONFIG_BOARDDIR board/$BOARDDIR" >> config.h

#将输入的内容追加到config.h中,直到出现“EOF”这样的标识为止。

cat << EOF>> config.h

#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

u-boot根目录下mkconfig文件学习笔记

标签:linux   u-boot   mkconfig   

原文地址:http://blog.csdn.net/emsoften/article/details/44217269

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!