wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 2 | * (C) Copyright 2008-2011 |
| 3 | * Graeme Russ, <graeme.russ@gmail.com> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002 |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
| 7 | * |
| 8 | * (C) Copyright 2002 |
| 9 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 <watchdog.h> |
| 36 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 37 | #include <stdio_dev.h> |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 38 | #include <timestamp.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | #include <version.h> |
| 40 | #include <malloc.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | #include <net.h> |
| 42 | #include <ide.h> |
Graeme Russ | bf16500 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 43 | #include <serial.h> |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 44 | #include <asm/u-boot-x86.h> |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 45 | #include <elf.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_BITBANGMII |
| 48 | #include <miiphy.h> |
| 49 | #endif |
| 50 | |
Graeme Russ | 2e2613d | 2011-02-12 15:11:50 +1100 | [diff] [blame] | 51 | /* |
| 52 | * Pointer to initial global data area |
| 53 | * |
| 54 | * Here we initialize it. |
| 55 | */ |
| 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); |
| 59 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 60 | |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 61 | /* Exports from the Linker Script */ |
Graeme Russ | 067f9b1 | 2010-10-07 20:03:31 +1100 | [diff] [blame] | 62 | extern ulong __text_start; |
Graeme Russ | 2219142 | 2010-10-07 20:03:32 +1100 | [diff] [blame] | 63 | extern ulong __data_end; |
Graeme Russ | 067f9b1 | 2010-10-07 20:03:31 +1100 | [diff] [blame] | 64 | extern ulong __rel_dyn_start; |
| 65 | extern ulong __rel_dyn_end; |
| 66 | extern ulong __bss_start; |
Graeme Russ | f2ff75c | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 67 | extern ulong __bss_end; |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 68 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | const char version_string[] = |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 70 | U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | /************************************************************************ |
| 73 | * Init Utilities * |
| 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... |
| 78 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 79 | static int init_baudrate (void) |
| 80 | { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 81 | char tmp[64]; /* long enough for environment variables */ |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 82 | int i = getenv_f("baudrate", tmp, 64); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 83 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 84 | gd->baudrate = (i != 0) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | ? (int) simple_strtoul (tmp, NULL, 10) |
| 86 | : CONFIG_BAUDRATE; |
| 87 | |
| 88 | return (0); |
| 89 | } |
| 90 | |
| 91 | static int display_banner (void) |
| 92 | { |
| 93 | |
| 94 | printf ("\n\n%s\n\n", version_string); |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 95 | /* |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | i386boot_bss_start+i386boot_bss_size, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 104 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 105 | |
| 106 | return (0); |
| 107 | } |
| 108 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 109 | static int display_dram_config (void) |
| 110 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 111 | int i; |
| 112 | |
| 113 | puts ("DRAM Configuration:\n"); |
| 114 | |
| 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"); |
| 118 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 119 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 120 | return (0); |
| 121 | } |
| 122 | |
| 123 | static void display_flash_config (ulong size) |
| 124 | { |
| 125 | puts ("Flash: "); |
| 126 | print_size (size, "\n"); |
| 127 | } |
| 128 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 129 | /* |
| 130 | * Breath some life into the board... |
| 131 | * |
| 132 | * Initialize an SMC for serial comms, and carry out some hardware |
| 133 | * tests. |
| 134 | * |
| 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. |
| 138 | */ |
| 139 | |
| 140 | /* |
| 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. |
| 146 | * |
| 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". |
| 151 | */ |
| 152 | typedef int (init_fnc_t) (void); |
| 153 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 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); |
| 158 | |
| 159 | init_fnc_t *init_sequence_f[] = { |
| 160 | cpu_init_f, |
| 161 | board_early_init_f, |
| 162 | env_init, |
| 163 | init_baudrate, |
| 164 | serial_init, |
| 165 | console_init_f, |
| 166 | dram_init_f, |
| 167 | calculate_relocation_address, |
| 168 | copy_uboot_to_ram, |
| 169 | clear_bss, |
| 170 | do_elf_reloc_fixups, |
| 171 | |
| 172 | NULL, |
| 173 | }; |
| 174 | |
| 175 | init_fnc_t *init_sequence_r[] = { |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 176 | cpu_init_r, /* basic cpu dependent setup */ |
| 177 | board_early_init_r, /* basic board dependent setup */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 178 | dram_init, /* configure available RAM banks */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 179 | interrupt_init, /* set up exceptions */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 180 | timer_init, |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 181 | display_banner, |
| 182 | display_dram_config, |
| 183 | |
| 184 | NULL, |
| 185 | }; |
| 186 | |
Graeme Russ | 3ef96de | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 187 | gd_t *gd; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 188 | |
Graeme Russ | 71a5404 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 189 | static int calculate_relocation_address(void) |
| 190 | { |
| 191 | void *text_start = &__text_start; |
| 192 | void *bss_end = &__bss_end; |
| 193 | void *dest_addr; |
| 194 | ulong rel_offset; |
| 195 | |
| 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; |
| 201 | |
| 202 | gd->start_addr_sp = gd->ram_size; |
| 203 | gd->relocaddr = (ulong)dest_addr; |
| 204 | gd->reloc_off = rel_offset; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int copy_uboot_to_ram(void) |
| 210 | { |
| 211 | ulong *dst_addr = (ulong *)gd->relocaddr; |
| 212 | ulong *src_addr = (ulong *)&__text_start; |
| 213 | ulong *end_addr = (ulong *)&__data_end; |
| 214 | |
| 215 | while (src_addr < end_addr) |
| 216 | *dst_addr++ = *src_addr++; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int clear_bss(void) |
| 222 | { |
| 223 | void *bss_start = &__bss_start; |
| 224 | void *bss_end = &__bss_end; |
| 225 | |
| 226 | ulong *dst_addr = (ulong *)(bss_start + gd->reloc_off); |
| 227 | ulong *end_addr = (ulong *)(bss_end + gd->reloc_off);; |
| 228 | |
| 229 | while (dst_addr < end_addr) |
| 230 | *dst_addr++ = 0x00000000; |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int do_elf_reloc_fixups(void) |
| 236 | { |
| 237 | Elf32_Rel *re_src = (Elf32_Rel *)(&__rel_dyn_start); |
| 238 | Elf32_Rel *re_end = (Elf32_Rel *)(&__rel_dyn_end); |
| 239 | |
| 240 | do { |
| 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); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 249 | /* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */ |
Graeme Russ | 96cd664 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 250 | void board_init_f(ulong boot_flags) |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 251 | { |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 252 | init_fnc_t **init_fnc_ptr; |
Graeme Russ | a382414 | 2011-02-12 15:12:08 +1100 | [diff] [blame] | 253 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 254 | gd->flags = boot_flags; |
| 255 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 256 | for (init_fnc_ptr = init_sequence_f; *init_fnc_ptr; ++init_fnc_ptr) { |
| 257 | if ((*init_fnc_ptr)() != 0) |
| 258 | hang(); |
| 259 | } |
Graeme Russ | f2ff75c | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 260 | |
Graeme Russ | 2e2613d | 2011-02-12 15:11:50 +1100 | [diff] [blame] | 261 | gd->flags |= GD_FLG_RELOC; |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 262 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 263 | /* Enter the relocated U-Boot! */ |
Graeme Russ | 71a5404 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 264 | relocate_code(gd->start_addr_sp, gd, gd->relocaddr); |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 265 | |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 266 | /* NOTREACHED - relocate_code() does not return */ |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 267 | while(1); |
| 268 | } |
| 269 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 270 | void board_init_r(gd_t *id, ulong dest_addr) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 271 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 272 | char *s; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 273 | ulong size; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 274 | static bd_t bd_data; |
Graeme Russ | 2e2613d | 2011-02-12 15:11:50 +1100 | [diff] [blame] | 275 | static gd_t gd_data; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 276 | init_fnc_t **init_fnc_ptr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 277 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 278 | show_boot_progress(0x21); |
| 279 | |
Graeme Russ | 2e2613d | 2011-02-12 15:11:50 +1100 | [diff] [blame] | 280 | /* Global data pointer is now writable */ |
| 281 | gd = &gd_data; |
| 282 | memcpy(gd, id, sizeof(gd_t)); |
| 283 | |
wdenk | 93f6a67 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 284 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
| 285 | __asm__ __volatile__("": : :"memory"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 286 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 287 | gd->bd = &bd_data; |
| 288 | memset (gd->bd, 0, sizeof (bd_t)); |
| 289 | show_boot_progress(0x22); |
| 290 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 291 | gd->baudrate = CONFIG_BAUDRATE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 292 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 293 | mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3, |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 294 | CONFIG_SYS_MALLOC_LEN); |
| 295 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 296 | for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr) { |
| 297 | if ((*init_fnc_ptr)() != 0) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 298 | hang (); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 299 | } |
| 300 | show_boot_progress(0x23); |
| 301 | |
Graeme Russ | bf16500 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 302 | #ifdef CONFIG_SERIAL_MULTI |
| 303 | serial_initialize(); |
| 304 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 305 | /* configure available FLASH banks */ |
| 306 | size = flash_init(); |
| 307 | display_flash_config(size); |
| 308 | show_boot_progress(0x24); |
| 309 | |
| 310 | show_boot_progress(0x25); |
| 311 | |
| 312 | /* initialize environment */ |
| 313 | env_relocate (); |
| 314 | show_boot_progress(0x26); |
| 315 | |
| 316 | |
Graeme Russ | 535ad2d | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 317 | #ifdef CONFIG_CMD_NET |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 318 | /* IP Address */ |
| 319 | bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr"); |
Graeme Russ | 535ad2d | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 320 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 321 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 322 | #if defined(CONFIG_PCI) |
| 323 | /* |
| 324 | * Do pci configuration |
| 325 | */ |
| 326 | pci_init(); |
| 327 | #endif |
| 328 | |
| 329 | show_boot_progress(0x27); |
| 330 | |
| 331 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 332 | stdio_init (); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 333 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 334 | jumptable_init (); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 335 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 336 | /* Initialize the console (after the relocation and devices init) */ |
| 337 | console_init_r(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 338 | |
| 339 | #ifdef CONFIG_MISC_INIT_R |
| 340 | /* miscellaneous platform dependent initialisations */ |
| 341 | misc_init_r(); |
| 342 | #endif |
| 343 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 344 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 345 | WATCHDOG_RESET(); |
| 346 | puts ("PCMCIA:"); |
| 347 | pcmcia_init(); |
| 348 | #endif |
| 349 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 350 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 351 | WATCHDOG_RESET(); |
| 352 | puts("KGDB: "); |
| 353 | kgdb_init(); |
| 354 | #endif |
| 355 | |
| 356 | /* enable exceptions */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 357 | enable_interrupts(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 358 | show_boot_progress(0x28); |
| 359 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 360 | #ifdef CONFIG_STATUS_LED |
| 361 | status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING); |
| 362 | #endif |
| 363 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 364 | udelay(20); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 365 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 366 | /* Initialize from environment */ |
| 367 | if ((s = getenv ("loadaddr")) != NULL) { |
| 368 | load_addr = simple_strtoul (s, NULL, 16); |
| 369 | } |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 370 | #if defined(CONFIG_CMD_NET) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 371 | if ((s = getenv ("bootfile")) != NULL) { |
| 372 | copy_filename (BootFile, s, sizeof (BootFile)); |
| 373 | } |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 374 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 375 | |
| 376 | WATCHDOG_RESET(); |
| 377 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 378 | #if defined(CONFIG_CMD_IDE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 379 | WATCHDOG_RESET(); |
| 380 | puts("IDE: "); |
| 381 | ide_init(); |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 382 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 383 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 384 | #if defined(CONFIG_CMD_SCSI) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 385 | WATCHDOG_RESET(); |
| 386 | puts("SCSI: "); |
| 387 | scsi_init(); |
| 388 | #endif |
| 389 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 390 | #if defined(CONFIG_CMD_DOC) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 391 | WATCHDOG_RESET(); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 392 | puts("DOC: "); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 393 | doc_init(); |
| 394 | #endif |
| 395 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 396 | #ifdef CONFIG_BITBANGMII |
| 397 | bb_miiphy_init(); |
| 398 | #endif |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 399 | #if defined(CONFIG_CMD_NET) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 400 | #if defined(CONFIG_NET_MULTI) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 401 | WATCHDOG_RESET(); |
| 402 | puts("Net: "); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 403 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 404 | eth_initialize(gd->bd); |
| 405 | #endif |
| 406 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 407 | #if ( defined(CONFIG_CMD_NET)) && (0) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 408 | WATCHDOG_RESET(); |
| 409 | # ifdef DEBUG |
| 410 | puts ("Reset Ethernet PHY\n"); |
| 411 | # endif |
| 412 | reset_phy(); |
| 413 | #endif |
| 414 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 415 | #ifdef CONFIG_LAST_STAGE_INIT |
| 416 | WATCHDOG_RESET(); |
| 417 | /* |
| 418 | * Some parts can be only initialized if all others (like |
| 419 | * Interrupts) are up and running (i.e. the PC-style ISA |
| 420 | * keyboard). |
| 421 | */ |
| 422 | last_stage_init(); |
| 423 | #endif |
| 424 | |
| 425 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 426 | #ifdef CONFIG_POST |
| 427 | post_run (NULL, POST_RAM | post_bootmode_get(0)); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 428 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 429 | |
| 430 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 431 | show_boot_progress(0x29); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 432 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 433 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
| 434 | for (;;) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 435 | main_loop(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* NOTREACHED - no way out of command loop except booting */ |
| 439 | } |
| 440 | |
| 441 | void hang (void) |
| 442 | { |
| 443 | puts ("### ERROR ### Please RESET the board ###\n"); |
| 444 | for (;;); |
| 445 | } |
Mike Frysinger | a498645 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 446 | |
Graeme Russ | e69c0cb | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 447 | unsigned long do_go_exec (ulong (*entry)(int, char * const []), int argc, char * const argv[]) |
Mike Frysinger | a498645 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 448 | { |
Graeme Russ | e69c0cb | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 449 | unsigned long ret = 0; |
| 450 | char **argv_tmp; |
Graeme Russ | 9e08efc | 2010-04-24 00:05:39 +1000 | [diff] [blame] | 451 | |
Graeme Russ | e69c0cb | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 452 | /* |
| 453 | * x86 does not use a dedicated register to pass the pointer to |
| 454 | * the global_data, so it is instead passed as argv[-1]. By using |
| 455 | * argv[-1], the called 'Application' can use the contents of |
| 456 | * argv natively. However, to safely use argv[-1] a new copy of |
| 457 | * argv is needed with the extra element |
| 458 | */ |
| 459 | argv_tmp = malloc(sizeof(char *) * (argc + 1)); |
| 460 | |
| 461 | if (argv_tmp) { |
| 462 | argv_tmp[0] = (char *)gd; |
| 463 | |
| 464 | memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc)); |
| 465 | |
| 466 | ret = (entry) (argc, &argv_tmp[1]); |
| 467 | free(argv_tmp); |
| 468 | } |
| 469 | |
| 470 | return ret; |
Mike Frysinger | a498645 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 471 | } |
Graeme Russ | 79ea6b8 | 2010-04-24 00:05:48 +1000 | [diff] [blame] | 472 | |
| 473 | void setup_pcat_compatibility(void) |
| 474 | __attribute__((weak, alias("__setup_pcat_compatibility"))); |
| 475 | |
| 476 | void __setup_pcat_compatibility(void) |
| 477 | { |
| 478 | } |