Skip to contentSkip to conversation

sntp for NET_LWIP

PATCH Superseded Jerome Forissier 2 participants 21 messages Jun 6, 2025 – Jun 17, 2025 Networking

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover sntp for NET_LWIP

Implement the sntp command with lwIP (CONFIG_NET_LWIP=y). SNTP is supported as an app in lib/lwip/lwip/src/apps/sntp/sntp.c so this is mainly about adding that file to the build and writing do_sntp() to use the sntp_*() API and run the receive & timer loop. There is a patch to extract a small bit of common code from net/sntp.c to avoid duplication. The QEMU arm64 lwIP defconfig is updated to provide the sntp command by default for convenience.
I could not test the case when the NTP server IP is provided by DHCP. If someone has access right away to such a configuration and in case it does not work, please let me know.

Changes in v2:
- Move the network commands from net/lwip to cmd/lwip. Some commands such as dns and ping can be moved entirely, others such as dhcp, tftp and wget need to remain partly in net/lwip because the protocol may be used even when the command is not enabled.
- ping, sntp: accept host names in addtion to IP addresses
- Update doc/README.sntp

Jerome Forissier (13):
lwip: remove net/lwip/eth_internal.h
lwip: split cmd/net-lwip.c into one file per command
lwip: split net/lwip/wget.c
lwip: move net/lwip/dns.c to cmd/lwip
lwip: move net/lwip/ping.c to cmd/lwip
lwip: dns: do not return CMD_RET_FAILURE on successful resolution
lwip: dns: do not print IP address when a variable is specified
lwip: add net_lwip_dns_resolve()
lwip: ping: accept host name when CONFIG_CMD_DNS=y
net: extract function net_sntp_set_rtc() from sntp_handler()
lwip: add sntp command
Update doc/README.SNTP
configs: qemu_arm64_lwip_defconfig: enable CMD_SNTP

 MAINTAINERS                       |   1 +
 cmd/Kconfig                       |  13 +-
 cmd/Makefile                      |   2 +-
 cmd/lwip/Makefile                 |   6 +
 cmd/lwip/dhcp.c                   |   9 ++
 {net => cmd}/lwip/dns.c           |  14 +-
 {net => cmd}/lwip/ping.c          |   9 +-
 cmd/lwip/sntp.c                   | 133 ++++++++++++++++++
 cmd/lwip/tftp.c                   |   9 ++
 cmd/lwip/wget.c                   | 218 ++++++++++++++++++++++++++++++
 cmd/net-lwip.c                    |  50 -------
 configs/qemu_arm64_lwip_defconfig |   1 +
 doc/README.SNTP                   |  23 +++-
 include/net-common.h              |  13 ++
 include/net-lwip.h                |  14 ++
 lib/lwip/Makefile                 |   1 +
 lib/lwip/u-boot/arch/cc.h         |   4 +
 lib/lwip/u-boot/lwipopts.h        |   4 +
 net/lwip/Makefile                 |   2 -
 net/lwip/eth_internal.h           |  35 -----
 net/lwip/net-lwip.c               |  39 ++++++
 net/lwip/wget.c                   | 206 +---------------------------
 net/net-common.c                  |  23 ++++
 net/sntp.c                        |  23 +---
 24 files changed, 522 insertions(+), 330 deletions(-)
 create mode 100644 cmd/lwip/Makefile
 create mode 100644 cmd/lwip/dhcp.c
 rename {net => cmd}/lwip/dns.c (88%)
 rename {net => cmd}/lwip/ping.c (94%)
 create mode 100644 cmd/lwip/sntp.c
 create mode 100644 cmd/lwip/tftp.c
 create mode 100644 cmd/lwip/wget.c
 delete mode 100644 cmd/net-lwip.c
 delete mode 100644 net/lwip/eth_internal.h
Signature · 4 lines
2.43.0

base-commit: fdc0dcbb2c84c4c63fc10315bcf042575198610d
branch: lwip-sntp-v2
#1 lore raw

PATCH v2 1/13 lwip: remove net/lwip/eth_internal.h

net/lwip/eth_internal.h is not used. Remove it.

---

Changes in v2:
- New patch

 net/lwip/eth_internal.h | 35 -----------------------------------
 1 file changed, 35 deletions(-)
 delete mode 100644 net/lwip/eth_internal.h
net/lwip/eth_internal.h deleted +0 -35
deleted file mode 100644
index 87561d5b214..00000000000
@@ -1,35 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Copyright 2001-2015
- * Wolfgang Denk, DENX Software Engineering, [email protected].
- * Joe Hershberger, National Instruments
- */
-
-#ifndef __ETH_INTERNAL_H
-#define __ETH_INTERNAL_H
-
-/* Do init that is common to driver model and legacy networking */
-void eth_common_init(void);
-
-/**
- * eth_env_set_enetaddr_by_index() - set the MAC address environment variable
- *
- * This sets up an environment variable with the given MAC address (@enetaddr).
- * The environment variable to be set is defined by <@base_name><@index>addr.
- * If @index is 0 it is omitted. For common Ethernet this means ethaddr,
- * eth1addr, etc.
- *
- * @base_name:	Base name for variable, typically "eth"
- * @index:	Index of interface being updated (>=0)
- * @enetaddr:	Pointer to MAC address to put into the variable
- * Return: 0 if OK, other value on error
- */
-int eth_env_set_enetaddr_by_index(const char *base_name, int index,
-				  uchar *enetaddr);
-
-int eth_mac_skip(int index);
-void eth_current_changed(void);
-void eth_set_dev(struct udevice *dev);
-void eth_set_current_to_next(void);
-
-#endif
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/13 lwip: split cmd/net-lwip.c into one file per command

In reply to Jerome Forissier

Move each command in cmd/net-lwip.c into its own file (cmd/lwip/${cmd}.c).

---

