blob: 75a0fc5df0788de3f0a4df8820d5b1839416383d [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 Glassab7cd622014-07-23 06:55:04 -060061#include <dm/root.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000062#include <linux/compiler.h>
63
64/*
65 * Pointer to initial global data area
66 *
67 * Here we initialize it if needed.
68 */
69#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
70#undef XTRN_DECLARE_GLOBAL_DATA_PTR
71#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
72DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
73#else
74DECLARE_GLOBAL_DATA_PTR;
75#endif
76
77/*
Simon Glass4c509342015-04-28 20:25:03 -060078 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000079 * refactored to a single function, something like:
80 *
81 * void led_set_state(enum led_colour_t colour, int on);
82 */
83/************************************************************************
84 * Coloured LED functionality
85 ************************************************************************
86 * May be supplied by boards if desired
87 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020088__weak void coloured_LED_init(void) {}
89__weak void red_led_on(void) {}
90__weak void red_led_off(void) {}
91__weak void green_led_on(void) {}
92__weak void green_led_off(void) {}
93__weak void yellow_led_on(void) {}
94__weak void yellow_led_off(void) {}
95__weak void blue_led_on(void) {}
96__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000097
98/*
99 * Why is gd allocated a register? Prior to reloc it might be better to
100 * just pass it around to each function in this file?
101 *
102 * After reloc one could argue that it is hardly used and doesn't need
103 * to be in a register. Or if it is it should perhaps hold pointers to all
104 * global data for all modules, so that post-reloc we can avoid the massive
105 * literal pool we get on ARM. Or perhaps just encourage each module to use
106 * a structure...
107 */
108
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800109#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000110static int init_func_watchdog_init(void)
111{
Tom Riniea3310e2017-03-14 11:08:10 -0400112# if defined(CONFIG_HW_WATCHDOG) && \
113 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100114 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200115 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100116 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800117 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000118 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200119# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000120 WATCHDOG_RESET();
121
122 return 0;
123}
124
125int init_func_watchdog_reset(void)
126{
127 WATCHDOG_RESET();
128
129 return 0;
130}
131#endif /* CONFIG_WATCHDOG */
132
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200133__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000134{
135 /* please define platform specific board_add_ram_info() */
136}
137
Simon Glass1938f4a2013-03-11 06:49:53 +0000138static int init_baud_rate(void)
139{
140 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
141 return 0;
142}
143
144static int display_text_info(void)
145{
Ben Stoltz9b217492015-07-31 09:31:37 -0600146#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100147 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000148
Simon Glass632efa72013-03-11 07:06:48 +0000149 bss_start = (ulong)&__bss_start;
150 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100151
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800152#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100153 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800154#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100155 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800156#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100157
158 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
159 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000160#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000161
Simon Glass1938f4a2013-03-11 06:49:53 +0000162#ifdef CONFIG_USE_IRQ
163 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
164 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
165#endif
166
167 return 0;
168}
169
170static int announce_dram_init(void)
171{
172 puts("DRAM: ");
173 return 0;
174}
175
angelo@sysam.ite310b932015-02-12 01:40:17 +0100176#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000177static int init_func_ram(void)
178{
Simon Glass088454c2017-03-31 08:40:25 -0600179 return initdram();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000180}
181#endif
182
Simon Glass1938f4a2013-03-11 06:49:53 +0000183static int show_dram_config(void)
184{
York Sunfa39ffe2014-05-02 17:28:05 -0700185 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000186
187#ifdef CONFIG_NR_DRAM_BANKS
188 int i;
189
190 debug("\nRAM Configuration:\n");
191 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
192 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700193 debug("Bank #%d: %llx ", i,
194 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000195#ifdef DEBUG
196 print_size(gd->bd->bi_dram[i].size, "\n");
197#endif
198 }
199 debug("\nDRAM: ");
200#else
201 size = gd->ram_size;
202#endif
203
Simon Glasse4fef6c2013-03-11 14:30:42 +0000204 print_size(size, "");
205 board_add_ram_info(0);
206 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000207
208 return 0;
209}
210
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200211__weak void dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000212{
213#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
214 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
215 gd->bd->bi_dram[0].size = get_effective_memsize();
216#endif
217}
218
Heiko Schocherea818db2013-01-29 08:53:15 +0100219#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000220static int init_func_i2c(void)
221{
222 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200223#ifdef CONFIG_SYS_I2C
224 i2c_init_all();
225#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000226 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200227#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000228 puts("ready\n");
229 return 0;
230}
231#endif
232
233#if defined(CONFIG_HARD_SPI)
234static int init_func_spi(void)
235{
236 puts("SPI: ");
237 spi_init();
238 puts("ready\n");
239 return 0;
240}
241#endif
242
243__maybe_unused
Simon Glass1938f4a2013-03-11 06:49:53 +0000244static int zero_global_data(void)
245{
246 memset((void *)gd, '\0', sizeof(gd_t));
247
248 return 0;
249}
250
251static int setup_mon_len(void)
252{
Michal Simeke945f6d2014-05-08 16:08:44 +0200253#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100254 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600255#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000256 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400257#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800258 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200259#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800260 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600261#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000262 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
263 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000264#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000265 return 0;
266}
267
268__weak int arch_cpu_init(void)
269{
270 return 0;
271}
272
Paul Burton8ebf5062016-09-21 11:18:46 +0100273__weak int mach_cpu_init(void)
274{
275 return 0;
276}
277
Simon Glass1938f4a2013-03-11 06:49:53 +0000278/* Get the top of usable RAM */
279__weak ulong board_get_usable_ram_top(ulong total_size)
280{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700281#ifdef CONFIG_SYS_SDRAM_BASE
282 /*
Simon Glass4c509342015-04-28 20:25:03 -0600283 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700284 * 32-bit address space. If so, clip the usable RAM so it doesn't.
285 */
286 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
287 /*
288 * Will wrap back to top of 32-bit space when reservations
289 * are made.
290 */
291 return 0;
292#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000293 return gd->ram_top;
294}
295
296static int setup_dest_addr(void)
297{
298 debug("Monitor len: %08lX\n", gd->mon_len);
299 /*
300 * Ram is setup, size stored in gd !!
301 */
302 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800303#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000304 /*
305 * Subtract specified amount of memory to hide so that it won't
306 * get "touched" at all by U-Boot. By fixing up gd->ram_size
307 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800308 * memory size and won't touch it either. This should work
309 * for arch/ppc and arch/powerpc. Only Linux board ports in
310 * arch/powerpc with bootwrapper support, that recalculate the
311 * memory size from the SDRAM controller setup will have to
312 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000313 */
York Sun36cc0de2017-03-06 09:02:28 -0800314 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
315#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000316#ifdef CONFIG_SYS_SDRAM_BASE
317 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
318#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000319 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000320 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000321 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000322 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700323#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000324 /*
325 * We need to make sure the location we intend to put secondary core
326 * boot code is reserved and not used by any part of u-boot
327 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000328 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
329 gd->relocaddr = determine_mp_bootpg(NULL);
330 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000331 }
332#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000333 return 0;
334}
335
Simon Glassb56db482017-03-31 08:40:28 -0600336#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000337static int reserve_logbuffer(void)
338{
Simon Glassb56db482017-03-31 08:40:28 -0600339#ifndef CONFIG_ALT_LB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000340 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000341 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000342 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000343 gd->relocaddr);
Simon Glassb56db482017-03-31 08:40:28 -0600344#endif
345
Simon Glass1938f4a2013-03-11 06:49:53 +0000346 return 0;
347}
348#endif
349
350#ifdef CONFIG_PRAM
351/* reserve protected RAM */
352static int reserve_pram(void)
353{
354 ulong reg;
355
356 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000357 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000358 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000359 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 return 0;
361}
362#endif /* CONFIG_PRAM */
363
364/* Round memory pointer down to next 4 kB limit */
365static int reserve_round_4k(void)
366{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000367 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000368 return 0;
369}
370
Simon Glass80d4bcd2017-03-31 08:40:29 -0600371#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000372static int reserve_mmu(void)
373{
Simon Glass80d4bcd2017-03-31 08:40:29 -0600374#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000375 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800376 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000377 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000378
379 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000380 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000381
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000382 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000383 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
384 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700385
386#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
387 /*
388 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
389 * with location within secure ram.
390 */
391 gd->arch.tlb_allocated = gd->arch.tlb_addr;
392#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600393#endif
York Sun50e93b92016-06-24 16:46:19 -0700394
Simon Glass1938f4a2013-03-11 06:49:53 +0000395 return 0;
396}
397#endif
398
Simon Glass5a541942016-01-18 19:52:21 -0700399static int reserve_video(void)
400{
Simon Glass0f079eb2017-03-31 08:40:30 -0600401#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700402 ulong addr;
403 int ret;
404
405 addr = gd->relocaddr;
406 ret = video_reserve(&addr);
407 if (ret)
408 return ret;
409 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600410#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700411# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000412 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700413# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000414 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000415 gd->relocaddr = lcd_setmem(gd->relocaddr);
416 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700417# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600418#elif defined(CONFIG_VIDEO) && \
419 (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700420 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Riniea3310e2017-03-14 11:08:10 -0400421 !defined(CONFIG_M68K)
Simon Glass8703ef32016-01-18 19:52:20 -0700422 /* reserve memory for video display (always full pages) */
423 gd->relocaddr = video_setmem(gd->relocaddr);
424 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600425#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700426
427 return 0;
428}
Simon Glass8703ef32016-01-18 19:52:20 -0700429
Simon Glass71c52db2013-06-11 11:14:42 -0700430static int reserve_trace(void)
431{
432#ifdef CONFIG_TRACE
433 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
434 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
435 debug("Reserving %dk for trace data at: %08lx\n",
436 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
437#endif
438
439 return 0;
440}
441
Simon Glass1938f4a2013-03-11 06:49:53 +0000442static int reserve_uboot(void)
443{
444 /*
445 * reserve memory for U-Boot code, data & bss
446 * round down to next 4 kB limit
447 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000448 gd->relocaddr -= gd->mon_len;
449 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000450#ifdef CONFIG_E500
451 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000452 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000453#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000454
455 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000456 gd->relocaddr);
457
458 gd->start_addr_sp = gd->relocaddr;
459
Simon Glass1938f4a2013-03-11 06:49:53 +0000460 return 0;
461}
462
463/* reserve memory for malloc() area */
464static int reserve_malloc(void)
465{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000466 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000467 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000468 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000469 return 0;
470}
471
472/* (permanently) allocate a Board Info struct */
473static int reserve_board(void)
474{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800475 if (!gd->bd) {
476 gd->start_addr_sp -= sizeof(bd_t);
477 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
478 memset(gd->bd, '\0', sizeof(bd_t));
479 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
480 sizeof(bd_t), gd->start_addr_sp);
481 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000482 return 0;
483}
484
485static int setup_machine(void)
486{
487#ifdef CONFIG_MACH_TYPE
488 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
489#endif
490 return 0;
491}
492
493static int reserve_global_data(void)
494{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000495 gd->start_addr_sp -= sizeof(gd_t);
496 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000497 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000498 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000499 return 0;
500}
501
502static int reserve_fdt(void)
503{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100504#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000505 /*
Simon Glass4c509342015-04-28 20:25:03 -0600506 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000507 * must relocate it. If it is embedded in the data section, then it
508 * will be relocated with other data.
509 */
510 if (gd->fdt_blob) {
511 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
512
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000513 gd->start_addr_sp -= gd->fdt_size;
514 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000515 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000516 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000517 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100518#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000519
520 return 0;
521}
522
Andreas Bießmann68145d42015-02-06 23:06:45 +0100523int arch_reserve_stacks(void)
524{
525 return 0;
526}
527
Simon Glass1938f4a2013-03-11 06:49:53 +0000528static int reserve_stacks(void)
529{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100530 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000531 gd->start_addr_sp -= 16;
532 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000533
534 /*
Simon Glass4c509342015-04-28 20:25:03 -0600535 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100536 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000537 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100538 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000539}
540
541static int display_new_sp(void)
542{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000543 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000544
545 return 0;
546}
547
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200548#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
549 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000550static int setup_board_part1(void)
551{
552 bd_t *bd = gd->bd;
553
554 /*
555 * Save local variables to board info struct
556 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000557 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
558 bd->bi_memsize = gd->ram_size; /* size in bytes */
559
560#ifdef CONFIG_SYS_SRAM_BASE
561 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
562 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
563#endif
564
Masahiro Yamada58dac322014-03-05 17:40:10 +0900565#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000566 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
567 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
568#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100569#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000570 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
571#endif
572#if defined(CONFIG_MPC83xx)
573 bd->bi_immrbar = CONFIG_SYS_IMMR;
574#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000575
576 return 0;
577}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100578#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000579
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100580#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000581static int setup_board_part2(void)
582{
583 bd_t *bd = gd->bd;
584
585 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
586 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
587#if defined(CONFIG_CPM2)
588 bd->bi_cpmfreq = gd->arch.cpm_clk;
589 bd->bi_brgfreq = gd->arch.brg_clk;
590 bd->bi_sccfreq = gd->arch.scc_clk;
591 bd->bi_vco = gd->arch.vco_out;
592#endif /* CONFIG_CPM2 */
593#if defined(CONFIG_MPC512X)
594 bd->bi_ipsfreq = gd->arch.ips_clk;
595#endif /* CONFIG_MPC512X */
596#if defined(CONFIG_MPC5xxx)
597 bd->bi_ipbfreq = gd->arch.ipb_clk;
598 bd->bi_pcifreq = gd->pci_clk;
599#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800600#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
601 bd->bi_pcifreq = gd->pci_clk;
602#endif
603#if defined(CONFIG_EXTRA_CLOCK)
604 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
605 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
606 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
607#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000608
609 return 0;
610}
611#endif
612
613#ifdef CONFIG_SYS_EXTBDINFO
614static int setup_board_extra(void)
615{
616 bd_t *bd = gd->bd;
617
618 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
619 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
620 sizeof(bd->bi_r_version));
621
622 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
623 bd->bi_plb_busfreq = gd->bus_clk;
624#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
625 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
626 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
627 bd->bi_pci_busfreq = get_PCI_freq();
628 bd->bi_opbfreq = get_OPB_freq();
629#elif defined(CONFIG_XILINX_405)
630 bd->bi_pci_busfreq = get_PCI_freq();
631#endif
632
633 return 0;
634}
635#endif
636
Simon Glass1938f4a2013-03-11 06:49:53 +0000637#ifdef CONFIG_POST
638static int init_post(void)
639{
640 post_bootmode_init();
641 post_run(NULL, POST_ROM | post_bootmode_get(0));
642
643 return 0;
644}
645#endif
646
Simon Glass1938f4a2013-03-11 06:49:53 +0000647static int setup_dram_config(void)
648{
649 /* Ram is board specific, so move it to board code ... */
650 dram_init_banksize();
651
652 return 0;
653}
654
655static int reloc_fdt(void)
656{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100657#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600658 if (gd->flags & GD_FLG_SKIP_RELOC)
659 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000660 if (gd->new_fdt) {
661 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
662 gd->fdt_blob = gd->new_fdt;
663 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100664#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000665
666 return 0;
667}
668
669static int setup_reloc(void)
670{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600671 if (gd->flags & GD_FLG_SKIP_RELOC) {
672 debug("Skipping relocation due to flag\n");
673 return 0;
674 }
675
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800676#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000677 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100678#ifdef CONFIG_M68K
679 /*
680 * On all ColdFire arch cpu, monitor code starts always
681 * just after the default vector table location, so at 0x400
682 */
683 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
684#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800685#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000686 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
687
688 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000689 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000690 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
691 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000692
693 return 0;
694}
695
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100696#ifdef CONFIG_OF_BOARD_FIXUP
697static int fix_fdt(void)
698{
699 return board_fix_fdt((void *)gd->fdt_blob);
700}
701#endif
702
Simon Glass1938f4a2013-03-11 06:49:53 +0000703/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700704#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
705 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000706
707static int jump_to_copy(void)
708{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600709 if (gd->flags & GD_FLG_SKIP_RELOC)
710 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000711 /*
712 * x86 is special, but in a nice way. It uses a trampoline which
713 * enables the dcache if possible.
714 *
715 * For now, other archs use relocate_code(), which is implemented
716 * similarly for all archs. When we do generic relocation, hopefully
717 * we can make all archs enable the dcache prior to relocation.
718 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300719#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000720 /*
721 * SDRAM and console are now initialised. The final stack can now
722 * be setup in SDRAM. Code execution will continue in Flash, but
723 * with the stack in SDRAM and Global Data in temporary memory
724 * (CPU cache)
725 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600726 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000727 board_init_f_r_trampoline(gd->start_addr_sp);
728#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000729 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000730#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000731
732 return 0;
733}
734#endif
735
736/* Record the board_init_f() bootstage (after arch_cpu_init()) */
737static int mark_bootstage(void)
738{
739 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
740
741 return 0;
742}
743
Simon Glass9854a872015-11-08 23:47:48 -0700744static int initf_console_record(void)
745{
746#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
747 return console_record_init();
748#else
749 return 0;
750#endif
751}
752
Simon Glassab7cd622014-07-23 06:55:04 -0600753static int initf_dm(void)
754{
755#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
756 int ret;
757
758 ret = dm_init_and_scan(true);
759 if (ret)
760 return ret;
761#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700762#ifdef CONFIG_TIMER_EARLY
763 ret = dm_timer_init();
764 if (ret)
765 return ret;
766#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600767
768 return 0;
769}
770
Simon Glass146251f2015-01-19 22:16:12 -0700771/* Architecture-specific memory reservation */
772__weak int reserve_arch(void)
773{
774 return 0;
775}
776
Simon Glassd4c671c2015-03-05 12:25:16 -0700777__weak int arch_cpu_init_dm(void)
778{
779 return 0;
780}
781
Simon Glass4acff452017-01-16 07:03:50 -0700782static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000783 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700784#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700785 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700786#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800787#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700788 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800789#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700790 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700791 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600792#if defined(CONFIG_HAVE_FSP)
793 arch_fsp_init,
Bin Menga52a0682015-08-20 06:40:18 -0700794#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000795 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100796 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600797 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700798 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800799 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000800#if defined(CONFIG_BOARD_EARLY_INIT_F)
801 board_early_init_f,
802#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600803#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600804 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000805 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600806#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000807 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000808#if defined(CONFIG_BOARD_POSTCLK_INIT)
809 board_postclk_init,
810#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000811 env_init, /* initialize environment */
812 init_baud_rate, /* initialze baudrate settings */
813 serial_init, /* serial communications setup */
814 console_init_f, /* stage 1 init of console */
815 display_options, /* say that we are here */
816 display_text_info, /* show debugging info if required */
Simon Glass76d1d022017-03-28 10:27:30 -0600817#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
818 defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000819 checkcpu,
820#endif
Simon Glasscc664002017-01-23 13:31:25 -0700821#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000822 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700823#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000824#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900825 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000826#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000827 INIT_FUNC_WATCHDOG_INIT
828#if defined(CONFIG_MISC_INIT_F)
829 misc_init_f,
830#endif
831 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100832#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000833 init_func_i2c,
834#endif
835#if defined(CONFIG_HARD_SPI)
836 init_func_spi,
837#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000838 announce_dram_init,
839 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800840#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200841 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
842 defined(CONFIG_SH)
Simon Glass1938f4a2013-03-11 06:49:53 +0000843 dram_init, /* configure available RAM banks */
844#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100845#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000846 init_func_ram,
847#endif
848#ifdef CONFIG_POST
849 post_init_f,
850#endif
851 INIT_FUNC_WATCHDOG_RESET
852#if defined(CONFIG_SYS_DRAM_TEST)
853 testdram,
854#endif /* CONFIG_SYS_DRAM_TEST */
855 INIT_FUNC_WATCHDOG_RESET
856
Simon Glass1938f4a2013-03-11 06:49:53 +0000857#ifdef CONFIG_POST
858 init_post,
859#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000860 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000861 /*
862 * Now that we have DRAM mapped and working, we can
863 * relocate the code and continue running from DRAM.
864 *
865 * Reserve memory at end of RAM for (top down in that order):
866 * - area that won't get touched by U-Boot and Linux (optional)
867 * - kernel log buffer
868 * - protected RAM
869 * - LCD framebuffer
870 * - monitor code
871 * - board info struct
872 */
873 setup_dest_addr,
Simon Glassb56db482017-03-31 08:40:28 -0600874#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000875 reserve_logbuffer,
876#endif
877#ifdef CONFIG_PRAM
878 reserve_pram,
879#endif
880 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600881#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000882 reserve_mmu,
883#endif
Simon Glass5a541942016-01-18 19:52:21 -0700884 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700885 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000886 reserve_uboot,
887 reserve_malloc,
888 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000889 setup_machine,
890 reserve_global_data,
891 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -0700892 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000893 reserve_stacks,
894 setup_dram_config,
895 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200896#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
897 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000898 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100899#endif
900#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000901 INIT_FUNC_WATCHDOG_RESET
902 setup_board_part2,
903#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000904 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000905#ifdef CONFIG_SYS_EXTBDINFO
906 setup_board_extra,
907#endif
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100908#ifdef CONFIG_OF_BOARD_FIXUP
909 fix_fdt,
910#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000911 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000912 reloc_fdt,
913 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300914#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700915 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700916 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700917 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700918#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300919#if defined(CONFIG_XTENSA)
920 clear_bss,
921#endif
Simon Glass530f27e2017-01-16 07:03:49 -0700922#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
923 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000924 jump_to_copy,
925#endif
926 NULL,
927};
928
929void board_init_f(ulong boot_flags)
930{
York Sun2a1680e2014-05-02 17:28:04 -0700931#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
932 /*
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400933 * For some architectures, global data is initialized and used before
York Sun2a1680e2014-05-02 17:28:04 -0700934 * calling this function. The data should be preserved. For others,
935 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
936 * here to host global data until relocation.
937 */
Simon Glass1938f4a2013-03-11 06:49:53 +0000938 gd_t data;
939
940 gd = &data;
941
David Fengcce6be72013-12-14 11:47:36 +0800942 /*
943 * Clear global data before it is accessed at debug print
944 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400945 * get the wrong value of gd->have_console.
David Fengcce6be72013-12-14 11:47:36 +0800946 */
David Fengcce6be72013-12-14 11:47:36 +0800947 zero_global_data();
948#endif
949
Simon Glass1938f4a2013-03-11 06:49:53 +0000950 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400951 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000952
953 if (initcall_run_list(init_sequence_f))
954 hang();
955
Ben Stoltz9b217492015-07-31 09:31:37 -0600956#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass530f27e2017-01-16 07:03:49 -0700957 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000958 /* NOTREACHED - jump_to_copy() does not return */
959 hang();
960#endif
961}
962
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300963#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000964/*
965 * For now this code is only used on x86.
966 *
967 * init_sequence_f_r is the list of init functions which are run when
968 * U-Boot is executing from Flash with a semi-limited 'C' environment.
969 * The following limitations must be considered when implementing an
970 * '_f_r' function:
971 * - 'static' variables are read-only
972 * - Global Data (gd->xxx) is read/write
973 *
974 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
975 * supported). It _should_, if possible, copy global data to RAM and
976 * initialise the CPU caches (to speed up the relocation process)
977 *
978 * NOTE: At present only x86 uses this route, but it is intended that
979 * all archs will move to this when generic relocation is implemented.
980 */
Simon Glass4acff452017-01-16 07:03:50 -0700981static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700982#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000983 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700984#endif
Simon Glass48a33802013-03-05 14:39:52 +0000985
986 NULL,
987};
988
989void board_init_f_r(void)
990{
991 if (initcall_run_list(init_sequence_f_r))
992 hang();
993
994 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700995 * The pre-relocation drivers may be using memory that has now gone
996 * away. Mark serial as unavailable - this will fall back to the debug
997 * UART if available.
998 */
999 gd->flags &= ~GD_FLG_SERIAL_READY;
1000
1001 /*
Simon Glass48a33802013-03-05 14:39:52 +00001002 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1003 * Transfer execution from Flash to RAM by calculating the address
1004 * of the in-RAM copy of board_init_r() and calling it
1005 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001006 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001007
1008 /* NOTREACHED - board_init_r() does not return */
1009 hang();
1010}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001011#endif /* CONFIG_X86 */