net: lwip: move eth_init() out of new_netif()
Move the initialization of the ethernet devices out of the new_netif()
function. Indeed, new_netif() accepts a struct device argument, which
is expected to be valid and active. The activation and selection of
this device are achieved by eth_init() (on first time the network
stack is used) and eth_set_current(). This is what takes care of the
ethrotate and ethact environment variables. Therefore, move these calls
to a new function: net_lwip_set_current(), and use it whenever a
net-lwip command is run.
This patch hopefully fixes the incorrect net-lwip behavior observed on
boards with multiple ethernet interfaces [1].
Tested on an i.MX8MPlus EVK equipped wih two ethernet ports. The dhcp
command succeeds whether the cable is plugged into the first or second
port.
[1] https://lists.denx.de/pipermail/u-boot/2025-January/576326.html
Reported-by: E Shattow <e@freeshell.de>
Tested-by: E Shattow <e@freeshell.de>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c
index b863047..cab1dd7 100644
--- a/net/lwip/net-lwip.c
+++ b/net/lwip/net-lwip.c
@@ -127,6 +127,20 @@
return 0;
}
+/* Initialize the lwIP stack and the ethernet devices and set current device */
+void net_lwip_set_current(void)
+{
+ static bool init_done;
+
+ if (!init_done) {
+ eth_init_rings();
+ eth_init();
+ lwip_init();
+ init_done = true;
+ }
+ eth_set_current();
+}
+
static struct netif *new_netif(struct udevice *udev, bool with_ip)
{
unsigned char enetaddr[ARP_HLEN];
@@ -134,19 +148,10 @@
ip4_addr_t ip, mask, gw;
struct netif *netif;
int ret = 0;
- static bool first_call = true;
if (!udev)
return NULL;
- if (first_call) {
- eth_init_rings();
- /* Pick a valid active device, if any */
- eth_init();
- lwip_init();
- first_call = false;
- }
-
if (eth_start_udev(udev) < 0) {
log_err("Could not start %s\n", udev->name);
return NULL;