Merge branch 'master' of git://git.denx.de/u-boot-x86
[oweals/u-boot.git] / common / board_f.c
index 74f77f1ea1c494094f079ad38293e2433d28010f..8094ac4efe0d6feb120433e021f0cd2e723c85dd 100644 (file)
@@ -13,6 +13,7 @@
 #include <common.h>
 #include <linux/compiler.h>
 #include <version.h>
+#include <console.h>
 #include <environment.h>
 #include <dm.h>
 #include <fdtdec.h>
@@ -272,6 +273,8 @@ static int setup_mon_len(void)
        gd->mon_len = (ulong)&_end - (ulong)_init;
 #elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
        gd->mon_len = CONFIG_SYS_MONITOR_LEN;
+#elif defined(CONFIG_NDS32)
+       gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
 #else
        /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
        gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
@@ -314,6 +317,15 @@ __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);
@@ -321,19 +333,26 @@ static int setup_dest_addr(void)
         * Ram is setup, size stored in gd !!
         */
        debug("Ram size: %08lX\n", (ulong)gd->ram_size);
-#if defined(CONFIG_SYS_MEM_TOP_HIDE)
+#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->secure_ram = gd->ram_size;
+#endif
        /*
         * 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 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.
+        * 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.
         */
-       gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
-#endif
+       gd->ram_size = board_reserve_ram_top(gd->ram_size);
+
 #ifdef CONFIG_SYS_SDRAM_BASE
        gd->ram_top = CONFIG_SYS_SDRAM_BASE;
 #endif
@@ -354,6 +373,20 @@ 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)
 {
@@ -499,7 +532,6 @@ static int setup_machine(void)
 static int reserve_global_data(void)
 {
        gd->start_addr_sp -= sizeof(gd_t);
-       gd->start_addr_sp &= ~0xf;
        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);
@@ -508,6 +540,7 @@ static int reserve_global_data(void)
 
 static int reserve_fdt(void)
 {
+#ifndef CONFIG_OF_EMBED
        /*
         * If the device tree is sitting immediately above our image then we
         * must relocate it. If it is embedded in the data section, then it
@@ -521,6 +554,7 @@ static int reserve_fdt(void)
                debug("Reserving %lu Bytes for FDT at: %08lx\n",
                      gd->fdt_size, gd->start_addr_sp);
        }
+#endif
 
        return 0;
 }
@@ -550,7 +584,7 @@ static int display_new_sp(void)
        return 0;
 }
 
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
 static int setup_board_part1(void)
 {
        bd_t *bd = gd->bd;
@@ -579,7 +613,9 @@ static int setup_board_part1(void)
 
        return 0;
 }
+#endif
 
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
 static int setup_board_part2(void)
 {
        bd_t *bd = gd->bd;
@@ -656,12 +692,14 @@ static int setup_dram_config(void)
 
 static int reloc_fdt(void)
 {
+#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;
 }
@@ -715,6 +753,7 @@ static int jump_to_copy(void)
         * with the stack in SDRAM and Global Data in temporary memory
         * (CPU cache)
         */
+       arch_setup_gd(gd->new_gd);
        board_init_f_r_trampoline(gd->start_addr_sp);
 #else
        relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
@@ -732,6 +771,15 @@ static int mark_bootstage(void)
        return 0;
 }
 
+static int initf_console_record(void)
+{
+#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
+       return console_record_init();
+#else
+       return 0;
+#endif
+}
+
 static int initf_dm(void)
 {
 #if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
@@ -764,21 +812,22 @@ static init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_OF_CONTROL
        fdtdec_setup,
 #endif
-#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
-       x86_fsp_init,
-#endif
 #ifdef CONFIG_TRACE
        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,
+#endif
+#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
+       x86_fsp_init,
 #endif
        arch_cpu_init,          /* basic arch cpu dependent setup */
-       mark_bootstage,
        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
@@ -792,7 +841,9 @@ static init_fnc_t init_sequence_f[] = {
        /* TODO: can we rename this to timer_init()? */
        init_timebase,
 #endif
-#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_BLACKFIN)
+#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
+               defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
+               defined(CONFIG_SPARC)
        timer_init,             /* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
@@ -803,10 +854,7 @@ static init_fnc_t init_sequence_f[] = {
 #if defined(CONFIG_BOARD_POSTCLK_INIT)
        board_postclk_init,
 #endif
-#ifdef CONFIG_FSL_ESDHC
-       get_clocks,
-#endif
-#ifdef CONFIG_M68K
+#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
        get_clocks,
 #endif
        env_init,               /* initialize environment */
@@ -858,7 +906,8 @@ static init_fnc_t init_sequence_f[] = {
 #endif
        announce_dram_init,
        /* TODO: unify all these dram functions? */
-#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
+#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)
@@ -890,10 +939,13 @@ static init_fnc_t init_sequence_f[] = {
         *  - board info struct
         */
        setup_dest_addr,
-#if defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
+#if defined(CONFIG_BLACKFIN)
        /* 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
@@ -915,7 +967,7 @@ static init_fnc_t init_sequence_f[] = {
                !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
        reserve_video,
 #endif
-#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_NIOS2)
+#if !defined(CONFIG_BLACKFIN)
        reserve_uboot,
 #endif
 #ifndef CONFIG_SPL_BUILD
@@ -929,8 +981,10 @@ static init_fnc_t init_sequence_f[] = {
        reserve_stacks,
        setup_dram_config,
        show_dram_config,
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
        setup_board_part1,
+#endif
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
        INIT_FUNC_WATCHDOG_RESET
        setup_board_part2,
 #endif
@@ -1026,23 +1080,3 @@ void board_init_f_r(void)
        hang();
 }
 #endif /* CONFIG_X86 */
-
-#ifndef CONFIG_X86
-ulong board_init_f_mem(ulong top)
-{
-       /* Leave space for the stack we are running with now */
-       top -= 0x40;
-
-       top -= sizeof(struct global_data);
-       top = ALIGN(top, 16);
-       gd = (struct global_data *)top;
-       memset((void *)gd, '\0', sizeof(*gd));
-
-#ifdef CONFIG_SYS_MALLOC_F_LEN
-       top -= CONFIG_SYS_MALLOC_F_LEN;
-       gd->malloc_base = top;
-#endif
-
-       return top;
-}
-#endif /* !CONFIG_X86 */