spl.c 3.3 KB

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