spl.h 8.4 KB

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