blob: 13d761c1f755bd2fe8922f70b3ec7b4d8d337726 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
Wolfgang Denk9b998b02011-11-04 15:55:07 +00002 * (C) Copyright 2000-2011
wdenkfe8c2802002-11-03 00:38:21 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkfe8c2802002-11-03 00:38:21 +00006 */
7
8#include <common.h>
9#include <watchdog.h>
10#include <command.h>
11#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020012#include <stdio_dev.h>
wdenkfe8c2802002-11-03 00:38:21 +000013#ifdef CONFIG_8xx
14#include <mpc8xx.h>
15#endif
wdenk0db5bca2003-03-31 17:27:09 +000016#ifdef CONFIG_5xx
17#include <mpc5xx.h>
18#endif
wdenkcbd8a352004-02-24 02:00:03 +000019#ifdef CONFIG_MPC5xxx
wdenk945af8d2003-07-16 21:53:01 +000020#include <mpc5xxx.h>
21#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -050022#if defined(CONFIG_CMD_IDE)
wdenkfe8c2802002-11-03 00:38:21 +000023#include <ide.h>
24#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -050025#if defined(CONFIG_CMD_SCSI)
wdenkfe8c2802002-11-03 00:38:21 +000026#include <scsi.h>
27#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -050028#if defined(CONFIG_CMD_KGDB)
wdenkfe8c2802002-11-03 00:38:21 +000029#include <kgdb.h>
30#endif
31#ifdef CONFIG_STATUS_LED
32#include <status_led.h>
33#endif
34#include <net.h>
Andy Fleming272cc702008-10-30 16:41:01 -050035#ifdef CONFIG_GENERIC_MMC
36#include <mmc.h>
37#endif
wdenk281e00a2004-08-01 22:48:16 +000038#include <serial.h>
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039#ifdef CONFIG_SYS_ALLOC_DPRAM
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -050040#if !defined(CONFIG_CPM2)
wdenkfe8c2802002-11-03 00:38:21 +000041#include <commproc.h>
42#endif
wdenk7aa78612003-05-03 15:50:43 +000043#endif
wdenkfe8c2802002-11-03 00:38:21 +000044#include <version.h>
45#if defined(CONFIG_BAB7xx)
46#include <w83c553f.h>
47#endif
48#include <dtt.h>
49#if defined(CONFIG_POST)
50#include <post.h>
51#endif
wdenk56f94be2002-11-05 16:35:14 +000052#if defined(CONFIG_LOGBUFFER)
53#include <logbuff.h>
54#endif
Wolfgang Denk9c673522009-07-26 23:28:02 +020055#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
wdenk42d1f032003-10-15 23:53:47 +000056#include <asm/cache.h>
57#endif
wdenk1c437712004-01-16 00:30:56 +000058#ifdef CONFIG_PS2KBD
59#include <keyboard.h>
60#endif
wdenkfe8c2802002-11-03 00:38:21 +000061
Kumar Galaecf5b982008-12-16 14:59:20 -060062#ifdef CONFIG_ADDR_MAP
63#include <asm/mmu.h>
64#endif
65
Kumar Galafc39c2fd2009-03-31 17:58:13 -050066#ifdef CONFIG_MP
67#include <asm/mp.h>
68#endif
69
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020070#ifdef CONFIG_BITBANGMII
71#include <miiphy.h>
72#endif
73
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020074#ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
Wolfgang Denk9b998b02011-11-04 15:55:07 +000075extern int update_flash_size(int flash_size);
Heiko Schocherfa230442006-12-21 17:17:02 +010076#endif
77
Wolfgang Denk9045f332007-06-08 10:24:58 +020078#if defined(CONFIG_SC3)
Heiko Schocherca43ba12007-01-11 15:44:44 +010079extern void sc3_read_eeprom(void);
80#endif
81
Jon Loeliger7def6b32007-07-09 18:02:11 -050082#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +000083void doc_init(void);
wdenkfe8c2802002-11-03 00:38:21 +000084#endif
Heiko Schocherea818db2013-01-29 08:53:15 +010085#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
wdenkfe8c2802002-11-03 00:38:21 +000086#include <i2c.h>
87#endif
Ben Warren04a9e112008-01-16 22:37:35 -050088#include <spi.h>
Scott Woodd6ac2ed2008-05-22 10:49:46 -050089#include <nand.h>
wdenkfe8c2802002-11-03 00:38:21 +000090
91static char *failed = "*** failed ***\n";
92
Wolfgang Denk544d97e2010-10-05 22:54:53 +020093#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenkfe8c2802002-11-03 00:38:21 +000094extern flash_info_t flash_info[];
wdenk17d704e2004-04-10 20:43:50 +000095#endif
wdenkfe8c2802002-11-03 00:38:21 +000096
Heiko Schocherca43ba12007-01-11 15:44:44 +010097#if defined(CONFIG_START_IDE)
98extern int board_start_ide(void);
99#endif
wdenkfe8c2802002-11-03 00:38:21 +0000100#include <environment.h>
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200101
Wolfgang Denkbce84c42005-08-30 14:13:23 +0200102DECLARE_GLOBAL_DATA_PTR;
wdenkfe8c2802002-11-03 00:38:21 +0000103
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104#if !defined(CONFIG_SYS_MEM_TOP_HIDE)
105#define CONFIG_SYS_MEM_TOP_HIDE 0
Stefan Roese6fb4b642008-03-27 10:24:03 +0100106#endif
107
wdenk3b57fe02003-05-30 12:48:29 +0000108extern ulong __init_end;
Simon Glass3929fb02013-03-14 06:54:53 +0000109extern ulong __bss_end;
wdenk3b57fe02003-05-30 12:48:29 +0000110ulong monitor_flash_len;
111
Jon Loeliger7def6b32007-07-09 18:02:11 -0500112#if defined(CONFIG_CMD_BEDBUG)
wdenk8bde7f72003-06-27 21:31:46 +0000113#include <bedbug/type.h>
114#endif
115
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000116/*
117 * Utilities
wdenkfe8c2802002-11-03 00:38:21 +0000118 */
119
120/*
wdenkfe8c2802002-11-03 00:38:21 +0000121 * All attempts to come up with a "common" initialization sequence
122 * that works for all boards and architectures failed: some of the
123 * requirements are just _too_ different. To get rid of the resulting
124 * mess of board dependend #ifdef'ed code we now make the whole
125 * initialization sequence configurable to the user.
126 *
127 * The requirements for any new initalization function is simple: it
128 * receives a pointer to the "global data" structure as it's only
129 * argument, and returns an integer return code, where 0 means
130 * "continue" and != 0 means "fatal error, hang the system".
131 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000132typedef int (init_fnc_t)(void);
wdenkfe8c2802002-11-03 00:38:21 +0000133
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000134/*
135 * Init Utilities
136 *
wdenkfe8c2802002-11-03 00:38:21 +0000137 * Some of this code should be moved into the core functions,
138 * but let's get it working (again) first...
139 */
140
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000141static int init_baudrate(void)
wdenkfe8c2802002-11-03 00:38:21 +0000142{
Simon Glass12725922011-10-13 14:43:12 +0000143 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
144 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000145}
146
147/***********************************************************************/
148
Kim Phillips20051f22012-10-29 13:34:29 +0000149static void __board_add_ram_info(int use_default)
Kim Phillips79f240f2007-08-16 22:52:39 -0500150{
151 /* please define platform specific board_add_ram_info() */
152}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000153
154void board_add_ram_info(int)
155 __attribute__ ((weak, alias("__board_add_ram_info")));
Kim Phillips79f240f2007-08-16 22:52:39 -0500156
Kim Phillips20051f22012-10-29 13:34:29 +0000157static int __board_flash_wp_on(void)
John Schmollerc62491d2010-09-29 14:05:44 -0500158{
159 /*
160 * Most flashes can't be detected when write protection is enabled,
161 * so provide a way to let U-Boot gracefully ignore write protected
162 * devices.
163 */
164 return 0;
165}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000166
167int board_flash_wp_on(void)
168 __attribute__ ((weak, alias("__board_flash_wp_on")));
Stefan Roesed96f41e2005-11-30 13:06:40 +0100169
Kim Phillips20051f22012-10-29 13:34:29 +0000170static void __cpu_secondary_init_r(void)
Kumar Galaf9a33f12011-02-02 11:23:50 -0600171{
172}
Kumar Galaf9a33f12011-02-02 11:23:50 -0600173
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000174void cpu_secondary_init_r(void)
175 __attribute__ ((weak, alias("__cpu_secondary_init_r")));
176
177static int init_func_ram(void)
wdenkfe8c2802002-11-03 00:38:21 +0000178{
wdenkfe8c2802002-11-03 00:38:21 +0000179#ifdef CONFIG_BOARD_TYPES
180 int board_type = gd->board_type;
181#else
182 int board_type = 0; /* use dummy arg */
183#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000184 puts("DRAM: ");
wdenkfe8c2802002-11-03 00:38:21 +0000185
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000186 gd->ram_size = initdram(board_type);
187
188 if (gd->ram_size > 0) {
189 print_size(gd->ram_size, "");
Stefan Roesed96f41e2005-11-30 13:06:40 +0100190 board_add_ram_info(0);
Stefan Roesed96f41e2005-11-30 13:06:40 +0100191 putc('\n');
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000192 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000193 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000194 puts(failed);
195 return 1;
wdenkfe8c2802002-11-03 00:38:21 +0000196}
197
198/***********************************************************************/
199
Heiko Schocherea818db2013-01-29 08:53:15 +0100200#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000201static int init_func_i2c(void)
wdenkfe8c2802002-11-03 00:38:21 +0000202{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000203 puts("I2C: ");
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000204#ifdef CONFIG_SYS_I2C
205 i2c_init_all();
206#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000207 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000208#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000209 puts("ready\n");
210 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000211}
212#endif
213
Ben Warren04a9e112008-01-16 22:37:35 -0500214#if defined(CONFIG_HARD_SPI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000215static int init_func_spi(void)
Ben Warren04a9e112008-01-16 22:37:35 -0500216{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000217 puts("SPI: ");
218 spi_init();
219 puts("ready\n");
220 return 0;
Ben Warren04a9e112008-01-16 22:37:35 -0500221}
222#endif
223
wdenkfe8c2802002-11-03 00:38:21 +0000224/***********************************************************************/
225
226#if defined(CONFIG_WATCHDOG)
Simon Glassa6741bc2013-03-05 14:39:42 +0000227int init_func_watchdog_init(void)
wdenkfe8c2802002-11-03 00:38:21 +0000228{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000229 puts(" Watchdog enabled\n");
230 WATCHDOG_RESET();
231 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000232}
wdenkfe8c2802002-11-03 00:38:21 +0000233
Simon Glassa6741bc2013-03-05 14:39:42 +0000234int init_func_watchdog_reset(void)
wdenkfe8c2802002-11-03 00:38:21 +0000235{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000236 WATCHDOG_RESET();
237 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000238}
wdenkfe8c2802002-11-03 00:38:21 +0000239#endif /* CONFIG_WATCHDOG */
240
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000241/*
242 * Initialization sequence
wdenkfe8c2802002-11-03 00:38:21 +0000243 */
244
Kim Phillips20051f22012-10-29 13:34:29 +0000245static init_fnc_t *init_sequence[] = {
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530246#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
247 probecpu,
248#endif
Anton Vorontsov91525c62009-10-12 23:55:39 +0400249#if defined(CONFIG_BOARD_EARLY_INIT_F)
250 board_early_init_f,
251#endif
wdenk66ca92a2004-09-28 17:59:53 +0000252#if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
wdenkfe8c2802002-11-03 00:38:21 +0000253 get_clocks, /* get CPU and bus clocks (etc.) */
Markus Klotzbuecher090eb732006-07-12 15:26:01 +0200254#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
255 && !defined(CONFIG_TQM885D)
wdenke9132ea2004-04-24 23:23:30 +0000256 adjust_sdram_tbs_8xx,
257#endif
wdenkfe8c2802002-11-03 00:38:21 +0000258 init_timebase,
wdenkc178d3d2004-01-24 20:25:54 +0000259#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200260#ifdef CONFIG_SYS_ALLOC_DPRAM
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500261#if !defined(CONFIG_CPM2)
wdenkfe8c2802002-11-03 00:38:21 +0000262 dpram_init,
263#endif
wdenk7aa78612003-05-03 15:50:43 +0000264#endif
wdenkfe8c2802002-11-03 00:38:21 +0000265#if defined(CONFIG_BOARD_POSTCLK_INIT)
266 board_postclk_init,
267#endif
268 env_init,
wdenk66ca92a2004-09-28 17:59:53 +0000269#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000270 /* get CPU and bus clocks according to the environment variable */
271 get_clocks_866,
272 /* adjust sdram refresh rate according to the new clock */
273 sdram_adjust_866,
wdenkc178d3d2004-01-24 20:25:54 +0000274 init_timebase,
275#endif
wdenkfe8c2802002-11-03 00:38:21 +0000276 init_baudrate,
277 serial_init,
278 console_init_f,
279 display_options,
280#if defined(CONFIG_8260)
281 prt_8260_rsr,
282 prt_8260_clks,
283#endif /* CONFIG_8260 */
Peter Tyser0f898602009-05-22 17:23:24 -0500284#if defined(CONFIG_MPC83xx)
Dave Liu9be39a62007-06-25 10:41:56 +0800285 prt_83xx_rsr,
286#endif
wdenkfe8c2802002-11-03 00:38:21 +0000287 checkcpu,
wdenkcbd8a352004-02-24 02:00:03 +0000288#if defined(CONFIG_MPC5xxx)
wdenk945af8d2003-07-16 21:53:01 +0000289 prt_mpc5xxx_clks,
wdenkcbd8a352004-02-24 02:00:03 +0000290#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000291 checkboard,
292 INIT_FUNC_WATCHDOG_INIT
wdenkc837dcb2004-01-20 23:12:12 +0000293#if defined(CONFIG_MISC_INIT_F)
wdenkfe8c2802002-11-03 00:38:21 +0000294 misc_init_f,
295#endif
296 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100297#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
wdenkfe8c2802002-11-03 00:38:21 +0000298 init_func_i2c,
299#endif
Ben Warren04a9e112008-01-16 22:37:35 -0500300#if defined(CONFIG_HARD_SPI)
301 init_func_spi,
302#endif
wdenk4532cb62003-04-27 22:52:51 +0000303#ifdef CONFIG_POST
304 post_init_f,
305#endif
Simon Glass6f6430d2013-03-11 14:30:37 +0000306 INIT_FUNC_WATCHDOG_RESET
307 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200308#if defined(CONFIG_SYS_DRAM_TEST)
wdenkfe8c2802002-11-03 00:38:21 +0000309 testdram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200310#endif /* CONFIG_SYS_DRAM_TEST */
wdenkfe8c2802002-11-03 00:38:21 +0000311 INIT_FUNC_WATCHDOG_RESET
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000312 NULL, /* Terminate this list */
wdenkfe8c2802002-11-03 00:38:21 +0000313};
314
Kim Phillips20051f22012-10-29 13:34:29 +0000315static int __fixup_cpu(void)
York Sun123bd962012-08-17 08:20:22 +0000316{
317 return 0;
318}
319
320int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
321
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000322/*
wdenkfe8c2802002-11-03 00:38:21 +0000323 * This is the first part of the initialization sequence that is
324 * implemented in C, but still running from ROM.
325 *
326 * The main purpose is to provide a (serial) console interface as
327 * soon as possible (so we can see any error messages), and to
328 * initialize the RAM so that we can relocate the monitor code to
329 * RAM.
330 *
331 * Be aware of the restrictions: global data is read-only, BSS is not
332 * initialized, and stack space is limited to a few kB.
wdenkfe8c2802002-11-03 00:38:21 +0000333 */
334
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000335void board_init_f(ulong bootflag)
wdenkfe8c2802002-11-03 00:38:21 +0000336{
wdenkfe8c2802002-11-03 00:38:21 +0000337 bd_t *bd;
338 ulong len, addr, addr_sp;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200339 ulong *s;
wdenkfe8c2802002-11-03 00:38:21 +0000340 gd_t *id;
341 init_fnc_t **init_fnc_ptr;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000342
wdenkfe8c2802002-11-03 00:38:21 +0000343#ifdef CONFIG_PRAM
wdenkfe8c2802002-11-03 00:38:21 +0000344 ulong reg;
wdenkfe8c2802002-11-03 00:38:21 +0000345#endif
346
347 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200348 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk93f6a672004-07-01 20:28:03 +0000349 /* compiler optimization barrier needed for GCC >= 3.4 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000350 __asm__ __volatile__("":::"memory");
wdenkfe8c2802002-11-03 00:38:21 +0000351
Detlev Zundel82826d52010-01-22 14:47:59 +0100352#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
353 !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
354 !defined(CONFIG_MPC86xx)
wdenkfe8c2802002-11-03 00:38:21 +0000355 /* Clear initial global data */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000356 memset((void *) gd, 0, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000357#endif
358
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000359 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
360 if ((*init_fnc_ptr) () != 0)
361 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000362
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000363#ifdef CONFIG_POST
364 post_bootmode_init();
Kim Phillips20051f22012-10-29 13:34:29 +0000365 post_run(NULL, POST_ROM | post_bootmode_get(NULL));
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000366#endif
367
368 WATCHDOG_RESET();
369
wdenkfe8c2802002-11-03 00:38:21 +0000370 /*
371 * Now that we have DRAM mapped and working, we can
372 * relocate the code and continue running from DRAM.
373 *
374 * Reserve memory at end of RAM for (top down in that order):
Stefan Roese14f73ca2008-03-26 10:14:11 +0100375 * - area that won't get touched by U-Boot and Linux (optional)
wdenk8bde7f72003-06-27 21:31:46 +0000376 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000377 * - protected RAM
378 * - LCD framebuffer
379 * - monitor code
380 * - board info struct
381 */
Simon Glass3929fb02013-03-14 06:54:53 +0000382 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000383
Stefan Roese14f73ca2008-03-26 10:14:11 +0100384 /*
385 * Subtract specified amount of memory to hide so that it won't
386 * get "touched" at all by U-Boot. By fixing up gd->ram_size
387 * the Linux kernel should now get passed the now "corrected"
388 * memory size and won't touch it either. This should work
389 * for arch/ppc and arch/powerpc. Only Linux board ports in
390 * arch/powerpc with bootwrapper support, that recalculate the
391 * memory size from the SDRAM controller setup will have to
392 * get fixed.
393 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200394 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
Stefan Roese14f73ca2008-03-26 10:14:11 +0100395
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200396 addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
wdenkfe8c2802002-11-03 00:38:21 +0000397
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500398#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
399 /*
400 * We need to make sure the location we intend to put secondary core
401 * boot code is reserved and not used by any part of u-boot
Wolfgang Denkc0a14ae2009-04-05 00:27:57 +0200402 */
York Suneb539412012-10-08 07:44:25 +0000403 if (addr > determine_mp_bootpg(NULL)) {
404 addr = determine_mp_bootpg(NULL);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000405 debug("Reserving MP boot page to %08lx\n", addr);
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500406 }
407#endif
408
wdenk228f29a2002-12-08 09:53:23 +0000409#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100410#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000411 /* reserve kernel log buffer */
412 addr -= (LOGBUFF_RESERVE);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000413 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
414 addr);
wdenk228f29a2002-12-08 09:53:23 +0000415#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100416#endif
wdenk228f29a2002-12-08 09:53:23 +0000417
wdenkfe8c2802002-11-03 00:38:21 +0000418#ifdef CONFIG_PRAM
419 /*
420 * reserve protected RAM
421 */
Simon Glass12725922011-10-13 14:43:12 +0000422 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000423 addr -= (reg << 10); /* size is in kB */
Simon Glass12725922011-10-13 14:43:12 +0000424 debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000425#endif /* CONFIG_PRAM */
426
427 /* round down to next 4 kB limit */
428 addr &= ~(4096 - 1);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000429 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000430
431#ifdef CONFIG_LCD
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000432#ifdef CONFIG_FB_ADDR
433 gd->fb_base = CONFIG_FB_ADDR;
434#else
wdenkfe8c2802002-11-03 00:38:21 +0000435 /* reserve memory for LCD display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000436 addr = lcd_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000437 gd->fb_base = addr;
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000438#endif /* CONFIG_FB_ADDR */
wdenkfe8c2802002-11-03 00:38:21 +0000439#endif /* CONFIG_LCD */
440
441#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
442 /* reserve memory for video display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000443 addr = video_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000444 gd->fb_base = addr;
445#endif /* CONFIG_VIDEO */
446
447 /*
448 * reserve memory for U-Boot code, data & bss
wdenk682011f2003-06-03 23:54:09 +0000449 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000450 */
451 addr -= len;
wdenk682011f2003-06-03 23:54:09 +0000452 addr &= ~(4096 - 1);
Wolfgang Denk7d314992005-10-05 00:00:54 +0200453#ifdef CONFIG_E500
454 /* round down to next 64 kB limit so that IVPR stays aligned */
455 addr &= ~(65536 - 1);
456#endif
wdenkfe8c2802002-11-03 00:38:21 +0000457
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000458 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000459
460 /*
461 * reserve memory for malloc() arena
462 */
463 addr_sp = addr - TOTAL_MALLOC_LEN;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000464 debug("Reserving %dk for malloc() at: %08lx\n",
465 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000466
467 /*
468 * (permanently) allocate a Board Info struct
469 * and a permanent copy of the "global" data
470 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000471 addr_sp -= sizeof(bd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000472 bd = (bd_t *) addr_sp;
Peter Tysera1c48642010-09-14 19:13:51 -0500473 memset(bd, 0, sizeof(bd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000474 gd->bd = bd;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000475 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
476 sizeof(bd_t), addr_sp);
477 addr_sp -= sizeof(gd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000478 id = (gd_t *) addr_sp;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000479 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
480 sizeof(gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000481
482 /*
483 * Finally, we set up a new (bigger) stack.
484 *
485 * Leave some safety gap for SP, force alignment on 16 byte boundary
486 * Clear initial stack frame
487 */
488 addr_sp -= 16;
489 addr_sp &= ~0xF;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000490 s = (ulong *) addr_sp;
Joakim Tjernlund7de8a712012-07-23 10:58:03 +0000491 *s = 0; /* Terminate back chain */
492 *++s = 0; /* NULL return address */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000493 debug("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000494
495 /*
496 * Save local variables to board info struct
497 */
498
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000499 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
500 bd->bi_memsize = gd->ram_size; /* size in bytes */
wdenkfe8c2802002-11-03 00:38:21 +0000501
Wolfgang Denk36116652010-08-11 09:38:31 +0200502#ifdef CONFIG_SYS_SRAM_BASE
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000503 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
504 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
wdenkfe8c2802002-11-03 00:38:21 +0000505#endif
506
wdenk42d1f032003-10-15 23:53:47 +0000507#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
Jon Loeligerdebb7352006-04-26 17:58:56 -0500508 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200509 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
wdenkfe8c2802002-11-03 00:38:21 +0000510#endif
wdenkcbd8a352004-02-24 02:00:03 +0000511#if defined(CONFIG_MPC5xxx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200512 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenk945af8d2003-07-16 21:53:01 +0000513#endif
Peter Tyser0f898602009-05-22 17:23:24 -0500514#if defined(CONFIG_MPC83xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200515 bd->bi_immrbar = CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500516#endif
wdenkfe8c2802002-11-03 00:38:21 +0000517
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000518 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000519 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
520 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500521#if defined(CONFIG_CPM2)
Simon Glass748cd052012-12-13 20:48:46 +0000522 bd->bi_cpmfreq = gd->arch.cpm_clk;
Simon Glass1206c182012-12-13 20:48:44 +0000523 bd->bi_brgfreq = gd->arch.brg_clk;
Simon Glass748cd052012-12-13 20:48:46 +0000524 bd->bi_sccfreq = gd->arch.scc_clk;
525 bd->bi_vco = gd->arch.vco_out;
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500526#endif /* CONFIG_CPM2 */
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100527#if defined(CONFIG_MPC512X)
Simon Glassfefb0982012-12-13 20:48:54 +0000528 bd->bi_ipsfreq = gd->arch.ips_clk;
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100529#endif /* CONFIG_MPC512X */
wdenkcbd8a352004-02-24 02:00:03 +0000530#if defined(CONFIG_MPC5xxx)
Simon Glassb2877492012-12-13 20:48:53 +0000531 bd->bi_ipbfreq = gd->arch.ipb_clk;
wdenk945af8d2003-07-16 21:53:01 +0000532 bd->bi_pcifreq = gd->pci_clk;
wdenkcbd8a352004-02-24 02:00:03 +0000533#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000534 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
535
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200536#ifdef CONFIG_SYS_EXTBDINFO
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000537 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
538 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
539 sizeof(bd->bi_r_version));
wdenkfe8c2802002-11-03 00:38:21 +0000540
541 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
542 bd->bi_plb_busfreq = gd->bus_clk;
Stefan Roese343c48b2007-05-11 12:01:06 +0200543#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
544 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
545 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000546 bd->bi_pci_busfreq = get_PCI_freq();
547 bd->bi_opbfreq = get_OPB_freq();
Michal Simek9fea65a2008-06-24 09:54:09 +0200548#elif defined(CONFIG_XILINX_405)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000549 bd->bi_pci_busfreq = get_PCI_freq();
wdenkfe8c2802002-11-03 00:38:21 +0000550#endif
551#endif
552
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000553 debug("New Stack Pointer is: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000554
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000555 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000556
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000557 gd->relocaddr = addr; /* Store relocation addr, useful for debug */
Richard Retanubun4b993272010-01-15 10:06:06 -0500558
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000559 memcpy(id, (void *) gd, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000560
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000561 relocate_code(addr_sp, id, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000562
563 /* NOTREACHED - relocate_code() does not return */
564}
565
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000566/*
wdenkfe8c2802002-11-03 00:38:21 +0000567 * This is the next part if the initialization sequence: we are now
568 * running from RAM and have a "normal" C environment, i. e. global
569 * data can be written, BSS has been cleared, the stack size in not
570 * that critical any more, etc.
wdenkfe8c2802002-11-03 00:38:21 +0000571 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000572void board_init_r(gd_t *id, ulong dest_addr)
wdenkfe8c2802002-11-03 00:38:21 +0000573{
wdenkfe8c2802002-11-03 00:38:21 +0000574 bd_t *bd;
Peter Tysera483a162009-08-21 23:05:20 -0500575 ulong malloc_start;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000576
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200577#ifndef CONFIG_SYS_NO_FLASH
wdenkfe8c2802002-11-03 00:38:21 +0000578 ulong flash_size;
579#endif
580
581 gd = id; /* initialize RAM version of global data */
582 bd = gd->bd;
583
584 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
Grant Likelyf82b3b62007-07-03 00:34:19 -0600585
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500586 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysera483a162009-08-21 23:05:20 -0500587 malloc_start = dest_addr - TOTAL_MALLOC_LEN;
Kumar Gala13d46ab2009-09-01 21:07:08 -0500588
Peter Tyserf9476902009-12-15 12:10:47 -0600589#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
590 /*
Simon Glass67ac13b2012-12-13 20:48:48 +0000591 * The gd->arch.cpu pointer is set to an address in flash before
592 * relocation. We need to update it to point to the same CPU entry
593 * in RAM.
Peter Tyserf9476902009-12-15 12:10:47 -0600594 */
Simon Glass67ac13b2012-12-13 20:48:48 +0000595 gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
York Sun123bd962012-08-17 08:20:22 +0000596
597 /*
598 * If we didn't know the cpu mask & # cores, we can save them of
599 * now rather than 'computing' them constantly
600 */
601 fixup_cpu();
Peter Tyserf9476902009-12-15 12:10:47 -0600602#endif
603
Kumar Galaa55bb832010-11-29 14:32:11 -0600604#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
605 /*
606 * Some systems need to relocate the env_addr pointer early because the
607 * location it points to will get invalidated before env_relocate is
608 * called. One example is on systems that might use a L2 or L3 cache
609 * in SRAM mode and initialize that cache from SRAM mode back to being
610 * a cache in cpu_init_r.
611 */
612 gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
613#endif
614
Marian Balakowiczbb105f22006-06-30 15:27:09 +0200615 serial_initialize();
wdenkfe8c2802002-11-03 00:38:21 +0000616
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000617 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000618
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000619 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000620
Becky Bruced025aa42008-10-31 17:14:39 -0500621 /*
622 * Setup trap handlers
623 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000624 trap_init(dest_addr);
Becky Bruced025aa42008-10-31 17:14:39 -0500625
Becky Brucec9315e62009-02-03 18:10:52 -0600626#ifdef CONFIG_ADDR_MAP
Kumar Galaecf5b982008-12-16 14:59:20 -0600627 init_addr_map();
628#endif
629
wdenkc837dcb2004-01-20 23:12:12 +0000630#if defined(CONFIG_BOARD_EARLY_INIT_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000631 board_early_init_r();
wdenkc837dcb2004-01-20 23:12:12 +0000632#endif
633
wdenk3b57fe02003-05-30 12:48:29 +0000634 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkfe8c2802002-11-03 00:38:21 +0000635
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000636 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000637
wdenk56f94be2002-11-05 16:35:14 +0000638#ifdef CONFIG_LOGBUFFER
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000639 logbuff_init_ptrs();
wdenk56f94be2002-11-05 16:35:14 +0000640#endif
wdenkfe8c2802002-11-03 00:38:21 +0000641#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000642 post_output_backlog();
wdenkfe8c2802002-11-03 00:38:21 +0000643#endif
644
645 WATCHDOG_RESET();
646
Kim Phillips1a2e2032010-04-20 19:37:54 -0500647#if defined(CONFIG_SYS_DELAYED_ICACHE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000648 icache_enable(); /* it's time to enable the instruction cache */
wdenkfe8c2802002-11-03 00:38:21 +0000649#endif
650
Wolfgang Denk9c673522009-07-26 23:28:02 +0200651#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
652 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
wdenk42d1f032003-10-15 23:53:47 +0000653#endif
654
Andre Schwarz76221a62010-10-05 11:59:31 +0200655#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000656 /*
Andre Schwarz76221a62010-10-05 11:59:31 +0200657 * Do early PCI configuration _before_ the flash gets initialised,
658 * because PCU ressources are crucial for flash access on some boards.
wdenkfe8c2802002-11-03 00:38:21 +0000659 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000660 pci_init();
wdenk3bac3512003-03-12 10:41:04 +0000661#endif
Wolfgang Denk57d6c582010-11-23 23:17:18 +0100662#if defined(CONFIG_WINBOND_83C553)
wdenkfe8c2802002-11-03 00:38:21 +0000663 /*
664 * Initialise the ISA bridge
665 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000666 initialise_w83c553f();
wdenkfe8c2802002-11-03 00:38:21 +0000667#endif
668
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000669 asm("sync ; isync");
wdenkfe8c2802002-11-03 00:38:21 +0000670
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000671 mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
Stefan Roesec790b042009-05-11 15:50:12 +0200672
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200673#if !defined(CONFIG_SYS_NO_FLASH)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000674 puts("Flash: ");
wdenkfe8c2802002-11-03 00:38:21 +0000675
John Schmollerc62491d2010-09-29 14:05:44 -0500676 if (board_flash_wp_on()) {
677 printf("Uninitialized - Write Protect On\n");
678 /* Since WP is on, we can't find real size. Set to 0 */
679 flash_size = 0;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000680 } else if ((flash_size = flash_init()) > 0) {
681#ifdef CONFIG_SYS_FLASH_CHECKSUM
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000682 print_size(flash_size, "");
wdenkfe8c2802002-11-03 00:38:21 +0000683 /*
684 * Compute and print flash CRC if flashchecksum is set to 'y'
685 *
686 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
687 */
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600688 if (getenv_yesno("flashchecksum") == 1) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000689 printf(" CRC: %08X",
690 crc32(0,
691 (const unsigned char *)
692 CONFIG_SYS_FLASH_BASE, flash_size)
693 );
wdenkfe8c2802002-11-03 00:38:21 +0000694 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000695 putc('\n');
696#else /* !CONFIG_SYS_FLASH_CHECKSUM */
697 print_size(flash_size, "\n");
698#endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000699 } else {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000700 puts(failed);
701 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000702 }
703
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000704 /* update start of FLASH memory */
705 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
706 /* size of FLASH memory (final value) */
707 bd->bi_flashsize = flash_size;
Heiko Schocherfa230442006-12-21 17:17:02 +0100708
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200709#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
Heiko Schocherfa230442006-12-21 17:17:02 +0100710 /* Make a update of the Memctrl. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000711 update_flash_size(flash_size);
Heiko Schocherfa230442006-12-21 17:17:02 +0100712#endif
713
714
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000715#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenk7e780362004-04-08 22:31:29 +0000716 /* flash mapped at end of memory map */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200717 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000718#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
719 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
720#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200721#endif /* !CONFIG_SYS_NO_FLASH */
wdenkfe8c2802002-11-03 00:38:21 +0000722
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000723 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000724
725 /* initialize higher level parts of CPU like time base and timers */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000726 cpu_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000727
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000728 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000729
wdenkfe8c2802002-11-03 00:38:21 +0000730#ifdef CONFIG_SPI
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000731#if !defined(CONFIG_ENV_IS_IN_EEPROM)
732 spi_init_f();
733#endif
734 spi_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000735#endif
736
Jon Loeliger7def6b32007-07-09 18:02:11 -0500737#if defined(CONFIG_CMD_NAND)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000738 WATCHDOG_RESET();
739 puts("NAND: ");
Stefan Roese887e2ec2006-09-07 11:51:23 +0200740 nand_init(); /* go init the NAND */
741#endif
742
Terry Lva8060352010-05-17 10:57:01 +0800743#ifdef CONFIG_GENERIC_MMC
744/*
745 * MMC initialization is called before relocating env.
746 * Thus It is required that operations like pin multiplexer
747 * be put in board_init.
748 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000749 WATCHDOG_RESET();
750 puts("MMC: ");
751 mmc_initialize(bd);
Terry Lva8060352010-05-17 10:57:01 +0800752#endif
753
wdenkfe8c2802002-11-03 00:38:21 +0000754 /* relocate environment function pointers etc. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000755 env_relocate();
wdenkfe8c2802002-11-03 00:38:21 +0000756
757 /*
Kumar Galaf9a33f12011-02-02 11:23:50 -0600758 * after non-volatile devices & environment is setup and cpu code have
759 * another round to deal with any initialization that might require
760 * full access to the environment or loading of some image (firmware)
761 * from a non-volatile device
762 */
763 cpu_secondary_init_r();
764
765 /*
wdenkfe8c2802002-11-03 00:38:21 +0000766 * Fill in missing fields of bd_info.
wdenk8bde7f72003-06-27 21:31:46 +0000767 * We do this here, where we have "normal" access to the
768 * environment; we used to do this still running from ROM,
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200769 * where had to use getenv_f(), which can be pretty slow when
wdenk8bde7f72003-06-27 21:31:46 +0000770 * the environment is in EEPROM.
wdenkfe8c2802002-11-03 00:38:21 +0000771 */
wdenk7abf0c52004-04-18 21:45:42 +0000772
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200773#if defined(CONFIG_SYS_EXTBDINFO)
wdenk7abf0c52004-04-18 21:45:42 +0000774#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
775#if defined(CONFIG_I2CFAST)
776 /*
777 * set bi_iic_fast for linux taking environment variable
778 * "i2cfast" into account
779 */
780 {
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600781 if (getenv_yesno("i2cfast") == 1) {
wdenk7abf0c52004-04-18 21:45:42 +0000782 bd->bi_iic_fast[0] = 1;
783 bd->bi_iic_fast[1] = 1;
wdenk7abf0c52004-04-18 21:45:42 +0000784 }
785 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000786#endif /* CONFIG_I2CFAST */
787#endif /* CONFIG_405GP, CONFIG_405EP */
788#endif /* CONFIG_SYS_EXTBDINFO */
wdenk7abf0c52004-04-18 21:45:42 +0000789
Wolfgang Denk9045f332007-06-08 10:24:58 +0200790#if defined(CONFIG_SC3)
Heiko Schocherca43ba12007-01-11 15:44:44 +0100791 sc3_read_eeprom();
792#endif
Haiying Wangd59feff2008-01-16 17:12:12 -0500793
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000794#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
Haiying Wangd59feff2008-01-16 17:12:12 -0500795 mac_read_from_eeprom();
796#endif
797
wdenkfe8c2802002-11-03 00:38:21 +0000798#ifdef CONFIG_HERMES
799 if ((gd->board_type >> 16) == 2)
800 bd->bi_ethspeed = gd->board_type & 0xFFFF;
801 else
802 bd->bi_ethspeed = 0xFFFF;
803#endif
804
Stefan Roese02a301c2009-02-25 12:11:15 +0100805#ifdef CONFIG_CMD_NET
Mike Frysingereb85aa52009-02-11 20:07:19 -0500806 /* kept around for legacy kernels only ... ignore the next section */
807 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
wdenke2ffd592004-12-31 09:32:47 +0000808#ifdef CONFIG_HAS_ETH1
Mike Frysingereb85aa52009-02-11 20:07:19 -0500809 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
wdenkfe8c2802002-11-03 00:38:21 +0000810#endif
wdenke2ffd592004-12-31 09:32:47 +0000811#ifdef CONFIG_HAS_ETH2
Mike Frysingereb85aa52009-02-11 20:07:19 -0500812 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
wdenkfe8c2802002-11-03 00:38:21 +0000813#endif
wdenke2ffd592004-12-31 09:32:47 +0000814#ifdef CONFIG_HAS_ETH3
Mike Frysingereb85aa52009-02-11 20:07:19 -0500815 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
wdenkba56f622004-02-06 23:19:44 +0000816#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400817#ifdef CONFIG_HAS_ETH4
Mike Frysingereb85aa52009-02-11 20:07:19 -0500818 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400819#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400820#ifdef CONFIG_HAS_ETH5
Mike Frysingereb85aa52009-02-11 20:07:19 -0500821 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400822#endif
Stefan Roese02a301c2009-02-25 12:11:15 +0100823#endif /* CONFIG_CMD_NET */
richardretanubunc68a05f2008-09-29 18:28:23 -0400824
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000825 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000826
Andre Schwarz76221a62010-10-05 11:59:31 +0200827#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000828 /*
829 * Do pci configuration
830 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000831 pci_init();
wdenkfe8c2802002-11-03 00:38:21 +0000832#endif
833
834/** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200835 /* Initialize stdio devices */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000836 stdio_init();
wdenkfe8c2802002-11-03 00:38:21 +0000837
wdenk27b207f2003-07-24 23:38:38 +0000838 /* Initialize the jump table for applications */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000839 jumptable_init();
wdenkfe8c2802002-11-03 00:38:21 +0000840
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100841#if defined(CONFIG_API)
842 /* Initialize API */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000843 api_init();
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100844#endif
845
wdenkfe8c2802002-11-03 00:38:21 +0000846 /* Initialize the console (after the relocation and devices init) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000847 console_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000848
Peter Tyser3a8f28d2009-09-16 22:03:07 -0500849#if defined(CONFIG_MISC_INIT_R)
wdenkfe8c2802002-11-03 00:38:21 +0000850 /* miscellaneous platform dependent initialisations */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000851 misc_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000852#endif
853
854#ifdef CONFIG_HERMES
855 if (bd->bi_ethspeed != 0xFFFF)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000856 hermes_start_lxt980((int) bd->bi_ethspeed);
wdenkfe8c2802002-11-03 00:38:21 +0000857#endif
858
Jon Loeliger7def6b32007-07-09 18:02:11 -0500859#if defined(CONFIG_CMD_KGDB)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000860 WATCHDOG_RESET();
861 puts("KGDB: ");
862 kgdb_init();
wdenkfe8c2802002-11-03 00:38:21 +0000863#endif
864
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000865 debug("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000866
867 /*
868 * Enable Interrupts
869 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000870 interrupt_init();
wdenkfe8c2802002-11-03 00:38:21 +0000871
Heiko Schocher566a4942007-06-22 19:11:54 +0200872#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000873 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
wdenkfe8c2802002-11-03 00:38:21 +0000874#endif
875
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000876 udelay(20);
wdenkfe8c2802002-11-03 00:38:21 +0000877
wdenkfe8c2802002-11-03 00:38:21 +0000878 /* Initialize from environment */
Simon Glass12725922011-10-13 14:43:12 +0000879 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000880
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000881 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000882
Jon Loeliger7def6b32007-07-09 18:02:11 -0500883#if defined(CONFIG_CMD_SCSI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000884 WATCHDOG_RESET();
885 puts("SCSI: ");
886 scsi_init();
wdenkfe8c2802002-11-03 00:38:21 +0000887#endif
888
Jon Loeliger7def6b32007-07-09 18:02:11 -0500889#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000890 WATCHDOG_RESET();
891 puts("DOC: ");
892 doc_init();
wdenkfe8c2802002-11-03 00:38:21 +0000893#endif
894
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200895#ifdef CONFIG_BITBANGMII
896 bb_miiphy_init();
897#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -0500898#if defined(CONFIG_CMD_NET)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000899 WATCHDOG_RESET();
900 puts("Net: ");
901 eth_initialize(bd);
wdenkfe8c2802002-11-03 00:38:21 +0000902#endif
903
Peter Tyser004eca02009-09-16 22:03:08 -0500904#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000905 WATCHDOG_RESET();
906 debug("Reset Ethernet PHY\n");
907 reset_phy();
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200908#endif
909
wdenkfe8c2802002-11-03 00:38:21 +0000910#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000911 post_run(NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000912#endif
913
Jon Loeliger7def6b32007-07-09 18:02:11 -0500914#if defined(CONFIG_CMD_PCMCIA) \
915 && !defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000916 WATCHDOG_RESET();
917 puts("PCMCIA:");
918 pcmcia_init();
wdenkfe8c2802002-11-03 00:38:21 +0000919#endif
920
Jon Loeliger7def6b32007-07-09 18:02:11 -0500921#if defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000922 WATCHDOG_RESET();
923#ifdef CONFIG_IDE_8xx_PCCARD
924 puts("PCMCIA:");
925#else
926 puts("IDE: ");
wdenkfe8c2802002-11-03 00:38:21 +0000927#endif
Heiko Schocherca43ba12007-01-11 15:44:44 +0100928#if defined(CONFIG_START_IDE)
929 if (board_start_ide())
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000930 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100931#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000932 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100933#endif
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500934#endif
wdenkfe8c2802002-11-03 00:38:21 +0000935
936#ifdef CONFIG_LAST_STAGE_INIT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000937 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000938 /*
939 * Some parts can be only initialized if all others (like
940 * Interrupts) are up and running (i.e. the PC-style ISA
941 * keyboard).
942 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000943 last_stage_init();
wdenkfe8c2802002-11-03 00:38:21 +0000944#endif
945
Jon Loeliger7def6b32007-07-09 18:02:11 -0500946#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000947 WATCHDOG_RESET();
948 bedbug_init();
wdenkfe8c2802002-11-03 00:38:21 +0000949#endif
950
wdenk228f29a2002-12-08 09:53:23 +0000951#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000952 /*
953 * Export available size of memory for Linux,
954 * taking into account the protected RAM at top of memory
955 */
956 {
Simon Glass12725922011-10-13 14:43:12 +0000957 ulong pram = 0;
Simon Glassd01b1762012-01-05 17:54:57 +0000958 char memsz[32];
wdenkfe8c2802002-11-03 00:38:21 +0000959
Simon Glass12725922011-10-13 14:43:12 +0000960#ifdef CONFIG_PRAM
961 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenk228f29a2002-12-08 09:53:23 +0000962#endif
963#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100964#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000965 /* Also take the logbuffer into account (pram is in kB) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000966 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
wdenk228f29a2002-12-08 09:53:23 +0000967#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100968#endif
Valentin Longchamp13287e32013-10-18 11:47:14 +0200969 sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
Simon Glassd01b1762012-01-05 17:54:57 +0000970 setenv("mem", memsz);
wdenkfe8c2802002-11-03 00:38:21 +0000971 }
972#endif
973
wdenk1c437712004-01-16 00:30:56 +0000974#ifdef CONFIG_PS2KBD
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000975 puts("PS/2: ");
wdenk1c437712004-01-16 00:30:56 +0000976 kbd_init();
977#endif
978
wdenk4532cb62003-04-27 22:52:51 +0000979#ifdef CONFIG_MODEM_SUPPORT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000980 {
981 extern int do_mdm_init;
982
983 do_mdm_init = gd->do_mdm_init;
984 }
wdenk4532cb62003-04-27 22:52:51 +0000985#endif
986
wdenkfe8c2802002-11-03 00:38:21 +0000987 /* Initialization complete - start the monitor */
988
989 /* main_loop() can return to retry autoboot, if so just run it again. */
990 for (;;) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000991 WATCHDOG_RESET();
992 main_loop();
wdenkfe8c2802002-11-03 00:38:21 +0000993 }
994
995 /* NOTREACHED - no way out of command loop except booting */
996}
997
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000998#if 0 /* We could use plain global data, but the resulting code is bigger */
wdenkfe8c2802002-11-03 00:38:21 +0000999/*
1000 * Pointer to initial global data area
1001 *
1002 * Here we initialize it.
1003 */
1004#undef XTRN_DECLARE_GLOBAL_DATA_PTR
1005#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001006DECLARE_GLOBAL_DATA_PTR =
1007 (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
1008#endif /* 0 */
wdenkfe8c2802002-11-03 00:38:21 +00001009
1010/************************************************************************/