u-boot的Makefile分析
本文引用地址:http://butianyuan.cn/article/151835.htm
mkconfig腳本文件的執(zhí)行至此結(jié)束,繼續(xù)分析Makefile剩下部分。
3)包含include/config.mk,其實(shí)也就相當(dāng)于在Makefile里定義了上面四個(gè)變量而已。
4) 指定交叉編譯器前綴:
ifeq ($(ARCH),arm)#這里根據(jù)ARCH變量,指定編譯器前綴。
CROSS_COMPILE = arm-linux-
endif
5)包含config.mk:
#包含頂層目錄下的config.mk,這個(gè)文件里面主要定義了交叉編譯器及選項(xiàng)和編譯規(guī)則
# load other configuration
include $(TOPDIR)/config.mk
下面分析config.mk的內(nèi)容:
?。腊w系,開(kāi)發(fā)板,CPU特定的規(guī)則文件:
ifdefARCH #指定預(yù)編譯體系結(jié)構(gòu)選項(xiàng)
sinclude $(TOPDIR)/$(ARCH)_config.mk# include architecture dependend rules
endif
ifdefCPU #定義編譯時(shí)對(duì)齊,浮點(diǎn)等選項(xiàng)
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk# include CPUspecific rules
endif
ifdefSOC #沒(méi)有這個(gè)文件
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk# include SoCspecific rules
endififdefBOARD #指定特定板子的鏡像連接時(shí)的內(nèi)存基地址,重要!
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk# include board specific rules
endif@定義交叉編譯鏈工具
# 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@定義AR選項(xiàng)ARFLAGS,調(diào)試選項(xiàng)DBGFLAGS,優(yōu)化選項(xiàng)OPTFLAGS
預(yù)處理選項(xiàng)CPPFLAGS,C編譯器選項(xiàng)CFLAGS,連接選項(xiàng)LDFLAGS
LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS) #指定了起始地址TEXT_BASE
@指定編譯規(guī)則:
$(obj)%.s:%.S
$(CPP) $(AFLAGS) -o $@ $
$(obj)%.%.S
$(CC) $(AFLAGS) -c -o $@ $
$(obj)%.%.c
$(CC) $(CFLAGS) -c -o $@ $
回到頂層makefile文件:
6)U-boot需要的目標(biāo)文件。
OBJS = cpu/$(CPU)/start.o # 順序很重要,start.o必須放第一位
7)需要的庫(kù)文件:
LIBS = lib_generic/libgeneric.a
LIBS += board/$(BOARDDIR)/lib$(BOARD).a
LIBS += cpu/$(CPU)/lib$(CPU).a
ifdef SOC
LIBS += cpu/$(CPU)/$(SOC)/lib$(SOC).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
LIBS += net/libnet.a
LIBS += disk/libdisk.a
LIBS += rtc/librtc.a
LIBS += dtt/libdtt.a
LIBS += drivers/libdrivers.a
LIBS += drivers/nand/libnand.a
LIBS += drivers/nand_legacy/libnand_legacy.a
LIBS += drivers/sk98lin/libsk98lin.a
LIBS += post/libpost.a post/cpu/libcpu.a
LIBS += common/libcommon.a
LIBS += $(BOARDLIBS)LIBS := $(addprefix $(obj),$(LIBS))
.PHONY : $(LIBS)根據(jù)上面的include/config.mk文件定義的ARCH、CPU、BOARD、SOC這些變量。硬件平臺(tái)依賴的目錄文件可以根據(jù)這些定義來(lái)確定。SMDK2410平臺(tái)相關(guān)目錄及對(duì)應(yīng)生成的庫(kù)文件如下。
board/smdk2410/ :庫(kù)文件board/smdk2410/libsmdk2410.a
cpu/arm920t/ :庫(kù)文件cpu/arm920t/libarm920t.a
cpu/arm920t/s3c24x0/ :庫(kù)文件cpu/arm920t/s3c24x0/libs3c24x0.a
lib_arm/ :庫(kù)文件lib_arm/libarm.a
include/asm-arm/ :下面兩個(gè)是頭文件。
include/configs/smdk2410.h
8)最終生成的各種鏡像文件:
ALL = $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND)
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 $ $@
評(píng)論