spl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <debug_uart.h>
  9. #include <fdtdec.h>
  10. #include <spl.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/cpu.h>
  13. #include <asm/arch/soc.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static u32 get_boot_device(void)
  16. {
  17. u32 val;
  18. u32 boot_device;
  19. /*
  20. * First check, if UART boot-mode is active. This can only
  21. * be done, via the bootrom error register. Here the
  22. * MSB marks if the UART mode is active.
  23. */
  24. val = readl(CONFIG_BOOTROM_ERR_REG);
  25. boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
  26. debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  27. if (boot_device == BOOTROM_ERR_MODE_UART)
  28. return BOOT_DEVICE_UART;
  29. /*
  30. * Now check the SAR register for the strapped boot-device
  31. */
  32. val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
  33. boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
  34. debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  35. switch (boot_device) {
  36. #ifdef CONFIG_SPL_MMC_SUPPORT
  37. case BOOT_FROM_MMC:
  38. case BOOT_FROM_MMC_ALT:
  39. return BOOT_DEVICE_MMC1;
  40. #endif
  41. case BOOT_FROM_UART:
  42. return BOOT_DEVICE_UART;
  43. case BOOT_FROM_SPI:
  44. default:
  45. return BOOT_DEVICE_SPI;
  46. };
  47. }
  48. u32 spl_boot_device(void)
  49. {
  50. return get_boot_device();
  51. }
  52. #ifdef CONFIG_SPL_MMC_SUPPORT
  53. u32 spl_boot_mode(const u32 boot_device)
  54. {
  55. return MMCSD_MODE_RAW;
  56. }
  57. #endif
  58. void board_init_f(ulong dummy)
  59. {
  60. int ret;
  61. /*
  62. * Pin muxing needs to be done before UART output, since
  63. * on A38x the UART pins need some re-muxing for output
  64. * to work.
  65. */
  66. board_early_init_f();
  67. /* Example code showing how to enable the debug UART on MVEBU */
  68. #ifdef EARLY_UART
  69. /*
  70. * Debug UART can be used from here if required:
  71. *
  72. * debug_uart_init();
  73. * printch('a');
  74. * printhex8(0x1234);
  75. * printascii("string");
  76. */
  77. #endif
  78. ret = spl_init();
  79. if (ret) {
  80. debug("spl_init() failed: %d\n", ret);
  81. hang();
  82. }
  83. /* Use special translation offset for SPL */
  84. dm_set_translation_offset(0xd0000000 - 0xf1000000);
  85. preloader_console_init();
  86. timer_init();
  87. /* Armada 375 does not support SerDes and DDR3 init yet */
  88. #if !defined(CONFIG_ARMADA_375)
  89. /* First init the serdes PHY's */
  90. serdes_phy_config();
  91. /* Setup DDR */
  92. ddr3_init();
  93. #endif
  94. /*
  95. * Return to the BootROM to continue the Marvell xmodem
  96. * UART boot protocol. As initiated by the kwboot tool.
  97. *
  98. * This can only be done by the BootROM and not by the
  99. * U-Boot SPL infrastructure, since the beginning of the
  100. * image is already read and interpreted by the BootROM.
  101. * SPL has no chance to receive this information. So we
  102. * need to return to the BootROM to enable this xmodem
  103. * UART download.
  104. */
  105. if (get_boot_device() == BOOT_DEVICE_UART)
  106. return_to_bootrom();
  107. }