1. 程式人生 > >最近看Omapl138UBOOT主Makefile的一些整理

最近看Omapl138UBOOT主Makefile的一些整理

如下:

VERSION = 2012

PATCHLEVEL = 04

SUBLEVEL = 01

EXTRAVERSION =

ifneq “$(SUBLEVEL)” “”

U_BOOT_VERSION =
$ (VERSION).$ (PATCHLEVEL).$ (SUBLEVEL)$(EXTRAVERSION)

else

U_BOOT_VERSION =
$ (VERSION).$ (PATCHLEVEL)$(EXTRAVERSION)

endif

TIMESTAMP_FILE =
$(obj)include/generated/timestamp_autogenerated.h

VERSION_FILE =
$(obj)include/generated/version_autogenerated.h

變數名 含義
U_BOOT_VERSION 2012.04.01
TIMESTAMP_FILE include/generated/timestamp_autogenerated.h
VERSION_FILE include/generated/version_autogenerated.h


HOSTARCH := $(shell uname -m | \

       sed
-e s/i.86/x86/ \

           -e s/sun4u/sparc64/ \

           -e s/arm.*/arm/ \

           -e s/sa110/arm/ \

           -e s/ppc64/powerpc/ \

           -e s/ppc/powerpc/ \

           -e s/macppc/powerpc/\

           -e s/sh.*/sh/)


HOSTOS := $(shell uname -s | tr '[:upper:]'
'[:lower:]' | \

           sed -e 's/\(cygwin\).*/cygwin/')





    “sed
–e”表示後面跟的是一串命令指令碼,而表示式“s/abc/def/”表示要從標準輸入中,查詢到內容為“abc”的,然後替換成“def”。其中“abc”表示式用可以使用“.”作為萬用字元。

       命令“uname –m”將輸出主機CPU的體系架構型別。作者的電腦使用Intel Core2系列的CPU,因此“uname –m”輸出“i686”。 “i686”可以匹配命令“sed -e
s/i.86/x86/”中的“i.86”,因此在作者的機器上執行Makefile,HOSTARCH將被設定成“x86” 。

“uname
–s”輸出主機核心名字,作者使用Linux發行版Ubuntu10.04,因此“uname –s”結果是“Linux”。“tr
'[:upper:]' '[:lower:]'”作用是將標準輸入中的所有大寫字母轉換為響應的小寫字母。因此執行結果是將HOSTOS 設定為“linux”。




# 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

 

# Deal with colliding definitions from tcsh
etc.

VENDOR=

 

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

# Allow for silent builds

ifeq (,$(findstring s,$(MAKEFLAGS)))

XECHO = echo

else

XECHO = :

endif

#因為沒有定義MAKEFLAGS,所以XECHO=echo

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

#

# 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

 

ifneq ($(BUILD_DIR),)

saved-output := $(BUILD_DIR)

 

# Attempt to create a output directory.

$(shell [ -d ${BUILD_DIR} ] || mkdir -p
${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))

SPLTREE        :=
$(OBJTREE)/spl

SRCTREE        :=
$(CURDIR)

TOPDIR         :=
$(SRCTREE)

LNDIR            :=
$(OBJTREE)

export    TOPDIR
SRCTREE OBJTREE SPLTREE

 

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


   CURDIR變數指示Make當前的工作目錄,由於當前Make在U-Boot頂層目錄執行Makefile,因此CURDIR此時就是U-Boot頂層目錄。

   執行完上面的程式碼後, SRCTREE,src變數就是U-Boot程式碼頂層目錄,而OBJTREE,obj變數就是輸出目錄,若沒有定義BUILD_DIR環境變數,則SRCTREE,src變數與OBJTREE,obj變數都是U-Boot原始碼目錄。而MKCONFIG則表示U-Boot根目錄下的mkconfig指令碼。
變數 含義
OBJTREE Omapl138/uboot
SPLTREE Omapl138/uboot/spl
SRCTREE Omapl138/uboot
TOPDIR Omapl138/uboot
LNDDIR Omapl138/uboot
src Omapl138/uboot
obj Omapl138/uboot
MKCONFIG Omapl138/uboot/mkconfig


# Make sure CDPATH settings don't interfere

unexport
CDPATH

 

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

 

# The "tools" are needed early,
so put this first

# Don't include stuff already done in
$(LIBS)

