blob: a960144b02f362434fe5985f22e6b56da16e5a91 [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 Glass209a1a62013-06-11 11:14:42 -070048#include <trace.h>
Simon Glassfce58f52016-01-18 19:52:21 -070049#include <video.h>
Simon Glass50250b52013-03-11 14:30:42 +000050#include <watchdog.h>
Simon Glass62cf9122013-04-26 02:53:43 +000051#include <asm/errno.h>
Simon Glassc45e3592013-03-11 06:49:53 +000052#include <asm/io.h>
53#include <asm/sections.h>
Alexey Brodkin913e9f02015-02-24 19:40:36 +030054#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +000055#include <asm/init_helpers.h>
56#include <asm/relocate.h>
57#endif
Simon Glass62cf9122013-04-26 02:53:43 +000058#ifdef CONFIG_SANDBOX
59#include <asm/state.h>
60#endif
Simon Glassa730c5d2014-07-23 06:55:04 -060061#include <dm/root.h>
Simon Glassc45e3592013-03-11 06:49:53 +000062#include <linux/compiler.h>
63
64/*
65 * Pointer to initial global data area
66 *
67 * Here we initialize it if needed.
68 */
69#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
70#undef XTRN_DECLARE_GLOBAL_DATA_PTR
71#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
72DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
73#else
74DECLARE_GLOBAL_DATA_PTR;
75#endif
76
77/*
Simon Glass839855c2015-04-28 20:25:03 -060078 * TODO(sjg@chromium.org): IMO this code should be
Simon Glassc45e3592013-03-11 06:49:53 +000079 * refactored to a single function, something like:
80 *
81 * void led_set_state(enum led_colour_t colour, int on);
82 */
83/************************************************************************
84 * Coloured LED functionality
85 ************************************************************************
86 * May be supplied by boards if desired
87 */
Jeroen Hofsteea802b982014-06-23 23:20:19 +020088__weak void coloured_LED_init(void) {}
89__weak void red_led_on(void) {}
90__weak void red_led_off(void) {}
91__weak void green_led_on(void) {}
92__weak void green_led_off(void) {}
93__weak void yellow_led_on(void) {}
94__weak void yellow_led_off(void) {}
95__weak void blue_led_on(void) {}
96__weak void blue_led_off(void) {}
Simon Glassc45e3592013-03-11 06:49:53 +000097
98/*
99 * Why is gd allocated a register? Prior to reloc it might be better to
100 * just pass it around to each function in this file?
101 *
102 * After reloc one could argue that it is hardly used and doesn't need
103 * to be in a register. Or if it is it should perhaps hold pointers to all
104 * global data for all modules, so that post-reloc we can avoid the massive
105 * literal pool we get on ARM. Or perhaps just encourage each module to use
106 * a structure...
107 */
108
109/*
110 * Could the CONFIG_SPL_BUILD infection become a flag in gd?
111 */
112
Sonic Zhangf503a522014-07-17 19:01:34 +0800113#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glass50250b52013-03-11 14:30:42 +0000114static int init_func_watchdog_init(void)
115{
Sonic Zhangf503a522014-07-17 19:01:34 +0800116# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
117 defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100118 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
119 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangf503a522014-07-17 19:01:34 +0800120 hw_watchdog_init();
121# endif
Simon Glass50250b52013-03-11 14:30:42 +0000122 puts(" Watchdog enabled\n");
123 WATCHDOG_RESET();
124
125 return 0;
126}
127
128int init_func_watchdog_reset(void)
129{
130 WATCHDOG_RESET();
131
132 return 0;
133}
134#endif /* CONFIG_WATCHDOG */
135
Jeroen Hofstee45846052014-10-08 22:57:22 +0200136__weak void board_add_ram_info(int use_default)
Simon Glass50250b52013-03-11 14:30:42 +0000137{
138 /* please define platform specific board_add_ram_info() */
139}
140
Simon Glassc45e3592013-03-11 06:49:53 +0000141static int init_baud_rate(void)
142{
143 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
144 return 0;
145}
146
147static int display_text_info(void)
148{
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600149#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100150 ulong bss_start, bss_end, text_base;
Simon Glassc45e3592013-03-11 06:49:53 +0000151
Simon Glass9c9f44a2013-03-11 07:06:48 +0000152 bss_start = (ulong)&__bss_start;
153 bss_end = (ulong)&__bss_end;
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100154
Sonic Zhangf503a522014-07-17 19:01:34 +0800155#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100156 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800157#else
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100158 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800159#endif
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100160
161 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
162 text_base, bss_start, bss_end);
Simon Glass62cf9122013-04-26 02:53:43 +0000163#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000164
Simon Glassc45e3592013-03-11 06:49:53 +0000165#ifdef CONFIG_USE_IRQ
166 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
167 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
168#endif
169
170 return 0;
171}
172
173static int announce_dram_init(void)
174{
175 puts("DRAM: ");
176 return 0;
177}
178
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100179#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000180static int init_func_ram(void)
181{
182#ifdef CONFIG_BOARD_TYPES
183 int board_type = gd->board_type;
184#else
185 int board_type = 0; /* use dummy arg */
186#endif
187
188 gd->ram_size = initdram(board_type);
189
190 if (gd->ram_size > 0)
191 return 0;
192
193 puts("*** failed ***\n");
194 return 1;
195}
196#endif
197
Simon Glassc45e3592013-03-11 06:49:53 +0000198static int show_dram_config(void)
199{
York Sun60ac15a2014-05-02 17:28:05 -0700200 unsigned long long size;
Simon Glassc45e3592013-03-11 06:49:53 +0000201
202#ifdef CONFIG_NR_DRAM_BANKS
203 int i;
204
205 debug("\nRAM Configuration:\n");
206 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
207 size += gd->bd->bi_dram[i].size;
Bin Mengc8964482015-08-06 01:31:20 -0700208 debug("Bank #%d: %llx ", i,
209 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glassc45e3592013-03-11 06:49:53 +0000210#ifdef DEBUG
211 print_size(gd->bd->bi_dram[i].size, "\n");
212#endif
213 }
214 debug("\nDRAM: ");
215#else
216 size = gd->ram_size;
217#endif
218
Simon Glass50250b52013-03-11 14:30:42 +0000219 print_size(size, "");
220 board_add_ram_info(0);
221 putc('\n');
Simon Glassc45e3592013-03-11 06:49:53 +0000222
223 return 0;
224}
225
Jeroen Hofstee45846052014-10-08 22:57:22 +0200226__weak void dram_init_banksize(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000227{
228#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
229 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
230 gd->bd->bi_dram[0].size = get_effective_memsize();
231#endif
232}
233
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100234#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000235static int init_func_i2c(void)
236{
237 puts("I2C: ");
trema6612902013-09-21 18:13:34 +0200238#ifdef CONFIG_SYS_I2C
239 i2c_init_all();
240#else
Simon Glass50250b52013-03-11 14:30:42 +0000241 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trema6612902013-09-21 18:13:34 +0200242#endif
Simon Glass50250b52013-03-11 14:30:42 +0000243 puts("ready\n");
244 return 0;
245}
246#endif
247
248#if defined(CONFIG_HARD_SPI)
249static int init_func_spi(void)
250{
251 puts("SPI: ");
252 spi_init();
253 puts("ready\n");
254 return 0;
255}
256#endif
257
258__maybe_unused
Simon Glassc45e3592013-03-11 06:49:53 +0000259static int zero_global_data(void)
260{
261 memset((void *)gd, '\0', sizeof(gd_t));
262
263 return 0;
264}
265
266static int setup_mon_len(void)
267{
Michal Simek65e915c2014-05-08 16:08:44 +0200268#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100269 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz1930e8d2015-07-31 09:31:37 -0600270#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glass62cf9122013-04-26 02:53:43 +0000271 gd->mon_len = (ulong)&_end - (ulong)_init;
Thomas Choucce3e752014-08-22 11:36:47 +0800272#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
Sonic Zhangf503a522014-07-17 19:01:34 +0800273 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800274#elif defined(CONFIG_NDS32)
275 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass9c9f44a2013-03-11 07:06:48 +0000276#else
Simon Glass50250b52013-03-11 14:30:42 +0000277 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
278 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000279#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000280 return 0;
281}
282
283__weak int arch_cpu_init(void)
284{
285 return 0;
286}
287
Simon Glass62cf9122013-04-26 02:53:43 +0000288#ifdef CONFIG_SANDBOX
289static int setup_ram_buf(void)
290{
Simon Glass9dd10bf2013-11-10 10:27:03 -0700291 struct sandbox_state *state = state_get_current();
292
293 gd->arch.ram_buf = state->ram_buf;
294 gd->ram_size = state->ram_size;
Simon Glass62cf9122013-04-26 02:53:43 +0000295
296 return 0;
297}
298#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000299
300/* Get the top of usable RAM */
301__weak ulong board_get_usable_ram_top(ulong total_size)
302{
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700303#ifdef CONFIG_SYS_SDRAM_BASE
304 /*
Simon Glass839855c2015-04-28 20:25:03 -0600305 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren0ba4a8a2014-12-23 10:34:49 -0700306 * 32-bit address space. If so, clip the usable RAM so it doesn't.
307 */
308 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
309 /*
310 * Will wrap back to top of 32-bit space when reservations
311 * are made.
312 */
313 return 0;
314#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000315 return gd->ram_top;
316}
317
York Sun50739372015-12-07 11:05:29 -0800318__weak phys_size_t board_reserve_ram_top(phys_size_t ram_size)
319{
320#ifdef CONFIG_SYS_MEM_TOP_HIDE
321 return ram_size - CONFIG_SYS_MEM_TOP_HIDE;
322#else
323 return ram_size;
324#endif
325}
326
Simon Glassc45e3592013-03-11 06:49:53 +0000327static 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 Sun5d286cd2015-12-04 11:57:07 -0800334#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
335 /* Reserve memory for secure MMU tables, and/or security monitor */
336 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
337 /*
338 * Record secure memory location. Need recalcuate if memory splits
339 * into banks, or the ram base is not zero.
340 */
341 gd->secure_ram = gd->ram_size;
342#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000343 /*
344 * Subtract specified amount of memory to hide so that it won't
345 * get "touched" at all by U-Boot. By fixing up gd->ram_size
346 * the Linux kernel should now get passed the now "corrected"
York Sun50739372015-12-07 11:05:29 -0800347 * memory size and won't touch it either. This has been used
348 * by arch/powerpc exclusively. Now ARMv8 takes advantage of
349 * thie mechanism. If memory is split into banks, addresses
350 * need to be calculated.
Simon Glassc45e3592013-03-11 06:49:53 +0000351 */
York Sun50739372015-12-07 11:05:29 -0800352 gd->ram_size = board_reserve_ram_top(gd->ram_size);
353
Simon Glassc45e3592013-03-11 06:49:53 +0000354#ifdef CONFIG_SYS_SDRAM_BASE
355 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
356#endif
Simon Glass50250b52013-03-11 14:30:42 +0000357 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000358 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000359 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000360 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700361#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000362 /*
363 * We need to make sure the location we intend to put secondary core
364 * boot code is reserved and not used by any part of u-boot
365 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000366 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
367 gd->relocaddr = determine_mp_bootpg(NULL);
368 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000369 }
370#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000371 return 0;
372}
373
Francois Retieffc7784e2015-11-23 13:05:44 +0200374#if defined(CONFIG_SPARC)
375static int reserve_prom(void)
376{
377 /* defined in arch/sparc/cpu/leon?/prom.c */
378 extern void *__prom_start_reloc;
379 int size = 8192; /* page table = 2k, prom = 6k */
380 gd->relocaddr -= size;
381 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
382 debug("Reserving %dk for PROM and page table at %08lx\n", size,
383 gd->relocaddr);
384 return 0;
385}
386#endif
387
Simon Glassc45e3592013-03-11 06:49:53 +0000388#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
389static int reserve_logbuffer(void)
390{
391 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000392 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000393 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000394 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000395 return 0;
396}
397#endif
398
399#ifdef CONFIG_PRAM
400/* reserve protected RAM */
401static int reserve_pram(void)
402{
403 ulong reg;
404
405 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000406 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000407 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000408 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000409 return 0;
410}
411#endif /* CONFIG_PRAM */
412
413/* Round memory pointer down to next 4 kB limit */
414static int reserve_round_4k(void)
415{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000416 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000417 return 0;
418}
419
420#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
421 defined(CONFIG_ARM)
422static int reserve_mmu(void)
423{
424 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800425 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000426 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000427
428 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000429 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000430
Masahiro Yamadad1589242013-05-27 00:37:30 +0000431 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000432 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
433 gd->arch.tlb_addr + gd->arch.tlb_size);
434 return 0;
435}
436#endif
437
Simon Glassfce58f52016-01-18 19:52:21 -0700438#ifdef CONFIG_DM_VIDEO
439static int reserve_video(void)
440{
441 ulong addr;
442 int ret;
443
444 addr = gd->relocaddr;
445 ret = video_reserve(&addr);
446 if (ret)
447 return ret;
448 gd->relocaddr = addr;
449
450 return 0;
451}
452#else
453
454# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000455static int reserve_lcd(void)
456{
Simon Glassfce58f52016-01-18 19:52:21 -0700457# ifdef CONFIG_FB_ADDR
Simon Glassc45e3592013-03-11 06:49:53 +0000458 gd->fb_base = CONFIG_FB_ADDR;
Simon Glassfce58f52016-01-18 19:52:21 -0700459# else
Simon Glassc45e3592013-03-11 06:49:53 +0000460 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000461 gd->relocaddr = lcd_setmem(gd->relocaddr);
462 gd->fb_base = gd->relocaddr;
Simon Glassfce58f52016-01-18 19:52:21 -0700463# endif /* CONFIG_FB_ADDR */
464
Simon Glassc45e3592013-03-11 06:49:53 +0000465 return 0;
466}
Simon Glassfce58f52016-01-18 19:52:21 -0700467# endif /* CONFIG_LCD */
Simon Glassc45e3592013-03-11 06:49:53 +0000468
Simon Glassfce58f52016-01-18 19:52:21 -0700469# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800470 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.ite23aed32015-03-28 11:34:52 +0100471 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass1008da02016-01-18 19:52:20 -0700472static int reserve_legacy_video(void)
Simon Glass50250b52013-03-11 14:30:42 +0000473{
474 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000475 gd->relocaddr = video_setmem(gd->relocaddr);
476 gd->fb_base = gd->relocaddr;
Simon Glass50250b52013-03-11 14:30:42 +0000477
478 return 0;
479}
Simon Glassfce58f52016-01-18 19:52:21 -0700480# endif
481#endif /* !CONFIG_DM_VIDEO */
Simon Glass50250b52013-03-11 14:30:42 +0000482
Simon Glass1008da02016-01-18 19:52:20 -0700483static int reserve_trace(void)
484{
485#ifdef CONFIG_TRACE
486 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
487 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
488 debug("Reserving %dk for trace data at: %08lx\n",
489 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
490#endif
491
492 return 0;
493}
494
Simon Glassc45e3592013-03-11 06:49:53 +0000495static int reserve_uboot(void)
496{
497 /*
498 * reserve memory for U-Boot code, data & bss
499 * round down to next 4 kB limit
500 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000501 gd->relocaddr -= gd->mon_len;
502 gd->relocaddr &= ~(4096 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000503#ifdef CONFIG_E500
504 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000505 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000506#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000507
508 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000509 gd->relocaddr);
510
511 gd->start_addr_sp = gd->relocaddr;
512
Simon Glassc45e3592013-03-11 06:49:53 +0000513 return 0;
514}
515
Simon Glass4d2aee82013-03-05 14:39:45 +0000516#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000517/* reserve memory for malloc() area */
518static int reserve_malloc(void)
519{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000520 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000521 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000522 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000523 return 0;
524}
525
526/* (permanently) allocate a Board Info struct */
527static int reserve_board(void)
528{
Sonic Zhangf503a522014-07-17 19:01:34 +0800529 if (!gd->bd) {
530 gd->start_addr_sp -= sizeof(bd_t);
531 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
532 memset(gd->bd, '\0', sizeof(bd_t));
533 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
534 sizeof(bd_t), gd->start_addr_sp);
535 }
Simon Glassc45e3592013-03-11 06:49:53 +0000536 return 0;
537}
Simon Glass4d2aee82013-03-05 14:39:45 +0000538#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000539
540static int setup_machine(void)
541{
542#ifdef CONFIG_MACH_TYPE
543 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
544#endif
545 return 0;
546}
547
548static int reserve_global_data(void)
549{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000550 gd->start_addr_sp -= sizeof(gd_t);
551 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000552 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000553 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000554 return 0;
555}
556
557static int reserve_fdt(void)
558{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100559#ifndef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000560 /*
Simon Glass839855c2015-04-28 20:25:03 -0600561 * If the device tree is sitting immediately above our image then we
Simon Glassc45e3592013-03-11 06:49:53 +0000562 * must relocate it. If it is embedded in the data section, then it
563 * will be relocated with other data.
564 */
565 if (gd->fdt_blob) {
566 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
567
Masahiro Yamadad1589242013-05-27 00:37:30 +0000568 gd->start_addr_sp -= gd->fdt_size;
569 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000570 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000571 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000572 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100573#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000574
575 return 0;
576}
577
Andreas Bießmann25429862015-02-06 23:06:45 +0100578int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000579{
Andreas Bießmann25429862015-02-06 23:06:45 +0100580 return 0;
581}
Simon Glass4d2aee82013-03-05 14:39:45 +0000582
Andreas Bießmann25429862015-02-06 23:06:45 +0100583static int reserve_stacks(void)
584{
585 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000586 gd->start_addr_sp -= 16;
587 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000588
589 /*
Simon Glass839855c2015-04-28 20:25:03 -0600590 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann25429862015-02-06 23:06:45 +0100591 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000592 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100593 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000594}
595
596static int display_new_sp(void)
597{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000598 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000599
600 return 0;
601}
602
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100603#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glass50250b52013-03-11 14:30:42 +0000604static int setup_board_part1(void)
605{
606 bd_t *bd = gd->bd;
607
608 /*
609 * Save local variables to board info struct
610 */
Simon Glass50250b52013-03-11 14:30:42 +0000611 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
612 bd->bi_memsize = gd->ram_size; /* size in bytes */
613
614#ifdef CONFIG_SYS_SRAM_BASE
615 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
616 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
617#endif
618
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900619#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glass50250b52013-03-11 14:30:42 +0000620 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
621 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
622#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100623#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000624 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
625#endif
626#if defined(CONFIG_MPC83xx)
627 bd->bi_immrbar = CONFIG_SYS_IMMR;
628#endif
Simon Glass50250b52013-03-11 14:30:42 +0000629
630 return 0;
631}
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100632#endif
Simon Glass50250b52013-03-11 14:30:42 +0000633
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +0100634#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000635static int setup_board_part2(void)
636{
637 bd_t *bd = gd->bd;
638
639 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
640 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
641#if defined(CONFIG_CPM2)
642 bd->bi_cpmfreq = gd->arch.cpm_clk;
643 bd->bi_brgfreq = gd->arch.brg_clk;
644 bd->bi_sccfreq = gd->arch.scc_clk;
645 bd->bi_vco = gd->arch.vco_out;
646#endif /* CONFIG_CPM2 */
647#if defined(CONFIG_MPC512X)
648 bd->bi_ipsfreq = gd->arch.ips_clk;
649#endif /* CONFIG_MPC512X */
650#if defined(CONFIG_MPC5xxx)
651 bd->bi_ipbfreq = gd->arch.ipb_clk;
652 bd->bi_pcifreq = gd->pci_clk;
653#endif /* CONFIG_MPC5xxx */
Alison Wang8f6d8f32015-02-12 18:33:15 +0800654#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
655 bd->bi_pcifreq = gd->pci_clk;
656#endif
657#if defined(CONFIG_EXTRA_CLOCK)
658 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
659 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
660 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
661#endif
Simon Glass50250b52013-03-11 14:30:42 +0000662
663 return 0;
664}
665#endif
666
667#ifdef CONFIG_SYS_EXTBDINFO
668static int setup_board_extra(void)
669{
670 bd_t *bd = gd->bd;
671
672 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
673 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
674 sizeof(bd->bi_r_version));
675
676 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
677 bd->bi_plb_busfreq = gd->bus_clk;
678#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
679 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
680 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
681 bd->bi_pci_busfreq = get_PCI_freq();
682 bd->bi_opbfreq = get_OPB_freq();
683#elif defined(CONFIG_XILINX_405)
684 bd->bi_pci_busfreq = get_PCI_freq();
685#endif
686
687 return 0;
688}
689#endif
690
Simon Glassc45e3592013-03-11 06:49:53 +0000691#ifdef CONFIG_POST
692static int init_post(void)
693{
694 post_bootmode_init();
695 post_run(NULL, POST_ROM | post_bootmode_get(0));
696
697 return 0;
698}
699#endif
700
Simon Glassc45e3592013-03-11 06:49:53 +0000701static int setup_dram_config(void)
702{
703 /* Ram is board specific, so move it to board code ... */
704 dram_init_banksize();
705
706 return 0;
707}
708
709static int reloc_fdt(void)
710{
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100711#ifndef CONFIG_OF_EMBED
Simon Glass00dd17a2015-08-04 12:33:39 -0600712 if (gd->flags & GD_FLG_SKIP_RELOC)
713 return 0;
Simon Glassc45e3592013-03-11 06:49:53 +0000714 if (gd->new_fdt) {
715 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
716 gd->fdt_blob = gd->new_fdt;
717 }
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100718#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000719
720 return 0;
721}
722
723static int setup_reloc(void)
724{
Simon Glass00dd17a2015-08-04 12:33:39 -0600725 if (gd->flags & GD_FLG_SKIP_RELOC) {
726 debug("Skipping relocation due to flag\n");
727 return 0;
728 }
729
Sonic Zhangf503a522014-07-17 19:01:34 +0800730#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadad1589242013-05-27 00:37:30 +0000731 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100732#ifdef CONFIG_M68K
733 /*
734 * On all ColdFire arch cpu, monitor code starts always
735 * just after the default vector table location, so at 0x400
736 */
737 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
738#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800739#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000740 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
741
742 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000743 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000744 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
745 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000746
747 return 0;
748}
749
750/* ARM calls relocate_code from its crt0.S */
Simon Glass2fd34e62013-11-10 10:26:59 -0700751#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glassc45e3592013-03-11 06:49:53 +0000752
753static int jump_to_copy(void)
754{
Simon Glass00dd17a2015-08-04 12:33:39 -0600755 if (gd->flags & GD_FLG_SKIP_RELOC)
756 return 0;
Simon Glass6d179872013-03-05 14:39:52 +0000757 /*
758 * x86 is special, but in a nice way. It uses a trampoline which
759 * enables the dcache if possible.
760 *
761 * For now, other archs use relocate_code(), which is implemented
762 * similarly for all archs. When we do generic relocation, hopefully
763 * we can make all archs enable the dcache prior to relocation.
764 */
Alexey Brodkin913e9f02015-02-24 19:40:36 +0300765#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +0000766 /*
767 * SDRAM and console are now initialised. The final stack can now
768 * be setup in SDRAM. Code execution will continue in Flash, but
769 * with the stack in SDRAM and Global Data in temporary memory
770 * (CPU cache)
771 */
Simon Glass0e27b872015-08-10 20:44:32 -0600772 arch_setup_gd(gd->new_gd);
Simon Glass6d179872013-03-05 14:39:52 +0000773 board_init_f_r_trampoline(gd->start_addr_sp);
774#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000775 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000776#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000777
778 return 0;
779}
780#endif
781
782/* Record the board_init_f() bootstage (after arch_cpu_init()) */
783static int mark_bootstage(void)
784{
785 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
786
787 return 0;
788}
789
Simon Glass1bb49232015-11-08 23:47:48 -0700790static int initf_console_record(void)
791{
792#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
793 return console_record_init();
794#else
795 return 0;
796#endif
797}
798
Simon Glassa730c5d2014-07-23 06:55:04 -0600799static int initf_dm(void)
800{
801#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
802 int ret;
803
804 ret = dm_init_and_scan(true);
805 if (ret)
806 return ret;
807#endif
808
809 return 0;
810}
811
Simon Glass5ded7e52015-01-19 22:16:12 -0700812/* Architecture-specific memory reservation */
813__weak int reserve_arch(void)
814{
815 return 0;
816}
817
Simon Glass7af8d052015-03-05 12:25:16 -0700818__weak int arch_cpu_init_dm(void)
819{
820 return 0;
821}
822
Simon Glassc45e3592013-03-11 06:49:53 +0000823static init_fnc_t init_sequence_f[] = {
Simon Glass62cf9122013-04-26 02:53:43 +0000824#ifdef CONFIG_SANDBOX
825 setup_ram_buf,
826#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000827 setup_mon_len,
Simon Glass26b78b22015-02-27 22:06:34 -0700828#ifdef CONFIG_OF_CONTROL
Simon Glassa0877672015-02-27 22:06:35 -0700829 fdtdec_setup,
Simon Glass26b78b22015-02-27 22:06:34 -0700830#endif
Kevin Hilman676f0192014-12-09 15:03:58 -0800831#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700832 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800833#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700834 initf_malloc,
Simon Glass1bb49232015-11-08 23:47:48 -0700835 initf_console_record,
Simon Glass50250b52013-03-11 14:30:42 +0000836#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
837 /* TODO: can this go into arch_cpu_init()? */
838 probecpu,
839#endif
Bin Meng178f8972015-08-20 06:40:18 -0700840#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
841 x86_fsp_init,
842#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000843 arch_cpu_init, /* basic arch cpu dependent setup */
Simon Glass6df5de22014-09-03 17:36:59 -0600844 initf_dm,
Simon Glass7af8d052015-03-05 12:25:16 -0700845 arch_cpu_init_dm,
Thomas Chouc2fbaa22015-10-30 15:35:51 +0800846 mark_bootstage, /* need timer, go after init dm */
Simon Glassc45e3592013-03-11 06:49:53 +0000847#if defined(CONFIG_BOARD_EARLY_INIT_F)
848 board_early_init_f,
849#endif
Simon Glass50250b52013-03-11 14:30:42 +0000850 /* TODO: can any of this go into arch_cpu_init()? */
851#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
852 get_clocks, /* get CPU and bus clocks (etc.) */
853#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
854 && !defined(CONFIG_TQM885D)
855 adjust_sdram_tbs_8xx,
856#endif
857 /* TODO: can we rename this to timer_init()? */
858 init_timebase,
859#endif
Bin Meng31617642015-12-08 17:31:40 -0800860#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retief7d07d682015-10-28 15:18:22 +0200861 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
862 defined(CONFIG_SPARC)
Simon Glassc45e3592013-03-11 06:49:53 +0000863 timer_init, /* initialize timer */
Simon Glass50250b52013-03-11 14:30:42 +0000864#endif
Simon Glass50250b52013-03-11 14:30:42 +0000865#ifdef CONFIG_SYS_ALLOC_DPRAM
866#if !defined(CONFIG_CPM2)
867 dpram_init,
868#endif
869#endif
870#if defined(CONFIG_BOARD_POSTCLK_INIT)
871 board_postclk_init,
872#endif
Peng Fand7f18922015-10-30 17:30:02 +0800873#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100874 get_clocks,
875#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000876 env_init, /* initialize environment */
Simon Glass50250b52013-03-11 14:30:42 +0000877#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
878 /* get CPU and bus clocks according to the environment variable */
879 get_clocks_866,
880 /* adjust sdram refresh rate according to the new clock */
881 sdram_adjust_866,
882 init_timebase,
883#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000884 init_baud_rate, /* initialze baudrate settings */
885 serial_init, /* serial communications setup */
886 console_init_f, /* stage 1 init of console */
Simon Glass62cf9122013-04-26 02:53:43 +0000887#ifdef CONFIG_SANDBOX
888 sandbox_early_getopt_check,
889#endif
890#ifdef CONFIG_OF_CONTROL
891 fdtdec_prepare_fdt,
Simon Glass6d179872013-03-05 14:39:52 +0000892#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000893 display_options, /* say that we are here */
894 display_text_info, /* show debugging info if required */
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900895#if defined(CONFIG_MPC8260)
Simon Glass50250b52013-03-11 14:30:42 +0000896 prt_8260_rsr,
897 prt_8260_clks,
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900898#endif /* CONFIG_MPC8260 */
Simon Glass50250b52013-03-11 14:30:42 +0000899#if defined(CONFIG_MPC83xx)
900 prt_83xx_rsr,
901#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100902#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000903 checkcpu,
904#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000905 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass50250b52013-03-11 14:30:42 +0000906#if defined(CONFIG_MPC5xxx)
907 prt_mpc5xxx_clks,
908#endif /* CONFIG_MPC5xxx */
Simon Glassc45e3592013-03-11 06:49:53 +0000909#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900910 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000911#endif
Simon Glass50250b52013-03-11 14:30:42 +0000912 INIT_FUNC_WATCHDOG_INIT
913#if defined(CONFIG_MISC_INIT_F)
914 misc_init_f,
915#endif
916 INIT_FUNC_WATCHDOG_RESET
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100917#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000918 init_func_i2c,
919#endif
920#if defined(CONFIG_HARD_SPI)
921 init_func_spi,
922#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000923 announce_dram_init,
924 /* TODO: unify all these dram functions? */
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800925#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
926 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glassc45e3592013-03-11 06:49:53 +0000927 dram_init, /* configure available RAM banks */
928#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100929#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +0000930 init_func_ram,
931#endif
932#ifdef CONFIG_POST
933 post_init_f,
934#endif
935 INIT_FUNC_WATCHDOG_RESET
936#if defined(CONFIG_SYS_DRAM_TEST)
937 testdram,
938#endif /* CONFIG_SYS_DRAM_TEST */
939 INIT_FUNC_WATCHDOG_RESET
940
Simon Glassc45e3592013-03-11 06:49:53 +0000941#ifdef CONFIG_POST
942 init_post,
943#endif
Simon Glass50250b52013-03-11 14:30:42 +0000944 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000945 /*
946 * Now that we have DRAM mapped and working, we can
947 * relocate the code and continue running from DRAM.
948 *
949 * Reserve memory at end of RAM for (top down in that order):
950 * - area that won't get touched by U-Boot and Linux (optional)
951 * - kernel log buffer
952 * - protected RAM
953 * - LCD framebuffer
954 * - monitor code
955 * - board info struct
956 */
957 setup_dest_addr,
Thomas Chou133b9c32015-10-27 11:23:39 +0800958#if defined(CONFIG_BLACKFIN)
Sonic Zhangf503a522014-07-17 19:01:34 +0800959 /* Blackfin u-boot monitor should be on top of the ram */
960 reserve_uboot,
961#endif
Francois Retieffc7784e2015-11-23 13:05:44 +0200962#if defined(CONFIG_SPARC)
963 reserve_prom,
964#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000965#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
966 reserve_logbuffer,
967#endif
968#ifdef CONFIG_PRAM
969 reserve_pram,
970#endif
971 reserve_round_4k,
972#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
973 defined(CONFIG_ARM)
974 reserve_mmu,
975#endif
Simon Glassfce58f52016-01-18 19:52:21 -0700976#ifdef CONFIG_DM_VIDEO
977 reserve_video,
978#else
979# ifdef CONFIG_LCD
Simon Glassc45e3592013-03-11 06:49:53 +0000980 reserve_lcd,
Simon Glassfce58f52016-01-18 19:52:21 -0700981# endif
Simon Glass50250b52013-03-11 14:30:42 +0000982 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glassfce58f52016-01-18 19:52:21 -0700983# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangf503a522014-07-17 19:01:34 +0800984 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.ite23aed32015-03-28 11:34:52 +0100985 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glassfce58f52016-01-18 19:52:21 -0700986 reserve_legacy_video,
987# endif
988#endif /* CONFIG_DM_VIDEO */
Simon Glass1008da02016-01-18 19:52:20 -0700989 reserve_trace,
Thomas Chou133b9c32015-10-27 11:23:39 +0800990#if !defined(CONFIG_BLACKFIN)
Simon Glassc45e3592013-03-11 06:49:53 +0000991 reserve_uboot,
Sonic Zhangf503a522014-07-17 19:01:34 +0800992#endif
Simon Glass4d2aee82013-03-05 14:39:45 +0000993#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000994 reserve_malloc,
995 reserve_board,
Simon Glass4d2aee82013-03-05 14:39:45 +0000996#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000997 setup_machine,
998 reserve_global_data,
999 reserve_fdt,
Simon Glass5ded7e52015-01-19 22:16:12 -07001000 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +00001001 reserve_stacks,
1002 setup_dram_config,
1003 show_dram_config,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +01001004#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glass50250b52013-03-11 14:30:42 +00001005 setup_board_part1,
Daniel Schwierzeckbb08b0b2015-11-01 17:36:13 +01001006#endif
1007#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass50250b52013-03-11 14:30:42 +00001008 INIT_FUNC_WATCHDOG_RESET
1009 setup_board_part2,
1010#endif
Simon Glassc45e3592013-03-11 06:49:53 +00001011 display_new_sp,
Simon Glass50250b52013-03-11 14:30:42 +00001012#ifdef CONFIG_SYS_EXTBDINFO
1013 setup_board_extra,
1014#endif
1015 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +00001016 reloc_fdt,
1017 setup_reloc,
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001018#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glassd50b2f42015-01-01 16:18:09 -07001019 copy_uboot_to_ram,
1020 clear_bss,
1021 do_elf_reloc_fixups,
1022#endif
Simon Glass2fd34e62013-11-10 10:26:59 -07001023#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glassc45e3592013-03-11 06:49:53 +00001024 jump_to_copy,
1025#endif
1026 NULL,
1027};
1028
1029void board_init_f(ulong boot_flags)
1030{
York Sun021d2022014-05-02 17:28:04 -07001031#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1032 /*
1033 * For some archtectures, global data is initialized and used before
1034 * calling this function. The data should be preserved. For others,
1035 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1036 * here to host global data until relocation.
1037 */
Simon Glassc45e3592013-03-11 06:49:53 +00001038 gd_t data;
1039
1040 gd = &data;
1041
David Feng1735de82013-12-14 11:47:36 +08001042 /*
1043 * Clear global data before it is accessed at debug print
1044 * in initcall_run_list. Otherwise the debug print probably
1045 * get the wrong vaule of gd->have_console.
1046 */
David Feng1735de82013-12-14 11:47:36 +08001047 zero_global_data();
1048#endif
1049
Simon Glassc45e3592013-03-11 06:49:53 +00001050 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +04001051 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +00001052
1053 if (initcall_run_list(init_sequence_f))
1054 hang();
1055
Ben Stoltz1930e8d2015-07-31 09:31:37 -06001056#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1057 !defined(CONFIG_EFI_APP)
Simon Glassc45e3592013-03-11 06:49:53 +00001058 /* NOTREACHED - jump_to_copy() does not return */
1059 hang();
1060#endif
1061}
Simon Glass6d179872013-03-05 14:39:52 +00001062
Alexey Brodkin913e9f02015-02-24 19:40:36 +03001063#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass6d179872013-03-05 14:39:52 +00001064/*
1065 * For now this code is only used on x86.
1066 *
1067 * init_sequence_f_r is the list of init functions which are run when
1068 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1069 * The following limitations must be considered when implementing an
1070 * '_f_r' function:
1071 * - 'static' variables are read-only
1072 * - Global Data (gd->xxx) is read/write
1073 *
1074 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1075 * supported). It _should_, if possible, copy global data to RAM and
1076 * initialise the CPU caches (to speed up the relocation process)
1077 *
1078 * NOTE: At present only x86 uses this route, but it is intended that
1079 * all archs will move to this when generic relocation is implemented.
1080 */
1081static init_fnc_t init_sequence_f_r[] = {
1082 init_cache_f_r,
Simon Glass6d179872013-03-05 14:39:52 +00001083
1084 NULL,
1085};
1086
1087void board_init_f_r(void)
1088{
1089 if (initcall_run_list(init_sequence_f_r))
1090 hang();
1091
1092 /*
1093 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1094 * Transfer execution from Flash to RAM by calculating the address
1095 * of the in-RAM copy of board_init_r() and calling it
1096 */
Alexey Brodkin9c832f12015-02-25 17:59:02 +03001097 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +00001098
1099 /* NOTREACHED - board_init_r() does not return */
1100 hang();
1101}
Alexey Brodkin73503182015-03-24 11:12:47 +03001102#endif /* CONFIG_X86 */