]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
nios2: add generic board support
authorThomas Chou <thomas@wytron.com.tw>
Fri, 22 Aug 2014 03:36:47 +0000 (11:36 +0800)
committerThomas Chou <thomas@wytron.com.tw>
Sun, 24 Aug 2014 03:28:10 +0000 (11:28 +0800)
This patch implements the generic board init as described in
doc/README.generic-board.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Scott McNutt <smcnutt@psyent.com>
Reviewed-by: Stefan Roese <sr@denx.de>
arch/nios2/config.mk
arch/nios2/cpu/cpu.c
arch/nios2/cpu/start.S
arch/nios2/include/asm/config.h
arch/nios2/include/asm/u-boot.h
arch/nios2/lib/Makefile
arch/nios2/lib/board.c [deleted file]
common/board_f.c
common/board_r.c
include/configs/nios2-generic.h

index 82bd887961b65b5848b7e30e66cb11221eb38632..9b7c56dc8564f76972a85d2726d66461ad0c0641 100644 (file)
@@ -17,3 +17,5 @@ PLATFORM_CPPFLAGS += -G0
 
 LDFLAGS_FINAL += --gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+
+__HAVE_ARCH_GENERIC_BOARD := y
index e0dcbc201f32fe6fa34f6fbece7d92cd4cfa9903..86f94b76fadca4f34b5bc299ad63a9a5e28f98e8 100644 (file)
 #include <nios2-io.h>
 #include <asm/cache.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #if defined (CONFIG_SYS_NIOS_SYSID_BASE)
 extern void display_sysid (void);
 #endif /* CONFIG_SYS_NIOS_SYSID_BASE */
 
-int checkcpu (void)
+#ifdef CONFIG_DISPLAY_CPUINFO
+int print_cpuinfo(void)
 {
        printf ("CPU   : Nios-II\n");
 #if !defined(CONFIG_SYS_NIOS_SYSID_BASE)
@@ -24,6 +27,7 @@ int checkcpu (void)
 #endif
        return (0);
 }
+#endif /* CONFIG_DISPLAY_CPUINFO */
 
 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -47,3 +51,11 @@ void dcache_disable(void)
 {
        flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
 }
+
+int arch_cpu_init(void)
+{
+       gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
+       gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
+
+       return 0;
+}
index 7ce0d34d7fadd61b2705eba5e3f0cfdd30fed5b5..6af9b4e94334f80f22057646b12db3d1c58f7799 100644 (file)
@@ -134,11 +134,12 @@ _reloc:
        mov     fp, sp
 
        /*
-        * Call board_init -- never returns
+        * Call board_init_f -- never returns
         */
