"Das U-Boot" Source Tree
1Generic xPL framework
2=====================
3
4Overview
5--------
6
7To unify all existing implementations for secondary/tertiary program loaders
8(generically called xPL)
9and to allow simply adding of new implementations this generic xPL framework
10has been created. With this framework almost all source files for a board
11can be reused. No code duplication or symlinking is necessary anymore.
12
13
14How it works
15------------
16
17The object files for xPL are built separately and placed in a subdirectory
18("spl", "tpl" or "vpl").
19The final binaries which are generated for SPL are u-boot-spl, u-boot-spl.bin
20and u-boot-spl.map
21
22A config option named CONFIG_XPL_BUILD is enabled by Kconfig for xPL builds.
23Source files can therefore be compiled for xPL with different settings.
24
25For example::
26
27 ifeq ($(CONFIG_XPL_BUILD),y)
28 obj-y += board_spl.o
29 else
30 obj-y += board.o
31 endif
32
33 obj-$(CONFIG_XPL_BUILD) += foo.o
34
35 if (IS_ENABLED(CONFIG_XPL_BUILD))
36 foo();
37
38 if (xpl_phase() == PHASE_TPL)
39 bar();
40
41The building of xPL images can be enabled by CONFIG_SPL (etc.) options in
42Kconfig.
43
44Because xPL images normally have a different text base, one has to be
45configured by defining CONFIG_xPL_TEXT_BASE. The linker script has to be
46defined with CONFIG_xPL_LDSCRIPT.
47
48To support generic U-Boot libraries and drivers in the xPL binary one can
49optionally define CONFIG_xPL_XXX_SUPPORT. Currently following options
50are supported:
51
52CONFIG_SPL_LIBCOMMON_SUPPORT (common/libcommon.o)
53CONFIG_SPL_LIBDISK_SUPPORT (disk/libdisk.o)
54CONFIG_SPL_I2C (drivers/i2c/libi2c.o)
55CONFIG_SPL_GPIO (drivers/gpio/libgpio.o)
56CONFIG_SPL_MMC (drivers/mmc/libmmc.o)
57CONFIG_SPL_SERIAL (drivers/serial/libserial.o)
58CONFIG_SPL_SPI_FLASH_SUPPORT (drivers/mtd/spi/libspi_flash.o)
59CONFIG_SPL_SPI (drivers/spi/libspi.o)
60CONFIG_SPL_FS_FAT (fs/fat/libfat.o)
61CONFIG_SPL_FS_EXT4
62CONFIG_SPL_LIBGENERIC_SUPPORT (lib/libgeneric.o)
63CONFIG_SPL_POWER (drivers/power/libpower.o)
64CONFIG_SPL_NAND_SUPPORT (drivers/mtd/nand/raw/libnand.o)
65CONFIG_SPL_DRIVERS_MISC (drivers/misc)
66CONFIG_SPL_DMA (drivers/dma/libdma.o)
67CONFIG_SPL_POST_MEM_SUPPORT (post/drivers/memory.o)
68CONFIG_SPL_NAND_LOAD (drivers/mtd/nand/raw/nand_spl_load.o)
69CONFIG_SPL_SPI_LOAD (drivers/mtd/spi/spi_spl_load.o)
70CONFIG_SPL_RAM_DEVICE (common/spl/spl.c)
71CONFIG_SPL_WATCHDOG (drivers/watchdog/libwatchdog.o)
72CONFIG_SPL_SYSCON (drivers/core/syscon-uclass.o)
73CONFIG_SPL_GZIP (lib/gzip.o)
74CONFIG_SPL_VIDEO (drivers/video/video-uclass.o drivers/video/vidconsole-uclass.o)
75CONFIG_SPL_SPLASH_SCREEN (common/splash.o)
76CONFIG_SPL_SPLASH_SOURCE (common/splash_source.o)
77CONFIG_SPL_GPIO (drivers/gpio)
78CONFIG_SPL_DM_GPIO (drivers/gpio/gpio-uclass.o)
79CONFIG_SPL_BMP (drivers/video/bmp.o)
80CONFIG_SPL_BLOBLIST (common/bloblist.o)
81
82Adding xPL-specific code
83------------------------
84
85To check whether a feature is enabled, use CONFIG_IS_ENABLED()::
86
87 if (CONFIG_IS_ENABLED(CLK))
88 ...
89
90This checks CONFIG_CLK for the main build, CONFIG_SPL_CLK for the SPL build,
91CONFIG_TPL_CLK for the TPL build, etc.
92
93U-Boot Boot Phases
94------------------
95
96U-Boot goes through the following boot phases where TPL, VPL, SPL are optional.
97While many boards use SPL, fewer use TPL.
98
99TPL
100 Very early init, as tiny as possible. This loads SPL (or VPL if enabled).
101
102VPL
103 Optional verification step, which can select one of several SPL binaries,
104 if A/B verified boot is enabled. Implementation of the VPL logic is
105 work-in-progress. For now it just boots into SPL.
106
107SPL
108 Secondary program loader. Sets up SDRAM and loads U-Boot proper. It may also
109 load other firmware components.
110
111U-Boot
112 U-Boot proper, containing the command line and boot logic.
113
114Further usages of U-Boot SPL comprise:
115
116* Launching BL31 of ARM Trusted Firmware which invokes main U-Boot as BL33
117* launching EDK II
118* launching Linux kernel
119* launching RISC-V OpenSBI which invokes main U-Boot
120
121Checking the boot phase
122-----------------------
123
124Use `xpl_phase()` to find the current U-Boot phase, e.g. `PHASE_SPL`. You can
125also find the previous and next phase and get the phase name.
126
127
128.. _fdtgrep_filter:
129
130Device tree
131-----------
132The U-Boot device tree is filtered by the fdtgrep tools during the build
133process to generate a much smaller device tree used in SPL (spl/u-boot-spl.dtb)
134with:
135
136- the mandatory nodes (/alias, /chosen, /config)
137- the nodes with one pre-relocation property:
138 'bootph-all' or 'bootph-pre-ram'
139
140fdtgrep is also used to remove:
141
142- the properties defined in CONFIG_OF_SPL_REMOVE_PROPS
143- all the pre-relocation properties
144 ('bootph-all', 'bootph-pre-ram' (SPL), 'bootph-pre-sram' (TPL) and
145 'bootph-verify' (TPL))
146
147All the nodes remaining in the SPL devicetree are bound
148(see doc/driver-model/design.rst).
149
150NOTE: U-Boot migrated to a new schema for the u-boot,dm-* tags in 2023. Please
151update to use the new bootph-* tags as described in the
152doc/device-tree-bindings/bootph.yaml binding file.
153
154Debugging
155---------
156
157When building SPL with DEBUG set you may also need to set CONFIG_PANIC_HANG
158as in most cases do_reset is not defined within SPL.
159
160
161Estimating stack usage
162----------------------
163
164With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate
165stack usage at various points in run sequence of SPL. The -fstack-usage option
166to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that
167will give stack usage information and cflow can construct program flow.
168
169Must have gcc 4.6 or later, which supports -fstack-usage:
170
171#. Build normally
172#. Perform the following shell command to generate a list of C files used in
173 SPL:
174#. `find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list`
175#. Execute cflow:
176 `$ cflow --main=board_init_r $(cat used-spl.list) 2>&1 | $PAGER`
177
178cflow will spit out a number of warnings as it does not parse
179the config files and picks functions based on #ifdef. Parsing the '.i'
180files instead introduces another set of headaches. These warnings are
181not usually important to understanding the flow, however.
182
183
184Reserving memory in xPL
185-----------------------
186
187If memory needs to be reserved in RAM during an xPL phase with the requirement
188that the xPL reserved memory remains preserved across further boot phases too
189then it needs to be reserved mandatorily starting from end of RAM. This is to
190ensure that further phases can simply skip this region before carrying out
191further reservations or updating the relocation address.
192
193Also out of these regions which are to be preserved across further phases of
194boot, video framebuffer memory region must be reserved first starting from
195end of RAM for which the helper function spl_reserve_video_from_ram_top() is
196provided
197which makes sure that video memory is placed at the top of reservation area with
198further reservations below it.
199
200The reservation information for these regions can be passed to the
201further boot phases using a bloblist. For e.g. the information for the
202framebuffer area reserved by xPL can be passed onto U-Boot using
203BLOBLISTT_U_BOOT_VIDEO
204
205The further boot phases need to parse each of the blobs passed from xPL phase
206starting from video bloblist and skip this whole xPL reserved-memory area from
207end of RAM as per the blobs received, before carrying out further
208reservations or updating the relocation address. For e.g, U-Boot proper uses
209function setup_relocaddr_from_bloblist() to parse the bloblist passed from
210previous phase and skip the memory reserved from previous phase accordingly.