blob: bed09e249809ed41a5b1e130f08bba87fd6027ae [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 Glasse47b2d62017-03-31 08:40:38 -060042#include <relocate.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000043#include <spi.h>
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020044#include <status_led.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070045#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070046#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070047#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000048#include <watchdog.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000049#include <asm/io.h>
50#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060051#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060052#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000053
54/*
55 * Pointer to initial global data area
56 *
57 * Here we initialize it if needed.
58 */
59#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
60#undef XTRN_DECLARE_GLOBAL_DATA_PTR
61#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
62DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
63#else
64DECLARE_GLOBAL_DATA_PTR;
65#endif
66
67/*
Simon Glass4c509342015-04-28 20:25:03 -060068 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000069 * refactored to a single function, something like:
70 *
71 * void led_set_state(enum led_colour_t colour, int on);
72 */
73/************************************************************************
74 * Coloured LED functionality
75 ************************************************************************
76 * May be supplied by boards if desired
77 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020078__weak void coloured_LED_init(void) {}
79__weak void red_led_on(void) {}
80__weak void red_led_off(void) {}
81__weak void green_led_on(void) {}
82__weak void green_led_off(void) {}
83__weak void yellow_led_on(void) {}
84__weak void yellow_led_off(void) {}
85__weak void blue_led_on(void) {}
86__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000087
88/*
89 * Why is gd allocated a register? Prior to reloc it might be better to
90 * just pass it around to each function in this file?
91 *
92 * After reloc one could argue that it is hardly used and doesn't need
93 * to be in a register. Or if it is it should perhaps hold pointers to all
94 * global data for all modules, so that post-reloc we can avoid the massive
95 * literal pool we get on ARM. Or perhaps just encourage each module to use
96 * a structure...
97 */
98
Sonic Zhangd54d7eb2014-07-17 19:01:34 +080099#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000100static int init_func_watchdog_init(void)
101{
Tom Riniea3310e2017-03-14 11:08:10 -0400102# if defined(CONFIG_HW_WATCHDOG) && \
103 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100104 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200105 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100106 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800107 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000108 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200109# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000110 WATCHDOG_RESET();
111
112 return 0;
113}
114
115int init_func_watchdog_reset(void)
116{
117 WATCHDOG_RESET();
118
119 return 0;
120}
121#endif /* CONFIG_WATCHDOG */
122
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200123__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000124{
125 /* please define platform specific board_add_ram_info() */
126}
127
Simon Glass1938f4a2013-03-11 06:49:53 +0000128static int init_baud_rate(void)
129{
130 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
131 return 0;
132}
133
134static int display_text_info(void)
135{
Ben Stoltz9b217492015-07-31 09:31:37 -0600136#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100137 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000138
Simon Glass632efa72013-03-11 07:06:48 +0000139 bss_start = (ulong)&__bss_start;
140 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100141
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800142#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100143 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800144#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100145 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800146#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100147
148 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
149 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000150#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000151
Simon Glass1938f4a2013-03-11 06:49:53 +0000152#ifdef CONFIG_USE_IRQ
153 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
154 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
155#endif
156
157 return 0;
158}
159
160static int announce_dram_init(void)
161{
162 puts("DRAM: ");
163 return 0;
164}
165
angelo@sysam.ite310b932015-02-12 01:40:17 +0100166#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000167static int init_func_ram(void)
168{
Simon Glass088454c2017-03-31 08:40:25 -0600169 return initdram();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000170}
171#endif
172
Simon Glass1938f4a2013-03-11 06:49:53 +0000173static int show_dram_config(void)
174{
York Sunfa39ffe2014-05-02 17:28:05 -0700175 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000176
177#ifdef CONFIG_NR_DRAM_BANKS
178 int i;
179
180 debug("\nRAM Configuration:\n");
181 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
182 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700183 debug("Bank #%d: %llx ", i,
184 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000185#ifdef DEBUG
186 print_size(gd->bd->bi_dram[i].size, "\n");
187#endif
188 }
189 debug("\nDRAM: ");
190#else
191 size = gd->ram_size;
192#endif
193
Simon Glasse4fef6c2013-03-11 14:30:42 +0000194 print_size(size, "");
195 board_add_ram_info(0);
196 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000197
198 return 0;
199}
200
Simon Glass76b00ac2017-03-31 08:40:32 -0600201__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000202{
203#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
204 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
205 gd->bd->bi_dram[0].size = get_effective_memsize();
206#endif
Simon Glass76b00ac2017-03-31 08:40:32 -0600207
208 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000209}
210
Heiko Schocherea818db2013-01-29 08:53:15 +0100211#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000212static int init_func_i2c(void)
213{
214 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200215#ifdef CONFIG_SYS_I2C
216 i2c_init_all();
217#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000218 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200219#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000220 puts("ready\n");
221 return 0;
222}
223#endif
224
225#if defined(CONFIG_HARD_SPI)
226static int init_func_spi(void)
227{
228 puts("SPI: ");
229 spi_init();
230 puts("ready\n");
231 return 0;
232}
233#endif
234
235__maybe_unused
Simon Glass1938f4a2013-03-11 06:49:53 +0000236static int zero_global_data(void)
237{
238 memset((void *)gd, '\0', sizeof(gd_t));
239
240 return 0;
241}
242
243static int setup_mon_len(void)
244{
Michal Simeke945f6d2014-05-08 16:08:44 +0200245#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100246 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600247#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000248 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400249#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800250 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200251#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800252 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600253#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000254 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
255 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000256#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000257 return 0;
258}
259
260__weak int arch_cpu_init(void)
261{
262 return 0;
263}
264
Paul Burton8ebf5062016-09-21 11:18:46 +0100265__weak int mach_cpu_init(void)
266{
267 return 0;
268}
269
Simon Glass1938f4a2013-03-11 06:49:53 +0000270/* Get the top of usable RAM */
271__weak ulong board_get_usable_ram_top(ulong total_size)
272{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700273#ifdef CONFIG_SYS_SDRAM_BASE
274 /*
Simon Glass4c509342015-04-28 20:25:03 -0600275 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700276 * 32-bit address space. If so, clip the usable RAM so it doesn't.
277 */
278 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
279 /*
280 * Will wrap back to top of 32-bit space when reservations
281 * are made.
282 */
283 return 0;
284#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000285 return gd->ram_top;
286}
287
288static int setup_dest_addr(void)
289{
290 debug("Monitor len: %08lX\n", gd->mon_len);
291 /*
292 * Ram is setup, size stored in gd !!
293 */
294 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800295#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000296 /*
297 * Subtract specified amount of memory to hide so that it won't
298 * get "touched" at all by U-Boot. By fixing up gd->ram_size
299 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800300 * memory size and won't touch it either. This should work
301 * for arch/ppc and arch/powerpc. Only Linux board ports in
302 * arch/powerpc with bootwrapper support, that recalculate the
303 * memory size from the SDRAM controller setup will have to
304 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000305 */
York Sun36cc0de2017-03-06 09:02:28 -0800306 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
307#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000308#ifdef CONFIG_SYS_SDRAM_BASE
309 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
310#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000311 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000312 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000313 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000314 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700315#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000316 /*
317 * We need to make sure the location we intend to put secondary core
318 * boot code is reserved and not used by any part of u-boot
319 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000320 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
321 gd->relocaddr = determine_mp_bootpg(NULL);
322 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000323 }
324#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000325 return 0;
326}
327
Simon Glassb56db482017-03-31 08:40:28 -0600328#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000329static int reserve_logbuffer(void)
330{
Simon Glassb56db482017-03-31 08:40:28 -0600331#ifndef CONFIG_ALT_LB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000332 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000333 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000334 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000335 gd->relocaddr);
Simon Glassb56db482017-03-31 08:40:28 -0600336#endif
337
Simon Glass1938f4a2013-03-11 06:49:53 +0000338 return 0;
339}
340#endif
341
342#ifdef CONFIG_PRAM
343/* reserve protected RAM */
344static int reserve_pram(void)
345{
346 ulong reg;
347
348 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000349 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000350 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000351 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000352 return 0;
353}
354#endif /* CONFIG_PRAM */
355
356/* Round memory pointer down to next 4 kB limit */
357static int reserve_round_4k(void)
358{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000359 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 return 0;
361}
362
Simon Glass80d4bcd2017-03-31 08:40:29 -0600363#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000364static int reserve_mmu(void)
365{
Simon Glass80d4bcd2017-03-31 08:40:29 -0600366#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000367 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800368 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000369 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000370
371 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000372 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000373
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000374 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000375 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
376 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700377
378#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
379 /*
380 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
381 * with location within secure ram.
382 */
383 gd->arch.tlb_allocated = gd->arch.tlb_addr;
384#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600385#endif
York Sun50e93b92016-06-24 16:46:19 -0700386
Simon Glass1938f4a2013-03-11 06:49:53 +0000387 return 0;
388}
389#endif
390
Simon Glass5a541942016-01-18 19:52:21 -0700391static int reserve_video(void)
392{
Simon Glass0f079eb2017-03-31 08:40:30 -0600393#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700394 ulong addr;
395 int ret;
396
397 addr = gd->relocaddr;
398 ret = video_reserve(&addr);
399 if (ret)
400 return ret;
401 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600402#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700403# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000404 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700405# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000406 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000407 gd->relocaddr = lcd_setmem(gd->relocaddr);
408 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700409# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600410#elif defined(CONFIG_VIDEO) && \
411 (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700412 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
Tom Riniea3310e2017-03-14 11:08:10 -0400413 !defined(CONFIG_M68K)
Simon Glass8703ef32016-01-18 19:52:20 -0700414 /* reserve memory for video display (always full pages) */
415 gd->relocaddr = video_setmem(gd->relocaddr);
416 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600417#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700418
419 return 0;
420}
Simon Glass8703ef32016-01-18 19:52:20 -0700421
Simon Glass71c52db2013-06-11 11:14:42 -0700422static int reserve_trace(void)
423{
424#ifdef CONFIG_TRACE
425 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
426 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
427 debug("Reserving %dk for trace data at: %08lx\n",
428 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
429#endif
430
431 return 0;
432}
433
Simon Glass1938f4a2013-03-11 06:49:53 +0000434static int reserve_uboot(void)
435{
436 /*
437 * reserve memory for U-Boot code, data & bss
438 * round down to next 4 kB limit
439 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000440 gd->relocaddr -= gd->mon_len;
441 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000442#ifdef CONFIG_E500
443 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000444 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000445#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000446
447 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000448 gd->relocaddr);
449
450 gd->start_addr_sp = gd->relocaddr;
451
Simon Glass1938f4a2013-03-11 06:49:53 +0000452 return 0;
453}
454
455/* reserve memory for malloc() area */
456static int reserve_malloc(void)
457{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000458 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000459 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000460 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000461 return 0;
462}
463
464/* (permanently) allocate a Board Info struct */
465static int reserve_board(void)
466{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800467 if (!gd->bd) {
468 gd->start_addr_sp -= sizeof(bd_t);
469 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
470 memset(gd->bd, '\0', sizeof(bd_t));
471 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
472 sizeof(bd_t), gd->start_addr_sp);
473 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000474 return 0;
475}
476
477static int setup_machine(void)
478{
479#ifdef CONFIG_MACH_TYPE
480 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
481#endif
482 return 0;
483}
484
485static int reserve_global_data(void)
486{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000487 gd->start_addr_sp -= sizeof(gd_t);
488 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000489 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000490 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000491 return 0;
492}
493
494static int reserve_fdt(void)
495{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100496#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000497 /*
Simon Glass4c509342015-04-28 20:25:03 -0600498 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000499 * must relocate it. If it is embedded in the data section, then it
500 * will be relocated with other data.
501 */
502 if (gd->fdt_blob) {
503 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
504
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000505 gd->start_addr_sp -= gd->fdt_size;
506 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000507 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000508 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000509 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100510#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000511
512 return 0;
513}
514
Andreas Bießmann68145d42015-02-06 23:06:45 +0100515int arch_reserve_stacks(void)
516{
517 return 0;
518}
519
Simon Glass1938f4a2013-03-11 06:49:53 +0000520static int reserve_stacks(void)
521{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100522 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000523 gd->start_addr_sp -= 16;
524 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000525
526 /*
Simon Glass4c509342015-04-28 20:25:03 -0600527 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100528 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000529 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100530 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000531}
532
533static int display_new_sp(void)
534{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000535 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000536
537 return 0;
538}
539
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200540#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
541 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000542static int setup_board_part1(void)
543{
544 bd_t *bd = gd->bd;
545
546 /*
547 * Save local variables to board info struct
548 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000549 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
550 bd->bi_memsize = gd->ram_size; /* size in bytes */
551
552#ifdef CONFIG_SYS_SRAM_BASE
553 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
554 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
555#endif
556
Masahiro Yamada58dac322014-03-05 17:40:10 +0900557#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000558 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
559 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
560#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100561#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000562 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
563#endif
564#if defined(CONFIG_MPC83xx)
565 bd->bi_immrbar = CONFIG_SYS_IMMR;
566#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000567
568 return 0;
569}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100570#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000571
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100572#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000573static int setup_board_part2(void)
574{
575 bd_t *bd = gd->bd;
576
577 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
578 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
579#if defined(CONFIG_CPM2)
580 bd->bi_cpmfreq = gd->arch.cpm_clk;
581 bd->bi_brgfreq = gd->arch.brg_clk;
582 bd->bi_sccfreq = gd->arch.scc_clk;
583 bd->bi_vco = gd->arch.vco_out;
584#endif /* CONFIG_CPM2 */
585#if defined(CONFIG_MPC512X)
586 bd->bi_ipsfreq = gd->arch.ips_clk;
587#endif /* CONFIG_MPC512X */
588#if defined(CONFIG_MPC5xxx)
589 bd->bi_ipbfreq = gd->arch.ipb_clk;
590 bd->bi_pcifreq = gd->pci_clk;
591#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800592#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
593 bd->bi_pcifreq = gd->pci_clk;
594#endif
595#if defined(CONFIG_EXTRA_CLOCK)
596 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
597 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
598 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
599#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000600
601 return 0;
602}
603#endif
604
Simon Glass1938f4a2013-03-11 06:49:53 +0000605#ifdef CONFIG_POST
606static int init_post(void)
607{
608 post_bootmode_init();
609 post_run(NULL, POST_ROM | post_bootmode_get(0));
610
611 return 0;
612}
613#endif
614
Simon Glass1938f4a2013-03-11 06:49:53 +0000615static int reloc_fdt(void)
616{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100617#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600618 if (gd->flags & GD_FLG_SKIP_RELOC)
619 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000620 if (gd->new_fdt) {
621 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
622 gd->fdt_blob = gd->new_fdt;
623 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100624#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000625
626 return 0;
627}
628
629static int setup_reloc(void)
630{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600631 if (gd->flags & GD_FLG_SKIP_RELOC) {
632 debug("Skipping relocation due to flag\n");
633 return 0;
634 }
635
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800636#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000637 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100638#ifdef CONFIG_M68K
639 /*
640 * On all ColdFire arch cpu, monitor code starts always
641 * just after the default vector table location, so at 0x400
642 */
643 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
644#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800645#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000646 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
647
648 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000649 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000650 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
651 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000652
653 return 0;
654}
655
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100656#ifdef CONFIG_OF_BOARD_FIXUP
657static int fix_fdt(void)
658{
659 return board_fix_fdt((void *)gd->fdt_blob);
660}
661#endif
662
Simon Glass1938f4a2013-03-11 06:49:53 +0000663/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700664#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
665 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000666
667static int jump_to_copy(void)
668{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600669 if (gd->flags & GD_FLG_SKIP_RELOC)
670 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000671 /*
672 * x86 is special, but in a nice way. It uses a trampoline which
673 * enables the dcache if possible.
674 *
675 * For now, other archs use relocate_code(), which is implemented
676 * similarly for all archs. When we do generic relocation, hopefully
677 * we can make all archs enable the dcache prior to relocation.
678 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300679#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000680 /*
681 * SDRAM and console are now initialised. The final stack can now
682 * be setup in SDRAM. Code execution will continue in Flash, but
683 * with the stack in SDRAM and Global Data in temporary memory
684 * (CPU cache)
685 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600686 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000687 board_init_f_r_trampoline(gd->start_addr_sp);
688#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000689 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000690#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000691
692 return 0;
693}
694#endif
695
696/* Record the board_init_f() bootstage (after arch_cpu_init()) */
697static int mark_bootstage(void)
698{
699 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
700
701 return 0;
702}
703
Simon Glass9854a872015-11-08 23:47:48 -0700704static int initf_console_record(void)
705{
706#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
707 return console_record_init();
708#else
709 return 0;
710#endif
711}
712
Simon Glassab7cd622014-07-23 06:55:04 -0600713static int initf_dm(void)
714{
715#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
716 int ret;
717
718 ret = dm_init_and_scan(true);
719 if (ret)
720 return ret;
721#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700722#ifdef CONFIG_TIMER_EARLY
723 ret = dm_timer_init();
724 if (ret)
725 return ret;
726#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600727
728 return 0;
729}
730
Simon Glass146251f2015-01-19 22:16:12 -0700731/* Architecture-specific memory reservation */
732__weak int reserve_arch(void)
733{
734 return 0;
735}
736
Simon Glassd4c671c2015-03-05 12:25:16 -0700737__weak int arch_cpu_init_dm(void)
738{
739 return 0;
740}
741
Simon Glass4acff452017-01-16 07:03:50 -0700742static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000743 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700744#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700745 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700746#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800747#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700748 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800749#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700750 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700751 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600752#if defined(CONFIG_HAVE_FSP)
753 arch_fsp_init,
Bin Menga52a068e2015-08-20 06:40:18 -0700754#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000755 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100756 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600757 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700758 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800759 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000760#if defined(CONFIG_BOARD_EARLY_INIT_F)
761 board_early_init_f,
762#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600763#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600764 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000765 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600766#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000767 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000768#if defined(CONFIG_BOARD_POSTCLK_INIT)
769 board_postclk_init,
770#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000771 env_init, /* initialize environment */
772 init_baud_rate, /* initialze baudrate settings */
773 serial_init, /* serial communications setup */
774 console_init_f, /* stage 1 init of console */
775 display_options, /* say that we are here */
776 display_text_info, /* show debugging info if required */
Simon Glass76d1d022017-03-28 10:27:30 -0600777#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
778 defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000779 checkcpu,
780#endif
Simon Glasscc664002017-01-23 13:31:25 -0700781#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000782 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700783#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000784#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900785 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000786#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000787 INIT_FUNC_WATCHDOG_INIT
788#if defined(CONFIG_MISC_INIT_F)
789 misc_init_f,
790#endif
791 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100792#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000793 init_func_i2c,
794#endif
795#if defined(CONFIG_HARD_SPI)
796 init_func_spi,
797#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000798 announce_dram_init,
799 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800800#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200801 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
802 defined(CONFIG_SH)
Simon Glass1938f4a2013-03-11 06:49:53 +0000803 dram_init, /* configure available RAM banks */
804#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100805#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000806 init_func_ram,
807#endif
808#ifdef CONFIG_POST
809 post_init_f,
810#endif
811 INIT_FUNC_WATCHDOG_RESET
812#if defined(CONFIG_SYS_DRAM_TEST)
813 testdram,
814#endif /* CONFIG_SYS_DRAM_TEST */
815 INIT_FUNC_WATCHDOG_RESET
816
Simon Glass1938f4a2013-03-11 06:49:53 +0000817#ifdef CONFIG_POST
818 init_post,
819#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000820 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000821 /*
822 * Now that we have DRAM mapped and working, we can
823 * relocate the code and continue running from DRAM.
824 *
825 * Reserve memory at end of RAM for (top down in that order):
826 * - area that won't get touched by U-Boot and Linux (optional)
827 * - kernel log buffer
828 * - protected RAM
829 * - LCD framebuffer
830 * - monitor code
831 * - board info struct
832 */
833 setup_dest_addr,
Simon Glassb56db482017-03-31 08:40:28 -0600834#if defined(CONFIG_LOGBUFFER)
Simon Glass1938f4a2013-03-11 06:49:53 +0000835 reserve_logbuffer,
836#endif
837#ifdef CONFIG_PRAM
838 reserve_pram,
839#endif
840 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600841#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000842 reserve_mmu,
843#endif
Simon Glass5a541942016-01-18 19:52:21 -0700844 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700845 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000846 reserve_uboot,
847 reserve_malloc,
848 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000849 setup_machine,
850 reserve_global_data,
851 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -0700852 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000853 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600854 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000855 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200856#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
857 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000858 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100859#endif
860#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000861 INIT_FUNC_WATCHDOG_RESET
862 setup_board_part2,
863#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000864 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000865#ifdef CONFIG_SYS_EXTBDINFO
866 setup_board_extra,
867#endif
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100868#ifdef CONFIG_OF_BOARD_FIXUP
869 fix_fdt,
870#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000871 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000872 reloc_fdt,
873 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300874#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700875 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700876 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700877 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700878#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300879#if defined(CONFIG_XTENSA)
880 clear_bss,
881#endif
Simon Glass530f27e2017-01-16 07:03:49 -0700882#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
883 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000884 jump_to_copy,
885#endif
886 NULL,
887};
888
889void board_init_f(ulong boot_flags)
890{
York Sun2a1680e2014-05-02 17:28:04 -0700891#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
892 /*
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400893 * For some architectures, global data is initialized and used before
York Sun2a1680e2014-05-02 17:28:04 -0700894 * calling this function. The data should be preserved. For others,
895 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
896 * here to host global data until relocation.
897 */
Simon Glass1938f4a2013-03-11 06:49:53 +0000898 gd_t data;
899
900 gd = &data;
901
David Fengcce6be72013-12-14 11:47:36 +0800902 /*
903 * Clear global data before it is accessed at debug print
904 * in initcall_run_list. Otherwise the debug print probably
Robert P. J. Dayfc0b5942016-09-07 14:27:59 -0400905 * get the wrong value of gd->have_console.
David Fengcce6be72013-12-14 11:47:36 +0800906 */
David Fengcce6be72013-12-14 11:47:36 +0800907 zero_global_data();
908#endif
909
Simon Glass1938f4a2013-03-11 06:49:53 +0000910 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400911 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000912
913 if (initcall_run_list(init_sequence_f))
914 hang();
915
Ben Stoltz9b217492015-07-31 09:31:37 -0600916#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Simon Glass530f27e2017-01-16 07:03:49 -0700917 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000918 /* NOTREACHED - jump_to_copy() does not return */
919 hang();
920#endif
921}
922
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300923#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000924/*
925 * For now this code is only used on x86.
926 *
927 * init_sequence_f_r is the list of init functions which are run when
928 * U-Boot is executing from Flash with a semi-limited 'C' environment.
929 * The following limitations must be considered when implementing an
930 * '_f_r' function:
931 * - 'static' variables are read-only
932 * - Global Data (gd->xxx) is read/write
933 *
934 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
935 * supported). It _should_, if possible, copy global data to RAM and
936 * initialise the CPU caches (to speed up the relocation process)
937 *
938 * NOTE: At present only x86 uses this route, but it is intended that
939 * all archs will move to this when generic relocation is implemented.
940 */
Simon Glass4acff452017-01-16 07:03:50 -0700941static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700942#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000943 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700944#endif
Simon Glass48a33802013-03-05 14:39:52 +0000945
946 NULL,
947};
948
949void board_init_f_r(void)
950{
951 if (initcall_run_list(init_sequence_f_r))
952 hang();
953
954 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700955 * The pre-relocation drivers may be using memory that has now gone
956 * away. Mark serial as unavailable - this will fall back to the debug
957 * UART if available.
958 */
959 gd->flags &= ~GD_FLG_SERIAL_READY;
960
961 /*
Simon Glass48a33802013-03-05 14:39:52 +0000962 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
963 * Transfer execution from Flash to RAM by calculating the address
964 * of the in-RAM copy of board_init_r() and calling it
965 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +0300966 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000967
968 /* NOTREACHED - board_init_r() does not return */
969 hang();
970}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +0300971#endif /* CONFIG_X86 */