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 988DAC433F5 for ; Wed, 3 Nov 2021 23:25:40 +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 276DE611C4 for ; Wed, 3 Nov 2021 23:25:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 276DE611C4 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 B6A3A83679; Thu, 4 Nov 2021 00:24:33 +0100 (CET) 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="EBg2fW4s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 14E1183653; Thu, 4 Nov 2021 00:24:00 +0100 (CET) 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 71BAD8364B for ; Thu, 4 Nov 2021 00:23:51 +0100 (CET) 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 1F3DA611CE; Wed, 3 Nov 2021 23:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635981830; bh=Z+e/h7GLy0P0WAab74vNFJNYXGqDE59oG5k4VXhzghU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBg2fW4sfESkk0FsA8fOfcfVLDVSxxd4wRZRqdrwqjpmvg1b6YcRYKMqqYbusum32 IS6QOKqJkIc+VCOMLDzXWrbucUG5pkX34rXY21wQ4hpUcw0xawgVbLY7p/XxxKvqe1 DpTolK48btrHkRpz5MADRvIycWzWfvuiirxBQ04NGkR+RjG4T0lEhC9IgU/z9vNpwi USHq6HTY6lozdAEsOHgWWJj1N6jGL+AmvWs7iibbb29O2GIaX0/j+GadD9jlEOyYCu TBQUzXyfu8JRVEvItIEuZuD2B98RCKtJWxx6ZuDMiEV4hSPCK51pnMjdZ54/AhF6Rf ZIrfyq2SakfHQ== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Simon Glass , =?UTF-8?q?Pali=20Roh=C3=A1r?= Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH v2 11/12] arm: mvebu: Espressobin: Use new API for setting default env at runtime Date: Thu, 4 Nov 2021 00:23:31 +0100 Message-Id: <20211103232332.2737-12-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211103232332.2737-1-kabel@kernel.org> References: <20211103232332.2737-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. Signed-off-by: Marek BehĂșn --- board/Marvell/mvebu_armada-37xx/board.c | 135 +++++++++++++------- configs/mvebu_espressobin-88f3720_defconfig | 1 + include/configs/mvebu_armada-37xx.h | 17 +-- 3 files changed, 90 insertions(+), 63 deletions(-) diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index d7b6ecafbf..d36620c37a 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -6,17 +6,20 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -85,66 +88,104 @@ int board_init(void) } #ifdef CONFIG_BOARD_LATE_INIT -int board_late_init(void) -{ - char *ptr = &default_environment[0]; - struct udevice *dev; - struct mmc *mmc_dev; +struct ebin_sysinfo { 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; + char vars[5][9]; + u8 nvars; + u8 macs[4][6]; +}; - 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; - } +/* + * We must do this in probe() instead of detect(), because we call + * eth_env_get_enetaddr_by_index(), which may try to read default environment, + * which may call detect() again from itself. + */ +static int ebin_probe(struct udevice *dev) +{ + struct ebin_sysinfo *priv = dev_get_priv(dev); + struct mmc *mmc; + int i; /* 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; + priv->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; /* eMMC is mmc dev num 1 */ - mmc_dev = find_mmc_device(1); - emmc = (mmc_dev && mmc_get_op_cond(mmc_dev, true) == 0); + mmc = find_mmc_device(1); + priv->emmc = (mmc && mmc_get_op_cond(mmc, true) == 0); /* if eMMC is not present then remove it from DM */ - if (!emmc && mmc_dev) { - dev = mmc_dev->dev; - device_remove(dev, DM_REMOVE_NORMAL); - device_unbind(dev); + if (!priv->emmc && mmc) { + struct udevice *mmc_dev = mmc->dev; + device_remove(mmc_dev, DM_REMOVE_NORMAL); + device_unbind(mmc_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"); + strcpy(priv->vars[priv->nvars++], "fdtfile"); + + for (i = 0; i < 4; ++i) + if (eth_env_get_enetaddr_by_index("eth", i, + priv->macs[priv->nvars - 1])) + sprintf(priv->vars[priv->nvars++], + i ? "eth%daddr" : "ethaddr", i); return 0; } + +static int ebin_get_str_list(struct udevice *dev, int id, unsigned idx, + size_t size, char *val) +{ + struct ebin_sysinfo *priv = dev_get_priv(dev); + + if (id != SYSINFO_ID_DEF_ENV_NAMES && id != SYSINFO_ID_DEF_ENV_VALUES) + return -ENOENT; + + if (idx >= priv->nvars) + return -ERANGE; + + if (id == SYSINFO_ID_DEF_ENV_NAMES) + return snprintf(val, size, "%s", priv->vars[idx]); + + if (idx == 0) + return snprintf(val, size, + "marvell/armada-3720-espressobin%s%s.dtb", + priv->ddr4 ? "-v7" : "", + priv->emmc ? "-emmc" : ""); + + return snprintf(val, size, "%pM", priv->macs[idx - 1]); +} + +static struct sysinfo_ops ebin_sysinfo_ops = { + .get_str_list = ebin_get_str_list, +}; + +U_BOOT_DRIVER(ebin_sysinfo) = { + .name = "espressobin-sysinfo", + .id = UCLASS_SYSINFO, + .ops = &ebin_sysinfo_ops, + .priv_auto = sizeof(struct ebin_sysinfo), + .probe = ebin_probe, +}; + +int board_late_init(void) +{ + struct udevice *dev; + int res; + + if (!of_machine_is_compatible("globalscale,espressobin")) + return 0; + + res = device_bind_driver(gd->dm_root, "espressobin-sysinfo", + "espressobin-sysinfo", &dev); + if (res < 0) + return res; + + res = device_probe(dev); + if (res < 0) + return res; + + return sysinfo_detect(dev); +} #endif /* Board specific AHCI / SATA enable code */ diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 3a69954fcd..6e15d9b4b1 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -84,6 +84,7 @@ CONFIG_DM_REGULATOR_GPIO=y CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y CONFIG_MVEBU_A3700_SPI=y +CONFIG_SYSINFO=y CONFIG_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_EHCI_HCD=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 */ -- 2.32.0