blob: 18b05b2f67208de0e2561cdd94036619c5ed8257 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060016#include <asm/mtrr.h>
17#include <asm/processor.h>
18#include <asm-generic/sections.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
Simon Glass7cf5fe02019-05-02 10:52:12 -060022static int x86_tpl_init(void)
23{
24 int ret;
25
26 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060027 ret = x86_cpu_init_tpl();
28 if (ret) {
29 debug("%s: x86_cpu_init_tpl() failed\n", __func__);
30 return ret;
31 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060032 ret = spl_init();
33 if (ret) {
34 debug("%s: spl_init() failed\n", __func__);
35 return ret;
36 }
37 ret = arch_cpu_init();
38 if (ret) {
39 debug("%s: arch_cpu_init() failed\n", __func__);
40 return ret;
41 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060042 preloader_console_init();
Simon Glass7cf5fe02019-05-02 10:52:12 -060043
44 return 0;
45}
46
47void board_init_f(ulong flags)
48{
49 int ret;
50
51 ret = x86_tpl_init();
52 if (ret) {
53 debug("Error %d\n", ret);
Simon Glass11ba7142019-09-25 08:56:51 -060054 panic("x86_tpl_init fail");
Simon Glass7cf5fe02019-05-02 10:52:12 -060055 }
56
57 /* Uninit CAR and jump to board_init_f_r() */
58 board_init_r(gd, 0);
59}
60
61void board_init_f_r(void)
62{
63 /* Not used since we never call board_init_f_r_trampoline() */
64 while (1);
65}
66
67u32 spl_boot_device(void)
68{
Simon Glassd81f07f2020-11-04 09:57:35 -070069 return IS_ENABLED(CONFIG_CHROMEOS_VBOOT) ? BOOT_DEVICE_CROS_VBOOT :
Simon Glass19da9c42019-09-25 08:11:39 -060070 BOOT_DEVICE_SPI_MMAP;
Simon Glass7cf5fe02019-05-02 10:52:12 -060071}
72
73int spl_start_uboot(void)
74{
75 return 0;
76}
77
78void spl_board_announce_boot_device(void)
79{
80 printf("SPI flash");
81}
82
83static int spl_board_load_image(struct spl_image_info *spl_image,
84 struct spl_boot_device *bootdev)
85{
86 spl_image->size = CONFIG_SYS_MONITOR_LEN; /* We don't know SPL size */
87 spl_image->entry_point = CONFIG_SPL_TEXT_BASE;
88 spl_image->load_addr = CONFIG_SPL_TEXT_BASE;
89 spl_image->os = IH_OS_U_BOOT;
90 spl_image->name = "U-Boot";
91
92 debug("Loading to %lx\n", spl_image->load_addr);
93
94 return 0;
95}
Simon Glass19da9c42019-09-25 08:11:39 -060096SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass7cf5fe02019-05-02 10:52:12 -060097
98int spl_spi_load_image(void)
99{
100 return -EPERM;
101}
102
103void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
104{
Simon Glassc00af3e2021-01-24 10:06:11 -0700105 debug("Jumping to %s at %lx\n", spl_phase_name(spl_next_phase()),
106 (ulong)spl_image->entry_point);
107#ifdef DEBUG
108 print_buffer(spl_image->entry_point, (void *)spl_image->entry_point, 1,
109 0x20, 0);
110#endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600111 jump_to_spl(spl_image->entry_point);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600112 hang();
Simon Glass7cf5fe02019-05-02 10:52:12 -0600113}
114
115void spl_board_init(void)
116{
117 preloader_console_init();
118}
Simon Glass7b8a5582019-10-20 21:37:50 -0600119
120#if !CONFIG_IS_ENABLED(PCI)
121/*
122 * This is a fake PCI bus for TPL when it doesn't have proper PCI. It is enough
123 * to bind the devices on the PCI bus, some of which have early-regs properties
124 * providing fixed BARs. Individual drivers program these BARs themselves so
125 * that they can access the devices. The BARs are allocated statically in the
126 * device tree.
127 *
128 * Once SPL is running it enables PCI properly, but does not auto-assign BARs
129 * for devices, so the TPL BARs continue to be used. Once U-Boot starts it does
130 * the auto allocation (after relocation).
131 */
Simon Glass92882652021-08-07 07:24:04 -0600132#if CONFIG_IS_ENABLED(OF_REAL)
Simon Glass7b8a5582019-10-20 21:37:50 -0600133static const struct udevice_id tpl_fake_pci_ids[] = {
134 { .compatible = "pci-x86" },
135 { }
136};
Simon Glasse1bafd52020-12-23 08:11:32 -0700137#endif
Simon Glass7b8a5582019-10-20 21:37:50 -0600138
139U_BOOT_DRIVER(pci_x86) = {
140 .name = "pci_x86",
141 .id = UCLASS_SIMPLE_BUS,
Simon Glasse1bafd52020-12-23 08:11:32 -0700142 .of_match = of_match_ptr(tpl_fake_pci_ids),
Simon Glassf7ffa922021-03-15 17:25:48 +1300143 DM_PHASE(tpl)
Simon Glass7b8a5582019-10-20 21:37:50 -0600144};
145#endif