Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Graeme Russ, <graeme.russ@gmail.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 8 | #include <fdtdec.h> |
Gabe Black | 8313315 | 2012-11-03 11:41:23 +0000 | [diff] [blame] | 9 | #include <spi.h> |
Simon Glass | db55bd7 | 2015-01-01 16:18:11 -0700 | [diff] [blame^] | 10 | #include <asm/mtrr.h> |
Simon Glass | 86cfb6b | 2013-03-05 14:39:54 +0000 | [diff] [blame] | 11 | #include <asm/sections.h> |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 15 | /* Get the top of usable RAM */ |
| 16 | __weak ulong board_get_usable_ram_top(ulong total_size) |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 17 | { |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 18 | return gd->ram_size; |
| 19 | } |
| 20 | |
| 21 | int calculate_relocation_address(void) |
| 22 | { |
| 23 | const ulong uboot_size = (uintptr_t)&__bss_end - |
| 24 | (uintptr_t)&__text_start; |
| 25 | ulong total_size; |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 26 | ulong dest_addr; |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 27 | ulong fdt_size = 0; |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 28 | |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 29 | #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL) |
| 30 | if (gd->fdt_blob) |
| 31 | fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); |
| 32 | #endif |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 33 | total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN + |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 34 | CONFIG_SYS_STACK_SIZE + fdt_size; |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 35 | |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 36 | dest_addr = board_get_usable_ram_top(total_size); |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 37 | /* |
| 38 | * NOTE: All destination address are rounded down to 16-byte |
| 39 | * boundary to satisfy various worst-case alignment |
| 40 | * requirements |
| 41 | */ |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 42 | dest_addr &= ~15; |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 43 | |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 44 | #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL) |
| 45 | /* |
| 46 | * If the device tree is sitting immediate above our image then we |
| 47 | * must relocate it. If it is embedded in the data section, then it |
| 48 | * will be relocated with other data. |
| 49 | */ |
| 50 | if (gd->fdt_blob) { |
| 51 | dest_addr -= fdt_size; |
Simon Glass | 1938f4a | 2013-03-11 06:49:53 +0000 | [diff] [blame] | 52 | gd->new_fdt = (void *)dest_addr; |
Simon Glass | f697d52 | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 53 | dest_addr &= ~15; |
| 54 | } |
| 55 | #endif |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 56 | /* U-Boot is below the FDT */ |
| 57 | dest_addr -= uboot_size; |
| 58 | dest_addr &= ~((1 << 12) - 1); |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 59 | gd->relocaddr = dest_addr; |
Simon Glass | 5e98947 | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 60 | gd->reloc_off = dest_addr - (uintptr_t)&__text_start; |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 61 | |
Gabe Black | 32f9873 | 2012-11-03 11:41:24 +0000 | [diff] [blame] | 62 | /* Stack is at the bottom, so it can grow down */ |
| 63 | gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN; |
| 64 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 68 | int init_cache_f_r(void) |
| 69 | { |
Simon Glass | db55bd7 | 2015-01-01 16:18:11 -0700 | [diff] [blame^] | 70 | #if defined(CONFIG_X86_RESET_VECTOR) & !defined(CONFIG_HAVE_FSP) |
| 71 | int ret; |
| 72 | |
| 73 | ret = mtrr_commit(false); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | #endif |
Graeme Russ | a1d57b7 | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 77 | /* Initialise the CPU cache(s) */ |
| 78 | return init_cache(); |
| 79 | } |
| 80 | |
Graeme Russ | d47ab0e | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 81 | bd_t bd_data; |
| 82 | |
| 83 | int init_bd_struct_r(void) |
| 84 | { |
| 85 | gd->bd = &bd_data; |
| 86 | memset(gd->bd, 0, sizeof(bd_t)); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Gabe Black | 8313315 | 2012-11-03 11:41:23 +0000 | [diff] [blame] | 91 | int init_func_spi(void) |
| 92 | { |
| 93 | puts("SPI: "); |
| 94 | spi_init(); |
| 95 | puts("ready\n"); |
| 96 | return 0; |
| 97 | } |