spl.c 3.3 KB

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