Skip to content

system/fastboot: fix socket() parameter order for TCP transport#3429

Open
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:fb_socket
Open

system/fastboot: fix socket() parameter order for TCP transport#3429
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:fb_socket

Conversation

@JianyuWang0623
Copy link
Contributor

@JianyuWang0623 JianyuWang0623 commented Mar 20, 2026

Note: Please adhere to Contributing Guidelines.

Summary

In fastboot_tcp_initialize(), SOCK_CLOEXEC and SOCK_NONBLOCK were passed as the third argument (protocol) of socket() instead of being OR'd into the second argument (type).

The resulting protocol value (SOCK_CLOEXEC | SOCK_NONBLOCK = 0x80800) is not a valid protocol number, causing socket() to fail on both Linux (EINVAL) and NuttX (EPROTONOSUPPORT). This means TCP transport has never worked.

Fix: move SOCK_CLOEXEC | SOCK_NONBLOCK into the type parameter and set protocol to 0.

// Before (broken):
socket(AF_INET, SOCK_STREAM, SOCK_CLOEXEC | SOCK_NONBLOCK);

// After (correct):
socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);

Impact

Without this fix, fastbootd TCP transport fails on startup and cannot accept any connections. USB transport is not affected.

No API or configuration changes. Existing defconfigs with CONFIG_SYSTEM_FASTBOOT_TCP=y will now work correctly without any modification.

Testing

  • Host: Ubuntu 22.04 x86_64, GCC 14.2.0 (Xtensa esp32s3 cross-compiler)
  • Target: xtensa, lckfb-szpi-esp32s3:fastboot_tcp (ESP32-S3)

Build:

$ make -j$(nproc)

Runtime verification (before fix):

nsh> fastbootd &
create socket failed 93

Runtime verification (after fix):

nsh> fastbootd &

$ fastboot -s tcp:192.168.137.81 getvar version
version: 12.12.0

SOCK_CLOEXEC and SOCK_NONBLOCK were incorrectly passed as the
third argument (protocol) instead of being OR'd into the second
argument (type). This caused socket() to fail with EPROTONOSUPPORT
(errno 93) on NuttX.

Move SOCK_CLOEXEC | SOCK_NONBLOCK to the type parameter and set
protocol to 0.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@xiaoxiang781216
Copy link
Contributor

@JianyuWang0623 but we should follow/support Linux behavior?

@JianyuWang0623 JianyuWang0623 marked this pull request as draft March 20, 2026 07:57
@JianyuWang0623
Copy link
Contributor Author

@JianyuWang0623 but we should follow/support Linux behavior?

@xiaoxiang781216 Incorrect summary description (updated). The original code did not work properly on both NuttX and Linux.

@JianyuWang0623 JianyuWang0623 marked this pull request as ready for review March 20, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants