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