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