spl.c 3.3 KB

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