Skip to contentSkip to conversation

Turris Omnia - New board revision support

PATCH Superseded Marek Behún 2 participants 22 messages Mar 23, 2024 – Mar 25, 2024

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Turris Omnia - New board revision support

Hi Stefan,

this is v2 of series adding support for new board revision of Turris Omnia.

See v1 at
https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

Changes since v1:
- MCU firmware features can be 32-bit wide, updated the code to support reading 32 bits of features (both in board driver and in gpio driver)
- gpio driver now moved to misc, since it handles more functionality (rng, sysreset)
- mvebu system-controller driver expanded to also support UCLASS_SYSRESET, configurable by config option
- LTO enabled by default for Turris Omnia, otherwise it won't fit into the space reserved for U-Boot with these changes
- enabled the poweroff command (via sysreset) in defconfig (new MCU firmware can power off the board voltage regulators)
- enabled the rng command in defconfig

Marek Behún (18):
arm: mvebu: turris_omnia: Enable LTO by default on Turris Omnia
arm: mvebu: turris_omnia: Add header containing MCU command interface
and use it
arm: mvebu: turris_{omnia, mox}: Don't print model two times
arm: mvebu: turris_omnia: Update MCU status and features reading
arm: mvebu: turris_omnia: Implement getting board information from MCU
arm: mvebu: turris_omnia: Print board ECDSA public key if available
arm: mvebu: turris_omnia: Disable Atmel SHA node if not present
arm: mvebu: spl: Do not build mvebu-reset in SPL
arm: mvebu: system-controller: Rework to use UCLASS_SYSCON
arm: mvebu: system-controller: Select mvebu-reset if DM_RESET &&
PCI_MVEBU
arm: mvebu: system-controller: Add support for SYSRESET
gpio: turris_omnia_mcu: Use byteorder conversion functions
gpio: turris_omnia_mcu: Update firmware features reading
gpio: turris_omnia_mcu: Add support for system power off via sysreset
arm: mvebu: turris_omnia: Enable poweroff command via sysreset in
defconfig
cmd: rng: Print "Abort" on -EINTR
misc: turris_omnia_mcu: Add support for rng provided by MCU
arm: mvebu: turris_omnia: Enable rng command in defconfig

 arch/arm/mach-mvebu/Kconfig              |  25 ++
 arch/arm/mach-mvebu/Makefile             |   3 +-
 arch/arm/mach-mvebu/cpu.c                |   2 +
 arch/arm/mach-mvebu/system-controller.c  | 144 ++++++--
 board/CZ.NIC/turris_atsha_otp.c          |  27 +-
 board/CZ.NIC/turris_mox/turris_mox.c     |   5 +-
 board/CZ.NIC/turris_omnia/Makefile       |   2 +-
 board/CZ.NIC/turris_omnia/turris_omnia.c | 310 ++++++++++++-----
 cmd/rng.c                                |   7 +-
 configs/turris_omnia_defconfig           |   6 +
 drivers/gpio/Kconfig                     |   7 -
 drivers/gpio/Makefile                    |   1 -
 drivers/gpio/turris_omnia_mcu.c          | 316 -----------------
 drivers/misc/Kconfig                     |  11 +
 drivers/misc/Makefile                    |   1 +
 drivers/misc/turris_omnia_mcu.c          | 411 +++++++++++++++++++++++
 include/turris-omnia-mcu-interface.h     | 238 +++++++++++++
 17 files changed, 1034 insertions(+), 482 deletions(-)
 delete mode 100644 drivers/gpio/turris_omnia_mcu.c
 create mode 100644 drivers/misc/turris_omnia_mcu.c
 create mode 100644 include/turris-omnia-mcu-interface.h
Signature · 1 line
2.43.2
#1 lore raw

PATCH v2 1/18 arm: mvebu: turris_omnia: Enable LTO by default on Turris Omnia

U-Boot builds for Turris Omnia are approaching the limit of 0xf0000 bytes, which is the size of the U-Boot partition on Omnia.

Enable LTO to get more size optimized binaries.

---
 configs/turris_omnia_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/turris_omnia_defconfig +1 -0
index 29148402a1..39e15043df 100644
@@ -31,6 +31,7 @@ CONFIG_AHCI=y
 CONFIG_OF_BOARD_FIXUP=y
 CONFIG_SYS_MEMTEST_START=0x00800000
 CONFIG_SYS_MEMTEST_END=0x00ffffff
+CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=983040
 CONFIG_FIT=y
Signature · 1 line
2.43.2
#2 lore raw

PATCH v2 2/18 arm: mvebu: turris_omnia: Add header containing MCU command interface and use it

In reply to Marek Behún

Add header containing all MCU command definitions and use it in board code and in MCU driver.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c |  81 +++-----
 drivers/gpio/turris_omnia_mcu.c          |  54 +----
 include/turris-omnia-mcu-interface.h     | 238 +++++++++++++++++++++++
 3 files changed, 262 insertions(+), 111 deletions(-)
 create mode 100644 include/turris-omnia-mcu-interface.h
board/CZ.NIC/turris_omnia/turris_omnia.c +23 -58
index adeb69a205..6c2d7da528 100644
@@ -23,6 +23,7 @@
 #include <fdt_support.h>
 #include <hexdump.h>
 #include <time.h>
+#include <turris-omnia-mcu-interface.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <u-boot/crc.h>
@@ -59,46 +60,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define A385_WD_RSTOUT_UNMASK		MVEBU_REGISTER(0x20704)
 #define   A385_WD_RSTOUT_UNMASK_GLOBAL	BIT(8)
 