Changes in v2:
- New patch

 MAINTAINERS                     |  1 +
 cmd/Makefile                    |  2 +-
 cmd/lwip/Makefile               |  5 +++++
 cmd/lwip/dhcp.c                 |  9 +++++++++
 cmd/lwip/dns.c                  |  8 ++++++++
 cmd/lwip/ping.c                 |  8 ++++++++
 cmd/lwip/tftp.c                 |  9 +++++++++
 cmd/{net-lwip.c => lwip/wget.c} | 26 +-------------------------
 8 files changed, 42 insertions(+), 26 deletions(-)
 create mode 100644 cmd/lwip/Makefile
 create mode 100644 cmd/lwip/dhcp.c
 create mode 100644 cmd/lwip/dns.c
 create mode 100644 cmd/lwip/ping.c
 create mode 100644 cmd/lwip/tftp.c
 rename cmd/{net-lwip.c => lwip/wget.c} (51%)
MAINTAINERS +1 -0
index d62dd35a385..e8f644fc75b 100644
@@ -1409,6 +1409,7 @@ F:	net/
 NETWORK (LWIP)
 M:	Jerome Forissier <[email protected]>
 S:	Maintained
+F:	cmd/lwip/
 F:	cmd/net-lwip.c
 F:	configs/qemu_arm64_lwip_defconfig
 F:	drivers/net/sandbox-lwip.c
cmd/Makefile +1 -1
index 80cf70b7fe8..2c6b13ffc5c 100644
@@ -133,7 +133,7 @@ obj-$(CONFIG_CMD_NAND) += nand.o
 ifdef CONFIG_NET
 obj-$(CONFIG_CMD_NET) += net.o net-common.o
 else ifdef CONFIG_NET_LWIP
-obj-$(CONFIG_CMD_NET) += net-lwip.o net-common.o
+obj-$(CONFIG_CMD_NET) += lwip/ net-common.o
 endif
 obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
cmd/lwip/Makefile new file +5 -0
new file mode 100644
index 00000000000..4c28d2b28e5
@@ -0,0 +1,5 @@
+obj-$(CONFIG_CMD_DHCP) += dhcp.o
+obj-$(CONFIG_CMD_DNS) += dns.o
+obj-$(CONFIG_CMD_PING) += ping.o
+obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
+obj-$(CONFIG_CMD_WGET) += wget.o
cmd/lwip/dhcp.c new file +9 -0
new file mode 100644
index 00000000000..3894d71f654
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024-2025 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+U_BOOT_CMD(dhcp, 3, 1, do_dhcp,
+	   "boot image via network using DHCP/TFTP protocol",
+	   "[loadAddress] [[hostIPaddr:]bootfilename]");
cmd/lwip/dns.c new file +8 -0
new file mode 100644
index 00000000000..31642b864af
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024-2025 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname",
+	   "hostname [envvar]");
cmd/lwip/ping.c new file +8 -0
new file mode 100644
index 00000000000..af5c022f55f
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024-2025 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host",
+	   "pingAddress");
cmd/lwip/tftp.c new file +9 -0
new file mode 100644
index 00000000000..6bb7a3733a2
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024-2025 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+U_BOOT_CMD(tftpboot, 3, 0, do_tftpb,
+	   "boot image via network using TFTP protocol",
+	   "[loadAddress] [[hostIPaddr:]bootfilename]");
cmd/lwip/wget.c renamed from cmd/net-lwip.c +1 -25
similarity index 51%
rename from cmd/net-lwip.c
rename to cmd/lwip/wget.c
index cecf8d02555..3f5b9952c93 100644
@@ -1,32 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0+
-/* Copyright (C) 2024 Linaro Ltd. */
+/* Copyright (C) 2024-2025 Linaro Ltd. */
 
 #include <command.h>
 #include <net.h>
 
-#if defined(CONFIG_CMD_DHCP)
-U_BOOT_CMD(dhcp, 3, 1, do_dhcp,
-	   "boot image via network using DHCP/TFTP protocol",
-	   "[loadAddress] [[hostIPaddr:]bootfilename]");
-#endif
-
-#if defined(CONFIG_CMD_PING)
-U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host",
-	   "pingAddress");
-#endif
-
-#if defined(CONFIG_CMD_TFTPBOOT)
-U_BOOT_CMD(tftpboot, 3, 0, do_tftpb,
-	   "boot image via network using TFTP protocol",
-	   "[loadAddress] [[hostIPaddr:]bootfilename]");
-#endif
-
-#if defined(CONFIG_CMD_DNS)
-U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname",
-	   "hostname [envvar]");
-#endif
-
-#if defined(CONFIG_CMD_WGET)
 U_BOOT_CMD(wget, 4, 1, do_wget,
 	   "boot image via network using HTTP/HTTPS protocol"
 #if defined(CONFIG_WGET_CACERT)
@@ -47,4 +24,3 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
 #endif
 #endif
 );
-#endif
Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 3/13 lwip: split net/lwip/wget.c

In reply to Jerome Forissier

Split net/lwip/wget.c in two: one part which implements CONFIG_WGET stays in net/ while the part that implements CONFIG_CMD_WGET is moved into cmd/.

---

Changes in v2:
- New patch

 cmd/lwip/wget.c    | 192 ++++++++++++++++++++++++++++++++++++++++++
 include/net-lwip.h |  13 +++
 net/lwip/wget.c    | 206 +--------------------------------------------
 3 files changed, 209 insertions(+), 202 deletions(-)
cmd/lwip/wget.c +192 -0
index 3f5b9952c93..5baad2e0f19 100644
@@ -2,7 +2,9 @@
 /* Copyright (C) 2024-2025 Linaro Ltd. */
 
 #include <command.h>
+#include <image.h>
 #include <net.h>
+#include <lwip/altcp_tls.h>
 
 U_BOOT_CMD(wget, 4, 1, do_wget,
 	   "boot image via network using HTTP/HTTPS protocol"
@@ -24,3 +26,193 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
 #endif
 #endif
 );
