blob: 832a5d7c0ea3b997820898061438b692689af914 [file] [log] [blame]
Simon Glass4bbc0242017-01-16 07:03:56 -07001/*
2 * Copyright (c) 2016 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include <common.h>
8#include <debug_uart.h>
Simon Glass96d4b752017-03-31 08:40:37 -06009#include <init_helpers.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070010#include <spl.h>
11#include <asm/cpu.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070012#include <asm/mtrr.h>
13#include <asm/processor.h>
14#include <asm-generic/sections.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Bin Meng8f60ea02017-01-18 03:32:53 -080018__weak int arch_cpu_init_dm(void)
19{
20 return 0;
21}
22
Simon Glass4bbc0242017-01-16 07:03:56 -070023static int x86_spl_init(void)
24{
25 /*
26 * TODO(sjg@chromium.org): We use this area of RAM for the stack
27 * and global_data in SPL. Once U-Boot starts up and releocates it
28 * is not needed. We could make this a CONFIG option or perhaps
29 * place it immediately below CONFIG_SYS_TEXT_BASE.
30 */
31 char *ptr = (char *)0x110000;
32 int ret;
33
34 debug("%s starting\n", __func__);
35 ret = spl_init();
36 if (ret) {
37 debug("%s: spl_init() failed\n", __func__);
38 return ret;
39 }
Simon Glass4bbc0242017-01-16 07:03:56 -070040 ret = arch_cpu_init();
41 if (ret) {
42 debug("%s: arch_cpu_init() failed\n", __func__);
43 return ret;
44 }
45 ret = arch_cpu_init_dm();
46 if (ret) {
47 debug("%s: arch_cpu_init_dm() failed\n", __func__);
48 return ret;
49 }
Simon Glass3ff09002017-03-19 12:59:21 -060050 preloader_console_init();
Simon Glass4bbc0242017-01-16 07:03:56 -070051 ret = print_cpuinfo();
52 if (ret) {
53 debug("%s: print_cpuinfo() failed\n", __func__);
54 return ret;
55 }
56 ret = dram_init();
57 if (ret) {
58 debug("%s: dram_init() failed\n", __func__);
59 return ret;
60 }
61 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
62
63 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
64 ret = interrupt_init();
65 if (ret) {
66 debug("%s: interrupt_init() failed\n", __func__);
67 return ret;
68 }
69
70 /*
71 * The stack grows down from ptr. Put the global data at ptr. This
72 * will only be used for SPL. Once SPL loads U-Boot proper it will
73 * set up its own stack.
74 */
75 gd->new_gd = (struct global_data *)ptr;
76 memcpy(gd->new_gd, gd, sizeof(*gd));
77 arch_setup_gd(gd->new_gd);
78 gd->start_addr_sp = (ulong)ptr;
79
80 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
81 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
82 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
83 CONFIG_XIP_ROM_SIZE);
84 if (ret) {
85 debug("%s: SPI cache setup failed\n", __func__);
86 return ret;
87 }
88
89 return 0;
90}
91
92void board_init_f(ulong flags)
93{
94 int ret;
95
96 ret = x86_spl_init();
97 if (ret) {
98 debug("Error %d\n", ret);
99 hang();
100 }
101
102 /* Uninit CAR and jump to board_init_f_r() */
103 board_init_f_r_trampoline(gd->start_addr_sp);
104}
105
106void board_init_f_r(void)
107{
108 init_cache_f_r();
109 gd->flags &= ~GD_FLG_SERIAL_READY;
110 debug("cache status %d\n", dcache_status());
111 board_init_r(gd, 0);
112}
113
114u32 spl_boot_device(void)
115{
116 return BOOT_DEVICE_BOARD;
117}
118
119int spl_start_uboot(void)
120{
121 return 0;
122}
123
124void spl_board_announce_boot_device(void)
125{
126 printf("SPI flash");
127}
128
129static int spl_board_load_image(struct spl_image_info *spl_image,
130 struct spl_boot_device *bootdev)
131{
132 spl_image->size = CONFIG_SYS_MONITOR_LEN;
133 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
134 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
135 spl_image->os = IH_OS_U_BOOT;
136 spl_image->name = "U-Boot";
137
138 debug("Loading to %lx\n", spl_image->load_addr);
139
140 return 0;
141}
142SPL_LOAD_IMAGE_METHOD("SPI", 0, BOOT_DEVICE_BOARD, spl_board_load_image);
143
144int spl_spi_load_image(void)
145{
146 return -EPERM;
147}
148
149void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
150{
151 int ret;
152
153 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
154 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
155 debug("ret=%d\n", ret);
156 while (1)
157 ;
158}