blob: 01044452bf27e3790b2741cfb711d7a21ba644c3 [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 Glassab7cd622014-07-23 06:55:04 -060016#include <dm.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060017#include <env.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060018#include <env_internal.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000019#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000020#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000021#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000022#include <initcall.h>
Simon Glass3c1ecde2019-08-01 09:46:38 -060023#include <lcd.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070024#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050025#include <mapmem.h>
Simon Glassa733b062013-04-26 02:53:43 +000026#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000027#include <post.h>
Simon Glasse47b2d62017-03-31 08:40:38 -060028#include <relocate.h>
Simon Glassb03e0512019-11-14 12:57:24 -070029#include <serial.h>
Simon Glassb0edea32018-11-15 18:44:09 -070030#ifdef CONFIG_SPL
31#include <spl.h>
32#endif
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020033#include <status_led.h>
Mario Six23471ae2018-08-06 10:23:34 +020034#include <sysreset.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070035#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070036#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070037#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000038#include <watchdog.h>
Simon Glassb885d022017-05-17 08:23:01 -060039#ifdef CONFIG_MACH_TYPE
40#include <asm/mach-types.h>
41#endif
Simon Glass1fbf97d2017-03-31 08:40:39 -060042#if defined(CONFIG_MP) && defined(CONFIG_PPC)
43#include <asm/mp.h>
44#endif
Simon Glass1938f4a2013-03-11 06:49:53 +000045#include <asm/io.h>
46#include <asm/sections.h>
Simon Glassab7cd622014-07-23 06:55:04 -060047#include <dm/root.h>
Simon Glass056285f2017-03-31 08:40:35 -060048#include <linux/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000049
50/*
51 * Pointer to initial global data area
52 *
53 * Here we initialize it if needed.
54 */
55#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
56#undef XTRN_DECLARE_GLOBAL_DATA_PTR
57#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Mario Six16ef1472018-01-15 11:10:02 +010058DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
Simon Glass1938f4a2013-03-11 06:49:53 +000059#else
60DECLARE_GLOBAL_DATA_PTR;
61#endif
62
63/*
Simon Glass4c509342015-04-28 20:25:03 -060064 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000065 * refactored to a single function, something like:
66 *
67 * void led_set_state(enum led_colour_t colour, int on);
68 */
69/************************************************************************
70 * Coloured LED functionality
71 ************************************************************************
72 * May be supplied by boards if desired
73 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020074__weak void coloured_LED_init(void) {}
75__weak void red_led_on(void) {}
76__weak void red_led_off(void) {}
77__weak void green_led_on(void) {}
78__weak void green_led_off(void) {}
79__weak void yellow_led_on(void) {}
80__weak void yellow_led_off(void) {}
81__weak void blue_led_on(void) {}
82__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000083
84/*
85 * Why is gd allocated a register? Prior to reloc it might be better to
86 * just pass it around to each function in this file?
87 *
88 * After reloc one could argue that it is hardly used and doesn't need
89 * to be in a register. Or if it is it should perhaps hold pointers to all
90 * global data for all modules, so that post-reloc we can avoid the massive
91 * literal pool we get on ARM. Or perhaps just encourage each module to use
92 * a structure...
93 */
94
Sonic Zhangd54d7eb2014-07-17 19:01:34 +080095#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +000096static int init_func_watchdog_init(void)
97{
Tom Riniea3310e2017-03-14 11:08:10 -040098# if defined(CONFIG_HW_WATCHDOG) && \
99 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -0700100 defined(CONFIG_SH) || \
Anatolij Gustschin46d7a3b2016-06-13 14:24:23 +0200101 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100102 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800103 hw_watchdog_init();
Simon Glasse4fef6c2013-03-11 14:30:42 +0000104 puts(" Watchdog enabled\n");
Anatolij Gustschinba169d92016-06-13 14:24:24 +0200105# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000106 WATCHDOG_RESET();
107
108 return 0;
109}
110
111int init_func_watchdog_reset(void)
112{
113 WATCHDOG_RESET();
114
115 return 0;
116}
117#endif /* CONFIG_WATCHDOG */
118
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200119__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000120{
121 /* please define platform specific board_add_ram_info() */
122}
123
Simon Glass1938f4a2013-03-11 06:49:53 +0000124static int init_baud_rate(void)
125{
Simon Glassbfebc8c2017-08-03 12:22:13 -0600126 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
Simon Glass1938f4a2013-03-11 06:49:53 +0000127 return 0;
128}
129
130static int display_text_info(void)
131{
Ben Stoltz9b217492015-07-31 09:31:37 -0600132#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100133 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000134
Simon Glass632efa72013-03-11 07:06:48 +0000135 bss_start = (ulong)&__bss_start;
136 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100137
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800138#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100139 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800140#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100141 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800142#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100143
144 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
Mario Six16ef1472018-01-15 11:10:02 +0100145 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000146#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000147
Simon Glass1938f4a2013-03-11 06:49:53 +0000148 return 0;
149}
150
Mario Six23471ae2018-08-06 10:23:34 +0200151#ifdef CONFIG_SYSRESET
152static int print_resetinfo(void)
153{
154 struct udevice *dev;
155 char status[256];
156 int ret;
157
158 ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
159 if (ret) {
160 debug("%s: No sysreset device found (error: %d)\n",
161 __func__, ret);
162 /* Not all boards have sysreset drivers available during early
163 * boot, so don't fail if one can't be found.
164 */
165 return 0;
166 }
167
168 if (!sysreset_get_status(dev, status, sizeof(status)))
169 printf("%s", status);
170
171 return 0;
172}
173#endif
174
Mario Six5d6c61a2018-08-06 10:23:41 +0200175#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
176static int print_cpuinfo(void)
177{
178 struct udevice *dev;
179 char desc[512];
180 int ret;
181
182 ret = uclass_first_device_err(UCLASS_CPU, &dev);
183 if (ret) {
184 debug("%s: Could not get CPU device (err = %d)\n",
185 __func__, ret);
186 return ret;
187 }
188
189 ret = cpu_get_desc(dev, desc, sizeof(desc));
190 if (ret) {
191 debug("%s: Could not get CPU description (err = %d)\n",
192 dev->name, ret);
193 return ret;
194 }
195
Bin Mengecfe6632018-10-10 22:06:55 -0700196 printf("CPU: %s\n", desc);
Mario Six5d6c61a2018-08-06 10:23:41 +0200197
198 return 0;
199}
200#endif
201
Simon Glass1938f4a2013-03-11 06:49:53 +0000202static int announce_dram_init(void)
203{
204 puts("DRAM: ");
205 return 0;
206}
207
208static int show_dram_config(void)
209{
York Sunfa39ffe2014-05-02 17:28:05 -0700210 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000211
212#ifdef CONFIG_NR_DRAM_BANKS
213 int i;
214
215 debug("\nRAM Configuration:\n");
216 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
217 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700218 debug("Bank #%d: %llx ", i,
219 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000220#ifdef DEBUG
221 print_size(gd->bd->bi_dram[i].size, "\n");
222#endif
223 }
224 debug("\nDRAM: ");
225#else
226 size = gd->ram_size;
227#endif
228
Simon Glasse4fef6c2013-03-11 14:30:42 +0000229 print_size(size, "");
230 board_add_ram_info(0);
231 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000232
233 return 0;
234}
235
Simon Glass76b00ac2017-03-31 08:40:32 -0600236__weak int dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000237{
238#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
239 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
240 gd->bd->bi_dram[0].size = get_effective_memsize();
241#endif
Simon Glass76b00ac2017-03-31 08:40:32 -0600242
243 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000244}
245
Simon Glass69153982017-05-12 21:09:56 -0600246#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000247static int init_func_i2c(void)
248{
249 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200250#ifdef CONFIG_SYS_I2C
251 i2c_init_all();
252#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000253 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200254#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000255 puts("ready\n");
256 return 0;
257}
258#endif
259
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530260#if defined(CONFIG_VID)
261__weak int init_func_vid(void)
262{
263 return 0;
264}
265#endif
266
Simon Glass1938f4a2013-03-11 06:49:53 +0000267static int setup_mon_len(void)
268{
Michal Simeke945f6d2014-05-08 16:08:44 +0200269#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100270 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600271#elif defined(CONFIG_SANDBOX) || 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;
Rick Chen068feb92017-12-26 13:55:58 +0800275#elif defined(CONFIG_NDS32) || 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)
287 gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
288 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{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700308#ifdef CONFIG_SYS_SDRAM_BASE
309 /*
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);
York Sun36cc0de2017-03-06 09:02:28 -0800330#if defined(CONFIG_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
Simon Glass80d4bcd2017-03-31 08:40:29 -0600384#ifdef CONFIG_ARM
Siva Durga Prasad Paladugu60873f72017-07-13 19:01:08 +0530385__weak int reserve_mmu(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000386{
Trevor Woerner10015022019-05-03 09:41:00 -0400387#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Simon Glass1938f4a2013-03-11 06:49:53 +0000388 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800389 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000390 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000391
392 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000393 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000394
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000395 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000396 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
397 gd->arch.tlb_addr + gd->arch.tlb_size);
York Sun50e93b92016-06-24 16:46:19 -0700398
399#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
400 /*
401 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
402 * with location within secure ram.
403 */
404 gd->arch.tlb_allocated = gd->arch.tlb_addr;
405#endif
Simon Glass80d4bcd2017-03-31 08:40:29 -0600406#endif
York Sun50e93b92016-06-24 16:46:19 -0700407
Simon Glass1938f4a2013-03-11 06:49:53 +0000408 return 0;
409}
410#endif
411
Simon Glass5a541942016-01-18 19:52:21 -0700412static int reserve_video(void)
413{
Simon Glass0f079eb2017-03-31 08:40:30 -0600414#ifdef CONFIG_DM_VIDEO
Simon Glass5a541942016-01-18 19:52:21 -0700415 ulong addr;
416 int ret;
417
418 addr = gd->relocaddr;
419 ret = video_reserve(&addr);
420 if (ret)
421 return ret;
422 gd->relocaddr = addr;
Simon Glass0f079eb2017-03-31 08:40:30 -0600423#elif defined(CONFIG_LCD)
Simon Glass5a541942016-01-18 19:52:21 -0700424# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000425 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700426# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000427 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000428 gd->relocaddr = lcd_setmem(gd->relocaddr);
429 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700430# endif /* CONFIG_FB_ADDR */
Simon Glass0f079eb2017-03-31 08:40:30 -0600431#endif
Simon Glass8703ef32016-01-18 19:52:20 -0700432
433 return 0;
434}
Simon Glass8703ef32016-01-18 19:52:20 -0700435
Simon Glass71c52db2013-06-11 11:14:42 -0700436static int reserve_trace(void)
437{
438#ifdef CONFIG_TRACE
439 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
440 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
Heinrich Schuchardt7ea33572019-06-14 21:52:22 +0200441 debug("Reserving %luk for trace data at: %08lx\n",
442 (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
Simon Glass71c52db2013-06-11 11:14:42 -0700443#endif
444
445 return 0;
446}
447
Simon Glass1938f4a2013-03-11 06:49:53 +0000448static int reserve_uboot(void)
449{
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300450 if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
451 /*
452 * reserve memory for U-Boot code, data & bss
453 * round down to next 4 kB limit
454 */
455 gd->relocaddr -= gd->mon_len;
456 gd->relocaddr &= ~(4096 - 1);
457 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
458 /* round down to next 64 kB limit so that IVPR stays aligned */
459 gd->relocaddr &= ~(65536 - 1);
460 #endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000461
Alexey Brodkinff2b2ba2018-05-25 16:08:14 +0300462 debug("Reserving %ldk for U-Boot at: %08lx\n",
463 gd->mon_len >> 10, gd->relocaddr);
464 }
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000465
466 gd->start_addr_sp = gd->relocaddr;
467
Simon Glass1938f4a2013-03-11 06:49:53 +0000468 return 0;
469}
470
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700471#ifdef CONFIG_SYS_NONCACHED_MEMORY
472static int reserve_noncached(void)
473{
Stephen Warren5e0404f2019-08-27 11:54:31 -0600474 /*
475 * The value of gd->start_addr_sp must match the value of malloc_start
476 * calculated in boatrd_f.c:initr_malloc(), which is passed to
477 * board_r.c:mem_malloc_init() and then used by
478 * cache.c:noncached_init()
479 *
480 * These calculations must match the code in cache.c:noncached_init()
481 */
482 gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
483 MMU_SECTION_SIZE;
484 gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
485 MMU_SECTION_SIZE);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700486 debug("Reserving %dM for noncached_alloc() at: %08lx\n",
487 CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
488
489 return 0;
490}
491#endif
492
Simon Glass1938f4a2013-03-11 06:49:53 +0000493/* reserve memory for malloc() area */
494static int reserve_malloc(void)
495{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000496 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000497 debug("Reserving %dk for malloc() at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100498 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Vikas Manocha5f7adb52019-08-16 09:57:44 -0700499#ifdef CONFIG_SYS_NONCACHED_MEMORY
500 reserve_noncached();
501#endif
502
Simon Glass1938f4a2013-03-11 06:49:53 +0000503 return 0;
504}
505
506/* (permanently) allocate a Board Info struct */
507static int reserve_board(void)
508{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800509 if (!gd->bd) {
510 gd->start_addr_sp -= sizeof(bd_t);
511 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
512 memset(gd->bd, '\0', sizeof(bd_t));
513 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
514 sizeof(bd_t), gd->start_addr_sp);
515 }
Simon Glass1938f4a2013-03-11 06:49:53 +0000516 return 0;
517}
518
519static int setup_machine(void)
520{
521#ifdef CONFIG_MACH_TYPE
522 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
523#endif
524 return 0;
525}
526
527static int reserve_global_data(void)
528{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000529 gd->start_addr_sp -= sizeof(gd_t);
530 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glass1938f4a2013-03-11 06:49:53 +0000531 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Mario Six16ef1472018-01-15 11:10:02 +0100532 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000533 return 0;
534}
535
536static int reserve_fdt(void)
537{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100538#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000539 /*
Simon Glass4c509342015-04-28 20:25:03 -0600540 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000541 * must relocate it. If it is embedded in the data section, then it
542 * will be relocated with other data.
543 */
544 if (gd->fdt_blob) {
545 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
546
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000547 gd->start_addr_sp -= gd->fdt_size;
548 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000549 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000550 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000551 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100552#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000553
554 return 0;
555}
556
Simon Glass25e7dc62017-05-22 05:05:30 -0600557static int reserve_bootstage(void)
558{
559#ifdef CONFIG_BOOTSTAGE
560 int size = bootstage_get_size();
561
562 gd->start_addr_sp -= size;
563 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
564 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
565 gd->start_addr_sp);
566#endif
567
568 return 0;
569}
570
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100571__weak int arch_reserve_stacks(void)
Andreas Bießmann68145d42015-02-06 23:06:45 +0100572{
573 return 0;
574}
575
Simon Glass1938f4a2013-03-11 06:49:53 +0000576static int reserve_stacks(void)
577{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100578 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000579 gd->start_addr_sp -= 16;
580 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000581
582 /*
Simon Glass4c509342015-04-28 20:25:03 -0600583 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100584 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000585 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100586 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000587}
588
Simon Glassf0293d32018-11-15 18:43:52 -0700589static int reserve_bloblist(void)
590{
591#ifdef CONFIG_BLOBLIST
Simon Glass5074a8a2019-10-21 17:26:46 -0600592 gd->start_addr_sp &= ~0xf;
Simon Glassf0293d32018-11-15 18:43:52 -0700593 gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
594 gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
595#endif
596
597 return 0;
598}
599
Simon Glass1938f4a2013-03-11 06:49:53 +0000600static int display_new_sp(void)
601{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000602 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000603
604 return 0;
605}
606
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200607#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
608 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000609static int setup_board_part1(void)
610{
611 bd_t *bd = gd->bd;
612
613 /*
614 * Save local variables to board info struct
615 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000616 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
617 bd->bi_memsize = gd->ram_size; /* size in bytes */
618
619#ifdef CONFIG_SYS_SRAM_BASE
620 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
621 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
622#endif
623
Heiko Schocher50258972017-06-07 17:33:11 +0200624#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000625 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
626#endif
Heiko Schocher064b55c2017-06-14 05:49:40 +0200627#if defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000628 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
629#endif
630#if defined(CONFIG_MPC83xx)
631 bd->bi_immrbar = CONFIG_SYS_IMMR;
632#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000633
634 return 0;
635}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100636#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000637
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100638#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000639static int setup_board_part2(void)
640{
641 bd_t *bd = gd->bd;
642
643 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
644 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
645#if defined(CONFIG_CPM2)
646 bd->bi_cpmfreq = gd->arch.cpm_clk;
647 bd->bi_brgfreq = gd->arch.brg_clk;
648 bd->bi_sccfreq = gd->arch.scc_clk;
649 bd->bi_vco = gd->arch.vco_out;
650#endif /* CONFIG_CPM2 */
Alison Wang1313db42015-02-12 18:33:15 +0800651#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
652 bd->bi_pcifreq = gd->pci_clk;
653#endif
654#if defined(CONFIG_EXTRA_CLOCK)
655 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
656 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
657 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
658#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000659
660 return 0;
661}
662#endif
663
Simon Glass1938f4a2013-03-11 06:49:53 +0000664#ifdef CONFIG_POST
665static int init_post(void)
666{
667 post_bootmode_init();
668 post_run(NULL, POST_ROM | post_bootmode_get(0));
669
670 return 0;
671}
672#endif
673
Simon Glass1938f4a2013-03-11 06:49:53 +0000674static int reloc_fdt(void)
675{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100676#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600677 if (gd->flags & GD_FLG_SKIP_RELOC)
678 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000679 if (gd->new_fdt) {
680 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
681 gd->fdt_blob = gd->new_fdt;
682 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100683#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000684
685 return 0;
686}
687
Simon Glass25e7dc62017-05-22 05:05:30 -0600688static int reloc_bootstage(void)
689{
690#ifdef CONFIG_BOOTSTAGE
691 if (gd->flags & GD_FLG_SKIP_RELOC)
692 return 0;
693 if (gd->new_bootstage) {
694 int size = bootstage_get_size();
695
696 debug("Copying bootstage from %p to %p, size %x\n",
697 gd->bootstage, gd->new_bootstage, size);
698 memcpy(gd->new_bootstage, gd->bootstage, size);
699 gd->bootstage = gd->new_bootstage;
Simon Glassac9cd482019-10-21 17:26:50 -0600700 bootstage_relocate();
Simon Glass25e7dc62017-05-22 05:05:30 -0600701 }
702#endif
703
704 return 0;
705}
706
Simon Glassf0293d32018-11-15 18:43:52 -0700707static int reloc_bloblist(void)
708{
709#ifdef CONFIG_BLOBLIST
710 if (gd->flags & GD_FLG_SKIP_RELOC)
711 return 0;
712 if (gd->new_bloblist) {
713 int size = CONFIG_BLOBLIST_SIZE;
714
715 debug("Copying bloblist from %p to %p, size %x\n",
716 gd->bloblist, gd->new_bloblist, size);
717 memcpy(gd->new_bloblist, gd->bloblist, size);
718 gd->bloblist = gd->new_bloblist;
719 }
720#endif
721
722 return 0;
723}
724
Simon Glass1938f4a2013-03-11 06:49:53 +0000725static int setup_reloc(void)
726{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600727 if (gd->flags & GD_FLG_SKIP_RELOC) {
728 debug("Skipping relocation due to flag\n");
729 return 0;
730 }
731
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800732#ifdef CONFIG_SYS_TEXT_BASE
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200733#ifdef ARM
734 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
735#elif defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100736 /*
737 * On all ColdFire arch cpu, monitor code starts always
738 * just after the default vector table location, so at 0x400
739 */
740 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
Simon Glass001d1882019-04-08 13:20:41 -0600741#elif !defined(CONFIG_SANDBOX)
Lothar Waßmann53207bf2017-06-08 10:18:25 +0200742 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100743#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800744#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000745 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
746
747 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000748 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000749 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
750 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000751
752 return 0;
753}
754
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100755#ifdef CONFIG_OF_BOARD_FIXUP
756static int fix_fdt(void)
757{
758 return board_fix_fdt((void *)gd->fdt_blob);
759}
760#endif
761
Simon Glass1938f4a2013-03-11 06:49:53 +0000762/* ARM calls relocate_code from its crt0.S */
Simon Glass530f27e2017-01-16 07:03:49 -0700763#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
764 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +0000765
766static int jump_to_copy(void)
767{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600768 if (gd->flags & GD_FLG_SKIP_RELOC)
769 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000770 /*
771 * x86 is special, but in a nice way. It uses a trampoline which
772 * enables the dcache if possible.
773 *
774 * For now, other archs use relocate_code(), which is implemented
775 * similarly for all archs. When we do generic relocation, hopefully
776 * we can make all archs enable the dcache prior to relocation.
777 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300778#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000779 /*
780 * SDRAM and console are now initialised. The final stack can now
781 * be setup in SDRAM. Code execution will continue in Flash, but
782 * with the stack in SDRAM and Global Data in temporary memory
783 * (CPU cache)
784 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600785 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000786 board_init_f_r_trampoline(gd->start_addr_sp);
787#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000788 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000789#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000790
791 return 0;
792}
793#endif
794
795/* Record the board_init_f() bootstage (after arch_cpu_init()) */
Simon Glassb383d6c2017-05-22 05:05:25 -0600796static int initf_bootstage(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000797{
Simon Glassbaa7d342017-06-07 10:28:46 -0600798 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
799 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
Simon Glassb383d6c2017-05-22 05:05:25 -0600800 int ret;
801
Simon Glass824bb1b2017-05-22 05:05:35 -0600802 ret = bootstage_init(!from_spl);
Simon Glassb383d6c2017-05-22 05:05:25 -0600803 if (ret)
804 return ret;
Simon Glass824bb1b2017-05-22 05:05:35 -0600805 if (from_spl) {
806 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
807 CONFIG_BOOTSTAGE_STASH_SIZE);
808
809 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
810 if (ret && ret != -ENOENT) {
811 debug("Failed to unstash bootstage: err=%d\n", ret);
812 return ret;
813 }
814 }
Simon Glassb383d6c2017-05-22 05:05:25 -0600815
Simon Glass1938f4a2013-03-11 06:49:53 +0000816 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
817
818 return 0;
819}
820
Simon Glass9854a872015-11-08 23:47:48 -0700821static int initf_console_record(void)
822{
Andy Yanf1896c42017-07-24 17:43:34 +0800823#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glass9854a872015-11-08 23:47:48 -0700824 return console_record_init();
825#else
826 return 0;
827#endif
828}
829
Simon Glassab7cd622014-07-23 06:55:04 -0600830static int initf_dm(void)
831{
Andy Yanf1896c42017-07-24 17:43:34 +0800832#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glassab7cd622014-07-23 06:55:04 -0600833 int ret;
834
Simon Glass63c5bf42017-05-22 05:05:32 -0600835 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
Simon Glassab7cd622014-07-23 06:55:04 -0600836 ret = dm_init_and_scan(true);
Simon Glass63c5bf42017-05-22 05:05:32 -0600837 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
Simon Glassab7cd622014-07-23 06:55:04 -0600838 if (ret)
839 return ret;
840#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700841#ifdef CONFIG_TIMER_EARLY
842 ret = dm_timer_init();
843 if (ret)
844 return ret;
845#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600846
847 return 0;
848}
849
Simon Glass146251f2015-01-19 22:16:12 -0700850/* Architecture-specific memory reservation */
851__weak int reserve_arch(void)
852{
853 return 0;
854}
855
Simon Glassd4c671c2015-03-05 12:25:16 -0700856__weak int arch_cpu_init_dm(void)
857{
858 return 0;
859}
860
Simon Glass4acff452017-01-16 07:03:50 -0700861static const init_fnc_t init_sequence_f[] = {
Simon Glass1938f4a2013-03-11 06:49:53 +0000862 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700863#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700864 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700865#endif
Heinrich Schuchardt7ef8e9b2019-06-02 00:53:24 +0200866#ifdef CONFIG_TRACE_EARLY
Simon Glass71c52db2013-06-11 11:14:42 -0700867 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800868#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700869 initf_malloc,
Simon Glassaf1bc0c2017-12-04 13:48:28 -0700870 log_init,
Simon Glass5ac44a52017-05-22 05:05:31 -0600871 initf_bootstage, /* uses its own timer, so does not need DM */
Simon Glassf0293d32018-11-15 18:43:52 -0700872#ifdef CONFIG_BLOBLIST
873 bloblist_init,
874#endif
Simon Glassb0edea32018-11-15 18:44:09 -0700875 setup_spl_handoff,
Simon Glass9854a872015-11-08 23:47:48 -0700876 initf_console_record,
Simon Glass671549e2017-03-28 10:27:18 -0600877#if defined(CONFIG_HAVE_FSP)
878 arch_fsp_init,
Bin Menga52a0682015-08-20 06:40:18 -0700879#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000880 arch_cpu_init, /* basic arch cpu dependent setup */
Paul Burton8ebf5062016-09-21 11:18:46 +0100881 mach_cpu_init, /* SoC/machine dependent CPU setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600882 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700883 arch_cpu_init_dm,
Simon Glass1938f4a2013-03-11 06:49:53 +0000884#if defined(CONFIG_BOARD_EARLY_INIT_F)
885 board_early_init_f,
886#endif
Simon Glass727e94a2017-03-28 10:27:26 -0600887#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
Simon Glassc252c062017-03-28 10:27:19 -0600888 /* get CPU and bus clocks according to the environment variable */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000889 get_clocks, /* get CPU and bus clocks (etc.) */
Simon Glass1793e782017-03-28 10:27:23 -0600890#endif
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200891#if !defined(CONFIG_M68K)
Simon Glass1938f4a2013-03-11 06:49:53 +0000892 timer_init, /* initialize timer */
Angelo Dureghello0ce45282017-05-10 23:58:06 +0200893#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000894#if defined(CONFIG_BOARD_POSTCLK_INIT)
895 board_postclk_init,
896#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000897 env_init, /* initialize environment */
898 init_baud_rate, /* initialze baudrate settings */
899 serial_init, /* serial communications setup */
900 console_init_f, /* stage 1 init of console */
901 display_options, /* say that we are here */
902 display_text_info, /* show debugging info if required */
Angelo Dureghellob9153fe32017-08-20 00:01:55 +0200903#if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000904 checkcpu,
905#endif
Mario Six23471ae2018-08-06 10:23:34 +0200906#if defined(CONFIG_SYSRESET)
907 print_resetinfo,
908#endif
Simon Glasscc664002017-01-23 13:31:25 -0700909#if defined(CONFIG_DISPLAY_CPUINFO)
Simon Glass1938f4a2013-03-11 06:49:53 +0000910 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasscc664002017-01-23 13:31:25 -0700911#endif
Cooper Jr., Franklinaf9e6ad2017-06-16 17:25:12 -0500912#if defined(CONFIG_DTB_RESELECT)
913 embedded_dtb_select,
914#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000915#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900916 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000917#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000918 INIT_FUNC_WATCHDOG_INIT
919#if defined(CONFIG_MISC_INIT_F)
920 misc_init_f,
921#endif
922 INIT_FUNC_WATCHDOG_RESET
Simon Glass69153982017-05-12 21:09:56 -0600923#if defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000924 init_func_i2c,
925#endif
Rajesh Bhagat1fab98f2018-01-17 16:13:08 +0530926#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
927 init_func_vid,
928#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000929 announce_dram_init,
Simon Glass1938f4a2013-03-11 06:49:53 +0000930 dram_init, /* configure available RAM banks */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000931#ifdef CONFIG_POST
932 post_init_f,
933#endif
934 INIT_FUNC_WATCHDOG_RESET
935#if defined(CONFIG_SYS_DRAM_TEST)
936 testdram,
937#endif /* CONFIG_SYS_DRAM_TEST */
938 INIT_FUNC_WATCHDOG_RESET
939
Simon Glass1938f4a2013-03-11 06:49:53 +0000940#ifdef CONFIG_POST
941 init_post,
942#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000943 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000944 /*
945 * Now that we have DRAM mapped and working, we can
946 * relocate the code and continue running from DRAM.
947 *
948 * Reserve memory at end of RAM for (top down in that order):
949 * - area that won't get touched by U-Boot and Linux (optional)
950 * - kernel log buffer
951 * - protected RAM
952 * - LCD framebuffer
953 * - monitor code
954 * - board info struct
955 */
956 setup_dest_addr,
Simon Glass1938f4a2013-03-11 06:49:53 +0000957#ifdef CONFIG_PRAM
958 reserve_pram,
959#endif
960 reserve_round_4k,
Simon Glass80d4bcd2017-03-31 08:40:29 -0600961#ifdef CONFIG_ARM
Simon Glass1938f4a2013-03-11 06:49:53 +0000962 reserve_mmu,
963#endif
Simon Glass5a541942016-01-18 19:52:21 -0700964 reserve_video,
Simon Glass8703ef32016-01-18 19:52:20 -0700965 reserve_trace,
Simon Glass1938f4a2013-03-11 06:49:53 +0000966 reserve_uboot,
967 reserve_malloc,
968 reserve_board,
Simon Glass1938f4a2013-03-11 06:49:53 +0000969 setup_machine,
970 reserve_global_data,
971 reserve_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600972 reserve_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700973 reserve_bloblist,
Simon Glass146251f2015-01-19 22:16:12 -0700974 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +0000975 reserve_stacks,
Simon Glass76b00ac2017-03-31 08:40:32 -0600976 dram_init_banksize,
Simon Glass1938f4a2013-03-11 06:49:53 +0000977 show_dram_config,
Vladimir Zapolskiye2099d72016-11-28 00:15:24 +0200978#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
979 defined(CONFIG_SH)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000980 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100981#endif
982#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000983 INIT_FUNC_WATCHDOG_RESET
984 setup_board_part2,
985#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000986 display_new_sp,
mario.six@gdsys.cc2a792752017-02-22 16:07:22 +0100987#ifdef CONFIG_OF_BOARD_FIXUP
988 fix_fdt,
989#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000990 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000991 reloc_fdt,
Simon Glass25e7dc62017-05-22 05:05:30 -0600992 reloc_bootstage,
Simon Glassf0293d32018-11-15 18:43:52 -0700993 reloc_bloblist,
Simon Glass1938f4a2013-03-11 06:49:53 +0000994 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300995#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -0700996 copy_uboot_to_ram,
Simon Glass313aef32015-01-01 16:18:09 -0700997 do_elf_reloc_fixups,
Simon Glass6bda55a2017-01-16 07:03:52 -0700998 clear_bss,
Simon Glass313aef32015-01-01 16:18:09 -0700999#endif
Chris Zankelde5e5ce2016-08-10 18:36:43 +03001000#if defined(CONFIG_XTENSA)
1001 clear_bss,
1002#endif
Simon Glass530f27e2017-01-16 07:03:49 -07001003#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1004 !CONFIG_IS_ENABLED(X86_64)
Simon Glass1938f4a2013-03-11 06:49:53 +00001005 jump_to_copy,
1006#endif
1007 NULL,
1008};
1009
1010void board_init_f(ulong boot_flags)
1011{
Simon Glass1938f4a2013-03-11 06:49:53 +00001012 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001013 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001014
1015 if (initcall_run_list(init_sequence_f))
1016 hang();
1017
Ben Stoltz9b217492015-07-31 09:31:37 -06001018#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
Alexey Brodkin264d2982015-12-16 19:24:10 +03001019 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
1020 !defined(CONFIG_ARC)
Simon Glass1938f4a2013-03-11 06:49:53 +00001021 /* NOTREACHED - jump_to_copy() does not return */
1022 hang();
1023#endif
1024}
1025
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001026#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +00001027/*
1028 * For now this code is only used on x86.
1029 *
1030 * init_sequence_f_r is the list of init functions which are run when
1031 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1032 * The following limitations must be considered when implementing an
1033 * '_f_r' function:
1034 * - 'static' variables are read-only
1035 * - Global Data (gd->xxx) is read/write
1036 *
1037 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1038 * supported). It _should_, if possible, copy global data to RAM and
1039 * initialise the CPU caches (to speed up the relocation process)
1040 *
1041 * NOTE: At present only x86 uses this route, but it is intended that
1042 * all archs will move to this when generic relocation is implemented.
1043 */
Simon Glass4acff452017-01-16 07:03:50 -07001044static const init_fnc_t init_sequence_f_r[] = {
Simon Glass530f27e2017-01-16 07:03:49 -07001045#if !CONFIG_IS_ENABLED(X86_64)
Simon Glass48a33802013-03-05 14:39:52 +00001046 init_cache_f_r,
Simon Glass530f27e2017-01-16 07:03:49 -07001047#endif
Simon Glass48a33802013-03-05 14:39:52 +00001048
1049 NULL,
1050};
1051
1052void board_init_f_r(void)
1053{
1054 if (initcall_run_list(init_sequence_f_r))
1055 hang();
1056
1057 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001058 * The pre-relocation drivers may be using memory that has now gone
1059 * away. Mark serial as unavailable - this will fall back to the debug
1060 * UART if available.
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001061 *
1062 * Do the same with log drivers since the memory may not be available.
Simon Glasse4d6ab02016-03-11 22:06:51 -07001063 */
Simon Glassaf1bc0c2017-12-04 13:48:28 -07001064 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
Simon Glass5ee94b42017-09-05 19:49:45 -06001065#ifdef CONFIG_TIMER
1066 gd->timer = NULL;
1067#endif
Simon Glasse4d6ab02016-03-11 22:06:51 -07001068
1069 /*
Simon Glass48a33802013-03-05 14:39:52 +00001070 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1071 * Transfer execution from Flash to RAM by calculating the address
1072 * of the in-RAM copy of board_init_r() and calling it
1073 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001074 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001075
1076 /* NOTREACHED - board_init_r() does not return */
1077 hang();
1078}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001079#endif /* CONFIG_X86 */