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