太----->木------->本-------->杰-------->太
万能的主啊,为什么创造汉字? 这让我想到了打飞机~~~ 诶~~我邪恶了
VERSION = 2010
PATCHLEVEL = 03
SUBLEVEL =
EXTRAVERSION =
ifneq "$(SUBLEVEL)" ""
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
else
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL)$(EXTRAVERSION)
endif
TIMESTAMP_FILE = $(obj)include/timestamp_autogenerated.h
VERSION_FILE = $(obj)include/version_autogenerated.h
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/')
# Set shell to bash if possible, otherwise fall back to sh
SHELL := $(shell if [ -x "$BASH" ]; then echo $BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi; fi)
export HOSTARCH HOSTOS SHELL
VERSION,PATCHLEVEL等都是变量。
HOSTARCH这个变量的赋值,是通过执行一套shell程序来完成的,其中$(shell xxx)的语法就是在shell中执行xxx的命令。这里的|就是linux中的管道处理符,/就是换行的连接符,表示下一行与本行是同行程序处理。
uname -m,就是得到machine hardware name,中文翻译成机器硬件名?!
sed -e的意思,就是表示后面跟的是一串命令脚本,s/abc/def/的命令表达式,就是表示要从标准输入中,查找到内容为abc的,然后替换成def。这样执行这一套程序下来,就知道了机器的硬件体系了。
uname -s,得到kernel name,内核的名字。
tr '[:upper:]' '[:lower:]',表示从标准输入里,把大字都换成小写,然后输出到标准输出。
然后后面再跟了一串用来特别处理cygwin环境下编译的环境变量的配置的。
知识: 当$( .... .... )的形式,如果括号内部是变量,那么就是执行前面的这一条命令。
#########################################################################
#
# U-boot build supports producing a object files to the separate external
# directory. Two use cases are supported:
#
# 1) Add O= to the make command line
# 'make O=/tmp/build all'
#
# 2) Set environement variable BUILD_DIR to point to the desired location
# 'export BUILD_DIR=/tmp/build'
# 'make'
#
# The second approach can also be used with a MAKEALL script
# 'export BUILD_DIR=/tmp/build'
# './MAKEALL'
#
# Command line 'O=' setting overrides BUILD_DIR environent variable.
#
# When none of the above methods is used the local build is performed and
# the object files are placed in the source directory.
#
ifdef O
ifeq ("$(origin O)", "command line")
BUILD_DIR := $(O)
endif
endif
#origin查看O的来源,如果是命令行输入O则赋值给BUILD_DIR。如:make O=....
ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)
# Attempt to create a output directory.
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})
#判断BUILD_DIR目录是否存在,不存在建立他
# Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)
OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) #if(a,b,c)表示如果a为真,a=b,如果为假a=c
SRCTREE := $(CURDIR)
TOPDIR := $(SRCTREE)
LNDIR := $(OBJTREE)
export TOPDIR SRCTREE OBJTREE
MKCONFIG := $(SRCTREE)/mkconfig
export MKCONFIG
ifneq ($(OBJTREE),$(SRCTREE))
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.
ifneq ($(OBJTREE),$(SRCTREE))
obj := $(OBJTREE)/
src := $(SRCTREE)/
else
obj :=
src :=
endif
export obj src
# Make sure CDPATH settings don't interfere
unexport CDPATH
对目录进行赋值操作。
知识点:origin函数用法, if(a,b,c)
#########################################################################
ifeq ($(ARCH),powerpc)
ARCH = ppc
endif
# The "tools" are needed early, so put this first
# Don't include stuff already done in $(LIBS)
SUBDIRS = tools \
examples/standalone \
examples/api
.PHONY : $(SUBDIRS)
ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk)) #这个语句就是判断是否执行过make xxx_config,看config.mk是否生成,如果条件不如何就会执行报错。
# Include autoconf.mk before config.mk so that the config options are available
# to all top level build files. We need the dummy all: target to prevent the
# dependency target in autoconf.mk.dep from being the default.
all:
sinclude $(obj)include/autoconf.mk.dep #sinclude和-include是一样的,如果后面的文件不存在,也不会报错。
sinclude $(obj)include/autoconf.mk #这两个文件的生成下面 介绍
# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk #config.mk就是前面介绍的 make xx_config的命令生成的。
export ARCH CPU BOARD VENDOR SOC
//CROSS_COMPILE = arm-tekkaman-linux-gnueabi-
CROSS_COMPILE = arm-linux-
# set default to nothing for native builds
ifeq ($(HOSTARCH),$(ARCH))
CROSS_COMPILE ?=
endif
# load other configuration
include $(TOPDIR)/config.mk
.phony 用法 http://www.cnblogs.com/hongzg1982/articles/2169348.html 有个介绍
autoconf.mk和autoconf.mk.dep文件的产生
#
# Auto-generate the autoconf.mk file (which is included by all makefiles)
#
# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
# the dep file is only include in this top level makefile to determine when
# to regenerate the autoconf.mk file.
$(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h
@$(XECHO) Generating $@ ; \
set -e ; \
: Generate the dependancies ; \
$(CC) -x c -DDO_DEPS_ONLY -M $(HOSTCFLAGS) $(CPPFLAGS) \
-MQ $(obj)include/autoconf.mk include/common.h > $@
$(obj)include/autoconf.mk: $(obj)include/config.h
@$(XECHO) Generating $@ ; \
set -e ; \
: Extract the config macros ; \
$(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
sed -n -f tools/scripts/define2mk.sed > [email protected] && \
mv [email protected] $@
将common.h中的所有#include 的h文件并且h文件中的include文件 都放到autoconf.mk.dep中。
将common.h中的所有的#define 变量,和h文件中的#define变量,都放到autoconf.mk中。
tools/scripts/define2mk.sed是一个script,基本上用的是前面说的 s命令,进行字符的替换。
这里具体的gcc编译选项 可以在http://www.doc88.com/p-91267749405.html这里找。
继续顺着刚才的程序向下:
#########################################################################
# U-Boot objects....order is important (i.e. start must be first)
OBJS = cpu/$(CPU)/start.o
ifeq ($(CPU),i386)
OBJS += cpu/$(CPU)/start16.o
OBJS += cpu/$(CPU)/resetvec.o
endif
ifeq ($(CPU),ppc4xx)
OBJS += cpu/$(CPU)/resetvec.o
endif
ifeq ($(CPU),mpc85xx)
OBJS += cpu/$(CPU)/resetvec.o
endif
OBJS := $(addprefix $(obj),$(OBJS)) #addprefix是将 obj放到OBJS的前面,其实就是将所有的文件 加上 路径名
LIBS = lib_generic/libgeneric.a
LIBS += lib_generic/lzma/liblzma.a
LIBS += lib_generic/lzo/liblzo.a
LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \
"board/$(VENDOR)/common/lib$(VENDOR).a"; fi)
LIBS += cpu/$(CPU)/lib$(CPU).a
ifdef SOC
LIBS += cpu/$(CPU)/$(SOC)/lib$(SOC).a
endif
ifeq ($(CPU),ixp)
LIBS += cpu/ixp/npe/libnpe.a
endif
LIBS += lib_$(ARCH)/lib$(ARCH).a
LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a \
fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a \
fs/ubifs/libubifs.a
LIBS += net/libnet.a
LIBS += disk/libdisk.a
LIBS += drivers/bios_emulator/libatibiosemu.a
LIBS += drivers/block/libblock.a
LIBS += drivers/dma/libdma.a
LIBS += drivers/fpga/libfpga.a
。。。。。。
制定编译规则,uboot是将文件都做成.a库的方式再进行连接的。
制定编译个规则了:
#########################################################################
# Always append ALL so that arch config.mk's can add custom ones
ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND)
all: $(ALL)
$(obj)u-boot.hex: $(obj)u-boot
$(OBJCOPY) ${OBJCFLAGS} -O ihex {1}lt; $@
$(obj)u-boot.srec: $(obj)u-boot
$(OBJCOPY) -O srec {1}lt; $@
$(obj)u-boot.bin: $(obj)u-boot
$(OBJCOPY) ${OBJCFLAGS} -O binary {1}lt; $@
$(obj)u-boot.ldr: $(obj)u-boot
$(CREATE_LDR_ENV)
$(LDR) -T $(CONFIG_BFIN_CPU) -c $@ {1}lt; $(LDR_FLAGS)
$(obj)u-boot.ldr.hex: $(obj)u-boot.ldr
$(OBJCOPY) ${OBJCFLAGS} -O ihex {1}lt; $@ -I binary
$(obj)u-boot.ldr.srec: $(obj)u-boot.ldr
$(OBJCOPY) ${OBJCFLAGS} -O srec {1}lt; $@ -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 {1}lt; $@
$(obj)u-boot.imx: $(obj)u-boot.bin
$(obj)tools/mkimage -n $(IMX_CONFIG) -T imximage \
-e $(TEXT_BASE) -d {1}lt; $@
$(obj)u-boot.kwb: $(obj)u-boot.bin
$(obj)tools/mkimage -n $(KWD_CONFIG) -T kwbimage \
-a $(TEXT_BASE) -e $(TEXT_BASE) -d {1}lt; $@
$(obj)u-boot.sha1: $(obj)u-boot.bin
$(obj)tools/ubsha1 $(obj)u-boot.bin
$(obj)u-boot.dis: $(obj)u-boot
$(OBJDUMP) -d {1}lt; > $@
GEN_UBOOT = \
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
$(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
$(GEN_UBOOT)
ifeq ($(CONFIG_KALLSYMS),y)
smap=`$(call SYSTEM_MAP,u-boot) | \
awk '$2 ~ /[tTwW]/ {printf $1 $3 "\\\\000"}'` ; \
$(CC) $(CFLAGS) -DSYSTEM_MAP="\"${smap}\"" \
-c common/system_map.c -o $(obj)common/system_map.o
$(GEN_UBOOT) $(obj)common/system_map.o
endif
从主要的u-boot来入手分析:
$(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
$(GEN_UBOOT)
ifeq ($(CONFIG_KALLSYMS),y)
smap=`$(call SYSTEM_MAP,u-boot) | \
awk '$2 ~ /[tTwW]/ {printf $1 $3 "\\\\000"}'` ; \
$(CC) $(CFLAGS) -DSYSTEM_MAP="\"${smap}\"" \
-c common/system_map.c -o $(obj)common/system_map.o
$(GEN_UBOOT) $(obj)common/system_map.o
endif
u-boot依赖的depend
# Explicitly make _depend in subdirs containing multiple targets to prevent
# parallel sub-makes creating .depend files simultaneously.
depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk
for dir in $(SUBDIRS) cpu/$(CPU) $(dir $(LDSCRIPT)) ; do \
$(MAKE) -C $dir _depend ; done
就是到这几个目录里面运行make _depend
u-boot依赖的SUBDIRS
SUBDIRS = tools \
examples/standalone \
examples/api
.PHONY : $(SUBDIRS)
$(SUBDIRS): depend
$(MAKE) -C $@ all
其实就是到SUBDIRS的目录下,运行make all命令。 那么,我们去那个不为人知的地方看看。
看了看,诶~~~~太美了·~~~我们来世再见吧。
u-boot依赖的OBJS
OBJS = cpu/$(CPU)/start.o
ifeq ($(CPU),i386)
OBJS += cpu/$(CPU)/start16.o
OBJS += cpu/$(CPU)/resetvec.o
endif
ifeq ($(CPU),ppc4xx)
OBJS += cpu/$(CPU)/resetvec.o
endif
ifeq ($(CPU),mpc85xx)
OBJS += cpu/$(CPU)/resetvec.o
endif
OBJS := $(addprefix $(obj),$(OBJS))
$(OBJS): depend
$(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
就是在cpu/arm920t下运行make,生成libarm920t.a。
另外该目录下makefile里面有句这样的话: $(START:.o=.S) $(SOBJS:.o=.S) $(COBJS-y:.o=.c) 意思应该是: START 变量依赖的.o 文件的源文件是 .s,COBJS-y 依赖的.o文件源文件是.c,应该是这样的
另外在该目录下运行make,由于依赖关系,也会生成.depend 文件。 这就是刚才依赖的 depend动作并没到这个目录下运行make _depend,而在这个目录下也会生成.depend文件的原因。
大概看了一下,后面意思都差不多,进去目录下 make, 后面几个LDSCRIPT是连接脚本,在cpu/arm920t目录下,然后根据u-boot.lds的这个依赖,进行生成连接。
最后用GEN_UBOOT这个鸟东西根据lds文件,生成uboot和uboot.map。
好了到这就算齐活了吧。越写越不瞌睡,其实大部分都是网上cpy的,对不起那些原创了!