]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/board_f.c
ARM: dts: DRA7: use new dra7-specific compatible string
[people/ms/u-boot.git] / common / board_f.c
index bafe3aa49ce268c36f64932ebaf64d0bec0937e1..c6bc53e1bf058c783214b08e01d3724bfc06cf87 100644 (file)
 #include <fs.h>
 #include <i2c.h>
 #include <initcall.h>
-#include <logbuff.h>
+#include <init_helpers.h>
 #include <malloc.h>
 #include <mapmem.h>
-
-/* TODO: Can we move these into arch/ headers? */
-#ifdef CONFIG_8xx
-#include <mpc8xx.h>
-#endif
-#ifdef CONFIG_5xx
-#include <mpc5xx.h>
-#endif
-#ifdef CONFIG_MPC5xxx
-#include <mpc5xxx.h>
-#endif
-#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
-#include <asm/mp.h>
-#endif
-
 #include <os.h>
 #include <post.h>
+#include <relocate.h>
 #include <spi.h>
 #include <status_led.h>
 #include <timer.h>
 #include <trace.h>
 #include <video.h>
 #include <watchdog.h>
-#include <asm/io.h>
-#include <asm/sections.h>
-#if defined(CONFIG_X86) || defined(CONFIG_ARC)
-#include <asm/init_helpers.h>
+#ifdef CONFIG_MACH_TYPE
+#include <asm/mach-types.h>
 #endif
-#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
-#include <asm/relocate.h>
+#if defined(CONFIG_MP) && defined(CONFIG_PPC)
+#include <asm/mp.h>
 #endif
+#include <asm/io.h>
+#include <asm/sections.h>
 #include <dm/root.h>
 #include <linux/errno.h>
 
@@ -63,7 +49,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
@@ -131,7 +117,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;
 }
 
@@ -150,12 +136,7 @@ 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;
@@ -167,13 +148,6 @@ static int announce_dram_init(void)
        return 0;
 }
 
-#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
-static int init_func_ram(void)
-{
-       return initdram();
-}
-#endif
-
 static int show_dram_config(void)
 {
        unsigned long long size;
@@ -212,7 +186,7 @@ __weak int dram_init_banksize(void)
        return 0;
 }
 
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C)
 static int init_func_i2c(void)
 {
        puts("I2C:   ");
@@ -226,6 +200,13 @@ static int init_func_i2c(void)
 }
 #endif
 
+#if defined(CONFIG_VID)
+__weak int init_func_vid(void)
+{
+       return 0;
+}
+#endif
+
 #if defined(CONFIG_HARD_SPI)
 static int init_func_spi(void)
 {
@@ -236,14 +217,6 @@ static int init_func_spi(void)
 }
 #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__)
@@ -252,7 +225,7 @@ static int setup_mon_len(void)
        gd->mon_len = (ulong)&_end - (ulong)_init;
 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
        gd->mon_len = CONFIG_SYS_MONITOR_LEN;
-#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
+#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; ? */
@@ -329,27 +302,13 @@ static int setup_dest_addr(void)
        return 0;
 }
 
-#if defined(CONFIG_LOGBUFFER)
-static int reserve_logbuffer(void)
-{
-#ifndef CONFIG_ALT_LB_ADDR
-       /* reserve kernel log buffer */
-       gd->relocaddr -= LOGBUFF_RESERVE;
-       debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
-               gd->relocaddr);
-#endif
-
-       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);
@@ -365,7 +324,7 @@ static int reserve_round_4k(void)
 }
 
 #ifdef CONFIG_ARM
-static int reserve_mmu(void)
+__weak int reserve_mmu(void)
 {
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
        /* reserve TLB table */
@@ -412,7 +371,7 @@ static int reserve_video(void)
        gd->fb_base = gd->relocaddr;
 #  endif /* CONFIG_FB_ADDR */
 #elif defined(CONFIG_VIDEO) && \
-               (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
+               (!defined(CONFIG_PPC)) && \
                !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
                !defined(CONFIG_M68K)
        /* reserve memory for video display (always full pages) */
@@ -443,7 +402,7 @@ static int reserve_uboot(void)
         */
        gd->relocaddr -= gd->mon_len;
        gd->relocaddr &= ~(4096 - 1);
-#ifdef CONFIG_E500
+#if defined(CONFIG_E500) || defined(CONFIG_MIPS)
        /* round down to next 64 kB limit so that IVPR stays aligned */
        gd->relocaddr &= ~(65536 - 1);
 #endif
@@ -461,7 +420,7 @@ 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;
 }
 
@@ -491,7 +450,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;
 }
 
