Patchwork [U-Boot] Write MAC address whenever ethernet subsystem is initialized

login
register
mail settings
Submitter Ingo van Lil
Date Aug. 26, 2011, 9:24 a.m.
Message ID <1314350667-13314-1-git-send-email-inguin@gmx.de>
Download mbox | patch
Permalink /patch/111732/
State Changes Requested
Headers show

Comments

Ingo van Lil - Aug. 26, 2011, 9:24 a.m.
Currently the ethernet MAC address is read from the 'ethaddr'
environment variable into the dev->enetaddr field each time the network
hardware is initialized, but it is written to the actual hardware only
once at board startup. When 'ethaddr' is set or changed after startup
the device can no longer receive packets because the hardware filter is
still programmed to the old MAC.

This patch moves the writing of the hardware address from eth_initialize
(board startup) to eth_init (just before actually using the network).
---
 net/eth.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
Sergei Shtylyov - Aug. 26, 2011, 12:37 p.m.
Hello.

On 26-08-2011 13:24, Ingo van Lil wrote:

> Currently the ethernet MAC address is read from the 'ethaddr'
> environment variable into the dev->enetaddr field each time the network
> hardware is initialized, but it is written to the actual hardware only
> once at board startup. When 'ethaddr' is set or changed after startup
> the device can no longer receive packets because the hardware filter is
> still programmed to the old MAC.

> This patch moves the writing of the hardware address from eth_initialize
> (board startup) to eth_init (just before actually using the network).

    You didn't sign off the patch...

WBR, Sergei

Patch

diff --git a/net/eth.c b/net/eth.c
index 6082c90..2b43ae7 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -261,11 +261,6 @@  int eth_initialize(bd_t *bis)
 
 				memcpy(dev->enetaddr, env_enetaddr, 6);
 			}
-			if (dev->write_hwaddr &&
-				!eth_mac_skip(eth_number) &&
-				is_valid_ether_addr(dev->enetaddr)) {
-				dev->write_hwaddr(dev);
-			}
 
 			eth_number++;
 			dev = dev->next;
@@ -347,8 +342,14 @@  int eth_init(bd_t *bis)
 	do {
 		uchar env_enetaddr[6];
 
-		if (eth_getenv_enetaddr_by_index(eth_number, env_enetaddr))
+		if (eth_getenv_enetaddr_by_index(eth_number, env_enetaddr)) {
 			memcpy(dev->enetaddr, env_enetaddr, 6);
+			if (dev->write_hwaddr &&
+				!eth_mac_skip(eth_number) &&
+				is_valid_ether_addr(dev->enetaddr)) {
+				dev->write_hwaddr(dev);
+			}
+		}
 
 		++eth_number;
 		dev = dev->next;