blob: bb24a633fb74750654cbb5baa3d1c1b47fcff22c [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{
Sonic Zhangf503a522014-07-17 19:01:34 +0800119# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
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;
Chris Zankel41e37372016-08-10 18:36:43 +0300276#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2) || \
277 defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800278 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200279#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800280 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass90632bd2016-05-14 18:49:28 -0600281#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glass50250b52013-03-11 14:30:42 +0000282 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
283 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000284#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000285 return 0;
286}
287
288__weak int arch_cpu_init(void)
289{
290 return 0;
291}
292
Paul Burton1f508dd2016-09-21 11:18:46 +0100293__weak int mach_cpu_init(void)
294{
295 return 0;
296}
297
Simon Glass62cf9122013-04-26 02:53:43 +0000298#ifdef CONFIG_SANDBOX
299static int setup_ram_buf(void)
300{
Simon Glass9dd10bf2013-11-10 10:27:03 -0700301 struct sandbox_state *state = state_get_current();
302
303 gd->arch.ram_buf = state->ram_buf;
304 gd->ram_size = state->ram_size;
Simon Glass62cf9122013-04-26 02:53:43 +0000305
306 return 0;
307}
308#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000309
310/* Get the top of usable RAM */
311__weak ulong board_get_usable_ram_top(ulong total_size)
312{
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700313#ifdef CONFIG_SYS_SDRAM_BASE
314 /*
Simon Glass839855c2015-04-28 20:25:03 -0600315 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700316 * 32-bit address space. If so, clip the usable RAM so it doesn't.
317 */
318 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
319 /*
320 * Will wrap back to top of 32-bit space when reservations
321 * are made.
322 */
323 return 0;
324#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000325 return gd->ram_top;
326}
327
328static int setup_dest_addr(void)
329{
330 debug("Monitor len: %08lX\n", gd->mon_len);
331 /*
332 * Ram is setup, size stored in gd !!
333 */
334 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun4de24ef2017-03-06 09:02:28 -0800335#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glassc45e3592013-03-11 06:49:53 +0000336 /*
337 * Subtract specified amount of memory to hide so that it won't
338 * get "touched" at all by U-Boot. By fixing up gd->ram_size
339 * the Linux kernel should now get passed the now "corrected"
York Sun4de24ef2017-03-06 09:02:28 -0800340 * memory size and won't touch it either. This should work
341 * for arch/ppc and arch/powerpc. Only Linux board ports in
342 * arch/powerpc with bootwrapper support, that recalculate the
343 * memory size from the SDRAM controller setup will have to
344 * get fixed.
Simon Glassc45e3592013-03-11 06:49:53 +0000345 */
York Sun4de24ef2017-03-06 09:02:28 -0800346 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
347#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000348#ifdef CONFIG_SYS_SDRAM_BASE
349 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
350#endif
Simon Glass50250b52013-03-11 14:30:42 +0000351 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000352 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000353 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000354 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700355#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000356 /*
357 * We need to make sure the location we intend to put secondary core
358 * boot code is reserved and not used by any part of u-boot
359 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000360 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
361 gd->relocaddr = determine_mp_bootpg(NULL);
362 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000363 }
364#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000365 return 0;
366}
367
Francois Retieffc7784e2015-11-23 13:05:44 +0200368#if defined(CONFIG_SPARC)
369static int reserve_prom(void)
370{
371 /* defined in arch/sparc/cpu/leon?/prom.c */
372 extern void *__prom_start_reloc;
373 int size = 8192; /* page table = 2k, prom = 6k */
374 gd->relocaddr -= size;
375 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
376 debug("Reserving %dk for PROM and page table at %08lx\n", size,
377 gd->relocaddr);
378 return 0;
379}
380#endif
381
Simon Glassc45e3592013-03-11 06:49:53 +0000382#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
383static int reserve_logbuffer(void)
384{
385 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000386 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000387 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000388 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000389 return 0;
390}
391#endif
392
393#ifdef CONFIG_PRAM
394/* reserve protected RAM */
395static int reserve_pram(void)
396{
397 ulong reg;
398
399 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000400 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000401 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000402 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000403 return 0;
404}
405#endif /* CONFIG_PRAM */
406
407/* Round memory pointer down to next 4 kB limit */
408static int reserve_round_4k(void)
409{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000410 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000411 return 0;
412}
413
414#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
415 defined(CONFIG_ARM)
416static int reserve_mmu(void)
417{
418 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800419 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000420 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000421
422 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000423 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000424
Masahiro Yamadad1589242013-05-27 00:37:30 +0000425 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000426 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
427 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sunf84f81e2016-06-24 16:46:19 -0700428
429#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
430 /*
431 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
432 * with location within secure ram.
433 */
434 gd->arch.tlb_allocated = gd->arch.tlb_addr;
435#endif
436
Simon Glassc45e3592013-03-11 06:49:53 +0000437 return 0;
438}
439#endif
440
Simon Glassfce58f52016-01-18 19:52:21 -0700441#ifdef CONFIG_DM_VIDEO
442static int reserve_video(void)
443{
444 ulong addr;
445 int ret;
446
447 addr = gd->relocaddr;
448 ret = video_reserve(&addr);
449 if (ret)
450 return ret;
451 gd->relocaddr = addr;
452
453 return 0;
454}
455#else
456
457# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000458static int reserve_lcd(void)
459{
Simon Glassfce58f52016-01-18 19:52:21 -0700460# ifdef CONFIG_FB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000461 gd->fb_base = CONFIG_FB_ADDR;
Simon Glassfce58f52016-01-18 19:52:21 -0700462# else
Simon Glassc45e3592013-03-11 06:49:53 +0000463 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000464 gd->relocaddr = lcd_setmem(gd->relocaddr);
465 gd->fb_base = gd->relocaddr;
Simon Glassfce58f52016-01-18 19:52:21 -0700466# endif /* CONFIG_FB_ADDR */
467
Simon Glassc45e3592013-03-11 06:49:53 +0000468 return 0;
469}
Simon Glassfce58f52016-01-18 19:52:21 -0700470# endif /* CONFIG_LCD */
Simon Glassc45e3592013-03-11 06:49:53 +0000471
Simon Glassfce58f52016-01-18 19:52:21 -0700472# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800473 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.ite23aed32015-03-28 11:34:52 +0100474 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass1008da02016-01-18 19:52:20 -0700475static int reserve_legacy_video(void)
Simon Glass50250b52013-03-11 14:30:42 +0000476{
477 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000478 gd->relocaddr = video_setmem(gd->relocaddr);
479 gd->fb_base = gd->relocaddr;
Simon Glass50250b52013-03-11 14:30:42 +0000480
481 return 0;
482}
Simon Glassfce58f52016-01-18 19:52:21 -0700483# endif
484#endif /* !CONFIG_DM_VIDEO */
Simon Glass50250b52013-03-11 14:30:42 +0000485
Simon Glass1008da02016-01-18 19:52:20 -0700486static int reserve_trace(void)
487{
488#ifdef CONFIG_TRACE
489 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
490 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
491 debug("Reserving %dk for trace data at: %08lx\n",
492 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
493#endif
494
495 return 0;
496}
497
Simon Glassc45e3592013-03-11 06:49:53 +0000498static int reserve_uboot(void)
499{
500 /*
501 * reserve memory for U-Boot code, data & bss
502 * round down to next 4 kB limit
503 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000504 gd->relocaddr -= gd->mon_len;
505 gd->relocaddr &= ~(4096 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000506#ifdef CONFIG_E500
507 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000508 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000509#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000510
511 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000512 gd->relocaddr);
513
514 gd->start_addr_sp = gd->relocaddr;
515
Simon Glassc45e3592013-03-11 06:49:53 +0000516 return 0;
517}
518
Simon Glass4d2aee82013-03-05 14:39:45 +0000519#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000520/* reserve memory for malloc() area */
521static int reserve_malloc(void)
522{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000523 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000524 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000525 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000526 return 0;
527}
528
529/* (permanently) allocate a Board Info struct */
530static int reserve_board(void)
531{
Sonic Zhangf503a522014-07-17 19:01:34 +0800532 if (!gd->bd) {
533 gd->start_addr_sp -= sizeof(bd_t);
534 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
535 memset(gd->bd, '\0', sizeof(bd_t));
536 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
537 sizeof(bd_t), gd->start_addr_sp);
538 }
Simon Glassc45e3592013-03-11 06:49:53 +0000539 return 0;
540}
Simon Glass4d2aee82013-03-05 14:39:45 +0000541#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000542
543static int setup_machine(void)
544{
545#ifdef CONFIG_MACH_TYPE
546 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
547#endif
548 return 0;
549}
550
551static int reserve_global_data(void)
552{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000553 gd->start_addr_sp -= sizeof(gd_t);
554 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000555 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000556 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000557 return 0;
558}
559
560static int reserve_fdt(void)
561{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100562#ifndef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000563 /*
Simon Glass839855c2015-04-28 20:25:03 -0600564 * If the device tree is sitting immediately above our image then we
Simon Glassc45e3592013-03-11 06:49:53 +0000565 * must relocate it. If it is embedded in the data section, then it
566 * will be relocated with other data.
567 */
568 if (gd->fdt_blob) {
569 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
570
Masahiro Yamadad1589242013-05-27 00:37:30 +0000571 gd->start_addr_sp -= gd->fdt_size;
572 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000573 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000574 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000575 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100576#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000577
578 return 0;
579}
580
Andreas Bießmann25429862015-02-06 23:06:45 +0100581int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000582{
Andreas Bießmann25429862015-02-06 23:06:45 +0100583 return 0;
584}
Simon Glass4d2aee82013-03-05 14:39:45 +0000585
Andreas Bießmann25429862015-02-06 23:06:45 +0100586static int reserve_stacks(void)
587{
588 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000589 gd->start_addr_sp -= 16;
590 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000591
592 /*
Simon Glass839855c2015-04-28 20:25:03 -0600593 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann25429862015-02-06 23:06:45 +0100594 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000595 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100596 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000597}
598
599static int display_new_sp(void)
600{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000601 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000602
603 return 0;
604}
605
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200606#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
607 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000608static int setup_board_part1(void)
609{
610 bd_t *bd = gd->bd;
611
612 /*
613 * Save local variables to board info struct
614 */
Simon Glass50250b52013-03-11 14:30:42 +0000615 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
616 bd->bi_memsize = gd->ram_size; /* size in bytes */
617
618#ifdef CONFIG_SYS_SRAM_BASE
619 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
620 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
621#endif
622
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900623#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glass50250b52013-03-11 14:30:42 +0000624 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
625 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
626#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100627#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000628 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
629#endif
630#if defined(CONFIG_MPC83xx)
631 bd->bi_immrbar = CONFIG_SYS_IMMR;
632#endif
Simon Glass50250b52013-03-11 14:30:42 +0000633
634 return 0;
635}
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100636#endif
Simon Glass50250b52013-03-11 14:30:42 +0000637
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100638#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000639static int setup_board_part2(void)
640{
641 bd_t *bd = gd->bd;
642
643 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
644 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
645#if defined(CONFIG_CPM2)
646 bd->bi_cpmfreq = gd->arch.cpm_clk;
647 bd->bi_brgfreq = gd->arch.brg_clk;
648 bd->bi_sccfreq = gd->arch.scc_clk;
649 bd->bi_vco = gd->arch.vco_out;
650#endif /* CONFIG_CPM2 */
651#if defined(CONFIG_MPC512X)
652 bd->bi_ipsfreq = gd->arch.ips_clk;
653#endif /* CONFIG_MPC512X */
654#if defined(CONFIG_MPC5xxx)
655 bd->bi_ipbfreq = gd->arch.ipb_clk;
656 bd->bi_pcifreq = gd->pci_clk;
657#endif /* CONFIG_MPC5xxx */
Alison Wang8f6d8f32015-02-12 18:33:15 +0800658#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
659 bd->bi_pcifreq = gd->pci_clk;
660#endif
661#if defined(CONFIG_EXTRA_CLOCK)
662 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
663 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
664 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
665#endif
Simon Glass50250b52013-03-11 14:30:42 +0000666
667 return 0;
668}
669#endif
670
671#ifdef CONFIG_SYS_EXTBDINFO
672static int setup_board_extra(void)
673{
674 bd_t *bd = gd->bd;
675
676 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
677 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
678 sizeof(bd->bi_r_version));
679
680 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
681 bd->bi_plb_busfreq = gd->bus_clk;
682#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
683 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
684 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
685 bd->bi_pci_busfreq = get_PCI_freq();
686 bd->bi_opbfreq = get_OPB_freq();
687#elif defined(CONFIG_XILINX_405)
688 bd->bi_pci_busfreq = get_PCI_freq();
689#endif
690
691 return 0;
692}
693#endif
694
Simon Glassc45e3592013-03-11 06:49:53 +0000695#ifdef CONFIG_POST
696static int init_post(void)
697{
698 post_bootmode_init();
699 post_run(NULL, POST_ROM | post_bootmode_get(0));
700
701 return 0;
702}
703#endif
704
Simon Glassc45e3592013-03-11 06:49:53 +0000705static int setup_dram_config(void)
706{
707 /* Ram is board specific, so move it to board code ... */
708 dram_init_banksize();
709
710 return 0;
711}
712
713static int reloc_fdt(void)
714{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100715#ifndef CONFIG_OF_EMBED
Simon Glass00dd17a2015-08-04 12:33:39 -0600716 if (gd->flags & GD_FLG_SKIP_RELOC)
717 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000718 if (gd->new_fdt) {
719 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
720 gd->fdt_blob = gd->new_fdt;
721 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100722#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000723
724 return 0;
725}
726
727static int setup_reloc(void)
728{
Simon Glass00dd17a2015-08-04 12:33:39 -0600729 if (gd->flags & GD_FLG_SKIP_RELOC) {
730 debug("Skipping relocation due to flag\n");
731 return 0;
732 }
733
Sonic Zhangf503a522014-07-17 19:01:34 +0800734#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadad1589242013-05-27 00:37:30 +0000735 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100736#ifdef CONFIG_M68K
737 /*
738 * On all ColdFire arch cpu, monitor code starts always
739 * just after the default vector table location, so at 0x400
740 */
741 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
742#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800743#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000744 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
745
746 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000747 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000748 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
749 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000750
751 return 0;
752}
753
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +0100754#ifdef CONFIG_OF_BOARD_FIXUP
755static int fix_fdt(void)
756{
757 return board_fix_fdt((void *)gd->fdt_blob);
758}
759#endif
760
Simon Glassc45e3592013-03-11 06:49:53 +0000761/* ARM calls relocate_code from its crt0.S */
Simon Glass6e1a81a2017-01-16 07:03:49 -0700762#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
763 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +0000764
765static int jump_to_copy(void)
766{
Simon Glass00dd17a2015-08-04 12:33:39 -0600767 if (gd->flags & GD_FLG_SKIP_RELOC)
768 return 0;
Simon Glass6d179872013-03-05 14:39:52 +0000769 /*
770 * x86 is special, but in a nice way. It uses a trampoline which
771 * enables the dcache if possible.
772 *
773 * For now, other archs use relocate_code(), which is implemented
774 * similarly for all archs. When we do generic relocation, hopefully
775 * we can make all archs enable the dcache prior to relocation.
776 */
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300777#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000778 /*
779 * SDRAM and console are now initialised. The final stack can now
780 * be setup in SDRAM. Code execution will continue in Flash, but
781 * with the stack in SDRAM and Global Data in temporary memory
782 * (CPU cache)
783 */
Simon Glass0e27b872015-08-10 20:44:32 -0600784 arch_setup_gd(gd->new_gd);
Simon Glass6d179872013-03-05 14:39:52 +0000785 board_init_f_r_trampoline(gd->start_addr_sp);
786#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000787 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000788#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000789
790 return 0;
791}
792#endif
793
794/* Record the board_init_f() bootstage (after arch_cpu_init()) */
795static int mark_bootstage(void)
796{
797 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
798
799 return 0;
800}
801
Simon Glass1bb49232015-11-08 23:47:48 -0700802static int initf_console_record(void)
803{
804#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
805 return console_record_init();
806#else
807 return 0;
808#endif
809}
810
Simon Glassa730c5d2014-07-23 06:55:04 -0600811static int initf_dm(void)
812{
813#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
814 int ret;
815
816 ret = dm_init_and_scan(true);
817 if (ret)
818 return ret;
819#endif
Simon Glass8e4f80f2016-02-24 09:14:50 -0700820#ifdef CONFIG_TIMER_EARLY
821 ret = dm_timer_init();
822 if (ret)
823 return ret;
824#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600825
826 return 0;
827}
828
Simon Glass5ded7e52015-01-19 22:16:12 -0700829/* Architecture-specific memory reservation */
830__weak int reserve_arch(void)
831{
832 return 0;
833}
834
Simon Glass7af8d052015-03-05 12:25:16 -0700835__weak int arch_cpu_init_dm(void)
836{
837 return 0;
838}
839
Simon Glass2031fad2017-01-16 07:03:50 -0700840static const init_fnc_t init_sequence_f[] = {
Simon Glass62cf9122013-04-26 02:53:43 +0000841#ifdef CONFIG_SANDBOX
842 setup_ram_buf,
843#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000844 setup_mon_len,
Simon Glass26b78b22015-02-27 22:06:34 -0700845#ifdef CONFIG_OF_CONTROL
Simon Glassa0877672015-02-27 22:06:35 -0700846 fdtdec_setup,
Simon Glass26b78b22015-02-27 22:06:34 -0700847#endif
Kevin Hilman676f0192014-12-09 15:03:58 -0800848#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700849 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800850#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700851 initf_malloc,
Simon Glass1bb49232015-11-08 23:47:48 -0700852 initf_console_record,
Bin Meng178f8972015-08-20 06:40:18 -0700853#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
854 x86_fsp_init,
855#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000856 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton1f508dd2016-09-21 11:18:46 +0100857 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass6df5de22014-09-03 17:36:59 -0600858 initf_dm,
Simon Glass7af8d052015-03-05 12:25:16 -0700859 arch_cpu_init_dm,
Thomas Chouc2fbaa22015-10-30 15:35:51 +0800860 mark_bootstage, /* need timer, go after init dm */
Simon Glassc45e3592013-03-11 06:49:53 +0000861#if defined(CONFIG_BOARD_EARLY_INIT_F)
862 board_early_init_f,
863#endif
Simon Glass50250b52013-03-11 14:30:42 +0000864 /* TODO: can any of this go into arch_cpu_init()? */
865#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
866 get_clocks, /* get CPU and bus clocks (etc.) */
867#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
868 && !defined(CONFIG_TQM885D)
869 adjust_sdram_tbs_8xx,
870#endif
871 /* TODO: can we rename this to timer_init()? */
872 init_timebase,
873#endif
Bin Meng31617642015-12-08 17:31:40 -0800874#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retief7d07d682015-10-28 15:18:22 +0200875 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200876 defined(CONFIG_SH) || defined(CONFIG_SPARC)
Simon Glassc45e3592013-03-11 06:49:53 +0000877 timer_init, /* initialize timer */
Simon Glass50250b52013-03-11 14:30:42 +0000878#endif
Simon Glass50250b52013-03-11 14:30:42 +0000879#if defined(CONFIG_BOARD_POSTCLK_INIT)
880 board_postclk_init,
881#endif
Peng Fand7f18922015-10-30 17:30:02 +0800882#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100883 get_clocks,
884#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000885 env_init, /* initialize environment */
Simon Glass50250b52013-03-11 14:30:42 +0000886#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
887 /* get CPU and bus clocks according to the environment variable */
888 get_clocks_866,
889 /* adjust sdram refresh rate according to the new clock */
890 sdram_adjust_866,
891 init_timebase,
892#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000893 init_baud_rate, /* initialze baudrate settings */
894 serial_init, /* serial communications setup */
895 console_init_f, /* stage 1 init of console */
Simon Glass62cf9122013-04-26 02:53:43 +0000896#ifdef CONFIG_SANDBOX
897 sandbox_early_getopt_check,
898#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000899 display_options, /* say that we are here */
900 display_text_info, /* show debugging info if required */
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900901#if defined(CONFIG_MPC8260)
Simon Glass50250b52013-03-11 14:30:42 +0000902 prt_8260_rsr,
903 prt_8260_clks,
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900904#endif /* CONFIG_MPC8260 */
Simon Glass50250b52013-03-11 14:30:42 +0000905#if defined(CONFIG_MPC83xx)
906 prt_83xx_rsr,
907#endif
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200908#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +0000909 checkcpu,
910#endif
Simon Glass68c1d012017-01-23 13:31:25 -0700911#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glassc45e3592013-03-11 06:49:53 +0000912 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass68c1d012017-01-23 13:31:25 -0700913#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000914#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900915 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000916#endif
Simon Glass50250b52013-03-11 14:30:42 +0000917 INIT_FUNC_WATCHDOG_INIT
918#if defined(CONFIG_MISC_INIT_F)
919 misc_init_f,
920#endif
921 INIT_FUNC_WATCHDOG_RESET
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100922#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000923 init_func_i2c,
924#endif
925#if defined(CONFIG_HARD_SPI)
926 init_func_spi,
927#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000928 announce_dram_init,
929 /* TODO: unify all these dram functions? */
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800930#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +0200931 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
932 defined(CONFIG_SH)
Simon Glassc45e3592013-03-11 06:49:53 +0000933 dram_init, /* configure available RAM banks */
934#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100935#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000936 init_func_ram,
937#endif
938#ifdef CONFIG_POST
939 post_init_f,
940#endif
941 INIT_FUNC_WATCHDOG_RESET
942#if defined(CONFIG_SYS_DRAM_TEST)
943 testdram,
944#endif /* CONFIG_SYS_DRAM_TEST */
945 INIT_FUNC_WATCHDOG_RESET
946
Simon Glassc45e3592013-03-11 06:49:53 +0000947#ifdef CONFIG_POST
948 init_post,
949#endif
Simon Glass50250b52013-03-11 14:30:42 +0000950 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000951 /*
952 * Now that we have DRAM mapped and working, we can
953 * relocate the code and continue running from DRAM.
954 *
955 * Reserve memory at end of RAM for (top down in that order):
956 * - area that won't get touched by U-Boot and Linux (optional)
957 * - kernel log buffer
958 * - protected RAM
959 * - LCD framebuffer
960 * - monitor code
961 * - board info struct
962 */
963 setup_dest_addr,
Chris Zankel41e37372016-08-10 18:36:43 +0300964#if defined(CONFIG_BLACKFIN) || defined(CONFIG_XTENSA)
Sonic Zhangf503a522014-07-17 19:01:34 +0800965 /* Blackfin u-boot monitor should be on top of the ram */
966 reserve_uboot,
967#endif
Francois Retieffc7784e2015-11-23 13:05:44 +0200968#if defined(CONFIG_SPARC)
969 reserve_prom,
970#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000971#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
972 reserve_logbuffer,
973#endif
974#ifdef CONFIG_PRAM
975 reserve_pram,
976#endif
977 reserve_round_4k,
978#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
979 defined(CONFIG_ARM)
980 reserve_mmu,
981#endif
Simon Glassfce58f52016-01-18 19:52:21 -0700982#ifdef CONFIG_DM_VIDEO
983 reserve_video,
984#else
985# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000986 reserve_lcd,
Simon Glassfce58f52016-01-18 19:52:21 -0700987# endif
Simon Glass50250b52013-03-11 14:30:42 +0000988 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glassfce58f52016-01-18 19:52:21 -0700989# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800990 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.ite23aed32015-03-28 11:34:52 +0100991 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glassfce58f52016-01-18 19:52:21 -0700992 reserve_legacy_video,
993# endif
994#endif /* CONFIG_DM_VIDEO */
Simon Glass1008da02016-01-18 19:52:20 -0700995 reserve_trace,
Chris Zankel41e37372016-08-10 18:36:43 +0300996#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_XTENSA)
Simon Glassc45e3592013-03-11 06:49:53 +0000997 reserve_uboot,
Sonic Zhangf503a522014-07-17 19:01:34 +0800998#endif
Simon Glass4d2aee82013-03-05 14:39:45 +0000999#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +00001000 reserve_malloc,
1001 reserve_board,
Simon Glass4d2aee82013-03-05 14:39:45 +00001002#endif
Simon Glassc45e3592013-03-11 06:49:53 +00001003 setup_machine,
1004 reserve_global_data,
1005 reserve_fdt,
Simon Glass5ded7e52015-01-19 22:16:12 -07001006 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +00001007 reserve_stacks,
1008 setup_dram_config,
1009 show_dram_config,
Vladimir Zapolskiy67fa10d2016-11-28 00:15:24 +02001010#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
1011 defined(CONFIG_SH)
Simon Glass50250b52013-03-11 14:30:42 +00001012 setup_board_part1,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +01001013#endif
1014#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +00001015 INIT_FUNC_WATCHDOG_RESET
1016 setup_board_part2,
1017#endif
Simon Glassc45e3592013-03-11 06:49:53 +00001018 display_new_sp,
Simon Glass50250b52013-03-11 14:30:42 +00001019#ifdef CONFIG_SYS_EXTBDINFO
1020 setup_board_extra,
1021#endif
mario.six@gdsys.cc7e9b9d62017-02-22 16:07:22 +01001022#ifdef CONFIG_OF_BOARD_FIXUP
1023 fix_fdt,
1024#endif
Simon Glass50250b52013-03-11 14:30:42 +00001025 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +00001026 reloc_fdt,
1027 setup_reloc,
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001028#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glassd50b2f42015-01-01 16:18:09 -07001029 copy_uboot_to_ram,
Simon Glassd50b2f42015-01-01 16:18:09 -07001030 do_elf_reloc_fixups,
Simon Glass2a7bf772017-01-16 07:03:52 -07001031 clear_bss,
Simon Glassd50b2f42015-01-01 16:18:09 -07001032#endif
Chris Zankel41e37372016-08-10 18:36:43 +03001033#if defined(CONFIG_XTENSA)
1034 clear_bss,
1035#endif
Simon Glass6e1a81a2017-01-16 07:03:49 -07001036#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1037 !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +00001038 jump_to_copy,
1039#endif
1040 NULL,
1041};
1042
1043void board_init_f(ulong boot_flags)
1044{
York Sun021d2022014-05-02 17:28:04 -07001045#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1046 /*
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -04001047 * For some architectures, global data is initialized and used before
York Sun021d2022014-05-02 17:28:04 -07001048 * calling this function. The data should be preserved. For others,
1049 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1050 * here to host global data until relocation.
1051 */
Simon Glassc45e3592013-03-11 06:49:53 +00001052 gd_t data;
1053
1054 gd = &data;
1055
David Feng1735de82013-12-14 11:47:36 +08001056 /*
1057 * Clear global data before it is accessed at debug print
1058 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayc5b1e5d2016-09-07 14:27:59 -04001059 * get the wrong value of gd->have_console.
David Feng1735de82013-12-14 11:47:36 +08001060 */
David Feng1735de82013-12-14 11:47:36 +08001061 zero_global_data();
1062#endif
1063
Simon Glassc45e3592013-03-11 06:49:53 +00001064 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +04001065 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +00001066
1067 if (initcall_run_list(init_sequence_f))
1068 hang();
1069
Ben Stoltz1930e8d2015-07-31 09:31:37 -06001070#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass6e1a81a2017-01-16 07:03:49 -07001071 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glassc45e3592013-03-11 06:49:53 +00001072 /* NOTREACHED - jump_to_copy() does not return */
1073 hang();
1074#endif
1075}
Simon Glass6d179872013-03-05 14:39:52 +00001076
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001077#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +00001078/*
1079 * For now this code is only used on x86.
1080 *
1081 * init_sequence_f_r is the list of init functions which are run when
1082 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1083 * The following limitations must be considered when implementing an
1084 * '_f_r' function:
1085 * - 'static' variables are read-only
1086 * - Global Data (gd->xxx) is read/write
1087 *
1088 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1089 * supported). It _should_, if possible, copy global data to RAM and
1090 * initialise the CPU caches (to speed up the relocation process)
1091 *
1092 * NOTE: At present only x86 uses this route, but it is intended that
1093 * all archs will move to this when generic relocation is implemented.
1094 */
Simon Glass2031fad2017-01-16 07:03:50 -07001095static const init_fnc_t init_sequence_f_r[] = {
Simon Glass6e1a81a2017-01-16 07:03:49 -07001096#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass6d179872013-03-05 14:39:52 +00001097 init_cache_f_r,
Simon Glass6e1a81a2017-01-16 07:03:49 -07001098#endif
Simon Glass6d179872013-03-05 14:39:52 +00001099
1100 NULL,
1101};
1102
1103void board_init_f_r(void)
1104{
1105 if (initcall_run_list(init_sequence_f_r))
1106 hang();
1107
1108 /*
Simon Glass51f73f12016-03-11 22:06:51 -07001109 * The pre-relocation drivers may be using memory that has now gone
1110 * away. Mark serial as unavailable - this will fall back to the debug
1111 * UART if available.
1112 */
1113 gd->flags &= ~GD_FLG_SERIAL_READY;
1114
1115 /*
Simon Glass6d179872013-03-05 14:39:52 +00001116 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1117 * Transfer execution from Flash to RAM by calculating the address
1118 * of the in-RAM copy of board_init_r() and calling it
1119 */
Alexey Brodkin9c832f12015-02-25 17:59:02 +03001120 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +00001121
1122 /* NOTREACHED - board_init_r() does not return */
1123 hang();
1124}
Alexey Brodkin73503182015-03-24 11:12:47 +03001125#endif /* CONFIG_X86 */