board.c 25.0 KB
Newer Older
W
wdenk 已提交
1
/*
2
 * (C) Copyright 2000-2011
W
wdenk 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <malloc.h>
28
#include <stdio_dev.h>
W
wdenk 已提交
29 30 31
#ifdef CONFIG_8xx
#include <mpc8xx.h>
#endif
32 33 34
#ifdef CONFIG_5xx
#include <mpc5xx.h>
#endif
W
wdenk 已提交
35
#ifdef CONFIG_MPC5xxx
36 37
#include <mpc5xxx.h>
#endif
38
#if defined(CONFIG_CMD_IDE)
W
wdenk 已提交
39 40
#include <ide.h>
#endif
41
#if defined(CONFIG_CMD_SCSI)
W
wdenk 已提交
42 43
#include <scsi.h>
#endif
44
#if defined(CONFIG_CMD_KGDB)
W
wdenk 已提交
45 46 47 48 49 50
#include <kgdb.h>
#endif
#ifdef CONFIG_STATUS_LED
#include <status_led.h>
#endif
#include <net.h>
A
Andy Fleming 已提交
51 52 53
#ifdef CONFIG_GENERIC_MMC
#include <mmc.h>
#endif
W
wdenk 已提交
54
#include <serial.h>
55
#ifdef CONFIG_SYS_ALLOC_DPRAM
56
#if !defined(CONFIG_CPM2)
W
wdenk 已提交
57 58
#include <commproc.h>
#endif
W
wdenk 已提交
59
#endif
W
wdenk 已提交
60 61 62 63 64 65 66 67
#include <version.h>
#if defined(CONFIG_BAB7xx)
#include <w83c553f.h>
#endif
#include <dtt.h>
#if defined(CONFIG_POST)
#include <post.h>
#endif
68 69 70
#if defined(CONFIG_LOGBUFFER)
#include <logbuff.h>
#endif
71
#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
W
wdenk 已提交
72 73
#include <asm/cache.h>
#endif
74 75 76
#ifdef CONFIG_PS2KBD
#include <keyboard.h>
#endif
W
wdenk 已提交
77

78 79 80 81
#ifdef CONFIG_ADDR_MAP
#include <asm/mmu.h>
#endif

82 83 84 85
#ifdef CONFIG_MP
#include <asm/mp.h>
#endif

86 87 88 89
#ifdef CONFIG_BITBANGMII
#include <miiphy.h>
#endif

90
#ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
91
extern int update_flash_size(int flash_size);
92 93
#endif

94
#if defined(CONFIG_SC3)
95 96 97
extern void sc3_read_eeprom(void);
#endif

98
#if defined(CONFIG_CMD_DOC)
99
void doc_init(void);
W
wdenk 已提交
100 101 102 103 104
#endif
#if defined(CONFIG_HARD_I2C) || \
    defined(CONFIG_SOFT_I2C)
#include <i2c.h>
#endif
105
#include <spi.h>
106
#include <nand.h>
W
wdenk 已提交
107 108 109

static char *failed = "*** failed ***\n";

110
#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
W
wdenk 已提交
111
extern flash_info_t flash_info[];
W
wdenk 已提交
112
#endif
W
wdenk 已提交
113

114 115 116
#if defined(CONFIG_START_IDE)
extern int board_start_ide(void);
#endif
W
wdenk 已提交
117
#include <environment.h>
118

119
DECLARE_GLOBAL_DATA_PTR;
W
wdenk 已提交
120

121 122
#if !defined(CONFIG_SYS_MEM_TOP_HIDE)
#define CONFIG_SYS_MEM_TOP_HIDE	0
123 124
#endif

125
extern ulong __init_end;
P
Po-Yu Chuang 已提交
126
extern ulong __bss_end__;
127 128
ulong monitor_flash_len;

129
#if defined(CONFIG_CMD_BEDBUG)
W
wdenk 已提交
130 131 132
#include <bedbug/type.h>
#endif

133 134
/*
 * Utilities
W
wdenk 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148
 */

/*
 * All attempts to come up with a "common" initialization sequence
 * that works for all boards and architectures failed: some of the
 * requirements are just _too_ different. To get rid of the resulting
 * mess of board dependend #ifdef'ed code we now make the whole
 * initialization sequence configurable to the user.
 *
 * The requirements for any new initalization function is simple: it
 * receives a pointer to the "global data" structure as it's only
 * argument, and returns an integer return code, where 0 means
 * "continue" and != 0 means "fatal error, hang the system".
 */
149
typedef int (init_fnc_t)(void);
W
wdenk 已提交
150

151 152 153
/*
 * Init Utilities
 *
W
wdenk 已提交
154 155 156 157
 * Some of this code should be moved into the core functions,
 * but let's get it working (again) first...
 */

158
static int init_baudrate(void)
W
wdenk 已提交
159
{
160 161
	gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
	return 0;
W
wdenk 已提交
162 163 164 165
}

/***********************************************************************/

