]>
Commit | Line | Data |
---|---|---|
1938f4a5 SG |
1 | /* |
2 | * Copyright (c) 2011 The Chromium OS Authors. | |
3 | * (C) Copyright 2002-2006 | |
4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
5 | * | |
6 | * (C) Copyright 2002 | |
7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
8 | * Marius Groeger <[email protected]> | |
9 | * | |
1a459660 | 10 | * SPDX-License-Identifier: GPL-2.0+ |
1938f4a5 SG |
11 | */ |
12 | ||
13 | #include <common.h> | |
14 | #include <linux/compiler.h> | |
15 | #include <version.h> | |
24b852a7 | 16 | #include <console.h> |
1938f4a5 | 17 | #include <environment.h> |
ab7cd627 | 18 | #include <dm.h> |
1938f4a5 | 19 | #include <fdtdec.h> |
f828bf25 | 20 | #include <fs.h> |
e4fef6cf SG |
21 | #if defined(CONFIG_CMD_IDE) |
22 | #include <ide.h> | |
23 | #endif | |
24 | #include <i2c.h> | |
1938f4a5 SG |
25 | #include <initcall.h> |
26 | #include <logbuff.h> | |
fb5cf7f1 | 27 | #include <malloc.h> |
0eb25b61 | 28 | #include <mapmem.h> |
e4fef6cf SG |
29 | |
30 | /* TODO: Can we move these into arch/ headers? */ | |
31 | #ifdef CONFIG_8xx | |
32 | #include <mpc8xx.h> | |
33 | #endif | |
34 | #ifdef CONFIG_5xx | |
35 | #include <mpc5xx.h> | |
36 | #endif | |
37 | #ifdef CONFIG_MPC5xxx | |
38 | #include <mpc5xxx.h> | |
39 | #endif | |
ec3b4820 | 40 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) |
a76df709 GH |
41 | #include <asm/mp.h> |
42 | #endif | |
e4fef6cf | 43 | |
a733b06b | 44 | #include <os.h> |
1938f4a5 | 45 | #include <post.h> |
e4fef6cf | 46 | #include <spi.h> |
c5d4001a | 47 | #include <status_led.h> |
1057e6cf | 48 | #include <timer.h> |
71c52dba | 49 | #include <trace.h> |
5a541945 | 50 | #include <video.h> |
e4fef6cf | 51 | #include <watchdog.h> |
1221ce45 | 52 | #include <linux/errno.h> |
1938f4a5 SG |
53 | #include <asm/io.h> |
54 | #include <asm/sections.h> | |
3fb80163 | 55 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
48a33806 | 56 | #include <asm/init_helpers.h> |
de5e5cea CZ |
57 | #endif |
58 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA) | |
48a33806 SG |
59 | #include <asm/relocate.h> |
60 | #endif | |
a733b06b SG |
61 | #ifdef CONFIG_SANDBOX |
62 | #include <asm/state.h> | |
63 | #endif | |
ab7cd627 | 64 | #include <dm/root.h> |
1938f4a5 SG |
65 | #include <linux/compiler.h> |
66 | ||
67 | /* | |
68 | * Pointer to initial global data area | |
69 | * | |
70 | * Here we initialize it if needed. | |
71 | */ | |
72 | #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR | |
73 | #undef XTRN_DECLARE_GLOBAL_DATA_PTR | |
74 | #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ | |
75 | DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); | |
76 | #else | |
77 | DECLARE_GLOBAL_DATA_PTR; | |
78 | #endif | |
79 | ||
80 | /* | |
4c509343 | 81 | * TODO([email protected]): IMO this code should be |
1938f4a5 SG |
82 | * refactored to a single function, something like: |
83 | * | |
84 | * void led_set_state(enum led_colour_t colour, int on); | |
85 | */ | |
86 | /************************************************************************ | |
87 | * Coloured LED functionality | |
88 | ************************************************************************ | |
89 | * May be supplied by boards if desired | |
90 | */ | |
c5d4001a JH |
91 | __weak void coloured_LED_init(void) {} |
92 | __weak void red_led_on(void) {} | |
93 | __weak void red_led_off(void) {} | |
94 | __weak void green_led_on(void) {} | |
95 | __weak void green_led_off(void) {} | |
96 | __weak void yellow_led_on(void) {} | |
97 | __weak void yellow_led_off(void) {} | |
98 | __weak void blue_led_on(void) {} | |
99 | __weak void blue_led_off(void) {} | |
1938f4a5 SG |
100 | |
101 | /* | |
102 | * Why is gd allocated a register? Prior to reloc it might be better to | |
103 | * just pass it around to each function in this file? | |
104 | * | |
105 | * After reloc one could argue that it is hardly used and doesn't need | |
106 | * to be in a register. Or if it is it should perhaps hold pointers to all | |
107 | * global data for all modules, so that post-reloc we can avoid the massive | |
108 | * literal pool we get on ARM. Or perhaps just encourage each module to use | |
109 | * a structure... | |
110 | */ | |
111 | ||
112 | /* | |
113 | * Could the CONFIG_SPL_BUILD infection become a flag in gd? | |
114 | */ | |
115 | ||
d54d7eb9 | 116 | #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) |
e4fef6cf SG |
117 | static int init_func_watchdog_init(void) |
118 | { | |
d54d7eb9 SZ |
119 | # if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \ |
120 | defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ | |
14a380a8 | 121 | defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \ |
46d7a3b3 | 122 | defined(CONFIG_DESIGNWARE_WATCHDOG) || \ |
14a380a8 | 123 | defined(CONFIG_IMX_WATCHDOG)) |
d54d7eb9 | 124 | hw_watchdog_init(); |
e4fef6cf | 125 | puts(" Watchdog enabled\n"); |
ba169d98 | 126 | # endif |
e4fef6cf SG |
127 | WATCHDOG_RESET(); |
128 | ||
129 | return 0; | |
130 | } | |
131 | ||
132 | int init_func_watchdog_reset(void) | |
133 | { | |
134 | WATCHDOG_RESET(); | |
135 | ||
136 | return 0; | |
137 | } | |
138 | #endif /* CONFIG_WATCHDOG */ | |
139 | ||
dd2a6cd0 | 140 | __weak void board_add_ram_info(int use_default) |
e4fef6cf SG |
141 | { |
142 | /* please define platform specific board_add_ram_info() */ | |
143 | } | |
144 | ||
1938f4a5 SG |
145 | static int init_baud_rate(void) |
146 | { | |
147 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); | |
148 | return 0; | |
149 | } | |
150 | ||
151 | static int display_text_info(void) | |
152 | { | |
9b217498 | 153 | #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP) |
9fdee7d7 | 154 | ulong bss_start, bss_end, text_base; |
1938f4a5 | 155 | |
632efa74 SG |
156 | bss_start = (ulong)&__bss_start; |
157 | bss_end = (ulong)&__bss_end; | |
b60eff31 | 158 | |
d54d7eb9 | 159 | #ifdef CONFIG_SYS_TEXT_BASE |
9fdee7d7 | 160 | text_base = CONFIG_SYS_TEXT_BASE; |
d54d7eb9 | 161 | #else |
9fdee7d7 | 162 | text_base = CONFIG_SYS_MONITOR_BASE; |
d54d7eb9 | 163 | #endif |
9fdee7d7 DS |
164 | |
165 | debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", | |
166 | text_base, bss_start, bss_end); | |
a733b06b | 167 | #endif |
1938f4a5 | 168 | |
1938f4a5 SG |
169 | #ifdef CONFIG_USE_IRQ |
170 | debug("IRQ Stack: %08lx\n", IRQ_STACK_START); | |
171 | debug("FIQ Stack: %08lx\n", FIQ_STACK_START); | |
172 | #endif | |
173 | ||
174 | return 0; | |
175 | } | |
176 | ||
177 | static int announce_dram_init(void) | |
178 | { | |
179 | puts("DRAM: "); | |
180 | return 0; | |
181 | } | |
182 | ||
e310b93e | 183 | #if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) |
e4fef6cf SG |
184 | static int init_func_ram(void) |
185 | { | |
186 | #ifdef CONFIG_BOARD_TYPES | |
187 | int board_type = gd->board_type; | |
188 | #else | |
189 | int board_type = 0; /* use dummy arg */ | |
190 | #endif | |
191 | ||
192 | gd->ram_size = initdram(board_type); | |
193 | ||
194 | if (gd->ram_size > 0) | |
195 | return 0; | |
196 | ||
197 | puts("*** failed ***\n"); | |
198 | return 1; | |
199 | } | |
200 | #endif | |
201 | ||
1938f4a5 SG |
202 | static int show_dram_config(void) |
203 | { | |
fa39ffe5 | 204 | unsigned long long size; |
1938f4a5 SG |
205 | |
206 | #ifdef CONFIG_NR_DRAM_BANKS | |
207 | int i; | |
208 | ||
209 | debug("\nRAM Configuration:\n"); | |
210 | for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) { | |
211 | size += gd->bd->bi_dram[i].size; | |
715f599f BM |
212 | debug("Bank #%d: %llx ", i, |
213 | (unsigned long long)(gd->bd->bi_dram[i].start)); | |
1938f4a5 SG |
214 | #ifdef DEBUG |
215 | print_size(gd->bd->bi_dram[i].size, "\n"); | |
216 | #endif | |
217 | } | |
218 | debug("\nDRAM: "); | |
219 | #else | |
220 | size = gd->ram_size; | |
221 | #endif | |
222 | ||
e4fef6cf SG |
223 | print_size(size, ""); |
224 | board_add_ram_info(0); | |
225 | putc('\n'); | |
1938f4a5 SG |
226 | |
227 | return 0; | |
228 | } | |
229 | ||
dd2a6cd0 | 230 | __weak void dram_init_banksize(void) |
1938f4a5 SG |
231 | { |
232 | #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) | |
233 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; | |
234 | gd->bd->bi_dram[0].size = get_effective_memsize(); | |
235 | #endif | |
236 | } | |
237 | ||
ea818dbb | 238 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) |
e4fef6cf SG |
239 | static int init_func_i2c(void) |
240 | { | |
241 | puts("I2C: "); | |
815a76f2 | 242 | #ifdef CONFIG_SYS_I2C |
243 | i2c_init_all(); | |
244 | #else | |
e4fef6cf | 245 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
815a76f2 | 246 | #endif |
e4fef6cf SG |
247 | puts("ready\n"); |
248 | return 0; | |
249 | } | |
250 | #endif | |
251 | ||
252 | #if defined(CONFIG_HARD_SPI) | |
253 | static int init_func_spi(void) | |
254 | { | |
255 | puts("SPI: "); | |
256 | spi_init(); | |
257 | puts("ready\n"); | |
258 | return 0; | |
259 | } | |
260 | #endif | |
261 | ||
262 | __maybe_unused | |
1938f4a5 SG |
263 | static int zero_global_data(void) |
264 | { | |
265 | memset((void *)gd, '\0', sizeof(gd_t)); | |
266 | ||
267 | return 0; | |
268 | } | |
269 | ||
270 | static int setup_mon_len(void) | |
271 | { | |
e945f6dc | 272 | #if defined(__ARM__) || defined(__MICROBLAZE__) |
b60eff31 | 273 | gd->mon_len = (ulong)&__bss_end - (ulong)_start; |
9b217498 | 274 | #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) |
a733b06b | 275 | gd->mon_len = (ulong)&_end - (ulong)_init; |
de5e5cea CZ |
276 | #elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2) || \ |
277 | defined(CONFIG_XTENSA) | |
d54d7eb9 | 278 | gd->mon_len = CONFIG_SYS_MONITOR_LEN; |
e2099d78 | 279 | #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) |
2e88bb28 | 280 | gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start); |
b0b35953 | 281 | #elif defined(CONFIG_SYS_MONITOR_BASE) |
e4fef6cf SG |
282 | /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ |
283 | gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; | |
632efa74 | 284 | #endif |
1938f4a5 SG |
285 | return 0; |
286 | } | |
287 | ||
288 | __weak int arch_cpu_init(void) | |
289 | { | |
290 | return 0; | |
291 | } | |
292 | ||
8ebf5069 PB |
293 | __weak int mach_cpu_init(void) |
294 | { | |
295 | return 0; | |
296 | } | |
297 | ||
a733b06b SG |
298 | #ifdef CONFIG_SANDBOX |
299 | static int setup_ram_buf(void) | |
300 | { | |
5c2859cd SG |
301 | struct sandbox_state *state = state_get_current(); |
302 | ||
303 | gd->arch.ram_buf = state->ram_buf; | |
304 | gd->ram_size = state->ram_size; | |
a733b06b SG |
305 | |
306 | return 0; | |
307 | } | |
308 | #endif | |
309 | ||
1938f4a5 SG |
310 | /* Get the top of usable RAM */ |
311 | __weak ulong board_get_usable_ram_top(ulong total_size) | |
312 | { | |
1e4d11a5 SW |
313 | #ifdef CONFIG_SYS_SDRAM_BASE |
314 | /* | |
4c509343 | 315 | * Detect whether we have so much RAM that it goes past the end of our |
1e4d11a5 SW |
316 | * 32-bit address space. If so, clip the usable RAM so it doesn't. |
317 | */ | |
318 | if (gd->ram_top < CONFIG_SYS_SDRAM_BASE) | |
319 | /* | |
320 | * Will wrap back to top of 32-bit space when reservations | |
321 | * are made. | |
322 | */ | |
323 | return 0; | |
324 | #endif | |
1938f4a5 SG |
325 | return gd->ram_top; |
326 | } | |
327 | ||
aabd7ddb YS |
328 | __weak phys_size_t board_reserve_ram_top(phys_size_t ram_size) |
329 | { | |
330 | #ifdef CONFIG_SYS_MEM_TOP_HIDE | |
331 | return ram_size - CONFIG_SYS_MEM_TOP_HIDE; | |
332 | #else | |
333 | return ram_size; | |
334 | #endif | |
335 | } | |
336 | ||
1938f4a5 SG |
337 | static int setup_dest_addr(void) |
338 | { | |
339 | debug("Monitor len: %08lX\n", gd->mon_len); | |
340 | /* | |
341 | * Ram is setup, size stored in gd !! | |
342 | */ | |
343 | debug("Ram size: %08lX\n", (ulong)gd->ram_size); | |
e8149522 YS |
344 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
345 | /* Reserve memory for secure MMU tables, and/or security monitor */ | |
346 | gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE; | |
347 | /* | |
348 | * Record secure memory location. Need recalcuate if memory splits | |
349 | * into banks, or the ram base is not zero. | |
350 | */ | |
e61a7534 | 351 | gd->arch.secure_ram = gd->ram_size; |
e8149522 | 352 | #endif |
1938f4a5 SG |
353 | /* |
354 | * Subtract specified amount of memory to hide so that it won't | |
355 | * get "touched" at all by U-Boot. By fixing up gd->ram_size | |
356 | * the Linux kernel should now get passed the now "corrected" | |
aabd7ddb YS |
357 | * memory size and won't touch it either. This has been used |
358 | * by arch/powerpc exclusively. Now ARMv8 takes advantage of | |
359 | * thie mechanism. If memory is split into banks, addresses | |
360 | * need to be calculated. | |
1938f4a5 | 361 | */ |
aabd7ddb YS |
362 | gd->ram_size = board_reserve_ram_top(gd->ram_size); |
363 | ||
1938f4a5 SG |
364 | #ifdef CONFIG_SYS_SDRAM_BASE |
365 | gd->ram_top = CONFIG_SYS_SDRAM_BASE; | |
366 | #endif | |
e4fef6cf | 367 | gd->ram_top += get_effective_memsize(); |
1938f4a5 | 368 | gd->ram_top = board_get_usable_ram_top(gd->mon_len); |
a0ba279a | 369 | gd->relocaddr = gd->ram_top; |
1938f4a5 | 370 | debug("Ram top: %08lX\n", (ulong)gd->ram_top); |
ec3b4820 | 371 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) |
e4fef6cf SG |
372 | /* |
373 | * We need to make sure the location we intend to put secondary core | |
374 | * boot code is reserved and not used by any part of u-boot | |
375 | */ | |
a0ba279a MY |
376 | if (gd->relocaddr > determine_mp_bootpg(NULL)) { |
377 | gd->relocaddr = determine_mp_bootpg(NULL); | |
378 | debug("Reserving MP boot page to %08lx\n", gd->relocaddr); | |
e4fef6cf SG |
379 | } |
380 | #endif | |
1938f4a5 SG |
381 | return 0; |
382 | } | |
383 | ||
1e85ccec FR |
384 | #if defined(CONFIG_SPARC) |
385 | static int reserve_prom(void) | |
386 | { | |
387 | /* defined in arch/sparc/cpu/leon?/prom.c */ | |
388 | extern void *__prom_start_reloc; | |
389 | int size = 8192; /* page table = 2k, prom = 6k */ | |
390 | gd->relocaddr -= size; | |
391 | __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048); | |
392 | debug("Reserving %dk for PROM and page table at %08lx\n", size, | |
393 | gd->relocaddr); | |
394 | return 0; | |
395 | } | |
396 | #endif | |
397 | ||
1938f4a5 SG |
398 | #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) |
399 | static int reserve_logbuffer(void) | |
400 | { | |
401 | /* reserve kernel log buffer */ | |
a0ba279a | 402 | gd->relocaddr -= LOGBUFF_RESERVE; |
1938f4a5 | 403 | debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, |
a0ba279a | 404 | gd->relocaddr); |
1938f4a5 SG |
405 | return 0; |
406 | } | |
407 | #endif | |
408 | ||
409 | #ifdef CONFIG_PRAM | |
410 | /* reserve protected RAM */ | |
411 | static int reserve_pram(void) | |
412 | { | |
413 | ulong reg; | |
414 | ||
415 | reg = getenv_ulong("pram", 10, CONFIG_PRAM); | |
a0ba279a | 416 | gd->relocaddr -= (reg << 10); /* size is in kB */ |
1938f4a5 | 417 | debug("Reserving %ldk for protected RAM at %08lx\n", reg, |
a0ba279a | 418 | gd->relocaddr); |
1938f4a5 SG |
419 | return 0; |
420 | } | |
421 | #endif /* CONFIG_PRAM */ | |
422 | ||
423 | /* Round memory pointer down to next 4 kB limit */ | |
424 | static int reserve_round_4k(void) | |
425 | { | |
a0ba279a | 426 | gd->relocaddr &= ~(4096 - 1); |
1938f4a5 SG |
427 | return 0; |
428 | } | |
429 | ||
430 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ | |
431 | defined(CONFIG_ARM) | |
432 | static int reserve_mmu(void) | |
433 | { | |
434 | /* reserve TLB table */ | |
cce6be7f | 435 | gd->arch.tlb_size = PGTABLE_SIZE; |
a0ba279a | 436 | gd->relocaddr -= gd->arch.tlb_size; |
1938f4a5 SG |
437 | |
438 | /* round down to next 64 kB limit */ | |
a0ba279a | 439 | gd->relocaddr &= ~(0x10000 - 1); |
1938f4a5 | 440 | |
a0ba279a | 441 | gd->arch.tlb_addr = gd->relocaddr; |
1938f4a5 SG |
442 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
443 | gd->arch.tlb_addr + gd->arch.tlb_size); | |
50e93b95 YS |
444 | |
445 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE | |
446 | /* | |
447 | * Record allocated tlb_addr in case gd->tlb_addr to be overwritten | |
448 | * with location within secure ram. | |
449 | */ | |
450 | gd->arch.tlb_allocated = gd->arch.tlb_addr; | |
451 | #endif | |
452 | ||
1938f4a5 SG |
453 | return 0; |
454 | } | |
455 | #endif | |
456 | ||
5a541945 SG |
457 | #ifdef CONFIG_DM_VIDEO |
458 | static int reserve_video(void) | |
459 | { | |
460 | ulong addr; | |
461 | int ret; | |
462 | ||
463 | addr = gd->relocaddr; | |
464 | ret = video_reserve(&addr); | |
465 | if (ret) | |
466 | return ret; | |
467 | gd->relocaddr = addr; | |
468 | ||
469 | return 0; | |
470 | } | |
471 | #else | |
472 | ||
473 | # ifdef CONFIG_LCD | |
1938f4a5 SG |
474 | static int reserve_lcd(void) |
475 | { | |
5a541945 | 476 | # ifdef CONFIG_FB_ADDR |
1938f4a5 | 477 | gd->fb_base = CONFIG_FB_ADDR; |
5a541945 | 478 | # else |
1938f4a5 | 479 | /* reserve memory for LCD display (always full pages) */ |
a0ba279a MY |
480 | gd->relocaddr = lcd_setmem(gd->relocaddr); |
481 | gd->fb_base = gd->relocaddr; | |
5a541945 SG |
482 | # endif /* CONFIG_FB_ADDR */ |
483 | ||
1938f4a5 SG |
484 | return 0; |
485 | } | |
5a541945 | 486 | # endif /* CONFIG_LCD */ |
1938f4a5 | 487 | |
5a541945 | 488 | # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ |
d54d7eb9 | 489 | !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ |
944ab340 | 490 | !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) |
8703ef3f | 491 | static int reserve_legacy_video(void) |
e4fef6cf SG |
492 | { |
493 | /* reserve memory for video display (always full pages) */ | |
a0ba279a MY |
494 | gd->relocaddr = video_setmem(gd->relocaddr); |
495 | gd->fb_base = gd->relocaddr; | |
e4fef6cf SG |
496 | |
497 | return 0; | |
498 | } | |
5a541945 SG |
499 | # endif |
500 | #endif /* !CONFIG_DM_VIDEO */ | |
e4fef6cf | 501 | |
8703ef3f SG |
502 | static int reserve_trace(void) |
503 | { | |
504 | #ifdef CONFIG_TRACE | |
505 | gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE; | |
506 | gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE); | |
507 | debug("Reserving %dk for trace data at: %08lx\n", | |
508 | CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr); | |
509 | #endif | |
510 | ||
511 | return 0; | |
512 | } | |
513 | ||
1938f4a5 SG |
514 | static int reserve_uboot(void) |
515 | { | |
516 | /* | |
517 | * reserve memory for U-Boot code, data & bss | |
518 | * round down to next 4 kB limit | |
519 | */ | |
a0ba279a MY |
520 | gd->relocaddr -= gd->mon_len; |
521 | gd->relocaddr &= ~(4096 - 1); | |
e4fef6cf SG |
522 | #ifdef CONFIG_E500 |
523 | /* round down to next 64 kB limit so that IVPR stays aligned */ | |
a0ba279a | 524 | gd->relocaddr &= ~(65536 - 1); |
e4fef6cf | 525 | #endif |
1938f4a5 SG |
526 | |
527 | debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, | |
a0ba279a MY |
528 | gd->relocaddr); |
529 | ||
530 | gd->start_addr_sp = gd->relocaddr; | |
531 | ||
1938f4a5 SG |
532 | return 0; |
533 | } | |
534 | ||
8cae8a68 | 535 | #ifndef CONFIG_SPL_BUILD |
1938f4a5 SG |
536 | /* reserve memory for malloc() area */ |
537 | static int reserve_malloc(void) | |
538 | { | |
a0ba279a | 539 | gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; |
1938f4a5 | 540 | debug("Reserving %dk for malloc() at: %08lx\n", |
a0ba279a | 541 | TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); |
1938f4a5 SG |
542 | return 0; |
543 | } | |
544 | ||
545 | /* (permanently) allocate a Board Info struct */ | |
546 | static int reserve_board(void) | |
547 | { | |
d54d7eb9 SZ |
548 | if (!gd->bd) { |
549 | gd->start_addr_sp -= sizeof(bd_t); | |
550 | gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t)); | |
551 | memset(gd->bd, '\0', sizeof(bd_t)); | |
552 | debug("Reserving %zu Bytes for Board Info at: %08lx\n", | |
553 | sizeof(bd_t), gd->start_addr_sp); | |
554 | } | |
1938f4a5 SG |
555 | return 0; |
556 | } | |
8cae8a68 | 557 | #endif |
1938f4a5 SG |
558 | |
559 | static int setup_machine(void) | |
560 | { | |
561 | #ifdef CONFIG_MACH_TYPE | |
562 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ | |
563 | #endif | |
564 | return 0; | |
565 | } | |
566 | ||
567 | static int reserve_global_data(void) | |
568 | { | |
a0ba279a MY |
569 | gd->start_addr_sp -= sizeof(gd_t); |
570 | gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t)); | |
1938f4a5 | 571 | debug("Reserving %zu Bytes for Global Data at: %08lx\n", |
a0ba279a | 572 | sizeof(gd_t), gd->start_addr_sp); |
1938f4a5 SG |
573 | return 0; |
574 | } | |
575 | ||
576 | static int reserve_fdt(void) | |
577 | { | |
e9acb9ea | 578 | #ifndef CONFIG_OF_EMBED |
1938f4a5 | 579 | /* |
4c509343 | 580 | * If the device tree is sitting immediately above our image then we |
1938f4a5 SG |
581 | * must relocate it. If it is embedded in the data section, then it |
582 | * will be relocated with other data. | |
583 | */ | |
584 | if (gd->fdt_blob) { | |
585 | gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); | |
586 | ||
a0ba279a MY |
587 | gd->start_addr_sp -= gd->fdt_size; |
588 | gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); | |
a733b06b | 589 | debug("Reserving %lu Bytes for FDT at: %08lx\n", |
a0ba279a | 590 | gd->fdt_size, gd->start_addr_sp); |
1938f4a5 | 591 | } |
e9acb9ea | 592 | #endif |
1938f4a5 SG |
593 | |
594 | return 0; | |
595 | } | |
596 | ||
68145d4c | 597 | int arch_reserve_stacks(void) |
1938f4a5 | 598 | { |
68145d4c AB |
599 | return 0; |
600 | } | |
8cae8a68 | 601 | |
68145d4c AB |
602 | static int reserve_stacks(void) |
603 | { | |
604 | /* make stack pointer 16-byte aligned */ | |
a0ba279a MY |
605 | gd->start_addr_sp -= 16; |
606 | gd->start_addr_sp &= ~0xf; | |
1938f4a5 SG |
607 | |
608 | /* | |
4c509343 | 609 | * let the architecture-specific code tailor gd->start_addr_sp and |
68145d4c | 610 | * gd->irq_sp |
1938f4a5 | 611 | */ |
68145d4c | 612 | return arch_reserve_stacks(); |
1938f4a5 SG |
613 | } |
614 | ||
615 | static int display_new_sp(void) | |
616 | { | |
a0ba279a | 617 | debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp); |
1938f4a5 SG |
618 | |
619 | return 0; | |
620 | } | |
621 | ||
e2099d78 VZ |
622 | #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ |
623 | defined(CONFIG_SH) | |
e4fef6cf SG |
624 | static int setup_board_part1(void) |
625 | { | |
626 | bd_t *bd = gd->bd; | |
627 | ||
628 | /* | |
629 | * Save local variables to board info struct | |
630 | */ | |
e4fef6cf SG |
631 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */ |
632 | bd->bi_memsize = gd->ram_size; /* size in bytes */ | |
633 | ||
634 | #ifdef CONFIG_SYS_SRAM_BASE | |
635 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */ | |
636 | bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ | |
637 | #endif | |
638 | ||
58dac327 | 639 | #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \ |
e4fef6cf SG |
640 | defined(CONFIG_E500) || defined(CONFIG_MPC86xx) |
641 | bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */ | |
642 | #endif | |
e310b93e | 643 | #if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K) |
e4fef6cf SG |
644 | bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ |
645 | #endif | |
646 | #if defined(CONFIG_MPC83xx) | |
647 | bd->bi_immrbar = CONFIG_SYS_IMMR; | |
648 | #endif | |
e4fef6cf SG |
649 | |
650 | return 0; | |
651 | } | |
fb3db635 | 652 | #endif |
e4fef6cf | 653 | |
fb3db635 | 654 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) |
e4fef6cf SG |
655 | static int setup_board_part2(void) |
656 | { | |
657 | bd_t *bd = gd->bd; | |
658 | ||
659 | bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ | |
660 | bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ | |
661 | #if defined(CONFIG_CPM2) | |
662 | bd->bi_cpmfreq = gd->arch.cpm_clk; | |
663 | bd->bi_brgfreq = gd->arch.brg_clk; | |
664 | bd->bi_sccfreq = gd->arch.scc_clk; | |
665 | bd->bi_vco = gd->arch.vco_out; | |
666 | #endif /* CONFIG_CPM2 */ | |
667 | #if defined(CONFIG_MPC512X) | |
668 | bd->bi_ipsfreq = gd->arch.ips_clk; | |
669 | #endif /* CONFIG_MPC512X */ | |
670 | #if defined(CONFIG_MPC5xxx) | |
671 | bd->bi_ipbfreq = gd->arch.ipb_clk; | |
672 | bd->bi_pcifreq = gd->pci_clk; | |
673 | #endif /* CONFIG_MPC5xxx */ | |
1313db48 AW |
674 | #if defined(CONFIG_M68K) && defined(CONFIG_PCI) |
675 | bd->bi_pcifreq = gd->pci_clk; | |
676 | #endif | |
677 | #if defined(CONFIG_EXTRA_CLOCK) | |
678 | bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */ | |
679 | bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */ | |
680 | bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */ | |
681 | #endif | |
e4fef6cf SG |
682 | |
683 | return 0; | |
684 | } | |
685 | #endif | |
686 | ||
687 | #ifdef CONFIG_SYS_EXTBDINFO | |
688 | static int setup_board_extra(void) | |
689 | { | |
690 | bd_t *bd = gd->bd; | |
691 | ||
692 | strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version)); | |
693 | strncpy((char *) bd->bi_r_version, U_BOOT_VERSION, | |
694 | sizeof(bd->bi_r_version)); | |
695 | ||
696 | bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */ | |
697 | bd->bi_plb_busfreq = gd->bus_clk; | |
698 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ | |
699 | defined(CONFIG_440EP) || defined(CONFIG_440GR) || \ | |
700 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) | |
701 | bd->bi_pci_busfreq = get_PCI_freq(); | |
702 | bd->bi_opbfreq = get_OPB_freq(); | |
703 | #elif defined(CONFIG_XILINX_405) | |
704 | bd->bi_pci_busfreq = get_PCI_freq(); | |
705 | #endif | |
706 | ||
707 | return 0; | |
708 | } | |
709 | #endif | |
710 | ||
1938f4a5 SG |
711 | #ifdef CONFIG_POST |
712 | static int init_post(void) | |
713 | { | |
714 | post_bootmode_init(); | |
715 | post_run(NULL, POST_ROM | post_bootmode_get(0)); | |
716 | ||
717 | return 0; | |
718 | } | |
719 | #endif | |
720 | ||
1938f4a5 SG |
721 | static int setup_dram_config(void) |
722 | { | |
723 | /* Ram is board specific, so move it to board code ... */ | |
724 | dram_init_banksize(); | |
725 | ||
726 | return 0; | |
727 | } | |
728 | ||
729 | static int reloc_fdt(void) | |
730 | { | |
e9acb9ea | 731 | #ifndef CONFIG_OF_EMBED |
f05ad9ba SG |
732 | if (gd->flags & GD_FLG_SKIP_RELOC) |
733 | return 0; | |
1938f4a5 SG |
734 | if (gd->new_fdt) { |
735 | memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); | |
736 | gd->fdt_blob = gd->new_fdt; | |
737 | } | |
e9acb9ea | 738 | #endif |
1938f4a5 SG |
739 | |
740 | return 0; | |
741 | } | |
742 | ||
743 | static int setup_reloc(void) | |
744 | { | |
f05ad9ba SG |
745 | if (gd->flags & GD_FLG_SKIP_RELOC) { |
746 | debug("Skipping relocation due to flag\n"); | |
747 | return 0; | |
748 | } | |
749 | ||
d54d7eb9 | 750 | #ifdef CONFIG_SYS_TEXT_BASE |
a0ba279a | 751 | gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; |
e310b93e | 752 | #ifdef CONFIG_M68K |
753 | /* | |
754 | * On all ColdFire arch cpu, monitor code starts always | |
755 | * just after the default vector table location, so at 0x400 | |
756 | */ | |
757 | gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400); | |
758 | #endif | |
d54d7eb9 | 759 | #endif |
1938f4a5 SG |
760 | memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); |
761 | ||
762 | debug("Relocation Offset is: %08lx\n", gd->reloc_off); | |
a733b06b | 763 | debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", |
a0ba279a MY |
764 | gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd), |
765 | gd->start_addr_sp); | |
1938f4a5 SG |
766 | |
767 | return 0; | |
768 | } | |
769 | ||
770 | /* ARM calls relocate_code from its crt0.S */ | |
808434cd | 771 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) |
1938f4a5 SG |
772 | |
773 | static int jump_to_copy(void) | |
774 | { | |
f05ad9ba SG |
775 | if (gd->flags & GD_FLG_SKIP_RELOC) |
776 | return 0; | |
48a33806 SG |
777 | /* |
778 | * x86 is special, but in a nice way. It uses a trampoline which | |
779 | * enables the dcache if possible. | |
780 | * | |
781 | * For now, other archs use relocate_code(), which is implemented | |
782 | * similarly for all archs. When we do generic relocation, hopefully | |
783 | * we can make all archs enable the dcache prior to relocation. | |
784 | */ | |
3fb80163 | 785 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
48a33806 SG |
786 | /* |
787 | * SDRAM and console are now initialised. The final stack can now | |
788 | * be setup in SDRAM. Code execution will continue in Flash, but | |
789 | * with the stack in SDRAM and Global Data in temporary memory | |
790 | * (CPU cache) | |
791 | */ | |
f0c7d9c7 | 792 | arch_setup_gd(gd->new_gd); |
48a33806 SG |
793 | board_init_f_r_trampoline(gd->start_addr_sp); |
794 | #else | |
a0ba279a | 795 | relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr); |
48a33806 | 796 | #endif |
1938f4a5 SG |
797 | |
798 | return 0; | |
799 | } | |
800 | #endif | |
801 | ||
802 | /* Record the board_init_f() bootstage (after arch_cpu_init()) */ | |
803 | static int mark_bootstage(void) | |
804 | { | |
805 | bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f"); | |
806 | ||
807 | return 0; | |
808 | } | |
809 | ||
9854a874 SG |
810 | static int initf_console_record(void) |
811 | { | |
812 | #if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN) | |
813 | return console_record_init(); | |
814 | #else | |
815 | return 0; | |
816 | #endif | |
817 | } | |
818 | ||
ab7cd627 SG |
819 | static int initf_dm(void) |
820 | { | |
821 | #if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN) | |
822 | int ret; | |
823 | ||
824 | ret = dm_init_and_scan(true); | |
825 | if (ret) | |
826 | return ret; | |
827 | #endif | |
1057e6cf SG |
828 | #ifdef CONFIG_TIMER_EARLY |
829 | ret = dm_timer_init(); | |
830 | if (ret) | |
831 | return ret; | |
832 | #endif | |
ab7cd627 SG |
833 | |
834 | return 0; | |
835 | } | |
836 | ||
146251f8 SG |
837 | /* Architecture-specific memory reservation */ |
838 | __weak int reserve_arch(void) | |
839 | { | |
840 | return 0; | |
841 | } | |
842 | ||
d4c671cc SG |
843 | __weak int arch_cpu_init_dm(void) |
844 | { | |
845 | return 0; | |
846 | } | |
847 | ||
1938f4a5 | 848 | static init_fnc_t init_sequence_f[] = { |
a733b06b SG |
849 | #ifdef CONFIG_SANDBOX |
850 | setup_ram_buf, | |
e4fef6cf | 851 | #endif |
1938f4a5 | 852 | setup_mon_len, |
b45122fd | 853 | #ifdef CONFIG_OF_CONTROL |
0879361f | 854 | fdtdec_setup, |
b45122fd | 855 | #endif |
d210718d | 856 | #ifdef CONFIG_TRACE |
71c52dba | 857 | trace_early_init, |
d210718d | 858 | #endif |
768e0f52 | 859 | initf_malloc, |
9854a874 | 860 | initf_console_record, |
a52a068e BM |
861 | #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) |
862 | x86_fsp_init, | |
e4fef6cf | 863 | #endif |
1938f4a5 | 864 | arch_cpu_init, /* basic arch cpu dependent setup */ |
8ebf5069 | 865 | mach_cpu_init, /* SoC/machine dependent CPU setup */ |
3ea0953d | 866 | initf_dm, |
d4c671cc | 867 | arch_cpu_init_dm, |
67521957 | 868 | mark_bootstage, /* need timer, go after init dm */ |
1938f4a5 SG |
869 | #if defined(CONFIG_BOARD_EARLY_INIT_F) |
870 | board_early_init_f, | |
871 | #endif | |
e4fef6cf SG |
872 | /* TODO: can any of this go into arch_cpu_init()? */ |
873 | #if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT) | |
874 | get_clocks, /* get CPU and bus clocks (etc.) */ | |
875 | #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \ | |
876 | && !defined(CONFIG_TQM885D) | |
877 | adjust_sdram_tbs_8xx, | |
878 | #endif | |
879 | /* TODO: can we rename this to timer_init()? */ | |
880 | init_timebase, | |
881 | #endif | |
2317cf09 | 882 | #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \ |
c97088c3 | 883 | defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \ |
e2099d78 | 884 | defined(CONFIG_SH) || defined(CONFIG_SPARC) |
1938f4a5 | 885 | timer_init, /* initialize timer */ |
e4fef6cf | 886 | #endif |
e4fef6cf SG |
887 | #if defined(CONFIG_BOARD_POSTCLK_INIT) |
888 | board_postclk_init, | |
b8521b74 | 889 | #endif |
7664846b | 890 | #if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) |
e310b93e | 891 | get_clocks, |
1938f4a5 SG |
892 | #endif |
893 | env_init, /* initialize environment */ | |
e4fef6cf SG |
894 | #if defined(CONFIG_8xx_CPUCLK_DEFAULT) |
895 | /* get CPU and bus clocks according to the environment variable */ | |
896 | get_clocks_866, | |
897 | /* adjust sdram refresh rate according to the new clock */ | |
898 | sdram_adjust_866, | |
899 | init_timebase, | |
900 | #endif | |
1938f4a5 SG |
901 | init_baud_rate, /* initialze baudrate settings */ |
902 | serial_init, /* serial communications setup */ | |
903 | console_init_f, /* stage 1 init of console */ | |
a733b06b SG |
904 | #ifdef CONFIG_SANDBOX |
905 | sandbox_early_getopt_check, | |
48a33806 | 906 | #endif |
1938f4a5 SG |
907 | display_options, /* say that we are here */ |
908 | display_text_info, /* show debugging info if required */ | |
58dac327 | 909 | #if defined(CONFIG_MPC8260) |
e4fef6cf SG |
910 | prt_8260_rsr, |
911 | prt_8260_clks, | |
58dac327 | 912 | #endif /* CONFIG_MPC8260 */ |
e4fef6cf SG |
913 | #if defined(CONFIG_MPC83xx) |
914 | prt_83xx_rsr, | |
915 | #endif | |
e2099d78 | 916 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) |
e4fef6cf SG |
917 | checkcpu, |
918 | #endif | |
1938f4a5 | 919 | print_cpuinfo, /* display cpu info (and speed) */ |
e4fef6cf SG |
920 | #if defined(CONFIG_MPC5xxx) |
921 | prt_mpc5xxx_clks, | |
922 | #endif /* CONFIG_MPC5xxx */ | |
1938f4a5 | 923 | #if defined(CONFIG_DISPLAY_BOARDINFO) |
0365ffcc | 924 | show_board_info, |
e4fef6cf SG |
925 | #endif |
926 | INIT_FUNC_WATCHDOG_INIT | |
927 | #if defined(CONFIG_MISC_INIT_F) | |
928 | misc_init_f, | |
929 | #endif | |
930 | INIT_FUNC_WATCHDOG_RESET | |
ea818dbb | 931 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) |
e4fef6cf SG |
932 | init_func_i2c, |
933 | #endif | |
934 | #if defined(CONFIG_HARD_SPI) | |
935 | init_func_spi, | |
1938f4a5 SG |
936 | #endif |
937 | announce_dram_init, | |
938 | /* TODO: unify all these dram functions? */ | |
2e88bb28 | 939 | #if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \ |
e2099d78 VZ |
940 | defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \ |
941 | defined(CONFIG_SH) | |
1938f4a5 SG |
942 | dram_init, /* configure available RAM banks */ |
943 | #endif | |
e310b93e | 944 | #if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K) |
e4fef6cf SG |
945 | init_func_ram, |
946 | #endif | |
947 | #ifdef CONFIG_POST | |
948 | post_init_f, | |
949 | #endif | |
950 | INIT_FUNC_WATCHDOG_RESET | |
951 | #if defined(CONFIG_SYS_DRAM_TEST) | |
952 | testdram, | |
953 | #endif /* CONFIG_SYS_DRAM_TEST */ | |
954 | INIT_FUNC_WATCHDOG_RESET | |
955 | ||
1938f4a5 SG |
956 | #ifdef CONFIG_POST |
957 | init_post, | |
958 | #endif | |
e4fef6cf | 959 | INIT_FUNC_WATCHDOG_RESET |
1938f4a5 SG |
960 | /* |
961 | * Now that we have DRAM mapped and working, we can | |
962 | * relocate the code and continue running from DRAM. | |
963 | * | |
964 | * Reserve memory at end of RAM for (top down in that order): | |
965 | * - area that won't get touched by U-Boot and Linux (optional) | |
966 | * - kernel log buffer | |
967 | * - protected RAM | |
968 | * - LCD framebuffer | |
969 | * - monitor code | |
970 | * - board info struct | |
971 | */ | |
972 | setup_dest_addr, | |
de5e5cea | 973 | #if defined(CONFIG_BLACKFIN) || defined(CONFIG_XTENSA) |
d54d7eb9 SZ |
974 | /* Blackfin u-boot monitor should be on top of the ram */ |
975 | reserve_uboot, | |
976 | #endif | |
1e85ccec FR |
977 | #if defined(CONFIG_SPARC) |
978 | reserve_prom, | |
979 | #endif | |
1938f4a5 SG |
980 | #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) |
981 | reserve_logbuffer, | |
982 | #endif | |
983 | #ifdef CONFIG_PRAM | |
984 | reserve_pram, | |
985 | #endif | |
986 | reserve_round_4k, | |
987 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \ | |
988 | defined(CONFIG_ARM) | |
989 | reserve_mmu, | |
990 | #endif | |
5a541945 SG |
991 | #ifdef CONFIG_DM_VIDEO |
992 | reserve_video, | |
993 | #else | |
994 | # ifdef CONFIG_LCD | |
1938f4a5 | 995 | reserve_lcd, |
5a541945 | 996 | # endif |
e4fef6cf | 997 | /* TODO: Why the dependency on CONFIG_8xx? */ |
5a541945 | 998 | # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \ |
d54d7eb9 | 999 | !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ |
944ab340 | 1000 | !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K) |
5a541945 SG |
1001 | reserve_legacy_video, |
1002 | # endif | |
1003 | #endif /* CONFIG_DM_VIDEO */ | |
8703ef3f | 1004 | reserve_trace, |
de5e5cea | 1005 | #if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_XTENSA) |
1938f4a5 | 1006 | reserve_uboot, |
d54d7eb9 | 1007 | #endif |
8cae8a68 | 1008 | #ifndef CONFIG_SPL_BUILD |
1938f4a5 SG |
1009 | reserve_malloc, |
1010 | reserve_board, | |
8cae8a68 | 1011 | #endif |
1938f4a5 SG |
1012 | setup_machine, |
1013 | reserve_global_data, | |
1014 | reserve_fdt, | |
146251f8 | 1015 | reserve_arch, |
1938f4a5 SG |
1016 | reserve_stacks, |
1017 | setup_dram_config, | |
1018 | show_dram_config, | |
e2099d78 VZ |
1019 | #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ |
1020 | defined(CONFIG_SH) | |
e4fef6cf | 1021 | setup_board_part1, |
fb3db635 DS |
1022 | #endif |
1023 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) | |
e4fef6cf SG |
1024 | INIT_FUNC_WATCHDOG_RESET |
1025 | setup_board_part2, | |
1026 | #endif | |
1938f4a5 | 1027 | display_new_sp, |
e4fef6cf SG |
1028 | #ifdef CONFIG_SYS_EXTBDINFO |
1029 | setup_board_extra, | |
1030 | #endif | |
1031 | INIT_FUNC_WATCHDOG_RESET | |
1938f4a5 SG |
1032 | reloc_fdt, |
1033 | setup_reloc, | |
3fb80163 | 1034 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
313aef37 SG |
1035 | copy_uboot_to_ram, |
1036 | clear_bss, | |
1037 | do_elf_reloc_fixups, | |
1038 | #endif | |
de5e5cea CZ |
1039 | #if defined(CONFIG_XTENSA) |
1040 | clear_bss, | |
1041 | #endif | |
808434cd | 1042 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) |
1938f4a5 SG |
1043 | jump_to_copy, |
1044 | #endif | |
1045 | NULL, | |
1046 | }; | |
1047 | ||
1048 | void board_init_f(ulong boot_flags) | |
1049 | { | |
2a1680e3 YS |
1050 | #ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA |
1051 | /* | |
fc0b5948 | 1052 | * For some architectures, global data is initialized and used before |
2a1680e3 YS |
1053 | * calling this function. The data should be preserved. For others, |
1054 | * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack | |
1055 | * here to host global data until relocation. | |
1056 | */ | |
1938f4a5 SG |
1057 | gd_t data; |
1058 | ||
1059 | gd = &data; | |
1060 | ||
cce6be7f DF |
1061 | /* |
1062 | * Clear global data before it is accessed at debug print | |
1063 | * in initcall_run_list. Otherwise the debug print probably | |
fc0b5948 | 1064 | * get the wrong value of gd->have_console. |
cce6be7f | 1065 | */ |
cce6be7f DF |
1066 | zero_global_data(); |
1067 | #endif | |
1068 | ||
1938f4a5 | 1069 | gd->flags = boot_flags; |
9aed5a27 | 1070 | gd->have_console = 0; |
1938f4a5 SG |
1071 | |
1072 | if (initcall_run_list(init_sequence_f)) | |
1073 | hang(); | |
1074 | ||
9b217498 BS |
1075 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ |
1076 | !defined(CONFIG_EFI_APP) | |
1938f4a5 SG |
1077 | /* NOTREACHED - jump_to_copy() does not return */ |
1078 | hang(); | |
1079 | #endif | |
1080 | } | |
1081 | ||
3fb80163 | 1082 | #if defined(CONFIG_X86) || defined(CONFIG_ARC) |
48a33806 SG |
1083 | /* |
1084 | * For now this code is only used on x86. | |
1085 | * | |
1086 | * init_sequence_f_r is the list of init functions which are run when | |
1087 | * U-Boot is executing from Flash with a semi-limited 'C' environment. | |
1088 | * The following limitations must be considered when implementing an | |
1089 | * '_f_r' function: | |
1090 | * - 'static' variables are read-only | |
1091 | * - Global Data (gd->xxx) is read/write | |
1092 | * | |
1093 | * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if | |
1094 | * supported). It _should_, if possible, copy global data to RAM and | |
1095 | * initialise the CPU caches (to speed up the relocation process) | |
1096 | * | |
1097 | * NOTE: At present only x86 uses this route, but it is intended that | |
1098 | * all archs will move to this when generic relocation is implemented. | |
1099 | */ | |
1100 | static init_fnc_t init_sequence_f_r[] = { | |
1101 | init_cache_f_r, | |
48a33806 SG |
1102 | |
1103 | NULL, | |
1104 | }; | |
1105 | ||
1106 | void board_init_f_r(void) | |
1107 | { | |
1108 | if (initcall_run_list(init_sequence_f_r)) | |
1109 | hang(); | |
1110 | ||
e4d6ab0c SG |
1111 | /* |
1112 | * The pre-relocation drivers may be using memory that has now gone | |
1113 | * away. Mark serial as unavailable - this will fall back to the debug | |
1114 | * UART if available. | |
1115 | */ | |
1116 | gd->flags &= ~GD_FLG_SERIAL_READY; | |
1117 | ||
48a33806 SG |
1118 | /* |
1119 | * U-Boot has been copied into SDRAM, the BSS has been cleared etc. | |
1120 | * Transfer execution from Flash to RAM by calculating the address | |
1121 | * of the in-RAM copy of board_init_r() and calling it | |
1122 | */ | |
7bf9f20d | 1123 | (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr); |
48a33806 SG |
1124 | |
1125 | /* NOTREACHED - board_init_r() does not return */ | |
1126 | hang(); | |
1127 | } | |
5bcd19aa | 1128 | #endif /* CONFIG_X86 */ |