spl.c 6.4 KB

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