]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/board_f.c
common/board_f: factor out reserve_stacks
[karo-tx-uboot.git] / common / board_f.c
index 6203d85619e4917abb393bbe432f19a26880458b..541ca1a955ae27fac6f6bb15fbd3d863451fa966 100644 (file)
@@ -34,6 +34,9 @@
 #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>
@@ -43,9 +46,6 @@
 #include <watchdog.h>
 #include <asm/errno.h>
 #include <asm/io.h>
-#ifdef CONFIG_MP
-#include <asm/mp.h>
-#endif
 #include <asm/sections.h>
 #ifdef CONFIG_X86
 #include <asm/init_helpers.h>
@@ -106,9 +106,14 @@ __weak void blue_led_off(void) {}
  * Could the CONFIG_SPL_BUILD infection become a flag in gd?
  */
 
-#if defined(CONFIG_WATCHDOG)
+#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))
+       hw_watchdog_init();
+# endif
        puts("       Watchdog enabled\n");
        WATCHDOG_RESET();
 
@@ -123,14 +128,11 @@ int init_func_watchdog_reset(void)
 }
 #endif /* CONFIG_WATCHDOG */
 
-void __board_add_ram_info(int use_default)
+__weak void board_add_ram_info(int use_default)
 {
        /* please define platform specific board_add_ram_info() */
 }
 
-void board_add_ram_info(int)
-       __attribute__ ((weak, alias("__board_add_ram_info")));
-
 static int init_baud_rate(void)
 {
        gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
@@ -140,13 +142,19 @@ static int init_baud_rate(void)
 static int display_text_info(void)
 {
 #ifndef CONFIG_SANDBOX
-       ulong bss_start, bss_end;
+       ulong bss_start, bss_end, text_base;
 
        bss_start = (ulong)&__bss_start;
        bss_end = (ulong)&__bss_end;
 
-       debug("U-Boot code: %08X -> %08lX  BSS: -> %08lX\n",
-             CONFIG_SYS_TEXT_BASE, bss_start, bss_end);
+#ifdef CONFIG_SYS_TEXT_BASE
+       text_base = CONFIG_SYS_TEXT_BASE;
+#else
+       text_base = CONFIG_SYS_MONITOR_BASE;
+#endif
+
+       debug("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
+               text_base, bss_start, bss_end);
 #endif
 
 #ifdef CONFIG_MODEM_SUPPORT
@@ -212,7 +220,7 @@ static int show_dram_config(void)
        return 0;
 }
 
-void __dram_init_banksize(void)
+__weak void 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;
@@ -220,9 +228,6 @@ void __dram_init_banksize(void)
 #endif
 }
 
-void dram_init_banksize(void)
-       __attribute__((weak, alias("__dram_init_banksize")));
-
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
 static int init_func_i2c(void)
 {
@@ -257,10 +262,12 @@ static int zero_global_data(void)
 
 static int setup_mon_len(void)
 {
-#ifdef __ARM__
+#if defined(__ARM__) || defined(__MICROBLAZE__)
        gd->mon_len = (ulong)&__bss_end - (ulong)_start;
 #elif defined(CONFIG_SANDBOX)
        gd->mon_len = (ulong)&_end - (ulong)_init;
+#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
+       gd->mon_len = CONFIG_SYS_MONITOR_LEN;
 #else
        /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
        gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
@@ -273,6 +280,11 @@ __weak int arch_cpu_init(void)
        return 0;
 }
 
+__weak unsigned long get_timer_masked(void)
+{
+       return get_timer(0);
+}
+
 #ifdef CONFIG_OF_HOSTFILE
 
 static int read_fdt_from_file(void)
@@ -280,7 +292,7 @@ static int read_fdt_from_file(void)
        struct sandbox_state *state = state_get_current();
        const char *fname = state->fdt_fname;
        void *blob;
-       ssize_t size;
+       loff_t size;
        int err;
        int fd;
 
@@ -293,10 +305,10 @@ static int read_fdt_from_file(void)
                return -EINVAL;
        }
 
