Skip to contentSkip to conversation

net: lwip: call sys_check_timeouts and schedule on rx

PATCH Superseded Tim Harvey 2 participants 13 messages May 29, 2025 – May 30, 2025 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

PATCH 1/6 net: lwip: call sys_check_timeouts and schedule on rx

Call sys_check_timeouts to service lwIP timers and schedule to service U-Boot tasks and actions during packet rx.

This resolves the issue of an active watchdog resetting the board on long network activities.

---
 net/lwip/net-lwip.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/lwip/net-lwip.c +7 -0
index f05c4cd3f64f..e8d4cc542ed8 100644
@@ -13,8 +13,10 @@
 #include <lwip/etharp.h>
 #include <lwip/init.h>
 #include <lwip/prot/etharp.h>
+#include <lwip/timeouts.h>
 #include <net.h>
 #include <timer.h>
+#include <u-boot/schedule.h>
 
 /* xx:xx:xx:xx:xx:xx\0 */
 #define MAC_ADDR_STRLEN 18
@@ -284,6 +286,11 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif)
 	int len;
 	int i;
 
+	/* lwIP timers */
+	sys_check_timeouts();
+	/* Other tasks and actions */
+	schedule();
+
 	if (!eth_is_active(udev))
 		return -EINVAL;
 
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/6 net: lwip: enable IP_FRAG and IP_REASSEMBLY

Enable IP_FRAG and IP_REASSEMBLY to allow packets larger than MTU.

---
 lib/lwip/u-boot/lwipopts.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lwip/u-boot/lwipopts.h +2 -2
index edac74ff7a21..1818a445dc5e 100644
@@ -72,8 +72,8 @@
 
 #define IP_FORWARD                      0
 #define IP_OPTIONS_ALLOWED              1
-#define IP_REASSEMBLY                   0
-#define IP_FRAG                         0
+#define IP_REASSEMBLY                   1
+#define IP_FRAG                         1
 #define IP_REASS_MAXAGE                 3
 #define IP_REASS_MAX_PBUFS              4
 #define IP_FRAG_USES_STATIC_BUF         0
Signature · 1 line
2.25.1
Reviewed-by on v1 2/6
#2 lore raw

Re: [PATCH 2/6] net: lwip: enable IP_FRAG and IP_REASSEMBLY

Quoted 12 lines · Tim Harvey

Enable IP_FRAG and IP_REASSEMBLY to allow packets larger than MTU.

---
 lib/lwip/u-boot/lwipopts.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lwip/u-boot/lwipopts.h +0 -0
index edac74ff7a21..1818a445dc5e 100644

lib/lwip/u-boot/lwipopts.h line 79

Quoted 10 lines
lib/lwip/u-boot/lwipopts.h +2 -2
@@ -72,8 +72,8 @@
 
 #define IP_FORWARD                      0
 #define IP_OPTIONS_ALLOWED              1
-#define IP_REASSEMBLY                   0
-#define IP_FRAG                         0
+#define IP_REASSEMBLY                   1
+#define IP_FRAG                         1
 #define IP_REASS_MAXAGE                 3
 #define IP_REASS_MAX_PBUFS              4
 #define IP_FRAG_USES_STATIC_BUF         0

Thanks,

Signature · 1 line
Jerome
author
#3 lore raw

PATCH 3/6 net: lwip: tftp: add support for setting blocksize at runtime

In reply to Tim Harvey

Add support for setting the blocksize at runtime via the tftpblocksize env variable as such is done with the legacy stack (CONFIG_NET).

---
 net/lwip/tftp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/lwip/tftp.c +6 -1
