From 3aa29de0b04be9d56251474d1036b23da249f607 Mon Sep 17 00:00:00 2001 From: Ying Zhang Date: Fri, 16 Aug 2013 15:16:15 +0800 Subject: TPL : introduce the TPL based on the SPL Due to the nand SPL on some board(e.g. P1022DS)has a size limit, it can not be more than 4K. So, the SPL cannot initialize the DDR with the SPD code. This patch introduces TPL to enable a loader stub that is loaded by the code from the SPL. It initializes the DDR with the SPD or other operations. The TPL's size is sizeable, the maximum size is decided by the memory's size that TPL runs. It initializes the DDR through SPD code, and copys final uboot image to DDR. So there are three stage uboot images: * spl_boot, * tpl_boot, * final uboot image Signed-off-by: Ying Zhang Acked-by: York Sun diff --git a/Makefile b/Makefile index 43b57da..8d7159d 100644 --- a/Makefile +++ b/Makefile @@ -102,10 +102,11 @@ endif # ifneq ($(BUILD_DIR),) OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) SPLTREE := $(OBJTREE)/spl +TPLTREE := $(OBJTREE)/tpl SRCTREE := $(CURDIR) TOPDIR := $(SRCTREE) LNDIR := $(OBJTREE) -export TOPDIR SRCTREE OBJTREE SPLTREE +export TOPDIR SRCTREE OBJTREE SPLTREE TPLTREE MKCONFIG := $(SRCTREE)/mkconfig export MKCONFIG @@ -397,6 +398,7 @@ ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map ALL-$(CONFIG_NAND_U_BOOT) += $(obj)u-boot-nand.bin ALL-$(CONFIG_ONENAND_U_BOOT) += $(obj)u-boot-onenand.bin ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin +ALL-$(CONFIG_TPL) += $(obj)tpl/u-boot-tpl.bin ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin ifneq ($(CONFIG_SPL_TARGET),) ALL-$(CONFIG_SPL) += $(obj)$(subst ",,$(CONFIG_SPL_TARGET)) @@ -475,13 +477,25 @@ $(obj)u-boot.sha1: $(obj)u-boot.bin $(obj)u-boot.dis: $(obj)u-boot $(OBJDUMP) -d $< > $@ +# $@ is output, $(1) and $(2) are inputs, $(3) is padded intermediate, +# $(4) is pad-to +SPL_PAD_APPEND = \ + $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(4) -I binary -O binary \ + $(1) $(obj)$(3); \ + cat $(obj)$(3) $(obj)$(2) > $@; \ + rm $(obj)$(3) +ifdef CONFIG_TPL +SPL_PAYLOAD := $(obj)tpl/u-boot-with-tpl.bin +else +SPL_PAYLOAD := $(obj)u-boot.bin +endif -$(obj)u-boot-with-spl.bin: $(obj)spl/u-boot-spl.bin $(obj)u-boot.bin - $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(CONFIG_SPL_PAD_TO) \ - -I binary -O binary $< $(obj)spl/u-boot-spl-pad.bin - cat $(obj)spl/u-boot-spl-pad.bin $(obj)u-boot.bin > $@ - rm $(obj)spl/u-boot-spl-pad.bin +$(obj)u-boot-with-spl.bin: $(obj)spl/u-boot-spl.bin $(SPL_PAYLOAD) + $(call SPL_PAD_APPEND,$<,$(SPL_PAYLOAD),spl/u-boot-spl-pad.bin,$(CONFIG_SPL_PAD_TO)) + +$(obj)tpl/u-boot-with-tpl.bin: $(obj)tpl/u-boot-tpl.bin $(obj)u-boot.bin + $(call SPL_PAD_APPEND,$<,u-boot.bin,tpl/u-boot-tpl-pad.bin,$(CONFIG_TPL_PAD_TO)) $(obj)u-boot-with-spl.imx: $(obj)spl/u-boot-spl.bin $(obj)u-boot.bin $(MAKE) -C $(SRCTREE)/arch/arm/imx-common \ @@ -607,6 +621,9 @@ $(obj)u-boot-nand.bin: nand_spl $(obj)u-boot.bin $(obj)spl/u-boot-spl.bin: $(SUBDIR_TOOLS) depend $(MAKE) -C spl all +$(obj)tpl/u-boot-tpl.bin: $(SUBDIR_TOOLS) depend + $(MAKE) -C spl all CONFIG_TPL_BUILD=y + updater: $(MAKE) -C tools/updater all @@ -614,6 +631,7 @@ updater: # parallel sub-makes creating .depend files simultaneously. depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \ $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk \ $(obj)include/autoconf.mk \ $(obj)include/generated/generic-asm-offsets.h \ $(obj)include/generated/asm-offsets.h @@ -696,6 +714,15 @@ $(obj)include/autoconf.mk: $(obj)include/config.h mv $@.tmp $@ # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL) +$(obj)include/tpl-autoconf.mk: $(obj)include/config.h + @$(XECHO) Generating $@ ; \ + set -e ; \ + : Extract the config macros ; \ + $(CPP) $(CFLAGS) -DCONFIG_TPL_BUILD -DCONFIG_SPL_BUILD\ + -DDO_DEPS_ONLY -dM include/common.h | \ + sed -n -f tools/scripts/define2mk.sed > $@.tmp && \ + mv $@.tmp $@ + $(obj)include/spl-autoconf.mk: $(obj)include/config.h @$(XECHO) Generating $@ ; \ set -e ; \ @@ -706,12 +733,14 @@ $(obj)include/spl-autoconf.mk: $(obj)include/config.h $(obj)include/generated/generic-asm-offsets.h: $(obj)include/autoconf.mk.dep \ $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk \ $(obj)lib/asm-offsets.s @$(XECHO) Generating $@ tools/scripts/make-asm-offsets $(obj)lib/asm-offsets.s $@ $(obj)lib/asm-offsets.s: $(obj)include/autoconf.mk.dep \ $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk \ $(src)lib/asm-offsets.c @mkdir -p $(obj)lib $(CC) -DDO_DEPS_ONLY \ @@ -720,12 +749,14 @@ $(obj)lib/asm-offsets.s: $(obj)include/autoconf.mk.dep \ $(obj)include/generated/asm-offsets.h: $(obj)include/autoconf.mk.dep \ $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk \ $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s @$(XECHO) Generating $@ tools/scripts/make-asm-offsets $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s $@ $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s: $(obj)include/autoconf.mk.dep \ - $(obj)include/spl-autoconf.mk + $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk @mkdir -p $(obj)$(CPUDIR)/$(SOC) if [ -f $(src)$(CPUDIR)/$(SOC)/asm-offsets.c ];then \ $(CC) -DDO_DEPS_ONLY \ @@ -798,7 +829,8 @@ unconfig: @rm -f $(obj)include/config.h $(obj)include/config.mk \ $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \ $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep \ - $(obj)include/spl-autoconf.mk + $(obj)include/spl-autoconf.mk \ + $(obj)include/tpl-autoconf.mk %_config:: unconfig @$(MKCONFIG) -A $(@:_config=) @@ -884,6 +916,8 @@ clobber: tidy @rm -f $(obj)nand_spl/{u-boot-nand_spl.lds,u-boot-spl,u-boot-spl.map} @rm -f $(obj)spl/{u-boot-spl,u-boot-spl.bin,u-boot-spl.map} @rm -f $(obj)spl/u-boot-spl.lds + @rm -f $(obj)tpl/{u-boot-tpl,u-boot-tpl.bin,u-boot-tpl.map} + @rm -f $(obj)tpl/u-boot-spl.lds @rm -f $(obj)MLO MLO.byteswap @rm -f $(obj)SPL @rm -f $(obj)tools/xway-swap-bytes diff --git a/README b/README index 18f5233..677c3dc 100644 --- a/README +++ b/README @@ -3167,6 +3167,17 @@ FIT uImage format: option to re-enable it. This will affect the output of the bootm command when booting a FIT image. +- TPL framework + CONFIG_TPL + Enable building of TPL globally. + + CONFIG_TPL_PAD_TO + Image offset to which the TPL should be padded before appending + the TPL payload. By default, this is defined as + CONFIG_SPL_MAX_SIZE, or 0 if CONFIG_SPL_MAX_SIZE is undefined. + CONFIG_SPL_PAD_TO must be either 0, meaning to append the SPL + payload without any padding, or >= CONFIG_SPL_MAX_SIZE. + Modem Support: -------------- @@ -4204,6 +4215,11 @@ Low Level (hardware related) configuration options: that is executed before the actual U-Boot. E.g. when compiling a NAND SPL. +- CONFIG_TPL_BUILD + Modifies the behaviour of start.S when compiling a loader + that is executed after the SPL and before the actual U-Boot. + It is loaded by the SPL. + - CONFIG_SYS_MPC85XX_NO_RESETVEC Only for 85xx systems. If this variable is specified, the section .resetvec is not kept and the section .bootpg is placed in the diff --git a/config.mk b/config.mk index 54e99f4..b3ecaa7 100644 --- a/config.mk +++ b/config.mk @@ -13,6 +13,12 @@ SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ export SHELL +ifeq ($(CONFIG_TPL_BUILD),y) +SPL_BIN := u-boot-tpl +else +SPL_BIN := u-boot-spl +endif + ifeq ($(CURDIR),$(SRCTREE)) dir := else @@ -22,7 +28,11 @@ endif ifneq ($(OBJTREE),$(SRCTREE)) # Create object files for SPL in a separate directory ifeq ($(CONFIG_SPL_BUILD),y) +ifeq ($(CONFIG_TPL_BUILD),y) +obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) +else obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) +endif else obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) endif @@ -32,8 +42,12 @@ $(shell mkdir -p $(obj)) else # Create object files for SPL in a separate directory ifeq ($(CONFIG_SPL_BUILD),y) +ifeq ($(CONFIG_TPL_BUILD),y) +obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) +else obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) +endif $(shell mkdir -p $(obj)) else obj := @@ -145,6 +159,10 @@ CHECK = sparse ######################################################################### # Load generated board configuration +ifeq ($(CONFIG_TPL_BUILD),y) +# Include TPL autoconf +sinclude $(OBJTREE)/include/tpl-autoconf.mk +else ifeq ($(CONFIG_SPL_BUILD),y) # Include SPL autoconf sinclude $(OBJTREE)/include/spl-autoconf.mk @@ -152,6 +170,7 @@ else # Include normal autoconf sinclude $(OBJTREE)/include/autoconf.mk endif +endif sinclude $(OBJTREE)/include/config.mk # Some architecture config.mk files need to know what CPUDIR is set to, @@ -221,12 +240,19 @@ ifneq ($(CONFIG_SPL_PAD_TO),) CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO) endif +ifneq ($(CONFIG_TPL_PAD_TO),) +CPPFLAGS += -DCONFIG_TPL_PAD_TO=$(CONFIG_TPL_PAD_TO) +endif + ifneq ($(CONFIG_UBOOT_PAD_TO),) CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO) endif ifeq ($(CONFIG_SPL_BUILD),y) CPPFLAGS += -DCONFIG_SPL_BUILD +ifeq ($(CONFIG_TPL_BUILD),y) +CPPFLAGS += -DCONFIG_TPL_BUILD +endif endif # Does this architecture support generic board init? @@ -298,9 +324,9 @@ ifneq ($(CONFIG_SYS_TEXT_BASE),) LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) endif -LDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) +LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) ifneq ($(CONFIG_SPL_TEXT_BASE),) -LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE) +LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) endif # Linus' kernel sanity checking tool diff --git a/doc/README.TPL b/doc/README.TPL new file mode 100644 index 0000000..1df03b9 --- /dev/null +++ b/doc/README.TPL @@ -0,0 +1,45 @@ +Generic TPL framework +===================== + +Overview +-------- + +TPL---Third Program Loader. + +Due to the SPL on some boards(powerpc mpc85xx) has a size limit and cannot +be compatible with all the external device(e.g. DDR). So add a tertiary +program loader (TPL) to enable a loader stub loaded by the code from the +SPL. It loads the final uboot image into DDR, then jump to it to begin +execution. Now, only the powerpc mpc85xx has this requirement and will +implemente it. + +Keep consistent with SPL, with this framework almost all source files for a +board can be reused. No code duplication or symlinking is necessary anymore. + +How it works +------------ + +There has been a directory TOPDIR/spl which contains only a Makefile. The +Makefile is shared by SPL and TPL. + +The object files are built separately for SPL/TPL and placed in the +directory spl/tpl. The final binaries which are generated are +u-boot-{spl|tpl}, u-boot-{spl|tpl}.bin and u-boot-{spl|tpl}.map. + +During the TPL build a variable named CONFIG_TPL_BUILD is exported in the +make environment and also appended to CPPFLAGS with -DCONFIG_TPL_BUILD. + +The SPL options are shared by SPL and TPL, the board config file should +determine which SPL options to choose based on whether CONFIG_TPL_BUILD +is set. Source files can be compiled for TPL with options choosed in the +board config file. + +For example: + +spl/Makefile: +LIBS-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/libcommon.o + +CONFIG_SPL_LIBCOMMON_SUPPORT is defined in board config file: +#ifdef CONFIG_TPL_BUILD +#define CONFIG_SPL_LIBCOMMON_SUPPORT +#endif diff --git a/spl/Makefile b/spl/Makefile index a9a8564..339e5e8 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -17,10 +17,22 @@ CONFIG_SPL_BUILD := y export CONFIG_SPL_BUILD +ifeq ($(CONFIG_TPL_BUILD),y) +export CONFIG_TPL_BUILD +SPL_BIN := u-boot-tpl +else +SPL_BIN := u-boot-spl +endif + include $(TOPDIR)/config.mk # We want the final binaries in this directory +ifeq ($(CONFIG_TPL_BUILD),y) +obj := $(OBJTREE)/tpl/ +SPLTREE := $(TPLTREE) +else obj := $(OBJTREE)/spl/ +endif HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n) @@ -161,7 +173,7 @@ $(OBJTREE)/MLO.byteswap: $(obj)u-boot-spl.bin $(OBJTREE)/SPL : $(obj)u-boot-spl.bin depend $(MAKE) -C $(SRCTREE)/arch/arm/imx-common $@ -ALL-y += $(obj)u-boot-spl.bin +ALL-y += $(obj)$(SPL_BIN).bin ifdef CONFIG_SAMSUNG ALL-y += $(obj)$(BOARD)-spl.bin @@ -175,15 +187,15 @@ $(obj)$(BOARD)-spl.bin: $(obj)u-boot-spl.bin $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin endif -$(obj)u-boot-spl.bin: $(obj)u-boot-spl +$(obj)$(SPL_BIN).bin: $(obj)$(SPL_BIN) $(OBJCOPY) $(OBJCFLAGS) -O binary $< $@ GEN_UBOOT = \ cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \ --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \ - -Map u-boot-spl.map -o u-boot-spl + -Map $(SPL_BIN).map -o $(SPL_BIN) -$(obj)u-boot-spl: depend $(START) $(LIBS) $(obj)u-boot-spl.lds +$(obj)$(SPL_BIN): depend $(START) $(LIBS) $(obj)u-boot-spl.lds $(GEN_UBOOT) $(START): depend -- cgit v0.10.2