blob: 2baafa5df3e9147fdc6dc1bc6e5c29a99b505e39 [file] [log] [blame]
wdenk4e5ca3e2003-12-08 01:34:36 +00001/*
wdenkbf9e3b32004-02-12 00:47:09 +00002 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
4 *
5 * (C) Copyright 2000-2002
wdenk4e5ca3e2003-12-08 01:34:36 +00006 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <watchdog.h>
29#include <command.h>
30#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020031#include <stdio_dev.h>
Marek Vasutc59ac902012-10-03 13:28:46 +000032#include <linux/compiler.h>
wdenkbf9e3b32004-02-12 00:47:09 +000033
TsiChungLiew8ae158c2007-08-16 15:05:11 -050034#include <asm/immap.h>
wdenkbf9e3b32004-02-12 00:47:09 +000035
Jon Loeliger7def6b32007-07-09 18:02:11 -050036#if defined(CONFIG_CMD_IDE)
wdenk4e5ca3e2003-12-08 01:34:36 +000037#include <ide.h>
38#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -050039#if defined(CONFIG_CMD_SCSI)
wdenk4e5ca3e2003-12-08 01:34:36 +000040#include <scsi.h>
41#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -050042#if defined(CONFIG_CMD_KGDB)
wdenk4e5ca3e2003-12-08 01:34:36 +000043#include <kgdb.h>
44#endif
45#ifdef CONFIG_STATUS_LED
46#include <status_led.h>
47#endif
48#include <net.h>
Marcel Ziswilerb71190f2008-05-01 09:05:26 +020049#include <serial.h>
Jon Loeliger7def6b32007-07-09 18:02:11 -050050#if defined(CONFIG_CMD_BEDBUG)
wdenk4e5ca3e2003-12-08 01:34:36 +000051#include <cmd_bedbug.h>
52#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053#ifdef CONFIG_SYS_ALLOC_DPRAM
wdenk4e5ca3e2003-12-08 01:34:36 +000054#include <commproc.h>
55#endif
56#include <version.h>
57
stroesee2c22d72004-12-16 17:55:22 +000058#if defined(CONFIG_HARD_I2C) || \
Heiko Schocherea818db2013-01-29 08:53:15 +010059 defined(CONFIG_SYS_I2C)
stroesee2c22d72004-12-16 17:55:22 +000060#include <i2c.h>
61#endif
62
TsiChung Liewa7323bb2008-07-23 17:53:36 -050063#ifdef CONFIG_CMD_SPI
64#include <spi.h>
65#endif
66
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020067#ifdef CONFIG_BITBANGMII
68#include <miiphy.h>
69#endif
70
TsiChung Liewab6ba842008-08-13 12:07:03 +000071#include <nand.h>
72
Wolfgang Denkd87080b2006-03-31 18:32:53 +020073DECLARE_GLOBAL_DATA_PTR;
74
wdenk4e5ca3e2003-12-08 01:34:36 +000075static char *failed = "*** failed ***\n";
76
wdenkbf9e3b32004-02-12 00:47:09 +000077#include <environment.h>
78
wdenkbf9e3b32004-02-12 00:47:09 +000079extern ulong __init_end;
Simon Glass3929fb02013-03-14 06:54:53 +000080extern ulong __bss_end;
wdenkbf9e3b32004-02-12 00:47:09 +000081
wdenkbf9e3b32004-02-12 00:47:09 +000082#if defined(CONFIG_WATCHDOG)
Simon Glassa6741bc2013-03-05 14:39:42 +000083# undef INIT_FUNC_WATCHDOG_INIT
wdenkbf9e3b32004-02-12 00:47:09 +000084# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
85# define WATCHDOG_DISABLE watchdog_disable
86
87extern int watchdog_init(void);
88extern int watchdog_disable(void);
89#else
90# define INIT_FUNC_WATCHDOG_INIT /* undef */
91# define WATCHDOG_DISABLE /* undef */
92#endif /* CONFIG_WATCHDOG */
93
94ulong monitor_flash_len;
95
wdenk4e5ca3e2003-12-08 01:34:36 +000096/************************************************************************
97 * Utilities *
98 ************************************************************************
99 */
100
101/*
wdenkbf9e3b32004-02-12 00:47:09 +0000102 * All attempts to come up with a "common" initialization sequence
103 * that works for all boards and architectures failed: some of the
104 * requirements are just _too_ different. To get rid of the resulting
105 * mess of board dependend #ifdef'ed code we now make the whole
106 * initialization sequence configurable to the user.
107 *
108 * The requirements for any new initalization function is simple: it
109 * receives a pointer to the "global data" structure as it's only
110 * argument, and returns an integer return code, where 0 means
111 * "continue" and != 0 means "fatal error, hang the system".
112 */
113typedef int (init_fnc_t) (void);
114
115/************************************************************************
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500116 * Init Utilities
wdenkbf9e3b32004-02-12 00:47:09 +0000117 ************************************************************************
118 * Some of this code should be moved into the core functions,
119 * but let's get it working (again) first...
120 */
121
122static int init_baudrate (void)
wdenk4e5ca3e2003-12-08 01:34:36 +0000123{
Simon Glass77b8f202011-10-13 14:43:09 +0000124 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
125 return 0;
wdenk4e5ca3e2003-12-08 01:34:36 +0000126}
127
wdenkbf9e3b32004-02-12 00:47:09 +0000128/***********************************************************************/
129
130static int init_func_ram (void)
131{
wdenkbf9e3b32004-02-12 00:47:09 +0000132 int board_type = 0; /* use dummy arg */
133 puts ("DRAM: ");
134
135 if ((gd->ram_size = initdram (board_type)) > 0) {
136 print_size (gd->ram_size, "\n");
137 return (0);
138 }
139 puts (failed);
140 return (1);
141}
142
143/***********************************************************************/
144
Heiko Schocherea818db2013-01-29 08:53:15 +0100145#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
stroesee2c22d72004-12-16 17:55:22 +0000146static int init_func_i2c (void)
147{
148 puts ("I2C: ");
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000149#ifdef CONFIG_SYS_I2C
150 i2c_init_all();
151#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000153#endif
stroesee2c22d72004-12-16 17:55:22 +0000154 puts ("ready\n");
155 return (0);
156}
157#endif
158
TsiChung Liewa7323bb2008-07-23 17:53:36 -0500159#if defined(CONFIG_HARD_SPI)
160static int init_func_spi (void)
161{
162 puts ("SPI: ");
163 spi_init ();
164 puts ("ready\n");
165 return (0);
166}
167#endif
168
stroesee2c22d72004-12-16 17:55:22 +0000169/***********************************************************************/
170
wdenkbf9e3b32004-02-12 00:47:09 +0000171/************************************************************************
172 * Initialization sequence *
173 ************************************************************************
174 */
175
176init_fnc_t *init_sequence[] = {
Stefan Roesed61ea142007-08-15 14:51:27 +0200177 get_clocks,
wdenkbf9e3b32004-02-12 00:47:09 +0000178 env_init,
179 init_baudrate,
180 serial_init,
181 console_init_f,
182 display_options,
183 checkcpu,
184 checkboard,
Heiko Schocherea818db2013-01-29 08:53:15 +0100185#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
stroesee2c22d72004-12-16 17:55:22 +0000186 init_func_i2c,
187#endif
TsiChung Liewa7323bb2008-07-23 17:53:36 -0500188#if defined(CONFIG_HARD_SPI)
189 init_func_spi,
190#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000191 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192#if defined(CONFIG_SYS_DRAM_TEST)
wdenkbf9e3b32004-02-12 00:47:09 +0000193 testdram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200194#endif /* CONFIG_SYS_DRAM_TEST */
wdenkbf9e3b32004-02-12 00:47:09 +0000195 INIT_FUNC_WATCHDOG_INIT
196 NULL, /* Terminate this list */
197};
198
199
wdenk4e5ca3e2003-12-08 01:34:36 +0000200/************************************************************************
201 *
202 * This is the first part of the initialization sequence that is
203 * implemented in C, but still running from ROM.
204 *
205 * The main purpose is to provide a (serial) console interface as
206 * soon as possible (so we can see any error messages), and to
207 * initialize the RAM so that we can relocate the monitor code to
208 * RAM.
209 *
210 * Be aware of the restrictions: global data is read-only, BSS is not
211 * initialized, and stack space is limited to a few kB.
212 *
213 ************************************************************************
214 */
215
wdenkbf9e3b32004-02-12 00:47:09 +0000216void
217board_init_f (ulong bootflag)
wdenk4e5ca3e2003-12-08 01:34:36 +0000218{
wdenk4e5ca3e2003-12-08 01:34:36 +0000219 bd_t *bd;
wdenkbf9e3b32004-02-12 00:47:09 +0000220 ulong len, addr, addr_sp;
Marian Balakowicz483a0cf2006-05-09 11:28:36 +0200221 ulong *paddr;
wdenkbf9e3b32004-02-12 00:47:09 +0000222 gd_t *id;
223 init_fnc_t **init_fnc_ptr;
224#ifdef CONFIG_PRAM
wdenkbf9e3b32004-02-12 00:47:09 +0000225 ulong reg;
wdenkbf9e3b32004-02-12 00:47:09 +0000226#endif
wdenk4e5ca3e2003-12-08 01:34:36 +0000227
wdenkbf9e3b32004-02-12 00:47:09 +0000228 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200229 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk93f6a672004-07-01 20:28:03 +0000230 /* compiler optimization barrier needed for GCC >= 3.4 */
231 __asm__ __volatile__("": : :"memory");
wdenk4e5ca3e2003-12-08 01:34:36 +0000232
wdenkbf9e3b32004-02-12 00:47:09 +0000233 /* Clear initial global data */
234 memset ((void *) gd, 0, sizeof (gd_t));
wdenk4e5ca3e2003-12-08 01:34:36 +0000235
wdenkbf9e3b32004-02-12 00:47:09 +0000236 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
237 if ((*init_fnc_ptr)() != 0) {
238 hang ();
239 }
wdenk4e5ca3e2003-12-08 01:34:36 +0000240 }
wdenk4e5ca3e2003-12-08 01:34:36 +0000241
242 /*
243 * Now that we have DRAM mapped and working, we can
244 * relocate the code and continue running from DRAM.
245 *
246 * Reserve memory at end of RAM for (top down in that order):
wdenkbf9e3b32004-02-12 00:47:09 +0000247 * - protected RAM
248 * - LCD framebuffer
249 * - monitor code
250 * - board info struct
wdenk4e5ca3e2003-12-08 01:34:36 +0000251 */
Simon Glass3929fb02013-03-14 06:54:53 +0000252 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenk4e5ca3e2003-12-08 01:34:36 +0000253
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200254 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
wdenk4e5ca3e2003-12-08 01:34:36 +0000255
wdenkbf9e3b32004-02-12 00:47:09 +0000256#ifdef CONFIG_LOGBUFFER
257 /* reserve kernel log buffer */
258 addr -= (LOGBUFF_RESERVE);
259 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
260#endif
wdenk4e5ca3e2003-12-08 01:34:36 +0000261
wdenkbf9e3b32004-02-12 00:47:09 +0000262#ifdef CONFIG_PRAM
263 /*
264 * reserve protected RAM
265 */
Simon Glass77b8f202011-10-13 14:43:09 +0000266 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenkbf9e3b32004-02-12 00:47:09 +0000267 addr -= (reg << 10); /* size is in kB */
268 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
269#endif /* CONFIG_PRAM */
270
TsiChungLiew1552af72008-01-14 17:43:33 -0600271 /* round down to next 4 kB limit */
272 addr &= ~(4096 - 1);
273 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
274
275#ifdef CONFIG_LCD
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000276#ifdef CONFIG_FB_ADDR
277 gd->fb_base = CONFIG_FB_ADDR;
278#else
TsiChungLiew1552af72008-01-14 17:43:33 -0600279 /* reserve memory for LCD display (always full pages) */
280 addr = lcd_setmem (addr);
281 gd->fb_base = addr;
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000282#endif /* CONFIG_FB_ADDR */
TsiChungLiew1552af72008-01-14 17:43:33 -0600283#endif /* CONFIG_LCD */
284
wdenkbf9e3b32004-02-12 00:47:09 +0000285 /*
286 * reserve memory for U-Boot code, data & bss
287 * round down to next 4 kB limit
288 */
wdenk4e5ca3e2003-12-08 01:34:36 +0000289 addr -= len;
wdenkbf9e3b32004-02-12 00:47:09 +0000290 addr &= ~(4096 - 1);
291
292 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
293
294 /*
295 * reserve memory for malloc() arena
296 */
297 addr_sp = addr - TOTAL_MALLOC_LEN;
298 debug ("Reserving %dk for malloc() at: %08lx\n",
299 TOTAL_MALLOC_LEN >> 10, addr_sp);
300
301 /*
302 * (permanently) allocate a Board Info struct
303 * and a permanent copy of the "global" data
304 */
305 addr_sp -= sizeof (bd_t);
306 bd = (bd_t *) addr_sp;
307 gd->bd = bd;
Wolfgang Denkb64f1902008-07-14 15:06:35 +0200308 debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
wdenkbf9e3b32004-02-12 00:47:09 +0000309 sizeof (bd_t), addr_sp);
310 addr_sp -= sizeof (gd_t);
311 id = (gd_t *) addr_sp;
Wolfgang Denkb64f1902008-07-14 15:06:35 +0200312 debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
wdenkbf9e3b32004-02-12 00:47:09 +0000313 sizeof (gd_t), addr_sp);
314
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200315 /* Reserve memory for boot params. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200316 addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
wdenkbf9e3b32004-02-12 00:47:09 +0000317 bd->bi_boot_params = addr_sp;
318 debug ("Reserving %dk for boot parameters at: %08lx\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200319 CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
wdenkbf9e3b32004-02-12 00:47:09 +0000320
321 /*
322 * Finally, we set up a new (bigger) stack.
323 *
324 * Leave some safety gap for SP, force alignment on 16 byte boundary
325 * Clear initial stack frame
326 */
327 addr_sp -= 16;
328 addr_sp &= ~0xF;
Marian Balakowicz483a0cf2006-05-09 11:28:36 +0200329
330 paddr = (ulong *)addr_sp;
331 *paddr-- = 0;
332 *paddr-- = 0;
333 addr_sp = (ulong)paddr;
Wolfgang Denk977b50f2006-05-10 17:43:20 +0200334
wdenkbf9e3b32004-02-12 00:47:09 +0000335 debug ("Stack Pointer at: %08lx\n", addr_sp);
wdenk4e5ca3e2003-12-08 01:34:36 +0000336
337 /*
338 * Save local variables to board info struct
339 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200340 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM memory */
wdenkbf9e3b32004-02-12 00:47:09 +0000341 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200342#ifdef CONFIG_SYS_INIT_RAM_ADDR
343 bd->bi_sramstart = CONFIG_SYS_INIT_RAM_ADDR; /* start of SRAM memory */
Wolfgang Denk553f0982010-10-26 13:32:32 +0200344 bd->bi_sramsize = CONFIG_SYS_INIT_RAM_SIZE; /* size of SRAM memory */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500345#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200346 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenk4e5ca3e2003-12-08 01:34:36 +0000347
wdenkbf9e3b32004-02-12 00:47:09 +0000348 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
wdenk4e5ca3e2003-12-08 01:34:36 +0000349
wdenkbf9e3b32004-02-12 00:47:09 +0000350 WATCHDOG_RESET ();
351 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
352 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500353#ifdef CONFIG_PCI
354 bd->bi_pcifreq = gd->pci_clk; /* PCI Freq in Hz */
355#endif
356#ifdef CONFIG_EXTRA_CLOCK
Simon Glass7e2592f2012-12-13 20:49:07 +0000357 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
358 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
359 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500360#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000361 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
wdenk4e5ca3e2003-12-08 01:34:36 +0000362
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200363#ifdef CONFIG_SYS_EXTBDINFO
wdenk4e5ca3e2003-12-08 01:34:36 +0000364 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
wdenkbf9e3b32004-02-12 00:47:09 +0000365 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
wdenk4e5ca3e2003-12-08 01:34:36 +0000366#endif
367
wdenkbf9e3b32004-02-12 00:47:09 +0000368 WATCHDOG_RESET ();
wdenk4e5ca3e2003-12-08 01:34:36 +0000369
wdenkbf9e3b32004-02-12 00:47:09 +0000370#ifdef CONFIG_POST
371 post_bootmode_init();
372 post_run (NULL, POST_ROM | post_bootmode_get(0));
373#endif
374
375 WATCHDOG_RESET();
376
377 memcpy (id, (void *)gd, sizeof (gd_t));
378
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200379 debug ("Start relocate of code from %08x to %08lx\n", CONFIG_SYS_MONITOR_BASE, addr);
wdenkbf9e3b32004-02-12 00:47:09 +0000380 relocate_code (addr_sp, id, addr);
381
382 /* NOTREACHED - jump_to_ram() does not return */
wdenk4e5ca3e2003-12-08 01:34:36 +0000383}
384
wdenk4e5ca3e2003-12-08 01:34:36 +0000385/************************************************************************
386 *
387 * This is the next part if the initialization sequence: we are now
388 * running from RAM and have a "normal" C environment, i. e. global
389 * data can be written, BSS has been cleared, the stack size in not
390 * that critical any more, etc.
391 *
392 ************************************************************************
393 */
wdenkbf9e3b32004-02-12 00:47:09 +0000394void board_init_r (gd_t *id, ulong dest_addr)
wdenk4e5ca3e2003-12-08 01:34:36 +0000395{
Marek Vasutc59ac902012-10-03 13:28:46 +0000396 char *s __maybe_unused;
wdenk4e5ca3e2003-12-08 01:34:36 +0000397 bd_t *bd;
398
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +0200399#ifndef CONFIG_ENV_IS_NOWHERE
wdenkbf9e3b32004-02-12 00:47:09 +0000400 extern char * env_name_spec;
401#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200402#ifndef CONFIG_SYS_NO_FLASH
wdenkbf9e3b32004-02-12 00:47:09 +0000403 ulong flash_size;
404#endif
405 gd = id; /* initialize RAM version of global data */
wdenk4e5ca3e2003-12-08 01:34:36 +0000406 bd = gd->bd;
wdenkbf9e3b32004-02-12 00:47:09 +0000407
408 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
409
wdenkbf9e3b32004-02-12 00:47:09 +0000410 WATCHDOG_RESET ();
411
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200412 gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
wdenkbf9e3b32004-02-12 00:47:09 +0000413
angelofd70aa42012-11-23 12:23:39 +0000414 serial_initialize();
415
Jens Scharsig (BuS Elektronik)aea5eee2013-01-16 08:24:10 +0100416 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
417
wdenkbf9e3b32004-02-12 00:47:09 +0000418 monitor_flash_len = (ulong)&__init_end - dest_addr;
419
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200420#if defined(CONFIG_NEEDS_MANUAL_RELOC)
wdenkbf9e3b32004-02-12 00:47:09 +0000421 /*
422 * We have to relocate the command table manually
423 */
Marek Vasut6c7c9462012-10-12 10:27:04 +0000424 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
425 ll_entry_count(cmd_tbl_t, cmd));
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200426#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
wdenkbf9e3b32004-02-12 00:47:09 +0000427
wdenkbf9e3b32004-02-12 00:47:09 +0000428 /* there are some other pointer constants we must deal with */
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +0200429#ifndef CONFIG_ENV_IS_NOWHERE
wdenkbf9e3b32004-02-12 00:47:09 +0000430 env_name_spec += gd->reloc_off;
431#endif
432
433 WATCHDOG_RESET ();
434
435#ifdef CONFIG_LOGBUFFER
436 logbuff_init_ptrs ();
437#endif
438#ifdef CONFIG_POST
439 post_output_backlog ();
440 post_reloc ();
441#endif
442 WATCHDOG_RESET();
443
444#if 0
445 /* instruction cache enabled in cpu_init_f() for faster relocation */
446 icache_enable (); /* it's time to enable the instruction cache */
447#endif
wdenk4e5ca3e2003-12-08 01:34:36 +0000448
449 /*
450 * Setup trap handlers
451 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200452 trap_init (CONFIG_SYS_SDRAM_BASE);
wdenk4e5ca3e2003-12-08 01:34:36 +0000453
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500454 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysera483a162009-08-21 23:05:20 -0500455 mem_malloc_init (CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
456 TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
Stefan Roesec790b042009-05-11 15:50:12 +0200457
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200458#if !defined(CONFIG_SYS_NO_FLASH)
Peter Tysereddf52b2010-12-28 18:12:05 -0600459 puts ("Flash: ");
wdenk4e5ca3e2003-12-08 01:34:36 +0000460
461 if ((flash_size = flash_init ()) > 0) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200462# ifdef CONFIG_SYS_FLASH_CHECKSUM
wdenkbf9e3b32004-02-12 00:47:09 +0000463 print_size (flash_size, "");
wdenk4e5ca3e2003-12-08 01:34:36 +0000464 /*
465 * Compute and print flash CRC if flashchecksum is set to 'y'
466 *
wdenkbf9e3b32004-02-12 00:47:09 +0000467 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
wdenk4e5ca3e2003-12-08 01:34:36 +0000468 */
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600469 if (getenv_yesno("flashchecksum") == 1) {
TsiChung Liew11d88b22009-06-12 13:03:34 +0000470 printf (" CRC: %08X",
wdenkbf9e3b32004-02-12 00:47:09 +0000471 crc32 (0,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200472 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
wdenkbf9e3b32004-02-12 00:47:09 +0000473 flash_size)
474 );
wdenk4e5ca3e2003-12-08 01:34:36 +0000475 }
476 putc ('\n');
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200477# else /* !CONFIG_SYS_FLASH_CHECKSUM */
wdenkbf9e3b32004-02-12 00:47:09 +0000478 print_size (flash_size, "\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200479# endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenk4e5ca3e2003-12-08 01:34:36 +0000480 } else {
481 puts (failed);
482 hang ();
483 }
484
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200485 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
wdenkbf9e3b32004-02-12 00:47:09 +0000486 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
487 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200488#else /* CONFIG_SYS_NO_FLASH */
wdenkbf9e3b32004-02-12 00:47:09 +0000489 bd->bi_flashsize = 0;
490 bd->bi_flashstart = 0;
491 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200492#endif /* !CONFIG_SYS_NO_FLASH */
wdenk4e5ca3e2003-12-08 01:34:36 +0000493
494 WATCHDOG_RESET ();
495
496 /* initialize higher level parts of CPU like time base and timers */
497 cpu_init_r ();
498
499 WATCHDOG_RESET ();
500
wdenk4e5ca3e2003-12-08 01:34:36 +0000501#ifdef CONFIG_SPI
Jean-Christophe PLAGNIOL-VILLARDbb1f8b42008-09-05 09:19:30 +0200502# if !defined(CONFIG_ENV_IS_IN_EEPROM)
wdenk4e5ca3e2003-12-08 01:34:36 +0000503 spi_init_f ();
504# endif
505 spi_init_r ();
506#endif
507
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000508#if defined(CONFIG_SYS_I2C)
509 /* Adjust I2C subsystem pointers after relocation */
510 i2c_reloc_fixup();
511#endif
512
wdenk4e5ca3e2003-12-08 01:34:36 +0000513 /* relocate environment function pointers etc. */
514 env_relocate ();
515
wdenk4e5ca3e2003-12-08 01:34:36 +0000516 WATCHDOG_RESET ();
517
TsiChung Liew8e585f02007-06-18 13:50:13 -0500518#if defined(CONFIG_PCI)
519 /*
520 * Do pci configuration
521 */
522 pci_init ();
523#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000524
525 /** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200526 /* Initialize stdio devices */
527 stdio_init ();
wdenkbf9e3b32004-02-12 00:47:09 +0000528
529 /* Initialize the jump table for applications */
530 jumptable_init ();
wdenk4e5ca3e2003-12-08 01:34:36 +0000531
532 /* Initialize the console (after the relocation and devices init) */
wdenkbf9e3b32004-02-12 00:47:09 +0000533 console_init_r ();
wdenk4e5ca3e2003-12-08 01:34:36 +0000534
stroesee2c22d72004-12-16 17:55:22 +0000535#if defined(CONFIG_MISC_INIT_R)
536 /* miscellaneous platform dependent initialisations */
537 misc_init_r ();
538#endif
539
Jon Loeliger7def6b32007-07-09 18:02:11 -0500540#if defined(CONFIG_CMD_KGDB)
wdenk4e5ca3e2003-12-08 01:34:36 +0000541 WATCHDOG_RESET ();
542 puts ("KGDB: ");
543 kgdb_init ();
544#endif
545
wdenkbf9e3b32004-02-12 00:47:09 +0000546 debug ("U-Boot relocated to %08lx\n", dest_addr);
547
wdenk4e5ca3e2003-12-08 01:34:36 +0000548 /*
549 * Enable Interrupts
550 */
551 interrupt_init ();
wdenkbf9e3b32004-02-12 00:47:09 +0000552
553 /* Must happen after interrupts are initialized since
554 * an irq handler gets installed
555 */
556 timer_init();
557
wdenkbf9e3b32004-02-12 00:47:09 +0000558#ifdef CONFIG_STATUS_LED
559 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
560#endif
561
wdenk4e5ca3e2003-12-08 01:34:36 +0000562 udelay (20);
wdenkbf9e3b32004-02-12 00:47:09 +0000563
wdenk4e5ca3e2003-12-08 01:34:36 +0000564 /* Insert function pointers now that we have relocated the code */
565
566 /* Initialize from environment */
Simon Glass77b8f202011-10-13 14:43:09 +0000567 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenk4e5ca3e2003-12-08 01:34:36 +0000568
569 WATCHDOG_RESET ();
570
Jon Loeliger7def6b32007-07-09 18:02:11 -0500571#if defined(CONFIG_CMD_DOC)
wdenk4e5ca3e2003-12-08 01:34:36 +0000572 WATCHDOG_RESET ();
wdenkbf9e3b32004-02-12 00:47:09 +0000573 puts ("DOC: ");
574 doc_init ();
575#endif
576
Jon Loeliger7def6b32007-07-09 18:02:11 -0500577#if defined(CONFIG_CMD_NAND)
wdenkbf9e3b32004-02-12 00:47:09 +0000578 WATCHDOG_RESET ();
Markus Klotzbuecherd860c342006-04-25 17:00:33 +0200579 puts ("NAND: ");
wdenkbf9e3b32004-02-12 00:47:09 +0000580 nand_init(); /* go init the NAND */
581#endif
582
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200583#ifdef CONFIG_BITBANGMII
584 bb_miiphy_init();
585#endif
Stefan Roesed61ea142007-08-15 14:51:27 +0200586#if defined(CONFIG_CMD_NET)
wdenkbf9e3b32004-02-12 00:47:09 +0000587 WATCHDOG_RESET();
TsiChung Liew8e585f02007-06-18 13:50:13 -0500588#if defined(FEC_ENET)
wdenkbf9e3b32004-02-12 00:47:09 +0000589 eth_init(bd);
590#endif
TsiChung Liew8e585f02007-06-18 13:50:13 -0500591 puts ("Net: ");
TsiChungLiewab77bc52007-08-15 15:39:17 -0500592 eth_initialize (bd);
TsiChung Liew8e585f02007-06-18 13:50:13 -0500593#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000594
595#ifdef CONFIG_POST
596 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenk4e5ca3e2003-12-08 01:34:36 +0000597#endif
598
Stefan Roesed61ea142007-08-15 14:51:27 +0200599#if defined(CONFIG_CMD_PCMCIA) \
600 && !defined(CONFIG_CMD_IDE)
TsiChung Liew8e585f02007-06-18 13:50:13 -0500601 WATCHDOG_RESET ();
602 puts ("PCMCIA:");
603 pcmcia_init ();
604#endif
605
Stefan Roesed61ea142007-08-15 14:51:27 +0200606#if defined(CONFIG_CMD_IDE)
TsiChung Liew8e585f02007-06-18 13:50:13 -0500607 WATCHDOG_RESET ();
608 puts ("IDE: ");
609 ide_init ();
Stefan Roesed61ea142007-08-15 14:51:27 +0200610#endif
TsiChung Liew8e585f02007-06-18 13:50:13 -0500611
wdenk4e5ca3e2003-12-08 01:34:36 +0000612#ifdef CONFIG_LAST_STAGE_INIT
613 WATCHDOG_RESET ();
614 /*
615 * Some parts can be only initialized if all others (like
616 * Interrupts) are up and running (i.e. the PC-style ISA
617 * keyboard).
618 */
619 last_stage_init ();
620#endif
621
Jon Loeliger7def6b32007-07-09 18:02:11 -0500622#if defined(CONFIG_CMD_BEDBUG)
wdenk4e5ca3e2003-12-08 01:34:36 +0000623 WATCHDOG_RESET ();
624 bedbug_init ();
625#endif
626
wdenkbf9e3b32004-02-12 00:47:09 +0000627#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenk4e5ca3e2003-12-08 01:34:36 +0000628 /*
629 * Export available size of memory for Linux,
630 * taking into account the protected RAM at top of memory
631 */
632 {
Simon Glass77b8f202011-10-13 14:43:09 +0000633 ulong pram = 0;
Simon Glassa5466652012-01-05 17:54:56 +0000634 char memsz[32];
wdenk4e5ca3e2003-12-08 01:34:36 +0000635
Simon Glass77b8f202011-10-13 14:43:09 +0000636#ifdef CONFIG_PRAM
637 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenkbf9e3b32004-02-12 00:47:09 +0000638#endif
639#ifdef CONFIG_LOGBUFFER
640 /* Also take the logbuffer into account (pram is in kB) */
641 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
642#endif
wdenk4e5ca3e2003-12-08 01:34:36 +0000643 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
644 setenv ("mem", memsz);
645 }
646#endif
647
wdenkbf9e3b32004-02-12 00:47:09 +0000648#ifdef CONFIG_MODEM_SUPPORT
649 {
650 extern int do_mdm_init;
651 do_mdm_init = gd->do_mdm_init;
652 }
653#endif
654
655#ifdef CONFIG_WATCHDOG
656 /* disable watchdog if environment is set */
657 if ((s = getenv ("watchdog")) != NULL) {
658 if (strncmp (s, "off", 3) == 0) {
659 WATCHDOG_DISABLE ();
660 }
661 }
662#endif /* CONFIG_WATCHDOG*/
663
664
wdenk4e5ca3e2003-12-08 01:34:36 +0000665 /* Initialization complete - start the monitor */
666
667 /* main_loop() can return to retry autoboot, if so just run it again. */
668 for (;;) {
669 WATCHDOG_RESET ();
670 main_loop ();
671 }
672
673 /* NOTREACHED - no way out of command loop except booting */
674}