Skip to contentSkip to conversation

Introduce the lwIP network stack

PATCH Superseded Jerome Forissier 3 participants 27 messages Jun 6, 2024 – Jun 7, 2024

Subsystems (6)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce the lwIP network stack

This is a rework of a patch series by Maxim Uvarov: "net/lwip: add lwip library for the network stack" [1]. The goal is to introduce the lwIP TCP/IP stack [2] [3] as an alternative to the current implementation in net/, selectable with Kconfig, and ultimately keep only lwIP if possible. Some reasons for doing so are:
- Make the support of HTTPS in the wget command easier. Javier T. (CC'd) has some additional lwIP and Mbed TLS patches to do so. With that it becomes possible to fetch and launch a distro installer such as Debian etc. using a secure, authenticated connection directly from the U-Boot shell. Several use cases:
* Authentication: prevent MITM attack (third party replacing the
binary with a different one)
* Confidentiality: prevent third parties from grabbing a copy of the
image as it is being downloaded
* Allow connection to servers that do not support plain HTTP anymore
(this is becoming more and more common on the Internet these days)
- Possibly benefit from additional features implemented in lwIP
- Less code to maintain in U-Boot

Prior to applying this series, the lwIP stack needs to be added as a Git subtree with the following command:

 $  git subtree add --squash --prefix lib/lwip/lwip https://git.savannah.gnu.org/git/lwip.git STABLE-2_2_0_RELEASE

The first patch introduces a new Kconfig symbol: NET_LWIP, which selects the lwIP implementation instead of the current one (NET). Contrary to the approach chosen by Maxim in [1], NET_LWIP and NET cannot be enabled simultaneously. The rationale is we want to start from a clean state and not pull potentially duplicated functionality from both stacks. Note however that a few files are still built in net/, they are the ones related to ethernet device management and the ethernet bootflow.

The second patch introduces the Makefile to build lwIP when NET_LWIP is enabled.

The subsequent patches implement various network-oriented commands and
features: dhcp, dns, ping, tftpboot, wget.

NET_LWIP is not enabled by default because it lacks functionality compared to NET and many CI tests would fail to run or even build.

Some tests (dm dsa/eth) are disabled when NET_LWIP is selected because they make strong assumptions on how the network stack is implemented and how the packet flow occurs. For example, an ARP exchange is expected when an ICMP packet goes out, but with lwIP no exchange will occur if the host IP is already in the the ARP cache.

Due to the above and in order to provide some level of testing, a new QEMU configuration is introduced (qemu_arm64_lwip_defconfig) which is the same as qemu_arm64_lwip_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Changes in v3:

- Make NET_LWIP a Kconfig choice in patch "net: introduce alternative implementation as net-lwip/" (Tom R.)
- Drop the patch introducing lwIP as a Git subtree and document the git command in the cover letter instead (Tom R.)
- "net-lwip: add TFTP support and tftpboot command": use the same "Bytes transferred =" message as in the legacy implementation (Tom R., Maxim U.)
- Drop "test/py: net: add _lwip variants of dhcp, ping and tftpboot tests" which is not needed anymore.
- Add missing kfree() calls in cmd/net-common.c and fix the parsing of decimal address in net-lwip/wget.c (patch "net-lwip: add wget command") (Maxim U.)
- "net-lwip: add ping command": drop the ICMP payload (Ilias A.). Set the sequence number to zero when entering ping_loop().

Changes in v2:

** Address comments from Ilias A.

- "net-lwip: add wget command"
Implement the wget_with_dns() function to do most of the wget work and call it from do_wget(). This allows to simplify patch "net-lwip: add support for EFI_HTTP_BOOT".

- "net-lwip: import net command from cmd/net.c"
Move a few functions from cmd/net.c to a new file cmd/net-common.c rather than duplicating then in cmd/net-lwip.c.

- "net-lwip: add support for EFI_HTTP_BOOT"
Since wget_with_dns() is now implemented in "net-lwip: add wget command", just enable the wget command when the lwIP stack is enabled and EFI_HTTP_BOOT is requested.

** Address comments from Tom R.

- "net-lwip: add DHCP support and dhcp commmand", "net-lwip: add TFTP support and tftpboot command", "net-lwip: add ping command",
"net-lwip: add dns command",
"net-lwip: add wget command"
Do not introduce new CMD_XXX_LWIP symbols and use existing CMD_XXX instead.

- "configs: add qemu_arm64_lwip_defconfig"
Use #include <configs/qemu_arm64_defconfig>.

- "net-lwip: import lwIP library under lib/lwip"
Patch removed and replaced by the introduction of a Git subtree:
"Squashed 'lib/lwip/lwip/' content from commit 0a0452b2c3".

Note that I have not yet addressed your comments on "test: dm: dsa,
eth: disable tests when CONFIG_NET_LWIP=y"). I need some more time for that and I think running CI on this v2 will help better understand what is needed for v3.

** Miscellaneous improvements

- "net: introduce alternative implementation as net-lwip/":

* Make DFU_OVER_TFTP not DFU_TFTP incompatible with NET_LWIP. It seems quite natural to supplement "depends on NET" with "&& !NET_LWIP".
* Make PROT_*_LWIP not visible by removing the Kconfig prompt.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://www.nongnu.org/lwip/
[3] https://en.wikipedia.org/wiki/LwIP

CC Javier Tia <[email protected]>

Jerome Forissier (12):
net: introduce alternative implementation as net-lwip/
net-lwip: build lwIP
net-lwip: add DHCP support and dhcp commmand
net-lwip: add TFTP support and tftpboot command
net-lwip: add ping command
net-lwip: add dns command
net-lwip: add wget command
test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y
cmd: bdinfo: enable -e when CONFIG_CMD_NET_LWIP=y
configs: add qemu_arm64_lwip_defconfig
MAINTAINERS: net-lwip: add myself as a maintainer
CI: add qemu_arm64_lwip to the test matrix

 .azure-pipelines.yml              |   7 +
 Kconfig                           |  40 ++++++
 MAINTAINERS                       |  11 ++
 Makefile                          |   3 +-
 boot/Kconfig                      |   5 +-
 cmd/Kconfig                       |  44 ++++++
 cmd/Makefile                      |   7 +
 cmd/bdinfo.c                      |   5 +-
 cmd/efidebug.c                    |   8 +-
 cmd/net-common.c                  | 115 +++++++++++++++
 cmd/net-lwip.c                    |  49 +++++++
 cmd/net.c                         | 115 ---------------
 common/Kconfig                    |   2 +-
 common/board_r.c                  |   4 +-
 common/spl/Kconfig                |   1 +
 configs/qemu_arm64_lwip_defconfig |   3 +
 drivers/dfu/Kconfig               |   2 +-
 drivers/fastboot/Kconfig          |   4 +-
 drivers/net/Kconfig               |   2 +-
 drivers/net/phy/Kconfig           |   2 +-
 drivers/usb/gadget/Kconfig        |   2 +-
 include/net-lwip.h                | 140 +++++++++++++++++++
 include/net.h                     |   2 +-
 lib/Makefile                      |   2 +
 lib/lwip/Makefile                 |  57 ++++++++
 lib/lwip/u-boot/arch/cc.h         |  43 ++++++
 lib/lwip/u-boot/arch/sys_arch.h   |   0
 lib/lwip/u-boot/limits.h          |   0
 lib/lwip/u-boot/lwipopts.h        | 197 ++++++++++++++++++++++++++
 net-lwip/Kconfig                  |  37 +++++
 net-lwip/Makefile                 |  18 +++
 net-lwip/dhcp.c                   | 114 +++++++++++++++
 net-lwip/dns.c                    | 107 ++++++++++++++
 net-lwip/eth_internal.h           |  35 +++++
 net-lwip/net-lwip.c               | 224 ++++++++++++++++++++++++++++++
 net-lwip/ping.c                   | 163 ++++++++++++++++++++++
 net-lwip/tftp.c                   | 209 ++++++++++++++++++++++++++++
 net-lwip/wget.c                   | 180 ++++++++++++++++++++++++
 net/Kconfig                       |  14 --
 test/dm/dsa.c                     |   2 +
 test/dm/eth.c                     |   4 +
 41 files changed, 1832 insertions(+), 147 deletions(-)
 create mode 100644 cmd/net-common.c
 create mode 100644 cmd/net-lwip.c
 create mode 100644 configs/qemu_arm64_lwip_defconfig
 create mode 100644 include/net-lwip.h
 create mode 100644 lib/lwip/Makefile
 create mode 100644 lib/lwip/u-boot/arch/cc.h
 create mode 100644 lib/lwip/u-boot/arch/sys_arch.h
 create mode 100644 lib/lwip/u-boot/limits.h
 create mode 100644 lib/lwip/u-boot/lwipopts.h
 create mode 100644 net-lwip/Kconfig
 create mode 100644 net-lwip/Makefile
 create mode 100644 net-lwip/dhcp.c
 create mode 100644 net-lwip/dns.c
 create mode 100644 net-lwip/eth_internal.h
 create mode 100644 net-lwip/net-lwip.c
 create mode 100644 net-lwip/ping.c
 create mode 100644 net-lwip/tftp.c
 create mode 100644 net-lwip/wget.c
Signature · 1 line
2.40.1
#1 lore raw

PATCH v3 1/12 net: introduce alternative implementation as net-lwip/

Prepare the introduction of the lwIP (lightweight IP) TCP/IP stack by adding a new net-lwip/ directory and the NET_LWIP symbol. Network support is either NO_NET, NET (legacy stack) or NET_LWIP. Subsequent commits will introduce the lwIP code, re-work the NETDEVICE integration and port some of the NET commands and features to lwIP.

SPL_NET cannot be enabled when NET_LWIP=y. SPL_NET pulls some symbols that are part of NET (such as arp_init(), arp_timeout_check(), arp_receive(), net_arp_wait_packet_ip()). lwIP support in SPL may be added later.

Similarly, DFU_TFTP is not compatible with NET_LWIP because it depends on net_loop(), tftp_timeout_ms, tftp_timeout_count_max. Let's add a dependency of DFU_OVER_TFTP on !NET_LWIP for now.

---
 Kconfig                    | 40 ++++++++++++++++++++++++++++++++++++++
 Makefile                   |  2 +-
 common/Kconfig             |  2 +-
 common/spl/Kconfig         |  1 +
 drivers/dfu/Kconfig        |  2 +-
 drivers/fastboot/Kconfig   |  4 ++--
 drivers/net/phy/Kconfig    |  2 +-
 drivers/usb/gadget/Kconfig |  2 +-
 net-lwip/Kconfig           | 37 +++++++++++++++++++++++++++++++++++
 net/Kconfig                | 14 -------------
 10 files changed, 85 insertions(+), 21 deletions(-)
 create mode 100644 net-lwip/Kconfig
Kconfig +40 -0
index 82df59f176e..b7304bd37c5 100644
@@ -745,7 +745,47 @@ source "dts/Kconfig"
 
 source "env/Kconfig"
 
+choice
+	prompt "Networking stack"
+	default NET
+
+config NO_NET
+	bool "No networking support"
+
+config NET
+	bool "Legacy U-Boot networking stack"
+	imply NETDEVICES
+
+config NET_LWIP
+	bool "Use lwIP for networking stack"
+	imply NETDEVICES
+	help
+	  Include networking support based on the lwIP (lightweight IP)
+	  TCP/IP stack (https://nongnu.org/lwip). This is a replacement for
+	  the default U-Boot network stack and applications located in net/
+	  and enabled via CONFIG_NET as well as other pieces of code that
+	  depend on CONFIG_NET (such as cmd/net.c enabled via CONFIG_CMD_NET).
+	  Therefore the two symbols CONFIG_NET and CONFIG_NET_LWIP are mutually
+	  exclusive.
+
+endchoice
+
+if NET
 source "net/Kconfig"
+endif
+
+if NET_LWIP
+source "net-lwip/Kconfig"
+endif
+
+config SYS_RX_ETH_BUFFER
+	int "Number of receive packet buffers"
+	default 4
+	help
+	  Defines the number of Ethernet receive buffers. On some Ethernet
+	  controllers it is recommended to set this value to 8 or even higher,
+	  since all buffers can be full shortly after enabling the interface on
+	  high Ethernet traffic.
 
 source "drivers/Kconfig"
 
Makefile +1 -1
index f8206b2e30a..ceb99a2698e 100644
@@ -859,7 +859,7 @@ libs-$(CONFIG_OF_EMBED) += dts/
 libs-y += env/
 libs-y += lib/
 libs-y += fs/
-libs-y += net/
+libs-$(CONFIG_NET) += net/
 libs-y += disk/
 libs-y += drivers/
 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
common/Kconfig +1 -1
index 5e3070e9253..807b726384d 100644
@@ -424,7 +424,7 @@ config LOGF_FUNC_PAD
 
 config LOG_SYSLOG
 	bool "Log output to syslog server"
-	depends on NET
+	depends on NET || NET_LWIP
 	help
 	  Enables a log driver which broadcasts log records via UDP port 514
 	  to syslog servers.
common/spl/Kconfig +1 -0
index 6405374bcc1..f67f0a859db 100644
@@ -1055,6 +1055,7 @@ config SPL_DM_SPI_FLASH
 
 config SPL_NET
 	bool "Support networking"
+	depends on !NET_LWIP
 	help
 	  Enable support for network devices (such as Ethernet) in SPL.
 	  This permits SPL to load U-Boot over a network link rather than
drivers/dfu/Kconfig +1 -1
index 0360d9da142..c6bce82eb10 100644
@@ -11,7 +11,7 @@ config DFU_OVER_USB
 
 config DFU_OVER_TFTP
 	bool
-	depends on NET
+	depends on NET && !NET_LWIP
 
 if DFU
 config DFU_WRITE_ALT
drivers/fastboot/Kconfig +2 -2
index 70207573de2..05e988166fb 100644
@@ -27,7 +27,7 @@ config USB_FUNCTION_FASTBOOT
 	  This enables the USB part of the fastboot gadget.
 
 config UDP_FUNCTION_FASTBOOT
-	depends on NET
+	depends on NET || NET_LWIP
 	select FASTBOOT
 	bool "Enable fastboot protocol over UDP"
 	help
@@ -41,7 +41,7 @@ config UDP_FUNCTION_FASTBOOT_PORT
 	  The fastboot protocol requires a UDP port number.
 
 config TCP_FUNCTION_FASTBOOT
-	depends on NET
+	depends on NET || NET_LWIP
 	select FASTBOOT
 	bool "Enable fastboot protocol over TCP"
 	help
drivers/net/phy/Kconfig +1 -1
index 3d96938eaba..738752d29c2 100644
@@ -11,7 +11,7 @@ config MV88E6352_SWITCH
 
 menuconfig PHYLIB
 	bool "Ethernet PHY (physical media interface) support"
-	depends on NET
+	depends on NET || NET_LWIP
 	help
 	  Enable Ethernet PHY (physical media interface) support.
 
drivers/usb/gadget/Kconfig +1 -1
index 4621a6fd5e6..03fe3bca197 100644
@@ -224,7 +224,7 @@ endif # USB_GADGET_DOWNLOAD
 
 config USB_ETHER
 	bool "USB Ethernet Gadget"
-	depends on NET
+	depends on NET || NET_LWIP
 	default y if ARCH_SUNXI && USB_MUSB_GADGET
 	help
 	  Creates an Ethernet network device through a USB peripheral
net-lwip/Kconfig new file +37 -0
new file mode 100644
index 00000000000..a0938964b51
@@ -0,0 +1,37 @@
+#
+# Network configuration (with lwIP stack)
+#
+
+config LWIP_DEBUG
+	bool "Enable debug traces in the lwIP library"
+
+config LWIP_ASSERT
+	bool "Enable assertions in the lwIP library"
+
+config PROT_DHCP_LWIP
+	bool "DHCP support in lwIP"
+	depends on PROT_UDP_LWIP
+	help
+	  Enable support for the DHCP protocol in lwIP.
+
+config PROT_DNS_LWIP
+	bool
+	depends on PROT_UDP_LWIP
+
+config PROT_RAW_LWIP
+	bool
+
+config PROT_TCP_LWIP
+	bool
+
+config PROT_UDP_LWIP
+	bool
+
+config BOOTDEV_ETH
+        bool "Enable bootdev for ethernet"
+        depends on BOOTSTD
+        default y
+        help
+          Provide a bootdev for ethernet so that is it possible to boot
+          an operating system over the network, using the PXE (Preboot
+          Execution Environment) protocol.
net/Kconfig +0 -14
index 5dff6336293..4929428d2a5 100644
@@ -2,11 +2,6 @@
 # Network configuration
 #
 
-menuconfig NET
-	bool "Networking support"
-	default y
-	imply NETDEVICES
-
 if NET
 
 config ARP_TIMEOUT
@@ -254,12 +249,3 @@ config IPV6
 	  address and find it, it will force using IPv6 in the network stack.
 
 endif   # if NET
-
-config SYS_RX_ETH_BUFFER
-	int "Number of receive packet buffers"
-	default 4
-	help
-	  Defines the number of Ethernet receive buffers. On some Ethernet
-	  controllers it is recommended to set this value to 8 or even higher,
-	  since all buffers can be full shortly after enabling the interface on
-	  high Ethernet traffic.
Signature · 1 line
2.40.1
#2 lore raw

PATCH v3 2/12 net-lwip: build lwIP

In reply to Jerome Forissier

Build the lwIP library when NET_LWIP is enabled. The following files are adaptation layers written specially for U-Boot:

lib/lwip/u-boot/arch/cc.h
lib/lwip/u-boot/arch/sys_arch.h (empty)
lib/lwip/u-boot/limits.h (empty)
lib/lwip/u-boot/lwipopts.h

They were initially contributed by Maxim in a previous RFC patch series.

---
 lib/Makefile                    |   2 +
 lib/lwip/Makefile               |  57 +++++++++
 lib/lwip/u-boot/arch/cc.h       |  43 +++++++
 lib/lwip/u-boot/arch/sys_arch.h |   0
 lib/lwip/u-boot/limits.h        |   0
 lib/lwip/u-boot/lwipopts.h      | 197 ++++++++++++++++++++++++++++++++
 6 files changed, 299 insertions(+)
 create mode 100644 lib/lwip/Makefile
 create mode 100644 lib/lwip/u-boot/arch/cc.h
 create mode 100644 lib/lwip/u-boot/arch/sys_arch.h
 create mode 100644 lib/lwip/u-boot/limits.h
 create mode 100644 lib/lwip/u-boot/lwipopts.h
lib/Makefile +2 -0
index 2a76acf100d..c35786a0576 100644
@@ -94,6 +94,8 @@ obj-$(CONFIG_LIBAVB) += libavb/
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
 obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o
 
+obj-$(CONFIG_NET_LWIP) += lwip/
+
 ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o
 obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o
lib/lwip/Makefile new file +57 -0

57 lines not on this page · raw message

lib/lwip/u-boot/arch/cc.h new file +43 -0

43 lines not on this page · raw message

lib/lwip/u-boot/arch/sys_arch.h new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
lib/lwip/u-boot/limits.h new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
lib/lwip/u-boot/lwipopts.h new file +197 -0

197 lines not on this page · raw message

Signature · 1 line
2.40.1
Acked-by on v3 2/12
#3 lore raw

Re: [PATCH v3 02/12] net-lwip: build lwIP

Quoted 363 lines · Jerome Forissier

Build the lwIP library when NET_LWIP is enabled. The following files are adaptation layers written specially for U-Boot:

lib/lwip/u-boot/arch/cc.h
lib/lwip/u-boot/arch/sys_arch.h (empty)
lib/lwip/u-boot/limits.h (empty)
lib/lwip/u-boot/lwipopts.h

They were initially contributed by Maxim in a previous RFC patch series.

---
 lib/Makefile                    |   2 +
 lib/lwip/Makefile               |  57 +++++++++
 lib/lwip/u-boot/arch/cc.h       |  43 +++++++
 lib/lwip/u-boot/arch/sys_arch.h |   0
 lib/lwip/u-boot/limits.h        |   0
 lib/lwip/u-boot/lwipopts.h      | 197 ++++++++++++++++++++++++++++++++
 6 files changed, 299 insertions(+)
 create mode 100644 lib/lwip/Makefile
 create mode 100644 lib/lwip/u-boot/arch/cc.h
 create mode 100644 lib/lwip/u-boot/arch/sys_arch.h
 create mode 100644 lib/lwip/u-boot/limits.h
 create mode 100644 lib/lwip/u-boot/lwipopts.h
lib/Makefile +2 -0
index 2a76acf100d..c35786a0576 100644
@@ -94,6 +94,8 @@ obj-$(CONFIG_LIBAVB) += libavb/
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
 obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o
 
+obj-$(CONFIG_NET_LWIP) += lwip/
+
 ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o
 obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o
lib/lwip/Makefile new file +57 -0
new file mode 100644
index 00000000000..158e59b91fc
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2024 Linaro Ltd.
+
+ccflags-y += -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+
+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
lib/lwip/u-boot/arch/cc.h new file +43 -0
new file mode 100644
index 00000000000..31c036dc0c5
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2023 Linaro Ltd. <[email protected]> */
+
+#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())
+#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)  strnstr(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 */
lib/lwip/u-boot/arch/sys_arch.h new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
lib/lwip/u-boot/limits.h new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
lib/lwip/u-boot/lwipopts.h new file +197 -1
new file mode 100644
index 00000000000..aac0a6259fd
@@ -0,0 +1,197 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+/* Copyright (C) 2023 Linaro Ltd. <[email protected]> */
+
+#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
+#else
+#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
+#define LWIP_DBG_TYPES_ON               LWIP_DBG_OFF
+#define ETHARP_DEBUG                    LWIP_DBG_OFF
+#define NETIF_DEBUG                     LWIP_DBG_OFF
+#define PBUF_DEBUG                      LWIP_DBG_OFF
+#define API_LIB_DEBUG                   LWIP_DBG_OFF
+#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_OFF
+#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_OFF
+#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_OFF
+#define AUTOIP_DEBUG                    LWIP_DBG_OFF
+#define DNS_DEBUG                       LWIP_DBG_OFF
+#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                   1
+#define MEM_SIZE                        1600
+
+#define MEMP_NUM_PBUF                   4
+#define MEMP_NUM_RAW_PCB                2
+#define MEMP_NUM_UDP_PCB                4
+#define MEMP_NUM_TCP_PCB                2
+#define MEMP_NUM_TCP_PCB_LISTEN         2
+#define MEMP_NUM_TCP_SEG                16
+#define MEMP_NUM_REASSDATA              1
+#define MEMP_NUM_ARP_QUEUE              2
+#define MEMP_NUM_SYS_TIMEOUT            4
+#define MEMP_NUM_NETBUF                 2
+#define MEMP_NUM_NETCONN               32
+#define MEMP_NUM_TCPIP_MSG_API          8
+#define MEMP_NUM_TCPIP_MSG_INPKT        8
+#define PBUF_POOL_SIZE                  8
+
+#define LWIP_ARP                        1
+#define ARP_TABLE_SIZE                  1
+#define ARP_QUEUEING                    0
+
+#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
+#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 */
--
Quoted 2 lines

2.40.1

#4 lore raw

PATCH v3 3/12 net-lwip: add DHCP support and dhcp commmand

In reply to Jerome Forissier

Add what it takes to enable NETDEVICES with NET_LWIP and enable DHCP as well as the dhcp command.
- net-lwip/net-lwip.c is mostly empty for now. It will provide functions similar to net/net.c except based on the lwIP stack
- include/net-lwip.h is a replacement for include/net.h which is unused when NET_LWIP is enabled. Declarations from the latter will be transferred to the former as needed when new network commands are ported on top of lwIP.
- CMD_TFTPBOOT is selected by BOOTMETH_EFI due to this code having an implicit dependency on do_tftpb().

---
 Makefile                |   1 +
 boot/Kconfig            |   3 +-
 cmd/Kconfig             |  26 +++++
 cmd/Makefile            |   4 +
 cmd/net-lwip.c          |  13 +++
 common/board_r.c        |   4 +-
 drivers/net/Kconfig     |   2 +-
 include/net-lwip.h      |  85 +++++++++++++++
 include/net.h           |   2 +-
 net-lwip/Makefile       |  15 +++
 net-lwip/dhcp.c         | 105 +++++++++++++++++++
 net-lwip/eth_internal.h |  35 +++++++
 net-lwip/net-lwip.c     | 224 ++++++++++++++++++++++++++++++++++++++++
 net-lwip/tftp.c         |  11 ++
 14 files changed, 525 insertions(+), 5 deletions(-)
 create mode 100644 cmd/net-lwip.c
 create mode 100644 include/net-lwip.h
 create mode 100644 net-lwip/Makefile
 create mode 100644 net-lwip/dhcp.c
 create mode 100644 net-lwip/eth_internal.h
 create mode 100644 net-lwip/net-lwip.c
 create mode 100644 net-lwip/tftp.c
Makefile +1 -0
index ceb99a2698e..d3c9e6775dc 100644
@@ -860,6 +860,7 @@ libs-y += env/
 libs-y += lib/
 libs-y += fs/
 libs-$(CONFIG_NET) += net/
+libs-$(CONFIG_NET_LWIP) += net-lwip/
 libs-y += disk/
 libs-y += drivers/
 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
boot/Kconfig +2 -1
index 6f3096c15a6..004e69dd92a 100644
@@ -378,7 +378,7 @@ config BOOT_DEFAULTS_CMDS
 	select CMD_FAT
 	select CMD_FS_GENERIC
 	select CMD_PART if PARTITIONS
-	select CMD_DHCP if CMD_NET
+	select CMD_DHCP if CMD_NET || CMD_NET_LWIP
 	select CMD_PING if CMD_NET
 	select CMD_PXE if CMD_NET
 	select CMD_BOOTI if ARM64
@@ -540,6 +540,7 @@ config BOOTMETH_EXTLINUX_PXE
 config BOOTMETH_EFILOADER
 	bool "Bootdev support for EFI boot"
 	depends on EFI_BINARY_EXEC
+	select CMD_TFTPBOOT if CMD_NET_LWIP
 	default y
 	help
 	  Enables support for EFI boot using bootdevs. This makes the
cmd/Kconfig +26 -0
index b026439c773..1bfa528e945 100644
@@ -2084,6 +2084,32 @@ config CMD_WOL
 
 endif
 
+if NET_LWIP
+
+menuconfig CMD_NET_LWIP
+	bool "Network commands (lwIP)"
+	default y
+
+if CMD_NET_LWIP
+
+config CMD_DHCP
+	bool "dhcp"
+	select PROT_DHCP_LWIP
+	help
+	  Boot image via network using DHCP/TFTP protocol
+
+config CMD_TFTPBOOT
+	bool "tftp"
+	select PROT_UDP_LWIP
+	default n
+	help
+	  tftpboot - load file via network using TFTP protocol
+	  Currently a placeholder (not implemented)
+
+endif
+
+endif
+
 menu "Misc commands"
 
 config CMD_2048
cmd/Makefile +4 -0
index 87133cc27a8..535b6838ca5 100644
@@ -128,6 +128,10 @@ endif
 obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
+obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o
+ifdef CONFIG_CMD_NET_LWIP
+CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+endif
 obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
 obj-$(CONFIG_CMD_ONENAND) += onenand.o
cmd/net-lwip.c new file +13 -0
new file mode 100644
index 00000000000..966d7226eda
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <net-lwip.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
common/board_r.c +2 -2
index da0b80f24ff..6548eb8fdd5 100644
@@ -472,7 +472,7 @@ static int initr_status_led(void)
 }
 #endif
 
-#ifdef CONFIG_CMD_NET
+#if defined(CONFIG_CMD_NET) || defined(CONFIG_CMD_NET_LWIP)
 static int initr_net(void)
 {
 	puts("Net:   ");
@@ -727,7 +727,7 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_PCI_ENDPOINT
 	pci_ep_init,
 #endif
-#ifdef CONFIG_CMD_NET
+#if defined(CONFIG_CMD_NET) || defined(CONFIG_CMD_NET_LWIP)
 	INIT_FUNC_WATCHDOG_RESET
 	initr_net,
 #endif
drivers/net/Kconfig +1 -1
index b2d7b499766..4ba09c9d6f8 100644
@@ -96,7 +96,7 @@ config DSA_SANDBOX
 
 menuconfig NETDEVICES
 	bool "Network device support"
-	depends on NET
+	depends on NET || NET_LWIP
 	select DM_ETH
 	help
 	  You must select Y to enable any network device support
include/net-lwip.h new file +85 -0

85 lines not on this page · raw message

include/net.h +1 -1
index ac511eab103..330bc6bf66c 100644
@@ -914,7 +914,7 @@ static inline struct in_addr env_get_ip(char *var)
  */
 void reset_phy(void);
 
-#if CONFIG_IS_ENABLED(NET)
+#if CONFIG_IS_ENABLED(NET) || CONFIG_IS_ENABLED(NET_LWIP)
 /**
  * eth_set_enable_bootdevs() - Enable or disable binding of Ethernet bootdevs
  *
net-lwip/Makefile new file +15 -0
new file mode 100644
index 00000000000..a56c32bfa74
@@ -0,0 +1,15 @@
+ccflags-y += -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTDEV_ETH) += ../net/eth_bootdev.o
+obj-$(CONFIG_DM_MDIO)  += ../net/mdio-uclass.o
+obj-$(CONFIG_DM_MDIO_MUX) += ../net/mdio-mux-uclass.o
+obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
+obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
+obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o
+obj-$(CONFIG_CMD_DHCP) += dhcp.o
+obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
+
+# Disable this warning as it is triggered by:
+# sprintf(buf, index ? "foo%d" : "foo", index)
+# and this is intentional usage.
+CFLAGS_eth_common.o += -Wno-format-extra-args
net-lwip/dhcp.c new file +105 -0

105 lines not on this page · raw message

net-lwip/eth_internal.h new file +35 -0
new file mode 100644
index 00000000000..0b829a8d388
@@ -0,0 +1,35 @@
+/* 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
net-lwip/net-lwip.c new file +224 -0

224 lines not on this page · raw message

net-lwip/tftp.c new file +11 -0
new file mode 100644
index 00000000000..1fa246f55d9
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <net-lwip.h>
+
+int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	/* Not implemented */
+	return CMD_RET_FAILURE;
+}
Signature · 1 line
2.40.1
#5 lore raw

PATCH v3 4/12 net-lwip: add TFTP support and tftpboot command

In reply to Jerome Forissier

Implement do_tftpb().

---
 cmd/Kconfig     |   3 +-
 cmd/net-lwip.c  |   8 ++
 net-lwip/dhcp.c |  11 ++-
 net-lwip/tftp.c | 202 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 219 insertions(+), 5 deletions(-)
cmd/Kconfig +1 -2
index 1bfa528e945..94a8de266f6 100644
@@ -2101,10 +2101,9 @@ config CMD_DHCP
 config CMD_TFTPBOOT
 	bool "tftp"
 	select PROT_UDP_LWIP
-	default n
+	default y
 	help
 	  tftpboot - load file via network using TFTP protocol
-	  Currently a placeholder (not implemented)
 
 endif
 
cmd/net-lwip.c +8 -0
index 966d7226eda..490a2e4ac5c 100644
@@ -11,3 +11,11 @@ U_BOOT_CMD(
         "[loadAddress] [[hostIPaddr:]bootfilename]"
 );
 #endif
+
+#if defined(CONFIG_CMD_TFTPBOOT)
+U_BOOT_CMD(
+	tftpboot,	3,	0,	do_tftpb,
+	"boot image via network using TFTP protocol\n",
+	"[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
net-lwip/dhcp.c +10 -1
index d1d35999b04..7bacc234f1e 100644
@@ -94,11 +94,20 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 int dhcp_run(ulong addr, const char *fname, bool autoload)
 {
 	char *dhcp_argv[] = {"dhcp", NULL, };
+#ifdef CONFIG_CMD_TFTPBOOT
+	char *tftp_argv[] = {"tftpboot", boot_file_name, NULL, };
+#endif
 	struct cmd_tbl cmdtp = {};	/* dummy */
 
 	if (autoload) {
-		/* Will be supported when TFTP is added */
+#ifdef CONFIG_CMD_TFTPBOOT
+		/* Assume DHCP was already performed */
+		if (boot_file_name[0])
+			return do_tftpb(&cmdtp, 0, 2, tftp_argv);
+		return 0;
+#else
 		return -EOPNOTSUPP;
+#endif
 	}
 
 	return do_dhcp(&cmdtp, 0, 1, dhcp_argv);
net-lwip/tftp.c +200 -2

210 lines not on this page · raw message

Signature · 1 line
2.40.1
#6 lore raw

PATCH v3 5/12 net-lwip: add ping command

In reply to Jerome Forissier

Add support for the the ping command with NET_LWIP. The implementation is derived from lwIP's contrib/apps/ping/ping.c.

---
 boot/Kconfig       |   2 +-
 cmd/Kconfig        |   6 ++
 cmd/net-lwip.c     |   8 +++
 include/net-lwip.h |   3 +
 net-lwip/Makefile  |   1 +
 net-lwip/ping.c    | 163 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 182 insertions(+), 1 deletion(-)
 create mode 100644 net-lwip/ping.c
boot/Kconfig +1 -1
index 004e69dd92a..983a284ec52 100644
@@ -379,7 +379,7 @@ config BOOT_DEFAULTS_CMDS
 	select CMD_FS_GENERIC
 	select CMD_PART if PARTITIONS
 	select CMD_DHCP if CMD_NET || CMD_NET_LWIP
-	select CMD_PING if CMD_NET
+	select CMD_PING if CMD_NET || CMD_NET_LWIP
 	select CMD_PXE if CMD_NET
 	select CMD_BOOTI if ARM64
 	select CMD_BOOTZ if ARM && !ARM64
cmd/Kconfig +6 -0
index 94a8de266f6..07cfe824e3f 100644
@@ -2098,6 +2098,12 @@ config CMD_DHCP
 	help
 	  Boot image via network using DHCP/TFTP protocol
 
+config CMD_PING
+	bool "ping"
+	select PROT_RAW_LWIP
+	help
+	  Send ICMP ECHO_REQUEST to network host
+
 config CMD_TFTPBOOT
 	bool "tftp"
 	select PROT_UDP_LWIP
cmd/net-lwip.c +8 -0
index 490a2e4ac5c..13856703fcf 100644
@@ -12,6 +12,14 @@ U_BOOT_CMD(
 );
 #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,
include/net-lwip.h +3 -0
index 2308703e46b..2abaaa3b4e3 100644
@@ -5,6 +5,7 @@
 
 #include <asm/cache.h>
 #include <linux/types.h>
+#include <lwip/ip_addr.h>
 #include <lwip/netif.h>
 #include <time.h>
 
@@ -50,6 +51,7 @@ int eth_env_get_enetaddr_by_index(const char *base_name, int index,
 int eth_init(void);			/* Initialize the device */
 int eth_send(void *packet, int length);	   /* Send a packet */
 int eth_rx(void);
+const char *eth_get_name(void);
 int eth_get_dev_index(void);
 int eth_init_state_only(void); /* Set active state */
 void eth_set_current(void);		/* set nterface to ethcur var */
@@ -80,6 +82,7 @@ int net_lwip_init(void);
 struct netif *net_lwip_get_netif(void);
 
 int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
 #endif /* __NET_LWIP_H__ */
net-lwip/Makefile +1 -0
index a56c32bfa74..e68d4e24197 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
 obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
 obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o
 obj-$(CONFIG_CMD_DHCP) += dhcp.o
+obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
 
 # Disable this warning as it is triggered by:
net-lwip/ping.c new file +163 -0

163 lines not on this page · raw message

Signature · 1 line
2.40.1
#7 lore raw

Re: [PATCH v3 05/12] net-lwip: add ping command

[...]

Quoted 5 lines
net-lwip/ping.c new file +5 -0
+static int ping_raw_init(void *recv_arg)
+{
+       ping_pcb = raw_new(IP_PROTO_ICMP);
+       if (!ping_pcb)
+               return -ENOMEM;

net-lwip/ping.c line 65

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+
+       raw_recv(ping_pcb, ping_recv, recv_arg);
+       raw_bind(ping_pcb, IP_ADDR_ANY);
+
+       return 0;
+}
+
+static void ping_raw_stop(void)
+{
+       if (ping_pcb != NULL) {

nits, but we usually do if (!ping_pcb) for NULL pointers and variables that have a value of 0.
Please change it in other files as well

Quoted 17 lines
net-lwip/ping.c new file +17 -0
+               raw_remove(ping_pcb);
+               ping_pcb = NULL;
+       }
+}
+
+static void ping_prepare_echo(struct icmp_echo_hdr *iecho)
+{
+       ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+       ICMPH_CODE_SET(iecho, 0);
+       iecho->chksum = 0;
+       iecho->id = PING_ID;
+       iecho->seqno = lwip_htons(++ping_seq_num);
+
+       iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
+}
+
+static void ping_send_icmp(struct raw_pcb *raw, const ip_addr_t *addr)

net-lwip/ping.c line 92

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+{
+       struct pbuf *p;
+       struct icmp_echo_hdr *iecho;
+       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 == NULL)) {

&& !p->next

Quoted 33 lines
net-lwip/ping.c new file +33 -0
+               iecho = (struct icmp_echo_hdr *)p->payload;
+               ping_prepare_echo(iecho);
+               raw_sendto(raw, p, addr);
+       }
+
+       pbuf_free(p);
+}
+
+static void ping_send(void *arg)
+{
+       struct raw_pcb *pcb = (struct raw_pcb *)arg;
+
+       ping_send_icmp(pcb, ping_target);
+       sys_timeout(PING_DELAY_MS, ping_send, ping_pcb);
+}
+
+static int ping_loop(const ip_addr_t* addr)
+{
+       bool alive;
+       ulong start;
+       int ret;
+
+       printf("Using %s device\n", eth_get_name());
+
+       ret = ping_raw_init(&alive);
+       if (ret < 0)
+               return ret;
+       ping_target = addr;
+       ping_seq_num = 0;
+
+       start = get_timer(0);
+       ping_send(ping_pcb);
+

net-lwip/ping.c line 135

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+       do {
+               eth_rx();
+               if (alive)
+                       break;
+               sys_check_timeouts();
+               if (ctrlc()) {
+                       printf("\nAbort\n");
+                       break;
+               }
+       } while (get_timer(start) < PING_TIMEOUT_MS);

I am a bit confused about what happens here.
ping_send() will send the packet, but it will also schedule itself to rerun after 1 ms and send another ping?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       sys_untimeout(ping_send, ping_pcb);

So we need the sys_untimeout() because we queued 2 pings? Because sys_timeout() is supposed to be an one shot.

Thanks
/Ilias

Quoted 29 lines
net-lwip/ping.c new file +26 -1
+       ping_raw_stop();
+       ping_target = NULL;
+
+       if (alive) {
+               alive = false;
+               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;
+
+       if (ping_loop(&addr) < 0)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
--

2.40.1

#8 lore raw

Re: [PATCH v3 05/12] net-lwip: add ping command

Quoted 102 lines · Ilias Apalodimas

[...]

Quoted 5 lines
net-lwip/ping.c new file +5 -0
+static int ping_raw_init(void *recv_arg)
+{
+       ping_pcb = raw_new(IP_PROTO_ICMP);
+       if (!ping_pcb)
+               return -ENOMEM;

net-lwip/ping.c line 65

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+
+       raw_recv(ping_pcb, ping_recv, recv_arg);
+       raw_bind(ping_pcb, IP_ADDR_ANY);
+
+       return 0;
+}
+
+static void ping_raw_stop(void)
+{
+       if (ping_pcb != NULL) {

nits, but we usually do if (!ping_pcb) for NULL pointers and variables that have a value of 0.
Please change it in other files as well

Quoted 17 lines
net-lwip/ping.c new file +17 -0
+               raw_remove(ping_pcb);
+               ping_pcb = NULL;
+       }
+}
+
+static void ping_prepare_echo(struct icmp_echo_hdr *iecho)
+{
+       ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+       ICMPH_CODE_SET(iecho, 0);
+       iecho->chksum = 0;
+       iecho->id = PING_ID;
+       iecho->seqno = lwip_htons(++ping_seq_num);
+
+       iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
+}
+
+static void ping_send_icmp(struct raw_pcb *raw, const ip_addr_t *addr)

net-lwip/ping.c line 92

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+{
+       struct pbuf *p;
+       struct icmp_echo_hdr *iecho;
+       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 == NULL)) {

&& !p->next

Quoted 33 lines
net-lwip/ping.c new file +33 -0
+               iecho = (struct icmp_echo_hdr *)p->payload;
+               ping_prepare_echo(iecho);
+               raw_sendto(raw, p, addr);
+       }
+
+       pbuf_free(p);
+}
+
+static void ping_send(void *arg)
+{
+       struct raw_pcb *pcb = (struct raw_pcb *)arg;
+
+       ping_send_icmp(pcb, ping_target);
+       sys_timeout(PING_DELAY_MS, ping_send, ping_pcb);
+}
+
+static int ping_loop(const ip_addr_t* addr)
+{
+       bool alive;
+       ulong start;
+       int ret;
+
+       printf("Using %s device\n", eth_get_name());
+
+       ret = ping_raw_init(&alive);
+       if (ret < 0)
+               return ret;
+       ping_target = addr;
+       ping_seq_num = 0;
+
+       start = get_timer(0);
+       ping_send(ping_pcb);
+

net-lwip/ping.c line 135

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+       do {
+               eth_rx();
+               if (alive)
+                       break;
+               sys_check_timeouts();
+               if (ctrlc()) {
+                       printf("\nAbort\n");
+                       break;
+               }
+       } while (get_timer(start) < PING_TIMEOUT_MS);

I am a bit confused about what happens here.
ping_send() will send the packet, but it will also schedule itself to rerun after 1 ms and send another ping?

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       sys_untimeout(ping_send, ping_pcb);

So we need the sys_untimeout() because we queued 2 pings? Because sys_timeout() is supposed to be an one shot.

Ah nvm, I misread that. We always reschedule ping_send_icmp(), that's why we have to delete it here

Quoted 32 lines

Thanks
/Ilias

Quoted 29 lines
net-lwip/ping.c new file +26 -1
+       ping_raw_stop();
+       ping_target = NULL;
+
+       if (alive) {
+               alive = false;
+               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;
+
+       if (ping_loop(&addr) < 0)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
--

2.40.1

#9 lore raw

Re: [PATCH v3 05/12] net-lwip: add ping command

Quoted 105 lines · Ilias Apalodimas
Quoted 102 lines · Ilias Apalodimas

[...]

Quoted 5 lines
net-lwip/ping.c new file +5 -0
+static int ping_raw_init(void *recv_arg)
+{
+       ping_pcb = raw_new(IP_PROTO_ICMP);
+       if (!ping_pcb)
+               return -ENOMEM;

net-lwip/ping.c line 65

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+
+       raw_recv(ping_pcb, ping_recv, recv_arg);
+       raw_bind(ping_pcb, IP_ADDR_ANY);
+
+       return 0;
+}
+
+static void ping_raw_stop(void)
+{
+       if (ping_pcb != NULL) {

nits, but we usually do if (!ping_pcb) for NULL pointers and variables that have a value of 0.
Please change it in other files as well

Quoted 17 lines
net-lwip/ping.c new file +17 -0
+               raw_remove(ping_pcb);
+               ping_pcb = NULL;
+       }
+}
+
+static void ping_prepare_echo(struct icmp_echo_hdr *iecho)
+{
+       ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+       ICMPH_CODE_SET(iecho, 0);
+       iecho->chksum = 0;
+       iecho->id = PING_ID;
+       iecho->seqno = lwip_htons(++ping_seq_num);
+
+       iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
+}
+
+static void ping_send_icmp(struct raw_pcb *raw, const ip_addr_t *addr)

net-lwip/ping.c line 92

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+{
+       struct pbuf *p;
+       struct icmp_echo_hdr *iecho;
+       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 == NULL)) {

&& !p->next

Quoted 33 lines
net-lwip/ping.c new file +33 -0
+               iecho = (struct icmp_echo_hdr *)p->payload;
+               ping_prepare_echo(iecho);
+               raw_sendto(raw, p, addr);
+       }
+
+       pbuf_free(p);
+}
+
+static void ping_send(void *arg)
+{
+       struct raw_pcb *pcb = (struct raw_pcb *)arg;
+
+       ping_send_icmp(pcb, ping_target);
+       sys_timeout(PING_DELAY_MS, ping_send, ping_pcb);
+}
+
+static int ping_loop(const ip_addr_t* addr)
+{
+       bool alive;
+       ulong start;
+       int ret;
+
+       printf("Using %s device\n", eth_get_name());
+
+       ret = ping_raw_init(&alive);
+       if (ret < 0)
+               return ret;
+       ping_target = addr;
+       ping_seq_num = 0;
+
+       start = get_timer(0);
+       ping_send(ping_pcb);
+

net-lwip/ping.c line 135

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+       do {
+               eth_rx();
+               if (alive)
+                       break;
+               sys_check_timeouts();
+               if (ctrlc()) {
+                       printf("\nAbort\n");
+                       break;
+               }
+       } while (get_timer(start) < PING_TIMEOUT_MS);

I am a bit confused about what happens here.
ping_send() will send the packet, but it will also schedule itself to rerun after 1 ms and send another ping?

Quoted 8 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       sys_untimeout(ping_send, ping_pcb);

So we need the sys_untimeout() because we queued 2 pings? Because sys_timeout() is supposed to be an one shot.

Ah nvm, I misread that. We always reschedule ping_send_icmp(), that's why we have to delete it here

Ok so looking at it a bit more. Why do we have to schedule contunuous pings? We just have to send one packet and wait for the response no?

Thanks
/Ilias

Quoted 34 lines
Quoted 34 lines

Thanks
/Ilias

Quoted 29 lines
net-lwip/ping.c new file +26 -1
+       ping_raw_stop();
+       ping_target = NULL;
+
+       if (alive) {
+               alive = false;
+               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;
+
+       if (ping_loop(&addr) < 0)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
--

2.40.1

#10 lore raw

Re: [PATCH v3 05/12] net-lwip: add ping command

Quoted 110 lines · Ilias Apalodimas
Quoted 108 lines · Ilias Apalodimas
Quoted 105 lines · Ilias Apalodimas

[...]

Quoted 5 lines
net-lwip/ping.c new file +5 -0
+static int ping_raw_init(void *recv_arg)
+{
+       ping_pcb = raw_new(IP_PROTO_ICMP);
+       if (!ping_pcb)
+               return -ENOMEM;

net-lwip/ping.c line 65

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+
+       raw_recv(ping_pcb, ping_recv, recv_arg);
+       raw_bind(ping_pcb, IP_ADDR_ANY);
+
+       return 0;
+}
+
+static void ping_raw_stop(void)
+{
+       if (ping_pcb != NULL) {

nits, but we usually do if (!ping_pcb) for NULL pointers and variables that have a value of 0.
Please change it in other files as well

Quoted 17 lines
net-lwip/ping.c new file +17 -0
+               raw_remove(ping_pcb);
+               ping_pcb = NULL;
+       }
+}
+
+static void ping_prepare_echo(struct icmp_echo_hdr *iecho)
+{
+       ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+       ICMPH_CODE_SET(iecho, 0);
+       iecho->chksum = 0;
+       iecho->id = PING_ID;
+       iecho->seqno = lwip_htons(++ping_seq_num);
+
+       iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
+}
+
+static void ping_send_icmp(struct raw_pcb *raw, const ip_addr_t *addr)

net-lwip/ping.c line 92

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+{
+       struct pbuf *p;
+       struct icmp_echo_hdr *iecho;
+       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 == NULL)) {

&& !p->next

Quoted 33 lines
net-lwip/ping.c new file +33 -0
+               iecho = (struct icmp_echo_hdr *)p->payload;
+               ping_prepare_echo(iecho);
+               raw_sendto(raw, p, addr);
+       }
+
+       pbuf_free(p);
+}
+
+static void ping_send(void *arg)
+{
+       struct raw_pcb *pcb = (struct raw_pcb *)arg;
+
+       ping_send_icmp(pcb, ping_target);
+       sys_timeout(PING_DELAY_MS, ping_send, ping_pcb);
+}
+
+static int ping_loop(const ip_addr_t* addr)
+{
+       bool alive;
+       ulong start;
+       int ret;
+
+       printf("Using %s device\n", eth_get_name());
+
+       ret = ping_raw_init(&alive);
+       if (ret < 0)
+               return ret;
+       ping_target = addr;
+       ping_seq_num = 0;
+
+       start = get_timer(0);
+       ping_send(ping_pcb);
+

net-lwip/ping.c line 135

Quoted 10 lines
net-lwip/ping.c new file +10 -0
+       do {
+               eth_rx();
+               if (alive)
+                       break;
+               sys_check_timeouts();
+               if (ctrlc()) {
+                       printf("\nAbort\n");
+                       break;
+               }
+       } while (get_timer(start) < PING_TIMEOUT_MS);

I am a bit confused about what happens here.
ping_send() will send the packet, but it will also schedule itself to rerun after 1 ms and send another ping?

Quoted 2 lines
(quoted diff) +2 -0
+
+       sys_untimeout(ping_send, ping_pcb);
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

So we need the sys_untimeout() because we queued 2 pings? Because sys_timeout() is supposed to be an one shot.

Ah nvm, I misread that. We always reschedule ping_send_icmp(), that's why we have to delete it here

Ok so looking at it a bit more. Why do we have to schedule contunuous pings? We just have to send one packet and wait for the response no?

We could send just one packet as NET does, but if there's packet loss then the ping command will report the host is unreachable. I think it is safer to allow for a few retries for better reliability. The code for one packet would be marginally simpler anyways. What I can do however is use a send counter rather than a timeout.

Thanks,

Signature · 1 line
Jerome
#11 lore raw

PATCH v3 6/12 net-lwip: add dns command

In reply to Jerome Forissier

Add CMD_DNS when NET_LWIP is enabled to provide the dns command using lwIP.

---
 cmd/Kconfig        |   6 +++
 cmd/net-lwip.c     |   8 ++++
 include/net-lwip.h |   1 +
 net-lwip/Makefile  |   1 +
 net-lwip/dns.c     | 107 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 123 insertions(+)
 create mode 100644 net-lwip/dns.c
cmd/Kconfig +6 -0
index 07cfe824e3f..6ef0b52cd34 100644
@@ -2098,6 +2098,12 @@ config CMD_DHCP
 	help
 	  Boot image via network using DHCP/TFTP protocol
 
+config CMD_DNS
+	bool "dns"
+	select PROT_DNS_LWIP
+	help
+	  Lookup the IP of a hostname
+
 config CMD_PING
 	bool "ping"
 	select PROT_RAW_LWIP
cmd/net-lwip.c +8 -0
index 13856703fcf..3abafdf7969 100644
@@ -27,3 +27,11 @@ U_BOOT_CMD(
 	"[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
include/net-lwip.h +1 -0
index 2abaaa3b4e3..0019d1524e5 100644
@@ -82,6 +82,7 @@ int net_lwip_init(void);
 struct netif *net_lwip_get_netif(void);
 
 int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
net-lwip/Makefile +1 -0
index e68d4e24197..aa247859483 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
 obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
 obj-$(CONFIG_$(SPL_)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
 
net-lwip/dns.c new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.40.1
#12 lore raw

Re: [PATCH v3 06/12] net-lwip: add dns command

Quoted 41 lines
net-lwip/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
 obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
 obj-$(CONFIG_$(SPL_)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
 
net-lwip/dns.c new file +27 -0
new file mode 100644
index 00000000000..24a5149343a
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <console.h>
+#include <lwip/dns.h>
+#include <lwip/timeouts.h>
+#include <net-lwip.h>
+#include <time.h>
+
+#define DNS_RESEND_MS 1000
+#define DNS_TIMEOUT_MS 10000
+
+static ulong start;
+static ip_addr_t host_ipaddr;
+static 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)
+{
+       const char *var = arg;
+       char *ipstr = ip4addr_ntoa(ipaddr);
+

net-lwip/dns.c line 37

Quoted 10 lines
net-lwip/dns.c new file +10 -0
+       done = true;
+
+       if (!ipaddr) {
+               printf("DNS: host not found\n");
+               host_ipaddr.addr = 0;
+               return;
+       }
+
+       if (var)
+               env_set(var, ipstr);

Do we need this? Won't this set <dns_name> == ipaddr?
If we do not need it repurpose the void *arg and get rid of the global 'done'

net-lwip/dns.c line 50

Quoted 13 lines
net-lwip/dns.c new file +13 -0
+
+       printf("%s\n", ipstr);
+}
+
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       bool has_server = false;
+       ip_addr_t ipaddr;
+       ip_addr_t ns;
+       char *nsenv;
+       char *name;
+       char *var;
+       int ret;

[...]

Thanks
/Ilias

#13 lore raw

Re: [PATCH v3 06/12] net-lwip: add dns command

Quoted 45 lines · Ilias Apalodimas
Quoted 45 lines
net-lwip/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
 obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
 obj-$(CONFIG_$(SPL_)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
 
net-lwip/dns.c new file +31 -0
new file mode 100644
index 00000000000..24a5149343a
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <console.h>
+#include <lwip/dns.h>
+#include <lwip/timeouts.h>
+#include <net-lwip.h>
+#include <time.h>
+
+#define DNS_RESEND_MS 1000
+#define DNS_TIMEOUT_MS 10000
+
+static ulong start;
+static ip_addr_t host_ipaddr;
+static 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)
+{
+       const char *var = arg;
+       char *ipstr = ip4addr_ntoa(ipaddr);
+
+       done = true;
+
+       if (!ipaddr) {
+               printf("DNS: host not found\n");
Quoted 8 lines

net-lwip/dns.c line 37

Quoted 6 lines
net-lwip/dns.c new file +6 -0
+               host_ipaddr.addr = 0;
+               return;
+       }
+
+       if (var)
+               env_set(var, ipstr);

Do we need this? Won't this set <dns_name> == ipaddr?

No, the syntax of the dns command is: 'dns hostname [env_var]' so one can pretty much give any variable name to receive the IP address.

Quoted 1 line

If we do not need it repurpose the void *arg and get rid of the global 'done'

I could probably use a struct to get rid of the globals. Let me see what I can do.

Quoted 18 lines

net-lwip/dns.c line 50

Quoted 13 lines
net-lwip/dns.c new file +13 -0
+
+       printf("%s\n", ipstr);
+}
+
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       bool has_server = false;
+       ip_addr_t ipaddr;
+       ip_addr_t ns;
+       char *nsenv;
+       char *name;
+       char *var;
+       int ret;

[...]

Thanks
/Ilias

#14 lore raw

Re: [PATCH v3 06/12] net-lwip: add dns command

[...]

Quoted 12 lines
Quoted 11 lines

net-lwip/dns.c line 37

Quoted 9 lines
net-lwip/dns.c new file +9 -0
+
+       if (!ipaddr) {
+               printf("DNS: host not found\n");
+               host_ipaddr.addr = 0;
+               return;
+       }
+
+       if (var)
+               env_set(var, ipstr);

Do we need this? Won't this set <dns_name> == ipaddr?

Quoted 6 lines

No, the syntax of the dns command is: 'dns hostname [env_var]' so one can pretty much give any variable name to receive the IP address.

Quoted 1 line

If we do not need it repurpose the void *arg and get rid of the global 'done'

I could probably use a struct to get rid of the globals. Let me see what I can do.

Yea just pass a struct with char* and a bool * and you should be fine

Thanks
/Ilias

Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
net-lwip/dns.c new file +3 -0
+
+       printf("%s\n", ipstr);
+}

net-lwip/dns.c line 50

Quoted 10 lines
net-lwip/dns.c new file +10 -0
+
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       bool has_server = false;
+       ip_addr_t ipaddr;
+       ip_addr_t ns;
+       char *nsenv;
+       char *name;
+       char *var;
+       int ret;

[...]

Thanks
/Ilias

#15 lore raw

Re: [PATCH v3 06/12] net-lwip: add dns command

Quoted 14 lines · Ilias Apalodimas

[...]

Quoted 12 lines
Quoted 11 lines

net-lwip/dns.c line 37

Quoted 9 lines
net-lwip/dns.c new file +9 -0
+
+       if (!ipaddr) {
+               printf("DNS: host not found\n");
+               host_ipaddr.addr = 0;
+               return;
+       }
+
+       if (var)
+               env_set(var, ipstr);

Do we need this? Won't this set <dns_name> == ipaddr?

Quoted 8 lines
Quoted 6 lines

No, the syntax of the dns command is: 'dns hostname [env_var]' so one can pretty much give any variable name to receive the IP address.

Quoted 1 line

If we do not need it repurpose the void *arg and get rid of the global 'done'

I could probably use a struct to get rid of the globals. Let me see what I can do.

Yea just pass a struct with char* and a bool * and you should be fine

Done in v4.

Thanks,

Signature · 1 line
Jerome
#16 lore raw

PATCH v3 7/12 net-lwip: add wget command

In reply to Jerome Forissier

Add support for the wget command with NET_LWIP.

About the small change in cmd/efidebug.c: when the wget command based on the lwIP stack is used the wget command has a built-in URL validation function since it needs to parse it anyways (in parse_url()). Therefore wget_validate_uri() doesn't exist. So, guard the call in efidebug.c with CONFIG_CMD_WGET.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/Makefile       |   5 +-
 cmd/efidebug.c     |   8 +-
 cmd/net-common.c   | 115 +++++++++++++++++++++++++++++
 cmd/net-lwip.c     |  12 +++
 cmd/net.c          | 115 -----------------------------
 include/net-lwip.h |  51 +++++++++++++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 180 +++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 375 insertions(+), 119 deletions(-)
 create mode 100644 cmd/net-common.c
 create mode 100644 net-lwip/wget.c
cmd/Kconfig +7 -0
index 6ef0b52cd34..d9a86540be6 100644
@@ -2117,6 +2117,13 @@ config CMD_TFTPBOOT
 	help
 	  tftpboot - load file via network using TFTP protocol
 
+config CMD_WGET
+	bool "wget"
+	select PROT_TCP_LWIP
+	help
+	  wget is a simple command to download kernel, or other files,
+	  from a http server over TCP.
+
 endif
 
 endif
cmd/Makefile +4 -1
index 535b6838ca5..e90f2f68211 100644
@@ -129,8 +129,11 @@ obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
 obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o
+obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o
 ifdef CONFIG_CMD_NET_LWIP
-CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+CFLAGS_net-lwip.o := $(lwip-includes)
+CFLAGS_net-common.o := $(lwip-includes)
 endif
 obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
cmd/efidebug.c +5 -3
index c2c525f2351..d80e91ecadd 100644
@@ -741,9 +741,11 @@ static int efi_boot_add_uri(int argc, char *const argv[], u16 *var_name16,
 	if (!label)
 		return CMD_RET_FAILURE;
 
-	if (!wget_validate_uri(argv[3])) {
-		printf("ERROR: invalid URI\n");
-		return CMD_RET_FAILURE;
+	if (IS_ENABLED(CONFIG_CMD_WGET)) {
+		if (!wget_validate_uri(argv[3])) {
+			printf("ERROR: invalid URI\n");
+			return CMD_RET_FAILURE;
+		}
 	}
 
 	efi_create_indexed_name(var_name16, var_name16_size, "Boot", id);
cmd/net-common.c new file +115 -0

115 lines not on this page · raw message

cmd/net-lwip.c +12 -0
index 3abafdf7969..b80375c831e 100644
@@ -2,6 +2,10 @@
 /* Copyright (C) 2024 Linaro Ltd. */
 
 #include <command.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+#include <linux/compat.h>
+#include <linux/ethtool.h>
 #include <net-lwip.h>
 
 #if defined(CONFIG_CMD_DHCP)
@@ -35,3 +39,11 @@ U_BOOT_CMD(
 	"hostname [envvar]"
 );
 #endif
+
+#if defined(CONFIG_CMD_WGET)
+U_BOOT_CMD(
+	wget,   3,      1,      do_wget,
+	"boot image via network using HTTP protocol",
+	"[loadAddress] URL"
+);
+#endif
cmd/net.c +0 -115

118 lines not on this page · raw message

include/net-lwip.h +51 -0

62 lines not on this page · raw message

net-lwip/Makefile +1 -0
index aa247859483..bc011bb0e32 100644
@@ -10,6 +10,7 @@ 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
 
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
net-lwip/wget.c new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
2.40.1
#17 lore raw

Re: [PATCH v3 07/12] net-lwip: add wget command

Hi Jerome,

Can we split this in 2 patches instead?
A preparatory one, with split the net-common etc and one that adds wget?

Thanks
/Ilias

Quoted 622 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

About the small change in cmd/efidebug.c: when the wget command based on the lwIP stack is used the wget command has a built-in URL validation function since it needs to parse it anyways (in parse_url()). Therefore wget_validate_uri() doesn't exist. So, guard the call in efidebug.c with CONFIG_CMD_WGET.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/Makefile       |   5 +-
 cmd/efidebug.c     |   8 +-
 cmd/net-common.c   | 115 +++++++++++++++++++++++++++++
 cmd/net-lwip.c     |  12 +++
 cmd/net.c          | 115 -----------------------------
 include/net-lwip.h |  51 +++++++++++++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 180 +++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 375 insertions(+), 119 deletions(-)
 create mode 100644 cmd/net-common.c
 create mode 100644 net-lwip/wget.c
cmd/Kconfig +7 -0
index 6ef0b52cd34..d9a86540be6 100644
@@ -2117,6 +2117,13 @@ config CMD_TFTPBOOT
        help
          tftpboot - load file via network using TFTP protocol
 
+config CMD_WGET
+       bool "wget"
+       select PROT_TCP_LWIP
+       help
+         wget is a simple command to download kernel, or other files,
+         from a http server over TCP.
+
 endif
 
 endif
cmd/Makefile +4 -1
index 535b6838ca5..e90f2f68211 100644
@@ -129,8 +129,11 @@ obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
 obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o
+obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o
 ifdef CONFIG_CMD_NET_LWIP
-CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot
+CFLAGS_net-lwip.o := $(lwip-includes)
+CFLAGS_net-common.o := $(lwip-includes)
 endif
 obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
cmd/efidebug.c +5 -3
index c2c525f2351..d80e91ecadd 100644
@@ -741,9 +741,11 @@ static int efi_boot_add_uri(int argc, char *const argv[], u16 *var_name16,
        if (!label)
                return CMD_RET_FAILURE;
 
-       if (!wget_validate_uri(argv[3])) {
-               printf("ERROR: invalid URI\n");
-               return CMD_RET_FAILURE;
+       if (IS_ENABLED(CONFIG_CMD_WGET)) {
+               if (!wget_validate_uri(argv[3])) {
+                       printf("ERROR: invalid URI\n");
+                       return CMD_RET_FAILURE;
+               }
        }
 
        efi_create_indexed_name(var_name16, var_name16_size, "Boot", id);
cmd/net-common.c new file +115 -0
new file mode 100644
index 00000000000..f01d9e63998
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ */
+
+#include <command.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+#ifdef CONFIG_NET
+#include <net.h>
+#elif defined CONFIG_NET_LWIP
+#include <net-lwip.h>
+#else
+#error Either NET or NET_LWIP must be enabled
+#endif
+#include <linux/compat.h>
+#include <linux/ethtool.h>
+
+static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       const struct udevice *current = eth_get_dev();
+       unsigned char env_enetaddr[ARP_HLEN];
+       const struct udevice *dev;
+       struct uclass *uc;
+
+       uclass_id_foreach_dev(UCLASS_ETH, dev, uc) {
+               eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr);
+               printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr,
+                      current == dev ? "active" : "");
+       }
+       return CMD_RET_SUCCESS;
+}
+
+static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       int nstats, err, i, off;
+       struct udevice *dev;
+       u64 *values;
+       u8 *strings;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev);
+       if (err) {
+               printf("Could not find device %s\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       if (!eth_get_ops(dev)->get_sset_count ||
+           !eth_get_ops(dev)->get_strings ||
+           !eth_get_ops(dev)->get_stats) {
+               printf("Driver does not implement stats dump!\n");
+               return CMD_RET_FAILURE;
+       }
+
+       nstats = eth_get_ops(dev)->get_sset_count(dev);
+       strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL);
+       if (!strings)
+               return CMD_RET_FAILURE;
+
+       values = kcalloc(nstats, sizeof(u64), GFP_KERNEL);
+       if (!values)
+               goto err_free_strings;
+
+       eth_get_ops(dev)->get_strings(dev, strings);
+       eth_get_ops(dev)->get_stats(dev, values);
+
+       off = 0;
+       for (i = 0; i < nstats; i++) {
+               printf("  %s: %llu\n", &strings[off], values[i]);
+               off += ETH_GSTRING_LEN;
+       };
+
+       kfree(strings);
+       kfree(values);
+
+       return CMD_RET_SUCCESS;
+
+err_free_strings:
+       kfree(strings);
+
+       return CMD_RET_FAILURE;
+}
+
+static struct cmd_tbl cmd_net[] = {
+       U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""),
+       U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""),
+};
+
+static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+       struct cmd_tbl *cp;
+
+       cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net));
+
+       /* Drop the net command */
+       argc--;
+       argv++;
+
+       if (!cp || argc > cp->maxargs)
+               return CMD_RET_USAGE;
+       if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
+               return CMD_RET_SUCCESS;
+
+       return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+       net, 3, 1, do_net,
+       "NET sub-system",
+       "list - list available devices\n"
+       "stats <device> - dump statistics for specified device\n"
+);
cmd/net-lwip.c +12 -0
index 3abafdf7969..b80375c831e 100644
@@ -2,6 +2,10 @@
 /* Copyright (C) 2024 Linaro Ltd. */
 
 #include <command.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+#include <linux/compat.h>