166 167 168 169
void __board_add_ram_info(int use_default)
{
	/* please define platform specific board_add_ram_info() */
}
170 171 172

void board_add_ram_info(int)
	__attribute__ ((weak, alias("__board_add_ram_info")));
173

174 175 176 177 178 179 180 181 182
int __board_flash_wp_on(void)
{
	/*
	 * Most flashes can't be detected when write protection is enabled,
	 * so provide a way to let U-Boot gracefully ignore write protected
	 * devices.
	 */
	return 0;
}
183 184 185

int board_flash_wp_on(void)
	__attribute__ ((weak, alias("__board_flash_wp_on")));
186

187 188 189
void __cpu_secondary_init_r(void)
{
}
190

191
void cpu_secondary_init_r(void)
192
	__attribute__ ((weak, alias("__cpu_secondary_init_r")));
193

194
static int init_func_ram(void)
W
wdenk 已提交
195 196 197 198 199 200
{
#ifdef	CONFIG_BOARD_TYPES
	int board_type = gd->board_type;
#else
	int board_type = 0;	/* use dummy arg */
#endif
201
	puts("DRAM:  ");
W
wdenk 已提交
202

203 204 205 206
	gd->ram_size = initdram(board_type);

	if (gd->ram_size > 0) {
		print_size(gd->ram_size, "");
207 208
		board_add_ram_info(0);
		putc('\n');
209
		return 0;
W
wdenk 已提交
210
	}
211 212
	puts(failed);
	return 1;
W
wdenk 已提交
213 214 215 216 217
}

/***********************************************************************/

#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
218
static int init_func_i2c(void)
W
wdenk 已提交
219
{
220 221 222 223
	puts("I2C:   ");
	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
	puts("ready\n");
	return 0;
W
wdenk 已提交
224 225 226
}
#endif

227
#if defined(CONFIG_HARD_SPI)
228
static int init_func_spi(void)
229
{
230 231 232 233
	puts("SPI:   ");
	spi_init();
	puts("ready\n");
	return 0;
234 235 236
}
#endif

W
wdenk 已提交
237 238 239
/***********************************************************************/

#if defined(CONFIG_WATCHDOG)
240
static int init_func_watchdog_init(void)
W
wdenk 已提交
241
{
242 243 244
	puts("       Watchdog enabled\n");
	WATCHDOG_RESET();
	return 0;
W
wdenk 已提交
245 246
}

247 248 249
#define INIT_FUNC_WATCHDOG_INIT	init_func_watchdog_init,

static int init_func_watchdog_reset(void)
W
wdenk 已提交
250
{
251 252
	WATCHDOG_RESET();
	return 0;
W
wdenk 已提交
253
}
254 255

#define INIT_FUNC_WATCHDOG_RESET	init_func_watchdog_reset,
W
wdenk 已提交
256
#else
257 258
#define INIT_FUNC_WATCHDOG_INIT		/* undef */
#define INIT_FUNC_WATCHDOG_RESET	/* undef */
W
wdenk 已提交
259 260
#endif /* CONFIG_WATCHDOG */

261 262
/*
 * Initialization sequence
W
wdenk 已提交
263 264 265
 */

init_fnc_t *init_sequence[] = {
266 267 268
#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
	probecpu,
#endif
269 270 271
#if defined(CONFIG_BOARD_EARLY_INIT_F)
	board_early_init_f,
#endif
W
wdenk 已提交
272
#if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
W
wdenk 已提交
273
	get_clocks,		/* get CPU and bus clocks (etc.) */
274 275
#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
    && !defined(CONFIG_TQM885D)
276 277
	adjust_sdram_tbs_8xx,
#endif
W
wdenk 已提交
278
	init_timebase,
279
#endif
280
#ifdef CONFIG_SYS_ALLOC_DPRAM
281
#if !defined(CONFIG_CPM2)
W
wdenk 已提交
282 283
	dpram_init,
#endif
W
wdenk 已提交
284
#endif
W
wdenk 已提交
285 286 287 288
#if defined(CONFIG_BOARD_POSTCLK_INIT)
	board_postclk_init,
#endif
	env_init,
W
wdenk 已提交
289
#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
290 291 292 293
	/* get CPU and bus clocks according to the environment variable */
	get_clocks_866,
	/* adjust sdram refresh rate according to the new clock */
	sdram_adjust_866,
294 295
	init_timebase,
#endif
W
wdenk 已提交
296 297 298 299 300 301 302 303
	init_baudrate,
	serial_init,
	console_init_f,
	display_options,
#if defined(CONFIG_8260)
	prt_8260_rsr,
	prt_8260_clks,
#endif /* CONFIG_8260 */
304
#if defined(CONFIG_MPC83xx)
305 306
	prt_83xx_rsr,
#endif
W
wdenk 已提交
307
	checkcpu,
W
wdenk 已提交
308
#if defined(CONFIG_MPC5xxx)
309
	prt_mpc5xxx_clks,
W
wdenk 已提交
310
#endif /* CONFIG_MPC5xxx */
W
wdenk 已提交
311 312 313
#if defined(CONFIG_MPC8220)
	prt_mpc8220_clks,
#endif
W
wdenk 已提交
314 315
	checkboard,
	INIT_FUNC_WATCHDOG_INIT
316
#if defined(CONFIG_MISC_INIT_F)
W
wdenk 已提交
317 318 319 320 321 322
	misc_init_f,
#endif
	INIT_FUNC_WATCHDOG_RESET
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	init_func_i2c,
#endif
323 324 325
#if defined(CONFIG_HARD_SPI)
	init_func_spi,
#endif
W
wdenk 已提交
326 327
#ifdef CONFIG_POST
	post_init_f,
W
wdenk 已提交
328
#endif
329
	INIT_FUNC_WATCHDOG_RESET init_func_ram,
330
#if defined(CONFIG_SYS_DRAM_TEST)
W
wdenk 已提交
331
	testdram,
332
#endif /* CONFIG_SYS_DRAM_TEST */
W
wdenk 已提交
333
	INIT_FUNC_WATCHDOG_RESET
334
	NULL,	/* Terminate this list */
W
wdenk 已提交
335 336
};

