blob: bef3f76f0c534c877b179cd7ffbb7015c348c939 [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
85#if defined(CONFIG_HARD_I2C) || \
86 defined(CONFIG_SOFT_I2C)
87#include <i2c.h>
88#endif
Ben Warren04a9e112008-01-16 22:37:35 -050089#include <spi.h>
Scott Woodd6ac2ed2008-05-22 10:49:46 -050090#include <nand.h>
wdenkfe8c2802002-11-03 00:38:21 +000091
92static char *failed = "*** failed ***\n";
93
Wolfgang Denk544d97e2010-10-05 22:54:53 +020094#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenkfe8c2802002-11-03 00:38:21 +000095extern flash_info_t flash_info[];
wdenk17d704e2004-04-10 20:43:50 +000096#endif
wdenkfe8c2802002-11-03 00:38:21 +000097
Heiko Schocherca43ba12007-01-11 15:44:44 +010098#if defined(CONFIG_START_IDE)
99extern int board_start_ide(void);
100#endif
wdenkfe8c2802002-11-03 00:38:21 +0000101#include <environment.h>
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200102
Wolfgang Denkbce84c42005-08-30 14:13:23 +0200103DECLARE_GLOBAL_DATA_PTR;
wdenkfe8c2802002-11-03 00:38:21 +0000104
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200105#if !defined(CONFIG_SYS_MEM_TOP_HIDE)
106#define CONFIG_SYS_MEM_TOP_HIDE 0
Stefan Roese6fb4b642008-03-27 10:24:03 +0100107#endif
108
wdenk3b57fe02003-05-30 12:48:29 +0000109extern ulong __init_end;
Simon Glass3929fb02013-03-14 06:54:53 +0000110extern ulong __bss_end;
wdenk3b57fe02003-05-30 12:48:29 +0000111ulong monitor_flash_len;
112
Jon Loeliger7def6b32007-07-09 18:02:11 -0500113#if defined(CONFIG_CMD_BEDBUG)
wdenk8bde7f72003-06-27 21:31:46 +0000114#include <bedbug/type.h>
115#endif
116
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000117/*
118 * Utilities
wdenkfe8c2802002-11-03 00:38:21 +0000119 */
120
121/*
wdenkfe8c2802002-11-03 00:38:21 +0000122 * All attempts to come up with a "common" initialization sequence
123 * that works for all boards and architectures failed: some of the
124 * requirements are just _too_ different. To get rid of the resulting
125 * mess of board dependend #ifdef'ed code we now make the whole
126 * initialization sequence configurable to the user.
127 *
128 * The requirements for any new initalization function is simple: it
129 * receives a pointer to the "global data" structure as it's only
130 * argument, and returns an integer return code, where 0 means
131 * "continue" and != 0 means "fatal error, hang the system".
132 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000133typedef int (init_fnc_t)(void);
wdenkfe8c2802002-11-03 00:38:21 +0000134
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000135/*
136 * Init Utilities
137 *
wdenkfe8c2802002-11-03 00:38:21 +0000138 * Some of this code should be moved into the core functions,
139 * but let's get it working (again) first...
140 */
141
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000142static int init_baudrate(void)
wdenkfe8c2802002-11-03 00:38:21 +0000143{
Simon Glass12725922011-10-13 14:43:12 +0000144 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
145 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000146}
147
148/***********************************************************************/
149
Kim Phillips20051f22012-10-29 13:34:29 +0000150static void __board_add_ram_info(int use_default)
Kim Phillips79f240f2007-08-16 22:52:39 -0500151{
152 /* please define platform specific board_add_ram_info() */
153}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000154
155void board_add_ram_info(int)
156 __attribute__ ((weak, alias("__board_add_ram_info")));
Kim Phillips79f240f2007-08-16 22:52:39 -0500157
Kim Phillips20051f22012-10-29 13:34:29 +0000158static int __board_flash_wp_on(void)
John Schmollerc62491d2010-09-29 14:05:44 -0500159{
160 /*
161 * Most flashes can't be detected when write protection is enabled,
162 * so provide a way to let U-Boot gracefully ignore write protected
163 * devices.
164 */
165 return 0;
166}
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000167
168int board_flash_wp_on(void)
169 __attribute__ ((weak, alias("__board_flash_wp_on")));
Stefan Roesed96f41e2005-11-30 13:06:40 +0100170
Kim Phillips20051f22012-10-29 13:34:29 +0000171static void __cpu_secondary_init_r(void)
Kumar Galaf9a33f12011-02-02 11:23:50 -0600172{
173}
Kumar Galaf9a33f12011-02-02 11:23:50 -0600174
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000175void cpu_secondary_init_r(void)
176 __attribute__ ((weak, alias("__cpu_secondary_init_r")));
177
178static int init_func_ram(void)
wdenkfe8c2802002-11-03 00:38:21 +0000179{
wdenkfe8c2802002-11-03 00:38:21 +0000180#ifdef CONFIG_BOARD_TYPES
181 int board_type = gd->board_type;
182#else
183 int board_type = 0; /* use dummy arg */
184#endif
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000185 puts("DRAM: ");
wdenkfe8c2802002-11-03 00:38:21 +0000186
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000187 gd->ram_size = initdram(board_type);
188
189 if (gd->ram_size > 0) {
190 print_size(gd->ram_size, "");
Stefan Roesed96f41e2005-11-30 13:06:40 +0100191 board_add_ram_info(0);
Stefan Roesed96f41e2005-11-30 13:06:40 +0100192 putc('\n');
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000193 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000194 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000195 puts(failed);
196 return 1;
wdenkfe8c2802002-11-03 00:38:21 +0000197}
198
199/***********************************************************************/
200
201#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000202static int init_func_i2c(void)
wdenkfe8c2802002-11-03 00:38:21 +0000203{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000204 puts("I2C: ");
205 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
206 puts("ready\n");
207 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000208}
209#endif
210
Ben Warren04a9e112008-01-16 22:37:35 -0500211#if defined(CONFIG_HARD_SPI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000212static int init_func_spi(void)
Ben Warren04a9e112008-01-16 22:37:35 -0500213{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000214 puts("SPI: ");
215 spi_init();
216 puts("ready\n");
217 return 0;
Ben Warren04a9e112008-01-16 22:37:35 -0500218}
219#endif
220
wdenkfe8c2802002-11-03 00:38:21 +0000221/***********************************************************************/
222
223#if defined(CONFIG_WATCHDOG)
Simon Glassa6741bc2013-03-05 14:39:42 +0000224int init_func_watchdog_init(void)
wdenkfe8c2802002-11-03 00:38:21 +0000225{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000226 puts(" Watchdog enabled\n");
227 WATCHDOG_RESET();
228 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000229}
wdenkfe8c2802002-11-03 00:38:21 +0000230
Simon Glassa6741bc2013-03-05 14:39:42 +0000231int init_func_watchdog_reset(void)
wdenkfe8c2802002-11-03 00:38:21 +0000232{
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000233 WATCHDOG_RESET();
234 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000235}
wdenkfe8c2802002-11-03 00:38:21 +0000236#endif /* CONFIG_WATCHDOG */
237
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000238/*
239 * Initialization sequence
wdenkfe8c2802002-11-03 00:38:21 +0000240 */
241
Kim Phillips20051f22012-10-29 13:34:29 +0000242static init_fnc_t *init_sequence[] = {
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530243#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
244 probecpu,
245#endif
Anton Vorontsov91525c62009-10-12 23:55:39 +0400246#if defined(CONFIG_BOARD_EARLY_INIT_F)
247 board_early_init_f,
248#endif
wdenk66ca92a2004-09-28 17:59:53 +0000249#if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
wdenkfe8c2802002-11-03 00:38:21 +0000250 get_clocks, /* get CPU and bus clocks (etc.) */
Markus Klotzbuecher090eb732006-07-12 15:26:01 +0200251#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
252 && !defined(CONFIG_TQM885D)
wdenke9132ea2004-04-24 23:23:30 +0000253 adjust_sdram_tbs_8xx,
254#endif
wdenkfe8c2802002-11-03 00:38:21 +0000255 init_timebase,
wdenkc178d3d2004-01-24 20:25:54 +0000256#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200257#ifdef CONFIG_SYS_ALLOC_DPRAM
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500258#if !defined(CONFIG_CPM2)
wdenkfe8c2802002-11-03 00:38:21 +0000259 dpram_init,
260#endif
wdenk7aa78612003-05-03 15:50:43 +0000261#endif
wdenkfe8c2802002-11-03 00:38:21 +0000262#if defined(CONFIG_BOARD_POSTCLK_INIT)
263 board_postclk_init,
264#endif
265 env_init,
wdenk66ca92a2004-09-28 17:59:53 +0000266#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000267 /* get CPU and bus clocks according to the environment variable */
268 get_clocks_866,
269 /* adjust sdram refresh rate according to the new clock */
270 sdram_adjust_866,
wdenkc178d3d2004-01-24 20:25:54 +0000271 init_timebase,
272#endif
wdenkfe8c2802002-11-03 00:38:21 +0000273 init_baudrate,
274 serial_init,
275 console_init_f,
276 display_options,
277#if defined(CONFIG_8260)
278 prt_8260_rsr,
279 prt_8260_clks,
280#endif /* CONFIG_8260 */
Peter Tyser0f898602009-05-22 17:23:24 -0500281#if defined(CONFIG_MPC83xx)
Dave Liu9be39a62007-06-25 10:41:56 +0800282 prt_83xx_rsr,
283#endif
wdenkfe8c2802002-11-03 00:38:21 +0000284 checkcpu,
wdenkcbd8a352004-02-24 02:00:03 +0000285#if defined(CONFIG_MPC5xxx)
wdenk945af8d2003-07-16 21:53:01 +0000286 prt_mpc5xxx_clks,
wdenkcbd8a352004-02-24 02:00:03 +0000287#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000288 checkboard,
289 INIT_FUNC_WATCHDOG_INIT
wdenkc837dcb2004-01-20 23:12:12 +0000290#if defined(CONFIG_MISC_INIT_F)
wdenkfe8c2802002-11-03 00:38:21 +0000291 misc_init_f,
292#endif
293 INIT_FUNC_WATCHDOG_RESET
294#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
295 init_func_i2c,
296#endif
Ben Warren04a9e112008-01-16 22:37:35 -0500297#if defined(CONFIG_HARD_SPI)
298 init_func_spi,
299#endif
wdenk4532cb62003-04-27 22:52:51 +0000300#ifdef CONFIG_POST
301 post_init_f,
302#endif
Simon Glass6f6430d2013-03-11 14:30:37 +0000303 INIT_FUNC_WATCHDOG_RESET
304 init_func_ram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200305#if defined(CONFIG_SYS_DRAM_TEST)
wdenkfe8c2802002-11-03 00:38:21 +0000306 testdram,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200307#endif /* CONFIG_SYS_DRAM_TEST */
wdenkfe8c2802002-11-03 00:38:21 +0000308 INIT_FUNC_WATCHDOG_RESET
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000309 NULL, /* Terminate this list */
wdenkfe8c2802002-11-03 00:38:21 +0000310};
311
Kumar Gala81d93e52008-02-18 08:09:37 -0600312ulong get_effective_memsize(void)
313{
314#ifndef CONFIG_VERY_BIG_RAM
315 return gd->ram_size;
316#else
317 /* limit stack to what we can reasonable map */
318 return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000319 CONFIG_MAX_MEM_MAPPED : gd->ram_size);
Kumar Gala81d93e52008-02-18 08:09:37 -0600320#endif
321}
322
Kim Phillips20051f22012-10-29 13:34:29 +0000323static int __fixup_cpu(void)
York Sun123bd962012-08-17 08:20:22 +0000324{
325 return 0;
326}
327
328int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
329
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000330/*
wdenkfe8c2802002-11-03 00:38:21 +0000331 * This is the first part of the initialization sequence that is
332 * implemented in C, but still running from ROM.
333 *
334 * The main purpose is to provide a (serial) console interface as
335 * soon as possible (so we can see any error messages), and to
336 * initialize the RAM so that we can relocate the monitor code to
337 * RAM.
338 *
339 * Be aware of the restrictions: global data is read-only, BSS is not
340 * initialized, and stack space is limited to a few kB.
wdenkfe8c2802002-11-03 00:38:21 +0000341 */
342
Marian Balakowicz95d449a2008-05-13 15:53:29 +0200343#ifdef CONFIG_LOGBUFFER
344unsigned long logbuffer_base(void)
345{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200346 return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
Marian Balakowicz95d449a2008-05-13 15:53:29 +0200347}
348#endif
349
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000350void board_init_f(ulong bootflag)
wdenkfe8c2802002-11-03 00:38:21 +0000351{
wdenkfe8c2802002-11-03 00:38:21 +0000352 bd_t *bd;
353 ulong len, addr, addr_sp;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200354 ulong *s;
wdenkfe8c2802002-11-03 00:38:21 +0000355 gd_t *id;
356 init_fnc_t **init_fnc_ptr;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000357
wdenkfe8c2802002-11-03 00:38:21 +0000358#ifdef CONFIG_PRAM
wdenkfe8c2802002-11-03 00:38:21 +0000359 ulong reg;
wdenkfe8c2802002-11-03 00:38:21 +0000360#endif
361
362 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200363 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk93f6a672004-07-01 20:28:03 +0000364 /* compiler optimization barrier needed for GCC >= 3.4 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000365 __asm__ __volatile__("":::"memory");
wdenkfe8c2802002-11-03 00:38:21 +0000366
Detlev Zundel82826d52010-01-22 14:47:59 +0100367#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
368 !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
369 !defined(CONFIG_MPC86xx)
wdenkfe8c2802002-11-03 00:38:21 +0000370 /* Clear initial global data */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000371 memset((void *) gd, 0, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000372#endif
373
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000374 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
375 if ((*init_fnc_ptr) () != 0)
376 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000377
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000378#ifdef CONFIG_POST
379 post_bootmode_init();
Kim Phillips20051f22012-10-29 13:34:29 +0000380 post_run(NULL, POST_ROM | post_bootmode_get(NULL));
Bernhard Kaindl9d256b62011-10-16 00:07:08 +0000381#endif
382
383 WATCHDOG_RESET();
384
wdenkfe8c2802002-11-03 00:38:21 +0000385 /*
386 * Now that we have DRAM mapped and working, we can
387 * relocate the code and continue running from DRAM.
388 *
389 * Reserve memory at end of RAM for (top down in that order):
Stefan Roese14f73ca2008-03-26 10:14:11 +0100390 * - area that won't get touched by U-Boot and Linux (optional)
wdenk8bde7f72003-06-27 21:31:46 +0000391 * - kernel log buffer
wdenkfe8c2802002-11-03 00:38:21 +0000392 * - protected RAM
393 * - LCD framebuffer
394 * - monitor code
395 * - board info struct
396 */
Simon Glass3929fb02013-03-14 06:54:53 +0000397 len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
wdenkfe8c2802002-11-03 00:38:21 +0000398
Stefan Roese14f73ca2008-03-26 10:14:11 +0100399 /*
400 * Subtract specified amount of memory to hide so that it won't
401 * get "touched" at all by U-Boot. By fixing up gd->ram_size
402 * the Linux kernel should now get passed the now "corrected"
403 * memory size and won't touch it either. This should work
404 * for arch/ppc and arch/powerpc. Only Linux board ports in
405 * arch/powerpc with bootwrapper support, that recalculate the
406 * memory size from the SDRAM controller setup will have to
407 * get fixed.
408 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200409 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
Stefan Roese14f73ca2008-03-26 10:14:11 +0100410
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200411 addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
wdenkfe8c2802002-11-03 00:38:21 +0000412
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500413#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
414 /*
415 * We need to make sure the location we intend to put secondary core
416 * boot code is reserved and not used by any part of u-boot
Wolfgang Denkc0a14ae2009-04-05 00:27:57 +0200417 */
York Suneb539412012-10-08 07:44:25 +0000418 if (addr > determine_mp_bootpg(NULL)) {
419 addr = determine_mp_bootpg(NULL);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000420 debug("Reserving MP boot page to %08lx\n", addr);
Kumar Galafc39c2fd2009-03-31 17:58:13 -0500421 }
422#endif
423
wdenk228f29a2002-12-08 09:53:23 +0000424#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100425#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000426 /* reserve kernel log buffer */
427 addr -= (LOGBUFF_RESERVE);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000428 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
429 addr);
wdenk228f29a2002-12-08 09:53:23 +0000430#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100431#endif
wdenk228f29a2002-12-08 09:53:23 +0000432
wdenkfe8c2802002-11-03 00:38:21 +0000433#ifdef CONFIG_PRAM
434 /*
435 * reserve protected RAM
436 */
Simon Glass12725922011-10-13 14:43:12 +0000437 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000438 addr -= (reg << 10); /* size is in kB */
Simon Glass12725922011-10-13 14:43:12 +0000439 debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000440#endif /* CONFIG_PRAM */
441
442 /* round down to next 4 kB limit */
443 addr &= ~(4096 - 1);
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000444 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
wdenkfe8c2802002-11-03 00:38:21 +0000445
446#ifdef CONFIG_LCD
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000447#ifdef CONFIG_FB_ADDR
448 gd->fb_base = CONFIG_FB_ADDR;
449#else
wdenkfe8c2802002-11-03 00:38:21 +0000450 /* reserve memory for LCD display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000451 addr = lcd_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000452 gd->fb_base = addr;
Minkyu Kangd32a1a42011-04-24 22:22:34 +0000453#endif /* CONFIG_FB_ADDR */
wdenkfe8c2802002-11-03 00:38:21 +0000454#endif /* CONFIG_LCD */
455
456#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
457 /* reserve memory for video display (always full pages) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000458 addr = video_setmem(addr);
wdenkfe8c2802002-11-03 00:38:21 +0000459 gd->fb_base = addr;
460#endif /* CONFIG_VIDEO */
461
462 /*
463 * reserve memory for U-Boot code, data & bss
wdenk682011f2003-06-03 23:54:09 +0000464 * round down to next 4 kB limit
wdenkfe8c2802002-11-03 00:38:21 +0000465 */
466 addr -= len;
wdenk682011f2003-06-03 23:54:09 +0000467 addr &= ~(4096 - 1);
Wolfgang Denk7d314992005-10-05 00:00:54 +0200468#ifdef CONFIG_E500
469 /* round down to next 64 kB limit so that IVPR stays aligned */
470 addr &= ~(65536 - 1);
471#endif
wdenkfe8c2802002-11-03 00:38:21 +0000472
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000473 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000474
475 /*
476 * reserve memory for malloc() arena
477 */
478 addr_sp = addr - TOTAL_MALLOC_LEN;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000479 debug("Reserving %dk for malloc() at: %08lx\n",
480 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000481
482 /*
483 * (permanently) allocate a Board Info struct
484 * and a permanent copy of the "global" data
485 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000486 addr_sp -= sizeof(bd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000487 bd = (bd_t *) addr_sp;
Peter Tysera1c48642010-09-14 19:13:51 -0500488 memset(bd, 0, sizeof(bd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000489 gd->bd = bd;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000490 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
491 sizeof(bd_t), addr_sp);
492 addr_sp -= sizeof(gd_t);
wdenkfe8c2802002-11-03 00:38:21 +0000493 id = (gd_t *) addr_sp;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000494 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
495 sizeof(gd_t), addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000496
497 /*
498 * Finally, we set up a new (bigger) stack.
499 *
500 * Leave some safety gap for SP, force alignment on 16 byte boundary
501 * Clear initial stack frame
502 */
503 addr_sp -= 16;
504 addr_sp &= ~0xF;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000505 s = (ulong *) addr_sp;
Joakim Tjernlund7de8a712012-07-23 10:58:03 +0000506 *s = 0; /* Terminate back chain */
507 *++s = 0; /* NULL return address */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000508 debug("Stack Pointer at: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000509
510 /*
511 * Save local variables to board info struct
512 */
513
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000514 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
515 bd->bi_memsize = gd->ram_size; /* size in bytes */
wdenkfe8c2802002-11-03 00:38:21 +0000516
Wolfgang Denk36116652010-08-11 09:38:31 +0200517#ifdef CONFIG_SYS_SRAM_BASE
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000518 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
519 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
wdenkfe8c2802002-11-03 00:38:21 +0000520#endif
521
wdenk42d1f032003-10-15 23:53:47 +0000522#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
Jon Loeligerdebb7352006-04-26 17:58:56 -0500523 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200524 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
wdenkfe8c2802002-11-03 00:38:21 +0000525#endif
wdenkcbd8a352004-02-24 02:00:03 +0000526#if defined(CONFIG_MPC5xxx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200527 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
wdenk945af8d2003-07-16 21:53:01 +0000528#endif
Peter Tyser0f898602009-05-22 17:23:24 -0500529#if defined(CONFIG_MPC83xx)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200530 bd->bi_immrbar = CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500531#endif
wdenkfe8c2802002-11-03 00:38:21 +0000532
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000533 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000534 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
535 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500536#if defined(CONFIG_CPM2)
Simon Glass748cd052012-12-13 20:48:46 +0000537 bd->bi_cpmfreq = gd->arch.cpm_clk;
Simon Glass1206c182012-12-13 20:48:44 +0000538 bd->bi_brgfreq = gd->arch.brg_clk;
Simon Glass748cd052012-12-13 20:48:46 +0000539 bd->bi_sccfreq = gd->arch.scc_clk;
540 bd->bi_vco = gd->arch.vco_out;
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500541#endif /* CONFIG_CPM2 */
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100542#if defined(CONFIG_MPC512X)
Simon Glassfefb0982012-12-13 20:48:54 +0000543 bd->bi_ipsfreq = gd->arch.ips_clk;
Grzegorz Bernacki281ff9a2008-01-08 17:16:15 +0100544#endif /* CONFIG_MPC512X */
wdenkcbd8a352004-02-24 02:00:03 +0000545#if defined(CONFIG_MPC5xxx)
Simon Glassb2877492012-12-13 20:48:53 +0000546 bd->bi_ipbfreq = gd->arch.ipb_clk;
wdenk945af8d2003-07-16 21:53:01 +0000547 bd->bi_pcifreq = gd->pci_clk;
wdenkcbd8a352004-02-24 02:00:03 +0000548#endif /* CONFIG_MPC5xxx */
wdenkfe8c2802002-11-03 00:38:21 +0000549 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
550
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200551#ifdef CONFIG_SYS_EXTBDINFO
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000552 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
553 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
554 sizeof(bd->bi_r_version));
wdenkfe8c2802002-11-03 00:38:21 +0000555
556 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
557 bd->bi_plb_busfreq = gd->bus_clk;
Stefan Roese343c48b2007-05-11 12:01:06 +0200558#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
559 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
560 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000561 bd->bi_pci_busfreq = get_PCI_freq();
562 bd->bi_opbfreq = get_OPB_freq();
Michal Simek9fea65a2008-06-24 09:54:09 +0200563#elif defined(CONFIG_XILINX_405)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000564 bd->bi_pci_busfreq = get_PCI_freq();
wdenkfe8c2802002-11-03 00:38:21 +0000565#endif
566#endif
567
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000568 debug("New Stack Pointer is: %08lx\n", addr_sp);
wdenkfe8c2802002-11-03 00:38:21 +0000569
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000570 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000571
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000572 gd->relocaddr = addr; /* Store relocation addr, useful for debug */
Richard Retanubun4b993272010-01-15 10:06:06 -0500573
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000574 memcpy(id, (void *) gd, sizeof(gd_t));
wdenkfe8c2802002-11-03 00:38:21 +0000575
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000576 relocate_code(addr_sp, id, addr);
wdenkfe8c2802002-11-03 00:38:21 +0000577
578 /* NOTREACHED - relocate_code() does not return */
579}
580
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000581/*
wdenkfe8c2802002-11-03 00:38:21 +0000582 * This is the next part if the initialization sequence: we are now
583 * running from RAM and have a "normal" C environment, i. e. global
584 * data can be written, BSS has been cleared, the stack size in not
585 * that critical any more, etc.
wdenkfe8c2802002-11-03 00:38:21 +0000586 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000587void board_init_r(gd_t *id, ulong dest_addr)
wdenkfe8c2802002-11-03 00:38:21 +0000588{
wdenkfe8c2802002-11-03 00:38:21 +0000589 bd_t *bd;
Peter Tysera483a162009-08-21 23:05:20 -0500590 ulong malloc_start;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000591
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200592#ifndef CONFIG_SYS_NO_FLASH
wdenkfe8c2802002-11-03 00:38:21 +0000593 ulong flash_size;
594#endif
595
596 gd = id; /* initialize RAM version of global data */
597 bd = gd->bd;
598
599 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
Grant Likelyf82b3b62007-07-03 00:34:19 -0600600
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500601 /* The Malloc area is immediately below the monitor copy in DRAM */
Peter Tysera483a162009-08-21 23:05:20 -0500602 malloc_start = dest_addr - TOTAL_MALLOC_LEN;
Kumar Gala13d46ab2009-09-01 21:07:08 -0500603
Peter Tyserf9476902009-12-15 12:10:47 -0600604#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
605 /*
Simon Glass67ac13b2012-12-13 20:48:48 +0000606 * The gd->arch.cpu pointer is set to an address in flash before
607 * relocation. We need to update it to point to the same CPU entry
608 * in RAM.
Peter Tyserf9476902009-12-15 12:10:47 -0600609 */
Simon Glass67ac13b2012-12-13 20:48:48 +0000610 gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
York Sun123bd962012-08-17 08:20:22 +0000611
612 /*
613 * If we didn't know the cpu mask & # cores, we can save them of
614 * now rather than 'computing' them constantly
615 */
616 fixup_cpu();
Peter Tyserf9476902009-12-15 12:10:47 -0600617#endif
618
Kumar Galaa55bb832010-11-29 14:32:11 -0600619#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
620 /*
621 * Some systems need to relocate the env_addr pointer early because the
622 * location it points to will get invalidated before env_relocate is
623 * called. One example is on systems that might use a L2 or L3 cache
624 * in SRAM mode and initialize that cache from SRAM mode back to being
625 * a cache in cpu_init_r.
626 */
627 gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
628#endif
629
Marian Balakowiczbb105f22006-06-30 15:27:09 +0200630 serial_initialize();
wdenkfe8c2802002-11-03 00:38:21 +0000631
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000632 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000633
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000634 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000635
Becky Bruced025aa42008-10-31 17:14:39 -0500636 /*
637 * Setup trap handlers
638 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000639 trap_init(dest_addr);
Becky Bruced025aa42008-10-31 17:14:39 -0500640
Becky Brucec9315e62009-02-03 18:10:52 -0600641#ifdef CONFIG_ADDR_MAP
Kumar Galaecf5b982008-12-16 14:59:20 -0600642 init_addr_map();
643#endif
644
wdenkc837dcb2004-01-20 23:12:12 +0000645#if defined(CONFIG_BOARD_EARLY_INIT_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000646 board_early_init_r();
wdenkc837dcb2004-01-20 23:12:12 +0000647#endif
648
wdenk3b57fe02003-05-30 12:48:29 +0000649 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkfe8c2802002-11-03 00:38:21 +0000650
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000651 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000652
wdenk56f94be2002-11-05 16:35:14 +0000653#ifdef CONFIG_LOGBUFFER
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000654 logbuff_init_ptrs();
wdenk56f94be2002-11-05 16:35:14 +0000655#endif
wdenkfe8c2802002-11-03 00:38:21 +0000656#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000657 post_output_backlog();
wdenkfe8c2802002-11-03 00:38:21 +0000658#endif
659
660 WATCHDOG_RESET();
661
Kim Phillips1a2e2032010-04-20 19:37:54 -0500662#if defined(CONFIG_SYS_DELAYED_ICACHE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000663 icache_enable(); /* it's time to enable the instruction cache */
wdenkfe8c2802002-11-03 00:38:21 +0000664#endif
665
Wolfgang Denk9c673522009-07-26 23:28:02 +0200666#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
667 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
wdenk42d1f032003-10-15 23:53:47 +0000668#endif
669
Andre Schwarz76221a62010-10-05 11:59:31 +0200670#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000671 /*
Andre Schwarz76221a62010-10-05 11:59:31 +0200672 * Do early PCI configuration _before_ the flash gets initialised,
673 * because PCU ressources are crucial for flash access on some boards.
wdenkfe8c2802002-11-03 00:38:21 +0000674 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000675 pci_init();
wdenk3bac3512003-03-12 10:41:04 +0000676#endif
Wolfgang Denk57d6c582010-11-23 23:17:18 +0100677#if defined(CONFIG_WINBOND_83C553)
wdenkfe8c2802002-11-03 00:38:21 +0000678 /*
679 * Initialise the ISA bridge
680 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000681 initialise_w83c553f();
wdenkfe8c2802002-11-03 00:38:21 +0000682#endif
683
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000684 asm("sync ; isync");
wdenkfe8c2802002-11-03 00:38:21 +0000685
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000686 mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
Stefan Roesec790b042009-05-11 15:50:12 +0200687
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200688#if !defined(CONFIG_SYS_NO_FLASH)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000689 puts("Flash: ");
wdenkfe8c2802002-11-03 00:38:21 +0000690
John Schmollerc62491d2010-09-29 14:05:44 -0500691 if (board_flash_wp_on()) {
692 printf("Uninitialized - Write Protect On\n");
693 /* Since WP is on, we can't find real size. Set to 0 */
694 flash_size = 0;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000695 } else if ((flash_size = flash_init()) > 0) {
696#ifdef CONFIG_SYS_FLASH_CHECKSUM
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000697 print_size(flash_size, "");
wdenkfe8c2802002-11-03 00:38:21 +0000698 /*
699 * Compute and print flash CRC if flashchecksum is set to 'y'
700 *
701 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
702 */
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600703 if (getenv_yesno("flashchecksum") == 1) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000704 printf(" CRC: %08X",
705 crc32(0,
706 (const unsigned char *)
707 CONFIG_SYS_FLASH_BASE, flash_size)
708 );
wdenkfe8c2802002-11-03 00:38:21 +0000709 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000710 putc('\n');
711#else /* !CONFIG_SYS_FLASH_CHECKSUM */
712 print_size(flash_size, "\n");
713#endif /* CONFIG_SYS_FLASH_CHECKSUM */
wdenkfe8c2802002-11-03 00:38:21 +0000714 } else {
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000715 puts(failed);
716 hang();
wdenkfe8c2802002-11-03 00:38:21 +0000717 }
718
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000719 /* update start of FLASH memory */
720 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
721 /* size of FLASH memory (final value) */
722 bd->bi_flashsize = flash_size;
Heiko Schocherfa230442006-12-21 17:17:02 +0100723
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200724#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
Heiko Schocherfa230442006-12-21 17:17:02 +0100725 /* Make a update of the Memctrl. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000726 update_flash_size(flash_size);
Heiko Schocherfa230442006-12-21 17:17:02 +0100727#endif
728
729
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000730#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
wdenk7e780362004-04-08 22:31:29 +0000731 /* flash mapped at end of memory map */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200732 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000733#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
734 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
735#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200736#endif /* !CONFIG_SYS_NO_FLASH */
wdenkfe8c2802002-11-03 00:38:21 +0000737
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000738 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000739
740 /* initialize higher level parts of CPU like time base and timers */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000741 cpu_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000742
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000743 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000744
wdenkfe8c2802002-11-03 00:38:21 +0000745#ifdef CONFIG_SPI
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000746#if !defined(CONFIG_ENV_IS_IN_EEPROM)
747 spi_init_f();
748#endif
749 spi_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000750#endif
751
Jon Loeliger7def6b32007-07-09 18:02:11 -0500752#if defined(CONFIG_CMD_NAND)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000753 WATCHDOG_RESET();
754 puts("NAND: ");
Stefan Roese887e2ec2006-09-07 11:51:23 +0200755 nand_init(); /* go init the NAND */
756#endif
757
Terry Lva8060352010-05-17 10:57:01 +0800758#ifdef CONFIG_GENERIC_MMC
759/*
760 * MMC initialization is called before relocating env.
761 * Thus It is required that operations like pin multiplexer
762 * be put in board_init.
763 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000764 WATCHDOG_RESET();
765 puts("MMC: ");
766 mmc_initialize(bd);
Terry Lva8060352010-05-17 10:57:01 +0800767#endif
768
wdenkfe8c2802002-11-03 00:38:21 +0000769 /* relocate environment function pointers etc. */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000770 env_relocate();
wdenkfe8c2802002-11-03 00:38:21 +0000771
772 /*
Kumar Galaf9a33f12011-02-02 11:23:50 -0600773 * after non-volatile devices & environment is setup and cpu code have
774 * another round to deal with any initialization that might require
775 * full access to the environment or loading of some image (firmware)
776 * from a non-volatile device
777 */
778 cpu_secondary_init_r();
779
780 /*
wdenkfe8c2802002-11-03 00:38:21 +0000781 * Fill in missing fields of bd_info.
wdenk8bde7f72003-06-27 21:31:46 +0000782 * We do this here, where we have "normal" access to the
783 * environment; we used to do this still running from ROM,
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200784 * where had to use getenv_f(), which can be pretty slow when
wdenk8bde7f72003-06-27 21:31:46 +0000785 * the environment is in EEPROM.
wdenkfe8c2802002-11-03 00:38:21 +0000786 */
wdenk7abf0c52004-04-18 21:45:42 +0000787
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200788#if defined(CONFIG_SYS_EXTBDINFO)
wdenk7abf0c52004-04-18 21:45:42 +0000789#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
790#if defined(CONFIG_I2CFAST)
791 /*
792 * set bi_iic_fast for linux taking environment variable
793 * "i2cfast" into account
794 */
795 {
Joe Hershbergerec8a2522012-12-11 22:16:22 -0600796 if (getenv_yesno("i2cfast") == 1) {
wdenk7abf0c52004-04-18 21:45:42 +0000797 bd->bi_iic_fast[0] = 1;
798 bd->bi_iic_fast[1] = 1;
wdenk7abf0c52004-04-18 21:45:42 +0000799 }
800 }
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000801#endif /* CONFIG_I2CFAST */
802#endif /* CONFIG_405GP, CONFIG_405EP */
803#endif /* CONFIG_SYS_EXTBDINFO */
wdenk7abf0c52004-04-18 21:45:42 +0000804
Wolfgang Denk9045f332007-06-08 10:24:58 +0200805#if defined(CONFIG_SC3)
Heiko Schocherca43ba12007-01-11 15:44:44 +0100806 sc3_read_eeprom();
807#endif
Haiying Wangd59feff2008-01-16 17:12:12 -0500808
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000809#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
Haiying Wangd59feff2008-01-16 17:12:12 -0500810 mac_read_from_eeprom();
811#endif
812
wdenkfe8c2802002-11-03 00:38:21 +0000813#ifdef CONFIG_HERMES
814 if ((gd->board_type >> 16) == 2)
815 bd->bi_ethspeed = gd->board_type & 0xFFFF;
816 else
817 bd->bi_ethspeed = 0xFFFF;
818#endif
819
Stefan Roese02a301c2009-02-25 12:11:15 +0100820#ifdef CONFIG_CMD_NET
Mike Frysingereb85aa52009-02-11 20:07:19 -0500821 /* kept around for legacy kernels only ... ignore the next section */
822 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
wdenke2ffd592004-12-31 09:32:47 +0000823#ifdef CONFIG_HAS_ETH1
Mike Frysingereb85aa52009-02-11 20:07:19 -0500824 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
wdenkfe8c2802002-11-03 00:38:21 +0000825#endif
wdenke2ffd592004-12-31 09:32:47 +0000826#ifdef CONFIG_HAS_ETH2
Mike Frysingereb85aa52009-02-11 20:07:19 -0500827 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
wdenkfe8c2802002-11-03 00:38:21 +0000828#endif
wdenke2ffd592004-12-31 09:32:47 +0000829#ifdef CONFIG_HAS_ETH3
Mike Frysingereb85aa52009-02-11 20:07:19 -0500830 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
wdenkba56f622004-02-06 23:19:44 +0000831#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400832#ifdef CONFIG_HAS_ETH4
Mike Frysingereb85aa52009-02-11 20:07:19 -0500833 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400834#endif
richardretanubunc68a05f2008-09-29 18:28:23 -0400835#ifdef CONFIG_HAS_ETH5
Mike Frysingereb85aa52009-02-11 20:07:19 -0500836 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
richardretanubunc68a05f2008-09-29 18:28:23 -0400837#endif
Stefan Roese02a301c2009-02-25 12:11:15 +0100838#endif /* CONFIG_CMD_NET */
richardretanubunc68a05f2008-09-29 18:28:23 -0400839
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000840 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000841
Andre Schwarz76221a62010-10-05 11:59:31 +0200842#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
wdenkfe8c2802002-11-03 00:38:21 +0000843 /*
844 * Do pci configuration
845 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000846 pci_init();
wdenkfe8c2802002-11-03 00:38:21 +0000847#endif
848
849/** leave this here (after malloc(), environment and PCI are working) **/
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200850 /* Initialize stdio devices */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000851 stdio_init();
wdenkfe8c2802002-11-03 00:38:21 +0000852
wdenk27b207f2003-07-24 23:38:38 +0000853 /* Initialize the jump table for applications */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000854 jumptable_init();
wdenkfe8c2802002-11-03 00:38:21 +0000855
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100856#if defined(CONFIG_API)
857 /* Initialize API */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000858 api_init();
Rafal Jaworowski500856e2008-01-09 19:39:36 +0100859#endif
860
wdenkfe8c2802002-11-03 00:38:21 +0000861 /* Initialize the console (after the relocation and devices init) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000862 console_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000863
Peter Tyser3a8f28d2009-09-16 22:03:07 -0500864#if defined(CONFIG_MISC_INIT_R)
wdenkfe8c2802002-11-03 00:38:21 +0000865 /* miscellaneous platform dependent initialisations */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000866 misc_init_r();
wdenkfe8c2802002-11-03 00:38:21 +0000867#endif
868
869#ifdef CONFIG_HERMES
870 if (bd->bi_ethspeed != 0xFFFF)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000871 hermes_start_lxt980((int) bd->bi_ethspeed);
wdenkfe8c2802002-11-03 00:38:21 +0000872#endif
873
Jon Loeliger7def6b32007-07-09 18:02:11 -0500874#if defined(CONFIG_CMD_KGDB)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000875 WATCHDOG_RESET();
876 puts("KGDB: ");
877 kgdb_init();
wdenkfe8c2802002-11-03 00:38:21 +0000878#endif
879
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000880 debug("U-Boot relocated to %08lx\n", dest_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000881
882 /*
883 * Enable Interrupts
884 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000885 interrupt_init();
wdenkfe8c2802002-11-03 00:38:21 +0000886
Heiko Schocher566a4942007-06-22 19:11:54 +0200887#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000888 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
wdenkfe8c2802002-11-03 00:38:21 +0000889#endif
890
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000891 udelay(20);
wdenkfe8c2802002-11-03 00:38:21 +0000892
wdenkfe8c2802002-11-03 00:38:21 +0000893 /* Initialize from environment */
Simon Glass12725922011-10-13 14:43:12 +0000894 load_addr = getenv_ulong("loadaddr", 16, load_addr);
wdenkfe8c2802002-11-03 00:38:21 +0000895
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000896 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000897
Jon Loeliger7def6b32007-07-09 18:02:11 -0500898#if defined(CONFIG_CMD_SCSI)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000899 WATCHDOG_RESET();
900 puts("SCSI: ");
901 scsi_init();
wdenkfe8c2802002-11-03 00:38:21 +0000902#endif
903
Jon Loeliger7def6b32007-07-09 18:02:11 -0500904#if defined(CONFIG_CMD_DOC)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000905 WATCHDOG_RESET();
906 puts("DOC: ");
907 doc_init();
wdenkfe8c2802002-11-03 00:38:21 +0000908#endif
909
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200910#ifdef CONFIG_BITBANGMII
911 bb_miiphy_init();
912#endif
Jon Loeliger7def6b32007-07-09 18:02:11 -0500913#if defined(CONFIG_CMD_NET)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000914 WATCHDOG_RESET();
915 puts("Net: ");
916 eth_initialize(bd);
wdenkfe8c2802002-11-03 00:38:21 +0000917#endif
918
Peter Tyser004eca02009-09-16 22:03:08 -0500919#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000920 WATCHDOG_RESET();
921 debug("Reset Ethernet PHY\n");
922 reset_phy();
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200923#endif
924
wdenkfe8c2802002-11-03 00:38:21 +0000925#ifdef CONFIG_POST
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000926 post_run(NULL, POST_RAM | post_bootmode_get(0));
wdenkfe8c2802002-11-03 00:38:21 +0000927#endif
928
Jon Loeliger7def6b32007-07-09 18:02:11 -0500929#if defined(CONFIG_CMD_PCMCIA) \
930 && !defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000931 WATCHDOG_RESET();
932 puts("PCMCIA:");
933 pcmcia_init();
wdenkfe8c2802002-11-03 00:38:21 +0000934#endif
935
Jon Loeliger7def6b32007-07-09 18:02:11 -0500936#if defined(CONFIG_CMD_IDE)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000937 WATCHDOG_RESET();
938#ifdef CONFIG_IDE_8xx_PCCARD
939 puts("PCMCIA:");
940#else
941 puts("IDE: ");
wdenkfe8c2802002-11-03 00:38:21 +0000942#endif
Heiko Schocherca43ba12007-01-11 15:44:44 +0100943#if defined(CONFIG_START_IDE)
944 if (board_start_ide())
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000945 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100946#else
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000947 ide_init();
Heiko Schocherca43ba12007-01-11 15:44:44 +0100948#endif
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500949#endif
wdenkfe8c2802002-11-03 00:38:21 +0000950
951#ifdef CONFIG_LAST_STAGE_INIT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000952 WATCHDOG_RESET();
wdenkfe8c2802002-11-03 00:38:21 +0000953 /*
954 * Some parts can be only initialized if all others (like
955 * Interrupts) are up and running (i.e. the PC-style ISA
956 * keyboard).
957 */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000958 last_stage_init();
wdenkfe8c2802002-11-03 00:38:21 +0000959#endif
960
Jon Loeliger7def6b32007-07-09 18:02:11 -0500961#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000962 WATCHDOG_RESET();
963 bedbug_init();
wdenkfe8c2802002-11-03 00:38:21 +0000964#endif
965
wdenk228f29a2002-12-08 09:53:23 +0000966#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkfe8c2802002-11-03 00:38:21 +0000967 /*
968 * Export available size of memory for Linux,
969 * taking into account the protected RAM at top of memory
970 */
971 {
Simon Glass12725922011-10-13 14:43:12 +0000972 ulong pram = 0;
Simon Glassd01b1762012-01-05 17:54:57 +0000973 char memsz[32];
wdenkfe8c2802002-11-03 00:38:21 +0000974
Simon Glass12725922011-10-13 14:43:12 +0000975#ifdef CONFIG_PRAM
976 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
wdenk228f29a2002-12-08 09:53:23 +0000977#endif
978#ifdef CONFIG_LOGBUFFER
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100979#ifndef CONFIG_ALT_LB_ADDR
wdenk228f29a2002-12-08 09:53:23 +0000980 /* Also take the logbuffer into account (pram is in kB) */
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000981 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
wdenk228f29a2002-12-08 09:53:23 +0000982#endif
Yuri Tikhonov3d610182008-02-06 18:48:36 +0100983#endif
Simon Glassd01b1762012-01-05 17:54:57 +0000984 sprintf(memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
985 setenv("mem", memsz);
wdenkfe8c2802002-11-03 00:38:21 +0000986 }
987#endif
988
wdenk1c437712004-01-16 00:30:56 +0000989#ifdef CONFIG_PS2KBD
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000990 puts("PS/2: ");
wdenk1c437712004-01-16 00:30:56 +0000991 kbd_init();
992#endif
993
wdenk4532cb62003-04-27 22:52:51 +0000994#ifdef CONFIG_MODEM_SUPPORT
Wolfgang Denk9b998b02011-11-04 15:55:07 +0000995 {
996 extern int do_mdm_init;
997
998 do_mdm_init = gd->do_mdm_init;
999 }
wdenk4532cb62003-04-27 22:52:51 +00001000#endif
1001
wdenkfe8c2802002-11-03 00:38:21 +00001002 /* Initialization complete - start the monitor */
1003
1004 /* main_loop() can return to retry autoboot, if so just run it again. */
1005 for (;;) {
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001006 WATCHDOG_RESET();
1007 main_loop();
wdenkfe8c2802002-11-03 00:38:21 +00001008 }
1009
1010 /* NOTREACHED - no way out of command loop except booting */
1011}
1012
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001013#if 0 /* We could use plain global data, but the resulting code is bigger */
wdenkfe8c2802002-11-03 00:38:21 +00001014/*
1015 * Pointer to initial global data area
1016 *
1017 * Here we initialize it.
1018 */
1019#undef XTRN_DECLARE_GLOBAL_DATA_PTR
1020#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
Wolfgang Denk9b998b02011-11-04 15:55:07 +00001021DECLARE_GLOBAL_DATA_PTR =
1022 (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
1023#endif /* 0 */
wdenkfe8c2802002-11-03 00:38:21 +00001024
1025/************************************************************************/