=分析uboot的配置过程(mkconfig脚本)=
uboot怎么配置?我们在终端上执行make NAME_config时的运行过程解析!

STEP1:

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

我们执行make *_config时会运行makefile的这两行程序,先分析下:
这个其实就是运行uboot根目录下的mkconfig文件,
并传入2个参数:

$1: -A
$2: $(@:_config=) :去掉目标*_config中的_config字符串也就是 *

STEP2:

然后开始运行mkconfig

STEP2.1:

APPEND=no   # Default: Create new config file
BOARD_NAME=""    # Name to print in make output
TARGETS=""arch=""
cpu=""
board=""
vendor=""
soc=""
options=""if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then# Automatic modeline=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` || {echo "make: *** No rule to make target \`$2_config'.  Stop." >&2exit 1}set ${line}# add default board name if needed[ $# = 3 ] && set ${line} ${1}
fi

这里面涉及到shell脚本if的使用语法,单分支语句结构

if [ 条件表达式 ]; then指令
fi

分析条件语句:

\( $# -eq 2 \) -a \( "$1" = "-A" \)

其中-a表示&& (语法:-o = or = ||, -a = and = && )
( $# -eq 2 )表示:输入的参数数目=2
( “$1” = “-A” ) 表示:输入的第一个参数=-A
这里条件满足,执行内部语句。

line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` ||{echo "make: *** No rule to make target \`$2_config'.  Stop." >&2 exit 1}

两个语句执行||。
语句1:搜索文件获得模式。-i表示当进行比较时忽略字符的大小写。表示在boards.cfg里面搜索字符串"^ [[:space:]]*${2}[[:space:]]"即含有2#参数的字符串
例如:配置命令为

make halley2_xImage_nand_spl_boot_config

在boards.cfg里面line586

halley2_xImage_nand_spl_boot   mips        xburst     halley2         ingenic        x1000       halley2:SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND

如果有该行代码则赋值给line,否则打印

"make: *** No rule to make target \`$2_config'.  Stop."

同时退出。
继续!

set ${line}

表示把line中存储的变量作为本文件的输入参数,即执行该语句之前参数数量为2,执行之后为7!

STEP2.2:

while [ $# -gt 0 ] ; do          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

关于shell指令的while循环语法:

while expression
docommand
done

条件是:参数个数$# -greater than 0 then…

关于shell指令的case语法:

case $xxx in
yyy)do something;;esac

检查1#参数是否有这几个符号,这里1#参数是

halley2_xImage_nand_spl_boot

条件不满足,则不执行该语句。

STEP2.3:

[ $# -lt 4 ] && exit 1           //$# -less than 4 退出
[ $# -gt 7 ] && exit 1      //$# -great than 7 退出# Strip all options and/or _config suffixes
CONFIG_NAME="${1%_config}"[ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"

如果定义了BOARD_NAME,则给它赋值。BOARD_NAME=halley2_xImage_nand_spl_boot_config

arch="$2"                                                         #赋值arch=mips
cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`                 #赋值cpu=xburst
spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`             #

awk为shell命令,具体参见收藏具体介绍。

if [ "$4" = "-" ] ; thenboard=${BOARD_NAME}
elseboard="$4"
fi

board="$4"=halley2

STEP2.4

1# halley2_xImage_nand_spl_boot
2# mips
3# xburst
4# halley2
5# ingenic
6# x1000
7# halley2:SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND
[ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
[ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6"

这里参数数量为7,两个条件均满足,所以vendor="$5" &&soc="$6"

[ $# -gt 6 ] && [ "$7" != "-" ] && {tmp="${7%:*}"        if [ "$tmp" ] ; thenCONFIG_NAME="$tmp"fi# Check if we only have a colon...if [ "${tmp}" != "$7" ] ; thenoptions=${7#*:}TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"fi
}

以上条件满足,
#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
#截取7#参数:前面的部分和后面的部分,分别给CONFIG_NAMEoptions

语法1:${VALUE%.*}或${VALUE%%.*}删除VALUE字符串中以分隔符“.”匹配的右边字符,保留左边字符。tmp="${7%:*}"这里tmp=halley2
CONFIG_NAME="$tmp"=halley2

语法2:sed是shell指令

if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; thenecho "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2exit 1
fi

语法:-a表示and,条件与
这里条件不满足。

if [ "$options" ] ; thenecho "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"
elseecho "Configuring for ${BOARD_NAME} board..."
fi

options变量存在,打印以下内容Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}=Configuring for halley2_xImage_nand_spl_boot - Board: halley2, Options: SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND

STEP2.5 创建asm链接

if [ "$SRCTREE" != "$OBJTREE" ] ; thenmkdir -p ${OBJTREE}/includemkdir -p ${OBJTREE}/include2cd ${OBJTREE}/include2rm -f asmln -s ${SRCTREE}/arch/${arch}/include/asm asmLNPREFIX=${SRCTREE}/arch/${arch}/include/asm/cd ../includemkdir -p asm
elsecd ./includerm -f asmln -s ../arch/${arch}/include/asm asm
fi

条件不满足,进入else分支,创建一个名称为asm的链接文件指向../arch/${arch}/include/asm
如果提示一下错误:
不可使用共享文件夹的方式进行

STEP2.6

if [ -z "${soc}" ] ; thenln -s ${LNPREFIX}arch-${cpu} asm/arch
elseln -s ${LNPREFIX}arch-${soc} asm/arch
fi

语法1:shell脚本中的if 参数-a至-z
[-z string] “string”的长度为零则为真
这里条件不满足,执行else 创建链接文件asm/arch指向${LNPREFIX}arch-${soc}arch-x1000

STEP2.7

#
# Create include file for Make
#
( echo "ARCH   = ${arch}"if [ ! -z "$spl_cpu" ] ; thenecho 'ifeq ($(CONFIG_SPL_BUILD),y)'echo "CPU    = ${spl_cpu}"echo "else"echo "CPU    = ${cpu}"echo "endif"elseecho "CPU    = ${cpu}"fiecho "BOARD  = ${board}"[ "${vendor}" ] && echo "VENDOR = ${vendor}"[ "${soc}"    ] && echo "SOC    = ${soc}"exit 0 ) > config.mk

在include/建立config.mk文件,

1.echo "ARCH   = ${arch}"   ----------------------->ARCH   = mips
2.
if [ ! -z "$spl_cpu" ] ; thenecho 'ifeq ($(CONFIG_SPL_BUILD),y)'echo "CPU    = ${spl_cpu}"echo "else"echo "CPU    = ${cpu}"echo "endif"elseecho "CPU    = ${cpu}"fi-------------------->CPU    = xburst
3.echo "BOARD  = ${board}"--------------------->BOARD  = halley2
4.echo "VENDOR = ${vendor}"--------------->VENDOR = ingenic
5.echo "SOC    = ${soc}"--------------------->SOC    = x1000

STEP2.8

#
# Create board specific header file
#
if [ "$APPEND" = "yes" ]   # Append to existing config file
thenecho >> config.h
else> config.h       # Create new config file
fi
echo "/* Automatically generated - do not edit */" >>config.h

创建文件./include/config.h,打印第一句到文件

for i in ${TARGETS} ; doi="`echo ${i} | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'`"echo "#define CONFIG_${i}" >>config.h ;
done

???需要查阅语法
对应文本为:

#define CONFIG_SPL_SFC_NAND  1
#define CONFIG_SPL_OS_BOOT  1
#define CONFIG_MTD_SFCNAND  1

打印下列语句到文件

echo "#define CONFIG_SYS_ARCH  \"${arch}\""  >> config.h
echo "#define CONFIG_SYS_CPU   \"${cpu}\""   >> config.h
echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h[ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h[ "${soc}"    ] && echo "#define CONFIG_SYS_SOC    \"${soc}\""    >> config.h

===

#define CONFIG_SYS_ARCH  "mips"
#define CONFIG_SYS_CPU   "xburst"
#define CONFIG_SYS_BOARD "halley2"
#define CONFIG_SYS_VENDOR "ingenic"
#define CONFIG_SYS_SOC    "x1000"
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#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

=============

#define CONFIG_BOARDDIR board/ingenic/halley2
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/halley2.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>

uboot - 配置过程1(分析国产君正的ingenic-linux-kernel3.10.14-x1000-v8.2-20181116\u-boot\mkconfig脚本)相关推荐

  1. 君正全平台linux源码同步教程(除X1830人脸识别板)

    环境:Ubuntu20.04 一.获取许可认证 根据君正全平台linux源码获取文档,使用"Alt+Ctrl+T"打开命令窗口,输入 $ssh-keygen 一直回车,回车,回车 ...

  2. U-Boot启动过程完全分析

    1.1       U-Boot工作过程 U-Boot启动内核的过程可以分为两个阶段,两个阶段的功能如下: (1)第一阶段的功能 Ø  硬件设备初始化 Ø  加载U-Boot第二阶段代码到RAM空间 ...

  3. U-Boot启动过程完全分析(转)

    1.1 U-Boot工作过程 U-Boot启动内核的过程可以分为两个阶段,两个阶段的功能如下: (1)第一阶段的功能 Ø 硬件设备初始化 Ø 加载U-Boot第二阶段代码到RAM空间 Ø 设置好栈 Ø ...

  4. U-Boot启动过程完全分析转

    转载自:http://www.cnblogs.com/heaad/archive/2010/07/17/1779829.html 1.1       U-Boot工作过程 U-Boot启动内核的过程可 ...

  5. U-Boot配置过程

    在顶层Makefile中可以看到如下代码: SRCTREE:= $(CURDIR) -- MKCONFIG:= $(SRCTREE)/mkconfig -- smdk2410_config:uncon ...

  6. 君正Zeratul开发(2)——uboot启动分析

    前言    boot启动一般分为两个阶段,君正设备的第一阶段uboot spl 程序没有开源,用户编译的是第二阶段的boot,最后将两个阶段的boot合并到一起,写入到boot分区中去,boot分区如 ...

  7. 2.4.U-Boot配置和编译过程详解-U-Boot和系统移植第4部分视频课程笔记

    目录 2.uboot 主Makefile分析 2.1.Makefile 分析2 2.2.Makefile 分析3 2.3.Makefile 分析4 2.4.链接脚本的定义 2.5.指定链接地址 如果T ...

  8. uboot配置和编译过程详解

    ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ 分享一个大神朋友的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到 ...

  9. fl2440——u-boot启动过程的简要分析

    u-boot是在嵌入式开发中,经常使用的bootloader. 我们知道,在PC上引导程序一般是由BIOS(一段固件程序)开始执行,然后读取硬盘中位于MBR(Main Boot Record,主引导记 ...

  10. S5PV210 Uboot开发与移植02:Uboot配置与编译

    目录 1. uboot源码目录简介 2. uboot编译原理引入 2.1 功能模块配置 2.1.1 在.c文件中不编译相应的功能语句 2.1.2 在make时不编译相应的功能模块 2.2 跨平台编译环 ...

最新文章

  1. Numpy入门教程:04. 数学函数
  2. 【java】java工具类StringUtils,org.apache.commons.lang3.StringUtils
  3. 023_JavaScript数字方法
  4. Java 对比Vector、ArrayList、LinkedList
  5. JVM学习笔记之-JVM性能监控-JVM监控及诊断工具-命令行方式
  6. keil 查看 stm32 io波形_你知道 KEIL 自带示波器吗?
  7. 华为双11发 20 亿奖金!?
  8. Android Day05-网络编程之文件下载之多线程断点续传技术
  9. java 线程 handler,java.lang.RuntimeException:处理程序(android.os.Handler)在死线程上向处理程序发送消息...
  10. js权威指南---学习笔记01
  11. lua java 传参_java和lua交互方法(1)
  12. Seasonal-ARIMA模型
  13. 3DGIS+数字孪生技术打造智慧工地监控系统分析
  14. 简述et代理换ip软件网络功能。
  15. 古琴十大名曲——唐畅古琴
  16. SEO常用的数据名词解释
  17. Scratch软件编程等级考试四级——20200620
  18. js中的3种弹出式消息提醒(警告窗口,确认窗口,信息输入窗口)的命令是什么?
  19. torch.meshgrid()函数解析
  20. windows System32 与SysWOW64区别

热门文章

  1. 英语一2011 阅读四
  2. python画一个心形照片墙怎么摆_这个七夕节,用Python为女友绘制一张爱心照片墙吧!...
  3. AD19快速制作多管脚元件符号
  4. 关于里程碑图 2017.01
  5. adb 查看浏览器内核版本
  6. Python 自动化办公 —— PyPDF2 库的基本使用
  7. 25.HTTP协议和WEB服务器APACHE
  8. HTTP协议报文头部结构和Web相关工具
  9. Vins-Fusion运行kitti,euroc和tum数据集并使用evo评估
  10. Cesium图形绘制