spl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <spl.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/cpu.h>
  12. #include <asm/arch/soc.h>
  13. static u32 get_boot_device(void)
  14. {
  15. u32 val;
  16. u32 boot_device;
  17. /*
  18. * First check, if UART boot-mode is active. This can only
  19. * be done, via the bootrom error register. Here the
  20. * MSB marks if the UART mode is active.
  21. */
  22. val = readl(CONFIG_BOOTROM_ERR_REG);
  23. boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
  24. debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  25. #if defined(CONFIG_ARMADA_38X)
  26. /*
  27. * If the bootrom error register contains any else than zeros
  28. * in the first 8 bits it's an error condition. And in that case
  29. * try to boot from UART.
  30. */
  31. if (boot_device)
  32. #else
  33. if (boot_device == BOOTROM_ERR_MODE_UART)
  34. #endif
  35. return BOOT_DEVICE_UART;
  36. /*
  37. * Now check the SAR register for the strapped boot-device
  38. */
  39. val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
  40. boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
  41. debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  42. switch (boot_device) {
  43. #if defined(CONFIG_ARMADA_38X)
  44. case BOOT_FROM_NAND:
  45. return BOOT_DEVICE_NAND;
  46. #endif
  47. #ifdef CONFIG_SPL_MMC_SUPPORT
  48. case BOOT_FROM_MMC:
  49. case BOOT_FROM_MMC_ALT:
  50. return BOOT_DEVICE_MMC1;
  51. #endif
  52. case BOOT_FROM_UART:
  53. #ifdef BOOT_FROM_UART_ALT
  54. case BOOT_FROM_UART_ALT:
  55. #endif
  56. return BOOT_DEVICE_UART;
  57. case BOOT_FROM_SPI:
  58. default:
  59. return BOOT_DEVICE_SPI;
  60. };
  61. }
  62. u32 spl_boot_device(void)
  63. {
  64. return get_boot_device();
  65. }
  66. void board_init_f(ulong dummy)
  67. {
  68. int ret;
  69. /*
  70. * Pin muxing needs to be done before UART output, since
  71. * on A38x the UART pins need some re-muxing for output
  72. * to work.
  73. */
  74. board_early_init_f();
  75. /* Example code showing how to enable the debug UART on MVEBU */
  76. #ifdef EARLY_UART
  77. /*
  78. * Debug UART can be used from here if required:
  79. *
  80. * debug_uart_init();
  81. * printch('a');
  82. * printhex8(0x1234);
  83. * printascii("string");
  84. */
  85. #endif
  86. ret = spl_init();
  87. if (ret) {
  88. debug("spl_init() failed: %d\n", ret);
  89. hang();
  90. }
  91. /* Use special translation offset for SPL */
  92. dm_set_translation_offset(0xd0000000 - 0xf1000000);
  93. preloader_console_init();
  94. timer_init();
  95. /* Armada 375 does not support SerDes and DDR3 init yet */
  96. #if !defined(CONFIG_ARMADA_375)
  97. /* First init the serdes PHY's */
  98. serdes_phy_config();
  99. /* Setup DDR */
  100. ddr3_init();
  101. #endif
  102. /*
  103. * Return to the BootROM to continue the Marvell xmodem
  104. * UART boot protocol. As initiated by the kwboot tool.
  105. *
  106. * This can only be done by the BootROM and not by the
  107. * U-Boot SPL infrastructure, since the beginning of the
  108. * image is already read and interpreted by the BootROM.
  109. * SPL has no chance to receive this information. So we
  110. * need to return to the BootROM to enable this xmodem
  111. * UART download.
  112. *
  113. * If booting from NAND lets let the BootROM load the
  114. * rest of the bootloader.
  115. */
  116. switch (get_boot_device()) {
  117. case BOOT_DEVICE_UART:
  118. #if defined(CONFIG_ARMADA_38X)
  119. case BOOT_DEVICE_NAND:
  120. #endif
  121. return_to_bootrom();
  122. }
  123. }