net: lwip: call sys_check_timeouts and schedule on rx
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
@@ -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
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
@@ -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
Re: [PATCH 2/6] net: lwip: enable IP_FRAG and IP_REASSEMBLY
Quoted 12 lines · Tim Harvey
Enable
IP_FRAGandIP_REASSEMBLYto allow packets larger than MTU.Signed-off-by Tim Harvey <[email protected]>--- lib/lwip/u-boot/lwipopts.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/lwip/u-boot/lwipopts.h +0
-0
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
PATCH 3/6 net: lwip: tftp: add support for setting blocksize at runtime
In reply to Tim HarveyAdd 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
@@ -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
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).Signed-off-by Tim Harvey <[email protected]>--- net/lwip/tftp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/lwip/tftp.c +2
-0@@ -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
-1log_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
PATCH 4/6 net: lwip: move dns init to common function
In reply to Tim Harveymove 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
@@ -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
@@ -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
@@ -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
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.
Signed-off-by Tim Harvey <[email protected]>--- 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@@ -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@@ -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@@ -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
PATCH 5/6 net: lwip: wget: initialize dns if a hostname is used in a URL
In reply to Tim HarveyInitialize 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
@@ -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
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_gethostbynamefailing 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
Signed-off-by Tim Harvey <[email protected]>--- net/lwip/wget.c | 4 ++++ 1 file changed, 4 insertions(+)net/lwip/wget.c +0
-0
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
PATCH 6/6 net: lwip: wget: use loadaddr env var for default address
In reply to Tim HarveyThe 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
@@ -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
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_addresswhich should be initialized to the 'loadaddr' env variable like the legacy stack (CONFIG_NET) does.Signed-off-by Tim Harvey <[email protected]>--- net/lwip/wget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/lwip/wget.c +0
-0
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
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_addresswhich should be initialized to the 'loadaddr' env variable like the legacy stack (CONFIG_NET) does.Signed-off-by Tim Harvey <[email protected]>--- 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@@ -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_addris initialized ininitr_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
Hi Tim,
Quoted 29 lines · Tim Harvey
Call
sys_check_timeoutsto 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.
Suggested-by Jerome Forissier <[email protected]>Signed-off-by Tim Harvey <[email protected]>--- net/lwip/net-lwip.c | 7 +++++++ 1 file changed, 7 insertions(+)net/lwip/net-lwip.c +2
-0@@ -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
-0int 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