2.4.uboot配置和编译过程详解(2021-4-18)


2.4.1、uboot主Makefile分析1

2.4.1.1、uboot version确定(Makefile的24-29行)

在这里插入图片描述

//uboot中的Makefile部分代码
VERSION = 1          //主版本号   Makefile定义和使用变量,直接定义和使用,引用变量时用%var
PATCHLEVEL = 3       //次版本号   Mkaefile不要求赋值运算符两边一定要有空格或者无空格
SUBLEVEL = 4         //再次版本号
EXTRAVERSION =       //附加的版本信息
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)   //最终版本号

//version_autogenerated.h在uboot的头文件include下面
///root/x210v3_bsp/uboot/include
//用=赋值的变量,在被解析时他的值取决于最后一次赋值时的值,
//所以你看变量引用时的值不能只往前面看,还要往后面看
VERSION_FILE = $(obj)include/version_autogenerated.h        //=往后面找

2.4.1.2、HOSTARCH和HOSTOS

在这里插入图片描述

//uname -m:得到当前CPU的版本号
root@xfj-virtual-machine:/mnt/hgfs/winshare/s5pv210/uboot/4.makefile/4.1# uname -m
x86_64

//uname -s: 显示当前内核名称
root@xfj-virtual-machine:/mnt/hgfs/winshare/s5pv210/uboot/4.makefile/4.1# uname -s
Linux


#var=`pwd`

#var=$(shell pwd)

# X86_64
HOSTARCH := $(shell uname -m | \
        sed -e s/i.86/i386/ \
            -e s/sun4u/sparc64/ \
            -e s/arm.*/arm/ \
            -e s/sa110/arm/ \
            -e s/powerpc/ppc/ \
            -e s/ppc64/ppc/ \
            -e s/macppc/ppc/)

HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
            sed -e 's/\(cygwin\).*/cygwin/')

all:
        #echo $(var)
        echo $(HOSTARCH)
        echo $(HOSTOS)

//uboot中的Makefile部分代码
HOSTARCH := $(shell uname -m | \
	sed -e s/i.86/i386/ \
	    -e s/sun4u/sparc64/ \
	    -e s/arm.*/arm/ \
	    -e s/sa110/arm/ \
	    -e s/powerpc/ppc/ \
	    -e s/ppc64/ppc/ \
	    -e s/macppc/ppc/)

HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
	    sed -e 's/\(cygwin\).*/cygwin/')
//Makefile中用export导出的就是环境变量。
//环境变量类似于整个工程中所有Makefile之间可以共享的全局变量
//定义了一个环境变量会影响工程中别的Makefile文件
export	HOSTARCH HOSTOS                                     //导出环境变量

2.4.2、uboot主Makefile分析2

2.4.2.1、静默编译(50-54行)

在这里插入图片描述

#########################################################################
# Allow for silent builds        允许静默编译
ifeq ( , $(findstring s,$(MAKEFLAGS)))    
XECHO = echo                     //如果在输入的命令行中MAKEFLAGS中没有找到s,其为空,与前面的相等,执行此句
else
XECHO = :                        //如果在输入的命令行中在MAKEFLAGS中找到s,其不为空,与前面的不相等,执行此句
endif

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

2.4.2.2、2种编译方法(原地编译和单独输出文件夹编译)

在这里插入图片描述

#########################################################################
#
# U-boot build supports producing a object files to the separate external
# directory. Two use cases are supported:
# U-boot构建支持在单独的外部目录中生成目标文件。支持两种用例:
#
# 1) Add O= to the make command line  将O =添加到生成命令行
# 'make O=/tmp/build all'
#
# 2) Set environement variable BUILD_DIR to point to the desired location
# 将环境变量BUILD_DIR设置为指向所需位置
# 'export BUILD_DIR=/tmp/build'       设置方法
# 'make'
#
# The second approach can also be used with a MAKEALL script  
# 第二种方法也可以用于MAKEALL脚本
# 'export BUILD_DIR=/tmp/build'
# './MAKEALL'
#
# Command line 'O=' setting overrides BUILD_DIR environent variable.
# 命令行“O=”设置覆盖BUILD_DIR环境变量。
#
# When none of the above methods is used the local build is performed and
# the object files are placed in the source directory.
# 当不使用上述任何方法时,将执行本地构建,并将目标文件放在源目录中。

