uboot之Makefile浅析

拿到新的 uboot后(uboot1.1.6),最开始进行 make xxx_config。然后再进行make。这里面进行了什么操作呢?

以三星的 s3c2410为例。首先打开Makefile

发现其中:


$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})  //-d是判断BUILD_DIR是否存在。倘若不存在就创建。mkdir的-p参数代表若路径中的BUILD_DIR不存在就创建
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)     //尝试进入BUILD_DIR 文件夹,如果能正常进入则将文件路劲赋值给BUILD_DIR 。
OBJTREE		:= $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) //如果BUILD_DIR不为空,OBJTREE := $(BUILD_DIR)否则就是当前目录$(CURDIR)
SRCTREE		:= $(CURDIR)
TOPDIR		:= $(SRCTREE)
LNDIR		:= $(OBJTREE)
export	TOPDIR SRCTREE OBJTREE
MKCONFIG	:= $(SRCTREE)/mkconfig

export MKCONFIG
smdk2410_config	:	unconfig
	@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0  //$(@:_config=) 去掉 _config

//此句话翻译过来就是执行脚本
//mkconfig smdk2410  arm arm920t smdk2410 NULL s3c24x0

看下 mkconfig   smdk2410 arm arm920t smdk2410 NULL s3c24x0 做了什么?

ln -s ${LNPREFIX}arch-$3 asm-$2/arch //建立软连接
echo "ARCH   = $2" >  config.mk
echo "CPU    = $3" >> config.mk
echo "BOARD  = $4" >> config.mk
//头文件包含输入到config.h
echo "#include " >>config.h

打开include目录下的config.mk

ARCH   = arm
CPU    = arm920t
BOARD  = s3c2410
SOC    = s3c24x0

打开include目录下的 config.h

/* Automatically generated - do not edit */
#include 

smdk2410.h类似于kernel的make menuconfig,只不过没有图形界面。打开smdk2410大概内容如下:

包含一些 sp,中断栈,sdram大小,sdram基地址等等所有信息。

 * Stack sizes
 *
 * The stack sizes are set up in start.S using the settings below
 */
#define CONFIG_STACKSIZE        (128*1024)      /* regular stack */
#ifdef CONFIG_USE_IRQ
#define CONFIG_STACKSIZE_IRQ    (4*1024)        /* IRQ stack */
#define CONFIG_STACKSIZE_FIQ    (4*1024)        /* FIQ stack */
#endif

/*-----------------------------------------------------------------------
 * Physical Memory Map
 */
#define CONFIG_NR_DRAM_BANKS    1          /* we have 1 bank of DRAM */
#define PHYS_SDRAM_1            0x30000000 /* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE       0x04000000 /* 64 MB */

#define PHYS_FLASH_1            0x00000000 /* Flash Bank #1 */

#define CFG_FLASH_BASE          PHYS_FLASH_1
#define CFG_MONITOR_BASE        PHYS_FLASH_1

2.确定交叉工具链

include $(OBJTREE)/include/config.mk
export	ARCH CPU BOARD VENDOR SOC   //应用上述生成的inluude目录下config.mk.输出环境变量 

CROSS_COMPILE = arm-linux- //编译选项
export	CROSS_COMPILE     //导出编译选项

3.添加objs和lib库

OBJS  = cpu/$(CPU)/start.o  // cpu/arm920t/

#lib 库
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/usb/libusb.a
LIBS += drivers/sk98lin/libsk98lin.a
LIBS += common/libcommon.a
LIBS += $(BOARDLIBS)

4.查看依赖关系,编译uboot.bin

all:        $(ALL)  //这个伪目标all是所有目标的目标,其功能一般是编译所有的目标。

//这条编译命令实现了ELF格式的U-Boot文件到BIN格式的转换。
$(obj)u-boot.bin:    $(obj)u-boot            
        $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@

//展开arm-linux-objdump -d uboot > uboot.dis 反汇编
$(obj)u-boot.dis:    $(obj)u-boot
        $(OBJDUMP) -d $< > $@

//u-boot.bin依赖于$(obj)u-boot ,$(obj)u-boot 又依赖于depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)

$(obj)u-boot:	depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)
		UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed  -n -e 's/.*\(__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

 

你可能感兴趣的:(uboot)