spl.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * @info: Structure containing the information required to load data.
  47. * @sector: Sector number where FIT image is located in the device
  48. * @fdt: Pointer to the copied FIT header.
  49. *
  50. * Reads the FIT image @sector in the device. Loads u-boot image to
  51. * specified load address and copies the dtb to end of u-boot image.
  52. * Returns 0 on success.
  53. */
  54. int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fdt);
  55. #define SPL_COPY_PAYLOAD_ONLY 1
  56. extern struct spl_image_info spl_image;
  57. /* SPL common functions */
  58. void preloader_console_init(void);
  59. u32 spl_boot_device(void);
  60. u32 spl_boot_mode(const u32 boot_device);
  61. /**
  62. * spl_set_header_raw_uboot() - Set up a standard SPL image structure
  63. *
  64. * This sets up the given spl_image which the standard values obtained from
  65. * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
  66. * CONFIG_SYS_TEXT_BASE.
  67. *
  68. * @spl_image: Image description to set up
  69. */
  70. void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
  71. /**
  72. * spl_parse_image_header() - parse the image header and set up info
  73. *
  74. * This parses the legacy image header information at @header and sets up
  75. * @spl_image according to what is found. If no image header is found, then
  76. * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is
  77. * enabled, then this causes a panic. If CONFIG_SPL_ABORT_ON_RAW_IMAGE is
  78. * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using
  79. * spl_set_header_raw_uboot(), or possibly the bootz header.
  80. *
  81. * @spl_image: Image description to set up
  82. * @header image header to parse
  83. * @return 0 if a header was correctly parsed, -ve on error
  84. */
  85. int spl_parse_image_header(struct spl_image_info *spl_image,
  86. const struct image_header *header);
  87. void spl_board_prepare_for_linux(void);
  88. void spl_board_prepare_for_boot(void);
  89. int spl_board_ubi_load_image(u32 boot_device);
  90. /**
  91. * jump_to_image_linux() - Jump to a Linux kernel from SPL
  92. *
  93. * This jumps into a Linux kernel using the information in @spl_image.
  94. *
  95. * @spl_image: Image description to set up
  96. * @arg: Argument to pass to Linux (typically a device tree pointer)
  97. */
  98. void __noreturn jump_to_image_linux(struct spl_image_info *spl_image,
  99. void *arg);
  100. int spl_start_uboot(void);
  101. void spl_display_print(void);
  102. /* NAND SPL functions */
  103. int spl_nand_load_image(void);
  104. /* OneNAND SPL functions */
  105. int spl_onenand_load_image(void);
  106. /* NOR SPL functions */
  107. int spl_nor_load_image(void);
  108. /* UBI SPL functions */
  109. int spl_ubi_load_image(u32 boot_device);
  110. /* MMC SPL functions */
  111. int spl_mmc_load_image(u32 boot_device);
  112. /* YMODEM SPL functions */
  113. int spl_ymodem_load_image(void);
  114. /* SPI SPL functions */
  115. int spl_spi_load_image(void);
  116. /* Ethernet SPL functions */
  117. int spl_net_load_image(const char *device);
  118. /* USB SPL functions */
  119. int spl_usb_load_image(void);
  120. /* SATA SPL functions */
  121. int spl_sata_load_image(void);
  122. /* SPL FAT image functions */
  123. int spl_load_image_fat(struct blk_desc *block_dev, int partition,
  124. const char *filename);
  125. int spl_load_image_fat_os(struct blk_desc *block_dev, int partition);
  126. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
  127. /* SPL EXT image functions */
  128. int spl_load_image_ext(struct blk_desc *block_dev, int partition,
  129. const char *filename);
  130. int spl_load_image_ext_os(struct blk_desc *block_dev, int partition);
  131. /**
  132. * spl_init() - Set up device tree and driver model in SPL if enabled
  133. *
  134. * Call this function in board_init_f() if you want to use device tree and
  135. * driver model early, before board_init_r() is called. This function will
  136. * be called from board_init_r() if not called earlier.
  137. *
  138. * If this is not called, then driver model will be inactive in SPL's
  139. * board_init_f(), and no device tree will be available.
  140. */
  141. int spl_init(void);
  142. #ifdef CONFIG_SPL_BOARD_INIT
  143. void spl_board_init(void);
  144. #endif
  145. /**
  146. * spl_was_boot_source() - check if U-Boot booted from SPL
  147. *
  148. * This will normally be true, but if U-Boot jumps to second U-Boot, it will
  149. * be false. This should be implemented by board-specific code.
  150. *
  151. * @return true if U-Boot booted from SPL, else false
  152. */
  153. bool spl_was_boot_source(void);
  154. /**
  155. * spl_dfu_cmd- run dfu command with chosen mmc device interface
  156. * @param usb_index - usb controller number
  157. * @param mmc_dev - mmc device nubmer
  158. *
  159. * @return 0 on success, otherwise error code
  160. */
  161. int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
  162. /**
  163. * Board-specific load method for boards that have a special way of loading
  164. * U-Boot, which does not fit with the existing SPL code.
  165. *
  166. * @return 0 on success, negative errno value on failure.
  167. */
  168. int spl_board_load_image(void);
  169. #endif