//这是第一种方法的实现过程,$(origin O)是输出变量O的定义来源,假设在命令行模式输
//入#make O=/tmp/build all来编译,
//那么O的定义来源是命令行,函数的输出是command line。
ifdef O                                 //如果定义了O
ifeq ("$(origin O)", "command line")    //比如make O=/tmp/build all
//:=用来赋值,就是直接就地解析,只用往前看即可
BUILD_DIR := $(O)                       //将O的值赋值给BUILD_DIR
endif
endif

//倘若BUILD_DIR定义过了,也就是不希望目标文件与源文件混在一起,
//那么直到“endif # //ifneq ($(BUILD_DIR),)”
//的内容都有效;倘若没有定义BUILD_DIR,那么这部分代码将不起作用。
ifneq ($(BUILD_DIR),)                   //如果BUILD_DIR不为空的话
//:=用来赋值,就是直接就地解析,只用往前看即可
saved-output := $(BUILD_DIR)            //将BUILD_DIR保存在saved-output变量中

# Attempt to create a output directory.
# 尝试创建输出目录
//-d是判断BUILD_DIR是否存在,倘若不存在就就创建。mkdir的-p参数代表若路径中的某些目录不存在
//也一并创建
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}) 

# Verify if it was successful.验证是否成功。
//试图进入$(BUILD_DIR),倘若能进入,则将它的路径赋给BUILD_DIR,注意这时的BUILD_DIR已经是一个
//真实存在目录的代言人,而之前的只是希望创建的目录。需要说明的是倘若BUILD_DIR还没有创建,
//那么cd $(BUILD_DIR)将执行错误,返回值是空,虽然这时发生错误,
//但是编译会忽略这个错误还能继续进行。
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)

//如果没有创建成功,就执行error函数,输出信息output directory "$(saved-output)" does not exist),然后编译终止
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)

//如果BUILD_DIR不为空,目标目录就等于BUILD_DIR;倘若没定义,就取为当前目录
OBJTREE		:= $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE		:= $(CURDIR)   //源文件目录等于当前文件夹
TOPDIR		:= $(SRCTREE)  //顶层目录等于源文件目录
LNDIR		:= $(OBJTREE)  //连接目录等于BUILD_DIR
export	TOPDIR SRCTREE OBJTREE //将这三个变量导出

MKCONFIG	:= $(SRCTREE)/mkconfig  //指定mkconfig的位置
export MKCONFIG            //将MKCONFIG变量导出

ifneq ($(OBJTREE),$(SRCTREE))   //如果目标目录和源文件目录不相等
REMOTE_BUILD	:= 1            //就定义REMOTE_BUILD变量并取值为1
export REMOTE_BUILD             //然后再将变量导出
endif

# $(obj) and (src) are defined in config.mk but here in main Makefile
# we also need them before config.mk is included which is the case for
# some targets like unconfig, clean, clobber, distclean, etc.
//$(obj)和(src)是在config.mk中定义的,但是在主Makefile中,我们在包含config.mk
//之前也需要它们,这是一些目标的情况,比如unpack、clean、clobber、distclean等。

//定义变量obj和src,并将这两个变量导出,obj是编译目标文件的前缀,从而实现生成的目标文件在于
//源文件相区别的目录中
ifneq ($(OBJTREE),$(SRCTREE))
obj := $(OBJTREE)/
src := $(SRCTREE)/
else
obj :=
src :=
endif
export obj src 