+#include <linux/ethtool.h>
 #include <net-lwip.h>
 
 #if defined(CONFIG_CMD_DHCP)
@@ -35,3 +39,11 @@ U_BOOT_CMD(
        "hostname [envvar]"
 );
 #endif
+
+#if defined(CONFIG_CMD_WGET)
+U_BOOT_CMD(
+       wget,   3,      1,      do_wget,
+       "boot image via network using HTTP protocol",
+       "[loadAddress] URL"
+);
+#endif
cmd/net.c +0 -115
index d407d8320a3..03b4582204f 100644
@@ -676,118 +676,3 @@ U_BOOT_CMD(
 );
 
 #endif  /* CONFIG_CMD_LINK_LOCAL */
-
-static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-       const struct udevice *current = eth_get_dev();
-       unsigned char env_enetaddr[ARP_HLEN];
-       const struct udevice *dev;
-       struct uclass *uc;
-
-       uclass_id_foreach_dev(UCLASS_ETH, dev, uc) {
-               eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr);
-               printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr,
-                      current == dev ? "active" : "");
-       }
-       return CMD_RET_SUCCESS;
-}
-
-static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-       int nstats, err, i, off;
-       struct udevice *dev;
-       u64 *values;
-       u8 *strings;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev);
-       if (err) {
-               printf("Could not find device %s\n", argv[1]);
-               return CMD_RET_FAILURE;
-       }
-
-       if (!eth_get_ops(dev)->get_sset_count ||
-           !eth_get_ops(dev)->get_strings ||
-           !eth_get_ops(dev)->get_stats) {
-               printf("Driver does not implement stats dump!\n");
-               return CMD_RET_FAILURE;
-       }
-
-       nstats = eth_get_ops(dev)->get_sset_count(dev);
-       strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL);
-       if (!strings)
-               return CMD_RET_FAILURE;
-
-       values = kcalloc(nstats, sizeof(u64), GFP_KERNEL);
-       if (!values)
-               goto err_free_strings;
-
-       eth_get_ops(dev)->get_strings(dev, strings);
-       eth_get_ops(dev)->get_stats(dev, values);
-
-       off = 0;
-       for (i = 0; i < nstats; i++) {
-               printf("  %s: %llu\n", &strings[off], values[i]);
-               off += ETH_GSTRING_LEN;
-       };
-
-       return CMD_RET_SUCCESS;
-
-err_free_strings:
-       kfree(strings);
-
-       return CMD_RET_FAILURE;
-}
-
-static struct cmd_tbl cmd_net[] = {
-       U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""),
-       U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""),
-};
-
-static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-       struct cmd_tbl *cp;
-
-       cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net));
-
-       /* Drop the net command */
-       argc--;
-       argv++;
-
-       if (!cp || argc > cp->maxargs)
-               return CMD_RET_USAGE;
-       if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
-               return CMD_RET_SUCCESS;
-
-       return cp->cmd(cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(
-       net, 3, 1, do_net,
-       "NET sub-system",
-       "list - list available devices\n"
-       "stats <device> - dump statistics for specified device\n"
-);
-
-#if defined(CONFIG_CMD_NCSI)
-static int do_ncsi(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (!phy_interface_is_ncsi() || !ncsi_active()) {
-               printf("Device not configured for NC-SI\n");
-               return CMD_RET_FAILURE;
-       }
-
-       if (net_loop(NCSI) < 0)
-               return CMD_RET_FAILURE;
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       ncsi,   1,      1,      do_ncsi,
-       "Configure attached NIC via NC-SI",
-       ""
-);
-#endif  /* CONFIG_CMD_NCSI */
include/net-lwip.h +51 -0
index 0019d1524e5..6fda940fec2 100644
@@ -51,6 +51,56 @@ int eth_env_get_enetaddr_by_index(const char *base_name, int index,
 int eth_init(void);                    /* Initialize the device */
 int eth_send(void *packet, int length);           /* Send a packet */
 int eth_rx(void);
+
+/**
+ * struct eth_ops - functions of Ethernet MAC controllers
+ *
+ * start: Prepare the hardware to send and receive packets
+ * send: Send the bytes passed in "packet" as a packet on the wire
+ * recv: Check if the hardware received a packet. If so, set the pointer to the
+ *      packet buffer in the packetp parameter. If not, return an error or 0 to
+ *      indicate that the hardware receive FIFO is empty. If 0 is returned, the
+ *      network stack will not process the empty packet, but free_pkt() will be
+ *      called if supplied
+ * free_pkt: Give the driver an opportunity to manage its packet buffer memory
+ *          when the network stack is finished processing it. This will only be
+ *          called when no error was returned from recv - optional
+ * stop: Stop the hardware from looking for packets - may be called even if
+ *      state == PASSIVE
+ * mcast: Join or leave a multicast group (for TFTP) - optional
+ * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux
+ *              on some platforms like ARM). This function expects the
+ *              eth_pdata::enetaddr field to be populated. The method can
+ *              return -ENOSYS to indicate that this is not implemented for
+                this hardware - optional.
+ * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a
+ *                 ROM on the board. This is how the driver should expose it
+ *                 to the network stack. This function should fill in the
+ *                 eth_pdata::enetaddr field - optional
+ * set_promisc: Enable or Disable promiscuous mode
+ * get_sset_count: Number of statistics counters
+ * get_string: Names of the statistic counters
+ * get_stats: The values of the statistic counters
+ */
+struct eth_ops {
+       int (*start)(struct udevice *dev);
+       int (*send)(struct udevice *dev, void *packet, int length);
+       int (*recv)(struct udevice *dev, int flags, uchar **packetp);
+       int (*free_pkt)(struct udevice *dev, uchar *packet, int length);
+       void (*stop)(struct udevice *dev);
+       int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join);
+       int (*write_hwaddr)(struct udevice *dev);
+       int (*read_rom_hwaddr)(struct udevice *dev);
+       int (*set_promisc)(struct udevice *dev, bool enable);
+       int (*get_sset_count)(struct udevice *dev);
+       void (*get_strings)(struct udevice *dev, u8 *data);
+       void (*get_stats)(struct udevice *dev, u64 *data);
+};
+
+#define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops)
+
+struct udevice *eth_get_dev(void); /* get the current device */
+int eth_get_dev_index(void);
 const char *eth_get_name(void);
 int eth_get_dev_index(void);
 int eth_init_state_only(void); /* Set active state */
@@ -85,5 +135,6 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
 
 #endif /* __NET_LWIP_H__ */
net-lwip/Makefile +1 -0
index aa247859483..bc011bb0e32 100644
@@ -10,6 +10,7 @@ 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
 
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
net-lwip/wget.c new file +180 -1
new file mode 100644
index 00000000000..e3e6f525674
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <console.h>
+#include <display_options.h>
+#include <image.h>
+#include <lwip/apps/http_client.h>
+#include <lwip/timeouts.h>
+#include <net-lwip.h>
+#include <time.h>
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+
+static ulong daddr;
+static ulong saved_daddr;
+static ulong size;
+static ulong prevsize;
+#define PROGRESS_PRINT_STEP_BYTES (100 * 1024)
+static ulong start_time;
+static enum done_state {
+        NOT_DONE = 0,
+        SUCCESS = 1,
+        FAILURE = 2
+} done;
+
+static int parse_url(char *url, char *host, u16 *port, char **path)
+{
+       char *p, *pp;
+       long lport;
+
+       p = strstr(url, "http://");
+       if (!p)
+               return -EINVAL;
+
+       p += strlen("http://");
+
+       /* Parse hostname */
+       pp = strchr(p, ':');
+       if (!pp)
+               pp = strchr(p, '/');
+       if (!pp)
+               return -EINVAL;
+
+       if (p + SERVER_NAME_SIZE <= pp)
+               return -EINVAL;
+
+       memcpy(host, p, pp - p);
+       host[pp - p + 1] = '\0';
+
+       if (*pp == ':') {
+               /* Parse port number */
+               p = pp + 1;
+               lport = simple_strtol(p, &pp, 10);
+               if (pp && *pp != '/')
+                       return -EINVAL;
+               if (lport > 65535)
+                       return -EINVAL;
+               *port = (u16)lport;
+       } else {
+               *port = HTTP_PORT_DEFAULT;
+       }
+       if (*pp != '/')
+               return -EINVAL;
+       *path = pp;
+
+       return 0;
+}
+
+static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf,
+                          err_t err)
+{
+       struct pbuf *buf;
+
+       if (!pbuf)
+               return ERR_BUF;
+
+       for (buf = pbuf; buf; buf = buf->next) {
+               memcpy((void *)daddr, buf->payload, buf->len);
+               daddr += buf->len;
+               size += buf->len;
+               if (size - prevsize > PROGRESS_PRINT_STEP_BYTES) {
+                       printf("#");
+                       prevsize = size;
+               }
+       }
+
+       altcp_recved(pcb, pbuf->tot_len);
+       pbuf_free(pbuf);
+       return ERR_OK;
+}
+
+static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
+                           u32_t rx_content_len, u32_t srv_res, err_t err)
+{
+       ulong elapsed;
+
+       if (httpc_result != HTTPC_RESULT_OK) {
+               log_err("\nHTTP client error %d\n", httpc_result);
+               done = FAILURE;
+               return;
+       }
+
+       elapsed = get_timer(start_time);
+        log_info("\n%u bytes transferred in %lu ms (", rx_content_len,
+                 get_timer(start_time));
+        print_size(rx_content_len / elapsed * 1000, "/s)\n");
+
+       if (env_set_hex("filesize", rx_content_len) ||
+           env_set_hex("fileaddr", saved_daddr)) {
+               log_err("Could not set filesize or fileaddr\n");
+               done = FAILURE;
+               return;
+       }
+
+       done = SUCCESS;
+}
+
+int wget_with_dns(ulong dst_addr, char *uri)
+{
+       char server_name[SERVER_NAME_SIZE];
+       httpc_connection_t conn;
+       httpc_state_t *state;
+       char *path;
+       u16 port;
+
+       daddr = dst_addr;
+       saved_daddr = dst_addr;
+       done = NOT_DONE;
+       size = 0;
+       prevsize = 0;
+
+       if (parse_url(uri, server_name, &port, &path))
+               return CMD_RET_USAGE;
+
+       memset(&conn, 0, sizeof(conn));
+       conn.result_fn = httpc_result_cb;
+       start_time = get_timer(0);
+       if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+                              NULL, &state))
+               return CMD_RET_FAILURE;
+
+       while (!done) {
+               eth_rx();
+               sys_check_timeouts();
+               if (ctrlc())
+                       break;
+       }
+
+       if (done == SUCCESS)
+               return 0;
+
+       return -1;
+}
+
+int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *end;
+       char *url;
+       ulong dst_addr;
+
+       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 (wget_with_dns(dst_addr, url))
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
--

