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,
37 #include <stdio_dev.h>
43 #include <asm/u-boot-x86.h>
44 #include <asm/processor.h>
46 #ifdef CONFIG_BITBANGMII
50 /************************************************************************
52 ************************************************************************
53 * Some of this code should be moved into the core functions,
54 * or dropped completely,
55 * but let's get it working (again) first...
57 static int init_baudrate(void)
59 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
63 static int display_banner(void)
66 printf("\n\n%s\n\n", version_string);
71 static int display_dram_config(void)
75 puts("DRAM Configuration:\n");
77 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
78 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
79 print_size(gd->bd->bi_dram[i].size, "\n");
85 #ifndef CONFIG_SYS_NO_FLASH
86 static void display_flash_config(ulong size)
89 print_size(size, "\n");
94 * Breath some life into the board...
96 * Initialize an SMC for serial comms, and carry out some hardware
99 * The first part of initialization is running from Flash memory;
100 * its main purpose is to initialize the RAM so that we
101 * can relocate the monitor code to RAM.
105 * All attempts to come up with a "common" initialization sequence
106 * that works for all boards and architectures failed: some of the
107 * requirements are just _too_ different. To get rid of the resulting
108 * mess of board dependend #ifdef'ed code we now make the whole
109 * initialization sequence configurable to the user.
111 * The requirements for any new initalization function is simple: it
112 * receives a pointer to the "global data" structure as it's only
113 * argument, and returns an integer return code, where 0 means
114 * "continue" and != 0 means "fatal error, hang the system".
116 typedef int (init_fnc_t) (void);
118 static int calculate_relocation_address(void);
119 static int copy_gd_to_ram(void);
121 init_fnc_t *init_sequence_f[] = {
129 calculate_relocation_address,
134 init_fnc_t *init_sequence_r[] = {
135 cpu_init_r, /* basic cpu dependent setup */
136 board_early_init_r, /* basic board dependent setup */
137 dram_init, /* configure available RAM banks */
138 interrupt_init, /* set up exceptions */
146 static int calculate_relocation_address(void)
148 ulong text_start = (ulong)&__text_start;
149 ulong bss_end = (ulong)&__bss_end;
153 * NOTE: All destination address are rounded down to 16-byte
154 * boundary to satisfy various worst-case alignment
158 /* Global Data is at top of available memory */
159 dest_addr = gd->ram_size;
160 dest_addr -= GENERATED_GBL_DATA_SIZE;
162 gd->new_gd_addr = dest_addr;
164 /* GDT is below Global Data */
165 dest_addr -= X86_GDT_SIZE;
167 gd->gdt_addr = dest_addr;
169 /* Stack is below GDT */
170 gd->start_addr_sp = dest_addr;
172 /* U-Boot is below the stack */
173 dest_addr -= CONFIG_SYS_STACK_SIZE;
174 dest_addr -= (bss_end - text_start);
176 gd->relocaddr = dest_addr;
177 gd->reloc_off = (dest_addr - text_start);
182 /* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */
183 void board_init_f(ulong boot_flags)
185 init_fnc_t **init_fnc_ptr;
187 gd->flags = boot_flags;
189 for (init_fnc_ptr = init_sequence_f; *init_fnc_ptr; ++init_fnc_ptr) {
190 if ((*init_fnc_ptr)() != 0)
195 * SDRAM is now initialised, U-Boot has been copied into SDRAM,
196 * the BSS has been cleared etc. The final stack can now be setup
197 * in SDRAM. Code execution will continue (momentarily) in Flash,
198 * but with the stack in SDRAM and Global Data in temporary memory
201 board_init_f_r_trampoline(gd->start_addr_sp);
203 /* NOTREACHED - board_init_f_r_trampoline() does not return */
208 void board_init_f_r(void)
210 if (copy_gd_to_ram() != 0)
213 if (init_cache() != 0)
216 relocate_code(0, gd, 0);
218 /* NOTREACHED - relocate_code() does not return */
223 static int copy_gd_to_ram(void)
228 * Global data is still in temporary memory (the CPU cache).
229 * calculate_relocation_address() has set gd->new_gd_addr to
230 * where the global data lives in RAM but getting it there
231 * safely is a bit tricky due to the 'F-Segment Hack' that
232 * we need to use for x86
234 ram_gd = (gd_t *)gd->new_gd_addr;
235 memcpy((void *)ram_gd, gd, sizeof(gd_t));
238 * Reload the Global Descriptor Table so FS points to the
239 * in-RAM copy of Global Data (calculate_relocation_address()
240 * has already calculated the in-RAM location of the GDT)
242 ram_gd->gd_addr = (ulong)ram_gd;
243 init_gd(ram_gd, (u64 *)gd->gdt_addr);
248 void board_init_r(gd_t *id, ulong dest_addr)
250 #if defined(CONFIG_CMD_NET)
253 #ifndef CONFIG_SYS_NO_FLASH
257 init_fnc_t **init_fnc_ptr;
259 show_boot_progress(0x21);
261 /* compiler optimization barrier needed for GCC >= 3.4 */
262 __asm__ __volatile__("" : : : "memory");
264 gd->flags |= GD_FLG_RELOC;
267 memset(gd->bd, 0, sizeof(bd_t));
268 show_boot_progress(0x22);
270 gd->baudrate = CONFIG_BAUDRATE;
272 mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
273 CONFIG_SYS_MALLOC_LEN);
275 for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr) {
276 if ((*init_fnc_ptr)() != 0)
279 show_boot_progress(0x23);
281 #ifdef CONFIG_SERIAL_MULTI
285 #ifndef CONFIG_SYS_NO_FLASH
286 /* configure available FLASH banks */
288 display_flash_config(size);
289 show_boot_progress(0x24);
292 show_boot_progress(0x25);
294 /* initialize environment */
296 show_boot_progress(0x26);
299 #ifdef CONFIG_CMD_NET
301 bd_data.bi_ip_addr = getenv_IPaddr("ipaddr");
304 #if defined(CONFIG_PCI)
306 * Do pci configuration
311 show_boot_progress(0x27);
318 /* Initialize the console (after the relocation and devices init) */
321 #ifdef CONFIG_MISC_INIT_R
322 /* miscellaneous platform dependent initialisations */
326 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
332 #if defined(CONFIG_CMD_KGDB)
338 /* enable exceptions */
340 show_boot_progress(0x28);
342 #ifdef CONFIG_STATUS_LED
343 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
348 /* Initialize from environment */
349 load_addr = getenv_ulong("loadaddr", 16, load_addr);
350 #if defined(CONFIG_CMD_NET)
351 s = getenv("bootfile");
354 copy_filename(BootFile, s, sizeof(BootFile));
359 #if defined(CONFIG_CMD_IDE)
365 #if defined(CONFIG_CMD_SCSI)
371 #if defined(CONFIG_CMD_DOC)
377 #ifdef CONFIG_BITBANGMII
380 #if defined(CONFIG_CMD_NET)
383 eth_initialize(gd->bd);
386 #if (defined(CONFIG_CMD_NET)) && (0)
389 puts("Reset Ethernet PHY\n");
394 #ifdef CONFIG_LAST_STAGE_INIT
397 * Some parts can be only initialized if all others (like
398 * Interrupts) are up and running (i.e. the PC-style ISA
406 post_run(NULL, POST_RAM | post_bootmode_get(0));
409 show_boot_progress(0x29);
411 /* main_loop() can return to retry autoboot, if so just run it again. */
415 /* NOTREACHED - no way out of command loop except booting */
420 puts("### ERROR ### Please RESET the board ###\n");