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> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 36 | #include <stdio_dev.h> |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 37 | #include <asm/u-boot-x86.h> |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 38 | #include <asm/relocate.h> |
Graeme Russ | 8d61625 | 2012-11-27 15:38:36 +0000 | [diff] [blame] | 39 | #include <asm/processor.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 40 | |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 41 | #include <asm/init_helpers.h> |
| 42 | #include <asm/init_wrappers.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 43 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | /* |
| 45 | * Breath some life into the board... |
| 46 | * |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 47 | * Getting the board up and running is a three-stage process: |
| 48 | * 1) Execute from Flash, SDRAM Uninitialised |
| 49 | * At this point, there is a limited amount of non-SDRAM memory |
| 50 | * (typically the CPU cache, but can also be SRAM or even a buffer of |
| 51 | * of some peripheral). This limited memory is used to hold: |
| 52 | * - The initial copy of the Global Data Structure |
| 53 | * - A temporary stack |
| 54 | * - A temporary x86 Global Descriptor Table |
| 55 | * - The pre-console buffer (if enabled) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | * |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 57 | * The following is performed during this phase of execution: |
| 58 | * - Core low-level CPU initialisation |
| 59 | * - Console initialisation |
| 60 | * - SDRAM initialisation |
| 61 | * |
| 62 | * 2) Execute from Flash, SDRAM Initialised |
| 63 | * At this point we copy Global Data from the initial non-SDRAM |
| 64 | * memory and set up the permanent stack in SDRAM. The CPU cache is no |
| 65 | * longer being used as temporary memory, so we can now fully enable |
| 66 | * it. |
| 67 | * |
| 68 | * The following is performed during this phase of execution: |
| 69 | * - Create final stack in SDRAM |
| 70 | * - Copy Global Data from temporary memory to SDRAM |
| 71 | * - Enabling of CPU cache(s), |
| 72 | * - Copying of U-Boot code and data from Flash to RAM |
| 73 | * - Clearing of the BSS |
| 74 | * - ELF relocation adjustments |
| 75 | * |
| 76 | * 3) Execute from SDRAM |
| 77 | * The following is performed during this phase of execution: |
| 78 | * - All remaining initialisation |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | /* |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 82 | * The requirements for any new initalization function is simple: it is |
| 83 | * a function with no parameters which returns an integer return code, |
| 84 | * where 0 means "continue" and != 0 means "fatal error, hang the system" |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | */ |
| 86 | typedef int (init_fnc_t) (void); |
| 87 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 88 | /* |
| 89 | * init_sequence_f is the list of init functions which are run when U-Boot |
| 90 | * is executing from Flash with a limited 'C' environment. The following |
| 91 | * limitations must be considered when implementing an '_f' function: |
| 92 | * - 'static' variables are read-only |
| 93 | * - Global Data (gd->xxx) is read/write |
| 94 | * - Stack space is limited |
| 95 | * |
| 96 | * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_ |
| 97 | * also initialise the console (to provide early debug output) |
| 98 | */ |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 99 | init_fnc_t *init_sequence_f[] = { |
| 100 | cpu_init_f, |
| 101 | board_early_init_f, |
Gabe Black | b208c7f | 2012-11-03 11:41:30 +0000 | [diff] [blame] | 102 | #ifdef CONFIG_OF_CONTROL |
| 103 | find_fdt, |
| 104 | fdtdec_check_fdt, |
| 105 | #endif |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 106 | env_init, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 107 | init_baudrate_f, |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 108 | serial_init, |
| 109 | console_init_f, |
Gabe Black | b208c7f | 2012-11-03 11:41:30 +0000 | [diff] [blame] | 110 | #ifdef CONFIG_OF_CONTROL |
| 111 | prepare_fdt, |
| 112 | #endif |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 113 | dram_init_f, |
| 114 | calculate_relocation_address, |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 115 | |
| 116 | NULL, |
| 117 | }; |
| 118 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 119 | /* |
| 120 | * init_sequence_f_r is the list of init functions which are run when |
| 121 | * U-Boot is executing from Flash with a semi-limited 'C' environment. |
| 122 | * The following limitations must be considered when implementing an |
| 123 | * '_f_r' function: |
| 124 | * - 'static' variables are read-only |
| 125 | * - Global Data (gd->xxx) is read/write |
| 126 | * |
| 127 | * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if |
| 128 | * supported). It _should_, if possible, copy global data to RAM and |
| 129 | * initialise the CPU caches (to speed up the relocation process) |
| 130 | */ |
| 131 | init_fnc_t *init_sequence_f_r[] = { |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 132 | init_cache_f_r, |
| 133 | copy_uboot_to_ram, |
| 134 | clear_bss, |
| 135 | do_elf_reloc_fixups, |
| 136 | |
| 137 | NULL, |
| 138 | }; |
| 139 | |
| 140 | /* |
| 141 | * init_sequence_r is the list of init functions which are run when U-Boot |
| 142 | * is executing from RAM with a full 'C' environment. There are no longer |
| 143 | * any limitations which must be considered when implementing an '_r' |
| 144 | * function, (i.e.'static' variables are read/write) |
| 145 | * |
| 146 | * If not already done, the '_r' sequence must copy global data to RAM and |
| 147 | * (should) initialise the CPU caches. |
| 148 | */ |
Graeme Russ | e4f78d7 | 2011-02-12 15:12:10 +1100 | [diff] [blame] | 149 | init_fnc_t *init_sequence_r[] = { |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 150 | set_reloc_flag_r, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 151 | init_bd_struct_r, |
| 152 | mem_malloc_init_r, |
| 153 | cpu_init_r, |
| 154 | board_early_init_r, |
| 155 | dram_init, |
| 156 | interrupt_init, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | timer_init, |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 158 | display_banner, |
| 159 | display_dram_config, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 160 | serial_initialize_r, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 161 | #ifndef CONFIG_SYS_NO_FLASH |
| 162 | flash_init_r, |
| 163 | #endif |
Gabe Black | 8313315 | 2012-11-03 11:41:23 +0000 | [diff] [blame] | 164 | #ifdef CONFIG_SPI |
| 165 | init_func_spi; |
| 166 | #endif |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 167 | env_relocate_r, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 168 | #ifdef CONFIG_PCI |
| 169 | pci_init_r, |
| 170 | #endif |
| 171 | stdio_init, |
| 172 | jumptable_init_r, |
| 173 | console_init_r, |
| 174 | #ifdef CONFIG_MISC_INIT_R |
| 175 | misc_init_r, |
| 176 | #endif |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 177 | #if defined(CONFIG_CMD_KGDB) |
| 178 | kgdb_init_r, |
| 179 | #endif |
| 180 | enable_interrupts_r, |
| 181 | #ifdef CONFIG_STATUS_LED |
| 182 | status_led_set_r, |
| 183 | #endif |
| 184 | set_load_addr_r, |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 185 | #if defined(CONFIG_CMD_IDE) |
| 186 | ide_init_r, |
| 187 | #endif |
| 188 | #if defined(CONFIG_CMD_SCSI) |
| 189 | scsi_init_r, |
| 190 | #endif |
| 191 | #if defined(CONFIG_CMD_DOC) |
| 192 | doc_init_r, |
| 193 | #endif |
| 194 | #ifdef CONFIG_BITBANGMII |
| 195 | bb_miiphy_init_r, |
| 196 | #endif |
| 197 | #if defined(CONFIG_CMD_NET) |
| 198 | eth_initialize_r, |
| 199 | #ifdef CONFIG_RESET_PHY_R |
| 200 | reset_phy_r, |
| 201 | #endif |
| 202 | #endif |
| 203 | #ifdef CONFIG_LAST_STAGE_INIT |
| 204 | last_stage_init, |
| 205 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 206 | NULL, |
| 207 | }; |
| 208 | |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 209 | static void do_init_loop(init_fnc_t **init_fnc_ptr) |
| 210 | { |
| 211 | for (; *init_fnc_ptr; ++init_fnc_ptr) { |
| 212 | WATCHDOG_RESET(); |
| 213 | if ((*init_fnc_ptr)() != 0) |
| 214 | hang(); |
| 215 | } |
| 216 | } |
| 217 | |
Graeme Russ | 96cd664 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 218 | void board_init_f(ulong boot_flags) |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 219 | { |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 220 | gd->flags = boot_flags; |
| 221 | |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 222 | do_init_loop(init_sequence_f); |
Graeme Russ | f2ff75c | 2010-10-07 20:03:33 +1100 | [diff] [blame] | 223 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 224 | /* |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 225 | * SDRAM and console are now initialised. The final stack can now |
| 226 | * be setup in SDRAM. Code execution will continue in Flash, but |
| 227 | * with the stack in SDRAM and Global Data in temporary memory |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 228 | * (CPU cache) |
| 229 | */ |
| 230 | board_init_f_r_trampoline(gd->start_addr_sp); |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 231 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 232 | /* NOTREACHED - board_init_f_r_trampoline() does not return */ |
| 233 | while (1) |
| 234 | ; |
| 235 | } |
| 236 | |
| 237 | void board_init_f_r(void) |
| 238 | { |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 239 | do_init_loop(init_sequence_f_r); |
Graeme Russ | 98f1fa9 | 2011-12-27 22:46:42 +1100 | [diff] [blame] | 240 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 241 | /* |
| 242 | * U-Boot has been copied into SDRAM, the BSS has been cleared etc. |
| 243 | * Transfer execution from Flash to RAM by calculating the address |
| 244 | * of the in-RAM copy of board_init_r() and calling it |
| 245 | */ |
| 246 | (board_init_r + gd->reloc_off)(gd, gd->relocaddr); |
Graeme Russ | 98f1fa9 | 2011-12-27 22:46:42 +1100 | [diff] [blame] | 247 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 248 | /* NOTREACHED - board_init_r() does not return */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 249 | while (1) |
| 250 | ; |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 251 | } |
| 252 | |
Graeme Russ | 2fb1bc4 | 2010-04-24 00:05:44 +1000 | [diff] [blame] | 253 | void board_init_r(gd_t *id, ulong dest_addr) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 254 | { |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 255 | do_init_loop(init_sequence_r); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 256 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 257 | /* 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] | 258 | for (;;) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 259 | main_loop(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 260 | |
| 261 | /* NOTREACHED - no way out of command loop except booting */ |
| 262 | } |
| 263 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 264 | void hang(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 265 | { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 266 | puts("### ERROR ### Please RESET the board ###\n"); |
| 267 | for (;;) |
| 268 | ; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 269 | } |