[PATCH v2 6/9] net/eth-uclass: Add eth_get_ethaddr_from_dev

Adriano Cordova adrianox at gmail.com
Wed May 28 10:38:18 CEST 2025


Add eth_get_ethaddr_from_dev() to retrieve the MAC address
of a specific eth udevice. The function eth_get_ethaddr()
preserves its behavior of returning the MAC address of the
current eth udevice.

Signed-off-by: Adriano Cordova <adriano.cordova at canonical.com>
---
 include/net-common.h |  1 +
 net/eth-uclass.c     | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/net-common.h b/include/net-common.h
index 7853612b237..b051dd1fdb5 100644
--- a/include/net-common.h
+++ b/include/net-common.h
@@ -292,6 +292,7 @@ struct eth_ops {
 
 struct udevice *eth_get_dev(void); /* get the current device */
 void eth_set_dev(struct udevice *dev); /* set a device */
+unsigned char *eth_get_ethaddr_from_dev(struct udevice *dev); /* get a device's MAC */
 unsigned char *eth_get_ethaddr(void); /* get the current device MAC */
 int eth_rx(void);                      /* Check for received packets */
 void eth_halt(void);			/* stop SCC */
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index a233912fd8e..6e440437887 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -175,18 +175,23 @@ struct udevice *eth_get_dev_by_name(const char *devname)
 	return NULL;
 }
 
-unsigned char *eth_get_ethaddr(void)
+unsigned char *eth_get_ethaddr_from_dev(struct udevice *dev)
 {
 	struct eth_pdata *pdata;
 
-	if (eth_get_dev()) {
-		pdata = dev_get_plat(eth_get_dev());
+	if (dev) {
+		pdata = dev_get_plat(dev);
 		return pdata->enetaddr;
 	}
 
 	return NULL;
 }
 
+unsigned char *eth_get_ethaddr(void)
+{
+	return eth_get_ethaddr_from_dev(eth_get_dev());
+}
+
 /* Set active state without calling start on the driver */
 int eth_init_state_only(void)
 {
-- 
2.48.1



More information about the U-Boot mailing list