xref: /rk3399_rockchip-uboot/include/spl.h (revision 71316c1d8c1799b444d14cfb00eaacb6cf1ce44a)
147f7bcaeSTom Rini /*
247f7bcaeSTom Rini  * (C) Copyright 2012
347f7bcaeSTom Rini  * Texas Instruments, <www.ti.com>
447f7bcaeSTom Rini  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
647f7bcaeSTom Rini  */
747f7bcaeSTom Rini #ifndef	_SPL_H_
847f7bcaeSTom Rini #define	_SPL_H_
947f7bcaeSTom Rini 
1047f7bcaeSTom Rini /* Platform-specific defines */
116507f133STom Rini #include <linux/compiler.h>
1247f7bcaeSTom Rini #include <asm/spl.h>
1347f7bcaeSTom Rini 
1432ba8952SSimon Glass /* Value in r0 indicates we booted from U-Boot */
1532ba8952SSimon Glass #define UBOOT_NOT_LOADED_FROM_SPL	0x13578642
16773b5940SDan Murphy 
1747f7bcaeSTom Rini /* Boot type */
1847f7bcaeSTom Rini #define MMCSD_MODE_UNDEFINED	0
1947f7bcaeSTom Rini #define MMCSD_MODE_RAW		1
20205b4f33SGuillaume GARDET #define MMCSD_MODE_FS		2
217dbe63bcSTom Rini #define MMCSD_MODE_EMMCBOOT	3
2247f7bcaeSTom Rini 
2347f7bcaeSTom Rini struct spl_image_info {
2447f7bcaeSTom Rini 	const char *name;
2547f7bcaeSTom Rini 	u8 os;
2647f7bcaeSTom Rini 	u32 load_addr;
2747f7bcaeSTom Rini 	u32 entry_point;
2847f7bcaeSTom Rini 	u32 size;
29022b4975SStefan Roese 	u32 flags;
3047f7bcaeSTom Rini };
3147f7bcaeSTom Rini 
32f1dcee59SSimon Glass /*
33f1dcee59SSimon Glass  * Information required to load data from a device
34f1dcee59SSimon Glass  *
35f1dcee59SSimon Glass  * @dev: Pointer to the device, e.g. struct mmc *
36f1dcee59SSimon Glass  * @priv: Private data for the device
37f1dcee59SSimon Glass  * @bl_len: Block length for reading in bytes
38eafd5410SLokesh Vutla  * @filename: Name of the fit image file.
39f1dcee59SSimon Glass  * @read: Function to call to read from the device
40f1dcee59SSimon Glass  */
41f1dcee59SSimon Glass struct spl_load_info {
42f1dcee59SSimon Glass 	void *dev;
43f1dcee59SSimon Glass 	void *priv;
44f1dcee59SSimon Glass 	int bl_len;
45eafd5410SLokesh Vutla 	const char *filename;
46f1dcee59SSimon Glass 	ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
47f1dcee59SSimon Glass 		      void *buf);
48f1dcee59SSimon Glass };
49f1dcee59SSimon Glass 
50eafd5410SLokesh Vutla /**
51eafd5410SLokesh Vutla  * spl_load_simple_fit() - Loads a fit image from a device.
52eafd5410SLokesh Vutla  * @info:	Structure containing the information required to load data.
53eafd5410SLokesh Vutla  * @sector:	Sector number where FIT image is located in the device
54eafd5410SLokesh Vutla  * @fdt:	Pointer to the copied FIT header.
55eafd5410SLokesh Vutla  *
56eafd5410SLokesh Vutla  * Reads the FIT image @sector in the device. Loads u-boot image to
57eafd5410SLokesh Vutla  * specified load address and copies the dtb to end of u-boot image.
58eafd5410SLokesh Vutla  * Returns 0 on success.
59eafd5410SLokesh Vutla  */
60f1dcee59SSimon Glass int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fdt);
61f1dcee59SSimon Glass 
62022b4975SStefan Roese #define SPL_COPY_PAYLOAD_ONLY	1
63022b4975SStefan Roese 
6447f7bcaeSTom Rini extern struct spl_image_info spl_image;
6547f7bcaeSTom Rini 
6647f7bcaeSTom Rini /* SPL common functions */
6747f7bcaeSTom Rini void preloader_console_init(void);
6847f7bcaeSTom Rini u32 spl_boot_device(void);
692b1cdafaSMarek Vasut u32 spl_boot_mode(const u32 boot_device);
70d95ceb97SSimon Glass 
71d95ceb97SSimon Glass /**
72d95ceb97SSimon Glass  * spl_set_header_raw_uboot() - Set up a standard SPL image structure
73d95ceb97SSimon Glass  *
74d95ceb97SSimon Glass  * This sets up the given spl_image which the standard values obtained from
75d95ceb97SSimon Glass  * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
76d95ceb97SSimon Glass  * CONFIG_SYS_TEXT_BASE.
77d95ceb97SSimon Glass  *
78*71316c1dSSimon Glass  * @spl_image: Image description to set up
79d95ceb97SSimon Glass  */
80d95ceb97SSimon Glass void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
81d95ceb97SSimon Glass 
82*71316c1dSSimon Glass /**
83*71316c1dSSimon Glass  * spl_parse_image_header() - parse the image header and set up info
84*71316c1dSSimon Glass  *
85*71316c1dSSimon Glass  * This parses the legacy image header information at @header and sets up
86*71316c1dSSimon Glass  * @spl_image according to what is found. If no image header is found, then
87*71316c1dSSimon Glass  * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is
88*71316c1dSSimon Glass  * enabled, then this causes a panic. If CONFIG_SPL_ABORT_ON_RAW_IMAGE is
89*71316c1dSSimon Glass  * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using
90*71316c1dSSimon Glass  * spl_set_header_raw_uboot(), or possibly the bootz header.
91*71316c1dSSimon Glass  *
92*71316c1dSSimon Glass  * @spl_image: Image description to set up
93*71316c1dSSimon Glass  * @header image header to parse
94*71316c1dSSimon Glass  * @return 0 if a header was correctly parsed, -ve on error
95*71316c1dSSimon Glass  */
96*71316c1dSSimon Glass int spl_parse_image_header(struct spl_image_info *spl_image,
97*71316c1dSSimon Glass 			   const struct image_header *header);
98*71316c1dSSimon Glass 
9947f7bcaeSTom Rini void spl_board_prepare_for_linux(void);
1003a3b9147SMichal Simek void spl_board_prepare_for_boot(void);
101bf55cd4fSLadislav Michl int spl_board_ubi_load_image(u32 boot_device);
1026507f133STom Rini void __noreturn jump_to_image_linux(void *arg);
10347f7bcaeSTom Rini int spl_start_uboot(void);
10447f7bcaeSTom Rini void spl_display_print(void);
10547f7bcaeSTom Rini 
10647f7bcaeSTom Rini /* NAND SPL functions */
10736afd451SNikita Kiryanov int spl_nand_load_image(void);
10847f7bcaeSTom Rini 
1096000992eSEnric Balletbo i Serra /* OneNAND SPL functions */
11036afd451SNikita Kiryanov int spl_onenand_load_image(void);
1116000992eSEnric Balletbo i Serra 
11233d34646SStefan Roese /* NOR SPL functions */
11336afd451SNikita Kiryanov int spl_nor_load_image(void);
11433d34646SStefan Roese 
115bf55cd4fSLadislav Michl /* UBI SPL functions */
116bf55cd4fSLadislav Michl int spl_ubi_load_image(u32 boot_device);
117bf55cd4fSLadislav Michl 
11847f7bcaeSTom Rini /* MMC SPL functions */
119a1e56cf6SNikita Kiryanov int spl_mmc_load_image(u32 boot_device);
12047f7bcaeSTom Rini 
12147f7bcaeSTom Rini /* YMODEM SPL functions */
12236afd451SNikita Kiryanov int spl_ymodem_load_image(void);
12347f7bcaeSTom Rini 
12447f7bcaeSTom Rini /* SPI SPL functions */
12536afd451SNikita Kiryanov int spl_spi_load_image(void);
12647f7bcaeSTom Rini 
1277ac2fe2dSIlya Yanok /* Ethernet SPL functions */
12836afd451SNikita Kiryanov int spl_net_load_image(const char *device);
1297ac2fe2dSIlya Yanok 
1308cffe5bdSDan Murphy /* USB SPL functions */
13136afd451SNikita Kiryanov int spl_usb_load_image(void);
1328cffe5bdSDan Murphy 
133fff40a7eSDan Murphy /* SATA SPL functions */
13436afd451SNikita Kiryanov int spl_sata_load_image(void);
135fff40a7eSDan Murphy 
136773b5940SDan Murphy /* SPL FAT image functions */
1374101f687SSimon Glass int spl_load_image_fat(struct blk_desc *block_dev, int partition,
1384101f687SSimon Glass 		       const char *filename);
1394101f687SSimon Glass int spl_load_image_fat_os(struct blk_desc *block_dev, int partition);
140773b5940SDan Murphy 
141ce048224SJeroen Hofstee void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
142ce048224SJeroen Hofstee 
143592f9222SGuillaume GARDET /* SPL EXT image functions */
1444101f687SSimon Glass int spl_load_image_ext(struct blk_desc *block_dev, int partition,
1454101f687SSimon Glass 		       const char *filename);
1464101f687SSimon Glass int spl_load_image_ext_os(struct blk_desc *block_dev, int partition);
147592f9222SGuillaume GARDET 
148070d00b8SSimon Glass /**
149070d00b8SSimon Glass  * spl_init() - Set up device tree and driver model in SPL if enabled
150070d00b8SSimon Glass  *
151070d00b8SSimon Glass  * Call this function in board_init_f() if you want to use device tree and
152070d00b8SSimon Glass  * driver model early, before board_init_r() is called. This function will
153070d00b8SSimon Glass  * be called from board_init_r() if not called earlier.
154070d00b8SSimon Glass  *
155070d00b8SSimon Glass  * If this is not called, then driver model will be inactive in SPL's
156070d00b8SSimon Glass  * board_init_f(), and no device tree will be available.
157070d00b8SSimon Glass  */
158070d00b8SSimon Glass int spl_init(void);
159070d00b8SSimon Glass 
16047f7bcaeSTom Rini #ifdef CONFIG_SPL_BOARD_INIT
16147f7bcaeSTom Rini void spl_board_init(void);
16247f7bcaeSTom Rini #endif
16332ba8952SSimon Glass 
16432ba8952SSimon Glass /**
16532ba8952SSimon Glass  * spl_was_boot_source() - check if U-Boot booted from SPL
16632ba8952SSimon Glass  *
16732ba8952SSimon Glass  * This will normally be true, but if U-Boot jumps to second U-Boot, it will
16832ba8952SSimon Glass  * be false. This should be implemented by board-specific code.
16932ba8952SSimon Glass  *
17032ba8952SSimon Glass  * @return true if U-Boot booted from SPL, else false
17132ba8952SSimon Glass  */
17232ba8952SSimon Glass bool spl_was_boot_source(void);
17332ba8952SSimon Glass 
17452f2acc5SB, Ravi /**
17552f2acc5SB, Ravi  * spl_dfu_cmd- run dfu command with chosen mmc device interface
17652f2acc5SB, Ravi  * @param usb_index - usb controller number
17752f2acc5SB, Ravi  * @param mmc_dev -  mmc device nubmer
17852f2acc5SB, Ravi  *
17952f2acc5SB, Ravi  * @return 0 on success, otherwise error code
18052f2acc5SB, Ravi  */
18152f2acc5SB, Ravi int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
182e50d76ccSSimon Glass 
183e50d76ccSSimon Glass /**
184e50d76ccSSimon Glass  * Board-specific load method for boards that have a special way of loading
185e50d76ccSSimon Glass  * U-Boot, which does not fit with the existing SPL code.
186e50d76ccSSimon Glass  *
187e50d76ccSSimon Glass  * @return 0 on success, negative errno value on failure.
188e50d76ccSSimon Glass  */
189e50d76ccSSimon Glass int spl_board_load_image(void);
190e50d76ccSSimon Glass 
19147f7bcaeSTom Rini #endif
192