blob: ecca1edb04e0a4335bc4f5e6c5d2638b6d64ba45 [file] [log] [blame]
Simon Glassdb397fa2013-03-11 14:30:37 +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 Glassdb397fa2013-03-11 14:30:37 +000011 */
12
13#include <common.h>
Simon Glassac53a5c2017-05-17 08:22:40 -060014#include <api.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000015/* TODO: can we just include all these headers whether needed or not? */
16#if defined(CONFIG_CMD_BEDBUG)
17#include <bedbug/type.h>
18#endif
Tom Rini23415e52015-12-07 08:23:29 -050019#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070020#include <console.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000021#ifdef CONFIG_HAS_DATAFLASH
22#include <dataflash.h>
23#endif
Simon Glasseea87102014-02-26 15:59:20 -070024#include <dm.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000025#include <environment.h>
26#include <fdtdec.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000027#include <ide.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000028#include <initcall.h>
Simon Glass6bbf83f2017-03-31 08:40:37 -060029#include <init_helpers.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000030#ifdef CONFIG_PS2KBD
31#include <keyboard.h>
32#endif
33#if defined(CONFIG_CMD_KGDB)
34#include <kgdb.h>
35#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000036#include <logbuff.h>
37#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050038#include <mapmem.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000039#ifdef CONFIG_BITBANGMII
40#include <miiphy.h>
41#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000042#include <mmc.h>
43#include <nand.h>
Simon Glass46e09772017-05-18 20:08:56 -060044#include <of_live.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000045#include <onenand_uboot.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000046#include <scsi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000047#include <serial.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000048#include <spi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000049#include <stdio_dev.h>
Simon Glass8e4f80f2016-02-24 09:14:50 -070050#include <timer.h>
Simon Glass209a1a62013-06-11 11:14:42 -070051#include <trace.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000052#include <watchdog.h>
53#ifdef CONFIG_ADDR_MAP
54#include <asm/mmu.h>
55#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000056#include <asm/sections.h>
Simon Glasseea87102014-02-26 15:59:20 -070057#include <dm/root.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000058#include <linux/compiler.h>
Simon Glasseea87102014-02-26 15:59:20 -070059#include <linux/err.h>
Alexander Graf0bd425a2016-03-04 01:10:01 +010060#include <efi_loader.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000061
62DECLARE_GLOBAL_DATA_PTR;
63
64ulong monitor_flash_len;
65
Jeroen Hofstee45846052014-10-08 22:57:22 +020066__weak int board_flash_wp_on(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000067{
68 /*
69 * Most flashes can't be detected when write protection is enabled,
70 * so provide a way to let U-Boot gracefully ignore write protected
71 * devices.
72 */
73 return 0;
74}
75
Jeroen Hofstee45846052014-10-08 22:57:22 +020076__weak void cpu_secondary_init_r(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000077{
78}
79
Simon Glass5af29bd2013-03-14 07:20:12 +000080static int initr_secondary_cpu(void)
81{
82 /*
83 * after non-volatile devices & environment is setup and cpu code have
84 * another round to deal with any initialization that might require
85 * full access to the environment or loading of some image (firmware)
86 * from a non-volatile device
87 */
88 /* TODO: maybe define this for all archs? */
89 cpu_secondary_init_r();
90
91 return 0;
92}
Simon Glassdb397fa2013-03-11 14:30:37 +000093
Simon Glass209a1a62013-06-11 11:14:42 -070094static int initr_trace(void)
95{
96#ifdef CONFIG_TRACE
97 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
98#endif
99
100 return 0;
101}
102
Simon Glassdb397fa2013-03-11 14:30:37 +0000103static int initr_reloc(void)
104{
Simon Glass94890462014-11-10 17:16:43 -0700105 /* tell others: relocation done */
106 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
Simon Glassdb397fa2013-03-11 14:30:37 +0000107
108 return 0;
109}
110
111#ifdef CONFIG_ARM
112/*
113 * Some of these functions are needed purely because the functions they
114 * call return void. If we change them to return 0, these stubs can go away.
115 */
116static int initr_caches(void)
117{
118 /* Enable caches */
119 enable_caches();
120 return 0;
121}
122#endif
123
Simon Glass5af29bd2013-03-14 07:20:12 +0000124__weak int fixup_cpu(void)
125{
126 return 0;
127}
128
Simon Glassdb397fa2013-03-11 14:30:37 +0000129static int initr_reloc_global_data(void)
130{
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100131#ifdef __ARM__
132 monitor_flash_len = _end - __image_copy_start;
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800133#elif defined(CONFIG_NDS32)
134 monitor_flash_len = (ulong)&_end - (ulong)&_start;
Thomas Choucce3e752014-08-22 11:36:47 +0800135#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000136 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
Simon Glassdb397fa2013-03-11 14:30:37 +0000137#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000138#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
139 /*
140 * The gd->cpu pointer is set to an address in flash before relocation.
141 * We need to update it to point to the same CPU entry in RAM.
142 * TODO: why not just add gd->reloc_ofs?
143 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000144 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000145
146 /*
147 * If we didn't know the cpu mask & # cores, we can save them of
148 * now rather than 'computing' them constantly
149 */
150 fixup_cpu();
151#endif
152#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
153 /*
154 * Some systems need to relocate the env_addr pointer early because the
155 * location it points to will get invalidated before env_relocate is
156 * called. One example is on systems that might use a L2 or L3 cache
157 * in SRAM mode and initialize that cache from SRAM mode back to being
158 * a cache in cpu_init_r.
159 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000160 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000161#endif
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100162#ifdef CONFIG_OF_EMBED
163 /*
164 * The fdt_blob needs to be moved to new relocation address
165 * incase of FDT blob is embedded with in image
166 */
167 gd->fdt_blob += gd->reloc_off;
168#endif
Alexander Graf0bd425a2016-03-04 01:10:01 +0100169#ifdef CONFIG_EFI_LOADER
170 efi_runtime_relocate(gd->relocaddr, NULL);
171#endif
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100172
Simon Glass5af29bd2013-03-14 07:20:12 +0000173 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000174}
175
176static int initr_serial(void)
177{
178 serial_initialize();
179 return 0;
180}
181
Daniel Schwierzeckb9da7da2016-01-09 18:34:15 +0100182#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glass5af29bd2013-03-14 07:20:12 +0000183static int initr_trap(void)
184{
185 /*
186 * Setup trap handlers
187 */
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100188#if defined(CONFIG_PPC)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000189 trap_init(gd->relocaddr);
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100190#else
191 trap_init(CONFIG_SYS_SDRAM_BASE);
192#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000193 return 0;
194}
195#endif
196
197#ifdef CONFIG_ADDR_MAP
198static int initr_addr_map(void)
199{
200 init_addr_map();
201
202 return 0;
203}
204#endif
205
Simon Glassdb397fa2013-03-11 14:30:37 +0000206#ifdef CONFIG_LOGBUFFER
207unsigned long logbuffer_base(void)
208{
209 return gd->ram_top - LOGBUFF_LEN;
210}
211
212static int initr_logbuffer(void)
213{
214 logbuff_init_ptrs();
215 return 0;
216}
217#endif
218
219#ifdef CONFIG_POST
220static int initr_post_backlog(void)
221{
222 post_output_backlog();
223 return 0;
224}
225#endif
226
Simon Glass5af29bd2013-03-14 07:20:12 +0000227#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
228static int initr_unlock_ram_in_cache(void)
229{
230 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
231 return 0;
232}
233#endif
234
235#ifdef CONFIG_PCI
236static int initr_pci(void)
237{
Simon Glassb94dc892015-03-05 12:25:25 -0700238#ifndef CONFIG_DM_PCI
Simon Glass5af29bd2013-03-14 07:20:12 +0000239 pci_init();
Simon Glassb94dc892015-03-05 12:25:25 -0700240#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000241
242 return 0;
243}
244#endif
245
Simon Glass5af29bd2013-03-14 07:20:12 +0000246static int initr_barrier(void)
247{
248#ifdef CONFIG_PPC
249 /* TODO: Can we not use dmb() macros for this? */
250 asm("sync ; isync");
251#endif
252 return 0;
253}
254
Simon Glassdb397fa2013-03-11 14:30:37 +0000255static int initr_malloc(void)
256{
257 ulong malloc_start;
258
Simon Glass863e4042014-07-10 22:23:28 -0600259#ifdef CONFIG_SYS_MALLOC_F_LEN
260 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
261 gd->malloc_ptr / 1024);
262#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000263 /* The malloc area is immediately below the monitor copy in DRAM */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000264 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
Simon Glass62cf9122013-04-26 02:53:43 +0000265 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
266 TOTAL_MALLOC_LEN);
Simon Glassdb397fa2013-03-11 14:30:37 +0000267 return 0;
268}
Thierry Redingc97d9742014-12-09 22:25:22 -0700269
Simon Glass1bb49232015-11-08 23:47:48 -0700270static int initr_console_record(void)
271{
272#if defined(CONFIG_CONSOLE_RECORD)
273 return console_record_init();
274#else
275 return 0;
276#endif
277}
278
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100279#ifdef CONFIG_SYS_NONCACHED_MEMORY
280static int initr_noncached(void)
281{
282 noncached_init();
283 return 0;
284}
285#endif
286
Simon Glass46e09772017-05-18 20:08:56 -0600287#ifdef CONFIG_OF_LIVE
288static int initr_of_live(void)
289{
Simon Glassfda60522017-05-22 05:05:36 -0600290 int ret;
291
292 bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
293 ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root);
294 bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
295 if (ret)
296 return ret;
297
298 return 0;
Simon Glass46e09772017-05-18 20:08:56 -0600299}
300#endif
301
Simon Glasseea87102014-02-26 15:59:20 -0700302#ifdef CONFIG_DM
303static int initr_dm(void)
304{
Simon Glass8e4f80f2016-02-24 09:14:50 -0700305 int ret;
306
Simon Glassa730c5d2014-07-23 06:55:04 -0600307 /* Save the pre-reloc driver model and start a new one */
308 gd->dm_root_f = gd->dm_root;
309 gd->dm_root = NULL;
Simon Glassb0fb7bd2016-03-11 22:06:46 -0700310#ifdef CONFIG_TIMER
311 gd->timer = NULL;
312#endif
Simon Glass405e2b02017-05-22 05:05:32 -0600313 bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
Simon Glass8e4f80f2016-02-24 09:14:50 -0700314 ret = dm_init_and_scan(false);
Simon Glass405e2b02017-05-22 05:05:32 -0600315 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
Simon Glass8e4f80f2016-02-24 09:14:50 -0700316 if (ret)
317 return ret;
318#ifdef CONFIG_TIMER_EARLY
Simon Glass8e4f80f2016-02-24 09:14:50 -0700319 ret = dm_timer_init();
320 if (ret)
321 return ret;
Thomas Chou78815972015-10-09 13:48:56 +0800322#endif
Simon Glass8e4f80f2016-02-24 09:14:50 -0700323
324 return 0;
Simon Glasseea87102014-02-26 15:59:20 -0700325}
326#endif
327
Simon Glass7edd07d2015-11-28 22:16:35 -0700328static int initr_bootstage(void)
329{
Simon Glass7edd07d2015-11-28 22:16:35 -0700330 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
331
332 return 0;
333}
334
Simon Glassdb397fa2013-03-11 14:30:37 +0000335__weak int power_init_board(void)
336{
337 return 0;
338}
339
340static int initr_announce(void)
341{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000342 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
Simon Glassdb397fa2013-03-11 14:30:37 +0000343 return 0;
344}
345
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100346#ifdef CONFIG_NEEDS_MANUAL_RELOC
347static int initr_manual_reloc_cmdtable(void)
348{
349 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
350 ll_entry_count(cmd_tbl_t, cmd));
351 return 0;
352}
353#endif
354
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900355#if defined(CONFIG_MTD_NOR_FLASH)
Simon Glassdb397fa2013-03-11 14:30:37 +0000356static int initr_flash(void)
357{
Simon Glass5af29bd2013-03-14 07:20:12 +0000358 ulong flash_size = 0;
359 bd_t *bd = gd->bd;
Simon Glassdb397fa2013-03-11 14:30:37 +0000360
361 puts("Flash: ");
362
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900363 if (board_flash_wp_on())
Simon Glass5af29bd2013-03-14 07:20:12 +0000364 printf("Uninitialized - Write Protect On\n");
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900365 else
Simon Glass5af29bd2013-03-14 07:20:12 +0000366 flash_size = flash_init();
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900367
Simon Glassdb397fa2013-03-11 14:30:37 +0000368 print_size(flash_size, "");
369#ifdef CONFIG_SYS_FLASH_CHECKSUM
370 /*
371 * Compute and print flash CRC if flashchecksum is set to 'y'
372 *
373 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
374 */
375 if (getenv_yesno("flashchecksum") == 1) {
376 printf(" CRC: %08X", crc32(0,
377 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
378 flash_size));
379 }
380#endif /* CONFIG_SYS_FLASH_CHECKSUM */
381 putc('\n');
382
Simon Glass5af29bd2013-03-14 07:20:12 +0000383 /* update start of FLASH memory */
384#ifdef CONFIG_SYS_FLASH_BASE
385 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
386#endif
387 /* size of FLASH memory (final value) */
388 bd->bi_flashsize = flash_size;
389
390#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
391 /* Make a update of the Memctrl. */
392 update_flash_size(flash_size);
393#endif
394
395
396#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
397 /* flash mapped at end of memory map */
398 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
399#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
400 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
401#endif
402 return 0;
403}
404#endif
405
Simon Glass55316ad2014-10-13 23:41:54 -0600406#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000407static int initr_spi(void)
408{
409 /* PPC does this here */
410#ifdef CONFIG_SPI
411#if !defined(CONFIG_ENV_IS_IN_EEPROM)
412 spi_init_f();
413#endif
414 spi_init_r();
415#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000416 return 0;
417}
418#endif
419
420#ifdef CONFIG_CMD_NAND
421/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200422static int initr_nand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000423{
424 puts("NAND: ");
425 nand_init();
Hou Zhiqiang9c8b3c72017-03-17 16:12:31 +0800426 printf("%lu MiB\n", nand_size() / 1024);
Simon Glassdb397fa2013-03-11 14:30:37 +0000427 return 0;
428}
429#endif
430
431#if defined(CONFIG_CMD_ONENAND)
432/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200433static int initr_onenand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000434{
435 puts("NAND: ");
436 onenand_init();
437 return 0;
438}
439#endif
440
Masahiro Yamada0a780172017-05-09 20:31:39 +0900441#ifdef CONFIG_MMC
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200442static int initr_mmc(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000443{
444 puts("MMC: ");
445 mmc_initialize(gd->bd);
446 return 0;
447}
448#endif
449
450#ifdef CONFIG_HAS_DATAFLASH
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200451static int initr_dataflash(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000452{
453 AT91F_DataflashInit();
454 dataflash_print_info();
455 return 0;
456}
457#endif
458
459/*
460 * Tell if it's OK to load the environment early in boot.
461 *
Masahiro Yamadab970a892016-02-05 20:49:39 +0900462 * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see
Simon Glassdb397fa2013-03-11 14:30:37 +0000463 * if this is OK (defaulting to saying it's OK).
464 *
465 * NOTE: Loading the environment early can be a bad idea if security is
466 * important, since no verification is done on the environment.
467 *
468 * @return 0 if environment should not be loaded, !=0 if it is ok to load
469 */
470static int should_load_env(void)
471{
472#ifdef CONFIG_OF_CONTROL
473 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
474#elif defined CONFIG_DELAY_ENVIRONMENT
475 return 0;
476#else
477 return 1;
478#endif
479}
480
481static int initr_env(void)
482{
483 /* initialize environment */
484 if (should_load_env())
485 env_relocate();
486 else
487 set_default_env(NULL);
Thomas Chou4fda2812015-10-16 08:44:51 +0800488#ifdef CONFIG_OF_CONTROL
489 setenv_addr("fdtcontroladdr", gd->fdt_blob);
490#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000491
492 /* Initialize from environment */
493 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000494
Simon Glass5af29bd2013-03-14 07:20:12 +0000495 return 0;
496}
497
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100498#ifdef CONFIG_SYS_BOOTPARAMS_LEN
499static int initr_malloc_bootparams(void)
500{
501 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
502 if (!gd->bd->bi_boot_params) {
503 puts("WARNING: Cannot allocate space for boot parameters\n");
504 return -ENOMEM;
505 }
506 return 0;
507}
508#endif
509
Simon Glassdb397fa2013-03-11 14:30:37 +0000510static int initr_jumptable(void)
511{
512 jumptable_init();
513 return 0;
514}
515
516#if defined(CONFIG_API)
517static int initr_api(void)
518{
519 /* Initialize API */
520 api_init();
521 return 0;
522}
523#endif
524
Simon Glassdb397fa2013-03-11 14:30:37 +0000525/* enable exceptions */
Andy Shevchenko8cb5cdd2017-07-05 16:25:22 +0300526#ifdef CONFIG_ARM
Simon Glassdb397fa2013-03-11 14:30:37 +0000527static int initr_enable_interrupts(void)
528{
529 enable_interrupts();
530 return 0;
531}
Simon Glass2e4622d2013-03-11 07:40:13 +0000532#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000533
534#ifdef CONFIG_CMD_NET
535static int initr_ethaddr(void)
536{
Simon Glass5af29bd2013-03-14 07:20:12 +0000537 bd_t *bd = gd->bd;
538
539 /* kept around for legacy kernels only ... ignore the next section */
540 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
541#ifdef CONFIG_HAS_ETH1
542 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
543#endif
544#ifdef CONFIG_HAS_ETH2
545 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
546#endif
547#ifdef CONFIG_HAS_ETH3
548 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
549#endif
550#ifdef CONFIG_HAS_ETH4
551 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
552#endif
553#ifdef CONFIG_HAS_ETH5
554 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
555#endif
556 return 0;
557}
558#endif /* CONFIG_CMD_NET */
559
560#ifdef CONFIG_CMD_KGDB
561static int initr_kgdb(void)
562{
563 puts("KGDB: ");
564 kgdb_init();
565 return 0;
566}
567#endif
568
Uri Mashiach4892d392017-01-19 10:51:45 +0200569#if defined(CONFIG_LED_STATUS)
Simon Glass5af29bd2013-03-14 07:20:12 +0000570static int initr_status_led(void)
571{
Uri Mashiach4892d392017-01-19 10:51:45 +0200572#if defined(CONFIG_LED_STATUS_BOOT)
573 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200574#else
575 status_led_init();
576#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000577 return 0;
578}
579#endif
580
Michal Simekc886f352016-09-08 15:06:45 +0200581#if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000582static int initr_scsi(void)
583{
Simon Glass5af29bd2013-03-14 07:20:12 +0000584 puts("SCSI: ");
585 scsi_init();
Simon Glassdb397fa2013-03-11 14:30:37 +0000586
587 return 0;
588}
Ian Campbell63d424b2014-07-21 19:23:18 +0100589#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000590
591#ifdef CONFIG_BITBANGMII
592static int initr_bbmii(void)
593{
594 bb_miiphy_init();
595 return 0;
596}
597#endif
598
599#ifdef CONFIG_CMD_NET
600static int initr_net(void)
601{
602 puts("Net: ");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500603 eth_initialize();
Simon Glassdb397fa2013-03-11 14:30:37 +0000604#if defined(CONFIG_RESET_PHY_R)
605 debug("Reset Ethernet PHY\n");
606 reset_phy();
607#endif
608 return 0;
609}
610#endif
611
612#ifdef CONFIG_POST
613static int initr_post(void)
614{
615 post_run(NULL, POST_RAM | post_bootmode_get(0));
616 return 0;
617}
618#endif
619
Simon Glassb569a012017-05-17 03:25:30 -0600620#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
Simon Glass5af29bd2013-03-14 07:20:12 +0000621static int initr_pcmcia(void)
622{
623 puts("PCMCIA:");
624 pcmcia_init();
625 return 0;
626}
627#endif
628
Simon Glassb569a012017-05-17 03:25:30 -0600629#if defined(CONFIG_IDE)
Simon Glass5af29bd2013-03-14 07:20:12 +0000630static int initr_ide(void)
631{
Simon Glass5af29bd2013-03-14 07:20:12 +0000632 puts("IDE: ");
Simon Glass5af29bd2013-03-14 07:20:12 +0000633#if defined(CONFIG_START_IDE)
634 if (board_start_ide())
635 ide_init();
636#else
637 ide_init();
638#endif
639 return 0;
640}
641#endif
642
Simon Glassdb397fa2013-03-11 14:30:37 +0000643#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
644/*
645 * Export available size of memory for Linux, taking into account the
646 * protected RAM at top of memory
647 */
648int initr_mem(void)
649{
650 ulong pram = 0;
651 char memsz[32];
652
653# ifdef CONFIG_PRAM
654 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
655# endif
656# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
657 /* Also take the logbuffer into account (pram is in kB) */
658 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
659# endif
Valentin Longchampd6b46942014-10-03 11:16:19 +0200660 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
Simon Glassdb397fa2013-03-11 14:30:37 +0000661 setenv("mem", memsz);
Simon Glass5af29bd2013-03-14 07:20:12 +0000662
663 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000664}
665#endif
666
Simon Glass5af29bd2013-03-14 07:20:12 +0000667#ifdef CONFIG_CMD_BEDBUG
668static int initr_bedbug(void)
669{
670 bedbug_init();
671
672 return 0;
673}
674#endif
675
676#ifdef CONFIG_PS2KBD
677static int initr_kbd(void)
678{
679 puts("PS/2: ");
680 kbd_init();
681 return 0;
682}
683#endif
684
Simon Glassdb397fa2013-03-11 14:30:37 +0000685static int run_main_loop(void)
686{
Simon Glass62cf9122013-04-26 02:53:43 +0000687#ifdef CONFIG_SANDBOX
688 sandbox_main_loop_init();
689#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000690 /* main_loop() can return to retry autoboot, if so just run it again */
691 for (;;)
692 main_loop();
693 return 0;
694}
695
696/*
697 * Over time we hope to remove these functions with code fragments and
698 * stub funtcions, and instead call the relevant function directly.
699 *
700 * We also hope to remove most of the driver-related init and do it if/when
701 * the driver is later used.
Simon Glass5af29bd2013-03-14 07:20:12 +0000702 *
703 * TODO: perhaps reset the watchdog in the initcall function after each call?
Simon Glassdb397fa2013-03-11 14:30:37 +0000704 */
Simon Glass2031fad2017-01-16 07:03:50 -0700705static init_fnc_t init_sequence_r[] = {
Simon Glass209a1a62013-06-11 11:14:42 -0700706 initr_trace,
Simon Glassdb397fa2013-03-11 14:30:37 +0000707 initr_reloc,
Simon Glass5af29bd2013-03-14 07:20:12 +0000708 /* TODO: could x86/PPC have this also perhaps? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000709#ifdef CONFIG_ARM
710 initr_caches,
York Sun820a18f2015-03-20 19:28:11 -0700711 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
712 * A temporary mapping of IFC high region is since removed,
713 * so environmental variables in NOR flash is not availble
714 * until board_init() is called below to remap IFC to high
715 * region.
716 */
Simon Glass712da5e2014-09-03 17:37:01 -0600717#endif
718 initr_reloc_global_data,
York Sun6e78b3b2014-10-02 15:20:10 -0700719#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
720 initr_unlock_ram_in_cache,
721#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600722 initr_barrier,
723 initr_malloc,
Simon Glasse635af12017-05-22 05:05:31 -0600724 initr_bootstage, /* Needs malloc() but has its own timer */
Simon Glass1bb49232015-11-08 23:47:48 -0700725 initr_console_record,
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100726#ifdef CONFIG_SYS_NONCACHED_MEMORY
727 initr_noncached,
728#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600729 bootstage_relocate,
Simon Glass46e09772017-05-18 20:08:56 -0600730#ifdef CONFIG_OF_LIVE
731 initr_of_live,
732#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600733#ifdef CONFIG_DM
734 initr_dm,
735#endif
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800736#if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000737 board_init, /* Setup chipselects */
738#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000739 /*
740 * TODO: printing of the clock inforamtion of the board is now
741 * implemented as part of bdinfo command. Currently only support for
742 * davinci SOC's is added. Remove this check once all the board
743 * implement this.
744 */
745#ifdef CONFIG_CLOCKS
746 set_cpu_clk_info, /* Setup clock information */
747#endif
Alexander Graf8623f922016-03-04 01:10:04 +0100748#ifdef CONFIG_EFI_LOADER
749 efi_memory_init,
750#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600751 stdio_init_tables,
Simon Glassdb397fa2013-03-11 14:30:37 +0000752 initr_serial,
753 initr_announce,
Simon Glass5af29bd2013-03-14 07:20:12 +0000754 INIT_FUNC_WATCHDOG_RESET
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100755#ifdef CONFIG_NEEDS_MANUAL_RELOC
756 initr_manual_reloc_cmdtable,
757#endif
Daniel Schwierzeckb9da7da2016-01-09 18:34:15 +0100758#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
Simon Glass5af29bd2013-03-14 07:20:12 +0000759 initr_trap,
760#endif
761#ifdef CONFIG_ADDR_MAP
762 initr_addr_map,
763#endif
764#if defined(CONFIG_BOARD_EARLY_INIT_R)
765 board_early_init_r,
766#endif
767 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000768#ifdef CONFIG_LOGBUFFER
769 initr_logbuffer,
770#endif
771#ifdef CONFIG_POST
772 initr_post_backlog,
773#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000774 INIT_FUNC_WATCHDOG_RESET
Simon Glass5af29bd2013-03-14 07:20:12 +0000775#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
776 /*
777 * Do early PCI configuration _before_ the flash gets initialised,
778 * because PCU ressources are crucial for flash access on some boards.
779 */
780 initr_pci,
781#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000782#ifdef CONFIG_ARCH_EARLY_INIT_R
783 arch_early_init_r,
784#endif
785 power_init_board,
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900786#ifdef CONFIG_MTD_NOR_FLASH
Simon Glassdb397fa2013-03-11 14:30:37 +0000787 initr_flash,
788#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000789 INIT_FUNC_WATCHDOG_RESET
Tom Rinifef2bd12017-03-14 11:08:11 -0400790#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
Simon Glass5af29bd2013-03-14 07:20:12 +0000791 /* initialize higher level parts of CPU like time base and timers */
792 cpu_init_r,
Simon Glass6f5567d2013-03-05 14:39:53 +0000793#endif
794#ifdef CONFIG_PPC
Simon Glass5af29bd2013-03-14 07:20:12 +0000795 initr_spi,
796#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000797#ifdef CONFIG_CMD_NAND
798 initr_nand,
799#endif
800#ifdef CONFIG_CMD_ONENAND
801 initr_onenand,
802#endif
Masahiro Yamada0a780172017-05-09 20:31:39 +0900803#ifdef CONFIG_MMC
Simon Glassdb397fa2013-03-11 14:30:37 +0000804 initr_mmc,
805#endif
806#ifdef CONFIG_HAS_DATAFLASH
807 initr_dataflash,
808#endif
809 initr_env,
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100810#ifdef CONFIG_SYS_BOOTPARAMS_LEN
811 initr_malloc_bootparams,
812#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000813 INIT_FUNC_WATCHDOG_RESET
814 initr_secondary_cpu,
Simon Glass5af29bd2013-03-14 07:20:12 +0000815#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
816 mac_read_from_eeprom,
817#endif
818 INIT_FUNC_WATCHDOG_RESET
819#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
820 /*
821 * Do pci configuration
822 */
823 initr_pci,
824#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600825 stdio_add_devices,
Simon Glassdb397fa2013-03-11 14:30:37 +0000826 initr_jumptable,
827#ifdef CONFIG_API
828 initr_api,
829#endif
830 console_init_r, /* fully init console as a device */
831#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
Simon Glassc9c5c9f2017-06-15 21:37:50 -0600832 console_announce_r,
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900833 show_board_info,
Simon Glassdb397fa2013-03-11 14:30:37 +0000834#endif
835#ifdef CONFIG_ARCH_MISC_INIT
836 arch_misc_init, /* miscellaneous arch-dependent init */
837#endif
838#ifdef CONFIG_MISC_INIT_R
839 misc_init_r, /* miscellaneous platform-dependent init */
840#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000841 INIT_FUNC_WATCHDOG_RESET
842#ifdef CONFIG_CMD_KGDB
843 initr_kgdb,
844#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000845 interrupt_init,
Andy Shevchenko8cb5cdd2017-07-05 16:25:22 +0300846#ifdef CONFIG_ARM
Simon Glassdb397fa2013-03-11 14:30:37 +0000847 initr_enable_interrupts,
Simon Glass5af29bd2013-03-14 07:20:12 +0000848#endif
Andy Shevchenko8cb5cdd2017-07-05 16:25:22 +0300849#if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
Simon Glass6f5567d2013-03-05 14:39:53 +0000850 timer_init, /* initialize timer */
851#endif
Uri Mashiach4892d392017-01-19 10:51:45 +0200852#if defined(CONFIG_LED_STATUS)
Simon Glass5af29bd2013-03-14 07:20:12 +0000853 initr_status_led,
854#endif
855 /* PPC has a udelay(20) here dating from 2002. Why? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000856#ifdef CONFIG_CMD_NET
857 initr_ethaddr,
858#endif
859#ifdef CONFIG_BOARD_LATE_INIT
860 board_late_init,
861#endif
Michal Simekc886f352016-09-08 15:06:45 +0200862#if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000863 INIT_FUNC_WATCHDOG_RESET
864 initr_scsi,
865#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000866#ifdef CONFIG_BITBANGMII
867 initr_bbmii,
868#endif
869#ifdef CONFIG_CMD_NET
Simon Glass5af29bd2013-03-14 07:20:12 +0000870 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000871 initr_net,
872#endif
873#ifdef CONFIG_POST
874 initr_post,
875#endif
Simon Glassb569a012017-05-17 03:25:30 -0600876#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
Simon Glass5af29bd2013-03-14 07:20:12 +0000877 initr_pcmcia,
878#endif
Simon Glassb569a012017-05-17 03:25:30 -0600879#if defined(CONFIG_IDE)
Simon Glass5af29bd2013-03-14 07:20:12 +0000880 initr_ide,
881#endif
882#ifdef CONFIG_LAST_STAGE_INIT
883 INIT_FUNC_WATCHDOG_RESET
884 /*
885 * Some parts can be only initialized if all others (like
886 * Interrupts) are up and running (i.e. the PC-style ISA
887 * keyboard).
888 */
889 last_stage_init,
890#endif
891#ifdef CONFIG_CMD_BEDBUG
892 INIT_FUNC_WATCHDOG_RESET
893 initr_bedbug,
894#endif
895#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
896 initr_mem,
897#endif
898#ifdef CONFIG_PS2KBD
899 initr_kbd,
900#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000901 run_main_loop,
902};
903
904void board_init_r(gd_t *new_gd, ulong dest_addr)
905{
Simon Glass96c867d2017-01-16 07:03:51 -0700906 /*
907 * Set up the new global data pointer. So far only x86 does this
908 * here.
909 * TODO(sjg@chromium.org): Consider doing this for all archs, or
910 * dropping the new_gd parameter.
911 */
912#if CONFIG_IS_ENABLED(X86_64)
913 arch_setup_gd(new_gd);
914#endif
915
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400916#ifdef CONFIG_NEEDS_MANUAL_RELOC
917 int i;
918#endif
919
Jeroen Hofstee498f97f2014-07-30 21:54:49 +0200920#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
Simon Glassdb397fa2013-03-11 14:30:37 +0000921 gd = new_gd;
Simon Glass6f5567d2013-03-05 14:39:53 +0000922#endif
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400923
924#ifdef CONFIG_NEEDS_MANUAL_RELOC
925 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
926 init_sequence_r[i] += gd->reloc_off;
927#endif
928
Simon Glassdb397fa2013-03-11 14:30:37 +0000929 if (initcall_run_list(init_sequence_r))
930 hang();
931
932 /* NOTREACHED - run_main_loop() does not return */
933 hang();
934}