summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile2
-rw-r--r--lib/binman.c1
-rw-r--r--lib/lwip/Makefile55
-rw-r--r--lib/lwip/lwip/src/apps/tftp/tftp.c102
-rw-r--r--lib/lwip/lwip/src/include/lwip/apps/tftp_client.h1
-rw-r--r--lib/lwip/u-boot/arch/cc.h45
-rw-r--r--lib/lwip/u-boot/arch/sys_arch.h0
-rw-r--r--lib/lwip/u-boot/limits.h0
-rw-r--r--lib/lwip/u-boot/lwipopts.h157
-rw-r--r--lib/tiny-printf.c3
10 files changed, 355 insertions, 11 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 3fc428cff1d..dbcfa87ebd6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -99,6 +99,8 @@ obj-$(CONFIG_$(PHASE_)OF_REAL) += fdtdec_common.o fdtdec.o
obj-$(CONFIG_MBEDTLS_LIB) += mbedtls/
+obj-$(CONFIG_NET_LWIP) += lwip/
+
ifdef CONFIG_XPL_BUILD
obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o
obj-$(CONFIG_$(PHASE_)HASH) += crc16-ccitt.o
diff --git a/lib/binman.c b/lib/binman.c
index 9047f5275f3..93d85548116 100644
--- a/lib/binman.c
+++ b/lib/binman.c
@@ -137,6 +137,7 @@ int binman_init(void)
{
int ret;
+ return 0;
binman = malloc(sizeof(struct binman_info));
if (!binman)
return log_msg_ret("space for binman", -ENOMEM);
diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile
new file mode 100644
index 00000000000..dfcd700ca47
--- /dev/null
+++ b/lib/lwip/Makefile
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2024 Linaro Ltd.
+
+obj-y += \
+ lwip/src/api/api_lib.o \
+ lwip/src/api/api_msg.o \
+ lwip/src/api/err.o \
+ lwip/src/api/if_api.o \
+ lwip/src/api/netbuf.o \
+ lwip/src/api/netdb.o \
+ lwip/src/api/netifapi.o \
+ lwip/src/api/sockets.o \
+ lwip/src/api/tcpip.o \
+ lwip/src/apps/http/http_client.o \
+ lwip/src/apps/tftp/tftp.o \
+ lwip/src/core/altcp_alloc.o \
+ lwip/src/core/altcp.o \
+ lwip/src/core/altcp_tcp.o \
+ lwip/src/core/def.o \
+ lwip/src/core/dns.o \
+ lwip/src/core/inet_chksum.o \
+ lwip/src/core/init.o \
+ lwip/src/core/ip.o \
+ lwip/src/core/ipv4/acd.o \
+ lwip/src/core/ipv4/autoip.o \
+ lwip/src/core/ipv4/dhcp.o \
+ lwip/src/core/ipv4/etharp.o \
+ lwip/src/core/ipv4/icmp.o \
+ lwip/src/core/ipv4/igmp.o \
+ lwip/src/core/ipv4/ip4_addr.o \
+ lwip/src/core/ipv4/ip4.o \
+ lwip/src/core/ipv4/ip4_frag.o \
+ lwip/src/core/ipv6/dhcp6.o \
+ lwip/src/core/ipv6/ethip6.o \
+ lwip/src/core/ipv6/icmp6.o \
+ lwip/src/core/ipv6/inet6.o \
+ lwip/src/core/ipv6/ip6_addr.o \
+ lwip/src/core/ipv6/ip6.o \
+ lwip/src/core/ipv6/ip6_frag.o \
+ lwip/src/core/ipv6/mld6.o \
+ lwip/src/core/ipv6/nd6.o \
+ lwip/src/core/mem.o \
+ lwip/src/core/memp.o \
+ lwip/src/core/netif.o \
+ lwip/src/core/pbuf.o \
+ lwip/src/core/raw.o \
+ lwip/src/core/stats.o \
+ lwip/src/core/sys.o \
+ lwip/src/core/tcp.o \
+ lwip/src/core/tcp_in.o \
+ lwip/src/core/tcp_out.o \
+ lwip/src/core/timeouts.o \
+ lwip/src/core/udp.o \
+ lwip/src/netif/ethernet.o
diff --git a/lib/lwip/lwip/src/apps/tftp/tftp.c b/lib/lwip/lwip/src/apps/tftp/tftp.c
index ddfdbfc0c1b..56aeabc4d73 100644
--- a/lib/lwip/lwip/src/apps/tftp/tftp.c
+++ b/lib/lwip/lwip/src/apps/tftp/tftp.c
@@ -57,7 +57,7 @@
#include "lwip/timeouts.h"
#include "lwip/debug.h"
-#define TFTP_MAX_PAYLOAD_SIZE 512
+#define TFTP_DEFAULT_BLOCK_SIZE 512
#define TFTP_HEADER_LENGTH 4
#define TFTP_RRQ 1
@@ -65,6 +65,7 @@
#define TFTP_DATA 3
#define TFTP_ACK 4
#define TFTP_ERROR 5
+#define TFTP_OACK 6
enum tftp_error {
TFTP_ERROR_FILE_NOT_FOUND = 1,
@@ -88,9 +89,11 @@ struct tftp_state {
int timer;
int last_pkt;
u16_t blknum;
+ u16_t blksize;
u8_t retries;
u8_t mode_write;
u8_t tftp_mode;
+ bool wait_oack;
};
static struct tftp_state tftp_state;
@@ -137,10 +140,22 @@ send_request(const ip_addr_t *addr, u16_t port, u16_t opcode, const char* fname,
{
size_t fname_length = strlen(fname)+1;
size_t mode_length = strlen(mode)+1;
- struct pbuf* p = init_packet(opcode, 0, fname_length + mode_length - 2);
+ size_t blksize_length = 0;
+ int blksize = tftp_state.blksize;
+ struct pbuf* p;
char* payload;
err_t ret;
+ if (blksize) {
+ /* 'blksize\0'.\0" with . = 1 digit */
+ blksize_length = strlen("blksize") + 1 + 1 + 1;
+ while (blksize >= 10) {
+ blksize /= 10;
+ blksize_length++;
+ }
+ }
+
+ p = init_packet(opcode, 0, fname_length + mode_length + blksize_length - 2);
if (p == NULL) {
return ERR_MEM;
}
@@ -148,7 +163,10 @@ send_request(const ip_addr_t *addr, u16_t port, u16_t opcode, const char* fname,
payload = (char*) p->payload;
MEMCPY(payload+2, fname, fname_length);
MEMCPY(payload+2+fname_length, mode, mode_length);
+ if (tftp_state.blksize)
+ sprintf(payload+2+fname_length+mode_length, "blksize%c%d%c", 0, tftp_state.blksize, 0);
+ tftp_state.wait_oack = true;
ret = udp_sendto(tftp_state.upcb, p, addr, port);
pbuf_free(p);
return ret;
@@ -221,14 +239,14 @@ send_data(const ip_addr_t *addr, u16_t port)
pbuf_free(tftp_state.last_data);
}
- tftp_state.last_data = init_packet(TFTP_DATA, tftp_state.blknum, TFTP_MAX_PAYLOAD_SIZE);
+ tftp_state.last_data = init_packet(TFTP_DATA, tftp_state.blknum, TFTP_DEFAULT_BLOCK_SIZE);
if (tftp_state.last_data == NULL) {
return;
}
payload = (u16_t *) tftp_state.last_data->payload;
- ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
+ ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_DEFAULT_BLOCK_SIZE);
if (ret < 0) {
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Error occurred while reading the file.");
close_handle();
@@ -239,6 +257,28 @@ send_data(const ip_addr_t *addr, u16_t port)
resend_data(addr, port);
}
+static u16_t payload_size(void)
+{
+ if (tftp_state.blksize)
+ return tftp_state.blksize;
+ return TFTP_DEFAULT_BLOCK_SIZE;
+}
+
+static const char *
+find_option(struct pbuf *p, const char *option)
+{
+ int i;
+ u16_t optlen = strlen(option);
+ const char *b = p->payload;
+
+ for (i = 0; i + optlen + 1 < p->len; i++) {
+ if (lwip_strnstr(b + i, option, optlen))
+ return b + i + optlen + 2;
+ }
+
+ return NULL;
+}
+
static void
tftp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
@@ -338,6 +378,15 @@ tftp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr
}
blknum = lwip_ntohs(sbuf[1]);
+ if (tftp_state.blksize && tftp_state.wait_oack) {
+ /*
+ * Data received while we are expecting an OACK for our blksize option.
+ * This means the server doesn't support it, let's switch back to the
+ * default block size.
+ */
+ tftp_state.blksize = 0;
+ tftp_state.wait_oack = false;
+ }
if (blknum == tftp_state.blknum) {
pbuf_remove_header(p, TFTP_HEADER_LENGTH);
@@ -349,7 +398,7 @@ tftp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr
send_ack(addr, port, blknum);
}
- if (p->tot_len < TFTP_MAX_PAYLOAD_SIZE) {
+ if (p->tot_len < payload_size()) {
close_handle();
} else {
tftp_state.blknum++;
@@ -386,7 +435,7 @@ tftp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr
lastpkt = 0;
if (tftp_state.last_data != NULL) {
- lastpkt = tftp_state.last_data->tot_len != (TFTP_MAX_PAYLOAD_SIZE + TFTP_HEADER_LENGTH);
+ lastpkt = tftp_state.last_data->tot_len != (TFTP_DEFAULT_BLOCK_SIZE + TFTP_HEADER_LENGTH);
}
if (!lastpkt) {
@@ -405,6 +454,25 @@ tftp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr
close_handle();
}
break;
+ case PP_HTONS(TFTP_OACK): {
+ const char *optval = find_option(p, "blksize");
+ u16_t srv_blksize = 0;
+ tftp_state.wait_oack = false;
+ if (optval) {
+ if (!tftp_state.blksize) {
+ /* We did not request this option */
+ send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "blksize unexpected");
+ }
+ srv_blksize = atoi(optval);
+ if (srv_blksize <= 0 || srv_blksize > tftp_state.blksize) {
+ send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Invalid blksize");
+ }
+ LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: accepting blksize=%d\n", srv_blksize));
+ tftp_state.blksize = srv_blksize;
+ }
+ send_ack(addr, port, 0);
+ break;
+ }
default:
send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Unknown operation");
break;
@@ -454,10 +522,12 @@ tftp_init_common(u8_t mode, const struct tftp_context *ctx)
return ERR_MEM;
}
- ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
- if (ret != ERR_OK) {
- udp_remove(pcb);
- return ret;
+ if (mode == LWIP_TFTP_MODE_SERVER) {
+ ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
+ if (ret != ERR_OK) {
+ udp_remove(pcb);
+ return ret;
+ }
}
tftp_state.handle = NULL;
@@ -494,6 +564,18 @@ tftp_init_client(const struct tftp_context *ctx)
}
/** @ingroup tftp
+ * Set the block size to be used by the TFTP client. The server may choose to
+ * accept a lower value.
+ * @param blksize Block size in bytes
+ */
+void
+tftp_client_set_blksize(u16_t blksize)
+{
+ if (blksize != TFTP_DEFAULT_BLOCK_SIZE)
+ tftp_state.blksize = blksize;
+}
+
+/** @ingroup tftp
* Deinitialize ("turn off") TFTP client/server.
*/
void tftp_cleanup(void)
diff --git a/lib/lwip/lwip/src/include/lwip/apps/tftp_client.h b/lib/lwip/lwip/src/include/lwip/apps/tftp_client.h
index 24dbda6a8c9..e1e21d06b67 100644
--- a/lib/lwip/lwip/src/include/lwip/apps/tftp_client.h
+++ b/lib/lwip/lwip/src/include/lwip/apps/tftp_client.h
@@ -44,6 +44,7 @@ enum tftp_transfer_mode {
};
err_t tftp_init_client(const struct tftp_context* ctx);
+void tftp_client_set_blksize(u16_t blksize);
err_t tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
err_t tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
diff --git a/lib/lwip/u-boot/arch/cc.h b/lib/lwip/u-boot/arch/cc.h
new file mode 100644
index 00000000000..563d3bfa98b
--- /dev/null
+++ b/lib/lwip/u-boot/arch/cc.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2023 Linaro Ltd. <maxim.uvarov@linaro.org> */
+
+#ifndef LWIP_ARCH_CC_H
+#define LWIP_ARCH_CC_H
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <vsprintf.h>
+#include <rand.h>
+
+#define LWIP_ERRNO_INCLUDE <errno.h>
+
+#define LWIP_ERRNO_STDINCLUDE 1
+#define LWIP_NO_UNISTD_H 1
+#define LWIP_TIMEVAL_PRIVATE 1
+
+#ifdef CONFIG_LIB_RAND
+#define LWIP_RAND() ((u32_t)rand())
+#else
+#define LWIP_DNS_SECURE 0
+#endif
+
+/* different handling for unit test, normally not needed */
+#ifdef LWIP_NOASSERT_ON_ERROR
+#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
+ handler; }} while (0)
+#endif
+
+#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
+
+#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
+ x, __LINE__, __FILE__); } while (0)
+
+#define atoi(str) (int)dectoul(str, NULL)
+#define lwip_strnstr(a, b, c) strstr(a, b)
+
+#define LWIP_ERR_T int
+#define LWIP_CONST_CAST(target_type, val) ((target_type)((uintptr_t)val))
+
+#if defined(CONFIG_SYS_BIG_ENDIAN)
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+
+#endif /* LWIP_ARCH_CC_H */
diff --git a/lib/lwip/u-boot/arch/sys_arch.h b/lib/lwip/u-boot/arch/sys_arch.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lib/lwip/u-boot/arch/sys_arch.h
diff --git a/lib/lwip/u-boot/limits.h b/lib/lwip/u-boot/limits.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lib/lwip/u-boot/limits.h
diff --git a/lib/lwip/u-boot/lwipopts.h b/lib/lwip/u-boot/lwipopts.h
new file mode 100644
index 00000000000..9d618625fac
--- /dev/null
+++ b/lib/lwip/u-boot/lwipopts.h
@@ -0,0 +1,157 @@
+/* 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
+
+#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
+#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
+#define PBUF_POOL_SIZE 8
+
+#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 0
+#define IP_FRAG 0
+#define IP_REASS_MAXAGE 3
+#define IP_REASS_MAX_PBUFS 4
+#define IP_FRAG_USES_STATIC_BUF 0
+
+#define IP_DEFAULT_TTL 255
+
+#define LWIP_ICMP 0
+
+#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
+
+#if defined(CONFIG_PROT_TCP_LWIP)
+#define LWIP_TCP 1
+#define TCP_MSS 1460
+#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
+
+#endif /* LWIP_UBOOT_LWIPOPTS_H */
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 64dee779c4a..cc1dfe61cf7 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -269,7 +269,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
}
break;
case 'p':
- if (CONFIG_IS_ENABLED(NET) || _DEBUG) {
+ if (CONFIG_IS_ENABLED(NET) ||
+ CONFIG_IS_ENABLED(NET_LWIP) || _DEBUG) {
pointer(info, fmt, va_arg(va, void *));
/*
* Skip this because it pulls in _ctype which is