+
+#if CONFIG_IS_ENABLED(WGET_CACERT)
+char *cacert;
+size_t cacert_size;
+enum auth_mode cacert_auth_mode = AUTH_OPTIONAL;
+
+static int set_auth(enum auth_mode auth)
+{
+	cacert_auth_mode = auth;
+
+	return CMD_RET_SUCCESS;
+}
+
+#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
+static const char builtin_cacert[];
+static const size_t builtin_cacert_size;
+static bool cacert_initialized;
+#endif
+
+static int _set_cacert(const void *addr, size_t sz)
+{
+	mbedtls_x509_crt crt;
+	void *p;
+	int ret;
+
+	if (cacert)
+		free(cacert);
+
+	if (!addr) {
+		cacert = NULL;
+		cacert_size = 0;
+		return CMD_RET_SUCCESS;
+	}
+
+	p = malloc(sz);
+	if (!p)
+		return CMD_RET_FAILURE;
+	cacert = p;
+	cacert_size = sz;
+
+	memcpy(cacert, (void *)addr, sz);
+
+	mbedtls_x509_crt_init(&crt);
+	ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size);
+	if (ret) {
+		if (!wget_info->silent)
+			printf("Could not parse certificates (%d)\n", ret);
+		free(cacert);
+		cacert = NULL;
+		cacert_size = 0;
+		return CMD_RET_FAILURE;
+	}
+
+#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
+	cacert_initialized = true;
+#endif
+	return CMD_RET_SUCCESS;
+}
+
+#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
+static int set_cacert_builtin(void)
+{
+	return _set_cacert(builtin_cacert, builtin_cacert_size);
+}
+#endif
+
+static int set_cacert(char * const saddr, char * const ssz)
+{
+	ulong addr, sz;
+
+	addr = hextoul(saddr, NULL);
+	sz = hextoul(ssz, NULL);
+
+	return _set_cacert((void *)addr, sz);
+}
+#endif  /* CONFIG_WGET_CACERT */
+
+/*
+ * Legacy syntax support
+ * Convert [<server_name_or_ip>:]filename into a URL if needed
+ */
+static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
+{
+	char *p = nurl;
+	size_t n;
+	char *col = strchr(arg, ':');
+	char *env;
+	char *server;
+	char *path;
+
+	if (strstr(arg, "http") == arg) {
+		n = snprintf(nurl, rem, "%s", arg);
+		if (n < 0 || n > rem)
+			return -1;
+		return 0;
+	}
+
+	n = snprintf(p, rem, "%s", "http://");
+	if (n < 0 || n > rem)
+		return -1;
+	p += n;
+	rem -= n;
+
+	if (col) {
+		n = col - arg;
+		server = arg;
+		path = col + 1;
+	} else {
+		env = env_get("httpserverip");
+		if (!env)
+			env = env_get("serverip");
+		if (!env) {
+			log_err("error: httpserver/serverip has to be set\n");
+			return -1;
+		}
+		n = strlen(env);
+		server = env;
+		path = arg;
+	}
+
+	if (rem < n)
+		return -1;
+	strncpy(p, server, n);
+	p += n;
+	rem -= n;
+	if (rem < 1)
+		return -1;
+	*p = '/';
+	p++;
+	rem--;
+	n = strlen(path);
+	if (rem < n)
+		return -1;
+	strncpy(p, path, n);
+	p += n;
+	rem -= n;
+	if (rem < 1)
+		return -1;
+	*p = '\0';
+
+	return 0;
+}
+
+int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
+{
+	char *end;
+	char *url;
+	ulong dst_addr;
+	char nurl[1024];
+
+#if CONFIG_IS_ENABLED(WGET_CACERT)
+	if (argc == 4 && !strncmp(argv[1], "cacert", strlen("cacert")))
+		return set_cacert(argv[2], argv[3]);
+	if (argc == 3 && !strncmp(argv[1], "cacert", strlen("cacert"))) {
+#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
+		if (!strncmp(argv[2], "builtin", strlen("builtin")))
+			return set_cacert_builtin();
+#endif
+		if (!strncmp(argv[2], "none", strlen("none")))
+			return set_auth(AUTH_NONE);
+		if (!strncmp(argv[2], "optional", strlen("optional")))
+			return set_auth(AUTH_OPTIONAL);
+		if (!strncmp(argv[2], "required", strlen("required")))
+			return set_auth(AUTH_REQUIRED);
+		return CMD_RET_USAGE;
+	}
+#endif
+
+	if (argc < 2 || argc > 3)
+		return CMD_RET_USAGE;
+
+	dst_addr = hextoul(argv[1], &end);
+	if (end == (argv[1] + strlen(argv[1]))) {
+		if (argc < 3)
+			return CMD_RET_USAGE;
+		url = argv[2];
+	} else {
+		dst_addr = image_load_addr;
+		url = argv[1];
+	}
+
+	if (parse_legacy_arg(url, nurl, sizeof(nurl)))
+		return CMD_RET_FAILURE;
+
+	wget_info = &default_wget_info;
+	if (wget_do_request(dst_addr, nurl))
+		return CMD_RET_FAILURE;
+
+	return CMD_RET_SUCCESS;
+}
include/net-lwip.h +13 -0
index b762956e8fd..cf3cf513b2b 100644
@@ -6,6 +6,19 @@
 #include <lwip/ip4.h>
 #include <lwip/netif.h>
 
+#if CONFIG_IS_ENABLED(WGET_CACERT)
+/* HTTPS authentication mode */
+enum auth_mode {
+	AUTH_NONE,
+	AUTH_OPTIONAL,
+	AUTH_REQUIRED,
+};
+
+extern char *cacert;
+extern size_t cacert_size;
+extern enum auth_mode cacert_auth_mode;
+#endif
+
 enum proto_t {
 	TFTPGET
 };
net/lwip/wget.c +4 -202

246 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 03/13] lwip: split net/lwip/wget.c

Quoted 5 lines · Jerome Forissier

Split net/lwip/wget.c in two: one part which implements CONFIG_WGET stays in net/ while the part that implements CONFIG_CMD_WGET is moved into cmd/.

[snip]

