spl.c 4.2 KB

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