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