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