Add nds32 architecture with generic lib C files support.

Signed-off-by: Macpaul Lin <[email protected]>
---
 arch/nds32/lib/Makefile |   53 ++++++++
 arch/nds32/lib/board.c  |  341 +++++++++++++++++++++++++++++++++++++++++++++++
 arch/nds32/lib/bootm.c  |  209 +++++++++++++++++++++++++++++
 3 files changed, 603 insertions(+), 0 deletions(-)
 create mode 100644 arch/nds32/lib/Makefile
 create mode 100644 arch/nds32/lib/board.c
 create mode 100644 arch/nds32/lib/bootm.c

diff --git a/arch/nds32/lib/Makefile b/arch/nds32/lib/Makefile
new file mode 100644
index 0000000..0fe0351
--- /dev/null
+++ b/arch/nds32/lib/Makefile
@@ -0,0 +1,53 @@
+#
+# (C) Copyright 2000-2006
+# Wolfgang Denk, DENX Software Engineering, [email protected].
+#
+# Copyright (C) 2006 Andes Technology Corporation
+# Shawn Lin, Andes Technology Corporation <[email protected]>
+# Macpaul Lin, Andes Technology Corporation <[email protected]>
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+include $(TOPDIR)/config.mk
+
+LIB    = $(obj)lib$(ARCH).a
+
+OBJS   := board.o  bootm.o
+SOBJS  :=
+
+all:   $(LIB)
+
+$(LIB):        $(OBJS) $(SOBJS)
+       $(AR) crv $@ $^
+
+clean:
+       rm -f $(SOBJS) $(OBJS)
+
+distclean:     clean
+       rm -f $(LIB) core *.bak .depend
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/arch/nds32/lib/board.c b/arch/nds32/lib/board.c
new file mode 100644
index 0000000..d70d8ab
--- /dev/null
+++ b/arch/nds32/lib/board.c
@@ -0,0 +1,341 @@
+/*
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ *
+ * (C) Copyright 2002
+ * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Marius Groeger <[email protected]>
+ *
+ * Copyright 2006 (C) Andes Technology Corporation
+ * Shawn Lin, Andes Technology Corporation <[email protected]>
+ * Macpaul Lin, Andes Technology Corporation <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <stdio_dev.h>
+#include <timestamp.h>
+#include <version.h>
+#include <net.h>
+#include <version.h>
+#include <asm/global_data.h>
+#include <asm/andesboot.h>
+//#include <andes.h>
+
+//volatile bd_t sg_bd;
+//volatile gd_t g_gd;
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifndef CONFIG_IDENT_STRING
+#define CONFIG_IDENT_STRING ""
+#endif
+
+const char version_string[] =
+       U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;
+
+#ifdef CONFIG_DRIVER_CS8900
+extern void cs8900_get_enetaddr(uchar *addr);
+#endif
+
+#ifdef CONFIG_EPXA1DB_MAC_ADDR
+extern void epxa1db_set_mac_addr(bd_t* bd);
+#endif
+
+/*
+ * Breath some life into the board...
+ *
+ * Initialize an SMC for serial comms, and carry out some hardware
+ * tests.
+ *
+ * The first part of initialization is running from Flash memory;
+ * its main purpose is to initialize the RAM so that we
+ * can relocate the monitor code to RAM.
+ */
+
+void LED_Show(ulong u32Val)
+{
+       volatile ulong u32i;
+       LED_ShowHex(u32Val);
+       for(u32i=0; u32i<0x100000; u32i++); // delay
+}
+
+inline void wait_ms(unsigned long ms);
+
+struct NS16550 {
+       unsigned char rbr;              /* 0 */
+       int pad1:24;
+       unsigned char ier;              /* 1 */
+       int pad2:24;
+       unsigned char fcr;              /* 2 */
+       int pad3:24;
+       unsigned char lcr;              /* 3 */
+       int pad4:24;
+       unsigned char mcr;              /* 4 */
+       int pad5:24;
+       unsigned char lsr;              /* 5 */
+       int pad6:24;
+       unsigned char msr;              /* 6 */
+       int pad7:24;
+       unsigned char scr;              /* 7 */
+       int pad8:24;
+#if defined(CONFIG_OMAP)
+       unsigned char mdr1;             /* mode select reset TL16C750*/
+#endif
+#ifdef CONFIG_OMAP1510
+       int pad9:24;
+       unsigned long pad[10];
+       unsigned char osc_12m_sel;
+       int pad10:24;
+#endif
+} __attribute__ ((packed));
+
+
+void test_func(void)
+{
+       struct NS16550 *pND16500 = (struct NS16550*)0x98a00000;
+       memset(pND16500, 0, sizeof(struct NS16550));
+
+       printf("st size: %X  \r\n", sizeof(struct NS16550));
+
+       printf("ier  addr: %X  val: %X \r\n",&pND16500->ier, pND16500->ier);
+       pND16500->ier = 0xAA;
+       printf("ier  addr: %X  val: %X \r\n",&pND16500->ier, pND16500->ier);
+       pND16500->ier = 0x55AA;
+       printf("ier  addr: %X  val: %X \r\n",&pND16500->ier, pND16500->ier);
+
+       printf("lsr  addr: %X  val: %X \r\n",&pND16500->lsr, pND16500->lsr);
+       pND16500->lsr = 0xAA;
+       printf("lsr  addr: %X  val: %X \r\n",&pND16500->lsr, pND16500->lsr);
+       pND16500->lsr = 0x55AA;
+       printf("lsr  addr: %X  val: %X \r\n",&pND16500->lsr, pND16500->lsr);
+       printf("pad6  no addr  val: %X \r\n", pND16500->pad6);
+}
+
+/*
+ * 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 dependent #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);
+
+int print_cpuinfo (void);
+
+init_fnc_t *init_sequence[] = {
+#if defined(CONFIG_ARCH_CPU_INIT)
+       arch_cpu_init,          /* basic arch cpu dependent setup */
+#endif
+//     board_init,             /* basic board dependent setup */
+#if defined(CONFIG_USE_IRQ)
+       interrupt_init,         /* set up exceptions */
+#endif
+//     timer_init,             /* initialize timer */
+#ifdef CONFIG_FSL_ESDHC
+       get_clocks,
+#endif
+       env_init,               /* initialize environment */
+//     init_baudrate,          /* initialze baudrate settings */
+       serial_init,            /* serial communications setup */
+       console_init_f,         /* stage 1 init of console */
+//     display_banner,         /* say that we are here */
+#if defined(CONFIG_DISPLAY_CPUINFO)
+       print_cpuinfo,          /* display cpu info (and speed) */
+#endif
+#if defined(CONFIG_DISPLAY_BOARDINFO)
+       checkboard,             /* display board info */
+#endif
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+       init_func_i2c,
+#endif
+//     dram_init,              /* configure available RAM banks */
+//#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
+//     pci_init,
+//#endif
+       display_dram_config,
+       NULL,
+};
+
+void start_andesboot(void)
+{
+       init_fnc_t **init_fnc_ptr;
+       char *s;
+
+       ulong size;
+
+       /* Pointer is writable since we allocated a register for it */
+       gd = (gd_t*)(_andesboot_start - CONFIG_MALLOC_SIZE - sizeof(gd_t));
+       /* compiler optimization barrier needed for GCC >= 3.4 */
+       __asm__ __volatile__("": : :"memory");
+
+       memset ((void*)gd, 0, sizeof (gd_t));
+       gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
+       memset (gd->bd, 0, sizeof (bd_t));
+
+       gd->flags |= GD_FLG_RELOC;
+
+       for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
+               if ((*init_fnc_ptr)() != 0) {
+                       hang ();
+               }
+       }
+
+#if 0
+       /* set up bd strucuture */
+
+       /* basic cpu dependent setup */
+       cpu_init(); /* reserve stack size in DRAM, prepare for heap setup*/
+#endif
+       /* basic board dependent setup */
+       board_init(gd->bd); /* set arch-number & boot-params*/
+#if 0
+       /* initialize environment */
+//     env_init(); /* now refer to the env_flash.c */
+
+       /* serial communications setup */
+       serial_init();
+#endif
+       display_banner(gd->bd);
+
+test_func();
+
+       /* get the devices list going. */
+       stdio_init ();
+
+       /* set up execptions */
+       interrupt_init();
+#if 0
+       /* configure available RAM banks */
+       dram_init(gd->bd);
+#endif
+       display_dram_config(gd->bd);
+       /* configure available FLASH banks */
+
+#ifndef CONFIG_SYS_NO_FLASH
+       /* configure available FLASH banks */
+       display_flash_config (flash_init ());
+#endif /* CONFIG_SYS_NO_FLASH */
+
+//#endif
+
+       /* andesboot_end is defined in the board-specific linker script */
+       mem_malloc_init(_andesboot_start - CONFIG_MALLOC_SIZE, 
CONFIG_MALLOC_SIZE);
+
+       /* initialize environment */
+       env_relocate();
+
+       /* IP Address */
+       gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
+       /* MAC Address */
+       {
+               int i;
+               ulong reg;
+               char *s, *e;
+               char tmp[64];
+
+               i = getenv_r ("ethaddr", tmp, sizeof (tmp));
+               s = (i > 0) ? tmp : NULL;
+
+               for (reg = 0; reg < 6; ++reg) {
+                       gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 
16) : 0;
+                       if (s)
+                               s = (*e) ? e + 1 : e;
+               }
+       }
+
+#if defined(CONFIG_PCI)
+       pci_init(); /* Do pci configuration */
+#endif
+
+       /* enable exceptions */
+       enable_interrupts();
+
+/*
+ * FIXME: this should probably be rationalised into a standard call for
+ * each board, e.g. enet_mac_init() - but this'll do for now.
+ */
+#ifdef BOARD_POST_INIT // no defined
+       board_post_init(gd->bd);
+#endif
+
+       /* main_loop() can return to retry autoboot, if so just run it again. */
+       for (;;) {
+       main_loop();
+       }
+
+       /* NOTREACHED - no way out of command loop except booting */
+}
+
+void hang(void)
+{
+       puts ("### ERROR ### Please RESET the board ###\n");
+       for (;;);
+}
+
+
+void pretty_print_size(ulong size)
+{
+       if (size > 0x100000)
+         printf("%ld MB", size / 0x100000);
+       else
+         printf("%ld KB", size / 0x400);
+}
+
+void display_banner(bd_t *bd)
+{
+       printf ("\n\n%s\n\n", version_string);
+       printf ("ANDES maintain version %d.%d. 
Clock:%uMHz\n",VERSION_MAJOR_NUM,VERSION_MINOR_NUM,VERSION_CLOCK/1000000);
+       printf("ANDESboot code: %08lx -> %08lx\n", _andesboot_start, 
_andesboot_end);
+
+#ifdef CONFIG_USE_IRQ
+       printf("IRQ Stack: %08lx\n", IRQ_STACK_START);
+       printf("FIQ Stack: %08lx\n", FIQ_STACK_START);
+#endif
+}
+
+void display_dram_config(bd_t *bd)
+{
+       int i;
+
+       printf("DRAM Configuration:\n");
+
+       for(i=0; i<CONFIG_NR_DRAM_BANKS; i++)
+       {
+       printf("Bank #%d: %08lx ", i, bd->bi_dram[i].start);
+       pretty_print_size(bd->bi_dram[i].size);
+       printf("\n");
+       }
+}
+
+#ifndef CONFIG_SYS_NO_FLASH
+void display_flash_config (ulong size)
+{
+       puts ("Flash: ");
+       print_size (size, "\n");
+}
+#endif /* CONFIG_SYS_NO_FLASH */
+
diff --git a/arch/nds32/lib/bootm.c b/arch/nds32/lib/bootm.c
new file mode 100644
index 0000000..c0bbab1
--- /dev/null
+++ b/arch/nds32/lib/bootm.c
@@ -0,0 +1,209 @@
+/*
+ * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <[email protected]>
+ *
+ * Copyright 2006 (C) Andes Technology Corporation
+ * Shawn Lin, Andes Technology Corporation <[email protected]>
+ * Macpaul Lin, Andes Technology Corporation <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <asm/setup.h>
+#include <asm/andesboot.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+extern image_header_t header;  /* common/cmd_bootm.c */
+#undef DEBUG
+static struct tag *params;
+
+static void setup_start_tag(void)
+{
+       params = (struct tag *)gd->bd->bi_boot_params;
+
+       params->hdr.tag = ATAG_CORE;
+       params->hdr.size = tag_size(tag_core);
+
+       params->u.core.flags = 0;
+       params->u.core.pagesize = 0;
+       params->u.core.rootdev = 0;
+
+       params = tag_next(params);
+}
+
+
+static void setup_memory_tags(void)
+{
+       int i;
+
+       for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
+       {
+               params->hdr.tag = ATAG_MEM;
+               params->hdr.size = tag_size(tag_mem32);
+
+               params->u.mem.start = gd->bd->bi_dram[i].start;
+               params->u.mem.size = gd->bd->bi_dram[i].size;
+#ifdef not_complete_yet
+               printf("params->u.mem.start = %x\n", params->u.mem.start);
+               printf("params->u.mem.size = %x\n", params->u.mem.size);
+#endif /* end_of_not */
+               params = tag_next(params);
+       }
+}
+
+static void setup_commandline_tag(char *commandline)
+{
+       char *p;
+
+       if (commandline == NULL)
+       {
+               return;
+       }
+       /* eat leading white space */
+       for(p = commandline; *p == ' '; p++)
+         ;
+
+       /* skip non-existent command lines so the kernel will still
+        * use its default command line.
+        */
+       if(*p == '\0')
+               return;
+
+       params->hdr.tag = ATAG_CMDLINE;
+       params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
+
+       strcpy(params->u.cmdline.cmdline, p);
+
+       params = tag_next(params);
+}
+
+
+static void setup_clock_tags(void)
+{
+#if 0
+       params->hdr.tag = ATAG_CLOCK;
+       params->hdr.size = tag_size(tag_clock);
+       params->u.clock.clock_id = ACLOCK_BOOTCPU;
+       params->u.clock.clock_flags = 0;
+       params->u.clock.clock_hz = gd->cpu_hz;
+       params = tag_next(params);
+#endif
+}
+
+
+static void setup_ethernet_tag(char *addr, int index)
+{
+#if 0
+       char *s, *e;
+       int i;
+
+       params->hdr.tag = ATAG_ETHERNET;
+       params->hdr.size = tag_size(tag_ethernet);
+
+       params->u.ethernet.mac_index = index;
+       params->u.ethernet.mii_phy_addr = gd->bd->bi_phy_id[index];
+
+       s = addr;
+       for (i = 0; i < 6; i++) {
+               params->u.ethernet.hw_address[i] = simple_strtoul(s, &e, 16);
+               s = e + 1;
+       }
+
+       params = tag_next(params);
+#endif
+}
+
+static void setup_ethernet_tags(void)
+{
+#if 0
+       char name[16] = "ethaddr";
+       char *addr;
+       int i = 0;
+
+       do {
+               addr = getenv(name);
+               if (addr)
+                       params = setup_ethernet_tag(params, addr, i);
+               sprintf(name, "eth%daddr", ++i);
+       } while (i < 4);
+
+       params = tag_next(params);
+#endif
+}
+
+static void setup_end_tag(void)
+{
+       params->hdr.tag = ATAG_NONE;
+       params->hdr.size = 0;
+}
+
+
+void show_boot_progress(int progress)
+{
+       //printf("booting, please wait... \r\n");
+}
+
+static void setup_ramdisk_tag(unsigned long rd_start, unsigned long rd_end)
+{
+       if (rd_start == rd_end)
+               return params;
+
+       params->hdr.tag = ATAG_RDIMG;
+       params->hdr.size = tag_size(tag_mem_range);
+
+       params->u.mem_range.addr = rd_start;
+       params->u.mem_range.size = rd_end - rd_start;
+
+       params = tag_next(params);
+}
+
+
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
+{
+       void    (*theKernel)(int magic, void *tagtable);
+       char    *commandline = getenv("bootargs");
+
+       if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
+               return 1;
+
+       theKernel = (void *)images->ep;
+       show_boot_progress (1);
+
+       setup_start_tag();
+       setup_memory_tags();
+       if (images->rd_start) {
+               setup_ramdisk_tag(images->rd_start, images->rd_end);
+       }
+       setup_commandline_tag(commandline);
+       setup_end_tag();
+
+       printf("\nStarting kernel at %p (params at %p)...\n\n",
+                  theKernel, params);
+
+       cleanup_before_linux();
+       theKernel(0, params);
+       /* does not return */
+
+       return 1;
+
+}
-- 
1.7.1

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to