[PATCH 1/2] sunxi: setup_environment: do not generate a MAC address when one is set using nvmem-cells

Lukas Schmid lukas.schmid at netcube.li
Sat Jun 7 11:11:39 CEST 2025


Boards using MAC addresses stored in EEPROM via the device tree's
`nvmem-cells` mechanism may already have a valid MAC loaded by the
device model. However, setup_environment() currently ignores this
and generates a fallback address from the SoC SID if no environment
variable is set.

This leads to a mismatch warning during boot when the kernel or U-Boot
detects the MAC from nvmem and compares it to the environment.

This patch checks whether the corresponding ethernet device node
has a `nvmem-cells` property and skips generating a fallback MAC
if it does, thus avoiding redundant or incorrect ethaddr setup.

This improves compatibility with nvmem-based MAC provisioning and
aligns U-Boot behavior with Linux.

Signed-off-by: Lukas Schmid <lukas.schmid at netcube.li>
---
 board/sunxi/board.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index ac9cefc6..41b85c66 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -774,10 +774,23 @@ static void setup_environment(const void *fdt)
 		return;
 
 	for (i = 0; i < 4; i++) {
+		const char *alias;
+		int nodeoffset;
+		int len;
+		const fdt32_t *prop;
+
 		sprintf(ethaddr, "ethernet%d", i);
-		if (!fdt_get_alias(fdt, ethaddr))
+		alias = fdt_get_alias(fdt, ethaddr);
+		if (!alias)
 			continue;
 
+		nodeoffset = fdt_path_offset(fdt, alias);
+		if (nodeoffset >= 0) {
+			prop = fdt_getprop(fdt, nodeoffset, "nvmem-cells", &len);
+			if (prop && len > 0)
+				continue;
+		}
+
 		if (i == 0)
 			strcpy(ethaddr, "ethaddr");
 		else
-- 
2.39.5




More information about the U-Boot mailing list