對於Makefile 由於源碼特別長,所以,我在這裡就一邊摘錄一邊分析
- # 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
- # load ARCH, BOARD, and CPU configuration
- # 該文件為配置時生成的
- include $(obj)include/config.mk
- export ARCH CPU BOARD VENDOR SOC
- # set default to nothing for native builds
- ifeq ($(HOSTARCH),$(ARCH))
- CROSS_COMPILE ?= arm-linux-
- endif
- # load other configuration
- include $(TOPDIR)/config.mk
這段代碼中,上面的解釋已經很到位了.我這裡就不多說了,直接看一個相對比較重要的文件include $(TOPDIR)/config.mk
不知道怎麼分析好.就挑幾個重點講下.
1:編譯器的變量聲明
2:連接腳本
3:連接選項
1:編譯器的變量聲明
- #
- # 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
- LDR = $(CROSS_COMPILE)ldr
- STRIP = $(CROSS_COMPILE)strip
- OBJCOPY = $(CROSS_COMPILE)objcopy
- OBJDUMP = $(CROSS_COMPILE)objdump
- RANLIB = $(CROSS_COMPILE)RANLIB
這裡就知道為什麼交叉編譯器只需要指定前綴的原因了。
2:連接腳本
- 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
LDSCRIPT會根據是否啟用nand_boot的選項,來選擇連接腳本,連接腳本可以指定代碼生成的先後位置,比如把nand相關的函數指定到最前面.
uboot就是通過該連接腳本來使start.S這段代碼放到整個程序的最前面,這樣才能保證arm能正常啟動
3:連接選項
- LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
- ifneq ($(TEXT_BASE),)
- LDFLAGS += -Ttext $(TEXT_BASE)
- endif
LDFLAGS指明在連接的時候,指定連接地址,還有連接腳本的參數之類的.
剩下的就自己分析吧....
再回到Makefile,指定要編譯的對象了
- #########################################################################
- # 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))
- 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
- 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
- LIBS += 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
- LIBS := $(addprefix $(obj),$(LIBS))
- .PHONY : $(LIBS) $(TIMESTAMP_FILE) $(VERSION_FILE)
- LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).a
- LIBBOARD := $(addprefix $(obj),$(LIBBOARD))
- # Add GCC lib
- ifdef USE_PRIVATE_LIBGCC
- ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
- PLATFORM_LIBGCC = -L $(OBJTREE)/lib_$(ARCH) -lgcc
- else
- PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
- endif
- else
- PLATFORM_LIBGCC = -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
- 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 \
- $(shell $(LD) --version | \
- sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
- ifeq ($(CONFIG_NAND_U_BOOT),y)
- NAND_SPL = nand_spl
- U_BOOT_NAND = $(obj)u-boot-nand.bin
- endif
- ifeq ($(CONFIG_ONENAND_U_BOOT),y)
- ONENAND_IPL = onenand_ipl
- U_BOOT_ONENAND = $(obj)u-boot-onenand.bin
- ONENAND_BIN ?= $(obj)onenand_ipl/onenand-ipl-2k.bin
- endif
- __OBJS := $(subst $(obj),,$(OBJS))
- __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
- #########################################################################
- #########################################################################