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