【u-boot-2016到s5pv210】0.3 SPL和uboot编译流程

时间:2021-10-31 16:32:24

上一节成功点亮了led的,但是,它是裸机程序,还没有真正的开始,真正的开始应该是运行u-boot所以本节主要解决以下问题:

1 uboot怎么下载

2 uboot怎么生成BL1(u-boot-spl.bin)

3 uboot怎么样生成BL2(u-boot.bin)

一 下载源码

u-boot的源码,一般下载下来的都是压缩格式,ftp://ftp.denx.de/pub/u-boot/,为了方便版本的切换,在此使用git工具下载,具体步骤如下:

1) clone 出仓库:

git clone git://git.denx.de/u-boot.git u-boot
2) 查看仓库的一些信息:
git status
3) 查看 release 版本(打的标签):
git tag
4)切换到特定的标签版本下:
git checkout v2016.09.01
5) 查看本标签与其他的标签的不同:

git diff v2016.09

二 版本结构

1 版本命名变化,主要发生在2008年,以前按版本号命名,2008年后,以年月命名,如下图所示:

【u-boot-2016到s5pv210】0.3 SPL和uboot编译流程

2 目录结构变化,随着版本地升级,目录的组织结构也发生了变化,当前使用的版本的目录结构如下所示

【u-boot-2016到s5pv210】0.3 SPL和uboot编译流程

三 make <board>_defconfig过程

1 编译前,需要先清理源码树:make distclean

Cleaning targets:
  clean		  - Remove most generated files but keep the config
  mrproper	  - Remove all generated files + config + various backup files
  distclean	  - mrproper + remove editor backup and patch files

2 配置

rabbit@rabbit:~/work/samba/u-boot$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-  am335x_boneblack_defconfig  V=1
make -f ./scripts/Makefile.build obj=scripts/basic
  cc -Wp,-MD,scripts/basic/.fixdep.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer     -o scripts/basic/fixdep scripts/basic/fixdep.c  
rm -f .tmp_quiet_recordmcount
make -f ./scripts/Makefile.build obj=scripts/kconfig am335x_boneblack_defconfig
  cc -Wp,-MD,scripts/kconfig/.conf.o.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer   -D_GNU_SOURCE -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/conf.o scripts/kconfig/conf.c
  cat scripts/kconfig/zconf.tab.c_shipped > scripts/kconfig/zconf.tab.c
  cat scripts/kconfig/zconf.lex.c_shipped > scripts/kconfig/zconf.lex.c
  cat scripts/kconfig/zconf.hash.c_shipped > scripts/kconfig/zconf.hash.c
  cc -Wp,-MD,scripts/kconfig/.zconf.tab.o.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer   -D_GNU_SOURCE -DCURSES_LOC="<ncurses.h>" -DLOCALE  -Iscripts/kconfig -c -o scripts/kconfig/zconf.tab.o scripts/kconfig/zconf.tab.c
  cc  -o scripts/kconfig/conf scripts/kconfig/conf.o scripts/kconfig/zconf.tab.o  
scripts/kconfig/conf  --defconfig=arch/../configs/am335x_boneblack_defconfig Kconfig
#
# configuration written to .config
#


二 make all过程

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 

(1)uboot.bin过程


# Always append ALL so that arch config.mk's can add custom ones
ALL-y += u-boot.srec u-boot.bin u-boot.sym System.map u-boot.cfg binary_size_check

ALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin
ifeq ($(CONFIG_SPL_FSL_PBL),y)
ALL-$(CONFIG_RAMBOOT_PBL) += u-boot-with-spl-pbl.bin
else
ifneq ($(CONFIG_SECURE_BOOT), y)
# For Secure Boot The Image needs to be signed and Header must also
# be included. So The image has to be built explicitly
ALL-$(CONFIG_RAMBOOT_PBL) += u-boot.pbl
endif
endif
ALL-$(CONFIG_SPL) += spl/u-boot-spl.bin
ALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
ALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
ALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb
ifeq ($(CONFIG_SPL_FRAMEWORK),y)
ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
endif
ALL-$(CONFIG_OF_HOSTFILE) += u-boot.dtb
ifneq ($(CONFIG_SPL_TARGET),)
ALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
endif
ALL-$(CONFIG_REMAKE_ELF) += u-boot.elf
ALL-$(CONFIG_EFI_APP) += u-boot-app.efi
ALL-$(CONFIG_EFI_STUB) += u-boot-payload.efi

ifneq ($(BUILD_ROM),)
ALL-$(CONFIG_X86_RESET_VECTOR) += u-boot.rom
endif
铎
# enable combined SPL/u-boot/dtb rules for tegra
ifeq ($(CONFIG_TEGRA)$(CONFIG_SPL),yy)
ALL-y += u-boot-tegra.bin u-boot-nodtb-tegra.bin
ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb-tegra.bin
endif

# Add optional build target if defined in board/cpu/soc headers
ifneq ($(CONFIG_BUILD_TARGET),)
ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
endif

