Skip to contentSkip to conversation

Introduce the lwIP network stack

PATCH Superseded Jerome Forissier 10 participants 53 messages Jun 17, 2024 – Jul 1, 2024

Subsystems (7)

v4 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v4 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Changes in v4:

- Fixed the DHCP algorithm which was missing a sys_timeout() call in the "fine timer" callback. This should close the issue that Tom R. reported with his Raspberry Pi 3 (it does fix it on mine).
- The DHCP exchange timeout is increased from 2 to 10 seconds
- The DHCP exchange can be interrupted with Ctrl-C.
- "net: introduce alternative implementation as net-lwip/": rework dependencies. A few symbols have 'depends on !NET_LWIP' and in addition 'NET_LWIP depends on !SANDBOX'. Sandbox, DSA and fastboot are unsupported, because they are deeply welded to the current stack.
- All network commands (dns, ping, tftp and wget):
* Get rid of global variables (Ilias A.)
* Use printf() rather than log_info()
- "net-lwip: add ping command": use packet count instead of timeout, fix code style (Ilias A.)
- Add "net: split cmd/net.c into cmd/net.c and cmd/net-common.c" extracted from the wget patch (Ilias A.).
- Add "net: split include/net.h into net{,-common,-legacy,-lwip}.h" (Ilias A.)
- Add "flash: prefix error codes with FL_" which is required to avoid name clashes when splitting net.h
- Reworked the initialization of the lwIP stack. One and only one network interface (struct netif) is added for the duration of the command that uses that interface. That's commit "net-lwip:
add DHCP support and dhcp commmand".
- Drop "test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y", not needed now that NET_LWIP depend on !SANDBOX.
- qemu_arm64_lwip_defconfig now enables CMD_DNS and CMD_WGET (so that all the supported network commands are available).

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 (14):
flash: prefix error codes with FL_
net: introduce alternative implementation as net-lwip/
net: split include/net.h into net{,-common,-legacy,-lwip}.h
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: split cmd/net.c into cmd/net.c and cmd/net-common.c
net-lwip: add wget command
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                           |  41 ++
 MAINTAINERS                       |  11 +
 Makefile                          |  12 +-
 board/cobra5272/flash.c           |  26 +-
 board/freescale/m5253demo/flash.c |   6 +-
 boot/Kconfig                      |   5 +-
 cmd/Kconfig                       |  44 ++
 cmd/Makefile                      |   7 +
 cmd/bdinfo.c                      |   5 +-
 cmd/net-common.c                  | 109 ++++
 cmd/net-lwip.c                    |  45 ++
 cmd/net.c                         | 115 ----
 common/Kconfig                    |   2 +-
 common/board_r.c                  |   4 +-
 common/flash.c                    |  44 +-
 common/spl/Kconfig                |   1 +
 configs/qemu_arm64_lwip_defconfig |   4 +
 drivers/dfu/Kconfig               |   1 +
 drivers/fastboot/Kconfig          |   1 +
 drivers/mtd/cfi_flash.c           |  36 +-
 drivers/net/Kconfig               |   3 +-
 drivers/net/phy/Kconfig           |   2 +-
 drivers/usb/gadget/Kconfig        |   2 +-
 include/flash.h                   |  20 +-
 include/net-common.h              | 408 +++++++++++++
 include/net-legacy.h              | 649 ++++++++++++++++++++
 include/net-lwip.h                |  36 ++
 include/net.h                     | 944 +-----------------------------
 lib/Makefile                      |   2 +
 lib/lwip/Makefile                 |  55 ++
 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                   | 108 ++++
 net-lwip/dns.c                    | 117 ++++
 net-lwip/eth_internal.h           |  35 ++
 net-lwip/net-lwip.c               | 270 +++++++++
 net-lwip/ping.c                   | 174 ++++++
 net-lwip/tftp.c                   | 226 +++++++
 net-lwip/wget.c                   | 269 +++++++++
 net/Kconfig                       |  14 -
 45 files changed, 3008 insertions(+), 1147 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-common.h
 create mode 100644 include/net-legacy.h
 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 v4 1/14 flash: prefix error codes with FL_

Prefix the flash status codes (ERR_*) with FL_ in order to avoid clashes with third-party libraries. Case in point: including the lwIP library header file <lwip/err.h> which defines err_enum_t as an enum with values being ERR_*.

---
 board/cobra5272/flash.c           | 26 +++++++++---------
 board/freescale/m5253demo/flash.c |  6 ++---
 common/flash.c                    | 44 +++++++++++++++----------------
 drivers/mtd/cfi_flash.c           | 36 ++++++++++++-------------
 include/flash.h                   | 20 +++++++-------
 5 files changed, 66 insertions(+), 66 deletions(-)
board/cobra5272/flash.c +13 -13
index 8416af163ad..6464975f184 100644
@@ -134,22 +134,22 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 {
 	ulong result;
 	int iflag, cflag, prot, sect;
-	int rc = ERR_OK;
+	int rc = FL_ERR_OK;
 	int chip1;
 	ulong start;
 
 	/* first look for protection bits */
 
 	if (info->flash_id == FLASH_UNKNOWN)
-		return ERR_UNKNOWN_FLASH_TYPE;
+		return FL_ERR_UNKNOWN_FLASH_TYPE;
 
 	if ((s_first < 0) || (s_first > s_last)) {
-		return ERR_INVAL;
+		return FL_ERR_INVAL;
 	}
 
 	if ((info->flash_id & FLASH_VENDMASK) !=
 	    (AMD_MANUFACT & FLASH_VENDMASK)) {
-		return ERR_UNKNOWN_FLASH_VENDOR;
+		return FL_ERR_UNKNOWN_FLASH_VENDOR;
 	}
 
 	prot = 0;
@@ -159,7 +159,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 		}
 	}
 	if (prot)
-		return ERR_PROTECTED;
+		return FL_ERR_PROTECTED;
 
 	/*
 	 * Disable interrupts which might cause a timeout
@@ -216,11 +216,11 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 			MEM_FLASH_ADDR1 = CMD_READ_ARRAY;
 
 			if (chip1 == ERR) {
-				rc = ERR_PROG_ERROR;
+				rc = FL_ERR_PROG_ERROR;
 				goto outahere;
 			}
 			if (chip1 == TMO) {
-				rc = ERR_TIMEOUT;
+				rc = FL_ERR_TIMEOUT;
 				goto outahere;
 			}
 
@@ -251,7 +251,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
 {
 	volatile u16 *addr = (volatile u16 *) dest;
 	ulong result;
-	int rc = ERR_OK;
+	int rc = FL_ERR_OK;
 	int cflag, iflag;
 	int chip1;
 	ulong start;
@@ -261,7 +261,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
 	 */
 	result = *addr;
 	if ((result & data) != data)
-		return ERR_NOT_ERASED;
+		return FL_ERR_NOT_ERASED;
 
 
 	/*
@@ -302,7 +302,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
 	*addr = CMD_READ_ARRAY;
 
 	if (chip1 == ERR || *addr != data)
-		rc = ERR_PROG_ERROR;
+		rc = FL_ERR_PROG_ERROR;
 
 	if (iflag)
 		enable_interrupts();
@@ -321,13 +321,13 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 
 	if (addr & 1) {
 		printf ("unaligned destination not supported\n");
-		return ERR_ALIGN;
+		return FL_ERR_ALIGN;
 	}
 
 #if 0
 	if (cnt & 1) {
 		printf ("odd transfer sizes not supported\n");
-		return ERR_ALIGN;
+		return FL_ERR_ALIGN;
 	}
 #endif
 
@@ -365,5 +365,5 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 		cnt -= 1;
 	}
 
-	return ERR_OK;
+	return FL_ERR_OK;
 }
board/freescale/m5253demo/flash.c +3 -3
index eeb9cfd3125..b6b7df88761 100644
@@ -71,7 +71,7 @@ int flash_get_offsets(ulong base, flash_info_t * info)
 		}
 	}
 
-	return ERR_OK;
+	return FL_ERR_OK;
 }
 
 void flash_print_info(flash_info_t * info)
@@ -368,9 +368,9 @@ int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 	}
 
 	if (cnt == 0)
-		return ERR_OK;
+		return FL_ERR_OK;
 
-	return ERR_OK;
+	return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
common/flash.c +22 -22

97 lines not on this page · raw message

drivers/mtd/cfi_flash.c +18 -18
index 8ade7949a68..6369c7127c6 100644
@@ -592,11 +592,11 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector,
 			       flash_read_long(info, sector, 0));
 			flash_write_cmd(info, sector, 0, info->cmd_reset);
 			udelay(1);
-			return ERR_TIMEOUT;
+			return FL_ERR_TIMEOUT;
 		}
 		udelay(1);		/* also triggers watchdog */
 	}
-	return ERR_OK;
+	return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
@@ -615,9 +615,9 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector,
 	case CFI_CMDSET_INTEL_PROG_REGIONS:
 	case CFI_CMDSET_INTEL_EXTENDED:
 	case CFI_CMDSET_INTEL_STANDARD:
-		if (retcode == ERR_OK &&
+		if (retcode == FL_ERR_OK &&
 		    !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) {
-			retcode = ERR_INVAL;
+			retcode = FL_ERR_INVAL;
 			printf("Flash %s error at address %lx\n", prompt,
 			       info->start[sector]);
 			if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS |
@@ -626,14 +626,14 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector,
 			} else if (flash_isset(info, sector, 0,
 						FLASH_STATUS_ECLBS)) {
 				puts("Block Erase Error.\n");
-				retcode = ERR_NOT_ERASED;
+				retcode = FL_ERR_NOT_ERASED;
 			} else if (flash_isset(info, sector, 0,
 						FLASH_STATUS_PSLBS)) {
 				puts("Locking Error\n");
 			}
 			if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) {
 				puts("Block locked.\n");
-				retcode = ERR_PROTECTED;
+				retcode = FL_ERR_PROTECTED;
 			}
 			if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS))
 				puts("Vpp Low Error.\n");
@@ -701,12 +701,12 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst,
 		if (get_timer(start) > tout) {
 			printf("Flash %s timeout at address %lx data %lx\n",
 			       prompt, (ulong)dst, (ulong)flash_read8(dst));
-			return ERR_TIMEOUT;
+			return FL_ERR_TIMEOUT;
 		}
 		udelay(1);		/* also triggers watchdog */
 	}
 #endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */
-	return ERR_OK;
+	return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
@@ -809,7 +809,7 @@ static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword)
 		break;
 	}
 	if (!flag)
-		return ERR_NOT_ERASED;
+		return FL_ERR_NOT_ERASED;
 
 	/* Disable interrupts which might cause a timeout here */
 	flag = disable_interrupts();
@@ -898,7 +898,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 		shift = 3;
 		break;
 	default:
-		retcode = ERR_INVAL;
+		retcode = FL_ERR_INVAL;
 		goto out_unmap;
 	}
 
@@ -929,7 +929,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 		}
 	}
 	if (!flag) {
-		retcode = ERR_NOT_ERASED;
+		retcode = FL_ERR_NOT_ERASED;
 		goto out_unmap;
 	}
 
@@ -949,7 +949,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 		retcode = flash_status_check(info, sector,
 					     info->buffer_write_tout,
 					     "write to buffer");
-		if (retcode == ERR_OK) {
+		if (retcode == FL_ERR_OK) {
 			/* reduce the number of loops by the width of
 			 * the port
 			 */
@@ -974,7 +974,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 					src += 8, dst += 8;
 					break;
 				default:
-					retcode = ERR_INVAL;
+					retcode = FL_ERR_INVAL;
 					goto out_unmap;
 				}
 			}
@@ -1024,7 +1024,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 			}
 			break;
 		default:
-			retcode = ERR_INVAL;
+			retcode = FL_ERR_INVAL;
 			goto out_unmap;
 		}
 
@@ -1042,7 +1042,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 
 	default:
 		debug("Unknown Command Set\n");
-		retcode = ERR_INVAL;
+		retcode = FL_ERR_INVAL;
 		break;
 	}
 
@@ -1388,7 +1388,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 		if (i > cnt)
 			i = cnt;
 		rc = flash_write_cfibuffer(info, wp, src, i);
-		if (rc != ERR_OK)
+		if (rc != FL_ERR_OK)
 			return rc;
 		i -= i & (info->portwidth - 1);
 		wp += i;
@@ -1397,7 +1397,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 		FLASH_SHOW_PROGRESS(scale, dots, digit, i);
 		/* Only check every once in a while */
 		if ((cnt & 0xFFFF) < buffered_size && ctrlc())
-			return ERR_ABORTED;
+			return FL_ERR_ABORTED;
 	}
 #else
 	while (cnt >= info->portwidth) {
@@ -1412,7 +1412,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 		FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth);
 		/* Only check every once in a while */
 		if ((cnt & 0xFFFF) < info->portwidth && ctrlc())
-			return ERR_ABORTED;
+			return FL_ERR_ABORTED;
 	}
 #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
 
include/flash.h +10 -10
index 3710a2731b7..77bee42f76b 100644
@@ -125,16 +125,16 @@ void flash_perror(int err);
 /*-----------------------------------------------------------------------
  * return codes from flash_write():
  */
-#define ERR_OK				0
-#define ERR_TIMEOUT			1
-#define ERR_NOT_ERASED			2
-#define ERR_PROTECTED			4
-#define ERR_INVAL			8
-#define ERR_ALIGN			16
-#define ERR_UNKNOWN_FLASH_VENDOR	32
-#define ERR_UNKNOWN_FLASH_TYPE		64
-#define ERR_PROG_ERROR			128
-#define ERR_ABORTED			256
+#define FL_ERR_OK			0
+#define FL_ERR_TIMEOUT			1
+#define FL_ERR_NOT_ERASED		2
+#define FL_ERR_PROTECTED		4
+#define FL_ERR_INVAL			8
+#define FL_ERR_ALIGN			16
+#define FL_ERR_UNKNOWN_FLASH_VENDOR	32
+#define FL_ERR_UNKNOWN_FLASH_TYPE	64
+#define FL_ERR_PROG_ERROR		128
+#define FL_ERR_ABORTED			256
 
 /*-----------------------------------------------------------------------
  * Protection Flags for flash_protect():
Signature · 1 line
2.40.1
Reviewed-by on v4 1/14
#2 lore raw

Re: [PATCH v4 01/14] flash: prefix error codes with FL_

Quoted 6 lines · Jerome Forissier

Prefix the flash status codes (ERR_*) with FL_ in order to avoid clashes with third-party libraries. Case in point: including the lwIP library header file <lwip/err.h> which defines err_enum_t as an enum with values being ERR_*.

Signature · 1 line
Tom
Reviewed-by on v4 1/14
#3 lore raw

Re: [PATCH v4 01/14] flash: prefix error codes with FL_

In reply to Jerome Forissier
Quoted 434 lines · Jerome Forissier

Prefix the flash status codes (ERR_*) with FL_ in order to avoid clashes with third-party libraries. Case in point: including the lwIP library header file <lwip/err.h> which defines err_enum_t as an enum with values being ERR_*.

---
 board/cobra5272/flash.c           | 26 +++++++++---------
 board/freescale/m5253demo/flash.c |  6 ++---
 common/flash.c                    | 44 +++++++++++++++----------------
 drivers/mtd/cfi_flash.c           | 36 ++++++++++++-------------
 include/flash.h                   | 20 +++++++-------
 5 files changed, 66 insertions(+), 66 deletions(-)
board/cobra5272/flash.c +13 -13
index 8416af163ad..6464975f184 100644
@@ -134,22 +134,22 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 {
        ulong result;
        int iflag, cflag, prot, sect;
-       int rc = ERR_OK;
+       int rc = FL_ERR_OK;
        int chip1;
        ulong start;
 
        /* first look for protection bits */
 
        if (info->flash_id == FLASH_UNKNOWN)
-               return ERR_UNKNOWN_FLASH_TYPE;
+               return FL_ERR_UNKNOWN_FLASH_TYPE;
 
        if ((s_first < 0) || (s_first > s_last)) {
-               return ERR_INVAL;
+               return FL_ERR_INVAL;
        }
 
        if ((info->flash_id & FLASH_VENDMASK) !=
            (AMD_MANUFACT & FLASH_VENDMASK)) {
-               return ERR_UNKNOWN_FLASH_VENDOR;
+               return FL_ERR_UNKNOWN_FLASH_VENDOR;
        }
 
        prot = 0;
@@ -159,7 +159,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
                }
        }
        if (prot)
-               return ERR_PROTECTED;
+               return FL_ERR_PROTECTED;
 
        /*
         * Disable interrupts which might cause a timeout
@@ -216,11 +216,11 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
                        MEM_FLASH_ADDR1 = CMD_READ_ARRAY;
 
                        if (chip1 == ERR) {
-                               rc = ERR_PROG_ERROR;
+                               rc = FL_ERR_PROG_ERROR;
                                goto outahere;
                        }
                        if (chip1 == TMO) {
-                               rc = ERR_TIMEOUT;
+                               rc = FL_ERR_TIMEOUT;
                                goto outahere;
                        }
 
@@ -251,7 +251,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
 {
        volatile u16 *addr = (volatile u16 *) dest;
        ulong result;
-       int rc = ERR_OK;
+       int rc = FL_ERR_OK;
        int cflag, iflag;
        int chip1;
        ulong start;
@@ -261,7 +261,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
         */
        result = *addr;
        if ((result & data) != data)
-               return ERR_NOT_ERASED;
+               return FL_ERR_NOT_ERASED;
 
 
        /*
@@ -302,7 +302,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data)
        *addr = CMD_READ_ARRAY;
 
        if (chip1 == ERR || *addr != data)
-               rc = ERR_PROG_ERROR;
+               rc = FL_ERR_PROG_ERROR;
 
        if (iflag)
                enable_interrupts();
@@ -321,13 +321,13 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 
        if (addr & 1) {
                printf ("unaligned destination not supported\n");
-               return ERR_ALIGN;
+               return FL_ERR_ALIGN;
        }
 
 #if 0
        if (cnt & 1) {
                printf ("odd transfer sizes not supported\n");
-               return ERR_ALIGN;
+               return FL_ERR_ALIGN;
        }
 #endif
 
@@ -365,5 +365,5 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
                cnt -= 1;
        }
 
-       return ERR_OK;
+       return FL_ERR_OK;
 }
board/freescale/m5253demo/flash.c +3 -3
index eeb9cfd3125..b6b7df88761 100644
@@ -71,7 +71,7 @@ int flash_get_offsets(ulong base, flash_info_t * info)
                }
        }
 
-       return ERR_OK;
+       return FL_ERR_OK;
 }
 
 void flash_print_info(flash_info_t * info)
@@ -368,9 +368,9 @@ int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
        }
 
        if (cnt == 0)
-               return ERR_OK;
+               return FL_ERR_OK;
 
-       return ERR_OK;
+       return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
common/flash.c +22 -22
index 848f44e59df..99fd84e2aef 100644
@@ -110,13 +110,13 @@ addr2info(ulong addr)
  * Make sure all target addresses are within Flash bounds,
  * and no protected sectors are hit.
  * Returns:
- * ERR_OK          0 - OK
- * ERR_TIMEOUT     1 - write timeout
- * ERR_NOT_ERASED  2 - Flash not erased
- * ERR_PROTECTED   4 - target range includes protected sectors
- * ERR_INVAL       8 - target address not in Flash memory
- * ERR_ALIGN       16 - target address not aligned on boundary
- *                     (only some targets require alignment)
+ * FL_ERR_OK          0 - OK
+ * FL_ERR_TIMEOUT     1 - write timeout
+ * FL_ERR_NOT_ERASED  2 - Flash not erased
+ * FL_ERR_PROTECTED   4 - target range includes protected sectors
+ * FL_ERR_INVAL       8 - target address not in Flash memory
+ * FL_ERR_ALIGN       16 - target address not aligned on boundary
+ *                        (only some targets require alignment)
  */
 int
 flash_write(char *src, ulong addr, ulong cnt)
@@ -131,11 +131,11 @@ flash_write(char *src, ulong addr, ulong cnt)
        __maybe_unused ulong cnt_orig = cnt;
 
        if (cnt == 0) {
-               return (ERR_OK);
+               return (FL_ERR_OK);
        }
 
        if (!info_first || !info_last) {
-               return (ERR_INVAL);
+               return (FL_ERR_INVAL);
        }
 
        for (info = info_first; info <= info_last; ++info) {
@@ -146,7 +146,7 @@ flash_write(char *src, ulong addr, ulong cnt)
 
                        if ((end >= info->start[i]) && (addr < e_addr) &&
                            (info->protect[i] != 0) ) {
-                               return (ERR_PROTECTED);
+                               return (FL_ERR_PROTECTED);
                        }
                }
        }
@@ -169,11 +169,11 @@ flash_write(char *src, ulong addr, ulong cnt)
 #if defined(CONFIG_FLASH_VERIFY)
        if (memcmp(src_orig, addr_orig, cnt_orig)) {
                printf("\nVerify failed!\n");
-               return ERR_PROG_ERROR;
+               return FL_ERR_PROG_ERROR;
        }
 #endif /* CONFIG_SYS_FLASH_VERIFY_AFTER_WRITE */
 
