summaryrefslogtreecommitdiffstats
path: root/net/eth.c
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2023-11-22 10:47:50 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-11-22 16:23:55 +0100
commit66c48a374eef983220e1cf4145fb1d17bc7e51eb (patch)
tree506ada7ff6ec1061569587192b4c112659223048 /net/eth.c
parentb6941d29a55c3889f9ad1c1c05516d6b775ebb62 (diff)
downloadbarebox-66c48a374eef983220e1cf4145fb1d17bc7e51eb.tar.gz
barebox-66c48a374eef983220e1cf4145fb1d17bc7e51eb.tar.xz
net: add generic MAC address derivation from machine ID
Especially during development, devices often lack a MAC address. While a MAC address can be easily added to the environment: nv dev.eth0.ethaddr="aa:bb:cc:dd:ee:ff" It's easily lost when flashing complete new images, e.g. from CI. Make the development experience neater by deriving a stable MAC address if possible. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122094747.340825-3-uwe@kleine-koenig.org Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net/eth.c')
-rw-r--r--net/eth.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/net/eth.c b/net/eth.c
index ccac5e2a64..d1474ec57d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -10,6 +10,7 @@
#include <dhcp.h>
#include <net.h>
#include <dma.h>
+#include <machine_id.h>
#include <of.h>
#include <of_net.h>
#include <linux/phy.h>
@@ -554,10 +555,11 @@ void eth_open_all(void)
}
}
-static int of_populate_ethaddr(void)
+static int populate_ethaddr(void)
{
char str[sizeof("xx:xx:xx:xx:xx:xx")];
struct eth_device *edev;
+ bool generated = false;
int ret;
list_for_each_entry(edev, &netdev_list, list) {
@@ -566,14 +568,21 @@ static int of_populate_ethaddr(void)
ret = of_get_mac_addr_nvmem(edev->parent->of_node,
edev->ethaddr);
+ if (IS_ENABLED(CONFIG_NET_ETHADDR_FROM_MACHINE_ID) && ret) {
+ ret = generate_ether_addr(edev->ethaddr, edev->dev.id);
+ generated = true;
+ }
if (ret)
continue;
ethaddr_to_string(edev->ethaddr, str);
- dev_info(&edev->dev, "Got preset MAC address from device tree: %s\n", str);
+ if (generated)
+ dev_notice(&edev->dev, "Generated MAC address from unique id: %s\n", str);
+ else
+ dev_info(&edev->dev, "Got preset MAC address from NVMEM: %s\n", str);
eth_set_ethaddr(edev, edev->ethaddr);
}
return 0;
}
-postenvironment_initcall(of_populate_ethaddr);
+postenvironment_initcall(populate_ethaddr);