Quoted 10 lines
include/net-lwip.h +2 -0
index b762956e8fd..cf3cf513b2b 100644
@@ -6,6 +6,19 @@
 #include <lwip/ip4.h>
 #include <lwip/netif.h>
 
+#if CONFIG_IS_ENABLED(WGET_CACERT)
+/* HTTPS authentication mode */

include/net-lwip.h line 20

Quoted 10 lines
include/net-lwip.h +10 -0
+enum auth_mode {
+	AUTH_NONE,
+	AUTH_OPTIONAL,
+	AUTH_REQUIRED,
+};
+
+extern char *cacert;
+extern size_t cacert_size;
+extern enum auth_mode cacert_auth_mode;
+#endif

Since we aren't going to run in to compile problems elsewhere because these are in the header file (IOW we don't reference CONFIG symbols which might not be set), we shouldn't guard these here. In general it's an anti-pattern because it makes it harder to do:
if (IS_ENABLED(CONFIG_FOO)) { ... }
in code. Thanks.

Signature · 1 line
Tom
#6 lore raw

PATCH v2 4/13 lwip: move net/lwip/dns.c to cmd/lwip

In reply to Jerome Forissier

Move the implementation of the dns command under cmd/.

---

Changes in v2:
- New patch

 cmd/lwip/dns.c    | 123 ++++++++++++++++++++++++++++++++++++++++++++
 net/lwip/Makefile |   1 -
 net/lwip/dns.c    | 128 ----------------------------------------------
 3 files changed, 123 insertions(+), 129 deletions(-)
 delete mode 100644 net/lwip/dns.c
cmd/lwip/dns.c +123 -0
index 31642b864af..be57a4d1b88 100644
@@ -2,7 +2,130 @@
 /* Copyright (C) 2024-2025 Linaro Ltd. */
 
 #include <command.h>
+#include <console.h>
+#include <lwip/dns.h>
+#include <lwip/timeouts.h>
 #include <net.h>
+#include <time.h>
 
 U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname",
 	   "hostname [envvar]");
+
+#define DNS_RESEND_MS 1000
+#define DNS_TIMEOUT_MS 10000
+
+struct dns_cb_arg {
+	ip_addr_t host_ipaddr;
+	const char *var;
+	bool done;
+};
+
+static void do_dns_tmr(void *arg)
+{
+	dns_tmr();
+}
+
+static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
+{
+	struct dns_cb_arg *dns_cb_arg = arg;
+	char *ipstr = ip4addr_ntoa(ipaddr);
+
+	dns_cb_arg->done = true;
+
+	if (!ipaddr) {
+		printf("DNS: host not found\n");
+		dns_cb_arg->host_ipaddr.addr = 0;
+		return;
+	}
+
+	if (dns_cb_arg->var)
+		env_set(dns_cb_arg->var, ipstr);
+
+	printf("%s\n", ipstr);
+}
+
+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;
+
+	netif = net_lwip_new_netif(udev);
+	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");
+		net_lwip_remove_netif(netif);
+		return CMD_RET_FAILURE;
+	}
+
+	dns_cb_arg.done = false;
+
+	ret = dns_gethostbyname(name, &ipaddr, dns_cb, &dns_cb_arg);
+
+	if (ret == ERR_OK) {
+		dns_cb(name, &ipaddr, &dns_cb_arg);
+	} else if (ret == ERR_INPROGRESS) {
+		start = get_timer(0);
+		sys_timeout(DNS_RESEND_MS, do_dns_tmr, NULL);
+		do {
+			net_lwip_rx(udev, netif);
+			if (dns_cb_arg.done)
+				break;
+			sys_check_timeouts();
+			if (ctrlc()) {
+				printf("\nAbort\n");
+				break;
+			}
+		} while (get_timer(start) < DNS_TIMEOUT_MS);
+		sys_untimeout(do_dns_tmr, NULL);
+	}
+
+	net_lwip_remove_netif(netif);
+
+	if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0)
+		return CMD_RET_SUCCESS;
+
+	return CMD_RET_FAILURE;
+}
+
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	char *name;
+	char *var = NULL;
+
+	if (argc == 1 || argc > 3)
+		return CMD_RET_USAGE;
+
+	name = argv[1];
+
+	if (argc == 3)
+		var = argv[2];
+
+	if (net_lwip_eth_start() < 0)
+		return CMD_RET_FAILURE;
+
+	return dns_loop(eth_get_dev(), name, var);
+}
net/lwip/Makefile +0 -1
index 5df222589b8..255c7d018b0 100644
@@ -2,7 +2,6 @@ ccflags-y += -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
 
 obj-$(CONFIG_$(PHASE_)DM_ETH) += net-lwip.o
 obj-$(CONFIG_CMD_DHCP) += dhcp.o
-obj-$(CONFIG_CMD_DNS) += dns.o
 obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
 obj-$(CONFIG_WGET) += wget.o
net/lwip/dns.c deleted +0 -128

128 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v2 04/13] lwip: move net/lwip/dns.c to cmd/lwip

Quoted 5 lines · Jerome Forissier

Move the implementation of the dns command under cmd/.

---

Quoted 8 lines

Changes in v2:
- New patch

 cmd/lwip/dns.c    | 123 ++++++++++++++++++++++++++++++++++++++++++++
 net/lwip/Makefile |   1 -
 net/lwip/dns.c    | 128 ----------------------------------------------
 3 files changed, 123 insertions(+), 129 deletions(-)
 delete mode 100644 net/lwip/dns.c

I assume this is copy/paste from the previous file to the new file. Since I've asked for other changes, maybe if you do the move then split cmd/net-lwip.c up git will more clearly see this as a move? I think you you reword the commits with "Prepare to split $cmd from cmd/net-lwip.c by moving ..." it will be sufficiently clear in the logs why there's a short time of not strictly cmd code in cmd/lwip/. Thanks!

Signature · 1 line
Tom
#8 lore raw

PATCH v2 5/13 lwip: move net/lwip/ping.c to cmd/lwip

In reply to Jerome Forissier

Move the implementation of the ping command under cmd/.

