blob: 89ce7954ab8c48f8564c2098e7552a4a9b6aad0a [file] [log] [blame]
Simon Glassc45e3592013-03-11 06:49:53 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
9 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glassc45e3592013-03-11 06:49:53 +000011 */
12
13#include <common.h>
14#include <linux/compiler.h>
15#include <version.h>
16#include <environment.h>
Simon Glassa730c5d2014-07-23 06:55:04 -060017#include <dm.h>
Simon Glassc45e3592013-03-11 06:49:53 +000018#include <fdtdec.h>
Simon Glass15393432013-04-20 08:42:41 +000019#include <fs.h>
Simon Glass50250b52013-03-11 14:30:42 +000020#if defined(CONFIG_CMD_IDE)
21#include <ide.h>
22#endif
23#include <i2c.h>
Simon Glassc45e3592013-03-11 06:49:53 +000024#include <initcall.h>
25#include <logbuff.h>
Simon Glass50250b52013-03-11 14:30:42 +000026
27/* TODO: Can we move these into arch/ headers? */
28#ifdef CONFIG_8xx
29#include <mpc8xx.h>
30#endif
31#ifdef CONFIG_5xx
32#include <mpc5xx.h>
33#endif
34#ifdef CONFIG_MPC5xxx
35#include <mpc5xxx.h>
36#endif
Gabriel Huauda0afc22014-09-03 13:57:54 -070037#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huau170ceaf2014-07-26 11:35:43 -070038#include <asm/mp.h>
39#endif
Simon Glass50250b52013-03-11 14:30:42 +000040
Simon Glass62cf9122013-04-26 02:53:43 +000041#include <os.h>
Simon Glassc45e3592013-03-11 06:49:53 +000042#include <post.h>
Simon Glass50250b52013-03-11 14:30:42 +000043#include <spi.h>
Jeroen Hofsteea802b982014-06-23 23:20:19 +020044#include <status_led.h>
Simon Glass209a1a62013-06-11 11:14:42 -070045#include <trace.h>
Simon Glass50250b52013-03-11 14:30:42 +000046#include <watchdog.h>
Simon Glass62cf9122013-04-26 02:53:43 +000047#include <asm/errno.h>
Simon Glassc45e3592013-03-11 06:49:53 +000048#include <asm/io.h>
49#include <asm/sections.h>
Simon Glass6d179872013-03-05 14:39:52 +000050#ifdef CONFIG_X86
51#include <asm/init_helpers.h>
52#include <asm/relocate.h>
53#endif
Simon Glass62cf9122013-04-26 02:53:43 +000054#ifdef CONFIG_SANDBOX
55#include <asm/state.h>
56#endif
Simon Glassa730c5d2014-07-23 06:55:04 -060057#include <dm/root.h>
Simon Glassc45e3592013-03-11 06:49:53 +000058#include <linux/compiler.h>
59
60/*
61 * Pointer to initial global data area
62 *
63 * Here we initialize it if needed.
64 */
65#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
66#undef XTRN_DECLARE_GLOBAL_DATA_PTR
67#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
68DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
69#else
70DECLARE_GLOBAL_DATA_PTR;
71#endif
72
73/*
74 * sjg: IMO this code should be
75 * refactored to a single function, something like:
76 *
77 * void led_set_state(enum led_colour_t colour, int on);
78 */
79/************************************************************************
80 * Coloured LED functionality
81 ************************************************************************
82 * May be supplied by boards if desired
83 */
Jeroen Hofsteea802b982014-06-23 23:20:19 +020084__weak void coloured_LED_init(void) {}
85__weak void red_led_on(void) {}
86__weak void red_led_off(void) {}
87__weak void green_led_on(void) {}
88__weak void green_led_off(void) {}
89__weak void yellow_led_on(void) {}
90__weak void yellow_led_off(void) {}
91__weak void blue_led_on(void) {}
92__weak void blue_led_off(void) {}
Simon Glassc45e3592013-03-11 06:49:53 +000093
94/*
95 * Why is gd allocated a register? Prior to reloc it might be better to
96 * just pass it around to each function in this file?
97 *
98 * After reloc one could argue that it is hardly used and doesn't need
99 * to be in a register. Or if it is it should perhaps hold pointers to all
100 * global data for all modules, so that post-reloc we can avoid the massive
101 * literal pool we get on ARM. Or perhaps just encourage each module to use
102 * a structure...
103 */
104
105/*
106 * Could the CONFIG_SPL_BUILD infection become a flag in gd?
107 */
108
Sonic Zhangf503a522014-07-17 19:01:34 +0800109#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glass50250b52013-03-11 14:30:42 +0000110static int init_func_watchdog_init(void)
111{
Sonic Zhangf503a522014-07-17 19:01:34 +0800112# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
113 defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roeseee86af22015-03-10 08:04:36 +0100114 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
115 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangf503a522014-07-17 19:01:34 +0800116 hw_watchdog_init();
117# endif
Simon Glass50250b52013-03-11 14:30:42 +0000118 puts(" Watchdog enabled\n");
119 WATCHDOG_RESET();
120
121 return 0;
122}
123
124int init_func_watchdog_reset(void)
125{
126 WATCHDOG_RESET();
127
128 return 0;
129}
130#endif /* CONFIG_WATCHDOG */
131
Jeroen Hofstee45846052014-10-08 22:57:22 +0200132__weak void board_add_ram_info(int use_default)
Simon Glass50250b52013-03-11 14:30:42 +0000133{
134 /* please define platform specific board_add_ram_info() */
135}
136
Simon Glassc45e3592013-03-11 06:49:53 +0000137static int init_baud_rate(void)
138{
139 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
140 return 0;
141}
142
143static int display_text_info(void)
144{
Simon Glass62cf9122013-04-26 02:53:43 +0000145#ifndef CONFIG_SANDBOX
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100146 ulong bss_start, bss_end, text_base;
Simon Glassc45e3592013-03-11 06:49:53 +0000147
Simon Glass9c9f44a2013-03-11 07:06:48 +0000148 bss_start = (ulong)&__bss_start;
149 bss_end = (ulong)&__bss_end;
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100150
Sonic Zhangf503a522014-07-17 19:01:34 +0800151#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100152 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800153#else
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100154 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800155#endif
Daniel Schwierzeck17c2af62014-11-15 23:46:53 +0100156
157 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
158 text_base, bss_start, bss_end);
Simon Glass62cf9122013-04-26 02:53:43 +0000159#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000160
161#ifdef CONFIG_MODEM_SUPPORT
162 debug("Modem Support enabled\n");
163#endif
164#ifdef CONFIG_USE_IRQ
165 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
166 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
167#endif
168
169 return 0;
170}
171
172static int announce_dram_init(void)
173{
174 puts("DRAM: ");
175 return 0;
176}
177
Paul Burton10da49b2014-04-07 10:11:20 +0100178#if defined(CONFIG_MIPS) || defined(CONFIG_PPC)
Simon Glass50250b52013-03-11 14:30:42 +0000179static int init_func_ram(void)
180{
181#ifdef CONFIG_BOARD_TYPES
182 int board_type = gd->board_type;
183#else
184 int board_type = 0; /* use dummy arg */
185#endif
186
187 gd->ram_size = initdram(board_type);
188
189 if (gd->ram_size > 0)
190 return 0;
191
192 puts("*** failed ***\n");
193 return 1;
194}
195#endif
196
Simon Glassc45e3592013-03-11 06:49:53 +0000197static int show_dram_config(void)
198{
York Sun60ac15a2014-05-02 17:28:05 -0700199 unsigned long long size;
Simon Glassc45e3592013-03-11 06:49:53 +0000200
201#ifdef CONFIG_NR_DRAM_BANKS
202 int i;
203
204 debug("\nRAM Configuration:\n");
205 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
206 size += gd->bd->bi_dram[i].size;
207 debug("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
208#ifdef DEBUG
209 print_size(gd->bd->bi_dram[i].size, "\n");
210#endif
211 }
212 debug("\nDRAM: ");
213#else
214 size = gd->ram_size;
215#endif
216
Simon Glass50250b52013-03-11 14:30:42 +0000217 print_size(size, "");
218 board_add_ram_info(0);
219 putc('\n');
Simon Glassc45e3592013-03-11 06:49:53 +0000220
221 return 0;
222}
223
Jeroen Hofstee45846052014-10-08 22:57:22 +0200224__weak void dram_init_banksize(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000225{
226#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
227 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
228 gd->bd->bi_dram[0].size = get_effective_memsize();
229#endif
230}
231
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100232#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000233static int init_func_i2c(void)
234{
235 puts("I2C: ");
trema6612902013-09-21 18:13:34 +0200236#ifdef CONFIG_SYS_I2C
237 i2c_init_all();
238#else
Simon Glass50250b52013-03-11 14:30:42 +0000239 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trema6612902013-09-21 18:13:34 +0200240#endif
Simon Glass50250b52013-03-11 14:30:42 +0000241 puts("ready\n");
242 return 0;
243}
244#endif
245
246#if defined(CONFIG_HARD_SPI)
247static int init_func_spi(void)
248{
249 puts("SPI: ");
250 spi_init();
251 puts("ready\n");
252 return 0;
253}
254#endif
255
256__maybe_unused
Simon Glassc45e3592013-03-11 06:49:53 +0000257static int zero_global_data(void)
258{
259 memset((void *)gd, '\0', sizeof(gd_t));
260
261 return 0;
262}
263
264static int setup_mon_len(void)
265{
Michal Simek65e915c2014-05-08 16:08:44 +0200266#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100267 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Simon Glass62cf9122013-04-26 02:53:43 +0000268#elif defined(CONFIG_SANDBOX)
269 gd->mon_len = (ulong)&_end - (ulong)_init;
Thomas Choucce3e752014-08-22 11:36:47 +0800270#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
Sonic Zhangf503a522014-07-17 19:01:34 +0800271 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000272#else
Simon Glass50250b52013-03-11 14:30:42 +0000273 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
274 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass9c9f44a2013-03-11 07:06:48 +0000275#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000276 return 0;
277}
278
279__weak int arch_cpu_init(void)
280{
281 return 0;
282}
283
Simon Glass15393432013-04-20 08:42:41 +0000284#ifdef CONFIG_OF_HOSTFILE
285
Simon Glass15393432013-04-20 08:42:41 +0000286static int read_fdt_from_file(void)
287{
288 struct sandbox_state *state = state_get_current();
Simon Glasse735b682014-02-27 13:25:58 -0700289 const char *fname = state->fdt_fname;
Simon Glass15393432013-04-20 08:42:41 +0000290 void *blob;
Suriyan Ramasami378da1032014-11-17 14:39:37 -0800291 loff_t size;
Simon Glass15393432013-04-20 08:42:41 +0000292 int err;
Simon Glasse735b682014-02-27 13:25:58 -0700293 int fd;
Simon Glass15393432013-04-20 08:42:41 +0000294
295 blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
296 if (!state->fdt_fname) {
Simon Glasse735b682014-02-27 13:25:58 -0700297 err = fdt_create_empty_tree(blob, 256);
Simon Glass15393432013-04-20 08:42:41 +0000298 if (!err)
299 goto done;
Simon Glasse735b682014-02-27 13:25:58 -0700300 printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
301 return -EINVAL;
302 }
303
Suriyan Ramasami378da1032014-11-17 14:39:37 -0800304 err = os_get_filesize(fname, &size);
305 if (err < 0) {
Simon Glasse735b682014-02-27 13:25:58 -0700306 printf("Failed to file FDT file '%s'\n", fname);
Suriyan Ramasami378da1032014-11-17 14:39:37 -0800307 return err;
Simon Glass15393432013-04-20 08:42:41 +0000308 }
Simon Glasse735b682014-02-27 13:25:58 -0700309 fd = os_open(fname, OS_O_RDONLY);
310 if (fd < 0) {
311 printf("Failed to open FDT file '%s'\n", fname);
312 return -EACCES;
313 }
314 if (os_read(fd, blob, size) != size) {
315 os_close(fd);
Simon Glass15393432013-04-20 08:42:41 +0000316 return -EIO;
Simon Glasse735b682014-02-27 13:25:58 -0700317 }
318 os_close(fd);
Simon Glass15393432013-04-20 08:42:41 +0000319
320done:
321 gd->fdt_blob = blob;
322
323 return 0;
324}
325#endif
326
Simon Glass62cf9122013-04-26 02:53:43 +0000327#ifdef CONFIG_SANDBOX
328static int setup_ram_buf(void)
329{
Simon Glass9dd10bf2013-11-10 10:27:03 -0700330 struct sandbox_state *state = state_get_current();
331
332 gd->arch.ram_buf = state->ram_buf;
333 gd->ram_size = state->ram_size;
Simon Glass62cf9122013-04-26 02:53:43 +0000334
335 return 0;
336}
337#endif
338
Simon Glassc45e3592013-03-11 06:49:53 +0000339static int setup_fdt(void)
340{
Masahiro Yamada45c30572014-09-06 23:39:00 +0900341#ifdef CONFIG_OF_CONTROL
342# ifdef CONFIG_OF_EMBED
Simon Glassc45e3592013-03-11 06:49:53 +0000343 /* Get a pointer to the FDT */
Masahiro Yamada43c08932014-02-05 11:28:25 +0900344 gd->fdt_blob = __dtb_dt_begin;
Masahiro Yamada45c30572014-09-06 23:39:00 +0900345# elif defined CONFIG_OF_SEPARATE
Simon Glassc45e3592013-03-11 06:49:53 +0000346 /* FDT is at end of image */
Simon Glass9c9f44a2013-03-11 07:06:48 +0000347 gd->fdt_blob = (ulong *)&_end;
Masahiro Yamada45c30572014-09-06 23:39:00 +0900348# elif defined(CONFIG_OF_HOSTFILE)
Simon Glass15393432013-04-20 08:42:41 +0000349 if (read_fdt_from_file()) {
350 puts("Failed to read control FDT\n");
351 return -1;
352 }
Masahiro Yamada45c30572014-09-06 23:39:00 +0900353# endif
Simon Glassc45e3592013-03-11 06:49:53 +0000354 /* Allow the early environment to override the fdt address */
355 gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
356 (uintptr_t)gd->fdt_blob);
Masahiro Yamada45c30572014-09-06 23:39:00 +0900357#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000358 return 0;
359}
360
361/* Get the top of usable RAM */
362__weak ulong board_get_usable_ram_top(ulong total_size)
363{
364 return gd->ram_top;
365}
366
367static int setup_dest_addr(void)
368{
369 debug("Monitor len: %08lX\n", gd->mon_len);
370 /*
371 * Ram is setup, size stored in gd !!
372 */
373 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
374#if defined(CONFIG_SYS_MEM_TOP_HIDE)
375 /*
376 * Subtract specified amount of memory to hide so that it won't
377 * get "touched" at all by U-Boot. By fixing up gd->ram_size
378 * the Linux kernel should now get passed the now "corrected"
379 * memory size and won't touch it either. This should work
380 * for arch/ppc and arch/powerpc. Only Linux board ports in
381 * arch/powerpc with bootwrapper support, that recalculate the
382 * memory size from the SDRAM controller setup will have to
383 * get fixed.
384 */
385 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
386#endif
387#ifdef CONFIG_SYS_SDRAM_BASE
388 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
389#endif
Simon Glass50250b52013-03-11 14:30:42 +0000390 gd->ram_top += get_effective_memsize();
Simon Glassc45e3592013-03-11 06:49:53 +0000391 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000392 gd->relocaddr = gd->ram_top;
Simon Glassc45e3592013-03-11 06:49:53 +0000393 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauda0afc22014-09-03 13:57:54 -0700394#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glass50250b52013-03-11 14:30:42 +0000395 /*
396 * We need to make sure the location we intend to put secondary core
397 * boot code is reserved and not used by any part of u-boot
398 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000399 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
400 gd->relocaddr = determine_mp_bootpg(NULL);
401 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glass50250b52013-03-11 14:30:42 +0000402 }
403#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000404 return 0;
405}
406
407#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
408static int reserve_logbuffer(void)
409{
410 /* reserve kernel log buffer */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000411 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glassc45e3592013-03-11 06:49:53 +0000412 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000413 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000414 return 0;
415}
416#endif
417
418#ifdef CONFIG_PRAM
419/* reserve protected RAM */
420static int reserve_pram(void)
421{
422 ulong reg;
423
424 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadad1589242013-05-27 00:37:30 +0000425 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glassc45e3592013-03-11 06:49:53 +0000426 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000427 gd->relocaddr);
Simon Glassc45e3592013-03-11 06:49:53 +0000428 return 0;
429}
430#endif /* CONFIG_PRAM */
431
432/* Round memory pointer down to next 4 kB limit */
433static int reserve_round_4k(void)
434{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000435 gd->relocaddr &= ~(4096 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000436 return 0;
437}
438
439#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
440 defined(CONFIG_ARM)
441static int reserve_mmu(void)
442{
443 /* reserve TLB table */
David Feng1735de82013-12-14 11:47:36 +0800444 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadad1589242013-05-27 00:37:30 +0000445 gd->relocaddr -= gd->arch.tlb_size;
Simon Glassc45e3592013-03-11 06:49:53 +0000446
447 /* round down to next 64 kB limit */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000448 gd->relocaddr &= ~(0x10000 - 1);
Simon Glassc45e3592013-03-11 06:49:53 +0000449
Masahiro Yamadad1589242013-05-27 00:37:30 +0000450 gd->arch.tlb_addr = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000451 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
452 gd->arch.tlb_addr + gd->arch.tlb_size);
453 return 0;
454}
455#endif
456
457#ifdef CONFIG_LCD
458static int reserve_lcd(void)
459{
460#ifdef CONFIG_FB_ADDR
461 gd->fb_base = CONFIG_FB_ADDR;
462#else
463 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000464 gd->relocaddr = lcd_setmem(gd->relocaddr);
465 gd->fb_base = gd->relocaddr;
Simon Glassc45e3592013-03-11 06:49:53 +0000466#endif /* CONFIG_FB_ADDR */
467 return 0;
468}
469#endif /* CONFIG_LCD */
470
Simon Glass209a1a62013-06-11 11:14:42 -0700471static int reserve_trace(void)
472{
473#ifdef CONFIG_TRACE
474 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
475 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
476 debug("Reserving %dk for trace data at: %08lx\n",
477 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
478#endif
479
480 return 0;
481}
482
Sonic Zhangf503a522014-07-17 19:01:34 +0800483#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
484 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
485 !defined(CONFIG_BLACKFIN)
Simon Glass50250b52013-03-11 14:30:42 +0000486static int reserve_video(void)
487{
488 /* reserve memory for video display (always full pages) */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000489 gd->relocaddr = video_setmem(gd->relocaddr);
490 gd->fb_base = gd->relocaddr;
Simon Glass50250b52013-03-11 14:30:42 +0000491
492 return 0;
493}
494#endif
495
Simon Glassc45e3592013-03-11 06:49:53 +0000496static int reserve_uboot(void)
497{
498 /*
499 * reserve memory for U-Boot code, data & bss
500 * round down to next 4 kB limit
501 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000502 gd->relocaddr -= gd->mon_len;
503 gd->relocaddr &= ~(4096 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000504#ifdef CONFIG_E500
505 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000506 gd->relocaddr &= ~(65536 - 1);
Simon Glass50250b52013-03-11 14:30:42 +0000507#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000508
509 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadad1589242013-05-27 00:37:30 +0000510 gd->relocaddr);
511
512 gd->start_addr_sp = gd->relocaddr;
513
Simon Glassc45e3592013-03-11 06:49:53 +0000514 return 0;
515}
516
Simon Glass4d2aee82013-03-05 14:39:45 +0000517#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000518/* reserve memory for malloc() area */
519static int reserve_malloc(void)
520{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000521 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glassc45e3592013-03-11 06:49:53 +0000522 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000523 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000524 return 0;
525}
526
527/* (permanently) allocate a Board Info struct */
528static int reserve_board(void)
529{
Sonic Zhangf503a522014-07-17 19:01:34 +0800530 if (!gd->bd) {
531 gd->start_addr_sp -= sizeof(bd_t);
532 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
533 memset(gd->bd, '\0', sizeof(bd_t));
534 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
535 sizeof(bd_t), gd->start_addr_sp);
536 }
Simon Glassc45e3592013-03-11 06:49:53 +0000537 return 0;
538}
Simon Glass4d2aee82013-03-05 14:39:45 +0000539#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000540
541static int setup_machine(void)
542{
543#ifdef CONFIG_MACH_TYPE
544 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
545#endif
546 return 0;
547}
548
549static int reserve_global_data(void)
550{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000551 gd->start_addr_sp -= sizeof(gd_t);
552 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
Simon Glassc45e3592013-03-11 06:49:53 +0000553 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000554 sizeof(gd_t), gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000555 return 0;
556}
557
558static int reserve_fdt(void)
559{
560 /*
561 * If the device tree is sitting immediate above our image then we
562 * must relocate it. If it is embedded in the data section, then it
563 * will be relocated with other data.
564 */
565 if (gd->fdt_blob) {
566 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
567
Masahiro Yamadad1589242013-05-27 00:37:30 +0000568 gd->start_addr_sp -= gd->fdt_size;
569 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glass62cf9122013-04-26 02:53:43 +0000570 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000571 gd->fdt_size, gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000572 }
573
574 return 0;
575}
576
Andreas Bießmann25429862015-02-06 23:06:45 +0100577int arch_reserve_stacks(void)
Simon Glassc45e3592013-03-11 06:49:53 +0000578{
Andreas Bießmann25429862015-02-06 23:06:45 +0100579 return 0;
580}
Simon Glass4d2aee82013-03-05 14:39:45 +0000581
Andreas Bießmann25429862015-02-06 23:06:45 +0100582static int reserve_stacks(void)
583{
584 /* make stack pointer 16-byte aligned */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000585 gd->start_addr_sp -= 16;
586 gd->start_addr_sp &= ~0xf;
Simon Glassc45e3592013-03-11 06:49:53 +0000587
588 /*
Andreas Bießmann25429862015-02-06 23:06:45 +0100589 * let the architecture specific code tailor gd->start_addr_sp and
590 * gd->irq_sp
Simon Glassc45e3592013-03-11 06:49:53 +0000591 */
Andreas Bießmann25429862015-02-06 23:06:45 +0100592 return arch_reserve_stacks();
Simon Glassc45e3592013-03-11 06:49:53 +0000593}
594
595static int display_new_sp(void)
596{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000597 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000598
599 return 0;
600}
601
Simon Glass50250b52013-03-11 14:30:42 +0000602#ifdef CONFIG_PPC
603static int setup_board_part1(void)
604{
605 bd_t *bd = gd->bd;
606
607 /*
608 * Save local variables to board info struct
609 */
610
611 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
612 bd->bi_memsize = gd->ram_size; /* size in bytes */
613
614#ifdef CONFIG_SYS_SRAM_BASE
615 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
616 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
617#endif
618
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900619#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glass50250b52013-03-11 14:30:42 +0000620 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
621 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
622#endif
623#if defined(CONFIG_MPC5xxx)
624 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
625#endif
626#if defined(CONFIG_MPC83xx)
627 bd->bi_immrbar = CONFIG_SYS_IMMR;
628#endif
Simon Glass50250b52013-03-11 14:30:42 +0000629
630 return 0;
631}
632
633static int setup_board_part2(void)
634{
635 bd_t *bd = gd->bd;
636
637 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
638 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
639#if defined(CONFIG_CPM2)
640 bd->bi_cpmfreq = gd->arch.cpm_clk;
641 bd->bi_brgfreq = gd->arch.brg_clk;
642 bd->bi_sccfreq = gd->arch.scc_clk;
643 bd->bi_vco = gd->arch.vco_out;
644#endif /* CONFIG_CPM2 */
645#if defined(CONFIG_MPC512X)
646 bd->bi_ipsfreq = gd->arch.ips_clk;
647#endif /* CONFIG_MPC512X */
648#if defined(CONFIG_MPC5xxx)
649 bd->bi_ipbfreq = gd->arch.ipb_clk;
650 bd->bi_pcifreq = gd->pci_clk;
651#endif /* CONFIG_MPC5xxx */
652
653 return 0;
654}
655#endif
656
657#ifdef CONFIG_SYS_EXTBDINFO
658static int setup_board_extra(void)
659{
660 bd_t *bd = gd->bd;
661
662 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
663 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
664 sizeof(bd->bi_r_version));
665
666 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
667 bd->bi_plb_busfreq = gd->bus_clk;
668#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
669 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
670 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
671 bd->bi_pci_busfreq = get_PCI_freq();
672 bd->bi_opbfreq = get_OPB_freq();
673#elif defined(CONFIG_XILINX_405)
674 bd->bi_pci_busfreq = get_PCI_freq();
675#endif
676
677 return 0;
678}
679#endif
680
Simon Glassc45e3592013-03-11 06:49:53 +0000681#ifdef CONFIG_POST
682static int init_post(void)
683{
684 post_bootmode_init();
685 post_run(NULL, POST_ROM | post_bootmode_get(0));
686
687 return 0;
688}
689#endif
690
Simon Glassc45e3592013-03-11 06:49:53 +0000691static int setup_dram_config(void)
692{
693 /* Ram is board specific, so move it to board code ... */
694 dram_init_banksize();
695
696 return 0;
697}
698
699static int reloc_fdt(void)
700{
701 if (gd->new_fdt) {
702 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
703 gd->fdt_blob = gd->new_fdt;
704 }
705
706 return 0;
707}
708
709static int setup_reloc(void)
710{
Sonic Zhangf503a522014-07-17 19:01:34 +0800711#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadad1589242013-05-27 00:37:30 +0000712 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
Sonic Zhangf503a522014-07-17 19:01:34 +0800713#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000714 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
715
716 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glass62cf9122013-04-26 02:53:43 +0000717 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadad1589242013-05-27 00:37:30 +0000718 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
719 gd->start_addr_sp);
Simon Glassc45e3592013-03-11 06:49:53 +0000720
721 return 0;
722}
723
724/* ARM calls relocate_code from its crt0.S */
Simon Glass2fd34e62013-11-10 10:26:59 -0700725#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glassc45e3592013-03-11 06:49:53 +0000726
727static int jump_to_copy(void)
728{
Simon Glass6d179872013-03-05 14:39:52 +0000729 /*
730 * x86 is special, but in a nice way. It uses a trampoline which
731 * enables the dcache if possible.
732 *
733 * For now, other archs use relocate_code(), which is implemented
734 * similarly for all archs. When we do generic relocation, hopefully
735 * we can make all archs enable the dcache prior to relocation.
736 */
737#ifdef CONFIG_X86
738 /*
739 * SDRAM and console are now initialised. The final stack can now
740 * be setup in SDRAM. Code execution will continue in Flash, but
741 * with the stack in SDRAM and Global Data in temporary memory
742 * (CPU cache)
743 */
744 board_init_f_r_trampoline(gd->start_addr_sp);
745#else
Masahiro Yamadad1589242013-05-27 00:37:30 +0000746 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass6d179872013-03-05 14:39:52 +0000747#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000748
749 return 0;
750}
751#endif
752
753/* Record the board_init_f() bootstage (after arch_cpu_init()) */
754static int mark_bootstage(void)
755{
756 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
757
758 return 0;
759}
760
Simon Glass863e4042014-07-10 22:23:28 -0600761static int initf_malloc(void)
762{
763#ifdef CONFIG_SYS_MALLOC_F_LEN
764 assert(gd->malloc_base); /* Set up by crt0.S */
765 gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
766 gd->malloc_ptr = 0;
767#endif
768
769 return 0;
770}
771
Simon Glassa730c5d2014-07-23 06:55:04 -0600772static int initf_dm(void)
773{
774#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
775 int ret;
776
777 ret = dm_init_and_scan(true);
778 if (ret)
779 return ret;
780#endif
781
782 return 0;
783}
784
Simon Glass5ded7e52015-01-19 22:16:12 -0700785/* Architecture-specific memory reservation */
786__weak int reserve_arch(void)
787{
788 return 0;
789}
790
Simon Glassc45e3592013-03-11 06:49:53 +0000791static init_fnc_t init_sequence_f[] = {
Simon Glass62cf9122013-04-26 02:53:43 +0000792#ifdef CONFIG_SANDBOX
793 setup_ram_buf,
794#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000795 setup_mon_len,
Simon Glass209a1a62013-06-11 11:14:42 -0700796 setup_fdt,
Kevin Hilman676f0192014-12-09 15:03:58 -0800797#ifdef CONFIG_TRACE
Simon Glass209a1a62013-06-11 11:14:42 -0700798 trace_early_init,
Kevin Hilman676f0192014-12-09 15:03:58 -0800799#endif
Simon Glasscfcb8862014-11-10 18:00:18 -0700800 initf_malloc,
Simon Glass50250b52013-03-11 14:30:42 +0000801#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
802 /* TODO: can this go into arch_cpu_init()? */
803 probecpu,
804#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000805 arch_cpu_init, /* basic arch cpu dependent setup */
806 mark_bootstage,
807#ifdef CONFIG_OF_CONTROL
808 fdtdec_check_fdt,
809#endif
Simon Glass6df5de22014-09-03 17:36:59 -0600810 initf_dm,
Simon Glassc45e3592013-03-11 06:49:53 +0000811#if defined(CONFIG_BOARD_EARLY_INIT_F)
812 board_early_init_f,
813#endif
Simon Glass50250b52013-03-11 14:30:42 +0000814 /* TODO: can any of this go into arch_cpu_init()? */
815#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
816 get_clocks, /* get CPU and bus clocks (etc.) */
817#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
818 && !defined(CONFIG_TQM885D)
819 adjust_sdram_tbs_8xx,
820#endif
821 /* TODO: can we rename this to timer_init()? */
822 init_timebase,
823#endif
Sonic Zhangf503a522014-07-17 19:01:34 +0800824#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_BLACKFIN)
Simon Glassc45e3592013-03-11 06:49:53 +0000825 timer_init, /* initialize timer */
Simon Glass50250b52013-03-11 14:30:42 +0000826#endif
Simon Glass50250b52013-03-11 14:30:42 +0000827#ifdef CONFIG_SYS_ALLOC_DPRAM
828#if !defined(CONFIG_CPM2)
829 dpram_init,
830#endif
831#endif
832#if defined(CONFIG_BOARD_POSTCLK_INIT)
833 board_postclk_init,
834#endif
Masahiro Yamada4b989cc2013-05-21 21:08:09 +0000835#ifdef CONFIG_FSL_ESDHC
836 get_clocks,
837#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000838 env_init, /* initialize environment */
Simon Glass50250b52013-03-11 14:30:42 +0000839#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
840 /* get CPU and bus clocks according to the environment variable */
841 get_clocks_866,
842 /* adjust sdram refresh rate according to the new clock */
843 sdram_adjust_866,
844 init_timebase,
845#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000846 init_baud_rate, /* initialze baudrate settings */
847 serial_init, /* serial communications setup */
848 console_init_f, /* stage 1 init of console */
Simon Glass62cf9122013-04-26 02:53:43 +0000849#ifdef CONFIG_SANDBOX
850 sandbox_early_getopt_check,
851#endif
852#ifdef CONFIG_OF_CONTROL
853 fdtdec_prepare_fdt,
Simon Glass6d179872013-03-05 14:39:52 +0000854#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000855 display_options, /* say that we are here */
856 display_text_info, /* show debugging info if required */
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900857#if defined(CONFIG_MPC8260)
Simon Glass50250b52013-03-11 14:30:42 +0000858 prt_8260_rsr,
859 prt_8260_clks,
Masahiro Yamada5a2bf982014-03-05 17:40:10 +0900860#endif /* CONFIG_MPC8260 */
Simon Glass50250b52013-03-11 14:30:42 +0000861#if defined(CONFIG_MPC83xx)
862 prt_83xx_rsr,
863#endif
864#ifdef CONFIG_PPC
865 checkcpu,
866#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000867 print_cpuinfo, /* display cpu info (and speed) */
Simon Glass50250b52013-03-11 14:30:42 +0000868#if defined(CONFIG_MPC5xxx)
869 prt_mpc5xxx_clks,
870#endif /* CONFIG_MPC5xxx */
Simon Glassc45e3592013-03-11 06:49:53 +0000871#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900872 show_board_info,
Simon Glassc45e3592013-03-11 06:49:53 +0000873#endif
Simon Glass50250b52013-03-11 14:30:42 +0000874 INIT_FUNC_WATCHDOG_INIT
875#if defined(CONFIG_MISC_INIT_F)
876 misc_init_f,
877#endif
878 INIT_FUNC_WATCHDOG_RESET
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100879#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glass50250b52013-03-11 14:30:42 +0000880 init_func_i2c,
881#endif
882#if defined(CONFIG_HARD_SPI)
883 init_func_spi,
884#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000885 announce_dram_init,
886 /* TODO: unify all these dram functions? */
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100887#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glassc45e3592013-03-11 06:49:53 +0000888 dram_init, /* configure available RAM banks */
889#endif
Paul Burton10da49b2014-04-07 10:11:20 +0100890#if defined(CONFIG_MIPS) || defined(CONFIG_PPC)
Simon Glass50250b52013-03-11 14:30:42 +0000891 init_func_ram,
892#endif
893#ifdef CONFIG_POST
894 post_init_f,
895#endif
896 INIT_FUNC_WATCHDOG_RESET
897#if defined(CONFIG_SYS_DRAM_TEST)
898 testdram,
899#endif /* CONFIG_SYS_DRAM_TEST */
900 INIT_FUNC_WATCHDOG_RESET
901
Simon Glassc45e3592013-03-11 06:49:53 +0000902#ifdef CONFIG_POST
903 init_post,
904#endif
Simon Glass50250b52013-03-11 14:30:42 +0000905 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000906 /*
907 * Now that we have DRAM mapped and working, we can
908 * relocate the code and continue running from DRAM.
909 *
910 * Reserve memory at end of RAM for (top down in that order):
911 * - area that won't get touched by U-Boot and Linux (optional)
912 * - kernel log buffer
913 * - protected RAM
914 * - LCD framebuffer
915 * - monitor code
916 * - board info struct
917 */
918 setup_dest_addr,
Thomas Choucce3e752014-08-22 11:36:47 +0800919#if defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
Sonic Zhangf503a522014-07-17 19:01:34 +0800920 /* Blackfin u-boot monitor should be on top of the ram */
921 reserve_uboot,
922#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000923#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
924 reserve_logbuffer,
925#endif
926#ifdef CONFIG_PRAM
927 reserve_pram,
928#endif
929 reserve_round_4k,
930#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
931 defined(CONFIG_ARM)
932 reserve_mmu,
933#endif
934#ifdef CONFIG_LCD
935 reserve_lcd,
936#endif
Simon Glass209a1a62013-06-11 11:14:42 -0700937 reserve_trace,
Simon Glass50250b52013-03-11 14:30:42 +0000938 /* TODO: Why the dependency on CONFIG_8xx? */
Sonic Zhangf503a522014-07-17 19:01:34 +0800939#if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
940 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
941 !defined(CONFIG_BLACKFIN)
Simon Glass50250b52013-03-11 14:30:42 +0000942 reserve_video,
943#endif
Thomas Choucce3e752014-08-22 11:36:47 +0800944#if !defined(CONFIG_BLACKFIN) && !defined(CONFIG_NIOS2)
Simon Glassc45e3592013-03-11 06:49:53 +0000945 reserve_uboot,
Sonic Zhangf503a522014-07-17 19:01:34 +0800946#endif
Simon Glass4d2aee82013-03-05 14:39:45 +0000947#ifndef CONFIG_SPL_BUILD
Simon Glassc45e3592013-03-11 06:49:53 +0000948 reserve_malloc,
949 reserve_board,
Simon Glass4d2aee82013-03-05 14:39:45 +0000950#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000951 setup_machine,
952 reserve_global_data,
953 reserve_fdt,
Simon Glass5ded7e52015-01-19 22:16:12 -0700954 reserve_arch,
Simon Glassc45e3592013-03-11 06:49:53 +0000955 reserve_stacks,
956 setup_dram_config,
957 show_dram_config,
Simon Glass50250b52013-03-11 14:30:42 +0000958#ifdef CONFIG_PPC
959 setup_board_part1,
960 INIT_FUNC_WATCHDOG_RESET
961 setup_board_part2,
962#endif
Simon Glassc45e3592013-03-11 06:49:53 +0000963 display_new_sp,
Simon Glass50250b52013-03-11 14:30:42 +0000964#ifdef CONFIG_SYS_EXTBDINFO
965 setup_board_extra,
966#endif
967 INIT_FUNC_WATCHDOG_RESET
Simon Glassc45e3592013-03-11 06:49:53 +0000968 reloc_fdt,
969 setup_reloc,
Simon Glassd50b2f42015-01-01 16:18:09 -0700970#ifdef CONFIG_X86
971 copy_uboot_to_ram,
972 clear_bss,
973 do_elf_reloc_fixups,
974#endif
Simon Glass2fd34e62013-11-10 10:26:59 -0700975#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glassc45e3592013-03-11 06:49:53 +0000976 jump_to_copy,
977#endif
978 NULL,
979};
980
981void board_init_f(ulong boot_flags)
982{
York Sun021d2022014-05-02 17:28:04 -0700983#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
984 /*
985 * For some archtectures, global data is initialized and used before
986 * calling this function. The data should be preserved. For others,
987 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
988 * here to host global data until relocation.
989 */
Simon Glassc45e3592013-03-11 06:49:53 +0000990 gd_t data;
991
992 gd = &data;
993
David Feng1735de82013-12-14 11:47:36 +0800994 /*
995 * Clear global data before it is accessed at debug print
996 * in initcall_run_list. Otherwise the debug print probably
997 * get the wrong vaule of gd->have_console.
998 */
David Feng1735de82013-12-14 11:47:36 +0800999 zero_global_data();
1000#endif
1001
Simon Glassc45e3592013-03-11 06:49:53 +00001002 gd->flags = boot_flags;
Alexey Brodkin07236912013-11-27 22:32:40 +04001003 gd->have_console = 0;
Simon Glassc45e3592013-03-11 06:49:53 +00001004
1005 if (initcall_run_list(init_sequence_f))
1006 hang();
1007
Simon Glass2fd34e62013-11-10 10:26:59 -07001008#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glassc45e3592013-03-11 06:49:53 +00001009 /* NOTREACHED - jump_to_copy() does not return */
1010 hang();
1011#endif
1012}
Simon Glass6d179872013-03-05 14:39:52 +00001013
1014#ifdef CONFIG_X86
1015/*
1016 * For now this code is only used on x86.
1017 *
1018 * init_sequence_f_r is the list of init functions which are run when
1019 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1020 * The following limitations must be considered when implementing an
1021 * '_f_r' function:
1022 * - 'static' variables are read-only
1023 * - Global Data (gd->xxx) is read/write
1024 *
1025 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1026 * supported). It _should_, if possible, copy global data to RAM and
1027 * initialise the CPU caches (to speed up the relocation process)
1028 *
1029 * NOTE: At present only x86 uses this route, but it is intended that
1030 * all archs will move to this when generic relocation is implemented.
1031 */
1032static init_fnc_t init_sequence_f_r[] = {
1033 init_cache_f_r,
Simon Glass6d179872013-03-05 14:39:52 +00001034
1035 NULL,
1036};
1037
1038void board_init_f_r(void)
1039{
1040 if (initcall_run_list(init_sequence_f_r))
1041 hang();
1042
1043 /*
1044 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1045 * Transfer execution from Flash to RAM by calculating the address
1046 * of the in-RAM copy of board_init_r() and calling it
1047 */
1048 (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
1049
1050 /* NOTREACHED - board_init_r() does not return */
1051 hang();
1052}
Simon Glassd2542ff2015-02-07 11:51:34 -07001053#else
1054ulong board_init_f_mem(ulong top)
1055{
1056 /* Leave space for the stack we are running with now */
1057 top -= 0x40;
1058
1059 top -= sizeof(struct global_data);
1060 top = ALIGN(top, 16);
1061 gd = (struct global_data *)top;
1062 memset((void *)gd, '\0', sizeof(*gd));
1063
1064#ifdef CONFIG_SYS_MALLOC_F_LEN
1065 top -= CONFIG_SYS_MALLOC_F_LEN;
1066 gd->malloc_base = top;
1067#endif
1068
1069 return top;
1070}
Simon Glass6d179872013-03-05 14:39:52 +00001071#endif /* CONFIG_X86 */