Skip to content

feat(start-wrt): factory reset from the FDL button - #4519

Merged
dr-bonez merged 3 commits into
masterfrom
wrt/fdl-factory-reset
Nov 19, 2026
Merged

dr-bonez merged 3 commits into
masterfrom
wrt/fdl-factory-reset

Conversation

@Dominion5254

@Dominion5254 Dominion5254 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a hardware factory reset to StartWRT for the four-port Start9 Router, using the K1's FDL button.

  • Device tree. openwrt-overlay/target/linux/spacemit/dts/k1-x_deb1.dts includes the vendor k1-x_deb1.dts and declares GPIO 98 (QSPI_DATA3, the FDL strap) as a gpio-keys KEY_RESTART input with an internal pull-down, disabling the unused qspi controller whose pin it takes. k1-sbc.mk points DEVICE_DTS_DIR at it, so the dtb keeps its name for the boot firmware. No kernel patch; CONFIG_KEYBOARD_GPIO and CONFIG_INPUT_EVDEV were already set.
  • Watcher. fdl_button.rs runs as startwrt startwrt-fdl-reset from a procd service (S11startwrt-fdl-reset, respawned) for the life of the system. It reads the key state with EVIOCGKEY at start, then follows input events, timed by their kernel timestamps on the monotonic clock. A hold of 10 s sets sys-led to a 100 ms timer blink; a release after that cue runs firstboot -y and 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.
  • Wipe path. system::wipe_overlay_and_reboot is the button's path and does not write to the activity log, whose directory the wipe removes. The RPC system.factory-reset keeps its existing behaviour.
  • Docs and fragment. The Factory Reset page gains a "Soft Reset (Factory-Reset Button)" section: which pinhole, the sequence, the red-LED cue, that only the four-port router has buttons, and that it is a last resort. The FAQ's forgotten-password answer names the button as a way to reset without logging in. minor-added fragment, with StartWRT bumped to 1.5.0.

gpio-button-hotplug / rc.button were rejected: they need broadcast_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).
  • rustfmt (pinned nightly), taplo clean; changelog.mjs check-version ok (1.5.0).
  • Watcher on a K1, binaries before and after the review round. The single-LAN-port router has no button, so a uinput device named gpio-keys stood in for it, and the watcher ran from /tmp with firstboot and reboot replaced by logging stubs. With the watcher stopped and resumed to simulate a stall:
    • A release 4 s into a hold, queued behind another event, wiped on resume before the round; after it, nothing is wiped and the LED returns to heartbeat.
    • A queue overflow that dropped 16 release/press pairs (last press 5 s before the release) wiped before the round; after it, the watcher exits with "hold history lost", the LED stays on heartbeat, and nothing is wiped.
    • A hold that starts while the watcher is stalled blinks as soon as it resumes past 10 s and wipes on release.
    • A 10.5 s hold blinks at 10 s and wipes on release; a 5 s hold does nothing.
  • Full image built (make start-wrt-image) and sysupgraded onto a four-port router with settings kept: gpio-keys input device present, GPIO 98 registered as FDL with an edge IRQ, watcher running under procd with respawn, sys-led on heartbeat, QSPI controller gone (that unit's SPI-NOR probe had read an all-zero JEDEC id, so nothing was populated).
  • Software hold via evdev injection into the gpio-keys device: 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.
  • Physical hold on the four-port router about four minutes after boot: red LED went to the fast blink (the developer counted ~13 s), firstboot erased 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 smoke passes on the reset router.
  • Single-LAN-port router on its shipping 1.4.0 image: the kernel's SPI-NOR probe reads an all-zero JEDEC id and /proc/mtd is empty, so disabling qspi loses nothing. In U-Boot, with pad 93 (QSPI_DAT3) set to this dts's value 0xa441 (GPIO, pull-down), gpio input 98 read 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 and bench.sh smoke passed.

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.
@Dominion5254
Dominion5254 marked this pull request as ready for review November 18, 2026 01:59
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two reset-safety issues in projects/start-wrt/backend/ctrl/src/fdl_button.rs.

  1. [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 clears held_since without clearing armed, 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.

  2. [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 retained held_since/armed state 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/startup EVIOCGKEY path 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

@Dominion5254

Copy link
Copy Markdown
Member Author
  • P1 (queued early release wipes): adopted as proposed. Reproduced on the old binary on a K1, using a uinput gpio-keys stand-in and a stopped watcher: a release 4 s into the hold, queued behind another event, wiped on resume. The new binary cancels it and restores the heartbeat. A release queued alone was already read before the deadline check; the window is an event ahead of it, such as the press's own SYN_REPORT.
  • P2 (SYN_DROPPED): adopted as proposed. On the old binary, an overflow that dropped 16 release/press pairs, with the last press 5 s before release, wiped. The new binary exits with "hold history lost", the LED stays on heartbeat, and nothing is wiped.
  • Proposed tests run: 988 + 37 pass, including all 12 fdl_button tests. A full 10 s hold still blinks and wipes on release on the round's binary.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_DROPPED now 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_DROPPED that EVIOCSCLOCKID can queue at startup;
  • the riscv64 input_event layout;
  • whether anything else drives sys-led. Nothing does: 01_leds only configures the WAN netdev LED, and the K1 target has no diag.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 runs firstboot -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-reset entry 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 on CLOCK_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.dts includes the vendor file and declares GPIO 98 as a gpio-keys KEY_RESTART input with a pull-down. GPIO 98 is the pad QSPI_DAT3, which carries the FDL strap. The overlay also disables the qspi controller that owns that pad.
  • k1-sbc.mk now 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.rs adds wipe_overlay_and_reboot for the button path. It writes no activity-log entry, because the wipe deletes /var/lib/startwrt and logging afterwards would recreate it in the reset state. The system.factory-reset RPC behaves as before.
  • Docs: a "Soft Reset (Factory-Reset Button)" section on the Factory Reset page, plus a FAQ mention. A minor-added fragment bumps StartWRT from 1.4.1 to 1.5.0; the latest stable tag is start-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-hotplug with rc.button, needs broadcast_uevent, an OpenWrt generic kernel hack. The overlay supplies none for the K1's 6.18 kernel. The PR uses the mainline gpio-keys driver 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 startup EVIOCGKEY read.
  • Disabling qspi applies 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

  • HOLD is 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 version line, to 1.4.1, and already conflicts with master. Whichever of the two merges second takes 1.5.0 and the matching Cargo.lock line.
  • 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 the master merge, make start-wrt-test passed: 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 and changelog.mjs check-version also passed.
  • Before and after the review changes, the watcher ran on a single-LAN-port router against a uinput device named gpio-keys, with firstboot and reboot stubbed. 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 smoke passed 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-keys driver, 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.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5

@dr-bonez
dr-bonez merged commit bbbfed0 into master Nov 19, 2026
30 of 31 checks passed
@dr-bonez
dr-bonez deleted the wrt/fdl-factory-reset branch November 19, 2026 23:04
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.

3 participants