blob: a960144b02f362434fe5985f22e6b56da16e5a91 [file] [log] [blame]
Simon Glass1938f4a2013-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 Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glass1938f4a2013-03-11 06:49:53 +000011 */
12
13#include <common.h>
14#include <linux/compiler.h>
15#include <version.h>
Simon Glass24b852a2015-11-08 23:47:45 -070016#include <console.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000017#include <environment.h>
Simon Glassab7cd622014-07-23 06:55:04 -060018#include <dm.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000019#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000020#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000021#if defined(CONFIG_CMD_IDE)
22#include <ide.h>
23#endif
24#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000025#include <initcall.h>
26#include <logbuff.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070027#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050028#include <mapmem.h>
Simon Glasse4fef6c2013-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 Huauec3b4822014-09-03 13:57:54 -070040#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huaua76df702014-07-26 11:35:43 -070041#include <asm/mp.h>
42#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +000043
Simon Glassa733b062013-04-26 02:53:43 +000044#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000045#include <post.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000046#include <spi.h>
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020047#include <status_led.h>
Simon Glass71c52db2013-06-11 11:14:42 -070048#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070049#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000050#include <watchdog.h>
Simon Glassa733b062013-04-26 02:53:43 +000051#include <asm/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000052#include <asm/io.h>
53#include <asm/sections.h>
Alexey Brodkin3fb80162015-02-24 19:40:36 +030054#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +000055#include <asm/init_helpers.h>
56#include <asm/relocate.h>
57#endif
Simon Glassa733b062013-04-26 02:53:43 +000058#ifdef CONFIG_SANDBOX
59#include <asm/state.h>
60#endif
Simon Glassab7cd622014-07-23 06:55:04 -060061#include <dm/root.h>
Simon Glass1938f4a2013-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 Glass4c509342015-04-28 20:25:03 -060078 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-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 Hofsteec5d40012014-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 Glass1938f4a2013-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 Zhangd54d7eb2014-07-17 19:01:34 +0800113#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000114static int init_func_watchdog_init(void)
115{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800116# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
117 defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100118 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
119 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800120 hw_watchdog_init();
121# endif
Simon Glasse4fef6c2013-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 Hofsteedd2a6cd2014-10-08 22:57:22 +0200136__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000137{
138 /* please define platform specific board_add_ram_info() */
139}
140
Simon Glass1938f4a2013-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 Stoltz9b217492015-07-31 09:31:37 -0600149#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100150 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000151
Simon Glass632efa72013-03-11 07:06:48 +0000152 bss_start = (ulong)&__bss_start;
153 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100154
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800155#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100156 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800157#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100158 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800159#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100160
161 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
162 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000163#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000164
Simon Glass1938f4a2013-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.ite310b932015-02-12 01:40:17 +0100179#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-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 Glass1938f4a2013-03-11 06:49:53 +0000198static int show_dram_config(void)
199{
York Sunfa39ffe2014-05-02 17:28:05 -0700200 unsigned long long size;
Simon Glass1938f4a2013-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 Meng715f5992015-08-06 01:31:20 -0700208 debug("Bank #%d: %llx ", i,
209 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-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 Glasse4fef6c2013-03-11 14:30:42 +0000219 print_size(size, "");
220 board_add_ram_info(0);
221 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000222
223 return 0;
224}
225
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200226__weak void dram_init_banksize(void)
Simon Glass1938f4a2013-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 Schocherea818db2013-01-29 08:53:15 +0100234#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000235static int init_func_i2c(void)
236{
237 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200238#ifdef CONFIG_SYS_I2C
239 i2c_init_all();
240#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000241 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200242#endif
Simon Glasse4fef6c2013-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 Glass1938f4a2013-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 Simeke945f6d2014-05-08 16:08:44 +0200268#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100269 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600270#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000271 gd->mon_len = (ulong)&_end - (ulong)_init;
Thomas Chou5ff10aa2014-08-22 11:36:47 +0800272#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800273 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800274#elif defined(CONFIG_NDS32)
275 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glass632efa72013-03-11 07:06:48 +0000276#else
Simon Glasse4fef6c2013-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 Glass632efa72013-03-11 07:06:48 +0000279#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000280 return 0;
281}
282
283__weak int arch_cpu_init(void)
284{
285 return 0;
286}
287
Simon Glassa733b062013-04-26 02:53:43 +0000288#ifdef CONFIG_SANDBOX
289static int setup_ram_buf(void)
290{
Simon Glass5c2859c2013-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 Glassa733b062013-04-26 02:53:43 +0000295
296 return 0;
297}
298#endif
299
Simon Glass1938f4a2013-03-11 06:49:53 +0000300/* Get the top of usable RAM */
301__weak ulong board_get_usable_ram_top(ulong total_size)
302{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700303#ifdef CONFIG_SYS_SDRAM_BASE
304 /*
Simon Glass4c509342015-04-28 20:25:03 -0600305 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-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 Glass1938f4a2013-03-11 06:49:53 +0000315 return gd->ram_top;
316}
317
York Sunaabd7dd2015-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 Glass1938f4a2013-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 Sune8149522015-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 Glass1938f4a2013-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 Sunaabd7dd2015-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 Glass1938f4a2013-03-11 06:49:53 +0000351 */
York Sunaabd7dd2015-12-07 11:05:29 -0800352 gd->ram_size = board_reserve_ram_top(gd->ram_size);
353
Simon Glass1938f4a2013-03-11 06:49:53 +0000354#ifdef CONFIG_SYS_SDRAM_BASE
355 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
356#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000357 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000358 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000359 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700361#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-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 Yamadaa0ba2792013-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 Glasse4fef6c2013-03-11 14:30:42 +0000369 }
370#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000371 return 0;
372}
373
Francois Retief1e85cce2015-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 Glass1938f4a2013-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 Yamadaa0ba2792013-05-27 00:37:30 +0000392 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000393 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000394 gd->relocaddr);
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-05-27 00:37:30 +0000406 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000407 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000408 gd->relocaddr);
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-05-27 00:37:30 +0000416 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-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 Fengcce6be72013-12-14 11:47:36 +0800425 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000426 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000427
428 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000429 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000430
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000431 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-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 Glass5a541942016-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 Glass1938f4a2013-03-11 06:49:53 +0000455static int reserve_lcd(void)
456{
Simon Glass5a541942016-01-18 19:52:21 -0700457# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000458 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700459# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000460 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000461 gd->relocaddr = lcd_setmem(gd->relocaddr);
462 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700463# endif /* CONFIG_FB_ADDR */
464
Simon Glass1938f4a2013-03-11 06:49:53 +0000465 return 0;
466}
Simon Glass5a541942016-01-18 19:52:21 -0700467# endif /* CONFIG_LCD */
Simon Glass1938f4a2013-03-11 06:49:53 +0000468
Simon Glass5a541942016-01-18 19:52:21 -0700469# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700470 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
471 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
472static int reserve_legacy_video(void)
473{
474 /* reserve memory for video display (always full pages) */
475 gd->relocaddr = video_setmem(gd->relocaddr);
476 gd->fb_base = gd->relocaddr;
477
478 return 0;
479}
Simon Glass5a541942016-01-18 19:52:21 -0700480# endif
481#endif /* !CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700482
Simon Glass71c52db2013-06-11 11:14:42 -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 Glass1938f4a2013-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 Yamadaa0ba2792013-05-27 00:37:30 +0000501 gd->relocaddr -= gd->mon_len;
502 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000503#ifdef CONFIG_E500
504 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000505 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000506#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000507
508 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000509 gd->relocaddr);
510
511 gd->start_addr_sp = gd->relocaddr;
512
Simon Glass1938f4a2013-03-11 06:49:53 +0000513 return 0;
514}
515
Simon Glass8cae8a62013-03-05 14:39:45 +0000516#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +0000517/* reserve memory for malloc() area */
518static int reserve_malloc(void)
519{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000520 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000521 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000522 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000523 return 0;
524}
525
526/* (permanently) allocate a Board Info struct */
527static int reserve_board(void)
528{
Sonic Zhangd54d7eb2014-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 Glass1938f4a2013-03-11 06:49:53 +0000536 return 0;
537}
Simon Glass8cae8a62013-03-05 14:39:45 +0000538#endif
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-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 Glass1938f4a2013-03-11 06:49:53 +0000552 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000553 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000554 return 0;
555}
556
557static int reserve_fdt(void)
558{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100559#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000560 /*
Simon Glass4c509342015-04-28 20:25:03 -0600561 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-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 Glassa733b062013-04-26 02:53:43 +0000570 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000571 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000572 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100573#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000574
575 return 0;
576}
577
Andreas Bießmann68145d42015-02-06 23:06:45 +0100578int arch_reserve_stacks(void)
579{
580 return 0;
581}
582
Simon Glass1938f4a2013-03-11 06:49:53 +0000583static int reserve_stacks(void)
584{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100585 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000586 gd->start_addr_sp -= 16;
587 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000588
589 /*
Simon Glass4c509342015-04-28 20:25:03 -0600590 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100591 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000592 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100593 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000594}
595
596static int display_new_sp(void)
597{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000598 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000599
600 return 0;
601}
602
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100603#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-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 Glasse4fef6c2013-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 Yamada58dac322014-03-05 17:40:10 +0900619#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-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.ite310b932015-02-12 01:40:17 +0100623#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-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 Glasse4fef6c2013-03-11 14:30:42 +0000629
630 return 0;
631}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100632#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000633
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100634#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-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 Wang1313db42015-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 Glasse4fef6c2013-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 Glass1938f4a2013-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 Glass1938f4a2013-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 Paladugue9acb9e2015-12-03 15:46:03 +0100711#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600712 if (gd->flags & GD_FLG_SKIP_RELOC)
713 return 0;
Simon Glass1938f4a2013-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 Paladugue9acb9e2015-12-03 15:46:03 +0100718#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000719
720 return 0;
721}
722
723static int setup_reloc(void)
724{
Simon Glassf05ad9b2015-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 Zhangd54d7eb2014-07-17 19:01:34 +0800730#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000731 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-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 Zhangd54d7eb2014-07-17 19:01:34 +0800739#endif
Simon Glass1938f4a2013-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 Glassa733b062013-04-26 02:53:43 +0000743 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000744 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
745 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000746
747 return 0;
748}
749
750/* ARM calls relocate_code from its crt0.S */
Simon Glass808434c2013-11-10 10:26:59 -0700751#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +0000752
753static int jump_to_copy(void)
754{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600755 if (gd->flags & GD_FLG_SKIP_RELOC)
756 return 0;
Simon Glass48a33802013-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 Brodkin3fb80162015-02-24 19:40:36 +0300765#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-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 Glassf0c7d9c2015-08-10 20:44:32 -0600772 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000773 board_init_f_r_trampoline(gd->start_addr_sp);
774#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000775 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000776#endif
Simon Glass1938f4a2013-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 Glass9854a872015-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 Glassab7cd622014-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 Glass146251f2015-01-19 22:16:12 -0700812/* Architecture-specific memory reservation */
813__weak int reserve_arch(void)
814{
815 return 0;
816}
817
Simon Glassd4c671c2015-03-05 12:25:16 -0700818__weak int arch_cpu_init_dm(void)
819{
820 return 0;
821}
822
Simon Glass1938f4a2013-03-11 06:49:53 +0000823static init_fnc_t init_sequence_f[] = {
Simon Glassa733b062013-04-26 02:53:43 +0000824#ifdef CONFIG_SANDBOX
825 setup_ram_buf,
826#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000827 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700828#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700829 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700830#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800831#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700832 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800833#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700834 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700835 initf_console_record,
Simon Glasse4fef6c2013-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 Menga52a068e2015-08-20 06:40:18 -0700840#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
841 x86_fsp_init,
842#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000843 arch_cpu_init, /* basic arch cpu dependent setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600844 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700845 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800846 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000847#if defined(CONFIG_BOARD_EARLY_INIT_F)
848 board_early_init_f,
849#endif
Simon Glasse4fef6c2013-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 Meng2317cf02015-12-08 17:31:40 -0800860#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retiefc97088c2015-10-28 15:18:22 +0200861 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
862 defined(CONFIG_SPARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000863 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000864#endif
Simon Glasse4fef6c2013-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 Fan76648462015-10-30 17:30:02 +0800873#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100874 get_clocks,
875#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000876 env_init, /* initialize environment */
Simon Glasse4fef6c2013-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 Glass1938f4a2013-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 Glassa733b062013-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 Glass48a33802013-03-05 14:39:52 +0000892#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000893 display_options, /* say that we are here */
894 display_text_info, /* show debugging info if required */
Masahiro Yamada58dac322014-03-05 17:40:10 +0900895#if defined(CONFIG_MPC8260)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000896 prt_8260_rsr,
897 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900898#endif /* CONFIG_MPC8260 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000899#if defined(CONFIG_MPC83xx)
900 prt_83xx_rsr,
901#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100902#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000903 checkcpu,
904#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000905 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000906#if defined(CONFIG_MPC5xxx)
907 prt_mpc5xxx_clks,
908#endif /* CONFIG_MPC5xxx */
Simon Glass1938f4a2013-03-11 06:49:53 +0000909#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900910 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000911#endif
Simon Glasse4fef6c2013-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 Schocherea818db2013-01-29 08:53:15 +0100917#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000918 init_func_i2c,
919#endif
920#if defined(CONFIG_HARD_SPI)
921 init_func_spi,
922#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000923 announce_dram_init,
924 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800925#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
926 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glass1938f4a2013-03-11 06:49:53 +0000927 dram_init, /* configure available RAM banks */
928#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100929#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-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 Glass1938f4a2013-03-11 06:49:53 +0000941#ifdef CONFIG_POST
942 init_post,
943#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000944 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-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 Choubbfdff32015-10-27 11:23:39 +0800958#if defined(CONFIG_BLACKFIN)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800959 /* Blackfin u-boot monitor should be on top of the ram */
960 reserve_uboot,
961#endif
Francois Retief1e85cce2015-11-23 13:05:44 +0200962#if defined(CONFIG_SPARC)
963 reserve_prom,
964#endif
Simon Glass1938f4a2013-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 Glass5a541942016-01-18 19:52:21 -0700976#ifdef CONFIG_DM_VIDEO
977 reserve_video,
978#else
979# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000980 reserve_lcd,
Simon Glass5a541942016-01-18 19:52:21 -0700981# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000982 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glass5a541942016-01-18 19:52:21 -0700983# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800984 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.it944ab342015-03-28 11:34:52 +0100985 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass5a541942016-01-18 19:52:21 -0700986 reserve_legacy_video,
987# endif
988#endif /* CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700989 reserve_trace,
Thomas Choubbfdff32015-10-27 11:23:39 +0800990#if !defined(CONFIG_BLACKFIN)
Simon Glass1938f4a2013-03-11 06:49:53 +0000991 reserve_uboot,
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800992#endif
Simon Glass8cae8a62013-03-05 14:39:45 +0000993#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +0000994 reserve_malloc,
995 reserve_board,
Simon Glass8cae8a62013-03-05 14:39:45 +0000996#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000997 setup_machine,
998 reserve_global_data,
999 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -07001000 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +00001001 reserve_stacks,
1002 setup_dram_config,
1003 show_dram_config,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001004#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001005 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001006#endif
1007#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001008 INIT_FUNC_WATCHDOG_RESET
1009 setup_board_part2,
1010#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001011 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +00001012#ifdef CONFIG_SYS_EXTBDINFO
1013 setup_board_extra,
1014#endif
1015 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +00001016 reloc_fdt,
1017 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001018#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -07001019 copy_uboot_to_ram,
1020 clear_bss,
1021 do_elf_reloc_fixups,
1022#endif
Simon Glass808434c2013-11-10 10:26:59 -07001023#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +00001024 jump_to_copy,
1025#endif
1026 NULL,
1027};
1028
1029void board_init_f(ulong boot_flags)
1030{
York Sun2a1680e2014-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 Glass1938f4a2013-03-11 06:49:53 +00001038 gd_t data;
1039
1040 gd = &data;
1041
David Fengcce6be72013-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 Fengcce6be72013-12-14 11:47:36 +08001047 zero_global_data();
1048#endif
1049
Simon Glass1938f4a2013-03-11 06:49:53 +00001050 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001051 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001052
1053 if (initcall_run_list(init_sequence_f))
1054 hang();
1055
Ben Stoltz9b217492015-07-31 09:31:37 -06001056#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1057 !defined(CONFIG_EFI_APP)
Simon Glass1938f4a2013-03-11 06:49:53 +00001058 /* NOTREACHED - jump_to_copy() does not return */
1059 hang();
1060#endif
1061}
1062
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001063#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-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 Glass48a33802013-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 Brodkin7bf9f202015-02-25 17:59:02 +03001097 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001098
1099 /* NOTREACHED - board_init_r() does not return */
1100 hang();
1101}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001102#endif /* CONFIG_X86 */