board.c 22.6 KB
Newer Older
wdenk's avatar
wdenk committed
1
/*
2
 * (C) Copyright 2002-2006
wdenk's avatar
wdenk committed
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.
 *
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Marius Groeger <mgroeger@sysgo.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
 */

28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * To match the U-Boot user interface on ARM platforms to the U-Boot
 * standard (as on PPC platforms), some messages with debug character
 * are removed from the default U-Boot build.
 *
 * Define DEBUG here if you want additional info as shown below
 * printed upon startup:
 *
 * U-Boot code: 00F00000 -> 00F3C774  BSS: -> 00FC3274
 * IRQ Stack: 00ebff7c
 * FIQ Stack: 00ebef7c
 */

wdenk's avatar
wdenk committed
41 42
#include <common.h>
#include <command.h>
wdenk's avatar
wdenk committed
43
#include <malloc.h>
44
#include <stdio_dev.h>
45
#include <timestamp.h>
wdenk's avatar
wdenk committed
46 47
#include <version.h>
#include <net.h>
48
#include <serial.h>
49 50
#include <nand.h>
#include <onenand_uboot.h>
51
#include <mmc.h>
wdenk's avatar
wdenk committed
52

53 54 55 56
#ifdef CONFIG_BITBANGMII
#include <miiphy.h>
#endif

wdenk's avatar
wdenk committed
57
#ifdef CONFIG_DRIVER_SMC91111
58
#include "../drivers/net/smc91111.h"
wdenk's avatar
wdenk committed
59 60
#endif
#ifdef CONFIG_DRIVER_LAN91C96
61
#include "../drivers/net/lan91c96.h"
wdenk's avatar
wdenk committed
62 63
#endif

64 65
DECLARE_GLOBAL_DATA_PTR;

66 67
ulong monitor_flash_len;

68 69 70 71 72
#ifdef CONFIG_HAS_DATAFLASH
extern int  AT91F_DataflashInit(void);
extern void dataflash_print_info(void);
#endif

wdenk's avatar
wdenk committed
73 74 75 76
#ifndef CONFIG_IDENT_STRING
#define CONFIG_IDENT_STRING ""
#endif

wdenk's avatar
wdenk committed
77
const char version_string[] =
78
	U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
wdenk's avatar
wdenk committed
79

wdenk's avatar
wdenk committed
80
#ifdef CONFIG_DRIVER_RTL8019
81 82 83
extern void rtl8019_get_enetaddr (uchar * addr);
#endif

84 85 86 87 88
#if defined(CONFIG_HARD_I2C) || \
    defined(CONFIG_SOFT_I2C)
#include <i2c.h>
#endif

Stelian Pop's avatar
Stelian Pop committed
89

90 91 92 93 94 95
/************************************************************************
 * Coloured LED functionality
 ************************************************************************
 * May be supplied by boards if desired
 */
void inline __coloured_LED_init (void) {}
Ron Lee's avatar
Ron Lee committed
96
void coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init")));
97
void inline __red_LED_on (void) {}
Ron Lee's avatar
Ron Lee committed
98
void red_LED_on (void) __attribute__((weak, alias("__red_LED_on")));
99
void inline __red_LED_off(void) {}
Ron Lee's avatar
Ron Lee committed
100
void red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
101
void inline __green_LED_on(void) {}
Ron Lee's avatar
Ron Lee committed
102
void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
103
void inline __green_LED_off(void) {}
Ron Lee's avatar
Ron Lee committed
104
void green_LED_off(void) __attribute__((weak, alias("__green_LED_off")));
105
void inline __yellow_LED_on(void) {}
Ron Lee's avatar
Ron Lee committed
106
void yellow_LED_on(void) __attribute__((weak, alias("__yellow_LED_on")));
107
void inline __yellow_LED_off(void) {}
Ron Lee's avatar
Ron Lee committed
108
void yellow_LED_off(void) __attribute__((weak, alias("__yellow_LED_off")));
109
void inline __blue_LED_on(void) {}
Ron Lee's avatar
Ron Lee committed
110
void blue_LED_on(void) __attribute__((weak, alias("__blue_LED_on")));
111
void inline __blue_LED_off(void) {}
Ron Lee's avatar
Ron Lee committed
112
void blue_LED_off(void) __attribute__((weak, alias("__blue_LED_off")));
113

