From 48f2c8a37f700859a7004dce5adb116597a45700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 17 Aug 2020 16:36:38 +0200 Subject: [PATCH 01/14] arm: mvebu: Espressobin: Disallow forwarding packets between wan and lan ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default Topaz switch on Espressobin board forwards packets between all ethernet ports, including CPU (port 0), wan (port 1) and lan (ports 2,3). This default U-Boot setup is unsuitable for using Espressobin as router as it opens security hole in forwarding all packets between wan and lan ports. E.g. dhcp packets from wan network leaks to lan network during small time window until U-Boot boots Linux kernel which loads network drivers which disallows forwarding between wan and lan. This patch fixes above problem. For Espressobin board prior putting Topaz switch into forwarding mode, Topaz switch is reconfigured to allow forwarding packets from wan and lan ports only to CPU port. This ensures that packets from wan port are not forwarded to lan ports and vice-versa. Packets from CPU port are still forwarded to all other ports, so U-Boot network boot works with any ethernet port as before. This problem was already discussed on Espressobin forum [1] and on Marvell's github issue tracker [2]. As a workaround people on Espressobin forum patched U-Boot to completely disable lan ports on Topaz switch which prevented forwarding packets. That workaround had an issue that U-Boot was unable to netboot via lan ports anymore. Change in this patch does not have such issue. This security issue has been dicussed here as well: [3]. [1] - https://web.archive.org/web/20191231164238/http://espressobin.net/forums/topic/boot-behavior-of-the-switch-and-security/ [2] - https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18 [3] - https://forum.armbian.com/topic/12635-espressobin-uboot-security-concerns-switch-init-portmask/ Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Tested-by: Andre Heider --- board/Marvell/mvebu_armada-37xx/board.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 9bea1986d4..031de318c6 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -44,6 +44,7 @@ DECLARE_GLOBAL_DATA_PTR; /* Switch Port Registers */ #define MVEBU_SW_LINK_CTRL_REG (1) #define MVEBU_SW_PORT_CTRL_REG (4) +#define MVEBU_SW_PORT_BASE_VLAN (6) /* Global 2 Registers */ #define MVEBU_G2_SMI_PHY_CMD_REG (24) @@ -207,8 +208,16 @@ int board_network_enable(struct mii_dev *bus) * FIXME: remove this code once Topaz driver gets available * A3720 Community Board Only * Configure Topaz switch (88E6341) + * Restrict output to ports 1,2,3 only from port 0 (CPU) * Set port 0,1,2,3 to forwarding Mode (through Switch Port registers) */ + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0), MVEBU_SW_PORT_CTRL_REG, 0x7f); mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), From a68676535f2fdb279d0510ed4a202b940da9ca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 17 Aug 2020 17:13:19 +0200 Subject: [PATCH 02/14] arm: mvebu: Espressobin: Enable CONFIG_MVNETA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Espressobin uses mvneta ethernet driver. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Tested-by: Andre Heider --- configs/mvebu_espressobin-88f3720_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 5136f02806..495faf43a3 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -80,3 +80,4 @@ CONFIG_USB_ETHER_RTL8152=y CONFIG_USB_ETHER_SMSC95XX=y CONFIG_SHA1=y CONFIG_SHA256=y +CONFIG_MVNETA=y From 545591132aa701ff1262bb309fbcd0c3ff0acd75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Wed, 19 Aug 2020 11:57:25 +0200 Subject: [PATCH 03/14] arm64: dts: armada-3720-espressobin: fix COMPHY nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes initialization of COMPHY on EspressoBin. Commit 22f418935be4 ("phy: marvell: a3700: Use comphy_mux on Armada 37xx.") introduced usage of comphy_mux on Armada 37xx comphy driver. The lanes are defined in comphy_a3700.c as described in functional specification, that is: lane 0 is SGMII1 or USB3 lane 1 is PCIe or SGMII0 lane 2 is SATA or USB3 But the DTS for EspressoBin configures PCIe on lane 0 and USB3 on lane 1, which is wrong in the sense of the specification and doesn't work with the comphy_mux code, which is 2 years now (the aardvark driver causes synchronous abort in U-Boot). It worked till the above mentioned commit, because the code for powering up PCIe PHY doesn't work with lane number at all, and the code for powering up USB3 PHY works differently only if USB3 is on lane 2, ie. the check goes like: if (lane == 2) something else something else so it does not differentiate between lanes 0 and 1. In the future I shall post patches that remove the comphy_a3700 driver and add comphy driver which uses calls to ATF, like Linux' driver does. This will have the advantage of same DTS bindings as Linux', but till this is done, we need this patch. Signed-off-by: Marek Behún Tested-by: Pali Rohár Cc: Stefan Roese Reviewed-by: Stefan Roese Tested-by: Andre Heider --- arch/arm/dts/armada-3720-espressobin.dts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index 84e2c2adba..50381e979e 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -72,13 +72,13 @@ &comphy { max-lanes = <3>; phy0 { - phy-type = ; - phy-speed = ; + phy-type = ; + phy-speed = ; }; phy1 { - phy-type = ; - phy-speed = ; + phy-type = ; + phy-speed = ; }; phy2 { From 563b85bd88772c8949d10f7fa8e39a20280b1aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 19 Aug 2020 15:57:06 +0200 Subject: [PATCH 04/14] arm64: a37xx: pci: Make PCIe Reset GPIO DT compatible with Linux kernel DT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change active-high to active-low and change DT property name from reset-gpio to reset-gpios. This format of gpio reset is used by pci-aardvark driver in Linux kernel. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Reviewed-by: Konstantin Porotchkin Tested-by: Andre Heider --- arch/arm/dts/armada-3720-db.dts | 2 +- arch/arm/dts/armada-3720-espressobin.dts | 2 +- arch/arm/dts/armada-3720-turris-mox.dts | 2 +- drivers/pci/pci-aardvark.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm/dts/armada-3720-db.dts b/arch/arm/dts/armada-3720-db.dts index 1b219c423b..1b1b66b94d 100644 --- a/arch/arm/dts/armada-3720-db.dts +++ b/arch/arm/dts/armada-3720-db.dts @@ -159,6 +159,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay"; }; diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index 50381e979e..2ace52e812 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -145,6 +145,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay"; }; diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index 0f0a6ce65d..974270cc8c 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -172,6 +172,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "disabled"; }; diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 711b930d0f..5b3f23c184 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -616,7 +616,7 @@ static int pcie_advk_probe(struct udevice *dev) #if CONFIG_IS_ENABLED(DM_GPIO) struct gpio_desc reset_gpio; - gpio_request_by_name(dev, "reset-gpio", 0, &reset_gpio, + gpio_request_by_name(dev, "reset-gpios", 0, &reset_gpio, GPIOD_IS_OUT); /* * Issue reset to add-in card through the dedicated GPIO. @@ -633,9 +633,9 @@ static int pcie_advk_probe(struct udevice *dev) */ if (dm_gpio_is_valid(&reset_gpio)) { dev_dbg(pcie->dev, "Toggle PCIE Reset GPIO ...\n"); - dm_gpio_set_value(&reset_gpio, 0); - mdelay(200); dm_gpio_set_value(&reset_gpio, 1); + mdelay(200); + dm_gpio_set_value(&reset_gpio, 0); } #else dev_dbg(pcie->dev, "PCIE Reset on GPIO support is missing\n"); From 828d32621686aec593076d16445d39b9b8d49c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 19 Aug 2020 15:57:07 +0200 Subject: [PATCH 05/14] arm64: a37xx: pci: Assert PERST# signal when unloading driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that PCIe card is put into reset state when U-Boot stops using it. DM_FLAG_OS_PREPARE ensures that U-Boot executes driver's remove callback prior booting Linux kernel. Linux kernel pci-aardvark driver needs to reset PCIe card via PERST# signal prior initializing it. If it does not issue reset then some PCIe cards (specially Compex WiFi cards) are not detected at all. Putting PCIe card into reset state prior booting Linux kernel would ensure that card would be properly reset at time when Linux kernel starts initializing pci-aardvark driver. Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Tested-by: Andre Heider --- drivers/pci/pci-aardvark.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 5b3f23c184..8996be5309 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -148,6 +148,9 @@ struct pcie_advk { void *base; int first_busno; struct udevice *dev; +#if CONFIG_IS_ENABLED(DM_GPIO) + struct gpio_desc reset_gpio; +#endif }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -614,9 +617,7 @@ static int pcie_advk_probe(struct udevice *dev) struct pcie_advk *pcie = dev_get_priv(dev); #if CONFIG_IS_ENABLED(DM_GPIO) - struct gpio_desc reset_gpio; - - gpio_request_by_name(dev, "reset-gpios", 0, &reset_gpio, + gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT); /* * Issue reset to add-in card through the dedicated GPIO. @@ -631,11 +632,11 @@ static int pcie_advk_probe(struct udevice *dev) * possible before PCIe PHY initialization. Moreover, the PCIe * clock should be gated as well. */ - if (dm_gpio_is_valid(&reset_gpio)) { + if (dm_gpio_is_valid(&pcie->reset_gpio)) { dev_dbg(pcie->dev, "Toggle PCIE Reset GPIO ...\n"); - dm_gpio_set_value(&reset_gpio, 1); + dm_gpio_set_value(&pcie->reset_gpio, 1); mdelay(200); - dm_gpio_set_value(&reset_gpio, 0); + dm_gpio_set_value(&pcie->reset_gpio, 0); } #else dev_dbg(pcie->dev, "PCIE Reset on GPIO support is missing\n"); @@ -647,6 +648,18 @@ static int pcie_advk_probe(struct udevice *dev) return pcie_advk_setup_hw(pcie); } +static int pcie_advk_remove(struct udevice *dev) +{ +#if CONFIG_IS_ENABLED(DM_GPIO) + struct pcie_advk *pcie = dev_get_priv(dev); + + if (dm_gpio_is_valid(&pcie->reset_gpio)) + dm_gpio_set_value(&pcie->reset_gpio, 1); +#endif /* DM_GPIO */ + + return 0; +} + /** * pcie_advk_ofdata_to_platdata() - Translate from DT to device state * @@ -687,5 +700,7 @@ U_BOOT_DRIVER(pcie_advk) = { .ops = &pcie_advk_ops, .ofdata_to_platdata = pcie_advk_ofdata_to_platdata, .probe = pcie_advk_probe, + .remove = pcie_advk_remove, + .flags = DM_FLAG_OS_PREPARE, .priv_auto_alloc_size = sizeof(struct pcie_advk), }; From 91b85e25b610db0d3bdfc5e91df451f07bc9c851 Mon Sep 17 00:00:00 2001 From: Evan Wang Date: Wed, 19 Aug 2020 16:19:39 +0200 Subject: [PATCH 06/14] mmc: xenon: set signal voltage and max base clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The SDIO signal voltage and max base clock frequency setting are missing in driver, which causes SDIO not working. - The patch adds SDIO signal voltage switch support, which is based on regulator-gpio of vqmmc-supply, and sets the max base clock frequency. - Fix the zero clock value in call to sdhci_setup_cfg() function. Change-Id: I79c8860c65b8db166f4f70db56ede4097f71f1fa Signed-off-by: Evan Wang Reviewed-on: http://vgitil04.il.marvell.com:8080/53589 Reviewed-by: Hua Jing Tested-by: Hua Jing [pali: Amended fixup patch] Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Reviewed-by: Stefan Roese Tested-by: Andre Heider --- drivers/mmc/xenon_sdhci.c | 79 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/xenon_sdhci.c b/drivers/mmc/xenon_sdhci.c index 356dd9846d..7f9a579c83 100644 --- a/drivers/mmc/xenon_sdhci.c +++ b/drivers/mmc/xenon_sdhci.c @@ -22,6 +22,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -42,6 +43,14 @@ DECLARE_GLOBAL_DATA_PTR; #define SDHC_SYS_EXT_OP_CTRL 0x010C #define MASK_CMD_CONFLICT_ERROR BIT(8) +#define SDHC_SLOT_EMMC_CTRL 0x0130 +#define ENABLE_DATA_STROBE_SHIFT 24 +#define SET_EMMC_RSTN_SHIFT 16 +#define EMMC_VCCQ_MASK 0x3 +#define EMMC_VCCQ_1_8V 0x1 +#define EMMC_VCCQ_1_2V 0x2 +#define EMMC_VCCQ_3_3V 0x3 + #define SDHC_SLOT_RETUNING_REQ_CTRL 0x0144 /* retuning compatible */ #define RETUNING_COMPATIBLE 0x1 @@ -108,6 +117,8 @@ DECLARE_GLOBAL_DATA_PTR; #define MMC_TIMING_MMC_HS400 10 #define XENON_MMC_MAX_CLK 400000000 +#define XENON_MMC_3V3_UV 3300000 +#define XENON_MMC_1V8_UV 1800000 enum soc_pad_ctrl_type { SOC_PAD_SD, @@ -128,6 +139,8 @@ struct xenon_sdhci_priv { void *pad_ctrl_reg; int pad_type; + + struct udevice *vqmmc; }; static int xenon_mmc_phy_init(struct sdhci_host *host) @@ -208,6 +221,51 @@ static void armada_3700_soc_pad_voltage_set(struct sdhci_host *host) writel(ARMADA_3700_SOC_PAD_3_3V, priv->pad_ctrl_reg); } +static int xenon_mmc_start_signal_voltage_switch(struct sdhci_host *host) +{ + struct xenon_sdhci_priv *priv = host->mmc->priv; + u8 voltage; + u32 ctrl; + int ret = 0; + + /* If there is no vqmmc regulator, return */ + if (!priv->vqmmc) + return 0; + + if (priv->pad_type == SOC_PAD_FIXED_1_8V) { + /* Switch to 1.8v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_1V8_UV); + } else if (priv->pad_type == SOC_PAD_SD) { + /* Get voltage info */ + voltage = sdhci_readb(host, SDHCI_POWER_CONTROL); + voltage &= ~SDHCI_POWER_ON; + + if (voltage == SDHCI_POWER_330) { + /* Switch to 3.3v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_3V3_UV); + } else { + /* Switch to 1.8v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_1V8_UV); + } + } + + /* Set VCCQ, eMMC mode: 1.8V; SD/SDIO mode: 3.3V */ + ctrl = sdhci_readl(host, SDHC_SLOT_EMMC_CTRL); + if (IS_SD(host->mmc)) + ctrl |= EMMC_VCCQ_3_3V; + else + ctrl |= EMMC_VCCQ_1_8V; + sdhci_writel(host, ctrl, SDHC_SLOT_EMMC_CTRL); + + if (ret) + printf("Signal voltage switch fail\n"); + + return ret; +} + static void xenon_mmc_phy_set(struct sdhci_host *host) { struct xenon_sdhci_priv *priv = host->mmc->priv; @@ -334,6 +392,13 @@ static int xenon_sdhci_set_ios_post(struct sdhci_host *host) uint speed = host->mmc->tran_speed; int pwr_18v = 0; + /* + * Signal Voltage Switching is only applicable for Host Controllers + * v3.00 and above. + */ + if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) + xenon_mmc_start_signal_voltage_switch(host); + if ((sdhci_readb(host, SDHCI_POWER_CONTROL) & ~SDHCI_POWER_ON) == SDHCI_POWER_180) pwr_18v = 1; @@ -394,6 +459,18 @@ static int xenon_sdhci_probe(struct udevice *dev) /* Set default timing */ priv->timing = MMC_TIMING_LEGACY; + /* Get the vqmmc regulator if there is */ + device_get_supply_regulator(dev, "vqmmc-supply", &priv->vqmmc); + /* Set the initial voltage value to 3.3V if there is regulator */ + if (priv->vqmmc) { + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_3V3_UV); + if (ret) { + printf("Failed to set VQMMC regulator to 3.3V\n"); + return ret; + } + } + /* Disable auto clock gating during init */ xenon_mmc_set_acg(host, false); @@ -426,7 +503,7 @@ static int xenon_sdhci_probe(struct udevice *dev) host->ops = &xenon_sdhci_ops; host->max_clk = XENON_MMC_MAX_CLK; - ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); + ret = sdhci_setup_cfg(&plat->cfg, host, XENON_MMC_MAX_CLK, 0); if (ret) return ret; From 96fa3c4fda5cad85b05b086bed3855d4037d1639 Mon Sep 17 00:00:00 2001 From: Wilson Ding Date: Wed, 19 Aug 2020 16:19:40 +0200 Subject: [PATCH 07/14] arm: dts: a37x0: enable sd card support on espressobin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enabled SDIO slot 0 (south bridge) for SD card on Espressobin board. Change-Id: I51a2debf9fba276b9c4a2bc6da91328d47f443e3 Signed-off-by: Wilson Ding Signed-off-by: Konstantin Porotchkin Reviewed-on: http://vgitil04.il.marvell.com:8080/60945 Tested-by: iSoC Platform CI Reviewed-by: Igal Liberman [pali: Define cd-gpios and enable CONFIG_DM_REGULATOR_GPIO] Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Reviewed-by: Stefan Roese Tested-by: Andre Heider --- arch/arm/dts/armada-3720-espressobin.dts | 20 ++++++++++++++++++++ configs/mvebu_espressobin-88f3720_defconfig | 1 + 2 files changed, 21 insertions(+) diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index 2ace52e812..4534f5ff29 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -67,6 +67,17 @@ device_type = "memory"; reg = <0x00000000 0x00000000 0x00000000 0x20000000>; }; + + vcc_sd_reg0: regulator@0 { + compatible = "regulator-gpio"; + regulator-name = "vcc_sd0"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3300000>; + regulator-type = "voltage"; + states = <1800000 0x1 + 3300000 0x0>; + gpios = <&gpionb 4 GPIO_ACTIVE_HIGH>; + }; }; &comphy { @@ -110,6 +121,15 @@ status = "okay"; }; +&sdhci0 { + pinctrl-names = "default"; + pinctrl-0 = <&sdio_pins>; + bus-width = <4>; + cd-gpios = <&gpionb 3 GPIO_ACTIVE_LOW>; + vqmmc-supply = <&vcc_sd_reg0>; + status = "okay"; +}; + &spi0 { status = "okay"; pinctrl-names = "default"; diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 495faf43a3..933592af88 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -81,3 +81,4 @@ CONFIG_USB_ETHER_SMSC95XX=y CONFIG_SHA1=y CONFIG_SHA256=y CONFIG_MVNETA=y +CONFIG_DM_REGULATOR_GPIO=y From 4366082bfee345d2ca9f8ca7a27e70b6e30efd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 19 Aug 2020 16:24:16 +0200 Subject: [PATCH 08/14] arm: mvebu: Espressobin: Make SPI env offset compatible with Marvell's U-Boot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Espressobin board comes with Marvell's U-Boot version where U-Boot env is stored in SPI at offset 0x3F0000. This patch changes env offset in Espressobin defconfig file to match Marvell's U-Boot version. Users who want to use previous or different env offset can still change it in .config file when compiling U-Boot. Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Reviewed-by: Stefan Roese Tested-by: Andre Heider --- configs/mvebu_espressobin-88f3720_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 933592af88..afcdd947c1 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -6,7 +6,7 @@ CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_NR_DRAM_BANKS=1 CONFIG_TARGET_MVEBU_ARMADA_37XX=y CONFIG_ENV_SIZE=0x10000 -CONFIG_ENV_OFFSET=0x180000 +CONFIG_ENV_OFFSET=0x3F0000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEBUG_UART_BASE=0xd0012000 From a65e65939eaee611c86c96bee4556f552f5b42a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 19 Aug 2020 16:24:17 +0200 Subject: [PATCH 09/14] arm: mvebu: Espressobin: Setup MTD partitions when booting kernel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to different partition layouts in different U-Boot versions, DTS for Espressobin in Linux does not contain any definition of MTD partitions. See commit https://git.kernel.org/stable/c/00954566464a4 for more details. This patch via ft_board_setup() hook fills current partition layout used by U-Boot, so booted kernel would see correct MTD partitions layout. U-Boot env partition is calculated from CONFIG_ENV_OFFSET option. First partition contains secure firmware, ARM trusted firmware and U-Boot with checksums. So it is not possible to replace just one image (e.g. U-Boot) without updating other parts where is stored checksum of U-Boot. Therefore there is no extra partition defined for U-Boot and first partition is called just 'firmware'. Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Tested-by: Andre Heider --- board/Marvell/mvebu_armada-37xx/board.c | 100 ++++++++++++++++++++ configs/mvebu_espressobin-88f3720_defconfig | 1 + 2 files changed, 101 insertions(+) diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 031de318c6..7b9c3223ed 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -243,3 +243,103 @@ int board_network_enable(struct mii_dev *bus) return 0; } + +#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_ENV_IS_IN_SPI_FLASH) +int ft_board_setup(void *blob, struct bd_info *bd) +{ + int ret; + int spi_off; + int parts_off; + int part_off; + + /* Fill SPI MTD partitions for Linux kernel on Espressobin */ + if (!of_machine_is_compatible("marvell,armada-3720-espressobin")) + return 0; + + spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor"); + if (spi_off < 0) + return 0; + + /* Do not touch partitions if they are already defined */ + if (fdt_subnode_offset(blob, spi_off, "partitions") >= 0) + return 0; + + parts_off = fdt_add_subnode(blob, spi_off, "partitions"); + if (parts_off < 0) { + printf("Can't add partitions node: %s\n", fdt_strerror(parts_off)); + return 0; + } + + ret = fdt_setprop_string(blob, parts_off, "compatible", "fixed-partitions"); + if (ret < 0) { + printf("Can't set compatible property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_u32(blob, parts_off, "#address-cells", 1); + if (ret < 0) { + printf("Can't set #address-cells property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_u32(blob, parts_off, "#size-cells", 1); + if (ret < 0) { + printf("Can't set #size-cells property: %s\n", fdt_strerror(ret)); + return 0; + } + + /* Add u-boot-env partition */ + + part_off = fdt_add_subnode(blob, parts_off, "partition@u-boot-env"); + if (part_off < 0) { + printf("Can't add partition@u-boot-env node: %s\n", fdt_strerror(part_off)); + return 0; + } + + ret = fdt_setprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); + if (ret < 0) { + printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_SIZE); + if (ret < 0) { + printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_string(blob, part_off, "label", "u-boot-env"); + if (ret < 0) { + printf("Can't set partition@u-boot-env label property: %s\n", fdt_strerror(ret)); + return 0; + } + + /* Add firmware partition */ + + part_off = fdt_add_subnode(blob, parts_off, "partition@firmware"); + if (part_off < 0) { + printf("Can't add partition@firmware node: %s\n", fdt_strerror(part_off)); + return 0; + } + + ret = fdt_setprop_u32(blob, part_off, "reg", 0); + if (ret < 0) { + printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); + if (ret < 0) { + printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_string(blob, part_off, "label", "firmware"); + if (ret < 0) { + printf("Can't set partition@firmware label property: %s\n", fdt_strerror(ret)); + return 0; + } + + return 0; +} +#endif diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index afcdd947c1..0c1c92d4ff 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -82,3 +82,4 @@ CONFIG_SHA1=y CONFIG_SHA256=y CONFIG_MVNETA=y CONFIG_DM_REGULATOR_GPIO=y +CONFIG_OF_BOARD_SETUP=y From 835d969c1f67f9a7be811c3811c6ec0b68ef79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Tue, 25 Aug 2020 10:45:04 +0200 Subject: [PATCH 10/14] arm64: a37xx: pci: Depends on DM_GPIO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For proper initialization of aardvark pci driver it is required to de-assert reset GPIO. So depeneds on DM_GPIO option. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Tested-by: Andre Heider --- drivers/pci/Kconfig | 1 + drivers/pci/pci-aardvark.c | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index c19d09bc41..dd1cc65229 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -30,6 +30,7 @@ config PCI_AARDVARK bool "Enable Aardvark PCIe driver" default n depends on DM_PCI + depends on DM_GPIO depends on ARMADA_3700 help Say Y here if you want to enable PCIe controller support on diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 8996be5309..b2c417701f 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -148,9 +148,7 @@ struct pcie_advk { void *base; int first_busno; struct udevice *dev; -#if CONFIG_IS_ENABLED(DM_GPIO) struct gpio_desc reset_gpio; -#endif }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -616,7 +614,6 @@ static int pcie_advk_probe(struct udevice *dev) { struct pcie_advk *pcie = dev_get_priv(dev); -#if CONFIG_IS_ENABLED(DM_GPIO) gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT); /* @@ -637,10 +634,9 @@ static int pcie_advk_probe(struct udevice *dev) dm_gpio_set_value(&pcie->reset_gpio, 1); mdelay(200); dm_gpio_set_value(&pcie->reset_gpio, 0); + } else { + dev_warn(pcie->dev, "PCIE Reset on GPIO support is missing\n"); } -#else - dev_dbg(pcie->dev, "PCIE Reset on GPIO support is missing\n"); -#endif /* DM_GPIO */ pcie->first_busno = dev->seq; pcie->dev = pci_get_controller(dev); @@ -650,12 +646,10 @@ static int pcie_advk_probe(struct udevice *dev) static int pcie_advk_remove(struct udevice *dev) { -#if CONFIG_IS_ENABLED(DM_GPIO) struct pcie_advk *pcie = dev_get_priv(dev); if (dm_gpio_is_valid(&pcie->reset_gpio)) dm_gpio_set_value(&pcie->reset_gpio, 1); -#endif /* DM_GPIO */ return 0; } From bb40fe1f6ce20f818306d34e17b1bb829f00cb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 27 Aug 2020 15:01:25 +0200 Subject: [PATCH 11/14] arm: mvebu: Espressobin: Move env load addresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to Marvell's U-Boot description [1] current env load addresses overlaps with ATF RT services region and TEE. Because the ATF RT service and TEE region is going to be marked as secure and can't be overwritten, use different different addresses for envs. [1] - https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/commit/0a5b159806baa0746b6449920e450498bc269ba7 Signed-off-by: Pali Rohár Tested-by: Andre Heider Reviewed-by: Stefan Roese --- include/configs/mvebu_armada-37xx.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index ca662b0ce7..a9ed0a838f 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -91,11 +91,11 @@ #include #define CONFIG_EXTRA_ENV_SETTINGS \ - "scriptaddr=0x4d00000\0" \ - "pxefile_addr_r=0x4e00000\0" \ - "fdt_addr_r=0x4f00000\0" \ - "kernel_addr_r=0x5000000\0" \ - "ramdisk_addr_r=0x8000000\0" \ + "scriptaddr=0x6d00000\0" \ + "pxefile_addr_r=0x6e00000\0" \ + "fdt_addr_r=0x6f00000\0" \ + "kernel_addr_r=0x7000000\0" \ + "ramdisk_addr_r=0xa000000\0" \ BOOTENV #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */ From 996ecfd3ec4e86be9dbee17b2223061e16627f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 27 Aug 2020 15:01:26 +0200 Subject: [PATCH 12/14] arm: mvebu: Espressobin: Change default loadaddr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current loadaddr is not writable on Espressobin and 'loadb' command cause rebooting board. Marvell's U-Boot already set default loadaddr to value 0x06000000 [1] and after this change 'loadb' is working fine. [1] - https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/commit/0a5b159806baa0746b6449920e450498bc269ba7 Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Tested-by: Andre Heider --- include/configs/mvebu_armada-37xx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index a9ed0a838f..93c05e30cc 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -37,7 +37,7 @@ /* * Other required minimal configurations */ -#define CONFIG_SYS_LOAD_ADDR 0x00800000 /* default load adr- 8M */ +#define CONFIG_SYS_LOAD_ADDR 0x06000000 /* default load adr */ #define CONFIG_SYS_RESET_ADDRESS 0xffff0000 /* Rst Vector Adr */ #define CONFIG_SYS_MAXARGS 32 /* max number of command args */ From 6b610662106eafef516875198c30795f584536c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 27 Aug 2020 15:01:27 +0200 Subject: [PATCH 13/14] arm: mvebu: Espressobin: Define fdt_addr and kernel_addr env aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Boot scripts for existing Espressobin Linux distributions, like OpenWRT, expect that U-Boot set fdt_addr and kernel_addr envs. So add env aliases from fdt_addr_r and kernel_addr_r values. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Tested-by: Andre Heider --- include/configs/mvebu_armada-37xx.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index 93c05e30cc..905ce09b7a 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -90,10 +90,13 @@ #include +/* fdt_addr and kernel_addr are needed for existing distribution boot scripts */ #define CONFIG_EXTRA_ENV_SETTINGS \ "scriptaddr=0x6d00000\0" \ "pxefile_addr_r=0x6e00000\0" \ + "fdt_addr=0x6f00000\0" \ "fdt_addr_r=0x6f00000\0" \ + "kernel_addr=0x7000000\0" \ "kernel_addr_r=0x7000000\0" \ "ramdisk_addr_r=0xa000000\0" \ BOOTENV From 64430efe6960bee0d0a392c0391d815a70a1805d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 27 Aug 2020 15:01:28 +0200 Subject: [PATCH 14/14] arm: mvebu: Espressobin: Update README.marvell file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include information about permanent ethernet MAC address and add link how to build ATF as U-Boot on Espressobin cannot be flashed without ATF. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- doc/README.marvell | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/README.marvell b/doc/README.marvell index 336461745c..5416bc3035 100644 --- a/doc/README.marvell +++ b/doc/README.marvell @@ -13,7 +13,8 @@ Build Procedure 2. Set the cross compiler: - # export CROSS_COMPILE=/path/to/toolchain/aarch64-marvell-linux-gnu- + # sudo apt-get install gcc-aarch64-linux-gnu + # export CROSS_COMPILE=aarch64-linux-gnu- 3. Clean-up old residuals: @@ -30,7 +31,7 @@ Build Procedure 5. Configure the device-tree and build the U-Boot image: - Compile u-boot and set the required device-tree using: + For the Armada-70x0/80x0 DB board compile u-boot and set the required device-tree using: # make DEVICE_TREE= @@ -42,12 +43,45 @@ Build Procedure In order to prevent this, the required device-tree MUST be set during compilation. All device-tree files are located in ./arch/arm/dts/ folder. + For other DB boards (MacchiatoBin, EspressoBin and 3700 DB board) compile u-boot with + just default device-tree from defconfig using: + + # make + NOTE: The u-boot.bin should not be used as a stand-alone image. The ARM Trusted Firmware (ATF) build process uses this image to generate the - flash image. + flash image. See TF-A Build Instructions for Marvell Platforms for more details at: + https://trustedfirmware-a.readthedocs.io/en/latest/plat/marvell/armada/build.html Configuration update --------------------- To update the U-Boot configuration, please refer to doc/README.kconfig + +Permanent ethernet MAC address +------------------------------- + Prior flashing new U-Boot version (as part of ATF image) it is suggested to backup + permanent ethernet MAC address as it is stored only in U-Boot env storage (SPI or eMMC). + Some boards like EspressoBin have MAC address printed on sticker. To print current MAC + address run: + + # echo $ethaddr + + MAC addresses 00:51:82:11:22:00, 00:51:82:11:22:01, 00:51:82:11:22:02, 00:51:82:11:22:03 + and F0:AD:4E:03:64:7F are default hardcoded values found in Marvell's and Armbian U-Boot + forks and therefore *not* unique. Usage of static hardcoded MAC addresses should be avoided. + When original address is lost (e.g. erased by Armbian boot scripts for EspressoBin) it is + suggested to generate new random one. + + After flashing new U-Boot version it is suggested to reset U-Boot env variables to default + and then set correct permanent ethernet MAC address. + + # env default -a + # setenv ethaddr XX:XX:XX:XX:XX:XX + # saveenv + + Where XX:XX:XX:XX:XX:XX is permanent ethernet MAC address. + + Recent Linux kernel versions use correct permanent ethernet MAC address from U-Boot env as + U-Boot will inject it into kernel's device-tree.