Merge tag 'u-boot-imx-20200825' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[platform/kernel/u-boot.git] / board / xilinx / versal / board.c
index 5718e1a..a5ca4ca 100644 (file)
@@ -5,15 +5,21 @@
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <env.h>
 #include <fdtdec.h>
+#include <init.h>
+#include <log.h>
 #include <malloc.h>
+#include <time.h>
+#include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/sys_proto.h>
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <versalpl.h>
-#include <linux/sizes.h>
+#include "../common/board.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -79,9 +85,23 @@ int board_early_init_r(void)
        return 0;
 }
 
-int board_late_init(void)
+static u8 versal_get_bootmode(void)
 {
+       u8 bootmode;
        u32 reg = 0;
+
+       reg = readl(&crp_base->boot_mode_usr);
+
+       if (reg >> BOOT_MODE_ALT_SHIFT)
+               reg >>= BOOT_MODE_ALT_SHIFT;
+
+       bootmode = reg & BOOT_MODES_MASK;
+
+       return bootmode;
+}
+
+int board_late_init(void)
+{
        u8 bootmode;
        struct udevice *dev;
        int bootseq = -1;
@@ -90,25 +110,26 @@ int board_late_init(void)
        const char *mode;
        char *new_targets;
        char *env_targets;
-       ulong initrd_hi;
 
        if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
                debug("Saved variables - Skipping\n");
                return 0;
        }
 
-       reg = readl(&crp_base->boot_mode_usr);
-
-       if (reg >> BOOT_MODE_ALT_SHIFT)
-               reg >>= BOOT_MODE_ALT_SHIFT;
+       if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
+               return 0;
 
-       bootmode = reg & BOOT_MODES_MASK;
+       bootmode = versal_get_bootmode();
 
        puts("Bootmode: ");
        switch (bootmode) {
+       case USB_MODE:
+               puts("USB_MODE\n");
+               mode = "dfu_usb";
+               break;
        case JTAG_MODE:
                puts("JTAG_MODE\n");
-               mode = "pxe dhcp";
+               mode = "jtag pxe dhcp";
                break;
        case QSPI_MODE_24BIT:
                puts("QSPI_MODE_24\n");
@@ -124,7 +145,14 @@ int board_late_init(void)
                break;
        case EMMC_MODE:
                puts("EMMC_MODE\n");
-               mode = "mmc0";
+               if (uclass_get_device_by_name(UCLASS_MMC,
+                                             "sdhci@f1050000", &dev)) {
+                       puts("Boot from EMMC but without SD1 enabled!\n");
+                       return -1;
+               }
+               debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
+               mode = "mmc";
+               bootseq = dev->seq;
                break;
        case SD_MODE:
                puts("SD_MODE\n");
@@ -186,11 +214,7 @@ int board_late_init(void)
 
        env_set("boot_targets", new_targets);
 
-       initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
-       initrd_hi = round_down(initrd_hi, SZ_16M);
-       env_set_addr("initrd_high", (void *)initrd_hi);
-
-       return 0;
+       return board_late_init_xilinx();
 }
 
 int dram_init_banksize(void)
@@ -208,7 +232,7 @@ int dram_init_banksize(void)
 
 int dram_init(void)
 {
-       if (fdtdec_setup_mem_size_base() != 0)
+       if (fdtdec_setup_mem_size_base_lowest() != 0)
                return -EINVAL;
 
        return 0;