arm: mvebu: Espressobin: Set default value for $fdtfile env variable
authorPali Rohár <pali@kernel.org>
Wed, 23 Dec 2020 11:21:29 +0000 (12:21 +0100)
committerStefan Roese <sr@denx.de>
Mon, 8 Feb 2021 07:53:08 +0000 (08:53 +0100)
On Espressobin board value for $fdtfile cannot be determined at compile
time and is calculated at board runtime code. This change uses a new option
DEFAULT_ENV_IS_RW to allow modifying default_environment[] array at runtime
and set into it correct value.

This change also ensure that 'env default -a' set correct value to $fdtfile.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>
board/Marvell/mvebu_armada-37xx/board.c
include/configs/mvebu_armada-37xx.h

index 1b9e752..7c9cc35 100644 (file)
@@ -7,6 +7,7 @@
 #include <dm.h>
 #include <dm/device-internal.h>
 #include <env.h>
+#include <env_internal.h>
 #include <i2c.h>
 #include <init.h>
 #include <mmc.h>
@@ -85,6 +86,7 @@ int board_init(void)
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
+       char *ptr = (char *)&default_environment[0];
        struct udevice *dev;
        struct mmc *mmc_dev;
        bool ddr4, emmc;
@@ -92,6 +94,10 @@ int board_late_init(void)
        if (!of_machine_is_compatible("globalscale,espressobin"))
                return 0;
 
+       /* Find free buffer in default_environment[] for new variables */
+       while (*ptr != '\0' && *(ptr+1) != '\0') ptr++;
+       ptr += 2;
+
        /* If the memory controller has been configured for DDR4, we're running on v7 */
        ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
                & A3700_MC_CTRL2_SDRAM_TYPE_MASK) == A3700_MC_CTRL2_SDRAM_TYPE_DDR4;
@@ -110,14 +116,19 @@ int board_late_init(void)
        if (env_get("fdtfile"))
                return 0;
 
+       /* Ensure that 'env default -a' set correct value to $fdtfile */
        if (ddr4 && emmc)
-               env_set("fdtfile", "marvell/armada-3720-espressobin-v7-emmc.dtb");
+               strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7-emmc.dtb");
        else if (ddr4)
-               env_set("fdtfile", "marvell/armada-3720-espressobin-v7.dtb");
+               strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7.dtb");
        else if (emmc)
-               env_set("fdtfile", "marvell/armada-3720-espressobin-emmc.dtb");
+               strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-emmc.dtb");
        else
-               env_set("fdtfile", "marvell/armada-3720-espressobin.dtb");
+               strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin.dtb");
+
+       /* If $fdtfile was not set explicitly by user then set default value */
+       if (!env_get("fdtfile"))
+               env_set("fdtfile", ptr + sizeof("fdtfile="));
 
        return 0;
 }
index 0d58560..6df7023 100644 (file)
 #define CONFIG_MTD_PARTITIONS          /* required for UBI partition support */
 
 /*
+ * Environment
+ */
+#define DEFAULT_ENV_IS_RW              /* required for configuring default fdtfile= */
+
+/*
  * Ethernet Driver configuration
  */
 #define CONFIG_ARP_TIMEOUT     200
 
 #include <config_distro_bootcmd.h>
 
+/* filler for default values filled by board_early_init_f() */
+#define ENV_RW_FILLER \
+       "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" /* for fdtfile= */ \
+       ""
+
 /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
 #define CONFIG_EXTRA_ENV_SETTINGS      \
        "scriptaddr=0x6d00000\0"        \
        "kernel_addr=0x7000000\0"       \
        "kernel_addr_r=0x7000000\0"     \
        "ramdisk_addr_r=0xa000000\0"    \
-       BOOTENV
+       BOOTENV \
+       ENV_RW_FILLER
 
 #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */