Merge branch '2022-08-04-Kconfig-migrations'
[platform/kernel/u-boot.git] / common / board_r.c
index 48e898b..e702f02 100644 (file)
 #include <bootstage.h>
 #include <cpu_func.h>
 #include <exports.h>
+#ifdef CONFIG_MTD_NOR_FLASH
 #include <flash.h>
+#endif
 #include <hang.h>
 #include <image.h>
 #include <irq_func.h>
 #include <log.h>
 #include <net.h>
 #include <asm/cache.h>
+#include <asm/global_data.h>
 #include <u-boot/crc.h>
-/* TODO: can we just include all these headers whether needed or not? */
-#if defined(CONFIG_CMD_BEDBUG)
-#include <bedbug/type.h>
-#endif
 #include <binman.h>
 #include <command.h>
 #include <console.h>
 #include <ide.h>
 #include <init.h>
 #include <initcall.h>
-#if defined(CONFIG_CMD_KGDB)
 #include <kgdb.h>
-#endif
 #include <irq_func.h>
 #include <malloc.h>
 #include <mapmem.h>
-#ifdef CONFIG_BITBANGMII
 #include <miiphy.h>
-#endif
 #include <mmc.h>
 #include <mux.h>
 #include <nand.h>
 #include <timer.h>
 #include <trace.h>
 #include <watchdog.h>
-#ifdef CONFIG_XEN
 #include <xen.h>
-#endif
-#ifdef CONFIG_ADDR_MAP
-#include <asm/mmu.h>
-#endif
 #include <asm/sections.h>
 #include <dm/root.h>
+#include <dm/ofnode.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <efi_loader.h>
 #include <wdt.h>
-#if defined(CONFIG_GPIO_HOG)
-#include <asm/gpio.h>
-#endif
-#ifdef CONFIG_EFI_SETUP_EARLY
+#include <asm-generic/gpio.h>
 #include <efi_loader.h>
-#endif
+#include <relocate.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -113,7 +101,7 @@ static int initr_reloc(void)
        return 0;
 }
 
-#ifdef CONFIG_ARM
+#if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
 /*
  * Some of these functions are needed purely because the functions they
  * call return void. If we change them to return 0, these stubs can go away.
@@ -135,7 +123,7 @@ static int initr_reloc_global_data(void)
 {
 #ifdef __ARM__
        monitor_flash_len = _end - __image_copy_start;
-#elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
+#elif defined(CONFIG_RISCV)
        monitor_flash_len = (ulong)&_end - (ulong)&_start;
 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
        monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
@@ -182,29 +170,10 @@ static int initr_reloc_global_data(void)
        return 0;
 }
 
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
-static int initr_trap(void)
-{
-       /*
-        * Setup trap handlers
-        */
-#if defined(CONFIG_PPC)
-       trap_init(gd->relocaddr);
-#else
-       trap_init(CONFIG_SYS_SDRAM_BASE);
-#endif
-       return 0;
-}
-#endif
-
-#ifdef CONFIG_ADDR_MAP
-static int initr_addr_map(void)
+__weak int arch_initr_trap(void)
 {
-       init_addr_map();
-
        return 0;
 }
-#endif
 
 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
 static int initr_unlock_ram_in_cache(void)
@@ -332,10 +301,16 @@ static int initr_manual_reloc_cmdtable(void)
 
 static int initr_binman(void)
 {
+       int ret;
+
        if (!CONFIG_IS_ENABLED(BINMAN_FDT))
                return 0;
 
-       return binman_init();
+       ret = binman_init();
+       if (ret)
+               printf("binman_init failed:%d\n", ret);
+
+       return ret;
 }
 
 #if defined(CONFIG_MTD_NOR_FLASH)
@@ -428,14 +403,6 @@ static int initr_mmc(void)
 }
 #endif
 
