]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/x86/lib/board.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / arch / x86 / lib / board.c
1 /*
2  * (C) Copyright 2008-2011
3  * Graeme Russ, <graeme.russ@gmail.com>
4  *
5  * (C) Copyright 2002
6  * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
7  *
8  * (C) Copyright 2002
9  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
10  *
11  * (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 <fdtdec.h>
36 #include <watchdog.h>
37 #include <stdio_dev.h>
38 #include <asm/u-boot-x86.h>
39 #include <asm/relocate.h>
40 #include <asm/processor.h>
41
42 #include <asm/init_helpers.h>
43 #include <asm/init_wrappers.h>
44
45 /*
46  * Breath some life into the board...
47  *
48  * Getting the board up and running is a three-stage process:
49  *  1) Execute from Flash, SDRAM Uninitialised
50  *     At this point, there is a limited amount of non-SDRAM memory
51  *     (typically the CPU cache, but can also be SRAM or even a buffer of
52  *     of some peripheral). This limited memory is used to hold:
53  *      - The initial copy of the Global Data Structure
54  *      - A temporary stack
55  *      - A temporary x86 Global Descriptor Table
56  *      - The pre-console buffer (if enabled)
57  *
58  *     The following is performed during this phase of execution:
59  *      - Core low-level CPU initialisation
60  *      - Console initialisation
61  *      - SDRAM initialisation
62  *
63  *  2) Execute from Flash, SDRAM Initialised
64  *     At this point we copy Global Data from the initial non-SDRAM
65  *     memory and set up the permanent stack in SDRAM. The CPU cache is no
66  *     longer being used as temporary memory, so we can now fully enable
67  *     it.
68  *
69  *     The following is performed during this phase of execution:
70  *      - Create final stack in SDRAM
71  *      - Copy Global Data from temporary memory to SDRAM
72  *      - Enabling of CPU cache(s),
73  *      - Copying of U-Boot code and data from Flash to RAM
74  *      - Clearing of the BSS
75  *      - ELF relocation adjustments
76  *
77  *  3) Execute from SDRAM
78  *     The following is performed during this phase of execution:
79  *      - All remaining initialisation
80  */
81
82 /*
83  * The requirements for any new initalization function is simple: it is
84  * a function with no parameters which returns an integer return code,
85  * where 0 means "continue" and != 0 means "fatal error, hang the system"
86  */
87 typedef int (init_fnc_t) (void);
88
89 /*
90  * init_sequence_f is the list of init functions which are run when U-Boot
91  * is executing from Flash with a limited 'C' environment. The following
92  * limitations must be considered when implementing an '_f' function:
93  *  - 'static' variables are read-only
94  *  - Global Data (gd->xxx) is read/write
95  *  - Stack space is limited
96  *
97  * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_
98  * also initialise the console (to provide early debug output)
99  */
100 init_fnc_t *init_sequence_f[] = {
101         cpu_init_f,
102         board_early_init_f,
103 #ifdef CONFIG_OF_CONTROL
104         find_fdt,
105         fdtdec_check_fdt,
106 #endif
107         env_init,
108         init_baudrate_f,
109         serial_init,
110         console_init_f,
111 #ifdef CONFIG_OF_CONTROL
112         prepare_fdt,
113 #endif
114         dram_init_f,
115         calculate_relocation_address,
116
117         NULL,
118 };
119
120 /*
121  * init_sequence_f_r is the list of init functions which are run when
122  * U-Boot is executing from Flash with a semi-limited 'C' environment.
123  * The following limitations must be considered when implementing an
124  * '_f_r' function:
125  *  - 'static' variables are read-only
126  *  - Global Data (gd->xxx) is read/write
127  *
128  * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
129  * supported).  It _should_, if possible, copy global data to RAM and
130  * initialise the CPU caches (to speed up the relocation process)
131  */
132 init_fnc_t *init_sequence_f_r[] = {
133         init_cache_f_r,
134         copy_uboot_to_ram,
135         copy_fdt_to_ram,
136         clear_bss,
137         do_elf_reloc_fixups,
138
139         NULL,
140 };
141
142 /*
143  * init_sequence_r is the list of init functions which are run when U-Boot
144  * is executing from RAM with a full 'C' environment. There are no longer
145  * any limitations which must be considered when implementing an '_r'
146  * function, (i.e.'static' variables are read/write)
147  *
148  * If not already done, the '_r' sequence must copy global data to RAM and
149  * (should) initialise the CPU caches.
150  */
151 init_fnc_t *init_sequence_r[] = {
152         set_reloc_flag_r,
153         init_bd_struct_r,
154         mem_malloc_init_r,
155         cpu_init_r,
156         board_early_init_r,
157         dram_init,
158         interrupt_init,
159         timer_init,
160         display_banner,
161         display_dram_config,
162         serial_initialize_r,
163 #ifndef CONFIG_SYS_NO_FLASH
164         flash_init_r,
165 #endif
166 #ifdef CONFIG_SPI
167         init_func_spi;
168 #endif
169         env_relocate_r,
170 #ifdef CONFIG_PCI
171         pci_init_r,
172 #endif
173         stdio_init,
174         jumptable_init_r,
175         console_init_r,
176 #ifdef CONFIG_MISC_INIT_R
177         misc_init_r,
178 #endif
179 #if defined(CONFIG_CMD_KGDB)
180         kgdb_init_r,
181 #endif
182         enable_interrupts_r,
183 #ifdef CONFIG_STATUS_LED
184         status_led_set_r,
185 #endif
186         set_load_addr_r,
187 #if defined(CONFIG_CMD_IDE)
188         ide_init_r,
189 #endif
190 #if defined(CONFIG_CMD_SCSI)
191         scsi_init_r,
192 #endif
193 #if defined(CONFIG_CMD_DOC)
194         doc_init_r,
195 #endif
196 #ifdef CONFIG_BITBANGMII
197         bb_miiphy_init_r,
198 #endif
199 #if defined(CONFIG_CMD_NET)
200         eth_initialize_r,
201 #ifdef CONFIG_RESET_PHY_R
202         reset_phy_r,
203 #endif
204 #endif
205 #ifdef CONFIG_LAST_STAGE_INIT
206         last_stage_init,
207 #endif
208         NULL,
209 };
210
211 static void do_init_loop(init_fnc_t **init_fnc_ptr)
212 {
213         for (; *init_fnc_ptr; ++init_fnc_ptr) {
214                 WATCHDOG_RESET();
215                 if ((*init_fnc_ptr)() != 0)
216                         hang();
217         }
218 }
219
220 void board_init_f(ulong boot_flags)
221 {
222         gd->fdt_blob = gd->arch.new_fdt = NULL;
223         gd->flags = boot_flags;
224
225         do_init_loop(init_sequence_f);
226
227         /*
228          * SDRAM and console are now initialised. The final stack can now
229          * be setup in SDRAM. Code execution will continue in Flash, but
230          * with the stack in SDRAM and Global Data in temporary memory
231          * (CPU cache)
232          */
233         board_init_f_r_trampoline(gd->start_addr_sp);
234
235         /* NOTREACHED - board_init_f_r_trampoline() does not return */
236         while (1)
237                 ;
238 }
239
240 void board_init_f_r(void)
241 {
242         do_init_loop(init_sequence_f_r);
243
244         /*
245          * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
246          * Transfer execution from Flash to RAM by calculating the address
247          * of the in-RAM copy of board_init_r() and calling it
248          */
249         (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
250
251         /* NOTREACHED - board_init_r() does not return */
252         while (1)
253                 ;
254 }
255
256 void board_init_r(gd_t *id, ulong dest_addr)
257 {
258         do_init_loop(init_sequence_r);
259
260         /* main_loop() can return to retry autoboot, if so just run it again. */
261         for (;;)
262                 main_loop();
263
264         /* NOTREACHED - no way out of command loop except booting */
265 }
266
267 void hang(void)
268 {
269         puts("### ERROR ### Please RESET the board ###\n");
270         for (;;)
271                 ;
272 }