# Make sure CDPATH settings don't interfere 确保CDPATH设置不会干扰
unexport CDPATH

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

2.4.3、uboot主Makefile分析3

2.4.3.1、OBJTREE、SRCTREE、TOPDIR

在这里插入图片描述

# $(obj) and (src) are defined in config.mk but here in main Makefile
# we also need them before config.mk is included which is the case for
# some targets like unconfig, clean, clobber, distclean, etc.
//$(obj)和(src)是在config.mk中定义的,但是在主Makefile中,我们在包含config.mk
//之前也需要它们,这是一些目标的情况,比如unpack、clean、clobber、distclean等。

//定义变量obj和src,并将这两个变量导出,obj是编译目标文件的前缀,
//从而实现生成的目标文件在于源文件相区别的目录中
ifneq ($(OBJTREE),$(SRCTREE))      //OBJTREE目录和SRCTREE目录是否相等
obj := $(OBJTREE)/                 //OBJTREE目录和SRCTREE目录不相等执行此处
src := $(SRCTREE)/
else                               //OBJTREE目录和SRCTREE目录相等执行此处(默认情况下相等)
obj :=
src :=
endif
export obj src                   //导出环境变量obj 、src                   

2.4.3.2、MKCONFIG(Makefile的101行)

在这里插入图片描述

//如果没有创建成功,就执行error函数,输出信息output directory "$(saved-output)" does not exist),
//然后编译终止
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)

//如果BUILD_DIR不为空,目标目录就等于BUILD_DIR;倘若没定义,就取为当前目录
OBJTREE		:= $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE		:= $(CURDIR)   //源文件目录等于当前文件夹
TOPDIR		:= $(SRCTREE)  //顶层目录等于源文件目录
LNDIR		:= $(OBJTREE)  //连接目录等于BUILD_DIR
export	TOPDIR SRCTREE OBJTREE //将这三个变量导出

MKCONFIG	:= $(SRCTREE)/mkconfig  //指定mkconfig的位置
export MKCONFIG                     //将MKCONFIG变量导出

2.4.3.3、include $(obj)include/config.mk(133行)

在这里插入图片描述

#########################################################################
ifeq ($(ARCH),powerpc)
ARCH = ppc
endif
//这个ifeq横跨的范围非常广,用红色加粗字体表明。只有$(OBJTREE)/include/config.mk存在
//(也就是说已经执行了make *.config)的情况下,这部分包含的内容才有效
ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk))

# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk   //将make *_config生成的config.mk文件包含进来
export	ARCH CPU BOARD VENDOR SOC //导出5个变量以供其他子目录的makefile调用

#########################################################################
x210_sd_config :	unconfig
	//调用MKCONFIG脚本,然后向里面传参
	@$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
	@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk
#########################################################################

2.4.3.4、ARCH CROSS_COMPILE

在这里插入图片描述

