blob: c84a0c9bc7d98ce0e0f35816e37bafb54b0a8e72 [file] [log] [blame]
Simon Glass7cf5fe02019-05-02 10:52:12 -06001// 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 Glass7b8a5582019-10-20 21:37:50 -06008#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060013#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
19DECLARE_GLOBAL_DATA_PTR;
20
21__weak int arch_cpu_init_dm(void)
22{
23 return 0;
24}
25
26static int x86_tpl_init(void)
27{
28 int ret;
29
30 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060031 ret = x86_cpu_init_tpl();
32 if (ret) {
33 debug("%s: x86_cpu_init_tpl() failed\n", __func__);
34 return ret;
35 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060036 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 Glass7cf5fe02019-05-02 10:52:12 -060052
53 return 0;
54}
55
56void 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 Glass11ba7142019-09-25 08:56:51 -060063 panic("x86_tpl_init fail");
Simon Glass7cf5fe02019-05-02 10:52:12 -060064 }
65
66 /* Uninit CAR and jump to board_init_f_r() */
67 board_init_r(gd, 0);
68}
69
70void board_init_f_r(void)
71{
72 /* Not used since we never call board_init_f_r_trampoline() */
73 while (1);
74}
75
76u32 spl_boot_device(void)
77{
Simon Glassd81f07f2020-11-04 09:57:35 -070078 return IS_ENABLED(CONFIG_CHROMEOS_VBOOT) ? BOOT_DEVICE_CROS_VBOOT :
Simon Glass19da9c42019-09-25 08:11:39 -060079 BOOT_DEVICE_SPI_MMAP;
Simon Glass7cf5fe02019-05-02 10:52:12 -060080}
81
82int spl_start_uboot(void)
83{
84 return 0;
85}
86
87void spl_board_announce_boot_device(void)
88{
89 printf("SPI flash");
90}
91
92static 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 Glass19da9c42019-09-25 08:11:39 -0600105SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600106
107int spl_spi_load_image(void)
108{
109 return -EPERM;
110}
111
112void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
113{
Simon Glassc00af3e2021-01-24 10:06:11 -0700114 debug("Jumping to %s at %lx\n", spl_phase_name(spl_next_phase()),
115 (ulong)spl_image->entry_point);
116#ifdef DEBUG
117 print_buffer(spl_image->entry_point, (void *)spl_image->entry_point, 1,
118 0x20, 0);
119#endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600120 jump_to_spl(spl_image->entry_point);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600121 hang();
Simon Glass7cf5fe02019-05-02 10:52:12 -0600122}
123
124void spl_board_init(void)
125{
126 preloader_console_init();
127}
Simon Glass7b8a5582019-10-20 21:37:50 -0600128
129#if !CONFIG_IS_ENABLED(PCI)
130/*
131 * This is a fake PCI bus for TPL when it doesn't have proper PCI. It is enough
132 * to bind the devices on the PCI bus, some of which have early-regs properties
133 * providing fixed BARs. Individual drivers program these BARs themselves so
134 * that they can access the devices. The BARs are allocated statically in the
135 * device tree.
136 *
137 * Once SPL is running it enables PCI properly, but does not auto-assign BARs
138 * for devices, so the TPL BARs continue to be used. Once U-Boot starts it does
139 * the auto allocation (after relocation).
140 */
Simon Glasse1bafd52020-12-23 08:11:32 -0700141#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass7b8a5582019-10-20 21:37:50 -0600142static const struct udevice_id tpl_fake_pci_ids[] = {
143 { .compatible = "pci-x86" },
144 { }
145};
Simon Glasse1bafd52020-12-23 08:11:32 -0700146#endif
Simon Glass7b8a5582019-10-20 21:37:50 -0600147
148U_BOOT_DRIVER(pci_x86) = {
149 .name = "pci_x86",
150 .id = UCLASS_SIMPLE_BUS,
Simon Glasse1bafd52020-12-23 08:11:32 -0700151 .of_match = of_match_ptr(tpl_fake_pci_ids),
Simon Glass7b8a5582019-10-20 21:37:50 -0600152};
153#endif