blob: 7df9536a4788906230a1d2f525e016d456144b74 [file] [log] [blame]
Graeme Russa875dda2011-12-23 16:51:29 +11001/*
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 Glass347c05b2013-02-28 19:26:15 +000025#include <fdtdec.h>
Graeme Russa875dda2011-12-23 16:51:29 +110026#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 Blacka97cbda2012-11-03 11:41:23 +000032#include <spi.h>
Graeme Russa875dda2011-12-23 16:51:29 +110033#include <status_led.h>
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110034#include <asm/processor.h>
Graeme Russa875dda2011-12-23 16:51:29 +110035#include <asm/u-boot-x86.h>
Gabe Blackb841abf2012-11-03 11:41:26 +000036#include <linux/compiler.h>
Graeme Russa875dda2011-12-23 16:51:29 +110037
38#include <asm/init_helpers.h>
39
40DECLARE_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
50int display_banner(void)
51{
52 printf("\n\n%s\n\n", version_string);
53
54 return 0;
55}
56
57int 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
71int init_baudrate_f(void)
72{
73 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
74 return 0;
75}
76
Simon Glass3297d4d2013-02-28 19:26:10 +000077/* Get the top of usable RAM */
78__weak ulong board_get_usable_ram_top(ulong total_size)
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110079{
Simon Glass3297d4d2013-02-28 19:26:10 +000080 return gd->ram_size;
81}
82
83int calculate_relocation_address(void)
84{
85 const ulong uboot_size = (uintptr_t)&__bss_end -
86 (uintptr_t)&__text_start;
87 ulong total_size;
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110088 ulong dest_addr;
Simon Glass347c05b2013-02-28 19:26:15 +000089 ulong fdt_size = 0;
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110090
Simon Glass347c05b2013-02-28 19:26:15 +000091#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 Glass3297d4d2013-02-28 19:26:10 +000095 total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
Simon Glass347c05b2013-02-28 19:26:15 +000096 CONFIG_SYS_STACK_SIZE + fdt_size;
Simon Glass3297d4d2013-02-28 19:26:10 +000097
Simon Glass347c05b2013-02-28 19:26:15 +000098 dest_addr = board_get_usable_ram_top(total_size);
Graeme Russ3fb4f9e2011-12-23 21:14:22 +110099 /*
100 * NOTE: All destination address are rounded down to 16-byte
101 * boundary to satisfy various worst-case alignment
102 * requirements
103 */
Simon Glass347c05b2013-02-28 19:26:15 +0000104 dest_addr &= ~15;
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100105
Simon Glass347c05b2013-02-28 19:26:15 +0000106#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 Glassc45e3592013-03-11 06:49:53 +0000114 gd->new_fdt = (void *)dest_addr;
Simon Glass347c05b2013-02-28 19:26:15 +0000115 dest_addr &= ~15;
116 }
117#endif
Simon Glass3297d4d2013-02-28 19:26:10 +0000118 /* U-Boot is below the FDT */
119 dest_addr -= uboot_size;
120 dest_addr &= ~((1 << 12) - 1);
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100121 gd->relocaddr = dest_addr;
Simon Glass3297d4d2013-02-28 19:26:10 +0000122 gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100123
Gabe Black13113612012-11-03 11:41:24 +0000124 /* Stack is at the bottom, so it can grow down */
125 gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
126
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100127 return 0;
128}
129
Graeme Russ3fb4f9e2011-12-23 21:14:22 +1100130int init_cache_f_r(void)
131{
132 /* Initialise the CPU cache(s) */
133 return init_cache();
134}
135
136int set_reloc_flag_r(void)
137{
138 gd->flags = GD_FLG_RELOC;
139
140 return 0;
141}
142
Graeme Russa875dda2011-12-23 16:51:29 +1100143int 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
151bd_t bd_data;
152
153int 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
162int 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 Russa875dda2011-12-23 16:51:29 +1100177#ifdef CONFIG_STATUS_LED
178int 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 Russa875dda2011-12-23 16:51:29 +1100186int 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 Blacka97cbda2012-11-03 11:41:23 +0000193
194int init_func_spi(void)
195{
196 puts("SPI: ");
197 spi_init();
198 puts("ready\n");
199 return 0;
200}
Gabe Black050a4c62012-11-03 11:41:30 +0000201
202#ifdef CONFIG_OF_CONTROL
203int 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 Glass781db8c2013-02-28 19:26:13 +0000210 gd->fdt_blob = (ulong *)&_end;
Gabe Black050a4c62012-11-03 11:41:30 +0000211#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
219int 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