Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * (C) Copyright 2002-2006 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Marius Groeger <mgroeger@sysgo.de> |
| 9 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <linux/compiler.h> |
| 15 | #include <version.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 16 | #include <console.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 17 | #include <environment.h> |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 18 | #include <dm.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 19 | #include <fdtdec.h> |
Simon Glass | f828bf2 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 20 | #include <fs.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 21 | #if defined(CONFIG_CMD_IDE) |
| 22 | #include <ide.h> |
| 23 | #endif |
| 24 | #include <i2c.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 25 | #include <initcall.h> |
| 26 | #include <logbuff.h> |
Simon Glass | fb5cf7f | 2015-02-27 22:06:36 -0700 | [diff] [blame] | 27 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 28 | #include <mapmem.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 29 | |
| 30 | /* TODO: Can we move these into arch/ headers? */ |
| 31 | #ifdef CONFIG_8xx |
| 32 | #include <mpc8xx.h> |
| 33 | #endif |
| 34 | #ifdef CONFIG_5xx |
| 35 | #include <mpc5xx.h> |
| 36 | #endif |
| 37 | #ifdef CONFIG_MPC5xxx |
| 38 | #include <mpc5xxx.h> |
| 39 | #endif |
Gabriel Huau | ec3b482 | 2014-09-03 13:57:54 -0700 | [diff] [blame] | 40 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) |
Gabriel Huau | a76df70 | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 41 | #include <asm/mp.h> |
| 42 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 43 | |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 44 | #include <os.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 45 | #include <post.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 46 | #include <spi.h> |
Jeroen Hofstee | c5d4001 | 2014-06-23 23:20:19 +0200 | [diff] [blame] | 47 | #include <status_led.h> |
Simon Glass | 1057e6c | 2016-02-24 09:14:50 -0700 | [diff] [blame] | 48 | #include <timer.h> |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 49 | #include <trace.h> |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 50 | #include <video.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 51 | #include <watchdog.h> |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 52 | #include <asm/errno.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 53 | #include <asm/io.h> |
| 54 | #include <asm/sections.h> |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 55 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 56 | #include <asm/init_helpers.h> |
| 57 | #include <asm/relocate.h> |
| 58 | #endif |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_SANDBOX |
| 60 | #include <asm/state.h> |
| 61 | #endif |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 62 | #include <dm/root.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 63 | #include <linux/compiler.h> |
| 64 | |
| 65 | /* |
| 66 | * Pointer to initial global data area |
| 67 | * |
| 68 | * Here we initialize it if needed. |
| 69 | */ |
| 70 | #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR |
| 71 | #undef XTRN_DECLARE_GLOBAL_DATA_PTR |
| 72 | #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ |
| 73 | DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); |
| 74 | #else |
| 75 | DECLARE_GLOBAL_DATA_PTR; |
| 76 | #endif |
| 77 | |
| 78 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 79 | * TODO(sjg@chromium.org): IMO this code should be |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 80 | * refactored to a single function, something like: |
| 81 | * |
| 82 | * void led_set_state(enum led_colour_t colour, int on); |
| 83 | */ |
| 84 | /************************************************************************ |
| 85 | * Coloured LED functionality |
| 86 | ************************************************************************ |
| 87 | * May be supplied by boards if desired |
| 88 | */ |
Jeroen Hofstee | c5d4001 | 2014-06-23 23:20:19 +0200 | [diff] [blame] | 89 | __weak void coloured_LED_init(void) {} |
| 90 | __weak void red_led_on(void) {} |
| 91 | __weak void red_led_off(void) {} |
| 92 | __weak void green_led_on(void) {} |
| 93 | __weak void green_led_off(void) {} |
| 94 | __weak void yellow_led_on(void) {} |
| 95 | __weak void yellow_led_off(void) {} |
| 96 | __weak void blue_led_on(void) {} |
| 97 | __weak void blue_led_off(void) {} |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Why is gd allocated a register? Prior to reloc it might be better to |
| 101 | * just pass it around to each function in this file? |
| 102 | * |
| 103 | * After reloc one could argue that it is hardly used and doesn't need |
| 104 | * to be in a register. Or if it is it should perhaps hold pointers to all |
| 105 | * global data for all modules, so that post-reloc we can avoid the massive |
| 106 | * literal pool we get on ARM. Or perhaps just encourage each module to use |
| 107 | * a structure... |
| 108 | */ |
| 109 | |
| 110 | /* |
| 111 | * Could the CONFIG_SPL_BUILD infection become a flag in gd? |
| 112 | */ |
| 113 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 114 | #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 115 | static int init_func_watchdog_init(void) |
| 116 | { |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 117 | # if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \ |
| 118 | defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ |
Stefan Roese | 14a380a | 2015-03-10 08:04:36 +0100 | [diff] [blame] | 119 | defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \ |
| 120 | defined(CONFIG_IMX_WATCHDOG)) |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 121 | hw_watchdog_init(); |
| 122 | # endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 123 | puts(" Watchdog enabled\n"); |
| 124 | WATCHDOG_RESET(); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int init_func_watchdog_reset(void) |
| 130 | { |
| 131 | WATCHDOG_RESET(); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | #endif /* CONFIG_WATCHDOG */ |
| 136 | |
Jeroen Hofstee | dd2a6cd | 2014-10-08 22:57:22 +0200 | [diff] [blame] | 137 | __weak void board_add_ram_info(int use_default) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 138 | { |
| 139 | /* please define platform specific board_add_ram_info() */ |
| 140 | } |
| 141 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 142 | static int init_baud_rate(void) |
| 143 | { |
| 144 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static int display_text_info(void) |
| 149 | { |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 150 | #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP) |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 151 | ulong bss_start, bss_end, text_base; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 152 | |
Simon Glass | 632efa7 | 2013-03-11 07:06:48 +0000 | [diff] [blame] | 153 | bss_start = (ulong)&__bss_start; |
| 154 | bss_end = (ulong)&__bss_end; |
Albert ARIBAUD | b60eff3 | 2014-02-22 17:53:43 +0100 | [diff] [blame] | 155 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 156 | #ifdef CONFIG_SYS_TEXT_BASE |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 157 | text_base = CONFIG_SYS_TEXT_BASE; |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 158 | #else |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 159 | text_base = CONFIG_SYS_MONITOR_BASE; |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 160 | #endif |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 161 | |
| 162 | debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", |
| 163 | text_base, bss_start, bss_end); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 164 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 165 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 166 | #ifdef CONFIG_USE_IRQ |
| 167 | debug("IRQ Stack: %08lx\n", IRQ_STACK_START); |
| 168 | debug("FIQ Stack: %08lx\n", FIQ_STACK_START); |
| 169 | #endif |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int announce_dram_init(void) |
| 175 | { |
| 176 | puts("DRAM: "); |
| 177 | return 0; |
| 178 | } |
| 179 | |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 180 | #if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 181 | static int init_func_ram(void) |
| 182 | { |
| 183 | #ifdef CONFIG_BOARD_TYPES |
| 184 | int board_type = gd->board_type; |
| 185 | #else |
| 186 | int board_type = 0; /* use dummy arg */ |
| 187 | #endif |
| 188 | |
| 189 | gd->ram_size = initdram(board_type); |
| 190 | |
| 191 | if (gd->ram_size > 0) |
| 192 | return 0; |
| 193 | |
| 194 | puts("*** failed ***\n"); |
| 195 | return 1; |
| 196 | } |
| 197 | #endif |
| 198 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 199 | static int show_dram_config(void) |
| 200 | { |
York Sun | fa39ffe | 2014-05-02 17:28:05 -0700 | [diff] [blame] | 201 | unsigned long long size; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 202 | |
| 203 | #ifdef CONFIG_NR_DRAM_BANKS |
| 204 | int i; |
| 205 | |
| 206 | debug("\nRAM Configuration:\n"); |
| 207 | for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 208 | size += gd->bd->bi_dram[i].size; |
Bin Meng | 715f599 | 2015-08-06 01:31:20 -0700 | [diff] [blame] | 209 | debug("Bank #%d: %llx ", i, |
| 210 | (unsigned long long)(gd->bd->bi_dram[i].start)); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 211 | #ifdef DEBUG |
| 212 | print_size(gd->bd->bi_dram[i].size, "\n"); |
| 213 | #endif |
| 214 | } |
| 215 | debug("\nDRAM: "); |
| 216 | #else |
| 217 | size = gd->ram_size; |
| 218 | #endif |
| 219 | |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 220 | print_size(size, ""); |
| 221 | board_add_ram_info(0); |
| 222 | putc('\n'); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
Jeroen Hofstee | dd2a6cd | 2014-10-08 22:57:22 +0200 | [diff] [blame] | 227 | __weak void dram_init_banksize(void) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 228 | { |
| 229 | #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) |
| 230 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 231 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
| 232 | #endif |
| 233 | } |
| 234 | |
Heiko Schocher | ea818db | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 235 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 236 | static int init_func_i2c(void) |
| 237 | { |
| 238 | puts("I2C: "); |
trem | 815a76f | 2013-09-21 18:13:34 +0200 | [diff] [blame] | 239 | #ifdef CONFIG_SYS_I2C |
| 240 | i2c_init_all(); |
| 241 | #else |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 242 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
trem | 815a76f | 2013-09-21 18:13:34 +0200 | [diff] [blame] | 243 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 244 | puts("ready\n"); |
| 245 | return 0; |
| 246 | } |
| 247 | #endif |
| 248 | |
| 249 | #if defined(CONFIG_HARD_SPI) |
| 250 | static int init_func_spi(void) |
| 251 | { |
| 252 | puts("SPI: "); |
| 253 | spi_init(); |
| 254 | puts("ready\n"); |
| 255 | return 0; |
| 256 | } |
| 257 | #endif |
| 258 | |
| 259 | __maybe_unused |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 260 | static int zero_global_data(void) |
| 261 | { |
| 262 | memset((void *)gd, '\0', sizeof(gd_t)); |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int setup_mon_len(void) |
| 268 | { |
Michal Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 269 | #if defined(__ARM__) || defined(__MICROBLAZE__) |
Albert ARIBAUD | b60eff3 | 2014-02-22 17:53:43 +0100 | [diff] [blame] | 270 | gd->mon_len = (ulong)&__bss_end - (ulong)_start; |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 271 | #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 272 | gd->mon_len = (ulong)&_end - (ulong)_init; |
Thomas Chou | 5ff10aa | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 273 | #elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2) |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 274 | gd->mon_len = CONFIG_SYS_MONITOR_LEN; |
Kun-Hua Huang | 2e88bb2 | 2015-08-24 14:52:35 +0800 | [diff] [blame] | 275 | #elif defined(CONFIG_NDS32) |
| 276 | gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start); |
Simon Glass | b0b3595 | 2016-05-14 18:49:28 -0600 | [diff] [blame] | 277 | #elif defined(CONFIG_SYS_MONITOR_BASE) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 278 | /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ |
| 279 | gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; |
Simon Glass | 632efa7 | 2013-03-11 07:06:48 +0000 | [diff] [blame] | 280 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | __weak int arch_cpu_init(void) |
| 285 | { |
| 286 | return 0; |
| 287 | } |
| 288 | |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 289 | #ifdef CONFIG_SANDBOX |
| 290 | static int setup_ram_buf(void) |
| 291 | { |
Simon Glass | 5c2859c | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 292 | struct sandbox_state *state = state_get_current(); |
| 293 | |
| 294 | gd->arch.ram_buf = state->ram_buf; |
| 295 | gd->ram_size = state->ram_size; |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | #endif |
| 300 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 301 | /* Get the top of usable RAM */ |
| 302 | __weak ulong board_get_usable_ram_top(ulong total_size) |
| 303 | { |
Stephen Warren | 1e4d11a | 2014-12-23 10:34:49 -0700 | [diff] [blame] | 304 | #ifdef CONFIG_SYS_SDRAM_BASE |
| 305 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 306 | * Detect whether we have so much RAM that it goes past the end of our |
Stephen Warren | 1e4d11a | 2014-12-23 10:34:49 -0700 | [diff] [blame] | 307 | * 32-bit address space. If so, clip the usable RAM so it doesn't. |
| 308 | */ |
| 309 | if (gd->ram_top < CONFIG_SYS_SDRAM_BASE) |
| 310 | /* |
| 311 | * Will wrap back to top of 32-bit space when reservations |
| 312 | * are made. |
| 313 | */ |
| 314 | return 0; |
| 315 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 316 | return gd->ram_top; |
| 317 | } |
| 318 | |
York Sun | aabd7dd | 2015-12-07 11:05:29 -0800 | [diff] [blame] | 319 | __weak phys_size_t board_reserve_ram_top(phys_size_t ram_size) |
| 320 | { |
| 321 | #ifdef CONFIG_SYS_MEM_TOP_HIDE |
| 322 | return ram_size - CONFIG_SYS_MEM_TOP_HIDE; |
| 323 | #else |
| 324 | return ram_size; |
| 325 | #endif |
| 326 | } |
| 327 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 328 | static int setup_dest_addr(void) |
| 329 | { |
| 330 | debug("Monitor len: %08lX\n", gd->mon_len); |
| 331 | /* |
| 332 | * Ram is setup, size stored in gd !! |
| 333 | */ |
| 334 | debug("Ram size: %08lX\n", (ulong)gd->ram_size); |
York Sun | e814952 | 2015-12-04 11:57:07 -0800 | [diff] [blame] | 335 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 336 | /* Reserve memory for secure MMU tables, and/or security monitor */ |
| 337 | gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE; |
| 338 | /* |
| 339 | * Record secure memory location. Need recalcuate if memory splits |
| 340 | * into banks, or the ram base is not zero. |
| 341 | */ |
York Sun | e61a753 | 2016-06-24 16:46:18 -0700 | [diff] [blame] | 342 | gd->arch.secure_ram = gd->ram_size; |
York Sun | e814952 | 2015-12-04 11:57:07 -0800 | [diff] [blame] | 343 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 344 | /* |
| 345 | * Subtract specified amount of memory to hide so that it won't |
| 346 | * get "touched" at all by U-Boot. By fixing up gd->ram_size |
| 347 | * the Linux kernel should now get passed the now "corrected" |
York Sun | aabd7dd | 2015-12-07 11:05:29 -0800 | [diff] [blame] | 348 | * memory size and won't touch it either. This has been used |
| 349 | * by arch/powerpc exclusively. Now ARMv8 takes advantage of |
| 350 | * thie mechanism. If memory is split into banks, addresses |
| 351 | * need to be calculated. |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 352 | */ |
York Sun | aabd7dd | 2015-12-07 11:05:29 -0800 | [diff] [blame] | 353 | gd->ram_size = board_reserve_ram_top(gd->ram_size); |
| 354 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 355 | #ifdef CONFIG_SYS_SDRAM_BASE |
| 356 | gd->ram_top = CONFIG_SYS_SDRAM_BASE; |
| 357 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 358 | gd->ram_top += get_effective_memsize(); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 359 | gd->ram_top = board_get_usable_ram_top(gd->mon_len); |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 360 | gd->relocaddr = gd->ram_top; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 361 | debug("Ram top: %08lX\n", (ulong)gd->ram_top); |
Gabriel Huau | ec3b482 | 2014-09-03 13:57:54 -0700 | [diff] [blame] | 362 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 363 | /* |
| 364 | * We need to make sure the location we intend to put secondary core |
| 365 | * boot code is reserved and not used by any part of u-boot |
| 366 | */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 367 | if (gd->relocaddr > determine_mp_bootpg(NULL)) { |
| 368 | gd->relocaddr = determine_mp_bootpg(NULL); |
| 369 | debug("Reserving MP boot page to %08lx\n", gd->relocaddr); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 370 | } |
| 371 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Francois Retief | 1e85cce | 2015-11-23 13:05:44 +0200 | [diff] [blame] | 375 | #if defined(CONFIG_SPARC) |
| 376 | static int reserve_prom(void) |
| 377 | { |
| 378 | /* defined in arch/sparc/cpu/leon?/prom.c */ |
| 379 | extern void *__prom_start_reloc; |
| 380 | int size = 8192; /* page table = 2k, prom = 6k */ |
| 381 | gd->relocaddr -= size; |
| 382 | __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048); |
| 383 | debug("Reserving %dk for PROM and page table at %08lx\n", size, |
| 384 | gd->relocaddr); |
| 385 | return 0; |
| 386 | } |
| 387 | #endif |
| 388 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 389 | #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) |
| 390 | static int reserve_logbuffer(void) |
| 391 | { |
| 392 | /* reserve kernel log buffer */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 393 | gd->relocaddr -= LOGBUFF_RESERVE; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 394 | debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 395 | gd->relocaddr); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | #endif |
| 399 | |
| 400 | #ifdef CONFIG_PRAM |
| 401 | /* reserve protected RAM */ |
| 402 | static int reserve_pram(void) |
| 403 | { |
| 404 | ulong reg; |
| 405 | |
| 406 | reg = getenv_ulong("pram", 10, CONFIG_PRAM); |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 407 | gd->relocaddr -= (reg << 10); /* size is in kB */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 408 | debug("Reserving %ldk for protected RAM at %08lx\n", reg, |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 409 | gd->relocaddr); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | #endif /* CONFIG_PRAM */ |
| 413 | |
| 414 | /* Round memory pointer down to next 4 kB limit */ |
| 415 | static int reserve_round_4k(void) |
| 416 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 417 | gd->relocaddr &= ~(4096 - 1); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ |
| 422 | defined(CONFIG_ARM) |
| 423 | static int reserve_mmu(void) |
| 424 | { |
| 425 | /* reserve TLB table */ |
David Feng | cce6be7 | 2013-12-14 11:47:36 +0800 | [diff] [blame] | 426 | gd->arch.tlb_size = PGTABLE_SIZE; |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 427 | gd->relocaddr -= gd->arch.tlb_size; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 428 | |
| 429 | /* round down to next 64 kB limit */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 430 | gd->relocaddr &= ~(0x10000 - 1); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 431 | |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 432 | gd->arch.tlb_addr = gd->relocaddr; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 433 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 434 | gd->arch.tlb_addr + gd->arch.tlb_size); |
York Sun | 50e93b9 | 2016-06-24 16:46:19 -0700 | [diff] [blame] | 435 | |
| 436 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 437 | /* |
| 438 | * Record allocated tlb_addr in case gd->tlb_addr to be overwritten |
| 439 | * with location within secure ram. |
| 440 | */ |
| 441 | gd->arch.tlb_allocated = gd->arch.tlb_addr; |
| 442 | #endif |
| 443 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | #endif |
| 447 | |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 448 | #ifdef CONFIG_DM_VIDEO |
| 449 | static int reserve_video(void) |
| 450 | { |
| 451 | ulong addr; |
| 452 | int ret; |
| 453 | |
| 454 | addr = gd->relocaddr; |
| 455 | ret = video_reserve(&addr); |
| 456 | if (ret) |
| 457 | return ret; |
| 458 | gd->relocaddr = addr; |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | #else |
| 463 | |
| 464 | # ifdef CONFIG_LCD |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 465 | static int reserve_lcd(void) |
| 466 | { |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 467 | # ifdef CONFIG_FB_ADDR |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 468 | gd->fb_base = CONFIG_FB_ADDR; |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 469 | # else |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 470 | /* reserve memory for LCD display (always full pages) */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 471 | gd->relocaddr = lcd_setmem(gd->relocaddr); |
| 472 | gd->fb_base = gd->relocaddr; |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 473 | # endif /* CONFIG_FB_ADDR */ |
| 474 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 475 | return 0; |
| 476 | } |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 477 | # endif /* CONFIG_LCD */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 478 | |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 479 | # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 480 | !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ |
| 481 | !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) |
| 482 | static int reserve_legacy_video(void) |
| 483 | { |
| 484 | /* reserve memory for video display (always full pages) */ |
| 485 | gd->relocaddr = video_setmem(gd->relocaddr); |
| 486 | gd->fb_base = gd->relocaddr; |
| 487 | |
| 488 | return 0; |
| 489 | } |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 490 | # endif |
| 491 | #endif /* !CONFIG_DM_VIDEO */ |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 492 | |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 493 | static int reserve_trace(void) |
| 494 | { |
| 495 | #ifdef CONFIG_TRACE |
| 496 | gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE; |
| 497 | gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE); |
| 498 | debug("Reserving %dk for trace data at: %08lx\n", |
| 499 | CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr); |
| 500 | #endif |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 505 | static int reserve_uboot(void) |
| 506 | { |
| 507 | /* |
| 508 | * reserve memory for U-Boot code, data & bss |
| 509 | * round down to next 4 kB limit |
| 510 | */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 511 | gd->relocaddr -= gd->mon_len; |
| 512 | gd->relocaddr &= ~(4096 - 1); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 513 | #ifdef CONFIG_E500 |
| 514 | /* round down to next 64 kB limit so that IVPR stays aligned */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 515 | gd->relocaddr &= ~(65536 - 1); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 516 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 517 | |
| 518 | debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 519 | gd->relocaddr); |
| 520 | |
| 521 | gd->start_addr_sp = gd->relocaddr; |
| 522 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 523 | return 0; |
| 524 | } |
| 525 | |
Simon Glass | 8cae8a6 | 2013-03-05 14:39:45 +0000 | [diff] [blame] | 526 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 527 | /* reserve memory for malloc() area */ |
| 528 | static int reserve_malloc(void) |
| 529 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 530 | gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 531 | debug("Reserving %dk for malloc() at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 532 | TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* (permanently) allocate a Board Info struct */ |
| 537 | static int reserve_board(void) |
| 538 | { |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 539 | if (!gd->bd) { |
| 540 | gd->start_addr_sp -= sizeof(bd_t); |
| 541 | gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t)); |
| 542 | memset(gd->bd, '\0', sizeof(bd_t)); |
| 543 | debug("Reserving %zu Bytes for Board Info at: %08lx\n", |
| 544 | sizeof(bd_t), gd->start_addr_sp); |
| 545 | } |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 546 | return 0; |
| 547 | } |
Simon Glass | 8cae8a6 | 2013-03-05 14:39:45 +0000 | [diff] [blame] | 548 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 549 | |
| 550 | static int setup_machine(void) |
| 551 | { |
| 552 | #ifdef CONFIG_MACH_TYPE |
| 553 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ |
| 554 | #endif |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | static int reserve_global_data(void) |
| 559 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 560 | gd->start_addr_sp -= sizeof(gd_t); |
| 561 | gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t)); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 562 | debug("Reserving %zu Bytes for Global Data at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 563 | sizeof(gd_t), gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static int reserve_fdt(void) |
| 568 | { |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 569 | #ifndef CONFIG_OF_EMBED |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 570 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 571 | * If the device tree is sitting immediately above our image then we |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 572 | * must relocate it. If it is embedded in the data section, then it |
| 573 | * will be relocated with other data. |
| 574 | */ |
| 575 | if (gd->fdt_blob) { |
| 576 | gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); |
| 577 | |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 578 | gd->start_addr_sp -= gd->fdt_size; |
| 579 | gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 580 | debug("Reserving %lu Bytes for FDT at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 581 | gd->fdt_size, gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 582 | } |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 583 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 584 | |
| 585 | return 0; |
| 586 | } |
| 587 | |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 588 | int arch_reserve_stacks(void) |
| 589 | { |
| 590 | return 0; |
| 591 | } |
| 592 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 593 | static int reserve_stacks(void) |
| 594 | { |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 595 | /* make stack pointer 16-byte aligned */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 596 | gd->start_addr_sp -= 16; |
| 597 | gd->start_addr_sp &= ~0xf; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 598 | |
| 599 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 600 | * let the architecture-specific code tailor gd->start_addr_sp and |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 601 | * gd->irq_sp |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 602 | */ |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 603 | return arch_reserve_stacks(); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | static int display_new_sp(void) |
| 607 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 608 | debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 613 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 614 | static int setup_board_part1(void) |
| 615 | { |
| 616 | bd_t *bd = gd->bd; |
| 617 | |
| 618 | /* |
| 619 | * Save local variables to board info struct |
| 620 | */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 621 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */ |
| 622 | bd->bi_memsize = gd->ram_size; /* size in bytes */ |
| 623 | |
| 624 | #ifdef CONFIG_SYS_SRAM_BASE |
| 625 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */ |
| 626 | bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ |
| 627 | #endif |
| 628 | |
Masahiro Yamada | 58dac32 | 2014-03-05 17:40:10 +0900 | [diff] [blame] | 629 | #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 630 | defined(CONFIG_E500) || defined(CONFIG_MPC86xx) |
| 631 | bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */ |
| 632 | #endif |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 633 | #if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 634 | bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ |
| 635 | #endif |
| 636 | #if defined(CONFIG_MPC83xx) |
| 637 | bd->bi_immrbar = CONFIG_SYS_IMMR; |
| 638 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 639 | |
| 640 | return 0; |
| 641 | } |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 642 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 643 | |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 644 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 645 | static int setup_board_part2(void) |
| 646 | { |
| 647 | bd_t *bd = gd->bd; |
| 648 | |
| 649 | bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ |
| 650 | bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ |
| 651 | #if defined(CONFIG_CPM2) |
| 652 | bd->bi_cpmfreq = gd->arch.cpm_clk; |
| 653 | bd->bi_brgfreq = gd->arch.brg_clk; |
| 654 | bd->bi_sccfreq = gd->arch.scc_clk; |
| 655 | bd->bi_vco = gd->arch.vco_out; |
| 656 | #endif /* CONFIG_CPM2 */ |
| 657 | #if defined(CONFIG_MPC512X) |
| 658 | bd->bi_ipsfreq = gd->arch.ips_clk; |
| 659 | #endif /* CONFIG_MPC512X */ |
| 660 | #if defined(CONFIG_MPC5xxx) |
| 661 | bd->bi_ipbfreq = gd->arch.ipb_clk; |
| 662 | bd->bi_pcifreq = gd->pci_clk; |
| 663 | #endif /* CONFIG_MPC5xxx */ |
Alison Wang | 1313db4 | 2015-02-12 18:33:15 +0800 | [diff] [blame] | 664 | #if defined(CONFIG_M68K) && defined(CONFIG_PCI) |
| 665 | bd->bi_pcifreq = gd->pci_clk; |
| 666 | #endif |
| 667 | #if defined(CONFIG_EXTRA_CLOCK) |
| 668 | bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */ |
| 669 | bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */ |
| 670 | bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */ |
| 671 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | #ifdef CONFIG_SYS_EXTBDINFO |
| 678 | static int setup_board_extra(void) |
| 679 | { |
| 680 | bd_t *bd = gd->bd; |
| 681 | |
| 682 | strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version)); |
| 683 | strncpy((char *) bd->bi_r_version, U_BOOT_VERSION, |
| 684 | sizeof(bd->bi_r_version)); |
| 685 | |
| 686 | bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */ |
| 687 | bd->bi_plb_busfreq = gd->bus_clk; |
| 688 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ |
| 689 | defined(CONFIG_440EP) || defined(CONFIG_440GR) || \ |
| 690 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) |
| 691 | bd->bi_pci_busfreq = get_PCI_freq(); |
| 692 | bd->bi_opbfreq = get_OPB_freq(); |
| 693 | #elif defined(CONFIG_XILINX_405) |
| 694 | bd->bi_pci_busfreq = get_PCI_freq(); |
| 695 | #endif |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | #endif |
| 700 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 701 | #ifdef CONFIG_POST |
| 702 | static int init_post(void) |
| 703 | { |
| 704 | post_bootmode_init(); |
| 705 | post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | #endif |
| 710 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 711 | static int setup_dram_config(void) |
| 712 | { |
| 713 | /* Ram is board specific, so move it to board code ... */ |
| 714 | dram_init_banksize(); |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | static int reloc_fdt(void) |
| 720 | { |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 721 | #ifndef CONFIG_OF_EMBED |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 722 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 723 | return 0; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 724 | if (gd->new_fdt) { |
| 725 | memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); |
| 726 | gd->fdt_blob = gd->new_fdt; |
| 727 | } |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 728 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int setup_reloc(void) |
| 734 | { |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 735 | if (gd->flags & GD_FLG_SKIP_RELOC) { |
| 736 | debug("Skipping relocation due to flag\n"); |
| 737 | return 0; |
| 738 | } |
| 739 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 740 | #ifdef CONFIG_SYS_TEXT_BASE |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 741 | gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 742 | #ifdef CONFIG_M68K |
| 743 | /* |
| 744 | * On all ColdFire arch cpu, monitor code starts always |
| 745 | * just after the default vector table location, so at 0x400 |
| 746 | */ |
| 747 | gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400); |
| 748 | #endif |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 749 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 750 | memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); |
| 751 | |
| 752 | debug("Relocation Offset is: %08lx\n", gd->reloc_off); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 753 | debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 754 | gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd), |
| 755 | gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /* ARM calls relocate_code from its crt0.S */ |
Simon Glass | 808434c | 2013-11-10 10:26:59 -0700 | [diff] [blame] | 761 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 762 | |
| 763 | static int jump_to_copy(void) |
| 764 | { |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 765 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 766 | return 0; |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 767 | /* |
| 768 | * x86 is special, but in a nice way. It uses a trampoline which |
| 769 | * enables the dcache if possible. |
| 770 | * |
| 771 | * For now, other archs use relocate_code(), which is implemented |
| 772 | * similarly for all archs. When we do generic relocation, hopefully |
| 773 | * we can make all archs enable the dcache prior to relocation. |
| 774 | */ |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 775 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 776 | /* |
| 777 | * SDRAM and console are now initialised. The final stack can now |
| 778 | * be setup in SDRAM. Code execution will continue in Flash, but |
| 779 | * with the stack in SDRAM and Global Data in temporary memory |
| 780 | * (CPU cache) |
| 781 | */ |
Simon Glass | f0c7d9c | 2015-08-10 20:44:32 -0600 | [diff] [blame] | 782 | arch_setup_gd(gd->new_gd); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 783 | board_init_f_r_trampoline(gd->start_addr_sp); |
| 784 | #else |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 785 | relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 786 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | #endif |
| 791 | |
| 792 | /* Record the board_init_f() bootstage (after arch_cpu_init()) */ |
| 793 | static int mark_bootstage(void) |
| 794 | { |
| 795 | bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f"); |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
Simon Glass | 9854a87 | 2015-11-08 23:47:48 -0700 | [diff] [blame] | 800 | static int initf_console_record(void) |
| 801 | { |
| 802 | #if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN) |
| 803 | return console_record_init(); |
| 804 | #else |
| 805 | return 0; |
| 806 | #endif |
| 807 | } |
| 808 | |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 809 | static int initf_dm(void) |
| 810 | { |
| 811 | #if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN) |
| 812 | int ret; |
| 813 | |
| 814 | ret = dm_init_and_scan(true); |
| 815 | if (ret) |
| 816 | return ret; |
| 817 | #endif |
Simon Glass | 1057e6c | 2016-02-24 09:14:50 -0700 | [diff] [blame] | 818 | #ifdef CONFIG_TIMER_EARLY |
| 819 | ret = dm_timer_init(); |
| 820 | if (ret) |
| 821 | return ret; |
| 822 | #endif |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
Simon Glass | 146251f | 2015-01-19 22:16:12 -0700 | [diff] [blame] | 827 | /* Architecture-specific memory reservation */ |
| 828 | __weak int reserve_arch(void) |
| 829 | { |
| 830 | return 0; |
| 831 | } |
| 832 | |
Simon Glass | d4c671c | 2015-03-05 12:25:16 -0700 | [diff] [blame] | 833 | __weak int arch_cpu_init_dm(void) |
| 834 | { |
| 835 | return 0; |
| 836 | } |
| 837 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 838 | static init_fnc_t init_sequence_f[] = { |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 839 | #ifdef CONFIG_SANDBOX |
| 840 | setup_ram_buf, |
| 841 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 842 | setup_mon_len, |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 843 | #ifdef CONFIG_OF_CONTROL |
Simon Glass | 0879361 | 2015-02-27 22:06:35 -0700 | [diff] [blame] | 844 | fdtdec_setup, |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 845 | #endif |
Kevin Hilman | d210718 | 2014-12-09 15:03:58 -0800 | [diff] [blame] | 846 | #ifdef CONFIG_TRACE |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 847 | trace_early_init, |
Kevin Hilman | d210718 | 2014-12-09 15:03:58 -0800 | [diff] [blame] | 848 | #endif |
Simon Glass | 768e0f5 | 2014-11-10 18:00:18 -0700 | [diff] [blame] | 849 | initf_malloc, |
Simon Glass | 9854a87 | 2015-11-08 23:47:48 -0700 | [diff] [blame] | 850 | initf_console_record, |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 851 | #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) |
| 852 | /* TODO: can this go into arch_cpu_init()? */ |
| 853 | probecpu, |
| 854 | #endif |
Bin Meng | a52a068e | 2015-08-20 06:40:18 -0700 | [diff] [blame] | 855 | #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) |
| 856 | x86_fsp_init, |
| 857 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 858 | arch_cpu_init, /* basic arch cpu dependent setup */ |
Simon Glass | 3ea0953 | 2014-09-03 17:36:59 -0600 | [diff] [blame] | 859 | initf_dm, |
Simon Glass | d4c671c | 2015-03-05 12:25:16 -0700 | [diff] [blame] | 860 | arch_cpu_init_dm, |
Thomas Chou | 6752195 | 2015-10-30 15:35:51 +0800 | [diff] [blame] | 861 | mark_bootstage, /* need timer, go after init dm */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 862 | #if defined(CONFIG_BOARD_EARLY_INIT_F) |
| 863 | board_early_init_f, |
| 864 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 865 | /* TODO: can any of this go into arch_cpu_init()? */ |
| 866 | #if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT) |
| 867 | get_clocks, /* get CPU and bus clocks (etc.) */ |
| 868 | #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \ |
| 869 | && !defined(CONFIG_TQM885D) |
| 870 | adjust_sdram_tbs_8xx, |
| 871 | #endif |
| 872 | /* TODO: can we rename this to timer_init()? */ |
| 873 | init_timebase, |
| 874 | #endif |
Bin Meng | 2317cf0 | 2015-12-08 17:31:40 -0800 | [diff] [blame] | 875 | #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \ |
Francois Retief | c97088c | 2015-10-28 15:18:22 +0200 | [diff] [blame] | 876 | defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \ |
| 877 | defined(CONFIG_SPARC) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 878 | timer_init, /* initialize timer */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 879 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 880 | #ifdef CONFIG_SYS_ALLOC_DPRAM |
| 881 | #if !defined(CONFIG_CPM2) |
| 882 | dpram_init, |
| 883 | #endif |
| 884 | #endif |
| 885 | #if defined(CONFIG_BOARD_POSTCLK_INIT) |
| 886 | board_postclk_init, |
| 887 | #endif |
Peng Fan | 7664846 | 2015-10-30 17:30:02 +0800 | [diff] [blame] | 888 | #if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 889 | get_clocks, |
| 890 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 891 | env_init, /* initialize environment */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 892 | #if defined(CONFIG_8xx_CPUCLK_DEFAULT) |
| 893 | /* get CPU and bus clocks according to the environment variable */ |
| 894 | get_clocks_866, |
| 895 | /* adjust sdram refresh rate according to the new clock */ |
| 896 | sdram_adjust_866, |
| 897 | init_timebase, |
| 898 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 899 | init_baud_rate, /* initialze baudrate settings */ |
| 900 | serial_init, /* serial communications setup */ |
| 901 | console_init_f, /* stage 1 init of console */ |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 902 | #ifdef CONFIG_SANDBOX |
| 903 | sandbox_early_getopt_check, |
| 904 | #endif |
| 905 | #ifdef CONFIG_OF_CONTROL |
| 906 | fdtdec_prepare_fdt, |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 907 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 908 | display_options, /* say that we are here */ |
| 909 | display_text_info, /* show debugging info if required */ |
Masahiro Yamada | 58dac32 | 2014-03-05 17:40:10 +0900 | [diff] [blame] | 910 | #if defined(CONFIG_MPC8260) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 911 | prt_8260_rsr, |
| 912 | prt_8260_clks, |
Masahiro Yamada | 58dac32 | 2014-03-05 17:40:10 +0900 | [diff] [blame] | 913 | #endif /* CONFIG_MPC8260 */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 914 | #if defined(CONFIG_MPC83xx) |
| 915 | prt_83xx_rsr, |
| 916 | #endif |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 917 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 918 | checkcpu, |
| 919 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 920 | print_cpuinfo, /* display cpu info (and speed) */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 921 | #if defined(CONFIG_MPC5xxx) |
| 922 | prt_mpc5xxx_clks, |
| 923 | #endif /* CONFIG_MPC5xxx */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 924 | #if defined(CONFIG_DISPLAY_BOARDINFO) |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 925 | show_board_info, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 926 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 927 | INIT_FUNC_WATCHDOG_INIT |
| 928 | #if defined(CONFIG_MISC_INIT_F) |
| 929 | misc_init_f, |
| 930 | #endif |
| 931 | INIT_FUNC_WATCHDOG_RESET |
Heiko Schocher | ea818db | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 932 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 933 | init_func_i2c, |
| 934 | #endif |
| 935 | #if defined(CONFIG_HARD_SPI) |
| 936 | init_func_spi, |
| 937 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 938 | announce_dram_init, |
| 939 | /* TODO: unify all these dram functions? */ |
Kun-Hua Huang | 2e88bb2 | 2015-08-24 14:52:35 +0800 | [diff] [blame] | 940 | #if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \ |
| 941 | defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 942 | dram_init, /* configure available RAM banks */ |
| 943 | #endif |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 944 | #if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 945 | init_func_ram, |
| 946 | #endif |
| 947 | #ifdef CONFIG_POST |
| 948 | post_init_f, |
| 949 | #endif |
| 950 | INIT_FUNC_WATCHDOG_RESET |
| 951 | #if defined(CONFIG_SYS_DRAM_TEST) |
| 952 | testdram, |
| 953 | #endif /* CONFIG_SYS_DRAM_TEST */ |
| 954 | INIT_FUNC_WATCHDOG_RESET |
| 955 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 956 | #ifdef CONFIG_POST |
| 957 | init_post, |
| 958 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 959 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 960 | /* |
| 961 | * Now that we have DRAM mapped and working, we can |
| 962 | * relocate the code and continue running from DRAM. |
| 963 | * |
| 964 | * Reserve memory at end of RAM for (top down in that order): |
| 965 | * - area that won't get touched by U-Boot and Linux (optional) |
| 966 | * - kernel log buffer |
| 967 | * - protected RAM |
| 968 | * - LCD framebuffer |
| 969 | * - monitor code |
| 970 | * - board info struct |
| 971 | */ |
| 972 | setup_dest_addr, |
Thomas Chou | bbfdff3 | 2015-10-27 11:23:39 +0800 | [diff] [blame] | 973 | #if defined(CONFIG_BLACKFIN) |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 974 | /* Blackfin u-boot monitor should be on top of the ram */ |
| 975 | reserve_uboot, |
| 976 | #endif |
Francois Retief | 1e85cce | 2015-11-23 13:05:44 +0200 | [diff] [blame] | 977 | #if defined(CONFIG_SPARC) |
| 978 | reserve_prom, |
| 979 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 980 | #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) |
| 981 | reserve_logbuffer, |
| 982 | #endif |
| 983 | #ifdef CONFIG_PRAM |
| 984 | reserve_pram, |
| 985 | #endif |
| 986 | reserve_round_4k, |
| 987 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ |
| 988 | defined(CONFIG_ARM) |
| 989 | reserve_mmu, |
| 990 | #endif |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 991 | #ifdef CONFIG_DM_VIDEO |
| 992 | reserve_video, |
| 993 | #else |
| 994 | # ifdef CONFIG_LCD |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 995 | reserve_lcd, |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 996 | # endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 997 | /* TODO: Why the dependency on CONFIG_8xx? */ |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 998 | # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 999 | !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ |
angelo@sysam.it | 944ab34 | 2015-03-28 11:34:52 +0100 | [diff] [blame] | 1000 | !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 1001 | reserve_legacy_video, |
| 1002 | # endif |
| 1003 | #endif /* CONFIG_DM_VIDEO */ |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 1004 | reserve_trace, |
Thomas Chou | bbfdff3 | 2015-10-27 11:23:39 +0800 | [diff] [blame] | 1005 | #if !defined(CONFIG_BLACKFIN) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1006 | reserve_uboot, |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 1007 | #endif |
Simon Glass | 8cae8a6 | 2013-03-05 14:39:45 +0000 | [diff] [blame] | 1008 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1009 | reserve_malloc, |
| 1010 | reserve_board, |
Simon Glass | 8cae8a6 | 2013-03-05 14:39:45 +0000 | [diff] [blame] | 1011 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1012 | setup_machine, |
| 1013 | reserve_global_data, |
| 1014 | reserve_fdt, |
Simon Glass | 146251f | 2015-01-19 22:16:12 -0700 | [diff] [blame] | 1015 | reserve_arch, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1016 | reserve_stacks, |
| 1017 | setup_dram_config, |
| 1018 | show_dram_config, |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 1019 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 1020 | setup_board_part1, |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 1021 | #endif |
| 1022 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 1023 | INIT_FUNC_WATCHDOG_RESET |
| 1024 | setup_board_part2, |
| 1025 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1026 | display_new_sp, |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 1027 | #ifdef CONFIG_SYS_EXTBDINFO |
| 1028 | setup_board_extra, |
| 1029 | #endif |
| 1030 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1031 | reloc_fdt, |
| 1032 | setup_reloc, |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 1033 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 313aef3 | 2015-01-01 16:18:09 -0700 | [diff] [blame] | 1034 | copy_uboot_to_ram, |
| 1035 | clear_bss, |
| 1036 | do_elf_reloc_fixups, |
| 1037 | #endif |
Simon Glass | 808434c | 2013-11-10 10:26:59 -0700 | [diff] [blame] | 1038 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1039 | jump_to_copy, |
| 1040 | #endif |
| 1041 | NULL, |
| 1042 | }; |
| 1043 | |
| 1044 | void board_init_f(ulong boot_flags) |
| 1045 | { |
York Sun | 2a1680e | 2014-05-02 17:28:04 -0700 | [diff] [blame] | 1046 | #ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA |
| 1047 | /* |
| 1048 | * For some archtectures, global data is initialized and used before |
| 1049 | * calling this function. The data should be preserved. For others, |
| 1050 | * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack |
| 1051 | * here to host global data until relocation. |
| 1052 | */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1053 | gd_t data; |
| 1054 | |
| 1055 | gd = &data; |
| 1056 | |
David Feng | cce6be7 | 2013-12-14 11:47:36 +0800 | [diff] [blame] | 1057 | /* |
| 1058 | * Clear global data before it is accessed at debug print |
| 1059 | * in initcall_run_list. Otherwise the debug print probably |
| 1060 | * get the wrong vaule of gd->have_console. |
| 1061 | */ |
David Feng | cce6be7 | 2013-12-14 11:47:36 +0800 | [diff] [blame] | 1062 | zero_global_data(); |
| 1063 | #endif |
| 1064 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1065 | gd->flags = boot_flags; |
Alexey Brodkin | 9aed5a2 | 2013-11-27 22:32:40 +0400 | [diff] [blame] | 1066 | gd->have_console = 0; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1067 | |
| 1068 | if (initcall_run_list(init_sequence_f)) |
| 1069 | hang(); |
| 1070 | |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 1071 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ |
| 1072 | !defined(CONFIG_EFI_APP) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 1073 | /* NOTREACHED - jump_to_copy() does not return */ |
| 1074 | hang(); |
| 1075 | #endif |
| 1076 | } |
| 1077 | |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 1078 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 1079 | /* |
| 1080 | * For now this code is only used on x86. |
| 1081 | * |
| 1082 | * init_sequence_f_r is the list of init functions which are run when |
| 1083 | * U-Boot is executing from Flash with a semi-limited 'C' environment. |
| 1084 | * The following limitations must be considered when implementing an |
| 1085 | * '_f_r' function: |
| 1086 | * - 'static' variables are read-only |
| 1087 | * - Global Data (gd->xxx) is read/write |
| 1088 | * |
| 1089 | * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if |
| 1090 | * supported). It _should_, if possible, copy global data to RAM and |
| 1091 | * initialise the CPU caches (to speed up the relocation process) |
| 1092 | * |
| 1093 | * NOTE: At present only x86 uses this route, but it is intended that |
| 1094 | * all archs will move to this when generic relocation is implemented. |
| 1095 | */ |
| 1096 | static init_fnc_t init_sequence_f_r[] = { |
| 1097 | init_cache_f_r, |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 1098 | |
| 1099 | NULL, |
| 1100 | }; |
| 1101 | |
| 1102 | void board_init_f_r(void) |
| 1103 | { |
| 1104 | if (initcall_run_list(init_sequence_f_r)) |
| 1105 | hang(); |
| 1106 | |
| 1107 | /* |
Simon Glass | e4d6ab0 | 2016-03-11 22:06:51 -0700 | [diff] [blame] | 1108 | * The pre-relocation drivers may be using memory that has now gone |
| 1109 | * away. Mark serial as unavailable - this will fall back to the debug |
| 1110 | * UART if available. |
| 1111 | */ |
| 1112 | gd->flags &= ~GD_FLG_SERIAL_READY; |
| 1113 | |
| 1114 | /* |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 1115 | * U-Boot has been copied into SDRAM, the BSS has been cleared etc. |
| 1116 | * Transfer execution from Flash to RAM by calculating the address |
| 1117 | * of the in-RAM copy of board_init_r() and calling it |
| 1118 | */ |
Alexey Brodkin | 7bf9f20 | 2015-02-25 17:59:02 +0300 | [diff] [blame] | 1119 | (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 1120 | |
| 1121 | /* NOTREACHED - board_init_r() does not return */ |
| 1122 | hang(); |
| 1123 | } |
Alexey Brodkin | 5bcd19a | 2015-03-24 11:12:47 +0300 | [diff] [blame] | 1124 | #endif /* CONFIG_X86 */ |