2.40.1

#18 lore raw

Re: [PATCH v3 07/12] net-lwip: add wget command

Quoted 4 lines · Ilias Apalodimas

Hi Jerome,

Can we split this in 2 patches instead?
A preparatory one, with split the net-common etc and one that adds wget?

Sure, done in v4.

Quoted 32 lines

Thanks
/Ilias

Quoted 27 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

About the small change in cmd/efidebug.c: when the wget command based on the lwIP stack is used the wget command has a built-in URL validation function since it needs to parse it anyways (in parse_url()). Therefore wget_validate_uri() doesn't exist. So, guard the call in efidebug.c with CONFIG_CMD_WGET.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/Makefile       |   5 +-
 cmd/efidebug.c     |   8 +-
 cmd/net-common.c   | 115 +++++++++++++++++++++++++++++
 cmd/net-lwip.c     |  12 +++
 cmd/net.c          | 115 -----------------------------
 include/net-lwip.h |  51 +++++++++++++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 180 +++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 375 insertions(+), 119 deletions(-)
 create mode 100644 cmd/net-common.c
 create mode 100644 net-lwip/wget.c

Thanks,

Signature · 1 line
Jerome
#19 lore raw

PATCH v3 8/12 test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y

In reply to Jerome Forissier

Some sandbox tests make strong assumptions on how the network stack is implemented. For example, the ping tests assume that ARP resolution occurs upon sending out the ICMP packet. This is not always the case with the lwIP stack which can cache ARP information. Therefore, disable these tests when CONFIG_NET_LWIP is enabled.

