zoukankan      html  css  js  c++  java
  • 嵌入式Linux驱动学习之路(三)u-boot配置分析

    u-boot配置流程分析

      执行make tiny4412_config后,将会对u-boot进行一些列的配置,以便于后面的编译。

      打开顶层目录下的Makefile,查找对于的规则tiny4412_config。

      TINY4412对应的规则是%_config

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

      在Makefile中%为通配符,代表任意长度的任何字符,因此%_config就匹配到 tiny4412_config。

      双::表示强制执行下面的命令。

      先执行依赖 unconfig,删除以前的配置。

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

    $(@:_config=)使用了替代引用规则,所谓替代引用规则为 $(variable:search=replace)

    :号后为搜索字符串,=号后为用于替代的字符串。
    $@为目标,也就是 tiny4412_config,搜索字符串为"_config",用于替代的字符串为空串,因此$(@:_config=)最后就被解析为"tiny4412"。

    MKCONFIG在前面定义为:
      MKCONFIG := $(SRCTREE)/mkconfig
      SRCTREE := $(CURDIR)

    这样命令最后被解析为:mkconfig -A tiny4412

    转而去执行mkconfig脚本。

    现在分析mkconfig脚本。

       首先将一些关键变量设置为空。

    APPEND=no    # Default: Create new config file
    BOARD_NAME=""    # Name to print in make output
    TARGETS=""
    
    arch=""
    cpu=""
    board=""
    vendor=""
    soc=""
    options=""

      然后判断传入给mkconfig的参数格式是否正确。

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

      $#传入参数的个数。$1传入的第一个参数。-a 则代表前后都成立。

      然后依据传入的第二个参数(tiny4412)从boards.cfg中提取相关信息。

    line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` || {

      从中读取到的信息为:tiny4412(目标板型号)   arm(CPU架构)         armv7(CPU型号)       tiny4412(开发板名称)            samsung(生产厂家)        exynos(片上系统)

    while [ $# -gt 0 ] ; do  //参数大于0则执行
        case "$1" in
        --) shift ; break ;;
        -a) shift ; APPEND=yes ;;
        -n) shift ; BOARD_NAME="${1%_config}" ; shift ;;
        -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
        *)  break ;;
        esac
    done

      读取的信息中没有和以上匹配的,故不执行。

    [ $# -lt 4 ] && exit 1
    [ $# -gt 7 ] && exit 1
    

      读取到的数据个数为6,以上也不执行。

    # Strip all options and/or _config suffixes
    CONFIG_NAME="${1%_config}"    //将第一个参数后面加上_config赋值给CONFIG_NAME  即tiny4412_config
    
    [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
    
    arch="$2"
    cpu="$3"
    if [ "$4" = "-" ] ; then    //如果第4个参数没有设置则设置为BOARD_NAME
    board=${BOARD_NAME} else board="$4" fi [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5" [ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6" [ $# -gt 6 ] && [ "$7" != "-" ] && { # check if we have a board config name in the options field # the options field mave have a board config name and a list # of options, both separated by a colon (':'); the options are # separated by commas (','). # # Check for board name tmp="${7%:*}" if [ "$tmp" ] ; then CONFIG_NAME="$tmp" fi # Check if we only have a colon... if [ "${tmp}" != "$7" ] ; then options=${7#*:} TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}" fi } if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then echo "Failed: $ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2 exit 1 fi if [ "$options" ] ; then echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}" else echo "Configuring for ${BOARD_NAME} board..." fi

      

    接下来是创建平台相关的头文件的链接。

    会创建一个include和include2目录

    在include目录下建立config.mk并保存相关文件。

    在include目录下建立config.h

    并写一下内容

    #define CONFIG_BOARDDIR board/$BOARDDIR
    #include <config_defaults.h>
    #include <configs/${CONFIG_NAME}.h>    //实际是#include <configs/tiny4412.h>
    #include <asm/config.h>
    

       在include/configs/下需要我们提供写好的tiny4412.h的文件。

    到此配置过程结束。

    总结命令make tiny4412_config

    1. 创建到目标板相关文件的链接,也就是执行了如下命令。

    ln -s asm-arm asm
    ln -s arch-s3c24x0 asm-arm/arch
    ln -s proc-armv asm-arm/proc

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

    ARCH   = arm
    CPU    = armv7
    BOARD  = tiny4412
    VENDOR = samsung
    SOC    = exynos

     3. 创建include/config.h文件,内容如下:

    /* Automatically generated - do not edit */
    #define CONFIG_BOARDDIR board/samsung/tiny4412
    #include <config_defaults.h>
    #include <configs/tiny4412.h>
    #include <asm/config.h>
  • 相关阅读:
    后缀数组板子
    上海高校金马五校赛 J
    西安电子科技大学第16届程序设计竞赛网络同步赛 G-小国的复仇
    HDU
    string 与char* char[]之间的转换 .
    (分治思想)(归并排序)C
    如何取出 Map中key和value的值
    C++ STL 中 map 容器的说明和使用技巧 .
    (经典map)A
    Babelfish(6.1.2)(sort结构体排序)(sscanf()基本使用方法)(二分法)
  • 原文地址:https://www.cnblogs.com/ynxf/p/5952896.html
Copyright © 2011-2022 走看看