spl.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <debug_uart.h>
  7. #include <spl.h>
  8. #include <asm/cpu.h>
  9. #include <asm/mtrr.h>
  10. #include <asm/processor.h>
  11. #include <asm-generic/sections.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. __weak int arch_cpu_init_dm(void)
  14. {
  15. return 0;
  16. }
  17. static int x86_spl_init(void)
  18. {
  19. /*
  20. * TODO(sjg@chromium.org): We use this area of RAM for the stack
  21. * and global_data in SPL. Once U-Boot starts up and releocates it
  22. * is not needed. We could make this a CONFIG option or perhaps
  23. * place it immediately below CONFIG_SYS_TEXT_BASE.
  24. */
  25. char *ptr = (char *)0x110000;
  26. int ret;
  27. debug("%s starting\n", __func__);
  28. ret = spl_init();
  29. if (ret) {
  30. debug("%s: spl_init() failed\n", __func__);
  31. return ret;
  32. }
  33. ret = arch_cpu_init();
  34. if (ret) {
  35. debug("%s: arch_cpu_init() failed\n", __func__);
  36. return ret;
  37. }
  38. ret = arch_cpu_init_dm();
  39. if (ret) {
  40. debug("%s: arch_cpu_init_dm() failed\n", __func__);
  41. return ret;
  42. }
  43. preloader_console_init();
  44. ret = print_cpuinfo();
  45. if (ret) {
  46. debug("%s: print_cpuinfo() failed\n", __func__);
  47. return ret;
  48. }
  49. ret = dram_init();
  50. if (ret) {
  51. debug("%s: dram_init() failed\n", __func__);
  52. return ret;
  53. }
  54. memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
  55. /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
  56. ret = interrupt_init();
  57. if (ret) {
  58. debug("%s: interrupt_init() failed\n", __func__);
  59. return ret;
  60. }
  61. /*
  62. * The stack grows down from ptr. Put the global data at ptr. This
  63. * will only be used for SPL. Once SPL loads U-Boot proper it will
  64. * set up its own stack.
  65. */
  66. gd->new_gd = (struct global_data *)ptr;
  67. memcpy(gd->new_gd, gd, sizeof(*gd));
  68. arch_setup_gd(gd->new_gd);
  69. gd->start_addr_sp = (ulong)ptr;
  70. /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
  71. ret = mtrr_add_request(MTRR_TYPE_WRBACK,
  72. (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
  73. CONFIG_XIP_ROM_SIZE);
  74. if (ret) {
  75. debug("%s: SPI cache setup failed\n", __func__);
  76. return ret;
  77. }
  78. return 0;
  79. }
  80. void board_init_f(ulong flags)
  81. {
  82. int ret;
  83. ret = x86_spl_init();
  84. if (ret) {
  85. debug("Error %d\n", ret);
  86. hang();
  87. }
  88. /* Uninit CAR and jump to board_init_f_r() */
  89. board_init_f_r_trampoline(gd->start_addr_sp);
  90. }
  91. void board_init_f_r(void)
  92. {
  93. init_cache_f_r();
  94. gd->flags &= ~GD_FLG_SERIAL_READY;
  95. debug("cache status %d\n", dcache_status());
  96. board_init_r(gd, 0);
  97. }
  98. u32 spl_boot_device(void)
  99. {
  100. return BOOT_DEVICE_BOARD;
  101. }
  102. int spl_start_uboot(void)
  103. {
  104. return 0;
  105. }
  106. void spl_board_announce_boot_device(void)
  107. {
  108. printf("SPI flash");
  109. }
  110. static int spl_board_load_image(struct spl_image_info *spl_image,
  111. struct spl_boot_device *bootdev)
  112. {
  113. spl_image->size = CONFIG_SYS_MONITOR_LEN;
  114. spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
  115. spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
  116. spl_image->os = IH_OS_U_BOOT;
  117. spl_image->name = "U-Boot";
  118. debug("Loading to %lx\n", spl_image->load_addr);
  119. return 0;
  120. }
  121. SPL_LOAD_IMAGE_METHOD("SPI", 0, BOOT_DEVICE_BOARD, spl_board_load_image);
  122. int spl_spi_load_image(void)
  123. {
  124. return -EPERM;
  125. }
  126. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  127. {
  128. int ret;
  129. printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
  130. ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
  131. debug("ret=%d\n", ret);
  132. while (1)
  133. ;
  134. }