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>
38 #include <timestamp.h>
44 #include <asm/u-boot-x86.h>
47 #ifdef CONFIG_BITBANGMII
52 * Pointer to initial global data area
54 * Here we initialize it.
56 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
57 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
58 DECLARE_GLOBAL_DATA_PTR
= (gd_t
*) (CONFIG_SYS_INIT_GD_ADDR
);
61 /* Exports from the Linker Script */
62 extern ulong __text_start
;
63 extern ulong __data_end
;
64 extern ulong __rel_dyn_start
;
65 extern ulong __rel_dyn_end
;
66 extern ulong __bss_start
;
67 extern ulong __bss_end
;
69 const char version_string
[] =
70 U_BOOT_VERSION
" (" U_BOOT_DATE
" - " U_BOOT_TIME
")";
72 /************************************************************************
74 ************************************************************************
75 * Some of this code should be moved into the core functions,
76 * or dropped completely,
77 * but let's get it working (again) first...
79 static int init_baudrate (void)
81 char tmp
[64]; /* long enough for environment variables */
82 int i
= getenv_f("baudrate", tmp
, 64);
84 gd
->baudrate
= (i
!= 0)
85 ? (int) simple_strtoul (tmp
, NULL
, 10)
91 static int display_banner (void)
94 printf ("\n\n%s\n\n", version_string
);
96 printf ("U-Boot code: %08lX -> %08lX data: %08lX -> %08lX\n"
97 " BSS: %08lX -> %08lX stack: %08lX -> %08lX\n",
98 i386boot_start, i386boot_romdata_start-1,
99 i386boot_romdata_dest, i386boot_romdata_dest+i386boot_romdata_size-1,
100 i386boot_bss_start, i386boot_bss_start+i386boot_bss_size-1,
101 i386boot_bss_start+i386boot_bss_size,
102 i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1);
109 static int display_dram_config (void)
113 puts ("DRAM Configuration:\n");
115 for (i
=0; i
<CONFIG_NR_DRAM_BANKS
; i
++) {
116 printf ("Bank #%d: %08lx ", i
, gd
->bd
->bi_dram
[i
].start
);
117 print_size (gd
->bd
->bi_dram
[i
].size
, "\n");
123 static void display_flash_config (ulong size
)
126 print_size (size
, "\n");
130 * Breath some life into the board...
132 * Initialize an SMC for serial comms, and carry out some hardware
135 * The first part of initialization is running from Flash memory;
136 * its main purpose is to initialize the RAM so that we
137 * can relocate the monitor code to RAM.
141 * All attempts to come up with a "common" initialization sequence
142 * that works for all boards and architectures failed: some of the
143 * requirements are just _too_ different. To get rid of the resulting
144 * mess of board dependend #ifdef'ed code we now make the whole
145 * initialization sequence configurable to the user.
147 * The requirements for any new initalization function is simple: it
148 * receives a pointer to the "global data" structure as it's only
149 * argument, and returns an integer return code, where 0 means
150 * "continue" and != 0 means "fatal error, hang the system".
152 typedef int (init_fnc_t
) (void);
154 static int calculate_relocation_address(void);
155 static int copy_uboot_to_ram(void);
156 static int clear_bss(void);
157 static int do_elf_reloc_fixups(void);
159 init_fnc_t
*init_sequence_f
[] = {
167 calculate_relocation_address
,
175 init_fnc_t
*init_sequence_r
[] = {
176 cpu_init_r
, /* basic cpu dependent setup */
177 board_early_init_r
, /* basic board dependent setup */
178 dram_init
, /* configure available RAM banks */
179 interrupt_init
, /* set up exceptions */
189 static int calculate_relocation_address(void)
191 void *text_start
= &__text_start
;
192 void *bss_end
= &__bss_end
;
196 /* Calculate destination RAM Address and relocation offset */
197 dest_addr
= (void *)gd
->ram_size
;
198 dest_addr
-= CONFIG_SYS_STACK_SIZE
;
199 dest_addr
-= (bss_end
- text_start
);
200 rel_offset
= dest_addr
- text_start
;
202 gd
->start_addr_sp
= gd
->ram_size
;
203 gd
->relocaddr
= (ulong
)dest_addr
;
204 gd
->reloc_off
= rel_offset
;
209 static int copy_uboot_to_ram(void)
211 ulong
*dst_addr
= (ulong
*)gd
->relocaddr
;
212 ulong
*src_addr
= (ulong
*)&__text_start
;
213 ulong
*end_addr
= (ulong
*)&__data_end
;
215 while (src_addr
< end_addr
)
216 *dst_addr
++ = *src_addr
++;
221 static int clear_bss(void)
223 void *bss_start
= &__bss_start
;
224 void *bss_end
= &__bss_end
;
226 ulong
*dst_addr
= (ulong
*)(bss_start
+ gd
->reloc_off
);
227 ulong
*end_addr
= (ulong
*)(bss_end
+ gd
->reloc_off
);;
229 while (dst_addr
< end_addr
)
230 *dst_addr
++ = 0x00000000;
235 static int do_elf_reloc_fixups(void)
237 Elf32_Rel
*re_src
= (Elf32_Rel
*)(&__rel_dyn_start
);
238 Elf32_Rel
*re_end
= (Elf32_Rel
*)(&__rel_dyn_end
);
241 if (re_src
->r_offset
>= CONFIG_SYS_TEXT_BASE
)
242 if (*(Elf32_Addr
*)(re_src
->r_offset
+ gd
->reloc_off
) >= CONFIG_SYS_TEXT_BASE
)
243 *(Elf32_Addr
*)(re_src
->r_offset
+ gd
->reloc_off
) += gd
->reloc_off
;
244 } while (re_src
++ < re_end
);
249 /* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */
250 void board_init_f(ulong boot_flags
)
252 init_fnc_t
**init_fnc_ptr
;
254 gd
->flags
= boot_flags
;
256 for (init_fnc_ptr
= init_sequence_f
; *init_fnc_ptr
; ++init_fnc_ptr
) {
257 if ((*init_fnc_ptr
)() != 0)
261 gd
->flags
|= GD_FLG_RELOC
;
263 /* Enter the relocated U-Boot! */
264 relocate_code(gd
->start_addr_sp
, gd
, gd
->relocaddr
);
266 /* NOTREACHED - relocate_code() does not return */
270 void board_init_r(gd_t
*id
, ulong dest_addr
)
276 init_fnc_t
**init_fnc_ptr
;
278 show_boot_progress(0x21);
280 /* Global data pointer is now writable */
282 memcpy(gd
, id
, sizeof(gd_t
));
284 /* compiler optimization barrier needed for GCC >= 3.4 */
285 __asm__
__volatile__("": : :"memory");
288 memset (gd
->bd
, 0, sizeof (bd_t
));
289 show_boot_progress(0x22);
291 gd
->baudrate
= CONFIG_BAUDRATE
;
293 mem_malloc_init((((ulong
)dest_addr
- CONFIG_SYS_MALLOC_LEN
)+3)&~3,
294 CONFIG_SYS_MALLOC_LEN
);
296 for (init_fnc_ptr
= init_sequence_r
; *init_fnc_ptr
; ++init_fnc_ptr
) {
297 if ((*init_fnc_ptr
)() != 0)
300 show_boot_progress(0x23);
302 #ifdef CONFIG_SERIAL_MULTI
305 /* configure available FLASH banks */
307 display_flash_config(size
);
308 show_boot_progress(0x24);
310 show_boot_progress(0x25);
312 /* initialize environment */
314 show_boot_progress(0x26);
317 #ifdef CONFIG_CMD_NET
319 bd_data
.bi_ip_addr
= getenv_IPaddr ("ipaddr");
322 #if defined(CONFIG_PCI)
324 * Do pci configuration
329 show_boot_progress(0x27);
336 /* Initialize the console (after the relocation and devices init) */
339 #ifdef CONFIG_MISC_INIT_R
340 /* miscellaneous platform dependent initialisations */
344 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
350 #if defined(CONFIG_CMD_KGDB)
356 /* enable exceptions */
358 show_boot_progress(0x28);
360 #ifdef CONFIG_STATUS_LED
361 status_led_set (STATUS_LED_BOOT
, STATUS_LED_BLINKING
);
368 /* Initialize from environment */
369 if ((s
= getenv ("loadaddr")) != NULL
) {
370 load_addr
= simple_strtoul (s
, NULL
, 16);
372 #if defined(CONFIG_CMD_NET)
373 if ((s
= getenv ("bootfile")) != NULL
) {
374 copy_filename (BootFile
, s
, sizeof (BootFile
));
380 #if defined(CONFIG_CMD_IDE)
386 #if defined(CONFIG_CMD_SCSI)
392 #if defined(CONFIG_CMD_DOC)
398 #ifdef CONFIG_BITBANGMII
401 #if defined(CONFIG_CMD_NET)
402 #if defined(CONFIG_NET_MULTI)
406 eth_initialize(gd
->bd
);
409 #if ( defined(CONFIG_CMD_NET)) && (0)
412 puts ("Reset Ethernet PHY\n");
417 #ifdef CONFIG_LAST_STAGE_INIT
420 * Some parts can be only initialized if all others (like
421 * Interrupts) are up and running (i.e. the PC-style ISA
429 post_run (NULL
, POST_RAM
| post_bootmode_get(0));
433 show_boot_progress(0x29);
435 /* main_loop() can return to retry autoboot, if so just run it again. */
440 /* NOTREACHED - no way out of command loop except booting */
445 puts ("### ERROR ### Please RESET the board ###\n");
449 unsigned long do_go_exec (ulong (*entry
)(int, char * const []), int argc
, char * const argv
[])
451 unsigned long ret
= 0;
455 * x86 does not use a dedicated register to pass the pointer to
456 * the global_data, so it is instead passed as argv[-1]. By using
457 * argv[-1], the called 'Application' can use the contents of
458 * argv natively. However, to safely use argv[-1] a new copy of
459 * argv is needed with the extra element
461 argv_tmp
= malloc(sizeof(char *) * (argc
+ 1));
464 argv_tmp
[0] = (char *)gd
;
466 memcpy(&argv_tmp
[1], argv
, (size_t)(sizeof(char *) * argc
));
468 ret
= (entry
) (argc
, &argv_tmp
[1]);
475 void setup_pcat_compatibility(void)
476 __attribute__((weak
, alias("__setup_pcat_compatibility")));
478 void __setup_pcat_compatibility(void)