wdenk's avatar
wdenk committed
114 115 116 117 118 119 120 121
/************************************************************************
 * Init Utilities							*
 ************************************************************************
 * Some of this code should be moved into the core functions,
 * or dropped completely,
 * but let's get it working (again) first...
 */

122 123 124
#if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
#define CONFIG_BAUDRATE 115200
#endif
wdenk's avatar
wdenk committed
125 126
static int init_baudrate (void)
{
Wolfgang Denk's avatar
Wolfgang Denk committed
127
	char tmp[64];	/* long enough for environment variables */
128
	int i = getenv_f("baudrate", tmp, sizeof (tmp));
Heiko Schocher's avatar
Heiko Schocher committed
129 130 131 132

#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
	gd->baudrate = (i > 0)
#else
wdenk's avatar
wdenk committed
133
	gd->bd->bi_baudrate = gd->baudrate = (i > 0)
Heiko Schocher's avatar
Heiko Schocher committed
134
#endif
wdenk's avatar
wdenk committed
135 136 137 138 139 140 141 142 143
			? (int) simple_strtoul (tmp, NULL, 10)
			: CONFIG_BAUDRATE;

	return (0);
}

static int display_banner (void)
{
	printf ("\n\n%s\n\n", version_string);
144
	debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
Heiko Schocher's avatar
Heiko Schocher committed
145 146 147 148 149 150
#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
	       _TEXT_BASE,
#else
	       _armboot_start,
#endif
	       _bss_start, _bss_end);
wdenk's avatar
wdenk committed
151
#ifdef CONFIG_MODEM_SUPPORT
152
	debug ("Modem Support enabled\n");
wdenk's avatar
wdenk committed
153 154
#endif
#ifdef CONFIG_USE_IRQ
155 156
	debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
	debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
wdenk's avatar
wdenk committed
157
#endif
158

wdenk's avatar
wdenk committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172
	return (0);
}

/*
 * WARNING: this code looks "cleaner" than the PowerPC version, but
 * has the disadvantage that you either get nothing, or everything.
 * On PowerPC, you might see "DRAM: " before the system hangs - which
 * gives a simple yet clear indication which part of the
 * initialization if failing.
 */
static int display_dram_config (void)
{
	int i;

173
#ifdef DEBUG
wdenk's avatar
wdenk committed
174
	puts ("RAM Configuration:\n");
wdenk's avatar
wdenk committed
175 176 177 178 179

	for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
		printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
		print_size (gd->bd->bi_dram[i].size, "\n");
	}
180 181 182 183 184 185 186 187 188
#else
	ulong size = 0;

	for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
		size += gd->bd->bi_dram[i].size;
	}
	puts("DRAM:  ");
	print_size(size, "\n");
#endif
wdenk's avatar
wdenk committed
189 190 191 192

	return (0);
}

Heiko Schocher's avatar
Heiko Schocher committed
193
#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
194
#ifndef CONFIG_SYS_NO_FLASH
wdenk's avatar
wdenk committed
195 196 197 198 199
static void display_flash_config (ulong size)
{
	puts ("Flash: ");
	print_size (size, "\n");
}
200
#endif /* CONFIG_SYS_NO_FLASH */
Heiko Schocher's avatar
Heiko Schocher committed
201
#endif
wdenk's avatar
wdenk committed
202

203 204 205 206
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
static int init_func_i2c (void)
{
	puts ("I2C:   ");
207
	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
208 209 210 211 212
	puts ("ready\n");
	return (0);
}
#endif

213 214 215 216 217 218 219 220 221
#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
#include <pci.h>
static int arm_pci_init(void)
{
	pci_init();
	return 0;
}
#endif /* CONFIG_CMD_PCI || CONFIG_PCI */

wdenk's avatar
wdenk committed
222
/*
wdenk's avatar
wdenk committed
223
 * Breathe some life into the board...
wdenk's avatar
wdenk committed
224
 *
225
 * Initialize a serial port as console, and carry out some hardware
wdenk's avatar
wdenk committed
226 227 228 229 230 231 232 233 234 235 236
 * tests.
 *
 * The first part of initialization is running from Flash memory;
 * its main purpose is to initialize the RAM so that we
 * can relocate the monitor code to RAM.
 */

