Skip to contentSkip to conversation

fastboot: lift restrictions on !NET_LWIP for USB

PATCH In review Michael Walle 5 participants 8 messages Mar 12, 2025 – Apr 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 fastboot: lift restrictions on !NET_LWIP for USB

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

---
Alternatively, we could add the defines and stub functions to the lwip header.

---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)
cmd/fastboot.c +4 -0
index d4cfc0c7a28..be84a482b81 100644
@@ -16,6 +16,7 @@
 #include <linux/printk.h>
 #include <linux/stringify.h>
 
+#if CONFIG_IS_ENABLED(NET)
 static int do_fastboot_udp(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)
 {
@@ -55,6 +56,7 @@ static int do_fastboot_tcp(int argc, char *const argv[],
 
 	return CMD_RET_SUCCESS;
 }
+#endif
 
 static int do_fastboot_usb(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)
@@ -160,10 +162,12 @@ NXTARG:
 
 	fastboot_init((void *)buf_addr, buf_size);
 
+#if CONFIG_IS_ENABLED(NET)
 	if (!strcmp(argv[1], "udp"))
 		return do_fastboot_udp(argc, argv, buf_addr, buf_size);
 	if (!strcmp(argv[1], "tcp"))
 		return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
+#endif
 	if (!strcmp(argv[1], "usb")) {
 		argv++;
 		argc--;
drivers/fastboot/Kconfig +0 -1
index 1eb460f5a02..70207573de2 100644
@@ -1,6 +1,5 @@
 menu "Fastboot support"
 	depends on CMDLINE
-	depends on !NET_LWIP
 
 config FASTBOOT
 	bool
drivers/fastboot/fb_common.c +4 -0
index 12ffb463deb..68f92c4b887 100644
@@ -183,11 +183,15 @@ void fastboot_handle_boot(int command, bool success)
 	switch (command) {
 	case FASTBOOT_COMMAND_BOOT:
 		fastboot_boot();
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif
 		break;
 
 	case FASTBOOT_COMMAND_CONTINUE:
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif
 		break;
 
 	case FASTBOOT_COMMAND_REBOOT:
Signature · 1 line
2.39.5
#1 lore raw

Sorry this should have been individual patches. Please read the subject as "[PATCH 1/1]" or just "[PATCH]".

-michael

Reviewed-by on v1 1/3
#2 lore raw
In reply to Michael Walle

Hi Michael,

Quoted 17 lines · Michael Walle

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

---
Alternatively, we could add the defines and stub functions to the lwip header.

---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)

[...]

Thanks,

Signature · 1 line
Jerome
#3 lore raw
In reply to Michael Walle

Hi Michael,

Thank you for the patch.

Quoted 9 lines · Michael Walle

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

checkpatch.pl reports some issues with this:

$ ./scripts/checkpatch.pl --strict --u-boot --git HEAD^..HEAD

<snip>
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible <snip>

Some occurences below could be fixed. Could you please have a look?

Quoted 14 lines

---
Alternatively, we could add the defines and stub functions to the lwip header.

---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)
cmd/fastboot.c +0 -0
index d4cfc0c7a28..be84a482b81 100644

cmd/fastboot.c line 19

Quoted 4 lines
cmd/fastboot.c +1 -0
@@ -16,6 +16,7 @@
 #include <linux/printk.h>
 #include <linux/stringify.h>
 
+#if CONFIG_IS_ENABLED(NET)

I think this can be dropped. I hope that since it's a static function, -if there are no users in the file- the compiler will optimize it out.
Note: I have not verified this, so I might be wrong.

If you measure and see size changes between keeping the #if and not keeping it, please ignore this comment.

Quoted 12 lines
cmd/fastboot.c +1 -0
 static int do_fastboot_udp(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)
 {
@@ -55,6 +56,7 @@ static int do_fastboot_tcp(int argc, char *const argv[],
 
 	return CMD_RET_SUCCESS;
 }
+#endif
 
 static int do_fastboot_usb(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)

cmd/fastboot.c NXTARG: · line 170

Quoted 9 lines
cmd/fastboot.c +2 -0
@@ -160,10 +162,12 @@ NXTARG:
 
 	fastboot_init((void *)buf_addr, buf_size);
 
+#if CONFIG_IS_ENABLED(NET)
 	if (!strcmp(argv[1], "udp"))
 		return do_fastboot_udp(argc, argv, buf_addr, buf_size);
 	if (!strcmp(argv[1], "tcp"))
 		return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
+#endif

This can be replaced with:

	if (IS_ENABLED(CONFIG_NET)) {
		if (!strcmp(argv[1], "udp"))
			return do_fastboot_udp(argc, argv, buf_addr, buf_size);
		if (!strcmp(argv[1], "tcp"))
			return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
	}
Quoted 19 lines
cmd/fastboot.c +0 -0
 	if (!strcmp(argv[1], "usb")) {
 		argv++;
 		argc--;
drivers/fastboot/Kconfig +0 -1
index 1eb460f5a02..70207573de2 100644
@@ -1,6 +1,5 @@
 menu "Fastboot support"
 	depends on CMDLINE
-	depends on !NET_LWIP
 
 config FASTBOOT
 	bool
drivers/fastboot/fb_common.c +0 -0
index 12ffb463deb..68f92c4b887 100644

drivers/fastboot/fb_common.c void fastboot_handle_boot(int command, bool success) · line 188

Quoted 6 lines
drivers/fastboot/fb_common.c +2 -0
@@ -183,11 +183,15 @@ void fastboot_handle_boot(int command, bool success)
 	switch (command) {
 	case FASTBOOT_COMMAND_BOOT:
 		fastboot_boot();
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif

This can be replaced with:

		if (IS_ENABLED((CONFIG_NET))
		    net_set_state(NETLOOP_SUCCESS);

drivers/fastboot/fb_common.c void fastboot_handle_boot(int command, bool success) · line 194

Quoted 6 lines
drivers/fastboot/fb_common.c +2 -0
 		break;
 
 	case FASTBOOT_COMMAND_CONTINUE:
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif

Same here.

Quoted 5 lines
drivers/fastboot/fb_common.c +0 -0
 		break;
 
 	case FASTBOOT_COMMAND_REBOOT:
Signature · 1 line
2.39.5
#4 lore raw

Hi Mattijs,

Quoted 12 lines
Quoted 9 lines

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

checkpatch.pl reports some issues with this:

Quoted 7 lines
$ ./scripts/checkpatch.pl --strict --u-boot --git HEAD^..HEAD

<snip>
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible <snip>

Some occurences below could be fixed. Could you please have a look?

I've seen these. More below.

Quoted 4 lines
Quoted 4 lines

---
Alternatively, we could add the defines and stub functions to the lwip header.

This is relevant :)

Quoted 14 lines
Quoted 14 lines
---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)
cmd/fastboot.c +0 -0
index d4cfc0c7a28..be84a482b81 100644
@@ -16,6 +16,7 @@
 #include <linux/printk.h>
 #include <linux/stringify.h>
 
Quoted 8 lines

cmd/fastboot.c line 19

Quoted 1 line
cmd/fastboot.c +1 -0
+#if CONFIG_IS_ENABLED(NET)

I think this can be dropped. I hope that since it's a static function, -if there are no users in the file- the compiler will optimize it out.
Note: I have not verified this, so I might be wrong.

If you measure and see size changes between keeping the #if and not keeping it, please ignore this comment.

No, because net_loop(), net_set_state() and NETLOOP_SUCCESS is only defined in net-legacy.h. Thus we need this ifdeffery.. Unless of course, we add the enums and function stubs to the new lwip net inlcude. I don't know if that's a good idea though.

-michael

Quoted 77 lines
Quoted 13 lines
cmd/fastboot.c +1 -0
 static int do_fastboot_udp(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)
 {
@@ -55,6 +56,7 @@ static int do_fastboot_tcp(int argc, char *const argv[],
 
 	return CMD_RET_SUCCESS;
 }
+#endif
 
 static int do_fastboot_usb(int argc, char *const argv[],
 			   uintptr_t buf_addr, size_t buf_size)

cmd/fastboot.c NXTARG: · line 170

Quoted 9 lines
cmd/fastboot.c +2 -0
@@ -160,10 +162,12 @@ NXTARG:
 
 	fastboot_init((void *)buf_addr, buf_size);
 
+#if CONFIG_IS_ENABLED(NET)
 	if (!strcmp(argv[1], "udp"))
 		return do_fastboot_udp(argc, argv, buf_addr, buf_size);
 	if (!strcmp(argv[1], "tcp"))
 		return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
+#endif

This can be replaced with:

	if (IS_ENABLED(CONFIG_NET)) {
		if (!strcmp(argv[1], "udp"))
			return do_fastboot_udp(argc, argv, buf_addr, buf_size);
		if (!strcmp(argv[1], "tcp"))
			return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
	}
Quoted 19 lines
cmd/fastboot.c +0 -0
 	if (!strcmp(argv[1], "usb")) {
 		argv++;
 		argc--;
drivers/fastboot/Kconfig +0 -1
index 1eb460f5a02..70207573de2 100644
@@ -1,6 +1,5 @@
 menu "Fastboot support"
 	depends on CMDLINE
-	depends on !NET_LWIP
 
 config FASTBOOT
 	bool
drivers/fastboot/fb_common.c +0 -0
index 12ffb463deb..68f92c4b887 100644

drivers/fastboot/fb_common.c void fastboot_handle_boot(int command, bool success) · line 188

Quoted 6 lines
drivers/fastboot/fb_common.c +2 -0
@@ -183,11 +183,15 @@ void fastboot_handle_boot(int command, bool success)
 	switch (command) {
 	case FASTBOOT_COMMAND_BOOT:
 		fastboot_boot();
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif

This can be replaced with:

		if (IS_ENABLED((CONFIG_NET))
		    net_set_state(NETLOOP_SUCCESS);

drivers/fastboot/fb_common.c void fastboot_handle_boot(int command, bool success) · line 194

Quoted 6 lines
drivers/fastboot/fb_common.c +2 -0
 		break;
 
 	case FASTBOOT_COMMAND_CONTINUE:
+#if CONFIG_IS_ENABLED(NET)
 		net_set_state(NETLOOP_SUCCESS);
+#endif

Same here.

Quoted 5 lines
drivers/fastboot/fb_common.c +0 -0
 		break;
 
 	case FASTBOOT_COMMAND_REBOOT:
Signature · 1 line
2.39.5
#5 lore raw
Quoted 16 lines · Michael Walle

Hi Mattijs,

Quoted 14 lines
Quoted 9 lines

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

checkpatch.pl reports some issues with this:

$ ./scripts/checkpatch.pl --strict --u-boot --git HEAD^..HEAD
Quoted 7 lines
Quoted 5 lines

<snip>
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible <snip>

Some occurences below could be fixed. Could you please have a look?

I've seen these. More below.

That is also my least favorite checkpatch warning, and it's a warning not an error. Best judgement is needed about making things readable rather than just silencing checkpatch.

Quoted 28 lines
Quoted 5 lines
Quoted 5 lines

---
Alternatively, we could add the defines and stub functions to the lwip header.

This is relevant :)

Quoted 20 lines
Quoted 11 lines
---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)
cmd/fastboot.c +0 -0
index d4cfc0c7a28..be84a482b81 100644

cmd/fastboot.c line 19

Quoted 4 lines
cmd/fastboot.c +1 -0
@@ -16,6 +16,7 @@
 #include <linux/printk.h>
 #include <linux/stringify.h>
 
+#if CONFIG_IS_ENABLED(NET)

I think this can be dropped. I hope that since it's a static function, -if there are no users in the file- the compiler will optimize it out.
Note: I have not verified this, so I might be wrong.

Quoted 7 lines
Quoted 2 lines

If you measure and see size changes between keeping the #if and not keeping it, please ignore this comment.

No, because net_loop(), net_set_state() and NETLOOP_SUCCESS is only defined in net-legacy.h. Thus we need this ifdeffery.. Unless of course, we add the enums and function stubs to the new lwip net inlcude. I don't know if that's a good idea though.

Yeah, I'm not sure that's worth it either, or at least as maybe only a future clean-up or investigate more. Perhaps filing an issue on source.denx.de on the -net tree so it's not forgotten?

Signature · 1 line
Tom
#6 lore raw

Hi Michael, Tom,

Quoted 21 lines · Tom Rini
Quoted 20 lines · Michael Walle

Hi Mattijs,

Quoted 18 lines
Quoted 9 lines

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

checkpatch.pl reports some issues with this:

$ ./scripts/checkpatch.pl --strict --u-boot --git HEAD^..HEAD

<snip>
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible <snip>

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Some occurences below could be fixed. Could you please have a look?

I've seen these. More below.

That is also my least favorite checkpatch warning, and it's a warning not an error. Best judgement is needed about making things readable rather than just silencing checkpatch.

I think that using if (IS_ENABLED(CONFIG...) is more readable in this case.
However ...

Quoted 29 lines
Quoted 29 lines
Quoted 6 lines
Quoted 6 lines

---
Alternatively, we could add the defines and stub functions to the lwip header.

This is relevant :)

Quoted 20 lines
Quoted 11 lines
---
 cmd/fastboot.c               | 4 ++++
 drivers/fastboot/Kconfig     | 1 -
 drivers/fastboot/fb_common.c | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)
cmd/fastboot.c +0 -0
index d4cfc0c7a28..be84a482b81 100644

cmd/fastboot.c line 19

Quoted 4 lines
cmd/fastboot.c +1 -0
@@ -16,6 +16,7 @@
 #include <linux/printk.h>
 #include <linux/stringify.h>
 
+#if CONFIG_IS_ENABLED(NET)

I think this can be dropped. I hope that since it's a static function, -if there are no users in the file- the compiler will optimize it out.
Note: I have not verified this, so I might be wrong.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

If you measure and see size changes between keeping the #if and not keeping it, please ignore this comment.

No, because net_loop(), net_set_state() and NETLOOP_SUCCESS is only defined in net-legacy.h. Thus we need this ifdeffery.. Unless of course, we add the enums and function stubs to the new lwip net inlcude. I don't know if that's a good idea though.

... my suggestion does not work without adding the defines and stub functions to the lwip header.
Apologies about that :( And thank you for being patient with my remarks.

This patch is fine as-is, and I don't want ifdeffery vs if IS_ENABLED to block this contribution.

Quoted 4 lines

Yeah, I'm not sure that's worth it either, or at least as maybe only a future clean-up or investigate more. Perhaps filing an issue on source.denx.de on the -net tree so it's not forgotten?

I'd like to do this future cleanup. I could not file an issue on
https://source.denx.de/u-boot/custodians/u-boot-net so I have opened one in the -dfu tree here:

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/issues/5

Quoted 3 lines
Signature · 2 lines
-- 
Tom
#7 lore raw
In reply to Michael Walle

Hi,

Quoted 9 lines · Michael Walle

Fastboot works either over TCP, UDP or USB. The latter doesn't have anything to do with networking, thus should work just fine with regardless which network stack is selected. In practice, header symbols are used inside common code paths. Add some ifdeffery to guard against that.

This will make fastboot over USB work with the new LWIP stack.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/3] fastboot: lift restrictions on !NET_LWIP for USB

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/d3c9f810f2b317ba376b4d9556e63a043b210355

--
Mattijs