wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 2 | * (C) Copyright 2008-2011 |
| 3 | * Graeme Russ, <graeme.russ@gmail.com> |
| 4 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 7 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 8 | * (C) Copyright 2002 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 9 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
wdenk | 591dda5 | 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 | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 37 | #include <stdio_dev.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 38 | #include <version.h> |
| 39 | #include <malloc.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 40 | #include <net.h> |
| 41 | #include <ide.h> |
Graeme Russ | 06dfe37 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 42 | #include <serial.h> |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 43 | #include <asm/u-boot-x86.h> |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 44 | #include <elf.h> |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 45 | #include <asm/processor.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_BITBANGMII |
| 48 | #include <miiphy.h> |
| 49 | #endif |
| 50 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 51 | /************************************************************************ |
| 52 | * Init Utilities * |
| 53 | ************************************************************************ |
| 54 | * Some of this code should be moved into the core functions, |
| 55 | * or dropped completely, |
| 56 | * but let's get it working (again) first... |
| 57 | */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 58 | static int init_baudrate(void) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | { |
Simon Glass | 32ef00a | 2011-10-13 14:43:14 +0000 | [diff] [blame] | 60 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
| 61 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 64 | static int display_banner(void) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 65 | { |
| 66 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 67 | printf("\n\n%s\n\n", version_string); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 68 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 69 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 72 | static int display_dram_config(void) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | int i; |
| 75 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 76 | puts("DRAM Configuration:\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 78 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 79 | printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); |
| 80 | print_size(gd->bd->bi_dram[i].size, "\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 82 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 83 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 86 | #ifndef CONFIG_SYS_NO_FLASH |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 87 | static void display_flash_config(ulong size) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 89 | puts("Flash: "); |
| 90 | print_size(size, "\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 91 | } |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 92 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 94 | /* |
| 95 | * Breath some life into the board... |
| 96 | * |
| 97 | * Initialize an SMC for serial comms, and carry out some hardware |
| 98 | * tests. |
| 99 | * |
| 100 | * The first part of initialization is running from Flash memory; |
| 101 | * its main purpose is to initialize the RAM so that we |
| 102 | * can relocate the monitor code to RAM. |
| 103 | */ |
| 104 | |
| 105 | /* |
| 106 | * All attempts to come up with a "common" initialization sequence |
| 107 | * that works for all boards and architectures failed: some of the |
| 108 | * requirements are just _too_ different. To get rid of the resulting |
| 109 | * mess of board dependend #ifdef'ed code we now make the whole |
| 110 | * initialization sequence configurable to the user. |
| 111 | * |
| 112 | * The requirements for any new initalization function is simple: it |
| 113 | * receives a pointer to the "global data" structure as it's only |
| 114 | * argument, and returns an integer return code, where 0 means |
| 115 | * "continue" and != 0 means "fatal error, hang the system". |
| 116 | */ |
| 117 | typedef int (init_fnc_t) (void); |
| 118 | |
Graeme Russ | 6ec93c3 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 119 | static int calculate_relocation_address(void); |
| 120 | static int copy_uboot_to_ram(void); |
| 121 | static int clear_bss(void); |
| 122 | static int do_elf_reloc_fixups(void); |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 123 | static int copy_gd_to_ram(void); |
Graeme Russ | 6ec93c3 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 124 | |
| 125 | init_fnc_t *init_sequence_f[] = { |
| 126 | cpu_init_f, |
| 127 | board_early_init_f, |
| 128 | env_init, |
| 129 | init_baudrate, |
| 130 | serial_init, |
| 131 | console_init_f, |
| 132 | dram_init_f, |
| 133 | calculate_relocation_address, |
| 134 | copy_uboot_to_ram, |
| 135 | clear_bss, |
| 136 | do_elf_reloc_fixups, |
| 137 | |
| 138 | NULL, |
| 139 | }; |
| 140 | |
| 141 | init_fnc_t *init_sequence_r[] = { |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 142 | copy_gd_to_ram, |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 143 | cpu_init_r, /* basic cpu dependent setup */ |
| 144 | board_early_init_r, /* basic board dependent setup */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 145 | dram_init, /* configure available RAM banks */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 146 | interrupt_init, /* set up exceptions */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 147 | timer_init, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 148 | display_banner, |
| 149 | display_dram_config, |
| 150 | |
| 151 | NULL, |
| 152 | }; |
| 153 | |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 154 | static int calculate_relocation_address(void) |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 155 | { |
Graeme Russ | 2768d85 | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 156 | ulong text_start = (ulong)&__text_start; |
| 157 | ulong bss_end = (ulong)&__bss_end; |
| 158 | ulong dest_addr; |
Graeme Russ | 2768d85 | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 159 | |
| 160 | /* |
Graeme Russ | 6aa071f | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 161 | * NOTE: All destination address are rounded down to 16-byte |
| 162 | * boundary to satisfy various worst-case alignment |
| 163 | * requirements |
Graeme Russ | 2768d85 | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 164 | */ |
Graeme Russ | 2768d85 | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 165 | |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 166 | /* Global Data is at top of available memory */ |
Graeme Russ | 6aa071f | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 167 | dest_addr = gd->ram_size; |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 168 | dest_addr -= GENERATED_GBL_DATA_SIZE; |
| 169 | dest_addr &= ~15; |
| 170 | gd->new_gd_addr = dest_addr; |
| 171 | |
| 172 | /* GDT is below Global Data */ |
| 173 | dest_addr -= X86_GDT_SIZE; |
| 174 | dest_addr &= ~15; |
| 175 | gd->gdt_addr = dest_addr; |
| 176 | |
| 177 | /* Stack is below GDT */ |
Graeme Russ | 6aa071f | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 178 | gd->start_addr_sp = dest_addr; |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 179 | |
Graeme Russ | 6aa071f | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 180 | /* U-Boot is below the stack */ |
| 181 | dest_addr -= CONFIG_SYS_STACK_SIZE; |
| 182 | dest_addr -= (bss_end - text_start); |
| 183 | dest_addr &= ~15; |
Graeme Russ | 2768d85 | 2011-11-08 02:33:21 +0000 | [diff] [blame] | 184 | gd->relocaddr = dest_addr; |
Graeme Russ | 6aa071f | 2012-01-01 15:57:02 +1100 | [diff] [blame] | 185 | gd->reloc_off = (dest_addr - text_start); |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int copy_uboot_to_ram(void) |
| 191 | { |
Graeme Russ | 9954080 | 2011-12-27 22:46:41 +1100 | [diff] [blame] | 192 | size_t len = (size_t)&__data_end - (size_t)&__text_start; |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 193 | |
Graeme Russ | 9954080 | 2011-12-27 22:46:41 +1100 | [diff] [blame] | 194 | memcpy((void *)gd->relocaddr, (void *)&__text_start, len); |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int clear_bss(void) |
| 200 | { |
Graeme Russ | 9954080 | 2011-12-27 22:46:41 +1100 | [diff] [blame] | 201 | ulong dst_addr = (ulong)&__bss_start + gd->reloc_off; |
| 202 | size_t len = (size_t)&__bss_end - (size_t)&__bss_start; |
Graeme Russ | 9905285 | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 203 | |
Graeme Russ | 9954080 | 2011-12-27 22:46:41 +1100 | [diff] [blame] | 204 | memset((void *)dst_addr, 0x00, len); |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int do_elf_reloc_fixups(void) |
| 210 | { |
| 211 | Elf32_Rel *re_src = (Elf32_Rel *)(&__rel_dyn_start); |
| 212 | Elf32_Rel *re_end = (Elf32_Rel *)(&__rel_dyn_end); |
| 213 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 214 | Elf32_Addr *offset_ptr_rom; |
| 215 | Elf32_Addr *offset_ptr_ram; |
| 216 | |
Gabe Black | 6ed1888 | 2011-11-16 23:32:50 +0000 | [diff] [blame] | 217 | /* The size of the region of u-boot that runs out of RAM. */ |
| 218 | uintptr_t size = (uintptr_t)&__bss_end - (uintptr_t)&__text_start; |
| 219 | |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 220 | do { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 221 | /* Get the location from the relocation entry */ |
| 222 | offset_ptr_rom = (Elf32_Addr *)re_src->r_offset; |
| 223 | |
| 224 | /* Check that the location of the relocation is in .text */ |
| 225 | if (offset_ptr_rom >= (Elf32_Addr *)CONFIG_SYS_TEXT_BASE) { |
| 226 | |
| 227 | /* Switch to the in-RAM version */ |
Gabe Black | 6ed1888 | 2011-11-16 23:32:50 +0000 | [diff] [blame] | 228 | offset_ptr_ram = (Elf32_Addr *)((ulong)offset_ptr_rom + |
| 229 | gd->reloc_off); |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 230 | |
| 231 | /* Check that the target points into .text */ |
Gabe Black | 3530c07 | 2011-11-12 16:34:48 +0000 | [diff] [blame] | 232 | if (*offset_ptr_ram >= CONFIG_SYS_TEXT_BASE && |
| 233 | *offset_ptr_ram < |
| 234 | (CONFIG_SYS_TEXT_BASE + size)) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 235 | *offset_ptr_ram += gd->reloc_off; |
Gabe Black | 3530c07 | 2011-11-12 16:34:48 +0000 | [diff] [blame] | 236 | } |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 237 | } |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 238 | } while (re_src++ < re_end); |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 239 | |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 240 | return 0; |
| 241 | } |
Graeme Russ | 3818393 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 242 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 243 | /* Load U-Boot into RAM, initialize BSS, perform relocation adjustments */ |
Graeme Russ | 4b25982 | 2011-02-12 15:12:06 +1100 | [diff] [blame] | 244 | void board_init_f(ulong boot_flags) |
| 245 | { |
Graeme Russ | 6ec93c3 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 246 | init_fnc_t **init_fnc_ptr; |
Graeme Russ | 9905285 | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 247 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 248 | gd->flags = boot_flags; |
| 249 | |
Graeme Russ | 6ec93c3 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 250 | for (init_fnc_ptr = init_sequence_f; *init_fnc_ptr; ++init_fnc_ptr) { |
| 251 | if ((*init_fnc_ptr)() != 0) |
| 252 | hang(); |
| 253 | } |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 254 | |
Graeme Russ | 4e0f55f | 2011-02-12 15:11:50 +1100 | [diff] [blame] | 255 | gd->flags |= GD_FLG_RELOC; |
Graeme Russ | 5fb91cc | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 256 | |
Graeme Russ | d7755b4 | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 257 | /* |
| 258 | * SDRAM is now initialised, U-Boot has been copied into SDRAM, |
| 259 | * the BSS has been cleared etc. The final stack can now be setup |
| 260 | * in SDRAM. Code execution will continue (momentarily) in Flash, |
| 261 | * but with the stack in SDRAM and Global Data in temporary memory |
| 262 | * (CPU cache) |
| 263 | */ |
| 264 | board_init_f_r_trampoline(gd->start_addr_sp); |
| 265 | |
| 266 | /* NOTREACHED - board_init_f_r_trampoline() does not return */ |
| 267 | while (1) |
| 268 | ; |
| 269 | } |
| 270 | |
| 271 | void board_init_f_r(void) |
| 272 | { |
| 273 | /* |
| 274 | * Transfer execution from Flash to RAM by calculating the address |
| 275 | * of the in-RAM copy of board_init_r() and calling it |
| 276 | */ |
| 277 | (board_init_r + gd->reloc_off)(gd, gd->relocaddr); |
Graeme Russ | 5fb91cc | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 278 | |
Graeme Russ | d7755b4 | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 279 | /* NOTREACHED - board_init_r() does not return */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 280 | while (1) |
| 281 | ; |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 282 | } |
| 283 | |
Graeme Russ | 3536896 | 2011-12-31 22:58:15 +1100 | [diff] [blame^] | 284 | static int copy_gd_to_ram(void) |
| 285 | { |
| 286 | gd_t *ram_gd; |
| 287 | |
| 288 | /* |
| 289 | * Global data is still in temporary memory (the CPU cache). |
| 290 | * calculate_relocation_address() has set gd->new_gd_addr to |
| 291 | * where the global data lives in RAM but getting it there |
| 292 | * safely is a bit tricky due to the 'F-Segment Hack' that |
| 293 | * we need to use for x86 |
| 294 | */ |
| 295 | ram_gd = (gd_t *)gd->new_gd_addr; |
| 296 | memcpy((void *)ram_gd, gd, sizeof(gd_t)); |
| 297 | |
| 298 | /* |
| 299 | * Reload the Global Descriptor Table so FS points to the |
| 300 | * in-RAM copy of Global Data (calculate_relocation_address() |
| 301 | * has already calculated the in-RAM location of the GDT) |
| 302 | */ |
| 303 | ram_gd->gd_addr = (ulong)ram_gd; |
| 304 | init_gd(ram_gd, (u64 *)gd->gdt_addr); |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Graeme Russ | e07da07 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 309 | void board_init_r(gd_t *id, ulong dest_addr) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 310 | { |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 311 | #if defined(CONFIG_CMD_NET) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 312 | char *s; |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 313 | #endif |
| 314 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 315 | ulong size; |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 316 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 317 | static bd_t bd_data; |
| 318 | init_fnc_t **init_fnc_ptr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 319 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 320 | show_boot_progress(0x21); |
| 321 | |
wdenk | 3337af4 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 322 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 323 | __asm__ __volatile__("" : : : "memory"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 324 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 325 | gd->bd = &bd_data; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 326 | memset(gd->bd, 0, sizeof(bd_t)); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 327 | show_boot_progress(0x22); |
| 328 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 329 | gd->baudrate = CONFIG_BAUDRATE; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 330 | |
Graeme Russ | e07da07 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 331 | mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3, |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 332 | CONFIG_SYS_MALLOC_LEN); |
| 333 | |
Graeme Russ | 6ec93c3 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 334 | for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr) { |
| 335 | if ((*init_fnc_ptr)() != 0) |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 336 | hang(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 337 | } |
| 338 | show_boot_progress(0x23); |
| 339 | |
Graeme Russ | 06dfe37 | 2010-04-24 00:05:47 +1000 | [diff] [blame] | 340 | #ifdef CONFIG_SERIAL_MULTI |
| 341 | serial_initialize(); |
| 342 | #endif |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 343 | |
| 344 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 345 | /* configure available FLASH banks */ |
| 346 | size = flash_init(); |
| 347 | display_flash_config(size); |
| 348 | show_boot_progress(0x24); |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 349 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 350 | |
| 351 | show_boot_progress(0x25); |
| 352 | |
| 353 | /* initialize environment */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 354 | env_relocate(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 355 | show_boot_progress(0x26); |
| 356 | |
| 357 | |
Graeme Russ | d520c0e | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 358 | #ifdef CONFIG_CMD_NET |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 359 | /* IP Address */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 360 | bd_data.bi_ip_addr = getenv_IPaddr("ipaddr"); |
Graeme Russ | d520c0e | 2010-04-24 00:05:36 +1000 | [diff] [blame] | 361 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 362 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 363 | #if defined(CONFIG_PCI) |
| 364 | /* |
| 365 | * Do pci configuration |
| 366 | */ |
| 367 | pci_init(); |
| 368 | #endif |
| 369 | |
| 370 | show_boot_progress(0x27); |
| 371 | |
| 372 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 373 | stdio_init(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 374 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 375 | jumptable_init(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 376 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 377 | /* Initialize the console (after the relocation and devices init) */ |
| 378 | console_init_r(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 379 | |
| 380 | #ifdef CONFIG_MISC_INIT_R |
| 381 | /* miscellaneous platform dependent initialisations */ |
| 382 | misc_init_r(); |
| 383 | #endif |
| 384 | |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 385 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 386 | WATCHDOG_RESET(); |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 387 | puts("PCMCIA:"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 388 | pcmcia_init(); |
| 389 | #endif |
| 390 | |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 391 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 392 | WATCHDOG_RESET(); |
| 393 | puts("KGDB: "); |
| 394 | kgdb_init(); |
| 395 | #endif |
| 396 | |
| 397 | /* enable exceptions */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 398 | enable_interrupts(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 399 | show_boot_progress(0x28); |
| 400 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 401 | #ifdef CONFIG_STATUS_LED |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 402 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 403 | #endif |
| 404 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 405 | udelay(20); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 406 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 407 | /* Initialize from environment */ |
Simon Glass | 32ef00a | 2011-10-13 14:43:14 +0000 | [diff] [blame] | 408 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 409 | #if defined(CONFIG_CMD_NET) |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 410 | s = getenv("bootfile"); |
| 411 | |
| 412 | if (s != NULL) |
| 413 | copy_filename(BootFile, s, sizeof(BootFile)); |
Jon Loeliger | 1670a5b | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 414 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 415 | |
| 416 | WATCHDOG_RESET(); |
| 417 | |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 418 | #if defined(CONFIG_CMD_IDE) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 419 | WATCHDOG_RESET(); |
| 420 | puts("IDE: "); |
| 421 | ide_init(); |
Jon Loeliger | 1670a5b | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 422 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 423 | |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 424 | #if defined(CONFIG_CMD_SCSI) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 425 | WATCHDOG_RESET(); |
| 426 | puts("SCSI: "); |
| 427 | scsi_init(); |
| 428 | #endif |
| 429 | |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 430 | #if defined(CONFIG_CMD_DOC) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 431 | WATCHDOG_RESET(); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 432 | puts("DOC: "); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 433 | doc_init(); |
| 434 | #endif |
| 435 | |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 436 | #ifdef CONFIG_BITBANGMII |
| 437 | bb_miiphy_init(); |
| 438 | #endif |
Jon Loeliger | 1207797 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 439 | #if defined(CONFIG_CMD_NET) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 440 | WATCHDOG_RESET(); |
| 441 | puts("Net: "); |
| 442 | eth_initialize(gd->bd); |
| 443 | #endif |
| 444 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 445 | #if (defined(CONFIG_CMD_NET)) && (0) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 446 | WATCHDOG_RESET(); |
| 447 | # ifdef DEBUG |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 448 | puts("Reset Ethernet PHY\n"); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 449 | # endif |
| 450 | reset_phy(); |
| 451 | #endif |
| 452 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 453 | #ifdef CONFIG_LAST_STAGE_INIT |
| 454 | WATCHDOG_RESET(); |
| 455 | /* |
| 456 | * Some parts can be only initialized if all others (like |
| 457 | * Interrupts) are up and running (i.e. the PC-style ISA |
| 458 | * keyboard). |
| 459 | */ |
| 460 | last_stage_init(); |
| 461 | #endif |
| 462 | |
| 463 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 464 | #ifdef CONFIG_POST |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 465 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 466 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 467 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 468 | show_boot_progress(0x29); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 469 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 470 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 471 | for (;;) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 472 | main_loop(); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 473 | |
| 474 | /* NOTREACHED - no way out of command loop except booting */ |
| 475 | } |
| 476 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 477 | void hang(void) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 478 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 479 | puts("### ERROR ### Please RESET the board ###\n"); |
| 480 | for (;;) |
| 481 | ; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 482 | } |
Mike Frysinger | 0870e47 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 483 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 484 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), |
| 485 | int argc, char * const argv[]) |
Mike Frysinger | 0870e47 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 486 | { |
Graeme Russ | 757660f | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 487 | unsigned long ret = 0; |
| 488 | char **argv_tmp; |
| 489 | |
Mike Frysinger | 0870e47 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 490 | /* |
Graeme Russ | 757660f | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 491 | * x86 does not use a dedicated register to pass the pointer to |
| 492 | * the global_data, so it is instead passed as argv[-1]. By using |
| 493 | * argv[-1], the called 'Application' can use the contents of |
| 494 | * argv natively. However, to safely use argv[-1] a new copy of |
| 495 | * argv is needed with the extra element |
Mike Frysinger | 0870e47 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 496 | */ |
Graeme Russ | 757660f | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 497 | argv_tmp = malloc(sizeof(char *) * (argc + 1)); |
| 498 | |
| 499 | if (argv_tmp) { |
| 500 | argv_tmp[0] = (char *)gd; |
| 501 | |
| 502 | memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc)); |
| 503 | |
| 504 | ret = (entry) (argc, &argv_tmp[1]); |
| 505 | free(argv_tmp); |
| 506 | } |
Graeme Russ | 0b9fe9d | 2010-04-24 00:05:39 +1000 | [diff] [blame] | 507 | |
Graeme Russ | 757660f | 2010-08-22 16:25:58 +1000 | [diff] [blame] | 508 | return ret; |
Mike Frysinger | 0870e47 | 2008-04-13 19:42:19 -0400 | [diff] [blame] | 509 | } |
Graeme Russ | a8d06b4 | 2010-04-24 00:05:48 +1000 | [diff] [blame] | 510 | |
| 511 | void setup_pcat_compatibility(void) |
| 512 | __attribute__((weak, alias("__setup_pcat_compatibility"))); |
| 513 | |
| 514 | void __setup_pcat_compatibility(void) |
| 515 | { |
| 516 | } |