Skip to contentSkip to conversation

Fix enetaddr initialization with CONFIG_NET_MULTI

PATCH New Albin Tonnerre 2 participants 3 messages Jul 28, 2009 – Aug 13, 2009 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix enetaddr initialization with CONFIG_NET_MULTI

When CONFIG_NET_MULTI is defined, the NetLoop code looks in eth_get_device()->enetaddr for the MAC address. However, this value may not be set. In fact, it will not be if ethaddr was not present in the environment when uboot was started. Therefore, even with 'setenv ethaddr xx:xx:xx:xx:xx:xx', eg. tftp will error out because it doesn't find the MAC address.
This patch tries to fix this by checking the ethaddr for the current ethernet device in the environment and setting the enetaddr field accordingly when NetLoop is called.
As I don't have a good knowledge of how the whole net subsystem works in u-boot, I'm not sure this is the right way to do it, and would appreciate guidance on the matter.

---
 net/net.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
net/net.c +17 -6
index 5637cf5..99666e9 100644
@@ -341,19 +341,30 @@ NetLoop(proto_t protocol)
 	eth_halt();
 #ifdef CONFIG_NET_MULTI
 	eth_set_current();
+
+	if (memcmp (eth_get_dev()->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
+		int eth_cur_index;
+		char eth_cur_name[8];
+
+		eth_cur_index = eth_get_dev_index();
+		if (eth_cur_index)
+			sprintf(eth_cur_name, "eth%iaddr", eth_cur_index);
+		else
+			strcpy(eth_cur_name, "ethaddr");
+
+		eth_getenv_enetaddr(eth_cur_name, NetOurEther);
+	}
+#else
+	eth_getenv_enetaddr("ethaddr", NetOurEther);
 #endif
+	memcpy(eth_get_dev()->enetaddr, NetOurEther, 6);
+
 	if (eth_init(bd) < 0) {
 		eth_halt();
 		return(-1);
 	}
 
 restart:
-#ifdef CONFIG_NET_MULTI
-	memcpy (NetOurEther, eth_get_dev()->enetaddr, 6);
-#else
-	eth_getenv_enetaddr("ethaddr", NetOurEther);
-#endif
-
 	NetState = NETLOOP_CONTINUE;
 
 	/*
Signature · 1 line
1.6.0.4
#1 lore raw

PATCH 1/1 Fix enetaddr initialization with CONFIG_NET_MULTI

Quoted 6 lines · On Tuesday 28 July 2009 11:44:27 Albin Tonnerre wrote:

When CONFIG_NET_MULTI is defined, the NetLoop code looks in eth_get_device()->enetaddr for the MAC address. However, this value may not be set. In fact, it will not be if ethaddr was not present in the environment when uboot was started. Therefore, even with 'setenv ethaddr xx:xx:xx:xx:xx:xx', eg. tftp will error out because it doesn't find the MAC address.

please grab the latest git tree and try again. this should be fixed by commit 86848a74c3c8...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/f6b5cc77/attachment.pgp

#2 lore raw

PATCH 1/1 Fix enetaddr initialization with CONFIG_NET_MULTI

Quoted 11 lines · Mike Frysinger
Quoted 6 lines · On Tuesday 28 July 2009 11:44:27 Albin Tonnerre wrote:

When CONFIG_NET_MULTI is defined, the NetLoop code looks in eth_get_device()->enetaddr for the MAC address. However, this value may not be set. In fact, it will not be if ethaddr was not present in the environment when uboot was started. Therefore, even with 'setenv ethaddr xx:xx:xx:xx:xx:xx', eg. tftp will error out because it doesn't find the MAC address.

please grab the latest git tree and try again. this should be fixed by commit 86848a74c3c8...
-mike

Indeed ... I noticed there was already a patch for this a couple days after sending mine, sorry for that.

Regards,

Signature · 11 lines
Albin Tonnerre, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/2625ab13/attachment.pgp