Commit 3aa29de0b04be9d56251474d1036b23da249f607

Authored by Ying Zhang
Committed by York Sun
1 parent 382ce7e909

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 <b40530@freescale.com>
Acked-by: York Sun <yorksun@freescale.com>

Showing 5 changed files with 147 additions and 14 deletions Side-by-side Diff

... ... @@ -102,10 +102,11 @@
102 102  
103 103 OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
104 104 SPLTREE := $(OBJTREE)/spl
  105 +TPLTREE := $(OBJTREE)/tpl
105 106 SRCTREE := $(CURDIR)
106 107 TOPDIR := $(SRCTREE)
107 108 LNDIR := $(OBJTREE)
108   -export TOPDIR SRCTREE OBJTREE SPLTREE
  109 +export TOPDIR SRCTREE OBJTREE SPLTREE TPLTREE
109 110  
110 111 MKCONFIG := $(SRCTREE)/mkconfig
111 112 export MKCONFIG
... ... @@ -397,6 +398,7 @@
397 398 ALL-$(CONFIG_NAND_U_BOOT) += $(obj)u-boot-nand.bin
398 399 ALL-$(CONFIG_ONENAND_U_BOOT) += $(obj)u-boot-onenand.bin
399 400 ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin
  401 +ALL-$(CONFIG_TPL) += $(obj)tpl/u-boot-tpl.bin
