1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 Google, Inc
7 #include <debug_uart.h>
11 #include <asm/mrccache.h>
13 #include <asm/processor.h>
14 #include <asm-generic/sections.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 __weak int arch_cpu_init_dm(void)
23 static int x86_spl_init(void)
27 * TODO(sjg@chromium.org): We use this area of RAM for the stack
28 * and global_data in SPL. Once U-Boot starts up and releocates it
29 * is not needed. We could make this a CONFIG option or perhaps
30 * place it immediately below CONFIG_SYS_TEXT_BASE.
32 char *ptr = (char *)0x110000;
36 debug("%s starting\n", __func__);
39 debug("%s: spl_init() failed\n", __func__);
43 /* Do a mini-init if TPL has already done the full init */
44 ret = x86_cpu_reinit_f();
46 ret = arch_cpu_init();
49 debug("%s: arch_cpu_init() failed\n", __func__);
53 ret = arch_cpu_init_dm();
55 debug("%s: arch_cpu_init_dm() failed\n", __func__);
59 preloader_console_init();
61 ret = print_cpuinfo();
63 debug("%s: print_cpuinfo() failed\n", __func__);
69 debug("%s: dram_init() failed\n", __func__);
72 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
73 ret = mrccache_spl_save();
75 debug("%s: Failed to write to mrccache (err=%d)\n",
80 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
82 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
83 ret = interrupt_init();
85 debug("%s: interrupt_init() failed\n", __func__);
90 * The stack grows down from ptr. Put the global data at ptr. This
91 * will only be used for SPL. Once SPL loads U-Boot proper it will
92 * set up its own stack.
94 gd->new_gd = (struct global_data *)ptr;
95 memcpy(gd->new_gd, gd, sizeof(*gd));
96 arch_setup_gd(gd->new_gd);
97 gd->start_addr_sp = (ulong)ptr;
99 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
100 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
101 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
102 CONFIG_XIP_ROM_SIZE);
104 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
113 void board_init_f(ulong flags)
117 ret = x86_spl_init();
119 debug("Error %d\n", ret);
123 gd->bd = malloc(sizeof(*gd->bd));
125 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
130 /* Uninit CAR and jump to board_init_f_r() */
131 board_init_f_r_trampoline(gd->start_addr_sp);
135 void board_init_f_r(void)
138 gd->flags &= ~GD_FLG_SERIAL_READY;
139 debug("cache status %d\n", dcache_status());
143 u32 spl_boot_device(void)
145 return BOOT_DEVICE_BOARD;
148 int spl_start_uboot(void)
153 void spl_board_announce_boot_device(void)
158 static int spl_board_load_image(struct spl_image_info *spl_image,
159 struct spl_boot_device *bootdev)
161 spl_image->size = CONFIG_SYS_MONITOR_LEN;
162 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
163 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
164 spl_image->os = IH_OS_U_BOOT;
165 spl_image->name = "U-Boot";
167 debug("Loading to %lx\n", spl_image->load_addr);
171 SPL_LOAD_IMAGE_METHOD("SPI", 0, BOOT_DEVICE_BOARD, spl_board_load_image);
173 int spl_spi_load_image(void)
178 #ifdef CONFIG_X86_RUN_64BIT
179 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
183 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
184 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
185 debug("ret=%d\n", ret);
191 void spl_board_init(void)
194 preloader_console_init();