sh: First support code of SuperH.
[oweals/u-boot.git] / lib_sh / board.c
1 /*
2  * Copyright (C) 2007
3  * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
20
21 #include <common.h>
22 #include <command.h>
23 #include <malloc.h>
24 #include <devices.h>
25 #include <version.h>
26 #include <net.h>
27 #include <environment.h>
28
29 extern void malloc_bin_reloc (void);
30 extern int cpu_init(void);
31 extern int board_init(void);
32 extern int dram_init(void);
33 extern int watchdog_init(void);
34 extern int timer_init(void);
35
36 const char version_string[] = U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
37
38 unsigned long monitor_flash_len = CFG_MONITOR_LEN;
39
40 static unsigned long mem_malloc_start;
41 static unsigned long mem_malloc_end;
42 static unsigned long mem_malloc_brk;
43
44 static void mem_malloc_init (void)
45 {
46
47         mem_malloc_start = (TEXT_BASE - CFG_GBL_DATA_SIZE - CFG_MALLOC_LEN);
48         mem_malloc_end = (mem_malloc_start + CFG_MALLOC_LEN - 16);
49         mem_malloc_brk = mem_malloc_start;
50         memset ((void *) mem_malloc_start, 0, 
51                 (mem_malloc_end - mem_malloc_start));
52 }
53
54 void *sbrk (ptrdiff_t increment)
55 {
56         unsigned long old = mem_malloc_brk;
57         unsigned long new = old + increment;
58
59         if ((new < mem_malloc_start) ||
60             (new > mem_malloc_end)) {
61                 return NULL;
62         }
63
64         mem_malloc_brk = new;
65         return (void *) old;
66 }
67
68 typedef int (init_fnc_t) (void);
69
70 init_fnc_t *init_sequence[] =
71 {
72         cpu_init,               /* basic cpu dependent setup */
73         board_init,             /* basic board dependent setup */
74         interrupt_init,         /* set up exceptions */
75         env_init,               /* event init */
76         serial_init,            /* SCIF init */
77         watchdog_init,
78         console_init_f,
79         display_options,
80         checkcpu,
81         checkboard,
82         dram_init,              /* SDRAM init */
83         NULL                    /* Terminate this list */
84 };
85
86 void sh_generic_init (void)
87 {
88         DECLARE_GLOBAL_DATA_PTR;
89
90         bd_t *bd;
91         init_fnc_t **init_fnc_ptr;
92         char *s, *e;
93         int i;
94
95         memset (gd, 0, CFG_GBL_DATA_SIZE);
96
97         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
98
99         gd->bd = (bd_t *) (gd + 1);             /* At end of global data */
100         gd->baudrate = CONFIG_BAUDRATE;
101
102         gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
103
104         bd = gd->bd;
105         bd->bi_memstart = CFG_SDRAM_BASE;
106         bd->bi_memsize = CFG_SDRAM_SIZE;
107         bd->bi_flashstart = CFG_FLASH_BASE;
108 #if defined(CFG_SRAM_BASE) && defined(CFG_SRAM_SIZE)
109         bd->bi_sramstart= CFG_SRAM_BASE;
110         bd->bi_sramsize = CFG_SRAM_SIZE;
111 #endif
112         bd->bi_baudrate = CONFIG_BAUDRATE;
113
114         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
115                 if ((*init_fnc_ptr) () != 0) {
116                         hang();
117                 }
118         }
119         
120         timer_init();
121         
122         /* flash_init need timer_init().(TMU) */
123         bd->bi_flashsize = flash_init();
124         printf("FLASH: %dMB\n", bd->bi_flashsize / (1024*1024));
125
126         mem_malloc_init();
127         malloc_bin_reloc();
128         env_relocate();
129
130 #if  (CONFIG_COMMANDS & CFG_CMD_NET)
131         bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
132         s = getenv ("ethaddr");
133         for (i = 0; i < 6; ++i) {
134                 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
135                 if (s) s = (*e) ? e + 1 : e;
136         }
137 #endif
138         devices_init();
139         jumptable_init();
140         console_init_r();
141         interrupt_init();
142 #ifdef BOARD_LATE_INIT
143         board_late_init ();
144 #endif
145 #if (CONFIG_COMMANDS & CFG_CMD_NET)
146 #if defined(CONFIG_NET_MULTI)
147         puts ("Net:   ");
148 #endif
149         eth_initialize(gd->bd);
150 #endif
151         while (1) {
152                 main_loop();
153         }
154 }
155
156
157 /***********************************************************************/
158
159 void hang (void)
160 {
161         puts ("Board ERROR \n");
162         for (;;);
163 }