From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64488C433EF for ; Thu, 28 Oct 2021 03:29:21 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC9C661167 for ; Thu, 28 Oct 2021 03:29:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC9C661167 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A96BC8356D; Thu, 28 Oct 2021 05:28:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="WS+z3PyL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E82482FE7; Thu, 28 Oct 2021 05:28:34 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6583F8347C for ; Thu, 28 Oct 2021 05:28:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A57561175; Thu, 28 Oct 2021 03:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635391701; bh=kPtCPqySfhPbU3I8Kt8fq9kpeGdAp3uqP4kEd5ZVs+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WS+z3PyLDkEofO6zkiNYo5ZDSKrzHto8QT12Nn8zS2rP6Znt3OZQis3SXyQAu6F1b yAQ5JjfaRTNfKhVr3U1gw/mh4qJP0GcISQ5ncl/NvtfhikjoWnnHqplAC9vlVmCVsn hvzJCBG/ry+QPrTnibGlHfguz+z1TY+WidTxG38jPIJGnHFgcpDumCa9LfI+BtTfgg Kacgy5aweiDpI9LtLLIBKlgiQqWzRh9R3glRLlUendjvgcqEOUhKzrjuBGWMYAO9ts MVcBsI44xSXXgLdSFzytoiO8vfoAsnCfFvnmEzeSNhzEvGGFadn9fbd4DoQkHjDK5l pyiOGofCguPJQ== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Simon Glass , Stefan Roese , =?UTF-8?q?Pali=20Roh=C3=A1r?= Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH 5/5] arm: mvebu: Espressobin: Use new API for setting default env at runtime Date: Thu, 28 Oct 2021 05:28:10 +0200 Message-Id: <20211028032810.18146-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211028032810.18146-1-kabel@kernel.org> References: <20211028032810.18146-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn 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 --- 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 -/* 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