blob: 9220815441e51f58d34eac914c570a84da206bd1 [file] [log] [blame]
Simon Glassc45e3592013-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 Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glassc45e3592013-03-11 06:49:53 +000011 */
12
13#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070014#include <console.h>
Simon Glassc45e3592013-03-11 06:49:53 +000015#include <environment.h>
Simon Glassa730c5d2014-07-23 06:55:04 -060016#include <dm.h>
Simon Glassc45e3592013-03-11 06:49:53 +000017#include <fdtdec.h>
Simon Glass15393432013-04-20 08:42:41 +000018#include <fs.h>
Simon Glass50250b52013-03-11 14:30:42 +000019#include <i2c.h>
Simon Glassc45e3592013-03-11 06:49:53 +000020#include <initcall.h>
Simon Glass6bbf83f2017-03-31 08:40:37 -060021#include <init_helpers.h>
Simon Glassc45e3592013-03-11 06:49:53 +000022#include <logbuff.h>
Simon Glassd1d087d2015-02-27 22:06:36 -070023#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050024#include <mapmem.h>
Simon Glass62cf9122013-04-26 02:53:43 +000025#include <os.h>
Simon Glassc45e3592013-03-11 06:49:53 +000026#include <post.h>
Simon Glass6ab91072017-03-31 08:40:38 -060027#include <relocate.h>
Simon Glass50250b52013-03-11 14:30:42 +000028#include <spi.h>
Jeroen Hofsteea802b982014-06-23 23:20:19 +020029#include <status_led.h>
Simon Glass8e4f80f2016-02-24 09:14:50 -070030#include <timer.h>
Simon Glass209a1a62013-06-11 11:14:42 -070031#include <trace.h>
Simon Glassfce58f52016-01-18 19:52:21 -070032#include <video.h>
Simon Glass50250b52013-03-11 14:30:42 +000033#include <watchdog.h>
Simon Glassf004e8a2017-05-17 08:23:01 -060034#ifdef CONFIG_MACH_TYPE
35#include <asm/mach-types.h>
36#endif
Simon Glasse7706032017-03-31 08:40:39 -060037#if defined(CONFIG_MP) && defined(CONFIG_PPC)
38#include <asm/mp.h>
39#endif
Simon Glassc45e3592013-03-11 06:49:53 +000040#include <asm/io.h>
41#include <asm/sections.h>
Simon Glassa730c5d2014-07-23 06:55:04 -060042#include <dm/root.h>
Simon Glassb3c12562017-03-31 08:40:35 -060043#include <linux/errno.h>
Simon Glassc45e3592013-03-11 06:49:53 +000044
45/*
46 * Pointer to initial global data area
47 *
48 * Here we initialize it if needed.
49 */
50#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
51#undef XTRN_DECLARE_GLOBAL_DATA_PTR
52#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
53DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
54#else
55DECLARE_GLOBAL_DATA_PTR;
56#endif
57
58/*
Simon Glass839855c2015-04-28 20:25:03 -060059 * TODO(sjg@chromium.org): IMO this code should be
Simon Glassc45e3592013-03-11 06:49:53 +000060 * refactored to a single function, something like:
61 *
62 * void led_set_state(enum led_colour_t colour, int on);
63 */
64/************************************************************************
65 * Coloured LED functionality
66 ************************************************************************
67 * May be supplied by boards if desired
68 */
Jeroen Hofsteea802b982014-06-23 23:20:19 +020069__weak void coloured_LED_init(void) {}
70__weak void red_led_on(void) {}
71__weak void red_led_off(void) {}
72__weak void green_led_on(void) {}
73__weak void green_led_off(void) {}
74__weak void yellow_led_on(void) {}
75__weak void yellow_led_off(void) {}
76__weak void blue_led_on(void) {}
77__weak void blue_led_off(void) {}
Simon Glassc45e3592013-03-11 06:49:53 +000078
79/*
80 * Why is gd allocated a register? Prior to reloc it might be better to
81 * just pass it around to each function in this file?
82 *
83 * After reloc one could argue that it is hardly used and doesn't need
84 * to be in a register. Or if it is it should perhaps hold pointers to all
85 * global data for all modules, so that post-reloc we can avoid the massive
86 * literal pool we get on ARM. Or perhaps just encourage each module to use
87 * a structure...
88 */
89
Sonic Zhangf503a522014-07-17 19:01:34 +080090#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glass50250b52013-03-11 14:30:42 +000091static int init_func_watchdog_init(void)
92{
Tom Rini210ebce2017-03-14 11:08:10 -040093# if defined(CONFIG_HW_WATCHDOG) && \
94 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roeseee86af22015-03-10 08:04:36 +010095 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin87db2942016-06-13 14:24:23 +020096 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roeseee86af22015-03-10 08:04:36 +010097 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangf503a522014-07-17 19:01:34 +080098 hw_watchdog_init();
Simon Glass50250b52013-03-11 14:30:42 +000099 puts(" Watchdog enabled\n");
Anatolij Gustschind3aa98a2016-06-13 14:24:24 +0200100# endif
Simon Glass50250b52013-03-11 14:30:42 +0000101 WATCHDOG_RESET();
102
103 return 0;
104}
105
106int init_func_watchdog_reset(void)
107{
108 WATCHDOG_RESET();
109
110 return 0;
111}
112#endif /* CONFIG_WATCHDOG */
113
Jeroen Hofstee45846052014-10-08 22:57:22 +0200114__weak void board_add_ram_info(int use_default)
Simon Glass50250b52013-03-11 14:30:42 +0000115{
116 /* please define platform specific board_add_ram_info() */
117}
118
Simon Glassc45e3592013-03-11 06:49:53 +0000119static int init_baud_rate(void)
120{
Simon Glass22c34c22017-08-03 12:22:13 -0600121 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glassc45e3592013-03-11 06:49:53 +0000122 return 0;
123}
124
125static int display_text_info(void)
126{
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600127#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100128 ulong bss_start, bss_end, text_base;
Simon Glassc45e3592013-03-11 06:49:53 +0000129
Simon Glass9c9f44a2013-03-11 07:06:48 +0000130 bss_start = (ulong)&__bss_start;
131 bss_end = (ulong)&__bss_end;
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100132
Sonic Zhangf503a522014-07-17 19:01:34 +0800133#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100134 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800135#else
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100136 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800137#endif
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100138
139 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
140 text_base, bss_start, bss_end);
Simon Glass62cf9122013-04-26 02:53:43 +0000141#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000142
Simon Glassc45e3592013-03-11 06:49:53 +0000143 return 0;
144}
145
146static int announce_dram_init(void)
147{
148 puts("DRAM: ");
149 return 0;
150}
151
152static int show_dram_config(void)
153{
York Sun60ac15a2014-05-02 17:28:05 -0700154 unsigned long long size;
Simon Glassc45e3592013-03-11 06:49:53 +0000155
156#ifdef CONFIG_NR_DRAM_BANKS
157 int i;
158
159 debug("\nRAM Configuration:\n");
160 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
161 size += gd->bd->bi_dram[i].size;
Bin Mengc8964482015-08-06 01:31:20 -0700162 debug("Bank #%d: %llx ", i,
163 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glassc45e3592013-03-11 06:49:53 +0000164#ifdef DEBUG
165 print_size(gd->bd->bi_dram[i].size, "\n");
166#endif
167 }
168 debug("\nDRAM: ");
169#else
170 size = gd->ram_size;
171#endif
172
Simon Glass50250b52013-03-11 14:30:42 +0000173 print_size(size, "");
174 board_add_ram_info(0);
175 putc('\n');
Simon Glassc45e3592013-03-11 06:49:53 +0000176
177 return 0;
178}
179
Simon Glass2f949c32017-03-31 08:40:32 -0600180__weak int dram_init_banksize(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000181{
182#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
183 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
184 gd->bd->bi_dram[0].size = get_effective_memsize();
185#endif
Simon Glass2f949c32017-03-31 08:40:32 -0600186
187 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000188}
189
Simon Glass1a46a722017-05-12 21:09:56 -0600190#if defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000191static int init_func_i2c(void)
192{
193 puts("I2C: ");
trema6612902013-09-21 18:13:34 +0200194#ifdef CONFIG_SYS_I2C
195 i2c_init_all();
196#else
Simon Glass50250b52013-03-11 14:30:42 +0000197 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trema6612902013-09-21 18:13:34 +0200198#endif
Simon Glass50250b52013-03-11 14:30:42 +0000199 puts("ready\n");
200 return 0;
201}
202#endif
203
204#if defined(CONFIG_HARD_SPI)
205static int init_func_spi(void)
206{
207 puts("SPI: ");
208 spi_init();
209 puts("ready\n");
210 return 0;
211}
212#endif
213
Simon Glassc45e3592013-03-11 06:49:53 +0000214static int setup_mon_len(void)
215{
Michal Simek65e915c2014-05-08 16:08:44 +0200216#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100217 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600218#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glass62cf9122013-04-26 02:53:43 +0000219 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Rini210ebce2017-03-14 11:08:10 -0400220#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800221 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200222#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800223 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass90632bd2016-05-14 18:49:28 -0600224#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glass50250b52013-03-11 14:30:42 +0000225 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
226 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000227#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000228 return 0;
229}
230
231__weak int arch_cpu_init(void)
232{
233 return 0;
234}
235
Paul Burton1f508dd2016-09-21 11:18:46 +0100236__weak int mach_cpu_init(void)
237{
238 return 0;
239}
240
Simon Glassc45e3592013-03-11 06:49:53 +0000241/* Get the top of usable RAM */
242__weak ulong board_get_usable_ram_top(ulong total_size)
243{
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700244#ifdef CONFIG_SYS_SDRAM_BASE
245 /*
Simon Glass839855c2015-04-28 20:25:03 -0600246 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700247 * 32-bit address space. If so, clip the usable RAM so it doesn't.
248 */
249 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
250 /*
251 * Will wrap back to top of 32-bit space when reservations
252 * are made.
253 */
254 return 0;
255#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000256 return gd->ram_top;
257}
258
259static int setup_dest_addr(void)
260{
261 debug("Monitor len: %08lX\n", gd->mon_len);
262 /*
263 * Ram is setup, size stored in gd !!
264 */
265 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun4de24ef2017-03-06 09:02:28 -0800266#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glassc45e3592013-03-11 06:49:53 +0000267 /*
268 * Subtract specified amount of memory to hide so that it won't
269 * get "touched" at all by U-Boot. By fixing up gd->ram_size
270 * the Linux kernel should now get passed the now "corrected"
York Sun4de24ef2017-03-06 09:02:28 -0800271 * memory size and won't touch it either. This should work
272 * for arch/ppc and arch/powerpc. Only Linux board ports in
273 * arch/powerpc with bootwrapper support, that recalculate the
274 * memory size from the SDRAM controller setup will have to
275 * get fixed.
Simon Glassc45e3592013-03-11 06:49:53 +0000276 */
York Sun4de24ef2017-03-06 09:02:28 -0800277 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
278#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000279#ifdef CONFIG_SYS_SDRAM_BASE
280 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
281#endif
Simon Glass50250b52013-03-11 14:30:42 +0000282 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000283 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000284 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000285 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700286#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000287 /*
288 * We need to make sure the location we intend to put secondary core
289 * boot code is reserved and not used by any part of u-boot
290 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000291 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
292 gd->relocaddr = determine_mp_bootpg(NULL);
293 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000294 }
295#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000296 return 0;
297}
298
Simon Glassbcf257d2017-03-31 08:40:28 -0600299#if defined(CONFIG_LOGBUFFER)
Simon Glassc45e3592013-03-11 06:49:53 +0000300static int reserve_logbuffer(void)
301{
Simon Glassbcf257d2017-03-31 08:40:28 -0600302#ifndef CONFIG_ALT_LB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000303 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000304 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000305 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000306 gd->relocaddr);
Simon Glassbcf257d2017-03-31 08:40:28 -0600307#endif
308
Simon Glassc45e3592013-03-11 06:49:53 +0000309 return 0;
310}
311#endif
312
313#ifdef CONFIG_PRAM
314/* reserve protected RAM */
315static int reserve_pram(void)
316{
317 ulong reg;
318
Simon Glass22c34c22017-08-03 12:22:13 -0600319 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000320 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000321 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000322 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000323 return 0;
324}
325#endif /* CONFIG_PRAM */
326
327/* Round memory pointer down to next 4 kB limit */
328static int reserve_round_4k(void)
329{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000330 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000331 return 0;
332}
333
Simon Glasse3cb4492017-03-31 08:40:29 -0600334#ifdef CONFIG_ARM
Siva Durga Prasad Paladugu05223532017-07-13 19:01:08 +0530335__weak int reserve_mmu(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000336{
Simon Glasse3cb4492017-03-31 08:40:29 -0600337#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glassc45e3592013-03-11 06:49:53 +0000338 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800339 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000340 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000341
342 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000343 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000344
Masahiro Yamadad1589242013-05-27 00:37:30 +0000345 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000346 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
347 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sunf84f81e2016-06-24 16:46:19 -0700348
349#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
350 /*
351 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
352 * with location within secure ram.
353 */
354 gd->arch.tlb_allocated = gd->arch.tlb_addr;
355#endif
Simon Glasse3cb4492017-03-31 08:40:29 -0600356#endif
York Sunf84f81e2016-06-24 16:46:19 -0700357
Simon Glassc45e3592013-03-11 06:49:53 +0000358 return 0;
359}
360#endif
361
Simon Glassfce58f52016-01-18 19:52:21 -0700362static int reserve_video(void)
363{
Simon Glass70ac86c2017-03-31 08:40:30 -0600364#ifdef CONFIG_DM_VIDEO
Simon Glassfce58f52016-01-18 19:52:21 -0700365 ulong addr;
366 int ret;
367
368 addr = gd->relocaddr;
369 ret = video_reserve(&addr);
370 if (ret)
371 return ret;
372 gd->relocaddr = addr;
Simon Glass70ac86c2017-03-31 08:40:30 -0600373#elif defined(CONFIG_LCD)
Simon Glassfce58f52016-01-18 19:52:21 -0700374# ifdef CONFIG_FB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000375 gd->fb_base = CONFIG_FB_ADDR;
Simon Glassfce58f52016-01-18 19:52:21 -0700376# else
Simon Glassc45e3592013-03-11 06:49:53 +0000377 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000378 gd->relocaddr = lcd_setmem(gd->relocaddr);
379 gd->fb_base = gd->relocaddr;
Simon Glassfce58f52016-01-18 19:52:21 -0700380# endif /* CONFIG_FB_ADDR */
Simon Glass70ac86c2017-03-31 08:40:30 -0600381#elif defined(CONFIG_VIDEO) && \
Heiko Schocher65d94db2017-06-07 17:33:09 +0200382 (!defined(CONFIG_PPC)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800383 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Rini210ebce2017-03-14 11:08:10 -0400384 !defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000385 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000386 gd->relocaddr = video_setmem(gd->relocaddr);
387 gd->fb_base = gd->relocaddr;
Simon Glass70ac86c2017-03-31 08:40:30 -0600388#endif
Simon Glass50250b52013-03-11 14:30:42 +0000389
390 return 0;
391}
Simon Glass50250b52013-03-11 14:30:42 +0000392
Simon Glass1008da02016-01-18 19:52:20 -0700393static int reserve_trace(void)
394{
395#ifdef CONFIG_TRACE
396 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
397 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
398 debug("Reserving %dk for trace data at: %08lx\n",
399 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
400#endif
401
402 return 0;
403}
404
Simon Glassc45e3592013-03-11 06:49:53 +0000405static int reserve_uboot(void)
406{
407 /*
408 * reserve memory for U-Boot code, data & bss
409 * round down to next 4 kB limit
410 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000411 gd->relocaddr -= gd->mon_len;
412 gd->relocaddr &= ~(4096 - 1);
Paul Burtond3a278d2017-06-19 11:53:47 -0700413#if defined(CONFIG_E500) || defined(CONFIG_MIPS)
Simon Glass50250b52013-03-11 14:30:42 +0000414 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000415 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000416#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000417
418 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000419 gd->relocaddr);
420
421 gd->start_addr_sp = gd->relocaddr;
422
Simon Glassc45e3592013-03-11 06:49:53 +0000423 return 0;
424}
425
426/* reserve memory for malloc() area */
427static int reserve_malloc(void)
428{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000429 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000430 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000431 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000432 return 0;
433}
434
435/* (permanently) allocate a Board Info struct */
436static int reserve_board(void)
437{
Sonic Zhangf503a522014-07-17 19:01:34 +0800438 if (!gd->bd) {
439 gd->start_addr_sp -= sizeof(bd_t);
440 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
441 memset(gd->bd, '\0', sizeof(bd_t));
442 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
443 sizeof(bd_t), gd->start_addr_sp);
444 }
Simon Glassc45e3592013-03-11 06:49:53 +0000445 return 0;
446}
447
448static int setup_machine(void)
449{
450#ifdef CONFIG_MACH_TYPE
451 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
452#endif
453 return 0;
454}
455
456static int reserve_global_data(void)
457{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000458 gd->start_addr_sp -= sizeof(gd_t);
459 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000460 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000461 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000462 return 0;
463}
464
465static int reserve_fdt(void)
466{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100467#ifndef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000468 /*
Simon Glass839855c2015-04-28 20:25:03 -0600469 * If the device tree is sitting immediately above our image then we
Simon Glassc45e3592013-03-11 06:49:53 +0000470 * must relocate it. If it is embedded in the data section, then it
471 * will be relocated with other data.
472 */
473 if (gd->fdt_blob) {
474 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
475
Masahiro Yamadad1589242013-05-27 00:37:30 +0000476 gd->start_addr_sp -= gd->fdt_size;
477 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000478 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000479 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000480 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100481#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000482
483 return 0;
484}
485
Simon Glassb9aff922017-05-22 05:05:30 -0600486static int reserve_bootstage(void)
487{
488#ifdef CONFIG_BOOTSTAGE
489 int size = bootstage_get_size();
490
491 gd->start_addr_sp -= size;
492 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
493 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
494 gd->start_addr_sp);
495#endif
496
497 return 0;
498}
499
Andreas Bießmann25429862015-02-06 23:06:45 +0100500int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000501{
Andreas Bießmann25429862015-02-06 23:06:45 +0100502 return 0;
503}
Simon Glass4d2aee82013-03-05 14:39:45 +0000504
Andreas Bießmann25429862015-02-06 23:06:45 +0100505static int reserve_stacks(void)
506{
507 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000508 gd->start_addr_sp -= 16;
509 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000510
511 /*
Simon Glass839855c2015-04-28 20:25:03 -0600512 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann25429862015-02-06 23:06:45 +0100513 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000514 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100515 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000516}
517
518static int display_new_sp(void)
519{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000520 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000521
522 return 0;
523}
524
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200525#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
526 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000527static int setup_board_part1(void)
528{
529 bd_t *bd = gd->bd;
530
531 /*
532 * Save local variables to board info struct
533 */
Simon Glass50250b52013-03-11 14:30:42 +0000534 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
535 bd->bi_memsize = gd->ram_size; /* size in bytes */
536
537#ifdef CONFIG_SYS_SRAM_BASE
538 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
539 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
540#endif
541
Heiko Schocherd4def9b2017-06-07 17:33:11 +0200542#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Simon Glass50250b52013-03-11 14:30:42 +0000543 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
544#endif
Heiko Schocher6f90e582017-06-14 05:49:40 +0200545#if defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000546 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
547#endif
548#if defined(CONFIG_MPC83xx)
549 bd->bi_immrbar = CONFIG_SYS_IMMR;
550#endif
Simon Glass50250b52013-03-11 14:30:42 +0000551
552 return 0;
553}
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100554#endif
Simon Glass50250b52013-03-11 14:30:42 +0000555
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100556#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000557static int setup_board_part2(void)
558{
559 bd_t *bd = gd->bd;
560
561 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
562 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
563#if defined(CONFIG_CPM2)
564 bd->bi_cpmfreq = gd->arch.cpm_clk;
565 bd->bi_brgfreq = gd->arch.brg_clk;
566 bd->bi_sccfreq = gd->arch.scc_clk;
567 bd->bi_vco = gd->arch.vco_out;
568#endif /* CONFIG_CPM2 */
Alison Wang8f6d8f32015-02-12 18:33:15 +0800569#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
570 bd->bi_pcifreq = gd->pci_clk;
571#endif
572#if defined(CONFIG_EXTRA_CLOCK)
573 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
574 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
575 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
576#endif
Simon Glass50250b52013-03-11 14:30:42 +0000577
578 return 0;
579}
580#endif
581
Simon Glassc45e3592013-03-11 06:49:53 +0000582#ifdef CONFIG_POST
583static int init_post(void)
584{
585 post_bootmode_init();
586 post_run(NULL, POST_ROM | post_bootmode_get(0));
587
588 return 0;
589}
590#endif
591
Simon Glassc45e3592013-03-11 06:49:53 +0000592static int reloc_fdt(void)
593{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100594#ifndef CONFIG_OF_EMBED
Simon Glass00dd17a2015-08-04 12:33:39 -0600595 if (gd->flags & GD_FLG_SKIP_RELOC)
596 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000597 if (gd->new_fdt) {
598 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
599 gd->fdt_blob = gd->new_fdt;
600 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100601#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000602
603 return 0;
604}
605
Simon Glassb9aff922017-05-22 05:05:30 -0600606static int reloc_bootstage(void)
607{
608#ifdef CONFIG_BOOTSTAGE
609 if (gd->flags & GD_FLG_SKIP_RELOC)
610 return 0;
611 if (gd->new_bootstage) {
612 int size = bootstage_get_size();
613
614 debug("Copying bootstage from %p to %p, size %x\n",
615 gd->bootstage, gd->new_bootstage, size);
616 memcpy(gd->new_bootstage, gd->bootstage, size);
617 gd->bootstage = gd->new_bootstage;
618 }
619#endif
620
621 return 0;
622}
623
Simon Glassc45e3592013-03-11 06:49:53 +0000624static int setup_reloc(void)
625{
Simon Glass00dd17a2015-08-04 12:33:39 -0600626 if (gd->flags & GD_FLG_SKIP_RELOC) {
627 debug("Skipping relocation due to flag\n");
628 return 0;
629 }
630
Sonic Zhangf503a522014-07-17 19:01:34 +0800631#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann160583b2017-06-08 10:18:25 +0200632#ifdef ARM
633 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
634#elif defined(CONFIG_M68K)
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100635 /*
636 * On all ColdFire arch cpu, monitor code starts always
637 * just after the default vector table location, so at 0x400
638 */
639 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Lothar Waßmann160583b2017-06-08 10:18:25 +0200640#else
641 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100642#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800643#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000644 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
645
646 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000647 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000648 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
649 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000650
651 return 0;
652}
653
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100654#ifdef CONFIG_OF_BOARD_FIXUP
655static int fix_fdt(void)
656{
657 return board_fix_fdt((void *)gd->fdt_blob);
658}
659#endif
660
Simon Glassc45e3592013-03-11 06:49:53 +0000661/* ARM calls relocate_code from its crt0.S */
Simon Glass6e1a81a2017-01-16 07:03:49 -0700662#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
663 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000664
665static int jump_to_copy(void)
666{
Simon Glass00dd17a2015-08-04 12:33:39 -0600667 if (gd->flags & GD_FLG_SKIP_RELOC)
668 return 0;
Simon Glass6d179872013-03-05 14:39:52 +0000669 /*
670 * x86 is special, but in a nice way. It uses a trampoline which
671 * enables the dcache if possible.
672 *
673 * For now, other archs use relocate_code(), which is implemented
674 * similarly for all archs. When we do generic relocation, hopefully
675 * we can make all archs enable the dcache prior to relocation.
676 */
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300677#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000678 /*
679 * SDRAM and console are now initialised. The final stack can now
680 * be setup in SDRAM. Code execution will continue in Flash, but
681 * with the stack in SDRAM and Global Data in temporary memory
682 * (CPU cache)
683 */
Simon Glass0e27b872015-08-10 20:44:32 -0600684 arch_setup_gd(gd->new_gd);
Simon Glass6d179872013-03-05 14:39:52 +0000685 board_init_f_r_trampoline(gd->start_addr_sp);
686#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000687 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000688#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000689
690 return 0;
691}
692#endif
693
694/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glass88200332017-05-22 05:05:25 -0600695static int initf_bootstage(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000696{
Simon Glassc55d5c32017-06-07 10:28:46 -0600697 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
698 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glass88200332017-05-22 05:05:25 -0600699 int ret;
700
Simon Glass01154cb2017-05-22 05:05:35 -0600701 ret = bootstage_init(!from_spl);
Simon Glass88200332017-05-22 05:05:25 -0600702 if (ret)
703 return ret;
Simon Glass01154cb2017-05-22 05:05:35 -0600704 if (from_spl) {
705 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
706 CONFIG_BOOTSTAGE_STASH_SIZE);
707
708 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
709 if (ret && ret != -ENOENT) {
710 debug("Failed to unstash bootstage: err=%d\n", ret);
711 return ret;
712 }
713 }
Simon Glass88200332017-05-22 05:05:25 -0600714
Simon Glassc45e3592013-03-11 06:49:53 +0000715 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
716
717 return 0;
718}
719
Simon Glass1bb49232015-11-08 23:47:48 -0700720static int initf_console_record(void)
721{
Andy Yan1fa20e4d2017-07-24 17:43:34 +0800722#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glass1bb49232015-11-08 23:47:48 -0700723 return console_record_init();
724#else
725 return 0;
726#endif
727}
728
Simon Glassa730c5d2014-07-23 06:55:04 -0600729static int initf_dm(void)
730{
Andy Yan1fa20e4d2017-07-24 17:43:34 +0800731#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassa730c5d2014-07-23 06:55:04 -0600732 int ret;
733
Simon Glass405e2b02017-05-22 05:05:32 -0600734 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
Simon Glassa730c5d2014-07-23 06:55:04 -0600735 ret = dm_init_and_scan(true);
Simon Glass405e2b02017-05-22 05:05:32 -0600736 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
Simon Glassa730c5d2014-07-23 06:55:04 -0600737 if (ret)
738 return ret;
739#endif
Simon Glass8e4f80f2016-02-24 09:14:50 -0700740#ifdef CONFIG_TIMER_EARLY
741 ret = dm_timer_init();
742 if (ret)
743 return ret;
744#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600745
746 return 0;
747}
748
Simon Glass5ded7e52015-01-19 22:16:12 -0700749/* Architecture-specific memory reservation */
750__weak int reserve_arch(void)
751{
752 return 0;
753}
754
Simon Glass7af8d052015-03-05 12:25:16 -0700755__weak int arch_cpu_init_dm(void)
756{
757 return 0;
758}
759
Simon Glass2031fad2017-01-16 07:03:50 -0700760static const init_fnc_t init_sequence_f[] = {
Simon Glassc45e3592013-03-11 06:49:53 +0000761 setup_mon_len,
Simon Glass26b78b22015-02-27 22:06:34 -0700762#ifdef CONFIG_OF_CONTROL
Simon Glassa0877672015-02-27 22:06:35 -0700763 fdtdec_setup,
Simon Glass26b78b22015-02-27 22:06:34 -0700764#endif
Kevin Hilman676f0192014-12-09 15:03:58 -0800765#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700766 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800767#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700768 initf_malloc,
Simon Glasse635af12017-05-22 05:05:31 -0600769 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glass1bb49232015-11-08 23:47:48 -0700770 initf_console_record,
Simon Glass295c4232017-03-28 10:27:18 -0600771#if defined(CONFIG_HAVE_FSP)
772 arch_fsp_init,
Bin Meng178f8972015-08-20 06:40:18 -0700773#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000774 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton1f508dd2016-09-21 11:18:46 +0100775 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass6df5de22014-09-03 17:36:59 -0600776 initf_dm,
Simon Glass7af8d052015-03-05 12:25:16 -0700777 arch_cpu_init_dm,
Simon Glassc45e3592013-03-11 06:49:53 +0000778#if defined(CONFIG_BOARD_EARLY_INIT_F)
779 board_early_init_f,
780#endif
Simon Glass6829d8c2017-03-28 10:27:26 -0600781#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glass70064a72017-03-28 10:27:19 -0600782 /* get CPU and bus clocks according to the environment variable */
Simon Glass50250b52013-03-11 14:30:42 +0000783 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glasse8d20d42017-03-28 10:27:23 -0600784#endif
Angelo Dureghellocd226852017-05-10 23:58:06 +0200785#if !defined(CONFIG_M68K)
Simon Glassc45e3592013-03-11 06:49:53 +0000786 timer_init, /* initialize timer */
Angelo Dureghellocd226852017-05-10 23:58:06 +0200787#endif
Simon Glass50250b52013-03-11 14:30:42 +0000788#if defined(CONFIG_BOARD_POSTCLK_INIT)
789 board_postclk_init,
790#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000791 env_init, /* initialize environment */
792 init_baud_rate, /* initialze baudrate settings */
793 serial_init, /* serial communications setup */
794 console_init_f, /* stage 1 init of console */
795 display_options, /* say that we are here */
796 display_text_info, /* show debugging info if required */
Simon Glassee7c36f2017-03-28 10:27:30 -0600797#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
798 defined(CONFIG_X86)
Simon Glass50250b52013-03-11 14:30:42 +0000799 checkcpu,
800#endif
Simon Glass68c1d012017-01-23 13:31:25 -0700801#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glassc45e3592013-03-11 06:49:53 +0000802 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass68c1d012017-01-23 13:31:25 -0700803#endif
Cooper Jr., Franklind8b354a2017-06-16 17:25:12 -0500804#if defined(CONFIG_DTB_RESELECT)
805 embedded_dtb_select,
806#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000807#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900808 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000809#endif
Simon Glass50250b52013-03-11 14:30:42 +0000810 INIT_FUNC_WATCHDOG_INIT
811#if defined(CONFIG_MISC_INIT_F)
812 misc_init_f,
813#endif
814 INIT_FUNC_WATCHDOG_RESET
Simon Glass1a46a722017-05-12 21:09:56 -0600815#if defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000816 init_func_i2c,
817#endif
818#if defined(CONFIG_HARD_SPI)
819 init_func_spi,
820#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000821 announce_dram_init,
Simon Glassc45e3592013-03-11 06:49:53 +0000822 dram_init, /* configure available RAM banks */
Simon Glass50250b52013-03-11 14:30:42 +0000823#ifdef CONFIG_POST
824 post_init_f,
825#endif
826 INIT_FUNC_WATCHDOG_RESET
827#if defined(CONFIG_SYS_DRAM_TEST)
828 testdram,
829#endif /* CONFIG_SYS_DRAM_TEST */
830 INIT_FUNC_WATCHDOG_RESET
831
Simon Glassc45e3592013-03-11 06:49:53 +0000832#ifdef CONFIG_POST
833 init_post,
834#endif
Simon Glass50250b52013-03-11 14:30:42 +0000835 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000836 /*
837 * Now that we have DRAM mapped and working, we can
838 * relocate the code and continue running from DRAM.
839 *
840 * Reserve memory at end of RAM for (top down in that order):
841 * - area that won't get touched by U-Boot and Linux (optional)
842 * - kernel log buffer
843 * - protected RAM
844 * - LCD framebuffer
845 * - monitor code
846 * - board info struct
847 */
848 setup_dest_addr,
Simon Glassbcf257d2017-03-31 08:40:28 -0600849#if defined(CONFIG_LOGBUFFER)
Simon Glassc45e3592013-03-11 06:49:53 +0000850 reserve_logbuffer,
851#endif
852#ifdef CONFIG_PRAM
853 reserve_pram,
854#endif
855 reserve_round_4k,
Simon Glasse3cb4492017-03-31 08:40:29 -0600856#ifdef CONFIG_ARM
Simon Glassc45e3592013-03-11 06:49:53 +0000857 reserve_mmu,
858#endif
Simon Glassfce58f52016-01-18 19:52:21 -0700859 reserve_video,
Simon Glass1008da02016-01-18 19:52:20 -0700860 reserve_trace,
Simon Glassc45e3592013-03-11 06:49:53 +0000861 reserve_uboot,
862 reserve_malloc,
863 reserve_board,
Simon Glassc45e3592013-03-11 06:49:53 +0000864 setup_machine,
865 reserve_global_data,
866 reserve_fdt,
Simon Glassb9aff922017-05-22 05:05:30 -0600867 reserve_bootstage,
Simon Glass5ded7e52015-01-19 22:16:12 -0700868 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +0000869 reserve_stacks,
Simon Glass2f949c32017-03-31 08:40:32 -0600870 dram_init_banksize,
Simon Glassc45e3592013-03-11 06:49:53 +0000871 show_dram_config,
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200872#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
873 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000874 setup_board_part1,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100875#endif
876#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000877 INIT_FUNC_WATCHDOG_RESET
878 setup_board_part2,
879#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000880 display_new_sp,
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100881#ifdef CONFIG_OF_BOARD_FIXUP
882 fix_fdt,
883#endif
Simon Glass50250b52013-03-11 14:30:42 +0000884 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000885 reloc_fdt,
Simon Glassb9aff922017-05-22 05:05:30 -0600886 reloc_bootstage,
Simon Glassc45e3592013-03-11 06:49:53 +0000887 setup_reloc,
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300888#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glassd50b2f42015-01-01 16:18:09 -0700889 copy_uboot_to_ram,
Simon Glassd50b2f42015-01-01 16:18:09 -0700890 do_elf_reloc_fixups,
Simon Glass2a7bf772017-01-16 07:03:52 -0700891 clear_bss,
Simon Glassd50b2f42015-01-01 16:18:09 -0700892#endif
Chris Zankel41e37372016-08-10 18:36:43 +0300893#if defined(CONFIG_XTENSA)
894 clear_bss,
895#endif
Simon Glass6e1a81a2017-01-16 07:03:49 -0700896#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
897 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000898 jump_to_copy,
899#endif
900 NULL,
901};
902
903void board_init_f(ulong boot_flags)
904{
Simon Glassc45e3592013-03-11 06:49:53 +0000905 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +0400906 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000907
908 if (initcall_run_list(init_sequence_f))
909 hang();
910
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600911#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass6e1a81a2017-01-16 07:03:49 -0700912 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000913 /* NOTREACHED - jump_to_copy() does not return */
914 hang();
915#endif
916}
Simon Glass6d179872013-03-05 14:39:52 +0000917
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300918#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000919/*
920 * For now this code is only used on x86.
921 *
922 * init_sequence_f_r is the list of init functions which are run when
923 * U-Boot is executing from Flash with a semi-limited 'C' environment.
924 * The following limitations must be considered when implementing an
925 * '_f_r' function:
926 * - 'static' variables are read-only
927 * - Global Data (gd->xxx) is read/write
928 *
929 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
930 * supported). It _should_, if possible, copy global data to RAM and
931 * initialise the CPU caches (to speed up the relocation process)
932 *
933 * NOTE: At present only x86 uses this route, but it is intended that
934 * all archs will move to this when generic relocation is implemented.
935 */
Simon Glass2031fad2017-01-16 07:03:50 -0700936static const init_fnc_t init_sequence_f_r[] = {
Simon Glass6e1a81a2017-01-16 07:03:49 -0700937#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass6d179872013-03-05 14:39:52 +0000938 init_cache_f_r,
Simon Glass6e1a81a2017-01-16 07:03:49 -0700939#endif
Simon Glass6d179872013-03-05 14:39:52 +0000940
941 NULL,
942};
943
944void board_init_f_r(void)
945{
946 if (initcall_run_list(init_sequence_f_r))
947 hang();
948
949 /*
Simon Glass51f73f12016-03-11 22:06:51 -0700950 * The pre-relocation drivers may be using memory that has now gone
951 * away. Mark serial as unavailable - this will fall back to the debug
952 * UART if available.
953 */
954 gd->flags &= ~GD_FLG_SERIAL_READY;
Simon Glassb77fe1f2017-09-05 19:49:45 -0600955#ifdef CONFIG_TIMER
956 gd->timer = NULL;
957#endif
Simon Glass51f73f12016-03-11 22:06:51 -0700958
959 /*
Simon Glass6d179872013-03-05 14:39:52 +0000960 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
961 * Transfer execution from Flash to RAM by calculating the address
962 * of the in-RAM copy of board_init_r() and calling it
963 */
Alexey Brodkin9c832f12015-02-25 17:59:02 +0300964 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000965
966 /* NOTREACHED - board_init_r() does not return */
967 hang();
968}
Alexey Brodkin73503182015-03-24 11:12:47 +0300969#endif /* CONFIG_X86 */