blob: 6de920eb43735f08e5949902975fedc250374454 [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) || \
Heiko Schocher479a4cf2013-01-29 08:53:15 +010043 defined(CONFIG_SYS_I2C)
stroesecd2128e2004-12-16 17:55:22 +000044#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
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100129#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
stroesecd2128e2004-12-16 17:55:22 +0000130static int init_func_i2c (void)
131{
132 puts ("I2C: ");
Heiko Schochere0e55bc2012-01-16 21:12:24 +0000133#ifdef CONFIG_SYS_I2C
134 i2c_init_all();
135#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Heiko Schochere0e55bc2012-01-16 21:12:24 +0000137#endif
stroesecd2128e2004-12-16 17:55:22 +0000138 puts ("ready\n");
139 return (0);
140}
141#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000142
TsiChung Liew663c9522008-07-23 17:53:36 -0500143#if defined(CONFIG_HARD_SPI)
144static int init_func_spi (void)
145{
146 puts ("SPI: ");
147 spi_init ();
148 puts ("ready\n");
149 return (0);
150}
151#endif
152
wdenke65527f2004-02-12 00:47:09 +0000153/***********************************************************************/
154
155/************************************************************************
156 * Initialization sequence *
157 ************************************************************************
158 */
159
160init_fnc_t *init_sequence[] = {
Stefan Roesea06fd372007-08-15 14:51:27 +0200161 get_clocks,
wdenke65527f2004-02-12 00:47:09 +0000162 env_init,
163 init_baudrate,
164 serial_init,
165 console_init_f,
166 display_options,
167 checkcpu,
168 checkboard,
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100169#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
stroesecd2128e2004-12-16 17:55:22 +0000170 init_func_i2c,
171#endif
TsiChung Liew663c9522008-07-23 17:53:36 -0500172#if defined(CONFIG_HARD_SPI)
173 init_func_spi,
174#endif
wdenke65527f2004-02-12 00:47:09 +0000175 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176#if defined(CONFIG_SYS_DRAM_TEST)
wdenke65527f2004-02-12 00:47:09 +0000177 testdram,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178#endif /* CONFIG_SYS_DRAM_TEST */
wdenke65527f2004-02-12 00:47:09 +0000179 INIT_FUNC_WATCHDOG_INIT
180 NULL, /* Terminate this list */
181};
182
183
wdenkabf7a7c2003-12-08 01:34:36 +0000184/************************************************************************
185 *
186 * This is the first part of the initialization sequence that is
187 * implemented in C, but still running from ROM.
188 *
189 * The main purpose is to provide a (serial) console interface as
190 * soon as possible (so we can see any error messages), and to
191 * initialize the RAM so that we can relocate the monitor code to
192 * RAM.
193 *
194 * Be aware of the restrictions: global data is read-only, BSS is not
195 * initialized, and stack space is limited to a few kB.
196 *
197 ************************************************************************
198 */
199
wdenke65527f2004-02-12 00:47:09 +0000200void
201board_init_f (ulong bootflag)
wdenkabf7a7c2003-12-08 01:34:36 +0000202{
wdenkabf7a7c2003-12-08 01:34:36 +0000203 bd_t *bd;
wdenke65527f2004-02-12 00:47:09 +0000204 ulong len, addr, addr_sp;
Marian Balakowicz3e8b1dc2006-05-09 11:28:36 +0200205 ulong *paddr;
wdenke65527f2004-02-12 00:47:09 +0000206 gd_t *id;
207 init_fnc_t **init_fnc_ptr;
208#ifdef CONFIG_PRAM
wdenke65527f2004-02-12 00:47:09 +0000209 ulong reg;
wdenke65527f2004-02-12 00:47:09 +0000210#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000211
wdenke65527f2004-02-12 00:47:09 +0000212 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk3337af42004-07-01 20:28:03 +0000214 /* compiler optimization barrier needed for GCC >= 3.4 */
215 __asm__ __volatile__("": : :"memory");
wdenkabf7a7c2003-12-08 01:34:36 +0000216
wdenke65527f2004-02-12 00:47:09 +0000217 /* Clear initial global data */
218 memset ((void *) gd, 0, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000219
wdenke65527f2004-02-12 00:47:09 +0000220 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
221 if ((*init_fnc_ptr)() != 0) {
222 hang ();
223 }
wdenkabf7a7c2003-12-08 01:34:36 +0000224 }
wdenkabf7a7c2003-12-08 01:34:36 +0000225
226 /*
227 * Now that we have DRAM mapped and working, we can
228 * relocate the code and continue running from DRAM.
229 *
230 * Reserve memory at end of RAM for (top down in that order):
wdenke65527f2004-02-12 00:47:09 +0000231 * - protected RAM
232 * - LCD framebuffer
233 * - monitor code
234 * - board info struct
wdenkabf7a7c2003-12-08 01:34:36 +0000235 */
Simon Glassed70c8f2013-03-14 06:54:53 +0000236 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkabf7a7c2003-12-08 01:34:36 +0000237
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200238 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
wdenkabf7a7c2003-12-08 01:34:36 +0000239
wdenke65527f2004-02-12 00:47:09 +0000240#ifdef CONFIG_LOGBUFFER
241 /* reserve kernel log buffer */
242 addr -= (LOGBUFF_RESERVE);
243 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
244#endif
245
246#ifdef CONFIG_PRAM
247 /*
248 * reserve protected RAM
249 */
Simon Glass9e5689f2011-10-13 14:43:09 +0000250 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenke65527f2004-02-12 00:47:09 +0000251 addr -= (reg << 10); /* size is in kB */
252 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
253#endif /* CONFIG_PRAM */
wdenkabf7a7c2003-12-08 01:34:36 +0000254
TsiChungLiew99b037a2008-01-14 17:43:33 -0600255 /* round down to next 4 kB limit */
256 addr &= ~(4096 - 1);
257 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
258
259#ifdef CONFIG_LCD
Minkyu Kang50777c42011-04-24 22:22:34 +0000260#ifdef CONFIG_FB_ADDR
261 gd->fb_base = CONFIG_FB_ADDR;
262#else
TsiChungLiew99b037a2008-01-14 17:43:33 -0600263 /* reserve memory for LCD display (always full pages) */
264 addr = lcd_setmem (addr);
265 gd->fb_base = addr;
Minkyu Kang50777c42011-04-24 22:22:34 +0000266#endif /* CONFIG_FB_ADDR */
TsiChungLiew99b037a2008-01-14 17:43:33 -0600267#endif /* CONFIG_LCD */
268
wdenke65527f2004-02-12 00:47:09 +0000269 /*
270 * reserve memory for U-Boot code, data & bss
271 * round down to next 4 kB limit
272 */
wdenkabf7a7c2003-12-08 01:34:36 +0000273 addr -= len;
wdenke65527f2004-02-12 00:47:09 +0000274 addr &= ~(4096 - 1);
275
276 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkabf7a7c2003-12-08 01:34:36 +0000277
278 /*
wdenke65527f2004-02-12 00:47:09 +0000279 * reserve memory for malloc() arena
wdenkabf7a7c2003-12-08 01:34:36 +0000280 */
wdenke65527f2004-02-12 00:47:09 +0000281 addr_sp = addr - TOTAL_MALLOC_LEN;
282 debug ("Reserving %dk for malloc() at: %08lx\n",
283 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000284
wdenke65527f2004-02-12 00:47:09 +0000285 /*
286 * (permanently) allocate a Board Info struct
287 * and a permanent copy of the "global" data
288 */
289 addr_sp -= sizeof (bd_t);
290 bd = (bd_t *) addr_sp;
291 gd->bd = bd;
Wolfgang Denk509cd072008-07-14 15:06:35 +0200292 debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
wdenke65527f2004-02-12 00:47:09 +0000293 sizeof (bd_t), addr_sp);
294 addr_sp -= sizeof (gd_t);
295 id = (gd_t *) addr_sp;
Wolfgang Denk509cd072008-07-14 15:06:35 +0200296 debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
wdenke65527f2004-02-12 00:47:09 +0000297 sizeof (gd_t), addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000298
Wolfgang Denka1be4762008-05-20 16:00:29 +0200299 /* Reserve memory for boot params. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200300 addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
wdenke65527f2004-02-12 00:47:09 +0000301 bd->bi_boot_params = addr_sp;
302 debug ("Reserving %dk for boot parameters at: %08lx\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200303 CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
wdenke65527f2004-02-12 00:47:09 +0000304
305 /*
306 * Finally, we set up a new (bigger) stack.
307 *
308 * Leave some safety gap for SP, force alignment on 16 byte boundary
309 * Clear initial stack frame
310 */
311 addr_sp -= 16;
312 addr_sp &= ~0xF;
Marian Balakowicz3e8b1dc2006-05-09 11:28:36 +0200313
314 paddr = (ulong *)addr_sp;
315 *paddr-- = 0;
316 *paddr-- = 0;
317 addr_sp = (ulong)paddr;
Wolfgang Denkc2c49442006-05-10 17:43:20 +0200318
wdenke65527f2004-02-12 00:47:09 +0000319 debug ("Stack Pointer at: %08lx\n", addr_sp);
320
321 /*
322 * Save local variables to board info struct
323 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200324 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM memory */
wdenke65527f2004-02-12 00:47:09 +0000325 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200326#ifdef CONFIG_SYS_INIT_RAM_ADDR
327 bd->bi_sramstart = CONFIG_SYS_INIT_RAM_ADDR; /* start of SRAM memory */
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200328 bd->bi_sramsize = CONFIG_SYS_INIT_RAM_SIZE; /* size of SRAM memory */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500329#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200330 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenke65527f2004-02-12 00:47:09 +0000331
332 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
wdenkabf7a7c2003-12-08 01:34:36 +0000333
wdenke65527f2004-02-12 00:47:09 +0000334 WATCHDOG_RESET ();
335 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
336 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500337#ifdef CONFIG_PCI
338 bd->bi_pcifreq = gd->pci_clk; /* PCI Freq in Hz */
339#endif
340#ifdef CONFIG_EXTRA_CLOCK
Simon Glass568a7b62012-12-13 20:49:07 +0000341 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
342 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
343 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500344#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000345
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200346#ifdef CONFIG_SYS_EXTBDINFO
wdenkabf7a7c2003-12-08 01:34:36 +0000347 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
wdenke65527f2004-02-12 00:47:09 +0000348 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
349#endif
350
351 WATCHDOG_RESET ();
wdenkabf7a7c2003-12-08 01:34:36 +0000352
wdenke65527f2004-02-12 00:47:09 +0000353#ifdef CONFIG_POST
354 post_bootmode_init();
355 post_run (NULL, POST_ROM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000356#endif
357
wdenke65527f2004-02-12 00:47:09 +0000358 WATCHDOG_RESET();
wdenkabf7a7c2003-12-08 01:34:36 +0000359
wdenke65527f2004-02-12 00:47:09 +0000360 memcpy (id, (void *)gd, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000361
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200362 debug ("Start relocate of code from %08x to %08lx\n", CONFIG_SYS_MONITOR_BASE, addr);
wdenke65527f2004-02-12 00:47:09 +0000363 relocate_code (addr_sp, id, addr);
364
365 /* NOTREACHED - jump_to_ram() does not return */
366}
wdenkabf7a7c2003-12-08 01:34:36 +0000367
368/************************************************************************
369 *
370 * This is the next part if the initialization sequence: we are now
371 * running from RAM and have a "normal" C environment, i. e. global
372 * data can be written, BSS has been cleared, the stack size in not
373 * that critical any more, etc.
374 *
375 ************************************************************************
376 */
wdenke65527f2004-02-12 00:47:09 +0000377void board_init_r (gd_t *id, ulong dest_addr)
wdenkabf7a7c2003-12-08 01:34:36 +0000378{
Marek Vasut136c04a2012-10-03 13:28:46 +0000379 char *s __maybe_unused;
wdenkabf7a7c2003-12-08 01:34:36 +0000380 bd_t *bd;
381
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200382#ifndef CONFIG_ENV_IS_NOWHERE
wdenke65527f2004-02-12 00:47:09 +0000383 extern char * env_name_spec;
384#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200385#ifndef CONFIG_SYS_NO_FLASH
wdenke65527f2004-02-12 00:47:09 +0000386 ulong flash_size;
387#endif
388 gd = id; /* initialize RAM version of global data */
wdenkabf7a7c2003-12-08 01:34:36 +0000389 bd = gd->bd;
wdenke65527f2004-02-12 00:47:09 +0000390
391 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
392
wdenke65527f2004-02-12 00:47:09 +0000393 WATCHDOG_RESET ();
394
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200395 gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
wdenke65527f2004-02-12 00:47:09 +0000396
angelo46c1ca12012-11-23 12:23:39 +0000397 serial_initialize();
398
Jens Scharsig (BuS Elektronik)537f1862013-01-16 08:24:10 +0100399 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
400
wdenke65527f2004-02-12 00:47:09 +0000401 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkabf7a7c2003-12-08 01:34:36 +0000402
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200403#if defined(CONFIG_NEEDS_MANUAL_RELOC)
wdenkabf7a7c2003-12-08 01:34:36 +0000404 /*
wdenke65527f2004-02-12 00:47:09 +0000405 * We have to relocate the command table manually
406 */
Marek Vasut69c5e342012-10-12 10:27:04 +0000407 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
408 ll_entry_count(cmd_tbl_t, cmd));
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200409#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
wdenke65527f2004-02-12 00:47:09 +0000410
wdenke65527f2004-02-12 00:47:09 +0000411 /* there are some other pointer constants we must deal with */
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200412#ifndef CONFIG_ENV_IS_NOWHERE
wdenke65527f2004-02-12 00:47:09 +0000413 env_name_spec += gd->reloc_off;
414#endif
415
416 WATCHDOG_RESET ();
417
418#ifdef CONFIG_LOGBUFFER
419 logbuff_init_ptrs ();
420#endif
421#ifdef CONFIG_POST
422 post_output_backlog ();
423 post_reloc ();
424#endif
425 WATCHDOG_RESET();
426
427#if 0
428 /* instruction cache enabled in cpu_init_f() for faster relocation */
429 icache_enable (); /* it's time to enable the instruction cache */
430#endif
431
432 /*
wdenkabf7a7c2003-12-08 01:34:36 +0000433 * Setup trap handlers
434 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200435 trap_init (CONFIG_SYS_SDRAM_BASE);
wdenkabf7a7c2003-12-08 01:34:36 +0000436
Peter Tyser781c9b82009-08-21 23:05:21 -0500437 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysered527702009-08-21 23:05:20 -0500438 mem_malloc_init (CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
439 TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
Stefan Roeseb81464e2009-05-11 15:50:12 +0200440
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200441#if !defined(CONFIG_SYS_NO_FLASH)
Peter Tyser0b5a2632010-12-28 18:12:05 -0600442 puts ("Flash: ");
wdenkabf7a7c2003-12-08 01:34:36 +0000443
444 if ((flash_size = flash_init ()) > 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200445# ifdef CONFIG_SYS_FLASH_CHECKSUM
wdenke65527f2004-02-12 00:47:09 +0000446 print_size (flash_size, "");
wdenkabf7a7c2003-12-08 01:34:36 +0000447 /*
448 * Compute and print flash CRC if flashchecksum is set to 'y'
449 *
wdenke65527f2004-02-12 00:47:09 +0000450 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
wdenkabf7a7c2003-12-08 01:34:36 +0000451 */
Joe Hershberger864ec562012-12-11 22:16:22 -0600452 if (getenv_yesno("flashchecksum") == 1) {
TsiChung Liew063097d2009-06-12 13:03:34 +0000453 printf (" CRC: %08X",
wdenke65527f2004-02-12 00:47:09 +0000454 crc32 (0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200455 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
wdenke65527f2004-02-12 00:47:09 +0000456 flash_size)
457 );
wdenkabf7a7c2003-12-08 01:34:36 +0000458 }
459 putc ('\n');
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200460# else /* !CONFIG_SYS_FLASH_CHECKSUM */
wdenke65527f2004-02-12 00:47:09 +0000461 print_size (flash_size, "\n");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200462# endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenkabf7a7c2003-12-08 01:34:36 +0000463 } else {
464 puts (failed);
465 hang ();
466 }
467
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200468 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
wdenke65527f2004-02-12 00:47:09 +0000469 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
470 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200471#else /* CONFIG_SYS_NO_FLASH */
wdenke65527f2004-02-12 00:47:09 +0000472 bd->bi_flashsize = 0;
473 bd->bi_flashstart = 0;
474 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200475#endif /* !CONFIG_SYS_NO_FLASH */
wdenkabf7a7c2003-12-08 01:34:36 +0000476
477 WATCHDOG_RESET ();
478
479 /* initialize higher level parts of CPU like time base and timers */
480 cpu_init_r ();
481
482 WATCHDOG_RESET ();
483
wdenkabf7a7c2003-12-08 01:34:36 +0000484#ifdef CONFIG_SPI
Jean-Christophe PLAGNIOL-VILLARDe46af642008-09-05 09:19:30 +0200485# if !defined(CONFIG_ENV_IS_IN_EEPROM)
wdenkabf7a7c2003-12-08 01:34:36 +0000486 spi_init_f ();
487# endif
488 spi_init_r ();
489#endif
490
Heiko Schochere0e55bc2012-01-16 21:12:24 +0000491#if defined(CONFIG_SYS_I2C)
492 /* Adjust I2C subsystem pointers after relocation */
493 i2c_reloc_fixup();
494#endif
495
wdenkabf7a7c2003-12-08 01:34:36 +0000496 /* relocate environment function pointers etc. */
497 env_relocate ();
498
wdenkabf7a7c2003-12-08 01:34:36 +0000499 WATCHDOG_RESET ();
500
TsiChung Liewf6afe722007-06-18 13:50:13 -0500501#if defined(CONFIG_PCI)
502 /*
503 * Do pci configuration
504 */
505 pci_init ();
506#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000507
wdenke65527f2004-02-12 00:47:09 +0000508 /** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200509 /* Initialize stdio devices */
510 stdio_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000511
wdenke65527f2004-02-12 00:47:09 +0000512 /* Initialize the jump table for applications */
513 jumptable_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000514
wdenke65527f2004-02-12 00:47:09 +0000515 /* Initialize the console (after the relocation and devices init) */
516 console_init_r ();
wdenkabf7a7c2003-12-08 01:34:36 +0000517
stroesecd2128e2004-12-16 17:55:22 +0000518#if defined(CONFIG_MISC_INIT_R)
519 /* miscellaneous platform dependent initialisations */
520 misc_init_r ();
521#endif
522
Jon Loeliger6b233052007-07-09 18:02:11 -0500523#if defined(CONFIG_CMD_KGDB)
wdenkabf7a7c2003-12-08 01:34:36 +0000524 WATCHDOG_RESET ();
525 puts ("KGDB: ");
526 kgdb_init ();
527#endif
528
wdenke65527f2004-02-12 00:47:09 +0000529 debug ("U-Boot relocated to %08lx\n", dest_addr);
530
wdenkabf7a7c2003-12-08 01:34:36 +0000531 /*
532 * Enable Interrupts
533 */
534 interrupt_init ();
wdenke65527f2004-02-12 00:47:09 +0000535
536 /* Must happen after interrupts are initialized since
537 * an irq handler gets installed
538 */
539 timer_init();
540
wdenke65527f2004-02-12 00:47:09 +0000541#ifdef CONFIG_STATUS_LED
542 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
543#endif
544
wdenkabf7a7c2003-12-08 01:34:36 +0000545 udelay (20);
wdenke65527f2004-02-12 00:47:09 +0000546
wdenkabf7a7c2003-12-08 01:34:36 +0000547 /* Insert function pointers now that we have relocated the code */
548
549 /* Initialize from environment */
Simon Glass9e5689f2011-10-13 14:43:09 +0000550 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkabf7a7c2003-12-08 01:34:36 +0000551
wdenke65527f2004-02-12 00:47:09 +0000552 WATCHDOG_RESET ();
553
Jon Loeliger6b233052007-07-09 18:02:11 -0500554#if defined(CONFIG_CMD_DOC)
wdenkabf7a7c2003-12-08 01:34:36 +0000555 WATCHDOG_RESET ();
wdenke65527f2004-02-12 00:47:09 +0000556 puts ("DOC: ");
557 doc_init ();
558#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000559
Jon Loeliger6b233052007-07-09 18:02:11 -0500560#if defined(CONFIG_CMD_NAND)
wdenkabf7a7c2003-12-08 01:34:36 +0000561 WATCHDOG_RESET ();
Markus Klotzbuecherb6437322006-04-25 17:00:33 +0200562 puts ("NAND: ");
wdenke65527f2004-02-12 00:47:09 +0000563 nand_init(); /* go init the NAND */
564#endif
565
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +0200566#ifdef CONFIG_BITBANGMII
567 bb_miiphy_init();
568#endif
Stefan Roesea06fd372007-08-15 14:51:27 +0200569#if defined(CONFIG_CMD_NET)
wdenke65527f2004-02-12 00:47:09 +0000570 WATCHDOG_RESET();
TsiChung Liewf6afe722007-06-18 13:50:13 -0500571#if defined(FEC_ENET)
wdenke65527f2004-02-12 00:47:09 +0000572 eth_init(bd);
573#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500574 puts ("Net: ");
TsiChungLiewaedd3d72007-08-15 15:39:17 -0500575 eth_initialize (bd);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500576#endif
wdenke65527f2004-02-12 00:47:09 +0000577
578#ifdef CONFIG_POST
579 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000580#endif
581
Stefan Roesea06fd372007-08-15 14:51:27 +0200582#if defined(CONFIG_CMD_PCMCIA) \
583 && !defined(CONFIG_CMD_IDE)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500584 WATCHDOG_RESET ();
585 puts ("PCMCIA:");
586 pcmcia_init ();
587#endif
588
Stefan Roesea06fd372007-08-15 14:51:27 +0200589#if defined(CONFIG_CMD_IDE)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500590 WATCHDOG_RESET ();
591 puts ("IDE: ");
592 ide_init ();
Stefan Roesea06fd372007-08-15 14:51:27 +0200593#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500594
wdenkabf7a7c2003-12-08 01:34:36 +0000595#ifdef CONFIG_LAST_STAGE_INIT
596 WATCHDOG_RESET ();
597 /*
598 * Some parts can be only initialized if all others (like
599 * Interrupts) are up and running (i.e. the PC-style ISA
600 * keyboard).
601 */
602 last_stage_init ();
603#endif
604
Jon Loeliger6b233052007-07-09 18:02:11 -0500605#if defined(CONFIG_CMD_BEDBUG)
wdenkabf7a7c2003-12-08 01:34:36 +0000606 WATCHDOG_RESET ();
607 bedbug_init ();
608#endif
609
wdenke65527f2004-02-12 00:47:09 +0000610#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkabf7a7c2003-12-08 01:34:36 +0000611 /*
612 * Export available size of memory for Linux,
613 * taking into account the protected RAM at top of memory
614 */
615 {
Simon Glass9e5689f2011-10-13 14:43:09 +0000616 ulong pram = 0;
Simon Glass0fb06222012-01-05 17:54:56 +0000617 char memsz[32];
wdenkabf7a7c2003-12-08 01:34:36 +0000618
Simon Glass9e5689f2011-10-13 14:43:09 +0000619#ifdef CONFIG_PRAM
620 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenke65527f2004-02-12 00:47:09 +0000621#endif
622#ifdef CONFIG_LOGBUFFER
623 /* Also take the logbuffer into account (pram is in kB) */
624 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
625#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000626 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
627 setenv ("mem", memsz);
628 }
629#endif
630
wdenke65527f2004-02-12 00:47:09 +0000631#ifdef CONFIG_WATCHDOG
632 /* disable watchdog if environment is set */
633 if ((s = getenv ("watchdog")) != NULL) {
634 if (strncmp (s, "off", 3) == 0) {
635 WATCHDOG_DISABLE ();
636 }
637 }
638#endif /* CONFIG_WATCHDOG*/
639
640
wdenkabf7a7c2003-12-08 01:34:36 +0000641 /* Initialization complete - start the monitor */
642
643 /* main_loop() can return to retry autoboot, if so just run it again. */
644 for (;;) {
645 WATCHDOG_RESET ();
646 main_loop ();
647 }
648
649 /* NOTREACHED - no way out of command loop except booting */
650}