---
 test/dm/dsa.c | 2 ++
 test/dm/eth.c | 4 ++++
 2 files changed, 6 insertions(+)
test/dm/dsa.c +2 -0
index c857106eaf4..147e2a4afe2 100644
@@ -59,6 +59,7 @@ static int dm_test_dsa_probe(struct unit_test_state *uts)
 
 DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
 
+#if !defined(CONFIG_NET_LWIP)
 /* This test sends ping requests with the local address through each DSA port
  * via the sandbox DSA master Eth.
  */
@@ -80,3 +81,4 @@ static int dm_test_dsa(struct unit_test_state *uts)
 }
 
 DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);
+#endif /* !defined(CONFIG_NET_LWIP) */
test/dm/eth.c +4 -0
index bb3dcc6b954..cf97b1c1ab3 100644
@@ -170,6 +170,7 @@ static int dm_test_ip6_make_lladdr(struct unit_test_state *uts)
 DM_TEST(dm_test_ip6_make_lladdr, UT_TESTF_SCAN_FDT);
 #endif
 
+#if !defined(CONFIG_NET_LWIP)
 static int dm_test_eth(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
@@ -298,6 +299,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_eth_act, UT_TESTF_SCAN_FDT);
+#endif /* !CONFIG_NET_LWIP */
 
 /* Ensure that all addresses are loaded properly */
 static int dm_test_ethaddr(struct unit_test_state *uts)
