From ee48f53722b092618bab6597e92073a97de227f4 Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Wed, 30 Jun 2021 21:26:22 -0700 Subject: [PATCH 01/10] arm: kirkwood: NSA310S: Add device tree DTS for Zyxel NSA310S board Add device tree kirkwood-nsa310s.dts for Zyxel NSA310S board to convert to Driver Model. Signed-off-by: Tony Dinh Reviewed-by: Stefan Roese --- arch/arm/dts/Makefile | 1 + arch/arm/dts/kirkwood-nsa310s.dts | 318 ++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 arch/arm/dts/kirkwood-nsa310s.dts diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 90e3004dbe..3941a08cf4 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -56,6 +56,7 @@ dtb-$(CONFIG_ARCH_KIRKWOOD) += \ kirkwood-ns2lite.dtb \ kirkwood-ns2max.dtb \ kirkwood-ns2mini.dtb \ + kirkwood-nsa310s.dtb \ kirkwood-openrd-base.dtb \ kirkwood-openrd-client.dtb \ kirkwood-openrd-ultimate.dtb \ diff --git a/arch/arm/dts/kirkwood-nsa310s.dts b/arch/arm/dts/kirkwood-nsa310s.dts new file mode 100644 index 0000000000..e1c9c9080c --- /dev/null +++ b/arch/arm/dts/kirkwood-nsa310s.dts @@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Device tree file for the Zyxel NSA 310S NAS box. + * + * Copyright (c) 2015-2021, Tony Dinh + * + * Based on + * Copyright (c) 2014, Adam Baker + * Based upon the board setup file created by Peter Schildmann + */ +/dts-v1/; + +#include "kirkwood.dtsi" +#include "kirkwood-6281.dtsi" + +/ { + model = "Zyxel NSA310S"; + compatible = "zyxel,nsa320s", "marvell,kirkwood-88f6702", "marvell,kirkwood"; + + memory { + device_type = "memory"; + reg = <0x00000000 0x10000000>; + }; + + chosen { + bootargs = "console=ttyS0,115200"; + stdout-path = &uart0; + }; + + ocp@f1000000 { + pinctrl: pin-controller@10000 { + pinctrl-names = "default"; + + pmx_sata0: pmx-sata0 { + marvell,pins ; + marvell,function = "sata0"; + }; + + pmx_sata1: pmx-sata1 { + marvell,pins ; + marvell,function = "sata1"; + }; + + pmx_usb_power: pmx-usb-power { + marvell,pins = "mpp21"; + marvell,function = "gpio"; + }; + + pmx_pwr_off: pmx-pwr-off { + marvell,pins = "mpp27"; + marvell,function = "gpio"; + }; + + pmx_btn_reset: pmx-btn-reset { + marvell,pins = "mpp24"; + marvell,function = "gpio"; + }; + + pmx_btn_copy: pmx-btn-copy { + marvell,pins = "mpp25"; + marvell,function = "gpio"; + }; + + pmx_btn_power: pmx-btn-power { + marvell,pins = "mpp26"; + marvell,function = "gpio"; + }; + + pmx_led_hdd2_green: pmx-led-hdd2-green { + marvell,pins = "mpp34"; + marvell,function = "gpio"; + }; + + pmx_led_hdd2_red: pmx-led-hdd2-red { + marvell,pins = "mpp12"; + marvell,function = "gpio"; + }; + + pmx_led_usb_green: pmx-led-usb-green { + marvell,pins = "mpp15"; + marvell,function = "gpio"; + }; + + pmx_led_copy_green: pmx-led-copy-green { + marvell,pins = "mpp22"; + marvell,function = "gpio"; + }; + + pmx_led_copy_red: pmx-led-copy-red { + marvell,pins = "mpp23"; + marvell,function = "gpio"; + }; + + pmx_led_sys_green: pmx-led-sys-green { + marvell,pins = "mpp28"; + marvell,function = "gpio"; + }; + + pmx_led_sys_orange: pmx-led-sys-orange { + marvell,pins = "mpp29"; + marvell,function = "gpio"; + }; + + pmx_led_hdd1_green: pmx-led-hdd1-green { + marvell,pins = "mpp16"; + marvell,function = "gpio"; + }; + + pmx_led_hdd1_red: pmx-led-hdd1-red { + marvell,pins = "mpp13"; + marvell,function = "gpio"; + }; + + pmx_pwr_sata1: pmx-pwr-sata1 { + marvell,pins = "mpp33"; + marvell,function = "gpio"; + }; + }; + + serial@12000 { + status = "ok"; + }; + + sata@80000 { + status = "okay"; + nr-ports = <1>; + }; + + rtc@10300 { + status = "disabled"; + }; + + i2c@11000 { + status = "okay"; + ht1382: rtc@68 { + compatible = "htk,ht1382"; + reg = <0x68>; + }; + }; + }; + + regulators { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&pmx_usb_power &pmx_pwr_sata1>; + + usb0_power: regulator@1 { + compatible = "regulator-fixed"; + reg = <1>; + regulator-name = "USB Power"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + regulator-always-on; + regulator-boot-on; + enable-active-high; + gpio = <&gpio0 21 GPIO_ACTIVE_HIGH>; + }; + + sata1_power: regulator@2 { + compatible = "regulator-fixed"; + reg = <2>; + regulator-name = "SATA1 Power"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + regulator-always-on; + regulator-boot-on; + enable-active-high; + gpio = <&gpio1 1 GPIO_ACTIVE_HIGH>; + }; + }; + + gpio_poweroff { + compatible = "gpio-poweroff"; + pinctrl-0 = <&pmx_pwr_off>; + pinctrl-names = "default"; + gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>; + }; + + gpio_keys { + compatible = "gpio-keys"; + #address-cells = <1>; + #size-cells = <0>; + pinctrl-0 = <&pmx_btn_reset &pmx_btn_copy &pmx_btn_power>; + pinctrl-names = "default"; + + button@1 { + label = "Power Button"; + linux,code = ; + gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>; + }; + button@2 { + label = "Copy Button"; + linux,code = ; + gpios = <&gpio0 25 GPIO_ACTIVE_LOW>; + }; + button@3 { + label = "Reset Button"; + linux,code = ; + gpios = <&gpio0 24 GPIO_ACTIVE_LOW>; + }; + }; + + gpio-leds { + compatible = "gpio-leds"; + pinctrl-0 = <&pmx_led_hdd2_green &pmx_led_hdd2_red + &pmx_led_usb_green + &pmx_led_sys_green &pmx_led_sys_orange + &pmx_led_copy_green &pmx_led_copy_red + &pmx_led_hdd1_green &pmx_led_hdd1_red>; + pinctrl-names = "default"; + + green-sys { + label = "nsa310s:green:sys"; + gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "default-on"; + }; + orange-sys { + label = "nsa310s:orange:sys"; + gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; + }; + green-hdd1 { + label = "nsa310s:green:hdd1"; + gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>; + }; + red-hdd1 { + label = "nsa310s:red:hdd1"; + gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>; + }; + green-hdd2 { + label = "nsa310s:green:hdd2"; + gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; + }; + red-hdd2 { + label = "nsa310s:red:hdd2"; + gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; + }; + green-usb { + label = "nsa310s:green:usb"; + gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>; + }; + green-copy { + label = "nsa310s:green:copy"; + gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "ide-disk"; + }; + red-copy { + label = "nsa310s:red:copy"; + gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; + }; + }; +}; + +&nand { + status = "okay"; + chip-delay = <35>; + + partition@0 { + label = "uboot"; + reg = <0x0000000 0x0100000>; + }; + partition@100000 { + label = "stock_uboot_env"; + reg = <0x0100000 0x0080000>; + }; + partition@180000 { + label = "key_store"; + reg = <0x0180000 0x0080000>; + }; + partition@200000 { + label = "info"; + reg = <0x0200000 0x0080000>; + }; + partition@280000 { + label = "etc"; + reg = <0x0280000 0x0a00000>; + }; + partition@c80000 { + label = "kernel_1"; + reg = <0x0c80000 0x0a00000>; + }; + partition@1680000 { + label = "rootfs1"; + reg = <0x1680000 0x2fc0000>; + }; + partition@4640000 { + label = "kernel_2"; + reg = <0x4640000 0x0a00000>; + }; + partition@5040000 { + label = "rootfs2"; + reg = <0x5040000 0x2fc0000>; + }; +}; + +&mdio { + status = "okay"; + ethphy0: ethernet-phy@1 { + compatible = "marvell,88e1510"; + reg = <1>; + }; +}; + +ð0 { + status = "okay"; + ethernet0-port@0 { + phy-handle = <ðphy0>; + }; +}; + +&pciec { + status = "okay"; +}; + +&pcie0 { + status = "okay"; +}; From 2fd89bd3b141a5c487eaa0a5352c382c9d8a0c0d Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Wed, 30 Jun 2021 21:26:23 -0700 Subject: [PATCH 02/10] arm: kirkwood: NSA310S: Add DM USB, DM Ethernet, and DM SATA configs Convert to Driver Model. - Add DM USB, DM Ethernet, and DM SATA configs to nsa310s_defconfig - Add CONFIG_DEFAULT_DEVICE_TREE to nsa310s_defconfig - Move CONFIG_ENV_SECT_SIZE from board file to nsa310s_defconfig - Add CONFIG_IDENT_STRING, and CONFIG_NET_RANDOM_ETHADDR to nsa310s_defconfig Signed-off-by: Tony Dinh Reviewed-by: Stefan Roese --- configs/nsa310s_defconfig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/configs/nsa310s_defconfig b/configs/nsa310s_defconfig index e4cf1c470e..fac0322e2b 100644 --- a/configs/nsa310s_defconfig +++ b/configs/nsa310s_defconfig @@ -7,14 +7,16 @@ CONFIG_NR_DRAM_BANKS=2 CONFIG_TARGET_NSA310S=y CONFIG_ENV_SIZE=0x20000 CONFIG_ENV_OFFSET=0xE0000 +CONFIG_ENV_SECT_SIZE=0x20000 +CONFIG_DEFAULT_DEVICE_TREE="kirkwood-nsa310s" CONFIG_BOOTDELAY=3 CONFIG_USE_PREBOOT=y # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="nsa310s => " +CONFIG_IDENT_STRING="\nZyXEL NSA310S/320S 1/2-Bay Power Media Server" CONFIG_CMD_BOOTZ=y # CONFIG_CMD_FLASH is not set -CONFIG_CMD_IDE=y CONFIG_CMD_NAND=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set @@ -44,3 +46,11 @@ CONFIG_USB_STORAGE=y CONFIG_LZMA=y CONFIG_BZIP2=y CONFIG_OF_LIBFDT=y +CONFIG_DM=y +CONFIG_BLK=y +CONFIG_OF_CONTROL=y +CONFIG_DM_USB=y +CONFIG_DM_ETH=y +CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_CMD_SATA=y +CONFIG_SATA_MV=y From 3a2f2983357546ccc70b948de95dd3072c02a35a Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Fri, 2 Jul 2021 20:08:14 -0700 Subject: [PATCH 03/10] arm: kirkwood: NSA310S: Add DM SATA configs Enable DM SATA, removed IDE driver, and add SATA MV driver. Signed-off-by: Tony Dinh --- include/configs/nsa310s.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/configs/nsa310s.h b/include/configs/nsa310s.h index e38c65a485..23cf94ec99 100644 --- a/include/configs/nsa310s.h +++ b/include/configs/nsa310s.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* + * Copyright (C) 2015, 2021 Tony Dinh * Copyright (C) 2015 * Gerald Kerma - * Tony Dinh * Luka Perkov */ @@ -46,10 +46,10 @@ #endif /* CONFIG_CMD_NET */ /* SATA driver configuration */ -#ifdef CONFIG_IDE -#define __io -#define CONFIG_SYS_ATA_IDE0_OFFSET MV_SATA_PORT0_OFFSET -#endif /* CONFIG_IDE */ +#ifdef CONFIG_SATA +#define CONFIG_SYS_SATA_MAX_DEVICE 1 +#define CONFIG_LBA48 +#endif /* CONFIG_SATA */ /* RTC driver configuration */ #ifdef CONFIG_CMD_DATE From 5c151bfee414d04db6e140b2f75adc683484c862 Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Wed, 7 Jul 2021 02:06:47 -0700 Subject: [PATCH 04/10] arm: kirkwood: NSA310S: Use Ethernet PHY name from device tree In DM Ethernet, the old "egiga0" name is no longer valid, so replace it with Ethernet PHY name from device tree. Also, Ethernet PHY address is available so read it from device tree. Signed-off-by: Tony Dinh --- board/zyxel/nsa310s/nsa310s.c | 47 +++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/board/zyxel/nsa310s/nsa310s.c b/board/zyxel/nsa310s/nsa310s.c index cd4a7723b1..b71de4e11f 100644 --- a/board/zyxel/nsa310s/nsa310s.c +++ b/board/zyxel/nsa310s/nsa310s.c @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2015 - * Gerald Kerma - * Tony Dinh + * Copyright (C) 2015, 2021 Tony Dinh + * Copyright (C) 2015 Gerald Kerma */ #include @@ -81,21 +80,51 @@ int board_init(void) return 0; } +static int fdt_get_phy_addr(const char *path) +{ + const void *fdt = gd->fdt_blob; + const u32 *reg; + const u32 *val; + int node, phandle, addr; + + /* Find the node by its full path */ + node = fdt_path_offset(fdt, path); + if (node >= 0) { + /* Look up phy-handle */ + val = fdt_getprop(fdt, node, "phy-handle", NULL); + if (val) { + phandle = fdt32_to_cpu(*val); + if (!phandle) + return -1; + /* Follow it to its node */ + node = fdt_node_offset_by_phandle(fdt, phandle); + if (node) { + /* Look up reg */ + reg = fdt_getprop(fdt, node, "reg", NULL); + if (reg) { + addr = fdt32_to_cpu(*reg); + return addr; + } + } + } + } + return -1; +} + #ifdef CONFIG_RESET_PHY_R void reset_phy(void) { u16 reg; u16 phyaddr; - char *name = "egiga0"; + char *name = "ethernet-controller@72000"; + char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0"; if (miiphy_set_current_dev(name)) return; - /* read PHY dev address */ - if (miiphy_read(name, 0xee, 0xee, (u16 *) &phyaddr)) { - printf("could not read PHY dev address\n"); + phyaddr = fdt_get_phy_addr(eth0_path); + if (phyaddr < 0) return; - } /* set RGMII delay */ miiphy_write(name, phyaddr, MV88E1318_PGADR_REG, MV88E1318_MAC_CTRL_PG); @@ -131,5 +160,7 @@ void reset_phy(void) /* downshift */ miiphy_write(name, phyaddr, 0x10, 0x3860); miiphy_write(name, phyaddr, 0x0, 0x9140); + + printf("MV88E1318 PHY initialized on %s\n", name); } #endif /* CONFIG_RESET_PHY_R */ From dca2c733b2007ddf69c9858737c4578796a55097 Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Tue, 13 Jul 2021 21:35:44 -0700 Subject: [PATCH 05/10] arm: kirkwood: Marvell Sheevaplug: Add DM Ethernet and DM SATA configs Add DM_ETH, SATA_MV and associated configs to sheevaplug_defconfig Signed-off-by: Tony Dinh --- configs/sheevaplug_defconfig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configs/sheevaplug_defconfig b/configs/sheevaplug_defconfig index 676c47af27..4c7259e6d7 100644 --- a/configs/sheevaplug_defconfig +++ b/configs/sheevaplug_defconfig @@ -17,7 +17,6 @@ CONFIG_USE_PREBOOT=y CONFIG_HUSH_PARSER=y CONFIG_CMD_BOOTZ=y # CONFIG_CMD_FLASH is not set -CONFIG_CMD_IDE=y CONFIG_CMD_MMC=y CONFIG_CMD_NAND=y CONFIG_CMD_USB=y @@ -53,3 +52,8 @@ CONFIG_USB_EHCI_HCD=y CONFIG_USB_STORAGE=y CONFIG_LZMA=y CONFIG_BZIP2=y +CONFIG_BLK=y +CONFIG_DM_ETH=y +CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_CMD_SATA=y +CONFIG_SATA_MV=y From ba7174fc53f2bfde825eed172c581be4f3e9bae0 Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Tue, 13 Jul 2021 21:35:46 -0700 Subject: [PATCH 06/10] arm: kirkwood: Marvell Sheevaplug: Add DM SATA and remove IDE configs Enable DM SATA, removed IDE driver, and add SATA MV driver. Signed-off-by: Tony Dinh --- include/configs/sheevaplug.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/configs/sheevaplug.h b/include/configs/sheevaplug.h index 41ba799659..e28f98458e 100644 --- a/include/configs/sheevaplug.h +++ b/include/configs/sheevaplug.h @@ -53,10 +53,9 @@ /* * SATA driver configuration */ -#ifdef CONFIG_IDE -#define __io -#define CONFIG_SYS_ATA_IDE0_OFFSET MV_SATA_PORT0_OFFSET -#define CONFIG_SYS_ATA_IDE1_OFFSET MV_SATA_PORT1_OFFSET -#endif /* CONFIG_IDE */ +#ifdef CONFIG_SATA +#define CONFIG_SYS_SATA_MAX_DEVICE 2 +#define CONFIG_LBA48 +#endif /* CONFIG_SATA */ #endif /* _CONFIG_SHEEVAPLUG_H */ From 6e73bb7e403b25d96a15d987dd08a5905737dd96 Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Fri, 16 Jul 2021 02:18:04 -0700 Subject: [PATCH 07/10] arm: kirkwood: Marvell Sheevaplug: Use Ethernet PHY name and address from device tree - In DM Ethernet, the old "egiga0" name is no longer valid, so replace it with Ethernet PHY name from device tree. Also, Ethernet PHY address is available so read it from device tree. Signed-off-by: Tony Dinh --- board/Marvell/sheevaplug/sheevaplug.c | 54 +++++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/board/Marvell/sheevaplug/sheevaplug.c b/board/Marvell/sheevaplug/sheevaplug.c index 0cc7f2b392..5952d158b2 100644 --- a/board/Marvell/sheevaplug/sheevaplug.c +++ b/board/Marvell/sheevaplug/sheevaplug.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Copyright (C) 2021 Tony Dinh * (C) Copyright 2009 * Marvell Semiconductor * Written-by: Prafulla Wadaskar @@ -100,36 +101,65 @@ int board_init(void) return 0; } +static int fdt_get_phy_addr(const char *path) +{ + const void *fdt = gd->fdt_blob; + const u32 *reg; + const u32 *val; + int node, phandle, addr; + + /* Find the node by its full path */ + node = fdt_path_offset(fdt, path); + if (node >= 0) { + /* Look up phy-handle */ + val = fdt_getprop(fdt, node, "phy-handle", NULL); + if (val) { + phandle = fdt32_to_cpu(*val); + if (!phandle) + return -1; + /* Follow it to its node */ + node = fdt_node_offset_by_phandle(fdt, phandle); + if (node) { + /* Look up reg */ + reg = fdt_getprop(fdt, node, "reg", NULL); + if (reg) { + addr = fdt32_to_cpu(*reg); + return addr; + } + } + } + } + return -1; +} + #ifdef CONFIG_RESET_PHY_R /* Configure and enable MV88E1116 PHY */ void reset_phy(void) { u16 reg; - u16 devadr; - char *name = "egiga0"; + int phyaddr; + char *name = "ethernet-controller@72000"; + char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0"; if (miiphy_set_current_dev(name)) return; - /* command to read PHY dev address */ - if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) { - printf("Err..%s could not read PHY dev address\n", - __FUNCTION__); + phyaddr = fdt_get_phy_addr(eth0_path); + if (phyaddr < 0) return; - } /* * Enable RGMII delay on Tx and Rx for CPU port * Ref: sec 4.7.2 of chip datasheet */ - miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2); - miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, ®); + miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2); + miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); - miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg); - miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0); + miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); + miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0); /* reset the phy */ - miiphy_reset(name, devadr); + miiphy_reset(name, phyaddr); printf("88E1116 Initialized on %s\n", name); } From 644b9864700ee5227232a69ed4f180b99559b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 15 Jul 2021 19:21:01 +0200 Subject: [PATCH 08/10] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Specify a separate partition `u-boot-env` for U-Boot's env settings for the Turris Omnia board. Do this only in U-Boot's specific DTS. We do not want to do this in Linux' official DTS, because Omnia's stock U-Boot stores env at a different address, and there are still boards with stock U-Boot. In a subsequent patch will add board code that fixes Linux's DTB before booting Linux. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi index af0655daaa..3ff76c9462 100644 --- a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi +++ b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi @@ -43,6 +43,17 @@ spi-nor@0 { u-boot,dm-pre-reloc; + + partitions { + partition@0 { + reg = <0x0 CONFIG_ENV_OFFSET>; + }; + + partition@f0000 { + reg = ; + label = "u-boot-env"; + }; + }; }; }; From 92f36c8e74c19a7a84aca4dcea121eabc97b05f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 15 Jul 2021 19:21:02 +0200 Subject: [PATCH 09/10] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixup SPI NOR partition nodes in Linux' device tree prior booting Linux. Linux' devicetree does not contain "u-boot-env" partition and we do not want to add it there because the address is different between stock U-Boot and current upstream U-Boot. Instead we add code that recreates partition nodes from scratch according to how U-Boot sees them (which is defined in U-Boot's device tree). Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 90 ++++++++++++++++++++++++ configs/turris_omnia_defconfig | 1 + 2 files changed, 91 insertions(+) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index 8b2f94f959..a7e5f56eed 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ DECLARE_GLOBAL_DATA_PTR; +#define OMNIA_SPI_NOR_PATH "/soc/spi@10600/spi-nor@0" + #define OMNIA_I2C_BUS_NAME "i2c@11000->i2cmux@70->i2c@0" #define OMNIA_I2C_MCU_CHIP_ADDR 0x2a @@ -557,3 +560,90 @@ out: return 0; } +#if defined(CONFIG_OF_BOARD_SETUP) +/* + * I plan to generalize this function and move it to common/fdt_support.c. + * This will require some more work on multiple boards, though, so for now leave + * it here. + */ +static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd) +{ + struct mtd_info *slave; + int parts; + + parts = fdt_subnode_offset(blob, offset, "partitions"); + if (parts < 0) + return false; + + if (fdt_del_node(blob, parts) < 0) + return false; + + parts = fdt_add_subnode(blob, offset, "partitions"); + if (parts < 0) + return false; + + if (fdt_setprop_u32(blob, parts, "#address-cells", 1) < 0) + return false; + + if (fdt_setprop_u32(blob, parts, "#size-cells", 1) < 0) + return false; + + if (fdt_setprop_string(blob, parts, "compatible", + "fixed-partitions") < 0) + return false; + + mtd_probe_devices(); + + list_for_each_entry(slave, &mtd->partitions, node) { + char name[32]; + int part; + + snprintf(name, sizeof(name), "partition@%llx", slave->offset); + part = fdt_add_subnode(blob, parts, name); + if (part < 0) + return false; + + if (fdt_setprop_u32(blob, part, "reg", slave->offset) < 0) + return false; + + if (fdt_appendprop_u32(blob, part, "reg", slave->size) < 0) + return false; + + if (fdt_setprop_string(blob, part, "label", slave->name) < 0) + return false; + + if (!(slave->flags & MTD_WRITEABLE)) + if (fdt_setprop_empty(blob, part, "read-only") < 0) + return false; + + if (slave->flags & MTD_POWERUP_LOCK) + if (fdt_setprop_empty(blob, part, "lock") < 0) + return false; + } + + return true; +} + +int ft_board_setup(void *blob, struct bd_info *bd) +{ + struct mtd_info *mtd; + int node; + + mtd = get_mtd_device_nm(OMNIA_SPI_NOR_PATH); + if (IS_ERR_OR_NULL(mtd)) + goto fail; + + node = fdt_path_offset(blob, OMNIA_SPI_NOR_PATH); + if (node < 0) + goto fail; + + if (!fixup_mtd_partitions(blob, node, mtd)) + goto fail; + + return 0; + +fail: + printf("Failed fixing SPI NOR partitions!\n"); + return 0; +} +#endif diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig index f860cf5e7d..5f7b1a67a2 100644 --- a/configs/turris_omnia_defconfig +++ b/configs/turris_omnia_defconfig @@ -23,6 +23,7 @@ CONFIG_SPL=y CONFIG_DEBUG_UART_BASE=0xd0012000 CONFIG_DEBUG_UART_CLOCK=250000000 CONFIG_DEBUG_UART=y +CONFIG_OF_BOARD_SETUP=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y CONFIG_FIT=y From a675eb14bd4a827c97afd8a44210aff81ee8095a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Fri, 16 Jul 2021 12:34:42 +0200 Subject: [PATCH 10/10] arm: mvebu: Espressobin: Enable 'mtd' command and define SPI NOR partitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit U-Boot now supports parsing SPI NOR partitions from Device Tree. So enable 'mtd' command support for Espressobin board and define partition layout in U-Boot Espressobin DTS file. Access to SPI NOR via 'sf' command is old method and 'mtd' command is now preferred variant. From include file remove '#define CONFIG_MTD_PARTITIONS' as this option is now defined and enabled in defconfig file. This change is required to fix compile error: CC arch/arm/lib/asm-offsets.s In file included from include/config.h:4, from include/common.h:16, from lib/asm-offsets.c:14: include/configs/mvebu_armada-37xx.h:63: warning: "CONFIG_MTD_PARTITIONS" redefined #define CONFIG_MTD_PARTITIONS /* required for UBI partition support */ In file included from ././include/linux/kconfig.h:4, from : include/generated/autoconf.h:44: note: this is the location of the previous definition #define CONFIG_MTD_PARTITIONS 1 After enabling support for mtd command, output from 'mtd list' on Espressobin board is: => mtd list List of MTD devices: * w25q32dw - device: spi-flash@0 - parent: spi@10600 - driver: jedec_spi_nor - path: /soc/internal-regs/spi@10600/spi-flash@0 - type: NOR flash - block size: 0x1000 bytes - min I/O: 0x1 bytes - 0x000000000000-0x000000400000 : "w25q32dw" - 0x000000000000-0x0000003f0000 : "firmware" - 0x0000003f0000-0x000000400000 : "u-boot-env" => Signed-off-by: Pali Rohár Reviewed-by: Konstantin Porotchkin Reviewed-by: Stefan Roese --- arch/arm/dts/armada-3720-espressobin.dts | 18 ++++++++++++++++++ configs/mvebu_espressobin-88f3720_defconfig | 3 +++ include/configs/mvebu_armada-37xx.h | 5 ----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index d86d8f0b63..cba6139be6 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -164,6 +164,24 @@ reg = <0>; /* Chip select 0 */ spi-max-frequency = <50000000>; m25p,fast-read; + +#ifdef CONFIG_ENV_IS_IN_SPI_FLASH + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@firmware { + reg = <0 CONFIG_ENV_OFFSET>; + label = "firmware"; + }; + + partition@u-boot-env { + reg = ; + label = "u-boot-env"; + }; + }; +#endif }; }; diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index dc199cfe50..78796115cd 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -28,6 +28,7 @@ CONFIG_BOARD_LATE_INIT=y CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y @@ -54,6 +55,7 @@ CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y CONFIG_MMC_SDHCI_XENON=y CONFIG_MTD=y +CONFIG_DM_MTD=y CONFIG_SF_DEFAULT_MODE=0 CONFIG_SF_DEFAULT_SPEED=40000000 CONFIG_SPI_FLASH_GIGADEVICE=y @@ -62,6 +64,7 @@ CONFIG_SPI_FLASH_MACRONIX=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_SPI_FLASH_WINBOND=y +CONFIG_SPI_FLASH_MTD=y CONFIG_PHY_MARVELL=y CONFIG_PHY_GIGE=y CONFIG_E1000=y diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index a2bea2947d..c8c34d7d92 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -57,11 +57,6 @@ #define CONFIG_I2C_MV #define CONFIG_SYS_I2C_SLAVE 0x0 -/* - * SPI Flash configuration - */ -#define CONFIG_MTD_PARTITIONS /* required for UBI partition support */ - /* * Environment */