[PATCH 5/5] arm: mvebu: Espressobin: Use new API for setting default env at runtime
Marek Behún
kabel at kernel.org
Thu Oct 28 05:28:10 CEST 2021
From: Marek Behún <marek.behun at nic.cz>
ESPRESSObin's board code uses an ad-hoc solution for ensuring that
ethaddrs are not overwritten by `env default -a` command and that the
`fdtfile` is set to correct value when `env default -a` is called.
This ad-hoc solution is overwriting the default_environment[] buffer in
board_late_init().
Since now we have a specific API for overwriting default environment,
convert this ad-hoc code to this new API.
Since the default_environment[] buffer is not overwritten anymore by any
board, remove support for read-write default_environment[].
Signed-off-by: Marek Behún <marek.behun at nic.cz>
---
board/Marvell/mvebu_armada-37xx/board.c | 120 ++++++++++++--------
configs/mvebu_espressobin-88f3720_defconfig | 1 -
include/configs/mvebu_armada-37xx.h | 17 +--
include/env_default.h | 2 -
include/env_internal.h | 4 -
5 files changed, 75 insertions(+), 69 deletions(-)
diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
index d7b6ecafbf..5464482423 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -84,43 +84,16 @@ int board_init(void)
return 0;
}
-#ifdef CONFIG_BOARD_LATE_INIT
-int board_late_init(void)
+static bool ram_is_ddr4(void)
{
- char *ptr = &default_environment[0];
- struct udevice *dev;
- struct mmc *mmc_dev;
- bool ddr4, emmc;
- const char *mac;
- char eth[10];
- int i;
-
- 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;
-
- /*
- * Ensure that 'env default -a' does not erase permanent MAC addresses
- * stored in env variables: $ethaddr, $eth1addr, $eth2addr and $eth3addr
- */
-
- mac = env_get("ethaddr");
- if (mac && strlen(mac) <= 17)
- ptr += sprintf(ptr, "ethaddr=%s", mac) + 1;
-
- for (i = 1; i <= 3; i++) {
- sprintf(eth, "eth%daddr", i);
- mac = env_get(eth);
- if (mac && strlen(mac) <= 17)
- ptr += sprintf(ptr, "%s=%s", eth, mac) + 1;
- }
-
- /* 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)
+ return ((readl(A3700_CH0_MC_CTRL2_REG) >> A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
& A3700_MC_CTRL2_SDRAM_TYPE_MASK) == A3700_MC_CTRL2_SDRAM_TYPE_DDR4;
+}
+
+static bool has_emmc(void)
+{
+ struct mmc *mmc_dev;
+ bool emmc;
/* eMMC is mmc dev num 1 */
mmc_dev = find_mmc_device(1);
@@ -128,24 +101,79 @@ int board_late_init(void)
/* if eMMC is not present then remove it from DM */
if (!emmc && mmc_dev) {
+ struct udevice *dev;
dev = mmc_dev->dev;
device_remove(dev, DM_REMOVE_NORMAL);
device_unbind(dev);
}
- /* Ensure that 'env default -a' set correct value to $fdtfile */
- if (ddr4 && emmc)
- strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7-emmc.dtb");
- else if (ddr4)
- strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7.dtb");
- else if (emmc)
- strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-emmc.dtb");
- else
- strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin.dtb");
+ return emmc;
+}
- return 0;
+const char *board_special_default_env(unsigned i, const char **name)
+{
+ static unsigned nvars;
+ static bool built;
+ static struct {
+ const char *name;
+ char *value;
+ } vars[5];
+
+ if (!of_machine_is_compatible("globalscale,espressobin"))
+ return NULL;
+
+ /*
+ * We can access ethNaddr variables only when environment is valid.
+ * We can access mmc only if relocated (initr_env() is called after
+ * initr_mmc(), so at this point mmc device is present.
+ */
+ if (gd->env_valid != ENV_VALID || !(gd->flags & GD_FLG_RELOC))
+ return NULL;
+
+ if (!built) {
+ const char *names[4] = { "ethaddr", "eth1addr", "eth2addr",
+ "eth3addr" };
+ bool ddr4, emmc;
+
+ for (i = 0; i < 4; ++i) {
+ const char *mac;
+
+ mac = env_get(names[i]);
+ if (mac && strlen(mac) <= 17) {
+ vars[nvars].name = names[i];
+ vars[nvars].value = strdup(mac);
+ ++nvars;
+ }
+ }
+
+ /*
+ * If the memory controller has been configured for DDR4, we're
+ * running on v7
+ */
+ ddr4 = ram_is_ddr4();
+
+ emmc = has_emmc();
+
+ vars[nvars].name = "fdtfile";
+ if (ddr4 && emmc)
+ vars[nvars].value = "marvell/armada-3720-espressobin-v7-emmc.dtb";
+ else if (ddr4)
+ vars[nvars].value = "marvell/armada-3720-espressobin-v7.dtb";
+ else if (emmc)
+ vars[nvars].value = "marvell/armada-3720-espressobin-emmc.dtb";
+ else
+ vars[nvars].value = "marvell/armada-3720-espressobin.dtb";
+ ++nvars;
+
+ built = true;
+ }
+
+ if (i >= nvars)
+ return NULL;
+
+ *name = vars[i].name;
+ return vars[i].value;
}
-#endif
/* Board specific AHCI / SATA enable code */
int board_ahci_enable(void)
diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig
index 3a69954fcd..3dc6da04f8 100644
--- a/configs/mvebu_espressobin-88f3720_defconfig
+++ b/configs/mvebu_espressobin-88f3720_defconfig
@@ -24,7 +24,6 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
CONFIG_DISPLAY_BOARDINFO_LATE=y
CONFIG_ARCH_EARLY_INIT_R=y
CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_BOARD_LATE_INIT=y
# CONFIG_CMD_FLASH is not set
CONFIG_CMD_GPIO=y
CONFIG_CMD_GPT=y
diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
index e7f7e772fc..1669eaf715 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -35,11 +35,6 @@
/* End of 16M scrubbed by training in bootrom */
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_TEXT_BASE + 0xFF0000)
-/*
- * Environment
- */
-#define DEFAULT_ENV_IS_RW /* required for configuring default fdtfile= */
-
/*
* Ethernet Driver configuration
*/
@@ -70,15 +65,6 @@
#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" /* for ethaddr= */ \
- "\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 eth1addr= */ \
- "\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 eth2addr= */ \
- "\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 eth3addr= */ \
- "\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" \
@@ -88,7 +74,6 @@
"kernel_addr=0x7000000\0" \
"kernel_addr_r=0x7000000\0" \
"ramdisk_addr_r=0xa000000\0" \
- BOOTENV \
- ENV_RW_FILLER
+ BOOTENV
#endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
diff --git a/include/env_default.h b/include/env_default.h
index 23430dc70d..a1bdf97d38 100644
--- a/include/env_default.h
+++ b/include/env_default.h
@@ -19,8 +19,6 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) = {
{
#elif defined(DEFAULT_ENV_INSTANCE_STATIC)
static char default_environment[] = {
-#elif defined(DEFAULT_ENV_IS_RW)
-char default_environment[] = {
#else
const char default_environment[] = {
#endif
diff --git a/include/env_internal.h b/include/env_internal.h
index f74927cd64..e0fc3e0070 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -111,11 +111,7 @@ typedef struct environment_s {
extern env_t embedded_environment;
#endif /* ENV_IS_EMBEDDED */
-#ifdef DEFAULT_ENV_IS_RW
-extern char default_environment[];
-#else
extern const char default_environment[];
-#endif
#ifndef DO_DEPS_ONLY
--
2.32.0
More information about the U-Boot
mailing list