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