blob: 4fcd4f6a7057e3ba8afeb985869f358718fa7c66 [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>
Simon Glass5af29bd2013-03-14 07:20:12 +000036#ifdef CONFIG_BITBANGMII
37#include <miiphy.h>
38#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000039#include <mmc.h>
40#include <nand.h>
41#include <onenand_uboot.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000042#include <scsi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000043#include <serial.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000044#include <spi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000045#include <stdio_dev.h>
Simon Glass209a1a62013-06-11 11:14:42 -070046#include <trace.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000047#include <watchdog.h>
48#ifdef CONFIG_ADDR_MAP
49#include <asm/mmu.h>
50#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000051#include <asm/sections.h>
Simon Glass6f5567d2013-03-05 14:39:53 +000052#ifdef CONFIG_X86
53#include <asm/init_helpers.h>
54#endif
Simon Glasseea87102014-02-26 15:59:20 -070055#include <dm/root.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000056#include <linux/compiler.h>
Simon Glasseea87102014-02-26 15:59:20 -070057#include <linux/err.h>
Andreas Bießmannc1d09172015-02-06 23:06:48 +010058#ifdef CONFIG_AVR32
59#include <asm/arch/mmu.h>
60#endif
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 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
108
109 return 0;
110}
111
112#ifdef CONFIG_ARM
113/*
114 * Some of these functions are needed purely because the functions they
115 * call return void. If we change them to return 0, these stubs can go away.
116 */
117static int initr_caches(void)
118{
119 /* Enable caches */
120 enable_caches();
121 return 0;
122}
123#endif
124
Simon Glass5af29bd2013-03-14 07:20:12 +0000125__weak int fixup_cpu(void)
126{
127 return 0;
128}
129
Simon Glassdb397fa2013-03-11 14:30:37 +0000130static int initr_reloc_global_data(void)
131{
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100132#ifdef __ARM__
133 monitor_flash_len = _end - __image_copy_start;
Thomas Choucce3e752014-08-22 11:36:47 +0800134#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000135 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
Simon Glassdb397fa2013-03-11 14:30:37 +0000136#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000137#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
138 /*
139 * The gd->cpu pointer is set to an address in flash before relocation.
140 * We need to update it to point to the same CPU entry in RAM.
141 * TODO: why not just add gd->reloc_ofs?
142 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000143 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000144
145 /*
146 * If we didn't know the cpu mask & # cores, we can save them of
147 * now rather than 'computing' them constantly
148 */
149 fixup_cpu();
150#endif
151#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
152 /*
153 * Some systems need to relocate the env_addr pointer early because the
154 * location it points to will get invalidated before env_relocate is
155 * called. One example is on systems that might use a L2 or L3 cache
156 * in SRAM mode and initialize that cache from SRAM mode back to being
157 * a cache in cpu_init_r.
158 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000159 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000160#endif
161 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000162}
163
164static int initr_serial(void)
165{
166 serial_initialize();
167 return 0;
168}
169
Simon Glass5af29bd2013-03-14 07:20:12 +0000170#ifdef CONFIG_PPC
171static int initr_trap(void)
172{
173 /*
174 * Setup trap handlers
175 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000176 trap_init(gd->relocaddr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000177
178 return 0;
179}
180#endif
181
182#ifdef CONFIG_ADDR_MAP
183static int initr_addr_map(void)
184{
185 init_addr_map();
186
187 return 0;
188}
189#endif
190
Simon Glassdb397fa2013-03-11 14:30:37 +0000191#ifdef CONFIG_LOGBUFFER
192unsigned long logbuffer_base(void)
193{
194 return gd->ram_top - LOGBUFF_LEN;
195}
196
197static int initr_logbuffer(void)
198{
199 logbuff_init_ptrs();
200 return 0;
201}
202#endif
203
204#ifdef CONFIG_POST
205static int initr_post_backlog(void)
206{
207 post_output_backlog();
208 return 0;
209}
210#endif
211
Simon Glass5af29bd2013-03-14 07:20:12 +0000212#ifdef CONFIG_SYS_DELAYED_ICACHE
213static int initr_icache_enable(void)
214{
215 return 0;
216}
217#endif
218
219#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
220static int initr_unlock_ram_in_cache(void)
221{
222 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
223 return 0;
224}
225#endif
226
227#ifdef CONFIG_PCI
228static int initr_pci(void)
229{
230 pci_init();
231
232 return 0;
233}
234#endif
235
236#ifdef CONFIG_WINBOND_83C553
237static int initr_w83c553f(void)
238{
239 /*
240 * Initialise the ISA bridge
241 */
242 initialise_w83c553f();
243 return 0;
244}
245#endif
246
247static int initr_barrier(void)
248{
249#ifdef CONFIG_PPC
250 /* TODO: Can we not use dmb() macros for this? */
251 asm("sync ; isync");
252#endif
253 return 0;
254}
255
Simon Glassdb397fa2013-03-11 14:30:37 +0000256static int initr_malloc(void)
257{
258 ulong malloc_start;
259
Simon Glass863e4042014-07-10 22:23:28 -0600260#ifdef CONFIG_SYS_MALLOC_F_LEN
261 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
262 gd->malloc_ptr / 1024);
263#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000264 /* The malloc area is immediately below the monitor copy in DRAM */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000265 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
Simon Glass62cf9122013-04-26 02:53:43 +0000266 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
267 TOTAL_MALLOC_LEN);
Simon Glassdb397fa2013-03-11 14:30:37 +0000268 return 0;
269}
270
Thierry Redingc97d9742014-12-09 22:25:22 -0700271#ifdef CONFIG_SYS_NONCACHED_MEMORY
272static int initr_noncached(void)
273{
274 noncached_init();
275 return 0;
276}
277#endif
278
Simon Glasseea87102014-02-26 15:59:20 -0700279#ifdef CONFIG_DM
280static int initr_dm(void)
281{
Simon Glassa730c5d2014-07-23 06:55:04 -0600282 /* Save the pre-reloc driver model and start a new one */
283 gd->dm_root_f = gd->dm_root;
284 gd->dm_root = NULL;
285 return dm_init_and_scan(false);
Simon Glasseea87102014-02-26 15:59:20 -0700286}
287#endif
288
Simon Glassdb397fa2013-03-11 14:30:37 +0000289__weak int power_init_board(void)
290{
291 return 0;
292}
293
294static int initr_announce(void)
295{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000296 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
Simon Glassdb397fa2013-03-11 14:30:37 +0000297 return 0;
298}
299
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100300#ifdef CONFIG_NEEDS_MANUAL_RELOC
301static int initr_manual_reloc_cmdtable(void)
302{
303 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
304 ll_entry_count(cmd_tbl_t, cmd));
305 return 0;
306}
307#endif
308
Simon Glassdb397fa2013-03-11 14:30:37 +0000309#if !defined(CONFIG_SYS_NO_FLASH)
310static int initr_flash(void)
311{
Simon Glass5af29bd2013-03-14 07:20:12 +0000312 ulong flash_size = 0;
313 bd_t *bd = gd->bd;
Simon Glassdb397fa2013-03-11 14:30:37 +0000314
315 puts("Flash: ");
316
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900317 if (board_flash_wp_on())
Simon Glass5af29bd2013-03-14 07:20:12 +0000318 printf("Uninitialized - Write Protect On\n");
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900319 else
Simon Glass5af29bd2013-03-14 07:20:12 +0000320 flash_size = flash_init();
Masahiro Yamadaeb0e02b2014-12-05 12:20:58 +0900321
Simon Glassdb397fa2013-03-11 14:30:37 +0000322 print_size(flash_size, "");
323#ifdef CONFIG_SYS_FLASH_CHECKSUM
324 /*
325 * Compute and print flash CRC if flashchecksum is set to 'y'
326 *
327 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
328 */
329 if (getenv_yesno("flashchecksum") == 1) {
330 printf(" CRC: %08X", crc32(0,
331 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
332 flash_size));
333 }
334#endif /* CONFIG_SYS_FLASH_CHECKSUM */
335 putc('\n');
336
Simon Glass5af29bd2013-03-14 07:20:12 +0000337 /* update start of FLASH memory */
338#ifdef CONFIG_SYS_FLASH_BASE
339 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
340#endif
341 /* size of FLASH memory (final value) */
342 bd->bi_flashsize = flash_size;
343
344#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
345 /* Make a update of the Memctrl. */
346 update_flash_size(flash_size);
347#endif
348
349
350#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
351 /* flash mapped at end of memory map */
352 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
353#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
354 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
355#endif
356 return 0;
357}
358#endif
359
Simon Glass55316ad2014-10-13 23:41:54 -0600360#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
Simon Glass5af29bd2013-03-14 07:20:12 +0000361static int initr_spi(void)
362{
363 /* PPC does this here */
364#ifdef CONFIG_SPI
365#if !defined(CONFIG_ENV_IS_IN_EEPROM)
366 spi_init_f();
367#endif
368 spi_init_r();
369#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000370 return 0;
371}
372#endif
373
374#ifdef CONFIG_CMD_NAND
375/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200376static int initr_nand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000377{
378 puts("NAND: ");
379 nand_init();
380 return 0;
381}
382#endif
383
384#if defined(CONFIG_CMD_ONENAND)
385/* go init the NAND */
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200386static int initr_onenand(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000387{
388 puts("NAND: ");
389 onenand_init();
390 return 0;
391}
392#endif
393
394#ifdef CONFIG_GENERIC_MMC
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200395static int initr_mmc(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000396{
397 puts("MMC: ");
398 mmc_initialize(gd->bd);
399 return 0;
400}
401#endif
402
403#ifdef CONFIG_HAS_DATAFLASH
Jeroen Hofsteed9e87622014-10-08 22:57:32 +0200404static int initr_dataflash(void)
Simon Glassdb397fa2013-03-11 14:30:37 +0000405{
406 AT91F_DataflashInit();
407 dataflash_print_info();
408 return 0;
409}
410#endif
411
412/*
413 * Tell if it's OK to load the environment early in boot.
414 *
415 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
416 * if this is OK (defaulting to saying it's OK).
417 *
418 * NOTE: Loading the environment early can be a bad idea if security is
419 * important, since no verification is done on the environment.
420 *
421 * @return 0 if environment should not be loaded, !=0 if it is ok to load
422 */
423static int should_load_env(void)
424{
425#ifdef CONFIG_OF_CONTROL
426 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
427#elif defined CONFIG_DELAY_ENVIRONMENT
428 return 0;
429#else
430 return 1;
431#endif
432}
433
434static int initr_env(void)
435{
436 /* initialize environment */
437 if (should_load_env())
438 env_relocate();
439 else
440 set_default_env(NULL);
441
442 /* Initialize from environment */
443 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000444#if defined(CONFIG_SYS_EXTBDINFO)
445#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
446#if defined(CONFIG_I2CFAST)
447 /*
448 * set bi_iic_fast for linux taking environment variable
449 * "i2cfast" into account
450 */
451 {
452 char *s = getenv("i2cfast");
453
454 if (s && ((*s == 'y') || (*s == 'Y'))) {
455 gd->bd->bi_iic_fast[0] = 1;
456 gd->bd->bi_iic_fast[1] = 1;
457 }
458 }
459#endif /* CONFIG_I2CFAST */
460#endif /* CONFIG_405GP, CONFIG_405EP */
461#endif /* CONFIG_SYS_EXTBDINFO */
462 return 0;
463}
464
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100465#ifdef CONFIG_SYS_BOOTPARAMS_LEN
466static int initr_malloc_bootparams(void)
467{
468 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
469 if (!gd->bd->bi_boot_params) {
470 puts("WARNING: Cannot allocate space for boot parameters\n");
471 return -ENOMEM;
472 }
473 return 0;
474}
475#endif
476
Simon Glass5af29bd2013-03-14 07:20:12 +0000477#ifdef CONFIG_SC3
478/* TODO: with new initcalls, move this into the driver */
479extern void sc3_read_eeprom(void);
480
481static int initr_sc3_read_eeprom(void)
482{
483 sc3_read_eeprom();
484 return 0;
485}
486#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000487
488static int initr_jumptable(void)
489{
490 jumptable_init();
491 return 0;
492}
493
494#if defined(CONFIG_API)
495static int initr_api(void)
496{
497 /* Initialize API */
498 api_init();
499 return 0;
500}
501#endif
502
Simon Glassdb397fa2013-03-11 14:30:37 +0000503/* enable exceptions */
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100504#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000505static int initr_enable_interrupts(void)
506{
507 enable_interrupts();
508 return 0;
509}
Simon Glass2e4622d2013-03-11 07:40:13 +0000510#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000511
512#ifdef CONFIG_CMD_NET
513static int initr_ethaddr(void)
514{
Simon Glass5af29bd2013-03-14 07:20:12 +0000515 bd_t *bd = gd->bd;
516
517 /* kept around for legacy kernels only ... ignore the next section */
518 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
519#ifdef CONFIG_HAS_ETH1
520 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
521#endif
522#ifdef CONFIG_HAS_ETH2
523 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
524#endif
525#ifdef CONFIG_HAS_ETH3
526 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
527#endif
528#ifdef CONFIG_HAS_ETH4
529 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
530#endif
531#ifdef CONFIG_HAS_ETH5
532 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
533#endif
534 return 0;
535}
536#endif /* CONFIG_CMD_NET */
537
538#ifdef CONFIG_CMD_KGDB
539static int initr_kgdb(void)
540{
541 puts("KGDB: ");
542 kgdb_init();
543 return 0;
544}
545#endif
546
547#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
548static int initr_status_led(void)
549{
550 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
551
552 return 0;
553}
554#endif
555
556#if defined(CONFIG_CMD_SCSI)
557static int initr_scsi(void)
558{
Simon Glass5af29bd2013-03-14 07:20:12 +0000559 puts("SCSI: ");
560 scsi_init();
Simon Glassdb397fa2013-03-11 14:30:37 +0000561
562 return 0;
563}
Ian Campbell63d424b2014-07-21 19:23:18 +0100564#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000565
Simon Glass5af29bd2013-03-14 07:20:12 +0000566#if defined(CONFIG_CMD_DOC)
567static int initr_doc(void)
568{
569 puts("DOC: ");
570 doc_init();
Ian Campbell1e81e5b2014-07-24 09:29:57 +0100571 return 0;
Simon Glass5af29bd2013-03-14 07:20:12 +0000572}
573#endif
574
Simon Glassdb397fa2013-03-11 14:30:37 +0000575#ifdef CONFIG_BITBANGMII
576static int initr_bbmii(void)
577{
578 bb_miiphy_init();
579 return 0;
580}
581#endif
582
583#ifdef CONFIG_CMD_NET
584static int initr_net(void)
585{
586 puts("Net: ");
587 eth_initialize(gd->bd);
588#if defined(CONFIG_RESET_PHY_R)
589 debug("Reset Ethernet PHY\n");
590 reset_phy();
591#endif
592 return 0;
593}
594#endif
595
596#ifdef CONFIG_POST
597static int initr_post(void)
598{
599 post_run(NULL, POST_RAM | post_bootmode_get(0));
600 return 0;
601}
602#endif
603
Simon Glass5af29bd2013-03-14 07:20:12 +0000604#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
605static int initr_pcmcia(void)
606{
607 puts("PCMCIA:");
608 pcmcia_init();
609 return 0;
610}
611#endif
612
613#if defined(CONFIG_CMD_IDE)
614static int initr_ide(void)
615{
616#ifdef CONFIG_IDE_8xx_PCCARD
617 puts("PCMCIA:");
618#else
619 puts("IDE: ");
620#endif
621#if defined(CONFIG_START_IDE)
622 if (board_start_ide())
623 ide_init();
624#else
625 ide_init();
626#endif
627 return 0;
628}
629#endif
630
Simon Glassdb397fa2013-03-11 14:30:37 +0000631#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
632/*
633 * Export available size of memory for Linux, taking into account the
634 * protected RAM at top of memory
635 */
636int initr_mem(void)
637{
638 ulong pram = 0;
639 char memsz[32];
640
641# ifdef CONFIG_PRAM
642 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
643# endif
644# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
645 /* Also take the logbuffer into account (pram is in kB) */
646 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
647# endif
Valentin Longchampd6b46942014-10-03 11:16:19 +0200648 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
Simon Glassdb397fa2013-03-11 14:30:37 +0000649 setenv("mem", memsz);
Simon Glass5af29bd2013-03-14 07:20:12 +0000650
651 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000652}
653#endif
654
Simon Glass5af29bd2013-03-14 07:20:12 +0000655#ifdef CONFIG_CMD_BEDBUG
656static int initr_bedbug(void)
657{
658 bedbug_init();
659
660 return 0;
661}
662#endif
663
664#ifdef CONFIG_PS2KBD
665static int initr_kbd(void)
666{
667 puts("PS/2: ");
668 kbd_init();
669 return 0;
670}
671#endif
672
Simon Glassdb397fa2013-03-11 14:30:37 +0000673static int run_main_loop(void)
674{
Simon Glass62cf9122013-04-26 02:53:43 +0000675#ifdef CONFIG_SANDBOX
676 sandbox_main_loop_init();
677#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000678 /* main_loop() can return to retry autoboot, if so just run it again */
679 for (;;)
680 main_loop();
681 return 0;
682}
683
684/*
685 * Over time we hope to remove these functions with code fragments and
686 * stub funtcions, and instead call the relevant function directly.
687 *
688 * We also hope to remove most of the driver-related init and do it if/when
689 * the driver is later used.
Simon Glass5af29bd2013-03-14 07:20:12 +0000690 *
691 * TODO: perhaps reset the watchdog in the initcall function after each call?
Simon Glassdb397fa2013-03-11 14:30:37 +0000692 */
693init_fnc_t init_sequence_r[] = {
Simon Glass209a1a62013-06-11 11:14:42 -0700694 initr_trace,
Simon Glassdb397fa2013-03-11 14:30:37 +0000695 initr_reloc,
Simon Glass5af29bd2013-03-14 07:20:12 +0000696 /* TODO: could x86/PPC have this also perhaps? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000697#ifdef CONFIG_ARM
698 initr_caches,
Simon Glass712da5e2014-09-03 17:37:01 -0600699#endif
700 initr_reloc_global_data,
York Sun6e78b3b2014-10-02 15:20:10 -0700701#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
702 initr_unlock_ram_in_cache,
703#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600704 initr_barrier,
705 initr_malloc,
Thierry Redingc97d9742014-12-09 22:25:22 -0700706#ifdef CONFIG_SYS_NONCACHED_MEMORY
707 initr_noncached,
708#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600709 bootstage_relocate,
710#ifdef CONFIG_DM
711 initr_dm,
712#endif
713#ifdef CONFIG_ARM
Simon Glassdb397fa2013-03-11 14:30:37 +0000714 board_init, /* Setup chipselects */
715#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000716 /*
717 * TODO: printing of the clock inforamtion of the board is now
718 * implemented as part of bdinfo command. Currently only support for
719 * davinci SOC's is added. Remove this check once all the board
720 * implement this.
721 */
722#ifdef CONFIG_CLOCKS
723 set_cpu_clk_info, /* Setup clock information */
724#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600725 stdio_init_tables,
Simon Glassdb397fa2013-03-11 14:30:37 +0000726 initr_serial,
727 initr_announce,
Simon Glass5af29bd2013-03-14 07:20:12 +0000728 INIT_FUNC_WATCHDOG_RESET
Andreas Bießmann9e4f3962015-01-20 00:29:05 +0100729#ifdef CONFIG_NEEDS_MANUAL_RELOC
730 initr_manual_reloc_cmdtable,
731#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000732#ifdef CONFIG_PPC
733 initr_trap,
734#endif
735#ifdef CONFIG_ADDR_MAP
736 initr_addr_map,
737#endif
738#if defined(CONFIG_BOARD_EARLY_INIT_R)
739 board_early_init_r,
740#endif
741 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000742#ifdef CONFIG_LOGBUFFER
743 initr_logbuffer,
744#endif
745#ifdef CONFIG_POST
746 initr_post_backlog,
747#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000748 INIT_FUNC_WATCHDOG_RESET
749#ifdef CONFIG_SYS_DELAYED_ICACHE
750 initr_icache_enable,
751#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000752#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
753 /*
754 * Do early PCI configuration _before_ the flash gets initialised,
755 * because PCU ressources are crucial for flash access on some boards.
756 */
757 initr_pci,
758#endif
759#ifdef CONFIG_WINBOND_83C553
760 initr_w83c553f,
761#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000762#ifdef CONFIG_ARCH_EARLY_INIT_R
763 arch_early_init_r,
764#endif
765 power_init_board,
766#ifndef CONFIG_SYS_NO_FLASH
767 initr_flash,
768#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000769 INIT_FUNC_WATCHDOG_RESET
Bin Meng57a6cd82014-11-20 16:11:00 +0800770#if defined(CONFIG_PPC)
Simon Glass5af29bd2013-03-14 07:20:12 +0000771 /* initialize higher level parts of CPU like time base and timers */
772 cpu_init_r,
Simon Glass6f5567d2013-03-05 14:39:53 +0000773#endif
774#ifdef CONFIG_PPC
Simon Glass5af29bd2013-03-14 07:20:12 +0000775 initr_spi,
776#endif
Simon Glass6f5567d2013-03-05 14:39:53 +0000777#if defined(CONFIG_X86) && defined(CONFIG_SPI)
778 init_func_spi,
779#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000780#ifdef CONFIG_CMD_NAND
781 initr_nand,
782#endif
783#ifdef CONFIG_CMD_ONENAND
784 initr_onenand,
785#endif
786#ifdef CONFIG_GENERIC_MMC
787 initr_mmc,
788#endif
789#ifdef CONFIG_HAS_DATAFLASH
790 initr_dataflash,
791#endif
792 initr_env,
Andreas Bießmann111bbf52015-02-06 23:06:47 +0100793#ifdef CONFIG_SYS_BOOTPARAMS_LEN
794 initr_malloc_bootparams,
795#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000796 INIT_FUNC_WATCHDOG_RESET
797 initr_secondary_cpu,
798#ifdef CONFIG_SC3
799 initr_sc3_read_eeprom,
800#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000801#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
802 mac_read_from_eeprom,
803#endif
804 INIT_FUNC_WATCHDOG_RESET
805#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
806 /*
807 * Do pci configuration
808 */
809 initr_pci,
810#endif
Simon Glass712da5e2014-09-03 17:37:01 -0600811 stdio_add_devices,
Simon Glassdb397fa2013-03-11 14:30:37 +0000812 initr_jumptable,
813#ifdef CONFIG_API
814 initr_api,
815#endif
816 console_init_r, /* fully init console as a device */
817#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
Masahiro Yamada9607f7a2015-01-14 17:07:05 +0900818 show_board_info,
Simon Glassdb397fa2013-03-11 14:30:37 +0000819#endif
820#ifdef CONFIG_ARCH_MISC_INIT
821 arch_misc_init, /* miscellaneous arch-dependent init */
822#endif
823#ifdef CONFIG_MISC_INIT_R
824 misc_init_r, /* miscellaneous platform-dependent init */
825#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000826 INIT_FUNC_WATCHDOG_RESET
827#ifdef CONFIG_CMD_KGDB
828 initr_kgdb,
829#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000830 interrupt_init,
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100831#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
Simon Glassdb397fa2013-03-11 14:30:37 +0000832 initr_enable_interrupts,
Simon Glass5af29bd2013-03-14 07:20:12 +0000833#endif
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100834#if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
Simon Glass6f5567d2013-03-05 14:39:53 +0000835 timer_init, /* initialize timer */
836#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000837#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
838 initr_status_led,
839#endif
840 /* PPC has a udelay(20) here dating from 2002. Why? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000841#ifdef CONFIG_CMD_NET
842 initr_ethaddr,
843#endif
844#ifdef CONFIG_BOARD_LATE_INIT
845 board_late_init,
846#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000847#ifdef CONFIG_CMD_SCSI
848 INIT_FUNC_WATCHDOG_RESET
849 initr_scsi,
850#endif
851#ifdef CONFIG_CMD_DOC
852 INIT_FUNC_WATCHDOG_RESET
853 initr_doc,
854#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000855#ifdef CONFIG_BITBANGMII
856 initr_bbmii,
857#endif
858#ifdef CONFIG_CMD_NET
Simon Glass5af29bd2013-03-14 07:20:12 +0000859 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000860 initr_net,
861#endif
862#ifdef CONFIG_POST
863 initr_post,
864#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000865#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
866 initr_pcmcia,
867#endif
868#if defined(CONFIG_CMD_IDE)
869 initr_ide,
870#endif
871#ifdef CONFIG_LAST_STAGE_INIT
872 INIT_FUNC_WATCHDOG_RESET
873 /*
874 * Some parts can be only initialized if all others (like
875 * Interrupts) are up and running (i.e. the PC-style ISA
876 * keyboard).
877 */
878 last_stage_init,
879#endif
880#ifdef CONFIG_CMD_BEDBUG
881 INIT_FUNC_WATCHDOG_RESET
882 initr_bedbug,
883#endif
884#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
885 initr_mem,
886#endif
887#ifdef CONFIG_PS2KBD
888 initr_kbd,
889#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000890 run_main_loop,
891};
892
893void board_init_r(gd_t *new_gd, ulong dest_addr)
894{
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400895#ifdef CONFIG_NEEDS_MANUAL_RELOC
896 int i;
897#endif
898
Andreas Bießmannc1d09172015-02-06 23:06:48 +0100899#ifdef CONFIG_AVR32
900 mmu_init_r(dest_addr);
901#endif
902
Jeroen Hofstee498f97f2014-07-30 21:54:49 +0200903#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
Simon Glassdb397fa2013-03-11 14:30:37 +0000904 gd = new_gd;
Simon Glass6f5567d2013-03-05 14:39:53 +0000905#endif
Alexey Brodkin3f0516f2014-01-20 14:30:39 +0400906
907#ifdef CONFIG_NEEDS_MANUAL_RELOC
908 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
909 init_sequence_r[i] += gd->reloc_off;
910#endif
911
Simon Glassdb397fa2013-03-11 14:30:37 +0000912 if (initcall_run_list(init_sequence_r))
913 hang();
914
915 /* NOTREACHED - run_main_loop() does not return */
916 hang();
917}