2 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
6 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
9 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
12 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13 * Marius Groeger <mgroeger@sysgo.de>
15 * See file CREDITS for list of people who contributed to this
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.
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.
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,
36 #include <stdio_dev.h>
37 #include <asm/u-boot-x86.h>
38 #include <asm/relocate.h>
40 #include <asm/init_helpers.h>
41 #include <asm/init_wrappers.h>
44 * Breath some life into the board...
46 * Getting the board up and running is a three-stage process:
47 * 1) Execute from Flash, SDRAM Uninitialised
48 * At this point, there is a limited amount of non-SDRAM memory
49 * (typically the CPU cache, but can also be SRAM or even a buffer of
50 * of some peripheral). This limited memory is used to hold:
51 * - The initial copy of the Global Data Structure
53 * - A temporary x86 Global Descriptor Table
54 * - The pre-console buffer (if enabled)
56 * The following is performed during this phase of execution:
57 * - Core low-level CPU initialisation
58 * - Console initialisation
59 * - SDRAM initialisation
61 * 2) Execute from Flash, SDRAM Initialised
62 * At this point we copy Global Data from the initial non-SDRAM
63 * memory and set up the permanent stack in SDRAM. The CPU cache is no
64 * longer being used as temporary memory, so we can now fully enable
67 * The following is performed during this phase of execution:
68 * - Create final stack in SDRAM
69 * - Copy Global Data from temporary memory to SDRAM
70 * - Enabling of CPU cache(s),
71 * - Copying of U-Boot code and data from Flash to RAM
72 * - Clearing of the BSS
73 * - ELF relocation adjustments
75 * 3) Execute from SDRAM
76 * The following is performed during this phase of execution:
77 * - All remaining initialisation
81 * The requirements for any new initalization function is simple: it is
82 * a function with no parameters which returns an integer return code,
83 * where 0 means "continue" and != 0 means "fatal error, hang the system"
85 typedef int (init_fnc_t) (void);
88 * init_sequence_f is the list of init functions which are run when U-Boot
89 * is executing from Flash with a limited 'C' environment. The following
90 * limitations must be considered when implementing an '_f' function:
91 * - 'static' variables are read-only
92 * - Global Data (gd->xxx) is read/write
93 * - Stack space is limited
95 * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_
96 * also initialise the console (to provide early debug output)
98 init_fnc_t *init_sequence_f[] = {
106 calculate_relocation_address,
112 * init_sequence_f_r is the list of init functions which are run when
113 * U-Boot is executing from Flash with a semi-limited 'C' environment.
114 * The following limitations must be considered when implementing an
116 * - 'static' variables are read-only
117 * - Global Data (gd->xxx) is read/write
119 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
120 * supported). It _should_, if possible, copy global data to RAM and
121 * initialise the CPU caches (to speed up the relocation process)
123 init_fnc_t *init_sequence_f_r[] = {
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)
139 * If not already done, the '_r' sequence must copy global data to RAM and
140 * (should) initialise the CPU caches.
142 init_fnc_t *init_sequence_r[] = {
154 #ifndef CONFIG_SYS_NO_FLASH
164 #ifdef CONFIG_MISC_INIT_R
167 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
170 #if defined(CONFIG_CMD_KGDB)
174 #ifdef CONFIG_STATUS_LED
178 #if defined(CONFIG_CMD_IDE)
181 #if defined(CONFIG_CMD_SCSI)
184 #if defined(CONFIG_CMD_DOC)
187 #ifdef CONFIG_BITBANGMII
190 #if defined(CONFIG_CMD_NET)
192 #ifdef CONFIG_RESET_PHY_R
196 #ifdef CONFIG_LAST_STAGE_INIT
202 static void do_init_loop(init_fnc_t **init_fnc_ptr)
204 for (; *init_fnc_ptr; ++init_fnc_ptr) {
206 if ((*init_fnc_ptr)() != 0)
211 void board_init_f(ulong boot_flags)
213 gd->flags = boot_flags;
215 do_init_loop(init_sequence_f);
218 * 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
223 board_init_f_r_trampoline(gd->start_addr_sp);
225 /* NOTREACHED - board_init_f_r_trampoline() does not return */
230 void board_init_f_r(void)
232 do_init_loop(init_sequence_f_r);
235 * 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
239 (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
241 /* NOTREACHED - board_init_r() does not return */
246 void board_init_r(gd_t *id, ulong dest_addr)
248 do_init_loop(init_sequence_r);
250 /* main_loop() can return to retry autoboot, if so just run it again. */
254 /* NOTREACHED - no way out of command loop except booting */
259 puts("### ERROR ### Please RESET the board ###\n");