uboot 2013.01 代码简析(1)开发板配置

u-boot下载地址:ftp://ftp.denx.de/pub/u-boot/u-boot-2013.01.01.tar.bz2

下载之后对该文件进行解压。

我试着分析smdk2410_config对应的代码执行流程,接触u-boot时间较短,有不周之处还请见谅。

通常执行u-boot第一步就是进行开发板的配置,而smdk2410的配置命令如下:

make smdk2410_config

而Makefile中对应内容如下:

   775    %_config::    unconfig
   776        @$(MKCONFIG) -A $(@:_config=)

因为Makefile是先执行后面的目标再执行其后的命令,所以会执行unconfig对应的目标:

   770    unconfig:
   771        @rm -f $(obj)include/config.h $(obj)include/config.mk \
   772            $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \
   773            $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep

unconfig目标会把以前配置产生的文件先删除掉。

 

$(MKCONFIG)对应mkconfig文件

当配置参数是smdk2410时,$(@:_config=)的值为smdk2410

所以相当于执行下面的内容:

mkconfig -A smdk2410

mkconfig文件内容如下:

     1    #!/bin/sh -e
     2    
     3    # Script to create header files and links to configure
     4    # U-Boot for a specific board.
     5    #
     6    # Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
     7    #
     8    # (C) 2002-2010 DENX Software Engineering, Wolfgang Denk <wd@denx.de>
     9    #
    10    
    11    APPEND=no    # Default: Create new config file
    12    BOARD_NAME=""    # Name to print in make output
    13    TARGETS=""
    14    
    15    arch=""
    16    cpu=""
    17    board=""
    18    vendor=""
    19    soc=""
    20    options=""
    21    
    22    if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then
    23        # Automatic mode
    24        line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` || {
    25            echo "make: *** No rule to make target \`$2_config'.  Stop." >&2
    26            exit 1
    27        }
    28    
    29        set ${line}
    30        # add default board name if needed
    31        [ $# = 3 ] && set ${line} ${1}
    32    elif [ "${MAKEFLAGS+set}${MAKELEVEL+set}" = "setset" ] ; then
    33        # only warn when using a config target in the Makefile
    34        cat <<-EOF
    35    
    36        warning: Please migrate to boards.cfg.  Failure to do so will
    37                 mean removal of your board in the next release.
    38    
    39        EOF
    40        sleep 5
    41    fi
    42    
    43    while [ $# -gt 0 ] ; do
    44        case "$1" in
    45        --) shift ; break ;;
    46        -a) shift ; APPEND=yes ;;
    47        -n) shift ; BOARD_NAME="${1%_config}" ; shift ;;
    48        -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
    49        *)  break ;;
    50        esac
    51    done
    52    
    53    [ $# -lt 4 ] && exit 1
    54    [ $# -gt 7 ] && exit 1
    55    
    56    # Strip all options and/or _config suffixes
    57    CONFIG_NAME="${1%_config}"
    58    
    59    [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
    60    
    61    arch="$2"
    62    cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`
    63    spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`
    64    if [ "$4" = "-" ] ; then
    65        board=${BOARD_NAME}
    66    else
    67        board="$4"
    68    fi
    69    [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
    70    [ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6"
    71    [ $# -gt 6 ] && [ "$7" != "-" ] && {
    72        # check if we have a board config name in the options field
    73        # the options field mave have a board config name and a list
    74        # of options, both separated by a colon (':'); the options are
    75        # separated by commas (',').
    76        #
    77        # Check for board name
    78        tmp="${7%:*}"
    79        if [ "$tmp" ] ; then
    80            CONFIG_NAME="$tmp"
    81        fi
    82        # Check if we only have a colon...
    83        if [ "${tmp}" != "$7" ] ; then
    84            options=${7#*:}
    85            TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"
    86        fi
    87    }
    88    
    89    if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then
    90        echo "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2
    91        exit 1
    92    fi
    93    
    94    if [ "$options" ] ; then
    95        echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"
    96    else
    97        echo "Configuring for ${BOARD_NAME} board..."
    98    fi
    99    
   100    #
   101    # Create link to architecture specific headers
   102    #
   103    if [ "$SRCTREE" != "$OBJTREE" ] ; then
   104        mkdir -p ${OBJTREE}/include
   105        mkdir -p ${OBJTREE}/include2
   106        cd ${OBJTREE}/include2
   107        rm -f asm
   108        ln -s ${SRCTREE}/arch/${arch}/include/asm asm
   109        LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/
   110        cd ../include
   111        mkdir -p asm
   112    else
   113        cd ./include
   114        rm -f asm
   115        ln -s ../arch/${arch}/include/asm asm
   116    fi
   117    
   118    rm -f asm/arch
   119    
   120    if [ -z "${soc}" ] ; then
   121        ln -s ${LNPREFIX}arch-${cpu} asm/arch
   122    else
   123        ln -s ${LNPREFIX}arch-${soc} asm/arch
   124    fi
   125    
   126    if [ "${arch}" = "arm" ] ; then
   127        rm -f asm/proc
   128        ln -s ${LNPREFIX}proc-armv asm/proc
   129    fi
   130    
   131    #
   132    # Create include file for Make
   133    #
   134    ( echo "ARCH   = ${arch}"
   135        if [ ! -z "$spl_cpu" ] ; then
   136        echo 'ifeq ($(CONFIG_SPL_BUILD),y)'
   137        echo "CPU    = ${spl_cpu}"
   138        echo "else"
   139        echo "CPU    = ${cpu}"
   140        echo "endif"
   141        else
   142        echo "CPU    = ${cpu}"
   143        fi
   144        echo "BOARD  = ${board}"
   145    
   146        [ "${vendor}" ] && echo "VENDOR = ${vendor}"
   147        [ "${soc}"    ] && echo "SOC    = ${soc}"
   148        exit 0 ) > config.mk
   149    
   150    # Assign board directory to BOARDIR variable
   151    if [ -z "${vendor}" ] ; then
   152        BOARDDIR=${board}
   153    else
   154        BOARDDIR=${vendor}/${board}
   155    fi
   156    
   157    #
   158    # Create board specific header file
   159    #
   160    if [ "$APPEND" = "yes" ]    # Append to existing config file
   161    then
   162        echo >> config.h
   163    else
   164        > config.h        # Create new config file
   165    fi
   166    echo "/* Automatically generated - do not edit */" >>config.h
   167    
   168    for i in ${TARGETS} ; do
   169        i="`echo ${i} | sed '/=/ {s/=/    /;q; } ; { s/$/    1/; }'`"
   170        echo "#define CONFIG_${i}" >>config.h ;
   171    done
   172    
   173    echo "#define CONFIG_SYS_ARCH  \"${arch}\""  >> config.h
   174    echo "#define CONFIG_SYS_CPU   \"${cpu}\""   >> config.h
   175    echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h
   176    
   177    [ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h
   178    
   179    [ "${soc}"    ] && echo "#define CONFIG_SYS_SOC    \"${soc}\""    >> config.h
   180    
   181    cat << EOF >> config.h
   182    #define CONFIG_BOARDDIR board/$BOARDDIR
   183    #include <config_cmd_defaults.h>
   184    #include <config_defaults.h>
   185    #include <configs/${CONFIG_NAME}.h>
   186    #include <asm/config.h>
   187    #include <config_fallbacks.h>
   188    #include <config_uncmd_spl.h>
   189    EOF
   190    
   191    exit 0

其中24行从boards.cfg中查找包含smdk2410并其后紧跟空格的行,从而可以得到:

line = smdk2410 arm arm920t - samsung s3c24x0

后续内容就是创建一些文件夹链接。

之后根据line提取出arch,cpu,board,vendor,soc,并写入到include/config.mk中,include/config.mk内容如下:

     1    ARCH   = arm
     2    CPU    = arm920t
     3    BOARD  = smdk2410
     4    VENDOR = samsung
     5    SOC    = s3c24x0

然后将配置写入到include/config.h中,include/config.h内容如下:

     1    /* Automatically generated - do not edit */
     2    #define CONFIG_SYS_ARCH  "arm"
     3    #define CONFIG_SYS_CPU   "arm920t"
     4    #define CONFIG_SYS_BOARD "smdk2410"
     5    #define CONFIG_SYS_VENDOR "samsung"
     6    #define CONFIG_SYS_SOC    "s3c24x0"
     7    #define CONFIG_BOARDDIR board/samsung/smdk2410
     8    #include <config_cmd_defaults.h>
     9    #include <config_defaults.h>
    10    #include <configs/smdk2410.h>
    11    #include <asm/config.h>
    12    #include <config_fallbacks.h>
    13    #include <config_uncmd_spl.h>

这样整个配置部分就基本完成了

 

posted on 2014-05-13 22:20  qiaoqiao2003  阅读(996)  评论(0编辑  收藏  举报

导航