board.c 11.8 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 */
wdenk's avatar
wdenk committed
128
	int i = getenv_r ("baudrate", tmp, sizeof (tmp));
wdenk's avatar
wdenk committed
129
	gd->bd->bi_baudrate = gd->baudrate = (i > 0)
wdenk's avatar
wdenk committed
130 131 132 133 134 135 136 137 138
			? (int) simple_strtoul (tmp, NULL, 10)
			: CONFIG_BAUDRATE;

	return (0);
}

static int display_banner (void)
{
	printf ("\n\n%s\n\n", version_string);
139 140
	debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
	       _armboot_start, _bss_start, _bss_end);
wdenk's avatar
wdenk committed
141
#ifdef CONFIG_MODEM_SUPPORT
142
	debug ("Modem Support enabled\n");
wdenk's avatar
wdenk committed
143 144
#endif
#ifdef CONFIG_USE_IRQ
145 146
	debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
	debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
wdenk's avatar
wdenk committed
147
#endif
148

wdenk's avatar
wdenk committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162
	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;

163
#ifdef DEBUG
wdenk's avatar
wdenk committed
164
	puts ("RAM Configuration:\n");
wdenk's avatar
wdenk committed
165 166 167 168 169

	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");
	}
170 171 172 173 174 175 176 177 178
#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
179 180 181 182

	return (0);
}

183
#ifndef CONFIG_SYS_NO_FLASH
wdenk's avatar
wdenk committed
184 185 186 187 188
static void display_flash_config (ulong size)
{
	puts ("Flash: ");
	print_size (size, "\n");
}
189
#endif /* CONFIG_SYS_NO_FLASH */
wdenk's avatar
wdenk committed
190

191 192 193 194
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
static int init_func_i2c (void)
{
	puts ("I2C:   ");
195
	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
196 197 198 199 200
	puts ("ready\n");
	return (0);
}
#endif

201 202 203 204 205 206 207 208 209
#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
210
/*
wdenk's avatar
wdenk committed
211
 * Breathe some life into the board...
wdenk's avatar
wdenk committed
212
 *
213
 * Initialize a serial port as console, and carry out some hardware
wdenk's avatar
wdenk committed
214 215 216 217 218 219 220 221 222 223 224
 * 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
225
 * mess of board dependent #ifdef'ed code we now make the whole
wdenk's avatar
wdenk committed
226 227 228 229 230 231 232 233 234
 * 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);

235
int print_cpuinfo (void);
236

wdenk's avatar
wdenk committed
237
init_fnc_t *init_sequence[] = {
238 239 240
#if defined(CONFIG_ARCH_CPU_INIT)
	arch_cpu_init,		/* basic arch cpu dependent setup */
#endif
wdenk's avatar
wdenk committed
241
	board_init,		/* basic board dependent setup */
242
#if defined(CONFIG_USE_IRQ)
wdenk's avatar
wdenk committed
243
	interrupt_init,		/* set up exceptions */
244 245
#endif
	timer_init,		/* initialize timer */
246 247 248
#ifdef CONFIG_FSL_ESDHC
	get_clocks,
#endif
wdenk's avatar
wdenk committed
249 250 251
	env_init,		/* initialize environment */
	init_baudrate,		/* initialze baudrate settings */
	serial_init,		/* serial communications setup */
wdenk's avatar
wdenk committed
252
	console_init_f,		/* stage 1 init of console */
253
	display_banner,		/* say that we are here */
254 255 256 257 258
#if defined(CONFIG_DISPLAY_CPUINFO)
	print_cpuinfo,		/* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
	checkboard,		/* display board info */
259 260 261
#endif
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	init_func_i2c,
262
#endif
wdenk's avatar
wdenk committed
263
	dram_init,		/* configure available RAM banks */
264 265 266
#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
	arm_pci_init,
#endif
wdenk's avatar
wdenk committed
267 268 269 270 271 272 273
	display_dram_config,
	NULL,
};

