u-boot顶层目录config.mk分析

1. 设置obj与src

ifneq ($(OBJTREE),$(SRCTREE))
ifeq ($(CURDIR),$(SRCTREE))
dir :=
else
dir := $(subst $(SRCTREE)/,,$(CURDIR))
endif

obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)

$(shell mkdir -p $(obj))
else
obj :=
src :=
endif

一般目标输出到源代码目录下,因此执行完上面的代码后,src和obj都为空。

2.设置编译选项

主要是设置以下三个编译选项

# clean the slate ...
PLATFORM_RELFLAGS =
PLATFORM_CPPFLAGS =
PLATFORM_LDFLAGS =

2.1 $(ARCH)=arm,所以包含的文件是arm_config.mk,架构相关的编译选项。

ifdef    ARCH
sinclude $(TOPDIR)/$(ARCH)_config.mk    # include architecture dependend rules
endif

arm_config.mk只有一行,内容如下

PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__

2.2 $(CPU)=s3c64xx,所以包含的文件是cpu/s3c64xx/config.mk,处理器相关的编译选项。

ifdef    CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk    # include  CPU    specific rules
endif

cpu/s3c64xx/config.mk内容如下:

PLATFORM_RELFLAGS += -fno-strict-aliasing  -fno-common -ffixed-r8 -msoft-float

# Make ARMv5 to allow more compilers to work, even though its v6.
PLATFORM_CPPFLAGS += -march=armv5t
# =========================================================================
#
# Supply options according to compiler version
#
# =========================================================================
#PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))

 这里解释一下as-option、ld-option、cc-option的作用:

当编译、链接文件时,xx-opiton可以用来检查当前使用的$(CC)是否支持给出的编译选项。如前者不支持,可使用后者。

可以参考这篇文章  Linux 2.6内核Makefile浅析 

 

2.3 $(SOC)=s3c6410,所以包含的文件是cpu/s3c64xx/s3c6410/config.mk。但这个文件不存在,因为用sinclude包含,所以不会报错

ifdef    SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk    # include  SoC    specific rules
endif

以上代码执行完成后,

 1 PLATFORM_RELFLAGS :  -fno-strict-aliasing  -fno-common -ffixed-r8 -msoft-float 
 2 PLATFORM_CPPFLAGS :  -DCONFIG_ARM -D__ARM__ -march=armv5t

3 指定交叉编译工具,$(CROSS_COMPILE) = /usr/local/arm/4.3.2/bin/arm-linux-

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

4 连接器选项的设置

LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)

4.1 $(BOARD)=smdk6410,$(BOARDDIR)=samsung/smdk6410,所以包含的文件是board/samsung/smdk6410/config.mk。

ifdef    VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef    BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk    # include board specific rules
endif

board/samsung/smdk6410/config.mk文件中定义了TEXT_BASE。u-boot编译时使用TEXT_BASE作为代码段链接的起始地址。

ifndef TEXT_BASE
TEXT_BASE = 0xCFE00000
endif

4.2 指定board/samsung/smdk6410/u-boot.lds位u-boot的链接脚本

LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
    . = 0x00000000;

    . = ALIGN(4);
    .text      :
    {
      cpu/s3c64xx/start.o    (.text)
      cpu/s3c64xx/s3c6410/cpu_init.o    (.text)
      cpu/s3c64xx/onenand_cp.o    (.text)
      cpu/s3c64xx/nand_cp.o    (.text)
      cpu/s3c64xx/movi.o (.text)
      *(.text)
      lib_arm/div0.o
    }

    . = ALIGN(4);
    .rodata : { *(.rodata) }

    . = ALIGN(4);
    .data : { *(.data) }

    . = ALIGN(4);
    .got : { *(.got) }

    __u_boot_cmd_start = .;
    .u_boot_cmd : { *(.u_boot_cmd) }
    __u_boot_cmd_end = .;

    . = ALIGN(4);
    .mmudata : { *(.mmudata) }

    . = ALIGN(4);
    __bss_start = .;
    .bss : { *(.bss) }
    _end = .;
}
u-boot.lds

5 指定隐含的编译规则

AFLAGS为汇编代码编译选项,CFLAGS为C代码编译选项

4 CFLAGS : -g  -Os   -fno-strict-aliasing  -fno-common -ffixed-r8 -msoft-float  -D__KERNEL__ -DTEXT_BASE=0xCFE00000  -I/home/yjg/arm6410/qudong/01-uboot/uboot_ok6410/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include -pipe  -DCONFIG_ARM -D__ARM__ -march=armv5t -Wall -Wstrict-prototypes
5 AFLAGS :  -D__ASSEMBLY__ -g  -Os   -fno-strict-aliasing  -fno-common -ffixed-r8 -msoft-float  -D__KERNEL__ -DTEXT_BASE=0xCFE00000  -I/home/yjg/arm6410/qudong/01-uboot/uboot_ok6410/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include -pipe  -DCONFIG_ARM -D__ARM__ -march=armv5t
%.s:    %.S
    $(CPP) $(AFLAGS) -o $@ $<
%.o:    %.S
    $(CC) $(AFLAGS) -c -o $@ $<
%.o:    %.c
    $(CC) $(CFLAGS) -c -o $@ $<
CPP: /usr/local/arm/4.3.2/bin/arm-linux-gcc -E,只激活预处理,不生成文件。

6 ARFLAGS,ARFLAGS声明如下,为AR命令的参数,暂时不知道在哪里使用。
ARFLAGS = crv

 



posted @ 2017-11-11 23:09  bluebluebluesky  阅读(427)  评论(0编辑  收藏  举报