# The "examples" conditionally
depend on U-Boot (say, when USE_PRIVATE_LIBGCC

# is "yes"), so compile examples
after U-Boot is compiled.

SUBDIR_TOOLS = tools

SUBDIR_EXAMPLES = examples/standalone
examples/api

SUBDIRS = $(SUBDIR_TOOLS)

 

.PHONY : $(SUBDIRS) $(VERSION_FILE)
$(TIMESTAMP_FILE)

 

ifeq ($(obj)include/config.mk,$(wildcard
$(obj)include/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 $(obj)include/autoconf.mk


當makefile中有兩個相同目標的時候,會執行後一個目標。因為後一個目標會過載前一個。如果你 執行make的時候沒有帶任何其他目標。單獨的一個make。可以避免以autoconf.mk.dep裡面的include/autoconf.mk作為錯誤目標。如果你執行make的時候帶了目標。這個all:有不有都無所謂。



ifndef CONFIG_SANDBOX

SUBDIRS += $(SUBDIR_EXAMPLES)

endif

 

# load ARCH, BOARD, and CPU configuration

include $(obj)include/config.mk

export    ARCH
CPU BOARD VENDOR SOC


#包含include/config.mk檔案,這個檔案是在makexxx_config過程中產生的



# set default to nothing for native builds

ifeq ($(HOSTARCH),$(ARCH))

CROSS_COMPILE ?=

endif


#HOSTARCH是x86的,目標是arm的,所以不執行

這個CROSS_COMPILE是通過命令列引入的,make CROSS_COMPILE=arm-none-linux-gnueabi-



# load other configuration

include $(TOPDIR)/config.mk


#包含Omapl138/uboot/mkconfig



# If board code explicitly specified
LDSCRIPT or CONFIG_SYS_LDSCRIPT, use

# that (or fail if absent).  Otherwise, search for a linker script in a

# standard location.

 

LDSCRIPT_MAKEFILE_DIR = $(dir $(LDSCRIPT))


#用等號賦值的變數是遞迴方式擴充套件的變數。變數定義時,變數值中對其他變數的引用不會被替換展開;

#而是變數在引用它的地方替換展開的同時,它所引用的其它變數才會被一同替換展開。

#其優點是:

#這種型別變數在定義時,可以引用其它的之前沒有定義的變數(可能在後續部分定義,或者是通過make的命令列選項傳遞的變數)。

#LDSCRIPT變數就是後面才定義的



ifndef LDSCRIPT

       #LDSCRIPT
:= $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug

       ifdef
CONFIG_SYS_LDSCRIPT

       #沒有定義

              #
need to strip off double quotes

              LDSCRIPT
:= $(subst ",,$(CONFIG_SYS_LDSCRIPT))

#如果定義了CONFIG_SYS_LDSCRIPT,將CONFIG_SYS_LDSCRIPT代表的字串去掉雙引號後賦值給LDSCRIPT變數

       endif

endif

 

# If there is no specified link script, we
look in a number of places for it

ifndef LDSCRIPT

       ifeq
($(CONFIG_NAND_U_BOOT),y)

              LDSCRIPT
:= $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds

              ifeq
($(wildcard $(LDSCRIPT)),)

                     LDSCRIPT
:= $(TOPDIR)/$(CPUDIR)/u-boot-nand.lds

              endif

       endif

       ifeq
($(wildcard $(LDSCRIPT)),)

              LDSCRIPT
:= $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds

       endif

       ifeq
($(wildcard $(LDSCRIPT)),)

              LDSCRIPT
:= $(TOPDIR)/$(CPUDIR)/u-boot.lds

       endif

       ifeq
($(wildcard $(LDSCRIPT)),)

              LDSCRIPT
:= $(TOPDIR)/arch/$(ARCH)/cpu/u-boot.lds

              #
We don't expect a Makefile here

              LDSCRIPT_MAKEFILE_DIR
=

       endif

       ifeq
($(wildcard $(LDSCRIPT)),)

$(error could not find linker script)

       endif

endif


在config.mk中有如下定義:

BOARDDIR =$ (VENDDOR)/$( BOARD)

CPUDIR=arch/$ (ARCH)/cpu/$(CPU)

ifneq
($ (SRCTREE)/$ (CPUDIR),$ (wildcard $ (SRCTREE)/$ (CPUDIR)))

CPUDIR= arch/$(ARCH)/cpu

結合boards.cfg中的定義:

變數名 定義
ARCH arm
CPU arm926ejs
BOARD name da8xxevm
Vendor davinci
SOC davinci

綜上:

BOARDDIR=davinci/da8xxevm/

CPUDIF=arch/arm/cpu/arm926ejs

#註釋寫的很明確,如果沒有用CONFIG_SYS_LDSCRIPT指定LDSCRIPT,那麼就在幾個地方搜

#第一個地方:如果CONFIG_NAND_U_BOOT是y,就用u-boot-nand.lds但是這裡沒有這個定義

#第一個地方沒找到,就找第二個地方:uboot/board/davinci /da8xxevm這個目錄沒有u-boot.lds檔案

#第二個地方沒找到,就找第三個地方:其中CPUDIR是在頂層的config.mk中定義的,在arch/arm/cpu/arm926ejs中找這個目錄也沒有

#第三個地方沒找到,就找第四個地方:arch/arm/cpu/u-boot.lds,這裡就找到了!!!!



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

# U-Boot objects....order is important
(i.e. start must be first)

 

OBJS 
= $(CPUDIR)/start.o

OBJS    =arch/arm/cpu/arm926ejs/start.o 

ifeq ($(CPU),x86)

OBJS += $(CPUDIR)/start16.o

OBJS += $(CPUDIR)/resetvec.o

endif

ifeq ($(CPU),ppc4xx)

OBJS += $(CPUDIR)/resetvec.o

endif

ifeq ($(CPU),mpc85xx)

OBJS += $(CPUDIR)/resetvec.o

endif

均不滿足

OBJS := $(addprefix $(obj),$(OBJS))

OBJS:=arch/arm/cpu/arm926ejs/start.o 

 

LIBS 
= lib/libgeneric.o

LIBS += lib/lzma/liblzma.o

LIBS += lib/lzo/liblzo.o

LIBS += lib/zlib/libz.o

LIBS += $(shell if [ -f
board/$(VENDOR)/common/Makefile ]; then echo \

       "board/$(VENDOR)/common/lib$(VENDOR).o";
fi)

#-f表示該檔案為常規檔案,經查該檔案不存在

LIBS += $(CPUDIR)/lib$(CPU).o

LIBS+= arch/arm/cpu/arm926ejs/libarm926ejs.o

ifdef SOC

LIBS += $(CPUDIR)/$(SOC)/lib$(SOC).o

LIBS+=
arch/arm/cpu/arm926ejs/davinci/libdavinci.o

endif

ifeq ($(CPU),ixp)

LIBS += arch/arm/cpu/ixp/npe/libnpe.o

endif

ifeq ($(CONFIG_OF_EMBED),y)

LIBS += dts/libdts.o

endif

LIBS += arch/$(ARCH)/lib/lib$(ARCH).o

LIBS+= arch/arm/libarm.o

LIBS += fs/cramfs/libcramfs.o
fs/fat/libfat.o fs/fdos/libfdos.o fs/jffs2/libjffs2.o \

       fs/reiserfs/libreiserfs.o
fs/ext2/libext2fs.o fs/yaffs2/libyaffs2.o \

       fs/ubifs/libubifs.o

LIBS += net/libnet.o

LIBS += disk/libdisk.o

LIBS +=
drivers/bios_emulator/libatibiosemu.o

LIBS += drivers/block/libblock.o

LIBS += drivers/dma/libdma.o

LIBS += drivers/fpga/libfpga.o

LIBS += drivers/gpio/libgpio.o

LIBS += drivers/hwmon/libhwmon.o

LIBS += drivers/i2c/libi2c.o

LIBS += drivers/input/libinput.o

LIBS += drivers/misc/libmisc.o

LIBS += drivers/mmc/libmmc.o

LIBS += drivers/mtd/libmtd.o

LIBS += drivers/mtd/nand/libnand.o

LIBS += drivers/mtd/onenand/libonenand.o

LIBS += drivers/mtd/ubi/libubi.o

LIBS += drivers/mtd/spi/libspi_flash.o

LIBS += drivers/net/libnet.o

LIBS += drivers/net/phy/libphy.o

LIBS += drivers/pci/libpci.o

LIBS += drivers/pcmcia/libpcmcia.o

LIBS += drivers/power/libpower.o

LIBS += drivers/spi/libspi.o

ifeq ($(CPU),mpc83xx)

LIBS += drivers/qe/libqe.o

LIBS +=
arch/powerpc/cpu/mpc8xxx/ddr/libddr.o

LIBS += arch/powerpc/cpu/mpc8xxx/lib8xxx.o

endif

ifeq ($(CPU),mpc85xx)

LIBS += drivers/qe/libqe.o

LIBS += drivers/net/fm/libfm.o

LIBS +=
arch/powerpc/cpu/mpc8xxx/ddr/libddr.o

LIBS += arch/powerpc/cpu/mpc8xxx/lib8xxx.o

endif

ifeq ($(CPU),mpc86xx)

LIBS +=
arch/powerpc/cpu/mpc8xxx/ddr/libddr.o

LIBS += arch/powerpc/cpu/mpc8xxx/lib8xxx.o

endif

LIBS += drivers/rtc/librtc.o

LIBS += drivers/serial/libserial.o

ifeq ($(CONFIG_GENERIC_LPC_TPM),y)

LIBS += drivers/tpm/libtpm.o

endif

LIBS += drivers/twserial/libtws.o

LIBS += drivers/usb/eth/libusb_eth.o

LIBS += drivers/usb/gadget/libusb_gadget.o

LIBS += drivers/usb/host/libusb_host.o

LIBS += drivers/usb/musb/libusb_musb.o

LIBS += drivers/usb/phy/libusb_phy.o

LIBS += drivers/usb/ulpi/libusb_ulpi.o

LIBS += drivers/video/libvideo.o

LIBS += drivers/watchdog/libwatchdog.o

LIBS += common/libcommon.o

LIBS += lib/libfdt/libfdt.o

LIBS += api/libapi.o

LIBS += post/libpost.o

 

ifneq
($(CONFIG_AM33XX)$(CONFIG_OMAP34XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)

LIBS +=
$(CPUDIR)/omap-common/libomap-common.o

endif

 

ifeq ($(SOC),mx5)

LIBS +=
$(CPUDIR)/imx-common/libimx-common.o

endif

ifeq ($(SOC),mx6)

LIBS +=
$(CPUDIR)/imx-common/libimx-common.o

endif

 

ifeq ($(SOC),s5pc1xx)

LIBS +=
$(CPUDIR)/s5p-common/libs5p-common.o

endif

ifeq ($(SOC),exynos)

LIBS +=
$(CPUDIR)/s5p-common/libs5p-common.o

endif

 

LIBS := $(addprefix $(obj),$(sort $(LIBS)))

.PHONY : $(LIBS)

 

LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).o

LIBBOARD := $(addprefix $(obj),$(LIBBOARD))

#為LIBBOARD增加字首,board/davinci/da8xxevm/libda8xxevm.o

 

# Add GCC lib

ifdef USE_PRIVATE_LIBGCC

ifeq ("$(USE_PRIVATE_LIBGCC)",
"yes")

PLATFORM_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/libgcc.o

else

PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC)
-lgcc

endif

else

PLATFORM_LIBGCC := -L $(shell dirname
`$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc


#dirname 命令讀取指定路徑名刪除最後一個“/”(斜槓)及其後面的字元,保留其他部分,並寫結果到標準輸出。如果最後一個“/”後無字元,dirname
命令使用倒數第二個“/”,並忽略其後的所有字元。

CFLGS:=$(CPPFLAGS) -Wall
-Wstrict-prototypes

1)USE_PRIVATE_LIBGCC = yes,從 /arch/arm/lib 中獲得 libgcc.a

2)USE_PRIVATE_LIBGCC = path+file,從 指定的路徑獲得 libgcc.a

3)如果沒有配置USE_PRIVATE_LIBGCC,就從工具鏈 libgcc路徑獲得。

我們這裡沒有定義使用者私有GCC庫,所以執行ifdef的else分支

PLATFORM_LIBGCC
= -L $ (shell dirname $(CC) $(CFLAGS) -print-libgcc-file-name) -lgcc

CC和CFLAGS都是make的隱含變數,CC表示C語言編譯器,預設為:‘cc’。cflags表示執行CC時的命令列引數

但是在這裡並不是使用“cc”這個編譯器,在頂層的config.mk檔案中我們可以找到關於$ (CC)和$(CFLAGS)的定義,如下:

dirname
$(CC) $(CFLAGS) -print-libgcc-file-name取得交叉編譯器的libgcc.a的絕對路徑

CC =
$(CROSS_COMPILE)gcc // CROSS_COMPILE = arm-none-linux-gnueabi-

                                                    //所以這裡:CC = arm-none-linux-gnueabi-gcc


# 沒有定義BUILD_TAG,執行else分支,賦值CFLAGS  

ifdef BUILD_TAG  

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \  

    -DBUILD_TAG='"$(BUILD_TAG)"'  

else  

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes  

endif  

  

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

# 利用call函式,使得$1=cc-option ,$2=-fno-stack-protector  

# CFLAGS_SSP= $1$2 = -fno-stack-protector,然後把CFLAGS_SSP  

# 追加給CFLAGS  

CFLAGS_SSP := $(call cc-option,-fno-stack-protector)  

# ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)  

# RELFLAGS=$(PLATFORM_RELFLAGS)=-fno-common -ffixed-r8 -msoft-float  

# DBGFLAGS = -g  

# OPTFLAGS = -Os  

# OBJCFLAGS = --gap-fill=0xff  

# gccincdir = $(shell $(CC) -print-file-name=include)=交叉工具鏈include目錄在宿# 主機中的位置CPPFLAGS = -g -Os -fno-common -ffixed-r8 -msoft-float -D__KERNEL__  

ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)  

RELFLAGS= $(PLATFORM_RELFLAGS)  

DBGFLAGS= -g  # -DDEBUG  

OPTFLAGS= -Os # -fomit-frame-pointer  

  

OBJCFLAGS += --gap-fill=0xff  

  

gccincdir := $(shell $(CC) -print-file-name=include)  

  

CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS)     \  

    -D__KERNEL__  

  

# Enable garbage collection of un-used sections for SPL  

ifeq ($(CONFIG_SPL_BUILD),y)  

CPPFLAGS += -ffunction-sections -fdata-sections  

LDFLAGS_FINAL += --gc-sections  

endif  




 -L

表示:編譯程式按照-L指定的路進去尋找庫檔案,一般的在-L的後面可以一次用-l指定多個庫檔案。

-lgcc 代表連結器將連線GCC的支援庫libgcc.a  

 




endif

PLATFORM_LIBS += $(PLATFORM_LIBGCC)

export PLATFORM_LIBS

 

# Special flags for CPP when processing the
linker script.

# Pass the version down so we can handle
backwards compatibility

# on the fly.

LDPPFLAGS += \

       -include
$(TOPDIR)/include/u-boot/u-boot.lds.h \

       -DCPUDIR=$(CPUDIR)
\

       $(shell
$(LD) --version | \

         sed -ne 's/GNU ld version
\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')

 

__OBJS := $(subst $(obj),,$(OBJS))

__LIBS := $(subst $(obj),,$(LIBS)) $(subst
$(obj),,$(LIBBOARD))

 

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

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

 

ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)

BOARD_SIZE_CHECK = \

       @actual=`wc
-c [email protected] | awk '{print $$1}'`; \

       limit=$(CONFIG_BOARD_SIZE_LIMIT);
\

       if
test $$actual -gt $$limit; then \

              echo
"[email protected] exceeds file size limit:"; \

              echo
"  limit:  $$limit bytes"; \

              echo
"  actual: $$actual bytes"; \

              echo
"  excess: $$((actual - limit))
bytes"; \

              exit
1; \

       fi

else

BOARD_SIZE_CHECK =

endif

 

# Always append ALL so that arch
config.mk's can add custom ones

ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin
$(obj)System.map

 

ALL-$(CONFIG_NAND_U_BOOT) +=
$(obj)u-boot-nand.bin

ALL-$(CONFIG_ONENAND_U_BOOT) +=
$(obj)u-boot-onenand.bin

ONENAND_BIN ?=
$(obj)onenand_ipl/onenand-ipl-2k.bin

ALL-$(CONFIG_SPL) +=
$(obj)spl/u-boot-spl.bin

ALL-$(CONFIG_OF_SEPARATE) +=
$(obj)u-boot.dtb $(obj)u-boot-dtb.bin

 

all:          $(ALL-y)
$(SUBDIR_EXAMPLES)

 

$(obj)u-boot.dtb: $(obj)u-boot

              $(MAKE)
-C dts binary

              mv
$(obj)dts/dt.dtb [email protected]

 

$(obj)u-boot-dtb.bin:  $(obj)u-boot.bin $(obj)u-boot.dtb

              cat
$^ >[email protected]

 

$(obj)u-boot.hex: $(obj)u-boot

              $(OBJCOPY)
${OBJCFLAGS} -O ihex $< [email protected]

 

$(obj)u-boot.srec: $(obj)u-boot

              $(OBJCOPY)
-O srec $< [email protected]

 

$(obj)u-boot.bin:  $(obj)u-boot

              $(OBJCOPY)
${OBJCFLAGS} -O binary $< [email protected]

              $(BOARD_SIZE_CHECK)

 

$(obj)u-boot.ldr:   $(obj)u-boot

              $(CREATE_LDR_ENV)

              $(LDR)
-T $(CONFIG_BFIN_CPU) -c [email protected] $< $(LDR_FLAGS)

              $(BOARD_SIZE_CHECK)

 

$(obj)u-boot.ldr.hex:   $(obj)u-boot.ldr

              $(OBJCOPY)
${OBJCFLAGS} -O ihex $< [email protected] -I binary

 

$(obj)u-boot.ldr.srec:   $(obj)u-boot.ldr

              $(OBJCOPY)
${OBJCFLAGS} -O srec $< [email protected] -I binary

 

$(obj)u-boot.img: $(obj)u-boot.bin

              $(obj)tools/mkimage
-A $(ARCH) -T firmware -C none \

              -O
u-boot -a $(CONFIG_SYS_TEXT_BASE) -e 0 \

              -n
$(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \

                     sed
-e 's/"[     ]*$$/ for $(BOARD)
board"/') \

              -d
$< [email protected]

 

$(obj)u-boot.imx:       $(obj)u-boot.bin

              $(obj)tools/mkimage
-n  $(CONFIG_IMX_CONFIG) -T imximage \

              -e
$(CONFIG_SYS_TEXT_BASE) -d $< [email protected]

 

$(obj)u-boot.kwb:       $(obj)u-boot.bin

              $(obj)tools/mkimage
-n $(CONFIG_SYS_KWD_CONFIG) -T kwbimage \

              -a
$(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) -d $< [email protected]

 

$(obj)u-boot.sha1: $(obj)u-boot.bin

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

 

$(obj)u-boot.dis:  $(obj)u-boot

              $(OBJDUMP)
-d $< > [email protected]

 

$(obj)u-boot.ubl:       $(obj)spl/u-boot-spl.bin
$(obj)u-boot.bin

              $(OBJCOPY)
${OBJCFLAGS} --pad-to=$(PAD_TO) -O binary $(obj)spl/u-boot-spl
$(obj)spl/u-boot-spl-pad.bin

              cat
$(obj)spl/u-boot-spl-pad.bin $(obj)u-boot.bin > $(obj)u-boot-ubl.bin

              $(obj)tools/mkimage
-n $(UBL_CONFIG) -T ublimage \

              -e
$(CONFIG_SYS_TEXT_BASE) -d $(obj)u-boot-ubl.bin $(obj)u-boot.ubl

              rm
$(obj)u-boot-ubl.bin

              rm
$(obj)spl/u-boot-spl-pad.bin




$(obj)u-boot.ais:       $(obj)spl/u-boot-spl.bin
$(obj)u-boot.bin

              $(obj)tools/mkimage -s -n
/dev/null -T aisimage \

                     -e $(CONFIG_SPL_TEXT_BASE)
\

                     -d $(obj)spl/u-boot-spl.bin
\

                     $(obj)spl/u-boot-spl.ais

              $(OBJCOPY) ${OBJCFLAGS} -I binary
\

                     --pad-to=$(CONFIG_SPL_MAX_SIZE)
-O binary \

                     $(obj)spl/u-boot-spl.ais
$(obj)spl/u-boot-spl-pad.ais

              cat $(obj)spl/u-boot-spl-pad.ais
$(obj)u-boot.bin > \

                     $(obj)u-boot.ais

u-boot.ais的編譯依賴u-boot-spl.bin,u-boot.bin等檔案

$(obj)u-boot.sb:       $(obj)u-boot.bin
$(obj)spl/u-boot-spl.bin

              elftosb
-zdf imx28 -c $(TOPDIR)/board/$(BOARDDIR)/u-boot.bd \

                     -o
$(obj)u-boot.sb

 

ifeq ($(CONFIG_SANDBOX),y)

GEN_UBOOT = \

              cd
$(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \

                     -Wl,--start-group
$(__LIBS) -Wl,--end-group \

                     $(PLATFORM_LIBS)
-Wl,-Map -Wl,u-boot.map -o u-boot

else

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) $(LDFLAGS_$(@F)) $$UNDEF_SYM $(__OBJS) \

                     --start-group
$(__LIBS) --end-group $(PLATFORM_LIBS) \

                     -Map
u-boot.map -o u-boot

endif

$(obj)u-boot: depend \

              $(SUBDIR_TOOLS)
$(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds

              $(GEN_UBOOT)


u-boot.ais的編譯依賴u-boot-spl.bin,u-boot.bin等檔案



$(obj)u-boot.sb:       $(obj)u-boot.bin
$(obj)spl/u-boot-spl.bin

              elftosb
-zdf imx28 -c $(TOPDIR)/board/$(BOARDDIR)/u-boot.bd \

                     -o
$(obj)u-boot.sb

 

ifeq ($(CONFIG_SANDBOX),y)

GEN_UBOOT = \

              cd
$(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \

                     -Wl,--start-group
$(__LIBS) -Wl,--end-group \

                     $(PLATFORM_LIBS)
-Wl,-Map -Wl,u-boot.map -o u-boot

else

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) $(LDFLAGS_$(@F)) $$UNDEF_SYM $(__OBJS) \

                     --start-group
$(__LIBS) --end-group $(PLATFORM_LIBS) \

                     -Map
u-boot.map -o u-boot

endif

$(obj)u-boot: depend \

              $(SUBDIR_TOOLS)
$(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds

              $(GEN_UBOOT)


#all依賴於$(ALL) 最終生成映象檔案,注意各種依賴關係。

重點分析一下“u-boot.bin”, u-boot.bin的依賴關係是這樣的:$(obj)u-boot.bin - > $(obj)u-boot - >

depend
$(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds

先來看看GEN_UBOOT變數的具體內容:

(1) $(OBJDUMP)

在頂層目錄的config.mk($(TOPDIR)/config.mk )檔案中我們可以找到該變數的定義:

OBJDUMP =
$(CROSS_COMPILE)objdump

命令列中定義了 CROSS_COMPILE=arm-none-linux-gnueabi-,所以

OBJDUMP =arm- none-linux-gnueabi
-objdump

(2) $(LIBBOARD)

LIBBOARD在Makefile中有定義。如下:

LIBBOARD =
board/ ( B O A R D D I R ) / l i b (BOARDDIR)/lib (BOARD).o

LIBBOARD :=
$(addprefix ( o b j ) , (obj), (LIBBOARD))

展開後得到的結果是:

LIBBOARD =
$(obj)board/davinci/da8xxevm/libda8xxevm.o

(3)$(LIBS)

這個變數是新增庫了(在Makefile中定義的),內容比較多,如下:

LIBS =
lib_generic/libgeneric.a

LIBS +=
lib_generic/lzma/liblzma.a

LIBS +=
lib_generic/lzo/liblzo.a

LIBS += ( s h e l l i f [ f b o a r d / (shell if [ -f board/ (VENDOR)/common/Makefile ]; then echo \

“board/ ( V E N D O R ) / c o m m o n / l i b (VENDOR)/common/lib (VENDOR).a”;
fi)

LIBS +=
cpu/ ( C P U ) / l i b (CPU)/lib (CPU).a

ifdef SOC

LIBS +=
cpu/ ( C P U ) / (CPU)/ (SOC)/lib$(SOC).a

endif

ifeq ($(CPU),ixp)

LIBS +=
cpu/ixp/npe/libnpe.a

endif

LIBS +=
lib_ ( A R C H ) / l i b (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

LIBS +=
drivers/gpio/libgpio.a

LIBS +=
drivers/hwmon/libhwmon.a

LIBS +=
drivers/i2c/libi2c.a

LIBS +=
drivers/input/libinput.a

LIBS +=
drivers/misc/libmisc.a

LIBS +=
drivers/mmc/libmmc.a

LIBS +=
drivers/mtd/libmtd.a

LIBS +=
drivers/mtd/nand/libnand.a

LIBS +=
drivers/mtd/onenand/libonenand.a

LIBS +=
drivers/mtd/ubi/libubi.a

LIBS +=
drivers/mtd/spi/libspi_flash.a

LIBS +=
drivers/net/libnet.a

LIBS +=
drivers/net/phy/libphy.a

LIBS +=
drivers/pci/libpci.a

LIBS +=
drivers/pcmcia/libpcmcia.a

LIBS +=
drivers/power/libpower.a

LIBS +=
drivers/spi/libspi.a

ifeq ($(CPU),mpc83xx)

LIBS += drivers/qe/qe.a

endif

ifeq ($(CPU),mpc85xx)

LIBS += drivers/qe/qe.a

LIBS += cpu/mpc8xxx/ddr/libddr.a

LIBS +=
cpu/mpc8xxx/lib8xxx.a

endif

ifeq ($(CPU),mpc86xx)

LIBS +=
cpu/mpc8xxx/ddr/libddr.a

LIBS +=
cpu/mpc8xxx/lib8xxx.a

endif

LIBS +=
drivers/rtc/librtc.a

LIBS +=
drivers/serial/libserial.a

LIBS +=
drivers/twserial/libtws.a

LIBS += drivers/usb/gadget/libusb_gadget.a

LIBS +=
drivers/usb/host/libusb_host.a

LIBS +=
drivers/usb/musb/libusb_musb.a

LBS +=
drivers/usb/phy/libusb_phy.a

LIBS +=
drivers/video/libvideo.a

LIBS += drivers/watchdog/libwatchdog.a

LIBS +=
common/libcommon.a

LIBS += libfdt/libfdt.a

LIBS += api/libapi.a

LIBS += post/libpost.a

從這些新增進來的這些庫的檔名,大概可以知道這些庫的用途了,包含了cup的配置、drivers驅動程式、api等,這裡就不列出了。

(3)$(SYM_PREFIX)

沒有定義這個變數,

(4) $(LNDIR)

LNDIR := $(OBJTREE) ,前面分析知道 OBJTREE就是頂層目錄了。

(5) $(LD)

在config.mk中有定義

LD =

$(CROSS_COMPILE)ld

 結果為:  LD = arm-none-linux-gnueabi-ld

咱們可以用type命令檢視一下“ arm-linux-ld”命令在哪裡:
在這裡插入圖片描述



(6)$(LDFLAGS)、$(LDFLAGS_$(@F))

  在config.mk中有定義  :

  LDFLAGS
+=$(PLATFORM_LDFLAGS)




LDFLAGS_FINAL += -Bstatic  

  

# 設定U-boot的連結選項  

LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)  

ifneq ($(CONFIG_SYS_TEXT_BASE),)  

LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)  

endif  

  

# 設定U-boot的連結選項,當uboot是採用spl時的情況  

LDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)  

ifneq ($(CONFIG_SPL_TEXT_BASE),)  

LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE)  

endif  



(7) $(__OBJS)和 $(__LIBS)

  在config.mk中有定義  :

  __OBJS :=
$(subst $(obj),,$(OBJS))

  __LIBS :=
$(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))

    

    subst函式的使用規則:

    $(subst from,to,text)

    在文字‘text’中使用‘to’替換每一處‘from’。

 

 結果就是:將變數OBJS內容裡的$(obj)替換成空,然後賦給 __OBJS

     
                

(8)$(PLATFORM_LIBS)

   
PLATFORM_LIBS在Makefile中定義為:

   
PLATFORM_LIBS += $(PLATFORM_LIBGCC)

 




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

 

$(OBJS): depend

              $(MAKE)
-C $(CPUDIR) $(if $(REMOTE_BUILD),[email protected],$(notdir [email protected]))

 

$(LIBS):   depend
$(SUBDIR_TOOLS)

              $(MAKE)
-C $(dir $(subst $(obj),,[email protected]))

 

$(LIBBOARD): depend $(LIBS)

              $(MAKE)
-C $(dir $(subst $(obj),,[email protected]))

 

$(SUBDIRS):   depend

              $(MAKE)
-C [email protected] all

 

$(SUBDIR_EXAMPLES): $(obj)u-boot

 

$(LDSCRIPT):  depend

              $(MAKE)
-C $(dir [email protected]) $(notdir [email protected])

 

$(obj)u-boot.lds: $(LDSCRIPT)

              $(CPP)
$(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >[email protected]

 



#CPP=$(CC)
-E=$(CORSS_COMPILE)gcc -E=arm-none-linux-gnueabi-gcc -E

# LDPPFLAGS += \

       -include $(TOPDIR)/include/u-boot/u-boot.lds.h \具體的位置是/include/u-boot/u-boot.lds.h

       -DCPUDIR=$(CPUDIR) \

       $(shell $(LD) --version | \

         sed -ne 's/GNU ld
version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')

預設變數“ CPP”  :C
程式的前處理器(輸出是標準輸出裝置)。預設命令是“$(CC) –E”。

-Dmacro:定義巨集macro,巨集的內容定義為字串`1'. 這裡

-D__ASSEMBLY__ 相當於  #define __ASSEMBLY__   ‘1’
。-D 是選項,__ASSEMBLY__ 相當於一個巨集。