xref: /openbmc/u-boot/arch/x86/lib/init_helpers.c (revision e874d5b0)
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>
31 #include <spi.h>
32 #include <status_led.h>
33 #include <asm/processor.h>
34 #include <asm/u-boot-x86.h>
35 #include <linux/compiler.h>
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 
76 __weak int calculate_relocation_address(void)
77 {
78 	ulong text_start = (ulong)&__text_start;
79 	ulong bss_end = (ulong)&__bss_end;
80 	ulong dest_addr;
81 
82 	/*
83 	 * NOTE: All destination address are rounded down to 16-byte
84 	 *       boundary to satisfy various worst-case alignment
85 	 *       requirements
86 	 */
87 
88 	/* Stack is at top of available memory */
89 	dest_addr = gd->ram_size;
90 
91 	/* U-Boot is at the top */
92 	dest_addr -= (bss_end - text_start);
93 	dest_addr &= ~15;
94 	gd->relocaddr = dest_addr;
95 	gd->reloc_off = (dest_addr - text_start);
96 
97 	/* Stack is at the bottom, so it can grow down */
98 	gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
99 
100 	return 0;
101 }
102 
103 int init_cache_f_r(void)
104 {
105 	/* Initialise the CPU cache(s) */
106 	return init_cache();
107 }
108 
109 int set_reloc_flag_r(void)
110 {
111 	gd->flags = GD_FLG_RELOC;
112 
113 	return 0;
114 }
115 
116 int mem_malloc_init_r(void)
117 {
118 	mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
119 			CONFIG_SYS_MALLOC_LEN);
120 
121 	return 0;
122 }
123 
124 bd_t bd_data;
125 
126 int init_bd_struct_r(void)
127 {
128 	gd->bd = &bd_data;
129 	memset(gd->bd, 0, sizeof(bd_t));
130 
131 	return 0;
132 }
133 
134 #ifndef CONFIG_SYS_NO_FLASH
135 int flash_init_r(void)
136 {
137 	ulong size;
138 
139 	puts("Flash: ");
140 
141 	/* configure available FLASH banks */
142 	size = flash_init();
143 
144 	print_size(size, "\n");
145 
146 	return 0;
147 }
148 #endif
149 
150 #ifdef CONFIG_STATUS_LED
151 int status_led_set_r(void)
152 {
153 	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
154 
155 	return 0;
156 }
157 #endif
158 
159 int set_load_addr_r(void)
160 {
161 	/* Initialize from environment */
162 	load_addr = getenv_ulong("loadaddr", 16, load_addr);
163 
164 	return 0;
165 }
166 
167 int init_func_spi(void)
168 {
169 	puts("SPI:   ");
170 	spi_init();
171 	puts("ready\n");
172 	return 0;
173 }
174 
175 #ifdef CONFIG_OF_CONTROL
176 int find_fdt(void)
177 {
178 #ifdef CONFIG_OF_EMBED
179 	/* Get a pointer to the FDT */
180 	gd->fdt_blob = _binary_dt_dtb_start;
181 #elif defined CONFIG_OF_SEPARATE
182 	/* FDT is at end of image */
183 	gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);
184 #endif
185 	/* Allow the early environment to override the fdt address */
186 	gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
187 						(uintptr_t)gd->fdt_blob);
188 
189 	return 0;
190 }
191 
192 int prepare_fdt(void)
193 {
194 	/* For now, put this check after the console is ready */
195 	if (fdtdec_prepare_fdt()) {
196 		panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
197 			"doc/README.fdt-control");
198 	}
199 
200 	return 0;
201 }
202 #endif
203