spl.c 3.6 KB

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