blob: 6c238652790c2d1aa839015a359e3f69e9a09c7b [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 Glass5af29bd2013-03-14 07:20:12 +000014/* TODO: can we just include all these headers whether needed or not? */
15#if defined(CONFIG_CMD_BEDBUG)
16#include <bedbug/type.h>
17#endif
Tom Rini23415e52015-12-07 08:23:29 -050018#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070019#include <console.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000020#ifdef CONFIG_HAS_DATAFLASH
21#include <dataflash.h>
22#endif
Simon Glasseea87102014-02-26 15:59:20 -070023#include <dm.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000024#include <environment.h>
25#include <fdtdec.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000026#if defined(CONFIG_CMD_IDE)
27#include <ide.h>
28#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000029#include <initcall.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>
44#include <onenand_uboot.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000045#include <scsi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000046#include <serial.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000047#include <spi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000048#include <stdio_dev.h>
Simon Glass209a1a62013-06-11 11:14:42 -070049#include <trace.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000050#include <watchdog.h>
Francois Retief77732022014-10-27 13:39:03 +020051#ifdef CONFIG_CMD_AMBAPP
52#include <ambapp.h>
53#endif
Simon Glass5af29bd2013-03-14 07:20:12 +000054#ifdef CONFIG_ADDR_MAP
55#include <asm/mmu.h>
56#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000057#include <asm/sections.h>
Simon Glass6f5567d2013-03-05 14:39:53 +000058#ifdef CONFIG_X86
59#include <asm/init_helpers.h>
60#endif
Simon Glasseea87102014-02-26 15:59:20 -070061#include <dm/root.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000062#include <linux/compiler.h>
Simon Glasseea87102014-02-26 15:59:20 -070063#include <linux/err.h>
Andreas Bießmannc1d09172015-02-06 23:06:48 +010064#ifdef CONFIG_AVR32
65#include <asm/arch/mmu.h>
66#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000067
68DECLARE_GLOBAL_DATA_PTR;
69
Francois Retieffc7784e2015-11-23 13:05:44 +020070#if defined(CONFIG_SPARC)
71extern int prom_init(void);
72#endif
73
Simon Glassdb397fa2013-03-11 14:30:37 +000074ulong monitor_flash_len;
75
Jeroen Hofstee45846052014-10-08 22:57:22 +020076__weak int board_flash_wp_on(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000077{
78 /*
79 * Most flashes can't be detected when write protection is enabled,
80 * so provide a way to let U-Boot gracefully ignore write protected
81 * devices.
82 */
83 return 0;
84}
85
Jeroen Hofstee45846052014-10-08 22:57:22 +020086__weak void cpu_secondary_init_r(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000087{
88}
89
Simon Glass5af29bd2013-03-14 07:20:12 +000090static int initr_secondary_cpu(void)
91{
92 /*
93 * after non-volatile devices & environment is setup and cpu code have
94 * another round to deal with any initialization that might require
95 * full access to the environment or loading of some image (firmware)
96 * from a non-volatile device
97 */
98 /* TODO: maybe define this for all archs? */
99 cpu_secondary_init_r();
100
101 return 0;
102}
Simon Glassdb397fa2013-03-11 14:30:37 +0000103
Simon Glass209a1a62013-06-11 11:14:42 -0700104static int initr_trace(void)
105{
106#ifdef CONFIG_TRACE
107 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
108#endif
109
110 return 0;
111}
112
Simon Glassdb397fa2013-03-11 14:30:37 +0000113static int initr_reloc(void)
114{
Simon Glass94890462014-11-10 17:16:43 -0700115 /* tell others: relocation done */
116 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
Simon Glassdb397fa2013-03-11 14:30:37 +0000117
118 return 0;
119}
120
121#ifdef CONFIG_ARM
122/*
123 * Some of these functions are needed purely because the functions they
124 * call return void. If we change them to return 0, these stubs can go away.
125 */
126static int initr_caches(void)
127{
128 /* Enable caches */
129 enable_caches();
130 return 0;
131}
132#endif
133
Simon Glass5af29bd2013-03-14 07:20:12 +0000134__weak int fixup_cpu(void)
135{
136 return 0;
137}
138
Simon Glassdb397fa2013-03-11 14:30:37 +0000139static int initr_reloc_global_data(void)
140{
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100141#ifdef __ARM__
142 monitor_flash_len = _end - __image_copy_start;
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800143#elif defined(CONFIG_NDS32)
144 monitor_flash_len = (ulong)&_end - (ulong)&_start;
Thomas Choucce3e752014-08-22 11:36:47 +0800145#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000146 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
Simon Glassdb397fa2013-03-11 14:30:37 +0000147#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000148#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
149 /*
150 * The gd->cpu pointer is set to an address in flash before relocation.
151 * We need to update it to point to the same CPU entry in RAM.
152 * TODO: why not just add gd->reloc_ofs?
153 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000154 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000155
156 /*
157 * If we didn't know the cpu mask & # cores, we can save them of
158 * now rather than 'computing' them constantly
159 */
160 fixup_cpu();
161#endif
162#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
163 /*
164 * Some systems need to relocate the env_addr pointer early because the
165 * location it points to will get invalidated before env_relocate is
166 * called. One example is on systems that might use a L2 or L3 cache
167 * in SRAM mode and initialize that cache from SRAM mode back to being
168 * a cache in cpu_init_r.
169 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000170 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000171#endif
Siva Durga Prasad Paladuguabffd312015-12-03 15:46:03 +0100172#ifdef CONFIG_OF_EMBED
173 /*
174 * The fdt_blob needs to be moved to new relocation address
175 * incase of FDT blob is embedded with in image
176 */
177 gd->fdt_blob += gd->reloc_off;
178#endif
179
Simon Glass5af29bd2013-03-14 07:20:12 +0000180 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000181}
182
183static int initr_serial(void)
184{
185 serial_initialize();
186 return 0;
187}
188
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100189#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass5af29bd2013-03-14 07:20:12 +0000190static int initr_trap(void)
191{
192 /*
193 * Setup trap handlers
194 */
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100195#if defined(CONFIG_PPC)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000196 trap_init(gd->relocaddr);
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100197#else
198 trap_init(CONFIG_SYS_SDRAM_BASE);
199#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000200 return 0;
201}
202#endif
203
204#ifdef CONFIG_ADDR_MAP
205static int initr_addr_map(void)
206{
207 init_addr_map();
208
209 return 0;
210}
211#endif
212
Simon Glassdb397fa2013-03-11 14:30:37 +0000213#ifdef CONFIG_LOGBUFFER
214unsigned long logbuffer_base(void)
215{
216 return gd->ram_top - LOGBUFF_LEN;
217}
218
219static int initr_logbuffer(void)
220{
221 logbuff_init_ptrs();
222 return 0;
223}
224#endif
225
226#ifdef CONFIG_POST
227static int initr_post_backlog(void)
228{
229 post_output_backlog();
230 return 0;
231}
232#endif
233
Simon Glass5af29bd2013-03-14 07:20:12 +0000234#ifdef CONFIG_SYS_DELAYED_ICACHE
235static int initr_icache_enable(void)
236{
237 return 0;
238}
239#endif
240
241#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
242static int initr_unlock_ram_in_cache(void)
243{
244 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
245 return 0;
246}
247#endif
248
249#ifdef CONFIG_PCI
250static int initr_pci(void)
251{
Simon Glassb94dc892015-03-05 12:25:25 -0700252#ifndef CONFIG_DM_PCI
Simon Glass5af29bd2013-03-14 07:20:12 +0000253 pci_init();
Simon Glassb94dc892015-03-05 12:25:25 -0700254#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000255
256 return 0;
257}
258#endif
259
260#ifdef CONFIG_WINBOND_83C553
261static int initr_w83c553f(void)
262{
263 /*
264 * Initialise the ISA bridge
265 */
266 initialise_w83c553f();
267 return 0;
268}
269#endif
270
271static int initr_barrier(void)
272{
273#ifdef CONFIG_PPC
274 /* TODO: Can we not use dmb() macros for this? */
275 asm("sync ; isync");
276#endif
277 return 0;
278}
279
Simon Glassdb397fa2013-03-11 14:30:37 +0000280static int initr_malloc(void)
281{
282 ulong malloc_start;
283
Simon Glass863e4042014-07-10 22:23:28 -0600284#ifdef CONFIG_SYS_MALLOC_F_LEN
285 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
286 gd->malloc_ptr / 1024);
287#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000288 /* The malloc area is immediately below the monitor copy in DRAM */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000289 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
Simon Glass62cf9122013-04-26 02:53:43 +0000290 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
291 TOTAL_MALLOC_LEN);
Simon Glassdb397fa2013-03-11 14:30:37 +0000292 return 0;
293}
Thierry Redingc97d9742014-12-09 22:25:22 -0700294
Simon Glass1bb49232015-11-08 23:47:48 -0700295static int initr_console_record(void)
296{
297#if defined(CONFIG_CONSOLE_RECORD)
298 return console_record_init();
299#else
300 return 0;
301#endif
302}
303
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100304#ifdef CONFIG_SYS_NONCACHED_MEMORY
305static int initr_noncached(void)
306{
307 noncached_init();
308 return 0;
309}
310#endif
311
Simon Glasseea87102014-02-26 15:59:20 -0700312#ifdef CONFIG_DM
313static int initr_dm(void)
314{
Simon Glassa730c5d2014-07-23 06:55:04 -0600315 /* Save the pre-reloc driver model and start a new one */
316 gd->dm_root_f = gd->dm_root;
317 gd->dm_root = NULL;
Thomas Chou78815972015-10-09 13:48:56 +0800318#ifdef CONFIG_TIMER
319 gd->timer = NULL;
320#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600321 return dm_init_and_scan(false);
Simon Glasseea87102014-02-26 15:59:20 -0700322}
323#endif
324
Simon Glass7edd07d2015-11-28 22:16:35 -0700325static int initr_bootstage(void)
326{
327 /* We cannot do this before initr_dm() */
328 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
329
330 return 0;
331}
332
Simon Glassdb397fa2013-03-11 14:30:37 +0000333__weak int power_init_board(void)
334{
335 return 0;
336}
337
338static int initr_announce(void)
339{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000340 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
Simon Glassdb397fa2013-03-11 14:30:37 +0000341 return 0;
342}
343
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100344#ifdef CONFIG_NEEDS_MANUAL_RELOC
345static int initr_manual_reloc_cmdtable(void)
346{
347 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
348 ll_entry_count(cmd_tbl_t, cmd));
349 return 0;
350}
351#endif
352
Simon Glassdb397fa2013-03-11 14:30:37 +0000353#if !defined(CONFIG_SYS_NO_FLASH)
354static int initr_flash(void)
355{
Simon Glass5af29bd2013-03-14 07:20:12 +0000356 ulong flash_size = 0;
357 bd_t *bd = gd->bd;
Simon Glassdb397fa2013-03-11 14:30:37 +0000358
359 puts("Flash: ");
360
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900361 if (board_flash_wp_on())
Simon Glass5af29bd2013-03-14 07:20:12 +0000362 printf("Uninitialized - Write Protect On\n");
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900363 else
Simon Glass5af29bd2013-03-14 07:20:12 +0000364 flash_size = flash_init();
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900365
Simon Glassdb397fa2013-03-11 14:30:37 +0000366 print_size(flash_size, "");
367#ifdef CONFIG_SYS_FLASH_CHECKSUM
368 /*
369 * Compute and print flash CRC if flashchecksum is set to 'y'
370 *
371 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
372 */
373 if (getenv_yesno("flashchecksum") == 1) {
374 printf(" CRC: %08X", crc32(0,
375 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
376 flash_size));
377 }
378#endif /* CONFIG_SYS_FLASH_CHECKSUM */
379 putc('\n');
380
Simon Glass5af29bd2013-03-14 07:20:12 +0000381 /* update start of FLASH memory */
382#ifdef CONFIG_SYS_FLASH_BASE
383 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
384#endif
385 /* size of FLASH memory (final value) */
386 bd->bi_flashsize = flash_size;
387
388#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
389 /* Make a update of the Memctrl. */
390 update_flash_size(flash_size);
391#endif
392
393
394#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
395 /* flash mapped at end of memory map */
396 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
397#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
398 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
399#endif
400 return 0;
401}
402#endif
403
Simon Glass55316ad2014-10-13 23:41:54 -0600404#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000405static int initr_spi(void)
406{
407 /* PPC does this here */
408#ifdef CONFIG_SPI
409#if !defined(CONFIG_ENV_IS_IN_EEPROM)
410 spi_init_f();
411#endif
412 spi_init_r();
413#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000414 return 0;
415}
416#endif
417
418#ifdef CONFIG_CMD_NAND
419/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200420static int initr_nand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000421{
422 puts("NAND: ");
423 nand_init();
424 return 0;
425}
426#endif
427
428#if defined(CONFIG_CMD_ONENAND)
429/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200430static int initr_onenand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000431{
432 puts("NAND: ");
433 onenand_init();
434 return 0;
435}
436#endif
437
438#ifdef CONFIG_GENERIC_MMC
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200439static int initr_mmc(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000440{
441 puts("MMC: ");
442 mmc_initialize(gd->bd);
443 return 0;
444}
445#endif
446
447#ifdef CONFIG_HAS_DATAFLASH
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200448static int initr_dataflash(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000449{
450 AT91F_DataflashInit();
451 dataflash_print_info();
452 return 0;
453}
454#endif
455
456/*
457 * Tell if it's OK to load the environment early in boot.
458 *
Masahiro Yamadab970a892016-02-05 20:49:39 +0900459 * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see
Simon Glassdb397fa2013-03-11 14:30:37 +0000460 * if this is OK (defaulting to saying it's OK).
461 *
462 * NOTE: Loading the environment early can be a bad idea if security is
463 * important, since no verification is done on the environment.
464 *
465 * @return 0 if environment should not be loaded, !=0 if it is ok to load
466 */
467static int should_load_env(void)
468{
469#ifdef CONFIG_OF_CONTROL
470 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
471#elif defined CONFIG_DELAY_ENVIRONMENT
472 return 0;
473#else
474 return 1;
475#endif
476}
477
478static int initr_env(void)
479{
480 /* initialize environment */
481 if (should_load_env())
482 env_relocate();
483 else
484 set_default_env(NULL);
Thomas Chou4fda2812015-10-16 08:44:51 +0800485#ifdef CONFIG_OF_CONTROL
486 setenv_addr("fdtcontroladdr", gd->fdt_blob);
487#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000488
489 /* Initialize from environment */
490 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000491#if defined(CONFIG_SYS_EXTBDINFO)
492#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
493#if defined(CONFIG_I2CFAST)
494 /*
495 * set bi_iic_fast for linux taking environment variable
496 * "i2cfast" into account
497 */
498 {
499 char *s = getenv("i2cfast");
500
501 if (s && ((*s == 'y') || (*s == 'Y'))) {
502 gd->bd->bi_iic_fast[0] = 1;
503 gd->bd->bi_iic_fast[1] = 1;
504 }
505 }
506#endif /* CONFIG_I2CFAST */
507#endif /* CONFIG_405GP, CONFIG_405EP */
508#endif /* CONFIG_SYS_EXTBDINFO */
509 return 0;
510}
511
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100512#ifdef CONFIG_SYS_BOOTPARAMS_LEN
513static int initr_malloc_bootparams(void)
514{
515 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
516 if (!gd->bd->bi_boot_params) {
517 puts("WARNING: Cannot allocate space for boot parameters\n");
518 return -ENOMEM;
519 }
520 return 0;
521}
522#endif
523
Simon Glassdb397fa2013-03-11 14:30:37 +0000524static int initr_jumptable(void)
525{
526 jumptable_init();
527 return 0;
528}
529
530#if defined(CONFIG_API)
531static int initr_api(void)
532{
533 /* Initialize API */
534 api_init();
535 return 0;
536}
537#endif
538
Simon Glassdb397fa2013-03-11 14:30:37 +0000539/* enable exceptions */
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100540#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000541static int initr_enable_interrupts(void)
542{
543 enable_interrupts();
544 return 0;
545}
Simon Glass2e4622d2013-03-11 07:40:13 +0000546#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000547
548#ifdef CONFIG_CMD_NET
549static int initr_ethaddr(void)
550{
Simon Glass5af29bd2013-03-14 07:20:12 +0000551 bd_t *bd = gd->bd;
552
553 /* kept around for legacy kernels only ... ignore the next section */
554 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
555#ifdef CONFIG_HAS_ETH1
556 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
557#endif
558#ifdef CONFIG_HAS_ETH2
559 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
560#endif
561#ifdef CONFIG_HAS_ETH3
562 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
563#endif
564#ifdef CONFIG_HAS_ETH4
565 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
566#endif
567#ifdef CONFIG_HAS_ETH5
568 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
569#endif
570 return 0;
571}
572#endif /* CONFIG_CMD_NET */
573
574#ifdef CONFIG_CMD_KGDB
575static int initr_kgdb(void)
576{
577 puts("KGDB: ");
578 kgdb_init();
579 return 0;
580}
581#endif
582
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200583#if defined(CONFIG_STATUS_LED)
Simon Glass5af29bd2013-03-14 07:20:12 +0000584static int initr_status_led(void)
585{
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200586#if defined(STATUS_LED_BOOT)
Simon Glass5af29bd2013-03-14 07:20:12 +0000587 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200588#else
589 status_led_init();
590#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000591 return 0;
592}
593#endif
594
Francois Retief77732022014-10-27 13:39:03 +0200595#if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
596extern int do_ambapp_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
597
598static int initr_ambapp_print(void)
599{
600 puts("AMBA:\n");
601 do_ambapp_print(NULL, 0, 0, NULL);
602
603 return 0;
604}
605#endif
606
Simon Glass5af29bd2013-03-14 07:20:12 +0000607#if defined(CONFIG_CMD_SCSI)
608static int initr_scsi(void)
609{
Simon Glass5af29bd2013-03-14 07:20:12 +0000610 puts("SCSI: ");
611 scsi_init();
Simon Glassdb397fa2013-03-11 14:30:37 +0000612
613 return 0;
614}
Ian Campbell63d424b2014-07-21 19:23:18 +0100615#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000616
Simon Glass5af29bd2013-03-14 07:20:12 +0000617#if defined(CONFIG_CMD_DOC)
618static int initr_doc(void)
619{
620 puts("DOC: ");
621 doc_init();
Ian Campbell1e81e5b2014-07-24 09:29:57 +0100622 return 0;
Simon Glass5af29bd2013-03-14 07:20:12 +0000623}
624#endif
625
Simon Glassdb397fa2013-03-11 14:30:37 +0000626#ifdef CONFIG_BITBANGMII
627static int initr_bbmii(void)
628{
629 bb_miiphy_init();
630 return 0;
631}
632#endif
633
634#ifdef CONFIG_CMD_NET
635static int initr_net(void)
636{
637 puts("Net: ");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500638 eth_initialize();
Simon Glassdb397fa2013-03-11 14:30:37 +0000639#if defined(CONFIG_RESET_PHY_R)
640 debug("Reset Ethernet PHY\n");
641 reset_phy();
642#endif
643 return 0;
644}
645#endif
646
647#ifdef CONFIG_POST
648static int initr_post(void)
649{
650 post_run(NULL, POST_RAM | post_bootmode_get(0));
651 return 0;
652}
653#endif
654
Simon Glass5af29bd2013-03-14 07:20:12 +0000655#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
656static int initr_pcmcia(void)
657{
658 puts("PCMCIA:");
659 pcmcia_init();
660 return 0;
661}
662#endif
663
664#if defined(CONFIG_CMD_IDE)
665static int initr_ide(void)
666{
667#ifdef CONFIG_IDE_8xx_PCCARD
668 puts("PCMCIA:");
669#else
670 puts("IDE: ");
671#endif
672#if defined(CONFIG_START_IDE)
673 if (board_start_ide())
674 ide_init();
675#else
676 ide_init();
677#endif
678 return 0;
679}
680#endif
681
Simon Glassdb397fa2013-03-11 14:30:37 +0000682#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
683/*
684 * Export available size of memory for Linux, taking into account the
685 * protected RAM at top of memory
686 */
687int initr_mem(void)
688{
689 ulong pram = 0;
690 char memsz[32];
691
692# ifdef CONFIG_PRAM
693 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
694# endif
695# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
696 /* Also take the logbuffer into account (pram is in kB) */
697 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
698# endif
Valentin Longchampd6b46942014-10-03 11:16:19 +0200699 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
Simon Glassdb397fa2013-03-11 14:30:37 +0000700 setenv("mem", memsz);
Simon Glass5af29bd2013-03-14 07:20:12 +0000701
702 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000703}
704#endif
705
Simon Glass5af29bd2013-03-14 07:20:12 +0000706#ifdef CONFIG_CMD_BEDBUG
707static int initr_bedbug(void)
708{
709 bedbug_init();
710
711 return 0;
712}
713#endif
714
715#ifdef CONFIG_PS2KBD
716static int initr_kbd(void)
717{
718 puts("PS/2: ");
719 kbd_init();
720 return 0;
721}
722#endif
723
Simon Glassdb397fa2013-03-11 14:30:37 +0000724static int run_main_loop(void)
725{
Simon Glass62cf9122013-04-26 02:53:43 +0000726#ifdef CONFIG_SANDBOX
727 sandbox_main_loop_init();
728#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000729 /* main_loop() can return to retry autoboot, if so just run it again */
730 for (;;)
731 main_loop();
732 return 0;
733}
734
735/*
736 * Over time we hope to remove these functions with code fragments and
737 * stub funtcions, and instead call the relevant function directly.
738 *
739 * We also hope to remove most of the driver-related init and do it if/when
740 * the driver is later used.
Simon Glass5af29bd2013-03-14 07:20:12 +0000741 *
742 * TODO: perhaps reset the watchdog in the initcall function after each call?
Simon Glassdb397fa2013-03-11 14:30:37 +0000743 */
744init_fnc_t init_sequence_r[] = {
Simon Glass209a1a62013-06-11 11:14:42 -0700745 initr_trace,
Simon Glassdb397fa2013-03-11 14:30:37 +0000746 initr_reloc,
Simon Glass5af29bd2013-03-14 07:20:12 +0000747 /* TODO: could x86/PPC have this also perhaps? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000748#ifdef CONFIG_ARM
749 initr_caches,
York Sun820a18f2015-03-20 19:28:11 -0700750 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
751 * A temporary mapping of IFC high region is since removed,
752 * so environmental variables in NOR flash is not availble
753 * until board_init() is called below to remap IFC to high
754 * region.
755 */
Simon Glass712da5e2014-09-03 17:37:01 -0600756#endif
757 initr_reloc_global_data,
York Sun6e78b3b2014-10-02 15:20:10 -0700758#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
759 initr_unlock_ram_in_cache,
760#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600761 initr_barrier,
762 initr_malloc,
Simon Glass1bb49232015-11-08 23:47:48 -0700763 initr_console_record,
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100764#ifdef CONFIG_SYS_NONCACHED_MEMORY
765 initr_noncached,
766#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600767 bootstage_relocate,
768#ifdef CONFIG_DM
769 initr_dm,
770#endif
Simon Glass7edd07d2015-11-28 22:16:35 -0700771 initr_bootstage,
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800772#if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000773 board_init, /* Setup chipselects */
774#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000775 /*
776 * TODO: printing of the clock inforamtion of the board is now
777 * implemented as part of bdinfo command. Currently only support for
778 * davinci SOC's is added. Remove this check once all the board
779 * implement this.
780 */
781#ifdef CONFIG_CLOCKS
782 set_cpu_clk_info, /* Setup clock information */
783#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600784 stdio_init_tables,
Simon Glassdb397fa2013-03-11 14:30:37 +0000785 initr_serial,
786 initr_announce,
Simon Glass5af29bd2013-03-14 07:20:12 +0000787 INIT_FUNC_WATCHDOG_RESET
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100788#ifdef CONFIG_NEEDS_MANUAL_RELOC
789 initr_manual_reloc_cmdtable,
790#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100791#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass5af29bd2013-03-14 07:20:12 +0000792 initr_trap,
793#endif
794#ifdef CONFIG_ADDR_MAP
795 initr_addr_map,
796#endif
797#if defined(CONFIG_BOARD_EARLY_INIT_R)
798 board_early_init_r,
799#endif
800 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000801#ifdef CONFIG_LOGBUFFER
802 initr_logbuffer,
803#endif
804#ifdef CONFIG_POST
805 initr_post_backlog,
806#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000807 INIT_FUNC_WATCHDOG_RESET
808#ifdef CONFIG_SYS_DELAYED_ICACHE
809 initr_icache_enable,
810#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000811#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
812 /*
813 * Do early PCI configuration _before_ the flash gets initialised,
814 * because PCU ressources are crucial for flash access on some boards.
815 */
816 initr_pci,
817#endif
818#ifdef CONFIG_WINBOND_83C553
819 initr_w83c553f,
820#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000821#ifdef CONFIG_ARCH_EARLY_INIT_R
822 arch_early_init_r,
823#endif
824 power_init_board,
825#ifndef CONFIG_SYS_NO_FLASH
826 initr_flash,
827#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000828 INIT_FUNC_WATCHDOG_RESET
Francois Retiefe3051d92015-10-28 14:29:32 +0200829#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86) || \
830 defined(CONFIG_SPARC)
Simon Glass5af29bd2013-03-14 07:20:12 +0000831 /* initialize higher level parts of CPU like time base and timers */
832 cpu_init_r,
Simon Glass6f5567d2013-03-05 14:39:53 +0000833#endif
834#ifdef CONFIG_PPC
Simon Glass5af29bd2013-03-14 07:20:12 +0000835 initr_spi,
836#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000837#ifdef CONFIG_CMD_NAND
838 initr_nand,
839#endif
840#ifdef CONFIG_CMD_ONENAND
841 initr_onenand,
842#endif
843#ifdef CONFIG_GENERIC_MMC
844 initr_mmc,
845#endif
846#ifdef CONFIG_HAS_DATAFLASH
847 initr_dataflash,
848#endif
849 initr_env,
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100850#ifdef CONFIG_SYS_BOOTPARAMS_LEN
851 initr_malloc_bootparams,
852#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000853 INIT_FUNC_WATCHDOG_RESET
854 initr_secondary_cpu,
Simon Glass5af29bd2013-03-14 07:20:12 +0000855#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
856 mac_read_from_eeprom,
857#endif
858 INIT_FUNC_WATCHDOG_RESET
859#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
860 /*
861 * Do pci configuration
862 */
863 initr_pci,
864#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600865 stdio_add_devices,
Simon Glassdb397fa2013-03-11 14:30:37 +0000866 initr_jumptable,
867#ifdef CONFIG_API
868 initr_api,
869#endif
870 console_init_r, /* fully init console as a device */
871#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900872 show_board_info,
Simon Glassdb397fa2013-03-11 14:30:37 +0000873#endif
874#ifdef CONFIG_ARCH_MISC_INIT
875 arch_misc_init, /* miscellaneous arch-dependent init */
876#endif
877#ifdef CONFIG_MISC_INIT_R
878 misc_init_r, /* miscellaneous platform-dependent init */
879#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000880 INIT_FUNC_WATCHDOG_RESET
881#ifdef CONFIG_CMD_KGDB
882 initr_kgdb,
883#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000884 interrupt_init,
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100885#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000886 initr_enable_interrupts,
Simon Glass5af29bd2013-03-14 07:20:12 +0000887#endif
Bin Menge8e589d2015-10-22 19:13:33 -0700888#if defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || defined(CONFIG_M68K)
Simon Glass6f5567d2013-03-05 14:39:53 +0000889 timer_init, /* initialize timer */
890#endif
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200891#if defined(CONFIG_STATUS_LED)
Simon Glass5af29bd2013-03-14 07:20:12 +0000892 initr_status_led,
893#endif
894 /* PPC has a udelay(20) here dating from 2002. Why? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000895#ifdef CONFIG_CMD_NET
896 initr_ethaddr,
897#endif
898#ifdef CONFIG_BOARD_LATE_INIT
899 board_late_init,
900#endif
Francois Retief77732022014-10-27 13:39:03 +0200901#if defined(CONFIG_CMD_AMBAPP)
902 ambapp_init_reloc,
903#if defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
904 initr_ambapp_print,
905#endif
906#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000907#ifdef CONFIG_CMD_SCSI
908 INIT_FUNC_WATCHDOG_RESET
909 initr_scsi,
910#endif
911#ifdef CONFIG_CMD_DOC
912 INIT_FUNC_WATCHDOG_RESET
913 initr_doc,
914#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000915#ifdef CONFIG_BITBANGMII
916 initr_bbmii,
917#endif
918#ifdef CONFIG_CMD_NET
Simon Glass5af29bd2013-03-14 07:20:12 +0000919 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000920 initr_net,
921#endif
922#ifdef CONFIG_POST
923 initr_post,
924#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000925#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
926 initr_pcmcia,
927#endif
928#if defined(CONFIG_CMD_IDE)
929 initr_ide,
930#endif
931#ifdef CONFIG_LAST_STAGE_INIT
932 INIT_FUNC_WATCHDOG_RESET
933 /*
934 * Some parts can be only initialized if all others (like
935 * Interrupts) are up and running (i.e. the PC-style ISA
936 * keyboard).
937 */
938 last_stage_init,
939#endif
940#ifdef CONFIG_CMD_BEDBUG
941 INIT_FUNC_WATCHDOG_RESET
942 initr_bedbug,
943#endif
944#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
945 initr_mem,
946#endif
947#ifdef CONFIG_PS2KBD
948 initr_kbd,
949#endif
Francois Retieffc7784e2015-11-23 13:05:44 +0200950#if defined(CONFIG_SPARC)
951 prom_init,
952#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000953 run_main_loop,
954};
955
956void board_init_r(gd_t *new_gd, ulong dest_addr)
957{
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400958#ifdef CONFIG_NEEDS_MANUAL_RELOC
959 int i;
960#endif
961
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100962#ifdef CONFIG_AVR32
963 mmu_init_r(dest_addr);
964#endif
965
Jeroen Hofstee498f97f2014-07-30 21:54:49 +0200966#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
Simon Glassdb397fa2013-03-11 14:30:37 +0000967 gd = new_gd;
Simon Glass6f5567d2013-03-05 14:39:53 +0000968#endif
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400969
970#ifdef CONFIG_NEEDS_MANUAL_RELOC
971 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
972 init_sequence_r[i] += gd->reloc_off;
973#endif
974
Simon Glassdb397fa2013-03-11 14:30:37 +0000975 if (initcall_run_list(init_sequence_r))
976 hang();
977
978 /* NOTREACHED - run_main_loop() does not return */
979 hang();
980}