blob: 90cf7fc8883c2ee02a0b22361b69a1905f214b4b [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
Graeme Russdbf71152011-04-13 19:43:26 +10002 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
wdenk8bde7f72003-06-27 21:31:46 +00004 *
wdenk2262cfe2002-11-18 00:14:45 +00005 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02006 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
Graeme Russdbf71152011-04-13 19:43:26 +10007 *
8 * (C) Copyright 2002
9 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
wdenk8bde7f72003-06-27 21:31:46 +000010 *
wdenk2262cfe2002-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-VILLARD52cb4d42009-05-16 12:14:54 +020036#include <stdio_dev.h>
Graeme Russfea25722011-04-13 19:43:28 +100037#include <asm/u-boot-x86.h>
Graeme Russa1d57b72011-12-23 21:14:22 +110038#include <asm/relocate.h>
wdenk2262cfe2002-11-18 00:14:45 +000039
Graeme Russd47ab0e2011-12-23 16:51:29 +110040#include <asm/init_helpers.h>
41#include <asm/init_wrappers.h>
wdenk2262cfe2002-11-18 00:14:45 +000042
wdenk2262cfe2002-11-18 00:14:45 +000043/*
44 * Breath some life into the board...
45 *
Graeme Russa1d57b72011-12-23 21:14:22 +110046 * 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
52 * - A temporary stack
53 * - A temporary x86 Global Descriptor Table
54 * - The pre-console buffer (if enabled)
wdenk2262cfe2002-11-18 00:14:45 +000055 *
Graeme Russa1d57b72011-12-23 21:14:22 +110056 * The following is performed during this phase of execution:
57 * - Core low-level CPU initialisation
58 * - Console initialisation
59 * - SDRAM initialisation
60 *
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
65 * it.
66 *
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
74 *
75 * 3) Execute from SDRAM
76 * The following is performed during this phase of execution:
77 * - All remaining initialisation
wdenk2262cfe2002-11-18 00:14:45 +000078 */
79
80/*
Graeme Russa1d57b72011-12-23 21:14:22 +110081 * 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"
wdenk2262cfe2002-11-18 00:14:45 +000084 */
85typedef int (init_fnc_t) (void);
86
Graeme Russa1d57b72011-12-23 21:14:22 +110087/*
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
94 *
95 * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_
96 * also initialise the console (to provide early debug output)
97 */
Graeme Russe4f78d72011-02-12 15:12:10 +110098init_fnc_t *init_sequence_f[] = {
99 cpu_init_f,
100 board_early_init_f,
101 env_init,
Graeme Russd47ab0e2011-12-23 16:51:29 +1100102 init_baudrate_f,
Graeme Russe4f78d72011-02-12 15:12:10 +1100103 serial_init,
104 console_init_f,
105 dram_init_f,
106 calculate_relocation_address,
Graeme Russe4f78d72011-02-12 15:12:10 +1100107
108 NULL,
109};
110
Graeme Russa1d57b72011-12-23 21:14:22 +1100111/*
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
115 * '_f_r' function:
116 * - 'static' variables are read-only
117 * - Global Data (gd->xxx) is read/write
118 *
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)
122 */
123init_fnc_t *init_sequence_f_r[] = {
124 copy_gd_to_ram_f_r,
125 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 Russe4f78d72011-02-12 15:12:10 +1100142init_fnc_t *init_sequence_r[] = {
Graeme Russa1d57b72011-12-23 21:14:22 +1100143 set_reloc_flag_r,
Graeme Russd47ab0e2011-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,
wdenk8bde7f72003-06-27 21:31:46 +0000150 timer_init,
wdenk2262cfe2002-11-18 00:14:45 +0000151 display_banner,
152 display_dram_config,
Graeme Russd47ab0e2011-12-23 16:51:29 +1100153#ifdef CONFIG_SERIAL_MULTI
154 serial_initialize_r,
155#endif
156#ifndef CONFIG_SYS_NO_FLASH
157 flash_init_r,
158#endif
159 env_relocate_r,
Graeme Russd47ab0e2011-12-23 16:51:29 +1100160#ifdef CONFIG_PCI
161 pci_init_r,
162#endif
163 stdio_init,
164 jumptable_init_r,
165 console_init_r,
166#ifdef CONFIG_MISC_INIT_R
167 misc_init_r,
168#endif
169#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
170 pci_init_r,
171#endif
172#if defined(CONFIG_CMD_KGDB)
173 kgdb_init_r,
174#endif
175 enable_interrupts_r,
176#ifdef CONFIG_STATUS_LED
177 status_led_set_r,
178#endif
179 set_load_addr_r,
Graeme Russd47ab0e2011-12-23 16:51:29 +1100180#if defined(CONFIG_CMD_IDE)
181 ide_init_r,
182#endif
183#if defined(CONFIG_CMD_SCSI)
184 scsi_init_r,
185#endif
186#if defined(CONFIG_CMD_DOC)
187 doc_init_r,
188#endif
189#ifdef CONFIG_BITBANGMII
190 bb_miiphy_init_r,
191#endif
192#if defined(CONFIG_CMD_NET)
193 eth_initialize_r,
194#ifdef CONFIG_RESET_PHY_R
195 reset_phy_r,
196#endif
197#endif
198#ifdef CONFIG_LAST_STAGE_INIT
199 last_stage_init,
200#endif
wdenk2262cfe2002-11-18 00:14:45 +0000201 NULL,
202};
203
Graeme Russd47ab0e2011-12-23 16:51:29 +1100204static void do_init_loop(init_fnc_t **init_fnc_ptr)
205{
206 for (; *init_fnc_ptr; ++init_fnc_ptr) {
207 WATCHDOG_RESET();
208 if ((*init_fnc_ptr)() != 0)
209 hang();
210 }
211}
212
Graeme Russ96cd6642011-02-12 15:11:54 +1100213void board_init_f(ulong boot_flags)
Graeme Russ1c409bc2009-11-24 20:04:21 +1100214{
Graeme Russdbf71152011-04-13 19:43:26 +1000215 gd->flags = boot_flags;
216
Graeme Russd47ab0e2011-12-23 16:51:29 +1100217 do_init_loop(init_sequence_f);
Graeme Russf2ff75c2010-10-07 20:03:33 +1100218
Graeme Russf48dd6f2012-01-01 15:06:39 +1100219 /*
Graeme Russa1d57b72011-12-23 21:14:22 +1100220 * SDRAM and console are now initialised. The final stack can now
221 * be setup in SDRAM. Code execution will continue in Flash, but
222 * with the stack in SDRAM and Global Data in temporary memory
Graeme Russf48dd6f2012-01-01 15:06:39 +1100223 * (CPU cache)
224 */
225 board_init_f_r_trampoline(gd->start_addr_sp);
Graeme Russ161b3582010-10-07 20:03:29 +1100226
Graeme Russf48dd6f2012-01-01 15:06:39 +1100227 /* NOTREACHED - board_init_f_r_trampoline() does not return */
228 while (1)
229 ;
230}
231
232void board_init_f_r(void)
233{
Graeme Russa1d57b72011-12-23 21:14:22 +1100234 do_init_loop(init_sequence_f_r);
Graeme Russ98f1fa92011-12-27 22:46:42 +1100235
Graeme Russa1d57b72011-12-23 21:14:22 +1100236 /*
237 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
238 * Transfer execution from Flash to RAM by calculating the address
239 * of the in-RAM copy of board_init_r() and calling it
240 */
241 (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
Graeme Russ98f1fa92011-12-27 22:46:42 +1100242
Graeme Russa1d57b72011-12-23 21:14:22 +1100243 /* NOTREACHED - board_init_r() does not return */
Graeme Russ83088af2011-11-08 02:33:15 +0000244 while (1)
245 ;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100246}
247
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000248void board_init_r(gd_t *id, ulong dest_addr)
wdenk2262cfe2002-11-18 00:14:45 +0000249{
Graeme Russd47ab0e2011-12-23 16:51:29 +1100250 do_init_loop(init_sequence_r);
wdenk8bde7f72003-06-27 21:31:46 +0000251
wdenk2262cfe2002-11-18 00:14:45 +0000252 /* main_loop() can return to retry autoboot, if so just run it again. */
Graeme Russ83088af2011-11-08 02:33:15 +0000253 for (;;)
wdenk7a8e9bed2003-05-31 18:35:21 +0000254 main_loop();
wdenk2262cfe2002-11-18 00:14:45 +0000255
256 /* NOTREACHED - no way out of command loop except booting */
257}
258
Graeme Russ83088af2011-11-08 02:33:15 +0000259void hang(void)
wdenk2262cfe2002-11-18 00:14:45 +0000260{
Graeme Russ83088af2011-11-08 02:33:15 +0000261 puts("### ERROR ### Please RESET the board ###\n");
262 for (;;)
263 ;
wdenk2262cfe2002-11-18 00:14:45 +0000264}