@@ -332,6 +334,7 @@ static int dm_test_ethaddr(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_ethaddr, UT_TESTF_SCAN_FDT);
 
+#if !defined(CONFIG_NET_LWIP)
 /* The asserts include a return on fail; cleanup in the caller */
 static int _dm_test_eth_rotate1(struct unit_test_state *uts)
 {
@@ -616,6 +619,7 @@ static int dm_test_eth_async_ping_reply(struct unit_test_state *uts)
 }
 
 DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
+#endif /* !CONFIG_NET_LWIP */
 
 #if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
 
Signature · 1 line
2.40.1
#20 lore raw

PATCH v3 9/12 cmd: bdinfo: enable -e when CONFIG_CMD_NET_LWIP=y

In reply to Jerome Forissier

Support "bdinfo -e" when lwIP is selected.

---
 cmd/bdinfo.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
cmd/bdinfo.c +3 -2
index 79106caeec2..690fb894bf6 100644
@@ -152,7 +152,7 @@ static int bdinfo_print_all(struct bd_info *bd)
 	bdinfo_print_num_l("relocaddr", gd->relocaddr);
 	bdinfo_print_num_l("reloc off", gd->reloc_off);
 	printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
-	if (IS_ENABLED(CONFIG_CMD_NET))
+	if (IS_ENABLED(CONFIG_CMD_NET) || IS_ENABLED(CONFIG_CMD_NET_LWIP))
 		print_eth();
 	bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
 	bdinfo_print_num_l("new_fdt", (ulong)map_to_sysmem(gd->new_fdt));