-#ifdef CONFIG_XEN
-static int initr_xen(void)
-{
-       xen_init();
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_PVBLOCK
 static int initr_pvblock(void)
 {
@@ -454,13 +421,12 @@ static int initr_pvblock(void)
  * NOTE: Loading the environment early can be a bad idea if security is
  *       important, since no verification is done on the environment.
  *
- * @return 0 if environment should not be loaded, !=0 if it is ok to load
+ * Return: 0 if environment should not be loaded, !=0 if it is ok to load
  */
 static int should_load_env(void)
 {
        if (IS_ENABLED(CONFIG_OF_CONTROL))
-               return fdtdec_get_config_int(gd->fdt_blob,
-                                               "load-environment", 1);
+               return ofnode_conf_read_int("load-environment", 1);
 
        if (IS_ENABLED(CONFIG_DELAY_ENVIRONMENT))
                return 0;
@@ -476,17 +442,24 @@ static int initr_env(void)
        else
                env_set_default(NULL, 0);
 
+       env_import_fdt();
+
        if (IS_ENABLED(CONFIG_OF_CONTROL))
                env_set_hex("fdtcontroladdr",
                            (unsigned long)map_to_sysmem(gd->fdt_blob));
 
+       #if (CONFIG_IS_ENABLED(SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
+                                               CONFIG_IS_ENABLED(SAVE_PREV_BL_FDT_ADDR))
+               save_prev_bl_data();
+       #endif
+
        /* Initialize from environment */
        image_load_addr = env_get_ulong("loadaddr", 16, image_load_addr);
 
        return 0;
 }
 
-#ifdef CONFIG_SYS_BOOTPARAMS_LEN
+#ifdef CONFIG_SYS_MALLOC_BOOTPARAMS
 static int initr_malloc_bootparams(void)
 {
        gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
@@ -498,42 +471,6 @@ static int initr_malloc_bootparams(void)
 }
 #endif
 
-static int initr_jumptable(void)
-{
-       jumptable_init();
-       return 0;
-}
-
-#if defined(CONFIG_API)
-static int initr_api(void)
-{
-       /* Initialize API */
-       api_init();
-       return 0;
-}
-#endif
-
-#ifdef CONFIG_CMD_NET
-static int initr_ethaddr(void)
-{
-       struct bd_info *bd = gd->bd;
-
-       /* kept around for legacy kernels only ... ignore the next section */
-       eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr);
-
-       return 0;
-}
-#endif /* CONFIG_CMD_NET */
-
-#ifdef CONFIG_CMD_KGDB
-static int initr_kgdb(void)
-{
-       puts("KGDB:  ");
-       kgdb_init();
-       return 0;
-}
-#endif
-
 #if defined(CONFIG_LED_STATUS)
 static int initr_status_led(void)
 {
@@ -557,14 +494,6 @@ static int initr_scsi(void)
 }
 #endif
 