-enum mcu_commands {
-	CMD_GET_STATUS_WORD	= 0x01,
-	CMD_GET_RESET		= 0x09,
-	CMD_GET_FW_VERSION_APP	= 0x0a,
-	CMD_WATCHDOG_STATE	= 0x0b,
-	CMD_GET_FW_VERSION_BOOT	= 0x0e,
-
-	/* available if STS_FEATURES_SUPPORTED bit set in status word */
-	CMD_GET_FEATURES	= 0x10,
-
-	/* available if EXT_CMD bit set in features */
-	CMD_EXT_CONTROL		= 0x12,
-};
-
-enum status_word_bits {
-	STS_MCU_TYPE_MASK	= GENMASK(1, 0),
-	STS_MCU_TYPE_STM32	= 0,
-	STS_MCU_TYPE_GD32	= 1,
-	STS_MCU_TYPE_MKL	= 2,
-	STS_MCU_TYPE_UNKN	= 3,
-	STS_FEATURES_SUPPORTED	= BIT(2),
-	CARD_DET_STSBIT		= 0x0010,
-	MSATA_IND_STSBIT	= 0x0020,
-};
-
-/* CMD_GET_FEATURES */
-enum features_e {
-	FEAT_PERIPH_MCU		= BIT(0),
-	FEAT_EXT_CMDS		= BIT(1),
-};
-
-/* CMD_EXT_CONTROL */
-enum ext_ctl_e {
-	EXT_CTL_nRES_LAN	= BIT(1),
-	EXT_CTL_nRES_PHY	= BIT(2),
-	EXT_CTL_nPERST0		= BIT(3),
-	EXT_CTL_nPERST1		= BIT(4),
-	EXT_CTL_nPERST2		= BIT(5),
-};
-
 /*
  * Those values and defines are taken from the Marvell U-Boot version
  * "u-boot-2013.01-2014_T3.0"
@@ -219,7 +180,7 @@ static bool disable_mcu_watchdog(void)
 
 	puts("Disabling MCU watchdog... ");
 
-	ret = omnia_mcu_write(CMD_WATCHDOG_STATE, "\x00", 1);
+	ret = omnia_mcu_write(CMD_SET_WATCHDOG_STATE, "\x00", 1);
 	if (ret) {
 		printf("omnia_mcu_write failed: %i\n", ret);
 		return false;
@@ -256,17 +217,17 @@ static bool omnia_detect_sata(const char *msata_slot)
 		return false;
 	}
 
-	if (!(stsword & CARD_DET_STSBIT)) {
+	if (!(stsword & STS_CARD_DET)) {
 		puts("none\n");
 		return false;
 	}
 
-	if (stsword & MSATA_IND_STSBIT)
+	if (stsword & STS_MSATA_IND)
 		puts("mSATA\n");
 	else
 		puts("MiniPCIe\n");
 
-	return stsword & MSATA_IND_STSBIT ? true : false;
+	return stsword & STS_MSATA_IND;
 }
 
 static bool omnia_detect_wwan_usb3(const char *wwan_slot)
@@ -393,18 +354,7 @@ static int omnia_get_ram_size_gb(void)
 
 static const char * const omnia_get_mcu_type(void)
 {
-	static const char * const mcu_types[] = {
-		[STS_MCU_TYPE_STM32] = "STM32",
-		[STS_MCU_TYPE_GD32]  = "GD32",
-		[STS_MCU_TYPE_MKL]   = "MKL",
-		[STS_MCU_TYPE_UNKN]  = "unknown",
-	};
-	static const char * const mcu_types_with_perip_resets[] = {
-		[STS_MCU_TYPE_STM32] = "STM32 (with peripheral resets)",
-		[STS_MCU_TYPE_GD32]  = "GD32 (with peripheral resets)",
-		[STS_MCU_TYPE_MKL]   = "MKL (with peripheral resets)",
-		[STS_MCU_TYPE_UNKN]  = "unknown (with peripheral resets)",
-	};
+	static char result[] = "xxxxxxx (with peripheral resets)";
 	u16 stsword, features;
 	int ret;
 
@@ -412,13 +362,28 @@ static const char * const omnia_get_mcu_type(void)
 	if (ret)
 		return "unknown";
 
+	switch (stsword & STS_MCU_TYPE_MASK) {
+	case STS_MCU_TYPE_STM32:
+		strcpy(result, "STM32");
+		break;
+	case STS_MCU_TYPE_GD32:
+		strcpy(result, "GD32");
+		break;
+	case STS_MCU_TYPE_MKL:
+		strcpy(result, "MKL");
+		break;
+	default:
+		strcpy(result, "unknown");
+		break;
+	}
+
 	if (stsword & STS_FEATURES_SUPPORTED) {
 		ret = omnia_mcu_read(CMD_GET_FEATURES, &features, sizeof(features));
 		if (ret == 0 && (features & FEAT_PERIPH_MCU))
-			return mcu_types_with_perip_resets[stsword & STS_MCU_TYPE_MASK];
+			strcat(result, " (with peripheral resets)");
 	}
 
-	return mcu_types[stsword & STS_MCU_TYPE_MASK];
+	return result;
 }
 
 static const char * const omnia_get_mcu_version(void)
drivers/gpio/turris_omnia_mcu.c +1 -53

63 lines not on this page · raw message

include/turris-omnia-mcu-interface.h new file +238 -0

238 lines not on this page · raw message

Signature · 1 line
2.43.2
#3 lore raw

PATCH v2 3/18 arm: mvebu: turris_{omnia, mox}: Don't print model two times

In reply to Marek Behún

Since commit 8cd4bf7dc9ba ("turris: Use checkboard() instead of show_board_info()") the model is show two times during boot:
Model: Turris Omnia
Model: Turris Omnia

This is because the common function show_board_info() shows it, and Turris' checkboard() also does.

Remove the second print.

Fixes 8cd4bf7dc9ba ("turris: Use checkboard() instead of show_board_info()")
---
 board/CZ.NIC/turris_mox/turris_mox.c     | 5 +----
 board/CZ.NIC/turris_omnia/turris_omnia.c | 1 -
 2 files changed, 1 insertion(+), 5 deletions(-)
board/CZ.NIC/turris_mox/turris_mox.c +1 -4
index 3489bdd74b..1a2f60e3d1 100644
@@ -565,13 +565,10 @@ static void handle_reset_button(void)
 int checkboard(void)
 {
 	int i, ret, board_version, ram_size, is_sd;
-	const char *pub_key, *model;
+	const char *pub_key;
 	const u8 *topology;
 	u64 serial_number;
 
-	model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
-	printf("Model: %s\n", model);
-
 	ret = mbox_sp_get_board_info(&serial_number, NULL, NULL, &board_version,
 				     &ram_size, NULL);
 	if (ret < 0) {
board/CZ.NIC/turris_omnia/turris_omnia.c +0 -1
index 6c2d7da528..87e33d88c4 100644
@@ -933,7 +933,6 @@ int checkboard(void)
 	int err;
 
 	err = turris_atsha_otp_get_serial_number(serial);
-	printf("Model: Turris Omnia\n");
 	printf("  MCU type: %s\n", omnia_get_mcu_type());
 	printf("  MCU version: %s\n", omnia_get_mcu_version());
 	printf("  RAM size: %i MiB\n", omnia_get_ram_size_gb() * 1024);
Signature · 1 line
2.43.2
#4 lore raw

PATCH v2 4/18 arm: mvebu: turris_omnia: Update MCU status and features reading

In reply to Marek Behún

Refactor MCU status word and MCU firmware features reading to make it simpler to use.

Try reading 32 bits of features, if that fails, read 16 bits. Older MCU firmware supports only 16-bit wide features, and if more bytes are read, either 0xff is sent or I2C transaction fails. Handle both cases.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 100 +++++++++++++++--------
 1 file changed, 68 insertions(+), 32 deletions(-)
board/CZ.NIC/turris_omnia/turris_omnia.c +68 -32
index 87e33d88c4..6dfde5ee7a 100644
@@ -133,6 +133,59 @@ static int omnia_mcu_write(u8 cmd, const void *buf, int len)
 	return dm_i2c_write(chip, cmd, buf, len);
 }
 
+static int omnia_mcu_get_sts_and_features(u16 *psts, u32 *pfeatures)
+{
+	u16 sts, feat16;
+	int ret;
+
+	ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &sts, sizeof(sts));
+	if (ret)
+		return ret;
+
+	if (psts)
+		*psts = sts;
+
+	if (!pfeatures)
+		return 0;
+
+	if (sts & STS_FEATURES_SUPPORTED) {
+		/* try read 32-bit features */
+		ret = omnia_mcu_read(CMD_GET_FEATURES, pfeatures,
+				     sizeof(*pfeatures));
+		if (ret) {
+			/* try read 16-bit features */
+			ret = omnia_mcu_read(CMD_GET_FEATURES, &feat16,
+					     sizeof(&feat16));
+			if (ret)
+				return ret;
+
+			*pfeatures = feat16;
+		} else {
+			if (*pfeatures & FEAT_FROM_BIT_16_INVALID)
+				*pfeatures &= GENMASK(15, 0);
+		}
+	} else {
+		*pfeatures = 0;
+	}
+
+	return 0;
+}
+
+static int omnia_mcu_get_sts(u16 *sts)
+{
+	return omnia_mcu_get_sts_and_features(sts, NULL);
+}
+
+static bool omnia_mcu_has_feature(u32 feature)
+{
+	u32 features;
+
+	if (omnia_mcu_get_sts_and_features(NULL, &features))
+		return false;
+
+	return feature & features;
+}
+
 static void enable_a385_watchdog(unsigned int timeout_minutes)
 {
 	struct sar_freq_modes sar_freq;
@@ -194,7 +247,7 @@ static bool disable_mcu_watchdog(void)
 static bool omnia_detect_sata(const char *msata_slot)
 {
 	int ret;
-	u16 stsword;
+	u16 sts;
 
 	puts("MiniPCIe/mSATA card detection... ");
 
@@ -210,24 +263,24 @@ static bool omnia_detect_sata(const char *msata_slot)
 		}
 	}
 
