spl.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/spl.h>
  13. #include <spl.h>
  14. #include <asm/imx-common/hab.h>
  15. #if defined(CONFIG_MX6)
  16. /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
  17. u32 spl_boot_device(void)
  18. {
  19. struct src *psrc = (struct src *)SRC_BASE_ADDR;
  20. unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
  21. unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
  22. unsigned int bmode = readl(&psrc->sbmr2);
  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_UART;
  29. /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
  30. switch ((reg & 0x000000FF) >> 4) {
  31. /* EIM: See 8.5.1, Table 8-9 */
  32. case 0x0:
  33. /* BOOT_CFG1[3]: NOR/OneNAND Selection */
  34. if ((reg & 0x00000008) >> 3)
  35. return BOOT_DEVICE_ONENAND;
  36. else
  37. return BOOT_DEVICE_NOR;
  38. break;
  39. /* Reserved: Used to force Serial Downloader */
  40. case 0x1:
  41. return BOOT_DEVICE_UART;
  42. /* SATA: See 8.5.4, Table 8-20 */
  43. case 0x2:
  44. return BOOT_DEVICE_SATA;
  45. /* Serial ROM: See 8.5.5.1, Table 8-22 */
  46. case 0x3:
  47. /* BOOT_CFG4[2:0] */
  48. switch ((reg & 0x07000000) >> 24) {
  49. case 0x0 ... 0x4:
  50. return BOOT_DEVICE_SPI;
  51. case 0x5 ... 0x7:
  52. return BOOT_DEVICE_I2C;
  53. }
  54. break;
  55. /* SD/eSD: 8.5.3, Table 8-15 */
  56. case 0x4:
  57. case 0x5:
  58. return BOOT_DEVICE_MMC1;
  59. /* MMC/eMMC: 8.5.3 */
  60. case 0x6:
  61. case 0x7:
  62. return BOOT_DEVICE_MMC1;
  63. /* NAND Flash: 8.5.2 */
  64. case 0x8 ... 0xf:
  65. return BOOT_DEVICE_NAND;
  66. }
  67. return BOOT_DEVICE_NONE;
  68. }
  69. #endif
  70. #if defined(CONFIG_SPL_MMC_SUPPORT)
  71. /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
  72. u32 spl_boot_mode(const u32 boot_device)
  73. {
  74. switch (spl_boot_device()) {
  75. /* for MMC return either RAW or FAT mode */
  76. case BOOT_DEVICE_MMC1:
  77. case BOOT_DEVICE_MMC2:
  78. #if defined(CONFIG_SPL_FAT_SUPPORT)
  79. return MMCSD_MODE_FS;
  80. #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
  81. return MMCSD_MODE_EMMCBOOT;
  82. #else
  83. return MMCSD_MODE_RAW;
  84. #endif
  85. break;
  86. default:
  87. puts("spl: ERROR: unsupported device\n");
  88. hang();
  89. }
  90. }
  91. #endif
  92. #if defined(CONFIG_SECURE_BOOT)
  93. __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  94. {
  95. typedef void __noreturn (*image_entry_noargs_t)(void);
  96. image_entry_noargs_t image_entry =
  97. (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
  98. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  99. /* HAB looks for the CSF at the end of the authenticated data therefore,
  100. * we need to subtract the size of the CSF from the actual filesize */
  101. if (authenticate_image(spl_image->load_addr,
  102. spl_image->size - CONFIG_CSF_SIZE)) {
  103. image_entry();
  104. } else {
  105. puts("spl: ERROR: image authentication unsuccessful\n");
  106. hang();
  107. }
  108. }
  109. #endif