From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 12/13] net: consult device tree for ethernet address in NVMEM as fall-back
Date: Sat, 19 Jun 2021 05:45:15 +0200 [thread overview]
Message-ID: <20210619034516.6737-13-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210619034516.6737-1-a.fatoum@pengutronix.de>
While barebox fixes up the mac-address into the device tree, it doesn't
care much for extracting a mac address _from_ the device tree, whether
it be from local-mac-address property or from a mac-address nvmem cell.
Fix the latter by calling of_get_mac_addr_nvmem for each Ethernet adapter.
We do this in a very late initcall, because we don't want to enforce a
probe a probe order between nvmem providers and network devices. We
can't do it at randomization time, because we need to fixup Ethernet mac
addresses, even when barebox itself doesn't ifup the netdev.
of_get_mac_addr_nvmem could be replaced by of_get_mac_address to also
parse local-mac-address and brethern, but justifying this change is left
as a future exercise.
Cc: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
net/eth.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/net/eth.c b/net/eth.c
index 84f99d3aa822..762c5dfb8aa8 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -11,6 +11,7 @@
#include <net.h>
#include <dma.h>
#include <of.h>
+#include <of_net.h>
#include <linux/phy.h>
#include <errno.h>
#include <malloc.h>
@@ -504,3 +505,26 @@ void led_trigger_network(enum led_trigger trigger)
led_trigger(trigger, TRIGGER_FLASH);
led_trigger(LED_TRIGGER_NET_TXRX, TRIGGER_FLASH);
}
+
+static int of_populate_ethaddr(void)
+{
+ char str[sizeof("xx:xx:xx:xx:xx:xx")];
+ struct eth_device *edev;
+ int ret;
+
+ list_for_each_entry(edev, &netdev_list, list) {
+ if (!edev->parent || is_valid_ether_addr(edev->ethaddr))
+ continue;
+
+ ret = of_get_mac_addr_nvmem(edev->parent->device_node, edev->ethaddr);
+ if (ret)
+ continue;
+
+ ethaddr_to_string(edev->ethaddr, str);
+ dev_info(&edev->dev, "Got preset MAC address from device tree: %s\n", str);
+ eth_set_ethaddr(edev, edev->ethaddr);
+ }
+
+ return 0;
+}
+postenvironment_initcall(of_populate_ethaddr);
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-19 3:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-19 3:45 [PATCH 00/13] nvmem: misc enhancements Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 01/13] nvmem: bsec: remove unused, left-over, struct member Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 02/13] nvmem: treat devices without nvmem_bus::write as read only Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 03/13] nvmem: add support for new read-only memory (rmem) binding Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 04/13] nvmem: add support for nvmem-cells binding Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 05/13] sandbox: use nvmem on top of stickypage for reset reason Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 06/13] power: reset: port Linux generic NVMEM reboot mode driver Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 07/13] sandbox: use nvmem-reboot-mode instead of syscon-reboot-mode Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 08/13] sandbox: dts: fix unit-address for state partition Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 09/13] nvmem: add command to list nvmem devices Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 10/13] sandbox: hostfile: move initcall to earlier postcore level Ahmad Fatoum
2021-06-19 3:45 ` [PATCH 11/13] of: of_net: sync of_get_mac_address with Linux for NVMEM support Ahmad Fatoum
2021-06-19 3:45 ` Ahmad Fatoum [this message]
2021-06-19 3:45 ` [PATCH 13/13] sandbox: ship sample environment Ahmad Fatoum
2021-06-21 6:05 ` [PATCH 00/13] nvmem: misc enhancements Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210619034516.6737-13-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox