spl.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_SECURE_BOOT)
  125. /*
  126. * +------------+ 0x0 (DDR_UIMAGE_START) -
  127. * | Header | |
  128. * +------------+ 0x40 |
  129. * | | |
  130. * | | |
  131. * | | |
  132. * | | |
  133. * | Image Data | |
  134. * . | |
  135. * . | > Stuff to be authenticated ----+
  136. * . | | |
  137. * | | | |
  138. * | | | |
  139. * +------------+ | |
  140. * | | | |
  141. * | Fill Data | | |
  142. * | | | |
  143. * +------------+ Align to ALIGN_SIZE | |
  144. * | IVT | | |
  145. * +------------+ + IVT_SIZE - |
  146. * | | |
  147. * | CSF DATA | <---------------------------------------------------------+
  148. * | |
  149. * +------------+
  150. * | |
  151. * | Fill Data |
  152. * | |
  153. * +------------+ + CSF_PAD_SIZE
  154. */
  155. __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  156. {
  157. typedef void __noreturn (*image_entry_noargs_t)(void);
  158. uint32_t offset;
  159. image_entry_noargs_t image_entry =
  160. (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
  161. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  162. /* HAB looks for the CSF at the end of the authenticated data therefore,
  163. * we need to subtract the size of the CSF from the actual filesize */
  164. offset = spl_image->size - CONFIG_CSF_SIZE;
  165. if (!imx_hab_authenticate_image(spl_image->load_addr,
  166. offset + IVT_SIZE + CSF_PAD_SIZE,
  167. offset)) {
  168. image_entry();
  169. } else {
  170. puts("spl: ERROR: image authentication unsuccessful\n");
  171. hang();
  172. }
  173. }
  174. #endif
  175. #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
  176. int dram_init_banksize(void)
  177. {
  178. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  179. gd->bd->bi_dram[0].size = imx_ddr_size();
  180. return 0;
  181. }
  182. #endif