[PATCH v4 21/28] fdt: Populate wifi MAC from environment
Stephen Boyd
swboyd at chromium.org
Sat May 24 00:58:36 CEST 2025
Set the MAC address of the wifi device node with an alias like 'wifi0'
or 'wifi' based on the environment variables. This allows us to populate
the wifi device's MAC address on devices like Trogdor that store the
wifi MAC in the VPD.
Signed-off-by: Stephen Boyd <swboyd at chromium.org>
---
boot/fdt_support.c | 54 +++++++++++++++++++++++++++------------
lib/coreboot/cb_sysinfo.c | 2 ++
2 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 92f2f534ee02..a02de4dfd9c5 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -611,13 +611,34 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
return fdt_fixup_memory_banks(blob, &start, &size, 1);
}
+static void fdt_fixup_net_node(void *fdt, const char *path, const char *mac)
+{
+ int j;
+ char *tmp, *end;
+ unsigned char mac_addr[ARP_HLEN];
+
+ tmp = env_get(mac);
+ if (!tmp)
+ return;
+
+ for (j = 0; j < 6; j++) {
+ mac_addr[j] = tmp ?
+ hextoul(tmp, &end) : 0;
+ if (tmp)
+ tmp = (*end) ? end + 1 : end;
+ }
+
+ do_fixup_by_path(fdt, path, "mac-address",
+ &mac_addr, 6, 0);
+ do_fixup_by_path(fdt, path, "local-mac-address",
+ &mac_addr, 6, 1);
+}
+
void fdt_fixup_ethernet(void *fdt)
{
- int i = 0, j, prop;
- char *tmp, *end;
+ int i = 0, w = 0, j, prop;
char mac[16];
const char *path;
- unsigned char mac_addr[ARP_HLEN];
int offset;
#ifdef FDT_SEQ_MACADDR_FROM_ENV
int nodeoff;
@@ -670,21 +691,22 @@ void fdt_fixup_ethernet(void *fdt)
continue;
i++;
#endif
- tmp = env_get(mac);
- if (!tmp)
+ fdt_fixup_net_node(fdt, path, mac);
+ } else if (!strncmp(name, "wifi", 4)) {
+ /* Treat plain "wifi" same as "wifi0". */
+ if (!strcmp(name, "wifi"))
+ w = 0;
+ else
+ w = trailing_strtol(name);
+ if (w != -1) {
+ if (w == 0)
+ strcpy(mac, "wifiaddr");
+ else
+ sprintf(mac, "wifi%daddr", w);
+ } else {
continue;
-
- for (j = 0; j < 6; j++) {
- mac_addr[j] = tmp ?
- hextoul(tmp, &end) : 0;
- if (tmp)
- tmp = (*end) ? end + 1 : end;
}
-
- do_fixup_by_path(fdt, path, "mac-address",
- &mac_addr, 6, 0);
- do_fixup_by_path(fdt, path, "local-mac-address",
- &mac_addr, 6, 1);
+ fdt_fixup_net_node(fdt, path, mac);
}
}
}
diff --git a/lib/coreboot/cb_sysinfo.c b/lib/coreboot/cb_sysinfo.c
index 555abc93f1cb..959eaaab8e88 100644
--- a/lib/coreboot/cb_sysinfo.c
+++ b/lib/coreboot/cb_sysinfo.c
@@ -686,9 +686,11 @@ static unsigned int coreboot_set_one(const u8 *blob, unsigned int i)
const u8 *key;
const u8 *val;
+ /* We only care about strings that may contain keys we can use */
if (vpd_type != VPD_TYPE_INFO && vpd_type != VPD_TYPE_STRING)
return i;
+ /* Conntinue to move 'i' forward through the VPD blob */
i = vpd_cbmem_parse_key_value(blob, i, &key_offset, &key_len, &val_offset, &val_len);
if (vpd_type != VPD_TYPE_STRING)
return i;
--
Sent by a computer, using git, on the internet
More information about the U-Boot
mailing list