All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Add support for the GST ESPRESSOBin-Ultra board
@ 2021-08-12 23:39 Luka Kovacic
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-12 23:39 UTC (permalink / raw)
  To: u-boot
  Cc: robert.marko, luka.perkov, marek.behun, pali, sr, sjg,
	patrick.delaunay, xypron.glpk, Luka Kovacic

This patchset adds initial support for the ESPRESSOBin-Ultra board from
Globalscale Technologies, Inc.

The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
Peripherals:
 - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
 - RTC clock (PCF8563)
 - USB 3.0 port
 - USB 2.0 port
 - 4x LED
 - UART over Micro-USB
 - M.2 slot (2280)
 - Mini PCI-E slot

Additionally support for importing Marvell hw_info formatted environments
is added to fully support the board.

Changes for v3:
  - Use the common mac command instead of the vendor specific hw_info
  - Clean up the device tree to use a dtsi, like in Linux
  - Sync the defconfig with the latest mainline changes

Luka Kovacic (3):
  arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell
    hw_info)
  arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment
    variable
  arm: mvebu: Initial ESPRESSOBin-Ultra board support

 arch/arm/dts/Makefile                         |   1 +
 .../arm/dts/armada-3720-espressobin-ultra.dts | 114 +++++
 arch/arm/dts/armada-3720-espressobin.dts      | 199 +--------
 arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++
 arch/arm/mach-mvebu/Kconfig                   |   1 +
 board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
 board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
 board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
 board/Marvell/mvebu_armada-37xx/board.c       |  92 ++++-
 board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
 board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
 .../mvebu_espressobin-ultra-88f3720_defconfig |  93 +++++
 include/configs/mvebu_armada-37xx.h           |   8 +
 lib/hashtable.c                               |   2 +-
 14 files changed, 951 insertions(+), 205 deletions(-)
 create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
 create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
 create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
 create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
 create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
 create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig

-- 
2.31.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-12 23:39 [PATCH v3 0/3] Add support for the GST ESPRESSOBin-Ultra board Luka Kovacic
@ 2021-08-12 23:39 ` Luka Kovacic
  2021-08-13  1:43   ` Marek Behún
                     ` (2 more replies)
  2021-08-12 23:39 ` [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable Luka Kovacic
  2021-08-12 23:39 ` [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support Luka Kovacic
  2 siblings, 3 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-12 23:39 UTC (permalink / raw)
  To: u-boot
  Cc: robert.marko, luka.perkov, marek.behun, pali, sr, sjg,
	patrick.delaunay, xypron.glpk, Luka Kovacic

The mac command is implemented to enable parsing Marvell hw_info formatted
environments. This format is often used on Marvell Armada A37XX based
devices to store parameters like the board serial number, factory
MAC addresses and some other information.
These parameters are usually written to the flash in the factory.

Currently the mac command supports reading/writing parameters and dumping
the current hw_info parameters.
EEPROM config pattern and checksum aren't supported.

This functionality has been tested on the GST ESPRESSOBin-Ultra board
successfully, both reading the stock U-Boot parameters in mainline U-Boot
and reading the parameters written by this command in the stock U-Boot.

Usage example:
 => mac read
 => saveenv

Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Cc: Robert Marko <robert.marko@sartura.hr>
---
 arch/arm/mach-mvebu/Kconfig                   |   1 +
 board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
 board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
 board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
 board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
 include/configs/mvebu_armada-37xx.h           |   7 +
 lib/hashtable.c                               |   2 +-
 7 files changed, 436 insertions(+), 2 deletions(-)
 create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
 create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
 create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 89737a37ad..dff9f05b28 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
 	default 0
 	depends on SECURED_MODE_IMAGE
 
+source "board/Marvell/mvebu_armada-37xx/Kconfig"
 source "board/solidrun/clearfog/Kconfig"
 source "board/kobol/helios4/Kconfig"
 
diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
new file mode 100644
index 0000000000..b84dd20023
--- /dev/null
+++ b/board/Marvell/mvebu_armada-37xx/Kconfig
@@ -0,0 +1,29 @@
+menu "Marvell Armada 37xx configuration"
+depends on TARGET_MVEBU_ARMADA_37XX
+
+config MVEBU_MAC_HW_INFO
+	bool "Marvell hw_info (mac) support"
+	depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
+	default n
+	help
+	  Enable loading of the Marvell hw_info parameters from the
+	  SPI flash hw_info area. Parameters (usually the board serial
+	  number and MAC addresses) are then imported into the
+	  existing U-Boot environment.
+	  Implementation of this command is compatible with the
+	  original Marvell U-Boot command. Reading and writing is
+	  supported.
+	  EEPROM config pattern and checksum aren't supported.
+	  After enabled, these parameters are managed from the common
+	  U-Boot mac command.
+
+config MVEBU_MAC_HW_INFO_OFFSET
+	hex "Marvell hw_info (mac) SPI flash offset"
+	depends on MVEBU_MAC_HW_INFO
+	default 0x3E0000
+	help
+	  This option defines the SPI flash offset of the Marvell
+	  hw_info area. This defaults to 0x3E0000 on most Armada
+	  A3720 platforms.
+
+endmenu
diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
index 27221557c7..6f6ac6b193 100644
--- a/board/Marvell/mvebu_armada-37xx/Makefile
+++ b/board/Marvell/mvebu_armada-37xx/Makefile
@@ -2,4 +2,5 @@
 #
 # Copyright (C) 2016 Stefan Roese <sr@denx.de>
 
-obj-y	:= board.o
+obj-y += board.o
+obj-y += mac/
diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
new file mode 100644
index 0000000000..7c30fe6194
--- /dev/null
+++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2021 Sartura Ltd.
+
+obj-$(CONFIG_ID_EEPROM) += hw_info.o
diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
new file mode 100644
index 0000000000..91e5cd8dcf
--- /dev/null
+++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
@@ -0,0 +1,391 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Marvell hw_info (mac) command implementation
+ * Helper command for interfacing with the Marvell hw_info parameters
+ *
+ * Copyright (c) 2021 Sartura Ltd.
+ * Copyright (c) 2018 Marvell International Ltd.
+ *
+ * Author: Luka Kovacic <luka.kovacic@sartura.hr>
+ */
+
+#include <command.h>
+#include <common.h>
+#include <env.h>
+#include <env_internal.h>
+#include <spi.h>
+#include <spi_flash.h>
+
+#define HW_INFO_SPI_FLASH_OFFSET	CONFIG_MVEBU_MAC_HW_INFO_OFFSET
+
+#define HW_INFO_MAX_ENV_SIZE		0x1F0
+#define HW_INFO_ENV_OFFSET		0xA
+#define HW_INFO_ENV_SEP			0x20
+
+#define HW_INFO_MAX_NAME_LEN		32
+
+#define HW_INFO_MERGED_VARIABLE		"read_board_hw_info"
+
+static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
+	"pcb_slm",
+	"pcb_rev",
+	"eco_rev",
+	"pcb_sn",
+	"ethaddr",
+	"eth1addr",
+	"eth2addr",
+	"eth3addr",
+	"eth4addr",
+	"eth5addr",
+	"eth6addr",
+	"eth7addr",
+	"eth8addr",
+	"eth9addr",
+};
+
+static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
+					sizeof(hw_info_allowed_parameters[0]));
+
+static int hw_info_check_parameter(char *name)
+{
+	int idx;
+
+	for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
+		if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
+			return 0;
+	}
+
+	return -EINVAL;
+}
+
+/**
+ * read_spi_flash_offset() - Read data from the SPI flash
+ * @buf: Buffer to write in
+ * @offset: Offset from the flash start
+ *
+ * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
+ */
+static int read_spi_flash_offset(char *buf, int offset)
+{
+	struct spi_flash *flash;
+	int ret;
+
+	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
+				CONFIG_SF_DEFAULT_CS,
+				CONFIG_SF_DEFAULT_SPEED,
+				CONFIG_SF_DEFAULT_MODE);
+
+	if (!flash) {
+		printf("Error - unable to probe SPI flash.\n");
+		return -EIO;
+	}
+
+	ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
+	if (ret) {
+		printf("Error - unable to read hw_info environment from SPI flash.\n");
+		return ret;
+	}
+
+	return ret;
+}
+
+/**
+ * write_spi_flash_offset() - Write a buffer to SPI flash
+ * @buf: Buffer to write to SPI flash
+ * @offset: Offset from the flash start
+ * @size: Size of the buffer content
+ *
+ * This function probes the SPI flash and updates the specified flash location
+ * with new data from the buffer.
+ */
+static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
+{
+	ssize_t safe_size, erase_size;
+	struct spi_flash *flash;
+	int ret;
+
+	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
+				CONFIG_SF_DEFAULT_CS,
+				CONFIG_SF_DEFAULT_SPEED,
+				CONFIG_SF_DEFAULT_MODE);
+
+	if (!flash) {
+		printf("Error - unable to probe SPI flash.\n");
+		return -EIO;
+	}
+
+	safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
+	erase_size = safe_size +
+		     (flash->erase_size - safe_size % flash->erase_size);
+	ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
+	if (ret) {
+		printf("Error - unable to erase the hw_info area on SPI flash.\n");
+		return ret;
+	}
+	ret = spi_flash_write(flash, offset, safe_size, buf);
+	if (ret) {
+		printf("Error - unable to write hw_info parameters to SPI flash.\n");
+		return ret;
+	}
+
+	return ret;
+}
+
+/**
+ * cmd_hw_info_dump() - Dump the hw_info parameters
+ *
+ * This function prints all Marvell hw_info parameters, which are stored in
+ * the SPI flash.
+ */
+static int cmd_hw_info_dump(void)
+{
+	char buffer[HW_INFO_MAX_ENV_SIZE];
+	struct hsearch_data htab;
+	char *res = NULL;
+	ssize_t len;
+	int ret = 0;
+
+	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
+				    HW_INFO_ENV_OFFSET);
+	if (ret)
+		goto err;
+	memset(&htab, 0, sizeof(htab));
+	if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
+		ret = -ENOMEM;
+		goto err;
+	}
+	if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
+		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
+		ret = -EFAULT;
+		goto err_htab;
+	}
+
+	len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
+	if (len > 0) {
+		printf("Parameters (hw_info):\n");
+		puts(res);
+		free(res);
+		ret = 0;
+		goto ret_htab;
+	}
+ret_htab:
+	hdestroy_r(&htab);
+	return ret;
+err_htab:
+	hdestroy_r(&htab);
+err:
+	printf("## Error: cannot store hw_info parameters to SPI flash\n");
+	return ret;
+}
+
+/**
+ * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
+ * @print_env: Print U-Boot environment after new parameters are imported
+ *
+ * This function reads the Marvell hw_info parameters from SPI flash and
+ * imports them into the U-Boot env.
+ */
+static int cmd_hw_info_read(bool print_env)
+{
+	char buffer[HW_INFO_MAX_ENV_SIZE];
+	char *res = NULL;
+	ssize_t len;
+	int ret = 0;
+
+	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
+				    HW_INFO_ENV_OFFSET);
+	if (ret)
+		goto err;
+	if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
+		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
+		ret = -EFAULT;
+		goto err;
+	}
+
+	printf("Successfully imported the Marvell hw_info parameters.\n");
+	if (!print_env)
+		return 0;
+
+	len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
+	if (len > 0) {
+		printf("Updated environment:\n");
+		puts(res);
+		free(res);
+		return 0;
+	}
+err:
+	printf("## Error: cannot import hw_info parameters\n");
+	return ret;
+}
+
+/**
+ * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
+ * @name: Name of the U-Boot env parameter to save
+ *
+ * This function finds the specified parameter by name in the U-Boot env
+ * and then updates the Marvell hw_info parameters with the new value.
+ */
+static int cmd_hw_info_save(char *name)
+{
+	char buffer[HW_INFO_MAX_ENV_SIZE];
+	struct env_entry e, *ep, *rv;
+	struct hsearch_data htab;
+	char *res = NULL;
+	ssize_t len;
+	int ret = 0;
+
+	ret = hw_info_check_parameter(name);
+	if (ret) {
+		printf("Invalid parameter %s, stopping.\n", name);
+		goto err;
+	}
+
+	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
+				    HW_INFO_ENV_OFFSET);
+	if (ret)
+		goto err;
+	memset(&htab, 0, sizeof(htab));
+	if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
+		ret = -ENOMEM;
+		goto err;
+	}
+	if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
+		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
+		ret = -EFAULT;
+		goto err_htab;
+	}
+
+	e.key = name;
+	e.data = NULL;
+	if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
+		ret = -ENOENT;
+		goto err_htab;
+	}
+	if (!ep) {
+		ret = -ENOENT;
+		goto err_htab;
+	}
+
+	printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
+
+	e.key = ep->key;
+	e.data = ep->data;
+	if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
+		ret = -EINVAL;
+		goto err_htab;
+	}
+	if (!rv) {
+		ret = -EINVAL;
+		goto err_htab;
+	}
+	len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
+			&res, 0, 0, NULL);
+	if (len <= 0) {
+		free(res);
+		goto ret_htab;
+	}
+	ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
+				     HW_INFO_ENV_OFFSET, len);
+	free(res);
+	if (ret)
+		goto err_htab;
+
+	printf("Successfully stored the Marvell hw_info parameters.\n");
+	return 0;
+ret_htab:
+	hdestroy_r(&htab);
+	return ret;
+err_htab:
+	hdestroy_r(&htab);
+err:
+	printf("## Error: cannot store hw_info parameters to SPI flash\n");
+	return ret;
+}
+
+/**
+ * mac_read_from_eeprom() - Read the parameters from SPI flash.
+ *
+ * This function reads the content of the Marvell hw_info parameters from the
+ * SPI flash and imports them into the U-Boot environment.
+ * This includes MAC addresses and board serial numbers.
+ *
+ * The import is performed only once.
+ *
+ * This function is a part of the U-Boot mac command and must be executed
+ * after SPI flash initialization.
+ */
+int mac_read_from_eeprom(void)
+{
+	if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
+		if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
+			return -ENOENT;
+		return cmd_hw_info_read(false);
+	}
+	return 0;
+}
+
+/**
+ * print_platform_help() - Print the platform specific help
+ *
+ * Extend the existing U-Boot mac command description by also printing
+ * platform specific help text.
+ */
+static void print_platform_help(void)
+{
+	printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
+	       "are unavailable on Marvell Armada A37xx platforms.\n"
+	       "Use mac [read|save {parameter}] instead.\n"
+	       "Available parameters:\n"
+	       "pcb_slm\tPCB SLM number\n"
+	       "pcb_rev\tPCB revision number\n"
+	       "eco_rev\tECO revision number\n"
+	       "pcb_sn\tPCB SN\n"
+	       "ethaddr\tfirst MAC address\n"
+	       "eth[1-9]addr\tsecond-ninth MAC address\n");
+}
+
+/**
+ * do_mac() - Standard U-Boot mac command implementation
+ * @cmdtp: U-Boot command table
+ * @flag: Execution flags
+ * @argc: Count of arguments
+ * @argv: Arguments
+ *
+ * This function implements the standard U-Boot mac command in a mostly
+ * compatible way.
+ * To conform to the general command structure as much as possible, the
+ * command description from cmd/mac.c is followed.
+ * Where not possible, convenient or sensible additional comments for the user
+ * are added.
+ */
+int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	const char *cmd = argv[1];
+	int ret = 0;
+
+	if (argc == 1) {
+		ret = cmd_hw_info_dump();
+		if (ret)
+			return -EINVAL;
+		return CMD_RET_SUCCESS;
+	}
+
+	if (!strcmp(cmd, "read")) {
+		if (cmd_hw_info_read(true))
+			return -EINVAL;
+	} else if (!strcmp(cmd, "save")) {
+		if (argc != 3) {
+			printf("Please pass an additional argument to specify, "
+			       "which env parameter to save.\n");
+			return -EINVAL;
+		}
+		if (cmd_hw_info_save(argv[2]))
+			return -EINVAL;
+	} else {
+		ret = cmd_usage(cmdtp);
+		print_platform_help();
+		return ret;
+	}
+
+	return CMD_RET_SUCCESS;
+}
diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
index c8c34d7d92..8e8bcfa018 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -62,6 +62,13 @@
  */
 #define DEFAULT_ENV_IS_RW		/* required for configuring default fdtfile= */
 
+/*
+ * Platform identification (Marvell hw_info parameters)
+ */
+#ifdef CONFIG_MVEBU_MAC_HW_INFO
+#define CONFIG_ID_EEPROM /* U-Boot mac command */
+#endif
+
 /*
  * Ethernet Driver configuration
  */
diff --git a/lib/hashtable.c b/lib/hashtable.c
index ff5ff72639..06322e3304 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
  * multi-line values.
  *
  * In theory, arbitrary separator characters can be used, but only
- * '\0' and '\n' have really been tested.
+ * '\0', '\n' and 0x20 have been tested.
  */
 
 int himport_r(struct hsearch_data *htab,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-12 23:39 [PATCH v3 0/3] Add support for the GST ESPRESSOBin-Ultra board Luka Kovacic
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
@ 2021-08-12 23:39 ` Luka Kovacic
  2021-08-13  8:08   ` Pali Rohár
  2021-08-13 13:59   ` Pali Rohár
  2021-08-12 23:39 ` [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support Luka Kovacic
  2 siblings, 2 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-12 23:39 UTC (permalink / raw)
  To: u-boot
  Cc: robert.marko, luka.perkov, marek.behun, pali, sr, sjg,
	patrick.delaunay, xypron.glpk, Luka Kovacic

Add the loadaddr U-Boot environment variable, as this is available in
the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.

Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Cc: Robert Marko <robert.marko@sartura.hr>
---
 include/configs/mvebu_armada-37xx.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
index 8e8bcfa018..6901680e32 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -110,6 +110,7 @@
 
 /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
 #define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadaddr=0x6000000\0"		\
 	"scriptaddr=0x6d00000\0"	\
 	"pxefile_addr_r=0x6e00000\0"	\
 	"fdt_addr=0x6f00000\0"		\
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-12 23:39 [PATCH v3 0/3] Add support for the GST ESPRESSOBin-Ultra board Luka Kovacic
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
  2021-08-12 23:39 ` [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable Luka Kovacic
@ 2021-08-12 23:39 ` Luka Kovacic
  2021-08-13  8:14   ` Pali Rohár
  2021-08-13  9:27   ` Pali Rohár
  2 siblings, 2 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-12 23:39 UTC (permalink / raw)
  To: u-boot
  Cc: robert.marko, luka.perkov, marek.behun, pali, sr, sjg,
	patrick.delaunay, xypron.glpk, Luka Kovacic

Add initial support for the ESPRESSOBin-Ultra board from Globalscale
Technologies, Inc.

The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
Peripherals:
 - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
 - RTC clock (PCF8563)
 - USB 3.0 port
 - USB 2.0 port
 - 4x LED
 - UART over Micro-USB
 - M.2 slot (2280)
 - Mini PCI-E slot

Additionally, automatic import of the Marvell hw_info parameters is
enabled via the recently added mac command for A37XX platforms.
The parameters stored in Marvell hw_info are usually the board serial
number and MAC addresses.

Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Cc: Robert Marko <robert.marko@sartura.hr>
---
 arch/arm/dts/Makefile                         |   1 +
 .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
 arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
 arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
 board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
 board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
 .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
 7 files changed, 514 insertions(+), 203 deletions(-)
 create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
 create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
 create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index c42715ead4..f21c9c94d3 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
 dtb-$(CONFIG_ARCH_MVEBU) +=			\
 	armada-3720-db.dtb			\
 	armada-3720-espressobin.dtb		\
+	armada-3720-espressobin-ultra.dtb	\
 	armada-3720-turris-mox.dtb		\
 	armada-3720-uDPU.dtb			\
 	armada-375-db.dtb			\
diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
new file mode 100644
index 0000000000..5ad0c723e3
--- /dev/null
+++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Device Tree file for ESPRESSObin-Ultra board
+ * Copyright (C) 2016 Marvell
+ * Copyright (C) 2019 Globalscale technologies, Inc.
+ * Copyright (C) 2021 Sartura Ltd.
+ *
+ * Author: Jason Hung <jhung@globalscaletechnologies.com>
+ * Author: Luka Kovacic <luka.kovacic@sartura.hr>
+ * Author: Vladimir Vid <vladimir.vid@sartura.hr>
+ */
+
+/dts-v1/;
+
+#include "armada-3720-espressobin.dtsi"
+
+/ {
+	model = "Globalscale Marvell ESPRESSOBin Ultra Board";
+	compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
+
+	gpio-leds {
+		pinctrl-names = "default";
+		pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
+		compatible = "gpio-leds";
+
+		led1 {
+			label = "led1";
+			gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
+			default-state = "on";
+		};
+		led2 {
+			label = "led2";
+			gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
+			default-state = "on";
+		};
+		led3 {
+			label = "led3";
+			gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
+			default-state = "on";
+		};
+		led4 {
+			label = "led4";
+			gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
+			default-state = "on";
+		};
+	};
+};
+
+&pinctrl_nb {
+	led1_pins: led1-pins {
+		groups = "pwm0";
+		function = "gpio";
+	};
+	led2_pins: led2-pins {
+		groups = "pwm1";
+		function = "gpio";
+	};
+	led3_pins: led3-pins {
+		groups = "pwm2";
+		function = "gpio";
+	};
+	led4_pins: led4-pins {
+		groups = "pwm3";
+		function = "gpio";
+	};
+};
+
+&eth0 {
+	status = "okay";
+	phy_addr = <0x3>;
+};
+
+&i2c0 {
+	status = "okay";
+	#address-cells = <1>;
+	#size-cells = <0>;
+	rtc@51 {
+		compatible = "nxp,pcf8563";
+		reg = <0x51>;
+	};
+};
+
+&sata {
+	status = "okay";
+};
+
+&sdhci0 {
+	status = "disabled";
+};
+
+&sdhci1 {
+	status = "okay";
+};
+
+&spi0 {
+	status = "okay";
+};
+
+/* Exported on the micro USB connector through an FTDI */
+&uart0 {
+	status = "okay";
+};
+
+&usb2 {
+	status = "okay";
+};
+
+&usb3 {
+	status = "okay";
+};
+
+&pcie0 {
+	status = "okay";
+};
diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
index cba6139be6..925ce6a38e 100644
--- a/arch/arm/dts/armada-3720-espressobin.dts
+++ b/arch/arm/dts/armada-3720-espressobin.dts
@@ -1,210 +1,15 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 /*
  * Device Tree file for Marvell Armada 3720 community board
  * (ESPRESSOBin)
  * Copyright (C) 2016 Marvell
- *
- * Gregory CLEMENT <gregory.clement@free-electrons.com>
- * Konstantin Porotchkin <kostap@marvell.com>
- *
- * This file is dual-licensed: you can use it either under the terms
- * of the GPL or the X11 license, at your option. Note that this dual
- * licensing only applies to this file, and not this project as a
- * whole.
- *
- *  a) This file is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This file is distributed in the hope that it will be useful
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- * Or, alternatively
- *
- *  b) Permission is hereby granted, free of charge, to any person
- *     obtaining a copy of this software and associated documentation
- *     files (the "Software"), to deal in the Software without
- *     restriction, including without limitation the rights to use
- *     copy, modify, merge, publish, distribute, sublicense, and/or
- *     sell copies of the Software, and to permit persons to whom the
- *     Software is furnished to do so, subject to the following
- *     conditions:
- *
- *     The above copyright notice and this permission notice shall be
- *     included in all copies or substantial portions of the Software.
- *
- *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
- *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
- *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- *     OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /dts-v1/;
 
-#include "armada-372x.dtsi"
+#include "armada-3720-espressobin.dtsi"
 
 / {
 	model = "Globalscale Marvell ESPRESSOBin Board";
 	compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
-
-	chosen {
-		stdout-path = "serial0:115200n8";
-	};
-
-	aliases {
-		ethernet0 = &eth0;
-		i2c0 = &i2c0;
-		spi0 = &spi0;
-	};
-
-	memory {
-		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 {
-	max-lanes = <3>;
-	phy0 {
-		phy-type = <COMPHY_TYPE_USB3_HOST0>;
-		phy-speed = <COMPHY_SPEED_5G>;
-	};
-
-	phy1 {
-		phy-type = <COMPHY_TYPE_PEX0>;
-		phy-speed = <COMPHY_SPEED_2_5G>;
-	};
-
-	phy2 {
-		phy-type = <COMPHY_TYPE_SATA0>;
-		phy-speed = <COMPHY_SPEED_5G>;
-	};
-};
-
-&eth0 {
-	status = "okay";
-	pinctrl-names = "default";
-	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
-	phy-mode = "rgmii";
-	phy_addr = <0x1>;
-	fixed-link {
-		speed = <1000>;
-		full-duplex;
-	};
-};
-
-&i2c0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&i2c1_pins>;
-	status = "okay";
-};
-
-/* CON3 */
-&sata {
-	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";
-};
-
-/* U11 */
-&sdhci1 {
-	non-removable;
-	bus-width = <8>;
-	mmc-ddr-1_8v;
-	mmc-hs400-1_8v;
-	marvell,xenon-emmc;
-	marvell,xenon-tun-count = <9>;
-	marvell,pad-type = "fixed-1-8v";
-
-	pinctrl-names = "default";
-	pinctrl-0 = <&mmc_pins>;
-	status = "okay";
-
-	#address-cells = <1>;
-	#size-cells = <0>;
-	mmccard: mmccard@0 {
-		compatible = "mmc-card";
-		reg = <0>;
-	};
-};
-
-&spi0 {
-	status = "okay";
-	pinctrl-names = "default";
-	pinctrl-0 = <&spi_quad_pins>;
-
-	spi-flash@0 {
-		#address-cells = <1>;
-		#size-cells = <1>;
-		compatible = "st,m25p128", "jedec,spi-nor";
-		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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
-				label = "u-boot-env";
-			};
-		};
-#endif
-	};
-};
-
-/* Exported on the micro USB connector CON32 through an FTDI */
-&uart0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&uart1_pins>;
-	status = "okay";
-};
-
-/* CON29 */
-&usb2 {
-	status = "okay";
-};
-
-/* CON31 */
-&usb3 {
-	status = "okay";
-};
-
-&pcie0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&pcie_pins>;
-	reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
-	status = "okay";
 };
diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
new file mode 100644
index 0000000000..cba6139be6
--- /dev/null
+++ b/arch/arm/dts/armada-3720-espressobin.dtsi
@@ -0,0 +1,210 @@
+/*
+ * Device Tree file for Marvell Armada 3720 community board
+ * (ESPRESSOBin)
+ * Copyright (C) 2016 Marvell
+ *
+ * Gregory CLEMENT <gregory.clement@free-electrons.com>
+ * Konstantin Porotchkin <kostap@marvell.com>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of the
+ *     License, or (at your option) any later version.
+ *
+ *     This file is distributed in the hope that it will be useful
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ * Or, alternatively
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+
+#include "armada-372x.dtsi"
+
+/ {
+	model = "Globalscale Marvell ESPRESSOBin Board";
+	compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+	};
+
+	aliases {
+		ethernet0 = &eth0;
+		i2c0 = &i2c0;
+		spi0 = &spi0;
+	};
+
+	memory {
+		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 {
+	max-lanes = <3>;
+	phy0 {
+		phy-type = <COMPHY_TYPE_USB3_HOST0>;
+		phy-speed = <COMPHY_SPEED_5G>;
+	};
+
+	phy1 {
+		phy-type = <COMPHY_TYPE_PEX0>;
+		phy-speed = <COMPHY_SPEED_2_5G>;
+	};
+
+	phy2 {
+		phy-type = <COMPHY_TYPE_SATA0>;
+		phy-speed = <COMPHY_SPEED_5G>;
+	};
+};
+
+&eth0 {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
+	phy-mode = "rgmii";
+	phy_addr = <0x1>;
+	fixed-link {
+		speed = <1000>;
+		full-duplex;
+	};
+};
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+	status = "okay";
+};
+
+/* CON3 */
+&sata {
+	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";
+};
+
+/* U11 */
+&sdhci1 {
+	non-removable;
+	bus-width = <8>;
+	mmc-ddr-1_8v;
+	mmc-hs400-1_8v;
+	marvell,xenon-emmc;
+	marvell,xenon-tun-count = <9>;
+	marvell,pad-type = "fixed-1-8v";
+
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc_pins>;
+	status = "okay";
+
+	#address-cells = <1>;
+	#size-cells = <0>;
+	mmccard: mmccard@0 {
+		compatible = "mmc-card";
+		reg = <0>;
+	};
+};
+
+&spi0 {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&spi_quad_pins>;
+
+	spi-flash@0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "st,m25p128", "jedec,spi-nor";
+		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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
+				label = "u-boot-env";
+			};
+		};
+#endif
+	};
+};
+
+/* Exported on the micro USB connector CON32 through an FTDI */
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart1_pins>;
+	status = "okay";
+};
+
+/* CON29 */
+&usb2 {
+	status = "okay";
+};
+
+/* CON31 */
+&usb3 {
+	status = "okay";
+};
+
+&pcie0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pcie_pins>;
+	reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
+	status = "okay";
+};
diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
index f2c0a582d7..d69af832fc 100644
--- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
+++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
@@ -10,6 +10,14 @@ M:	Konstantin Porotchkin <kostap@marvell.com>
 S:	Maintained
 F:	configs/mvebu_espressobin-88f3720_defconfig
 
+ESPRESSOBin-Ultra BOARD
+M:	Luka Kovacic <luka.kovacic@sartura.hr>
+M:	Robert Marko <robert.marko@sartura.hr>
+M:	Luka Perkov <luka.perkov@sartura.hr>
+S:	Maintained
+F:	arch/arm/dts/armada-3720-espressobin-ultra.dts
+F:	configs/mvebu_espressobin-ultra-88f3720_defconfig
+
 uDPU BOARD
 M:	Vladimir Vid <vladimir.vid@sartura.hr>
 S:	Maintained
diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
index 2de9c2ac17..21c1eb7b22 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -11,6 +11,7 @@
 #include <i2c.h>
 #include <init.h>
 #include <mmc.h>
+#include <miiphy.h>
 #include <phy.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
 #define MVEBU_G2_SMI_PHY_CMD_REG	(24)
 #define MVEBU_G2_SMI_PHY_DATA_REG	(25)
 
+/* Marvell 88E1512 */
+#define MII_MARVELL_PHY_PAGE		22
+
+#define MV88E1512_GENERAL_CTRL		20
+#define MV88E1512_MODE_SGMII		1
+#define MV88E1512_RESET_OFFS		15
+
+#define ULTRA_MV88E1512_PHYADDR		0x1
+
 /*
  * Memory Controller Registers
  *
@@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
 	return 0;
 }
 
-/* Bring-up board-specific network stuff */
-int board_network_enable(struct mii_dev *bus)
+void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
 {
-	if (!of_machine_is_compatible("globalscale,espressobin"))
-		return 0;
+	const char *name;
+	u16 reg;
+
+	name = miiphy_get_current_dev();
+	if (name) {
+		/* SGMII-to-Copper mode initialization */
+
+		/* Select page 18 */
+		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
+		/* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
+		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
+		reg &= ~0x7;
+		reg |= MV88E1512_MODE_SGMII;
+		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
+		/* PHY reset is necessary after changing MODE[2:0] */
+		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
+		reg |= 1 << MV88E1512_RESET_OFFS;
+		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
+		/* Reset page selection */
+		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
+		udelay(100);
+	}
+}
+
+int board_network_enable_espressobin_ultra(struct mii_dev *bus)
+{
+	int i;
+	/* Setup 88E1512 SGMII-to-Copper mode */
+	force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
 
+	/*
+	 * FIXME: remove this code once Topaz driver gets available
+	 * A3720 ESPRESSObin Ultra Board Only
+	 * Configure Topaz switch (88E6341)
+	 * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
+	 */
+	for (i = 0; i <= 5; i++) {
+		mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
+					  MVEBU_SW_PORT_CTRL_REG,
+					  i == 5 ? 0x7c : 0x7f);
+	}
+
+	/* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
+	mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
+				  MVEBU_SW_LINK_CTRL_REG, 0xe002);
+
+	/* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
+	mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
+				  MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
+	for (i = 1; i <= 5; i++) {
+		mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
+					  MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
+					  (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
+	}
+
+	return 0;
+}
+
+int board_network_enable_espressobin(struct mii_dev *bus)
+{
 	/*
 	 * FIXME: remove this code once Topaz driver gets available
 	 * A3720 Community Board Only
@@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
 	return 0;
 }
 
+/* Bring-up the board-specific networking */
+int board_network_enable(struct mii_dev *bus)
+{
+	if (of_machine_is_compatible("globalscale,espressobin"))
+		return board_network_enable_espressobin(bus);
+	if (of_machine_is_compatible("globalscale,espressobin-ultra"))
+		return board_network_enable_espressobin_ultra(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)
 {
@@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	int parts_off;
 	int part_off;
 
-	/* Fill SPI MTD partitions for Linux kernel on Espressobin */
-	if (!of_machine_is_compatible("globalscale,espressobin"))
+	/*
+	 * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
+	 * ESPRESSOBin Ultra boards.
+	 */
+	if (!of_machine_is_compatible("globalscale,espressobin") &&
+	    !of_machine_is_compatible("globalscale,espressobin-ultra"))
 		return 0;
 
 	spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
new file mode 100644
index 0000000000..1bac0a96ad
--- /dev/null
+++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
@@ -0,0 +1,93 @@
+CONFIG_ARM=y
+CONFIG_ARCH_CPU_INIT=y
+CONFIG_ARCH_MVEBU=y
+CONFIG_SYS_TEXT_BASE=0x00000000
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_TARGET_MVEBU_ARMADA_37XX=y
+CONFIG_ENV_SIZE=0x10000
+CONFIG_ENV_OFFSET=0x3F0000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_DM_GPIO=y
+CONFIG_DEBUG_UART_BASE=0xd0012000
+CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
+CONFIG_DEBUG_UART=y
+CONFIG_AHCI=y
+CONFIG_DISTRO_DEFAULTS=y
+# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
+CONFIG_OF_BOARD_SETUP=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_BEST_MATCH=y
+CONFIG_AUTOBOOT_KEYED=y
+CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
+CONFIG_AUTOBOOT_STOP_STR="s"
+CONFIG_AUTOBOOT_KEYED_CTRLC=y
+CONFIG_HUSH_PARSER=y
+CONFIG_SYS_CONSOLE_INFO_QUIET=y
+# CONFIG_DISPLAY_CPUINFO is not set
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_ARCH_EARLY_INIT_R=y
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_BOARD_LATE_INIT=y
+# CONFIG_CMD_FLASH is not set
+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
+CONFIG_CMD_WDT=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_TFTPPUT=y
+CONFIG_CMD_CACHE=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_MVEBU_BUBT=y
+CONFIG_MVEBU_MAC_HW_INFO=y
+CONFIG_CMD_EXT4_WRITE=y
+CONFIG_MAC_PARTITION=y
+CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_AHCI_MVEBU=y
+CONFIG_CLK=y
+CONFIG_CLK_MVEBU=y
+CONFIG_DM_I2C=y
+CONFIG_MISC=y
+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_SPI_FLASH_MACRONIX=y
+CONFIG_SPI_FLASH_MTD=y
+CONFIG_PHY_MARVELL=y
+CONFIG_PHY_GIGE=y
+CONFIG_MVNETA=y
+CONFIG_PCI=y
+CONFIG_PCI_AARDVARK=y
+CONFIG_PHY=y
+CONFIG_MVEBU_COMPHY_SUPPORT=y
+CONFIG_PINCTRL=y
+CONFIG_PINCTRL_ARMADA_37XX=y
+CONFIG_DM_REGULATOR_GPIO=y
+CONFIG_DEBUG_UART_SHIFT=2
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_MVEBU_A3700_UART=y
+CONFIG_MVEBU_A3700_SPI=y
+CONFIG_USB=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_HOST_ETHER=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ARMADA_37XX=y
+CONFIG_SHA1=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_PCF8563=y
+CONFIG_LED=y
+CONFIG_LED_GPIO=y
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
@ 2021-08-13  1:43   ` Marek Behún
  2021-08-13  8:23   ` Pali Rohár
  2021-08-13 10:29   ` Pali Rohár
  2 siblings, 0 replies; 36+ messages in thread
From: Marek Behún @ 2021-08-13  1:43 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, pali, sr, sjg,
	patrick.delaunay, xypron.glpk

On Fri, 13 Aug 2021 01:39:36 +0200
Luka Kovacic <luka.kovacic@sartura.hr> wrote:

> The mac command is implemented to enable parsing Marvell hw_info formatted
> environments. This format is often used on Marvell Armada A37XX based
> devices to store parameters like the board serial number, factory
> MAC addresses and some other information.
> These parameters are usually written to the flash in the factory.
> 
> Currently the mac command supports reading/writing parameters and dumping
> the current hw_info parameters.
> EEPROM config pattern and checksum aren't supported.
> 
> This functionality has been tested on the GST ESPRESSOBin-Ultra board
> successfully, both reading the stock U-Boot parameters in mainline U-Boot
> and reading the parameters written by this command in the stock U-Boot.
> 
> Usage example:
>  => mac read
>  => saveenv  

I think the mac/fuse commands should be killed and nvmem API should be
implemented as is in Linux, with a corresponding nvmem command.

Marek

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-12 23:39 ` [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable Luka Kovacic
@ 2021-08-13  8:08   ` Pali Rohár
  2021-08-13  8:59     ` Luka Kovacic
  2021-08-13 13:59   ` Pali Rohár
  1 sibling, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  8:08 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> Add the loadaddr U-Boot environment variable, as this is available in
> the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.

Hello Luka! Why is this change needed? Reason that it is in historic
vendor U-Boot does not mean that it has to be also in new mainline
version.

I have already wrote some reasons in previous review thread:
https://lore.kernel.org/u-boot/20210301150505.3iajeeufi7ahsnk3@pali/

I think this change was needed when CONFIG_SYS_LOAD_ADDR was set to
incorrect value, which is already fixed in mainline U-Boot.

> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Robert Marko <robert.marko@sartura.hr>
> ---
>  include/configs/mvebu_armada-37xx.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> index 8e8bcfa018..6901680e32 100644
> --- a/include/configs/mvebu_armada-37xx.h
> +++ b/include/configs/mvebu_armada-37xx.h
> @@ -110,6 +110,7 @@
>  
>  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
>  #define CONFIG_EXTRA_ENV_SETTINGS	\
> +	"loadaddr=0x6000000\0"		\
>  	"scriptaddr=0x6d00000\0"	\
>  	"pxefile_addr_r=0x6e00000\0"	\
>  	"fdt_addr=0x6f00000\0"		\
> -- 
> 2.31.1
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-12 23:39 ` [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support Luka Kovacic
@ 2021-08-13  8:14   ` Pali Rohár
  2021-08-13  9:08     ` Luka Kovacic
  2021-08-13  9:27   ` Pali Rohár
  1 sibling, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  8:14 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> Technologies, Inc.
> 
> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> Peripherals:
>  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
>  - RTC clock (PCF8563)
>  - USB 3.0 port
>  - USB 2.0 port
>  - 4x LED
>  - UART over Micro-USB
>  - M.2 slot (2280)
>  - Mini PCI-E slot
> 
> Additionally, automatic import of the Marvell hw_info parameters is
> enabled via the recently added mac command for A37XX platforms.
> The parameters stored in Marvell hw_info are usually the board serial
> number and MAC addresses.
> 
> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Robert Marko <robert.marko@sartura.hr>
> ---
>  arch/arm/dts/Makefile                         |   1 +
>  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
>  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
>  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
>  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
>  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
>  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
>  7 files changed, 514 insertions(+), 203 deletions(-)
>  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
>  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
>  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig

Hello Luka! Please look at my comments from previous review:
https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/

I think it is not a good idea to duplicate espressobin code, specially
now when differences between v5, v7, non-emmc and emmc were
de-duplicated and correctly detected at runtime. Just use one DTS and
one config file and differences can be handled in board code functions
"board_fix_fdt" and "board_late_init".

> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index c42715ead4..f21c9c94d3 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
>  dtb-$(CONFIG_ARCH_MVEBU) +=			\
>  	armada-3720-db.dtb			\
>  	armada-3720-espressobin.dtb		\
> +	armada-3720-espressobin-ultra.dtb	\
>  	armada-3720-turris-mox.dtb		\
>  	armada-3720-uDPU.dtb			\
>  	armada-375-db.dtb			\
> diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> new file mode 100644
> index 0000000000..5ad0c723e3
> --- /dev/null
> +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> @@ -0,0 +1,114 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> +/*
> + * Device Tree file for ESPRESSObin-Ultra board
> + * Copyright (C) 2016 Marvell
> + * Copyright (C) 2019 Globalscale technologies, Inc.
> + * Copyright (C) 2021 Sartura Ltd.
> + *
> + * Author: Jason Hung <jhung@globalscaletechnologies.com>
> + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
> + */
> +
> +/dts-v1/;
> +
> +#include "armada-3720-espressobin.dtsi"
> +
> +/ {
> +	model = "Globalscale Marvell ESPRESSOBin Ultra Board";
> +	compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
> +
> +	gpio-leds {
> +		pinctrl-names = "default";
> +		pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
> +		compatible = "gpio-leds";
> +
> +		led1 {
> +			label = "led1";
> +			gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
> +			default-state = "on";
> +		};
> +		led2 {
> +			label = "led2";
> +			gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
> +			default-state = "on";
> +		};
> +		led3 {
> +			label = "led3";
> +			gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
> +			default-state = "on";
> +		};
> +		led4 {
> +			label = "led4";
> +			gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
> +			default-state = "on";
> +		};
> +	};
> +};
> +
> +&pinctrl_nb {
> +	led1_pins: led1-pins {
> +		groups = "pwm0";
> +		function = "gpio";
> +	};
> +	led2_pins: led2-pins {
> +		groups = "pwm1";
> +		function = "gpio";
> +	};
> +	led3_pins: led3-pins {
> +		groups = "pwm2";
> +		function = "gpio";
> +	};
> +	led4_pins: led4-pins {
> +		groups = "pwm3";
> +		function = "gpio";
> +	};
> +};
> +
> +&eth0 {
> +	status = "okay";
> +	phy_addr = <0x3>;
> +};
> +
> +&i2c0 {
> +	status = "okay";
> +	#address-cells = <1>;
> +	#size-cells = <0>;
> +	rtc@51 {
> +		compatible = "nxp,pcf8563";
> +		reg = <0x51>;
> +	};
> +};
> +
> +&sata {
> +	status = "okay";
> +};
> +
> +&sdhci0 {
> +	status = "disabled";
> +};
> +
> +&sdhci1 {
> +	status = "okay";
> +};
> +
> +&spi0 {
> +	status = "okay";
> +};
> +
> +/* Exported on the micro USB connector through an FTDI */
> +&uart0 {
> +	status = "okay";
> +};
> +
> +&usb2 {
> +	status = "okay";
> +};
> +
> +&usb3 {
> +	status = "okay";
> +};
> +
> +&pcie0 {
> +	status = "okay";
> +};
> diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
> index cba6139be6..925ce6a38e 100644
> --- a/arch/arm/dts/armada-3720-espressobin.dts
> +++ b/arch/arm/dts/armada-3720-espressobin.dts
> @@ -1,210 +1,15 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>  /*
>   * Device Tree file for Marvell Armada 3720 community board
>   * (ESPRESSOBin)
>   * Copyright (C) 2016 Marvell
> - *
> - * Gregory CLEMENT <gregory.clement@free-electrons.com>
> - * Konstantin Porotchkin <kostap@marvell.com>
> - *
> - * This file is dual-licensed: you can use it either under the terms
> - * of the GPL or the X11 license, at your option. Note that this dual
> - * licensing only applies to this file, and not this project as a
> - * whole.
> - *
> - *  a) This file is free software; you can redistribute it and/or
> - *     modify it under the terms of the GNU General Public License as
> - *     published by the Free Software Foundation; either version 2 of the
> - *     License, or (at your option) any later version.
> - *
> - *     This file is distributed in the hope that it will be useful
> - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - *     GNU General Public License for more details.
> - *
> - * Or, alternatively
> - *
> - *  b) Permission is hereby granted, free of charge, to any person
> - *     obtaining a copy of this software and associated documentation
> - *     files (the "Software"), to deal in the Software without
> - *     restriction, including without limitation the rights to use
> - *     copy, modify, merge, publish, distribute, sublicense, and/or
> - *     sell copies of the Software, and to permit persons to whom the
> - *     Software is furnished to do so, subject to the following
> - *     conditions:
> - *
> - *     The above copyright notice and this permission notice shall be
> - *     included in all copies or substantial portions of the Software.
> - *
> - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> - *     OTHER DEALINGS IN THE SOFTWARE.
>   */
>  
>  /dts-v1/;
>  
> -#include "armada-372x.dtsi"
> +#include "armada-3720-espressobin.dtsi"
>  
>  / {
>  	model = "Globalscale Marvell ESPRESSOBin Board";
>  	compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> -
> -	chosen {
> -		stdout-path = "serial0:115200n8";
> -	};
> -
> -	aliases {
> -		ethernet0 = &eth0;
> -		i2c0 = &i2c0;
> -		spi0 = &spi0;
> -	};
> -
> -	memory {
> -		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 {
> -	max-lanes = <3>;
> -	phy0 {
> -		phy-type = <COMPHY_TYPE_USB3_HOST0>;
> -		phy-speed = <COMPHY_SPEED_5G>;
> -	};
> -
> -	phy1 {
> -		phy-type = <COMPHY_TYPE_PEX0>;
> -		phy-speed = <COMPHY_SPEED_2_5G>;
> -	};
> -
> -	phy2 {
> -		phy-type = <COMPHY_TYPE_SATA0>;
> -		phy-speed = <COMPHY_SPEED_5G>;
> -	};
> -};
> -
> -&eth0 {
> -	status = "okay";
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> -	phy-mode = "rgmii";
> -	phy_addr = <0x1>;
> -	fixed-link {
> -		speed = <1000>;
> -		full-duplex;
> -	};
> -};
> -
> -&i2c0 {
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&i2c1_pins>;
> -	status = "okay";
> -};
> -
> -/* CON3 */
> -&sata {
> -	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";
> -};
> -
> -/* U11 */
> -&sdhci1 {
> -	non-removable;
> -	bus-width = <8>;
> -	mmc-ddr-1_8v;
> -	mmc-hs400-1_8v;
> -	marvell,xenon-emmc;
> -	marvell,xenon-tun-count = <9>;
> -	marvell,pad-type = "fixed-1-8v";
> -
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&mmc_pins>;
> -	status = "okay";
> -
> -	#address-cells = <1>;
> -	#size-cells = <0>;
> -	mmccard: mmccard@0 {
> -		compatible = "mmc-card";
> -		reg = <0>;
> -	};
> -};
> -
> -&spi0 {
> -	status = "okay";
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&spi_quad_pins>;
> -
> -	spi-flash@0 {
> -		#address-cells = <1>;
> -		#size-cells = <1>;
> -		compatible = "st,m25p128", "jedec,spi-nor";
> -		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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> -				label = "u-boot-env";
> -			};
> -		};
> -#endif
> -	};
> -};
> -
> -/* Exported on the micro USB connector CON32 through an FTDI */
> -&uart0 {
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&uart1_pins>;
> -	status = "okay";
> -};
> -
> -/* CON29 */
> -&usb2 {
> -	status = "okay";
> -};
> -
> -/* CON31 */
> -&usb3 {
> -	status = "okay";
> -};
> -
> -&pcie0 {
> -	pinctrl-names = "default";
> -	pinctrl-0 = <&pcie_pins>;
> -	reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> -	status = "okay";
>  };
> diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
> new file mode 100644
> index 0000000000..cba6139be6
> --- /dev/null
> +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
> @@ -0,0 +1,210 @@
> +/*
> + * Device Tree file for Marvell Armada 3720 community board
> + * (ESPRESSOBin)
> + * Copyright (C) 2016 Marvell
> + *
> + * Gregory CLEMENT <gregory.clement@free-electrons.com>
> + * Konstantin Porotchkin <kostap@marvell.com>
> + *
> + * This file is dual-licensed: you can use it either under the terms
> + * of the GPL or the X11 license, at your option. Note that this dual
> + * licensing only applies to this file, and not this project as a
> + * whole.
> + *
> + *  a) This file is free software; you can redistribute it and/or
> + *     modify it under the terms of the GNU General Public License as
> + *     published by the Free Software Foundation; either version 2 of the
> + *     License, or (at your option) any later version.
> + *
> + *     This file is distributed in the hope that it will be useful
> + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *     GNU General Public License for more details.
> + *
> + * Or, alternatively
> + *
> + *  b) Permission is hereby granted, free of charge, to any person
> + *     obtaining a copy of this software and associated documentation
> + *     files (the "Software"), to deal in the Software without
> + *     restriction, including without limitation the rights to use
> + *     copy, modify, merge, publish, distribute, sublicense, and/or
> + *     sell copies of the Software, and to permit persons to whom the
> + *     Software is furnished to do so, subject to the following
> + *     conditions:
> + *
> + *     The above copyright notice and this permission notice shall be
> + *     included in all copies or substantial portions of the Software.
> + *
> + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + *     OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +/dts-v1/;
> +
> +#include "armada-372x.dtsi"
> +
> +/ {
> +	model = "Globalscale Marvell ESPRESSOBin Board";
> +	compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> +
> +	chosen {
> +		stdout-path = "serial0:115200n8";
> +	};
> +
> +	aliases {
> +		ethernet0 = &eth0;
> +		i2c0 = &i2c0;
> +		spi0 = &spi0;
> +	};
> +
> +	memory {
> +		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 {
> +	max-lanes = <3>;
> +	phy0 {
> +		phy-type = <COMPHY_TYPE_USB3_HOST0>;
> +		phy-speed = <COMPHY_SPEED_5G>;
> +	};
> +
> +	phy1 {
> +		phy-type = <COMPHY_TYPE_PEX0>;
> +		phy-speed = <COMPHY_SPEED_2_5G>;
> +	};
> +
> +	phy2 {
> +		phy-type = <COMPHY_TYPE_SATA0>;
> +		phy-speed = <COMPHY_SPEED_5G>;
> +	};
> +};
> +
> +&eth0 {
> +	status = "okay";
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> +	phy-mode = "rgmii";
> +	phy_addr = <0x1>;
> +	fixed-link {
> +		speed = <1000>;
> +		full-duplex;
> +	};
> +};
> +
> +&i2c0 {
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&i2c1_pins>;
> +	status = "okay";
> +};
> +
> +/* CON3 */
> +&sata {
> +	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";
> +};
> +
> +/* U11 */
> +&sdhci1 {
> +	non-removable;
> +	bus-width = <8>;
> +	mmc-ddr-1_8v;
> +	mmc-hs400-1_8v;
> +	marvell,xenon-emmc;
> +	marvell,xenon-tun-count = <9>;
> +	marvell,pad-type = "fixed-1-8v";
> +
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&mmc_pins>;
> +	status = "okay";
> +
> +	#address-cells = <1>;
> +	#size-cells = <0>;
> +	mmccard: mmccard@0 {
> +		compatible = "mmc-card";
> +		reg = <0>;
> +	};
> +};
> +
> +&spi0 {
> +	status = "okay";
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&spi_quad_pins>;
> +
> +	spi-flash@0 {
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +		compatible = "st,m25p128", "jedec,spi-nor";
> +		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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> +				label = "u-boot-env";
> +			};
> +		};
> +#endif
> +	};
> +};
> +
> +/* Exported on the micro USB connector CON32 through an FTDI */
> +&uart0 {
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&uart1_pins>;
> +	status = "okay";
> +};
> +
> +/* CON29 */
> +&usb2 {
> +	status = "okay";
> +};
> +
> +/* CON31 */
> +&usb3 {
> +	status = "okay";
> +};
> +
> +&pcie0 {
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&pcie_pins>;
> +	reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> +	status = "okay";
> +};
> diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> index f2c0a582d7..d69af832fc 100644
> --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> @@ -10,6 +10,14 @@ M:	Konstantin Porotchkin <kostap@marvell.com>
>  S:	Maintained
>  F:	configs/mvebu_espressobin-88f3720_defconfig
>  
> +ESPRESSOBin-Ultra BOARD
> +M:	Luka Kovacic <luka.kovacic@sartura.hr>
> +M:	Robert Marko <robert.marko@sartura.hr>
> +M:	Luka Perkov <luka.perkov@sartura.hr>
> +S:	Maintained
> +F:	arch/arm/dts/armada-3720-espressobin-ultra.dts
> +F:	configs/mvebu_espressobin-ultra-88f3720_defconfig
> +
>  uDPU BOARD
>  M:	Vladimir Vid <vladimir.vid@sartura.hr>
>  S:	Maintained
> diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> index 2de9c2ac17..21c1eb7b22 100644
> --- a/board/Marvell/mvebu_armada-37xx/board.c
> +++ b/board/Marvell/mvebu_armada-37xx/board.c
> @@ -11,6 +11,7 @@
>  #include <i2c.h>
>  #include <init.h>
>  #include <mmc.h>
> +#include <miiphy.h>
>  #include <phy.h>
>  #include <asm/global_data.h>
>  #include <asm/io.h>
> @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
>  #define MVEBU_G2_SMI_PHY_CMD_REG	(24)
>  #define MVEBU_G2_SMI_PHY_DATA_REG	(25)
>  
> +/* Marvell 88E1512 */
> +#define MII_MARVELL_PHY_PAGE		22
> +
> +#define MV88E1512_GENERAL_CTRL		20
> +#define MV88E1512_MODE_SGMII		1
> +#define MV88E1512_RESET_OFFS		15
> +
> +#define ULTRA_MV88E1512_PHYADDR		0x1
> +
>  /*
>   * Memory Controller Registers
>   *
> @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
>  	return 0;
>  }
>  
> -/* Bring-up board-specific network stuff */
> -int board_network_enable(struct mii_dev *bus)
> +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
>  {
> -	if (!of_machine_is_compatible("globalscale,espressobin"))
> -		return 0;
> +	const char *name;
> +	u16 reg;
> +
> +	name = miiphy_get_current_dev();
> +	if (name) {
> +		/* SGMII-to-Copper mode initialization */
> +
> +		/* Select page 18 */
> +		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> +		/* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> +		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> +		reg &= ~0x7;
> +		reg |= MV88E1512_MODE_SGMII;
> +		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> +		/* PHY reset is necessary after changing MODE[2:0] */
> +		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> +		reg |= 1 << MV88E1512_RESET_OFFS;
> +		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> +		/* Reset page selection */
> +		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> +		udelay(100);
> +	}
> +}
> +
> +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> +{
> +	int i;
> +	/* Setup 88E1512 SGMII-to-Copper mode */
> +	force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
>  
> +	/*
> +	 * FIXME: remove this code once Topaz driver gets available
> +	 * A3720 ESPRESSObin Ultra Board Only
> +	 * Configure Topaz switch (88E6341)
> +	 * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> +	 */
> +	for (i = 0; i <= 5; i++) {
> +		mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> +					  MVEBU_SW_PORT_CTRL_REG,
> +					  i == 5 ? 0x7c : 0x7f);
> +	}
> +
> +	/* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> +	mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> +				  MVEBU_SW_LINK_CTRL_REG, 0xe002);
> +
> +	/* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> +	mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> +				  MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> +	for (i = 1; i <= 5; i++) {
> +		mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> +					  MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> +					  (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> +	}
> +
> +	return 0;
> +}
> +
> +int board_network_enable_espressobin(struct mii_dev *bus)
> +{
>  	/*
>  	 * FIXME: remove this code once Topaz driver gets available
>  	 * A3720 Community Board Only
> @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
>  	return 0;
>  }
>  
> +/* Bring-up the board-specific networking */
> +int board_network_enable(struct mii_dev *bus)
> +{
> +	if (of_machine_is_compatible("globalscale,espressobin"))
> +		return board_network_enable_espressobin(bus);
> +	if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> +		return board_network_enable_espressobin_ultra(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)
>  {
> @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
>  	int parts_off;
>  	int part_off;
>  
> -	/* Fill SPI MTD partitions for Linux kernel on Espressobin */
> -	if (!of_machine_is_compatible("globalscale,espressobin"))
> +	/*
> +	 * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> +	 * ESPRESSOBin Ultra boards.
> +	 */
> +	if (!of_machine_is_compatible("globalscale,espressobin") &&
> +	    !of_machine_is_compatible("globalscale,espressobin-ultra"))
>  		return 0;
>  
>  	spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> new file mode 100644
> index 0000000000..1bac0a96ad
> --- /dev/null
> +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> @@ -0,0 +1,93 @@
> +CONFIG_ARM=y
> +CONFIG_ARCH_CPU_INIT=y
> +CONFIG_ARCH_MVEBU=y
> +CONFIG_SYS_TEXT_BASE=0x00000000
> +CONFIG_SYS_MALLOC_F_LEN=0x2000
> +CONFIG_NR_DRAM_BANKS=1
> +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
> +CONFIG_ENV_SIZE=0x10000
> +CONFIG_ENV_OFFSET=0x3F0000
> +CONFIG_ENV_SECT_SIZE=0x10000
> +CONFIG_DM_GPIO=y
> +CONFIG_DEBUG_UART_BASE=0xd0012000
> +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
> +CONFIG_DEBUG_UART=y
> +CONFIG_AHCI=y
> +CONFIG_DISTRO_DEFAULTS=y
> +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> +CONFIG_OF_BOARD_SETUP=y
> +CONFIG_FIT=y
> +CONFIG_FIT_VERBOSE=y
> +CONFIG_FIT_BEST_MATCH=y
> +CONFIG_AUTOBOOT_KEYED=y
> +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
> +CONFIG_AUTOBOOT_STOP_STR="s"
> +CONFIG_AUTOBOOT_KEYED_CTRLC=y
> +CONFIG_HUSH_PARSER=y
> +CONFIG_SYS_CONSOLE_INFO_QUIET=y
> +# CONFIG_DISPLAY_CPUINFO is not set
> +# CONFIG_DISPLAY_BOARDINFO is not set
> +CONFIG_DISPLAY_BOARDINFO_LATE=y
> +CONFIG_ARCH_EARLY_INIT_R=y
> +CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_BOARD_LATE_INIT=y
> +# CONFIG_CMD_FLASH is not set
> +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
> +CONFIG_CMD_WDT=y
> +# CONFIG_CMD_SETEXPR is not set
> +CONFIG_CMD_TFTPPUT=y
> +CONFIG_CMD_CACHE=y
> +CONFIG_CMD_TIME=y
> +CONFIG_CMD_MVEBU_BUBT=y
> +CONFIG_MVEBU_MAC_HW_INFO=y
> +CONFIG_CMD_EXT4_WRITE=y
> +CONFIG_MAC_PARTITION=y
> +CONFIG_ENV_OVERWRITE=y
> +CONFIG_ENV_IS_IN_SPI_FLASH=y
> +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> +CONFIG_NET_RANDOM_ETHADDR=y
> +CONFIG_AHCI_MVEBU=y
> +CONFIG_CLK=y
> +CONFIG_CLK_MVEBU=y
> +CONFIG_DM_I2C=y
> +CONFIG_MISC=y
> +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_SPI_FLASH_MACRONIX=y
> +CONFIG_SPI_FLASH_MTD=y
> +CONFIG_PHY_MARVELL=y
> +CONFIG_PHY_GIGE=y
> +CONFIG_MVNETA=y
> +CONFIG_PCI=y
> +CONFIG_PCI_AARDVARK=y
> +CONFIG_PHY=y
> +CONFIG_MVEBU_COMPHY_SUPPORT=y
> +CONFIG_PINCTRL=y
> +CONFIG_PINCTRL_ARMADA_37XX=y
> +CONFIG_DM_REGULATOR_GPIO=y
> +CONFIG_DEBUG_UART_SHIFT=2
> +CONFIG_DEBUG_UART_ANNOUNCE=y
> +CONFIG_MVEBU_A3700_UART=y
> +CONFIG_MVEBU_A3700_SPI=y
> +CONFIG_USB=y
> +CONFIG_USB_XHCI_HCD=y
> +CONFIG_USB_EHCI_HCD=y
> +CONFIG_USB_HOST_ETHER=y
> +# CONFIG_WATCHDOG_AUTOSTART is not set
> +CONFIG_WDT=y
> +CONFIG_WDT_ARMADA_37XX=y
> +CONFIG_SHA1=y
> +CONFIG_DM_RTC=y
> +CONFIG_RTC_PCF8563=y
> +CONFIG_LED=y
> +CONFIG_LED_GPIO=y
> -- 
> 2.31.1
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
  2021-08-13  1:43   ` Marek Behún
@ 2021-08-13  8:23   ` Pali Rohár
  2021-08-13  9:23     ` Luka Kovacic
  2021-08-13 10:29   ` Pali Rohár
  2 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  8:23 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> The mac command is implemented to enable parsing Marvell hw_info formatted
> environments. This format is often used on Marvell Armada A37XX based
> devices to store parameters like the board serial number, factory
> MAC addresses and some other information.
> These parameters are usually written to the flash in the factory.
> 
> Currently the mac command supports reading/writing parameters and dumping
> the current hw_info parameters.
> EEPROM config pattern and checksum aren't supported.
> 
> This functionality has been tested on the GST ESPRESSOBin-Ultra board
> successfully, both reading the stock U-Boot parameters in mainline U-Boot
> and reading the parameters written by this command in the stock U-Boot.
> 
> Usage example:
>  => mac read
>  => saveenv

Hello Luka!

You are just using above commands for accessing following variables,
right?

pcb_slm
pcb_rev
eco_rev
pcb_sn
ethaddr
eth1addr
eth2addr
eth3addr
eth4addr
eth5addr
eth6addr
eth7addr
eth8addr
eth9addr

So why is additional command required? Espressobin boards can already
load and use correct eth*addr variables, which is implemented in board
file.

So what about implementing this import for all above variables for ultra
variant in board file, like it is already for all other variants? I have
already suggested it in the past. As I think this approach is just one
giant and complicated hack...
https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/

I guess that it should be enough to import variables from SPI to env in
board_late_init() function.

> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Robert Marko <robert.marko@sartura.hr>
> ---
>  arch/arm/mach-mvebu/Kconfig                   |   1 +
>  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
>  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
>  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
>  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
>  include/configs/mvebu_armada-37xx.h           |   7 +
>  lib/hashtable.c                               |   2 +-
>  7 files changed, 436 insertions(+), 2 deletions(-)
>  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
>  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
>  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> 
> diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> index 89737a37ad..dff9f05b28 100644
> --- a/arch/arm/mach-mvebu/Kconfig
> +++ b/arch/arm/mach-mvebu/Kconfig
> @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
>  	default 0
>  	depends on SECURED_MODE_IMAGE
>  
> +source "board/Marvell/mvebu_armada-37xx/Kconfig"
>  source "board/solidrun/clearfog/Kconfig"
>  source "board/kobol/helios4/Kconfig"
>  
> diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> new file mode 100644
> index 0000000000..b84dd20023
> --- /dev/null
> +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> @@ -0,0 +1,29 @@
> +menu "Marvell Armada 37xx configuration"
> +depends on TARGET_MVEBU_ARMADA_37XX
> +
> +config MVEBU_MAC_HW_INFO
> +	bool "Marvell hw_info (mac) support"
> +	depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> +	default n
> +	help
> +	  Enable loading of the Marvell hw_info parameters from the
> +	  SPI flash hw_info area. Parameters (usually the board serial
> +	  number and MAC addresses) are then imported into the
> +	  existing U-Boot environment.
> +	  Implementation of this command is compatible with the
> +	  original Marvell U-Boot command. Reading and writing is
> +	  supported.
> +	  EEPROM config pattern and checksum aren't supported.
> +	  After enabled, these parameters are managed from the common
> +	  U-Boot mac command.
> +
> +config MVEBU_MAC_HW_INFO_OFFSET
> +	hex "Marvell hw_info (mac) SPI flash offset"
> +	depends on MVEBU_MAC_HW_INFO
> +	default 0x3E0000
> +	help
> +	  This option defines the SPI flash offset of the Marvell
> +	  hw_info area. This defaults to 0x3E0000 on most Armada
> +	  A3720 platforms.
> +
> +endmenu
> diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> index 27221557c7..6f6ac6b193 100644
> --- a/board/Marvell/mvebu_armada-37xx/Makefile
> +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> @@ -2,4 +2,5 @@
>  #
>  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
>  
> -obj-y	:= board.o
> +obj-y += board.o
> +obj-y += mac/
> diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> new file mode 100644
> index 0000000000..7c30fe6194
> --- /dev/null
> +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +#
> +# Copyright (c) 2021 Sartura Ltd.
> +
> +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> new file mode 100644
> index 0000000000..91e5cd8dcf
> --- /dev/null
> +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> @@ -0,0 +1,391 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Marvell hw_info (mac) command implementation
> + * Helper command for interfacing with the Marvell hw_info parameters
> + *
> + * Copyright (c) 2021 Sartura Ltd.
> + * Copyright (c) 2018 Marvell International Ltd.
> + *
> + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> + */
> +
> +#include <command.h>
> +#include <common.h>
> +#include <env.h>
> +#include <env_internal.h>
> +#include <spi.h>
> +#include <spi_flash.h>
> +
> +#define HW_INFO_SPI_FLASH_OFFSET	CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> +
> +#define HW_INFO_MAX_ENV_SIZE		0x1F0
> +#define HW_INFO_ENV_OFFSET		0xA
> +#define HW_INFO_ENV_SEP			0x20
> +
> +#define HW_INFO_MAX_NAME_LEN		32
> +
> +#define HW_INFO_MERGED_VARIABLE		"read_board_hw_info"
> +
> +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> +	"pcb_slm",
> +	"pcb_rev",
> +	"eco_rev",
> +	"pcb_sn",
> +	"ethaddr",
> +	"eth1addr",
> +	"eth2addr",
> +	"eth3addr",
> +	"eth4addr",
> +	"eth5addr",
> +	"eth6addr",
> +	"eth7addr",
> +	"eth8addr",
> +	"eth9addr",
> +};
> +
> +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> +					sizeof(hw_info_allowed_parameters[0]));
> +
> +static int hw_info_check_parameter(char *name)
> +{
> +	int idx;
> +
> +	for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> +		if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> +			return 0;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +/**
> + * read_spi_flash_offset() - Read data from the SPI flash
> + * @buf: Buffer to write in
> + * @offset: Offset from the flash start
> + *
> + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> + */
> +static int read_spi_flash_offset(char *buf, int offset)
> +{
> +	struct spi_flash *flash;
> +	int ret;
> +
> +	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> +				CONFIG_SF_DEFAULT_CS,
> +				CONFIG_SF_DEFAULT_SPEED,
> +				CONFIG_SF_DEFAULT_MODE);
> +
> +	if (!flash) {
> +		printf("Error - unable to probe SPI flash.\n");
> +		return -EIO;
> +	}
> +
> +	ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> +	if (ret) {
> +		printf("Error - unable to read hw_info environment from SPI flash.\n");
> +		return ret;
> +	}
> +
> +	return ret;
> +}
> +
> +/**
> + * write_spi_flash_offset() - Write a buffer to SPI flash
> + * @buf: Buffer to write to SPI flash
> + * @offset: Offset from the flash start
> + * @size: Size of the buffer content
> + *
> + * This function probes the SPI flash and updates the specified flash location
> + * with new data from the buffer.
> + */
> +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> +{
> +	ssize_t safe_size, erase_size;
> +	struct spi_flash *flash;
> +	int ret;
> +
> +	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> +				CONFIG_SF_DEFAULT_CS,
> +				CONFIG_SF_DEFAULT_SPEED,
> +				CONFIG_SF_DEFAULT_MODE);
> +
> +	if (!flash) {
> +		printf("Error - unable to probe SPI flash.\n");
> +		return -EIO;
> +	}
> +
> +	safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> +	erase_size = safe_size +
> +		     (flash->erase_size - safe_size % flash->erase_size);
> +	ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> +	if (ret) {
> +		printf("Error - unable to erase the hw_info area on SPI flash.\n");
> +		return ret;
> +	}
> +	ret = spi_flash_write(flash, offset, safe_size, buf);
> +	if (ret) {
> +		printf("Error - unable to write hw_info parameters to SPI flash.\n");
> +		return ret;
> +	}
> +
> +	return ret;
> +}
> +
> +/**
> + * cmd_hw_info_dump() - Dump the hw_info parameters
> + *
> + * This function prints all Marvell hw_info parameters, which are stored in
> + * the SPI flash.
> + */
> +static int cmd_hw_info_dump(void)
> +{
> +	char buffer[HW_INFO_MAX_ENV_SIZE];
> +	struct hsearch_data htab;
> +	char *res = NULL;
> +	ssize_t len;
> +	int ret = 0;
> +
> +	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> +				    HW_INFO_ENV_OFFSET);
> +	if (ret)
> +		goto err;
> +	memset(&htab, 0, sizeof(htab));
> +	if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> +		ret = -ENOMEM;
> +		goto err;
> +	}
> +	if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> +		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> +		ret = -EFAULT;
> +		goto err_htab;
> +	}
> +
> +	len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> +	if (len > 0) {
> +		printf("Parameters (hw_info):\n");
> +		puts(res);
> +		free(res);
> +		ret = 0;
> +		goto ret_htab;
> +	}
> +ret_htab:
> +	hdestroy_r(&htab);
> +	return ret;
> +err_htab:
> +	hdestroy_r(&htab);
> +err:
> +	printf("## Error: cannot store hw_info parameters to SPI flash\n");
> +	return ret;
> +}
> +
> +/**
> + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> + * @print_env: Print U-Boot environment after new parameters are imported
> + *
> + * This function reads the Marvell hw_info parameters from SPI flash and
> + * imports them into the U-Boot env.
> + */
> +static int cmd_hw_info_read(bool print_env)
> +{
> +	char buffer[HW_INFO_MAX_ENV_SIZE];
> +	char *res = NULL;
> +	ssize_t len;
> +	int ret = 0;
> +
> +	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> +				    HW_INFO_ENV_OFFSET);
> +	if (ret)
> +		goto err;
> +	if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> +		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> +		ret = -EFAULT;
> +		goto err;
> +	}
> +
> +	printf("Successfully imported the Marvell hw_info parameters.\n");
> +	if (!print_env)
> +		return 0;
> +
> +	len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> +	if (len > 0) {
> +		printf("Updated environment:\n");
> +		puts(res);
> +		free(res);
> +		return 0;
> +	}
> +err:
> +	printf("## Error: cannot import hw_info parameters\n");
> +	return ret;
> +}
> +
> +/**
> + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> + * @name: Name of the U-Boot env parameter to save
> + *
> + * This function finds the specified parameter by name in the U-Boot env
> + * and then updates the Marvell hw_info parameters with the new value.
> + */
> +static int cmd_hw_info_save(char *name)
> +{
> +	char buffer[HW_INFO_MAX_ENV_SIZE];
> +	struct env_entry e, *ep, *rv;
> +	struct hsearch_data htab;
> +	char *res = NULL;
> +	ssize_t len;
> +	int ret = 0;
> +
> +	ret = hw_info_check_parameter(name);
> +	if (ret) {
> +		printf("Invalid parameter %s, stopping.\n", name);
> +		goto err;
> +	}
> +
> +	ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> +				    HW_INFO_ENV_OFFSET);
> +	if (ret)
> +		goto err;
> +	memset(&htab, 0, sizeof(htab));
> +	if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> +		ret = -ENOMEM;
> +		goto err;
> +	}
> +	if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> +		       HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> +		ret = -EFAULT;
> +		goto err_htab;
> +	}
> +
> +	e.key = name;
> +	e.data = NULL;
> +	if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> +		ret = -ENOENT;
> +		goto err_htab;
> +	}
> +	if (!ep) {
> +		ret = -ENOENT;
> +		goto err_htab;
> +	}
> +
> +	printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> +
> +	e.key = ep->key;
> +	e.data = ep->data;
> +	if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> +		ret = -EINVAL;
> +		goto err_htab;
> +	}
> +	if (!rv) {
> +		ret = -EINVAL;
> +		goto err_htab;
> +	}
> +	len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> +			&res, 0, 0, NULL);
> +	if (len <= 0) {
> +		free(res);
> +		goto ret_htab;
> +	}
> +	ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> +				     HW_INFO_ENV_OFFSET, len);
> +	free(res);
> +	if (ret)
> +		goto err_htab;
> +
> +	printf("Successfully stored the Marvell hw_info parameters.\n");
> +	return 0;
> +ret_htab:
> +	hdestroy_r(&htab);
> +	return ret;
> +err_htab:
> +	hdestroy_r(&htab);
> +err:
> +	printf("## Error: cannot store hw_info parameters to SPI flash\n");
> +	return ret;
> +}
> +
> +/**
> + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> + *
> + * This function reads the content of the Marvell hw_info parameters from the
> + * SPI flash and imports them into the U-Boot environment.
> + * This includes MAC addresses and board serial numbers.
> + *
> + * The import is performed only once.
> + *
> + * This function is a part of the U-Boot mac command and must be executed
> + * after SPI flash initialization.
> + */
> +int mac_read_from_eeprom(void)
> +{
> +	if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> +		if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> +			return -ENOENT;
> +		return cmd_hw_info_read(false);
> +	}
> +	return 0;
> +}
> +
> +/**
> + * print_platform_help() - Print the platform specific help
> + *
> + * Extend the existing U-Boot mac command description by also printing
> + * platform specific help text.
> + */
> +static void print_platform_help(void)
> +{
> +	printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> +	       "are unavailable on Marvell Armada A37xx platforms.\n"
> +	       "Use mac [read|save {parameter}] instead.\n"
> +	       "Available parameters:\n"
> +	       "pcb_slm\tPCB SLM number\n"
> +	       "pcb_rev\tPCB revision number\n"
> +	       "eco_rev\tECO revision number\n"
> +	       "pcb_sn\tPCB SN\n"
> +	       "ethaddr\tfirst MAC address\n"
> +	       "eth[1-9]addr\tsecond-ninth MAC address\n");
> +}
> +
> +/**
> + * do_mac() - Standard U-Boot mac command implementation
> + * @cmdtp: U-Boot command table
> + * @flag: Execution flags
> + * @argc: Count of arguments
> + * @argv: Arguments
> + *
> + * This function implements the standard U-Boot mac command in a mostly
> + * compatible way.
> + * To conform to the general command structure as much as possible, the
> + * command description from cmd/mac.c is followed.
> + * Where not possible, convenient or sensible additional comments for the user
> + * are added.
> + */
> +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> +{
> +	const char *cmd = argv[1];
> +	int ret = 0;
> +
> +	if (argc == 1) {
> +		ret = cmd_hw_info_dump();
> +		if (ret)
> +			return -EINVAL;
> +		return CMD_RET_SUCCESS;
> +	}
> +
> +	if (!strcmp(cmd, "read")) {
> +		if (cmd_hw_info_read(true))
> +			return -EINVAL;
> +	} else if (!strcmp(cmd, "save")) {
> +		if (argc != 3) {
> +			printf("Please pass an additional argument to specify, "
> +			       "which env parameter to save.\n");
> +			return -EINVAL;
> +		}
> +		if (cmd_hw_info_save(argv[2]))
> +			return -EINVAL;
> +	} else {
> +		ret = cmd_usage(cmdtp);
> +		print_platform_help();
> +		return ret;
> +	}
> +
> +	return CMD_RET_SUCCESS;
> +}
> diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> index c8c34d7d92..8e8bcfa018 100644
> --- a/include/configs/mvebu_armada-37xx.h
> +++ b/include/configs/mvebu_armada-37xx.h
> @@ -62,6 +62,13 @@
>   */
>  #define DEFAULT_ENV_IS_RW		/* required for configuring default fdtfile= */
>  
> +/*
> + * Platform identification (Marvell hw_info parameters)
> + */
> +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> +#endif
> +
>  /*
>   * Ethernet Driver configuration
>   */
> diff --git a/lib/hashtable.c b/lib/hashtable.c
> index ff5ff72639..06322e3304 100644
> --- a/lib/hashtable.c
> +++ b/lib/hashtable.c
> @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
>   * multi-line values.
>   *
>   * In theory, arbitrary separator characters can be used, but only
> - * '\0' and '\n' have really been tested.
> + * '\0', '\n' and 0x20 have been tested.
>   */
>  
>  int himport_r(struct hsearch_data *htab,
> -- 
> 2.31.1
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-13  8:08   ` Pali Rohár
@ 2021-08-13  8:59     ` Luka Kovacic
  2021-08-13  9:31       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13  8:59 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 10:08 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > Add the loadaddr U-Boot environment variable, as this is available in
> > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
>
> Hello Luka! Why is this change needed? Reason that it is in historic
> vendor U-Boot does not mean that it has to be also in new mainline
> version.
>
> I have already wrote some reasons in previous review thread:
> https://lore.kernel.org/u-boot/20210301150505.3iajeeufi7ahsnk3@pali/
>
> I think this change was needed when CONFIG_SYS_LOAD_ADDR was set to
> incorrect value, which is already fixed in mainline U-Boot.

This value is very useful when building custom Linux boot scripts.
Yesterday, I booted the board without this patch and there was no loadaddr
variable.

Do I understand this correctly? Are you saying that the value in the loadaddr
variable should be automatically inherited from CONFIG_SYS_LOAD_ADDR
even without this patch?

>
> > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Cc: Robert Marko <robert.marko@sartura.hr>
> > ---
> >  include/configs/mvebu_armada-37xx.h | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > index 8e8bcfa018..6901680e32 100644
> > --- a/include/configs/mvebu_armada-37xx.h
> > +++ b/include/configs/mvebu_armada-37xx.h
> > @@ -110,6 +110,7 @@
> >
> >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > +     "loadaddr=0x6000000\0"          \
> >       "scriptaddr=0x6d00000\0"        \
> >       "pxefile_addr_r=0x6e00000\0"    \
> >       "fdt_addr=0x6f00000\0"          \
> > --
> > 2.31.1
> >

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13  8:14   ` Pali Rohár
@ 2021-08-13  9:08     ` Luka Kovacic
  2021-08-13  9:54       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13  9:08 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > Technologies, Inc.
> >
> > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > Peripherals:
> >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> >  - RTC clock (PCF8563)
> >  - USB 3.0 port
> >  - USB 2.0 port
> >  - 4x LED
> >  - UART over Micro-USB
> >  - M.2 slot (2280)
> >  - Mini PCI-E slot
> >
> > Additionally, automatic import of the Marvell hw_info parameters is
> > enabled via the recently added mac command for A37XX platforms.
> > The parameters stored in Marvell hw_info are usually the board serial
> > number and MAC addresses.
> >
> > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Cc: Robert Marko <robert.marko@sartura.hr>
> > ---
> >  arch/arm/dts/Makefile                         |   1 +
> >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> >  7 files changed, 514 insertions(+), 203 deletions(-)
> >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
>
> Hello Luka! Please look at my comments from previous review:
> https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
>
> I think it is not a good idea to duplicate espressobin code, specially
> now when differences between v5, v7, non-emmc and emmc were
> de-duplicated and correctly detected at runtime. Just use one DTS and
> one config file and differences can be handled in board code functions
> "board_fix_fdt" and "board_late_init".

I believe that patching the DTS at runtime diminishes the value of
device trees in the first case.

As far as the v5, v7, non-emmc and emmc boards go I do understand
that, as they are physically similar and more or less different revisions
of the same board.

The ESPRESSOBin Ultra board is completely different from those boards
physically and so I doesn't make sense to me, why we would merge all
of them into one device tree.

I resorted to the Linux way and used a common dtsi for both the
ESPRESSOBin - which is the base and the ESPRESSOBin-Ultra.

>
> > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > index c42715ead4..f21c9c94d3 100644
> > --- a/arch/arm/dts/Makefile
> > +++ b/arch/arm/dts/Makefile
> > @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
> >  dtb-$(CONFIG_ARCH_MVEBU) +=                  \
> >       armada-3720-db.dtb                      \
> >       armada-3720-espressobin.dtb             \
> > +     armada-3720-espressobin-ultra.dtb       \
> >       armada-3720-turris-mox.dtb              \
> >       armada-3720-uDPU.dtb                    \
> >       armada-375-db.dtb                       \
> > diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > new file mode 100644
> > index 0000000000..5ad0c723e3
> > --- /dev/null
> > +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > @@ -0,0 +1,114 @@
> > +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> > +/*
> > + * Device Tree file for ESPRESSObin-Ultra board
> > + * Copyright (C) 2016 Marvell
> > + * Copyright (C) 2019 Globalscale technologies, Inc.
> > + * Copyright (C) 2021 Sartura Ltd.
> > + *
> > + * Author: Jason Hung <jhung@globalscaletechnologies.com>
> > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
> > + */
> > +
> > +/dts-v1/;
> > +
> > +#include "armada-3720-espressobin.dtsi"
> > +
> > +/ {
> > +     model = "Globalscale Marvell ESPRESSOBin Ultra Board";
> > +     compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
> > +
> > +     gpio-leds {
> > +             pinctrl-names = "default";
> > +             pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
> > +             compatible = "gpio-leds";
> > +
> > +             led1 {
> > +                     label = "led1";
> > +                     gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
> > +                     default-state = "on";
> > +             };
> > +             led2 {
> > +                     label = "led2";
> > +                     gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
> > +                     default-state = "on";
> > +             };
> > +             led3 {
> > +                     label = "led3";
> > +                     gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
> > +                     default-state = "on";
> > +             };
> > +             led4 {
> > +                     label = "led4";
> > +                     gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
> > +                     default-state = "on";
> > +             };
> > +     };
> > +};
> > +
> > +&pinctrl_nb {
> > +     led1_pins: led1-pins {
> > +             groups = "pwm0";
> > +             function = "gpio";
> > +     };
> > +     led2_pins: led2-pins {
> > +             groups = "pwm1";
> > +             function = "gpio";
> > +     };
> > +     led3_pins: led3-pins {
> > +             groups = "pwm2";
> > +             function = "gpio";
> > +     };
> > +     led4_pins: led4-pins {
> > +             groups = "pwm3";
> > +             function = "gpio";
> > +     };
> > +};
> > +
> > +&eth0 {
> > +     status = "okay";
> > +     phy_addr = <0x3>;
> > +};
> > +
> > +&i2c0 {
> > +     status = "okay";
> > +     #address-cells = <1>;
> > +     #size-cells = <0>;
> > +     rtc@51 {
> > +             compatible = "nxp,pcf8563";
> > +             reg = <0x51>;
> > +     };
> > +};
> > +
> > +&sata {
> > +     status = "okay";
> > +};
> > +
> > +&sdhci0 {
> > +     status = "disabled";
> > +};
> > +
> > +&sdhci1 {
> > +     status = "okay";
> > +};
> > +
> > +&spi0 {
> > +     status = "okay";
> > +};
> > +
> > +/* Exported on the micro USB connector through an FTDI */
> > +&uart0 {
> > +     status = "okay";
> > +};
> > +
> > +&usb2 {
> > +     status = "okay";
> > +};
> > +
> > +&usb3 {
> > +     status = "okay";
> > +};
> > +
> > +&pcie0 {
> > +     status = "okay";
> > +};
> > diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
> > index cba6139be6..925ce6a38e 100644
> > --- a/arch/arm/dts/armada-3720-espressobin.dts
> > +++ b/arch/arm/dts/armada-3720-espressobin.dts
> > @@ -1,210 +1,15 @@
> > +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> >  /*
> >   * Device Tree file for Marvell Armada 3720 community board
> >   * (ESPRESSOBin)
> >   * Copyright (C) 2016 Marvell
> > - *
> > - * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > - * Konstantin Porotchkin <kostap@marvell.com>
> > - *
> > - * This file is dual-licensed: you can use it either under the terms
> > - * of the GPL or the X11 license, at your option. Note that this dual
> > - * licensing only applies to this file, and not this project as a
> > - * whole.
> > - *
> > - *  a) This file is free software; you can redistribute it and/or
> > - *     modify it under the terms of the GNU General Public License as
> > - *     published by the Free Software Foundation; either version 2 of the
> > - *     License, or (at your option) any later version.
> > - *
> > - *     This file is distributed in the hope that it will be useful
> > - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > - *     GNU General Public License for more details.
> > - *
> > - * Or, alternatively
> > - *
> > - *  b) Permission is hereby granted, free of charge, to any person
> > - *     obtaining a copy of this software and associated documentation
> > - *     files (the "Software"), to deal in the Software without
> > - *     restriction, including without limitation the rights to use
> > - *     copy, modify, merge, publish, distribute, sublicense, and/or
> > - *     sell copies of the Software, and to permit persons to whom the
> > - *     Software is furnished to do so, subject to the following
> > - *     conditions:
> > - *
> > - *     The above copyright notice and this permission notice shall be
> > - *     included in all copies or substantial portions of the Software.
> > - *
> > - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > - *     OTHER DEALINGS IN THE SOFTWARE.
> >   */
> >
> >  /dts-v1/;
> >
> > -#include "armada-372x.dtsi"
> > +#include "armada-3720-espressobin.dtsi"
> >
> >  / {
> >       model = "Globalscale Marvell ESPRESSOBin Board";
> >       compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > -
> > -     chosen {
> > -             stdout-path = "serial0:115200n8";
> > -     };
> > -
> > -     aliases {
> > -             ethernet0 = &eth0;
> > -             i2c0 = &i2c0;
> > -             spi0 = &spi0;
> > -     };
> > -
> > -     memory {
> > -             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 {
> > -     max-lanes = <3>;
> > -     phy0 {
> > -             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > -             phy-speed = <COMPHY_SPEED_5G>;
> > -     };
> > -
> > -     phy1 {
> > -             phy-type = <COMPHY_TYPE_PEX0>;
> > -             phy-speed = <COMPHY_SPEED_2_5G>;
> > -     };
> > -
> > -     phy2 {
> > -             phy-type = <COMPHY_TYPE_SATA0>;
> > -             phy-speed = <COMPHY_SPEED_5G>;
> > -     };
> > -};
> > -
> > -&eth0 {
> > -     status = "okay";
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > -     phy-mode = "rgmii";
> > -     phy_addr = <0x1>;
> > -     fixed-link {
> > -             speed = <1000>;
> > -             full-duplex;
> > -     };
> > -};
> > -
> > -&i2c0 {
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&i2c1_pins>;
> > -     status = "okay";
> > -};
> > -
> > -/* CON3 */
> > -&sata {
> > -     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";
> > -};
> > -
> > -/* U11 */
> > -&sdhci1 {
> > -     non-removable;
> > -     bus-width = <8>;
> > -     mmc-ddr-1_8v;
> > -     mmc-hs400-1_8v;
> > -     marvell,xenon-emmc;
> > -     marvell,xenon-tun-count = <9>;
> > -     marvell,pad-type = "fixed-1-8v";
> > -
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&mmc_pins>;
> > -     status = "okay";
> > -
> > -     #address-cells = <1>;
> > -     #size-cells = <0>;
> > -     mmccard: mmccard@0 {
> > -             compatible = "mmc-card";
> > -             reg = <0>;
> > -     };
> > -};
> > -
> > -&spi0 {
> > -     status = "okay";
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&spi_quad_pins>;
> > -
> > -     spi-flash@0 {
> > -             #address-cells = <1>;
> > -             #size-cells = <1>;
> > -             compatible = "st,m25p128", "jedec,spi-nor";
> > -             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > -                             label = "u-boot-env";
> > -                     };
> > -             };
> > -#endif
> > -     };
> > -};
> > -
> > -/* Exported on the micro USB connector CON32 through an FTDI */
> > -&uart0 {
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&uart1_pins>;
> > -     status = "okay";
> > -};
> > -
> > -/* CON29 */
> > -&usb2 {
> > -     status = "okay";
> > -};
> > -
> > -/* CON31 */
> > -&usb3 {
> > -     status = "okay";
> > -};
> > -
> > -&pcie0 {
> > -     pinctrl-names = "default";
> > -     pinctrl-0 = <&pcie_pins>;
> > -     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > -     status = "okay";
> >  };
> > diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
> > new file mode 100644
> > index 0000000000..cba6139be6
> > --- /dev/null
> > +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
> > @@ -0,0 +1,210 @@
> > +/*
> > + * Device Tree file for Marvell Armada 3720 community board
> > + * (ESPRESSOBin)
> > + * Copyright (C) 2016 Marvell
> > + *
> > + * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > + * Konstantin Porotchkin <kostap@marvell.com>
> > + *
> > + * This file is dual-licensed: you can use it either under the terms
> > + * of the GPL or the X11 license, at your option. Note that this dual
> > + * licensing only applies to this file, and not this project as a
> > + * whole.
> > + *
> > + *  a) This file is free software; you can redistribute it and/or
> > + *     modify it under the terms of the GNU General Public License as
> > + *     published by the Free Software Foundation; either version 2 of the
> > + *     License, or (at your option) any later version.
> > + *
> > + *     This file is distributed in the hope that it will be useful
> > + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + *     GNU General Public License for more details.
> > + *
> > + * Or, alternatively
> > + *
> > + *  b) Permission is hereby granted, free of charge, to any person
> > + *     obtaining a copy of this software and associated documentation
> > + *     files (the "Software"), to deal in the Software without
> > + *     restriction, including without limitation the rights to use
> > + *     copy, modify, merge, publish, distribute, sublicense, and/or
> > + *     sell copies of the Software, and to permit persons to whom the
> > + *     Software is furnished to do so, subject to the following
> > + *     conditions:
> > + *
> > + *     The above copyright notice and this permission notice shall be
> > + *     included in all copies or substantial portions of the Software.
> > + *
> > + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + *     OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +/dts-v1/;
> > +
> > +#include "armada-372x.dtsi"
> > +
> > +/ {
> > +     model = "Globalscale Marvell ESPRESSOBin Board";
> > +     compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > +
> > +     chosen {
> > +             stdout-path = "serial0:115200n8";
> > +     };
> > +
> > +     aliases {
> > +             ethernet0 = &eth0;
> > +             i2c0 = &i2c0;
> > +             spi0 = &spi0;
> > +     };
> > +
> > +     memory {
> > +             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 {
> > +     max-lanes = <3>;
> > +     phy0 {
> > +             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > +             phy-speed = <COMPHY_SPEED_5G>;
> > +     };
> > +
> > +     phy1 {
> > +             phy-type = <COMPHY_TYPE_PEX0>;
> > +             phy-speed = <COMPHY_SPEED_2_5G>;
> > +     };
> > +
> > +     phy2 {
> > +             phy-type = <COMPHY_TYPE_SATA0>;
> > +             phy-speed = <COMPHY_SPEED_5G>;
> > +     };
> > +};
> > +
> > +&eth0 {
> > +     status = "okay";
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > +     phy-mode = "rgmii";
> > +     phy_addr = <0x1>;
> > +     fixed-link {
> > +             speed = <1000>;
> > +             full-duplex;
> > +     };
> > +};
> > +
> > +&i2c0 {
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&i2c1_pins>;
> > +     status = "okay";
> > +};
> > +
> > +/* CON3 */
> > +&sata {
> > +     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";
> > +};
> > +
> > +/* U11 */
> > +&sdhci1 {
> > +     non-removable;
> > +     bus-width = <8>;
> > +     mmc-ddr-1_8v;
> > +     mmc-hs400-1_8v;
> > +     marvell,xenon-emmc;
> > +     marvell,xenon-tun-count = <9>;
> > +     marvell,pad-type = "fixed-1-8v";
> > +
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&mmc_pins>;
> > +     status = "okay";
> > +
> > +     #address-cells = <1>;
> > +     #size-cells = <0>;
> > +     mmccard: mmccard@0 {
> > +             compatible = "mmc-card";
> > +             reg = <0>;
> > +     };
> > +};
> > +
> > +&spi0 {
> > +     status = "okay";
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&spi_quad_pins>;
> > +
> > +     spi-flash@0 {
> > +             #address-cells = <1>;
> > +             #size-cells = <1>;
> > +             compatible = "st,m25p128", "jedec,spi-nor";
> > +             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > +                             label = "u-boot-env";
> > +                     };
> > +             };
> > +#endif
> > +     };
> > +};
> > +
> > +/* Exported on the micro USB connector CON32 through an FTDI */
> > +&uart0 {
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&uart1_pins>;
> > +     status = "okay";
> > +};
> > +
> > +/* CON29 */
> > +&usb2 {
> > +     status = "okay";
> > +};
> > +
> > +/* CON31 */
> > +&usb3 {
> > +     status = "okay";
> > +};
> > +
> > +&pcie0 {
> > +     pinctrl-names = "default";
> > +     pinctrl-0 = <&pcie_pins>;
> > +     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > +     status = "okay";
> > +};
> > diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > index f2c0a582d7..d69af832fc 100644
> > --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > @@ -10,6 +10,14 @@ M: Konstantin Porotchkin <kostap@marvell.com>
> >  S:   Maintained
> >  F:   configs/mvebu_espressobin-88f3720_defconfig
> >
> > +ESPRESSOBin-Ultra BOARD
> > +M:   Luka Kovacic <luka.kovacic@sartura.hr>
> > +M:   Robert Marko <robert.marko@sartura.hr>
> > +M:   Luka Perkov <luka.perkov@sartura.hr>
> > +S:   Maintained
> > +F:   arch/arm/dts/armada-3720-espressobin-ultra.dts
> > +F:   configs/mvebu_espressobin-ultra-88f3720_defconfig
> > +
> >  uDPU BOARD
> >  M:   Vladimir Vid <vladimir.vid@sartura.hr>
> >  S:   Maintained
> > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > index 2de9c2ac17..21c1eb7b22 100644
> > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > @@ -11,6 +11,7 @@
> >  #include <i2c.h>
> >  #include <init.h>
> >  #include <mmc.h>
> > +#include <miiphy.h>
> >  #include <phy.h>
> >  #include <asm/global_data.h>
> >  #include <asm/io.h>
> > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> >
> > +/* Marvell 88E1512 */
> > +#define MII_MARVELL_PHY_PAGE         22
> > +
> > +#define MV88E1512_GENERAL_CTRL               20
> > +#define MV88E1512_MODE_SGMII         1
> > +#define MV88E1512_RESET_OFFS         15
> > +
> > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > +
> >  /*
> >   * Memory Controller Registers
> >   *
> > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> >       return 0;
> >  }
> >
> > -/* Bring-up board-specific network stuff */
> > -int board_network_enable(struct mii_dev *bus)
> > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> >  {
> > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > -             return 0;
> > +     const char *name;
> > +     u16 reg;
> > +
> > +     name = miiphy_get_current_dev();
> > +     if (name) {
> > +             /* SGMII-to-Copper mode initialization */
> > +
> > +             /* Select page 18 */
> > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > +             reg &= ~0x7;
> > +             reg |= MV88E1512_MODE_SGMII;
> > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > +             /* PHY reset is necessary after changing MODE[2:0] */
> > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > +             /* Reset page selection */
> > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > +             udelay(100);
> > +     }
> > +}
> > +
> > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > +{
> > +     int i;
> > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> >
> > +     /*
> > +      * FIXME: remove this code once Topaz driver gets available
> > +      * A3720 ESPRESSObin Ultra Board Only
> > +      * Configure Topaz switch (88E6341)
> > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > +      */
> > +     for (i = 0; i <= 5; i++) {
> > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > +                                       MVEBU_SW_PORT_CTRL_REG,
> > +                                       i == 5 ? 0x7c : 0x7f);
> > +     }
> > +
> > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > +
> > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > +     for (i = 1; i <= 5; i++) {
> > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > +     }
> > +
> > +     return 0;
> > +}
> > +
> > +int board_network_enable_espressobin(struct mii_dev *bus)
> > +{
> >       /*
> >        * FIXME: remove this code once Topaz driver gets available
> >        * A3720 Community Board Only
> > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> >       return 0;
> >  }
> >
> > +/* Bring-up the board-specific networking */
> > +int board_network_enable(struct mii_dev *bus)
> > +{
> > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > +             return board_network_enable_espressobin(bus);
> > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > +             return board_network_enable_espressobin_ultra(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)
> >  {
> > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> >       int parts_off;
> >       int part_off;
> >
> > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > +     /*
> > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > +      * ESPRESSOBin Ultra boards.
> > +      */
> > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> >               return 0;
> >
> >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> > diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > new file mode 100644
> > index 0000000000..1bac0a96ad
> > --- /dev/null
> > +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > @@ -0,0 +1,93 @@
> > +CONFIG_ARM=y
> > +CONFIG_ARCH_CPU_INIT=y
> > +CONFIG_ARCH_MVEBU=y
> > +CONFIG_SYS_TEXT_BASE=0x00000000
> > +CONFIG_SYS_MALLOC_F_LEN=0x2000
> > +CONFIG_NR_DRAM_BANKS=1
> > +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
> > +CONFIG_ENV_SIZE=0x10000
> > +CONFIG_ENV_OFFSET=0x3F0000
> > +CONFIG_ENV_SECT_SIZE=0x10000
> > +CONFIG_DM_GPIO=y
> > +CONFIG_DEBUG_UART_BASE=0xd0012000
> > +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
> > +CONFIG_DEBUG_UART=y
> > +CONFIG_AHCI=y
> > +CONFIG_DISTRO_DEFAULTS=y
> > +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> > +CONFIG_OF_BOARD_SETUP=y
> > +CONFIG_FIT=y
> > +CONFIG_FIT_VERBOSE=y
> > +CONFIG_FIT_BEST_MATCH=y
> > +CONFIG_AUTOBOOT_KEYED=y
> > +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
> > +CONFIG_AUTOBOOT_STOP_STR="s"
> > +CONFIG_AUTOBOOT_KEYED_CTRLC=y
> > +CONFIG_HUSH_PARSER=y
> > +CONFIG_SYS_CONSOLE_INFO_QUIET=y
> > +# CONFIG_DISPLAY_CPUINFO is not set
> > +# CONFIG_DISPLAY_BOARDINFO is not set
> > +CONFIG_DISPLAY_BOARDINFO_LATE=y
> > +CONFIG_ARCH_EARLY_INIT_R=y
> > +CONFIG_BOARD_EARLY_INIT_F=y
> > +CONFIG_BOARD_LATE_INIT=y
> > +# CONFIG_CMD_FLASH is not set
> > +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
> > +CONFIG_CMD_WDT=y
> > +# CONFIG_CMD_SETEXPR is not set
> > +CONFIG_CMD_TFTPPUT=y
> > +CONFIG_CMD_CACHE=y
> > +CONFIG_CMD_TIME=y
> > +CONFIG_CMD_MVEBU_BUBT=y
> > +CONFIG_MVEBU_MAC_HW_INFO=y
> > +CONFIG_CMD_EXT4_WRITE=y
> > +CONFIG_MAC_PARTITION=y
> > +CONFIG_ENV_OVERWRITE=y
> > +CONFIG_ENV_IS_IN_SPI_FLASH=y
> > +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> > +CONFIG_NET_RANDOM_ETHADDR=y
> > +CONFIG_AHCI_MVEBU=y
> > +CONFIG_CLK=y
> > +CONFIG_CLK_MVEBU=y
> > +CONFIG_DM_I2C=y
> > +CONFIG_MISC=y
> > +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_SPI_FLASH_MACRONIX=y
> > +CONFIG_SPI_FLASH_MTD=y
> > +CONFIG_PHY_MARVELL=y
> > +CONFIG_PHY_GIGE=y
> > +CONFIG_MVNETA=y
> > +CONFIG_PCI=y
> > +CONFIG_PCI_AARDVARK=y
> > +CONFIG_PHY=y
> > +CONFIG_MVEBU_COMPHY_SUPPORT=y
> > +CONFIG_PINCTRL=y
> > +CONFIG_PINCTRL_ARMADA_37XX=y
> > +CONFIG_DM_REGULATOR_GPIO=y
> > +CONFIG_DEBUG_UART_SHIFT=2
> > +CONFIG_DEBUG_UART_ANNOUNCE=y
> > +CONFIG_MVEBU_A3700_UART=y
> > +CONFIG_MVEBU_A3700_SPI=y
> > +CONFIG_USB=y
> > +CONFIG_USB_XHCI_HCD=y
> > +CONFIG_USB_EHCI_HCD=y
> > +CONFIG_USB_HOST_ETHER=y
> > +# CONFIG_WATCHDOG_AUTOSTART is not set
> > +CONFIG_WDT=y
> > +CONFIG_WDT_ARMADA_37XX=y
> > +CONFIG_SHA1=y
> > +CONFIG_DM_RTC=y
> > +CONFIG_RTC_PCF8563=y
> > +CONFIG_LED=y
> > +CONFIG_LED_GPIO=y
> > --
> > 2.31.1
> >

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13  8:23   ` Pali Rohár
@ 2021-08-13  9:23     ` Luka Kovacic
  2021-08-13  9:41       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13  9:23 UTC (permalink / raw)
  To: Marek Behun, Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, sr, sjg, patrick.delaunay,
	xypron.glpk

Hello Marek and Pali,

On Fri, Aug 13, 2021 at 10:23 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > The mac command is implemented to enable parsing Marvell hw_info formatted
> > environments. This format is often used on Marvell Armada A37XX based
> > devices to store parameters like the board serial number, factory
> > MAC addresses and some other information.
> > These parameters are usually written to the flash in the factory.
> >
> > Currently the mac command supports reading/writing parameters and dumping
> > the current hw_info parameters.
> > EEPROM config pattern and checksum aren't supported.
> >
> > This functionality has been tested on the GST ESPRESSOBin-Ultra board
> > successfully, both reading the stock U-Boot parameters in mainline U-Boot
> > and reading the parameters written by this command in the stock U-Boot.
> >
> > Usage example:
> >  => mac read
> >  => saveenv
>
> Hello Luka!
>
> You are just using above commands for accessing following variables,
> right?
>
> pcb_slm
> pcb_rev
> eco_rev
> pcb_sn
> ethaddr
> eth1addr
> eth2addr
> eth3addr
> eth4addr
> eth5addr
> eth6addr
> eth7addr
> eth8addr
> eth9addr
>

Yes, I am accessing these variables.

> So why is additional command required? Espressobin boards can already
> load and use correct eth*addr variables, which is implemented in board
> file.

The current implementation in the board file preserves currently stored MAC
addresses, which are in the U-Boot environment.

My implementation is suitable for the ESPRESSOBin-Ultra, as the MACs
are stored in the hw_info area of the SPI flash and the tool imports them
into the normal U-Boot env.
They can also be modified using the tool - we won't be able to get this
functionality in the board file.

>
> So what about implementing this import for all above variables for ultra
> variant in board file, like it is already for all other variants? I have
> already suggested it in the past. As I think this approach is just one
> giant and complicated hack...
> https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/
>
> I guess that it should be enough to import variables from SPI to env in
> board_late_init() function.

Currently, the MACs are automatically imported from the
common/board_r.c file at boot, I think this is more standard and cleaner.

Nevertheless, I believe this a sufficient solution for now,
as this has been suggested as a solution in the previous patchset
comments too.

>
> > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Cc: Robert Marko <robert.marko@sartura.hr>
> > ---
> >  arch/arm/mach-mvebu/Kconfig                   |   1 +
> >  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
> >  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
> >  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
> >  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
> >  include/configs/mvebu_armada-37xx.h           |   7 +
> >  lib/hashtable.c                               |   2 +-
> >  7 files changed, 436 insertions(+), 2 deletions(-)
> >  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
> >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
> >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> >
> > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> > index 89737a37ad..dff9f05b28 100644
> > --- a/arch/arm/mach-mvebu/Kconfig
> > +++ b/arch/arm/mach-mvebu/Kconfig
> > @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
> >       default 0
> >       depends on SECURED_MODE_IMAGE
> >
> > +source "board/Marvell/mvebu_armada-37xx/Kconfig"
> >  source "board/solidrun/clearfog/Kconfig"
> >  source "board/kobol/helios4/Kconfig"
> >
> > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > new file mode 100644
> > index 0000000000..b84dd20023
> > --- /dev/null
> > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > @@ -0,0 +1,29 @@
> > +menu "Marvell Armada 37xx configuration"
> > +depends on TARGET_MVEBU_ARMADA_37XX
> > +
> > +config MVEBU_MAC_HW_INFO
> > +     bool "Marvell hw_info (mac) support"
> > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > +     default n
> > +     help
> > +       Enable loading of the Marvell hw_info parameters from the
> > +       SPI flash hw_info area. Parameters (usually the board serial
> > +       number and MAC addresses) are then imported into the
> > +       existing U-Boot environment.
> > +       Implementation of this command is compatible with the
> > +       original Marvell U-Boot command. Reading and writing is
> > +       supported.
> > +       EEPROM config pattern and checksum aren't supported.
> > +       After enabled, these parameters are managed from the common
> > +       U-Boot mac command.
> > +
> > +config MVEBU_MAC_HW_INFO_OFFSET
> > +     hex "Marvell hw_info (mac) SPI flash offset"
> > +     depends on MVEBU_MAC_HW_INFO
> > +     default 0x3E0000
> > +     help
> > +       This option defines the SPI flash offset of the Marvell
> > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > +       A3720 platforms.
> > +
> > +endmenu
> > diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> > index 27221557c7..6f6ac6b193 100644
> > --- a/board/Marvell/mvebu_armada-37xx/Makefile
> > +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> > @@ -2,4 +2,5 @@
> >  #
> >  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
> >
> > -obj-y        := board.o
> > +obj-y += board.o
> > +obj-y += mac/
> > diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > new file mode 100644
> > index 0000000000..7c30fe6194
> > --- /dev/null
> > +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > @@ -0,0 +1,5 @@
> > +# SPDX-License-Identifier: GPL-2.0+
> > +#
> > +# Copyright (c) 2021 Sartura Ltd.
> > +
> > +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> > diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > new file mode 100644
> > index 0000000000..91e5cd8dcf
> > --- /dev/null
> > +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > @@ -0,0 +1,391 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Marvell hw_info (mac) command implementation
> > + * Helper command for interfacing with the Marvell hw_info parameters
> > + *
> > + * Copyright (c) 2021 Sartura Ltd.
> > + * Copyright (c) 2018 Marvell International Ltd.
> > + *
> > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > + */
> > +
> > +#include <command.h>
> > +#include <common.h>
> > +#include <env.h>
> > +#include <env_internal.h>
> > +#include <spi.h>
> > +#include <spi_flash.h>
> > +
> > +#define HW_INFO_SPI_FLASH_OFFSET     CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> > +
> > +#define HW_INFO_MAX_ENV_SIZE         0x1F0
> > +#define HW_INFO_ENV_OFFSET           0xA
> > +#define HW_INFO_ENV_SEP                      0x20
> > +
> > +#define HW_INFO_MAX_NAME_LEN         32
> > +
> > +#define HW_INFO_MERGED_VARIABLE              "read_board_hw_info"
> > +
> > +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> > +     "pcb_slm",
> > +     "pcb_rev",
> > +     "eco_rev",
> > +     "pcb_sn",
> > +     "ethaddr",
> > +     "eth1addr",
> > +     "eth2addr",
> > +     "eth3addr",
> > +     "eth4addr",
> > +     "eth5addr",
> > +     "eth6addr",
> > +     "eth7addr",
> > +     "eth8addr",
> > +     "eth9addr",
> > +};
> > +
> > +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> > +                                     sizeof(hw_info_allowed_parameters[0]));
> > +
> > +static int hw_info_check_parameter(char *name)
> > +{
> > +     int idx;
> > +
> > +     for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> > +             if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> > +                     return 0;
> > +     }
> > +
> > +     return -EINVAL;
> > +}
> > +
> > +/**
> > + * read_spi_flash_offset() - Read data from the SPI flash
> > + * @buf: Buffer to write in
> > + * @offset: Offset from the flash start
> > + *
> > + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> > + */
> > +static int read_spi_flash_offset(char *buf, int offset)
> > +{
> > +     struct spi_flash *flash;
> > +     int ret;
> > +
> > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > +                             CONFIG_SF_DEFAULT_CS,
> > +                             CONFIG_SF_DEFAULT_SPEED,
> > +                             CONFIG_SF_DEFAULT_MODE);
> > +
> > +     if (!flash) {
> > +             printf("Error - unable to probe SPI flash.\n");
> > +             return -EIO;
> > +     }
> > +
> > +     ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> > +     if (ret) {
> > +             printf("Error - unable to read hw_info environment from SPI flash.\n");
> > +             return ret;
> > +     }
> > +
> > +     return ret;
> > +}
> > +
> > +/**
> > + * write_spi_flash_offset() - Write a buffer to SPI flash
> > + * @buf: Buffer to write to SPI flash
> > + * @offset: Offset from the flash start
> > + * @size: Size of the buffer content
> > + *
> > + * This function probes the SPI flash and updates the specified flash location
> > + * with new data from the buffer.
> > + */
> > +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> > +{
> > +     ssize_t safe_size, erase_size;
> > +     struct spi_flash *flash;
> > +     int ret;
> > +
> > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > +                             CONFIG_SF_DEFAULT_CS,
> > +                             CONFIG_SF_DEFAULT_SPEED,
> > +                             CONFIG_SF_DEFAULT_MODE);
> > +
> > +     if (!flash) {
> > +             printf("Error - unable to probe SPI flash.\n");
> > +             return -EIO;
> > +     }
> > +
> > +     safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> > +     erase_size = safe_size +
> > +                  (flash->erase_size - safe_size % flash->erase_size);
> > +     ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> > +     if (ret) {
> > +             printf("Error - unable to erase the hw_info area on SPI flash.\n");
> > +             return ret;
> > +     }
> > +     ret = spi_flash_write(flash, offset, safe_size, buf);
> > +     if (ret) {
> > +             printf("Error - unable to write hw_info parameters to SPI flash.\n");
> > +             return ret;
> > +     }
> > +
> > +     return ret;
> > +}
> > +
> > +/**
> > + * cmd_hw_info_dump() - Dump the hw_info parameters
> > + *
> > + * This function prints all Marvell hw_info parameters, which are stored in
> > + * the SPI flash.
> > + */
> > +static int cmd_hw_info_dump(void)
> > +{
> > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > +     struct hsearch_data htab;
> > +     char *res = NULL;
> > +     ssize_t len;
> > +     int ret = 0;
> > +
> > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > +                                 HW_INFO_ENV_OFFSET);
> > +     if (ret)
> > +             goto err;
> > +     memset(&htab, 0, sizeof(htab));
> > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > +             ret = -ENOMEM;
> > +             goto err;
> > +     }
> > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > +             ret = -EFAULT;
> > +             goto err_htab;
> > +     }
> > +
> > +     len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > +     if (len > 0) {
> > +             printf("Parameters (hw_info):\n");
> > +             puts(res);
> > +             free(res);
> > +             ret = 0;
> > +             goto ret_htab;
> > +     }
> > +ret_htab:
> > +     hdestroy_r(&htab);
> > +     return ret;
> > +err_htab:
> > +     hdestroy_r(&htab);
> > +err:
> > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > +     return ret;
> > +}
> > +
> > +/**
> > + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> > + * @print_env: Print U-Boot environment after new parameters are imported
> > + *
> > + * This function reads the Marvell hw_info parameters from SPI flash and
> > + * imports them into the U-Boot env.
> > + */
> > +static int cmd_hw_info_read(bool print_env)
> > +{
> > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > +     char *res = NULL;
> > +     ssize_t len;
> > +     int ret = 0;
> > +
> > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > +                                 HW_INFO_ENV_OFFSET);
> > +     if (ret)
> > +             goto err;
> > +     if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > +             ret = -EFAULT;
> > +             goto err;
> > +     }
> > +
> > +     printf("Successfully imported the Marvell hw_info parameters.\n");
> > +     if (!print_env)
> > +             return 0;
> > +
> > +     len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > +     if (len > 0) {
> > +             printf("Updated environment:\n");
> > +             puts(res);
> > +             free(res);
> > +             return 0;
> > +     }
> > +err:
> > +     printf("## Error: cannot import hw_info parameters\n");
> > +     return ret;
> > +}
> > +
> > +/**
> > + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> > + * @name: Name of the U-Boot env parameter to save
> > + *
> > + * This function finds the specified parameter by name in the U-Boot env
> > + * and then updates the Marvell hw_info parameters with the new value.
> > + */
> > +static int cmd_hw_info_save(char *name)
> > +{
> > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > +     struct env_entry e, *ep, *rv;
> > +     struct hsearch_data htab;
> > +     char *res = NULL;
> > +     ssize_t len;
> > +     int ret = 0;
> > +
> > +     ret = hw_info_check_parameter(name);
> > +     if (ret) {
> > +             printf("Invalid parameter %s, stopping.\n", name);
> > +             goto err;
> > +     }
> > +
> > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > +                                 HW_INFO_ENV_OFFSET);
> > +     if (ret)
> > +             goto err;
> > +     memset(&htab, 0, sizeof(htab));
> > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > +             ret = -ENOMEM;
> > +             goto err;
> > +     }
> > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > +             ret = -EFAULT;
> > +             goto err_htab;
> > +     }
> > +
> > +     e.key = name;
> > +     e.data = NULL;
> > +     if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> > +             ret = -ENOENT;
> > +             goto err_htab;
> > +     }
> > +     if (!ep) {
> > +             ret = -ENOENT;
> > +             goto err_htab;
> > +     }
> > +
> > +     printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> > +
> > +     e.key = ep->key;
> > +     e.data = ep->data;
> > +     if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> > +             ret = -EINVAL;
> > +             goto err_htab;
> > +     }
> > +     if (!rv) {
> > +             ret = -EINVAL;
> > +             goto err_htab;
> > +     }
> > +     len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> > +                     &res, 0, 0, NULL);
> > +     if (len <= 0) {
> > +             free(res);
> > +             goto ret_htab;
> > +     }
> > +     ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> > +                                  HW_INFO_ENV_OFFSET, len);
> > +     free(res);
> > +     if (ret)
> > +             goto err_htab;
> > +
> > +     printf("Successfully stored the Marvell hw_info parameters.\n");
> > +     return 0;
> > +ret_htab:
> > +     hdestroy_r(&htab);
> > +     return ret;
> > +err_htab:
> > +     hdestroy_r(&htab);
> > +err:
> > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > +     return ret;
> > +}
> > +
> > +/**
> > + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> > + *
> > + * This function reads the content of the Marvell hw_info parameters from the
> > + * SPI flash and imports them into the U-Boot environment.
> > + * This includes MAC addresses and board serial numbers.
> > + *
> > + * The import is performed only once.
> > + *
> > + * This function is a part of the U-Boot mac command and must be executed
> > + * after SPI flash initialization.
> > + */
> > +int mac_read_from_eeprom(void)
> > +{
> > +     if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> > +             if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> > +                     return -ENOENT;
> > +             return cmd_hw_info_read(false);
> > +     }
> > +     return 0;
> > +}
> > +
> > +/**
> > + * print_platform_help() - Print the platform specific help
> > + *
> > + * Extend the existing U-Boot mac command description by also printing
> > + * platform specific help text.
> > + */
> > +static void print_platform_help(void)
> > +{
> > +     printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> > +            "are unavailable on Marvell Armada A37xx platforms.\n"
> > +            "Use mac [read|save {parameter}] instead.\n"
> > +            "Available parameters:\n"
> > +            "pcb_slm\tPCB SLM number\n"
> > +            "pcb_rev\tPCB revision number\n"
> > +            "eco_rev\tECO revision number\n"
> > +            "pcb_sn\tPCB SN\n"
> > +            "ethaddr\tfirst MAC address\n"
> > +            "eth[1-9]addr\tsecond-ninth MAC address\n");
> > +}
> > +
> > +/**
> > + * do_mac() - Standard U-Boot mac command implementation
> > + * @cmdtp: U-Boot command table
> > + * @flag: Execution flags
> > + * @argc: Count of arguments
> > + * @argv: Arguments
> > + *
> > + * This function implements the standard U-Boot mac command in a mostly
> > + * compatible way.
> > + * To conform to the general command structure as much as possible, the
> > + * command description from cmd/mac.c is followed.
> > + * Where not possible, convenient or sensible additional comments for the user
> > + * are added.
> > + */
> > +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > +{
> > +     const char *cmd = argv[1];
> > +     int ret = 0;
> > +
> > +     if (argc == 1) {
> > +             ret = cmd_hw_info_dump();
> > +             if (ret)
> > +                     return -EINVAL;
> > +             return CMD_RET_SUCCESS;
> > +     }
> > +
> > +     if (!strcmp(cmd, "read")) {
> > +             if (cmd_hw_info_read(true))
> > +                     return -EINVAL;
> > +     } else if (!strcmp(cmd, "save")) {
> > +             if (argc != 3) {
> > +                     printf("Please pass an additional argument to specify, "
> > +                            "which env parameter to save.\n");
> > +                     return -EINVAL;
> > +             }
> > +             if (cmd_hw_info_save(argv[2]))
> > +                     return -EINVAL;
> > +     } else {
> > +             ret = cmd_usage(cmdtp);
> > +             print_platform_help();
> > +             return ret;
> > +     }
> > +
> > +     return CMD_RET_SUCCESS;
> > +}
> > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > index c8c34d7d92..8e8bcfa018 100644
> > --- a/include/configs/mvebu_armada-37xx.h
> > +++ b/include/configs/mvebu_armada-37xx.h
> > @@ -62,6 +62,13 @@
> >   */
> >  #define DEFAULT_ENV_IS_RW            /* required for configuring default fdtfile= */
> >
> > +/*
> > + * Platform identification (Marvell hw_info parameters)
> > + */
> > +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> > +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> > +#endif
> > +
> >  /*
> >   * Ethernet Driver configuration
> >   */
> > diff --git a/lib/hashtable.c b/lib/hashtable.c
> > index ff5ff72639..06322e3304 100644
> > --- a/lib/hashtable.c
> > +++ b/lib/hashtable.c
> > @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
> >   * multi-line values.
> >   *
> >   * In theory, arbitrary separator characters can be used, but only
> > - * '\0' and '\n' have really been tested.
> > + * '\0', '\n' and 0x20 have been tested.
> >   */
> >
> >  int himport_r(struct hsearch_data *htab,
> > --
> > 2.31.1
> >

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-12 23:39 ` [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support Luka Kovacic
  2021-08-13  8:14   ` Pali Rohár
@ 2021-08-13  9:27   ` Pali Rohár
  2021-08-13 10:03     ` Luka Kovacic
  1 sibling, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  9:27 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> Technologies, Inc.
> 
> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> Peripherals:
>  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
>  - RTC clock (PCF8563)
>  - USB 3.0 port
>  - USB 2.0 port
>  - 4x LED
>  - UART over Micro-USB
>  - M.2 slot (2280)
>  - Mini PCI-E slot
> 
> Additionally, automatic import of the Marvell hw_info parameters is
> enabled via the recently added mac command for A37XX platforms.
> The parameters stored in Marvell hw_info are usually the board serial
> number and MAC addresses.
> 
> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Robert Marko <robert.marko@sartura.hr>
> ---
>  arch/arm/dts/Makefile                         |   1 +
>  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
>  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
>  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
>  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
>  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
>  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
>  7 files changed, 514 insertions(+), 203 deletions(-)
>  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
>  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
>  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
...
> diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> index 2de9c2ac17..21c1eb7b22 100644
> --- a/board/Marvell/mvebu_armada-37xx/board.c
> +++ b/board/Marvell/mvebu_armada-37xx/board.c
> @@ -11,6 +11,7 @@
>  #include <i2c.h>
>  #include <init.h>
>  #include <mmc.h>
> +#include <miiphy.h>
>  #include <phy.h>
>  #include <asm/global_data.h>
>  #include <asm/io.h>
> @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
>  #define MVEBU_G2_SMI_PHY_CMD_REG	(24)
>  #define MVEBU_G2_SMI_PHY_DATA_REG	(25)
>  
> +/* Marvell 88E1512 */
> +#define MII_MARVELL_PHY_PAGE		22
> +
> +#define MV88E1512_GENERAL_CTRL		20
> +#define MV88E1512_MODE_SGMII		1
> +#define MV88E1512_RESET_OFFS		15
> +
> +#define ULTRA_MV88E1512_PHYADDR		0x1
> +
>  /*
>   * Memory Controller Registers
>   *
> @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
>  	return 0;
>  }
>  
> -/* Bring-up board-specific network stuff */
> -int board_network_enable(struct mii_dev *bus)
> +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
>  {
> -	if (!of_machine_is_compatible("globalscale,espressobin"))
> -		return 0;
> +	const char *name;
> +	u16 reg;
> +
> +	name = miiphy_get_current_dev();
> +	if (name) {

It is possible that phy is not available? As you are calling code below
only in case name is not-NULL.

> +		/* SGMII-to-Copper mode initialization */
> +
> +		/* Select page 18 */
> +		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> +		/* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> +		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> +		reg &= ~0x7;
> +		reg |= MV88E1512_MODE_SGMII;
> +		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> +		/* PHY reset is necessary after changing MODE[2:0] */
> +		miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> +		reg |= 1 << MV88E1512_RESET_OFFS;
> +		miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> +		/* Reset page selection */
> +		miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> +		udelay(100);
> +	}
> +}
> +
> +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> +{
> +	int i;
> +	/* Setup 88E1512 SGMII-to-Copper mode */
> +	force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
>  
> +	/*
> +	 * FIXME: remove this code once Topaz driver gets available
> +	 * A3720 ESPRESSObin Ultra Board Only
> +	 * Configure Topaz switch (88E6341)
> +	 * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> +	 */
> +	for (i = 0; i <= 5; i++) {
> +		mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> +					  MVEBU_SW_PORT_CTRL_REG,
> +					  i == 5 ? 0x7c : 0x7f);

Why port 5 has different settings?

> +	}
> +
> +	/* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> +	mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> +				  MVEBU_SW_LINK_CTRL_REG, 0xe002);
> +
> +	/* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> +	mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> +				  MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> +	for (i = 1; i <= 5; i++) {
> +		mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> +					  MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> +					  (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> +	}

It looks like that by copying board_network_enable_espressobin_ultra()
function from Marvell U-Boot instead of using code which is in mainline
function board_network_enable() for Espressobin, you are introducing a
security hole, which is in Marvell U-Boot and which was fixed in
mainline U-Boot for all supported Espressobin boards (see commit
48f2c8a37f700859a7004dce5adb116597a45700).

I would really suggest to not blindly copy old code from Marvell into
mainline U-Boot, as here we have fixed lot of issues.

> +	return 0;
> +}
> +
> +int board_network_enable_espressobin(struct mii_dev *bus)
> +{
>  	/*
>  	 * FIXME: remove this code once Topaz driver gets available
>  	 * A3720 Community Board Only
> @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
>  	return 0;
>  }
>  
> +/* Bring-up the board-specific networking */
> +int board_network_enable(struct mii_dev *bus)
> +{
> +	if (of_machine_is_compatible("globalscale,espressobin"))
> +		return board_network_enable_espressobin(bus);
> +	if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> +		return board_network_enable_espressobin_ultra(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)
>  {
> @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
>  	int parts_off;
>  	int part_off;
>  
> -	/* Fill SPI MTD partitions for Linux kernel on Espressobin */
> -	if (!of_machine_is_compatible("globalscale,espressobin"))
> +	/*
> +	 * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> +	 * ESPRESSOBin Ultra boards.
> +	 */
> +	if (!of_machine_is_compatible("globalscale,espressobin") &&
> +	    !of_machine_is_compatible("globalscale,espressobin-ultra"))
>  		return 0;

According to kernel DTS file, it looks like that Espressobin Ultra has
different MTD partitions as other variants... Therefore Ultra needs
adjustments in this code.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78

>  
>  	spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-13  8:59     ` Luka Kovacic
@ 2021-08-13  9:31       ` Pali Rohár
  2021-08-13  9:33         ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  9:31 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 10:59:33 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 10:08 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > > Add the loadaddr U-Boot environment variable, as this is available in
> > > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> >
> > Hello Luka! Why is this change needed? Reason that it is in historic
> > vendor U-Boot does not mean that it has to be also in new mainline
> > version.
> >
> > I have already wrote some reasons in previous review thread:
> > https://lore.kernel.org/u-boot/20210301150505.3iajeeufi7ahsnk3@pali/
> >
> > I think this change was needed when CONFIG_SYS_LOAD_ADDR was set to
> > incorrect value, which is already fixed in mainline U-Boot.
> 
> This value is very useful when building custom Linux boot scripts.
> Yesterday, I booted the board without this patch and there was no loadaddr
> variable.
> 
> Do I understand this correctly? Are you saying that the value in the loadaddr
> variable should be automatically inherited from CONFIG_SYS_LOAD_ADDR
> even without this patch?

If you do not specify load address then address from
CONFIG_SYS_LOAD_ADDR is used. But as I mentioned in above email,
CONFIG_SYS_LOAD_ADDR was defined incorrectly and which cause that it did
not worked and caused crashes...

> >
> > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > ---
> > >  include/configs/mvebu_armada-37xx.h | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > index 8e8bcfa018..6901680e32 100644
> > > --- a/include/configs/mvebu_armada-37xx.h
> > > +++ b/include/configs/mvebu_armada-37xx.h
> > > @@ -110,6 +110,7 @@
> > >
> > >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> > >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > > +     "loadaddr=0x6000000\0"          \
> > >       "scriptaddr=0x6d00000\0"        \
> > >       "pxefile_addr_r=0x6e00000\0"    \
> > >       "fdt_addr=0x6f00000\0"          \
> > > --
> > > 2.31.1
> > >
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-13  9:31       ` Pali Rohár
@ 2021-08-13  9:33         ` Luka Kovacic
  2021-08-13  9:42           ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13  9:33 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 11:31 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 10:59:33 Luka Kovacic wrote:
> > Hello Pali,
> >
> > On Fri, Aug 13, 2021 at 10:08 AM Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > > > Add the loadaddr U-Boot environment variable, as this is available in
> > > > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> > >
> > > Hello Luka! Why is this change needed? Reason that it is in historic
> > > vendor U-Boot does not mean that it has to be also in new mainline
> > > version.
> > >
> > > I have already wrote some reasons in previous review thread:
> > > https://lore.kernel.org/u-boot/20210301150505.3iajeeufi7ahsnk3@pali/
> > >
> > > I think this change was needed when CONFIG_SYS_LOAD_ADDR was set to
> > > incorrect value, which is already fixed in mainline U-Boot.
> >
> > This value is very useful when building custom Linux boot scripts.
> > Yesterday, I booted the board without this patch and there was no loadaddr
> > variable.
> >
> > Do I understand this correctly? Are you saying that the value in the loadaddr
> > variable should be automatically inherited from CONFIG_SYS_LOAD_ADDR
> > even without this patch?
>
> If you do not specify load address then address from
> CONFIG_SYS_LOAD_ADDR is used. But as I mentioned in above email,
> CONFIG_SYS_LOAD_ADDR was defined incorrectly and which cause that it did
> not worked and caused crashes...

I tried not specifying it and then the loadaddr variable doesn't even exist.

>
> > >
> > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > ---
> > > >  include/configs/mvebu_armada-37xx.h | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > > index 8e8bcfa018..6901680e32 100644
> > > > --- a/include/configs/mvebu_armada-37xx.h
> > > > +++ b/include/configs/mvebu_armada-37xx.h
> > > > @@ -110,6 +110,7 @@
> > > >
> > > >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> > > >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > > > +     "loadaddr=0x6000000\0"          \
> > > >       "scriptaddr=0x6d00000\0"        \
> > > >       "pxefile_addr_r=0x6e00000\0"    \
> > > >       "fdt_addr=0x6f00000\0"          \
> > > > --
> > > > 2.31.1
> > > >
> >
> > Kind regards,
> > Luka

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13  9:23     ` Luka Kovacic
@ 2021-08-13  9:41       ` Pali Rohár
  2021-08-13  9:51         ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  9:41 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: Marek Behun, u-boot, Robert Marko, Luka Perkov, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 11:23:15 Luka Kovacic wrote:
> Hello Marek and Pali,
> 
> On Fri, Aug 13, 2021 at 10:23 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > > The mac command is implemented to enable parsing Marvell hw_info formatted
> > > environments. This format is often used on Marvell Armada A37XX based
> > > devices to store parameters like the board serial number, factory
> > > MAC addresses and some other information.
> > > These parameters are usually written to the flash in the factory.
> > >
> > > Currently the mac command supports reading/writing parameters and dumping
> > > the current hw_info parameters.
> > > EEPROM config pattern and checksum aren't supported.
> > >
> > > This functionality has been tested on the GST ESPRESSOBin-Ultra board
> > > successfully, both reading the stock U-Boot parameters in mainline U-Boot
> > > and reading the parameters written by this command in the stock U-Boot.
> > >
> > > Usage example:
> > >  => mac read
> > >  => saveenv
> >
> > Hello Luka!
> >
> > You are just using above commands for accessing following variables,
> > right?
> >
> > pcb_slm
> > pcb_rev
> > eco_rev
> > pcb_sn
> > ethaddr
> > eth1addr
> > eth2addr
> > eth3addr
> > eth4addr
> > eth5addr
> > eth6addr
> > eth7addr
> > eth8addr
> > eth9addr
> >
> 
> Yes, I am accessing these variables.
> 
> > So why is additional command required? Espressobin boards can already
> > load and use correct eth*addr variables, which is implemented in board
> > file.
> 
> The current implementation in the board file preserves currently stored MAC
> addresses, which are in the U-Boot environment.

Yes, this is for v5/v7 variants. But it can be easily modified for ultra
to read mac addresses from this custom storage.

> My implementation is suitable for the ESPRESSOBin-Ultra, as the MACs
> are stored in the hw_info area of the SPI flash and the tool imports them
> into the normal U-Boot env.
> They can also be modified using the tool - we won't be able to get this
> functionality in the board file.

Modification by env variables is also possible from the board file. Look
at U_BOOT_ENV_CALLBACK() functionality, which allows to call custom code
when trying to change/delete particular env variable.

> > So what about implementing this import for all above variables for ultra
> > variant in board file, like it is already for all other variants? I have
> > already suggested it in the past. As I think this approach is just one
> > giant and complicated hack...
> > https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/
> >
> > I guess that it should be enough to import variables from SPI to env in
> > board_late_init() function.
> 
> Currently, the MACs are automatically imported from the
> common/board_r.c file at boot, I think this is more standard and cleaner.

Hm... then I somehow misunderstood how it works.

Because I do not see any change in common/board_r.c which could read or
import mac addresses via calling this new "mac read" command.

> Nevertheless, I believe this a sufficient solution for now,
> as this has been suggested as a solution in the previous patchset
> comments too.
> 
> >
> > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > ---
> > >  arch/arm/mach-mvebu/Kconfig                   |   1 +
> > >  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
> > >  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
> > >  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
> > >  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
> > >  include/configs/mvebu_armada-37xx.h           |   7 +
> > >  lib/hashtable.c                               |   2 +-
> > >  7 files changed, 436 insertions(+), 2 deletions(-)
> > >  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
> > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
> > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > >
> > > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> > > index 89737a37ad..dff9f05b28 100644
> > > --- a/arch/arm/mach-mvebu/Kconfig
> > > +++ b/arch/arm/mach-mvebu/Kconfig
> > > @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
> > >       default 0
> > >       depends on SECURED_MODE_IMAGE
> > >
> > > +source "board/Marvell/mvebu_armada-37xx/Kconfig"
> > >  source "board/solidrun/clearfog/Kconfig"
> > >  source "board/kobol/helios4/Kconfig"
> > >
> > > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > new file mode 100644
> > > index 0000000000..b84dd20023
> > > --- /dev/null
> > > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > @@ -0,0 +1,29 @@
> > > +menu "Marvell Armada 37xx configuration"
> > > +depends on TARGET_MVEBU_ARMADA_37XX
> > > +
> > > +config MVEBU_MAC_HW_INFO
> > > +     bool "Marvell hw_info (mac) support"
> > > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > > +     default n
> > > +     help
> > > +       Enable loading of the Marvell hw_info parameters from the
> > > +       SPI flash hw_info area. Parameters (usually the board serial
> > > +       number and MAC addresses) are then imported into the
> > > +       existing U-Boot environment.
> > > +       Implementation of this command is compatible with the
> > > +       original Marvell U-Boot command. Reading and writing is
> > > +       supported.
> > > +       EEPROM config pattern and checksum aren't supported.
> > > +       After enabled, these parameters are managed from the common
> > > +       U-Boot mac command.
> > > +
> > > +config MVEBU_MAC_HW_INFO_OFFSET
> > > +     hex "Marvell hw_info (mac) SPI flash offset"
> > > +     depends on MVEBU_MAC_HW_INFO
> > > +     default 0x3E0000
> > > +     help
> > > +       This option defines the SPI flash offset of the Marvell
> > > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > > +       A3720 platforms.
> > > +
> > > +endmenu
> > > diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> > > index 27221557c7..6f6ac6b193 100644
> > > --- a/board/Marvell/mvebu_armada-37xx/Makefile
> > > +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> > > @@ -2,4 +2,5 @@
> > >  #
> > >  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
> > >
> > > -obj-y        := board.o
> > > +obj-y += board.o
> > > +obj-y += mac/
> > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > new file mode 100644
> > > index 0000000000..7c30fe6194
> > > --- /dev/null
> > > +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > @@ -0,0 +1,5 @@
> > > +# SPDX-License-Identifier: GPL-2.0+
> > > +#
> > > +# Copyright (c) 2021 Sartura Ltd.
> > > +
> > > +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > new file mode 100644
> > > index 0000000000..91e5cd8dcf
> > > --- /dev/null
> > > +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > @@ -0,0 +1,391 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * Marvell hw_info (mac) command implementation
> > > + * Helper command for interfacing with the Marvell hw_info parameters
> > > + *
> > > + * Copyright (c) 2021 Sartura Ltd.
> > > + * Copyright (c) 2018 Marvell International Ltd.
> > > + *
> > > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > > + */
> > > +
> > > +#include <command.h>
> > > +#include <common.h>
> > > +#include <env.h>
> > > +#include <env_internal.h>
> > > +#include <spi.h>
> > > +#include <spi_flash.h>
> > > +
> > > +#define HW_INFO_SPI_FLASH_OFFSET     CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> > > +
> > > +#define HW_INFO_MAX_ENV_SIZE         0x1F0
> > > +#define HW_INFO_ENV_OFFSET           0xA
> > > +#define HW_INFO_ENV_SEP                      0x20
> > > +
> > > +#define HW_INFO_MAX_NAME_LEN         32
> > > +
> > > +#define HW_INFO_MERGED_VARIABLE              "read_board_hw_info"
> > > +
> > > +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> > > +     "pcb_slm",
> > > +     "pcb_rev",
> > > +     "eco_rev",
> > > +     "pcb_sn",
> > > +     "ethaddr",
> > > +     "eth1addr",
> > > +     "eth2addr",
> > > +     "eth3addr",
> > > +     "eth4addr",
> > > +     "eth5addr",
> > > +     "eth6addr",
> > > +     "eth7addr",
> > > +     "eth8addr",
> > > +     "eth9addr",
> > > +};
> > > +
> > > +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> > > +                                     sizeof(hw_info_allowed_parameters[0]));
> > > +
> > > +static int hw_info_check_parameter(char *name)
> > > +{
> > > +     int idx;
> > > +
> > > +     for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> > > +             if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> > > +                     return 0;
> > > +     }
> > > +
> > > +     return -EINVAL;
> > > +}
> > > +
> > > +/**
> > > + * read_spi_flash_offset() - Read data from the SPI flash
> > > + * @buf: Buffer to write in
> > > + * @offset: Offset from the flash start
> > > + *
> > > + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> > > + */
> > > +static int read_spi_flash_offset(char *buf, int offset)
> > > +{
> > > +     struct spi_flash *flash;
> > > +     int ret;
> > > +
> > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > +                             CONFIG_SF_DEFAULT_CS,
> > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > +                             CONFIG_SF_DEFAULT_MODE);
> > > +
> > > +     if (!flash) {
> > > +             printf("Error - unable to probe SPI flash.\n");
> > > +             return -EIO;
> > > +     }
> > > +
> > > +     ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> > > +     if (ret) {
> > > +             printf("Error - unable to read hw_info environment from SPI flash.\n");
> > > +             return ret;
> > > +     }
> > > +
> > > +     return ret;
> > > +}
> > > +
> > > +/**
> > > + * write_spi_flash_offset() - Write a buffer to SPI flash
> > > + * @buf: Buffer to write to SPI flash
> > > + * @offset: Offset from the flash start
> > > + * @size: Size of the buffer content
> > > + *
> > > + * This function probes the SPI flash and updates the specified flash location
> > > + * with new data from the buffer.
> > > + */
> > > +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> > > +{
> > > +     ssize_t safe_size, erase_size;
> > > +     struct spi_flash *flash;
> > > +     int ret;
> > > +
> > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > +                             CONFIG_SF_DEFAULT_CS,
> > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > +                             CONFIG_SF_DEFAULT_MODE);
> > > +
> > > +     if (!flash) {
> > > +             printf("Error - unable to probe SPI flash.\n");
> > > +             return -EIO;
> > > +     }
> > > +
> > > +     safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> > > +     erase_size = safe_size +
> > > +                  (flash->erase_size - safe_size % flash->erase_size);
> > > +     ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> > > +     if (ret) {
> > > +             printf("Error - unable to erase the hw_info area on SPI flash.\n");
> > > +             return ret;
> > > +     }
> > > +     ret = spi_flash_write(flash, offset, safe_size, buf);
> > > +     if (ret) {
> > > +             printf("Error - unable to write hw_info parameters to SPI flash.\n");
> > > +             return ret;
> > > +     }
> > > +
> > > +     return ret;
> > > +}
> > > +
> > > +/**
> > > + * cmd_hw_info_dump() - Dump the hw_info parameters
> > > + *
> > > + * This function prints all Marvell hw_info parameters, which are stored in
> > > + * the SPI flash.
> > > + */
> > > +static int cmd_hw_info_dump(void)
> > > +{
> > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > +     struct hsearch_data htab;
> > > +     char *res = NULL;
> > > +     ssize_t len;
> > > +     int ret = 0;
> > > +
> > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > +                                 HW_INFO_ENV_OFFSET);
> > > +     if (ret)
> > > +             goto err;
> > > +     memset(&htab, 0, sizeof(htab));
> > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > +             ret = -ENOMEM;
> > > +             goto err;
> > > +     }
> > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > +             ret = -EFAULT;
> > > +             goto err_htab;
> > > +     }
> > > +
> > > +     len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > +     if (len > 0) {
> > > +             printf("Parameters (hw_info):\n");
> > > +             puts(res);
> > > +             free(res);
> > > +             ret = 0;
> > > +             goto ret_htab;
> > > +     }
> > > +ret_htab:
> > > +     hdestroy_r(&htab);
> > > +     return ret;
> > > +err_htab:
> > > +     hdestroy_r(&htab);
> > > +err:
> > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > +     return ret;
> > > +}
> > > +
> > > +/**
> > > + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> > > + * @print_env: Print U-Boot environment after new parameters are imported
> > > + *
> > > + * This function reads the Marvell hw_info parameters from SPI flash and
> > > + * imports them into the U-Boot env.
> > > + */
> > > +static int cmd_hw_info_read(bool print_env)
> > > +{
> > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > +     char *res = NULL;
> > > +     ssize_t len;
> > > +     int ret = 0;
> > > +
> > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > +                                 HW_INFO_ENV_OFFSET);
> > > +     if (ret)
> > > +             goto err;
> > > +     if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > +             ret = -EFAULT;
> > > +             goto err;
> > > +     }
> > > +
> > > +     printf("Successfully imported the Marvell hw_info parameters.\n");
> > > +     if (!print_env)
> > > +             return 0;
> > > +
> > > +     len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > +     if (len > 0) {
> > > +             printf("Updated environment:\n");
> > > +             puts(res);
> > > +             free(res);
> > > +             return 0;
> > > +     }
> > > +err:
> > > +     printf("## Error: cannot import hw_info parameters\n");
> > > +     return ret;
> > > +}
> > > +
> > > +/**
> > > + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> > > + * @name: Name of the U-Boot env parameter to save
> > > + *
> > > + * This function finds the specified parameter by name in the U-Boot env
> > > + * and then updates the Marvell hw_info parameters with the new value.
> > > + */
> > > +static int cmd_hw_info_save(char *name)
> > > +{
> > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > +     struct env_entry e, *ep, *rv;
> > > +     struct hsearch_data htab;
> > > +     char *res = NULL;
> > > +     ssize_t len;
> > > +     int ret = 0;
> > > +
> > > +     ret = hw_info_check_parameter(name);
> > > +     if (ret) {
> > > +             printf("Invalid parameter %s, stopping.\n", name);
> > > +             goto err;
> > > +     }
> > > +
> > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > +                                 HW_INFO_ENV_OFFSET);
> > > +     if (ret)
> > > +             goto err;
> > > +     memset(&htab, 0, sizeof(htab));
> > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > +             ret = -ENOMEM;
> > > +             goto err;
> > > +     }
> > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > +             ret = -EFAULT;
> > > +             goto err_htab;
> > > +     }
> > > +
> > > +     e.key = name;
> > > +     e.data = NULL;
> > > +     if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> > > +             ret = -ENOENT;
> > > +             goto err_htab;
> > > +     }
> > > +     if (!ep) {
> > > +             ret = -ENOENT;
> > > +             goto err_htab;
> > > +     }
> > > +
> > > +     printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> > > +
> > > +     e.key = ep->key;
> > > +     e.data = ep->data;
> > > +     if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> > > +             ret = -EINVAL;
> > > +             goto err_htab;
> > > +     }
> > > +     if (!rv) {
> > > +             ret = -EINVAL;
> > > +             goto err_htab;
> > > +     }
> > > +     len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> > > +                     &res, 0, 0, NULL);
> > > +     if (len <= 0) {
> > > +             free(res);
> > > +             goto ret_htab;
> > > +     }
> > > +     ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> > > +                                  HW_INFO_ENV_OFFSET, len);
> > > +     free(res);
> > > +     if (ret)
> > > +             goto err_htab;
> > > +
> > > +     printf("Successfully stored the Marvell hw_info parameters.\n");
> > > +     return 0;
> > > +ret_htab:
> > > +     hdestroy_r(&htab);
> > > +     return ret;
> > > +err_htab:
> > > +     hdestroy_r(&htab);
> > > +err:
> > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > +     return ret;
> > > +}
> > > +
> > > +/**
> > > + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> > > + *
> > > + * This function reads the content of the Marvell hw_info parameters from the
> > > + * SPI flash and imports them into the U-Boot environment.
> > > + * This includes MAC addresses and board serial numbers.
> > > + *
> > > + * The import is performed only once.
> > > + *
> > > + * This function is a part of the U-Boot mac command and must be executed
> > > + * after SPI flash initialization.
> > > + */
> > > +int mac_read_from_eeprom(void)
> > > +{
> > > +     if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> > > +             if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> > > +                     return -ENOENT;
> > > +             return cmd_hw_info_read(false);
> > > +     }
> > > +     return 0;
> > > +}
> > > +
> > > +/**
> > > + * print_platform_help() - Print the platform specific help
> > > + *
> > > + * Extend the existing U-Boot mac command description by also printing
> > > + * platform specific help text.
> > > + */
> > > +static void print_platform_help(void)
> > > +{
> > > +     printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> > > +            "are unavailable on Marvell Armada A37xx platforms.\n"
> > > +            "Use mac [read|save {parameter}] instead.\n"
> > > +            "Available parameters:\n"
> > > +            "pcb_slm\tPCB SLM number\n"
> > > +            "pcb_rev\tPCB revision number\n"
> > > +            "eco_rev\tECO revision number\n"
> > > +            "pcb_sn\tPCB SN\n"
> > > +            "ethaddr\tfirst MAC address\n"
> > > +            "eth[1-9]addr\tsecond-ninth MAC address\n");
> > > +}
> > > +
> > > +/**
> > > + * do_mac() - Standard U-Boot mac command implementation
> > > + * @cmdtp: U-Boot command table
> > > + * @flag: Execution flags
> > > + * @argc: Count of arguments
> > > + * @argv: Arguments
> > > + *
> > > + * This function implements the standard U-Boot mac command in a mostly
> > > + * compatible way.
> > > + * To conform to the general command structure as much as possible, the
> > > + * command description from cmd/mac.c is followed.
> > > + * Where not possible, convenient or sensible additional comments for the user
> > > + * are added.
> > > + */
> > > +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > > +{
> > > +     const char *cmd = argv[1];
> > > +     int ret = 0;
> > > +
> > > +     if (argc == 1) {
> > > +             ret = cmd_hw_info_dump();
> > > +             if (ret)
> > > +                     return -EINVAL;
> > > +             return CMD_RET_SUCCESS;
> > > +     }
> > > +
> > > +     if (!strcmp(cmd, "read")) {
> > > +             if (cmd_hw_info_read(true))
> > > +                     return -EINVAL;
> > > +     } else if (!strcmp(cmd, "save")) {
> > > +             if (argc != 3) {
> > > +                     printf("Please pass an additional argument to specify, "
> > > +                            "which env parameter to save.\n");
> > > +                     return -EINVAL;
> > > +             }
> > > +             if (cmd_hw_info_save(argv[2]))
> > > +                     return -EINVAL;
> > > +     } else {
> > > +             ret = cmd_usage(cmdtp);
> > > +             print_platform_help();
> > > +             return ret;
> > > +     }
> > > +
> > > +     return CMD_RET_SUCCESS;
> > > +}
> > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > index c8c34d7d92..8e8bcfa018 100644
> > > --- a/include/configs/mvebu_armada-37xx.h
> > > +++ b/include/configs/mvebu_armada-37xx.h
> > > @@ -62,6 +62,13 @@
> > >   */
> > >  #define DEFAULT_ENV_IS_RW            /* required for configuring default fdtfile= */
> > >
> > > +/*
> > > + * Platform identification (Marvell hw_info parameters)
> > > + */
> > > +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> > > +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> > > +#endif
> > > +
> > >  /*
> > >   * Ethernet Driver configuration
> > >   */
> > > diff --git a/lib/hashtable.c b/lib/hashtable.c
> > > index ff5ff72639..06322e3304 100644
> > > --- a/lib/hashtable.c
> > > +++ b/lib/hashtable.c
> > > @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
> > >   * multi-line values.
> > >   *
> > >   * In theory, arbitrary separator characters can be used, but only
> > > - * '\0' and '\n' have really been tested.
> > > + * '\0', '\n' and 0x20 have been tested.
> > >   */
> > >
> > >  int himport_r(struct hsearch_data *htab,
> > > --
> > > 2.31.1
> > >
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-13  9:33         ` Luka Kovacic
@ 2021-08-13  9:42           ` Pali Rohár
  0 siblings, 0 replies; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  9:42 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 11:33:58 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 11:31 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 10:59:33 Luka Kovacic wrote:
> > > Hello Pali,
> > >
> > > On Fri, Aug 13, 2021 at 10:08 AM Pali Rohár <pali@kernel.org> wrote:
> > > >
> > > > On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > > > > Add the loadaddr U-Boot environment variable, as this is available in
> > > > > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> > > >
> > > > Hello Luka! Why is this change needed? Reason that it is in historic
> > > > vendor U-Boot does not mean that it has to be also in new mainline
> > > > version.
> > > >
> > > > I have already wrote some reasons in previous review thread:
> > > > https://lore.kernel.org/u-boot/20210301150505.3iajeeufi7ahsnk3@pali/
> > > >
> > > > I think this change was needed when CONFIG_SYS_LOAD_ADDR was set to
> > > > incorrect value, which is already fixed in mainline U-Boot.
> > >
> > > This value is very useful when building custom Linux boot scripts.
> > > Yesterday, I booted the board without this patch and there was no loadaddr
> > > variable.
> > >
> > > Do I understand this correctly? Are you saying that the value in the loadaddr
> > > variable should be automatically inherited from CONFIG_SYS_LOAD_ADDR
> > > even without this patch?
> >
> > If you do not specify load address then address from
> > CONFIG_SYS_LOAD_ADDR is used. But as I mentioned in above email,
> > CONFIG_SYS_LOAD_ADDR was defined incorrectly and which cause that it did
> > not worked and caused crashes...
> 
> I tried not specifying it and then the loadaddr variable doesn't even exist.

Could you send full example of your command?

> >
> > > >
> > > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > > ---
> > > > >  include/configs/mvebu_armada-37xx.h | 1 +
> > > > >  1 file changed, 1 insertion(+)
> > > > >
> > > > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > > > index 8e8bcfa018..6901680e32 100644
> > > > > --- a/include/configs/mvebu_armada-37xx.h
> > > > > +++ b/include/configs/mvebu_armada-37xx.h
> > > > > @@ -110,6 +110,7 @@
> > > > >
> > > > >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> > > > >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > > > > +     "loadaddr=0x6000000\0"          \
> > > > >       "scriptaddr=0x6d00000\0"        \
> > > > >       "pxefile_addr_r=0x6e00000\0"    \
> > > > >       "fdt_addr=0x6f00000\0"          \
> > > > > --
> > > > > 2.31.1
> > > > >
> > >
> > > Kind regards,
> > > Luka
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13  9:41       ` Pali Rohár
@ 2021-08-13  9:51         ` Luka Kovacic
  2021-08-13 10:09           ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13  9:51 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Marek Behun, u-boot, Robert Marko, Luka Perkov, sr, sjg,
	patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 11:41 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 11:23:15 Luka Kovacic wrote:
> > Hello Marek and Pali,
> >
> > On Fri, Aug 13, 2021 at 10:23 AM Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > > > The mac command is implemented to enable parsing Marvell hw_info formatted
> > > > environments. This format is often used on Marvell Armada A37XX based
> > > > devices to store parameters like the board serial number, factory
> > > > MAC addresses and some other information.
> > > > These parameters are usually written to the flash in the factory.
> > > >
> > > > Currently the mac command supports reading/writing parameters and dumping
> > > > the current hw_info parameters.
> > > > EEPROM config pattern and checksum aren't supported.
> > > >
> > > > This functionality has been tested on the GST ESPRESSOBin-Ultra board
> > > > successfully, both reading the stock U-Boot parameters in mainline U-Boot
> > > > and reading the parameters written by this command in the stock U-Boot.
> > > >
> > > > Usage example:
> > > >  => mac read
> > > >  => saveenv
> > >
> > > Hello Luka!
> > >
> > > You are just using above commands for accessing following variables,
> > > right?
> > >
> > > pcb_slm
> > > pcb_rev
> > > eco_rev
> > > pcb_sn
> > > ethaddr
> > > eth1addr
> > > eth2addr
> > > eth3addr
> > > eth4addr
> > > eth5addr
> > > eth6addr
> > > eth7addr
> > > eth8addr
> > > eth9addr
> > >
> >
> > Yes, I am accessing these variables.
> >
> > > So why is additional command required? Espressobin boards can already
> > > load and use correct eth*addr variables, which is implemented in board
> > > file.
> >
> > The current implementation in the board file preserves currently stored MAC
> > addresses, which are in the U-Boot environment.
>
> Yes, this is for v5/v7 variants. But it can be easily modified for ultra
> to read mac addresses from this custom storage.
>
> > My implementation is suitable for the ESPRESSOBin-Ultra, as the MACs
> > are stored in the hw_info area of the SPI flash and the tool imports them
> > into the normal U-Boot env.
> > They can also be modified using the tool - we won't be able to get this
> > functionality in the board file.
>
> Modification by env variables is also possible from the board file. Look
> at U_BOOT_ENV_CALLBACK() functionality, which allows to call custom code
> when trying to change/delete particular env variable.
>
> > > So what about implementing this import for all above variables for ultra
> > > variant in board file, like it is already for all other variants? I have
> > > already suggested it in the past. As I think this approach is just one
> > > giant and complicated hack...
> > > https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/
> > >
> > > I guess that it should be enough to import variables from SPI to env in
> > > board_late_init() function.
> >
> > Currently, the MACs are automatically imported from the
> > common/board_r.c file at boot, I think this is more standard and cleaner.
>
> Hm... then I somehow misunderstood how it works.
>
> Because I do not see any change in common/board_r.c which could read or
> import mac addresses via calling this new "mac read" command.

The function mac_read_from_eeprom() is called, if CONFIG_ID_EEPROM is
enabled. This has also been tested and a mechanism was added to avoid
duplicate imports (if the user wants to modify the MAC address, so it then
isn't overwritten).

https://source.denx.de/u-boot/u-boot/-/blob/master/common/board_r.c#L724

>
> > Nevertheless, I believe this a sufficient solution for now,
> > as this has been suggested as a solution in the previous patchset
> > comments too.
> >
> > >
> > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > ---
> > > >  arch/arm/mach-mvebu/Kconfig                   |   1 +
> > > >  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
> > > >  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
> > > >  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
> > > >  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
> > > >  include/configs/mvebu_armada-37xx.h           |   7 +
> > > >  lib/hashtable.c                               |   2 +-
> > > >  7 files changed, 436 insertions(+), 2 deletions(-)
> > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
> > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > >
> > > > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> > > > index 89737a37ad..dff9f05b28 100644
> > > > --- a/arch/arm/mach-mvebu/Kconfig
> > > > +++ b/arch/arm/mach-mvebu/Kconfig
> > > > @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
> > > >       default 0
> > > >       depends on SECURED_MODE_IMAGE
> > > >
> > > > +source "board/Marvell/mvebu_armada-37xx/Kconfig"
> > > >  source "board/solidrun/clearfog/Kconfig"
> > > >  source "board/kobol/helios4/Kconfig"
> > > >
> > > > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > new file mode 100644
> > > > index 0000000000..b84dd20023
> > > > --- /dev/null
> > > > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > @@ -0,0 +1,29 @@
> > > > +menu "Marvell Armada 37xx configuration"
> > > > +depends on TARGET_MVEBU_ARMADA_37XX
> > > > +
> > > > +config MVEBU_MAC_HW_INFO
> > > > +     bool "Marvell hw_info (mac) support"
> > > > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > > > +     default n
> > > > +     help
> > > > +       Enable loading of the Marvell hw_info parameters from the
> > > > +       SPI flash hw_info area. Parameters (usually the board serial
> > > > +       number and MAC addresses) are then imported into the
> > > > +       existing U-Boot environment.
> > > > +       Implementation of this command is compatible with the
> > > > +       original Marvell U-Boot command. Reading and writing is
> > > > +       supported.
> > > > +       EEPROM config pattern and checksum aren't supported.
> > > > +       After enabled, these parameters are managed from the common
> > > > +       U-Boot mac command.
> > > > +
> > > > +config MVEBU_MAC_HW_INFO_OFFSET
> > > > +     hex "Marvell hw_info (mac) SPI flash offset"
> > > > +     depends on MVEBU_MAC_HW_INFO
> > > > +     default 0x3E0000
> > > > +     help
> > > > +       This option defines the SPI flash offset of the Marvell
> > > > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > > > +       A3720 platforms.
> > > > +
> > > > +endmenu
> > > > diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > index 27221557c7..6f6ac6b193 100644
> > > > --- a/board/Marvell/mvebu_armada-37xx/Makefile
> > > > +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > @@ -2,4 +2,5 @@
> > > >  #
> > > >  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
> > > >
> > > > -obj-y        := board.o
> > > > +obj-y += board.o
> > > > +obj-y += mac/
> > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > new file mode 100644
> > > > index 0000000000..7c30fe6194
> > > > --- /dev/null
> > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > @@ -0,0 +1,5 @@
> > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > +#
> > > > +# Copyright (c) 2021 Sartura Ltd.
> > > > +
> > > > +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > new file mode 100644
> > > > index 0000000000..91e5cd8dcf
> > > > --- /dev/null
> > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > @@ -0,0 +1,391 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > +/*
> > > > + * Marvell hw_info (mac) command implementation
> > > > + * Helper command for interfacing with the Marvell hw_info parameters
> > > > + *
> > > > + * Copyright (c) 2021 Sartura Ltd.
> > > > + * Copyright (c) 2018 Marvell International Ltd.
> > > > + *
> > > > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > + */
> > > > +
> > > > +#include <command.h>
> > > > +#include <common.h>
> > > > +#include <env.h>
> > > > +#include <env_internal.h>
> > > > +#include <spi.h>
> > > > +#include <spi_flash.h>
> > > > +
> > > > +#define HW_INFO_SPI_FLASH_OFFSET     CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> > > > +
> > > > +#define HW_INFO_MAX_ENV_SIZE         0x1F0
> > > > +#define HW_INFO_ENV_OFFSET           0xA
> > > > +#define HW_INFO_ENV_SEP                      0x20
> > > > +
> > > > +#define HW_INFO_MAX_NAME_LEN         32
> > > > +
> > > > +#define HW_INFO_MERGED_VARIABLE              "read_board_hw_info"
> > > > +
> > > > +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> > > > +     "pcb_slm",
> > > > +     "pcb_rev",
> > > > +     "eco_rev",
> > > > +     "pcb_sn",
> > > > +     "ethaddr",
> > > > +     "eth1addr",
> > > > +     "eth2addr",
> > > > +     "eth3addr",
> > > > +     "eth4addr",
> > > > +     "eth5addr",
> > > > +     "eth6addr",
> > > > +     "eth7addr",
> > > > +     "eth8addr",
> > > > +     "eth9addr",
> > > > +};
> > > > +
> > > > +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> > > > +                                     sizeof(hw_info_allowed_parameters[0]));
> > > > +
> > > > +static int hw_info_check_parameter(char *name)
> > > > +{
> > > > +     int idx;
> > > > +
> > > > +     for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> > > > +             if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> > > > +                     return 0;
> > > > +     }
> > > > +
> > > > +     return -EINVAL;
> > > > +}
> > > > +
> > > > +/**
> > > > + * read_spi_flash_offset() - Read data from the SPI flash
> > > > + * @buf: Buffer to write in
> > > > + * @offset: Offset from the flash start
> > > > + *
> > > > + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> > > > + */
> > > > +static int read_spi_flash_offset(char *buf, int offset)
> > > > +{
> > > > +     struct spi_flash *flash;
> > > > +     int ret;
> > > > +
> > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > +
> > > > +     if (!flash) {
> > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > +             return -EIO;
> > > > +     }
> > > > +
> > > > +     ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> > > > +     if (ret) {
> > > > +             printf("Error - unable to read hw_info environment from SPI flash.\n");
> > > > +             return ret;
> > > > +     }
> > > > +
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * write_spi_flash_offset() - Write a buffer to SPI flash
> > > > + * @buf: Buffer to write to SPI flash
> > > > + * @offset: Offset from the flash start
> > > > + * @size: Size of the buffer content
> > > > + *
> > > > + * This function probes the SPI flash and updates the specified flash location
> > > > + * with new data from the buffer.
> > > > + */
> > > > +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> > > > +{
> > > > +     ssize_t safe_size, erase_size;
> > > > +     struct spi_flash *flash;
> > > > +     int ret;
> > > > +
> > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > +
> > > > +     if (!flash) {
> > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > +             return -EIO;
> > > > +     }
> > > > +
> > > > +     safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> > > > +     erase_size = safe_size +
> > > > +                  (flash->erase_size - safe_size % flash->erase_size);
> > > > +     ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> > > > +     if (ret) {
> > > > +             printf("Error - unable to erase the hw_info area on SPI flash.\n");
> > > > +             return ret;
> > > > +     }
> > > > +     ret = spi_flash_write(flash, offset, safe_size, buf);
> > > > +     if (ret) {
> > > > +             printf("Error - unable to write hw_info parameters to SPI flash.\n");
> > > > +             return ret;
> > > > +     }
> > > > +
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * cmd_hw_info_dump() - Dump the hw_info parameters
> > > > + *
> > > > + * This function prints all Marvell hw_info parameters, which are stored in
> > > > + * the SPI flash.
> > > > + */
> > > > +static int cmd_hw_info_dump(void)
> > > > +{
> > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > +     struct hsearch_data htab;
> > > > +     char *res = NULL;
> > > > +     ssize_t len;
> > > > +     int ret = 0;
> > > > +
> > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > +                                 HW_INFO_ENV_OFFSET);
> > > > +     if (ret)
> > > > +             goto err;
> > > > +     memset(&htab, 0, sizeof(htab));
> > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > +             ret = -ENOMEM;
> > > > +             goto err;
> > > > +     }
> > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > +             ret = -EFAULT;
> > > > +             goto err_htab;
> > > > +     }
> > > > +
> > > > +     len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > +     if (len > 0) {
> > > > +             printf("Parameters (hw_info):\n");
> > > > +             puts(res);
> > > > +             free(res);
> > > > +             ret = 0;
> > > > +             goto ret_htab;
> > > > +     }
> > > > +ret_htab:
> > > > +     hdestroy_r(&htab);
> > > > +     return ret;
> > > > +err_htab:
> > > > +     hdestroy_r(&htab);
> > > > +err:
> > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> > > > + * @print_env: Print U-Boot environment after new parameters are imported
> > > > + *
> > > > + * This function reads the Marvell hw_info parameters from SPI flash and
> > > > + * imports them into the U-Boot env.
> > > > + */
> > > > +static int cmd_hw_info_read(bool print_env)
> > > > +{
> > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > +     char *res = NULL;
> > > > +     ssize_t len;
> > > > +     int ret = 0;
> > > > +
> > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > +                                 HW_INFO_ENV_OFFSET);
> > > > +     if (ret)
> > > > +             goto err;
> > > > +     if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > +             ret = -EFAULT;
> > > > +             goto err;
> > > > +     }
> > > > +
> > > > +     printf("Successfully imported the Marvell hw_info parameters.\n");
> > > > +     if (!print_env)
> > > > +             return 0;
> > > > +
> > > > +     len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > +     if (len > 0) {
> > > > +             printf("Updated environment:\n");
> > > > +             puts(res);
> > > > +             free(res);
> > > > +             return 0;
> > > > +     }
> > > > +err:
> > > > +     printf("## Error: cannot import hw_info parameters\n");
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> > > > + * @name: Name of the U-Boot env parameter to save
> > > > + *
> > > > + * This function finds the specified parameter by name in the U-Boot env
> > > > + * and then updates the Marvell hw_info parameters with the new value.
> > > > + */
> > > > +static int cmd_hw_info_save(char *name)
> > > > +{
> > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > +     struct env_entry e, *ep, *rv;
> > > > +     struct hsearch_data htab;
> > > > +     char *res = NULL;
> > > > +     ssize_t len;
> > > > +     int ret = 0;
> > > > +
> > > > +     ret = hw_info_check_parameter(name);
> > > > +     if (ret) {
> > > > +             printf("Invalid parameter %s, stopping.\n", name);
> > > > +             goto err;
> > > > +     }
> > > > +
> > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > +                                 HW_INFO_ENV_OFFSET);
> > > > +     if (ret)
> > > > +             goto err;
> > > > +     memset(&htab, 0, sizeof(htab));
> > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > +             ret = -ENOMEM;
> > > > +             goto err;
> > > > +     }
> > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > +             ret = -EFAULT;
> > > > +             goto err_htab;
> > > > +     }
> > > > +
> > > > +     e.key = name;
> > > > +     e.data = NULL;
> > > > +     if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> > > > +             ret = -ENOENT;
> > > > +             goto err_htab;
> > > > +     }
> > > > +     if (!ep) {
> > > > +             ret = -ENOENT;
> > > > +             goto err_htab;
> > > > +     }
> > > > +
> > > > +     printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> > > > +
> > > > +     e.key = ep->key;
> > > > +     e.data = ep->data;
> > > > +     if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> > > > +             ret = -EINVAL;
> > > > +             goto err_htab;
> > > > +     }
> > > > +     if (!rv) {
> > > > +             ret = -EINVAL;
> > > > +             goto err_htab;
> > > > +     }
> > > > +     len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> > > > +                     &res, 0, 0, NULL);
> > > > +     if (len <= 0) {
> > > > +             free(res);
> > > > +             goto ret_htab;
> > > > +     }
> > > > +     ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> > > > +                                  HW_INFO_ENV_OFFSET, len);
> > > > +     free(res);
> > > > +     if (ret)
> > > > +             goto err_htab;
> > > > +
> > > > +     printf("Successfully stored the Marvell hw_info parameters.\n");
> > > > +     return 0;
> > > > +ret_htab:
> > > > +     hdestroy_r(&htab);
> > > > +     return ret;
> > > > +err_htab:
> > > > +     hdestroy_r(&htab);
> > > > +err:
> > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> > > > + *
> > > > + * This function reads the content of the Marvell hw_info parameters from the
> > > > + * SPI flash and imports them into the U-Boot environment.
> > > > + * This includes MAC addresses and board serial numbers.
> > > > + *
> > > > + * The import is performed only once.
> > > > + *
> > > > + * This function is a part of the U-Boot mac command and must be executed
> > > > + * after SPI flash initialization.
> > > > + */
> > > > +int mac_read_from_eeprom(void)
> > > > +{
> > > > +     if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> > > > +             if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> > > > +                     return -ENOENT;
> > > > +             return cmd_hw_info_read(false);
> > > > +     }
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +/**
> > > > + * print_platform_help() - Print the platform specific help
> > > > + *
> > > > + * Extend the existing U-Boot mac command description by also printing
> > > > + * platform specific help text.
> > > > + */
> > > > +static void print_platform_help(void)
> > > > +{
> > > > +     printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> > > > +            "are unavailable on Marvell Armada A37xx platforms.\n"
> > > > +            "Use mac [read|save {parameter}] instead.\n"
> > > > +            "Available parameters:\n"
> > > > +            "pcb_slm\tPCB SLM number\n"
> > > > +            "pcb_rev\tPCB revision number\n"
> > > > +            "eco_rev\tECO revision number\n"
> > > > +            "pcb_sn\tPCB SN\n"
> > > > +            "ethaddr\tfirst MAC address\n"
> > > > +            "eth[1-9]addr\tsecond-ninth MAC address\n");
> > > > +}
> > > > +
> > > > +/**
> > > > + * do_mac() - Standard U-Boot mac command implementation
> > > > + * @cmdtp: U-Boot command table
> > > > + * @flag: Execution flags
> > > > + * @argc: Count of arguments
> > > > + * @argv: Arguments
> > > > + *
> > > > + * This function implements the standard U-Boot mac command in a mostly
> > > > + * compatible way.
> > > > + * To conform to the general command structure as much as possible, the
> > > > + * command description from cmd/mac.c is followed.
> > > > + * Where not possible, convenient or sensible additional comments for the user
> > > > + * are added.
> > > > + */
> > > > +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > > > +{
> > > > +     const char *cmd = argv[1];
> > > > +     int ret = 0;
> > > > +
> > > > +     if (argc == 1) {
> > > > +             ret = cmd_hw_info_dump();
> > > > +             if (ret)
> > > > +                     return -EINVAL;
> > > > +             return CMD_RET_SUCCESS;
> > > > +     }
> > > > +
> > > > +     if (!strcmp(cmd, "read")) {
> > > > +             if (cmd_hw_info_read(true))
> > > > +                     return -EINVAL;
> > > > +     } else if (!strcmp(cmd, "save")) {
> > > > +             if (argc != 3) {
> > > > +                     printf("Please pass an additional argument to specify, "
> > > > +                            "which env parameter to save.\n");
> > > > +                     return -EINVAL;
> > > > +             }
> > > > +             if (cmd_hw_info_save(argv[2]))
> > > > +                     return -EINVAL;
> > > > +     } else {
> > > > +             ret = cmd_usage(cmdtp);
> > > > +             print_platform_help();
> > > > +             return ret;
> > > > +     }
> > > > +
> > > > +     return CMD_RET_SUCCESS;
> > > > +}
> > > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > > index c8c34d7d92..8e8bcfa018 100644
> > > > --- a/include/configs/mvebu_armada-37xx.h
> > > > +++ b/include/configs/mvebu_armada-37xx.h
> > > > @@ -62,6 +62,13 @@
> > > >   */
> > > >  #define DEFAULT_ENV_IS_RW            /* required for configuring default fdtfile= */
> > > >
> > > > +/*
> > > > + * Platform identification (Marvell hw_info parameters)
> > > > + */
> > > > +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> > > > +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> > > > +#endif
> > > > +
> > > >  /*
> > > >   * Ethernet Driver configuration
> > > >   */
> > > > diff --git a/lib/hashtable.c b/lib/hashtable.c
> > > > index ff5ff72639..06322e3304 100644
> > > > --- a/lib/hashtable.c
> > > > +++ b/lib/hashtable.c
> > > > @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
> > > >   * multi-line values.
> > > >   *
> > > >   * In theory, arbitrary separator characters can be used, but only
> > > > - * '\0' and '\n' have really been tested.
> > > > + * '\0', '\n' and 0x20 have been tested.
> > > >   */
> > > >
> > > >  int himport_r(struct hsearch_data *htab,
> > > > --
> > > > 2.31.1
> > > >
> >
> > Kind regards,
> > Luka

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13  9:08     ` Luka Kovacic
@ 2021-08-13  9:54       ` Pali Rohár
  2021-08-13  9:58         ` Stefan Roese
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13  9:54 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 11:08:08 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > Technologies, Inc.
> > >
> > > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > Peripherals:
> > >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > >  - RTC clock (PCF8563)
> > >  - USB 3.0 port
> > >  - USB 2.0 port
> > >  - 4x LED
> > >  - UART over Micro-USB
> > >  - M.2 slot (2280)
> > >  - Mini PCI-E slot
> > >
> > > Additionally, automatic import of the Marvell hw_info parameters is
> > > enabled via the recently added mac command for A37XX platforms.
> > > The parameters stored in Marvell hw_info are usually the board serial
> > > number and MAC addresses.
> > >
> > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > ---
> > >  arch/arm/dts/Makefile                         |   1 +
> > >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > >  7 files changed, 514 insertions(+), 203 deletions(-)
> > >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> >
> > Hello Luka! Please look at my comments from previous review:
> > https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
> >
> > I think it is not a good idea to duplicate espressobin code, specially
> > now when differences between v5, v7, non-emmc and emmc were
> > de-duplicated and correctly detected at runtime. Just use one DTS and
> > one config file and differences can be handled in board code functions
> > "board_fix_fdt" and "board_late_init".
> 
> I believe that patching the DTS at runtime diminishes the value of
> device trees in the first case.
> 
> As far as the v5, v7, non-emmc and emmc boards go I do understand
> that, as they are physically similar and more or less different revisions
> of the same board.
> 
> The ESPRESSOBin Ultra board is completely different from those boards
> physically and so I doesn't make sense to me, why we would merge all
> of them into one device tree.

See email for reasons:
https://lore.kernel.org/u-boot/20210301154101.ke5j2r3lazjlxrsl@pali/

Anyway, I'm looking at differences between ultra and non-ultra boards
which are used by U-Boot... And I see only:
* switch configuration & phy
* i2c rtc
* sdhci slot

Other changes are not used by U-Boot (led).

For switch configuration & phy there is already custom code in U-Boot
board file. For sdhci slot there is also (to enable/disable eMMC after
detection).

So the only difference is presence of i2c rtc, right?

I guess it does not make much sense to copy and duplicate whole DTS and
also defconfig file for such small differences. Insertion of just few
nodes is not a big problem.

These boars are not very different, and having tons of u-boot binaries
for every combination just complicate it as explained in above email.

If you need help with this I can try to do something... as I was already
involved in unification of all v5/v7/emmc/non-emmc variants into one
binary with one DTS.

> I resorted to the Linux way and used a common dtsi for both the
> ESPRESSOBin - which is the base and the ESPRESSOBin-Ultra.
> 
> >
> > > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > > index c42715ead4..f21c9c94d3 100644
> > > --- a/arch/arm/dts/Makefile
> > > +++ b/arch/arm/dts/Makefile
> > > @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
> > >  dtb-$(CONFIG_ARCH_MVEBU) +=                  \
> > >       armada-3720-db.dtb                      \
> > >       armada-3720-espressobin.dtb             \
> > > +     armada-3720-espressobin-ultra.dtb       \
> > >       armada-3720-turris-mox.dtb              \
> > >       armada-3720-uDPU.dtb                    \
> > >       armada-375-db.dtb                       \
> > > diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > new file mode 100644
> > > index 0000000000..5ad0c723e3
> > > --- /dev/null
> > > +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > @@ -0,0 +1,114 @@
> > > +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> > > +/*
> > > + * Device Tree file for ESPRESSObin-Ultra board
> > > + * Copyright (C) 2016 Marvell
> > > + * Copyright (C) 2019 Globalscale technologies, Inc.
> > > + * Copyright (C) 2021 Sartura Ltd.
> > > + *
> > > + * Author: Jason Hung <jhung@globalscaletechnologies.com>
> > > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > > + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
> > > + */
> > > +
> > > +/dts-v1/;
> > > +
> > > +#include "armada-3720-espressobin.dtsi"
> > > +
> > > +/ {
> > > +     model = "Globalscale Marvell ESPRESSOBin Ultra Board";
> > > +     compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
> > > +
> > > +     gpio-leds {
> > > +             pinctrl-names = "default";
> > > +             pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
> > > +             compatible = "gpio-leds";
> > > +
> > > +             led1 {
> > > +                     label = "led1";
> > > +                     gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
> > > +                     default-state = "on";
> > > +             };
> > > +             led2 {
> > > +                     label = "led2";
> > > +                     gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
> > > +                     default-state = "on";
> > > +             };
> > > +             led3 {
> > > +                     label = "led3";
> > > +                     gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
> > > +                     default-state = "on";
> > > +             };
> > > +             led4 {
> > > +                     label = "led4";
> > > +                     gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
> > > +                     default-state = "on";
> > > +             };
> > > +     };
> > > +};
> > > +
> > > +&pinctrl_nb {
> > > +     led1_pins: led1-pins {
> > > +             groups = "pwm0";
> > > +             function = "gpio";
> > > +     };
> > > +     led2_pins: led2-pins {
> > > +             groups = "pwm1";
> > > +             function = "gpio";
> > > +     };
> > > +     led3_pins: led3-pins {
> > > +             groups = "pwm2";
> > > +             function = "gpio";
> > > +     };
> > > +     led4_pins: led4-pins {
> > > +             groups = "pwm3";
> > > +             function = "gpio";
> > > +     };
> > > +};
> > > +
> > > +&eth0 {
> > > +     status = "okay";
> > > +     phy_addr = <0x3>;
> > > +};
> > > +
> > > +&i2c0 {
> > > +     status = "okay";
> > > +     #address-cells = <1>;
> > > +     #size-cells = <0>;
> > > +     rtc@51 {
> > > +             compatible = "nxp,pcf8563";
> > > +             reg = <0x51>;
> > > +     };
> > > +};
> > > +
> > > +&sata {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&sdhci0 {
> > > +     status = "disabled";
> > > +};
> > > +
> > > +&sdhci1 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&spi0 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +/* Exported on the micro USB connector through an FTDI */
> > > +&uart0 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&usb2 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&usb3 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&pcie0 {
> > > +     status = "okay";
> > > +};
> > > diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
> > > index cba6139be6..925ce6a38e 100644
> > > --- a/arch/arm/dts/armada-3720-espressobin.dts
> > > +++ b/arch/arm/dts/armada-3720-espressobin.dts
> > > @@ -1,210 +1,15 @@
> > > +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> > >  /*
> > >   * Device Tree file for Marvell Armada 3720 community board
> > >   * (ESPRESSOBin)
> > >   * Copyright (C) 2016 Marvell
> > > - *
> > > - * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > > - * Konstantin Porotchkin <kostap@marvell.com>
> > > - *
> > > - * This file is dual-licensed: you can use it either under the terms
> > > - * of the GPL or the X11 license, at your option. Note that this dual
> > > - * licensing only applies to this file, and not this project as a
> > > - * whole.
> > > - *
> > > - *  a) This file is free software; you can redistribute it and/or
> > > - *     modify it under the terms of the GNU General Public License as
> > > - *     published by the Free Software Foundation; either version 2 of the
> > > - *     License, or (at your option) any later version.
> > > - *
> > > - *     This file is distributed in the hope that it will be useful
> > > - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > - *     GNU General Public License for more details.
> > > - *
> > > - * Or, alternatively
> > > - *
> > > - *  b) Permission is hereby granted, free of charge, to any person
> > > - *     obtaining a copy of this software and associated documentation
> > > - *     files (the "Software"), to deal in the Software without
> > > - *     restriction, including without limitation the rights to use
> > > - *     copy, modify, merge, publish, distribute, sublicense, and/or
> > > - *     sell copies of the Software, and to permit persons to whom the
> > > - *     Software is furnished to do so, subject to the following
> > > - *     conditions:
> > > - *
> > > - *     The above copyright notice and this permission notice shall be
> > > - *     included in all copies or substantial portions of the Software.
> > > - *
> > > - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > > - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > > - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > > - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > > - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > > - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > > - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > > - *     OTHER DEALINGS IN THE SOFTWARE.
> > >   */
> > >
> > >  /dts-v1/;
> > >
> > > -#include "armada-372x.dtsi"
> > > +#include "armada-3720-espressobin.dtsi"
> > >
> > >  / {
> > >       model = "Globalscale Marvell ESPRESSOBin Board";
> > >       compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > > -
> > > -     chosen {
> > > -             stdout-path = "serial0:115200n8";
> > > -     };
> > > -
> > > -     aliases {
> > > -             ethernet0 = &eth0;
> > > -             i2c0 = &i2c0;
> > > -             spi0 = &spi0;
> > > -     };
> > > -
> > > -     memory {
> > > -             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 {
> > > -     max-lanes = <3>;
> > > -     phy0 {
> > > -             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > > -             phy-speed = <COMPHY_SPEED_5G>;
> > > -     };
> > > -
> > > -     phy1 {
> > > -             phy-type = <COMPHY_TYPE_PEX0>;
> > > -             phy-speed = <COMPHY_SPEED_2_5G>;
> > > -     };
> > > -
> > > -     phy2 {
> > > -             phy-type = <COMPHY_TYPE_SATA0>;
> > > -             phy-speed = <COMPHY_SPEED_5G>;
> > > -     };
> > > -};
> > > -
> > > -&eth0 {
> > > -     status = "okay";
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > > -     phy-mode = "rgmii";
> > > -     phy_addr = <0x1>;
> > > -     fixed-link {
> > > -             speed = <1000>;
> > > -             full-duplex;
> > > -     };
> > > -};
> > > -
> > > -&i2c0 {
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&i2c1_pins>;
> > > -     status = "okay";
> > > -};
> > > -
> > > -/* CON3 */
> > > -&sata {
> > > -     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";
> > > -};
> > > -
> > > -/* U11 */
> > > -&sdhci1 {
> > > -     non-removable;
> > > -     bus-width = <8>;
> > > -     mmc-ddr-1_8v;
> > > -     mmc-hs400-1_8v;
> > > -     marvell,xenon-emmc;
> > > -     marvell,xenon-tun-count = <9>;
> > > -     marvell,pad-type = "fixed-1-8v";
> > > -
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&mmc_pins>;
> > > -     status = "okay";
> > > -
> > > -     #address-cells = <1>;
> > > -     #size-cells = <0>;
> > > -     mmccard: mmccard@0 {
> > > -             compatible = "mmc-card";
> > > -             reg = <0>;
> > > -     };
> > > -};
> > > -
> > > -&spi0 {
> > > -     status = "okay";
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&spi_quad_pins>;
> > > -
> > > -     spi-flash@0 {
> > > -             #address-cells = <1>;
> > > -             #size-cells = <1>;
> > > -             compatible = "st,m25p128", "jedec,spi-nor";
> > > -             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > > -                             label = "u-boot-env";
> > > -                     };
> > > -             };
> > > -#endif
> > > -     };
> > > -};
> > > -
> > > -/* Exported on the micro USB connector CON32 through an FTDI */
> > > -&uart0 {
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&uart1_pins>;
> > > -     status = "okay";
> > > -};
> > > -
> > > -/* CON29 */
> > > -&usb2 {
> > > -     status = "okay";
> > > -};
> > > -
> > > -/* CON31 */
> > > -&usb3 {
> > > -     status = "okay";
> > > -};
> > > -
> > > -&pcie0 {
> > > -     pinctrl-names = "default";
> > > -     pinctrl-0 = <&pcie_pins>;
> > > -     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > > -     status = "okay";
> > >  };
> > > diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
> > > new file mode 100644
> > > index 0000000000..cba6139be6
> > > --- /dev/null
> > > +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
> > > @@ -0,0 +1,210 @@
> > > +/*
> > > + * Device Tree file for Marvell Armada 3720 community board
> > > + * (ESPRESSOBin)
> > > + * Copyright (C) 2016 Marvell
> > > + *
> > > + * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > > + * Konstantin Porotchkin <kostap@marvell.com>
> > > + *
> > > + * This file is dual-licensed: you can use it either under the terms
> > > + * of the GPL or the X11 license, at your option. Note that this dual
> > > + * licensing only applies to this file, and not this project as a
> > > + * whole.
> > > + *
> > > + *  a) This file is free software; you can redistribute it and/or
> > > + *     modify it under the terms of the GNU General Public License as
> > > + *     published by the Free Software Foundation; either version 2 of the
> > > + *     License, or (at your option) any later version.
> > > + *
> > > + *     This file is distributed in the hope that it will be useful
> > > + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + *     GNU General Public License for more details.
> > > + *
> > > + * Or, alternatively
> > > + *
> > > + *  b) Permission is hereby granted, free of charge, to any person
> > > + *     obtaining a copy of this software and associated documentation
> > > + *     files (the "Software"), to deal in the Software without
> > > + *     restriction, including without limitation the rights to use
> > > + *     copy, modify, merge, publish, distribute, sublicense, and/or
> > > + *     sell copies of the Software, and to permit persons to whom the
> > > + *     Software is furnished to do so, subject to the following
> > > + *     conditions:
> > > + *
> > > + *     The above copyright notice and this permission notice shall be
> > > + *     included in all copies or substantial portions of the Software.
> > > + *
> > > + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > > + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > > + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > > + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > > + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > > + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > > + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > > + *     OTHER DEALINGS IN THE SOFTWARE.
> > > + */
> > > +
> > > +/dts-v1/;
> > > +
> > > +#include "armada-372x.dtsi"
> > > +
> > > +/ {
> > > +     model = "Globalscale Marvell ESPRESSOBin Board";
> > > +     compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > > +
> > > +     chosen {
> > > +             stdout-path = "serial0:115200n8";
> > > +     };
> > > +
> > > +     aliases {
> > > +             ethernet0 = &eth0;
> > > +             i2c0 = &i2c0;
> > > +             spi0 = &spi0;
> > > +     };
> > > +
> > > +     memory {
> > > +             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 {
> > > +     max-lanes = <3>;
> > > +     phy0 {
> > > +             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > > +             phy-speed = <COMPHY_SPEED_5G>;
> > > +     };
> > > +
> > > +     phy1 {
> > > +             phy-type = <COMPHY_TYPE_PEX0>;
> > > +             phy-speed = <COMPHY_SPEED_2_5G>;
> > > +     };
> > > +
> > > +     phy2 {
> > > +             phy-type = <COMPHY_TYPE_SATA0>;
> > > +             phy-speed = <COMPHY_SPEED_5G>;
> > > +     };
> > > +};
> > > +
> > > +&eth0 {
> > > +     status = "okay";
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > > +     phy-mode = "rgmii";
> > > +     phy_addr = <0x1>;
> > > +     fixed-link {
> > > +             speed = <1000>;
> > > +             full-duplex;
> > > +     };
> > > +};
> > > +
> > > +&i2c0 {
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&i2c1_pins>;
> > > +     status = "okay";
> > > +};
> > > +
> > > +/* CON3 */
> > > +&sata {
> > > +     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";
> > > +};
> > > +
> > > +/* U11 */
> > > +&sdhci1 {
> > > +     non-removable;
> > > +     bus-width = <8>;
> > > +     mmc-ddr-1_8v;
> > > +     mmc-hs400-1_8v;
> > > +     marvell,xenon-emmc;
> > > +     marvell,xenon-tun-count = <9>;
> > > +     marvell,pad-type = "fixed-1-8v";
> > > +
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&mmc_pins>;
> > > +     status = "okay";
> > > +
> > > +     #address-cells = <1>;
> > > +     #size-cells = <0>;
> > > +     mmccard: mmccard@0 {
> > > +             compatible = "mmc-card";
> > > +             reg = <0>;
> > > +     };
> > > +};
> > > +
> > > +&spi0 {
> > > +     status = "okay";
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&spi_quad_pins>;
> > > +
> > > +     spi-flash@0 {
> > > +             #address-cells = <1>;
> > > +             #size-cells = <1>;
> > > +             compatible = "st,m25p128", "jedec,spi-nor";
> > > +             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > > +                             label = "u-boot-env";
> > > +                     };
> > > +             };
> > > +#endif
> > > +     };
> > > +};
> > > +
> > > +/* Exported on the micro USB connector CON32 through an FTDI */
> > > +&uart0 {
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&uart1_pins>;
> > > +     status = "okay";
> > > +};
> > > +
> > > +/* CON29 */
> > > +&usb2 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +/* CON31 */
> > > +&usb3 {
> > > +     status = "okay";
> > > +};
> > > +
> > > +&pcie0 {
> > > +     pinctrl-names = "default";
> > > +     pinctrl-0 = <&pcie_pins>;
> > > +     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > > +     status = "okay";
> > > +};
> > > diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > > index f2c0a582d7..d69af832fc 100644
> > > --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > > +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > > @@ -10,6 +10,14 @@ M: Konstantin Porotchkin <kostap@marvell.com>
> > >  S:   Maintained
> > >  F:   configs/mvebu_espressobin-88f3720_defconfig
> > >
> > > +ESPRESSOBin-Ultra BOARD
> > > +M:   Luka Kovacic <luka.kovacic@sartura.hr>
> > > +M:   Robert Marko <robert.marko@sartura.hr>
> > > +M:   Luka Perkov <luka.perkov@sartura.hr>
> > > +S:   Maintained
> > > +F:   arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > +F:   configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > +
> > >  uDPU BOARD
> > >  M:   Vladimir Vid <vladimir.vid@sartura.hr>
> > >  S:   Maintained
> > > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > > index 2de9c2ac17..21c1eb7b22 100644
> > > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > > @@ -11,6 +11,7 @@
> > >  #include <i2c.h>
> > >  #include <init.h>
> > >  #include <mmc.h>
> > > +#include <miiphy.h>
> > >  #include <phy.h>
> > >  #include <asm/global_data.h>
> > >  #include <asm/io.h>
> > > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > >
> > > +/* Marvell 88E1512 */
> > > +#define MII_MARVELL_PHY_PAGE         22
> > > +
> > > +#define MV88E1512_GENERAL_CTRL               20
> > > +#define MV88E1512_MODE_SGMII         1
> > > +#define MV88E1512_RESET_OFFS         15
> > > +
> > > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > > +
> > >  /*
> > >   * Memory Controller Registers
> > >   *
> > > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > >       return 0;
> > >  }
> > >
> > > -/* Bring-up board-specific network stuff */
> > > -int board_network_enable(struct mii_dev *bus)
> > > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > >  {
> > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > -             return 0;
> > > +     const char *name;
> > > +     u16 reg;
> > > +
> > > +     name = miiphy_get_current_dev();
> > > +     if (name) {
> > > +             /* SGMII-to-Copper mode initialization */
> > > +
> > > +             /* Select page 18 */
> > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > +             reg &= ~0x7;
> > > +             reg |= MV88E1512_MODE_SGMII;
> > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > +             /* PHY reset is necessary after changing MODE[2:0] */
> > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > +             /* Reset page selection */
> > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > > +             udelay(100);
> > > +     }
> > > +}
> > > +
> > > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > > +{
> > > +     int i;
> > > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > >
> > > +     /*
> > > +      * FIXME: remove this code once Topaz driver gets available
> > > +      * A3720 ESPRESSObin Ultra Board Only
> > > +      * Configure Topaz switch (88E6341)
> > > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > > +      */
> > > +     for (i = 0; i <= 5; i++) {
> > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > > +                                       MVEBU_SW_PORT_CTRL_REG,
> > > +                                       i == 5 ? 0x7c : 0x7f);
> > > +     }
> > > +
> > > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > > +
> > > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > > +     for (i = 1; i <= 5; i++) {
> > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > > +     }
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +int board_network_enable_espressobin(struct mii_dev *bus)
> > > +{
> > >       /*
> > >        * FIXME: remove this code once Topaz driver gets available
> > >        * A3720 Community Board Only
> > > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > >       return 0;
> > >  }
> > >
> > > +/* Bring-up the board-specific networking */
> > > +int board_network_enable(struct mii_dev *bus)
> > > +{
> > > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > > +             return board_network_enable_espressobin(bus);
> > > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > +             return board_network_enable_espressobin_ultra(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)
> > >  {
> > > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > >       int parts_off;
> > >       int part_off;
> > >
> > > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > +     /*
> > > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > > +      * ESPRESSOBin Ultra boards.
> > > +      */
> > > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > >               return 0;
> > >
> > >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> > > diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > new file mode 100644
> > > index 0000000000..1bac0a96ad
> > > --- /dev/null
> > > +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > @@ -0,0 +1,93 @@
> > > +CONFIG_ARM=y
> > > +CONFIG_ARCH_CPU_INIT=y
> > > +CONFIG_ARCH_MVEBU=y
> > > +CONFIG_SYS_TEXT_BASE=0x00000000
> > > +CONFIG_SYS_MALLOC_F_LEN=0x2000
> > > +CONFIG_NR_DRAM_BANKS=1
> > > +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
> > > +CONFIG_ENV_SIZE=0x10000
> > > +CONFIG_ENV_OFFSET=0x3F0000
> > > +CONFIG_ENV_SECT_SIZE=0x10000
> > > +CONFIG_DM_GPIO=y
> > > +CONFIG_DEBUG_UART_BASE=0xd0012000
> > > +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
> > > +CONFIG_DEBUG_UART=y
> > > +CONFIG_AHCI=y
> > > +CONFIG_DISTRO_DEFAULTS=y
> > > +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> > > +CONFIG_OF_BOARD_SETUP=y
> > > +CONFIG_FIT=y
> > > +CONFIG_FIT_VERBOSE=y
> > > +CONFIG_FIT_BEST_MATCH=y
> > > +CONFIG_AUTOBOOT_KEYED=y
> > > +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
> > > +CONFIG_AUTOBOOT_STOP_STR="s"
> > > +CONFIG_AUTOBOOT_KEYED_CTRLC=y
> > > +CONFIG_HUSH_PARSER=y
> > > +CONFIG_SYS_CONSOLE_INFO_QUIET=y
> > > +# CONFIG_DISPLAY_CPUINFO is not set
> > > +# CONFIG_DISPLAY_BOARDINFO is not set
> > > +CONFIG_DISPLAY_BOARDINFO_LATE=y
> > > +CONFIG_ARCH_EARLY_INIT_R=y
> > > +CONFIG_BOARD_EARLY_INIT_F=y
> > > +CONFIG_BOARD_LATE_INIT=y
> > > +# CONFIG_CMD_FLASH is not set
> > > +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
> > > +CONFIG_CMD_WDT=y
> > > +# CONFIG_CMD_SETEXPR is not set
> > > +CONFIG_CMD_TFTPPUT=y
> > > +CONFIG_CMD_CACHE=y
> > > +CONFIG_CMD_TIME=y
> > > +CONFIG_CMD_MVEBU_BUBT=y
> > > +CONFIG_MVEBU_MAC_HW_INFO=y
> > > +CONFIG_CMD_EXT4_WRITE=y
> > > +CONFIG_MAC_PARTITION=y
> > > +CONFIG_ENV_OVERWRITE=y
> > > +CONFIG_ENV_IS_IN_SPI_FLASH=y
> > > +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> > > +CONFIG_NET_RANDOM_ETHADDR=y
> > > +CONFIG_AHCI_MVEBU=y
> > > +CONFIG_CLK=y
> > > +CONFIG_CLK_MVEBU=y
> > > +CONFIG_DM_I2C=y
> > > +CONFIG_MISC=y
> > > +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_SPI_FLASH_MACRONIX=y
> > > +CONFIG_SPI_FLASH_MTD=y
> > > +CONFIG_PHY_MARVELL=y
> > > +CONFIG_PHY_GIGE=y
> > > +CONFIG_MVNETA=y
> > > +CONFIG_PCI=y
> > > +CONFIG_PCI_AARDVARK=y
> > > +CONFIG_PHY=y
> > > +CONFIG_MVEBU_COMPHY_SUPPORT=y
> > > +CONFIG_PINCTRL=y
> > > +CONFIG_PINCTRL_ARMADA_37XX=y
> > > +CONFIG_DM_REGULATOR_GPIO=y
> > > +CONFIG_DEBUG_UART_SHIFT=2
> > > +CONFIG_DEBUG_UART_ANNOUNCE=y
> > > +CONFIG_MVEBU_A3700_UART=y
> > > +CONFIG_MVEBU_A3700_SPI=y
> > > +CONFIG_USB=y
> > > +CONFIG_USB_XHCI_HCD=y
> > > +CONFIG_USB_EHCI_HCD=y
> > > +CONFIG_USB_HOST_ETHER=y
> > > +# CONFIG_WATCHDOG_AUTOSTART is not set
> > > +CONFIG_WDT=y
> > > +CONFIG_WDT_ARMADA_37XX=y
> > > +CONFIG_SHA1=y
> > > +CONFIG_DM_RTC=y
> > > +CONFIG_RTC_PCF8563=y
> > > +CONFIG_LED=y
> > > +CONFIG_LED_GPIO=y
> > > --
> > > 2.31.1
> > >
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13  9:54       ` Pali Rohár
@ 2021-08-13  9:58         ` Stefan Roese
  2021-08-13 10:25           ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Stefan Roese @ 2021-08-13  9:58 UTC (permalink / raw)
  To: Pali Rohár, Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sjg,
	patrick.delaunay, xypron.glpk

Hi,

On 13.08.21 11:54, Pali Rohár wrote:
> On Friday 13 August 2021 11:08:08 Luka Kovacic wrote:
>> Hello Pali,
>>
>> On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
>>>
>>> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
>>>> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
>>>> Technologies, Inc.
>>>>
>>>> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
>>>> Peripherals:
>>>>   - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
>>>>   - RTC clock (PCF8563)
>>>>   - USB 3.0 port
>>>>   - USB 2.0 port
>>>>   - 4x LED
>>>>   - UART over Micro-USB
>>>>   - M.2 slot (2280)
>>>>   - Mini PCI-E slot
>>>>
>>>> Additionally, automatic import of the Marvell hw_info parameters is
>>>> enabled via the recently added mac command for A37XX platforms.
>>>> The parameters stored in Marvell hw_info are usually the board serial
>>>> number and MAC addresses.
>>>>
>>>> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
>>>> Cc: Luka Perkov <luka.perkov@sartura.hr>
>>>> Cc: Robert Marko <robert.marko@sartura.hr>
>>>> ---
>>>>   arch/arm/dts/Makefile                         |   1 +
>>>>   .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
>>>>   arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
>>>>   arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
>>>>   board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
>>>>   board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
>>>>   .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
>>>>   7 files changed, 514 insertions(+), 203 deletions(-)
>>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
>>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
>>>>   create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
>>>
>>> Hello Luka! Please look at my comments from previous review:
>>> https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
>>>
>>> I think it is not a good idea to duplicate espressobin code, specially
>>> now when differences between v5, v7, non-emmc and emmc were
>>> de-duplicated and correctly detected at runtime. Just use one DTS and
>>> one config file and differences can be handled in board code functions
>>> "board_fix_fdt" and "board_late_init".
>>
>> I believe that patching the DTS at runtime diminishes the value of
>> device trees in the first case.
>>
>> As far as the v5, v7, non-emmc and emmc boards go I do understand
>> that, as they are physically similar and more or less different revisions
>> of the same board.
>>
>> The ESPRESSOBin Ultra board is completely different from those boards
>> physically and so I doesn't make sense to me, why we would merge all
>> of them into one device tree.
> 
> See email for reasons:
> https://lore.kernel.org/u-boot/20210301154101.ke5j2r3lazjlxrsl@pali/
> 
> Anyway, I'm looking at differences between ultra and non-ultra boards
> which are used by U-Boot... And I see only:
> * switch configuration & phy
> * i2c rtc
> * sdhci slot
> 
> Other changes are not used by U-Boot (led).
> 
> For switch configuration & phy there is already custom code in U-Boot
> board file. For sdhci slot there is also (to enable/disable eMMC after
> detection).
> 
> So the only difference is presence of i2c rtc, right?
> 
> I guess it does not make much sense to copy and duplicate whole DTS and
> also defconfig file for such small differences. Insertion of just few
> nodes is not a big problem.
> 
> These boars are not very different, and having tons of u-boot binaries
> for every combination just complicate it as explained in above email.

I fully agree with Pali. It's much more conveniant to just have one
U-Boot target (and binary) which can handle multiple board variants
by runtime detection. I would very much welcome to see the support for
the "Ultra" variant added this way.

> If you need help with this I can try to do something... as I was already
> involved in unification of all v5/v7/emmc/non-emmc variants into one
> binary with one DTS.

Thanks Pali for all your work here.

Thanks,
Stefan

>> I resorted to the Linux way and used a common dtsi for both the
>> ESPRESSOBin - which is the base and the ESPRESSOBin-Ultra.
>>
>>>
>>>> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
>>>> index c42715ead4..f21c9c94d3 100644
>>>> --- a/arch/arm/dts/Makefile
>>>> +++ b/arch/arm/dts/Makefile
>>>> @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
>>>>   dtb-$(CONFIG_ARCH_MVEBU) +=                  \
>>>>        armada-3720-db.dtb                      \
>>>>        armada-3720-espressobin.dtb             \
>>>> +     armada-3720-espressobin-ultra.dtb       \
>>>>        armada-3720-turris-mox.dtb              \
>>>>        armada-3720-uDPU.dtb                    \
>>>>        armada-375-db.dtb                       \
>>>> diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
>>>> new file mode 100644
>>>> index 0000000000..5ad0c723e3
>>>> --- /dev/null
>>>> +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
>>>> @@ -0,0 +1,114 @@
>>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>>>> +/*
>>>> + * Device Tree file for ESPRESSObin-Ultra board
>>>> + * Copyright (C) 2016 Marvell
>>>> + * Copyright (C) 2019 Globalscale technologies, Inc.
>>>> + * Copyright (C) 2021 Sartura Ltd.
>>>> + *
>>>> + * Author: Jason Hung <jhung@globalscaletechnologies.com>
>>>> + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
>>>> + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
>>>> + */
>>>> +
>>>> +/dts-v1/;
>>>> +
>>>> +#include "armada-3720-espressobin.dtsi"
>>>> +
>>>> +/ {
>>>> +     model = "Globalscale Marvell ESPRESSOBin Ultra Board";
>>>> +     compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
>>>> +
>>>> +     gpio-leds {
>>>> +             pinctrl-names = "default";
>>>> +             pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
>>>> +             compatible = "gpio-leds";
>>>> +
>>>> +             led1 {
>>>> +                     label = "led1";
>>>> +                     gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
>>>> +                     default-state = "on";
>>>> +             };
>>>> +             led2 {
>>>> +                     label = "led2";
>>>> +                     gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
>>>> +                     default-state = "on";
>>>> +             };
>>>> +             led3 {
>>>> +                     label = "led3";
>>>> +                     gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
>>>> +                     default-state = "on";
>>>> +             };
>>>> +             led4 {
>>>> +                     label = "led4";
>>>> +                     gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
>>>> +                     default-state = "on";
>>>> +             };
>>>> +     };
>>>> +};
>>>> +
>>>> +&pinctrl_nb {
>>>> +     led1_pins: led1-pins {
>>>> +             groups = "pwm0";
>>>> +             function = "gpio";
>>>> +     };
>>>> +     led2_pins: led2-pins {
>>>> +             groups = "pwm1";
>>>> +             function = "gpio";
>>>> +     };
>>>> +     led3_pins: led3-pins {
>>>> +             groups = "pwm2";
>>>> +             function = "gpio";
>>>> +     };
>>>> +     led4_pins: led4-pins {
>>>> +             groups = "pwm3";
>>>> +             function = "gpio";
>>>> +     };
>>>> +};
>>>> +
>>>> +&eth0 {
>>>> +     status = "okay";
>>>> +     phy_addr = <0x3>;
>>>> +};
>>>> +
>>>> +&i2c0 {
>>>> +     status = "okay";
>>>> +     #address-cells = <1>;
>>>> +     #size-cells = <0>;
>>>> +     rtc@51 {
>>>> +             compatible = "nxp,pcf8563";
>>>> +             reg = <0x51>;
>>>> +     };
>>>> +};
>>>> +
>>>> +&sata {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&sdhci0 {
>>>> +     status = "disabled";
>>>> +};
>>>> +
>>>> +&sdhci1 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&spi0 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +/* Exported on the micro USB connector through an FTDI */
>>>> +&uart0 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&usb2 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&usb3 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&pcie0 {
>>>> +     status = "okay";
>>>> +};
>>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
>>>> index cba6139be6..925ce6a38e 100644
>>>> --- a/arch/arm/dts/armada-3720-espressobin.dts
>>>> +++ b/arch/arm/dts/armada-3720-espressobin.dts
>>>> @@ -1,210 +1,15 @@
>>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>>>>   /*
>>>>    * Device Tree file for Marvell Armada 3720 community board
>>>>    * (ESPRESSOBin)
>>>>    * Copyright (C) 2016 Marvell
>>>> - *
>>>> - * Gregory CLEMENT <gregory.clement@free-electrons.com>
>>>> - * Konstantin Porotchkin <kostap@marvell.com>
>>>> - *
>>>> - * This file is dual-licensed: you can use it either under the terms
>>>> - * of the GPL or the X11 license, at your option. Note that this dual
>>>> - * licensing only applies to this file, and not this project as a
>>>> - * whole.
>>>> - *
>>>> - *  a) This file is free software; you can redistribute it and/or
>>>> - *     modify it under the terms of the GNU General Public License as
>>>> - *     published by the Free Software Foundation; either version 2 of the
>>>> - *     License, or (at your option) any later version.
>>>> - *
>>>> - *     This file is distributed in the hope that it will be useful
>>>> - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
>>>> - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>>> - *     GNU General Public License for more details.
>>>> - *
>>>> - * Or, alternatively
>>>> - *
>>>> - *  b) Permission is hereby granted, free of charge, to any person
>>>> - *     obtaining a copy of this software and associated documentation
>>>> - *     files (the "Software"), to deal in the Software without
>>>> - *     restriction, including without limitation the rights to use
>>>> - *     copy, modify, merge, publish, distribute, sublicense, and/or
>>>> - *     sell copies of the Software, and to permit persons to whom the
>>>> - *     Software is furnished to do so, subject to the following
>>>> - *     conditions:
>>>> - *
>>>> - *     The above copyright notice and this permission notice shall be
>>>> - *     included in all copies or substantial portions of the Software.
>>>> - *
>>>> - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
>>>> - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
>>>> - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>>>> - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
>>>> - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
>>>> - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>>>> - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
>>>> - *     OTHER DEALINGS IN THE SOFTWARE.
>>>>    */
>>>>
>>>>   /dts-v1/;
>>>>
>>>> -#include "armada-372x.dtsi"
>>>> +#include "armada-3720-espressobin.dtsi"
>>>>
>>>>   / {
>>>>        model = "Globalscale Marvell ESPRESSOBin Board";
>>>>        compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
>>>> -
>>>> -     chosen {
>>>> -             stdout-path = "serial0:115200n8";
>>>> -     };
>>>> -
>>>> -     aliases {
>>>> -             ethernet0 = &eth0;
>>>> -             i2c0 = &i2c0;
>>>> -             spi0 = &spi0;
>>>> -     };
>>>> -
>>>> -     memory {
>>>> -             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 {
>>>> -     max-lanes = <3>;
>>>> -     phy0 {
>>>> -             phy-type = <COMPHY_TYPE_USB3_HOST0>;
>>>> -             phy-speed = <COMPHY_SPEED_5G>;
>>>> -     };
>>>> -
>>>> -     phy1 {
>>>> -             phy-type = <COMPHY_TYPE_PEX0>;
>>>> -             phy-speed = <COMPHY_SPEED_2_5G>;
>>>> -     };
>>>> -
>>>> -     phy2 {
>>>> -             phy-type = <COMPHY_TYPE_SATA0>;
>>>> -             phy-speed = <COMPHY_SPEED_5G>;
>>>> -     };
>>>> -};
>>>> -
>>>> -&eth0 {
>>>> -     status = "okay";
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
>>>> -     phy-mode = "rgmii";
>>>> -     phy_addr = <0x1>;
>>>> -     fixed-link {
>>>> -             speed = <1000>;
>>>> -             full-duplex;
>>>> -     };
>>>> -};
>>>> -
>>>> -&i2c0 {
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&i2c1_pins>;
>>>> -     status = "okay";
>>>> -};
>>>> -
>>>> -/* CON3 */
>>>> -&sata {
>>>> -     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";
>>>> -};
>>>> -
>>>> -/* U11 */
>>>> -&sdhci1 {
>>>> -     non-removable;
>>>> -     bus-width = <8>;
>>>> -     mmc-ddr-1_8v;
>>>> -     mmc-hs400-1_8v;
>>>> -     marvell,xenon-emmc;
>>>> -     marvell,xenon-tun-count = <9>;
>>>> -     marvell,pad-type = "fixed-1-8v";
>>>> -
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&mmc_pins>;
>>>> -     status = "okay";
>>>> -
>>>> -     #address-cells = <1>;
>>>> -     #size-cells = <0>;
>>>> -     mmccard: mmccard@0 {
>>>> -             compatible = "mmc-card";
>>>> -             reg = <0>;
>>>> -     };
>>>> -};
>>>> -
>>>> -&spi0 {
>>>> -     status = "okay";
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&spi_quad_pins>;
>>>> -
>>>> -     spi-flash@0 {
>>>> -             #address-cells = <1>;
>>>> -             #size-cells = <1>;
>>>> -             compatible = "st,m25p128", "jedec,spi-nor";
>>>> -             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
>>>> -                             label = "u-boot-env";
>>>> -                     };
>>>> -             };
>>>> -#endif
>>>> -     };
>>>> -};
>>>> -
>>>> -/* Exported on the micro USB connector CON32 through an FTDI */
>>>> -&uart0 {
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&uart1_pins>;
>>>> -     status = "okay";
>>>> -};
>>>> -
>>>> -/* CON29 */
>>>> -&usb2 {
>>>> -     status = "okay";
>>>> -};
>>>> -
>>>> -/* CON31 */
>>>> -&usb3 {
>>>> -     status = "okay";
>>>> -};
>>>> -
>>>> -&pcie0 {
>>>> -     pinctrl-names = "default";
>>>> -     pinctrl-0 = <&pcie_pins>;
>>>> -     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
>>>> -     status = "okay";
>>>>   };
>>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
>>>> new file mode 100644
>>>> index 0000000000..cba6139be6
>>>> --- /dev/null
>>>> +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
>>>> @@ -0,0 +1,210 @@
>>>> +/*
>>>> + * Device Tree file for Marvell Armada 3720 community board
>>>> + * (ESPRESSOBin)
>>>> + * Copyright (C) 2016 Marvell
>>>> + *
>>>> + * Gregory CLEMENT <gregory.clement@free-electrons.com>
>>>> + * Konstantin Porotchkin <kostap@marvell.com>
>>>> + *
>>>> + * This file is dual-licensed: you can use it either under the terms
>>>> + * of the GPL or the X11 license, at your option. Note that this dual
>>>> + * licensing only applies to this file, and not this project as a
>>>> + * whole.
>>>> + *
>>>> + *  a) This file is free software; you can redistribute it and/or
>>>> + *     modify it under the terms of the GNU General Public License as
>>>> + *     published by the Free Software Foundation; either version 2 of the
>>>> + *     License, or (at your option) any later version.
>>>> + *
>>>> + *     This file is distributed in the hope that it will be useful
>>>> + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
>>>> + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>>> + *     GNU General Public License for more details.
>>>> + *
>>>> + * Or, alternatively
>>>> + *
>>>> + *  b) Permission is hereby granted, free of charge, to any person
>>>> + *     obtaining a copy of this software and associated documentation
>>>> + *     files (the "Software"), to deal in the Software without
>>>> + *     restriction, including without limitation the rights to use
>>>> + *     copy, modify, merge, publish, distribute, sublicense, and/or
>>>> + *     sell copies of the Software, and to permit persons to whom the
>>>> + *     Software is furnished to do so, subject to the following
>>>> + *     conditions:
>>>> + *
>>>> + *     The above copyright notice and this permission notice shall be
>>>> + *     included in all copies or substantial portions of the Software.
>>>> + *
>>>> + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
>>>> + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
>>>> + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>>>> + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
>>>> + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
>>>> + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>>>> + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
>>>> + *     OTHER DEALINGS IN THE SOFTWARE.
>>>> + */
>>>> +
>>>> +/dts-v1/;
>>>> +
>>>> +#include "armada-372x.dtsi"
>>>> +
>>>> +/ {
>>>> +     model = "Globalscale Marvell ESPRESSOBin Board";
>>>> +     compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
>>>> +
>>>> +     chosen {
>>>> +             stdout-path = "serial0:115200n8";
>>>> +     };
>>>> +
>>>> +     aliases {
>>>> +             ethernet0 = &eth0;
>>>> +             i2c0 = &i2c0;
>>>> +             spi0 = &spi0;
>>>> +     };
>>>> +
>>>> +     memory {
>>>> +             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 {
>>>> +     max-lanes = <3>;
>>>> +     phy0 {
>>>> +             phy-type = <COMPHY_TYPE_USB3_HOST0>;
>>>> +             phy-speed = <COMPHY_SPEED_5G>;
>>>> +     };
>>>> +
>>>> +     phy1 {
>>>> +             phy-type = <COMPHY_TYPE_PEX0>;
>>>> +             phy-speed = <COMPHY_SPEED_2_5G>;
>>>> +     };
>>>> +
>>>> +     phy2 {
>>>> +             phy-type = <COMPHY_TYPE_SATA0>;
>>>> +             phy-speed = <COMPHY_SPEED_5G>;
>>>> +     };
>>>> +};
>>>> +
>>>> +&eth0 {
>>>> +     status = "okay";
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
>>>> +     phy-mode = "rgmii";
>>>> +     phy_addr = <0x1>;
>>>> +     fixed-link {
>>>> +             speed = <1000>;
>>>> +             full-duplex;
>>>> +     };
>>>> +};
>>>> +
>>>> +&i2c0 {
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&i2c1_pins>;
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +/* CON3 */
>>>> +&sata {
>>>> +     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";
>>>> +};
>>>> +
>>>> +/* U11 */
>>>> +&sdhci1 {
>>>> +     non-removable;
>>>> +     bus-width = <8>;
>>>> +     mmc-ddr-1_8v;
>>>> +     mmc-hs400-1_8v;
>>>> +     marvell,xenon-emmc;
>>>> +     marvell,xenon-tun-count = <9>;
>>>> +     marvell,pad-type = "fixed-1-8v";
>>>> +
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&mmc_pins>;
>>>> +     status = "okay";
>>>> +
>>>> +     #address-cells = <1>;
>>>> +     #size-cells = <0>;
>>>> +     mmccard: mmccard@0 {
>>>> +             compatible = "mmc-card";
>>>> +             reg = <0>;
>>>> +     };
>>>> +};
>>>> +
>>>> +&spi0 {
>>>> +     status = "okay";
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&spi_quad_pins>;
>>>> +
>>>> +     spi-flash@0 {
>>>> +             #address-cells = <1>;
>>>> +             #size-cells = <1>;
>>>> +             compatible = "st,m25p128", "jedec,spi-nor";
>>>> +             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
>>>> +                             label = "u-boot-env";
>>>> +                     };
>>>> +             };
>>>> +#endif
>>>> +     };
>>>> +};
>>>> +
>>>> +/* Exported on the micro USB connector CON32 through an FTDI */
>>>> +&uart0 {
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&uart1_pins>;
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +/* CON29 */
>>>> +&usb2 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +/* CON31 */
>>>> +&usb3 {
>>>> +     status = "okay";
>>>> +};
>>>> +
>>>> +&pcie0 {
>>>> +     pinctrl-names = "default";
>>>> +     pinctrl-0 = <&pcie_pins>;
>>>> +     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
>>>> +     status = "okay";
>>>> +};
>>>> diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
>>>> index f2c0a582d7..d69af832fc 100644
>>>> --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
>>>> +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
>>>> @@ -10,6 +10,14 @@ M: Konstantin Porotchkin <kostap@marvell.com>
>>>>   S:   Maintained
>>>>   F:   configs/mvebu_espressobin-88f3720_defconfig
>>>>
>>>> +ESPRESSOBin-Ultra BOARD
>>>> +M:   Luka Kovacic <luka.kovacic@sartura.hr>
>>>> +M:   Robert Marko <robert.marko@sartura.hr>
>>>> +M:   Luka Perkov <luka.perkov@sartura.hr>
>>>> +S:   Maintained
>>>> +F:   arch/arm/dts/armada-3720-espressobin-ultra.dts
>>>> +F:   configs/mvebu_espressobin-ultra-88f3720_defconfig
>>>> +
>>>>   uDPU BOARD
>>>>   M:   Vladimir Vid <vladimir.vid@sartura.hr>
>>>>   S:   Maintained
>>>> diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
>>>> index 2de9c2ac17..21c1eb7b22 100644
>>>> --- a/board/Marvell/mvebu_armada-37xx/board.c
>>>> +++ b/board/Marvell/mvebu_armada-37xx/board.c
>>>> @@ -11,6 +11,7 @@
>>>>   #include <i2c.h>
>>>>   #include <init.h>
>>>>   #include <mmc.h>
>>>> +#include <miiphy.h>
>>>>   #include <phy.h>
>>>>   #include <asm/global_data.h>
>>>>   #include <asm/io.h>
>>>> @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
>>>>   #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
>>>>   #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
>>>>
>>>> +/* Marvell 88E1512 */
>>>> +#define MII_MARVELL_PHY_PAGE         22
>>>> +
>>>> +#define MV88E1512_GENERAL_CTRL               20
>>>> +#define MV88E1512_MODE_SGMII         1
>>>> +#define MV88E1512_RESET_OFFS         15
>>>> +
>>>> +#define ULTRA_MV88E1512_PHYADDR              0x1
>>>> +
>>>>   /*
>>>>    * Memory Controller Registers
>>>>    *
>>>> @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
>>>>        return 0;
>>>>   }
>>>>
>>>> -/* Bring-up board-specific network stuff */
>>>> -int board_network_enable(struct mii_dev *bus)
>>>> +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
>>>>   {
>>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
>>>> -             return 0;
>>>> +     const char *name;
>>>> +     u16 reg;
>>>> +
>>>> +     name = miiphy_get_current_dev();
>>>> +     if (name) {
>>>> +             /* SGMII-to-Copper mode initialization */
>>>> +
>>>> +             /* Select page 18 */
>>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
>>>> +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
>>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
>>>> +             reg &= ~0x7;
>>>> +             reg |= MV88E1512_MODE_SGMII;
>>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
>>>> +             /* PHY reset is necessary after changing MODE[2:0] */
>>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
>>>> +             reg |= 1 << MV88E1512_RESET_OFFS;
>>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
>>>> +             /* Reset page selection */
>>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
>>>> +             udelay(100);
>>>> +     }
>>>> +}
>>>> +
>>>> +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
>>>> +{
>>>> +     int i;
>>>> +     /* Setup 88E1512 SGMII-to-Copper mode */
>>>> +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
>>>>
>>>> +     /*
>>>> +      * FIXME: remove this code once Topaz driver gets available
>>>> +      * A3720 ESPRESSObin Ultra Board Only
>>>> +      * Configure Topaz switch (88E6341)
>>>> +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
>>>> +      */
>>>> +     for (i = 0; i <= 5; i++) {
>>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
>>>> +                                       MVEBU_SW_PORT_CTRL_REG,
>>>> +                                       i == 5 ? 0x7c : 0x7f);
>>>> +     }
>>>> +
>>>> +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
>>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
>>>> +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
>>>> +
>>>> +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
>>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
>>>> +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
>>>> +     for (i = 1; i <= 5; i++) {
>>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
>>>> +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
>>>> +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
>>>> +     }
>>>> +
>>>> +     return 0;
>>>> +}
>>>> +
>>>> +int board_network_enable_espressobin(struct mii_dev *bus)
>>>> +{
>>>>        /*
>>>>         * FIXME: remove this code once Topaz driver gets available
>>>>         * A3720 Community Board Only
>>>> @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
>>>>        return 0;
>>>>   }
>>>>
>>>> +/* Bring-up the board-specific networking */
>>>> +int board_network_enable(struct mii_dev *bus)
>>>> +{
>>>> +     if (of_machine_is_compatible("globalscale,espressobin"))
>>>> +             return board_network_enable_espressobin(bus);
>>>> +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
>>>> +             return board_network_enable_espressobin_ultra(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)
>>>>   {
>>>> @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
>>>>        int parts_off;
>>>>        int part_off;
>>>>
>>>> -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
>>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
>>>> +     /*
>>>> +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
>>>> +      * ESPRESSOBin Ultra boards.
>>>> +      */
>>>> +     if (!of_machine_is_compatible("globalscale,espressobin") &&
>>>> +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
>>>>                return 0;
>>>>
>>>>        spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
>>>> diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
>>>> new file mode 100644
>>>> index 0000000000..1bac0a96ad
>>>> --- /dev/null
>>>> +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
>>>> @@ -0,0 +1,93 @@
>>>> +CONFIG_ARM=y
>>>> +CONFIG_ARCH_CPU_INIT=y
>>>> +CONFIG_ARCH_MVEBU=y
>>>> +CONFIG_SYS_TEXT_BASE=0x00000000
>>>> +CONFIG_SYS_MALLOC_F_LEN=0x2000
>>>> +CONFIG_NR_DRAM_BANKS=1
>>>> +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
>>>> +CONFIG_ENV_SIZE=0x10000
>>>> +CONFIG_ENV_OFFSET=0x3F0000
>>>> +CONFIG_ENV_SECT_SIZE=0x10000
>>>> +CONFIG_DM_GPIO=y
>>>> +CONFIG_DEBUG_UART_BASE=0xd0012000
>>>> +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
>>>> +CONFIG_DEBUG_UART=y
>>>> +CONFIG_AHCI=y
>>>> +CONFIG_DISTRO_DEFAULTS=y
>>>> +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
>>>> +CONFIG_OF_BOARD_SETUP=y
>>>> +CONFIG_FIT=y
>>>> +CONFIG_FIT_VERBOSE=y
>>>> +CONFIG_FIT_BEST_MATCH=y
>>>> +CONFIG_AUTOBOOT_KEYED=y
>>>> +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
>>>> +CONFIG_AUTOBOOT_STOP_STR="s"
>>>> +CONFIG_AUTOBOOT_KEYED_CTRLC=y
>>>> +CONFIG_HUSH_PARSER=y
>>>> +CONFIG_SYS_CONSOLE_INFO_QUIET=y
>>>> +# CONFIG_DISPLAY_CPUINFO is not set
>>>> +# CONFIG_DISPLAY_BOARDINFO is not set
>>>> +CONFIG_DISPLAY_BOARDINFO_LATE=y
>>>> +CONFIG_ARCH_EARLY_INIT_R=y
>>>> +CONFIG_BOARD_EARLY_INIT_F=y
>>>> +CONFIG_BOARD_LATE_INIT=y
>>>> +# CONFIG_CMD_FLASH is not set
>>>> +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
>>>> +CONFIG_CMD_WDT=y
>>>> +# CONFIG_CMD_SETEXPR is not set
>>>> +CONFIG_CMD_TFTPPUT=y
>>>> +CONFIG_CMD_CACHE=y
>>>> +CONFIG_CMD_TIME=y
>>>> +CONFIG_CMD_MVEBU_BUBT=y
>>>> +CONFIG_MVEBU_MAC_HW_INFO=y
>>>> +CONFIG_CMD_EXT4_WRITE=y
>>>> +CONFIG_MAC_PARTITION=y
>>>> +CONFIG_ENV_OVERWRITE=y
>>>> +CONFIG_ENV_IS_IN_SPI_FLASH=y
>>>> +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
>>>> +CONFIG_NET_RANDOM_ETHADDR=y
>>>> +CONFIG_AHCI_MVEBU=y
>>>> +CONFIG_CLK=y
>>>> +CONFIG_CLK_MVEBU=y
>>>> +CONFIG_DM_I2C=y
>>>> +CONFIG_MISC=y
>>>> +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_SPI_FLASH_MACRONIX=y
>>>> +CONFIG_SPI_FLASH_MTD=y
>>>> +CONFIG_PHY_MARVELL=y
>>>> +CONFIG_PHY_GIGE=y
>>>> +CONFIG_MVNETA=y
>>>> +CONFIG_PCI=y
>>>> +CONFIG_PCI_AARDVARK=y
>>>> +CONFIG_PHY=y
>>>> +CONFIG_MVEBU_COMPHY_SUPPORT=y
>>>> +CONFIG_PINCTRL=y
>>>> +CONFIG_PINCTRL_ARMADA_37XX=y
>>>> +CONFIG_DM_REGULATOR_GPIO=y
>>>> +CONFIG_DEBUG_UART_SHIFT=2
>>>> +CONFIG_DEBUG_UART_ANNOUNCE=y
>>>> +CONFIG_MVEBU_A3700_UART=y
>>>> +CONFIG_MVEBU_A3700_SPI=y
>>>> +CONFIG_USB=y
>>>> +CONFIG_USB_XHCI_HCD=y
>>>> +CONFIG_USB_EHCI_HCD=y
>>>> +CONFIG_USB_HOST_ETHER=y
>>>> +# CONFIG_WATCHDOG_AUTOSTART is not set
>>>> +CONFIG_WDT=y
>>>> +CONFIG_WDT_ARMADA_37XX=y
>>>> +CONFIG_SHA1=y
>>>> +CONFIG_DM_RTC=y
>>>> +CONFIG_RTC_PCF8563=y
>>>> +CONFIG_LED=y
>>>> +CONFIG_LED_GPIO=y
>>>> --
>>>> 2.31.1
>>>>
>>
>> Kind regards,
>> Luka


Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13  9:27   ` Pali Rohár
@ 2021-08-13 10:03     ` Luka Kovacic
  2021-08-13 10:22       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13 10:03 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 11:27 AM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > Technologies, Inc.
> >
> > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > Peripherals:
> >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> >  - RTC clock (PCF8563)
> >  - USB 3.0 port
> >  - USB 2.0 port
> >  - 4x LED
> >  - UART over Micro-USB
> >  - M.2 slot (2280)
> >  - Mini PCI-E slot
> >
> > Additionally, automatic import of the Marvell hw_info parameters is
> > enabled via the recently added mac command for A37XX platforms.
> > The parameters stored in Marvell hw_info are usually the board serial
> > number and MAC addresses.
> >
> > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Cc: Robert Marko <robert.marko@sartura.hr>
> > ---
> >  arch/arm/dts/Makefile                         |   1 +
> >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> >  7 files changed, 514 insertions(+), 203 deletions(-)
> >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> ...
> > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > index 2de9c2ac17..21c1eb7b22 100644
> > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > @@ -11,6 +11,7 @@
> >  #include <i2c.h>
> >  #include <init.h>
> >  #include <mmc.h>
> > +#include <miiphy.h>
> >  #include <phy.h>
> >  #include <asm/global_data.h>
> >  #include <asm/io.h>
> > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> >
> > +/* Marvell 88E1512 */
> > +#define MII_MARVELL_PHY_PAGE         22
> > +
> > +#define MV88E1512_GENERAL_CTRL               20
> > +#define MV88E1512_MODE_SGMII         1
> > +#define MV88E1512_RESET_OFFS         15
> > +
> > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > +
> >  /*
> >   * Memory Controller Registers
> >   *
> > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> >       return 0;
> >  }
> >
> > -/* Bring-up board-specific network stuff */
> > -int board_network_enable(struct mii_dev *bus)
> > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> >  {
> > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > -             return 0;
> > +     const char *name;
> > +     u16 reg;
> > +
> > +     name = miiphy_get_current_dev();
> > +     if (name) {
>
> It is possible that phy is not available? As you are calling code below
> only in case name is not-NULL.

Well, according to common/miiphyutil.c, it could also happen that it's NULL.

>
> > +             /* SGMII-to-Copper mode initialization */
> > +
> > +             /* Select page 18 */
> > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > +             reg &= ~0x7;
> > +             reg |= MV88E1512_MODE_SGMII;
> > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > +             /* PHY reset is necessary after changing MODE[2:0] */
> > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > +             /* Reset page selection */
> > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > +             udelay(100);
> > +     }
> > +}
> > +
> > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > +{
> > +     int i;
> > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> >
> > +     /*
> > +      * FIXME: remove this code once Topaz driver gets available
> > +      * A3720 ESPRESSObin Ultra Board Only
> > +      * Configure Topaz switch (88E6341)
> > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > +      */
> > +     for (i = 0; i <= 5; i++) {
> > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > +                                       MVEBU_SW_PORT_CTRL_REG,
> > +                                       i == 5 ? 0x7c : 0x7f);
>
> Why port 5 has different settings?

It's to disable forwarding between the WAN port and LAN ports (I've
tested this).
I'm aware of this thread:
https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18

>
> > +     }
> > +
> > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > +
> > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > +     for (i = 1; i <= 5; i++) {
> > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > +     }
>
> It looks like that by copying board_network_enable_espressobin_ultra()
> function from Marvell U-Boot instead of using code which is in mainline
> function board_network_enable() for Espressobin, you are introducing a
> security hole, which is in Marvell U-Boot and which was fixed in
> mainline U-Boot for all supported Espressobin boards (see commit
> 48f2c8a37f700859a7004dce5adb116597a45700).
>
> I would really suggest to not blindly copy old code from Marvell into
> mainline U-Boot, as here we have fixed lot of issues.
>
> > +     return 0;
> > +}
> > +
> > +int board_network_enable_espressobin(struct mii_dev *bus)
> > +{
> >       /*
> >        * FIXME: remove this code once Topaz driver gets available
> >        * A3720 Community Board Only
> > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> >       return 0;
> >  }
> >
> > +/* Bring-up the board-specific networking */
> > +int board_network_enable(struct mii_dev *bus)
> > +{
> > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > +             return board_network_enable_espressobin(bus);
> > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > +             return board_network_enable_espressobin_ultra(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)
> >  {
> > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> >       int parts_off;
> >       int part_off;
> >
> > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > +     /*
> > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > +      * ESPRESSOBin Ultra boards.
> > +      */
> > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> >               return 0;
>
> According to kernel DTS file, it looks like that Espressobin Ultra has
> different MTD partitions as other variants... Therefore Ultra needs
> adjustments in this code.
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78

That's true, I'll have to fix this.

>
> >
> >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13  9:51         ` Luka Kovacic
@ 2021-08-13 10:09           ` Pali Rohár
  2021-08-13 10:16             ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:09 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: Marek Behun, u-boot, Robert Marko, Luka Perkov, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 11:51:02 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 11:41 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 11:23:15 Luka Kovacic wrote:
> > > Hello Marek and Pali,
> > >
> > > On Fri, Aug 13, 2021 at 10:23 AM Pali Rohár <pali@kernel.org> wrote:
> > > >
> > > > On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > > > > The mac command is implemented to enable parsing Marvell hw_info formatted
> > > > > environments. This format is often used on Marvell Armada A37XX based
> > > > > devices to store parameters like the board serial number, factory
> > > > > MAC addresses and some other information.
> > > > > These parameters are usually written to the flash in the factory.
> > > > >
> > > > > Currently the mac command supports reading/writing parameters and dumping
> > > > > the current hw_info parameters.
> > > > > EEPROM config pattern and checksum aren't supported.
> > > > >
> > > > > This functionality has been tested on the GST ESPRESSOBin-Ultra board
> > > > > successfully, both reading the stock U-Boot parameters in mainline U-Boot
> > > > > and reading the parameters written by this command in the stock U-Boot.
> > > > >
> > > > > Usage example:
> > > > >  => mac read
> > > > >  => saveenv
> > > >
> > > > Hello Luka!
> > > >
> > > > You are just using above commands for accessing following variables,
> > > > right?
> > > >
> > > > pcb_slm
> > > > pcb_rev
> > > > eco_rev
> > > > pcb_sn
> > > > ethaddr
> > > > eth1addr
> > > > eth2addr
> > > > eth3addr
> > > > eth4addr
> > > > eth5addr
> > > > eth6addr
> > > > eth7addr
> > > > eth8addr
> > > > eth9addr
> > > >
> > >
> > > Yes, I am accessing these variables.
> > >
> > > > So why is additional command required? Espressobin boards can already
> > > > load and use correct eth*addr variables, which is implemented in board
> > > > file.
> > >
> > > The current implementation in the board file preserves currently stored MAC
> > > addresses, which are in the U-Boot environment.
> >
> > Yes, this is for v5/v7 variants. But it can be easily modified for ultra
> > to read mac addresses from this custom storage.
> >
> > > My implementation is suitable for the ESPRESSOBin-Ultra, as the MACs
> > > are stored in the hw_info area of the SPI flash and the tool imports them
> > > into the normal U-Boot env.
> > > They can also be modified using the tool - we won't be able to get this
> > > functionality in the board file.
> >
> > Modification by env variables is also possible from the board file. Look
> > at U_BOOT_ENV_CALLBACK() functionality, which allows to call custom code
> > when trying to change/delete particular env variable.
> >
> > > > So what about implementing this import for all above variables for ultra
> > > > variant in board file, like it is already for all other variants? I have
> > > > already suggested it in the past. As I think this approach is just one
> > > > giant and complicated hack...
> > > > https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/
> > > >
> > > > I guess that it should be enough to import variables from SPI to env in
> > > > board_late_init() function.
> > >
> > > Currently, the MACs are automatically imported from the
> > > common/board_r.c file at boot, I think this is more standard and cleaner.
> >
> > Hm... then I somehow misunderstood how it works.
> >
> > Because I do not see any change in common/board_r.c which could read or
> > import mac addresses via calling this new "mac read" command.
> 
> The function mac_read_from_eeprom() is called, if CONFIG_ID_EEPROM is
> enabled. This has also been tested and a mechanism was added to avoid
> duplicate imports (if the user wants to modify the MAC address, so it then
> isn't overwritten).
> 
> https://source.denx.de/u-boot/u-boot/-/blob/master/common/board_r.c#L724

Ok, thank you. Now I see how it works. From commit message and from the
first look at the code it was not clear for me.

So in this patch you are implementing:

1) mac_read_from_eeprom() function for CONFIG_ID_EEPROM

2) do_mac() function for CONFIG_ID_EEPROM

which looks fine now.

> >
> > > Nevertheless, I believe this a sufficient solution for now,
> > > as this has been suggested as a solution in the previous patchset
> > > comments too.

Ok, this seems to be sufficient.

> > > >
> > > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > > ---
> > > > >  arch/arm/mach-mvebu/Kconfig                   |   1 +
> > > > >  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
> > > > >  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
> > > > >  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
> > > > >  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++

What about renaming this file just to?

board/Marvell/mvebu_armada-37xx/mac.c

I do not know if we need separate directory just for one hw_info.c file.

> > > > >  include/configs/mvebu_armada-37xx.h           |   7 +
> > > > >  lib/hashtable.c                               |   2 +-
> > > > >  7 files changed, 436 insertions(+), 2 deletions(-)
> > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
> > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > >
> > > > > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> > > > > index 89737a37ad..dff9f05b28 100644
> > > > > --- a/arch/arm/mach-mvebu/Kconfig
> > > > > +++ b/arch/arm/mach-mvebu/Kconfig
> > > > > @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
> > > > >       default 0
> > > > >       depends on SECURED_MODE_IMAGE
> > > > >
> > > > > +source "board/Marvell/mvebu_armada-37xx/Kconfig"
> > > > >  source "board/solidrun/clearfog/Kconfig"
> > > > >  source "board/kobol/helios4/Kconfig"
> > > > >
> > > > > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > > new file mode 100644
> > > > > index 0000000000..b84dd20023
> > > > > --- /dev/null
> > > > > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > > @@ -0,0 +1,29 @@
> > > > > +menu "Marvell Armada 37xx configuration"
> > > > > +depends on TARGET_MVEBU_ARMADA_37XX
> > > > > +
> > > > > +config MVEBU_MAC_HW_INFO
> > > > > +     bool "Marvell hw_info (mac) support"
> > > > > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > > > > +     default n
> > > > > +     help
> > > > > +       Enable loading of the Marvell hw_info parameters from the
> > > > > +       SPI flash hw_info area. Parameters (usually the board serial
> > > > > +       number and MAC addresses) are then imported into the
> > > > > +       existing U-Boot environment.
> > > > > +       Implementation of this command is compatible with the
> > > > > +       original Marvell U-Boot command. Reading and writing is
> > > > > +       supported.
> > > > > +       EEPROM config pattern and checksum aren't supported.
> > > > > +       After enabled, these parameters are managed from the common
> > > > > +       U-Boot mac command.
> > > > > +
> > > > > +config MVEBU_MAC_HW_INFO_OFFSET
> > > > > +     hex "Marvell hw_info (mac) SPI flash offset"
> > > > > +     depends on MVEBU_MAC_HW_INFO
> > > > > +     default 0x3E0000
> > > > > +     help
> > > > > +       This option defines the SPI flash offset of the Marvell
> > > > > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > > > > +       A3720 platforms.
> > > > > +
> > > > > +endmenu
> > > > > diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > index 27221557c7..6f6ac6b193 100644
> > > > > --- a/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > @@ -2,4 +2,5 @@
> > > > >  #
> > > > >  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
> > > > >
> > > > > -obj-y        := board.o
> > > > > +obj-y += board.o
> > > > > +obj-y += mac/
> > > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > > new file mode 100644
> > > > > index 0000000000..7c30fe6194
> > > > > --- /dev/null
> > > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > > @@ -0,0 +1,5 @@
> > > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > > +#
> > > > > +# Copyright (c) 2021 Sartura Ltd.
> > > > > +
> > > > > +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> > > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > > new file mode 100644
> > > > > index 0000000000..91e5cd8dcf
> > > > > --- /dev/null
> > > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > > @@ -0,0 +1,391 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > +/*
> > > > > + * Marvell hw_info (mac) command implementation
> > > > > + * Helper command for interfacing with the Marvell hw_info parameters
> > > > > + *
> > > > > + * Copyright (c) 2021 Sartura Ltd.
> > > > > + * Copyright (c) 2018 Marvell International Ltd.
> > > > > + *
> > > > > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > + */
> > > > > +
> > > > > +#include <command.h>
> > > > > +#include <common.h>
> > > > > +#include <env.h>
> > > > > +#include <env_internal.h>
> > > > > +#include <spi.h>
> > > > > +#include <spi_flash.h>
> > > > > +
> > > > > +#define HW_INFO_SPI_FLASH_OFFSET     CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> > > > > +
> > > > > +#define HW_INFO_MAX_ENV_SIZE         0x1F0
> > > > > +#define HW_INFO_ENV_OFFSET           0xA
> > > > > +#define HW_INFO_ENV_SEP                      0x20
> > > > > +
> > > > > +#define HW_INFO_MAX_NAME_LEN         32
> > > > > +
> > > > > +#define HW_INFO_MERGED_VARIABLE              "read_board_hw_info"
> > > > > +
> > > > > +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> > > > > +     "pcb_slm",
> > > > > +     "pcb_rev",
> > > > > +     "eco_rev",
> > > > > +     "pcb_sn",
> > > > > +     "ethaddr",
> > > > > +     "eth1addr",
> > > > > +     "eth2addr",
> > > > > +     "eth3addr",
> > > > > +     "eth4addr",
> > > > > +     "eth5addr",
> > > > > +     "eth6addr",
> > > > > +     "eth7addr",
> > > > > +     "eth8addr",
> > > > > +     "eth9addr",
> > > > > +};
> > > > > +
> > > > > +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> > > > > +                                     sizeof(hw_info_allowed_parameters[0]));
> > > > > +
> > > > > +static int hw_info_check_parameter(char *name)
> > > > > +{
> > > > > +     int idx;
> > > > > +
> > > > > +     for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> > > > > +             if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> > > > > +                     return 0;
> > > > > +     }
> > > > > +
> > > > > +     return -EINVAL;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * read_spi_flash_offset() - Read data from the SPI flash
> > > > > + * @buf: Buffer to write in
> > > > > + * @offset: Offset from the flash start
> > > > > + *
> > > > > + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> > > > > + */
> > > > > +static int read_spi_flash_offset(char *buf, int offset)
> > > > > +{
> > > > > +     struct spi_flash *flash;
> > > > > +     int ret;
> > > > > +
> > > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > > +
> > > > > +     if (!flash) {
> > > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > > +             return -EIO;
> > > > > +     }
> > > > > +
> > > > > +     ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> > > > > +     if (ret) {
> > > > > +             printf("Error - unable to read hw_info environment from SPI flash.\n");
> > > > > +             return ret;
> > > > > +     }
> > > > > +
> > > > > +     return ret;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * write_spi_flash_offset() - Write a buffer to SPI flash
> > > > > + * @buf: Buffer to write to SPI flash
> > > > > + * @offset: Offset from the flash start
> > > > > + * @size: Size of the buffer content
> > > > > + *
> > > > > + * This function probes the SPI flash and updates the specified flash location
> > > > > + * with new data from the buffer.
> > > > > + */
> > > > > +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> > > > > +{
> > > > > +     ssize_t safe_size, erase_size;
> > > > > +     struct spi_flash *flash;
> > > > > +     int ret;
> > > > > +
> > > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > > +
> > > > > +     if (!flash) {
> > > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > > +             return -EIO;
> > > > > +     }
> > > > > +
> > > > > +     safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> > > > > +     erase_size = safe_size +
> > > > > +                  (flash->erase_size - safe_size % flash->erase_size);
> > > > > +     ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> > > > > +     if (ret) {
> > > > > +             printf("Error - unable to erase the hw_info area on SPI flash.\n");
> > > > > +             return ret;
> > > > > +     }
> > > > > +     ret = spi_flash_write(flash, offset, safe_size, buf);
> > > > > +     if (ret) {
> > > > > +             printf("Error - unable to write hw_info parameters to SPI flash.\n");
> > > > > +             return ret;
> > > > > +     }
> > > > > +
> > > > > +     return ret;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * cmd_hw_info_dump() - Dump the hw_info parameters
> > > > > + *
> > > > > + * This function prints all Marvell hw_info parameters, which are stored in
> > > > > + * the SPI flash.
> > > > > + */
> > > > > +static int cmd_hw_info_dump(void)
> > > > > +{
> > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > +     struct hsearch_data htab;
> > > > > +     char *res = NULL;
> > > > > +     ssize_t len;
> > > > > +     int ret = 0;
> > > > > +
> > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > +     if (ret)
> > > > > +             goto err;
> > > > > +     memset(&htab, 0, sizeof(htab));
> > > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > > +             ret = -ENOMEM;
> > > > > +             goto err;
> > > > > +     }
> > > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > +             ret = -EFAULT;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +
> > > > > +     len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > > +     if (len > 0) {
> > > > > +             printf("Parameters (hw_info):\n");
> > > > > +             puts(res);
> > > > > +             free(res);
> > > > > +             ret = 0;
> > > > > +             goto ret_htab;
> > > > > +     }
> > > > > +ret_htab:
> > > > > +     hdestroy_r(&htab);
> > > > > +     return ret;
> > > > > +err_htab:
> > > > > +     hdestroy_r(&htab);
> > > > > +err:
> > > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > > +     return ret;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> > > > > + * @print_env: Print U-Boot environment after new parameters are imported
> > > > > + *
> > > > > + * This function reads the Marvell hw_info parameters from SPI flash and
> > > > > + * imports them into the U-Boot env.
> > > > > + */
> > > > > +static int cmd_hw_info_read(bool print_env)
> > > > > +{
> > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > +     char *res = NULL;
> > > > > +     ssize_t len;
> > > > > +     int ret = 0;
> > > > > +
> > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > +     if (ret)
> > > > > +             goto err;
> > > > > +     if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > +             ret = -EFAULT;
> > > > > +             goto err;
> > > > > +     }
> > > > > +
> > > > > +     printf("Successfully imported the Marvell hw_info parameters.\n");
> > > > > +     if (!print_env)
> > > > > +             return 0;
> > > > > +
> > > > > +     len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > > +     if (len > 0) {
> > > > > +             printf("Updated environment:\n");
> > > > > +             puts(res);
> > > > > +             free(res);
> > > > > +             return 0;
> > > > > +     }
> > > > > +err:
> > > > > +     printf("## Error: cannot import hw_info parameters\n");
> > > > > +     return ret;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> > > > > + * @name: Name of the U-Boot env parameter to save
> > > > > + *
> > > > > + * This function finds the specified parameter by name in the U-Boot env
> > > > > + * and then updates the Marvell hw_info parameters with the new value.
> > > > > + */
> > > > > +static int cmd_hw_info_save(char *name)
> > > > > +{
> > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > +     struct env_entry e, *ep, *rv;
> > > > > +     struct hsearch_data htab;
> > > > > +     char *res = NULL;
> > > > > +     ssize_t len;
> > > > > +     int ret = 0;
> > > > > +
> > > > > +     ret = hw_info_check_parameter(name);
> > > > > +     if (ret) {
> > > > > +             printf("Invalid parameter %s, stopping.\n", name);
> > > > > +             goto err;
> > > > > +     }
> > > > > +
> > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > +     if (ret)
> > > > > +             goto err;
> > > > > +     memset(&htab, 0, sizeof(htab));
> > > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > > +             ret = -ENOMEM;
> > > > > +             goto err;
> > > > > +     }
> > > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > +             ret = -EFAULT;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +
> > > > > +     e.key = name;
> > > > > +     e.data = NULL;
> > > > > +     if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> > > > > +             ret = -ENOENT;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +     if (!ep) {
> > > > > +             ret = -ENOENT;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +
> > > > > +     printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> > > > > +
> > > > > +     e.key = ep->key;
> > > > > +     e.data = ep->data;
> > > > > +     if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> > > > > +             ret = -EINVAL;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +     if (!rv) {
> > > > > +             ret = -EINVAL;
> > > > > +             goto err_htab;
> > > > > +     }
> > > > > +     len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> > > > > +                     &res, 0, 0, NULL);
> > > > > +     if (len <= 0) {
> > > > > +             free(res);
> > > > > +             goto ret_htab;
> > > > > +     }
> > > > > +     ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> > > > > +                                  HW_INFO_ENV_OFFSET, len);
> > > > > +     free(res);
> > > > > +     if (ret)
> > > > > +             goto err_htab;
> > > > > +
> > > > > +     printf("Successfully stored the Marvell hw_info parameters.\n");
> > > > > +     return 0;
> > > > > +ret_htab:
> > > > > +     hdestroy_r(&htab);
> > > > > +     return ret;
> > > > > +err_htab:
> > > > > +     hdestroy_r(&htab);
> > > > > +err:
> > > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > > +     return ret;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> > > > > + *
> > > > > + * This function reads the content of the Marvell hw_info parameters from the
> > > > > + * SPI flash and imports them into the U-Boot environment.
> > > > > + * This includes MAC addresses and board serial numbers.
> > > > > + *
> > > > > + * The import is performed only once.
> > > > > + *
> > > > > + * This function is a part of the U-Boot mac command and must be executed
> > > > > + * after SPI flash initialization.
> > > > > + */
> > > > > +int mac_read_from_eeprom(void)
> > > > > +{
> > > > > +     if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> > > > > +             if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> > > > > +                     return -ENOENT;
> > > > > +             return cmd_hw_info_read(false);
> > > > > +     }
> > > > > +     return 0;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * print_platform_help() - Print the platform specific help
> > > > > + *
> > > > > + * Extend the existing U-Boot mac command description by also printing
> > > > > + * platform specific help text.
> > > > > + */
> > > > > +static void print_platform_help(void)
> > > > > +{
> > > > > +     printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> > > > > +            "are unavailable on Marvell Armada A37xx platforms.\n"
> > > > > +            "Use mac [read|save {parameter}] instead.\n"
> > > > > +            "Available parameters:\n"
> > > > > +            "pcb_slm\tPCB SLM number\n"
> > > > > +            "pcb_rev\tPCB revision number\n"
> > > > > +            "eco_rev\tECO revision number\n"
> > > > > +            "pcb_sn\tPCB SN\n"
> > > > > +            "ethaddr\tfirst MAC address\n"
> > > > > +            "eth[1-9]addr\tsecond-ninth MAC address\n");
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > + * do_mac() - Standard U-Boot mac command implementation
> > > > > + * @cmdtp: U-Boot command table
> > > > > + * @flag: Execution flags
> > > > > + * @argc: Count of arguments
> > > > > + * @argv: Arguments
> > > > > + *
> > > > > + * This function implements the standard U-Boot mac command in a mostly
> > > > > + * compatible way.
> > > > > + * To conform to the general command structure as much as possible, the
> > > > > + * command description from cmd/mac.c is followed.
> > > > > + * Where not possible, convenient or sensible additional comments for the user
> > > > > + * are added.
> > > > > + */
> > > > > +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > > > > +{
> > > > > +     const char *cmd = argv[1];
> > > > > +     int ret = 0;
> > > > > +
> > > > > +     if (argc == 1) {
> > > > > +             ret = cmd_hw_info_dump();
> > > > > +             if (ret)
> > > > > +                     return -EINVAL;
> > > > > +             return CMD_RET_SUCCESS;
> > > > > +     }
> > > > > +
> > > > > +     if (!strcmp(cmd, "read")) {
> > > > > +             if (cmd_hw_info_read(true))
> > > > > +                     return -EINVAL;
> > > > > +     } else if (!strcmp(cmd, "save")) {
> > > > > +             if (argc != 3) {
> > > > > +                     printf("Please pass an additional argument to specify, "
> > > > > +                            "which env parameter to save.\n");
> > > > > +                     return -EINVAL;
> > > > > +             }
> > > > > +             if (cmd_hw_info_save(argv[2]))
> > > > > +                     return -EINVAL;
> > > > > +     } else {
> > > > > +             ret = cmd_usage(cmdtp);
> > > > > +             print_platform_help();
> > > > > +             return ret;
> > > > > +     }
> > > > > +
> > > > > +     return CMD_RET_SUCCESS;
> > > > > +}
> > > > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > > > index c8c34d7d92..8e8bcfa018 100644
> > > > > --- a/include/configs/mvebu_armada-37xx.h
> > > > > +++ b/include/configs/mvebu_armada-37xx.h
> > > > > @@ -62,6 +62,13 @@
> > > > >   */
> > > > >  #define DEFAULT_ENV_IS_RW            /* required for configuring default fdtfile= */
> > > > >
> > > > > +/*
> > > > > + * Platform identification (Marvell hw_info parameters)
> > > > > + */
> > > > > +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> > > > > +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> > > > > +#endif
> > > > > +
> > > > >  /*
> > > > >   * Ethernet Driver configuration
> > > > >   */
> > > > > diff --git a/lib/hashtable.c b/lib/hashtable.c
> > > > > index ff5ff72639..06322e3304 100644
> > > > > --- a/lib/hashtable.c
> > > > > +++ b/lib/hashtable.c
> > > > > @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
> > > > >   * multi-line values.
> > > > >   *
> > > > >   * In theory, arbitrary separator characters can be used, but only
> > > > > - * '\0' and '\n' have really been tested.
> > > > > + * '\0', '\n' and 0x20 have been tested.
> > > > >   */
> > > > >
> > > > >  int himport_r(struct hsearch_data *htab,
> > > > > --
> > > > > 2.31.1
> > > > >
> > >
> > > Kind regards,
> > > Luka
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13 10:09           ` Pali Rohár
@ 2021-08-13 10:16             ` Luka Kovacic
  0 siblings, 0 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13 10:16 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Marek Behun, u-boot, Robert Marko, Luka Perkov, sr, sjg,
	patrick.delaunay, xypron.glpk

On Fri, Aug 13, 2021 at 12:09 PM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 11:51:02 Luka Kovacic wrote:
> > Hello Pali,
> >
> > On Fri, Aug 13, 2021 at 11:41 AM Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On Friday 13 August 2021 11:23:15 Luka Kovacic wrote:
> > > > Hello Marek and Pali,
> > > >
> > > > On Fri, Aug 13, 2021 at 10:23 AM Pali Rohár <pali@kernel.org> wrote:
> > > > >
> > > > > On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > > > > > The mac command is implemented to enable parsing Marvell hw_info formatted
> > > > > > environments. This format is often used on Marvell Armada A37XX based
> > > > > > devices to store parameters like the board serial number, factory
> > > > > > MAC addresses and some other information.
> > > > > > These parameters are usually written to the flash in the factory.
> > > > > >
> > > > > > Currently the mac command supports reading/writing parameters and dumping
> > > > > > the current hw_info parameters.
> > > > > > EEPROM config pattern and checksum aren't supported.
> > > > > >
> > > > > > This functionality has been tested on the GST ESPRESSOBin-Ultra board
> > > > > > successfully, both reading the stock U-Boot parameters in mainline U-Boot
> > > > > > and reading the parameters written by this command in the stock U-Boot.
> > > > > >
> > > > > > Usage example:
> > > > > >  => mac read
> > > > > >  => saveenv
> > > > >
> > > > > Hello Luka!
> > > > >
> > > > > You are just using above commands for accessing following variables,
> > > > > right?
> > > > >
> > > > > pcb_slm
> > > > > pcb_rev
> > > > > eco_rev
> > > > > pcb_sn
> > > > > ethaddr
> > > > > eth1addr
> > > > > eth2addr
> > > > > eth3addr
> > > > > eth4addr
> > > > > eth5addr
> > > > > eth6addr
> > > > > eth7addr
> > > > > eth8addr
> > > > > eth9addr
> > > > >
> > > >
> > > > Yes, I am accessing these variables.
> > > >
> > > > > So why is additional command required? Espressobin boards can already
> > > > > load and use correct eth*addr variables, which is implemented in board
> > > > > file.
> > > >
> > > > The current implementation in the board file preserves currently stored MAC
> > > > addresses, which are in the U-Boot environment.
> > >
> > > Yes, this is for v5/v7 variants. But it can be easily modified for ultra
> > > to read mac addresses from this custom storage.
> > >
> > > > My implementation is suitable for the ESPRESSOBin-Ultra, as the MACs
> > > > are stored in the hw_info area of the SPI flash and the tool imports them
> > > > into the normal U-Boot env.
> > > > They can also be modified using the tool - we won't be able to get this
> > > > functionality in the board file.
> > >
> > > Modification by env variables is also possible from the board file. Look
> > > at U_BOOT_ENV_CALLBACK() functionality, which allows to call custom code
> > > when trying to change/delete particular env variable.
> > >
> > > > > So what about implementing this import for all above variables for ultra
> > > > > variant in board file, like it is already for all other variants? I have
> > > > > already suggested it in the past. As I think this approach is just one
> > > > > giant and complicated hack...
> > > > > https://lore.kernel.org/u-boot/20210301151721.xt62rdun5dnlevqk@pali/
> > > > >
> > > > > I guess that it should be enough to import variables from SPI to env in
> > > > > board_late_init() function.
> > > >
> > > > Currently, the MACs are automatically imported from the
> > > > common/board_r.c file at boot, I think this is more standard and cleaner.
> > >
> > > Hm... then I somehow misunderstood how it works.
> > >
> > > Because I do not see any change in common/board_r.c which could read or
> > > import mac addresses via calling this new "mac read" command.
> >
> > The function mac_read_from_eeprom() is called, if CONFIG_ID_EEPROM is
> > enabled. This has also been tested and a mechanism was added to avoid
> > duplicate imports (if the user wants to modify the MAC address, so it then
> > isn't overwritten).
> >
> > https://source.denx.de/u-boot/u-boot/-/blob/master/common/board_r.c#L724
>
> Ok, thank you. Now I see how it works. From commit message and from the
> first look at the code it was not clear for me.
>
> So in this patch you are implementing:
>
> 1) mac_read_from_eeprom() function for CONFIG_ID_EEPROM
>
> 2) do_mac() function for CONFIG_ID_EEPROM
>
> which looks fine now.
>
> > >
> > > > Nevertheless, I believe this a sufficient solution for now,
> > > > as this has been suggested as a solution in the previous patchset
> > > > comments too.
>
> Ok, this seems to be sufficient.
>
> > > > >
> > > > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > > > ---
> > > > > >  arch/arm/mach-mvebu/Kconfig                   |   1 +
> > > > > >  board/Marvell/mvebu_armada-37xx/Kconfig       |  29 ++
> > > > > >  board/Marvell/mvebu_armada-37xx/Makefile      |   3 +-
> > > > > >  board/Marvell/mvebu_armada-37xx/mac/Makefile  |   5 +
> > > > > >  board/Marvell/mvebu_armada-37xx/mac/hw_info.c | 391 ++++++++++++++++++
>
> What about renaming this file just to?
>
> board/Marvell/mvebu_armada-37xx/mac.c
>
> I do not know if we need separate directory just for one hw_info.c file.

Sure, I can rename this.

>
> > > > > >  include/configs/mvebu_armada-37xx.h           |   7 +
> > > > > >  lib/hashtable.c                               |   2 +-
> > > > > >  7 files changed, 436 insertions(+), 2 deletions(-)
> > > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/Kconfig
> > > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > > >  create mode 100644 board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > > >
> > > > > > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> > > > > > index 89737a37ad..dff9f05b28 100644
> > > > > > --- a/arch/arm/mach-mvebu/Kconfig
> > > > > > +++ b/arch/arm/mach-mvebu/Kconfig
> > > > > > @@ -312,6 +312,7 @@ config SECURED_MODE_CSK_INDEX
> > > > > >       default 0
> > > > > >       depends on SECURED_MODE_IMAGE
> > > > > >
> > > > > > +source "board/Marvell/mvebu_armada-37xx/Kconfig"
> > > > > >  source "board/solidrun/clearfog/Kconfig"
> > > > > >  source "board/kobol/helios4/Kconfig"
> > > > > >
> > > > > > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > > > new file mode 100644
> > > > > > index 0000000000..b84dd20023
> > > > > > --- /dev/null
> > > > > > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > > > > @@ -0,0 +1,29 @@
> > > > > > +menu "Marvell Armada 37xx configuration"
> > > > > > +depends on TARGET_MVEBU_ARMADA_37XX
> > > > > > +
> > > > > > +config MVEBU_MAC_HW_INFO
> > > > > > +     bool "Marvell hw_info (mac) support"
> > > > > > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > > > > > +     default n
> > > > > > +     help
> > > > > > +       Enable loading of the Marvell hw_info parameters from the
> > > > > > +       SPI flash hw_info area. Parameters (usually the board serial
> > > > > > +       number and MAC addresses) are then imported into the
> > > > > > +       existing U-Boot environment.
> > > > > > +       Implementation of this command is compatible with the
> > > > > > +       original Marvell U-Boot command. Reading and writing is
> > > > > > +       supported.
> > > > > > +       EEPROM config pattern and checksum aren't supported.
> > > > > > +       After enabled, these parameters are managed from the common
> > > > > > +       U-Boot mac command.
> > > > > > +
> > > > > > +config MVEBU_MAC_HW_INFO_OFFSET
> > > > > > +     hex "Marvell hw_info (mac) SPI flash offset"
> > > > > > +     depends on MVEBU_MAC_HW_INFO
> > > > > > +     default 0x3E0000
> > > > > > +     help
> > > > > > +       This option defines the SPI flash offset of the Marvell
> > > > > > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > > > > > +       A3720 platforms.
> > > > > > +
> > > > > > +endmenu
> > > > > > diff --git a/board/Marvell/mvebu_armada-37xx/Makefile b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > > index 27221557c7..6f6ac6b193 100644
> > > > > > --- a/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > > +++ b/board/Marvell/mvebu_armada-37xx/Makefile
> > > > > > @@ -2,4 +2,5 @@
> > > > > >  #
> > > > > >  # Copyright (C) 2016 Stefan Roese <sr@denx.de>
> > > > > >
> > > > > > -obj-y        := board.o
> > > > > > +obj-y += board.o
> > > > > > +obj-y += mac/
> > > > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/Makefile b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > > > new file mode 100644
> > > > > > index 0000000000..7c30fe6194
> > > > > > --- /dev/null
> > > > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/Makefile
> > > > > > @@ -0,0 +1,5 @@
> > > > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > > > +#
> > > > > > +# Copyright (c) 2021 Sartura Ltd.
> > > > > > +
> > > > > > +obj-$(CONFIG_ID_EEPROM) += hw_info.o
> > > > > > diff --git a/board/Marvell/mvebu_armada-37xx/mac/hw_info.c b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > > > new file mode 100644
> > > > > > index 0000000000..91e5cd8dcf
> > > > > > --- /dev/null
> > > > > > +++ b/board/Marvell/mvebu_armada-37xx/mac/hw_info.c
> > > > > > @@ -0,0 +1,391 @@
> > > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > > +/*
> > > > > > + * Marvell hw_info (mac) command implementation
> > > > > > + * Helper command for interfacing with the Marvell hw_info parameters
> > > > > > + *
> > > > > > + * Copyright (c) 2021 Sartura Ltd.
> > > > > > + * Copyright (c) 2018 Marvell International Ltd.
> > > > > > + *
> > > > > > + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > > + */
> > > > > > +
> > > > > > +#include <command.h>
> > > > > > +#include <common.h>
> > > > > > +#include <env.h>
> > > > > > +#include <env_internal.h>
> > > > > > +#include <spi.h>
> > > > > > +#include <spi_flash.h>
> > > > > > +
> > > > > > +#define HW_INFO_SPI_FLASH_OFFSET     CONFIG_MVEBU_MAC_HW_INFO_OFFSET
> > > > > > +
> > > > > > +#define HW_INFO_MAX_ENV_SIZE         0x1F0
> > > > > > +#define HW_INFO_ENV_OFFSET           0xA
> > > > > > +#define HW_INFO_ENV_SEP                      0x20
> > > > > > +
> > > > > > +#define HW_INFO_MAX_NAME_LEN         32
> > > > > > +
> > > > > > +#define HW_INFO_MERGED_VARIABLE              "read_board_hw_info"
> > > > > > +
> > > > > > +static char hw_info_allowed_parameters[][HW_INFO_MAX_NAME_LEN] = {
> > > > > > +     "pcb_slm",
> > > > > > +     "pcb_rev",
> > > > > > +     "eco_rev",
> > > > > > +     "pcb_sn",
> > > > > > +     "ethaddr",
> > > > > > +     "eth1addr",
> > > > > > +     "eth2addr",
> > > > > > +     "eth3addr",
> > > > > > +     "eth4addr",
> > > > > > +     "eth5addr",
> > > > > > +     "eth6addr",
> > > > > > +     "eth7addr",
> > > > > > +     "eth8addr",
> > > > > > +     "eth9addr",
> > > > > > +};
> > > > > > +
> > > > > > +static int hw_info_allowed_param_count = (sizeof(hw_info_allowed_parameters) /
> > > > > > +                                     sizeof(hw_info_allowed_parameters[0]));
> > > > > > +
> > > > > > +static int hw_info_check_parameter(char *name)
> > > > > > +{
> > > > > > +     int idx;
> > > > > > +
> > > > > > +     for (idx = 0; idx < hw_info_allowed_param_count; idx++) {
> > > > > > +             if (strcmp(name, hw_info_allowed_parameters[idx]) == 0)
> > > > > > +                     return 0;
> > > > > > +     }
> > > > > > +
> > > > > > +     return -EINVAL;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * read_spi_flash_offset() - Read data from the SPI flash
> > > > > > + * @buf: Buffer to write in
> > > > > > + * @offset: Offset from the flash start
> > > > > > + *
> > > > > > + * Read SPI flash data into the buffer from offset to HW_INFO_MAX_ENV_SIZE.
> > > > > > + */
> > > > > > +static int read_spi_flash_offset(char *buf, int offset)
> > > > > > +{
> > > > > > +     struct spi_flash *flash;
> > > > > > +     int ret;
> > > > > > +
> > > > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > > > +
> > > > > > +     if (!flash) {
> > > > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > > > +             return -EIO;
> > > > > > +     }
> > > > > > +
> > > > > > +     ret = spi_flash_read(flash, offset, HW_INFO_MAX_ENV_SIZE, buf);
> > > > > > +     if (ret) {
> > > > > > +             printf("Error - unable to read hw_info environment from SPI flash.\n");
> > > > > > +             return ret;
> > > > > > +     }
> > > > > > +
> > > > > > +     return ret;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * write_spi_flash_offset() - Write a buffer to SPI flash
> > > > > > + * @buf: Buffer to write to SPI flash
> > > > > > + * @offset: Offset from the flash start
> > > > > > + * @size: Size of the buffer content
> > > > > > + *
> > > > > > + * This function probes the SPI flash and updates the specified flash location
> > > > > > + * with new data from the buffer.
> > > > > > + */
> > > > > > +static int write_spi_flash_offset(char *buf, int offset, ssize_t size)
> > > > > > +{
> > > > > > +     ssize_t safe_size, erase_size;
> > > > > > +     struct spi_flash *flash;
> > > > > > +     int ret;
> > > > > > +
> > > > > > +     flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
> > > > > > +                             CONFIG_SF_DEFAULT_CS,
> > > > > > +                             CONFIG_SF_DEFAULT_SPEED,
> > > > > > +                             CONFIG_SF_DEFAULT_MODE);
> > > > > > +
> > > > > > +     if (!flash) {
> > > > > > +             printf("Error - unable to probe SPI flash.\n");
> > > > > > +             return -EIO;
> > > > > > +     }
> > > > > > +
> > > > > > +     safe_size = size > HW_INFO_MAX_ENV_SIZE ? HW_INFO_MAX_ENV_SIZE : size;
> > > > > > +     erase_size = safe_size +
> > > > > > +                  (flash->erase_size - safe_size % flash->erase_size);
> > > > > > +     ret = spi_flash_erase(flash, HW_INFO_SPI_FLASH_OFFSET, erase_size);
> > > > > > +     if (ret) {
> > > > > > +             printf("Error - unable to erase the hw_info area on SPI flash.\n");
> > > > > > +             return ret;
> > > > > > +     }
> > > > > > +     ret = spi_flash_write(flash, offset, safe_size, buf);
> > > > > > +     if (ret) {
> > > > > > +             printf("Error - unable to write hw_info parameters to SPI flash.\n");
> > > > > > +             return ret;
> > > > > > +     }
> > > > > > +
> > > > > > +     return ret;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * cmd_hw_info_dump() - Dump the hw_info parameters
> > > > > > + *
> > > > > > + * This function prints all Marvell hw_info parameters, which are stored in
> > > > > > + * the SPI flash.
> > > > > > + */
> > > > > > +static int cmd_hw_info_dump(void)
> > > > > > +{
> > > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > > +     struct hsearch_data htab;
> > > > > > +     char *res = NULL;
> > > > > > +     ssize_t len;
> > > > > > +     int ret = 0;
> > > > > > +
> > > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > > +     if (ret)
> > > > > > +             goto err;
> > > > > > +     memset(&htab, 0, sizeof(htab));
> > > > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > > > +             ret = -ENOMEM;
> > > > > > +             goto err;
> > > > > > +     }
> > > > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > > +             ret = -EFAULT;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +
> > > > > > +     len = hexport_r(&htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > > > +     if (len > 0) {
> > > > > > +             printf("Parameters (hw_info):\n");
> > > > > > +             puts(res);
> > > > > > +             free(res);
> > > > > > +             ret = 0;
> > > > > > +             goto ret_htab;
> > > > > > +     }
> > > > > > +ret_htab:
> > > > > > +     hdestroy_r(&htab);
> > > > > > +     return ret;
> > > > > > +err_htab:
> > > > > > +     hdestroy_r(&htab);
> > > > > > +err:
> > > > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > > > +     return ret;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * cmd_hw_info_read() - Import the hw_info parameters into U-Boot env
> > > > > > + * @print_env: Print U-Boot environment after new parameters are imported
> > > > > > + *
> > > > > > + * This function reads the Marvell hw_info parameters from SPI flash and
> > > > > > + * imports them into the U-Boot env.
> > > > > > + */
> > > > > > +static int cmd_hw_info_read(bool print_env)
> > > > > > +{
> > > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > > +     char *res = NULL;
> > > > > > +     ssize_t len;
> > > > > > +     int ret = 0;
> > > > > > +
> > > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > > +     if (ret)
> > > > > > +             goto err;
> > > > > > +     if (!himport_r(&env_htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > > +             ret = -EFAULT;
> > > > > > +             goto err;
> > > > > > +     }
> > > > > > +
> > > > > > +     printf("Successfully imported the Marvell hw_info parameters.\n");
> > > > > > +     if (!print_env)
> > > > > > +             return 0;
> > > > > > +
> > > > > > +     len = hexport_r(&env_htab, '\n', H_HIDE_DOT, &res, 0, 0, NULL);
> > > > > > +     if (len > 0) {
> > > > > > +             printf("Updated environment:\n");
> > > > > > +             puts(res);
> > > > > > +             free(res);
> > > > > > +             return 0;
> > > > > > +     }
> > > > > > +err:
> > > > > > +     printf("## Error: cannot import hw_info parameters\n");
> > > > > > +     return ret;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * cmd_hw_info_save() - Save a parameter from U-Boot env to hw_info parameters
> > > > > > + * @name: Name of the U-Boot env parameter to save
> > > > > > + *
> > > > > > + * This function finds the specified parameter by name in the U-Boot env
> > > > > > + * and then updates the Marvell hw_info parameters with the new value.
> > > > > > + */
> > > > > > +static int cmd_hw_info_save(char *name)
> > > > > > +{
> > > > > > +     char buffer[HW_INFO_MAX_ENV_SIZE];
> > > > > > +     struct env_entry e, *ep, *rv;
> > > > > > +     struct hsearch_data htab;
> > > > > > +     char *res = NULL;
> > > > > > +     ssize_t len;
> > > > > > +     int ret = 0;
> > > > > > +
> > > > > > +     ret = hw_info_check_parameter(name);
> > > > > > +     if (ret) {
> > > > > > +             printf("Invalid parameter %s, stopping.\n", name);
> > > > > > +             goto err;
> > > > > > +     }
> > > > > > +
> > > > > > +     ret = read_spi_flash_offset(buffer, HW_INFO_SPI_FLASH_OFFSET +
> > > > > > +                                 HW_INFO_ENV_OFFSET);
> > > > > > +     if (ret)
> > > > > > +             goto err;
> > > > > > +     memset(&htab, 0, sizeof(htab));
> > > > > > +     if (!hcreate_r(HW_INFO_MAX_ENV_SIZE, &htab)) {
> > > > > > +             ret = -ENOMEM;
> > > > > > +             goto err;
> > > > > > +     }
> > > > > > +     if (!himport_r(&htab, buffer, HW_INFO_MAX_ENV_SIZE,
> > > > > > +                    HW_INFO_ENV_SEP, H_NOCLEAR, 0, 0, NULL)) {
> > > > > > +             ret = -EFAULT;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +
> > > > > > +     e.key = name;
> > > > > > +     e.data = NULL;
> > > > > > +     if (!hsearch_r(e, ENV_FIND, &ep, &env_htab, H_HIDE_DOT)) {
> > > > > > +             ret = -ENOENT;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +     if (!ep) {
> > > > > > +             ret = -ENOENT;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +
> > > > > > +     printf("Storing %s=%s to hw_info...\n", ep->key, ep->data);
> > > > > > +
> > > > > > +     e.key = ep->key;
> > > > > > +     e.data = ep->data;
> > > > > > +     if (!hsearch_r(e, ENV_ENTER, &rv, &htab, H_HIDE_DOT)) {
> > > > > > +             ret = -EINVAL;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +     if (!rv) {
> > > > > > +             ret = -EINVAL;
> > > > > > +             goto err_htab;
> > > > > > +     }
> > > > > > +     len = hexport_r(&htab, HW_INFO_ENV_SEP, H_MATCH_KEY | H_MATCH_IDENT,
> > > > > > +                     &res, 0, 0, NULL);
> > > > > > +     if (len <= 0) {
> > > > > > +             free(res);
> > > > > > +             goto ret_htab;
> > > > > > +     }
> > > > > > +     ret = write_spi_flash_offset(res, HW_INFO_SPI_FLASH_OFFSET +
> > > > > > +                                  HW_INFO_ENV_OFFSET, len);
> > > > > > +     free(res);
> > > > > > +     if (ret)
> > > > > > +             goto err_htab;
> > > > > > +
> > > > > > +     printf("Successfully stored the Marvell hw_info parameters.\n");
> > > > > > +     return 0;
> > > > > > +ret_htab:
> > > > > > +     hdestroy_r(&htab);
> > > > > > +     return ret;
> > > > > > +err_htab:
> > > > > > +     hdestroy_r(&htab);
> > > > > > +err:
> > > > > > +     printf("## Error: cannot store hw_info parameters to SPI flash\n");
> > > > > > +     return ret;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * mac_read_from_eeprom() - Read the parameters from SPI flash.
> > > > > > + *
> > > > > > + * This function reads the content of the Marvell hw_info parameters from the
> > > > > > + * SPI flash and imports them into the U-Boot environment.
> > > > > > + * This includes MAC addresses and board serial numbers.
> > > > > > + *
> > > > > > + * The import is performed only once.
> > > > > > + *
> > > > > > + * This function is a part of the U-Boot mac command and must be executed
> > > > > > + * after SPI flash initialization.
> > > > > > + */
> > > > > > +int mac_read_from_eeprom(void)
> > > > > > +{
> > > > > > +     if (env_get_ulong(HW_INFO_MERGED_VARIABLE, 10, 0) == 0) {
> > > > > > +             if (env_set_ulong(HW_INFO_MERGED_VARIABLE, 1))
> > > > > > +                     return -ENOENT;
> > > > > > +             return cmd_hw_info_read(false);
> > > > > > +     }
> > > > > > +     return 0;
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * print_platform_help() - Print the platform specific help
> > > > > > + *
> > > > > > + * Extend the existing U-Boot mac command description by also printing
> > > > > > + * platform specific help text.
> > > > > > + */
> > > > > > +static void print_platform_help(void)
> > > > > > +{
> > > > > > +     printf("\nNote: arguments mac [id|num|errata|date|ports|port_number]\n"
> > > > > > +            "are unavailable on Marvell Armada A37xx platforms.\n"
> > > > > > +            "Use mac [read|save {parameter}] instead.\n"
> > > > > > +            "Available parameters:\n"
> > > > > > +            "pcb_slm\tPCB SLM number\n"
> > > > > > +            "pcb_rev\tPCB revision number\n"
> > > > > > +            "eco_rev\tECO revision number\n"
> > > > > > +            "pcb_sn\tPCB SN\n"
> > > > > > +            "ethaddr\tfirst MAC address\n"
> > > > > > +            "eth[1-9]addr\tsecond-ninth MAC address\n");
> > > > > > +}
> > > > > > +
> > > > > > +/**
> > > > > > + * do_mac() - Standard U-Boot mac command implementation
> > > > > > + * @cmdtp: U-Boot command table
> > > > > > + * @flag: Execution flags
> > > > > > + * @argc: Count of arguments
> > > > > > + * @argv: Arguments
> > > > > > + *
> > > > > > + * This function implements the standard U-Boot mac command in a mostly
> > > > > > + * compatible way.
> > > > > > + * To conform to the general command structure as much as possible, the
> > > > > > + * command description from cmd/mac.c is followed.
> > > > > > + * Where not possible, convenient or sensible additional comments for the user
> > > > > > + * are added.
> > > > > > + */
> > > > > > +int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > > > > > +{
> > > > > > +     const char *cmd = argv[1];
> > > > > > +     int ret = 0;
> > > > > > +
> > > > > > +     if (argc == 1) {
> > > > > > +             ret = cmd_hw_info_dump();
> > > > > > +             if (ret)
> > > > > > +                     return -EINVAL;
> > > > > > +             return CMD_RET_SUCCESS;
> > > > > > +     }
> > > > > > +
> > > > > > +     if (!strcmp(cmd, "read")) {
> > > > > > +             if (cmd_hw_info_read(true))
> > > > > > +                     return -EINVAL;
> > > > > > +     } else if (!strcmp(cmd, "save")) {
> > > > > > +             if (argc != 3) {
> > > > > > +                     printf("Please pass an additional argument to specify, "
> > > > > > +                            "which env parameter to save.\n");
> > > > > > +                     return -EINVAL;
> > > > > > +             }
> > > > > > +             if (cmd_hw_info_save(argv[2]))
> > > > > > +                     return -EINVAL;
> > > > > > +     } else {
> > > > > > +             ret = cmd_usage(cmdtp);
> > > > > > +             print_platform_help();
> > > > > > +             return ret;
> > > > > > +     }
> > > > > > +
> > > > > > +     return CMD_RET_SUCCESS;
> > > > > > +}
> > > > > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > > > > index c8c34d7d92..8e8bcfa018 100644
> > > > > > --- a/include/configs/mvebu_armada-37xx.h
> > > > > > +++ b/include/configs/mvebu_armada-37xx.h
> > > > > > @@ -62,6 +62,13 @@
> > > > > >   */
> > > > > >  #define DEFAULT_ENV_IS_RW            /* required for configuring default fdtfile= */
> > > > > >
> > > > > > +/*
> > > > > > + * Platform identification (Marvell hw_info parameters)
> > > > > > + */
> > > > > > +#ifdef CONFIG_MVEBU_MAC_HW_INFO
> > > > > > +#define CONFIG_ID_EEPROM /* U-Boot mac command */
> > > > > > +#endif
> > > > > > +
> > > > > >  /*
> > > > > >   * Ethernet Driver configuration
> > > > > >   */
> > > > > > diff --git a/lib/hashtable.c b/lib/hashtable.c
> > > > > > index ff5ff72639..06322e3304 100644
> > > > > > --- a/lib/hashtable.c
> > > > > > +++ b/lib/hashtable.c
> > > > > > @@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
> > > > > >   * multi-line values.
> > > > > >   *
> > > > > >   * In theory, arbitrary separator characters can be used, but only
> > > > > > - * '\0' and '\n' have really been tested.
> > > > > > + * '\0', '\n' and 0x20 have been tested.
> > > > > >   */
> > > > > >
> > > > > >  int himport_r(struct hsearch_data *htab,
> > > > > > --
> > > > > > 2.31.1
> > > > > >
> > > >
> > > > Kind regards,
> > > > Luka
> >
> > Kind regards,
> > Luka

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:03     ` Luka Kovacic
@ 2021-08-13 10:22       ` Pali Rohár
  2021-08-13 10:33         ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:22 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 12:03:57 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 11:27 AM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > Technologies, Inc.
> > >
> > > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > Peripherals:
> > >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > >  - RTC clock (PCF8563)
> > >  - USB 3.0 port
> > >  - USB 2.0 port
> > >  - 4x LED
> > >  - UART over Micro-USB
> > >  - M.2 slot (2280)
> > >  - Mini PCI-E slot
> > >
> > > Additionally, automatic import of the Marvell hw_info parameters is
> > > enabled via the recently added mac command for A37XX platforms.
> > > The parameters stored in Marvell hw_info are usually the board serial
> > > number and MAC addresses.
> > >
> > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > ---
> > >  arch/arm/dts/Makefile                         |   1 +
> > >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > >  7 files changed, 514 insertions(+), 203 deletions(-)
> > >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > ...
> > > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > > index 2de9c2ac17..21c1eb7b22 100644
> > > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > > @@ -11,6 +11,7 @@
> > >  #include <i2c.h>
> > >  #include <init.h>
> > >  #include <mmc.h>
> > > +#include <miiphy.h>
> > >  #include <phy.h>
> > >  #include <asm/global_data.h>
> > >  #include <asm/io.h>
> > > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > >
> > > +/* Marvell 88E1512 */
> > > +#define MII_MARVELL_PHY_PAGE         22
> > > +
> > > +#define MV88E1512_GENERAL_CTRL               20
> > > +#define MV88E1512_MODE_SGMII         1
> > > +#define MV88E1512_RESET_OFFS         15
> > > +
> > > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > > +
> > >  /*
> > >   * Memory Controller Registers
> > >   *
> > > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > >       return 0;
> > >  }
> > >
> > > -/* Bring-up board-specific network stuff */
> > > -int board_network_enable(struct mii_dev *bus)
> > > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > >  {
> > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > -             return 0;
> > > +     const char *name;
> > > +     u16 reg;
> > > +
> > > +     name = miiphy_get_current_dev();
> > > +     if (name) {
> >
> > It is possible that phy is not available? As you are calling code below
> > only in case name is not-NULL.
> 
> Well, according to common/miiphyutil.c, it could also happen that it's NULL.

I see. But if it happens, is not it fatal error for this board? If name
is NULL then you cannot correctly configure board correctly, right?

> >
> > > +             /* SGMII-to-Copper mode initialization */
> > > +
> > > +             /* Select page 18 */
> > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > +             reg &= ~0x7;
> > > +             reg |= MV88E1512_MODE_SGMII;
> > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > +             /* PHY reset is necessary after changing MODE[2:0] */
> > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > +             /* Reset page selection */
> > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > > +             udelay(100);
> > > +     }
> > > +}
> > > +
> > > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > > +{
> > > +     int i;
> > > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > >
> > > +     /*
> > > +      * FIXME: remove this code once Topaz driver gets available
> > > +      * A3720 ESPRESSObin Ultra Board Only
> > > +      * Configure Topaz switch (88E6341)
> > > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > > +      */
> > > +     for (i = 0; i <= 5; i++) {
> > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > > +                                       MVEBU_SW_PORT_CTRL_REG,
> > > +                                       i == 5 ? 0x7c : 0x7f);
> >
> > Why port 5 has different settings?
> 
> It's to disable forwarding between the WAN port and LAN ports (I've
> tested this).
> I'm aware of this thread:
> https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18

Ok. But your change seems to not be correct. I'm looking at
documentation and when low 2 bits in Port Control Register are zero then
specified port is completely disabled.

I agree that for disabled port is obviously disabled also forwarding.
But I do not think it is what you want... Or, which behavior you want to
achieve? From above added comment (which seems to be also copy+paste) it
is not clear.

Look at that my change which only disables forwarding between ports. And
does not disable ports itself. It is already in newly renamed function
board_network_enable_espressobin(). That is why I do not like copy+paste
of code as it can be copied incorrectly, or differently without
describing commenting why it is differently.

I see that board_network_enable_espressobin_ultra() and
board_network_enable_espressobin() are different. But they have some
common parts, e.g. this port policy configuration. So at least this code
path can be moved in some common function.

> >
> > > +     }
> > > +
> > > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > > +
> > > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > > +     for (i = 1; i <= 5; i++) {
> > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > > +     }
> >
> > It looks like that by copying board_network_enable_espressobin_ultra()
> > function from Marvell U-Boot instead of using code which is in mainline
> > function board_network_enable() for Espressobin, you are introducing a
> > security hole, which is in Marvell U-Boot and which was fixed in
> > mainline U-Boot for all supported Espressobin boards (see commit
> > 48f2c8a37f700859a7004dce5adb116597a45700).
> >
> > I would really suggest to not blindly copy old code from Marvell into
> > mainline U-Boot, as here we have fixed lot of issues.
> >
> > > +     return 0;
> > > +}
> > > +
> > > +int board_network_enable_espressobin(struct mii_dev *bus)
> > > +{
> > >       /*
> > >        * FIXME: remove this code once Topaz driver gets available
> > >        * A3720 Community Board Only
> > > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > >       return 0;
> > >  }
> > >
> > > +/* Bring-up the board-specific networking */
> > > +int board_network_enable(struct mii_dev *bus)
> > > +{
> > > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > > +             return board_network_enable_espressobin(bus);
> > > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > +             return board_network_enable_espressobin_ultra(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)
> > >  {
> > > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > >       int parts_off;
> > >       int part_off;
> > >
> > > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > +     /*
> > > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > > +      * ESPRESSOBin Ultra boards.
> > > +      */
> > > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > >               return 0;
> >
> > According to kernel DTS file, it looks like that Espressobin Ultra has
> > different MTD partitions as other variants... Therefore Ultra needs
> > adjustments in this code.
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78
> 
> That's true, I'll have to fix this.

It is needed to call this function for ultra variant at all? Because as
I understand ultra variant has fixed layout as specified in kernel DTS
file and therefore it should not have any dynamic modification.

Or is there any other issue?

> >
> > >
> > >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13  9:58         ` Stefan Roese
@ 2021-08-13 10:25           ` Luka Kovacic
  2021-08-13 10:46             ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13 10:25 UTC (permalink / raw)
  To: Stefan Roese, Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, sjg,
	patrick.delaunay, xypron.glpk

Hello Stefan and Pali,

On Fri, Aug 13, 2021 at 11:58 AM Stefan Roese <sr@denx.de> wrote:
>
> Hi,
>
> On 13.08.21 11:54, Pali Rohár wrote:
> > On Friday 13 August 2021 11:08:08 Luka Kovacic wrote:
> >> Hello Pali,
> >>
> >> On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
> >>>
> >>> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> >>>> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> >>>> Technologies, Inc.
> >>>>
> >>>> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> >>>> Peripherals:
> >>>>   - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> >>>>   - RTC clock (PCF8563)
> >>>>   - USB 3.0 port
> >>>>   - USB 2.0 port
> >>>>   - 4x LED
> >>>>   - UART over Micro-USB
> >>>>   - M.2 slot (2280)
> >>>>   - Mini PCI-E slot
> >>>>
> >>>> Additionally, automatic import of the Marvell hw_info parameters is
> >>>> enabled via the recently added mac command for A37XX platforms.
> >>>> The parameters stored in Marvell hw_info are usually the board serial
> >>>> number and MAC addresses.
> >>>>
> >>>> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> >>>> Cc: Luka Perkov <luka.perkov@sartura.hr>
> >>>> Cc: Robert Marko <robert.marko@sartura.hr>
> >>>> ---
> >>>>   arch/arm/dts/Makefile                         |   1 +
> >>>>   .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> >>>>   arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> >>>>   arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> >>>>   board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> >>>>   board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> >>>>   .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> >>>>   7 files changed, 514 insertions(+), 203 deletions(-)
> >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> >>>>   create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> >>>
> >>> Hello Luka! Please look at my comments from previous review:
> >>> https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
> >>>
> >>> I think it is not a good idea to duplicate espressobin code, specially
> >>> now when differences between v5, v7, non-emmc and emmc were
> >>> de-duplicated and correctly detected at runtime. Just use one DTS and
> >>> one config file and differences can be handled in board code functions
> >>> "board_fix_fdt" and "board_late_init".
> >>
> >> I believe that patching the DTS at runtime diminishes the value of
> >> device trees in the first case.
> >>
> >> As far as the v5, v7, non-emmc and emmc boards go I do understand
> >> that, as they are physically similar and more or less different revisions
> >> of the same board.
> >>
> >> The ESPRESSOBin Ultra board is completely different from those boards
> >> physically and so I doesn't make sense to me, why we would merge all
> >> of them into one device tree.
> >
> > See email for reasons:
> > https://lore.kernel.org/u-boot/20210301154101.ke5j2r3lazjlxrsl@pali/
> >
> > Anyway, I'm looking at differences between ultra and non-ultra boards
> > which are used by U-Boot... And I see only:
> > * switch configuration & phy
> > * i2c rtc
> > * sdhci slot
> >
> > Other changes are not used by U-Boot (led).
> >
> > For switch configuration & phy there is already custom code in U-Boot
> > board file. For sdhci slot there is also (to enable/disable eMMC after
> > detection).
> >
> > So the only difference is presence of i2c rtc, right?
> >
> > I guess it does not make much sense to copy and duplicate whole DTS and
> > also defconfig file for such small differences. Insertion of just few
> > nodes is not a big problem.
> >
> > These boars are not very different, and having tons of u-boot binaries
> > for every combination just complicate it as explained in above email.
>
> I fully agree with Pali. It's much more conveniant to just have one
> U-Boot target (and binary) which can handle multiple board variants
> by runtime detection. I would very much welcome to see the support for
> the "Ultra" variant added this way.

I understand your points and concerns.

I'm just worried that this counterproductive as I don't see the same thing
happening in Linux and looking at this we could make similar arguments
for other boards, which aren't so different from the ESPRESSOBin boards
with the exception of the name.

>
> > If you need help with this I can try to do something... as I was already
> > involved in unification of all v5/v7/emmc/non-emmc variants into one
> > binary with one DTS.
>
> Thanks Pali for all your work here.
>
> Thanks,
> Stefan
>
> >> I resorted to the Linux way and used a common dtsi for both the
> >> ESPRESSOBin - which is the base and the ESPRESSOBin-Ultra.
> >>
> >>>
> >>>> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> >>>> index c42715ead4..f21c9c94d3 100644
> >>>> --- a/arch/arm/dts/Makefile
> >>>> +++ b/arch/arm/dts/Makefile
> >>>> @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
> >>>>   dtb-$(CONFIG_ARCH_MVEBU) +=                  \
> >>>>        armada-3720-db.dtb                      \
> >>>>        armada-3720-espressobin.dtb             \
> >>>> +     armada-3720-espressobin-ultra.dtb       \
> >>>>        armada-3720-turris-mox.dtb              \
> >>>>        armada-3720-uDPU.dtb                    \
> >>>>        armada-375-db.dtb                       \
> >>>> diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> >>>> new file mode 100644
> >>>> index 0000000000..5ad0c723e3
> >>>> --- /dev/null
> >>>> +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> >>>> @@ -0,0 +1,114 @@
> >>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> >>>> +/*
> >>>> + * Device Tree file for ESPRESSObin-Ultra board
> >>>> + * Copyright (C) 2016 Marvell
> >>>> + * Copyright (C) 2019 Globalscale technologies, Inc.
> >>>> + * Copyright (C) 2021 Sartura Ltd.
> >>>> + *
> >>>> + * Author: Jason Hung <jhung@globalscaletechnologies.com>
> >>>> + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> >>>> + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
> >>>> + */
> >>>> +
> >>>> +/dts-v1/;
> >>>> +
> >>>> +#include "armada-3720-espressobin.dtsi"
> >>>> +
> >>>> +/ {
> >>>> +     model = "Globalscale Marvell ESPRESSOBin Ultra Board";
> >>>> +     compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
> >>>> +
> >>>> +     gpio-leds {
> >>>> +             pinctrl-names = "default";
> >>>> +             pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
> >>>> +             compatible = "gpio-leds";
> >>>> +
> >>>> +             led1 {
> >>>> +                     label = "led1";
> >>>> +                     gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
> >>>> +                     default-state = "on";
> >>>> +             };
> >>>> +             led2 {
> >>>> +                     label = "led2";
> >>>> +                     gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
> >>>> +                     default-state = "on";
> >>>> +             };
> >>>> +             led3 {
> >>>> +                     label = "led3";
> >>>> +                     gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
> >>>> +                     default-state = "on";
> >>>> +             };
> >>>> +             led4 {
> >>>> +                     label = "led4";
> >>>> +                     gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
> >>>> +                     default-state = "on";
> >>>> +             };
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&pinctrl_nb {
> >>>> +     led1_pins: led1-pins {
> >>>> +             groups = "pwm0";
> >>>> +             function = "gpio";
> >>>> +     };
> >>>> +     led2_pins: led2-pins {
> >>>> +             groups = "pwm1";
> >>>> +             function = "gpio";
> >>>> +     };
> >>>> +     led3_pins: led3-pins {
> >>>> +             groups = "pwm2";
> >>>> +             function = "gpio";
> >>>> +     };
> >>>> +     led4_pins: led4-pins {
> >>>> +             groups = "pwm3";
> >>>> +             function = "gpio";
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&eth0 {
> >>>> +     status = "okay";
> >>>> +     phy_addr = <0x3>;
> >>>> +};
> >>>> +
> >>>> +&i2c0 {
> >>>> +     status = "okay";
> >>>> +     #address-cells = <1>;
> >>>> +     #size-cells = <0>;
> >>>> +     rtc@51 {
> >>>> +             compatible = "nxp,pcf8563";
> >>>> +             reg = <0x51>;
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&sata {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&sdhci0 {
> >>>> +     status = "disabled";
> >>>> +};
> >>>> +
> >>>> +&sdhci1 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&spi0 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +/* Exported on the micro USB connector through an FTDI */
> >>>> +&uart0 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&usb2 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&usb3 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&pcie0 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
> >>>> index cba6139be6..925ce6a38e 100644
> >>>> --- a/arch/arm/dts/armada-3720-espressobin.dts
> >>>> +++ b/arch/arm/dts/armada-3720-espressobin.dts
> >>>> @@ -1,210 +1,15 @@
> >>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> >>>>   /*
> >>>>    * Device Tree file for Marvell Armada 3720 community board
> >>>>    * (ESPRESSOBin)
> >>>>    * Copyright (C) 2016 Marvell
> >>>> - *
> >>>> - * Gregory CLEMENT <gregory.clement@free-electrons.com>
> >>>> - * Konstantin Porotchkin <kostap@marvell.com>
> >>>> - *
> >>>> - * This file is dual-licensed: you can use it either under the terms
> >>>> - * of the GPL or the X11 license, at your option. Note that this dual
> >>>> - * licensing only applies to this file, and not this project as a
> >>>> - * whole.
> >>>> - *
> >>>> - *  a) This file is free software; you can redistribute it and/or
> >>>> - *     modify it under the terms of the GNU General Public License as
> >>>> - *     published by the Free Software Foundation; either version 2 of the
> >>>> - *     License, or (at your option) any later version.
> >>>> - *
> >>>> - *     This file is distributed in the hope that it will be useful
> >>>> - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> >>>> - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >>>> - *     GNU General Public License for more details.
> >>>> - *
> >>>> - * Or, alternatively
> >>>> - *
> >>>> - *  b) Permission is hereby granted, free of charge, to any person
> >>>> - *     obtaining a copy of this software and associated documentation
> >>>> - *     files (the "Software"), to deal in the Software without
> >>>> - *     restriction, including without limitation the rights to use
> >>>> - *     copy, modify, merge, publish, distribute, sublicense, and/or
> >>>> - *     sell copies of the Software, and to permit persons to whom the
> >>>> - *     Software is furnished to do so, subject to the following
> >>>> - *     conditions:
> >>>> - *
> >>>> - *     The above copyright notice and this permission notice shall be
> >>>> - *     included in all copies or substantial portions of the Software.
> >>>> - *
> >>>> - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> >>>> - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> >>>> - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> >>>> - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> >>>> - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> >>>> - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> >>>> - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> >>>> - *     OTHER DEALINGS IN THE SOFTWARE.
> >>>>    */
> >>>>
> >>>>   /dts-v1/;
> >>>>
> >>>> -#include "armada-372x.dtsi"
> >>>> +#include "armada-3720-espressobin.dtsi"
> >>>>
> >>>>   / {
> >>>>        model = "Globalscale Marvell ESPRESSOBin Board";
> >>>>        compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> >>>> -
> >>>> -     chosen {
> >>>> -             stdout-path = "serial0:115200n8";
> >>>> -     };
> >>>> -
> >>>> -     aliases {
> >>>> -             ethernet0 = &eth0;
> >>>> -             i2c0 = &i2c0;
> >>>> -             spi0 = &spi0;
> >>>> -     };
> >>>> -
> >>>> -     memory {
> >>>> -             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 {
> >>>> -     max-lanes = <3>;
> >>>> -     phy0 {
> >>>> -             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> >>>> -             phy-speed = <COMPHY_SPEED_5G>;
> >>>> -     };
> >>>> -
> >>>> -     phy1 {
> >>>> -             phy-type = <COMPHY_TYPE_PEX0>;
> >>>> -             phy-speed = <COMPHY_SPEED_2_5G>;
> >>>> -     };
> >>>> -
> >>>> -     phy2 {
> >>>> -             phy-type = <COMPHY_TYPE_SATA0>;
> >>>> -             phy-speed = <COMPHY_SPEED_5G>;
> >>>> -     };
> >>>> -};
> >>>> -
> >>>> -&eth0 {
> >>>> -     status = "okay";
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> >>>> -     phy-mode = "rgmii";
> >>>> -     phy_addr = <0x1>;
> >>>> -     fixed-link {
> >>>> -             speed = <1000>;
> >>>> -             full-duplex;
> >>>> -     };
> >>>> -};
> >>>> -
> >>>> -&i2c0 {
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&i2c1_pins>;
> >>>> -     status = "okay";
> >>>> -};
> >>>> -
> >>>> -/* CON3 */
> >>>> -&sata {
> >>>> -     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";
> >>>> -};
> >>>> -
> >>>> -/* U11 */
> >>>> -&sdhci1 {
> >>>> -     non-removable;
> >>>> -     bus-width = <8>;
> >>>> -     mmc-ddr-1_8v;
> >>>> -     mmc-hs400-1_8v;
> >>>> -     marvell,xenon-emmc;
> >>>> -     marvell,xenon-tun-count = <9>;
> >>>> -     marvell,pad-type = "fixed-1-8v";
> >>>> -
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&mmc_pins>;
> >>>> -     status = "okay";
> >>>> -
> >>>> -     #address-cells = <1>;
> >>>> -     #size-cells = <0>;
> >>>> -     mmccard: mmccard@0 {
> >>>> -             compatible = "mmc-card";
> >>>> -             reg = <0>;
> >>>> -     };
> >>>> -};
> >>>> -
> >>>> -&spi0 {
> >>>> -     status = "okay";
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&spi_quad_pins>;
> >>>> -
> >>>> -     spi-flash@0 {
> >>>> -             #address-cells = <1>;
> >>>> -             #size-cells = <1>;
> >>>> -             compatible = "st,m25p128", "jedec,spi-nor";
> >>>> -             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> >>>> -                             label = "u-boot-env";
> >>>> -                     };
> >>>> -             };
> >>>> -#endif
> >>>> -     };
> >>>> -};
> >>>> -
> >>>> -/* Exported on the micro USB connector CON32 through an FTDI */
> >>>> -&uart0 {
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&uart1_pins>;
> >>>> -     status = "okay";
> >>>> -};
> >>>> -
> >>>> -/* CON29 */
> >>>> -&usb2 {
> >>>> -     status = "okay";
> >>>> -};
> >>>> -
> >>>> -/* CON31 */
> >>>> -&usb3 {
> >>>> -     status = "okay";
> >>>> -};
> >>>> -
> >>>> -&pcie0 {
> >>>> -     pinctrl-names = "default";
> >>>> -     pinctrl-0 = <&pcie_pins>;
> >>>> -     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> >>>> -     status = "okay";
> >>>>   };
> >>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
> >>>> new file mode 100644
> >>>> index 0000000000..cba6139be6
> >>>> --- /dev/null
> >>>> +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
> >>>> @@ -0,0 +1,210 @@
> >>>> +/*
> >>>> + * Device Tree file for Marvell Armada 3720 community board
> >>>> + * (ESPRESSOBin)
> >>>> + * Copyright (C) 2016 Marvell
> >>>> + *
> >>>> + * Gregory CLEMENT <gregory.clement@free-electrons.com>
> >>>> + * Konstantin Porotchkin <kostap@marvell.com>
> >>>> + *
> >>>> + * This file is dual-licensed: you can use it either under the terms
> >>>> + * of the GPL or the X11 license, at your option. Note that this dual
> >>>> + * licensing only applies to this file, and not this project as a
> >>>> + * whole.
> >>>> + *
> >>>> + *  a) This file is free software; you can redistribute it and/or
> >>>> + *     modify it under the terms of the GNU General Public License as
> >>>> + *     published by the Free Software Foundation; either version 2 of the
> >>>> + *     License, or (at your option) any later version.
> >>>> + *
> >>>> + *     This file is distributed in the hope that it will be useful
> >>>> + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> >>>> + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >>>> + *     GNU General Public License for more details.
> >>>> + *
> >>>> + * Or, alternatively
> >>>> + *
> >>>> + *  b) Permission is hereby granted, free of charge, to any person
> >>>> + *     obtaining a copy of this software and associated documentation
> >>>> + *     files (the "Software"), to deal in the Software without
> >>>> + *     restriction, including without limitation the rights to use
> >>>> + *     copy, modify, merge, publish, distribute, sublicense, and/or
> >>>> + *     sell copies of the Software, and to permit persons to whom the
> >>>> + *     Software is furnished to do so, subject to the following
> >>>> + *     conditions:
> >>>> + *
> >>>> + *     The above copyright notice and this permission notice shall be
> >>>> + *     included in all copies or substantial portions of the Software.
> >>>> + *
> >>>> + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> >>>> + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> >>>> + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> >>>> + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> >>>> + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> >>>> + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> >>>> + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> >>>> + *     OTHER DEALINGS IN THE SOFTWARE.
> >>>> + */
> >>>> +
> >>>> +/dts-v1/;
> >>>> +
> >>>> +#include "armada-372x.dtsi"
> >>>> +
> >>>> +/ {
> >>>> +     model = "Globalscale Marvell ESPRESSOBin Board";
> >>>> +     compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> >>>> +
> >>>> +     chosen {
> >>>> +             stdout-path = "serial0:115200n8";
> >>>> +     };
> >>>> +
> >>>> +     aliases {
> >>>> +             ethernet0 = &eth0;
> >>>> +             i2c0 = &i2c0;
> >>>> +             spi0 = &spi0;
> >>>> +     };
> >>>> +
> >>>> +     memory {
> >>>> +             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 {
> >>>> +     max-lanes = <3>;
> >>>> +     phy0 {
> >>>> +             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> >>>> +             phy-speed = <COMPHY_SPEED_5G>;
> >>>> +     };
> >>>> +
> >>>> +     phy1 {
> >>>> +             phy-type = <COMPHY_TYPE_PEX0>;
> >>>> +             phy-speed = <COMPHY_SPEED_2_5G>;
> >>>> +     };
> >>>> +
> >>>> +     phy2 {
> >>>> +             phy-type = <COMPHY_TYPE_SATA0>;
> >>>> +             phy-speed = <COMPHY_SPEED_5G>;
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&eth0 {
> >>>> +     status = "okay";
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> >>>> +     phy-mode = "rgmii";
> >>>> +     phy_addr = <0x1>;
> >>>> +     fixed-link {
> >>>> +             speed = <1000>;
> >>>> +             full-duplex;
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&i2c0 {
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&i2c1_pins>;
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +/* CON3 */
> >>>> +&sata {
> >>>> +     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";
> >>>> +};
> >>>> +
> >>>> +/* U11 */
> >>>> +&sdhci1 {
> >>>> +     non-removable;
> >>>> +     bus-width = <8>;
> >>>> +     mmc-ddr-1_8v;
> >>>> +     mmc-hs400-1_8v;
> >>>> +     marvell,xenon-emmc;
> >>>> +     marvell,xenon-tun-count = <9>;
> >>>> +     marvell,pad-type = "fixed-1-8v";
> >>>> +
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&mmc_pins>;
> >>>> +     status = "okay";
> >>>> +
> >>>> +     #address-cells = <1>;
> >>>> +     #size-cells = <0>;
> >>>> +     mmccard: mmccard@0 {
> >>>> +             compatible = "mmc-card";
> >>>> +             reg = <0>;
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +&spi0 {
> >>>> +     status = "okay";
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&spi_quad_pins>;
> >>>> +
> >>>> +     spi-flash@0 {
> >>>> +             #address-cells = <1>;
> >>>> +             #size-cells = <1>;
> >>>> +             compatible = "st,m25p128", "jedec,spi-nor";
> >>>> +             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> >>>> +                             label = "u-boot-env";
> >>>> +                     };
> >>>> +             };
> >>>> +#endif
> >>>> +     };
> >>>> +};
> >>>> +
> >>>> +/* Exported on the micro USB connector CON32 through an FTDI */
> >>>> +&uart0 {
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&uart1_pins>;
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +/* CON29 */
> >>>> +&usb2 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +/* CON31 */
> >>>> +&usb3 {
> >>>> +     status = "okay";
> >>>> +};
> >>>> +
> >>>> +&pcie0 {
> >>>> +     pinctrl-names = "default";
> >>>> +     pinctrl-0 = <&pcie_pins>;
> >>>> +     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> >>>> +     status = "okay";
> >>>> +};
> >>>> diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> >>>> index f2c0a582d7..d69af832fc 100644
> >>>> --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> >>>> +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> >>>> @@ -10,6 +10,14 @@ M: Konstantin Porotchkin <kostap@marvell.com>
> >>>>   S:   Maintained
> >>>>   F:   configs/mvebu_espressobin-88f3720_defconfig
> >>>>
> >>>> +ESPRESSOBin-Ultra BOARD
> >>>> +M:   Luka Kovacic <luka.kovacic@sartura.hr>
> >>>> +M:   Robert Marko <robert.marko@sartura.hr>
> >>>> +M:   Luka Perkov <luka.perkov@sartura.hr>
> >>>> +S:   Maintained
> >>>> +F:   arch/arm/dts/armada-3720-espressobin-ultra.dts
> >>>> +F:   configs/mvebu_espressobin-ultra-88f3720_defconfig
> >>>> +
> >>>>   uDPU BOARD
> >>>>   M:   Vladimir Vid <vladimir.vid@sartura.hr>
> >>>>   S:   Maintained
> >>>> diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> >>>> index 2de9c2ac17..21c1eb7b22 100644
> >>>> --- a/board/Marvell/mvebu_armada-37xx/board.c
> >>>> +++ b/board/Marvell/mvebu_armada-37xx/board.c
> >>>> @@ -11,6 +11,7 @@
> >>>>   #include <i2c.h>
> >>>>   #include <init.h>
> >>>>   #include <mmc.h>
> >>>> +#include <miiphy.h>
> >>>>   #include <phy.h>
> >>>>   #include <asm/global_data.h>
> >>>>   #include <asm/io.h>
> >>>> @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> >>>>   #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> >>>>   #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> >>>>
> >>>> +/* Marvell 88E1512 */
> >>>> +#define MII_MARVELL_PHY_PAGE         22
> >>>> +
> >>>> +#define MV88E1512_GENERAL_CTRL               20
> >>>> +#define MV88E1512_MODE_SGMII         1
> >>>> +#define MV88E1512_RESET_OFFS         15
> >>>> +
> >>>> +#define ULTRA_MV88E1512_PHYADDR              0x1
> >>>> +
> >>>>   /*
> >>>>    * Memory Controller Registers
> >>>>    *
> >>>> @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> >>>>        return 0;
> >>>>   }
> >>>>
> >>>> -/* Bring-up board-specific network stuff */
> >>>> -int board_network_enable(struct mii_dev *bus)
> >>>> +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> >>>>   {
> >>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
> >>>> -             return 0;
> >>>> +     const char *name;
> >>>> +     u16 reg;
> >>>> +
> >>>> +     name = miiphy_get_current_dev();
> >>>> +     if (name) {
> >>>> +             /* SGMII-to-Copper mode initialization */
> >>>> +
> >>>> +             /* Select page 18 */
> >>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> >>>> +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> >>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> >>>> +             reg &= ~0x7;
> >>>> +             reg |= MV88E1512_MODE_SGMII;
> >>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> >>>> +             /* PHY reset is necessary after changing MODE[2:0] */
> >>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> >>>> +             reg |= 1 << MV88E1512_RESET_OFFS;
> >>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> >>>> +             /* Reset page selection */
> >>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> >>>> +             udelay(100);
> >>>> +     }
> >>>> +}
> >>>> +
> >>>> +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> >>>> +{
> >>>> +     int i;
> >>>> +     /* Setup 88E1512 SGMII-to-Copper mode */
> >>>> +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> >>>>
> >>>> +     /*
> >>>> +      * FIXME: remove this code once Topaz driver gets available
> >>>> +      * A3720 ESPRESSObin Ultra Board Only
> >>>> +      * Configure Topaz switch (88E6341)
> >>>> +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> >>>> +      */
> >>>> +     for (i = 0; i <= 5; i++) {
> >>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> >>>> +                                       MVEBU_SW_PORT_CTRL_REG,
> >>>> +                                       i == 5 ? 0x7c : 0x7f);
> >>>> +     }
> >>>> +
> >>>> +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> >>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> >>>> +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> >>>> +
> >>>> +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> >>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> >>>> +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> >>>> +     for (i = 1; i <= 5; i++) {
> >>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> >>>> +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> >>>> +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> >>>> +     }
> >>>> +
> >>>> +     return 0;
> >>>> +}
> >>>> +
> >>>> +int board_network_enable_espressobin(struct mii_dev *bus)
> >>>> +{
> >>>>        /*
> >>>>         * FIXME: remove this code once Topaz driver gets available
> >>>>         * A3720 Community Board Only
> >>>> @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> >>>>        return 0;
> >>>>   }
> >>>>
> >>>> +/* Bring-up the board-specific networking */
> >>>> +int board_network_enable(struct mii_dev *bus)
> >>>> +{
> >>>> +     if (of_machine_is_compatible("globalscale,espressobin"))
> >>>> +             return board_network_enable_espressobin(bus);
> >>>> +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> >>>> +             return board_network_enable_espressobin_ultra(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)
> >>>>   {
> >>>> @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> >>>>        int parts_off;
> >>>>        int part_off;
> >>>>
> >>>> -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> >>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
> >>>> +     /*
> >>>> +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> >>>> +      * ESPRESSOBin Ultra boards.
> >>>> +      */
> >>>> +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> >>>> +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> >>>>                return 0;
> >>>>
> >>>>        spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> >>>> diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> >>>> new file mode 100644
> >>>> index 0000000000..1bac0a96ad
> >>>> --- /dev/null
> >>>> +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> >>>> @@ -0,0 +1,93 @@
> >>>> +CONFIG_ARM=y
> >>>> +CONFIG_ARCH_CPU_INIT=y
> >>>> +CONFIG_ARCH_MVEBU=y
> >>>> +CONFIG_SYS_TEXT_BASE=0x00000000
> >>>> +CONFIG_SYS_MALLOC_F_LEN=0x2000
> >>>> +CONFIG_NR_DRAM_BANKS=1
> >>>> +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
> >>>> +CONFIG_ENV_SIZE=0x10000
> >>>> +CONFIG_ENV_OFFSET=0x3F0000
> >>>> +CONFIG_ENV_SECT_SIZE=0x10000
> >>>> +CONFIG_DM_GPIO=y
> >>>> +CONFIG_DEBUG_UART_BASE=0xd0012000
> >>>> +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
> >>>> +CONFIG_DEBUG_UART=y
> >>>> +CONFIG_AHCI=y
> >>>> +CONFIG_DISTRO_DEFAULTS=y
> >>>> +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> >>>> +CONFIG_OF_BOARD_SETUP=y
> >>>> +CONFIG_FIT=y
> >>>> +CONFIG_FIT_VERBOSE=y
> >>>> +CONFIG_FIT_BEST_MATCH=y
> >>>> +CONFIG_AUTOBOOT_KEYED=y
> >>>> +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
> >>>> +CONFIG_AUTOBOOT_STOP_STR="s"
> >>>> +CONFIG_AUTOBOOT_KEYED_CTRLC=y
> >>>> +CONFIG_HUSH_PARSER=y
> >>>> +CONFIG_SYS_CONSOLE_INFO_QUIET=y
> >>>> +# CONFIG_DISPLAY_CPUINFO is not set
> >>>> +# CONFIG_DISPLAY_BOARDINFO is not set
> >>>> +CONFIG_DISPLAY_BOARDINFO_LATE=y
> >>>> +CONFIG_ARCH_EARLY_INIT_R=y
> >>>> +CONFIG_BOARD_EARLY_INIT_F=y
> >>>> +CONFIG_BOARD_LATE_INIT=y
> >>>> +# CONFIG_CMD_FLASH is not set
> >>>> +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
> >>>> +CONFIG_CMD_WDT=y
> >>>> +# CONFIG_CMD_SETEXPR is not set
> >>>> +CONFIG_CMD_TFTPPUT=y
> >>>> +CONFIG_CMD_CACHE=y
> >>>> +CONFIG_CMD_TIME=y
> >>>> +CONFIG_CMD_MVEBU_BUBT=y
> >>>> +CONFIG_MVEBU_MAC_HW_INFO=y
> >>>> +CONFIG_CMD_EXT4_WRITE=y
> >>>> +CONFIG_MAC_PARTITION=y
> >>>> +CONFIG_ENV_OVERWRITE=y
> >>>> +CONFIG_ENV_IS_IN_SPI_FLASH=y
> >>>> +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> >>>> +CONFIG_NET_RANDOM_ETHADDR=y
> >>>> +CONFIG_AHCI_MVEBU=y
> >>>> +CONFIG_CLK=y
> >>>> +CONFIG_CLK_MVEBU=y
> >>>> +CONFIG_DM_I2C=y
> >>>> +CONFIG_MISC=y
> >>>> +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_SPI_FLASH_MACRONIX=y
> >>>> +CONFIG_SPI_FLASH_MTD=y
> >>>> +CONFIG_PHY_MARVELL=y
> >>>> +CONFIG_PHY_GIGE=y
> >>>> +CONFIG_MVNETA=y
> >>>> +CONFIG_PCI=y
> >>>> +CONFIG_PCI_AARDVARK=y
> >>>> +CONFIG_PHY=y
> >>>> +CONFIG_MVEBU_COMPHY_SUPPORT=y
> >>>> +CONFIG_PINCTRL=y
> >>>> +CONFIG_PINCTRL_ARMADA_37XX=y
> >>>> +CONFIG_DM_REGULATOR_GPIO=y
> >>>> +CONFIG_DEBUG_UART_SHIFT=2
> >>>> +CONFIG_DEBUG_UART_ANNOUNCE=y
> >>>> +CONFIG_MVEBU_A3700_UART=y
> >>>> +CONFIG_MVEBU_A3700_SPI=y
> >>>> +CONFIG_USB=y
> >>>> +CONFIG_USB_XHCI_HCD=y
> >>>> +CONFIG_USB_EHCI_HCD=y
> >>>> +CONFIG_USB_HOST_ETHER=y
> >>>> +# CONFIG_WATCHDOG_AUTOSTART is not set
> >>>> +CONFIG_WDT=y
> >>>> +CONFIG_WDT_ARMADA_37XX=y
> >>>> +CONFIG_SHA1=y
> >>>> +CONFIG_DM_RTC=y
> >>>> +CONFIG_RTC_PCF8563=y
> >>>> +CONFIG_LED=y
> >>>> +CONFIG_LED_GPIO=y
> >>>> --
> >>>> 2.31.1
> >>>>
> >>
> >> Kind regards,
> >> Luka
>
>
> Viele Grüße,
> Stefan
>
> --
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
  2021-08-13  1:43   ` Marek Behún
  2021-08-13  8:23   ` Pali Rohár
@ 2021-08-13 10:29   ` Pali Rohár
  2021-08-13 10:43     ` Luka Kovacic
  2 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:29 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> new file mode 100644
> index 0000000000..b84dd20023
> --- /dev/null
> +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> @@ -0,0 +1,29 @@
> +menu "Marvell Armada 37xx configuration"
> +depends on TARGET_MVEBU_ARMADA_37XX
> +
> +config MVEBU_MAC_HW_INFO
> +	bool "Marvell hw_info (mac) support"
> +	depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> +	default n
> +	help
> +	  Enable loading of the Marvell hw_info parameters from the
> +	  SPI flash hw_info area. Parameters (usually the board serial
> +	  number and MAC addresses) are then imported into the
> +	  existing U-Boot environment.
> +	  Implementation of this command is compatible with the
> +	  original Marvell U-Boot command. Reading and writing is
> +	  supported.
> +	  EEPROM config pattern and checksum aren't supported.
> +	  After enabled, these parameters are managed from the common
> +	  U-Boot mac command.
> +
> +config MVEBU_MAC_HW_INFO_OFFSET
> +	hex "Marvell hw_info (mac) SPI flash offset"
> +	depends on MVEBU_MAC_HW_INFO
> +	default 0x3E0000
> +	help
> +	  This option defines the SPI flash offset of the Marvell
> +	  hw_info area. This defaults to 0x3E0000 on most Armada
> +	  A3720 platforms.

Just a question, cannot we load this offset from DTS? In DTS are already
specified SPI partitions, so this could eliminate need for defining this
offset at two places. But I really do not know at which time is this
code called, if DTB is available at this time or not.

> +endmenu

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:22       ` Pali Rohár
@ 2021-08-13 10:33         ` Luka Kovacic
  2021-08-13 10:59           ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13 10:33 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

On Fri, Aug 13, 2021 at 12:22 PM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 12:03:57 Luka Kovacic wrote:
> > Hello Pali,
> >
> > On Fri, Aug 13, 2021 at 11:27 AM Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > > Technologies, Inc.
> > > >
> > > > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > > Peripherals:
> > > >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > > >  - RTC clock (PCF8563)
> > > >  - USB 3.0 port
> > > >  - USB 2.0 port
> > > >  - 4x LED
> > > >  - UART over Micro-USB
> > > >  - M.2 slot (2280)
> > > >  - Mini PCI-E slot
> > > >
> > > > Additionally, automatic import of the Marvell hw_info parameters is
> > > > enabled via the recently added mac command for A37XX platforms.
> > > > The parameters stored in Marvell hw_info are usually the board serial
> > > > number and MAC addresses.
> > > >
> > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > ---
> > > >  arch/arm/dts/Makefile                         |   1 +
> > > >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > > >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > > >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > > >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > > >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > > >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > > >  7 files changed, 514 insertions(+), 203 deletions(-)
> > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > > >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > ...
> > > > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > > > index 2de9c2ac17..21c1eb7b22 100644
> > > > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > > > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > > > @@ -11,6 +11,7 @@
> > > >  #include <i2c.h>
> > > >  #include <init.h>
> > > >  #include <mmc.h>
> > > > +#include <miiphy.h>
> > > >  #include <phy.h>
> > > >  #include <asm/global_data.h>
> > > >  #include <asm/io.h>
> > > > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > > >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > > >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > > >
> > > > +/* Marvell 88E1512 */
> > > > +#define MII_MARVELL_PHY_PAGE         22
> > > > +
> > > > +#define MV88E1512_GENERAL_CTRL               20
> > > > +#define MV88E1512_MODE_SGMII         1
> > > > +#define MV88E1512_RESET_OFFS         15
> > > > +
> > > > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > > > +
> > > >  /*
> > > >   * Memory Controller Registers
> > > >   *
> > > > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > > >       return 0;
> > > >  }
> > > >
> > > > -/* Bring-up board-specific network stuff */
> > > > -int board_network_enable(struct mii_dev *bus)
> > > > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > > >  {
> > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > -             return 0;
> > > > +     const char *name;
> > > > +     u16 reg;
> > > > +
> > > > +     name = miiphy_get_current_dev();
> > > > +     if (name) {
> > >
> > > It is possible that phy is not available? As you are calling code below
> > > only in case name is not-NULL.
> >
> > Well, according to common/miiphyutil.c, it could also happen that it's NULL.
>
> I see. But if it happens, is not it fatal error for this board? If name
> is NULL then you cannot correctly configure board correctly, right?
>
> > >
> > > > +             /* SGMII-to-Copper mode initialization */
> > > > +
> > > > +             /* Select page 18 */
> > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > > > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > +             reg &= ~0x7;
> > > > +             reg |= MV88E1512_MODE_SGMII;
> > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > +             /* PHY reset is necessary after changing MODE[2:0] */
> > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > +             /* Reset page selection */
> > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > > > +             udelay(100);
> > > > +     }
> > > > +}
> > > > +
> > > > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > > > +{
> > > > +     int i;
> > > > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > > > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > > >
> > > > +     /*
> > > > +      * FIXME: remove this code once Topaz driver gets available
> > > > +      * A3720 ESPRESSObin Ultra Board Only
> > > > +      * Configure Topaz switch (88E6341)
> > > > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > > > +      */
> > > > +     for (i = 0; i <= 5; i++) {
> > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > > > +                                       MVEBU_SW_PORT_CTRL_REG,
> > > > +                                       i == 5 ? 0x7c : 0x7f);
> > >
> > > Why port 5 has different settings?
> >
> > It's to disable forwarding between the WAN port and LAN ports (I've
> > tested this).
> > I'm aware of this thread:
> > https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18
>
> Ok. But your change seems to not be correct. I'm looking at
> documentation and when low 2 bits in Port Control Register are zero then
> specified port is completely disabled.
>
> I agree that for disabled port is obviously disabled also forwarding.
> But I do not think it is what you want... Or, which behavior you want to
> achieve? From above added comment (which seems to be also copy+paste) it
> is not clear.
>

I think it would be completely fine if the WAN port is disabled in U-Boot.
The current behaviour is that the LAN ports forward between each other and
are all accessible from U-Boot, while the WAN port is in no way accessible.
The link is up when testing the WAN port, but no traffic passes.

> Look at that my change which only disables forwarding between ports. And
> does not disable ports itself. It is already in newly renamed function
> board_network_enable_espressobin(). That is why I do not like copy+paste
> of code as it can be copied incorrectly, or differently without
> describing commenting why it is differently.
>
> I see that board_network_enable_espressobin_ultra() and
> board_network_enable_espressobin() are different. But they have some
> common parts, e.g. this port policy configuration. So at least this code
> path can be moved in some common function.

I agree, these could be somehow unified. I will take a look.

>
> > >
> > > > +     }
> > > > +
> > > > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > > > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > > > +
> > > > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > > > +     for (i = 1; i <= 5; i++) {
> > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > > > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > > > +     }
> > >
> > > It looks like that by copying board_network_enable_espressobin_ultra()
> > > function from Marvell U-Boot instead of using code which is in mainline
> > > function board_network_enable() for Espressobin, you are introducing a
> > > security hole, which is in Marvell U-Boot and which was fixed in
> > > mainline U-Boot for all supported Espressobin boards (see commit
> > > 48f2c8a37f700859a7004dce5adb116597a45700).
> > >
> > > I would really suggest to not blindly copy old code from Marvell into
> > > mainline U-Boot, as here we have fixed lot of issues.
> > >
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +int board_network_enable_espressobin(struct mii_dev *bus)
> > > > +{
> > > >       /*
> > > >        * FIXME: remove this code once Topaz driver gets available
> > > >        * A3720 Community Board Only
> > > > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > > >       return 0;
> > > >  }
> > > >
> > > > +/* Bring-up the board-specific networking */
> > > > +int board_network_enable(struct mii_dev *bus)
> > > > +{
> > > > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > > > +             return board_network_enable_espressobin(bus);
> > > > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > > +             return board_network_enable_espressobin_ultra(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)
> > > >  {
> > > > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > > >       int parts_off;
> > > >       int part_off;
> > > >
> > > > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > +     /*
> > > > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > > > +      * ESPRESSOBin Ultra boards.
> > > > +      */
> > > > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > > > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > >               return 0;
> > >
> > > According to kernel DTS file, it looks like that Espressobin Ultra has
> > > different MTD partitions as other variants... Therefore Ultra needs
> > > adjustments in this code.
> > >
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78
> >
> > That's true, I'll have to fix this.
>
> It is needed to call this function for ultra variant at all? Because as
> I understand ultra variant has fixed layout as specified in kernel DTS
> file and therefore it should not have any dynamic modification.
>
> Or is there any other issue?

If the ports aren't correctly configured in U-Boot, Linux fails to configure the
Topaz switch.
In the current configuration traffic between LAN and WAN is blocked in U-Boot
and Linux correctly configures the Topaz switch.

>
> > >
> > > >
> > > >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> >
> > Kind regards,
> > Luka

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13 10:29   ` Pali Rohár
@ 2021-08-13 10:43     ` Luka Kovacic
  2021-08-13 10:49       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-13 10:43 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

On Fri, Aug 13, 2021 at 12:29 PM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > new file mode 100644
> > index 0000000000..b84dd20023
> > --- /dev/null
> > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > @@ -0,0 +1,29 @@
> > +menu "Marvell Armada 37xx configuration"
> > +depends on TARGET_MVEBU_ARMADA_37XX
> > +
> > +config MVEBU_MAC_HW_INFO
> > +     bool "Marvell hw_info (mac) support"
> > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > +     default n
> > +     help
> > +       Enable loading of the Marvell hw_info parameters from the
> > +       SPI flash hw_info area. Parameters (usually the board serial
> > +       number and MAC addresses) are then imported into the
> > +       existing U-Boot environment.
> > +       Implementation of this command is compatible with the
> > +       original Marvell U-Boot command. Reading and writing is
> > +       supported.
> > +       EEPROM config pattern and checksum aren't supported.
> > +       After enabled, these parameters are managed from the common
> > +       U-Boot mac command.
> > +
> > +config MVEBU_MAC_HW_INFO_OFFSET
> > +     hex "Marvell hw_info (mac) SPI flash offset"
> > +     depends on MVEBU_MAC_HW_INFO
> > +     default 0x3E0000
> > +     help
> > +       This option defines the SPI flash offset of the Marvell
> > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > +       A3720 platforms.
>
> Just a question, cannot we load this offset from DTS? In DTS are already
> specified SPI partitions, so this could eliminate need for defining this
> offset at two places. But I really do not know at which time is this
> code called, if DTB is available at this time or not.

The code is called right after cpu_secondary_init_r.
I'm not sure, there also some other values, which are hard-coded and
so far I didn't really see any other possible offset.

Are you aware of any other relevant board with the Marvell hw_info
parameters?

>
> > +endmenu

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:25           ` Luka Kovacic
@ 2021-08-13 10:46             ` Pali Rohár
  2021-09-24 18:30               ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:46 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: Stefan Roese, u-boot, Robert Marko, Luka Perkov, Marek Behun,
	sjg, patrick.delaunay, xypron.glpk

On Friday 13 August 2021 12:25:46 Luka Kovacic wrote:
> Hello Stefan and Pali,
> 
> On Fri, Aug 13, 2021 at 11:58 AM Stefan Roese <sr@denx.de> wrote:
> >
> > Hi,
> >
> > On 13.08.21 11:54, Pali Rohár wrote:
> > > On Friday 13 August 2021 11:08:08 Luka Kovacic wrote:
> > >> Hello Pali,
> > >>
> > >> On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
> > >>>
> > >>> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > >>>> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > >>>> Technologies, Inc.
> > >>>>
> > >>>> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > >>>> Peripherals:
> > >>>>   - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > >>>>   - RTC clock (PCF8563)
> > >>>>   - USB 3.0 port
> > >>>>   - USB 2.0 port
> > >>>>   - 4x LED
> > >>>>   - UART over Micro-USB
> > >>>>   - M.2 slot (2280)
> > >>>>   - Mini PCI-E slot
> > >>>>
> > >>>> Additionally, automatic import of the Marvell hw_info parameters is
> > >>>> enabled via the recently added mac command for A37XX platforms.
> > >>>> The parameters stored in Marvell hw_info are usually the board serial
> > >>>> number and MAC addresses.
> > >>>>
> > >>>> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > >>>> Cc: Luka Perkov <luka.perkov@sartura.hr>
> > >>>> Cc: Robert Marko <robert.marko@sartura.hr>
> > >>>> ---
> > >>>>   arch/arm/dts/Makefile                         |   1 +
> > >>>>   .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > >>>>   arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > >>>>   arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > >>>>   board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > >>>>   board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > >>>>   .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > >>>>   7 files changed, 514 insertions(+), 203 deletions(-)
> > >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > >>>>   create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > >>>
> > >>> Hello Luka! Please look at my comments from previous review:
> > >>> https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
> > >>>
> > >>> I think it is not a good idea to duplicate espressobin code, specially
> > >>> now when differences between v5, v7, non-emmc and emmc were
> > >>> de-duplicated and correctly detected at runtime. Just use one DTS and
> > >>> one config file and differences can be handled in board code functions
> > >>> "board_fix_fdt" and "board_late_init".
> > >>
> > >> I believe that patching the DTS at runtime diminishes the value of
> > >> device trees in the first case.
> > >>
> > >> As far as the v5, v7, non-emmc and emmc boards go I do understand
> > >> that, as they are physically similar and more or less different revisions
> > >> of the same board.
> > >>
> > >> The ESPRESSOBin Ultra board is completely different from those boards
> > >> physically and so I doesn't make sense to me, why we would merge all
> > >> of them into one device tree.
> > >
> > > See email for reasons:
> > > https://lore.kernel.org/u-boot/20210301154101.ke5j2r3lazjlxrsl@pali/
> > >
> > > Anyway, I'm looking at differences between ultra and non-ultra boards
> > > which are used by U-Boot... And I see only:
> > > * switch configuration & phy
> > > * i2c rtc
> > > * sdhci slot
> > >
> > > Other changes are not used by U-Boot (led).
> > >
> > > For switch configuration & phy there is already custom code in U-Boot
> > > board file. For sdhci slot there is also (to enable/disable eMMC after
> > > detection).
> > >
> > > So the only difference is presence of i2c rtc, right?
> > >
> > > I guess it does not make much sense to copy and duplicate whole DTS and
> > > also defconfig file for such small differences. Insertion of just few
> > > nodes is not a big problem.
> > >
> > > These boars are not very different, and having tons of u-boot binaries
> > > for every combination just complicate it as explained in above email.
> >
> > I fully agree with Pali. It's much more conveniant to just have one
> > U-Boot target (and binary) which can handle multiple board variants
> > by runtime detection. I would very much welcome to see the support for
> > the "Ultra" variant added this way.
> 
> I understand your points and concerns.
> 
> I'm just worried that this counterproductive as I don't see the same thing
> happening in Linux and looking at this we could make similar arguments
> for other boards, which aren't so different from the ESPRESSOBin boards
> with the exception of the name.

I have already opened this question also in Linux, but there was no feedback:
https://lore.kernel.org/linux-devicetree/20201022140007.hppmeyt34lubotbc@pali/t/#u

Anyway, as U-Boot can detect variant of the board, it also can load
specific DTS kernel file for detected variant. So it has still advantage
even when Linux does not use it (yet).

Also another argument is maintenance. This patch adds lot of lines of
code and lot of them are duplicated. It means that somebody has to
maintain it. So if Ultra variant can be supported by single binary too
it should mean less code in U-Boot for Ultra (but needs to check!!!) and
less code for maintaining.

> >
> > > If you need help with this I can try to do something... as I was already
> > > involved in unification of all v5/v7/emmc/non-emmc variants into one
> > > binary with one DTS.
> >
> > Thanks Pali for all your work here.
> >
> > Thanks,
> > Stefan
> >
> > >> I resorted to the Linux way and used a common dtsi for both the
> > >> ESPRESSOBin - which is the base and the ESPRESSOBin-Ultra.
> > >>
> > >>>
> > >>>> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > >>>> index c42715ead4..f21c9c94d3 100644
> > >>>> --- a/arch/arm/dts/Makefile
> > >>>> +++ b/arch/arm/dts/Makefile
> > >>>> @@ -213,6 +213,7 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
> > >>>>   dtb-$(CONFIG_ARCH_MVEBU) +=                  \
> > >>>>        armada-3720-db.dtb                      \
> > >>>>        armada-3720-espressobin.dtb             \
> > >>>> +     armada-3720-espressobin-ultra.dtb       \
> > >>>>        armada-3720-turris-mox.dtb              \
> > >>>>        armada-3720-uDPU.dtb                    \
> > >>>>        armada-375-db.dtb                       \
> > >>>> diff --git a/arch/arm/dts/armada-3720-espressobin-ultra.dts b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >>>> new file mode 100644
> > >>>> index 0000000000..5ad0c723e3
> > >>>> --- /dev/null
> > >>>> +++ b/arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >>>> @@ -0,0 +1,114 @@
> > >>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> > >>>> +/*
> > >>>> + * Device Tree file for ESPRESSObin-Ultra board
> > >>>> + * Copyright (C) 2016 Marvell
> > >>>> + * Copyright (C) 2019 Globalscale technologies, Inc.
> > >>>> + * Copyright (C) 2021 Sartura Ltd.
> > >>>> + *
> > >>>> + * Author: Jason Hung <jhung@globalscaletechnologies.com>
> > >>>> + * Author: Luka Kovacic <luka.kovacic@sartura.hr>
> > >>>> + * Author: Vladimir Vid <vladimir.vid@sartura.hr>
> > >>>> + */
> > >>>> +
> > >>>> +/dts-v1/;
> > >>>> +
> > >>>> +#include "armada-3720-espressobin.dtsi"
> > >>>> +
> > >>>> +/ {
> > >>>> +     model = "Globalscale Marvell ESPRESSOBin Ultra Board";
> > >>>> +     compatible = "globalscale,espressobin-ultra", "marvell,armada3720", "marvell,armada3710";
> > >>>> +
> > >>>> +     gpio-leds {
> > >>>> +             pinctrl-names = "default";
> > >>>> +             pinctrl-0 = <&led1_pins>, <&led2_pins>, <&led3_pins>, <&led4_pins>;
> > >>>> +             compatible = "gpio-leds";
> > >>>> +
> > >>>> +             led1 {
> > >>>> +                     label = "led1";
> > >>>> +                     gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
> > >>>> +                     default-state = "on";
> > >>>> +             };
> > >>>> +             led2 {
> > >>>> +                     label = "led2";
> > >>>> +                     gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
> > >>>> +                     default-state = "on";
> > >>>> +             };
> > >>>> +             led3 {
> > >>>> +                     label = "led3";
> > >>>> +                     gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
> > >>>> +                     default-state = "on";
> > >>>> +             };
> > >>>> +             led4 {
> > >>>> +                     label = "led4";
> > >>>> +                     gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
> > >>>> +                     default-state = "on";
> > >>>> +             };
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&pinctrl_nb {
> > >>>> +     led1_pins: led1-pins {
> > >>>> +             groups = "pwm0";
> > >>>> +             function = "gpio";
> > >>>> +     };
> > >>>> +     led2_pins: led2-pins {
> > >>>> +             groups = "pwm1";
> > >>>> +             function = "gpio";
> > >>>> +     };
> > >>>> +     led3_pins: led3-pins {
> > >>>> +             groups = "pwm2";
> > >>>> +             function = "gpio";
> > >>>> +     };
> > >>>> +     led4_pins: led4-pins {
> > >>>> +             groups = "pwm3";
> > >>>> +             function = "gpio";
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&eth0 {
> > >>>> +     status = "okay";
> > >>>> +     phy_addr = <0x3>;
> > >>>> +};
> > >>>> +
> > >>>> +&i2c0 {
> > >>>> +     status = "okay";
> > >>>> +     #address-cells = <1>;
> > >>>> +     #size-cells = <0>;
> > >>>> +     rtc@51 {
> > >>>> +             compatible = "nxp,pcf8563";
> > >>>> +             reg = <0x51>;
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&sata {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&sdhci0 {
> > >>>> +     status = "disabled";
> > >>>> +};
> > >>>> +
> > >>>> +&sdhci1 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&spi0 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +/* Exported on the micro USB connector through an FTDI */
> > >>>> +&uart0 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&usb2 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&usb3 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&pcie0 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts
> > >>>> index cba6139be6..925ce6a38e 100644
> > >>>> --- a/arch/arm/dts/armada-3720-espressobin.dts
> > >>>> +++ b/arch/arm/dts/armada-3720-espressobin.dts
> > >>>> @@ -1,210 +1,15 @@
> > >>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> > >>>>   /*
> > >>>>    * Device Tree file for Marvell Armada 3720 community board
> > >>>>    * (ESPRESSOBin)
> > >>>>    * Copyright (C) 2016 Marvell
> > >>>> - *
> > >>>> - * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > >>>> - * Konstantin Porotchkin <kostap@marvell.com>
> > >>>> - *
> > >>>> - * This file is dual-licensed: you can use it either under the terms
> > >>>> - * of the GPL or the X11 license, at your option. Note that this dual
> > >>>> - * licensing only applies to this file, and not this project as a
> > >>>> - * whole.
> > >>>> - *
> > >>>> - *  a) This file is free software; you can redistribute it and/or
> > >>>> - *     modify it under the terms of the GNU General Public License as
> > >>>> - *     published by the Free Software Foundation; either version 2 of the
> > >>>> - *     License, or (at your option) any later version.
> > >>>> - *
> > >>>> - *     This file is distributed in the hope that it will be useful
> > >>>> - *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > >>>> - *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > >>>> - *     GNU General Public License for more details.
> > >>>> - *
> > >>>> - * Or, alternatively
> > >>>> - *
> > >>>> - *  b) Permission is hereby granted, free of charge, to any person
> > >>>> - *     obtaining a copy of this software and associated documentation
> > >>>> - *     files (the "Software"), to deal in the Software without
> > >>>> - *     restriction, including without limitation the rights to use
> > >>>> - *     copy, modify, merge, publish, distribute, sublicense, and/or
> > >>>> - *     sell copies of the Software, and to permit persons to whom the
> > >>>> - *     Software is furnished to do so, subject to the following
> > >>>> - *     conditions:
> > >>>> - *
> > >>>> - *     The above copyright notice and this permission notice shall be
> > >>>> - *     included in all copies or substantial portions of the Software.
> > >>>> - *
> > >>>> - *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > >>>> - *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > >>>> - *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > >>>> - *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > >>>> - *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > >>>> - *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > >>>> - *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > >>>> - *     OTHER DEALINGS IN THE SOFTWARE.
> > >>>>    */
> > >>>>
> > >>>>   /dts-v1/;
> > >>>>
> > >>>> -#include "armada-372x.dtsi"
> > >>>> +#include "armada-3720-espressobin.dtsi"
> > >>>>
> > >>>>   / {
> > >>>>        model = "Globalscale Marvell ESPRESSOBin Board";
> > >>>>        compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > >>>> -
> > >>>> -     chosen {
> > >>>> -             stdout-path = "serial0:115200n8";
> > >>>> -     };
> > >>>> -
> > >>>> -     aliases {
> > >>>> -             ethernet0 = &eth0;
> > >>>> -             i2c0 = &i2c0;
> > >>>> -             spi0 = &spi0;
> > >>>> -     };
> > >>>> -
> > >>>> -     memory {
> > >>>> -             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 {
> > >>>> -     max-lanes = <3>;
> > >>>> -     phy0 {
> > >>>> -             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > >>>> -             phy-speed = <COMPHY_SPEED_5G>;
> > >>>> -     };
> > >>>> -
> > >>>> -     phy1 {
> > >>>> -             phy-type = <COMPHY_TYPE_PEX0>;
> > >>>> -             phy-speed = <COMPHY_SPEED_2_5G>;
> > >>>> -     };
> > >>>> -
> > >>>> -     phy2 {
> > >>>> -             phy-type = <COMPHY_TYPE_SATA0>;
> > >>>> -             phy-speed = <COMPHY_SPEED_5G>;
> > >>>> -     };
> > >>>> -};
> > >>>> -
> > >>>> -&eth0 {
> > >>>> -     status = "okay";
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > >>>> -     phy-mode = "rgmii";
> > >>>> -     phy_addr = <0x1>;
> > >>>> -     fixed-link {
> > >>>> -             speed = <1000>;
> > >>>> -             full-duplex;
> > >>>> -     };
> > >>>> -};
> > >>>> -
> > >>>> -&i2c0 {
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&i2c1_pins>;
> > >>>> -     status = "okay";
> > >>>> -};
> > >>>> -
> > >>>> -/* CON3 */
> > >>>> -&sata {
> > >>>> -     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";
> > >>>> -};
> > >>>> -
> > >>>> -/* U11 */
> > >>>> -&sdhci1 {
> > >>>> -     non-removable;
> > >>>> -     bus-width = <8>;
> > >>>> -     mmc-ddr-1_8v;
> > >>>> -     mmc-hs400-1_8v;
> > >>>> -     marvell,xenon-emmc;
> > >>>> -     marvell,xenon-tun-count = <9>;
> > >>>> -     marvell,pad-type = "fixed-1-8v";
> > >>>> -
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&mmc_pins>;
> > >>>> -     status = "okay";
> > >>>> -
> > >>>> -     #address-cells = <1>;
> > >>>> -     #size-cells = <0>;
> > >>>> -     mmccard: mmccard@0 {
> > >>>> -             compatible = "mmc-card";
> > >>>> -             reg = <0>;
> > >>>> -     };
> > >>>> -};
> > >>>> -
> > >>>> -&spi0 {
> > >>>> -     status = "okay";
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&spi_quad_pins>;
> > >>>> -
> > >>>> -     spi-flash@0 {
> > >>>> -             #address-cells = <1>;
> > >>>> -             #size-cells = <1>;
> > >>>> -             compatible = "st,m25p128", "jedec,spi-nor";
> > >>>> -             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > >>>> -                             label = "u-boot-env";
> > >>>> -                     };
> > >>>> -             };
> > >>>> -#endif
> > >>>> -     };
> > >>>> -};
> > >>>> -
> > >>>> -/* Exported on the micro USB connector CON32 through an FTDI */
> > >>>> -&uart0 {
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&uart1_pins>;
> > >>>> -     status = "okay";
> > >>>> -};
> > >>>> -
> > >>>> -/* CON29 */
> > >>>> -&usb2 {
> > >>>> -     status = "okay";
> > >>>> -};
> > >>>> -
> > >>>> -/* CON31 */
> > >>>> -&usb3 {
> > >>>> -     status = "okay";
> > >>>> -};
> > >>>> -
> > >>>> -&pcie0 {
> > >>>> -     pinctrl-names = "default";
> > >>>> -     pinctrl-0 = <&pcie_pins>;
> > >>>> -     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > >>>> -     status = "okay";
> > >>>>   };
> > >>>> diff --git a/arch/arm/dts/armada-3720-espressobin.dtsi b/arch/arm/dts/armada-3720-espressobin.dtsi
> > >>>> new file mode 100644
> > >>>> index 0000000000..cba6139be6
> > >>>> --- /dev/null
> > >>>> +++ b/arch/arm/dts/armada-3720-espressobin.dtsi
> > >>>> @@ -0,0 +1,210 @@
> > >>>> +/*
> > >>>> + * Device Tree file for Marvell Armada 3720 community board
> > >>>> + * (ESPRESSOBin)
> > >>>> + * Copyright (C) 2016 Marvell
> > >>>> + *
> > >>>> + * Gregory CLEMENT <gregory.clement@free-electrons.com>
> > >>>> + * Konstantin Porotchkin <kostap@marvell.com>
> > >>>> + *
> > >>>> + * This file is dual-licensed: you can use it either under the terms
> > >>>> + * of the GPL or the X11 license, at your option. Note that this dual
> > >>>> + * licensing only applies to this file, and not this project as a
> > >>>> + * whole.
> > >>>> + *
> > >>>> + *  a) This file is free software; you can redistribute it and/or
> > >>>> + *     modify it under the terms of the GNU General Public License as
> > >>>> + *     published by the Free Software Foundation; either version 2 of the
> > >>>> + *     License, or (at your option) any later version.
> > >>>> + *
> > >>>> + *     This file is distributed in the hope that it will be useful
> > >>>> + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
> > >>>> + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > >>>> + *     GNU General Public License for more details.
> > >>>> + *
> > >>>> + * Or, alternatively
> > >>>> + *
> > >>>> + *  b) Permission is hereby granted, free of charge, to any person
> > >>>> + *     obtaining a copy of this software and associated documentation
> > >>>> + *     files (the "Software"), to deal in the Software without
> > >>>> + *     restriction, including without limitation the rights to use
> > >>>> + *     copy, modify, merge, publish, distribute, sublicense, and/or
> > >>>> + *     sell copies of the Software, and to permit persons to whom the
> > >>>> + *     Software is furnished to do so, subject to the following
> > >>>> + *     conditions:
> > >>>> + *
> > >>>> + *     The above copyright notice and this permission notice shall be
> > >>>> + *     included in all copies or substantial portions of the Software.
> > >>>> + *
> > >>>> + *     THE SOFTWARE IS PROVIDED , WITHOUT WARRANTY OF ANY KIND
> > >>>> + *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > >>>> + *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > >>>> + *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > >>>> + *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
> > >>>> + *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > >>>> + *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > >>>> + *     OTHER DEALINGS IN THE SOFTWARE.
> > >>>> + */
> > >>>> +
> > >>>> +/dts-v1/;
> > >>>> +
> > >>>> +#include "armada-372x.dtsi"
> > >>>> +
> > >>>> +/ {
> > >>>> +     model = "Globalscale Marvell ESPRESSOBin Board";
> > >>>> +     compatible = "globalscale,espressobin", "marvell,armada3720", "marvell,armada3710";
> > >>>> +
> > >>>> +     chosen {
> > >>>> +             stdout-path = "serial0:115200n8";
> > >>>> +     };
> > >>>> +
> > >>>> +     aliases {
> > >>>> +             ethernet0 = &eth0;
> > >>>> +             i2c0 = &i2c0;
> > >>>> +             spi0 = &spi0;
> > >>>> +     };
> > >>>> +
> > >>>> +     memory {
> > >>>> +             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 {
> > >>>> +     max-lanes = <3>;
> > >>>> +     phy0 {
> > >>>> +             phy-type = <COMPHY_TYPE_USB3_HOST0>;
> > >>>> +             phy-speed = <COMPHY_SPEED_5G>;
> > >>>> +     };
> > >>>> +
> > >>>> +     phy1 {
> > >>>> +             phy-type = <COMPHY_TYPE_PEX0>;
> > >>>> +             phy-speed = <COMPHY_SPEED_2_5G>;
> > >>>> +     };
> > >>>> +
> > >>>> +     phy2 {
> > >>>> +             phy-type = <COMPHY_TYPE_SATA0>;
> > >>>> +             phy-speed = <COMPHY_SPEED_5G>;
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&eth0 {
> > >>>> +     status = "okay";
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
> > >>>> +     phy-mode = "rgmii";
> > >>>> +     phy_addr = <0x1>;
> > >>>> +     fixed-link {
> > >>>> +             speed = <1000>;
> > >>>> +             full-duplex;
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&i2c0 {
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&i2c1_pins>;
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +/* CON3 */
> > >>>> +&sata {
> > >>>> +     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";
> > >>>> +};
> > >>>> +
> > >>>> +/* U11 */
> > >>>> +&sdhci1 {
> > >>>> +     non-removable;
> > >>>> +     bus-width = <8>;
> > >>>> +     mmc-ddr-1_8v;
> > >>>> +     mmc-hs400-1_8v;
> > >>>> +     marvell,xenon-emmc;
> > >>>> +     marvell,xenon-tun-count = <9>;
> > >>>> +     marvell,pad-type = "fixed-1-8v";
> > >>>> +
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&mmc_pins>;
> > >>>> +     status = "okay";
> > >>>> +
> > >>>> +     #address-cells = <1>;
> > >>>> +     #size-cells = <0>;
> > >>>> +     mmccard: mmccard@0 {
> > >>>> +             compatible = "mmc-card";
> > >>>> +             reg = <0>;
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +&spi0 {
> > >>>> +     status = "okay";
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&spi_quad_pins>;
> > >>>> +
> > >>>> +     spi-flash@0 {
> > >>>> +             #address-cells = <1>;
> > >>>> +             #size-cells = <1>;
> > >>>> +             compatible = "st,m25p128", "jedec,spi-nor";
> > >>>> +             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 = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> > >>>> +                             label = "u-boot-env";
> > >>>> +                     };
> > >>>> +             };
> > >>>> +#endif
> > >>>> +     };
> > >>>> +};
> > >>>> +
> > >>>> +/* Exported on the micro USB connector CON32 through an FTDI */
> > >>>> +&uart0 {
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&uart1_pins>;
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +/* CON29 */
> > >>>> +&usb2 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +/* CON31 */
> > >>>> +&usb3 {
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> +
> > >>>> +&pcie0 {
> > >>>> +     pinctrl-names = "default";
> > >>>> +     pinctrl-0 = <&pcie_pins>;
> > >>>> +     reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>;
> > >>>> +     status = "okay";
> > >>>> +};
> > >>>> diff --git a/board/Marvell/mvebu_armada-37xx/MAINTAINERS b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > >>>> index f2c0a582d7..d69af832fc 100644
> > >>>> --- a/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > >>>> +++ b/board/Marvell/mvebu_armada-37xx/MAINTAINERS
> > >>>> @@ -10,6 +10,14 @@ M: Konstantin Porotchkin <kostap@marvell.com>
> > >>>>   S:   Maintained
> > >>>>   F:   configs/mvebu_espressobin-88f3720_defconfig
> > >>>>
> > >>>> +ESPRESSOBin-Ultra BOARD
> > >>>> +M:   Luka Kovacic <luka.kovacic@sartura.hr>
> > >>>> +M:   Robert Marko <robert.marko@sartura.hr>
> > >>>> +M:   Luka Perkov <luka.perkov@sartura.hr>
> > >>>> +S:   Maintained
> > >>>> +F:   arch/arm/dts/armada-3720-espressobin-ultra.dts
> > >>>> +F:   configs/mvebu_espressobin-ultra-88f3720_defconfig
> > >>>> +
> > >>>>   uDPU BOARD
> > >>>>   M:   Vladimir Vid <vladimir.vid@sartura.hr>
> > >>>>   S:   Maintained
> > >>>> diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > >>>> index 2de9c2ac17..21c1eb7b22 100644
> > >>>> --- a/board/Marvell/mvebu_armada-37xx/board.c
> > >>>> +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > >>>> @@ -11,6 +11,7 @@
> > >>>>   #include <i2c.h>
> > >>>>   #include <init.h>
> > >>>>   #include <mmc.h>
> > >>>> +#include <miiphy.h>
> > >>>>   #include <phy.h>
> > >>>>   #include <asm/global_data.h>
> > >>>>   #include <asm/io.h>
> > >>>> @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > >>>>   #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > >>>>   #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > >>>>
> > >>>> +/* Marvell 88E1512 */
> > >>>> +#define MII_MARVELL_PHY_PAGE         22
> > >>>> +
> > >>>> +#define MV88E1512_GENERAL_CTRL               20
> > >>>> +#define MV88E1512_MODE_SGMII         1
> > >>>> +#define MV88E1512_RESET_OFFS         15
> > >>>> +
> > >>>> +#define ULTRA_MV88E1512_PHYADDR              0x1
> > >>>> +
> > >>>>   /*
> > >>>>    * Memory Controller Registers
> > >>>>    *
> > >>>> @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > >>>>        return 0;
> > >>>>   }
> > >>>>
> > >>>> -/* Bring-up board-specific network stuff */
> > >>>> -int board_network_enable(struct mii_dev *bus)
> > >>>> +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > >>>>   {
> > >>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > >>>> -             return 0;
> > >>>> +     const char *name;
> > >>>> +     u16 reg;
> > >>>> +
> > >>>> +     name = miiphy_get_current_dev();
> > >>>> +     if (name) {
> > >>>> +             /* SGMII-to-Copper mode initialization */
> > >>>> +
> > >>>> +             /* Select page 18 */
> > >>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > >>>> +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > >>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > >>>> +             reg &= ~0x7;
> > >>>> +             reg |= MV88E1512_MODE_SGMII;
> > >>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > >>>> +             /* PHY reset is necessary after changing MODE[2:0] */
> > >>>> +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > >>>> +             reg |= 1 << MV88E1512_RESET_OFFS;
> > >>>> +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > >>>> +             /* Reset page selection */
> > >>>> +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > >>>> +             udelay(100);
> > >>>> +     }
> > >>>> +}
> > >>>> +
> > >>>> +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > >>>> +{
> > >>>> +     int i;
> > >>>> +     /* Setup 88E1512 SGMII-to-Copper mode */
> > >>>> +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > >>>>
> > >>>> +     /*
> > >>>> +      * FIXME: remove this code once Topaz driver gets available
> > >>>> +      * A3720 ESPRESSObin Ultra Board Only
> > >>>> +      * Configure Topaz switch (88E6341)
> > >>>> +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > >>>> +      */
> > >>>> +     for (i = 0; i <= 5; i++) {
> > >>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > >>>> +                                       MVEBU_SW_PORT_CTRL_REG,
> > >>>> +                                       i == 5 ? 0x7c : 0x7f);
> > >>>> +     }
> > >>>> +
> > >>>> +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > >>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > >>>> +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > >>>> +
> > >>>> +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > >>>> +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > >>>> +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > >>>> +     for (i = 1; i <= 5; i++) {
> > >>>> +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > >>>> +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > >>>> +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > >>>> +     }
> > >>>> +
> > >>>> +     return 0;
> > >>>> +}
> > >>>> +
> > >>>> +int board_network_enable_espressobin(struct mii_dev *bus)
> > >>>> +{
> > >>>>        /*
> > >>>>         * FIXME: remove this code once Topaz driver gets available
> > >>>>         * A3720 Community Board Only
> > >>>> @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > >>>>        return 0;
> > >>>>   }
> > >>>>
> > >>>> +/* Bring-up the board-specific networking */
> > >>>> +int board_network_enable(struct mii_dev *bus)
> > >>>> +{
> > >>>> +     if (of_machine_is_compatible("globalscale,espressobin"))
> > >>>> +             return board_network_enable_espressobin(bus);
> > >>>> +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > >>>> +             return board_network_enable_espressobin_ultra(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)
> > >>>>   {
> > >>>> @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > >>>>        int parts_off;
> > >>>>        int part_off;
> > >>>>
> > >>>> -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > >>>> -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > >>>> +     /*
> > >>>> +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > >>>> +      * ESPRESSOBin Ultra boards.
> > >>>> +      */
> > >>>> +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > >>>> +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > >>>>                return 0;
> > >>>>
> > >>>>        spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> > >>>> diff --git a/configs/mvebu_espressobin-ultra-88f3720_defconfig b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > >>>> new file mode 100644
> > >>>> index 0000000000..1bac0a96ad
> > >>>> --- /dev/null
> > >>>> +++ b/configs/mvebu_espressobin-ultra-88f3720_defconfig
> > >>>> @@ -0,0 +1,93 @@
> > >>>> +CONFIG_ARM=y
> > >>>> +CONFIG_ARCH_CPU_INIT=y
> > >>>> +CONFIG_ARCH_MVEBU=y
> > >>>> +CONFIG_SYS_TEXT_BASE=0x00000000
> > >>>> +CONFIG_SYS_MALLOC_F_LEN=0x2000
> > >>>> +CONFIG_NR_DRAM_BANKS=1
> > >>>> +CONFIG_TARGET_MVEBU_ARMADA_37XX=y
> > >>>> +CONFIG_ENV_SIZE=0x10000
> > >>>> +CONFIG_ENV_OFFSET=0x3F0000
> > >>>> +CONFIG_ENV_SECT_SIZE=0x10000
> > >>>> +CONFIG_DM_GPIO=y
> > >>>> +CONFIG_DEBUG_UART_BASE=0xd0012000
> > >>>> +CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin-ultra"
> > >>>> +CONFIG_DEBUG_UART=y
> > >>>> +CONFIG_AHCI=y
> > >>>> +CONFIG_DISTRO_DEFAULTS=y
> > >>>> +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> > >>>> +CONFIG_OF_BOARD_SETUP=y
> > >>>> +CONFIG_FIT=y
> > >>>> +CONFIG_FIT_VERBOSE=y
> > >>>> +CONFIG_FIT_BEST_MATCH=y
> > >>>> +CONFIG_AUTOBOOT_KEYED=y
> > >>>> +CONFIG_AUTOBOOT_PROMPT="Autoboot in %d seconds, to stop use 's' key\n"
> > >>>> +CONFIG_AUTOBOOT_STOP_STR="s"
> > >>>> +CONFIG_AUTOBOOT_KEYED_CTRLC=y
> > >>>> +CONFIG_HUSH_PARSER=y
> > >>>> +CONFIG_SYS_CONSOLE_INFO_QUIET=y
> > >>>> +# CONFIG_DISPLAY_CPUINFO is not set
> > >>>> +# CONFIG_DISPLAY_BOARDINFO is not set
> > >>>> +CONFIG_DISPLAY_BOARDINFO_LATE=y
> > >>>> +CONFIG_ARCH_EARLY_INIT_R=y
> > >>>> +CONFIG_BOARD_EARLY_INIT_F=y
> > >>>> +CONFIG_BOARD_LATE_INIT=y
> > >>>> +# CONFIG_CMD_FLASH is not set
> > >>>> +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
> > >>>> +CONFIG_CMD_WDT=y
> > >>>> +# CONFIG_CMD_SETEXPR is not set
> > >>>> +CONFIG_CMD_TFTPPUT=y
> > >>>> +CONFIG_CMD_CACHE=y
> > >>>> +CONFIG_CMD_TIME=y
> > >>>> +CONFIG_CMD_MVEBU_BUBT=y
> > >>>> +CONFIG_MVEBU_MAC_HW_INFO=y
> > >>>> +CONFIG_CMD_EXT4_WRITE=y
> > >>>> +CONFIG_MAC_PARTITION=y
> > >>>> +CONFIG_ENV_OVERWRITE=y
> > >>>> +CONFIG_ENV_IS_IN_SPI_FLASH=y
> > >>>> +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> > >>>> +CONFIG_NET_RANDOM_ETHADDR=y
> > >>>> +CONFIG_AHCI_MVEBU=y
> > >>>> +CONFIG_CLK=y
> > >>>> +CONFIG_CLK_MVEBU=y
> > >>>> +CONFIG_DM_I2C=y
> > >>>> +CONFIG_MISC=y
> > >>>> +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_SPI_FLASH_MACRONIX=y
> > >>>> +CONFIG_SPI_FLASH_MTD=y
> > >>>> +CONFIG_PHY_MARVELL=y
> > >>>> +CONFIG_PHY_GIGE=y
> > >>>> +CONFIG_MVNETA=y
> > >>>> +CONFIG_PCI=y
> > >>>> +CONFIG_PCI_AARDVARK=y
> > >>>> +CONFIG_PHY=y
> > >>>> +CONFIG_MVEBU_COMPHY_SUPPORT=y
> > >>>> +CONFIG_PINCTRL=y
> > >>>> +CONFIG_PINCTRL_ARMADA_37XX=y
> > >>>> +CONFIG_DM_REGULATOR_GPIO=y
> > >>>> +CONFIG_DEBUG_UART_SHIFT=2
> > >>>> +CONFIG_DEBUG_UART_ANNOUNCE=y
> > >>>> +CONFIG_MVEBU_A3700_UART=y
> > >>>> +CONFIG_MVEBU_A3700_SPI=y
> > >>>> +CONFIG_USB=y
> > >>>> +CONFIG_USB_XHCI_HCD=y
> > >>>> +CONFIG_USB_EHCI_HCD=y
> > >>>> +CONFIG_USB_HOST_ETHER=y
> > >>>> +# CONFIG_WATCHDOG_AUTOSTART is not set
> > >>>> +CONFIG_WDT=y
> > >>>> +CONFIG_WDT_ARMADA_37XX=y
> > >>>> +CONFIG_SHA1=y
> > >>>> +CONFIG_DM_RTC=y
> > >>>> +CONFIG_RTC_PCF8563=y
> > >>>> +CONFIG_LED=y
> > >>>> +CONFIG_LED_GPIO=y
> > >>>> --
> > >>>> 2.31.1
> > >>>>
> > >>
> > >> Kind regards,
> > >> Luka
> >
> >
> > Viele Grüße,
> > Stefan
> >
> > --
> > DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> > Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info)
  2021-08-13 10:43     ` Luka Kovacic
@ 2021-08-13 10:49       ` Pali Rohár
  0 siblings, 0 replies; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:49 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

On Friday 13 August 2021 12:43:47 Luka Kovacic wrote:
> On Fri, Aug 13, 2021 at 12:29 PM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:36 Luka Kovacic wrote:
> > > diff --git a/board/Marvell/mvebu_armada-37xx/Kconfig b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > new file mode 100644
> > > index 0000000000..b84dd20023
> > > --- /dev/null
> > > +++ b/board/Marvell/mvebu_armada-37xx/Kconfig
> > > @@ -0,0 +1,29 @@
> > > +menu "Marvell Armada 37xx configuration"
> > > +depends on TARGET_MVEBU_ARMADA_37XX
> > > +
> > > +config MVEBU_MAC_HW_INFO
> > > +     bool "Marvell hw_info (mac) support"
> > > +     depends on SPI_FLASH && ENV_IS_IN_SPI_FLASH && ARCH_MVEBU
> > > +     default n
> > > +     help
> > > +       Enable loading of the Marvell hw_info parameters from the
> > > +       SPI flash hw_info area. Parameters (usually the board serial
> > > +       number and MAC addresses) are then imported into the
> > > +       existing U-Boot environment.
> > > +       Implementation of this command is compatible with the
> > > +       original Marvell U-Boot command. Reading and writing is
> > > +       supported.
> > > +       EEPROM config pattern and checksum aren't supported.
> > > +       After enabled, these parameters are managed from the common
> > > +       U-Boot mac command.
> > > +
> > > +config MVEBU_MAC_HW_INFO_OFFSET
> > > +     hex "Marvell hw_info (mac) SPI flash offset"
> > > +     depends on MVEBU_MAC_HW_INFO
> > > +     default 0x3E0000
> > > +     help
> > > +       This option defines the SPI flash offset of the Marvell
> > > +       hw_info area. This defaults to 0x3E0000 on most Armada
> > > +       A3720 platforms.
> >
> > Just a question, cannot we load this offset from DTS? In DTS are already
> > specified SPI partitions, so this could eliminate need for defining this
> > offset at two places. But I really do not know at which time is this
> > code called, if DTB is available at this time or not.
> 
> The code is called right after cpu_secondary_init_r.
> I'm not sure, there also some other values, which are hard-coded and
> so far I didn't really see any other possible offset.
> 
> Are you aware of any other relevant board with the Marvell hw_info
> parameters?

I do not know any other board which uses this hw_info. And because you
adding config option for address, I though that there are more boards
with different addresses... And so I was thinking if it cannot be loaded
fro DTS.

I can check espressobin v5 if there is not some "hidden" hw_info stuff
somewhere...

> >
> > > +endmenu
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:33         ` Luka Kovacic
@ 2021-08-13 10:59           ` Pali Rohár
  2021-08-16  8:37             ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 10:59 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

On Friday 13 August 2021 12:33:25 Luka Kovacic wrote:
> On Fri, Aug 13, 2021 at 12:22 PM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 12:03:57 Luka Kovacic wrote:
> > > Hello Pali,
> > >
> > > On Fri, Aug 13, 2021 at 11:27 AM Pali Rohár <pali@kernel.org> wrote:
> > > >
> > > > On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > > > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > > > Technologies, Inc.
> > > > >
> > > > > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > > > Peripherals:
> > > > >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > > > >  - RTC clock (PCF8563)
> > > > >  - USB 3.0 port
> > > > >  - USB 2.0 port
> > > > >  - 4x LED
> > > > >  - UART over Micro-USB
> > > > >  - M.2 slot (2280)
> > > > >  - Mini PCI-E slot
> > > > >
> > > > > Additionally, automatic import of the Marvell hw_info parameters is
> > > > > enabled via the recently added mac command for A37XX platforms.
> > > > > The parameters stored in Marvell hw_info are usually the board serial
> > > > > number and MAC addresses.
> > > > >
> > > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > > ---
> > > > >  arch/arm/dts/Makefile                         |   1 +
> > > > >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > > > >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > > > >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > > > >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > > > >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > > > >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > > > >  7 files changed, 514 insertions(+), 203 deletions(-)
> > > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > > > >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > > ...
> > > > > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > > > > index 2de9c2ac17..21c1eb7b22 100644
> > > > > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > > > > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > > > > @@ -11,6 +11,7 @@
> > > > >  #include <i2c.h>
> > > > >  #include <init.h>
> > > > >  #include <mmc.h>
> > > > > +#include <miiphy.h>
> > > > >  #include <phy.h>
> > > > >  #include <asm/global_data.h>
> > > > >  #include <asm/io.h>
> > > > > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > > > >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > > > >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > > > >
> > > > > +/* Marvell 88E1512 */
> > > > > +#define MII_MARVELL_PHY_PAGE         22
> > > > > +
> > > > > +#define MV88E1512_GENERAL_CTRL               20
> > > > > +#define MV88E1512_MODE_SGMII         1
> > > > > +#define MV88E1512_RESET_OFFS         15
> > > > > +
> > > > > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > > > > +
> > > > >  /*
> > > > >   * Memory Controller Registers
> > > > >   *
> > > > > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > > > >       return 0;
> > > > >  }
> > > > >
> > > > > -/* Bring-up board-specific network stuff */
> > > > > -int board_network_enable(struct mii_dev *bus)
> > > > > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > > > >  {
> > > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > > -             return 0;
> > > > > +     const char *name;
> > > > > +     u16 reg;
> > > > > +
> > > > > +     name = miiphy_get_current_dev();
> > > > > +     if (name) {
> > > >
> > > > It is possible that phy is not available? As you are calling code below
> > > > only in case name is not-NULL.
> > >
> > > Well, according to common/miiphyutil.c, it could also happen that it's NULL.
> >
> > I see. But if it happens, is not it fatal error for this board? If name
> > is NULL then you cannot correctly configure board correctly, right?
> >
> > > >
> > > > > +             /* SGMII-to-Copper mode initialization */
> > > > > +
> > > > > +             /* Select page 18 */
> > > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > > > > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > > +             reg &= ~0x7;
> > > > > +             reg |= MV88E1512_MODE_SGMII;
> > > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > > +             /* PHY reset is necessary after changing MODE[2:0] */
> > > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > > +             /* Reset page selection */
> > > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > > > > +             udelay(100);
> > > > > +     }
> > > > > +}
> > > > > +
> > > > > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > > > > +{
> > > > > +     int i;
> > > > > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > > > > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > > > >
> > > > > +     /*
> > > > > +      * FIXME: remove this code once Topaz driver gets available
> > > > > +      * A3720 ESPRESSObin Ultra Board Only
> > > > > +      * Configure Topaz switch (88E6341)
> > > > > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > > > > +      */
> > > > > +     for (i = 0; i <= 5; i++) {
> > > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > > > > +                                       MVEBU_SW_PORT_CTRL_REG,
> > > > > +                                       i == 5 ? 0x7c : 0x7f);
> > > >
> > > > Why port 5 has different settings?
> > >
> > > It's to disable forwarding between the WAN port and LAN ports (I've
> > > tested this).
> > > I'm aware of this thread:
> > > https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18
> >
> > Ok. But your change seems to not be correct. I'm looking at
> > documentation and when low 2 bits in Port Control Register are zero then
> > specified port is completely disabled.
> >
> > I agree that for disabled port is obviously disabled also forwarding.
> > But I do not think it is what you want... Or, which behavior you want to
> > achieve? From above added comment (which seems to be also copy+paste) it
> > is not clear.
> >
> 
> I think it would be completely fine if the WAN port is disabled in U-Boot.
> The current behaviour is that the LAN ports forward between each other and
> are all accessible from U-Boot, while the WAN port is in no way accessible.
> The link is up when testing the WAN port, but no traffic passes.

For espressobin v5/v7 all ports are enabled, but forwarding is possible
only in directions: "cpu to any non-cpu port" and "non-cpu port to cpu
port". So between lan ports it is disabled and also between lan an wan.

User may have custom settings in Linux where want to use e.g. two ports
as wans (e.g. use one lan labeled port as wan2) and then during u-boot
stage it would would break his network. That is why also forwarding
between lan labeled ports is disabled.

Or user may use custom vlan settings with authentication and then
enabled forwarding in u-boot also can break network. This industrial
Topaz switch has lot of HW functionality, so it is ideal for such kind
of usage.

> > Look at that my change which only disables forwarding between ports. And
> > does not disable ports itself. It is already in newly renamed function
> > board_network_enable_espressobin(). That is why I do not like copy+paste
> > of code as it can be copied incorrectly, or differently without
> > describing commenting why it is differently.
> >
> > I see that board_network_enable_espressobin_ultra() and
> > board_network_enable_espressobin() are different. But they have some
> > common parts, e.g. this port policy configuration. So at least this code
> > path can be moved in some common function.
> 
> I agree, these could be somehow unified. I will take a look.
> 
> >
> > > >
> > > > > +     }
> > > > > +
> > > > > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > > > > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > > > > +
> > > > > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > > > > +     for (i = 1; i <= 5; i++) {
> > > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > > > > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > > > > +     }
> > > >
> > > > It looks like that by copying board_network_enable_espressobin_ultra()
> > > > function from Marvell U-Boot instead of using code which is in mainline
> > > > function board_network_enable() for Espressobin, you are introducing a
> > > > security hole, which is in Marvell U-Boot and which was fixed in
> > > > mainline U-Boot for all supported Espressobin boards (see commit
> > > > 48f2c8a37f700859a7004dce5adb116597a45700).
> > > >
> > > > I would really suggest to not blindly copy old code from Marvell into
> > > > mainline U-Boot, as here we have fixed lot of issues.
> > > >
> > > > > +     return 0;
> > > > > +}
> > > > > +
> > > > > +int board_network_enable_espressobin(struct mii_dev *bus)
> > > > > +{
> > > > >       /*
> > > > >        * FIXME: remove this code once Topaz driver gets available
> > > > >        * A3720 Community Board Only
> > > > > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > > > >       return 0;
> > > > >  }
> > > > >
> > > > > +/* Bring-up the board-specific networking */
> > > > > +int board_network_enable(struct mii_dev *bus)
> > > > > +{
> > > > > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > > > > +             return board_network_enable_espressobin(bus);
> > > > > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > > > +             return board_network_enable_espressobin_ultra(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)
> > > > >  {
> > > > > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > > > >       int parts_off;
> > > > >       int part_off;
> > > > >
> > > > > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > > +     /*
> > > > > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > > > > +      * ESPRESSOBin Ultra boards.
> > > > > +      */
> > > > > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > > > > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > > >               return 0;
> > > >
> > > > According to kernel DTS file, it looks like that Espressobin Ultra has
> > > > different MTD partitions as other variants... Therefore Ultra needs
> > > > adjustments in this code.
> > > >
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78
> > >
> > > That's true, I'll have to fix this.
> >
> > It is needed to call this function for ultra variant at all? Because as
> > I understand ultra variant has fixed layout as specified in kernel DTS
> > file and therefore it should not have any dynamic modification.
> >
> > Or is there any other issue?

(This was about MTD partitions)

> If the ports aren't correctly configured in U-Boot, Linux fails to configure the
> Topaz switch.

So this is a bug in Linux. Kernel really should not depend on specific
network configuration done by bootloader.

So DTS file for Ultra variant in Linux kernel is incomplete?

I remember that DTS was merged into Linux kernel, but there were some
issues and I do not know if they were fixed later after merging...

> In the current configuration traffic between LAN and WAN is blocked in U-Boot
> and Linux correctly configures the Topaz switch.
> 
> >
> > > >
> > > > >
> > > > >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> > >
> > > Kind regards,
> > > Luka
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-12 23:39 ` [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable Luka Kovacic
  2021-08-13  8:08   ` Pali Rohár
@ 2021-08-13 13:59   ` Pali Rohár
  2021-08-16  8:21     ` Luka Kovacic
  1 sibling, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-08-13 13:59 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, robert.marko, luka.perkov, marek.behun, sr, sjg,
	patrick.delaunay, xypron.glpk

On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> Add the loadaddr U-Boot environment variable, as this is available in
> the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> 
> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Robert Marko <robert.marko@sartura.hr>
> ---
>  include/configs/mvebu_armada-37xx.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> index 8e8bcfa018..6901680e32 100644
> --- a/include/configs/mvebu_armada-37xx.h
> +++ b/include/configs/mvebu_armada-37xx.h
> @@ -110,6 +110,7 @@
>  
>  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
>  #define CONFIG_EXTRA_ENV_SETTINGS	\
> +	"loadaddr=0x6000000\0"		\

Now I see where is the issue...

In file include/env_default.h is:

#ifdef	CONFIG_LOADADDR
	"loadaddr="	__stringify(CONFIG_LOADADDR)	"\0"
#endif

So default value for loadaddr= is set only when CONFIG_LOADADDR is
defined.

But lot of cmd load commands are using config option
CONFIG_SYS_LOAD_ADDR as a default value for load address.

And also for espressobin we set correct value into CONFIG_SYS_LOAD_ADDR.

I'm looking at the u-boot code and CONFIG_LOADADDR is used only by
cmd/qfw.c and include/env_default.h. And on all other places (in cmd
load commands) is used CONFIG_SYS_LOAD_ADDR.

So for me it looks like that cmd/qfw.c and include/env_default.h should
be fixed to use CONFIG_SYS_LOAD_ADDR instead of CONFIG_LOADADDR.

>  	"scriptaddr=0x6d00000\0"	\
>  	"pxefile_addr_r=0x6e00000\0"	\
>  	"fdt_addr=0x6f00000\0"		\
> -- 
> 2.31.1
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-13 13:59   ` Pali Rohár
@ 2021-08-16  8:21     ` Luka Kovacic
  2021-08-16  8:22       ` Pali Rohár
  0 siblings, 1 reply; 36+ messages in thread
From: Luka Kovacic @ 2021-08-16  8:21 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 3:59 PM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > Add the loadaddr U-Boot environment variable, as this is available in
> > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> >
> > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Cc: Robert Marko <robert.marko@sartura.hr>
> > ---
> >  include/configs/mvebu_armada-37xx.h | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > index 8e8bcfa018..6901680e32 100644
> > --- a/include/configs/mvebu_armada-37xx.h
> > +++ b/include/configs/mvebu_armada-37xx.h
> > @@ -110,6 +110,7 @@
> >
> >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > +     "loadaddr=0x6000000\0"          \
>
> Now I see where is the issue...
>
> In file include/env_default.h is:
>
> #ifdef  CONFIG_LOADADDR
>         "loadaddr="     __stringify(CONFIG_LOADADDR)    "\0"
> #endif
>
> So default value for loadaddr= is set only when CONFIG_LOADADDR is
> defined.
>
> But lot of cmd load commands are using config option
> CONFIG_SYS_LOAD_ADDR as a default value for load address.
>
> And also for espressobin we set correct value into CONFIG_SYS_LOAD_ADDR.
>
> I'm looking at the u-boot code and CONFIG_LOADADDR is used only by
> cmd/qfw.c and include/env_default.h. And on all other places (in cmd
> load commands) is used CONFIG_SYS_LOAD_ADDR.
>
> So for me it looks like that cmd/qfw.c and include/env_default.h should
> be fixed to use CONFIG_SYS_LOAD_ADDR instead of CONFIG_LOADADDR.

Thanks, this makes sense now.
I can correct this in the next patchset if that's okay with you.

>
> >       "scriptaddr=0x6d00000\0"        \
> >       "pxefile_addr_r=0x6e00000\0"    \
> >       "fdt_addr=0x6f00000\0"          \
> > --
> > 2.31.1
> >

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable
  2021-08-16  8:21     ` Luka Kovacic
@ 2021-08-16  8:22       ` Pali Rohár
  0 siblings, 0 replies; 36+ messages in thread
From: Pali Rohár @ 2021-08-16  8:22 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

On Monday 16 August 2021 10:21:19 Luka Kovacic wrote:
> Hello Pali,
> 
> On Fri, Aug 13, 2021 at 3:59 PM Pali Rohár <pali@kernel.org> wrote:
> >
> > On Friday 13 August 2021 01:39:37 Luka Kovacic wrote:
> > > Add the loadaddr U-Boot environment variable, as this is available in
> > > the stock Marvell U-Boot by default on Marvell Armada A37XX platforms.
> > >
> > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > ---
> > >  include/configs/mvebu_armada-37xx.h | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h
> > > index 8e8bcfa018..6901680e32 100644
> > > --- a/include/configs/mvebu_armada-37xx.h
> > > +++ b/include/configs/mvebu_armada-37xx.h
> > > @@ -110,6 +110,7 @@
> > >
> > >  /* fdt_addr and kernel_addr are needed for existing distribution boot scripts */
> > >  #define CONFIG_EXTRA_ENV_SETTINGS    \
> > > +     "loadaddr=0x6000000\0"          \
> >
> > Now I see where is the issue...
> >
> > In file include/env_default.h is:
> >
> > #ifdef  CONFIG_LOADADDR
> >         "loadaddr="     __stringify(CONFIG_LOADADDR)    "\0"
> > #endif
> >
> > So default value for loadaddr= is set only when CONFIG_LOADADDR is
> > defined.
> >
> > But lot of cmd load commands are using config option
> > CONFIG_SYS_LOAD_ADDR as a default value for load address.
> >
> > And also for espressobin we set correct value into CONFIG_SYS_LOAD_ADDR.
> >
> > I'm looking at the u-boot code and CONFIG_LOADADDR is used only by
> > cmd/qfw.c and include/env_default.h. And on all other places (in cmd
> > load commands) is used CONFIG_SYS_LOAD_ADDR.
> >
> > So for me it looks like that cmd/qfw.c and include/env_default.h should
> > be fixed to use CONFIG_SYS_LOAD_ADDR instead of CONFIG_LOADADDR.
> 
> Thanks, this makes sense now.
> I can correct this in the next patchset if that's okay with you.

Ok!

> >
> > >       "scriptaddr=0x6d00000\0"        \
> > >       "pxefile_addr_r=0x6e00000\0"    \
> > >       "fdt_addr=0x6f00000\0"          \
> > > --
> > > 2.31.1
> > >
> 
> Kind regards,
> Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:59           ` Pali Rohár
@ 2021-08-16  8:37             ` Luka Kovacic
  0 siblings, 0 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-08-16  8:37 UTC (permalink / raw)
  To: Pali Rohár
  Cc: u-boot, Robert Marko, Luka Perkov, Marek Behun, Stefan Roese,
	sjg, patrick.delaunay, xypron.glpk

Hello Pali,

On Fri, Aug 13, 2021 at 12:59 PM Pali Rohár <pali@kernel.org> wrote:
>
> On Friday 13 August 2021 12:33:25 Luka Kovacic wrote:
> > On Fri, Aug 13, 2021 at 12:22 PM Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On Friday 13 August 2021 12:03:57 Luka Kovacic wrote:
> > > > Hello Pali,
> > > >
> > > > On Fri, Aug 13, 2021 at 11:27 AM Pali Rohár <pali@kernel.org> wrote:
> > > > >
> > > > > On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > > > > Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > > > > Technologies, Inc.
> > > > > >
> > > > > > The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > > > > Peripherals:
> > > > > >  - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > > > > >  - RTC clock (PCF8563)
> > > > > >  - USB 3.0 port
> > > > > >  - USB 2.0 port
> > > > > >  - 4x LED
> > > > > >  - UART over Micro-USB
> > > > > >  - M.2 slot (2280)
> > > > > >  - Mini PCI-E slot
> > > > > >
> > > > > > Additionally, automatic import of the Marvell hw_info parameters is
> > > > > > enabled via the recently added mac command for A37XX platforms.
> > > > > > The parameters stored in Marvell hw_info are usually the board serial
> > > > > > number and MAC addresses.
> > > > > >
> > > > > > Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > > > > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > > > > Cc: Robert Marko <robert.marko@sartura.hr>
> > > > > > ---
> > > > > >  arch/arm/dts/Makefile                         |   1 +
> > > > > >  .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > > > > >  arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > > > > >  arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > > > > >  board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > > > > >  board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > > > > >  .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > > > > >  7 files changed, 514 insertions(+), 203 deletions(-)
> > > > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > > > >  create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > > > > >  create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > > > ...
> > > > > > diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c
> > > > > > index 2de9c2ac17..21c1eb7b22 100644
> > > > > > --- a/board/Marvell/mvebu_armada-37xx/board.c
> > > > > > +++ b/board/Marvell/mvebu_armada-37xx/board.c
> > > > > > @@ -11,6 +11,7 @@
> > > > > >  #include <i2c.h>
> > > > > >  #include <init.h>
> > > > > >  #include <mmc.h>
> > > > > > +#include <miiphy.h>
> > > > > >  #include <phy.h>
> > > > > >  #include <asm/global_data.h>
> > > > > >  #include <asm/io.h>
> > > > > > @@ -55,6 +56,15 @@ DECLARE_GLOBAL_DATA_PTR;
> > > > > >  #define MVEBU_G2_SMI_PHY_CMD_REG     (24)
> > > > > >  #define MVEBU_G2_SMI_PHY_DATA_REG    (25)
> > > > > >
> > > > > > +/* Marvell 88E1512 */
> > > > > > +#define MII_MARVELL_PHY_PAGE         22
> > > > > > +
> > > > > > +#define MV88E1512_GENERAL_CTRL               20
> > > > > > +#define MV88E1512_MODE_SGMII         1
> > > > > > +#define MV88E1512_RESET_OFFS         15
> > > > > > +
> > > > > > +#define ULTRA_MV88E1512_PHYADDR              0x1
> > > > > > +
> > > > > >  /*
> > > > > >   * Memory Controller Registers
> > > > > >   *
> > > > > > @@ -282,12 +292,68 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
> > > > > >       return 0;
> > > > > >  }
> > > > > >
> > > > > > -/* Bring-up board-specific network stuff */
> > > > > > -int board_network_enable(struct mii_dev *bus)
> > > > > > +void force_phy_88e1512_sgmii_to_copper(u16 devaddr)
> > > > > >  {
> > > > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > > > -             return 0;
> > > > > > +     const char *name;
> > > > > > +     u16 reg;
> > > > > > +
> > > > > > +     name = miiphy_get_current_dev();
> > > > > > +     if (name) {
> > > > >
> > > > > It is possible that phy is not available? As you are calling code below
> > > > > only in case name is not-NULL.
> > > >
> > > > Well, according to common/miiphyutil.c, it could also happen that it's NULL.
> > >
> > > I see. But if it happens, is not it fatal error for this board? If name
> > > is NULL then you cannot correctly configure board correctly, right?
> > >
> > > > >
> > > > > > +             /* SGMII-to-Copper mode initialization */
> > > > > > +
> > > > > > +             /* Select page 18 */
> > > > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0x12);
> > > > > > +             /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
> > > > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > > > +             reg &= ~0x7;
> > > > > > +             reg |= MV88E1512_MODE_SGMII;
> > > > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > > > +             /* PHY reset is necessary after changing MODE[2:0] */
> > > > > > +             miiphy_read(name, devaddr, MV88E1512_GENERAL_CTRL, &reg);
> > > > > > +             reg |= 1 << MV88E1512_RESET_OFFS;
> > > > > > +             miiphy_write(name, devaddr, MV88E1512_GENERAL_CTRL, reg);
> > > > > > +             /* Reset page selection */
> > > > > > +             miiphy_write(name, devaddr, MII_MARVELL_PHY_PAGE, 0);
> > > > > > +             udelay(100);
> > > > > > +     }
> > > > > > +}
> > > > > > +
> > > > > > +int board_network_enable_espressobin_ultra(struct mii_dev *bus)
> > > > > > +{
> > > > > > +     int i;
> > > > > > +     /* Setup 88E1512 SGMII-to-Copper mode */
> > > > > > +     force_phy_88e1512_sgmii_to_copper(ULTRA_MV88E1512_PHYADDR);
> > > > > >
> > > > > > +     /*
> > > > > > +      * FIXME: remove this code once Topaz driver gets available
> > > > > > +      * A3720 ESPRESSObin Ultra Board Only
> > > > > > +      * Configure Topaz switch (88E6341)
> > > > > > +      * Set port 1,2,3,4,5 to forwarding Mode (through Switch Port registers)
> > > > > > +      */
> > > > > > +     for (i = 0; i <= 5; i++) {
> > > > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(i),
> > > > > > +                                       MVEBU_SW_PORT_CTRL_REG,
> > > > > > +                                       i == 5 ? 0x7c : 0x7f);
> > > > >
> > > > > Why port 5 has different settings?
> > > >
> > > > It's to disable forwarding between the WAN port and LAN ports (I've
> > > > tested this).
> > > > I'm aware of this thread:
> > > > https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/issues/18
> > >
> > > Ok. But your change seems to not be correct. I'm looking at
> > > documentation and when low 2 bits in Port Control Register are zero then
> > > specified port is completely disabled.
> > >
> > > I agree that for disabled port is obviously disabled also forwarding.
> > > But I do not think it is what you want... Or, which behavior you want to
> > > achieve? From above added comment (which seems to be also copy+paste) it
> > > is not clear.
> > >
> >
> > I think it would be completely fine if the WAN port is disabled in U-Boot.
> > The current behaviour is that the LAN ports forward between each other and
> > are all accessible from U-Boot, while the WAN port is in no way accessible.
> > The link is up when testing the WAN port, but no traffic passes.
>
> For espressobin v5/v7 all ports are enabled, but forwarding is possible
> only in directions: "cpu to any non-cpu port" and "non-cpu port to cpu
> port". So between lan ports it is disabled and also between lan an wan.
>
> User may have custom settings in Linux where want to use e.g. two ports
> as wans (e.g. use one lan labeled port as wan2) and then during u-boot
> stage it would would break his network. That is why also forwarding
> between lan labeled ports is disabled.

I see, that makes sense.
I'll find a way to implement it like this.

>
> Or user may use custom vlan settings with authentication and then
> enabled forwarding in u-boot also can break network. This industrial
> Topaz switch has lot of HW functionality, so it is ideal for such kind
> of usage.
>
> > > Look at that my change which only disables forwarding between ports. And
> > > does not disable ports itself. It is already in newly renamed function
> > > board_network_enable_espressobin(). That is why I do not like copy+paste
> > > of code as it can be copied incorrectly, or differently without
> > > describing commenting why it is differently.
> > >
> > > I see that board_network_enable_espressobin_ultra() and
> > > board_network_enable_espressobin() are different. But they have some
> > > common parts, e.g. this port policy configuration. So at least this code
> > > path can be moved in some common function.
> >
> > I agree, these could be somehow unified. I will take a look.
> >
> > >
> > > > >
> > > > > > +     }
> > > > > > +
> > > > > > +     /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
> > > > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_PORT_CTRL_SMI_ADDR(0),
> > > > > > +                               MVEBU_SW_LINK_CTRL_REG, 0xe002);
> > > > > > +
> > > > > > +     /* Power up PHY 1, 2, 3, 4, 5 (through Global 2 registers) */
> > > > > > +     mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > > > +                               MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
> > > > > > +     for (i = 1; i <= 5; i++) {
> > > > > > +             mii_multi_chip_mode_write(bus, 3, MVEBU_SW_G2_SMI_ADDR,
> > > > > > +                                       MVEBU_G2_SMI_PHY_CMD_REG, 0x9400 +
> > > > > > +                                       (MVEBU_PORT_CTRL_SMI_ADDR(i) << 5));
> > > > > > +     }
> > > > >
> > > > > It looks like that by copying board_network_enable_espressobin_ultra()
> > > > > function from Marvell U-Boot instead of using code which is in mainline
> > > > > function board_network_enable() for Espressobin, you are introducing a
> > > > > security hole, which is in Marvell U-Boot and which was fixed in
> > > > > mainline U-Boot for all supported Espressobin boards (see commit
> > > > > 48f2c8a37f700859a7004dce5adb116597a45700).
> > > > >
> > > > > I would really suggest to not blindly copy old code from Marvell into
> > > > > mainline U-Boot, as here we have fixed lot of issues.
> > > > >
> > > > > > +     return 0;
> > > > > > +}
> > > > > > +
> > > > > > +int board_network_enable_espressobin(struct mii_dev *bus)
> > > > > > +{
> > > > > >       /*
> > > > > >        * FIXME: remove this code once Topaz driver gets available
> > > > > >        * A3720 Community Board Only
> > > > > > @@ -328,6 +394,16 @@ int board_network_enable(struct mii_dev *bus)
> > > > > >       return 0;
> > > > > >  }
> > > > > >
> > > > > > +/* Bring-up the board-specific networking */
> > > > > > +int board_network_enable(struct mii_dev *bus)
> > > > > > +{
> > > > > > +     if (of_machine_is_compatible("globalscale,espressobin"))
> > > > > > +             return board_network_enable_espressobin(bus);
> > > > > > +     if (of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > > > > +             return board_network_enable_espressobin_ultra(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)
> > > > > >  {
> > > > > > @@ -336,8 +412,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > > > > >       int parts_off;
> > > > > >       int part_off;
> > > > > >
> > > > > > -     /* Fill SPI MTD partitions for Linux kernel on Espressobin */
> > > > > > -     if (!of_machine_is_compatible("globalscale,espressobin"))
> > > > > > +     /*
> > > > > > +      * Fill SPI MTD partitions for the Linux kernel on ESPRESSOBin and
> > > > > > +      * ESPRESSOBin Ultra boards.
> > > > > > +      */
> > > > > > +     if (!of_machine_is_compatible("globalscale,espressobin") &&
> > > > > > +         !of_machine_is_compatible("globalscale,espressobin-ultra"))
> > > > > >               return 0;
> > > > >
> > > > > According to kernel DTS file, it looks like that Espressobin Ultra has
> > > > > different MTD partitions as other variants... Therefore Ultra needs
> > > > > adjustments in this code.
> > > > >
> > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/marvell/armada-3720-espressobin-ultra.dts?h=v5.13#n78
> > > >
> > > > That's true, I'll have to fix this.
> > >
> > > It is needed to call this function for ultra variant at all? Because as
> > > I understand ultra variant has fixed layout as specified in kernel DTS
> > > file and therefore it should not have any dynamic modification.
> > >
> > > Or is there any other issue?
>
> (This was about MTD partitions)

This won't be needed, thanks for pointing it out.

>
> > If the ports aren't correctly configured in U-Boot, Linux fails to configure the
> > Topaz switch.
>
> So this is a bug in Linux. Kernel really should not depend on specific
> network configuration done by bootloader.
>
> So DTS file for Ultra variant in Linux kernel is incomplete?
>
> I remember that DTS was merged into Linux kernel, but there were some
> issues and I do not know if they were fixed later after merging...

The DTS in the Linux kernel should be fine regarding networking, I think.
There was some issue with USB 3, so the node was disabled.

I'll check if it can be resolved.

>
> > In the current configuration traffic between LAN and WAN is blocked in U-Boot
> > and Linux correctly configures the Topaz switch.
> >
> > >
> > > > >
> > > > > >
> > > > > >       spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> > > >
> > > > Kind regards,
> > > > Luka
> >
> > Kind regards,
> > Luka

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-08-13 10:46             ` Pali Rohár
@ 2021-09-24 18:30               ` Pali Rohár
  2021-09-27  8:31                 ` Luka Kovacic
  0 siblings, 1 reply; 36+ messages in thread
From: Pali Rohár @ 2021-09-24 18:30 UTC (permalink / raw)
  To: Luka Kovacic
  Cc: Stefan Roese, u-boot, Robert Marko, Luka Perkov, Marek Behun,
	sjg, patrick.delaunay, xypron.glpk

On Friday 13 August 2021 12:46:38 Pali Rohár wrote:
> On Friday 13 August 2021 12:25:46 Luka Kovacic wrote:
> > Hello Stefan and Pali,
> > 
> > On Fri, Aug 13, 2021 at 11:58 AM Stefan Roese <sr@denx.de> wrote:
> > >
> > > Hi,
> > >
> > > On 13.08.21 11:54, Pali Rohár wrote:
> > > > On Friday 13 August 2021 11:08:08 Luka Kovacic wrote:
> > > >> Hello Pali,
> > > >>
> > > >> On Fri, Aug 13, 2021 at 10:14 AM Pali Rohár <pali@kernel.org> wrote:
> > > >>>
> > > >>> On Friday 13 August 2021 01:39:38 Luka Kovacic wrote:
> > > >>>> Add initial support for the ESPRESSOBin-Ultra board from Globalscale
> > > >>>> Technologies, Inc.
> > > >>>>
> > > >>>> The board is based on the 64-bit dual-core Marvell Armada 3720 SoC.
> > > >>>> Peripherals:
> > > >>>>   - 5 Gigabit Ethernet ports (WAN has PoE, up to 30W, Topaz 6341 switch)
> > > >>>>   - RTC clock (PCF8563)
> > > >>>>   - USB 3.0 port
> > > >>>>   - USB 2.0 port
> > > >>>>   - 4x LED
> > > >>>>   - UART over Micro-USB
> > > >>>>   - M.2 slot (2280)
> > > >>>>   - Mini PCI-E slot
> > > >>>>
> > > >>>> Additionally, automatic import of the Marvell hw_info parameters is
> > > >>>> enabled via the recently added mac command for A37XX platforms.
> > > >>>> The parameters stored in Marvell hw_info are usually the board serial
> > > >>>> number and MAC addresses.
> > > >>>>
> > > >>>> Signed-off-by: Luka Kovacic <luka.kovacic@sartura.hr>
> > > >>>> Cc: Luka Perkov <luka.perkov@sartura.hr>
> > > >>>> Cc: Robert Marko <robert.marko@sartura.hr>
> > > >>>> ---
> > > >>>>   arch/arm/dts/Makefile                         |   1 +
> > > >>>>   .../arm/dts/armada-3720-espressobin-ultra.dts | 114 ++++++++++
> > > >>>>   arch/arm/dts/armada-3720-espressobin.dts      | 199 +----------------
> > > >>>>   arch/arm/dts/armada-3720-espressobin.dtsi     | 210 ++++++++++++++++++
> > > >>>>   board/Marvell/mvebu_armada-37xx/MAINTAINERS   |   8 +
> > > >>>>   board/Marvell/mvebu_armada-37xx/board.c       |  92 +++++++-
> > > >>>>   .../mvebu_espressobin-ultra-88f3720_defconfig |  93 ++++++++
> > > >>>>   7 files changed, 514 insertions(+), 203 deletions(-)
> > > >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin-ultra.dts
> > > >>>>   create mode 100644 arch/arm/dts/armada-3720-espressobin.dtsi
> > > >>>>   create mode 100644 configs/mvebu_espressobin-ultra-88f3720_defconfig
> > > >>>
> > > >>> Hello Luka! Please look at my comments from previous review:
> > > >>> https://lore.kernel.org/u-boot/20210227004852.5urcwnn6uxehuk72@pali/
> > > >>>
> > > >>> I think it is not a good idea to duplicate espressobin code, specially
> > > >>> now when differences between v5, v7, non-emmc and emmc were
> > > >>> de-duplicated and correctly detected at runtime. Just use one DTS and
> > > >>> one config file and differences can be handled in board code functions
> > > >>> "board_fix_fdt" and "board_late_init".
> > > >>
> > > >> I believe that patching the DTS at runtime diminishes the value of
> > > >> device trees in the first case.
> > > >>
> > > >> As far as the v5, v7, non-emmc and emmc boards go I do understand
> > > >> that, as they are physically similar and more or less different revisions
> > > >> of the same board.
> > > >>
> > > >> The ESPRESSOBin Ultra board is completely different from those boards
> > > >> physically and so I doesn't make sense to me, why we would merge all
> > > >> of them into one device tree.
> > > >
> > > > See email for reasons:
> > > > https://lore.kernel.org/u-boot/20210301154101.ke5j2r3lazjlxrsl@pali/
> > > >
> > > > Anyway, I'm looking at differences between ultra and non-ultra boards
> > > > which are used by U-Boot... And I see only:
> > > > * switch configuration & phy
> > > > * i2c rtc
> > > > * sdhci slot
> > > >
> > > > Other changes are not used by U-Boot (led).
> > > >
> > > > For switch configuration & phy there is already custom code in U-Boot
> > > > board file. For sdhci slot there is also (to enable/disable eMMC after
> > > > detection).
> > > >
> > > > So the only difference is presence of i2c rtc, right?
> > > >
> > > > I guess it does not make much sense to copy and duplicate whole DTS and
> > > > also defconfig file for such small differences. Insertion of just few
> > > > nodes is not a big problem.
> > > >
> > > > These boars are not very different, and having tons of u-boot binaries
> > > > for every combination just complicate it as explained in above email.
> > >
> > > I fully agree with Pali. It's much more conveniant to just have one
> > > U-Boot target (and binary) which can handle multiple board variants
> > > by runtime detection. I would very much welcome to see the support for
> > > the "Ultra" variant added this way.
> > 
> > I understand your points and concerns.
> > 
> > I'm just worried that this counterproductive as I don't see the same thing
> > happening in Linux and looking at this we could make similar arguments
> > for other boards, which aren't so different from the ESPRESSOBin boards
> > with the exception of the name.
> 
> I have already opened this question also in Linux, but there was no feedback:
> https://lore.kernel.org/linux-devicetree/20201022140007.hppmeyt34lubotbc@pali/t/#u
> 
> Anyway, as U-Boot can detect variant of the board, it also can load
> specific DTS kernel file for detected variant. So it has still advantage
> even when Linux does not use it (yet).
> 
> Also another argument is maintenance. This patch adds lot of lines of
> code and lot of them are duplicated. It means that somebody has to
> maintain it. So if Ultra variant can be supported by single binary too
> it should mean less code in U-Boot for Ultra (but needs to check!!!) and
> less code for maintaining.
> 
> > >
> > > > If you need help with this I can try to do something... as I was already
> > > > involved in unification of all v5/v7/emmc/non-emmc variants into one
> > > > binary with one DTS.
> > >
> > > Thanks Pali for all your work here.

Hello Luka! Do you need some help with this?

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support
  2021-09-24 18:30               ` Pali Rohár
@ 2021-09-27  8:31                 ` Luka Kovacic
  0 siblings, 0 replies; 36+ messages in thread
From: Luka Kovacic @ 2021-09-27  8:31 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Stefan Roese, u-boot, Robert Marko, Luka Perkov, Marek Behun,
	sjg, patrick.delaunay, xypron.glpk

Hello Pali,

> Hello Luka! Do you need some help with this?

I wasn't able to get to this yet, as I am working on something else
right now and will circle back to the ESPRESSOBin-Ultra shortly.

Kind regards,
Luka

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2021-09-27  8:32 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 23:39 [PATCH v3 0/3] Add support for the GST ESPRESSOBin-Ultra board Luka Kovacic
2021-08-12 23:39 ` [PATCH v3 1/3] arm: mvebu: mvebu_armada-37xx: Implement the mac command (Marvell hw_info) Luka Kovacic
2021-08-13  1:43   ` Marek Behún
2021-08-13  8:23   ` Pali Rohár
2021-08-13  9:23     ` Luka Kovacic
2021-08-13  9:41       ` Pali Rohár
2021-08-13  9:51         ` Luka Kovacic
2021-08-13 10:09           ` Pali Rohár
2021-08-13 10:16             ` Luka Kovacic
2021-08-13 10:29   ` Pali Rohár
2021-08-13 10:43     ` Luka Kovacic
2021-08-13 10:49       ` Pali Rohár
2021-08-12 23:39 ` [PATCH v3 2/3] arm: mvebu: mvebu_armada-37xx: Define the loadaddr environment variable Luka Kovacic
2021-08-13  8:08   ` Pali Rohár
2021-08-13  8:59     ` Luka Kovacic
2021-08-13  9:31       ` Pali Rohár
2021-08-13  9:33         ` Luka Kovacic
2021-08-13  9:42           ` Pali Rohár
2021-08-13 13:59   ` Pali Rohár
2021-08-16  8:21     ` Luka Kovacic
2021-08-16  8:22       ` Pali Rohár
2021-08-12 23:39 ` [PATCH v3 3/3] arm: mvebu: Initial ESPRESSOBin-Ultra board support Luka Kovacic
2021-08-13  8:14   ` Pali Rohár
2021-08-13  9:08     ` Luka Kovacic
2021-08-13  9:54       ` Pali Rohár
2021-08-13  9:58         ` Stefan Roese
2021-08-13 10:25           ` Luka Kovacic
2021-08-13 10:46             ` Pali Rohár
2021-09-24 18:30               ` Pali Rohár
2021-09-27  8:31                 ` Luka Kovacic
2021-08-13  9:27   ` Pali Rohár
2021-08-13 10:03     ` Luka Kovacic
2021-08-13 10:22       ` Pali Rohár
2021-08-13 10:33         ` Luka Kovacic
2021-08-13 10:59           ` Pali Rohár
2021-08-16  8:37             ` Luka Kovacic

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.