-       movhi   r4, %hi(board_init@h)
-       ori     r4, r4, %lo(board_init@h)
-       callr   r4
+       mov     r4, r0
+       movhi   r2, %hi(board_init_f@h)
+       ori     r2, r2, %lo(board_init_f@h)
+       callr   r2
 
        /* NEVER RETURNS -- but branch to the _start just
         * in case ;-)
@@ -146,6 +147,31 @@ _reloc:
        br      _start
 
 
+
+/*
+ * relocate_code -- Nios2 handles the relocation above. But
+ * the generic board code monkeys with the heap, stack, etc.
+ * (it makes some assumptions that may not be appropriate
+ * for Nios). Nevertheless, we capitulate here.
+ *
+ * We'll call the board_init_r from here since this isn't
+ * supposed to return.
+ *
+ * void relocate_code (ulong sp, gd_t *global_data,
+ *                     ulong reloc_addr)
+ *                     __attribute__ ((noreturn));
+ */
+       .text
+       .global relocate_code
+
+relocate_code:
+       mov     sp, r4          /* Set the new sp */
+       mov     r4, r5
+       movhi   r8, %hi(board_init_r@h)
+       ori     r8, r8, %lo(board_init_r@h)
+       callr   r8
+       ret
+
 /*
  * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
  * the core. For simple delay loops, we do our best by counting
index cd29734789449b2cd0a0a006a821af9cf897e0d1..476a32bdc6529089e7b477086682c6820ed2b28e 100644 (file)
@@ -7,4 +7,7 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_SYS_GENERIC_BOARD
+#define CONFIG_SYS_GENERIC_GLOBAL_DATA
+
 #endif
index 51f6c30ef76e2d3b4217a58bf9959e309deb7842..cb02e98a82784f76bc3de3f1719e07140dea9c83 100644 (file)
 #ifndef __ASM_NIOS2_U_BOOT_H_
 #define __ASM_NIOS2_U_BOOT_H_
 
-typedef struct bd_info {
-       unsigned long   bi_memstart;    /* start of DRAM memory */
-       phys_size_t     bi_memsize;     /* size  of DRAM memory in bytes */
-       unsigned long   bi_flashstart;  /* start of FLASH memory */
-       unsigned long   bi_flashsize;   /* size  of FLASH memory */
-       unsigned long   bi_flashoffset; /* reserved area for startup monitor */
-       unsigned long   bi_sramstart;   /* start of SRAM memory */
-       unsigned long   bi_sramsize;    /* size  of SRAM memory */
-} bd_t;
+#include <asm-generic/u-boot.h>
 
 /* For image.h:image_check_target_arch() */
 #define IH_ARCH_DEFAULT IH_ARCH_NIOS2
index 7cb25c0ee13de6dd91ad364376680830fea5bb45..079378a90569a6f217a12bc7c8602d6ab7c00257 100644 (file)
@@ -6,7 +6,6 @@
 #
 
 obj-y  += cache.o
-obj-y  += board.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-y  += libgcc.o
 obj-y  += time.o
diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c
deleted file mode 100644 (file)
index f24218f..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
- * Scott McNutt <smcnutt@psyent.com>
- *
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <stdio_dev.h>
-#include <watchdog.h>
-#include <malloc.h>
-#include <mmc.h>
-#include <net.h>
-#ifdef CONFIG_STATUS_LED
-#include <status_led.h>
-#endif
-#if defined(CONFIG_SYS_NIOS_EPCSBASE)
-#include <nios2-epcs.h>
-#endif
-#ifdef CONFIG_CMD_NAND
-#include <nand.h>      /* cannot even include nand.h if it isnt configured */
-#endif
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/*
- * All attempts to come up with a "common" initialization sequence
- * that works for all boards and architectures failed: some of the
- * requirements are just _too_ different. To get rid of the resulting
- * mess of board dependend #ifdef'ed code we now make the whole
- * initialization sequence configurable to the user.
- *
- * The requirements for any new initalization function is simple: it
- * receives a pointer to the "global data" structure as it's only
- * argument, and returns an integer return code, where 0 means
- * "continue" and != 0 means "fatal error, hang the system".
- */
-
-
-typedef int (init_fnc_t) (void);
-
-
-/************************************************************************
- * Initialization sequence                                             *
- ***********************************************************************/
-
-init_fnc_t *init_sequence[] = {
-#if defined(CONFIG_BOARD_EARLY_INIT_F)
-       board_early_init_f,     /* Call board-specific init code early.*/
-#endif
-#if defined(CONFIG_SYS_NIOS_EPCSBASE)
-       epcs_reset,
-#endif
-
-       env_init,
-       serial_init,
-       console_init_f,
-       display_options,
-       checkcpu,
-       checkboard,
-       NULL,                   /* Terminate this list */
-};
-
-
-/***********************************************************************/
-void board_init(void)
-{
-       bd_t *bd;
-       init_fnc_t **init_fnc_ptr;
-       static gd_t gd_data;
-       static bd_t bd_data;
-
-       /* Pointer is writable since we allocated a register for it. */
-       gd = &gd_data;
-       /* compiler optimization barrier needed for GCC >= 3.4 */
-       __asm__ __volatile__("" : : : "memory");
-
-       gd->bd = &bd_data;
-       gd->baudrate = CONFIG_BAUDRATE;
-       gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
-
-       bd = gd->bd;
-       bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
-       bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
-#ifndef CONFIG_SYS_NO_FLASH
-       bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
-#endif
-#if    defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
-       bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
-       bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
-#endif
-
-       for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
-               WATCHDOG_RESET();
-               if ((*init_fnc_ptr) () != 0)
-                       hang();
-       }
-
-       WATCHDOG_RESET();
-
-       /* The Malloc area is immediately below the monitor copy in RAM */
-       mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
-
-#ifndef CONFIG_SYS_NO_FLASH
-       WATCHDOG_RESET();
-       bd->bi_flashsize = flash_init();
-#endif
-
-#ifdef CONFIG_CMD_NAND
-       puts("NAND:  ");
-       nand_init();
-#endif
-
-#ifdef CONFIG_GENERIC_MMC
-       puts("MMC:   ");
-       mmc_initialize(bd);
-#endif
-
-       WATCHDOG_RESET();
-       env_relocate();
-
-       WATCHDOG_RESET();
-       stdio_init();
-       jumptable_init();
-       console_init_r();
-
-       WATCHDOG_RESET();
-       interrupt_init();
-
-#if defined(CONFIG_BOARD_LATE_INIT)
-       board_late_init();
-#endif
-
-#if defined(CONFIG_CMD_NET)
-       puts("Net:   ");
-       eth_initialize(bd);
-#endif
-
-       /* main_loop */
-       for (;;) {
-               WATCHDOG_RESET();
-               main_loop();
-       }
-}
index d5e7622eebbdfb0cf82aba249ed75a9325e42470..11aa55597b2c96c21d2e379e17a900049d482bfb 100644 (file)
@@ -270,7 +270,7 @@ static int setup_mon_len(void)
        gd->mon_len = (ulong)&__bss_end - (ulong)_start;
 #elif defined(CONFIG_SANDBOX)
        gd->mon_len = (ulong)&_end - (ulong)_init;
