Files
u-boot-krane/lib/lwip/u-boot/lwipopts.h
T
James HilliardandJerome Forissier 0601d2d9a2 net: lwip: add tftpsrv command
The legacy network stack supports tftpsrv, which listens for an
incoming TFTP write request and receives the first file into memory.
Despite the old command help wording, the command returns after
receiving the file and does not boot it automatically.

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. Update the command help text and add
usage documentation for the receive-only behavior.

Add pytest coverage for tftpsrv using a generated host file and curl's
TFTP upload support. Enable the command in qemu_arm64_lwip_defconfig so
the test can be run with the existing lwIP QEMU build when the boardenv
provides env__net_tftpsrv_file.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
[Jerome Forissier: remove trailing ':' after SPDX tag]
Signed-off-by: Jerome Forissier <jerome.forissier@arm.com>
Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>
2026-07-23 17:05:20 +02:00

204 lines
6.2 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (C) 2023 Linaro Ltd. <maxim.uvarov@linaro.org> */
#ifndef LWIP_UBOOT_LWIPOPTS_H
#define LWIP_UBOOT_LWIPOPTS_H
#include <linux/kconfig.h>
#if defined(CONFIG_LWIP_DEBUG)
#define LWIP_DEBUG 1
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
#define ETHARP_DEBUG LWIP_DBG_ON
#define NETIF_DEBUG LWIP_DBG_ON
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_ON
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define IGMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_ON
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TIMERS_DEBUG LWIP_DBG_ON
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_ON
#define AUTOIP_DEBUG LWIP_DBG_ON
#define DNS_DEBUG LWIP_DBG_ON
#define IP6_DEBUG LWIP_DBG_OFF
#define DHCP6_DEBUG LWIP_DBG_OFF
#define SNTP_DEBUG LWIP_DBG_ON
#endif
#define LWIP_TESTMODE 0
#if !defined(CONFIG_LWIP_ASSERT)
#define LWIP_NOASSERT 1
#define LWIP_ASSERT(message, assertion)
#endif
#include "lwip/debug.h"
#define SYS_LIGHTWEIGHT_PROT 0
#define NO_SYS 1
#define LWIP_IPV4 1
#define LWIP_IPV6 0
#define MEM_ALIGNMENT 8
#define MEMP_NUM_TCP_SEG 16
/* IP fragmentation parameters for TFTP reassembly */
#define IP_FRAG_MTU_USABLE 1480
#define PBUF_POOL_HEADROOM 6
#define PBUF_POOL_RESERVE 4
#define TFTP_BLOCKSIZE_THRESHOLD 4096
/*
* Match the legacy U-Boot TFTP filename buffer. The legacy
* CONFIG_TFTP_FILE_NAME_MAX_LEN value is a buffer size including the trailing
* NUL, while lwIP's TFTP_MAX_FILENAME_LEN is the usable string length.
*/
#ifdef CONFIG_TFTP_FILE_NAME_MAX_LEN
#define TFTP_MAX_FILENAME_LEN (CONFIG_TFTP_FILE_NAME_MAX_LEN - 1)
#else
#define TFTP_MAX_FILENAME_LEN 127
#endif
#if defined(CONFIG_TFTP_BLOCKSIZE) && (CONFIG_TFTP_BLOCKSIZE > TFTP_BLOCKSIZE_THRESHOLD)
#define PBUF_POOL_SIZE (((CONFIG_TFTP_BLOCKSIZE + (IP_FRAG_MTU_USABLE - 1)) / \
IP_FRAG_MTU_USABLE) + PBUF_POOL_HEADROOM)
#define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - PBUF_POOL_RESERVE)
#else
#define PBUF_POOL_SIZE 8
#define IP_REASS_MAX_PBUFS 4
#endif
#define LWIP_ARP 1
#define ARP_TABLE_SIZE 4
#define ARP_QUEUEING 1
#define IP_FORWARD 0
#define IP_OPTIONS_ALLOWED 1
#define IP_REASSEMBLY 1
#define IP_FRAG 1
#define IP_REASS_MAXAGE 3
#define IP_FRAG_USES_STATIC_BUF 0
#define IP_DEFAULT_TTL 255
#if defined(CONFIG_PROT_ICMP_LWIP)
#define LWIP_ICMP 1
#else
#define LWIP_ICMP 0
#endif
#if defined(CONFIG_PROT_RAW_LWIP)
#define LWIP_RAW 1
#else
#define LWIP_RAW 0
#endif
#if defined(CONFIG_PROT_DHCP_LWIP)
#define LWIP_DHCP 1
#define LWIP_DHCP_BOOTP_FILE 1
#else
#define LWIP_DHCP 0
#endif
#define LWIP_DHCP_DOES_ACD_CHECK 0
#define LWIP_AUTOIP 0
#define LWIP_SNMP 0
#define LWIP_IGMP 0
#if defined(CONFIG_PROT_DNS_LWIP)
#define LWIP_DNS 1
#define DNS_TABLE_SIZE 1
#else
#define LWIP_DNS 0
#endif
#if defined(CONFIG_PROT_UDP_LWIP)
#define LWIP_UDP 1
#else
#define LWIP_UDP 0
#endif
/*
* PBUF_POOL_BUFSIZE is derived from TCP_MSS even when
* CONFIG_PROT_TCP_LWIP is not defined
*/
#define TCP_MSS 1460
#if defined(CONFIG_PROT_TCP_LWIP)
#define LWIP_TCP 1
#define TCP_WND CONFIG_LWIP_TCP_WND
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 0x7
#define TCP_SND_BUF (2 * TCP_MSS)
#ifdef CONFIG_PROT_TCP_SACK_LWIP
#define LWIP_TCP_SACK_OUT 1
#endif
#else
#define LWIP_TCP 0
#endif
#define LWIP_LISTEN_BACKLOG 0
#define PBUF_LINK_HLEN 14
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN)
#define LWIP_HAVE_LOOPIF 0
#define LWIP_NETCONN 0
#define LWIP_DISABLE_MEMP_SANITY_CHECKS 1
#define LWIP_SOCKET 0
#define SO_REUSE 0
#define LWIP_STATS 0
#define PPP_SUPPORT 0
#define LWIP_TCPIP_CORE_LOCKING 0
#define LWIP_NETIF_LOOPBACK 0
/* use malloc instead of pool */
#define MEMP_MEM_MALLOC 1
#define MEMP_MEM_INIT 1
#define MEM_LIBC_MALLOC 1
#if CONFIG_IS_ENABLED(MBEDTLS_LIB_TLS)
#define LWIP_ALTCP 1
#define LWIP_ALTCP_TLS 1
#define LWIP_ALTCP_TLS_MBEDTLS 1
#endif
#if defined(CONFIG_CMD_SNTP)
#define LWIP_DHCP_GET_NTP_SRV 1
#endif
#endif /* LWIP_UBOOT_LWIPOPTS_H */