blob: 2cd60d76be28e4f51c3144abde4d4eb3e4c13044 [file] [log] [blame]
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09001/*
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
29extern void malloc_bin_reloc (void);
30extern int cpu_init(void);
31extern int board_init(void);
32extern int dram_init(void);
33extern int watchdog_init(void);
34extern int timer_init(void);
35
36const char version_string[] = U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
37
38unsigned long monitor_flash_len = CFG_MONITOR_LEN;
39
40static unsigned long mem_malloc_start;
41static unsigned long mem_malloc_end;
42static unsigned long mem_malloc_brk;
43
44static 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;
Wolfgang Denk61fb15c52007-12-27 01:52:50 +010050 memset ((void *) mem_malloc_start, 0,
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090051 (mem_malloc_end - mem_malloc_start));
52}
53
54void *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
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090068static int sh_flash_init(void)
69{
70 DECLARE_GLOBAL_DATA_PTR;
71
72 gd->bd->bi_flashsize = flash_init();
73 printf("FLASH: %dMB\n", gd->bd->bi_flashsize / (1024*1024));
74
75 return 0;
76}
77
78#if defined(CONFIG_CMD_NAND)
79void nand_init (void);
80static int sh_nand_init(void)
81{
82 printf("NAND: ");
83 nand_init(); /* go init the NAND */
84 return 0;
85}
86#endif /* CONFIG_CMD_NAND */
87
88#if defined(CONFIG_CMD_IDE)
89#include <ide.h>
90static int sh_marubun_init(void)
91{
92 puts ("IDE: ");
93 ide_init();
94 return 0;
95}
96#endif /* (CONFIG_CMD_IDE) */
97
98static int sh_mem_env_init(void)
99{
100 mem_malloc_init();
101 malloc_bin_reloc();
102 env_relocate();
103 jumptable_init();
104 return 0;
105}
106
107static int sh_net_init(void)
108{
109 DECLARE_GLOBAL_DATA_PTR;
110 char *s, *e;
111 int i;
112
113 gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
114 s = getenv("ethaddr");
115 for (i = 0; i < 6; ++i) {
116 gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
117 if (s) s = (*e) ? e + 1 : e;
118 }
119
120 return 0;
121}
122
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900123typedef int (init_fnc_t) (void);
124
125init_fnc_t *init_sequence[] =
126{
127 cpu_init, /* basic cpu dependent setup */
128 board_init, /* basic board dependent setup */
129 interrupt_init, /* set up exceptions */
130 env_init, /* event init */
131 serial_init, /* SCIF init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900132 watchdog_init, /* watchdog init */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900133 console_init_f,
134 display_options,
135 checkcpu,
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900136 checkboard, /* Check support board */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900137 dram_init, /* SDRAM init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900138 timer_init, /* SuperH Timer (TCNT0 only) init */
139 sh_flash_init, /* Flash memory(NOR) init*/
140 sh_mem_env_init,
141#if defined(CONFIG_CMD_NAND)
142 sh_nand_init, /* Flash memory (NAND) init */
143#endif
144 devices_init,
145 console_init_r,
146 interrupt_init,
147#ifdef BOARD_LATE_INIT
148 board_late_init,
149#endif
150#if defined(CONFIG_CMD_NET)
151 sh_net_init, /* SH specific eth init */
152#endif
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900153 NULL /* Terminate this list */
154};
155
156void sh_generic_init (void)
157{
158 DECLARE_GLOBAL_DATA_PTR;
159
160 bd_t *bd;
161 init_fnc_t **init_fnc_ptr;
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900162 char *s;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900163 int i;
164
165 memset (gd, 0, CFG_GBL_DATA_SIZE);
166
167 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
168
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900169 gd->bd = (bd_t *) (gd + 1); /* At end of global data */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900170 gd->baudrate = CONFIG_BAUDRATE;
171
172 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
173
174 bd = gd->bd;
175 bd->bi_memstart = CFG_SDRAM_BASE;
176 bd->bi_memsize = CFG_SDRAM_SIZE;
177 bd->bi_flashstart = CFG_FLASH_BASE;
178#if defined(CFG_SRAM_BASE) && defined(CFG_SRAM_SIZE)
179 bd->bi_sramstart= CFG_SRAM_BASE;
180 bd->bi_sramsize = CFG_SRAM_SIZE;
181#endif
182 bd->bi_baudrate = CONFIG_BAUDRATE;
183
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900184 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr , i++) {
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900185 if ((*init_fnc_ptr) () != 0) {
186 hang();
187 }
188 }
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900189
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900190#if defined(CONFIG_CMD_NET)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900191 puts ("Net: ");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900192 eth_initialize(gd->bd);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900193
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100194 if ((s = getenv ("bootfile")) != NULL) {
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900195 copy_filename (BootFile, s, sizeof (BootFile));
196 }
197#endif /* CONFIG_CMD_NET */
198
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900199 while (1) {
200 main_loop();
201 }
202}
203
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900204/***********************************************************************/
205
206void hang (void)
207{
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900208 puts ("Board ERROR\n");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900209 for (;;);
210}