Repository navigation
feat(start-wrt): factory reset from the FDL button - #4519
Conversation
The FDL button sits on QSPI_DATA3, a boot strap the BootROM samples only as the chip leaves reset. Declare it to the kernel's built-in gpio-keys driver and watch the input device from a procd service, `startwrt startwrt-fdl-reset`, for the life of the system. A press held for 10 seconds blinks sys-led, and the release wipes the overlay and reboots. Acting on release keeps the strap low across the reboot, so a completed hold cannot land in download mode. The service asks the kernel for the key state on startup, so a hold started before it runs counts. It runs as its own respawned process, so it works when the daemon does not. The device tree is a plain target dts that includes the vendor k1-x_deb1.dts, rather than a kernel patch, and keeps its name for the boot firmware. gpio-button-hotplug and rc.button are not used: they need broadcast_uevent, an OpenWrt kernel hack absent from the K1's 6.18 kernel.
3526ad7 to
279574e
Compare
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
helix-white
left a comment
There was a problem hiding this comment.
Requesting changes for two reset-safety issues in projects/start-wrt/backend/ctrl/src/fdl_button.rs.
-
[P1] A queued early release can cause a factory reset (lines 44–58, 123–141). The loop checks the deadline before consuming pending events, and replaces kernel event timestamps with processing time. If the watcher is delayed between iterations after observing a press, a release before ten seconds can already be queued when
step()arms and blinks. Reading that release then clearsheld_sincewithout clearingarmed, so the next iteration wipes the overlay. This contradicts the documented early-release cancellation guarantee. The proposal selects the monotonic evdev clock, preserves event timestamps, and cancels releases that precede the LED cue—even when processing happens later. -
[P2] Queue overflow preserves invalid hold history (lines 87–96). The parser silently discards
EV_SYN/SYN_DROPPED. After enough button transitions accumulate while the watcher cannot run, evdev can drop an intervening release/repress pair; the retainedheld_since/armedstate can then authorize a wipe without a continuous hold. Linux explicitly marks this event as lost state requiring resynchronization. The proposal fails closed and reuses the existing procd respawn/startupEVIOCGKEYpath for fresh observation, restoring the heartbeat cue rather than retaining an armed blink.
The proposal records these cancellation guarantees beside their production owner and adds regression cases for delayed releases, cue ordering, event timestamps, and overflow. It leaves the RPC reset path and device tree unchanged.
Proposed changes: 279574e...proposal/4519
Reviewed head: 279574e6c049064e93e414cbf04094bc1ea6ff63; merges cleanly with current master. No reviewer builds, tests, or lint runs; proposed tests are unexecuted and belong to the author to verify if adopted. CI is still running, including StartWRT tests and the riscv64 binary build.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
|
helix-white
left a comment
There was a problem hiding this comment.
Approving a120752af. Since my review of 279574e6c, the branch has gained two things: my proposal 8b99c406d, adopted unchanged, and a merge of master that changes none of this PR's lines. It merges cleanly with current master. Both earlier findings are resolved:
- A release whose kernel timestamp precedes the LED cue now cancels, even when the watcher reads it after a delayed tick.
SYN_DROPPEDnow discards the hold, and procd restarts the watcher from the live key state.
I re-read the adopted watcher as part of the whole diff and found nothing further. This pass covered:
- a re-press queued behind a cancelled release;
- the buffer flush and
SYN_DROPPEDthatEVIOCSCLOCKIDcan queue at startup; - the riscv64
input_eventlayout; - whether anything else drives
sys-led. Nothing does:01_ledsonly configures the WAN netdev LED, and the K1 target has nodiag.sh.
PR brief
Summary
- On the four-port Start9 Router, holding the FDL pinhole button for 10 s switches the status LED (
sys-led) from its heartbeat to a 100 ms timer blink. Releasing after that runsfirstboot -y, the same overlay wipe the web UI's Factory Reset performs, and reboots. - Releasing before the blink cancels and leaves the heartbeat. The watcher judges this by the kernel's event timestamp, so a release it reads late still cancels.
- The wipe waits for release, so the FDL strap the BootROM samples is low when the router restarts. A reboot with the button still held would land in download mode.
- The watcher is a new
startwrt startwrt-fdl-resetentry point of the multi-call binary. A procd service,startwrt-fdl-reset(START=11, respawn), runs it for the life of the system. It reads the key state at start (EVIOCGKEY), then follows evdev events timed onCLOCK_MONOTONIC. - If the kernel reports a dropped input queue (
SYN_DROPPED), the watcher abandons the hold and exits. procd restarts it 5 s later from the live key state with the LED back on heartbeat, so a hold in progress restarts its 10 s count. - Device tree: an overlay
k1-x_deb1.dtsincludes the vendor file and declares GPIO 98 as agpio-keysKEY_RESTARTinput with a pull-down. GPIO 98 is the pad QSPI_DAT3, which carries the FDL strap. The overlay also disables theqspicontroller that owns that pad. k1-sbc.mknow builds from the overlay directory, so the DTB keeps its name. The single-LAN-port router gets the same DTB; its pad is unconnected, and the pull-down keeps the key released.system.rsaddswipe_overlay_and_rebootfor the button path. It writes no activity-log entry, because the wipe deletes/var/lib/startwrtand logging afterwards would recreate it in the reset state. Thesystem.factory-resetRPC behaves as before.- Docs: a "Soft Reset (Factory-Reset Button)" section on the Factory Reset page, plus a FAQ mention. A
minor-addedfragment bumps StartWRT from 1.4.1 to 1.5.0; the latest stable tag isstart-wrt/v1.4.0.
Implementation diff: +291 / −8 lines in 10 files (excludes lockfiles, tests, docs, release notes, and changelog).
Approach
- OpenWrt's usual button path,
gpio-button-hotplugwithrc.button, needsbroadcast_uevent, an OpenWrt generic kernel hack. The overlay supplies none for the K1's 6.18 kernel. The PR uses the mainlinegpio-keysdriver and evdev instead. - Timestamp-based cancellation and overflow handling came from a review proposal by @helix-white (commit
8b99c406d), adopted unchanged. Recovery after an overflow reuses procd's respawn and the startupEVIOCGKEYread. - Disabling
qspiapplies to every board the image runs on, and the install docs support flashing any bare BPI-F3. The vendor reference DTS declares a SPI-NOR on that controller, so on a bare BPI-F3 with one fitted, Linux no longer sees it. - StartWRT never reads SPI-NOR; it provisions boot firmware to the eMMC boot partitions. The SPI-NOR probe read an all-zero JEDEC ID on the one tested unit of each Start9 model.
Limits and exposure
HOLDis 10 s, a chosen value; the docs tell users to hold for 10–15 s.- Recovery relies on procd's default respawn policy: a restart 5 s after each exit. After six consecutive runs shorter than an hour, procd stops restarting the watcher, and the button is inert until reboot. Only repeated queue overflows or device errors reach that. An overflow needs about 16 press-and-release pairs queued while the watcher cannot run.
- Anyone with physical access to a four-port router can now erase its configuration, including the admin password, without logging in. The first person to reach its setup portal afterwards sets a new admin password. Physical access already allowed the same through a microSD reflash.
Neighbors
- #4691 changes the same
versionline, to 1.4.1, and already conflicts withmaster. Whichever of the two merges second takes 1.5.0 and the matchingCargo.lockline. - This PR adds no conflict with #4613 or #4711 beyond those they already have with
master. - Not settled here: the FAQ's steady-green-light entry, from #4775, says red only shows power and green is the heartbeat, without naming a model. This PR's page says the four-port router's heartbeat light is red. If the two models' LEDs differ, that FAQ entry misleads four-port owners. I can't check the hardware; the author can.
Testing (recorded by the author; I ran nothing)
- On
8b99c406d, the reviewed code before themastermerge,make start-wrt-testpassed: 988 + 37 tests, 1 ignored. That includes 12 button tests covering late releases on either side of the cue, timestamp parsing and overflow. rustfmt, taplo andchangelog.mjs check-versionalso passed. - Before and after the review changes, the watcher ran on a single-LAN-port router against a uinput device named
gpio-keys, withfirstbootandrebootstubbed. It was stopped and resumed to simulate stalls.- The old watcher wiped on a late early release and on an overflow. The new one did neither.
- The new one still blinked and wiped after a real 10 s hold.
- A full image built from the pre-review code was sysupgraded, settings kept, onto a four-port router.
- The input device, GPIO 98 with an edge IRQ and the watcher under procd were all present, and the QSPI controller was gone.
- A physical hold blinked the LED, erased the overlay on release, and rebooted to defaults with the watcher running.
bench.sh smokepassed afterwards.
- On a single-LAN-port router, U-Boot read GPIO 98 low with this pull-down and high with a pull-up, so nothing on the board drives the pin.
- Not exercised end to end:
- The final watcher against the real
gpio-keysdriver, or with a physical press in a flashed image. Those checks ran the pre-review watcher. - The DTS and init script in CI. PR CI skips the OpenWrt image build, so they were built only in the author's pre-review image.
- CI on the merge head. StartWRT Tests, the riscv64 StartWRT binary build, the product builds and the start-core tests are still pending. Formatting, Prettier, changelog/version and licence checks have passed.
- The final watcher against the real
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
Summary
Adds a hardware factory reset to StartWRT for the four-port Start9 Router, using the K1's FDL button.
openwrt-overlay/target/linux/spacemit/dts/k1-x_deb1.dtsincludes the vendork1-x_deb1.dtsand declares GPIO 98 (QSPI_DATA3, the FDL strap) as agpio-keysKEY_RESTARTinput with an internal pull-down, disabling the unusedqspicontroller whose pin it takes.k1-sbc.mkpointsDEVICE_DTS_DIRat it, so the dtb keeps its name for the boot firmware. No kernel patch;CONFIG_KEYBOARD_GPIOandCONFIG_INPUT_EVDEVwere already set.fdl_button.rsruns asstartwrt startwrt-fdl-resetfrom a procd service (S11startwrt-fdl-reset, respawned) for the life of the system. It reads the key state withEVIOCGKEYat start, then follows input events, timed by their kernel timestamps on the monotonic clock. A hold of 10 s setssys-ledto a 100 ms timer blink; a release after that cue runsfirstboot -yand reboots. A release that happened before the cue cancels, even when the watcher reads it late, and puts the LED back on heartbeat. If the kernel reports a dropped input queue (SYN_DROPPED), the watcher discards the hold and exits, and procd restarts it from the live key state. Acting on release keeps the strap low across the reboot so a completed hold cannot land in the BootROM's download mode.system::wipe_overlay_and_rebootis the button's path and does not write to the activity log, whose directory the wipe removes. The RPCsystem.factory-resetkeeps its existing behaviour.minor-addedfragment, with StartWRT bumped to 1.5.0.gpio-button-hotplug/rc.buttonwere rejected: they needbroadcast_uevent, an OpenWrt kernel hack absent from the K1's 6.18 kernel.The device tree reaches the single-LAN-port router too, which has no buttons and no SPI-NOR fitted. There GPIO 98 is unconnected, so the pull-down holds it released and the watcher stays idle.
Verification
Run on 8b99c40; master f09a255 was then merged in without conflicts (a120752) and left to CI. The image and physical checks ran on images built before the review round; the watcher checks below ran on the round's binary.
make start-wrt-test: 988 + 37 pass (1 ignored), including 12 button tests (hold, early release, a release read late before and after the cue, repeat events, hold long after boot, kernel timestamp parsing, parse filtering, queue overflow).changelog.mjs check-versionok (1.5.0).gpio-keysstood in for it, and the watcher ran from/tmpwithfirstbootandrebootreplaced by logging stubs. With the watcher stopped and resumed to simulate a stall:make start-wrt-image) and sysupgraded onto a four-port router with settings kept:gpio-keysinput device present, GPIO 98 registered as FDL with an edge IRQ, watcher running under procd with respawn,sys-ledon heartbeat, QSPI controller gone (that unit's SPI-NOR probe had read an all-zero JEDEC id, so nothing was populated).gpio-keysdevice: LED switched to the timer blink at 10 s; releasing with the watcher stopped wiped nothing; the restarted watcher read the key as up and stayed idle.firstbooterased the overlay one second after release, procd rebooted, and the router came back on defaults with no root password, the Wi-Fi key restored from the EEPROM, and the watcher running.bench.sh smokepasses on the reset router./proc/mtdis empty, so disablingqspiloses nothing. In U-Boot, with pad 93 (QSPI_DAT3) set to this dts's value0xa441(GPIO, pull-down),gpio input 98read 0 on eight reads over about ten seconds, matching the GPIO level register; with a pull-up instead (0xc441) it read 1, so nothing on the board drives the pin. The router booted normally afterwards andbench.sh smokepassed.