blob: c6aa7e5224ab77b8b1cbf7fc2c51d1d9df09fc2b [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
Simon Glassdb397fa2013-03-11 14:30:37 +000018#ifdef CONFIG_HAS_DATAFLASH
19#include <dataflash.h>
20#endif
Simon Glasseea87102014-02-26 15:59:20 -070021#include <dm.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000022#include <environment.h>
23#include <fdtdec.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000024#if defined(CONFIG_CMD_IDE)
25#include <ide.h>
26#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000027#include <initcall.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000028#ifdef CONFIG_PS2KBD
29#include <keyboard.h>
30#endif
31#if defined(CONFIG_CMD_KGDB)
32#include <kgdb.h>
33#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000034#include <logbuff.h>
35#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050036#include <mapmem.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000037#ifdef CONFIG_BITBANGMII
38#include <miiphy.h>
39#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000040#include <mmc.h>
41#include <nand.h>
42#include <onenand_uboot.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000043#include <scsi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000044#include <serial.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000045#include <spi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000046#include <stdio_dev.h>
Simon Glass209a1a62013-06-11 11:14:42 -070047#include <trace.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000048#include <watchdog.h>
Francois Retief77732022014-10-27 13:39:03 +020049#ifdef CONFIG_CMD_AMBAPP
50#include <ambapp.h>
51#endif
Simon Glass5af29bd2013-03-14 07:20:12 +000052#ifdef CONFIG_ADDR_MAP
53#include <asm/mmu.h>
54#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000055#include <asm/sections.h>
Simon Glass6f5567d2013-03-05 14:39:53 +000056#ifdef CONFIG_X86
57#include <asm/init_helpers.h>
58#endif
Simon Glasseea87102014-02-26 15:59:20 -070059#include <dm/root.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000060#include <linux/compiler.h>
Simon Glasseea87102014-02-26 15:59:20 -070061#include <linux/err.h>
Andreas Bießmannc1d09172015-02-06 23:06:48 +010062#ifdef CONFIG_AVR32
63#include <asm/arch/mmu.h>
64#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000065
66DECLARE_GLOBAL_DATA_PTR;
67
68ulong monitor_flash_len;
69
Jeroen Hofstee45846052014-10-08 22:57:22 +020070__weak int board_flash_wp_on(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000071{
72 /*
73 * Most flashes can't be detected when write protection is enabled,
74 * so provide a way to let U-Boot gracefully ignore write protected
75 * devices.
76 */
77 return 0;
78}
79
Jeroen Hofstee45846052014-10-08 22:57:22 +020080__weak void cpu_secondary_init_r(void)
Simon Glass5af29bd2013-03-14 07:20:12 +000081{
82}
83
Simon Glass5af29bd2013-03-14 07:20:12 +000084static int initr_secondary_cpu(void)
85{
86 /*
87 * after non-volatile devices & environment is setup and cpu code have
88 * another round to deal with any initialization that might require
89 * full access to the environment or loading of some image (firmware)
90 * from a non-volatile device
91 */
92 /* TODO: maybe define this for all archs? */
93 cpu_secondary_init_r();
94
95 return 0;
96}
Simon Glassdb397fa2013-03-11 14:30:37 +000097
Simon Glass209a1a62013-06-11 11:14:42 -070098static int initr_trace(void)
99{
100#ifdef CONFIG_TRACE
101 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
102#endif
103
104 return 0;
105}
106
Simon Glassdb397fa2013-03-11 14:30:37 +0000107static int initr_reloc(void)
108{
Simon Glass94890462014-11-10 17:16:43 -0700109 /* tell others: relocation done */
110 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
Simon Glassdb397fa2013-03-11 14:30:37 +0000111 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
112
113 return 0;
114}
115
116#ifdef CONFIG_ARM
117/*
118 * Some of these functions are needed purely because the functions they
119 * call return void. If we change them to return 0, these stubs can go away.
120 */
121static int initr_caches(void)
122{
123 /* Enable caches */
124 enable_caches();
125 return 0;
126}
127#endif
128
Simon Glass5af29bd2013-03-14 07:20:12 +0000129__weak int fixup_cpu(void)
130{
131 return 0;
132}
133
Simon Glassdb397fa2013-03-11 14:30:37 +0000134static int initr_reloc_global_data(void)
135{
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100136#ifdef __ARM__
137 monitor_flash_len = _end - __image_copy_start;
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800138#elif defined(CONFIG_NDS32)
139 monitor_flash_len = (ulong)&_end - (ulong)&_start;
Thomas Choucce3e752014-08-22 11:36:47 +0800140#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000141 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
Simon Glassdb397fa2013-03-11 14:30:37 +0000142#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000143#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
144 /*
145 * The gd->cpu pointer is set to an address in flash before relocation.
146 * We need to update it to point to the same CPU entry in RAM.
147 * TODO: why not just add gd->reloc_ofs?
148 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000149 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000150
151 /*
152 * If we didn't know the cpu mask & # cores, we can save them of
153 * now rather than 'computing' them constantly
154 */
155 fixup_cpu();
156#endif
157#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
158 /*
159 * Some systems need to relocate the env_addr pointer early because the
160 * location it points to will get invalidated before env_relocate is
161 * called. One example is on systems that might use a L2 or L3 cache
162 * in SRAM mode and initialize that cache from SRAM mode back to being
163 * a cache in cpu_init_r.
164 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000165 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000166#endif
167 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000168}
169
170static int initr_serial(void)
171{
172 serial_initialize();
173 return 0;
174}
175
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100176#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass5af29bd2013-03-14 07:20:12 +0000177static int initr_trap(void)
178{
179 /*
180 * Setup trap handlers
181 */
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100182#if defined(CONFIG_PPC)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000183 trap_init(gd->relocaddr);
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100184#else
185 trap_init(CONFIG_SYS_SDRAM_BASE);
186#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000187 return 0;
188}
189#endif
190
191#ifdef CONFIG_ADDR_MAP
192static int initr_addr_map(void)
193{
194 init_addr_map();
195
196 return 0;
197}
198#endif
199
Simon Glassdb397fa2013-03-11 14:30:37 +0000200#ifdef CONFIG_LOGBUFFER
201unsigned long logbuffer_base(void)
202{
203 return gd->ram_top - LOGBUFF_LEN;
204}
205
206static int initr_logbuffer(void)
207{
208 logbuff_init_ptrs();
209 return 0;
210}
211#endif
212
213#ifdef CONFIG_POST
214static int initr_post_backlog(void)
215{
216 post_output_backlog();
217 return 0;
218}
219#endif
220
Simon Glass5af29bd2013-03-14 07:20:12 +0000221#ifdef CONFIG_SYS_DELAYED_ICACHE
222static int initr_icache_enable(void)
223{
224 return 0;
225}
226#endif
227
228#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
229static int initr_unlock_ram_in_cache(void)
230{
231 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
232 return 0;
233}
234#endif
235
236#ifdef CONFIG_PCI
237static int initr_pci(void)
238{
Simon Glassb94dc892015-03-05 12:25:25 -0700239#ifndef CONFIG_DM_PCI
Simon Glass5af29bd2013-03-14 07:20:12 +0000240 pci_init();
Simon Glassb94dc892015-03-05 12:25:25 -0700241#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000242
243 return 0;
244}
245#endif
246
247#ifdef CONFIG_WINBOND_83C553
248static int initr_w83c553f(void)
249{
250 /*
251 * Initialise the ISA bridge
252 */
253 initialise_w83c553f();
254 return 0;
255}
256#endif
257
258static int initr_barrier(void)
259{
260#ifdef CONFIG_PPC
261 /* TODO: Can we not use dmb() macros for this? */
262 asm("sync ; isync");
263#endif
264 return 0;
265}
266
Simon Glassdb397fa2013-03-11 14:30:37 +0000267static int initr_malloc(void)
268{
269 ulong malloc_start;
270
Simon Glass863e4042014-07-10 22:23:28 -0600271#ifdef CONFIG_SYS_MALLOC_F_LEN
272 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
273 gd->malloc_ptr / 1024);
274#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000275 /* The malloc area is immediately below the monitor copy in DRAM */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000276 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
Simon Glass62cf9122013-04-26 02:53:43 +0000277 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
278 TOTAL_MALLOC_LEN);
Simon Glassdb397fa2013-03-11 14:30:37 +0000279 return 0;
280}
Thierry Redingc97d9742014-12-09 22:25:22 -0700281
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100282#ifdef CONFIG_SYS_NONCACHED_MEMORY
283static int initr_noncached(void)
284{
285 noncached_init();
286 return 0;
287}
288#endif
289
Simon Glasseea87102014-02-26 15:59:20 -0700290#ifdef CONFIG_DM
291static int initr_dm(void)
292{
Simon Glassa730c5d2014-07-23 06:55:04 -0600293 /* Save the pre-reloc driver model and start a new one */
294 gd->dm_root_f = gd->dm_root;
295 gd->dm_root = NULL;
Thomas Chou78815972015-10-09 13:48:56 +0800296#ifdef CONFIG_TIMER
297 gd->timer = NULL;
298#endif
Simon Glassa730c5d2014-07-23 06:55:04 -0600299 return dm_init_and_scan(false);
Simon Glasseea87102014-02-26 15:59:20 -0700300}
301#endif
302
Simon Glassdb397fa2013-03-11 14:30:37 +0000303__weak int power_init_board(void)
304{
305 return 0;
306}
307
308static int initr_announce(void)
309{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000310 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
Simon Glassdb397fa2013-03-11 14:30:37 +0000311 return 0;
312}
313
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100314#ifdef CONFIG_NEEDS_MANUAL_RELOC
315static int initr_manual_reloc_cmdtable(void)
316{
317 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
318 ll_entry_count(cmd_tbl_t, cmd));
319 return 0;
320}
321#endif
322
Simon Glassdb397fa2013-03-11 14:30:37 +0000323#if !defined(CONFIG_SYS_NO_FLASH)
324static int initr_flash(void)
325{
Simon Glass5af29bd2013-03-14 07:20:12 +0000326 ulong flash_size = 0;
327 bd_t *bd = gd->bd;
Simon Glassdb397fa2013-03-11 14:30:37 +0000328
329 puts("Flash: ");
330
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900331 if (board_flash_wp_on())
Simon Glass5af29bd2013-03-14 07:20:12 +0000332 printf("Uninitialized - Write Protect On\n");
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900333 else
Simon Glass5af29bd2013-03-14 07:20:12 +0000334 flash_size = flash_init();
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900335
Simon Glassdb397fa2013-03-11 14:30:37 +0000336 print_size(flash_size, "");
337#ifdef CONFIG_SYS_FLASH_CHECKSUM
338 /*
339 * Compute and print flash CRC if flashchecksum is set to 'y'
340 *
341 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
342 */
343 if (getenv_yesno("flashchecksum") == 1) {
344 printf(" CRC: %08X", crc32(0,
345 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
346 flash_size));
347 }
348#endif /* CONFIG_SYS_FLASH_CHECKSUM */
349 putc('\n');
350
Simon Glass5af29bd2013-03-14 07:20:12 +0000351 /* update start of FLASH memory */
352#ifdef CONFIG_SYS_FLASH_BASE
353 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
354#endif
355 /* size of FLASH memory (final value) */
356 bd->bi_flashsize = flash_size;
357
358#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
359 /* Make a update of the Memctrl. */
360 update_flash_size(flash_size);
361#endif
362
363
364#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
365 /* flash mapped at end of memory map */
366 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
367#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
368 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
369#endif
370 return 0;
371}
372#endif
373
Simon Glass55316ad2014-10-13 23:41:54 -0600374#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000375static int initr_spi(void)
376{
377 /* PPC does this here */
378#ifdef CONFIG_SPI
379#if !defined(CONFIG_ENV_IS_IN_EEPROM)
380 spi_init_f();
381#endif
382 spi_init_r();
383#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000384 return 0;
385}
386#endif
387
388#ifdef CONFIG_CMD_NAND
389/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200390static int initr_nand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000391{
392 puts("NAND: ");
393 nand_init();
394 return 0;
395}
396#endif
397
398#if defined(CONFIG_CMD_ONENAND)
399/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200400static int initr_onenand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000401{
402 puts("NAND: ");
403 onenand_init();
404 return 0;
405}
406#endif
407
408#ifdef CONFIG_GENERIC_MMC
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200409static int initr_mmc(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000410{
411 puts("MMC: ");
412 mmc_initialize(gd->bd);
413 return 0;
414}
415#endif
416
417#ifdef CONFIG_HAS_DATAFLASH
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200418static int initr_dataflash(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000419{
420 AT91F_DataflashInit();
421 dataflash_print_info();
422 return 0;
423}
424#endif
425
426/*
427 * Tell if it's OK to load the environment early in boot.
428 *
429 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
430 * if this is OK (defaulting to saying it's OK).
431 *
432 * NOTE: Loading the environment early can be a bad idea if security is
433 * important, since no verification is done on the environment.
434 *
435 * @return 0 if environment should not be loaded, !=0 if it is ok to load
436 */
437static int should_load_env(void)
438{
439#ifdef CONFIG_OF_CONTROL
440 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
441#elif defined CONFIG_DELAY_ENVIRONMENT
442 return 0;
443#else
444 return 1;
445#endif
446}
447
448static int initr_env(void)
449{
450 /* initialize environment */
451 if (should_load_env())
452 env_relocate();
453 else
454 set_default_env(NULL);
Thomas Chou4fda2812015-10-16 08:44:51 +0800455#ifdef CONFIG_OF_CONTROL
456 setenv_addr("fdtcontroladdr", gd->fdt_blob);
457#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000458
459 /* Initialize from environment */
460 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000461#if defined(CONFIG_SYS_EXTBDINFO)
462#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
463#if defined(CONFIG_I2CFAST)
464 /*
465 * set bi_iic_fast for linux taking environment variable
466 * "i2cfast" into account
467 */
468 {
469 char *s = getenv("i2cfast");
470
471 if (s && ((*s == 'y') || (*s == 'Y'))) {
472 gd->bd->bi_iic_fast[0] = 1;
473 gd->bd->bi_iic_fast[1] = 1;
474 }
475 }
476#endif /* CONFIG_I2CFAST */
477#endif /* CONFIG_405GP, CONFIG_405EP */
478#endif /* CONFIG_SYS_EXTBDINFO */
479 return 0;
480}
481
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100482#ifdef CONFIG_SYS_BOOTPARAMS_LEN
483static int initr_malloc_bootparams(void)
484{
485 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
486 if (!gd->bd->bi_boot_params) {
487 puts("WARNING: Cannot allocate space for boot parameters\n");
488 return -ENOMEM;
489 }
490 return 0;
491}
492#endif
493
Simon Glassdb397fa2013-03-11 14:30:37 +0000494static int initr_jumptable(void)
495{
496 jumptable_init();
497 return 0;
498}
499
500#if defined(CONFIG_API)
501static int initr_api(void)
502{
503 /* Initialize API */
504 api_init();
505 return 0;
506}
507#endif
508
Simon Glassdb397fa2013-03-11 14:30:37 +0000509/* enable exceptions */
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100510#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000511static int initr_enable_interrupts(void)
512{
513 enable_interrupts();
514 return 0;
515}
Simon Glass2e4622d2013-03-11 07:40:13 +0000516#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000517
518#ifdef CONFIG_CMD_NET
519static int initr_ethaddr(void)
520{
Simon Glass5af29bd2013-03-14 07:20:12 +0000521 bd_t *bd = gd->bd;
522
523 /* kept around for legacy kernels only ... ignore the next section */
524 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
525#ifdef CONFIG_HAS_ETH1
526 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
527#endif
528#ifdef CONFIG_HAS_ETH2
529 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
530#endif
531#ifdef CONFIG_HAS_ETH3
532 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
533#endif
534#ifdef CONFIG_HAS_ETH4
535 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
536#endif
537#ifdef CONFIG_HAS_ETH5
538 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
539#endif
540 return 0;
541}
542#endif /* CONFIG_CMD_NET */
543
544#ifdef CONFIG_CMD_KGDB
545static int initr_kgdb(void)
546{
547 puts("KGDB: ");
548 kgdb_init();
549 return 0;
550}
551#endif
552
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200553#if defined(CONFIG_STATUS_LED)
Simon Glass5af29bd2013-03-14 07:20:12 +0000554static int initr_status_led(void)
555{
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200556#if defined(STATUS_LED_BOOT)
Simon Glass5af29bd2013-03-14 07:20:12 +0000557 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200558#else
559 status_led_init();
560#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000561 return 0;
562}
563#endif
564
Francois Retief77732022014-10-27 13:39:03 +0200565#if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
566extern int do_ambapp_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
567
568static int initr_ambapp_print(void)
569{
570 puts("AMBA:\n");
571 do_ambapp_print(NULL, 0, 0, NULL);
572
573 return 0;
574}
575#endif
576
Simon Glass5af29bd2013-03-14 07:20:12 +0000577#if defined(CONFIG_CMD_SCSI)
578static int initr_scsi(void)
579{
Simon Glass5af29bd2013-03-14 07:20:12 +0000580 puts("SCSI: ");
581 scsi_init();
Simon Glassdb397fa2013-03-11 14:30:37 +0000582
583 return 0;
584}
Ian Campbell63d424b2014-07-21 19:23:18 +0100585#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000586
Simon Glass5af29bd2013-03-14 07:20:12 +0000587#if defined(CONFIG_CMD_DOC)
588static int initr_doc(void)
589{
590 puts("DOC: ");
591 doc_init();
Ian Campbell1e81e5b2014-07-24 09:29:57 +0100592 return 0;
Simon Glass5af29bd2013-03-14 07:20:12 +0000593}
594#endif
595
Simon Glassdb397fa2013-03-11 14:30:37 +0000596#ifdef CONFIG_BITBANGMII
597static int initr_bbmii(void)
598{
599 bb_miiphy_init();
600 return 0;
601}
602#endif
603
604#ifdef CONFIG_CMD_NET
605static int initr_net(void)
606{
607 puts("Net: ");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500608 eth_initialize();
Simon Glassdb397fa2013-03-11 14:30:37 +0000609#if defined(CONFIG_RESET_PHY_R)
610 debug("Reset Ethernet PHY\n");
611 reset_phy();
612#endif
613 return 0;
614}
615#endif
616
617#ifdef CONFIG_POST
618static int initr_post(void)
619{
620 post_run(NULL, POST_RAM | post_bootmode_get(0));
621 return 0;
622}
623#endif
624
Simon Glass5af29bd2013-03-14 07:20:12 +0000625#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
626static int initr_pcmcia(void)
627{
628 puts("PCMCIA:");
629 pcmcia_init();
630 return 0;
631}
632#endif
633
634#if defined(CONFIG_CMD_IDE)
635static int initr_ide(void)
636{
637#ifdef CONFIG_IDE_8xx_PCCARD
638 puts("PCMCIA:");
639#else
640 puts("IDE: ");
641#endif
642#if defined(CONFIG_START_IDE)
643 if (board_start_ide())
644 ide_init();
645#else
646 ide_init();
647#endif
648 return 0;
649}
650#endif
651
Simon Glassdb397fa2013-03-11 14:30:37 +0000652#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
653/*
654 * Export available size of memory for Linux, taking into account the
655 * protected RAM at top of memory
656 */
657int initr_mem(void)
658{
659 ulong pram = 0;
660 char memsz[32];
661
662# ifdef CONFIG_PRAM
663 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
664# endif
665# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
666 /* Also take the logbuffer into account (pram is in kB) */
667 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
668# endif
Valentin Longchampd6b46942014-10-03 11:16:19 +0200669 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
Simon Glassdb397fa2013-03-11 14:30:37 +0000670 setenv("mem", memsz);
Simon Glass5af29bd2013-03-14 07:20:12 +0000671
672 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000673}
674#endif
675
Simon Glass5af29bd2013-03-14 07:20:12 +0000676#ifdef CONFIG_CMD_BEDBUG
677static int initr_bedbug(void)
678{
679 bedbug_init();
680
681 return 0;
682}
683#endif
684
685#ifdef CONFIG_PS2KBD
686static int initr_kbd(void)
687{
688 puts("PS/2: ");
689 kbd_init();
690 return 0;
691}
692#endif
693
Simon Glassdb397fa2013-03-11 14:30:37 +0000694static int run_main_loop(void)
695{
Simon Glass62cf9122013-04-26 02:53:43 +0000696#ifdef CONFIG_SANDBOX
697 sandbox_main_loop_init();
698#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000699 /* main_loop() can return to retry autoboot, if so just run it again */
700 for (;;)
701 main_loop();
702 return 0;
703}
704
705/*
706 * Over time we hope to remove these functions with code fragments and
707 * stub funtcions, and instead call the relevant function directly.
708 *
709 * We also hope to remove most of the driver-related init and do it if/when
710 * the driver is later used.
Simon Glass5af29bd2013-03-14 07:20:12 +0000711 *
712 * TODO: perhaps reset the watchdog in the initcall function after each call?
Simon Glassdb397fa2013-03-11 14:30:37 +0000713 */
714init_fnc_t init_sequence_r[] = {
Simon Glass209a1a62013-06-11 11:14:42 -0700715 initr_trace,
Simon Glassdb397fa2013-03-11 14:30:37 +0000716 initr_reloc,
Simon Glass5af29bd2013-03-14 07:20:12 +0000717 /* TODO: could x86/PPC have this also perhaps? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000718#ifdef CONFIG_ARM
719 initr_caches,
York Sun820a18f2015-03-20 19:28:11 -0700720 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
721 * A temporary mapping of IFC high region is since removed,
722 * so environmental variables in NOR flash is not availble
723 * until board_init() is called below to remap IFC to high
724 * region.
725 */
Simon Glass712da5e2014-09-03 17:37:01 -0600726#endif
727 initr_reloc_global_data,
York Sun6e78b3b2014-10-02 15:20:10 -0700728#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
729 initr_unlock_ram_in_cache,
730#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600731 initr_barrier,
732 initr_malloc,
Jan Kiszkaa714a6b92015-03-09 07:47:18 +0100733#ifdef CONFIG_SYS_NONCACHED_MEMORY
734 initr_noncached,
735#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600736 bootstage_relocate,
737#ifdef CONFIG_DM
738 initr_dm,
739#endif
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800740#if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000741 board_init, /* Setup chipselects */
742#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000743 /*
744 * TODO: printing of the clock inforamtion of the board is now
745 * implemented as part of bdinfo command. Currently only support for
746 * davinci SOC's is added. Remove this check once all the board
747 * implement this.
748 */
749#ifdef CONFIG_CLOCKS
750 set_cpu_clk_info, /* Setup clock information */
751#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600752 stdio_init_tables,
Simon Glassdb397fa2013-03-11 14:30:37 +0000753 initr_serial,
754 initr_announce,
Simon Glass5af29bd2013-03-14 07:20:12 +0000755 INIT_FUNC_WATCHDOG_RESET
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100756#ifdef CONFIG_NEEDS_MANUAL_RELOC
757 initr_manual_reloc_cmdtable,
758#endif
angelo@sysam.itf245ae92015-02-12 01:40:17 +0100759#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Simon Glass5af29bd2013-03-14 07:20:12 +0000760 initr_trap,
761#endif
762#ifdef CONFIG_ADDR_MAP
763 initr_addr_map,
764#endif
765#if defined(CONFIG_BOARD_EARLY_INIT_R)
766 board_early_init_r,
767#endif
768 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000769#ifdef CONFIG_LOGBUFFER
770 initr_logbuffer,
771#endif
772#ifdef CONFIG_POST
773 initr_post_backlog,
774#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000775 INIT_FUNC_WATCHDOG_RESET
776#ifdef CONFIG_SYS_DELAYED_ICACHE
777 initr_icache_enable,
778#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000779#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
780 /*
781 * Do early PCI configuration _before_ the flash gets initialised,
782 * because PCU ressources are crucial for flash access on some boards.
783 */
784 initr_pci,
785#endif
786#ifdef CONFIG_WINBOND_83C553
787 initr_w83c553f,
788#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000789#ifdef CONFIG_ARCH_EARLY_INIT_R
790 arch_early_init_r,
791#endif
792 power_init_board,
793#ifndef CONFIG_SYS_NO_FLASH
794 initr_flash,
795#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000796 INIT_FUNC_WATCHDOG_RESET
Simon Glass02fe5e62015-04-29 22:26:01 -0600797#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
Simon Glass5af29bd2013-03-14 07:20:12 +0000798 /* initialize higher level parts of CPU like time base and timers */
799 cpu_init_r,
Simon Glass6f5567d2013-03-05 14:39:53 +0000800#endif
801#ifdef CONFIG_PPC
Simon Glass5af29bd2013-03-14 07:20:12 +0000802 initr_spi,
803#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000804#ifdef CONFIG_CMD_NAND
805 initr_nand,
806#endif
807#ifdef CONFIG_CMD_ONENAND
808 initr_onenand,
809#endif
810#ifdef CONFIG_GENERIC_MMC
811 initr_mmc,
812#endif
813#ifdef CONFIG_HAS_DATAFLASH
814 initr_dataflash,
815#endif
816 initr_env,
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100817#ifdef CONFIG_SYS_BOOTPARAMS_LEN
818 initr_malloc_bootparams,
819#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000820 INIT_FUNC_WATCHDOG_RESET
821 initr_secondary_cpu,
Simon Glass5af29bd2013-03-14 07:20:12 +0000822#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
823 mac_read_from_eeprom,
824#endif
825 INIT_FUNC_WATCHDOG_RESET
826#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
827 /*
828 * Do pci configuration
829 */
830 initr_pci,
831#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600832 stdio_add_devices,
Simon Glassdb397fa2013-03-11 14:30:37 +0000833 initr_jumptable,
834#ifdef CONFIG_API
835 initr_api,
836#endif
837 console_init_r, /* fully init console as a device */
838#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900839 show_board_info,
Simon Glassdb397fa2013-03-11 14:30:37 +0000840#endif
841#ifdef CONFIG_ARCH_MISC_INIT
842 arch_misc_init, /* miscellaneous arch-dependent init */
843#endif
844#ifdef CONFIG_MISC_INIT_R
845 misc_init_r, /* miscellaneous platform-dependent init */
846#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000847 INIT_FUNC_WATCHDOG_RESET
848#ifdef CONFIG_CMD_KGDB
849 initr_kgdb,
850#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000851 interrupt_init,
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100852#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000853 initr_enable_interrupts,
Simon Glass5af29bd2013-03-14 07:20:12 +0000854#endif
Bin Menge8e589d2015-10-22 19:13:33 -0700855#if defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || defined(CONFIG_M68K)
Simon Glass6f5567d2013-03-05 14:39:53 +0000856 timer_init, /* initialize timer */
857#endif
Bernhard Nortmannc5dcb4a2015-08-21 15:13:21 +0200858#if defined(CONFIG_STATUS_LED)
Simon Glass5af29bd2013-03-14 07:20:12 +0000859 initr_status_led,
860#endif
861 /* PPC has a udelay(20) here dating from 2002. Why? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000862#ifdef CONFIG_CMD_NET
863 initr_ethaddr,
864#endif
865#ifdef CONFIG_BOARD_LATE_INIT
866 board_late_init,
867#endif
Francois Retief77732022014-10-27 13:39:03 +0200868#if defined(CONFIG_CMD_AMBAPP)
869 ambapp_init_reloc,
870#if defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
871 initr_ambapp_print,
872#endif
873#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000874#ifdef CONFIG_CMD_SCSI
875 INIT_FUNC_WATCHDOG_RESET
876 initr_scsi,
877#endif
878#ifdef CONFIG_CMD_DOC
879 INIT_FUNC_WATCHDOG_RESET
880 initr_doc,
881#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000882#ifdef CONFIG_BITBANGMII
883 initr_bbmii,
884#endif
885#ifdef CONFIG_CMD_NET
Simon Glass5af29bd2013-03-14 07:20:12 +0000886 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000887 initr_net,
888#endif
889#ifdef CONFIG_POST
890 initr_post,
891#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000892#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
893 initr_pcmcia,
894#endif
895#if defined(CONFIG_CMD_IDE)
896 initr_ide,
897#endif
898#ifdef CONFIG_LAST_STAGE_INIT
899 INIT_FUNC_WATCHDOG_RESET
900 /*
901 * Some parts can be only initialized if all others (like
902 * Interrupts) are up and running (i.e. the PC-style ISA
903 * keyboard).
904 */
905 last_stage_init,
906#endif
907#ifdef CONFIG_CMD_BEDBUG
908 INIT_FUNC_WATCHDOG_RESET
909 initr_bedbug,
910#endif
911#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
912 initr_mem,
913#endif
914#ifdef CONFIG_PS2KBD
915 initr_kbd,
916#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000917 run_main_loop,
918};
919
920void board_init_r(gd_t *new_gd, ulong dest_addr)
921{
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400922#ifdef CONFIG_NEEDS_MANUAL_RELOC
923 int i;
924#endif
925
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100926#ifdef CONFIG_AVR32
927 mmu_init_r(dest_addr);
928#endif
929
Jeroen Hofstee498f97f2014-07-30 21:54:49 +0200930#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
Simon Glassdb397fa2013-03-11 14:30:37 +0000931 gd = new_gd;
Simon Glass6f5567d2013-03-05 14:39:53 +0000932#endif
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400933
934#ifdef CONFIG_NEEDS_MANUAL_RELOC
935 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
936 init_sequence_r[i] += gd->reloc_off;
937#endif
938
Simon Glassdb397fa2013-03-11 14:30:37 +0000939 if (initcall_run_list(init_sequence_r))
940 hang();
941
942 /* NOTREACHED - run_main_loop() does not return */
943 hang();
944}