---

Changes in v2:
- New patch

 cmd/lwip/ping.c   | 175 ++++++++++++++++++++++++++++++++++++++++++++
 net/lwip/Makefile |   1 -
 net/lwip/ping.c   | 180 ----------------------------------------------
 3 files changed, 175 insertions(+), 181 deletions(-)
 delete mode 100644 net/lwip/ping.c
cmd/lwip/ping.c +175 -0
index af5c022f55f..21931821521 100644
@@ -2,7 +2,182 @@
 /* Copyright (C) 2024-2025 Linaro Ltd. */
 
 #include <command.h>
+#include <console.h>
+#include <dm/device.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <lwip/icmp.h>
+#include <lwip/inet_chksum.h>
+#include <lwip/raw.h>
+#include <lwip/timeouts.h>
 #include <net.h>
+#include <time.h>
 
 U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host",
 	   "pingAddress");
+
+#define PING_DELAY_MS 1000
+#define PING_COUNT 5
+/* Ping identifier - must fit on a u16_t */
+#define PING_ID 0xAFAF
+
+struct ping_ctx {
+	ip_addr_t target;
+	struct raw_pcb *pcb;
+	struct icmp_echo_hdr *iecho;
+	u16 seq_num;
+	bool alive;
+};
+
+static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p,
+		      const ip_addr_t *addr)
+{
+	struct ping_ctx *ctx = arg;
+	struct icmp_echo_hdr *iecho = ctx->iecho;
+
+	if (addr->addr != ctx->target.addr)
+		return 0;
+
+	if ((p->tot_len >= (IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
+	    pbuf_remove_header(p, IP_HLEN) == 0) {
+		iecho = (struct icmp_echo_hdr *)p->payload;
+
+		if (iecho->id == PING_ID &&
+		    iecho->seqno == lwip_htons(ctx->seq_num)) {
+			ctx->alive = true;
+			printf("host %s is alive\n", ipaddr_ntoa(addr));
+			pbuf_free(p);
+			return 1; /* eat the packet */
+		}
+		/* not eaten, restore original packet */
+		pbuf_add_header(p, IP_HLEN);
+	}
+
+	return 0; /* don't eat the packet */
+}
+
+static int ping_raw_init(struct ping_ctx *ctx)
+{
+	ctx->pcb = raw_new(IP_PROTO_ICMP);
+	if (!ctx->pcb)
+		return -ENOMEM;
+
+	raw_recv(ctx->pcb, ping_recv, ctx);
+	raw_bind(ctx->pcb, IP_ADDR_ANY);
+
+	return 0;
+}
+
+static void ping_raw_stop(struct ping_ctx *ctx)
+{
+	if (ctx->pcb)
+		raw_remove(ctx->pcb);
+}
+
+static void ping_prepare_echo(struct ping_ctx *ctx)
+{
+	struct icmp_echo_hdr *iecho = ctx->iecho;
+
+	ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+	ICMPH_CODE_SET(iecho, 0);
+	iecho->chksum = 0;
+	iecho->id = PING_ID;
+	iecho->seqno = lwip_htons(ctx->seq_num);
+
+	iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
+}
+
+static void ping_send_icmp(struct ping_ctx *ctx)
+{
+	struct pbuf *p;
+	size_t ping_size = sizeof(struct icmp_echo_hdr);
+
+	p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
+	if (!p)
+		return;
+
+	if (p->len == p->tot_len && !p->next) {
+		ctx->iecho = (struct icmp_echo_hdr *)p->payload;
+		ping_prepare_echo(ctx);
+		raw_sendto(ctx->pcb, p, &ctx->target);
+	}
+
+	pbuf_free(p);
+}
+
+static void ping_send(void *arg)
+{
+	struct ping_ctx *ctx = arg;
+
+	ctx->seq_num++;
+	if (ctx->seq_num <= PING_COUNT) {
+		ping_send_icmp(ctx);
+		sys_timeout(PING_DELAY_MS, ping_send, ctx);
+	}
+}
+
+static int ping_loop(struct udevice *udev, const ip_addr_t *addr)
+{
+	struct ping_ctx ctx = {};
+	struct netif *netif;
+	int ret;
+
+	netif = net_lwip_new_netif(udev);
+	if (!netif)
+		return -ENODEV;
+
+	printf("Using %s device\n", udev->name);
+
+	ret = ping_raw_init(&ctx);
+	if (ret < 0) {
+		net_lwip_remove_netif(netif);
+		return ret;
+	}
+
+	ctx.target = *addr;
+
+	ping_send(&ctx);
+
+	do {
+		sys_check_timeouts();
+		net_lwip_rx(udev, netif);
+		if (ctx.alive)
+			break;
+		if (ctrlc()) {
+			printf("\nAbort\n");
+			break;
+		}
+	} while (ctx.seq_num <= PING_COUNT);
+
+	sys_untimeout(ping_send, &ctx);
+	ping_raw_stop(&ctx);
+
+	net_lwip_remove_netif(netif);
+
+	if (ctx.alive)
+		return 0;
+
+	printf("ping failed; host %s is not alive\n", ipaddr_ntoa(addr));
+	return -1;
+}
+
+int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	ip_addr_t addr;
+
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+	if (!ipaddr_aton(argv[1], &addr))
+		return CMD_RET_USAGE;
+
+restart:
+	if (net_lwip_eth_start() < 0 || ping_loop(eth_get_dev(), &addr) < 0) {
+		if (net_start_again() == 0)
+			goto restart;
+		else
+			return CMD_RET_FAILURE;
+	}
+
+	return CMD_RET_SUCCESS;
+}
net/lwip/Makefile +0 -1
index 255c7d018b0..97299d9b542 100644
@@ -2,7 +2,6 @@ ccflags-y += -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
 
 obj-$(CONFIG_$(PHASE_)DM_ETH) += net-lwip.o
 obj-$(CONFIG_CMD_DHCP) += dhcp.o
-obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
 obj-$(CONFIG_WGET) += wget.o
 
net/lwip/ping.c deleted +0 -180

180 lines not on this page · raw message

Signature · 1 line
2.43.0
#9 lore raw

PATCH v2 6/13 lwip: dns: do not return CMD_RET_FAILURE on successful resolution

In reply to Jerome Forissier

The DNS loop checks for a non-zero IP address after DNS resolution, but the address is in fact never copied into the context. Fix that.

---

Changes in v2:
- New patch

 cmd/lwip/dns.c | 2 ++
 1 file changed, 2 insertions(+)
cmd/lwip/dns.c +2 -0
index be57a4d1b88..b757638cd1e 100644
@@ -38,6 +38,8 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 		return;
 	}
 
