3 * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
12 * See file CREDITS for list of people who contributed to this
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 #include <stdio_dev.h>
35 #include <timestamp.h>
41 #include <asm/u-boot-i386.h>
44 #ifdef CONFIG_BITBANGMII
49 * Pointer to initial global data area
51 * Here we initialize it.
53 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
54 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
55 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
58 /* Exports from the Linker Script */
59 extern ulong __text_start;
60 extern ulong __data_end;
61 extern ulong __rel_dyn_start;
62 extern ulong __rel_dyn_end;
63 extern ulong __bss_start;
64 extern ulong __bss_end;
66 const char version_string[] =
67 U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
69 /************************************************************************
71 ************************************************************************
72 * Some of this code should be moved into the core functions,
73 * or dropped completely,
74 * but let's get it working (again) first...
76 static int init_baudrate (void)
78 char tmp[64]; /* long enough for environment variables */
79 int i = getenv_f("baudrate", tmp, 64);
81 gd->baudrate = (i != 0)
82 ? (int) simple_strtoul (tmp, NULL, 10)
88 static int display_banner (void)
91 printf ("\n\n%s\n\n", version_string);
93 printf ("U-Boot code: %08lX -> %08lX data: %08lX -> %08lX\n"
94 " BSS: %08lX -> %08lX stack: %08lX -> %08lX\n",
95 i386boot_start, i386boot_romdata_start-1,
96 i386boot_romdata_dest, i386boot_romdata_dest+i386boot_romdata_size-1,
97 i386boot_bss_start, i386boot_bss_start+i386boot_bss_size-1,
98 i386boot_bss_start+i386boot_bss_size,
99 i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1);
107 * WARNING: this code looks "cleaner" than the PowerPC version, but
108 * has the disadvantage that you either get nothing, or everything.
109 * On PowerPC, you might see "DRAM: " before the system hangs - which
110 * gives a simple yet clear indication which part of the
111 * initialization if failing.
113 static int display_dram_config (void)
117 puts ("DRAM Configuration:\n");
119 for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
120 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
121 print_size (gd->bd->bi_dram[i].size, "\n");
127 static void display_flash_config (ulong size)
130 print_size (size, "\n");
134 * Breath some life into the board...
136 * Initialize an SMC for serial comms, and carry out some hardware
139 * The first part of initialization is running from Flash memory;
140 * its main purpose is to initialize the RAM so that we
141 * can relocate the monitor code to RAM.
146 * All attempts to come up with a "common" initialization sequence
147 * that works for all boards and architectures failed: some of the
148 * requirements are just _too_ different. To get rid of the resulting
149 * mess of board dependend #ifdef'ed code we now make the whole
150 * initialization sequence configurable to the user.
152 * The requirements for any new initalization function is simple: it
153 * receives a pointer to the "global data" structure as it's only
154 * argument, and returns an integer return code, where 0 means
155 * "continue" and != 0 means "fatal error, hang the system".
157 typedef int (init_fnc_t) (void);
159 init_fnc_t *init_sequence[] = {
160 cpu_init_r, /* basic cpu dependent setup */
161 board_early_init_r, /* basic board dependent setup */
162 dram_init, /* configure available RAM banks */
163 interrupt_init, /* set up exceptions */
173 static int calculate_relocation_address(void)
175 void *text_start = &__text_start;
176 void *bss_end = &__bss_end;
180 /* Calculate destination RAM Address and relocation offset */
181 dest_addr = (void *)gd->ram_size;
182 dest_addr -= CONFIG_SYS_STACK_SIZE;
183 dest_addr -= (bss_end - text_start);
184 rel_offset = dest_addr - text_start;
186 gd->start_addr_sp = gd->ram_size;
187 gd->relocaddr = (ulong)dest_addr;
188 gd->reloc_off = rel_offset;
193 static int copy_uboot_to_ram(void)
195 ulong *dst_addr = (ulong *)gd->relocaddr;
196 ulong *src_addr = (ulong *)&__text_start;
197 ulong *end_addr = (ulong *)&__data_end;
199 while (src_addr < end_addr)
200 *dst_addr++ = *src_addr++;
205 static int clear_bss(void)
207 void *bss_start = &__bss_start;
208 void *bss_end = &__bss_end;
210 ulong *dst_addr = (ulong *)(bss_start + gd->reloc_off);
211 ulong *end_addr = (ulong *)(bss_end + gd->reloc_off);;
213 while (dst_addr < end_addr)
214 *dst_addr++ = 0x00000000;
219 static int do_elf_reloc_fixups(void)
221 Elf32_Rel *re_src = (Elf32_Rel *)(&__rel_dyn_start);
222 Elf32_Rel *re_end = (Elf32_Rel *)(&__rel_dyn_end);
225 if (re_src->r_offset >= CONFIG_SYS_TEXT_BASE)
226 if (*(Elf32_Addr *)(re_src->r_offset + gd->reloc_off) >= CONFIG_SYS_TEXT_BASE)
227 *(Elf32_Addr *)(re_src->r_offset + gd->reloc_off) += gd->reloc_off;
228 } while (re_src++ < re_end);
234 * Load U-Boot into RAM, initialize BSS, perform relocation adjustments
236 void board_init_f(ulong boot_flags)
241 if (init_baudrate() != 0)
244 if (serial_init() != 0)
247 if (console_init_f() != 0)
250 if (dram_init_f() != 0)
253 if (calculate_relocation_address() != 0)
256 /* First stage CPU initialization */
257 if (cpu_init_f() != 0)
260 /* First stage Board initialization */
261 if (board_early_init_f() != 0)
264 /* Copy U-Boot into RAM */
265 if (copy_uboot_to_ram() != 0)
268 if (clear_bss() != 0)
271 if (do_elf_reloc_fixups() != 0)
274 gd->flags |= GD_FLG_RELOC;
276 /* Enter the relocated U-Boot! */
277 relocate_code(gd->start_addr_sp, gd, gd->relocaddr);
279 /* NOTREACHED - relocate_code() does not return */
283 void board_init_r(gd_t *id, ulong dest_addr)
290 init_fnc_t **init_fnc_ptr;
292 show_boot_progress(0x21);
294 /* Global data pointer is now writable */
296 memcpy(gd, id, sizeof(gd_t));
298 /* compiler optimization barrier needed for GCC >= 3.4 */
299 __asm__ __volatile__("": : :"memory");
302 memset (gd->bd, 0, sizeof (bd_t));
303 show_boot_progress(0x22);
305 gd->baudrate = CONFIG_BAUDRATE;
307 mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
308 CONFIG_SYS_MALLOC_LEN);
310 for (init_fnc_ptr = init_sequence, i=0; *init_fnc_ptr; ++init_fnc_ptr, i++) {
311 show_boot_progress(0xa130|i);
313 if ((*init_fnc_ptr)() != 0) {
317 show_boot_progress(0x23);
319 #ifdef CONFIG_SERIAL_MULTI
322 /* configure available FLASH banks */
324 display_flash_config(size);
325 show_boot_progress(0x24);
327 show_boot_progress(0x25);
329 /* initialize environment */
331 show_boot_progress(0x26);
334 #ifdef CONFIG_CMD_NET
336 bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr");
339 #if defined(CONFIG_PCI)
341 * Do pci configuration
346 show_boot_progress(0x27);
353 /* Initialize the console (after the relocation and devices init) */
356 #ifdef CONFIG_MISC_INIT_R
357 /* miscellaneous platform dependent initialisations */
361 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
367 #if defined(CONFIG_CMD_KGDB)
373 /* enable exceptions */
375 show_boot_progress(0x28);
377 #ifdef CONFIG_STATUS_LED
378 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
385 /* Initialize from environment */
386 if ((s = getenv ("loadaddr")) != NULL) {
387 load_addr = simple_strtoul (s, NULL, 16);
389 #if defined(CONFIG_CMD_NET)
390 if ((s = getenv ("bootfile")) != NULL) {
391 copy_filename (BootFile, s, sizeof (BootFile));
397 #if defined(CONFIG_CMD_IDE)
403 #if defined(CONFIG_CMD_SCSI)
409 #if defined(CONFIG_CMD_DOC)
415 #ifdef CONFIG_BITBANGMII
418 #if defined(CONFIG_CMD_NET)
419 #if defined(CONFIG_NET_MULTI)
423 eth_initialize(gd->bd);
426 #if ( defined(CONFIG_CMD_NET)) && (0)
429 puts ("Reset Ethernet PHY\n");
434 #ifdef CONFIG_LAST_STAGE_INIT
437 * Some parts can be only initialized if all others (like
438 * Interrupts) are up and running (i.e. the PC-style ISA
446 post_run (NULL, POST_RAM | post_bootmode_get(0));
450 show_boot_progress(0x29);
452 /* main_loop() can return to retry autoboot, if so just run it again. */
457 /* NOTREACHED - no way out of command loop except booting */
462 puts ("### ERROR ### Please RESET the board ###\n");
466 unsigned long do_go_exec (ulong (*entry)(int, char * const []), int argc, char * const argv[])
468 unsigned long ret = 0;
472 * x86 does not use a dedicated register to pass the pointer to
473 * the global_data, so it is instead passed as argv[-1]. By using
474 * argv[-1], the called 'Application' can use the contents of
475 * argv natively. However, to safely use argv[-1] a new copy of
476 * argv is needed with the extra element
478 argv_tmp = malloc(sizeof(char *) * (argc + 1));
481 argv_tmp[0] = (char *)gd;
483 memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
485 ret = (entry) (argc, &argv_tmp[1]);
492 void setup_pcat_compatibility(void)
493 __attribute__((weak, alias("__setup_pcat_compatibility")));
495 void __setup_pcat_compatibility(void)