index fae701bad2eb..6cdb0642536c 100644
@@ -156,8 +156,10 @@ static void no_response(void *arg)
 static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
 		     ip_addr_t srvip, uint16_t srvport)
 {
+	int blksize = CONFIG_TFTP_BLOCKSIZE;
 	struct netif *netif;
 	struct tftp_ctx ctx;
+	const char *ep;
 	err_t err;
 
 	if (!fname || addr == 0)
@@ -186,7 +188,10 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
 	if (!(err == ERR_OK || err == ERR_USE))
 		log_err("tftp_init_client err: %d\n", err);
 
-	tftp_client_set_blksize(CONFIG_TFTP_BLOCKSIZE);
+	ep = env_get("tftpblocksize");
+	if (ep)
+		blksize = simple_strtol(ep, NULL, 10);
+	tftp_client_set_blksize(blksize);
 
 	ctx.start_time = get_timer(0);
 	err = tftp_get(&ctx, &srvip, srvport, fname, TFTP_MODE_OCTET);
Signature · 1 line
2.25.1
Reviewed-by on v1 3/6
#4 lore raw

Re: [PATCH 3/6] net: lwip: tftp: add support for setting blocksize at runtime

Quoted 25 lines · Tim Harvey

Add support for setting the blocksize at runtime via the tftpblocksize env variable as such is done with the legacy stack (CONFIG_NET).

---
 net/lwip/tftp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/lwip/tftp.c +2 -0
index fae701bad2eb..6cdb0642536c 100644
@@ -156,8 +156,10 @@ static void no_response(void *arg)
 static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
 		     ip_addr_t srvip, uint16_t srvport)
 {
+	int blksize = CONFIG_TFTP_BLOCKSIZE;
 	struct netif *netif;
 	struct tftp_ctx ctx;
+	const char *ep;
 	err_t err;
 
 	if (!fname || addr == 0)
@@ -186,7 +188,10 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
 	if (!(err == ERR_OK || err == ERR_USE))

net/lwip/tftp.c static int tftp_loop(struct udevice *udev, ulong addr, char *fname, · line 197

Quoted 10 lines
net/lwip/tftp.c +4 -1
 		log_err("tftp_init_client err: %d\n", err);
 
-	tftp_client_set_blksize(CONFIG_TFTP_BLOCKSIZE);
+	ep = env_get("tftpblocksize");
+	if (ep)
+		blksize = simple_strtol(ep, NULL, 10);
+	tftp_client_set_blksize(blksize);
 
 	ctx.start_time = get_timer(0);
 	err = tftp_get(&ctx, &srvip, srvport, fname, TFTP_MODE_OCTET);

Thanks,

Signature · 1 line
Jerome
author
#5 lore raw

PATCH 4/6 net: lwip: move dns init to common function

In reply to Tim Harvey

move the dns init including setting the dns servers from env vars to a common function as other commands that support hostname lookups will need this.

---
 include/net-lwip.h  |  1 +
 net/lwip/dns.c      | 20 +-------------------
 net/lwip/net-lwip.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 19 deletions(-)
include/net-lwip.h +1 -0
index b762956e8fda..6b5eb1990fbf 100644
@@ -17,6 +17,7 @@ static inline int eth_is_on_demand_init(void)
 
 int eth_init_state_only(void); /* Set active state */
 
+int net_lwip_dns_init(void);
 int net_lwip_eth_start(void);
 struct netif *net_lwip_new_netif(struct udevice *udev);
 struct netif *net_lwip_new_netif_noip(struct udevice *udev);
net/lwip/dns.c +1 -19
index 19172ac959ac..ff1903f7191a 100644
@@ -44,12 +44,9 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
 	struct dns_cb_arg dns_cb_arg = { };
-	bool has_server = false;
 	struct netif *netif;
 	ip_addr_t ipaddr;
-	ip_addr_t ns;
 	ulong start;
-	char *nsenv;
 	int ret;
 
 	dns_cb_arg.var = var;
@@ -58,22 +55,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 	if (!netif)
 		return CMD_RET_FAILURE;
 
-	dns_init();
-
-	nsenv = env_get("dnsip");
-	if (nsenv && ipaddr_aton(nsenv, &ns)) {
-		dns_setserver(0, &ns);
-		has_server = true;
-	}
-
-	nsenv = env_get("dnsip2");
-	if (nsenv && ipaddr_aton(nsenv, &ns)) {
-		dns_setserver(1, &ns);
-		has_server = true;
-	}
-
-	if (!has_server) {
-		log_err("No valid name server (dnsip/dnsip2)\n");
+	if (net_lwip_dns_init()) {
 		net_lwip_remove_netif(netif);
 		return CMD_RET_FAILURE;
 	}
net/lwip/net-lwip.c +30 -0
index e8d4cc542ed8..23dccfef8993 100644
@@ -7,6 +7,7 @@
 #include <dm/uclass.h>
 #include <hexdump.h>
 #include <lwip/ip4_addr.h>
+#include <lwip/dns.h>
 #include <lwip/err.h>
 #include <lwip/netif.h>
 #include <lwip/pbuf.h>
@@ -139,6 +140,35 @@ static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
 	return 0;
 }
 
+/*
+ * Initialize DNS via env
+ */
+int net_lwip_dns_init(void)
+{
+	bool has_server = false;
+	ip_addr_t ns;
+	char *nsenv;
+
+	nsenv = env_get("dnsip");
+	if (nsenv && ipaddr_aton(nsenv, &ns)) {
+		dns_setserver(0, &ns);
+		has_server = true;
+	}
+
+	nsenv = env_get("dnsip2");
+	if (nsenv && ipaddr_aton(nsenv, &ns)) {
+		dns_setserver(1, &ns);
+		has_server = true;
+	}
+
+	if (!has_server) {
+		log_err("No valid name server (dnsip/dnsip2)\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*
  * Initialize the network stack if needed and start the current device if valid
  */
Signature · 1 line
2.25.1
Reviewed-by on v1 4/6
#6 lore raw

Re: [PATCH 4/6] net: lwip: move dns init to common function

Quoted 102 lines · Tim Harvey

move the dns init including setting the dns servers from env vars to a common function as other commands that support hostname lookups will need this.

---
 include/net-lwip.h  |  1 +
 net/lwip/dns.c      | 20 +-------------------
 net/lwip/net-lwip.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 19 deletions(-)
include/net-lwip.h +1 -0
index b762956e8fda..6b5eb1990fbf 100644
@@ -17,6 +17,7 @@ static inline int eth_is_on_demand_init(void)
 
 int eth_init_state_only(void); /* Set active state */
 
+int net_lwip_dns_init(void);
 int net_lwip_eth_start(void);
 struct netif *net_lwip_new_netif(struct udevice *udev);
 struct netif *net_lwip_new_netif_noip(struct udevice *udev);
net/lwip/dns.c +1 -19
index 19172ac959ac..ff1903f7191a 100644
@@ -44,12 +44,9 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
 	struct dns_cb_arg dns_cb_arg = { };
-	bool has_server = false;
 	struct netif *netif;
 	ip_addr_t ipaddr;
-	ip_addr_t ns;
 	ulong start;
-	char *nsenv;
 	int ret;
 
 	dns_cb_arg.var = var;
@@ -58,22 +55,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 	if (!netif)
 		return CMD_RET_FAILURE;
 
-	dns_init();
-
-	nsenv = env_get("dnsip");
-	if (nsenv && ipaddr_aton(nsenv, &ns)) {
-		dns_setserver(0, &ns);
-		has_server = true;
-	}
-
-	nsenv = env_get("dnsip2");
-	if (nsenv && ipaddr_aton(nsenv, &ns)) {
-		dns_setserver(1, &ns);
-		has_server = true;
-	}
-
-	if (!has_server) {
-		log_err("No valid name server (dnsip/dnsip2)\n");
+	if (net_lwip_dns_init()) {
 		net_lwip_remove_netif(netif);
 		return CMD_RET_FAILURE;
 	}
net/lwip/net-lwip.c +23 -0
index e8d4cc542ed8..23dccfef8993 100644
@@ -7,6 +7,7 @@
 #include <dm/uclass.h>
 #include <hexdump.h>
 #include <lwip/ip4_addr.h>
+#include <lwip/dns.h>
 #include <lwip/err.h>
 #include <lwip/netif.h>
 #include <lwip/pbuf.h>
@@ -139,6 +140,35 @@ static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
 	return 0;
 }
 
+/*
+ * Initialize DNS via env
+ */
+int net_lwip_dns_init(void)
+{
+	bool has_server = false;
+	ip_addr_t ns;
+	char *nsenv;
+
+	nsenv = env_get("dnsip");
+	if (nsenv && ipaddr_aton(nsenv, &ns)) {
+		dns_setserver(0, &ns);
+		has_server = true;
+	}
+
+	nsenv = env_get("dnsip2");
+	if (nsenv && ipaddr_aton(nsenv, &ns)) {
+		dns_setserver(1, &ns);
+		has_server = true;
+	}
+
+	if (!has_server) {

net/lwip/net-lwip.c static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip, · line 174

Quoted 10 lines
net/lwip/net-lwip.c +7 -0
+		log_err("No valid name server (dnsip/dnsip2)\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*
  * Initialize the network stack if needed and start the current device if valid
  */

Thanks,

Signature · 1 line
Jerome
author
#7 lore raw

PATCH 5/6 net: lwip: wget: initialize dns if a hostname is used in a URL

In reply to Tim Harvey

Initialize dns servers if a hostname (vs ipaddr) is used in a URL. Otherwise the wget will fail without displaying an error due to dns_gethostbyname failing silently when no DNS servers are set unless you have previously performed a 'dns <arg>' command.

---
 net/lwip/wget.c | 4 ++++
 1 file changed, 4 insertions(+)
net/lwip/wget.c +4 -0
index ea1113e18b11..76401991bde6 100644
@@ -460,6 +460,10 @@ int wget_do_request(ulong dst_addr, char *uri)
 	if (!netif)
 		return -1;
 
+	/* if URL with hostname init dns */
+	if (!ipaddr_aton(ctx.server_name, NULL) && net_lwip_dns_init())
+		return CMD_RET_FAILURE;
+
 	memset(&conn, 0, sizeof(conn));
 #if CONFIG_IS_ENABLED(WGET_HTTPS)
 	if (is_https) {
Signature · 1 line
2.25.1
Acked-by on v1 5/6
#8 lore raw

Re: [PATCH 5/6] net: lwip: wget: initialize dns if a hostname is used in a URL

Quoted 4 lines · Tim Harvey

Initialize dns servers if a hostname (vs ipaddr) is used in a URL. Otherwise the wget will fail without displaying an error due to dns_gethostbyname failing silently when no DNS servers are set unless you have previously performed a 'dns <arg>' command.

Ha! I think I did not notice this issue because I always used DHCP, which populates the DNS servers internally in the lwIP stack. That sounds reasonable.

Quoted 11 lines
---
 net/lwip/wget.c | 4 ++++
 1 file changed, 4 insertions(+)
net/lwip/wget.c +0 -0
index ea1113e18b11..76401991bde6 100644

net/lwip/wget.c int wget_do_request(ulong dst_addr, char *uri) · line 469

Quoted 10 lines
net/lwip/wget.c +4 -0
@@ -460,6 +460,10 @@ int wget_do_request(ulong dst_addr, char *uri)
 	if (!netif)
 		return -1;
 
+	/* if URL with hostname init dns */
+	if (!ipaddr_aton(ctx.server_name, NULL) && net_lwip_dns_init())
+		return CMD_RET_FAILURE;
+
 	memset(&conn, 0, sizeof(conn));
 #if CONFIG_IS_ENABLED(WGET_HTTPS)
 	if (is_https) {

Thanks,

Signature · 1 line
Jerome
author
#9 lore raw

PATCH 6/6 net: lwip: wget: use loadaddr env var for default address

In reply to Tim Harvey

The loadAddress is optional and defaults to image_load_address which should be initialized to the 'loadaddr' env variable like the legacy stack (CONFIG_NET) does.

---
 net/lwip/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/wget.c +1 -1
index 76401991bde6..ff8dbdc08d9b 100644
@@ -579,7 +579,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
 			return CMD_RET_USAGE;
 		url = argv[2];
 	} else {
-		dst_addr = image_load_addr;
+		dst_addr = env_get_ulong("loadaddr", 16, image_load_addr);
 		url = argv[1];
 	}
 
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH 6/6] net: lwip: wget: use loadaddr env var for default address

Quoted 14 lines · Tim Harvey

The loadAddress is optional and defaults to image_load_address which should be initialized to the 'loadaddr' env variable like the legacy stack (CONFIG_NET) does.

---
 net/lwip/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/wget.c +0 -0
index 76401991bde6..ff8dbdc08d9b 100644

net/lwip/wget.c int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) · line 585

Quoted 8 lines
net/lwip/wget.c +1 -1
@@ -579,7 +579,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
 			return CMD_RET_USAGE;
 		url = argv[2];
 	} else {
-		dst_addr = image_load_addr;
+		dst_addr = env_get_ulong("loadaddr", 16, image_load_addr);
 		url = argv[1];
 	}
 

image_load_addr is initialized in initr_env() (common/board_r.c) so this should not be necessary.

Thanks,

Signature · 1 line
Jerome
author
#11 lore raw

Re: [PATCH 6/6] net: lwip: wget: use loadaddr env var for default address

Quoted 13 lines · Jerome Forissier
Quoted 9 lines · Tim Harvey

The loadAddress is optional and defaults to image_load_address which should be initialized to the 'loadaddr' env variable like the legacy stack (CONFIG_NET) does.

---
 net/lwip/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines

net/lwip/wget.c int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) · line 585

Quoted 13 lines
net/lwip/wget.c +1 -1
index 76401991bde6..ff8dbdc08d9b 100644
@@ -579,7 +579,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
                      return CMD_RET_USAGE;
              url = argv[2];
      } else {
-             dst_addr = image_load_addr;
+             dst_addr = env_get_ulong("loadaddr", 16, image_load_addr);
              url = argv[1];
      }
 

image_load_addr is initialized in initr_env() (common/board_r.c) so this should not be necessary.

Hi Jerome,

You are correct - not sure how I missed this. I'll drop it from v2.

Thanks,

Tim

#12 lore raw
In reply to Tim Harvey

Hi Tim,

Quoted 29 lines · Tim Harvey

Call sys_check_timeouts to service lwIP timers and schedule to service U-Boot tasks and actions during packet rx.

This resolves the issue of an active watchdog resetting the board on long network activities.

---
 net/lwip/net-lwip.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/lwip/net-lwip.c +2 -0
index f05c4cd3f64f..e8d4cc542ed8 100644
@@ -13,8 +13,10 @@
 #include <lwip/etharp.h>
 #include <lwip/init.h>
 #include <lwip/prot/etharp.h>
+#include <lwip/timeouts.h>
 #include <net.h>
 #include <timer.h>
+#include <u-boot/schedule.h>
 
 /* xx:xx:xx:xx:xx:xx\0 */
 #define MAC_ADDR_STRLEN 18
@@ -284,6 +286,11 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif)
 	int len;

net/lwip/net-lwip.c int net_lwip_rx(struct udevice *udev, struct netif *netif) · line 296

Quoted 10 lines
net/lwip/net-lwip.c +5 -0
 	int i;
 
+	/* lwIP timers */
+	sys_check_timeouts();
+	/* Other tasks and actions */
+	schedule();
+
 	if (!eth_is_active(udev))
 		return -EINVAL;
 

With that, there is no need for calling sys_check_timeouts() in the callers of net_lwip_rx(). Please simplify the dhcp/dns/ping/tftp/wget loops.

Thanks,

Signature · 1 line
Jerome