/*
 * 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
wdenk's avatar
wdenk committed
237
 * mess of board dependent #ifdef'ed code we now make the whole
wdenk's avatar
wdenk committed
238 239 240 241 242 243 244 245 246
 * 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".
 */
typedef int (init_fnc_t) (void);

247
int print_cpuinfo (void);
248

Heiko Schocher's avatar
Heiko Schocher committed
249
#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
wdenk's avatar
wdenk committed
250
init_fnc_t *init_sequence[] = {
251 252 253
#if defined(CONFIG_ARCH_CPU_INIT)
	arch_cpu_init,		/* basic arch cpu dependent setup */
#endif
wdenk's avatar
wdenk committed
254
	board_init,		/* basic board dependent setup */
255
#if defined(CONFIG_USE_IRQ)
wdenk's avatar
wdenk committed
256
	interrupt_init,		/* set up exceptions */
257 258
#endif
	timer_init,		/* initialize timer */
259 260 261
#ifdef CONFIG_FSL_ESDHC
	get_clocks,
#endif
wdenk's avatar
wdenk committed
262 263 264
	env_init,		/* initialize environment */
	init_baudrate,		/* initialze baudrate settings */
	serial_init,		/* serial communications setup */
wdenk's avatar
wdenk committed
265
	console_init_f,		/* stage 1 init of console */
266
	display_banner,		/* say that we are here */
267 268 269 270 271
#if defined(CONFIG_DISPLAY_CPUINFO)
	print_cpuinfo,		/* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
	checkboard,		/* display board info */
272 273 274
#endif
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	init_func_i2c,
275
#endif
wdenk's avatar
wdenk committed
276
	dram_init,		/* configure available RAM banks */
277 278 279
#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
	arm_pci_init,
#endif
wdenk's avatar
wdenk committed
280 281 282 283 284 285 286
	display_dram_config,
	NULL,
};

void start_armboot (void)
{
	init_fnc_t **init_fnc_ptr;
wdenk's avatar
wdenk committed
287
	char *s;
288
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
wdenk's avatar
wdenk committed
289 290 291 292
	unsigned long addr;
#endif

	/* Pointer is writable since we allocated a register for it */
293
	gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
294 295 296
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("": : :"memory");

wdenk's avatar
wdenk committed
297 298
	memset ((void*)gd, 0, sizeof (gd_t));
	gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
wdenk's avatar
wdenk committed
299 300
	memset (gd->bd, 0, sizeof (bd_t));

301 302
	gd->flags |= GD_FLG_RELOC;

wdenk's avatar
wdenk committed
303
	monitor_flash_len = _bss_start - _armboot_start;
304

wdenk's avatar
wdenk committed
305 306 307 308 309 310
	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

311
	/* armboot_start is defined in the board-specific linker script */
312 313
	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
			CONFIG_SYS_MALLOC_LEN);
314

315
#ifndef CONFIG_SYS_NO_FLASH
wdenk's avatar
wdenk committed
316
	/* configure available FLASH banks */
317
	display_flash_config (flash_init ());
318
#endif /* CONFIG_SYS_NO_FLASH */
wdenk's avatar
wdenk committed
319 320

#ifdef CONFIG_VFD
wdenk's avatar
wdenk committed
321 322 323
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
wdenk's avatar
wdenk committed
324 325 326
	/*
	 * reserve memory for VFD display (always full pages)
	 */
327 328
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
329
	vfd_setmem (addr);
wdenk's avatar
wdenk committed
330 331 332
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

333
#ifdef CONFIG_LCD
Stelian Pop's avatar
Stelian Pop committed
334 335 336 337 338 339 340 341 342 343
	/* board init may have inited fb_base */
	if (!gd->fb_base) {
#		ifndef PAGE_SIZE
#		  define PAGE_SIZE 4096
#		endif
		/*
		 * reserve memory for LCD display (always full pages)
		 */
		/* bss_end is defined in the board-specific linker script */
		addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
344
		lcd_setmem (addr);
Stelian Pop's avatar
Stelian Pop committed
345 346
		gd->fb_base = addr;
	}
