From patchwork Thu Aug 21 12:11:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 381942 X-Patchwork-Delegate: thomas@wytron.com.tw Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id F309B14008C for ; Thu, 21 Aug 2014 22:12:21 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7E9C04B729; Thu, 21 Aug 2014 14:12:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y0FBrrs6UGbc; Thu, 21 Aug 2014 14:12:18 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BB1CC4B71D; Thu, 21 Aug 2014 14:12:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 918B44B71D for ; Thu, 21 Aug 2014 14:12:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FG7nJWMwM5pD for ; Thu, 21 Aug 2014 14:12:09 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from darkstar.wytron.com.tw (220-132-188-42.HINET-IP.hinet.net [220.132.188.42]) by theia.denx.de (Postfix) with ESMTP id 4C3C24B71C for ; Thu, 21 Aug 2014 14:12:06 +0200 (CEST) Received: by darkstar.wytron.com.tw (Postfix, from userid 1000) id F053B7F81; Thu, 21 Aug 2014 20:12:03 +0800 (CST) From: Thomas Chou To: u-boot@lists.denx.de Date: Thu, 21 Aug 2014 20:11:16 +0800 Message-Id: <1408623076-9068-1-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 1.7.1 In-Reply-To: <53F5C35C.6070007@denx.de> References: <53F5C35C.6070007@denx.de> Cc: Scott McNutt Subject: [U-Boot] [PATCH v2] nios2: add generic board support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This patch implements the generic board init as described in doc/README.generic-board. Signed-off-by: Thomas Chou Signed-off-by: Scott McNutt Reviewed-by: Stefan Roese --- 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 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..9f17d8b 100644 --- a/arch/nios2/cpu/cpu.c +++ b/arch/nios2/cpu/cpu.c @@ -10,11 +10,13 @@ #include #include +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; +} 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@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 diff --git a/arch/nios2/include/asm/config.h b/arch/nios2/include/asm/config.h index cd29734..59546f0 100644 --- a/arch/nios2/include/asm/config.h +++ b/arch/nios2/include/asm/config.h @@ -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 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 /* 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 - * Scott McNutt - * - * (C) Copyright 2000-2002 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_STATUS_LED -#include -#endif -#if defined(CONFIG_SYS_NIOS_EPCSBASE) -#include -#endif -#ifdef CONFIG_CMD_NAND -#include /* 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)