blob: 224ba09803f159afc1055199a766884dc2624ad3 [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>
14#include <linux/compiler.h>
15#include <version.h>
Simon Glassa73bda42015-11-08 23:47:45 -070016#include <console.h>
Simon Glassc45e3592013-03-11 06:49:53 +000017#include <environment.h>
Simon Glassa730c5d2014-07-23 06:55:04 -060018#include <dm.h>
Simon Glassc45e3592013-03-11 06:49:53 +000019#include <fdtdec.h>
Simon Glass15393432013-04-20 08:42:41 +000020#include <fs.h>
Simon Glass50250b52013-03-11 14:30:42 +000021#if defined(CONFIG_CMD_IDE)
22#include <ide.h>
23#endif
24#include <i2c.h>
Simon Glassc45e3592013-03-11 06:49:53 +000025#include <initcall.h>
26#include <logbuff.h>
Simon Glassd1d087d2015-02-27 22:06:36 -070027#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050028#include <mapmem.h>
Simon Glass50250b52013-03-11 14:30:42 +000029
30/* TODO: Can we move these into arch/ headers? */
31#ifdef CONFIG_8xx
32#include <mpc8xx.h>
33#endif
34#ifdef CONFIG_5xx
35#include <mpc5xx.h>
36#endif
37#ifdef CONFIG_MPC5xxx
38#include <mpc5xxx.h>
39#endif
Gabriel Huauda0afc22014-09-03 13:57:54 -070040#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huau170ceaf2014-07-26 11:35:43 -070041#include <asm/mp.h>
42#endif
Simon Glass50250b52013-03-11 14:30:42 +000043
Simon Glass62cf9122013-04-26 02:53:43 +000044#include <os.h>
Simon Glassc45e3592013-03-11 06:49:53 +000045#include <post.h>
Simon Glass50250b52013-03-11 14:30:42 +000046#include <spi.h>
Jeroen Hofsteea802b982014-06-23 23:20:19 +020047#include <status_led.h>
Simon Glass8e4f80f2016-02-24 09:14:50 -070048#include <timer.h>
Simon Glass209a1a62013-06-11 11:14:42 -070049#include <trace.h>
Simon Glassfce58f52016-01-18 19:52:21 -070050#include <video.h>
Simon Glass50250b52013-03-11 14:30:42 +000051#include <watchdog.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090052#include <linux/errno.h>
Simon Glassc45e3592013-03-11 06:49:53 +000053#include <asm/io.h>
54#include <asm/sections.h>
Alexey Brodkin913e9f02015-02-24 19:40:36 +030055#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +000056#include <asm/init_helpers.h>
Chris Zankel41e37372016-08-10 18:36:43 +030057#endif
58#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
Simon Glass6d179872013-03-05 14:39:52 +000059#include <asm/relocate.h>
60#endif
Simon Glass62cf9122013-04-26 02:53:43 +000061#ifdef CONFIG_SANDBOX
62#include <asm/state.h>
63#endif
Simon Glassa730c5d2014-07-23 06:55:04 -060064#include <dm/root.h>
Simon Glassc45e3592013-03-11 06:49:53 +000065#include <linux/compiler.h>
66
67/*
68 * Pointer to initial global data area
69 *
70 * Here we initialize it if needed.
71 */
72#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
73#undef XTRN_DECLARE_GLOBAL_DATA_PTR
74#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
75DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
76#else
77DECLARE_GLOBAL_DATA_PTR;
78#endif
79
80/*
Simon Glass839855c2015-04-28 20:25:03 -060081 * TODO(sjg@chromium.org): IMO this code should be
Simon Glassc45e3592013-03-11 06:49:53 +000082 * refactored to a single function, something like:
83 *
84 * void led_set_state(enum led_colour_t colour, int on);
85 */
86/************************************************************************
87 * Coloured LED functionality
88 ************************************************************************
89 * May be supplied by boards if desired
90 */
Jeroen Hofsteea802b982014-06-23 23:20:19 +020091__weak void coloured_LED_init(void) {}
92__weak void red_led_on(void) {}
93__weak void red_led_off(void) {}
94__weak void green_led_on(void) {}
95__weak void green_led_off(void) {}
96__weak void yellow_led_on(void) {}
97__weak void yellow_led_off(void) {}
98__weak void blue_led_on(void) {}
99__weak void blue_led_off(void) {}
Simon Glassc45e3592013-03-11 06:49:53 +0000100
101/*
102 * Why is gd allocated a register? Prior to reloc it might be better to
103 * just pass it around to each function in this file?
104 *
105 * After reloc one could argue that it is hardly used and doesn't need
106 * to be in a register. Or if it is it should perhaps hold pointers to all
107 * global data for all modules, so that post-reloc we can avoid the massive
108 * literal pool we get on ARM. Or perhaps just encourage each module to use
109 * a structure...
110 */
111
112/*
113 * Could the CONFIG_SPL_BUILD infection become a flag in gd?
114 */
115
Sonic Zhangf503a522014-07-17 19:01:34 +0800116#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glass50250b52013-03-11 14:30:42 +0000117static int init_func_watchdog_init(void)
118{
Tom Rini210ebce2017-03-14 11:08:10 -0400119# if defined(CONFIG_HW_WATCHDOG) && \
120 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100121 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin87db2942016-06-13 14:24:23 +0200122 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100123 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangf503a522014-07-17 19:01:34 +0800124 hw_watchdog_init();
Simon Glass50250b52013-03-11 14:30:42 +0000125 puts(" Watchdog enabled\n");
Anatolij Gustschind3aa98a2016-06-13 14:24:24 +0200126# endif
Simon Glass50250b52013-03-11 14:30:42 +0000127 WATCHDOG_RESET();
128
129 return 0;
130}
131
132int init_func_watchdog_reset(void)
133{
134 WATCHDOG_RESET();
135
136 return 0;
137}
138#endif /* CONFIG_WATCHDOG */
139
Jeroen Hofstee45846052014-10-08 22:57:22 +0200140__weak void board_add_ram_info(int use_default)
Simon Glass50250b52013-03-11 14:30:42 +0000141{
142 /* please define platform specific board_add_ram_info() */
143}
144
Simon Glassc45e3592013-03-11 06:49:53 +0000145static int init_baud_rate(void)
146{
147 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
148 return 0;
149}
150
151static int display_text_info(void)
152{
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600153#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100154 ulong bss_start, bss_end, text_base;
Simon Glassc45e3592013-03-11 06:49:53 +0000155
Simon Glass9c9f44a2013-03-11 07:06:48 +0000156 bss_start = (ulong)&__bss_start;
157 bss_end = (ulong)&__bss_end;
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100158
Sonic Zhangf503a522014-07-17 19:01:34 +0800159#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100160 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800161#else
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100162 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800163#endif
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100164
165 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
166 text_base, bss_start, bss_end);
Simon Glass62cf9122013-04-26 02:53:43 +0000167#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000168
Simon Glassc45e3592013-03-11 06:49:53 +0000169#ifdef CONFIG_USE_IRQ
170 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
171 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
172#endif
173
174 return 0;
175}
176
177static int announce_dram_init(void)
178{
179 puts("DRAM: ");
180 return 0;
181}
182
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100183#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000184static int init_func_ram(void)
185{
186#ifdef CONFIG_BOARD_TYPES
187 int board_type = gd->board_type;
188#else
189 int board_type = 0; /* use dummy arg */
190#endif
191
192 gd->ram_size = initdram(board_type);
193
194 if (gd->ram_size > 0)
195 return 0;
196
197 puts("*** failed ***\n");
198 return 1;
199}
200#endif
201
Simon Glassc45e3592013-03-11 06:49:53 +0000202static int show_dram_config(void)
203{
York Sun60ac15a2014-05-02 17:28:05 -0700204 unsigned long long size;
Simon Glassc45e3592013-03-11 06:49:53 +0000205
206#ifdef CONFIG_NR_DRAM_BANKS
207 int i;
208
209 debug("\nRAM Configuration:\n");
210 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
211 size += gd->bd->bi_dram[i].size;
Bin Mengc8964482015-08-06 01:31:20 -0700212 debug("Bank #%d: %llx ", i,
213 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glassc45e3592013-03-11 06:49:53 +0000214#ifdef DEBUG
215 print_size(gd->bd->bi_dram[i].size, "\n");
216#endif
217 }
218 debug("\nDRAM: ");
219#else
220 size = gd->ram_size;
221#endif
222
Simon Glass50250b52013-03-11 14:30:42 +0000223 print_size(size, "");
224 board_add_ram_info(0);
225 putc('\n');
Simon Glassc45e3592013-03-11 06:49:53 +0000226
227 return 0;
228}
229
Jeroen Hofstee45846052014-10-08 22:57:22 +0200230__weak void dram_init_banksize(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000231{
232#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
233 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
234 gd->bd->bi_dram[0].size = get_effective_memsize();
235#endif
236}
237
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100238#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000239static int init_func_i2c(void)
240{
241 puts("I2C: ");
trema6612902013-09-21 18:13:34 +0200242#ifdef CONFIG_SYS_I2C
243 i2c_init_all();
244#else
Simon Glass50250b52013-03-11 14:30:42 +0000245 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trema6612902013-09-21 18:13:34 +0200246#endif
Simon Glass50250b52013-03-11 14:30:42 +0000247 puts("ready\n");
248 return 0;
249}
250#endif
251
252#if defined(CONFIG_HARD_SPI)
253static int init_func_spi(void)
254{
255 puts("SPI: ");
256 spi_init();
257 puts("ready\n");
258 return 0;
259}
260#endif
261
262__maybe_unused
Simon Glassc45e3592013-03-11 06:49:53 +0000263static int zero_global_data(void)
264{
265 memset((void *)gd, '\0', sizeof(gd_t));
266
267 return 0;
268}
269
270static int setup_mon_len(void)
271{
Michal Simek65e915c2014-05-08 16:08:44 +0200272#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100273 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600274#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glass62cf9122013-04-26 02:53:43 +0000275 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Rini210ebce2017-03-14 11:08:10 -0400276#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800277 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200278#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800279 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass90632bd2016-05-14 18:49:28 -0600280#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glass50250b52013-03-11 14:30:42 +0000281 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
282 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000283#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000284 return 0;
285}
286
287__weak int arch_cpu_init(void)
288{
289 return 0;
290}
291
Paul Burton1f508dd2016-09-21 11:18:46 +0100292__weak int mach_cpu_init(void)
293{
294 return 0;
295}
296
Simon Glass62cf9122013-04-26 02:53:43 +0000297#ifdef CONFIG_SANDBOX
298static int setup_ram_buf(void)
299{
Simon Glass9dd10bf2013-11-10 10:27:03 -0700300 struct sandbox_state *state = state_get_current();
301
302 gd->arch.ram_buf = state->ram_buf;
303 gd->ram_size = state->ram_size;
Simon Glass62cf9122013-04-26 02:53:43 +0000304
305 return 0;
306}
307#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000308
309/* Get the top of usable RAM */
310__weak ulong board_get_usable_ram_top(ulong total_size)
311{
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700312#ifdef CONFIG_SYS_SDRAM_BASE
313 /*
Simon Glass839855c2015-04-28 20:25:03 -0600314 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700315 * 32-bit address space. If so, clip the usable RAM so it doesn't.
316 */
317 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
318 /*
319 * Will wrap back to top of 32-bit space when reservations
320 * are made.
321 */
322 return 0;
323#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000324 return gd->ram_top;
325}
326
327static int setup_dest_addr(void)
328{
329 debug("Monitor len: %08lX\n", gd->mon_len);
330 /*
331 * Ram is setup, size stored in gd !!
332 */
333 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun4de24ef2017-03-06 09:02:28 -0800334#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glassc45e3592013-03-11 06:49:53 +0000335 /*
336 * Subtract specified amount of memory to hide so that it won't
337 * get "touched" at all by U-Boot. By fixing up gd->ram_size
338 * the Linux kernel should now get passed the now "corrected"
York Sun4de24ef2017-03-06 09:02:28 -0800339 * memory size and won't touch it either. This should work
340 * for arch/ppc and arch/powerpc. Only Linux board ports in
341 * arch/powerpc with bootwrapper support, that recalculate the
342 * memory size from the SDRAM controller setup will have to
343 * get fixed.
Simon Glassc45e3592013-03-11 06:49:53 +0000344 */
York Sun4de24ef2017-03-06 09:02:28 -0800345 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
346#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000347#ifdef CONFIG_SYS_SDRAM_BASE
348 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
349#endif
Simon Glass50250b52013-03-11 14:30:42 +0000350 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000351 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000352 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000353 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700354#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000355 /*
356 * We need to make sure the location we intend to put secondary core
357 * boot code is reserved and not used by any part of u-boot
358 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000359 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
360 gd->relocaddr = determine_mp_bootpg(NULL);
361 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000362 }
363#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000364 return 0;
365}
366
Francois Retieffc7784e2015-11-23 13:05:44 +0200367#if defined(CONFIG_SPARC)
368static int reserve_prom(void)
369{
370 /* defined in arch/sparc/cpu/leon?/prom.c */
371 extern void *__prom_start_reloc;
372 int size = 8192; /* page table = 2k, prom = 6k */
373 gd->relocaddr -= size;
374 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
375 debug("Reserving %dk for PROM and page table at %08lx\n", size,
376 gd->relocaddr);
377 return 0;
378}
379#endif
380
Simon Glassc45e3592013-03-11 06:49:53 +0000381#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
382static int reserve_logbuffer(void)
383{
384 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000385 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000386 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000387 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000388 return 0;
389}
390#endif
391
392#ifdef CONFIG_PRAM
393/* reserve protected RAM */
394static int reserve_pram(void)
395{
396 ulong reg;
397
398 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000399 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000400 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000401 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000402 return 0;
403}
404#endif /* CONFIG_PRAM */
405
406/* Round memory pointer down to next 4 kB limit */
407static int reserve_round_4k(void)
408{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000409 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000410 return 0;
411}
412
413#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
414 defined(CONFIG_ARM)
415static int reserve_mmu(void)
416{
417 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800418 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000419 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000420
421 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000422 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000423
Masahiro Yamadad1589242013-05-27 00:37:30 +0000424 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000425 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
426 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sunf84f81e2016-06-24 16:46:19 -0700427
428#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
429 /*
430 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
431 * with location within secure ram.
432 */
433 gd->arch.tlb_allocated = gd->arch.tlb_addr;
434#endif
435
Simon Glassc45e3592013-03-11 06:49:53 +0000436 return 0;
437}
438#endif
439
Simon Glassfce58f52016-01-18 19:52:21 -0700440#ifdef CONFIG_DM_VIDEO
441static int reserve_video(void)
442{
443 ulong addr;
444 int ret;
445
446 addr = gd->relocaddr;
447 ret = video_reserve(&addr);
448 if (ret)
449 return ret;
450 gd->relocaddr = addr;
451
452 return 0;
453}
454#else
455
456# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000457static int reserve_lcd(void)
458{
Simon Glassfce58f52016-01-18 19:52:21 -0700459# ifdef CONFIG_FB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000460 gd->fb_base = CONFIG_FB_ADDR;
Simon Glassfce58f52016-01-18 19:52:21 -0700461# else
Simon Glassc45e3592013-03-11 06:49:53 +0000462 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000463 gd->relocaddr = lcd_setmem(gd->relocaddr);
464 gd->fb_base = gd->relocaddr;
Simon Glassfce58f52016-01-18 19:52:21 -0700465# endif /* CONFIG_FB_ADDR */
466
Simon Glassc45e3592013-03-11 06:49:53 +0000467 return 0;
468}
Simon Glassfce58f52016-01-18 19:52:21 -0700469# endif /* CONFIG_LCD */
Simon Glassc45e3592013-03-11 06:49:53 +0000470
Simon Glassfce58f52016-01-18 19:52:21 -0700471# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800472 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Rini210ebce2017-03-14 11:08:10 -0400473 !defined(CONFIG_M68K)
Simon Glass1008da02016-01-18 19:52:20 -0700474static int reserve_legacy_video(void)
Simon Glass50250b52013-03-11 14:30:42 +0000475{
476 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000477 gd->relocaddr = video_setmem(gd->relocaddr);
478 gd->fb_base = gd->relocaddr;
Simon Glass50250b52013-03-11 14:30:42 +0000479
480 return 0;
481}
Simon Glassfce58f52016-01-18 19:52:21 -0700482# endif
483#endif /* !CONFIG_DM_VIDEO */
Simon Glass50250b52013-03-11 14:30:42 +0000484
Simon Glass1008da02016-01-18 19:52:20 -0700485static int reserve_trace(void)
486{
487#ifdef CONFIG_TRACE
488 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
489 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
490 debug("Reserving %dk for trace data at: %08lx\n",
491 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
492#endif
493
494 return 0;
495}
496
Simon Glassc45e3592013-03-11 06:49:53 +0000497static int reserve_uboot(void)
498{
499 /*
500 * reserve memory for U-Boot code, data & bss
501 * round down to next 4 kB limit
502 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000503 gd->relocaddr -= gd->mon_len;
504 gd->relocaddr &= ~(4096 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000505#ifdef CONFIG_E500
506 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000507 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000508#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000509
510 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000511 gd->relocaddr);
512
513 gd->start_addr_sp = gd->relocaddr;
514
Simon Glassc45e3592013-03-11 06:49:53 +0000515 return 0;
516}
517
Simon Glass4d2aee82013-03-05 14:39:45 +0000518#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000519/* reserve memory for malloc() area */
520static int reserve_malloc(void)
521{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000522 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000523 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000524 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000525 return 0;
526}
527
528/* (permanently) allocate a Board Info struct */
529static int reserve_board(void)
530{
Sonic Zhangf503a522014-07-17 19:01:34 +0800531 if (!gd->bd) {
532 gd->start_addr_sp -= sizeof(bd_t);
533 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
534 memset(gd->bd, '\0', sizeof(bd_t));
535 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
536 sizeof(bd_t), gd->start_addr_sp);
537 }
Simon Glassc45e3592013-03-11 06:49:53 +0000538 return 0;
539}
Simon Glass4d2aee82013-03-05 14:39:45 +0000540#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000541
542static int setup_machine(void)
543{
544#ifdef CONFIG_MACH_TYPE
545 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
546#endif
547 return 0;
548}
549
550static int reserve_global_data(void)
551{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000552 gd->start_addr_sp -= sizeof(gd_t);
553 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000554 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000555 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000556 return 0;
557}
558
559static int reserve_fdt(void)
560{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100561#ifndef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000562 /*
Simon Glass839855c2015-04-28 20:25:03 -0600563 * If the device tree is sitting immediately above our image then we
Simon Glassc45e3592013-03-11 06:49:53 +0000564 * must relocate it. If it is embedded in the data section, then it
565 * will be relocated with other data.
566 */
567 if (gd->fdt_blob) {
568 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
569
Masahiro Yamadad1589242013-05-27 00:37:30 +0000570 gd->start_addr_sp -= gd->fdt_size;
571 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000572 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000573 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000574 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100575#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000576
577 return 0;
578}
579
Andreas Bießmann25429862015-02-06 23:06:45 +0100580int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000581{
Andreas Bießmann25429862015-02-06 23:06:45 +0100582 return 0;
583}
Simon Glass4d2aee82013-03-05 14:39:45 +0000584
Andreas Bießmann25429862015-02-06 23:06:45 +0100585static int reserve_stacks(void)
586{
587 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000588 gd->start_addr_sp -= 16;
589 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000590
591 /*
Simon Glass839855c2015-04-28 20:25:03 -0600592 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann25429862015-02-06 23:06:45 +0100593 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000594 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100595 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000596}
597
598static int display_new_sp(void)
599{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000600 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000601
602 return 0;
603}
604
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200605#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
606 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000607static int setup_board_part1(void)
608{
609 bd_t *bd = gd->bd;
610
611 /*
612 * Save local variables to board info struct
613 */
Simon Glass50250b52013-03-11 14:30:42 +0000614 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
615 bd->bi_memsize = gd->ram_size; /* size in bytes */
616
617#ifdef CONFIG_SYS_SRAM_BASE
618 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
619 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
620#endif
621
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900622#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glass50250b52013-03-11 14:30:42 +0000623 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
624 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
625#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100626#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000627 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
628#endif
629#if defined(CONFIG_MPC83xx)
630 bd->bi_immrbar = CONFIG_SYS_IMMR;
631#endif
Simon Glass50250b52013-03-11 14:30:42 +0000632
633 return 0;
634}
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100635#endif
Simon Glass50250b52013-03-11 14:30:42 +0000636
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100637#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000638static int setup_board_part2(void)
639{
640 bd_t *bd = gd->bd;
641
642 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
643 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
644#if defined(CONFIG_CPM2)
645 bd->bi_cpmfreq = gd->arch.cpm_clk;
646 bd->bi_brgfreq = gd->arch.brg_clk;
647 bd->bi_sccfreq = gd->arch.scc_clk;
648 bd->bi_vco = gd->arch.vco_out;
649#endif /* CONFIG_CPM2 */
650#if defined(CONFIG_MPC512X)
651 bd->bi_ipsfreq = gd->arch.ips_clk;
652#endif /* CONFIG_MPC512X */
653#if defined(CONFIG_MPC5xxx)
654 bd->bi_ipbfreq = gd->arch.ipb_clk;
655 bd->bi_pcifreq = gd->pci_clk;
656#endif /* CONFIG_MPC5xxx */
Alison Wang8f6d8f32015-02-12 18:33:15 +0800657#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
658 bd->bi_pcifreq = gd->pci_clk;
659#endif
660#if defined(CONFIG_EXTRA_CLOCK)
661 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
662 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
663 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
664#endif
Simon Glass50250b52013-03-11 14:30:42 +0000665
666 return 0;
667}
668#endif
669
670#ifdef CONFIG_SYS_EXTBDINFO
671static int setup_board_extra(void)
672{
673 bd_t *bd = gd->bd;
674
675 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
676 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
677 sizeof(bd->bi_r_version));
678
679 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
680 bd->bi_plb_busfreq = gd->bus_clk;
681#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
682 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
683 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
684 bd->bi_pci_busfreq = get_PCI_freq();
685 bd->bi_opbfreq = get_OPB_freq();
686#elif defined(CONFIG_XILINX_405)
687 bd->bi_pci_busfreq = get_PCI_freq();
688#endif
689
690 return 0;
691}
692#endif
693
Simon Glassc45e3592013-03-11 06:49:53 +0000694#ifdef CONFIG_POST
695static int init_post(void)
696{
697 post_bootmode_init();
698 post_run(NULL, POST_ROM | post_bootmode_get(0));
699
700 return 0;
701}
702#endif
703
Simon Glassc45e3592013-03-11 06:49:53 +0000704static int setup_dram_config(void)
705{
706 /* Ram is board specific, so move it to board code ... */
707 dram_init_banksize();
708
709 return 0;
710}
711
712static int reloc_fdt(void)
713{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100714#ifndef CONFIG_OF_EMBED
Simon Glass00dd17a2015-08-04 12:33:39 -0600715 if (gd->flags & GD_FLG_SKIP_RELOC)
716 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000717 if (gd->new_fdt) {
718 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
719 gd->fdt_blob = gd->new_fdt;
720 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100721#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000722
723 return 0;
724}
725
726static int setup_reloc(void)
727{
Simon Glass00dd17a2015-08-04 12:33:39 -0600728 if (gd->flags & GD_FLG_SKIP_RELOC) {
729 debug("Skipping relocation due to flag\n");
730 return 0;
731 }
732
Sonic Zhangf503a522014-07-17 19:01:34 +0800733#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadad1589242013-05-27 00:37:30 +0000734 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100735#ifdef CONFIG_M68K
736 /*
737 * On all ColdFire arch cpu, monitor code starts always
738 * just after the default vector table location, so at 0x400
739 */
740 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
741#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800742#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000743 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
744
745 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000746 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000747 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
748 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000749
750 return 0;
751}
752
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100753#ifdef CONFIG_OF_BOARD_FIXUP
754static int fix_fdt(void)
755{
756 return board_fix_fdt((void *)gd->fdt_blob);
757}
758#endif
759
Simon Glassc45e3592013-03-11 06:49:53 +0000760/* ARM calls relocate_code from its crt0.S */
Simon Glass6e1a81a2017-01-16 07:03:49 -0700761#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
762 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000763
764static int jump_to_copy(void)
765{
Simon Glass00dd17a2015-08-04 12:33:39 -0600766 if (gd->flags & GD_FLG_SKIP_RELOC)
767 return 0;
Simon Glass6d179872013-03-05 14:39:52 +0000768 /*
769 * x86 is special, but in a nice way. It uses a trampoline which
770 * enables the dcache if possible.
771 *
772 * For now, other archs use relocate_code(), which is implemented
773 * similarly for all archs. When we do generic relocation, hopefully
774 * we can make all archs enable the dcache prior to relocation.
775 */
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300776#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000777 /*
778 * SDRAM and console are now initialised. The final stack can now
779 * be setup in SDRAM. Code execution will continue in Flash, but
780 * with the stack in SDRAM and Global Data in temporary memory
781 * (CPU cache)
782 */
Simon Glass0e27b872015-08-10 20:44:32 -0600783 arch_setup_gd(gd->new_gd);
Simon Glass6d179872013-03-05 14:39:52 +0000784 board_init_f_r_trampoline(gd->start_addr_sp);
785#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000786 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000787#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000788
789 return 0;
790}
791#endif
792
793/* Record the board_init_f() bootstage (after arch_cpu_init()) */
794static int mark_bootstage(void)
795{
796 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
797
798 return 0;
799}
800
Simon Glass1bb49232015-11-08 23:47:48 -0700801static int initf_console_record(void)
802{
803#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
804 return console_record_init();
805#else
806 return 0;
807#endif
808}
809
Simon Glassa730c5d2014-07-23 06:55:04 -0600810static int initf_dm(void)
811{
812#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
813 int ret;
814
815 ret = dm_init_and_scan(true);
816 if (ret)
817 return ret;
818#endif
Simon Glass8e4f80f2016-02-24 09:14:50 -0700819#ifdef CONFIG_TIMER_EARLY
820 ret = dm_timer_init();
821 if (ret)
822 return ret;
823#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600824
825 return 0;
826}
827
Simon Glass5ded7e52015-01-19 22:16:12 -0700828/* Architecture-specific memory reservation */
829__weak int reserve_arch(void)
830{
831 return 0;
832}
833
Simon Glass7af8d052015-03-05 12:25:16 -0700834__weak int arch_cpu_init_dm(void)
835{
836 return 0;
837}
838
Simon Glass2031fad2017-01-16 07:03:50 -0700839static const init_fnc_t init_sequence_f[] = {
Simon Glass62cf9122013-04-26 02:53:43 +0000840#ifdef CONFIG_SANDBOX
841 setup_ram_buf,
842#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000843 setup_mon_len,
Simon Glass26b78b22015-02-27 22:06:34 -0700844#ifdef CONFIG_OF_CONTROL
Simon Glassa0877672015-02-27 22:06:35 -0700845 fdtdec_setup,
Simon Glass26b78b22015-02-27 22:06:34 -0700846#endif
Kevin Hilman676f0192014-12-09 15:03:58 -0800847#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700848 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800849#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700850 initf_malloc,
Simon Glass1bb49232015-11-08 23:47:48 -0700851 initf_console_record,
Bin Meng178f8972015-08-20 06:40:18 -0700852#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
853 x86_fsp_init,
854#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000855 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton1f508dd2016-09-21 11:18:46 +0100856 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass6df5de22014-09-03 17:36:59 -0600857 initf_dm,
Simon Glass7af8d052015-03-05 12:25:16 -0700858 arch_cpu_init_dm,
Thomas Chouc2fbaa22015-10-30 15:35:51 +0800859 mark_bootstage, /* need timer, go after init dm */
Simon Glassc45e3592013-03-11 06:49:53 +0000860#if defined(CONFIG_BOARD_EARLY_INIT_F)
861 board_early_init_f,
862#endif
Simon Glass50250b52013-03-11 14:30:42 +0000863 /* TODO: can any of this go into arch_cpu_init()? */
864#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
865 get_clocks, /* get CPU and bus clocks (etc.) */
866#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
867 && !defined(CONFIG_TQM885D)
868 adjust_sdram_tbs_8xx,
869#endif
870 /* TODO: can we rename this to timer_init()? */
871 init_timebase,
872#endif
Bin Meng31617642015-12-08 17:31:40 -0800873#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Tom Rini210ebce2017-03-14 11:08:10 -0400874 defined(CONFIG_NDS32) || defined(CONFIG_SH) || \
875 defined(CONFIG_SPARC)
Simon Glassc45e3592013-03-11 06:49:53 +0000876 timer_init, /* initialize timer */
Simon Glass50250b52013-03-11 14:30:42 +0000877#endif
Simon Glass50250b52013-03-11 14:30:42 +0000878#if defined(CONFIG_BOARD_POSTCLK_INIT)
879 board_postclk_init,
880#endif
Peng Fand7f18922015-10-30 17:30:02 +0800881#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100882 get_clocks,
883#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000884 env_init, /* initialize environment */
Simon Glass50250b52013-03-11 14:30:42 +0000885#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
886 /* get CPU and bus clocks according to the environment variable */
887 get_clocks_866,
888 /* adjust sdram refresh rate according to the new clock */
889 sdram_adjust_866,
890 init_timebase,
891#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000892 init_baud_rate, /* initialze baudrate settings */
893 serial_init, /* serial communications setup */
894 console_init_f, /* stage 1 init of console */
Simon Glass62cf9122013-04-26 02:53:43 +0000895#ifdef CONFIG_SANDBOX
896 sandbox_early_getopt_check,
897#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000898 display_options, /* say that we are here */
899 display_text_info, /* show debugging info if required */
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900900#if defined(CONFIG_MPC8260)
Simon Glass50250b52013-03-11 14:30:42 +0000901 prt_8260_rsr,
902 prt_8260_clks,
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900903#endif /* CONFIG_MPC8260 */
Simon Glass50250b52013-03-11 14:30:42 +0000904#if defined(CONFIG_MPC83xx)
905 prt_83xx_rsr,
906#endif
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200907#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000908 checkcpu,
909#endif
Simon Glass68c1d012017-01-23 13:31:25 -0700910#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glassc45e3592013-03-11 06:49:53 +0000911 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass68c1d012017-01-23 13:31:25 -0700912#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000913#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900914 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000915#endif
Simon Glass50250b52013-03-11 14:30:42 +0000916 INIT_FUNC_WATCHDOG_INIT
917#if defined(CONFIG_MISC_INIT_F)
918 misc_init_f,
919#endif
920 INIT_FUNC_WATCHDOG_RESET
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100921#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000922 init_func_i2c,
923#endif
924#if defined(CONFIG_HARD_SPI)
925 init_func_spi,
926#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000927 announce_dram_init,
928 /* TODO: unify all these dram functions? */
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800929#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200930 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
931 defined(CONFIG_SH)
Simon Glassc45e3592013-03-11 06:49:53 +0000932 dram_init, /* configure available RAM banks */
933#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100934#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000935 init_func_ram,
936#endif
937#ifdef CONFIG_POST
938 post_init_f,
939#endif
940 INIT_FUNC_WATCHDOG_RESET
941#if defined(CONFIG_SYS_DRAM_TEST)
942 testdram,
943#endif /* CONFIG_SYS_DRAM_TEST */
944 INIT_FUNC_WATCHDOG_RESET
945
Simon Glassc45e3592013-03-11 06:49:53 +0000946#ifdef CONFIG_POST
947 init_post,
948#endif
Simon Glass50250b52013-03-11 14:30:42 +0000949 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000950 /*
951 * Now that we have DRAM mapped and working, we can
952 * relocate the code and continue running from DRAM.
953 *
954 * Reserve memory at end of RAM for (top down in that order):
955 * - area that won't get touched by U-Boot and Linux (optional)
956 * - kernel log buffer
957 * - protected RAM
958 * - LCD framebuffer
959 * - monitor code
960 * - board info struct
961 */
962 setup_dest_addr,
Tom Rini210ebce2017-03-14 11:08:10 -0400963#if defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800964 /* Blackfin u-boot monitor should be on top of the ram */
965 reserve_uboot,
966#endif
Francois Retieffc7784e2015-11-23 13:05:44 +0200967#if defined(CONFIG_SPARC)
968 reserve_prom,
969#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000970#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
971 reserve_logbuffer,
972#endif
973#ifdef CONFIG_PRAM
974 reserve_pram,
975#endif
976 reserve_round_4k,
977#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
978 defined(CONFIG_ARM)
979 reserve_mmu,
980#endif
Simon Glassfce58f52016-01-18 19:52:21 -0700981#ifdef CONFIG_DM_VIDEO
982 reserve_video,
983#else
984# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000985 reserve_lcd,
Simon Glassfce58f52016-01-18 19:52:21 -0700986# endif
Simon Glass50250b52013-03-11 14:30:42 +0000987 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glassfce58f52016-01-18 19:52:21 -0700988# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800989 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Rini210ebce2017-03-14 11:08:10 -0400990 !defined(CONFIG_M68K)
Simon Glassfce58f52016-01-18 19:52:21 -0700991 reserve_legacy_video,
992# endif
993#endif /* CONFIG_DM_VIDEO */
Simon Glass1008da02016-01-18 19:52:20 -0700994 reserve_trace,
Tom Rini210ebce2017-03-14 11:08:10 -0400995#if !defined(CONFIG_XTENSA)
Simon Glassc45e3592013-03-11 06:49:53 +0000996 reserve_uboot,
Sonic Zhangf503a522014-07-17 19:01:34 +0800997#endif
Simon Glass4d2aee82013-03-05 14:39:45 +0000998#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000999 reserve_malloc,
1000 reserve_board,
Simon Glass4d2aee82013-03-05 14:39:45 +00001001#endif
Simon Glassc45e3592013-03-11 06:49:53 +00001002 setup_machine,
1003 reserve_global_data,
1004 reserve_fdt,
Simon Glass5ded7e52015-01-19 22:16:12 -07001005 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +00001006 reserve_stacks,
1007 setup_dram_config,
1008 show_dram_config,
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +02001009#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
1010 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +00001011 setup_board_part1,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +01001012#endif
1013#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +00001014 INIT_FUNC_WATCHDOG_RESET
1015 setup_board_part2,
1016#endif
Simon Glassc45e3592013-03-11 06:49:53 +00001017 display_new_sp,
Simon Glass50250b52013-03-11 14:30:42 +00001018#ifdef CONFIG_SYS_EXTBDINFO
1019 setup_board_extra,
1020#endif
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +01001021#ifdef CONFIG_OF_BOARD_FIXUP
1022 fix_fdt,
1023#endif
Simon Glass50250b52013-03-11 14:30:42 +00001024 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +00001025 reloc_fdt,
1026 setup_reloc,
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001027#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glassd50b2f42015-01-01 16:18:09 -07001028 copy_uboot_to_ram,
Simon Glassd50b2f42015-01-01 16:18:09 -07001029 do_elf_reloc_fixups,
Simon Glass2a7bf772017-01-16 07:03:52 -07001030 clear_bss,
Simon Glassd50b2f42015-01-01 16:18:09 -07001031#endif
Chris Zankel41e37372016-08-10 18:36:43 +03001032#if defined(CONFIG_XTENSA)
1033 clear_bss,
1034#endif
Simon Glass6e1a81a2017-01-16 07:03:49 -07001035#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1036 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +00001037 jump_to_copy,
1038#endif
1039 NULL,
1040};
1041
1042void board_init_f(ulong boot_flags)
1043{
York Sun021d2022014-05-02 17:28:04 -07001044#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1045 /*
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -04001046 * For some architectures, global data is initialized and used before
York Sun021d2022014-05-02 17:28:04 -07001047 * calling this function. The data should be preserved. For others,
1048 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1049 * here to host global data until relocation.
1050 */
Simon Glassc45e3592013-03-11 06:49:53 +00001051 gd_t data;
1052
1053 gd = &data;
1054
David Feng1735de82013-12-14 11:47:36 +08001055 /*
1056 * Clear global data before it is accessed at debug print
1057 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -04001058 * get the wrong value of gd->have_console.
David Feng1735de82013-12-14 11:47:36 +08001059 */
David Feng1735de82013-12-14 11:47:36 +08001060 zero_global_data();
1061#endif
1062
Simon Glassc45e3592013-03-11 06:49:53 +00001063 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +04001064 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +00001065
1066 if (initcall_run_list(init_sequence_f))
1067 hang();
1068
Ben Stoltz1930e8d2015-07-31 09:31:37 -06001069#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass6e1a81a2017-01-16 07:03:49 -07001070 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +00001071 /* NOTREACHED - jump_to_copy() does not return */
1072 hang();
1073#endif
1074}
Simon Glass6d179872013-03-05 14:39:52 +00001075
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001076#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +00001077/*
1078 * For now this code is only used on x86.
1079 *
1080 * init_sequence_f_r is the list of init functions which are run when
1081 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1082 * The following limitations must be considered when implementing an
1083 * '_f_r' function:
1084 * - 'static' variables are read-only
1085 * - Global Data (gd->xxx) is read/write
1086 *
1087 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1088 * supported). It _should_, if possible, copy global data to RAM and
1089 * initialise the CPU caches (to speed up the relocation process)
1090 *
1091 * NOTE: At present only x86 uses this route, but it is intended that
1092 * all archs will move to this when generic relocation is implemented.
1093 */
Simon Glass2031fad2017-01-16 07:03:50 -07001094static const init_fnc_t init_sequence_f_r[] = {
Simon Glass6e1a81a2017-01-16 07:03:49 -07001095#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass6d179872013-03-05 14:39:52 +00001096 init_cache_f_r,
Simon Glass6e1a81a2017-01-16 07:03:49 -07001097#endif
Simon Glass6d179872013-03-05 14:39:52 +00001098
1099 NULL,
1100};
1101
1102void board_init_f_r(void)
1103{
1104 if (initcall_run_list(init_sequence_f_r))
1105 hang();
1106
1107 /*
Simon Glass51f73f12016-03-11 22:06:51 -07001108 * The pre-relocation drivers may be using memory that has now gone
1109 * away. Mark serial as unavailable - this will fall back to the debug
1110 * UART if available.
1111 */
1112 gd->flags &= ~GD_FLG_SERIAL_READY;
1113
1114 /*
Simon Glass6d179872013-03-05 14:39:52 +00001115 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1116 * Transfer execution from Flash to RAM by calculating the address
1117 * of the in-RAM copy of board_init_r() and calling it
1118 */
Alexey Brodkin9c832f12015-02-25 17:59:02 +03001119 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +00001120
1121 /* NOTREACHED - board_init_r() does not return */
1122 hang();
1123}
Alexey Brodkin73503182015-03-24 11:12:47 +03001124#endif /* CONFIG_X86 */