337 338 339 340 341 342 343
ulong get_effective_memsize(void)
{
#ifndef	CONFIG_VERY_BIG_RAM
	return gd->ram_size;
#else
	/* limit stack to what we can reasonable map */
	return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
344
		CONFIG_MAX_MEM_MAPPED : gd->ram_size);
345 346 347
#endif
}

348
/*
W
wdenk 已提交
349 350 351 352 353 354 355 356 357 358 359 360
 * This is the first part of the initialization sequence that is
 * implemented in C, but still running from ROM.
 *
 * The main purpose is to provide a (serial) console interface as
 * soon as possible (so we can see any error messages), and to
 * initialize the RAM so that we can relocate the monitor code to
 * RAM.
 *
 * Be aware of the restrictions: global data is read-only, BSS is not
 * initialized, and stack space is limited to a few kB.
 */

361 362 363
#ifdef CONFIG_LOGBUFFER
unsigned long logbuffer_base(void)
{
364
	return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
365 366 367
}
#endif

368
void board_init_f(ulong bootflag)
W
wdenk 已提交
369 370 371
{
	bd_t *bd;
	ulong len, addr, addr_sp;
W
Wolfgang Denk 已提交
372
	ulong *s;
W
wdenk 已提交
373 374
	gd_t *id;
	init_fnc_t **init_fnc_ptr;
375

W
wdenk 已提交
376 377 378 379 380
#ifdef CONFIG_PRAM
	ulong reg;
#endif

	/* Pointer is writable since we allocated a register for it */
381
	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
382
	/* compiler optimization barrier needed for GCC >= 3.4 */
383
	__asm__ __volatile__("":::"memory");
W
wdenk 已提交
384

385 386 387
#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
    !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
    !defined(CONFIG_MPC86xx)
W
wdenk 已提交
388
	/* Clear initial global data */
389
	memset((void *) gd, 0, sizeof(gd_t));
W
wdenk 已提交
390 391
#endif

392 393 394
	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
		if ((*init_fnc_ptr) () != 0)
			hang();
W
wdenk 已提交
395

396 397 398 399 400 401 402
#ifdef CONFIG_POST
	post_bootmode_init();
	post_run(NULL, POST_ROM | post_bootmode_get(0));
#endif

	WATCHDOG_RESET();

W
wdenk 已提交
403 404 405 406 407
	/*
	 * Now that we have DRAM mapped and working, we can
	 * relocate the code and continue running from DRAM.
	 *
	 * Reserve memory at end of RAM for (top down in that order):
408
	 *  - area that won't get touched by U-Boot and Linux (optional)
W
wdenk 已提交
409
	 *  - kernel log buffer
W
wdenk 已提交
410 411 412 413 414
	 *  - protected RAM
	 *  - LCD framebuffer
	 *  - monitor code
	 *  - board info struct
	 */
P
Po-Yu Chuang 已提交
415
	len = (ulong)&__bss_end__ - CONFIG_SYS_MONITOR_BASE;
W
wdenk 已提交
416

417 418 419 420 421 422 423 424 425 426
	/*
	 * Subtract specified amount of memory to hide so that it won't
	 * get "touched" at all by U-Boot. By fixing up gd->ram_size
	 * the Linux kernel should now get passed the now "corrected"
	 * memory size and won't touch it either. This should work
	 * for arch/ppc and arch/powerpc. Only Linux board ports in
	 * arch/powerpc with bootwrapper support, that recalculate the
	 * memory size from the SDRAM controller setup will have to
	 * get fixed.
	 */
427
	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
428

429
	addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
W
wdenk 已提交
430

431 432 433 434
#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
	/*
	 * We need to make sure the location we intend to put secondary core
	 * boot code is reserved and not used by any part of u-boot
435
	 */
436 437
	if (addr > determine_mp_bootpg()) {
		addr = determine_mp_bootpg();
438
		debug("Reserving MP boot page to %08lx\n", addr);
439 440 441
	}
#endif

442
#ifdef CONFIG_LOGBUFFER
443
#ifndef CONFIG_ALT_LB_ADDR
444 445
	/* reserve kernel log buffer */
	addr -= (LOGBUFF_RESERVE);
446 447
	debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
	      addr);
