xref: /openbmc/u-boot/arch/x86/lib/init_helpers.c (revision 8313315b)
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 
36 #include <asm/init_helpers.h>
37 
38 DECLARE_GLOBAL_DATA_PTR;
39 
40 /************************************************************************
41  * Init Utilities							*
42  ************************************************************************
43  * Some of this code should be moved into the core functions,
44  * or dropped completely,
45  * but let's get it working (again) first...
46  */
47 
48 int display_banner(void)
49 {
50 	printf("\n\n%s\n\n", version_string);
51 
52 	return 0;
53 }
54 
55 int display_dram_config(void)
56 {
57 	int i;
58 
59 	puts("DRAM Configuration:\n");
60 
61 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
62 		printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
63 		print_size(gd->bd->bi_dram[i].size, "\n");
64 	}
65 
66 	return 0;
67 }
68 
69 int init_baudrate_f(void)
70 {
71 	gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
72 	return 0;
73 }
74 
75 int calculate_relocation_address(void)
76 {
77 	ulong text_start = (ulong)&__text_start;
78 	ulong bss_end = (ulong)&__bss_end;
79 	ulong dest_addr;
80 
81 	/*
82 	 * NOTE: All destination address are rounded down to 16-byte
83 	 *       boundary to satisfy various worst-case alignment
84 	 *       requirements
85 	 */
86 
87 	/* Stack is at top of available memory */
88 	dest_addr = gd->ram_size;
89 	gd->start_addr_sp = dest_addr;
90 
91 	/* U-Boot is below the stack */
92 	dest_addr -= CONFIG_SYS_STACK_SIZE;
93 	dest_addr -= (bss_end - text_start);
94 	dest_addr &= ~15;
95 	gd->relocaddr = dest_addr;
96 	gd->reloc_off = (dest_addr - text_start);
97 
98 	return 0;
99 }
100 
101 int init_cache_f_r(void)
102 {
103 	/* Initialise the CPU cache(s) */
104 	return init_cache();
105 }
106 
107 int set_reloc_flag_r(void)
108 {
109 	gd->flags = GD_FLG_RELOC;
110 
111 	return 0;
112 }
113 
114 int mem_malloc_init_r(void)
115 {
116 	mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
117 			CONFIG_SYS_MALLOC_LEN);
118 
119 	return 0;
120 }
121 
122 bd_t bd_data;
123 
124 int init_bd_struct_r(void)
125 {
126 	gd->bd = &bd_data;
127 	memset(gd->bd, 0, sizeof(bd_t));
128 
129 	return 0;
130 }
131 
132 #ifndef CONFIG_SYS_NO_FLASH
133 int flash_init_r(void)
134 {
135 	ulong size;
136 
137 	puts("Flash: ");
138 
139 	/* configure available FLASH banks */
140 	size = flash_init();
141 
142 	print_size(size, "\n");
143 
144 	return 0;
145 }
146 #endif
147 
148 #ifdef CONFIG_STATUS_LED
149 int status_led_set_r(void)
150 {
151 	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
152 
153 	return 0;
154 }
155 #endif
156 
157 int set_load_addr_r(void)
158 {
159 	/* Initialize from environment */
160 	load_addr = getenv_ulong("loadaddr", 16, load_addr);
161 
162 	return 0;
163 }
164 
165 int init_func_spi(void)
166 {
167 	puts("SPI:   ");
168 	spi_init();
169 	puts("ready\n");
170 	return 0;
171 }
172