blob: bafe3aa49ce268c36f64932ebaf64d0bec0937e1 [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>
21#include <logbuff.h>
Simon Glassd1d087d2015-02-27 22:06:36 -070022#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050023#include <mapmem.h>
Simon Glass50250b52013-03-11 14:30:42 +000024
25/* TODO: Can we move these into arch/ headers? */
26#ifdef CONFIG_8xx
27#include <mpc8xx.h>
28#endif
29#ifdef CONFIG_5xx
30#include <mpc5xx.h>
31#endif
32#ifdef CONFIG_MPC5xxx
33#include <mpc5xxx.h>
34#endif
Gabriel Huauda0afc22014-09-03 13:57:54 -070035#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huau170ceaf2014-07-26 11:35:43 -070036#include <asm/mp.h>
37#endif
Simon Glass50250b52013-03-11 14:30:42 +000038
Simon Glass62cf9122013-04-26 02:53:43 +000039#include <os.h>
Simon Glassc45e3592013-03-11 06:49:53 +000040#include <post.h>
Simon Glass50250b52013-03-11 14:30:42 +000041#include <spi.h>
Jeroen Hofsteea802b982014-06-23 23:20:19 +020042#include <status_led.h>
Simon Glass8e4f80f2016-02-24 09:14:50 -070043#include <timer.h>
Simon Glass209a1a62013-06-11 11:14:42 -070044#include <trace.h>
Simon Glassfce58f52016-01-18 19:52:21 -070045#include <video.h>
Simon Glass50250b52013-03-11 14:30:42 +000046#include <watchdog.h>
Simon Glassc45e3592013-03-11 06:49:53 +000047#include <asm/io.h>
48#include <asm/sections.h>
Alexey Brodkin913e9f02015-02-24 19:40:36 +030049#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +000050#include <asm/init_helpers.h>
Chris Zankel41e37372016-08-10 18:36:43 +030051#endif
52#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
Simon Glass6d179872013-03-05 14:39:52 +000053#include <asm/relocate.h>
54#endif
Simon Glassa730c5d2014-07-23 06:55:04 -060055#include <dm/root.h>
Simon Glassb3c12562017-03-31 08:40:35 -060056#include <linux/errno.h>
Simon Glassc45e3592013-03-11 06:49:53 +000057
58/*
59 * Pointer to initial global data area
60 *
61 * Here we initialize it if needed.
62 */
63#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
64#undef XTRN_DECLARE_GLOBAL_DATA_PTR
65#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
66DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
67#else
68DECLARE_GLOBAL_DATA_PTR;
69#endif
70
71/*
Simon Glass839855c2015-04-28 20:25:03 -060072 * TODO(sjg@chromium.org): IMO this code should be
Simon Glassc45e3592013-03-11 06:49:53 +000073 * refactored to a single function, something like:
74 *
75 * void led_set_state(enum led_colour_t colour, int on);
76 */
77/************************************************************************
78 * Coloured LED functionality
79 ************************************************************************
80 * May be supplied by boards if desired
81 */
Jeroen Hofsteea802b982014-06-23 23:20:19 +020082__weak void coloured_LED_init(void) {}
83__weak void red_led_on(void) {}
84__weak void red_led_off(void) {}
85__weak void green_led_on(void) {}
86__weak void green_led_off(void) {}
87__weak void yellow_led_on(void) {}
88__weak void yellow_led_off(void) {}
89__weak void blue_led_on(void) {}
90__weak void blue_led_off(void) {}
Simon Glassc45e3592013-03-11 06:49:53 +000091
92/*
93 * Why is gd allocated a register? Prior to reloc it might be better to
94 * just pass it around to each function in this file?
95 *
96 * After reloc one could argue that it is hardly used and doesn't need
97 * to be in a register. Or if it is it should perhaps hold pointers to all
98 * global data for all modules, so that post-reloc we can avoid the massive
99 * literal pool we get on ARM. Or perhaps just encourage each module to use
100 * a structure...
101 */
102
Sonic Zhangf503a522014-07-17 19:01:34 +0800103#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glass50250b52013-03-11 14:30:42 +0000104static int init_func_watchdog_init(void)
105{
Tom Rini210ebce2017-03-14 11:08:10 -0400106# if defined(CONFIG_HW_WATCHDOG) && \
107 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100108 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin87db2942016-06-13 14:24:23 +0200109 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100110 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangf503a522014-07-17 19:01:34 +0800111 hw_watchdog_init();
Simon Glass50250b52013-03-11 14:30:42 +0000112 puts(" Watchdog enabled\n");
Anatolij Gustschind3aa98a2016-06-13 14:24:24 +0200113# endif
Simon Glass50250b52013-03-11 14:30:42 +0000114 WATCHDOG_RESET();
115
116 return 0;
117}
118
119int init_func_watchdog_reset(void)
120{
121 WATCHDOG_RESET();
122
123 return 0;
124}
125#endif /* CONFIG_WATCHDOG */
126
Jeroen Hofstee45846052014-10-08 22:57:22 +0200127__weak void board_add_ram_info(int use_default)
Simon Glass50250b52013-03-11 14:30:42 +0000128{
129 /* please define platform specific board_add_ram_info() */
130}
131
Simon Glassc45e3592013-03-11 06:49:53 +0000132static int init_baud_rate(void)
133{
134 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
135 return 0;
136}
137
138static int display_text_info(void)
139{
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600140#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100141 ulong bss_start, bss_end, text_base;
Simon Glassc45e3592013-03-11 06:49:53 +0000142
Simon Glass9c9f44a2013-03-11 07:06:48 +0000143 bss_start = (ulong)&__bss_start;
144 bss_end = (ulong)&__bss_end;
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100145
Sonic Zhangf503a522014-07-17 19:01:34 +0800146#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100147 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800148#else
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100149 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800150#endif
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100151
152 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
153 text_base, bss_start, bss_end);
Simon Glass62cf9122013-04-26 02:53:43 +0000154#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000155
Simon Glassc45e3592013-03-11 06:49:53 +0000156#ifdef CONFIG_USE_IRQ
157 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
158 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
159#endif
160
161 return 0;
162}
163
164static int announce_dram_init(void)
165{
166 puts("DRAM: ");
167 return 0;
168}
169
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100170#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000171static int init_func_ram(void)
172{
Simon Glass39f90ba2017-03-31 08:40:25 -0600173 return initdram();
Simon Glass50250b52013-03-11 14:30:42 +0000174}
175#endif
176
Simon Glassc45e3592013-03-11 06:49:53 +0000177static int show_dram_config(void)
178{
York Sun60ac15a2014-05-02 17:28:05 -0700179 unsigned long long size;
Simon Glassc45e3592013-03-11 06:49:53 +0000180
181#ifdef CONFIG_NR_DRAM_BANKS
182 int i;
183
184 debug("\nRAM Configuration:\n");
185 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
186 size += gd->bd->bi_dram[i].size;
Bin Mengc8964482015-08-06 01:31:20 -0700187 debug("Bank #%d: %llx ", i,
188 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glassc45e3592013-03-11 06:49:53 +0000189#ifdef DEBUG
190 print_size(gd->bd->bi_dram[i].size, "\n");
191#endif
192 }
193 debug("\nDRAM: ");
194#else
195 size = gd->ram_size;
196#endif
197
Simon Glass50250b52013-03-11 14:30:42 +0000198 print_size(size, "");
199 board_add_ram_info(0);
200 putc('\n');
Simon Glassc45e3592013-03-11 06:49:53 +0000201
202 return 0;
203}
204
Simon Glass2f949c32017-03-31 08:40:32 -0600205__weak int dram_init_banksize(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000206{
207#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
208 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
209 gd->bd->bi_dram[0].size = get_effective_memsize();
210#endif
Simon Glass2f949c32017-03-31 08:40:32 -0600211
212 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000213}
214
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100215#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000216static int init_func_i2c(void)
217{
218 puts("I2C: ");
trema6612902013-09-21 18:13:34 +0200219#ifdef CONFIG_SYS_I2C
220 i2c_init_all();
221#else
Simon Glass50250b52013-03-11 14:30:42 +0000222 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trema6612902013-09-21 18:13:34 +0200223#endif
Simon Glass50250b52013-03-11 14:30:42 +0000224 puts("ready\n");
225 return 0;
226}
227#endif
228
229#if defined(CONFIG_HARD_SPI)
230static int init_func_spi(void)
231{
232 puts("SPI: ");
233 spi_init();
234 puts("ready\n");
235 return 0;
236}
237#endif
238
239__maybe_unused
Simon Glassc45e3592013-03-11 06:49:53 +0000240static int zero_global_data(void)
241{
242 memset((void *)gd, '\0', sizeof(gd_t));
243
244 return 0;
245}
246
247static int setup_mon_len(void)
248{
Michal Simek65e915c2014-05-08 16:08:44 +0200249#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100250 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600251#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glass62cf9122013-04-26 02:53:43 +0000252 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Rini210ebce2017-03-14 11:08:10 -0400253#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800254 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200255#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800256 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass90632bd2016-05-14 18:49:28 -0600257#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glass50250b52013-03-11 14:30:42 +0000258 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
259 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000260#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000261 return 0;
262}
263
264__weak int arch_cpu_init(void)
265{
266 return 0;
267}
268
Paul Burton1f508dd2016-09-21 11:18:46 +0100269__weak int mach_cpu_init(void)
270{
271 return 0;
272}
273
Simon Glassc45e3592013-03-11 06:49:53 +0000274/* Get the top of usable RAM */
275__weak ulong board_get_usable_ram_top(ulong total_size)
276{
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700277#ifdef CONFIG_SYS_SDRAM_BASE
278 /*
Simon Glass839855c2015-04-28 20:25:03 -0600279 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700280 * 32-bit address space. If so, clip the usable RAM so it doesn't.
281 */
282 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
283 /*
284 * Will wrap back to top of 32-bit space when reservations
285 * are made.
286 */
287 return 0;
288#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000289 return gd->ram_top;
290}
291
292static int setup_dest_addr(void)
293{
294 debug("Monitor len: %08lX\n", gd->mon_len);
295 /*
296 * Ram is setup, size stored in gd !!
297 */
298 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun4de24ef2017-03-06 09:02:28 -0800299#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glassc45e3592013-03-11 06:49:53 +0000300 /*
301 * Subtract specified amount of memory to hide so that it won't
302 * get "touched" at all by U-Boot. By fixing up gd->ram_size
303 * the Linux kernel should now get passed the now "corrected"
York Sun4de24ef2017-03-06 09:02:28 -0800304 * memory size and won't touch it either. This should work
305 * for arch/ppc and arch/powerpc. Only Linux board ports in
306 * arch/powerpc with bootwrapper support, that recalculate the
307 * memory size from the SDRAM controller setup will have to
308 * get fixed.
Simon Glassc45e3592013-03-11 06:49:53 +0000309 */
York Sun4de24ef2017-03-06 09:02:28 -0800310 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
311#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000312#ifdef CONFIG_SYS_SDRAM_BASE
313 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
314#endif
Simon Glass50250b52013-03-11 14:30:42 +0000315 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000316 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000317 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000318 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700319#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000320 /*
321 * We need to make sure the location we intend to put secondary core
322 * boot code is reserved and not used by any part of u-boot
323 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000324 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
325 gd->relocaddr = determine_mp_bootpg(NULL);
326 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000327 }
328#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000329 return 0;
330}
331
Simon Glassbcf257d2017-03-31 08:40:28 -0600332#if defined(CONFIG_LOGBUFFER)
Simon Glassc45e3592013-03-11 06:49:53 +0000333static int reserve_logbuffer(void)
334{
Simon Glassbcf257d2017-03-31 08:40:28 -0600335#ifndef CONFIG_ALT_LB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000336 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000337 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000338 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000339 gd->relocaddr);
Simon Glassbcf257d2017-03-31 08:40:28 -0600340#endif
341
Simon Glassc45e3592013-03-11 06:49:53 +0000342 return 0;
343}
344#endif
345
346#ifdef CONFIG_PRAM
347/* reserve protected RAM */
348static int reserve_pram(void)
349{
350 ulong reg;
351
352 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000353 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000354 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000355 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000356 return 0;
357}
358#endif /* CONFIG_PRAM */
359
360/* Round memory pointer down to next 4 kB limit */
361static int reserve_round_4k(void)
362{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000363 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000364 return 0;
365}
366
Simon Glasse3cb4492017-03-31 08:40:29 -0600367#ifdef CONFIG_ARM
Simon Glassc45e3592013-03-11 06:49:53 +0000368static int reserve_mmu(void)
369{
Simon Glasse3cb4492017-03-31 08:40:29 -0600370#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glassc45e3592013-03-11 06:49:53 +0000371 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800372 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000373 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000374
375 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000376 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000377
Masahiro Yamadad1589242013-05-27 00:37:30 +0000378 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000379 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
380 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sunf84f81e2016-06-24 16:46:19 -0700381
382#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
383 /*
384 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
385 * with location within secure ram.
386 */
387 gd->arch.tlb_allocated = gd->arch.tlb_addr;
388#endif
Simon Glasse3cb4492017-03-31 08:40:29 -0600389#endif
York Sunf84f81e2016-06-24 16:46:19 -0700390
Simon Glassc45e3592013-03-11 06:49:53 +0000391 return 0;
392}
393#endif
394
Simon Glassfce58f52016-01-18 19:52:21 -0700395static int reserve_video(void)
396{
Simon Glass70ac86c2017-03-31 08:40:30 -0600397#ifdef CONFIG_DM_VIDEO
Simon Glassfce58f52016-01-18 19:52:21 -0700398 ulong addr;
399 int ret;
400
401 addr = gd->relocaddr;
402 ret = video_reserve(&addr);
403 if (ret)
404 return ret;
405 gd->relocaddr = addr;
Simon Glass70ac86c2017-03-31 08:40:30 -0600406#elif defined(CONFIG_LCD)
Simon Glassfce58f52016-01-18 19:52:21 -0700407# ifdef CONFIG_FB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000408 gd->fb_base = CONFIG_FB_ADDR;
Simon Glassfce58f52016-01-18 19:52:21 -0700409# else
Simon Glassc45e3592013-03-11 06:49:53 +0000410 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000411 gd->relocaddr = lcd_setmem(gd->relocaddr);
412 gd->fb_base = gd->relocaddr;
Simon Glassfce58f52016-01-18 19:52:21 -0700413# endif /* CONFIG_FB_ADDR */
Simon Glass70ac86c2017-03-31 08:40:30 -0600414#elif defined(CONFIG_VIDEO) && \
415 (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800416 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Rini210ebce2017-03-14 11:08:10 -0400417 !defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000418 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000419 gd->relocaddr = video_setmem(gd->relocaddr);
420 gd->fb_base = gd->relocaddr;
Simon Glass70ac86c2017-03-31 08:40:30 -0600421#endif
Simon Glass50250b52013-03-11 14:30:42 +0000422
423 return 0;
424}
Simon Glass50250b52013-03-11 14:30:42 +0000425
Simon Glass1008da02016-01-18 19:52:20 -0700426static int reserve_trace(void)
427{
428#ifdef CONFIG_TRACE
429 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
430 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
431 debug("Reserving %dk for trace data at: %08lx\n",
432 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
433#endif
434
435 return 0;
436}
437
Simon Glassc45e3592013-03-11 06:49:53 +0000438static int reserve_uboot(void)
439{
440 /*
441 * reserve memory for U-Boot code, data & bss
442 * round down to next 4 kB limit
443 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000444 gd->relocaddr -= gd->mon_len;
445 gd->relocaddr &= ~(4096 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000446#ifdef CONFIG_E500
447 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000448 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000449#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000450
451 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000452 gd->relocaddr);
453
454 gd->start_addr_sp = gd->relocaddr;
455
Simon Glassc45e3592013-03-11 06:49:53 +0000456 return 0;
457}
458
459/* reserve memory for malloc() area */
460static int reserve_malloc(void)
461{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000462 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000463 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000464 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000465 return 0;
466}
467
468/* (permanently) allocate a Board Info struct */
469static int reserve_board(void)
470{
Sonic Zhangf503a522014-07-17 19:01:34 +0800471 if (!gd->bd) {
472 gd->start_addr_sp -= sizeof(bd_t);
473 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
474 memset(gd->bd, '\0', sizeof(bd_t));
475 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
476 sizeof(bd_t), gd->start_addr_sp);
477 }
Simon Glassc45e3592013-03-11 06:49:53 +0000478 return 0;
479}
480
481static int setup_machine(void)
482{
483#ifdef CONFIG_MACH_TYPE
484 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
485#endif
486 return 0;
487}
488
489static int reserve_global_data(void)
490{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000491 gd->start_addr_sp -= sizeof(gd_t);
492 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000493 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000494 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000495 return 0;
496}
497
498static int reserve_fdt(void)
499{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100500#ifndef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000501 /*
Simon Glass839855c2015-04-28 20:25:03 -0600502 * If the device tree is sitting immediately above our image then we
Simon Glassc45e3592013-03-11 06:49:53 +0000503 * must relocate it. If it is embedded in the data section, then it
504 * will be relocated with other data.
505 */
506 if (gd->fdt_blob) {
507 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
508
Masahiro Yamadad1589242013-05-27 00:37:30 +0000509 gd->start_addr_sp -= gd->fdt_size;
510 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000511 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000512 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000513 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100514#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000515
516 return 0;
517}
518
Andreas Bießmann25429862015-02-06 23:06:45 +0100519int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000520{
Andreas Bießmann25429862015-02-06 23:06:45 +0100521 return 0;
522}
Simon Glass4d2aee82013-03-05 14:39:45 +0000523
Andreas Bießmann25429862015-02-06 23:06:45 +0100524static int reserve_stacks(void)
525{
526 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000527 gd->start_addr_sp -= 16;
528 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000529
530 /*
Simon Glass839855c2015-04-28 20:25:03 -0600531 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann25429862015-02-06 23:06:45 +0100532 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000533 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100534 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000535}
536
537static int display_new_sp(void)
538{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000539 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000540
541 return 0;
542}
543
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200544#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
545 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000546static int setup_board_part1(void)
547{
548 bd_t *bd = gd->bd;
549
550 /*
551 * Save local variables to board info struct
552 */
Simon Glass50250b52013-03-11 14:30:42 +0000553 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
554 bd->bi_memsize = gd->ram_size; /* size in bytes */
555
556#ifdef CONFIG_SYS_SRAM_BASE
557 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
558 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
559#endif
560
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900561#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glass50250b52013-03-11 14:30:42 +0000562 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
563 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
564#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100565#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000566 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
567#endif
568#if defined(CONFIG_MPC83xx)
569 bd->bi_immrbar = CONFIG_SYS_IMMR;
570#endif
Simon Glass50250b52013-03-11 14:30:42 +0000571
572 return 0;
573}
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100574#endif
Simon Glass50250b52013-03-11 14:30:42 +0000575
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100576#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000577static int setup_board_part2(void)
578{
579 bd_t *bd = gd->bd;
580
581 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
582 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
583#if defined(CONFIG_CPM2)
584 bd->bi_cpmfreq = gd->arch.cpm_clk;
585 bd->bi_brgfreq = gd->arch.brg_clk;
586 bd->bi_sccfreq = gd->arch.scc_clk;
587 bd->bi_vco = gd->arch.vco_out;
588#endif /* CONFIG_CPM2 */
589#if defined(CONFIG_MPC512X)
590 bd->bi_ipsfreq = gd->arch.ips_clk;
591#endif /* CONFIG_MPC512X */
592#if defined(CONFIG_MPC5xxx)
593 bd->bi_ipbfreq = gd->arch.ipb_clk;
594 bd->bi_pcifreq = gd->pci_clk;
595#endif /* CONFIG_MPC5xxx */
Alison Wang8f6d8f32015-02-12 18:33:15 +0800596#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
597 bd->bi_pcifreq = gd->pci_clk;
598#endif
599#if defined(CONFIG_EXTRA_CLOCK)
600 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
601 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
602 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
603#endif
Simon Glass50250b52013-03-11 14:30:42 +0000604
605 return 0;
606}
607#endif
608
Simon Glassc45e3592013-03-11 06:49:53 +0000609#ifdef CONFIG_POST
610static int init_post(void)
611{
612 post_bootmode_init();
613 post_run(NULL, POST_ROM | post_bootmode_get(0));
614
615 return 0;
616}
617#endif
618
Simon Glassc45e3592013-03-11 06:49:53 +0000619static int reloc_fdt(void)
620{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100621#ifndef CONFIG_OF_EMBED
Simon Glass00dd17a2015-08-04 12:33:39 -0600622 if (gd->flags & GD_FLG_SKIP_RELOC)
623 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000624 if (gd->new_fdt) {
625 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
626 gd->fdt_blob = gd->new_fdt;
627 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100628#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000629
630 return 0;
631}
632
633static int setup_reloc(void)
634{
Simon Glass00dd17a2015-08-04 12:33:39 -0600635 if (gd->flags & GD_FLG_SKIP_RELOC) {
636 debug("Skipping relocation due to flag\n");
637 return 0;
638 }
639
Sonic Zhangf503a522014-07-17 19:01:34 +0800640#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadad1589242013-05-27 00:37:30 +0000641 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100642#ifdef CONFIG_M68K
643 /*
644 * On all ColdFire arch cpu, monitor code starts always
645 * just after the default vector table location, so at 0x400
646 */
647 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
648#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800649#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000650 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
651
652 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000653 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000654 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
655 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000656
657 return 0;
658}
659
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100660#ifdef CONFIG_OF_BOARD_FIXUP
661static int fix_fdt(void)
662{
663 return board_fix_fdt((void *)gd->fdt_blob);
664}
665#endif
666
Simon Glassc45e3592013-03-11 06:49:53 +0000667/* ARM calls relocate_code from its crt0.S */
Simon Glass6e1a81a2017-01-16 07:03:49 -0700668#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
669 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000670
671static int jump_to_copy(void)
672{
Simon Glass00dd17a2015-08-04 12:33:39 -0600673 if (gd->flags & GD_FLG_SKIP_RELOC)
674 return 0;
Simon Glass6d179872013-03-05 14:39:52 +0000675 /*
676 * x86 is special, but in a nice way. It uses a trampoline which
677 * enables the dcache if possible.
678 *
679 * For now, other archs use relocate_code(), which is implemented
680 * similarly for all archs. When we do generic relocation, hopefully
681 * we can make all archs enable the dcache prior to relocation.
682 */
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300683#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000684 /*
685 * SDRAM and console are now initialised. The final stack can now
686 * be setup in SDRAM. Code execution will continue in Flash, but
687 * with the stack in SDRAM and Global Data in temporary memory
688 * (CPU cache)
689 */
Simon Glass0e27b872015-08-10 20:44:32 -0600690 arch_setup_gd(gd->new_gd);
Simon Glass6d179872013-03-05 14:39:52 +0000691 board_init_f_r_trampoline(gd->start_addr_sp);
692#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000693 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000694#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000695
696 return 0;
697}
698#endif
699
700/* Record the board_init_f() bootstage (after arch_cpu_init()) */
701static int mark_bootstage(void)
702{
703 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
704
705 return 0;
706}
707
Simon Glass1bb49232015-11-08 23:47:48 -0700708static int initf_console_record(void)
709{
710#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
711 return console_record_init();
712#else
713 return 0;
714#endif
715}
716
Simon Glassa730c5d2014-07-23 06:55:04 -0600717static int initf_dm(void)
718{
719#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
720 int ret;
721
722 ret = dm_init_and_scan(true);
723 if (ret)
724 return ret;
725#endif
Simon Glass8e4f80f2016-02-24 09:14:50 -0700726#ifdef CONFIG_TIMER_EARLY
727 ret = dm_timer_init();
728 if (ret)
729 return ret;
730#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600731
732 return 0;
733}
734
Simon Glass5ded7e52015-01-19 22:16:12 -0700735/* Architecture-specific memory reservation */
736__weak int reserve_arch(void)
737{
738 return 0;
739}
740
Simon Glass7af8d052015-03-05 12:25:16 -0700741__weak int arch_cpu_init_dm(void)
742{
743 return 0;
744}
745
Simon Glass2031fad2017-01-16 07:03:50 -0700746static const init_fnc_t init_sequence_f[] = {
Simon Glassc45e3592013-03-11 06:49:53 +0000747 setup_mon_len,
Simon Glass26b78b22015-02-27 22:06:34 -0700748#ifdef CONFIG_OF_CONTROL
Simon Glassa0877672015-02-27 22:06:35 -0700749 fdtdec_setup,
Simon Glass26b78b22015-02-27 22:06:34 -0700750#endif
Kevin Hilman676f0192014-12-09 15:03:58 -0800751#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700752 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800753#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700754 initf_malloc,
Simon Glass1bb49232015-11-08 23:47:48 -0700755 initf_console_record,
Simon Glass295c4232017-03-28 10:27:18 -0600756#if defined(CONFIG_HAVE_FSP)
757 arch_fsp_init,
Bin Meng178f8972015-08-20 06:40:18 -0700758#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000759 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton1f508dd2016-09-21 11:18:46 +0100760 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass6df5de22014-09-03 17:36:59 -0600761 initf_dm,
Simon Glass7af8d052015-03-05 12:25:16 -0700762 arch_cpu_init_dm,
Thomas Chouc2fbaa22015-10-30 15:35:51 +0800763 mark_bootstage, /* need timer, go after init dm */
Simon Glassc45e3592013-03-11 06:49:53 +0000764#if defined(CONFIG_BOARD_EARLY_INIT_F)
765 board_early_init_f,
766#endif
Simon Glass6829d8c2017-03-28 10:27:26 -0600767#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glass70064a72017-03-28 10:27:19 -0600768 /* get CPU and bus clocks according to the environment variable */
Simon Glass50250b52013-03-11 14:30:42 +0000769 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glasse8d20d42017-03-28 10:27:23 -0600770#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000771 timer_init, /* initialize timer */
Simon Glass50250b52013-03-11 14:30:42 +0000772#if defined(CONFIG_BOARD_POSTCLK_INIT)
773 board_postclk_init,
774#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000775 env_init, /* initialize environment */
776 init_baud_rate, /* initialze baudrate settings */
777 serial_init, /* serial communications setup */
778 console_init_f, /* stage 1 init of console */
779 display_options, /* say that we are here */
780 display_text_info, /* show debugging info if required */
Simon Glassee7c36f2017-03-28 10:27:30 -0600781#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
782 defined(CONFIG_X86)
Simon Glass50250b52013-03-11 14:30:42 +0000783 checkcpu,
784#endif
Simon Glass68c1d012017-01-23 13:31:25 -0700785#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glassc45e3592013-03-11 06:49:53 +0000786 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass68c1d012017-01-23 13:31:25 -0700787#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000788#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900789 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000790#endif
Simon Glass50250b52013-03-11 14:30:42 +0000791 INIT_FUNC_WATCHDOG_INIT
792#if defined(CONFIG_MISC_INIT_F)
793 misc_init_f,
794#endif
795 INIT_FUNC_WATCHDOG_RESET
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100796#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000797 init_func_i2c,
798#endif
799#if defined(CONFIG_HARD_SPI)
800 init_func_spi,
801#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000802 announce_dram_init,
803 /* TODO: unify all these dram functions? */
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800804#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200805 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
806 defined(CONFIG_SH)
Simon Glassc45e3592013-03-11 06:49:53 +0000807 dram_init, /* configure available RAM banks */
808#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100809#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000810 init_func_ram,
811#endif
812#ifdef CONFIG_POST
813 post_init_f,
814#endif
815 INIT_FUNC_WATCHDOG_RESET
816#if defined(CONFIG_SYS_DRAM_TEST)
817 testdram,
818#endif /* CONFIG_SYS_DRAM_TEST */
819 INIT_FUNC_WATCHDOG_RESET
820
Simon Glassc45e3592013-03-11 06:49:53 +0000821#ifdef CONFIG_POST
822 init_post,
823#endif
Simon Glass50250b52013-03-11 14:30:42 +0000824 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000825 /*
826 * Now that we have DRAM mapped and working, we can
827 * relocate the code and continue running from DRAM.
828 *
829 * Reserve memory at end of RAM for (top down in that order):
830 * - area that won't get touched by U-Boot and Linux (optional)
831 * - kernel log buffer
832 * - protected RAM
833 * - LCD framebuffer
834 * - monitor code
835 * - board info struct
836 */
837 setup_dest_addr,
Simon Glassbcf257d2017-03-31 08:40:28 -0600838#if defined(CONFIG_LOGBUFFER)
Simon Glassc45e3592013-03-11 06:49:53 +0000839 reserve_logbuffer,
840#endif
841#ifdef CONFIG_PRAM
842 reserve_pram,
843#endif
844 reserve_round_4k,
Simon Glasse3cb4492017-03-31 08:40:29 -0600845#ifdef CONFIG_ARM
Simon Glassc45e3592013-03-11 06:49:53 +0000846 reserve_mmu,
847#endif
Simon Glassfce58f52016-01-18 19:52:21 -0700848 reserve_video,
Simon Glass1008da02016-01-18 19:52:20 -0700849 reserve_trace,
Simon Glassc45e3592013-03-11 06:49:53 +0000850 reserve_uboot,
851 reserve_malloc,
852 reserve_board,
Simon Glassc45e3592013-03-11 06:49:53 +0000853 setup_machine,
854 reserve_global_data,
855 reserve_fdt,
Simon Glass5ded7e52015-01-19 22:16:12 -0700856 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +0000857 reserve_stacks,
Simon Glass2f949c32017-03-31 08:40:32 -0600858 dram_init_banksize,
Simon Glassc45e3592013-03-11 06:49:53 +0000859 show_dram_config,
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200860#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
861 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000862 setup_board_part1,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100863#endif
864#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000865 INIT_FUNC_WATCHDOG_RESET
866 setup_board_part2,
867#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000868 display_new_sp,
Simon Glass50250b52013-03-11 14:30:42 +0000869#ifdef CONFIG_SYS_EXTBDINFO
870 setup_board_extra,
871#endif
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100872#ifdef CONFIG_OF_BOARD_FIXUP
873 fix_fdt,
874#endif
Simon Glass50250b52013-03-11 14:30:42 +0000875 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000876 reloc_fdt,
877 setup_reloc,
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300878#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glassd50b2f42015-01-01 16:18:09 -0700879 copy_uboot_to_ram,
Simon Glassd50b2f42015-01-01 16:18:09 -0700880 do_elf_reloc_fixups,
Simon Glass2a7bf772017-01-16 07:03:52 -0700881 clear_bss,
Simon Glassd50b2f42015-01-01 16:18:09 -0700882#endif
Chris Zankel41e37372016-08-10 18:36:43 +0300883#if defined(CONFIG_XTENSA)
884 clear_bss,
885#endif
Simon Glass6e1a81a2017-01-16 07:03:49 -0700886#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
887 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000888 jump_to_copy,
889#endif
890 NULL,
891};
892
893void board_init_f(ulong boot_flags)
894{
York Sun021d2022014-05-02 17:28:04 -0700895#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
896 /*
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -0400897 * For some architectures, global data is initialized and used before
York Sun021d2022014-05-02 17:28:04 -0700898 * calling this function. The data should be preserved. For others,
899 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
900 * here to host global data until relocation.
901 */
Simon Glassc45e3592013-03-11 06:49:53 +0000902 gd_t data;
903
904 gd = &data;
905
David Feng1735de82013-12-14 11:47:36 +0800906 /*
907 * Clear global data before it is accessed at debug print
908 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -0400909 * get the wrong value of gd->have_console.
David Feng1735de82013-12-14 11:47:36 +0800910 */
David Feng1735de82013-12-14 11:47:36 +0800911 zero_global_data();
912#endif
913
Simon Glassc45e3592013-03-11 06:49:53 +0000914 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +0400915 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000916
917 if (initcall_run_list(init_sequence_f))
918 hang();
919
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600920#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass6e1a81a2017-01-16 07:03:49 -0700921 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000922 /* NOTREACHED - jump_to_copy() does not return */
923 hang();
924#endif
925}
Simon Glass6d179872013-03-05 14:39:52 +0000926
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300927#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000928/*
929 * For now this code is only used on x86.
930 *
931 * init_sequence_f_r is the list of init functions which are run when
932 * U-Boot is executing from Flash with a semi-limited 'C' environment.
933 * The following limitations must be considered when implementing an
934 * '_f_r' function:
935 * - 'static' variables are read-only
936 * - Global Data (gd->xxx) is read/write
937 *
938 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
939 * supported). It _should_, if possible, copy global data to RAM and
940 * initialise the CPU caches (to speed up the relocation process)
941 *
942 * NOTE: At present only x86 uses this route, but it is intended that
943 * all archs will move to this when generic relocation is implemented.
944 */
Simon Glass2031fad2017-01-16 07:03:50 -0700945static const init_fnc_t init_sequence_f_r[] = {
Simon Glass6e1a81a2017-01-16 07:03:49 -0700946#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass6d179872013-03-05 14:39:52 +0000947 init_cache_f_r,
Simon Glass6e1a81a2017-01-16 07:03:49 -0700948#endif
Simon Glass6d179872013-03-05 14:39:52 +0000949
950 NULL,
951};
952
953void board_init_f_r(void)
954{
955 if (initcall_run_list(init_sequence_f_r))
956 hang();
957
958 /*
Simon Glass51f73f12016-03-11 22:06:51 -0700959 * The pre-relocation drivers may be using memory that has now gone
960 * away. Mark serial as unavailable - this will fall back to the debug
961 * UART if available.
962 */
963 gd->flags &= ~GD_FLG_SERIAL_READY;
964
965 /*
Simon Glass6d179872013-03-05 14:39:52 +0000966 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
967 * Transfer execution from Flash to RAM by calculating the address
968 * of the in-RAM copy of board_init_r() and calling it
969 */
Alexey Brodkin9c832f12015-02-25 17:59:02 +0300970 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000971
972 /* NOTREACHED - board_init_r() does not return */
973 hang();
974}
Alexey Brodkin73503182015-03-24 11:12:47 +0300975#endif /* CONFIG_X86 */