-       return (ERR_OK);
+       return (FL_ERR_OK);
 }
 
 /*-----------------------------------------------------------------------
@@ -182,33 +182,33 @@ flash_write(char *src, ulong addr, ulong cnt)
 void flash_perror(int err)
 {
        switch (err) {
-       case ERR_OK:
+       case FL_ERR_OK:
                break;
-       case ERR_TIMEOUT:
+       case FL_ERR_TIMEOUT:
                puts ("Timeout writing to Flash\n");
                break;
-       case ERR_NOT_ERASED:
+       case FL_ERR_NOT_ERASED:
                puts ("Flash not Erased\n");
                break;
-       case ERR_PROTECTED:
+       case FL_ERR_PROTECTED:
                puts ("Can't write to protected Flash sectors\n");
                break;
-       case ERR_INVAL:
+       case FL_ERR_INVAL:
                puts ("Outside available Flash\n");
                break;
-       case ERR_ALIGN:
+       case FL_ERR_ALIGN:
                puts ("Start and/or end address not on sector boundary\n");
                break;
-       case ERR_UNKNOWN_FLASH_VENDOR:
+       case FL_ERR_UNKNOWN_FLASH_VENDOR:
                puts ("Unknown Vendor of Flash\n");
                break;
-       case ERR_UNKNOWN_FLASH_TYPE:
+       case FL_ERR_UNKNOWN_FLASH_TYPE:
                puts ("Unknown Type of Flash\n");
                break;
-       case ERR_PROG_ERROR:
+       case FL_ERR_PROG_ERROR:
                puts ("General Flash Programming Error\n");
                break;
-       case ERR_ABORTED:
+       case FL_ERR_ABORTED:
                puts("Flash Programming Aborted\n");
                break;
        default:
drivers/mtd/cfi_flash.c +18 -18
index 8ade7949a68..6369c7127c6 100644
@@ -592,11 +592,11 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector,
                               flash_read_long(info, sector, 0));
                        flash_write_cmd(info, sector, 0, info->cmd_reset);
                        udelay(1);
-                       return ERR_TIMEOUT;
+                       return FL_ERR_TIMEOUT;
                }
                udelay(1);              /* also triggers watchdog */
        }
-       return ERR_OK;
+       return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
@@ -615,9 +615,9 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector,
        case CFI_CMDSET_INTEL_PROG_REGIONS:
        case CFI_CMDSET_INTEL_EXTENDED:
        case CFI_CMDSET_INTEL_STANDARD:
-               if (retcode == ERR_OK &&
+               if (retcode == FL_ERR_OK &&
                    !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) {
-                       retcode = ERR_INVAL;
+                       retcode = FL_ERR_INVAL;
                        printf("Flash %s error at address %lx\n", prompt,
                               info->start[sector]);
                        if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS |
@@ -626,14 +626,14 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector,
                        } else if (flash_isset(info, sector, 0,
                                                FLASH_STATUS_ECLBS)) {
                                puts("Block Erase Error.\n");
-                               retcode = ERR_NOT_ERASED;
+                               retcode = FL_ERR_NOT_ERASED;
                        } else if (flash_isset(info, sector, 0,
                                                FLASH_STATUS_PSLBS)) {
                                puts("Locking Error\n");
                        }
                        if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) {
                                puts("Block locked.\n");
-                               retcode = ERR_PROTECTED;
+                               retcode = FL_ERR_PROTECTED;
                        }
                        if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS))
                                puts("Vpp Low Error.\n");
@@ -701,12 +701,12 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst,
                if (get_timer(start) > tout) {
                        printf("Flash %s timeout at address %lx data %lx\n",
                               prompt, (ulong)dst, (ulong)flash_read8(dst));
-                       return ERR_TIMEOUT;
+                       return FL_ERR_TIMEOUT;
                }
                udelay(1);              /* also triggers watchdog */
        }
 #endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */
-       return ERR_OK;
+       return FL_ERR_OK;
 }
 
 /*-----------------------------------------------------------------------
@@ -809,7 +809,7 @@ static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword)
                break;
        }
        if (!flag)
-               return ERR_NOT_ERASED;
+               return FL_ERR_NOT_ERASED;
 
        /* Disable interrupts which might cause a timeout here */
        flag = disable_interrupts();
@@ -898,7 +898,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
                shift = 3;
                break;
        default:
-               retcode = ERR_INVAL;
+               retcode = FL_ERR_INVAL;
                goto out_unmap;
        }
 
@@ -929,7 +929,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
                }
        }
        if (!flag) {
-               retcode = ERR_NOT_ERASED;
+               retcode = FL_ERR_NOT_ERASED;
                goto out_unmap;
        }
 
@@ -949,7 +949,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
                retcode = flash_status_check(info, sector,
                                             info->buffer_write_tout,
                                             "write to buffer");
-               if (retcode == ERR_OK) {
+               if (retcode == FL_ERR_OK) {
                        /* reduce the number of loops by the width of
                         * the port
                         */
@@ -974,7 +974,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
                                        src += 8, dst += 8;
                                        break;
                                default:
-                                       retcode = ERR_INVAL;
+                                       retcode = FL_ERR_INVAL;
                                        goto out_unmap;
                                }
                        }
@@ -1024,7 +1024,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
                        }
                        break;
                default:
-                       retcode = ERR_INVAL;
+                       retcode = FL_ERR_INVAL;
                        goto out_unmap;
                }
 
@@ -1042,7 +1042,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp,
 
        default:
                debug("Unknown Command Set\n");
-               retcode = ERR_INVAL;
+               retcode = FL_ERR_INVAL;
                break;
        }
 
@@ -1388,7 +1388,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
                if (i > cnt)
                        i = cnt;
                rc = flash_write_cfibuffer(info, wp, src, i);
-               if (rc != ERR_OK)
+               if (rc != FL_ERR_OK)
                        return rc;
                i -= i & (info->portwidth - 1);
                wp += i;
@@ -1397,7 +1397,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
                FLASH_SHOW_PROGRESS(scale, dots, digit, i);
                /* Only check every once in a while */
                if ((cnt & 0xFFFF) < buffered_size && ctrlc())
-                       return ERR_ABORTED;
+                       return FL_ERR_ABORTED;
        }
 #else
        while (cnt >= info->portwidth) {
@@ -1412,7 +1412,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
                FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth);
                /* Only check every once in a while */
                if ((cnt & 0xFFFF) < info->portwidth && ctrlc())
-                       return ERR_ABORTED;
+                       return FL_ERR_ABORTED;
        }
 #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
 
include/flash.h +10 -11
index 3710a2731b7..77bee42f76b 100644
@@ -125,16 +125,16 @@ void flash_perror(int err);
 /*-----------------------------------------------------------------------
  * return codes from flash_write():
  */
-#define ERR_OK                         0
-#define ERR_TIMEOUT                    1
-#define ERR_NOT_ERASED                 2
-#define ERR_PROTECTED                  4
-#define ERR_INVAL                      8
-#define ERR_ALIGN                      16
-#define ERR_UNKNOWN_FLASH_VENDOR       32
-#define ERR_UNKNOWN_FLASH_TYPE         64
-#define ERR_PROG_ERROR                 128
-#define ERR_ABORTED                    256
+#define FL_ERR_OK                      0
+#define FL_ERR_TIMEOUT                 1
+#define FL_ERR_NOT_ERASED              2
+#define FL_ERR_PROTECTED               4
+#define FL_ERR_INVAL                   8
+#define FL_ERR_ALIGN                   16
+#define FL_ERR_UNKNOWN_FLASH_VENDOR    32
+#define FL_ERR_UNKNOWN_FLASH_TYPE      64
+#define FL_ERR_PROG_ERROR              128
+#define FL_ERR_ABORTED                 256
 
 /*-----------------------------------------------------------------------
  * Protection Flags for flash_protect():
--
Quoted 2 lines

2.40.1

#4 lore raw

PATCH v4 2/14 net: introduce alternative implementation as net-lwip/

In reply to Jerome Forissier

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 and FASTBOOT are not compatible with NET_LWIP because of dependencies on net_loop(), tftp_timeout_ms, tftp_timeout_count_max and other NET things. Let's add a dependency on !NET_LWIP for now.

As for SANDBOX, NET_LWIP cannot be used either because of strong assumptions on the network stack. Make NET_LWIP depend on !SANDBOX so that the NET_LWIP alternative is not visible in make menuconfig when sandbox_defconfig is used.

---
 Kconfig                    | 41 ++++++++++++++++++++++++++++++++++++++
 Makefile                   |  2 +-
 common/Kconfig             |  2 +-
 common/spl/Kconfig         |  1 +
 drivers/dfu/Kconfig        |  1 +
 drivers/fastboot/Kconfig   |  1 +
 drivers/net/Kconfig        |  1 +
 drivers/net/phy/Kconfig    |  2 +-
 drivers/usb/gadget/Kconfig |  2 +-
 net-lwip/Kconfig           | 37 ++++++++++++++++++++++++++++++++++
 net/Kconfig                | 14 -------------
 11 files changed, 86 insertions(+), 18 deletions(-)
 create mode 100644 net-lwip/Kconfig
Kconfig +41 -0
index 82df59f176e..cfe2a6d3eac 100644
@@ -745,7 +745,48 @@ 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
+	depends on !SANDBOX
+	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 -0
index 0360d9da142..6405a23574e 100644
@@ -20,6 +20,7 @@ config DFU_WRITE_ALT
 config DFU_TFTP
 	bool "DFU via TFTP"
 	depends on NETDEVICES
+	depends on !NET_LWIP
 	select UPDATE_COMMON
 	select DFU_OVER_TFTP
 	help
drivers/fastboot/Kconfig +1 -0
index 70207573de2..1eb460f5a02 100644
@@ -1,5 +1,6 @@
 menu "Fastboot support"
 	depends on CMDLINE
+	depends on !NET_LWIP
 
 config FASTBOOT
 	bool
drivers/net/Kconfig +1 -0
index b2d7b499766..efc55e45ca8 100644
@@ -48,6 +48,7 @@ config DM_DSA
 	bool "Enable Driver Model for DSA switches"
 	depends on DM_MDIO
 	depends on PHY_FIXED
+	depends on !NET_LWIP
 	help
 	  Enable driver model for DSA switches
 
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
#5 lore raw

Re: [PATCH v4 02/14] net: introduce alternative implementation as net-lwip/

Quoted 20 lines · Jerome Forissier

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 and FASTBOOT are not compatible with NET_LWIP because of dependencies on net_loop(), tftp_timeout_ms, tftp_timeout_count_max and other NET things. Let's add a dependency on !NET_LWIP for now.

As for SANDBOX, NET_LWIP cannot be used either because of strong assumptions on the network stack. Make NET_LWIP depend on !SANDBOX so that the NET_LWIP alternative is not visible in make menuconfig when sandbox_defconfig is used.

[snip]

Quoted 23 lines
Kconfig +15 -0
index 82df59f176e..cfe2a6d3eac 100644
@@ -745,7 +745,48 @@ 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
+	depends on !SANDBOX

Kconfig source "dts/Kconfig" · line 772

Quoted 10 lines
Kconfig +10 -0
+	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

For ease of reviewability the next patch in the series should change all of the configs with '# CONFIG_NET is not set' to 'CONFIG_NO_NET=y' so that they functionally don't change. It's 105 files and so while it will be folded in when lwIP is ready for merge, keeping it separate for now will make review easier.

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH v4 02/14] net: introduce alternative implementation as net-lwip/

Quoted 54 lines · Tom Rini
Quoted 20 lines · Jerome Forissier

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 and FASTBOOT are not compatible with NET_LWIP because of dependencies on net_loop(), tftp_timeout_ms, tftp_timeout_count_max and other NET things. Let's add a dependency on !NET_LWIP for now.

As for SANDBOX, NET_LWIP cannot be used either because of strong assumptions on the network stack. Make NET_LWIP depend on !SANDBOX so that the NET_LWIP alternative is not visible in make menuconfig when sandbox_defconfig is used.

[snip]

Quoted 31 lines
Kconfig +23 -0
index 82df59f176e..cfe2a6d3eac 100644
@@ -745,7 +745,48 @@ 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
+	depends on !SANDBOX
+	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.
Quoted 8 lines

Kconfig source "dts/Kconfig" · line 772

Quoted 2 lines
Kconfig +2 -0
+
+endchoice

For ease of reviewability the next patch in the series should change all of the configs with '# CONFIG_NET is not set' to 'CONFIG_NO_NET=y' so that they functionally don't change. It's 105 files and so while it will be folded in when lwIP is ready for merge, keeping it separate for now will make review easier.

OK, done in v6.

Thanks,

Signature · 1 line
Jerome
#7 lore raw

PATCH v4 3/14 net: split include/net.h into net{, -common, -legacy, -lwip}.h

In reply to Jerome Forissier

Make net.h a wrapper which includes net-common.h and either net-legacy.h or net-lwip.h based on NET_LWIP.

---
 Makefile             |   4 +-
 include/net-common.h | 408 +++++++++++++++++++
 include/net-legacy.h | 649 +++++++++++++++++++++++++++++
 include/net-lwip.h   |  14 +
 include/net.h        | 944 +------------------------------------------
 5 files changed, 1078 insertions(+), 941 deletions(-)
 create mode 100644 include/net-common.h
 create mode 100644 include/net-legacy.h
 create mode 100644 include/net-lwip.h
Makefile +3 -1
index ceb99a2698e..0fe1623c550 100644
@@ -836,7 +836,9 @@ UBOOTINCLUDE    := \
 			-I$(srctree)/arch/arm/thumb1/include)) \
 	-I$(srctree)/arch/$(ARCH)/include \
 	-include $(srctree)/include/linux/kconfig.h \
-	-I$(srctree)/dts/upstream/include
+	-I$(srctree)/dts/upstream/include \
+	$(if $(CONFIG_NET_LWIP), -I$(srctree)/lib/lwip/lwip/src/include \
+		-I$(srctree)/lib/lwip/u-boot)
 
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
 
include/net-common.h new file +408 -0

408 lines not on this page · raw message

include/net-legacy.h new file +649 -0

649 lines not on this page · raw message

include/net-lwip.h new file +14 -0
new file mode 100644
index 00000000000..f5c743b8d11
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __NET_LWIP_H__
+#define __NET_LWIP_H__
+
+#include <lwip/ip4.h>
+#include <lwip/netif.h>
+
+struct netif *net_lwip_new_netif(void);
+struct netif *net_lwip_new_netif_noip(void);
+void net_lwip_remove_netif(struct netif *netif);
+struct netif *net_lwip_get_netif(void);
+
+#endif /* __NET_LWIP_H__ */
include/net.h +4 -940

954 lines not on this page · raw message

Signature · 1 line
2.40.1
#8 lore raw

PATCH v4 4/14 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               |  55 +++++++++
 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, 297 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 +55 -0

55 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
#9 lore raw

PATCH v4 5/14 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. CMD_TFTPBOOT is selected by BOOTMETH_EFI due to this code having an implicit dependency on do_tftpb().

---
 Makefile                |   6 +
 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      |   2 +
 net-lwip/Makefile       |  15 +++
 net-lwip/dhcp.c         |  99 +++++++++++++++
 net-lwip/eth_internal.h |  35 ++++++
 net-lwip/net-lwip.c     | 270 ++++++++++++++++++++++++++++++++++++++++
 net-lwip/tftp.c         |  11 ++
 13 files changed, 486 insertions(+), 4 deletions(-)
 create mode 100644 cmd/net-lwip.c
 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 +6 -0
index 0fe1623c550..92a0ab770bb 100644
@@ -862,6 +862,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/
@@ -2132,6 +2133,11 @@ etags:
 cscope:
 		$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
 						cscope.files
