]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_arm/board.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / lib_arm / board.c
1 /*
2  * (C) Copyright 2002-2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 /*
29  * To match the U-Boot user interface on ARM platforms to the U-Boot
30  * standard (as on PPC platforms), some messages with debug character
31  * are removed from the default U-Boot build.
32  *
33  * Define DEBUG here if you want additional info as shown below
34  * printed upon startup:
35  *
36  * U-Boot code: 00F00000 -> 00F3C774  BSS: -> 00FC3274
37  * IRQ Stack: 00ebff7c
38  * FIQ Stack: 00ebef7c
39  */
40
41 #include <common.h>
42 #include <command.h>
43 #include <malloc.h>
44 #include <stdio_dev.h>
45 #include <timestamp.h>
46 #include <version.h>
47 #include <net.h>
48 #include <serial.h>
49 #include <nand.h>
50 #include <onenand_uboot.h>
51 #include <mmc.h>
52
53 #ifdef CONFIG_DRIVER_SMC91111
54 #include "../drivers/net/smc91111.h"
55 #endif
56 #ifdef CONFIG_DRIVER_LAN91C96
57 #include "../drivers/net/lan91c96.h"
58 #endif
59
60 DECLARE_GLOBAL_DATA_PTR;
61
62 ulong monitor_flash_len;
63
64 #ifdef CONFIG_HAS_DATAFLASH
65 extern int  AT91F_DataflashInit(void);
66 extern void dataflash_print_info(void);
67 #endif
68
69 #ifndef CONFIG_IDENT_STRING
70 #define CONFIG_IDENT_STRING ""
71 #endif
72
73 const char version_string[] =
74         U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
75
76 #ifdef CONFIG_DRIVER_CS8900
77 extern void cs8900_get_enetaddr(void);
78 #endif
79
80 #ifdef CONFIG_DRIVER_RTL8019
81 extern void rtl8019_get_enetaddr(uchar * addr);
82 #endif
83
84 #if defined(CONFIG_HARD_I2C) || \
85     defined(CONFIG_SOFT_I2C)
86 #include <i2c.h>
87 #endif
88
89 /*
90  * Begin and End of memory area for malloc(), and current "brk"
91  */
92 static void *mem_malloc_start;
93 static void *mem_malloc_end;
94 static void *mem_malloc_brk;
95
96 static
97 void mem_malloc_init(void *dest_addr)
98 {
99         mem_malloc_start = dest_addr;
100         mem_malloc_end = dest_addr + CONFIG_SYS_MALLOC_LEN;
101         mem_malloc_brk = mem_malloc_start;
102
103         memset(mem_malloc_start, 0,
104                 mem_malloc_end - mem_malloc_start);
105 }
106
107 void *sbrk(ptrdiff_t increment)
108 {
109         void *old = mem_malloc_brk;
110         void *new = old + increment;
111
112         if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
113                 return NULL;
114         }
115         mem_malloc_brk = new;
116
117         return old;
118 }
119
120
121 /************************************************************************
122  * Coloured LED functionality
123  ************************************************************************
124  * May be supplied by boards if desired
125  */
126 void __coloured_LED_init(void) {}
127 void coloured_LED_init(void) __attribute__((weak, alias("__coloured_LED_init")));
128 void __red_LED_on(void) {}
129 void red_LED_on(void) __attribute__((weak, alias("__red_LED_on")));
130 void __red_LED_off(void) {}
131 void red_LED_off(void)       __attribute__((weak, alias("__red_LED_off")));
132 void __green_LED_on(void) {}
133 void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
134 void __green_LED_off(void) {}
135 void green_LED_off(void)__attribute__((weak, alias("__green_LED_off")));
136 void __yellow_LED_on(void) {}
137 void yellow_LED_on(void)__attribute__((weak, alias("__yellow_LED_on")));
138 void __yellow_LED_off(void) {}
139 void yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")));
140 void __blue_LED_on(void) {}
141 void blue_LED_on(void)__attribute__((weak, alias("__blue_LED_on")));
142 void __blue_LED_off(void) {}
143 void blue_LED_off(void)__attribute__((weak, alias("__blue_LED_off")));
144
145 /************************************************************************
146  * Init Utilities                                                       *
147  ************************************************************************
148  * Some of this code should be moved into the core functions,
149  * or dropped completely,
150  * but let's get it working (again) first...
151  */
152
153 #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
154 #define CONFIG_BAUDRATE 115200
155 #endif
156 static int init_baudrate(void)
157 {
158         char tmp[64];   /* long enough for environment variables */
159         int i = getenv_r("baudrate", tmp, sizeof(tmp));
160
161         gd->bd->bi_baudrate = gd->baudrate = (i > 0) ?
162                 (int)simple_strtoul(tmp, NULL, 10) :
163                 CONFIG_BAUDRATE;
164
165         return 0;
166 }
167
168 static int display_banner(void)
169 {
170         printf("\n\n%s\n\n", version_string);
171         debug("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
172                _armboot_start, _bss_start, _bss_end);
173 #ifdef CONFIG_MODEM_SUPPORT
174         debug("Modem Support enabled\n");
175 #endif
176 #ifdef CONFIG_USE_IRQ
177         debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
178         debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
179 #endif
180
181         return 0;
182 }
183
184 /*
185  * WARNING: this code looks "cleaner" than the PowerPC version, but
186  * has the disadvantage that you either get nothing, or everything.
187  * On PowerPC, you might see "DRAM: " before the system hangs - which
188  * gives a simple yet clear indication which part of the
189  * initialization if failing.
190  */
191 static int display_dram_config(void)
192 {
193         int i;
194
195 #ifdef DEBUG
196         puts("RAM Configuration:\n");
197
198         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
199                 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
200                 print_size(gd->bd->bi_dram[i].size, "\n");
201         }
202 #else
203         ulong size = 0;
204
205         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
206                 size += gd->bd->bi_dram[i].size;
207         }
208         puts("DRAM:  ");
209         print_size(size, "\n");
210 #endif
211
212         return 0;
213 }
214
215 #ifndef CONFIG_SYS_NO_FLASH
216 static void display_flash_config(ulong size)
217 {
218         puts("Flash: ");
219         print_size(size, "\n");
220 }
221 #endif /* CONFIG_SYS_NO_FLASH */
222
223 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
224 static int init_func_i2c(void)
225 {
226         puts("I2C:   ");
227         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
228         puts("ready\n");
229         return (0);
230 }
231 #endif
232
233 #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
234 #include <pci.h>
235 static int arm_pci_init(void)
236 {
237         pci_init();
238         return 0;
239 }
240 #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
241
242 /*
243  * Breathe some life into the board...
244  *
245  * Initialize a serial port as console, and carry out some hardware
246  * tests.
247  *
248  * The first part of initialization is running from Flash memory;
249  * its main purpose is to initialize the RAM so that we
250  * can relocate the monitor code to RAM.
251  */
252
253 /*
254  * All attempts to come up with a "common" initialization sequence
255  * that works for all boards and architectures failed: some of the
256  * requirements are just _too_ different. To get rid of the resulting
257  * mess of board dependent #ifdef'ed code we now make the whole
258  * initialization sequence configurable to the user.
259  *
260  * The requirements for any new initalization function is simple: it
261  * receives a pointer to the "global data" structure as it's only
262  * argument, and returns an integer return code, where 0 means
263  * "continue" and != 0 means "fatal error, hang the system".
264  */
265 typedef int (init_fnc_t)(void);
266
267 int print_cpuinfo(void);
268
269 init_fnc_t *init_sequence[] = {
270 #if defined(CONFIG_ARCH_CPU_INIT)
271         arch_cpu_init,          /* basic arch cpu dependent setup */
272 #endif
273         board_init,             /* basic board dependent setup */
274 #if defined(CONFIG_USE_IRQ)
275         interrupt_init,         /* set up exceptions */
276 #endif
277         timer_init,             /* initialize timer */
278         env_init,               /* initialize environment */
279         init_baudrate,          /* initialze baudrate settings */
280         serial_init,            /* serial communications setup */
281         console_init_f,         /* stage 1 init of console */
282         display_banner,         /* say that we are here */
283 #if defined(CONFIG_DISPLAY_CPUINFO)
284         print_cpuinfo,          /* display cpu info (and speed) */
285 #endif
286 #if defined(CONFIG_DISPLAY_BOARDINFO)
287         checkboard,             /* display board info */
288 #endif
289 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
290         init_func_i2c,
291 #endif
292         dram_init,              /* configure available RAM banks */
293 #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
294         arm_pci_init,
295 #endif
296         display_dram_config,
297         NULL,
298 };
299
300 void start_armboot(void)
301 {
302         init_fnc_t **init_fnc_ptr;
303         char *s;
304 #if defined(CONFIG_VFD) || defined(CONFIG_LCD)
305         unsigned long addr;
306 #endif
307
308         /* Pointer is writable since we allocated a register for it */
309         gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
310         /* compiler optimization barrier needed for GCC >= 3.4 */
311         __asm__ __volatile__("": : :"memory");
312
313         memset((void *)gd, 0, sizeof(gd_t));
314         gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
315         memset(gd->bd, 0, sizeof(bd_t));
316
317         gd->flags |= GD_FLG_RELOC;
318
319         monitor_flash_len = _bss_start - _armboot_start;
320
321         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
322                 if ((*init_fnc_ptr)() != 0) {
323                         hang();
324                 }
325         }
326
327         /* armboot_start is defined in the board-specific linker script */
328         mem_malloc_init((void *)(_armboot_start - CONFIG_SYS_MALLOC_LEN));
329
330 #ifndef CONFIG_SYS_NO_FLASH
331         /* configure available FLASH banks */
332         display_flash_config(flash_init());
333 #endif /* CONFIG_SYS_NO_FLASH */
334
335 #ifdef CONFIG_VFD
336 #       ifndef PAGE_SIZE
337 #         define PAGE_SIZE 4096
338 #       endif
339         /*
340          * reserve memory for VFD display (always full pages)
341          */
342         /* bss_end is defined in the board-specific linker script */
343         addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
344         vfd_setmem(addr);
345         gd->fb_base = addr;
346 #endif /* CONFIG_VFD */
347
348 #ifdef CONFIG_LCD
349         /* board init may have inited fb_base */
350         if (!gd->fb_base) {
351 #               ifndef PAGE_SIZE
352 #                 define PAGE_SIZE 4096
353 #               endif
354                 /*
355                  * reserve memory for LCD display (always full pages)
356                  */
357                 /* bss_end is defined in the board-specific linker script */
358                 addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
359                 lcd_setmem(addr);
360                 gd->fb_base = addr;
361         }
362 #endif /* CONFIG_LCD */
363
364 #if defined(CONFIG_CMD_NAND)
365         puts("NAND:  ");
366         nand_init();            /* go init the NAND */
367 #endif
368
369 #if defined(CONFIG_CMD_ONENAND)
370         onenand_init();
371 #endif
372
373 #ifdef CONFIG_HAS_DATAFLASH
374         AT91F_DataflashInit();
375         dataflash_print_info();
376 #endif
377
378 #ifdef CONFIG_GENERIC_MMC
379         puts("MMC:   ");
380         mmc_initialize(gd->bd);
381 #endif
382
383         /* initialize environment */
384         env_relocate();
385
386 #ifdef CONFIG_VFD
387         /* must do this after the framebuffer is allocated */
388         drv_vfd_init();
389 #endif /* CONFIG_VFD */
390
391 #ifdef CONFIG_SERIAL_MULTI
392         serial_initialize();
393 #endif
394
395         /* IP Address */
396         gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
397
398         stdio_init();   /* get the devices list going. */
399
400         jumptable_init();
401
402 #if defined(CONFIG_API)
403         /* Initialize API */
404         api_init();
405 #endif
406
407         console_init_r();       /* fully init console as a device */
408
409 #if defined(CONFIG_ARCH_MISC_INIT)
410         /* miscellaneous arch dependent initialisations */
411         arch_misc_init();
412 #endif
413 #if defined(CONFIG_MISC_INIT_R)
414         /* miscellaneous platform dependent initialisations */
415         misc_init_r();
416 #endif
417
418         /* enable exceptions */
419         enable_interrupts();
420
421         /* Perform network card initialisation if necessary */
422 #ifdef CONFIG_DRIVER_TI_EMAC
423         /* XXX: this needs to be moved to board init */
424 extern void davinci_eth_set_mac_addr(const u_int8_t *addr);
425         if (getenv("ethaddr")) {
426                 uchar enetaddr[6];
427                 eth_getenv_enetaddr("ethaddr", enetaddr);
428                 davinci_eth_set_mac_addr(enetaddr);
429         }
430 #endif
431
432 #ifdef CONFIG_DRIVER_CS8900
433         /* XXX: this needs to be moved to board init */
434         cs8900_get_enetaddr();
435 #endif
436
437 #if defined(CONFIG_DRIVER_SMC91111) || defined(CONFIG_DRIVER_LAN91C96)
438         /* XXX: this needs to be moved to board init */
439         if (getenv("ethaddr")) {
440                 uchar enetaddr[6];
441                 eth_getenv_enetaddr("ethaddr", enetaddr);
442                 smc_set_mac_addr(enetaddr);
443         }
444 #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
445
446 #if defined(CONFIG_ENC28J60_ETH) && !defined(CONFIG_ETHADDR)
447         extern void enc_set_mac_addr(void);
448         enc_set_mac_addr();
449 #endif /* CONFIG_ENC28J60_ETH && !CONFIG_ETHADDR*/
450
451         /* Initialize from environment */
452         if ((s = getenv("loadaddr")) != NULL) {
453                 load_addr = simple_strtoul(s, NULL, 16);
454         }
455 #if defined(CONFIG_CMD_NET)
456         if ((s = getenv("bootfile")) != NULL) {
457                 copy_filename(BootFile, s, sizeof(BootFile));
458         }
459 #endif
460
461 #ifdef BOARD_LATE_INIT
462         board_late_init();
463 #endif
464
465 #if defined(CONFIG_CMD_NET)
466 #if defined(CONFIG_NET_MULTI)
467         puts("Net:   ");
468 #endif
469         eth_initialize(gd->bd);
470 #if defined(CONFIG_RESET_PHY_R)
471         debug("Reset Ethernet PHY\n");
472         reset_phy();
473 #endif
474 #endif
475         /* main_loop() can return to retry autoboot, if so just run it again. */
476         for (;;) {
477                 main_loop();
478         }
479
480         /* NOTREACHED - no way out of command loop except booting */
481 }
482
483 void hang(void)
484 {
485         puts("### ERROR ### Please RESET the board ###\n");
486         for (;;);
487 }