* [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID
@ 2026-11-25 19:36 Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 1/5] dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID Alexey Charkov
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
Rockchip SoCs are shipped with a unique CPU ID in their internal OTP
memory, and Rockchip bootloaders use it to give boards which have no
dedicated storage for a MAC address a stable one anyway: they hash the CPU
ID and patch the resulting addresses into the device tree they hand over.
Kernels started without that fixup, e.g. straight from the SPL in Falcon
mode or by any other loader which does not implement Rockchip's derivation,
fall back to random MAC addresses which change on every boot.
Derive the addresses in of_get_mac_address() instead, as the last resort
after any stored address, from a "unique-id" NVMEM cell referenced by
the Ethernet controller, so that a Linux image can use the same stable
addresses regardless of the boot flow.
v5 moves the derivation out of the OTP driver following Andrew's review
of v4. The CPU ID cell keeps returning the raw CPU ID to everyone, and
the Ethernet controller references it as its unique ID rather than as
its MAC address. The derivation is picked by the compatible of the
referenced cell, as the algorithms differ between vendors: Allwinner and
Amlogic bootloaders also derive addresses from chip IDs, each in their
own way. The addresses are indexed by the controller's "ethernetN"
alias, which is how the bootloaders assign them to interfaces. Doing it
in of_net.c lets any controller with a device tree node use it,
including PCIe ones, and needs no changes to NVMEM or to the handling of
"mac-address" cells.
On the Rockchip side, the existing CPU ID cell gets a "rockchip,cpuid"
compatible. Its location comes from the cell's reg property, so no
per-SoC data is needed, and other SoCs only need the compatible on their
CPU ID cell plus the references from their Ethernet controllers.
Controllers without an "ethernetN" alias keep getting random addresses,
as they would with the bootloaders.
Patch 4 moves the RK3576 OTP cells from the deprecated direct-child
syntax into a fixed layout, as the former does not allow a compatible on
a cell.
Only RK3576 is wired up here, that being the SoC I can test on.
Cross-checked on an RK3576 board: the addresses fixed up into the FDT by
U-Boot match the ones derived from the CPU ID, and both GMACs get them
when the kernel is booted without U-Boot proper at all (via Falcon
mode). The raw CPU ID cell remains readable alongside (e.g. via sysfs).
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
Changes in v5:
- Moved the derivation from the rockchip-otp driver into
of_get_mac_address(), with the Ethernet controller referencing the CPU
ID as a "unique-id" NVMEM cell (Andrew)
- Indexed the addresses by the controller's "ethernetN" alias instead of
a cell argument, matching how the bootloaders assign them
- Added "unique-id" to the ethernet-controller binding
- Dropped #nvmem-cell-cells from the "rockchip,cpuid" cell
- Dropped the net change accepting longer "mac-address" cells and the
OTP post-processor
- Did not carry over Ryan's Tested-by from v4, as the implementation
changed
- Link to v4: https://patch.msgid.link/20261124-rk3576-otp-cpuid-mac-v4-0-d403b8a25113@flipper.net
Changes in v4:
- Dropped the NVMEM core change letting post-processing shorten the
output, as cells have a fixed size (Srinivas)
- Added a net change letting the NVMEM MAC address helpers take the
first six bytes of a longer cell instead
- Made the OTP post-processor write the address into the first six
bytes of the CPU ID cell, keeping its size
- Link to v3: https://patch.msgid.link/20261123-rk3576-otp-cpuid-mac-v3-0-40c756dcf36f@flipper.net
Changes in v3:
- Dropped the OTP read serialization patch, applied separately
- Replaced the SoC-specific NVMEM layout with a "rockchip,cpuid"
compatible on the existing CPU ID fixed cell, so that it works
alongside other fixed cells (Ricardo) and needs no per-SoC table (Ryan)
- Moved the derivation into the rockchip-otp driver's cell fixup hook,
which also makes the layout module unload issue moot (Sashiko)
- Made #nvmem-cell-cells required for the new compatible (Sashiko)
- Dropped the dead match data and address validity checks (Srinivas)
- Allowed MAC address indices up to 255 rather than just 0 and 1
- Added an NVMEM core change letting post-processing shorten the output
- Moved the RK3576 OTP cells into a fixed layout
- Dropped Miquel's Reviewed-by from the driver patch, as the code moved
- Link to v2: https://patch.msgid.link/20260902-rk3576-otp-cpuid-mac-v2-0-e4b7fe2ab13f@flipper.net
Changes in v2:
- Switched from a scope-based guard to explicit lock/unlock calls in the
OTP driver to avoid mixing styles in a function using goto error
handling (Sashiko)
- Link to v1: https://patch.msgid.link/20260901-rk3576-otp-cpuid-mac-v1-0-ea9135270fc2@flipper.net
---
Alexey Charkov (5):
dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID
dt-bindings: net: ethernet-controller: Allow a unique ID NVMEM cell
net: of_net: Derive MAC addresses from a unique device ID
arm64: dts: rockchip: Move RK3576 OTP cells into a fixed layout
arm64: dts: rockchip: Derive GMAC MAC addresses from OTP on RK3576
.../bindings/net/ethernet-controller.yaml | 11 ++-
.../bindings/nvmem/layouts/fixed-cell.yaml | 24 +++++
.../bindings/nvmem/layouts/fixed-layout.yaml | 5 +
arch/arm64/boot/dts/rockchip/rk3576.dtsi | 110 +++++++++++----------
net/core/of_net.c | 105 +++++++++++++++++++-
5 files changed, 200 insertions(+), 55 deletions(-)
---
base-commit: 3dd8c790a7b7027abdd568e36db5e82ffaea7c77
change-id: 20260901-rk3576-otp-cpuid-mac-3c90243d0884
Best regards,
--
Alexey Charkov <alchark@flipper.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 1/5] dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
@ 2026-11-25 19:36 ` Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 2/5] dt-bindings: net: ethernet-controller: Allow a unique ID NVMEM cell Alexey Charkov
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
Rockchip SoCs ship with a unique CPU ID programmed into their OTP memory,
and compatible bootloaders derive Ethernet MAC addresses from it, so that
boards with no dedicated storage for one still get a stable address.
Whether a board ends up with those addresses then depends on the
bootloader patching them into the device tree.
Describe the CPU ID cell with a compatible which also defines that
derivation for Ethernet controllers referencing the cell as their unique
ID, so that the addresses are available to anything which reads the
device tree, whatever the boot flow. Index the addresses by the
controller's "ethernetN" alias, which is how the bootloaders assign
them. Keep the compatible vendor-wide, as only the location of the CPU
ID differs between SoCs, and that is given by the reg property already.
Plain "mac-base" does not fit: the CPU ID is not a MAC address in either
of the formats it allows, and may require different processing vs. adding
an offset to the base.
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
.../bindings/nvmem/layouts/fixed-cell.yaml | 24 ++++++++++++++++++++++
.../bindings/nvmem/layouts/fixed-layout.yaml | 5 +++++
2 files changed, 29 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
index 38e3ad50ff4f..3acf306612ad 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
@@ -19,6 +19,17 @@ properties:
addresses.
It can be stored in a plain binary format (cell length 6) or as an
ASCII text like "00:11:22:33:44:55" (cell length 17).
+ - const: rockchip,cpuid
+ description: >
+ Cell with the unique CPU ID of a Rockchip SoC (cell length 16).
+ An Ethernet controller referencing it as its "unique-id" NVMEM cell
+ derives its MAC address from it. The base of such addresses consists
+ of the first six octets of the SHA-256 digest of the 32-character
+ string of lowercase hexadecimal digits representing the 16 CPU ID
+ bytes in stored order, without separators or a terminator. In the
+ first octet, the multicast bit (bit 0) is then cleared and the
+ locally administered bit (bit 1) set. The number N of the
+ controller's "ethernetN" alias is XORed into the last octet.
reg:
maxItems: 1
@@ -48,6 +59,19 @@ allOf:
const: 1
required:
- "#nvmem-cell-cells"
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: rockchip,cpuid
+ required: [ compatible ]
+ then:
+ properties:
+ reg:
+ items:
+ - items:
+ - description: Offset of the CPU ID
+ - const: 16
required:
- reg
diff --git a/Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml
index b01567f99284..a1935bb49282 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml
@@ -56,6 +56,11 @@ examples:
#nvmem-cell-cells = <1>;
};
+ id@200 {
+ compatible = "rockchip,cpuid";
+ reg = <0x200 0x10>;
+ };
+
calibration@4000 {
reg = <0x4000 0x100>;
};
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 2/5] dt-bindings: net: ethernet-controller: Allow a unique ID NVMEM cell
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 1/5] dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID Alexey Charkov
@ 2026-11-25 19:36 ` Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID Alexey Charkov
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
Boards without dedicated storage for a MAC address often still have an
identifier unique to the device, such as a SoC serial number in OTP
memory, and bootloaders on several platforms derive a stable MAC address
from it. The device tree can only reference a stored MAC address, so
such boards depend on the bootloader patching the derived one in.
Allow referencing the unique ID as a "unique-id" NVMEM cell instead.
Leave the derivation to the binding of the referenced cell, as it differs
between platforms.
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
.../devicetree/bindings/net/ethernet-controller.yaml | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
index 30b2a335116e..6966270ff78b 100644
--- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
@@ -24,10 +24,17 @@ properties:
nvmem-cells:
maxItems: 1
description:
- Reference to an nvmem node for the MAC address
+ Reference to an nvmem node for the MAC address, or for an identifier
+ unique to the device from which the MAC address is derived
nvmem-cell-names:
- const: mac-address
+ oneOf:
+ - const: mac-address
+ - const: unique-id
+ description:
+ Identifier unique to the device, such as a SoC serial number, from
+ which a stable MAC address is derived. How the address is derived
+ is defined by the binding of the referenced cell.
phy-connection-type:
description:
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 1/5] dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 2/5] dt-bindings: net: ethernet-controller: Allow a unique ID NVMEM cell Alexey Charkov
@ 2026-11-25 19:36 ` Alexey Charkov
2026-11-26 4:02 ` Ryan Leung
2026-12-01 1:30 ` Andrew Lunn
2026-11-25 19:36 ` [PATCH v5 4/5] arm64: dts: rockchip: Move RK3576 OTP cells into a fixed layout Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 5/5] arm64: dts: rockchip: Derive GMAC MAC addresses from OTP on RK3576 Alexey Charkov
4 siblings, 2 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
Bootloaders on several platforms derive a stable MAC address from an
identifier unique to the chip, such as a SoC serial number in OTP
memory, so that boards without dedicated storage for an address still
get a persistent one. They patch the result into the device tree they
pass on, which leaves kernels started any other way, e.g. straight from
the SPL in Falcon mode, with a random address changing on every boot.
Derive the address in of_get_mac_address() instead, as the last resort
after any stored one, from a "unique-id" NVMEM cell. Doing it here
rather than in individual drivers lets any controller with a device tree
node use it, including PCIe ones. Pick the derivation by the compatible
of the referenced cell, as the algorithms differ between vendors, and
index the addresses by the device's "ethernetN" alias, which is how the
bootloaders assign them to interfaces.
Start with Rockchip, whose bootloaders hash the CPU ID as a lowercase
hex string with SHA-256 and XOR the index into the last octet. Follow
U-Boot's rockchip_setup_macaddr() exactly, so that both yield the same
addresses.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
net/core/of_net.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 103 insertions(+), 2 deletions(-)
diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248..1f9858d2d444 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -4,7 +4,9 @@
*
* Initially copied out of arch/powerpc/kernel/prom_parse.c
*/
+#include <crypto/sha2.h>
#include <linux/etherdevice.h>
+#include <linux/hex.h>
#include <linux/kernel.h>
#include <linux/of_net.h>
#include <linux/of_platform.h>
@@ -97,6 +99,99 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr)
}
EXPORT_SYMBOL(of_get_mac_address_nvmem);
+#define ROCKCHIP_CPUID_LEN 16
+
+/*
+ * Rockchip bootloaders hash the CPU ID as a lowercase hex string with SHA-256
+ * and XOR the index into the last octet, see rockchip_setup_macaddr() in
+ * U-Boot's arch/arm/mach-rockchip/board.c.
+ */
+static int of_mac_from_rockchip_cpuid(const u8 *id, size_t len, int index,
+ u8 *addr)
+{
+ char hex[ROCKCHIP_CPUID_LEN * 2];
+ u8 digest[SHA256_DIGEST_SIZE];
+
+ if (len != ROCKCHIP_CPUID_LEN || index > U8_MAX)
+ return -EINVAL;
+
+ bin2hex(hex, id, ROCKCHIP_CPUID_LEN);
+ sha256(hex, sizeof(hex), digest);
+
+ memcpy(addr, digest, ETH_ALEN);
+ addr[0] &= 0xfe; /* clear the multicast bit */
+ addr[0] |= 0x02; /* set the locally administered bit */
+ addr[5] ^= index;
+
+ return 0;
+}
+
+struct of_mac_unique_id {
+ const char *compatible;
+ int (*derive)(const u8 *id, size_t len, int index, u8 *addr);
+};
+
+/* Derivations by the compatible of the unique ID cell */
+static const struct of_mac_unique_id of_mac_unique_ids[] = {
+ { "rockchip,cpuid", of_mac_from_rockchip_cpuid },
+};
+
+/*
+ * Derive a MAC address from a "unique-id" NVMEM cell the way the cell's
+ * binding defines it, indexed by the "ethernetN" alias of the device, as that
+ * is how bootloaders assign the derived addresses to interfaces.
+ */
+static int of_get_mac_address_unique_id(struct device_node *np, u8 *addr)
+{
+ const struct of_mac_unique_id *entry = NULL;
+ struct of_phandle_args cell_spec;
+ struct nvmem_cell *cell;
+ int index, alias, ret, i;
+ size_t len;
+ u8 *id;
+
+ index = of_property_match_string(np, "nvmem-cell-names", "unique-id");
+ if (index < 0)
+ return -ENOENT;
+
+ ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
+ "#nvmem-cell-cells",
+ index, &cell_spec);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < ARRAY_SIZE(of_mac_unique_ids); i++) {
+ if (of_device_is_compatible(cell_spec.np,
+ of_mac_unique_ids[i].compatible)) {
+ entry = &of_mac_unique_ids[i];
+ break;
+ }
+ }
+ of_node_put(cell_spec.np);
+ if (!entry)
+ return -EOPNOTSUPP;
+
+ alias = of_alias_get_id(np, "ethernet");
+ if (alias < 0)
+ return alias;
+
+ cell = of_nvmem_cell_get(np, "unique-id");
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ id = nvmem_cell_read(cell, &len);
+ nvmem_cell_put(cell);
+ if (IS_ERR(id))
+ return PTR_ERR(id);
+
+ ret = entry->derive(id, len, alias, addr);
+ kfree(id);
+ if (ret)
+ return ret;
+
+ return is_valid_ether_addr(addr) ? 0 : -EINVAL;
+}
+
/**
* of_get_mac_address()
* @np: Caller's Device Node
@@ -108,7 +203,9 @@ EXPORT_SYMBOL(of_get_mac_address_nvmem);
* because that is the default address. If that isn't set, then the obsolete
* 'address' is checked, just in case we're using an old device tree. If any
* of the above isn't set, then try to get MAC address from nvmem cell named
- * 'mac-address'.
+ * 'mac-address'. As the last resort, derive one from an identifier unique to
+ * the device in an nvmem cell named 'unique-id', if the way to do so is known
+ * for that cell.
*
* Note that the 'address' property is supposed to contain a virtual address of
* the register set, but some DTS files have redefined that property to be the
@@ -142,7 +239,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
if (!ret)
return 0;
- return of_get_mac_address_nvmem(np, addr);
+ ret = of_get_mac_address_nvmem(np, addr);
+ if (!ret || ret == -EPROBE_DEFER)
+ return ret;
+
+ return of_get_mac_address_unique_id(np, addr);
}
EXPORT_SYMBOL(of_get_mac_address);
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 4/5] arm64: dts: rockchip: Move RK3576 OTP cells into a fixed layout
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
` (2 preceding siblings ...)
2026-11-25 19:36 ` [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID Alexey Charkov
@ 2026-11-25 19:36 ` Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 5/5] arm64: dts: rockchip: Derive GMAC MAC addresses from OTP on RK3576 Alexey Charkov
4 siblings, 0 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
The RK3576 OTP describes its cells as direct children of the OTP node,
which is the deprecated syntax predating NVMEM layouts. It does not
allow a compatible on a cell, which describing the CPU ID cell needs.
Move the cells into a fixed layout, as already done for RK3528, RK3562
and RK356x. Labels and node names stay the same, so the cells keep their
names and existing references keep working.
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
arch/arm64/boot/dts/rockchip/rk3576.dtsi | 105 ++++++++++++++++---------------
1 file changed, 54 insertions(+), 51 deletions(-)
diff --git a/arch/arm64/boot/dts/rockchip/rk3576.dtsi b/arch/arm64/boot/dts/rockchip/rk3576.dtsi
index 6f5780af4192..2e83a73ddbb2 100644
--- a/arch/arm64/boot/dts/rockchip/rk3576.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3576.dtsi
@@ -2298,63 +2298,66 @@ rng: rng@2a410000 {
otp: otp@2a580000 {
compatible = "rockchip,rk3576-otp";
reg = <0x0 0x2a580000 0x0 0x400>;
- #address-cells = <1>;
- #size-cells = <1>;
clocks = <&cru CLK_OTPC_NS>, <&cru PCLK_OTPC_NS>,
<&cru CLK_OTP_PHY_G>;
clock-names = "otp", "apb_pclk", "phy";
resets = <&cru SRST_OTPC_NS>, <&cru SRST_P_OTPC_NS>;
reset-names = "otp", "apb";
- /* Data cells */
- cpu_code: cpu-code@2 {
- reg = <0x02 0x2>;
- };
- otp_cpu_version: cpu-version@5 {
- reg = <0x05 0x1>;
- bits = <3 3>;
- };
- otp_id: id@a {
- reg = <0x0a 0x10>;
- };
- cpub_leakage: cpub-leakage@1e {
- reg = <0x1e 0x1>;
- };
- cpul_leakage: cpul-leakage@1f {
- reg = <0x1f 0x1>;
- };
- npu_leakage: npu-leakage@20 {
- reg = <0x20 0x1>;
- };
- gpu_leakage: gpu-leakage@21 {
- reg = <0x21 0x1>;
- };
- log_leakage: log-leakage@22 {
- reg = <0x22 0x1>;
- };
- bigcore_tsadc_trim: bigcore-tsadc-trim@24 {
- reg = <0x24 0x2>;
- bits = <0 10>;
- };
- litcore_tsadc_trim: litcore-tsadc-trim@26 {
- reg = <0x26 0x2>;
- bits = <0 10>;
- };
- ddr_tsadc_trim: ddr-tsadc-trim@28 {
- reg = <0x28 0x2>;
- bits = <0 10>;
- };
- npu_tsadc_trim: npu-tsadc-trim@2a {
- reg = <0x2a 0x2>;
- bits = <0 10>;
- };
- gpu_tsadc_trim: gpu-tsadc-trim@2c {
- reg = <0x2c 0x2>;
- bits = <0 10>;
- };
- soc_tsadc_trim: soc-tsadc-trim@64 {
- reg = <0x64 0x2>;
- bits = <0 10>;
+ nvmem-layout {
+ compatible = "fixed-layout";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ cpu_code: cpu-code@2 {
+ reg = <0x02 0x2>;
+ };
+ otp_cpu_version: cpu-version@5 {
+ reg = <0x05 0x1>;
+ bits = <3 3>;
+ };
+ otp_id: id@a {
+ reg = <0x0a 0x10>;
+ };
+ cpub_leakage: cpub-leakage@1e {
+ reg = <0x1e 0x1>;
+ };
+ cpul_leakage: cpul-leakage@1f {
+ reg = <0x1f 0x1>;
+ };
+ npu_leakage: npu-leakage@20 {
+ reg = <0x20 0x1>;
+ };
+ gpu_leakage: gpu-leakage@21 {
+ reg = <0x21 0x1>;
+ };
+ log_leakage: log-leakage@22 {
+ reg = <0x22 0x1>;
+ };
+ bigcore_tsadc_trim: bigcore-tsadc-trim@24 {
+ reg = <0x24 0x2>;
+ bits = <0 10>;
+ };
+ litcore_tsadc_trim: litcore-tsadc-trim@26 {
+ reg = <0x26 0x2>;
+ bits = <0 10>;
+ };
+ ddr_tsadc_trim: ddr-tsadc-trim@28 {
+ reg = <0x28 0x2>;
+ bits = <0 10>;
+ };
+ npu_tsadc_trim: npu-tsadc-trim@2a {
+ reg = <0x2a 0x2>;
+ bits = <0 10>;
+ };
+ gpu_tsadc_trim: gpu-tsadc-trim@2c {
+ reg = <0x2c 0x2>;
+ bits = <0 10>;
+ };
+ soc_tsadc_trim: soc-tsadc-trim@64 {
+ reg = <0x64 0x2>;
+ bits = <0 10>;
+ };
};
};
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 5/5] arm64: dts: rockchip: Derive GMAC MAC addresses from OTP on RK3576
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
` (3 preceding siblings ...)
2026-11-25 19:36 ` [PATCH v5 4/5] arm64: dts: rockchip: Move RK3576 OTP cells into a fixed layout Alexey Charkov
@ 2026-11-25 19:36 ` Alexey Charkov
4 siblings, 0 replies; 10+ messages in thread
From: Alexey Charkov @ 2026-11-25 19:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman
Cc: Ryan Leung, Ricardo Pardini, devicetree, linux-arm-kernel,
linux-rockchip, netdev, linux-kernel, Alexey Charkov
RK3576 boards without dedicated storage for a MAC address only get a
stable one if the bootloader derives it from the CPU ID and patches it
into the device tree, which not every boot flow does.
Mark the CPU ID cell as such and reference it from both GMACs as their
unique ID, so that the addresses can be derived from the device tree
alone, whatever the bootloader. Each GMAC gets the address of its
"ethernetN" alias, as with the bootloaders. Boards which store a MAC
address of their own can reference it instead.
Note that the GMACs then depend on the OTP memory being accessible, as
the thermal sensors already do for their trim values.
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
arch/arm64/boot/dts/rockchip/rk3576.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/boot/dts/rockchip/rk3576.dtsi b/arch/arm64/boot/dts/rockchip/rk3576.dtsi
index 2e83a73ddbb2..d14236c783b5 100644
--- a/arch/arm64/boot/dts/rockchip/rk3576.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3576.dtsi
@@ -2070,6 +2070,8 @@ gmac0: ethernet@2a220000 {
interrupts = <GIC_SPI 293 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 298 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq", "eth_wake_irq";
+ nvmem-cells = <&otp_id>;
+ nvmem-cell-names = "unique-id";
power-domains = <&power RK3576_PD_SDGMAC>;
resets = <&cru SRST_A_GMAC0>;
reset-names = "stmmaceth";
@@ -2118,6 +2120,8 @@ gmac1: ethernet@2a230000 {
interrupts = <GIC_SPI 301 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq", "eth_wake_irq";
+ nvmem-cells = <&otp_id>;
+ nvmem-cell-names = "unique-id";
power-domains = <&power RK3576_PD_SDGMAC>;
resets = <&cru SRST_A_GMAC1>;
reset-names = "stmmaceth";
@@ -2317,6 +2321,7 @@ otp_cpu_version: cpu-version@5 {
bits = <3 3>;
};
otp_id: id@a {
+ compatible = "rockchip,cpuid";
reg = <0x0a 0x10>;
};
cpub_leakage: cpub-leakage@1e {
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID
2026-11-25 19:36 ` [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID Alexey Charkov
@ 2026-11-26 4:02 ` Ryan Leung
2026-12-01 1:30 ` Andrew Lunn
1 sibling, 0 replies; 10+ messages in thread
From: Ryan Leung @ 2026-11-26 4:02 UTC (permalink / raw)
To: Alexey Charkov
Cc: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Andrew Lunn, Heiner Kallweit, Russell King,
Willem de Bruijn, Simon Horman, Ricardo Pardini, devicetree,
linux-arm-kernel, linux-rockchip, netdev, linux-kernel
Hi Alexey,
Tested-by: Ryan Leung <untilscour@protonmail.com> # RK3528 NanoPi R28S
I tested on FriendlyELEC NanoPi R28S (RK3528) with ethernet200 = &gmac1 alias
and the MAC address was exactly as expected with XOR 200 the last octet.
Thanks and looking forward to using this.
Best regards,
Ryan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID
2026-11-25 19:36 ` [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID Alexey Charkov
2026-11-26 4:02 ` Ryan Leung
@ 2026-12-01 1:30 ` Andrew Lunn
2026-12-01 4:17 ` Alexey Charkov
1 sibling, 1 reply; 10+ messages in thread
From: Andrew Lunn @ 2026-12-01 1:30 UTC (permalink / raw)
To: Alexey Charkov
Cc: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Heiner Kallweit, Russell King, Willem de Bruijn,
Simon Horman, Ryan Leung, Ricardo Pardini, devicetree,
linux-arm-kernel, linux-rockchip, netdev, linux-kernel
> @@ -142,7 +239,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
> if (!ret)
> return 0;
>
> - return of_get_mac_address_nvmem(np, addr);
> + ret = of_get_mac_address_nvmem(np, addr);
> + if (!ret || ret == -EPROBE_DEFER)
> + return ret;
You need to be careful here. There might be devices which currently
work because they return EPROBE_DEFER here and try again later.
Also, none of the other sources of the MAC address in this function
special case it.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID
2026-12-01 1:30 ` Andrew Lunn
@ 2026-12-01 4:17 ` Alexey Charkov
2026-12-01 13:05 ` Andrew Lunn
0 siblings, 1 reply; 10+ messages in thread
From: Alexey Charkov @ 2026-12-01 4:17 UTC (permalink / raw)
To: Andrew Lunn
Cc: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Heiner Kallweit, Russell King, Willem de Bruijn,
Simon Horman, Ryan Leung, Ricardo Pardini, devicetree,
linux-arm-kernel, linux-rockchip, netdev, linux-kernel
On Tue, Dec 1, 2026 at 5:30 AM Andrew Lunn <andrew@lunn.ch> wrote:
>
> > @@ -142,7 +239,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
> > if (!ret)
> > return 0;
> >
> > - return of_get_mac_address_nvmem(np, addr);
> > + ret = of_get_mac_address_nvmem(np, addr);
> > + if (!ret || ret == -EPROBE_DEFER)
> > + return ret;
>
> You need to be careful here. There might be devices which currently
> work because they return EPROBE_DEFER here and try again later.
But that's exactly why I'm catching EPROBE_DEFER and returning it
immediately, so that the driver core can retry once the NVMEM cell
appears, instead of falling through to the next case. Am I missing
anything?
> Also, none of the other sources of the MAC address in this function
> special case it.
I don't think any of the others can defer, because they don't rely on
an external provider. While NVMEM relies on the nvmem driver, which
might be a module.
Best regards,
Alexey
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID
2026-12-01 4:17 ` Alexey Charkov
@ 2026-12-01 13:05 ` Andrew Lunn
0 siblings, 0 replies; 10+ messages in thread
From: Andrew Lunn @ 2026-12-01 13:05 UTC (permalink / raw)
To: Alexey Charkov
Cc: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner, Rafał Miłecki,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Heiner Kallweit, Russell King, Willem de Bruijn,
Simon Horman, Ryan Leung, Ricardo Pardini, devicetree,
linux-arm-kernel, linux-rockchip, netdev, linux-kernel
On Tue, Dec 01, 2026 at 08:17:03AM +0400, Alexey Charkov wrote:
> On Tue, Dec 1, 2026 at 5:30 AM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > > @@ -142,7 +239,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
> > > if (!ret)
> > > return 0;
> > >
> > > - return of_get_mac_address_nvmem(np, addr);
> > > + ret = of_get_mac_address_nvmem(np, addr);
> > > + if (!ret || ret == -EPROBE_DEFER)
> > > + return ret;
> >
> > You need to be careful here. There might be devices which currently
> > work because they return EPROBE_DEFER here and try again later.
>
> But that's exactly why I'm catching EPROBE_DEFER and returning it
> immediately, so that the driver core can retry once the NVMEM cell
> appears, instead of falling through to the next case. Am I missing
> anything?
>
> > Also, none of the other sources of the MAC address in this function
> > special case it.
>
> I don't think any of the others can defer, because they don't rely on
> an external provider. While NVMEM relies on the nvmem driver, which
> might be a module.
Ah, this function is not great. Generally we consider real errors as
fatal and return them. EIO, ETIMEDOUT, EINVAL etc indicate something
has gone wrong. EPROBE_DEFER would also fall into that class. Errors
like ENODEV would indicate the property does not exist, and we should
try the next.
However, this code does not do that. All errors are ignored, and the
next source is tried.
So your change is correct, in this context. And it is probably too
late to add proper error handling.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-01 13:06 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 19:36 [PATCH v5 0/5] net: Derive stable MAC addresses from a unique device ID Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 1/5] dt-bindings: nvmem: fixed-cell: Add Rockchip CPU ID Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 2/5] dt-bindings: net: ethernet-controller: Allow a unique ID NVMEM cell Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 3/5] net: of_net: Derive MAC addresses from a unique device ID Alexey Charkov
2026-11-26 4:02 ` Ryan Leung
2026-12-01 1:30 ` Andrew Lunn
2026-12-01 4:17 ` Alexey Charkov
2026-12-01 13:05 ` Andrew Lunn
2026-11-25 19:36 ` [PATCH v5 4/5] arm64: dts: rockchip: Move RK3576 OTP cells into a fixed layout Alexey Charkov
2026-11-25 19:36 ` [PATCH v5 5/5] arm64: dts: rockchip: Derive GMAC MAC addresses from OTP on RK3576 Alexey Charkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®