+	dns_cb_arg->host_ipaddr.addr = ipaddr->addr;
+
 	if (dns_cb_arg->var)
 		env_set(dns_cb_arg->var, ipstr);
 
Signature · 1 line
2.43.0
#10 lore raw

PATCH v2 7/13 lwip: dns: do not print IP address when a variable is specified

In reply to Jerome Forissier

When calling "dns <hostname> <varname>", do not print out the IP address of <hostname> onto the console. Print it only when no variable is passed. The reason is to be able to call do_dns() from another command in need of the DNS services without polluting the output.

---

Changes in v2:
- New patch

 cmd/lwip/dns.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cmd/lwip/dns.c +4 -3
index b757638cd1e..0bfd8f198cf 100644
@@ -42,8 +42,6 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 
 	if (dns_cb_arg->var)
 		env_set(dns_cb_arg->var, ipstr);
-
-	printf("%s\n", ipstr);
 }
 
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
@@ -107,8 +105,11 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 
 	net_lwip_remove_netif(netif);
 
-	if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0)
+	if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) {
+		if (!var)
+			printf("%s\n", ipaddr_ntoa(&ipaddr));
 		return CMD_RET_SUCCESS;
+	}
 
 	return CMD_RET_FAILURE;
 }
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH v2 07/13] lwip: dns: do not print IP address when a variable is specified

Quoted 6 lines · Jerome Forissier

When calling "dns <hostname> <varname>", do not print out the IP address of <hostname> onto the console. Print it only when no variable is passed. The reason is to be able to call do_dns() from another command in need of the DNS services without polluting the output.

As I do not know off-hand, how does this compare with other commands which can be used to set a variable? I assume it's similar. And then, oh, we don't have doc/cmd/usage/dns.rst to start with. So, follow-up to this series please, document the network commands that we have in both lwip and legacy stack and please note where there's differences if any. Thanks!

Signature · 1 line
Tom
#12 lore raw

Re: [PATCH v2 07/13] lwip: dns: do not print IP address when a variable is specified

Quoted 11 lines · Tom Rini
Quoted 6 lines · Jerome Forissier

When calling "dns <hostname> <varname>", do not print out the IP address of <hostname> onto the console. Print it only when no variable is passed. The reason is to be able to call do_dns() from another command in need of the DNS services without polluting the output.

As I do not know off-hand, how does this compare with other commands which can be used to set a variable? I assume it's similar.

Yes, it seems to be a general pattern. For example:
- 'part list <interface> <dev> [flags] <varname>', see do_part_list() (and other sub-commands as well)
- 'op count [*]src1 [*]src2 [[*]dest]', see do_binop()
- 'sm reboot_reason [name]', see do_sm_reboot_reason()
etc.

Quoted 4 lines

And then,
oh, we don't have doc/cmd/usage/dns.rst to start with. So, follow-up to this series please, document the network commands that we have in both lwip and legacy stack and please note where there's differences if any.

Added to my to-do list ;)

Thanks,

Signature · 1 line
Jerome
#13 lore raw

PATCH v2 8/13 lwip: add net_lwip_dns_resolve()

In reply to Jerome Forissier

Add a helper fonction to convert an IP address (supplied as a text string) or a host name to an ip_addr_t.

---

Changes in v2:
- New patch

 include/net-lwip.h  |  1 +
 net/lwip/net-lwip.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/net-lwip.h +1 -0
index cf3cf513b2b..4240aa4b0b2 100644
@@ -36,6 +36,7 @@ struct netif *net_lwip_new_netif_noip(struct udevice *udev);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 int net_lwip_rx(struct udevice *udev, struct netif *netif);
+int net_lwip_dns_resolve(char *name_or_ip, ip_addr_t *ip);
 
 /**
  * wget_validate_uri() - varidate the uri
net/lwip/net-lwip.c +39 -0
index f05c4cd3f64..c9a7114bbff 100644
@@ -6,6 +6,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <hexdump.h>
+#include <linux/kernel.h>
 #include <lwip/ip4_addr.h>
 #include <lwip/err.h>
 #include <lwip/netif.h>
@@ -315,6 +316,44 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif)
 	return len;
 }
 
+/**
+ * net_lwip_dns_resolve() - find IP address from name or IP
+ *
+ * @name_or_ip: host name or IP address
+ * @ip: output IP address
+ *
+ * Return value: 0 on success, -1 on failure.
+ */
+int net_lwip_dns_resolve(char *name_or_ip, ip_addr_t *ip)
+{
+#if defined(CONFIG_CMD_DNS)
+	char *var = "_dnsres";
+	char *argv[] = { "dns", name_or_ip, var, NULL };
+	int argc = ARRAY_SIZE(argv) - 1;
+#endif
+
+	if (ipaddr_aton(name_or_ip, ip))
+		return 0;
+
+#if defined(CONFIG_CMD_DNS)
+	if (do_dns(NULL, 0, argc, argv) != CMD_RET_SUCCESS)
+		return -1;
+
+	name_or_ip = env_get(var);
+	if (!name_or_ip)
+		return -1;
+
+	if (!ipaddr_aton(name_or_ip, ip))
+		return -1;
+
+	env_set(var, NULL);
+
+	return 0;
+#else
+	return -1;
+#endif
+}
+
 void net_process_received_packet(uchar *in_packet, int len)
 {
 #if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
Signature · 1 line
2.43.0
#14 lore raw

PATCH v2 9/13 lwip: ping: accept host name when CONFIG_CMD_DNS=y

In reply to Jerome Forissier

Update the ping command so that a host name is accepted in addition to an IP address, provided DNS support is enabled.

---

Changes in v2:
- New patch

 cmd/lwip/ping.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/lwip/ping.c +2 -2
index 21931821521..9fe02a21a78 100644
@@ -14,7 +14,7 @@
 #include <time.h>
 
 U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host",
-	   "pingAddress");
+	   "pingAddressOrHostName");
 
 #define PING_DELAY_MS 1000
 #define PING_COUNT 5
