blob: 8e05df16de0c446150d87d6207055dea65a9c025 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
wdenkd4ca31c2004-01-02 14:00:00 +00002 * (C) Copyright 2000-2004
wdenkfe8c2802002-11-03 00:38:21 +00003 * 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
wdenk0db5bca2003-03-31 17:27:09 +000032#ifdef CONFIG_5xx
33#include <mpc5xx.h>
34#endif
wdenk945af8d2003-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
wdenk42d1f032003-10-15 23:53:47 +000052#if !(defined(CONFIG_8260)||defined(CONFIG_MPC8560))
wdenkfe8c2802002-11-03 00:38:21 +000053#include <commproc.h>
54#endif
wdenk7aa78612003-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
wdenk42d1f032003-10-15 23:53:47 +000067#if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
68#include <asm/cache.h>
69#endif
wdenkfe8c2802002-11-03 00:38:21 +000070
71#if (CONFIG_COMMANDS & CFG_CMD_DOC)
72void doc_init (void);
73#endif
74#if defined(CONFIG_HARD_I2C) || \
75 defined(CONFIG_SOFT_I2C)
76#include <i2c.h>
77#endif
stroesebedc4972003-05-23 11:16:49 +000078#if (CONFIG_COMMANDS & CFG_CMD_NAND)
79void nand_init (void);
80#endif
wdenkfe8c2802002-11-03 00:38:21 +000081
82static char *failed = "*** failed ***\n";
83
84#if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
85extern flash_info_t flash_info[];
86#endif
87
88#include <environment.h>
89
90#if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
91 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
92 defined(CFG_ENV_IS_IN_NVRAM)
93#define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
94#else
95#define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
96#endif
97
wdenk3b57fe02003-05-30 12:48:29 +000098extern ulong __init_end;
99extern ulong _end;
wdenk3b57fe02003-05-30 12:48:29 +0000100ulong monitor_flash_len;
101
wdenk8bde7f72003-06-27 21:31:46 +0000102#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
103#include <bedbug/type.h>
104#endif
105
wdenkfe8c2802002-11-03 00:38:21 +0000106/*
107 * Begin and End of memory area for malloc(), and current "brk"
108 */
109static ulong mem_malloc_start = 0;
110static ulong mem_malloc_end = 0;
111static ulong mem_malloc_brk = 0;
112
113/************************************************************************
114 * Utilities *
115 ************************************************************************
116 */
117
118/*
119 * The Malloc area is immediately below the monitor copy in DRAM
120 */
121static void mem_malloc_init (void)
122{
123 DECLARE_GLOBAL_DATA_PTR;
124
125 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
126
127 mem_malloc_end = dest_addr;
128 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
129 mem_malloc_brk = mem_malloc_start;
130
131 memset ((void *) mem_malloc_start,
132 0,
133 mem_malloc_end - mem_malloc_start);
134}
135
136void *sbrk (ptrdiff_t increment)
137{
138 ulong old = mem_malloc_brk;
139 ulong new = old + increment;
140
141 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
142 return (NULL);
143 }
144 mem_malloc_brk = new;
145 return ((void *) old);
146}
147
148char *strmhz (char *buf, long hz)
149{
150 long l, n;
151 long m;
152
153 n = hz / 1000000L;
154 l = sprintf (buf, "%ld", n);
155 m = (hz % 1000000L) / 1000L;
156 if (m != 0)
157 sprintf (buf + l, ".%03ld", m);
158 return (buf);
159}
160
wdenkfe8c2802002-11-03 00:38:21 +0000161/*
162 * All attempts to come up with a "common" initialization sequence
163 * that works for all boards and architectures failed: some of the
164 * requirements are just _too_ different. To get rid of the resulting
165 * mess of board dependend #ifdef'ed code we now make the whole
166 * initialization sequence configurable to the user.
167 *
168 * The requirements for any new initalization function is simple: it
169 * receives a pointer to the "global data" structure as it's only
170 * argument, and returns an integer return code, where 0 means
171 * "continue" and != 0 means "fatal error, hang the system".
172 */
173typedef int (init_fnc_t) (void);
174
175/************************************************************************
176 * Init Utilities *
177 ************************************************************************
178 * Some of this code should be moved into the core functions,
179 * but let's get it working (again) first...
180 */
181
182static int init_baudrate (void)
183{
184 DECLARE_GLOBAL_DATA_PTR;
185
186 uchar tmp[64]; /* long enough for environment variables */
187 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
188
189 gd->baudrate = (i > 0)
190 ? (int) simple_strtoul (tmp, NULL, 10)
191 : CONFIG_BAUDRATE;
wdenkfe8c2802002-11-03 00:38:21 +0000192 return (0);
193}
194
195/***********************************************************************/
196
197static int init_func_ram (void)
198{
199 DECLARE_GLOBAL_DATA_PTR;
200
201#ifdef CONFIG_BOARD_TYPES
202 int board_type = gd->board_type;
203#else
204 int board_type = 0; /* use dummy arg */
205#endif
206 puts ("DRAM: ");
207
208 if ((gd->ram_size = initdram (board_type)) > 0) {
209 print_size (gd->ram_size, "\n");
210 return (0);
211 }
212 puts (failed);
213 return (1);
214}
215
216/***********************************************************************/
217
218#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
219static int init_func_i2c (void)
220{
221 puts ("I2C: ");
222 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
223 puts ("ready\n");
224 return (0);
225}
226#endif
227
228/***********************************************************************/
229
230#if defined(CONFIG_WATCHDOG)
231static int init_func_watchdog_init (void)
232{
233 puts (" Watchdog enabled\n");
234 WATCHDOG_RESET ();
235 return (0);
236}
237# define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
238
239static int init_func_watchdog_reset (void)
240{
241 WATCHDOG_RESET ();
242 return (0);
243}
244# define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
245#else
246# define INIT_FUNC_WATCHDOG_INIT /* undef */
247# define INIT_FUNC_WATCHDOG_RESET /* undef */
248#endif /* CONFIG_WATCHDOG */
249
250/************************************************************************
251 * Initialization sequence *
252 ************************************************************************
253 */
254
255init_fnc_t *init_sequence[] = {
256
257#if defined(CONFIG_BOARD_PRE_INIT)
258 board_pre_init, /* very early board init code (fpga boot, etc.) */
259#endif
260
261 get_clocks, /* get CPU and bus clocks (etc.) */
262 init_timebase,
263#ifdef CFG_ALLOC_DPRAM
wdenk42d1f032003-10-15 23:53:47 +0000264#if !(defined(CONFIG_8260) || defined(CONFIG_MPC8560))
wdenkfe8c2802002-11-03 00:38:21 +0000265 dpram_init,
266#endif
wdenk7aa78612003-05-03 15:50:43 +0000267#endif
wdenkfe8c2802002-11-03 00:38:21 +0000268#if defined(CONFIG_BOARD_POSTCLK_INIT)
269 board_postclk_init,
270#endif
271 env_init,
272 init_baudrate,
273 serial_init,
274 console_init_f,
275 display_options,
276#if defined(CONFIG_8260)
277 prt_8260_rsr,
278 prt_8260_clks,
279#endif /* CONFIG_8260 */
280 checkcpu,
wdenk945af8d2003-07-16 21:53:01 +0000281#if defined(CONFIG_MPC5XXX)
282 prt_mpc5xxx_clks,
283#endif /* CONFIG_MPC5XXX */
wdenkfe8c2802002-11-03 00:38:21 +0000284 checkboard,
285 INIT_FUNC_WATCHDOG_INIT
286#if defined(CONFIG_BMW) || \
287 defined(CONFIG_COGENT) || \
288 defined(CONFIG_HYMOD) || \
289 defined(CONFIG_RSD_PROTO) || \
290 defined(CONFIG_W7O)
291 misc_init_f,
292#endif
293 INIT_FUNC_WATCHDOG_RESET
294#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
295 init_func_i2c,
296#endif
297#if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
298 dtt_init,
299#endif
wdenk4532cb62003-04-27 22:52:51 +0000300#ifdef CONFIG_POST
301 post_init_f,
302#endif
wdenkfe8c2802002-11-03 00:38:21 +0000303 INIT_FUNC_WATCHDOG_RESET
304 init_func_ram,
305#if defined(CFG_DRAM_TEST)
306 testdram,
307#endif /* CFG_DRAM_TEST */
308 INIT_FUNC_WATCHDOG_RESET
309
310 NULL, /* Terminate this list */
311};
312
313/************************************************************************
314 *
315 * This is the first part of the initialization sequence that is
316 * implemented in C, but still running from ROM.
317 *
318 * The main purpose is to provide a (serial) console interface as
319 * soon as possible (so we can see any error messages), and to
320 * initialize the RAM so that we can relocate the monitor code to
321 * RAM.
322 *
323 * Be aware of the restrictions: global data is read-only, BSS is not
324 * initialized, and stack space is limited to a few kB.
325 *
326 ************************************************************************
327 */
328
329void board_init_f (ulong bootflag)
330{
331 DECLARE_GLOBAL_DATA_PTR;
332
333 bd_t *bd;
334 ulong len, addr, addr_sp;
335 gd_t *id;
336 init_fnc_t **init_fnc_ptr;
337#ifdef CONFIG_PRAM
338 int i;
339 ulong reg;
340 uchar tmp[64]; /* long enough for environment variables */
341#endif
342
343 /* Pointer is writable since we allocated a register for it */
344 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
345
wdenk42d1f032003-10-15 23:53:47 +0000346#if !(defined(CONFIG_8260) || defined(CONFIG_MPC8560))
wdenkfe8c2802002-11-03 00:38:21 +0000347 /* Clear initial global data */
348 memset ((void *) gd, 0, sizeof (gd_t));
349#endif
350
351 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
352 if ((*init_fnc_ptr) () != 0) {
353 hang ();
354 }
355 }
356
357 /*
358 * Now that we have DRAM mapped and working, we can
359 * relocate the code and continue running from DRAM.
360 *
361 * Reserve memory at end of RAM for (top down in that order):
wdenk8bde7f72003-06-27 21:31:46 +0000362 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000363 * - protected RAM
364 * - LCD framebuffer
365 * - monitor code
366 * - board info struct
367 */
wdenk3b57fe02003-05-30 12:48:29 +0000368 len = (ulong)&_end - CFG_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000369
370#ifndef CONFIG_VERY_BIG_RAM
371 addr = CFG_SDRAM_BASE + gd->ram_size;
372#else
373 /* only allow stack below 256M */
374 addr = CFG_SDRAM_BASE +
375 (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
376#endif
377
wdenk228f29a2002-12-08 09:53:23 +0000378#ifdef CONFIG_LOGBUFFER
379 /* reserve kernel log buffer */
380 addr -= (LOGBUFF_RESERVE);
wdenk9d2b18a2003-06-28 23:11:04 +0000381 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
wdenk228f29a2002-12-08 09:53:23 +0000382#endif
383
wdenkfe8c2802002-11-03 00:38:21 +0000384#ifdef CONFIG_PRAM
385 /*
386 * reserve protected RAM
387 */
388 i = getenv_r ("pram", tmp, sizeof (tmp));
389 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
390 addr -= (reg << 10); /* size is in kB */
wdenk9d2b18a2003-06-28 23:11:04 +0000391 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000392#endif /* CONFIG_PRAM */
393
394 /* round down to next 4 kB limit */
395 addr &= ~(4096 - 1);
wdenk9d2b18a2003-06-28 23:11:04 +0000396 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000397
398#ifdef CONFIG_LCD
399 /* reserve memory for LCD display (always full pages) */
400 addr = lcd_setmem (addr);
401 gd->fb_base = addr;
402#endif /* CONFIG_LCD */
403
404#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
405 /* reserve memory for video display (always full pages) */
406 addr = video_setmem (addr);
407 gd->fb_base = addr;
408#endif /* CONFIG_VIDEO */
409
410 /*
411 * reserve memory for U-Boot code, data & bss
wdenk682011f2003-06-03 23:54:09 +0000412 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000413 */
414 addr -= len;
wdenk682011f2003-06-03 23:54:09 +0000415 addr &= ~(4096 - 1);
wdenkfe8c2802002-11-03 00:38:21 +0000416
wdenk9d2b18a2003-06-28 23:11:04 +0000417 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000418
wdenkc7de8292002-11-19 11:04:11 +0000419#ifdef CONFIG_AMIGAONEG3SE
420 gd->relocaddr = addr;
421#endif
422
wdenkfe8c2802002-11-03 00:38:21 +0000423 /*
424 * reserve memory for malloc() arena
425 */
426 addr_sp = addr - TOTAL_MALLOC_LEN;
wdenk9d2b18a2003-06-28 23:11:04 +0000427 debug ("Reserving %dk for malloc() at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000428 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000429
430 /*
431 * (permanently) allocate a Board Info struct
432 * and a permanent copy of the "global" data
433 */
434 addr_sp -= sizeof (bd_t);
435 bd = (bd_t *) addr_sp;
436 gd->bd = bd;
wdenk9d2b18a2003-06-28 23:11:04 +0000437 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000438 sizeof (bd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000439 addr_sp -= sizeof (gd_t);
440 id = (gd_t *) addr_sp;
wdenk9d2b18a2003-06-28 23:11:04 +0000441 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
wdenkfe8c2802002-11-03 00:38:21 +0000442 sizeof (gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000443
444 /*
445 * Finally, we set up a new (bigger) stack.
446 *
447 * Leave some safety gap for SP, force alignment on 16 byte boundary
448 * Clear initial stack frame
449 */
450 addr_sp -= 16;
451 addr_sp &= ~0xF;
452 *((ulong *) addr_sp)-- = 0;
453 *((ulong *) addr_sp)-- = 0;
wdenk9d2b18a2003-06-28 23:11:04 +0000454 debug ("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000455
456 /*
457 * Save local variables to board info struct
458 */
459
460 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
461 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
462
463#ifdef CONFIG_IP860
464 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
465 bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
466#else
467 bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
468 bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
469#endif
470
wdenk42d1f032003-10-15 23:53:47 +0000471#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
472 defined(CONFIG_E500)
wdenkfe8c2802002-11-03 00:38:21 +0000473 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
474#endif
wdenk945af8d2003-07-16 21:53:01 +0000475#if defined(CONFIG_MPC5XXX)
476 bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
477#endif
wdenkfe8c2802002-11-03 00:38:21 +0000478
479 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
480
481 WATCHDOG_RESET ();
482 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
483 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
wdenk42d1f032003-10-15 23:53:47 +0000484#if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
wdenkfe8c2802002-11-03 00:38:21 +0000485 bd->bi_cpmfreq = gd->cpm_clk;
486 bd->bi_brgfreq = gd->brg_clk;
487 bd->bi_sccfreq = gd->scc_clk;
488 bd->bi_vco = gd->vco_out;
489#endif /* CONFIG_8260 */
wdenk945af8d2003-07-16 21:53:01 +0000490#if defined(CONFIG_MPC5XXX)
491 bd->bi_ipbfreq = gd->ipb_clk;
492 bd->bi_pcifreq = gd->pci_clk;
493#endif /* CONFIG_MPC5XXX */
wdenkfe8c2802002-11-03 00:38:21 +0000494 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
495
496#ifdef CFG_EXTBDINFO
497 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
498 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
499
500 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
501 bd->bi_plb_busfreq = gd->bus_clk;
stroesebedc4972003-05-23 11:16:49 +0000502#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenkfe8c2802002-11-03 00:38:21 +0000503 bd->bi_pci_busfreq = get_PCI_freq ();
wdenk5bb226e2003-11-17 21:14:37 +0000504
505#ifdef CFG_OPB_FREQ
506 bd->bi_opbfreq = CFG_OPB_FREQ;
507#else
508 bd->bi_opbfreq = 50000000;
509#endif
510 bd->bi_iic_fast[0] = 0;
511 bd->bi_iic_fast[1] = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000512#endif
513#endif
514
wdenk9d2b18a2003-06-28 23:11:04 +0000515 debug ("New Stack Pointer is: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000516
517 WATCHDOG_RESET ();
518
519#ifdef CONFIG_POST
520 post_bootmode_init();
wdenk6dff5522003-07-15 07:45:49 +0000521 post_run (NULL, POST_ROM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000522#endif
523
524 WATCHDOG_RESET();
525
wdenk27b207f2003-07-24 23:38:38 +0000526 memcpy (id, (void *)gd, sizeof (gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000527
528 relocate_code (addr_sp, id, addr);
529
530 /* NOTREACHED - relocate_code() does not return */
531}
532
533
534/************************************************************************
535 *
536 * This is the next part if the initialization sequence: we are now
537 * running from RAM and have a "normal" C environment, i. e. global
538 * data can be written, BSS has been cleared, the stack size in not
539 * that critical any more, etc.
540 *
541 ************************************************************************
542 */
543
544void board_init_r (gd_t *id, ulong dest_addr)
545{
546 DECLARE_GLOBAL_DATA_PTR;
wdenkfe8c2802002-11-03 00:38:21 +0000547 cmd_tbl_t *cmdtp;
548 char *s, *e;
549 bd_t *bd;
550 int i;
551 extern void malloc_bin_reloc (void);
552#ifndef CFG_ENV_IS_NOWHERE
553 extern char * env_name_spec;
554#endif
555
556#ifndef CFG_NO_FLASH
557 ulong flash_size;
558#endif
559
560 gd = id; /* initialize RAM version of global data */
561 bd = gd->bd;
562
563 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
564
wdenk9d2b18a2003-06-28 23:11:04 +0000565 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000566
567 WATCHDOG_RESET ();
568
569 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
wdenk8bde7f72003-06-27 21:31:46 +0000570
wdenk3b57fe02003-05-30 12:48:29 +0000571 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkfe8c2802002-11-03 00:38:21 +0000572
573 /*
574 * We have to relocate the command table manually
575 */
wdenk8bde7f72003-06-27 21:31:46 +0000576 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
wdenkfe8c2802002-11-03 00:38:21 +0000577 ulong addr;
wdenkfe8c2802002-11-03 00:38:21 +0000578 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
579#if 0
580 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
581 cmdtp->name, (ulong) (cmdtp->cmd), addr);
582#endif
583 cmdtp->cmd =
584 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
585
586 addr = (ulong)(cmdtp->name) + gd->reloc_off;
587 cmdtp->name = (char *)addr;
588
589 if (cmdtp->usage) {
590 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
591 cmdtp->usage = (char *)addr;
592 }
593#ifdef CFG_LONGHELP
594 if (cmdtp->help) {
595 addr = (ulong)(cmdtp->help) + gd->reloc_off;
596 cmdtp->help = (char *)addr;
597 }
598#endif
599 }
600 /* there are some other pointer constants we must deal with */
601#ifndef CFG_ENV_IS_NOWHERE
602 env_name_spec += gd->reloc_off;
603#endif
604
605 WATCHDOG_RESET ();
606
wdenk56f94be2002-11-05 16:35:14 +0000607#ifdef CONFIG_LOGBUFFER
wdenk228f29a2002-12-08 09:53:23 +0000608 logbuff_init_ptrs ();
wdenk56f94be2002-11-05 16:35:14 +0000609#endif
wdenkfe8c2802002-11-03 00:38:21 +0000610#ifdef CONFIG_POST
wdenk228f29a2002-12-08 09:53:23 +0000611 post_output_backlog ();
wdenkfe8c2802002-11-03 00:38:21 +0000612 post_reloc ();
613#endif
614
615 WATCHDOG_RESET();
616
617#if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
618 icache_enable (); /* it's time to enable the instruction cache */
619#endif
620
wdenk42d1f032003-10-15 23:53:47 +0000621#if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
622 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
623#endif
624
wdenk3bac3512003-03-12 10:41:04 +0000625#if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
wdenkfe8c2802002-11-03 00:38:21 +0000626 /*
wdenk3bac3512003-03-12 10:41:04 +0000627 * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
628 * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
629 * bridge there.
wdenkfe8c2802002-11-03 00:38:21 +0000630 */
631 pci_init ();
wdenk3bac3512003-03-12 10:41:04 +0000632#endif
633#if defined(CONFIG_BAB7xx)
wdenkfe8c2802002-11-03 00:38:21 +0000634 /*
635 * Initialise the ISA bridge
636 */
637 initialise_w83c553f ();
638#endif
639
640 asm ("sync ; isync");
641
642 /*
643 * Setup trap handlers
644 */
645 trap_init (dest_addr);
646
647#if !defined(CFG_NO_FLASH)
648 puts ("FLASH: ");
649
650 if ((flash_size = flash_init ()) > 0) {
wdenk0cb61d72003-08-30 00:05:50 +0000651# ifdef CFG_FLASH_CHECKSUM
wdenkfe8c2802002-11-03 00:38:21 +0000652 print_size (flash_size, "");
653 /*
654 * Compute and print flash CRC if flashchecksum is set to 'y'
655 *
656 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
657 */
658 s = getenv ("flashchecksum");
659 if (s && (*s == 'y')) {
660 printf (" CRC: %08lX",
661 crc32 (0,
662 (const unsigned char *) CFG_FLASH_BASE,
663 flash_size)
664 );
665 }
666 putc ('\n');
wdenk0cb61d72003-08-30 00:05:50 +0000667# else /* !CFG_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000668 print_size (flash_size, "\n");
wdenk0cb61d72003-08-30 00:05:50 +0000669# endif /* CFG_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000670 } else {
671 puts (failed);
672 hang ();
673 }
674
675 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
676 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
wdenk0cb61d72003-08-30 00:05:50 +0000677# if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
wdenkfe8c2802002-11-03 00:38:21 +0000678 bd->bi_flashoffset = 0;
wdenk0cb61d72003-08-30 00:05:50 +0000679# elif CFG_MONITOR_BASE == CFG_FLASH_BASE
wdenk3b57fe02003-05-30 12:48:29 +0000680 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
wdenk0cb61d72003-08-30 00:05:50 +0000681# else
wdenkfe8c2802002-11-03 00:38:21 +0000682 bd->bi_flashoffset = 0;
wdenk0cb61d72003-08-30 00:05:50 +0000683# endif
684#else /* CFG_NO_FLASH */
wdenkfe8c2802002-11-03 00:38:21 +0000685
686 bd->bi_flashsize = 0;
687 bd->bi_flashstart = 0;
688 bd->bi_flashoffset = 0;
689#endif /* !CFG_NO_FLASH */
690
691 WATCHDOG_RESET ();
692
693 /* initialize higher level parts of CPU like time base and timers */
694 cpu_init_r ();
695
696 WATCHDOG_RESET ();
697
698 /* initialize malloc() area */
699 mem_malloc_init ();
700 malloc_bin_reloc ();
701
702#ifdef CONFIG_SPI
703# if !defined(CFG_ENV_IS_IN_EEPROM)
704 spi_init_f ();
705# endif
706 spi_init_r ();
707#endif
708
709 /* relocate environment function pointers etc. */
710 env_relocate ();
711
712 /*
713 * Fill in missing fields of bd_info.
wdenk8bde7f72003-06-27 21:31:46 +0000714 * We do this here, where we have "normal" access to the
715 * environment; we used to do this still running from ROM,
716 * where had to use getenv_r(), which can be pretty slow when
717 * the environment is in EEPROM.
wdenkfe8c2802002-11-03 00:38:21 +0000718 */
719 s = getenv ("ethaddr");
720#if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
721 if (s == NULL)
722 board_get_enetaddr (bd->bi_enetaddr);
723 else
724#endif
725 for (i = 0; i < 6; ++i) {
726 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
727 if (s)
728 s = (*e) ? e + 1 : e;
729 }
730#ifdef CONFIG_HERMES
731 if ((gd->board_type >> 16) == 2)
732 bd->bi_ethspeed = gd->board_type & 0xFFFF;
733 else
734 bd->bi_ethspeed = 0xFFFF;
735#endif
736
737#ifdef CONFIG_NX823
738 load_sernum_ethaddr ();
739#endif
740
wdenk42d1f032003-10-15 23:53:47 +0000741#if defined(CFG_GT_6426x) || defined(CONFIG_PN62) || defined(CONFIG_PPCHAMELEONEVB) || \
742 defined(CONFIG_MPC8540ADS) || defined(CONFIG_MPC8560ADS)
wdenkfe8c2802002-11-03 00:38:21 +0000743 /* handle the 2nd ethernet address */
744
745 s = getenv ("eth1addr");
746
747 for (i = 0; i < 6; ++i) {
748 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
749 if (s)
750 s = (*e) ? e + 1 : e;
751 }
752#endif
wdenk42d1f032003-10-15 23:53:47 +0000753#if defined(CFG_GT_6426x) || defined(CONFIG_MPC8540ADS) || defined(CONFIG_MPC8560ADS)
wdenkfe8c2802002-11-03 00:38:21 +0000754 /* handle the 3rd ethernet address */
755
756 s = getenv ("eth2addr");
757
758 for (i = 0; i < 6; ++i) {
759 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
760 if (s)
761 s = (*e) ? e + 1 : e;
762 }
763#endif
764
765
766#if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
767 defined(CONFIG_CCM)
768 load_sernum_ethaddr ();
769#endif
770 /* IP Address */
771 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
772
773 WATCHDOG_RESET ();
774
775#if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
776 /*
777 * Do pci configuration
778 */
779 pci_init ();
780#endif
781
782/** leave this here (after malloc(), environment and PCI are working) **/
783 /* Initialize devices */
784 devices_init ();
785
wdenk27b207f2003-07-24 23:38:38 +0000786 /* Initialize the jump table for applications */
787 jumptable_init ();
wdenkfe8c2802002-11-03 00:38:21 +0000788
789 /* Initialize the console (after the relocation and devices init) */
790 console_init_r ();
wdenkfe8c2802002-11-03 00:38:21 +0000791
792#if defined(CONFIG_CCM) || \
793 defined(CONFIG_COGENT) || \
794 defined(CONFIG_CPCI405) || \
795 defined(CONFIG_EVB64260) || \
wdenk56f94be2002-11-05 16:35:14 +0000796 defined(CONFIG_KUP4K) || \
wdenkfe8c2802002-11-03 00:38:21 +0000797 defined(CONFIG_LWMON) || \
798 defined(CONFIG_PCU_E) || \
799 defined(CONFIG_W7O) || \
800 defined(CONFIG_MISC_INIT_R)
801 /* miscellaneous platform dependent initialisations */
802 misc_init_r ();
803#endif
804
805#ifdef CONFIG_HERMES
806 if (bd->bi_ethspeed != 0xFFFF)
807 hermes_start_lxt980 ((int) bd->bi_ethspeed);
808#endif
809
810#if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
811 defined(CONFIG_CCM) || \
wdenk3bac3512003-03-12 10:41:04 +0000812 defined(CONFIG_ELPT860) || \
wdenkfe8c2802002-11-03 00:38:21 +0000813 defined(CONFIG_EP8260) || \
814 defined(CONFIG_IP860) || \
815 defined(CONFIG_IVML24) || \
816 defined(CONFIG_IVMS8) || \
817 defined(CONFIG_LWMON) || \
818 defined(CONFIG_MPC8260ADS) || \
wdenk5d232d02003-05-22 22:52:13 +0000819 defined(CONFIG_MPC8266ADS) || \
wdenk42d1f032003-10-15 23:53:47 +0000820 defined(CONFIG_MPC8560ADS) || \
wdenkfe8c2802002-11-03 00:38:21 +0000821 defined(CONFIG_PCU_E) || \
822 defined(CONFIG_RPXSUPER) || \
823 defined(CONFIG_SPD823TS) )
824
825 WATCHDOG_RESET ();
wdenk9d2b18a2003-06-28 23:11:04 +0000826 debug ("Reset Ethernet PHY\n");
wdenkfe8c2802002-11-03 00:38:21 +0000827 reset_phy ();
828#endif
829
830#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
831 WATCHDOG_RESET ();
832 puts ("KGDB: ");
833 kgdb_init ();
834#endif
835
wdenk9d2b18a2003-06-28 23:11:04 +0000836 debug ("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000837
838 /*
839 * Enable Interrupts
840 */
841 interrupt_init ();
842
843 /* Must happen after interrupts are initialized since
844 * an irq handler gets installed
845 */
846#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
847 serial_buffered_init();
848#endif
849
850#ifdef CONFIG_STATUS_LED
851 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
852#endif
853
854 udelay (20);
855
856 set_timer (0);
857
858 /* Insert function pointers now that we have relocated the code */
859
860 /* Initialize from environment */
861 if ((s = getenv ("loadaddr")) != NULL) {
862 load_addr = simple_strtoul (s, NULL, 16);
863 }
864#if (CONFIG_COMMANDS & CFG_CMD_NET)
865 if ((s = getenv ("bootfile")) != NULL) {
866 copy_filename (BootFile, s, sizeof (BootFile));
867 }
868#endif /* CFG_CMD_NET */
869
870 WATCHDOG_RESET ();
871
872#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
873 WATCHDOG_RESET ();
874 puts ("SCSI: ");
875 scsi_init ();
876#endif
877
878#if (CONFIG_COMMANDS & CFG_CMD_DOC)
879 WATCHDOG_RESET ();
880 puts ("DOC: ");
881 doc_init ();
882#endif
883
stroesebedc4972003-05-23 11:16:49 +0000884#if (CONFIG_COMMANDS & CFG_CMD_NAND)
885 WATCHDOG_RESET ();
wdenka43278a2003-09-11 19:48:06 +0000886 puts ("NAND:");
stroesebedc4972003-05-23 11:16:49 +0000887 nand_init(); /* go init the NAND */
888#endif
889
wdenkfe8c2802002-11-03 00:38:21 +0000890#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
891 WATCHDOG_RESET ();
892 puts ("Net: ");
893 eth_initialize (bd);
894#endif
895
896#ifdef CONFIG_POST
wdenk6dff5522003-07-15 07:45:49 +0000897 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000898#endif
899
900#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
901 WATCHDOG_RESET ();
902 puts ("PCMCIA:");
903 pcmcia_init ();
904#endif
905
906#if (CONFIG_COMMANDS & CFG_CMD_IDE)
907 WATCHDOG_RESET ();
908# ifdef CONFIG_IDE_8xx_PCCARD
909 puts ("PCMCIA:");
910# else
911 puts ("IDE: ");
912#endif
913 ide_init ();
914#endif /* CFG_CMD_IDE */
915
916#ifdef CONFIG_LAST_STAGE_INIT
917 WATCHDOG_RESET ();
918 /*
919 * Some parts can be only initialized if all others (like
920 * Interrupts) are up and running (i.e. the PC-style ISA
921 * keyboard).
922 */
923 last_stage_init ();
924#endif
925
926#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
927 WATCHDOG_RESET ();
928 bedbug_init ();
929#endif
930
wdenk228f29a2002-12-08 09:53:23 +0000931#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000932 /*
933 * Export available size of memory for Linux,
934 * taking into account the protected RAM at top of memory
935 */
936 {
937 ulong pram;
wdenkfe8c2802002-11-03 00:38:21 +0000938 uchar memsz[32];
wdenk228f29a2002-12-08 09:53:23 +0000939#ifdef CONFIG_PRAM
940 char *s;
wdenkfe8c2802002-11-03 00:38:21 +0000941
942 if ((s = getenv ("pram")) != NULL) {
943 pram = simple_strtoul (s, NULL, 10);
944 } else {
945 pram = CONFIG_PRAM;
946 }
wdenk228f29a2002-12-08 09:53:23 +0000947#else
948 pram=0;
949#endif
950#ifdef CONFIG_LOGBUFFER
951 /* Also take the logbuffer into account (pram is in kB) */
952 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
953#endif
wdenkfe8c2802002-11-03 00:38:21 +0000954 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
955 setenv ("mem", memsz);
956 }
957#endif
958
wdenk4532cb62003-04-27 22:52:51 +0000959#ifdef CONFIG_MODEM_SUPPORT
960 {
961 extern int do_mdm_init;
962 do_mdm_init = gd->do_mdm_init;
963 }
964#endif
965
wdenkfe8c2802002-11-03 00:38:21 +0000966 /* Initialization complete - start the monitor */
967
968 /* main_loop() can return to retry autoboot, if so just run it again. */
969 for (;;) {
970 WATCHDOG_RESET ();
971 main_loop ();
972 }
973
974 /* NOTREACHED - no way out of command loop except booting */
975}
976
977void hang (void)
978{
979 puts ("### ERROR ### Please RESET the board ###\n");
980 for (;;);
981}
982
wdenk4532cb62003-04-27 22:52:51 +0000983#ifdef CONFIG_MODEM_SUPPORT
984/* called from main loop (common/main.c) */
985extern void dbg(const char *fmt, ...);
986int mdm_init (void)
987{
988 char env_str[16];
989 char *init_str;
990 int i;
991 extern char console_buffer[];
992 static inline void mdm_readline(char *buf, int bufsiz);
993 extern void enable_putc(void);
994 extern int hwflow_onoff(int);
995
996 enable_putc(); /* enable serial_putc() */
997
998#ifdef CONFIG_HWFLOW
999 init_str = getenv("mdm_flow_control");
1000 if (init_str && (strcmp(init_str, "rts/cts") == 0))
1001 hwflow_onoff (1);
1002 else
1003 hwflow_onoff(-1);
1004#endif
1005
1006 for (i = 1;;i++) {
1007 sprintf(env_str, "mdm_init%d", i);
1008 if ((init_str = getenv(env_str)) != NULL) {
1009 serial_puts(init_str);
1010 serial_puts("\n");
1011 for(;;) {
1012 mdm_readline(console_buffer, CFG_CBSIZE);
1013 dbg("ini%d: [%s]", i, console_buffer);
1014
1015 if ((strcmp(console_buffer, "OK") == 0) ||
1016 (strcmp(console_buffer, "ERROR") == 0)) {
1017 dbg("ini%d: cmd done", i);
1018 break;
1019 } else /* in case we are originating call ... */
1020 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1021 dbg("ini%d: connect", i);
1022 return 0;
1023 }
1024 }
1025 } else
1026 break; /* no init string - stop modem init */
1027
1028 udelay(100000);
1029 }
1030
1031 udelay(100000);
1032
1033 /* final stage - wait for connect */
1034 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1035 message from modem */
1036 mdm_readline(console_buffer, CFG_CBSIZE);
1037 dbg("ini_f: [%s]", console_buffer);
1038 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1039 dbg("ini_f: connected");
1040 return 0;
1041 }
1042 }
1043
1044 return 0;
1045}
1046
1047/* 'inline' - We have to do it fast */
1048static inline void mdm_readline(char *buf, int bufsiz)
1049{
1050 char c;
1051 char *p;
1052 int n;
1053
1054 n = 0;
1055 p = buf;
1056 for(;;) {
1057 c = serial_getc();
1058
1059 /* dbg("(%c)", c); */
1060
1061 switch(c) {
1062 case '\r':
1063 break;
1064 case '\n':
1065 *p = '\0';
1066 return;
1067
1068 default:
1069 if(n++ > bufsiz) {
1070 *p = '\0';
1071 return; /* sanity check */
1072 }
1073 *p = c;
1074 p++;
1075 break;
1076 }
1077 }
1078}
1079#endif
1080
wdenkfe8c2802002-11-03 00:38:21 +00001081#if 0 /* We could use plain global data, but the resulting code is bigger */
1082/*
1083 * Pointer to initial global data area
1084 *
1085 * Here we initialize it.
1086 */
1087#undef XTRN_DECLARE_GLOBAL_DATA_PTR
1088#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1089DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1090#endif /* 0 */
1091
1092/************************************************************************/