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