spl.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014 Gateworks Corporation
  4. * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
  5. *
  6. * Author: Tim Harvey <tharvey@gateworks.com>
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/imx-regs.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/spl.h>
  13. #include <spl.h>
  14. #include <asm/mach-imx/hab.h>
  15. #include <asm/mach-imx/boot_mode.h>
  16. #include <g_dnl.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. #if defined(CONFIG_MX6)
  19. /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
  20. u32 spl_boot_device(void)
  21. {
  22. unsigned int bmode = readl(&src_base->sbmr2);
  23. u32 reg = imx6_src_get_boot_mode();
  24. /*
  25. * Check for BMODE if serial downloader is enabled
  26. * BOOT_MODE - see IMX6DQRM Table 8-1
  27. */
  28. if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
  29. return BOOT_DEVICE_BOARD;
  30. /*
  31. * The above method does not detect that the boot ROM used
  32. * serial downloader in case the boot ROM decided to use the
  33. * serial downloader as a fall back (primary boot source failed).
  34. *
  35. * Infer that the boot ROM used the USB serial downloader by
  36. * checking whether the USB PHY is currently active... This
  37. * assumes that SPL did not (yet) initialize the USB PHY...
  38. */
  39. if (is_usbotg_phy_active())
  40. return BOOT_DEVICE_BOARD;
  41. /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
  42. switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
  43. /* EIM: See 8.5.1, Table 8-9 */
  44. case IMX6_BMODE_EMI:
  45. /* BOOT_CFG1[3]: NOR/OneNAND Selection */
  46. switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
  47. case IMX6_BMODE_ONENAND:
  48. return BOOT_DEVICE_ONENAND;
  49. case IMX6_BMODE_NOR:
  50. return BOOT_DEVICE_NOR;
  51. break;
  52. }
  53. /* Reserved: Used to force Serial Downloader */
  54. case IMX6_BMODE_RESERVED:
  55. return BOOT_DEVICE_BOARD;
  56. /* SATA: See 8.5.4, Table 8-20 */
  57. #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
  58. case IMX6_BMODE_SATA:
  59. return BOOT_DEVICE_SATA;
  60. #endif
  61. /* Serial ROM: See 8.5.5.1, Table 8-22 */
  62. case IMX6_BMODE_SERIAL_ROM:
  63. /* BOOT_CFG4[2:0] */
  64. switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
  65. IMX6_BMODE_SERIAL_ROM_SHIFT) {
  66. case IMX6_BMODE_ECSPI1:
  67. case IMX6_BMODE_ECSPI2:
  68. case IMX6_BMODE_ECSPI3:
  69. case IMX6_BMODE_ECSPI4:
  70. case IMX6_BMODE_ECSPI5:
  71. return BOOT_DEVICE_SPI;
  72. case IMX6_BMODE_I2C1:
  73. case IMX6_BMODE_I2C2:
  74. case IMX6_BMODE_I2C3:
  75. return BOOT_DEVICE_I2C;
  76. }
  77. break;
  78. /* SD/eSD: 8.5.3, Table 8-15 */
  79. case IMX6_BMODE_SD:
  80. case IMX6_BMODE_ESD:
  81. return BOOT_DEVICE_MMC1;
  82. /* MMC/eMMC: 8.5.3 */
  83. case IMX6_BMODE_MMC:
  84. case IMX6_BMODE_EMMC:
  85. return BOOT_DEVICE_MMC1;
  86. /* NAND Flash: 8.5.2, Table 8-10 */
  87. case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
  88. return BOOT_DEVICE_NAND;
  89. }
  90. return BOOT_DEVICE_NONE;
  91. }
  92. #elif defined(CONFIG_MX7) || defined(CONFIG_MX8M)
  93. /* Translate iMX7/MX8M boot device to the SPL boot device enumeration */
  94. u32 spl_boot_device(void)
  95. {
  96. #if defined(CONFIG_MX7)
  97. unsigned int bmode = readl(&src_base->sbmr2);
  98. /*
  99. * Check for BMODE if serial downloader is enabled
  100. * BOOT_MODE - see IMX7DRM Table 6-24
  101. */
  102. if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
  103. return BOOT_DEVICE_BOARD;
  104. /*
  105. * The above method does not detect that the boot ROM used
  106. * serial downloader in case the boot ROM decided to use the
  107. * serial downloader as a fall back (primary boot source failed).
  108. *
  109. * Infer that the boot ROM used the USB serial downloader by
  110. * checking whether the USB PHY is currently active... This
  111. * assumes that SPL did not (yet) initialize the USB PHY...
  112. */
  113. if (is_boot_from_usb())
  114. return BOOT_DEVICE_BOARD;
  115. #endif
  116. enum boot_device boot_device_spl = get_boot_device();
  117. switch (boot_device_spl) {
  118. case SD1_BOOT:
  119. case MMC1_BOOT:
  120. case SD2_BOOT:
  121. case MMC2_BOOT:
  122. case SD3_BOOT:
  123. case MMC3_BOOT:
  124. return BOOT_DEVICE_MMC1;
  125. case NAND_BOOT:
  126. return BOOT_DEVICE_NAND;
  127. case SPI_NOR_BOOT:
  128. return BOOT_DEVICE_SPI;
  129. case USB_BOOT:
  130. return BOOT_DEVICE_USB;
  131. default:
  132. return BOOT_DEVICE_NONE;
  133. }
  134. }
  135. #endif /* CONFIG_MX6 || CONFIG_MX7 || CONFIG_MX8M */
  136. #ifdef CONFIG_SPL_USB_GADGET_SUPPORT
  137. int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
  138. {
  139. put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
  140. return 0;
  141. }
  142. #endif
  143. #if defined(CONFIG_SPL_MMC_SUPPORT)
  144. /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
  145. u32 spl_boot_mode(const u32 boot_device)
  146. {
  147. switch (spl_boot_device()) {
  148. /* for MMC return either RAW or FAT mode */
  149. case BOOT_DEVICE_MMC1:
  150. case BOOT_DEVICE_MMC2:
  151. #if defined(CONFIG_SPL_FAT_SUPPORT)
  152. return MMCSD_MODE_FS;
  153. #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
  154. return MMCSD_MODE_EMMCBOOT;
  155. #else
  156. return MMCSD_MODE_RAW;
  157. #endif
  158. break;
  159. default:
  160. puts("spl: ERROR: unsupported device\n");
  161. hang();
  162. }
  163. }
  164. #endif
  165. #if defined(CONFIG_SECURE_BOOT)
  166. /*
  167. * +------------+ 0x0 (DDR_UIMAGE_START) -
  168. * | Header | |
  169. * +------------+ 0x40 |
  170. * | | |
  171. * | | |
  172. * | | |
  173. * | | |
  174. * | Image Data | |
  175. * . | |
  176. * . | > Stuff to be authenticated ----+
  177. * . | | |
  178. * | | | |
  179. * | | | |
  180. * +------------+ | |
  181. * | | | |
  182. * | Fill Data | | |
  183. * | | | |
  184. * +------------+ Align to ALIGN_SIZE | |
  185. * | IVT | | |
  186. * +------------+ + IVT_SIZE - |
  187. * | | |
  188. * | CSF DATA | <---------------------------------------------------------+
  189. * | |
  190. * +------------+
  191. * | |
  192. * | Fill Data |
  193. * | |
  194. * +------------+ + CSF_PAD_SIZE
  195. */
  196. __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  197. {
  198. typedef void __noreturn (*image_entry_noargs_t)(void);
  199. uint32_t offset;
  200. image_entry_noargs_t image_entry =
  201. (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
  202. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  203. /* HAB looks for the CSF at the end of the authenticated data therefore,
  204. * we need to subtract the size of the CSF from the actual filesize */
  205. offset = spl_image->size - CONFIG_CSF_SIZE;
  206. if (!imx_hab_authenticate_image(spl_image->load_addr,
  207. offset + IVT_SIZE + CSF_PAD_SIZE,
  208. offset)) {
  209. image_entry();
  210. } else {
  211. puts("spl: ERROR: image authentication unsuccessful\n");
  212. hang();
  213. }
  214. }
  215. #endif
  216. #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
  217. int dram_init_banksize(void)
  218. {
  219. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  220. gd->bd->bi_dram[0].size = imx_ddr_size();
  221. return 0;
  222. }
  223. #endif