1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2002-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Marius Groeger <mgroeger@sysgo.de>
14 #include <bootstage.h>
15 #include <clock_legacy.h>
20 #include <display_options.h>
23 #include <env_internal.h>
39 #include <status_led.h>
47 #include <asm/cache.h>
48 #include <asm/global_data.h>
50 #include <asm/sections.h>
52 #include <linux/errno.h>
53 #include <linux/log2.h>
55 DECLARE_GLOBAL_DATA_PTR
;
58 * TODO(sjg@chromium.org): IMO this code should be
59 * refactored to a single function, something like:
61 * void led_set_state(enum led_colour_t colour, int on);
63 /************************************************************************
64 * Coloured LED functionality
65 ************************************************************************
66 * May be supplied by boards if desired
68 __weak
void coloured_LED_init(void) {}
69 __weak
void red_led_on(void) {}
70 __weak
void red_led_off(void) {}
71 __weak
void green_led_on(void) {}
72 __weak
void green_led_off(void) {}
73 __weak
void yellow_led_on(void) {}
74 __weak
void yellow_led_off(void) {}
75 __weak
void blue_led_on(void) {}
76 __weak
void blue_led_off(void) {}
79 * Why is gd allocated a register? Prior to reloc it might be better to
80 * just pass it around to each function in this file?
82 * After reloc one could argue that it is hardly used and doesn't need
83 * to be in a register. Or if it is it should perhaps hold pointers to all
84 * global data for all modules, so that post-reloc we can avoid the massive
85 * literal pool we get on ARM. Or perhaps just encourage each module to use
89 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
90 static int init_func_watchdog_init(void)
92 # if defined(CONFIG_HW_WATCHDOG) && \
93 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
94 defined(CONFIG_SH) || \
95 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
96 defined(CONFIG_IMX_WATCHDOG))
98 puts(" Watchdog enabled\n");
105 int init_func_watchdog_reset(void)
111 #endif /* CONFIG_WATCHDOG */
113 __weak
void board_add_ram_info(int use_default
)
115 /* please define platform specific board_add_ram_info() */
118 static int init_baud_rate(void)
120 gd
->baudrate
= env_get_ulong("baudrate", 10, CONFIG_BAUDRATE
);
124 static int display_text_info(void)
126 #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
127 ulong bss_start
, bss_end
, text_base
;
129 bss_start
= (ulong
)__bss_start
;
130 bss_end
= (ulong
)__bss_end
;
132 #ifdef CONFIG_TEXT_BASE
133 text_base
= CONFIG_TEXT_BASE
;
135 text_base
= CONFIG_SYS_MONITOR_BASE
;
138 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
139 text_base
, bss_start
, bss_end
);
145 #ifdef CONFIG_SYSRESET
146 static int print_resetinfo(void)
150 bool status_printed
= false;
154 * Not all boards have sysreset drivers available during early
155 * boot, so don't fail if one can't be found.
157 for (ret
= uclass_first_device_check(UCLASS_SYSRESET
, &dev
); dev
;
158 ret
= uclass_next_device_check(&dev
)) {
160 debug("%s: %s sysreset device (error: %d)\n",
161 __func__
, dev
->name
, ret
);
165 if (!sysreset_get_status(dev
, status
, sizeof(status
))) {
166 printf("%s%s", status_printed
? " " : "", status
);
167 status_printed
= true;
177 #if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
178 static int print_cpuinfo(void)
184 dev
= cpu_get_current_dev();
186 debug("%s: Could not get CPU device\n",
191 ret
= cpu_get_desc(dev
, desc
, sizeof(desc
));
193 debug("%s: Could not get CPU description (err = %d)\n",
198 printf("CPU: %s\n", desc
);
204 static int announce_dram_init(void)
211 * From input size calculate its nearest rounded unit scale (multiply of 2^10)
212 * and value in calculated unit scale multiplied by 10 (as fractional fixed
213 * point number with one decimal digit), which is human natural format,
214 * same what uses print_size() function for displaying. Mathematically it is:
215 * round_nearest(val * 2^scale) = size * 10; where: 10 <= val < 10240.
217 * For example for size=87654321 we calculate scale=20 and val=836 which means
218 * that input has natural human format 83.6 M (mega = 2^20).
220 #define compute_size_scale_val(size, scale, val) do { \
221 scale = ilog2(size) / 10 * 10; \
222 val = (10 * size + ((1ULL << scale) >> 1)) >> scale; \
223 if (val == 10240) { val = 10; scale += 10; } \
227 * Check if the sizes in their natural units written in decimal format with
228 * one fraction number are same.
230 static int sizes_near(unsigned long long size1
, unsigned long long size2
)
232 unsigned int size1_scale
, size1_val
, size2_scale
, size2_val
;
234 compute_size_scale_val(size1
, size1_scale
, size1_val
);
235 compute_size_scale_val(size2
, size2_scale
, size2_val
);
237 return size1_scale
== size2_scale
&& size1_val
== size2_val
;
240 static int show_dram_config(void)
242 unsigned long long size
;
245 debug("\nRAM Configuration:\n");
246 for (i
= size
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
247 size
+= gd
->bd
->bi_dram
[i
].size
;
248 debug("Bank #%d: %llx ", i
,
249 (unsigned long long)(gd
->bd
->bi_dram
[i
].start
));
251 print_size(gd
->bd
->bi_dram
[i
].size
, "\n");
256 print_size(gd
->ram_size
, "");
257 if (!sizes_near(gd
->ram_size
, size
)) {
259 print_size(size
, ")");
261 board_add_ram_info(0);
267 __weak
int dram_init_banksize(void)
269 gd
->bd
->bi_dram
[0].start
= gd
->ram_base
;
270 gd
->bd
->bi_dram
[0].size
= get_effective_memsize();
275 #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
276 static int init_func_i2c(void)
285 static int setup_mon_len(void)
287 #if defined(CONFIG_ARCH_NEXELL)
288 gd
->mon_len
= (ulong
)__bss_end
- (ulong
)__image_copy_start
;
289 #elif defined(__ARM__) || defined(__MICROBLAZE__)
290 gd
->mon_len
= (ulong
)__bss_end
- (ulong
)_start
;
291 #elif defined(CONFIG_SANDBOX) && !defined(__riscv)
292 gd
->mon_len
= (ulong
)_end
- (ulong
)_init
;
293 #elif defined(CONFIG_SANDBOX)
294 /* gcc does not provide _init in crti.o on RISC-V */
296 #elif defined(CONFIG_EFI_APP)
297 gd
->mon_len
= (ulong
)_end
- (ulong
)_init
;
298 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
299 gd
->mon_len
= CONFIG_SYS_MONITOR_LEN
;
300 #elif defined(CONFIG_SH) || defined(CONFIG_RISCV)
301 gd
->mon_len
= (ulong
)(__bss_end
) - (ulong
)(_start
);
302 #elif defined(CONFIG_SYS_MONITOR_BASE)
303 /* TODO: use (ulong)__bss_end - (ulong)__text_start; ? */
304 gd
->mon_len
= (ulong
)__bss_end
- CONFIG_SYS_MONITOR_BASE
;
309 static int setup_spl_handoff(void)
311 #if CONFIG_IS_ENABLED(HANDOFF)
312 gd
->spl_handoff
= bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF
,
313 sizeof(struct spl_handoff
));
314 debug("Found SPL hand-off info %p\n", gd
->spl_handoff
);
320 __weak
int arch_cpu_init(void)
325 __weak
int mach_cpu_init(void)
330 /* Get the top of usable RAM */
331 __weak phys_addr_t
board_get_usable_ram_top(phys_size_t total_size
)
333 #if defined(CFG_SYS_SDRAM_BASE) && CFG_SYS_SDRAM_BASE > 0
335 * Detect whether we have so much RAM that it goes past the end of our
336 * 32-bit address space. If so, clip the usable RAM so it doesn't.
338 if (gd
->ram_top
< CFG_SYS_SDRAM_BASE
)
340 * Will wrap back to top of 32-bit space when reservations
348 __weak
int arch_setup_dest_addr(void)
353 static int setup_dest_addr(void)
355 debug("Monitor len: %08x\n", gd
->mon_len
);
357 * Ram is setup, size stored in gd !!
359 debug("Ram size: %08llX\n", (unsigned long long)gd
->ram_size
);
360 #if CONFIG_VAL(SYS_MEM_TOP_HIDE)
362 * Subtract specified amount of memory to hide so that it won't
363 * get "touched" at all by U-Boot. By fixing up gd->ram_size
364 * the Linux kernel should now get passed the now "corrected"
365 * memory size and won't touch it either. This should work
366 * for arch/ppc and arch/powerpc. Only Linux board ports in
367 * arch/powerpc with bootwrapper support, that recalculate the
368 * memory size from the SDRAM controller setup will have to
371 gd
->ram_size
-= CONFIG_SYS_MEM_TOP_HIDE
;
373 #ifdef CFG_SYS_SDRAM_BASE
374 gd
->ram_base
= CFG_SYS_SDRAM_BASE
;
376 gd
->ram_top
= gd
->ram_base
+ get_effective_memsize();
377 gd
->ram_top
= board_get_usable_ram_top(gd
->mon_len
);
378 gd
->relocaddr
= gd
->ram_top
;
379 debug("Ram top: %08llX\n", (unsigned long long)gd
->ram_top
);
381 return arch_setup_dest_addr();
385 /* reserve protected RAM */
386 static int reserve_pram(void)
390 reg
= env_get_ulong("pram", 10, CFG_PRAM
);
391 gd
->relocaddr
-= (reg
<< 10); /* size is in kB */
392 debug("Reserving %ldk for protected RAM at %08lx\n", reg
,
396 #endif /* CFG_PRAM */
398 /* Round memory pointer down to next 4 kB limit */
399 static int reserve_round_4k(void)
401 gd
->relocaddr
&= ~(4096 - 1);
405 __weak
int arch_reserve_mmu(void)
410 static int reserve_video_from_videoblob(void)
412 if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF
) && xpl_phase() > PHASE_SPL
) {
413 struct video_handoff
*ho
;
416 ho
= bloblist_find(BLOBLISTT_U_BOOT_VIDEO
, sizeof(*ho
));
418 return log_msg_ret("Missing video bloblist", -ENOENT
);
420 ret
= video_reserve_from_bloblist(ho
);
422 return log_msg_ret("Invalid Video handoff info", ret
);
424 /* Sanity check fb from blob is before current relocaddr */
425 if (likely(gd
->relocaddr
> (unsigned long)ho
->fb
))
426 gd
->relocaddr
= ho
->fb
;
433 * Check if any bloblist received specifying reserved areas from previous stage and adjust
434 * gd->relocaddr accordingly, so that we start reserving after pre-reserved areas
435 * from previous stage.
438 * IT is recommended that all bloblists from previous stage are reserved from ram_top
439 * as next stage will simply start reserving further regions after them.
441 static int setup_relocaddr_from_bloblist(void)
443 reserve_video_from_videoblob();
448 static int reserve_video(void)
450 if (CONFIG_IS_ENABLED(VIDEO
)) {
454 addr
= gd
->relocaddr
;
455 ret
= video_reserve(&addr
);
458 debug("Reserving %luk for video at: %08lx\n",
459 ((unsigned long)gd
->relocaddr
- addr
) >> 10, addr
);
460 gd
->relocaddr
= addr
;
466 static int reserve_trace(void)
469 gd
->relocaddr
-= CONFIG_TRACE_BUFFER_SIZE
;
470 gd
->trace_buff
= map_sysmem(gd
->relocaddr
, CONFIG_TRACE_BUFFER_SIZE
);
471 debug("Reserving %luk for trace data at: %08lx\n",
472 (unsigned long)CONFIG_TRACE_BUFFER_SIZE
>> 10, gd
->relocaddr
);
478 static int reserve_uboot(void)
481 * This should be the first place GD_FLG_SKIP_RELOC is read from.
482 * Set GD_FLG_SKIP_RELOC flag if CONFIG_SKIP_RELOCATE is enabled.
484 if (CONFIG_IS_ENABLED(SKIP_RELOCATE
))
485 gd
->flags
|= GD_FLG_SKIP_RELOC
;
487 if (!(gd
->flags
& GD_FLG_SKIP_RELOC
)) {
489 * reserve memory for U-Boot code, data & bss
490 * round down to next 4 kB limit
492 gd
->relocaddr
-= gd
->mon_len
;
493 gd
->relocaddr
&= ~(4096 - 1);
494 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
495 /* round down to next 64 kB limit so that IVPR stays aligned */
496 gd
->relocaddr
&= ~(65536 - 1);
499 debug("Reserving %dk for U-Boot at: %08lx\n",
500 gd
->mon_len
>> 10, gd
->relocaddr
);
503 gd
->start_addr_sp
= gd
->relocaddr
;
509 * reserve after start_addr_sp the requested size and make the stack pointer
510 * 16-byte aligned, this alignment is needed for cast on the reserved memory
511 * ref = x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
512 * = ARMv8 Instruction Set Overview: quad word, 16 bytes
514 static unsigned long reserve_stack_aligned(size_t size
)
516 return ALIGN_DOWN(gd
->start_addr_sp
- size
, 16);
519 #ifdef CONFIG_SYS_NONCACHED_MEMORY
520 static int reserve_noncached(void)
523 * The value of gd->start_addr_sp must match the value of
524 * mem_malloc_start calculated in board_r.c:initr_malloc(), which is
525 * passed to dlmalloc.c:mem_malloc_init() and then used by
526 * cache.c:noncached_init()
528 * These calculations must match the code in cache.c:noncached_init()
530 gd
->start_addr_sp
= ALIGN(gd
->start_addr_sp
, MMU_SECTION_SIZE
) -
532 gd
->start_addr_sp
-= ALIGN(CONFIG_SYS_NONCACHED_MEMORY
,
534 debug("Reserving %dM for noncached_alloc() at: %08lx\n",
535 CONFIG_SYS_NONCACHED_MEMORY
>> 20, gd
->start_addr_sp
);
541 /* reserve memory for malloc() area */
542 static int reserve_malloc(void)
544 gd
->start_addr_sp
= reserve_stack_aligned(TOTAL_MALLOC_LEN
);
545 debug("Reserving %dk for malloc() at: %08lx\n",
546 TOTAL_MALLOC_LEN
>> 10, gd
->start_addr_sp
);
547 #ifdef CONFIG_SYS_NONCACHED_MEMORY
554 /* (permanently) allocate a Board Info struct */
555 static int reserve_board(void)
558 gd
->start_addr_sp
= reserve_stack_aligned(sizeof(struct bd_info
));
559 gd
->bd
= (struct bd_info
*)map_sysmem(gd
->start_addr_sp
,
560 sizeof(struct bd_info
));
561 memset(gd
->bd
, '\0', sizeof(struct bd_info
));
562 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
563 sizeof(struct bd_info
), gd
->start_addr_sp
);
568 static int reserve_global_data(void)
570 gd
->start_addr_sp
= reserve_stack_aligned(sizeof(gd_t
));
571 gd
->new_gd
= (gd_t
*)map_sysmem(gd
->start_addr_sp
, sizeof(gd_t
));
572 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
573 sizeof(gd_t
), gd
->start_addr_sp
);
577 static int reserve_fdt(void)
579 if (!IS_ENABLED(CONFIG_OF_EMBED
)) {
581 * If the device tree is sitting immediately above our image
582 * then we must relocate it. If it is embedded in the data
583 * section, then it will be relocated with other data.
586 gd
->boardf
->fdt_size
=
587 ALIGN(fdt_totalsize(gd
->fdt_blob
), 32);
589 gd
->start_addr_sp
= reserve_stack_aligned(
590 gd
->boardf
->fdt_size
);
591 gd
->boardf
->new_fdt
= map_sysmem(gd
->start_addr_sp
,
592 gd
->boardf
->fdt_size
);
593 debug("Reserving %lu Bytes for FDT at: %08lx\n",
594 gd
->boardf
->fdt_size
, gd
->start_addr_sp
);
601 static int reserve_bootstage(void)
603 #ifdef CONFIG_BOOTSTAGE
604 int size
= bootstage_get_size(true);
606 gd
->start_addr_sp
= reserve_stack_aligned(size
);
607 gd
->boardf
->new_bootstage
= map_sysmem(gd
->start_addr_sp
, size
);
608 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size
,
615 __weak
int arch_reserve_stacks(void)
620 static int reserve_stacks(void)
622 /* make stack pointer 16-byte aligned */
623 gd
->start_addr_sp
= reserve_stack_aligned(16);
626 * let the architecture-specific code tailor gd->start_addr_sp and
629 return arch_reserve_stacks();
632 static int reserve_bloblist(void)
634 #ifdef CONFIG_BLOBLIST
635 ulong size
= bloblist_get_total_size();
637 if (size
< CONFIG_BLOBLIST_SIZE_RELOC
)
638 size
= CONFIG_BLOBLIST_SIZE_RELOC
;
640 /* Align to a 4KB boundary for easier reading of addresses */
641 gd
->start_addr_sp
= ALIGN_DOWN(gd
->start_addr_sp
- size
, 0x1000);
642 gd
->boardf
->new_bloblist
= map_sysmem(gd
->start_addr_sp
, size
);
648 static int display_new_sp(void)
650 debug("New Stack Pointer is: %08lx\n", gd
->start_addr_sp
);
655 __weak
int arch_setup_bdinfo(void)
660 int setup_bdinfo(void)
662 return arch_setup_bdinfo();
666 static int init_post(void)
668 post_bootmode_init();
669 post_run(NULL
, POST_ROM
| post_bootmode_get(0));
675 static int reloc_fdt(void)
677 if (!IS_ENABLED(CONFIG_OF_EMBED
)) {
678 if (gd
->boardf
->new_fdt
) {
679 memcpy(gd
->boardf
->new_fdt
, gd
->fdt_blob
,
680 fdt_totalsize(gd
->fdt_blob
));
681 gd
->fdt_blob
= gd
->boardf
->new_fdt
;
688 static int reloc_bootstage(void)
690 #ifdef CONFIG_BOOTSTAGE
691 if (gd
->flags
& GD_FLG_SKIP_RELOC
)
693 if (gd
->boardf
->new_bootstage
)
694 bootstage_relocate(gd
->boardf
->new_bootstage
);
700 static int reloc_bloblist(void)
702 #ifdef CONFIG_BLOBLIST
704 * Relocate only if we are supposed to send it
706 if ((gd
->flags
& GD_FLG_SKIP_RELOC
) &&
707 CONFIG_BLOBLIST_SIZE
== CONFIG_BLOBLIST_SIZE_RELOC
) {
708 debug("Not relocating bloblist\n");
711 if (gd
->boardf
->new_bloblist
) {
712 ulong size
= bloblist_get_total_size();
714 if (size
< CONFIG_BLOBLIST_SIZE_RELOC
)
715 size
= CONFIG_BLOBLIST_SIZE_RELOC
;
717 debug("Copying bloblist from %p to %p, size %lx\n",
718 gd
->bloblist
, gd
->boardf
->new_bloblist
, size
);
719 return bloblist_reloc(gd
->boardf
->new_bloblist
, size
);
726 void mcheck_on_ramrelocation(size_t offset
);
727 static int setup_reloc(void)
729 if (!(gd
->flags
& GD_FLG_SKIP_RELOC
)) {
730 #ifdef CONFIG_TEXT_BASE
732 gd
->reloc_off
= gd
->relocaddr
- (unsigned long)__image_copy_start
;
733 #elif defined(CONFIG_MICROBLAZE)
734 gd
->reloc_off
= gd
->relocaddr
- (u32
)_start
;
735 #elif defined(CONFIG_M68K)
737 * On all ColdFire arch cpu, monitor code starts always
738 * just after the default vector table location, so at 0x400
740 gd
->reloc_off
= gd
->relocaddr
- (CONFIG_TEXT_BASE
+ 0x400);
741 #elif !defined(CONFIG_SANDBOX)
742 gd
->reloc_off
= gd
->relocaddr
- CONFIG_TEXT_BASE
;
747 memcpy(gd
->new_gd
, (char *)gd
, sizeof(gd_t
));
749 if (gd
->flags
& GD_FLG_SKIP_RELOC
) {
750 debug("Skipping relocation due to flag\n");
752 #ifdef MCHECK_HEAP_PROTECTION
753 mcheck_on_ramrelocation(gd
->reloc_off
);
755 debug("Relocation Offset is: %08lx\n", gd
->reloc_off
);
756 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
757 gd
->relocaddr
, (ulong
)map_to_sysmem(gd
->new_gd
),
764 #if CONFIG_IS_ENABLED(OF_BOARD_FIXUP)
765 static int fix_fdt(void)
767 return board_fix_fdt((void *)gd
->fdt_blob
);
771 /* ARM calls relocate_code from its crt0.S */
772 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
774 static int jump_to_copy(void)
776 if (gd
->flags
& GD_FLG_SKIP_RELOC
)
779 * x86 is special, but in a nice way. It uses a trampoline which
780 * enables the dcache if possible.
782 * For now, other archs use relocate_code(), which is implemented
783 * similarly for all archs. When we do generic relocation, hopefully
784 * we can make all archs enable the dcache prior to relocation.
786 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
788 * SDRAM and console are now initialised. The final stack can now
789 * be setup in SDRAM. Code execution will continue in Flash, but
790 * with the stack in SDRAM and Global Data in temporary memory
793 arch_setup_gd(gd
->new_gd
);
794 # if CONFIG_IS_ENABLED(X86_64)
795 board_init_f_r_trampoline64(gd
->new_gd
, gd
->start_addr_sp
);
797 board_init_f_r_trampoline(gd
->start_addr_sp
);
800 relocate_code(gd
->start_addr_sp
, gd
->new_gd
, gd
->relocaddr
);
807 /* Record the board_init_f() bootstage (after arch_cpu_init()) */
808 static int initf_bootstage(void)
810 bool from_spl
= IS_ENABLED(CONFIG_SPL_BOOTSTAGE
) &&
811 IS_ENABLED(CONFIG_BOOTSTAGE_STASH
);
814 ret
= bootstage_init(!from_spl
);
818 ret
= bootstage_unstash_default();
819 if (ret
&& ret
!= -ENOENT
) {
820 debug("Failed to unstash bootstage: err=%d\n", ret
);
825 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F
, "board_init_f");
830 static int initf_dm(void)
834 if (!CONFIG_IS_ENABLED(SYS_MALLOC_F
))
837 bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F
, "dm_f");
838 ret
= dm_init_and_scan(true);
842 ret
= dm_autoprobe();
845 bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F
);
847 if (IS_ENABLED(CONFIG_TIMER_EARLY
)) {
848 ret
= dm_timer_init();
856 /* Architecture-specific memory reservation */
857 __weak
int reserve_arch(void)
862 __weak
int checkcpu(void)
867 __weak
int clear_bss(void)
872 static int initf_upl(void)
877 if (!IS_ENABLED(CONFIG_UPL_IN
) || !(gd
->flags
& GD_FLG_UPL
))
880 upl
= malloc(sizeof(struct upl
));
882 ret
= upl_read_handoff(upl
, oftree_default());
884 printf("UPL handoff: read failure (err=%dE)\n", ret
);
892 static void initcall_run_f(void)
895 * Please do not add logic to this function (variables, if (), etc.).
896 * For simplicity it should remain an ordered list of function calls.
898 INITCALL(setup_mon_len
);
899 #if CONFIG_IS_ENABLED(OF_CONTROL)
900 INITCALL(fdtdec_setup
);
902 #if CONFIG_IS_ENABLED(TRACE_EARLY)
903 INITCALL(trace_early_init
);
905 INITCALL(initf_malloc
);
908 INITCALL(initf_bootstage
); /* uses its own timer, so does not need DM */
909 INITCALL(event_init
);
910 INITCALL(bloblist_maybe_init
);
911 INITCALL(setup_spl_handoff
);
912 #if CONFIG_IS_ENABLED(CONSOLE_RECORD_INIT_F)
913 INITCALL(console_record_init
);
915 INITCALL_EVT(EVT_FSP_INIT_F
);
916 INITCALL(arch_cpu_init
); /* basic arch cpu dependent setup */
917 INITCALL(mach_cpu_init
); /* SoC/machine dependent CPU setup */
919 #if CONFIG_IS_ENABLED(BOARD_EARLY_INIT_F)
920 INITCALL(board_early_init_f
);
922 #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
923 /* get CPU and bus clocks according to the environment variable */
924 INITCALL(get_clocks
); /* get CPU and bus clocks (etc.) */
926 #if !defined(CONFIG_M68K) || (defined(CONFIG_M68K) && !defined(CONFIG_MCFTMR))
927 INITCALL(timer_init
); /* initialize timer */
929 #if CONFIG_IS_ENABLED(BOARD_POSTCLK_INIT)
930 INITCALL(board_postclk_init
);
932 INITCALL(env_init
); /* initialize environment */
933 INITCALL(init_baud_rate
); /* initialze baudrate settings */
934 INITCALL(serial_init
); /* serial communications setup */
935 INITCALL(console_init_f
); /* stage 1 init of console */
936 INITCALL(display_options
); /* say that we are here */
937 INITCALL(display_text_info
); /* show debugging info if required */
939 #if CONFIG_IS_ENABLED(SYSRESET)
940 INITCALL(print_resetinfo
);
942 /* display cpu info (and speed) */
943 #if CONFIG_IS_ENABLED(DISPLAY_CPUINFO)
944 INITCALL(print_cpuinfo
);
946 #if CONFIG_IS_ENABLED(DTB_RESELECT)
947 INITCALL(embedded_dtb_select
);
949 #if CONFIG_IS_ENABLED(DISPLAY_BOARDINFO)
950 INITCALL(show_board_info
);
953 INITCALL_EVT(EVT_MISC_INIT_F
);
955 #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
956 INITCALL(init_func_i2c
);
958 INITCALL(announce_dram_init
);
959 INITCALL(dram_init
); /* configure available RAM banks */
960 #if CONFIG_IS_ENABLED(POST)
961 INITCALL(post_init_f
);
964 #if defined(CFG_SYS_DRAM_TEST)
966 #endif /* CFG_SYS_DRAM_TEST */
968 #if CONFIG_IS_ENABLED(POST)
973 * Now that we have DRAM mapped and working, we can
974 * relocate the code and continue running from DRAM.
976 * Reserve memory at end of RAM for (top down in that order):
977 * - area that won't get touched by U-Boot and Linux (optional)
978 * - kernel log buffer
982 * - board info struct
984 INITCALL(setup_dest_addr
);
985 #if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \
986 !CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY)
990 INITCALL(reserve_pram
);
992 INITCALL(reserve_round_4k
);
993 INITCALL(setup_relocaddr_from_bloblist
);
994 INITCALL(arch_reserve_mmu
);
995 INITCALL(reserve_video
);
996 INITCALL(reserve_trace
);
997 INITCALL(reserve_uboot
);
998 INITCALL(reserve_malloc
);
999 INITCALL(reserve_board
);
1000 INITCALL(reserve_global_data
);
1001 INITCALL(reserve_fdt
);
1002 #if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \
1003 CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY)
1004 INITCALL(reloc_fdt
);
1007 INITCALL(reserve_bootstage
);
1008 INITCALL(reserve_bloblist
);
1009 INITCALL(reserve_arch
);
1010 INITCALL(reserve_stacks
);
1011 INITCALL(dram_init_banksize
);
1012 INITCALL(show_dram_config
);
1014 INITCALL(setup_bdinfo
);
1015 INITCALL(display_new_sp
);
1017 #if !CONFIG_IS_ENABLED(OF_BOARD_FIXUP) || \
1018 !CONFIG_IS_ENABLED(INITIAL_DTB_READONLY)
1019 INITCALL(reloc_fdt
);
1021 INITCALL(reloc_bootstage
);
1022 INITCALL(reloc_bloblist
);
1023 INITCALL(setup_reloc
);
1024 #if CONFIG_IS_ENABLED(X86) || CONFIG_IS_ENABLED(ARC)
1025 INITCALL(copy_uboot_to_ram
);
1026 INITCALL(do_elf_reloc_fixups
);
1028 INITCALL(clear_bss
);
1030 * Deregister all cyclic functions before relocation, so that
1031 * gd->cyclic_list does not contain any references to pre-relocation
1032 * devices. Drivers will register their cyclic functions anew when the
1033 * devices are probed again.
1035 * This should happen as late as possible so that the window where a
1036 * watchdog device is not serviced is as small as possible.
1038 INITCALL(cyclic_unregister_all
);
1039 #if !CONFIG_IS_ENABLED(ARM) && !CONFIG_IS_ENABLED(SANDBOX)
1040 INITCALL(jump_to_copy
);
1044 void board_init_f(ulong boot_flags
)
1046 struct board_f boardf
;
1048 gd
->flags
= boot_flags
;
1049 gd
->flags
&= ~GD_FLG_HAVE_CONSOLE
;
1050 gd
->boardf
= &boardf
;
1054 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1055 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
1056 !defined(CONFIG_ARC)
1057 /* NOTREACHED - jump_to_copy() does not return */
1062 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
1064 * For now this code is only used on x86.
1066 * Run init functions which are run when U-Boot is executing from Flash with a
1067 * semi-limited 'C' environment.
1068 * The following limitations must be considered when implementing an
1070 * - 'static' variables are read-only
1071 * - Global Data (gd->xxx) is read/write
1073 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1074 * supported). It _should_, if possible, copy global data to RAM and
1075 * initialise the CPU caches (to speed up the relocation process)
1077 * NOTE: At present only x86 uses this route, but it is intended that
1078 * all archs will move to this when generic relocation is implemented.
1080 static void initcall_run_f_r(void)
1082 #if !CONFIG_IS_ENABLED(X86_64)
1083 INITCALL(init_cache_f_r
);
1087 void board_init_f_r(void)
1092 * The pre-relocation drivers may be using memory that has now gone
1093 * away. Mark serial as unavailable - this will fall back to the debug
1094 * UART if available.
1096 * Do the same with log drivers since the memory may not be available.
1098 gd
->flags
&= ~(GD_FLG_SERIAL_READY
| GD_FLG_LOG_READY
);
1104 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1105 * Transfer execution from Flash to RAM by calculating the address
1106 * of the in-RAM copy of board_init_r() and calling it
1108 (board_init_r
+ gd
->reloc_off
)((gd_t
*)gd
, gd
->relocaddr
);
1110 /* NOTREACHED - board_init_r() does not return */
1113 #endif /* CONFIG_X86 */