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