spl.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <debug_uart.h>
  8. #include <fdtdec.h>
  9. #include <hang.h>
  10. #include <init.h>
  11. #include <log.h>
  12. #include <spl.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/soc.h>
  16. static u32 get_boot_device(void)
  17. {
  18. u32 val;
  19. u32 boot_device;
  20. /*
  21. * First check, if UART boot-mode is active. This can only
  22. * be done, via the bootrom error register. Here the
  23. * MSB marks if the UART mode is active.
  24. */
  25. val = readl(CONFIG_BOOTROM_ERR_REG);
  26. boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
  27. debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  28. if (boot_device == BOOTROM_ERR_MODE_UART)
  29. return BOOT_DEVICE_UART;
  30. #ifdef CONFIG_ARMADA_38X
  31. /*
  32. * If the bootrom error code contains any other than zeros it's an
  33. * error condition and the bootROM has fallen back to UART boot
  34. */
  35. boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
  36. if (boot_device)
  37. return BOOT_DEVICE_UART;
  38. #endif
  39. /*
  40. * Now check the SAR register for the strapped boot-device
  41. */
  42. val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
  43. boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
  44. debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  45. switch (boot_device) {
  46. #if defined(CONFIG_ARMADA_38X)
  47. case BOOT_FROM_NAND:
  48. return BOOT_DEVICE_NAND;
  49. #endif
  50. #ifdef CONFIG_SPL_MMC_SUPPORT
  51. case BOOT_FROM_MMC:
  52. case BOOT_FROM_MMC_ALT:
  53. return BOOT_DEVICE_MMC1;
  54. #endif
  55. case BOOT_FROM_UART:
  56. #ifdef BOOT_FROM_UART_ALT
  57. case BOOT_FROM_UART_ALT:
  58. #endif
  59. return BOOT_DEVICE_UART;
  60. #ifdef BOOT_FROM_SATA
  61. case BOOT_FROM_SATA:
  62. case BOOT_FROM_SATA_ALT:
  63. return BOOT_DEVICE_SATA;
  64. #endif
  65. case BOOT_FROM_SPI:
  66. default:
  67. return BOOT_DEVICE_SPI;
  68. };
  69. }
  70. u32 spl_boot_device(void)
  71. {
  72. return get_boot_device();
  73. }
  74. void board_init_f(ulong dummy)
  75. {
  76. int ret;
  77. /*
  78. * Pin muxing needs to be done before UART output, since
  79. * on A38x the UART pins need some re-muxing for output
  80. * to work.
  81. */
  82. board_early_init_f();
  83. /* Example code showing how to enable the debug UART on MVEBU */
  84. #ifdef EARLY_UART
  85. /*
  86. * Debug UART can be used from here if required:
  87. *
  88. * debug_uart_init();
  89. * printch('a');
  90. * printhex8(0x1234);
  91. * printascii("string");
  92. */
  93. #endif
  94. /*
  95. * Use special translation offset for SPL. This needs to be
  96. * configured *before* spl_init() is called as this function
  97. * calls dm_init() which calls the bind functions of the
  98. * device drivers. Here the base address needs to be configured
  99. * (translated) correctly.
  100. */
  101. gd->translation_offset = 0xd0000000 - 0xf1000000;
  102. ret = spl_init();
  103. if (ret) {
  104. debug("spl_init() failed: %d\n", ret);
  105. hang();
  106. }
  107. preloader_console_init();
  108. timer_init();
  109. /* Armada 375 does not support SerDes and DDR3 init yet */
  110. #if !defined(CONFIG_ARMADA_375)
  111. /* First init the serdes PHY's */
  112. serdes_phy_config();
  113. /* Setup DDR */
  114. ddr3_init();
  115. #endif
  116. /* Initialize Auto Voltage Scaling */
  117. mv_avs_init();
  118. /* Update read timing control for PCIe */
  119. mv_rtc_config();
  120. /*
  121. * Return to the BootROM to continue the Marvell xmodem
  122. * UART boot protocol. As initiated by the kwboot tool.
  123. *
  124. * This can only be done by the BootROM and not by the
  125. * U-Boot SPL infrastructure, since the beginning of the
  126. * image is already read and interpreted by the BootROM.
  127. * SPL has no chance to receive this information. So we
  128. * need to return to the BootROM to enable this xmodem
  129. * UART download.
  130. *
  131. * If booting from NAND lets let the BootROM load the
  132. * rest of the bootloader.
  133. */
  134. switch (get_boot_device()) {
  135. case BOOT_DEVICE_UART:
  136. #if defined(CONFIG_ARMADA_38X)
  137. case BOOT_DEVICE_NAND:
  138. #endif
  139. return_to_bootrom();
  140. }
  141. }