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