void start_armboot (void)
{
	init_fnc_t **init_fnc_ptr;
wdenk's avatar
wdenk committed
274
	char *s;
275
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
wdenk's avatar
wdenk committed
276 277 278 279
	unsigned long addr;
#endif

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

wdenk's avatar
wdenk committed
284 285
	memset ((void*)gd, 0, sizeof (gd_t));
	gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
wdenk's avatar
wdenk committed
286 287
	memset (gd->bd, 0, sizeof (bd_t));

288 289
	gd->flags |= GD_FLG_RELOC;

wdenk's avatar
wdenk committed
290
	monitor_flash_len = _bss_start - _armboot_start;
291

wdenk's avatar
wdenk committed
292 293 294 295 296 297
	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

298
	/* armboot_start is defined in the board-specific linker script */
299 300
	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
			CONFIG_SYS_MALLOC_LEN);
301

302
#ifndef CONFIG_SYS_NO_FLASH
wdenk's avatar
wdenk committed
303
	/* configure available FLASH banks */
304
	display_flash_config (flash_init ());
305
#endif /* CONFIG_SYS_NO_FLASH */
wdenk's avatar
wdenk committed
306 307

#ifdef CONFIG_VFD
wdenk's avatar
wdenk committed
308 309 310
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
wdenk's avatar
wdenk committed
311 312 313
	/*
	 * reserve memory for VFD display (always full pages)
	 */
314 315
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
316
	vfd_setmem (addr);
wdenk's avatar
wdenk committed
317 318 319
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

320
#ifdef CONFIG_LCD
Stelian Pop's avatar
Stelian Pop committed
321 322 323 324 325 326 327 328 329 330
	/* 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);
331
		lcd_setmem (addr);
Stelian Pop's avatar
Stelian Pop committed
332 333
		gd->fb_base = addr;
	}
334 335
#endif /* CONFIG_LCD */

336
#if defined(CONFIG_CMD_NAND)
337
	puts ("NAND:  ");
wdenk's avatar
wdenk committed
338 339 340
	nand_init();		/* go init the NAND */
#endif

Kyungmin Park's avatar
Kyungmin Park committed
341 342 343 344
#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

345 346 347 348 349
#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

350 351 352
	/* initialize environment */
	env_relocate ();

wdenk's avatar
wdenk committed
353 354 355
#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
wdenk's avatar
wdenk committed
356
#endif /* CONFIG_VFD */
wdenk's avatar
wdenk committed
357

358 359 360 361
#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

wdenk's avatar
wdenk committed
362
	/* IP Address */
wdenk's avatar
wdenk committed
363
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
wdenk's avatar
wdenk committed
364

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

367
	jumptable_init ();
wdenk's avatar
wdenk committed
368

369 370 371 372 373
#if defined(CONFIG_API)
	/* Initialize API */
	api_init ();
#endif

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

376 377 378 379
#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init ();
#endif
wdenk's avatar
wdenk committed
380 381 382 383 384 385 386 387
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r ();
#endif

	/* enable exceptions */
	enable_interrupts ();

wdenk's avatar
wdenk committed
388
	/* Perform network card initialisation if necessary */
389
#ifdef CONFIG_DRIVER_TI_EMAC
390
	/* XXX: this needs to be moved to board init */
391
extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
392
	if (getenv ("ethaddr")) {
393 394 395
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		davinci_eth_set_mac_addr(enetaddr);
396 397 398
	}
#endif

wdenk's avatar
wdenk committed
399
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
400
	/* XXX: this needs to be moved to board init */
wdenk's avatar
wdenk committed
401
	if (getenv ("ethaddr")) {
402 403 404
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
wdenk's avatar
wdenk committed
405
	}
wdenk's avatar
wdenk committed
406
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
wdenk's avatar
wdenk committed
407

wdenk's avatar
wdenk committed
408 409 410 411
	/* Initialize from environment */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
412
#if defined(CONFIG_CMD_NET)
wdenk's avatar
wdenk committed
413 414 415
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
416
#endif
wdenk's avatar
wdenk committed
417

418 419
#ifdef BOARD_LATE_INIT
	board_late_init ();
wdenk's avatar
wdenk committed
420
#endif
421 422 423 424 425 426

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

427 428 429
#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
430
#if defined(CONFIG_CMD_NET)
431
#if defined(CONFIG_NET_MULTI)
wdenk's avatar
wdenk committed
432
	puts ("Net:   ");
433
#endif
wdenk's avatar
wdenk committed
434
	eth_initialize(gd->bd);
435 436 437 438
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
wdenk's avatar
wdenk committed
439
#endif
wdenk's avatar
wdenk committed
440 441 442 443 444 445 446 447 448 449 450 451 452
	/* 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 */
}

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