From: David Picard <david.picard@clermont.in2p3.fr>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: David Picard <david.picard@clermont.in2p3.fr>
Subject: [PATCH v2 10/10] boards: enclustra-sa2: read S/N from EEPROM
Date: Thu, 25 Sep 2025 13:59:17 +0200 [thread overview]
Message-ID: <20250925-boards-enclustra-sa2-add-support-v2-10-6820ad6c6256@clermont.in2p3.fr> (raw)
In-Reply-To: <20250925-boards-enclustra-sa2-add-support-v2-0-6820ad6c6256@clermont.in2p3.fr>
Read the SoM serial number from the EEPROM and set it in the
Barebox environment. The serial number can be checked:
- in Barebox, printenv global.serial_number
- in Linux, cat /proc/device-tree/serial-number
Signed-off-by: David Picard <david.picard@clermont.in2p3.fr>
---
arch/arm/boards/enclustra-sa2/board.c | 38 ++++++++++++++++++++++++++
arch/arm/dts/socfpga_cyclone5_mercury_sa2.dtsi | 12 ++++++++
2 files changed, 50 insertions(+)
diff --git a/arch/arm/boards/enclustra-sa2/board.c b/arch/arm/boards/enclustra-sa2/board.c
index d2e539cbf9460adddc158885473f4ef0004dc284..03539132654716460cedc2a6edcaf13935dea22c 100644
--- a/arch/arm/boards/enclustra-sa2/board.c
+++ b/arch/arm/boards/enclustra-sa2/board.c
@@ -19,6 +19,7 @@
/** Enclustra's MAC address vendor prefix is 20:B0:F7 */
#define ENCLUSTRA_PREFIX (0x20b0f7)
#define MAC_ADDR_NUM_BYTES (6)
+#define SERIAL_NUMBER_NUM_BYTES (4)
/*
* Ethernet PHY: Microchip/Micrel KSZ9031RNX
@@ -89,6 +90,42 @@ static void set_mac_addr(void)
eth_register_ethaddr(1, enclustra_ethaddr_fallback2);
}
+/*
+ * Read the SoM serial number via the atsha204a driver.
+ */
+static void set_ser_num(void)
+{
+ u8 *data = NULL;
+ uint32_t ser_num = 0;
+ char ser_num_str[12];
+ static const char * const aliases[] = { "som-sernum" };
+ struct device_node *np, *root;
+
+ root = of_get_root_node();
+
+ for (int i = 0; i < ARRAY_SIZE(aliases); i++) {
+ const char *alias = aliases[i];
+
+ np = of_find_node_by_alias(root, alias);
+ if (!np) {
+ pr_warn("%s() >> ERROR: can't find alias %s\n", __func__, alias);
+ continue;
+ }
+ data = nvmem_cell_get_and_read(np, "serial-number",
+ SERIAL_NUMBER_NUM_BYTES);
+ if (IS_ERR(data)) {
+ pr_warn("%s() >> ERROR: can't read NVMEM cell\n", __func__);
+ data = NULL;
+ }
+ }
+ if (!data)
+ return;
+
+ ser_num = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ sprintf(ser_num_str, "%d", ser_num);
+ barebox_set_serial_number(ser_num_str);
+}
+
static int socfpga_init(void)
{
if (!of_machine_is_compatible("enclustra,mercury-sa2"))
@@ -99,6 +136,7 @@ static int socfpga_init(void)
phy_fixup);
set_mac_addr();
+ set_ser_num();
#ifdef CONFIG_MACH_SOCFPGA_ENCLUSTRA_SA2_SI5338
/* configure clock generator on the Enclustra ST1 baseboard: */
diff --git a/arch/arm/dts/socfpga_cyclone5_mercury_sa2.dtsi b/arch/arm/dts/socfpga_cyclone5_mercury_sa2.dtsi
index 78ba8008af5d60f10d6a64b0f05e97bf2381079c..ade6f4f6df3a329ee404b2b7a70fcd00c8815fdd 100644
--- a/arch/arm/dts/socfpga_cyclone5_mercury_sa2.dtsi
+++ b/arch/arm/dts/socfpga_cyclone5_mercury_sa2.dtsi
@@ -24,6 +24,7 @@ chosen {
aliases {
ethernet0 = &gmac1;
+ som-sernum = "/serial-number";
};
/* Adjusted the i2c labels to use generic base-board dtsi files for
@@ -46,6 +47,11 @@ memory {
device_type = "memory";
reg = <0x0 0x80000000>; /* 2GB */
};
+
+ serial-number {
+ nvmem-cells = <&ser_num>;
+ nvmem-cell-names = "serial-number";
+ };
};
&osc1 {
@@ -82,6 +88,12 @@ nvmem-layout {
#address-cells = <1>;
#size-cells = <1>;
+ ser_num: serial-number@0 {
+ reg = <0x00 0x4>;
+ nvmem-cell-cells = <1>;
+ nvmem-cell-names = "serial-number";
+ };
+
mac_address_0: mac@10 {
compatible = "mac-base";
reg = <0x10 0x6>;
--
2.43.0
next prev parent reply other threads:[~2025-09-25 12:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 11:59 [PATCH v2 00/10] ARM: boards: add support for Enclustra Mercury SA2 David Picard
2025-09-25 11:59 ` [PATCH v2 01/10] Add handoff files David Picard
2025-09-25 11:59 ` [PATCH v2 02/10] Add Enclustra Mercury+ SA2 module David Picard
2025-09-25 11:59 ` [PATCH v2 03/10] ARM: dts: socfpga: use upstream SA2 device tree David Picard
2025-09-25 11:59 ` [PATCH v2 04/10] ARM: dts: socfpga: adapt " David Picard
2025-09-25 11:59 ` [PATCH v2 05/10] boards: enclustra-sa2: read MAC address from EEPROM David Picard
2025-09-26 12:40 ` Sascha Hauer
2025-09-26 12:57 ` David Picard
2025-09-29 8:04 ` David Picard
2025-09-25 11:59 ` [PATCH v2 06/10] boards: enclustra-sa2: configure SI5338 David Picard
2025-09-25 11:59 ` [PATCH v2 07/10] boards: enclustra-sa2: enable SI5338 David Picard
2025-09-25 11:59 ` [PATCH v2 08/10] lib: add crc16 support David Picard
2025-09-26 12:43 ` Sascha Hauer
2025-09-25 11:59 ` [PATCH v2 09/10] nvmem: add support for Atmel sha204(a) David Picard
2025-09-25 11:59 ` David Picard [this message]
2025-09-26 12:47 ` [PATCH v2 00/10] ARM: boards: add support for Enclustra Mercury SA2 Sascha Hauer
2025-09-30 10:40 ` Sascha Hauer
2025-09-30 11:47 ` David Picard
2025-09-30 11:49 ` David Picard
[not found] ` <aade6cdb-3244-4468-8bab-215a54fdef15@clermont.in2p3.fr>
2025-10-01 8:29 ` Sascha Hauer
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=20250925-boards-enclustra-sa2-add-support-v2-10-6820ad6c6256@clermont.in2p3.fr \
--to=david.picard@clermont.in2p3.fr \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox