[PATCH v2 RESEND] nvmem: layouts: u-boot-env: handle quotes in MAC post process

From: Michael C. Pratt

Date: Sun Oct 18 2026 - 04:53:36 EST


Although it is not common, some board models from some vendors have
a MAC address stored in u-boot environment as a quoted form, e.g.

ethaddr="AA:BB:CC:DD:EE:FF"

This is acceptable formatting for a u-boot environment variable, however,
it makes parsing MACs in post processing inconsistent and currently fails.

Add a second condition for processing to match the MAC address with quotes
by allowing a longer length and setting a shifted offset to compensate.

The mac_pton() function has strict behavior on the length and location
of delimiters for each octet and that each digit is hexadecimal,
so attempting different offsets of the same string is not problematic.

Signed-off-by: Michael C. Pratt <mcpratt@xxxxx>
---
v1: https://lore.kernel.org/all/20260820211654.8794-1-mcpratt@xxxxx/
v2: rebased and relocated changes to match style due to commit
45cb0223740b ("nvmem: layouts: u-boot-env: check earlier for ethaddr length")

drivers/nvmem/layouts/u-boot-env.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index 33ec2350386f..588996c1c11b 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -77,6 +77,13 @@ static int u_boot_env_parse_cells(struct device *dev, struct nvmem_device *nvmem
info.bytes = ETH_ALEN;
info.read_post_process = u_boot_env_read_post_process_ethaddr;
}
+ /* Handle quotation which increases length by 2 and offset by 1 if present. */
+ if (!strcmp(var, "ethaddr") && info.bytes == MAC_ADDR_STR_LEN + 2) {
+ info.offset = data_offset + value - data + 1;
+ info.raw_len = strlen(value);
+ info.bytes = ETH_ALEN;
+ info.read_post_process = u_boot_env_read_post_process_ethaddr;
+ }

nvmem_add_one_cell(nvmem, &info);
}
--
2.30.2