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.sch...@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


Reply via email to