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