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