#########################################################################
ifndef CROSS_COMPILE    //如果没有定义CROSS_COMPILE,就执行下面的,否则不执行  
ifeq ($(HOSTARCH),$(ARCH)) //如果主机架构和开发板ARCH一致
CROSS_COMPILE =
else                       //如果主机架构和开发板ARCH不一致
ifeq ($(ARCH),ppc)         //如果开发板的架构为ppc时,定义前缀ppc_8xx-
CROSS_COMPILE = ppc_8xx-
endif
ifeq ($(ARCH),arm)         //如果开发板的架构为arm时,定义前缀...
#CROSS_COMPILE = arm-linux-
#CROSS_COMPILE = /usr/local/arm/4.4.1-eabi-cortex-a8/usr/bin/arm-linux-
#CROSS_COMPILE = /usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-
CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
endif
ifeq ($(ARCH),i386)       //如果开发板的架构为i386时,定义前缀i386-linux-
CROSS_COMPILE = i386-linux-
endif
ifeq ($(ARCH),mips)       //如果开发板的架构为  时,定义前缀
CROSS_COMPILE = mips_4KC-
endif
ifeq ($(ARCH),nios)       //如果开发板的架构为nios时,定义前缀nios-elf-
CROSS_COMPILE = nios-elf-
endif
ifeq ($(ARCH),nios2)      //如果开发板的架构为nios2时,定义前缀nios2-elf-
CROSS_COMPILE = nios2-elf-
endif
ifeq ($(ARCH),m68k)      //如果开发板的架构为m68k时,定义前缀m68k-elf-
CROSS_COMPILE = m68k-elf-
endif
ifeq ($(ARCH),microblaze)//如果开发板的架构为microblaze时,定义前缀mb-
CROSS_COMPILE = mb-
endif
ifeq ($(ARCH),blackfin)//如果开发板的架构为blackfin时,定义前缀bfin-uclinux-
CROSS_COMPILE = bfin-uclinux-
endif
ifeq ($(ARCH),avr32)   //如果开发板的架构为avr32时,定义前缀avr32-linux-
CROSS_COMPILE = avr32-linux-
endif
ifeq ($(ARCH),sh)      //如果开发板的架构为sh时,定义前缀sh4-linux-
CROSS_COMPILE = sh4-linux-
endif
ifeq ($(ARCH),sparc)  //如果开发板的架构为sparc时,定义前缀sparc-elf-
CROSS_COMPILE = sparc-elf-
endif	# sparc
endif	# HOSTARCH,ARCH
endif	# CROSS_COMPILE

export	CROSS_COMPILE  //导出环境变量CROSS_COMPILE

# load other configuration下载其他配置文件
include $(TOPDIR)/config.mk

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

2.4.4、uboot主Makefile分析4

2.4.4.1、$(TOPDIR)/config.mk(主Makefile的185行)

//如果没有创建成功,就执行error函数,输出信息output directory "$(saved-output)" does not exist),
//然后编译终止
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)

//如果BUILD_DIR不为空,目标目录就等于BUILD_DIR;倘若没定义,就取为当前目录
OBJTREE		:= $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE		:= $(CURDIR)   //源文件目录等于当前文件夹
TOPDIR		:= $(SRCTREE)  //顶层目录等于源文件目录
LNDIR		:= $(OBJTREE)  //连接目录等于BUILD_DIR
export	TOPDIR SRCTREE OBJTREE //将这三个变量导出


# load other configuration下载其他配置文件
include $(TOPDIR)/config.mk    //TOPDIR顶层目录就是源文件目录

2.4.4.2、编译工具定义(config.mk 94-107行)

2.4.4.3、包含开发板配置项目(config.mk, 112行)

在这里插入图片描述

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

# Load generated board configuration
sinclude $(OBJTREE)/include/autoconf.mk

ifdef	ARCH
sinclude $(TOPDIR)/$(ARCH)_config.mk	# include architecture dependend rules
endif
ifdef	CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk	# include  CPU	specific rules
endif
ifdef	SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk	# include  SoC	specific rules
endif
ifdef	VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef	BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk	# include board specific rules
endif

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

2.4.5、uboot主Makefile分析5

2.4.5.1、链接脚本(config.mk 142-149行)

在这里插入图片描述

ifndef LDSCRIPT                 //如果没有定义LDSCRIPT
#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
ifeq ($(CONFIG_NAND_U_BOOT),y)  //如果定义了CONFIG_NAND_U_BOOT宏,链接脚本叫u-boot-nand.lds
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
else                            //如果没有定义CONFIG_NAND_U_BOOT宏,链接脚本叫u-boot.lds
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
endif
endif

2.4.5.2、TEXT_BASE(config.mk 156-158行)

在这里插入图片描述

ifneq ($(TEXT_BASE),)    //如果TEXT_BASE宏不为空的话
CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
endif

x210_sd_config :	unconfig    
	@$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
	@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk

2.4.5.3、自动推导规则(config.mk 239-256行)

