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 * 10 * SPDX-License-Identifier: GPL-2.0+ 11 */ 12 13 #include <common.h> 14 #include <api.h> 15 /* TODO: can we just include all these headers whether needed or not? */ 16 #if defined(CONFIG_CMD_BEDBUG) 17 #include <bedbug/type.h> 18 #endif 19 #include <command.h> 20 #include <console.h> 21 #include <dm.h> 22 #include <environment.h> 23 #include <fdtdec.h> 24 #include <ide.h> 25 #include <initcall.h> 26 #include <init_helpers.h> 27 #ifdef CONFIG_PS2KBD 28 #include <keyboard.h> 29 #endif 30 #if defined(CONFIG_CMD_KGDB) 31 #include <kgdb.h> 32 #endif 33 #include <malloc.h> 34 #include <mapmem.h> 35 #include <memalign.h> 36 #ifdef CONFIG_BITBANGMII 37 #include <miiphy.h> 38 #endif 39 #include <mmc.h> 40 #include <nand.h> 41 #include <of_live.h> 42 #include <onenand_uboot.h> 43 #include <scsi.h> 44 #include <serial.h> 45 #include <spi.h> 46 #include <stdio_dev.h> 47 #include <timer.h> 48 #include <trace.h> 49 #include <watchdog.h> 50 #ifdef CONFIG_ADDR_MAP 51 #include <asm/mmu.h> 52 #endif 53 #include <asm/sections.h> 54 #include <asm/system.h> 55 #include <dm/root.h> 56 #include <linux/compiler.h> 57 #include <linux/err.h> 58 #include <efi_loader.h> 59 #include <sysmem.h> 60 #include <bidram.h> 61 62 DECLARE_GLOBAL_DATA_PTR; 63 64 ulong monitor_flash_len; 65 66 __weak int board_flash_wp_on(void) 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 76 __weak void cpu_secondary_init_r(void) 77 { 78 } 79 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 } 93 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 103 static int initr_reloc(void) 104 { 105 /* tell others: relocation done */ 106 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; 107 108 return 0; 109 } 110 111 #ifdef CONFIG_ARM 112 /* 113 * Some of these functions are needed purely because the functions they 114 * call return void. If we change them to return 0, these stubs can go away. 115 */ 116 117 static void print_cr(void) 118 { 119 u32 reg; 120 121 #ifdef CONFIG_ARM64 122 reg = get_sctlr(); /* get control reg. */ 123 #else 124 reg = get_cr(); 125 #endif 126 puts("CR: "); 127 if (reg & CR_M) 128 puts("M/"); 129 if (reg & CR_C) 130 puts("C/"); 131 if (reg & CR_I) 132 puts("I"); 133 putc('\n'); 134 } 135 136 static int initr_caches(void) 137 { 138 /* Enable caches */ 139 enable_caches(); 140 print_cr(); 141 142 return 0; 143 } 144 #endif 145 146 __weak int fixup_cpu(void) 147 { 148 return 0; 149 } 150 151 static int initr_reloc_global_data(void) 152 { 153 #ifdef __ARM__ 154 monitor_flash_len = _end - __image_copy_start; 155 #elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV) 156 monitor_flash_len = (ulong)&_end - (ulong)&_start; 157 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2) 158 monitor_flash_len = (ulong)&__init_end - gd->relocaddr; 159 #endif 160 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) 161 /* 162 * The gd->cpu pointer is set to an address in flash before relocation. 163 * We need to update it to point to the same CPU entry in RAM. 164 * TODO: why not just add gd->reloc_ofs? 165 */ 166 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; 167 168 /* 169 * If we didn't know the cpu mask & # cores, we can save them of 170 * now rather than 'computing' them constantly 171 */ 172 fixup_cpu(); 173 #endif 174 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC 175 /* 176 * Some systems need to relocate the env_addr pointer early because the 177 * location it points to will get invalidated before env_relocate is 178 * called. One example is on systems that might use a L2 or L3 cache 179 * in SRAM mode and initialize that cache from SRAM mode back to being 180 * a cache in cpu_init_r. 181 */ 182 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; 183 #endif 184 #ifdef CONFIG_OF_EMBED 185 /* 186 * The fdt_blob needs to be moved to new relocation address 187 * incase of FDT blob is embedded with in image 188 */ 189 gd->fdt_blob += gd->reloc_off; 190 #endif 191 #ifdef CONFIG_EFI_LOADER 192 efi_runtime_relocate(gd->relocaddr, NULL); 193 #endif 194 195 return 0; 196 } 197 198 static int initr_serial(void) 199 { 200 serial_initialize(); 201 return 0; 202 } 203 204 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) 205 static int initr_trap(void) 206 { 207 /* 208 * Setup trap handlers 209 */ 210 #if defined(CONFIG_PPC) 211 trap_init(gd->relocaddr); 212 #else 213 trap_init(CONFIG_SYS_SDRAM_BASE); 214 #endif 215 return 0; 216 } 217 #endif 218 219 #ifdef CONFIG_ADDR_MAP 220 static int initr_addr_map(void) 221 { 222 init_addr_map(); 223 224 return 0; 225 } 226 #endif 227 228 #ifdef CONFIG_POST 229 static int initr_post_backlog(void) 230 { 231 post_output_backlog(); 232 return 0; 233 } 234 #endif 235 236 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) 237 static int initr_unlock_ram_in_cache(void) 238 { 239 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */ 240 return 0; 241 } 242 #endif 243 244 #ifdef CONFIG_PCI 245 static int initr_pci(void) 246 { 247 #ifndef CONFIG_DM_PCI 248 pci_init(); 249 #endif 250 251 return 0; 252 } 253 #endif 254 255 static int initr_barrier(void) 256 { 257 #ifdef CONFIG_PPC 258 /* TODO: Can we not use dmb() macros for this? */ 259 asm("sync ; isync"); 260 #endif 261 return 0; 262 } 263 264 static int initr_malloc(void) 265 { 266 ulong malloc_start; 267 268 #if CONFIG_VAL(SYS_MALLOC_F_LEN) 269 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr, 270 gd->malloc_ptr / 1024); 271 #endif 272 /* The malloc area is immediately below the monitor copy in DRAM */ 273 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; 274 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), 275 TOTAL_MALLOC_LEN); 276 return 0; 277 } 278 279 static int initr_console_record(void) 280 { 281 #if defined(CONFIG_CONSOLE_RECORD) 282 int ret; 283 284 ret = console_record_init(); 285 if (!ret) 286 console_record_reset_enable(); 287 return ret; 288 #else 289 return 0; 290 #endif 291 } 292 293 #ifdef CONFIG_SYS_NONCACHED_MEMORY 294 static int initr_noncached(void) 295 { 296 noncached_init(); 297 return 0; 298 } 299 #endif 300 301 #ifdef CONFIG_OF_LIVE 302 static int initr_of_live(void) 303 { 304 int ret; 305 306 bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live"); 307 ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root); 308 bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE); 309 if (ret) 310 return ret; 311 312 return 0; 313 } 314 #endif 315 316 #ifdef CONFIG_DM 317 static int initr_dm(void) 318 { 319 int ret; 320 321 /* Save the pre-reloc driver model and start a new one */ 322 gd->dm_root_f = gd->dm_root; 323 gd->dm_root = NULL; 324 #ifdef CONFIG_TIMER 325 gd->timer = NULL; 326 #endif 327 bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r"); 328 ret = dm_init_and_scan(false); 329 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R); 330 if (ret) 331 return ret; 332 #ifdef CONFIG_TIMER_EARLY 333 ret = dm_timer_init(); 334 if (ret) 335 return ret; 336 #endif 337 338 return 0; 339 } 340 #endif 341 342 static int initr_bootstage(void) 343 { 344 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r"); 345 346 return 0; 347 } 348 349 __weak int power_init_board(void) 350 { 351 return 0; 352 } 353 354 static int initr_announce(void) 355 { 356 ulong addr; 357 358 #ifndef CONFIG_SKIP_RELOCATE_UBOOT 359 addr = gd->relocaddr; 360 #else 361 addr = CONFIG_SYS_TEXT_BASE; 362 #endif 363 debug("Now running in RAM - U-Boot at: %08lx\n", addr); 364 365 return 0; 366 } 367 368 #ifdef CONFIG_NEEDS_MANUAL_RELOC 369 static int initr_manual_reloc_cmdtable(void) 370 { 371 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd), 372 ll_entry_count(cmd_tbl_t, cmd)); 373 return 0; 374 } 375 #endif 376 377 #if defined(CONFIG_MTD_NOR_FLASH) 378 static int initr_flash(void) 379 { 380 ulong flash_size = 0; 381 bd_t *bd = gd->bd; 382 383 puts("Flash: "); 384 385 if (board_flash_wp_on()) 386 printf("Uninitialized - Write Protect On\n"); 387 else 388 flash_size = flash_init(); 389 390 print_size(flash_size, ""); 391 #ifdef CONFIG_SYS_FLASH_CHECKSUM 392 /* 393 * Compute and print flash CRC if flashchecksum is set to 'y' 394 * 395 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX 396 */ 397 if (env_get_yesno("flashchecksum") == 1) { 398 printf(" CRC: %08X", crc32(0, 399 (const unsigned char *) CONFIG_SYS_FLASH_BASE, 400 flash_size)); 401 } 402 #endif /* CONFIG_SYS_FLASH_CHECKSUM */ 403 putc('\n'); 404 405 /* update start of FLASH memory */ 406 #ifdef CONFIG_SYS_FLASH_BASE 407 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; 408 #endif 409 /* size of FLASH memory (final value) */ 410 bd->bi_flashsize = flash_size; 411 412 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE) 413 /* Make a update of the Memctrl. */ 414 update_flash_size(flash_size); 415 #endif 416 417 418 #if defined(CONFIG_OXC) || defined(CONFIG_RMU) 419 /* flash mapped at end of memory map */ 420 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size; 421 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE 422 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */ 423 #endif 424 return 0; 425 } 426 #endif 427 428 #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI) 429 static int initr_spi(void) 430 { 431 /* MPC8xx does this here */ 432 #ifdef CONFIG_MPC8XX_SPI 433 #if !defined(CONFIG_ENV_IS_IN_EEPROM) 434 spi_init_f(); 435 #endif 436 spi_init_r(); 437 #endif 438 return 0; 439 } 440 #endif 441 442 #ifdef CONFIG_CMD_NAND 443 /* go init the NAND */ 444 static int initr_nand(void) 445 { 446 #ifndef CONFIG_USING_KERNEL_DTB 447 puts("NAND: "); 448 nand_init(); 449 printf("%lu MiB\n", nand_size() / 1024); 450 #endif 451 return 0; 452 } 453 #endif 454 455 #if defined(CONFIG_CMD_ONENAND) 456 /* go init the NAND */ 457 static int initr_onenand(void) 458 { 459 puts("NAND: "); 460 onenand_init(); 461 return 0; 462 } 463 #endif 464 465 #ifdef CONFIG_MMC 466 static int initr_mmc(void) 467 { 468 /* 469 * When CONFIG_USING_KERNEL_DTB is enabled, mmc has been initialized earlier. 470 */ 471 #ifndef CONFIG_USING_KERNEL_DTB 472 puts("MMC: "); 473 mmc_initialize(gd->bd); 474 #endif 475 return 0; 476 } 477 #endif 478 479 #ifdef CONFIG_MTD_BLK 480 static int initr_mtd_blk(void) 481 { 482 #ifndef CONFIG_USING_KERNEL_DTB 483 struct blk_desc *dev_desc; 484 485 puts("mtd_blk: "); 486 dev_desc = rockchip_get_bootdev(); 487 if (dev_desc) 488 mtd_blk_map_partitions(dev_desc); 489 #endif 490 return 0; 491 } 492 #endif 493 494 #if !defined(CONFIG_USING_KERNEL_DTB) || !defined(CONFIG_ENV_IS_NOWHERE) 495 /* 496 * Tell if it's OK to load the environment early in boot. 497 * 498 * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see 499 * if this is OK (defaulting to saying it's OK). 500 * 501 * NOTE: Loading the environment early can be a bad idea if security is 502 * important, since no verification is done on the environment. 503 * 504 * @return 0 if environment should not be loaded, !=0 if it is ok to load 505 */ 506 static int should_load_env(void) 507 { 508 #ifdef CONFIG_OF_CONTROL 509 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1); 510 #elif defined CONFIG_DELAY_ENVIRONMENT 511 return 0; 512 #else 513 return 1; 514 #endif 515 } 516 517 static int initr_env(void) 518 { 519 /* initialize environment */ 520 if (should_load_env()) 521 env_relocate(); 522 else 523 set_default_env(NULL); 524 #ifdef CONFIG_OF_CONTROL 525 env_set_addr("fdtcontroladdr", gd->fdt_blob); 526 #endif 527 528 /* Initialize from environment */ 529 load_addr = env_get_ulong("loadaddr", 16, load_addr); 530 531 return 0; 532 } 533 #endif 534 535 #ifdef CONFIG_USING_KERNEL_DTB 536 /* 537 * If !defined(CONFIG_ENV_IS_NOWHERE): 538 * 539 * Storage env or kernel dtb load depends on bootdev, while bootdev 540 * depends on env varname: devtype, devnum and rkimg_bootdev, etc. 541 * So we have to use nowhere env firstly and cover the storage env 542 * after it is loaded. 543 * 544 * Providing a minimum and necessary nowhere env for board init to 545 * avoid covering the other varnames in storage env. 546 */ 547 static int initr_env_nowhere(void) 548 { 549 #ifdef CONFIG_ENV_IS_NOWHERE 550 set_default_env(NULL); 551 return 0; 552 #else 553 const char env_minimum[] = { 554 ENV_MEM_LAYOUT_SETTINGS 555 #ifdef ENV_MEM_LAYOUT_SETTINGS1 556 ENV_MEM_LAYOUT_SETTINGS1 557 #endif 558 #ifdef RKIMG_DET_BOOTDEV 559 RKIMG_DET_BOOTDEV 560 #endif 561 }; 562 563 return set_board_env((char *)env_minimum, ENV_SIZE, 0, true); 564 #endif 565 } 566 567 #if !defined(CONFIG_ENV_IS_NOWHERE) 568 /* 569 * storage has been initialized in board_init(), we could switch env 570 * from nowhere to storage, i.e. CONFIG_ENV_IS_IN_xxx=y. 571 */ 572 static int initr_env_switch(void) 573 { 574 ALLOC_CACHE_ALIGN_BUFFER(env_t, env_nowhere, 1); 575 char *data; 576 int ret; 577 578 data = env_get("bootargs"); 579 if (data) { 580 env_set("bootargs_tmp", data); 581 env_set("bootargs", NULL); 582 } 583 584 /* Export nowhere env for late use */ 585 ret = env_export(env_nowhere); 586 if (ret) { 587 printf("%s: export nowhere env fail, ret=%d\n", __func__, ret); 588 return -EINVAL; 589 } 590 591 /* Destroy nowhere env and import storage env */ 592 initr_env(); 593 594 /* Append/override nowhere env to storage env */ 595 set_board_env((char *)env_nowhere->data, ENV_SIZE, H_NOCLEAR, false); 596 597 /* 598 * Restore nowhere bootargs to append/override the one in env storage. 599 * 600 * Without this, the entire "bootargs" in storage env is replaces by 601 * the one in env_nowhere->data. 602 */ 603 data = env_get("bootargs_tmp"); 604 if (data) { 605 env_update("bootargs", data); 606 env_set("bootargs_tmp", NULL); 607 } 608 609 return 0; 610 } 611 #endif /* CONFIG_ENV_IS_NOWHERE */ 612 #endif /* CONFIG_USING_KERNEL_DTB */ 613 614 #ifdef CONFIG_SYS_BOOTPARAMS_LEN 615 static int initr_malloc_bootparams(void) 616 { 617 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN); 618 if (!gd->bd->bi_boot_params) { 619 puts("WARNING: Cannot allocate space for boot parameters\n"); 620 return -ENOMEM; 621 } 622 return 0; 623 } 624 #endif 625 626 static int initr_jumptable(void) 627 { 628 jumptable_init(); 629 return 0; 630 } 631 632 #if defined(CONFIG_API) 633 static int initr_api(void) 634 { 635 /* Initialize API */ 636 api_init(); 637 return 0; 638 } 639 #endif 640 641 /* enable exceptions */ 642 #ifdef CONFIG_ARM 643 static int initr_enable_interrupts(void) 644 { 645 enable_interrupts(); 646 return 0; 647 } 648 #endif 649 650 #ifdef CONFIG_CMD_NET 651 static int initr_ethaddr(void) 652 { 653 bd_t *bd = gd->bd; 654 655 /* kept around for legacy kernels only ... ignore the next section */ 656 eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr); 657 #ifdef CONFIG_HAS_ETH1 658 eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr); 659 #endif 660 #ifdef CONFIG_HAS_ETH2 661 eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr); 662 #endif 663 #ifdef CONFIG_HAS_ETH3 664 eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr); 665 #endif 666 #ifdef CONFIG_HAS_ETH4 667 eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr); 668 #endif 669 #ifdef CONFIG_HAS_ETH5 670 eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr); 671 #endif 672 return 0; 673 } 674 #endif /* CONFIG_CMD_NET */ 675 676 #ifdef CONFIG_CMD_KGDB 677 static int initr_kgdb(void) 678 { 679 puts("KGDB: "); 680 kgdb_init(); 681 return 0; 682 } 683 #endif 684 685 #if defined(CONFIG_LED_STATUS) 686 static int initr_status_led(void) 687 { 688 #if defined(CONFIG_LED_STATUS_BOOT) 689 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING); 690 #else 691 status_led_init(); 692 #endif 693 return 0; 694 } 695 #endif 696 697 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI) 698 static int initr_scsi(void) 699 { 700 puts("SCSI: "); 701 scsi_init(); 702 703 return 0; 704 } 705 #endif 706 707 #ifdef CONFIG_BITBANGMII 708 static int initr_bbmii(void) 709 { 710 bb_miiphy_init(); 711 return 0; 712 } 713 #endif 714 715 #ifdef CONFIG_CMD_NET 716 static int initr_net(void) 717 { 718 puts("Net: "); 719 eth_initialize(); 720 #if defined(CONFIG_RESET_PHY_R) 721 debug("Reset Ethernet PHY\n"); 722 reset_phy(); 723 #endif 724 return 0; 725 } 726 #endif 727 728 #ifdef CONFIG_POST 729 static int initr_post(void) 730 { 731 post_run(NULL, POST_RAM | post_bootmode_get(0)); 732 return 0; 733 } 734 #endif 735 736 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE) 737 static int initr_pcmcia(void) 738 { 739 puts("PCMCIA:"); 740 pcmcia_init(); 741 return 0; 742 } 743 #endif 744 745 #if defined(CONFIG_IDE) 746 static int initr_ide(void) 747 { 748 puts("IDE: "); 749 #if defined(CONFIG_START_IDE) 750 if (board_start_ide()) 751 ide_init(); 752 #else 753 ide_init(); 754 #endif 755 return 0; 756 } 757 #endif 758 759 #if defined(CONFIG_PRAM) 760 /* 761 * Export available size of memory for Linux, taking into account the 762 * protected RAM at top of memory 763 */ 764 int initr_mem(void) 765 { 766 ulong pram = 0; 767 char memsz[32]; 768 769 # ifdef CONFIG_PRAM 770 pram = env_get_ulong("pram", 10, CONFIG_PRAM); 771 # endif 772 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram)); 773 env_set("mem", memsz); 774 775 return 0; 776 } 777 #endif 778 779 #ifdef CONFIG_CMD_BEDBUG 780 static int initr_bedbug(void) 781 { 782 bedbug_init(); 783 784 return 0; 785 } 786 #endif 787 788 #ifdef CONFIG_PS2KBD 789 static int initr_kbd(void) 790 { 791 puts("PS/2: "); 792 kbd_init(); 793 return 0; 794 } 795 #endif 796 797 __weak int interrupt_debugger_init(void) 798 { 799 return 0; 800 } 801 802 __weak int board_initr_caches_fixup(void) 803 { 804 return 0; 805 } 806 807 static int run_main_loop(void) 808 { 809 #ifdef CONFIG_SANDBOX 810 sandbox_main_loop_init(); 811 #endif 812 /* main_loop() can return to retry autoboot, if so just run it again */ 813 for (;;) 814 main_loop(); 815 return 0; 816 } 817 818 /* 819 * Over time we hope to remove these functions with code fragments and 820 * stub funtcions, and instead call the relevant function directly. 821 * 822 * We also hope to remove most of the driver-related init and do it if/when 823 * the driver is later used. 824 * 825 * TODO: perhaps reset the watchdog in the initcall function after each call? 826 */ 827 static init_fnc_t init_sequence_r[] = { 828 initr_trace, 829 initr_reloc, 830 /* TODO: could x86/PPC have this also perhaps? */ 831 #ifdef CONFIG_ARM 832 initr_caches, 833 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR. 834 * A temporary mapping of IFC high region is since removed, 835 * so environmental variables in NOR flash is not availble 836 * until board_init() is called below to remap IFC to high 837 * region. 838 */ 839 #endif 840 initr_reloc_global_data, 841 842 /* 843 * Some platform requires to reserve memory regions for some firmware 844 * to avoid kernel touches it, but U-Boot may have communication with 845 * firmware by share memory. So that we had better reserve firmware 846 * region after the initr_caches() which enables MMU and init 847 * translation table, we need firmware region to be mapped as cacheable 848 * like other regions, otherwise there would be dcache coherence issue 849 * between firmware and U-Boot. 850 */ 851 board_initr_caches_fixup, 852 853 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) 854 initr_unlock_ram_in_cache, 855 #endif 856 initr_barrier, 857 initr_malloc, 858 #ifdef CONFIG_BIDRAM 859 bidram_initr, 860 #endif 861 #ifdef CONFIG_SYSMEM 862 sysmem_initr, 863 #endif 864 log_init, 865 initr_bootstage, /* Needs malloc() but has its own timer */ 866 initr_console_record, 867 #ifdef CONFIG_SYS_NONCACHED_MEMORY 868 initr_noncached, 869 #endif 870 bootstage_relocate, 871 872 interrupt_init, 873 #ifdef CONFIG_ARM 874 initr_enable_interrupts, 875 #endif 876 interrupt_debugger_init, 877 878 #ifdef CONFIG_OF_LIVE 879 initr_of_live, 880 #endif 881 #ifdef CONFIG_DM 882 initr_dm, 883 #endif 884 885 #ifdef CONFIG_USING_KERNEL_DTB 886 initr_env_nowhere, 887 #endif 888 #if defined(CONFIG_BOARD_EARLY_INIT_R) 889 board_early_init_r, 890 #endif 891 892 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) 893 board_init, /* Setup chipselects */ 894 #endif 895 896 #if defined(CONFIG_USING_KERNEL_DTB) && !defined(CONFIG_ENV_IS_NOWHERE) 897 initr_env_switch, 898 #endif 899 900 /* 901 * TODO: printing of the clock inforamtion of the board is now 902 * implemented as part of bdinfo command. Currently only support for 903 * davinci SOC's is added. Remove this check once all the board 904 * implement this. 905 */ 906 #ifdef CONFIG_CLOCKS 907 set_cpu_clk_info, /* Setup clock information */ 908 #endif 909 #ifdef CONFIG_EFI_LOADER 910 efi_memory_init, 911 #endif 912 stdio_init_tables, 913 initr_serial, 914 initr_announce, 915 INIT_FUNC_WATCHDOG_RESET 916 #ifdef CONFIG_NEEDS_MANUAL_RELOC 917 initr_manual_reloc_cmdtable, 918 #endif 919 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) 920 initr_trap, 921 #endif 922 #ifdef CONFIG_ADDR_MAP 923 initr_addr_map, 924 #endif 925 INIT_FUNC_WATCHDOG_RESET 926 #ifdef CONFIG_POST 927 initr_post_backlog, 928 #endif 929 INIT_FUNC_WATCHDOG_RESET 930 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT) 931 /* 932 * Do early PCI configuration _before_ the flash gets initialised, 933 * because PCU ressources are crucial for flash access on some boards. 934 */ 935 initr_pci, 936 #endif 937 #ifdef CONFIG_ARCH_EARLY_INIT_R 938 arch_early_init_r, 939 #endif 940 power_init_board, 941 #ifdef CONFIG_MTD_NOR_FLASH 942 initr_flash, 943 #endif 944 INIT_FUNC_WATCHDOG_RESET 945 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86) 946 /* initialize higher level parts of CPU like time base and timers */ 947 cpu_init_r, 948 #endif 949 #ifdef CONFIG_PPC 950 initr_spi, 951 #endif 952 #ifdef CONFIG_CMD_NAND 953 initr_nand, 954 #endif 955 #ifdef CONFIG_CMD_ONENAND 956 initr_onenand, 957 #endif 958 #ifdef CONFIG_MTD_BLK 959 initr_mtd_blk, 960 #endif 961 #ifdef CONFIG_MMC 962 initr_mmc, 963 #endif 964 #ifndef CONFIG_USING_KERNEL_DTB 965 initr_env, 966 #endif 967 #ifdef CONFIG_SYS_BOOTPARAMS_LEN 968 initr_malloc_bootparams, 969 #endif 970 INIT_FUNC_WATCHDOG_RESET 971 initr_secondary_cpu, 972 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET) 973 mac_read_from_eeprom, 974 #endif 975 INIT_FUNC_WATCHDOG_RESET 976 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT) 977 /* 978 * Do pci configuration 979 */ 980 initr_pci, 981 #endif 982 stdio_add_devices, 983 initr_jumptable, 984 #ifdef CONFIG_API 985 initr_api, 986 #endif 987 console_init_r, /* fully init console as a device */ 988 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE 989 console_announce_r, 990 show_board_info, 991 #endif 992 #ifdef CONFIG_ARCH_MISC_INIT 993 arch_misc_init, /* miscellaneous arch-dependent init */ 994 #endif 995 #ifdef CONFIG_MISC_INIT_R 996 misc_init_r, /* miscellaneous platform-dependent init */ 997 #endif 998 INIT_FUNC_WATCHDOG_RESET 999 #ifdef CONFIG_CMD_KGDB 1000 initr_kgdb, 1001 #endif 1002 1003 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K) 1004 timer_init, /* initialize timer */ 1005 #endif 1006 #if defined(CONFIG_LED_STATUS) 1007 initr_status_led, 1008 #endif 1009 /* PPC has a udelay(20) here dating from 2002. Why? */ 1010 #ifdef CONFIG_CMD_NET 1011 initr_ethaddr, 1012 #endif 1013 #ifdef CONFIG_BOARD_LATE_INIT 1014 board_late_init, 1015 #endif 1016 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI) 1017 INIT_FUNC_WATCHDOG_RESET 1018 initr_scsi, 1019 #endif 1020 #ifdef CONFIG_BITBANGMII 1021 initr_bbmii, 1022 #endif 1023 #ifdef CONFIG_CMD_NET 1024 INIT_FUNC_WATCHDOG_RESET 1025 initr_net, 1026 #endif 1027 #ifdef CONFIG_POST 1028 initr_post, 1029 #endif 1030 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE) 1031 initr_pcmcia, 1032 #endif 1033 #if defined(CONFIG_IDE) 1034 initr_ide, 1035 #endif 1036 #ifdef CONFIG_LAST_STAGE_INIT 1037 INIT_FUNC_WATCHDOG_RESET 1038 /* 1039 * Some parts can be only initialized if all others (like 1040 * Interrupts) are up and running (i.e. the PC-style ISA 1041 * keyboard). 1042 */ 1043 last_stage_init, 1044 #endif 1045 #ifdef CONFIG_CMD_BEDBUG 1046 INIT_FUNC_WATCHDOG_RESET 1047 initr_bedbug, 1048 #endif 1049 #if defined(CONFIG_PRAM) 1050 initr_mem, 1051 #endif 1052 #ifdef CONFIG_PS2KBD 1053 initr_kbd, 1054 #endif 1055 run_main_loop, 1056 }; 1057 1058 void board_init_r(gd_t *new_gd, ulong dest_addr) 1059 { 1060 /* 1061 * Set up the new global data pointer. So far only x86 does this 1062 * here. 1063 * TODO(sjg@chromium.org): Consider doing this for all archs, or 1064 * dropping the new_gd parameter. 1065 */ 1066 #if CONFIG_IS_ENABLED(X86_64) 1067 arch_setup_gd(new_gd); 1068 #endif 1069 1070 #ifdef CONFIG_NEEDS_MANUAL_RELOC 1071 int i; 1072 #endif 1073 1074 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 1075 gd = new_gd; 1076 #endif 1077 gd->flags &= ~GD_FLG_LOG_READY; 1078 1079 #ifdef CONFIG_NEEDS_MANUAL_RELOC 1080 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++) 1081 init_sequence_r[i] += gd->reloc_off; 1082 #endif 1083 1084 if (initcall_run_list(init_sequence_r)) 1085 hang(); 1086 1087 /* NOTREACHED - run_main_loop() does not return */ 1088 hang(); 1089 } 1090