@@ -168,7 +168,7 @@ int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
-	if (!ipaddr_aton(argv[1], &addr))
+	if (net_lwip_dns_resolve(argv[1], &addr))
 		return CMD_RET_USAGE;
 
 restart:
Signature · 1 line
2.43.0
#15 lore raw

PATCH v2 10/13 net: extract function net_sntp_set_rtc() from sntp_handler()

In reply to Jerome Forissier

Extract the code that sets the RTC clock from sntp_handler() in net/sntp.c and make it a new function net_sntp_set_rtc() in net/net-common.c. This will allow re-use with NET_LWIP.

According to [1] it is safe to assume that all devices have been converted to DM_RTC so drop the useless code.

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

---

Changes in v2:
- Drop the non-RTC case

 include/net-common.h |  2 ++
 net/net-common.c     | 23 +++++++++++++++++++++++
 net/sntp.c           | 23 +++--------------------
 3 files changed, 28 insertions(+), 20 deletions(-)
include/net-common.h +2 -0
index 7853612b237..c212d2f9b3b 100644
@@ -588,4 +588,6 @@ extern struct wget_http_info default_wget_info;
 extern struct wget_http_info *wget_info;
 int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info);
 
+void net_sntp_set_rtc(u32 seconds);
+
 #endif /* __NET_COMMON_H__ */
net/net-common.c +23 -0
index e01b0da7d7b..b064557d524 100644
@@ -1,5 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
+
+#include <dm/uclass.h>
 #include <net-common.h>
+#include <linux/time.h>
+#include <rtc.h>
 
 void copy_filename(char *dst, const char *src, int size)
 {
@@ -25,3 +29,22 @@ int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info)
 	wget_info = info ? info : &default_wget_info;
 	return wget_do_request(dst_addr, uri);
 }
+
+void net_sntp_set_rtc(u32 seconds)
+{
+	struct rtc_time tm;
+	struct udevice *dev;
+	int ret;
+
+	rtc_to_tm(seconds, &tm);
+
+	ret = uclass_get_device(UCLASS_RTC, 0, &dev);
+	if (ret)
+		printf("SNTP: cannot find RTC: err=%d\n", ret);
+	else
+		dm_rtc_set(dev, &tm);
+
+	printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
+	       tm.tm_year, tm.tm_mon, tm.tm_mday,
+	       tm.tm_hour, tm.tm_min, tm.tm_sec);
+}
net/sntp.c +3 -20
index 73d1d87d38b..77cee0046bd 100644
@@ -57,8 +57,7 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 			 unsigned src, unsigned len)
 {
 	struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
-	struct rtc_time tm;
-	ulong seconds;
+	u32 seconds;
 
 	debug("%s\n", __func__);
 
@@ -69,24 +68,8 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 	 * As the RTC's used in U-Boot support second resolution only
 	 * we simply ignore the sub-second field.
 	 */
-	memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
-
-	rtc_to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
-#ifdef CONFIG_DM_RTC
-	struct udevice *dev;
-	int ret;
-
-	ret = uclass_get_device(UCLASS_RTC, 0, &dev);
-	if (ret)
-		printf("SNTP: cannot find RTC: err=%d\n", ret);
-	else
-		dm_rtc_set(dev, &tm);
-#elif defined(CONFIG_CMD_DATE)
-	rtc_set(&tm);
-#endif
-	printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
-	       tm.tm_year, tm.tm_mon, tm.tm_mday,
-	       tm.tm_hour, tm.tm_min, tm.tm_sec);
+	memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(seconds));
+	net_sntp_set_rtc(ntohl(seconds) - 2208988800UL + net_ntp_time_offset);
 
 	net_set_state(NETLOOP_SUCCESS);
 }
Signature · 1 line
2.43.0
#16 lore raw

PATCH v2 11/13 lwip: add sntp command

In reply to Jerome Forissier

Implement the sntp command when NET_LWIP=y.

---

(no changes since v1)

 cmd/Kconfig                |  13 ++--
 cmd/lwip/Makefile          |   1 +
 cmd/lwip/sntp.c            | 133 +++++++++++++++++++++++++++++++++++++
 include/net-common.h       |  11 +++
 lib/lwip/Makefile          |   1 +
 lib/lwip/u-boot/arch/cc.h  |   4 ++
 lib/lwip/u-boot/lwipopts.h |   4 ++
 7 files changed, 161 insertions(+), 6 deletions(-)
 create mode 100644 cmd/lwip/sntp.c
cmd/Kconfig +7 -6
index f21d27cb27f..58f629e1c34 100644
@@ -2061,12 +2061,6 @@ config CMD_CDP
 	  and to retrieve configuration data including the VLAN id using the
 	  proprietary Cisco Discovery Protocol (CDP).
 
-config CMD_SNTP
-	bool "sntp"
-	select PROT_UDP
-	help
-	  Synchronize RTC via network
-
 config CMD_LINK_LOCAL
 	bool "linklocal"
 	depends on (LIB_RAND || LIB_HW_RAND)
@@ -2144,6 +2138,13 @@ config CMD_PING
 	help
 	  Send ICMP ECHO_REQUEST to network host
 
+config CMD_SNTP
+	bool "sntp"
+	select PROT_UDP if NET
+	select PROT_UDP_LWIP if NET_LWIP
+	help
+	  Synchronize RTC via network
+
 config CMD_TFTPBOOT
 	bool "tftp"
 	select PROT_UDP_LWIP if NET_LWIP
