]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/x86/lib/init_helpers.c
9ec34ff992baec321687243d25b9b11da4ee51c6
[karo-tx-uboot.git] / arch / x86 / lib / init_helpers.c
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 <status_led.h>
32 #include <asm/processor.h>
33 #include <asm/u-boot-x86.h>
34
35 #include <asm/init_helpers.h>
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 /************************************************************************
40  * Init Utilities                                                       *
41  ************************************************************************
42  * Some of this code should be moved into the core functions,
43  * or dropped completely,
44  * but let's get it working (again) first...
45  */
46
47 int display_banner(void)
48 {
49         printf("\n\n%s\n\n", version_string);
50
51         return 0;
52 }
53
54 int display_dram_config(void)
55 {
56         int i;
57
58         puts("DRAM Configuration:\n");
59
60         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
61                 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
62                 print_size(gd->bd->bi_dram[i].size, "\n");
63         }
64
65         return 0;
66 }
67
68 int init_baudrate_f(void)
69 {
70         gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
71         return 0;
72 }
73
74 int calculate_relocation_address(void)
75 {
76         ulong text_start = (ulong)&__text_start;
77         ulong bss_end = (ulong)&__bss_end;
78         ulong dest_addr;
79
80         /*
81          * NOTE: All destination address are rounded down to 16-byte
82          *       boundary to satisfy various worst-case alignment
83          *       requirements
84          */
85
86         /* Global Data is at top of available memory */
87         dest_addr = gd->ram_size;
88         dest_addr -= GENERATED_GBL_DATA_SIZE;
89         dest_addr &= ~15;
90         gd->new_gd_addr = dest_addr;
91
92         /* GDT is below Global Data */
93         dest_addr -= X86_GDT_SIZE;
94         dest_addr &= ~15;
95         gd->gdt_addr = dest_addr;
96
97         /* Stack is below GDT */
98         gd->start_addr_sp = dest_addr;
99
100         /* U-Boot is below the stack */
101         dest_addr -= CONFIG_SYS_STACK_SIZE;
102         dest_addr -= (bss_end - text_start);
103         dest_addr &= ~15;
104         gd->relocaddr = dest_addr;
105         gd->reloc_off = (dest_addr - text_start);
106
107         return 0;
108 }
109
110 int copy_gd_to_ram_f_r(void)
111 {
112         gd_t *ram_gd;
113
114         /*
115          * Global data is still in temporary memory (the CPU cache).
116          * calculate_relocation_address() has set gd->new_gd_addr to
117          * where the global data lives in RAM but getting it there
118          * safely is a bit tricky due to the 'F-Segment Hack' that
119          * we need to use for x86
120          */
121         ram_gd = (gd_t *)gd->new_gd_addr;
122         memcpy((void *)ram_gd, gd, sizeof(gd_t));
123
124         /*
125          * Reload the Global Descriptor Table so FS points to the
126          * in-RAM copy of Global Data (calculate_relocation_address()
127          * has already calculated the in-RAM location of the GDT)
128          */
129         ram_gd->gd_addr = (ulong)ram_gd;
130         init_gd(ram_gd, (u64 *)gd->gdt_addr);
131
132         return 0;
133 }
134
135 int init_cache_f_r(void)
136 {
137         /* Initialise the CPU cache(s) */
138         return init_cache();
139 }
140
141 int set_reloc_flag_r(void)
142 {
143         gd->flags = GD_FLG_RELOC;
144
145         return 0;
146 }
147
148 int mem_malloc_init_r(void)
149 {
150         mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
151                         CONFIG_SYS_MALLOC_LEN);
152
153         return 0;
154 }
155
156 bd_t bd_data;
157
158 int init_bd_struct_r(void)
159 {
160         gd->bd = &bd_data;
161         memset(gd->bd, 0, sizeof(bd_t));
162
163         return 0;
164 }
165
166 #ifndef CONFIG_SYS_NO_FLASH
167 int flash_init_r(void)
168 {
169         ulong size;
170
171         puts("Flash: ");
172
173         /* configure available FLASH banks */
174         size = flash_init();
175
176         print_size(size, "\n");
177
178         return 0;
179 }
180 #endif
181
182 #ifdef CONFIG_STATUS_LED
183 int status_led_set_r(void)
184 {
185         status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
186
187         return 0;
188 }
189 #endif
190
191 int set_load_addr_r(void)
192 {
193         /* Initialize from environment */
194         load_addr = getenv_ulong("loadaddr", 16, load_addr);
195
196         return 0;
197 }