[PATCH] net: lwip: add tftpsrv command

Quentin Schulz quentin.schulz at cherry.de
Fri Jun 26 20:15:59 CEST 2026


Hi James,

On 6/22/26 10:31 PM, James Hilliard wrote:
> The legacy network stack supports tftpsrv, which listens for an
> incoming TFTP write request and receives the first file into memory.
> The lwIP stack already builds the lwIP TFTP application, but only wires
> it up for client-side tftpboot.
> 
> Add a lwIP tftpsrv command and implement the server path with
> tftp_init_server(). Reuse the existing lwIP TFTP write callback and
> memory copy path so LMB checks, progress output, filesize/fileaddr
> updates and EFI bootdev handling stay consistent with tftpboot.
> 
> Track receive timeout and write-failure state around the lwIP callbacks
> so a stalled or rejected receive is not reported as a successful close.
> 
> Move CMD_TFTPSRV out of the legacy-only Kconfig block so it can be
> enabled with either network stack.
> 

Do you think we could get some tests for this? I see we have some for 
tftpboot already, so maybe there's something we can do about tftpsrv?

> Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
> ---
>   cmd/Kconfig        |  14 ++--
>   cmd/lwip/Makefile  |   1 +
>   cmd/lwip/tftpsrv.c |  11 +++
>   include/net-lwip.h |   1 +
>   net/lwip/tftp.c    | 181 +++++++++++++++++++++++++++++++++++++++++++--
>   5 files changed, 197 insertions(+), 11 deletions(-)
>   create mode 100644 cmd/lwip/tftpsrv.c
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 032e55e8127..8f3d66ddc77 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -2127,12 +2127,6 @@ config CMD_TFTPPUT
>   	help
>   	  TFTP put command, for uploading files to a server
>   
> -config CMD_TFTPSRV
> -	bool "tftpsrv"
> -	depends on CMD_TFTPBOOT
> -	help
> -	  Act as a TFTP server and boot the first received file
> -
>   config NET_TFTP_VARS
>   	bool "Control TFTP timeout and count through environment"
>   	depends on CMD_TFTPBOOT
> @@ -2279,6 +2273,14 @@ config CMD_TFTPBOOT
>   	help
>   	  tftpboot - load file via network using TFTP protocol
>   
> +config CMD_TFTPSRV
> +	bool "tftpsrv"
> +	depends on CMD_TFTPBOOT
> +	help
> +	  Act as a TFTP server and receive the first incoming file into
> +	  memory. The command returns successfully after the transfer so
> +	  boot scripts can boot the received image from the load address.
> +

The help text has a very big difference, it seems this doesn't boot the 
first received file anymore. We need to know whether this was already 
the case with tftpsrv from NET_LEGACY or if this is specific to 
NET_LWIP. If it's the latter, I think this is an issue and we cannot 
really do it this way. If it's the former, then it's fine but you need 
to specify it in the commig log (I think I can read between the lines 
that NET_LEGACY indeed also doesn't automatically boot the uploaded file 
but I think it's better if made explicit).

>   config CMD_WGET
>   	bool "wget"
>   	default y if SANDBOX || ARCH_QEMU
> diff --git a/cmd/lwip/Makefile b/cmd/lwip/Makefile
> index 90df1f5511c..245683a9672 100644
> --- a/cmd/lwip/Makefile
> +++ b/cmd/lwip/Makefile
> @@ -4,4 +4,5 @@ obj-$(CONFIG_CMD_NFS) += nfs.o
>   obj-$(CONFIG_CMD_PING) += ping.o
>   obj-$(CONFIG_CMD_SNTP) += sntp.o
>   obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
> +obj-$(CONFIG_CMD_TFTPSRV) += tftpsrv.o
>   obj-$(CONFIG_CMD_WGET) += wget.o
> diff --git a/cmd/lwip/tftpsrv.c b/cmd/lwip/tftpsrv.c
> new file mode 100644
> index 00000000000..522a7ccacdf
> --- /dev/null
> +++ b/cmd/lwip/tftpsrv.c
> @@ -0,0 +1,11 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include <command.h>
> +#include <net.h>
> +
> +U_BOOT_CMD(tftpsrv, 2, 1, do_tftpsrv,
> +	   "act as a TFTP server and boot the first received file",
> +	   "[loadAddress]\n"
> +	   "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
> +	   "The transfer is aborted if a transfer has not been started after\n"
> +	   "about 50 seconds or if Ctrl-C is pressed.");

I'm sorry this falls on you since we already have a tftpsrv 
implementation in NET_LEGACY, but please add documentation for this 
command in a new doc/usage/cmd/tftpsrv.rst file.

Cheers,
Quentin


More information about the U-Boot mailing list