X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fboard_f.c;h=149a7229e8fa982d53ce003c67ddb2db7d45e2e1;hb=0a09f2f1173d877a007fe64c7e130c04c5085662;hp=4b7483503e21caebb67257ec2cc74884e8b21619;hpb=5ebd27d860ec0c6e36f1b0f973653fe66a7360be;p=oweals%2Fu-boot.git diff --git a/common/board_f.c b/common/board_f.c index 4b7483503e..149a7229e8 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2011 The Chromium OS Authors. * (C) Copyright 2002-2006 @@ -6,63 +7,42 @@ * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH * Marius Groeger - * - * SPDX-License-Identifier: GPL-2.0+ */ #include -#include -#include +#include #include -#include +#include #include +#include #include #include -#if defined(CONFIG_CMD_IDE) -#include -#endif #include #include -#include #include #include - -/* TODO: Can we move these into arch/ headers? */ -#ifdef CONFIG_8xx -#include -#endif -#ifdef CONFIG_5xx -#include -#endif -#ifdef CONFIG_MPC5xxx -#include -#endif -#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) -#include -#endif - #include #include -#include +#include +#ifdef CONFIG_SPL +#include +#endif #include +#include #include #include #include #include -#include -#include -#include -#if defined(CONFIG_X86) || defined(CONFIG_ARC) -#include -#endif -#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA) -#include +#ifdef CONFIG_MACH_TYPE +#include #endif -#ifdef CONFIG_SANDBOX -#include +#if defined(CONFIG_MP) && defined(CONFIG_PPC) +#include #endif +#include +#include #include -#include +#include /* * Pointer to initial global data area @@ -72,7 +52,7 @@ #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR #undef XTRN_DECLARE_GLOBAL_DATA_PTR #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ -DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); +DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR); #else DECLARE_GLOBAL_DATA_PTR; #endif @@ -109,16 +89,12 @@ __weak void blue_led_off(void) {} * a structure... */ -/* - * Could the CONFIG_SPL_BUILD infection become a flag in gd? - */ - #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) static int init_func_watchdog_init(void) { -# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \ - defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ - defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \ +# if defined(CONFIG_HW_WATCHDOG) && \ + (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ + defined(CONFIG_SH) || \ defined(CONFIG_DESIGNWARE_WATCHDOG) || \ defined(CONFIG_IMX_WATCHDOG)) hw_watchdog_init(); @@ -144,7 +120,7 @@ __weak void board_add_ram_info(int use_default) static int init_baud_rate(void) { - gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); + gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE); return 0; } @@ -163,42 +139,69 @@ static int display_text_info(void) #endif debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", - text_base, bss_start, bss_end); -#endif - -#ifdef CONFIG_USE_IRQ - debug("IRQ Stack: %08lx\n", IRQ_STACK_START); - debug("FIQ Stack: %08lx\n", FIQ_STACK_START); + text_base, bss_start, bss_end); #endif return 0; } -static int announce_dram_init(void) +#ifdef CONFIG_SYSRESET +static int print_resetinfo(void) { - puts("DRAM: "); + struct udevice *dev; + char status[256]; + int ret; + + ret = uclass_first_device_err(UCLASS_SYSRESET, &dev); + if (ret) { + debug("%s: No sysreset device found (error: %d)\n", + __func__, ret); + /* Not all boards have sysreset drivers available during early + * boot, so don't fail if one can't be found. + */ + return 0; + } + + if (!sysreset_get_status(dev, status, sizeof(status))) + printf("%s", status); + return 0; } +#endif -#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) -static int init_func_ram(void) +#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU) +static int print_cpuinfo(void) { -#ifdef CONFIG_BOARD_TYPES - int board_type = gd->board_type; -#else - int board_type = 0; /* use dummy arg */ -#endif + struct udevice *dev; + char desc[512]; + int ret; + + ret = uclass_first_device_err(UCLASS_CPU, &dev); + if (ret) { + debug("%s: Could not get CPU device (err = %d)\n", + __func__, ret); + return ret; + } - gd->ram_size = initdram(board_type); + ret = cpu_get_desc(dev, desc, sizeof(desc)); + if (ret) { + debug("%s: Could not get CPU description (err = %d)\n", + dev->name, ret); + return ret; + } - if (gd->ram_size > 0) - return 0; + printf("CPU: %s\n", desc); - puts("*** failed ***\n"); - return 1; + return 0; } #endif +static int announce_dram_init(void) +{ + puts("DRAM: "); + return 0; +} + static int show_dram_config(void) { unsigned long long size; @@ -227,15 +230,17 @@ static int show_dram_config(void) return 0; } -__weak void dram_init_banksize(void) +__weak int dram_init_banksize(void) { #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; gd->bd->bi_dram[0].size = get_effective_memsize(); #endif + + return 0; } -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) +#if defined(CONFIG_SYS_I2C) static int init_func_i2c(void) { puts("I2C: "); @@ -249,34 +254,22 @@ static int init_func_i2c(void) } #endif -#if defined(CONFIG_HARD_SPI) -static int init_func_spi(void) +#if defined(CONFIG_VID) +__weak int init_func_vid(void) { - puts("SPI: "); - spi_init(); - puts("ready\n"); return 0; } #endif -__maybe_unused -static int zero_global_data(void) -{ - memset((void *)gd, '\0', sizeof(gd_t)); - - return 0; -} - static int setup_mon_len(void) { #if defined(__ARM__) || defined(__MICROBLAZE__) gd->mon_len = (ulong)&__bss_end - (ulong)_start; #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) gd->mon_len = (ulong)&_end - (ulong)_init; -#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2) || \ - defined(CONFIG_XTENSA) +#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA) gd->mon_len = CONFIG_SYS_MONITOR_LEN; -#elif defined(CONFIG_NDS32) +#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV) gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start); #elif defined(CONFIG_SYS_MONITOR_BASE) /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ @@ -285,27 +278,26 @@ static int setup_mon_len(void) return 0; } -__weak int arch_cpu_init(void) +static int setup_spl_handoff(void) { +#if CONFIG_IS_ENABLED(HANDOFF) + gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF, + sizeof(struct spl_handoff)); + debug("Found SPL hand-off info %p\n", gd->spl_handoff); +#endif + return 0; } -__weak int mach_cpu_init(void) +__weak int arch_cpu_init(void) { return 0; } -#ifdef CONFIG_SANDBOX -static int setup_ram_buf(void) +__weak int mach_cpu_init(void) { - struct sandbox_state *state = state_get_current(); - - gd->arch.ram_buf = state->ram_buf; - gd->ram_size = state->ram_size; - return 0; } -#endif /* Get the top of usable RAM */ __weak ulong board_get_usable_ram_top(ulong total_size) @@ -325,15 +317,6 @@ __weak ulong board_get_usable_ram_top(ulong total_size) return gd->ram_top; } -__weak phys_size_t board_reserve_ram_top(phys_size_t ram_size) -{ -#ifdef CONFIG_SYS_MEM_TOP_HIDE - return ram_size - CONFIG_SYS_MEM_TOP_HIDE; -#else - return ram_size; -#endif -} - static int setup_dest_addr(void) { debug("Monitor len: %08lX\n", gd->mon_len); @@ -341,30 +324,23 @@ static int setup_dest_addr(void) * Ram is setup, size stored in gd !! */ debug("Ram size: %08lX\n", (ulong)gd->ram_size); -#ifdef CONFIG_SYS_MEM_RESERVE_SECURE - /* Reserve memory for secure MMU tables, and/or security monitor */ - gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE; - /* - * Record secure memory location. Need recalcuate if memory splits - * into banks, or the ram base is not zero. - */ - gd->arch.secure_ram = gd->ram_size; -#endif +#if defined(CONFIG_SYS_MEM_TOP_HIDE) /* * Subtract specified amount of memory to hide so that it won't * get "touched" at all by U-Boot. By fixing up gd->ram_size * the Linux kernel should now get passed the now "corrected" - * memory size and won't touch it either. This has been used - * by arch/powerpc exclusively. Now ARMv8 takes advantage of - * thie mechanism. If memory is split into banks, addresses - * need to be calculated. + * memory size and won't touch it either. This should work + * for arch/ppc and arch/powerpc. Only Linux board ports in + * arch/powerpc with bootwrapper support, that recalculate the + * memory size from the SDRAM controller setup will have to + * get fixed. */ - gd->ram_size = board_reserve_ram_top(gd->ram_size); - + gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE; +#endif #ifdef CONFIG_SYS_SDRAM_BASE - gd->ram_top = CONFIG_SYS_SDRAM_BASE; + gd->ram_base = CONFIG_SYS_SDRAM_BASE; #endif - gd->ram_top += get_effective_memsize(); + gd->ram_top = gd->ram_base + get_effective_memsize(); gd->ram_top = board_get_usable_ram_top(gd->mon_len); gd->relocaddr = gd->ram_top; debug("Ram top: %08lX\n", (ulong)gd->ram_top); @@ -381,38 +357,13 @@ static int setup_dest_addr(void) return 0; } -#if defined(CONFIG_SPARC) -static int reserve_prom(void) -{ - /* defined in arch/sparc/cpu/leon?/prom.c */ - extern void *__prom_start_reloc; - int size = 8192; /* page table = 2k, prom = 6k */ - gd->relocaddr -= size; - __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048); - debug("Reserving %dk for PROM and page table at %08lx\n", size, - gd->relocaddr); - return 0; -} -#endif - -#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) -static int reserve_logbuffer(void) -{ - /* reserve kernel log buffer */ - gd->relocaddr -= LOGBUFF_RESERVE; - debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, - gd->relocaddr); - return 0; -} -#endif - #ifdef CONFIG_PRAM /* reserve protected RAM */ static int reserve_pram(void) { ulong reg; - reg = getenv_ulong("pram", 10, CONFIG_PRAM); + reg = env_get_ulong("pram", 10, CONFIG_PRAM); gd->relocaddr -= (reg << 10); /* size is in kB */ debug("Reserving %ldk for protected RAM at %08lx\n", reg, gd->relocaddr); @@ -427,10 +378,10 @@ static int reserve_round_4k(void) return 0; } -#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ - defined(CONFIG_ARM) -static int reserve_mmu(void) +#ifdef CONFIG_ARM +__weak int reserve_mmu(void) { +#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) /* reserve TLB table */ gd->arch.tlb_size = PGTABLE_SIZE; gd->relocaddr -= gd->arch.tlb_size; @@ -448,15 +399,16 @@ static int reserve_mmu(void) * with location within secure ram. */ gd->arch.tlb_allocated = gd->arch.tlb_addr; +#endif #endif return 0; } #endif -#ifdef CONFIG_DM_VIDEO static int reserve_video(void) { +#ifdef CONFIG_DM_VIDEO ulong addr; int ret; @@ -465,14 +417,7 @@ static int reserve_video(void) if (ret) return ret; gd->relocaddr = addr; - - return 0; -} -#else - -# ifdef CONFIG_LCD -static int reserve_lcd(void) -{ +#elif defined(CONFIG_LCD) # ifdef CONFIG_FB_ADDR gd->fb_base = CONFIG_FB_ADDR; # else @@ -480,24 +425,17 @@ static int reserve_lcd(void) gd->relocaddr = lcd_setmem(gd->relocaddr); gd->fb_base = gd->relocaddr; # endif /* CONFIG_FB_ADDR */ - - return 0; -} -# endif /* CONFIG_LCD */ - -# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ +#elif defined(CONFIG_VIDEO) && \ + (!defined(CONFIG_PPC)) && \ !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ - !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) -static int reserve_legacy_video(void) -{ + !defined(CONFIG_M68K) /* reserve memory for video display (always full pages) */ gd->relocaddr = video_setmem(gd->relocaddr); gd->fb_base = gd->relocaddr; +#endif return 0; } -# endif -#endif /* !CONFIG_DM_VIDEO */ static int reserve_trace(void) { @@ -513,32 +451,33 @@ static int reserve_trace(void) static int reserve_uboot(void) { - /* - * reserve memory for U-Boot code, data & bss - * round down to next 4 kB limit - */ - gd->relocaddr -= gd->mon_len; - gd->relocaddr &= ~(4096 - 1); -#ifdef CONFIG_E500 - /* round down to next 64 kB limit so that IVPR stays aligned */ - gd->relocaddr &= ~(65536 - 1); -#endif - - debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, - gd->relocaddr); + if (!(gd->flags & GD_FLG_SKIP_RELOC)) { + /* + * reserve memory for U-Boot code, data & bss + * round down to next 4 kB limit + */ + gd->relocaddr -= gd->mon_len; + gd->relocaddr &= ~(4096 - 1); + #if defined(CONFIG_E500) || defined(CONFIG_MIPS) + /* round down to next 64 kB limit so that IVPR stays aligned */ + gd->relocaddr &= ~(65536 - 1); + #endif + + debug("Reserving %ldk for U-Boot at: %08lx\n", + gd->mon_len >> 10, gd->relocaddr); + } gd->start_addr_sp = gd->relocaddr; return 0; } -#ifndef CONFIG_SPL_BUILD /* reserve memory for malloc() area */ static int reserve_malloc(void) { gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; debug("Reserving %dk for malloc() at: %08lx\n", - TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); + TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); return 0; } @@ -554,7 +493,6 @@ static int reserve_board(void) } return 0; } -#endif static int setup_machine(void) { @@ -569,7 +507,7 @@ static int reserve_global_data(void) gd->start_addr_sp -= sizeof(gd_t); gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t)); debug("Reserving %zu Bytes for Global Data at: %08lx\n", - sizeof(gd_t), gd->start_addr_sp); + sizeof(gd_t), gd->start_addr_sp); return 0; } @@ -594,7 +532,21 @@ static int reserve_fdt(void) return 0; } -int arch_reserve_stacks(void) +static int reserve_bootstage(void) +{ +#ifdef CONFIG_BOOTSTAGE + int size = bootstage_get_size(); + + gd->start_addr_sp -= size; + gd->new_bootstage = map_sysmem(gd->start_addr_sp, size); + debug("Reserving %#x Bytes for bootstage at: %08lx\n", size, + gd->start_addr_sp); +#endif + + return 0; +} + +__weak int arch_reserve_stacks(void) { return 0; } @@ -612,6 +564,16 @@ static int reserve_stacks(void) return arch_reserve_stacks(); } +static int reserve_bloblist(void) +{ +#ifdef CONFIG_BLOBLIST + gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE; + gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE); +#endif + + return 0; +} + static int display_new_sp(void) { debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp); @@ -619,7 +581,8 @@ static int display_new_sp(void) return 0; } -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) +#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ + defined(CONFIG_SH) static int setup_board_part1(void) { bd_t *bd = gd->bd; @@ -635,11 +598,10 @@ static int setup_board_part1(void) bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ #endif -#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \ - defined(CONFIG_E500) || defined(CONFIG_MPC86xx) +#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx) bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */ #endif -#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K) +#if defined(CONFIG_M68K) bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ #endif #if defined(CONFIG_MPC83xx) @@ -663,13 +625,6 @@ static int setup_board_part2(void) bd->bi_sccfreq = gd->arch.scc_clk; bd->bi_vco = gd->arch.vco_out; #endif /* CONFIG_CPM2 */ -#if defined(CONFIG_MPC512X) - bd->bi_ipsfreq = gd->arch.ips_clk; -#endif /* CONFIG_MPC512X */ -#if defined(CONFIG_MPC5xxx) - bd->bi_ipbfreq = gd->arch.ipb_clk; - bd->bi_pcifreq = gd->pci_clk; -#endif /* CONFIG_MPC5xxx */ #if defined(CONFIG_M68K) && defined(CONFIG_PCI) bd->bi_pcifreq = gd->pci_clk; #endif @@ -683,56 +638,60 @@ static int setup_board_part2(void) } #endif -#ifdef CONFIG_SYS_EXTBDINFO -static int setup_board_extra(void) +#ifdef CONFIG_POST +static int init_post(void) { - bd_t *bd = gd->bd; - - strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version)); - strncpy((char *) bd->bi_r_version, U_BOOT_VERSION, - sizeof(bd->bi_r_version)); - - bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */ - bd->bi_plb_busfreq = gd->bus_clk; -#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ - defined(CONFIG_440EP) || defined(CONFIG_440GR) || \ - defined(CONFIG_440EPX) || defined(CONFIG_440GRX) - bd->bi_pci_busfreq = get_PCI_freq(); - bd->bi_opbfreq = get_OPB_freq(); -#elif defined(CONFIG_XILINX_405) - bd->bi_pci_busfreq = get_PCI_freq(); -#endif + post_bootmode_init(); + post_run(NULL, POST_ROM | post_bootmode_get(0)); return 0; } #endif -#ifdef CONFIG_POST -static int init_post(void) +static int reloc_fdt(void) { - post_bootmode_init(); - post_run(NULL, POST_ROM | post_bootmode_get(0)); +#ifndef CONFIG_OF_EMBED + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; + if (gd->new_fdt) { + memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); + gd->fdt_blob = gd->new_fdt; + } +#endif return 0; } -#endif -static int setup_dram_config(void) +static int reloc_bootstage(void) { - /* Ram is board specific, so move it to board code ... */ - dram_init_banksize(); +#ifdef CONFIG_BOOTSTAGE + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; + if (gd->new_bootstage) { + int size = bootstage_get_size(); + + debug("Copying bootstage from %p to %p, size %x\n", + gd->bootstage, gd->new_bootstage, size); + memcpy(gd->new_bootstage, gd->bootstage, size); + gd->bootstage = gd->new_bootstage; + } +#endif return 0; } -static int reloc_fdt(void) +static int reloc_bloblist(void) { -#ifndef CONFIG_OF_EMBED +#ifdef CONFIG_BLOBLIST if (gd->flags & GD_FLG_SKIP_RELOC) return 0; - if (gd->new_fdt) { - memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); - gd->fdt_blob = gd->new_fdt; + if (gd->new_bloblist) { + int size = CONFIG_BLOBLIST_SIZE; + + debug("Copying bloblist from %p to %p, size %x\n", + gd->bloblist, gd->new_bloblist, size); + memcpy(gd->new_bloblist, gd->bloblist, size); + gd->bloblist = gd->new_bloblist; } #endif @@ -747,13 +706,16 @@ static int setup_reloc(void) } #ifdef CONFIG_SYS_TEXT_BASE - gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; -#ifdef CONFIG_M68K +#ifdef ARM + gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start; +#elif defined(CONFIG_M68K) /* * On all ColdFire arch cpu, monitor code starts always * just after the default vector table location, so at 0x400 */ gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400); +#else + gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; #endif #endif memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); @@ -766,8 +728,16 @@ static int setup_reloc(void) return 0; } +#ifdef CONFIG_OF_BOARD_FIXUP +static int fix_fdt(void) +{ + return board_fix_fdt((void *)gd->fdt_blob); +} +#endif + /* ARM calls relocate_code from its crt0.S */ -#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) +#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ + !CONFIG_IS_ENABLED(X86_64) static int jump_to_copy(void) { @@ -799,8 +769,26 @@ static int jump_to_copy(void) #endif /* Record the board_init_f() bootstage (after arch_cpu_init()) */ -static int mark_bootstage(void) +static int initf_bootstage(void) { + bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) && + IS_ENABLED(CONFIG_BOOTSTAGE_STASH); + int ret; + + ret = bootstage_init(!from_spl); + if (ret) + return ret; + if (from_spl) { + const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR, + CONFIG_BOOTSTAGE_STASH_SIZE); + + ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE); + if (ret && ret != -ENOENT) { + debug("Failed to unstash bootstage: err=%d\n", ret); + return ret; + } + } + bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f"); return 0; @@ -808,7 +796,7 @@ static int mark_bootstage(void) static int initf_console_record(void) { -#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN) return console_record_init(); #else return 0; @@ -817,10 +805,12 @@ static int initf_console_record(void) static int initf_dm(void) { -#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN) int ret; + bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f"); ret = dm_init_and_scan(true); + bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F); if (ret) return ret; #endif @@ -844,10 +834,7 @@ __weak int arch_cpu_init_dm(void) return 0; } -static init_fnc_t init_sequence_f[] = { -#ifdef CONFIG_SANDBOX - setup_ram_buf, -#endif +static const init_fnc_t init_sequence_f[] = { setup_mon_len, #ifdef CONFIG_OF_CONTROL fdtdec_setup, @@ -856,78 +843,51 @@ static init_fnc_t init_sequence_f[] = { trace_early_init, #endif initf_malloc, - initf_console_record, -#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) - /* TODO: can this go into arch_cpu_init()? */ - probecpu, + log_init, + initf_bootstage, /* uses its own timer, so does not need DM */ +#ifdef CONFIG_BLOBLIST + bloblist_init, #endif -#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) - x86_fsp_init, + setup_spl_handoff, + initf_console_record, +#if defined(CONFIG_HAVE_FSP) + arch_fsp_init, #endif arch_cpu_init, /* basic arch cpu dependent setup */ mach_cpu_init, /* SoC/machine dependent CPU setup */ initf_dm, arch_cpu_init_dm, - mark_bootstage, /* need timer, go after init dm */ #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f, #endif - /* TODO: can any of this go into arch_cpu_init()? */ -#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT) +#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) + /* get CPU and bus clocks according to the environment variable */ get_clocks, /* get CPU and bus clocks (etc.) */ -#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \ - && !defined(CONFIG_TQM885D) - adjust_sdram_tbs_8xx, #endif - /* TODO: can we rename this to timer_init()? */ - init_timebase, -#endif -#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \ - defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \ - defined(CONFIG_SPARC) +#if !defined(CONFIG_M68K) timer_init, /* initialize timer */ #endif -#ifdef CONFIG_SYS_ALLOC_DPRAM -#if !defined(CONFIG_CPM2) - dpram_init, -#endif -#endif #if defined(CONFIG_BOARD_POSTCLK_INIT) board_postclk_init, -#endif -#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) - get_clocks, #endif env_init, /* initialize environment */ -#if defined(CONFIG_8xx_CPUCLK_DEFAULT) - /* get CPU and bus clocks according to the environment variable */ - get_clocks_866, - /* adjust sdram refresh rate according to the new clock */ - sdram_adjust_866, - init_timebase, -#endif init_baud_rate, /* initialze baudrate settings */ serial_init, /* serial communications setup */ console_init_f, /* stage 1 init of console */ -#ifdef CONFIG_SANDBOX - sandbox_early_getopt_check, -#endif display_options, /* say that we are here */ display_text_info, /* show debugging info if required */ -#if defined(CONFIG_MPC8260) - prt_8260_rsr, - prt_8260_clks, -#endif /* CONFIG_MPC8260 */ -#if defined(CONFIG_MPC83xx) - prt_83xx_rsr, -#endif -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) +#if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86) checkcpu, #endif +#if defined(CONFIG_SYSRESET) + print_resetinfo, +#endif +#if defined(CONFIG_DISPLAY_CPUINFO) print_cpuinfo, /* display cpu info (and speed) */ -#if defined(CONFIG_MPC5xxx) - prt_mpc5xxx_clks, -#endif /* CONFIG_MPC5xxx */ +#endif +#if defined(CONFIG_DTB_RESELECT) + embedded_dtb_select, +#endif #if defined(CONFIG_DISPLAY_BOARDINFO) show_board_info, #endif @@ -936,21 +896,14 @@ static init_fnc_t init_sequence_f[] = { misc_init_f, #endif INIT_FUNC_WATCHDOG_RESET -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) +#if defined(CONFIG_SYS_I2C) init_func_i2c, #endif -#if defined(CONFIG_HARD_SPI) - init_func_spi, +#if defined(CONFIG_VID) && !defined(CONFIG_SPL) + init_func_vid, #endif announce_dram_init, - /* TODO: unify all these dram functions? */ -#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \ - defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) dram_init, /* configure available RAM banks */ -#endif -#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) - init_func_ram, -#endif #ifdef CONFIG_POST post_init_f, #endif @@ -977,53 +930,29 @@ static init_fnc_t init_sequence_f[] = { * - board info struct */ setup_dest_addr, -#if defined(CONFIG_BLACKFIN) || defined(CONFIG_XTENSA) - /* Blackfin u-boot monitor should be on top of the ram */ - reserve_uboot, -#endif -#if defined(CONFIG_SPARC) - reserve_prom, -#endif -#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) - reserve_logbuffer, -#endif #ifdef CONFIG_PRAM reserve_pram, #endif reserve_round_4k, -#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ - defined(CONFIG_ARM) +#ifdef CONFIG_ARM reserve_mmu, #endif -#ifdef CONFIG_DM_VIDEO reserve_video, -#else -# ifdef CONFIG_LCD - reserve_lcd, -# endif - /* TODO: Why the dependency on CONFIG_8xx? */ -# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ - !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ - !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) - reserve_legacy_video, -# endif -#endif /* CONFIG_DM_VIDEO */ reserve_trace, -#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_XTENSA) reserve_uboot, -#endif -#ifndef CONFIG_SPL_BUILD reserve_malloc, reserve_board, -#endif setup_machine, reserve_global_data, reserve_fdt, + reserve_bootstage, + reserve_bloblist, reserve_arch, reserve_stacks, - setup_dram_config, + dram_init_banksize, show_dram_config, -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) +#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ + defined(CONFIG_SH) setup_board_part1, #endif #if defined(CONFIG_PPC) || defined(CONFIG_M68K) @@ -1031,21 +960,24 @@ static init_fnc_t init_sequence_f[] = { setup_board_part2, #endif display_new_sp, -#ifdef CONFIG_SYS_EXTBDINFO - setup_board_extra, +#ifdef CONFIG_OF_BOARD_FIXUP + fix_fdt, #endif INIT_FUNC_WATCHDOG_RESET reloc_fdt, + reloc_bootstage, + reloc_bloblist, setup_reloc, #if defined(CONFIG_X86) || defined(CONFIG_ARC) copy_uboot_to_ram, - clear_bss, do_elf_reloc_fixups, + clear_bss, #endif #if defined(CONFIG_XTENSA) clear_bss, #endif -#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) +#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ + !CONFIG_IS_ENABLED(X86_64) jump_to_copy, #endif NULL, @@ -1053,25 +985,6 @@ static init_fnc_t init_sequence_f[] = { void board_init_f(ulong boot_flags) { -#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA - /* - * For some architectures, global data is initialized and used before - * calling this function. The data should be preserved. For others, - * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack - * here to host global data until relocation. - */ - gd_t data; - - gd = &data; - - /* - * Clear global data before it is accessed at debug print - * in initcall_run_list. Otherwise the debug print probably - * get the wrong value of gd->have_console. - */ - zero_global_data(); -#endif - gd->flags = boot_flags; gd->have_console = 0; @@ -1079,7 +992,8 @@ void board_init_f(ulong boot_flags) hang(); #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ - !defined(CONFIG_EFI_APP) + !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \ + !defined(CONFIG_ARC) /* NOTREACHED - jump_to_copy() does not return */ hang(); #endif @@ -1103,8 +1017,10 @@ void board_init_f(ulong boot_flags) * NOTE: At present only x86 uses this route, but it is intended that * all archs will move to this when generic relocation is implemented. */ -static init_fnc_t init_sequence_f_r[] = { +static const init_fnc_t init_sequence_f_r[] = { +#if !CONFIG_IS_ENABLED(X86_64) init_cache_f_r, +#endif NULL, }; @@ -1118,8 +1034,13 @@ void board_init_f_r(void) * The pre-relocation drivers may be using memory that has now gone * away. Mark serial as unavailable - this will fall back to the debug * UART if available. + * + * Do the same with log drivers since the memory may not be available. */ - gd->flags &= ~GD_FLG_SERIAL_READY; + gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY); +#ifdef CONFIG_TIMER + gd->timer = NULL; +#endif /* * U-Boot has been copied into SDRAM, the BSS has been cleared etc.