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