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