blob: a73949130354f7fe580f6f09de130e3a629ddc9d [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 Glass7c03caf2019-05-02 10:52:12 -060043#ifdef CONFIG_TPL
44 /* Do a mini-init if TPL has already done the full init */
45 ret = x86_cpu_reinit_f();
46#else
Simon Glass4bbc0242017-01-16 07:03:56 -070047 ret = arch_cpu_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060048#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070049 if (ret) {
50 debug("%s: arch_cpu_init() failed\n", __func__);
51 return ret;
52 }
Simon Glass7c03caf2019-05-02 10:52:12 -060053#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070054 ret = arch_cpu_init_dm();
55 if (ret) {
56 debug("%s: arch_cpu_init_dm() failed\n", __func__);
57 return ret;
58 }
Simon Glass7c03caf2019-05-02 10:52:12 -060059#endif
Simon Glass3ff09002017-03-19 12:59:21 -060060 preloader_console_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060061#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070062 ret = print_cpuinfo();
63 if (ret) {
64 debug("%s: print_cpuinfo() failed\n", __func__);
65 return ret;
66 }
Simon Glass7c03caf2019-05-02 10:52:12 -060067#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070068 ret = dram_init();
69 if (ret) {
70 debug("%s: dram_init() failed\n", __func__);
71 return ret;
72 }
Simon Glass7c03caf2019-05-02 10:52:12 -060073 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
74 ret = mrccache_spl_save();
75 if (ret)
76 debug("%s: Failed to write to mrccache (err=%d)\n",
77 __func__, ret);
78 }
79
80#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070081 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
82
83 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
84 ret = interrupt_init();
85 if (ret) {
86 debug("%s: interrupt_init() failed\n", __func__);
87 return ret;
88 }
89
90 /*
91 * The stack grows down from ptr. Put the global data at ptr. This
92 * will only be used for SPL. Once SPL loads U-Boot proper it will
93 * set up its own stack.
94 */
95 gd->new_gd = (struct global_data *)ptr;
96 memcpy(gd->new_gd, gd, sizeof(*gd));
97 arch_setup_gd(gd->new_gd);
98 gd->start_addr_sp = (ulong)ptr;
99
100 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
101 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
102 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
103 CONFIG_XIP_ROM_SIZE);
104 if (ret) {
Simon Glass7c03caf2019-05-02 10:52:12 -0600105 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass4bbc0242017-01-16 07:03:56 -0700106 return ret;
107 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600108 mtrr_commit(true);
109#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700110
111 return 0;
112}
113
114void board_init_f(ulong flags)
115{
116 int ret;
117
118 ret = x86_spl_init();
119 if (ret) {
120 debug("Error %d\n", ret);
121 hang();
122 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600123#ifdef CONFIG_TPL
124 gd->bd = malloc(sizeof(*gd->bd));
125 if (!gd->bd) {
126 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
127 hang();
128 }
129 board_init_r(gd, 0);
130#else
Simon Glass4bbc0242017-01-16 07:03:56 -0700131 /* Uninit CAR and jump to board_init_f_r() */
132 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7c03caf2019-05-02 10:52:12 -0600133#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700134}
135
136void board_init_f_r(void)
137{
138 init_cache_f_r();
139 gd->flags &= ~GD_FLG_SERIAL_READY;
140 debug("cache status %d\n", dcache_status());
141 board_init_r(gd, 0);
142}
143
144u32 spl_boot_device(void)
145{
Simon Glassdaade112019-09-25 08:11:39 -0600146 return BOOT_DEVICE_SPI_MMAP;
Simon Glass4bbc0242017-01-16 07:03:56 -0700147}
148
149int spl_start_uboot(void)
150{
151 return 0;
152}
153
154void spl_board_announce_boot_device(void)
155{
156 printf("SPI flash");
157}
158
159static int spl_board_load_image(struct spl_image_info *spl_image,
160 struct spl_boot_device *bootdev)
161{
162 spl_image->size = CONFIG_SYS_MONITOR_LEN;
163 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
164 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
165 spl_image->os = IH_OS_U_BOOT;
166 spl_image->name = "U-Boot";
167
168 debug("Loading to %lx\n", spl_image->load_addr);
169
170 return 0;
171}
Simon Glassdaade112019-09-25 08:11:39 -0600172SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass4bbc0242017-01-16 07:03:56 -0700173
174int spl_spi_load_image(void)
175{
176 return -EPERM;
177}
178
Simon Glass7c03caf2019-05-02 10:52:12 -0600179#ifdef CONFIG_X86_RUN_64BIT
Simon Glass4bbc0242017-01-16 07:03:56 -0700180void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
181{
182 int ret;
183
184 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
185 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
186 debug("ret=%d\n", ret);
Simon Glass14dd93b2019-09-25 08:11:38 -0600187 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700188}
Simon Glass7c03caf2019-05-02 10:52:12 -0600189#endif
190
191void spl_board_init(void)
192{
193#ifndef CONFIG_TPL
194 preloader_console_init();
195#endif
196}