448
#endif
449
#endif
450

W
wdenk 已提交
451 452 453 454
#ifdef CONFIG_PRAM
	/*
	 * reserve protected RAM
	 */
455
	reg = getenv_ulong("pram", 10, CONFIG_PRAM);
456
	addr -= (reg << 10);	/* size is in kB */
457
	debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
W
wdenk 已提交
458 459 460 461
#endif /* CONFIG_PRAM */

	/* round down to next 4 kB limit */
	addr &= ~(4096 - 1);
462
	debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
W
wdenk 已提交
463 464

#ifdef CONFIG_LCD
465 466 467
#ifdef CONFIG_FB_ADDR
	gd->fb_base = CONFIG_FB_ADDR;
#else
W
wdenk 已提交
468
	/* reserve memory for LCD display (always full pages) */
469
	addr = lcd_setmem(addr);
W
wdenk 已提交
470
	gd->fb_base = addr;
471
#endif /* CONFIG_FB_ADDR */
W
wdenk 已提交
472 473 474 475
#endif /* CONFIG_LCD */

#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
	/* reserve memory for video display (always full pages) */
476
	addr = video_setmem(addr);
W
wdenk 已提交
477 478 479 480 481
	gd->fb_base = addr;
#endif /* CONFIG_VIDEO  */

	/*
	 * reserve memory for U-Boot code, data & bss
482
	 * round down to next 4 kB limit
W
wdenk 已提交
483 484
	 */
	addr -= len;
485
	addr &= ~(4096 - 1);
486 487 488 489
#ifdef CONFIG_E500
	/* round down to next 64 kB limit so that IVPR stays aligned */
	addr &= ~(65536 - 1);
#endif
W
wdenk 已提交
490

491
	debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
W
wdenk 已提交
492 493 494 495 496

	/*
	 * reserve memory for malloc() arena
	 */
	addr_sp = addr - TOTAL_MALLOC_LEN;
497 498
	debug("Reserving %dk for malloc() at: %08lx\n",
	      TOTAL_MALLOC_LEN >> 10, addr_sp);
W
wdenk 已提交
499 500 501 502 503

	/*
	 * (permanently) allocate a Board Info struct
	 * and a permanent copy of the "global" data
	 */
504
	addr_sp -= sizeof(bd_t);
W
wdenk 已提交
505
	bd = (bd_t *) addr_sp;
506
	memset(bd, 0, sizeof(bd_t));
W
wdenk 已提交
507
	gd->bd = bd;
508 509 510
	debug("Reserving %zu Bytes for Board Info at: %08lx\n",
	      sizeof(bd_t), addr_sp);
	addr_sp -= sizeof(gd_t);
W
wdenk 已提交
511
	id = (gd_t *) addr_sp;
512 513
	debug("Reserving %zu Bytes for Global Data at: %08lx\n",
	      sizeof(gd_t), addr_sp);
W
wdenk 已提交
514 515 516 517 518 519 520 521 522

	/*
	 * Finally, we set up a new (bigger) stack.
	 *
	 * Leave some safety gap for SP, force alignment on 16 byte boundary
	 * Clear initial stack frame
	 */
	addr_sp -= 16;
	addr_sp &= ~0xF;
523
	s = (ulong *) addr_sp;
524 525
	*s = 0; /* Terminate back chain */
	*++s = 0; /* NULL return address */
526
	debug("Stack Pointer at: %08lx\n", addr_sp);
W
wdenk 已提交
527 528 529 530 531

	/*
	 * Save local variables to board info struct
	 */

532 533
	bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;	/* start of memory */
	bd->bi_memsize = gd->ram_size;			/* size in bytes */
W
wdenk 已提交
534

535
#ifdef CONFIG_SYS_SRAM_BASE
536 537
	bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;	/* start of SRAM */
	bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;		/* size  of SRAM */
W
wdenk 已提交
538 539
#endif

W
wdenk 已提交
540
#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
541
    defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
542
	bd->bi_immr_base = CONFIG_SYS_IMMR;	/* base  of IMMR register     */
W
wdenk 已提交
543
#endif
W
wdenk 已提交
544
#if defined(CONFIG_MPC5xxx)
545
	bd->bi_mbar_base = CONFIG_SYS_MBAR;	/* base of internal registers */
546
#endif
547
#if defined(CONFIG_MPC83xx)
548
	bd->bi_immrbar = CONFIG_SYS_IMMR;