-	ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &stsword, sizeof(stsword));
+	ret = omnia_mcu_get_sts(&sts);
 	if (ret) {
 		printf("omnia_mcu_read failed: %i, defaulting to MiniPCIe card\n",
 		       ret);
 		return false;
 	}
 
-	if (!(stsword & STS_CARD_DET)) {
+	if (!(sts & STS_CARD_DET)) {
 		puts("none\n");
 		return false;
 	}
 
-	if (stsword & STS_MSATA_IND)
+	if (sts & STS_MSATA_IND)
 		puts("mSATA\n");
 	else
 		puts("MiniPCIe\n");
 
-	return stsword & STS_MSATA_IND;
+	return sts & STS_MSATA_IND;
 }
 
 static bool omnia_detect_wwan_usb3(const char *wwan_slot)
@@ -355,14 +408,14 @@ static int omnia_get_ram_size_gb(void)
 static const char * const omnia_get_mcu_type(void)
 {
 	static char result[] = "xxxxxxx (with peripheral resets)";
-	u16 stsword, features;
+	u16 sts;
 	int ret;
 
-	ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &stsword, sizeof(stsword));
+	ret = omnia_mcu_get_sts(&sts);
 	if (ret)
 		return "unknown";
 
-	switch (stsword & STS_MCU_TYPE_MASK) {
+	switch (sts & STS_MCU_TYPE_MASK) {
 	case STS_MCU_TYPE_STM32:
 		strcpy(result, "STM32");
 		break;
@@ -377,11 +430,8 @@ static const char * const omnia_get_mcu_type(void)
 		break;
 	}
 
-	if (stsword & STS_FEATURES_SUPPORTED) {
-		ret = omnia_mcu_read(CMD_GET_FEATURES, &features, sizeof(features));
-		if (ret == 0 && (features & FEAT_PERIPH_MCU))
-			strcat(result, " (with peripheral resets)");
-	}
+	if (omnia_mcu_has_feature(FEAT_PERIPH_MCU))
+		strcat(result, " (with peripheral resets)");
 
 	return result;
 }
@@ -660,9 +710,6 @@ int board_early_init_f(void)
 
 void spl_board_init(void)
 {
-	u16 val;
-	int ret;
-
 	/*
 	 * If booting from UART, disable MCU watchdog in SPL, since uploading
 	 * U-Boot proper can take too much time and trigger it. Instead enable
@@ -679,12 +726,8 @@ void spl_board_init(void)
 	 * resets then LAN eth switch is initialized automatically by bootstrap
 	 * pins when A385 is released from the reset.
 	 */
-	ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &val, sizeof(val));
-	if (ret == 0 && (val & STS_FEATURES_SUPPORTED)) {
-		ret = omnia_mcu_read(CMD_GET_FEATURES, &val, sizeof(val));
-		if (ret == 0 && (val & FEAT_PERIPH_MCU))
-			initialize_switch();
-	}
+	if (omnia_mcu_has_feature(FEAT_PERIPH_MCU))
+		initialize_switch();
 }
 
 #if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) || IS_ENABLED(CONFIG_OF_BOARD_SETUP)
@@ -884,16 +927,9 @@ static int fixup_mcu_gpio_in_eth_wan_node(void *blob)
 #if IS_ENABLED(CONFIG_OF_BOARD_FIXUP)
 int board_fix_fdt(void *blob)
 {
-	u16 val;
-	int ret;
-
-	ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &val, sizeof(val));
-	if (ret == 0 && (val & STS_FEATURES_SUPPORTED)) {
-		ret = omnia_mcu_read(CMD_GET_FEATURES, &val, sizeof(val));
-		if (ret == 0 && (val & FEAT_PERIPH_MCU)) {
-			fixup_mcu_gpio_in_pcie_nodes(blob);
-			fixup_mcu_gpio_in_eth_wan_node(blob);
-		}
+	if (omnia_mcu_has_feature(FEAT_PERIPH_MCU)) {
+		fixup_mcu_gpio_in_pcie_nodes(blob);
+		fixup_mcu_gpio_in_eth_wan_node(blob);
 	}
 
 	fixup_msata_port_nodes(blob);
Signature · 1 line
2.43.2
#5 lore raw

PATCH v2 5/18 arm: mvebu: turris_omnia: Implement getting board information from MCU

In reply to Marek Behún

Implement reading board serial number, first MAC address and board version from MCU. MCU supports board information if the FEAT_BOARD_INFO feature bit is set in MCU features.

Prefer getting board information from MCU if supported, fallback to Atmel SHA chip.

---
 board/CZ.NIC/turris_atsha_otp.c          | 27 +------
 board/CZ.NIC/turris_omnia/Makefile       |  2 +-
 board/CZ.NIC/turris_omnia/turris_omnia.c | 94 +++++++++++++++++++++++-
 3 files changed, 93 insertions(+), 30 deletions(-)
board/CZ.NIC/turris_atsha_otp.c +2 -25
index a29fe36231..85eebcdf18 100644
@@ -11,6 +11,7 @@
 #include <atsha204a-i2c.h>
 
 #include "turris_atsha_otp.h"
+#include "turris_common.h"
 
 #define TURRIS_ATSHA_OTP_VERSION	0
 #define TURRIS_ATSHA_OTP_SERIAL		1
@@ -32,26 +33,6 @@ static struct udevice *get_atsha204a_dev(void)
 	return dev;
 }
 
