]>
Commit | Line | Data |
---|---|---|
6f6430d7 SG |
1 | /* |
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 | * | |
1a459660 | 10 | * SPDX-License-Identifier: GPL-2.0+ |
6f6430d7 SG |
11 | */ |
12 | ||
13 | #include <common.h> | |
c2240d4d SG |
14 | /* 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 | |
6f6430d7 SG |
18 | #ifdef CONFIG_HAS_DATAFLASH |
19 | #include <dataflash.h> | |
20 | #endif | |
1ce60176 | 21 | #include <dm.h> |
6f6430d7 SG |
22 | #include <environment.h> |
23 | #include <fdtdec.h> | |
c2240d4d SG |
24 | #if defined(CONFIG_CMD_IDE) |
25 | #include <ide.h> | |
26 | #endif | |
6f6430d7 | 27 | #include <initcall.h> |
c2240d4d SG |
28 | #ifdef CONFIG_PS2KBD |
29 | #include <keyboard.h> | |
30 | #endif | |
31 | #if defined(CONFIG_CMD_KGDB) | |
32 | #include <kgdb.h> | |
33 | #endif | |
6f6430d7 SG |
34 | #include <logbuff.h> |
35 | #include <malloc.h> | |
c2240d4d SG |
36 | #ifdef CONFIG_BITBANGMII |
37 | #include <miiphy.h> | |
38 | #endif | |
6f6430d7 SG |
39 | #include <mmc.h> |
40 | #include <nand.h> | |
41 | #include <onenand_uboot.h> | |
c2240d4d | 42 | #include <scsi.h> |
6f6430d7 | 43 | #include <serial.h> |
c2240d4d | 44 | #include <spi.h> |
6f6430d7 | 45 | #include <stdio_dev.h> |
71c52dba | 46 | #include <trace.h> |
c2240d4d SG |
47 | #include <watchdog.h> |
48 | #ifdef CONFIG_ADDR_MAP | |
49 | #include <asm/mmu.h> | |
50 | #endif | |
6f6430d7 | 51 | #include <asm/sections.h> |
be274b99 SG |
52 | #ifdef CONFIG_X86 |
53 | #include <asm/init_helpers.h> | |
54 | #endif | |
1ce60176 | 55 | #include <dm/root.h> |
c2240d4d | 56 | #include <linux/compiler.h> |
1ce60176 | 57 | #include <linux/err.h> |
a752a8b4 AB |
58 | #ifdef CONFIG_AVR32 |
59 | #include <asm/arch/mmu.h> | |
60 | #endif | |
6f6430d7 SG |
61 | |
62 | DECLARE_GLOBAL_DATA_PTR; | |
63 | ||
64 | ulong monitor_flash_len; | |
65 | ||
dd2a6cd0 | 66 | __weak int board_flash_wp_on(void) |
c2240d4d SG |
67 | { |
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 | ||
dd2a6cd0 | 76 | __weak void cpu_secondary_init_r(void) |
c2240d4d SG |
77 | { |
78 | } | |
79 | ||
c2240d4d SG |
80 | static 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 | } | |
6f6430d7 | 93 | |
71c52dba SG |
94 | static 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 | ||
6f6430d7 SG |
103 | static int initr_reloc(void) |
104 | { | |
c9356be3 SG |
105 | /* tell others: relocation done */ |
106 | gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; | |
6f6430d7 SG |
107 | 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 | */ | |
117 | static int initr_caches(void) | |
118 | { | |
119 | /* Enable caches */ | |
120 | enable_caches(); | |
121 | return 0; | |
122 | } | |
123 | #endif | |
124 | ||
c2240d4d SG |
125 | __weak int fixup_cpu(void) |
126 | { | |
127 | return 0; | |
128 | } | |
129 | ||
6f6430d7 SG |
130 | static int initr_reloc_global_data(void) |
131 | { | |
b60eff31 AA |
132 | #ifdef __ARM__ |
133 | monitor_flash_len = _end - __image_copy_start; | |
5ff10aa7 | 134 | #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2) |
a0ba279a | 135 | monitor_flash_len = (ulong)&__init_end - gd->relocaddr; |
6f6430d7 | 136 | #endif |
c2240d4d SG |
137 | #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 | */ | |
a0ba279a | 143 | gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; |
c2240d4d SG |
144 | |
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 | */ | |
a0ba279a | 159 | gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; |
c2240d4d SG |
160 | #endif |
161 | return 0; | |
6f6430d7 SG |
162 | } |
163 | ||
164 | static int initr_serial(void) | |
165 | { | |
166 | serial_initialize(); | |
167 | return 0; | |
168 | } | |
169 | ||
c2240d4d SG |
170 | #ifdef CONFIG_PPC |
171 | static int initr_trap(void) | |
172 | { | |
173 | /* | |
174 | * Setup trap handlers | |
175 | */ | |
a0ba279a | 176 | trap_init(gd->relocaddr); |
c2240d4d SG |
177 | |
178 | return 0; | |
179 | } | |
180 | #endif | |
181 | ||
182 | #ifdef CONFIG_ADDR_MAP | |
183 | static int initr_addr_map(void) | |
184 | { | |
185 | init_addr_map(); | |
186 | ||
187 | return 0; | |
188 | } | |
189 | #endif | |
190 | ||
6f6430d7 SG |
191 | #ifdef CONFIG_LOGBUFFER |
192 | unsigned long logbuffer_base(void) | |
193 | { | |
194 | return gd->ram_top - LOGBUFF_LEN; | |
195 | } | |
196 | ||
197 | static int initr_logbuffer(void) | |
198 | { | |
199 | logbuff_init_ptrs(); | |
200 | return 0; | |
201 | } | |
202 | #endif | |
203 | ||
204 | #ifdef CONFIG_POST | |
205 | static int initr_post_backlog(void) | |
206 | { | |
207 | post_output_backlog(); | |
208 | return 0; | |
209 | } | |
210 | #endif | |
211 | ||
c2240d4d SG |
212 | #ifdef CONFIG_SYS_DELAYED_ICACHE |
213 | static int initr_icache_enable(void) | |
214 | { | |
215 | return 0; | |
216 | } | |
217 | #endif | |
218 | ||
219 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) | |
220 | static 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 | |
228 | static int initr_pci(void) | |
229 | { | |
230 | pci_init(); | |
231 | ||
232 | return 0; | |
233 | } | |
234 | #endif | |
235 | ||
236 | #ifdef CONFIG_WINBOND_83C553 | |
237 | static int initr_w83c553f(void) | |
238 | { | |
239 | /* | |
240 | * Initialise the ISA bridge | |
241 | */ | |
242 | initialise_w83c553f(); | |
243 | return 0; | |
244 | } | |
245 | #endif | |
246 | ||
247 | static 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 | ||
6f6430d7 SG |
256 | static int initr_malloc(void) |
257 | { | |
258 | ulong malloc_start; | |
259 | ||
d59476b6 SG |
260 | #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 | |
6f6430d7 | 264 | /* The malloc area is immediately below the monitor copy in DRAM */ |
a0ba279a | 265 | malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; |
a733b06b SG |
266 | mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), |
267 | TOTAL_MALLOC_LEN); | |
6f6430d7 SG |
268 | return 0; |
269 | } | |
270 | ||
1dfdd9ba TR |
271 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
272 | static int initr_noncached(void) | |
273 | { | |
274 | noncached_init(); | |
275 | return 0; | |
276 | } | |
277 | #endif | |
278 | ||
1ce60176 SG |
279 | #ifdef CONFIG_DM |
280 | static int initr_dm(void) | |
281 | { | |
ab7cd627 SG |
282 | /* 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); | |
1ce60176 SG |
286 | } |
287 | #endif | |
288 | ||
6f6430d7 SG |
289 | __weak int power_init_board(void) |
290 | { | |
291 | return 0; | |
292 | } | |
293 | ||
294 | static int initr_announce(void) | |
295 | { | |
a0ba279a | 296 | debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr); |
6f6430d7 SG |
297 | return 0; |
298 | } | |
299 | ||
61d7b1bb AB |
300 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
301 | static 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 | ||
6f6430d7 SG |
309 | #if !defined(CONFIG_SYS_NO_FLASH) |
310 | static int initr_flash(void) | |
311 | { | |
c2240d4d SG |
312 | ulong flash_size = 0; |
313 | bd_t *bd = gd->bd; | |
6f6430d7 SG |
314 | |
315 | puts("Flash: "); | |
316 | ||
70879a92 | 317 | if (board_flash_wp_on()) |
c2240d4d | 318 | printf("Uninitialized - Write Protect On\n"); |
70879a92 | 319 | else |
c2240d4d | 320 | flash_size = flash_init(); |
70879a92 | 321 | |
6f6430d7 SG |
322 | 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 | ||
c2240d4d SG |
337 | /* 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 | ||
ebe76a2d | 360 | #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI) |
c2240d4d SG |
361 | static 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 | |
6f6430d7 SG |
370 | return 0; |
371 | } | |
372 | #endif | |
373 | ||
374 | #ifdef CONFIG_CMD_NAND | |
375 | /* go init the NAND */ | |
2588ba14 | 376 | static int initr_nand(void) |
6f6430d7 SG |
377 | { |
378 | puts("NAND: "); | |
379 | nand_init(); | |
380 | return 0; | |
381 | } | |
382 | #endif | |
383 | ||
384 | #if defined(CONFIG_CMD_ONENAND) | |
385 | /* go init the NAND */ | |
2588ba14 | 386 | static int initr_onenand(void) |
6f6430d7 SG |
387 | { |
388 | puts("NAND: "); | |
389 | onenand_init(); | |
390 | return 0; | |
391 | } | |
392 | #endif | |
393 | ||
394 | #ifdef CONFIG_GENERIC_MMC | |
2588ba14 | 395 | static int initr_mmc(void) |
6f6430d7 SG |
396 | { |
397 | puts("MMC: "); | |
398 | mmc_initialize(gd->bd); | |
399 | return 0; | |
400 | } | |
401 | #endif | |
402 | ||
403 | #ifdef CONFIG_HAS_DATAFLASH | |
2588ba14 | 404 | static int initr_dataflash(void) |
6f6430d7 SG |
405 | { |
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 | */ | |
423 | static 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 | ||
434 | static 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); | |
c2240d4d SG |
444 | #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 | ||
c722f0b0 AB |
465 | #ifdef CONFIG_SYS_BOOTPARAMS_LEN |
466 | static 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 | ||
c2240d4d SG |
477 | #ifdef CONFIG_SC3 |
478 | /* TODO: with new initcalls, move this into the driver */ | |
479 | extern void sc3_read_eeprom(void); | |
480 | ||
481 | static int initr_sc3_read_eeprom(void) | |
482 | { | |
483 | sc3_read_eeprom(); | |
484 | return 0; | |
485 | } | |
486 | #endif | |
6f6430d7 SG |
487 | |
488 | static int initr_jumptable(void) | |
489 | { | |
490 | jumptable_init(); | |
491 | return 0; | |
492 | } | |
493 | ||
494 | #if defined(CONFIG_API) | |
495 | static int initr_api(void) | |
496 | { | |
497 | /* Initialize API */ | |
498 | api_init(); | |
499 | return 0; | |
500 | } | |
501 | #endif | |
502 | ||
6f6430d7 | 503 | /* enable exceptions */ |
a752a8b4 | 504 | #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) |
6f6430d7 SG |
505 | static int initr_enable_interrupts(void) |
506 | { | |
507 | enable_interrupts(); | |
508 | return 0; | |
509 | } | |
e424c15c | 510 | #endif |
6f6430d7 SG |
511 | |
512 | #ifdef CONFIG_CMD_NET | |
513 | static int initr_ethaddr(void) | |
514 | { | |
c2240d4d SG |
515 | 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 | |
539 | static 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) | |
548 | static 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) | |
557 | static int initr_scsi(void) | |
558 | { | |
c2240d4d SG |
559 | puts("SCSI: "); |
560 | scsi_init(); | |
6f6430d7 SG |
561 | |
562 | return 0; | |
563 | } | |
2c997e7a | 564 | #endif |
6f6430d7 | 565 | |
c2240d4d SG |
566 | #if defined(CONFIG_CMD_DOC) |
567 | static int initr_doc(void) | |
568 | { | |
569 | puts("DOC: "); | |
570 | doc_init(); | |
19ad527d | 571 | return 0; |
c2240d4d SG |
572 | } |
573 | #endif | |
574 | ||
6f6430d7 SG |
575 | #ifdef CONFIG_BITBANGMII |
576 | static int initr_bbmii(void) | |
577 | { | |
578 | bb_miiphy_init(); | |
579 | return 0; | |
580 | } | |
581 | #endif | |
582 | ||
583 | #ifdef CONFIG_CMD_NET | |
584 | static 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 | |
597 | static int initr_post(void) | |
598 | { | |
599 | post_run(NULL, POST_RAM | post_bootmode_get(0)); | |
600 | return 0; | |
601 | } | |
602 | #endif | |
603 | ||
c2240d4d SG |
604 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
605 | static int initr_pcmcia(void) | |
606 | { | |
607 | puts("PCMCIA:"); | |
608 | pcmcia_init(); | |
609 | return 0; | |
610 | } | |
611 | #endif | |
612 | ||
613 | #if defined(CONFIG_CMD_IDE) | |
614 | static 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 | ||
6f6430d7 SG |
631 | #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 | */ | |
636 | int 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 | |
ae1a74eb | 648 | sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram)); |
6f6430d7 | 649 | setenv("mem", memsz); |
c2240d4d SG |
650 | |
651 | return 0; | |
652 | } | |
653 | #endif | |
654 | ||
655 | #ifdef CONFIG_CMD_BEDBUG | |
656 | static int initr_bedbug(void) | |
657 | { | |
658 | bedbug_init(); | |
659 | ||
660 | return 0; | |
661 | } | |
662 | #endif | |
663 | ||
664 | #ifdef CONFIG_PS2KBD | |
665 | static int initr_kbd(void) | |
666 | { | |
667 | puts("PS/2: "); | |
668 | kbd_init(); | |
669 | return 0; | |
670 | } | |
671 | #endif | |
672 | ||
6f6430d7 SG |
673 | static int run_main_loop(void) |
674 | { | |
a733b06b SG |
675 | #ifdef CONFIG_SANDBOX |
676 | sandbox_main_loop_init(); | |
677 | #endif | |
6f6430d7 SG |
678 | /* 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. | |
c2240d4d SG |
690 | * |
691 | * TODO: perhaps reset the watchdog in the initcall function after each call? | |
6f6430d7 SG |
692 | */ |
693 | init_fnc_t init_sequence_r[] = { | |
71c52dba | 694 | initr_trace, |
6f6430d7 | 695 | initr_reloc, |
c2240d4d | 696 | /* TODO: could x86/PPC have this also perhaps? */ |
6f6430d7 SG |
697 | #ifdef CONFIG_ARM |
698 | initr_caches, | |
9fb02491 SG |
699 | #endif |
700 | initr_reloc_global_data, | |
fef3e25f YS |
701 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) |
702 | initr_unlock_ram_in_cache, | |
703 | #endif | |
9fb02491 SG |
704 | initr_barrier, |
705 | initr_malloc, | |
1dfdd9ba TR |
706 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
707 | initr_noncached, | |
708 | #endif | |
9fb02491 SG |
709 | bootstage_relocate, |
710 | #ifdef CONFIG_DM | |
711 | initr_dm, | |
712 | #endif | |
713 | #ifdef CONFIG_ARM | |
6f6430d7 | 714 | board_init, /* Setup chipselects */ |
c2240d4d SG |
715 | #endif |
716 | /* | |
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 */ | |
6f6430d7 | 724 | #endif |
9fb02491 | 725 | stdio_init_tables, |
6f6430d7 SG |
726 | initr_serial, |
727 | initr_announce, | |
c2240d4d | 728 | INIT_FUNC_WATCHDOG_RESET |
61d7b1bb AB |
729 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
730 | initr_manual_reloc_cmdtable, | |
731 | #endif | |
c2240d4d SG |
732 | #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 | |
6f6430d7 SG |
742 | #ifdef CONFIG_LOGBUFFER |
743 | initr_logbuffer, | |
744 | #endif | |
745 | #ifdef CONFIG_POST | |
746 | initr_post_backlog, | |
747 | #endif | |
c2240d4d SG |
748 | INIT_FUNC_WATCHDOG_RESET |
749 | #ifdef CONFIG_SYS_DELAYED_ICACHE | |
750 | initr_icache_enable, | |
751 | #endif | |
c2240d4d SG |
752 | #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, | |
1ce60176 | 761 | #endif |
6f6430d7 SG |
762 | #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, | |
c2240d4d SG |
768 | #endif |
769 | INIT_FUNC_WATCHDOG_RESET | |
a549f749 | 770 | #if defined(CONFIG_PPC) |
c2240d4d SG |
771 | /* initialize higher level parts of CPU like time base and timers */ |
772 | cpu_init_r, | |
be274b99 SG |
773 | #endif |
774 | #ifdef CONFIG_PPC | |
c2240d4d | 775 | initr_spi, |
6f6430d7 | 776 | #endif |
be274b99 SG |
777 | #if defined(CONFIG_X86) && defined(CONFIG_SPI) |
778 | init_func_spi, | |
779 | #endif | |
6f6430d7 SG |
780 | #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, | |
c722f0b0 AB |
793 | #ifdef CONFIG_SYS_BOOTPARAMS_LEN |
794 | initr_malloc_bootparams, | |
795 | #endif | |
c2240d4d SG |
796 | INIT_FUNC_WATCHDOG_RESET |
797 | initr_secondary_cpu, | |
798 | #ifdef CONFIG_SC3 | |
799 | initr_sc3_read_eeprom, | |
800 | #endif | |
c2240d4d SG |
801 | #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 | |
9fb02491 | 811 | stdio_add_devices, |
6f6430d7 SG |
812 | 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 | |
0365ffcc | 818 | show_board_info, |
6f6430d7 SG |
819 | #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 */ | |
c2240d4d SG |
825 | #endif |
826 | INIT_FUNC_WATCHDOG_RESET | |
827 | #ifdef CONFIG_CMD_KGDB | |
828 | initr_kgdb, | |
6f6430d7 SG |
829 | #endif |
830 | interrupt_init, | |
a752a8b4 | 831 | #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) |
6f6430d7 | 832 | initr_enable_interrupts, |
c2240d4d | 833 | #endif |
a752a8b4 | 834 | #if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) |
be274b99 SG |
835 | timer_init, /* initialize timer */ |
836 | #endif | |
c2240d4d SG |
837 | #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? */ | |
6f6430d7 SG |
841 | #ifdef CONFIG_CMD_NET |
842 | initr_ethaddr, | |
843 | #endif | |
844 | #ifdef CONFIG_BOARD_LATE_INIT | |
845 | board_late_init, | |
846 | #endif | |
c2240d4d SG |
847 | #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 | |
6f6430d7 SG |
855 | #ifdef CONFIG_BITBANGMII |
856 | initr_bbmii, | |
857 | #endif | |
858 | #ifdef CONFIG_CMD_NET | |
c2240d4d | 859 | INIT_FUNC_WATCHDOG_RESET |
6f6430d7 SG |
860 | initr_net, |
861 | #endif | |
862 | #ifdef CONFIG_POST | |
863 | initr_post, | |
c2240d4d SG |
864 | #endif |
865 | #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, | |
6f6430d7 SG |
889 | #endif |
890 | run_main_loop, | |
891 | }; | |
892 | ||
893 | void board_init_r(gd_t *new_gd, ulong dest_addr) | |
894 | { | |
7395398a AB |
895 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
896 | int i; | |
897 | #endif | |
898 | ||
a752a8b4 AB |
899 | #ifdef CONFIG_AVR32 |
900 | mmu_init_r(dest_addr); | |
901 | #endif | |
902 | ||
47a602ea | 903 | #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
6f6430d7 | 904 | gd = new_gd; |
be274b99 | 905 | #endif |
7395398a AB |
906 | |
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 | ||
6f6430d7 SG |
912 | if (initcall_run_list(init_sequence_r)) |
913 | hang(); | |
914 | ||
915 | /* NOTREACHED - run_main_loop() does not return */ | |
916 | hang(); | |
917 | } |