E
Eran Liberty 已提交
549
#endif
W
wdenk 已提交
550
#if defined(CONFIG_MPC8220)
551
	bd->bi_mbar_base = CONFIG_SYS_MBAR;	/* base of internal registers */
552 553 554 555 556
	bd->bi_inpfreq = gd->inp_clk;
	bd->bi_pcifreq = gd->pci_clk;
	bd->bi_vcofreq = gd->vco_clk;
	bd->bi_pevfreq = gd->pev_clk;
	bd->bi_flbfreq = gd->flb_clk;
W
wdenk 已提交
557

W
Wolfgang Denk 已提交
558 559
	/* store bootparam to sram (backward compatible), here? */
	{
560 561
		u32 *sram = (u32 *) CONFIG_SYS_SRAM_BASE;

W
Wolfgang Denk 已提交
562 563 564 565 566 567
		*sram++ = gd->ram_size;
		*sram++ = gd->bus_clk;
		*sram++ = gd->inp_clk;
		*sram++ = gd->cpu_clk;
		*sram++ = gd->vco_clk;
		*sram++ = gd->flb_clk;
568
		*sram++ = 0xb8c3ba11;	/* boot signature */
W
Wolfgang Denk 已提交
569
	}
W
wdenk 已提交
570
#endif
W
wdenk 已提交
571

572
	WATCHDOG_RESET();
W
wdenk 已提交
573 574
	bd->bi_intfreq = gd->cpu_clk;	/* Internal Freq, in Hz */
	bd->bi_busfreq = gd->bus_clk;	/* Bus Freq,      in Hz */
575
#if defined(CONFIG_CPM2)
W
wdenk 已提交
576 577 578
	bd->bi_cpmfreq = gd->cpm_clk;
	bd->bi_brgfreq = gd->brg_clk;
	bd->bi_sccfreq = gd->scc_clk;
579
	bd->bi_vco = gd->vco_out;
580
#endif /* CONFIG_CPM2 */
581
#if defined(CONFIG_MPC512X)
582
	bd->bi_ipsfreq = gd->ips_clk;
583
#endif /* CONFIG_MPC512X */
W
wdenk 已提交
584
#if defined(CONFIG_MPC5xxx)
585 586
	bd->bi_ipbfreq = gd->ipb_clk;
	bd->bi_pcifreq = gd->pci_clk;
W
wdenk 已提交
587
#endif /* CONFIG_MPC5xxx */
W
wdenk 已提交
588 589
	bd->bi_baudrate = gd->baudrate;	/* Console Baudrate     */

590
#ifdef CONFIG_SYS_EXTBDINFO
591 592 593
	strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
	strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
		sizeof(bd->bi_r_version));
W
wdenk 已提交
594 595 596

	bd->bi_procfreq = gd->cpu_clk;	/* Processor Speed, In Hz */
	bd->bi_plb_busfreq = gd->bus_clk;
597 598 599
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
    defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
    defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
600 601
	bd->bi_pci_busfreq = get_PCI_freq();
	bd->bi_opbfreq = get_OPB_freq();
602
#elif defined(CONFIG_XILINX_405)
603
	bd->bi_pci_busfreq = get_PCI_freq();
W
wdenk 已提交
604 605 606
#endif
#endif

607
	debug("New Stack Pointer is: %08lx\n", addr_sp);
W
wdenk 已提交
608

609
	WATCHDOG_RESET();
W
wdenk 已提交
610

611
	gd->relocaddr = addr;	/* Store relocation addr, useful for debug */
612

613
	memcpy(id, (void *) gd, sizeof(gd_t));
W
wdenk 已提交
614

615
	relocate_code(addr_sp, id, addr);
W
wdenk 已提交
616 617 618 619

	/* NOTREACHED - relocate_code() does not return */
}

620
/*
W
wdenk 已提交
621 622 623 624 625
 * This is the next part if the initialization sequence: we are now
 * running from RAM and have a "normal" C environment, i. e. global
 * data can be written, BSS has been cleared, the stack size in not
 * that critical any more, etc.
 */
