From 93f4048bc2f00d2d1bda962701077ad1afbfacdf Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 23 Dec 2020 12:21:28 +0100 Subject: env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change allows board code to modify default_environment[] array when compile option DEFAULT_ENV_IS_RW is specified in board config file. Some board default variables depend on runtime configuration which is not known at compile time. Therefore allow to set default_environment[] array as non-const and allow board code to modify it when it is needed. Signed-off-by: Pali Rohár Acked-by: Andre Heider --- include/env_default.h | 2 ++ include/env_internal.h | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'include') diff --git a/include/env_default.h b/include/env_default.h index 8a0c3057f0a..ea31a8eddfa 100644 --- a/include/env_default.h +++ b/include/env_default.h @@ -19,6 +19,8 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) = { { #elif defined(DEFAULT_ENV_INSTANCE_STATIC) static char default_environment[] = { +#elif defined(DEFAULT_ENV_IS_RW) +uchar default_environment[] = { #else const uchar default_environment[] = { #endif diff --git a/include/env_internal.h b/include/env_internal.h index b26dc6239c8..708c833a550 100644 --- a/include/env_internal.h +++ b/include/env_internal.h @@ -111,7 +111,11 @@ typedef struct environment_s { extern env_t embedded_environment; #endif /* ENV_IS_EMBEDDED */ +#ifdef DEFAULT_ENV_IS_RW +extern unsigned char default_environment[]; +#else extern const unsigned char default_environment[]; +#endif #ifndef DO_DEPS_ONLY -- cgit v1.3.1 From c4df0f6f315cfec2e34e346cfc22ae088e418c0d Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 23 Dec 2020 12:21:29 +0100 Subject: arm: mvebu: Espressobin: Set default value for $fdtfile env variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Andre Heider --- board/Marvell/mvebu_armada-37xx/board.c | 19 +++++++++++++++---- include/configs/mvebu_armada-37xx.h | 13 ++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 1b9e7520cc7..7c9cc358dd0 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index 0d585606a73..6df702367c3 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -57,6 +57,11 @@ */ #define CONFIG_MTD_PARTITIONS /* required for UBI partition support */ +/* + * Environment + */ +#define DEFAULT_ENV_IS_RW /* required for configuring default fdtfile= */ + /* * Ethernet Driver configuration */ @@ -87,6 +92,11 @@ #include +/* 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" \ @@ -96,6 +106,7 @@ "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 */ -- cgit v1.3.1 From 44be835d25ba17bfa353a81984dfad61b4a60259 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 23 Dec 2020 12:21:30 +0100 Subject: arm: mvebu: Espressobin: Set default value for $ethNaddr env variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Espressobin board are MAC addresses stored in U-Boot env area. Therefore they are not present in default_environment[] array constructed at compile time. This change puts permanent MAC addresses into default_environment[] array at board runtime. Espressobin board has enabled DEFAULT_ENV_IS_RW option and therefore can modify this array. This change ensure that 'env default -a' does not delete permanent MAC addresses from Espressobin env storage area. Signed-off-by: Pali Rohár Acked-by: Andre Heider --- board/Marvell/mvebu_armada-37xx/board.c | 19 +++++++++++++++++++ include/configs/mvebu_armada-37xx.h | 4 ++++ 2 files changed, 23 insertions(+) (limited to 'include') diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 7c9cc358dd0..636bdece400 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -90,6 +90,9 @@ int board_late_init(void) 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; @@ -98,6 +101,22 @@ int board_late_init(void) 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) & A3700_MC_CTRL2_SDRAM_TYPE_MASK) == A3700_MC_CTRL2_SDRAM_TYPE_DDR4; diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index 6df702367c3..2ad4325eaf5 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -94,6 +94,10 @@ /* 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= */ \ "" -- cgit v1.3.1