blob: 7623fc9ada0777d585f25d6e2d2f7842a304b93a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass4bbc0242017-01-16 07:03:56 -07002/*
3 * Copyright (c) 2016 Google, Inc
Simon Glass4bbc0242017-01-16 07:03:56 -07004 */
5
6#include <common.h>
7#include <debug_uart.h>
Simon Glass7c03caf2019-05-02 10:52:12 -06008#include <malloc.h>
Simon Glass4bbc0242017-01-16 07:03:56 -07009#include <spl.h>
10#include <asm/cpu.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060011#include <asm/mrccache.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070012#include <asm/mtrr.h>
13#include <asm/processor.h>
Simon Glassdaade112019-09-25 08:11:39 -060014#include <asm/spl.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070015#include <asm-generic/sections.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
Bin Meng8f60ea02017-01-18 03:32:53 -080019__weak int arch_cpu_init_dm(void)
20{
21 return 0;
22}
23
Simon Glass4bbc0242017-01-16 07:03:56 -070024static int x86_spl_init(void)
25{
Simon Glass7c03caf2019-05-02 10:52:12 -060026#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070027 /*
28 * TODO(sjg@chromium.org): We use this area of RAM for the stack
29 * and global_data in SPL. Once U-Boot starts up and releocates it
30 * is not needed. We could make this a CONFIG option or perhaps
31 * place it immediately below CONFIG_SYS_TEXT_BASE.
32 */
33 char *ptr = (char *)0x110000;
Simon Glass7c03caf2019-05-02 10:52:12 -060034#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070035 int ret;
36
37 debug("%s starting\n", __func__);
38 ret = spl_init();
39 if (ret) {
40 debug("%s: spl_init() failed\n", __func__);
41 return ret;
42 }
Simon Glass4bbc0242017-01-16 07:03:56 -070043 ret = arch_cpu_init();
44 if (ret) {
45 debug("%s: arch_cpu_init() failed\n", __func__);
46 return ret;
47 }
Simon Glass7c03caf2019-05-02 10:52:12 -060048#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070049 ret = arch_cpu_init_dm();
50 if (ret) {
51 debug("%s: arch_cpu_init_dm() failed\n", __func__);
52 return ret;
53 }
Simon Glass7c03caf2019-05-02 10:52:12 -060054#endif
Simon Glass3ff09002017-03-19 12:59:21 -060055 preloader_console_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060056#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070057 ret = print_cpuinfo();
58 if (ret) {
59 debug("%s: print_cpuinfo() failed\n", __func__);
60 return ret;
61 }
Simon Glass7c03caf2019-05-02 10:52:12 -060062#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070063 ret = dram_init();
64 if (ret) {
65 debug("%s: dram_init() failed\n", __func__);
66 return ret;
67 }
Simon Glass7c03caf2019-05-02 10:52:12 -060068 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
69 ret = mrccache_spl_save();
70 if (ret)
71 debug("%s: Failed to write to mrccache (err=%d)\n",
72 __func__, ret);
73 }
74
75#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070076 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
77
78 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
79 ret = interrupt_init();
80 if (ret) {
81 debug("%s: interrupt_init() failed\n", __func__);
82 return ret;
83 }
84
85 /*
86 * The stack grows down from ptr. Put the global data at ptr. This
87 * will only be used for SPL. Once SPL loads U-Boot proper it will
88 * set up its own stack.
89 */
90 gd->new_gd = (struct global_data *)ptr;
91 memcpy(gd->new_gd, gd, sizeof(*gd));
92 arch_setup_gd(gd->new_gd);
93 gd->start_addr_sp = (ulong)ptr;
94
95 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
96 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
97 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
98 CONFIG_XIP_ROM_SIZE);
99 if (ret) {
Simon Glass7c03caf2019-05-02 10:52:12 -0600100 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass4bbc0242017-01-16 07:03:56 -0700101 return ret;
102 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600103 mtrr_commit(true);
104#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700105
106 return 0;
107}
108
109void board_init_f(ulong flags)
110{
111 int ret;
112
113 ret = x86_spl_init();
114 if (ret) {
115 debug("Error %d\n", ret);
Simon Glass3d956882019-09-25 08:56:51 -0600116 panic("x86_spl_init fail");
Simon Glass4bbc0242017-01-16 07:03:56 -0700117 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600118#ifdef CONFIG_TPL
119 gd->bd = malloc(sizeof(*gd->bd));
120 if (!gd->bd) {
121 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
122 hang();
123 }
124 board_init_r(gd, 0);
125#else
Simon Glass4bbc0242017-01-16 07:03:56 -0700126 /* Uninit CAR and jump to board_init_f_r() */
127 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7c03caf2019-05-02 10:52:12 -0600128#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700129}
130
131void board_init_f_r(void)
132{
133 init_cache_f_r();
134 gd->flags &= ~GD_FLG_SERIAL_READY;
135 debug("cache status %d\n", dcache_status());
136 board_init_r(gd, 0);
137}
138
139u32 spl_boot_device(void)
140{
Simon Glassdaade112019-09-25 08:11:39 -0600141 return BOOT_DEVICE_SPI_MMAP;
Simon Glass4bbc0242017-01-16 07:03:56 -0700142}
143
144int spl_start_uboot(void)
145{
146 return 0;
147}
148
149void spl_board_announce_boot_device(void)
150{
151 printf("SPI flash");
152}
153
154static int spl_board_load_image(struct spl_image_info *spl_image,
155 struct spl_boot_device *bootdev)
156{
157 spl_image->size = CONFIG_SYS_MONITOR_LEN;
158 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
159 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
160 spl_image->os = IH_OS_U_BOOT;
161 spl_image->name = "U-Boot";
162
163 debug("Loading to %lx\n", spl_image->load_addr);
164
165 return 0;
166}
Simon Glassdaade112019-09-25 08:11:39 -0600167SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass4bbc0242017-01-16 07:03:56 -0700168
169int spl_spi_load_image(void)
170{
171 return -EPERM;
172}
173
Simon Glass7c03caf2019-05-02 10:52:12 -0600174#ifdef CONFIG_X86_RUN_64BIT
Simon Glass4bbc0242017-01-16 07:03:56 -0700175void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
176{
177 int ret;
178
179 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
180 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
181 debug("ret=%d\n", ret);
Simon Glass14dd93b2019-09-25 08:11:38 -0600182 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700183}
Simon Glass7c03caf2019-05-02 10:52:12 -0600184#endif
185
186void spl_board_init(void)
187{
188#ifndef CONFIG_TPL
189 preloader_console_init();
190#endif
191}