blob: 020dc2456ea6ad328445886f037d66cb89f5adcd [file] [log] [blame]
wdenkabf7a7c2003-12-08 01:34:36 +00001/*
wdenke65527f2004-02-12 00:47:09 +00002 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
4 *
5 * (C) Copyright 2000-2002
wdenkabf7a7c2003-12-08 01:34:36 +00006 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00009 */
10
11#include <common.h>
12#include <watchdog.h>
13#include <command.h>
14#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020015#include <stdio_dev.h>
Marek Vasut136c04a2012-10-03 13:28:46 +000016#include <linux/compiler.h>
wdenke65527f2004-02-12 00:47:09 +000017
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050018#include <asm/immap.h>
wdenke65527f2004-02-12 00:47:09 +000019
Jon Loeliger6b233052007-07-09 18:02:11 -050020#if defined(CONFIG_CMD_IDE)
wdenkabf7a7c2003-12-08 01:34:36 +000021#include <ide.h>
22#endif
Jon Loeliger6b233052007-07-09 18:02:11 -050023#if defined(CONFIG_CMD_SCSI)
wdenkabf7a7c2003-12-08 01:34:36 +000024#include <scsi.h>
25#endif
Jon Loeliger6b233052007-07-09 18:02:11 -050026#if defined(CONFIG_CMD_KGDB)
wdenkabf7a7c2003-12-08 01:34:36 +000027#include <kgdb.h>
28#endif
29#ifdef CONFIG_STATUS_LED
30#include <status_led.h>
31#endif
32#include <net.h>
Marcel Ziswilerb5a75412008-05-01 09:05:26 +020033#include <serial.h>
Jon Loeliger6b233052007-07-09 18:02:11 -050034#if defined(CONFIG_CMD_BEDBUG)
wdenkabf7a7c2003-12-08 01:34:36 +000035#include <cmd_bedbug.h>
36#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037#ifdef CONFIG_SYS_ALLOC_DPRAM
wdenkabf7a7c2003-12-08 01:34:36 +000038#include <commproc.h>
39#endif
40#include <version.h>
41
stroesecd2128e2004-12-16 17:55:22 +000042#if defined(CONFIG_HARD_I2C) || \
43 defined(CONFIG_SOFT_I2C)
44#include <i2c.h>
45#endif
46
TsiChung Liew663c9522008-07-23 17:53:36 -050047#ifdef CONFIG_CMD_SPI
48#include <spi.h>
49#endif
50
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +020051#ifdef CONFIG_BITBANGMII
52#include <miiphy.h>
53#endif
54
TsiChung Liew2a90e892008-08-13 12:07:03 +000055#include <nand.h>
56
Wolfgang Denk6405a152006-03-31 18:32:53 +020057DECLARE_GLOBAL_DATA_PTR;
58
wdenkabf7a7c2003-12-08 01:34:36 +000059static char *failed = "*** failed ***\n";
60
wdenke65527f2004-02-12 00:47:09 +000061#include <environment.h>
62
wdenke65527f2004-02-12 00:47:09 +000063extern ulong __init_end;
Simon Glassed70c8f2013-03-14 06:54:53 +000064extern ulong __bss_end;
wdenke65527f2004-02-12 00:47:09 +000065
wdenke65527f2004-02-12 00:47:09 +000066#if defined(CONFIG_WATCHDOG)
Simon Glass6f984902013-03-05 14:39:42 +000067# undef INIT_FUNC_WATCHDOG_INIT
wdenke65527f2004-02-12 00:47:09 +000068# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
69# define WATCHDOG_DISABLE watchdog_disable
70
71extern int watchdog_init(void);
72extern int watchdog_disable(void);
73#else
74# define INIT_FUNC_WATCHDOG_INIT /* undef */
75# define WATCHDOG_DISABLE /* undef */
76#endif /* CONFIG_WATCHDOG */
77
78ulong monitor_flash_len;
79
wdenkabf7a7c2003-12-08 01:34:36 +000080/************************************************************************
81 * Utilities *
82 ************************************************************************
83 */
84
85/*
wdenke65527f2004-02-12 00:47:09 +000086 * All attempts to come up with a "common" initialization sequence
87 * that works for all boards and architectures failed: some of the
88 * requirements are just _too_ different. To get rid of the resulting
89 * mess of board dependend #ifdef'ed code we now make the whole
90 * initialization sequence configurable to the user.
91 *
92 * The requirements for any new initalization function is simple: it
93 * receives a pointer to the "global data" structure as it's only
94 * argument, and returns an integer return code, where 0 means
95 * "continue" and != 0 means "fatal error, hang the system".
96 */
97typedef int (init_fnc_t) (void);
98
99/************************************************************************
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500100 * Init Utilities
wdenke65527f2004-02-12 00:47:09 +0000101 ************************************************************************
102 * Some of this code should be moved into the core functions,
103 * but let's get it working (again) first...
104 */
105
106static int init_baudrate (void)
wdenkabf7a7c2003-12-08 01:34:36 +0000107{
Simon Glass9e5689f2011-10-13 14:43:09 +0000108 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
109 return 0;
wdenke65527f2004-02-12 00:47:09 +0000110}
wdenkabf7a7c2003-12-08 01:34:36 +0000111
wdenke65527f2004-02-12 00:47:09 +0000112/***********************************************************************/
wdenkabf7a7c2003-12-08 01:34:36 +0000113
wdenke65527f2004-02-12 00:47:09 +0000114static int init_func_ram (void)
115{
wdenke65527f2004-02-12 00:47:09 +0000116 int board_type = 0; /* use dummy arg */
117 puts ("DRAM: ");
wdenkabf7a7c2003-12-08 01:34:36 +0000118
wdenke65527f2004-02-12 00:47:09 +0000119 if ((gd->ram_size = initdram (board_type)) > 0) {
120 print_size (gd->ram_size, "\n");
121 return (0);
122 }
123 puts (failed);
124 return (1);
wdenkabf7a7c2003-12-08 01:34:36 +0000125}
stroesecd2128e2004-12-16 17:55:22 +0000126
127/***********************************************************************/
128
129#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
130static int init_func_i2c (void)
131{
132 puts ("I2C: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
stroesecd2128e2004-12-16 17:55:22 +0000134 puts ("ready\n");
135 return (0);
136}
137#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000138
TsiChung Liew663c9522008-07-23 17:53:36 -0500139#if defined(CONFIG_HARD_SPI)
140static int init_func_spi (void)
141{
142 puts ("SPI: ");
143 spi_init ();
144 puts ("ready\n");
145 return (0);
146}
147#endif
148
wdenke65527f2004-02-12 00:47:09 +0000149/***********************************************************************/
150
151/************************************************************************
152 * Initialization sequence *
153 ************************************************************************
154 */
155
156init_fnc_t *init_sequence[] = {
Stefan Roesea06fd372007-08-15 14:51:27 +0200157 get_clocks,
wdenke65527f2004-02-12 00:47:09 +0000158 env_init,
159 init_baudrate,
160 serial_init,
161 console_init_f,
162 display_options,
163 checkcpu,
164 checkboard,
stroesecd2128e2004-12-16 17:55:22 +0000165#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
166 init_func_i2c,
167#endif
TsiChung Liew663c9522008-07-23 17:53:36 -0500168#if defined(CONFIG_HARD_SPI)
169 init_func_spi,
170#endif
wdenke65527f2004-02-12 00:47:09 +0000171 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172#if defined(CONFIG_SYS_DRAM_TEST)
wdenke65527f2004-02-12 00:47:09 +0000173 testdram,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174#endif /* CONFIG_SYS_DRAM_TEST */
wdenke65527f2004-02-12 00:47:09 +0000175 INIT_FUNC_WATCHDOG_INIT
176 NULL, /* Terminate this list */
177};
178
179
wdenkabf7a7c2003-12-08 01:34:36 +0000180/************************************************************************
181 *
182 * This is the first part of the initialization sequence that is
183 * implemented in C, but still running from ROM.
184 *
185 * The main purpose is to provide a (serial) console interface as
186 * soon as possible (so we can see any error messages), and to
187 * initialize the RAM so that we can relocate the monitor code to
188 * RAM.
189 *
190 * Be aware of the restrictions: global data is read-only, BSS is not
191 * initialized, and stack space is limited to a few kB.
192 *
193 ************************************************************************
194 */
195
wdenke65527f2004-02-12 00:47:09 +0000196void
197board_init_f (ulong bootflag)
wdenkabf7a7c2003-12-08 01:34:36 +0000198{
wdenkabf7a7c2003-12-08 01:34:36 +0000199 bd_t *bd;
wdenke65527f2004-02-12 00:47:09 +0000200 ulong len, addr, addr_sp;
Marian Balakowicz3e8b1dc2006-05-09 11:28:36 +0200201 ulong *paddr;
wdenke65527f2004-02-12 00:47:09 +0000202 gd_t *id;
203 init_fnc_t **init_fnc_ptr;
204#ifdef CONFIG_PRAM
wdenke65527f2004-02-12 00:47:09 +0000205 ulong reg;
wdenke65527f2004-02-12 00:47:09 +0000206#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000207
wdenke65527f2004-02-12 00:47:09 +0000208 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200209 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk3337af42004-07-01 20:28:03 +0000210 /* compiler optimization barrier needed for GCC >= 3.4 */
211 __asm__ __volatile__("": : :"memory");
wdenkabf7a7c2003-12-08 01:34:36 +0000212
wdenke65527f2004-02-12 00:47:09 +0000213 /* Clear initial global data */
214 memset ((void *) gd, 0, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000215
wdenke65527f2004-02-12 00:47:09 +0000216 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
217 if ((*init_fnc_ptr)() != 0) {
218 hang ();
219 }
wdenkabf7a7c2003-12-08 01:34:36 +0000220 }
wdenkabf7a7c2003-12-08 01:34:36 +0000221
222 /*
223 * Now that we have DRAM mapped and working, we can
224 * relocate the code and continue running from DRAM.
225 *
226 * Reserve memory at end of RAM for (top down in that order):
wdenke65527f2004-02-12 00:47:09 +0000227 * - protected RAM
228 * - LCD framebuffer
229 * - monitor code
230 * - board info struct
wdenkabf7a7c2003-12-08 01:34:36 +0000231 */
Simon Glassed70c8f2013-03-14 06:54:53 +0000232 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkabf7a7c2003-12-08 01:34:36 +0000233
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200234 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
wdenkabf7a7c2003-12-08 01:34:36 +0000235
wdenke65527f2004-02-12 00:47:09 +0000236#ifdef CONFIG_LOGBUFFER
237 /* reserve kernel log buffer */
238 addr -= (LOGBUFF_RESERVE);
239 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
240#endif
241
242#ifdef CONFIG_PRAM
243 /*
244 * reserve protected RAM
245 */
Simon Glass9e5689f2011-10-13 14:43:09 +0000246 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenke65527f2004-02-12 00:47:09 +0000247 addr -= (reg << 10); /* size is in kB */
248 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
249#endif /* CONFIG_PRAM */
wdenkabf7a7c2003-12-08 01:34:36 +0000250
TsiChungLiew99b037a2008-01-14 17:43:33 -0600251 /* round down to next 4 kB limit */
252 addr &= ~(4096 - 1);
253 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
254
255#ifdef CONFIG_LCD
Minkyu Kang50777c42011-04-24 22:22:34 +0000256#ifdef CONFIG_FB_ADDR
257 gd->fb_base = CONFIG_FB_ADDR;
258#else
TsiChungLiew99b037a2008-01-14 17:43:33 -0600259 /* reserve memory for LCD display (always full pages) */
260 addr = lcd_setmem (addr);
261 gd->fb_base = addr;
Minkyu Kang50777c42011-04-24 22:22:34 +0000262#endif /* CONFIG_FB_ADDR */
TsiChungLiew99b037a2008-01-14 17:43:33 -0600263#endif /* CONFIG_LCD */
264
wdenke65527f2004-02-12 00:47:09 +0000265 /*
266 * reserve memory for U-Boot code, data & bss
267 * round down to next 4 kB limit
268 */
wdenkabf7a7c2003-12-08 01:34:36 +0000269 addr -= len;
wdenke65527f2004-02-12 00:47:09 +0000270 addr &= ~(4096 - 1);
271
272 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkabf7a7c2003-12-08 01:34:36 +0000273
274 /*
wdenke65527f2004-02-12 00:47:09 +0000275 * reserve memory for malloc() arena
wdenkabf7a7c2003-12-08 01:34:36 +0000276 */
wdenke65527f2004-02-12 00:47:09 +0000277 addr_sp = addr - TOTAL_MALLOC_LEN;
278 debug ("Reserving %dk for malloc() at: %08lx\n",
279 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000280
wdenke65527f2004-02-12 00:47:09 +0000281 /*
282 * (permanently) allocate a Board Info struct
283 * and a permanent copy of the "global" data
284 */
285 addr_sp -= sizeof (bd_t);
286 bd = (bd_t *) addr_sp;
287 gd->bd = bd;
Wolfgang Denk509cd072008-07-14 15:06:35 +0200288 debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
wdenke65527f2004-02-12 00:47:09 +0000289 sizeof (bd_t), addr_sp);
290 addr_sp -= sizeof (gd_t);
291 id = (gd_t *) addr_sp;
Wolfgang Denk509cd072008-07-14 15:06:35 +0200292 debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
wdenke65527f2004-02-12 00:47:09 +0000293 sizeof (gd_t), addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000294
Wolfgang Denka1be4762008-05-20 16:00:29 +0200295 /* Reserve memory for boot params. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200296 addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
wdenke65527f2004-02-12 00:47:09 +0000297 bd->bi_boot_params = addr_sp;
298 debug ("Reserving %dk for boot parameters at: %08lx\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200299 CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
wdenke65527f2004-02-12 00:47:09 +0000300
301 /*
302 * Finally, we set up a new (bigger) stack.
303 *
304 * Leave some safety gap for SP, force alignment on 16 byte boundary
305 * Clear initial stack frame
306 */
307 addr_sp -= 16;
308 addr_sp &= ~0xF;
Marian Balakowicz3e8b1dc2006-05-09 11:28:36 +0200309
310 paddr = (ulong *)addr_sp;
311 *paddr-- = 0;
312 *paddr-- = 0;
313 addr_sp = (ulong)paddr;
Wolfgang Denkc2c49442006-05-10 17:43:20 +0200314
wdenke65527f2004-02-12 00:47:09 +0000315 debug ("Stack Pointer at: %08lx\n", addr_sp);
316
317 /*
318 * Save local variables to board info struct
319 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200320 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM memory */
wdenke65527f2004-02-12 00:47:09 +0000321 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200322#ifdef CONFIG_SYS_INIT_RAM_ADDR
323 bd->bi_sramstart = CONFIG_SYS_INIT_RAM_ADDR; /* start of SRAM memory */
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200324 bd->bi_sramsize = CONFIG_SYS_INIT_RAM_SIZE; /* size of SRAM memory */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500325#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200326 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenke65527f2004-02-12 00:47:09 +0000327
328 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
wdenkabf7a7c2003-12-08 01:34:36 +0000329
wdenke65527f2004-02-12 00:47:09 +0000330 WATCHDOG_RESET ();
331 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
332 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500333#ifdef CONFIG_PCI
334 bd->bi_pcifreq = gd->pci_clk; /* PCI Freq in Hz */
335#endif
336#ifdef CONFIG_EXTRA_CLOCK
Simon Glass568a7b62012-12-13 20:49:07 +0000337 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
338 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
339 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500340#endif
wdenke65527f2004-02-12 00:47:09 +0000341 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
wdenkabf7a7c2003-12-08 01:34:36 +0000342
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200343#ifdef CONFIG_SYS_EXTBDINFO
wdenkabf7a7c2003-12-08 01:34:36 +0000344 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
wdenke65527f2004-02-12 00:47:09 +0000345 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
346#endif
347
348 WATCHDOG_RESET ();
wdenkabf7a7c2003-12-08 01:34:36 +0000349
wdenke65527f2004-02-12 00:47:09 +0000350#ifdef CONFIG_POST
351 post_bootmode_init();
352 post_run (NULL, POST_ROM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000353#endif
354
wdenke65527f2004-02-12 00:47:09 +0000355 WATCHDOG_RESET();
wdenkabf7a7c2003-12-08 01:34:36 +0000356
wdenke65527f2004-02-12 00:47:09 +0000357 memcpy (id, (void *)gd, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000358
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200359 debug ("Start relocate of code from %08x to %08lx\n", CONFIG_SYS_MONITOR_BASE, addr);
wdenke65527f2004-02-12 00:47:09 +0000360 relocate_code (addr_sp, id, addr);
361
362 /* NOTREACHED - jump_to_ram() does not return */
363}
wdenkabf7a7c2003-12-08 01:34:36 +0000364
365/************************************************************************
366 *
367 * This is the next part if the initialization sequence: we are now
368 * running from RAM and have a "normal" C environment, i. e. global
369 * data can be written, BSS has been cleared, the stack size in not
370 * that critical any more, etc.
371 *
372 ************************************************************************
373 */
wdenke65527f2004-02-12 00:47:09 +0000374void board_init_r (gd_t *id, ulong dest_addr)
wdenkabf7a7c2003-12-08 01:34:36 +0000375{
Marek Vasut136c04a2012-10-03 13:28:46 +0000376 char *s __maybe_unused;
wdenkabf7a7c2003-12-08 01:34:36 +0000377 bd_t *bd;
378
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200379#ifndef CONFIG_ENV_IS_NOWHERE
wdenke65527f2004-02-12 00:47:09 +0000380 extern char * env_name_spec;
381#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200382#ifndef CONFIG_SYS_NO_FLASH
wdenke65527f2004-02-12 00:47:09 +0000383 ulong flash_size;
384#endif
385 gd = id; /* initialize RAM version of global data */
wdenkabf7a7c2003-12-08 01:34:36 +0000386 bd = gd->bd;
wdenke65527f2004-02-12 00:47:09 +0000387
388 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
389
wdenke65527f2004-02-12 00:47:09 +0000390 WATCHDOG_RESET ();
391
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200392 gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
wdenke65527f2004-02-12 00:47:09 +0000393
angelo46c1ca12012-11-23 12:23:39 +0000394 serial_initialize();
395
Jens Scharsig (BuS Elektronik)537f1862013-01-16 08:24:10 +0100396 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
397
wdenke65527f2004-02-12 00:47:09 +0000398 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkabf7a7c2003-12-08 01:34:36 +0000399
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200400#if defined(CONFIG_NEEDS_MANUAL_RELOC)
wdenkabf7a7c2003-12-08 01:34:36 +0000401 /*
wdenke65527f2004-02-12 00:47:09 +0000402 * We have to relocate the command table manually
403 */
Marek Vasut69c5e342012-10-12 10:27:04 +0000404 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
405 ll_entry_count(cmd_tbl_t, cmd));
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200406#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
wdenke65527f2004-02-12 00:47:09 +0000407
wdenke65527f2004-02-12 00:47:09 +0000408 /* there are some other pointer constants we must deal with */
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200409#ifndef CONFIG_ENV_IS_NOWHERE
wdenke65527f2004-02-12 00:47:09 +0000410 env_name_spec += gd->reloc_off;
411#endif
412
413 WATCHDOG_RESET ();
414
415#ifdef CONFIG_LOGBUFFER
416 logbuff_init_ptrs ();
417#endif
418#ifdef CONFIG_POST
419 post_output_backlog ();
420 post_reloc ();
421#endif
422 WATCHDOG_RESET();
423
424#if 0
425 /* instruction cache enabled in cpu_init_f() for faster relocation */
426 icache_enable (); /* it's time to enable the instruction cache */
427#endif
428
429 /*
wdenkabf7a7c2003-12-08 01:34:36 +0000430 * Setup trap handlers
431 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200432 trap_init (CONFIG_SYS_SDRAM_BASE);
wdenkabf7a7c2003-12-08 01:34:36 +0000433
Peter Tyser781c9b82009-08-21 23:05:21 -0500434 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysered527702009-08-21 23:05:20 -0500435 mem_malloc_init (CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
436 TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
Stefan Roeseb81464e2009-05-11 15:50:12 +0200437
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200438#if !defined(CONFIG_SYS_NO_FLASH)
Peter Tyser0b5a2632010-12-28 18:12:05 -0600439 puts ("Flash: ");
wdenkabf7a7c2003-12-08 01:34:36 +0000440
441 if ((flash_size = flash_init ()) > 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200442# ifdef CONFIG_SYS_FLASH_CHECKSUM
wdenke65527f2004-02-12 00:47:09 +0000443 print_size (flash_size, "");
wdenkabf7a7c2003-12-08 01:34:36 +0000444 /*
445 * Compute and print flash CRC if flashchecksum is set to 'y'
446 *
wdenke65527f2004-02-12 00:47:09 +0000447 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
wdenkabf7a7c2003-12-08 01:34:36 +0000448 */
Joe Hershberger864ec562012-12-11 22:16:22 -0600449 if (getenv_yesno("flashchecksum") == 1) {
TsiChung Liew063097d2009-06-12 13:03:34 +0000450 printf (" CRC: %08X",
wdenke65527f2004-02-12 00:47:09 +0000451 crc32 (0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200452 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
wdenke65527f2004-02-12 00:47:09 +0000453 flash_size)
454 );
wdenkabf7a7c2003-12-08 01:34:36 +0000455 }
456 putc ('\n');
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200457# else /* !CONFIG_SYS_FLASH_CHECKSUM */
wdenke65527f2004-02-12 00:47:09 +0000458 print_size (flash_size, "\n");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200459# endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenkabf7a7c2003-12-08 01:34:36 +0000460 } else {
461 puts (failed);
462 hang ();
463 }
464
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200465 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
wdenke65527f2004-02-12 00:47:09 +0000466 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
467 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200468#else /* CONFIG_SYS_NO_FLASH */
wdenke65527f2004-02-12 00:47:09 +0000469 bd->bi_flashsize = 0;
470 bd->bi_flashstart = 0;
471 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200472#endif /* !CONFIG_SYS_NO_FLASH */
wdenkabf7a7c2003-12-08 01:34:36 +0000473
474 WATCHDOG_RESET ();
475
476 /* initialize higher level parts of CPU like time base and timers */
477 cpu_init_r ();
478
479 WATCHDOG_RESET ();
480
wdenkabf7a7c2003-12-08 01:34:36 +0000481#ifdef CONFIG_SPI
Jean-Christophe PLAGNIOL-VILLARDe46af642008-09-05 09:19:30 +0200482# if !defined(CONFIG_ENV_IS_IN_EEPROM)
wdenkabf7a7c2003-12-08 01:34:36 +0000483 spi_init_f ();
484# endif
485 spi_init_r ();
486#endif
487
488 /* relocate environment function pointers etc. */
489 env_relocate ();
490
wdenkabf7a7c2003-12-08 01:34:36 +0000491 WATCHDOG_RESET ();
492
TsiChung Liewf6afe722007-06-18 13:50:13 -0500493#if defined(CONFIG_PCI)
494 /*
495 * Do pci configuration
496 */
497 pci_init ();
498#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000499
wdenke65527f2004-02-12 00:47:09 +0000500 /** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200501 /* Initialize stdio devices */
502 stdio_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000503
wdenke65527f2004-02-12 00:47:09 +0000504 /* Initialize the jump table for applications */
505 jumptable_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000506
wdenke65527f2004-02-12 00:47:09 +0000507 /* Initialize the console (after the relocation and devices init) */
508 console_init_r ();
wdenkabf7a7c2003-12-08 01:34:36 +0000509
stroesecd2128e2004-12-16 17:55:22 +0000510#if defined(CONFIG_MISC_INIT_R)
511 /* miscellaneous platform dependent initialisations */
512 misc_init_r ();
513#endif
514
Jon Loeliger6b233052007-07-09 18:02:11 -0500515#if defined(CONFIG_CMD_KGDB)
wdenkabf7a7c2003-12-08 01:34:36 +0000516 WATCHDOG_RESET ();
517 puts ("KGDB: ");
518 kgdb_init ();
519#endif
520
wdenke65527f2004-02-12 00:47:09 +0000521 debug ("U-Boot relocated to %08lx\n", dest_addr);
522
wdenkabf7a7c2003-12-08 01:34:36 +0000523 /*
524 * Enable Interrupts
525 */
526 interrupt_init ();
wdenke65527f2004-02-12 00:47:09 +0000527
528 /* Must happen after interrupts are initialized since
529 * an irq handler gets installed
530 */
531 timer_init();
532
wdenke65527f2004-02-12 00:47:09 +0000533#ifdef CONFIG_STATUS_LED
534 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
535#endif
536
wdenkabf7a7c2003-12-08 01:34:36 +0000537 udelay (20);
wdenke65527f2004-02-12 00:47:09 +0000538
wdenkabf7a7c2003-12-08 01:34:36 +0000539 /* Insert function pointers now that we have relocated the code */
540
541 /* Initialize from environment */
Simon Glass9e5689f2011-10-13 14:43:09 +0000542 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkabf7a7c2003-12-08 01:34:36 +0000543
wdenke65527f2004-02-12 00:47:09 +0000544 WATCHDOG_RESET ();
545
Jon Loeliger6b233052007-07-09 18:02:11 -0500546#if defined(CONFIG_CMD_DOC)
wdenkabf7a7c2003-12-08 01:34:36 +0000547 WATCHDOG_RESET ();
wdenke65527f2004-02-12 00:47:09 +0000548 puts ("DOC: ");
549 doc_init ();
550#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000551
Jon Loeliger6b233052007-07-09 18:02:11 -0500552#if defined(CONFIG_CMD_NAND)
wdenkabf7a7c2003-12-08 01:34:36 +0000553 WATCHDOG_RESET ();
Markus Klotzbuecherb6437322006-04-25 17:00:33 +0200554 puts ("NAND: ");
wdenke65527f2004-02-12 00:47:09 +0000555 nand_init(); /* go init the NAND */
556#endif
557
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +0200558#ifdef CONFIG_BITBANGMII
559 bb_miiphy_init();
560#endif
Stefan Roesea06fd372007-08-15 14:51:27 +0200561#if defined(CONFIG_CMD_NET)
wdenke65527f2004-02-12 00:47:09 +0000562 WATCHDOG_RESET();
TsiChung Liewf6afe722007-06-18 13:50:13 -0500563#if defined(FEC_ENET)
wdenke65527f2004-02-12 00:47:09 +0000564 eth_init(bd);
565#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500566 puts ("Net: ");
TsiChungLiewaedd3d72007-08-15 15:39:17 -0500567 eth_initialize (bd);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500568#endif
wdenke65527f2004-02-12 00:47:09 +0000569
570#ifdef CONFIG_POST
571 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000572#endif
573
Stefan Roesea06fd372007-08-15 14:51:27 +0200574#if defined(CONFIG_CMD_PCMCIA) \
575 && !defined(CONFIG_CMD_IDE)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500576 WATCHDOG_RESET ();
577 puts ("PCMCIA:");
578 pcmcia_init ();
579#endif
580
Stefan Roesea06fd372007-08-15 14:51:27 +0200581#if defined(CONFIG_CMD_IDE)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500582 WATCHDOG_RESET ();
583 puts ("IDE: ");
584 ide_init ();
Stefan Roesea06fd372007-08-15 14:51:27 +0200585#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500586
wdenkabf7a7c2003-12-08 01:34:36 +0000587#ifdef CONFIG_LAST_STAGE_INIT
588 WATCHDOG_RESET ();
589 /*
590 * Some parts can be only initialized if all others (like
591 * Interrupts) are up and running (i.e. the PC-style ISA
592 * keyboard).
593 */
594 last_stage_init ();
595#endif
596
Jon Loeliger6b233052007-07-09 18:02:11 -0500597#if defined(CONFIG_CMD_BEDBUG)
wdenkabf7a7c2003-12-08 01:34:36 +0000598 WATCHDOG_RESET ();
599 bedbug_init ();
600#endif
601
wdenke65527f2004-02-12 00:47:09 +0000602#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkabf7a7c2003-12-08 01:34:36 +0000603 /*
604 * Export available size of memory for Linux,
605 * taking into account the protected RAM at top of memory
606 */
607 {
Simon Glass9e5689f2011-10-13 14:43:09 +0000608 ulong pram = 0;
Simon Glass0fb06222012-01-05 17:54:56 +0000609 char memsz[32];
wdenkabf7a7c2003-12-08 01:34:36 +0000610
Simon Glass9e5689f2011-10-13 14:43:09 +0000611#ifdef CONFIG_PRAM
612 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenke65527f2004-02-12 00:47:09 +0000613#endif
614#ifdef CONFIG_LOGBUFFER
615 /* Also take the logbuffer into account (pram is in kB) */
616 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
617#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000618 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
619 setenv ("mem", memsz);
620 }
621#endif
622
wdenke65527f2004-02-12 00:47:09 +0000623#ifdef CONFIG_MODEM_SUPPORT
624 {
625 extern int do_mdm_init;
626 do_mdm_init = gd->do_mdm_init;
627 }
628#endif
629
630#ifdef CONFIG_WATCHDOG
631 /* disable watchdog if environment is set */
632 if ((s = getenv ("watchdog")) != NULL) {
633 if (strncmp (s, "off", 3) == 0) {
634 WATCHDOG_DISABLE ();
635 }
636 }
637#endif /* CONFIG_WATCHDOG*/
638
639
wdenkabf7a7c2003-12-08 01:34:36 +0000640 /* Initialization complete - start the monitor */
641
642 /* main_loop() can return to retry autoboot, if so just run it again. */
643 for (;;) {
644 WATCHDOG_RESET ();
645 main_loop ();
646 }
647
648 /* NOTREACHED - no way out of command loop except booting */
649}