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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | #include <common.h> |
| 24 | #include <command.h> |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 25 | #include <fdtdec.h> |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 26 | #include <stdio_dev.h> |
| 27 | #include <version.h> |
| 28 | #include <malloc.h> |
| 29 | #include <net.h> |
| 30 | #include <ide.h> |
| 31 | #include <serial.h> |
Gabe Black | a97cbda | 2012-11-03 11:41:23 +0000 | [diff] [blame] | 32 | #include <spi.h> |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 33 | #include <status_led.h> |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 34 | #include <asm/processor.h> |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 35 | #include <asm/u-boot-x86.h> |
Gabe Black | b841abf | 2012-11-03 11:41:26 +0000 | [diff] [blame] | 36 | #include <linux/compiler.h> |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 37 | |
| 38 | #include <asm/init_helpers.h> |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | /************************************************************************ |
| 43 | * Init Utilities * |
| 44 | ************************************************************************ |
| 45 | * Some of this code should be moved into the core functions, |
| 46 | * or dropped completely, |
| 47 | * but let's get it working (again) first... |
| 48 | */ |
| 49 | |
| 50 | int display_banner(void) |
| 51 | { |
| 52 | printf("\n\n%s\n\n", version_string); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int display_dram_config(void) |
| 58 | { |
| 59 | int i; |
| 60 | |
| 61 | puts("DRAM Configuration:\n"); |
| 62 | |
| 63 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 64 | printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); |
| 65 | print_size(gd->bd->bi_dram[i].size, "\n"); |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int init_baudrate_f(void) |
| 72 | { |
| 73 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
| 74 | return 0; |
| 75 | } |
| 76 | |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 77 | /* Get the top of usable RAM */ |
| 78 | __weak ulong board_get_usable_ram_top(ulong total_size) |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 79 | { |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 80 | return gd->ram_size; |
| 81 | } |
| 82 | |
| 83 | int calculate_relocation_address(void) |
| 84 | { |
| 85 | const ulong uboot_size = (uintptr_t)&__bss_end - |
| 86 | (uintptr_t)&__text_start; |
| 87 | ulong total_size; |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 88 | ulong dest_addr; |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 89 | ulong fdt_size = 0; |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 90 | |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 91 | #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL) |
| 92 | if (gd->fdt_blob) |
| 93 | fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); |
| 94 | #endif |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 95 | total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN + |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 96 | CONFIG_SYS_STACK_SIZE + fdt_size; |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 97 | |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 98 | dest_addr = board_get_usable_ram_top(total_size); |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 99 | /* |
| 100 | * NOTE: All destination address are rounded down to 16-byte |
| 101 | * boundary to satisfy various worst-case alignment |
| 102 | * requirements |
| 103 | */ |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 104 | dest_addr &= ~15; |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 105 | |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 106 | #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL) |
| 107 | /* |
| 108 | * If the device tree is sitting immediate above our image then we |
| 109 | * must relocate it. If it is embedded in the data section, then it |
| 110 | * will be relocated with other data. |
| 111 | */ |
| 112 | if (gd->fdt_blob) { |
| 113 | dest_addr -= fdt_size; |
Simon Glass | c45e359 | 2013-03-11 06:49:53 +0000 | [diff] [blame^] | 114 | gd->new_fdt = (void *)dest_addr; |
Simon Glass | 347c05b | 2013-02-28 19:26:15 +0000 | [diff] [blame] | 115 | dest_addr &= ~15; |
| 116 | } |
| 117 | #endif |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 118 | /* U-Boot is below the FDT */ |
| 119 | dest_addr -= uboot_size; |
| 120 | dest_addr &= ~((1 << 12) - 1); |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 121 | gd->relocaddr = dest_addr; |
Simon Glass | 3297d4d | 2013-02-28 19:26:10 +0000 | [diff] [blame] | 122 | gd->reloc_off = dest_addr - (uintptr_t)&__text_start; |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 123 | |
Gabe Black | 1311361 | 2012-11-03 11:41:24 +0000 | [diff] [blame] | 124 | /* Stack is at the bottom, so it can grow down */ |
| 125 | gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN; |
| 126 | |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Graeme Russ | 3fb4f9e | 2011-12-23 21:14:22 +1100 | [diff] [blame] | 130 | int init_cache_f_r(void) |
| 131 | { |
| 132 | /* Initialise the CPU cache(s) */ |
| 133 | return init_cache(); |
| 134 | } |
| 135 | |
| 136 | int set_reloc_flag_r(void) |
| 137 | { |
| 138 | gd->flags = GD_FLG_RELOC; |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 143 | int mem_malloc_init_r(void) |
| 144 | { |
| 145 | mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3, |
| 146 | CONFIG_SYS_MALLOC_LEN); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | bd_t bd_data; |
| 152 | |
| 153 | int init_bd_struct_r(void) |
| 154 | { |
| 155 | gd->bd = &bd_data; |
| 156 | memset(gd->bd, 0, sizeof(bd_t)); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | #ifndef CONFIG_SYS_NO_FLASH |
| 162 | int flash_init_r(void) |
| 163 | { |
| 164 | ulong size; |
| 165 | |
| 166 | puts("Flash: "); |
| 167 | |
| 168 | /* configure available FLASH banks */ |
| 169 | size = flash_init(); |
| 170 | |
| 171 | print_size(size, "\n"); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | #endif |
| 176 | |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 177 | #ifdef CONFIG_STATUS_LED |
| 178 | int status_led_set_r(void) |
| 179 | { |
| 180 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | #endif |
| 185 | |
Graeme Russ | a875dda | 2011-12-23 16:51:29 +1100 | [diff] [blame] | 186 | int set_load_addr_r(void) |
| 187 | { |
| 188 | /* Initialize from environment */ |
| 189 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
| 190 | |
| 191 | return 0; |
| 192 | } |
Gabe Black | a97cbda | 2012-11-03 11:41:23 +0000 | [diff] [blame] | 193 | |
| 194 | int init_func_spi(void) |
| 195 | { |
| 196 | puts("SPI: "); |
| 197 | spi_init(); |
| 198 | puts("ready\n"); |
| 199 | return 0; |
| 200 | } |
Gabe Black | 050a4c6 | 2012-11-03 11:41:30 +0000 | [diff] [blame] | 201 | |
| 202 | #ifdef CONFIG_OF_CONTROL |
| 203 | int find_fdt(void) |
| 204 | { |
| 205 | #ifdef CONFIG_OF_EMBED |
| 206 | /* Get a pointer to the FDT */ |
| 207 | gd->fdt_blob = _binary_dt_dtb_start; |
| 208 | #elif defined CONFIG_OF_SEPARATE |
| 209 | /* FDT is at end of image */ |
Simon Glass | 781db8c | 2013-02-28 19:26:13 +0000 | [diff] [blame] | 210 | gd->fdt_blob = (ulong *)&_end; |
Gabe Black | 050a4c6 | 2012-11-03 11:41:30 +0000 | [diff] [blame] | 211 | #endif |
| 212 | /* Allow the early environment to override the fdt address */ |
| 213 | gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16, |
| 214 | (uintptr_t)gd->fdt_blob); |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | int prepare_fdt(void) |
| 220 | { |
| 221 | /* For now, put this check after the console is ready */ |
| 222 | if (fdtdec_prepare_fdt()) { |
| 223 | panic("** CONFIG_OF_CONTROL defined but no FDT - please see " |
| 224 | "doc/README.fdt-control"); |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | #endif |