-static void increment_mac(u8 *mac)
-{
-	int i;
-
-	for (i = 5; i >= 3; i--) {
-		mac[i] += 1;
-		if (mac[i])
-			break;
-	}
-}
-
-static void set_mac_if_invalid(int i, u8 *mac)
-{
-	u8 oldmac[6];
-
-	if (is_valid_ethaddr(mac) &&
-	    !eth_env_get_enetaddr_by_index("eth", i, oldmac))
-		eth_env_set_enetaddr_by_index("eth", i, mac);
-}
-
 int turris_atsha_otp_init_mac_addresses(int first_idx)
 {
 	struct udevice *dev = get_atsha204a_dev();
@@ -84,11 +65,7 @@ int turris_atsha_otp_init_mac_addresses(int first_idx)
 	mac[4] = mac1[2];
 	mac[5] = mac1[3];
 
-	set_mac_if_invalid((first_idx + 0) % 3, mac);
-	increment_mac(mac);
-	set_mac_if_invalid((first_idx + 1) % 3, mac);
-	increment_mac(mac);
-	set_mac_if_invalid((first_idx + 2) % 3, mac);
+	turris_init_mac_addresses(first_idx, mac);
 
 	return 0;
 }
board/CZ.NIC/turris_omnia/Makefile +1 -1
index dc39b44ae1..341378b4e5 100644
@@ -2,4 +2,4 @@
 #
 # Copyright (C) 2017 Marek Behún <[email protected]>
 
-obj-y	:= turris_omnia.o ../turris_atsha_otp.o
+obj-y	:= turris_omnia.o ../turris_atsha_otp.o ../turris_common.o
board/CZ.NIC/turris_omnia/turris_omnia.c +90 -4

135 lines not on this page · raw message

Signature · 1 line
2.43.2
#6 lore raw

PATCH v2 6/18 arm: mvebu: turris_omnia: Print board ECDSA public key if available

In reply to Marek Behún

If MCU supports the FEAT_CRYPTO feature, read board ECDSA public key from MCU and print it.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 25 +++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_omnia/turris_omnia.c +24 -1
index f63640ad64..896c14bb99 100644
@@ -253,6 +253,24 @@ static int omnia_mcu_board_info(char *serial, u8 *mac, char *version)
 	return 0;
 }
 
+static int omnia_mcu_get_board_public_key(char pub_key[static 67])
+{
+	u8 reply[34];
+	int ret;
+
+	ret = omnia_mcu_read(CMD_CRYPTO_GET_PUBLIC_KEY, reply, sizeof(reply));
+	if (ret)
+		return ret;
+
+	if (reply[0] != 33)
+		return -EBADMSG;
+
+	bin2hex(pub_key, &reply[1], 33);
+	reply[66] = '\0';
+
+	return 0;
+}
+
 static void enable_a385_watchdog(unsigned int timeout_minutes)
 {
 	struct sar_freq_modes sar_freq;
@@ -1032,7 +1050,7 @@ int board_late_init(void)
 
 int checkboard(void)
 {
-	char serial[17], version[4];
+	char serial[17], version[4], pub_key[67];
 	bool has_version;
 	int err;
 
@@ -1051,6 +1069,11 @@ int checkboard(void)
 	printf("  Board version: %s\n", has_version ? version : "unknown");
 	printf("  Serial Number: %s\n", !err ? serial : "unknown");
 
+	if (omnia_mcu_has_feature(FEAT_CRYPTO)) {
+		err = omnia_mcu_get_board_public_key(pub_key);
+		printf("  ECDSA Public Key: %s\n", !err ? pub_key : "unknown");
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.43.2
#7 lore raw

Re: [PATCH u-boot-mvebu v2 06/18] arm: mvebu: turris_omnia: Print board ECDSA public key if available

Quoted 20 lines · On Sat, 23 Mar 2024 19:06:59 +0100 Marek Behún <[email protected]> wrote:

If MCU supports the FEAT_CRYPTO feature, read board ECDSA public key from MCU and print it.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 25 +++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_omnia/turris_omnia.c +4 -0
index f63640ad64..896c14bb99 100644
@@ -253,6 +253,24 @@ static int omnia_mcu_board_info(char *serial, u8 *mac, char *version)
 	return 0;
 }
 
+static int omnia_mcu_get_board_public_key(char pub_key[static 67])
+{
+	u8 reply[34];
+	int ret;

board/CZ.NIC/turris_omnia/turris_omnia.c static int omnia_mcu_board_info(char *serial, u8 *mac, char *version) · line 269

Quoted 10 lines
board/CZ.NIC/turris_omnia/turris_omnia.c +10 -0
+
+	ret = omnia_mcu_read(CMD_CRYPTO_GET_PUBLIC_KEY, reply, sizeof(reply));
+	if (ret)
+		return ret;
+
+	if (reply[0] != 33)
+		return -EBADMSG;
+
+	bin2hex(pub_key, &reply[1], 33);
+	reply[66] = '\0';

Aargh, this should be pub_key[66] = '\0'.

And I noticed once more thing, so I will sent another version.

#8 lore raw

PATCH v2 7/18 arm: mvebu: turris_omnia: Disable Atmel SHA node if not present

In reply to Marek Behún

If the FEAT_CRYPTO feature bit is present in MCU features, the board crypto is implemented by MCU and the Atmel SHA chip is not present. Disable Atmel SHA device-tree node in that case.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +23 -0
index 896c14bb99..6f3aae55a8 100644
@@ -1007,6 +1007,25 @@ static int fixup_mcu_gpio_in_eth_wan_node(void *blob)
 	return 0;
 }
 
+static void fixup_atsha_node(void *blob)
+{
+	int node;
+
+	if (!omnia_mcu_has_feature(FEAT_CRYPTO))
+		return;
+
+	node = fdt_node_offset_by_compatible(blob, -1, "atmel,atsha204a");
+	if (node < 0) {
+		printf("Cannot find ATSHA204A node!\n");
+		return;
+	}
+
+	if (fdt_status_disabled(blob, node) < 0)
+		printf("Cannot disable ATSHA204A node!\n");
+	else
+		debug("Disabled ATSHA204A node\n");
+}
+
 #endif
 
 #if IS_ENABLED(CONFIG_OF_BOARD_FIXUP)
@@ -1020,6 +1039,8 @@ int board_fix_fdt(void *blob)
 	fixup_msata_port_nodes(blob);
 	fixup_wwan_port_nodes(blob);
 
+	fixup_atsha_node(blob);
+
 	return 0;
 }
 #endif
@@ -1211,6 +1232,8 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	fixup_msata_port_nodes(blob);
 	fixup_wwan_port_nodes(blob);
 
+	fixup_atsha_node(blob);
+
 	return 0;
 }
 #endif
Signature · 1 line
2.43.2
#9 lore raw

PATCH v2 8/18 arm: mvebu: spl: Do not build mvebu-reset in SPL

In reply to Marek Behún

Commit 35e29e89a386 ("arm: mvebu: Implement simple mvebu-reset driver for enabling/disabling PCIe ports") made it so that the mvebu reset driver for enabling/disabling PCIe ports is build if CONFIG_DM_RESET is enabled. This is because PCI_MVEBU depends on DM_RESET.