400 402 ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin
401 403 ifneq ($(CONFIG_SPL_TARGET),)
402 404 ALL-$(CONFIG_SPL) += $(obj)$(subst ",,$(CONFIG_SPL_TARGET))
403 405  
404 406  
405 407  
... ... @@ -475,14 +477,26 @@
475 477 $(obj)u-boot.dis: $(obj)u-boot
476 478 $(OBJDUMP) -d $< > $@
477 479  
  480 +# $@ is output, $(1) and $(2) are inputs, $(3) is padded intermediate,
  481 +# $(4) is pad-to
  482 +SPL_PAD_APPEND = \
  483 + $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(4) -I binary -O binary \
  484 + $(1) $(obj)$(3); \
  485 + cat $(obj)$(3) $(obj)$(2) > $@; \
  486 + rm $(obj)$(3)
478 487  
  488 +ifdef CONFIG_TPL
  489 +SPL_PAYLOAD := $(obj)tpl/u-boot-with-tpl.bin
  490 +else
  491 +SPL_PAYLOAD := $(obj)u-boot.bin
  492 +endif
479 493  
480   -$(obj)u-boot-with-spl.bin: $(obj)spl/u-boot-spl.bin $(obj)u-boot.bin
481   - $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(CONFIG_SPL_PAD_TO) \
482   - -I binary -O binary $< $(obj)spl/u-boot-spl-pad.bin
483   - cat $(obj)spl/u-boot-spl-pad.bin $(obj)u-boot.bin > $@
484   - rm $(obj)spl/u-boot-spl-pad.bin
  494 +$(obj)u-boot-with-spl.bin: $(obj)spl/u-boot-spl.bin $(SPL_PAYLOAD)
  495 + $(call SPL_PAD_APPEND,$<,$(SPL_PAYLOAD),spl/u-boot-spl-pad.bin,$(CONFIG_SPL_PAD_TO))
485 496  
  497 +$(obj)tpl/u-boot-with-tpl.bin: $(obj)tpl/u-boot-tpl.bin $(obj)u-boot.bin
  498 + $(call SPL_PAD_APPEND,$<,u-boot.bin,tpl/u-boot-tpl-pad.bin,$(CONFIG_TPL_PAD_TO))
  499 +
486 500 $(obj)u-boot-with-spl.imx: $(obj)spl/u-boot-spl.bin $(obj)u-boot.bin
487 501 $(MAKE) -C $(SRCTREE)/arch/arm/imx-common \
488 502 $(OBJTREE)/u-boot-with-spl.imx
... ... @@ -607,6 +621,9 @@
607 621 $(obj)spl/u-boot-spl.bin: $(SUBDIR_TOOLS) depend
608 622 $(MAKE) -C spl all
609 623  
  624 +$(obj)tpl/u-boot-tpl.bin: $(SUBDIR_TOOLS) depend
  625 + $(MAKE) -C spl all CONFIG_TPL_BUILD=y
  626 +
610 627 updater:
611 628 $(MAKE) -C tools/updater all
612 629  
... ... @@ -614,6 +631,7 @@
614 631 # parallel sub-makes creating .depend files simultaneously.
615 632 depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \
616 633 $(obj)include/spl-autoconf.mk \
  634 + $(obj)include/tpl-autoconf.mk \
617 635 $(obj)include/autoconf.mk \
618 636 $(obj)include/generated/generic-asm-offsets.h \
619 637 $(obj)include/generated/asm-offsets.h
... ... @@ -696,6 +714,15 @@
696 714 mv $@.tmp $@
697 715  
698 716 # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
  717 +$(obj)include/tpl-autoconf.mk: $(obj)include/config.h
  718 + @$(XECHO) Generating $@ ; \
  719 + set -e ; \
  720 + : Extract the config macros ; \
  721 + $(CPP) $(CFLAGS) -DCONFIG_TPL_BUILD -DCONFIG_SPL_BUILD\
  722 + -DDO_DEPS_ONLY -dM include/common.h | \
  723 + sed -n -f tools/scripts/define2mk.sed > $@.tmp && \
  724 + mv $@.tmp $@
  725 +
699 726 $(obj)include/spl-autoconf.mk: $(obj)include/config.h
700 727 @$(XECHO) Generating $@ ; \
701 728 set -e ; \
702 729  
... ... @@ -706,12 +733,14 @@
706 733  
707 734 $(obj)include/generated/generic-asm-offsets.h: $(obj)include/autoconf.mk.dep \
708 735 $(obj)include/spl-autoconf.mk \
  736 + $(obj)include/tpl-autoconf.mk \
709 737 $(obj)lib/asm-offsets.s
710 738 @$(XECHO) Generating $@
711 739 tools/scripts/make-asm-offsets $(obj)lib/asm-offsets.s $@
712 740  
713 741 $(obj)lib/asm-offsets.s: $(obj)include/autoconf.mk.dep \
714 742 $(obj)include/spl-autoconf.mk \
  743 + $(obj)include/tpl-autoconf.mk \
715 744 $(src)lib/asm-offsets.c
716 745 @mkdir -p $(obj)lib
717 746 $(CC) -DDO_DEPS_ONLY \
718 747  
... ... @@ -720,12 +749,14 @@
720 749  
721 750 $(obj)include/generated/asm-offsets.h: $(obj)include/autoconf.mk.dep \
722 751 $(obj)include/spl-autoconf.mk \
  752 + $(obj)include/tpl-autoconf.mk \
723 753 $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s
724 754 @$(XECHO) Generating $@
725 755 tools/scripts/make-asm-offsets $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s $@
726 756  
727 757 $(obj)$(CPUDIR)/$(SOC)/asm-offsets.s: $(obj)include/autoconf.mk.dep \
728   - $(obj)include/spl-autoconf.mk
  758 + $(obj)include/spl-autoconf.mk \
  759 + $(obj)include/tpl-autoconf.mk
729 760 @mkdir -p $(obj)$(CPUDIR)/$(SOC)
730 761 if [ -f $(src)$(CPUDIR)/$(SOC)/asm-offsets.c ];then \
731 762 $(CC) -DDO_DEPS_ONLY \
... ... @@ -798,7 +829,8 @@
798 829 @rm -f $(obj)include/config.h $(obj)include/config.mk \
799 830 $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \
800 831 $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep \
801   - $(obj)include/spl-autoconf.mk
  832 + $(obj)include/spl-autoconf.mk \
  833 + $(obj)include/tpl-autoconf.mk
802 834  
803 835 %_config:: unconfig
804 836 @$(MKCONFIG) -A $(@:_config=)
... ... @@ -884,6 +916,8 @@
884 916 @rm -f $(obj)nand_spl/{u-boot-nand_spl.lds,u-boot-spl,u-boot-spl.map}
885 917 @rm -f $(obj)spl/{u-boot-spl,u-boot-spl.bin,u-boot-spl.map}
886 918 @rm -f $(obj)spl/u-boot-spl.lds
  919 + @rm -f $(obj)tpl/{u-boot-tpl,u-boot-tpl.bin,u-boot-tpl.map}
  920 + @rm -f $(obj)tpl/u-boot-spl.lds
887 921 @rm -f $(obj)MLO MLO.byteswap
888 922 @rm -f $(obj)SPL
889 923 @rm -f $(obj)tools/xway-swap-bytes
... ... @@ -3167,6 +3167,17 @@
3167 3167 option to re-enable it. This will affect the output of the
3168 3168 bootm command when booting a FIT image.
3169 3169  
  3170 +- TPL framework
  3171 + CONFIG_TPL
  3172 + Enable building of TPL globally.
  3173 +
  3174 + CONFIG_TPL_PAD_TO
  3175 + Image offset to which the TPL should be padded before appending
  3176 + the TPL payload. By default, this is defined as
  3177 + CONFIG_SPL_MAX_SIZE, or 0 if CONFIG_SPL_MAX_SIZE is undefined.
  3178 + CONFIG_SPL_PAD_TO must be either 0, meaning to append the SPL
  3179 + payload without any padding, or >= CONFIG_SPL_MAX_SIZE.
  3180 +
3170 3181 Modem Support:
3171 3182 --------------
3172 3183  
... ... @@ -4203,6 +4214,11 @@
4203 4214 Modifies the behaviour of start.S when compiling a loader
4204 4215 that is executed before the actual U-Boot. E.g. when
4205 4216 compiling a NAND SPL.
  4217 +
  4218 +- CONFIG_TPL_BUILD
  4219 + Modifies the behaviour of start.S when compiling a loader
  4220 + that is executed after the SPL and before the actual U-Boot.
  4221 + It is loaded by the SPL.
4206 4222  
4207 4223 - CONFIG_SYS_MPC85XX_NO_RESETVEC
4208 4224 Only for 85xx systems. If this variable is specified, the section
... ... @@ -13,6 +13,12 @@
13 13  
14 14 export SHELL
15 15  
  16 +ifeq ($(CONFIG_TPL_BUILD),y)
  17 +SPL_BIN := u-boot-tpl
  18 +else
  19 +SPL_BIN := u-boot-spl
  20 +endif
  21 +
16 22 ifeq ($(CURDIR),$(SRCTREE))
17 23 dir :=
18 24 else
19 25  
... ... @@ -22,7 +28,11 @@
22 28 ifneq ($(OBJTREE),$(SRCTREE))
23 29 # Create object files for SPL in a separate directory
24 30 ifeq ($(CONFIG_SPL_BUILD),y)
  31 +ifeq ($(CONFIG_TPL_BUILD),y)
  32 +obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  33 +else
25 34 obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  35 +endif
26 36 else
27 37 obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
28 38 endif
29 39  
... ... @@ -32,8 +42,12 @@
32 42 else
33 43 # Create object files for SPL in a separate directory
34 44 ifeq ($(CONFIG_SPL_BUILD),y)
  45 +ifeq ($(CONFIG_TPL_BUILD),y)
  46 +obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  47 +else
35 48 obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
36 49  
  50 +endif
37 51 $(shell mkdir -p $(obj))
38 52 else
39 53 obj :=
... ... @@ -145,6 +159,10 @@
145 159 #########################################################################
146 160  
147 161 # Load generated board configuration
  162 +ifeq ($(CONFIG_TPL_BUILD),y)
  163 +# Include TPL autoconf
  164 +sinclude $(OBJTREE)/include/tpl-autoconf.mk
  165 +else
148 166 ifeq ($(CONFIG_SPL_BUILD),y)
149 167 # Include SPL autoconf
150 168 sinclude $(OBJTREE)/include/spl-autoconf.mk
... ... @@ -152,6 +170,7 @@
152 170 # Include normal autoconf
153 171 sinclude $(OBJTREE)/include/autoconf.mk
154 172 endif
  173 +endif
155 174 sinclude $(OBJTREE)/include/config.mk
156 175  
157 176 # Some architecture config.mk files need to know what CPUDIR is set to,
158 177  
159 178  
... ... @@ -221,13 +240,20 @@
221 240 CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO)
222 241 endif
223 242  
  243 +ifneq ($(CONFIG_TPL_PAD_TO),)
  244 +CPPFLAGS += -DCONFIG_TPL_PAD_TO=$(CONFIG_TPL_PAD_TO)
  245 +endif
  246 +
