blob: 3dc0eaa59c53eef55dd5be5aa8ba2957176bc3f2 [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 Glass1938f4a2013-03-11 06:49:53 +000022#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000023#include <fs.h>
Simon Glassdb41d652019-12-28 10:45:07 -070024#include <hang.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000025#include <i2c.h>
Simon Glass67c4e9f2019-11-14 12:57:45 -070026#include <init.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000027#include <initcall.h>
Simon Glass3c1ecde2019-08-01 09:46:38 -060028#include <lcd.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060029#include <log.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070030#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050031#include <mapmem.h>
Simon Glassa733b062013-04-26 02:53:43 +000032#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000033#include <post.h>
Simon Glasse47b2d62017-03-31 08:40:38 -060034#include <relocate.h>
Simon Glassb03e0512019-11-14 12:57:24 -070035#include <serial.h>
Simon Glassb0edea32018-11-15 18:44:09 -070036#ifdef CONFIG_SPL
37#include <spl.h>
38#endif
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020039#include <status_led.h>
Mario Six23471ae2018-08-06 10:23:34 +020040#include <sysreset.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070041#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070042#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070043#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000044#include <watchdog.h>
Simon Glass90526e92020-05-10 11:39:56 -060045#include <asm/cache.h>
Simon Glassb885d022017-05-17 08:23:01 -060046#ifdef CONFIG_MACH_TYPE
47#include <asm/mach-types.h>
48#endif
Simon Glass1fbf97d2017-03-31 08:40:39 -060049#if defined(CONFIG_MP) && defined(CONFIG_PPC)
50#include <asm/mp.h>
51#endif
Simon Glass401d1c42020-10-30 21:38:53 -060052#include <asm/global_data.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000053#include <asm/io.h>
54#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060055#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060056#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000057
58/*
59 * Pointer to initial global data area
60 *
61 * Here we initialize it if needed.
62 */
63#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
64#undef XTRN_DECLARE_GLOBAL_DATA_PTR
65#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Mario Six16ef1472018-01-15 11:10:02 +010066DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
Simon Glass1938f4a2013-03-11 06:49:53 +000067#else
68DECLARE_GLOBAL_DATA_PTR;
69#endif
70
71/*
Simon Glass4c509342015-04-28 20:25:03 -060072 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000073 * refactored to a single function, something like:
74 *
75 * void led_set_state(enum led_colour_t colour, int on);
76 */
77/************************************************************************
78 * Coloured LED functionality
79 ************************************************************************
80 * May be supplied by boards if desired
81 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020082__weak void coloured_LED_init(void) {}
83__weak void red_led_on(void) {}
84__weak void red_led_off(void) {}
85__weak void green_led_on(void) {}
86__weak void green_led_off(void) {}
87__weak void yellow_led_on(void) {}
88__weak void yellow_led_off(void) {}
89__weak void blue_led_on(void) {}
90__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000091
92/*
93 * Why is gd allocated a register? Prior to reloc it might be better to
94 * just pass it around to each function in this file?
95 *
96 * After reloc one could argue that it is hardly used and doesn't need
97 * to be in a register. Or if it is it should perhaps hold pointers to all
98 * global data for all modules, so that post-reloc we can avoid the massive
99 * literal pool we get on ARM. Or perhaps just encourage each module to use
100 * a structure...
101 */
102
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800103#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000104static int init_func_watchdog_init(void)
105{
Tom Riniea3310e2017-03-14 11:08:10 -0400106# if defined(CONFIG_HW_WATCHDOG) && \
107 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -0700108 defined(CONFIG_SH) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200109 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100110 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800111 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000112 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200113# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000114 WATCHDOG_RESET();
115
116 return 0;
117}
118
119int init_func_watchdog_reset(void)
120{
121 WATCHDOG_RESET();
122
123 return 0;
124}
125#endif /* CONFIG_WATCHDOG */
126
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200127__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000128{
129 /* please define platform specific board_add_ram_info() */
130}
131
Simon Glass1938f4a2013-03-11 06:49:53 +0000132static int init_baud_rate(void)
133{
Simon Glassbfebc8c2017-08-03 12:22:13 -0600134 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glass1938f4a2013-03-11 06:49:53 +0000135 return 0;
136}
137
138static int display_text_info(void)
139{
Ben Stoltz9b217492015-07-31 09:31:37 -0600140#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100141 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000142
Simon Glass632efa72013-03-11 07:06:48 +0000143 bss_start = (ulong)&__bss_start;
144 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100145
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800146#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100147 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800148#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100149 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800150#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100151
152 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
Mario Six16ef1472018-01-15 11:10:02 +0100153 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000154#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000155
Simon Glass1938f4a2013-03-11 06:49:53 +0000156 return 0;
157}
158
Mario Six23471ae2018-08-06 10:23:34 +0200159#ifdef CONFIG_SYSRESET
160static int print_resetinfo(void)
161{
162 struct udevice *dev;
163 char status[256];
164 int ret;
165
166 ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
167 if (ret) {
168 debug("%s: No sysreset device found (error: %d)\n",
169 __func__, ret);
170 /* Not all boards have sysreset drivers available during early
171 * boot, so don't fail if one can't be found.
172 */
173 return 0;
174 }
175
176 if (!sysreset_get_status(dev, status, sizeof(status)))
177 printf("%s", status);
178
179 return 0;
180}
181#endif
182
Mario Six5d6c61a2018-08-06 10:23:41 +0200183#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
184static int print_cpuinfo(void)
185{
186 struct udevice *dev;
187 char desc[512];
188 int ret;
189
Ye Lif5b66af2020-05-03 21:58:50 +0800190 dev = cpu_get_current_dev();
191 if (!dev) {
192 debug("%s: Could not get CPU device\n",
193 __func__);
194 return -ENODEV;
Mario Six5d6c61a2018-08-06 10:23:41 +0200195 }
196
197 ret = cpu_get_desc(dev, desc, sizeof(desc));
198 if (ret) {
199 debug("%s: Could not get CPU description (err = %d)\n",
200 dev->name, ret);
201 return ret;
202 }
203
Bin Mengecfe6632018-10-10 22:06:55 -0700204 printf("CPU: %s\n", desc);
Mario Six5d6c61a2018-08-06 10:23:41 +0200205
206 return 0;
207}
208#endif
209
Simon Glass1938f4a2013-03-11 06:49:53 +0000210static int announce_dram_init(void)
211{
212 puts("DRAM: ");
213 return 0;
214}
215
216static int show_dram_config(void)
217{
York Sunfa39ffe2014-05-02 17:28:05 -0700218 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000219 int i;
220
221 debug("\nRAM Configuration:\n");
222 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
223 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700224 debug("Bank #%d: %llx ", i,
225 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000226#ifdef DEBUG
227 print_size(gd->bd->bi_dram[i].size, "\n");
228#endif
229 }
230 debug("\nDRAM: ");
Simon Glass1938f4a2013-03-11 06:49:53 +0000231
Simon Glasse4fef6c2013-03-11 14:30:42 +0000232 print_size(size, "");
233 board_add_ram_info(0);
234 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000235
236 return 0;
237}
238
Simon Glass76b00ac2017-03-31 08:40:32 -0600239__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000240{
Stefan Roesef120aa72020-08-12 13:02:39 +0200241 gd->bd->bi_dram[0].start = gd->ram_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000242 gd->bd->bi_dram[0].size = get_effective_memsize();
Simon Glass76b00ac2017-03-31 08:40:32 -0600243
244 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000245}
246
Tom Rini55dabcc2021-08-18 23:12:24 -0400247#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000248static int init_func_i2c(void)
249{
250 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200251 i2c_init_all();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000252 puts("ready\n");
253 return 0;
254}
255#endif
256
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530257#if defined(CONFIG_VID)
258__weak int init_func_vid(void)
259{
260 return 0;
261}
262#endif
263
Simon Glass1938f4a2013-03-11 06:49:53 +0000264static int setup_mon_len(void)
265{
Michal Simeke945f6d2014-05-08 16:08:44 +0200266#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100267 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Heinrich Schuchardt3c9fc232021-05-19 12:02:39 +0200268#elif defined(CONFIG_SANDBOX)
269 gd->mon_len = 0;
270#elif defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000271 gd->mon_len = (ulong)&_end - (ulong)_init;
Tom Riniea3310e2017-03-14 11:08:10 -0400272#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800273 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Rick Chen068feb92017-12-26 13:55:58 +0800274#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800275 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600276#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000277 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
278 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000279#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000280 return 0;
281}
282
Simon Glassb0edea32018-11-15 18:44:09 -0700283static int setup_spl_handoff(void)
284{
285#if CONFIG_IS_ENABLED(HANDOFF)
286 gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
287 sizeof(struct spl_handoff));
288 debug("Found SPL hand-off info %p\n", gd->spl_handoff);
289#endif
290
291 return 0;
292}
293
Simon Glass1938f4a2013-03-11 06:49:53 +0000294__weak int arch_cpu_init(void)
295{
296 return 0;
297}
298
Paul Burton8ebf5062016-09-21 11:18:46 +0100299__weak int mach_cpu_init(void)
300{
301 return 0;
302}
303
Simon Glass1938f4a2013-03-11 06:49:53 +0000304/* Get the top of usable RAM */
305__weak ulong board_get_usable_ram_top(ulong total_size)
306{
Heinrich Schuchardt54280962020-05-09 21:21:14 +0200307#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700308 /*
Simon Glass4c509342015-04-28 20:25:03 -0600309 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700310 * 32-bit address space. If so, clip the usable RAM so it doesn't.
311 */
312 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
313 /*
314 * Will wrap back to top of 32-bit space when reservations
315 * are made.
316 */
317 return 0;
318#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000319 return gd->ram_top;
320}
321
322static int setup_dest_addr(void)
323{
324 debug("Monitor len: %08lX\n", gd->mon_len);
325 /*
326 * Ram is setup, size stored in gd !!
327 */
328 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sun36cc0de2017-03-06 09:02:28 -0800329#if defined(CONFIG_SYS_MEM_TOP_HIDE)
Simon Glass1938f4a2013-03-11 06:49:53 +0000330 /*
331 * Subtract specified amount of memory to hide so that it won't
332 * get "touched" at all by U-Boot. By fixing up gd->ram_size
333 * the Linux kernel should now get passed the now "corrected"
York Sun36cc0de2017-03-06 09:02:28 -0800334 * memory size and won't touch it either. This should work
335 * for arch/ppc and arch/powerpc. Only Linux board ports in
336 * arch/powerpc with bootwrapper support, that recalculate the
337 * memory size from the SDRAM controller setup will have to
338 * get fixed.
Simon Glass1938f4a2013-03-11 06:49:53 +0000339 */
York Sun36cc0de2017-03-06 09:02:28 -0800340 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
341#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000342#ifdef CONFIG_SYS_SDRAM_BASE
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530343 gd->ram_base = CONFIG_SYS_SDRAM_BASE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000344#endif
Siva Durga Prasad Paladugu1473b122018-07-16 15:56:10 +0530345 gd->ram_top = gd->ram_base + get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000346 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000347 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000348 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700349#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000350 /*
351 * We need to make sure the location we intend to put secondary core
352 * boot code is reserved and not used by any part of u-boot
353 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000354 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
355 gd->relocaddr = determine_mp_bootpg(NULL);
356 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000357 }
358#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000359 return 0;
360}
361
Simon Glass1938f4a2013-03-11 06:49:53 +0000362#ifdef CONFIG_PRAM
363/* reserve protected RAM */
364static int reserve_pram(void)
365{
366 ulong reg;
367
Simon Glassbfebc8c2017-08-03 12:22:13 -0600368 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000369 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000370 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000371 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000372 return 0;
373}
374#endif /* CONFIG_PRAM */
375
376/* Round memory pointer down to next 4 kB limit */
377static int reserve_round_4k(void)
378{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000379 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000380 return 0;
381}
382
Ovidiu Panait79926e42020-03-29 20:57:41 +0300383__weak int arch_reserve_mmu(void)
384{
385 return 0;
386}
387
Simon Glass5a541942016-01-18 19:52:21 -0700388static int reserve_video(void)
389{
Simon Glass0f079eb2017-03-31 08:40:30 -0600390#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700391 ulong addr;
392 int ret;
393
394 addr = gd->relocaddr;
395 ret = video_reserve(&addr);
396 if (ret)
397 return ret;
Simon Glass5630d2f2020-09-27 18:46:22 -0600398 debug("Reserving %luk for video at: %08lx\n",
Patrick Delaunay83064c22021-04-09 18:02:06 +0200399 ((unsigned long)gd->relocaddr - addr) >> 10, addr);
Simon Glass5a541942016-01-18 19:52:21 -0700400 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600401#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700402# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000403 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700404# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000405 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000406 gd->relocaddr = lcd_setmem(gd->relocaddr);
407 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700408# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600409#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700410
411 return 0;
412}
Simon Glass8703ef32016-01-18 19:52:20 -0700413
Simon Glass71c52db2013-06-11 11:14:42 -0700414static int reserve_trace(void)
415{
416#ifdef CONFIG_TRACE
417 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
418 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
Heinrich Schuchardt7ea33572019-06-14 21:52:22 +0200419 debug("Reserving %luk for trace data at: %08lx\n",
420 (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
Simon Glass71c52db2013-06-11 11:14:42 -0700421#endif
422
423 return 0;
424}
425
Simon Glass1938f4a2013-03-11 06:49:53 +0000426static int reserve_uboot(void)
427{
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300428 if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
429 /*
430 * reserve memory for U-Boot code, data & bss
431 * round down to next 4 kB limit
432 */
433 gd->relocaddr -= gd->mon_len;
434 gd->relocaddr &= ~(4096 - 1);
435 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
436 /* round down to next 64 kB limit so that IVPR stays aligned */
437 gd->relocaddr &= ~(65536 - 1);
438 #endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000439
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300440 debug("Reserving %ldk for U-Boot at: %08lx\n",
441 gd->mon_len >> 10, gd->relocaddr);
442 }
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000443
444 gd->start_addr_sp = gd->relocaddr;
445
Simon Glass1938f4a2013-03-11 06:49:53 +0000446 return 0;
447}
448
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100449/*
450 * reserve after start_addr_sp the requested size and make the stack pointer
451 * 16-byte aligned, this alignment is needed for cast on the reserved memory
452 * ref = x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
453 * = ARMv8 Instruction Set Overview: quad word, 16 bytes
454 */
455static unsigned long reserve_stack_aligned(size_t size)
456{
457 return ALIGN_DOWN(gd->start_addr_sp - size, 16);
458}
459
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700460#ifdef CONFIG_SYS_NONCACHED_MEMORY
461static int reserve_noncached(void)
462{
Stephen Warren5e0404f2019-08-27 11:54:31 -0600463 /*
464 * The value of gd->start_addr_sp must match the value of malloc_start
465 * calculated in boatrd_f.c:initr_malloc(), which is passed to
466 * board_r.c:mem_malloc_init() and then used by
467 * cache.c:noncached_init()
468 *
469 * These calculations must match the code in cache.c:noncached_init()
470 */
471 gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
472 MMU_SECTION_SIZE;
473 gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
474 MMU_SECTION_SIZE);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700475 debug("Reserving %dM for noncached_alloc() at: %08lx\n",
476 CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
477
478 return 0;
479}
480#endif
481
Simon Glass1938f4a2013-03-11 06:49:53 +0000482/* reserve memory for malloc() area */
483static int reserve_malloc(void)
484{
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100485 gd->start_addr_sp = reserve_stack_aligned(TOTAL_MALLOC_LEN);
Simon Glass1938f4a2013-03-11 06:49:53 +0000486 debug("Reserving %dk for malloc() at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100487 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700488#ifdef CONFIG_SYS_NONCACHED_MEMORY
489 reserve_noncached();
490#endif
491
Simon Glass1938f4a2013-03-11 06:49:53 +0000492 return 0;
493}
494
495/* (permanently) allocate a Board Info struct */
496static int reserve_board(void)
497{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800498 if (!gd->bd) {
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900499 gd->start_addr_sp = reserve_stack_aligned(sizeof(struct bd_info));
500 gd->bd = (struct bd_info *)map_sysmem(gd->start_addr_sp,
501 sizeof(struct bd_info));
502 memset(gd->bd, '\0', sizeof(struct bd_info));
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800503 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900504 sizeof(struct bd_info), gd->start_addr_sp);
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800505 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000506 return 0;
507}
508
Simon Glass1938f4a2013-03-11 06:49:53 +0000509static int reserve_global_data(void)
510{
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100511 gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t));
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000512 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000513 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100514 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000515 return 0;
516}
517
518static int reserve_fdt(void)
519{
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200520 if (!IS_ENABLED(CONFIG_OF_EMBED)) {
521 /*
522 * If the device tree is sitting immediately above our image
523 * then we must relocate it. If it is embedded in the data
524 * section, then it will be relocated with other data.
525 */
526 if (gd->fdt_blob) {
527 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
Simon Glass1938f4a2013-03-11 06:49:53 +0000528
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200529 gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
530 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
531 debug("Reserving %lu Bytes for FDT at: %08lx\n",
532 gd->fdt_size, gd->start_addr_sp);
533 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000534 }
535
536 return 0;
537}
538
Simon Glass25e7dc62017-05-22 05:05:30 -0600539static int reserve_bootstage(void)
540{
541#ifdef CONFIG_BOOTSTAGE
542 int size = bootstage_get_size();
543
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100544 gd->start_addr_sp = reserve_stack_aligned(size);
Simon Glass25e7dc62017-05-22 05:05:30 -0600545 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
546 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
547 gd->start_addr_sp);
548#endif
549
550 return 0;
551}
552
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100553__weak int arch_reserve_stacks(void)
Andreas Bießmann68145d42015-02-06 23:06:45 +0100554{
555 return 0;
556}
557
Simon Glass1938f4a2013-03-11 06:49:53 +0000558static int reserve_stacks(void)
559{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100560 /* make stack pointer 16-byte aligned */
Patrick Delaunay65c141e2020-03-10 10:15:05 +0100561 gd->start_addr_sp = reserve_stack_aligned(16);
Simon Glass1938f4a2013-03-11 06:49:53 +0000562
563 /*
Simon Glass4c509342015-04-28 20:25:03 -0600564 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100565 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000566 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100567 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000568}
569
Simon Glassf0293d32018-11-15 18:43:52 -0700570static int reserve_bloblist(void)
571{
572#ifdef CONFIG_BLOBLIST
Simon Glass4a08fae2020-09-27 18:46:18 -0600573 /* Align to a 4KB boundary for easier reading of addresses */
Simon Glass9fe06462021-01-13 20:29:43 -0700574 gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp -
575 CONFIG_BLOBLIST_SIZE_RELOC, 0x1000);
576 gd->new_bloblist = map_sysmem(gd->start_addr_sp,
577 CONFIG_BLOBLIST_SIZE_RELOC);
Simon Glassf0293d32018-11-15 18:43:52 -0700578#endif
579
580 return 0;
581}
582
Simon Glass1938f4a2013-03-11 06:49:53 +0000583static int display_new_sp(void)
584{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000585 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000586
587 return 0;
588}
589
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300590__weak int arch_setup_bdinfo(void)
Ovidiu Panaitba743102020-07-24 14:12:14 +0300591{
592 return 0;
593}
594
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300595int setup_bdinfo(void)
596{
Ovidiu Panaita4aa1882020-07-24 14:12:16 +0300597 struct bd_info *bd = gd->bd;
598
Ovidiu Panait49122242020-07-24 14:12:17 +0300599 if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
600 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
601 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
602 }
603
Ovidiu Panait36716682020-11-28 10:43:06 +0200604#ifdef CONFIG_MACH_TYPE
605 bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
606#endif
607
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300608 return arch_setup_bdinfo();
609}
610
Simon Glass1938f4a2013-03-11 06:49:53 +0000611#ifdef CONFIG_POST
612static int init_post(void)
613{
614 post_bootmode_init();
615 post_run(NULL, POST_ROM | post_bootmode_get(0));
616
617 return 0;
618}
619#endif
620
Simon Glass1938f4a2013-03-11 06:49:53 +0000621static int reloc_fdt(void)
622{
Ovidiu Panait19b18da2020-11-28 10:43:07 +0200623 if (!IS_ENABLED(CONFIG_OF_EMBED)) {
624 if (gd->flags & GD_FLG_SKIP_RELOC)
625 return 0;
626 if (gd->new_fdt) {
627 memcpy(gd->new_fdt, gd->fdt_blob,
628 fdt_totalsize(gd->fdt_blob));
629 gd->fdt_blob = gd->new_fdt;
630 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000631 }
632
633 return 0;
634}
635
Simon Glass25e7dc62017-05-22 05:05:30 -0600636static int reloc_bootstage(void)
637{
638#ifdef CONFIG_BOOTSTAGE
639 if (gd->flags & GD_FLG_SKIP_RELOC)
640 return 0;
641 if (gd->new_bootstage) {
642 int size = bootstage_get_size();
643
644 debug("Copying bootstage from %p to %p, size %x\n",
645 gd->bootstage, gd->new_bootstage, size);
646 memcpy(gd->new_bootstage, gd->bootstage, size);
647 gd->bootstage = gd->new_bootstage;
Simon Glassac9cd482019-10-21 17:26:50 -0600648 bootstage_relocate();
Simon Glass25e7dc62017-05-22 05:05:30 -0600649 }
650#endif
651
652 return 0;
653}
654
Simon Glassf0293d32018-11-15 18:43:52 -0700655static int reloc_bloblist(void)
656{
657#ifdef CONFIG_BLOBLIST
658 if (gd->flags & GD_FLG_SKIP_RELOC)
659 return 0;
660 if (gd->new_bloblist) {
661 int size = CONFIG_BLOBLIST_SIZE;
662
663 debug("Copying bloblist from %p to %p, size %x\n",
664 gd->bloblist, gd->new_bloblist, size);
Simon Glass9fe06462021-01-13 20:29:43 -0700665 bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
666 gd->bloblist, size);
Simon Glassf0293d32018-11-15 18:43:52 -0700667 gd->bloblist = gd->new_bloblist;
668 }
669#endif
670
671 return 0;
672}
673
Simon Glass1938f4a2013-03-11 06:49:53 +0000674static int setup_reloc(void)
675{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600676 if (gd->flags & GD_FLG_SKIP_RELOC) {
677 debug("Skipping relocation due to flag\n");
678 return 0;
679 }
680
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800681#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200682#ifdef ARM
683 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
684#elif defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100685 /*
686 * On all ColdFire arch cpu, monitor code starts always
687 * just after the default vector table location, so at 0x400
688 */
689 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Simon Glass001d1882019-04-08 13:20:41 -0600690#elif !defined(CONFIG_SANDBOX)
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200691 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100692#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800693#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000694 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
695
696 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000697 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000698 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
699 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000700
701 return 0;
702}
703
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100704#ifdef CONFIG_OF_BOARD_FIXUP
705static int fix_fdt(void)
706{
707 return board_fix_fdt((void *)gd->fdt_blob);
708}
709#endif
710
Simon Glass1938f4a2013-03-11 06:49:53 +0000711/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700712#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
713 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000714
715static int jump_to_copy(void)
716{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600717 if (gd->flags & GD_FLG_SKIP_RELOC)
718 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000719 /*
720 * x86 is special, but in a nice way. It uses a trampoline which
721 * enables the dcache if possible.
722 *
723 * For now, other archs use relocate_code(), which is implemented
724 * similarly for all archs. When we do generic relocation, hopefully
725 * we can make all archs enable the dcache prior to relocation.
726 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300727#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000728 /*
729 * SDRAM and console are now initialised. The final stack can now
730 * be setup in SDRAM. Code execution will continue in Flash, but
731 * with the stack in SDRAM and Global Data in temporary memory
732 * (CPU cache)
733 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600734 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000735 board_init_f_r_trampoline(gd->start_addr_sp);
736#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000737 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000738#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000739
740 return 0;
741}
742#endif
743
744/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glassb383d6c2017-05-22 05:05:25 -0600745static int initf_bootstage(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000746{
Simon Glassbaa7d342017-06-07 10:28:46 -0600747 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
748 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glassb383d6c2017-05-22 05:05:25 -0600749 int ret;
750
Simon Glass824bb1b2017-05-22 05:05:35 -0600751 ret = bootstage_init(!from_spl);
Simon Glassb383d6c2017-05-22 05:05:25 -0600752 if (ret)
753 return ret;
Simon Glass824bb1b2017-05-22 05:05:35 -0600754 if (from_spl) {
755 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
756 CONFIG_BOOTSTAGE_STASH_SIZE);
757
758 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
759 if (ret && ret != -ENOENT) {
760 debug("Failed to unstash bootstage: err=%d\n", ret);
761 return ret;
762 }
763 }
Simon Glassb383d6c2017-05-22 05:05:25 -0600764
Simon Glass1938f4a2013-03-11 06:49:53 +0000765 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
766
767 return 0;
768}
769
Simon Glassab7cd622014-07-23 06:55:04 -0600770static int initf_dm(void)
771{
Andy Yanf1896c42017-07-24 17:43:34 +0800772#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassab7cd622014-07-23 06:55:04 -0600773 int ret;
774
Simon Glassb67eefd2020-05-10 11:39:59 -0600775 bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
Simon Glassab7cd622014-07-23 06:55:04 -0600776 ret = dm_init_and_scan(true);
Simon Glassb67eefd2020-05-10 11:39:59 -0600777 bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
Simon Glassab7cd622014-07-23 06:55:04 -0600778 if (ret)
779 return ret;
Ovidiu Panait4b9a1212020-11-28 10:43:05 +0200780
781 if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
782 ret = dm_timer_init();
783 if (ret)
784 return ret;
785 }
Simon Glass1057e6c2016-02-24 09:14:50 -0700786#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600787
788 return 0;
789}
790
Simon Glass146251f2015-01-19 22:16:12 -0700791/* Architecture-specific memory reservation */
792__weak int reserve_arch(void)
793{
794 return 0;
795}
796
Simon Glassd4c671c2015-03-05 12:25:16 -0700797__weak int arch_cpu_init_dm(void)
798{
799 return 0;
800}
801
Ovidiu Panait016e4ae2020-01-22 22:28:25 +0200802__weak int checkcpu(void)
803{
804 return 0;
805}
806
Ovidiu Panaitfbf9c152020-02-05 08:54:42 +0200807__weak int clear_bss(void)
808{
809 return 0;
810}
811
Simon Glass4acff452017-01-16 07:03:50 -0700812static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000813 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700814#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700815 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700816#endif
Heinrich Schuchardt7ef8e9b2019-06-02 00:53:24 +0200817#ifdef CONFIG_TRACE_EARLY
Simon Glass71c52db2013-06-11 11:14:42 -0700818 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800819#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700820 initf_malloc,
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700821 log_init,
Simon Glass5ac44a52017-05-22 05:05:31 -0600822 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glassf0293d32018-11-15 18:43:52 -0700823#ifdef CONFIG_BLOBLIST
824 bloblist_init,
825#endif
Simon Glassb0edea32018-11-15 18:44:09 -0700826 setup_spl_handoff,
Ovidiu Panait8e8d45e2020-11-28 10:43:04 +0200827#if defined(CONFIG_CONSOLE_RECORD_INIT_F)
828 console_record_init,
829#endif
Simon Glass671549e2017-03-28 10:27:18 -0600830#if defined(CONFIG_HAVE_FSP)
831 arch_fsp_init,
Bin Menga52a068e2015-08-20 06:40:18 -0700832#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000833 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100834 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600835 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700836 arch_cpu_init_dm,
Simon Glass1938f4a2013-03-11 06:49:53 +0000837#if defined(CONFIG_BOARD_EARLY_INIT_F)
838 board_early_init_f,
839#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600840#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600841 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000842 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600843#endif
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200844#if !defined(CONFIG_M68K)
Simon Glass1938f4a2013-03-11 06:49:53 +0000845 timer_init, /* initialize timer */
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200846#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000847#if defined(CONFIG_BOARD_POSTCLK_INIT)
848 board_postclk_init,
849#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000850 env_init, /* initialize environment */
851 init_baud_rate, /* initialze baudrate settings */
852 serial_init, /* serial communications setup */
853 console_init_f, /* stage 1 init of console */
854 display_options, /* say that we are here */
855 display_text_info, /* show debugging info if required */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000856 checkcpu,
Mario Six23471ae2018-08-06 10:23:34 +0200857#if defined(CONFIG_SYSRESET)
858 print_resetinfo,
859#endif
Simon Glasscc664002017-01-23 13:31:25 -0700860#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000861 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700862#endif
Cooper Jr., Franklinaf9e6ad2017-06-16 17:25:12 -0500863#if defined(CONFIG_DTB_RESELECT)
864 embedded_dtb_select,
865#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000866#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900867 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000868#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000869 INIT_FUNC_WATCHDOG_INIT
870#if defined(CONFIG_MISC_INIT_F)
871 misc_init_f,
872#endif
873 INIT_FUNC_WATCHDOG_RESET
Tom Rini55dabcc2021-08-18 23:12:24 -0400874#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000875 init_func_i2c,
876#endif
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530877#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
878 init_func_vid,
879#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000880 announce_dram_init,
Simon Glass1938f4a2013-03-11 06:49:53 +0000881 dram_init, /* configure available RAM banks */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000882#ifdef CONFIG_POST
883 post_init_f,
884#endif
885 INIT_FUNC_WATCHDOG_RESET
886#if defined(CONFIG_SYS_DRAM_TEST)
887 testdram,
888#endif /* CONFIG_SYS_DRAM_TEST */
889 INIT_FUNC_WATCHDOG_RESET
890
Simon Glass1938f4a2013-03-11 06:49:53 +0000891#ifdef CONFIG_POST
892 init_post,
893#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000894 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000895 /*
896 * Now that we have DRAM mapped and working, we can
897 * relocate the code and continue running from DRAM.
898 *
899 * Reserve memory at end of RAM for (top down in that order):
900 * - area that won't get touched by U-Boot and Linux (optional)
901 * - kernel log buffer
902 * - protected RAM
903 * - LCD framebuffer
904 * - monitor code
905 * - board info struct
906 */
907 setup_dest_addr,
Pragnesh Patel313981c2020-08-13 10:12:26 +0530908#ifdef CONFIG_OF_BOARD_FIXUP
909 fix_fdt,
910#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000911#ifdef CONFIG_PRAM
912 reserve_pram,
913#endif
914 reserve_round_4k,
Ovidiu Panait79926e42020-03-29 20:57:41 +0300915 arch_reserve_mmu,
Simon Glass5a541942016-01-18 19:52:21 -0700916 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700917 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000918 reserve_uboot,
919 reserve_malloc,
920 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000921 reserve_global_data,
922 reserve_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600923 reserve_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700924 reserve_bloblist,
Simon Glass146251f2015-01-19 22:16:12 -0700925 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000926 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600927 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000928 show_dram_config,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000929 INIT_FUNC_WATCHDOG_RESET
Ovidiu Panait15328852020-07-24 14:12:20 +0300930 setup_bdinfo,
Simon Glass1938f4a2013-03-11 06:49:53 +0000931 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000932 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000933 reloc_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600934 reloc_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700935 reloc_bloblist,
Simon Glass1938f4a2013-03-11 06:49:53 +0000936 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300937#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700938 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700939 do_elf_reloc_fixups,
940#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300941 clear_bss,
Simon Glass530f27e2017-01-16 07:03:49 -0700942#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
943 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000944 jump_to_copy,
945#endif
946 NULL,
947};
948
949void board_init_f(ulong boot_flags)
950{
Simon Glass1938f4a2013-03-11 06:49:53 +0000951 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +0400952 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000953
954 if (initcall_run_list(init_sequence_f))
955 hang();
956
Ben Stoltz9b217492015-07-31 09:31:37 -0600957#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Alexey Brodkin264d2982015-12-16 19:24:10 +0300958 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
959 !defined(CONFIG_ARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000960 /* NOTREACHED - jump_to_copy() does not return */
961 hang();
962#endif
963}
964
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300965#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000966/*
967 * For now this code is only used on x86.
968 *
969 * init_sequence_f_r is the list of init functions which are run when
970 * U-Boot is executing from Flash with a semi-limited 'C' environment.
971 * The following limitations must be considered when implementing an
972 * '_f_r' function:
973 * - 'static' variables are read-only
974 * - Global Data (gd->xxx) is read/write
975 *
976 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
977 * supported). It _should_, if possible, copy global data to RAM and
978 * initialise the CPU caches (to speed up the relocation process)
979 *
980 * NOTE: At present only x86 uses this route, but it is intended that
981 * all archs will move to this when generic relocation is implemented.
982 */
Simon Glass4acff452017-01-16 07:03:50 -0700983static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -0700984#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +0000985 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -0700986#endif
Simon Glass48a33802013-03-05 14:39:52 +0000987
988 NULL,
989};
990
991void board_init_f_r(void)
992{
993 if (initcall_run_list(init_sequence_f_r))
994 hang();
995
996 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -0700997 * The pre-relocation drivers may be using memory that has now gone
998 * away. Mark serial as unavailable - this will fall back to the debug
999 * UART if available.
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001000 *
1001 * Do the same with log drivers since the memory may not be available.
Simon Glasse4d6ab02016-03-11 22:06:51 -07001002 */
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001003 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
Simon Glass5ee94b42017-09-05 19:49:45 -06001004#ifdef CONFIG_TIMER
1005 gd->timer = NULL;
1006#endif
Simon Glasse4d6ab02016-03-11 22:06:51 -07001007
1008 /*
Simon Glass48a33802013-03-05 14:39:52 +00001009 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1010 * Transfer execution from Flash to RAM by calculating the address
1011 * of the in-RAM copy of board_init_r() and calling it
1012 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001013 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001014
1015 /* NOTREACHED - board_init_r() does not return */
1016 hang();
1017}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001018#endif /* CONFIG_X86 */