[U-Boot] [PATCH v3] nios2: add generic board support

Thomas Chou thomas at wytron.com.tw
Fri Aug 22 11:20:24 CEST 2014


This patch implements the generic board init as described in
doc/README.generic-board.

Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
Signed-off-by: Scott McNutt <smcnutt at psyent.com>
Reviewed-by: Stefan Roese <sr at denx.de>
---

Changes in v2:
- Coding style clean up

Changes in v3:
- Add display cpu and board info to nios2-generic board

 arch/nios2/config.mk            |    2 +
 arch/nios2/cpu/cpu.c            |   14 ++++-
 arch/nios2/cpu/start.S          |   34 ++++++++-
 arch/nios2/include/asm/config.h |    3 +
 arch/nios2/include/asm/u-boot.h |   10 +---
 arch/nios2/lib/Makefile         |    1 -
 arch/nios2/lib/board.c          |  147 ---------------------------------------
 common/board_f.c                |    6 +-
 common/board_r.c                |    2 +-
 include/configs/nios2-generic.h |    2 +
 10 files changed, 55 insertions(+), 166 deletions(-)
 delete mode 100644 arch/nios2/lib/board.c

diff --git a/arch/nios2/config.mk b/arch/nios2/config.mk
index 82bd887..9b7c56d 100644
--- a/arch/nios2/config.mk
+++ b/arch/nios2/config.mk
@@ -17,3 +17,5 @@ PLATFORM_CPPFLAGS += -G0
 
 LDFLAGS_FINAL += --gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+
+__HAVE_ARCH_GENERIC_BOARD := y
diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index e0dcbc2..86f94b7 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -10,11 +10,14 @@
 #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;
+}
diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
index 7ce0d34..6af9b4e 100644
--- a/arch/nios2/cpu/start.S
+++ b/arch/nios2/cpu/start.S
@@ -134,11 +134,12 @@ _reloc:
 	mov	fp, sp
 
 	/*
-	 * Call board_init -- never returns
+	 * Call board_init_f -- never returns
 	 */
-	movhi	r4, %hi(board_init at h)
-	ori	r4, r4, %lo(board_init at h)
-	callr	r4
+	mov	r4, r0
+	movhi	r2, %hi(board_init_f at h)
+	ori	r2, r2, %lo(board_init_f at 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 at h)
+	ori	r8, r8, %lo(board_init_r at 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
diff --git a/arch/nios2/include/asm/config.h b/arch/nios2/include/asm/config.h
index cd29734..476a32b 100644
--- a/arch/nios2/include/asm/config.h
+++ b/arch/nios2/include/asm/config.h
@@ -7,4 +7,7 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_SYS_GENERIC_BOARD
+#define CONFIG_SYS_GENERIC_GLOBAL_DATA
+
 #endif
diff --git a/arch/nios2/include/asm/u-boot.h b/arch/nios2/include/asm/u-boot.h
index 51f6c30..cb02e98 100644
--- a/arch/nios2/include/asm/u-boot.h
+++ b/arch/nios2/include/asm/u-boot.h
@@ -15,15 +15,7 @@
 #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
diff --git a/arch/nios2/lib/Makefile b/arch/nios2/lib/Makefile
index 7cb25c0..079378a 100644
--- a/arch/nios2/lib/Makefile
+++ b/arch/nios2/lib/Makefile
@@ -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
index f24218f..0000000
--- a/arch/nios2/lib/board.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
- * Scott McNutt <smcnutt at psyent.com>
- *
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, wd at 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();
-	}
-}
diff --git a/common/board_f.c b/common/board_f.c
index d5e7622..11aa555 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -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
diff --git a/common/board_r.c b/common/board_r.c
index ba9a68d..f9647e1 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -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)
diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h
index 1578b01..51b1d00 100644
--- a/include/configs/nios2-generic.h
+++ b/include/configs/nios2-generic.h
@@ -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
 
 /*
-- 
1.7.1



More information about the U-Boot mailing list