224 247 ifneq ($(CONFIG_UBOOT_PAD_TO),)
225 248 CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO)
226 249 endif
227 250  
228 251 ifeq ($(CONFIG_SPL_BUILD),y)
229 252 CPPFLAGS += -DCONFIG_SPL_BUILD
  253 +ifeq ($(CONFIG_TPL_BUILD),y)
  254 +CPPFLAGS += -DCONFIG_TPL_BUILD
230 255 endif
  256 +endif
231 257  
232 258 # Does this architecture support generic board init?
233 259 ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
234 260  
... ... @@ -298,9 +324,9 @@
298 324 LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
299 325 endif
300 326  
301   -LDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  327 +LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
302 328 ifneq ($(CONFIG_SPL_TEXT_BASE),)
303   -LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE)
  329 +LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
304 330 endif
305 331  
306 332 # Linus' kernel sanity checking tool
  1 +Generic TPL framework
  2 +=====================
  3 +
  4 +Overview
  5 +--------
  6 +
  7 +TPL---Third Program Loader.
  8 +
  9 +Due to the SPL on some boards(powerpc mpc85xx) has a size limit and cannot
  10 +be compatible with all the external device(e.g. DDR). So add a tertiary
  11 +program loader (TPL) to enable a loader stub loaded by the code from the
  12 +SPL. It loads the final uboot image into DDR, then jump to it to begin
  13 +execution. Now, only the powerpc mpc85xx has this requirement and will
  14 +implemente it.
  15 +
  16 +Keep consistent with SPL, with this framework almost all source files for a
  17 +board can be reused. No code duplication or symlinking is necessary anymore.
  18 +
  19 +How it works
  20 +------------
  21 +
  22 +There has been a directory TOPDIR/spl which contains only a Makefile. The
  23 +Makefile is shared by SPL and TPL.
  24 +
  25 +The object files are built separately for SPL/TPL and placed in the
  26 +directory spl/tpl. The final binaries which are generated are
  27 +u-boot-{spl|tpl}, u-boot-{spl|tpl}.bin and u-boot-{spl|tpl}.map.
  28 +
  29 +During the TPL build a variable named CONFIG_TPL_BUILD is exported in the
  30 +make environment and also appended to CPPFLAGS with -DCONFIG_TPL_BUILD.
  31 +
  32 +The SPL options are shared by SPL and TPL, the board config file should
  33 +determine which SPL options to choose based on whether CONFIG_TPL_BUILD
  34 +is set. Source files can be compiled for TPL with options choosed in the
  35 +board config file.
  36 +
  37 +For example:
  38 +
  39 +spl/Makefile:
  40 +LIBS-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/libcommon.o
  41 +
  42 +CONFIG_SPL_LIBCOMMON_SUPPORT is defined in board config file:
  43 +#ifdef CONFIG_TPL_BUILD
  44 +#define CONFIG_SPL_LIBCOMMON_SUPPORT
  45 +#endif
