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 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 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> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 38 | #include <version.h> |
| 39 | #include <malloc.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 40 | #include <net.h> |
| 41 | #include <ide.h> |
Graeme Russ | bf16500 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 42 | #include <serial.h> |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 43 | #include <asm/u-boot-x86.h> |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 44 | #include <asm/processor.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 45 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_BITBANGMII |
| 47 | #include <miiphy.h> |
| 48 | #endif |
| 49 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | /************************************************************************ |
| 51 | * Init Utilities * |
| 52 | ************************************************************************ |
| 53 | * Some of this code should be moved into the core functions, |
| 54 | * or dropped completely, |
| 55 | * but let's get it working (again) first... |
| 56 | */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 57 | static int init_baudrate(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | { |
Simon Glass | f5ca20c | 2011-10-13 14:43:14 +0000 | [diff] [blame] | 59 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
| 60 | return 0; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 63 | static int display_banner(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | { |
| 65 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 66 | printf("\n\n%s\n\n", version_string); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 68 | return 0; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 71 | static int display_dram_config(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | int i; |
| 74 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 75 | puts("DRAM Configuration:\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 76 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 77 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 78 | printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); |
| 79 | print_size(gd->bd->bi_dram[i].size, "\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 80 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 81 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 82 | return 0; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 85 | #ifndef CONFIG_SYS_NO_FLASH |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 86 | static void display_flash_config(ulong size) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 88 | puts("Flash: "); |
| 89 | print_size(size, "\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | } |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 91 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 92 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | /* |
| 94 | * Breath some life into the board... |
| 95 | * |
| 96 | * Initialize an SMC for serial comms, and carry out some hardware |
| 97 | * tests. |
| 98 | * |
| 99 | * The first part of initialization is running from Flash memory; |
| 100 | * its main purpose is to initialize the RAM so that we |
| 101 | * can relocate the monitor code to RAM. |
| 102 | */ |
| 103 | |
| 104 | /* |
| 105 | * All attempts to come up with a "common" initialization sequence |
| 106 | * that works for all boards and architectures failed: some of the |
| 107 | * requirements are just _too_ different. To get rid of the resulting |
| 108 | * mess of board dependend #ifdef'ed code we now make the whole |
| 109 | * initialization sequence configurable to the user. |
| 110 | * |
| 111 | * The requirements for any new initalization function is simple: it |
| 112 | * receives a pointer to the "global data" structure as it's only |
| 113 | * argument, and returns an integer return code, where 0 means |
| 114 | * "continue" and != 0 means "fatal error, hang the system". |
| 115 | */ |
| 116 | typedef int (init_fnc_t) (void); |
| 117 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 118 | static int calculate_relocation_address(void); |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 119 | static int copy_gd_to_ram(void); |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 120 | |
| 121 | init_fnc_t *init_sequence_f[] = { |
| 122 | cpu_init_f, |
| 123 | board_early_init_f, |
| 124 | env_init, |
| 125 | init_baudrate, |
| 126 | serial_init, |
| 127 | console_init_f, |
| 128 | dram_init_f, |
| 129 | calculate_relocation_address, |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 130 | |
| 131 | NULL, |
| 132 | }; |
| 133 | |
| 134 | init_fnc_t *init_sequence_r[] = { |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 135 | cpu_init_r, /* basic cpu dependent setup */ |
| 136 | board_early_init_r, /* basic board dependent setup */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 137 | dram_init, /* configure available RAM banks */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 138 | interrupt_init, /* set up exceptions */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 139 | timer_init, |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 140 | display_banner, |
| 141 | display_dram_config, |
| 142 | |
| 143 | NULL, |
| 144 | }; |
| 145 | |
Graeme Russ | 71a5404 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 146 | static int calculate_relocation_address(void) |
| 147 | { |
Graeme Russ | 303418c | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 148 | ulong text_start = (ulong)&__text_start; |
| 149 | ulong bss_end = (ulong)&__bss_end; |
| 150 | ulong dest_addr; |
Graeme Russ | 303418c | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 151 | |
| 152 | /* |
Graeme Russ | 240ab5a | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 153 | * NOTE: All destination address are rounded down to 16-byte |
| 154 | * boundary to satisfy various worst-case alignment |
| 155 | * requirements |
Graeme Russ | 303418c | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 156 | */ |
Graeme Russ | 240ab5a | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 157 | |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 158 | /* Global Data is at top of available memory */ |
Graeme Russ | 240ab5a | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 159 | dest_addr = gd->ram_size; |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 160 | dest_addr -= GENERATED_GBL_DATA_SIZE; |
| 161 | dest_addr &= ~15; |
| 162 | gd->new_gd_addr = dest_addr; |
| 163 | |
| 164 | /* GDT is below Global Data */ |
| 165 | dest_addr -= X86_GDT_SIZE; |
| 166 | dest_addr &= ~15; |
| 167 | gd->gdt_addr = dest_addr; |
| 168 | |
| 169 | /* Stack is below GDT */ |
Graeme Russ | 240ab5a | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 170 | gd->start_addr_sp = dest_addr; |
| 171 | |
| 172 | /* U-Boot is below the stack */ |
| 173 | dest_addr -= CONFIG_SYS_STACK_SIZE; |
| 174 | dest_addr -= (bss_end - text_start); |
Graeme Russ | 303418c | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 175 | dest_addr &= ~15; |
Graeme Russ | 303418c | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 176 | gd->relocaddr = dest_addr; |
Graeme Russ | 240ab5a | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 177 | gd->reloc_off = (dest_addr - text_start); |
Graeme Russ | 71a5404 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 182 | /* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */ |
Graeme Russ | 96cd664 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 183 | void board_init_f(ulong boot_flags) |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 184 | { |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 185 | init_fnc_t **init_fnc_ptr; |
Graeme Russ | a382414 | 2011-02-12 15:12:08 +1100 | [diff] [blame] | 186 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 187 | gd->flags = boot_flags; |
| 188 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 189 | for (init_fnc_ptr = init_sequence_f; *init_fnc_ptr; ++init_fnc_ptr) { |
| 190 | if ((*init_fnc_ptr)() != 0) |
| 191 | hang(); |
| 192 | } |
Graeme Russ | f2ff75c | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 193 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 194 | /* |
| 195 | * SDRAM is now initialised, U-Boot has been copied into SDRAM, |
| 196 | * the BSS has been cleared etc. The final stack can now be setup |
| 197 | * in SDRAM. Code execution will continue (momentarily) in Flash, |
| 198 | * but with the stack in SDRAM and Global Data in temporary memory |
| 199 | * (CPU cache) |
| 200 | */ |
| 201 | board_init_f_r_trampoline(gd->start_addr_sp); |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 202 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 203 | /* NOTREACHED - board_init_f_r_trampoline() does not return */ |
| 204 | while (1) |
| 205 | ; |
| 206 | } |
| 207 | |
| 208 | void board_init_f_r(void) |
| 209 | { |
Graeme Russ | 98f1fa9 | 2011-12-27 22:46:42 +1100 | [diff] [blame] | 210 | if (copy_gd_to_ram() != 0) |
| 211 | hang(); |
| 212 | |
| 213 | if (init_cache() != 0) |
| 214 | hang(); |
| 215 | |
Graeme Russ | b156ff0 | 2011-12-23 15:57:58 +1100 | [diff] [blame^] | 216 | relocate_code(0, gd, 0); |
Graeme Russ | 98f1fa9 | 2011-12-27 22:46:42 +1100 | [diff] [blame] | 217 | |
Graeme Russ | b156ff0 | 2011-12-23 15:57:58 +1100 | [diff] [blame^] | 218 | /* NOTREACHED - relocate_code() does not return */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 219 | while (1) |
| 220 | ; |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 221 | } |
| 222 | |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 223 | static int copy_gd_to_ram(void) |
| 224 | { |
| 225 | gd_t *ram_gd; |
| 226 | |
| 227 | /* |
| 228 | * Global data is still in temporary memory (the CPU cache). |
| 229 | * calculate_relocation_address() has set gd->new_gd_addr to |
| 230 | * where the global data lives in RAM but getting it there |
| 231 | * safely is a bit tricky due to the 'F-Segment Hack' that |
| 232 | * we need to use for x86 |
| 233 | */ |
| 234 | ram_gd = (gd_t *)gd->new_gd_addr; |
| 235 | memcpy((void *)ram_gd, gd, sizeof(gd_t)); |
| 236 | |
| 237 | /* |
| 238 | * Reload the Global Descriptor Table so FS points to the |
| 239 | * in-RAM copy of Global Data (calculate_relocation_address() |
| 240 | * has already calculated the in-RAM location of the GDT) |
| 241 | */ |
| 242 | ram_gd->gd_addr = (ulong)ram_gd; |
| 243 | init_gd(ram_gd, (u64 *)gd->gdt_addr); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 248 | void board_init_r(gd_t *id, ulong dest_addr) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 249 | { |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 250 | #if defined(CONFIG_CMD_NET) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 251 | char *s; |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 252 | #endif |
| 253 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 254 | ulong size; |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 255 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 256 | static bd_t bd_data; |
| 257 | init_fnc_t **init_fnc_ptr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 258 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 259 | show_boot_progress(0x21); |
| 260 | |
wdenk | 93f6a67 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 261 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 262 | __asm__ __volatile__("" : : : "memory"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 263 | |
Graeme Russ | 3766bb3 | 2012-01-01 15:49:43 +1100 | [diff] [blame] | 264 | gd->flags |= GD_FLG_RELOC; |
| 265 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 266 | gd->bd = &bd_data; |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 267 | memset(gd->bd, 0, sizeof(bd_t)); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 268 | show_boot_progress(0x22); |
| 269 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 270 | gd->baudrate = CONFIG_BAUDRATE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 271 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 272 | mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3, |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 273 | CONFIG_SYS_MALLOC_LEN); |
| 274 | |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 275 | for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr) { |
| 276 | if ((*init_fnc_ptr)() != 0) |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 277 | hang(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 278 | } |
| 279 | show_boot_progress(0x23); |
| 280 | |
Graeme Russ | bf16500 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 281 | #ifdef CONFIG_SERIAL_MULTI |
| 282 | serial_initialize(); |
| 283 | #endif |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 284 | |
| 285 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 286 | /* configure available FLASH banks */ |
| 287 | size = flash_init(); |
| 288 | display_flash_config(size); |
| 289 | show_boot_progress(0x24); |
Graeme Russ | a76fc70 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 290 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 291 | |
| 292 | show_boot_progress(0x25); |
| 293 | |
| 294 | /* initialize environment */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 295 | env_relocate(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 296 | show_boot_progress(0x26); |
| 297 | |
| 298 | |
Graeme Russ | 535ad2d | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 299 | #ifdef CONFIG_CMD_NET |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 300 | /* IP Address */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 301 | bd_data.bi_ip_addr = getenv_IPaddr("ipaddr"); |
Graeme Russ | 535ad2d | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 302 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 303 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 304 | #if defined(CONFIG_PCI) |
| 305 | /* |
| 306 | * Do pci configuration |
| 307 | */ |
| 308 | pci_init(); |
| 309 | #endif |
| 310 | |
| 311 | show_boot_progress(0x27); |
| 312 | |
| 313 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 314 | stdio_init(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 315 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 316 | jumptable_init(); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 317 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 318 | /* Initialize the console (after the relocation and devices init) */ |
| 319 | console_init_r(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 320 | |
| 321 | #ifdef CONFIG_MISC_INIT_R |
| 322 | /* miscellaneous platform dependent initialisations */ |
| 323 | misc_init_r(); |
| 324 | #endif |
| 325 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 326 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 327 | WATCHDOG_RESET(); |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 328 | puts("PCMCIA:"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 329 | pcmcia_init(); |
| 330 | #endif |
| 331 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 332 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 333 | WATCHDOG_RESET(); |
| 334 | puts("KGDB: "); |
| 335 | kgdb_init(); |
| 336 | #endif |
| 337 | |
| 338 | /* enable exceptions */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 339 | enable_interrupts(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 340 | show_boot_progress(0x28); |
| 341 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 342 | #ifdef CONFIG_STATUS_LED |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 343 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 344 | #endif |
| 345 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 346 | udelay(20); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 347 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 348 | /* Initialize from environment */ |
Simon Glass | f5ca20c | 2011-10-13 14:43:14 +0000 | [diff] [blame] | 349 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 350 | #if defined(CONFIG_CMD_NET) |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 351 | s = getenv("bootfile"); |
| 352 | |
| 353 | if (s != NULL) |
| 354 | copy_filename(BootFile, s, sizeof(BootFile)); |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 355 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 356 | |
| 357 | WATCHDOG_RESET(); |
| 358 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 359 | #if defined(CONFIG_CMD_IDE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 360 | WATCHDOG_RESET(); |
| 361 | puts("IDE: "); |
| 362 | ide_init(); |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 363 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 364 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 365 | #if defined(CONFIG_CMD_SCSI) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 366 | WATCHDOG_RESET(); |
| 367 | puts("SCSI: "); |
| 368 | scsi_init(); |
| 369 | #endif |
| 370 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 371 | #if defined(CONFIG_CMD_DOC) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 372 | WATCHDOG_RESET(); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 373 | puts("DOC: "); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 374 | doc_init(); |
| 375 | #endif |
| 376 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 377 | #ifdef CONFIG_BITBANGMII |
| 378 | bb_miiphy_init(); |
| 379 | #endif |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 380 | #if defined(CONFIG_CMD_NET) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 381 | WATCHDOG_RESET(); |
| 382 | puts("Net: "); |
| 383 | eth_initialize(gd->bd); |
| 384 | #endif |
| 385 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 386 | #if (defined(CONFIG_CMD_NET)) && (0) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 387 | WATCHDOG_RESET(); |
| 388 | # ifdef DEBUG |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 389 | puts("Reset Ethernet PHY\n"); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 390 | # endif |
| 391 | reset_phy(); |
| 392 | #endif |
| 393 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 394 | #ifdef CONFIG_LAST_STAGE_INIT |
| 395 | WATCHDOG_RESET(); |
| 396 | /* |
| 397 | * Some parts can be only initialized if all others (like |
| 398 | * Interrupts) are up and running (i.e. the PC-style ISA |
| 399 | * keyboard). |
| 400 | */ |
| 401 | last_stage_init(); |
| 402 | #endif |
| 403 | |
| 404 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 405 | #ifdef CONFIG_POST |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 406 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 407 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 408 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 409 | show_boot_progress(0x29); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 410 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 411 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 412 | for (;;) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 413 | main_loop(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 414 | |
| 415 | /* NOTREACHED - no way out of command loop except booting */ |
| 416 | } |
| 417 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 418 | void hang(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 419 | { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 420 | puts("### ERROR ### Please RESET the board ###\n"); |
| 421 | for (;;) |
| 422 | ; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 423 | } |