[U-Boot] [PATCH] Fix enetaddr initialization with CONFIG_NET_MULTI

Albin Tonnerre albin.tonnerre at free-electrons.com
Tue Jul 28 17:44:27 CEST 2009


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.

Signed-off-by: Albin Tonnerre <albin.tonnerre at free-electrons.com>
---
 net/net.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/net/net.c b/net/net.c
index 5637cf5..99666e9 100644
--- a/net/net.c
+++ b/net/net.c
@@ -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;
 
 	/*
-- 
1.6.0.4



More information about the U-Boot mailing list