mirror of
https://github.com/openwrt/openwrt.git
synced 2026-11-28 10:11:16 +04:00
generic: nvmem: u-boot-env: process numbered ethaddr variables
Variable names with the pattern eth[0-9]addr is documented by u-boot in a README file doc/README.enetaddr as being the preferred way to store MAC addresses in the environment variables, so process them as a binary address automatically. Suggested-by: Tomasz Maciej Nowak <tmn505@gmail.com> Signed-off-by: Michael Pratt <mcpratt@pm.me> Link: https://github.com/openwrt/openwrt/pull/24866 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
1 parent
2d98322953
commit
9b6fce180c
1 file changed
+46
+46
@@ -0,0 +1,46 @@
|
||||
From: "Michael C. Pratt" <mcpratt@pm.me>
|
||||
Date: Wed Sep 9 00:21:51 2026 -0400
|
||||
Subject: [PATCH] generic: nvmem: u-boot-env: process numbered ethaddr variables
|
||||
|
||||
Variable names with the pattern eth[0-9]addr is documented by u-boot
|
||||
in a README file doc/README.enetaddr as being the preferred way
|
||||
to store MAC addresses in the environment variables,
|
||||
so process them as a binary address automatically.
|
||||
|
||||
Suggested-by: Tomasz Maciej Nowak <tmn505@gmail.com>
|
||||
Signed-off-by: "Michael C. Pratt" <mcpratt@pm.me>
|
||||
---
|
||||
|
||||
--- a/drivers/nvmem/layouts/u-boot-env.c
|
||||
+++ b/drivers/nvmem/layouts/u-boot-env.c
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/crc32.h>
|
||||
+#include <linux/ctype.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/if_ether.h>
|
||||
@@ -91,6 +92,22 @@ static int u_boot_env_parse_cells(struct
|
||||
}
|
||||
}
|
||||
|
||||
+ /* Process eth[0-9]addr variables as a MAC address. */
|
||||
+ if (!strncmp(var, "eth", 3) && isdigit(var[3]) && !strncmp(var + 4, "addr", 4) &&
|
||||
+ strlen(var) == 8 && info.bytes == MAC_ADDR_STR_LEN) {
|
||||
+ info.raw_len = strlen(value);
|
||||
+ 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 (!strncmp(var, "eth", 3) && isdigit(var[3]) && !strncmp(var + 4, "addr", 4) &&
|
||||
+ strlen(var) == 8 && 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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user