blob: da381dbd93b4d7de42a547874c8e652decfe5a7d [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 Glass1057e6c2016-02-24 09:14:50 -070048#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070049#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070050#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000051#include <watchdog.h>
Simon Glassa733b062013-04-26 02:53:43 +000052#include <asm/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000053#include <asm/io.h>
54#include <asm/sections.h>
Alexey Brodkin3fb80162015-02-24 19:40:36 +030055#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +000056#include <asm/init_helpers.h>
Chris Zankelde5e5ce2016-08-10 18:36:43 +030057#endif
58#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
Simon Glass48a33802013-03-05 14:39:52 +000059#include <asm/relocate.h>
60#endif
Simon Glassa733b062013-04-26 02:53:43 +000061#ifdef CONFIG_SANDBOX
62#include <asm/state.h>
63#endif
Simon Glassab7cd622014-07-23 06:55:04 -060064#include <dm/root.h>
Simon Glass1938f4a2013-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 Glass4c509342015-04-28 20:25:03 -060081 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-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 Hofsteec5d40012014-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 Glass1938f4a2013-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 Zhangd54d7eb2014-07-17 19:01:34 +0800116#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000117static int init_func_watchdog_init(void)
118{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800119# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
120 defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100121 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200122 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100123 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800124 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000125 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200126# endif
Simon Glasse4fef6c2013-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 Hofsteedd2a6cd2014-10-08 22:57:22 +0200140__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000141{
142 /* please define platform specific board_add_ram_info() */
143}
144
Simon Glass1938f4a2013-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 Stoltz9b217492015-07-31 09:31:37 -0600153#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100154 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000155
Simon Glass632efa72013-03-11 07:06:48 +0000156 bss_start = (ulong)&__bss_start;
157 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100158
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800159#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100160 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800161#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100162 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800163#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100164
165 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
166 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000167#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000168
Simon Glass1938f4a2013-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.ite310b932015-02-12 01:40:17 +0100183#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-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 Glass1938f4a2013-03-11 06:49:53 +0000202static int show_dram_config(void)
203{
York Sunfa39ffe2014-05-02 17:28:05 -0700204 unsigned long long size;
Simon Glass1938f4a2013-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 Meng715f5992015-08-06 01:31:20 -0700212 debug("Bank #%d: %llx ", i,
213 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-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 Glasse4fef6c2013-03-11 14:30:42 +0000223 print_size(size, "");
224 board_add_ram_info(0);
225 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000226
227 return 0;
228}
229
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200230__weak void dram_init_banksize(void)
Simon Glass1938f4a2013-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 Schocherea818db2013-01-29 08:53:15 +0100238#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000239static int init_func_i2c(void)
240{
241 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200242#ifdef CONFIG_SYS_I2C
243 i2c_init_all();
244#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000245 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200246#endif
Simon Glasse4fef6c2013-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 Glass1938f4a2013-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 Simeke945f6d2014-05-08 16:08:44 +0200272#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100273 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600274#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000275 gd->mon_len = (ulong)&_end - (ulong)_init;
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300276#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2) || \
277 defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800278 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800279#elif defined(CONFIG_NDS32)
280 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600281#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-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 Glass632efa72013-03-11 07:06:48 +0000284#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000285 return 0;
286}
287
288__weak int arch_cpu_init(void)
289{
290 return 0;
291}
292
Simon Glassa733b062013-04-26 02:53:43 +0000293#ifdef CONFIG_SANDBOX
294static int setup_ram_buf(void)
295{
Simon Glass5c2859c2013-11-10 10:27:03 -0700296 struct sandbox_state *state = state_get_current();
297
298 gd->arch.ram_buf = state->ram_buf;
299 gd->ram_size = state->ram_size;
Simon Glassa733b062013-04-26 02:53:43 +0000300
301 return 0;
302}
303#endif
304
Simon Glass1938f4a2013-03-11 06:49:53 +0000305/* Get the top of usable RAM */
306__weak ulong board_get_usable_ram_top(ulong total_size)
307{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700308#ifdef CONFIG_SYS_SDRAM_BASE
309 /*
Simon Glass4c509342015-04-28 20:25:03 -0600310 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700311 * 32-bit address space. If so, clip the usable RAM so it doesn't.
312 */
313 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
314 /*
315 * Will wrap back to top of 32-bit space when reservations
316 * are made.
317 */
318 return 0;
319#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000320 return gd->ram_top;
321}
322
York Sunaabd7dd2015-12-07 11:05:29 -0800323__weak phys_size_t board_reserve_ram_top(phys_size_t ram_size)
324{
325#ifdef CONFIG_SYS_MEM_TOP_HIDE
326 return ram_size - CONFIG_SYS_MEM_TOP_HIDE;
327#else
328 return ram_size;
329#endif
330}
331
Simon Glass1938f4a2013-03-11 06:49:53 +0000332static int setup_dest_addr(void)
333{
334 debug("Monitor len: %08lX\n", gd->mon_len);
335 /*
336 * Ram is setup, size stored in gd !!
337 */
338 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sune8149522015-12-04 11:57:07 -0800339#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
340 /* Reserve memory for secure MMU tables, and/or security monitor */
341 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
342 /*
343 * Record secure memory location. Need recalcuate if memory splits
344 * into banks, or the ram base is not zero.
345 */
York Sune61a7532016-06-24 16:46:18 -0700346 gd->arch.secure_ram = gd->ram_size;
York Sune8149522015-12-04 11:57:07 -0800347#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000348 /*
349 * Subtract specified amount of memory to hide so that it won't
350 * get "touched" at all by U-Boot. By fixing up gd->ram_size
351 * the Linux kernel should now get passed the now "corrected"
York Sunaabd7dd2015-12-07 11:05:29 -0800352 * memory size and won't touch it either. This has been used
353 * by arch/powerpc exclusively. Now ARMv8 takes advantage of
354 * thie mechanism. If memory is split into banks, addresses
355 * need to be calculated.
Simon Glass1938f4a2013-03-11 06:49:53 +0000356 */
York Sunaabd7dd2015-12-07 11:05:29 -0800357 gd->ram_size = board_reserve_ram_top(gd->ram_size);
358
Simon Glass1938f4a2013-03-11 06:49:53 +0000359#ifdef CONFIG_SYS_SDRAM_BASE
360 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
361#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000362 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000363 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000364 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000365 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700366#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000367 /*
368 * We need to make sure the location we intend to put secondary core
369 * boot code is reserved and not used by any part of u-boot
370 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000371 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
372 gd->relocaddr = determine_mp_bootpg(NULL);
373 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000374 }
375#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000376 return 0;
377}
378
Francois Retief1e85cce2015-11-23 13:05:44 +0200379#if defined(CONFIG_SPARC)
380static int reserve_prom(void)
381{
382 /* defined in arch/sparc/cpu/leon?/prom.c */
383 extern void *__prom_start_reloc;
384 int size = 8192; /* page table = 2k, prom = 6k */
385 gd->relocaddr -= size;
386 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
387 debug("Reserving %dk for PROM and page table at %08lx\n", size,
388 gd->relocaddr);
389 return 0;
390}
391#endif
392
Simon Glass1938f4a2013-03-11 06:49:53 +0000393#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
394static int reserve_logbuffer(void)
395{
396 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000397 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000398 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000399 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000400 return 0;
401}
402#endif
403
404#ifdef CONFIG_PRAM
405/* reserve protected RAM */
406static int reserve_pram(void)
407{
408 ulong reg;
409
410 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000411 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000412 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000413 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000414 return 0;
415}
416#endif /* CONFIG_PRAM */
417
418/* Round memory pointer down to next 4 kB limit */
419static int reserve_round_4k(void)
420{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000421 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000422 return 0;
423}
424
425#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
426 defined(CONFIG_ARM)
427static int reserve_mmu(void)
428{
429 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800430 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000431 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000432
433 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000434 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000435
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000436 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000437 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
438 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700439
440#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
441 /*
442 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
443 * with location within secure ram.
444 */
445 gd->arch.tlb_allocated = gd->arch.tlb_addr;
446#endif
447
Simon Glass1938f4a2013-03-11 06:49:53 +0000448 return 0;
449}
450#endif
451
Simon Glass5a541942016-01-18 19:52:21 -0700452#ifdef CONFIG_DM_VIDEO
453static int reserve_video(void)
454{
455 ulong addr;
456 int ret;
457
458 addr = gd->relocaddr;
459 ret = video_reserve(&addr);
460 if (ret)
461 return ret;
462 gd->relocaddr = addr;
463
464 return 0;
465}
466#else
467
468# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000469static int reserve_lcd(void)
470{
Simon Glass5a541942016-01-18 19:52:21 -0700471# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000472 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700473# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000474 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000475 gd->relocaddr = lcd_setmem(gd->relocaddr);
476 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700477# endif /* CONFIG_FB_ADDR */
478
Simon Glass1938f4a2013-03-11 06:49:53 +0000479 return 0;
480}
Simon Glass5a541942016-01-18 19:52:21 -0700481# endif /* CONFIG_LCD */
Simon Glass1938f4a2013-03-11 06:49:53 +0000482
Simon Glass5a541942016-01-18 19:52:21 -0700483# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700484 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
485 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
486static int reserve_legacy_video(void)
487{
488 /* reserve memory for video display (always full pages) */
489 gd->relocaddr = video_setmem(gd->relocaddr);
490 gd->fb_base = gd->relocaddr;
491
492 return 0;
493}
Simon Glass5a541942016-01-18 19:52:21 -0700494# endif
495#endif /* !CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700496
Simon Glass71c52db2013-06-11 11:14:42 -0700497static int reserve_trace(void)
498{
499#ifdef CONFIG_TRACE
500 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
501 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
502 debug("Reserving %dk for trace data at: %08lx\n",
503 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
504#endif
505
506 return 0;
507}
508
Simon Glass1938f4a2013-03-11 06:49:53 +0000509static int reserve_uboot(void)
510{
511 /*
512 * reserve memory for U-Boot code, data & bss
513 * round down to next 4 kB limit
514 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000515 gd->relocaddr -= gd->mon_len;
516 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000517#ifdef CONFIG_E500
518 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000519 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000520#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000521
522 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000523 gd->relocaddr);
524
525 gd->start_addr_sp = gd->relocaddr;
526
Simon Glass1938f4a2013-03-11 06:49:53 +0000527 return 0;
528}
529
Simon Glass8cae8a62013-03-05 14:39:45 +0000530#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +0000531/* reserve memory for malloc() area */
532static int reserve_malloc(void)
533{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000534 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000535 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000536 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000537 return 0;
538}
539
540/* (permanently) allocate a Board Info struct */
541static int reserve_board(void)
542{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800543 if (!gd->bd) {
544 gd->start_addr_sp -= sizeof(bd_t);
545 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
546 memset(gd->bd, '\0', sizeof(bd_t));
547 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
548 sizeof(bd_t), gd->start_addr_sp);
549 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000550 return 0;
551}
Simon Glass8cae8a62013-03-05 14:39:45 +0000552#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000553
554static int setup_machine(void)
555{
556#ifdef CONFIG_MACH_TYPE
557 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
558#endif
559 return 0;
560}
561
562static int reserve_global_data(void)
563{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000564 gd->start_addr_sp -= sizeof(gd_t);
565 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000566 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000567 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000568 return 0;
569}
570
571static int reserve_fdt(void)
572{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100573#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000574 /*
Simon Glass4c509342015-04-28 20:25:03 -0600575 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000576 * must relocate it. If it is embedded in the data section, then it
577 * will be relocated with other data.
578 */
579 if (gd->fdt_blob) {
580 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
581
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000582 gd->start_addr_sp -= gd->fdt_size;
583 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000584 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000585 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000586 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100587#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000588
589 return 0;
590}
591
Andreas Bießmann68145d42015-02-06 23:06:45 +0100592int arch_reserve_stacks(void)
593{
594 return 0;
595}
596
Simon Glass1938f4a2013-03-11 06:49:53 +0000597static int reserve_stacks(void)
598{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100599 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000600 gd->start_addr_sp -= 16;
601 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000602
603 /*
Simon Glass4c509342015-04-28 20:25:03 -0600604 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100605 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000606 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100607 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000608}
609
610static int display_new_sp(void)
611{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000612 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000613
614 return 0;
615}
616
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100617#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000618static int setup_board_part1(void)
619{
620 bd_t *bd = gd->bd;
621
622 /*
623 * Save local variables to board info struct
624 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000625 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
626 bd->bi_memsize = gd->ram_size; /* size in bytes */
627
628#ifdef CONFIG_SYS_SRAM_BASE
629 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
630 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
631#endif
632
Masahiro Yamada58dac322014-03-05 17:40:10 +0900633#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000634 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
635 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
636#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100637#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000638 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
639#endif
640#if defined(CONFIG_MPC83xx)
641 bd->bi_immrbar = CONFIG_SYS_IMMR;
642#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000643
644 return 0;
645}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100646#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000647
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100648#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000649static int setup_board_part2(void)
650{
651 bd_t *bd = gd->bd;
652
653 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
654 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
655#if defined(CONFIG_CPM2)
656 bd->bi_cpmfreq = gd->arch.cpm_clk;
657 bd->bi_brgfreq = gd->arch.brg_clk;
658 bd->bi_sccfreq = gd->arch.scc_clk;
659 bd->bi_vco = gd->arch.vco_out;
660#endif /* CONFIG_CPM2 */
661#if defined(CONFIG_MPC512X)
662 bd->bi_ipsfreq = gd->arch.ips_clk;
663#endif /* CONFIG_MPC512X */
664#if defined(CONFIG_MPC5xxx)
665 bd->bi_ipbfreq = gd->arch.ipb_clk;
666 bd->bi_pcifreq = gd->pci_clk;
667#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800668#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
669 bd->bi_pcifreq = gd->pci_clk;
670#endif
671#if defined(CONFIG_EXTRA_CLOCK)
672 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
673 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
674 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
675#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000676
677 return 0;
678}
679#endif
680
681#ifdef CONFIG_SYS_EXTBDINFO
682static int setup_board_extra(void)
683{
684 bd_t *bd = gd->bd;
685
686 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
687 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
688 sizeof(bd->bi_r_version));
689
690 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
691 bd->bi_plb_busfreq = gd->bus_clk;
692#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
693 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
694 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
695 bd->bi_pci_busfreq = get_PCI_freq();
696 bd->bi_opbfreq = get_OPB_freq();
697#elif defined(CONFIG_XILINX_405)
698 bd->bi_pci_busfreq = get_PCI_freq();
699#endif
700
701 return 0;
702}
703#endif
704
Simon Glass1938f4a2013-03-11 06:49:53 +0000705#ifdef CONFIG_POST
706static int init_post(void)
707{
708 post_bootmode_init();
709 post_run(NULL, POST_ROM | post_bootmode_get(0));
710
711 return 0;
712}
713#endif
714
Simon Glass1938f4a2013-03-11 06:49:53 +0000715static int setup_dram_config(void)
716{
717 /* Ram is board specific, so move it to board code ... */
718 dram_init_banksize();
719
720 return 0;
721}
722
723static int reloc_fdt(void)
724{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100725#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600726 if (gd->flags & GD_FLG_SKIP_RELOC)
727 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000728 if (gd->new_fdt) {
729 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
730 gd->fdt_blob = gd->new_fdt;
731 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100732#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000733
734 return 0;
735}
736
737static int setup_reloc(void)
738{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600739 if (gd->flags & GD_FLG_SKIP_RELOC) {
740 debug("Skipping relocation due to flag\n");
741 return 0;
742 }
743
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800744#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000745 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100746#ifdef CONFIG_M68K
747 /*
748 * On all ColdFire arch cpu, monitor code starts always
749 * just after the default vector table location, so at 0x400
750 */
751 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
752#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800753#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000754 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
755
756 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000757 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000758 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
759 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000760
761 return 0;
762}
763
764/* ARM calls relocate_code from its crt0.S */
Simon Glass808434c2013-11-10 10:26:59 -0700765#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +0000766
767static int jump_to_copy(void)
768{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600769 if (gd->flags & GD_FLG_SKIP_RELOC)
770 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000771 /*
772 * x86 is special, but in a nice way. It uses a trampoline which
773 * enables the dcache if possible.
774 *
775 * For now, other archs use relocate_code(), which is implemented
776 * similarly for all archs. When we do generic relocation, hopefully
777 * we can make all archs enable the dcache prior to relocation.
778 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300779#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000780 /*
781 * SDRAM and console are now initialised. The final stack can now
782 * be setup in SDRAM. Code execution will continue in Flash, but
783 * with the stack in SDRAM and Global Data in temporary memory
784 * (CPU cache)
785 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600786 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000787 board_init_f_r_trampoline(gd->start_addr_sp);
788#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000789 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000790#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000791
792 return 0;
793}
794#endif
795
796/* Record the board_init_f() bootstage (after arch_cpu_init()) */
797static int mark_bootstage(void)
798{
799 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
800
801 return 0;
802}
803
Simon Glass9854a872015-11-08 23:47:48 -0700804static int initf_console_record(void)
805{
806#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
807 return console_record_init();
808#else
809 return 0;
810#endif
811}
812
Simon Glassab7cd622014-07-23 06:55:04 -0600813static int initf_dm(void)
814{
815#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
816 int ret;
817
818 ret = dm_init_and_scan(true);
819 if (ret)
820 return ret;
821#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700822#ifdef CONFIG_TIMER_EARLY
823 ret = dm_timer_init();
824 if (ret)
825 return ret;
826#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600827
828 return 0;
829}
830
Simon Glass146251f2015-01-19 22:16:12 -0700831/* Architecture-specific memory reservation */
832__weak int reserve_arch(void)
833{
834 return 0;
835}
836
Simon Glassd4c671c2015-03-05 12:25:16 -0700837__weak int arch_cpu_init_dm(void)
838{
839 return 0;
840}
841
Simon Glass1938f4a2013-03-11 06:49:53 +0000842static init_fnc_t init_sequence_f[] = {
Simon Glassa733b062013-04-26 02:53:43 +0000843#ifdef CONFIG_SANDBOX
844 setup_ram_buf,
845#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000846 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700847#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700848 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700849#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800850#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700851 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800852#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700853 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700854 initf_console_record,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000855#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
856 /* TODO: can this go into arch_cpu_init()? */
857 probecpu,
858#endif
Bin Menga52a068e2015-08-20 06:40:18 -0700859#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
860 x86_fsp_init,
861#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000862 arch_cpu_init, /* basic arch cpu dependent setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600863 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700864 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800865 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000866#if defined(CONFIG_BOARD_EARLY_INIT_F)
867 board_early_init_f,
868#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000869 /* TODO: can any of this go into arch_cpu_init()? */
870#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
871 get_clocks, /* get CPU and bus clocks (etc.) */
872#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
873 && !defined(CONFIG_TQM885D)
874 adjust_sdram_tbs_8xx,
875#endif
876 /* TODO: can we rename this to timer_init()? */
877 init_timebase,
878#endif
Bin Meng2317cf02015-12-08 17:31:40 -0800879#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retiefc97088c2015-10-28 15:18:22 +0200880 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
881 defined(CONFIG_SPARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000882 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000883#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000884#ifdef CONFIG_SYS_ALLOC_DPRAM
885#if !defined(CONFIG_CPM2)
886 dpram_init,
887#endif
888#endif
889#if defined(CONFIG_BOARD_POSTCLK_INIT)
890 board_postclk_init,
891#endif
Peng Fan76648462015-10-30 17:30:02 +0800892#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100893 get_clocks,
894#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000895 env_init, /* initialize environment */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000896#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
897 /* get CPU and bus clocks according to the environment variable */
898 get_clocks_866,
899 /* adjust sdram refresh rate according to the new clock */
900 sdram_adjust_866,
901 init_timebase,
902#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000903 init_baud_rate, /* initialze baudrate settings */
904 serial_init, /* serial communications setup */
905 console_init_f, /* stage 1 init of console */
Simon Glassa733b062013-04-26 02:53:43 +0000906#ifdef CONFIG_SANDBOX
907 sandbox_early_getopt_check,
908#endif
909#ifdef CONFIG_OF_CONTROL
910 fdtdec_prepare_fdt,
Simon Glass48a33802013-03-05 14:39:52 +0000911#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000912 display_options, /* say that we are here */
913 display_text_info, /* show debugging info if required */
Masahiro Yamada58dac322014-03-05 17:40:10 +0900914#if defined(CONFIG_MPC8260)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000915 prt_8260_rsr,
916 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900917#endif /* CONFIG_MPC8260 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000918#if defined(CONFIG_MPC83xx)
919 prt_83xx_rsr,
920#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100921#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000922 checkcpu,
923#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000924 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000925#if defined(CONFIG_MPC5xxx)
926 prt_mpc5xxx_clks,
927#endif /* CONFIG_MPC5xxx */
Simon Glass1938f4a2013-03-11 06:49:53 +0000928#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900929 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000930#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000931 INIT_FUNC_WATCHDOG_INIT
932#if defined(CONFIG_MISC_INIT_F)
933 misc_init_f,
934#endif
935 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100936#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000937 init_func_i2c,
938#endif
939#if defined(CONFIG_HARD_SPI)
940 init_func_spi,
941#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000942 announce_dram_init,
943 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800944#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
945 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glass1938f4a2013-03-11 06:49:53 +0000946 dram_init, /* configure available RAM banks */
947#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100948#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000949 init_func_ram,
950#endif
951#ifdef CONFIG_POST
952 post_init_f,
953#endif
954 INIT_FUNC_WATCHDOG_RESET
955#if defined(CONFIG_SYS_DRAM_TEST)
956 testdram,
957#endif /* CONFIG_SYS_DRAM_TEST */
958 INIT_FUNC_WATCHDOG_RESET
959
Simon Glass1938f4a2013-03-11 06:49:53 +0000960#ifdef CONFIG_POST
961 init_post,
962#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000963 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000964 /*
965 * Now that we have DRAM mapped and working, we can
966 * relocate the code and continue running from DRAM.
967 *
968 * Reserve memory at end of RAM for (top down in that order):
969 * - area that won't get touched by U-Boot and Linux (optional)
970 * - kernel log buffer
971 * - protected RAM
972 * - LCD framebuffer
973 * - monitor code
974 * - board info struct
975 */
976 setup_dest_addr,
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300977#if defined(CONFIG_BLACKFIN) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800978 /* Blackfin u-boot monitor should be on top of the ram */
979 reserve_uboot,
980#endif
Francois Retief1e85cce2015-11-23 13:05:44 +0200981#if defined(CONFIG_SPARC)
982 reserve_prom,
983#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000984#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
985 reserve_logbuffer,
986#endif
987#ifdef CONFIG_PRAM
988 reserve_pram,
989#endif
990 reserve_round_4k,
991#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
992 defined(CONFIG_ARM)
993 reserve_mmu,
994#endif
Simon Glass5a541942016-01-18 19:52:21 -0700995#ifdef CONFIG_DM_VIDEO
996 reserve_video,
997#else
998# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000999 reserve_lcd,
Simon Glass5a541942016-01-18 19:52:21 -07001000# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +00001001 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glass5a541942016-01-18 19:52:21 -07001002# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangd54d7eb2014-07-17 19:01:34 +08001003 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.it944ab342015-03-28 11:34:52 +01001004 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass5a541942016-01-18 19:52:21 -07001005 reserve_legacy_video,
1006# endif
1007#endif /* CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -07001008 reserve_trace,
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001009#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_XTENSA)
Simon Glass1938f4a2013-03-11 06:49:53 +00001010 reserve_uboot,
Sonic Zhangd54d7eb2014-07-17 19:01:34 +08001011#endif
Simon Glass8cae8a62013-03-05 14:39:45 +00001012#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +00001013 reserve_malloc,
1014 reserve_board,
Simon Glass8cae8a62013-03-05 14:39:45 +00001015#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001016 setup_machine,
1017 reserve_global_data,
1018 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -07001019 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +00001020 reserve_stacks,
1021 setup_dram_config,
1022 show_dram_config,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001023#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001024 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001025#endif
1026#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001027 INIT_FUNC_WATCHDOG_RESET
1028 setup_board_part2,
1029#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001030 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +00001031#ifdef CONFIG_SYS_EXTBDINFO
1032 setup_board_extra,
1033#endif
1034 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +00001035 reloc_fdt,
1036 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001037#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -07001038 copy_uboot_to_ram,
1039 clear_bss,
1040 do_elf_reloc_fixups,
1041#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001042#if defined(CONFIG_XTENSA)
1043 clear_bss,
1044#endif
Simon Glass808434c2013-11-10 10:26:59 -07001045#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +00001046 jump_to_copy,
1047#endif
1048 NULL,
1049};
1050
1051void board_init_f(ulong boot_flags)
1052{
York Sun2a1680e2014-05-02 17:28:04 -07001053#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1054 /*
1055 * For some archtectures, global data is initialized and used before
1056 * calling this function. The data should be preserved. For others,
1057 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1058 * here to host global data until relocation.
1059 */
Simon Glass1938f4a2013-03-11 06:49:53 +00001060 gd_t data;
1061
1062 gd = &data;
1063
David Fengcce6be72013-12-14 11:47:36 +08001064 /*
1065 * Clear global data before it is accessed at debug print
1066 * in initcall_run_list. Otherwise the debug print probably
1067 * get the wrong vaule of gd->have_console.
1068 */
David Fengcce6be72013-12-14 11:47:36 +08001069 zero_global_data();
1070#endif
1071
Simon Glass1938f4a2013-03-11 06:49:53 +00001072 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001073 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001074
1075 if (initcall_run_list(init_sequence_f))
1076 hang();
1077
Ben Stoltz9b217492015-07-31 09:31:37 -06001078#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1079 !defined(CONFIG_EFI_APP)
Simon Glass1938f4a2013-03-11 06:49:53 +00001080 /* NOTREACHED - jump_to_copy() does not return */
1081 hang();
1082#endif
1083}
1084
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001085#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +00001086/*
1087 * For now this code is only used on x86.
1088 *
1089 * init_sequence_f_r is the list of init functions which are run when
1090 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1091 * The following limitations must be considered when implementing an
1092 * '_f_r' function:
1093 * - 'static' variables are read-only
1094 * - Global Data (gd->xxx) is read/write
1095 *
1096 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1097 * supported). It _should_, if possible, copy global data to RAM and
1098 * initialise the CPU caches (to speed up the relocation process)
1099 *
1100 * NOTE: At present only x86 uses this route, but it is intended that
1101 * all archs will move to this when generic relocation is implemented.
1102 */
1103static init_fnc_t init_sequence_f_r[] = {
1104 init_cache_f_r,
Simon Glass48a33802013-03-05 14:39:52 +00001105
1106 NULL,
1107};
1108
1109void board_init_f_r(void)
1110{
1111 if (initcall_run_list(init_sequence_f_r))
1112 hang();
1113
1114 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001115 * The pre-relocation drivers may be using memory that has now gone
1116 * away. Mark serial as unavailable - this will fall back to the debug
1117 * UART if available.
1118 */
1119 gd->flags &= ~GD_FLG_SERIAL_READY;
1120
1121 /*
Simon Glass48a33802013-03-05 14:39:52 +00001122 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1123 * Transfer execution from Flash to RAM by calculating the address
1124 * of the in-RAM copy of board_init_r() and calling it
1125 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001126 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001127
1128 /* NOTREACHED - board_init_r() does not return */
1129 hang();
1130}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001131#endif /* CONFIG_X86 */