But the driver should not be built for SPL. Indeed the PCI_MVEBU driver is not supported in SPL now, and so the mvebu-reset driver is not needed.

---
 arch/arm/mach-mvebu/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/Makefile +2 -1
index 0584ed2be5..ef790d97fe 100644
@@ -22,13 +22,14 @@ else # CONFIG_ARCH_KIRKWOOD
 obj-y	= cpu.o
 obj-y	+= dram.o
 obj-y	+= lowlevel.o
-obj-$(CONFIG_DM_RESET) += system-controller.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_ARMADA_375) += ../../../drivers/ddr/marvell/axp/xor.o
 obj-$(CONFIG_ARMADA_38X) += ../../../drivers/ddr/marvell/a38x/xor.o
 obj-$(CONFIG_ARMADA_XP) += ../../../drivers/ddr/marvell/axp/xor.o
 obj-$(CONFIG_ARMADA_MSYS) += ../../../drivers/ddr/marvell/axp/xor.o
 
+obj-$(CONFIG_DM_RESET) += system-controller.o
+
 ifdef CONFIG_ARMADA_38X
 obj-$(CONFIG_MVEBU_EFUSE) += efuse.o
 endif
Signature · 1 line
2.43.2
#10 lore raw

PATCH v2 9/18 arm: mvebu: system-controller: Rework to use UCLASS_SYSCON

In reply to Marek Behún

The system-controller driver for 32-bit Armada is currently registered as UCLASS_RESET, since it only provides enabling/disabling PCIe ports.

Rework it as UCLASS_SYSCON and bind mvebu-reset as a child device.

---
 arch/arm/mach-mvebu/Kconfig             | 11 ++++
 arch/arm/mach-mvebu/Makefile            |  2 +-
 arch/arm/mach-mvebu/system-controller.c | 76 ++++++++++++++-----------
 3 files changed, 54 insertions(+), 35 deletions(-)
arch/arm/mach-mvebu/Kconfig +11 -0
index 2058c95ca2..62a2bc5958 100644
@@ -18,6 +18,7 @@ config ARMADA_32BIT
 	select TOOLS_KWBIMAGE if SPL
 	select SPL_SYS_NO_VECTOR_TABLE if SPL
 	select ARCH_VERY_EARLY_INIT
+	select ARMADA_32BIT_SYSCON_RESET if DM_RESET
 
 # ARMv7 SoCs...
 config ARMADA_375
@@ -456,6 +457,16 @@ config SF_DEFAULT_MODE
 	default 0x0
 	depends on MVEBU_SPL_BOOT_DEVICE_SPI
 
+config ARMADA_32BIT_SYSCON_RESET
+	bool "Support Armada XP/375/38x/39x reset controller"
+	depends on ARMADA_32BIT
+	depends on DM_RESET
+	select REGMAP
+	select SYSCON
+	help
+	  Build support for Armada XP/375/38x/39x reset controller. This is
+	  needed for PCIe support.
+
 source "board/solidrun/clearfog/Kconfig"
 source "board/kobol/helios4/Kconfig"
 
arch/arm/mach-mvebu/Makefile +1 -1
index ef790d97fe..d44ca3a0df 100644
@@ -28,7 +28,7 @@ obj-$(CONFIG_ARMADA_38X) += ../../../drivers/ddr/marvell/a38x/xor.o
 obj-$(CONFIG_ARMADA_XP) += ../../../drivers/ddr/marvell/axp/xor.o
 obj-$(CONFIG_ARMADA_MSYS) += ../../../drivers/ddr/marvell/axp/xor.o
 
-obj-$(CONFIG_DM_RESET) += system-controller.o
+obj-$(CONFIG_ARMADA_32BIT_SYSCON_RESET) += system-controller.o
 
 ifdef CONFIG_ARMADA_38X
 obj-$(CONFIG_MVEBU_EFUSE) += efuse.o
arch/arm/mach-mvebu/system-controller.c +42 -34

115 lines not on this page · raw message

Signature · 1 line
2.43.2
#11 lore raw

PATCH v2 10/18 arm: mvebu: system-controller: Select mvebu-reset if DM_RESET && PCI_MVEBU

In reply to Marek Behún

The mvebu-reset driver is only needed by the mvebu PCIe driver, but currently it is automatically selected if DM_RESET is enabled. Add the condition of PCI_MVEBU also being enabled for mvebu-reset to be selected.

---
 arch/arm/mach-mvebu/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-mvebu/Kconfig +1 -1
index 62a2bc5958..623432a60e 100644
@@ -18,7 +18,7 @@ config ARMADA_32BIT
 	select TOOLS_KWBIMAGE if SPL
 	select SPL_SYS_NO_VECTOR_TABLE if SPL
 	select ARCH_VERY_EARLY_INIT
-	select ARMADA_32BIT_SYSCON_RESET if DM_RESET
+	select ARMADA_32BIT_SYSCON_RESET if DM_RESET && PCI_MVEBU
 
 # ARMv7 SoCs...
 config ARMADA_375
Signature · 1 line
2.43.2
#12 lore raw

PATCH v2 11/18 arm: mvebu: system-controller: Add support for SYSRESET

In reply to Marek Behún

Add driver model support for sysreset via mvebu system controller. This is currently only available for U-Boot proper.

---
 arch/arm/mach-mvebu/Kconfig             | 18 +++++-
 arch/arm/mach-mvebu/Makefile            |  2 +-
 arch/arm/mach-mvebu/cpu.c               |  2 +
 arch/arm/mach-mvebu/system-controller.c | 74 +++++++++++++++++++++++--
 4 files changed, 89 insertions(+), 7 deletions(-)
arch/arm/mach-mvebu/Kconfig +16 -2
index 623432a60e..f15d3cc5ed 100644
@@ -19,6 +19,7 @@ config ARMADA_32BIT
 	select SPL_SYS_NO_VECTOR_TABLE if SPL
 	select ARCH_VERY_EARLY_INIT
 	select ARMADA_32BIT_SYSCON_RESET if DM_RESET && PCI_MVEBU
+	select ARMADA_32BIT_SYSCON_SYSRESET if SYSRESET
 
 # ARMv7 SoCs...
 config ARMADA_375
@@ -457,16 +458,29 @@ config SF_DEFAULT_MODE
 	default 0x0
 	depends on MVEBU_SPL_BOOT_DEVICE_SPI
 
+config ARMADA_32BIT_SYSCON
+	bool
+	depends on ARMADA_32BIT
+	select REGMAP
+	select SYSCON
+
 config ARMADA_32BIT_SYSCON_RESET
 	bool "Support Armada XP/375/38x/39x reset controller"
 	depends on ARMADA_32BIT
 	depends on DM_RESET
-	select REGMAP
-	select SYSCON
+	select ARMADA_32BIT_SYSCON
 	help
 	  Build support for Armada XP/375/38x/39x reset controller. This is
 	  needed for PCIe support.
 
