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