347 348
#endif /* CONFIG_LCD */

349
#if defined(CONFIG_CMD_NAND)
350
	puts ("NAND:  ");
wdenk's avatar
wdenk committed
351 352 353
	nand_init();		/* go init the NAND */
#endif

Kyungmin Park's avatar
Kyungmin Park committed
354 355 356 357
#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

358 359 360 361 362
#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

Terry Lv's avatar
Terry Lv committed
363 364 365 366 367 368 369 370 371 372
#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.
 */
	puts ("MMC:   ");
	mmc_initialize (gd->bd);
#endif

373 374 375
	/* initialize environment */
	env_relocate ();

wdenk's avatar
wdenk committed
376 377 378
#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
wdenk's avatar
wdenk committed
379
#endif /* CONFIG_VFD */
wdenk's avatar
wdenk committed
380

381 382 383 384
#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

wdenk's avatar
wdenk committed
385
	/* IP Address */
wdenk's avatar
wdenk committed
386
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
wdenk's avatar
wdenk committed
387

388
	stdio_init ();	/* get the devices list going. */
wdenk's avatar
wdenk committed
389

390
	jumptable_init ();
wdenk's avatar
wdenk committed
391

392 393 394 395 396
#if defined(CONFIG_API)
	/* Initialize API */
	api_init ();
#endif

wdenk's avatar
wdenk committed
397 398
	console_init_r ();	/* fully init console as a device */

399 400 401 402
#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init ();
#endif
wdenk's avatar
wdenk committed
403 404 405 406 407 408 409 410
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r ();
#endif

	/* enable exceptions */
	enable_interrupts ();

wdenk's avatar
wdenk committed
411
	/* Perform network card initialisation if necessary */
412

wdenk's avatar
wdenk committed
413
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
414
	/* XXX: this needs to be moved to board init */
wdenk's avatar
wdenk committed
415
	if (getenv ("ethaddr")) {
416 417 418
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
wdenk's avatar
wdenk committed
419
	}
wdenk's avatar
wdenk committed
420
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
wdenk's avatar
wdenk committed
421

wdenk's avatar
wdenk committed
422 423 424 425
	/* Initialize from environment */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
426
#if defined(CONFIG_CMD_NET)
wdenk's avatar
wdenk committed
427 428 429
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
430
#endif
wdenk's avatar
wdenk committed
431

432 433
#ifdef BOARD_LATE_INIT
	board_late_init ();
wdenk's avatar
wdenk committed
434
#endif
435

436 437 438
#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
439
#if defined(CONFIG_CMD_NET)
440
#if defined(CONFIG_NET_MULTI)
wdenk's avatar
wdenk committed
441
	puts ("Net:   ");
442
#endif
wdenk's avatar
wdenk committed
443
	eth_initialize(gd->bd);
444 445 446 447
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
wdenk's avatar
wdenk committed
448
#endif
wdenk's avatar
wdenk committed
449 450 451 452 453 454 455
	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop ();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
Heiko Schocher's avatar
Heiko Schocher committed
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
#else
void __dram_init_banksize(void)
{
	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
	gd->bd->bi_dram[0].size =  gd->ram_size;
}
void dram_init_banksize(void)
	__attribute__((weak, alias("__dram_init_banksize")));

init_fnc_t *init_sequence[] = {
#if defined(CONFIG_ARCH_CPU_INIT)
	arch_cpu_init,		/* basic arch cpu dependent setup */
#endif
#if defined(CONFIG_BOARD_EARLY_INIT_F)
	board_early_init_f,
#endif
	timer_init,		/* initialize timer */
#ifdef CONFIG_FSL_ESDHC
	get_clocks,
#endif
	env_init,		/* initialize environment */
	init_baudrate,		/* initialze baudrate settings */
	serial_init,		/* serial communications setup */
	console_init_f,		/* stage 1 init of console */
	display_banner,		/* say that we are here */
#if defined(CONFIG_DISPLAY_CPUINFO)
	print_cpuinfo,		/* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
	checkboard,		/* display board info */
#endif
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	init_func_i2c,
#endif
	dram_init,		/* configure available RAM banks */
#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
	arm_pci_init,
#endif
	NULL,
};

