spl.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. /* Platform-specific defines */
  10. #include <linux/compiler.h>
  11. #include <asm/spl.h>
  12. /* Value in r0 indicates we booted from U-Boot */
  13. #define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
  14. /* Boot type */
  15. #define MMCSD_MODE_UNDEFINED 0
  16. #define MMCSD_MODE_RAW 1
  17. #define MMCSD_MODE_FS 2
  18. #define MMCSD_MODE_EMMCBOOT 3
  19. struct spl_image_info {
  20. const char *name;
  21. u8 os;
  22. uintptr_t load_addr;
  23. uintptr_t entry_point;
  24. #if CONFIG_IS_ENABLED(LOAD_FIT)
  25. void *fdt_addr;
  26. #endif
  27. u32 size;
  28. u32 flags;
  29. void *arg;
  30. };
  31. /*
  32. * Information required to load data from a device
  33. *
  34. * @dev: Pointer to the device, e.g. struct mmc *
  35. * @priv: Private data for the device
  36. * @bl_len: Block length for reading in bytes
  37. * @filename: Name of the fit image file.
  38. * @read: Function to call to read from the device
  39. */
  40. struct spl_load_info {
  41. void *dev;
  42. void *priv;
  43. int bl_len;
  44. const char *filename;
  45. ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
  46. void *buf);
  47. };
  48. /**
  49. * spl_load_simple_fit() - Loads a fit image from a device.
  50. * @spl_image: Image description to set up
  51. * @info: Structure containing the information required to load data.
  52. * @sector: Sector number where FIT image is located in the device
  53. * @fdt: Pointer to the copied FIT header.
  54. *
  55. * Reads the FIT image @sector in the device. Loads u-boot image to
  56. * specified load address and copies the dtb to end of u-boot image.
  57. * Returns 0 on success.
  58. */
  59. int spl_load_simple_fit(struct spl_image_info *spl_image,
  60. struct spl_load_info *info, ulong sector, void *fdt);
  61. #define SPL_COPY_PAYLOAD_ONLY 1
  62. /* SPL common functions */
  63. void preloader_console_init(void);
  64. u32 spl_boot_device(void);
  65. u32 spl_boot_mode(const u32 boot_device);
  66. void spl_set_bd(void);
  67. /**
  68. * spl_set_header_raw_uboot() - Set up a standard SPL image structure
  69. *
  70. * This sets up the given spl_image which the standard values obtained from
  71. * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
  72. * CONFIG_SYS_TEXT_BASE.
  73. *
  74. * @spl_image: Image description to set up
  75. */
  76. void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
  77. /**
  78. * spl_parse_image_header() - parse the image header and set up info
  79. *
  80. * This parses the legacy image header information at @header and sets up
  81. * @spl_image according to what is found. If no image header is found, then
  82. * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is
  83. * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not
  84. * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using
  85. * spl_set_header_raw_uboot(), or possibly the bootz header.
  86. *
  87. * @spl_image: Image description to set up
  88. * @header image header to parse
  89. * @return 0 if a header was correctly parsed, -ve on error
  90. */
  91. int spl_parse_image_header(struct spl_image_info *spl_image,
  92. const struct image_header *header);
  93. void spl_board_prepare_for_linux(void);
  94. void spl_board_prepare_for_boot(void);
  95. int spl_board_ubi_load_image(u32 boot_device);
  96. /**
  97. * jump_to_image_linux() - Jump to a Linux kernel from SPL
  98. *
  99. * This jumps into a Linux kernel using the information in @spl_image.
  100. *
  101. * @spl_image: Image description to set up
  102. */
  103. void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
  104. /**
  105. * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
  106. *
  107. * This is called by the various SPL loaders to determine whether the board
  108. * wants to load the kernel or U-Boot. This function should be provided by
  109. * the board.
  110. *
  111. * @return 0 if SPL should start the kernel, 1 if U-Boot must be started
  112. */
  113. int spl_start_uboot(void);
  114. /**
  115. * spl_display_print() - Display a board-specific message in SPL
  116. *
  117. * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function
  118. * immediately after displaying the SPL console banner ("U-Boot SPL ...").
  119. * This function should be provided by the board.
  120. */
  121. void spl_display_print(void);
  122. /**
  123. * struct spl_boot_device - Describes a boot device used by SPL
  124. *
  125. * @boot_device: A number indicating the BOOT_DEVICE type. There are various
  126. * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently
  127. * numbered.
  128. * @boot_device_name: Named boot device, or NULL if none.
  129. *
  130. * Note: Additional fields can be added here, bearing in mind that SPL is
  131. * size-sensitive and common fields will be present on all boards. This
  132. * struct can also be used to return additional information about the load
  133. * process if that becomes useful.
  134. */
  135. struct spl_boot_device {
  136. uint boot_device;
  137. const char *boot_device_name;
  138. };
  139. /**
  140. * Holds information about a way of loading an SPL image
  141. *
  142. * @name: User-friendly name for this method (e.g. "MMC")
  143. * @boot_device: Boot device that this loader supports
  144. * @load_image: Function to call to load image
  145. */
  146. struct spl_image_loader {
  147. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  148. const char *name;
  149. #endif
  150. uint boot_device;
  151. /**
  152. * load_image() - Load an SPL image
  153. *
  154. * @spl_image: place to put image information
  155. * @bootdev: describes the boot device to load from
  156. */
  157. int (*load_image)(struct spl_image_info *spl_image,
  158. struct spl_boot_device *bootdev);
  159. };
  160. /* Declare an SPL image loader */
  161. #define SPL_LOAD_IMAGE(__name) \
  162. ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
  163. /*
  164. * _priority is the priority of this method, 0 meaning it will be the top
  165. * choice for this device, 9 meaning it is the bottom choice.
  166. * _boot_device is the BOOT_DEVICE_... value
  167. * _method is the load_image function to call
  168. */
  169. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  170. #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
  171. SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \
  172. .name = _name, \
  173. .boot_device = _boot_device, \
  174. .load_image = _method, \
  175. }
  176. #else
  177. #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
  178. SPL_LOAD_IMAGE(_method ## _priority ## _boot_device) = { \
  179. .boot_device = _boot_device, \
  180. .load_image = _method, \
  181. }
  182. #endif
  183. /* SPL FAT image functions */
  184. int spl_load_image_fat(struct spl_image_info *spl_image,
  185. struct blk_desc *block_dev, int partition,
  186. const char *filename);
  187. int spl_load_image_fat_os(struct spl_image_info *spl_image,
  188. struct blk_desc *block_dev, int partition);
  189. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
  190. /* SPL EXT image functions */
  191. int spl_load_image_ext(struct spl_image_info *spl_image,
  192. struct blk_desc *block_dev, int partition,
  193. const char *filename);
  194. int spl_load_image_ext_os(struct spl_image_info *spl_image,
  195. struct blk_desc *block_dev, int partition);
  196. /**
  197. * spl_early_init() - Set up device tree and driver model in SPL if enabled
  198. *
  199. * Call this function in board_init_f() if you want to use device tree and
  200. * driver model early, before board_init_r() is called.
  201. *
  202. * If this is not called, then driver model will be inactive in SPL's
  203. * board_init_f(), and no device tree will be available.
  204. */
  205. int spl_early_init(void);
  206. /**
  207. * spl_init() - Set up device tree and driver model in SPL if enabled
  208. *
  209. * You can optionally call spl_early_init(), then optionally call spl_init().
  210. * This function will be called from board_init_r() if not called earlier.
  211. *
  212. * Both spl_early_init() and spl_init() perform a similar function except that
  213. * the latter will not set up the malloc() area if
  214. * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to
  215. * already be done by a calll to spl_relocate_stack_gd() before board_init_r()
  216. * is reached.
  217. *
  218. * This function will be called from board_init_r() if not called earlier.
  219. *
  220. * If this is not called, then driver model will be inactive in SPL's
  221. * board_init_f(), and no device tree will be available.
  222. */
  223. int spl_init(void);
  224. #ifdef CONFIG_SPL_BOARD_INIT
  225. void spl_board_init(void);
  226. #endif
  227. /**
  228. * spl_was_boot_source() - check if U-Boot booted from SPL
  229. *
  230. * This will normally be true, but if U-Boot jumps to second U-Boot, it will
  231. * be false. This should be implemented by board-specific code.
  232. *
  233. * @return true if U-Boot booted from SPL, else false
  234. */
  235. bool spl_was_boot_source(void);
  236. /**
  237. * spl_dfu_cmd- run dfu command with chosen mmc device interface
  238. * @param usb_index - usb controller number
  239. * @param mmc_dev - mmc device nubmer
  240. *
  241. * @return 0 on success, otherwise error code
  242. */
  243. int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
  244. int spl_mmc_load_image(struct spl_image_info *spl_image,
  245. struct spl_boot_device *bootdev);
  246. /**
  247. * spl_invoke_atf - boot using an ARM trusted firmware image
  248. */
  249. void spl_invoke_atf(struct spl_image_info *spl_image);
  250. /**
  251. * board_return_to_bootrom - allow for boards to continue with the boot ROM
  252. *
  253. * If a board (e.g. the Rockchip RK3368 boards) provide some
  254. * supporting functionality for SPL in their boot ROM and the SPL
  255. * stage wants to return to the ROM code to continue booting, boards
  256. * can implement 'board_return_to_bootrom'.
  257. */
  258. void board_return_to_bootrom(void);
  259. #endif