@@ -198,7 +198,8 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		case 'a':
 			return bdinfo_print_all(bd);
 		case 'e':
-			if (!IS_ENABLED(CONFIG_CMD_NET))
+			if (!IS_ENABLED(CONFIG_CMD_NET) &&
+			    !IS_ENABLED(CONFIG_CMD_NET_LWIP))
 				return CMD_RET_USAGE;
 			print_eth();
 			return CMD_RET_SUCCESS;
Signature · 1 line
2.40.1
#21 lore raw

PATCH v3 10/12 configs: add qemu_arm64_lwip_defconfig

In reply to Jerome Forissier

Add qemu_arm64_lwip_defconfig based on qemu_arm64_defconfig but with NET_LWIP instead of NET.

---
 configs/qemu_arm64_lwip_defconfig | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 configs/qemu_arm64_lwip_defconfig
configs/qemu_arm64_lwip_defconfig new file +3 -0
new file mode 100644
index 00000000000..050c93ff97b
@@ -0,0 +1,3 @@
+#include <configs/qemu_arm64_defconfig>
+CONFIG_NET_LWIP=y
+# CONFIG_DFU_TFTP is not set
Signature · 1 line
2.40.1
#22 lore raw

PATCH v3 11/12 MAINTAINERS: net-lwip: add myself as a maintainer

