1d47ab0ecSGraeme Russ /* 2d47ab0ecSGraeme Russ * (C) Copyright 2011 3d47ab0ecSGraeme Russ * Graeme Russ, <graeme.russ@gmail.com> 4d47ab0ecSGraeme Russ * 5d47ab0ecSGraeme Russ * See file CREDITS for list of people who contributed to this 6d47ab0ecSGraeme Russ * project. 7d47ab0ecSGraeme Russ * 8d47ab0ecSGraeme Russ * This program is free software; you can redistribute it and/or 9d47ab0ecSGraeme Russ * modify it under the terms of the GNU General Public License as 10d47ab0ecSGraeme Russ * published by the Free Software Foundation; either version 2 of 11d47ab0ecSGraeme Russ * the License, or (at your option) any later version. 12d47ab0ecSGraeme Russ * 13d47ab0ecSGraeme Russ * This program is distributed in the hope that it will be useful, 14d47ab0ecSGraeme Russ * but WITHOUT ANY WARRANTY; without even the implied warranty of 15d47ab0ecSGraeme Russ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16d47ab0ecSGraeme Russ * GNU General Public License for more details. 17d47ab0ecSGraeme Russ * 18d47ab0ecSGraeme Russ * You should have received a copy of the GNU General Public License 19d47ab0ecSGraeme Russ * along with this program; if not, write to the Free Software 20d47ab0ecSGraeme Russ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21d47ab0ecSGraeme Russ * MA 02111-1307 USA 22d47ab0ecSGraeme Russ */ 23d47ab0ecSGraeme Russ #include <common.h> 24d47ab0ecSGraeme Russ #include <command.h> 25d47ab0ecSGraeme Russ #include <stdio_dev.h> 26d47ab0ecSGraeme Russ #include <version.h> 27d47ab0ecSGraeme Russ #include <malloc.h> 28d47ab0ecSGraeme Russ #include <net.h> 29d47ab0ecSGraeme Russ #include <ide.h> 30d47ab0ecSGraeme Russ #include <serial.h> 31d47ab0ecSGraeme Russ #include <status_led.h> 32a1d57b7aSGraeme Russ #include <asm/processor.h> 33d47ab0ecSGraeme Russ #include <asm/u-boot-x86.h> 34d47ab0ecSGraeme Russ 35d47ab0ecSGraeme Russ #include <asm/init_helpers.h> 36d47ab0ecSGraeme Russ 37d47ab0ecSGraeme Russ DECLARE_GLOBAL_DATA_PTR; 38d47ab0ecSGraeme Russ 39d47ab0ecSGraeme Russ /************************************************************************ 40d47ab0ecSGraeme Russ * Init Utilities * 41d47ab0ecSGraeme Russ ************************************************************************ 42d47ab0ecSGraeme Russ * Some of this code should be moved into the core functions, 43d47ab0ecSGraeme Russ * or dropped completely, 44d47ab0ecSGraeme Russ * but let's get it working (again) first... 45d47ab0ecSGraeme Russ */ 46d47ab0ecSGraeme Russ 47d47ab0ecSGraeme Russ int display_banner(void) 48d47ab0ecSGraeme Russ { 49d47ab0ecSGraeme Russ printf("\n\n%s\n\n", version_string); 50d47ab0ecSGraeme Russ 51d47ab0ecSGraeme Russ return 0; 52d47ab0ecSGraeme Russ } 53d47ab0ecSGraeme Russ 54d47ab0ecSGraeme Russ int display_dram_config(void) 55d47ab0ecSGraeme Russ { 56d47ab0ecSGraeme Russ int i; 57d47ab0ecSGraeme Russ 58d47ab0ecSGraeme Russ puts("DRAM Configuration:\n"); 59d47ab0ecSGraeme Russ 60d47ab0ecSGraeme Russ for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 61d47ab0ecSGraeme Russ printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); 62d47ab0ecSGraeme Russ print_size(gd->bd->bi_dram[i].size, "\n"); 63d47ab0ecSGraeme Russ } 64d47ab0ecSGraeme Russ 65d47ab0ecSGraeme Russ return 0; 66d47ab0ecSGraeme Russ } 67d47ab0ecSGraeme Russ 68d47ab0ecSGraeme Russ int init_baudrate_f(void) 69d47ab0ecSGraeme Russ { 70d47ab0ecSGraeme Russ gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); 71d47ab0ecSGraeme Russ return 0; 72d47ab0ecSGraeme Russ } 73d47ab0ecSGraeme Russ 74a1d57b7aSGraeme Russ int calculate_relocation_address(void) 75a1d57b7aSGraeme Russ { 76a1d57b7aSGraeme Russ ulong text_start = (ulong)&__text_start; 77a1d57b7aSGraeme Russ ulong bss_end = (ulong)&__bss_end; 78a1d57b7aSGraeme Russ ulong dest_addr; 79a1d57b7aSGraeme Russ 80a1d57b7aSGraeme Russ /* 81a1d57b7aSGraeme Russ * NOTE: All destination address are rounded down to 16-byte 82a1d57b7aSGraeme Russ * boundary to satisfy various worst-case alignment 83a1d57b7aSGraeme Russ * requirements 84a1d57b7aSGraeme Russ */ 85a1d57b7aSGraeme Russ 86*8d61625dSGraeme Russ /* Stack is at top of available memory */ 87a1d57b7aSGraeme Russ dest_addr = gd->ram_size; 88a1d57b7aSGraeme Russ gd->start_addr_sp = dest_addr; 89a1d57b7aSGraeme Russ 90a1d57b7aSGraeme Russ /* U-Boot is below the stack */ 91a1d57b7aSGraeme Russ dest_addr -= CONFIG_SYS_STACK_SIZE; 92a1d57b7aSGraeme Russ dest_addr -= (bss_end - text_start); 93a1d57b7aSGraeme Russ dest_addr &= ~15; 94a1d57b7aSGraeme Russ gd->relocaddr = dest_addr; 95a1d57b7aSGraeme Russ gd->reloc_off = (dest_addr - text_start); 96a1d57b7aSGraeme Russ 97a1d57b7aSGraeme Russ return 0; 98a1d57b7aSGraeme Russ } 99a1d57b7aSGraeme Russ 100a1d57b7aSGraeme Russ int init_cache_f_r(void) 101a1d57b7aSGraeme Russ { 102a1d57b7aSGraeme Russ /* Initialise the CPU cache(s) */ 103a1d57b7aSGraeme Russ return init_cache(); 104a1d57b7aSGraeme Russ } 105a1d57b7aSGraeme Russ 106a1d57b7aSGraeme Russ int set_reloc_flag_r(void) 107a1d57b7aSGraeme Russ { 108a1d57b7aSGraeme Russ gd->flags = GD_FLG_RELOC; 109a1d57b7aSGraeme Russ 110a1d57b7aSGraeme Russ return 0; 111a1d57b7aSGraeme Russ } 112a1d57b7aSGraeme Russ 113d47ab0ecSGraeme Russ int mem_malloc_init_r(void) 114d47ab0ecSGraeme Russ { 115d47ab0ecSGraeme Russ mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3, 116d47ab0ecSGraeme Russ CONFIG_SYS_MALLOC_LEN); 117d47ab0ecSGraeme Russ 118d47ab0ecSGraeme Russ return 0; 119d47ab0ecSGraeme Russ } 120d47ab0ecSGraeme Russ 121d47ab0ecSGraeme Russ bd_t bd_data; 122d47ab0ecSGraeme Russ 123d47ab0ecSGraeme Russ int init_bd_struct_r(void) 124d47ab0ecSGraeme Russ { 125d47ab0ecSGraeme Russ gd->bd = &bd_data; 126d47ab0ecSGraeme Russ memset(gd->bd, 0, sizeof(bd_t)); 127d47ab0ecSGraeme Russ 128d47ab0ecSGraeme Russ return 0; 129d47ab0ecSGraeme Russ } 130d47ab0ecSGraeme Russ 131d47ab0ecSGraeme Russ #ifndef CONFIG_SYS_NO_FLASH 132d47ab0ecSGraeme Russ int flash_init_r(void) 133d47ab0ecSGraeme Russ { 134d47ab0ecSGraeme Russ ulong size; 135d47ab0ecSGraeme Russ 136d47ab0ecSGraeme Russ puts("Flash: "); 137d47ab0ecSGraeme Russ 138d47ab0ecSGraeme Russ /* configure available FLASH banks */ 139d47ab0ecSGraeme Russ size = flash_init(); 140d47ab0ecSGraeme Russ 141d47ab0ecSGraeme Russ print_size(size, "\n"); 142d47ab0ecSGraeme Russ 143d47ab0ecSGraeme Russ return 0; 144d47ab0ecSGraeme Russ } 145d47ab0ecSGraeme Russ #endif 146d47ab0ecSGraeme Russ 147d47ab0ecSGraeme Russ #ifdef CONFIG_STATUS_LED 148d47ab0ecSGraeme Russ int status_led_set_r(void) 149d47ab0ecSGraeme Russ { 150d47ab0ecSGraeme Russ status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); 151d47ab0ecSGraeme Russ 152d47ab0ecSGraeme Russ return 0; 153d47ab0ecSGraeme Russ } 154d47ab0ecSGraeme Russ #endif 155d47ab0ecSGraeme Russ 156d47ab0ecSGraeme Russ int set_load_addr_r(void) 157d47ab0ecSGraeme Russ { 158d47ab0ecSGraeme Russ /* Initialize from environment */ 159d47ab0ecSGraeme Russ load_addr = getenv_ulong("loadaddr", 16, load_addr); 160d47ab0ecSGraeme Russ 161d47ab0ecSGraeme Russ return 0; 162d47ab0ecSGraeme Russ } 163