]> git.ipfire.org Git - people/ms/u-boot.git/blob - lib_ppc/board.c
* Patch by Gary Jennejohn, 11 Sep 2003:
[people/ms/u-boot.git] / lib_ppc / board.c
1 /*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 #include <common.h>
25 #include <watchdog.h>
26 #include <command.h>
27 #include <malloc.h>
28 #include <devices.h>
29 #ifdef CONFIG_8xx
30 #include <mpc8xx.h>
31 #endif
32 #ifdef CONFIG_5xx
33 #include <mpc5xx.h>
34 #endif
35 #ifdef CONFIG_MPC5XXX
36 #include <mpc5xxx.h>
37 #endif
38 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
39 #include <ide.h>
40 #endif
41 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
42 #include <scsi.h>
43 #endif
44 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
45 #include <kgdb.h>
46 #endif
47 #ifdef CONFIG_STATUS_LED
48 #include <status_led.h>
49 #endif
50 #include <net.h>
51 #ifdef CFG_ALLOC_DPRAM
52 #if !defined(CONFIG_8260)
53 #include <commproc.h>
54 #endif
55 #endif
56 #include <version.h>
57 #if defined(CONFIG_BAB7xx)
58 #include <w83c553f.h>
59 #endif
60 #include <dtt.h>
61 #if defined(CONFIG_POST)
62 #include <post.h>
63 #endif
64 #if defined(CONFIG_LOGBUFFER)
65 #include <logbuff.h>
66 #endif
67
68 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
69 void doc_init (void);
70 #endif
71 #if defined(CONFIG_HARD_I2C) || \
72 defined(CONFIG_SOFT_I2C)
73 #include <i2c.h>
74 #endif
75 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
76 void nand_init (void);
77 #endif
78
79 static char *failed = "*** failed ***\n";
80
81 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
82 extern flash_info_t flash_info[];
83 #endif
84
85 #include <environment.h>
86
87 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
88 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
89 defined(CFG_ENV_IS_IN_NVRAM)
90 #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
91 #else
92 #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
93 #endif
94
95 extern ulong __init_end;
96 extern ulong _end;
97 ulong monitor_flash_len;
98
99 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
100 #include <bedbug/type.h>
101 #endif
102
103 /*
104 * Begin and End of memory area for malloc(), and current "brk"
105 */
106 static ulong mem_malloc_start = 0;
107 static ulong mem_malloc_end = 0;
108 static ulong mem_malloc_brk = 0;
109
110 /************************************************************************
111 * Utilities *
112 ************************************************************************
113 */
114
115 /*
116 * The Malloc area is immediately below the monitor copy in DRAM
117 */
118 static void mem_malloc_init (void)
119 {
120 DECLARE_GLOBAL_DATA_PTR;
121
122 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
123
124 mem_malloc_end = dest_addr;
125 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
126 mem_malloc_brk = mem_malloc_start;
127
128 memset ((void *) mem_malloc_start,
129 0,
130 mem_malloc_end - mem_malloc_start);
131 }
132
133 void *sbrk (ptrdiff_t increment)
134 {
135 ulong old = mem_malloc_brk;
136 ulong new = old + increment;
137
138 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
139 return (NULL);
140 }
141 mem_malloc_brk = new;
142 return ((void *) old);
143 }
144
145 char *strmhz (char *buf, long hz)
146 {
147 long l, n;
148 long m;
149
150 n = hz / 1000000L;
151 l = sprintf (buf, "%ld", n);
152 m = (hz % 1000000L) / 1000L;
153 if (m != 0)
154 sprintf (buf + l, ".%03ld", m);
155 return (buf);
156 }
157
158 /*
159 * All attempts to come up with a "common" initialization sequence
160 * that works for all boards and architectures failed: some of the
161 * requirements are just _too_ different. To get rid of the resulting
162 * mess of board dependend #ifdef'ed code we now make the whole
163 * initialization sequence configurable to the user.
164 *
165 * The requirements for any new initalization function is simple: it
166 * receives a pointer to the "global data" structure as it's only
167 * argument, and returns an integer return code, where 0 means
168 * "continue" and != 0 means "fatal error, hang the system".
169 */
170 typedef int (init_fnc_t) (void);
171
172 /************************************************************************
173 * Init Utilities *
174 ************************************************************************
175 * Some of this code should be moved into the core functions,
176 * but let's get it working (again) first...
177 */
178
179 static int init_baudrate (void)
180 {
181 DECLARE_GLOBAL_DATA_PTR;
182
183 uchar tmp[64]; /* long enough for environment variables */
184 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
185
186 gd->baudrate = (i > 0)
187 ? (int) simple_strtoul (tmp, NULL, 10)
188 : CONFIG_BAUDRATE;
189 return (0);
190 }
191
192 /***********************************************************************/
193
194 static int init_func_ram (void)
195 {
196 DECLARE_GLOBAL_DATA_PTR;
197
198 #ifdef CONFIG_BOARD_TYPES
199 int board_type = gd->board_type;
200 #else
201 int board_type = 0; /* use dummy arg */
202 #endif
203 puts ("DRAM: ");
204
205 if ((gd->ram_size = initdram (board_type)) > 0) {
206 print_size (gd->ram_size, "\n");
207 return (0);
208 }
209 puts (failed);
210 return (1);
211 }
212
213 /***********************************************************************/
214
215 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
216 static int init_func_i2c (void)
217 {
218 puts ("I2C: ");
219 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
220 puts ("ready\n");
221 return (0);
222 }
223 #endif
224
225 /***********************************************************************/
226
227 #if defined(CONFIG_WATCHDOG)
228 static int init_func_watchdog_init (void)
229 {
230 puts (" Watchdog enabled\n");
231 WATCHDOG_RESET ();
232 return (0);
233 }
234 # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
235
236 static int init_func_watchdog_reset (void)
237 {
238 WATCHDOG_RESET ();
239 return (0);
240 }
241 # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
242 #else
243 # define INIT_FUNC_WATCHDOG_INIT /* undef */
244 # define INIT_FUNC_WATCHDOG_RESET /* undef */
245 #endif /* CONFIG_WATCHDOG */
246
247 /************************************************************************
248 * Initialization sequence *
249 ************************************************************************
250 */
251
252 init_fnc_t *init_sequence[] = {
253
254 #if defined(CONFIG_BOARD_PRE_INIT)
255 board_pre_init, /* very early board init code (fpga boot, etc.) */
256 #endif
257
258 get_clocks, /* get CPU and bus clocks (etc.) */
259 init_timebase,
260 #ifdef CFG_ALLOC_DPRAM
261 #if !defined(CONFIG_8260)
262 dpram_init,
263 #endif
264 #endif
265 #if defined(CONFIG_BOARD_POSTCLK_INIT)
266 board_postclk_init,
267 #endif
268 env_init,
269 init_baudrate,
270 serial_init,
271 console_init_f,
272 display_options,
273 #if defined(CONFIG_8260)
274 prt_8260_rsr,
275 prt_8260_clks,
276 #endif /* CONFIG_8260 */
277 checkcpu,
278 #if defined(CONFIG_MPC5XXX)
279 prt_mpc5xxx_clks,
280 #endif /* CONFIG_MPC5XXX */
281 checkboard,
282 INIT_FUNC_WATCHDOG_INIT
283 #if defined(CONFIG_BMW) || \
284 defined(CONFIG_COGENT) || \
285 defined(CONFIG_HYMOD) || \
286 defined(CONFIG_RSD_PROTO) || \
287 defined(CONFIG_W7O)
288 misc_init_f,
289 #endif
290 INIT_FUNC_WATCHDOG_RESET
291 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
292 init_func_i2c,
293 #endif
294 #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
295 dtt_init,
296 #endif
297 #ifdef CONFIG_POST
298 post_init_f,
299 #endif
300 INIT_FUNC_WATCHDOG_RESET
301 init_func_ram,
302 #if defined(CFG_DRAM_TEST)
303 testdram,
304 #endif /* CFG_DRAM_TEST */
305 INIT_FUNC_WATCHDOG_RESET
306
307 NULL, /* Terminate this list */
308 };
309
310 /************************************************************************
311 *
312 * This is the first part of the initialization sequence that is
313 * implemented in C, but still running from ROM.
314 *
315 * The main purpose is to provide a (serial) console interface as
316 * soon as possible (so we can see any error messages), and to
317 * initialize the RAM so that we can relocate the monitor code to
318 * RAM.
319 *
320 * Be aware of the restrictions: global data is read-only, BSS is not
321 * initialized, and stack space is limited to a few kB.
322 *
323 ************************************************************************
324 */
325
326 void board_init_f (ulong bootflag)
327 {
328 DECLARE_GLOBAL_DATA_PTR;
329
330 bd_t *bd;
331 ulong len, addr, addr_sp;
332 gd_t *id;
333 init_fnc_t **init_fnc_ptr;
334 #ifdef CONFIG_PRAM
335 int i;
336 ulong reg;
337 uchar tmp[64]; /* long enough for environment variables */
338 #endif
339
340 /* Pointer is writable since we allocated a register for it */
341 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
342
343 #ifndef CONFIG_8260
344 /* Clear initial global data */
345 memset ((void *) gd, 0, sizeof (gd_t));
346 #endif
347
348 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
349 if ((*init_fnc_ptr) () != 0) {
350 hang ();
351 }
352 }
353
354 /*
355 * Now that we have DRAM mapped and working, we can
356 * relocate the code and continue running from DRAM.
357 *
358 * Reserve memory at end of RAM for (top down in that order):
359 * - kernel log buffer
360 * - protected RAM
361 * - LCD framebuffer
362 * - monitor code
363 * - board info struct
364 */
365 len = (ulong)&_end - CFG_MONITOR_BASE;
366
367 #ifndef CONFIG_VERY_BIG_RAM
368 addr = CFG_SDRAM_BASE + gd->ram_size;
369 #else
370 /* only allow stack below 256M */
371 addr = CFG_SDRAM_BASE +
372 (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
373 #endif
374
375 #ifdef CONFIG_LOGBUFFER
376 /* reserve kernel log buffer */
377 addr -= (LOGBUFF_RESERVE);
378 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
379 #endif
380
381 #ifdef CONFIG_PRAM
382 /*
383 * reserve protected RAM
384 */
385 i = getenv_r ("pram", tmp, sizeof (tmp));
386 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
387 addr -= (reg << 10); /* size is in kB */
388 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
389 #endif /* CONFIG_PRAM */
390
391 /* round down to next 4 kB limit */
392 addr &= ~(4096 - 1);
393 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
394
395 #ifdef CONFIG_LCD
396 /* reserve memory for LCD display (always full pages) */
397 addr = lcd_setmem (addr);
398 gd->fb_base = addr;
399 #endif /* CONFIG_LCD */
400
401 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
402 /* reserve memory for video display (always full pages) */
403 addr = video_setmem (addr);
404 gd->fb_base = addr;
405 #endif /* CONFIG_VIDEO */
406
407 /*
408 * reserve memory for U-Boot code, data & bss
409 * round down to next 4 kB limit
410 */
411 addr -= len;
412 addr &= ~(4096 - 1);
413
414 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
415
416 #ifdef CONFIG_AMIGAONEG3SE
417 gd->relocaddr = addr;
418 #endif
419
420 /*
421 * reserve memory for malloc() arena
422 */
423 addr_sp = addr - TOTAL_MALLOC_LEN;
424 debug ("Reserving %dk for malloc() at: %08lx\n",
425 TOTAL_MALLOC_LEN >> 10, addr_sp);
426
427 /*
428 * (permanently) allocate a Board Info struct
429 * and a permanent copy of the "global" data
430 */
431 addr_sp -= sizeof (bd_t);
432 bd = (bd_t *) addr_sp;
433 gd->bd = bd;
434 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
435 sizeof (bd_t), addr_sp);
436 addr_sp -= sizeof (gd_t);
437 id = (gd_t *) addr_sp;
438 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
439 sizeof (gd_t), addr_sp);
440
441 /*
442 * Finally, we set up a new (bigger) stack.
443 *
444 * Leave some safety gap for SP, force alignment on 16 byte boundary
445 * Clear initial stack frame
446 */
447 addr_sp -= 16;
448 addr_sp &= ~0xF;
449 *((ulong *) addr_sp)-- = 0;
450 *((ulong *) addr_sp)-- = 0;
451 debug ("Stack Pointer at: %08lx\n", addr_sp);
452
453 /*
454 * Save local variables to board info struct
455 */
456
457 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
458 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
459
460 #ifdef CONFIG_IP860
461 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
462 bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
463 #else
464 bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
465 bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
466 #endif
467
468 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
469 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
470 #endif
471 #if defined(CONFIG_MPC5XXX)
472 bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
473 #endif
474
475 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
476
477 WATCHDOG_RESET ();
478 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
479 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
480 #if defined(CONFIG_8260)
481 bd->bi_cpmfreq = gd->cpm_clk;
482 bd->bi_brgfreq = gd->brg_clk;
483 bd->bi_sccfreq = gd->scc_clk;
484 bd->bi_vco = gd->vco_out;
485 #endif /* CONFIG_8260 */
486 #if defined(CONFIG_MPC5XXX)
487 bd->bi_ipbfreq = gd->ipb_clk;
488 bd->bi_pcifreq = gd->pci_clk;
489 #endif /* CONFIG_MPC5XXX */
490 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
491
492 #ifdef CFG_EXTBDINFO
493 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
494 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
495
496 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
497 bd->bi_plb_busfreq = gd->bus_clk;
498 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
499 bd->bi_pci_busfreq = get_PCI_freq ();
500 #endif
501 #endif
502
503 debug ("New Stack Pointer is: %08lx\n", addr_sp);
504
505 WATCHDOG_RESET ();
506
507 #ifdef CONFIG_POST
508 post_bootmode_init();
509 post_run (NULL, POST_ROM | post_bootmode_get(0));
510 #endif
511
512 WATCHDOG_RESET();
513
514 memcpy (id, (void *)gd, sizeof (gd_t));
515
516 relocate_code (addr_sp, id, addr);
517
518 /* NOTREACHED - relocate_code() does not return */
519 }
520
521
522 /************************************************************************
523 *
524 * This is the next part if the initialization sequence: we are now
525 * running from RAM and have a "normal" C environment, i. e. global
526 * data can be written, BSS has been cleared, the stack size in not
527 * that critical any more, etc.
528 *
529 ************************************************************************
530 */
531
532 void board_init_r (gd_t *id, ulong dest_addr)
533 {
534 DECLARE_GLOBAL_DATA_PTR;
535 cmd_tbl_t *cmdtp;
536 char *s, *e;
537 bd_t *bd;
538 int i;
539 extern void malloc_bin_reloc (void);
540 #ifndef CFG_ENV_IS_NOWHERE
541 extern char * env_name_spec;
542 #endif
543
544 #ifndef CFG_NO_FLASH
545 ulong flash_size;
546 #endif
547
548 gd = id; /* initialize RAM version of global data */
549 bd = gd->bd;
550
551 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
552
553 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
554
555 WATCHDOG_RESET ();
556
557 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
558
559 monitor_flash_len = (ulong)&__init_end - dest_addr;
560
561 /*
562 * We have to relocate the command table manually
563 */
564 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
565 ulong addr;
566 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
567 #if 0
568 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
569 cmdtp->name, (ulong) (cmdtp->cmd), addr);
570 #endif
571 cmdtp->cmd =
572 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
573
574 addr = (ulong)(cmdtp->name) + gd->reloc_off;
575 cmdtp->name = (char *)addr;
576
577 if (cmdtp->usage) {
578 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
579 cmdtp->usage = (char *)addr;
580 }
581 #ifdef CFG_LONGHELP
582 if (cmdtp->help) {
583 addr = (ulong)(cmdtp->help) + gd->reloc_off;
584 cmdtp->help = (char *)addr;
585 }
586 #endif
587 }
588 /* there are some other pointer constants we must deal with */
589 #ifndef CFG_ENV_IS_NOWHERE
590 env_name_spec += gd->reloc_off;
591 #endif
592
593 WATCHDOG_RESET ();
594
595 #ifdef CONFIG_LOGBUFFER
596 logbuff_init_ptrs ();
597 #endif
598 #ifdef CONFIG_POST
599 post_output_backlog ();
600 post_reloc ();
601 #endif
602
603 WATCHDOG_RESET();
604
605 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
606 icache_enable (); /* it's time to enable the instruction cache */
607 #endif
608
609 #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
610 /*
611 * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
612 * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
613 * bridge there.
614 */
615 pci_init ();
616 #endif
617 #if defined(CONFIG_BAB7xx)
618 /*
619 * Initialise the ISA bridge
620 */
621 initialise_w83c553f ();
622 #endif
623
624 asm ("sync ; isync");
625
626 /*
627 * Setup trap handlers
628 */
629 trap_init (dest_addr);
630
631 #if !defined(CFG_NO_FLASH)
632 puts ("FLASH: ");
633
634 if ((flash_size = flash_init ()) > 0) {
635 # ifdef CFG_FLASH_CHECKSUM
636 print_size (flash_size, "");
637 /*
638 * Compute and print flash CRC if flashchecksum is set to 'y'
639 *
640 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
641 */
642 s = getenv ("flashchecksum");
643 if (s && (*s == 'y')) {
644 printf (" CRC: %08lX",
645 crc32 (0,
646 (const unsigned char *) CFG_FLASH_BASE,
647 flash_size)
648 );
649 }
650 putc ('\n');
651 # else /* !CFG_FLASH_CHECKSUM */
652 print_size (flash_size, "\n");
653 # endif /* CFG_FLASH_CHECKSUM */
654 } else {
655 puts (failed);
656 hang ();
657 }
658
659 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
660 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
661 # if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
662 bd->bi_flashoffset = 0;
663 # elif CFG_MONITOR_BASE == CFG_FLASH_BASE
664 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
665 # else
666 bd->bi_flashoffset = 0;
667 # endif
668 #else /* CFG_NO_FLASH */
669
670 bd->bi_flashsize = 0;
671 bd->bi_flashstart = 0;
672 bd->bi_flashoffset = 0;
673 #endif /* !CFG_NO_FLASH */
674
675 WATCHDOG_RESET ();
676
677 /* initialize higher level parts of CPU like time base and timers */
678 cpu_init_r ();
679
680 WATCHDOG_RESET ();
681
682 /* initialize malloc() area */
683 mem_malloc_init ();
684 malloc_bin_reloc ();
685
686 #ifdef CONFIG_SPI
687 # if !defined(CFG_ENV_IS_IN_EEPROM)
688 spi_init_f ();
689 # endif
690 spi_init_r ();
691 #endif
692
693 /* relocate environment function pointers etc. */
694 env_relocate ();
695
696 /*
697 * Fill in missing fields of bd_info.
698 * We do this here, where we have "normal" access to the
699 * environment; we used to do this still running from ROM,
700 * where had to use getenv_r(), which can be pretty slow when
701 * the environment is in EEPROM.
702 */
703 s = getenv ("ethaddr");
704 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
705 if (s == NULL)
706 board_get_enetaddr (bd->bi_enetaddr);
707 else
708 #endif
709 for (i = 0; i < 6; ++i) {
710 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
711 if (s)
712 s = (*e) ? e + 1 : e;
713 }
714 #ifdef CONFIG_HERMES
715 if ((gd->board_type >> 16) == 2)
716 bd->bi_ethspeed = gd->board_type & 0xFFFF;
717 else
718 bd->bi_ethspeed = 0xFFFF;
719 #endif
720
721 #ifdef CONFIG_NX823
722 load_sernum_ethaddr ();
723 #endif
724
725 #if defined(CFG_GT_6426x) || defined(CONFIG_PN62) || defined(CONFIG_PPCHAMELEONEVB)
726 /* handle the 2nd ethernet address */
727
728 s = getenv ("eth1addr");
729
730 for (i = 0; i < 6; ++i) {
731 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
732 if (s)
733 s = (*e) ? e + 1 : e;
734 }
735 #endif
736 #if defined(CFG_GT_6426x)
737 /* handle the 3rd ethernet address */
738
739 s = getenv ("eth2addr");
740
741 for (i = 0; i < 6; ++i) {
742 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
743 if (s)
744 s = (*e) ? e + 1 : e;
745 }
746 #endif
747
748
749 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
750 defined(CONFIG_CCM)
751 load_sernum_ethaddr ();
752 #endif
753 /* IP Address */
754 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
755
756 WATCHDOG_RESET ();
757
758 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
759 /*
760 * Do pci configuration
761 */
762 pci_init ();
763 #endif
764
765 /** leave this here (after malloc(), environment and PCI are working) **/
766 /* Initialize devices */
767 devices_init ();
768
769 /* Initialize the jump table for applications */
770 jumptable_init ();
771
772 /* Initialize the console (after the relocation and devices init) */
773 console_init_r ();
774
775 #if defined(CONFIG_CCM) || \
776 defined(CONFIG_COGENT) || \
777 defined(CONFIG_CPCI405) || \
778 defined(CONFIG_EVB64260) || \
779 defined(CONFIG_KUP4K) || \
780 defined(CONFIG_LWMON) || \
781 defined(CONFIG_PCU_E) || \
782 defined(CONFIG_W7O) || \
783 defined(CONFIG_MISC_INIT_R)
784 /* miscellaneous platform dependent initialisations */
785 misc_init_r ();
786 #endif
787
788 #ifdef CONFIG_HERMES
789 if (bd->bi_ethspeed != 0xFFFF)
790 hermes_start_lxt980 ((int) bd->bi_ethspeed);
791 #endif
792
793 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
794 defined(CONFIG_CCM) || \
795 defined(CONFIG_ELPT860) || \
796 defined(CONFIG_EP8260) || \
797 defined(CONFIG_IP860) || \
798 defined(CONFIG_IVML24) || \
799 defined(CONFIG_IVMS8) || \
800 defined(CONFIG_LWMON) || \
801 defined(CONFIG_MPC8260ADS) || \
802 defined(CONFIG_MPC8266ADS) || \
803 defined(CONFIG_PCU_E) || \
804 defined(CONFIG_RPXSUPER) || \
805 defined(CONFIG_SPD823TS) )
806
807 WATCHDOG_RESET ();
808 debug ("Reset Ethernet PHY\n");
809 reset_phy ();
810 #endif
811
812 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
813 WATCHDOG_RESET ();
814 puts ("KGDB: ");
815 kgdb_init ();
816 #endif
817
818 debug ("U-Boot relocated to %08lx\n", dest_addr);
819
820 /*
821 * Enable Interrupts
822 */
823 interrupt_init ();
824
825 /* Must happen after interrupts are initialized since
826 * an irq handler gets installed
827 */
828 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
829 serial_buffered_init();
830 #endif
831
832 #ifdef CONFIG_STATUS_LED
833 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
834 #endif
835
836 udelay (20);
837
838 set_timer (0);
839
840 /* Insert function pointers now that we have relocated the code */
841
842 /* Initialize from environment */
843 if ((s = getenv ("loadaddr")) != NULL) {
844 load_addr = simple_strtoul (s, NULL, 16);
845 }
846 #if (CONFIG_COMMANDS & CFG_CMD_NET)
847 if ((s = getenv ("bootfile")) != NULL) {
848 copy_filename (BootFile, s, sizeof (BootFile));
849 }
850 #endif /* CFG_CMD_NET */
851
852 WATCHDOG_RESET ();
853
854 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
855 WATCHDOG_RESET ();
856 puts ("SCSI: ");
857 scsi_init ();
858 #endif
859
860 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
861 WATCHDOG_RESET ();
862 puts ("DOC: ");
863 doc_init ();
864 #endif
865
866 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
867 WATCHDOG_RESET ();
868 puts ("NAND:");
869 nand_init(); /* go init the NAND */
870 #endif
871
872 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
873 WATCHDOG_RESET ();
874 puts ("Net: ");
875 eth_initialize (bd);
876 #endif
877
878 #ifdef CONFIG_POST
879 post_run (NULL, POST_RAM | post_bootmode_get(0));
880 #endif
881
882 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
883 WATCHDOG_RESET ();
884 puts ("PCMCIA:");
885 pcmcia_init ();
886 #endif
887
888 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
889 WATCHDOG_RESET ();
890 # ifdef CONFIG_IDE_8xx_PCCARD
891 puts ("PCMCIA:");
892 # else
893 puts ("IDE: ");
894 #endif
895 ide_init ();
896 #endif /* CFG_CMD_IDE */
897
898 #ifdef CONFIG_LAST_STAGE_INIT
899 WATCHDOG_RESET ();
900 /*
901 * Some parts can be only initialized if all others (like
902 * Interrupts) are up and running (i.e. the PC-style ISA
903 * keyboard).
904 */
905 last_stage_init ();
906 #endif
907
908 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
909 WATCHDOG_RESET ();
910 bedbug_init ();
911 #endif
912
913 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
914 /*
915 * Export available size of memory for Linux,
916 * taking into account the protected RAM at top of memory
917 */
918 {
919 ulong pram;
920 uchar memsz[32];
921 #ifdef CONFIG_PRAM
922 char *s;
923
924 if ((s = getenv ("pram")) != NULL) {
925 pram = simple_strtoul (s, NULL, 10);
926 } else {
927 pram = CONFIG_PRAM;
928 }
929 #else
930 pram=0;
931 #endif
932 #ifdef CONFIG_LOGBUFFER
933 /* Also take the logbuffer into account (pram is in kB) */
934 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
935 #endif
936 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
937 setenv ("mem", memsz);
938 }
939 #endif
940
941 #ifdef CONFIG_MODEM_SUPPORT
942 {
943 extern int do_mdm_init;
944 do_mdm_init = gd->do_mdm_init;
945 }
946 #endif
947
948 /* Initialization complete - start the monitor */
949
950 /* main_loop() can return to retry autoboot, if so just run it again. */
951 for (;;) {
952 WATCHDOG_RESET ();
953 main_loop ();
954 }
955
956 /* NOTREACHED - no way out of command loop except booting */
957 }
958
959 void hang (void)
960 {
961 puts ("### ERROR ### Please RESET the board ###\n");
962 for (;;);
963 }
964
965 #ifdef CONFIG_MODEM_SUPPORT
966 /* called from main loop (common/main.c) */
967 extern void dbg(const char *fmt, ...);
968 int mdm_init (void)
969 {
970 char env_str[16];
971 char *init_str;
972 int i;
973 extern char console_buffer[];
974 static inline void mdm_readline(char *buf, int bufsiz);
975 extern void enable_putc(void);
976 extern int hwflow_onoff(int);
977
978 enable_putc(); /* enable serial_putc() */
979
980 #ifdef CONFIG_HWFLOW
981 init_str = getenv("mdm_flow_control");
982 if (init_str && (strcmp(init_str, "rts/cts") == 0))
983 hwflow_onoff (1);
984 else
985 hwflow_onoff(-1);
986 #endif
987
988 for (i = 1;;i++) {
989 sprintf(env_str, "mdm_init%d", i);
990 if ((init_str = getenv(env_str)) != NULL) {
991 serial_puts(init_str);
992 serial_puts("\n");
993 for(;;) {
994 mdm_readline(console_buffer, CFG_CBSIZE);
995 dbg("ini%d: [%s]", i, console_buffer);
996
997 if ((strcmp(console_buffer, "OK") == 0) ||
998 (strcmp(console_buffer, "ERROR") == 0)) {
999 dbg("ini%d: cmd done", i);
1000 break;
1001 } else /* in case we are originating call ... */
1002 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1003 dbg("ini%d: connect", i);
1004 return 0;
1005 }
1006 }
1007 } else
1008 break; /* no init string - stop modem init */
1009
1010 udelay(100000);
1011 }
1012
1013 udelay(100000);
1014
1015 /* final stage - wait for connect */
1016 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1017 message from modem */
1018 mdm_readline(console_buffer, CFG_CBSIZE);
1019 dbg("ini_f: [%s]", console_buffer);
1020 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1021 dbg("ini_f: connected");
1022 return 0;
1023 }
1024 }
1025
1026 return 0;
1027 }
1028
1029 /* 'inline' - We have to do it fast */
1030 static inline void mdm_readline(char *buf, int bufsiz)
1031 {
1032 char c;
1033 char *p;
1034 int n;
1035
1036 n = 0;
1037 p = buf;
1038 for(;;) {
1039 c = serial_getc();
1040
1041 /* dbg("(%c)", c); */
1042
1043 switch(c) {
1044 case '\r':
1045 break;
1046 case '\n':
1047 *p = '\0';
1048 return;
1049
1050 default:
1051 if(n++ > bufsiz) {
1052 *p = '\0';
1053 return; /* sanity check */
1054 }
1055 *p = c;
1056 p++;
1057 break;
1058 }
1059 }
1060 }
1061 #endif
1062
1063 #if 0 /* We could use plain global data, but the resulting code is bigger */
1064 /*
1065 * Pointer to initial global data area
1066 *
1067 * Here we initialize it.
1068 */
1069 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
1070 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1071 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1072 #endif /* 0 */
1073
1074 /************************************************************************/