blob: 4c9c3acb6dd7e972702b556fb0f739866ae50261 [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
Jon Loeliger7def6b32007-07-09 18:02:11 -050078#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +000079void doc_init(void);
wdenkfe8c2802002-11-03 00:38:21 +000080#endif
Heiko Schocherea818db2013-01-29 08:53:15 +010081#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
wdenkfe8c2802002-11-03 00:38:21 +000082#include <i2c.h>
83#endif
Ben Warren04a9e112008-01-16 22:37:35 -050084#include <spi.h>
Scott Woodd6ac2ed2008-05-22 10:49:46 -050085#include <nand.h>
wdenkfe8c2802002-11-03 00:38:21 +000086
87static char *failed = "*** failed ***\n";
88
Wolfgang Denk544d97e2010-10-05 22:54:53 +020089#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenkfe8c2802002-11-03 00:38:21 +000090extern flash_info_t flash_info[];
wdenk17d704e2004-04-10 20:43:50 +000091#endif
wdenkfe8c2802002-11-03 00:38:21 +000092
Heiko Schocherca43ba12007-01-11 15:44:44 +010093#if defined(CONFIG_START_IDE)
94extern int board_start_ide(void);
95#endif
wdenkfe8c2802002-11-03 00:38:21 +000096#include <environment.h>
Wolfgang Denkd87080b2006-03-31 18:32:53 +020097
Wolfgang Denkbce84c42005-08-30 14:13:23 +020098DECLARE_GLOBAL_DATA_PTR;
wdenkfe8c2802002-11-03 00:38:21 +000099
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100#if !defined(CONFIG_SYS_MEM_TOP_HIDE)
101#define CONFIG_SYS_MEM_TOP_HIDE 0
Stefan Roese6fb4b642008-03-27 10:24:03 +0100102#endif
103
wdenk3b57fe02003-05-30 12:48:29 +0000104extern ulong __init_end;
Simon Glass3929fb02013-03-14 06:54:53 +0000105extern ulong __bss_end;
wdenk3b57fe02003-05-30 12:48:29 +0000106ulong monitor_flash_len;
107
Jon Loeliger7def6b32007-07-09 18:02:11 -0500108#if defined(CONFIG_CMD_BEDBUG)
wdenk8bde7f72003-06-27 21:31:46 +0000109#include <bedbug/type.h>
110#endif
111
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000112/*
113 * Utilities
wdenkfe8c2802002-11-03 00:38:21 +0000114 */
115
116/*
wdenkfe8c2802002-11-03 00:38:21 +0000117 * All attempts to come up with a "common" initialization sequence
118 * that works for all boards and architectures failed: some of the
119 * requirements are just _too_ different. To get rid of the resulting
120 * mess of board dependend #ifdef'ed code we now make the whole
121 * initialization sequence configurable to the user.
122 *
123 * The requirements for any new initalization function is simple: it
124 * receives a pointer to the "global data" structure as it's only
125 * argument, and returns an integer return code, where 0 means
126 * "continue" and != 0 means "fatal error, hang the system".
127 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000128typedef int (init_fnc_t)(void);
wdenkfe8c2802002-11-03 00:38:21 +0000129
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000130/*
131 * Init Utilities
132 *
wdenkfe8c2802002-11-03 00:38:21 +0000133 * Some of this code should be moved into the core functions,
134 * but let's get it working (again) first...
135 */
136
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000137static int init_baudrate(void)
wdenkfe8c2802002-11-03 00:38:21 +0000138{
Simon Glass12725922011-10-13 14:43:12 +0000139 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
140 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000141}
142
143/***********************************************************************/
144
Kim Phillips20051f22012-10-29 13:34:29 +0000145static void __board_add_ram_info(int use_default)
Kim Phillips79f240f2007-08-16 22:52:39 -0500146{
147 /* please define platform specific board_add_ram_info() */
148}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000149
150void board_add_ram_info(int)
151 __attribute__ ((weak, alias("__board_add_ram_info")));
Kim Phillips79f240f2007-08-16 22:52:39 -0500152
Kim Phillips20051f22012-10-29 13:34:29 +0000153static int __board_flash_wp_on(void)
John Schmollerc62491d2010-09-29 14:05:44 -0500154{
155 /*
156 * Most flashes can't be detected when write protection is enabled,
157 * so provide a way to let U-Boot gracefully ignore write protected
158 * devices.
159 */
160 return 0;
161}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000162
163int board_flash_wp_on(void)
164 __attribute__ ((weak, alias("__board_flash_wp_on")));
Stefan Roesed96f41e2005-11-30 13:06:40 +0100165
Kim Phillips20051f22012-10-29 13:34:29 +0000166static void __cpu_secondary_init_r(void)
Kumar Galaf9a33f12011-02-02 11:23:50 -0600167{
168}
Kumar Galaf9a33f12011-02-02 11:23:50 -0600169
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000170void cpu_secondary_init_r(void)
171 __attribute__ ((weak, alias("__cpu_secondary_init_r")));
172
173static int init_func_ram(void)
wdenkfe8c2802002-11-03 00:38:21 +0000174{
wdenkfe8c2802002-11-03 00:38:21 +0000175#ifdef CONFIG_BOARD_TYPES
176 int board_type = gd->board_type;
177#else
178 int board_type = 0; /* use dummy arg */
179#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000180 puts("DRAM: ");
wdenkfe8c2802002-11-03 00:38:21 +0000181
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000182 gd->ram_size = initdram(board_type);
183
184 if (gd->ram_size > 0) {
185 print_size(gd->ram_size, "");
Stefan Roesed96f41e2005-11-30 13:06:40 +0100186 board_add_ram_info(0);
Stefan Roesed96f41e2005-11-30 13:06:40 +0100187 putc('\n');
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000188 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000189 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000190 puts(failed);
191 return 1;
wdenkfe8c2802002-11-03 00:38:21 +0000192}
193
194/***********************************************************************/
195
Heiko Schocherea818db2013-01-29 08:53:15 +0100196#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000197static int init_func_i2c(void)
wdenkfe8c2802002-11-03 00:38:21 +0000198{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000199 puts("I2C: ");
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000200#ifdef CONFIG_SYS_I2C
201 i2c_init_all();
202#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000203 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000204#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000205 puts("ready\n");
206 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000207}
208#endif
209
Ben Warren04a9e112008-01-16 22:37:35 -0500210#if defined(CONFIG_HARD_SPI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000211static int init_func_spi(void)
Ben Warren04a9e112008-01-16 22:37:35 -0500212{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000213 puts("SPI: ");
214 spi_init();
215 puts("ready\n");
216 return 0;
Ben Warren04a9e112008-01-16 22:37:35 -0500217}
218#endif
219
wdenkfe8c2802002-11-03 00:38:21 +0000220/***********************************************************************/
221
222#if defined(CONFIG_WATCHDOG)
Simon Glassa6741bc2013-03-05 14:39:42 +0000223int init_func_watchdog_init(void)
wdenkfe8c2802002-11-03 00:38:21 +0000224{
Boschung, Rainer919e0552014-06-03 09:05:15 +0200225#if defined(CONFIG_MPC85xx)
226 init_85xx_watchdog();
227#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000228 puts(" Watchdog enabled\n");
229 WATCHDOG_RESET();
230 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000231}
wdenkfe8c2802002-11-03 00:38:21 +0000232
Simon Glassa6741bc2013-03-05 14:39:42 +0000233int init_func_watchdog_reset(void)
wdenkfe8c2802002-11-03 00:38:21 +0000234{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000235 WATCHDOG_RESET();
236 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000237}
wdenkfe8c2802002-11-03 00:38:21 +0000238#endif /* CONFIG_WATCHDOG */
239
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000240/*
241 * Initialization sequence
wdenkfe8c2802002-11-03 00:38:21 +0000242 */
243
Kim Phillips20051f22012-10-29 13:34:29 +0000244static init_fnc_t *init_sequence[] = {
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530245#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
246 probecpu,
247#endif
Anton Vorontsov91525c62009-10-12 23:55:39 +0400248#if defined(CONFIG_BOARD_EARLY_INIT_F)
249 board_early_init_f,
250#endif
wdenk66ca92a2004-09-28 17:59:53 +0000251#if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
wdenkfe8c2802002-11-03 00:38:21 +0000252 get_clocks, /* get CPU and bus clocks (etc.) */
Markus Klotzbuecher090eb732006-07-12 15:26:01 +0200253#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
254 && !defined(CONFIG_TQM885D)
wdenke9132ea2004-04-24 23:23:30 +0000255 adjust_sdram_tbs_8xx,
256#endif
wdenkfe8c2802002-11-03 00:38:21 +0000257 init_timebase,
wdenkc178d3d2004-01-24 20:25:54 +0000258#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200259#ifdef CONFIG_SYS_ALLOC_DPRAM
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500260#if !defined(CONFIG_CPM2)
wdenkfe8c2802002-11-03 00:38:21 +0000261 dpram_init,
262#endif
wdenk7aa78612003-05-03 15:50:43 +0000263#endif
wdenkfe8c2802002-11-03 00:38:21 +0000264#if defined(CONFIG_BOARD_POSTCLK_INIT)
265 board_postclk_init,
266#endif
267 env_init,
wdenk66ca92a2004-09-28 17:59:53 +0000268#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000269 /* get CPU and bus clocks according to the environment variable */
270 get_clocks_866,
271 /* adjust sdram refresh rate according to the new clock */
272 sdram_adjust_866,
wdenkc178d3d2004-01-24 20:25:54 +0000273 init_timebase,
274#endif
wdenkfe8c2802002-11-03 00:38:21 +0000275 init_baudrate,
276 serial_init,
277 console_init_f,
278 display_options,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900279#if defined(CONFIG_MPC8260)
wdenkfe8c2802002-11-03 00:38:21 +0000280 prt_8260_rsr,
281 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900282#endif /* CONFIG_MPC8260 */
Peter Tyser0f898602009-05-22 17:23:24 -0500283#if defined(CONFIG_MPC83xx)
Dave Liu9be39a62007-06-25 10:41:56 +0800284 prt_83xx_rsr,
285#endif
wdenkfe8c2802002-11-03 00:38:21 +0000286 checkcpu,
wdenkcbd8a352004-02-24 02:00:03 +0000287#if defined(CONFIG_MPC5xxx)
wdenk945af8d2003-07-16 21:53:01 +0000288 prt_mpc5xxx_clks,
wdenkcbd8a352004-02-24 02:00:03 +0000289#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000290 checkboard,
291 INIT_FUNC_WATCHDOG_INIT
wdenkc837dcb2004-01-20 23:12:12 +0000292#if defined(CONFIG_MISC_INIT_F)
wdenkfe8c2802002-11-03 00:38:21 +0000293 misc_init_f,
294#endif
295 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100296#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
wdenkfe8c2802002-11-03 00:38:21 +0000297 init_func_i2c,
298#endif
Ben Warren04a9e112008-01-16 22:37:35 -0500299#if defined(CONFIG_HARD_SPI)
300 init_func_spi,
301#endif
wdenk4532cb62003-04-27 22:52:51 +0000302#ifdef CONFIG_POST
303 post_init_f,
304#endif
Simon Glass6f6430d2013-03-11 14:30:37 +0000305 INIT_FUNC_WATCHDOG_RESET
306 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200307#if defined(CONFIG_SYS_DRAM_TEST)
wdenkfe8c2802002-11-03 00:38:21 +0000308 testdram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200309#endif /* CONFIG_SYS_DRAM_TEST */
wdenkfe8c2802002-11-03 00:38:21 +0000310 INIT_FUNC_WATCHDOG_RESET
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000311 NULL, /* Terminate this list */
wdenkfe8c2802002-11-03 00:38:21 +0000312};
313
Kim Phillips20051f22012-10-29 13:34:29 +0000314static int __fixup_cpu(void)
York Sun123bd962012-08-17 08:20:22 +0000315{
316 return 0;
317}
318
319int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
320
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000321/*
wdenkfe8c2802002-11-03 00:38:21 +0000322 * This is the first part of the initialization sequence that is
323 * implemented in C, but still running from ROM.
324 *
325 * The main purpose is to provide a (serial) console interface as
326 * soon as possible (so we can see any error messages), and to
327 * initialize the RAM so that we can relocate the monitor code to
328 * RAM.
329 *
330 * Be aware of the restrictions: global data is read-only, BSS is not
331 * initialized, and stack space is limited to a few kB.
wdenkfe8c2802002-11-03 00:38:21 +0000332 */
333
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000334void board_init_f(ulong bootflag)
wdenkfe8c2802002-11-03 00:38:21 +0000335{
wdenkfe8c2802002-11-03 00:38:21 +0000336 bd_t *bd;
337 ulong len, addr, addr_sp;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200338 ulong *s;
wdenkfe8c2802002-11-03 00:38:21 +0000339 gd_t *id;
340 init_fnc_t **init_fnc_ptr;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000341
wdenkfe8c2802002-11-03 00:38:21 +0000342#ifdef CONFIG_PRAM
wdenkfe8c2802002-11-03 00:38:21 +0000343 ulong reg;
wdenkfe8c2802002-11-03 00:38:21 +0000344#endif
345
346 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200347 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk93f6a672004-07-01 20:28:03 +0000348 /* compiler optimization barrier needed for GCC >= 3.4 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000349 __asm__ __volatile__("":::"memory");
wdenkfe8c2802002-11-03 00:38:21 +0000350
Detlev Zundel82826d52010-01-22 14:47:59 +0100351#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
352 !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
353 !defined(CONFIG_MPC86xx)
wdenkfe8c2802002-11-03 00:38:21 +0000354 /* Clear initial global data */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000355 memset((void *) gd, 0, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000356#endif
357
Tang Yuantian30675472014-07-23 17:27:52 +0800358 gd->flags = bootflag;
359
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000360 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
361 if ((*init_fnc_ptr) () != 0)
362 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000363
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000364#ifdef CONFIG_POST
365 post_bootmode_init();
Kim Phillips20051f22012-10-29 13:34:29 +0000366 post_run(NULL, POST_ROM | post_bootmode_get(NULL));
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000367#endif
368
369 WATCHDOG_RESET();
370
wdenkfe8c2802002-11-03 00:38:21 +0000371 /*
372 * Now that we have DRAM mapped and working, we can
373 * relocate the code and continue running from DRAM.
374 *
375 * Reserve memory at end of RAM for (top down in that order):
Stefan Roese14f73ca2008-03-26 10:14:11 +0100376 * - area that won't get touched by U-Boot and Linux (optional)
wdenk8bde7f72003-06-27 21:31:46 +0000377 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000378 * - protected RAM
379 * - LCD framebuffer
380 * - monitor code
381 * - board info struct
382 */
Simon Glass3929fb02013-03-14 06:54:53 +0000383 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000384
Stefan Roese14f73ca2008-03-26 10:14:11 +0100385 /*
386 * Subtract specified amount of memory to hide so that it won't
387 * get "touched" at all by U-Boot. By fixing up gd->ram_size
388 * the Linux kernel should now get passed the now "corrected"
389 * memory size and won't touch it either. This should work
390 * for arch/ppc and arch/powerpc. Only Linux board ports in
391 * arch/powerpc with bootwrapper support, that recalculate the
392 * memory size from the SDRAM controller setup will have to
393 * get fixed.
394 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200395 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
Stefan Roese14f73ca2008-03-26 10:14:11 +0100396
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200397 addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
wdenkfe8c2802002-11-03 00:38:21 +0000398
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500399#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
400 /*
401 * We need to make sure the location we intend to put secondary core
402 * boot code is reserved and not used by any part of u-boot
Wolfgang Denkc0a14ae2009-04-05 00:27:57 +0200403 */
York Suneb539412012-10-08 07:44:25 +0000404 if (addr > determine_mp_bootpg(NULL)) {
405 addr = determine_mp_bootpg(NULL);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000406 debug("Reserving MP boot page to %08lx\n", addr);
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500407 }
408#endif
409
wdenk228f29a2002-12-08 09:53:23 +0000410#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100411#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000412 /* reserve kernel log buffer */
413 addr -= (LOGBUFF_RESERVE);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000414 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
415 addr);
wdenk228f29a2002-12-08 09:53:23 +0000416#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100417#endif
wdenk228f29a2002-12-08 09:53:23 +0000418
wdenkfe8c2802002-11-03 00:38:21 +0000419#ifdef CONFIG_PRAM
420 /*
421 * reserve protected RAM
422 */
Simon Glass12725922011-10-13 14:43:12 +0000423 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000424 addr -= (reg << 10); /* size is in kB */
Simon Glass12725922011-10-13 14:43:12 +0000425 debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000426#endif /* CONFIG_PRAM */
427
428 /* round down to next 4 kB limit */
429 addr &= ~(4096 - 1);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000430 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000431
432#ifdef CONFIG_LCD
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000433#ifdef CONFIG_FB_ADDR
434 gd->fb_base = CONFIG_FB_ADDR;
435#else
wdenkfe8c2802002-11-03 00:38:21 +0000436 /* reserve memory for LCD display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000437 addr = lcd_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000438 gd->fb_base = addr;
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000439#endif /* CONFIG_FB_ADDR */
wdenkfe8c2802002-11-03 00:38:21 +0000440#endif /* CONFIG_LCD */
441
442#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
443 /* reserve memory for video display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000444 addr = video_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000445 gd->fb_base = addr;
446#endif /* CONFIG_VIDEO */
447
448 /*
449 * reserve memory for U-Boot code, data & bss
wdenk682011f2003-06-03 23:54:09 +0000450 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000451 */
452 addr -= len;
wdenk682011f2003-06-03 23:54:09 +0000453 addr &= ~(4096 - 1);
Wolfgang Denk7d314992005-10-05 00:00:54 +0200454#ifdef CONFIG_E500
455 /* round down to next 64 kB limit so that IVPR stays aligned */
456 addr &= ~(65536 - 1);
457#endif
wdenkfe8c2802002-11-03 00:38:21 +0000458
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000459 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000460
461 /*
462 * reserve memory for malloc() arena
463 */
464 addr_sp = addr - TOTAL_MALLOC_LEN;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000465 debug("Reserving %dk for malloc() at: %08lx\n",
466 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000467
468 /*
469 * (permanently) allocate a Board Info struct
470 * and a permanent copy of the "global" data
471 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000472 addr_sp -= sizeof(bd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000473 bd = (bd_t *) addr_sp;
Peter Tysera1c48642010-09-14 19:13:51 -0500474 memset(bd, 0, sizeof(bd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000475 gd->bd = bd;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000476 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
477 sizeof(bd_t), addr_sp);
478 addr_sp -= sizeof(gd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000479 id = (gd_t *) addr_sp;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000480 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
481 sizeof(gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000482
483 /*
484 * Finally, we set up a new (bigger) stack.
485 *
486 * Leave some safety gap for SP, force alignment on 16 byte boundary
487 * Clear initial stack frame
488 */
489 addr_sp -= 16;
490 addr_sp &= ~0xF;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000491 s = (ulong *) addr_sp;
Joakim Tjernlund7de8a712012-07-23 10:58:03 +0000492 *s = 0; /* Terminate back chain */
493 *++s = 0; /* NULL return address */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000494 debug("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000495
496 /*
497 * Save local variables to board info struct
498 */
499
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000500 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
501 bd->bi_memsize = gd->ram_size; /* size in bytes */
wdenkfe8c2802002-11-03 00:38:21 +0000502
Wolfgang Denk36116652010-08-11 09:38:31 +0200503#ifdef CONFIG_SYS_SRAM_BASE
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000504 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
505 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
wdenkfe8c2802002-11-03 00:38:21 +0000506#endif
507
Masahiro Yamada58dac322014-03-05 17:40:10 +0900508#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Jon Loeligerdebb7352006-04-26 17:58:56 -0500509 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200510 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
wdenkfe8c2802002-11-03 00:38:21 +0000511#endif
wdenkcbd8a352004-02-24 02:00:03 +0000512#if defined(CONFIG_MPC5xxx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200513 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenk945af8d2003-07-16 21:53:01 +0000514#endif
Peter Tyser0f898602009-05-22 17:23:24 -0500515#if defined(CONFIG_MPC83xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200516 bd->bi_immrbar = CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500517#endif
wdenkfe8c2802002-11-03 00:38:21 +0000518
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000519 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000520 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
521 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500522#if defined(CONFIG_CPM2)
Simon Glass748cd052012-12-13 20:48:46 +0000523 bd->bi_cpmfreq = gd->arch.cpm_clk;
Simon Glass1206c182012-12-13 20:48:44 +0000524 bd->bi_brgfreq = gd->arch.brg_clk;
Simon Glass748cd052012-12-13 20:48:46 +0000525 bd->bi_sccfreq = gd->arch.scc_clk;
526 bd->bi_vco = gd->arch.vco_out;
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500527#endif /* CONFIG_CPM2 */
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100528#if defined(CONFIG_MPC512X)
Simon Glassfefb0982012-12-13 20:48:54 +0000529 bd->bi_ipsfreq = gd->arch.ips_clk;
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100530#endif /* CONFIG_MPC512X */
wdenkcbd8a352004-02-24 02:00:03 +0000531#if defined(CONFIG_MPC5xxx)
Simon Glassb2877492012-12-13 20:48:53 +0000532 bd->bi_ipbfreq = gd->arch.ipb_clk;
wdenk945af8d2003-07-16 21:53:01 +0000533 bd->bi_pcifreq = gd->pci_clk;
wdenkcbd8a352004-02-24 02:00:03 +0000534#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000535
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 Denk9b998b02011-11-04 15:55:07 +0000790#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
Haiying Wangd59feff2008-01-16 17:12:12 -0500791 mac_read_from_eeprom();
792#endif
793
Stefan Roese02a301c2009-02-25 12:11:15 +0100794#ifdef CONFIG_CMD_NET
Mike Frysingereb85aa52009-02-11 20:07:19 -0500795 /* kept around for legacy kernels only ... ignore the next section */
796 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
wdenke2ffd592004-12-31 09:32:47 +0000797#ifdef CONFIG_HAS_ETH1
Mike Frysingereb85aa52009-02-11 20:07:19 -0500798 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
wdenkfe8c2802002-11-03 00:38:21 +0000799#endif
wdenke2ffd592004-12-31 09:32:47 +0000800#ifdef CONFIG_HAS_ETH2
Mike Frysingereb85aa52009-02-11 20:07:19 -0500801 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
wdenkfe8c2802002-11-03 00:38:21 +0000802#endif
wdenke2ffd592004-12-31 09:32:47 +0000803#ifdef CONFIG_HAS_ETH3
Mike Frysingereb85aa52009-02-11 20:07:19 -0500804 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
wdenkba56f622004-02-06 23:19:44 +0000805#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400806#ifdef CONFIG_HAS_ETH4
Mike Frysingereb85aa52009-02-11 20:07:19 -0500807 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400808#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400809#ifdef CONFIG_HAS_ETH5
Mike Frysingereb85aa52009-02-11 20:07:19 -0500810 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400811#endif
Stefan Roese02a301c2009-02-25 12:11:15 +0100812#endif /* CONFIG_CMD_NET */
richardretanubunc68a05f2008-09-29 18:28:23 -0400813
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000814 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000815
Andre Schwarz76221a62010-10-05 11:59:31 +0200816#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000817 /*
818 * Do pci configuration
819 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000820 pci_init();
wdenkfe8c2802002-11-03 00:38:21 +0000821#endif
822
823/** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200824 /* Initialize stdio devices */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000825 stdio_init();
wdenkfe8c2802002-11-03 00:38:21 +0000826
wdenk27b207f2003-07-24 23:38:38 +0000827 /* Initialize the jump table for applications */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000828 jumptable_init();
wdenkfe8c2802002-11-03 00:38:21 +0000829
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100830#if defined(CONFIG_API)
831 /* Initialize API */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000832 api_init();
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100833#endif
834
wdenkfe8c2802002-11-03 00:38:21 +0000835 /* Initialize the console (after the relocation and devices init) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000836 console_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000837
Peter Tyser3a8f28d2009-09-16 22:03:07 -0500838#if defined(CONFIG_MISC_INIT_R)
wdenkfe8c2802002-11-03 00:38:21 +0000839 /* miscellaneous platform dependent initialisations */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000840 misc_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000841#endif
842
Jon Loeliger7def6b32007-07-09 18:02:11 -0500843#if defined(CONFIG_CMD_KGDB)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000844 WATCHDOG_RESET();
845 puts("KGDB: ");
846 kgdb_init();
wdenkfe8c2802002-11-03 00:38:21 +0000847#endif
848
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000849 debug("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000850
851 /*
852 * Enable Interrupts
853 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000854 interrupt_init();
wdenkfe8c2802002-11-03 00:38:21 +0000855
Heiko Schocher566a4942007-06-22 19:11:54 +0200856#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000857 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
wdenkfe8c2802002-11-03 00:38:21 +0000858#endif
859
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000860 udelay(20);
wdenkfe8c2802002-11-03 00:38:21 +0000861
wdenkfe8c2802002-11-03 00:38:21 +0000862 /* Initialize from environment */
Simon Glass12725922011-10-13 14:43:12 +0000863 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000864
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000865 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000866
Jon Loeliger7def6b32007-07-09 18:02:11 -0500867#if defined(CONFIG_CMD_SCSI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000868 WATCHDOG_RESET();
869 puts("SCSI: ");
870 scsi_init();
wdenkfe8c2802002-11-03 00:38:21 +0000871#endif
872
Jon Loeliger7def6b32007-07-09 18:02:11 -0500873#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000874 WATCHDOG_RESET();
875 puts("DOC: ");
876 doc_init();
wdenkfe8c2802002-11-03 00:38:21 +0000877#endif
878
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200879#ifdef CONFIG_BITBANGMII
880 bb_miiphy_init();
881#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -0500882#if defined(CONFIG_CMD_NET)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000883 WATCHDOG_RESET();
884 puts("Net: ");
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500885 eth_initialize();
wdenkfe8c2802002-11-03 00:38:21 +0000886#endif
887
Peter Tyser004eca02009-09-16 22:03:08 -0500888#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000889 WATCHDOG_RESET();
890 debug("Reset Ethernet PHY\n");
891 reset_phy();
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200892#endif
893
wdenkfe8c2802002-11-03 00:38:21 +0000894#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000895 post_run(NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000896#endif
897
Jon Loeliger7def6b32007-07-09 18:02:11 -0500898#if defined(CONFIG_CMD_PCMCIA) \
899 && !defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000900 WATCHDOG_RESET();
901 puts("PCMCIA:");
902 pcmcia_init();
wdenkfe8c2802002-11-03 00:38:21 +0000903#endif
904
Jon Loeliger7def6b32007-07-09 18:02:11 -0500905#if defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000906 WATCHDOG_RESET();
907#ifdef CONFIG_IDE_8xx_PCCARD
908 puts("PCMCIA:");
909#else
910 puts("IDE: ");
wdenkfe8c2802002-11-03 00:38:21 +0000911#endif
Heiko Schocherca43ba12007-01-11 15:44:44 +0100912#if defined(CONFIG_START_IDE)
913 if (board_start_ide())
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000914 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100915#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000916 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100917#endif
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500918#endif
wdenkfe8c2802002-11-03 00:38:21 +0000919
920#ifdef CONFIG_LAST_STAGE_INIT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000921 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000922 /*
923 * Some parts can be only initialized if all others (like
924 * Interrupts) are up and running (i.e. the PC-style ISA
925 * keyboard).
926 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000927 last_stage_init();
wdenkfe8c2802002-11-03 00:38:21 +0000928#endif
929
Jon Loeliger7def6b32007-07-09 18:02:11 -0500930#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000931 WATCHDOG_RESET();
932 bedbug_init();
wdenkfe8c2802002-11-03 00:38:21 +0000933#endif
934
wdenk228f29a2002-12-08 09:53:23 +0000935#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000936 /*
937 * Export available size of memory for Linux,
938 * taking into account the protected RAM at top of memory
939 */
940 {
Simon Glass12725922011-10-13 14:43:12 +0000941 ulong pram = 0;
Simon Glassd01b1762012-01-05 17:54:57 +0000942 char memsz[32];
wdenkfe8c2802002-11-03 00:38:21 +0000943
Simon Glass12725922011-10-13 14:43:12 +0000944#ifdef CONFIG_PRAM
945 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenk228f29a2002-12-08 09:53:23 +0000946#endif
947#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100948#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000949 /* Also take the logbuffer into account (pram is in kB) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000950 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
wdenk228f29a2002-12-08 09:53:23 +0000951#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100952#endif
Valentin Longchamp13287e32013-10-18 11:47:14 +0200953 sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
Simon Glassd01b1762012-01-05 17:54:57 +0000954 setenv("mem", memsz);
wdenkfe8c2802002-11-03 00:38:21 +0000955 }
956#endif
957
wdenk1c437712004-01-16 00:30:56 +0000958#ifdef CONFIG_PS2KBD
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000959 puts("PS/2: ");
wdenk1c437712004-01-16 00:30:56 +0000960 kbd_init();
961#endif
962
wdenkfe8c2802002-11-03 00:38:21 +0000963 /* Initialization complete - start the monitor */
964
965 /* main_loop() can return to retry autoboot, if so just run it again. */
966 for (;;) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000967 WATCHDOG_RESET();
968 main_loop();
wdenkfe8c2802002-11-03 00:38:21 +0000969 }
970
971 /* NOTREACHED - no way out of command loop except booting */
972}
973
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000974#if 0 /* We could use plain global data, but the resulting code is bigger */
wdenkfe8c2802002-11-03 00:38:21 +0000975/*
976 * Pointer to initial global data area
977 *
978 * Here we initialize it.
979 */
980#undef XTRN_DECLARE_GLOBAL_DATA_PTR
981#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000982DECLARE_GLOBAL_DATA_PTR =
983 (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
984#endif /* 0 */
wdenkfe8c2802002-11-03 00:38:21 +0000985
986/************************************************************************/