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; 2611e1479bSAndre Przywara ulong load_addr; 2711e1479bSAndre Przywara ulong entry_point; 2847f7bcaeSTom Rini u32 size; 29022b4975SStefan Roese u32 flags; 305bf5250eSVikas Manocha void *arg; 3147f7bcaeSTom Rini }; 3247f7bcaeSTom Rini 33f1dcee59SSimon Glass /* 34f1dcee59SSimon Glass * Information required to load data from a device 35f1dcee59SSimon Glass * 36f1dcee59SSimon Glass * @dev: Pointer to the device, e.g. struct mmc * 37f1dcee59SSimon Glass * @priv: Private data for the device 38f1dcee59SSimon Glass * @bl_len: Block length for reading in bytes 39eafd5410SLokesh Vutla * @filename: Name of the fit image file. 40f1dcee59SSimon Glass * @read: Function to call to read from the device 41f1dcee59SSimon Glass */ 42f1dcee59SSimon Glass struct spl_load_info { 43f1dcee59SSimon Glass void *dev; 44f1dcee59SSimon Glass void *priv; 45f1dcee59SSimon Glass int bl_len; 46eafd5410SLokesh Vutla const char *filename; 47f1dcee59SSimon Glass ulong (*read)(struct spl_load_info *load, ulong sector, ulong count, 48f1dcee59SSimon Glass void *buf); 49f1dcee59SSimon Glass }; 50f1dcee59SSimon Glass 51eafd5410SLokesh Vutla /** 52eafd5410SLokesh Vutla * spl_load_simple_fit() - Loads a fit image from a device. 53f4d7d859SSimon Glass * @spl_image: Image description to set up 54eafd5410SLokesh Vutla * @info: Structure containing the information required to load data. 55eafd5410SLokesh Vutla * @sector: Sector number where FIT image is located in the device 56eafd5410SLokesh Vutla * @fdt: Pointer to the copied FIT header. 57eafd5410SLokesh Vutla * 58eafd5410SLokesh Vutla * Reads the FIT image @sector in the device. Loads u-boot image to 59eafd5410SLokesh Vutla * specified load address and copies the dtb to end of u-boot image. 60eafd5410SLokesh Vutla * Returns 0 on success. 61eafd5410SLokesh Vutla */ 62f4d7d859SSimon Glass int spl_load_simple_fit(struct spl_image_info *spl_image, 63f4d7d859SSimon Glass struct spl_load_info *info, ulong sector, void *fdt); 64f1dcee59SSimon Glass 65022b4975SStefan Roese #define SPL_COPY_PAYLOAD_ONLY 1 66022b4975SStefan Roese 6747f7bcaeSTom Rini /* SPL common functions */ 6847f7bcaeSTom Rini void preloader_console_init(void); 6947f7bcaeSTom Rini u32 spl_boot_device(void); 702b1cdafaSMarek Vasut u32 spl_boot_mode(const u32 boot_device); 71d95ceb97SSimon Glass 72d95ceb97SSimon Glass /** 73d95ceb97SSimon Glass * spl_set_header_raw_uboot() - Set up a standard SPL image structure 74d95ceb97SSimon Glass * 75d95ceb97SSimon Glass * This sets up the given spl_image which the standard values obtained from 76d95ceb97SSimon Glass * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START, 77d95ceb97SSimon Glass * CONFIG_SYS_TEXT_BASE. 78d95ceb97SSimon Glass * 7971316c1dSSimon Glass * @spl_image: Image description to set up 80d95ceb97SSimon Glass */ 81d95ceb97SSimon Glass void spl_set_header_raw_uboot(struct spl_image_info *spl_image); 82d95ceb97SSimon Glass 8371316c1dSSimon Glass /** 8471316c1dSSimon Glass * spl_parse_image_header() - parse the image header and set up info 8571316c1dSSimon Glass * 8671316c1dSSimon Glass * This parses the legacy image header information at @header and sets up 8771316c1dSSimon Glass * @spl_image according to what is found. If no image header is found, then 8871316c1dSSimon Glass * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is 8924eb39b5SAndrew F. Davis * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not 9071316c1dSSimon Glass * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using 9171316c1dSSimon Glass * spl_set_header_raw_uboot(), or possibly the bootz header. 9271316c1dSSimon Glass * 9371316c1dSSimon Glass * @spl_image: Image description to set up 9471316c1dSSimon Glass * @header image header to parse 9571316c1dSSimon Glass * @return 0 if a header was correctly parsed, -ve on error 9671316c1dSSimon Glass */ 9771316c1dSSimon Glass int spl_parse_image_header(struct spl_image_info *spl_image, 9871316c1dSSimon Glass const struct image_header *header); 9971316c1dSSimon Glass 10047f7bcaeSTom Rini void spl_board_prepare_for_linux(void); 1013a3b9147SMichal Simek void spl_board_prepare_for_boot(void); 102bf55cd4fSLadislav Michl int spl_board_ubi_load_image(u32 boot_device); 103ca12e65cSSimon Glass 104ca12e65cSSimon Glass /** 105ca12e65cSSimon Glass * jump_to_image_linux() - Jump to a Linux kernel from SPL 106ca12e65cSSimon Glass * 107ca12e65cSSimon Glass * This jumps into a Linux kernel using the information in @spl_image. 108ca12e65cSSimon Glass * 109ca12e65cSSimon Glass * @spl_image: Image description to set up 110ca12e65cSSimon Glass */ 1115bf5250eSVikas Manocha void __noreturn jump_to_image_linux(struct spl_image_info *spl_image); 112f59961e3SSimon Glass 113f59961e3SSimon Glass /** 114f59961e3SSimon Glass * spl_start_uboot() - Check if SPL should start the kernel or U-Boot 115f59961e3SSimon Glass * 116f59961e3SSimon Glass * This is called by the various SPL loaders to determine whether the board 117f59961e3SSimon Glass * wants to load the kernel or U-Boot. This function should be provided by 118f59961e3SSimon Glass * the board. 119f59961e3SSimon Glass * 120f59961e3SSimon Glass * @return 0 if SPL should start the kernel, 1 if U-Boot must be started 121f59961e3SSimon Glass */ 12247f7bcaeSTom Rini int spl_start_uboot(void); 123f59961e3SSimon Glass 124a807ab33SSimon Glass /** 125a807ab33SSimon Glass * spl_display_print() - Display a board-specific message in SPL 126a807ab33SSimon Glass * 127a807ab33SSimon Glass * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function 128a807ab33SSimon Glass * immediately after displaying the SPL console banner ("U-Boot SPL ..."). 129a807ab33SSimon Glass * This function should be provided by the board. 130a807ab33SSimon Glass */ 13147f7bcaeSTom Rini void spl_display_print(void); 13247f7bcaeSTom Rini 133ecdfd69aSSimon Glass /** 134ecdfd69aSSimon Glass * struct spl_boot_device - Describes a boot device used by SPL 135ecdfd69aSSimon Glass * 136ecdfd69aSSimon Glass * @boot_device: A number indicating the BOOT_DEVICE type. There are various 137ecdfd69aSSimon Glass * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently 138ecdfd69aSSimon Glass * numbered. 139ecdfd69aSSimon Glass * @boot_device_name: Named boot device, or NULL if none. 140ecdfd69aSSimon Glass * 141ecdfd69aSSimon Glass * Note: Additional fields can be added here, bearing in mind that SPL is 142ecdfd69aSSimon Glass * size-sensitive and common fields will be present on all boards. This 143ecdfd69aSSimon Glass * struct can also be used to return additional information about the load 144ecdfd69aSSimon Glass * process if that becomes useful. 145ecdfd69aSSimon Glass */ 146ecdfd69aSSimon Glass struct spl_boot_device { 147ecdfd69aSSimon Glass uint boot_device; 148ecdfd69aSSimon Glass const char *boot_device_name; 149ecdfd69aSSimon Glass }; 150ecdfd69aSSimon Glass 151a0a80290SSimon Glass /** 152a0a80290SSimon Glass * Holds information about a way of loading an SPL image 153a0a80290SSimon Glass * 154ebc4ef61SSimon Glass * @name: User-friendly name for this method (e.g. "MMC") 155a0a80290SSimon Glass * @boot_device: Boot device that this loader supports 156a0a80290SSimon Glass * @load_image: Function to call to load image 157a0a80290SSimon Glass */ 158a0a80290SSimon Glass struct spl_image_loader { 159ebc4ef61SSimon Glass #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 160ebc4ef61SSimon Glass const char *name; 161ebc4ef61SSimon Glass #endif 162a0a80290SSimon Glass uint boot_device; 163a0a80290SSimon Glass /** 164a0a80290SSimon Glass * load_image() - Load an SPL image 165a0a80290SSimon Glass * 1662a2ee2acSSimon Glass * @spl_image: place to put image information 167a0a80290SSimon Glass * @bootdev: describes the boot device to load from 168a0a80290SSimon Glass */ 1692a2ee2acSSimon Glass int (*load_image)(struct spl_image_info *spl_image, 1702a2ee2acSSimon Glass struct spl_boot_device *bootdev); 171a0a80290SSimon Glass }; 172a0a80290SSimon Glass 173a0a80290SSimon Glass /* Declare an SPL image loader */ 174a0a80290SSimon Glass #define SPL_LOAD_IMAGE(__name) \ 175a0a80290SSimon Glass ll_entry_declare(struct spl_image_loader, __name, spl_image_loader) 176a0a80290SSimon Glass 177a0a80290SSimon Glass /* 1780d3b0591SSimon Glass * _priority is the priority of this method, 0 meaning it will be the top 179a0a80290SSimon Glass * choice for this device, 9 meaning it is the bottom choice. 1800d3b0591SSimon Glass * _boot_device is the BOOT_DEVICE_... value 1810d3b0591SSimon Glass * _method is the load_image function to call 182a0a80290SSimon Glass */ 183ebc4ef61SSimon Glass #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 184ebc4ef61SSimon Glass #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \ 185ebc4ef61SSimon Glass SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \ 186ebc4ef61SSimon Glass .name = _name, \ 187ebc4ef61SSimon Glass .boot_device = _boot_device, \ 188ebc4ef61SSimon Glass .load_image = _method, \ 189ebc4ef61SSimon Glass } 190ebc4ef61SSimon Glass #else 191ebc4ef61SSimon Glass #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \ 1920d3b0591SSimon Glass SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \ 1930d3b0591SSimon Glass .boot_device = _boot_device, \ 1940d3b0591SSimon Glass .load_image = _method, \ 195a0a80290SSimon Glass } 196ebc4ef61SSimon Glass #endif 197a0a80290SSimon Glass 198773b5940SDan Murphy /* SPL FAT image functions */ 199710e9ca5SSimon Glass int spl_load_image_fat(struct spl_image_info *spl_image, 200710e9ca5SSimon Glass struct blk_desc *block_dev, int partition, 2014101f687SSimon Glass const char *filename); 202710e9ca5SSimon Glass int spl_load_image_fat_os(struct spl_image_info *spl_image, 203710e9ca5SSimon Glass struct blk_desc *block_dev, int partition); 204773b5940SDan Murphy 205ce048224SJeroen Hofstee void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image); 206ce048224SJeroen Hofstee 207592f9222SGuillaume GARDET /* SPL EXT image functions */ 208b4a6c2aaSSimon Glass int spl_load_image_ext(struct spl_image_info *spl_image, 209b4a6c2aaSSimon Glass struct blk_desc *block_dev, int partition, 2104101f687SSimon Glass const char *filename); 211b4a6c2aaSSimon Glass int spl_load_image_ext_os(struct spl_image_info *spl_image, 212b4a6c2aaSSimon Glass struct blk_desc *block_dev, int partition); 213592f9222SGuillaume GARDET 214070d00b8SSimon Glass /** 215340f418aSEddie Cai * spl_early_init() - Set up device tree and driver model in SPL if enabled 216070d00b8SSimon Glass * 217070d00b8SSimon Glass * Call this function in board_init_f() if you want to use device tree and 218340f418aSEddie Cai * driver model early, before board_init_r() is called. 219340f418aSEddie Cai * 220340f418aSEddie Cai * If this is not called, then driver model will be inactive in SPL's 221340f418aSEddie Cai * board_init_f(), and no device tree will be available. 222340f418aSEddie Cai */ 223340f418aSEddie Cai int spl_early_init(void); 224340f418aSEddie Cai 225340f418aSEddie Cai /** 226340f418aSEddie Cai * spl_init() - Set up device tree and driver model in SPL if enabled 227340f418aSEddie Cai * 228340f418aSEddie Cai * You can optionally call spl_early_init(), then optionally call spl_init(). 229340f418aSEddie Cai * This function will be called from board_init_r() if not called earlier. 230340f418aSEddie Cai * 231340f418aSEddie Cai * Both spl_early_init() and spl_init() perform a similar function except that 232340f418aSEddie Cai * the latter will not set up the malloc() area if 233340f418aSEddie Cai * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to 234340f418aSEddie Cai * already be done by a calll to spl_relocate_stack_gd() before board_init_r() 235340f418aSEddie Cai * is reached. 236340f418aSEddie Cai * 237340f418aSEddie Cai * This function will be called from board_init_r() if not called earlier. 238070d00b8SSimon Glass * 239070d00b8SSimon Glass * If this is not called, then driver model will be inactive in SPL's 240070d00b8SSimon Glass * board_init_f(), and no device tree will be available. 241070d00b8SSimon Glass */ 242070d00b8SSimon Glass int spl_init(void); 243070d00b8SSimon Glass 24447f7bcaeSTom Rini #ifdef CONFIG_SPL_BOARD_INIT 24547f7bcaeSTom Rini void spl_board_init(void); 24647f7bcaeSTom Rini #endif 24732ba8952SSimon Glass 24832ba8952SSimon Glass /** 24932ba8952SSimon Glass * spl_was_boot_source() - check if U-Boot booted from SPL 25032ba8952SSimon Glass * 25132ba8952SSimon Glass * This will normally be true, but if U-Boot jumps to second U-Boot, it will 25232ba8952SSimon Glass * be false. This should be implemented by board-specific code. 25332ba8952SSimon Glass * 25432ba8952SSimon Glass * @return true if U-Boot booted from SPL, else false 25532ba8952SSimon Glass */ 25632ba8952SSimon Glass bool spl_was_boot_source(void); 25732ba8952SSimon Glass 25852f2acc5SB, Ravi /** 25952f2acc5SB, Ravi * spl_dfu_cmd- run dfu command with chosen mmc device interface 26052f2acc5SB, Ravi * @param usb_index - usb controller number 26152f2acc5SB, Ravi * @param mmc_dev - mmc device nubmer 26252f2acc5SB, Ravi * 26352f2acc5SB, Ravi * @return 0 on success, otherwise error code 26452f2acc5SB, Ravi */ 26552f2acc5SB, Ravi int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr); 266e50d76ccSSimon Glass 26709410c65SMarek Vasut int spl_mmc_load_image(struct spl_image_info *spl_image, 26809410c65SMarek Vasut struct spl_boot_device *bootdev); 26909410c65SMarek Vasut 270bcc1726aSKever Yang void bl31_entry(void); 271*225d30b7SPhilipp Tomsich 272*225d30b7SPhilipp Tomsich /** 273*225d30b7SPhilipp Tomsich * board_return_to_bootrom - allow for boards to continue with the boot ROM 274*225d30b7SPhilipp Tomsich * 275*225d30b7SPhilipp Tomsich * If a board (e.g. the Rockchip RK3368 boards) provide some 276*225d30b7SPhilipp Tomsich * supporting functionality for SPL in their boot ROM and the SPL 277*225d30b7SPhilipp Tomsich * stage wants to return to the ROM code to continue booting, boards 278*225d30b7SPhilipp Tomsich * can implement 'board_return_to_bootrom'. 279*225d30b7SPhilipp Tomsich */ 280*225d30b7SPhilipp Tomsich void board_return_to_bootrom(void); 28147f7bcaeSTom Rini #endif 282