cmd/lwip/Makefile +1 -0
index 4c28d2b28e5..a7f8976af3f 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_CMD_DHCP) += dhcp.o
 obj-$(CONFIG_CMD_DNS) += dns.o
 obj-$(CONFIG_CMD_PING) += ping.o
+obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
 obj-$(CONFIG_CMD_WGET) += wget.o
cmd/lwip/sntp.c new file +133 -0

133 lines not on this page · raw message

include/net-common.h +11 -0
index c212d2f9b3b..885ba97fdf3 100644
@@ -505,6 +505,17 @@ int dhcp_run(ulong addr, const char *fname, bool autoload);
  */
 int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
+/**
+ * do_sntp - Run the sntp command
+ *
+ * @cmdtp: Unused
+ * @flag: Command flags (CMD_FLAG_...)
+ * @argc: Number of arguments
+ * @argv: List of arguments
+ * Return: result (see enum command_ret_t)
+ */
+int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+
 /**
  * do_tftpb - Run the tftpboot command
  *
lib/lwip/Makefile +1 -0
index e9e8caee93a..c3f0e916f66 100644
@@ -13,6 +13,7 @@ obj-y += \
 	lwip/src/api/sockets.o \
 	lwip/src/api/tcpip.o \
 	lwip/src/apps/http/http_client.o \
+	lwip/src/apps/sntp/sntp.o \
 	lwip/src/apps/tftp/tftp.o \
 	lwip/src/core/altcp_alloc.o \
 	lwip/src/core/altcp.o \
lib/lwip/u-boot/arch/cc.h +4 -0
index 6104c296f6f..f91127ac565 100644
@@ -43,4 +43,8 @@
 #define BYTE_ORDER BIG_ENDIAN
 #endif
 
+#define SNTP_STARTUP_DELAY 0
+void sntp_set_system_time(uint32_t sec);
+#define SNTP_SET_SYSTEM_TIME(sec) sntp_set_system_time(sec)
+
 #endif /* LWIP_ARCH_CC_H */
lib/lwip/u-boot/lwipopts.h +4 -0
index edac74ff7a2..14ba7bd7ae2 100644
@@ -162,4 +162,8 @@
 #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 */
Signature · 1 line
2.43.0
#17 lore raw

PATCH v2 12/13 Update doc/README.SNTP

In reply to Jerome Forissier

Fix an error in doc/README.SNTP ("timeoffset") and clarify the differences between CONFIG_NET=y and CONFIG_NET_LWIP=y.

---

Changes in v2:
- New patch

 doc/README.SNTP | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
doc/README.SNTP +16 -7
index da9ec459ad4..da68aa318a5 100644
@@ -4,14 +4,23 @@ configuration file of the board.
 The "sntp" command gets network time from NTP time server and
 syncronize RTC of the board. This command needs the command line
 parameter of server's IP address or environment variable
-"ntpserverip". The network time is sent as UTC. So if you want to
-set local time to RTC, set the offset in second from UTC to the
-environment variable "time offset".
+"ntpserverip".
 
-If the DHCP server provides time server's IP or time offset, you
-don't need to set the above environment variables yourself.
+[CONFIG_NET_LWIP=y only] The host name of the NTP server may be
+provided instead of its IP address provided that CONFIG_CMD_DNS=y.
+
+The NTP server address does not need to be given if the DHCP server
+provides one.
+
+The network time is sent as UTC. So if you want to set local time to
+RTC, set the offset in second from UTC to the environment variable
+"timeoffset".
+
+[CONFIG_NET=y only] If the DHCP server provides time server's IP
+or time offset, you don't need to set the above environment
+variables yourself.
 
 Current limitations of SNTP support:
 1. The roundtrip time is ignored.
-2. Only the 1st NTP server IP, in the option ntp-servers of DHCP, will
-   be used.
+2. [CONFIG_NET=y only] Only the 1st NTP server IP, in the option
+   ntp-servers of DHCP, will be used.
Signature · 1 line
2.43.0
#18 lore raw

Re: [PATCH v2 12/13] Update doc/README.SNTP

Quoted 11 lines · Jerome Forissier

Fix an error in doc/README.SNTP ("timeoffset") and clarify the differences between CONFIG_NET=y and CONFIG_NET_LWIP=y.

---

Changes in v2:
- New patch

 doc/README.SNTP | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Thanks for touching the docs. But, can you please convert this to rst and then update it?

Signature · 1 line
Tom
#19 lore raw

Re: [PATCH v2 12/13] Update doc/README.SNTP

Quoted 8 lines · Tom Rini
Quoted 6 lines · Jerome Forissier

Fix an error in doc/README.SNTP ("timeoffset") and clarify the differences between CONFIG_NET=y and CONFIG_NET_LWIP=y.

---

Quoted 8 lines
Quoted 5 lines

Changes in v2:
- New patch

 doc/README.SNTP | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Thanks for touching the docs. But, can you please convert this to rst and then update it?

OK. I will post a v3 with a new file: doc/usage/cmd/sntp.rst.

Thanks,

Signature · 1 line
Jerome
#20 lore raw

PATCH v2 13/13 configs: qemu_arm64_lwip_defconfig: enable CMD_SNTP

In reply to Jerome Forissier

Enable the sntp command by default in the arm64 QEMU defconfig for lwIP since this config is meant to have all the features supported by lwIP.

---

(no changes since v1)

 configs/qemu_arm64_lwip_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/qemu_arm64_lwip_defconfig +1 -0
index 814e98729a3..e8f976efaf7 100644
@@ -5,6 +5,7 @@ CONFIG_ARCH_QEMU=y
 
 CONFIG_NET_LWIP=y
 CONFIG_CMD_DNS=y
+CONFIG_CMD_SNTP=y
 CONFIG_CMD_WGET=y
 CONFIG_EFI_HTTP_BOOT=y
 CONFIG_WGET_HTTPS=y
Signature · 1 line
2.43.0