From 5f3db8453bf2e4cff0c7d6efb9159d05e7bb2eab Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 1 Oct 2026 15:19:12 -0600 Subject: [PATCH] S50usbdevice: an unset USB role is client 0004's gate read a missing /userdata/warden/role as router, so a fresh store never composed the gadget and the panel had no usb0 until its second boot (flare-edge#278). Every other role reader defaults unset to client. 0014 changes the gate to match. A new patch rather than an edit to 0004: build-firmware.sh skips an edited, already-applied 0004 as inconclusive, so the runner SDK would keep the old gate. 0014 applies on a pristine replay and on a tree that already carries 0004 and 0008. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg --- luckfox-sdk-patches/README.md | 10 +++++ ...14-s50usbdevice-unset-role-is-client.patch | 45 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 luckfox-sdk-patches/board/patches/0014-s50usbdevice-unset-role-is-client.patch diff --git a/luckfox-sdk-patches/README.md b/luckfox-sdk-patches/README.md index 7a37651..fb54829 100644 --- a/luckfox-sdk-patches/README.md +++ b/luckfox-sdk-patches/README.md @@ -307,6 +307,16 @@ header explains its change. | `0012-drop-s50sshd.patch` | `overlay-luckfox-buildroot-init/etc/init.d/S50sshd` | deletes the generic sshd starter; dropbear provides SSH | | `0013-e2fsprogs-build-cflags.patch` | `sysdrv/tools/board/e2fsprogs/Makefile` | `BUILD_CFLAGS` so the host helpers build with gcc 14 | +### `board/patches/0014-s50usbdevice-unset-role-is-client.patch` + +0004's S50usbdevice gate read an unset role as router, so a fresh `/userdata` +never composed the USB gadget and the panel had no `usb0` until its second +boot (flare-edge#278). 0014 makes unset mean client (0), like every other +role reader; flare-edge's `tests/guards/run-role-default-tests.sh` pins the +gate to them. It is a separate patch, not an edit to 0004, because +`build-firmware.sh` would skip an edited 0004 as inconclusive on an SDK that +already carries 0004 and 0008. + ## Config fragments | fragment | why | diff --git a/luckfox-sdk-patches/board/patches/0014-s50usbdevice-unset-role-is-client.patch b/luckfox-sdk-patches/board/patches/0014-s50usbdevice-unset-role-is-client.patch new file mode 100644 index 0000000..52b19cf --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0014-s50usbdevice-unset-role-is-client.patch @@ -0,0 +1,45 @@ +Treat an unset USB role as client in S50usbdevice. + +0004 gated the gadget build on `role || echo 1`, so a fresh /userdata (no +role file) read as router and S50usbdevice exited before composing the +gadget. Every other reader (flare-edge S26usbhost, S35iptables, +usb-nic-hotplug.sh, wifi-link-watchdog.sh, flared's schema) defaults an +unset role to client (0), so S26usbhost put the port in device role with no +gadget to bind: a freshly provisioned or factory-reset panel had no usb0 +recovery link until its second boot (flare-edge#278). + +A separate patch rather than an edit to 0004: tools/build-firmware.sh +applies the series idempotently, and on an SDK that already carries 0004 +and 0008 an edited 0004 neither applies nor reverse-applies, so it would be +skipped as inconclusive and the old gate would keep shipping. This one +applies on top of either a pristine replay or an already-patched tree. + +diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice +index b521af4..fd8b693 100755 +--- a/sysdrv/tools/board/android-tools/S50usbdevice ++++ b/sysdrv/tools/board/android-tools/S50usbdevice +@@ -6,12 +6,19 @@ + # Load default env variables from profiles + . /etc/profile + +-# flare-edge: the OTG port is a USB HOST in router (and the unset-role default), +-# so building a gadget here is pointless AND harmful — the dwc3 "failed to add ++# flare-edge: only build the gadget in client role. A router's OTG port is a ++# USB HOST, where a gadget is pointless AND harmful: the dwc3 "failed to add + # gadget" + the usb2-phy "illegal mode" it triggers race with the USB-Ethernet +-# host enumeration and intermittently kill eth1 at boot. Only run in client role; +-# S26usbhost re-invokes this explicitly when switching to client. (unset -> router) +-[ "$(cat /userdata/warden/role 2>/dev/null || echo 1)" = "1" ] && exit 0 ++# host enumeration and intermittently kill eth1 at boot. S26usbhost re-invokes ++# this explicitly when switching to client. ++# ++# An UNSET role is client (0), the fresh-install default every other reader ++# uses (S26usbhost, S35iptables, usb-nic-hotplug.sh, wifi-link-watchdog.sh, ++# flared's schema). This gate used to read unset as router, so a fresh store ++# set the port to device role with no gadget to bind and came up with no usb0 ++# until a second boot (flare-edge#278). flare-edge's ++# tests/guards/run-role-default-tests.sh pins this line to the other readers. ++[ "$(cat /userdata/warden/role 2>/dev/null || echo 0)" = "1" ] && exit 0 + + UMS_EN=off + ADB_EN=on -- 2.54.0