blob: 5c86faeb217bedbceeaec993e0b5d0d0b4d456e5 [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 Glass52f24232020-05-10 11:40:00 -060014#include <bootstage.h>
Simon Glassd96c2602019-12-28 10:44:58 -070015#include <clock_legacy.h>
Simon Glass24b852a2015-11-08 23:47:45 -070016#include <console.h>
Mario Six5d6c61a2018-08-06 10:23:41 +020017#include <cpu.h>
Simon Glass30c7c432019-11-14 12:57:34 -070018#include <cpu_func.h>
Simon Glassab7cd622014-07-23 06:55:04 -060019#include <dm.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060020#include <env.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060021#include <env_internal.h>
Simon Glass5a421902022-03-04 08:43:02 -070022#include <event.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000023#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000024#include <fs.h>
Simon Glassdb41d652019-12-28 10:45:07 -070025#include <hang.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000026#include <i2c.h>
Simon Glass67c4e9f2019-11-14 12:57:45 -070027#include <init.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000028#include <initcall.h>
Simon Glass3c1ecde2019-08-01 09:46:38 -060029#include <lcd.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060030#include <log.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070031#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050032#include <mapmem.h>
Simon Glassa733b062013-04-26 02:53:43 +000033#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000034#include <post.h>
Simon Glasse47b2d62017-03-31 08:40:38 -060035#include <relocate.h>
Simon Glassb03e0512019-11-14 12:57:24 -070036#include <serial.h>
Simon Glassb0edea32018-11-15 18:44:09 -070037#ifdef CONFIG_SPL
38#include <spl.h>
39#endif
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020040#include <status_led.h>
Mario Six23471ae2018-08-06 10:23:34 +020041#include <sysreset.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070042#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070043#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070044#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000045#include <watchdog.h>
Simon Glass90526e92020-05-10 11:39:56 -060046#include <asm/cache.h>
Simon Glassb885d022017-05-17 08:23:01 -060047#ifdef CONFIG_MACH_TYPE
48#include <asm/mach-types.h>
49#endif
Simon Glass1fbf97d2017-03-31 08:40:39 -060050#if defined(CONFIG_MP) && defined(CONFIG_PPC)
51#include <asm/mp.h>
52#endif
Simon Glass401d1c42020-10-30 21:38:53 -060053#include <asm/global_data.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000054#include <asm/io.h>
55#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060056#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060057#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000058
59/*
60 * Pointer to initial global data area
61 *
62 * Here we initialize it if needed.
63 */
64#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
65#undef XTRN_DECLARE_GLOBAL_DATA_PTR
66#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Mario Six16ef1472018-01-15 11:10:02 +010067DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
Simon Glass1938f4a2013-03-11 06:49:53 +000068#else
69DECLARE_GLOBAL_DATA_PTR;
70#endif
71
72/*
Simon Glass4c509342015-04-28 20:25:03 -060073 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000074 * refactored to a single function, something like:
75 *
76 * void led_set_state(enum led_colour_t colour, int on);
77 */
78/************************************************************************
79 * Coloured LED functionality
80 ************************************************************************
81 * May be supplied by boards if desired
82 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020083__weak void coloured_LED_init(void) {}
84__weak void red_led_on(void) {}
85__weak void red_led_off(void) {}
86__weak void green_led_on(void) {}
87__weak void green_led_off(void) {}
88__weak void yellow_led_on(void) {}
89__weak void yellow_led_off(void) {}
90__weak void blue_led_on(void) {}
91__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000092
93/*
94 * Why is gd allocated a register? Prior to reloc it might be better to
95 * just pass it around to each function in this file?
96 *
97 * After reloc one could argue that it is hardly used and doesn't need
98 * to be in a register. Or if it is it should perhaps hold pointers to all
99 * global data for all modules, so that post-reloc we can avoid the massive
100 * literal pool we get on ARM. Or perhaps just encourage each module to use
101 * a structure...
102 */
103
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800104#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000105static int init_func_watchdog_init(void)
106{
Tom Riniea3310e2017-03-14 11:08:10 -0400107# if defined(CONFIG_HW_WATCHDOG) && \
108 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -0700109 defined(CONFIG_SH) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200110 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100111 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800112 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000113 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200114# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000115 WATCHDOG_RESET();
116
117 return 0;
118}
119
120int init_func_watchdog_reset(void)
121{
122 WATCHDOG_RESET();
123
124 return 0;
125}
126#endif /* CONFIG_WATCHDOG */
127
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200128__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000129{
130 /* please define platform specific board_add_ram_info() */
131}
132
Simon Glass1938f4a2013-03-11 06:49:53 +0000133static int init_baud_rate(void)
134{
Simon Glassbfebc8c2017-08-03 12:22:13 -0600135 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glass1938f4a2013-03-11 06:49:53 +0000136 return 0;
137}
138
139static int display_text_info(void)
140{
Ben Stoltz9b217492015-07-31 09:31:37 -0600141#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100142 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000143
Simon Glass632efa72013-03-11 07:06:48 +0000144 bss_start = (ulong)&__bss_start;
145 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100146
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800147#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100148 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800149#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100150 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800151#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100152
153 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
Mario Six16ef1472018-01-15 11:10:02 +0100154 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000155#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000156
Simon Glass1938f4a2013-03-11 06:49:53 +0000157 return 0;
158}
159
Mario Six23471ae2018-08-06 10:23:34 +0200160#ifdef CONFIG_SYSRESET
161static int print_resetinfo(void)
162{
163 struct udevice *dev;
164 char status[256];
165 int ret;
166
167 ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
168 if (ret) {
169 debug("%s: No sysreset device found (error: %d)\n",
170 __func__, ret);
171 /* Not all boards have sysreset drivers available during early
172 * boot, so don't fail if one can't be found.
173 */
174 return 0;
175 }
176
177 if (!sysreset_get_status(dev, status, sizeof(status)))
178 printf("%s", status);
179
180 return 0;
181}
182#endif
183
Mario Six5d6c61a2018-08-06 10:23:41 +0200184#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
185static int print_cpuinfo(void)
186{
187 struct udevice *dev;
188 char desc[512];
189 int ret;
190
Ye Lif5b66af2020-05-03 21:58:50 +0800191 dev = cpu_get_current_dev();
192 if (!dev) {
193 debug("%s: Could not get CPU device\n",
194 __func__);
195 return -ENODEV;
Mario Six5d6c61a2018-08-06 10:23:41 +0200196 }
197
198 ret = cpu_get_desc(dev, desc, sizeof(desc));
199 if (ret) {
200 debug("%s: Could not get CPU description (err = %d)\n",
201 dev->name, ret);
202 return ret;
203 }
204
Bin Mengecfe6632018-10-10 22:06:55 -0700205 printf("CPU: %s\n", desc);
Mario Six5d6c61a2018-08-06 10:23:41 +0200206
207 return 0;
208}
209#endif
210
Simon Glass1938f4a2013-03-11 06:49:53 +0000211static int announce_dram_init(void)
212{
213 puts("DRAM: ");
214 return 0;
215}
216
217static int show_dram_config(void)
218{
York Sunfa39ffe2014-05-02 17:28:05 -0700219 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000220 int i;
221
222 debug("\nRAM Configuration:\n");
223 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
224 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700225 debug("Bank #%d: %llx ", i,
226 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000227#ifdef DEBUG
228 print_size(gd->bd->bi_dram[i].size, "\n");
229#endif
230 }
231 debug("\nDRAM: ");
Simon Glass1938f4a2013-03-11 06:49:53 +0000232
Simon Glasse4fef6c2013-03-11 14:30:42 +0000233 print_size(size, "");
234 board_add_ram_info(0);
235 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000236
237 return 0;
238}
239
Simon Glass76b00ac2017-03-31 08:40:32 -0600240__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000241{
Stefan Roesef120aa72020-08-12 13:02:39 +0200242 gd->bd->bi_dram[0].start = gd->ram_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000243 gd->bd->bi_dram[0].size = get_effective_memsize();
Simon Glass76b00ac2017-03-31 08:40:32 -0600244
245 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000246}
247
Tom Rini55dabcc2021-08-18 23:12:24 -0400248#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000249static int init_func_i2c(void)
250{
251 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200252 i2c_init_all();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000253 puts("ready\n");
254 return 0;
255}
256#endif
257
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530258#if defined(CONFIG_VID)
259__weak int init_func_vid(void)
260{
261 return 0;
262}
263#endif
264
Simon Glass1938f4a2013-03-11 06:49:53 +0000265static int setup_mon_len(void)
266{
Michal Simeke945f6d2014-05-08 16:08:44 +0200267#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100268 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Heinrich Schuchardt3c9fc232021-05-19 12:02:39 +0200269#elif defined(CONFIG_SANDBOX)
270 gd->mon_len = 0;
271#elif defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000272 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400273#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800274 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Tom Rini11232132022-04-06 09:21:25 -0400275#elif defined(CONFIG_SH) || defined(CONFIG_RISCV)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800276 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600277#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000278 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
279 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000280#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000281 return 0;
282}
283
Simon Glassb0edea32018-11-15 18:44:09 -0700284static int setup_spl_handoff(void)
285{
286#if CONFIG_IS_ENABLED(HANDOFF)
Simon Glass7f3b79a2022-01-12 19:26:17 -0700287 gd->spl_handoff = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF,
Simon Glassb0edea32018-11-15 18:44:09 -0700288 sizeof(struct spl_handoff));
289 debug("Found SPL hand-off info %p\n", gd->spl_handoff);
290#endif
291
292 return 0;
293}
294
Simon Glass1938f4a2013-03-11 06:49:53 +0000295__weak int arch_cpu_init(void)
296{
297 return 0;
298}
299
Paul Burton8ebf5062016-09-21 11:18:46 +0100300__weak int mach_cpu_init(void)
301{
302 return 0;
303}
304
Simon Glass1938f4a2013-03-11 06:49:53 +0000305/* Get the top of usable RAM */
306__weak ulong board_get_usable_ram_top(ulong total_size)
307{
Heinrich Schuchardt54280962020-05-09 21:21:14 +0200308#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700309 /*
Simon Glass4c509342015-04-28 20:25:03 -0600310 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700311 * 32-bit address space. If so, clip the usable RAM so it doesn't.
312 */
313 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
314 /*
315 * Will wrap back to top of 32-bit space when reservations
316 * are made.
317 */
318 return 0;
319#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000320 return gd->ram_top;
321}
322
323static int setup_dest_addr(void)
324{
325 debug("Monitor len: %08lX\n", gd->mon_len);
326 /*
327 * Ram is setup, size stored in gd !!
328 */
329 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
Tom Rini24c904f2022-04-06 10:33:32 -0400330#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000331 /*
332 * Subtract specified amount of memory to hide so that it won't
333 * get "touched" at all by U-Boot. By fixing up gd->ram_size
334 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800335 * memory size and won't touch it either. This should work
336 * for arch/ppc and arch/powerpc. Only Linux board ports in
337 * arch/powerpc with bootwrapper support, that recalculate the
338 * memory size from the SDRAM controller setup will have to
339 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000340 */
York Sun36cc0de2017-03-06 09:02:28 -0800341 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
342#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000343#ifdef CONFIG_SYS_SDRAM_BASE
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530344 gd->ram_base = CONFIG_SYS_SDRAM_BASE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000345#endif
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530346 gd->ram_top = gd->ram_base + get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000347 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000348 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000349 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700350#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000351 /*
352 * We need to make sure the location we intend to put secondary core
353 * boot code is reserved and not used by any part of u-boot
354 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000355 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
356 gd->relocaddr = determine_mp_bootpg(NULL);
357 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000358 }
359#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000360 return 0;
361}
362
Simon Glass1938f4a2013-03-11 06:49:53 +0000363#ifdef CONFIG_PRAM
364/* reserve protected RAM */
365static int reserve_pram(void)
366{
367 ulong reg;
368
Simon Glassbfebc8c2017-08-03 12:22:13 -0600369 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000370 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000371 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000372 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000373 return 0;
374}
375#endif /* CONFIG_PRAM */
376
377/* Round memory pointer down to next 4 kB limit */
378static int reserve_round_4k(void)
379{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000380 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000381 return 0;
382}
383
Ovidiu Panait79926e42020-03-29 20:57:41 +0300384__weak int arch_reserve_mmu(void)
385{
386 return 0;
387}
388
Simon Glass5a541942016-01-18 19:52:21 -0700389static int reserve_video(void)
390{
Simon Glass0f079eb2017-03-31 08:40:30 -0600391#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700392 ulong addr;
393 int ret;
394
395 addr = gd->relocaddr;
396 ret = video_reserve(&addr);
397 if (ret)
398 return ret;
Simon Glass5630d2f2020-09-27 18:46:22 -0600399 debug("Reserving %luk for video at: %08lx\n",
Patrick Delaunay83064c22021-04-09 18:02:06 +0200400 ((unsigned long)gd->relocaddr - addr) >> 10, addr);
Simon Glass5a541942016-01-18 19:52:21 -0700401 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600402#elif defined(CONFIG_LCD)
Simon Glass1938f4a2013-03-11 06:49:53 +0000403 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000404 gd->relocaddr = lcd_setmem(gd->relocaddr);
405 gd->fb_base = gd->relocaddr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600406#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700407
408 return 0;
409}
Simon Glass8703ef32016-01-18 19:52:20 -0700410
Simon Glass71c52db2013-06-11 11:14:42 -0700411static int reserve_trace(void)
412{
413#ifdef CONFIG_TRACE
414 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
415 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
Heinrich Schuchardt7ea33572019-06-14 21:52:22 +0200416 debug("Reserving %luk for trace data at: %08lx\n",
417 (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
Simon Glass71c52db2013-06-11 11:14:42 -0700418#endif
419
420 return 0;
421}
422
Simon Glass1938f4a2013-03-11 06:49:53 +0000423static int reserve_uboot(void)
424{
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300425 if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
426 /*
427 * reserve memory for U-Boot code, data & bss
428 * round down to next 4 kB limit
429 */
430 gd->relocaddr -= gd->mon_len;
431 gd->relocaddr &= ~(4096 - 1);
432 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
433 /* round down to next 64 kB limit so that IVPR stays aligned */
434 gd->relocaddr &= ~(65536 - 1);
435 #endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000436
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300437 debug("Reserving %ldk for U-Boot at: %08lx\n",
438 gd->mon_len >> 10, gd->relocaddr);
439 }
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000440
441 gd->start_addr_sp = gd->relocaddr;
442
Simon Glass1938f4a2013-03-11 06:49:53 +0000443 return 0;
444}
445
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100446/*
447 * reserve after start_addr_sp the requested size and make the stack pointer
448 * 16-byte aligned, this alignment is needed for cast on the reserved memory
449 * ref = x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
450 * = ARMv8 Instruction Set Overview: quad word, 16 bytes
451 */
452static unsigned long reserve_stack_aligned(size_t size)
453{
454 return ALIGN_DOWN(gd->start_addr_sp - size, 16);
455}
456
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700457#ifdef CONFIG_SYS_NONCACHED_MEMORY
458static int reserve_noncached(void)
459{
Stephen Warren5e0404f2019-08-27 11:54:31 -0600460 /*
461 * The value of gd->start_addr_sp must match the value of malloc_start
462 * calculated in boatrd_f.c:initr_malloc(), which is passed to
463 * board_r.c:mem_malloc_init() and then used by
464 * cache.c:noncached_init()
465 *
466 * These calculations must match the code in cache.c:noncached_init()
467 */
468 gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
469 MMU_SECTION_SIZE;
470 gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
471 MMU_SECTION_SIZE);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700472 debug("Reserving %dM for noncached_alloc() at: %08lx\n",
473 CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
474
475 return 0;
476}
477#endif
478
Simon Glass1938f4a2013-03-11 06:49:53 +0000479/* reserve memory for malloc() area */
480static int reserve_malloc(void)
481{
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100482 gd->start_addr_sp = reserve_stack_aligned(TOTAL_MALLOC_LEN);
Simon Glass1938f4a2013-03-11 06:49:53 +0000483 debug("Reserving %dk for malloc() at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100484 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700485#ifdef CONFIG_SYS_NONCACHED_MEMORY
486 reserve_noncached();
487#endif
488
Simon Glass1938f4a2013-03-11 06:49:53 +0000489 return 0;
490}
491
492/* (permanently) allocate a Board Info struct */
493static int reserve_board(void)
494{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800495 if (!gd->bd) {
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900496 gd->start_addr_sp = reserve_stack_aligned(sizeof(struct bd_info));
497 gd->bd = (struct bd_info *)map_sysmem(gd->start_addr_sp,
498 sizeof(struct bd_info));
499 memset(gd->bd, '\0', sizeof(struct bd_info));
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800500 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900501 sizeof(struct bd_info), gd->start_addr_sp);
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800502 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000503 return 0;
504}
505
Simon Glass1938f4a2013-03-11 06:49:53 +0000506static int reserve_global_data(void)
507{
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100508 gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t));
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000509 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000510 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100511 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000512 return 0;
513}
514
515static int reserve_fdt(void)
516{
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200517 if (!IS_ENABLED(CONFIG_OF_EMBED)) {
518 /*
519 * If the device tree is sitting immediately above our image
520 * then we must relocate it. If it is embedded in the data
521 * section, then it will be relocated with other data.
522 */
523 if (gd->fdt_blob) {
524 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
Simon Glass1938f4a2013-03-11 06:49:53 +0000525
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200526 gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
527 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
528 debug("Reserving %lu Bytes for FDT at: %08lx\n",
529 gd->fdt_size, gd->start_addr_sp);
530 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000531 }
532
533 return 0;
534}
535
Simon Glass25e7dc62017-05-22 05:05:30 -0600536static int reserve_bootstage(void)
537{
538#ifdef CONFIG_BOOTSTAGE
539 int size = bootstage_get_size();
540
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100541 gd->start_addr_sp = reserve_stack_aligned(size);
Simon Glass25e7dc62017-05-22 05:05:30 -0600542 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
543 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
544 gd->start_addr_sp);
545#endif
546
547 return 0;
548}
549
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100550__weak int arch_reserve_stacks(void)
Andreas Bießmann68145d42015-02-06 23:06:45 +0100551{
552 return 0;
553}
554
Simon Glass1938f4a2013-03-11 06:49:53 +0000555static int reserve_stacks(void)
556{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100557 /* make stack pointer 16-byte aligned */
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100558 gd->start_addr_sp = reserve_stack_aligned(16);
Simon Glass1938f4a2013-03-11 06:49:53 +0000559
560 /*
Simon Glass4c509342015-04-28 20:25:03 -0600561 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100562 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000563 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100564 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000565}
566
Simon Glassf0293d32018-11-15 18:43:52 -0700567static int reserve_bloblist(void)
568{
569#ifdef CONFIG_BLOBLIST
Simon Glass4a08fae2020-09-27 18:46:18 -0600570 /* Align to a 4KB boundary for easier reading of addresses */
Simon Glass9fe06462021-01-13 20:29:43 -0700571 gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp -
572 CONFIG_BLOBLIST_SIZE_RELOC, 0x1000);
573 gd->new_bloblist = map_sysmem(gd->start_addr_sp,
574 CONFIG_BLOBLIST_SIZE_RELOC);
Simon Glassf0293d32018-11-15 18:43:52 -0700575#endif
576
577 return 0;
578}
579
Simon Glass1938f4a2013-03-11 06:49:53 +0000580static int display_new_sp(void)
581{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000582 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000583
584 return 0;
585}
586
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300587__weak int arch_setup_bdinfo(void)
Ovidiu Panaitba743102020-07-24 14:12:14 +0300588{
589 return 0;
590}
591
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300592int setup_bdinfo(void)
593{
Ovidiu Panaita4aa1882020-07-24 14:12:16 +0300594 struct bd_info *bd = gd->bd;
595
Ovidiu Panait49122242020-07-24 14:12:17 +0300596 if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
597 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
598 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
599 }
600
Ovidiu Panait36716682020-11-28 10:43:06 +0200601#ifdef CONFIG_MACH_TYPE
602 bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
603#endif
604
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300605 return arch_setup_bdinfo();
606}
607
Simon Glass1938f4a2013-03-11 06:49:53 +0000608#ifdef CONFIG_POST
609static int init_post(void)
610{
611 post_bootmode_init();
612 post_run(NULL, POST_ROM | post_bootmode_get(0));
613
614 return 0;
615}
616#endif
617
Simon Glass1938f4a2013-03-11 06:49:53 +0000618static int reloc_fdt(void)
619{
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200620 if (!IS_ENABLED(CONFIG_OF_EMBED)) {
621 if (gd->flags & GD_FLG_SKIP_RELOC)
622 return 0;
623 if (gd->new_fdt) {
624 memcpy(gd->new_fdt, gd->fdt_blob,
625 fdt_totalsize(gd->fdt_blob));
626 gd->fdt_blob = gd->new_fdt;
627 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000628 }
629
630 return 0;
631}
632
Simon Glass25e7dc62017-05-22 05:05:30 -0600633static int reloc_bootstage(void)
634{
635#ifdef CONFIG_BOOTSTAGE
636 if (gd->flags & GD_FLG_SKIP_RELOC)
637 return 0;
638 if (gd->new_bootstage) {
639 int size = bootstage_get_size();
640
641 debug("Copying bootstage from %p to %p, size %x\n",
642 gd->bootstage, gd->new_bootstage, size);
643 memcpy(gd->new_bootstage, gd->bootstage, size);
644 gd->bootstage = gd->new_bootstage;
Simon Glassac9cd482019-10-21 17:26:50 -0600645 bootstage_relocate();
Simon Glass25e7dc62017-05-22 05:05:30 -0600646 }
647#endif
648
649 return 0;
650}
651
Simon Glassf0293d32018-11-15 18:43:52 -0700652static int reloc_bloblist(void)
653{
654#ifdef CONFIG_BLOBLIST
Simon Glassd5b6e912021-11-03 21:09:20 -0600655 /*
656 * Relocate only if we are supposed to send it
657 */
658 if ((gd->flags & GD_FLG_SKIP_RELOC) &&
659 CONFIG_BLOBLIST_SIZE == CONFIG_BLOBLIST_SIZE_RELOC) {
660 debug("Not relocating bloblist\n");
Simon Glassf0293d32018-11-15 18:43:52 -0700661 return 0;
Simon Glassd5b6e912021-11-03 21:09:20 -0600662 }
Simon Glassf0293d32018-11-15 18:43:52 -0700663 if (gd->new_bloblist) {
664 int size = CONFIG_BLOBLIST_SIZE;
665
666 debug("Copying bloblist from %p to %p, size %x\n",
667 gd->bloblist, gd->new_bloblist, size);
Simon Glass9fe06462021-01-13 20:29:43 -0700668 bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
669 gd->bloblist, size);
Simon Glassf0293d32018-11-15 18:43:52 -0700670 gd->bloblist = gd->new_bloblist;
671 }
672#endif
673
674 return 0;
675}
676
Simon Glass1938f4a2013-03-11 06:49:53 +0000677static int setup_reloc(void)
678{
Marek Vasut47d7d032021-11-13 18:34:04 +0100679 if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800680#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200681#ifdef ARM
Marek Vasut47d7d032021-11-13 18:34:04 +0100682 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
Michal Simekd58c0072022-06-24 14:15:01 +0200683#elif defined(CONFIG_MICROBLAZE)
684 gd->reloc_off = gd->relocaddr - (u32)_start;
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200685#elif defined(CONFIG_M68K)
Marek Vasut47d7d032021-11-13 18:34:04 +0100686 /*
687 * On all ColdFire arch cpu, monitor code starts always
688 * just after the default vector table location, so at 0x400
689 */
690 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Simon Glass001d1882019-04-08 13:20:41 -0600691#elif !defined(CONFIG_SANDBOX)
Marek Vasut47d7d032021-11-13 18:34:04 +0100692 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100693#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800694#endif
Marek Vasut47d7d032021-11-13 18:34:04 +0100695 }
696
Simon Glass1938f4a2013-03-11 06:49:53 +0000697 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
698
Marek Vasut47d7d032021-11-13 18:34:04 +0100699 if (gd->flags & GD_FLG_SKIP_RELOC) {
700 debug("Skipping relocation due to flag\n");
701 } else {
702 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
703 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
704 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
705 gd->start_addr_sp);
706 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000707
708 return 0;
709}
710
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100711#ifdef CONFIG_OF_BOARD_FIXUP
712static int fix_fdt(void)
713{
714 return board_fix_fdt((void *)gd->fdt_blob);
715}
716#endif
717
Simon Glass1938f4a2013-03-11 06:49:53 +0000718/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700719#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
720 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000721
722static int jump_to_copy(void)
723{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600724 if (gd->flags & GD_FLG_SKIP_RELOC)
725 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000726 /*
727 * x86 is special, but in a nice way. It uses a trampoline which
728 * enables the dcache if possible.
729 *
730 * For now, other archs use relocate_code(), which is implemented
731 * similarly for all archs. When we do generic relocation, hopefully
732 * we can make all archs enable the dcache prior to relocation.
733 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300734#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000735 /*
736 * SDRAM and console are now initialised. The final stack can now
737 * be setup in SDRAM. Code execution will continue in Flash, but
738 * with the stack in SDRAM and Global Data in temporary memory
739 * (CPU cache)
740 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600741 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000742 board_init_f_r_trampoline(gd->start_addr_sp);
743#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000744 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000745#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000746
747 return 0;
748}
749#endif
750
751/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glassb383d6c2017-05-22 05:05:25 -0600752static int initf_bootstage(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000753{
Simon Glassbaa7d342017-06-07 10:28:46 -0600754 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
755 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glassb383d6c2017-05-22 05:05:25 -0600756 int ret;
757
Simon Glass824bb1b2017-05-22 05:05:35 -0600758 ret = bootstage_init(!from_spl);
Simon Glassb383d6c2017-05-22 05:05:25 -0600759 if (ret)
760 return ret;
Simon Glass824bb1b2017-05-22 05:05:35 -0600761 if (from_spl) {
762 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
763 CONFIG_BOOTSTAGE_STASH_SIZE);
764
765 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
766 if (ret && ret != -ENOENT) {
767 debug("Failed to unstash bootstage: err=%d\n", ret);
768 return ret;
769 }
770 }
Simon Glassb383d6c2017-05-22 05:05:25 -0600771
Simon Glass1938f4a2013-03-11 06:49:53 +0000772 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
773
774 return 0;
775}
776
Simon Glassab7cd622014-07-23 06:55:04 -0600777static int initf_dm(void)
778{
Andy Yanf1896c42017-07-24 17:43:34 +0800779#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassab7cd622014-07-23 06:55:04 -0600780 int ret;
781
Simon Glassb67eefd2020-05-10 11:39:59 -0600782 bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
Simon Glassab7cd622014-07-23 06:55:04 -0600783 ret = dm_init_and_scan(true);
Simon Glassb67eefd2020-05-10 11:39:59 -0600784 bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
Simon Glassab7cd622014-07-23 06:55:04 -0600785 if (ret)
786 return ret;
Ovidiu Panait4b9a1212020-11-28 10:43:05 +0200787
788 if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
789 ret = dm_timer_init();
790 if (ret)
791 return ret;
792 }
Simon Glass1057e6c2016-02-24 09:14:50 -0700793#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600794
795 return 0;
796}
797
Simon Glass146251f2015-01-19 22:16:12 -0700798/* Architecture-specific memory reservation */
799__weak int reserve_arch(void)
800{
801 return 0;
802}
803
Ovidiu Panait016e4ae2020-01-22 22:28:25 +0200804__weak int checkcpu(void)
805{
806 return 0;
807}
808
Ovidiu Panaitfbf9c152020-02-05 08:54:42 +0200809__weak int clear_bss(void)
810{
811 return 0;
812}
813
Simon Glass42fdceb2022-03-04 08:43:04 -0700814static int misc_init_f(void)
815{
816 return event_notify_null(EVT_MISC_INIT_F);
817}
818
Simon Glass4acff452017-01-16 07:03:50 -0700819static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000820 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700821#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700822 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700823#endif
Heinrich Schuchardt7ef8e9b2019-06-02 00:53:24 +0200824#ifdef CONFIG_TRACE_EARLY
Simon Glass71c52db2013-06-11 11:14:42 -0700825 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800826#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700827 initf_malloc,
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700828 log_init,
Simon Glass5ac44a52017-05-22 05:05:31 -0600829 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glass5a421902022-03-04 08:43:02 -0700830 event_init,
Simon Glassf0293d32018-11-15 18:43:52 -0700831#ifdef CONFIG_BLOBLIST
832 bloblist_init,
833#endif
Simon Glassb0edea32018-11-15 18:44:09 -0700834 setup_spl_handoff,
Ovidiu Panait8e8d45e2020-11-28 10:43:04 +0200835#if defined(CONFIG_CONSOLE_RECORD_INIT_F)
836 console_record_init,
837#endif
Simon Glass671549e2017-03-28 10:27:18 -0600838#if defined(CONFIG_HAVE_FSP)
839 arch_fsp_init,
Bin Menga52a068e2015-08-20 06:40:18 -0700840#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000841 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100842 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600843 initf_dm,
Simon Glass1938f4a2013-03-11 06:49:53 +0000844#if defined(CONFIG_BOARD_EARLY_INIT_F)
845 board_early_init_f,
846#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600847#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600848 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000849 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600850#endif
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200851#if !defined(CONFIG_M68K)
Simon Glass1938f4a2013-03-11 06:49:53 +0000852 timer_init, /* initialize timer */
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200853#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000854#if defined(CONFIG_BOARD_POSTCLK_INIT)
855 board_postclk_init,
856#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000857 env_init, /* initialize environment */
858 init_baud_rate, /* initialze baudrate settings */
859 serial_init, /* serial communications setup */
860 console_init_f, /* stage 1 init of console */
861 display_options, /* say that we are here */
862 display_text_info, /* show debugging info if required */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000863 checkcpu,
Mario Six23471ae2018-08-06 10:23:34 +0200864#if defined(CONFIG_SYSRESET)
865 print_resetinfo,
866#endif
Simon Glasscc664002017-01-23 13:31:25 -0700867#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000868 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700869#endif
Cooper Jr., Franklinaf9e6ad2017-06-16 17:25:12 -0500870#if defined(CONFIG_DTB_RESELECT)
871 embedded_dtb_select,
872#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000873#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900874 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000875#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000876 INIT_FUNC_WATCHDOG_INIT
Simon Glasse4fef6c2013-03-11 14:30:42 +0000877 misc_init_f,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000878 INIT_FUNC_WATCHDOG_RESET
Tom Rini55dabcc2021-08-18 23:12:24 -0400879#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000880 init_func_i2c,
881#endif
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530882#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
883 init_func_vid,
884#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000885 announce_dram_init,
Simon Glass1938f4a2013-03-11 06:49:53 +0000886 dram_init, /* configure available RAM banks */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000887#ifdef CONFIG_POST
888 post_init_f,
889#endif
890 INIT_FUNC_WATCHDOG_RESET
891#if defined(CONFIG_SYS_DRAM_TEST)
892 testdram,
893#endif /* CONFIG_SYS_DRAM_TEST */
894 INIT_FUNC_WATCHDOG_RESET
895
Simon Glass1938f4a2013-03-11 06:49:53 +0000896#ifdef CONFIG_POST
897 init_post,
898#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000899 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000900 /*
901 * Now that we have DRAM mapped and working, we can
902 * relocate the code and continue running from DRAM.
903 *
904 * Reserve memory at end of RAM for (top down in that order):
905 * - area that won't get touched by U-Boot and Linux (optional)
906 * - kernel log buffer
907 * - protected RAM
908 * - LCD framebuffer
909 * - monitor code
910 * - board info struct
911 */
912 setup_dest_addr,
Pragnesh Patel313981c2020-08-13 10:12:26 +0530913#ifdef CONFIG_OF_BOARD_FIXUP
914 fix_fdt,
915#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000916#ifdef CONFIG_PRAM
917 reserve_pram,
918#endif
919 reserve_round_4k,
Ovidiu Panait79926e42020-03-29 20:57:41 +0300920 arch_reserve_mmu,
Simon Glass5a541942016-01-18 19:52:21 -0700921 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700922 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000923 reserve_uboot,
924 reserve_malloc,
925 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000926 reserve_global_data,
927 reserve_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600928 reserve_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700929 reserve_bloblist,
Simon Glass146251f2015-01-19 22:16:12 -0700930 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000931 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600932 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000933 show_dram_config,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000934 INIT_FUNC_WATCHDOG_RESET
Ovidiu Panait15328852020-07-24 14:12:20 +0300935 setup_bdinfo,
Simon Glass1938f4a2013-03-11 06:49:53 +0000936 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000937 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000938 reloc_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600939 reloc_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700940 reloc_bloblist,
Simon Glass1938f4a2013-03-11 06:49:53 +0000941 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300942#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700943 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700944 do_elf_reloc_fixups,
945#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300946 clear_bss,
Simon Glass530f27e2017-01-16 07:03:49 -0700947#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
948 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000949 jump_to_copy,
950#endif
951 NULL,
952};
953
954void board_init_f(ulong boot_flags)
955{
Simon Glass1938f4a2013-03-11 06:49:53 +0000956 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400957 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000958
959 if (initcall_run_list(init_sequence_f))
960 hang();
961
Ben Stoltz9b217492015-07-31 09:31:37 -0600962#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Alexey Brodkin264d2982015-12-16 19:24:10 +0300963 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
964 !defined(CONFIG_ARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000965 /* NOTREACHED - jump_to_copy() does not return */
966 hang();
967#endif
968}
969
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300970#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000971/*
972 * For now this code is only used on x86.
973 *
974 * init_sequence_f_r is the list of init functions which are run when
975 * U-Boot is executing from Flash with a semi-limited 'C' environment.
976 * The following limitations must be considered when implementing an
977 * '_f_r' function:
978 * - 'static' variables are read-only
979 * - Global Data (gd->xxx) is read/write
980 *
981 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
982 * supported). It _should_, if possible, copy global data to RAM and
983 * initialise the CPU caches (to speed up the relocation process)
984 *
985 * NOTE: At present only x86 uses this route, but it is intended that
986 * all archs will move to this when generic relocation is implemented.
987 */
Simon Glass4acff452017-01-16 07:03:50 -0700988static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700989#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000990 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700991#endif
Simon Glass48a33802013-03-05 14:39:52 +0000992
993 NULL,
994};
995
996void board_init_f_r(void)
997{
998 if (initcall_run_list(init_sequence_f_r))
999 hang();
1000
1001 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001002 * The pre-relocation drivers may be using memory that has now gone
1003 * away. Mark serial as unavailable - this will fall back to the debug
1004 * UART if available.
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001005 *
1006 * Do the same with log drivers since the memory may not be available.
Simon Glasse4d6ab02016-03-11 22:06:51 -07001007 */
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001008 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
Simon Glass5ee94b42017-09-05 19:49:45 -06001009#ifdef CONFIG_TIMER
1010 gd->timer = NULL;
1011#endif
Simon Glasse4d6ab02016-03-11 22:06:51 -07001012
1013 /*
Simon Glass48a33802013-03-05 14:39:52 +00001014 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1015 * Transfer execution from Flash to RAM by calculating the address
1016 * of the in-RAM copy of board_init_r() and calling it
1017 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001018 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001019
1020 /* NOTREACHED - board_init_r() does not return */
1021 hang();
1022}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001023#endif /* CONFIG_X86 */