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> 25 #include <fdtdec.h> 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> 32 #include <spi.h> 33 #include <status_led.h> 34 #include <asm/processor.h> 35 #include <asm/u-boot-x86.h> 36 #include <linux/compiler.h> 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 77 /* Get the top of usable RAM */ 78 __weak ulong board_get_usable_ram_top(ulong total_size) 79 { 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; 88 ulong dest_addr; 89 ulong fdt_size = 0; 90 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 95 total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN + 96 CONFIG_SYS_STACK_SIZE + fdt_size; 97 98 dest_addr = board_get_usable_ram_top(total_size); 99 /* 100 * NOTE: All destination address are rounded down to 16-byte 101 * boundary to satisfy various worst-case alignment 102 * requirements 103 */ 104 dest_addr &= ~15; 105 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; 114 gd->arch.new_fdt = (void *)dest_addr; 115 dest_addr &= ~15; 116 } 117 #endif 118 /* U-Boot is below the FDT */ 119 dest_addr -= uboot_size; 120 dest_addr &= ~((1 << 12) - 1); 121 gd->relocaddr = dest_addr; 122 gd->reloc_off = dest_addr - (uintptr_t)&__text_start; 123 124 /* Stack is at the bottom, so it can grow down */ 125 gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN; 126 127 return 0; 128 } 129 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 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 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 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 } 193 194 int init_func_spi(void) 195 { 196 puts("SPI: "); 197 spi_init(); 198 puts("ready\n"); 199 return 0; 200 } 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 */ 210 gd->fdt_blob = (ulong *)&_end; 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 230