在这里插入图片描述

#########################################################################
//自动推导规则
ifndef REMOTE_BUILD

%.s:	%.S
	$(CPP) $(AFLAGS) -o $@ $<      $@规则的目标文件名
%.o:	%.S
	$(CC) $(AFLAGS) -c -o $@ $<    $<规则的依赖文件名
%.o:	%.c
	$(CC) $(CFLAGS) -c -o $@ $<

else

$(obj)%.s:	%.S
	$(CPP) $(AFLAGS) -o $@ $<
$(obj)%.o:	%.S
	$(CC) $(AFLAGS) -c -o $@ $<
$(obj)%.o:	%.c
	$(CC) $(CFLAGS) -c -o $@ $<
endif

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

2.4.6、uboot主Makefile分析6

在这里插入图片描述

//all:目标(默认目标);$(ALL):依赖
all:		$(ALL)

$(obj)u-boot.hex:	$(obj)u-boot
		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@

$(obj)u-boot.srec:	$(obj)u-boot
		$(OBJCOPY) ${OBJCFLAGS} -O srec $< $@

$(obj)u-boot.bin:	$(obj)u-boot
		$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@

$(obj)u-boot.ldr:	$(obj)u-boot
		$(LDR) -T $(CONFIG_BFIN_CPU) -f -c $@ $< $(LDR_FLAGS)

$(obj)u-boot.ldr.hex:	$(obj)u-boot.ldr
		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary

$(obj)u-boot.ldr.srec:	$(obj)u-boot.ldr
		$(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ -I binary

$(obj)u-boot.img:	$(obj)u-boot.bin
		./tools/mkimage -A $(ARCH) -T firmware -C none \
		-a $(TEXT_BASE) -e 0 \
		-n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
			sed -e 's/"[	 ]*$$/ for $(BOARD) board"/') \
		-d $< $@

$(obj)u-boot.sha1:	$(obj)u-boot.bin
		$(obj)tools/ubsha1 $(obj)u-boot.bin

$(obj)u-boot.dis:	$(obj)u-boot
		$(OBJDUMP) -d $< > $@

$(obj)u-boot:		depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
		UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
		sed  -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
		cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
			--start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
			-Map u-boot.map -o u-boot

$(OBJS):	depend $(obj)include/autoconf.mk
		$(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))

$(LIBS):	depend $(obj)include/autoconf.mk
		$(MAKE) -C $(dir $(subst $(obj),,$@))

$(LIBBOARD):	depend $(LIBS) $(obj)include/autoconf.mk
		$(MAKE) -C $(dir $(subst $(obj),,$@))

$(SUBDIRS):	depend $(obj)include/autoconf.mk
		$(MAKE) -C $@ all

$(LDSCRIPT):	depend $(obj)include/autoconf.mk
		$(MAKE) -C $(dir $@) $(notdir $@)

$(NAND_SPL):	$(VERSION_FILE)	$(obj)include/autoconf.mk
		$(MAKE) -C nand_spl/board/$(BOARDDIR) all

$(U_BOOT_NAND):	$(NAND_SPL) $(obj)u-boot.bin $(obj)include/autoconf.mk
		cat $(obj)nand_spl/u-boot-spl-16k.bin $(obj)u-boot.bin > $(obj)u-boot-nand.bin

#$(ONENAND_IPL):	$(VERSION_FILE)	$(obj)include/autoconf.mk
#		$(MAKE) -C onenand_ipl/board/$(BOARDDIR) all
#
#$(U_BOOT_ONENAND):	$(ONENAND_IPL) $(obj)u-boot.bin $(obj)include/autoconf.mk
#		cat $(obj)onenand_ipl/onenand-ipl-2k.bin $(obj)u-boot.bin > $(obj)u-boot-onenand.bin
#		cat $(obj)onenand_ipl/onenand-ipl-4k.bin $(obj)u-boot.bin > $(obj)u-boot-flexonenand.bin

