blob: 1bdc744952fa67d92706f57c8873172a5adf9263 [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
Simon Glass76b00ac2017-03-31 08:40:32 -0600211__weak int 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
Simon Glass76b00ac2017-03-31 08:40:32 -0600217
218 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000219}
220
Heiko Schocherea818db2013-01-29 08:53:15 +0100221#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000222static int init_func_i2c(void)
223{
224 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200225#ifdef CONFIG_SYS_I2C
226 i2c_init_all();
227#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000228 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200229#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000230 puts("ready\n");
231 return 0;
232}
233#endif
234
235#if defined(CONFIG_HARD_SPI)
236static int init_func_spi(void)
237{
238 puts("SPI: ");
239 spi_init();
240 puts("ready\n");
241 return 0;
242}
243#endif
244
245__maybe_unused
Simon Glass1938f4a2013-03-11 06:49:53 +0000246static int zero_global_data(void)
247{
248 memset((void *)gd, '\0', sizeof(gd_t));
249
250 return 0;
251}
252
253static int setup_mon_len(void)
254{
Michal Simeke945f6d2014-05-08 16:08:44 +0200255#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100256 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600257#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000258 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400259#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800260 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200261#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800262 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600263#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000264 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
265 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000266#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000267 return 0;
268}
269
270__weak int arch_cpu_init(void)
271{
272 return 0;
273}
274
Paul Burton8ebf5062016-09-21 11:18:46 +0100275__weak int mach_cpu_init(void)
276{
277 return 0;
278}
279
Simon Glass1938f4a2013-03-11 06:49:53 +0000280/* Get the top of usable RAM */
281__weak ulong board_get_usable_ram_top(ulong total_size)
282{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700283#ifdef CONFIG_SYS_SDRAM_BASE
284 /*
Simon Glass4c509342015-04-28 20:25:03 -0600285 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700286 * 32-bit address space. If so, clip the usable RAM so it doesn't.
287 */
288 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
289 /*
290 * Will wrap back to top of 32-bit space when reservations
291 * are made.
292 */
293 return 0;
294#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000295 return gd->ram_top;
296}
297
298static int setup_dest_addr(void)
299{
300 debug("Monitor len: %08lX\n", gd->mon_len);
301 /*
302 * Ram is setup, size stored in gd !!
303 */
304 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800305#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000306 /*
307 * Subtract specified amount of memory to hide so that it won't
308 * get "touched" at all by U-Boot. By fixing up gd->ram_size
309 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800310 * memory size and won't touch it either. This should work
311 * for arch/ppc and arch/powerpc. Only Linux board ports in
312 * arch/powerpc with bootwrapper support, that recalculate the
313 * memory size from the SDRAM controller setup will have to
314 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000315 */
York Sun36cc0de2017-03-06 09:02:28 -0800316 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
317#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000318#ifdef CONFIG_SYS_SDRAM_BASE
319 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
320#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000321 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000322 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000323 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000324 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700325#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000326 /*
327 * We need to make sure the location we intend to put secondary core
328 * boot code is reserved and not used by any part of u-boot
329 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000330 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
331 gd->relocaddr = determine_mp_bootpg(NULL);
332 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000333 }
334#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000335 return 0;
336}
337
Simon Glassb56db482017-03-31 08:40:28 -0600338#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000339static int reserve_logbuffer(void)
340{
Simon Glassb56db482017-03-31 08:40:28 -0600341#ifndef CONFIG_ALT_LB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000342 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000343 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000344 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000345 gd->relocaddr);
Simon Glassb56db482017-03-31 08:40:28 -0600346#endif
347
Simon Glass1938f4a2013-03-11 06:49:53 +0000348 return 0;
349}
350#endif
351
352#ifdef CONFIG_PRAM
353/* reserve protected RAM */
354static int reserve_pram(void)
355{
356 ulong reg;
357
358 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000359 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000361 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000362 return 0;
363}
364#endif /* CONFIG_PRAM */
365
366/* Round memory pointer down to next 4 kB limit */
367static int reserve_round_4k(void)
368{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000369 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000370 return 0;
371}
372
Simon Glass80d4bcd2017-03-31 08:40:29 -0600373#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000374static int reserve_mmu(void)
375{
Simon Glass80d4bcd2017-03-31 08:40:29 -0600376#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000377 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800378 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000379 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000380
381 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000382 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000383
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000384 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000385 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
386 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700387
388#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
389 /*
390 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
391 * with location within secure ram.
392 */
393 gd->arch.tlb_allocated = gd->arch.tlb_addr;
394#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600395#endif
York Sun50e93b92016-06-24 16:46:19 -0700396
Simon Glass1938f4a2013-03-11 06:49:53 +0000397 return 0;
398}
399#endif
400
Simon Glass5a541942016-01-18 19:52:21 -0700401static int reserve_video(void)
402{
Simon Glass0f079eb2017-03-31 08:40:30 -0600403#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700404 ulong addr;
405 int ret;
406
407 addr = gd->relocaddr;
408 ret = video_reserve(&addr);
409 if (ret)
410 return ret;
411 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600412#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700413# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000414 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700415# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000416 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000417 gd->relocaddr = lcd_setmem(gd->relocaddr);
418 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700419# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600420#elif defined(CONFIG_VIDEO) && \
421 (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700422 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Riniea3310e2017-03-14 11:08:10 -0400423 !defined(CONFIG_M68K)
Simon Glass8703ef32016-01-18 19:52:20 -0700424 /* reserve memory for video display (always full pages) */
425 gd->relocaddr = video_setmem(gd->relocaddr);
426 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600427#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700428
429 return 0;
430}
Simon Glass8703ef32016-01-18 19:52:20 -0700431
Simon Glass71c52db2013-06-11 11:14:42 -0700432static int reserve_trace(void)
433{
434#ifdef CONFIG_TRACE
435 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
436 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
437 debug("Reserving %dk for trace data at: %08lx\n",
438 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
439#endif
440
441 return 0;
442}
443
Simon Glass1938f4a2013-03-11 06:49:53 +0000444static int reserve_uboot(void)
445{
446 /*
447 * reserve memory for U-Boot code, data & bss
448 * round down to next 4 kB limit
449 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000450 gd->relocaddr -= gd->mon_len;
451 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000452#ifdef CONFIG_E500
453 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000454 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000455#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000456
457 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000458 gd->relocaddr);
459
460 gd->start_addr_sp = gd->relocaddr;
461
Simon Glass1938f4a2013-03-11 06:49:53 +0000462 return 0;
463}
464
465/* reserve memory for malloc() area */
466static int reserve_malloc(void)
467{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000468 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000469 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000470 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000471 return 0;
472}
473
474/* (permanently) allocate a Board Info struct */
475static int reserve_board(void)
476{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800477 if (!gd->bd) {
478 gd->start_addr_sp -= sizeof(bd_t);
479 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
480 memset(gd->bd, '\0', sizeof(bd_t));
481 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
482 sizeof(bd_t), gd->start_addr_sp);
483 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000484 return 0;
485}
486
487static int setup_machine(void)
488{
489#ifdef CONFIG_MACH_TYPE
490 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
491#endif
492 return 0;
493}
494
495static int reserve_global_data(void)
496{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000497 gd->start_addr_sp -= sizeof(gd_t);
498 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000499 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000500 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000501 return 0;
502}
503
504static int reserve_fdt(void)
505{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100506#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000507 /*
Simon Glass4c509342015-04-28 20:25:03 -0600508 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000509 * must relocate it. If it is embedded in the data section, then it
510 * will be relocated with other data.
511 */
512 if (gd->fdt_blob) {
513 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
514
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000515 gd->start_addr_sp -= gd->fdt_size;
516 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000517 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000518 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000519 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100520#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000521
522 return 0;
523}
524
Andreas Bießmann68145d42015-02-06 23:06:45 +0100525int arch_reserve_stacks(void)
526{
527 return 0;
528}
529
Simon Glass1938f4a2013-03-11 06:49:53 +0000530static int reserve_stacks(void)
531{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100532 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000533 gd->start_addr_sp -= 16;
534 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000535
536 /*
Simon Glass4c509342015-04-28 20:25:03 -0600537 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100538 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000539 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100540 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000541}
542
543static int display_new_sp(void)
544{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000545 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000546
547 return 0;
548}
549
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200550#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
551 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000552static int setup_board_part1(void)
553{
554 bd_t *bd = gd->bd;
555
556 /*
557 * Save local variables to board info struct
558 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000559 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
560 bd->bi_memsize = gd->ram_size; /* size in bytes */
561
562#ifdef CONFIG_SYS_SRAM_BASE
563 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
564 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
565#endif
566
Masahiro Yamada58dac322014-03-05 17:40:10 +0900567#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000568 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
569 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
570#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100571#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000572 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
573#endif
574#if defined(CONFIG_MPC83xx)
575 bd->bi_immrbar = CONFIG_SYS_IMMR;
576#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000577
578 return 0;
579}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100580#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000581
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100582#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000583static int setup_board_part2(void)
584{
585 bd_t *bd = gd->bd;
586
587 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
588 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
589#if defined(CONFIG_CPM2)
590 bd->bi_cpmfreq = gd->arch.cpm_clk;
591 bd->bi_brgfreq = gd->arch.brg_clk;
592 bd->bi_sccfreq = gd->arch.scc_clk;
593 bd->bi_vco = gd->arch.vco_out;
594#endif /* CONFIG_CPM2 */
595#if defined(CONFIG_MPC512X)
596 bd->bi_ipsfreq = gd->arch.ips_clk;
597#endif /* CONFIG_MPC512X */
598#if defined(CONFIG_MPC5xxx)
599 bd->bi_ipbfreq = gd->arch.ipb_clk;
600 bd->bi_pcifreq = gd->pci_clk;
601#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800602#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
603 bd->bi_pcifreq = gd->pci_clk;
604#endif
605#if defined(CONFIG_EXTRA_CLOCK)
606 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
607 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
608 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
609#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000610
611 return 0;
612}
613#endif
614
615#ifdef CONFIG_SYS_EXTBDINFO
616static int setup_board_extra(void)
617{
618 bd_t *bd = gd->bd;
619
620 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
621 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
622 sizeof(bd->bi_r_version));
623
624 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
625 bd->bi_plb_busfreq = gd->bus_clk;
626#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
627 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
628 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
629 bd->bi_pci_busfreq = get_PCI_freq();
630 bd->bi_opbfreq = get_OPB_freq();
631#elif defined(CONFIG_XILINX_405)
632 bd->bi_pci_busfreq = get_PCI_freq();
633#endif
634
635 return 0;
636}
637#endif
638
Simon Glass1938f4a2013-03-11 06:49:53 +0000639#ifdef CONFIG_POST
640static int init_post(void)
641{
642 post_bootmode_init();
643 post_run(NULL, POST_ROM | post_bootmode_get(0));
644
645 return 0;
646}
647#endif
648
Simon Glass1938f4a2013-03-11 06:49:53 +0000649static int reloc_fdt(void)
650{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100651#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600652 if (gd->flags & GD_FLG_SKIP_RELOC)
653 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000654 if (gd->new_fdt) {
655 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
656 gd->fdt_blob = gd->new_fdt;
657 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100658#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000659
660 return 0;
661}
662
663static int setup_reloc(void)
664{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600665 if (gd->flags & GD_FLG_SKIP_RELOC) {
666 debug("Skipping relocation due to flag\n");
667 return 0;
668 }
669
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800670#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000671 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100672#ifdef CONFIG_M68K
673 /*
674 * On all ColdFire arch cpu, monitor code starts always
675 * just after the default vector table location, so at 0x400
676 */
677 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
678#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800679#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000680 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
681
682 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000683 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000684 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
685 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000686
687 return 0;
688}
689
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100690#ifdef CONFIG_OF_BOARD_FIXUP
691static int fix_fdt(void)
692{
693 return board_fix_fdt((void *)gd->fdt_blob);
694}
695#endif
696
Simon Glass1938f4a2013-03-11 06:49:53 +0000697/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700698#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
699 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000700
701static int jump_to_copy(void)
702{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600703 if (gd->flags & GD_FLG_SKIP_RELOC)
704 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000705 /*
706 * x86 is special, but in a nice way. It uses a trampoline which
707 * enables the dcache if possible.
708 *
709 * For now, other archs use relocate_code(), which is implemented
710 * similarly for all archs. When we do generic relocation, hopefully
711 * we can make all archs enable the dcache prior to relocation.
712 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300713#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000714 /*
715 * SDRAM and console are now initialised. The final stack can now
716 * be setup in SDRAM. Code execution will continue in Flash, but
717 * with the stack in SDRAM and Global Data in temporary memory
718 * (CPU cache)
719 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600720 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000721 board_init_f_r_trampoline(gd->start_addr_sp);
722#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000723 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000724#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000725
726 return 0;
727}
728#endif
729
730/* Record the board_init_f() bootstage (after arch_cpu_init()) */
731static int mark_bootstage(void)
732{
733 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
734
735 return 0;
736}
737
Simon Glass9854a872015-11-08 23:47:48 -0700738static int initf_console_record(void)
739{
740#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
741 return console_record_init();
742#else
743 return 0;
744#endif
745}
746
Simon Glassab7cd622014-07-23 06:55:04 -0600747static int initf_dm(void)
748{
749#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
750 int ret;
751
752 ret = dm_init_and_scan(true);
753 if (ret)
754 return ret;
755#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700756#ifdef CONFIG_TIMER_EARLY
757 ret = dm_timer_init();
758 if (ret)
759 return ret;
760#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600761
762 return 0;
763}
764
Simon Glass146251f2015-01-19 22:16:12 -0700765/* Architecture-specific memory reservation */
766__weak int reserve_arch(void)
767{
768 return 0;
769}
770
Simon Glassd4c671c2015-03-05 12:25:16 -0700771__weak int arch_cpu_init_dm(void)
772{
773 return 0;
774}
775
Simon Glass4acff452017-01-16 07:03:50 -0700776static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000777 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700778#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700779 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700780#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800781#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700782 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800783#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700784 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700785 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600786#if defined(CONFIG_HAVE_FSP)
787 arch_fsp_init,
Bin Menga52a0682015-08-20 06:40:18 -0700788#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000789 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100790 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600791 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700792 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800793 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000794#if defined(CONFIG_BOARD_EARLY_INIT_F)
795 board_early_init_f,
796#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600797#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600798 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000799 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600800#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000801 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000802#if defined(CONFIG_BOARD_POSTCLK_INIT)
803 board_postclk_init,
804#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000805 env_init, /* initialize environment */
806 init_baud_rate, /* initialze baudrate settings */
807 serial_init, /* serial communications setup */
808 console_init_f, /* stage 1 init of console */
809 display_options, /* say that we are here */
810 display_text_info, /* show debugging info if required */
Simon Glass76d1d022017-03-28 10:27:30 -0600811#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
812 defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000813 checkcpu,
814#endif
Simon Glasscc664002017-01-23 13:31:25 -0700815#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000816 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700817#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000818#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900819 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000820#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000821 INIT_FUNC_WATCHDOG_INIT
822#if defined(CONFIG_MISC_INIT_F)
823 misc_init_f,
824#endif
825 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100826#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000827 init_func_i2c,
828#endif
829#if defined(CONFIG_HARD_SPI)
830 init_func_spi,
831#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000832 announce_dram_init,
833 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800834#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200835 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
836 defined(CONFIG_SH)
Simon Glass1938f4a2013-03-11 06:49:53 +0000837 dram_init, /* configure available RAM banks */
838#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100839#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000840 init_func_ram,
841#endif
842#ifdef CONFIG_POST
843 post_init_f,
844#endif
845 INIT_FUNC_WATCHDOG_RESET
846#if defined(CONFIG_SYS_DRAM_TEST)
847 testdram,
848#endif /* CONFIG_SYS_DRAM_TEST */
849 INIT_FUNC_WATCHDOG_RESET
850
Simon Glass1938f4a2013-03-11 06:49:53 +0000851#ifdef CONFIG_POST
852 init_post,
853#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000854 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000855 /*
856 * Now that we have DRAM mapped and working, we can
857 * relocate the code and continue running from DRAM.
858 *
859 * Reserve memory at end of RAM for (top down in that order):
860 * - area that won't get touched by U-Boot and Linux (optional)
861 * - kernel log buffer
862 * - protected RAM
863 * - LCD framebuffer
864 * - monitor code
865 * - board info struct
866 */
867 setup_dest_addr,
Simon Glassb56db482017-03-31 08:40:28 -0600868#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000869 reserve_logbuffer,
870#endif
871#ifdef CONFIG_PRAM
872 reserve_pram,
873#endif
874 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600875#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000876 reserve_mmu,
877#endif
Simon Glass5a541942016-01-18 19:52:21 -0700878 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700879 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000880 reserve_uboot,
881 reserve_malloc,
882 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000883 setup_machine,
884 reserve_global_data,
885 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -0700886 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000887 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600888 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000889 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200890#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
891 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000892 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100893#endif
894#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000895 INIT_FUNC_WATCHDOG_RESET
896 setup_board_part2,
897#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000898 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000899#ifdef CONFIG_SYS_EXTBDINFO
900 setup_board_extra,
901#endif
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100902#ifdef CONFIG_OF_BOARD_FIXUP
903 fix_fdt,
904#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000905 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000906 reloc_fdt,
907 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300908#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700909 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700910 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700911 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700912#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300913#if defined(CONFIG_XTENSA)
914 clear_bss,
915#endif
Simon Glass530f27e2017-01-16 07:03:49 -0700916#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
917 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000918 jump_to_copy,
919#endif
920 NULL,
921};
922
923void board_init_f(ulong boot_flags)
924{
York Sun2a1680e2014-05-02 17:28:04 -0700925#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
926 /*
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400927 * For some architectures, global data is initialized and used before
York Sun2a1680e2014-05-02 17:28:04 -0700928 * calling this function. The data should be preserved. For others,
929 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
930 * here to host global data until relocation.
931 */
Simon Glass1938f4a2013-03-11 06:49:53 +0000932 gd_t data;
933
934 gd = &data;
935
David Fengcce6be72013-12-14 11:47:36 +0800936 /*
937 * Clear global data before it is accessed at debug print
938 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400939 * get the wrong value of gd->have_console.
David Fengcce6be72013-12-14 11:47:36 +0800940 */
David Fengcce6be72013-12-14 11:47:36 +0800941 zero_global_data();
942#endif
943
Simon Glass1938f4a2013-03-11 06:49:53 +0000944 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400945 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000946
947 if (initcall_run_list(init_sequence_f))
948 hang();
949
Ben Stoltz9b217492015-07-31 09:31:37 -0600950#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass530f27e2017-01-16 07:03:49 -0700951 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000952 /* NOTREACHED - jump_to_copy() does not return */
953 hang();
954#endif
955}
956
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300957#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000958/*
959 * For now this code is only used on x86.
960 *
961 * init_sequence_f_r is the list of init functions which are run when
962 * U-Boot is executing from Flash with a semi-limited 'C' environment.
963 * The following limitations must be considered when implementing an
964 * '_f_r' function:
965 * - 'static' variables are read-only
966 * - Global Data (gd->xxx) is read/write
967 *
968 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
969 * supported). It _should_, if possible, copy global data to RAM and
970 * initialise the CPU caches (to speed up the relocation process)
971 *
972 * NOTE: At present only x86 uses this route, but it is intended that
973 * all archs will move to this when generic relocation is implemented.
974 */
Simon Glass4acff452017-01-16 07:03:50 -0700975static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700976#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000977 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700978#endif
Simon Glass48a33802013-03-05 14:39:52 +0000979
980 NULL,
981};
982
983void board_init_f_r(void)
984{
985 if (initcall_run_list(init_sequence_f_r))
986 hang();
987
988 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700989 * The pre-relocation drivers may be using memory that has now gone
990 * away. Mark serial as unavailable - this will fall back to the debug
991 * UART if available.
992 */
993 gd->flags &= ~GD_FLG_SERIAL_READY;
994
995 /*
Simon Glass48a33802013-03-05 14:39:52 +0000996 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
997 * Transfer execution from Flash to RAM by calculating the address
998 * of the in-RAM copy of board_init_r() and calling it
999 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001000 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001001
1002 /* NOTREACHED - board_init_r() does not return */
1003 hang();
1004}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001005#endif /* CONFIG_X86 */