void board_init_f (ulong bootflag)
{
	bd_t *bd;
	init_fnc_t **init_fnc_ptr;
	gd_t *id;
	ulong addr, addr_sp;

	/* Pointer is writable since we allocated a register for it */
	gd = (gd_t *) (CONFIG_SYS_INIT_SP_ADDR);
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("": : :"memory");

	memset ((void*)gd, 0, sizeof (gd_t));

	gd->mon_len = _bss_end - _TEXT_BASE;

	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

	debug ("monitor len: %08lX\n", gd->mon_len);
	/*
	 * Ram is setup, size stored in gd !!
	 */
	debug ("ramsize: %08lX\n", gd->ram_size);
#if defined(CONFIG_SYS_MEM_TOP_HIDE)
	/*
	 * 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.
	 */
	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
#endif

	addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;

#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
	/* reserve kernel log buffer */
	addr -= (LOGBUFF_RESERVE);
	debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
#endif
#endif

#ifdef CONFIG_PRAM
	/*
	 * reserve protected RAM
	 */
	i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
	reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
	addr -= (reg << 10);		/* size is in kB */
	debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
#endif /* CONFIG_PRAM */

#if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
	/* reserve TLB table */
	addr -= (4096 * 4);

	/* round down to next 64 kB limit */
	addr &= ~(0x10000 - 1);

	gd->tlb_addr = addr;
	debug ("TLB table at: %08lx\n", addr);
#endif

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

#ifdef CONFIG_VFD
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
	/*
	 * reserve memory for VFD display (always full pages)
	 */
	addr -= vfd_setmem (addr);
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

#ifdef CONFIG_LCD
	/* reserve memory for LCD display (always full pages) */
	addr = lcd_setmem (addr);
	gd->fb_base = addr;
#endif /* CONFIG_LCD */

	/*
	 * reserve memory for U-Boot code, data & bss
	 * round down to next 4 kB limit
	 */
	addr -= gd->mon_len;
	addr &= ~(4096 - 1);

	debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);

#ifndef CONFIG_PRELOADER
	/*
	 * reserve memory for malloc() arena
	 */
	addr_sp = addr - TOTAL_MALLOC_LEN;
	debug ("Reserving %dk for malloc() at: %08lx\n",
			TOTAL_MALLOC_LEN >> 10, addr_sp);
	/*
	 * (permanently) allocate a Board Info struct
	 * and a permanent copy of the "global" data
	 */
	addr_sp -= sizeof (bd_t);
	bd = (bd_t *) addr_sp;
	gd->bd = bd;
	debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
			sizeof (bd_t), addr_sp);
	addr_sp -= sizeof (gd_t);
	id = (gd_t *) addr_sp;
	debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
			sizeof (gd_t), addr_sp);

	/* setup stackpointer for exeptions */
	gd->irq_sp = addr_sp;
#ifdef CONFIG_USE_IRQ
	addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
	debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
		CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
#endif
	/* leave 3 words for abort-stack    */
	addr_sp -= 3;

	/* 8-byte alignment for ABI compliance */
	addr_sp &= ~0x07;
#else
	addr_sp += 128;	/* leave 32 words for abort-stack   */
	gd->irq_sp = addr_sp;
#endif

	debug ("New Stack Pointer is: %08lx\n", addr_sp);

#ifdef CONFIG_POST
	post_bootmode_init();
	post_run (NULL, POST_ROM | post_bootmode_get(0));
#endif

	gd->bd->bi_baudrate = gd->baudrate;
	/* Ram ist board specific, so move it to board code ... */
	dram_init_banksize();
	display_dram_config();	/* and display it */

	gd->relocaddr = addr;
	gd->start_addr_sp = addr_sp;
	gd->reloc_off = addr - _TEXT_BASE;
	debug ("relocation Offset is: %08lx\n", gd->reloc_off);
	memcpy (id, (void *)gd, sizeof (gd_t));

	relocate_code (addr_sp, id, addr);

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

