blob: 18e0edee8756e5ffdbcb86cb0fcd59b6df1998c7 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
Graeme Russ45fc1d82011-04-13 19:43:26 +10002 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
4 *
wdenk591dda52002-11-18 00:14:45 +00005 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02006 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk57b2d802003-06-27 21:31:46 +00007 *
wdenk591dda52002-11-18 00:14:45 +00008 * (C) Copyright 2002
Graeme Russ45fc1d82011-04-13 19:43:26 +10009 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
wdenk57b2d802003-06-27 21:31:46 +000010 *
wdenk591dda52002-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>
36#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020037#include <stdio_dev.h>
wdenk591dda52002-11-18 00:14:45 +000038#include <version.h>
39#include <malloc.h>
wdenk591dda52002-11-18 00:14:45 +000040#include <net.h>
41#include <ide.h>
Graeme Russ06dfe372010-04-24 00:05:47 +100042#include <serial.h>
Graeme Russcbfce1d2011-04-13 19:43:28 +100043#include <asm/u-boot-x86.h>
Graeme Russ078395c2009-11-24 20:04:21 +110044#include <elf.h>
wdenk591dda52002-11-18 00:14:45 +000045
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +020046#ifdef CONFIG_BITBANGMII
47#include <miiphy.h>
48#endif
49
Graeme Russ4e0f55f2011-02-12 15:11:50 +110050/*
51 * Pointer to initial global data area
52 *
53 * Here we initialize it.
54 */
55#undef XTRN_DECLARE_GLOBAL_DATA_PTR
56#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
57DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
58
wdenk591dda52002-11-18 00:14:45 +000059/************************************************************************
60 * Init Utilities *
61 ************************************************************************
62 * Some of this code should be moved into the core functions,
63 * or dropped completely,
64 * but let's get it working (again) first...
65 */
Graeme Russ883c6032011-11-08 02:33:15 +000066static int init_baudrate(void)
wdenk591dda52002-11-18 00:14:45 +000067{
Simon Glass32ef00a2011-10-13 14:43:14 +000068 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
69 return 0;
wdenk591dda52002-11-18 00:14:45 +000070}
71
Graeme Russ883c6032011-11-08 02:33:15 +000072static int display_banner(void)
wdenk591dda52002-11-18 00:14:45 +000073{
74
Graeme Russ883c6032011-11-08 02:33:15 +000075 printf("\n\n%s\n\n", version_string);
wdenk591dda52002-11-18 00:14:45 +000076
Graeme Russ883c6032011-11-08 02:33:15 +000077 return 0;
wdenk591dda52002-11-18 00:14:45 +000078}
79
Graeme Russ883c6032011-11-08 02:33:15 +000080static int display_dram_config(void)
wdenk591dda52002-11-18 00:14:45 +000081{
wdenk591dda52002-11-18 00:14:45 +000082 int i;
83
Graeme Russ883c6032011-11-08 02:33:15 +000084 puts("DRAM Configuration:\n");
wdenk591dda52002-11-18 00:14:45 +000085
Graeme Russ883c6032011-11-08 02:33:15 +000086 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
87 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
88 print_size(gd->bd->bi_dram[i].size, "\n");
wdenk591dda52002-11-18 00:14:45 +000089 }
wdenk57b2d802003-06-27 21:31:46 +000090
Graeme Russ883c6032011-11-08 02:33:15 +000091 return 0;
wdenk591dda52002-11-18 00:14:45 +000092}
93
Graeme Russ19fc0d52011-11-08 02:33:20 +000094#ifndef CONFIG_SYS_NO_FLASH
Graeme Russ883c6032011-11-08 02:33:15 +000095static void display_flash_config(ulong size)
wdenk591dda52002-11-18 00:14:45 +000096{
Graeme Russ883c6032011-11-08 02:33:15 +000097 puts("Flash: ");
98 print_size(size, "\n");
wdenk591dda52002-11-18 00:14:45 +000099}
Graeme Russ19fc0d52011-11-08 02:33:20 +0000100#endif
wdenk591dda52002-11-18 00:14:45 +0000101
wdenk591dda52002-11-18 00:14:45 +0000102/*
103 * Breath some life into the board...
104 *
105 * Initialize an SMC for serial comms, and carry out some hardware
106 * tests.
107 *
108 * The first part of initialization is running from Flash memory;
109 * its main purpose is to initialize the RAM so that we
110 * can relocate the monitor code to RAM.
111 */
112
113/*
114 * All attempts to come up with a "common" initialization sequence
115 * that works for all boards and architectures failed: some of the
116 * requirements are just _too_ different. To get rid of the resulting
117 * mess of board dependend #ifdef'ed code we now make the whole
118 * initialization sequence configurable to the user.
119 *
120 * The requirements for any new initalization function is simple: it
121 * receives a pointer to the "global data" structure as it's only
122 * argument, and returns an integer return code, where 0 means
123 * "continue" and != 0 means "fatal error, hang the system".
124 */
125typedef int (init_fnc_t) (void);
126
Graeme Russ6ec93c32011-02-12 15:12:10 +1100127static int calculate_relocation_address(void);
128static int copy_uboot_to_ram(void);
129static int clear_bss(void);
130static int do_elf_reloc_fixups(void);
131
132init_fnc_t *init_sequence_f[] = {
133 cpu_init_f,
134 board_early_init_f,
135 env_init,
136 init_baudrate,
137 serial_init,
138 console_init_f,
139 dram_init_f,
140 calculate_relocation_address,
141 copy_uboot_to_ram,
142 clear_bss,
143 do_elf_reloc_fixups,
144
145 NULL,
146};
147
148init_fnc_t *init_sequence_r[] = {
Graeme Russ078395c2009-11-24 20:04:21 +1100149 cpu_init_r, /* basic cpu dependent setup */
150 board_early_init_r, /* basic board dependent setup */
wdenk591dda52002-11-18 00:14:45 +0000151 dram_init, /* configure available RAM banks */
wdenk591dda52002-11-18 00:14:45 +0000152 interrupt_init, /* set up exceptions */
wdenk57b2d802003-06-27 21:31:46 +0000153 timer_init,
wdenk591dda52002-11-18 00:14:45 +0000154 display_banner,
155 display_dram_config,
156
157 NULL,
158};
159
Graeme Russ2fe2a972008-09-07 07:08:42 +1000160gd_t *gd;
wdenk591dda52002-11-18 00:14:45 +0000161
Graeme Russ4b259822011-02-12 15:12:06 +1100162static int calculate_relocation_address(void)
Graeme Russ078395c2009-11-24 20:04:21 +1100163{
Graeme Russ2768d852011-11-08 02:33:21 +0000164 ulong text_start = (ulong)&__text_start;
165 ulong bss_end = (ulong)&__bss_end;
166 ulong dest_addr;
Graeme Russ4b259822011-02-12 15:12:06 +1100167 ulong rel_offset;
168
169 /* Calculate destination RAM Address and relocation offset */
Graeme Russ2768d852011-11-08 02:33:21 +0000170 dest_addr = gd->ram_size;
Graeme Russ4b259822011-02-12 15:12:06 +1100171 dest_addr -= CONFIG_SYS_STACK_SIZE;
172 dest_addr -= (bss_end - text_start);
Graeme Russ2768d852011-11-08 02:33:21 +0000173
174 /*
175 * Round destination address down to 16-byte boundary to keep
176 * IDT and GDT 16-byte aligned
177 */
178 dest_addr &= ~15;
179
Graeme Russ4b259822011-02-12 15:12:06 +1100180 rel_offset = dest_addr - text_start;
181
182 gd->start_addr_sp = gd->ram_size;
Graeme Russ2768d852011-11-08 02:33:21 +0000183 gd->relocaddr = dest_addr;
Graeme Russ4b259822011-02-12 15:12:06 +1100184 gd->reloc_off = rel_offset;
185
186 return 0;
187}
188
189static int copy_uboot_to_ram(void)
190{
191 ulong *dst_addr = (ulong *)gd->relocaddr;
192 ulong *src_addr = (ulong *)&__text_start;
193 ulong *end_addr = (ulong *)&__data_end;
194
195 while (src_addr < end_addr)
196 *dst_addr++ = *src_addr++;
197
198 return 0;
199}
200
201static int clear_bss(void)
202{
Graeme Russae428db2010-10-07 20:03:31 +1100203 void *bss_start = &__bss_start;
Graeme Russ99052852010-10-07 20:03:33 +1100204 void *bss_end = &__bss_end;
Graeme Russ078395c2009-11-24 20:04:21 +1100205
Graeme Russ4b259822011-02-12 15:12:06 +1100206 ulong *dst_addr = (ulong *)(bss_start + gd->reloc_off);
Graeme Russ883c6032011-11-08 02:33:15 +0000207 ulong *end_addr = (ulong *)(bss_end + gd->reloc_off);
Graeme Russ99052852010-10-07 20:03:33 +1100208
Graeme Russ4b259822011-02-12 15:12:06 +1100209 while (dst_addr < end_addr)
210 *dst_addr++ = 0x00000000;
211
212 return 0;
213}
214
215static int do_elf_reloc_fixups(void)
216{
217 Elf32_Rel *re_src = (Elf32_Rel *)(&__rel_dyn_start);
218 Elf32_Rel *re_end = (Elf32_Rel *)(&__rel_dyn_end);
219
Graeme Russ883c6032011-11-08 02:33:15 +0000220 Elf32_Addr *offset_ptr_rom;
221 Elf32_Addr *offset_ptr_ram;
222
Graeme Russ4b259822011-02-12 15:12:06 +1100223 do {
Graeme Russ883c6032011-11-08 02:33:15 +0000224 /* Get the location from the relocation entry */
225 offset_ptr_rom = (Elf32_Addr *)re_src->r_offset;
226
227 /* Check that the location of the relocation is in .text */
228 if (offset_ptr_rom >= (Elf32_Addr *)CONFIG_SYS_TEXT_BASE) {
229
230 /* Switch to the in-RAM version */
231 offset_ptr_ram = offset_ptr_rom + gd->reloc_off;
232
233 /* Check that the target points into .text */
Gabe Black3530c072011-11-12 16:34:48 +0000234 if (*offset_ptr_ram >= CONFIG_SYS_TEXT_BASE &&
235 *offset_ptr_ram <
236 (CONFIG_SYS_TEXT_BASE + size)) {
Graeme Russ883c6032011-11-08 02:33:15 +0000237 *offset_ptr_ram += gd->reloc_off;
Gabe Black3530c072011-11-12 16:34:48 +0000238 }
Graeme Russ883c6032011-11-08 02:33:15 +0000239 }
Graeme Russ4b259822011-02-12 15:12:06 +1100240 } while (re_src++ < re_end);
Graeme Russ078395c2009-11-24 20:04:21 +1100241
Graeme Russ4b259822011-02-12 15:12:06 +1100242 return 0;
243}
Graeme Russ38183932011-02-12 15:11:54 +1100244
Graeme Russ45fc1d82011-04-13 19:43:26 +1000245/* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */
Graeme Russ4b259822011-02-12 15:12:06 +1100246void board_init_f(ulong boot_flags)
247{
Graeme Russ6ec93c32011-02-12 15:12:10 +1100248 init_fnc_t **init_fnc_ptr;
Graeme Russ99052852010-10-07 20:03:33 +1100249
Graeme Russ45fc1d82011-04-13 19:43:26 +1000250 gd->flags = boot_flags;
251
Graeme Russ6ec93c32011-02-12 15:12:10 +1100252 for (init_fnc_ptr = init_sequence_f; *init_fnc_ptr; ++init_fnc_ptr) {
253 if ((*init_fnc_ptr)() != 0)
254 hang();
255 }
Graeme Russ078395c2009-11-24 20:04:21 +1100256
Graeme Russ4e0f55f2011-02-12 15:11:50 +1100257 gd->flags |= GD_FLG_RELOC;
Graeme Russ5fb91cc2010-10-07 20:03:29 +1100258
Graeme Russe07da072010-04-24 00:05:44 +1000259 /* Enter the relocated U-Boot! */
Graeme Russ4b259822011-02-12 15:12:06 +1100260 relocate_code(gd->start_addr_sp, gd, gd->relocaddr);
Graeme Russ5fb91cc2010-10-07 20:03:29 +1100261
Graeme Russ9c44afc2011-02-12 15:11:58 +1100262 /* NOTREACHED - relocate_code() does not return */
Graeme Russ883c6032011-11-08 02:33:15 +0000263 while (1)
264 ;
Graeme Russ078395c2009-11-24 20:04:21 +1100265}
266
Graeme Russe07da072010-04-24 00:05:44 +1000267void board_init_r(gd_t *id, ulong dest_addr)
wdenk591dda52002-11-18 00:14:45 +0000268{
Graeme Russ19fc0d52011-11-08 02:33:20 +0000269#if defined(CONFIG_CMD_NET)
wdenk591dda52002-11-18 00:14:45 +0000270 char *s;
Graeme Russ19fc0d52011-11-08 02:33:20 +0000271#endif
272#ifndef CONFIG_SYS_NO_FLASH
wdenk591dda52002-11-18 00:14:45 +0000273 ulong size;
Graeme Russ19fc0d52011-11-08 02:33:20 +0000274#endif
wdenk591dda52002-11-18 00:14:45 +0000275 static bd_t bd_data;
Graeme Russ4e0f55f2011-02-12 15:11:50 +1100276 static gd_t gd_data;
wdenk591dda52002-11-18 00:14:45 +0000277 init_fnc_t **init_fnc_ptr;
wdenk57b2d802003-06-27 21:31:46 +0000278
wdenk591dda52002-11-18 00:14:45 +0000279 show_boot_progress(0x21);
280
Graeme Russ4e0f55f2011-02-12 15:11:50 +1100281 /* Global data pointer is now writable */
282 gd = &gd_data;
283 memcpy(gd, id, sizeof(gd_t));
284
wdenk3337af42004-07-01 20:28:03 +0000285 /* compiler optimization barrier needed for GCC >= 3.4 */
Graeme Russ883c6032011-11-08 02:33:15 +0000286 __asm__ __volatile__("" : : : "memory");
wdenk57b2d802003-06-27 21:31:46 +0000287
wdenk591dda52002-11-18 00:14:45 +0000288 gd->bd = &bd_data;
Graeme Russ883c6032011-11-08 02:33:15 +0000289 memset(gd->bd, 0, sizeof(bd_t));
wdenk591dda52002-11-18 00:14:45 +0000290 show_boot_progress(0x22);
291
wdenkabda5ca2003-05-31 18:35:21 +0000292 gd->baudrate = CONFIG_BAUDRATE;
wdenk57b2d802003-06-27 21:31:46 +0000293
Graeme Russe07da072010-04-24 00:05:44 +1000294 mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
Graeme Russ078395c2009-11-24 20:04:21 +1100295 CONFIG_SYS_MALLOC_LEN);
296
Graeme Russ6ec93c32011-02-12 15:12:10 +1100297 for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr) {
298 if ((*init_fnc_ptr)() != 0)
Graeme Russ883c6032011-11-08 02:33:15 +0000299 hang();
wdenk591dda52002-11-18 00:14:45 +0000300 }
301 show_boot_progress(0x23);
302
Graeme Russ06dfe372010-04-24 00:05:47 +1000303#ifdef CONFIG_SERIAL_MULTI
304 serial_initialize();
305#endif
Graeme Russ19fc0d52011-11-08 02:33:20 +0000306
307#ifndef CONFIG_SYS_NO_FLASH
wdenk591dda52002-11-18 00:14:45 +0000308 /* configure available FLASH banks */
309 size = flash_init();
310 display_flash_config(size);
311 show_boot_progress(0x24);
Graeme Russ19fc0d52011-11-08 02:33:20 +0000312#endif
wdenk591dda52002-11-18 00:14:45 +0000313
314 show_boot_progress(0x25);
315
316 /* initialize environment */
Graeme Russ883c6032011-11-08 02:33:15 +0000317 env_relocate();
wdenk591dda52002-11-18 00:14:45 +0000318 show_boot_progress(0x26);
319
320
Graeme Russd520c0e2010-04-24 00:05:36 +1000321#ifdef CONFIG_CMD_NET
wdenk591dda52002-11-18 00:14:45 +0000322 /* IP Address */
Graeme Russ883c6032011-11-08 02:33:15 +0000323 bd_data.bi_ip_addr = getenv_IPaddr("ipaddr");
Graeme Russd520c0e2010-04-24 00:05:36 +1000324#endif
wdenk591dda52002-11-18 00:14:45 +0000325
wdenk591dda52002-11-18 00:14:45 +0000326#if defined(CONFIG_PCI)
327 /*
328 * Do pci configuration
329 */
330 pci_init();
331#endif
332
333 show_boot_progress(0x27);
334
335
Graeme Russ883c6032011-11-08 02:33:15 +0000336 stdio_init();
wdenk591dda52002-11-18 00:14:45 +0000337
Graeme Russ883c6032011-11-08 02:33:15 +0000338 jumptable_init();
wdenk57b2d802003-06-27 21:31:46 +0000339
wdenk591dda52002-11-18 00:14:45 +0000340 /* Initialize the console (after the relocation and devices init) */
341 console_init_r();
wdenk591dda52002-11-18 00:14:45 +0000342
343#ifdef CONFIG_MISC_INIT_R
344 /* miscellaneous platform dependent initialisations */
345 misc_init_r();
346#endif
347
Jon Loeliger12077972007-07-09 18:05:38 -0500348#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
wdenk591dda52002-11-18 00:14:45 +0000349 WATCHDOG_RESET();
Graeme Russ883c6032011-11-08 02:33:15 +0000350 puts("PCMCIA:");
wdenk591dda52002-11-18 00:14:45 +0000351 pcmcia_init();
352#endif
353
Jon Loeliger12077972007-07-09 18:05:38 -0500354#if defined(CONFIG_CMD_KGDB)
wdenk591dda52002-11-18 00:14:45 +0000355 WATCHDOG_RESET();
356 puts("KGDB: ");
357 kgdb_init();
358#endif
359
360 /* enable exceptions */
wdenkabda5ca2003-05-31 18:35:21 +0000361 enable_interrupts();
wdenk591dda52002-11-18 00:14:45 +0000362 show_boot_progress(0x28);
363
wdenk591dda52002-11-18 00:14:45 +0000364#ifdef CONFIG_STATUS_LED
Graeme Russ883c6032011-11-08 02:33:15 +0000365 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
wdenk591dda52002-11-18 00:14:45 +0000366#endif
367
wdenkabda5ca2003-05-31 18:35:21 +0000368 udelay(20);
wdenk591dda52002-11-18 00:14:45 +0000369
wdenk591dda52002-11-18 00:14:45 +0000370 /* Initialize from environment */
Simon Glass32ef00a2011-10-13 14:43:14 +0000371 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Jon Loeliger12077972007-07-09 18:05:38 -0500372#if defined(CONFIG_CMD_NET)
Graeme Russ883c6032011-11-08 02:33:15 +0000373 s = getenv("bootfile");
374
375 if (s != NULL)
376 copy_filename(BootFile, s, sizeof(BootFile));
Jon Loeliger1670a5b2007-07-10 11:19:50 -0500377#endif
wdenk591dda52002-11-18 00:14:45 +0000378
379 WATCHDOG_RESET();
380
Jon Loeliger12077972007-07-09 18:05:38 -0500381#if defined(CONFIG_CMD_IDE)
wdenk591dda52002-11-18 00:14:45 +0000382 WATCHDOG_RESET();
383 puts("IDE: ");
384 ide_init();
Jon Loeliger1670a5b2007-07-10 11:19:50 -0500385#endif
wdenk591dda52002-11-18 00:14:45 +0000386
Jon Loeliger12077972007-07-09 18:05:38 -0500387#if defined(CONFIG_CMD_SCSI)
wdenk591dda52002-11-18 00:14:45 +0000388 WATCHDOG_RESET();
389 puts("SCSI: ");
390 scsi_init();
391#endif
392
Jon Loeliger12077972007-07-09 18:05:38 -0500393#if defined(CONFIG_CMD_DOC)
wdenk591dda52002-11-18 00:14:45 +0000394 WATCHDOG_RESET();
wdenkabda5ca2003-05-31 18:35:21 +0000395 puts("DOC: ");
wdenk591dda52002-11-18 00:14:45 +0000396 doc_init();
397#endif
398
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +0200399#ifdef CONFIG_BITBANGMII
400 bb_miiphy_init();
401#endif
Jon Loeliger12077972007-07-09 18:05:38 -0500402#if defined(CONFIG_CMD_NET)
wdenk591dda52002-11-18 00:14:45 +0000403 WATCHDOG_RESET();
404 puts("Net: ");
405 eth_initialize(gd->bd);
406#endif
407
Graeme Russ883c6032011-11-08 02:33:15 +0000408#if (defined(CONFIG_CMD_NET)) && (0)
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200409 WATCHDOG_RESET();
410# ifdef DEBUG
Graeme Russ883c6032011-11-08 02:33:15 +0000411 puts("Reset Ethernet PHY\n");
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200412# endif
413 reset_phy();
414#endif
415
wdenk591dda52002-11-18 00:14:45 +0000416#ifdef CONFIG_LAST_STAGE_INIT
417 WATCHDOG_RESET();
418 /*
419 * Some parts can be only initialized if all others (like
420 * Interrupts) are up and running (i.e. the PC-style ISA
421 * keyboard).
422 */
423 last_stage_init();
424#endif
425
426
wdenk591dda52002-11-18 00:14:45 +0000427#ifdef CONFIG_POST
Graeme Russ883c6032011-11-08 02:33:15 +0000428 post_run(NULL, POST_RAM | post_bootmode_get(0));
wdenk591dda52002-11-18 00:14:45 +0000429#endif
wdenk57b2d802003-06-27 21:31:46 +0000430
wdenk591dda52002-11-18 00:14:45 +0000431 show_boot_progress(0x29);
wdenk57b2d802003-06-27 21:31:46 +0000432
wdenk591dda52002-11-18 00:14:45 +0000433 /* main_loop() can return to retry autoboot, if so just run it again. */
Graeme Russ883c6032011-11-08 02:33:15 +0000434 for (;;)
wdenkabda5ca2003-05-31 18:35:21 +0000435 main_loop();
wdenk591dda52002-11-18 00:14:45 +0000436
437 /* NOTREACHED - no way out of command loop except booting */
438}
439
Graeme Russ883c6032011-11-08 02:33:15 +0000440void hang(void)
wdenk591dda52002-11-18 00:14:45 +0000441{
Graeme Russ883c6032011-11-08 02:33:15 +0000442 puts("### ERROR ### Please RESET the board ###\n");
443 for (;;)
444 ;
wdenk591dda52002-11-18 00:14:45 +0000445}
Mike Frysinger0870e472008-04-13 19:42:19 -0400446
Graeme Russ883c6032011-11-08 02:33:15 +0000447unsigned long do_go_exec(ulong (*entry)(int, char * const []),
448 int argc, char * const argv[])
Mike Frysinger0870e472008-04-13 19:42:19 -0400449{
Graeme Russ757660f2010-08-22 16:25:58 +1000450 unsigned long ret = 0;
451 char **argv_tmp;
452
Mike Frysinger0870e472008-04-13 19:42:19 -0400453 /*
Graeme Russ757660f2010-08-22 16:25:58 +1000454 * x86 does not use a dedicated register to pass the pointer to
455 * the global_data, so it is instead passed as argv[-1]. By using
456 * argv[-1], the called 'Application' can use the contents of
457 * argv natively. However, to safely use argv[-1] a new copy of
458 * argv is needed with the extra element
Mike Frysinger0870e472008-04-13 19:42:19 -0400459 */
Graeme Russ757660f2010-08-22 16:25:58 +1000460 argv_tmp = malloc(sizeof(char *) * (argc + 1));
461
462 if (argv_tmp) {
463 argv_tmp[0] = (char *)gd;
464
465 memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
466
467 ret = (entry) (argc, &argv_tmp[1]);
468 free(argv_tmp);
469 }
Graeme Russ0b9fe9d2010-04-24 00:05:39 +1000470
Graeme Russ757660f2010-08-22 16:25:58 +1000471 return ret;
Mike Frysinger0870e472008-04-13 19:42:19 -0400472}
Graeme Russa8d06b42010-04-24 00:05:48 +1000473
474void setup_pcat_compatibility(void)
475 __attribute__((weak, alias("__setup_pcat_compatibility")));
476
477void __setup_pcat_compatibility(void)
478{
479}