blob: 6eaab882437dda464db83c2943669203a26f2998 [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{
Boschung, Rainer919e0552014-06-03 09:05:15 +0200229#if defined(CONFIG_MPC85xx)
230 init_85xx_watchdog();
231#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000232 puts(" Watchdog enabled\n");
233 WATCHDOG_RESET();
234 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000235}
wdenkfe8c2802002-11-03 00:38:21 +0000236
Simon Glassa6741bc2013-03-05 14:39:42 +0000237int init_func_watchdog_reset(void)
wdenkfe8c2802002-11-03 00:38:21 +0000238{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000239 WATCHDOG_RESET();
240 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000241}
wdenkfe8c2802002-11-03 00:38:21 +0000242#endif /* CONFIG_WATCHDOG */
243
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000244/*
245 * Initialization sequence
wdenkfe8c2802002-11-03 00:38:21 +0000246 */
247
Kim Phillips20051f22012-10-29 13:34:29 +0000248static init_fnc_t *init_sequence[] = {
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530249#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
250 probecpu,
251#endif
Anton Vorontsov91525c62009-10-12 23:55:39 +0400252#if defined(CONFIG_BOARD_EARLY_INIT_F)
253 board_early_init_f,
254#endif
wdenk66ca92a2004-09-28 17:59:53 +0000255#if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
wdenkfe8c2802002-11-03 00:38:21 +0000256 get_clocks, /* get CPU and bus clocks (etc.) */
Markus Klotzbuecher090eb732006-07-12 15:26:01 +0200257#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
258 && !defined(CONFIG_TQM885D)
wdenke9132ea2004-04-24 23:23:30 +0000259 adjust_sdram_tbs_8xx,
260#endif
wdenkfe8c2802002-11-03 00:38:21 +0000261 init_timebase,
wdenkc178d3d2004-01-24 20:25:54 +0000262#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200263#ifdef CONFIG_SYS_ALLOC_DPRAM
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500264#if !defined(CONFIG_CPM2)
wdenkfe8c2802002-11-03 00:38:21 +0000265 dpram_init,
266#endif
wdenk7aa78612003-05-03 15:50:43 +0000267#endif
wdenkfe8c2802002-11-03 00:38:21 +0000268#if defined(CONFIG_BOARD_POSTCLK_INIT)
269 board_postclk_init,
270#endif
271 env_init,
wdenk66ca92a2004-09-28 17:59:53 +0000272#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000273 /* get CPU and bus clocks according to the environment variable */
274 get_clocks_866,
275 /* adjust sdram refresh rate according to the new clock */
276 sdram_adjust_866,
wdenkc178d3d2004-01-24 20:25:54 +0000277 init_timebase,
278#endif
wdenkfe8c2802002-11-03 00:38:21 +0000279 init_baudrate,
280 serial_init,
281 console_init_f,
282 display_options,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900283#if defined(CONFIG_MPC8260)
wdenkfe8c2802002-11-03 00:38:21 +0000284 prt_8260_rsr,
285 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900286#endif /* CONFIG_MPC8260 */
Peter Tyser0f898602009-05-22 17:23:24 -0500287#if defined(CONFIG_MPC83xx)
Dave Liu9be39a62007-06-25 10:41:56 +0800288 prt_83xx_rsr,
289#endif
wdenkfe8c2802002-11-03 00:38:21 +0000290 checkcpu,
wdenkcbd8a352004-02-24 02:00:03 +0000291#if defined(CONFIG_MPC5xxx)
wdenk945af8d2003-07-16 21:53:01 +0000292 prt_mpc5xxx_clks,
wdenkcbd8a352004-02-24 02:00:03 +0000293#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000294 checkboard,
295 INIT_FUNC_WATCHDOG_INIT
wdenkc837dcb2004-01-20 23:12:12 +0000296#if defined(CONFIG_MISC_INIT_F)
wdenkfe8c2802002-11-03 00:38:21 +0000297 misc_init_f,
298#endif
299 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100300#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
wdenkfe8c2802002-11-03 00:38:21 +0000301 init_func_i2c,
302#endif
Ben Warren04a9e112008-01-16 22:37:35 -0500303#if defined(CONFIG_HARD_SPI)
304 init_func_spi,
305#endif
wdenk4532cb62003-04-27 22:52:51 +0000306#ifdef CONFIG_POST
307 post_init_f,
308#endif
Simon Glass6f6430d2013-03-11 14:30:37 +0000309 INIT_FUNC_WATCHDOG_RESET
310 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200311#if defined(CONFIG_SYS_DRAM_TEST)
wdenkfe8c2802002-11-03 00:38:21 +0000312 testdram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200313#endif /* CONFIG_SYS_DRAM_TEST */
wdenkfe8c2802002-11-03 00:38:21 +0000314 INIT_FUNC_WATCHDOG_RESET
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000315 NULL, /* Terminate this list */
wdenkfe8c2802002-11-03 00:38:21 +0000316};
317
Kim Phillips20051f22012-10-29 13:34:29 +0000318static int __fixup_cpu(void)
York Sun123bd962012-08-17 08:20:22 +0000319{
320 return 0;
321}
322
323int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
324
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000325/*
wdenkfe8c2802002-11-03 00:38:21 +0000326 * This is the first part of the initialization sequence that is
327 * implemented in C, but still running from ROM.
328 *
329 * The main purpose is to provide a (serial) console interface as
330 * soon as possible (so we can see any error messages), and to
331 * initialize the RAM so that we can relocate the monitor code to
332 * RAM.
333 *
334 * Be aware of the restrictions: global data is read-only, BSS is not
335 * initialized, and stack space is limited to a few kB.
wdenkfe8c2802002-11-03 00:38:21 +0000336 */
337
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000338void board_init_f(ulong bootflag)
wdenkfe8c2802002-11-03 00:38:21 +0000339{
wdenkfe8c2802002-11-03 00:38:21 +0000340 bd_t *bd;
341 ulong len, addr, addr_sp;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200342 ulong *s;
wdenkfe8c2802002-11-03 00:38:21 +0000343 gd_t *id;
344 init_fnc_t **init_fnc_ptr;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000345
wdenkfe8c2802002-11-03 00:38:21 +0000346#ifdef CONFIG_PRAM
wdenkfe8c2802002-11-03 00:38:21 +0000347 ulong reg;
wdenkfe8c2802002-11-03 00:38:21 +0000348#endif
Tang Yuantianaade2002014-04-17 15:33:46 +0800349#ifdef CONFIG_DEEP_SLEEP
350 const ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
351 struct ccsr_scfg *scfg = (void *)CONFIG_SYS_MPC85xx_SCFG;
352 u32 start_addr;
353 typedef void (*func_t)(void);
354 func_t kernel_resume;
355#endif
wdenkfe8c2802002-11-03 00:38:21 +0000356
357 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200358 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk93f6a672004-07-01 20:28:03 +0000359 /* compiler optimization barrier needed for GCC >= 3.4 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000360 __asm__ __volatile__("":::"memory");
wdenkfe8c2802002-11-03 00:38:21 +0000361
Detlev Zundel82826d52010-01-22 14:47:59 +0100362#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
363 !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
364 !defined(CONFIG_MPC86xx)
wdenkfe8c2802002-11-03 00:38:21 +0000365 /* Clear initial global data */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000366 memset((void *) gd, 0, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000367#endif
368
Tang Yuantian30675472014-07-23 17:27:52 +0800369 gd->flags = bootflag;
370
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000371 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
372 if ((*init_fnc_ptr) () != 0)
373 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000374
Tang Yuantianaade2002014-04-17 15:33:46 +0800375#ifdef CONFIG_DEEP_SLEEP
376 /* Jump to kernel in deep sleep case */
377 if (in_be32(&gur->scrtsr[0]) & (1 << 3)) {
Tang Yuantian7cb72722014-07-04 17:39:26 +0800378 l2cache_init();
379#if defined(CONFIG_RAMBOOT_PBL)
380 disable_cpc_sram();
381#endif
382 enable_cpc();
Tang Yuantianaade2002014-04-17 15:33:46 +0800383 start_addr = in_be32(&scfg->sparecr[1]);
384 kernel_resume = (func_t)start_addr;
385 kernel_resume();
386 }
387#endif
388
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000389#ifdef CONFIG_POST
390 post_bootmode_init();
Kim Phillips20051f22012-10-29 13:34:29 +0000391 post_run(NULL, POST_ROM | post_bootmode_get(NULL));
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000392#endif
393
394 WATCHDOG_RESET();
395
wdenkfe8c2802002-11-03 00:38:21 +0000396 /*
397 * Now that we have DRAM mapped and working, we can
398 * relocate the code and continue running from DRAM.
399 *
400 * Reserve memory at end of RAM for (top down in that order):
Stefan Roese14f73ca2008-03-26 10:14:11 +0100401 * - area that won't get touched by U-Boot and Linux (optional)
wdenk8bde7f72003-06-27 21:31:46 +0000402 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000403 * - protected RAM
404 * - LCD framebuffer
405 * - monitor code
406 * - board info struct
407 */
Simon Glass3929fb02013-03-14 06:54:53 +0000408 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000409
Stefan Roese14f73ca2008-03-26 10:14:11 +0100410 /*
411 * Subtract specified amount of memory to hide so that it won't
412 * get "touched" at all by U-Boot. By fixing up gd->ram_size
413 * the Linux kernel should now get passed the now "corrected"
414 * memory size and won't touch it either. This should work
415 * for arch/ppc and arch/powerpc. Only Linux board ports in
416 * arch/powerpc with bootwrapper support, that recalculate the
417 * memory size from the SDRAM controller setup will have to
418 * get fixed.
419 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200420 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
Stefan Roese14f73ca2008-03-26 10:14:11 +0100421
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200422 addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
wdenkfe8c2802002-11-03 00:38:21 +0000423
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500424#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
425 /*
426 * We need to make sure the location we intend to put secondary core
427 * boot code is reserved and not used by any part of u-boot
Wolfgang Denkc0a14ae2009-04-05 00:27:57 +0200428 */
York Suneb539412012-10-08 07:44:25 +0000429 if (addr > determine_mp_bootpg(NULL)) {
430 addr = determine_mp_bootpg(NULL);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000431 debug("Reserving MP boot page to %08lx\n", addr);
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500432 }
433#endif
434
wdenk228f29a2002-12-08 09:53:23 +0000435#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100436#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000437 /* reserve kernel log buffer */
438 addr -= (LOGBUFF_RESERVE);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000439 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
440 addr);
wdenk228f29a2002-12-08 09:53:23 +0000441#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100442#endif
wdenk228f29a2002-12-08 09:53:23 +0000443
wdenkfe8c2802002-11-03 00:38:21 +0000444#ifdef CONFIG_PRAM
445 /*
446 * reserve protected RAM
447 */
Simon Glass12725922011-10-13 14:43:12 +0000448 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000449 addr -= (reg << 10); /* size is in kB */
Simon Glass12725922011-10-13 14:43:12 +0000450 debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000451#endif /* CONFIG_PRAM */
452
453 /* round down to next 4 kB limit */
454 addr &= ~(4096 - 1);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000455 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000456
457#ifdef CONFIG_LCD
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000458#ifdef CONFIG_FB_ADDR
459 gd->fb_base = CONFIG_FB_ADDR;
460#else
wdenkfe8c2802002-11-03 00:38:21 +0000461 /* reserve memory for LCD display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000462 addr = lcd_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000463 gd->fb_base = addr;
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000464#endif /* CONFIG_FB_ADDR */
wdenkfe8c2802002-11-03 00:38:21 +0000465#endif /* CONFIG_LCD */
466
467#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
468 /* reserve memory for video display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000469 addr = video_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000470 gd->fb_base = addr;
471#endif /* CONFIG_VIDEO */
472
473 /*
474 * reserve memory for U-Boot code, data & bss
wdenk682011f2003-06-03 23:54:09 +0000475 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000476 */
477 addr -= len;
wdenk682011f2003-06-03 23:54:09 +0000478 addr &= ~(4096 - 1);
Wolfgang Denk7d314992005-10-05 00:00:54 +0200479#ifdef CONFIG_E500
480 /* round down to next 64 kB limit so that IVPR stays aligned */
481 addr &= ~(65536 - 1);
482#endif
wdenkfe8c2802002-11-03 00:38:21 +0000483
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000484 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000485
486 /*
487 * reserve memory for malloc() arena
488 */
489 addr_sp = addr - TOTAL_MALLOC_LEN;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000490 debug("Reserving %dk for malloc() at: %08lx\n",
491 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000492
493 /*
494 * (permanently) allocate a Board Info struct
495 * and a permanent copy of the "global" data
496 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000497 addr_sp -= sizeof(bd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000498 bd = (bd_t *) addr_sp;
Peter Tysera1c48642010-09-14 19:13:51 -0500499 memset(bd, 0, sizeof(bd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000500 gd->bd = bd;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000501 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
502 sizeof(bd_t), addr_sp);
503 addr_sp -= sizeof(gd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000504 id = (gd_t *) addr_sp;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000505 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
506 sizeof(gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000507
508 /*
509 * Finally, we set up a new (bigger) stack.
510 *
511 * Leave some safety gap for SP, force alignment on 16 byte boundary
512 * Clear initial stack frame
513 */
514 addr_sp -= 16;
515 addr_sp &= ~0xF;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000516 s = (ulong *) addr_sp;
Joakim Tjernlund7de8a712012-07-23 10:58:03 +0000517 *s = 0; /* Terminate back chain */
518 *++s = 0; /* NULL return address */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000519 debug("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000520
521 /*
522 * Save local variables to board info struct
523 */
524
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000525 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
526 bd->bi_memsize = gd->ram_size; /* size in bytes */
wdenkfe8c2802002-11-03 00:38:21 +0000527
Wolfgang Denk36116652010-08-11 09:38:31 +0200528#ifdef CONFIG_SYS_SRAM_BASE
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000529 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
530 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
wdenkfe8c2802002-11-03 00:38:21 +0000531#endif
532
Masahiro Yamada58dac322014-03-05 17:40:10 +0900533#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Jon Loeligerdebb7352006-04-26 17:58:56 -0500534 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200535 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
wdenkfe8c2802002-11-03 00:38:21 +0000536#endif
wdenkcbd8a352004-02-24 02:00:03 +0000537#if defined(CONFIG_MPC5xxx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200538 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenk945af8d2003-07-16 21:53:01 +0000539#endif
Peter Tyser0f898602009-05-22 17:23:24 -0500540#if defined(CONFIG_MPC83xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200541 bd->bi_immrbar = CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500542#endif
wdenkfe8c2802002-11-03 00:38:21 +0000543
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000544 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000545 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
546 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500547#if defined(CONFIG_CPM2)
Simon Glass748cd052012-12-13 20:48:46 +0000548 bd->bi_cpmfreq = gd->arch.cpm_clk;
Simon Glass1206c182012-12-13 20:48:44 +0000549 bd->bi_brgfreq = gd->arch.brg_clk;
Simon Glass748cd052012-12-13 20:48:46 +0000550 bd->bi_sccfreq = gd->arch.scc_clk;
551 bd->bi_vco = gd->arch.vco_out;
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500552#endif /* CONFIG_CPM2 */
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100553#if defined(CONFIG_MPC512X)
Simon Glassfefb0982012-12-13 20:48:54 +0000554 bd->bi_ipsfreq = gd->arch.ips_clk;
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100555#endif /* CONFIG_MPC512X */
wdenkcbd8a352004-02-24 02:00:03 +0000556#if defined(CONFIG_MPC5xxx)
Simon Glassb2877492012-12-13 20:48:53 +0000557 bd->bi_ipbfreq = gd->arch.ipb_clk;
wdenk945af8d2003-07-16 21:53:01 +0000558 bd->bi_pcifreq = gd->pci_clk;
wdenkcbd8a352004-02-24 02:00:03 +0000559#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000560
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200561#ifdef CONFIG_SYS_EXTBDINFO
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000562 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
563 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
564 sizeof(bd->bi_r_version));
wdenkfe8c2802002-11-03 00:38:21 +0000565
566 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
567 bd->bi_plb_busfreq = gd->bus_clk;
Stefan Roese343c48b2007-05-11 12:01:06 +0200568#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
569 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
570 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000571 bd->bi_pci_busfreq = get_PCI_freq();
572 bd->bi_opbfreq = get_OPB_freq();
Michal Simek9fea65a2008-06-24 09:54:09 +0200573#elif defined(CONFIG_XILINX_405)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000574 bd->bi_pci_busfreq = get_PCI_freq();
wdenkfe8c2802002-11-03 00:38:21 +0000575#endif
576#endif
577
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000578 debug("New Stack Pointer is: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000579
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000580 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000581
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000582 gd->relocaddr = addr; /* Store relocation addr, useful for debug */
Richard Retanubun4b993272010-01-15 10:06:06 -0500583
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000584 memcpy(id, (void *) gd, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000585
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000586 relocate_code(addr_sp, id, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000587
588 /* NOTREACHED - relocate_code() does not return */
589}
590
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000591/*
wdenkfe8c2802002-11-03 00:38:21 +0000592 * This is the next part if the initialization sequence: we are now
593 * running from RAM and have a "normal" C environment, i. e. global
594 * data can be written, BSS has been cleared, the stack size in not
595 * that critical any more, etc.
wdenkfe8c2802002-11-03 00:38:21 +0000596 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000597void board_init_r(gd_t *id, ulong dest_addr)
wdenkfe8c2802002-11-03 00:38:21 +0000598{
wdenkfe8c2802002-11-03 00:38:21 +0000599 bd_t *bd;
Peter Tysera483a162009-08-21 23:05:20 -0500600 ulong malloc_start;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000601
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200602#ifndef CONFIG_SYS_NO_FLASH
wdenkfe8c2802002-11-03 00:38:21 +0000603 ulong flash_size;
604#endif
605
606 gd = id; /* initialize RAM version of global data */
607 bd = gd->bd;
608
609 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
Grant Likelyf82b3b62007-07-03 00:34:19 -0600610
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500611 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysera483a162009-08-21 23:05:20 -0500612 malloc_start = dest_addr - TOTAL_MALLOC_LEN;
Kumar Gala13d46ab2009-09-01 21:07:08 -0500613
Peter Tyserf9476902009-12-15 12:10:47 -0600614#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
615 /*
Simon Glass67ac13b2012-12-13 20:48:48 +0000616 * The gd->arch.cpu pointer is set to an address in flash before
617 * relocation. We need to update it to point to the same CPU entry
618 * in RAM.
Peter Tyserf9476902009-12-15 12:10:47 -0600619 */
Simon Glass67ac13b2012-12-13 20:48:48 +0000620 gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
York Sun123bd962012-08-17 08:20:22 +0000621
622 /*
623 * If we didn't know the cpu mask & # cores, we can save them of
624 * now rather than 'computing' them constantly
625 */
626 fixup_cpu();
Peter Tyserf9476902009-12-15 12:10:47 -0600627#endif
628
Kumar Galaa55bb832010-11-29 14:32:11 -0600629#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
630 /*
631 * Some systems need to relocate the env_addr pointer early because the
632 * location it points to will get invalidated before env_relocate is
633 * called. One example is on systems that might use a L2 or L3 cache
634 * in SRAM mode and initialize that cache from SRAM mode back to being
635 * a cache in cpu_init_r.
636 */
637 gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
638#endif
639
Marian Balakowiczbb105f22006-06-30 15:27:09 +0200640 serial_initialize();
wdenkfe8c2802002-11-03 00:38:21 +0000641
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000642 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000643
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000644 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000645
Becky Bruced025aa42008-10-31 17:14:39 -0500646 /*
647 * Setup trap handlers
648 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000649 trap_init(dest_addr);
Becky Bruced025aa42008-10-31 17:14:39 -0500650
Becky Brucec9315e62009-02-03 18:10:52 -0600651#ifdef CONFIG_ADDR_MAP
Kumar Galaecf5b982008-12-16 14:59:20 -0600652 init_addr_map();
653#endif
654
wdenkc837dcb2004-01-20 23:12:12 +0000655#if defined(CONFIG_BOARD_EARLY_INIT_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000656 board_early_init_r();
wdenkc837dcb2004-01-20 23:12:12 +0000657#endif
658
wdenk3b57fe02003-05-30 12:48:29 +0000659 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkfe8c2802002-11-03 00:38:21 +0000660
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000661 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000662
wdenk56f94be2002-11-05 16:35:14 +0000663#ifdef CONFIG_LOGBUFFER
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000664 logbuff_init_ptrs();
wdenk56f94be2002-11-05 16:35:14 +0000665#endif
wdenkfe8c2802002-11-03 00:38:21 +0000666#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000667 post_output_backlog();
wdenkfe8c2802002-11-03 00:38:21 +0000668#endif
669
670 WATCHDOG_RESET();
671
Kim Phillips1a2e2032010-04-20 19:37:54 -0500672#if defined(CONFIG_SYS_DELAYED_ICACHE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000673 icache_enable(); /* it's time to enable the instruction cache */
wdenkfe8c2802002-11-03 00:38:21 +0000674#endif
675
Wolfgang Denk9c673522009-07-26 23:28:02 +0200676#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
677 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
wdenk42d1f032003-10-15 23:53:47 +0000678#endif
679
Andre Schwarz76221a62010-10-05 11:59:31 +0200680#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000681 /*
Andre Schwarz76221a62010-10-05 11:59:31 +0200682 * Do early PCI configuration _before_ the flash gets initialised,
683 * because PCU ressources are crucial for flash access on some boards.
wdenkfe8c2802002-11-03 00:38:21 +0000684 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000685 pci_init();
wdenk3bac3512003-03-12 10:41:04 +0000686#endif
Wolfgang Denk57d6c582010-11-23 23:17:18 +0100687#if defined(CONFIG_WINBOND_83C553)
wdenkfe8c2802002-11-03 00:38:21 +0000688 /*
689 * Initialise the ISA bridge
690 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000691 initialise_w83c553f();
wdenkfe8c2802002-11-03 00:38:21 +0000692#endif
693
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000694 asm("sync ; isync");
wdenkfe8c2802002-11-03 00:38:21 +0000695
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000696 mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
Stefan Roesec790b042009-05-11 15:50:12 +0200697
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200698#if !defined(CONFIG_SYS_NO_FLASH)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000699 puts("Flash: ");
wdenkfe8c2802002-11-03 00:38:21 +0000700
John Schmollerc62491d2010-09-29 14:05:44 -0500701 if (board_flash_wp_on()) {
702 printf("Uninitialized - Write Protect On\n");
703 /* Since WP is on, we can't find real size. Set to 0 */
704 flash_size = 0;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000705 } else if ((flash_size = flash_init()) > 0) {
706#ifdef CONFIG_SYS_FLASH_CHECKSUM
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000707 print_size(flash_size, "");
wdenkfe8c2802002-11-03 00:38:21 +0000708 /*
709 * Compute and print flash CRC if flashchecksum is set to 'y'
710 *
711 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
712 */
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600713 if (getenv_yesno("flashchecksum") == 1) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000714 printf(" CRC: %08X",
715 crc32(0,
716 (const unsigned char *)
717 CONFIG_SYS_FLASH_BASE, flash_size)
718 );
wdenkfe8c2802002-11-03 00:38:21 +0000719 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000720 putc('\n');
721#else /* !CONFIG_SYS_FLASH_CHECKSUM */
722 print_size(flash_size, "\n");
723#endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000724 } else {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000725 puts(failed);
726 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000727 }
728
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000729 /* update start of FLASH memory */
730 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
731 /* size of FLASH memory (final value) */
732 bd->bi_flashsize = flash_size;
Heiko Schocherfa230442006-12-21 17:17:02 +0100733
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200734#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
Heiko Schocherfa230442006-12-21 17:17:02 +0100735 /* Make a update of the Memctrl. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000736 update_flash_size(flash_size);
Heiko Schocherfa230442006-12-21 17:17:02 +0100737#endif
738
739
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000740#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenk7e780362004-04-08 22:31:29 +0000741 /* flash mapped at end of memory map */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200742 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000743#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
744 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
745#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200746#endif /* !CONFIG_SYS_NO_FLASH */
wdenkfe8c2802002-11-03 00:38:21 +0000747
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000748 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000749
750 /* initialize higher level parts of CPU like time base and timers */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000751 cpu_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000752
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000753 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000754
wdenkfe8c2802002-11-03 00:38:21 +0000755#ifdef CONFIG_SPI
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000756#if !defined(CONFIG_ENV_IS_IN_EEPROM)
757 spi_init_f();
758#endif
759 spi_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000760#endif
761
Jon Loeliger7def6b32007-07-09 18:02:11 -0500762#if defined(CONFIG_CMD_NAND)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000763 WATCHDOG_RESET();
764 puts("NAND: ");
Stefan Roese887e2ec2006-09-07 11:51:23 +0200765 nand_init(); /* go init the NAND */
766#endif
767
Terry Lva8060352010-05-17 10:57:01 +0800768#ifdef CONFIG_GENERIC_MMC
769/*
770 * MMC initialization is called before relocating env.
771 * Thus It is required that operations like pin multiplexer
772 * be put in board_init.
773 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000774 WATCHDOG_RESET();
775 puts("MMC: ");
776 mmc_initialize(bd);
Terry Lva8060352010-05-17 10:57:01 +0800777#endif
778
wdenkfe8c2802002-11-03 00:38:21 +0000779 /* relocate environment function pointers etc. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000780 env_relocate();
wdenkfe8c2802002-11-03 00:38:21 +0000781
782 /*
Kumar Galaf9a33f12011-02-02 11:23:50 -0600783 * after non-volatile devices & environment is setup and cpu code have
784 * another round to deal with any initialization that might require
785 * full access to the environment or loading of some image (firmware)
786 * from a non-volatile device
787 */
788 cpu_secondary_init_r();
789
790 /*
wdenkfe8c2802002-11-03 00:38:21 +0000791 * Fill in missing fields of bd_info.
wdenk8bde7f72003-06-27 21:31:46 +0000792 * We do this here, where we have "normal" access to the
793 * environment; we used to do this still running from ROM,
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200794 * where had to use getenv_f(), which can be pretty slow when
wdenk8bde7f72003-06-27 21:31:46 +0000795 * the environment is in EEPROM.
wdenkfe8c2802002-11-03 00:38:21 +0000796 */
wdenk7abf0c52004-04-18 21:45:42 +0000797
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200798#if defined(CONFIG_SYS_EXTBDINFO)
wdenk7abf0c52004-04-18 21:45:42 +0000799#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
800#if defined(CONFIG_I2CFAST)
801 /*
802 * set bi_iic_fast for linux taking environment variable
803 * "i2cfast" into account
804 */
805 {
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600806 if (getenv_yesno("i2cfast") == 1) {
wdenk7abf0c52004-04-18 21:45:42 +0000807 bd->bi_iic_fast[0] = 1;
808 bd->bi_iic_fast[1] = 1;
wdenk7abf0c52004-04-18 21:45:42 +0000809 }
810 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000811#endif /* CONFIG_I2CFAST */
812#endif /* CONFIG_405GP, CONFIG_405EP */
813#endif /* CONFIG_SYS_EXTBDINFO */
wdenk7abf0c52004-04-18 21:45:42 +0000814
Wolfgang Denk9045f332007-06-08 10:24:58 +0200815#if defined(CONFIG_SC3)
Heiko Schocherca43ba12007-01-11 15:44:44 +0100816 sc3_read_eeprom();
817#endif
Haiying Wangd59feff2008-01-16 17:12:12 -0500818
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000819#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
Haiying Wangd59feff2008-01-16 17:12:12 -0500820 mac_read_from_eeprom();
821#endif
822
wdenkfe8c2802002-11-03 00:38:21 +0000823#ifdef CONFIG_HERMES
824 if ((gd->board_type >> 16) == 2)
825 bd->bi_ethspeed = gd->board_type & 0xFFFF;
826 else
827 bd->bi_ethspeed = 0xFFFF;
828#endif
829
Stefan Roese02a301c2009-02-25 12:11:15 +0100830#ifdef CONFIG_CMD_NET
Mike Frysingereb85aa52009-02-11 20:07:19 -0500831 /* kept around for legacy kernels only ... ignore the next section */
832 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
wdenke2ffd592004-12-31 09:32:47 +0000833#ifdef CONFIG_HAS_ETH1
Mike Frysingereb85aa52009-02-11 20:07:19 -0500834 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
wdenkfe8c2802002-11-03 00:38:21 +0000835#endif
wdenke2ffd592004-12-31 09:32:47 +0000836#ifdef CONFIG_HAS_ETH2
Mike Frysingereb85aa52009-02-11 20:07:19 -0500837 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
wdenkfe8c2802002-11-03 00:38:21 +0000838#endif
wdenke2ffd592004-12-31 09:32:47 +0000839#ifdef CONFIG_HAS_ETH3
Mike Frysingereb85aa52009-02-11 20:07:19 -0500840 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
wdenkba56f622004-02-06 23:19:44 +0000841#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400842#ifdef CONFIG_HAS_ETH4
Mike Frysingereb85aa52009-02-11 20:07:19 -0500843 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400844#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400845#ifdef CONFIG_HAS_ETH5
Mike Frysingereb85aa52009-02-11 20:07:19 -0500846 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400847#endif
Stefan Roese02a301c2009-02-25 12:11:15 +0100848#endif /* CONFIG_CMD_NET */
richardretanubunc68a05f2008-09-29 18:28:23 -0400849
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000850 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000851
Andre Schwarz76221a62010-10-05 11:59:31 +0200852#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000853 /*
854 * Do pci configuration
855 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000856 pci_init();
wdenkfe8c2802002-11-03 00:38:21 +0000857#endif
858
859/** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200860 /* Initialize stdio devices */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000861 stdio_init();
wdenkfe8c2802002-11-03 00:38:21 +0000862
wdenk27b207f2003-07-24 23:38:38 +0000863 /* Initialize the jump table for applications */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000864 jumptable_init();
wdenkfe8c2802002-11-03 00:38:21 +0000865
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100866#if defined(CONFIG_API)
867 /* Initialize API */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000868 api_init();
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100869#endif
870
wdenkfe8c2802002-11-03 00:38:21 +0000871 /* Initialize the console (after the relocation and devices init) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000872 console_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000873
Peter Tyser3a8f28d2009-09-16 22:03:07 -0500874#if defined(CONFIG_MISC_INIT_R)
wdenkfe8c2802002-11-03 00:38:21 +0000875 /* miscellaneous platform dependent initialisations */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000876 misc_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000877#endif
878
879#ifdef CONFIG_HERMES
880 if (bd->bi_ethspeed != 0xFFFF)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000881 hermes_start_lxt980((int) bd->bi_ethspeed);
wdenkfe8c2802002-11-03 00:38:21 +0000882#endif
883
Jon Loeliger7def6b32007-07-09 18:02:11 -0500884#if defined(CONFIG_CMD_KGDB)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000885 WATCHDOG_RESET();
886 puts("KGDB: ");
887 kgdb_init();
wdenkfe8c2802002-11-03 00:38:21 +0000888#endif
889
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000890 debug("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000891
892 /*
893 * Enable Interrupts
894 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000895 interrupt_init();
wdenkfe8c2802002-11-03 00:38:21 +0000896
Heiko Schocher566a4942007-06-22 19:11:54 +0200897#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000898 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
wdenkfe8c2802002-11-03 00:38:21 +0000899#endif
900
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000901 udelay(20);
wdenkfe8c2802002-11-03 00:38:21 +0000902
wdenkfe8c2802002-11-03 00:38:21 +0000903 /* Initialize from environment */
Simon Glass12725922011-10-13 14:43:12 +0000904 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000905
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000906 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000907
Jon Loeliger7def6b32007-07-09 18:02:11 -0500908#if defined(CONFIG_CMD_SCSI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000909 WATCHDOG_RESET();
910 puts("SCSI: ");
911 scsi_init();
wdenkfe8c2802002-11-03 00:38:21 +0000912#endif
913
Jon Loeliger7def6b32007-07-09 18:02:11 -0500914#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000915 WATCHDOG_RESET();
916 puts("DOC: ");
917 doc_init();
wdenkfe8c2802002-11-03 00:38:21 +0000918#endif
919
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200920#ifdef CONFIG_BITBANGMII
921 bb_miiphy_init();
922#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -0500923#if defined(CONFIG_CMD_NET)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000924 WATCHDOG_RESET();
925 puts("Net: ");
926 eth_initialize(bd);
wdenkfe8c2802002-11-03 00:38:21 +0000927#endif
928
Peter Tyser004eca02009-09-16 22:03:08 -0500929#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000930 WATCHDOG_RESET();
931 debug("Reset Ethernet PHY\n");
932 reset_phy();
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200933#endif
934
wdenkfe8c2802002-11-03 00:38:21 +0000935#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000936 post_run(NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000937#endif
938
Jon Loeliger7def6b32007-07-09 18:02:11 -0500939#if defined(CONFIG_CMD_PCMCIA) \
940 && !defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000941 WATCHDOG_RESET();
942 puts("PCMCIA:");
943 pcmcia_init();
wdenkfe8c2802002-11-03 00:38:21 +0000944#endif
945
Jon Loeliger7def6b32007-07-09 18:02:11 -0500946#if defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000947 WATCHDOG_RESET();
948#ifdef CONFIG_IDE_8xx_PCCARD
949 puts("PCMCIA:");
950#else
951 puts("IDE: ");
wdenkfe8c2802002-11-03 00:38:21 +0000952#endif
Heiko Schocherca43ba12007-01-11 15:44:44 +0100953#if defined(CONFIG_START_IDE)
954 if (board_start_ide())
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000955 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100956#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000957 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100958#endif
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500959#endif
wdenkfe8c2802002-11-03 00:38:21 +0000960
961#ifdef CONFIG_LAST_STAGE_INIT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000962 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000963 /*
964 * Some parts can be only initialized if all others (like
965 * Interrupts) are up and running (i.e. the PC-style ISA
966 * keyboard).
967 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000968 last_stage_init();
wdenkfe8c2802002-11-03 00:38:21 +0000969#endif
970
Jon Loeliger7def6b32007-07-09 18:02:11 -0500971#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000972 WATCHDOG_RESET();
973 bedbug_init();
wdenkfe8c2802002-11-03 00:38:21 +0000974#endif
975
wdenk228f29a2002-12-08 09:53:23 +0000976#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000977 /*
978 * Export available size of memory for Linux,
979 * taking into account the protected RAM at top of memory
980 */
981 {
Simon Glass12725922011-10-13 14:43:12 +0000982 ulong pram = 0;
Simon Glassd01b1762012-01-05 17:54:57 +0000983 char memsz[32];
wdenkfe8c2802002-11-03 00:38:21 +0000984
Simon Glass12725922011-10-13 14:43:12 +0000985#ifdef CONFIG_PRAM
986 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenk228f29a2002-12-08 09:53:23 +0000987#endif
988#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100989#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000990 /* Also take the logbuffer into account (pram is in kB) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000991 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
wdenk228f29a2002-12-08 09:53:23 +0000992#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100993#endif
Valentin Longchamp13287e32013-10-18 11:47:14 +0200994 sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
Simon Glassd01b1762012-01-05 17:54:57 +0000995 setenv("mem", memsz);
wdenkfe8c2802002-11-03 00:38:21 +0000996 }
997#endif
998
wdenk1c437712004-01-16 00:30:56 +0000999#ifdef CONFIG_PS2KBD
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001000 puts("PS/2: ");
wdenk1c437712004-01-16 00:30:56 +00001001 kbd_init();
1002#endif
1003
wdenkfe8c2802002-11-03 00:38:21 +00001004 /* Initialization complete - start the monitor */
1005
1006 /* main_loop() can return to retry autoboot, if so just run it again. */
1007 for (;;) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001008 WATCHDOG_RESET();
1009 main_loop();
wdenkfe8c2802002-11-03 00:38:21 +00001010 }
1011
1012 /* NOTREACHED - no way out of command loop except booting */
1013}
1014
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001015#if 0 /* We could use plain global data, but the resulting code is bigger */
wdenkfe8c2802002-11-03 00:38:21 +00001016/*
1017 * Pointer to initial global data area
1018 *
1019 * Here we initialize it.
1020 */
1021#undef XTRN_DECLARE_GLOBAL_DATA_PTR
1022#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001023DECLARE_GLOBAL_DATA_PTR =
1024 (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
1025#endif /* 0 */
wdenkfe8c2802002-11-03 00:38:21 +00001026
1027/************************************************************************/