#if !defined(CONFIG_SYS_NO_FLASH)
static char *failed = "*** failed ***\n";
#endif

/************************************************************************
 *
 * 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.
 *
 ************************************************************************
 */
void board_init_r (gd_t *id, ulong dest_addr)
{
	char *s;
	bd_t *bd;
	ulong malloc_start;
#if !defined(CONFIG_SYS_NO_FLASH)
	ulong flash_size;
#endif
#if !defined(CONFIG_RELOC_FIXUP_WORKS)
	extern void malloc_bin_reloc (void);
#if defined(CONFIG_CMD_BMP)
	extern void bmp_reloc(void);
#endif
#if defined(CONFIG_CMD_I2C)
	extern void i2c_reloc(void);
#endif
#endif

	gd = id;
	bd = gd->bd;

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

	monitor_flash_len = _bss_start - _TEXT_BASE;
	debug ("monitor flash len: %08lX\n", monitor_flash_len);
	board_init();	/* Setup chipselects */

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

	debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);

#if !defined(CONFIG_RELOC_FIXUP_WORKS)
	/*
	 * We have to relocate the command table manually
	 */
	fixup_cmdtable(&__u_boot_cmd_start,
		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
#if defined(CONFIG_CMD_BMP)
	bmp_reloc();
#endif
#if defined(CONFIG_CMD_I2C)
	i2c_reloc();
#endif
#endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */

#ifdef CONFIG_LOGBUFFER
	logbuff_init_ptrs ();
#endif
#ifdef CONFIG_POST
	post_output_backlog ();
#ifndef CONFIG_RELOC_FIXUP_WORKS
	post_reloc ();
#endif
#endif

	/* The Malloc area is immediately below the monitor copy in DRAM */
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
#if !defined(CONFIG_RELOC_FIXUP_WORKS)
	malloc_bin_reloc ();
#endif

#if !defined(CONFIG_SYS_NO_FLASH)
	puts ("FLASH: ");

	if ((flash_size = flash_init ()) > 0) {
# ifdef CONFIG_SYS_FLASH_CHECKSUM
		print_size (flash_size, "");
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
		s = getenv ("flashchecksum");
		if (s && (*s == 'y')) {
			printf ("  CRC: %08X",
				crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
			);
		}
		putc ('\n');
# else	/* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size (flash_size, "\n");
# endif /* CONFIG_SYS_FLASH_CHECKSUM */
	} else {
		puts (failed);
		hang ();
	}
#endif

#if defined(CONFIG_CMD_NAND)
	puts ("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	env_relocate ();

#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
#endif /* CONFIG_VFD */

	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

	stdio_init ();	/* get the devices list going. */

	jumptable_init ();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init ();
#endif

	console_init_r ();	/* fully init console as a device */

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init ();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r ();
#endif

	 /* set up exceptions */
	interrupt_init ();
	/* enable exceptions */
	enable_interrupts ();

	/* Perform network card initialisation if necessary */
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
	/* XXX: this needs to be moved to board init */
	if (getenv ("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
	}
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

	/* Initialize from environment */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
#if defined(CONFIG_CMD_NET)
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
#endif

#ifdef BOARD_LATE_INIT
	board_late_init ();
#endif

#ifdef CONFIG_GENERIC_MMC
	puts ("MMC:   ");
	mmc_initialize (gd->bd);
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts ("Net:   ");
#endif
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif

#ifdef CONFIG_POST
	post_run (NULL, POST_RAM | post_bootmode_get(0));
#endif

#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
		ulong pram;
		uchar memsz[32];
#ifdef CONFIG_PRAM
		char *s;

		if ((s = getenv ("pram")) != NULL) {
			pram = simple_strtoul (s, NULL, 10);
		} else {
			pram = CONFIG_PRAM;
		}
#else
		pram=0;
#endif
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
		/* Also take the logbuffer into account (pram is in kB) */
		pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
#endif
#endif
		sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
		setenv ("mem", (char *)memsz);
	}
#endif

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop ();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
#endif /* defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
wdenk's avatar
wdenk committed
899 900 901 902 903 904

void hang (void)
{
	puts ("### ERROR ### Please RESET the board ###\n");
	for (;;);
}