blob: 9db1827635c2b1041c02367285b8a4982ee7902f [file] [log] [blame]
Googlere00b8eb2019-07-08 16:37:07 -07001/*
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>
Googler40bc9d02023-12-15 16:42:49 +08009 *
10 * SPDX-License-Identifier: GPL-2.0+
Googlere00b8eb2019-07-08 16:37:07 -070011 */
12
13#include <common.h>
Googlere00b8eb2019-07-08 16:37:07 -070014/* 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
Googler40bc9d02023-12-15 16:42:49 +080018#ifdef CONFIG_HAS_DATAFLASH
19#include <dataflash.h>
20#endif
Googlere00b8eb2019-07-08 16:37:07 -070021#include <dm.h>
22#include <environment.h>
23#include <fdtdec.h>
Googler40bc9d02023-12-15 16:42:49 +080024#if defined(CONFIG_CMD_IDE)
Googlere00b8eb2019-07-08 16:37:07 -070025#include <ide.h>
Googler40bc9d02023-12-15 16:42:49 +080026#endif
Googlere00b8eb2019-07-08 16:37:07 -070027#include <initcall.h>
Googler40bc9d02023-12-15 16:42:49 +080028#ifdef CONFIG_PS2KBD
29#include <keyboard.h>
30#endif
Googlere00b8eb2019-07-08 16:37:07 -070031#if defined(CONFIG_CMD_KGDB)
32#include <kgdb.h>
33#endif
Googler40bc9d02023-12-15 16:42:49 +080034#include <logbuff.h>
Googlere00b8eb2019-07-08 16:37:07 -070035#include <malloc.h>
Googlere00b8eb2019-07-08 16:37:07 -070036#ifdef CONFIG_BITBANGMII
37#include <miiphy.h>
38#endif
39#include <mmc.h>
40#include <nand.h>
Googlere00b8eb2019-07-08 16:37:07 -070041#include <onenand_uboot.h>
42#include <scsi.h>
43#include <serial.h>
Googler40bc9d02023-12-15 16:42:49 +080044#include <spi.h>
Googlere00b8eb2019-07-08 16:37:07 -070045#include <stdio_dev.h>
Googlere00b8eb2019-07-08 16:37:07 -070046#include <trace.h>
47#include <watchdog.h>
48#ifdef CONFIG_ADDR_MAP
49#include <asm/mmu.h>
50#endif
51#include <asm/sections.h>
Googler40bc9d02023-12-15 16:42:49 +080052#ifdef CONFIG_X86
53#include <asm/init_helpers.h>
54#endif
Googlere00b8eb2019-07-08 16:37:07 -070055#include <dm/root.h>
56#include <linux/compiler.h>
57#include <linux/err.h>
Googler40bc9d02023-12-15 16:42:49 +080058#include <asm/arch/timer.h>
Googlere00b8eb2019-07-08 16:37:07 -070059
60DECLARE_GLOBAL_DATA_PTR;
61
Googler40bc9d02023-12-15 16:42:49 +080062#if defined(BL33_BOOT_TIME_PROBE)
63 #define TE TE_time
64#else
65 #define TE(...)
66#endif
67
Googlere00b8eb2019-07-08 16:37:07 -070068ulong monitor_flash_len;
69
70__weak int board_flash_wp_on(void)
71{
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
80__weak void cpu_secondary_init_r(void)
81{
82}
83
84static 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}
97
98static 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
107static int initr_reloc(void)
108{
109 /* tell others: relocation done */
110 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
Googler40bc9d02023-12-15 16:42:49 +0800111 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
Googlere00b8eb2019-07-08 16:37:07 -0700112
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
129__weak int fixup_cpu(void)
130{
131 return 0;
132}
133
134static int initr_reloc_global_data(void)
135{
136#ifdef __ARM__
137 monitor_flash_len = _end - __image_copy_start;
Googlere00b8eb2019-07-08 16:37:07 -0700138#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
139 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
140#endif
141#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
142 /*
143 * The gd->cpu pointer is set to an address in flash before relocation.
144 * We need to update it to point to the same CPU entry in RAM.
145 * TODO: why not just add gd->reloc_ofs?
146 */
147 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
148
149 /*
150 * If we didn't know the cpu mask & # cores, we can save them of
151 * now rather than 'computing' them constantly
152 */
153 fixup_cpu();
154#endif
Googler40bc9d02023-12-15 16:42:49 +0800155#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
Googlere00b8eb2019-07-08 16:37:07 -0700156 /*
Googler40bc9d02023-12-15 16:42:49 +0800157 * Some systems need to relocate the env_addr pointer early because the
158 * location it points to will get invalidated before env_relocate is
159 * called. One example is on systems that might use a L2 or L3 cache
160 * in SRAM mode and initialize that cache from SRAM mode back to being
161 * a cache in cpu_init_r.
Googlere00b8eb2019-07-08 16:37:07 -0700162 */
Googler40bc9d02023-12-15 16:42:49 +0800163 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
Googlere00b8eb2019-07-08 16:37:07 -0700164#endif
Googlere00b8eb2019-07-08 16:37:07 -0700165 return 0;
166}
167
168static int initr_serial(void)
169{
170 serial_initialize();
171 return 0;
172}
173
Googler40bc9d02023-12-15 16:42:49 +0800174#ifdef CONFIG_PPC
Googlere00b8eb2019-07-08 16:37:07 -0700175static int initr_trap(void)
176{
177 /*
178 * Setup trap handlers
179 */
Googlere00b8eb2019-07-08 16:37:07 -0700180 trap_init(gd->relocaddr);
Googler40bc9d02023-12-15 16:42:49 +0800181
Googlere00b8eb2019-07-08 16:37:07 -0700182 return 0;
183}
184#endif
185
186#ifdef CONFIG_ADDR_MAP
187static int initr_addr_map(void)
188{
189 init_addr_map();
190
191 return 0;
192}
193#endif
194
Googler40bc9d02023-12-15 16:42:49 +0800195#ifdef CONFIG_LOGBUFFER
196unsigned long logbuffer_base(void)
197{
198 return gd->ram_top - LOGBUFF_LEN;
199}
200
201static int initr_logbuffer(void)
202{
203 logbuff_init_ptrs();
204 return 0;
205}
206#endif
207
Googlere00b8eb2019-07-08 16:37:07 -0700208#ifdef CONFIG_POST
209static int initr_post_backlog(void)
210{
211 post_output_backlog();
212 return 0;
213}
214#endif
215
Googler40bc9d02023-12-15 16:42:49 +0800216#ifdef CONFIG_SYS_DELAYED_ICACHE
217static int initr_icache_enable(void)
218{
219 return 0;
220}
221#endif
222
Googlere00b8eb2019-07-08 16:37:07 -0700223#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
224static int initr_unlock_ram_in_cache(void)
225{
226 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
227 return 0;
228}
229#endif
230
231#ifdef CONFIG_PCI
232static int initr_pci(void)
233{
Googlere00b8eb2019-07-08 16:37:07 -0700234 pci_init();
Googler40bc9d02023-12-15 16:42:49 +0800235
236 return 0;
237}
Googlere00b8eb2019-07-08 16:37:07 -0700238#endif
239
Googler40bc9d02023-12-15 16:42:49 +0800240#ifdef CONFIG_WINBOND_83C553
241static int initr_w83c553f(void)
242{
243 /*
244 * Initialise the ISA bridge
245 */
246 initialise_w83c553f();
Googlere00b8eb2019-07-08 16:37:07 -0700247 return 0;
248}
249#endif
250
251static int initr_barrier(void)
252{
253#ifdef CONFIG_PPC
254 /* TODO: Can we not use dmb() macros for this? */
255 asm("sync ; isync");
256#endif
257 return 0;
258}
259
260static int initr_malloc(void)
261{
262 ulong malloc_start;
263
Googler40bc9d02023-12-15 16:42:49 +0800264#ifdef CONFIG_SYS_MALLOC_F_LEN
Googlere00b8eb2019-07-08 16:37:07 -0700265 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
266 gd->malloc_ptr / 1024);
267#endif
268 /* The malloc area is immediately below the monitor copy in DRAM */
269 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
270 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
271 TOTAL_MALLOC_LEN);
272 return 0;
273}
274
Googlere00b8eb2019-07-08 16:37:07 -0700275#ifdef CONFIG_SYS_NONCACHED_MEMORY
276static int initr_noncached(void)
277{
278 noncached_init();
279 return 0;
280}
281#endif
282
Googlere00b8eb2019-07-08 16:37:07 -0700283#ifdef CONFIG_DM
284static int initr_dm(void)
285{
Googlere00b8eb2019-07-08 16:37:07 -0700286 /* Save the pre-reloc driver model and start a new one */
287 gd->dm_root_f = gd->dm_root;
288 gd->dm_root = NULL;
Googler40bc9d02023-12-15 16:42:49 +0800289 return dm_init_and_scan(false);
Googlere00b8eb2019-07-08 16:37:07 -0700290}
291#endif
292
Googlere00b8eb2019-07-08 16:37:07 -0700293__weak int power_init_board(void)
294{
295 return 0;
296}
297
298static int initr_announce(void)
299{
300 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
301 return 0;
302}
303
Googler40bc9d02023-12-15 16:42:49 +0800304#if !defined(CONFIG_SYS_NO_FLASH)
Googlere00b8eb2019-07-08 16:37:07 -0700305static int initr_flash(void)
306{
307 ulong flash_size = 0;
308 bd_t *bd = gd->bd;
309
310 puts("Flash: ");
311
312 if (board_flash_wp_on())
313 printf("Uninitialized - Write Protect On\n");
314 else
315 flash_size = flash_init();
316
317 print_size(flash_size, "");
318#ifdef CONFIG_SYS_FLASH_CHECKSUM
319 /*
Googler40bc9d02023-12-15 16:42:49 +0800320 * Compute and print flash CRC if flashchecksum is set to 'y'
321 *
322 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
323 */
324 if (getenv_yesno("flashchecksum") == 1) {
Googlere00b8eb2019-07-08 16:37:07 -0700325 printf(" CRC: %08X", crc32(0,
Googler40bc9d02023-12-15 16:42:49 +0800326 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
327 flash_size));
Googlere00b8eb2019-07-08 16:37:07 -0700328 }
329#endif /* CONFIG_SYS_FLASH_CHECKSUM */
330 putc('\n');
331
332 /* update start of FLASH memory */
333#ifdef CONFIG_SYS_FLASH_BASE
334 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
335#endif
336 /* size of FLASH memory (final value) */
337 bd->bi_flashsize = flash_size;
338
339#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
340 /* Make a update of the Memctrl. */
341 update_flash_size(flash_size);
342#endif
343
Googler40bc9d02023-12-15 16:42:49 +0800344
Googlere00b8eb2019-07-08 16:37:07 -0700345#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
346 /* flash mapped at end of memory map */
347 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
348#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
349 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
350#endif
351 return 0;
352}
353#endif
354
Googler40bc9d02023-12-15 16:42:49 +0800355#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
356static int initr_spi(void)
357{
358 /* PPC does this here */
359#ifdef CONFIG_SPI
360#if !defined(CONFIG_ENV_IS_IN_EEPROM)
361 spi_init_f();
362#endif
363 spi_init_r();
364#endif
365 return 0;
366}
367#endif
368
Googlere00b8eb2019-07-08 16:37:07 -0700369#ifdef CONFIG_CMD_NAND
370/* go init the NAND */
371static int initr_nand(void)
372{
373 puts("NAND: ");
374 nand_init();
Googlere00b8eb2019-07-08 16:37:07 -0700375 return 0;
376}
377#endif
378
379#if defined(CONFIG_CMD_ONENAND)
380/* go init the NAND */
381static int initr_onenand(void)
382{
383 puts("NAND: ");
384 onenand_init();
385 return 0;
386}
387#endif
388
Googler40bc9d02023-12-15 16:42:49 +0800389#ifdef CONFIG_GENERIC_MMC
Googlere00b8eb2019-07-08 16:37:07 -0700390static int initr_mmc(void)
391{
Googler40bc9d02023-12-15 16:42:49 +0800392 puts("MMC: ");
Googlere00b8eb2019-07-08 16:37:07 -0700393 mmc_initialize(gd->bd);
394 return 0;
395}
396#endif
Googler40bc9d02023-12-15 16:42:49 +0800397
398#ifdef CONFIG_HAS_DATAFLASH
399static int initr_dataflash(void)
400{
401 AT91F_DataflashInit();
402 dataflash_print_info();
403 return 0;
404}
405#endif
Googlere00b8eb2019-07-08 16:37:07 -0700406
407/*
408 * Tell if it's OK to load the environment early in boot.
409 *
Googler40bc9d02023-12-15 16:42:49 +0800410 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
Googlere00b8eb2019-07-08 16:37:07 -0700411 * if this is OK (defaulting to saying it's OK).
412 *
413 * NOTE: Loading the environment early can be a bad idea if security is
414 * important, since no verification is done on the environment.
415 *
416 * @return 0 if environment should not be loaded, !=0 if it is ok to load
417 */
418static int should_load_env(void)
419{
420#ifdef CONFIG_OF_CONTROL
421 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
422#elif defined CONFIG_DELAY_ENVIRONMENT
423 return 0;
424#else
425 return 1;
426#endif
427}
428
429static int initr_env(void)
430{
Googler40bc9d02023-12-15 16:42:49 +0800431 TE(__func__);
432
Googlere00b8eb2019-07-08 16:37:07 -0700433 /* initialize environment */
434 if (should_load_env())
435 env_relocate();
436 else
Googler40bc9d02023-12-15 16:42:49 +0800437 set_default_env(NULL);
Googlere00b8eb2019-07-08 16:37:07 -0700438
439 /* Initialize from environment */
Googler40bc9d02023-12-15 16:42:49 +0800440 load_addr = getenv_ulong("loadaddr", 16, load_addr);
441#if defined(CONFIG_SYS_EXTBDINFO)
442#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
443#if defined(CONFIG_I2CFAST)
444 /*
445 * set bi_iic_fast for linux taking environment variable
446 * "i2cfast" into account
447 */
448 {
449 char *s = getenv("i2cfast");
450
451 if (s && ((*s == 'y') || (*s == 'Y'))) {
452 gd->bd->bi_iic_fast[0] = 1;
453 gd->bd->bi_iic_fast[1] = 1;
454 }
455 }
456#endif /* CONFIG_I2CFAST */
457#endif /* CONFIG_405GP, CONFIG_405EP */
458#endif /* CONFIG_SYS_EXTBDINFO */
459
460 TE(__func__);
Googlere00b8eb2019-07-08 16:37:07 -0700461
462 return 0;
463}
464
Googler40bc9d02023-12-15 16:42:49 +0800465#ifdef CONFIG_SC3
466/* TODO: with new initcalls, move this into the driver */
467extern void sc3_read_eeprom(void);
468
469static int initr_sc3_read_eeprom(void)
Googlere00b8eb2019-07-08 16:37:07 -0700470{
Googler40bc9d02023-12-15 16:42:49 +0800471 sc3_read_eeprom();
Googlere00b8eb2019-07-08 16:37:07 -0700472 return 0;
473}
474#endif
475
476static int initr_jumptable(void)
477{
478 jumptable_init();
479 return 0;
480}
481
482#if defined(CONFIG_API)
483static int initr_api(void)
484{
485 /* Initialize API */
486 api_init();
487 return 0;
488}
489#endif
490
Googler40bc9d02023-12-15 16:42:49 +0800491#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
492static int show_model_r(void)
493{
494 /* Put this here so it appears on the LCD, now it is ready */
495# ifdef CONFIG_OF_CONTROL
496 const char *model;
497
498 model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL);
499 printf("Model: %s\n", model ? model : "<unknown>");
500# else
501 checkboard();
502# endif
503 return 0;
504}
505#endif
506
Googlere00b8eb2019-07-08 16:37:07 -0700507/* enable exceptions */
508#ifdef CONFIG_ARM
509static int initr_enable_interrupts(void)
510{
511 enable_interrupts();
512 return 0;
513}
514#endif
515
516#ifdef CONFIG_CMD_NET
517static int initr_ethaddr(void)
518{
519 bd_t *bd = gd->bd;
520
521 /* kept around for legacy kernels only ... ignore the next section */
Googler40bc9d02023-12-15 16:42:49 +0800522 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
Googlere00b8eb2019-07-08 16:37:07 -0700523#ifdef CONFIG_HAS_ETH1
Googler40bc9d02023-12-15 16:42:49 +0800524 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
Googlere00b8eb2019-07-08 16:37:07 -0700525#endif
526#ifdef CONFIG_HAS_ETH2
Googler40bc9d02023-12-15 16:42:49 +0800527 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
Googlere00b8eb2019-07-08 16:37:07 -0700528#endif
529#ifdef CONFIG_HAS_ETH3
Googler40bc9d02023-12-15 16:42:49 +0800530 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
Googlere00b8eb2019-07-08 16:37:07 -0700531#endif
532#ifdef CONFIG_HAS_ETH4
Googler40bc9d02023-12-15 16:42:49 +0800533 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
Googlere00b8eb2019-07-08 16:37:07 -0700534#endif
535#ifdef CONFIG_HAS_ETH5
Googler40bc9d02023-12-15 16:42:49 +0800536 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
Googlere00b8eb2019-07-08 16:37:07 -0700537#endif
538 return 0;
539}
540#endif /* CONFIG_CMD_NET */
541
542#ifdef CONFIG_CMD_KGDB
543static int initr_kgdb(void)
544{
545 puts("KGDB: ");
546 kgdb_init();
547 return 0;
548}
549#endif
550
Googler40bc9d02023-12-15 16:42:49 +0800551#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Googlere00b8eb2019-07-08 16:37:07 -0700552static int initr_status_led(void)
553{
Googler40bc9d02023-12-15 16:42:49 +0800554 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
555
Googlere00b8eb2019-07-08 16:37:07 -0700556 return 0;
557}
558#endif
559
Googler40bc9d02023-12-15 16:42:49 +0800560#if defined(CONFIG_CMD_SCSI)
Googlere00b8eb2019-07-08 16:37:07 -0700561static int initr_scsi(void)
562{
563 puts("SCSI: ");
564 scsi_init();
Googlere00b8eb2019-07-08 16:37:07 -0700565
566 return 0;
567}
568#endif
569
Googler40bc9d02023-12-15 16:42:49 +0800570#if defined(CONFIG_CMD_DOC)
571static int initr_doc(void)
572{
573 puts("DOC: ");
574 doc_init();
575 return 0;
576}
577#endif
578
Googlere00b8eb2019-07-08 16:37:07 -0700579#ifdef CONFIG_BITBANGMII
580static int initr_bbmii(void)
581{
582 bb_miiphy_init();
583 return 0;
584}
585#endif
586
587#ifdef CONFIG_CMD_NET
588static int initr_net(void)
589{
Googler40bc9d02023-12-15 16:42:49 +0800590 TE(__func__);
591
Googler15b35d92022-10-03 17:48:21 +0800592 puts("Net: ");
Googler40bc9d02023-12-15 16:42:49 +0800593 eth_initialize(gd->bd);
Googlere00b8eb2019-07-08 16:37:07 -0700594#if defined(CONFIG_RESET_PHY_R)
Googler15b35d92022-10-03 17:48:21 +0800595 debug("Reset Ethernet PHY\n");
Googlere00b8eb2019-07-08 16:37:07 -0700596 reset_phy();
597#endif
Googler40bc9d02023-12-15 16:42:49 +0800598
599 TE(__func__);
600
Googlere00b8eb2019-07-08 16:37:07 -0700601 return 0;
602}
603#endif
604
605#ifdef CONFIG_POST
606static int initr_post(void)
607{
608 post_run(NULL, POST_RAM | post_bootmode_get(0));
609 return 0;
610}
611#endif
612
Googler40bc9d02023-12-15 16:42:49 +0800613#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
Googlere00b8eb2019-07-08 16:37:07 -0700614static int initr_pcmcia(void)
615{
616 puts("PCMCIA:");
617 pcmcia_init();
618 return 0;
619}
620#endif
621
Googler40bc9d02023-12-15 16:42:49 +0800622#if defined(CONFIG_CMD_IDE)
Googlere00b8eb2019-07-08 16:37:07 -0700623static int initr_ide(void)
624{
Googler40bc9d02023-12-15 16:42:49 +0800625#ifdef CONFIG_IDE_8xx_PCCARD
626 puts("PCMCIA:");
627#else
Googlere00b8eb2019-07-08 16:37:07 -0700628 puts("IDE: ");
Googler40bc9d02023-12-15 16:42:49 +0800629#endif
Googlere00b8eb2019-07-08 16:37:07 -0700630#if defined(CONFIG_START_IDE)
631 if (board_start_ide())
632 ide_init();
633#else
634 ide_init();
635#endif
636 return 0;
637}
638#endif
639
Googler40bc9d02023-12-15 16:42:49 +0800640#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
Googlere00b8eb2019-07-08 16:37:07 -0700641/*
642 * Export available size of memory for Linux, taking into account the
643 * protected RAM at top of memory
644 */
645int initr_mem(void)
646{
647 ulong pram = 0;
648 char memsz[32];
649
Googler40bc9d02023-12-15 16:42:49 +0800650# ifdef CONFIG_PRAM
651 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
652# endif
653# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
654 /* Also take the logbuffer into account (pram is in kB) */
655 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
656# endif
657 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
658 setenv("mem", memsz);
Googlere00b8eb2019-07-08 16:37:07 -0700659
660 return 0;
661}
662#endif
663
664#ifdef CONFIG_CMD_BEDBUG
665static int initr_bedbug(void)
666{
667 bedbug_init();
668
669 return 0;
670}
671#endif
672
Googler40bc9d02023-12-15 16:42:49 +0800673#ifdef CONFIG_PS2KBD
674static int initr_kbd(void)
675{
676 puts("PS/2: ");
677 kbd_init();
678 return 0;
679}
680#endif
681
Googlere00b8eb2019-07-08 16:37:07 -0700682static int run_main_loop(void)
683{
684#ifdef CONFIG_SANDBOX
685 sandbox_main_loop_init();
686#endif
687 /* main_loop() can return to retry autoboot, if so just run it again */
688 for (;;)
689 main_loop();
690 return 0;
691}
692
693/*
694 * Over time we hope to remove these functions with code fragments and
Googler40bc9d02023-12-15 16:42:49 +0800695 * stub funtcions, and instead call the relevant function directly.
Googlere00b8eb2019-07-08 16:37:07 -0700696 *
697 * We also hope to remove most of the driver-related init and do it if/when
698 * the driver is later used.
699 *
700 * TODO: perhaps reset the watchdog in the initcall function after each call?
701 */
Googler40bc9d02023-12-15 16:42:49 +0800702init_fnc_t init_sequence_r[] = {
Googlere00b8eb2019-07-08 16:37:07 -0700703 initr_trace,
704 initr_reloc,
705 /* TODO: could x86/PPC have this also perhaps? */
706#ifdef CONFIG_ARM
707 initr_caches,
Googlere00b8eb2019-07-08 16:37:07 -0700708#endif
709 initr_reloc_global_data,
710#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
711 initr_unlock_ram_in_cache,
712#endif
713 initr_barrier,
714 initr_malloc,
Googler40bc9d02023-12-15 16:42:49 +0800715 console_init_m,
Googlere00b8eb2019-07-08 16:37:07 -0700716#ifdef CONFIG_SYS_NONCACHED_MEMORY
717 initr_noncached,
718#endif
719 bootstage_relocate,
Googlere00b8eb2019-07-08 16:37:07 -0700720#ifdef CONFIG_DM
721 initr_dm,
722#endif
Googler40bc9d02023-12-15 16:42:49 +0800723#ifdef CONFIG_ARM
Googlere00b8eb2019-07-08 16:37:07 -0700724 board_init, /* Setup chipselects */
725#endif
726 /*
727 * TODO: printing of the clock inforamtion of the board is now
728 * implemented as part of bdinfo command. Currently only support for
729 * davinci SOC's is added. Remove this check once all the board
730 * implement this.
731 */
732#ifdef CONFIG_CLOCKS
733 set_cpu_clk_info, /* Setup clock information */
734#endif
Googlere00b8eb2019-07-08 16:37:07 -0700735 stdio_init_tables,
736 initr_serial,
737 initr_announce,
738 INIT_FUNC_WATCHDOG_RESET
Googler40bc9d02023-12-15 16:42:49 +0800739#ifdef CONFIG_PPC
Googlere00b8eb2019-07-08 16:37:07 -0700740 initr_trap,
741#endif
742#ifdef CONFIG_ADDR_MAP
743 initr_addr_map,
744#endif
745#if defined(CONFIG_BOARD_EARLY_INIT_R)
746 board_early_init_r,
747#endif
748 INIT_FUNC_WATCHDOG_RESET
Googler40bc9d02023-12-15 16:42:49 +0800749#ifdef CONFIG_LOGBUFFER
750 initr_logbuffer,
751#endif
Googlere00b8eb2019-07-08 16:37:07 -0700752#ifdef CONFIG_POST
753 initr_post_backlog,
754#endif
755 INIT_FUNC_WATCHDOG_RESET
Googler40bc9d02023-12-15 16:42:49 +0800756#ifdef CONFIG_SYS_DELAYED_ICACHE
757 initr_icache_enable,
758#endif
Googlere00b8eb2019-07-08 16:37:07 -0700759#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
760 /*
761 * Do early PCI configuration _before_ the flash gets initialised,
Googler40bc9d02023-12-15 16:42:49 +0800762 * because PCU ressources are crucial for flash access on some boards.
Googlere00b8eb2019-07-08 16:37:07 -0700763 */
764 initr_pci,
765#endif
Googler40bc9d02023-12-15 16:42:49 +0800766#ifdef CONFIG_WINBOND_83C553
767 initr_w83c553f,
768#endif
Googlere00b8eb2019-07-08 16:37:07 -0700769#ifdef CONFIG_ARCH_EARLY_INIT_R
770 arch_early_init_r,
771#endif
772 power_init_board,
Googler40bc9d02023-12-15 16:42:49 +0800773#ifndef CONFIG_SYS_NO_FLASH
Googlere00b8eb2019-07-08 16:37:07 -0700774 initr_flash,
775#endif
776 INIT_FUNC_WATCHDOG_RESET
Googler40bc9d02023-12-15 16:42:49 +0800777#if defined(CONFIG_PPC)
Googlere00b8eb2019-07-08 16:37:07 -0700778 /* initialize higher level parts of CPU like time base and timers */
779 cpu_init_r,
780#endif
Googler06419a42022-05-17 21:32:34 +0800781#ifdef CONFIG_PPC
782 initr_spi,
783#endif
Googler40bc9d02023-12-15 16:42:49 +0800784#if defined(CONFIG_X86) && defined(CONFIG_SPI)
785 init_func_spi,
786#endif
Googlere00b8eb2019-07-08 16:37:07 -0700787#ifdef CONFIG_CMD_NAND
788 initr_nand,
789#endif
790#ifdef CONFIG_CMD_ONENAND
791 initr_onenand,
792#endif
Googler40bc9d02023-12-15 16:42:49 +0800793#ifdef CONFIG_GENERIC_MMC
Googlere00b8eb2019-07-08 16:37:07 -0700794 initr_mmc,
795#endif
Googler40bc9d02023-12-15 16:42:49 +0800796#ifdef CONFIG_HAS_DATAFLASH
797 initr_dataflash,
Googlerfc3e29a2022-11-22 14:17:45 +0800798#endif
Googler40bc9d02023-12-15 16:42:49 +0800799 initr_env,
Googlere00b8eb2019-07-08 16:37:07 -0700800 INIT_FUNC_WATCHDOG_RESET
801 initr_secondary_cpu,
Googler40bc9d02023-12-15 16:42:49 +0800802#ifdef CONFIG_SC3
803 initr_sc3_read_eeprom,
804#endif
Googlere00b8eb2019-07-08 16:37:07 -0700805#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
806 mac_read_from_eeprom,
807#endif
808 INIT_FUNC_WATCHDOG_RESET
809#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
810 /*
811 * Do pci configuration
812 */
813 initr_pci,
814#endif
815 stdio_add_devices,
816 initr_jumptable,
817#ifdef CONFIG_API
818 initr_api,
819#endif
820 console_init_r, /* fully init console as a device */
821#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
Googler40bc9d02023-12-15 16:42:49 +0800822 show_model_r,
Googlere00b8eb2019-07-08 16:37:07 -0700823#endif
824#ifdef CONFIG_ARCH_MISC_INIT
825 arch_misc_init, /* miscellaneous arch-dependent init */
826#endif
827#ifdef CONFIG_MISC_INIT_R
828 misc_init_r, /* miscellaneous platform-dependent init */
829#endif
830 INIT_FUNC_WATCHDOG_RESET
831#ifdef CONFIG_CMD_KGDB
832 initr_kgdb,
833#endif
834 interrupt_init,
Googler40bc9d02023-12-15 16:42:49 +0800835#if defined(CONFIG_ARM)
Googlere00b8eb2019-07-08 16:37:07 -0700836 initr_enable_interrupts,
837#endif
Googler40bc9d02023-12-15 16:42:49 +0800838#ifdef CONFIG_X86
Googlere00b8eb2019-07-08 16:37:07 -0700839 timer_init, /* initialize timer */
840#endif
Googler40bc9d02023-12-15 16:42:49 +0800841#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
Googlere00b8eb2019-07-08 16:37:07 -0700842 initr_status_led,
843#endif
844 /* PPC has a udelay(20) here dating from 2002. Why? */
845#ifdef CONFIG_CMD_NET
846 initr_ethaddr,
847#endif
848#ifdef CONFIG_BOARD_LATE_INIT
849 board_late_init,
850#endif
Googler40bc9d02023-12-15 16:42:49 +0800851#ifdef CONFIG_CMD_SCSI
Googlere00b8eb2019-07-08 16:37:07 -0700852 INIT_FUNC_WATCHDOG_RESET
853 initr_scsi,
854#endif
Googler40bc9d02023-12-15 16:42:49 +0800855#ifdef CONFIG_CMD_DOC
856 INIT_FUNC_WATCHDOG_RESET
857 initr_doc,
858#endif
Googlere00b8eb2019-07-08 16:37:07 -0700859#ifdef CONFIG_BITBANGMII
860 initr_bbmii,
861#endif
862#ifdef CONFIG_CMD_NET
863 INIT_FUNC_WATCHDOG_RESET
864 initr_net,
865#endif
866#ifdef CONFIG_POST
867 initr_post,
868#endif
Googler40bc9d02023-12-15 16:42:49 +0800869#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
Googlere00b8eb2019-07-08 16:37:07 -0700870 initr_pcmcia,
871#endif
Googler40bc9d02023-12-15 16:42:49 +0800872#if defined(CONFIG_CMD_IDE)
Googlere00b8eb2019-07-08 16:37:07 -0700873 initr_ide,
874#endif
875#ifdef CONFIG_LAST_STAGE_INIT
876 INIT_FUNC_WATCHDOG_RESET
877 /*
878 * Some parts can be only initialized if all others (like
879 * Interrupts) are up and running (i.e. the PC-style ISA
880 * keyboard).
881 */
882 last_stage_init,
883#endif
884#ifdef CONFIG_CMD_BEDBUG
885 INIT_FUNC_WATCHDOG_RESET
886 initr_bedbug,
887#endif
Googler40bc9d02023-12-15 16:42:49 +0800888#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
Googlere00b8eb2019-07-08 16:37:07 -0700889 initr_mem,
890#endif
Googler40bc9d02023-12-15 16:42:49 +0800891#ifdef CONFIG_PS2KBD
892 initr_kbd,
893#endif
Googlere00b8eb2019-07-08 16:37:07 -0700894 run_main_loop,
895};
896
897void board_init_r(gd_t *new_gd, ulong dest_addr)
898{
Googlere00b8eb2019-07-08 16:37:07 -0700899#ifdef CONFIG_NEEDS_MANUAL_RELOC
900 int i;
901#endif
902
903#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
904 gd = new_gd;
905#endif
Googlere00b8eb2019-07-08 16:37:07 -0700906
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
912 if (initcall_run_list(init_sequence_r))
913 hang();
914
915 /* NOTREACHED - run_main_loop() does not return */
916 hang();
917}