blob: f928c3dc736452e7b9265e47e45068c1d29af7e5 [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>
Simon Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000015#include <environment.h>
Simon Glassab7cd622014-07-23 06:55:04 -060016#include <dm.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000017#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000018#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000019#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000020#include <initcall.h>
Simon Glass96d4b752017-03-31 08:40:37 -060021#include <init_helpers.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000022#include <logbuff.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070023#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050024#include <mapmem.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000025
26/* TODO: Can we move these into arch/ headers? */
27#ifdef CONFIG_8xx
28#include <mpc8xx.h>
29#endif
30#ifdef CONFIG_5xx
31#include <mpc5xx.h>
32#endif
33#ifdef CONFIG_MPC5xxx
34#include <mpc5xxx.h>
35#endif
Gabriel Huauec3b4822014-09-03 13:57:54 -070036#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huaua76df702014-07-26 11:35:43 -070037#include <asm/mp.h>
38#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +000039
Simon Glassa733b062013-04-26 02:53:43 +000040#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000041#include <post.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000042#include <spi.h>
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020043#include <status_led.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070044#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070045#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070046#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000047#include <watchdog.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000048#include <asm/io.h>
49#include <asm/sections.h>
Chris Zankelde5e5ce2016-08-10 18:36:43 +030050#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
Simon Glass48a33802013-03-05 14:39:52 +000051#include <asm/relocate.h>
52#endif
Simon Glassab7cd622014-07-23 06:55:04 -060053#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060054#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000055
56/*
57 * Pointer to initial global data area
58 *
59 * Here we initialize it if needed.
60 */
61#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
62#undef XTRN_DECLARE_GLOBAL_DATA_PTR
63#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
64DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
65#else
66DECLARE_GLOBAL_DATA_PTR;
67#endif
68
69/*
Simon Glass4c509342015-04-28 20:25:03 -060070 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000071 * refactored to a single function, something like:
72 *
73 * void led_set_state(enum led_colour_t colour, int on);
74 */
75/************************************************************************
76 * Coloured LED functionality
77 ************************************************************************
78 * May be supplied by boards if desired
79 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020080__weak void coloured_LED_init(void) {}
81__weak void red_led_on(void) {}
82__weak void red_led_off(void) {}
83__weak void green_led_on(void) {}
84__weak void green_led_off(void) {}
85__weak void yellow_led_on(void) {}
86__weak void yellow_led_off(void) {}
87__weak void blue_led_on(void) {}
88__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000089
90/*
91 * Why is gd allocated a register? Prior to reloc it might be better to
92 * just pass it around to each function in this file?
93 *
94 * After reloc one could argue that it is hardly used and doesn't need
95 * to be in a register. Or if it is it should perhaps hold pointers to all
96 * global data for all modules, so that post-reloc we can avoid the massive
97 * literal pool we get on ARM. Or perhaps just encourage each module to use
98 * a structure...
99 */
100
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800101#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000102static int init_func_watchdog_init(void)
103{
Tom Riniea3310e2017-03-14 11:08:10 -0400104# if defined(CONFIG_HW_WATCHDOG) && \
105 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100106 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200107 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100108 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800109 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000110 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200111# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000112 WATCHDOG_RESET();
113
114 return 0;
115}
116
117int init_func_watchdog_reset(void)
118{
119 WATCHDOG_RESET();
120
121 return 0;
122}
123#endif /* CONFIG_WATCHDOG */
124
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200125__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000126{
127 /* please define platform specific board_add_ram_info() */
128}
129
Simon Glass1938f4a2013-03-11 06:49:53 +0000130static int init_baud_rate(void)
131{
132 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
133 return 0;
134}
135
136static int display_text_info(void)
137{
Ben Stoltz9b217492015-07-31 09:31:37 -0600138#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100139 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000140
Simon Glass632efa72013-03-11 07:06:48 +0000141 bss_start = (ulong)&__bss_start;
142 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100143
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800144#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100145 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800146#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100147 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800148#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100149
150 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
151 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000152#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000153
Simon Glass1938f4a2013-03-11 06:49:53 +0000154#ifdef CONFIG_USE_IRQ
155 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
156 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
157#endif
158
159 return 0;
160}
161
162static int announce_dram_init(void)
163{
164 puts("DRAM: ");
165 return 0;
166}
167
angelo@sysam.ite310b932015-02-12 01:40:17 +0100168#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000169static int init_func_ram(void)
170{
Simon Glass088454c2017-03-31 08:40:25 -0600171 return initdram();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000172}
173#endif
174
Simon Glass1938f4a2013-03-11 06:49:53 +0000175static int show_dram_config(void)
176{
York Sunfa39ffe2014-05-02 17:28:05 -0700177 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000178
179#ifdef CONFIG_NR_DRAM_BANKS
180 int i;
181
182 debug("\nRAM Configuration:\n");
183 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
184 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700185 debug("Bank #%d: %llx ", i,
186 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000187#ifdef DEBUG
188 print_size(gd->bd->bi_dram[i].size, "\n");
189#endif
190 }
191 debug("\nDRAM: ");
192#else
193 size = gd->ram_size;
194#endif
195
Simon Glasse4fef6c2013-03-11 14:30:42 +0000196 print_size(size, "");
197 board_add_ram_info(0);
198 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000199
200 return 0;
201}
202
Simon Glass76b00ac2017-03-31 08:40:32 -0600203__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000204{
205#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
206 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
207 gd->bd->bi_dram[0].size = get_effective_memsize();
208#endif
Simon Glass76b00ac2017-03-31 08:40:32 -0600209
210 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000211}
212
Heiko Schocherea818db2013-01-29 08:53:15 +0100213#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000214static int init_func_i2c(void)
215{
216 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200217#ifdef CONFIG_SYS_I2C
218 i2c_init_all();
219#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000220 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200221#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000222 puts("ready\n");
223 return 0;
224}
225#endif
226
227#if defined(CONFIG_HARD_SPI)
228static int init_func_spi(void)
229{
230 puts("SPI: ");
231 spi_init();
232 puts("ready\n");
233 return 0;
234}
235#endif
236
237__maybe_unused
Simon Glass1938f4a2013-03-11 06:49:53 +0000238static int zero_global_data(void)
239{
240 memset((void *)gd, '\0', sizeof(gd_t));
241
242 return 0;
243}
244
245static int setup_mon_len(void)
246{
Michal Simeke945f6d2014-05-08 16:08:44 +0200247#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100248 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600249#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000250 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400251#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800252 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200253#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800254 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600255#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000256 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
257 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000258#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000259 return 0;
260}
261
262__weak int arch_cpu_init(void)
263{
264 return 0;
265}
266
Paul Burton8ebf5062016-09-21 11:18:46 +0100267__weak int mach_cpu_init(void)
268{
269 return 0;
270}
271
Simon Glass1938f4a2013-03-11 06:49:53 +0000272/* Get the top of usable RAM */
273__weak ulong board_get_usable_ram_top(ulong total_size)
274{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700275#ifdef CONFIG_SYS_SDRAM_BASE
276 /*
Simon Glass4c509342015-04-28 20:25:03 -0600277 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700278 * 32-bit address space. If so, clip the usable RAM so it doesn't.
279 */
280 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
281 /*
282 * Will wrap back to top of 32-bit space when reservations
283 * are made.
284 */
285 return 0;
286#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000287 return gd->ram_top;
288}
289
290static int setup_dest_addr(void)
291{
292 debug("Monitor len: %08lX\n", gd->mon_len);
293 /*
294 * Ram is setup, size stored in gd !!
295 */
296 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800297#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000298 /*
299 * Subtract specified amount of memory to hide so that it won't
300 * get "touched" at all by U-Boot. By fixing up gd->ram_size
301 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800302 * memory size and won't touch it either. This should work
303 * for arch/ppc and arch/powerpc. Only Linux board ports in
304 * arch/powerpc with bootwrapper support, that recalculate the
305 * memory size from the SDRAM controller setup will have to
306 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000307 */
York Sun36cc0de2017-03-06 09:02:28 -0800308 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
309#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000310#ifdef CONFIG_SYS_SDRAM_BASE
311 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
312#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000313 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000314 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000315 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000316 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700317#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000318 /*
319 * We need to make sure the location we intend to put secondary core
320 * boot code is reserved and not used by any part of u-boot
321 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000322 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
323 gd->relocaddr = determine_mp_bootpg(NULL);
324 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000325 }
326#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000327 return 0;
328}
329
Simon Glassb56db482017-03-31 08:40:28 -0600330#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000331static int reserve_logbuffer(void)
332{
Simon Glassb56db482017-03-31 08:40:28 -0600333#ifndef CONFIG_ALT_LB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000334 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000335 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000336 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000337 gd->relocaddr);
Simon Glassb56db482017-03-31 08:40:28 -0600338#endif
339
Simon Glass1938f4a2013-03-11 06:49:53 +0000340 return 0;
341}
342#endif
343
344#ifdef CONFIG_PRAM
345/* reserve protected RAM */
346static int reserve_pram(void)
347{
348 ulong reg;
349
350 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000351 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000352 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000353 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000354 return 0;
355}
356#endif /* CONFIG_PRAM */
357
358/* Round memory pointer down to next 4 kB limit */
359static int reserve_round_4k(void)
360{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000361 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000362 return 0;
363}
364
Simon Glass80d4bcd2017-03-31 08:40:29 -0600365#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000366static int reserve_mmu(void)
367{
Simon Glass80d4bcd2017-03-31 08:40:29 -0600368#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000369 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800370 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000371 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000372
373 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000374 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000375
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000376 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000377 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
378 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700379
380#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
381 /*
382 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
383 * with location within secure ram.
384 */
385 gd->arch.tlb_allocated = gd->arch.tlb_addr;
386#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600387#endif
York Sun50e93b92016-06-24 16:46:19 -0700388
Simon Glass1938f4a2013-03-11 06:49:53 +0000389 return 0;
390}
391#endif
392
Simon Glass5a541942016-01-18 19:52:21 -0700393static int reserve_video(void)
394{
Simon Glass0f079eb2017-03-31 08:40:30 -0600395#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700396 ulong addr;
397 int ret;
398
399 addr = gd->relocaddr;
400 ret = video_reserve(&addr);
401 if (ret)
402 return ret;
403 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600404#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700405# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000406 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700407# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000408 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000409 gd->relocaddr = lcd_setmem(gd->relocaddr);
410 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700411# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600412#elif defined(CONFIG_VIDEO) && \
413 (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700414 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Riniea3310e2017-03-14 11:08:10 -0400415 !defined(CONFIG_M68K)
Simon Glass8703ef32016-01-18 19:52:20 -0700416 /* reserve memory for video display (always full pages) */
417 gd->relocaddr = video_setmem(gd->relocaddr);
418 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600419#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700420
421 return 0;
422}
Simon Glass8703ef32016-01-18 19:52:20 -0700423
Simon Glass71c52db2013-06-11 11:14:42 -0700424static int reserve_trace(void)
425{
426#ifdef CONFIG_TRACE
427 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
428 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
429 debug("Reserving %dk for trace data at: %08lx\n",
430 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
431#endif
432
433 return 0;
434}
435
Simon Glass1938f4a2013-03-11 06:49:53 +0000436static int reserve_uboot(void)
437{
438 /*
439 * reserve memory for U-Boot code, data & bss
440 * round down to next 4 kB limit
441 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000442 gd->relocaddr -= gd->mon_len;
443 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000444#ifdef CONFIG_E500
445 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000446 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000447#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000448
449 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000450 gd->relocaddr);
451
452 gd->start_addr_sp = gd->relocaddr;
453
Simon Glass1938f4a2013-03-11 06:49:53 +0000454 return 0;
455}
456
457/* reserve memory for malloc() area */
458static int reserve_malloc(void)
459{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000460 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000461 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000462 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000463 return 0;
464}
465
466/* (permanently) allocate a Board Info struct */
467static int reserve_board(void)
468{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800469 if (!gd->bd) {
470 gd->start_addr_sp -= sizeof(bd_t);
471 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
472 memset(gd->bd, '\0', sizeof(bd_t));
473 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
474 sizeof(bd_t), gd->start_addr_sp);
475 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000476 return 0;
477}
478
479static int setup_machine(void)
480{
481#ifdef CONFIG_MACH_TYPE
482 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
483#endif
484 return 0;
485}
486
487static int reserve_global_data(void)
488{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000489 gd->start_addr_sp -= sizeof(gd_t);
490 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000491 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000492 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000493 return 0;
494}
495
496static int reserve_fdt(void)
497{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100498#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000499 /*
Simon Glass4c509342015-04-28 20:25:03 -0600500 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000501 * must relocate it. If it is embedded in the data section, then it
502 * will be relocated with other data.
503 */
504 if (gd->fdt_blob) {
505 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
506
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000507 gd->start_addr_sp -= gd->fdt_size;
508 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000509 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000510 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000511 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100512#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000513
514 return 0;
515}
516
Andreas Bießmann68145d42015-02-06 23:06:45 +0100517int arch_reserve_stacks(void)
518{
519 return 0;
520}
521
Simon Glass1938f4a2013-03-11 06:49:53 +0000522static int reserve_stacks(void)
523{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100524 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000525 gd->start_addr_sp -= 16;
526 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000527
528 /*
Simon Glass4c509342015-04-28 20:25:03 -0600529 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100530 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000531 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100532 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000533}
534
535static int display_new_sp(void)
536{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000537 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000538
539 return 0;
540}
541
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200542#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
543 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000544static int setup_board_part1(void)
545{
546 bd_t *bd = gd->bd;
547
548 /*
549 * Save local variables to board info struct
550 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000551 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
552 bd->bi_memsize = gd->ram_size; /* size in bytes */
553
554#ifdef CONFIG_SYS_SRAM_BASE
555 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
556 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
557#endif
558
Masahiro Yamada58dac322014-03-05 17:40:10 +0900559#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000560 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
561 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
562#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100563#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000564 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
565#endif
566#if defined(CONFIG_MPC83xx)
567 bd->bi_immrbar = CONFIG_SYS_IMMR;
568#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000569
570 return 0;
571}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100572#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000573
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100574#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000575static int setup_board_part2(void)
576{
577 bd_t *bd = gd->bd;
578
579 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
580 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
581#if defined(CONFIG_CPM2)
582 bd->bi_cpmfreq = gd->arch.cpm_clk;
583 bd->bi_brgfreq = gd->arch.brg_clk;
584 bd->bi_sccfreq = gd->arch.scc_clk;
585 bd->bi_vco = gd->arch.vco_out;
586#endif /* CONFIG_CPM2 */
587#if defined(CONFIG_MPC512X)
588 bd->bi_ipsfreq = gd->arch.ips_clk;
589#endif /* CONFIG_MPC512X */
590#if defined(CONFIG_MPC5xxx)
591 bd->bi_ipbfreq = gd->arch.ipb_clk;
592 bd->bi_pcifreq = gd->pci_clk;
593#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800594#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
595 bd->bi_pcifreq = gd->pci_clk;
596#endif
597#if defined(CONFIG_EXTRA_CLOCK)
598 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
599 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
600 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
601#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000602
603 return 0;
604}
605#endif
606
Simon Glass1938f4a2013-03-11 06:49:53 +0000607#ifdef CONFIG_POST
608static int init_post(void)
609{
610 post_bootmode_init();
611 post_run(NULL, POST_ROM | post_bootmode_get(0));
612
613 return 0;
614}
615#endif
616
Simon Glass1938f4a2013-03-11 06:49:53 +0000617static int reloc_fdt(void)
618{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100619#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600620 if (gd->flags & GD_FLG_SKIP_RELOC)
621 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000622 if (gd->new_fdt) {
623 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
624 gd->fdt_blob = gd->new_fdt;
625 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100626#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000627
628 return 0;
629}
630
631static int setup_reloc(void)
632{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600633 if (gd->flags & GD_FLG_SKIP_RELOC) {
634 debug("Skipping relocation due to flag\n");
635 return 0;
636 }
637
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800638#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000639 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100640#ifdef CONFIG_M68K
641 /*
642 * On all ColdFire arch cpu, monitor code starts always
643 * just after the default vector table location, so at 0x400
644 */
645 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
646#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800647#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000648 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
649
650 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000651 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000652 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
653 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000654
655 return 0;
656}
657
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100658#ifdef CONFIG_OF_BOARD_FIXUP
659static int fix_fdt(void)
660{
661 return board_fix_fdt((void *)gd->fdt_blob);
662}
663#endif
664
Simon Glass1938f4a2013-03-11 06:49:53 +0000665/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700666#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
667 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000668
669static int jump_to_copy(void)
670{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600671 if (gd->flags & GD_FLG_SKIP_RELOC)
672 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000673 /*
674 * x86 is special, but in a nice way. It uses a trampoline which
675 * enables the dcache if possible.
676 *
677 * For now, other archs use relocate_code(), which is implemented
678 * similarly for all archs. When we do generic relocation, hopefully
679 * we can make all archs enable the dcache prior to relocation.
680 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300681#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000682 /*
683 * SDRAM and console are now initialised. The final stack can now
684 * be setup in SDRAM. Code execution will continue in Flash, but
685 * with the stack in SDRAM and Global Data in temporary memory
686 * (CPU cache)
687 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600688 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000689 board_init_f_r_trampoline(gd->start_addr_sp);
690#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000691 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000692#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000693
694 return 0;
695}
696#endif
697
698/* Record the board_init_f() bootstage (after arch_cpu_init()) */
699static int mark_bootstage(void)
700{
701 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
702
703 return 0;
704}
705
Simon Glass9854a872015-11-08 23:47:48 -0700706static int initf_console_record(void)
707{
708#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
709 return console_record_init();
710#else
711 return 0;
712#endif
713}
714
Simon Glassab7cd622014-07-23 06:55:04 -0600715static int initf_dm(void)
716{
717#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
718 int ret;
719
720 ret = dm_init_and_scan(true);
721 if (ret)
722 return ret;
723#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700724#ifdef CONFIG_TIMER_EARLY
725 ret = dm_timer_init();
726 if (ret)
727 return ret;
728#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600729
730 return 0;
731}
732
Simon Glass146251f2015-01-19 22:16:12 -0700733/* Architecture-specific memory reservation */
734__weak int reserve_arch(void)
735{
736 return 0;
737}
738
Simon Glassd4c671c2015-03-05 12:25:16 -0700739__weak int arch_cpu_init_dm(void)
740{
741 return 0;
742}
743
Simon Glass4acff452017-01-16 07:03:50 -0700744static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000745 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700746#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700747 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700748#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800749#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700750 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800751#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700752 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700753 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600754#if defined(CONFIG_HAVE_FSP)
755 arch_fsp_init,
Bin Menga52a0682015-08-20 06:40:18 -0700756#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000757 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100758 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600759 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700760 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800761 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000762#if defined(CONFIG_BOARD_EARLY_INIT_F)
763 board_early_init_f,
764#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600765#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600766 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000767 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600768#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000769 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000770#if defined(CONFIG_BOARD_POSTCLK_INIT)
771 board_postclk_init,
772#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000773 env_init, /* initialize environment */
774 init_baud_rate, /* initialze baudrate settings */
775 serial_init, /* serial communications setup */
776 console_init_f, /* stage 1 init of console */
777 display_options, /* say that we are here */
778 display_text_info, /* show debugging info if required */
Simon Glass76d1d022017-03-28 10:27:30 -0600779#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
780 defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000781 checkcpu,
782#endif
Simon Glasscc664002017-01-23 13:31:25 -0700783#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000784 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700785#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000786#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900787 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000788#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000789 INIT_FUNC_WATCHDOG_INIT
790#if defined(CONFIG_MISC_INIT_F)
791 misc_init_f,
792#endif
793 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100794#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000795 init_func_i2c,
796#endif
797#if defined(CONFIG_HARD_SPI)
798 init_func_spi,
799#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000800 announce_dram_init,
801 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800802#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200803 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
804 defined(CONFIG_SH)
Simon Glass1938f4a2013-03-11 06:49:53 +0000805 dram_init, /* configure available RAM banks */
806#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100807#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000808 init_func_ram,
809#endif
810#ifdef CONFIG_POST
811 post_init_f,
812#endif
813 INIT_FUNC_WATCHDOG_RESET
814#if defined(CONFIG_SYS_DRAM_TEST)
815 testdram,
816#endif /* CONFIG_SYS_DRAM_TEST */
817 INIT_FUNC_WATCHDOG_RESET
818
Simon Glass1938f4a2013-03-11 06:49:53 +0000819#ifdef CONFIG_POST
820 init_post,
821#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000822 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000823 /*
824 * Now that we have DRAM mapped and working, we can
825 * relocate the code and continue running from DRAM.
826 *
827 * Reserve memory at end of RAM for (top down in that order):
828 * - area that won't get touched by U-Boot and Linux (optional)
829 * - kernel log buffer
830 * - protected RAM
831 * - LCD framebuffer
832 * - monitor code
833 * - board info struct
834 */
835 setup_dest_addr,
Simon Glassb56db482017-03-31 08:40:28 -0600836#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000837 reserve_logbuffer,
838#endif
839#ifdef CONFIG_PRAM
840 reserve_pram,
841#endif
842 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600843#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000844 reserve_mmu,
845#endif
Simon Glass5a541942016-01-18 19:52:21 -0700846 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700847 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000848 reserve_uboot,
849 reserve_malloc,
850 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000851 setup_machine,
852 reserve_global_data,
853 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -0700854 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000855 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600856 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000857 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200858#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
859 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000860 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100861#endif
862#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000863 INIT_FUNC_WATCHDOG_RESET
864 setup_board_part2,
865#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000866 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000867#ifdef CONFIG_SYS_EXTBDINFO
868 setup_board_extra,
869#endif
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100870#ifdef CONFIG_OF_BOARD_FIXUP
871 fix_fdt,
872#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000873 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000874 reloc_fdt,
875 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300876#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700877 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700878 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700879 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700880#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300881#if defined(CONFIG_XTENSA)
882 clear_bss,
883#endif
Simon Glass530f27e2017-01-16 07:03:49 -0700884#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
885 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000886 jump_to_copy,
887#endif
888 NULL,
889};
890
891void board_init_f(ulong boot_flags)
892{
York Sun2a1680e2014-05-02 17:28:04 -0700893#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
894 /*
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400895 * For some architectures, global data is initialized and used before
York Sun2a1680e2014-05-02 17:28:04 -0700896 * calling this function. The data should be preserved. For others,
897 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
898 * here to host global data until relocation.
899 */
Simon Glass1938f4a2013-03-11 06:49:53 +0000900 gd_t data;
901
902 gd = &data;
903
David Fengcce6be72013-12-14 11:47:36 +0800904 /*
905 * Clear global data before it is accessed at debug print
906 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400907 * get the wrong value of gd->have_console.
David Fengcce6be72013-12-14 11:47:36 +0800908 */
David Fengcce6be72013-12-14 11:47:36 +0800909 zero_global_data();
910#endif
911
Simon Glass1938f4a2013-03-11 06:49:53 +0000912 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400913 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000914
915 if (initcall_run_list(init_sequence_f))
916 hang();
917
Ben Stoltz9b217492015-07-31 09:31:37 -0600918#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass530f27e2017-01-16 07:03:49 -0700919 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000920 /* NOTREACHED - jump_to_copy() does not return */
921 hang();
922#endif
923}
924
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300925#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000926/*
927 * For now this code is only used on x86.
928 *
929 * init_sequence_f_r is the list of init functions which are run when
930 * U-Boot is executing from Flash with a semi-limited 'C' environment.
931 * The following limitations must be considered when implementing an
932 * '_f_r' function:
933 * - 'static' variables are read-only
934 * - Global Data (gd->xxx) is read/write
935 *
936 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
937 * supported). It _should_, if possible, copy global data to RAM and
938 * initialise the CPU caches (to speed up the relocation process)
939 *
940 * NOTE: At present only x86 uses this route, but it is intended that
941 * all archs will move to this when generic relocation is implemented.
942 */
Simon Glass4acff452017-01-16 07:03:50 -0700943static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700944#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000945 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700946#endif
Simon Glass48a33802013-03-05 14:39:52 +0000947
948 NULL,
949};
950
951void board_init_f_r(void)
952{
953 if (initcall_run_list(init_sequence_f_r))
954 hang();
955
956 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700957 * The pre-relocation drivers may be using memory that has now gone
958 * away. Mark serial as unavailable - this will fall back to the debug
959 * UART if available.
960 */
961 gd->flags &= ~GD_FLG_SERIAL_READY;
962
963 /*
Simon Glass48a33802013-03-05 14:39:52 +0000964 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
965 * Transfer execution from Flash to RAM by calculating the address
966 * of the in-RAM copy of board_init_r() and calling it
967 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +0300968 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000969
970 /* NOTREACHED - board_init_r() does not return */
971 hang();
972}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +0300973#endif /* CONFIG_X86 */