+config ARMADA_32BIT_SYSCON_SYSRESET
+	bool "Support Armada XP/375/38x/39x sysreset via driver model"
+	depends on ARMADA_32BIT
+	depends on SYSRESET
+	select ARMADA_32BIT_SYSCON
+	help
+	  Build support for Armada XP/375/38x/39x system reset via driver model.
+
 source "board/solidrun/clearfog/Kconfig"
 source "board/kobol/helios4/Kconfig"
 
arch/arm/mach-mvebu/Makefile +1 -1
index d44ca3a0df..329c2e4915 100644
@@ -28,7 +28,7 @@ obj-$(CONFIG_ARMADA_38X) += ../../../drivers/ddr/marvell/a38x/xor.o
 obj-$(CONFIG_ARMADA_XP) += ../../../drivers/ddr/marvell/axp/xor.o
 obj-$(CONFIG_ARMADA_MSYS) += ../../../drivers/ddr/marvell/axp/xor.o
 
-obj-$(CONFIG_ARMADA_32BIT_SYSCON_RESET) += system-controller.o
+obj-$(CONFIG_ARMADA_32BIT_SYSCON) += system-controller.o
 
 ifdef CONFIG_ARMADA_38X
 obj-$(CONFIG_MVEBU_EFUSE) += efuse.o
arch/arm/mach-mvebu/cpu.c +2 -0
index 8e0de93538..7c62a5dbb6 100644
@@ -52,6 +52,7 @@ void lowlevel_init(void)
 	 */
 }
 
+#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_ARMADA_32BIT_SYSCON_SYSRESET)
 void reset_cpu(void)
 {
 	struct mvebu_system_registers *reg =
@@ -62,6 +63,7 @@ void reset_cpu(void)
 	while (1)
 		;
 }
