blob: 2ffe0614dc91096ab227f6bd218211c889ed7688 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
Graeme Russ45fc1d82011-04-13 19:43:26 +10002 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
4 *
wdenk591dda52002-11-18 00:14:45 +00005 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02006 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk57b2d802003-06-27 21:31:46 +00007 *
wdenk591dda52002-11-18 00:14:45 +00008 * (C) Copyright 2002
Graeme Russ45fc1d82011-04-13 19:43:26 +10009 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
wdenk57b2d802003-06-27 21:31:46 +000010 *
wdenk591dda52002-11-18 00:14:45 +000011 * (C) Copyright 2002
12 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13 * Marius Groeger <mgroeger@sysgo.de>
14 *
15 * See file CREDITS for list of people who contributed to this
16 * project.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * MA 02111-1307 USA
32 */
33
34#include <common.h>
35#include <watchdog.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020036#include <stdio_dev.h>
Graeme Russcbfce1d2011-04-13 19:43:28 +100037#include <asm/u-boot-x86.h>
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110038#include <asm/relocate.h>
Graeme Russ007818a2012-11-27 15:38:36 +000039#include <asm/processor.h>
wdenk591dda52002-11-18 00:14:45 +000040
Graeme Russa875dda2011-12-23 16:51:29 +110041#include <asm/init_helpers.h>
42#include <asm/init_wrappers.h>
wdenk591dda52002-11-18 00:14:45 +000043
wdenk591dda52002-11-18 00:14:45 +000044/*
45 * Breath some life into the board...
46 *
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110047 * Getting the board up and running is a three-stage process:
48 * 1) Execute from Flash, SDRAM Uninitialised
49 * At this point, there is a limited amount of non-SDRAM memory
50 * (typically the CPU cache, but can also be SRAM or even a buffer of
51 * of some peripheral). This limited memory is used to hold:
52 * - The initial copy of the Global Data Structure
53 * - A temporary stack
54 * - A temporary x86 Global Descriptor Table
55 * - The pre-console buffer (if enabled)
wdenk591dda52002-11-18 00:14:45 +000056 *
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110057 * The following is performed during this phase of execution:
58 * - Core low-level CPU initialisation
59 * - Console initialisation
60 * - SDRAM initialisation
61 *
62 * 2) Execute from Flash, SDRAM Initialised
63 * At this point we copy Global Data from the initial non-SDRAM
64 * memory and set up the permanent stack in SDRAM. The CPU cache is no
65 * longer being used as temporary memory, so we can now fully enable
66 * it.
67 *
68 * The following is performed during this phase of execution:
69 * - Create final stack in SDRAM
70 * - Copy Global Data from temporary memory to SDRAM
71 * - Enabling of CPU cache(s),
72 * - Copying of U-Boot code and data from Flash to RAM
73 * - Clearing of the BSS
74 * - ELF relocation adjustments
75 *
76 * 3) Execute from SDRAM
77 * The following is performed during this phase of execution:
78 * - All remaining initialisation
wdenk591dda52002-11-18 00:14:45 +000079 */
80
81/*
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110082 * The requirements for any new initalization function is simple: it is
83 * a function with no parameters which returns an integer return code,
84 * where 0 means "continue" and != 0 means "fatal error, hang the system"
wdenk591dda52002-11-18 00:14:45 +000085 */
86typedef int (init_fnc_t) (void);
87
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110088/*
89 * init_sequence_f is the list of init functions which are run when U-Boot
90 * is executing from Flash with a limited 'C' environment. The following
91 * limitations must be considered when implementing an '_f' function:
92 * - 'static' variables are read-only
93 * - Global Data (gd->xxx) is read/write
94 * - Stack space is limited
95 *
96 * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_
97 * also initialise the console (to provide early debug output)
98 */
Graeme Russ6ec93c32011-02-12 15:12:10 +110099init_fnc_t *init_sequence_f[] = {
100 cpu_init_f,
101 board_early_init_f,
102 env_init,
Graeme Russa875dda2011-12-23 16:51:29 +1100103 init_baudrate_f,
Graeme Russ6ec93c32011-02-12 15:12:10 +1100104 serial_init,
105 console_init_f,
106 dram_init_f,
107 calculate_relocation_address,
Graeme Russ6ec93c32011-02-12 15:12:10 +1100108
109 NULL,
110};
111
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100112/*
113 * init_sequence_f_r is the list of init functions which are run when
114 * U-Boot is executing from Flash with a semi-limited 'C' environment.
115 * The following limitations must be considered when implementing an
116 * '_f_r' function:
117 * - 'static' variables are read-only
118 * - Global Data (gd->xxx) is read/write
119 *
120 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
121 * supported). It _should_, if possible, copy global data to RAM and
122 * initialise the CPU caches (to speed up the relocation process)
123 */
124init_fnc_t *init_sequence_f_r[] = {
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100125 init_cache_f_r,
126 copy_uboot_to_ram,
127 clear_bss,
128 do_elf_reloc_fixups,
129
130 NULL,
131};
132
133/*
134 * init_sequence_r is the list of init functions which are run when U-Boot
135 * is executing from RAM with a full 'C' environment. There are no longer
136 * any limitations which must be considered when implementing an '_r'
137 * function, (i.e.'static' variables are read/write)
138 *
139 * If not already done, the '_r' sequence must copy global data to RAM and
140 * (should) initialise the CPU caches.
141 */
Graeme Russ6ec93c32011-02-12 15:12:10 +1100142init_fnc_t *init_sequence_r[] = {
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100143 set_reloc_flag_r,
Graeme Russa875dda2011-12-23 16:51:29 +1100144 init_bd_struct_r,
145 mem_malloc_init_r,
146 cpu_init_r,
147 board_early_init_r,
148 dram_init,
149 interrupt_init,
wdenk57b2d802003-06-27 21:31:46 +0000150 timer_init,
wdenk591dda52002-11-18 00:14:45 +0000151 display_banner,
152 display_dram_config,
Graeme Russa875dda2011-12-23 16:51:29 +1100153 serial_initialize_r,
Graeme Russa875dda2011-12-23 16:51:29 +1100154#ifndef CONFIG_SYS_NO_FLASH
155 flash_init_r,
156#endif
Gabe Blacka97cbda2012-11-03 11:41:23 +0000157#ifdef CONFIG_SPI
158 init_func_spi;
159#endif
Graeme Russa875dda2011-12-23 16:51:29 +1100160 env_relocate_r,
Graeme Russa875dda2011-12-23 16:51:29 +1100161#ifdef CONFIG_PCI
162 pci_init_r,
163#endif
164 stdio_init,
165 jumptable_init_r,
166 console_init_r,
167#ifdef CONFIG_MISC_INIT_R
168 misc_init_r,
169#endif
Graeme Russa875dda2011-12-23 16:51:29 +1100170#if defined(CONFIG_CMD_KGDB)
171 kgdb_init_r,
172#endif
173 enable_interrupts_r,
174#ifdef CONFIG_STATUS_LED
175 status_led_set_r,
176#endif
177 set_load_addr_r,
Graeme Russa875dda2011-12-23 16:51:29 +1100178#if defined(CONFIG_CMD_IDE)
179 ide_init_r,
180#endif
181#if defined(CONFIG_CMD_SCSI)
182 scsi_init_r,
183#endif
184#if defined(CONFIG_CMD_DOC)
185 doc_init_r,
186#endif
187#ifdef CONFIG_BITBANGMII
188 bb_miiphy_init_r,
189#endif
190#if defined(CONFIG_CMD_NET)
191 eth_initialize_r,
192#ifdef CONFIG_RESET_PHY_R
193 reset_phy_r,
194#endif
195#endif
196#ifdef CONFIG_LAST_STAGE_INIT
197 last_stage_init,
198#endif
wdenk591dda52002-11-18 00:14:45 +0000199 NULL,
200};
201
Graeme Russa875dda2011-12-23 16:51:29 +1100202static void do_init_loop(init_fnc_t **init_fnc_ptr)
203{
204 for (; *init_fnc_ptr; ++init_fnc_ptr) {
205 WATCHDOG_RESET();
206 if ((*init_fnc_ptr)() != 0)
207 hang();
208 }
209}
210
Graeme Russ4b259822011-02-12 15:12:06 +1100211void board_init_f(ulong boot_flags)
212{
Graeme Russ45fc1d82011-04-13 19:43:26 +1000213 gd->flags = boot_flags;
214
Graeme Russa875dda2011-12-23 16:51:29 +1100215 do_init_loop(init_sequence_f);
Graeme Russ078395c2009-11-24 20:04:21 +1100216
Graeme Russd7755b42012-01-01 15:06:39 +1100217 /*
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100218 * SDRAM and console are now initialised. The final stack can now
219 * be setup in SDRAM. Code execution will continue in Flash, but
220 * with the stack in SDRAM and Global Data in temporary memory
Graeme Russd7755b42012-01-01 15:06:39 +1100221 * (CPU cache)
222 */
223 board_init_f_r_trampoline(gd->start_addr_sp);
224
225 /* NOTREACHED - board_init_f_r_trampoline() does not return */
226 while (1)
227 ;
228}
229
230void board_init_f_r(void)
231{
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100232 do_init_loop(init_sequence_f_r);
Graeme Russ35368962011-12-31 22:58:15 +1100233
234 /*
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100235 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
236 * Transfer execution from Flash to RAM by calculating the address
237 * of the in-RAM copy of board_init_r() and calling it
Graeme Russ35368962011-12-31 22:58:15 +1100238 */
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100239 (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
Graeme Russ35368962011-12-31 22:58:15 +1100240
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100241 /* NOTREACHED - board_init_r() does not return */
242 while (1)
243 ;
Graeme Russ35368962011-12-31 22:58:15 +1100244}
245
Graeme Russe07da072010-04-24 00:05:44 +1000246void board_init_r(gd_t *id, ulong dest_addr)
wdenk591dda52002-11-18 00:14:45 +0000247{
Graeme Russa875dda2011-12-23 16:51:29 +1100248 do_init_loop(init_sequence_r);
wdenk57b2d802003-06-27 21:31:46 +0000249
wdenk591dda52002-11-18 00:14:45 +0000250 /* main_loop() can return to retry autoboot, if so just run it again. */
Graeme Russ883c6032011-11-08 02:33:15 +0000251 for (;;)
wdenkabda5ca2003-05-31 18:35:21 +0000252 main_loop();
wdenk591dda52002-11-18 00:14:45 +0000253
254 /* NOTREACHED - no way out of command loop except booting */
255}
256
Graeme Russ883c6032011-11-08 02:33:15 +0000257void hang(void)
wdenk591dda52002-11-18 00:14:45 +0000258{
Graeme Russ883c6032011-11-08 02:33:15 +0000259 puts("### ERROR ### Please RESET the board ###\n");
260 for (;;)
261 ;
wdenk591dda52002-11-18 00:14:45 +0000262}