626
void board_init_r(gd_t *id, ulong dest_addr)
W
wdenk 已提交
627 628
{
	bd_t *bd;
629
	ulong malloc_start;
630

631
#ifndef CONFIG_SYS_NO_FLASH
W
wdenk 已提交
632 633 634 635 636 637 638
	ulong flash_size;
#endif

	gd = id;		/* initialize RAM version of global data */
	bd = gd->bd;

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
639

640
	/* The Malloc area is immediately below the monitor copy in DRAM */
641
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
642

643 644 645 646 647 648
#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
	/*
	 * The gd->cpu pointer is set to an address in flash before relocation.
	 * We need to update it to point to the same CPU entry in RAM.
	 */
	gd->cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
649 650 651 652 653 654 655 656 657 658 659
#endif

#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
	/*
	 * Some systems need to relocate the env_addr pointer early because the
	 * location it points to will get invalidated before env_relocate is
	 * called.  One example is on systems that might use a L2 or L3 cache
	 * in SRAM mode and initialize that cache from SRAM mode back to being
	 * a cache in cpu_init_r.
	 */
	gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
660 661
#endif

662 663 664
#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif
W
wdenk 已提交
665

666
	debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
W
wdenk 已提交
667

668
	WATCHDOG_RESET();
W
wdenk 已提交
669

670 671 672
	/*
	 * Setup trap handlers
	 */
673
	trap_init(dest_addr);
674

675
#ifdef CONFIG_ADDR_MAP
676 677 678
	init_addr_map();
#endif

679
#if defined(CONFIG_BOARD_EARLY_INIT_R)
680
	board_early_init_r();
681 682
#endif

683
	monitor_flash_len = (ulong)&__init_end - dest_addr;
W
wdenk 已提交
684

685
	WATCHDOG_RESET();
W
wdenk 已提交
686

687
#ifdef CONFIG_LOGBUFFER
688
	logbuff_init_ptrs();
689
#endif
W
wdenk 已提交
690
#ifdef CONFIG_POST
691
	post_output_backlog();
W
wdenk 已提交
692 693 694 695
#endif

	WATCHDOG_RESET();

696
#if defined(CONFIG_SYS_DELAYED_ICACHE)
697
	icache_enable();	/* it's time to enable the instruction cache */
W
wdenk 已提交
698 699
#endif

700 701
#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
	unlock_ram_in_cache();	/* it's time to unlock D-cache in e500 */
W
wdenk 已提交
702 703
#endif

704
#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
W
wdenk 已提交
705
	/*
706 707
	 * Do early PCI configuration _before_ the flash gets initialised,
	 * because PCU ressources are crucial for flash access on some boards.
W
wdenk 已提交
708
	 */
709
	pci_init();
W
wdenk 已提交
710
#endif
711
#if defined(CONFIG_WINBOND_83C553)
W
wdenk 已提交
712 713 714
	/*
	 * Initialise the ISA bridge
	 */
715
	initialise_w83c553f();
W
wdenk 已提交
716 717
#endif

718
	asm("sync ; isync");
W
wdenk 已提交
719

720
	mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
721

722
#if !defined(CONFIG_SYS_NO_FLASH)
723
	puts("Flash: ");
W
wdenk 已提交
724

725 726 727 728
	if (board_flash_wp_on()) {
		printf("Uninitialized - Write Protect On\n");
		/* Since WP is on, we can't find real size.  Set to 0 */
		flash_size = 0;
729 730
	} else if ((flash_size = flash_init()) > 0) {
#ifdef CONFIG_SYS_FLASH_CHECKSUM
731 732
		char *s;

733
		print_size(flash_size, "");
W
wdenk 已提交
734 735 736 737 738
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
739
		s = getenv("flashchecksum");
W
wdenk 已提交
740
		if (s && (*s == 'y')) {
741 742 743 744 745
			printf("  CRC: %08X",
			       crc32(0,
				     (const unsigned char *)
				     CONFIG_SYS_FLASH_BASE, flash_size)
				);
W
wdenk 已提交
746
		}
747 748 749 750
		putc('\n');
#else  /* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size(flash_size, "\n");
#endif /* CONFIG_SYS_FLASH_CHECKSUM */
W
wdenk 已提交
751
	} else {
752 753
		puts(failed);
		hang();
W
wdenk 已提交
754 755
	}

756 757 758 759
	/* update start of FLASH memory    */
	bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
	/* size of FLASH memory (final value) */
	bd->bi_flashsize = flash_size;
760

761
#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
762
	/* Make a update of the Memctrl. */
763
	update_flash_size(flash_size);
764 765 766
#endif


767
#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
768
	/* flash mapped at end of memory map */
769
	bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
770 771 772
#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
	bd->bi_flashoffset = monitor_flash_len;	/* reserved area for monitor */
#endif
773
#endif /* !CONFIG_SYS_NO_FLASH */
W
wdenk 已提交
774

775
	WATCHDOG_RESET();
W
wdenk 已提交
776 777

	/* initialize higher level parts of CPU like time base and timers */
778
	cpu_init_r();
W
wdenk 已提交
779

780
	WATCHDOG_RESET();
W
wdenk 已提交
781 782

#ifdef CONFIG_SPI
783 784 785 786
#if !defined(CONFIG_ENV_IS_IN_EEPROM)
	spi_init_f();
#endif
	spi_init_r();
W
wdenk 已提交
787 788
#endif

789
#if defined(CONFIG_CMD_NAND)
790 791
	WATCHDOG_RESET();
	puts("NAND:  ");
792 793 794
	nand_init();		/* go init the NAND */
#endif

T
Terry Lv 已提交
795 796 797 798 799 800
#ifdef CONFIG_GENERIC_MMC
/*
 * MMC initialization is called before relocating env.
 * Thus It is required that operations like pin multiplexer
 * be put in board_init.
 */
801 802 803
	WATCHDOG_RESET();
	puts("MMC:  ");
	mmc_initialize(bd);
T
Terry Lv 已提交
804 805
#endif

W
wdenk 已提交
806
	/* relocate environment function pointers etc. */
807
	env_relocate();
W
wdenk 已提交
808

809 810 811 812 813 814 815 816
	/*
	 * after non-volatile devices & environment is setup and cpu code have
	 * another round to deal with any initialization that might require
	 * full access to the environment or loading of some image (firmware)
	 * from a non-volatile device
	 */
	cpu_secondary_init_r();

W
wdenk 已提交
817 818
	/*
	 * Fill in missing fields of bd_info.
W
wdenk 已提交
819 820
	 * We do this here, where we have "normal" access to the
	 * environment; we used to do this still running from ROM,
821
	 * where had to use getenv_f(), which can be pretty slow when
W
wdenk 已提交
822
	 * the environment is in EEPROM.
W
wdenk 已提交
823
	 */
W
wdenk 已提交
824

825
#if defined(CONFIG_SYS_EXTBDINFO)
W
wdenk 已提交
826 827 828 829 830 831 832
#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
#if defined(CONFIG_I2CFAST)
	/*
	 * set bi_iic_fast for linux taking environment variable
	 * "i2cfast" into account
	 */
	{
833 834
		char *s = getenv("i2cfast");

W
wdenk 已提交
835 836 837 838 839
		if (s && ((*s == 'y') || (*s == 'Y'))) {
			bd->bi_iic_fast[0] = 1;
			bd->bi_iic_fast[1] = 1;
		}
	}
840 841 842
#endif /* CONFIG_I2CFAST */
#endif /* CONFIG_405GP, CONFIG_405EP */
#endif /* CONFIG_SYS_EXTBDINFO */
W
wdenk 已提交
843

844
#if defined(CONFIG_SC3)
845 846
	sc3_read_eeprom();
#endif
847

848
#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
849 850 851
	mac_read_from_eeprom();
#endif

W
wdenk 已提交
852 853 854 855 856 857 858
#ifdef	CONFIG_HERMES
	if ((gd->board_type >> 16) == 2)
		bd->bi_ethspeed = gd->board_type & 0xFFFF;
	else
		bd->bi_ethspeed = 0xFFFF;
#endif

859
#ifdef CONFIG_CMD_NET
860 861
	/* kept around for legacy kernels only ... ignore the next section */
	eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
W
wdenk 已提交
862
#ifdef CONFIG_HAS_ETH1
863
	eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
W
wdenk 已提交
864
#endif
W
wdenk 已提交
865
#ifdef CONFIG_HAS_ETH2
866
	eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
W
wdenk 已提交
867
#endif
W
wdenk 已提交
868
#ifdef CONFIG_HAS_ETH3
869
	eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
W
wdenk 已提交
870
#endif
871
#ifdef CONFIG_HAS_ETH4
872
	eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
873 874
#endif
#ifdef CONFIG_HAS_ETH5
875
	eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
876
#endif
877
#endif /* CONFIG_CMD_NET */
878

879
	WATCHDOG_RESET();
W
wdenk 已提交
880

881
#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
W
wdenk 已提交
882 883 884
	/*
	 * Do pci configuration
	 */
885
	pci_init();
W
wdenk 已提交
886 887 888
#endif

/** leave this here (after malloc(), environment and PCI are working) **/
889
	/* Initialize stdio devices */
890
	stdio_init();
W
wdenk 已提交
891

892
	/* Initialize the jump table for applications */
893
	jumptable_init();
W
wdenk 已提交
894

895 896
#if defined(CONFIG_API)
	/* Initialize API */
897
	api_init();
898 899
#endif

W
wdenk 已提交
900
	/* Initialize the console (after the relocation and devices init) */
901
	console_init_r();
W
wdenk 已提交
902

903
#if defined(CONFIG_MISC_INIT_R)
W
wdenk 已提交
904
	/* miscellaneous platform dependent initialisations */
905
	misc_init_r();
W
wdenk 已提交
906 907 908 909
#endif

#ifdef	CONFIG_HERMES
	if (bd->bi_ethspeed != 0xFFFF)
910
		hermes_start_lxt980((int) bd->bi_ethspeed);
W
wdenk 已提交
911 912
#endif

913
#if defined(CONFIG_CMD_KGDB)
914 915 916
	WATCHDOG_RESET();
	puts("KGDB:  ");
	kgdb_init();
W
wdenk 已提交
917 918
#endif

919
	debug("U-Boot relocated to %08lx\n", dest_addr);
W
wdenk 已提交
920 921 922 923

	/*
	 * Enable Interrupts
	 */
924
	interrupt_init();
W
wdenk 已提交
925

926
#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
927
	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
W
wdenk 已提交
928 929
#endif

930
	udelay(20);
W
wdenk 已提交
931 932

	/* Initialize from environment */
933
	load_addr = getenv_ulong("loadaddr", 16, load_addr);
W
wdenk 已提交
934

935
	WATCHDOG_RESET();
W
wdenk 已提交
936

937
#if defined(CONFIG_CMD_SCSI)
938 939 940
	WATCHDOG_RESET();
	puts("SCSI:  ");
	scsi_init();
W
wdenk 已提交
941 942
#endif

943
#if defined(CONFIG_CMD_DOC)
944 945 946
	WATCHDOG_RESET();
	puts("DOC:   ");
	doc_init();
W
wdenk 已提交
947 948
#endif

949 950 951
#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
952
#if defined(CONFIG_CMD_NET)
953 954 955
	WATCHDOG_RESET();
	puts("Net:   ");
	eth_initialize(bd);
W
wdenk 已提交
956 957
#endif

958
#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
959 960 961
	WATCHDOG_RESET();
	debug("Reset Ethernet PHY\n");
	reset_phy();
M
Marian Balakowicz 已提交
962 963
#endif

W
wdenk 已提交
964
#ifdef CONFIG_POST
965
	post_run(NULL, POST_RAM | post_bootmode_get(0));
W
wdenk 已提交
966 967
#endif

968 969
#if defined(CONFIG_CMD_PCMCIA) \
    && !defined(CONFIG_CMD_IDE)
970 971 972
	WATCHDOG_RESET();
	puts("PCMCIA:");
	pcmcia_init();
W
wdenk 已提交
973 974
#endif

975
#if defined(CONFIG_CMD_IDE)
976 977 978 979 980
	WATCHDOG_RESET();
#ifdef	CONFIG_IDE_8xx_PCCARD
	puts("PCMCIA:");
#else
	puts("IDE:   ");
W
wdenk 已提交
981
#endif
982 983
#if defined(CONFIG_START_IDE)
	if (board_start_ide())
984
		ide_init();
985
#else
986
	ide_init();
987
#endif
988
#endif
W
wdenk 已提交
989 990

#ifdef CONFIG_LAST_STAGE_INIT
991
	WATCHDOG_RESET();
W
wdenk 已提交
992 993 994 995 996
	/*
	 * Some parts can be only initialized if all others (like
	 * Interrupts) are up and running (i.e. the PC-style ISA
	 * keyboard).
	 */
997
	last_stage_init();
W
wdenk 已提交
998 999
#endif

1000
#if defined(CONFIG_CMD_BEDBUG)
1001 1002
	WATCHDOG_RESET();
	bedbug_init();
W
wdenk 已提交
1003 1004
#endif

1005
#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
W
wdenk 已提交
1006 1007 1008 1009 1010
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
1011
		ulong pram = 0;
1012
		char memsz[32];
W
wdenk 已提交
1013

1014 1015
#ifdef CONFIG_PRAM
		pram = getenv_ulong("pram", 10, CONFIG_PRAM);
1016 1017
#endif
#ifdef CONFIG_LOGBUFFER
1018
#ifndef CONFIG_ALT_LB_ADDR
1019
		/* Also take the logbuffer into account (pram is in kB) */
1020
		pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
1021
#endif
1022
#endif
1023 1024
		sprintf(memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
		setenv("mem", memsz);
W
wdenk 已提交
1025 1026 1027
	}
#endif

1028
#ifdef CONFIG_PS2KBD
1029
	puts("PS/2:  ");
1030 1031 1032
	kbd_init();
#endif

W
wdenk 已提交
1033
#ifdef CONFIG_MODEM_SUPPORT
1034 1035 1036 1037 1038
	{
		extern int do_mdm_init;

		do_mdm_init = gd->do_mdm_init;
	}
W
wdenk 已提交
1039 1040
#endif

W
wdenk 已提交
1041 1042 1043 1044
	/* Initialization complete - start the monitor */

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
1045 1046
		WATCHDOG_RESET();
		main_loop();
W
wdenk 已提交
1047 1048 1049 1050 1051
	}

	/* NOTREACHED - no way out of command loop except booting */
}

1052
void hang(void)
W
wdenk 已提交
1053
{
1054
	puts("### ERROR ### Please RESET the board ###\n");
1055
	bootstage_error(BOOTSTAGE_ID_NEED_RESET);
1056 1057
	for (;;)
		;
W
wdenk 已提交
1058 1059
}

W
wdenk 已提交
1060

1061
#if 0	/* We could use plain global data, but the resulting code is bigger */
W
wdenk 已提交
1062 1063 1064 1065 1066 1067 1068
/*
 * Pointer to initial global data area
 *
 * Here we initialize it.
 */
#undef	XTRN_DECLARE_GLOBAL_DATA_PTR
#define XTRN_DECLARE_GLOBAL_DATA_PTR	/* empty = allocate here */
1069 1070 1071
DECLARE_GLOBAL_DATA_PTR =
	(gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
#endif /* 0 */
W
wdenk 已提交
1072 1073

/************************************************************************/