+#endif
 
 u32 get_boot_device(void)
 {
arch/arm/mach-mvebu/system-controller.c +70 -4

92 lines not on this page · raw message

Signature · 1 line
2.43.2
#13 lore raw

PATCH v2 12/18 gpio: turris_omnia_mcu: Use byteorder conversion functions

In reply to Marek Behún

Use byteorder conversion function instead of manually assembling data from/to MCU.

---
 drivers/gpio/turris_omnia_mcu.c | 80 +++++++++++++++++++--------------
 1 file changed, 46 insertions(+), 34 deletions(-)
drivers/gpio/turris_omnia_mcu.c +46 -34
index da9a6efe6d..c441d07d69 100644
@@ -5,6 +5,7 @@
 #include <dm.h>
 #include <i2c.h>
 #include <turris-omnia-mcu-interface.h>
+#include <asm/byteorder.h>
 #include <asm/gpio.h>
 #include <linux/log2.h>
 
@@ -51,27 +52,31 @@ static int turris_omnia_mcu_get_function(struct udevice *dev, uint offset)
 static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
 {
 	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
-	u8 val16[2];
-	u8 val32[4];
+	u32 val32;
+	u16 val16;
 	int ret;
 
 	switch (offset) {
 	/* bank 0 */
 	case 0 ... 15:
-		ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, val16, 2);
+		ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, (void *)&val16,
+				  sizeof(val16));
 		if (ret)
 			return ret;
-		return ((((u16)val16[1] << 8) | val16[0]) >> offset) & 0x1;
+
+		return !!(le16_to_cpu(val16) & BIT(offset));
 
 	/* bank 1 - supported only when FEAT_EXT_CMDS is set */
 	case (16 + 0) ... (16 + 31):
 		if (!(info->features & FEAT_EXT_CMDS))
 			return -EINVAL;
-		ret = dm_i2c_read(dev, CMD_GET_EXT_STATUS_DWORD, val32, 4);
+
+		ret = dm_i2c_read(dev, CMD_GET_EXT_STATUS_DWORD, (void *)&val32,
+				  sizeof(val32));
 		if (ret)
 			return ret;
-		return ((((u32)val32[3] << 24) | ((u32)val32[2] << 16) |
-			 ((u32)val32[1] << 8) | val32[0]) >> (offset - 16)) & 0x1;
+
+		return !!(le32_to_cpu(val32) & BIT(offset - 16));
 
 	/* bank 2 - supported only when FEAT_EXT_CMDS and FEAT_PERIPH_MCU is set */
 	case (16 + 32 + 0) ... (16 + 32 + 15):
@@ -79,10 +84,13 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
 			return -EINVAL;
 		if (!(info->features & FEAT_PERIPH_MCU))
 			return -EINVAL;
-		ret = dm_i2c_read(dev, CMD_GET_EXT_CONTROL_STATUS, val16, 2);
+
+		ret = dm_i2c_read(dev, CMD_GET_EXT_CONTROL_STATUS,
+				  (void *)&val16, sizeof(val16));
 		if (ret)
 			return ret;
-		return ((((u16)val16[1] << 8) | val16[0]) >> (offset - 16 - 32)) & 0x1;
+
+		return !!(le16_to_cpu(val16) & BIT(offset - 16 - 32));
 
 	default:
 		return -EINVAL;
@@ -92,30 +100,33 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
 static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int value)
 {
 	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
-	u8 val16[2];
-	u8 val32[4];
+	u16 valmask16[2];
+	u8 valmask8[2];
 
 	switch (offset) {
 	/* bank 0 */
 	case 0 ... 15:
 		switch (offset) {
 		case ilog2(STS_USB30_PWRON):
-			val16[1] = CTL_USB30_PWRON;
+			valmask8[1] = CTL_USB30_PWRON;
 			break;
 		case ilog2(STS_USB31_PWRON):
-			val16[1] = CTL_USB31_PWRON;
+			valmask8[1] = CTL_USB31_PWRON;
 			break;
 		case ilog2(STS_ENABLE_4V5):
-			val16[1] = CTL_ENABLE_4V5;
+			valmask8[1] = CTL_ENABLE_4V5;
 			break;
 		case ilog2(STS_BUTTON_MODE):
-			val16[1] = CTL_BUTTON_MODE;
+			valmask8[1] = CTL_BUTTON_MODE;
 			break;
 		default:
 			return -EINVAL;
 		}
-		val16[0] = value ? val16[1] : 0;
-		return dm_i2c_write(dev, CMD_GENERAL_CONTROL, val16, sizeof(val16));
+
+		valmask8[0] = value ? valmask8[1] : 0;
+
+		return dm_i2c_write(dev, CMD_GENERAL_CONTROL, valmask8,
+				    sizeof(valmask8));
 
 	/* bank 2 - supported only when FEAT_EXT_CMDS and FEAT_PERIPH_MCU is set */
 	case (16 + 32 + 0) ... (16 + 32 + 15):
@@ -123,11 +134,12 @@ static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int valu
 			return -EINVAL;
 		if (!(info->features & FEAT_PERIPH_MCU))
 			return -EINVAL;
-		val32[3] = BIT(offset - 16 - 32) >> 8;
-		val32[2] = BIT(offset - 16 - 32) & 0xff;
-		val32[1] = value ? val32[3] : 0;
-		val32[0] = value ? val32[2] : 0;
-		return dm_i2c_write(dev, CMD_EXT_CONTROL, val32, sizeof(val32));
+
+		valmask16[1] = cpu_to_le16(BIT(offset - 16 - 32));
+		valmask16[0] = value ? valmask16[1] : 0;
+
+		return dm_i2c_write(dev, CMD_EXT_CONTROL, (void *)valmask16,
+				    sizeof(valmask16));
 
 	default:
 		return -EINVAL;
@@ -216,25 +228,25 @@ static int turris_omnia_mcu_probe(struct udevice *dev)
 {
 	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
 	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-	u16 status;
-	u8 val[2];
+	u16 val;
 	int ret;
 
-	ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, val, 2);
-	if (ret) {
-		printf("Error: turris_omnia_mcu CMD_GET_STATUS_WORD failed: %d\n", ret);
+	ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, (void *)&val, sizeof(val));
+	if (ret < 0) {
+		printf("Error: turris_omnia_mcu CMD_GET_STATUS_WORD failed: %d\n",
+		       ret);
 		return ret;
 	}
 
-	status = ((u16)val[1] << 8) | val[0];
-
-	if (status & STS_FEATURES_SUPPORTED) {
-		ret = dm_i2c_read(dev, CMD_GET_FEATURES, val, 2);
-		if (ret) {
-			printf("Error: turris_omnia_mcu CMD_GET_FEATURES failed: %d\n", ret);
+	if (le16_to_cpu(val) & STS_FEATURES_SUPPORTED) {
+		ret = dm_i2c_read(dev, CMD_GET_FEATURES, (void *)&val,
+				  sizeof(val));
+		if (ret < 0) {
+			printf("Error: turris_omnia_mcu CMD_GET_FEATURES failed: %d\n",
+			       ret);
 			return ret;
 		}
-		info->features = ((u16)val[1] << 8) | val[0];
+		info->features = le16_to_cpu(val);
 	}
 
 	uc_priv->bank_name = "mcu_";
Signature · 1 line
2.43.2
#14 lore raw

PATCH v2 13/18 gpio: turris_omnia_mcu: Update firmware features reading

In reply to Marek Behún

Update firmware features reading to try reading 32 bits of features and fallback to reading 16 bits.

---
 drivers/gpio/turris_omnia_mcu.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/gpio/turris_omnia_mcu.c +22 -10
index c441d07d69..40ced261e3 100644
@@ -10,7 +10,7 @@
 #include <linux/log2.h>
 
 struct turris_omnia_mcu_info {
-	u16 features;
+	u32 features;
 };
 
 static int turris_omnia_mcu_get_function(struct udevice *dev, uint offset)
@@ -228,25 +228,37 @@ static int turris_omnia_mcu_probe(struct udevice *dev)
 {
 	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
 	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-	u16 val;
+	u32 dword;
+	u16 word;
 	int ret;
 
-	ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, (void *)&val, sizeof(val));
+	ret = dm_i2c_read(dev, CMD_GET_STATUS_WORD, (void *)&word, sizeof(word));
 	if (ret < 0) {
 		printf("Error: turris_omnia_mcu CMD_GET_STATUS_WORD failed: %d\n",
 		       ret);
 		return ret;
 	}
 
-	if (le16_to_cpu(val) & STS_FEATURES_SUPPORTED) {
-		ret = dm_i2c_read(dev, CMD_GET_FEATURES, (void *)&val,
-				  sizeof(val));
+	if (le16_to_cpu(word) & STS_FEATURES_SUPPORTED) {
+		/* try read 32-bit features */
+		ret = dm_i2c_read(dev, CMD_GET_FEATURES, (void *)&dword,
+				  sizeof(dword));
 		if (ret < 0) {
-			printf("Error: turris_omnia_mcu CMD_GET_FEATURES failed: %d\n",
-			       ret);
-			return ret;
+			/* try read 16-bit features */
+			ret = dm_i2c_read(dev, CMD_GET_FEATURES, (void *)&word,
+					  sizeof(word));
+			if (ret < 0) {
+				printf("Error: turris_omnia_mcu CMD_GET_FEATURES failed: %d\n",
+				       ret);
+				return ret;
+			}
+
+			info->features = le16_to_cpu(word);
+		} else {
+			info->features = le32_to_cpu(dword);
+			if (info->features & FEAT_FROM_BIT_16_INVALID)
+				info->features &= GENMASK(15, 0);
 		}
-		info->features = le16_to_cpu(val);
 	}
 
 	uc_priv->bank_name = "mcu_";
Signature · 1 line
2.43.2
#15 lore raw

PATCH v2 14/18 gpio: turris_omnia_mcu: Add support for system power off via sysreset

In reply to Marek Behún

Add support for system power off via UCLASS_SYSRESET. Newer versions of Turris Omnia MCU firmware can power off the board (MCU will disable almost all voltage regulators and go into low power mode).

Move the MCU driver into drivers/misc and register it under UCLASS_MISC. The sysreset and gpio device are bound as child devices of the MCU device.

---
 configs/turris_omnia_defconfig            |   1 +
 drivers/gpio/Kconfig                      |   7 -
 drivers/gpio/Makefile                     |   1 -
 drivers/misc/Kconfig                      |  10 ++
 drivers/misc/Makefile                     |   1 +
 drivers/{gpio => misc}/turris_omnia_mcu.c | 150 ++++++++++++++++------
 6 files changed, 120 insertions(+), 50 deletions(-)
 rename drivers/{gpio => misc}/turris_omnia_mcu.c (60%)
configs/turris_omnia_defconfig +1 -0
index 39e15043df..9d5171c6a8 100644
@@ -113,6 +113,7 @@ CONFIG_SPL_DEBUG_UART_BASE=0xd0012000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+CONFIG_SYSRESET=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_EHCI_HCD=y
drivers/gpio/Kconfig +0 -7
index 2df3dc42d0..020c6ae74c 100644
@@ -662,13 +662,6 @@ config SLG7XL45106_I2C_GPO
 	   8-bit gpo expander, all gpo lines are controlled by writing
 	   value into data register.
 
-config TURRIS_OMNIA_MCU
-	bool "Turris Omnia MCU GPIO driver"
-	depends on DM_GPIO
-	default y if TARGET_TURRIS_OMNIA
-	help
-	   Support for GPIOs on MCU connected to Turris Omnia via i2c.
-
 config FTGPIO010
 	bool "Faraday Technology FTGPIO010 driver"
 	depends on DM_GPIO
drivers/gpio/Makefile +0 -1
index da3da5da2b..d637895c7a 100644
@@ -73,7 +73,6 @@ obj-$(CONFIG_$(SPL_)MAX77663_GPIO)	+= max77663_gpio.o
 obj-$(CONFIG_SL28CPLD_GPIO)	+= sl28cpld-gpio.o
 obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN)	+= zynqmp_gpio_modepin.o
 obj-$(CONFIG_SLG7XL45106_I2C_GPO)	+= gpio_slg7xl45106.o
-obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)	+= turris_omnia_mcu.o
 obj-$(CONFIG_FTGPIO010)		+= ftgpio010.o
 obj-$(CONFIG_ADP5585_GPIO)	+= adp5585_gpio.o
 obj-$(CONFIG_RZG2L_GPIO)	+= rzg2l-gpio.o
drivers/misc/Kconfig +10 -0
index f11ce72525..844a21be47 100644
@@ -505,6 +505,16 @@ config TEST_DRV
 	  model. This should only be enabled for testing as it is not useful for
 	  anything else.
 
+config TURRIS_OMNIA_MCU
+	bool "Enable Turris Omnia MCU driver"
+	depends on DM_I2C
+	depends on DM_GPIO
+	depends on SYSRESET
+	default y if TARGET_TURRIS_OMNIA
+	help
+	  This enables support for Turris Omnia MCU connected GPIOs and
+	  board power off.
+
 config USB_HUB_USB251XB
 	tristate "USB251XB Hub Controller Configuration Driver"
 	depends on I2C
drivers/misc/Makefile +1 -0
index 0432db6ed1..3cd8e2fd48 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
 obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
 obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
 obj-$(CONFIG_TEST_DRV) += test_drv.o
+obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU) += turris_omnia_mcu.o
 obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
drivers/misc/turris_omnia_mcu.c renamed from drivers/gpio/turris_omnia_mcu.c +108 -42

262 lines not on this page · raw message

Signature · 1 line
2.43.2
#16 lore raw

PATCH v2 15/18 arm: mvebu: turris_omnia: Enable poweroff command via sysreset in defconfig

In reply to Marek Behún

Enable support for the poweroff command via sysreset for Turris Omnia.

---
 configs/turris_omnia_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/turris_omnia_defconfig +2 -0
index 9d5171c6a8..0df0f3c90b 100644
@@ -65,6 +65,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_MTD=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_POWEROFF=y
 CONFIG_CMD_SATA=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
@@ -114,6 +115,7 @@ CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_SYSRESET=y
+CONFIG_SYSRESET_CMD_POWEROFF=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_EHCI_HCD=y
Signature · 1 line
2.43.2
#17 lore raw

PATCH v2 16/18 cmd: rng: Print "Abort" on -EINTR

In reply to Marek Behún

In the rng command, print
Abort
instead of
Reading RNG failed
if the error number is -EINTR.

---
 cmd/rng.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cmd/rng.c +4 -3
index 52f722c7af..48ba67061b 100644
@@ -17,7 +17,7 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	u8 buf[64];
 	int devnum;
 	struct udevice *dev;
-	int ret = CMD_RET_SUCCESS;
+	int ret = CMD_RET_SUCCESS, err;
 
 	switch (argc) {
 	case 1:
@@ -46,8 +46,9 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	n = min(n, sizeof(buf));
 
-	if (dm_rng_read(dev, buf, n)) {
-		printf("Reading RNG failed\n");
+	err = dm_rng_read(dev, buf, n);
+	if (err) {
+		puts(err == -EINTR ? "Abort\n" : "Reading RNG failed\n");
 		ret = CMD_RET_FAILURE;
 	} else {
 		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
Signature · 1 line
2.43.2
#18 lore raw

Re: [PATCH u-boot-mvebu v2 16/18] cmd: rng: Print "Abort" on -EINTR

Am 23. März 2024 19:07:09 MEZ schrieb "Marek Behún" <[email protected]>:

Quoted 5 lines

In the rng command, print
Abort
instead of
Reading RNG failed
if the error number is -EINTR.

It is unclear what would be the user benefit.

'Abort' relates to a user pressing CTRL-C?

Best regards

Heinrich

Quoted 31 lines

---
cmd/rng.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
cmd/rng.c +4 -3
index 52f722c7af..48ba67061b 100644
@@ -17,7 +17,7 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	u8 buf[64];
 	int devnum;
 	struct udevice *dev;
-	int ret = CMD_RET_SUCCESS;
+	int ret = CMD_RET_SUCCESS, err;
 
 	switch (argc) {
 	case 1:
@@ -46,8 +46,9 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	n = min(n, sizeof(buf));
 
-	if (dm_rng_read(dev, buf, n)) {
-		printf("Reading RNG failed\n");
+	err = dm_rng_read(dev, buf, n);
+	if (err) {
+		puts(err == -EINTR ? "Abort\n" : "Reading RNG failed\n");
 		ret = CMD_RET_FAILURE;
 	} else {
 		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
#19 lore raw

Re: [PATCH u-boot-mvebu v2 16/18] cmd: rng: Print "Abort" on -EINTR

Quoted 8 lines · On Sat, 23 Mar 2024 19:30:20 +0100 Heinrich Schuchardt <[email protected]>…

Am 23. März 2024 19:07:09 MEZ schrieb "Marek Behún" <[email protected]>:

Quoted 5 lines

In the rng command, print
Abort
instead of
Reading RNG failed
if the error number is -EINTR.

Quoted 4 lines

It is unclear what would be the user benefit.

'Abort' relates to a user pressing CTRL-C?

Precisely. The next patch of this series adds a rng driver that handles ctrlc() events.

Marek

#20 lore raw

PATCH v2 17/18 misc: turris_omnia_mcu: Add support for rng provided by MCU

In reply to Marek Behún

Add support for true random number generator provided by the MCU on Turris Omnia. The MCU firmware supports TRNG if the FEAT_TRNG bit is set in features. In that case we bind the rng driver.

---
 configs/turris_omnia_defconfig  |  1 +
 drivers/misc/Kconfig            |  1 +
 drivers/misc/turris_omnia_mcu.c | 57 +++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)
configs/turris_omnia_defconfig +1 -0
index 0df0f3c90b..4c21635ec9 100644
@@ -107,6 +107,7 @@ CONFIG_NVME_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_ARMADA_38X=y
+CONFIG_DM_RNG=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_ARMADA38X=y
 CONFIG_SERIAL_PROBE_ALL=y
drivers/misc/Kconfig +1 -0
index 844a21be47..a08f02196f 100644
@@ -509,6 +509,7 @@ config TURRIS_OMNIA_MCU
 	bool "Enable Turris Omnia MCU driver"
 	depends on DM_I2C
 	depends on DM_GPIO
+	depends on DM_RNG
 	depends on SYSRESET
 	default y if TARGET_TURRIS_OMNIA
 	help
drivers/misc/turris_omnia_mcu.c +57 -0

84 lines not on this page · raw message

Signature · 1 line
2.43.2
#21 lore raw

PATCH v2 18/18 arm: mvebu: turris_omnia: Enable rng command in defconfig

In reply to Marek Behún

Now that Turris Omnia has a rng driver provided in the MCU driver, enable the rng command in defconfig.

---
 configs/turris_omnia_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/turris_omnia_defconfig +1 -0
index 4c21635ec9..f2b39115fe 100644
@@ -73,6 +73,7 @@ CONFIG_CMD_WDT=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_RNG=y
 CONFIG_CMD_AES=y
 CONFIG_CMD_HASH=y
 CONFIG_CMD_BTRFS=y
Signature · 1 line
2.43.2