blob: 8308969c35ac339750c5af7ec1950037ce0a20ea [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
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>
wdenkfe8c2802002-11-03 00:38:21 +000029#ifdef CONFIG_8xx
30#include <mpc8xx.h>
31#endif
wdenk359733b2003-03-31 17:27:09 +000032#ifdef CONFIG_5xx
33#include <mpc5xx.h>
34#endif
wdenk21136db2003-07-16 21:53:01 +000035#ifdef CONFIG_MPC5XXX
36#include <mpc5xxx.h>
37#endif
wdenkfe8c2802002-11-03 00:38:21 +000038#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>
wdenkfe8c2802002-11-03 00:38:21 +000051#ifdef CFG_ALLOC_DPRAM
wdenk541a76d2003-05-03 15:50:43 +000052#if !defined(CONFIG_8260)
wdenkfe8c2802002-11-03 00:38:21 +000053#include <commproc.h>
54#endif
wdenk541a76d2003-05-03 15:50:43 +000055#endif
wdenkfe8c2802002-11-03 00:38:21 +000056#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
wdenk56f94be2002-11-05 16:35:14 +000064#if defined(CONFIG_LOGBUFFER)
65#include <logbuff.h>
66#endif
wdenkfe8c2802002-11-03 00:38:21 +000067
68#if (CONFIG_COMMANDS & CFG_CMD_DOC)
69void doc_init (void);
70#endif
71#if defined(CONFIG_HARD_I2C) || \
72 defined(CONFIG_SOFT_I2C)
73#include <i2c.h>
74#endif
stroese1b7b4d42003-05-23 11:16:49 +000075#if (CONFIG_COMMANDS & CFG_CMD_NAND)
76void nand_init (void);
77#endif
wdenkfe8c2802002-11-03 00:38:21 +000078
79static char *failed = "*** failed ***\n";
80
81#if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
82extern 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
wdenkb9a83a92003-05-30 12:48:29 +000095extern ulong __init_end;
96extern ulong _end;
wdenkb9a83a92003-05-30 12:48:29 +000097ulong monitor_flash_len;
98
wdenk57b2d802003-06-27 21:31:46 +000099#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
100#include <bedbug/type.h>
101#endif
102
wdenkfe8c2802002-11-03 00:38:21 +0000103/*
104 * Begin and End of memory area for malloc(), and current "brk"
105 */
106static ulong mem_malloc_start = 0;
107static ulong mem_malloc_end = 0;
108static 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 */
118static 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
133void *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
145char *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
wdenkfe8c2802002-11-03 00:38:21 +0000158/*
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 */
170typedef 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
179static 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;
wdenkfe8c2802002-11-03 00:38:21 +0000189 return (0);
190}
191
192/***********************************************************************/
193
194static 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)
216static 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)
228static 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
236static 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
252init_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
wdenk541a76d2003-05-03 15:50:43 +0000261#if !defined(CONFIG_8260)
wdenkfe8c2802002-11-03 00:38:21 +0000262 dpram_init,
263#endif
wdenk541a76d2003-05-03 15:50:43 +0000264#endif
wdenkfe8c2802002-11-03 00:38:21 +0000265#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,
wdenk21136db2003-07-16 21:53:01 +0000278#if defined(CONFIG_MPC5XXX)
279 prt_mpc5xxx_clks,
280#endif /* CONFIG_MPC5XXX */
wdenkfe8c2802002-11-03 00:38:21 +0000281 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
wdenkc08f1582003-04-27 22:52:51 +0000297#ifdef CONFIG_POST
298 post_init_f,
299#endif
wdenkfe8c2802002-11-03 00:38:21 +0000300 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
326void 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):
wdenk57b2d802003-06-27 21:31:46 +0000359 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000360 * - protected RAM
361 * - LCD framebuffer
362 * - monitor code
363 * - board info struct
364 */
wdenkb9a83a92003-05-30 12:48:29 +0000365 len = (ulong)&_end - CFG_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000366
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
wdenk9dfa8d12002-12-08 09:53:23 +0000375#ifdef CONFIG_LOGBUFFER
376 /* reserve kernel log buffer */
377 addr -= (LOGBUFF_RESERVE);
wdenk3086a972003-06-28 23:11:04 +0000378 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
wdenk9dfa8d12002-12-08 09:53:23 +0000379#endif
380
wdenkfe8c2802002-11-03 00:38:21 +0000381#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 */
wdenk3086a972003-06-28 23:11:04 +0000388 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000389#endif /* CONFIG_PRAM */
390
391 /* round down to next 4 kB limit */
392 addr &= ~(4096 - 1);
wdenk3086a972003-06-28 23:11:04 +0000393 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000394
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
wdenk4e112c12003-06-03 23:54:09 +0000409 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000410 */
411 addr -= len;
wdenk4e112c12003-06-03 23:54:09 +0000412 addr &= ~(4096 - 1);
wdenkfe8c2802002-11-03 00:38:21 +0000413
wdenk3086a972003-06-28 23:11:04 +0000414 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000415
wdenk452cfd62002-11-19 11:04:11 +0000416#ifdef CONFIG_AMIGAONEG3SE
417 gd->relocaddr = addr;
418#endif
419
wdenkfe8c2802002-11-03 00:38:21 +0000420 /*
421 * reserve memory for malloc() arena
422 */
423 addr_sp = addr - TOTAL_MALLOC_LEN;
wdenk3086a972003-06-28 23:11:04 +0000424 debug ("Reserving %dk for malloc() at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000425 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000426
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;
wdenk3086a972003-06-28 23:11:04 +0000434 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000435 sizeof (bd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000436 addr_sp -= sizeof (gd_t);
437 id = (gd_t *) addr_sp;
wdenk3086a972003-06-28 23:11:04 +0000438 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000439 sizeof (gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000440
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;
wdenk3086a972003-06-28 23:11:04 +0000451 debug ("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000452
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
wdenk359733b2003-03-31 17:27:09 +0000468#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
wdenkfe8c2802002-11-03 00:38:21 +0000469 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
470#endif
wdenk21136db2003-07-16 21:53:01 +0000471#if defined(CONFIG_MPC5XXX)
472 bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
473#endif
wdenkfe8c2802002-11-03 00:38:21 +0000474
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 */
wdenk21136db2003-07-16 21:53:01 +0000486#if defined(CONFIG_MPC5XXX)
487 bd->bi_ipbfreq = gd->ipb_clk;
488 bd->bi_pcifreq = gd->pci_clk;
489#endif /* CONFIG_MPC5XXX */
wdenkfe8c2802002-11-03 00:38:21 +0000490 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;
stroese1b7b4d42003-05-23 11:16:49 +0000498#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenkfe8c2802002-11-03 00:38:21 +0000499 bd->bi_pci_busfreq = get_PCI_freq ();
500#endif
501#endif
502
wdenk3086a972003-06-28 23:11:04 +0000503 debug ("New Stack Pointer is: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000504
505 WATCHDOG_RESET ();
506
507#ifdef CONFIG_POST
508 post_bootmode_init();
wdenkca9bc762003-07-15 07:45:49 +0000509 post_run (NULL, POST_ROM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000510#endif
511
512 WATCHDOG_RESET();
513
wdenk874ac262003-07-24 23:38:38 +0000514 memcpy (id, (void *)gd, sizeof (gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000515
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
532void board_init_r (gd_t *id, ulong dest_addr)
533{
534 DECLARE_GLOBAL_DATA_PTR;
wdenkfe8c2802002-11-03 00:38:21 +0000535 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
wdenk3086a972003-06-28 23:11:04 +0000553 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000554
555 WATCHDOG_RESET ();
556
557 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
wdenk57b2d802003-06-27 21:31:46 +0000558
wdenkb9a83a92003-05-30 12:48:29 +0000559 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkfe8c2802002-11-03 00:38:21 +0000560
561 /*
562 * We have to relocate the command table manually
563 */
wdenk57b2d802003-06-27 21:31:46 +0000564 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
wdenkfe8c2802002-11-03 00:38:21 +0000565 ulong addr;
wdenkfe8c2802002-11-03 00:38:21 +0000566 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
wdenk56f94be2002-11-05 16:35:14 +0000595#ifdef CONFIG_LOGBUFFER
wdenk9dfa8d12002-12-08 09:53:23 +0000596 logbuff_init_ptrs ();
wdenk56f94be2002-11-05 16:35:14 +0000597#endif
wdenkfe8c2802002-11-03 00:38:21 +0000598#ifdef CONFIG_POST
wdenk9dfa8d12002-12-08 09:53:23 +0000599 post_output_backlog ();
wdenkfe8c2802002-11-03 00:38:21 +0000600 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
wdenkef5fe752003-03-12 10:41:04 +0000609#if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
wdenkfe8c2802002-11-03 00:38:21 +0000610 /*
wdenkef5fe752003-03-12 10:41:04 +0000611 * 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.
wdenkfe8c2802002-11-03 00:38:21 +0000614 */
615 pci_init ();
wdenkef5fe752003-03-12 10:41:04 +0000616#endif
617#if defined(CONFIG_BAB7xx)
wdenkfe8c2802002-11-03 00:38:21 +0000618 /*
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) {
wdenk84650f52003-08-30 00:05:50 +0000635# ifdef CFG_FLASH_CHECKSUM
wdenkfe8c2802002-11-03 00:38:21 +0000636 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');
wdenk84650f52003-08-30 00:05:50 +0000651# else /* !CFG_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000652 print_size (flash_size, "\n");
wdenk84650f52003-08-30 00:05:50 +0000653# endif /* CFG_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000654 } 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) */
wdenk84650f52003-08-30 00:05:50 +0000661# if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
wdenkfe8c2802002-11-03 00:38:21 +0000662 bd->bi_flashoffset = 0;
wdenk84650f52003-08-30 00:05:50 +0000663# elif CFG_MONITOR_BASE == CFG_FLASH_BASE
wdenkb9a83a92003-05-30 12:48:29 +0000664 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
wdenk84650f52003-08-30 00:05:50 +0000665# else
wdenkfe8c2802002-11-03 00:38:21 +0000666 bd->bi_flashoffset = 0;
wdenk84650f52003-08-30 00:05:50 +0000667# endif
668#else /* CFG_NO_FLASH */
wdenkfe8c2802002-11-03 00:38:21 +0000669
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.
wdenk57b2d802003-06-27 21:31:46 +0000698 * 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.
wdenkfe8c2802002-11-03 00:38:21 +0000702 */
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)
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
wdenk874ac262003-07-24 23:38:38 +0000769 /* Initialize the jump table for applications */
770 jumptable_init ();
wdenkfe8c2802002-11-03 00:38:21 +0000771
772 /* Initialize the console (after the relocation and devices init) */
773 console_init_r ();
wdenkfe8c2802002-11-03 00:38:21 +0000774
775#if defined(CONFIG_CCM) || \
776 defined(CONFIG_COGENT) || \
777 defined(CONFIG_CPCI405) || \
778 defined(CONFIG_EVB64260) || \
wdenk56f94be2002-11-05 16:35:14 +0000779 defined(CONFIG_KUP4K) || \
wdenkfe8c2802002-11-03 00:38:21 +0000780 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) || \
wdenkef5fe752003-03-12 10:41:04 +0000795 defined(CONFIG_ELPT860) || \
wdenkfe8c2802002-11-03 00:38:21 +0000796 defined(CONFIG_EP8260) || \
797 defined(CONFIG_IP860) || \
798 defined(CONFIG_IVML24) || \
799 defined(CONFIG_IVMS8) || \
800 defined(CONFIG_LWMON) || \
801 defined(CONFIG_MPC8260ADS) || \
wdenkbf2f8c92003-05-22 22:52:13 +0000802 defined(CONFIG_MPC8266ADS) || \
wdenkfe8c2802002-11-03 00:38:21 +0000803 defined(CONFIG_PCU_E) || \
804 defined(CONFIG_RPXSUPER) || \
805 defined(CONFIG_SPD823TS) )
806
807 WATCHDOG_RESET ();
wdenk3086a972003-06-28 23:11:04 +0000808 debug ("Reset Ethernet PHY\n");
wdenkfe8c2802002-11-03 00:38:21 +0000809 reset_phy ();
810#endif
811
812#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
813 WATCHDOG_RESET ();
814 puts ("KGDB: ");
815 kgdb_init ();
816#endif
817
wdenk3086a972003-06-28 23:11:04 +0000818 debug ("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000819
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
stroese1b7b4d42003-05-23 11:16:49 +0000866#if (CONFIG_COMMANDS & CFG_CMD_NAND)
867 WATCHDOG_RESET ();
868 nand_init(); /* go init the NAND */
869#endif
870
wdenkfe8c2802002-11-03 00:38:21 +0000871#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
872 WATCHDOG_RESET ();
873 puts ("Net: ");
874 eth_initialize (bd);
875#endif
876
877#ifdef CONFIG_POST
wdenkca9bc762003-07-15 07:45:49 +0000878 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000879#endif
880
881#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
882 WATCHDOG_RESET ();
883 puts ("PCMCIA:");
884 pcmcia_init ();
885#endif
886
887#if (CONFIG_COMMANDS & CFG_CMD_IDE)
888 WATCHDOG_RESET ();
889# ifdef CONFIG_IDE_8xx_PCCARD
890 puts ("PCMCIA:");
891# else
892 puts ("IDE: ");
893#endif
894 ide_init ();
895#endif /* CFG_CMD_IDE */
896
897#ifdef CONFIG_LAST_STAGE_INIT
898 WATCHDOG_RESET ();
899 /*
900 * Some parts can be only initialized if all others (like
901 * Interrupts) are up and running (i.e. the PC-style ISA
902 * keyboard).
903 */
904 last_stage_init ();
905#endif
906
907#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
908 WATCHDOG_RESET ();
909 bedbug_init ();
910#endif
911
wdenk9dfa8d12002-12-08 09:53:23 +0000912#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000913 /*
914 * Export available size of memory for Linux,
915 * taking into account the protected RAM at top of memory
916 */
917 {
918 ulong pram;
wdenkfe8c2802002-11-03 00:38:21 +0000919 uchar memsz[32];
wdenk9dfa8d12002-12-08 09:53:23 +0000920#ifdef CONFIG_PRAM
921 char *s;
wdenkfe8c2802002-11-03 00:38:21 +0000922
923 if ((s = getenv ("pram")) != NULL) {
924 pram = simple_strtoul (s, NULL, 10);
925 } else {
926 pram = CONFIG_PRAM;
927 }
wdenk9dfa8d12002-12-08 09:53:23 +0000928#else
929 pram=0;
930#endif
931#ifdef CONFIG_LOGBUFFER
932 /* Also take the logbuffer into account (pram is in kB) */
933 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
934#endif
wdenkfe8c2802002-11-03 00:38:21 +0000935 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
936 setenv ("mem", memsz);
937 }
938#endif
939
wdenkc08f1582003-04-27 22:52:51 +0000940#ifdef CONFIG_MODEM_SUPPORT
941 {
942 extern int do_mdm_init;
943 do_mdm_init = gd->do_mdm_init;
944 }
945#endif
946
wdenkfe8c2802002-11-03 00:38:21 +0000947 /* Initialization complete - start the monitor */
948
949 /* main_loop() can return to retry autoboot, if so just run it again. */
950 for (;;) {
951 WATCHDOG_RESET ();
952 main_loop ();
953 }
954
955 /* NOTREACHED - no way out of command loop except booting */
956}
957
958void hang (void)
959{
960 puts ("### ERROR ### Please RESET the board ###\n");
961 for (;;);
962}
963
wdenkc08f1582003-04-27 22:52:51 +0000964#ifdef CONFIG_MODEM_SUPPORT
965/* called from main loop (common/main.c) */
966extern void dbg(const char *fmt, ...);
967int mdm_init (void)
968{
969 char env_str[16];
970 char *init_str;
971 int i;
972 extern char console_buffer[];
973 static inline void mdm_readline(char *buf, int bufsiz);
974 extern void enable_putc(void);
975 extern int hwflow_onoff(int);
976
977 enable_putc(); /* enable serial_putc() */
978
979#ifdef CONFIG_HWFLOW
980 init_str = getenv("mdm_flow_control");
981 if (init_str && (strcmp(init_str, "rts/cts") == 0))
982 hwflow_onoff (1);
983 else
984 hwflow_onoff(-1);
985#endif
986
987 for (i = 1;;i++) {
988 sprintf(env_str, "mdm_init%d", i);
989 if ((init_str = getenv(env_str)) != NULL) {
990 serial_puts(init_str);
991 serial_puts("\n");
992 for(;;) {
993 mdm_readline(console_buffer, CFG_CBSIZE);
994 dbg("ini%d: [%s]", i, console_buffer);
995
996 if ((strcmp(console_buffer, "OK") == 0) ||
997 (strcmp(console_buffer, "ERROR") == 0)) {
998 dbg("ini%d: cmd done", i);
999 break;
1000 } else /* in case we are originating call ... */
1001 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1002 dbg("ini%d: connect", i);
1003 return 0;
1004 }
1005 }
1006 } else
1007 break; /* no init string - stop modem init */
1008
1009 udelay(100000);
1010 }
1011
1012 udelay(100000);
1013
1014 /* final stage - wait for connect */
1015 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1016 message from modem */
1017 mdm_readline(console_buffer, CFG_CBSIZE);
1018 dbg("ini_f: [%s]", console_buffer);
1019 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1020 dbg("ini_f: connected");
1021 return 0;
1022 }
1023 }
1024
1025 return 0;
1026}
1027
1028/* 'inline' - We have to do it fast */
1029static inline void mdm_readline(char *buf, int bufsiz)
1030{
1031 char c;
1032 char *p;
1033 int n;
1034
1035 n = 0;
1036 p = buf;
1037 for(;;) {
1038 c = serial_getc();
1039
1040 /* dbg("(%c)", c); */
1041
1042 switch(c) {
1043 case '\r':
1044 break;
1045 case '\n':
1046 *p = '\0';
1047 return;
1048
1049 default:
1050 if(n++ > bufsiz) {
1051 *p = '\0';
1052 return; /* sanity check */
1053 }
1054 *p = c;
1055 p++;
1056 break;
1057 }
1058 }
1059}
1060#endif
1061
wdenkfe8c2802002-11-03 00:38:21 +00001062#if 0 /* We could use plain global data, but the resulting code is bigger */
1063/*
1064 * Pointer to initial global data area
1065 *
1066 * Here we initialize it.
1067 */
1068#undef XTRN_DECLARE_GLOBAL_DATA_PTR
1069#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1070DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1071#endif /* 0 */
1072
1073/************************************************************************/