all:		$(ALL-y)

ifeq ($(CONFIG_OF_SEPARATE),y)
u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
	$(call if_changed,cat)

u-boot.bin: u-boot-dtb.bin FORCE
	$(call if_changed,copy)
else
u-boot.bin: u-boot-nodtb.bin FORCE
	$(call if_changed,copy)
endif
u-boot-nodtb.bin: u-boot FORCE
	$(call if_changed,objcopy)
	$(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
	$(BOARD_SIZE_CHECK)
u-boot:	$(u-boot-init) $(u-boot-main) u-boot.lds FORCE
	$(call if_changed,u-boot__)
ifeq ($(CONFIG_KALLSYMS),y)
	$(call cmd,smap)
	$(call cmd,u-boot__) common/system_map.o
endif



u-boot-init := $(head-y)
u-boot-main := $(libs-y)

./scripts/Makefile.spl:51:libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
./scripts/Makefile.spl:55:libs-y += common/init/
./scripts/Makefile.spl:58:libs-y += drivers/
./scripts/Makefile.spl:59:libs-y += dts/
./scripts/Makefile.spl:60:libs-y += fs/
./scripts/Makefile.spl:66:libs-y		:= $(addprefix $(obj)/,$(libs-y))
./scripts/Makefile.spl:67:u-boot-spl-dirs	:= $(patsubst %/,%,$(filter %/, $(libs-y)))
./scripts/Makefile.spl:69:libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
./scripts/Makefile.spl:78:u-boot-spl-main := $(libs-y)
./arch/arc/Makefile:5:libs-y += arch/arc/cpu/$(CPU)/
./arch/arc/Makefile:6:libs-y += arch/arc/lib/
./arch/openrisc/Makefile:7:libs-y += arch/openrisc/cpu/
./arch/openrisc/Makefile:8:libs-y += arch/openrisc/lib/
./arch/powerpc/Makefile:9:libs-y += arch/powerpc/cpu/$(CPU)/
./arch/powerpc/Makefile:10:libs-y += arch/powerpc/cpu/
./arch/powerpc/Makefile:11:libs-y += arch/powerpc/lib/
./arch/sparc/Makefile:7:libs-y += arch/sparc/cpu/$(CPU)/
./arch/sparc/Makefile:8:libs-y += arch/sparc/lib/
./arch/arm/Makefile:71:libs-y += $(machdirs)
./arch/arm/Makefile:81:libs-y += arch/arm/cpu/$(CPU)/
./arch/arm/Makefile:82:libs-y += arch/arm/cpu/
./arch/arm/Makefile:83:libs-y += arch/arm/lib/
./arch/arm/Makefile:87:libs-y += arch/arm/imx-common/
./arch/arm/Makefile:91:libs-y += arch/arm/imx-common/
./arch/arm/Makefile:96:libs-y += arch/arm/mach-mvebu/
./arch/sandbox/Makefile:7:libs-y += arch/sandbox/cpu/
./arch/sandbox/Makefile:8:libs-y += arch/sandbox/lib/
./arch/nds32/Makefile:7:libs-y += arch/nds32/cpu/$(CPU)/
./arch/nds32/Makefile:8:libs-y += arch/nds32/lib/
./arch/blackfin/Makefile:7:libs-y += arch/blackfin/cpu/
./arch/blackfin/Makefile:8:libs-y += arch/blackfin/lib/
./arch/avr32/Makefile:7:libs-y += arch/avr32/cpu/
./arch/avr32/Makefile:8:libs-y += arch/avr32/lib/
./arch/mips/Makefile:7:libs-y += arch/mips/cpu/
./arch/mips/Makefile:8:libs-y += arch/mips/lib/
./arch/mips/Makefile:14:libs-y += $(machdirs)
./arch/nios2/Makefile:7:libs-y += arch/nios2/cpu/
./arch/nios2/Makefile:8:libs-y += arch/nios2/lib/
./arch/m68k/Makefile:7:libs-y += arch/m68k/cpu/$(CPU)/
./arch/m68k/Makefile:8:libs-y += arch/m68k/lib/
./arch/x86/Makefile:13:libs-y += arch/x86/cpu/
./arch/x86/Makefile:14:libs-y += arch/x86/lib/
./arch/sh/Makefile:7:libs-y += arch/sh/cpu/$(CPU)/
./arch/sh/Makefile:8:libs-y += arch/sh/lib/
./arch/microblaze/Makefile:7:libs-y += arch/microblaze/cpu/
./arch/microblaze/Makefile:8:libs-y += arch/microblaze/lib/
./Makefile:620:libs-y += lib/
./Makefile:623:libs-y += fs/
./Makefile:624:libs-y += net/
./Makefile:625:libs-y += disk/
./Makefile:626:libs-y += drivers/
./Makefile:627:libs-y += drivers/dma/
./Makefile:628:libs-y += drivers/gpio/
./Makefile:629:libs-y += drivers/i2c/
./Makefile:630:libs-y += drivers/mmc/
./Makefile:631:libs-y += drivers/mtd/
./Makefile:633:libs-y += drivers/mtd/onenand/
./Makefile:635:libs-y += drivers/mtd/spi/
./Makefile:636:libs-y += drivers/net/
./Makefile:637:libs-y += drivers/net/phy/
./Makefile:638:libs-y += drivers/pci/
./Makefile:639:libs-y += drivers/power/ \
./Makefile:645:libs-y += drivers/spi/
./Makefile:649:libs-y += drivers/serial/
./Makefile:650:libs-y += drivers/usb/dwc3/
./Makefile:651:libs-y += drivers/usb/common/
./Makefile:652:libs-y += drivers/usb/emul/
./Makefile:653:libs-y += drivers/usb/eth/
./Makefile:654:libs-y += drivers/usb/gadget/
./Makefile:655:libs-y += drivers/usb/gadget/udc/
./Makefile:656:libs-y += drivers/usb/host/
./Makefile:657:libs-y += drivers/usb/musb/
./Makefile:658:libs-y += drivers/usb/musb-new/
./Makefile:659:libs-y += drivers/usb/phy/
./Makefile:660:libs-y += drivers/usb/ulpi/
./Makefile:661:libs-y += cmd/
./Makefile:662:libs-y += common/
./Makefile:665:libs-y += test/
./Makefile:666:libs-y += test/dm/
./Makefile:669:libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
./Makefile:671:libs-y := $(sort $(libs-y))
./Makefile:673:u-boot-dirs	:= $(patsubst %/,%,$(filter %/, $(libs-y))) tools examples
./Makefile:677:libs-y		:= $(patsubst %/, %/built-in.o, $(libs-y))
./Makefile:680:u-boot-main := $(libs-y)


【u-boot-2016到s5pv210】0.3 SPL和uboot编译流程


(2)

uboot-spl.bin生成过程


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

spl/u-boot-spl.bin: spl/u-boot-spl
	@:
spl/u-boot-spl: tools prepare $(if $(CONFIG_OF_SEPARATE),dts/dt.dtb)
	$(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all


ALL-y	+= $(obj)/$(SPL_BIN).bin $(obj)/$(SPL_BIN).cfg

ifdef CONFIG_SAMSUNG
ALL-y	+= $(obj)/$(BOARD)-spl.bin
endif

ifdef CONFIG_ARCH_SOCFPGA
ALL-y	+= $(obj)/$(SPL_BIN).sfp
endif

ifdef CONFIG_SUNXI
ALL-y	+= $(obj)/sunxi-spl.bin
endif

ifeq ($(CONFIG_SYS_SOC),"at91")
ALL-y	+= boot.bin
endif

ifdef CONFIG_ARCH_ZYNQ
ALL-y	+= $(obj)/boot.bin
endif

all:	$(ALL-y)

ifeq ($(CONFIG_TPL_BUILD),y)
SPL_BIN := u-boot-tpl
else
SPL_BIN := u-boot-spl
endif

1

ifeq ($(CONFIG_SPL_OF_CONTROL)$(CONFIG_OF_SEPARATE),yy)
$(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin $(obj)/$(SPL_BIN)-pad.bin \
		$(obj)/$(SPL_BIN).dtb FORCE
	$(call if_changed,cat)

$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
	$(call if_changed,copy)
else
$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE
	$(call if_changed,copy)
endif


$(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE
	$(call if_changed,objcopy)


$(obj)/$(SPL_BIN): $(u-boot-spl-init) $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
	$(call if_changed,u-boot-spl)



include $(srctree)/config.mk
include $(srctree)/arch/$(ARCH)/Makefile

# Enable garbage collection of un-used sections for SPL
KBUILD_CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS_FINAL += --gc-sections

# FIX ME
cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
							$(NOSTDINC_FLAGS)

HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)

libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/

libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
libs-y += common/init/
libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/
libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
libs-y += drivers/
libs-y += dts/
libs-y += fs/
libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
libs-$(CONFIG_SPL_NET_SUPPORT) += net/

head-y		:= $(addprefix $(obj)/,$(head-y))
libs-y		:= $(addprefix $(obj)/,$(libs-y))
u-boot-spl-dirs	:= $(patsubst %/,%,$(filter %/, $(libs-y)))

libs-y := $(patsubst %/, %/built-in.o, $(libs-y))

# Add GCC lib
ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
endif

u-boot-spl-init := $(head-y)
u-boot-spl-main := $(libs-y)

$(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
	$(call if_changed_dep,cpp_lds)


2

$(obj)/$(SPL_BIN).cfg:	include/config.h FORCE
	$(call if_changed,cpp_cfg)


3

ifdef CONFIG_SAMSUNG
ifdef CONFIG_VAR_SIZE_SPL
VAR_SIZE_PARAM = --vs
else
VAR_SIZE_PARAM =
endif
$(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
	$(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
	$(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
	$(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
endif