Skip to contentSkip to conversation

nios2: add generic board support

PATCH New Thomas Chou 1 participant 1 message Aug 21, 2014 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nios2: add generic board support

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

---
 arch/nios2/config.mk            |    2 +
 arch/nios2/cpu/cpu.c            |   12 +++-
 arch/nios2/cpu/start.S          |   34 ++++++++-
 arch/nios2/include/asm/config.h |    4 +
 arch/nios2/include/asm/u-boot.h |   10 +---
 arch/nios2/lib/Makefile         |    1 -
 arch/nios2/lib/board.c          |  147 ---------------------------------------
 common/board_f.c                |    7 +-
 common/board_r.c                |    2 +-
 9 files changed, 52 insertions(+), 167 deletions(-)
 delete mode 100644 arch/nios2/lib/board.c
arch/nios2/config.mk +2 -0
index 82bd887..9b7c56d 100644
@@ -17,3 +17,5 @@ PLATFORM_CPPFLAGS += -G0
 
 LDFLAGS_FINAL += --gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+
+__HAVE_ARCH_GENERIC_BOARD := y
arch/nios2/cpu/cpu.c +11 -1
index e0dcbc2..4714171 100644
@@ -10,11 +10,13 @@
 #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)
+int print_cpuinfo (void)
 {
 	printf ("CPU   : Nios-II\n");
 #if !defined(CONFIG_SYS_NIOS_SYSID_BASE)
@@ -47,3 +49,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;
+}
arch/nios2/cpu/start.S +30 -4
index 7ce0d34..6af9b4e 100644
@@ -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
arch/nios2/include/asm/config.h +4 -0
index cd29734..59546f0 100644
@@ -7,4 +7,8 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_SYS_GENERIC_BOARD
+#define CONFIG_SYS_GENERIC_GLOBAL_DATA
+#define CONFIG_DISPLAY_CPUINFO
+
 #endif
arch/nios2/include/asm/u-boot.h +1 -9
index 51f6c30..cb02e98 100644
@@ -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
arch/nios2/lib/Makefile +0 -1
index 7cb25c0..079378a 100644
@@ -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
arch/nios2/lib/board.c deleted +0 -147

147 lines not on this page · raw message

common/board_f.c +3 -4
index d5e7622..77a1990 100644
@@ -9,7 +9,6 @@
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
-
 #include <common.h>
 #include <linux/compiler.h>
 #include <version.h>
@@ -270,7 +269,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 +944,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 +969,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
common/board_r.c +1 -1
index ba9a68d..f9647e1 100644
@@ -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)
Signature · 1 line
1.7.1