All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hal Feng <hal.feng@starfivetech.com>
To: Leo <ycliang@andestech.com>, Tom Rini <trini@konsulko.com>,
	Rick Chen <rick@andestech.com>,
	Sumit Garg <sumit.garg@kernel.org>,
	Emil Renner Berthing <emil.renner.berthing@canonical.com>,
	Heinrich Schuchardt <heinrich.schuchardt@canonical.com>,
	E Shattow <e@freeshell.de>
Cc: Hal Feng <hal.feng@starfivetech.com>, u-boot@lists.denx.de
Subject: [RFC 05/10] eeprom: starfive: Update eeprom data format version to 3
Date: Fri, 29 Aug 2025 14:09:26 +0800	[thread overview]
Message-ID: <20250829060931.79940-6-hal.feng@starfivetech.com> (raw)
In-Reply-To: <20250829060931.79940-1-hal.feng@starfivetech.com>

Add eeprom data format v3 support.
Add wifi_bt field in ATOM4 and add "mac wifi_bt <?>" command to modify it.
Set or show eth0/1 MAC address only if the board has eth0/1.

Signed-off-by: Hal Feng <hal.feng@starfivetech.com>
---
 .../visionfive2/visionfive2-i2c-eeprom.c      | 91 ++++++++++++++++---
 1 file changed, 78 insertions(+), 13 deletions(-)

diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
index 43b8af4fc59..7352252c475 100644
--- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
+++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
@@ -11,7 +11,7 @@
 #include <u-boot/crc.h>
 #include <linux/delay.h>
 
-#define FORMAT_VERSION		0x2
+#define FORMAT_VERSION		0x3
 #define PCB_VERSION		0xB1
 #define BOM_VERSION		'A'
 /*
@@ -105,7 +105,8 @@ struct eeprom_atom4_data {
 	u8 bom_revision;		/* BOM version */
 	u8 mac0_addr[MAC_ADDR_BYTES];	/* Ethernet0 MAC */
 	u8 mac1_addr[MAC_ADDR_BYTES];	/* Ethernet1 MAC */
