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> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 14 | #include <console.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 15 | #include <environment.h> |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 16 | #include <dm.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 17 | #include <fdtdec.h> |
Simon Glass | f828bf2 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 18 | #include <fs.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 19 | #include <i2c.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 20 | #include <initcall.h> |
Simon Glass | 96d4b75 | 2017-03-31 08:40:37 -0600 | [diff] [blame] | 21 | #include <init_helpers.h> |
Simon Glass | fb5cf7f | 2015-02-27 22:06:36 -0700 | [diff] [blame] | 22 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 23 | #include <mapmem.h> |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 24 | #include <os.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 25 | #include <post.h> |
Simon Glass | e47b2d6 | 2017-03-31 08:40:38 -0600 | [diff] [blame] | 26 | #include <relocate.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 27 | #include <spi.h> |
Jeroen Hofstee | c5d4001 | 2014-06-23 23:20:19 +0200 | [diff] [blame] | 28 | #include <status_led.h> |
Simon Glass | 1057e6c | 2016-02-24 09:14:50 -0700 | [diff] [blame] | 29 | #include <timer.h> |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 30 | #include <trace.h> |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 31 | #include <video.h> |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 32 | #include <watchdog.h> |
Simon Glass | b885d02 | 2017-05-17 08:23:01 -0600 | [diff] [blame] | 33 | #ifdef CONFIG_MACH_TYPE |
| 34 | #include <asm/mach-types.h> |
| 35 | #endif |
Simon Glass | 1fbf97d | 2017-03-31 08:40:39 -0600 | [diff] [blame] | 36 | #if defined(CONFIG_MP) && defined(CONFIG_PPC) |
| 37 | #include <asm/mp.h> |
| 38 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 39 | #include <asm/io.h> |
| 40 | #include <asm/sections.h> |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 41 | #include <dm/root.h> |
Simon Glass | 056285f | 2017-03-31 08:40:35 -0600 | [diff] [blame] | 42 | #include <linux/errno.h> |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Pointer to initial global data area |
| 46 | * |
| 47 | * Here we initialize it if needed. |
| 48 | */ |
| 49 | #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR |
| 50 | #undef XTRN_DECLARE_GLOBAL_DATA_PTR |
| 51 | #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ |
| 52 | DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); |
| 53 | #else |
| 54 | DECLARE_GLOBAL_DATA_PTR; |
| 55 | #endif |
| 56 | |
| 57 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 58 | * TODO(sjg@chromium.org): IMO this code should be |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 59 | * refactored to a single function, something like: |
| 60 | * |
| 61 | * void led_set_state(enum led_colour_t colour, int on); |
| 62 | */ |
| 63 | /************************************************************************ |
| 64 | * Coloured LED functionality |
| 65 | ************************************************************************ |
| 66 | * May be supplied by boards if desired |
| 67 | */ |
Jeroen Hofstee | c5d4001 | 2014-06-23 23:20:19 +0200 | [diff] [blame] | 68 | __weak void coloured_LED_init(void) {} |
| 69 | __weak void red_led_on(void) {} |
| 70 | __weak void red_led_off(void) {} |
| 71 | __weak void green_led_on(void) {} |
| 72 | __weak void green_led_off(void) {} |
| 73 | __weak void yellow_led_on(void) {} |
| 74 | __weak void yellow_led_off(void) {} |
| 75 | __weak void blue_led_on(void) {} |
| 76 | __weak void blue_led_off(void) {} |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Why is gd allocated a register? Prior to reloc it might be better to |
| 80 | * just pass it around to each function in this file? |
| 81 | * |
| 82 | * After reloc one could argue that it is hardly used and doesn't need |
| 83 | * to be in a register. Or if it is it should perhaps hold pointers to all |
| 84 | * global data for all modules, so that post-reloc we can avoid the massive |
| 85 | * literal pool we get on ARM. Or perhaps just encourage each module to use |
| 86 | * a structure... |
| 87 | */ |
| 88 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 89 | #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 90 | static int init_func_watchdog_init(void) |
| 91 | { |
Tom Rini | ea3310e | 2017-03-14 11:08:10 -0400 | [diff] [blame] | 92 | # if defined(CONFIG_HW_WATCHDOG) && \ |
| 93 | (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ |
Stefan Roese | 14a380a | 2015-03-10 08:04:36 +0100 | [diff] [blame] | 94 | defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \ |
Anatolij Gustschin | 46d7a3b | 2016-06-13 14:24:23 +0200 | [diff] [blame] | 95 | defined(CONFIG_DESIGNWARE_WATCHDOG) || \ |
Stefan Roese | 14a380a | 2015-03-10 08:04:36 +0100 | [diff] [blame] | 96 | defined(CONFIG_IMX_WATCHDOG)) |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 97 | hw_watchdog_init(); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 98 | puts(" Watchdog enabled\n"); |
Anatolij Gustschin | ba169d9 | 2016-06-13 14:24:24 +0200 | [diff] [blame] | 99 | # endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 100 | WATCHDOG_RESET(); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | int init_func_watchdog_reset(void) |
| 106 | { |
| 107 | WATCHDOG_RESET(); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | #endif /* CONFIG_WATCHDOG */ |
| 112 | |
Jeroen Hofstee | dd2a6cd | 2014-10-08 22:57:22 +0200 | [diff] [blame] | 113 | __weak void board_add_ram_info(int use_default) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 114 | { |
| 115 | /* please define platform specific board_add_ram_info() */ |
| 116 | } |
| 117 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 118 | static int init_baud_rate(void) |
| 119 | { |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 120 | gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int display_text_info(void) |
| 125 | { |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 126 | #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP) |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 127 | ulong bss_start, bss_end, text_base; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 128 | |
Simon Glass | 632efa7 | 2013-03-11 07:06:48 +0000 | [diff] [blame] | 129 | bss_start = (ulong)&__bss_start; |
| 130 | bss_end = (ulong)&__bss_end; |
Albert ARIBAUD | b60eff3 | 2014-02-22 17:53:43 +0100 | [diff] [blame] | 131 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 132 | #ifdef CONFIG_SYS_TEXT_BASE |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 133 | text_base = CONFIG_SYS_TEXT_BASE; |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 134 | #else |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 135 | text_base = CONFIG_SYS_MONITOR_BASE; |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 136 | #endif |
Daniel Schwierzeck | 9fdee7d | 2014-11-15 23:46:53 +0100 | [diff] [blame] | 137 | |
| 138 | debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", |
| 139 | text_base, bss_start, bss_end); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 140 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 141 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int announce_dram_init(void) |
| 146 | { |
| 147 | puts("DRAM: "); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static int show_dram_config(void) |
| 152 | { |
York Sun | fa39ffe | 2014-05-02 17:28:05 -0700 | [diff] [blame] | 153 | unsigned long long size; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 154 | |
| 155 | #ifdef CONFIG_NR_DRAM_BANKS |
| 156 | int i; |
| 157 | |
| 158 | debug("\nRAM Configuration:\n"); |
| 159 | for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 160 | size += gd->bd->bi_dram[i].size; |
Bin Meng | 715f599 | 2015-08-06 01:31:20 -0700 | [diff] [blame] | 161 | debug("Bank #%d: %llx ", i, |
| 162 | (unsigned long long)(gd->bd->bi_dram[i].start)); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 163 | #ifdef DEBUG |
| 164 | print_size(gd->bd->bi_dram[i].size, "\n"); |
| 165 | #endif |
| 166 | } |
| 167 | debug("\nDRAM: "); |
| 168 | #else |
| 169 | size = gd->ram_size; |
| 170 | #endif |
| 171 | |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 172 | print_size(size, ""); |
| 173 | board_add_ram_info(0); |
| 174 | putc('\n'); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 179 | __weak int dram_init_banksize(void) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 180 | { |
| 181 | #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) |
| 182 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 183 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
| 184 | #endif |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 185 | |
| 186 | return 0; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Simon Glass | 6915398 | 2017-05-12 21:09:56 -0600 | [diff] [blame] | 189 | #if defined(CONFIG_SYS_I2C) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 190 | static int init_func_i2c(void) |
| 191 | { |
| 192 | puts("I2C: "); |
trem | 815a76f | 2013-09-21 18:13:34 +0200 | [diff] [blame] | 193 | #ifdef CONFIG_SYS_I2C |
| 194 | i2c_init_all(); |
| 195 | #else |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 196 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
trem | 815a76f | 2013-09-21 18:13:34 +0200 | [diff] [blame] | 197 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 198 | puts("ready\n"); |
| 199 | return 0; |
| 200 | } |
| 201 | #endif |
| 202 | |
| 203 | #if defined(CONFIG_HARD_SPI) |
| 204 | static int init_func_spi(void) |
| 205 | { |
| 206 | puts("SPI: "); |
| 207 | spi_init(); |
| 208 | puts("ready\n"); |
| 209 | return 0; |
| 210 | } |
| 211 | #endif |
| 212 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 213 | static int setup_mon_len(void) |
| 214 | { |
Michal Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 215 | #if defined(__ARM__) || defined(__MICROBLAZE__) |
Albert ARIBAUD | b60eff3 | 2014-02-22 17:53:43 +0100 | [diff] [blame] | 216 | gd->mon_len = (ulong)&__bss_end - (ulong)_start; |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 217 | #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 218 | gd->mon_len = (ulong)&_end - (ulong)_init; |
Tom Rini | ea3310e | 2017-03-14 11:08:10 -0400 | [diff] [blame] | 219 | #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA) |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 220 | gd->mon_len = CONFIG_SYS_MONITOR_LEN; |
Rick Chen | 068feb9 | 2017-12-26 13:55:58 +0800 | [diff] [blame] | 221 | #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV) |
Kun-Hua Huang | 2e88bb2 | 2015-08-24 14:52:35 +0800 | [diff] [blame] | 222 | gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start); |
Simon Glass | b0b3595 | 2016-05-14 18:49:28 -0600 | [diff] [blame] | 223 | #elif defined(CONFIG_SYS_MONITOR_BASE) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 224 | /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ |
| 225 | gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; |
Simon Glass | 632efa7 | 2013-03-11 07:06:48 +0000 | [diff] [blame] | 226 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | __weak int arch_cpu_init(void) |
| 231 | { |
| 232 | return 0; |
| 233 | } |
| 234 | |
Paul Burton | 8ebf506 | 2016-09-21 11:18:46 +0100 | [diff] [blame] | 235 | __weak int mach_cpu_init(void) |
| 236 | { |
| 237 | return 0; |
| 238 | } |
| 239 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 240 | /* Get the top of usable RAM */ |
| 241 | __weak ulong board_get_usable_ram_top(ulong total_size) |
| 242 | { |
Stephen Warren | 1e4d11a | 2014-12-23 10:34:49 -0700 | [diff] [blame] | 243 | #ifdef CONFIG_SYS_SDRAM_BASE |
| 244 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 245 | * 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] | 246 | * 32-bit address space. If so, clip the usable RAM so it doesn't. |
| 247 | */ |
| 248 | if (gd->ram_top < CONFIG_SYS_SDRAM_BASE) |
| 249 | /* |
| 250 | * Will wrap back to top of 32-bit space when reservations |
| 251 | * are made. |
| 252 | */ |
| 253 | return 0; |
| 254 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 255 | return gd->ram_top; |
| 256 | } |
| 257 | |
| 258 | static int setup_dest_addr(void) |
| 259 | { |
| 260 | debug("Monitor len: %08lX\n", gd->mon_len); |
| 261 | /* |
| 262 | * Ram is setup, size stored in gd !! |
| 263 | */ |
| 264 | debug("Ram size: %08lX\n", (ulong)gd->ram_size); |
York Sun | 36cc0de | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 265 | #if defined(CONFIG_SYS_MEM_TOP_HIDE) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 266 | /* |
| 267 | * Subtract specified amount of memory to hide so that it won't |
| 268 | * get "touched" at all by U-Boot. By fixing up gd->ram_size |
| 269 | * the Linux kernel should now get passed the now "corrected" |
York Sun | 36cc0de | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 270 | * memory size and won't touch it either. This should work |
| 271 | * for arch/ppc and arch/powerpc. Only Linux board ports in |
| 272 | * arch/powerpc with bootwrapper support, that recalculate the |
| 273 | * memory size from the SDRAM controller setup will have to |
| 274 | * get fixed. |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 275 | */ |
York Sun | 36cc0de | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 276 | gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE; |
| 277 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 278 | #ifdef CONFIG_SYS_SDRAM_BASE |
| 279 | gd->ram_top = CONFIG_SYS_SDRAM_BASE; |
| 280 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 281 | gd->ram_top += get_effective_memsize(); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 282 | gd->ram_top = board_get_usable_ram_top(gd->mon_len); |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 283 | gd->relocaddr = gd->ram_top; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 284 | debug("Ram top: %08lX\n", (ulong)gd->ram_top); |
Gabriel Huau | ec3b482 | 2014-09-03 13:57:54 -0700 | [diff] [blame] | 285 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 286 | /* |
| 287 | * We need to make sure the location we intend to put secondary core |
| 288 | * boot code is reserved and not used by any part of u-boot |
| 289 | */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 290 | if (gd->relocaddr > determine_mp_bootpg(NULL)) { |
| 291 | gd->relocaddr = determine_mp_bootpg(NULL); |
| 292 | debug("Reserving MP boot page to %08lx\n", gd->relocaddr); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 293 | } |
| 294 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 298 | #ifdef CONFIG_PRAM |
| 299 | /* reserve protected RAM */ |
| 300 | static int reserve_pram(void) |
| 301 | { |
| 302 | ulong reg; |
| 303 | |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 304 | reg = env_get_ulong("pram", 10, CONFIG_PRAM); |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 305 | gd->relocaddr -= (reg << 10); /* size is in kB */ |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 306 | debug("Reserving %ldk for protected RAM at %08lx\n", reg, |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 307 | gd->relocaddr); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | #endif /* CONFIG_PRAM */ |
| 311 | |
| 312 | /* Round memory pointer down to next 4 kB limit */ |
| 313 | static int reserve_round_4k(void) |
| 314 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 315 | gd->relocaddr &= ~(4096 - 1); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Simon Glass | 80d4bcd | 2017-03-31 08:40:29 -0600 | [diff] [blame] | 319 | #ifdef CONFIG_ARM |
Siva Durga Prasad Paladugu | 60873f7 | 2017-07-13 19:01:08 +0530 | [diff] [blame] | 320 | __weak int reserve_mmu(void) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 321 | { |
Simon Glass | 80d4bcd | 2017-03-31 08:40:29 -0600 | [diff] [blame] | 322 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 323 | /* reserve TLB table */ |
David Feng | cce6be7 | 2013-12-14 11:47:36 +0800 | [diff] [blame] | 324 | gd->arch.tlb_size = PGTABLE_SIZE; |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 325 | gd->relocaddr -= gd->arch.tlb_size; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 326 | |
| 327 | /* round down to next 64 kB limit */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 328 | gd->relocaddr &= ~(0x10000 - 1); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 329 | |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 330 | gd->arch.tlb_addr = gd->relocaddr; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 331 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 332 | gd->arch.tlb_addr + gd->arch.tlb_size); |
York Sun | 50e93b9 | 2016-06-24 16:46:19 -0700 | [diff] [blame] | 333 | |
| 334 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 335 | /* |
| 336 | * Record allocated tlb_addr in case gd->tlb_addr to be overwritten |
| 337 | * with location within secure ram. |
| 338 | */ |
| 339 | gd->arch.tlb_allocated = gd->arch.tlb_addr; |
| 340 | #endif |
Simon Glass | 80d4bcd | 2017-03-31 08:40:29 -0600 | [diff] [blame] | 341 | #endif |
York Sun | 50e93b9 | 2016-06-24 16:46:19 -0700 | [diff] [blame] | 342 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | #endif |
| 346 | |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 347 | static int reserve_video(void) |
| 348 | { |
Simon Glass | 0f079eb | 2017-03-31 08:40:30 -0600 | [diff] [blame] | 349 | #ifdef CONFIG_DM_VIDEO |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 350 | ulong addr; |
| 351 | int ret; |
| 352 | |
| 353 | addr = gd->relocaddr; |
| 354 | ret = video_reserve(&addr); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | gd->relocaddr = addr; |
Simon Glass | 0f079eb | 2017-03-31 08:40:30 -0600 | [diff] [blame] | 358 | #elif defined(CONFIG_LCD) |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 359 | # ifdef CONFIG_FB_ADDR |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 360 | gd->fb_base = CONFIG_FB_ADDR; |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 361 | # else |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 362 | /* reserve memory for LCD display (always full pages) */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 363 | gd->relocaddr = lcd_setmem(gd->relocaddr); |
| 364 | gd->fb_base = gd->relocaddr; |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 365 | # endif /* CONFIG_FB_ADDR */ |
Simon Glass | 0f079eb | 2017-03-31 08:40:30 -0600 | [diff] [blame] | 366 | #elif defined(CONFIG_VIDEO) && \ |
Heiko Schocher | 5b8e76c | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 367 | (!defined(CONFIG_PPC)) && \ |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 368 | !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ |
Tom Rini | ea3310e | 2017-03-14 11:08:10 -0400 | [diff] [blame] | 369 | !defined(CONFIG_M68K) |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 370 | /* reserve memory for video display (always full pages) */ |
| 371 | gd->relocaddr = video_setmem(gd->relocaddr); |
| 372 | gd->fb_base = gd->relocaddr; |
Simon Glass | 0f079eb | 2017-03-31 08:40:30 -0600 | [diff] [blame] | 373 | #endif |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 374 | |
| 375 | return 0; |
| 376 | } |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 377 | |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 378 | static int reserve_trace(void) |
| 379 | { |
| 380 | #ifdef CONFIG_TRACE |
| 381 | gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE; |
| 382 | gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE); |
| 383 | debug("Reserving %dk for trace data at: %08lx\n", |
| 384 | CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr); |
| 385 | #endif |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 390 | static int reserve_uboot(void) |
| 391 | { |
| 392 | /* |
| 393 | * reserve memory for U-Boot code, data & bss |
| 394 | * round down to next 4 kB limit |
| 395 | */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 396 | gd->relocaddr -= gd->mon_len; |
| 397 | gd->relocaddr &= ~(4096 - 1); |
Paul Burton | 703ec9d | 2017-06-19 11:53:47 -0700 | [diff] [blame] | 398 | #if defined(CONFIG_E500) || defined(CONFIG_MIPS) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 399 | /* round down to next 64 kB limit so that IVPR stays aligned */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 400 | gd->relocaddr &= ~(65536 - 1); |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 401 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 402 | |
| 403 | 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] | 404 | gd->relocaddr); |
| 405 | |
| 406 | gd->start_addr_sp = gd->relocaddr; |
| 407 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* reserve memory for malloc() area */ |
| 412 | static int reserve_malloc(void) |
| 413 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 414 | gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 415 | debug("Reserving %dk for malloc() at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 416 | TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /* (permanently) allocate a Board Info struct */ |
| 421 | static int reserve_board(void) |
| 422 | { |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 423 | if (!gd->bd) { |
| 424 | gd->start_addr_sp -= sizeof(bd_t); |
| 425 | gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t)); |
| 426 | memset(gd->bd, '\0', sizeof(bd_t)); |
| 427 | debug("Reserving %zu Bytes for Board Info at: %08lx\n", |
| 428 | sizeof(bd_t), gd->start_addr_sp); |
| 429 | } |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int setup_machine(void) |
| 434 | { |
| 435 | #ifdef CONFIG_MACH_TYPE |
| 436 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ |
| 437 | #endif |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static int reserve_global_data(void) |
| 442 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 443 | gd->start_addr_sp -= sizeof(gd_t); |
| 444 | 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] | 445 | debug("Reserving %zu Bytes for Global Data at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 446 | sizeof(gd_t), gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static int reserve_fdt(void) |
| 451 | { |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 452 | #ifndef CONFIG_OF_EMBED |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 453 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 454 | * If the device tree is sitting immediately above our image then we |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 455 | * must relocate it. If it is embedded in the data section, then it |
| 456 | * will be relocated with other data. |
| 457 | */ |
| 458 | if (gd->fdt_blob) { |
| 459 | gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); |
| 460 | |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 461 | gd->start_addr_sp -= gd->fdt_size; |
| 462 | gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 463 | debug("Reserving %lu Bytes for FDT at: %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 464 | gd->fdt_size, gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 465 | } |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 466 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Simon Glass | 25e7dc6 | 2017-05-22 05:05:30 -0600 | [diff] [blame] | 471 | static int reserve_bootstage(void) |
| 472 | { |
| 473 | #ifdef CONFIG_BOOTSTAGE |
| 474 | int size = bootstage_get_size(); |
| 475 | |
| 476 | gd->start_addr_sp -= size; |
| 477 | gd->new_bootstage = map_sysmem(gd->start_addr_sp, size); |
| 478 | debug("Reserving %#x Bytes for bootstage at: %08lx\n", size, |
| 479 | gd->start_addr_sp); |
| 480 | #endif |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 485 | int arch_reserve_stacks(void) |
| 486 | { |
| 487 | return 0; |
| 488 | } |
| 489 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 490 | static int reserve_stacks(void) |
| 491 | { |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 492 | /* make stack pointer 16-byte aligned */ |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 493 | gd->start_addr_sp -= 16; |
| 494 | gd->start_addr_sp &= ~0xf; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 495 | |
| 496 | /* |
Simon Glass | 4c50934 | 2015-04-28 20:25:03 -0600 | [diff] [blame] | 497 | * let the architecture-specific code tailor gd->start_addr_sp and |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 498 | * gd->irq_sp |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 499 | */ |
Andreas Bießmann | 68145d4 | 2015-02-06 23:06:45 +0100 | [diff] [blame] | 500 | return arch_reserve_stacks(); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static int display_new_sp(void) |
| 504 | { |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 505 | debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
Vladimir Zapolskiy | e2099d7 | 2016-11-28 00:15:24 +0200 | [diff] [blame] | 510 | #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ |
| 511 | defined(CONFIG_SH) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 512 | static int setup_board_part1(void) |
| 513 | { |
| 514 | bd_t *bd = gd->bd; |
| 515 | |
| 516 | /* |
| 517 | * Save local variables to board info struct |
| 518 | */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 519 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */ |
| 520 | bd->bi_memsize = gd->ram_size; /* size in bytes */ |
| 521 | |
| 522 | #ifdef CONFIG_SYS_SRAM_BASE |
| 523 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */ |
| 524 | bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ |
| 525 | #endif |
| 526 | |
Heiko Schocher | 5025897 | 2017-06-07 17:33:11 +0200 | [diff] [blame] | 527 | #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 528 | bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */ |
| 529 | #endif |
Heiko Schocher | 064b55c | 2017-06-14 05:49:40 +0200 | [diff] [blame] | 530 | #if defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 531 | bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ |
| 532 | #endif |
| 533 | #if defined(CONFIG_MPC83xx) |
| 534 | bd->bi_immrbar = CONFIG_SYS_IMMR; |
| 535 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 536 | |
| 537 | return 0; |
| 538 | } |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 539 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 540 | |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 541 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 542 | static int setup_board_part2(void) |
| 543 | { |
| 544 | bd_t *bd = gd->bd; |
| 545 | |
| 546 | bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ |
| 547 | bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ |
| 548 | #if defined(CONFIG_CPM2) |
| 549 | bd->bi_cpmfreq = gd->arch.cpm_clk; |
| 550 | bd->bi_brgfreq = gd->arch.brg_clk; |
| 551 | bd->bi_sccfreq = gd->arch.scc_clk; |
| 552 | bd->bi_vco = gd->arch.vco_out; |
| 553 | #endif /* CONFIG_CPM2 */ |
Alison Wang | 1313db4 | 2015-02-12 18:33:15 +0800 | [diff] [blame] | 554 | #if defined(CONFIG_M68K) && defined(CONFIG_PCI) |
| 555 | bd->bi_pcifreq = gd->pci_clk; |
| 556 | #endif |
| 557 | #if defined(CONFIG_EXTRA_CLOCK) |
| 558 | bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */ |
| 559 | bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */ |
| 560 | bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */ |
| 561 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | #endif |
| 566 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 567 | #ifdef CONFIG_POST |
| 568 | static int init_post(void) |
| 569 | { |
| 570 | post_bootmode_init(); |
| 571 | post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | #endif |
| 576 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 577 | static int reloc_fdt(void) |
| 578 | { |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 579 | #ifndef CONFIG_OF_EMBED |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 580 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 581 | return 0; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 582 | if (gd->new_fdt) { |
| 583 | memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); |
| 584 | gd->fdt_blob = gd->new_fdt; |
| 585 | } |
Siva Durga Prasad Paladugu | e9acb9e | 2015-12-03 15:46:03 +0100 | [diff] [blame] | 586 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
Simon Glass | 25e7dc6 | 2017-05-22 05:05:30 -0600 | [diff] [blame] | 591 | static int reloc_bootstage(void) |
| 592 | { |
| 593 | #ifdef CONFIG_BOOTSTAGE |
| 594 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 595 | return 0; |
| 596 | if (gd->new_bootstage) { |
| 597 | int size = bootstage_get_size(); |
| 598 | |
| 599 | debug("Copying bootstage from %p to %p, size %x\n", |
| 600 | gd->bootstage, gd->new_bootstage, size); |
| 601 | memcpy(gd->new_bootstage, gd->bootstage, size); |
| 602 | gd->bootstage = gd->new_bootstage; |
| 603 | } |
| 604 | #endif |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 609 | static int setup_reloc(void) |
| 610 | { |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 611 | if (gd->flags & GD_FLG_SKIP_RELOC) { |
| 612 | debug("Skipping relocation due to flag\n"); |
| 613 | return 0; |
| 614 | } |
| 615 | |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 616 | #ifdef CONFIG_SYS_TEXT_BASE |
Lothar Waßmann | 53207bf | 2017-06-08 10:18:25 +0200 | [diff] [blame] | 617 | #ifdef ARM |
| 618 | gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start; |
| 619 | #elif defined(CONFIG_M68K) |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 620 | /* |
| 621 | * On all ColdFire arch cpu, monitor code starts always |
| 622 | * just after the default vector table location, so at 0x400 |
| 623 | */ |
| 624 | gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400); |
Lothar Waßmann | 53207bf | 2017-06-08 10:18:25 +0200 | [diff] [blame] | 625 | #else |
| 626 | gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; |
angelo@sysam.it | e310b93 | 2015-02-12 01:40:17 +0100 | [diff] [blame] | 627 | #endif |
Sonic Zhang | d54d7eb | 2014-07-17 19:01:34 +0800 | [diff] [blame] | 628 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 629 | memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); |
| 630 | |
| 631 | debug("Relocation Offset is: %08lx\n", gd->reloc_off); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 632 | debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 633 | gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd), |
| 634 | gd->start_addr_sp); |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
mario.six@gdsys.cc | 2a79275 | 2017-02-22 16:07:22 +0100 | [diff] [blame] | 639 | #ifdef CONFIG_OF_BOARD_FIXUP |
| 640 | static int fix_fdt(void) |
| 641 | { |
| 642 | return board_fix_fdt((void *)gd->fdt_blob); |
| 643 | } |
| 644 | #endif |
| 645 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 646 | /* ARM calls relocate_code from its crt0.S */ |
Simon Glass | 530f27e | 2017-01-16 07:03:49 -0700 | [diff] [blame] | 647 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ |
| 648 | !CONFIG_IS_ENABLED(X86_64) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 649 | |
| 650 | static int jump_to_copy(void) |
| 651 | { |
Simon Glass | f05ad9b | 2015-08-04 12:33:39 -0600 | [diff] [blame] | 652 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 653 | return 0; |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 654 | /* |
| 655 | * x86 is special, but in a nice way. It uses a trampoline which |
| 656 | * enables the dcache if possible. |
| 657 | * |
| 658 | * For now, other archs use relocate_code(), which is implemented |
| 659 | * similarly for all archs. When we do generic relocation, hopefully |
| 660 | * we can make all archs enable the dcache prior to relocation. |
| 661 | */ |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 662 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 663 | /* |
| 664 | * SDRAM and console are now initialised. The final stack can now |
| 665 | * be setup in SDRAM. Code execution will continue in Flash, but |
| 666 | * with the stack in SDRAM and Global Data in temporary memory |
| 667 | * (CPU cache) |
| 668 | */ |
Simon Glass | f0c7d9c | 2015-08-10 20:44:32 -0600 | [diff] [blame] | 669 | arch_setup_gd(gd->new_gd); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 670 | board_init_f_r_trampoline(gd->start_addr_sp); |
| 671 | #else |
Masahiro Yamada | a0ba279 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 672 | relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 673 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | #endif |
| 678 | |
| 679 | /* Record the board_init_f() bootstage (after arch_cpu_init()) */ |
Simon Glass | b383d6c | 2017-05-22 05:05:25 -0600 | [diff] [blame] | 680 | static int initf_bootstage(void) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 681 | { |
Simon Glass | baa7d34 | 2017-06-07 10:28:46 -0600 | [diff] [blame] | 682 | bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) && |
| 683 | IS_ENABLED(CONFIG_BOOTSTAGE_STASH); |
Simon Glass | b383d6c | 2017-05-22 05:05:25 -0600 | [diff] [blame] | 684 | int ret; |
| 685 | |
Simon Glass | 824bb1b | 2017-05-22 05:05:35 -0600 | [diff] [blame] | 686 | ret = bootstage_init(!from_spl); |
Simon Glass | b383d6c | 2017-05-22 05:05:25 -0600 | [diff] [blame] | 687 | if (ret) |
| 688 | return ret; |
Simon Glass | 824bb1b | 2017-05-22 05:05:35 -0600 | [diff] [blame] | 689 | if (from_spl) { |
| 690 | const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR, |
| 691 | CONFIG_BOOTSTAGE_STASH_SIZE); |
| 692 | |
| 693 | ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE); |
| 694 | if (ret && ret != -ENOENT) { |
| 695 | debug("Failed to unstash bootstage: err=%d\n", ret); |
| 696 | return ret; |
| 697 | } |
| 698 | } |
Simon Glass | b383d6c | 2017-05-22 05:05:25 -0600 | [diff] [blame] | 699 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 700 | bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f"); |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Simon Glass | 9854a87 | 2015-11-08 23:47:48 -0700 | [diff] [blame] | 705 | static int initf_console_record(void) |
| 706 | { |
Andy Yan | f1896c4 | 2017-07-24 17:43:34 +0800 | [diff] [blame] | 707 | #if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN) |
Simon Glass | 9854a87 | 2015-11-08 23:47:48 -0700 | [diff] [blame] | 708 | return console_record_init(); |
| 709 | #else |
| 710 | return 0; |
| 711 | #endif |
| 712 | } |
| 713 | |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 714 | static int initf_dm(void) |
| 715 | { |
Andy Yan | f1896c4 | 2017-07-24 17:43:34 +0800 | [diff] [blame] | 716 | #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN) |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 717 | int ret; |
| 718 | |
Simon Glass | 63c5bf4 | 2017-05-22 05:05:32 -0600 | [diff] [blame] | 719 | bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f"); |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 720 | ret = dm_init_and_scan(true); |
Simon Glass | 63c5bf4 | 2017-05-22 05:05:32 -0600 | [diff] [blame] | 721 | bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F); |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 722 | if (ret) |
| 723 | return ret; |
| 724 | #endif |
Simon Glass | 1057e6c | 2016-02-24 09:14:50 -0700 | [diff] [blame] | 725 | #ifdef CONFIG_TIMER_EARLY |
| 726 | ret = dm_timer_init(); |
| 727 | if (ret) |
| 728 | return ret; |
| 729 | #endif |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
Simon Glass | 146251f | 2015-01-19 22:16:12 -0700 | [diff] [blame] | 734 | /* Architecture-specific memory reservation */ |
| 735 | __weak int reserve_arch(void) |
| 736 | { |
| 737 | return 0; |
| 738 | } |
| 739 | |
Simon Glass | d4c671c | 2015-03-05 12:25:16 -0700 | [diff] [blame] | 740 | __weak int arch_cpu_init_dm(void) |
| 741 | { |
| 742 | return 0; |
| 743 | } |
| 744 | |
Simon Glass | 4acff45 | 2017-01-16 07:03:50 -0700 | [diff] [blame] | 745 | static const init_fnc_t init_sequence_f[] = { |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 746 | setup_mon_len, |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 747 | #ifdef CONFIG_OF_CONTROL |
Simon Glass | 0879361 | 2015-02-27 22:06:35 -0700 | [diff] [blame] | 748 | fdtdec_setup, |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 749 | #endif |
Kevin Hilman | d210718 | 2014-12-09 15:03:58 -0800 | [diff] [blame] | 750 | #ifdef CONFIG_TRACE |
Simon Glass | 71c52db | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 751 | trace_early_init, |
Kevin Hilman | d210718 | 2014-12-09 15:03:58 -0800 | [diff] [blame] | 752 | #endif |
Simon Glass | 768e0f5 | 2014-11-10 18:00:18 -0700 | [diff] [blame] | 753 | initf_malloc, |
Simon Glass | af1bc0c | 2017-12-04 13:48:28 -0700 | [diff] [blame] | 754 | log_init, |
Simon Glass | 5ac44a5 | 2017-05-22 05:05:31 -0600 | [diff] [blame] | 755 | initf_bootstage, /* uses its own timer, so does not need DM */ |
Simon Glass | 9854a87 | 2015-11-08 23:47:48 -0700 | [diff] [blame] | 756 | initf_console_record, |
Simon Glass | 671549e | 2017-03-28 10:27:18 -0600 | [diff] [blame] | 757 | #if defined(CONFIG_HAVE_FSP) |
| 758 | arch_fsp_init, |
Bin Meng | a52a068e | 2015-08-20 06:40:18 -0700 | [diff] [blame] | 759 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 760 | arch_cpu_init, /* basic arch cpu dependent setup */ |
Paul Burton | 8ebf506 | 2016-09-21 11:18:46 +0100 | [diff] [blame] | 761 | mach_cpu_init, /* SoC/machine dependent CPU setup */ |
Simon Glass | 3ea0953 | 2014-09-03 17:36:59 -0600 | [diff] [blame] | 762 | initf_dm, |
Simon Glass | d4c671c | 2015-03-05 12:25:16 -0700 | [diff] [blame] | 763 | arch_cpu_init_dm, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 764 | #if defined(CONFIG_BOARD_EARLY_INIT_F) |
| 765 | board_early_init_f, |
| 766 | #endif |
Simon Glass | 727e94a | 2017-03-28 10:27:26 -0600 | [diff] [blame] | 767 | #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) |
Simon Glass | c252c06 | 2017-03-28 10:27:19 -0600 | [diff] [blame] | 768 | /* get CPU and bus clocks according to the environment variable */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 769 | get_clocks, /* get CPU and bus clocks (etc.) */ |
Simon Glass | 1793e78 | 2017-03-28 10:27:23 -0600 | [diff] [blame] | 770 | #endif |
Angelo Dureghello | 0ce4528 | 2017-05-10 23:58:06 +0200 | [diff] [blame] | 771 | #if !defined(CONFIG_M68K) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 772 | timer_init, /* initialize timer */ |
Angelo Dureghello | 0ce4528 | 2017-05-10 23:58:06 +0200 | [diff] [blame] | 773 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 774 | #if defined(CONFIG_BOARD_POSTCLK_INIT) |
| 775 | board_postclk_init, |
| 776 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 777 | env_init, /* initialize environment */ |
| 778 | init_baud_rate, /* initialze baudrate settings */ |
| 779 | serial_init, /* serial communications setup */ |
| 780 | console_init_f, /* stage 1 init of console */ |
| 781 | display_options, /* say that we are here */ |
| 782 | display_text_info, /* show debugging info if required */ |
Simon Glass | 76d1d02 | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 783 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \ |
| 784 | defined(CONFIG_X86) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 785 | checkcpu, |
| 786 | #endif |
Simon Glass | cc66400 | 2017-01-23 13:31:25 -0700 | [diff] [blame] | 787 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 788 | print_cpuinfo, /* display cpu info (and speed) */ |
Simon Glass | cc66400 | 2017-01-23 13:31:25 -0700 | [diff] [blame] | 789 | #endif |
Cooper Jr., Franklin | af9e6ad | 2017-06-16 17:25:12 -0500 | [diff] [blame] | 790 | #if defined(CONFIG_DTB_RESELECT) |
| 791 | embedded_dtb_select, |
| 792 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 793 | #if defined(CONFIG_DISPLAY_BOARDINFO) |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 794 | show_board_info, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 795 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 796 | INIT_FUNC_WATCHDOG_INIT |
| 797 | #if defined(CONFIG_MISC_INIT_F) |
| 798 | misc_init_f, |
| 799 | #endif |
| 800 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 6915398 | 2017-05-12 21:09:56 -0600 | [diff] [blame] | 801 | #if defined(CONFIG_SYS_I2C) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 802 | init_func_i2c, |
| 803 | #endif |
| 804 | #if defined(CONFIG_HARD_SPI) |
| 805 | init_func_spi, |
| 806 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 807 | announce_dram_init, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 808 | dram_init, /* configure available RAM banks */ |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 809 | #ifdef CONFIG_POST |
| 810 | post_init_f, |
| 811 | #endif |
| 812 | INIT_FUNC_WATCHDOG_RESET |
| 813 | #if defined(CONFIG_SYS_DRAM_TEST) |
| 814 | testdram, |
| 815 | #endif /* CONFIG_SYS_DRAM_TEST */ |
| 816 | INIT_FUNC_WATCHDOG_RESET |
| 817 | |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 818 | #ifdef CONFIG_POST |
| 819 | init_post, |
| 820 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 821 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 822 | /* |
| 823 | * Now that we have DRAM mapped and working, we can |
| 824 | * relocate the code and continue running from DRAM. |
| 825 | * |
| 826 | * Reserve memory at end of RAM for (top down in that order): |
| 827 | * - area that won't get touched by U-Boot and Linux (optional) |
| 828 | * - kernel log buffer |
| 829 | * - protected RAM |
| 830 | * - LCD framebuffer |
| 831 | * - monitor code |
| 832 | * - board info struct |
| 833 | */ |
| 834 | setup_dest_addr, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 835 | #ifdef CONFIG_PRAM |
| 836 | reserve_pram, |
| 837 | #endif |
| 838 | reserve_round_4k, |
Simon Glass | 80d4bcd | 2017-03-31 08:40:29 -0600 | [diff] [blame] | 839 | #ifdef CONFIG_ARM |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 840 | reserve_mmu, |
| 841 | #endif |
Simon Glass | 5a54194 | 2016-01-18 19:52:21 -0700 | [diff] [blame] | 842 | reserve_video, |
Simon Glass | 8703ef3 | 2016-01-18 19:52:20 -0700 | [diff] [blame] | 843 | reserve_trace, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 844 | reserve_uboot, |
| 845 | reserve_malloc, |
| 846 | reserve_board, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 847 | setup_machine, |
| 848 | reserve_global_data, |
| 849 | reserve_fdt, |
Simon Glass | 25e7dc6 | 2017-05-22 05:05:30 -0600 | [diff] [blame] | 850 | reserve_bootstage, |
Simon Glass | 146251f | 2015-01-19 22:16:12 -0700 | [diff] [blame] | 851 | reserve_arch, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 852 | reserve_stacks, |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 853 | dram_init_banksize, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 854 | show_dram_config, |
Vladimir Zapolskiy | e2099d7 | 2016-11-28 00:15:24 +0200 | [diff] [blame] | 855 | #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ |
| 856 | defined(CONFIG_SH) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 857 | setup_board_part1, |
Daniel Schwierzeck | fb3db63 | 2015-11-01 17:36:13 +0100 | [diff] [blame] | 858 | #endif |
| 859 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 860 | INIT_FUNC_WATCHDOG_RESET |
| 861 | setup_board_part2, |
| 862 | #endif |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 863 | display_new_sp, |
mario.six@gdsys.cc | 2a79275 | 2017-02-22 16:07:22 +0100 | [diff] [blame] | 864 | #ifdef CONFIG_OF_BOARD_FIXUP |
| 865 | fix_fdt, |
| 866 | #endif |
Simon Glass | e4fef6c | 2013-03-11 14:30:42 +0000 | [diff] [blame] | 867 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 868 | reloc_fdt, |
Simon Glass | 25e7dc6 | 2017-05-22 05:05:30 -0600 | [diff] [blame] | 869 | reloc_bootstage, |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 870 | setup_reloc, |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 871 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 313aef3 | 2015-01-01 16:18:09 -0700 | [diff] [blame] | 872 | copy_uboot_to_ram, |
Simon Glass | 313aef3 | 2015-01-01 16:18:09 -0700 | [diff] [blame] | 873 | do_elf_reloc_fixups, |
Simon Glass | 6bda55a | 2017-01-16 07:03:52 -0700 | [diff] [blame] | 874 | clear_bss, |
Simon Glass | 313aef3 | 2015-01-01 16:18:09 -0700 | [diff] [blame] | 875 | #endif |
Chris Zankel | de5e5ce | 2016-08-10 18:36:43 +0300 | [diff] [blame] | 876 | #if defined(CONFIG_XTENSA) |
| 877 | clear_bss, |
| 878 | #endif |
Simon Glass | 530f27e | 2017-01-16 07:03:49 -0700 | [diff] [blame] | 879 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ |
| 880 | !CONFIG_IS_ENABLED(X86_64) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 881 | jump_to_copy, |
| 882 | #endif |
| 883 | NULL, |
| 884 | }; |
| 885 | |
| 886 | void board_init_f(ulong boot_flags) |
| 887 | { |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 888 | gd->flags = boot_flags; |
Alexey Brodkin | 9aed5a2 | 2013-11-27 22:32:40 +0400 | [diff] [blame] | 889 | gd->have_console = 0; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 890 | |
| 891 | if (initcall_run_list(init_sequence_f)) |
| 892 | hang(); |
| 893 | |
Ben Stoltz | 9b21749 | 2015-07-31 09:31:37 -0600 | [diff] [blame] | 894 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ |
Simon Glass | 530f27e | 2017-01-16 07:03:49 -0700 | [diff] [blame] | 895 | !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 896 | /* NOTREACHED - jump_to_copy() does not return */ |
| 897 | hang(); |
| 898 | #endif |
| 899 | } |
| 900 | |
Alexey Brodkin | 3fb8016 | 2015-02-24 19:40:36 +0300 | [diff] [blame] | 901 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 902 | /* |
| 903 | * For now this code is only used on x86. |
| 904 | * |
| 905 | * init_sequence_f_r is the list of init functions which are run when |
| 906 | * U-Boot is executing from Flash with a semi-limited 'C' environment. |
| 907 | * The following limitations must be considered when implementing an |
| 908 | * '_f_r' function: |
| 909 | * - 'static' variables are read-only |
| 910 | * - Global Data (gd->xxx) is read/write |
| 911 | * |
| 912 | * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if |
| 913 | * supported). It _should_, if possible, copy global data to RAM and |
| 914 | * initialise the CPU caches (to speed up the relocation process) |
| 915 | * |
| 916 | * NOTE: At present only x86 uses this route, but it is intended that |
| 917 | * all archs will move to this when generic relocation is implemented. |
| 918 | */ |
Simon Glass | 4acff45 | 2017-01-16 07:03:50 -0700 | [diff] [blame] | 919 | static const init_fnc_t init_sequence_f_r[] = { |
Simon Glass | 530f27e | 2017-01-16 07:03:49 -0700 | [diff] [blame] | 920 | #if !CONFIG_IS_ENABLED(X86_64) |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 921 | init_cache_f_r, |
Simon Glass | 530f27e | 2017-01-16 07:03:49 -0700 | [diff] [blame] | 922 | #endif |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 923 | |
| 924 | NULL, |
| 925 | }; |
| 926 | |
| 927 | void board_init_f_r(void) |
| 928 | { |
| 929 | if (initcall_run_list(init_sequence_f_r)) |
| 930 | hang(); |
| 931 | |
| 932 | /* |
Simon Glass | e4d6ab0 | 2016-03-11 22:06:51 -0700 | [diff] [blame] | 933 | * The pre-relocation drivers may be using memory that has now gone |
| 934 | * away. Mark serial as unavailable - this will fall back to the debug |
| 935 | * UART if available. |
Simon Glass | af1bc0c | 2017-12-04 13:48:28 -0700 | [diff] [blame] | 936 | * |
| 937 | * Do the same with log drivers since the memory may not be available. |
Simon Glass | e4d6ab0 | 2016-03-11 22:06:51 -0700 | [diff] [blame] | 938 | */ |
Simon Glass | af1bc0c | 2017-12-04 13:48:28 -0700 | [diff] [blame] | 939 | gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY); |
Simon Glass | 5ee94b4 | 2017-09-05 19:49:45 -0600 | [diff] [blame] | 940 | #ifdef CONFIG_TIMER |
| 941 | gd->timer = NULL; |
| 942 | #endif |
Simon Glass | e4d6ab0 | 2016-03-11 22:06:51 -0700 | [diff] [blame] | 943 | |
| 944 | /* |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 945 | * U-Boot has been copied into SDRAM, the BSS has been cleared etc. |
| 946 | * Transfer execution from Flash to RAM by calculating the address |
| 947 | * of the in-RAM copy of board_init_r() and calling it |
| 948 | */ |
Alexey Brodkin | 7bf9f20 | 2015-02-25 17:59:02 +0300 | [diff] [blame] | 949 | (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr); |
Simon Glass | 48a3380 | 2013-03-05 14:39:52 +0000 | [diff] [blame] | 950 | |
| 951 | /* NOTREACHED - board_init_r() does not return */ |
| 952 | hang(); |
| 953 | } |
Alexey Brodkin | 5bcd19a | 2015-03-24 11:12:47 +0300 | [diff] [blame] | 954 | #endif /* CONFIG_X86 */ |