-       size = os_get_filesize(fname);
-       if (size < 0) {
+       err = os_get_filesize(fname, &size);
+       if (err < 0) {
                printf("Failed to file FDT file '%s'\n", fname);
-               return -ENOENT;
+               return err;
        }
        fd = os_open(fname, OS_O_RDONLY);
        if (fd < 0) {
@@ -330,21 +342,23 @@ static int setup_ram_buf(void)
 
 static int setup_fdt(void)
 {
-#ifdef CONFIG_OF_EMBED
+#ifdef CONFIG_OF_CONTROL
+# ifdef CONFIG_OF_EMBED
        /* Get a pointer to the FDT */
        gd->fdt_blob = __dtb_dt_begin;
-#elif defined CONFIG_OF_SEPARATE
+# elif defined CONFIG_OF_SEPARATE
        /* FDT is at end of image */
        gd->fdt_blob = (ulong *)&_end;
-#elif defined(CONFIG_OF_HOSTFILE)
+# elif defined(CONFIG_OF_HOSTFILE)
        if (read_fdt_from_file()) {
                puts("Failed to read control FDT\n");
                return -1;
        }
-#endif
+# endif
        /* Allow the early environment to override the fdt address */
        gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
                                                (uintptr_t)gd->fdt_blob);
+#endif
        return 0;
 }
 
@@ -470,8 +484,9 @@ static int reserve_trace(void)
        return 0;
 }
 
-#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
-               && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
+#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
+               !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
+               !defined(CONFIG_BLACKFIN)
 static int reserve_video(void)
 {
        /* reserve memory for video display (always full pages) */
@@ -516,11 +531,13 @@ static int reserve_malloc(void)
 /* (permanently) allocate a Board Info struct */
 static int reserve_board(void)
 {
-       gd->start_addr_sp -= sizeof(bd_t);
-       gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
-       memset(gd->bd, '\0', sizeof(bd_t));
-       debug("Reserving %zu Bytes for Board Info at: %08lx\n",
-                       sizeof(bd_t), gd->start_addr_sp);
+       if (!gd->bd) {
+               gd->start_addr_sp -= sizeof(bd_t);
+               gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
+               memset(gd->bd, '\0', sizeof(bd_t));
+               debug("Reserving %zu Bytes for Board Info at: %08lx\n",
+                     sizeof(bd_t), gd->start_addr_sp);
+       }
        return 0;
 }
 #endif
@@ -561,48 +578,22 @@ static int reserve_fdt(void)
        return 0;
 }
 
-static int reserve_stacks(void)
+int arch_reserve_stacks(void)
 {
-#ifdef CONFIG_SPL_BUILD
-# ifdef CONFIG_ARM
-       gd->start_addr_sp -= 128;       /* leave 32 words for abort-stack */
-       gd->irq_sp = gd->start_addr_sp;
-# endif
-#else
-# ifdef CONFIG_PPC
-       ulong *s;
-# endif
+       return 0;
+}
 
-       /* setup stack pointer for exceptions */
+static int reserve_stacks(void)
+{
+       /* make stack pointer 16-byte aligned */
        gd->start_addr_sp -= 16;
        gd->start_addr_sp &= ~0xf;
-       gd->irq_sp = gd->start_addr_sp;
 
        /*
-        * Handle architecture-specific things here
-        * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
-        * to handle this and put in arch/xxx/lib/stack.c
+        * let the architecture specific code tailor gd->start_addr_sp and
+        * gd->irq_sp
         */
-# if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
-#  ifdef CONFIG_USE_IRQ
-       gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
-       debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
-               CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ, gd->start_addr_sp);
-
-       /* 8-byte alignment for ARM ABI compliance */
-       gd->start_addr_sp &= ~0x07;
-#  endif
-       /* leave 3 words for abort-stack, plus 1 for alignment */
-       gd->start_addr_sp -= 16;
-# elif defined(CONFIG_PPC)
-       /* Clear initial stack frame */
-       s = (ulong *) gd->start_addr_sp;
-       *s = 0; /* Terminate back chain */
-       *++s = 0; /* NULL return address */
-# endif /* Architecture specific code */
-
-       return 0;
-#endif
+       return arch_reserve_stacks();
 }
 
 static int display_new_sp(void)
@@ -721,7 +712,13 @@ static int reloc_fdt(void)
 
 static int setup_reloc(void)
 {
+#ifdef CONFIG_SYS_TEXT_BASE
+#ifndef CONFIG_ARM
        gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
+#else
+       gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
+#endif
+#endif
        memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
 
        debug("Relocation Offset is: %08lx\n", gd->reloc_off);
@@ -793,28 +790,32 @@ static int initf_dm(void)
        return 0;
 }
 
