blob: 05f4b73c6ed3db2ad666f16b9187baa1440b3331 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass1938f4a2013-03-11 06:49:53 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2002-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * (C) Copyright 2002
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Marius Groeger <mgroeger@sysgo.de>
Simon Glass1938f4a2013-03-11 06:49:53 +000010 */
11
12#include <common.h>
Simon Glassf0293d32018-11-15 18:43:52 -070013#include <bloblist.h>
Simon Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Mario Six5d6c61a2018-08-06 10:23:41 +020015#include <cpu.h>
Simon Glass30c7c432019-11-14 12:57:34 -070016#include <cpu_func.h>
Simon Glassab7cd622014-07-23 06:55:04 -060017#include <dm.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060018#include <env.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060019#include <env_internal.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000020#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000021#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000022#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000023#include <initcall.h>
Simon Glass3c1ecde2019-08-01 09:46:38 -060024#include <lcd.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070025#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050026#include <mapmem.h>
Simon Glassa733b062013-04-26 02:53:43 +000027#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000028#include <post.h>
Simon Glasse47b2d62017-03-31 08:40:38 -060029#include <relocate.h>
Simon Glassb03e0512019-11-14 12:57:24 -070030#include <serial.h>
Simon Glassb0edea32018-11-15 18:44:09 -070031#ifdef CONFIG_SPL
32#include <spl.h>
33#endif
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020034#include <status_led.h>
Mario Six23471ae2018-08-06 10:23:34 +020035#include <sysreset.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070036#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070037#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070038#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000039#include <watchdog.h>
Simon Glassb885d022017-05-17 08:23:01 -060040#ifdef CONFIG_MACH_TYPE
41#include <asm/mach-types.h>
42#endif
Simon Glass1fbf97d2017-03-31 08:40:39 -060043#if defined(CONFIG_MP) && defined(CONFIG_PPC)
44#include <asm/mp.h>
45#endif
Simon Glass1938f4a2013-03-11 06:49:53 +000046#include <asm/io.h>
47#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060048#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060049#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000050
51/*
52 * Pointer to initial global data area
53 *
54 * Here we initialize it if needed.
55 */
56#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
57#undef XTRN_DECLARE_GLOBAL_DATA_PTR
58#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Mario Six16ef1472018-01-15 11:10:02 +010059DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
Simon Glass1938f4a2013-03-11 06:49:53 +000060#else
61DECLARE_GLOBAL_DATA_PTR;
62#endif
63
64/*
Simon Glass4c509342015-04-28 20:25:03 -060065 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000066 * refactored to a single function, something like:
67 *
68 * void led_set_state(enum led_colour_t colour, int on);
69 */
70/************************************************************************
71 * Coloured LED functionality
72 ************************************************************************
73 * May be supplied by boards if desired
74 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020075__weak void coloured_LED_init(void) {}
76__weak void red_led_on(void) {}
77__weak void red_led_off(void) {}
78__weak void green_led_on(void) {}
79__weak void green_led_off(void) {}
80__weak void yellow_led_on(void) {}
81__weak void yellow_led_off(void) {}
82__weak void blue_led_on(void) {}
83__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000084
85/*
86 * Why is gd allocated a register? Prior to reloc it might be better to
87 * just pass it around to each function in this file?
88 *
89 * After reloc one could argue that it is hardly used and doesn't need
90 * to be in a register. Or if it is it should perhaps hold pointers to all
91 * global data for all modules, so that post-reloc we can avoid the massive
92 * literal pool we get on ARM. Or perhaps just encourage each module to use
93 * a structure...
94 */
95
Sonic Zhangd54d7eb2014-07-17 19:01:34 +080096#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +000097static int init_func_watchdog_init(void)
98{
Tom Riniea3310e2017-03-14 11:08:10 -040099# if defined(CONFIG_HW_WATCHDOG) && \
100 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -0700101 defined(CONFIG_SH) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200102 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100103 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800104 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000105 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200106# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000107 WATCHDOG_RESET();
108
109 return 0;
110}
111
112int init_func_watchdog_reset(void)
113{
114 WATCHDOG_RESET();
115
116 return 0;
117}
118#endif /* CONFIG_WATCHDOG */
119
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200120__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000121{
122 /* please define platform specific board_add_ram_info() */
123}
124
Simon Glass1938f4a2013-03-11 06:49:53 +0000125static int init_baud_rate(void)
126{
Simon Glassbfebc8c2017-08-03 12:22:13 -0600127 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glass1938f4a2013-03-11 06:49:53 +0000128 return 0;
129}
130
131static int display_text_info(void)
132{
Ben Stoltz9b217492015-07-31 09:31:37 -0600133#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100134 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000135
Simon Glass632efa72013-03-11 07:06:48 +0000136 bss_start = (ulong)&__bss_start;
137 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100138
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800139#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100140 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800141#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100142 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800143#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100144
145 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
Mario Six16ef1472018-01-15 11:10:02 +0100146 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000147#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000148
Simon Glass1938f4a2013-03-11 06:49:53 +0000149 return 0;
150}
151
Mario Six23471ae2018-08-06 10:23:34 +0200152#ifdef CONFIG_SYSRESET
153static int print_resetinfo(void)
154{
155 struct udevice *dev;
156 char status[256];
157 int ret;
158
159 ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
160 if (ret) {
161 debug("%s: No sysreset device found (error: %d)\n",
162 __func__, ret);
163 /* Not all boards have sysreset drivers available during early
164 * boot, so don't fail if one can't be found.
165 */
166 return 0;
167 }
168
169 if (!sysreset_get_status(dev, status, sizeof(status)))
170 printf("%s", status);
171
172 return 0;
173}
174#endif
175
Mario Six5d6c61a2018-08-06 10:23:41 +0200176#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
177static int print_cpuinfo(void)
178{
179 struct udevice *dev;
180 char desc[512];
181 int ret;
182
183 ret = uclass_first_device_err(UCLASS_CPU, &dev);
184 if (ret) {
185 debug("%s: Could not get CPU device (err = %d)\n",
186 __func__, ret);
187 return ret;
188 }
189
190 ret = cpu_get_desc(dev, desc, sizeof(desc));
191 if (ret) {
192 debug("%s: Could not get CPU description (err = %d)\n",
193 dev->name, ret);
194 return ret;
195 }
196
Bin Mengecfe6632018-10-10 22:06:55 -0700197 printf("CPU: %s\n", desc);
Mario Six5d6c61a2018-08-06 10:23:41 +0200198
199 return 0;
200}
201#endif
202
Simon Glass1938f4a2013-03-11 06:49:53 +0000203static int announce_dram_init(void)
204{
205 puts("DRAM: ");
206 return 0;
207}
208
209static int show_dram_config(void)
210{
York Sunfa39ffe2014-05-02 17:28:05 -0700211 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000212
213#ifdef CONFIG_NR_DRAM_BANKS
214 int i;
215
216 debug("\nRAM Configuration:\n");
217 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
218 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700219 debug("Bank #%d: %llx ", i,
220 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000221#ifdef DEBUG
222 print_size(gd->bd->bi_dram[i].size, "\n");
223#endif
224 }
225 debug("\nDRAM: ");
226#else
227 size = gd->ram_size;
228#endif
229
Simon Glasse4fef6c2013-03-11 14:30:42 +0000230 print_size(size, "");
231 board_add_ram_info(0);
232 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000233
234 return 0;
235}
236
Simon Glass76b00ac2017-03-31 08:40:32 -0600237__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000238{
239#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
240 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
241 gd->bd->bi_dram[0].size = get_effective_memsize();
242#endif
Simon Glass76b00ac2017-03-31 08:40:32 -0600243
244 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000245}
246
Simon Glass69153982017-05-12 21:09:56 -0600247#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000248static int init_func_i2c(void)
249{
250 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200251#ifdef CONFIG_SYS_I2C
252 i2c_init_all();
253#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000254 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200255#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000256 puts("ready\n");
257 return 0;
258}
259#endif
260
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530261#if defined(CONFIG_VID)
262__weak int init_func_vid(void)
263{
264 return 0;
265}
266#endif
267
Simon Glass1938f4a2013-03-11 06:49:53 +0000268static int setup_mon_len(void)
269{
Michal Simeke945f6d2014-05-08 16:08:44 +0200270#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100271 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600272#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000273 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400274#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800275 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Rick Chen068feb92017-12-26 13:55:58 +0800276#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800277 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600278#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000279 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
280 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000281#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000282 return 0;
283}
284
Simon Glassb0edea32018-11-15 18:44:09 -0700285static int setup_spl_handoff(void)
286{
287#if CONFIG_IS_ENABLED(HANDOFF)
288 gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
289 sizeof(struct spl_handoff));
290 debug("Found SPL hand-off info %p\n", gd->spl_handoff);
291#endif
292
293 return 0;
294}
295
Simon Glass1938f4a2013-03-11 06:49:53 +0000296__weak int arch_cpu_init(void)
297{
298 return 0;
299}
300
Paul Burton8ebf5062016-09-21 11:18:46 +0100301__weak int mach_cpu_init(void)
302{
303 return 0;
304}
305
Simon Glass1938f4a2013-03-11 06:49:53 +0000306/* Get the top of usable RAM */
307__weak ulong board_get_usable_ram_top(ulong total_size)
308{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700309#ifdef CONFIG_SYS_SDRAM_BASE
310 /*
Simon Glass4c509342015-04-28 20:25:03 -0600311 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700312 * 32-bit address space. If so, clip the usable RAM so it doesn't.
313 */
314 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
315 /*
316 * Will wrap back to top of 32-bit space when reservations
317 * are made.
318 */
319 return 0;
320#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000321 return gd->ram_top;
322}
323
324static int setup_dest_addr(void)
325{
326 debug("Monitor len: %08lX\n", gd->mon_len);
327 /*
328 * Ram is setup, size stored in gd !!
329 */
330 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800331#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000332 /*
333 * Subtract specified amount of memory to hide so that it won't
334 * get "touched" at all by U-Boot. By fixing up gd->ram_size
335 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800336 * memory size and won't touch it either. This should work
337 * for arch/ppc and arch/powerpc. Only Linux board ports in
338 * arch/powerpc with bootwrapper support, that recalculate the
339 * memory size from the SDRAM controller setup will have to
340 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000341 */
York Sun36cc0de2017-03-06 09:02:28 -0800342 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
343#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000344#ifdef CONFIG_SYS_SDRAM_BASE
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530345 gd->ram_base = CONFIG_SYS_SDRAM_BASE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000346#endif
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530347 gd->ram_top = gd->ram_base + get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000348 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000349 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000350 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700351#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000352 /*
353 * We need to make sure the location we intend to put secondary core
354 * boot code is reserved and not used by any part of u-boot
355 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000356 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
357 gd->relocaddr = determine_mp_bootpg(NULL);
358 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000359 }
360#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000361 return 0;
362}
363
Simon Glass1938f4a2013-03-11 06:49:53 +0000364#ifdef CONFIG_PRAM
365/* reserve protected RAM */
366static int reserve_pram(void)
367{
368 ulong reg;
369
Simon Glassbfebc8c2017-08-03 12:22:13 -0600370 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000371 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000372 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000373 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000374 return 0;
375}
376#endif /* CONFIG_PRAM */
377
378/* Round memory pointer down to next 4 kB limit */
379static int reserve_round_4k(void)
380{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000381 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000382 return 0;
383}
384
Simon Glass80d4bcd2017-03-31 08:40:29 -0600385#ifdef CONFIG_ARM
Siva Durga Prasad Paladugu60873f72017-07-13 19:01:08 +0530386__weak int reserve_mmu(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000387{
Trevor Woerner10015022019-05-03 09:41:00 -0400388#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000389 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800390 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000391 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000392
393 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000394 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000395
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000396 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000397 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
398 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700399
400#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
401 /*
402 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
403 * with location within secure ram.
404 */
405 gd->arch.tlb_allocated = gd->arch.tlb_addr;
406#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600407#endif
York Sun50e93b92016-06-24 16:46:19 -0700408
Simon Glass1938f4a2013-03-11 06:49:53 +0000409 return 0;
410}
411#endif
412
Simon Glass5a541942016-01-18 19:52:21 -0700413static int reserve_video(void)
414{
Simon Glass0f079eb2017-03-31 08:40:30 -0600415#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700416 ulong addr;
417 int ret;
418
419 addr = gd->relocaddr;
420 ret = video_reserve(&addr);
421 if (ret)
422 return ret;
423 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600424#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700425# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000426 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700427# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000428 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000429 gd->relocaddr = lcd_setmem(gd->relocaddr);
430 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700431# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600432#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700433
434 return 0;
435}
Simon Glass8703ef32016-01-18 19:52:20 -0700436
Simon Glass71c52db2013-06-11 11:14:42 -0700437static int reserve_trace(void)
438{
439#ifdef CONFIG_TRACE
440 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
441 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
Heinrich Schuchardt7ea33572019-06-14 21:52:22 +0200442 debug("Reserving %luk for trace data at: %08lx\n",
443 (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
Simon Glass71c52db2013-06-11 11:14:42 -0700444#endif
445
446 return 0;
447}
448
Simon Glass1938f4a2013-03-11 06:49:53 +0000449static int reserve_uboot(void)
450{
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300451 if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
452 /*
453 * reserve memory for U-Boot code, data & bss
454 * round down to next 4 kB limit
455 */
456 gd->relocaddr -= gd->mon_len;
457 gd->relocaddr &= ~(4096 - 1);
458 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
459 /* round down to next 64 kB limit so that IVPR stays aligned */
460 gd->relocaddr &= ~(65536 - 1);
461 #endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000462
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300463 debug("Reserving %ldk for U-Boot at: %08lx\n",
464 gd->mon_len >> 10, gd->relocaddr);
465 }
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000466
467 gd->start_addr_sp = gd->relocaddr;
468
Simon Glass1938f4a2013-03-11 06:49:53 +0000469 return 0;
470}
471
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700472#ifdef CONFIG_SYS_NONCACHED_MEMORY
473static int reserve_noncached(void)
474{
Stephen Warren5e0404f2019-08-27 11:54:31 -0600475 /*
476 * The value of gd->start_addr_sp must match the value of malloc_start
477 * calculated in boatrd_f.c:initr_malloc(), which is passed to
478 * board_r.c:mem_malloc_init() and then used by
479 * cache.c:noncached_init()
480 *
481 * These calculations must match the code in cache.c:noncached_init()
482 */
483 gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
484 MMU_SECTION_SIZE;
485 gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
486 MMU_SECTION_SIZE);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700487 debug("Reserving %dM for noncached_alloc() at: %08lx\n",
488 CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
489
490 return 0;
491}
492#endif
493
Simon Glass1938f4a2013-03-11 06:49:53 +0000494/* reserve memory for malloc() area */
495static int reserve_malloc(void)
496{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000497 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000498 debug("Reserving %dk for malloc() at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100499 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700500#ifdef CONFIG_SYS_NONCACHED_MEMORY
501 reserve_noncached();
502#endif
503
Simon Glass1938f4a2013-03-11 06:49:53 +0000504 return 0;
505}
506
507/* (permanently) allocate a Board Info struct */
508static int reserve_board(void)
509{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800510 if (!gd->bd) {
511 gd->start_addr_sp -= sizeof(bd_t);
512 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
513 memset(gd->bd, '\0', sizeof(bd_t));
514 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
515 sizeof(bd_t), gd->start_addr_sp);
516 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000517 return 0;
518}
519
520static int setup_machine(void)
521{
522#ifdef CONFIG_MACH_TYPE
523 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
524#endif
525 return 0;
526}
527
528static int reserve_global_data(void)
529{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000530 gd->start_addr_sp -= sizeof(gd_t);
531 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000532 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100533 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000534 return 0;
535}
536
537static int reserve_fdt(void)
538{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100539#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000540 /*
Simon Glass4c509342015-04-28 20:25:03 -0600541 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000542 * must relocate it. If it is embedded in the data section, then it
543 * will be relocated with other data.
544 */
545 if (gd->fdt_blob) {
546 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
547
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000548 gd->start_addr_sp -= gd->fdt_size;
549 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000550 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000551 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000552 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100553#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000554
555 return 0;
556}
557
Simon Glass25e7dc62017-05-22 05:05:30 -0600558static int reserve_bootstage(void)
559{
560#ifdef CONFIG_BOOTSTAGE
561 int size = bootstage_get_size();
562
563 gd->start_addr_sp -= size;
564 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
565 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
566 gd->start_addr_sp);
567#endif
568
569 return 0;
570}
571
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100572__weak int arch_reserve_stacks(void)
Andreas Bießmann68145d42015-02-06 23:06:45 +0100573{
574 return 0;
575}
576
Simon Glass1938f4a2013-03-11 06:49:53 +0000577static int reserve_stacks(void)
578{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100579 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000580 gd->start_addr_sp -= 16;
581 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000582
583 /*
Simon Glass4c509342015-04-28 20:25:03 -0600584 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100585 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000586 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100587 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000588}
589
Simon Glassf0293d32018-11-15 18:43:52 -0700590static int reserve_bloblist(void)
591{
592#ifdef CONFIG_BLOBLIST
Simon Glass5074a8a2019-10-21 17:26:46 -0600593 gd->start_addr_sp &= ~0xf;
Simon Glassf0293d32018-11-15 18:43:52 -0700594 gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
595 gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
596#endif
597
598 return 0;
599}
600
Simon Glass1938f4a2013-03-11 06:49:53 +0000601static int display_new_sp(void)
602{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000603 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000604
605 return 0;
606}
607
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200608#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
609 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000610static int setup_board_part1(void)
611{
612 bd_t *bd = gd->bd;
613
614 /*
615 * Save local variables to board info struct
616 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000617 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
618 bd->bi_memsize = gd->ram_size; /* size in bytes */
619
620#ifdef CONFIG_SYS_SRAM_BASE
621 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
622 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
623#endif
624
Heiko Schocher50258972017-06-07 17:33:11 +0200625#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000626 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
627#endif
Heiko Schocher064b55c2017-06-14 05:49:40 +0200628#if defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000629 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
630#endif
631#if defined(CONFIG_MPC83xx)
632 bd->bi_immrbar = CONFIG_SYS_IMMR;
633#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000634
635 return 0;
636}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100637#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000638
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100639#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000640static int setup_board_part2(void)
641{
642 bd_t *bd = gd->bd;
643
644 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
645 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
646#if defined(CONFIG_CPM2)
647 bd->bi_cpmfreq = gd->arch.cpm_clk;
648 bd->bi_brgfreq = gd->arch.brg_clk;
649 bd->bi_sccfreq = gd->arch.scc_clk;
650 bd->bi_vco = gd->arch.vco_out;
651#endif /* CONFIG_CPM2 */
Alison Wang1313db42015-02-12 18:33:15 +0800652#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
653 bd->bi_pcifreq = gd->pci_clk;
654#endif
655#if defined(CONFIG_EXTRA_CLOCK)
656 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
657 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
658 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
659#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000660
661 return 0;
662}
663#endif
664
Simon Glass1938f4a2013-03-11 06:49:53 +0000665#ifdef CONFIG_POST
666static int init_post(void)
667{
668 post_bootmode_init();
669 post_run(NULL, POST_ROM | post_bootmode_get(0));
670
671 return 0;
672}
673#endif
674
Simon Glass1938f4a2013-03-11 06:49:53 +0000675static int reloc_fdt(void)
676{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100677#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600678 if (gd->flags & GD_FLG_SKIP_RELOC)
679 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000680 if (gd->new_fdt) {
681 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
682 gd->fdt_blob = gd->new_fdt;
683 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100684#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000685
686 return 0;
687}
688
Simon Glass25e7dc62017-05-22 05:05:30 -0600689static int reloc_bootstage(void)
690{
691#ifdef CONFIG_BOOTSTAGE
692 if (gd->flags & GD_FLG_SKIP_RELOC)
693 return 0;
694 if (gd->new_bootstage) {
695 int size = bootstage_get_size();
696
697 debug("Copying bootstage from %p to %p, size %x\n",
698 gd->bootstage, gd->new_bootstage, size);
699 memcpy(gd->new_bootstage, gd->bootstage, size);
700 gd->bootstage = gd->new_bootstage;
Simon Glassac9cd482019-10-21 17:26:50 -0600701 bootstage_relocate();
Simon Glass25e7dc62017-05-22 05:05:30 -0600702 }
703#endif
704
705 return 0;
706}
707
Simon Glassf0293d32018-11-15 18:43:52 -0700708static int reloc_bloblist(void)
709{
710#ifdef CONFIG_BLOBLIST
711 if (gd->flags & GD_FLG_SKIP_RELOC)
712 return 0;
713 if (gd->new_bloblist) {
714 int size = CONFIG_BLOBLIST_SIZE;
715
716 debug("Copying bloblist from %p to %p, size %x\n",
717 gd->bloblist, gd->new_bloblist, size);
718 memcpy(gd->new_bloblist, gd->bloblist, size);
719 gd->bloblist = gd->new_bloblist;
720 }
721#endif
722
723 return 0;
724}
725
Simon Glass1938f4a2013-03-11 06:49:53 +0000726static int setup_reloc(void)
727{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600728 if (gd->flags & GD_FLG_SKIP_RELOC) {
729 debug("Skipping relocation due to flag\n");
730 return 0;
731 }
732
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800733#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200734#ifdef ARM
735 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
736#elif defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100737 /*
738 * On all ColdFire arch cpu, monitor code starts always
739 * just after the default vector table location, so at 0x400
740 */
741 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Simon Glass001d1882019-04-08 13:20:41 -0600742#elif !defined(CONFIG_SANDBOX)
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200743 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100744#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800745#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000746 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
747
748 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000749 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000750 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
751 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000752
753 return 0;
754}
755
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100756#ifdef CONFIG_OF_BOARD_FIXUP
757static int fix_fdt(void)
758{
759 return board_fix_fdt((void *)gd->fdt_blob);
760}
761#endif
762
Simon Glass1938f4a2013-03-11 06:49:53 +0000763/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700764#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
765 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000766
767static int jump_to_copy(void)
768{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600769 if (gd->flags & GD_FLG_SKIP_RELOC)
770 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000771 /*
772 * x86 is special, but in a nice way. It uses a trampoline which
773 * enables the dcache if possible.
774 *
775 * For now, other archs use relocate_code(), which is implemented
776 * similarly for all archs. When we do generic relocation, hopefully
777 * we can make all archs enable the dcache prior to relocation.
778 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300779#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000780 /*
781 * SDRAM and console are now initialised. The final stack can now
782 * be setup in SDRAM. Code execution will continue in Flash, but
783 * with the stack in SDRAM and Global Data in temporary memory
784 * (CPU cache)
785 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600786 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000787 board_init_f_r_trampoline(gd->start_addr_sp);
788#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000789 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000790#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000791
792 return 0;
793}
794#endif
795
796/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glassb383d6c2017-05-22 05:05:25 -0600797static int initf_bootstage(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000798{
Simon Glassbaa7d342017-06-07 10:28:46 -0600799 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
800 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glassb383d6c2017-05-22 05:05:25 -0600801 int ret;
802
Simon Glass824bb1b2017-05-22 05:05:35 -0600803 ret = bootstage_init(!from_spl);
Simon Glassb383d6c2017-05-22 05:05:25 -0600804 if (ret)
805 return ret;
Simon Glass824bb1b2017-05-22 05:05:35 -0600806 if (from_spl) {
807 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
808 CONFIG_BOOTSTAGE_STASH_SIZE);
809
810 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
811 if (ret && ret != -ENOENT) {
812 debug("Failed to unstash bootstage: err=%d\n", ret);
813 return ret;
814 }
815 }
Simon Glassb383d6c2017-05-22 05:05:25 -0600816
Simon Glass1938f4a2013-03-11 06:49:53 +0000817 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
818
819 return 0;
820}
821
Simon Glass9854a872015-11-08 23:47:48 -0700822static int initf_console_record(void)
823{
Andy Yanf1896c42017-07-24 17:43:34 +0800824#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glass9854a872015-11-08 23:47:48 -0700825 return console_record_init();
826#else
827 return 0;
828#endif
829}
830
Simon Glassab7cd622014-07-23 06:55:04 -0600831static int initf_dm(void)
832{
Andy Yanf1896c42017-07-24 17:43:34 +0800833#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassab7cd622014-07-23 06:55:04 -0600834 int ret;
835
Simon Glass63c5bf42017-05-22 05:05:32 -0600836 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
Simon Glassab7cd622014-07-23 06:55:04 -0600837 ret = dm_init_and_scan(true);
Simon Glass63c5bf42017-05-22 05:05:32 -0600838 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
Simon Glassab7cd622014-07-23 06:55:04 -0600839 if (ret)
840 return ret;
841#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700842#ifdef CONFIG_TIMER_EARLY
843 ret = dm_timer_init();
844 if (ret)
845 return ret;
846#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600847
848 return 0;
849}
850
Simon Glass146251f2015-01-19 22:16:12 -0700851/* Architecture-specific memory reservation */
852__weak int reserve_arch(void)
853{
854 return 0;
855}
856
Simon Glassd4c671c2015-03-05 12:25:16 -0700857__weak int arch_cpu_init_dm(void)
858{
859 return 0;
860}
861
Simon Glass4acff452017-01-16 07:03:50 -0700862static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000863 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700864#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700865 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700866#endif
Heinrich Schuchardt7ef8e9b2019-06-02 00:53:24 +0200867#ifdef CONFIG_TRACE_EARLY
Simon Glass71c52db2013-06-11 11:14:42 -0700868 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800869#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700870 initf_malloc,
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700871 log_init,
Simon Glass5ac44a52017-05-22 05:05:31 -0600872 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glassf0293d32018-11-15 18:43:52 -0700873#ifdef CONFIG_BLOBLIST
874 bloblist_init,
875#endif
Simon Glassb0edea32018-11-15 18:44:09 -0700876 setup_spl_handoff,
Simon Glass9854a872015-11-08 23:47:48 -0700877 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600878#if defined(CONFIG_HAVE_FSP)
879 arch_fsp_init,
Bin Menga52a0682015-08-20 06:40:18 -0700880#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000881 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100882 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600883 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700884 arch_cpu_init_dm,
Simon Glass1938f4a2013-03-11 06:49:53 +0000885#if defined(CONFIG_BOARD_EARLY_INIT_F)
886 board_early_init_f,
887#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600888#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600889 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000890 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600891#endif
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200892#if !defined(CONFIG_M68K)
Simon Glass1938f4a2013-03-11 06:49:53 +0000893 timer_init, /* initialize timer */
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200894#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000895#if defined(CONFIG_BOARD_POSTCLK_INIT)
896 board_postclk_init,
897#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000898 env_init, /* initialize environment */
899 init_baud_rate, /* initialze baudrate settings */
900 serial_init, /* serial communications setup */
901 console_init_f, /* stage 1 init of console */
902 display_options, /* say that we are here */
903 display_text_info, /* show debugging info if required */
Angelo Dureghellob9153fe32017-08-20 00:01:55 +0200904#if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000905 checkcpu,
906#endif
Mario Six23471ae2018-08-06 10:23:34 +0200907#if defined(CONFIG_SYSRESET)
908 print_resetinfo,
909#endif
Simon Glasscc664002017-01-23 13:31:25 -0700910#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000911 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700912#endif
Cooper Jr., Franklinaf9e6ad2017-06-16 17:25:12 -0500913#if defined(CONFIG_DTB_RESELECT)
914 embedded_dtb_select,
915#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000916#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900917 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000918#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000919 INIT_FUNC_WATCHDOG_INIT
920#if defined(CONFIG_MISC_INIT_F)
921 misc_init_f,
922#endif
923 INIT_FUNC_WATCHDOG_RESET
Simon Glass69153982017-05-12 21:09:56 -0600924#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000925 init_func_i2c,
926#endif
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530927#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
928 init_func_vid,
929#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000930 announce_dram_init,
Simon Glass1938f4a2013-03-11 06:49:53 +0000931 dram_init, /* configure available RAM banks */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000932#ifdef CONFIG_POST
933 post_init_f,
934#endif
935 INIT_FUNC_WATCHDOG_RESET
936#if defined(CONFIG_SYS_DRAM_TEST)
937 testdram,
938#endif /* CONFIG_SYS_DRAM_TEST */
939 INIT_FUNC_WATCHDOG_RESET
940
Simon Glass1938f4a2013-03-11 06:49:53 +0000941#ifdef CONFIG_POST
942 init_post,
943#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000944 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000945 /*
946 * Now that we have DRAM mapped and working, we can
947 * relocate the code and continue running from DRAM.
948 *
949 * Reserve memory at end of RAM for (top down in that order):
950 * - area that won't get touched by U-Boot and Linux (optional)
951 * - kernel log buffer
952 * - protected RAM
953 * - LCD framebuffer
954 * - monitor code
955 * - board info struct
956 */
957 setup_dest_addr,
Simon Glass1938f4a2013-03-11 06:49:53 +0000958#ifdef CONFIG_PRAM
959 reserve_pram,
960#endif
961 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600962#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000963 reserve_mmu,
964#endif
Simon Glass5a541942016-01-18 19:52:21 -0700965 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700966 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000967 reserve_uboot,
968 reserve_malloc,
969 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000970 setup_machine,
971 reserve_global_data,
972 reserve_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600973 reserve_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700974 reserve_bloblist,
Simon Glass146251f2015-01-19 22:16:12 -0700975 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000976 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600977 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000978 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200979#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
980 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000981 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100982#endif
983#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000984 INIT_FUNC_WATCHDOG_RESET
985 setup_board_part2,
986#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000987 display_new_sp,
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100988#ifdef CONFIG_OF_BOARD_FIXUP
989 fix_fdt,
990#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000991 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000992 reloc_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600993 reloc_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700994 reloc_bloblist,
Simon Glass1938f4a2013-03-11 06:49:53 +0000995 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300996#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700997 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700998 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700999 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -07001000#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001001#if defined(CONFIG_XTENSA)
1002 clear_bss,
1003#endif
Simon Glass530f27e2017-01-16 07:03:49 -07001004#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1005 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +00001006 jump_to_copy,
1007#endif
1008 NULL,
1009};
1010
1011void board_init_f(ulong boot_flags)
1012{
Simon Glass1938f4a2013-03-11 06:49:53 +00001013 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001014 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001015
1016 if (initcall_run_list(init_sequence_f))
1017 hang();
1018
Ben Stoltz9b217492015-07-31 09:31:37 -06001019#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Alexey Brodkin264d2982015-12-16 19:24:10 +03001020 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
1021 !defined(CONFIG_ARC)
Simon Glass1938f4a2013-03-11 06:49:53 +00001022 /* NOTREACHED - jump_to_copy() does not return */
1023 hang();
1024#endif
1025}
1026
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001027#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +00001028/*
1029 * For now this code is only used on x86.
1030 *
1031 * init_sequence_f_r is the list of init functions which are run when
1032 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1033 * The following limitations must be considered when implementing an
1034 * '_f_r' function:
1035 * - 'static' variables are read-only
1036 * - Global Data (gd->xxx) is read/write
1037 *
1038 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1039 * supported). It _should_, if possible, copy global data to RAM and
1040 * initialise the CPU caches (to speed up the relocation process)
1041 *
1042 * NOTE: At present only x86 uses this route, but it is intended that
1043 * all archs will move to this when generic relocation is implemented.
1044 */
Simon Glass4acff452017-01-16 07:03:50 -07001045static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -07001046#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +00001047 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -07001048#endif
Simon Glass48a33802013-03-05 14:39:52 +00001049
1050 NULL,
1051};
1052
1053void board_init_f_r(void)
1054{
1055 if (initcall_run_list(init_sequence_f_r))
1056 hang();
1057
1058 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001059 * The pre-relocation drivers may be using memory that has now gone
1060 * away. Mark serial as unavailable - this will fall back to the debug
1061 * UART if available.
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001062 *
1063 * Do the same with log drivers since the memory may not be available.
Simon Glasse4d6ab02016-03-11 22:06:51 -07001064 */
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001065 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
Simon Glass5ee94b42017-09-05 19:49:45 -06001066#ifdef CONFIG_TIMER
1067 gd->timer = NULL;
1068#endif
Simon Glasse4d6ab02016-03-11 22:06:51 -07001069
1070 /*
Simon Glass48a33802013-03-05 14:39:52 +00001071 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1072 * Transfer execution from Flash to RAM by calculating the address
1073 * of the in-RAM copy of board_init_r() and calling it
1074 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001075 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001076
1077 /* NOTREACHED - board_init_r() does not return */
1078 hang();
1079}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001080#endif /* CONFIG_X86 */