xref: /OK3568_Linux_fs/u-boot/include/spl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2012
3*4882a593Smuzhiyun  * Texas Instruments, <www.ti.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef	_SPL_H_
8*4882a593Smuzhiyun #define	_SPL_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /* Platform-specific defines */
11*4882a593Smuzhiyun #include <mmc.h>
12*4882a593Smuzhiyun #include <linux/compiler.h>
13*4882a593Smuzhiyun #include <asm/spl.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /* Value in r0 indicates we booted from U-Boot */
16*4882a593Smuzhiyun #define UBOOT_NOT_LOADED_FROM_SPL	0x13578642
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Boot type */
19*4882a593Smuzhiyun #define MMCSD_MODE_UNDEFINED	0
20*4882a593Smuzhiyun #define MMCSD_MODE_RAW		1
21*4882a593Smuzhiyun #define MMCSD_MODE_FS		2
22*4882a593Smuzhiyun #define MMCSD_MODE_EMMCBOOT	3
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define SPL_NEXT_STAGE_UNDEFINED	0
25*4882a593Smuzhiyun #define SPL_NEXT_STAGE_UBOOT		1
26*4882a593Smuzhiyun #define SPL_NEXT_STAGE_KERNEL		2
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun struct spl_image_info {
29*4882a593Smuzhiyun 	const char *name;
30*4882a593Smuzhiyun 	u8 os;
31*4882a593Smuzhiyun 	uintptr_t load_addr;
32*4882a593Smuzhiyun 	uintptr_t entry_point;		/* Next stage entry point */
33*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(ATF)
34*4882a593Smuzhiyun 	uintptr_t entry_point_bl32;
35*4882a593Smuzhiyun 	uintptr_t entry_point_bl33;
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(OPTEE) || CONFIG_IS_ENABLED(KERNEL_BOOT)
38*4882a593Smuzhiyun 	uintptr_t entry_point_os;	/* point to uboot or kernel */
39*4882a593Smuzhiyun #endif
40*4882a593Smuzhiyun 	void *fdt_addr;
41*4882a593Smuzhiyun 	u32 boot_device;
42*4882a593Smuzhiyun 	u32 next_stage;
43*4882a593Smuzhiyun 	u32 size;
44*4882a593Smuzhiyun 	u32 flags;
45*4882a593Smuzhiyun 	void *arg;
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /*
49*4882a593Smuzhiyun  * Information required to load data from a device
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * @dev: Pointer to the device, e.g. struct mmc *
52*4882a593Smuzhiyun  * @priv: Private data for the device
53*4882a593Smuzhiyun  * @bl_len: Block length for reading in bytes
54*4882a593Smuzhiyun  * @filename: Name of the fit image file.
55*4882a593Smuzhiyun  * @read: Function to call to read from the device
56*4882a593Smuzhiyun  */
57*4882a593Smuzhiyun struct spl_load_info {
58*4882a593Smuzhiyun 	void *dev;
59*4882a593Smuzhiyun 	void *priv;
60*4882a593Smuzhiyun 	int bl_len;
61*4882a593Smuzhiyun 	const char *filename;
62*4882a593Smuzhiyun 	ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
63*4882a593Smuzhiyun 		      void *buf);
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /**
67*4882a593Smuzhiyun  * spl_load_simple_fit() - Loads a fit image from a device.
68*4882a593Smuzhiyun  * @spl_image:	Image description to set up
69*4882a593Smuzhiyun  * @info:	Structure containing the information required to load data.
70*4882a593Smuzhiyun  * @sector:	Sector number where FIT image is located in the device
71*4882a593Smuzhiyun  * @fdt:	Pointer to the copied FIT header.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * Reads the FIT image @sector in the device. Loads u-boot image to
74*4882a593Smuzhiyun  * specified load address and copies the dtb to end of u-boot image.
75*4882a593Smuzhiyun  * Returns 0 on success.
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun int spl_load_simple_fit(struct spl_image_info *spl_image,
78*4882a593Smuzhiyun 			struct spl_load_info *info, ulong sector, void *fdt);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #define SPL_COPY_PAYLOAD_ONLY	1
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /* SPL common functions */
83*4882a593Smuzhiyun void preloader_console_init(void);
84*4882a593Smuzhiyun u32 spl_boot_device(void);
85*4882a593Smuzhiyun u32 spl_boot_mode(const u32 boot_device);
86*4882a593Smuzhiyun void spl_next_stage(struct spl_image_info *spl);
87*4882a593Smuzhiyun void spl_set_bd(void);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /**
90*4882a593Smuzhiyun  * spl_set_header_raw_uboot() - Set up a standard SPL image structure
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * This sets up the given spl_image which the standard values obtained from
93*4882a593Smuzhiyun  * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
94*4882a593Smuzhiyun  * CONFIG_SYS_TEXT_BASE.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * @spl_image: Image description to set up
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun /**
101*4882a593Smuzhiyun  * spl_parse_image_header() - parse the image header and set up info
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * This parses the legacy image header information at @header and sets up
104*4882a593Smuzhiyun  * @spl_image according to what is found. If no image header is found, then
105*4882a593Smuzhiyun  * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is
106*4882a593Smuzhiyun  * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not
107*4882a593Smuzhiyun  * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using
108*4882a593Smuzhiyun  * spl_set_header_raw_uboot(), or possibly the bootz header.
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * @spl_image: Image description to set up
111*4882a593Smuzhiyun  * @header image header to parse
112*4882a593Smuzhiyun  * @return 0 if a header was correctly parsed, -ve on error
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun int spl_parse_image_header(struct spl_image_info *spl_image,
115*4882a593Smuzhiyun 			   const struct image_header *header);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun void spl_board_prepare_for_linux(void);
118*4882a593Smuzhiyun void spl_board_prepare_for_boot(void);
119*4882a593Smuzhiyun int spl_board_ubi_load_image(u32 boot_device);
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /**
122*4882a593Smuzhiyun  * jump_to_image_linux() - Jump to a Linux kernel from SPL
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  * This jumps into a Linux kernel using the information in @spl_image.
125*4882a593Smuzhiyun  *
126*4882a593Smuzhiyun  * @spl_image: Image description to set up
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /**
131*4882a593Smuzhiyun  * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
132*4882a593Smuzhiyun  *
133*4882a593Smuzhiyun  * This is called by the various SPL loaders to determine whether the board
134*4882a593Smuzhiyun  * wants to load the kernel or U-Boot. This function should be provided by
135*4882a593Smuzhiyun  * the board.
136*4882a593Smuzhiyun  *
137*4882a593Smuzhiyun  * @return 0 if SPL should start the kernel, 1 if U-Boot must be started
138*4882a593Smuzhiyun  */
139*4882a593Smuzhiyun int spl_start_uboot(void);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /**
142*4882a593Smuzhiyun  * spl_display_print() - Display a board-specific message in SPL
143*4882a593Smuzhiyun  *
144*4882a593Smuzhiyun  * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function
145*4882a593Smuzhiyun  * immediately after displaying the SPL console banner ("U-Boot SPL ...").
146*4882a593Smuzhiyun  * This function should be provided by the board.
147*4882a593Smuzhiyun  */
148*4882a593Smuzhiyun void spl_display_print(void);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun  * struct spl_boot_device - Describes a boot device used by SPL
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * @boot_device: A number indicating the BOOT_DEVICE type. There are various
154*4882a593Smuzhiyun  * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently
155*4882a593Smuzhiyun  * numbered.
156*4882a593Smuzhiyun  * @boot_device_name: Named boot device, or NULL if none.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * Note: Additional fields can be added here, bearing in mind that SPL is
159*4882a593Smuzhiyun  * size-sensitive and common fields will be present on all boards. This
160*4882a593Smuzhiyun  * struct can also be used to return additional information about the load
161*4882a593Smuzhiyun  * process if that becomes useful.
162*4882a593Smuzhiyun  */
163*4882a593Smuzhiyun struct spl_boot_device {
164*4882a593Smuzhiyun 	uint boot_device;
165*4882a593Smuzhiyun 	const char *boot_device_name;
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun  * Holds information about a way of loading an SPL image
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * @name: User-friendly name for this method (e.g. "MMC")
172*4882a593Smuzhiyun  * @boot_device: Boot device that this loader supports
173*4882a593Smuzhiyun  * @load_image: Function to call to load image
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun struct spl_image_loader {
176*4882a593Smuzhiyun #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
177*4882a593Smuzhiyun 	const char *name;
178*4882a593Smuzhiyun #endif
179*4882a593Smuzhiyun 	uint boot_device;
180*4882a593Smuzhiyun 	/**
181*4882a593Smuzhiyun 	 * load_image() - Load an SPL image
182*4882a593Smuzhiyun 	 *
183*4882a593Smuzhiyun 	 * @spl_image: place to put image information
184*4882a593Smuzhiyun 	 * @bootdev: describes the boot device to load from
185*4882a593Smuzhiyun 	 */
186*4882a593Smuzhiyun 	int (*load_image)(struct spl_image_info *spl_image,
187*4882a593Smuzhiyun 			  struct spl_boot_device *bootdev);
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /* Declare an SPL image loader */
191*4882a593Smuzhiyun #define SPL_LOAD_IMAGE(__name)					\
192*4882a593Smuzhiyun 	ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun /*
195*4882a593Smuzhiyun  * _priority is the priority of this method, 0 meaning it will be the top
196*4882a593Smuzhiyun  * choice for this device, 9 meaning it is the bottom choice.
197*4882a593Smuzhiyun  * _boot_device is the BOOT_DEVICE_... value
198*4882a593Smuzhiyun  * _method is the load_image function to call
199*4882a593Smuzhiyun  */
200*4882a593Smuzhiyun #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
201*4882a593Smuzhiyun #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
202*4882a593Smuzhiyun 	SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \
203*4882a593Smuzhiyun 		.name = _name, \
204*4882a593Smuzhiyun 		.boot_device = _boot_device, \
205*4882a593Smuzhiyun 		.load_image = _method, \
206*4882a593Smuzhiyun 	}
207*4882a593Smuzhiyun #else
208*4882a593Smuzhiyun #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
209*4882a593Smuzhiyun 	SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \
210*4882a593Smuzhiyun 		.boot_device = _boot_device, \
211*4882a593Smuzhiyun 		.load_image = _method, \
212*4882a593Smuzhiyun 	}
213*4882a593Smuzhiyun #endif
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun /* SPL FAT image functions */
216*4882a593Smuzhiyun int spl_load_image_fat(struct spl_image_info *spl_image,
217*4882a593Smuzhiyun 		       struct blk_desc *block_dev, int partition,
218*4882a593Smuzhiyun 		       const char *filename);
219*4882a593Smuzhiyun int spl_load_image_fat_os(struct spl_image_info *spl_image,
220*4882a593Smuzhiyun 			  struct blk_desc *block_dev, int partition);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun /* SPL EXT image functions */
225*4882a593Smuzhiyun int spl_load_image_ext(struct spl_image_info *spl_image,
226*4882a593Smuzhiyun 		       struct blk_desc *block_dev, int partition,
227*4882a593Smuzhiyun 		       const char *filename);
228*4882a593Smuzhiyun int spl_load_image_ext_os(struct spl_image_info *spl_image,
229*4882a593Smuzhiyun 			  struct blk_desc *block_dev, int partition);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /**
232*4882a593Smuzhiyun  * spl_early_init() - Set up device tree and driver model in SPL if enabled
233*4882a593Smuzhiyun  *
234*4882a593Smuzhiyun  * Call this function in board_init_f() if you want to use device tree and
235*4882a593Smuzhiyun  * driver model early, before board_init_r() is called.
236*4882a593Smuzhiyun  *
237*4882a593Smuzhiyun  * If this is not called, then driver model will be inactive in SPL's
238*4882a593Smuzhiyun  * board_init_f(), and no device tree will be available.
239*4882a593Smuzhiyun  */
240*4882a593Smuzhiyun int spl_early_init(void);
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun /**
243*4882a593Smuzhiyun  * spl_init() - Set up device tree and driver model in SPL if enabled
244*4882a593Smuzhiyun  *
245*4882a593Smuzhiyun  * You can optionally call spl_early_init(), then optionally call spl_init().
246*4882a593Smuzhiyun  * This function will be called from board_init_r() if not called earlier.
247*4882a593Smuzhiyun  *
248*4882a593Smuzhiyun  * Both spl_early_init() and spl_init() perform a similar function except that
249*4882a593Smuzhiyun  * the latter will not set up the malloc() area if
250*4882a593Smuzhiyun  * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to
251*4882a593Smuzhiyun  * already be done by a calll to spl_relocate_stack_gd() before board_init_r()
252*4882a593Smuzhiyun  * is reached.
253*4882a593Smuzhiyun  *
254*4882a593Smuzhiyun  * This function will be called from board_init_r() if not called earlier.
255*4882a593Smuzhiyun  *
256*4882a593Smuzhiyun  * If this is not called, then driver model will be inactive in SPL's
257*4882a593Smuzhiyun  * board_init_f(), and no device tree will be available.
258*4882a593Smuzhiyun  */
259*4882a593Smuzhiyun int spl_init(void);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun #ifdef CONFIG_SPL_BOARD_INIT
262*4882a593Smuzhiyun void spl_board_init(void);
263*4882a593Smuzhiyun #endif
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun /**
266*4882a593Smuzhiyun  * spl_was_boot_source() - check if U-Boot booted from SPL
267*4882a593Smuzhiyun  *
268*4882a593Smuzhiyun  * This will normally be true, but if U-Boot jumps to second U-Boot, it will
269*4882a593Smuzhiyun  * be false. This should be implemented by board-specific code.
270*4882a593Smuzhiyun  *
271*4882a593Smuzhiyun  * @return true if U-Boot booted from SPL, else false
272*4882a593Smuzhiyun  */
273*4882a593Smuzhiyun bool spl_was_boot_source(void);
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /**
276*4882a593Smuzhiyun  * spl_dfu_cmd- run dfu command with chosen mmc device interface
277*4882a593Smuzhiyun  * @param usb_index - usb controller number
278*4882a593Smuzhiyun  * @param mmc_dev -  mmc device nubmer
279*4882a593Smuzhiyun  *
280*4882a593Smuzhiyun  * @return 0 on success, otherwise error code
281*4882a593Smuzhiyun  */
282*4882a593Smuzhiyun int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device);
285*4882a593Smuzhiyun int spl_mmc_load_image(struct spl_image_info *spl_image,
286*4882a593Smuzhiyun 		       struct spl_boot_device *bootdev);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun /**
289*4882a593Smuzhiyun  * spl_invoke_atf - boot using an ARM trusted firmware image
290*4882a593Smuzhiyun  */
291*4882a593Smuzhiyun void spl_invoke_atf(struct spl_image_info *spl_image);
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun /**
294*4882a593Smuzhiyun  * bl31_entry - Fill bl31_params structure, and jump to bl31
295*4882a593Smuzhiyun  */
296*4882a593Smuzhiyun void bl31_entry(struct spl_image_info *spl_image,
297*4882a593Smuzhiyun 		uintptr_t bl31_entry, uintptr_t bl32_entry,
298*4882a593Smuzhiyun 		uintptr_t bl33_entry, uintptr_t fdt_addr);
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun  * spl_optee_entry - entry function for optee
302*4882a593Smuzhiyun  *
303*4882a593Smuzhiyun  * args defind in op-tee project
304*4882a593Smuzhiyun  * https://github.com/OP-TEE/optee_os/
305*4882a593Smuzhiyun  * core/arch/arm/kernel/generic_entry_a32.S
306*4882a593Smuzhiyun  * @arg0: pagestore
307*4882a593Smuzhiyun  * @arg1: (ARMv7 standard bootarg #1)
308*4882a593Smuzhiyun  * @arg2: device tree address, (ARMv7 standard bootarg #2)
309*4882a593Smuzhiyun  * @arg3: non-secure entry address (ARMv7 bootarg #0)
310*4882a593Smuzhiyun  */
311*4882a593Smuzhiyun void spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun /**
314*4882a593Smuzhiyun  * board_return_to_bootrom - allow for boards to continue with the boot ROM
315*4882a593Smuzhiyun  *
316*4882a593Smuzhiyun  * If a board (e.g. the Rockchip RK3368 boards) provide some
317*4882a593Smuzhiyun  * supporting functionality for SPL in their boot ROM and the SPL
318*4882a593Smuzhiyun  * stage wants to return to the ROM code to continue booting, boards
319*4882a593Smuzhiyun  * can implement 'board_return_to_bootrom'.
320*4882a593Smuzhiyun  */
321*4882a593Smuzhiyun void board_return_to_bootrom(void);
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun /**
324*4882a593Smuzhiyun  * spl_cleanup_before_jump() - cleanup cache/mmu/interrupt, etc before jump
325*4882a593Smuzhiyun  *			       to next stage.
326*4882a593Smuzhiyun  */
327*4882a593Smuzhiyun void spl_cleanup_before_jump(struct spl_image_info *spl_image);
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun /**
330*4882a593Smuzhiyun  * spl_perform_fixups() - arch/board-specific callback before processing
331*4882a593Smuzhiyun  *                        the boot-payload
332*4882a593Smuzhiyun  */
333*4882a593Smuzhiyun void spl_perform_fixups(struct spl_image_info *spl_image);
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun /**
336*4882a593Smuzhiyun  * spl_board_prepare_for_jump() - arch/board-specific callback exactly before
337*4882a593Smuzhiyun  *				  jumping to next stage
338*4882a593Smuzhiyun  */
339*4882a593Smuzhiyun int spl_board_prepare_for_jump(struct spl_image_info *spl_image);
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun /**
342*4882a593Smuzhiyun  * spl_kernel_partition() - arch/board-specific callback to get kernel partition
343*4882a593Smuzhiyun  */
344*4882a593Smuzhiyun #ifdef CONFIG_SPL_KERNEL_BOOT
345*4882a593Smuzhiyun const char *spl_kernel_partition(struct spl_image_info *spl,
346*4882a593Smuzhiyun 				 struct spl_load_info *info);
347*4882a593Smuzhiyun #endif
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun #endif
350