+/* Architecture-specific memory reservation */
+__weak int reserve_arch(void)
+{
+       return 0;
+}
+
 static init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_SANDBOX
        setup_ram_buf,
 #endif
        setup_mon_len,
        setup_fdt,
+#ifdef CONFIG_TRACE
        trace_early_init,
+#endif
+       initf_malloc,
 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
        /* TODO: can this go into arch_cpu_init()? */
        probecpu,
 #endif
        arch_cpu_init,          /* basic arch cpu dependent setup */
-#ifdef CONFIG_X86
-       cpu_init_f,             /* TODO(sjg@chromium.org): remove */
-# ifdef CONFIG_OF_CONTROL
-       find_fdt,               /* TODO(sjg@chromium.org): remove */
-# endif
-#endif
        mark_bootstage,
 #ifdef CONFIG_OF_CONTROL
        fdtdec_check_fdt,
 #endif
+       initf_dm,
 #if defined(CONFIG_BOARD_EARLY_INIT_F)
        board_early_init_f,
 #endif
@@ -828,7 +829,7 @@ 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)
+#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_BLACKFIN)
        timer_init,             /* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
@@ -850,8 +851,6 @@ static init_fnc_t init_sequence_f[] = {
        sdram_adjust_866,
        init_timebase,
 #endif
-       initf_malloc,
-       initf_dm,
        init_baud_rate,         /* initialze baudrate settings */
        serial_init,            /* serial communications setup */
        console_init_f,         /* stage 1 init of console */
@@ -878,7 +877,7 @@ static init_fnc_t init_sequence_f[] = {
        prt_mpc5xxx_clks,
 #endif /* CONFIG_MPC5xxx */
 #if defined(CONFIG_DISPLAY_BOARDINFO)
-       checkboard,             /* display board info */
+       show_board_info,
 #endif
        INIT_FUNC_WATCHDOG_INIT
 #if defined(CONFIG_MISC_INIT_F)
@@ -890,14 +889,10 @@ static init_fnc_t init_sequence_f[] = {
 #endif
 #if defined(CONFIG_HARD_SPI)
        init_func_spi,
-#endif
-#ifdef CONFIG_X86
-       dram_init_f,            /* configure available RAM banks */
-       calculate_relocation_address,
 #endif
        announce_dram_init,
        /* TODO: unify all these dram functions? */
-#ifdef CONFIG_ARM
+#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE)
        dram_init,              /* configure available RAM banks */
 #endif
 #if defined(CONFIG_MIPS) || defined(CONFIG_PPC)
@@ -929,6 +924,10 @@ static init_fnc_t init_sequence_f[] = {
         *  - board info struct
         */
        setup_dest_addr,
+#if defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
+       /* Blackfin u-boot monitor should be on top of the ram */
+       reserve_uboot,
+#endif
 #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
        reserve_logbuffer,
 #endif
@@ -945,11 +944,14 @@ static init_fnc_t init_sequence_f[] = {
 #endif
        reserve_trace,
        /* TODO: Why the dependency on CONFIG_8xx? */
-#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
-               && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
+#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
+               !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
+               !defined(CONFIG_BLACKFIN)
        reserve_video,
 #endif
+#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_NIOS2)
        reserve_uboot,
+#endif
 #ifndef CONFIG_SPL_BUILD
        reserve_malloc,
        reserve_board,
@@ -957,6 +959,7 @@ static init_fnc_t init_sequence_f[] = {
        setup_machine,
        reserve_global_data,
        reserve_fdt,
+       reserve_arch,
        reserve_stacks,
        setup_dram_config,
        show_dram_config,
@@ -972,6 +975,11 @@ static init_fnc_t init_sequence_f[] = {
        INIT_FUNC_WATCHDOG_RESET
        reloc_fdt,
        setup_reloc,
+#ifdef CONFIG_X86
+       copy_uboot_to_ram,
+       clear_bss,
+       do_elf_reloc_fixups,
+#endif
 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
        jump_to_copy,
 #endif
@@ -1031,9 +1039,6 @@ void board_init_f(ulong boot_flags)
  */
 static init_fnc_t init_sequence_f_r[] = {
        init_cache_f_r,
-       copy_uboot_to_ram,
-       clear_bss,
-       do_elf_reloc_fixups,
 
        NULL,
 };
@@ -1053,4 +1058,22 @@ void board_init_f_r(void)
        /* NOTREACHED - board_init_r() does not return */
        hang();
 }
+#else
+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 */