[U-Boot] [PATCH] 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.
Signed-off-by: Albin Tonnerre albin.tonnerre@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;
/*

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

On Thu, Aug 13, 2009 at 01:01:16AM -0400, Mike Frysinger wrote :
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,
participants (2)
-
Albin Tonnerre
-
Mike Frysinger