From e04bf43681c205d73a50eb0cfa13d20667d7666e Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:46 +0200 Subject: arm: mvebu: dts: turris_mox: add button and LED nodes Add nodes for indicator LED and reset button so that board code can implement board factory reset mechanism. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- arch/arm/dts/armada-3720-turris-mox.dts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index 8e0ebf508d4..741b0eeeee3 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -11,6 +11,8 @@ /dts-v1/; #include +#include +#include #include "armada-372x.dtsi" / { @@ -34,6 +36,28 @@ reg = <0x00000000 0x00000000 0x00000000 0x20000000>; }; + leds { + compatible = "gpio-leds"; + + led { + gpios = <&gpiosb 21 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_ACTIVITY; + }; + }; + + gpio-keys { + compatible = "gpio-keys"; + + reset { + compatible = "gpio-keys"; + label = "reset"; + linux,code = ; + gpios = <&gpiosb 20 GPIO_ACTIVE_LOW>; + debounce-interval = <60>; + }; + }; + reg_usb3_vbus: usb3_vbus@0 { compatible = "regulator-fixed"; regulator-name = "usb3-vbus"; -- cgit v1.2.3 From ec3784d62646c8f765310d564a3fc898d9945088 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:47 +0200 Subject: arm: mvebu: turris_mox: add support for board rescue mode Add necessary config options and board code to support board factory reset / rescue mode on Turris MOX. In order to also support invoking rescue mode from U-Boot console, without having to press the factory reset button, put the rescue command into `bootcmd_rescue` default environment variable. When factory reset button is pressed, invoke rescue mode via distroboot by setting `boot_targets` to `rescue`. Rescue boot from console can be invoked by running run bootcmd_rescue Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 71 ++++++++++++++++++++++++++++++++++++ configs/turris_mox_defconfig | 6 +++ include/configs/turris_mox.h | 9 +++++ 3 files changed, 86 insertions(+) diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 15cbf92550e..a78f33661e7 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -10,11 +10,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -44,6 +46,8 @@ #define SFP_GPIO_PATH "/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0" #define PCIE_PATH "/soc/pcie@d0070000" #define SFP_PATH "/sfp" +#define LED_PATH "/leds/led" +#define BUTTON_PATH "/gpio-keys/reset" DECLARE_GLOBAL_DATA_PTR; @@ -373,6 +377,71 @@ int misc_init_r(void) return 0; } +static bool read_reset_button(void) +{ + struct udevice *button, *led; + int i; + + if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) { + printf("Cannot find reset button!\n"); + return false; + } + + if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) { + printf("Cannot find status LED!\n"); + return false; + } + + led_set_state(led, LEDST_ON); + + for (i = 0; i < 21; ++i) { + if (button_get_state(button) != BUTTON_ON) + return false; + if (i < 20) + mdelay(50); + } + + led_set_state(led, LEDST_OFF); + + return true; +} + +static void handle_reset_button(void) +{ + if (read_reset_button()) { + const char * const vars[3] = { + "bootcmd", + "bootcmd_rescue", + "distro_bootcmd", + }; + + /* + * Set the above envs to their default values, in case the user + * managed to break them. + */ + env_set_default_vars(3, (char * const *)vars, 0); + + /* Ensure bootcmd_rescue is used by distroboot */ + env_set("boot_targets", "rescue"); + + printf("RESET button was pressed, overwriting boot_targets!\n"); + } else { + /* + * In case the user somehow managed to save environment with + * boot_targets=rescue, reset boot_targets to default value. + * This could happen in subsequent commands if bootcmd_rescue + * failed. + */ + if (!strcmp(env_get("boot_targets"), "rescue")) { + const char * const vars[1] = { + "boot_targets", + }; + + env_set_default_vars(1, (char * const *)vars, 0); + } + } +} + static void mox_print_info(void) { int ret, board_version, ram_size; @@ -543,6 +612,8 @@ int last_stage_init(void) printf("\n"); + handle_reset_button(); + return 0; } diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig index 75524babbcc..d6d37a3d7d8 100644 --- a/configs/turris_mox_defconfig +++ b/configs/turris_mox_defconfig @@ -23,10 +23,14 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_ARCH_EARLY_INIT_R=y CONFIG_MISC_INIT_R=y +CONFIG_BUTTON=y +CONFIG_BUTTON_GPIO=y +CONFIG_CMD_BUTTON=y CONFIG_CMD_CLK=y # CONFIG_CMD_FLASH is not set CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y +CONFIG_CMD_LED=y CONFIG_CMD_MMC=y CONFIG_CMD_PCI=y CONFIG_CMD_SPI=y @@ -46,6 +50,8 @@ CONFIG_CLK=y CONFIG_CLK_MVEBU=y # CONFIG_MVEBU_GPIO is not set CONFIG_DM_I2C=y +CONFIG_LED=y +CONFIG_LED_GPIO=y CONFIG_MISC=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y diff --git a/include/configs/turris_mox.h b/include/configs/turris_mox.h index 51445ec60ae..b148b1621af 100644 --- a/include/configs/turris_mox.h +++ b/include/configs/turris_mox.h @@ -75,12 +75,21 @@ #include +#define TURRIS_MOX_BOOTCMD_RESCUE \ + "setenv bootargs \"console=ttyMV0,115200 " \ + "earlycon=ar3700_uart,0xd0012000\" && " \ + "sf probe && " \ + "sf read 0x5000000 0x190000 && " \ + "lzmadec 0x5000000 0x5800000 && " \ + "bootm 0x5800000" + #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" \ + "bootcmd_rescue=" TURRIS_MOX_BOOTCMD_RESCUE "\0" \ BOOTENV #endif /* _CONFIG_TURRIS_MOX_H */ -- cgit v1.2.3 From 45853413e2396e6a603d35e21d75712029a4cb19 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:48 +0200 Subject: arm: mvebu: turris_mox: start blinking PHY LEDs when entering rescue Configure blinking on ethernet PHY LEDs on the MOX A board when entering rescue mode via reset button. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index a78f33661e7..44c272c7cb8 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -377,6 +377,38 @@ int misc_init_r(void) return 0; } +static void mox_phy_modify(struct phy_device *phydev, int page, int reg, + u16 mask, u16 set) +{ + int val; + + val = phydev->drv->readext(phydev, MDIO_DEVAD_NONE, page, reg); + val &= ~mask; + val |= set; + phydev->drv->writeext(phydev, MDIO_DEVAD_NONE, page, reg, val); +} + +static void mox_phy_leds_start_blinking(void) +{ + struct phy_device *phydev; + struct mii_dev *bus; + + bus = miiphy_get_dev_by_name("neta@30000"); + if (!bus) { + printf("Cannot get MDIO bus device!\n"); + return; + } + + phydev = phy_find_by_mask(bus, BIT(1), PHY_INTERFACE_MODE_RGMII); + if (!phydev) { + printf("Cannot get ethernet PHY!\n"); + return; + } + + mox_phy_modify(phydev, 3, 0x12, 0x700, 0x400); + mox_phy_modify(phydev, 3, 0x10, 0xff, 0xbb); +} + static bool read_reset_button(void) { struct udevice *button, *led; @@ -424,6 +456,9 @@ static void handle_reset_button(void) /* Ensure bootcmd_rescue is used by distroboot */ env_set("boot_targets", "rescue"); + /* start blinking PHY LEDs */ + mox_phy_leds_start_blinking(); + printf("RESET button was pressed, overwriting boot_targets!\n"); } else { /* -- cgit v1.2.3 From 8805647ed0f8c50bc47de4da04e85a62deea20ff Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:49 +0200 Subject: arm: mvebu: configs: turris_mox: add fdtfile default env variable Add default fdtfile environment variable with value marvell/armada-3720-turris-mox.dtb. This can be useful for some boot scenarios. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- include/configs/turris_mox.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/configs/turris_mox.h b/include/configs/turris_mox.h index b148b1621af..9c021a1ef94 100644 --- a/include/configs/turris_mox.h +++ b/include/configs/turris_mox.h @@ -89,6 +89,7 @@ "fdt_addr_r=0x4f00000\0" \ "kernel_addr_r=0x5000000\0" \ "ramdisk_addr_r=0x8000000\0" \ + "fdtfile=marvell/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \ "bootcmd_rescue=" TURRIS_MOX_BOOTCMD_RESCUE "\0" \ BOOTENV -- cgit v1.2.3 From f2213334004e885aed15d2036f0047d3ce18ef49 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:50 +0200 Subject: arm: mvebu: dts: turris_mox: add nodes for SPI NOR partitions Add nodes for SPI NOR partitions to the device tree of Turris MOX, as are in Linux' device tree. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- arch/arm/dts/armada-3720-turris-mox.dts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index 741b0eeeee3..f47ced05c53 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -164,6 +164,37 @@ reg = <0>; spi-max-frequency = <20000000>; m25p,fast-read; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "secure-firmware"; + reg = <0x0 0x20000>; + }; + + partition@20000 { + label = "a53-firmware"; + reg = <0x20000 0x160000>; + }; + + partition@180000 { + label = "u-boot-env"; + reg = <0x180000 0x10000>; + }; + + partition@190000 { + label = "Rescue system"; + reg = <0x190000 0x660000>; + }; + + partition@7f0000 { + label = "dtb"; + reg = <0x7f0000 0x10000>; + }; + }; }; moxtet@1 { -- cgit v1.2.3 From d51bdaea1972ff0b905f7d33fdbb98056780bf75 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 7 Jun 2021 16:34:51 +0200 Subject: arm: mvebu: turris_mox: enable options for Turris network boot Enable configuration options to support Turris network boot. This includes FIT support and some crypto commands. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- configs/turris_mox_defconfig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig index d6d37a3d7d8..f93be912c95 100644 --- a/configs/turris_mox_defconfig +++ b/configs/turris_mox_defconfig @@ -25,14 +25,17 @@ CONFIG_ARCH_EARLY_INIT_R=y CONFIG_MISC_INIT_R=y CONFIG_BUTTON=y CONFIG_BUTTON_GPIO=y +CONFIG_CMD_AES=y CONFIG_CMD_BUTTON=y CONFIG_CMD_CLK=y # CONFIG_CMD_FLASH is not set CONFIG_CMD_GPIO=y +CONFIG_CMD_HASH=y CONFIG_CMD_I2C=y CONFIG_CMD_LED=y CONFIG_CMD_MMC=y CONFIG_CMD_PCI=y +CONFIG_CMD_SHA1SUM=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_WDT=y @@ -46,6 +49,11 @@ CONFIG_MAC_PARTITION=y CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_FIT=y +CONFIG_FIT_ENABLE_SHA256_SUPPORT=y +# CONFIG_FIT_SIGNATURE is not set +CONFIG_FIT_VERBOSE=y +# CONFIG_FIT_BEST_MATCH is not set CONFIG_CLK=y CONFIG_CLK_MVEBU=y # CONFIG_MVEBU_GPIO is not set -- cgit v1.2.3 From c64e2bd55883ede3dc29421f1f297d741ae5b137 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 8 Jun 2021 12:00:35 +0200 Subject: arm64: mvebu: correct Armada 8K addresses 0x04000000- 0x06000000 is reserved memory. We cannot load to anything here. Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese --- include/configs/mvebu_armada-8k.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/configs/mvebu_armada-8k.h b/include/configs/mvebu_armada-8k.h index 38f50468c54..493e3de9b9f 100644 --- a/include/configs/mvebu_armada-8k.h +++ b/include/configs/mvebu_armada-8k.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" \ "fdtfile=marvell/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \ BOOTENV -- cgit v1.2.3