-	u8 reserved[2];
+	u8 wifi_bt;			/* WIFI/BT support flag */
+	u8 reserved;
 };
 
 struct starfive_eeprom_atom4 {
@@ -128,6 +129,35 @@ static union {
 /* Set to 1 if we've read EEPROM into memory */
 static int has_been_read __section(".data");
 
+static const char * const board_no_eth0_list[] = {
+	"FML13V01",
+};
+
+static const char * const board_no_eth1_list[] = {
+	"FML13V01",
+	"MARS",
+	"VF7110SL",
+};
+
+static bool board_have_eth(u8 eth)
+{
+	int i;
+
+	if (eth == 0) {
+		for (i = 0 ; i < ARRAY_SIZE(board_no_eth0_list); i++)
+			if (!strncmp(pbuf.eeprom.atom1.data.pstr, board_no_eth0_list[i],
+				     strlen(board_no_eth0_list[i])))
+				return false;
+	} else {
+		for (i = 0 ; i < ARRAY_SIZE(board_no_eth1_list); i++)
+			if (!strncmp(pbuf.eeprom.atom1.data.pstr, board_no_eth1_list[i],
+				     strlen(board_no_eth1_list[i])))
+				return false;
+	}
+
+	return true;
+}
+
 static inline int is_match_magic(void)
 {
 	return strncmp(pbuf.eeprom.header.signature, STARFIVE_EEPROM_HATS_SIG,
@@ -176,17 +206,22 @@ static void show_eeprom(void)
 	printf("Vendor : %s\n", pbuf.eeprom.atom1.data.vstr);
 	printf("Product full SN: %s\n", pbuf.eeprom.atom1.data.pstr);
 	printf("data version: 0x%x\n", pbuf.eeprom.atom4.data.version);
-	if (pbuf.eeprom.atom4.data.version == 2) {
+	if (pbuf.eeprom.atom4.data.version >= 2 && pbuf.eeprom.atom4.data.version <= 3) {
 		printf("PCB revision: 0x%x\n", pbuf.eeprom.atom4.data.pcb_revision);
 		printf("BOM revision: %c\n", pbuf.eeprom.atom4.data.bom_revision);
-		printf("Ethernet MAC0 address: %02x:%02x:%02x:%02x:%02x:%02x\n",
-		       pbuf.eeprom.atom4.data.mac0_addr[0], pbuf.eeprom.atom4.data.mac0_addr[1],
-		       pbuf.eeprom.atom4.data.mac0_addr[2], pbuf.eeprom.atom4.data.mac0_addr[3],
-		       pbuf.eeprom.atom4.data.mac0_addr[4], pbuf.eeprom.atom4.data.mac0_addr[5]);
-		printf("Ethernet MAC1 address: %02x:%02x:%02x:%02x:%02x:%02x\n",
-		       pbuf.eeprom.atom4.data.mac1_addr[0], pbuf.eeprom.atom4.data.mac1_addr[1],
-		       pbuf.eeprom.atom4.data.mac1_addr[2], pbuf.eeprom.atom4.data.mac1_addr[3],
-		       pbuf.eeprom.atom4.data.mac1_addr[4], pbuf.eeprom.atom4.data.mac1_addr[5]);
+		if (board_have_eth(0))
+			printf("Ethernet MAC0 address: %02x:%02x:%02x:%02x:%02x:%02x\n",
+			pbuf.eeprom.atom4.data.mac0_addr[0], pbuf.eeprom.atom4.data.mac0_addr[1],
+			pbuf.eeprom.atom4.data.mac0_addr[2], pbuf.eeprom.atom4.data.mac0_addr[3],
+			pbuf.eeprom.atom4.data.mac0_addr[4], pbuf.eeprom.atom4.data.mac0_addr[5]);
+
+		if (board_have_eth(1))
+			printf("Ethernet MAC1 address: %02x:%02x:%02x:%02x:%02x:%02x\n",
+			pbuf.eeprom.atom4.data.mac1_addr[0], pbuf.eeprom.atom4.data.mac1_addr[1],
+			pbuf.eeprom.atom4.data.mac1_addr[2], pbuf.eeprom.atom4.data.mac1_addr[3],
+			pbuf.eeprom.atom4.data.mac1_addr[4], pbuf.eeprom.atom4.data.mac1_addr[5]);
+		if (pbuf.eeprom.atom4.data.version >= 3)
+			printf("WIFI/BT support: %x\n", pbuf.eeprom.atom4.data.wifi_bt);
 	} else {
 		printf("Custom data v%d is not Supported\n", pbuf.eeprom.atom4.data.version);
 		dump_raw_eeprom();
@@ -260,6 +295,7 @@ static void init_local_copy(void)
 	pbuf.eeprom.atom4.data.bom_revision = BOM_VERSION;
 	set_mac_address(STARFIVE_DEFAULT_MAC0, 0);
 	set_mac_address(STARFIVE_DEFAULT_MAC1, 1);
+	pbuf.eeprom.atom4.data.wifi_bt = 0;
 }
 
 /**
@@ -385,6 +421,28 @@ static void set_bom_revision(char *string)
 	update_crc();
 }
 
+/**
+ * set_wifi_bt() - stores a StarFive WIFI/BT support flag into the local EEPROM copy
+ *
+ * Takes a pointer to a string representing the numeric WIFI/BT support flag in
+ * decimal ("0" or "1"), stores it in the wifi_bt field of the
+ * EEPROM local copy, and updates the CRC of the local copy.
+ */
+static void set_wifi_bt(char *string)
+{
+	u8 wifi_bt;
+
+	wifi_bt = simple_strtoul(string, &string, 16);
+	if (wifi_bt > 1) {
+		printf("WIFI/BT support flag must not be greater than 1");
+		return;
+	}
+
+	pbuf.eeprom.atom4.data.wifi_bt = wifi_bt;
+
+	update_crc();
+}
+
 /**
  * set_product_id() - stores a StarFive product ID into the local EEPROM copy
  *
@@ -478,6 +536,9 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	} else if (!strcmp(cmd, "bom_revision")) {
 		set_bom_revision(argv[2]);
 		return 0;
+	} else if (!strcmp(cmd, "wifi_bt")) {
+		set_wifi_bt(argv[2]);
+		return 0;
 	} else if (!strcmp(cmd, "product_id")) {
 		set_product_id(argv[2]);
 		return 0;
@@ -513,8 +574,10 @@ int mac_read_from_eeprom(void)
 	}
 
 	// 1, setup ethaddr env
-	eth_env_set_enetaddr("ethaddr", pbuf.eeprom.atom4.data.mac0_addr);
-	eth_env_set_enetaddr("eth1addr", pbuf.eeprom.atom4.data.mac1_addr);
+	if (board_have_eth(0))
+		eth_env_set_enetaddr("ethaddr", pbuf.eeprom.atom4.data.mac0_addr);
+	if (board_have_eth(1))
+		eth_env_set_enetaddr("eth1addr", pbuf.eeprom.atom4.data.mac1_addr);
 
 	/**
 	 * 2, setup serial# env, reference to hifive-platform-i2c-eeprom.c,
@@ -585,6 +648,8 @@ U_BOOT_LONGHELP(mac,
 	"    - stores a StarFive PCB revision into the local EEPROM copy\n"
 	"mac bom_revision <A>\n"
 	"    - stores a StarFive BOM revision into the local EEPROM copy\n"
+	"mac wifi_bt <?>\n"
+	"    - stores a StarFive WIFI/BT support flag into the local EEPROM copy\n"
 	"mac product_id <VF7110A1-2228-D008E000-xxxxxxxx>\n"
 	"    - stores a StarFive product ID into the local EEPROM copy\n"
 	"mac vendor <Vendor Name>\n"
-- 
2.43.2


  parent reply	other threads:[~2025-08-29 14:31 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  6:09 [RFC 00/10] Add support for StarFive VisionFive 2 Lite board Hal Feng
2025-08-29  6:09 ` [RFC 01/10] riscv: dts: starfive: jh7110-common: Move out some nodes to the board dts Hal Feng
2025-08-29  7:19   ` Heinrich Schuchardt
2025-09-02 16:17     ` E Shattow
2025-10-22  9:59       ` Hal Feng
2025-10-22 11:26         ` E Shattow
2025-08-29  6:09 ` [RFC 02/10] riscv: dts: starfive: Add VisionFive 2 Lite board device tree Hal Feng
2025-09-02 20:03   ` E Shattow
2025-09-03 11:07     ` Sumit Garg
2025-09-03 12:03       ` Heinrich Schuchardt
2025-09-04  2:39       ` Hal Feng
2025-08-29  6:09 ` [RFC 03/10] eeprom: starfive: Simplify get_ddr_size_from_eeprom() Hal Feng
2025-08-29  7:33   ` Heinrich Schuchardt
2025-09-02 21:28     ` E Shattow
2025-09-02 22:18       ` Heinrich Schuchardt
2025-10-21  9:20       ` Hal Feng
2025-10-21 19:04         ` E Shattow
2025-08-29  6:09 ` [RFC 04/10] eeprom: starfive: Correct get_pcb_revision_from_eeprom() Hal Feng
2025-08-29  7:44   ` Heinrich Schuchardt
2025-09-02  7:44     ` Hal Feng
2025-09-02 22:12       ` E Shattow
2025-09-02 22:32         ` Heinrich Schuchardt
2025-10-22  3:02           ` Hal Feng
2025-10-22  8:44             ` Hal Feng
2025-08-29  6:09 ` Hal Feng [this message]
2025-08-29  7:47   ` [RFC 05/10] eeprom: starfive: Update eeprom data format version to 3 Heinrich Schuchardt
2025-09-02  7:10     ` Hal Feng
2025-09-02 23:29   ` E Shattow
2025-10-22  5:55     ` Hal Feng
2025-08-29  6:09 ` [RFC 06/10] pcie: starfive: Add a optional power gpio support Hal Feng
2025-09-02 23:47   ` E Shattow
2025-10-22  6:13     ` Hal Feng
2025-08-29  6:09 ` [RFC 07/10] riscv: dts: jh7110: Add StarFive VisionFive 2 Lite u-boot device tree Hal Feng
2025-09-03  0:00   ` E Shattow
2025-08-29  6:09 ` [RFC 08/10] configs: visionfive2: Add VisionFive 2 Lite DT to OF_LIST Hal Feng
2025-09-03  0:15   ` E Shattow
2025-10-22  7:12     ` Hal Feng
2025-08-29  6:09 ` [RFC 09/10] board: starfive: spl: Support VisionFive 2 Lite Hal Feng
2025-09-03  0:21   ` E Shattow
2025-08-29  6:09 ` [RFC 10/10] board: starfive: visionfive2: Add VisionFive 2 Lite fdt selection Hal Feng
2025-09-03  0:26   ` E Shattow
2025-09-03  4:34     ` Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250829060931.79940-6-hal.feng@starfivetech.com \
    --to=hal.feng@starfivetech.com \
    --cc=e@freeshell.de \
    --cc=emil.renner.berthing@canonical.com \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=rick@andestech.com \
    --cc=sumit.garg@kernel.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.