S50usbdevice: an unset USB role is client (flare-edge#278) #9

Merged
noah merged 1 commits from fix-278-s50-role-default into flare-edge-next 2026-10-01 16:04:39 -06:00
2 changed files with 55 additions and 0 deletions
+10
View File
@@ -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 |
@@ -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