@@ -516,6 +475,20 @@ static int reserve_fdt(void)
        return 0;
 }
 
+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;
+}
+
 int arch_reserve_stacks(void)
 {
        return 0;
@@ -558,11 +531,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)
@@ -586,13 +558,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
@@ -630,6 +595,24 @@ static int reloc_fdt(void)
        return 0;
 }
 
+static int reloc_bootstage(void)
+{
+#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 setup_reloc(void)
 {
        if (gd->flags & GD_FLG_SKIP_RELOC) {
@@ -638,13 +621,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));
@@ -698,8 +684,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;
@@ -707,7 +711,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;
@@ -716,10 +720,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
@@ -752,6 +758,8 @@ static const init_fnc_t init_sequence_f[] = {
        trace_early_init,
 #endif
        initf_malloc,
+       log_init,
+       initf_bootstage,        /* uses its own timer, so does not need DM */
        initf_console_record,
 #if defined(CONFIG_HAVE_FSP)
        arch_fsp_init,
@@ -760,7 +768,6 @@ static const init_fnc_t init_sequence_f[] = {
        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
@@ -768,7 +775,9 @@ static const init_fnc_t init_sequence_f[] = {
        /* get CPU and bus clocks according to the environment variable */
        get_clocks,             /* get CPU and bus clocks (etc.) */
 #endif
+#if !defined(CONFIG_M68K)
        timer_init,             /* initialize timer */
+#endif
 #if defined(CONFIG_BOARD_POSTCLK_INIT)
        board_postclk_init,
 #endif
@@ -778,13 +787,15 @@ static const init_fnc_t init_sequence_f[] = {
        console_init_f,         /* stage 1 init of console */
        display_options,        /* say that we are here */
        display_text_info,      /* show debugging info if required */
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
-               defined(CONFIG_X86)
+#if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86)
        checkcpu,
 #endif
 #if defined(CONFIG_DISPLAY_CPUINFO)
        print_cpuinfo,          /* display cpu info (and speed) */
 #endif
+#if defined(CONFIG_DTB_RESELECT)
+       embedded_dtb_select,
+#endif
 #if defined(CONFIG_DISPLAY_BOARDINFO)
        show_board_info,
 #endif
@@ -793,22 +804,17 @@ static const 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_VID) && !defined(CONFIG_SPL)
+       init_func_vid,
+#endif
 #if defined(CONFIG_HARD_SPI)
        init_func_spi,
 #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) || \
-               defined(CONFIG_SH)
        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
@@ -835,9 +841,6 @@ static const init_fnc_t init_sequence_f[] = {
         *  - board info struct
         */
        setup_dest_addr,
-#if defined(CONFIG_LOGBUFFER)
-       reserve_logbuffer,
-#endif
 #ifdef CONFIG_PRAM
        reserve_pram,
 #endif
@@ -853,6 +856,7 @@ static const init_fnc_t init_sequence_f[] = {
        setup_machine,
        reserve_global_data,
        reserve_fdt,
+       reserve_bootstage,
        reserve_arch,
        reserve_stacks,
        dram_init_banksize,
@@ -866,14 +870,12 @@ static const init_fnc_t init_sequence_f[] = {
        setup_board_part2,
 #endif
        display_new_sp,
-#ifdef CONFIG_SYS_EXTBDINFO
-       setup_board_extra,
-#endif
 #ifdef CONFIG_OF_BOARD_FIXUP
        fix_fdt,
 #endif
        INIT_FUNC_WATCHDOG_RESET
        reloc_fdt,
+       reloc_bootstage,
        setup_reloc,
 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
        copy_uboot_to_ram,
@@ -892,25 +894,6 @@ static const 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;
 
@@ -959,8 +942,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.