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>
15 #include <asm-generic/sections.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 __weak int arch_cpu_init_dm(void)
24 static int x86_spl_init(void)
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.
33 char *ptr = (char *)0x110000;
37 debug("%s starting\n", __func__);
40 debug("%s: spl_init() failed\n", __func__);
43 ret = arch_cpu_init();
45 debug("%s: arch_cpu_init() failed\n", __func__);
49 ret = arch_cpu_init_dm();
51 debug("%s: arch_cpu_init_dm() failed\n", __func__);
55 preloader_console_init();
57 ret = print_cpuinfo();
59 debug("%s: print_cpuinfo() failed\n", __func__);
65 debug("%s: dram_init() failed\n", __func__);
68 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
69 ret = mrccache_spl_save();
71 debug("%s: Failed to write to mrccache (err=%d)\n",
76 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
78 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
79 ret = interrupt_init();
81 debug("%s: interrupt_init() failed\n", __func__);
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.
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;
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,
100 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
109 void board_init_f(ulong flags)
113 ret = x86_spl_init();
115 debug("Error %d\n", ret);
116 panic("x86_spl_init fail");
119 gd->bd = malloc(sizeof(*gd->bd));
121 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
126 /* Uninit CAR and jump to board_init_f_r() */
127 board_init_f_r_trampoline(gd->start_addr_sp);
131 void board_init_f_r(void)
134 gd->flags &= ~GD_FLG_SERIAL_READY;
135 debug("cache status %d\n", dcache_status());
139 u32 spl_boot_device(void)
141 return BOOT_DEVICE_SPI_MMAP;
144 int spl_start_uboot(void)
149 void spl_board_announce_boot_device(void)
154 static int spl_board_load_image(struct spl_image_info *spl_image,
155 struct spl_boot_device *bootdev)
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";
163 debug("Loading to %lx\n", spl_image->load_addr);
167 SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
169 int spl_spi_load_image(void)
174 #ifdef CONFIG_X86_RUN_64BIT
175 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
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);
186 void spl_board_init(void)
189 preloader_console_init();