Simon Glass | 7c03caf | 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 | 0ced70a | 2019-10-20 21:37:50 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 10 | #include <spl.h> |
| 11 | #include <asm/cpu.h> |
| 12 | #include <asm/mtrr.h> |
| 13 | #include <asm/processor.h> |
| 14 | #include <asm-generic/sections.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | __weak int arch_cpu_init_dm(void) |
| 19 | { |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static int x86_tpl_init(void) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | debug("%s starting\n", __func__); |
Simon Glass | 0e72ac7 | 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 | 7c03caf | 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 | } |
| 43 | ret = arch_cpu_init_dm(); |
| 44 | if (ret) { |
| 45 | debug("%s: arch_cpu_init_dm() failed\n", __func__); |
| 46 | return ret; |
| 47 | } |
| 48 | preloader_console_init(); |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | void board_init_f(ulong flags) |
| 54 | { |
| 55 | int ret; |
| 56 | |
| 57 | ret = x86_tpl_init(); |
| 58 | if (ret) { |
| 59 | debug("Error %d\n", ret); |
Simon Glass | 3d95688 | 2019-09-25 08:56:51 -0600 | [diff] [blame] | 60 | panic("x86_tpl_init fail"); |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* Uninit CAR and jump to board_init_f_r() */ |
| 64 | board_init_r(gd, 0); |
| 65 | } |
| 66 | |
| 67 | void board_init_f_r(void) |
| 68 | { |
| 69 | /* Not used since we never call board_init_f_r_trampoline() */ |
| 70 | while (1); |
| 71 | } |
| 72 | |
| 73 | u32 spl_boot_device(void) |
| 74 | { |
| 75 | return IS_ENABLED(CONFIG_CHROMEOS) ? BOOT_DEVICE_CROS_VBOOT : |
Simon Glass | daade11 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 76 | BOOT_DEVICE_SPI_MMAP; |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int spl_start_uboot(void) |
| 80 | { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | void spl_board_announce_boot_device(void) |
| 85 | { |
| 86 | printf("SPI flash"); |
| 87 | } |
| 88 | |
| 89 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 90 | struct spl_boot_device *bootdev) |
| 91 | { |
| 92 | spl_image->size = CONFIG_SYS_MONITOR_LEN; /* We don't know SPL size */ |
| 93 | spl_image->entry_point = CONFIG_SPL_TEXT_BASE; |
| 94 | spl_image->load_addr = CONFIG_SPL_TEXT_BASE; |
| 95 | spl_image->os = IH_OS_U_BOOT; |
| 96 | spl_image->name = "U-Boot"; |
| 97 | |
| 98 | debug("Loading to %lx\n", spl_image->load_addr); |
| 99 | |
| 100 | return 0; |
| 101 | } |
Simon Glass | daade11 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 102 | SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image); |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 103 | |
| 104 | int spl_spi_load_image(void) |
| 105 | { |
| 106 | return -EPERM; |
| 107 | } |
| 108 | |
| 109 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 110 | { |
Simon Glass | 73c6cd6 | 2019-10-20 21:37:57 -0600 | [diff] [blame] | 111 | debug("Jumping to U-Boot SPL at %lx\n", (ulong)spl_image->entry_point); |
Simon Glass | 7c03caf | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 112 | jump_to_spl(spl_image->entry_point); |
Simon Glass | 14dd93b | 2019-09-25 08:11:38 -0600 | [diff] [blame] | 113 | hang(); |
Simon Glass | 7c03caf | 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 | 0ced70a | 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 | */ |
| 133 | static const struct udevice_id tpl_fake_pci_ids[] = { |
| 134 | { .compatible = "pci-x86" }, |
| 135 | { } |
| 136 | }; |
| 137 | |
| 138 | U_BOOT_DRIVER(pci_x86) = { |
| 139 | .name = "pci_x86", |
| 140 | .id = UCLASS_SIMPLE_BUS, |
| 141 | .of_match = tpl_fake_pci_ids, |
| 142 | }; |
| 143 | #endif |