+ifdef CONFIG_NET_LWIP
+		echo net/eth-uclass.c net/eth_common.c net/eth_bootdev.c \
+		     net/mdio-uclass.c net/mdio-mux-uclass.c >> \
+						cscope.files
+endif
 		@find $(TAG_SUBDIRS) -name '*.[chS]' -type l -print | \
 			grep -xvf - cscope.files > cscope.files.no-symlinks; \
 		mv cscope.files.no-symlinks cscope.files
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..82edb5fd2e6
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+#if defined(CONFIG_CMD_DHCP)
+U_BOOT_CMD(
+        dhcp,   3,      1,      do_dhcp,
+        "boot image via network using DHCP/TFTP protocol",
+        "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
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 efc55e45ca8..640c4218518 100644
@@ -97,7 +97,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 +2 -0
index f5c743b8d11..46cf6875f7e 100644
@@ -11,4 +11,6 @@ struct netif *net_lwip_new_netif_noip(void);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 
+int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+
 #endif /* __NET_LWIP_H__ */
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 +99 -0

99 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 +270 -0

270 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
#10 lore raw

Re: [PATCH v4 05/14] net-lwip: add DHCP support and dhcp commmand

Quoted 486 lines · Jerome Forissier

Add what it takes to enable NETDEVICES with NET_LWIP and enable DHCP as well as the dhcp command. CMD_TFTPBOOT is selected by BOOTMETH_EFI due to this code having an implicit dependency on do_tftpb().

---
  Makefile                |   6 +
  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      |   2 +
  net-lwip/Makefile       |  15 +++
  net-lwip/dhcp.c         |  99 +++++++++++++++
  net-lwip/eth_internal.h |  35 ++++++
  net-lwip/net-lwip.c     | 270 ++++++++++++++++++++++++++++++++++++++++
  net-lwip/tftp.c         |  11 ++
  13 files changed, 486 insertions(+), 4 deletions(-)

create mode 100644 cmd/net-lwip.c
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 +6 -0
index 0fe1623c550..92a0ab770bb 100644
@@ -862,6 +862,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/
@@ -2132,6 +2133,11 @@ etags:
  cscope:
  		$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
  						cscope.files
+ifdef CONFIG_NET_LWIP
+		echo net/eth-uclass.c net/eth_common.c net/eth_bootdev.c \
+		     net/mdio-uclass.c net/mdio-mux-uclass.c >> \
+						cscope.files
+endif
  		@find $(TAG_SUBDIRS) -name '*.[chS]' -type l -print | \
  			grep -xvf - cscope.files > cscope.files.no-symlinks; \
  		mv cscope.files.no-symlinks cscope.files
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..82edb5fd2e6
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+#if defined(CONFIG_CMD_DHCP)
+U_BOOT_CMD(
+        dhcp,   3,      1,      do_dhcp,
+        "boot image via network using DHCP/TFTP protocol",
+        "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
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 efc55e45ca8..640c4218518 100644
@@ -97,7 +97,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 +2 -0
index f5c743b8d11..46cf6875f7e 100644
@@ -11,4 +11,6 @@ struct netif *net_lwip_new_netif_noip(void);
  void net_lwip_remove_netif(struct netif *netif);
  struct netif *net_lwip_get_netif(void);
 
+int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+
  #endif /* __NET_LWIP_H__ */
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 +99 -0
new file mode 100644
index 00000000000..38ea565508f
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <console.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <lwip/dhcp.h>
+#include <lwip/dns.h>
+#include <lwip/timeouts.h>
+#include <net.h>
+#include <time.h>
+
+#define DHCP_TIMEOUT_MS 10000
+
+#ifdef CONFIG_CMD_TFTPBOOT
+/* Boot file obtained from DHCP (if present) */
+static char boot_file_name[DHCP_BOOT_FILE_LEN];
+#endif
+
+static void call_lwip_dhcp_fine_tmr(void *ctx)
+{
+	dhcp_fine_tmr();
+	sys_timeout(10, call_lwip_dhcp_fine_tmr, NULL);
+}
+
+int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	unsigned long start;
+	struct netif *netif;
+	struct dhcp *dhcp;
+	bool bound;
+
+	netif = net_lwip_new_netif_noip();
+	if (!netif)
+		return CMD_RET_FAILURE;
+
+	start = get_timer(0);
+	dhcp_start(netif);
+	call_lwip_dhcp_fine_tmr(NULL);
+
+	/* Wait for DHCP to complete */
+	do {
+		eth_rx();
+		sys_check_timeouts();
+		bound = dhcp_supplied_address(netif);
+		if (bound)
+			break;
+		if (ctrlc()) {
+			printf("Abort\n");
+			break;
+		}
+		mdelay(1);
+	} while (get_timer(start) < DHCP_TIMEOUT_MS);
+
+	sys_untimeout(call_lwip_dhcp_fine_tmr, NULL);
+
+	if (!bound) {
+		net_lwip_remove_netif(netif);
+		return CMD_RET_FAILURE;
+	}
+
+	dhcp = netif_dhcp_data(netif);
+
+	env_set("bootfile", dhcp->boot_file_name);
+	if (dhcp->offered_gw_addr.addr != 0)
+		env_set("gatewayip", ip4addr_ntoa(&dhcp->offered_gw_addr));
+	env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr));
+	env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask));
+	env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
+#ifdef CONFIG_PROT_DNS_LWIP
+	env_set("dnsip", ip4addr_ntoa(dns_getserver(0)));
+	env_set("dnsip2", ip4addr_ntoa(dns_getserver(1)));
+#endif
+#ifdef CONFIG_CMD_TFTPBOOT
+	if (dhcp->boot_file_name[0] != '\0')
+		strncpy(boot_file_name, dhcp->boot_file_name,
+			sizeof(boot_file_name));
+#endif
+
+	printf("DHCP client bound to address %pI4 (%lu ms)\n",
+	       &dhcp->offered_ip_addr, get_timer(start));
+
+	net_lwip_remove_netif(netif);
+	return CMD_RET_SUCCESS;
+}
+
+int dhcp_run(ulong addr, const char *fname, bool autoload)
+{
+	char *dhcp_argv[] = {"dhcp", NULL, };
+	struct cmd_tbl cmdtp = {};	/* dummy */
+
+	if (autoload) {
+		/* Will be supported when TFTP is added */
+		return -EOPNOTSUPP;
+	}
+
+	return do_dhcp(&cmdtp, 0, 1, dhcp_argv);
+}
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 +124 -0
new file mode 100644
index 00000000000..39e7e51e542
@@ -0,0 +1,270 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+#include <lwip/ip4_addr.h>
+#include <lwip/err.h>
+#include <lwip/netif.h>
+#include <lwip/pbuf.h>
+#include <lwip/etharp.h>
+#include <lwip/prot/etharp.h>
+#include <net.h>
+
+/* xx:xx:xx:xx:xx:xx\0 */
+#define MAC_ADDR_STRLEN 18
+
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
+void (*push_packet)(void *, int len) = 0;
+#endif
+int net_restart_wrap;
+static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+uchar *net_rx_packets[PKTBUFSRX];
+uchar *net_rx_packet;
+uchar *net_tx_packet;
+
+static err_t low_level_output(struct netif *netif, struct pbuf *p)
+{
+        int err;
+
+	/*
+	 * lwIP is alwys configured to use one device, the active one, so
+	 * there is no need to use the netif parameter.
+	 */
+
+        /* switch dev to active state */
+        eth_init_state_only();
+
+        err = eth_send(p->payload, p->len);
+        if (err) {
+                log_err("eth_send error %d\n", err);
+                return ERR_ABRT;
+        }
+        return ERR_OK;
+}
+
+static err_t net_lwip_if_init(struct netif *netif)
+{
+#if LWIP_IPV4
+	netif->output = etharp_output;
+#endif
+	netif->linkoutput = low_level_output;
+	netif->mtu = 1500;
+	netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
+
+	return ERR_OK;
+}
+
+static void eth_init_rings(void)
+{
+        static bool called;
+	int i;
+
+        if (called)
+		return;
+	called = true;
+
+	net_tx_packet = &net_pkt_buf[0] + (PKTALIGN - 1);
+	net_tx_packet -= (ulong)net_tx_packet % PKTALIGN;
+	for (i = 0; i < PKTBUFSRX; i++)
+		net_rx_packets[i] = net_tx_packet + (i + 1) * PKTSIZE_ALIGN;
+}
+
+struct netif *net_lwip_get_netif(void)
+{
+	struct netif *netif, *found = NULL;
+
+	NETIF_FOREACH(netif) {
+		if (!found)
+			found = netif;
+		else
+			printf("Error: more than one netif in lwIP\n");
+	}
+	return found;
+}
+
+static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
+			      ip4_addr_t *mask, ip4_addr_t *gw)
+{
+	char ipstr[9] = { 'i', 'p', 'a' , 'd', 'd', 'r', };
+	char maskstr[10] = { 'n', 'e', 't', 'm', 'a', 's', 'k', };
+	char gwstr[12] = { 'g', 'a', 't', 'e', 'w', 'a', 'y', 'i', 'p', };
+	char *env;
+	int ret;
+
+	if (dev_seq(dev) > 0) {
+		ret = snprintf(ipstr, sizeof(ipstr), "ipaddr%d", dev_seq(dev));
+		if (ret < 0 || ret >= sizeof(ipstr))
+			return -1;
+		snprintf(maskstr, sizeof(maskstr), "netmask%d", dev_seq(dev));
+		if (ret < 0 || ret >= sizeof(maskstr))
+			return -1;
+		snprintf(gwstr, sizeof(gwstr), "gw%d", dev_seq(dev));
+		if (ret < 0 || ret >= sizeof(gwstr))
+			return -1;
+	}
+
+	ip4_addr_set_zero(ip);
+	ip4_addr_set_zero(mask);
+	ip4_addr_set_zero(gw);
+
+	env = env_get(ipstr);
+	if (env)
+		ipaddr_aton(env, ip);
+
+	env = env_get(maskstr);
+	if (env)
+		ipaddr_aton(env, mask);
+
+	env = env_get(gwstr);
+	if (env)
+		ipaddr_aton(env, gw);
+

net-lwip/net-lwip.c line 134

Quoted 10 lines
net-lwip/net-lwip.c new file +10 -0
+	return 0;
+}
+
+static struct netif *new_netif(bool with_ip)
+{
+	unsigned char enetaddr[ARP_HLEN];
+	char hwstr[MAC_ADDR_STRLEN];
+	ip4_addr_t ip, mask, gw;
+	struct udevice *dev;
+	struct netif *netif;

This does not fit into the driver model.

In the EFI subsystem we want to implement network protocols like the EFI_DHCP4_PROTOCOL.

Please, carve out functions to which we can pass a UCLASS_ETH udevice to execute DHCP.

Quoted 97 lines
net-lwip/net-lwip.c new file +97 -0
+	int ret;
+	static bool first_call = true;
+
+	eth_init_rings();
+
+	if (first_call) {
+		if (eth_init()) {
+			printf("eth_init() error\n");
+			return NULL;
+		}
+		first_call = false;
+	}
+
+	netif_remove(net_lwip_get_netif());
+
+	eth_set_current();
+
+	dev = eth_get_dev();
+	if (!dev)
+		return NULL;
+
+	ip4_addr_set_zero(&ip);
+	ip4_addr_set_zero(&mask);
+	ip4_addr_set_zero(&gw);
+
+	if (with_ip)
+		if (get_udev_ipv4_info(dev, &ip, &mask, &gw) < 0)
+			return NULL;
+
+	eth_env_get_enetaddr_by_index("eth", dev_seq(dev), enetaddr);
+	ret = snprintf(hwstr, MAC_ADDR_STRLEN, "%pM",  enetaddr);
+	if (ret < 0 || ret >= MAC_ADDR_STRLEN)
+		return NULL;
+
+	netif = calloc(1, sizeof(struct netif));
+	if (!netif)
+		return NULL;
+
+	netif->name[0] = 'e';
+	netif->name[1] = 't';
+
+	string_to_enetaddr(hwstr, netif->hwaddr);
+	netif->hwaddr_len = ETHARP_HWADDR_LEN;
+
+	if (!netif_add(netif, &ip, &mask, &gw, netif, net_lwip_if_init,
+		       netif_input)) {
+		printf("error: netif_add() failed\n");
+		free(netif);
+		return NULL;
+	}
+
+	netif_set_up(netif);
+	netif_set_link_up(netif);
+	/* Routing: use this interface to reach the default gateway */
+	netif_set_default(netif);
+
+	return netif;
+}
+
+/* Configure lwIP to use the currently active network device */
+struct netif *net_lwip_new_netif()
+{
+	return new_netif(true);
+}
+
+struct netif *net_lwip_new_netif_noip()
+{
+
+	return new_netif(false);
+}
+
+void net_lwip_remove_netif(struct netif *netif)
+{
+	netif_remove(netif);
+	free(netif);
+}
+
+int net_init(void)
+{
+	net_lwip_new_netif();
+
+	return 0;
+}
+
+static struct pbuf *alloc_pbuf_and_copy(uchar *data, int len)
+{
+        struct pbuf *p, *q;
+
+        /* We allocate a pbuf chain of pbufs from the pool. */
+        p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
+        if (!p) {
+                LINK_STATS_INC(link.memerr);
+                LINK_STATS_INC(link.drop);
+                return NULL;
+        }
+
+        for (q = p; q != NULL; q = q->next) {

net-lwip/net-lwip.c line 241

Quoted 10 lines
net-lwip/net-lwip.c new file +10 -0
+                memcpy(q->payload, data, q->len);
+                data += q->len;
+        }
+
+        LINK_STATS_INC(link.recv);
+
+        return p;
+}
+
+void net_process_received_packet(uchar *in_packet, int len)

Library functions should take a udevice as an argument. Please, do not use the concept of "active device" in these library functions.

The command line interface may implement such a concept for backwards compatibility.

Best regards

Heinrich

Quoted 46 lines
net-lwip/net-lwip.c new file +29 -0
+{
+	struct netif *netif;
+	struct pbuf *pbuf;
+
+	if (len < ETHER_HDR_SIZE)
+		return;
+
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
+	if (push_packet) {
+		(*push_packet)(in_packet, len);
+		return;
+	}
+#endif
+
+	netif = net_lwip_get_netif();
+	if (!netif)
+		return;
+
+	pbuf = alloc_pbuf_and_copy(in_packet, len);
+	if (!pbuf)
+		return;
+
+	netif->input(pbuf, netif);
+}
+
+u32_t sys_now(void)
+{
+	return get_timer(0);
+}
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;
+}
#11 lore raw

Re: [PATCH v4 05/14] net-lwip: add DHCP support and dhcp commmand

Quoted 500 lines · Heinrich Schuchardt
Quoted 486 lines · Jerome Forissier

Add what it takes to enable NETDEVICES with NET_LWIP and enable DHCP as well as the dhcp command. CMD_TFTPBOOT is selected by BOOTMETH_EFI due to this code having an implicit dependency on do_tftpb().

---
  Makefile                |   6 +
  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      |   2 +
  net-lwip/Makefile       |  15 +++
  net-lwip/dhcp.c         |  99 +++++++++++++++ net-lwip/eth_internal.h |  35 ++++++
  net-lwip/net-lwip.c     | 270 ++++++++++++++++++++++++++++++++++++++++ net-lwip/tftp.c         |  11 ++

  13 files changed, 486 insertions(+), 4 deletions(-)

  create mode 100644 cmd/net-lwip.c
  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 +0 -0
index 0fe1623c550..92a0ab770bb 100644
@@ -862,6 +862,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/

Makefile +0 -0
@@ -2132,6 +2133,11 @@ etags:

  cscope:
          $(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
                          cscope.files

Makefile +5 -0
+ifdef CONFIG_NET_LWIP
+        echo net/eth-uclass.c net/eth_common.c net/eth_bootdev.c \
+             net/mdio-uclass.c net/mdio-mux-uclass.c >> \
+                        cscope.files
+endif

          @find $(TAG_SUBDIRS) -name '*.[chS]' -type l -print | \
              grep -xvf - cscope.files > cscope.files.no-symlinks; \
          mv cscope.files.no-symlinks cscope.files

boot/Kconfig +0 -0
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

boot/Kconfig +0 -0
@@ -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 +0 -0
index b026439c773..1bfa528e945 100644
@@ -2084,6 +2084,32 @@ config CMD_WOL
 

  endif

cmd/Kconfig +26 -0
+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 +0 -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

cmd/Makefile +4 -0
+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..82edb5fd2e6
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <net.h>
+
+#if defined(CONFIG_CMD_DHCP)
+U_BOOT_CMD(
+        dhcp,   3,      1,      do_dhcp,
+        "boot image via network using DHCP/TFTP protocol",
+        "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
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 +0 -0
index efc55e45ca8..640c4218518 100644
@@ -97,7 +97,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 +2 -0
index f5c743b8d11..46cf6875f7e 100644
@@ -11,4 +11,6 @@ struct netif *net_lwip_new_netif_noip(void);
   void net_lwip_remove_netif(struct netif *netif);
   struct netif *net_lwip_get_netif(void);
 
+int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+
   #endif /* __NET_LWIP_H__ */
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 +99 -0
new file mode 100644
index 00000000000..38ea565508f
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <console.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <lwip/dhcp.h>
+#include <lwip/dns.h>
+#include <lwip/timeouts.h>
+#include <net.h>
+#include <time.h>
+
+#define DHCP_TIMEOUT_MS 10000
+
+#ifdef CONFIG_CMD_TFTPBOOT
+/* Boot file obtained from DHCP (if present) */
+static char boot_file_name[DHCP_BOOT_FILE_LEN];
+#endif
+
+static void call_lwip_dhcp_fine_tmr(void *ctx)
+{
+    dhcp_fine_tmr();
+    sys_timeout(10, call_lwip_dhcp_fine_tmr, NULL);
+}
+
+int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+    unsigned long start;
+    struct netif *netif;
+    struct dhcp *dhcp;
+    bool bound;
+
+    netif = net_lwip_new_netif_noip();
+    if (!netif)
+        return CMD_RET_FAILURE;
+
+    start = get_timer(0);
+    dhcp_start(netif);
+    call_lwip_dhcp_fine_tmr(NULL);
+
+    /* Wait for DHCP to complete */
+    do {
+        eth_rx();
+        sys_check_timeouts();
+        bound = dhcp_supplied_address(netif);
+        if (bound)
+            break;
+        if (ctrlc()) {
+            printf("Abort\n");
+            break;
+        }
+        mdelay(1);
+    } while (get_timer(start) < DHCP_TIMEOUT_MS);
+
+    sys_untimeout(call_lwip_dhcp_fine_tmr, NULL);
+
+    if (!bound) {
+        net_lwip_remove_netif(netif);
+        return CMD_RET_FAILURE;
+    }
+
+    dhcp = netif_dhcp_data(netif);
+
+    env_set("bootfile", dhcp->boot_file_name);
+    if (dhcp->offered_gw_addr.addr != 0)
+        env_set("gatewayip", ip4addr_ntoa(&dhcp->offered_gw_addr));
+    env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr));
+    env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask));
+    env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
+#ifdef CONFIG_PROT_DNS_LWIP
+    env_set("dnsip", ip4addr_ntoa(dns_getserver(0)));
+    env_set("dnsip2", ip4addr_ntoa(dns_getserver(1)));
+#endif
+#ifdef CONFIG_CMD_TFTPBOOT
+    if (dhcp->boot_file_name[0] != '\0')
+        strncpy(boot_file_name, dhcp->boot_file_name,
+            sizeof(boot_file_name));
+#endif
+
+    printf("DHCP client bound to address %pI4 (%lu ms)\n",
+           &dhcp->offered_ip_addr, get_timer(start));
+
+    net_lwip_remove_netif(netif);
+    return CMD_RET_SUCCESS;
+}
+
+int dhcp_run(ulong addr, const char *fname, bool autoload)
+{
+    char *dhcp_argv[] = {"dhcp", NULL, };
+    struct cmd_tbl cmdtp = {};    /* dummy */
+
+    if (autoload) {
+        /* Will be supported when TFTP is added */
+        return -EOPNOTSUPP;
+    }
+
+    return do_dhcp(&cmdtp, 0, 1, dhcp_argv);
+}
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 +124 -0
new file mode 100644
index 00000000000..39e7e51e542
@@ -0,0 +1,270 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/* Copyright (C) 2024 Linaro Ltd. */
+
+#include <command.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+#include <lwip/ip4_addr.h>
+#include <lwip/err.h>
+#include <lwip/netif.h>
+#include <lwip/pbuf.h>
+#include <lwip/etharp.h>
+#include <lwip/prot/etharp.h>
+#include <net.h>
+
+/* xx:xx:xx:xx:xx:xx\0 */
+#define MAC_ADDR_STRLEN 18
+
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
+void (*push_packet)(void *, int len) = 0;
+#endif
+int net_restart_wrap;
+static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+uchar *net_rx_packets[PKTBUFSRX];
+uchar *net_rx_packet;
+uchar *net_tx_packet;
+
+static err_t low_level_output(struct netif *netif, struct pbuf *p)
+{
+        int err;
+
+    /*
+     * lwIP is alwys configured to use one device, the active one, so
+     * there is no need to use the netif parameter.
+     */
+
+        /* switch dev to active state */
+        eth_init_state_only();
+
+        err = eth_send(p->payload, p->len);
+        if (err) {
+                log_err("eth_send error %d\n", err);
+                return ERR_ABRT;
+        }
+        return ERR_OK;
+}
+
+static err_t net_lwip_if_init(struct netif *netif)
+{
+#if LWIP_IPV4
+    netif->output = etharp_output;
+#endif
+    netif->linkoutput = low_level_output;
+    netif->mtu = 1500;
+    netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
+
+    return ERR_OK;
+}
+
+static void eth_init_rings(void)
+{
+        static bool called;
+    int i;
+
+        if (called)
+        return;
+    called = true;
+
+    net_tx_packet = &net_pkt_buf[0] + (PKTALIGN - 1);
+    net_tx_packet -= (ulong)net_tx_packet % PKTALIGN;
+    for (i = 0; i < PKTBUFSRX; i++)
+        net_rx_packets[i] = net_tx_packet + (i + 1) * PKTSIZE_ALIGN;
+}
+
+struct netif *net_lwip_get_netif(void)
+{
+    struct netif *netif, *found = NULL;
+
+    NETIF_FOREACH(netif) {
+        if (!found)
+            found = netif;
+        else
+            printf("Error: more than one netif in lwIP\n");
+    }
+    return found;
+}
+
+static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
+                  ip4_addr_t *mask, ip4_addr_t *gw)
+{
+    char ipstr[9] = { 'i', 'p', 'a' , 'd', 'd', 'r', };
+    char maskstr[10] = { 'n', 'e', 't', 'm', 'a', 's', 'k', };
+    char gwstr[12] = { 'g', 'a', 't', 'e', 'w', 'a', 'y', 'i', 'p', };
+    char *env;
+    int ret;
+
+    if (dev_seq(dev) > 0) {
+        ret = snprintf(ipstr, sizeof(ipstr), "ipaddr%d", dev_seq(dev));
+        if (ret < 0 || ret >= sizeof(ipstr))
+            return -1;
+        snprintf(maskstr, sizeof(maskstr), "netmask%d", dev_seq(dev));
+        if (ret < 0 || ret >= sizeof(maskstr))
+            return -1;
+        snprintf(gwstr, sizeof(gwstr), "gw%d", dev_seq(dev));
+        if (ret < 0 || ret >= sizeof(gwstr))
+            return -1;
+    }
+
+    ip4_addr_set_zero(ip);
+    ip4_addr_set_zero(mask);
+    ip4_addr_set_zero(gw);
+
+    env = env_get(ipstr);
+    if (env)
+        ipaddr_aton(env, ip);
+
+    env = env_get(maskstr);
+    if (env)
+        ipaddr_aton(env, mask);
+
+    env = env_get(gwstr);
+    if (env)
+        ipaddr_aton(env, gw);
+

net-lwip/net-lwip.c line 134

Quoted 10 lines
net-lwip/net-lwip.c new file +10 -0
+    return 0;
+}
+
+static struct netif *new_netif(bool with_ip)
+{
+    unsigned char enetaddr[ARP_HLEN];
+    char hwstr[MAC_ADDR_STRLEN];
+    ip4_addr_t ip, mask, gw;
+    struct udevice *dev;
+    struct netif *netif;

This does not fit into the driver model.

Quoted 5 lines

In the EFI subsystem we want to implement network protocols like the EFI_DHCP4_PROTOCOL.

Please, carve out functions to which we can pass a UCLASS_ETH udevice to execute DHCP.

v6 will have:

static struct netif *new_netif(struct udevice *udev, bool with_ip) struct netif *net_lwip_new_netif(struct udevice *udev) struct netif *net_lwip_new_netif_noip(struct udevice *udev)

static int dhcp_loop(struct udevice *udev)

Quoted 103 lines
Quoted 103 lines
net-lwip/net-lwip.c new file +102 -0
+    int ret;
+    static bool first_call = true;
+
+    eth_init_rings();
+
+    if (first_call) {
+        if (eth_init()) {
+            printf("eth_init() error\n");
+            return NULL;
+        }
+        first_call = false;
+    }
+
+    netif_remove(net_lwip_get_netif());
+
+    eth_set_current();
+
+    dev = eth_get_dev();
+    if (!dev)
+        return NULL;
+
+    ip4_addr_set_zero(&ip);
+    ip4_addr_set_zero(&mask);
+    ip4_addr_set_zero(&gw);
+
+    if (with_ip)
+        if (get_udev_ipv4_info(dev, &ip, &mask, &gw) < 0)
+            return NULL;
+
+    eth_env_get_enetaddr_by_index("eth", dev_seq(dev), enetaddr);
+    ret = snprintf(hwstr, MAC_ADDR_STRLEN, "%pM",  enetaddr);
+    if (ret < 0 || ret >= MAC_ADDR_STRLEN)
+        return NULL;
+
+    netif = calloc(1, sizeof(struct netif));
+    if (!netif)
+        return NULL;
+
+    netif->name[0] = 'e';
+    netif->name[1] = 't';
+
+    string_to_enetaddr(hwstr, netif->hwaddr);
+    netif->hwaddr_len = ETHARP_HWADDR_LEN;
+
+    if (!netif_add(netif, &ip, &mask, &gw, netif, net_lwip_if_init,
+               netif_input)) {
+        printf("error: netif_add() failed\n");
+        free(netif);
+        return NULL;
+    }
+
+    netif_set_up(netif);
+    netif_set_link_up(netif);
+    /* Routing: use this interface to reach the default gateway */
+    netif_set_default(netif);
+
+    return netif;
+}
+
+/* Configure lwIP to use the currently active network device */
+struct netif *net_lwip_new_netif()
+{
+    return new_netif(true);
+}
+
+struct netif *net_lwip_new_netif_noip()
+{
+
+    return new_netif(false);
+}
+
+void net_lwip_remove_netif(struct netif *netif)
+{
+    netif_remove(netif);
+    free(netif);
+}
+
+int net_init(void)
+{
+    net_lwip_new_netif();
+
+    return 0;
+}
+
+static struct pbuf *alloc_pbuf_and_copy(uchar *data, int len)
+{
+        struct pbuf *p, *q;
+
+        /* We allocate a pbuf chain of pbufs from the pool. */
+        p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
+        if (!p) {
+                LINK_STATS_INC(link.memerr);
+                LINK_STATS_INC(link.drop);
+                return NULL;
+        }
+
+        for (q = p; q != NULL; q = q->next) {
+                memcpy(q->payload, data, q->len);
+                data += q->len;
+        }
+
+        LINK_STATS_INC(link.recv);
Quoted 8 lines

net-lwip/net-lwip.c line 241

Quoted 5 lines
net-lwip/net-lwip.c new file +5 -0
+
+        return p;
+}
+
+void net_process_received_packet(uchar *in_packet, int len)

