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 */ 11a786ab7aSJason Zhu #include <mmc.h> 126507f133STom Rini #include <linux/compiler.h> 1347f7bcaeSTom Rini #include <asm/spl.h> 1447f7bcaeSTom Rini 1532ba8952SSimon Glass /* Value in r0 indicates we booted from U-Boot */ 1632ba8952SSimon Glass #define UBOOT_NOT_LOADED_FROM_SPL 0x13578642 17773b5940SDan Murphy 1847f7bcaeSTom Rini /* Boot type */ 1947f7bcaeSTom Rini #define MMCSD_MODE_UNDEFINED 0 2047f7bcaeSTom Rini #define MMCSD_MODE_RAW 1 21205b4f33SGuillaume GARDET #define MMCSD_MODE_FS 2 227dbe63bcSTom Rini #define MMCSD_MODE_EMMCBOOT 3 2347f7bcaeSTom Rini 2469e1ad7bSJason Zhu #define SPL_NEXT_STAGE_UNDEFINED 0 2569e1ad7bSJason Zhu #define SPL_NEXT_STAGE_UBOOT 1 2669e1ad7bSJason Zhu #define SPL_NEXT_STAGE_KERNEL 2 2769e1ad7bSJason Zhu 2847f7bcaeSTom Rini struct spl_image_info { 2947f7bcaeSTom Rini const char *name; 3047f7bcaeSTom Rini u8 os; 3159acbc1bSPhilipp Tomsich uintptr_t load_addr; 321620aad4SJoseph Chen uintptr_t entry_point; /* Next stage entry point */ 331620aad4SJoseph Chen #if CONFIG_IS_ENABLED(ATF) 341620aad4SJoseph Chen uintptr_t entry_point_bl32; 351620aad4SJoseph Chen uintptr_t entry_point_bl33; 361620aad4SJoseph Chen #endif 3788d57c08SJason Zhu #if CONFIG_IS_ENABLED(OPTEE) || CONFIG_IS_ENABLED(KERNEL_BOOT) 381cb393f1SJason Zhu uintptr_t entry_point_os; /* point to uboot or kernel */ 39ae1e9f8fSPhilipp Tomsich #endif 401cb393f1SJason Zhu void *fdt_addr; 416f678d2aSJason Zhu u32 boot_device; 42c88ba1c4SJason Zhu u32 next_stage; 4347f7bcaeSTom Rini u32 size; 44022b4975SStefan Roese u32 flags; 455bf5250eSVikas Manocha void *arg; 4647f7bcaeSTom Rini }; 4747f7bcaeSTom Rini 48f1dcee59SSimon Glass /* 49f1dcee59SSimon Glass * Information required to load data from a device 50f1dcee59SSimon Glass * 51f1dcee59SSimon Glass * @dev: Pointer to the device, e.g. struct mmc * 52f1dcee59SSimon Glass * @priv: Private data for the device 53f1dcee59SSimon Glass * @bl_len: Block length for reading in bytes 54eafd5410SLokesh Vutla * @filename: Name of the fit image file. 55f1dcee59SSimon Glass * @read: Function to call to read from the device 56f1dcee59SSimon Glass */ 57f1dcee59SSimon Glass struct spl_load_info { 58f1dcee59SSimon Glass void *dev; 59f1dcee59SSimon Glass void *priv; 60f1dcee59SSimon Glass int bl_len; 61eafd5410SLokesh Vutla const char *filename; 62f1dcee59SSimon Glass ulong (*read)(struct spl_load_info *load, ulong sector, ulong count, 63f1dcee59SSimon Glass void *buf); 64f1dcee59SSimon Glass }; 65f1dcee59SSimon Glass 66eafd5410SLokesh Vutla /** 67eafd5410SLokesh Vutla * spl_load_simple_fit() - Loads a fit image from a device. 68f4d7d859SSimon Glass * @spl_image: Image description to set up 69eafd5410SLokesh Vutla * @info: Structure containing the information required to load data. 70eafd5410SLokesh Vutla * @sector: Sector number where FIT image is located in the device 71eafd5410SLokesh Vutla * @fdt: Pointer to the copied FIT header. 72eafd5410SLokesh Vutla * 73eafd5410SLokesh Vutla * Reads the FIT image @sector in the device. Loads u-boot image to 74eafd5410SLokesh Vutla * specified load address and copies the dtb to end of u-boot image. 75eafd5410SLokesh Vutla * Returns 0 on success. 76eafd5410SLokesh Vutla */ 77f4d7d859SSimon Glass int spl_load_simple_fit(struct spl_image_info *spl_image, 78f4d7d859SSimon Glass struct spl_load_info *info, ulong sector, void *fdt); 79f1dcee59SSimon Glass 80022b4975SStefan Roese #define SPL_COPY_PAYLOAD_ONLY 1 812e71311cSXuhui Lin #define SPL_ATF_AARCH32_BL33 BIT(31) 82022b4975SStefan Roese 8347f7bcaeSTom Rini /* SPL common functions */ 8447f7bcaeSTom Rini void preloader_console_init(void); 8547f7bcaeSTom Rini u32 spl_boot_device(void); 862b1cdafaSMarek Vasut u32 spl_boot_mode(const u32 boot_device); 872323b257SJason Zhu void spl_next_stage(struct spl_image_info *spl); 884f443bd2SYork Sun void spl_set_bd(void); 89d95ceb97SSimon Glass 90d95ceb97SSimon Glass /** 91d95ceb97SSimon Glass * spl_set_header_raw_uboot() - Set up a standard SPL image structure 92d95ceb97SSimon Glass * 93d95ceb97SSimon Glass * This sets up the given spl_image which the standard values obtained from 94d95ceb97SSimon Glass * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START, 95d95ceb97SSimon Glass * CONFIG_SYS_TEXT_BASE. 96d95ceb97SSimon Glass * 9771316c1dSSimon Glass * @spl_image: Image description to set up 98d95ceb97SSimon Glass */ 99d95ceb97SSimon Glass void spl_set_header_raw_uboot(struct spl_image_info *spl_image); 100d95ceb97SSimon Glass 10171316c1dSSimon Glass /** 10271316c1dSSimon Glass * spl_parse_image_header() - parse the image header and set up info 10371316c1dSSimon Glass * 10471316c1dSSimon Glass * This parses the legacy image header information at @header and sets up 10571316c1dSSimon Glass * @spl_image according to what is found. If no image header is found, then 10671316c1dSSimon Glass * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is 10724eb39b5SAndrew F. Davis * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not 10871316c1dSSimon Glass * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using 10971316c1dSSimon Glass * spl_set_header_raw_uboot(), or possibly the bootz header. 11071316c1dSSimon Glass * 11171316c1dSSimon Glass * @spl_image: Image description to set up 11271316c1dSSimon Glass * @header image header to parse 11371316c1dSSimon Glass * @return 0 if a header was correctly parsed, -ve on error 11471316c1dSSimon Glass */ 11571316c1dSSimon Glass int spl_parse_image_header(struct spl_image_info *spl_image, 11671316c1dSSimon Glass const struct image_header *header); 11771316c1dSSimon Glass 11847f7bcaeSTom Rini void spl_board_prepare_for_linux(void); 1193a3b9147SMichal Simek void spl_board_prepare_for_boot(void); 120bf55cd4fSLadislav Michl int spl_board_ubi_load_image(u32 boot_device); 121ca12e65cSSimon Glass 122ca12e65cSSimon Glass /** 123ca12e65cSSimon Glass * jump_to_image_linux() - Jump to a Linux kernel from SPL 124ca12e65cSSimon Glass * 125ca12e65cSSimon Glass * This jumps into a Linux kernel using the information in @spl_image. 126ca12e65cSSimon Glass * 127ca12e65cSSimon Glass * @spl_image: Image description to set up 128ca12e65cSSimon Glass */ 1295bf5250eSVikas Manocha void __noreturn jump_to_image_linux(struct spl_image_info *spl_image); 130f59961e3SSimon Glass 131f59961e3SSimon Glass /** 132f59961e3SSimon Glass * spl_start_uboot() - Check if SPL should start the kernel or U-Boot 133f59961e3SSimon Glass * 134f59961e3SSimon Glass * This is called by the various SPL loaders to determine whether the board 135f59961e3SSimon Glass * wants to load the kernel or U-Boot. This function should be provided by 136f59961e3SSimon Glass * the board. 137f59961e3SSimon Glass * 138f59961e3SSimon Glass * @return 0 if SPL should start the kernel, 1 if U-Boot must be started 139f59961e3SSimon Glass */ 14047f7bcaeSTom Rini int spl_start_uboot(void); 141f59961e3SSimon Glass 142a807ab33SSimon Glass /** 143a807ab33SSimon Glass * spl_display_print() - Display a board-specific message in SPL 144a807ab33SSimon Glass * 145a807ab33SSimon Glass * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function 146a807ab33SSimon Glass * immediately after displaying the SPL console banner ("U-Boot SPL ..."). 147a807ab33SSimon Glass * This function should be provided by the board. 148a807ab33SSimon Glass */ 14947f7bcaeSTom Rini void spl_display_print(void); 15047f7bcaeSTom Rini 151ecdfd69aSSimon Glass /** 152ecdfd69aSSimon Glass * struct spl_boot_device - Describes a boot device used by SPL 153ecdfd69aSSimon Glass * 154ecdfd69aSSimon Glass * @boot_device: A number indicating the BOOT_DEVICE type. There are various 155ecdfd69aSSimon Glass * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently 156ecdfd69aSSimon Glass * numbered. 157ecdfd69aSSimon Glass * @boot_device_name: Named boot device, or NULL if none. 158ecdfd69aSSimon Glass * 159ecdfd69aSSimon Glass * Note: Additional fields can be added here, bearing in mind that SPL is 160ecdfd69aSSimon Glass * size-sensitive and common fields will be present on all boards. This 161ecdfd69aSSimon Glass * struct can also be used to return additional information about the load 162ecdfd69aSSimon Glass * process if that becomes useful. 163ecdfd69aSSimon Glass */ 164ecdfd69aSSimon Glass struct spl_boot_device { 165ecdfd69aSSimon Glass uint boot_device; 166ecdfd69aSSimon Glass const char *boot_device_name; 167ecdfd69aSSimon Glass }; 168ecdfd69aSSimon Glass 169a0a80290SSimon Glass /** 170a0a80290SSimon Glass * Holds information about a way of loading an SPL image 171a0a80290SSimon Glass * 172ebc4ef61SSimon Glass * @name: User-friendly name for this method (e.g. "MMC") 173a0a80290SSimon Glass * @boot_device: Boot device that this loader supports 174a0a80290SSimon Glass * @load_image: Function to call to load image 175a0a80290SSimon Glass */ 176a0a80290SSimon Glass struct spl_image_loader { 177ebc4ef61SSimon Glass #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 178ebc4ef61SSimon Glass const char *name; 179ebc4ef61SSimon Glass #endif 180a0a80290SSimon Glass uint boot_device; 181a0a80290SSimon Glass /** 182a0a80290SSimon Glass * load_image() - Load an SPL image 183a0a80290SSimon Glass * 1842a2ee2acSSimon Glass * @spl_image: place to put image information 185a0a80290SSimon Glass * @bootdev: describes the boot device to load from 186a0a80290SSimon Glass */ 1872a2ee2acSSimon Glass int (*load_image)(struct spl_image_info *spl_image, 1882a2ee2acSSimon Glass struct spl_boot_device *bootdev); 189a0a80290SSimon Glass }; 190a0a80290SSimon Glass 191a0a80290SSimon Glass /* Declare an SPL image loader */ 192a0a80290SSimon Glass #define SPL_LOAD_IMAGE(__name) \ 193a0a80290SSimon Glass ll_entry_declare(struct spl_image_loader, __name, spl_image_loader) 194a0a80290SSimon Glass 195a0a80290SSimon Glass /* 1960d3b0591SSimon Glass * _priority is the priority of this method, 0 meaning it will be the top 197a0a80290SSimon Glass * choice for this device, 9 meaning it is the bottom choice. 1980d3b0591SSimon Glass * _boot_device is the BOOT_DEVICE_... value 1990d3b0591SSimon Glass * _method is the load_image function to call 200a0a80290SSimon Glass */ 201ebc4ef61SSimon Glass #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 202ebc4ef61SSimon Glass #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \ 203ebc4ef61SSimon Glass SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \ 204ebc4ef61SSimon Glass .name = _name, \ 205ebc4ef61SSimon Glass .boot_device = _boot_device, \ 206ebc4ef61SSimon Glass .load_image = _method, \ 207ebc4ef61SSimon Glass } 208ebc4ef61SSimon Glass #else 209ebc4ef61SSimon Glass #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \ 2100d3b0591SSimon Glass SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \ 2110d3b0591SSimon Glass .boot_device = _boot_device, \ 2120d3b0591SSimon Glass .load_image = _method, \ 213a0a80290SSimon Glass } 214ebc4ef61SSimon Glass #endif 215a0a80290SSimon Glass 216773b5940SDan Murphy /* SPL FAT image functions */ 217710e9ca5SSimon Glass int spl_load_image_fat(struct spl_image_info *spl_image, 218710e9ca5SSimon Glass struct blk_desc *block_dev, int partition, 2194101f687SSimon Glass const char *filename); 220710e9ca5SSimon Glass int spl_load_image_fat_os(struct spl_image_info *spl_image, 221710e9ca5SSimon Glass struct blk_desc *block_dev, int partition); 222773b5940SDan Murphy 223ce048224SJeroen Hofstee void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image); 224ce048224SJeroen Hofstee 225592f9222SGuillaume GARDET /* SPL EXT image functions */ 226b4a6c2aaSSimon Glass int spl_load_image_ext(struct spl_image_info *spl_image, 227b4a6c2aaSSimon Glass struct blk_desc *block_dev, int partition, 2284101f687SSimon Glass const char *filename); 229b4a6c2aaSSimon Glass int spl_load_image_ext_os(struct spl_image_info *spl_image, 230b4a6c2aaSSimon Glass struct blk_desc *block_dev, int partition); 231592f9222SGuillaume GARDET 232070d00b8SSimon Glass /** 233340f418aSEddie Cai * spl_early_init() - Set up device tree and driver model in SPL if enabled 234070d00b8SSimon Glass * 235070d00b8SSimon Glass * Call this function in board_init_f() if you want to use device tree and 236340f418aSEddie Cai * driver model early, before board_init_r() is called. 237340f418aSEddie Cai * 238340f418aSEddie Cai * If this is not called, then driver model will be inactive in SPL's 239340f418aSEddie Cai * board_init_f(), and no device tree will be available. 240340f418aSEddie Cai */ 241340f418aSEddie Cai int spl_early_init(void); 242340f418aSEddie Cai 243340f418aSEddie Cai /** 244340f418aSEddie Cai * spl_init() - Set up device tree and driver model in SPL if enabled 245340f418aSEddie Cai * 246340f418aSEddie Cai * You can optionally call spl_early_init(), then optionally call spl_init(). 247340f418aSEddie Cai * This function will be called from board_init_r() if not called earlier. 248340f418aSEddie Cai * 249340f418aSEddie Cai * Both spl_early_init() and spl_init() perform a similar function except that 250340f418aSEddie Cai * the latter will not set up the malloc() area if 251340f418aSEddie Cai * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to 252340f418aSEddie Cai * already be done by a calll to spl_relocate_stack_gd() before board_init_r() 253340f418aSEddie Cai * is reached. 254340f418aSEddie Cai * 255340f418aSEddie Cai * This function will be called from board_init_r() if not called earlier. 256070d00b8SSimon Glass * 257070d00b8SSimon Glass * If this is not called, then driver model will be inactive in SPL's 258070d00b8SSimon Glass * board_init_f(), and no device tree will be available. 259070d00b8SSimon Glass */ 260070d00b8SSimon Glass int spl_init(void); 261070d00b8SSimon Glass 26247f7bcaeSTom Rini #ifdef CONFIG_SPL_BOARD_INIT 26347f7bcaeSTom Rini void spl_board_init(void); 26447f7bcaeSTom Rini #endif 26532ba8952SSimon Glass 26632ba8952SSimon Glass /** 26732ba8952SSimon Glass * spl_was_boot_source() - check if U-Boot booted from SPL 26832ba8952SSimon Glass * 26932ba8952SSimon Glass * This will normally be true, but if U-Boot jumps to second U-Boot, it will 27032ba8952SSimon Glass * be false. This should be implemented by board-specific code. 27132ba8952SSimon Glass * 27232ba8952SSimon Glass * @return true if U-Boot booted from SPL, else false 27332ba8952SSimon Glass */ 27432ba8952SSimon Glass bool spl_was_boot_source(void); 27532ba8952SSimon Glass 27652f2acc5SB, Ravi /** 27752f2acc5SB, Ravi * spl_dfu_cmd- run dfu command with chosen mmc device interface 27852f2acc5SB, Ravi * @param usb_index - usb controller number 27952f2acc5SB, Ravi * @param mmc_dev - mmc device nubmer 28052f2acc5SB, Ravi * 28152f2acc5SB, Ravi * @return 0 on success, otherwise error code 28252f2acc5SB, Ravi */ 28352f2acc5SB, Ravi int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr); 284e50d76ccSSimon Glass 285a786ab7aSJason Zhu int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device); 28609410c65SMarek Vasut int spl_mmc_load_image(struct spl_image_info *spl_image, 28709410c65SMarek Vasut struct spl_boot_device *bootdev); 28809410c65SMarek Vasut 2897940094cSKever Yang /** 29059acbc1bSPhilipp Tomsich * spl_invoke_atf - boot using an ARM trusted firmware image 2917940094cSKever Yang */ 29259acbc1bSPhilipp Tomsich void spl_invoke_atf(struct spl_image_info *spl_image); 293225d30b7SPhilipp Tomsich 294225d30b7SPhilipp Tomsich /** 29564d1b263SJoseph Chen * bl31_entry - Fill bl31_params structure, and jump to bl31 29664d1b263SJoseph Chen */ 2973bf65388SJason Zhu void bl31_entry(struct spl_image_info *spl_image, 2983bf65388SJason Zhu uintptr_t bl31_entry, uintptr_t bl32_entry, 29964d1b263SJoseph Chen uintptr_t bl33_entry, uintptr_t fdt_addr); 30064d1b263SJoseph Chen 30164d1b263SJoseph Chen /** 3021bd2b131SKever Yang * spl_optee_entry - entry function for optee 303099855e2SKever Yang * 304099855e2SKever Yang * args defind in op-tee project 305099855e2SKever Yang * https://github.com/OP-TEE/optee_os/ 306099855e2SKever Yang * core/arch/arm/kernel/generic_entry_a32.S 307099855e2SKever Yang * @arg0: pagestore 308099855e2SKever Yang * @arg1: (ARMv7 standard bootarg #1) 309099855e2SKever Yang * @arg2: device tree address, (ARMv7 standard bootarg #2) 310099855e2SKever Yang * @arg3: non-secure entry address (ARMv7 bootarg #0) 3111bd2b131SKever Yang */ 3121bd2b131SKever Yang void spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3); 3131bd2b131SKever Yang 3141bd2b131SKever Yang /** 315225d30b7SPhilipp Tomsich * board_return_to_bootrom - allow for boards to continue with the boot ROM 316225d30b7SPhilipp Tomsich * 317225d30b7SPhilipp Tomsich * If a board (e.g. the Rockchip RK3368 boards) provide some 318225d30b7SPhilipp Tomsich * supporting functionality for SPL in their boot ROM and the SPL 319225d30b7SPhilipp Tomsich * stage wants to return to the ROM code to continue booting, boards 320225d30b7SPhilipp Tomsich * can implement 'board_return_to_bootrom'. 321225d30b7SPhilipp Tomsich */ 322225d30b7SPhilipp Tomsich void board_return_to_bootrom(void); 32364d1b263SJoseph Chen 3246f678d2aSJason Zhu /** 325f8ca9d16SJoseph Chen * spl_cleanup_before_jump() - cleanup cache/mmu/interrupt, etc before jump 326f8ca9d16SJoseph Chen * to next stage. 327f8ca9d16SJoseph Chen */ 328f8ca9d16SJoseph Chen void spl_cleanup_before_jump(struct spl_image_info *spl_image); 329f8ca9d16SJoseph Chen 330f8ca9d16SJoseph Chen /** 3316f678d2aSJason Zhu * spl_perform_fixups() - arch/board-specific callback before processing 3326f678d2aSJason Zhu * the boot-payload 3336f678d2aSJason Zhu */ 3346f678d2aSJason Zhu void spl_perform_fixups(struct spl_image_info *spl_image); 3356f678d2aSJason Zhu 336f8ca9d16SJoseph Chen /** 337f8ca9d16SJoseph Chen * spl_board_prepare_for_jump() - arch/board-specific callback exactly before 338f8ca9d16SJoseph Chen * jumping to next stage 339f8ca9d16SJoseph Chen */ 340f8ca9d16SJoseph Chen int spl_board_prepare_for_jump(struct spl_image_info *spl_image); 341f8ca9d16SJoseph Chen 34244f37eaaSXuhui Lin #ifdef CONFIG_SPL_KERNEL_BOOT 343e12dde2dSJoseph Chen /** 344e12dde2dSJoseph Chen * spl_kernel_partition() - arch/board-specific callback to get kernel partition 345e12dde2dSJoseph Chen */ 346e12dde2dSJoseph Chen const char *spl_kernel_partition(struct spl_image_info *spl, 347e12dde2dSJoseph Chen struct spl_load_info *info); 34844f37eaaSXuhui Lin /** 349b37add71SXuhui Lin * spl_fdt_fixup_memory() - arch/board-specific fixup kernel dtb memory node. 350b37add71SXuhui Lin */ 351b37add71SXuhui Lin void spl_fdt_fixup_memory(struct spl_image_info *spl_image); 352b37add71SXuhui Lin /** 35344f37eaaSXuhui Lin * spl_find_hwid_dtb() - Support select kernel dtb based on HW-ID 35444f37eaaSXuhui Lin */ 35544f37eaaSXuhui Lin int spl_find_hwid_dtb(const char *fdt_name); 356*b6bda7d5SXuhui Lin /** 357*b6bda7d5SXuhui Lin * spl_fdt_chosen_bootargs() - Support append bootargs into kernel fdt chosen node 358*b6bda7d5SXuhui Lin */ 359*b6bda7d5SXuhui Lin int spl_fdt_chosen_bootargs(struct spl_load_info *info, void *fdt); 360e12dde2dSJoseph Chen #endif 361e12dde2dSJoseph Chen 36247f7bcaeSTom Rini #endif 363