fangpeina opened a new pull request, #3760:
URL: https://github.com/apache/nuttx-apps/pull/3760
## Summary
Add a serial (UART) transport backend to the fastboot daemon, alongside
the existing USB and TCP transports. This enables fastboot on devices
where neither USB nor network is available — only a UART port is needed.
The serial backend reuses the TCP v1 wire framing (FB01 handshake +
8-byte big-endian length prefix), so the host side needs no new tool:
socat bridges the UART to a TCP socket and the standard fastboot client
connects via `tcp:`.
## Changes
- fix a bug where read_all did not advance the buffer pointer.
- allow individual transport enable/disable (SYSTEM_FASTBOOTD_USB,
SYSTEM_FASTBOOTD_TCP).
- factor out the 8-byte length-prefix frame parsing shared by TCP and
Serial.
- the new serial transport implementation
## Impact
- **Features**: New serial transport for fastboot; USB and TCP transports
can now be individually enabled/disabled via Kconfig
- **User Experience**: Enables fastboot on UART-only devices
- **Build**: New Kconfig options (SYSTEM_FASTBOOTD_SERIAL,
SYSTEM_FASTBOOTD_USB, SYSTEM_FASTBOOTD_TCP); no breaking changes to existing
configs
- **Compatibility**: Fully backward compatible; existing USB/TCP behavior
unchanged
## Testing
All tests based on `sim:nsh`.
```
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
# Apply transport-specific configs via menuconfig
cmake --build build
```
### Configuration
**Core**
```
CONFIG_SYSTEM_FASTBOOTD=y
CONFIG_SYSTEM_FASTBOOTD_DOWNLOAD_MAX=65536
```
**Flash Support (enabled on sim:nsh)**
```
CONFIG_FS_FAT=y
CONFIG_ETC_ROMFS=y # auto-creates /dev/ram0/1/2
CONFIG_ETC_ROMFSDEVNO=1 # /dev/ram1
CONFIG_ETC_FATDEVNO=2 # /dev/ram2 (usable for flash test)
```
**Transport Layer (Select one from USB, TCP, or Serial; multiple selections
allowed)**
```
── Serial ──
CONFIG_SYSTEM_FASTBOOTD_SERIAL=y
CONFIG_SYSTEM_FASTBOOTD_SERIAL_PORT="/dev/ttyFB"
CONFIG_SERIAL_TERMIOS=y
CONFIG_SIM_UART_NUMBER=1
CONFIG_SIM_UART_PTY=y
CONFIG_SIM_UART0_NAME="/dev/ttyFB"
── TCP ──
CONFIG_SYSTEM_FASTBOOTD_TCP=y
CONFIG_NET=y
CONFIG_NET_TCP=y
CONFIG_NET_TCPBACKLOG=y
CONFIG_SYSTEM_FASTBOOTD_NET_INIT=y
CONFIG_SIM_NETDEV=y
CONFIG_SIM_NETDEV_TAP=y
CONFIG_NETINIT_IPADDR=0x0a000002 # 10.0.0.2
CONFIG_NETINIT_DRIPADDR=0x0a000001 # 10.0.0.1 (host bridge)
── USB ──
CONFIG_SYSTEM_FASTBOOTD_USB=y
CONFIG_USBADB=y
CONFIG_USBFASTBOOT=y
CONFIG_USBDEV_FS=y
CONFIG_USBDEV_DUALSPEED=y
CONFIG_SIM_USB_DEV=y
CONFIG_SIM_USB_RAW_GADGET=y
CONFIG_SIM_LOOP_INTERVAL=1
```
### Verification
**1. Serial Transport**
Setup:
```
# Terminal 1: socat bridge (UART PTY ↔ TCP socket)
sudo socat -t 0 PTY,link=/dev/ttyFB,raw,echo=0
TCP-LISTEN:5556,reuseaddr,fork,nodelay &
sudo chmod 777 /dev/ttyFB
# Terminal 2: NuttX sim
cd build_fastboot_serial && sudo ./nuttx
nsh> fastbootd &
```
Test output
```
# 1. Query device info
$ fastboot -s tcp:127.0.0.1:5556 getvar version
version: 13.0.1
Finished. Total time: 0.010s
$ fastboot -s tcp:127.0.0.1:5556 getvar max-download-size
max-download-size: 65536
Finished. Total time: 0.010s
# 2. Download (within max-download-size)
$ fastboot -s tcp:127.0.0.1:5556 stage /tmp/test_64k.bin
Sending '/tmp/test_64k.bin' (64 KB) OKAY [ 0.012s]
Finished. Total time: 0.022s
# 3. Flash with sparse split (payload > max-download-size)
$ fastboot -s tcp:127.0.0.1:5556 flash ram2 /tmp/test_128k.bin
Invalid sparse file format at header magic
Sending sparse 'ram2' 1/3 (60 KB) OKAY [ 0.022s]
Writing 'ram2' OKAY [ 0.008s]
Sending sparse 'ram2' 2/3 (60 KB) OKAY [ 0.030s]
Writing 'ram2' OKAY [ 0.010s]
Sending sparse 'ram2' 3/3 (8 KB) OKAY [ 0.060s]
Writing 'ram2' OKAY [ 0.010s]
Finished. Total time: 0.170s
# 4. Erase partition
$ fastboot -s tcp:127.0.0.1:5556 erase ram2
Erasing 'ram2' OKAY [ 0.011s]
Finished. Total time: 0.031s
```
**2. TCP Transport**
Setup:
```
# Terminal 1: create host bridge (one-time)
sudo ip link add nuttx0 type bridge
sudo ip addr add 10.0.0.1/24 dev nuttx0
sudo ip link set nuttx0 up
# Terminal 2: NuttX sim (TAP auto-joins bridge on boot)
cd build_fastboot_tcp && sudo ./nuttx
nsh> fastbootd &
```
Test output
```
# 1. Query device info
$ fastboot -s tcp:10.0.0.2:5554 getvar version
version: 13.0.1
Finished. Total time: 0.060s
$ fastboot -s tcp:10.0.0.2:5554 getvar max-download-size
max-download-size: 65536
Finished. Total time: 0.060s
# 2. Download (within max-download-size)
$ fastboot -s tcp:10.0.0.2:5554 stage /tmp/test_64k.bin
Sending '/tmp/test_64k.bin' (64 KB) OKAY [ 0.120s]
Finished. Total time: 0.180s
# 3. Flash with sparse split (payload > max-download-size)
$ fastboot -s tcp:10.0.0.2:5554 flash ram2 /tmp/test_128k.bin
Invalid sparse file format at header magic
Sending sparse 'ram2' 1/3 (60 KB) OKAY [ 0.120s]
Writing 'ram2' OKAY [ 0.060s]
Sending sparse 'ram2' 2/3 (60 KB) OKAY [ 0.120s]
Writing 'ram2' OKAY [ 0.060s]
Sending sparse 'ram2' 3/3 (8 KB) OKAY [ 0.120s]
Writing 'ram2' OKAY [ 0.060s]
Finished. Total time: 0.720s
# 4. Erase partition
$ fastboot -s tcp:10.0.0.2:5554 erase ram2
Erasing 'ram2' OKAY [ 0.060s]
Finished. Total time: 0.180s
```
**3. USB Transport**
Setup:
```
# Terminal 1: load kernel modules (one-time)
sudo modprobe raw_gadget
sudo modprobe dummy_hcd
# Terminal 2: NuttX sim
cd build_fastboot_usb && sudo ./nuttx
nsh> fastbootd &
```
Test output
```
$ fastboot devices
1234 fastboot
# 1. Query device info
$ sudo fastboot getvar version
version: 13.0.1
Finished. Total time: 0.007s
$ sudo fastboot getvar max-download-size
max-download-size: 65536
Finished. Total time: 0.004s
# 2. Download (within max-download-size)
$ sudo fastboot stage /tmp/test_64k.bin
Sending '/tmp/test_64k.bin' (64 KB) OKAY [ 0.650s]
Finished. Total time: 0.653s
# 3. Flash with sparse split (payload > max-download-size)
$ sudo fastboot flash ram2 /tmp/test_128k.bin
Invalid sparse file format at header magic
Sending sparse 'ram2' 1/3 (60 KB) OKAY [ 0.620s]
Writing 'ram2' OKAY [ 0.010s]
Sending sparse 'ram2' 2/3 (60 KB) OKAY [ 0.620s]
Writing 'ram2' OKAY [ 0.010s]
Sending sparse 'ram2' 3/3 (8 KB) OKAY [ 0.100s]
Writing 'ram2' OKAY [ 0.010s]
Finished. Total time: 1.398s
# 4. Erase partition
$ sudo fastboot erase ram2
Erasing 'ram2' OKAY [ 0.011s]
Finished. Total time: 0.026s
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]