$(ONENAND_IPL):	$(VERSION_FILE)	$(obj)include/autoconf.mk
		$(MAKE) -C $(obj)onenand_bl1/$(BOARD) all

$(U_BOOT_ONENAND):	$(ONENAND_IPL) $(obj)u-boot.bin $(obj)include/autoconf.mk
		cat $(obj)onenand_bl1/$(BOARD)/BL1.bin.padding $(obj)u-boot.bin > $(U_BOOT_ONENAND)

$(VERSION_FILE):
		@( printf '#define U_BOOT_VERSION "U-Boot %s%s"\n' "$(U_BOOT_VERSION)" \
		 '$(shell $(CONFIG_SHELL) $(TOPDIR)/tools/setlocalversion $(TOPDIR))' \
		 ) > $@.tmp
		@cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@

在这里插入图片描述

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 \
		$(obj)board/$(VENDOR)/$(BOARD)/config.mk

在这里插入图片描述

x210_sd_config :	unconfig
	@$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
	@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk
	//echo指令创建爱你文件和追加输入文件
    //注意:一个大于号是创建文件;两个大于号是追加内容

2.4.7、uboot配置过程详解1

在这里插入图片描述

smdkv210single_rev02_config :	unconfig
	@$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
	@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk

#!/bin/sh -e

# Script to create header files and links to configure
# U-Boot for a specific board.
# 创建头文件和链接的脚本,为特定的主板配置U-Boot。
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
# 参数:目标 架构 CPU[供应商] [SOC]
# (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <wd@denx.de>
#

APPEND=no	# Default: Create new config file;默认:创建新的配置文件
BOARD_NAME=""	# Name to print in make output;输出时要打印的名称

//@$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
//$#:表示调用该shenll时传参的个数,$#=6
//-gt:大于
//$1:X210_sd
while [ $# -gt 0 ] ; do
	case "$1" in
	--) shift ; break ;;
	-a) shift ; APPEND=yes ;;
	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
	*)  break ;;              //*:万能匹配符,break跳出死循环
	esac
done

在这里插入图片描述

[ "${BOARD_NAME}" ] || BOARD_NAME="$1"  //此时${BOARD_NAME}为空,则BOARD_NAME=x210_sd

在这里插入图片描述

