spl.c 3.3 KB

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