blob: 99c0b5ac78107f16ed203fb5a0a4b05217ca26be [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>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090052#include <linux/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;
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200279#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800280 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
Paul Burton8ebf5062016-09-21 11:18:46 +0100293__weak int mach_cpu_init(void)
294{
295 return 0;
296}
297
Simon Glassa733b062013-04-26 02:53:43 +0000298#ifdef CONFIG_SANDBOX
299static int setup_ram_buf(void)
300{
Simon Glass5c2859c2013-11-10 10:27:03 -0700301 struct sandbox_state *state = state_get_current();
302
303 gd->arch.ram_buf = state->ram_buf;
304 gd->ram_size = state->ram_size;
Simon Glassa733b062013-04-26 02:53:43 +0000305
306 return 0;
307}
308#endif
309
Simon Glass1938f4a2013-03-11 06:49:53 +0000310/* Get the top of usable RAM */
311__weak ulong board_get_usable_ram_top(ulong total_size)
312{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700313#ifdef CONFIG_SYS_SDRAM_BASE
314 /*
Simon Glass4c509342015-04-28 20:25:03 -0600315 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700316 * 32-bit address space. If so, clip the usable RAM so it doesn't.
317 */
318 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
319 /*
320 * Will wrap back to top of 32-bit space when reservations
321 * are made.
322 */
323 return 0;
324#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000325 return gd->ram_top;
326}
327
York Sunaabd7dd2015-12-07 11:05:29 -0800328__weak phys_size_t board_reserve_ram_top(phys_size_t ram_size)
329{
330#ifdef CONFIG_SYS_MEM_TOP_HIDE
331 return ram_size - CONFIG_SYS_MEM_TOP_HIDE;
332#else
333 return ram_size;
334#endif
335}
336
Simon Glass1938f4a2013-03-11 06:49:53 +0000337static int setup_dest_addr(void)
338{
339 debug("Monitor len: %08lX\n", gd->mon_len);
340 /*
341 * Ram is setup, size stored in gd !!
342 */
343 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sune8149522015-12-04 11:57:07 -0800344#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
345 /* Reserve memory for secure MMU tables, and/or security monitor */
346 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
347 /*
348 * Record secure memory location. Need recalcuate if memory splits
349 * into banks, or the ram base is not zero.
350 */
York Sune61a7532016-06-24 16:46:18 -0700351 gd->arch.secure_ram = gd->ram_size;
York Sune8149522015-12-04 11:57:07 -0800352#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000353 /*
354 * Subtract specified amount of memory to hide so that it won't
355 * get "touched" at all by U-Boot. By fixing up gd->ram_size
356 * the Linux kernel should now get passed the now "corrected"
York Sunaabd7dd2015-12-07 11:05:29 -0800357 * memory size and won't touch it either. This has been used
358 * by arch/powerpc exclusively. Now ARMv8 takes advantage of
359 * thie mechanism. If memory is split into banks, addresses
360 * need to be calculated.
Simon Glass1938f4a2013-03-11 06:49:53 +0000361 */
York Sunaabd7dd2015-12-07 11:05:29 -0800362 gd->ram_size = board_reserve_ram_top(gd->ram_size);
363
Simon Glass1938f4a2013-03-11 06:49:53 +0000364#ifdef CONFIG_SYS_SDRAM_BASE
365 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
366#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000367 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000368 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000369 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000370 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700371#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000372 /*
373 * We need to make sure the location we intend to put secondary core
374 * boot code is reserved and not used by any part of u-boot
375 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000376 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
377 gd->relocaddr = determine_mp_bootpg(NULL);
378 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000379 }
380#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000381 return 0;
382}
383
Francois Retief1e85cce2015-11-23 13:05:44 +0200384#if defined(CONFIG_SPARC)
385static int reserve_prom(void)
386{
387 /* defined in arch/sparc/cpu/leon?/prom.c */
388 extern void *__prom_start_reloc;
389 int size = 8192; /* page table = 2k, prom = 6k */
390 gd->relocaddr -= size;
391 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
392 debug("Reserving %dk for PROM and page table at %08lx\n", size,
393 gd->relocaddr);
394 return 0;
395}
396#endif
397
Simon Glass1938f4a2013-03-11 06:49:53 +0000398#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
399static int reserve_logbuffer(void)
400{
401 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000402 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000403 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000404 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000405 return 0;
406}
407#endif
408
409#ifdef CONFIG_PRAM
410/* reserve protected RAM */
411static int reserve_pram(void)
412{
413 ulong reg;
414
415 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000416 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000417 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000418 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000419 return 0;
420}
421#endif /* CONFIG_PRAM */
422
423/* Round memory pointer down to next 4 kB limit */
424static int reserve_round_4k(void)
425{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000426 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000427 return 0;
428}
429
430#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
431 defined(CONFIG_ARM)
432static int reserve_mmu(void)
433{
434 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800435 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000436 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000437
438 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000439 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000440
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000441 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000442 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
443 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700444
445#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
446 /*
447 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
448 * with location within secure ram.
449 */
450 gd->arch.tlb_allocated = gd->arch.tlb_addr;
451#endif
452
Simon Glass1938f4a2013-03-11 06:49:53 +0000453 return 0;
454}
455#endif
456
Simon Glass5a541942016-01-18 19:52:21 -0700457#ifdef CONFIG_DM_VIDEO
458static int reserve_video(void)
459{
460 ulong addr;
461 int ret;
462
463 addr = gd->relocaddr;
464 ret = video_reserve(&addr);
465 if (ret)
466 return ret;
467 gd->relocaddr = addr;
468
469 return 0;
470}
471#else
472
473# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000474static int reserve_lcd(void)
475{
Simon Glass5a541942016-01-18 19:52:21 -0700476# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000477 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700478# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000479 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000480 gd->relocaddr = lcd_setmem(gd->relocaddr);
481 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700482# endif /* CONFIG_FB_ADDR */
483
Simon Glass1938f4a2013-03-11 06:49:53 +0000484 return 0;
485}
Simon Glass5a541942016-01-18 19:52:21 -0700486# endif /* CONFIG_LCD */
Simon Glass1938f4a2013-03-11 06:49:53 +0000487
Simon Glass5a541942016-01-18 19:52:21 -0700488# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700489 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
490 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
491static int reserve_legacy_video(void)
492{
493 /* reserve memory for video display (always full pages) */
494 gd->relocaddr = video_setmem(gd->relocaddr);
495 gd->fb_base = gd->relocaddr;
496
497 return 0;
498}
Simon Glass5a541942016-01-18 19:52:21 -0700499# endif
500#endif /* !CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700501
Simon Glass71c52db2013-06-11 11:14:42 -0700502static int reserve_trace(void)
503{
504#ifdef CONFIG_TRACE
505 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
506 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
507 debug("Reserving %dk for trace data at: %08lx\n",
508 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
509#endif
510
511 return 0;
512}
513
Simon Glass1938f4a2013-03-11 06:49:53 +0000514static int reserve_uboot(void)
515{
516 /*
517 * reserve memory for U-Boot code, data & bss
518 * round down to next 4 kB limit
519 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000520 gd->relocaddr -= gd->mon_len;
521 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000522#ifdef CONFIG_E500
523 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000524 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000525#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000526
527 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000528 gd->relocaddr);
529
530 gd->start_addr_sp = gd->relocaddr;
531
Simon Glass1938f4a2013-03-11 06:49:53 +0000532 return 0;
533}
534
Simon Glass8cae8a62013-03-05 14:39:45 +0000535#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +0000536/* reserve memory for malloc() area */
537static int reserve_malloc(void)
538{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000539 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000540 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000541 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000542 return 0;
543}
544
545/* (permanently) allocate a Board Info struct */
546static int reserve_board(void)
547{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800548 if (!gd->bd) {
549 gd->start_addr_sp -= sizeof(bd_t);
550 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
551 memset(gd->bd, '\0', sizeof(bd_t));
552 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
553 sizeof(bd_t), gd->start_addr_sp);
554 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000555 return 0;
556}
Simon Glass8cae8a62013-03-05 14:39:45 +0000557#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000558
559static int setup_machine(void)
560{
561#ifdef CONFIG_MACH_TYPE
562 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
563#endif
564 return 0;
565}
566
567static int reserve_global_data(void)
568{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000569 gd->start_addr_sp -= sizeof(gd_t);
570 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000571 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000572 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000573 return 0;
574}
575
576static int reserve_fdt(void)
577{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100578#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000579 /*
Simon Glass4c509342015-04-28 20:25:03 -0600580 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000581 * must relocate it. If it is embedded in the data section, then it
582 * will be relocated with other data.
583 */
584 if (gd->fdt_blob) {
585 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
586
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000587 gd->start_addr_sp -= gd->fdt_size;
588 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000589 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000590 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000591 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100592#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000593
594 return 0;
595}
596
Andreas Bießmann68145d42015-02-06 23:06:45 +0100597int arch_reserve_stacks(void)
598{
599 return 0;
600}
601
Simon Glass1938f4a2013-03-11 06:49:53 +0000602static int reserve_stacks(void)
603{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100604 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000605 gd->start_addr_sp -= 16;
606 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000607
608 /*
Simon Glass4c509342015-04-28 20:25:03 -0600609 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100610 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000611 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100612 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000613}
614
615static int display_new_sp(void)
616{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000617 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000618
619 return 0;
620}
621
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200622#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
623 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000624static int setup_board_part1(void)
625{
626 bd_t *bd = gd->bd;
627
628 /*
629 * Save local variables to board info struct
630 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000631 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
632 bd->bi_memsize = gd->ram_size; /* size in bytes */
633
634#ifdef CONFIG_SYS_SRAM_BASE
635 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
636 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
637#endif
638
Masahiro Yamada58dac322014-03-05 17:40:10 +0900639#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000640 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
641 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
642#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100643#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000644 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
645#endif
646#if defined(CONFIG_MPC83xx)
647 bd->bi_immrbar = CONFIG_SYS_IMMR;
648#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000649
650 return 0;
651}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100652#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000653
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100654#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000655static int setup_board_part2(void)
656{
657 bd_t *bd = gd->bd;
658
659 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
660 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
661#if defined(CONFIG_CPM2)
662 bd->bi_cpmfreq = gd->arch.cpm_clk;
663 bd->bi_brgfreq = gd->arch.brg_clk;
664 bd->bi_sccfreq = gd->arch.scc_clk;
665 bd->bi_vco = gd->arch.vco_out;
666#endif /* CONFIG_CPM2 */
667#if defined(CONFIG_MPC512X)
668 bd->bi_ipsfreq = gd->arch.ips_clk;
669#endif /* CONFIG_MPC512X */
670#if defined(CONFIG_MPC5xxx)
671 bd->bi_ipbfreq = gd->arch.ipb_clk;
672 bd->bi_pcifreq = gd->pci_clk;
673#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800674#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
675 bd->bi_pcifreq = gd->pci_clk;
676#endif
677#if defined(CONFIG_EXTRA_CLOCK)
678 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
679 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
680 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
681#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000682
683 return 0;
684}
685#endif
686
687#ifdef CONFIG_SYS_EXTBDINFO
688static int setup_board_extra(void)
689{
690 bd_t *bd = gd->bd;
691
692 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
693 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
694 sizeof(bd->bi_r_version));
695
696 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
697 bd->bi_plb_busfreq = gd->bus_clk;
698#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
699 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
700 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
701 bd->bi_pci_busfreq = get_PCI_freq();
702 bd->bi_opbfreq = get_OPB_freq();
703#elif defined(CONFIG_XILINX_405)
704 bd->bi_pci_busfreq = get_PCI_freq();
705#endif
706
707 return 0;
708}
709#endif
710
Simon Glass1938f4a2013-03-11 06:49:53 +0000711#ifdef CONFIG_POST
712static int init_post(void)
713{
714 post_bootmode_init();
715 post_run(NULL, POST_ROM | post_bootmode_get(0));
716
717 return 0;
718}
719#endif
720
Simon Glass1938f4a2013-03-11 06:49:53 +0000721static int setup_dram_config(void)
722{
723 /* Ram is board specific, so move it to board code ... */
724 dram_init_banksize();
725
726 return 0;
727}
728
729static int reloc_fdt(void)
730{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100731#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600732 if (gd->flags & GD_FLG_SKIP_RELOC)
733 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000734 if (gd->new_fdt) {
735 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
736 gd->fdt_blob = gd->new_fdt;
737 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100738#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000739
740 return 0;
741}
742
743static int setup_reloc(void)
744{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600745 if (gd->flags & GD_FLG_SKIP_RELOC) {
746 debug("Skipping relocation due to flag\n");
747 return 0;
748 }
749
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800750#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000751 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100752#ifdef CONFIG_M68K
753 /*
754 * On all ColdFire arch cpu, monitor code starts always
755 * just after the default vector table location, so at 0x400
756 */
757 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
758#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800759#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000760 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
761
762 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000763 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000764 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
765 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000766
767 return 0;
768}
769
770/* ARM calls relocate_code from its crt0.S */
Simon Glass808434c2013-11-10 10:26:59 -0700771#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +0000772
773static int jump_to_copy(void)
774{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600775 if (gd->flags & GD_FLG_SKIP_RELOC)
776 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000777 /*
778 * x86 is special, but in a nice way. It uses a trampoline which
779 * enables the dcache if possible.
780 *
781 * For now, other archs use relocate_code(), which is implemented
782 * similarly for all archs. When we do generic relocation, hopefully
783 * we can make all archs enable the dcache prior to relocation.
784 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300785#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000786 /*
787 * SDRAM and console are now initialised. The final stack can now
788 * be setup in SDRAM. Code execution will continue in Flash, but
789 * with the stack in SDRAM and Global Data in temporary memory
790 * (CPU cache)
791 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600792 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000793 board_init_f_r_trampoline(gd->start_addr_sp);
794#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000795 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000796#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000797
798 return 0;
799}
800#endif
801
802/* Record the board_init_f() bootstage (after arch_cpu_init()) */
803static int mark_bootstage(void)
804{
805 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
806
807 return 0;
808}
809
Simon Glass9854a872015-11-08 23:47:48 -0700810static int initf_console_record(void)
811{
812#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
813 return console_record_init();
814#else
815 return 0;
816#endif
817}
818
Simon Glassab7cd622014-07-23 06:55:04 -0600819static int initf_dm(void)
820{
821#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
822 int ret;
823
824 ret = dm_init_and_scan(true);
825 if (ret)
826 return ret;
827#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700828#ifdef CONFIG_TIMER_EARLY
829 ret = dm_timer_init();
830 if (ret)
831 return ret;
832#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600833
834 return 0;
835}
836
Simon Glass146251f2015-01-19 22:16:12 -0700837/* Architecture-specific memory reservation */
838__weak int reserve_arch(void)
839{
840 return 0;
841}
842
Simon Glassd4c671c2015-03-05 12:25:16 -0700843__weak int arch_cpu_init_dm(void)
844{
845 return 0;
846}
847
Simon Glass1938f4a2013-03-11 06:49:53 +0000848static init_fnc_t init_sequence_f[] = {
Simon Glassa733b062013-04-26 02:53:43 +0000849#ifdef CONFIG_SANDBOX
850 setup_ram_buf,
851#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000852 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700853#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700854 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700855#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800856#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700857 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800858#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700859 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700860 initf_console_record,
Bin Menga52a068e2015-08-20 06:40:18 -0700861#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
862 x86_fsp_init,
863#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000864 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100865 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600866 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700867 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800868 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000869#if defined(CONFIG_BOARD_EARLY_INIT_F)
870 board_early_init_f,
871#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000872 /* TODO: can any of this go into arch_cpu_init()? */
873#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
874 get_clocks, /* get CPU and bus clocks (etc.) */
875#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
876 && !defined(CONFIG_TQM885D)
877 adjust_sdram_tbs_8xx,
878#endif
879 /* TODO: can we rename this to timer_init()? */
880 init_timebase,
881#endif
Bin Meng2317cf02015-12-08 17:31:40 -0800882#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retiefc97088c2015-10-28 15:18:22 +0200883 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200884 defined(CONFIG_SH) || defined(CONFIG_SPARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000885 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000886#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000887#if defined(CONFIG_BOARD_POSTCLK_INIT)
888 board_postclk_init,
889#endif
Peng Fan76648462015-10-30 17:30:02 +0800890#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100891 get_clocks,
892#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000893 env_init, /* initialize environment */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000894#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
895 /* get CPU and bus clocks according to the environment variable */
896 get_clocks_866,
897 /* adjust sdram refresh rate according to the new clock */
898 sdram_adjust_866,
899 init_timebase,
900#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000901 init_baud_rate, /* initialze baudrate settings */
902 serial_init, /* serial communications setup */
903 console_init_f, /* stage 1 init of console */
Simon Glassa733b062013-04-26 02:53:43 +0000904#ifdef CONFIG_SANDBOX
905 sandbox_early_getopt_check,
906#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000907 display_options, /* say that we are here */
908 display_text_info, /* show debugging info if required */
Masahiro Yamada58dac322014-03-05 17:40:10 +0900909#if defined(CONFIG_MPC8260)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000910 prt_8260_rsr,
911 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900912#endif /* CONFIG_MPC8260 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000913#if defined(CONFIG_MPC83xx)
914 prt_83xx_rsr,
915#endif
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200916#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000917 checkcpu,
918#endif
Simon Glasscc664002017-01-23 13:31:25 -0700919#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000920 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700921#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000922#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900923 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000924#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000925 INIT_FUNC_WATCHDOG_INIT
926#if defined(CONFIG_MISC_INIT_F)
927 misc_init_f,
928#endif
929 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100930#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000931 init_func_i2c,
932#endif
933#if defined(CONFIG_HARD_SPI)
934 init_func_spi,
935#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000936 announce_dram_init,
937 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800938#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200939 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
940 defined(CONFIG_SH)
Simon Glass1938f4a2013-03-11 06:49:53 +0000941 dram_init, /* configure available RAM banks */
942#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100943#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000944 init_func_ram,
945#endif
946#ifdef CONFIG_POST
947 post_init_f,
948#endif
949 INIT_FUNC_WATCHDOG_RESET
950#if defined(CONFIG_SYS_DRAM_TEST)
951 testdram,
952#endif /* CONFIG_SYS_DRAM_TEST */
953 INIT_FUNC_WATCHDOG_RESET
954
Simon Glass1938f4a2013-03-11 06:49:53 +0000955#ifdef CONFIG_POST
956 init_post,
957#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000958 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000959 /*
960 * Now that we have DRAM mapped and working, we can
961 * relocate the code and continue running from DRAM.
962 *
963 * Reserve memory at end of RAM for (top down in that order):
964 * - area that won't get touched by U-Boot and Linux (optional)
965 * - kernel log buffer
966 * - protected RAM
967 * - LCD framebuffer
968 * - monitor code
969 * - board info struct
970 */
971 setup_dest_addr,
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300972#if defined(CONFIG_BLACKFIN) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800973 /* Blackfin u-boot monitor should be on top of the ram */
974 reserve_uboot,
975#endif
Francois Retief1e85cce2015-11-23 13:05:44 +0200976#if defined(CONFIG_SPARC)
977 reserve_prom,
978#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000979#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
980 reserve_logbuffer,
981#endif
982#ifdef CONFIG_PRAM
983 reserve_pram,
984#endif
985 reserve_round_4k,
986#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
987 defined(CONFIG_ARM)
988 reserve_mmu,
989#endif
Simon Glass5a541942016-01-18 19:52:21 -0700990#ifdef CONFIG_DM_VIDEO
991 reserve_video,
992#else
993# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000994 reserve_lcd,
Simon Glass5a541942016-01-18 19:52:21 -0700995# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000996 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glass5a541942016-01-18 19:52:21 -0700997# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800998 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.it944ab342015-03-28 11:34:52 +0100999 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass5a541942016-01-18 19:52:21 -07001000 reserve_legacy_video,
1001# endif
1002#endif /* CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -07001003 reserve_trace,
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001004#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_XTENSA)
Simon Glass1938f4a2013-03-11 06:49:53 +00001005 reserve_uboot,
Sonic Zhangd54d7eb2014-07-17 19:01:34 +08001006#endif
Simon Glass8cae8a62013-03-05 14:39:45 +00001007#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +00001008 reserve_malloc,
1009 reserve_board,
Simon Glass8cae8a62013-03-05 14:39:45 +00001010#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001011 setup_machine,
1012 reserve_global_data,
1013 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -07001014 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +00001015 reserve_stacks,
1016 setup_dram_config,
1017 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +02001018#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
1019 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001020 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001021#endif
1022#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001023 INIT_FUNC_WATCHDOG_RESET
1024 setup_board_part2,
1025#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001026 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +00001027#ifdef CONFIG_SYS_EXTBDINFO
1028 setup_board_extra,
1029#endif
1030 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +00001031 reloc_fdt,
1032 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001033#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -07001034 copy_uboot_to_ram,
1035 clear_bss,
1036 do_elf_reloc_fixups,
1037#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001038#if defined(CONFIG_XTENSA)
1039 clear_bss,
1040#endif
Simon Glass808434c2013-11-10 10:26:59 -07001041#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +00001042 jump_to_copy,
1043#endif
1044 NULL,
1045};
1046
1047void board_init_f(ulong boot_flags)
1048{
York Sun2a1680e2014-05-02 17:28:04 -07001049#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1050 /*
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -04001051 * For some architectures, global data is initialized and used before
York Sun2a1680e2014-05-02 17:28:04 -07001052 * calling this function. The data should be preserved. For others,
1053 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1054 * here to host global data until relocation.
1055 */
Simon Glass1938f4a2013-03-11 06:49:53 +00001056 gd_t data;
1057
1058 gd = &data;
1059
David Fengcce6be72013-12-14 11:47:36 +08001060 /*
1061 * Clear global data before it is accessed at debug print
1062 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -04001063 * get the wrong value of gd->have_console.
David Fengcce6be72013-12-14 11:47:36 +08001064 */
David Fengcce6be72013-12-14 11:47:36 +08001065 zero_global_data();
1066#endif
1067
Simon Glass1938f4a2013-03-11 06:49:53 +00001068 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001069 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001070
1071 if (initcall_run_list(init_sequence_f))
1072 hang();
1073
Ben Stoltz9b217492015-07-31 09:31:37 -06001074#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1075 !defined(CONFIG_EFI_APP)
Simon Glass1938f4a2013-03-11 06:49:53 +00001076 /* NOTREACHED - jump_to_copy() does not return */
1077 hang();
1078#endif
1079}
1080
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001081#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +00001082/*
1083 * For now this code is only used on x86.
1084 *
1085 * init_sequence_f_r is the list of init functions which are run when
1086 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1087 * The following limitations must be considered when implementing an
1088 * '_f_r' function:
1089 * - 'static' variables are read-only
1090 * - Global Data (gd->xxx) is read/write
1091 *
1092 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1093 * supported). It _should_, if possible, copy global data to RAM and
1094 * initialise the CPU caches (to speed up the relocation process)
1095 *
1096 * NOTE: At present only x86 uses this route, but it is intended that
1097 * all archs will move to this when generic relocation is implemented.
1098 */
1099static init_fnc_t init_sequence_f_r[] = {
1100 init_cache_f_r,
Simon Glass48a33802013-03-05 14:39:52 +00001101
1102 NULL,
1103};
1104
1105void board_init_f_r(void)
1106{
1107 if (initcall_run_list(init_sequence_f_r))
1108 hang();
1109
1110 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001111 * The pre-relocation drivers may be using memory that has now gone
1112 * away. Mark serial as unavailable - this will fall back to the debug
1113 * UART if available.
1114 */
1115 gd->flags &= ~GD_FLG_SERIAL_READY;
1116
1117 /*
Simon Glass48a33802013-03-05 14:39:52 +00001118 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1119 * Transfer execution from Flash to RAM by calculating the address
1120 * of the in-RAM copy of board_init_r() and calling it
1121 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001122 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001123
1124 /* NOTREACHED - board_init_r() does not return */
1125 hang();
1126}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001127#endif /* CONFIG_X86 */