tpl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <debug_uart.h>
  7. #include <dm.h>
  8. #include <hang.h>
  9. #include <image.h>
  10. #include <init.h>
  11. #include <log.h>
  12. #include <spl.h>
  13. #include <asm/cpu.h>
  14. #include <asm/global_data.h>
  15. #include <asm/mtrr.h>
  16. #include <asm/processor.h>
  17. #include <asm-generic/sections.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. static int x86_tpl_init(void)
  20. {
  21. int ret;
  22. debug("%s starting\n", __func__);
  23. ret = x86_cpu_init_tpl();
  24. if (ret) {
  25. debug("%s: x86_cpu_init_tpl() failed\n", __func__);
  26. return ret;
  27. }
  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. preloader_console_init();
  39. return 0;
  40. }
  41. void board_init_f(ulong flags)
  42. {
  43. int ret;
  44. ret = x86_tpl_init();
  45. if (ret) {
  46. debug("Error %d\n", ret);
  47. panic("x86_tpl_init fail");
  48. }
  49. /* Uninit CAR and jump to board_init_f_r() */
  50. board_init_r(gd, 0);
  51. }
  52. void board_init_f_r(void)
  53. {
  54. /* Not used since we never call board_init_f_r_trampoline() */
  55. while (1);
  56. }
  57. u32 spl_boot_device(void)
  58. {
  59. return IS_ENABLED(CONFIG_CHROMEOS_VBOOT) ? BOOT_DEVICE_CROS_VBOOT :
  60. BOOT_DEVICE_SPI_MMAP;
  61. }
  62. int spl_start_uboot(void)
  63. {
  64. return 0;
  65. }
  66. void spl_board_announce_boot_device(void)
  67. {
  68. printf("SPI flash");
  69. }
  70. static int spl_board_load_image(struct spl_image_info *spl_image,
  71. struct spl_boot_device *bootdev)
  72. {
  73. spl_image->size = CONFIG_SYS_MONITOR_LEN; /* We don't know SPL size */
  74. spl_image->entry_point = CONFIG_SPL_TEXT_BASE;
  75. spl_image->load_addr = CONFIG_SPL_TEXT_BASE;
  76. spl_image->os = IH_OS_U_BOOT;
  77. spl_image->name = "U-Boot";
  78. debug("Loading to %lx\n", spl_image->load_addr);
  79. return 0;
  80. }
  81. SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
  82. int spl_spi_load_image(void)
  83. {
  84. return -EPERM;
  85. }
  86. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  87. {
  88. debug("Jumping to %s at %lx\n", spl_phase_name(spl_next_phase()),
  89. (ulong)spl_image->entry_point);
  90. #ifdef DEBUG
  91. print_buffer(spl_image->entry_point, (void *)spl_image->entry_point, 1,
  92. 0x20, 0);
  93. #endif
  94. jump_to_spl(spl_image->entry_point);
  95. hang();
  96. }
  97. void spl_board_init(void)
  98. {
  99. preloader_console_init();
  100. }
  101. #if !CONFIG_IS_ENABLED(PCI)
  102. /*
  103. * This is a fake PCI bus for TPL when it doesn't have proper PCI. It is enough
  104. * to bind the devices on the PCI bus, some of which have early-regs properties
  105. * providing fixed BARs. Individual drivers program these BARs themselves so
  106. * that they can access the devices. The BARs are allocated statically in the
  107. * device tree.
  108. *
  109. * Once SPL is running it enables PCI properly, but does not auto-assign BARs
  110. * for devices, so the TPL BARs continue to be used. Once U-Boot starts it does
  111. * the auto allocation (after relocation).
  112. */
  113. #if CONFIG_IS_ENABLED(OF_REAL)
  114. static const struct udevice_id tpl_fake_pci_ids[] = {
  115. { .compatible = "pci-x86" },
  116. { }
  117. };
  118. #endif
  119. U_BOOT_DRIVER(pci_x86) = {
  120. .name = "pci_x86",
  121. .id = UCLASS_SIMPLE_BUS,
  122. .of_match = of_match_ptr(tpl_fake_pci_ids),
  123. DM_PHASE(tpl)
  124. };
  125. #endif