[ $# -lt 4 ] && exit 1     //[ $# -lt 4 ]为假,不执行
[ $# -gt 6 ] && exit 1     //[ $# -gt 6 ]为假,不执行,所以传递参数的值只能为4,5,6
echo "Configuring for ${BOARD_NAME} board..."  //打印出Configuring for ${BOARD_NAME} board...

在这里插入图片描述
在这里插入图片描述

# 创建到架构特定标题的链接
//第一个:在include目录下创建asm文件,指向asm-arm。(46-48行)
if [ "$SRCTREE" != "$OBJTREE" ] ; then    //如果不是本地编译的话
	mkdir -p ${OBJTREE}/include
	mkdir -p ${OBJTREE}/include2
	cd ${OBJTREE}/include2
	rm -f asm
	ln -s ${SRCTREE}/include/asm-$2 asm
	LNPREFIX="../../include2/asm/"
	cd ../include
	rm -rf asm-$2
	rm -f asm
	mkdir asm-$2
	ln -s asm-$2 asm
else                            //如果是本地编译的话
	cd ./include                //进入当前目录的include目录
	rm -f asm                   //将asm文件删掉
	ln -s asm-$2 asm            //为asm-$2创建符号链接,名字叫asm
fi
rm -f asm-$2/arch               //删掉asm-$2下面的arch目录
//$6:s5pc110   $3:arm
if [ -z "$6" -o "$6" = "NULL" ] ; then     //如果$6不为空或者不为NULL的话
	ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
	ln -s ${LNPREFIX}arch-$6 asm-$2/arch   //为${LNPREFIX}arch-$6创建符号链接,名字叫asm-$2/arch
fi
//第二个:在inlcude/asm-arm下创建一个arch文件,指向include/asm-arm/arch-s5pc110
//第三个:在include目录下创建regs.h文件,指向include/s5pc110.h
删除第二个。
# create link for s5pc11x SoC
# s5pc11x SoC创建符号链接,此时在include中
if [ "$3" = "s5pc11x" ] ; then   
        rm -f regs.h              //删除regs.h文件
        ln -s $6.h regs.h         //为s5pc110.h创建符号链接,名字叫regs.h
        rm -f asm-$2/arch         //删除asm-arm/arch 
        ln -s arch-$3 asm-$2/arch //为arch-s5pc11x创建符号链接,名字叫asm-arm/arch
fi
if [ "$2" = "arm" ] ; then         //第五个
	rm -f asm-$2/proc              //删除asm-$2/proc
	ln -s ${LNPREFIX}proc-armv asm-$2/proc
fi

2.4.8、uboot配置过程详解2

在这里插入图片描述

#
# Create include file for Make
# 为make创建头文件
echo "ARCH   = $2" >  config.mk
echo "CPU    = $3" >> config.mk
echo "BOARD  = $4" >> config.mk

[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk

[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk

在这里插入图片描述

//这个ifeq横跨的范围非常广,用红色加粗字体表明。只有$(OBJTREE)/include/config.mk存在
//(也就是说已经执行了make *.config)的情况下,这部分包含的内容才有效
ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk))

# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk   //将make *_config生成的config.mk文件包含进来
export	ARCH CPU BOARD VENDOR SOC //导出5个变量以供其他子目录的makefile调用

在这里插入图片描述
在这里插入图片描述

APPEND=no	# Default: Create new config file默认:创建新的配置文件
BOARD_NAME=""	# Name to print in make output输出时要打印的名称

//$#:表示调用该shenll时传参的个数,$#=6
//@$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
while [ $# -gt 0 ] ; do
	case "$1" in
	--) shift ; break ;;
	-a) shift ; APPEND=yes ;;
	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
	*)  break ;;              //*:万能匹配符,break跳出死循环
	esac
done

.......

# Create board specific header file
# 创建board指定的头文件
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
echo "#include <configs/$1.h>" >>config.h

exit 0       //正常结束

2.4.9、uboot的链接脚本

在这里插入图片描述

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")  //输出格式
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/  //注释
OUTPUT_ARCH(arm)  //输出架构
ENTRY(_start)     //用来指定整个程序的入口地址
SECTIONS
{
	. = 0x00000000;                            //指定地址

	. = ALIGN(4);                              //4字节对齐
	.text      :                               //代码段
	{
	  cpu/s5pc11x/start.o	(.text)
	  cpu/s5pc11x/s5pc110/cpu_init.o	(.text)
	  board/samsung/x210/lowlevel_init.o	(.text)
          cpu/s5pc11x/onenand_cp.o      (.text)                 
          cpu/s5pc11x/nand_cp.o (.text)                     
          cpu/s5pc11x/movi.o (.text) 
          common/secure_boot.o (.text) 
	  common/ace_sha1.o (.text)
	  cpu/s5pc11x/pmic.o (.text)
	  *(.text)
	}

	. = ALIGN(4);
	.rodata : { *(.rodata) }      	  /只读数据段

	. = ALIGN(4);
	.data : { *(.data) }

	. = ALIGN(4);
	.got : { *(.got) }                //自定义数据段段

	__u_boot_cmd_start = .;
	.u_boot_cmd : { *(.u_boot_cmd) }  //自定义数据段段
	__u_boot_cmd_end = .;

	. = ALIGN(4);
	.mmudata : { *(.mmudata) }        //自定义数据段段

	. = ALIGN(4);
	__bss_start = .;
	.bss : { *(.bss) }
	_end = .;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值