1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <common.h>
29#include <command.h>
30#include <malloc.h>
31#include <stdio_dev.h>
32#include <config.h>
33#if defined(CONFIG_CMD_IDE)
34#include <ide.h>
35#endif
36#ifdef CONFIG_STATUS_LED
37#include <status_led.h>
38#endif
39#include <net.h>
40#include <serial.h>
41#include <version.h>
42#if defined(CONFIG_POST)
43#include <post.h>
44#endif
45#ifdef CONFIG_PS2KBD
46#include <keyboard.h>
47#endif
48#ifdef CONFIG_CMD_AMBAPP
49#include <ambapp.h>
50#endif
51
52#ifdef CONFIG_BITBANGMII
53#include <miiphy.h>
54#endif
55
56DECLARE_GLOBAL_DATA_PTR;
57
58
59
60
61
62
63
64extern void timer_interrupt_init(void);
65extern void malloc_bin_reloc(void);
66extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
67extern int prom_init(void);
68
69#if defined(CONFIG__CMD_DOC)
70void doc_init(void);
71#endif
72
73#if !defined(CONFIG_SYS_NO_FLASH)
74static char *failed = "*** failed ***\n";
75#endif
76
77#include <environment.h>
78
79ulong monitor_flash_len;
80
81
82
83
84
85
86
87
88static int init_baudrate(void)
89{
90 char tmp[64];
91 int i = getenv_r("baudrate", tmp, sizeof(tmp));
92
93 gd->baudrate = (i > 0)
94 ? (int)simple_strtoul(tmp, NULL, 10)
95 : CONFIG_BAUDRATE;
96 return (0);
97}
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113typedef int (init_fnc_t) (void);
114
115#define WATCHDOG_RESET(x)
116
117
118
119
120
121
122init_fnc_t *init_sequence[] = {
123
124#if defined(CONFIG_BOARD_EARLY_INIT_F)
125 board_early_init_f,
126#endif
127 serial_init,
128
129 init_timebase,
130
131#if defined(CONFIG_CMD_AMBAPP)
132 ambapp_init_reloc,
133#endif
134
135 env_init,
136
137 init_baudrate,
138
139 console_init_f,
140 display_options,
141
142 checkcpu,
143 checkboard,
144#if defined(CONFIG_MISC_INIT_F)
145 misc_init_f,
146#endif
147
148#ifdef CONFIG_POST
149 post_init_f,
150#endif
151
152 NULL,
153
154
155
156
157
158};
159
160
161
162
163
164
165
166#ifdef DEBUG_INIT_SEQUENCE
167char *str_init_seq = "INIT_SEQ 00\n";
168char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
169#endif
170
171void board_init_f(ulong bootflag)
172{
173 cmd_tbl_t *cmdtp;
174 bd_t *bd;
175 unsigned char *s;
176 init_fnc_t **init_fnc_ptr;
177 int j;
178 int i;
179 char *e;
180
181#ifndef CONFIG_SYS_NO_FLASH
182 ulong flash_size;
183#endif
184
185 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
186
187
188 memset((void *)gd, 0, sizeof(gd_t));
189
190 gd->bd = (bd_t *) (gd + 1);
191 gd->baudrate = CONFIG_BAUDRATE;
192 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
193
194 bd = gd->bd;
195 bd->bi_memstart = CONFIG_SYS_RAM_BASE;
196 bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
197 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
198#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
199 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
200 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
201#endif
202 bd->bi_baudrate = CONFIG_BAUDRATE;
203 bd->bi_bootflags = bootflag;
204
205 gd->flags |= GD_FLG_RELOC;
206 gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
207
208 for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
209 ++init_fnc_ptr, j++) {
210#ifdef DEBUG_INIT_SEQUENCE
211 if (j > 9)
212 str_init_seq[9] = '0' + (j / 10);
213 str_init_seq[10] = '0' + (j - (j / 10) * 10);
214 serial_puts(str_init_seq);
215#endif
216 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
217 hang();
218 }
219 }
220#ifdef DEBUG_INIT_SEQUENCE
221 serial_puts(str_init_seq_done);
222#endif
223
224
225
226
227
228
229
230
231
232
233
234
235#ifdef DEBUG_MEM_LAYOUT
236 printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE);
237 printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR);
238 printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
239 CONFIG_SYS_MONITOR_LEN);
240 printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
241 CONFIG_SYS_MALLOC_LEN);
242 printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
243 CONFIG_SYS_STACK_SIZE);
244 printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
245 CONFIG_SYS_PROM_SIZE);
246 printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
247 CONFIG_SYS_GBL_DATA_SIZE);
248#endif
249
250#ifdef CONFIG_POST
251 post_bootmode_init();
252 post_run(NULL, POST_ROM | post_bootmode_get(0));
253#endif
254
255
256
257
258 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
259 ulong addr;
260 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
261#if DEBUG_COMMANDS
262 printf("Command \"%s\": 0x%08lx => 0x%08lx\n",
263 cmdtp->name, (ulong) (cmdtp->cmd), addr);
264#endif
265 cmdtp->cmd =
266 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
267
268 addr = (ulong) (cmdtp->name) + gd->reloc_off;
269 cmdtp->name = (char *)addr;
270
271 if (cmdtp->usage) {
272 addr = (ulong) (cmdtp->usage) + gd->reloc_off;
273 cmdtp->usage = (char *)addr;
274 }
275#ifdef CONFIG_SYS_LONGHELP
276 if (cmdtp->help) {
277 addr = (ulong) (cmdtp->help) + gd->reloc_off;
278 cmdtp->help = (char *)addr;
279 }
280#endif
281 }
282
283#if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
284 puts("AMBA:\n");
285 do_ambapp_print(NULL, 0, 0, NULL);
286#endif
287
288
289 cpu_init_r();
290
291
292 timer_interrupt_init();
293
294
295
296
297
298
299 interrupt_init();
300
301
302 mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
303 CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
304 malloc_bin_reloc();
305
306#if !defined(CONFIG_SYS_NO_FLASH)
307 puts("FLASH: ");
308
309 if ((flash_size = flash_init()) > 0) {
310# ifdef CONFIG_SYS_FLASH_CHECKSUM
311 print_size(flash_size, "");
312
313
314
315
316
317 s = getenv("flashchecksum");
318 if (s && (*s == 'y')) {
319 printf(" CRC: %08lX",
320 crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
321 flash_size)
322 );
323 }
324 putc('\n');
325# else
326 print_size(flash_size, "\n");
327# endif
328 } else {
329 puts(failed);
330 hang();
331 }
332
333 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
334 bd->bi_flashsize = flash_size;
335#if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
336 bd->bi_flashoffset = monitor_flash_len;
337#else
338 bd->bi_flashoffset = 0;
339#endif
340#else
341 bd->bi_flashsize = 0;
342 bd->bi_flashstart = 0;
343 bd->bi_flashoffset = 0;
344#endif
345
346#ifdef CONFIG_SPI
347# if !defined(CONFIG_ENV_IS_IN_EEPROM)
348 spi_init_f();
349# endif
350 spi_init_r();
351#endif
352
353
354 env_relocate();
355
356#if defined(CONFIG_BOARD_LATE_INIT)
357 board_late_init();
358#endif
359
360#ifdef CONFIG_ID_EEPROM
361 mac_read_from_eeprom();
362#endif
363
364
365 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
366#if defined(CONFIG_PCI)
367
368
369
370 pci_init();
371#endif
372
373
374 stdio_init();
375
376
377 jumptable_init();
378
379
380 console_init_r();
381
382#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
383 serial_buffered_init();
384#endif
385
386#ifdef CONFIG_STATUS_LED
387 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
388#endif
389
390 udelay(20);
391
392 set_timer(0);
393
394
395 if ((s = getenv("loadaddr")) != NULL) {
396 load_addr = simple_strtoul(s, NULL, 16);
397 }
398#if defined(CONFIG_CMD_NET)
399 if ((s = getenv("bootfile")) != NULL) {
400 copy_filename(BootFile, s, sizeof(BootFile));
401 }
402#endif
403
404 WATCHDOG_RESET();
405
406#if defined(CONFIG_CMD_DOC)
407 WATCHDOG_RESET();
408 puts("DOC: ");
409 doc_init();
410#endif
411
412#ifdef CONFIG_BITBANGMII
413 bb_miiphy_init();
414#endif
415#if defined(CONFIG_CMD_NET)
416#if defined(CONFIG_NET_MULTI)
417 WATCHDOG_RESET();
418 puts("Net: ");
419#endif
420 eth_initialize(bd);
421#endif
422
423#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
424 WATCHDOG_RESET();
425 debug("Reset Ethernet PHY\n");
426 reset_phy();
427#endif
428
429#ifdef CONFIG_POST
430 post_run(NULL, POST_RAM | post_bootmode_get(0));
431#endif
432
433#if defined(CONFIG_CMD_IDE)
434 WATCHDOG_RESET();
435 puts("IDE: ");
436 ide_init();
437#endif
438
439#ifdef CONFIG_LAST_STAGE_INIT
440 WATCHDOG_RESET();
441
442
443
444
445
446 last_stage_init();
447#endif
448
449#ifdef CONFIG_PS2KBD
450 puts("PS/2: ");
451 kbd_init();
452#endif
453 prom_init();
454
455
456 for (;;) {
457 WATCHDOG_RESET();
458 main_loop();
459 }
460
461}
462
463void hang(void)
464{
465 puts("### ERROR ### Please RESET the board ###\n");
466#ifdef CONFIG_SHOW_BOOT_PROGRESS
467 show_boot_progress(-30);
468#endif
469 for (;;) ;
470}
471
472
473