blob: d405b5b407e817677afcea7f626c44c2c9c16d23 [file] [log] [blame]
Simon Glass1938f4a2013-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 Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glass1938f4a2013-03-11 06:49:53 +000011 */
12
13#include <common.h>
14#include <linux/compiler.h>
15#include <version.h>
Simon Glass24b852a2015-11-08 23:47:45 -070016#include <console.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000017#include <environment.h>
Simon Glassab7cd622014-07-23 06:55:04 -060018#include <dm.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000019#include <fdtdec.h>
Simon Glassf828bf22013-04-20 08:42:41 +000020#include <fs.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000021#if defined(CONFIG_CMD_IDE)
22#include <ide.h>
23#endif
24#include <i2c.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000025#include <initcall.h>
26#include <logbuff.h>
Simon Glassfb5cf7f2015-02-27 22:06:36 -070027#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050028#include <mapmem.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000029
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
Gabriel Huauec3b4822014-09-03 13:57:54 -070040#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Gabriel Huaua76df702014-07-26 11:35:43 -070041#include <asm/mp.h>
42#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +000043
Simon Glassa733b062013-04-26 02:53:43 +000044#include <os.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000045#include <post.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000046#include <spi.h>
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020047#include <status_led.h>
Simon Glass1057e6c2016-02-24 09:14:50 -070048#include <timer.h>
Simon Glass71c52db2013-06-11 11:14:42 -070049#include <trace.h>
Simon Glass5a541942016-01-18 19:52:21 -070050#include <video.h>
Simon Glasse4fef6c2013-03-11 14:30:42 +000051#include <watchdog.h>
Simon Glassa733b062013-04-26 02:53:43 +000052#include <asm/errno.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000053#include <asm/io.h>
54#include <asm/sections.h>
Alexey Brodkin3fb80162015-02-24 19:40:36 +030055#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +000056#include <asm/init_helpers.h>
57#include <asm/relocate.h>
58#endif
Simon Glassa733b062013-04-26 02:53:43 +000059#ifdef CONFIG_SANDBOX
60#include <asm/state.h>
61#endif
Simon Glassab7cd622014-07-23 06:55:04 -060062#include <dm/root.h>
Simon Glass1938f4a2013-03-11 06:49:53 +000063#include <linux/compiler.h>
64
65/*
66 * Pointer to initial global data area
67 *
68 * Here we initialize it if needed.
69 */
70#ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
71#undef XTRN_DECLARE_GLOBAL_DATA_PTR
72#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
73DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
74#else
75DECLARE_GLOBAL_DATA_PTR;
76#endif
77
78/*
Simon Glass4c509342015-04-28 20:25:03 -060079 * TODO(sjg@chromium.org): IMO this code should be
Simon Glass1938f4a2013-03-11 06:49:53 +000080 * refactored to a single function, something like:
81 *
82 * void led_set_state(enum led_colour_t colour, int on);
83 */
84/************************************************************************
85 * Coloured LED functionality
86 ************************************************************************
87 * May be supplied by boards if desired
88 */
Jeroen Hofsteec5d40012014-06-23 23:20:19 +020089__weak void coloured_LED_init(void) {}
90__weak void red_led_on(void) {}
91__weak void red_led_off(void) {}
92__weak void green_led_on(void) {}
93__weak void green_led_off(void) {}
94__weak void yellow_led_on(void) {}
95__weak void yellow_led_off(void) {}
96__weak void blue_led_on(void) {}
97__weak void blue_led_off(void) {}
Simon Glass1938f4a2013-03-11 06:49:53 +000098
99/*
100 * Why is gd allocated a register? Prior to reloc it might be better to
101 * just pass it around to each function in this file?
102 *
103 * After reloc one could argue that it is hardly used and doesn't need
104 * to be in a register. Or if it is it should perhaps hold pointers to all
105 * global data for all modules, so that post-reloc we can avoid the massive
106 * literal pool we get on ARM. Or perhaps just encourage each module to use
107 * a structure...
108 */
109
110/*
111 * Could the CONFIG_SPL_BUILD infection become a flag in gd?
112 */
113
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800114#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000115static int init_func_watchdog_init(void)
116{
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800117# if defined(CONFIG_HW_WATCHDOG) && (defined(CONFIG_BLACKFIN) || \
118 defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
Stefan Roese14a380a2015-03-10 08:04:36 +0100119 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
120 defined(CONFIG_IMX_WATCHDOG))
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800121 hw_watchdog_init();
122# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000123 puts(" Watchdog enabled\n");
124 WATCHDOG_RESET();
125
126 return 0;
127}
128
129int init_func_watchdog_reset(void)
130{
131 WATCHDOG_RESET();
132
133 return 0;
134}
135#endif /* CONFIG_WATCHDOG */
136
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200137__weak void board_add_ram_info(int use_default)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000138{
139 /* please define platform specific board_add_ram_info() */
140}
141
Simon Glass1938f4a2013-03-11 06:49:53 +0000142static int init_baud_rate(void)
143{
144 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
145 return 0;
146}
147
148static int display_text_info(void)
149{
Ben Stoltz9b217492015-07-31 09:31:37 -0600150#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100151 ulong bss_start, bss_end, text_base;
Simon Glass1938f4a2013-03-11 06:49:53 +0000152
Simon Glass632efa72013-03-11 07:06:48 +0000153 bss_start = (ulong)&__bss_start;
154 bss_end = (ulong)&__bss_end;
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100155
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800156#ifdef CONFIG_SYS_TEXT_BASE
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100157 text_base = CONFIG_SYS_TEXT_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800158#else
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100159 text_base = CONFIG_SYS_MONITOR_BASE;
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800160#endif
Daniel Schwierzeck9fdee7d2014-11-15 23:46:53 +0100161
162 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
163 text_base, bss_start, bss_end);
Simon Glassa733b062013-04-26 02:53:43 +0000164#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000165
Simon Glass1938f4a2013-03-11 06:49:53 +0000166#ifdef CONFIG_USE_IRQ
167 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
168 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
169#endif
170
171 return 0;
172}
173
174static int announce_dram_init(void)
175{
176 puts("DRAM: ");
177 return 0;
178}
179
angelo@sysam.ite310b932015-02-12 01:40:17 +0100180#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000181static int init_func_ram(void)
182{
183#ifdef CONFIG_BOARD_TYPES
184 int board_type = gd->board_type;
185#else
186 int board_type = 0; /* use dummy arg */
187#endif
188
189 gd->ram_size = initdram(board_type);
190
191 if (gd->ram_size > 0)
192 return 0;
193
194 puts("*** failed ***\n");
195 return 1;
196}
197#endif
198
Simon Glass1938f4a2013-03-11 06:49:53 +0000199static int show_dram_config(void)
200{
York Sunfa39ffe2014-05-02 17:28:05 -0700201 unsigned long long size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000202
203#ifdef CONFIG_NR_DRAM_BANKS
204 int i;
205
206 debug("\nRAM Configuration:\n");
207 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
208 size += gd->bd->bi_dram[i].size;
Bin Meng715f5992015-08-06 01:31:20 -0700209 debug("Bank #%d: %llx ", i,
210 (unsigned long long)(gd->bd->bi_dram[i].start));
Simon Glass1938f4a2013-03-11 06:49:53 +0000211#ifdef DEBUG
212 print_size(gd->bd->bi_dram[i].size, "\n");
213#endif
214 }
215 debug("\nDRAM: ");
216#else
217 size = gd->ram_size;
218#endif
219
Simon Glasse4fef6c2013-03-11 14:30:42 +0000220 print_size(size, "");
221 board_add_ram_info(0);
222 putc('\n');
Simon Glass1938f4a2013-03-11 06:49:53 +0000223
224 return 0;
225}
226
Jeroen Hofsteedd2a6cd2014-10-08 22:57:22 +0200227__weak void dram_init_banksize(void)
Simon Glass1938f4a2013-03-11 06:49:53 +0000228{
229#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
230 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
231 gd->bd->bi_dram[0].size = get_effective_memsize();
232#endif
233}
234
Heiko Schocherea818db2013-01-29 08:53:15 +0100235#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000236static int init_func_i2c(void)
237{
238 puts("I2C: ");
trem815a76f2013-09-21 18:13:34 +0200239#ifdef CONFIG_SYS_I2C
240 i2c_init_all();
241#else
Simon Glasse4fef6c2013-03-11 14:30:42 +0000242 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
trem815a76f2013-09-21 18:13:34 +0200243#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000244 puts("ready\n");
245 return 0;
246}
247#endif
248
249#if defined(CONFIG_HARD_SPI)
250static int init_func_spi(void)
251{
252 puts("SPI: ");
253 spi_init();
254 puts("ready\n");
255 return 0;
256}
257#endif
258
259__maybe_unused
Simon Glass1938f4a2013-03-11 06:49:53 +0000260static int zero_global_data(void)
261{
262 memset((void *)gd, '\0', sizeof(gd_t));
263
264 return 0;
265}
266
267static int setup_mon_len(void)
268{
Michal Simeke945f6d2014-05-08 16:08:44 +0200269#if defined(__ARM__) || defined(__MICROBLAZE__)
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100270 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
Ben Stoltz9b217492015-07-31 09:31:37 -0600271#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
Simon Glassa733b062013-04-26 02:53:43 +0000272 gd->mon_len = (ulong)&_end - (ulong)_init;
Thomas Chou5ff10aa2014-08-22 11:36:47 +0800273#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_NIOS2)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800274 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800275#elif defined(CONFIG_NDS32)
276 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
Simon Glassb0b35952016-05-14 18:49:28 -0600277#elif defined(CONFIG_SYS_MONITOR_BASE)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000278 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
279 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
Simon Glass632efa72013-03-11 07:06:48 +0000280#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000281 return 0;
282}
283
284__weak int arch_cpu_init(void)
285{
286 return 0;
287}
288
Simon Glassa733b062013-04-26 02:53:43 +0000289#ifdef CONFIG_SANDBOX
290static int setup_ram_buf(void)
291{
Simon Glass5c2859c2013-11-10 10:27:03 -0700292 struct sandbox_state *state = state_get_current();
293
294 gd->arch.ram_buf = state->ram_buf;
295 gd->ram_size = state->ram_size;
Simon Glassa733b062013-04-26 02:53:43 +0000296
297 return 0;
298}
299#endif
300
Simon Glass1938f4a2013-03-11 06:49:53 +0000301/* Get the top of usable RAM */
302__weak ulong board_get_usable_ram_top(ulong total_size)
303{
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700304#ifdef CONFIG_SYS_SDRAM_BASE
305 /*
Simon Glass4c509342015-04-28 20:25:03 -0600306 * Detect whether we have so much RAM that it goes past the end of our
Stephen Warren1e4d11a2014-12-23 10:34:49 -0700307 * 32-bit address space. If so, clip the usable RAM so it doesn't.
308 */
309 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
310 /*
311 * Will wrap back to top of 32-bit space when reservations
312 * are made.
313 */
314 return 0;
315#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000316 return gd->ram_top;
317}
318
York Sunaabd7dd2015-12-07 11:05:29 -0800319__weak phys_size_t board_reserve_ram_top(phys_size_t ram_size)
320{
321#ifdef CONFIG_SYS_MEM_TOP_HIDE
322 return ram_size - CONFIG_SYS_MEM_TOP_HIDE;
323#else
324 return ram_size;
325#endif
326}
327
Simon Glass1938f4a2013-03-11 06:49:53 +0000328static int setup_dest_addr(void)
329{
330 debug("Monitor len: %08lX\n", gd->mon_len);
331 /*
332 * Ram is setup, size stored in gd !!
333 */
334 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
York Sune8149522015-12-04 11:57:07 -0800335#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
336 /* Reserve memory for secure MMU tables, and/or security monitor */
337 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
338 /*
339 * Record secure memory location. Need recalcuate if memory splits
340 * into banks, or the ram base is not zero.
341 */
342 gd->secure_ram = gd->ram_size;
343#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000344 /*
345 * Subtract specified amount of memory to hide so that it won't
346 * get "touched" at all by U-Boot. By fixing up gd->ram_size
347 * the Linux kernel should now get passed the now "corrected"
York Sunaabd7dd2015-12-07 11:05:29 -0800348 * memory size and won't touch it either. This has been used
349 * by arch/powerpc exclusively. Now ARMv8 takes advantage of
350 * thie mechanism. If memory is split into banks, addresses
351 * need to be calculated.
Simon Glass1938f4a2013-03-11 06:49:53 +0000352 */
York Sunaabd7dd2015-12-07 11:05:29 -0800353 gd->ram_size = board_reserve_ram_top(gd->ram_size);
354
Simon Glass1938f4a2013-03-11 06:49:53 +0000355#ifdef CONFIG_SYS_SDRAM_BASE
356 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
357#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000358 gd->ram_top += get_effective_memsize();
Simon Glass1938f4a2013-03-11 06:49:53 +0000359 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000360 gd->relocaddr = gd->ram_top;
Simon Glass1938f4a2013-03-11 06:49:53 +0000361 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
Gabriel Huauec3b4822014-09-03 13:57:54 -0700362#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
Simon Glasse4fef6c2013-03-11 14:30:42 +0000363 /*
364 * We need to make sure the location we intend to put secondary core
365 * boot code is reserved and not used by any part of u-boot
366 */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000367 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
368 gd->relocaddr = determine_mp_bootpg(NULL);
369 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000370 }
371#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000372 return 0;
373}
374
Francois Retief1e85cce2015-11-23 13:05:44 +0200375#if defined(CONFIG_SPARC)
376static int reserve_prom(void)
377{
378 /* defined in arch/sparc/cpu/leon?/prom.c */
379 extern void *__prom_start_reloc;
380 int size = 8192; /* page table = 2k, prom = 6k */
381 gd->relocaddr -= size;
382 __prom_start_reloc = map_sysmem(gd->relocaddr + 2048, size - 2048);
383 debug("Reserving %dk for PROM and page table at %08lx\n", size,
384 gd->relocaddr);
385 return 0;
386}
387#endif
388
Simon Glass1938f4a2013-03-11 06:49:53 +0000389#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
390static int reserve_logbuffer(void)
391{
392 /* reserve kernel log buffer */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000393 gd->relocaddr -= LOGBUFF_RESERVE;
Simon Glass1938f4a2013-03-11 06:49:53 +0000394 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000395 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000396 return 0;
397}
398#endif
399
400#ifdef CONFIG_PRAM
401/* reserve protected RAM */
402static int reserve_pram(void)
403{
404 ulong reg;
405
406 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000407 gd->relocaddr -= (reg << 10); /* size is in kB */
Simon Glass1938f4a2013-03-11 06:49:53 +0000408 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000409 gd->relocaddr);
Simon Glass1938f4a2013-03-11 06:49:53 +0000410 return 0;
411}
412#endif /* CONFIG_PRAM */
413
414/* Round memory pointer down to next 4 kB limit */
415static int reserve_round_4k(void)
416{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000417 gd->relocaddr &= ~(4096 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000418 return 0;
419}
420
421#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
422 defined(CONFIG_ARM)
423static int reserve_mmu(void)
424{
425 /* reserve TLB table */
David Fengcce6be72013-12-14 11:47:36 +0800426 gd->arch.tlb_size = PGTABLE_SIZE;
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000427 gd->relocaddr -= gd->arch.tlb_size;
Simon Glass1938f4a2013-03-11 06:49:53 +0000428
429 /* round down to next 64 kB limit */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000430 gd->relocaddr &= ~(0x10000 - 1);
Simon Glass1938f4a2013-03-11 06:49:53 +0000431
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000432 gd->arch.tlb_addr = gd->relocaddr;
Simon Glass1938f4a2013-03-11 06:49:53 +0000433 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
434 gd->arch.tlb_addr + gd->arch.tlb_size);
435 return 0;
436}
437#endif
438
Simon Glass5a541942016-01-18 19:52:21 -0700439#ifdef CONFIG_DM_VIDEO
440static int reserve_video(void)
441{
442 ulong addr;
443 int ret;
444
445 addr = gd->relocaddr;
446 ret = video_reserve(&addr);
447 if (ret)
448 return ret;
449 gd->relocaddr = addr;
450
451 return 0;
452}
453#else
454
455# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000456static int reserve_lcd(void)
457{
Simon Glass5a541942016-01-18 19:52:21 -0700458# ifdef CONFIG_FB_ADDR
Simon Glass1938f4a2013-03-11 06:49:53 +0000459 gd->fb_base = CONFIG_FB_ADDR;
Simon Glass5a541942016-01-18 19:52:21 -0700460# else
Simon Glass1938f4a2013-03-11 06:49:53 +0000461 /* reserve memory for LCD display (always full pages) */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000462 gd->relocaddr = lcd_setmem(gd->relocaddr);
463 gd->fb_base = gd->relocaddr;
Simon Glass5a541942016-01-18 19:52:21 -0700464# endif /* CONFIG_FB_ADDR */
465
Simon Glass1938f4a2013-03-11 06:49:53 +0000466 return 0;
467}
Simon Glass5a541942016-01-18 19:52:21 -0700468# endif /* CONFIG_LCD */
Simon Glass1938f4a2013-03-11 06:49:53 +0000469
Simon Glass5a541942016-01-18 19:52:21 -0700470# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Simon Glass8703ef32016-01-18 19:52:20 -0700471 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
472 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
473static int reserve_legacy_video(void)
474{
475 /* reserve memory for video display (always full pages) */
476 gd->relocaddr = video_setmem(gd->relocaddr);
477 gd->fb_base = gd->relocaddr;
478
479 return 0;
480}
Simon Glass5a541942016-01-18 19:52:21 -0700481# endif
482#endif /* !CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700483
Simon Glass71c52db2013-06-11 11:14:42 -0700484static int reserve_trace(void)
485{
486#ifdef CONFIG_TRACE
487 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
488 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
489 debug("Reserving %dk for trace data at: %08lx\n",
490 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
491#endif
492
493 return 0;
494}
495
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-05-27 00:37:30 +0000502 gd->relocaddr -= gd->mon_len;
503 gd->relocaddr &= ~(4096 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000504#ifdef CONFIG_E500
505 /* round down to next 64 kB limit so that IVPR stays aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000506 gd->relocaddr &= ~(65536 - 1);
Simon Glasse4fef6c2013-03-11 14:30:42 +0000507#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000508
509 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000510 gd->relocaddr);
511
512 gd->start_addr_sp = gd->relocaddr;
513
Simon Glass1938f4a2013-03-11 06:49:53 +0000514 return 0;
515}
516
Simon Glass8cae8a62013-03-05 14:39:45 +0000517#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +0000518/* reserve memory for malloc() area */
519static int reserve_malloc(void)
520{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000521 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
Simon Glass1938f4a2013-03-11 06:49:53 +0000522 debug("Reserving %dk for malloc() at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000523 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000524 return 0;
525}
526
527/* (permanently) allocate a Board Info struct */
528static int reserve_board(void)
529{
Sonic Zhangd54d7eb2014-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 Glass1938f4a2013-03-11 06:49:53 +0000537 return 0;
538}
Simon Glass8cae8a62013-03-05 14:39:45 +0000539#endif
Simon Glass1938f4a2013-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 Yamadaa0ba2792013-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 Glass1938f4a2013-03-11 06:49:53 +0000553 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000554 sizeof(gd_t), gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000555 return 0;
556}
557
558static int reserve_fdt(void)
559{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100560#ifndef CONFIG_OF_EMBED
Simon Glass1938f4a2013-03-11 06:49:53 +0000561 /*
Simon Glass4c509342015-04-28 20:25:03 -0600562 * If the device tree is sitting immediately above our image then we
Simon Glass1938f4a2013-03-11 06:49:53 +0000563 * must relocate it. If it is embedded in the data section, then it
564 * will be relocated with other data.
565 */
566 if (gd->fdt_blob) {
567 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
568
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000569 gd->start_addr_sp -= gd->fdt_size;
570 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
Simon Glassa733b062013-04-26 02:53:43 +0000571 debug("Reserving %lu Bytes for FDT at: %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000572 gd->fdt_size, gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000573 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100574#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000575
576 return 0;
577}
578
Andreas Bießmann68145d42015-02-06 23:06:45 +0100579int arch_reserve_stacks(void)
580{
581 return 0;
582}
583
Simon Glass1938f4a2013-03-11 06:49:53 +0000584static int reserve_stacks(void)
585{
Andreas Bießmann68145d42015-02-06 23:06:45 +0100586 /* make stack pointer 16-byte aligned */
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000587 gd->start_addr_sp -= 16;
588 gd->start_addr_sp &= ~0xf;
Simon Glass1938f4a2013-03-11 06:49:53 +0000589
590 /*
Simon Glass4c509342015-04-28 20:25:03 -0600591 * let the architecture-specific code tailor gd->start_addr_sp and
Andreas Bießmann68145d42015-02-06 23:06:45 +0100592 * gd->irq_sp
Simon Glass1938f4a2013-03-11 06:49:53 +0000593 */
Andreas Bießmann68145d42015-02-06 23:06:45 +0100594 return arch_reserve_stacks();
Simon Glass1938f4a2013-03-11 06:49:53 +0000595}
596
597static int display_new_sp(void)
598{
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000599 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000600
601 return 0;
602}
603
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100604#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000605static int setup_board_part1(void)
606{
607 bd_t *bd = gd->bd;
608
609 /*
610 * Save local variables to board info struct
611 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000612 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
613 bd->bi_memsize = gd->ram_size; /* size in bytes */
614
615#ifdef CONFIG_SYS_SRAM_BASE
616 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
617 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
618#endif
619
Masahiro Yamada58dac322014-03-05 17:40:10 +0900620#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
Simon Glasse4fef6c2013-03-11 14:30:42 +0000621 defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
622 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
623#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100624#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000625 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
626#endif
627#if defined(CONFIG_MPC83xx)
628 bd->bi_immrbar = CONFIG_SYS_IMMR;
629#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000630
631 return 0;
632}
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100633#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000634
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +0100635#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000636static int setup_board_part2(void)
637{
638 bd_t *bd = gd->bd;
639
640 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
641 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
642#if defined(CONFIG_CPM2)
643 bd->bi_cpmfreq = gd->arch.cpm_clk;
644 bd->bi_brgfreq = gd->arch.brg_clk;
645 bd->bi_sccfreq = gd->arch.scc_clk;
646 bd->bi_vco = gd->arch.vco_out;
647#endif /* CONFIG_CPM2 */
648#if defined(CONFIG_MPC512X)
649 bd->bi_ipsfreq = gd->arch.ips_clk;
650#endif /* CONFIG_MPC512X */
651#if defined(CONFIG_MPC5xxx)
652 bd->bi_ipbfreq = gd->arch.ipb_clk;
653 bd->bi_pcifreq = gd->pci_clk;
654#endif /* CONFIG_MPC5xxx */
Alison Wang1313db42015-02-12 18:33:15 +0800655#if defined(CONFIG_M68K) && defined(CONFIG_PCI)
656 bd->bi_pcifreq = gd->pci_clk;
657#endif
658#if defined(CONFIG_EXTRA_CLOCK)
659 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
660 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
661 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
662#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000663
664 return 0;
665}
666#endif
667
668#ifdef CONFIG_SYS_EXTBDINFO
669static int setup_board_extra(void)
670{
671 bd_t *bd = gd->bd;
672
673 strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
674 strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
675 sizeof(bd->bi_r_version));
676
677 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
678 bd->bi_plb_busfreq = gd->bus_clk;
679#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
680 defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
681 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
682 bd->bi_pci_busfreq = get_PCI_freq();
683 bd->bi_opbfreq = get_OPB_freq();
684#elif defined(CONFIG_XILINX_405)
685 bd->bi_pci_busfreq = get_PCI_freq();
686#endif
687
688 return 0;
689}
690#endif
691
Simon Glass1938f4a2013-03-11 06:49:53 +0000692#ifdef CONFIG_POST
693static int init_post(void)
694{
695 post_bootmode_init();
696 post_run(NULL, POST_ROM | post_bootmode_get(0));
697
698 return 0;
699}
700#endif
701
Simon Glass1938f4a2013-03-11 06:49:53 +0000702static int setup_dram_config(void)
703{
704 /* Ram is board specific, so move it to board code ... */
705 dram_init_banksize();
706
707 return 0;
708}
709
710static int reloc_fdt(void)
711{
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100712#ifndef CONFIG_OF_EMBED
Simon Glassf05ad9b2015-08-04 12:33:39 -0600713 if (gd->flags & GD_FLG_SKIP_RELOC)
714 return 0;
Simon Glass1938f4a2013-03-11 06:49:53 +0000715 if (gd->new_fdt) {
716 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
717 gd->fdt_blob = gd->new_fdt;
718 }
Siva Durga Prasad Paladugue9acb9e2015-12-03 15:46:03 +0100719#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000720
721 return 0;
722}
723
724static int setup_reloc(void)
725{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600726 if (gd->flags & GD_FLG_SKIP_RELOC) {
727 debug("Skipping relocation due to flag\n");
728 return 0;
729 }
730
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800731#ifdef CONFIG_SYS_TEXT_BASE
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000732 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
angelo@sysam.ite310b932015-02-12 01:40:17 +0100733#ifdef CONFIG_M68K
734 /*
735 * On all ColdFire arch cpu, monitor code starts always
736 * just after the default vector table location, so at 0x400
737 */
738 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
739#endif
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800740#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000741 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
742
743 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
Simon Glassa733b062013-04-26 02:53:43 +0000744 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000745 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
746 gd->start_addr_sp);
Simon Glass1938f4a2013-03-11 06:49:53 +0000747
748 return 0;
749}
750
751/* ARM calls relocate_code from its crt0.S */
Simon Glass808434c2013-11-10 10:26:59 -0700752#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +0000753
754static int jump_to_copy(void)
755{
Simon Glassf05ad9b2015-08-04 12:33:39 -0600756 if (gd->flags & GD_FLG_SKIP_RELOC)
757 return 0;
Simon Glass48a33802013-03-05 14:39:52 +0000758 /*
759 * x86 is special, but in a nice way. It uses a trampoline which
760 * enables the dcache if possible.
761 *
762 * For now, other archs use relocate_code(), which is implemented
763 * similarly for all archs. When we do generic relocation, hopefully
764 * we can make all archs enable the dcache prior to relocation.
765 */
Alexey Brodkin3fb80162015-02-24 19:40:36 +0300766#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +0000767 /*
768 * SDRAM and console are now initialised. The final stack can now
769 * be setup in SDRAM. Code execution will continue in Flash, but
770 * with the stack in SDRAM and Global Data in temporary memory
771 * (CPU cache)
772 */
Simon Glassf0c7d9c2015-08-10 20:44:32 -0600773 arch_setup_gd(gd->new_gd);
Simon Glass48a33802013-03-05 14:39:52 +0000774 board_init_f_r_trampoline(gd->start_addr_sp);
775#else
Masahiro Yamadaa0ba2792013-05-27 00:37:30 +0000776 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +0000777#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000778
779 return 0;
780}
781#endif
782
783/* Record the board_init_f() bootstage (after arch_cpu_init()) */
784static int mark_bootstage(void)
785{
786 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
787
788 return 0;
789}
790
Simon Glass9854a872015-11-08 23:47:48 -0700791static int initf_console_record(void)
792{
793#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
794 return console_record_init();
795#else
796 return 0;
797#endif
798}
799
Simon Glassab7cd622014-07-23 06:55:04 -0600800static int initf_dm(void)
801{
802#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
803 int ret;
804
805 ret = dm_init_and_scan(true);
806 if (ret)
807 return ret;
808#endif
Simon Glass1057e6c2016-02-24 09:14:50 -0700809#ifdef CONFIG_TIMER_EARLY
810 ret = dm_timer_init();
811 if (ret)
812 return ret;
813#endif
Simon Glassab7cd622014-07-23 06:55:04 -0600814
815 return 0;
816}
817
Simon Glass146251f2015-01-19 22:16:12 -0700818/* Architecture-specific memory reservation */
819__weak int reserve_arch(void)
820{
821 return 0;
822}
823
Simon Glassd4c671c2015-03-05 12:25:16 -0700824__weak int arch_cpu_init_dm(void)
825{
826 return 0;
827}
828
Simon Glass1938f4a2013-03-11 06:49:53 +0000829static init_fnc_t init_sequence_f[] = {
Simon Glassa733b062013-04-26 02:53:43 +0000830#ifdef CONFIG_SANDBOX
831 setup_ram_buf,
832#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000833 setup_mon_len,
Simon Glassb45122f2015-02-27 22:06:34 -0700834#ifdef CONFIG_OF_CONTROL
Simon Glass08793612015-02-27 22:06:35 -0700835 fdtdec_setup,
Simon Glassb45122f2015-02-27 22:06:34 -0700836#endif
Kevin Hilmand2107182014-12-09 15:03:58 -0800837#ifdef CONFIG_TRACE
Simon Glass71c52db2013-06-11 11:14:42 -0700838 trace_early_init,
Kevin Hilmand2107182014-12-09 15:03:58 -0800839#endif
Simon Glass768e0f52014-11-10 18:00:18 -0700840 initf_malloc,
Simon Glass9854a872015-11-08 23:47:48 -0700841 initf_console_record,
Simon Glasse4fef6c2013-03-11 14:30:42 +0000842#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
843 /* TODO: can this go into arch_cpu_init()? */
844 probecpu,
845#endif
Bin Menga52a068e2015-08-20 06:40:18 -0700846#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
847 x86_fsp_init,
848#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000849 arch_cpu_init, /* basic arch cpu dependent setup */
Simon Glass3ea09532014-09-03 17:36:59 -0600850 initf_dm,
Simon Glassd4c671c2015-03-05 12:25:16 -0700851 arch_cpu_init_dm,
Thomas Chou67521952015-10-30 15:35:51 +0800852 mark_bootstage, /* need timer, go after init dm */
Simon Glass1938f4a2013-03-11 06:49:53 +0000853#if defined(CONFIG_BOARD_EARLY_INIT_F)
854 board_early_init_f,
855#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000856 /* TODO: can any of this go into arch_cpu_init()? */
857#if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
858 get_clocks, /* get CPU and bus clocks (etc.) */
859#if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
860 && !defined(CONFIG_TQM885D)
861 adjust_sdram_tbs_8xx,
862#endif
863 /* TODO: can we rename this to timer_init()? */
864 init_timebase,
865#endif
Bin Meng2317cf02015-12-08 17:31:40 -0800866#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
Francois Retiefc97088c2015-10-28 15:18:22 +0200867 defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
868 defined(CONFIG_SPARC)
Simon Glass1938f4a2013-03-11 06:49:53 +0000869 timer_init, /* initialize timer */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000870#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000871#ifdef CONFIG_SYS_ALLOC_DPRAM
872#if !defined(CONFIG_CPM2)
873 dpram_init,
874#endif
875#endif
876#if defined(CONFIG_BOARD_POSTCLK_INIT)
877 board_postclk_init,
878#endif
Peng Fan76648462015-10-30 17:30:02 +0800879#if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
angelo@sysam.ite310b932015-02-12 01:40:17 +0100880 get_clocks,
881#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000882 env_init, /* initialize environment */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000883#if defined(CONFIG_8xx_CPUCLK_DEFAULT)
884 /* get CPU and bus clocks according to the environment variable */
885 get_clocks_866,
886 /* adjust sdram refresh rate according to the new clock */
887 sdram_adjust_866,
888 init_timebase,
889#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000890 init_baud_rate, /* initialze baudrate settings */
891 serial_init, /* serial communications setup */
892 console_init_f, /* stage 1 init of console */
Simon Glassa733b062013-04-26 02:53:43 +0000893#ifdef CONFIG_SANDBOX
894 sandbox_early_getopt_check,
895#endif
896#ifdef CONFIG_OF_CONTROL
897 fdtdec_prepare_fdt,
Simon Glass48a33802013-03-05 14:39:52 +0000898#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000899 display_options, /* say that we are here */
900 display_text_info, /* show debugging info if required */
Masahiro Yamada58dac322014-03-05 17:40:10 +0900901#if defined(CONFIG_MPC8260)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000902 prt_8260_rsr,
903 prt_8260_clks,
Masahiro Yamada58dac322014-03-05 17:40:10 +0900904#endif /* CONFIG_MPC8260 */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000905#if defined(CONFIG_MPC83xx)
906 prt_83xx_rsr,
907#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100908#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000909 checkcpu,
910#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000911 print_cpuinfo, /* display cpu info (and speed) */
Simon Glasse4fef6c2013-03-11 14:30:42 +0000912#if defined(CONFIG_MPC5xxx)
913 prt_mpc5xxx_clks,
914#endif /* CONFIG_MPC5xxx */
Simon Glass1938f4a2013-03-11 06:49:53 +0000915#if defined(CONFIG_DISPLAY_BOARDINFO)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +0900916 show_board_info,
Simon Glass1938f4a2013-03-11 06:49:53 +0000917#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000918 INIT_FUNC_WATCHDOG_INIT
919#if defined(CONFIG_MISC_INIT_F)
920 misc_init_f,
921#endif
922 INIT_FUNC_WATCHDOG_RESET
Heiko Schocherea818db2013-01-29 08:53:15 +0100923#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000924 init_func_i2c,
925#endif
926#if defined(CONFIG_HARD_SPI)
927 init_func_spi,
928#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000929 announce_dram_init,
930 /* TODO: unify all these dram functions? */
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800931#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
932 defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glass1938f4a2013-03-11 06:49:53 +0000933 dram_init, /* configure available RAM banks */
934#endif
angelo@sysam.ite310b932015-02-12 01:40:17 +0100935#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +0000936 init_func_ram,
937#endif
938#ifdef CONFIG_POST
939 post_init_f,
940#endif
941 INIT_FUNC_WATCHDOG_RESET
942#if defined(CONFIG_SYS_DRAM_TEST)
943 testdram,
944#endif /* CONFIG_SYS_DRAM_TEST */
945 INIT_FUNC_WATCHDOG_RESET
946
Simon Glass1938f4a2013-03-11 06:49:53 +0000947#ifdef CONFIG_POST
948 init_post,
949#endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000950 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +0000951 /*
952 * Now that we have DRAM mapped and working, we can
953 * relocate the code and continue running from DRAM.
954 *
955 * Reserve memory at end of RAM for (top down in that order):
956 * - area that won't get touched by U-Boot and Linux (optional)
957 * - kernel log buffer
958 * - protected RAM
959 * - LCD framebuffer
960 * - monitor code
961 * - board info struct
962 */
963 setup_dest_addr,
Thomas Choubbfdff32015-10-27 11:23:39 +0800964#if defined(CONFIG_BLACKFIN)
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800965 /* Blackfin u-boot monitor should be on top of the ram */
966 reserve_uboot,
967#endif
Francois Retief1e85cce2015-11-23 13:05:44 +0200968#if defined(CONFIG_SPARC)
969 reserve_prom,
970#endif
Simon Glass1938f4a2013-03-11 06:49:53 +0000971#if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
972 reserve_logbuffer,
973#endif
974#ifdef CONFIG_PRAM
975 reserve_pram,
976#endif
977 reserve_round_4k,
978#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
979 defined(CONFIG_ARM)
980 reserve_mmu,
981#endif
Simon Glass5a541942016-01-18 19:52:21 -0700982#ifdef CONFIG_DM_VIDEO
983 reserve_video,
984#else
985# ifdef CONFIG_LCD
Simon Glass1938f4a2013-03-11 06:49:53 +0000986 reserve_lcd,
Simon Glass5a541942016-01-18 19:52:21 -0700987# endif
Simon Glasse4fef6c2013-03-11 14:30:42 +0000988 /* TODO: Why the dependency on CONFIG_8xx? */
Simon Glass5a541942016-01-18 19:52:21 -0700989# if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800990 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
angelo@sysam.it944ab342015-03-28 11:34:52 +0100991 !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
Simon Glass5a541942016-01-18 19:52:21 -0700992 reserve_legacy_video,
993# endif
994#endif /* CONFIG_DM_VIDEO */
Simon Glass8703ef32016-01-18 19:52:20 -0700995 reserve_trace,
Thomas Choubbfdff32015-10-27 11:23:39 +0800996#if !defined(CONFIG_BLACKFIN)
Simon Glass1938f4a2013-03-11 06:49:53 +0000997 reserve_uboot,
Sonic Zhangd54d7eb2014-07-17 19:01:34 +0800998#endif
Simon Glass8cae8a62013-03-05 14:39:45 +0000999#ifndef CONFIG_SPL_BUILD
Simon Glass1938f4a2013-03-11 06:49:53 +00001000 reserve_malloc,
1001 reserve_board,
Simon Glass8cae8a62013-03-05 14:39:45 +00001002#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001003 setup_machine,
1004 reserve_global_data,
1005 reserve_fdt,
Simon Glass146251f2015-01-19 22:16:12 -07001006 reserve_arch,
Simon Glass1938f4a2013-03-11 06:49:53 +00001007 reserve_stacks,
1008 setup_dram_config,
1009 show_dram_config,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001010#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001011 setup_board_part1,
Daniel Schwierzeckfb3db632015-11-01 17:36:13 +01001012#endif
1013#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glasse4fef6c2013-03-11 14:30:42 +00001014 INIT_FUNC_WATCHDOG_RESET
1015 setup_board_part2,
1016#endif
Simon Glass1938f4a2013-03-11 06:49:53 +00001017 display_new_sp,
Simon Glasse4fef6c2013-03-11 14:30:42 +00001018#ifdef CONFIG_SYS_EXTBDINFO
1019 setup_board_extra,
1020#endif
1021 INIT_FUNC_WATCHDOG_RESET
Simon Glass1938f4a2013-03-11 06:49:53 +00001022 reloc_fdt,
1023 setup_reloc,
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001024#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass313aef32015-01-01 16:18:09 -07001025 copy_uboot_to_ram,
1026 clear_bss,
1027 do_elf_reloc_fixups,
1028#endif
Simon Glass808434c2013-11-10 10:26:59 -07001029#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
Simon Glass1938f4a2013-03-11 06:49:53 +00001030 jump_to_copy,
1031#endif
1032 NULL,
1033};
1034
1035void board_init_f(ulong boot_flags)
1036{
York Sun2a1680e2014-05-02 17:28:04 -07001037#ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
1038 /*
1039 * For some archtectures, global data is initialized and used before
1040 * calling this function. The data should be preserved. For others,
1041 * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
1042 * here to host global data until relocation.
1043 */
Simon Glass1938f4a2013-03-11 06:49:53 +00001044 gd_t data;
1045
1046 gd = &data;
1047
David Fengcce6be72013-12-14 11:47:36 +08001048 /*
1049 * Clear global data before it is accessed at debug print
1050 * in initcall_run_list. Otherwise the debug print probably
1051 * get the wrong vaule of gd->have_console.
1052 */
David Fengcce6be72013-12-14 11:47:36 +08001053 zero_global_data();
1054#endif
1055
Simon Glass1938f4a2013-03-11 06:49:53 +00001056 gd->flags = boot_flags;
Alexey Brodkin9aed5a22013-11-27 22:32:40 +04001057 gd->have_console = 0;
Simon Glass1938f4a2013-03-11 06:49:53 +00001058
1059 if (initcall_run_list(init_sequence_f))
1060 hang();
1061
Ben Stoltz9b217492015-07-31 09:31:37 -06001062#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1063 !defined(CONFIG_EFI_APP)
Simon Glass1938f4a2013-03-11 06:49:53 +00001064 /* NOTREACHED - jump_to_copy() does not return */
1065 hang();
1066#endif
1067}
1068
Alexey Brodkin3fb80162015-02-24 19:40:36 +03001069#if defined(CONFIG_X86) || defined(CONFIG_ARC)
Simon Glass48a33802013-03-05 14:39:52 +00001070/*
1071 * For now this code is only used on x86.
1072 *
1073 * init_sequence_f_r is the list of init functions which are run when
1074 * U-Boot is executing from Flash with a semi-limited 'C' environment.
1075 * The following limitations must be considered when implementing an
1076 * '_f_r' function:
1077 * - 'static' variables are read-only
1078 * - Global Data (gd->xxx) is read/write
1079 *
1080 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1081 * supported). It _should_, if possible, copy global data to RAM and
1082 * initialise the CPU caches (to speed up the relocation process)
1083 *
1084 * NOTE: At present only x86 uses this route, but it is intended that
1085 * all archs will move to this when generic relocation is implemented.
1086 */
1087static init_fnc_t init_sequence_f_r[] = {
1088 init_cache_f_r,
Simon Glass48a33802013-03-05 14:39:52 +00001089
1090 NULL,
1091};
1092
1093void board_init_f_r(void)
1094{
1095 if (initcall_run_list(init_sequence_f_r))
1096 hang();
1097
1098 /*
Simon Glasse4d6ab02016-03-11 22:06:51 -07001099 * The pre-relocation drivers may be using memory that has now gone
1100 * away. Mark serial as unavailable - this will fall back to the debug
1101 * UART if available.
1102 */
1103 gd->flags &= ~GD_FLG_SERIAL_READY;
1104
1105 /*
Simon Glass48a33802013-03-05 14:39:52 +00001106 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1107 * Transfer execution from Flash to RAM by calculating the address
1108 * of the in-RAM copy of board_init_r() and calling it
1109 */
Alexey Brodkin7bf9f202015-02-25 17:59:02 +03001110 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
Simon Glass48a33802013-03-05 14:39:52 +00001111
1112 /* NOTREACHED - board_init_r() does not return */
1113 hang();
1114}
Alexey Brodkin5bcd19a2015-03-24 11:12:47 +03001115#endif /* CONFIG_X86 */