spl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. DECLARE_GLOBAL_DATA_PTR;
  17. #if defined(CONFIG_MX6)
  18. /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
  19. u32 spl_boot_device(void)
  20. {
  21. unsigned int bmode = readl(&src_base->sbmr2);
  22. u32 reg = imx6_src_get_boot_mode();
  23. /*
  24. * Check for BMODE if serial downloader is enabled
  25. * BOOT_MODE - see IMX6DQRM Table 8-1
  26. */
  27. if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
  28. return BOOT_DEVICE_BOARD;
  29. /*
  30. * The above method does not detect that the boot ROM used
  31. * serial downloader in case the boot ROM decided to use the
  32. * serial downloader as a fall back (primary boot source failed).
  33. *
  34. * Infer that the boot ROM used the USB serial downloader by
  35. * checking whether the USB PHY is currently active... This
  36. * assumes that SPL did not (yet) initialize the USB PHY...
  37. */
  38. if (is_usbotg_phy_active())
  39. return BOOT_DEVICE_BOARD;
  40. /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
  41. switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
  42. /* EIM: See 8.5.1, Table 8-9 */
  43. case IMX6_BMODE_EMI:
  44. /* BOOT_CFG1[3]: NOR/OneNAND Selection */
  45. switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
  46. case IMX6_BMODE_ONENAND:
  47. return BOOT_DEVICE_ONENAND;
  48. case IMX6_BMODE_NOR:
  49. return BOOT_DEVICE_NOR;
  50. break;
  51. }
  52. /* Reserved: Used to force Serial Downloader */
  53. case IMX6_BMODE_RESERVED:
  54. return BOOT_DEVICE_BOARD;
  55. /* SATA: See 8.5.4, Table 8-20 */
  56. #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
  57. case IMX6_BMODE_SATA:
  58. return BOOT_DEVICE_SATA;
  59. #endif
  60. /* Serial ROM: See 8.5.5.1, Table 8-22 */
  61. case IMX6_BMODE_SERIAL_ROM:
  62. /* BOOT_CFG4[2:0] */
  63. switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
  64. IMX6_BMODE_SERIAL_ROM_SHIFT) {
  65. case IMX6_BMODE_ECSPI1:
  66. case IMX6_BMODE_ECSPI2:
  67. case IMX6_BMODE_ECSPI3:
  68. case IMX6_BMODE_ECSPI4:
  69. case IMX6_BMODE_ECSPI5:
  70. return BOOT_DEVICE_SPI;
  71. case IMX6_BMODE_I2C1:
  72. case IMX6_BMODE_I2C2:
  73. case IMX6_BMODE_I2C3:
  74. return BOOT_DEVICE_I2C;
  75. }
  76. break;
  77. /* SD/eSD: 8.5.3, Table 8-15 */
  78. case IMX6_BMODE_SD:
  79. case IMX6_BMODE_ESD:
  80. return BOOT_DEVICE_MMC1;
  81. /* MMC/eMMC: 8.5.3 */
  82. case IMX6_BMODE_MMC:
  83. case IMX6_BMODE_EMMC:
  84. return BOOT_DEVICE_MMC1;
  85. /* NAND Flash: 8.5.2, Table 8-10 */
  86. case IMX6_BMODE_NAND:
  87. return BOOT_DEVICE_NAND;
  88. }
  89. return BOOT_DEVICE_NONE;
  90. }
  91. #endif
  92. #if defined(CONFIG_SPL_MMC_SUPPORT)
  93. /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
  94. u32 spl_boot_mode(const u32 boot_device)
  95. {
  96. switch (spl_boot_device()) {
  97. /* for MMC return either RAW or FAT mode */
  98. case BOOT_DEVICE_MMC1:
  99. case BOOT_DEVICE_MMC2:
  100. #if defined(CONFIG_SPL_FAT_SUPPORT)
  101. return MMCSD_MODE_FS;
  102. #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
  103. return MMCSD_MODE_EMMCBOOT;
  104. #else
  105. return MMCSD_MODE_RAW;
  106. #endif
  107. break;
  108. default:
  109. puts("spl: ERROR: unsupported device\n");
  110. hang();
  111. }
  112. }
  113. #endif
  114. #if defined(CONFIG_SECURE_BOOT)
  115. __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  116. {
  117. typedef void __noreturn (*image_entry_noargs_t)(void);
  118. image_entry_noargs_t image_entry =
  119. (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
  120. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  121. /* HAB looks for the CSF at the end of the authenticated data therefore,
  122. * we need to subtract the size of the CSF from the actual filesize */
  123. if (authenticate_image(spl_image->load_addr,
  124. spl_image->size - CONFIG_CSF_SIZE)) {
  125. image_entry();
  126. } else {
  127. puts("spl: ERROR: image authentication unsuccessful\n");
  128. hang();
  129. }
  130. }
  131. #endif
  132. #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
  133. int dram_init_banksize(void)
  134. {
  135. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  136. gd->bd->bi_dram[0].size = imx_ddr_size();
  137. return 0;
  138. }
  139. #endif