-#elif defined(CONFIG_BLACKFIN)
+#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
        gd->mon_len = CONFIG_SYS_MONITOR_LEN;
 #else
        /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
@@ -945,7 +945,7 @@ static init_fnc_t init_sequence_f[] = {
         *  - board info struct
         */
        setup_dest_addr,
-#if defined(CONFIG_BLACKFIN)
+#if defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
        /* Blackfin u-boot monitor should be on top of the ram */
        reserve_uboot,
 #endif
@@ -970,7 +970,7 @@ static init_fnc_t init_sequence_f[] = {
                !defined(CONFIG_BLACKFIN)
        reserve_video,
 #endif
-#if !defined(CONFIG_BLACKFIN)
+#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_NIOS2)
        reserve_uboot,
 #endif
 #ifndef CONFIG_SPL_BUILD
index ba9a68dc6691d445e1803a1ad6eed06e661e5cee..f9647e13583f262a0fd78a389405027bc2108adb 100644 (file)
@@ -133,7 +133,7 @@ static int initr_reloc_global_data(void)
 {
 #ifdef __ARM__
        monitor_flash_len = _end - __image_copy_start;
-#elif !defined(CONFIG_SANDBOX)
+#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
        monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
 #endif
 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
index 1578b010b94a36dc6cd768bef26a3ff14521c579..51b1d00d993d667a09a2f8b61657950cde121e37 100644 (file)
@@ -15,6 +15,8 @@
 #include "../board/altera/nios2-generic/custom_fpga.h" /* fpga parameters */
 #define CONFIG_BOARD_NAME "nios2-generic" /* custom board name */
 #define CONFIG_BOARD_EARLY_INIT_F      /* enable early board-spec. init */
+#define CONFIG_DISPLAY_CPUINFO
+#define CONFIG_DISPLAY_BOARDINFO
 #define CONFIG_SYS_NIOS_SYSID_BASE     CONFIG_SYS_SYSID_BASE
 
 /*