Library functions should take a udevice as an argument. Please, do not use the concept of "active device" in these library functions.

OK, I have unified the naming in v6 and all functions will take a udevice:

static int dhcp_loop(struct udevice *udev)
static int dns_loop(struct udevice *udev, const char *name, const char *var) static int ping_loop(struct udevice *udev, const ip_addr_t* addr) static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
ip_addr_t srvip)
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)

Quoted 3 lines

The command line interface may implement such a concept for backwards compatibility.

Sure.

Thanks,

Signature · 1 line
Jerome
Quoted 52 lines

Best regards

Heinrich

Quoted 46 lines
net-lwip/net-lwip.c new file +29 -0
+{
+    struct netif *netif;
+    struct pbuf *pbuf;
+
+    if (len < ETHER_HDR_SIZE)
+        return;
+
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
+    if (push_packet) {
+        (*push_packet)(in_packet, len);
+        return;
+    }
+#endif
+
+    netif = net_lwip_get_netif();
+    if (!netif)
+        return;
+
+    pbuf = alloc_pbuf_and_copy(in_packet, len);
+    if (!pbuf)
+        return;
+
+    netif->input(pbuf, netif);
+}
+
+u32_t sys_now(void)
+{
+    return get_timer(0);
+}
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;
+}
#12 lore raw

Re: [PATCH v4 05/14] net-lwip: add DHCP support and dhcp commmand

[...]

Quoted 14 lines
Quoted 14 lines

net-lwip/net-lwip.c line 134

Quoted 8 lines
net-lwip/net-lwip.c new file +8 -0
+
+static struct netif *new_netif(bool with_ip)
+{
+    unsigned char enetaddr[ARP_HLEN];
+    char hwstr[MAC_ADDR_STRLEN];
+    ip4_addr_t ip, mask, gw;
+    struct udevice *dev;
+    struct netif *netif;

This does not fit into the driver model.

In the EFI subsystem we want to implement network protocols like the EFI_DHCP4_PROTOCOL.

Quoted 8 lines
Quoted 2 lines

Please, carve out functions to which we can pass a UCLASS_ETH udevice to execute DHCP.

v6 will have:

static struct netif *new_netif(struct udevice *udev, bool with_ip) struct netif *net_lwip_new_netif(struct udevice *udev) struct netif *net_lwip_new_netif_noip(struct udevice *udev)

Heinrich, any other EFI protocols you have in mind that would require similar tweaking? e.g the EFI_TCP4 and HTTP protocols?

Quoted 186 lines

static int dhcp_loop(struct udevice *udev)

Quoted 103 lines
Quoted 103 lines
net-lwip/net-lwip.c new file +102 -0
+    int ret;
+    static bool first_call = true;
+
+    eth_init_rings();
+
+    if (first_call) {
+        if (eth_init()) {
+            printf("eth_init() error\n");
+            return NULL;
+        }
+        first_call = false;
+    }
+
+    netif_remove(net_lwip_get_netif());
+
+    eth_set_current();
+
+    dev = eth_get_dev();
+    if (!dev)
+        return NULL;
+
+    ip4_addr_set_zero(&ip);
+    ip4_addr_set_zero(&mask);
+    ip4_addr_set_zero(&gw);
+
+    if (with_ip)
+        if (get_udev_ipv4_info(dev, &ip, &mask, &gw) < 0)
+            return NULL;
+
+    eth_env_get_enetaddr_by_index("eth", dev_seq(dev), enetaddr);
+    ret = snprintf(hwstr, MAC_ADDR_STRLEN, "%pM",  enetaddr);
+    if (ret < 0 || ret >= MAC_ADDR_STRLEN)
+        return NULL;
+
+    netif = calloc(1, sizeof(struct netif));
+    if (!netif)
+        return NULL;
+
+    netif->name[0] = 'e';
+    netif->name[1] = 't';
+
+    string_to_enetaddr(hwstr, netif->hwaddr);
+    netif->hwaddr_len = ETHARP_HWADDR_LEN;
+
+    if (!netif_add(netif, &ip, &mask, &gw, netif, net_lwip_if_init,
+               netif_input)) {
+        printf("error: netif_add() failed\n");
+        free(netif);
+        return NULL;
+    }
+
+    netif_set_up(netif);
+    netif_set_link_up(netif);
+    /* Routing: use this interface to reach the default gateway */
+    netif_set_default(netif);
+
+    return netif;
+}
+
+/* Configure lwIP to use the currently active network device */
+struct netif *net_lwip_new_netif()
+{
+    return new_netif(true);
+}
+
+struct netif *net_lwip_new_netif_noip()
+{
+
+    return new_netif(false);
+}
+
+void net_lwip_remove_netif(struct netif *netif)
+{
+    netif_remove(netif);
+    free(netif);
+}
+
+int net_init(void)
+{
+    net_lwip_new_netif();
+
+    return 0;
+}
+
+static struct pbuf *alloc_pbuf_and_copy(uchar *data, int len)
+{
+        struct pbuf *p, *q;
+
+        /* We allocate a pbuf chain of pbufs from the pool. */
+        p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
+        if (!p) {
+                LINK_STATS_INC(link.memerr);
+                LINK_STATS_INC(link.drop);
+                return NULL;
+        }
+
+        for (q = p; q != NULL; q = q->next) {
+                memcpy(q->payload, data, q->len);
+                data += q->len;
+        }
+
+        LINK_STATS_INC(link.recv);
Quoted 8 lines

net-lwip/net-lwip.c line 241

Quoted 5 lines
net-lwip/net-lwip.c new file +5 -0
+
+        return p;
+}
+
+void net_process_received_packet(uchar *in_packet, int len)

Library functions should take a udevice as an argument. Please, do not use the concept of "active device" in these library functions.

OK, I have unified the naming in v6 and all functions will take a udevice:

static int dhcp_loop(struct udevice *udev)
static int dns_loop(struct udevice *udev, const char *name, const char *var) static int ping_loop(struct udevice *udev, const ip_addr_t* addr) static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
ip_addr_t srvip)
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)

Quoted 3 lines

The command line interface may implement such a concept for backwards compatibility.

Sure.

Thanks,
--
Jerome

Quoted 52 lines

Best regards

Heinrich

Quoted 46 lines
net-lwip/net-lwip.c new file +29 -0
+{
+    struct netif *netif;
+    struct pbuf *pbuf;
+
+    if (len < ETHER_HDR_SIZE)
+        return;
+
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
+    if (push_packet) {
+        (*push_packet)(in_packet, len);
+        return;
+    }
+#endif
+
+    netif = net_lwip_get_netif();
+    if (!netif)
+        return;
+
+    pbuf = alloc_pbuf_and_copy(in_packet, len);
+    if (!pbuf)
+        return;
+
+    netif->input(pbuf, netif);
+}
+
+u32_t sys_now(void)
+{
+    return get_timer(0);
+}
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;
+}
#13 lore raw

PATCH v4 6/14 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 | 221 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 237 insertions(+), 6 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 82edb5fd2e6..80f0872bb8f 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 38ea565508f..af8ac214e81 100644
@@ -88,11 +88,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 +218 -3

228 lines not on this page · raw message

Signature · 1 line
2.40.1
#14 lore raw

PATCH v4 7/14 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 |   1 +
 net-lwip/Makefile  |   1 +
 net-lwip/ping.c    | 174 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 191 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 80f0872bb8f..feed719beef 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 +1 -0
index 46cf6875f7e..b34f53b4891 100644
@@ -12,5 +12,6 @@ void net_lwip_remove_netif(struct netif *netif);
 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[]);
 
 #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 +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.40.1
#15 lore raw

PATCH v4 8/14 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     | 117 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 133 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 feed719beef..c021da6a674 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 b34f53b4891..4d41b0208a3 100644
@@ -12,6 +12,7 @@ void net_lwip_remove_netif(struct netif *netif);
 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[]);
 
 #endif /* __NET_LWIP_H__ */
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 +117 -0

117 lines not on this page · raw message

Signature · 1 line
2.40.1
#16 lore raw

PATCH v4 9/14 net: split cmd/net.c into cmd/net.c and cmd/net-common.c

In reply to Jerome Forissier

Extract some code from cmd/net.c that will be useful in a subsequent commit to implement wget with NET_LWIP.

---
 cmd/Makefile     |   5 ++-
 cmd/net-common.c | 109 ++++++++++++++++++++++++++++++++++++++++++++
 cmd/net.c        | 115 -----------------------------------------------
 3 files changed, 113 insertions(+), 116 deletions(-)
 create mode 100644 cmd/net-common.c
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/net-common.c new file +109 -0

109 lines not on this page · raw message

cmd/net.c +0 -115

118 lines not on this page · raw message

Signature · 1 line
2.40.1
#17 lore raw

PATCH v4 10/14 net-lwip: add wget command

In reply to Jerome Forissier

Add support for the wget command with NET_LWIP.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/net-lwip.c     |   8 ++
 include/net-lwip.h |  18 +++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 269 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 303 insertions(+)
 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/net-lwip.c +8 -0
index c021da6a674..42f8bd6b259 100644
@@ -35,3 +35,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
include/net-lwip.h +18 -0
index 4d41b0208a3..ddf25e61417 100644
@@ -11,8 +11,26 @@ struct netif *net_lwip_new_netif_noip(void);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 
+/**
+ * wget_with_dns() - runs dns host IP address resulution before wget
+ *
+ * @dst_addr:	destination address to download the file
+ * @uri:	uri string of target file of wget
+ * Return:	downloaded file size, negative if failed
+ */
+
+int wget_with_dns(ulong dst_addr, char *uri);
+/**
+ * wget_validate_uri() - varidate the uri
+ *
+ * @uri:	uri string of target file of wget
+ * Return:	true if uri is valid, false if uri is invalid
+ */
+bool wget_validate_uri(char *uri);
+
 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_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 +269 -0

269 lines not on this page · raw message

Signature · 1 line
2.40.1
#18 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 371 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/net-lwip.c     |   8 ++
 include/net-lwip.h |  18 +++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 269 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 303 insertions(+)
 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/net-lwip.c +8 -0
index c021da6a674..42f8bd6b259 100644
@@ -35,3 +35,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
include/net-lwip.h +18 -0
index 4d41b0208a3..ddf25e61417 100644
@@ -11,8 +11,26 @@ struct netif *net_lwip_new_netif_noip(void);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 
+/**
+ * wget_with_dns() - runs dns host IP address resulution before wget
+ *
+ * @dst_addr:	destination address to download the file
+ * @uri:	uri string of target file of wget
+ * Return:	downloaded file size, negative if failed
+ */
+
+int wget_with_dns(ulong dst_addr, char *uri);
+/**
+ * wget_validate_uri() - varidate the uri
+ *
+ * @uri:	uri string of target file of wget
+ * Return:	true if uri is valid, false if uri is invalid
+ */
+bool wget_validate_uri(char *uri);
+
 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_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 +269 -0
