|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-7-17 16:46:40
|
显示全部楼层
本帖最后由 Garbage614 于 2012-7-17 18:31 编辑
/config.mk- #########################################################################
- ifneq ($(OBJTREE),$(SRCTREE)) #相同,执行第二个else
- ifeq ($(CURDIR),$(SRCTREE))
- dir :=
- else
- dir := $(subst $(SRCTREE)/,,$(CURDIR))
- #dir := /
- #$(subst <from>,<to>,<text>)
- #名称:字符串替换函数——subst。
- #功能:把字串<text>中的<from>字符串替换成<to>。
- #返回:函数返回被替换过后的字符串。
-
- endif
- obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
- src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
- $(shell mkdir -p $(obj))
- else
- obj :=
- src :=
- endif
- #目标输出到源代码目录下,因此执行完上面的代码后,src和obj都是空
- # clean the slate ...
- #设置编译选项,后边会添加
- PLATFORM_RELFLAGS =
- PLATFORM_CPPFLAGS =
- PLATFORM_LDFLAGS =
- #
- # When cross-compiling on NetBSD, we have to define __PPC__ or else we
- # will pick up a va_list declaration that is incompatible with the
- # actual argument lists emitted by the compiler.
- #
- # [Tested on NetBSD/i386 1.5 + cross-powerpc-netbsd-1.3]
- ifeq ($(ARCH),ppc)
- ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
- PLATFORM_CPPFLAGS+= -D__PPC__
- endif
- ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
- PLATFORM_CPPFLAGS+= -D__PPC__
- endif
- endif
- ifeq ($(ARCH),arm)
- ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
- PLATFORM_CPPFLAGS+= -D__ARM__
- endif
- ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
- PLATFORM_CPPFLAGS+= -D__ARM__
- endif
- endif
- ifeq ($(ARCH),blackfin)
- PLATFORM_CPPFLAGS+= -D__BLACKFIN__ -mno-underscore
- endif
- #不满足条件 PLATFORM_CPPFLAGS =
- #include开发板相关配置文件
- ifdef ARCH
- sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
- #/arm_config.mk,设置构架相关的编译选项。
- #只有一行:PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__
- #sinclude 无论include过程中出现什么错误,都不要报错继续执行
- endif
- ifdef CPU
- sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
- #cpu/arm920t/config.mk,设置处理器(arm920t)相关的编译选项。
- endif
- ifdef SOC
- sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
- #cpu/arm920t/s3c24x0/config.mk,该文件不存在
- endif
- ifdef VENDOR #VENDOR为空,执行else
- BOARDDIR = $(VENDOR)/$(BOARD)
- else
- BOARDDIR = $(BOARD)
- #BOARDDIR = smdk2410
- endif
- ifdef BOARD
- sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
- #board/smdk2410/config.mk,
- #只有一行:TEXT_BASE = 0x33F80000,指定代码段起始地址
- endif
- #########################################################################
- #shell
- CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
- else if [ -x /bin/bash ]; then echo /bin/bash; \
- else echo sh; fi ; fi)
- ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
- HOSTCC = cc
- else
- HOSTCC = gcc
- #主机编译器
- endif
- HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
- HOSTSTRIP = strip
- #主机编译选项
- #########################################################################
- #
- # Option checker (courtesy linux kernel) to ensure
- # only supported compiler options are used
- #
- cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
- > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
- #cc-option用于检查编译器CC是否支持某选项。将2个选项作为参数传递给cc-option函数
- #该函数调用CC编译器检查参数1是否支持,若支持则函数返回参数1,否则返回参数2
- #因此CC编译器必须支持参数1或参数2,若两个都不支持则会编译出错
- #
- # Include the make variables (CC, etc...)
- #
- AS = $(CROSS_COMPILE)as
- LD = $(CROSS_COMPILE)ld
- CC = $(CROSS_COMPILE)gcc
- CPP = $(CC) -E
- AR = $(CROSS_COMPILE)ar
- NM = $(CROSS_COMPILE)nm
- STRIP = $(CROSS_COMPILE)strip
- OBJCOPY = $(CROSS_COMPILE)objcopy
- OBJDUMP = $(CROSS_COMPILE)objdump
- RANLIB = $(CROSS_COMPILE)RANLIB
- #指定交叉编译链接工具,$(CROSS_COMPILE)在Makefile定义为arm-linux
- ifneq (,$(findstring s,$(MAKEFLAGS)))
- #如果能从$(MAKEFLAGS)中找到字符s
- ARFLAGS = cr
- else
- ARFLAGS = crv
- endif
- RELFLAGS= $(PLATFORM_RELFLAGS)
- DBGFLAGS= -g # -DDEBUG
- OPTFLAGS= -Os #-fomit-frame-pointer
- ifndef LDSCRIPT
- #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
- #定义链接文件
- ifeq ($(CONFIG_NAND_U_BOOT),y)
- LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
- else
- LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
- endif
- endif
- #编译、链接、调试等选项
- OBJCFLAGS += --gap-fill=0xff
- gccincdir := $(shell $(CC) -print-file-name=include)
- CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
- -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \
- ifneq ($(OBJTREE),$(SRCTREE))
- CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
- endif
- CPPFLAGS += -I$(TOPDIR)/include
- CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
- -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
- ifdef BUILD_TAG
- CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
- -DBUILD_TAG='"$(BUILD_TAG)"'
- else
- CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
- endif
- # avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9)
- # this option have to be placed behind -Wall -- that's why it is here
- ifeq ($(ARCH),nios)
- ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9)
- CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs
- endif
- endif
- # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
- # option to the assembler.
- AFLAGS_DEBUG :=
- # turn jbsr into jsr for m68k
- ifeq ($(ARCH),m68k)
- ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
- AFLAGS_DEBUG := -Wa,-gstabs,-S
- endif
- endif
- AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
- LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
- # Location of a usable BFD library, where we define "usable" as
- # "built for ${HOST}, supports ${TARGET}". Sensible values are
- # - When cross-compiling: the root of the cross-environment
- # - Linux/ppc (native): /usr
- # - NetBSD/ppc (native): you lose ... (must extract these from the
- # binutils build directory, plus the native and U-Boot include
- # files don't like each other)
- #
- # So far, this is used only by tools/gdb/Makefile.
- ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
- BFD_ROOT_DIR = /usr/local/tools
- else
- ifeq ($(HOSTARCH),$(ARCH))
- # native
- BFD_ROOT_DIR = /usr
- else
- #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
- #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
- BFD_ROOT_DIR = /opt/powerpc
- endif
- endif
- ifeq ($(PCI_CLOCK),PCI_66M)
- CFLAGS := $(CFLAGS) -DPCI_66M
- endif
- #########################################################################
- export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
- AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
- MAKE
- export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
- #########################################################################
- #定义编译规则
- 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
- #########################################################################
- #——————————————————>转到顶层makefile中\
- ## U-Boot objects....order is important (i.e. start must be first)
复制代码 1)定义了交叉编译、链接等工具
2)定义了编译、优化、链接等选项,其中包括链接脚本LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds,代码段起始地址TEXT_BASE = 0x33F80000
3)定义了编译规则
附:uboot存储使用图
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|