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