-#ifdef CONFIG_BITBANGMII
-static int initr_bbmii(void)
-{
-       bb_miiphy_init();
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_CMD_NET
 static int initr_net(void)
 {
@@ -618,6 +547,29 @@ int initr_mem(void)
 }
 #endif
 
+static int dm_announce(void)
+{
+       int device_count;
+       int uclass_count;
+
+       if (IS_ENABLED(CONFIG_DM)) {
+               dm_get_stats(&device_count, &uclass_count);
+               printf("Core:  %d devices, %d uclasses", device_count,
+                      uclass_count);
+               if (CONFIG_IS_ENABLED(OF_REAL))
+                       printf(", devicetree: %s", fdtdec_get_srcname());
+               printf("\n");
+               if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
+                   (gd->fdt_src == FDTSRC_SEPARATE ||
+                    gd->fdt_src == FDTSRC_EMBED)) {
+                       printf("Warning: Unexpected devicetree source (not from a prior stage)");
+                       printf("Warning: U-Boot may not function properly\n");
+               }
+       }
+
+       return 0;
+}
+
 static int run_main_loop(void)
 {
 #ifdef CONFIG_SANDBOX
@@ -638,8 +590,9 @@ static int run_main_loop(void)
 static init_fnc_t init_sequence_r[] = {
        initr_trace,
        initr_reloc,
+       event_init,
        /* TODO: could x86/PPC have this also perhaps? */
-#ifdef CONFIG_ARM
+#if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
        initr_caches,
        /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
         *       A temporary mapping of IFC high region is since removed,
@@ -649,6 +602,9 @@ static init_fnc_t init_sequence_r[] = {
         */
 #endif
        initr_reloc_global_data,
+#if CONFIG_IS_ENABLED(NEEDS_MANUAL_RELOC) && CONFIG_IS_ENABLED(EVENT)
+       event_manual_reloc,
+#endif
 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
        initr_unlock_ram_in_cache,
 #endif
@@ -666,8 +622,10 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_DM
        initr_dm,
 #endif
-#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
-       defined(CONFIG_SANDBOX)
+#ifdef CONFIG_ADDR_MAP
+       init_addr_map,
+#endif
+#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) || defined(CONFIG_SANDBOX)
        board_init,     /* Setup chipselects */
 #endif
        /*
@@ -690,6 +648,7 @@ static init_fnc_t init_sequence_r[] = {
        stdio_init_tables,
        serial_initialize,
        initr_announce,
+       dm_announce,
 #if CONFIG_IS_ENABLED(WDT)
        initr_watchdog,
 #endif
@@ -700,12 +659,7 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
        initr_manual_reloc_cmdtable,
 #endif
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
-       initr_trap,
-#endif
-#ifdef CONFIG_ADDR_MAP
-       initr_addr_map,
-#endif
+       arch_initr_trap,
 #if defined(CONFIG_BOARD_EARLY_INIT_R)
        board_early_init_r,
 #endif
@@ -733,6 +687,9 @@ static init_fnc_t init_sequence_r[] = {
        /* initialize higher level parts of CPU like time base and timers */
        cpu_init_r,
 #endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+       efi_init_early,
+#endif
 #ifdef CONFIG_CMD_NAND
        initr_nand,
 #endif
@@ -743,18 +700,18 @@ static init_fnc_t init_sequence_r[] = {
        initr_mmc,
 #endif
 #ifdef CONFIG_XEN
-       initr_xen,
+       xen_init,
 #endif
 #ifdef CONFIG_PVBLOCK
        initr_pvblock,
 #endif
        initr_env,
-#ifdef CONFIG_SYS_BOOTPARAMS_LEN
+#ifdef CONFIG_SYS_MALLOC_BOOTPARAMS
        initr_malloc_bootparams,
 #endif
        INIT_FUNC_WATCHDOG_RESET
        cpu_secondary_init_r,
-#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
+#if defined(CONFIG_ID_EEPROM)
        mac_read_from_eeprom,
 #endif
        INIT_FUNC_WATCHDOG_RESET
@@ -765,9 +722,9 @@ static init_fnc_t init_sequence_r[] = {
        pci_init,
 #endif
        stdio_add_devices,
-       initr_jumptable,
+       jumptable_init,
 #ifdef CONFIG_API
-       initr_api,
+       api_init,
 #endif
        console_init_r,         /* fully init console as a device */
 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
@@ -782,7 +739,7 @@ static init_fnc_t init_sequence_r[] = {
 #endif
        INIT_FUNC_WATCHDOG_RESET
 #ifdef CONFIG_CMD_KGDB
-       initr_kgdb,
+       kgdb_init,
 #endif
        interrupt_init,
 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
@@ -792,9 +749,6 @@ static init_fnc_t init_sequence_r[] = {
        initr_status_led,
 #endif
        /* PPC has a udelay(20) here dating from 2002. Why? */
-#ifdef CONFIG_CMD_NET
-       initr_ethaddr,
-#endif
 #if defined(CONFIG_GPIO_HOG)
        gpio_hog_probe_all,
 #endif
@@ -806,7 +760,7 @@ static init_fnc_t init_sequence_r[] = {
        initr_scsi,
 #endif
 #ifdef CONFIG_BITBANGMII
-       initr_bbmii,
+       bb_miiphy_init,
 #endif
 #ifdef CONFIG_PCI_ENDPOINT
        pci_ep_init,
@@ -830,16 +784,9 @@ static init_fnc_t init_sequence_r[] = {
         */
        last_stage_init,
 #endif
-#ifdef CONFIG_CMD_BEDBUG
-       INIT_FUNC_WATCHDOG_RESET
-       bedbug_init,
-#endif
 #if defined(CONFIG_PRAM)
        initr_mem,
 #endif
-#ifdef CONFIG_EFI_SETUP_EARLY
-       (init_fnc_t)efi_init_obj_list,
-#endif
        run_main_loop,
 };
 
@@ -851,23 +798,18 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
         * TODO(sjg@chromium.org): Consider doing this for all archs, or
         * dropping the new_gd parameter.
         */
-#if CONFIG_IS_ENABLED(X86_64)
-       arch_setup_gd(new_gd);
-#endif
-
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-       int i;
-#endif
+       if (CONFIG_IS_ENABLED(X86_64) && !IS_ENABLED(CONFIG_EFI_APP))
+               arch_setup_gd(new_gd);
 
 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
        gd = new_gd;
 #endif
        gd->flags &= ~GD_FLG_LOG_READY;
 
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-       for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
-               init_sequence_r[i] += gd->reloc_off;
-#endif
+       if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
+               for (int i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
+                       MANUAL_RELOC(init_sequence_r[i]);
+       }
 
        if (initcall_run_list(init_sequence_r))
                hang();