]> Git Repo - u-boot.git/blame - common/board_f.c
common: Kconfig: Introduce CONFIG_CONSOLE_RECORD_INIT_F
[u-boot.git] / common / board_f.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
1938f4a5
SG
2/*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2002-2006
5 * Wolfgang Denk, DENX Software Engineering, [email protected].
6 *
7 * (C) Copyright 2002
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Marius Groeger <[email protected]>
1938f4a5
SG
10 */
11
12#include <common.h>
f0293d33 13#include <bloblist.h>
52f24238 14#include <bootstage.h>
d96c2604 15#include <clock_legacy.h>
24b852a7 16#include <console.h>
5d6c61ac 17#include <cpu.h>
30c7c434 18#include <cpu_func.h>
ab7cd627 19#include <dm.h>
4bfd1f5d 20#include <env.h>
f3998fdc 21#include <env_internal.h>
1938f4a5 22#include <fdtdec.h>
f828bf25 23#include <fs.h>
db41d65a 24#include <hang.h>
e4fef6cf 25#include <i2c.h>
67c4e9f8 26#include <init.h>
1938f4a5 27#include <initcall.h>
3c1ecde4 28#include <lcd.h>
f7ae49fc 29#include <log.h>
fb5cf7f1 30#include <malloc.h>
0eb25b61 31#include <mapmem.h>
a733b06b 32#include <os.h>
1938f4a5 33#include <post.h>
e47b2d67 34#include <relocate.h>
b03e0510 35#include <serial.h>
b0edea3c
SG
36#ifdef CONFIG_SPL
37#include <spl.h>
38#endif
c5d4001a 39#include <status_led.h>
23471aed 40#include <sysreset.h>
1057e6cf 41#include <timer.h>
71c52dba 42#include <trace.h>
5a541945 43#include <video.h>
e4fef6cf 44#include <watchdog.h>
90526e9f 45#include <asm/cache.h>
b885d02e
SG
46#ifdef CONFIG_MACH_TYPE
47#include <asm/mach-types.h>
48#endif
1fbf97dc
SG
49#if defined(CONFIG_MP) && defined(CONFIG_PPC)
50#include <asm/mp.h>
51#endif
1938f4a5
SG
52#include <asm/io.h>
53#include <asm/sections.h>
ab7cd627 54#include <dm/root.h>
056285fd 55#include <linux/errno.h>
1938f4a5
SG
56
57/*
58 * Pointer to initial global data area
59 *
60 * Here we initialize it if needed.
61 */
62#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
63#undef XTRN_DECLARE_GLOBAL_DATA_PTR
64#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
16ef1474 65DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
1938f4a5
SG
66#else
67DECLARE_GLOBAL_DATA_PTR;
68#endif
69
70/*
4c509343 71 * TODO([email protected]): IMO this code should be
1938f4a5
SG
72 * refactored to a single function, something like:
73 *
74 * void led_set_state(enum led_colour_t colour, int on);
75 */
76/************************************************************************
77 * Coloured LED functionality
78 ************************************************************************
79 * May be supplied by boards if desired
80 */
c5d4001a
JH
81__weak void coloured_LED_init(void) {}
82__weak void red_led_on(void) {}
83__weak void red_led_off(void) {}
84__weak void green_led_on(void) {}
85__weak void green_led_off(void) {}
86__weak void yellow_led_on(void) {}
87__weak void yellow_led_off(void) {}
88__weak void blue_led_on(void) {}
89__weak void blue_led_off(void) {}
1938f4a5
SG
90
91/*
92 * Why is gd allocated a register? Prior to reloc it might be better to
93 * just pass it around to each function in this file?
94 *
95 * After reloc one could argue that it is hardly used and doesn't need
96 * to be in a register. Or if it is it should perhaps hold pointers to all
97 * global data for all modules, so that post-reloc we can avoid the massive
98 * literal pool we get on ARM. Or perhaps just encourage each module to use
99 * a structure...
100 */
101
d54d7eb9 102#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
e4fef6cf
SG
103static int init_func_watchdog_init(void)
104{
ea3310e8
TR
105# if defined(CONFIG_HW_WATCHDOG) && \
106 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
1473f6ac 107 defined(CONFIG_SH) || \
46d7a3b3 108 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
14a380a8 109 defined(CONFIG_IMX_WATCHDOG))
d54d7eb9 110 hw_watchdog_init();
e4fef6cf 111 puts(" Watchdog enabled\n");
ba169d98 112# endif
e4fef6cf
SG
113 WATCHDOG_RESET();
114
115 return 0;
116}
117
118int init_func_watchdog_reset(void)
119{
120 WATCHDOG_RESET();
121
122 return 0;
123}
124#endif /* CONFIG_WATCHDOG */
125
dd2a6cd0 126__weak void board_add_ram_info(int use_default)
e4fef6cf
SG
127{
128 /* please define platform specific board_add_ram_info() */
129}
130
1938f4a5
SG
131static int init_baud_rate(void)
132{
bfebc8c9 133 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
1938f4a5
SG
134 return 0;
135}
136
137static int display_text_info(void)
138{
9b217498 139#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
9fdee7d7 140 ulong bss_start, bss_end, text_base;
1938f4a5 141
632efa74
SG
142 bss_start = (ulong)&__bss_start;
143 bss_end = (ulong)&__bss_end;
b60eff31 144
d54d7eb9 145#ifdef CONFIG_SYS_TEXT_BASE
9fdee7d7 146 text_base = CONFIG_SYS_TEXT_BASE;
d54d7eb9 147#else
9fdee7d7 148 text_base = CONFIG_SYS_MONITOR_BASE;
d54d7eb9 149#endif
9fdee7d7
DS
150
151 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
16ef1474 152 text_base, bss_start, bss_end);
a733b06b 153#endif
1938f4a5 154
1938f4a5
SG
155 return 0;
156}
157
23471aed
MS
158#ifdef CONFIG_SYSRESET
159static int print_resetinfo(void)
160{
161 struct udevice *dev;
162 char status[256];
163 int ret;
164
165 ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
166 if (ret) {
167 debug("%s: No sysreset device found (error: %d)\n",
168 __func__, ret);
169 /* Not all boards have sysreset drivers available during early
170 * boot, so don't fail if one can't be found.
171 */
172 return 0;
173 }
174
175 if (!sysreset_get_status(dev, status, sizeof(status)))
176 printf("%s", status);
177
178 return 0;
179}
180#endif
181
5d6c61ac
MS
182#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
183static int print_cpuinfo(void)
184{
185 struct udevice *dev;
186 char desc[512];
187 int ret;
188
f5b66af2
YL
189 dev = cpu_get_current_dev();
190 if (!dev) {
191 debug("%s: Could not get CPU device\n",
192 __func__);
193 return -ENODEV;
5d6c61ac
MS
194 }
195
196 ret = cpu_get_desc(dev, desc, sizeof(desc));
197 if (ret) {
198 debug("%s: Could not get CPU description (err = %d)\n",
199 dev->name, ret);
200 return ret;
201 }
202
ecfe6633 203 printf("CPU: %s\n", desc);
5d6c61ac
MS
204
205 return 0;
206}
207#endif
208
1938f4a5
SG
209static int announce_dram_init(void)
210{
211 puts("DRAM: ");
212 return 0;
213}
214
215static int show_dram_config(void)
216{
fa39ffe5 217 unsigned long long size;
1938f4a5
SG
218 int i;
219
220 debug("\nRAM Configuration:\n");
221 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
222 size += gd->bd->bi_dram[i].size;
715f599f
BM
223 debug("Bank #%d: %llx ", i,
224 (unsigned long long)(gd->bd->bi_dram[i].start));
1938f4a5
SG
225#ifdef DEBUG
226 print_size(gd->bd->bi_dram[i].size, "\n");
227#endif
228 }
229 debug("\nDRAM: ");
1938f4a5 230
e4fef6cf
SG
231 print_size(size, "");
232 board_add_ram_info(0);
233 putc('\n');
1938f4a5
SG
234
235 return 0;
236}
237
76b00aca 238__weak int dram_init_banksize(void)
1938f4a5 239{
f120aa75 240 gd->bd->bi_dram[0].start = gd->ram_base;
1938f4a5 241 gd->bd->bi_dram[0].size = get_effective_memsize();
76b00aca
SG
242
243 return 0;
1938f4a5
SG
244}
245
69153988 246#if defined(CONFIG_SYS_I2C)
e4fef6cf
SG
247static int init_func_i2c(void)
248{
249 puts("I2C: ");
815a76f2 250 i2c_init_all();
e4fef6cf
SG
251 puts("ready\n");
252 return 0;
253}
254#endif
255
1fab98fb
RB
256#if defined(CONFIG_VID)
257__weak int init_func_vid(void)
258{
259 return 0;
260}
261#endif
262
1938f4a5
SG
263static int setup_mon_len(void)
264{
e945f6dc 265#if defined(__ARM__) || defined(__MICROBLAZE__)
b60eff31 266 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
9b217498 267#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
a733b06b 268 gd->mon_len = (ulong)&_end - (ulong)_init;
ea3310e8 269#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
d54d7eb9 270 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
068feb9b 271#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
2e88bb28 272 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
b0b35953 273#elif defined(CONFIG_SYS_MONITOR_BASE)
e4fef6cf
SG
274 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
275 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
632efa74 276#endif
1938f4a5
SG
277 return 0;
278}
279
b0edea3c
SG
280static int setup_spl_handoff(void)
281{
282#if CONFIG_IS_ENABLED(HANDOFF)
283 gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
284 sizeof(struct spl_handoff));
285 debug("Found SPL hand-off info %p\n", gd->spl_handoff);
286#endif
287
288 return 0;
289}
290
1938f4a5
SG
291__weak int arch_cpu_init(void)
292{
293 return 0;
294}
295
8ebf5069
PB
296__weak int mach_cpu_init(void)
297{
298 return 0;
299}
300
1938f4a5
SG
301/* Get the top of usable RAM */
302__weak ulong board_get_usable_ram_top(ulong total_size)
303{
54280962 304#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
1e4d11a5 305 /*
4c509343 306 * Detect whether we have so much RAM that it goes past the end of our
1e4d11a5
SW
307 * 32-bit address space. If so, clip the usable RAM so it doesn't.
308 */
309 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
310 /*
311 * Will wrap back to top of 32-bit space when reservations
312 * are made.
313 */
314 return 0;
315#endif
1938f4a5
SG
316 return gd->ram_top;
317}
318
319static int setup_dest_addr(void)
320{
321 debug("Monitor len: %08lX\n", gd->mon_len);
322 /*
323 * Ram is setup, size stored in gd !!
324 */
325 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
36cc0de0 326#if defined(CONFIG_SYS_MEM_TOP_HIDE)
1938f4a5
SG
327 /*
328 * Subtract specified amount of memory to hide so that it won't
329 * get "touched" at all by U-Boot. By fixing up gd->ram_size
330 * the Linux kernel should now get passed the now "corrected"
36cc0de0
YS
331 * memory size and won't touch it either. This should work
332 * for arch/ppc and arch/powerpc. Only Linux board ports in
333 * arch/powerpc with bootwrapper support, that recalculate the
334 * memory size from the SDRAM controller setup will have to
335 * get fixed.
1938f4a5 336 */
36cc0de0
YS
337 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
338#endif
1938f4a5 339#ifdef CONFIG_SYS_SDRAM_BASE
1473b12a 340 gd->ram_base = CONFIG_SYS_SDRAM_BASE;
1938f4a5 341#endif
1473b12a 342 gd->ram_top = gd->ram_base + get_effective_memsize();
1938f4a5 343 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
a0ba279a 344 gd->relocaddr = gd->ram_top;
1938f4a5 345 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
ec3b4820 346#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
e4fef6cf
SG
347 /*
348 * We need to make sure the location we intend to put secondary core
349 * boot code is reserved and not used by any part of u-boot
350 */
a0ba279a
MY
351 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
352 gd->relocaddr = determine_mp_bootpg(NULL);
353 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
e4fef6cf
SG
354 }
355#endif
1938f4a5
SG
356 return 0;
357}
358
1938f4a5
SG
359#ifdef CONFIG_PRAM
360/* reserve protected RAM */
361static int reserve_pram(void)
362{
363 ulong reg;
364
bfebc8c9 365 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
a0ba279a 366 gd->relocaddr -= (reg << 10); /* size is in kB */
1938f4a5 367 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
a0ba279a 368 gd->relocaddr);
1938f4a5
SG
369 return 0;
370}
371#endif /* CONFIG_PRAM */
372
373/* Round memory pointer down to next 4 kB limit */
374static int reserve_round_4k(void)
375{
a0ba279a 376 gd->relocaddr &= ~(4096 - 1);
1938f4a5
SG
377 return 0;
378}
379
79926e4f
OP
380__weak int arch_reserve_mmu(void)
381{
382 return 0;
383}
384
5a541945
SG
385static int reserve_video(void)
386{
0f079eb5 387#ifdef CONFIG_DM_VIDEO
5a541945
SG
388 ulong addr;
389 int ret;
390
391 addr = gd->relocaddr;
392 ret = video_reserve(&addr);
393 if (ret)
394 return ret;
5630d2fb
SG
395 debug("Reserving %luk for video at: %08lx\n",
396 (unsigned long)gd->relocaddr - addr, addr);
5a541945 397 gd->relocaddr = addr;
0f079eb5 398#elif defined(CONFIG_LCD)
5a541945 399# ifdef CONFIG_FB_ADDR
1938f4a5 400 gd->fb_base = CONFIG_FB_ADDR;
5a541945 401# else
1938f4a5 402 /* reserve memory for LCD display (always full pages) */
a0ba279a
MY
403 gd->relocaddr = lcd_setmem(gd->relocaddr);
404 gd->fb_base = gd->relocaddr;
5a541945 405# endif /* CONFIG_FB_ADDR */
0f079eb5 406#endif
e4fef6cf
SG
407
408 return 0;
409}
e4fef6cf 410
8703ef3f
SG
411static 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);
7ea33579
HS
416 debug("Reserving %luk for trace data at: %08lx\n",
417 (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
8703ef3f
SG
418#endif
419
420 return 0;
421}
422
1938f4a5
SG
423static int reserve_uboot(void)
424{
ff2b2ba8
AB
425 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
436
437 debug("Reserving %ldk for U-Boot at: %08lx\n",
438 gd->mon_len >> 10, gd->relocaddr);
439 }
a0ba279a
MY
440
441 gd->start_addr_sp = gd->relocaddr;
442
1938f4a5
SG
443 return 0;
444}
445
65c141eb
PD
446/*
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
5f7adb5b
VM
457#ifdef CONFIG_SYS_NONCACHED_MEMORY
458static int reserve_noncached(void)
459{
5e0404ff
SW
460 /*
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);
5f7adb5b
VM
472 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
1938f4a5
SG
479/* reserve memory for malloc() area */
480static int reserve_malloc(void)
481{
65c141eb 482 gd->start_addr_sp = reserve_stack_aligned(TOTAL_MALLOC_LEN);
1938f4a5 483 debug("Reserving %dk for malloc() at: %08lx\n",
16ef1474 484 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
5f7adb5b
VM
485#ifdef CONFIG_SYS_NONCACHED_MEMORY
486 reserve_noncached();
487#endif
488
1938f4a5
SG
489 return 0;
490}
491
492/* (permanently) allocate a Board Info struct */
493static int reserve_board(void)
494{
d54d7eb9 495 if (!gd->bd) {
b75d8dc5
MY
496 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));
d54d7eb9 500 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
b75d8dc5 501 sizeof(struct bd_info), gd->start_addr_sp);
d54d7eb9 502 }
1938f4a5
SG
503 return 0;
504}
505
506static int setup_machine(void)
507{
508#ifdef CONFIG_MACH_TYPE
509 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
510#endif
511 return 0;
512}
513
514static int reserve_global_data(void)
515{
65c141eb 516 gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t));
a0ba279a 517 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
1938f4a5 518 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
16ef1474 519 sizeof(gd_t), gd->start_addr_sp);
1938f4a5
SG
520 return 0;
521}
522
523static int reserve_fdt(void)
524{
e9acb9ea 525#ifndef CONFIG_OF_EMBED
1938f4a5 526 /*
4c509343 527 * If the device tree is sitting immediately above our image then we
1938f4a5
SG
528 * must relocate it. If it is embedded in the data section, then it
529 * will be relocated with other data.
530 */
531 if (gd->fdt_blob) {
b8fd54d6 532 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
1938f4a5 533
65c141eb 534 gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
a0ba279a 535 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
a733b06b 536 debug("Reserving %lu Bytes for FDT at: %08lx\n",
a0ba279a 537 gd->fdt_size, gd->start_addr_sp);
1938f4a5 538 }
e9acb9ea 539#endif
1938f4a5
SG
540
541 return 0;
542}
543
25e7dc6a
SG
544static int reserve_bootstage(void)
545{
546#ifdef CONFIG_BOOTSTAGE
547 int size = bootstage_get_size();
548
65c141eb 549 gd->start_addr_sp = reserve_stack_aligned(size);
25e7dc6a
SG
550 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
551 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
552 gd->start_addr_sp);
553#endif
554
555 return 0;
556}
557
d6f87712 558__weak int arch_reserve_stacks(void)
1938f4a5 559{
68145d4c
AB
560 return 0;
561}
8cae8a68 562
68145d4c
AB
563static int reserve_stacks(void)
564{
565 /* make stack pointer 16-byte aligned */
65c141eb 566 gd->start_addr_sp = reserve_stack_aligned(16);
1938f4a5
SG
567
568 /*
4c509343 569 * let the architecture-specific code tailor gd->start_addr_sp and
68145d4c 570 * gd->irq_sp
1938f4a5 571 */
68145d4c 572 return arch_reserve_stacks();
1938f4a5
SG
573}
574
f0293d33
SG
575static int reserve_bloblist(void)
576{
577#ifdef CONFIG_BLOBLIST
4a08fae1
SG
578 /* Align to a 4KB boundary for easier reading of addresses */
579 gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp - CONFIG_BLOBLIST_SIZE,
580 0x1000);
f0293d33
SG
581 gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
582#endif
583
584 return 0;
585}
586
1938f4a5
SG
587static int display_new_sp(void)
588{
a0ba279a 589 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
1938f4a5
SG
590
591 return 0;
592}
593
81e7cb1e 594__weak int arch_setup_bdinfo(void)
ba743103
OP
595{
596 return 0;
597}
598
81e7cb1e
OP
599int setup_bdinfo(void)
600{
a4aa1889
OP
601 struct bd_info *bd = gd->bd;
602
49122242
OP
603 if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
604 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
605 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
606 }
607
81e7cb1e
OP
608 return arch_setup_bdinfo();
609}
610
1938f4a5
SG
611#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
1938f4a5
SG
621static int reloc_fdt(void)
622{
e9acb9ea 623#ifndef CONFIG_OF_EMBED
f05ad9ba
SG
624 if (gd->flags & GD_FLG_SKIP_RELOC)
625 return 0;
1938f4a5 626 if (gd->new_fdt) {
53007fc1 627 memcpy(gd->new_fdt, gd->fdt_blob, fdt_totalsize(gd->fdt_blob));
1938f4a5
SG
628 gd->fdt_blob = gd->new_fdt;
629 }
e9acb9ea 630#endif
1938f4a5
SG
631
632 return 0;
633}
634
25e7dc6a
SG
635static int reloc_bootstage(void)
636{
637#ifdef CONFIG_BOOTSTAGE
638 if (gd->flags & GD_FLG_SKIP_RELOC)
639 return 0;
640 if (gd->new_bootstage) {
641 int size = bootstage_get_size();
642
643 debug("Copying bootstage from %p to %p, size %x\n",
644 gd->bootstage, gd->new_bootstage, size);
645 memcpy(gd->new_bootstage, gd->bootstage, size);
646 gd->bootstage = gd->new_bootstage;
ac9cd480 647 bootstage_relocate();
25e7dc6a
SG
648 }
649#endif
650
651 return 0;
652}
653
f0293d33
SG
654static int reloc_bloblist(void)
655{
656#ifdef CONFIG_BLOBLIST
657 if (gd->flags & GD_FLG_SKIP_RELOC)
658 return 0;
659 if (gd->new_bloblist) {
660 int size = CONFIG_BLOBLIST_SIZE;
661
662 debug("Copying bloblist from %p to %p, size %x\n",
663 gd->bloblist, gd->new_bloblist, size);
664 memcpy(gd->new_bloblist, gd->bloblist, size);
665 gd->bloblist = gd->new_bloblist;
666 }
667#endif
668
669 return 0;
670}
671
1938f4a5
SG
672static int setup_reloc(void)
673{
f05ad9ba
SG
674 if (gd->flags & GD_FLG_SKIP_RELOC) {
675 debug("Skipping relocation due to flag\n");
676 return 0;
677 }
678
d54d7eb9 679#ifdef CONFIG_SYS_TEXT_BASE
53207bfd
LW
680#ifdef ARM
681 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
682#elif defined(CONFIG_M68K)
e310b93e 683 /*
684 * On all ColdFire arch cpu, monitor code starts always
685 * just after the default vector table location, so at 0x400
686 */
687 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
001d1885 688#elif !defined(CONFIG_SANDBOX)
53207bfd 689 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
e310b93e 690#endif
d54d7eb9 691#endif
1938f4a5
SG
692 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
693
694 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
a733b06b 695 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
a0ba279a
MY
696 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
697 gd->start_addr_sp);
1938f4a5
SG
698
699 return 0;
700}
701
2a792753 702#ifdef CONFIG_OF_BOARD_FIXUP
703static int fix_fdt(void)
704{
705 return board_fix_fdt((void *)gd->fdt_blob);
706}
707#endif
708
1938f4a5 709/* ARM calls relocate_code from its crt0.S */
530f27ea
SG
710#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
711 !CONFIG_IS_ENABLED(X86_64)
1938f4a5
SG
712
713static int jump_to_copy(void)
714{
f05ad9ba
SG
715 if (gd->flags & GD_FLG_SKIP_RELOC)
716 return 0;
48a33806
SG
717 /*
718 * x86 is special, but in a nice way. It uses a trampoline which
719 * enables the dcache if possible.
720 *
721 * For now, other archs use relocate_code(), which is implemented
722 * similarly for all archs. When we do generic relocation, hopefully
723 * we can make all archs enable the dcache prior to relocation.
724 */
3fb80163 725#if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a33806
SG
726 /*
727 * SDRAM and console are now initialised. The final stack can now
728 * be setup in SDRAM. Code execution will continue in Flash, but
729 * with the stack in SDRAM and Global Data in temporary memory
730 * (CPU cache)
731 */
f0c7d9c7 732 arch_setup_gd(gd->new_gd);
48a33806
SG
733 board_init_f_r_trampoline(gd->start_addr_sp);
734#else
a0ba279a 735 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
48a33806 736#endif
1938f4a5
SG
737
738 return 0;
739}
740#endif
741
742/* Record the board_init_f() bootstage (after arch_cpu_init()) */
b383d6c0 743static int initf_bootstage(void)
1938f4a5 744{
baa7d345
SG
745 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
746 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
b383d6c0
SG
747 int ret;
748
824bb1b4 749 ret = bootstage_init(!from_spl);
b383d6c0
SG
750 if (ret)
751 return ret;
824bb1b4
SG
752 if (from_spl) {
753 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
754 CONFIG_BOOTSTAGE_STASH_SIZE);
755
756 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
757 if (ret && ret != -ENOENT) {
758 debug("Failed to unstash bootstage: err=%d\n", ret);
759 return ret;
760 }
761 }
b383d6c0 762
1938f4a5
SG
763 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
764
765 return 0;
766}
767
9854a874
SG
768static int initf_console_record(void)
769{
4e81920b
OP
770 if (IS_ENABLED(CONFIG_CONSOLE_RECORD_INIT_F))
771 return console_record_init();
772
9854a874 773 return 0;
9854a874
SG
774}
775
ab7cd627
SG
776static int initf_dm(void)
777{
f1896c45 778#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
ab7cd627
SG
779 int ret;
780
b67eefdb 781 bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
ab7cd627 782 ret = dm_init_and_scan(true);
b67eefdb 783 bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
ab7cd627
SG
784 if (ret)
785 return ret;
786#endif
1057e6cf
SG
787#ifdef CONFIG_TIMER_EARLY
788 ret = dm_timer_init();
789 if (ret)
790 return ret;
791#endif
ab7cd627
SG
792
793 return 0;
794}
795
146251f8
SG
796/* Architecture-specific memory reservation */
797__weak int reserve_arch(void)
798{
799 return 0;
800}
801
d4c671cc
SG
802__weak int arch_cpu_init_dm(void)
803{
804 return 0;
805}
806
016e4ae7
OP
807__weak int checkcpu(void)
808{
809 return 0;
810}
811
fbf9c154
OP
812__weak int clear_bss(void)
813{
814 return 0;
815}
816
4acff452 817static const init_fnc_t init_sequence_f[] = {
1938f4a5 818 setup_mon_len,
b45122fd 819#ifdef CONFIG_OF_CONTROL
0879361f 820 fdtdec_setup,
b45122fd 821#endif
7ef8e9b0 822#ifdef CONFIG_TRACE_EARLY
71c52dba 823 trace_early_init,
d210718d 824#endif
768e0f52 825 initf_malloc,
af1bc0cf 826 log_init,
5ac44a55 827 initf_bootstage, /* uses its own timer, so does not need DM */
f0293d33
SG
828#ifdef CONFIG_BLOBLIST
829 bloblist_init,
830#endif
b0edea3c 831 setup_spl_handoff,
9854a874 832 initf_console_record,
671549e5
SG
833#if defined(CONFIG_HAVE_FSP)
834 arch_fsp_init,
e4fef6cf 835#endif
1938f4a5 836 arch_cpu_init, /* basic arch cpu dependent setup */
8ebf5069 837 mach_cpu_init, /* SoC/machine dependent CPU setup */
3ea0953d 838 initf_dm,
d4c671cc 839 arch_cpu_init_dm,
1938f4a5
SG
840#if defined(CONFIG_BOARD_EARLY_INIT_F)
841 board_early_init_f,
842#endif
727e94a4 843#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
c252c068 844 /* get CPU and bus clocks according to the environment variable */
e4fef6cf 845 get_clocks, /* get CPU and bus clocks (etc.) */
1793e782 846#endif
0ce45287 847#if !defined(CONFIG_M68K)
1938f4a5 848 timer_init, /* initialize timer */
0ce45287 849#endif
e4fef6cf
SG
850#if defined(CONFIG_BOARD_POSTCLK_INIT)
851 board_postclk_init,
1938f4a5
SG
852#endif
853 env_init, /* initialize environment */
854 init_baud_rate, /* initialze baudrate settings */
855 serial_init, /* serial communications setup */
856 console_init_f, /* stage 1 init of console */
857 display_options, /* say that we are here */
858 display_text_info, /* show debugging info if required */
e4fef6cf 859 checkcpu,
23471aed
MS
860#if defined(CONFIG_SYSRESET)
861 print_resetinfo,
862#endif
cc664000 863#if defined(CONFIG_DISPLAY_CPUINFO)
1938f4a5 864 print_cpuinfo, /* display cpu info (and speed) */
cc664000 865#endif
af9e6ad4
CJF
866#if defined(CONFIG_DTB_RESELECT)
867 embedded_dtb_select,
868#endif
1938f4a5 869#if defined(CONFIG_DISPLAY_BOARDINFO)
0365ffcc 870 show_board_info,
e4fef6cf
SG
871#endif
872 INIT_FUNC_WATCHDOG_INIT
873#if defined(CONFIG_MISC_INIT_F)
874 misc_init_f,
875#endif
876 INIT_FUNC_WATCHDOG_RESET
69153988 877#if defined(CONFIG_SYS_I2C)
e4fef6cf
SG
878 init_func_i2c,
879#endif
1fab98fb
RB
880#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
881 init_func_vid,
1938f4a5
SG
882#endif
883 announce_dram_init,
1938f4a5 884 dram_init, /* configure available RAM banks */
e4fef6cf
SG
885#ifdef CONFIG_POST
886 post_init_f,
887#endif
888 INIT_FUNC_WATCHDOG_RESET
889#if defined(CONFIG_SYS_DRAM_TEST)
890 testdram,
891#endif /* CONFIG_SYS_DRAM_TEST */
892 INIT_FUNC_WATCHDOG_RESET
893
1938f4a5
SG
894#ifdef CONFIG_POST
895 init_post,
896#endif
e4fef6cf 897 INIT_FUNC_WATCHDOG_RESET
1938f4a5
SG
898 /*
899 * Now that we have DRAM mapped and working, we can
900 * relocate the code and continue running from DRAM.
901 *
902 * Reserve memory at end of RAM for (top down in that order):
903 * - area that won't get touched by U-Boot and Linux (optional)
904 * - kernel log buffer
905 * - protected RAM
906 * - LCD framebuffer
907 * - monitor code
908 * - board info struct
909 */
910 setup_dest_addr,
313981c2
PP
911#ifdef CONFIG_OF_BOARD_FIXUP
912 fix_fdt,
913#endif
1938f4a5
SG
914#ifdef CONFIG_PRAM
915 reserve_pram,
916#endif
917 reserve_round_4k,
79926e4f 918 arch_reserve_mmu,
5a541945 919 reserve_video,
8703ef3f 920 reserve_trace,
1938f4a5
SG
921 reserve_uboot,
922 reserve_malloc,
923 reserve_board,
924 setup_machine,
925 reserve_global_data,
926 reserve_fdt,
25e7dc6a 927 reserve_bootstage,
f0293d33 928 reserve_bloblist,
146251f8 929 reserve_arch,
1938f4a5 930 reserve_stacks,
76b00aca 931 dram_init_banksize,
1938f4a5 932 show_dram_config,
e4fef6cf 933 INIT_FUNC_WATCHDOG_RESET
1532885c 934 setup_bdinfo,
1938f4a5 935 display_new_sp,
e4fef6cf 936 INIT_FUNC_WATCHDOG_RESET
1938f4a5 937 reloc_fdt,
25e7dc6a 938 reloc_bootstage,
f0293d33 939 reloc_bloblist,
1938f4a5 940 setup_reloc,
3fb80163 941#if defined(CONFIG_X86) || defined(CONFIG_ARC)
313aef37 942 copy_uboot_to_ram,
313aef37
SG
943 do_elf_reloc_fixups,
944#endif
de5e5cea 945 clear_bss,
530f27ea
SG
946#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
947 !CONFIG_IS_ENABLED(X86_64)
1938f4a5
SG
948 jump_to_copy,
949#endif
950 NULL,
951};
952
953void board_init_f(ulong boot_flags)
954{
1938f4a5 955 gd->flags = boot_flags;
9aed5a27 956 gd->have_console = 0;
1938f4a5
SG
957
958 if (initcall_run_list(init_sequence_f))
959 hang();
960
9b217498 961#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
264d298f
AB
962 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
963 !defined(CONFIG_ARC)
1938f4a5
SG
964 /* NOTREACHED - jump_to_copy() does not return */
965 hang();
966#endif
967}
968
3fb80163 969#if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a33806
SG
970/*
971 * For now this code is only used on x86.
972 *
973 * init_sequence_f_r is the list of init functions which are run when
974 * U-Boot is executing from Flash with a semi-limited 'C' environment.
975 * The following limitations must be considered when implementing an
976 * '_f_r' function:
977 * - 'static' variables are read-only
978 * - Global Data (gd->xxx) is read/write
979 *
980 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
981 * supported). It _should_, if possible, copy global data to RAM and
982 * initialise the CPU caches (to speed up the relocation process)
983 *
984 * NOTE: At present only x86 uses this route, but it is intended that
985 * all archs will move to this when generic relocation is implemented.
986 */
4acff452 987static const init_fnc_t init_sequence_f_r[] = {
530f27ea 988#if !CONFIG_IS_ENABLED(X86_64)
48a33806 989 init_cache_f_r,
530f27ea 990#endif
48a33806
SG
991
992 NULL,
993};
994
995void board_init_f_r(void)
996{
997 if (initcall_run_list(init_sequence_f_r))
998 hang();
999
e4d6ab0c
SG
1000 /*
1001 * The pre-relocation drivers may be using memory that has now gone
1002 * away. Mark serial as unavailable - this will fall back to the debug
1003 * UART if available.
af1bc0cf
SG
1004 *
1005 * Do the same with log drivers since the memory may not be available.
e4d6ab0c 1006 */
af1bc0cf 1007 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
5ee94b4f
SG
1008#ifdef CONFIG_TIMER
1009 gd->timer = NULL;
1010#endif
e4d6ab0c 1011
48a33806
SG
1012 /*
1013 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1014 * Transfer execution from Flash to RAM by calculating the address
1015 * of the in-RAM copy of board_init_r() and calling it
1016 */
7bf9f20d 1017 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
48a33806
SG
1018
1019 /* NOTREACHED - board_init_r() does not return */
1020 hang();
1021}
5bcd19aa 1022#endif /* CONFIG_X86 */
This page took 0.467017 seconds and 4 git commands to generate.