blob: f7a036e32f42e0adcbda61cebb566ee695dd2340 [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 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29#include <common.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000030/* TODO: can we just include all these headers whether needed or not? */
31#if defined(CONFIG_CMD_BEDBUG)
32#include <bedbug/type.h>
33#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000034#ifdef CONFIG_HAS_DATAFLASH
35#include <dataflash.h>
36#endif
37#include <environment.h>
38#include <fdtdec.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000039#if defined(CONFIG_CMD_IDE)
40#include <ide.h>
41#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000042#include <initcall.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000043#ifdef CONFIG_PS2KBD
44#include <keyboard.h>
45#endif
46#if defined(CONFIG_CMD_KGDB)
47#include <kgdb.h>
48#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000049#include <logbuff.h>
50#include <malloc.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000051#ifdef CONFIG_BITBANGMII
52#include <miiphy.h>
53#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000054#include <mmc.h>
55#include <nand.h>
56#include <onenand_uboot.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000057#include <scsi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000058#include <serial.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000059#include <spi.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000060#include <stdio_dev.h>
Simon Glass209a1a62013-06-11 11:14:42 -070061#include <trace.h>
Simon Glass5af29bd2013-03-14 07:20:12 +000062#include <watchdog.h>
63#ifdef CONFIG_ADDR_MAP
64#include <asm/mmu.h>
65#endif
Simon Glassdb397fa2013-03-11 14:30:37 +000066#include <asm/sections.h>
Simon Glass6f5567d2013-03-05 14:39:53 +000067#ifdef CONFIG_X86
68#include <asm/init_helpers.h>
69#endif
Simon Glass5af29bd2013-03-14 07:20:12 +000070#include <linux/compiler.h>
Simon Glassdb397fa2013-03-11 14:30:37 +000071
72DECLARE_GLOBAL_DATA_PTR;
73
74ulong monitor_flash_len;
75
Simon Glass5af29bd2013-03-14 07:20:12 +000076int __board_flash_wp_on(void)
77{
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
86int board_flash_wp_on(void)
87 __attribute__ ((weak, alias("__board_flash_wp_on")));
88
89void __cpu_secondary_init_r(void)
90{
91}
92
93void cpu_secondary_init_r(void)
94 __attribute__ ((weak, alias("__cpu_secondary_init_r")));
95
96static int initr_secondary_cpu(void)
97{
98 /*
99 * after non-volatile devices & environment is setup and cpu code have
100 * another round to deal with any initialization that might require
101 * full access to the environment or loading of some image (firmware)
102 * from a non-volatile device
103 */
104 /* TODO: maybe define this for all archs? */
105 cpu_secondary_init_r();
106
107 return 0;
108}
Simon Glassdb397fa2013-03-11 14:30:37 +0000109
Simon Glass209a1a62013-06-11 11:14:42 -0700110static int initr_trace(void)
111{
112#ifdef CONFIG_TRACE
113 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
114#endif
115
116 return 0;
117}
118
Simon Glassdb397fa2013-03-11 14:30:37 +0000119static int initr_reloc(void)
120{
121 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
122 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
123
124 return 0;
125}
126
127#ifdef CONFIG_ARM
128/*
129 * Some of these functions are needed purely because the functions they
130 * call return void. If we change them to return 0, these stubs can go away.
131 */
132static int initr_caches(void)
133{
134 /* Enable caches */
135 enable_caches();
136 return 0;
137}
138#endif
139
Simon Glass5af29bd2013-03-14 07:20:12 +0000140__weak int fixup_cpu(void)
141{
142 return 0;
143}
144
Simon Glassdb397fa2013-03-11 14:30:37 +0000145static int initr_reloc_global_data(void)
146{
147#ifdef CONFIG_SYS_SYM_OFFSETS
148 monitor_flash_len = _end_ofs;
Simon Glass62cf9122013-04-26 02:53:43 +0000149#elif !defined(CONFIG_SANDBOX)
Masahiro Yamadad1589242013-05-27 00:37:30 +0000150 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
Simon Glassdb397fa2013-03-11 14:30:37 +0000151#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000152#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
153 /*
154 * The gd->cpu pointer is set to an address in flash before relocation.
155 * We need to update it to point to the same CPU entry in RAM.
156 * TODO: why not just add gd->reloc_ofs?
157 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000158 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000159
160 /*
161 * If we didn't know the cpu mask & # cores, we can save them of
162 * now rather than 'computing' them constantly
163 */
164 fixup_cpu();
165#endif
166#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
167 /*
168 * Some systems need to relocate the env_addr pointer early because the
169 * location it points to will get invalidated before env_relocate is
170 * called. One example is on systems that might use a L2 or L3 cache
171 * in SRAM mode and initialize that cache from SRAM mode back to being
172 * a cache in cpu_init_r.
173 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000174 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Simon Glass5af29bd2013-03-14 07:20:12 +0000175#endif
176 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000177}
178
179static int initr_serial(void)
180{
181 serial_initialize();
182 return 0;
183}
184
Simon Glass5af29bd2013-03-14 07:20:12 +0000185#ifdef CONFIG_PPC
186static int initr_trap(void)
187{
188 /*
189 * Setup trap handlers
190 */
Masahiro Yamadad1589242013-05-27 00:37:30 +0000191 trap_init(gd->relocaddr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000192
193 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#ifdef CONFIG_SYS_DELAYED_ICACHE
228static int initr_icache_enable(void)
229{
230 return 0;
231}
232#endif
233
234#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
235static int initr_unlock_ram_in_cache(void)
236{
237 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
238 return 0;
239}
240#endif
241
242#ifdef CONFIG_PCI
243static int initr_pci(void)
244{
245 pci_init();
246
247 return 0;
248}
249#endif
250
251#ifdef CONFIG_WINBOND_83C553
252static int initr_w83c553f(void)
253{
254 /*
255 * Initialise the ISA bridge
256 */
257 initialise_w83c553f();
258 return 0;
259}
260#endif
261
262static int initr_barrier(void)
263{
264#ifdef CONFIG_PPC
265 /* TODO: Can we not use dmb() macros for this? */
266 asm("sync ; isync");
267#endif
268 return 0;
269}
270
Simon Glassdb397fa2013-03-11 14:30:37 +0000271static int initr_malloc(void)
272{
273 ulong malloc_start;
274
275 /* 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}
281
282__weak int power_init_board(void)
283{
284 return 0;
285}
286
287static int initr_announce(void)
288{
Masahiro Yamadad1589242013-05-27 00:37:30 +0000289 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
Simon Glassdb397fa2013-03-11 14:30:37 +0000290 return 0;
291}
292
293#if !defined(CONFIG_SYS_NO_FLASH)
294static int initr_flash(void)
295{
Simon Glass5af29bd2013-03-14 07:20:12 +0000296 ulong flash_size = 0;
297 bd_t *bd = gd->bd;
298 int ok;
Simon Glassdb397fa2013-03-11 14:30:37 +0000299
300 puts("Flash: ");
301
Simon Glass5af29bd2013-03-14 07:20:12 +0000302 if (board_flash_wp_on()) {
303 printf("Uninitialized - Write Protect On\n");
304 /* Since WP is on, we can't find real size. Set to 0 */
305 ok = 1;
306 } else {
307 flash_size = flash_init();
308 ok = flash_size > 0;
309 }
310 if (!ok) {
Simon Glassdb397fa2013-03-11 14:30:37 +0000311 puts("*** failed ***\n");
Simon Glass5af29bd2013-03-14 07:20:12 +0000312#ifdef CONFIG_PPC
313 /* Why does PPC do this? */
314 hang();
315#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000316 return -1;
317 }
318 print_size(flash_size, "");
319#ifdef CONFIG_SYS_FLASH_CHECKSUM
320 /*
321 * Compute and print flash CRC if flashchecksum is set to 'y'
322 *
323 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
324 */
325 if (getenv_yesno("flashchecksum") == 1) {
326 printf(" CRC: %08X", crc32(0,
327 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
328 flash_size));
329 }
330#endif /* CONFIG_SYS_FLASH_CHECKSUM */
331 putc('\n');
332
Simon Glass5af29bd2013-03-14 07:20:12 +0000333 /* update start of FLASH memory */
334#ifdef CONFIG_SYS_FLASH_BASE
335 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
336#endif
337 /* size of FLASH memory (final value) */
338 bd->bi_flashsize = flash_size;
339
340#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
341 /* Make a update of the Memctrl. */
342 update_flash_size(flash_size);
343#endif
344
345
346#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
347 /* flash mapped at end of memory map */
348 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
349#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
350 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
351#endif
352 return 0;
353}
354#endif
355
356#ifdef CONFIG_PPC
357static int initr_spi(void)
358{
359 /* PPC does this here */
360#ifdef CONFIG_SPI
361#if !defined(CONFIG_ENV_IS_IN_EEPROM)
362 spi_init_f();
363#endif
364 spi_init_r();
365#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000366 return 0;
367}
368#endif
369
370#ifdef CONFIG_CMD_NAND
371/* go init the NAND */
372int initr_nand(void)
373{
374 puts("NAND: ");
375 nand_init();
376 return 0;
377}
378#endif
379
380#if defined(CONFIG_CMD_ONENAND)
381/* go init the NAND */
382int initr_onenand(void)
383{
384 puts("NAND: ");
385 onenand_init();
386 return 0;
387}
388#endif
389
390#ifdef CONFIG_GENERIC_MMC
391int initr_mmc(void)
392{
393 puts("MMC: ");
394 mmc_initialize(gd->bd);
395 return 0;
396}
397#endif
398
399#ifdef CONFIG_HAS_DATAFLASH
400int initr_dataflash(void)
401{
402 AT91F_DataflashInit();
403 dataflash_print_info();
404 return 0;
405}
406#endif
407
408/*
409 * Tell if it's OK to load the environment early in boot.
410 *
411 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
412 * if this is OK (defaulting to saying it's OK).
413 *
414 * NOTE: Loading the environment early can be a bad idea if security is
415 * important, since no verification is done on the environment.
416 *
417 * @return 0 if environment should not be loaded, !=0 if it is ok to load
418 */
419static int should_load_env(void)
420{
421#ifdef CONFIG_OF_CONTROL
422 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
423#elif defined CONFIG_DELAY_ENVIRONMENT
424 return 0;
425#else
426 return 1;
427#endif
428}
429
430static int initr_env(void)
431{
432 /* initialize environment */
433 if (should_load_env())
434 env_relocate();
435 else
436 set_default_env(NULL);
437
438 /* Initialize from environment */
439 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Simon Glass5af29bd2013-03-14 07:20:12 +0000440#if defined(CONFIG_SYS_EXTBDINFO)
441#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
442#if defined(CONFIG_I2CFAST)
443 /*
444 * set bi_iic_fast for linux taking environment variable
445 * "i2cfast" into account
446 */
447 {
448 char *s = getenv("i2cfast");
449
450 if (s && ((*s == 'y') || (*s == 'Y'))) {
451 gd->bd->bi_iic_fast[0] = 1;
452 gd->bd->bi_iic_fast[1] = 1;
453 }
454 }
455#endif /* CONFIG_I2CFAST */
456#endif /* CONFIG_405GP, CONFIG_405EP */
457#endif /* CONFIG_SYS_EXTBDINFO */
458 return 0;
459}
460
461#ifdef CONFIG_HERMES
462static int initr_hermes(void)
463{
464 if ((gd->board_type >> 16) == 2)
465 gd->bd->bi_ethspeed = gd->board_type & 0xFFFF;
466 else
467 gd->bd->bi_ethspeed = 0xFFFF;
468 return 0;
469}
470
471static int initr_hermes_start(void)
472{
473 if (gd->bd->bi_ethspeed != 0xFFFF)
474 hermes_start_lxt980((int) gd->bd->bi_ethspeed);
Simon Glassdb397fa2013-03-11 14:30:37 +0000475 return 0;
476}
Simon Glass5af29bd2013-03-14 07:20:12 +0000477#endif
478
479#ifdef CONFIG_SC3
480/* TODO: with new initcalls, move this into the driver */
481extern void sc3_read_eeprom(void);
482
483static int initr_sc3_read_eeprom(void)
484{
485 sc3_read_eeprom();
486 return 0;
487}
488#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000489
490static int initr_jumptable(void)
491{
492 jumptable_init();
493 return 0;
494}
495
496#if defined(CONFIG_API)
497static int initr_api(void)
498{
499 /* Initialize API */
500 api_init();
501 return 0;
502}
503#endif
504
505#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
506static int show_model_r(void)
507{
508 /* Put this here so it appears on the LCD, now it is ready */
509# ifdef CONFIG_OF_CONTROL
510 const char *model;
511
512 model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL);
513 printf("Model: %s\n", model ? model : "<unknown>");
514# else
515 checkboard();
516# endif
517}
518#endif
519
520/* enable exceptions */
Simon Glass2e4622d2013-03-11 07:40:13 +0000521#ifdef CONFIG_ARM
Simon Glassdb397fa2013-03-11 14:30:37 +0000522static int initr_enable_interrupts(void)
523{
524 enable_interrupts();
525 return 0;
526}
Simon Glass2e4622d2013-03-11 07:40:13 +0000527#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000528
529#ifdef CONFIG_CMD_NET
530static int initr_ethaddr(void)
531{
Simon Glass5af29bd2013-03-14 07:20:12 +0000532 bd_t *bd = gd->bd;
533
534 /* kept around for legacy kernels only ... ignore the next section */
535 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
536#ifdef CONFIG_HAS_ETH1
537 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
538#endif
539#ifdef CONFIG_HAS_ETH2
540 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
541#endif
542#ifdef CONFIG_HAS_ETH3
543 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
544#endif
545#ifdef CONFIG_HAS_ETH4
546 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
547#endif
548#ifdef CONFIG_HAS_ETH5
549 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
550#endif
551 return 0;
552}
553#endif /* CONFIG_CMD_NET */
554
555#ifdef CONFIG_CMD_KGDB
556static int initr_kgdb(void)
557{
558 puts("KGDB: ");
559 kgdb_init();
560 return 0;
561}
562#endif
563
564#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
565static int initr_status_led(void)
566{
567 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
568
569 return 0;
570}
571#endif
572
573#if defined(CONFIG_CMD_SCSI)
574static int initr_scsi(void)
575{
576 /* Not supported properly on ARM yet */
577#ifndef CONFIG_ARM
578 puts("SCSI: ");
579 scsi_init();
580#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000581
582 return 0;
583}
584#endif /* CONFIG_CMD_NET */
585
Simon Glass5af29bd2013-03-14 07:20:12 +0000586#if defined(CONFIG_CMD_DOC)
587static int initr_doc(void)
588{
589 puts("DOC: ");
590 doc_init();
591}
592#endif
593
Simon Glassdb397fa2013-03-11 14:30:37 +0000594#ifdef CONFIG_BITBANGMII
595static int initr_bbmii(void)
596{
597 bb_miiphy_init();
598 return 0;
599}
600#endif
601
602#ifdef CONFIG_CMD_NET
603static int initr_net(void)
604{
605 puts("Net: ");
606 eth_initialize(gd->bd);
607#if defined(CONFIG_RESET_PHY_R)
608 debug("Reset Ethernet PHY\n");
609 reset_phy();
610#endif
611 return 0;
612}
613#endif
614
615#ifdef CONFIG_POST
616static int initr_post(void)
617{
618 post_run(NULL, POST_RAM | post_bootmode_get(0));
619 return 0;
620}
621#endif
622
Simon Glass5af29bd2013-03-14 07:20:12 +0000623#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
624static int initr_pcmcia(void)
625{
626 puts("PCMCIA:");
627 pcmcia_init();
628 return 0;
629}
630#endif
631
632#if defined(CONFIG_CMD_IDE)
633static int initr_ide(void)
634{
635#ifdef CONFIG_IDE_8xx_PCCARD
636 puts("PCMCIA:");
637#else
638 puts("IDE: ");
639#endif
640#if defined(CONFIG_START_IDE)
641 if (board_start_ide())
642 ide_init();
643#else
644 ide_init();
645#endif
646 return 0;
647}
648#endif
649
Simon Glassdb397fa2013-03-11 14:30:37 +0000650#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
651/*
652 * Export available size of memory for Linux, taking into account the
653 * protected RAM at top of memory
654 */
655int initr_mem(void)
656{
657 ulong pram = 0;
658 char memsz[32];
659
660# ifdef CONFIG_PRAM
661 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
662# endif
663# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
664 /* Also take the logbuffer into account (pram is in kB) */
665 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
666# endif
667 sprintf(memsz, "%ldk", (gd->ram_size / 1024) - pram);
668 setenv("mem", memsz);
Simon Glass5af29bd2013-03-14 07:20:12 +0000669
670 return 0;
Simon Glassdb397fa2013-03-11 14:30:37 +0000671}
672#endif
673
Simon Glass5af29bd2013-03-14 07:20:12 +0000674#ifdef CONFIG_CMD_BEDBUG
675static int initr_bedbug(void)
676{
677 bedbug_init();
678
679 return 0;
680}
681#endif
682
683#ifdef CONFIG_PS2KBD
684static int initr_kbd(void)
685{
686 puts("PS/2: ");
687 kbd_init();
688 return 0;
689}
690#endif
691
692#ifdef CONFIG_MODEM_SUPPORT
693static int initr_modem(void)
694{
695 /* TODO: with new initcalls, move this into the driver */
696 extern int do_mdm_init;
697
698 do_mdm_init = gd->do_mdm_init;
699 return 0;
700}
701#endif
702
Simon Glassdb397fa2013-03-11 14:30:37 +0000703static int run_main_loop(void)
704{
Simon Glass62cf9122013-04-26 02:53:43 +0000705#ifdef CONFIG_SANDBOX
706 sandbox_main_loop_init();
707#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000708 /* main_loop() can return to retry autoboot, if so just run it again */
709 for (;;)
710 main_loop();
711 return 0;
712}
713
714/*
715 * Over time we hope to remove these functions with code fragments and
716 * stub funtcions, and instead call the relevant function directly.
717 *
718 * We also hope to remove most of the driver-related init and do it if/when
719 * the driver is later used.
Simon Glass5af29bd2013-03-14 07:20:12 +0000720 *
721 * TODO: perhaps reset the watchdog in the initcall function after each call?
Simon Glassdb397fa2013-03-11 14:30:37 +0000722 */
723init_fnc_t init_sequence_r[] = {
Simon Glass209a1a62013-06-11 11:14:42 -0700724 initr_trace,
Simon Glassdb397fa2013-03-11 14:30:37 +0000725 initr_reloc,
Simon Glass5af29bd2013-03-14 07:20:12 +0000726 /* TODO: could x86/PPC have this also perhaps? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000727#ifdef CONFIG_ARM
728 initr_caches,
729 board_init, /* Setup chipselects */
730#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000731 /*
732 * TODO: printing of the clock inforamtion of the board is now
733 * implemented as part of bdinfo command. Currently only support for
734 * davinci SOC's is added. Remove this check once all the board
735 * implement this.
736 */
737#ifdef CONFIG_CLOCKS
738 set_cpu_clk_info, /* Setup clock information */
739#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000740 initr_reloc_global_data,
741 initr_serial,
742 initr_announce,
Simon Glass5af29bd2013-03-14 07:20:12 +0000743 INIT_FUNC_WATCHDOG_RESET
744#ifdef CONFIG_PPC
745 initr_trap,
746#endif
747#ifdef CONFIG_ADDR_MAP
748 initr_addr_map,
749#endif
750#if defined(CONFIG_BOARD_EARLY_INIT_R)
751 board_early_init_r,
752#endif
753 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000754#ifdef CONFIG_LOGBUFFER
755 initr_logbuffer,
756#endif
757#ifdef CONFIG_POST
758 initr_post_backlog,
759#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000760 INIT_FUNC_WATCHDOG_RESET
761#ifdef CONFIG_SYS_DELAYED_ICACHE
762 initr_icache_enable,
763#endif
764#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
765 initr_unlock_ram_in_cache,
766#endif
767#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
768 /*
769 * Do early PCI configuration _before_ the flash gets initialised,
770 * because PCU ressources are crucial for flash access on some boards.
771 */
772 initr_pci,
773#endif
774#ifdef CONFIG_WINBOND_83C553
775 initr_w83c553f,
776#endif
777 initr_barrier,
Simon Glassdb397fa2013-03-11 14:30:37 +0000778 initr_malloc,
Doug Anderson844199d2013-04-17 16:13:42 +0000779 bootstage_relocate,
Simon Glassdb397fa2013-03-11 14:30:37 +0000780#ifdef CONFIG_ARCH_EARLY_INIT_R
781 arch_early_init_r,
782#endif
783 power_init_board,
784#ifndef CONFIG_SYS_NO_FLASH
785 initr_flash,
786#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000787 INIT_FUNC_WATCHDOG_RESET
Simon Glass6f5567d2013-03-05 14:39:53 +0000788#if defined(CONFIG_PPC) || defined(CONFIG_X86)
Simon Glass5af29bd2013-03-14 07:20:12 +0000789 /* initialize higher level parts of CPU like time base and timers */
790 cpu_init_r,
Simon Glass6f5567d2013-03-05 14:39:53 +0000791#endif
792#ifdef CONFIG_PPC
Simon Glass5af29bd2013-03-14 07:20:12 +0000793 initr_spi,
794#endif
Simon Glass6f5567d2013-03-05 14:39:53 +0000795#if defined(CONFIG_X86) && defined(CONFIG_SPI)
796 init_func_spi,
797#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000798#ifdef CONFIG_CMD_NAND
799 initr_nand,
800#endif
801#ifdef CONFIG_CMD_ONENAND
802 initr_onenand,
803#endif
804#ifdef CONFIG_GENERIC_MMC
805 initr_mmc,
806#endif
807#ifdef CONFIG_HAS_DATAFLASH
808 initr_dataflash,
809#endif
810 initr_env,
Simon Glass5af29bd2013-03-14 07:20:12 +0000811 INIT_FUNC_WATCHDOG_RESET
812 initr_secondary_cpu,
813#ifdef CONFIG_SC3
814 initr_sc3_read_eeprom,
815#endif
816#ifdef CONFIG_HERMES
817 initr_hermes,
818#endif
819#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
820 mac_read_from_eeprom,
821#endif
822 INIT_FUNC_WATCHDOG_RESET
823#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
824 /*
825 * Do pci configuration
826 */
827 initr_pci,
828#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000829 stdio_init,
830 initr_jumptable,
831#ifdef CONFIG_API
832 initr_api,
833#endif
834 console_init_r, /* fully init console as a device */
835#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
836 show_model_r,
837#endif
838#ifdef CONFIG_ARCH_MISC_INIT
839 arch_misc_init, /* miscellaneous arch-dependent init */
840#endif
841#ifdef CONFIG_MISC_INIT_R
842 misc_init_r, /* miscellaneous platform-dependent init */
843#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000844#ifdef CONFIG_HERMES
845 initr_hermes_start,
846#endif
847 INIT_FUNC_WATCHDOG_RESET
848#ifdef CONFIG_CMD_KGDB
849 initr_kgdb,
850#endif
Simon Glass6f5567d2013-03-05 14:39:53 +0000851#ifdef CONFIG_X86
852 board_early_init_r,
853#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000854 interrupt_init,
Simon Glass6f5567d2013-03-05 14:39:53 +0000855#if defined(CONFIG_ARM) || defined(CONFIG_x86)
Simon Glassdb397fa2013-03-11 14:30:37 +0000856 initr_enable_interrupts,
Simon Glass5af29bd2013-03-14 07:20:12 +0000857#endif
Simon Glass6f5567d2013-03-05 14:39:53 +0000858#ifdef CONFIG_X86
859 timer_init, /* initialize timer */
860#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000861#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
862 initr_status_led,
863#endif
864 /* PPC has a udelay(20) here dating from 2002. Why? */
Simon Glassdb397fa2013-03-11 14:30:37 +0000865#ifdef CONFIG_CMD_NET
866 initr_ethaddr,
867#endif
868#ifdef CONFIG_BOARD_LATE_INIT
869 board_late_init,
870#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000871#ifdef CONFIG_CMD_SCSI
872 INIT_FUNC_WATCHDOG_RESET
873 initr_scsi,
874#endif
875#ifdef CONFIG_CMD_DOC
876 INIT_FUNC_WATCHDOG_RESET
877 initr_doc,
878#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000879#ifdef CONFIG_BITBANGMII
880 initr_bbmii,
881#endif
882#ifdef CONFIG_CMD_NET
Simon Glass5af29bd2013-03-14 07:20:12 +0000883 INIT_FUNC_WATCHDOG_RESET
Simon Glassdb397fa2013-03-11 14:30:37 +0000884 initr_net,
885#endif
886#ifdef CONFIG_POST
887 initr_post,
888#endif
Simon Glass5af29bd2013-03-14 07:20:12 +0000889#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
890 initr_pcmcia,
891#endif
892#if defined(CONFIG_CMD_IDE)
893 initr_ide,
894#endif
895#ifdef CONFIG_LAST_STAGE_INIT
896 INIT_FUNC_WATCHDOG_RESET
897 /*
898 * Some parts can be only initialized if all others (like
899 * Interrupts) are up and running (i.e. the PC-style ISA
900 * keyboard).
901 */
902 last_stage_init,
903#endif
904#ifdef CONFIG_CMD_BEDBUG
905 INIT_FUNC_WATCHDOG_RESET
906 initr_bedbug,
907#endif
908#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
909 initr_mem,
910#endif
911#ifdef CONFIG_PS2KBD
912 initr_kbd,
913#endif
914#ifdef CONFIG_MODEM_SUPPORT
915 initr_modem,
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{
Simon Glass6f5567d2013-03-05 14:39:53 +0000922#ifndef CONFIG_X86
Simon Glassdb397fa2013-03-11 14:30:37 +0000923 gd = new_gd;
Simon Glass6f5567d2013-03-05 14:39:53 +0000924#endif
Simon Glassdb397fa2013-03-11 14:30:37 +0000925 if (initcall_run_list(init_sequence_r))
926 hang();
927
928 /* NOTREACHED - run_main_loop() does not return */
929 hang();
930}