[PATCH] net: lwip: tftp: time out if there is no reply from server

Jerome Forissier jerome.forissier at linaro.org
Tue May 13 13:35:32 CEST 2025


Hi Heinrich,

On 4/28/25 11:24, Jerome Forissier wrote:
> When there is no reply from the TFTP server, do_tftpb() should
> eventually time out. Add a 10 second timer for that purpose.
> 
> Reported-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> Signed-off-by: Jerome Forissier <jerome.forissier at linaro.org>
> ---
> 
>  net/lwip/tftp.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

Does this fix the stalling issue you mentioned in [1]?

[1] https://lists.denx.de/pipermail/u-boot/2025-April/587583.html

Thanks,
-- 
Jerome

> 
> diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c
> index 4f9b2049187..4f88924e47e 100644
> --- a/net/lwip/tftp.c
> +++ b/net/lwip/tftp.c
> @@ -15,6 +15,8 @@
>  #include <time.h>
>  
>  #define PROGRESS_PRINT_STEP_BYTES (10 * 1024)
> +/* Max time to wait for first data packet from server */
> +#define NO_RSP_TIMEOUT_MS 10000
>  
>  enum done_state {
>  	NOT_DONE = 0,
> @@ -106,6 +108,17 @@ static const struct tftp_context tftp_context = {
>  	tftp_error
>  };
>  
> +static void no_response(void *arg)
> +{
> +	struct tftp_ctx *ctx = (struct tftp_ctx *)arg;
> +
> +	if (ctx->size)
> +		return;
> +
> +	printf("Timeout!\n");
> +	ctx->done = FAILURE;
> +}
> +
>  static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
>  		     ip_addr_t srvip, uint16_t srvport)
>  {
> @@ -150,6 +163,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
>  		return -1;
>  	}
>  
> +	sys_timeout(NO_RSP_TIMEOUT_MS, no_response, &ctx);
>  	while (!ctx.done) {
>  		net_lwip_rx(udev, netif);
>  		sys_check_timeouts();
> @@ -159,6 +173,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
>  			break;
>  		}
>  	}
> +	sys_untimeout(no_response, (void *)&ctx);
>  
>  	tftp_cleanup();
>  


More information about the U-Boot mailing list