new file mode 100644
index 00000000000..069299bd469
@@ -0,0 +1,269 @@
+// 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.h>
+#include <time.h>
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+#define PROGRESS_PRINT_STEP_BYTES (100 * 1024)
+
+enum done_state {
+        NOT_DONE = 0,
+        SUCCESS = 1,
+        FAILURE = 2
+};
+
+struct wget_ctx {
+	ulong daddr;
+	ulong saved_daddr;
+	ulong size;
+	ulong prevsize;
+	ulong start_time;
+	enum done_state 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 wget_ctx *ctx = arg;
+	struct pbuf *buf;
+
+	if (!pbuf)
+		return ERR_BUF;
+
+	for (buf = pbuf; buf; buf = buf->next) {
+		memcpy((void *)ctx->daddr, buf->payload, buf->len);
+		ctx->daddr += buf->len;
+		ctx->size += buf->len;
+		if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) {
+			printf("#");
+			ctx->prevsize = ctx->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)
+{
+	struct wget_ctx *ctx = arg;
+	ulong elapsed;
+
+	if (httpc_result != HTTPC_RESULT_OK) {
+		log_err("\nHTTP client error %d\n", httpc_result);
+		ctx->done = FAILURE;
+		return;
+	}
+
+	elapsed = get_timer(ctx->start_time);
+	if (rx_content_len > PROGRESS_PRINT_STEP_BYTES)
+		printf("\n");
+        printf("%u bytes transferred in %lu ms (", rx_content_len,
+	       get_timer(ctx->start_time));
+        print_size(rx_content_len / elapsed * 1000, "/s)\n");
+
+	if (env_set_hex("filesize", rx_content_len) ||
+	    env_set_hex("fileaddr", ctx->saved_daddr)) {
+		log_err("Could not set filesize or fileaddr\n");
+		ctx->done = FAILURE;
+		return;
+	}
+
+	ctx->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;
+	struct netif *netif;
+	struct wget_ctx ctx;
+	char *path;
+	u16 port;
+
+	ctx.daddr = dst_addr;
+	ctx.saved_daddr = dst_addr;
+	ctx.done = NOT_DONE;
+	ctx.size = 0;
+	ctx.prevsize = 0;
+
+	if (parse_url(uri, server_name, &port, &path))
+		return CMD_RET_USAGE;
+
+	netif = net_lwip_new_netif();
+	if (!netif)
+		return -1;
+
+	memset(&conn, 0, sizeof(conn));
+	conn.result_fn = httpc_result_cb;
+	ctx.start_time = get_timer(0);
+	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+			       &ctx, &state)) {
+		net_lwip_remove_netif(netif);
+		return CMD_RET_FAILURE;
+	}
+
+	while (!ctx.done) {
+		eth_rx();
+		sys_check_timeouts();
+		if (ctrlc())
+			break;
+	}
+
+	net_lwip_remove_netif(netif);
+
+	if (ctx.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;
+}
+
+/**
+ * wget_validate_uri() - validate the uri for wget
+ *
+ * @uri:	uri string
+ *
+ * This function follows the current U-Boot wget implementation.
+ * scheme: only "http:" is supported
+ * authority:
+ *   - user information: not supported
+ *   - host: supported
+ *   - port: not supported(always use the default port)
+ *
+ * Uri is expected to be correctly percent encoded.
+ * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0')
+ * and space character(0x20) are not allowed.
+ *
+ * TODO: stricter uri conformance check
+ *
+ * Return:	true on success, false on failure
+ */
+bool wget_validate_uri(char *uri)
+{
+	char c;
+	bool ret = true;
+	char *str_copy, *s, *authority;
+
+	for (c = 0x1; c < 0x21; c++) {
+		if (strchr(uri, c)) {
+			log_err("invalid character is used\n");
+			return false;
+		}
+	}
+	if (strchr(uri, 0x7f)) {
+		log_err("invalid character is used\n");
+		return false;
+	}
+
+	if (strncmp(uri, "http://", 7)) {
+		log_err("only http:// is supported\n");
+		return false;
+	}
+	str_copy = strdup(uri);
+	if (!str_copy)
+		return false;
+
+	s = str_copy + strlen("http://");
+	authority = strsep(&s, "/");
+	if (!s) {
+		log_err("invalid uri, no file path\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, '@');
+	if (s) {
+		log_err("user information is not supported\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, ':');
+	if (s) {
+		log_err("user defined port is not supported\n");
+		ret = false;
+		goto out;
+	}
+
+out:
+	free(str_copy);
+
+	return ret;
+}
Signature · 1 line
2.40.1

Hi Jerome, I am trying out the lwIP stack on TI boards.

For wget, I noticed a bug and a user experience improvement. The bug is an off-by-one array access when parsing the url. The improvement emits a message if the url isn't an http://, since that is all we are supporting, and without the message, the wget command silently fails, which is confusing to the user.

I will post the 2 patches as a reply to this email. LMK if you want to use another method to collaborate. I can already see that efi http boot support will not work. wget_validate_uri() looks to be copied vertabim from the current implementation, and IMO we should completely remove it.

Jon

#19 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 365 lines · Jon Humphreys
Quoted 363 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/net-lwip.c     |   8 ++
 include/net-lwip.h |  18 +++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 269 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 303 insertions(+)
 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/net-lwip.c +8 -0
index c021da6a674..42f8bd6b259 100644
@@ -35,3 +35,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
include/net-lwip.h +18 -0
index 4d41b0208a3..ddf25e61417 100644
@@ -11,8 +11,26 @@ struct netif *net_lwip_new_netif_noip(void);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 
+/**
+ * wget_with_dns() - runs dns host IP address resulution before wget
+ *
+ * @dst_addr:	destination address to download the file
+ * @uri:	uri string of target file of wget
+ * Return:	downloaded file size, negative if failed
+ */
+
+int wget_with_dns(ulong dst_addr, char *uri);
+/**
+ * wget_validate_uri() - varidate the uri
+ *
+ * @uri:	uri string of target file of wget
+ * Return:	true if uri is valid, false if uri is invalid
+ */
+bool wget_validate_uri(char *uri);
+
 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_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 +263 -0
new file mode 100644
index 00000000000..069299bd469
@@ -0,0 +1,269 @@
+// 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.h>
+#include <time.h>
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+#define PROGRESS_PRINT_STEP_BYTES (100 * 1024)
+
+enum done_state {
+        NOT_DONE = 0,
+        SUCCESS = 1,
+        FAILURE = 2
+};
+
+struct wget_ctx {
+	ulong daddr;
+	ulong saved_daddr;
+	ulong size;
+	ulong prevsize;
+	ulong start_time;
+	enum done_state 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 wget_ctx *ctx = arg;
+	struct pbuf *buf;
+
+	if (!pbuf)
+		return ERR_BUF;
+
+	for (buf = pbuf; buf; buf = buf->next) {
+		memcpy((void *)ctx->daddr, buf->payload, buf->len);
+		ctx->daddr += buf->len;
+		ctx->size += buf->len;
+		if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) {
+			printf("#");
+			ctx->prevsize = ctx->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)
+{
+	struct wget_ctx *ctx = arg;
+	ulong elapsed;
+
+	if (httpc_result != HTTPC_RESULT_OK) {
+		log_err("\nHTTP client error %d\n", httpc_result);
+		ctx->done = FAILURE;
+		return;
+	}
+
+	elapsed = get_timer(ctx->start_time);
+	if (rx_content_len > PROGRESS_PRINT_STEP_BYTES)
+		printf("\n");
+        printf("%u bytes transferred in %lu ms (", rx_content_len,
+	       get_timer(ctx->start_time));
+        print_size(rx_content_len / elapsed * 1000, "/s)\n");
+
+	if (env_set_hex("filesize", rx_content_len) ||
+	    env_set_hex("fileaddr", ctx->saved_daddr)) {
+		log_err("Could not set filesize or fileaddr\n");
+		ctx->done = FAILURE;
+		return;
+	}
+
+	ctx->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;
+	struct netif *netif;
+	struct wget_ctx ctx;
+	char *path;
+	u16 port;
+
+	ctx.daddr = dst_addr;
+	ctx.saved_daddr = dst_addr;
+	ctx.done = NOT_DONE;
+	ctx.size = 0;
+	ctx.prevsize = 0;
+
+	if (parse_url(uri, server_name, &port, &path))
+		return CMD_RET_USAGE;
+
+	netif = net_lwip_new_netif();
+	if (!netif)
+		return -1;
+
+	memset(&conn, 0, sizeof(conn));
+	conn.result_fn = httpc_result_cb;
+	ctx.start_time = get_timer(0);
+	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+			       &ctx, &state)) {
+		net_lwip_remove_netif(netif);
+		return CMD_RET_FAILURE;
+	}
+
+	while (!ctx.done) {
+		eth_rx();
+		sys_check_timeouts();
+		if (ctrlc())
+			break;
+	}
+
+	net_lwip_remove_netif(netif);
+
+	if (ctx.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;
+}
+
+/**
+ * wget_validate_uri() - validate the uri for wget
+ *
+ * @uri:	uri string
+ *
+ * This function follows the current U-Boot wget implementation.
+ * scheme: only "http:" is supported
+ * authority:
+ *   - user information: not supported
+ *   - host: supported
+ *   - port: not supported(always use the default port)
+ *
+ * Uri is expected to be correctly percent encoded.
+ * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0')
+ * and space character(0x20) are not allowed.
+ *
+ * TODO: stricter uri conformance check
+ *
+ * Return:	true on success, false on failure
+ */
+bool wget_validate_uri(char *uri)
+{
+	char c;
+	bool ret = true;
+	char *str_copy, *s, *authority;
+
+	for (c = 0x1; c < 0x21; c++) {
+		if (strchr(uri, c)) {
+			log_err("invalid character is used\n");
+			return false;
+		}
+	}
+	if (strchr(uri, 0x7f)) {
+		log_err("invalid character is used\n");
+		return false;
+	}
+
+	if (strncmp(uri, "http://", 7)) {
+		log_err("only http:// is supported\n");
+		return false;
+	}
+	str_copy = strdup(uri);
+	if (!str_copy)
+		return false;
+
+	s = str_copy + strlen("http://");
+	authority = strsep(&s, "/");
+	if (!s) {
+		log_err("invalid uri, no file path\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, '@');
+	if (s) {
+		log_err("user information is not supported\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, ':');
+	if (s) {
+		log_err("user defined port is not supported\n");
+		ret = false;
+		goto out;
+	}
Quoted 8 lines
Quoted 8 lines
net-lwip/wget.c new file +6 -0
+
+out:
+	free(str_copy);
+
+	return ret;
+}
Signature · 1 line
2.40.1

Hi Jon,

Quoted 4 lines

Hi Jerome, I am trying out the lwIP stack on TI boards.

For wget, I noticed a bug and a user experience improvement. The bug is an off-by-one array access when parsing the url.

Indeed, someone reported this bug to me off-list and it's already fixed in my WIP branch.

Quoted 4 lines

The improvement emits a
message if the url isn't an http://, since that is all we are supporting, and without the message, the wget command silently fails, which is confusing to the user.

I agree.

Quoted 4 lines

I will post the 2 patches as a reply to this email. LMK if you want to use another method to collaborate. I can already see that efi http boot support will not work. wget_validate_uri() looks to be copied vertabim from the current implementation, and IMO we should completely remove it.

It is indeed copied. It is needed to avoid an unresolved symbol but I understand more work may be needed for EFI HTTP boot support (not tested by me).

If you are willing to help with this then you are welcome to post patches as replies and I will integrate them in the series.

Thanks,

Signature · 1 line
Jerome
#20 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 397 lines · Jerome Forissier
Quoted 365 lines · Jon Humphreys
Quoted 363 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/net-lwip.c     |   8 ++
 include/net-lwip.h |  18 +++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 269 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 303 insertions(+)
 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/net-lwip.c +8 -0
index c021da6a674..42f8bd6b259 100644
@@ -35,3 +35,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
include/net-lwip.h +18 -0
index 4d41b0208a3..ddf25e61417 100644
@@ -11,8 +11,26 @@ struct netif *net_lwip_new_netif_noip(void);
 void net_lwip_remove_netif(struct netif *netif);
 struct netif *net_lwip_get_netif(void);
 
+/**
+ * wget_with_dns() - runs dns host IP address resulution before wget
+ *
+ * @dst_addr:	destination address to download the file
+ * @uri:	uri string of target file of wget
+ * Return:	downloaded file size, negative if failed
+ */
+
+int wget_with_dns(ulong dst_addr, char *uri);
+/**
+ * wget_validate_uri() - varidate the uri
+ *
+ * @uri:	uri string of target file of wget
+ * Return:	true if uri is valid, false if uri is invalid
+ */
+bool wget_validate_uri(char *uri);
+
 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_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 +263 -0
new file mode 100644
index 00000000000..069299bd469
@@ -0,0 +1,269 @@
+// 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.h>
+#include <time.h>
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+#define PROGRESS_PRINT_STEP_BYTES (100 * 1024)
+
+enum done_state {
+        NOT_DONE = 0,
+        SUCCESS = 1,
+        FAILURE = 2
+};
+
+struct wget_ctx {
+	ulong daddr;
+	ulong saved_daddr;
+	ulong size;
+	ulong prevsize;
+	ulong start_time;
+	enum done_state 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 wget_ctx *ctx = arg;
+	struct pbuf *buf;
+
+	if (!pbuf)
+		return ERR_BUF;
+
+	for (buf = pbuf; buf; buf = buf->next) {
+		memcpy((void *)ctx->daddr, buf->payload, buf->len);
+		ctx->daddr += buf->len;
+		ctx->size += buf->len;
+		if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) {
+			printf("#");
+			ctx->prevsize = ctx->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)
+{
+	struct wget_ctx *ctx = arg;
+	ulong elapsed;
+
+	if (httpc_result != HTTPC_RESULT_OK) {
+		log_err("\nHTTP client error %d\n", httpc_result);
+		ctx->done = FAILURE;
+		return;
+	}
+
+	elapsed = get_timer(ctx->start_time);
+	if (rx_content_len > PROGRESS_PRINT_STEP_BYTES)
+		printf("\n");
+        printf("%u bytes transferred in %lu ms (", rx_content_len,
+	       get_timer(ctx->start_time));
+        print_size(rx_content_len / elapsed * 1000, "/s)\n");
+
+	if (env_set_hex("filesize", rx_content_len) ||
+	    env_set_hex("fileaddr", ctx->saved_daddr)) {
+		log_err("Could not set filesize or fileaddr\n");
+		ctx->done = FAILURE;
+		return;
+	}
+
+	ctx->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;
+	struct netif *netif;
+	struct wget_ctx ctx;
+	char *path;
+	u16 port;
+
+	ctx.daddr = dst_addr;
+	ctx.saved_daddr = dst_addr;
+	ctx.done = NOT_DONE;
+	ctx.size = 0;
+	ctx.prevsize = 0;
+
+	if (parse_url(uri, server_name, &port, &path))
+		return CMD_RET_USAGE;
+
+	netif = net_lwip_new_netif();
+	if (!netif)
+		return -1;
+
+	memset(&conn, 0, sizeof(conn));
+	conn.result_fn = httpc_result_cb;
+	ctx.start_time = get_timer(0);
+	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+			       &ctx, &state)) {
+		net_lwip_remove_netif(netif);
+		return CMD_RET_FAILURE;
+	}
+
+	while (!ctx.done) {
+		eth_rx();
+		sys_check_timeouts();
+		if (ctrlc())
+			break;
+	}
+
+	net_lwip_remove_netif(netif);
+
+	if (ctx.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;
+}
+
+/**
+ * wget_validate_uri() - validate the uri for wget
+ *
+ * @uri:	uri string
+ *
+ * This function follows the current U-Boot wget implementation.
+ * scheme: only "http:" is supported
+ * authority:
+ *   - user information: not supported
+ *   - host: supported
+ *   - port: not supported(always use the default port)
+ *
+ * Uri is expected to be correctly percent encoded.
+ * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0')
+ * and space character(0x20) are not allowed.
+ *
+ * TODO: stricter uri conformance check
+ *
+ * Return:	true on success, false on failure
+ */
+bool wget_validate_uri(char *uri)
+{
+	char c;
+	bool ret = true;
+	char *str_copy, *s, *authority;
+
+	for (c = 0x1; c < 0x21; c++) {
+		if (strchr(uri, c)) {
+			log_err("invalid character is used\n");
+			return false;
+		}
+	}
+	if (strchr(uri, 0x7f)) {
+		log_err("invalid character is used\n");
+		return false;
+	}
+
+	if (strncmp(uri, "http://", 7)) {
+		log_err("only http:// is supported\n");
+		return false;
+	}
+	str_copy = strdup(uri);
+	if (!str_copy)
+		return false;
+
+	s = str_copy + strlen("http://");
+	authority = strsep(&s, "/");
+	if (!s) {
+		log_err("invalid uri, no file path\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, '@');
+	if (s) {
+		log_err("user information is not supported\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, ':');
+	if (s) {
+		log_err("user defined port is not supported\n");
+		ret = false;
+		goto out;
+	}
Quoted 8 lines
Quoted 8 lines
net-lwip/wget.c new file +6 -0
+
+out:
+	free(str_copy);
+
+	return ret;
+}
Signature · 1 line
2.40.1

Hi Jon,

Quoted 4 lines

Hi Jerome, I am trying out the lwIP stack on TI boards.

For wget, I noticed a bug and a user experience improvement. The bug is an off-by-one array access when parsing the url.

Indeed, someone reported this bug to me off-list and it's already fixed in my WIP branch.

Quoted 4 lines

The improvement emits a
message if the url isn't an http://, since that is all we are supporting, and without the message, the wget command silently fails, which is confusing to the user.

I agree.

Quoted 4 lines

I will post the 2 patches as a reply to this email. LMK if you want to use another method to collaborate. I can already see that efi http boot support will not work. wget_validate_uri() looks to be copied vertabim from the current implementation, and IMO we should completely remove it.

Quoted 10 lines

It is indeed copied. It is needed to avoid an unresolved symbol but I understand more work may be needed for EFI HTTP boot support (not tested by me).

If you are willing to help with this then you are welcome to post patches as replies and I will integrate them in the series.

Thanks,

Signature · 1 line
Jerome

Jerome, here is a patch to allow a port specifier in wget's uri, which lwIP supports.

thanks
Jon

Subject: [PATCH] net-lwip: lwIP wget supports user defined port in the uri, so
allow it.

---
 net-lwip/wget.c | 6 ------
 1 file changed, 6 deletions(-)
net-lwip/wget.c +0 -6
index 6b9c953ef51..d3fdd44a29e 100644
@@ -257,12 +257,6 @@ bool wget_validate_uri(char *uri)
 		ret = false;
 		goto out;
 	}
-	s = strchr(authority, ':');
-	if (s) {
-		log_err("user defined port is not supported\n");
-		ret = false;
-		goto out;
-	}
 
 out:
 	free(str_copy);
Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 22 lines · Jon Humphreys
Quoted 20 lines · Jerome Forissier
Quoted 19 lines · Jon Humphreys
Quoted 17 lines · Jerome Forissier

Add support for the wget command with NET_LWIP.

Based on code initially developed by Maxim U.

---
 cmd/Kconfig        |   7 ++
 cmd/net-lwip.c     |   8 ++
 include/net-lwip.h |  18 +++
 net-lwip/Makefile  |   1 +
 net-lwip/wget.c    | 269 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 303 insertions(+)
 create mode 100644 net-lwip/wget.c

<snip>

Quoted 127 lines
Quoted 95 lines
Quoted 64 lines
Quoted 64 lines
(quoted diff) +64 -0
+/**
+ * wget_validate_uri() - validate the uri for wget
+ *
+ * @uri:	uri string
+ *
+ * This function follows the current U-Boot wget implementation.
+ * scheme: only "http:" is supported
+ * authority:
+ *   - user information: not supported
+ *   - host: supported
+ *   - port: not supported(always use the default port)
+ *
+ * Uri is expected to be correctly percent encoded.
+ * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0')
+ * and space character(0x20) are not allowed.
+ *
+ * TODO: stricter uri conformance check
+ *
+ * Return:	true on success, false on failure
+ */
+bool wget_validate_uri(char *uri)
+{
+	char c;
+	bool ret = true;
+	char *str_copy, *s, *authority;
+
+	for (c = 0x1; c < 0x21; c++) {
+		if (strchr(uri, c)) {
+			log_err("invalid character is used\n");
+			return false;
+		}
+	}
+	if (strchr(uri, 0x7f)) {
+		log_err("invalid character is used\n");
+		return false;
+	}
+
+	if (strncmp(uri, "http://", 7)) {
+		log_err("only http:// is supported\n");
+		return false;
+	}
+	str_copy = strdup(uri);
+	if (!str_copy)
+		return false;
+
+	s = str_copy + strlen("http://");
+	authority = strsep(&s, "/");
+	if (!s) {
+		log_err("invalid uri, no file path\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, '@');
+	if (s) {
+		log_err("user information is not supported\n");
+		ret = false;
+		goto out;
+	}
+	s = strchr(authority, ':');
+	if (s) {
+		log_err("user defined port is not supported\n");
+		ret = false;
+		goto out;
+	}
Quoted 8 lines
Quoted 8 lines
(quoted diff) +6 -0
+
+out:
+	free(str_copy);
+
+	return ret;
+}
Signature · 1 line
2.40.1

Hi Jon,

Quoted 4 lines

Hi Jerome, I am trying out the lwIP stack on TI boards.

For wget, I noticed a bug and a user experience improvement. The bug is an off-by-one array access when parsing the url.

Indeed, someone reported this bug to me off-list and it's already fixed in my WIP branch.

Quoted 4 lines

The improvement emits a
message if the url isn't an http://, since that is all we are supporting, and without the message, the wget command silently fails, which is confusing to the user.

I agree.

Quoted 4 lines

I will post the 2 patches as a reply to this email. LMK if you want to use another method to collaborate. I can already see that efi http boot support will not work. wget_validate_uri() looks to be copied vertabim from the current implementation, and IMO we should completely remove it.

Quoted 10 lines

It is indeed copied. It is needed to avoid an unresolved symbol but I understand more work may be needed for EFI HTTP boot support (not tested by me).

If you are willing to help with this then you are welcome to post patches as replies and I will integrate them in the series.

Thanks,

Signature · 1 line
Jerome

Jerome, here is a patch to allow a port specifier in wget's uri, which lwIP supports.

thanks
Jon

Subject: [PATCH] net-lwip: lwIP wget supports user defined port in the uri, so
allow it.

---
 net-lwip/wget.c | 6 ------
 1 file changed, 6 deletions(-)
net-lwip/wget.c +0 -0
index 6b9c953ef51..d3fdd44a29e 100644
@@ -257,12 +257,6 @@ bool wget_validate_uri(char *uri)
 		ret = false;
 		goto out;

net-lwip/wget.c bool wget_validate_uri(char *uri) · line 262

Quoted 10 lines
net-lwip/wget.c +0 -6
 	}
-	s = strchr(authority, ':');
-	if (s) {
-		log_err("user defined port is not supported\n");
-		ret = false;
-		goto out;
-	}
 
 out:
 	free(str_copy);

Patch added to v5, thanks!

Signature · 1 line
Jerome
#22 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

In reply to Jon Humphreys

Subject: [PATCH] net-lwip: fixes off-by-one array access error with wget

When wget parses the url and extracts the host, it is off by one on the index to terminate the character array.

---
 net-lwip/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net-lwip/wget.c +1 -1
index 069299bd469..63b19b99112 100644
@@ -51,7 +51,7 @@ static int parse_url(char *url, char *host, u16 *port, char **path)
 		return -EINVAL;
 
 	memcpy(host, p, pp - p);
-	host[pp - p + 1] = '\0';
+	host[pp - p] = '\0';
 
 	if (*pp == ':') {
 		/* Parse port number */
Signature · 1 line
2.34.1
#23 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 15 lines · Jon Humphreys

Subject: [PATCH] net-lwip: fixes off-by-one array access error with wget

When wget parses the url and extracts the host, it is off by one on the index to terminate the character array.

---
 net-lwip/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net-lwip/wget.c +0 -0
index 069299bd469..63b19b99112 100644

net-lwip/wget.c static int parse_url(char *url, char *host, u16 *port, char **path) · line 57

Quoted 8 lines
net-lwip/wget.c +1 -1
@@ -51,7 +51,7 @@ static int parse_url(char *url, char *host, u16 *port, char **path)
 		return -EINVAL;
 
 	memcpy(host, p, pp - p);
-	host[pp - p + 1] = '\0';
+	host[pp - p] = '\0';
 
 	if (*pp == ':') {
 		/* Parse port number */

Hi Jon,

As I said previously I am ignoring this patch since I already have it in my working tree. Thanks for reporting.

Signature · 1 line
Jerome
#24 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

In reply to Jon Humphreys

Subject: [PATCH] net-lwip: Add message if not using http:// for wget

U-Boot's wget only supports http://, so give the user a clue if they don't use it.

---
 net-lwip/wget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net-lwip/wget.c +3 -1
index 63b19b99112..6b9c953ef51 100644
@@ -35,8 +35,10 @@ static int parse_url(char *url, char *host, u16 *port, char **path)
 	long lport;
 
 	p = strstr(url, "http://");
-	if (!p)
+	if (!p) {
+		log_err("only http:// is supported\n");
 		return -EINVAL;
+	}
 
 	p += strlen("http://");
 
Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH v4 10/14] net-lwip: add wget command

Quoted 16 lines · Jon Humphreys

Subject: [PATCH] net-lwip: Add message if not using http:// for wget

U-Boot's wget only supports http://, so give the user a clue if they don't use it.

---
 net-lwip/wget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net-lwip/wget.c +0 -0
index 63b19b99112..6b9c953ef51 100644
@@ -35,8 +35,10 @@ static int parse_url(char *url, char *host, u16 *port, char **path)
 	long lport;

net-lwip/wget.c static int parse_url(char *url, char *host, u16 *port, char **path) · line 44

Quoted 10 lines
net-lwip/wget.c +3 -1
 
 	p = strstr(url, "http://");
-	if (!p)
+	if (!p) {
+		log_err("only http:// is supported\n");
 		return -EINVAL;
+	}
 
 	p += strlen("http://");
 

I am folding that into "net-lwip: add wget command" if you don't mind. Thanks!

Signature · 1 line
Jerome
#26 lore raw

PATCH v4 11/14 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
#27 lore raw

PATCH v4 12/14 configs: add qemu_arm64_lwip_defconfig

In reply to Jerome Forissier

Add qemu_arm64_lwip_defconfig which #include's qemu_arm64_defconfig and selects NET_LWIP instead of NET. This config has all the supported net commands enabled.

---
 configs/qemu_arm64_lwip_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 configs/qemu_arm64_lwip_defconfig
configs/qemu_arm64_lwip_defconfig new file +4 -0
new file mode 100644
index 00000000000..1f5fd097f0e
@@ -0,0 +1,4 @@
+#include <configs/qemu_arm64_defconfig>
+CONFIG_NET_LWIP=y
+CONFIG_CMD_DNS=y
+CONFIG_CMD_WGET=y
Signature · 1 line
2.40.1
Reviewed-by on v4 12/14
#28 lore raw

Re: [PATCH v4 12/14] configs: add qemu_arm64_lwip_defconfig

Quoted 22 lines · Jerome Forissier

Add qemu_arm64_lwip_defconfig which #include's qemu_arm64_defconfig and selects NET_LWIP instead of NET. This config has all the supported net commands enabled.

---
 configs/qemu_arm64_lwip_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 configs/qemu_arm64_lwip_defconfig
configs/qemu_arm64_lwip_defconfig new file +4 -1
new file mode 100644
index 00000000000..1f5fd097f0e
@@ -0,0 +1,4 @@
+#include <configs/qemu_arm64_defconfig>
+CONFIG_NET_LWIP=y
+CONFIG_CMD_DNS=y
+CONFIG_CMD_WGET=y
--
Quoted 2 lines

2.40.1

#29 lore raw

PATCH v4 13/14 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
#30 lore raw

PATCH v4 14/14 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
#31 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Signature · 1 line
Tom
#32 lore raw

Hi Tom

Quoted 52 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

Quoted 5 lines

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

Thanks
/Ilias

Quoted 2 lines

--
Tom

#33 lore raw
Quoted 55 lines · Ilias Apalodimas

Hi Tom

Quoted 52 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

Quoted 8 lines
Quoted 5 lines

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

The reason for the slower TFTP is the block size. lwIP supports only the default (512 bytes), while the legacy stack supports the 'blksize' option and sets CONFIG_TFTP_BLOCKSIZE=1468 by default.

Signature · 1 line
Jerome
#34 lore raw
Quoted 64 lines · Jerome Forissier
Quoted 61 lines · Ilias Apalodimas

Hi Tom

Quoted 57 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Quoted 6 lines
Quoted 2 lines

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

The reason for the slower TFTP is the block size. lwIP supports only the default (512 bytes), while the legacy stack supports the 'blksize' option and sets CONFIG_TFTP_BLOCKSIZE=1468 by default.

Ouch. Can we ask if upstream is agreeable to making that configurable some way, and then we utilize that? I'm not looking forward to lots of performance hit reports.

But please note that my dhcp request/reply is also taking 10x as long, and in v3 it wasn't working at all? I feel like there's possibly another issue lurking here.

Signature · 1 line
Tom
#35 lore raw
Quoted 68 lines · Tom Rini
Quoted 67 lines · Jerome Forissier
Quoted 63 lines · Ilias Apalodimas

Hi Tom

Quoted 52 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

Quoted 5 lines

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

Quoted 7 lines
Quoted 3 lines

The reason for the slower TFTP is the block size. lwIP supports only the default (512 bytes), while the legacy stack supports the 'blksize' option and sets CONFIG_TFTP_BLOCKSIZE=1468 by default.

Ouch. Can we ask if upstream is agreeable to making that configurable some way, and then we utilize that? I'm not looking forward to lots of performance hit reports.

I tried a quick & dirty hack to hardcode the blksize option in the lwIP stack and I can confirm I get the same speed as with the legacy implementation or even slightly better (legacy: 822 KB/s, hacked lwIP:
843 KB/s, upstream lwIP: 343 KB/s). That's on QEMU with py3tftp running on my laptop as a TFTP server. I would probably get better results with a good TFTP server and real hardware (RPi...) but at least this shows lwIP can be on par with the U-Boot stack.

I can consider writing a better patch for lwIP and submitting it upstream.

Quoted 3 lines

But please note that my dhcp request/reply is also taking 10x as long, and in v3 it wasn't working at all? I feel like there's possibly another issue lurking here.

This I need to investigate more on my RPi. I'll keep you posted. Thanks again for testing.

Signature · 1 line
Jerome
#36 lore raw
In reply to Jerome Forissier
Quoted 65 lines · Jerome Forissier
Quoted 61 lines · Ilias Apalodimas

Hi Tom

Quoted 57 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Quoted 6 lines
Quoted 2 lines

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

The reason for the slower TFTP is the block size. lwIP supports only the default (512 bytes), while the legacy stack supports the 'blksize' option and sets CONFIG_TFTP_BLOCKSIZE=1468 by default.

This number looks like it's derived from standard ethernet frame (1500) minus default packet sizes to get to 1468. Does LWIP have a concept of MTU? I would have thought it would be better to use MTU if so because it then means it's not hard coded and it can change based on what the driver/HW supports?

Peter

#37 lore raw
Quoted 70 lines · Peter Robinson
Quoted 68 lines · Jerome Forissier
Quoted 63 lines · Ilias Apalodimas

Hi Tom

Quoted 52 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

So, on a Pi 3 (rpi_3_defconfig) I see this now (and it passes normally):
========================================== FAILURES =========================================== ___________________________________ test_efi_helloworld_net ___________________________________ test/py/tests/test_efi_loader.py:163: in test_efi_helloworld_net
assert expected_text in output
E AssertionError: assert 'Hello, world' in 'No UEFI binary known at 200000'
------------------------------------ Captured stdout call ------------------------------------- U-Boot> tftpboot 200000 EFI/arm64/helloworld.efi
Using smsc95xx_eth device
TFTP from server 192.168.1.10; our IP address is 192.168.1.100
Filename 'EFI/arm64/helloworld.efi'.
Load address: 0x200000
Loading:
Bytes transferred = 4528 (11b0 hex)
U-Boot> U-Boot> crc32 200000 $filesize
CRC32 for 00200000 ... 002011af ==> 2b466005
U-Boot> U-Boot> bootefi 200000
No UEFI binary known at 200000
U-Boot>
=================================== short test summary info =================================== If I disable that test, it moves on to failing the same exact way for
grub. If I disable the grub test too. After that, oh, a bunch of other
tests get skipped because CMD_NET and similar aren't enabled now, and
the tests are wrong. I'll post that as another patch by itself. After
correcting for that, we're seemingly noticeably slower as I need to
increase the timeout for tftp'ing my 83MiB FIT image I use for kernel
testing. We no longer have the estimated speed message, so I can't as
easily say how much slower it is. After increasing the timeout, the
kernel boot test does work.

Quoted 5 lines

I can note that normally it takes ~18ms to get a dhcp reply, but with lwIP it's now 132ms, and previously the kernel loaded at 2.7MiB/s (which, not great) but if that has a similar level of slowdown, could well explain it.

Thanks for taking the time. We'll run the pytests before v5. That being said, my wget tests were faster with lwIP last time I checked.

Quoted 7 lines
Quoted 3 lines

The reason for the slower TFTP is the block size. lwIP supports only the default (512 bytes), while the legacy stack supports the 'blksize' option and sets CONFIG_TFTP_BLOCKSIZE=1468 by default.

This number looks like it's derived from standard ethernet frame (1500) minus default packet sizes to get to 1468. Does LWIP have a concept of MTU?

It does (netif->mtu), although it does not have path MTU discovery. But for the use cases we consider (mostly booting from the LAN) it shouldn't matter.

Quoted 3 lines

I would have thought it would be better to use MTU if
so because it then means it's not hard coded and it can change based on what the driver/HW supports?

I agree but for maximum flexibility I plan to extend the lwIP API and set blksize to the mtu in the caller (net-lwip/tftp.c):

tftp_init_client(&ctx); // Provide the callbacks tftp_client_set_bksize(netif->mtu); // New function tftp_get(&ctx, addr, port, fname, mode); // Start the transfer

Signature · 1 line
Jerome
#38 lore raw
In reply to Jerome Forissier
Quoted 50 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

Quoted 5 lines

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Hi Jermone,

I've given this a spin on an imx8mm-venice-gw73xx-0x via imx8mm_venice_defconfig and I can't get DHCP to work (didn't work in v3 either):

$ diff defconfig configs/imx8mm_venice_defconfig
68,69c68,71
< CONFIG_CMD_DNS_LWIP=y
< CONFIG_CMD_WGET_LWIP=y
---
Quoted 4 lines

CONFIG_CMD_DHCP6=y
CONFIG_CMD_TFTPPUT=y
CONFIG_SYS_DISABLE_AUTOLOAD=y
CONFIG_CMD_WGET=y

88,90c90,94
< CONFIG_NET_LWIP=y
< CONFIG_LWIP_DEBUG=y
< CONFIG_LWIP_ASSERT=y
---

Quoted 5 lines

CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_IP_DEFRAG=y
CONFIG_TFTP_BLOCKSIZE=4096
CONFIG_PROT_TCP_SACK=y
CONFIG_IPV6=y

Target:
u-boot=> net list
eth0 : ethernet@30be0000 00:d0:12:b5:f8:41 active
u-boot=> dhcp || echo fail
eth0: ethernet@30be0000 00:d0:12:b5:f8:41 active
netif_set_ipaddr: netif address being changed
netif: added interface 0 addr 192.168.1.1 netmask 0.0.0.0 gw 0.0.0.0
etharp_request: sending ARP request.
etharp_raw: sending raw ARP packet.
ethernet_output: sending packet 000000007df00bf0 dhcp_start(netif=000000007df2af40) 0dhcp_start(): mallocing new DHCP client dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
ip4_output_if: 0IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
ethernet_output: sending packet 000000007df2c010
dhcp_discover: deleting()
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 2000 msecs
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:28:28:5d:bb:16:9f, type:8899
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:00:27:0e:0d:74:ba, type:806
etharp_update_arp_entry: 172.24.20.24 - 00:27:0e:0d:74:ba
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:98:90:96:ac:d7:63, type:806
etharp_update_arp_entry: 172.24.20.3 - 98:90:96:ac:d7:63
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:84:2b:2b:4e:5a:9a, type:806
etharp_update_arp_entry: 172.24.0.1 - 84:2b:2b:4e:5a:9a
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:cc:96:e5:1e:a0:7b, type:800
ip_input: iphdr->dest 0xffff1fac netif->ip_addr 0x101a8c0 (0x0, 0x0, 0xffff1fac)
ip4_input: UDP packet to DHCP client port 138
ip4_input: packet not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:d4:be:d9:9f:5a:b4, type:800
ip_input: iphdr->dest 0xffffffff netif->ip_addr 0x101a8c0 (0x0, 0x0, 0xffffffff)
ip4_input: packet accepted on interface 0ip4_input:
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |        68     | (v, hl, tos, len)
+-------------------------------+
|    19472      |000|       0   | (id, flags, offset)
+-------------------------------+
|  128  |   17  |    0x2e51     | (ttl, proto, chksum)
+-------------------------------+
|  172  |   24  |   20  |   48  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_input: p->len 68 p->tot_len 68
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:00:0b:ab:2e:fa:51, type:806
etharp_update_arp_entry: 172.24.24.181 - 00:0b:ab:2e:fa:51
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:98:90:96:ac:d7:63, type:806
etharp_update_arp_entry: 172.24.20.3 - 98:90:96:ac:d7:63
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:84:2b:2b:4e:5a:9a, type:806
etharp_update_arp_entry: 172.24.0.1 - 84:2b:2b:4e:5a:9a
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
fail

Even using ping before DHCP fails:
u-boot=> setenv ipaddr 192.168.1.1; ping 192.168.1.146 || echo fail Using ethernet@30be0000 device
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ip4_route: No route to 192.168.1.146
ping failed; host 192.168.1.146 is not alive
fail

Best Regards,

Tim

#39 lore raw
Quoted 133 lines · Tim Harvey
Quoted 50 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

Quoted 5 lines

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Hi Jermone,

I've given this a spin on an imx8mm-venice-gw73xx-0x via imx8mm_venice_defconfig and I can't get DHCP to work (didn't work in v3 either):

$ diff defconfig configs/imx8mm_venice_defconfig
68,69c68,71
< CONFIG_CMD_DNS_LWIP=y
< CONFIG_CMD_WGET_LWIP=y
---
Quoted 4 lines

CONFIG_CMD_DHCP6=y
CONFIG_CMD_TFTPPUT=y
CONFIG_SYS_DISABLE_AUTOLOAD=y
CONFIG_CMD_WGET=y

88,90c90,94
< CONFIG_NET_LWIP=y
< CONFIG_LWIP_DEBUG=y
< CONFIG_LWIP_ASSERT=y
---

Quoted 5 lines

CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_IP_DEFRAG=y
CONFIG_TFTP_BLOCKSIZE=4096
CONFIG_PROT_TCP_SACK=y
CONFIG_IPV6=y

Target:
u-boot=> net list
eth0 : ethernet@30be0000 00:d0:12:b5:f8:41 active
u-boot=> dhcp || echo fail
eth0: ethernet@30be0000 00:d0:12:b5:f8:41 active
netif_set_ipaddr: netif address being changed
netif: added interface 0 addr 192.168.1.1 netmask 0.0.0.0 gw 0.0.0.0
etharp_request: sending ARP request.
etharp_raw: sending raw ARP packet.
ethernet_output: sending packet 000000007df00bf0 dhcp_start(netif=000000007df2af40) 0dhcp_start(): mallocing new DHCP client dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
ip4_output_if: 0IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
ethernet_output: sending packet 000000007df2c010
dhcp_discover: deleting()
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 2000 msecs
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:28:28:5d:bb:16:9f, type:8899
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:00:27:0e:0d:74:ba, type:806
etharp_update_arp_entry: 172.24.20.24 - 00:27:0e:0d:74:ba
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:98:90:96:ac:d7:63, type:806
etharp_update_arp_entry: 172.24.20.3 - 98:90:96:ac:d7:63
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:84:2b:2b:4e:5a:9a, type:806
etharp_update_arp_entry: 172.24.0.1 - 84:2b:2b:4e:5a:9a

Quoted 8 lines

etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:cc:96:e5:1e:a0:7b, type:800
ip_input: iphdr->dest 0xffff1fac netif->ip_addr 0x101a8c0 (0x0, 0x0, 0xffff1fac)
ip4_input: UDP packet to DHCP client port 138
ip4_input: packet not for us.

That's weird. I think what could happen is the interface already has a static IP assigned when it is registered to the lwIP stack and thus DHCP never receives the packed because it is dropped before.
I have reworked the initialization code in v5, lwIP will get to know only one interface at a time and I make sure that interface is registered without an IP address when doing DHCP. Hopefully that should fix the issue.

Thanks for testing!

Signature · 1 line
Jerome
Quoted 4 lines

Best Regards,

Tim

#40 lore raw
Quoted 146 lines · Jerome Forissier
Quoted 133 lines · Tim Harvey
Quoted 50 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

Quoted 5 lines

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Hi Jermone,

I've given this a spin on an imx8mm-venice-gw73xx-0x via imx8mm_venice_defconfig and I can't get DHCP to work (didn't work in v3 either):

$ diff defconfig configs/imx8mm_venice_defconfig
68,69c68,71
< CONFIG_CMD_DNS_LWIP=y
< CONFIG_CMD_WGET_LWIP=y
---
Quoted 4 lines

CONFIG_CMD_DHCP6=y
CONFIG_CMD_TFTPPUT=y
CONFIG_SYS_DISABLE_AUTOLOAD=y
CONFIG_CMD_WGET=y

88,90c90,94
< CONFIG_NET_LWIP=y
< CONFIG_LWIP_DEBUG=y
< CONFIG_LWIP_ASSERT=y
---

Quoted 5 lines

CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_IP_DEFRAG=y
CONFIG_TFTP_BLOCKSIZE=4096
CONFIG_PROT_TCP_SACK=y
CONFIG_IPV6=y

Target:
u-boot=> net list
eth0 : ethernet@30be0000 00:d0:12:b5:f8:41 active
u-boot=> dhcp || echo fail
eth0: ethernet@30be0000 00:d0:12:b5:f8:41 active
netif_set_ipaddr: netif address being changed
netif: added interface 0 addr 192.168.1.1 netmask 0.0.0.0 gw 0.0.0.0
etharp_request: sending ARP request.
etharp_raw: sending raw ARP packet.
ethernet_output: sending packet 000000007df00bf0 dhcp_start(netif=000000007df2af40) 0dhcp_start(): mallocing new DHCP client dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
ip4_output_if: 0IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
ethernet_output: sending packet 000000007df2c010
dhcp_discover: deleting()
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 2000 msecs
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:28:28:5d:bb:16:9f, type:8899
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:00:27:0e:0d:74:ba, type:806
etharp_update_arp_entry: 172.24.20.24 - 00:27:0e:0d:74:ba
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:98:90:96:ac:d7:63, type:806
etharp_update_arp_entry: 172.24.20.3 - 98:90:96:ac:d7:63
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:84:2b:2b:4e:5a:9a, type:806
etharp_update_arp_entry: 172.24.0.1 - 84:2b:2b:4e:5a:9a

Quoted 8 lines

etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:cc:96:e5:1e:a0:7b, type:800
ip_input: iphdr->dest 0xffff1fac netif->ip_addr 0x101a8c0 (0x0, 0x0, 0xffff1fac)
ip4_input: UDP packet to DHCP client port 138
ip4_input: packet not for us.

Quoted 9 lines

That's weird. I think what could happen is the interface already has a static IP assigned when it is registered to the lwIP stack and thus DHCP never receives the packed because it is dropped before.
I have reworked the initialization code in v5, lwIP will get to know only one interface at a time and I make sure that interface is registered without an IP address when doing DHCP. Hopefully that should fix the issue.

Thanks for testing!

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Best Regards,

Tim

#41 lore raw
Quoted 155 lines · Tim Harvey
Quoted 153 lines · Jerome Forissier
Quoted 133 lines · Tim Harvey
Quoted 50 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

Quoted 5 lines

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Hi Jermone,

I've given this a spin on an imx8mm-venice-gw73xx-0x via imx8mm_venice_defconfig and I can't get DHCP to work (didn't work in v3 either):

$ diff defconfig configs/imx8mm_venice_defconfig
68,69c68,71
< CONFIG_CMD_DNS_LWIP=y
< CONFIG_CMD_WGET_LWIP=y
---
Quoted 4 lines

CONFIG_CMD_DHCP6=y
CONFIG_CMD_TFTPPUT=y
CONFIG_SYS_DISABLE_AUTOLOAD=y
CONFIG_CMD_WGET=y

88,90c90,94
< CONFIG_NET_LWIP=y
< CONFIG_LWIP_DEBUG=y
< CONFIG_LWIP_ASSERT=y
---

Quoted 5 lines

CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_IP_DEFRAG=y
CONFIG_TFTP_BLOCKSIZE=4096
CONFIG_PROT_TCP_SACK=y
CONFIG_IPV6=y

Target:
u-boot=> net list
eth0 : ethernet@30be0000 00:d0:12:b5:f8:41 active
u-boot=> dhcp || echo fail
eth0: ethernet@30be0000 00:d0:12:b5:f8:41 active
netif_set_ipaddr: netif address being changed
netif: added interface 0 addr 192.168.1.1 netmask 0.0.0.0 gw 0.0.0.0
etharp_request: sending ARP request.
etharp_raw: sending raw ARP packet.
ethernet_output: sending packet 000000007df00bf0 dhcp_start(netif=000000007df2af40) 0dhcp_start(): mallocing new DHCP client dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
ip4_output_if: 0IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
ethernet_output: sending packet 000000007df2c010
dhcp_discover: deleting()
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 2000 msecs
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:28:28:5d:bb:16:9f, type:8899
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:00:27:0e:0d:74:ba, type:806
etharp_update_arp_entry: 172.24.20.24 - 00:27:0e:0d:74:ba
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:98:90:96:ac:d7:63, type:806
etharp_update_arp_entry: 172.24.20.3 - 98:90:96:ac:d7:63
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:84:2b:2b:4e:5a:9a, type:806
etharp_update_arp_entry: 172.24.0.1 - 84:2b:2b:4e:5a:9a

Quoted 8 lines

etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_input: incoming ARP request
etharp_input: ARP request was not for us.
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:cc:96:e5:1e:a0:7b, type:800
ip_input: iphdr->dest 0xffff1fac netif->ip_addr 0x101a8c0 (0x0, 0x0, 0xffff1fac)
ip4_input: UDP packet to DHCP client port 138
ip4_input: packet not for us.

That's weird. I think what could happen is the interface already has a static IP assigned when it is registered to the lwIP stack and thus DHCP never receives the packed because it is dropped before.
I have reworked the initialization code in v5, lwIP will get to know only one interface at a time and I make sure that interface is registered without an IP address when doing DHCP. Hopefully that should fix the issue.

Quoted 6 lines
Quoted 2 lines

Thanks for testing!

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Not at the moment, unfortunately. I'll take a closer look at what this message "packet not for us" means on Monday.

Thanks,

Signature · 1 line
Jerome
Quoted 4 lines

Best Regards,

Tim

#42 lore raw
In reply to Tim Harvey

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

#43 lore raw

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Signature · 2 lines
Best regards,
Maxim Uvarov
#44 lore raw
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

It seems 'packet not for us' can mean a lot of things.

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Best Regards,

Tim

#45 lore raw
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.
I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Thanks,

Signature · 1 line
Jerome
#46 lore raw
Quoted 82 lines · Jerome Forissier
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 7 lines
Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.

Here's what I see with all those enabled on an imx8mm-venice-gw73xx-0x:
Net: eth0: ethernet@30be0000 [PRIME]
GSC : boot watchdog disabled
Thermal protection:enabled at 96C
Hit any key to stop autoboot: 0
u-boot=> dhcp || echo fail
netif: added interface et IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
netif: setting default interface et dhcp_start(netif=00000000fdf23bb0) et0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 00000000fdf23d10
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 00000000fdf23d5e new 00000000fdf23d56 (8)
udp_send: added header in given pbuf 00000000fdf23d10
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
inet_chksum_pseudo(): checksumming pbuf 00000000fdf23d10 (has next 0000000000000000)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=807
udp_send: UDP checksum 0xf7f8
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 00000000fdf23d56 new 00000000fdf23d42 (20)
ip4_output_if: et0
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
pbuf_add_header: old 00000000fdf23d42 new 00000000fdf23d34 (14)
ethernet_output: sending packet 00000000fdf23d10
^^^ at this point a 350 byte packet gets sent to fecmxc_send for the NIC which looks like this via print_hex_dump_bytes():

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff  .P..............
00000020: ff ff 00 44 00 43 01 3c f8 f7 01 01 06 00 00 04  ...D.C.<........
00000030: 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00   !..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............

on my dhcp server 'tcpdump -i eth1 -X -vvv' shows:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:34:25.341167 [|llc]

0x0000:  0000 0000 0000 0000 0000 343d f2fd 0000  ..........4=....
0x0010:  0000 5e01 5e01 8000 0100 0000 0000 0000  ..^.^...........
0x0020:  0000 0000 0000 ffff ffff ffff 00d0 12ba  ................
0x0030:  f8cc 0800 4500 0150 001e 0000 ff11 ba7f  ....E..P........
0x0040:  0000 0000 ffff ffff 0044 0043 013c 6d78  .........D.C.<mx
0x0050:  0101 0600 1255 994f 0000 0000 0000 0000  .....U.O........
0x0060:  0000 0000 0000 0000 0000 0000 00d0 12ba  ................
0x0070:  f8cc 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 6382 5363  ............c.Sc
0x0140:  3501 0139 0205 dc37 0301 031c ff00 0000  5..9...7........

Comparing to w/o LWIP:
u-boot=> dhcp || echo fail
BOOTP broadcast 1
fecmxc_send ethernet@30be0000 342

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 48 00 00 40 00 ff 11 7a a5 00 00 00 00 ff ff  [email protected].......
00000020: ff ff 00 44 00 43 01 34 00 00 01 01 06 00 12 bb  ...D.C.4........
00000030: 82 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .d..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 02  ......c.Sc5..9..
00000120: 40 5d 02 00 16 5e 03 01 00 00 3c 0c 55 2d 42 6f  @]...^....<.U-Bo
00000130: 6f 74 2e 61 72 6d 76 38 37 05 01 03 06 0c 11 ff  ot.armv87.......
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00                                ......

^^^ Note the packet is 8 bytes shorter

and on the dhcp server:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

    0.0.0.0.bootpc > 255.255.255.255.bootps: [no cksum] BOOTP/DHCP,

Request from 00:d0:12:ba:f8:cc (oui Unknown), length 300, xid 0x12bb8264, Flags [none] (0x0000)
Client-Ethernet-Address 00:d0:12:ba:f8:cc (oui Unknown) Vendor-rfc1048 Extensions

    Magic Cookie 0x63825363
    DHCP-Message (53), length 1: Discover
    MSZ (57), length 2: 576
    ARCH (93), length 2: 22
    NDI (94), length 3: 1.0.0
    Vendor-Class (60), length 12: "U-Boot.armv8"
    Parameter-Request (55), length 5:
      Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6),
Hostname (12)
      RP (17)
    END (255), length 0
    PAD (0), length 0, occurs 22
0x0000:  4500 0148 0000 4000 ff11 7aa5 0000 0000  [email protected].....
0x0010:  ffff ffff 0044 0043 0134 0000 0101 0600  .....D.C.4......
0x0020:  12bb 8264 0000 0000 0000 0000 0000 0000  ...d............
0x0030:  0000 0000 0000 0000 00d0 12ba f8cc 0000  ................
0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 6382 5363 3501 0139  ........c.Sc5..9
0x0110:  0202 405d 0200 165e 0301 0000 3c0c 552d  ..@]...^....<.U-
0x0120:  426f 6f74 2e61 726d 7638 3705 0103 060c  Boot.armv87.....
0x0130:  11ff 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000                      ........
Quoted 2 lines

I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Please let me know your findings. I can test imx8mp as well but would have to reconfigure everything.

Best Regards,

Tim

#47 lore raw

Hi Tim,

Quoted 155 lines · Tim Harvey
Quoted 82 lines · Jerome Forissier
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 7 lines
Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.

Here's what I see with all those enabled on an imx8mm-venice-gw73xx-0x:
Net: eth0: ethernet@30be0000 [PRIME]
GSC : boot watchdog disabled
Thermal protection:enabled at 96C
Hit any key to stop autoboot: 0
u-boot=> dhcp || echo fail
netif: added interface et IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
netif: setting default interface et dhcp_start(netif=00000000fdf23bb0) et0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 00000000fdf23d10
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 00000000fdf23d5e new 00000000fdf23d56 (8)
udp_send: added header in given pbuf 00000000fdf23d10
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
inet_chksum_pseudo(): checksumming pbuf 00000000fdf23d10 (has next 0000000000000000)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=807
udp_send: UDP checksum 0xf7f8
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 00000000fdf23d56 new 00000000fdf23d42 (20)
ip4_output_if: et0
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
pbuf_add_header: old 00000000fdf23d42 new 00000000fdf23d34 (14)
ethernet_output: sending packet 00000000fdf23d10
^^^ at this point a 350 byte packet gets sent to fecmxc_send for the NIC which looks like this via print_hex_dump_bytes():

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff  .P..............
00000020: ff ff 00 44 00 43 01 3c f8 f7 01 01 06 00 00 04  ...D.C.<........
00000030: 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00   !..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
Quoted 8 lines
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............

Up to this point everything *seems* OK

Quoted 17 lines

on my dhcp server 'tcpdump -i eth1 -X -vvv' shows:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:34:25.341167 [|llc]

0x0000:  0000 0000 0000 0000 0000 343d f2fd 0000  ..........4=....
0x0010:  0000 5e01 5e01 8000 0100 0000 0000 0000  ..^.^...........
0x0020:  0000 0000 0000 ffff ffff ffff 00d0 12ba  ................
0x0030:  f8cc 0800 4500 0150 001e 0000 ff11 ba7f  ....E..P........
0x0040:  0000 0000 ffff ffff 0044 0043 013c 6d78  .........D.C.<mx
0x0050:  0101 0600 1255 994f 0000 0000 0000 0000  .....U.O........
0x0060:  0000 0000 0000 0000 0000 0000 00d0 12ba  ................
0x0070:  f8cc 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 6382 5363  ............c.Sc
0x0140:  3501 0139 0205 dc37 0301 031c ff00 0000  5..9...7........

But here it shows the DHCP packet is not received.

Quoted 26 lines

Comparing to w/o LWIP:
u-boot=> dhcp || echo fail
BOOTP broadcast 1
fecmxc_send ethernet@30be0000 342

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 48 00 00 40 00 ff 11 7a a5 00 00 00 00 ff ff  [email protected].......
00000020: ff ff 00 44 00 43 01 34 00 00 01 01 06 00 12 bb  ...D.C.4........
00000030: 82 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .d..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 02  ......c.Sc5..9..
00000120: 40 5d 02 00 16 5e 03 01 00 00 3c 0c 55 2d 42 6f  @]...^....<.U-Bo
00000130: 6f 74 2e 61 72 6d 76 38 37 05 01 03 06 0c 11 ff  ot.armv87.......
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00                                ......
Quoted 1 line

^^^ Note the packet is 8 bytes shorter

Yes but that's just padding IIUC.

Quoted 35 lines

and on the dhcp server:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

    0.0.0.0.bootpc > 255.255.255.255.bootps: [no cksum] BOOTP/DHCP,

Request from 00:d0:12:ba:f8:cc (oui Unknown), length 300, xid 0x12bb8264, Flags [none] (0x0000)
Client-Ethernet-Address 00:d0:12:ba:f8:cc (oui Unknown) Vendor-rfc1048 Extensions

    Magic Cookie 0x63825363
    DHCP-Message (53), length 1: Discover
    MSZ (57), length 2: 576
    ARCH (93), length 2: 22
    NDI (94), length 3: 1.0.0
    Vendor-Class (60), length 12: "U-Boot.armv8"
    Parameter-Request (55), length 5:
      Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6),
Hostname (12)
      RP (17)
    END (255), length 0
    PAD (0), length 0, occurs 22
0x0000:  4500 0148 0000 4000 ff11 7aa5 0000 0000  [email protected].....
0x0010:  ffff ffff 0044 0043 0134 0000 0101 0600  .....D.C.4......
0x0020:  12bb 8264 0000 0000 0000 0000 0000 0000  ...d............
0x0030:  0000 0000 0000 0000 00d0 12ba f8cc 0000  ................
0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 6382 5363 3501 0139  ........c.Sc5..9
0x0110:  0202 405d 0200 165e 0301 0000 3c0c 552d  ..@]...^....<.U-
0x0120:  426f 6f74 2e61 726d 7638 3705 0103 060c  Boot.armv87.....
0x0130:  11ff 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000                      ........

All good there, as expected.

Quoted 5 lines
Quoted 2 lines

I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Please let me know your findings. I can test imx8mp as well but would have to reconfigure everything.

So I did some tests on my imx8mp and I got DHCP to work on the second ethernet port (ENET2) but *not* on the first one (ENET1). They appear to be using different drivers (drivers/net/fec_mxc.c for ENET1 and drivers/net/dwc_eth_qos.c for ENET2). No matter what I do, there is no packet going out of ENET1.

With a network cable plugged into ENET2 (ethernet@30bf0000):

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> dhcp
ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done DHCP client bound to address 192.168.0.39 (2066 ms)
u-boot=>

Now moving the cable to ENET1 (ethernet@30be0000) and resetting the board:

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> setenv ethact ethernet@30be0000
u-boot=> dhcp
u-boot=> echo $?
1

I enabled the debug traces in fecmxc_send() but I see nothing wrong, the function is called with a packet and it returns success yet nothing is sent out on the wire. Any idea what could be wrong?
My plan is to add more traces to the driver and compare NET vs. NET_LWIP.

Regards,

Signature · 1 line
Jerome
#48 lore raw
Quoted 308 lines · Jerome Forissier

Hi Tim,

Quoted 155 lines · Tim Harvey
Quoted 82 lines · Jerome Forissier
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 7 lines
Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.

Here's what I see with all those enabled on an imx8mm-venice-gw73xx-0x:
Net: eth0: ethernet@30be0000 [PRIME]
GSC : boot watchdog disabled
Thermal protection:enabled at 96C
Hit any key to stop autoboot: 0
u-boot=> dhcp || echo fail
netif: added interface et IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
netif: setting default interface et dhcp_start(netif=00000000fdf23bb0) et0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 00000000fdf23d10
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 00000000fdf23d5e new 00000000fdf23d56 (8)
udp_send: added header in given pbuf 00000000fdf23d10
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
inet_chksum_pseudo(): checksumming pbuf 00000000fdf23d10 (has next 0000000000000000)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=807
udp_send: UDP checksum 0xf7f8
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 00000000fdf23d56 new 00000000fdf23d42 (20)
ip4_output_if: et0
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
pbuf_add_header: old 00000000fdf23d42 new 00000000fdf23d34 (14)
ethernet_output: sending packet 00000000fdf23d10
^^^ at this point a 350 byte packet gets sent to fecmxc_send for the NIC which looks like this via print_hex_dump_bytes():

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff  .P..............
00000020: ff ff 00 44 00 43 01 3c f8 f7 01 01 06 00 00 04  ...D.C.<........
00000030: 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00   !..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
Quoted 8 lines
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............

Up to this point everything *seems* OK

Quoted 17 lines

on my dhcp server 'tcpdump -i eth1 -X -vvv' shows:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:34:25.341167 [|llc]

0x0000:  0000 0000 0000 0000 0000 343d f2fd 0000  ..........4=....
0x0010:  0000 5e01 5e01 8000 0100 0000 0000 0000  ..^.^...........
0x0020:  0000 0000 0000 ffff ffff ffff 00d0 12ba  ................
0x0030:  f8cc 0800 4500 0150 001e 0000 ff11 ba7f  ....E..P........
0x0040:  0000 0000 ffff ffff 0044 0043 013c 6d78  .........D.C.<mx
0x0050:  0101 0600 1255 994f 0000 0000 0000 0000  .....U.O........
0x0060:  0000 0000 0000 0000 0000 0000 00d0 12ba  ................
0x0070:  f8cc 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 6382 5363  ............c.Sc
0x0140:  3501 0139 0205 dc37 0301 031c ff00 0000  5..9...7........

But here it shows the DHCP packet is not received.

Quoted 26 lines

Comparing to w/o LWIP:
u-boot=> dhcp || echo fail
BOOTP broadcast 1
fecmxc_send ethernet@30be0000 342

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 48 00 00 40 00 ff 11 7a a5 00 00 00 00 ff ff  [email protected].......
00000020: ff ff 00 44 00 43 01 34 00 00 01 01 06 00 12 bb  ...D.C.4........
00000030: 82 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .d..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 02  ......c.Sc5..9..
00000120: 40 5d 02 00 16 5e 03 01 00 00 3c 0c 55 2d 42 6f  @]...^....<.U-Bo
00000130: 6f 74 2e 61 72 6d 76 38 37 05 01 03 06 0c 11 ff  ot.armv87.......
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00                                ......
Quoted 1 line

^^^ Note the packet is 8 bytes shorter

Yes but that's just padding IIUC.

Quoted 35 lines

and on the dhcp server:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

    0.0.0.0.bootpc > 255.255.255.255.bootps: [no cksum] BOOTP/DHCP,

Request from 00:d0:12:ba:f8:cc (oui Unknown), length 300, xid 0x12bb8264, Flags [none] (0x0000)
Client-Ethernet-Address 00:d0:12:ba:f8:cc (oui Unknown) Vendor-rfc1048 Extensions

    Magic Cookie 0x63825363
    DHCP-Message (53), length 1: Discover
    MSZ (57), length 2: 576
    ARCH (93), length 2: 22
    NDI (94), length 3: 1.0.0
    Vendor-Class (60), length 12: "U-Boot.armv8"
    Parameter-Request (55), length 5:
      Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6),
Hostname (12)
      RP (17)
    END (255), length 0
    PAD (0), length 0, occurs 22
0x0000:  4500 0148 0000 4000 ff11 7aa5 0000 0000  [email protected].....
0x0010:  ffff ffff 0044 0043 0134 0000 0101 0600  .....D.C.4......
0x0020:  12bb 8264 0000 0000 0000 0000 0000 0000  ...d............
0x0030:  0000 0000 0000 0000 00d0 12ba f8cc 0000  ................
0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 6382 5363 3501 0139  ........c.Sc5..9
0x0110:  0202 405d 0200 165e 0301 0000 3c0c 552d  ..@]...^....<.U-
0x0120:  426f 6f74 2e61 726d 7638 3705 0103 060c  Boot.armv87.....
0x0130:  11ff 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000                      ........

All good there, as expected.

Quoted 5 lines
Quoted 2 lines

I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Please let me know your findings. I can test imx8mp as well but would have to reconfigure everything.

So I did some tests on my imx8mp and I got DHCP to work on the second ethernet port (ENET2) but *not* on the first one (ENET1). They appear to be using different drivers (drivers/net/fec_mxc.c for ENET1 and drivers/net/dwc_eth_qos.c for ENET2). No matter what I do, there is no packet going out of ENET1.

With a network cable plugged into ENET2 (ethernet@30bf0000):

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> dhcp
ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done DHCP client bound to address 192.168.0.39 (2066 ms)
u-boot=>

Now moving the cable to ENET1 (ethernet@30be0000) and resetting the board:

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> setenv ethact ethernet@30be0000
u-boot=> dhcp
u-boot=> echo $?
1

Quoted 5 lines

I enabled the debug traces in fecmxc_send() but I see nothing wrong, the function is called with a packet and it returns success yet nothing is sent out on the wire. Any idea what could be wrong?
My plan is to add more traces to the driver and compare NET vs. NET_LWIP.

Jerome,

That is consistent with what I see then. The imx8mm (and all imx all the way back to imx28) use the FEC ethernet MAC so I would assume you see the issue on all of those SOC's. The imx8mp introduced a 2nd different MAC, the eqos which you are showing working.

If you look at my results above a packet 'is' received by the DHCP server but its missing something where tcpdump shows an '[|llc]' and I don't know what that means - something wrong with the link layer?

I feel like something is wrong in the header or packet alignment. Maybe the key is to understand what the tcpdump output of '[llc]' means:
- lwip fec mac destination tcpdump shows '15:34:25.341167 [|llc]'
- no-lwip fec mac destination tcptdump shows '15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

(Adding Joe and Ramon, the network maintainers to cc)

Regards,

Tim

#49 lore raw
Quoted 323 lines · Tim Harvey
Quoted 308 lines · Jerome Forissier

Hi Tim,

Quoted 155 lines · Tim Harvey
Quoted 82 lines · Jerome Forissier
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 7 lines
Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.

Here's what I see with all those enabled on an imx8mm-venice-gw73xx-0x:
Net: eth0: ethernet@30be0000 [PRIME]
GSC : boot watchdog disabled
Thermal protection:enabled at 96C
Hit any key to stop autoboot: 0
u-boot=> dhcp || echo fail
netif: added interface et IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
netif: setting default interface et dhcp_start(netif=00000000fdf23bb0) et0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 00000000fdf23d10
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 00000000fdf23d5e new 00000000fdf23d56 (8)
udp_send: added header in given pbuf 00000000fdf23d10
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
inet_chksum_pseudo(): checksumming pbuf 00000000fdf23d10 (has next 0000000000000000)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=807
udp_send: UDP checksum 0xf7f8
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 00000000fdf23d56 new 00000000fdf23d42 (20)
ip4_output_if: et0
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
pbuf_add_header: old 00000000fdf23d42 new 00000000fdf23d34 (14)
ethernet_output: sending packet 00000000fdf23d10
^^^ at this point a 350 byte packet gets sent to fecmxc_send for the NIC which looks like this via print_hex_dump_bytes():

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff  .P..............
00000020: ff ff 00 44 00 43 01 3c f8 f7 01 01 06 00 00 04  ...D.C.<........
00000030: 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00   !..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
Quoted 8 lines
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............

Up to this point everything *seems* OK

Quoted 17 lines

on my dhcp server 'tcpdump -i eth1 -X -vvv' shows:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:34:25.341167 [|llc]

0x0000:  0000 0000 0000 0000 0000 343d f2fd 0000  ..........4=....
0x0010:  0000 5e01 5e01 8000 0100 0000 0000 0000  ..^.^...........
0x0020:  0000 0000 0000 ffff ffff ffff 00d0 12ba  ................
0x0030:  f8cc 0800 4500 0150 001e 0000 ff11 ba7f  ....E..P........
0x0040:  0000 0000 ffff ffff 0044 0043 013c 6d78  .........D.C.<mx
0x0050:  0101 0600 1255 994f 0000 0000 0000 0000  .....U.O........
0x0060:  0000 0000 0000 0000 0000 0000 00d0 12ba  ................
0x0070:  f8cc 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 6382 5363  ............c.Sc
0x0140:  3501 0139 0205 dc37 0301 031c ff00 0000  5..9...7........

But here it shows the DHCP packet is not received.

Quoted 26 lines

Comparing to w/o LWIP:
u-boot=> dhcp || echo fail
BOOTP broadcast 1
fecmxc_send ethernet@30be0000 342

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 48 00 00 40 00 ff 11 7a a5 00 00 00 00 ff ff  [email protected].......
00000020: ff ff 00 44 00 43 01 34 00 00 01 01 06 00 12 bb  ...D.C.4........
00000030: 82 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .d..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 02  ......c.Sc5..9..
00000120: 40 5d 02 00 16 5e 03 01 00 00 3c 0c 55 2d 42 6f  @]...^....<.U-Bo
00000130: 6f 74 2e 61 72 6d 76 38 37 05 01 03 06 0c 11 ff  ot.armv87.......
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00                                ......
Quoted 1 line

^^^ Note the packet is 8 bytes shorter

Yes but that's just padding IIUC.

Quoted 35 lines

and on the dhcp server:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

    0.0.0.0.bootpc > 255.255.255.255.bootps: [no cksum] BOOTP/DHCP,

Request from 00:d0:12:ba:f8:cc (oui Unknown), length 300, xid 0x12bb8264, Flags [none] (0x0000)
Client-Ethernet-Address 00:d0:12:ba:f8:cc (oui Unknown) Vendor-rfc1048 Extensions

    Magic Cookie 0x63825363
    DHCP-Message (53), length 1: Discover
    MSZ (57), length 2: 576
    ARCH (93), length 2: 22
    NDI (94), length 3: 1.0.0
    Vendor-Class (60), length 12: "U-Boot.armv8"
    Parameter-Request (55), length 5:
      Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6),
Hostname (12)
      RP (17)
    END (255), length 0
    PAD (0), length 0, occurs 22
0x0000:  4500 0148 0000 4000 ff11 7aa5 0000 0000  [email protected].....
0x0010:  ffff ffff 0044 0043 0134 0000 0101 0600  .....D.C.4......
0x0020:  12bb 8264 0000 0000 0000 0000 0000 0000  ...d............
0x0030:  0000 0000 0000 0000 00d0 12ba f8cc 0000  ................
0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 6382 5363 3501 0139  ........c.Sc5..9
0x0110:  0202 405d 0200 165e 0301 0000 3c0c 552d  ..@]...^....<.U-
0x0120:  426f 6f74 2e61 726d 7638 3705 0103 060c  Boot.armv87.....
0x0130:  11ff 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000                      ........

All good there, as expected.

Quoted 5 lines
Quoted 2 lines

I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Please let me know your findings. I can test imx8mp as well but would have to reconfigure everything.

So I did some tests on my imx8mp and I got DHCP to work on the second ethernet port (ENET2) but *not* on the first one (ENET1). They appear to be using different drivers (drivers/net/fec_mxc.c for ENET1 and drivers/net/dwc_eth_qos.c for ENET2). No matter what I do, there is no packet going out of ENET1.

With a network cable plugged into ENET2 (ethernet@30bf0000):

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> dhcp
ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done DHCP client bound to address 192.168.0.39 (2066 ms)
u-boot=>

Now moving the cable to ENET1 (ethernet@30be0000) and resetting the board:

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> setenv ethact ethernet@30be0000
u-boot=> dhcp
u-boot=> echo $?
1

Quoted 5 lines

I enabled the debug traces in fecmxc_send() but I see nothing wrong, the function is called with a packet and it returns success yet nothing is sent out on the wire. Any idea what could be wrong?
My plan is to add more traces to the driver and compare NET vs. NET_LWIP.

Jerome,

That is consistent with what I see then. The imx8mm (and all imx all the way back to imx28) use the FEC ethernet MAC so I would assume you see the issue on all of those SOC's. The imx8mp introduced a 2nd different MAC, the eqos which you are showing working.

Quoted 5 lines

If you look at my results above a packet 'is' received by the DHCP server but its missing something where tcpdump shows an '[|llc]' and I don't know what that means - something wrong with the link layer?

I feel like something is wrong in the header or packet alignment.

Good catch :) Here is a quick workaroud that works for me:

drivers/net/fec_mxc.c +16 -1
index 2dc1364beec..85bf1a2b52e 100644
@@ -658,7 +658,7 @@ static void fecmxc_halt(struct udevice *dev)
  * @param[in] length Data count in bytes
  * Return: 0 on success
  */
-static int fecmxc_send(struct udevice *dev, void *packet, int length)
+static int fecmxc_send_(struct udevice *dev, void *packet, int length)
 {
 	unsigned int status;
 	u32 size;
@@ -796,6 +796,21 @@ out:
 	return ret;
 }
 
+static int fecmxc_send(struct udevice *dev, void *packet, int length)
+{
+	void *pp;
+	int ret;
+
+	pp = memalign(64, length);
+	if (!pp)
+		return -ENOMEM;
+	memcpy(pp, packet, length);
+	ret = fecmxc_send_(dev, pp, length);
+	free(pp);
+
+	return ret;
+}
+
 /**
  * Pull one frame from the card
  * @param[in] dev Our ethernet device to handle

I believe the root of the problem is that lwIP uses malloc() to allocate the outgoing packets and doesn't enforce any alignement. I need to revisit that wrt. PKTALIGN.

Thanks,

Signature · 1 line
Jerome
Quoted 11 lines

Maybe the key is to understand what the tcpdump output of '[llc]' means:
- lwip fec mac destination tcpdump shows '15:34:25.341167 [|llc]'
- no-lwip fec mac destination tcptdump shows '15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

(Adding Joe and Ramon, the network maintainers to cc)

Regards,

Tim

#50 lore raw
Quoted 372 lines · Jerome Forissier
Quoted 323 lines · Tim Harvey
Quoted 308 lines · Jerome Forissier

Hi Tim,

Quoted 155 lines · Tim Harvey
Quoted 82 lines · Jerome Forissier
Quoted 30 lines · Tim Harvey
Quoted 20 lines · Maxim Uvarov

пт, 21 июн. 2024 г. в 21:42, Fabio Estevam <[email protected]>:

Quoted 9 lines

Hi Tim and Jerome,

Quoted 3 lines · Tim Harvey

I tried your to-upstream/v5-wip branch (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do you have something else to try/test?

Quoted 8 lines

Yes, when I tested older versions from Maxim I could never get lwIP to work with i.MX.

Jerome,

Please try to run the lwIP series on any i.MX board, if possible.

Thanks

Quoted 8 lines

Packet not for us means that incoming packet DST MAC does not match to the MAC address inside lwip. I.e. to MAC address set into lwip when lwip_init was done. Original U-Boot network stack does not compare MACs but lwip does. There is something specific on this board, in general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from the incoming packet.

Quoted 1 line

It seems 'packet not for us' can mean a lot of things.

Yeah :-/ in this case I believe the traces are caused by unrelated traffic (UDP port 138 is used by NetBIOS).

Quoted 4 lines

I added a bit of debugging around 'DHCP packet accepted' and found I'm not receiving any packets from my DHCP server. So I connected directly to another board (isolated network) where I ran my own server and tcpdump and I don't see packets coming from lwip:

Ha! That's interesting.

Quoted 31 lines

without lwip my server shows:

# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:18:01.043992 IP (tos 0x0, ttl 255, id 23, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044391 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
22:18:01.044454 IP (tos 0x0, ttl 255, id 24, offset 0, flags [DF],
proto UDP (17), length 328)
22:18:01.044752 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none],
proto UDP (17), length 328)
# tcpdump -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot
length 262144 bytes
22:22:41.602178  [|llc]
22:22:41.709978  [|llc]
22:22:41.867947  [|llc]
22:22:42.105202  [|llc]
22:22:42.502091  [|llc]
22:22:43.219079  [|llc]
22:22:44.497979  [|llc]
22:22:45.776884  [|llc]
22:22:47.054773  [|llc]
22:22:48.333667  [|llc]
22:22:49.611559  [|llc]
22:22:50.890469  [|llc]
Quoted 2 lines

What actual hardware has this been tested with? I think Tom mentioned he tested with an rpi of some sort.

Yes, I believe he tested on RPi 3B and me too. Ilias has tested on NVIDIA Jetson Nano.

Quoted 7 lines
Quoted 2 lines

I don't know what the meaning of the llc msg is above but you can see there is no DHCP request.

Some more tracing is needed. Can you try enabling all traces in lib/lwip/u-boot/lwipopts.h? i.e., replace all LWIP_DBG_OFF with LWIP_DBG_ON in the #if defined(CONFIG_LWIP_DEBUG) section. And of course enabled CONFIG_LWIP_DEBUG.

Here's what I see with all those enabled on an imx8mm-venice-gw73xx-0x:
Net: eth0: ethernet@30be0000 [PRIME]
GSC : boot watchdog disabled
Thermal protection:enabled at 96C
Hit any key to stop autoboot: 0
u-boot=> dhcp || echo fail
netif: added interface et IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
netif: setting default interface et dhcp_start(netif=00000000fdf23bb0) et0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcp
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 00000000fdf23d10
transaction id xid(42021)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 00000000fdf23d5e new 00000000fdf23d56 (8)
udp_send: added header in given pbuf 00000000fdf23d10
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
inet_chksum_pseudo(): checksumming pbuf 00000000fdf23d10 (has next 0000000000000000)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=807
udp_send: UDP checksum 0xf7f8
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 00000000fdf23d56 new 00000000fdf23d42 (20)
ip4_output_if: et0
IP header:

+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+

ip4_output_if: call netif->output()
pbuf_add_header: old 00000000fdf23d42 new 00000000fdf23d34 (14)
ethernet_output: sending packet 00000000fdf23d10
^^^ at this point a 350 byte packet gets sent to fecmxc_send for the NIC which looks like this via print_hex_dump_bytes():

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff  .P..............
00000020: ff ff 00 44 00 43 01 3c f8 f7 01 01 06 00 00 04  ...D.C.<........
00000030: 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00   !..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
Quoted 8 lines
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............

Up to this point everything *seems* OK

Quoted 17 lines

on my dhcp server 'tcpdump -i eth1 -X -vvv' shows:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:34:25.341167 [|llc]

0x0000:  0000 0000 0000 0000 0000 343d f2fd 0000  ..........4=....
0x0010:  0000 5e01 5e01 8000 0100 0000 0000 0000  ..^.^...........
0x0020:  0000 0000 0000 ffff ffff ffff 00d0 12ba  ................
0x0030:  f8cc 0800 4500 0150 001e 0000 ff11 ba7f  ....E..P........
0x0040:  0000 0000 ffff ffff 0044 0043 013c 6d78  .........D.C.<mx
0x0050:  0101 0600 1255 994f 0000 0000 0000 0000  .....U.O........
0x0060:  0000 0000 0000 0000 0000 0000 00d0 12ba  ................
0x0070:  f8cc 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 6382 5363  ............c.Sc
0x0140:  3501 0139 0205 dc37 0301 031c ff00 0000  5..9...7........

But here it shows the DHCP packet is not received.

Quoted 26 lines

Comparing to w/o LWIP:
u-boot=> dhcp || echo fail
BOOTP broadcast 1
fecmxc_send ethernet@30be0000 342

00000000: ff ff ff ff ff ff 00 d0 12 ba f8 cc 08 00 45 00  ..............E.
00000010: 01 48 00 00 40 00 ff 11 7a a5 00 00 00 00 ff ff  [email protected].......
00000020: ff ff 00 44 00 43 01 34 00 00 01 01 06 00 12 bb  ...D.C.4........
00000030: 82 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .d..............
00000040: 00 00 00 00 00 00 00 d0 12 ba f8 cc 00 00 00 00  ................
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 02  ......c.Sc5..9..
00000120: 40 5d 02 00 16 5e 03 01 00 00 3c 0c 55 2d 42 6f  @]...^....<.U-Bo
00000130: 6f 74 2e 61 72 6d 76 38 37 05 01 03 06 0c 11 ff  ot.armv87.......
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00                                ......
Quoted 1 line

^^^ Note the packet is 8 bytes shorter

Yes but that's just padding IIUC.

Quoted 35 lines

and on the dhcp server:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:45:12.548077 IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto UDP (17), length 328)

    0.0.0.0.bootpc > 255.255.255.255.bootps: [no cksum] BOOTP/DHCP,

Request from 00:d0:12:ba:f8:cc (oui Unknown), length 300, xid 0x12bb8264, Flags [none] (0x0000)
Client-Ethernet-Address 00:d0:12:ba:f8:cc (oui Unknown) Vendor-rfc1048 Extensions

    Magic Cookie 0x63825363
    DHCP-Message (53), length 1: Discover
    MSZ (57), length 2: 576
    ARCH (93), length 2: 22
    NDI (94), length 3: 1.0.0
    Vendor-Class (60), length 12: "U-Boot.armv8"
    Parameter-Request (55), length 5:
      Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6),
Hostname (12)
      RP (17)
    END (255), length 0
    PAD (0), length 0, occurs 22
0x0000:  4500 0148 0000 4000 ff11 7aa5 0000 0000  [email protected].....
0x0010:  ffff ffff 0044 0043 0134 0000 0101 0600  .....D.C.4......
0x0020:  12bb 8264 0000 0000 0000 0000 0000 0000  ...d............
0x0030:  0000 0000 0000 0000 00d0 12ba f8cc 0000  ................
0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
Quoted 8 lines
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 6382 5363 3501 0139  ........c.Sc5..9
0x0110:  0202 405d 0200 165e 0301 0000 3c0c 552d  ..@]...^....<.U-
0x0120:  426f 6f74 2e61 726d 7638 3705 0103 060c  Boot.armv87.....
0x0130:  11ff 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000                      ........

All good there, as expected.

Quoted 5 lines
Quoted 2 lines

I do have a i.MX8M Plus EVK board but will not be able to use it before tomorrow.

Please let me know your findings. I can test imx8mp as well but would have to reconfigure everything.

So I did some tests on my imx8mp and I got DHCP to work on the second ethernet port (ENET2) but *not* on the first one (ENET1). They appear to be using different drivers (drivers/net/fec_mxc.c for ENET1 and drivers/net/dwc_eth_qos.c for ENET2). No matter what I do, there is no packet going out of ENET1.

With a network cable plugged into ENET2 (ethernet@30bf0000):

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> dhcp
ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done DHCP client bound to address 192.168.0.39 (2066 ms)
u-boot=>

Now moving the cable to ENET1 (ethernet@30be0000) and resetting the board:

...

Net:   eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Hit any key to stop autoboot:  0

u-boot=>
u-boot=> setenv ethact ethernet@30be0000
u-boot=> dhcp
u-boot=> echo $?
1

Quoted 5 lines

I enabled the debug traces in fecmxc_send() but I see nothing wrong, the function is called with a packet and it returns success yet nothing is sent out on the wire. Any idea what could be wrong?
My plan is to add more traces to the driver and compare NET vs. NET_LWIP.

Jerome,

That is consistent with what I see then. The imx8mm (and all imx all the way back to imx28) use the FEC ethernet MAC so I would assume you see the issue on all of those SOC's. The imx8mp introduced a 2nd different MAC, the eqos which you are showing working.

Quoted 5 lines

If you look at my results above a packet 'is' received by the DHCP server but its missing something where tcpdump shows an '[|llc]' and I don't know what that means - something wrong with the link layer?

I feel like something is wrong in the header or packet alignment.

Good catch :) Here is a quick workaroud that works for me:

drivers/net/fec_mxc.c +16 -1
index 2dc1364beec..85bf1a2b52e 100644
@@ -658,7 +658,7 @@ static void fecmxc_halt(struct udevice *dev)
  * @param[in] length Data count in bytes
  * Return: 0 on success
  */
-static int fecmxc_send(struct udevice *dev, void *packet, int length)
+static int fecmxc_send_(struct udevice *dev, void *packet, int length)
 {
        unsigned int status;
        u32 size;
@@ -796,6 +796,21 @@ out:
        return ret;
 }
 
+static int fecmxc_send(struct udevice *dev, void *packet, int length)
+{
+       void *pp;
+       int ret;
+
+       pp = memalign(64, length);
+       if (!pp)
+               return -ENOMEM;
+       memcpy(pp, packet, length);
+       ret = fecmxc_send_(dev, pp, length);
+       free(pp);
+
+       return ret;
+}
+
 /**
  * Pull one frame from the card
  * @param[in] dev Our ethernet device to handle
Quoted 4 lines

I believe the root of the problem is that lwIP uses malloc() to allocate the outgoing packets and doesn't enforce any alignement. I need to revisit that wrt. PKTALIGN.

Yes, this makes sense. This driver uses DMA.

Glad we got to the bottom of it!

This hack does resolve the issue.

Best Regards,

Tim

#51 lore raw
In reply to Jerome Forissier

Hi Jerome,

Quoted 231 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Changes in v4:

- Fixed the DHCP algorithm which was missing a sys_timeout() call in the "fine timer" callback. This should close the issue that Tom R. reported with his Raspberry Pi 3 (it does fix it on mine).
- The DHCP exchange timeout is increased from 2 to 10 seconds
- The DHCP exchange can be interrupted with Ctrl-C.
- "net: introduce alternative implementation as net-lwip/": rework dependencies. A few symbols have 'depends on !NET_LWIP' and in addition 'NET_LWIP depends on !SANDBOX'. Sandbox, DSA and fastboot are unsupported, because they are deeply welded to the current stack.
- All network commands (dns, ping, tftp and wget):
* Get rid of global variables (Ilias A.)
* Use printf() rather than log_info()
- "net-lwip: add ping command": use packet count instead of timeout, fix code style (Ilias A.)
- Add "net: split cmd/net.c into cmd/net.c and cmd/net-common.c" extracted from the wget patch (Ilias A.).
- Add "net: split include/net.h into net{,-common,-legacy,-lwip}.h" (Ilias A.)
- Add "flash: prefix error codes with FL_" which is required to avoid name clashes when splitting net.h
- Reworked the initialization of the lwIP stack. One and only one network interface (struct netif) is added for the duration of the command that uses that interface. That's commit "net-lwip:
add DHCP support and dhcp commmand".
- Drop "test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y", not needed now that NET_LWIP depend on !SANDBOX.
- qemu_arm64_lwip_defconfig now enables CMD_DNS and CMD_WGET (so that all the supported network commands are available).

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 (14):
flash: prefix error codes with FL_
net: introduce alternative implementation as net-lwip/
net: split include/net.h into net{,-common,-legacy,-lwip}.h
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: split cmd/net.c into cmd/net.c and cmd/net-common.c
net-lwip: add wget command
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                           |  41 ++
 MAINTAINERS                       |  11 +
 Makefile                          |  12 +-
 board/cobra5272/flash.c           |  26 +-
 board/freescale/m5253demo/flash.c |   6 +-
 boot/Kconfig                      |   5 +-
 cmd/Kconfig                       |  44 ++
 cmd/Makefile                      |   7 +
 cmd/bdinfo.c                      |   5 +-
 cmd/net-common.c                  | 109 ++++
 cmd/net-lwip.c                    |  45 ++
 cmd/net.c                         | 115 ----
 common/Kconfig                    |   2 +-
 common/board_r.c                  |   4 +-
 common/flash.c                    |  44 +-
 common/spl/Kconfig                |   1 +
 configs/qemu_arm64_lwip_defconfig |   4 +
 drivers/dfu/Kconfig               |   1 +
 drivers/fastboot/Kconfig          |   1 +
 drivers/mtd/cfi_flash.c           |  36 +-
 drivers/net/Kconfig               |   3 +-
 drivers/net/phy/Kconfig           |   2 +-
 drivers/usb/gadget/Kconfig        |   2 +-
 include/flash.h                   |  20 +-
 include/net-common.h              | 408 +++++++++++++
 include/net-legacy.h              | 649 ++++++++++++++++++++
 include/net-lwip.h                |  36 ++
 include/net.h                     | 944 +-----------------------------
 lib/Makefile                      |   2 +
 lib/lwip/Makefile                 |  55 ++
 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                   | 108 ++++
 net-lwip/dns.c                    | 117 ++++
 net-lwip/eth_internal.h           |  35 ++
 net-lwip/net-lwip.c               | 270 +++++++++
 net-lwip/ping.c                   | 174 ++++++
 net-lwip/tftp.c                   | 226 +++++++
 net-lwip/wget.c                   | 269 +++++++++
 net/Kconfig                       |  14 -
 45 files changed, 3008 insertions(+), 1147 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-common.h
 create mode 100644 include/net-legacy.h
 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
Quoted 8 lines
 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

Would it be possible to put net-lwip in net/lwip? We should try to keep the directory structure clean / minimal.

Regards,
Simon

#52 lore raw

Hi Simon,

Quoted 244 lines · Simon Glass

Hi Jerome,

Quoted 231 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:
* 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 renames some enums in order to avoid a conflict when a later patch enables the lwIP library.

The second 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 third patch splits the net.h header into net-legacy.h, net-common.h, net-lwip.h, leaving net.h as a simple wrapper.

The fourth 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.

A number of features are currently incompatible with NET_LWIP: SANDBOX, DFU_TFTP, FASTBOOT, SPL_NET. All make assumptions on how the network stack is implemented and/or pull sybols that are not trivially exported from lwIP. Some interface rework may be needed.

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_defconfig but with NET_LWIP and CMD_*_LWIP enabled. Tests are added to test/py/tests/test_net.py for that configuration.

Changes in v4:

- Fixed the DHCP algorithm which was missing a sys_timeout() call in the "fine timer" callback. This should close the issue that Tom R. reported with his Raspberry Pi 3 (it does fix it on mine).
- The DHCP exchange timeout is increased from 2 to 10 seconds
- The DHCP exchange can be interrupted with Ctrl-C.
- "net: introduce alternative implementation as net-lwip/": rework dependencies. A few symbols have 'depends on !NET_LWIP' and in addition 'NET_LWIP depends on !SANDBOX'. Sandbox, DSA and fastboot are unsupported, because they are deeply welded to the current stack.
- All network commands (dns, ping, tftp and wget):
* Get rid of global variables (Ilias A.)
* Use printf() rather than log_info()
- "net-lwip: add ping command": use packet count instead of timeout, fix code style (Ilias A.)
- Add "net: split cmd/net.c into cmd/net.c and cmd/net-common.c" extracted from the wget patch (Ilias A.).
- Add "net: split include/net.h into net{,-common,-legacy,-lwip}.h" (Ilias A.)
- Add "flash: prefix error codes with FL_" which is required to avoid name clashes when splitting net.h
- Reworked the initialization of the lwIP stack. One and only one network interface (struct netif) is added for the duration of the command that uses that interface. That's commit "net-lwip:
add DHCP support and dhcp commmand".
- Drop "test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y", not needed now that NET_LWIP depend on !SANDBOX.
- qemu_arm64_lwip_defconfig now enables CMD_DNS and CMD_WGET (so that all the supported network commands are available).

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 (14):
flash: prefix error codes with FL_
net: introduce alternative implementation as net-lwip/
net: split include/net.h into net{,-common,-legacy,-lwip}.h
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: split cmd/net.c into cmd/net.c and cmd/net-common.c
net-lwip: add wget command
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                           |  41 ++
 MAINTAINERS                       |  11 +
 Makefile                          |  12 +-
 board/cobra5272/flash.c           |  26 +-
 board/freescale/m5253demo/flash.c |   6 +-
 boot/Kconfig                      |   5 +-
 cmd/Kconfig                       |  44 ++
 cmd/Makefile                      |   7 +
 cmd/bdinfo.c                      |   5 +-
 cmd/net-common.c                  | 109 ++++
 cmd/net-lwip.c                    |  45 ++
 cmd/net.c                         | 115 ----
 common/Kconfig                    |   2 +-
 common/board_r.c                  |   4 +-
 common/flash.c                    |  44 +-
 common/spl/Kconfig                |   1 +
 configs/qemu_arm64_lwip_defconfig |   4 +
 drivers/dfu/Kconfig               |   1 +
 drivers/fastboot/Kconfig          |   1 +
 drivers/mtd/cfi_flash.c           |  36 +-
 drivers/net/Kconfig               |   3 +-
 drivers/net/phy/Kconfig           |   2 +-
 drivers/usb/gadget/Kconfig        |   2 +-
 include/flash.h                   |  20 +-
 include/net-common.h              | 408 +++++++++++++
 include/net-legacy.h              | 649 ++++++++++++++++++++
 include/net-lwip.h                |  36 ++
 include/net.h                     | 944 +-----------------------------
 lib/Makefile                      |   2 +
 lib/lwip/Makefile                 |  55 ++
 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                   | 108 ++++
 net-lwip/dns.c                    | 117 ++++
 net-lwip/eth_internal.h           |  35 ++
 net-lwip/net-lwip.c               | 270 +++++++++
 net-lwip/ping.c                   | 174 ++++++
 net-lwip/tftp.c                   | 226 +++++++
 net-lwip/wget.c                   | 269 +++++++++
 net/Kconfig                       |  14 -
 45 files changed, 3008 insertions(+), 1147 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-common.h
 create mode 100644 include/net-legacy.h
 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
Quoted 8 lines
 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
Quoted 2 lines

Would it be possible to put net-lwip in net/lwip? We should try to keep the directory structure clean / minimal.

Sure.

Signature · 1 line
Jerome
Quoted 2 lines

Regards,
Simon