spl.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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)
  94. /* Translate iMX7 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. return BOOT_DEVICE_MMC1;
  104. case SPI_NOR_BOOT:
  105. return BOOT_DEVICE_SPI;
  106. default:
  107. return BOOT_DEVICE_NONE;
  108. }
  109. }
  110. #endif /* CONFIG_MX6 || CONFIG_MX7 */
  111. #ifdef CONFIG_SPL_USB_GADGET_SUPPORT
  112. int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
  113. {
  114. put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
  115. return 0;
  116. }
  117. #endif
  118. #if defined(CONFIG_SPL_MMC_SUPPORT)
  119. /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
  120. u32 spl_boot_mode(const u32 boot_device)
  121. {
  122. switch (spl_boot_device()) {
  123. /* for MMC return either RAW or FAT mode */
  124. case BOOT_DEVICE_MMC1:
  125. case BOOT_DEVICE_MMC2:
  126. #if defined(CONFIG_SPL_FAT_SUPPORT)
  127. return MMCSD_MODE_FS;
  128. #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
  129. return MMCSD_MODE_EMMCBOOT;
  130. #else
  131. return MMCSD_MODE_RAW;
  132. #endif
  133. break;
  134. default:
  135. puts("spl: ERROR: unsupported device\n");
  136. hang();
  137. }
  138. }
  139. #endif
  140. #if defined(CONFIG_SECURE_BOOT)
  141. __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  142. {
  143. typedef void __noreturn (*image_entry_noargs_t)(void);
  144. image_entry_noargs_t image_entry =
  145. (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
  146. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  147. /* HAB looks for the CSF at the end of the authenticated data therefore,
  148. * we need to subtract the size of the CSF from the actual filesize */
  149. if (authenticate_image(spl_image->load_addr,
  150. spl_image->size - CONFIG_CSF_SIZE)) {
  151. image_entry();
  152. } else {
  153. puts("spl: ERROR: image authentication unsuccessful\n");
  154. hang();
  155. }
  156. }
  157. #endif
  158. #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
  159. int dram_init_banksize(void)
  160. {
  161. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  162. gd->bd->bi_dram[0].size = imx_ddr_size();
  163. return 0;
  164. }
  165. #endif