In reply to Jerome Forissier

Add myself as a maintainer for the lwIP network stack integration code and network commands. The library code itself (i.e., most files under lib/lwip/ except README, Makefile and integration files in u-boot) is unmodified from upstream and therefore does not need a maintainer.

---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
index f8afd7d51e2..11105869304 100644
@@ -1310,6 +1310,17 @@ F:	drivers/net/
 F:	include/net.h
 F:	net/
 
+NETWORK (LWIP)
+M:	Jerome Forissier <[email protected]>
+S:	Maintained
+F:	cmd/net-lwip.c
+F:	configs/qemu_arm64_lwip_defconfig
+F:	include/net-lwip.h
+F:	lib/lwip/Makefile
+F:	lib/lwip/README
+F:	lib/lwip/u-boot/
+F:	net-lwip/
+
 NIOS
 M:	Thomas Chou <[email protected]>
 S:	Maintained
Signature · 1 line
2.40.1
#23 lore raw

PATCH v3 12/12 CI: add qemu_arm64_lwip to the test matrix

In reply to Jerome Forissier

Build and run qemu_arm64_lwip_defconfig in CI. This tests the lightweight IP (lwIP) implementation of the dhcp, tftpboot and ping commands.

---
 .azure-pipelines.yml | 7 +++++++
 1 file changed, 7 insertions(+)
