blob: 0bdce64ca583731c3ede6dc6c45ee75ebab4e0f7 [file] [log] [blame]
Simon Glass1938f4a2013-03-11 06:49:53 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glass1938f4a2013-03-11 06:49:53 +000011 */
12
13#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000015#include <environment.h>
Simon Glassab7cd622014-07-23 06:55:04 -060016#include <dm.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000017#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000018#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000019#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000020#include <initcall.h>
Simon Glass96d4b752017-03-31 08:40:37 -060021#include <init_helpers.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070022#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050023#include <mapmem.h>
Simon Glassa733b062013-04-26 02:53:43 +000024#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000025#include <post.h>
Simon Glasse47b2d62017-03-31 08:40:38 -060026#include <relocate.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000027#include <spi.h>
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020028#include <status_led.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070029#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070030#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070031#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000032#include <watchdog.h>
Simon Glassb885d022017-05-17 08:23:01 -060033#ifdef CONFIG_MACH_TYPE
34#include <asm/mach-types.h>
35#endif
Simon Glass1fbf97d2017-03-31 08:40:39 -060036#if defined(CONFIG_MP) && defined(CONFIG_PPC)
37#include <asm/mp.h>
38#endif
Simon Glass1938f4a2013-03-11 06:49:53 +000039#include <asm/io.h>
40#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060041#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060042#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000043
44/*
45 * Pointer to initial global data area
46 *
47 * Here we initialize it if needed.
48 */
49#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
50#undef XTRN_DECLARE_GLOBAL_DATA_PTR
51#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
52DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
53#else
54DECLARE_GLOBAL_DATA_PTR;
55#endif
56
57/*
Simon Glass4c509342015-04-28 20:25:03 -060058 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000059 * refactored to a single function, something like:
60 *
61 * void led_set_state(enum led_colour_t colour, int on);
62 */
63/************************************************************************
64 * Coloured LED functionality
65 ************************************************************************
66 * May be supplied by boards if desired
67 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020068__weak void coloured_LED_init(void) {}
69__weak void red_led_on(void) {}
70__weak void red_led_off(void) {}
71__weak void green_led_on(void) {}
72__weak void green_led_off(void) {}
73__weak void yellow_led_on(void) {}
74__weak void yellow_led_off(void) {}
75__weak void blue_led_on(void) {}
76__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000077
78/*
79 * Why is gd allocated a register? Prior to reloc it might be better to
80 * just pass it around to each function in this file?
81 *
82 * After reloc one could argue that it is hardly used and doesn't need
83 * to be in a register. Or if it is it should perhaps hold pointers to all
84 * global data for all modules, so that post-reloc we can avoid the massive
85 * literal pool we get on ARM. Or perhaps just encourage each module to use
86 * a structure...
87 */
88
Sonic Zhangd54d7eb2014-07-17 19:01:34 +080089#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +000090static int init_func_watchdog_init(void)
91{
Tom Riniea3310e2017-03-14 11:08:10 -040092# if defined(CONFIG_HW_WATCHDOG) && \
93 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +010094 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +020095 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +010096 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +080097 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +000098 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +020099# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000100 WATCHDOG_RESET();
101
102 return 0;
103}
104
105int init_func_watchdog_reset(void)
106{
107 WATCHDOG_RESET();
108
109 return 0;
110}
111#endif /* CONFIG_WATCHDOG */
112
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200113__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000114{
115 /* please define platform specific board_add_ram_info() */
116}
117
Simon Glass1938f4a2013-03-11 06:49:53 +0000118static int init_baud_rate(void)
119{
Simon Glassbfebc8c2017-08-03 12:22:13 -0600120 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glass1938f4a2013-03-11 06:49:53 +0000121 return 0;
122}
123
124static int display_text_info(void)
125{
Ben Stoltz9b217492015-07-31 09:31:37 -0600126#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100127 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000128
Simon Glass632efa72013-03-11 07:06:48 +0000129 bss_start = (ulong)&__bss_start;
130 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100131
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800132#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100133 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800134#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100135 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800136#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100137
138 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
139 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000140#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000141
Simon Glass1938f4a2013-03-11 06:49:53 +0000142 return 0;
143}
144
145static int announce_dram_init(void)
146{
147 puts("DRAM: ");
148 return 0;
149}
150
151static int show_dram_config(void)
152{
York Sunfa39ffe2014-05-02 17:28:05 -0700153 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000154
155#ifdef CONFIG_NR_DRAM_BANKS
156 int i;
157
158 debug("\nRAM Configuration:\n");
159 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
160 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700161 debug("Bank #%d: %llx ", i,
162 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000163#ifdef DEBUG
164 print_size(gd->bd->bi_dram[i].size, "\n");
165#endif
166 }
167 debug("\nDRAM: ");
168#else
169 size = gd->ram_size;
170#endif
171
Simon Glasse4fef6c2013-03-11 14:30:42 +0000172 print_size(size, "");
173 board_add_ram_info(0);
174 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000175
176 return 0;
177}
178
Simon Glass76b00ac2017-03-31 08:40:32 -0600179__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000180{
181#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
182 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
183 gd->bd->bi_dram[0].size = get_effective_memsize();
184#endif
Simon Glass76b00ac2017-03-31 08:40:32 -0600185
186 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000187}
188
Simon Glass69153982017-05-12 21:09:56 -0600189#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000190static int init_func_i2c(void)
191{
192 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200193#ifdef CONFIG_SYS_I2C
194 i2c_init_all();
195#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000196 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200197#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000198 puts("ready\n");
199 return 0;
200}
201#endif
202
203#if defined(CONFIG_HARD_SPI)
204static int init_func_spi(void)
205{
206 puts("SPI: ");
207 spi_init();
208 puts("ready\n");
209 return 0;
210}
211#endif
212
Simon Glass1938f4a2013-03-11 06:49:53 +0000213static int setup_mon_len(void)
214{
Michal Simeke945f6d2014-05-08 16:08:44 +0200215#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100216 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600217#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000218 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400219#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800220 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Rick Chen068feb92017-12-26 13:55:58 +0800221#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800222 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600223#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000224 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
225 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000226#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000227 return 0;
228}
229
230__weak int arch_cpu_init(void)
231{
232 return 0;
233}
234
Paul Burton8ebf5062016-09-21 11:18:46 +0100235__weak int mach_cpu_init(void)
236{
237 return 0;
238}
239
Simon Glass1938f4a2013-03-11 06:49:53 +0000240/* Get the top of usable RAM */
241__weak ulong board_get_usable_ram_top(ulong total_size)
242{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700243#ifdef CONFIG_SYS_SDRAM_BASE
244 /*
Simon Glass4c509342015-04-28 20:25:03 -0600245 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700246 * 32-bit address space. If so, clip the usable RAM so it doesn't.
247 */
248 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
249 /*
250 * Will wrap back to top of 32-bit space when reservations
251 * are made.
252 */
253 return 0;
254#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000255 return gd->ram_top;
256}
257
258static int setup_dest_addr(void)
259{
260 debug("Monitor len: %08lX\n", gd->mon_len);
261 /*
262 * Ram is setup, size stored in gd !!
263 */
264 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800265#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000266 /*
267 * Subtract specified amount of memory to hide so that it won't
268 * get "touched" at all by U-Boot. By fixing up gd->ram_size
269 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800270 * memory size and won't touch it either. This should work
271 * for arch/ppc and arch/powerpc. Only Linux board ports in
272 * arch/powerpc with bootwrapper support, that recalculate the
273 * memory size from the SDRAM controller setup will have to
274 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000275 */
York Sun36cc0de2017-03-06 09:02:28 -0800276 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
277#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000278#ifdef CONFIG_SYS_SDRAM_BASE
279 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
280#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000281 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000282 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000283 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000284 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700285#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000286 /*
287 * We need to make sure the location we intend to put secondary core
288 * boot code is reserved and not used by any part of u-boot
289 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000290 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
291 gd->relocaddr = determine_mp_bootpg(NULL);
292 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000293 }
294#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000295 return 0;
296}
297
Simon Glass1938f4a2013-03-11 06:49:53 +0000298#ifdef CONFIG_PRAM
299/* reserve protected RAM */
300static int reserve_pram(void)
301{
302 ulong reg;
303
Simon Glassbfebc8c2017-08-03 12:22:13 -0600304 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000305 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000306 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000307 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000308 return 0;
309}
310#endif /* CONFIG_PRAM */
311
312/* Round memory pointer down to next 4 kB limit */
313static int reserve_round_4k(void)
314{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000315 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000316 return 0;
317}
318
Simon Glass80d4bcd2017-03-31 08:40:29 -0600319#ifdef CONFIG_ARM
Siva Durga Prasad Paladugu60873f72017-07-13 19:01:08 +0530320__weak int reserve_mmu(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000321{
Simon Glass80d4bcd2017-03-31 08:40:29 -0600322#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000323 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800324 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000325 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000326
327 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000328 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000329
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000330 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000331 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
332 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700333
334#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
335 /*
336 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
337 * with location within secure ram.
338 */
339 gd->arch.tlb_allocated = gd->arch.tlb_addr;
340#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600341#endif
York Sun50e93b92016-06-24 16:46:19 -0700342
Simon Glass1938f4a2013-03-11 06:49:53 +0000343 return 0;
344}
345#endif
346
Simon Glass5a541942016-01-18 19:52:21 -0700347static int reserve_video(void)
348{
Simon Glass0f079eb2017-03-31 08:40:30 -0600349#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700350 ulong addr;
351 int ret;
352
353 addr = gd->relocaddr;
354 ret = video_reserve(&addr);
355 if (ret)
356 return ret;
357 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600358#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700359# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700361# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000362 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000363 gd->relocaddr = lcd_setmem(gd->relocaddr);
364 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700365# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600366#elif defined(CONFIG_VIDEO) && \
Heiko Schocher5b8e76c2017-06-07 17:33:09 +0200367 (!defined(CONFIG_PPC)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700368 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Riniea3310e2017-03-14 11:08:10 -0400369 !defined(CONFIG_M68K)
Simon Glass8703ef32016-01-18 19:52:20 -0700370 /* reserve memory for video display (always full pages) */
371 gd->relocaddr = video_setmem(gd->relocaddr);
372 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600373#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700374
375 return 0;
376}
Simon Glass8703ef32016-01-18 19:52:20 -0700377
Simon Glass71c52db2013-06-11 11:14:42 -0700378static int reserve_trace(void)
379{
380#ifdef CONFIG_TRACE
381 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
382 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
383 debug("Reserving %dk for trace data at: %08lx\n",
384 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
385#endif
386
387 return 0;
388}
389
Simon Glass1938f4a2013-03-11 06:49:53 +0000390static int reserve_uboot(void)
391{
392 /*
393 * reserve memory for U-Boot code, data & bss
394 * round down to next 4 kB limit
395 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000396 gd->relocaddr -= gd->mon_len;
397 gd->relocaddr &= ~(4096 - 1);
Paul Burton703ec9d2017-06-19 11:53:47 -0700398#if defined(CONFIG_E500) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000399 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000400 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000401#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000402
403 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000404 gd->relocaddr);
405
406 gd->start_addr_sp = gd->relocaddr;
407
Simon Glass1938f4a2013-03-11 06:49:53 +0000408 return 0;
409}
410
411/* reserve memory for malloc() area */
412static int reserve_malloc(void)
413{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000414 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000415 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000416 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000417 return 0;
418}
419
420/* (permanently) allocate a Board Info struct */
421static int reserve_board(void)
422{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800423 if (!gd->bd) {
424 gd->start_addr_sp -= sizeof(bd_t);
425 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
426 memset(gd->bd, '\0', sizeof(bd_t));
427 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
428 sizeof(bd_t), gd->start_addr_sp);
429 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000430 return 0;
431}
432
433static int setup_machine(void)
434{
435#ifdef CONFIG_MACH_TYPE
436 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
437#endif
438 return 0;
439}
440
441static int reserve_global_data(void)
442{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000443 gd->start_addr_sp -= sizeof(gd_t);
444 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000445 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000446 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000447 return 0;
448}
449
450static int reserve_fdt(void)
451{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100452#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000453 /*
Simon Glass4c509342015-04-28 20:25:03 -0600454 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000455 * must relocate it. If it is embedded in the data section, then it
456 * will be relocated with other data.
457 */
458 if (gd->fdt_blob) {
459 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
460
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000461 gd->start_addr_sp -= gd->fdt_size;
462 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000463 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000464 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000465 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100466#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000467
468 return 0;
469}
470
Simon Glass25e7dc62017-05-22 05:05:30 -0600471static int reserve_bootstage(void)
472{
473#ifdef CONFIG_BOOTSTAGE
474 int size = bootstage_get_size();
475
476 gd->start_addr_sp -= size;
477 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
478 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
479 gd->start_addr_sp);
480#endif
481
482 return 0;
483}
484
Andreas Bießmann68145d42015-02-06 23:06:45 +0100485int arch_reserve_stacks(void)
486{
487 return 0;
488}
489
Simon Glass1938f4a2013-03-11 06:49:53 +0000490static int reserve_stacks(void)
491{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100492 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000493 gd->start_addr_sp -= 16;
494 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000495
496 /*
Simon Glass4c509342015-04-28 20:25:03 -0600497 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100498 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000499 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100500 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000501}
502
503static int display_new_sp(void)
504{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000505 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000506
507 return 0;
508}
509
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200510#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
511 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000512static int setup_board_part1(void)
513{
514 bd_t *bd = gd->bd;
515
516 /*
517 * Save local variables to board info struct
518 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000519 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
520 bd->bi_memsize = gd->ram_size; /* size in bytes */
521
522#ifdef CONFIG_SYS_SRAM_BASE
523 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
524 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
525#endif
526
Heiko Schocher50258972017-06-07 17:33:11 +0200527#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000528 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
529#endif
Heiko Schocher064b55c2017-06-14 05:49:40 +0200530#if defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000531 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
532#endif
533#if defined(CONFIG_MPC83xx)
534 bd->bi_immrbar = CONFIG_SYS_IMMR;
535#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000536
537 return 0;
538}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100539#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000540
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100541#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000542static int setup_board_part2(void)
543{
544 bd_t *bd = gd->bd;
545
546 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
547 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
548#if defined(CONFIG_CPM2)
549 bd->bi_cpmfreq = gd->arch.cpm_clk;
550 bd->bi_brgfreq = gd->arch.brg_clk;
551 bd->bi_sccfreq = gd->arch.scc_clk;
552 bd->bi_vco = gd->arch.vco_out;
553#endif /* CONFIG_CPM2 */
Alison Wang1313db42015-02-12 18:33:15 +0800554#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
555 bd->bi_pcifreq = gd->pci_clk;
556#endif
557#if defined(CONFIG_EXTRA_CLOCK)
558 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
559 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
560 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
561#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000562
563 return 0;
564}
565#endif
566
Simon Glass1938f4a2013-03-11 06:49:53 +0000567#ifdef CONFIG_POST
568static int init_post(void)
569{
570 post_bootmode_init();
571 post_run(NULL, POST_ROM | post_bootmode_get(0));
572
573 return 0;
574}
575#endif
576
Simon Glass1938f4a2013-03-11 06:49:53 +0000577static int reloc_fdt(void)
578{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100579#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600580 if (gd->flags & GD_FLG_SKIP_RELOC)
581 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000582 if (gd->new_fdt) {
583 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
584 gd->fdt_blob = gd->new_fdt;
585 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100586#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000587
588 return 0;
589}
590
Simon Glass25e7dc62017-05-22 05:05:30 -0600591static int reloc_bootstage(void)
592{
593#ifdef CONFIG_BOOTSTAGE
594 if (gd->flags & GD_FLG_SKIP_RELOC)
595 return 0;
596 if (gd->new_bootstage) {
597 int size = bootstage_get_size();
598
599 debug("Copying bootstage from %p to %p, size %x\n",
600 gd->bootstage, gd->new_bootstage, size);
601 memcpy(gd->new_bootstage, gd->bootstage, size);
602 gd->bootstage = gd->new_bootstage;
603 }
604#endif
605
606 return 0;
607}
608
Simon Glass1938f4a2013-03-11 06:49:53 +0000609static int setup_reloc(void)
610{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600611 if (gd->flags & GD_FLG_SKIP_RELOC) {
612 debug("Skipping relocation due to flag\n");
613 return 0;
614 }
615
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800616#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200617#ifdef ARM
618 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
619#elif defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100620 /*
621 * On all ColdFire arch cpu, monitor code starts always
622 * just after the default vector table location, so at 0x400
623 */
624 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200625#else
626 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100627#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800628#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000629 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
630
631 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000632 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000633 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
634 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000635
636 return 0;
637}
638
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100639#ifdef CONFIG_OF_BOARD_FIXUP
640static int fix_fdt(void)
641{
642 return board_fix_fdt((void *)gd->fdt_blob);
643}
644#endif
645
Simon Glass1938f4a2013-03-11 06:49:53 +0000646/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700647#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
648 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000649
650static int jump_to_copy(void)
651{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600652 if (gd->flags & GD_FLG_SKIP_RELOC)
653 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000654 /*
655 * x86 is special, but in a nice way. It uses a trampoline which
656 * enables the dcache if possible.
657 *
658 * For now, other archs use relocate_code(), which is implemented
659 * similarly for all archs. When we do generic relocation, hopefully
660 * we can make all archs enable the dcache prior to relocation.
661 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300662#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000663 /*
664 * SDRAM and console are now initialised. The final stack can now
665 * be setup in SDRAM. Code execution will continue in Flash, but
666 * with the stack in SDRAM and Global Data in temporary memory
667 * (CPU cache)
668 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600669 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000670 board_init_f_r_trampoline(gd->start_addr_sp);
671#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000672 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000673#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000674
675 return 0;
676}
677#endif
678
679/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glassb383d6c2017-05-22 05:05:25 -0600680static int initf_bootstage(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000681{
Simon Glassbaa7d342017-06-07 10:28:46 -0600682 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
683 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glassb383d6c2017-05-22 05:05:25 -0600684 int ret;
685
Simon Glass824bb1b2017-05-22 05:05:35 -0600686 ret = bootstage_init(!from_spl);
Simon Glassb383d6c2017-05-22 05:05:25 -0600687 if (ret)
688 return ret;
Simon Glass824bb1b2017-05-22 05:05:35 -0600689 if (from_spl) {
690 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
691 CONFIG_BOOTSTAGE_STASH_SIZE);
692
693 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
694 if (ret && ret != -ENOENT) {
695 debug("Failed to unstash bootstage: err=%d\n", ret);
696 return ret;
697 }
698 }
Simon Glassb383d6c2017-05-22 05:05:25 -0600699
Simon Glass1938f4a2013-03-11 06:49:53 +0000700 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
701
702 return 0;
703}
704
Simon Glass9854a872015-11-08 23:47:48 -0700705static int initf_console_record(void)
706{
Andy Yanf1896c42017-07-24 17:43:34 +0800707#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glass9854a872015-11-08 23:47:48 -0700708 return console_record_init();
709#else
710 return 0;
711#endif
712}
713
Simon Glassab7cd622014-07-23 06:55:04 -0600714static int initf_dm(void)
715{
Andy Yanf1896c42017-07-24 17:43:34 +0800716#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassab7cd622014-07-23 06:55:04 -0600717 int ret;
718
Simon Glass63c5bf42017-05-22 05:05:32 -0600719 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
Simon Glassab7cd622014-07-23 06:55:04 -0600720 ret = dm_init_and_scan(true);
Simon Glass63c5bf42017-05-22 05:05:32 -0600721 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
Simon Glassab7cd622014-07-23 06:55:04 -0600722 if (ret)
723 return ret;
724#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700725#ifdef CONFIG_TIMER_EARLY
726 ret = dm_timer_init();
727 if (ret)
728 return ret;
729#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600730
731 return 0;
732}
733
Simon Glass146251f2015-01-19 22:16:12 -0700734/* Architecture-specific memory reservation */
735__weak int reserve_arch(void)
736{
737 return 0;
738}
739
Simon Glassd4c671c2015-03-05 12:25:16 -0700740__weak int arch_cpu_init_dm(void)
741{
742 return 0;
743}
744
Simon Glass4acff452017-01-16 07:03:50 -0700745static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000746 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700747#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700748 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700749#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800750#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700751 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800752#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700753 initf_malloc,
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700754 log_init,
Simon Glass5ac44a52017-05-22 05:05:31 -0600755 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glass9854a872015-11-08 23:47:48 -0700756 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600757#if defined(CONFIG_HAVE_FSP)
758 arch_fsp_init,
Bin Menga52a068e2015-08-20 06:40:18 -0700759#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000760 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100761 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600762 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700763 arch_cpu_init_dm,
Simon Glass1938f4a2013-03-11 06:49:53 +0000764#if defined(CONFIG_BOARD_EARLY_INIT_F)
765 board_early_init_f,
766#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600767#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600768 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000769 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600770#endif
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200771#if !defined(CONFIG_M68K)
Simon Glass1938f4a2013-03-11 06:49:53 +0000772 timer_init, /* initialize timer */
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200773#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000774#if defined(CONFIG_BOARD_POSTCLK_INIT)
775 board_postclk_init,
776#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000777 env_init, /* initialize environment */
778 init_baud_rate, /* initialze baudrate settings */
779 serial_init, /* serial communications setup */
780 console_init_f, /* stage 1 init of console */
781 display_options, /* say that we are here */
782 display_text_info, /* show debugging info if required */
Simon Glass76d1d022017-03-28 10:27:30 -0600783#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
784 defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000785 checkcpu,
786#endif
Simon Glasscc664002017-01-23 13:31:25 -0700787#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000788 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700789#endif
Cooper Jr., Franklinaf9e6ad2017-06-16 17:25:12 -0500790#if defined(CONFIG_DTB_RESELECT)
791 embedded_dtb_select,
792#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000793#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900794 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000795#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000796 INIT_FUNC_WATCHDOG_INIT
797#if defined(CONFIG_MISC_INIT_F)
798 misc_init_f,
799#endif
800 INIT_FUNC_WATCHDOG_RESET
Simon Glass69153982017-05-12 21:09:56 -0600801#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000802 init_func_i2c,
803#endif
804#if defined(CONFIG_HARD_SPI)
805 init_func_spi,
806#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000807 announce_dram_init,
Simon Glass1938f4a2013-03-11 06:49:53 +0000808 dram_init, /* configure available RAM banks */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000809#ifdef CONFIG_POST
810 post_init_f,
811#endif
812 INIT_FUNC_WATCHDOG_RESET
813#if defined(CONFIG_SYS_DRAM_TEST)
814 testdram,
815#endif /* CONFIG_SYS_DRAM_TEST */
816 INIT_FUNC_WATCHDOG_RESET
817
Simon Glass1938f4a2013-03-11 06:49:53 +0000818#ifdef CONFIG_POST
819 init_post,
820#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000821 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000822 /*
823 * Now that we have DRAM mapped and working, we can
824 * relocate the code and continue running from DRAM.
825 *
826 * Reserve memory at end of RAM for (top down in that order):
827 * - area that won't get touched by U-Boot and Linux (optional)
828 * - kernel log buffer
829 * - protected RAM
830 * - LCD framebuffer
831 * - monitor code
832 * - board info struct
833 */
834 setup_dest_addr,
Simon Glass1938f4a2013-03-11 06:49:53 +0000835#ifdef CONFIG_PRAM
836 reserve_pram,
837#endif
838 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600839#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000840 reserve_mmu,
841#endif
Simon Glass5a541942016-01-18 19:52:21 -0700842 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700843 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000844 reserve_uboot,
845 reserve_malloc,
846 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000847 setup_machine,
848 reserve_global_data,
849 reserve_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600850 reserve_bootstage,
Simon Glass146251f2015-01-19 22:16:12 -0700851 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000852 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600853 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000854 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200855#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
856 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000857 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100858#endif
859#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000860 INIT_FUNC_WATCHDOG_RESET
861 setup_board_part2,
862#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000863 display_new_sp,
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100864#ifdef CONFIG_OF_BOARD_FIXUP
865 fix_fdt,
866#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000867 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000868 reloc_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600869 reloc_bootstage,
Simon Glass1938f4a2013-03-11 06:49:53 +0000870 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300871#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700872 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700873 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700874 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700875#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300876#if defined(CONFIG_XTENSA)
877 clear_bss,
878#endif
Simon Glass530f27e2017-01-16 07:03:49 -0700879#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
880 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000881 jump_to_copy,
882#endif
883 NULL,
884};
885
886void board_init_f(ulong boot_flags)
887{
Simon Glass1938f4a2013-03-11 06:49:53 +0000888 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400889 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000890
891 if (initcall_run_list(init_sequence_f))
892 hang();
893
Ben Stoltz9b217492015-07-31 09:31:37 -0600894#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass530f27e2017-01-16 07:03:49 -0700895 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000896 /* NOTREACHED - jump_to_copy() does not return */
897 hang();
898#endif
899}
900
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300901#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000902/*
903 * For now this code is only used on x86.
904 *
905 * init_sequence_f_r is the list of init functions which are run when
906 * U-Boot is executing from Flash with a semi-limited 'C' environment.
907 * The following limitations must be considered when implementing an
908 * '_f_r' function:
909 * - 'static' variables are read-only
910 * - Global Data (gd->xxx) is read/write
911 *
912 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
913 * supported). It _should_, if possible, copy global data to RAM and
914 * initialise the CPU caches (to speed up the relocation process)
915 *
916 * NOTE: At present only x86 uses this route, but it is intended that
917 * all archs will move to this when generic relocation is implemented.
918 */
Simon Glass4acff452017-01-16 07:03:50 -0700919static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700920#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000921 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700922#endif
Simon Glass48a33802013-03-05 14:39:52 +0000923
924 NULL,
925};
926
927void board_init_f_r(void)
928{
929 if (initcall_run_list(init_sequence_f_r))
930 hang();
931
932 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700933 * The pre-relocation drivers may be using memory that has now gone
934 * away. Mark serial as unavailable - this will fall back to the debug
935 * UART if available.
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700936 *
937 * Do the same with log drivers since the memory may not be available.
Simon Glasse4d6ab02016-03-11 22:06:51 -0700938 */
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700939 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
Simon Glass5ee94b42017-09-05 19:49:45 -0600940#ifdef CONFIG_TIMER
941 gd->timer = NULL;
942#endif
Simon Glasse4d6ab02016-03-11 22:06:51 -0700943
944 /*
Simon Glass48a33802013-03-05 14:39:52 +0000945 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
946 * Transfer execution from Flash to RAM by calculating the address
947 * of the in-RAM copy of board_init_r() and calling it
948 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +0300949 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000950
951 /* NOTREACHED - board_init_r() does not return */
952 hang();
953}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +0300954#endif /* CONFIG_X86 */