... ... @@ -17,10 +17,22 @@
17 17 CONFIG_SPL_BUILD := y
18 18 export CONFIG_SPL_BUILD
19 19  
  20 +ifeq ($(CONFIG_TPL_BUILD),y)
  21 +export CONFIG_TPL_BUILD
  22 +SPL_BIN := u-boot-tpl
  23 +else
  24 +SPL_BIN := u-boot-spl
  25 +endif
  26 +
20 27 include $(TOPDIR)/config.mk
21 28  
22 29 # We want the final binaries in this directory
  30 +ifeq ($(CONFIG_TPL_BUILD),y)
  31 +obj := $(OBJTREE)/tpl/
  32 +SPLTREE := $(TPLTREE)
  33 +else
23 34 obj := $(OBJTREE)/spl/
  35 +endif
24 36  
25 37 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n)
26 38  
... ... @@ -161,7 +173,7 @@
161 173 $(OBJTREE)/SPL : $(obj)u-boot-spl.bin depend
162 174 $(MAKE) -C $(SRCTREE)/arch/arm/imx-common $@
163 175  
164   -ALL-y += $(obj)u-boot-spl.bin
  176 +ALL-y += $(obj)$(SPL_BIN).bin
165 177  
166 178 ifdef CONFIG_SAMSUNG
167 179 ALL-y += $(obj)$(BOARD)-spl.bin
168 180  
169 181  
... ... @@ -175,15 +187,15 @@
175 187 $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin
176 188 endif
177 189  
178   -$(obj)u-boot-spl.bin: $(obj)u-boot-spl
  190 +$(obj)$(SPL_BIN).bin: $(obj)$(SPL_BIN)
179 191 $(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
180 192  
181 193 GEN_UBOOT = \
182 194 cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \
183 195 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
184   - -Map u-boot-spl.map -o u-boot-spl
  196 + -Map $(SPL_BIN).map -o $(SPL_BIN)
185 197  
186   -$(obj)u-boot-spl: depend $(START) $(LIBS) $(obj)u-boot-spl.lds
  198 +$(obj)$(SPL_BIN): depend $(START) $(LIBS) $(obj)u-boot-spl.lds
187 199 $(GEN_UBOOT)
188 200  
189 201 $(START): depend