.azure-pipelines.yml +7 -0
index 27f69583c65..4da1bb12fab 100644
@@ -199,6 +199,10 @@ stages:
           cd \${WORK_DIR}
           git config --global --add safe.directory \${WORK_DIR}
           git clone --depth=1 https://source.denx.de/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
+          # qemu_arm64_lwip_defconfig is the same as qemu_arm64 but with NET_LWIP enabled.
+          # The test config and the boardenv file from qemu_arm64 can be re-used so create symlinks
+          ln -s conf.qemu_arm64_na /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na
+          ln -s u_boot_boardenv_qemu_arm64_na.py /tmp/uboot-test-hooks/py/travis-ci/u_boot_boardenv_qemu_arm64_lwip_na.py
           ln -s travis-ci /tmp/uboot-test-hooks/bin/\`hostname\`
           ln -s travis-ci /tmp/uboot-test-hooks/py/\`hostname\`
           grub-mkimage --prefix=\"\" -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd
@@ -371,6 +375,9 @@ stages:
         qemu_arm64:
           TEST_PY_BD: "qemu_arm64"
           TEST_PY_TEST_SPEC: "not sleep"
+        qemu_arm64_lwip:
+          TEST_PY_BD: "qemu_arm64_lwip"
+          TEST_PY_TEST_SPEC: "test_net_dhcp or test_net_ping or test_net_tftpboot"
         qemu_m68k:
           TEST_PY_BD: "M5208EVBE"
           TEST_PY_ID: "--id qemu"
Signature · 1 line
2.40.1
#24 lore raw
In reply to Jerome Forissier
Quoted 10 lines · Jerome Forissier

This is a rework of a patch series by Maxim Uvarov: "net/lwip: add lwip library for the network stack" [1]. The goal is to introduce the lwIP TCP/IP stack [2] [3] as an alternative to the current implementation in net/, selectable with Kconfig, and ultimately keep only lwIP if possible. Some reasons for doing so are:
- Make the support of HTTPS in the wget command easier. Javier T. (CC'd) has some additional lwIP and Mbed TLS patches to do so. With that it becomes possible to fetch and launch a distro installer such as Debian etc. using a secure, authenticated connection directly from the U-Boot shell. Several use cases:

Quoted 8 lines

* Authentication: prevent MITM attack (third party replacing the
binary with a different one)
* Confidentiality: prevent third parties from grabbing a copy of the
image as it is being downloaded
* Allow connection to servers that do not support plain HTTP anymore
(this is becoming more and more common on the Internet these days)
- Possibly benefit from additional features implemented in lwIP
- Less code to maintain in U-Boot

Alright, on Pi 3, I think we have more "output changed, test fails"
problems:
========================================== FAILURES =========================================== _____________________________________ test_efi_fit_launch _____________________________________ test/py/tests/test_efi_fit.py:452: in test_efi_fit_launch
launch_efi(False, False)
test/py/tests/test_efi_fit.py:394: in launch_efi

    net_set_up = net_dhcp()

test/py/tests/test_efi_fit.py:178: in net_dhcp
assert 'DHCP client bound to address ' in output
E AssertionError: assert 'DHCP client bound to address ' in 'Waiting for Ethernet connection... done.\r\neth0: smsc95xx_eth b8:27:eb:fc:64:a6 active'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> usb start
U-Boot> U-Boot> setenv autoload no
U-Boot> U-Boot> dhcp
Waiting for Ethernet connection... done.
eth0: smsc95xx_eth b8:27:eb:fc:64:a6 active
U-Boot>
=================================== short test summary info ===================================

I'm going to skip that set of tests and see how far we get but I suspect it'll keep failing on DHCP output being different.

Signature · 1 line
Tom
#25 lore raw
Quoted 41 lines · Tom Rini
Quoted 10 lines · Jerome Forissier

This is a rework of a patch series by Maxim Uvarov: "net/lwip: add lwip library for the network stack" [1]. The goal is to introduce the lwIP TCP/IP stack [2] [3] as an alternative to the current implementation in net/, selectable with Kconfig, and ultimately keep only lwIP if possible. Some reasons for doing so are:
- Make the support of HTTPS in the wget command easier. Javier T. (CC'd) has some additional lwIP and Mbed TLS patches to do so. With that it becomes possible to fetch and launch a distro installer such as Debian etc. using a secure, authenticated connection directly from the U-Boot shell. Several use cases:

Quoted 8 lines

* Authentication: prevent MITM attack (third party replacing the
binary with a different one)
* Confidentiality: prevent third parties from grabbing a copy of the
image as it is being downloaded
* Allow connection to servers that do not support plain HTTP anymore
(this is becoming more and more common on the Internet these days)
- Possibly benefit from additional features implemented in lwIP
- Less code to maintain in U-Boot

Alright, on Pi 3, I think we have more "output changed, test fails"
problems:
========================================== FAILURES =========================================== _____________________________________ test_efi_fit_launch _____________________________________ test/py/tests/test_efi_fit.py:452: in test_efi_fit_launch
launch_efi(False, False)
test/py/tests/test_efi_fit.py:394: in launch_efi

    net_set_up = net_dhcp()

test/py/tests/test_efi_fit.py:178: in net_dhcp
assert 'DHCP client bound to address ' in output
E AssertionError: assert 'DHCP client bound to address ' in 'Waiting for Ethernet connection... done.\r\neth0: smsc95xx_eth b8:27:eb:fc:64:a6 active'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> usb start
U-Boot> U-Boot> setenv autoload no
U-Boot> U-Boot> dhcp
Waiting for Ethernet connection... done.
eth0: smsc95xx_eth b8:27:eb:fc:64:a6 active
U-Boot>
=================================== short test summary info ===================================

Quoted 2 lines

I'm going to skip that set of tests and see how far we get but I suspect it'll keep failing on DHCP output being different.

As discussed offline with Ilias it might be a timeout issue, although 2000 ms for DHCP_TIMEOUT_MS seems a large value to me, it might not be enough in your environment. Can you please try to increase it? NET effectively has a timeout of 28 seconds if we take the retries into account.

Thanks,

Signature · 1 line
Jerome
#26 lore raw
Quoted 44 lines · Jerome Forissier
Quoted 41 lines · Tom Rini
Quoted 10 lines · Jerome Forissier

This is a rework of a patch series by Maxim Uvarov: "net/lwip: add lwip library for the network stack" [1]. The goal is to introduce the lwIP TCP/IP stack [2] [3] as an alternative to the current implementation in net/, selectable with Kconfig, and ultimately keep only lwIP if possible. Some reasons for doing so are:
- Make the support of HTTPS in the wget command easier. Javier T. (CC'd) has some additional lwIP and Mbed TLS patches to do so. With that it becomes possible to fetch and launch a distro installer such as Debian etc. using a secure, authenticated connection directly from the U-Boot shell. Several use cases:

Quoted 8 lines

* Authentication: prevent MITM attack (third party replacing the
binary with a different one)
* Confidentiality: prevent third parties from grabbing a copy of the
image as it is being downloaded
* Allow connection to servers that do not support plain HTTP anymore
(this is becoming more and more common on the Internet these days)
- Possibly benefit from additional features implemented in lwIP
- Less code to maintain in U-Boot

Alright, on Pi 3, I think we have more "output changed, test fails"
problems:
========================================== FAILURES =========================================== _____________________________________ test_efi_fit_launch _____________________________________ test/py/tests/test_efi_fit.py:452: in test_efi_fit_launch
launch_efi(False, False)
test/py/tests/test_efi_fit.py:394: in launch_efi

    net_set_up = net_dhcp()

test/py/tests/test_efi_fit.py:178: in net_dhcp
assert 'DHCP client bound to address ' in output
E AssertionError: assert 'DHCP client bound to address ' in 'Waiting for Ethernet connection... done.\r\neth0: smsc95xx_eth b8:27:eb:fc:64:a6 active'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> usb start
U-Boot> U-Boot> setenv autoload no
U-Boot> U-Boot> dhcp
Waiting for Ethernet connection... done.
eth0: smsc95xx_eth b8:27:eb:fc:64:a6 active
U-Boot>
=================================== short test summary info ===================================

Quoted 7 lines
Quoted 2 lines

I'm going to skip that set of tests and see how far we get but I suspect it'll keep failing on DHCP output being different.

As discussed offline with Ilias it might be a timeout issue, although 2000 ms for DHCP_TIMEOUT_MS seems a large value to me, it might not be enough in your environment. Can you please try to increase it? NET effectively has a timeout of 28 seconds if we take the retries into account.

I increased it to 20000 ms and no change.

Signature · 1 line
Tom