nios2: add generic board support
PATCH 1/1 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 1/1 nios2: add generic board support
Quoted 2 lines · Thomas Chou
This patch implements the generic board init as described in doc/README.generic-board.
Good idea. Please find below a few comments, mostly coding style related.
<snip>
Quoted 6 lines
arch/nios2/cpu/cpu.c +0
-0@@ -10,11 +10,13 @@#include <nios2-io.h>
arch/nios2/cpu/cpu.c line 19
Quoted 10 lines
arch/nios2/cpu/cpu.c +3
-1#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 )
While changing this line, please fix the coding style to:
+int print_cpuinfo(void)
No space before the "(".
<snip>
common/board_f.c line 12
Quoted 10 lines
common/board_f.c +0
-1@@ -9,7 +9,6 @@* * SPDX-License-Identifier: GPL-2.0+ */ -#include <common.h>
This empty line removal seems to have slipped in. I know, its nitpicking, but I would prefer to not change unrelated things.
Otherwise looks good:
Thanks,
Stefan
PATCH v2 1/1 nios2: add generic board support
This patch implements the generic board init as described in doc/README.generic-board.
---
Changes in v2:
- Coding style clean up
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 | 6 +- common/board_r.c | 2 +- 9 files changed, 52 insertions(+), 166 deletions(-) delete mode 100644 arch/nios2/lib/board.c
arch/nios2/config.mk +2 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 -3
@@ -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
common/board_r.c +1 -1
@@ -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
PATCH v3 1/1 nios2: add generic board support
In reply to Stefan RoeseThis patch implements the generic board init as described in doc/README.generic-board.
---
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
arch/nios2/config.mk +2 -0
@@ -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 +13 -1
@@ -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 ; +}
arch/nios2/cpu/start.S +30 -4
@@ -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 +3 -0
@@ -7,4 +7,7 @@#ifndef _ASM_CONFIG_H_#define _ASM_CONFIG_H_ +#define CONFIG_SYS_GENERIC_BOARD +#define CONFIG_SYS_GENERIC_GLOBAL_DATA +#endif
arch/nios2/include/asm/u-boot.h +1 -9
@@ -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
@@ -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 -3
@@ -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
common/board_r.c +1 -1
@@ -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)
include/configs/nios2-generic.h +2 -0
@@ -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/*
Signature · 1 line
1.7.1
Thomas Chou
AppliedPATCH v3 1/1 nios2: add generic board support
Applied.
Thomas Chou