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