Compare commits

..
Author SHA1 Message Date
noah 614f452d23 Merge pull request 'qemu: power-signal test waits for the trap install (flare-edge-next)' (#24) from lf-fix-sdk22-next into flare-edge-next
ci / test (push) Successful in 15s
ci / bench (push) Successful in 9s
ci / patches-apply (push) Successful in 22s
ci / qemu-tools (push) Successful in 55s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 33s
ci / badges (push) Skipped
ci / mcdc (push) Successful in 22s
2026-10-17 21:19:47 -06:00
noah 675b55aea0 Merge pull request 'qemu: input consumption wait is a hang backstop (flare-edge#1138)' (#21) from lf-fix-1138-next into flare-edge-next
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / badges (push) Canceled after 0s
2026-10-17 21:19:11 -06:00
BFE EngineeringandClaude Opus 5.5 3b41543fba qemu: power-signal test waits for the trap install (#22)
ci / patches-apply (push) Successful in 18s
ci / qemu-tools (push) Successful in 47s
ci / kernel-build (push) Skipped
ci / test (push) Successful in 10s
ci / mcdc (push) Successful in 12s
ci / prune-artifacts (push) Skipped
ci / quality (push) Successful in 31s
ci / badges (push) Skipped
ci / bench (push) Successful in 5s
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 15s
ci / bench (pull_request) Successful in 6s
ci / patches-apply (pull_request) Successful in 23s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / badges (pull_request) Skipped
ci / qemu-tools (pull_request) Successful in 56s
ci / quality (pull_request) Successful in 33s
init-power-signals-test.sh slept a fixed 0.5 s before sending each signal.
On a loaded runner the shell had not installed its traps yet, so SIGTERM
took its default action and the case failed with nothing written.

Each case now polls /proc/<pid>/status until SigCgt has the signal's bit
(10 s hang backstop, WARDEN_TEST_TRAP_WAIT_S), and fails clearly if the
handler never appears. Regression: a case whose handler install is held
back 1.5 s (fails on the old fixed sleep), plus a check that the wait gives
up on a shell without a handler.

Fixes #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-17 17:51:09 -06:00
BFE EngineeringandClaude Opus 5.5 be753f1453 qemu: input consumption wait is a hang backstop (flare-edge#1138)
ci / test (pull_request) Successful in 10s
ci / mcdc (pull_request) Successful in 15s
ci / bench (pull_request) Successful in 7s
ci / patches-apply (pull_request) Successful in 21s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 32s
ci / badges (pull_request) Skipped
ci / mcdc (push) Successful in 19s
ci / bench (push) Successful in 6s
ci / patches-apply (push) Successful in 16s
ci / kernel-build (push) Skipped
ci / test (push) Successful in 13s
ci / qemu-tools (push) Successful in 49s
ci / prune-artifacts (push) Skipped
ci / badges (push) Skipped
ci / quality (push) Successful in 34s
ci / qemu-tools (pull_request) Successful in 46s
The runner waited 2 s for the guest to count an injected press or
release. On a loaded runner the release that opens the drawer took
longer, so navigation/drawer-drag-release-policy failed both attempts
although the UI handled the swipe. The wait is now a 20 s hang backstop;
a wait over 2 s still passes and puts "slow guest: input consumed after
N s" in the step's detail.

Regression: test_swipe_release_counted_late_on_a_loaded_guest_passes
(release counted 2.5 s after the drag; fails with the 2 s bound), plus
a prompt-release case and a never-counted case bounded by the backstop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-17 14:25:06 -06:00
noah d22c900fb6 Merge pull request 'kernel: build in IPv6 netfilter (flare-edge#533)' (#15) from fix-533-ipv6-netfilter into flare-edge-next
ci / test (push) Successful in 13s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / patches-apply (push) Successful in 15s
ci / quality (push) Successful in 27s
ci / badges (push) Skipped
ci / qemu-tools (push) Successful in 44s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
2026-10-08 07:56:51 -06:00
NoahandClaude Sonnet 5.5 b7125fc4a7 kernel: correct IPv6 netfilter defconfig comment (flare-edge#533)
ci / badges (push) Skipped
ci / mcdc (push) Successful in 13s
ci / test (push) Successful in 15s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 29s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 44s
ci / patches-apply (push) Successful in 16s
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
ci / test (pull_request) Successful in 14s
ci / bench (pull_request) Successful in 6s
ci / mcdc (pull_request) Successful in 12s
ci / patches-apply (pull_request) Successful in 14s
ci / qemu-tools (pull_request) Successful in 43s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
The icmp6 match is part of the ip6_tables core (IP6_NF_IPTABLES), not
xt_tcpudp. Comment only; the symbol set is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
2026-10-07 14:35:09 -06:00
NoahandClaude Sonnet 5.5 35f3ca10eb kernel: build in IPv6 netfilter (flare-edge#533)
The panel kernel had no ip6tables filter table, so the IPv4 default-drop
firewall never applied to IPv6 and dropbear and telnetd were reachable over
::. Enable the ip6tables core (legacy flavour, matching the userland), the
filter table, and IPv6 defrag for conntrack, all built in because the panel
has no /lib/modules:

  CONFIG_NF_DEFRAG_IPV6=y
  CONFIG_IP6_NF_IPTABLES=y
  CONFIG_IP6_NF_IPTABLES_LEGACY=y
  CONFIG_IP6_NF_FILTER=y

No new match symbols: icmp6 lives in xt_tcpudp, and state, limit and
conntrack are family-agnostic and already enabled.

build-kernel.sh now asserts these four are =y in the final .config, because
olddefconfig drops an unmet-dependency line silently and the loss would only
show as an unfiltered IPv6 stack in the field.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
2026-10-07 13:16:08 -06:00
noah 8212bf5feb Merge pull request 'QEMU: allow seeded flow setup' (#14) from qemu-bt-flow-fixture into flare-edge-next
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / test (push) Successful in 12s
ci / qemu-tools (push) Successful in 44s
ci / patches-apply (push) Successful in 14s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 29s
ci / badges (push) Skipped
2026-10-04 21:09:36 -06:00
BFE Engineering 8c4870c6fb Allow seeded QEMU flow setup
ci / mcdc (pull_request) Successful in 12s
ci / bench (pull_request) Successful in 3s
ci / qemu-tools (pull_request) Successful in 42s
ci / patches-apply (pull_request) Successful in 15s
ci / test (push) Successful in 13s
ci / test (pull_request) Successful in 12s
ci / mcdc (push) Successful in 11s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 43s
ci / patches-apply (push) Successful in 18s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 30s
ci / badges (push) Skipped
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 1m39s
ci / badges (pull_request) Skipped
2026-10-04 18:29:49 -06:00
noah 92d601f585 Merge pull request 'qemu: seed installed RS485 profiles through SEED_DIR' (#13) from qemu-seed-profiles into flare-edge-next
ci / test (push) Successful in 18s
ci / mcdc (push) Successful in 19s
ci / bench (push) Successful in 9s
ci / qemu-tools (push) Successful in 55s
ci / patches-apply (push) Successful in 22s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 36s
ci / badges (push) Skipped
2026-10-03 03:05:49 -06:00
NoahandClaude Opus 5.5 65a6800228 qemu: seed installed RS485 profiles through SEED_DIR
ci / patches-apply (push) Successful in 21s
ci / qemu-tools (push) Successful in 49s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 29s
ci / badges (push) Skipped
ci / patches-apply (pull_request) Successful in 19s
ci / qemu-tools (pull_request) Successful in 46s
ci / bench (push) Successful in 6s
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 14s
ci / bench (pull_request) Successful in 6s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 28s
ci / badges (pull_request) Skipped
ci / test (push) Successful in 15s
ci / mcdc (push) Successful in 12s
A flow can now boot the rig with a .w485p profile already installed:
SEED_DIR may hold profiles/rs485/<slug>.w485p (plain files, lower-case
slug names, nothing else under profiles/), copied to
/userdata/warden/profiles/rs485/ where warden-modbus keeps them. Every
other subdirectory, symlink or name still fails closed. Needed for
flare-edge#387 (a flow whose undos stay pending needs the profile
installed at boot; the rig cannot reboot within a flow).

seed-dir.sh scenarios 7 and 8 cover the allowed path and five refused
ones.

Refs blueflare/flare-edge#387.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-10-03 01:16:03 -06:00
noah d01add5646 Merge pull request 'qemu: start warden-modbus before warden-automation' (#12) from qemu-init-modbus-order into flare-edge-next
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 28s
ci / badges (push) Skipped
ci / test (push) Successful in 18s
ci / mcdc (push) Successful in 18s
ci / patches-apply (push) Successful in 17s
ci / bench (push) Successful in 8s
ci / qemu-tools (push) Successful in 46s
2026-10-02 23:05:17 -06:00
NoahandClaude Opus 5.5 a828667b0f qemu: start warden-modbus before warden-automation in the rig init
ci / quality (push) Successful in 40s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 17s
ci / qemu-tools (pull_request) Successful in 47s
ci / test (pull_request) Successful in 19s
ci / bench (pull_request) Successful in 8s
ci / patches-apply (pull_request) Successful in 21s
ci / test (push) Successful in 17s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 39s
ci / badges (pull_request) Skipped
ci / mcdc (push) Successful in 19s
ci / bench (push) Successful in 9s
ci / patches-apply (push) Successful in 22s
ci / qemu-tools (push) Successful in 46s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
flare-edge#348 moves the panel's warden-modbus to S21modbus and
warden-automation to S22automation, right after S20linkmount, so a held
relay closes about 9 s sooner at boot. An automation's device command
goes through warden-modbus (flare-edge#331), so modbus starts first. The
rig's init starts the same daemons in the panel's S-number order and
listed automation before modbus (S93, S94); it now matches the panel.

init-daemon-order-test.sh reads the start loop and pins the order; it
fails on the old list. Wired into CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-10-02 21:25:03 -06:00
noah 45569611da Merge pull request 'relays: refuse a WARDEN_GPIO_ROOT too long for PATH_MAX' (#11) from fix-10-relay-path-bound into flare-edge-next
ci / quality (push) Successful in 29s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 42s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / badges (push) Skipped
ci / test (push) Successful in 13s
ci / mcdc (push) Successful in 10s
ci / patches-apply (push) Successful in 16s
2026-10-02 12:14:29 -06:00
BFE EngineeringandClaude Opus 5.5 b18ed3888b relays: refuse a WARDEN_GPIO_ROOT too long for PATH_MAX
ci / test (push) Successful in 16s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / bench (push) Successful in 11s
ci / patches-apply (push) Successful in 22s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / qemu-tools (pull_request) Successful in 45s
ci / qemu-tools (push) Successful in 49s
ci / test (pull_request) Successful in 17s
ci / mcdc (pull_request) Successful in 19s
ci / bench (pull_request) Successful in 8s
ci / mcdc (push) Successful in 23s
ci / patches-apply (pull_request) Successful in 22s
ci / quality (pull_request) Successful in 34s
ci / badges (pull_request) Skipped
Sysfs paths were built in fixed 80/96-byte stack buffers with unchecked
snprintf, so a root longer than about 70 bytes was truncated and both relays
silently read as unavailable.

Each operation now formats all of its paths up front into PATH_MAX buffers
and checks every snprintf return. A root whose longest path does not fit is
refused with a stderr line and the call reports unavailable, off or no-op;
nothing is ever truncated. The export argument comes from a constant table
instead of runtime formatting.

Regression tests: a 200-byte root through the fake io (full path reaches
the backend), the exact PATH_MAX boundary, one byte over (refused and logged
on available, get and set, io untouched), and a real scratch tree under a
root over 200 bytes. MC/DC stays at 100% (50/50 conditions).

Fixes #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-10-02 11:01:40 -06:00
noah d746ceba6d Merge pull request 'S50usbdevice: an unset USB role is client (flare-edge#278)' (#9) from fix-278-s50-role-default into flare-edge-next
ci / quality (push) Successful in 39s
ci / patches-apply (push) Successful in 26s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / test (push) Successful in 17s
ci / mcdc (push) Successful in 24s
ci / bench (push) Successful in 8s
ci / qemu-tools (push) Successful in 46s
ci / badges (push) Skipped
2026-10-01 16:04:39 -06:00
NoahandClaude Opus 5.5 5f3db8453b S50usbdevice: an unset USB role is client
ci / bench (push) Successful in 6s
ci / mcdc (push) Successful in 12s
ci / patches-apply (push) Successful in 15s
ci / test (pull_request) Successful in 14s
ci / quality (push) Successful in 29s
ci / badges (push) Skipped
ci / test (push) Successful in 13s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / qemu-tools (push) Successful in 42s
ci / patches-apply (pull_request) Successful in 16s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
ci / bench (pull_request) Successful in 4s
ci / mcdc (pull_request) Successful in 14s
ci / qemu-tools (pull_request) Successful in 41s
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-10-01 15:19:12 -06:00
noah 85dc1ee04d Merge pull request 'qemu: a reboot tap may lose the control channel; expect_reboot looks back one step' (#8) from qemu-reboot-tap-race into flare-edge-next
ci / bench (push) Successful in 6s
ci / qemu-tools (push) Successful in 41s
ci / patches-apply (push) Successful in 15s
ci / prune-artifacts (push) Skipped
ci / quality (push) Successful in 26s
ci / test (push) Successful in 13s
ci / mcdc (push) Successful in 9s
ci / kernel-build (push) Skipped
ci / badges (push) Skipped
2026-09-28 21:23:10 -06:00
NoahandClaude Opus 5.5 6576a4a506 qemu: a reboot tap may lose the control channel; expect_reboot looks back one step
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 13s
ci / bench (pull_request) Successful in 6s
ci / qemu-tools (pull_request) Successful in 40s
ci / patches-apply (push) Successful in 15s
ci / qemu-tools (push) Successful in 42s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 15s
ci / test (push) Successful in 12s
ci / quality (pull_request) Successful in 28s
ci / badges (pull_request) Skipped
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 6s
ci / quality (push) Successful in 1m5s
ci / badges (push) Skipped
A tap whose outcome is a reboot races init tearing warden-ui down: the
control channel can close while the tap's press/release counts are still
polled, which made the tap FATAL, and a fast guest can print its restart
line before expect_reboot starts, which expect_reboot then ignored.
flare-edge's Reboot flow passed about half its rig runs (flare-edge#233).

drive() now tells each step the next command and the console size when the
previous step began. A tap followed by expect_reboot that loses the channel
after its press went out is ok; expect_reboot reads the console from the
start of the step before it. Anything earlier still does not count.

Tests: RebootTapRace (3 cases) in test_qmp_drive.py; the old driver fails
the main one. Rig: settings/system-reboot-restarts 4/4 sequential passes,
each through the channel-close path (next: 2/4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 20:30:57 -06:00
noah 9b0659d30c Merge pull request 'Make the patch series reproduce the SDK from a clean vendor checkout' (#7) from sdk4-reproducible into flare-edge-next
ci / quality (push) Successful in 28s
ci / badges (push) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / test (push) Successful in 20s
ci / mcdc (push) Successful in 12s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 40s
ci / patches-apply (push) Successful in 15s
2026-09-28 14:04:32 -06:00
noah 317ae087fd Merge pull request 'qemu: rig init honours reboot, poweroff and halt' (#6) from qemu-init-reboot into flare-edge-next
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / badges (push) Canceled after 0s
2026-09-28 13:07:21 -06:00
NoahandClaude Opus 5.5 07db1b9ec0 qemu: rig init honours reboot, poweroff and halt
ci / test (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / mcdc (push) Successful in 15s
ci / patches-apply (push) Successful in 22s
ci / qemu-tools (push) Successful in 46s
ci / qemu-tools (pull_request) Successful in 42s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 11s
ci / bench (pull_request) Successful in 5s
ci / patches-apply (pull_request) Successful in 16s
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
The stage-2 init is a busybox sh script running as PID 1. Busybox reboot,
poweroff and halt only signal PID 1 (TERM, USR2, USR1), and the kernel
drops a signal PID 1 has no handler for, so a plain reboot did nothing on
the rig while a panel's busybox init honours it. Settings > System >
Reboot hit exactly that (flare-edge#96).

warden_trap_power_signals performs the -f action after a sync, and
warden_idle_forever idles with sleep & wait so the trap runs at once
instead of after an hour-long foreground sleep.

Test: qemu/tests/init-power-signals-test.sh runs the real helpers in sh
with stub commands and sends each signal; it fails without the traps and
with a foreground sleep, and cannot hang on failure.

Fixes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:17:07 -06:00
NoahandClaude Opus 5.5 67da1141a0 build: unpack the pinned Buildroot tree into the vendor SDK
ci / badges (push) Skipped
ci / mcdc (push) Successful in 18s
ci / test (push) Successful in 17s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 41s
ci / patches-apply (push) Successful in 20s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 31s
ci / test (pull_request) Successful in 15s
ci / mcdc (pull_request) Successful in 13s
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 39s
ci / patches-apply (pull_request) Successful in 14s
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (pull_request) Skipped
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
build/unpack-buildroot.sh fetches buildroot-2025.02.8 through
fetch-buildroot-tarball.sh (sha256-pinned) and unpacks it to
sysdrv/source/buildroot/buildroot-2025.02.8, the tree the patched
project/build.sh and sysdrv/Makefile select. It refuses an SDK whose
selectors are not patched, leaves an existing tree alone, and never leaves a
partial tree at the final path. flare-edge's build-firmware.sh calls it right
after applying luckfox-sdk-patches/.

Offline regression tests cover the fresh unpack, the existing-tree no-op and
every refusal path; the qemu-tools job runs and shellchecks them.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:10:53 -06:00
NoahandClaude Opus 5.5 5f36beb44a luckfox-sdk-patches: capture the SDK deltas that lived only in one tree
A clean vendor checkout plus this series could not build WardenOS: the
workstation SDK that CI copies carried tracked changes and two untracked
kernel fragments that no patch recorded (#4).

- board/0009: sysdrv/Makefile selects buildroot-2025.02.8 and relaxes the
  vendor unpack fallback's cp lines.
- board/0010: removes the five 2023-era busybox/hcitool package patches.
- board/0011: flare_minimize strips camera/ISP payload from /oem.
- board/0012: removes the generic S50sshd init script.
- board/0013: e2fsprogs BUILD_CFLAGS for gcc 14 host helpers.
- kernel/configs: flare-wireguard.config and rv1106-usb-host-ethernet.config,
  which the 86Panel board .mk names for the vendor 5.10 kernel.

Every hunk is git diff output against 824b817f8, byte for byte.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:10:53 -06:00
noah eb0691d84f Merge pull request 'Clear the shellcheck findings that would fail qemu-tools' (#3) from sdk-shellcheck into flare-edge-next
ci / kernel-build (push) Skipped
ci / test (push) Successful in 17s
ci / mcdc (push) Successful in 18s
ci / bench (push) Successful in 8s
ci / patches-apply (push) Successful in 16s
ci / prune-artifacts (push) Skipped
ci / qemu-tools (push) Successful in 39s
ci / quality (push) Successful in 26s
ci / badges (push) Skipped
2026-09-28 03:30:57 -06:00
NoahandClaude Opus 5.5 4636f0fe4c ci: keep PATH when the quality job runs npm under sudo
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 39s
ci / quality (pull_request) Successful in 26s
ci / badges (pull_request) Skipped
ci / test (push) Successful in 15s
ci / bench (push) Successful in 9s
ci / kernel-build (push) Skipped
ci / mcdc (push) Successful in 19s
ci / qemu-tools (push) Successful in 38s
ci / patches-apply (push) Successful in 27s
ci / prune-artifacts (push) Skipped
ci / quality (push) Successful in 28s
ci / badges (push) Skipped
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 12s
ci / patches-apply (pull_request) Successful in 16s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
sudo resets PATH to its secure_path, and the Gitea job image keeps node
and npm in the runner tool cache, so 'sudo npm' was not found. Pass the
job's PATH through; GitHub-hosted runners behave the same either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 02:42:47 -06:00
NoahandClaude Opus 5.5 fe29ece741 ci: let the quality job's pip install run on the Gitea runners
ci / test (push) Successful in 12s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / test (pull_request) Successful in 12s
ci / patches-apply (pull_request) Successful in 15s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Failing after 12s
ci / badges (pull_request) Skipped
ci / qemu-tools (push) Successful in 39s
ci / patches-apply (push) Successful in 16s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Failing after 15s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 12s
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 37s
The first CI run on Gitea (1447) failed only in quality: the job image's
Python is PEP 668 externally managed, so 'pip install lizard ruff' is
refused. GitHub's hosted runners set PIP_BREAK_SYSTEM_PACKAGES; set the
same for that step, which runs in a throwaway container on a throwaway
VM.

Refs #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 02:09:30 -06:00
NoahandClaude Opus 5.5 b30621e372 Clear the shellcheck findings that would fail qemu-tools
ci / patches-apply (pull_request) Successful in 20s
ci / qemu-tools (pull_request) Successful in 40s
ci / prune-artifacts (pull_request) Skipped
ci / quality (pull_request) Failing after 13s
ci / badges (pull_request) Skipped
ci / bench (pull_request) Successful in 5s
ci / mcdc (pull_request) Successful in 15s
ci / kernel-build (pull_request) Skipped
ci / test (pull_request) Successful in 11s
CI has not run on this repository since the move to Gitea (Actions was
off), and 13 shellcheck findings accumulated in the files the qemu-tools
job lints, so that job would fail the moment Actions is enabled.

- test-ui-drive-rs485.sh: eight `cond && pass || fail` checks become
  if/then/else, so a pass() that returned non-zero could never also
  record a failure.
- ui-drive.sh and mk-bootimg.sh: four `[ A ] && [ B ] || die` guards get
  explicit braces; the behaviour is unchanged.
- fetch-vendor.sh: the unused fourth read field is `_desc`; it still
  has to be read so the loop's other fields are split correctly.

Every qemu-tools step passes locally, including all four rs485 cases.

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 01:28:24 -06:00
noah 0cf46ba1a4 Merge pull request 'qemu: provision a real U-Boot env and add expect_reboot' (#1) from qemu-env-partition into flare-edge-next
Merge qemu-env-partition: real U-Boot env on the QEMU rig and expect_reboot (flare-edge#62)
2026-09-28 01:26:07 -06:00
NoahandClaude Opus 5.5 5fd6d2da5b qemu: provision a real U-Boot env and add expect_reboot
The rig's env partition was left zeroed, so flared could never clear
bootcount there. It treats that as "intentional reboot bookkeeping not
durable", so every factory reset on the rig wiped the store, was then
refused, and never rebooted (flare-edge#62). mkimage.sh now writes a
valid 32 KiB Rockchip ENVF image (bootcount=0, LE CRC32 over the rest),
the same format flared/src/envf.rs and flare-edge tools/envf.py read;
tools/envf.py parses it with a matching CRC.

An accepted reset then reboots the guest, which ends the VM under
-no-reboot. qmp.py gains expect_reboot TIMEOUT_S for an action whose
correct outcome is a reboot: it passes only when the console shows the
kernel's orderly "reboot: Restarting system" (written after the step
began) and QEMU is gone, and fails on a kernel panic, on an exit without
that line, and on a VM still running at the deadline. The console is
read after the liveness check so the guest's last lines are not missed.
Six drive tests cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 00:32:14 -06:00
NoahandClaude Opus 5.5 ed87da1159 Enable IPv4 policy routing for per-uplink reply routes
flare-edge#181: a wired DHCP uplink with no internet (an unactivated
Starlink Mini on eth0) took the default route from wlan0, and replies
to the office left through it, so the panel went unreachable although
its Wi-Fi never dropped. The fix gives every uplink its own routing
table and a `from <address>` rule, so replies leave by the interface
the request arrived on. That needs IPv4 policy routing, which this
kernel did not have: only IPV6_MULTIPLE_TABLES was set, and every
table silently aliased main (seen on the warehouse panel, 0.9.24-rc).

Adds CONFIG_IP_ADVANCED_ROUTER and CONFIG_IP_MULTIPLE_TABLES. Against
a pristine linux-6.18.46 (sha256 pinned), the expanded .config changes
only in that block: FIB_RULES was already selected by the IPv6 option.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-24 13:30:03 -06:00
NoahandClaude Opus 5.5 44b551f1d1 luckfox-sdk-patches: carry flare-edge's sdk-patches changes since the move
flare-edge main kept editing sdk-patches/ after the move was prepared.
Brings those edits across so the moved tree is byte-identical to
flare-edge main's sdk-patches/ (README aside):

- board 0008-usb-gadget-compose-once: stamp the RNDIS MAC before the
  function is linked, idempotently
- uboot 0003-flare-ab-slots: corrected hunk header
- wifi 0003-aic8800dc-disable-he: new, stops the radio negotiating
  802.11ax

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-24 11:51:22 -06:00
NoahandClaude Opus 5 d266e0774f Add luckfox-sdk-patches: the vendor-SDK delta moved from flare-edge
flare-edge's sdk-patches/ patched the legacy vendor Luckfox SDK (U-Boot
2017.09, optionally the vendor 5.10.160 kernel, the aic8800 wifi driver,
board build glue, and buildroot deltas) directly in that repo, even though
the workspace rule already says kernel/U-Boot/driver work belongs in this
SDK repo. Move the whole tree here as luckfox-sdk-patches/, named to stay
unambiguous next to this repo's own patches/ (the unrelated 6.18.46
forward-port series).

Every patch, config fragment, include and the embedded control DTB is
byte-identical to the flare-edge originals (verified: diff -rq against a
snapshot taken before the move). Only the two README files were rewritten
for the new location, cross-repo pointers, and a license note; also updated
build/vendor.manifest's stale flare-edge cross-reference and this repo's own
top-level README layout table.

Source: flare-edge@86d4633:sdk-patches/ (blueflare/flare-edge, worktree
sdk-patches-in-sdk). flare-edge's own consumers (tools/build-firmware.sh,
verify-sdk-patches.sh, sync-sdk-patches.sh, check-invariants.sh,
auto-version.sh, tests, docs) are updated in a companion commit on the
flare-edge side of this same branch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SMRwnkPp1upR6QFWCZouE7
2026-09-24 11:51:02 -06:00
NoahandClaude Opus 5 8066ef7d79 Stop the OTG state machines running blind in either role
Widens the #160 fix, which was scoped too narrowly to host role, and fixes
flare-edge#168.

Device role was deliberately left alone on the reasoning that the state
machine is only meaningless when the port is a host. That was wrong. On a
board with no extcon phandle the machine has no external role signal in
EITHER direction, and with bvalid pinned high by the VBUS bypass its charger
detection cannot be meaningful at all. In device role its verdict suspends
the phy underneath a bound gadget, so the USB recovery link dies.

Reproduced deterministically on warden-c8a3 with a host attached:

  device role, host attached   ccf=1  phy_sus=0x0    udc=configured  works
  -> host role                 ccf=1  phy_sus=0x0    udc=(none)
  -> back to gadget            ccf=0  phy_sus=0x1d1  udc=configured  SUSPENDED
  -> +15s / +30s               ccf=0  phy_sus=0x1d1  udc=configured  never recovers

and the 2207:0019 device disappears from the host for good.

Nothing notices, because every obvious signal lies: udc state reads
"configured", usb0 carrier reads 1, and DCTL RUN_STOP reads 1, so the gadget
really is asserting its pullup. It asserts into a phy whose analog front end
and 480M clock are off, so the SoC sees SE0 and the host sees no device at
all, not even an enumeration error.

It cannot self-heal either. bvalid is pinned high, so a host attaching later
produces no VBUS edge for the machine to trigger on: it ran once, powered the
phy off, and nothing re-evaluates. That is why a reboot appears to fix it and
why this read as a cable fault for weeks. It is not, and the cables were fine.

Gated on the extcon being self-allocated rather than on the board compatible,
so it describes the actual precondition: no external role signal exists.

Renamed from 29-usb2phy-no-otg-sm-in-host.patch, whose name now misstated the
scope.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-23 10:41:29 -06:00
NoahandClaude Opus 5 f6add60a9c Keep the usb2 phy OTG state machines out of host role
Issue #160: the USB ethernet link on the OTG port stops passing traffic and
the host controller is later declared dead ("xHCI host not responding to stop
endpoint command", "HC died").

Root cause. The phy's OTG state machine and charger detection only make sense
while the port is a peripheral. This board has no ID source, so in host role
their inputs are meaningless: rockchip_usb2phy_otg_sm_work() reaches
OTG_STATE_B_IDLE with vbus asserted, schedules rockchip_chg_detect_work(), and
a DCP verdict calls rockchip_usb2phy_power_off(). That suspends the phy and
drops the 480M clkout the controller's core runs on, while a device is
enumerated and working.

The controller then stops clocking with its register block still readable, so
it reports itself healthy: USBCMD keeps RS set, USBSTS reads 0, PORTSC still
shows CCS and PED. Only MFINDEX gives it away by no longer advancing. Nothing
completes from that point, and the first transmit afterwards times out. The
recovery path cannot help either, because xhci_halt() needs the core clock to
update USBSTS.HCH, so it times out and xhci_reset() returns early without ever
writing USBCMD.HCRST.

dwc3 already calls phy_set_mode() on every role change, but this driver
implemented no .set_mode, so the phy never learned the role. Implement it,
track the role per port, and return early from both work functions in host
role. The check is inside the functions because both have direct callers
besides the scheduled work.

This keeps dr_mode "otg" and runtime role switching. Setting dr_mode to "host"
also avoids the fault, by skipping the same state machine, but compiles out
the gadget needed for flashing, recovery and pairing.

Measured on warden-c8a3, per arm, transmit packets and xhci interrupts
delivered after the stated idle:

  idle 0 s    +9, +10, +9 packets   +170, +176, +188 interrupts
  idle 120 s  +0, +0, +0 packets    +0, +0, +0 interrupts

Also drops 28-dwc3-otg-no-live-reinit.patch. It guarded dwc3_otg_host_init()
against re-entry on a live controller, but that path never executes here:
GSTS reads OTG IP clear and instrumentation logged no entries on either the
hardware irq or the guard site.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-23 00:25:15 -06:00
NoahandClaude Opus 5 4a5481b6a5 Instrument the dwc3 OTG path to test the guard
The guard alone did not fix flare-edge#160: with dr_mode="otg" and the live
re-init skipped, the controller still died 14s after carrier-on under load
(carrier 54.1s, first Tx timeout 63.4s, HC died 68.4s).

That means either the OTG event path is not the trigger, or the harm comes from
somewhere else in it. dr_mode="host" removes far more than this one call: it
also skips dwc3_otgregs_init() and hands port-power control to xHCI instead of
the OTG block.

IRQ 47 is shared between dwc3-otg and xhci-hcd, so /proc/interrupts cannot say
whether OTG events fire at all. CONFIG_DYNAMIC_DEBUG is off, so dev_dbg is
compiled out and invisible.

So this build logs, ratelimited and always compiled:
  - every OTG hardware event with its OEVT value, role and restart flag
  - each time the guard skips a re-init on a live host

Run under load, that answers whether the OTG path is even active during the
failure window, instead of guessing a third patch.

Also worth measuring: load accelerates this dramatically -- 452-587s idle
versus 9-14s under line-rate traffic -- so idle soaks are not comparable to
load tests and earlier comparisons need re-reading with that in mind.

Refs flare-edge#160

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-22 17:34:51 -06:00
NoahandClaude Opus 5 9ff60d60db Do not re-init OTG host registers on a live controller
dwc3_otg_host_init() carries the comment "should be called before Host
controller driver is started". It rewrites OCTL/OCFG, touches GUSB2PHYCFG and
re-asserts port power (OCTL.PrtPwrCtl).

dwc3_otg_irq() sets otg_restart_host ONLY when current_otg_role is already
DWC3_OTG_ROLE_HOST. The threaded handler then calls dwc3_otg_host_init()
unconditionally, so that path always ran against a live, running host -- the
exact condition the comment forbids. Re-asserting port power under a running
xHCI corrupts an in-flight command.

Observed on the RV1106 86-panel as the controller failing to answer a Stop
Endpoint command, after which xhci-hcd declares it dead and tears the bus down.
An r8152 USB NIC stalls a transfer and the controller died 8 times out of 8
between 452s and 587s. Compiling the OTG path out entirely (dr_mode=host)
survived 1810s with zero deaths, which localised it here.

On this board the event is always spurious: the dwc3 node deliberately carries
no extcon, because wiring it pins the role to peripheral on D1-modded panels,
and CONIDSTS reads 0 -- so the role cannot legitimately change while host is
current. Skip the re-init in that case and log it at debug level.

This does not remove the restart capability. dwc3_set_mode() still runs
immediately below, and if the role has genuinely changed dwc3_otg_update()
performs a proper dwc3_host_exit() before re-initialising. The only behaviour
removed is poking a running controller, which was never legitimate.

Refs flare-edge#160

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-22 16:54:54 -06:00
BFE EngineeringandClaude Opus 5 e12bb2c554 Implement RV1106 USB2 PHY signal tuning
Cherry-picked onto the pinned SDK so the ONLY delta versus the pin is this
patch -- the xHCI controller-death investigation needs a controlled build.

The forward-port omitted the vendor driver's rv1106_usb2phy_tuning with the
note "the phy is functional without it". It is functional, but not reliable:
with these registers at reset defaults the HS link is electrically marginal
under sustained traffic, a bulk transfer eventually stalls, and the r8152
Tx-timeout recovery issues an xHCI Stop Endpoint command the controller never
answers. Measured carrier-on to death over four runs: 14s, 519s, 521s, 584s.

Refs flare-edge#160

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MVGTC78dgCGfRANNKjoPea
2026-09-22 12:11:14 -06:00
89 changed files with 9875 additions and 104 deletions
+18 -2
View File
@@ -111,7 +111,8 @@ jobs:
shellcheck -x qemu/*.sh qemu/tests/*.sh build/*.sh \
qemu/rootfs/etc/warden-lib.sh qemu/rootfs/etc/rc \
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh \
tests/unpack-buildroot/*.sh
- name: cache apt archives (python3-pil)
# Same cost class as the busybox binary cached below: a system package
# plus its libjpeg/libpng transitive deps, downloaded fresh on every
@@ -148,6 +149,10 @@ jobs:
# on the debug channel. All offline (a stub qemu-system-arm on
# PATH), so it runs on every push/PR, not only a real boot.
run: bash qemu/tests/run-sh-args-test.sh
- name: rig init honours reboot/poweroff/halt (#5)
run: bash qemu/tests/init-power-signals-test.sh
- name: rig init daemon order matches the panel (flare-edge#348)
run: bash qemu/tests/init-daemon-order-test.sh
- name: mkimage.sh SEED_DIR regression test
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
# otherwise; this builds the same unprivileged mkfs.ext4 image and
@@ -166,6 +171,11 @@ jobs:
# Retry-on-mismatch, cleanup, and the already-verified
# short-circuit, against a fake curl on PATH: no network.
run: bash tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh
- name: unpack-buildroot regression tests
# Fresh unpack, leave-existing-tree-alone, and every refusal path
# (unpatched selectors, bad tarball, half-present tree, failed
# fetch), against a stub fetch script: no network (issue #4).
run: bash tests/unpack-buildroot/run-unpack-buildroot-tests.sh
- name: mk-bootimg boot.img validation regression tests
# Guards issue #22 (a missing/erroring fdtget silently skipping the
# data-position check) plus the FIT metadata and per-image
@@ -340,10 +350,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: install analyzers
# The job image's Python is PEP 668 "externally managed", so a plain
# pip install is refused. GitHub's hosted runners set this same
# variable; here every job runs in a throwaway container on a
# throwaway VM (the GARM runners), so nothing outlives the job.
env:
PIP_BREAK_SYSTEM_PACKAGES: "1"
run: |
sudo apt-get update -qq && sudo apt-get install -y -qq cppcheck shellcheck
pip install --quiet lizard ruff
sudo npm install --silent -g jscpd
sudo env "PATH=$PATH" npm install --silent -g jscpd
curl -fsSL -o /tmp/scc.tar.gz \
https://github.com/boyter/scc/releases/download/v3.6.0/scc_Linux_x86_64.tar.gz
sudo tar -C /usr/local/bin -xzf /tmp/scc.tar.gz scc
+1
View File
@@ -52,6 +52,7 @@ scenario tests (portal, OTA apply, display + touch, watchdog).
| Directory | Contents |
|---|---|
| `patches/` | the RV1106 forward-port onto pristine linux-6.18.46, subsystem-split |
| `luckfox-sdk-patches/` | the delta against the **legacy** vendor Luckfox SDK (U-Boot 2017.09, optionally the vendor 5.10.160 kernel, wifi driver, board build, buildroot) -- moved from `blueflare/flare-edge`'s `sdk-patches/` on 2026-09-15; unrelated to `patches/` above |
| `build/` | hermetic kernel build: pinned fetch -> apply patches -> `zImage` + dtb; `vendor.manifest` pins the third-party trees this platform builds against (LVGL, the vendor RV1106 SDK) to exact commits, and `fetch-vendor.sh` obtains and verifies them |
| `qemu/` | device simulator: QEMU `-M virt` boots the real kernel and real userspace |
| `sim/` | register-level hardware models (Rust): membus, HPMCU, CRU, Modbus, RGA, NPU |
+16
View File
@@ -121,6 +121,22 @@ command -v "${CROSS_COMPILE}gcc" >/dev/null \
|| { echo "cross toolchain ${CROSS_COMPILE}gcc not on PATH (set SDK_TC, or CROSS_COMPILE to one that is)" >&2; exit 1; }
make -C "$SRC" ARCH=arm CROSS_COMPILE="$CROSS_COMPILE" olddefconfig >/dev/null
# Took-effect assertion for the symbols whose silent loss is a security hole,
# not a build failure. olddefconfig drops a defconfig line whose dependencies
# are unmet without a word, and the panel's firewall then quietly stops
# covering IPv6 (flare-edge#533: no ip6tables filter table, so the IPv4
# default-drop never applied to IPv6). Every symbol here must be built in
# (=y): the panel has no /lib/modules.
req_fail=0
for sym in CONFIG_NF_DEFRAG_IPV6 CONFIG_IP6_NF_IPTABLES \
CONFIG_IP6_NF_IPTABLES_LEGACY CONFIG_IP6_NF_FILTER; do
grep -qxF "$sym=y" "$SRC/.config" || {
echo "FATAL: required option $sym is not =y in the final .config (unmet Kconfig dependency?)" >&2
req_fail=1
}
done
[ "$req_fail" = 0 ] || exit 1
# Fragment took-effect assertion: merge_config -m only pastes text, and
# olddefconfig silently resolves any symbol whose dependencies are unmet:
# a fragment option could be dropped without a word. Verify every explicit
+3 -7
View File
@@ -12,13 +12,9 @@
# Same shape as fetch-kernel-tarball.sh, deliberately: a version bump edits this
# file and the pin beside it, nothing else. FAILS CLOSED on a missing pin.
#
# Not wired into build-firmware.sh or CI yet -- tools/build-firmware.sh stages
# sdk-patches/buildroot/ onto whatever buildroot tree the vendor SDK already
# has, it does not yet extract this pinned tarball over it. Exercised today by
# tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh and by
# running the script by hand; wiring it into the real build path is a separate
# change (it has to reconcile the pristine tree with the existing SDK buildroot
# checkout first).
# Called by build/unpack-buildroot.sh, which flare-edge's
# tools/build-firmware.sh runs after applying luckfox-sdk-patches/ (issue #4).
# Tested by tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh.
#
# Usage: fetch-buildroot-tarball.sh <destination-path>
set -euo pipefail
+1 -1
View File
@@ -66,7 +66,7 @@ tree_path() {
}
rc=0
while IFS=$'\t' read -r name url commit desc; do
while IFS=$'\t' read -r name url commit _desc; do
case "$name" in ''|\#*) continue ;; esac
path="$(tree_path "$name")"
+3 -3
View File
@@ -52,8 +52,8 @@ while [ $# -gt 0 ]; do
esac
done
[ -n "$KERNEL" ] && [ -f "$KERNEL" ] || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
[ -n "$DTB" ] && [ -f "$DTB" ] || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
{ [ -n "$KERNEL" ] && [ -f "$KERNEL" ]; } || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
{ [ -n "$DTB" ] && [ -f "$DTB" ]; } || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
[ -n "$OUT" ] || { echo "FATAL: --out is required" >&2; exit 1; }
command -v mkimage >/dev/null || {
echo "FATAL: mkimage not on PATH (Debian/Ubuntu: u-boot-tools)" >&2; exit 1; }
@@ -76,7 +76,7 @@ if [ -z "$RTOOL" ]; then
[ -x "$c" ] && { RTOOL="$c"; break; }
done
fi
[ -n "$RTOOL" ] && [ -x "$RTOOL" ] || {
{ [ -n "$RTOOL" ] && [ -x "$RTOOL" ]; } || {
echo "FATAL: resource_tool not found; pass --resource-tool PATH" >&2; exit 1; }
WORKDIR="$(mktemp -d)"
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# Unpack the pinned Buildroot tree where the vendor SDK builds it.
#
# The vendor SDK ships buildroot-2023.02.6. WardenOS builds against
# buildroot-2025.02.8, which is not in the vendor checkout, so a clean checkout
# plus luckfox-sdk-patches/ had nothing to build (blueflare/bfe-core1106-sdk#4).
# This script closes that gap: it fetches the tarball with
# fetch-buildroot-tarball.sh (sha256-pinned, fails closed) and unpacks it to
# sysdrv/source/buildroot/buildroot-<ver>, the path the patched project/build.sh
# and sysdrv/Makefile select.
#
# Idempotent. An SDK that already has the tree is left alone, so the
# persistent CI SDK and the workstation SDK are untouched. A partial unpack
# never lands at the final path: the tarball is unpacked into a scratch
# directory beside it and moved into place only when complete.
#
# Our own Buildroot delta (defconfigs, package patches, the busybox applet
# patch) is NOT applied here. flare-edge's tools/build-firmware.sh stages it
# after this script runs, the same way it applies the rest of the series.
#
# Usage: unpack-buildroot.sh <vendor-sdk-dir>
#
# The tarball is cached at sysdrv/source/buildroot/buildroot-<ver>.tar.xz
# (inside a directory the vendor .gitignore already ignores); set
# WARDEN_BUILDROOT_TARBALL to use another path.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
FETCH="$HERE/fetch-buildroot-tarball.sh"
SDK="${1:?usage: unpack-buildroot.sh <vendor-sdk-dir>}"
die() { echo "unpack-buildroot: FATAL: $*" >&2; exit 1; }
[ -f "$FETCH" ] || die "missing $FETCH"
BRVER="$(sed -n 's/^BRVER=//p' "$FETCH" | head -1)"
case "$BRVER" in
''|*[!0-9.]*) die "cannot read BRVER from $FETCH" ;;
esac
# The SDK must already select this version. Both selectors come from
# luckfox-sdk-patches/board/ (0006 for project/build.sh, 0009 for
# sysdrv/Makefile); if either still names another tree the series has not
# been applied, and unpacking would only hide that.
BUILD_SH="$SDK/project/build.sh"
MAKEFILE="$SDK/sysdrv/Makefile"
[ -f "$BUILD_SH" ] || die "no vendor SDK at $SDK (missing project/build.sh)"
[ -f "$MAKEFILE" ] || die "no vendor SDK at $SDK (missing sysdrv/Makefile)"
# shellcheck disable=SC2016 # the literal ${SDK_SYSDRV_DIR} text in build.sh
sel_build="$(sed -n 's|^BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/||p' "$BUILD_SH" | head -1)"
sel_make="$(sed -n 's/^BUILDROOT_VER[[:space:]]*?=[[:space:]]*//p' "$MAKEFILE" | head -1)"
[ "$sel_build" = "buildroot-$BRVER" ] ||
die "project/build.sh selects '${sel_build:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
[ "$sel_make" = "buildroot-$BRVER" ] ||
die "sysdrv/Makefile selects '${sel_make:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
PARENT="$SDK/sysdrv/source/buildroot"
TREE="$PARENT/buildroot-$BRVER"
TB="${WARDEN_BUILDROOT_TARBALL:-$PARENT/buildroot-$BRVER.tar.xz}"
if [ -f "$TREE/Makefile" ] && [ -d "$TREE/configs" ] && [ -d "$TREE/package" ]; then
echo "buildroot-$BRVER: tree already present at ${TREE#"$SDK"/}"
exit 0
fi
# Something is at the path but it is not a Buildroot tree. Deleting it here
# could destroy build output in a shared SDK, so say so and stop.
[ ! -e "$TREE" ] || die "$TREE exists but is not a complete Buildroot tree; remove it and rerun"
mkdir -p "$PARENT"
bash "$FETCH" "$TB"
SCRATCH="$(mktemp -d "$PARENT/.unpack-buildroot.XXXXXX")"
[ -d "$SCRATCH" ] || die "mktemp failed under $PARENT"
cleanup() { rm -rf "$SCRATCH"; }
trap cleanup EXIT
echo "== unpacking buildroot-$BRVER into ${TREE#"$SDK"/}"
tar -xJf "$TB" -C "$SCRATCH"
[ -f "$SCRATCH/buildroot-$BRVER/Makefile" ] ||
die "tarball did not contain buildroot-$BRVER/Makefile"
mv "$SCRATCH/buildroot-$BRVER" "$TREE"
echo "buildroot-$BRVER: unpacked"
+5 -3
View File
@@ -17,15 +17,17 @@
# release tarball has no commit to name:
#
# linux-6.18.46 build/fetch-kernel-tarball.sh
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh (unpacked into the
# vendor SDK by build/unpack-buildroot.sh)
#
# The buildroot one matters more than it looks. The firmware builds against
# sysdrv/source/buildroot/buildroot-2025.02.8 inside the vendor SDK, and the
# vendor SDK ships 2023.02.6 -- so that tree is not in the vendor checkout, was
# not in this manifest, and had no recorded origin at all. A clean rebuild
# silently used the vendor's older buildroot and produced a different userspace
# (flare-edge#135). Our delta on top of it is captured in the flare-edge repo at
# sdk-patches/buildroot/.
# (flare-edge#135). Our delta on top of it is captured in this repo at
# luckfox-sdk-patches/buildroot/ (moved 2026-09-15 from the flare-edge repo's
# sdk-patches/buildroot/).
#
# Format: name<TAB>url<TAB>commit<TAB>description
# Blank lines and lines starting with '#' are ignored.
+25
View File
@@ -138,6 +138,8 @@ CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
CONFIG_INET=y
CONFIG_IP_ADVANCED_ROUTER=y
CONFIG_IP_MULTIPLE_TABLES=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
CONFIG_IP_PNP_BOOTP=y
@@ -1370,3 +1372,26 @@ CONFIG_IP_NF_FILTER=y
CONFIG_IP_NF_TARGET_REJECT=y
CONFIG_IP_NF_NAT=y
CONFIG_IP_NF_MANGLE=y
#
# IPv6 netfilter (flare-edge#533). Without it ip6tables has no filter table
# ("Table does not exist"), so the IPv4 default-drop INPUT policy in
# S35iptables never applied to IPv6 and every listener bound to :: (dropbear,
# telnetd, the web UI) was reachable over IPv6. Four symbols, all built in
# because the panel has no /lib/modules:
# IP6_NF_IPTABLES + IP6_NF_IPTABLES_LEGACY the ip6tables core, legacy
# flavour (the userland is legacy)
# IP6_NF_FILTER the filter table; it defaults to
# =m under legacy, so =y is explicit
# NF_DEFRAG_IPV6 IPv6 reassembly for conntrack, so
# the state/conntrack matches work
# (NF_CONNTRACK selects it when
# IPV6 is on; listed so the set is
# visible and guarded)
# No new match symbols: the icmp6 match is part of the ip6_tables core
# (IP6_NF_IPTABLES); tcp/udp matches are in xt_tcpudp, always built with
# XTABLES; state, limit and conntrack are the family-agnostic matches enabled
# above.
CONFIG_NF_DEFRAG_IPV6=y
CONFIG_IP6_NF_IPTABLES=y
CONFIG_IP6_NF_IPTABLES_LEGACY=y
CONFIG_IP6_NF_FILTER=y
+1 -1
View File
@@ -82,7 +82,7 @@ tiered:
behind a small injectable seam, mock its world, build
`-fcondition-coverage`, enforce via the shared `drivers/enforce-mcdc.sh`
(gcc-14 `gcov --conditions`) in the CI `mcdc` job (the proven flare-edge
`tests/uboot-ab` method). **Done:** `relays.c` (40/40 conditions) and
`tests/uboot-ab` method). **Done:** `relays.c` (50/50 conditions) and
`freshness.c` (66/66). **Next in:** the modbus master and the RGA
dispatch, with the ADR-0005 unification (`drivers/README.md`).
- **Tier 2, near-mainline small drivers -> branch coverage + fault
+1 -1
View File
@@ -13,7 +13,7 @@ execute code on private infrastructure (ADR-0007).
| `mcdc` | ubuntu-latest | 100% MC/DC enforced on every `drivers/*/test` (gcc-14 `-fcondition-coverage`). |
| `bench` | ubuntu-latest | Smoke-runs the sim + rs485-bridge micro-benchmarks; emits ns/op trend JSON. |
| `patches-apply` | ubuntu-latest | Fetches pristine linux-6.18.46 (cached, sha256-verified) and applies `patches/*` in order. |
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`, `tests/unpack-buildroot/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, unpack-buildroot, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
| `quality` | ubuntu-latest | Codacy-style grade computed in-pipeline: clippy, cppcheck, shellcheck, ruff, lizard, jscpd, cargo-audit feed `tools/quality/score.py` (SQALE debt ratio + a separate worst-of security axis; SonarQube's published thresholds). Uploads `quality.json`; fails if the security grade is worse than C. |
| `kernel-build` | ubuntu-latest, **dispatch-only** | apt-installs the cross toolchain + qemu, `build/build-kernel.sh` -> `zImage` + `rv1106-warden.dtb`, QEMU `-M virt` boot smoke (fail-closed), artifact upload (best-effort). Trigger: `gh workflow run ci.yml`. |
| `prune-artifacts` | ubuntu-latest, dispatch-only | Deletes `kernel-rv1106` artifacts beyond the newest 3. |
+4 -2
View File
@@ -2,13 +2,15 @@
> **Outcome tested:** A relay is exported transparently and driven without disturbing a held contact.
**Coverage**: relays.c: 40/40 conditions, 100% MC/DC (CI-enforced)
**Coverage**: relays.c: 50/50 conditions, 100% MC/DC (CI-enforced)
```mermaid
flowchart TD
A[warden_relay_set idx,on] --> B{idx < COUNT?}
B -- no --> Z[no-op]
B -- yes --> C{exported?}
B -- yes --> P{all sysfs paths fit PATH_MAX?}
P -- no --> Z3[log to stderr, no-op]
P -- yes --> C{exported?}
C -- no --> D[write export] --> E{exported now?}
E -- no --> Z2[give up]
E -- yes --> F
+1 -1
View File
@@ -12,7 +12,7 @@ Self-contained logic with a clean seam, measured to **100% MC/DC** (gcc-14
| Driver | Seam | MC/DC |
|---|---|---|
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 40/40 conditions, 100% |
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 50/50 conditions, 100% |
| `freshness/` | produce/render callbacks (the "no stale numbers" guard) | 66/66 conditions, 100% |
**Adding a Tier-1 driver:** copy `<name>.{c,h}` here, put the hardware/OS calls behind
+60 -28
View File
@@ -1,5 +1,6 @@
#include "relays.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,6 +9,8 @@
/* GPIO1_A0 and GPIO1_A1; gpiochip1 base is 32. See relays.h. */
static const int s_gpio[WARDEN_RELAY_COUNT] = { 32, 33 };
static const char * const s_name[WARDEN_RELAY_COUNT] = { "Relay 1", "Relay 2" };
/* The same numbers as the strings written to `export`, so no runtime formatting. */
static const char * const s_gpio_str[WARDEN_RELAY_COUNT] = { "32", "33" };
/* ---- default sysfs backend (Tier-2 plumbing; covered by integration tests) ---- */
@@ -64,11 +67,46 @@ const char * warden_relay_name(uint32_t idx)
return idx < WARDEN_RELAY_COUNT ? s_name[idx] : "-";
}
static bool exported(int gpio)
/**
* Every sysfs path one relay operation can touch. Each holds PATH_MAX bytes, so
* any root the kernel would accept fits.
*/
struct relay_paths {
char gpio[PATH_MAX]; /* <root>/gpioN */
char export_[PATH_MAX]; /* <root>/export */
char direction[PATH_MAX]; /* <root>/gpioN/direction */
char value[PATH_MAX]; /* <root>/gpioN/value */
};
/**
* Format the paths for relay @p idx up front. A `$WARDEN_GPIO_ROOT` too long for
* any of them is refused with a log line, never truncated: a cut-short path
* would silently report both relays unavailable, or name a different node.
*/
static bool relay_paths(uint32_t idx, struct relay_paths * rp)
{
char p[80];
snprintf(p, sizeof(p), "%s/gpio%d", gpio_root(), gpio);
return s_io->exists(p);
const char * root = gpio_root();
int gpio = s_gpio[idx];
const int n[] = {
snprintf(rp->gpio, sizeof(rp->gpio), "%s/gpio%d", root, gpio),
snprintf(rp->export_, sizeof(rp->export_), "%s/export", root),
snprintf(rp->direction, sizeof(rp->direction), "%s/gpio%d/direction", root, gpio),
snprintf(rp->value, sizeof(rp->value), "%s/gpio%d/value", root, gpio),
};
for(size_t i = 0; i < sizeof(n) / sizeof(n[0]); i++) {
/* The unsigned cast also maps an encoding error (n < 0) to "does not fit". */
if((unsigned)n[i] >= PATH_MAX) {
fprintf(stderr, "relays: WARDEN_GPIO_ROOT is too long (%zu bytes): sysfs paths "
"under it exceed PATH_MAX (%d), refusing it\n", strlen(root), PATH_MAX);
return false;
}
}
return true;
}
static bool exported(const struct relay_paths * rp)
{
return s_io->exists(rp->gpio);
}
/**
@@ -77,28 +115,21 @@ static bool exported(int gpio)
* relay the first time this page is opened; reading the current level first and
* writing it straight back makes the export transparent.
*/
static bool ensure_ready(int gpio)
static bool ensure_ready(uint32_t idx, const struct relay_paths * rp)
{
if(!exported(gpio)) {
char ex[80], n[16];
snprintf(ex, sizeof(ex), "%s/export", gpio_root());
snprintf(n, sizeof(n), "%d", gpio);
s_io->write(ex, n);
if(!exported(gpio)) return false;
if(!exported(rp)) {
s_io->write(rp->export_, s_gpio_str[idx]);
if(!exported(rp)) return false;
}
char p[96];
snprintf(p, sizeof(p), "%s/gpio%d/direction", gpio_root(), gpio);
char dir[16] = "";
if(!s_io->read_line(p, dir, sizeof(dir))) return false;
if(!s_io->read_line(rp->direction, dir, sizeof(dir))) return false;
if(strncmp(dir, "out", 3) != 0) {
/* Preserve the level across the switch to output. */
char vp[96];
int cur;
snprintf(vp, sizeof(vp), "%s/gpio%d/value", gpio_root(), gpio);
if(!s_io->read_int(vp, &cur)) cur = 0;
s_io->write(p, cur ? "high" : "low");
if(!s_io->read_int(rp->value, &cur)) cur = 0;
s_io->write(rp->direction, cur ? "high" : "low");
}
return true;
}
@@ -106,27 +137,28 @@ static bool ensure_ready(int gpio)
bool warden_relay_available(uint32_t idx)
{
if(idx >= WARDEN_RELAY_COUNT) return false;
return ensure_ready(s_gpio[idx]);
struct relay_paths rp;
if(!relay_paths(idx, &rp)) return false;
return ensure_ready(idx, &rp);
}
bool warden_relay_get(uint32_t idx)
{
if(idx >= WARDEN_RELAY_COUNT) return false;
if(!exported(s_gpio[idx])) return false;
struct relay_paths rp;
if(!relay_paths(idx, &rp)) return false;
if(!exported(&rp)) return false;
char p[96];
int v;
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
if(!s_io->read_int(p, &v)) v = 0;
if(!s_io->read_int(rp.value, &v)) v = 0;
return v != 0;
}
void warden_relay_set(uint32_t idx, bool on)
{
if(idx >= WARDEN_RELAY_COUNT) return;
if(!ensure_ready(s_gpio[idx])) return;
char p[96];
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
s_io->write(p, on ? "1" : "0");
struct relay_paths rp;
if(!relay_paths(idx, &rp)) return;
if(!ensure_ready(idx, &rp)) return;
s_io->write(rp.value, on ? "1" : "0");
}
+4
View File
@@ -16,6 +16,10 @@
* the decision logic runs and is measured to 100% MC/DC on the host, and the
* gpio root is `$WARDEN_GPIO_ROOT`-overridable so the real backend can run
* against a scratch tree in an integration test.
*
* Paths are built in PATH_MAX buffers. A root too long for its longest path
* ("<root>/gpioNN/direction" within PATH_MAX) is refused with a stderr line, and
* every call then reports unavailable / off / no-op; it is never truncated.
*/
#ifndef WARDEN_RELAYS_H
#define WARDEN_RELAYS_H
+126 -5
View File
@@ -9,6 +9,8 @@
#include "../relays.h"
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -30,11 +32,12 @@ static struct {
const char *read_line_val;
bool read_int_ok;
int read_int_val;
char last_write_path[160];
char last_write_path[PATH_MAX];
char last_write_val[32];
int exists_calls;
} fk;
static bool fk_exists(const char *p) { (void)p; return fk.exists_ret; }
static bool fk_exists(const char *p) { (void)p; fk.exists_calls++; return fk.exists_ret; }
static void fk_write(const char *p, const char *v) {
snprintf(fk.last_write_path, sizeof fk.last_write_path, "%s", p);
snprintf(fk.last_write_val, sizeof fk.last_write_val, "%s", v);
@@ -56,6 +59,104 @@ static const struct relay_io FAKE = { fk_exists, fk_write, fk_read_line, fk_read
static void fk_reset(void) { memset(&fk, 0, sizeof fk); }
/* ---- stderr capture: proves a refusal is logged, not silent ---- */
static char g_err[1024];
static int g_saved_stderr = -1;
static char g_err_path[] = "/tmp/warden-relays-stderr-XXXXXX";
static void err_begin(void)
{
int fd = mkstemp(g_err_path);
assert(fd >= 0);
fflush(stderr);
g_saved_stderr = dup(2);
dup2(fd, 2);
close(fd);
}
static void err_end(void)
{
fflush(stderr);
dup2(g_saved_stderr, 2);
close(g_saved_stderr);
FILE *f = fopen(g_err_path, "r");
size_t n = f ? fread(g_err, 1, sizeof g_err - 1, f) : 0;
g_err[n] = '\0';
if(f) fclose(f);
unlink(g_err_path);
memcpy(g_err_path + strlen(g_err_path) - 6, "XXXXXX", 6);
}
/* A root of exactly @p len bytes ("/" then 'a's); it need not exist for fake io. */
static char g_long[PATH_MAX + 64];
static const char *long_root(size_t len)
{
assert(len >= 1 && len < sizeof g_long);
g_long[0] = '/';
memset(g_long + 1, 'a', len - 1);
g_long[len] = '\0';
return g_long;
}
/* Root-length bounds (issue #10). The longest path is "<root>/gpio32/direction",
* so a root of PATH_MAX - 1 - strlen("/gpio32/direction") bytes is the longest
* that fits. One byte more must be refused loudly, never truncated. */
static void long_root_unit_tests(void)
{
const size_t max_root = PATH_MAX - 1 - strlen("/gpio32/direction");
/* Well past the old 80/96-byte buffers but inside PATH_MAX: works, and the
* io sees the full, untruncated path. */
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
setenv("WARDEN_GPIO_ROOT", long_root(200), 1);
warden_relay_set(0, true);
EXPECT(strcmp(fk.last_write_val, "1") == 0);
EXPECT(strlen(fk.last_write_path) == 200 + strlen("/gpio32/value"));
EXPECT(strncmp(fk.last_write_path, g_long, 200) == 0);
EXPECT(strcmp(fk.last_write_path + 200, "/gpio32/value") == 0);
/* Exactly at the bound: still accepted. */
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
setenv("WARDEN_GPIO_ROOT", long_root(max_root), 1);
EXPECT(warden_relay_available(0) == true);
/* One byte over: "<root>/gpio32" still fits, the direction path does not.
* Every entry point refuses, logs, and never touches the io. */
setenv("WARDEN_GPIO_ROOT", long_root(max_root + 1), 1);
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
fk.read_int_ok = true; fk.read_int_val = 1;
err_begin();
EXPECT(warden_relay_available(0) == false);
err_end();
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
EXPECT(fk.exists_calls == 0);
err_begin();
EXPECT(warden_relay_get(0) == false);
err_end();
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
EXPECT(fk.exists_calls == 0);
err_begin();
warden_relay_set(1, true);
err_end();
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
EXPECT(fk.last_write_path[0] == '\0');
EXPECT(fk.exists_calls == 0);
/* A root longer than PATH_MAX itself: refused the same way. */
setenv("WARDEN_GPIO_ROOT", long_root(PATH_MAX + 10), 1);
fk_reset(); fk.exists_ret = true;
err_begin();
EXPECT(warden_relay_available(1) == false);
err_end();
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
EXPECT(fk.exists_calls == 0);
unsetenv("WARDEN_GPIO_ROOT");
}
static void unit_tests(void)
{
warden_relay__set_io(&FAKE);
@@ -142,18 +243,20 @@ static void unit_tests(void)
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
warden_relay_set(0, false);
EXPECT(strcmp(fk.last_write_val, "0") == 0);
long_root_unit_tests();
}
/* ---------------- layer 2: real sysfs backend over a scratch tree ---------------- */
static char g_root[128];
static char g_root[PATH_MAX];
static void wr(const char *rel, const char *content) {
char p[256]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
FILE *f = fopen(p, "w"); if(f) { fputs(content, f); fclose(f); }
}
static void mkgpio(int n) {
char p[256]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
}
static void integration_tests(void)
@@ -207,6 +310,24 @@ static void integration_tests(void)
wr("gpio33/direction", "in\n");
wr("gpio33/value", "1\n");
EXPECT(warden_relay_available(1) == true); /* reads value=1, writes direction "high" */
/* Issue #10: a real scratch tree under a root far longer than the old 80/96-byte
* buffers (the simulator's case). Both relays must be available and switchable. */
for(int i = 0; i < 5; i++) {
size_t l = strlen(g_root);
snprintf(g_root + l, sizeof g_root - l, "/%s", "long-scratch-directory-component-for-issue-10");
EXPECT(mkdir(g_root, 0777) == 0);
}
EXPECT(strlen(g_root) > 200);
setenv("WARDEN_GPIO_ROOT", g_root, 1);
mkgpio(32); mkgpio(33);
wr("gpio32/direction", "out\n"); wr("gpio32/value", "0\n");
wr("gpio33/direction", "out\n"); wr("gpio33/value", "0\n");
EXPECT(warden_relay_available(0) == true);
EXPECT(warden_relay_available(1) == true);
warden_relay_set(1, true);
EXPECT(warden_relay_get(1) == true);
EXPECT(warden_relay_get(0) == false);
}
int main(void)
@@ -1,12 +1,14 @@
* RV1106 USB2 PHY: single OTG port at 0xff3e0000 (ported from the vendor driver;
* fields map 1:1 to 6.18 except utmi_iddig -> utmi_id, and the 5.10-only
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning is
* left off for now (guarded, so NULL is safe): the phy is functional without it.
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning
* was originally left off here; it is now implemented (patches/27-usb-phy-tuning.patch)
* because "functional without it" turned out not to mean reliable -- see #160.
*/
static const struct rockchip_usb2phy_cfg rv1106_phy_cfgs[] = {
{
.reg = 0xff3e0000,
.num_ports = 1,
.phy_tuning = rv1106_usb2phy_tuning,
.clkout_ctl = { 0x0058, 4, 4, 1, 0 },
.port_cfgs = {
[USB2PHY_PORT_OTG] = {
+361
View File
@@ -0,0 +1,361 @@
# luckfox-sdk-patches
The Luckfox SDK (`LuckfoxTECH/luckfox-pico`, pinned in `../build/vendor.manifest`
as `luckfox-pico`) is a ~2 GB vendor checkout and is deliberately **not** in
this repo. Our changes to it were, until now, living only as uncommitted
edits in one person's working copy -- which is how a stale second copy on
another machine came within one command of silently reverting a day of work.
This directory is the tracked form of those changes.
**Moved here 2026-09-15** from `sdk-patches/` in `blueflare/flare-edge`
(source commit `flare-edge@86d4633`), so the SDK repo -- not the firmware
repo that merely consumes it -- is the single canonical home for every
kernel/U-Boot/driver delta. flare-edge's `tools/build-firmware.sh` and
friends now read this directory through the `vendor/warden-sdk` submodule
instead of a same-repo `sdk-patches/`.
**Vendor base: `824b817f8`** of <https://github.com/LuckfoxTECH/luckfox-pico>
(`Pullrequest 260319 (#355)`) -- the same commit `../build/vendor.manifest`
pins. Every patch here is `git diff` against that commit and has been
verified with `git apply --check` against a pristine tree at that revision.
If the vendor base moves, re-verify before trusting them.
**Not `patches/`, and not `sdk/`.** This repo's top-level `patches/` is a
different, unrelated thing: the from-scratch Linux 6.18.46 forward-port
series (see `../patches/README.md`). `luckfox-sdk-patches/` patches the
**legacy** vendor tree instead (U-Boot 2017.09 and, optionally, the vendor
5.10.160 kernel) -- naming it `luckfox-sdk-patches/` keeps the two
unmistakable next to each other. It also isn't named plain `sdk/`, carrying
forward the original naming rule from its flare-edge home: that repo's
`ui-src/pkgconfig-stub/libdrm.pc` resolves `${pcfiledir}/../../sdk`, so a
directory named `sdk/` anywhere it might be checked out alongside would
shadow the real vendor SDK checkout. That specific collision cannot happen
in this repo, but the name stayed to avoid a second rename and to keep the
provenance trail (wiki, commit messages, flare-edge doc citations) legible
across the move. Do not rename it.
## License
Everything here is a `git diff` against Rockchip/Luckfox's GPL-2.0 vendor
U-Boot (2017.09) and Linux (5.10.160) forks, plus a handful of small
standalone files we authored (`uboot/include/flare_touch.h`,
`uboot/include/flare_trace.h`, the bluez5 `wordexp.h` compat shim, the mpv
Bessel-function patch). The diffs are themselves GPL-2.0 derivative work,
consistent with this repo's repo-wide GPL-2.0-only license (`../LICENSE`);
the small standalone files carry no GPL restriction of their own but are
distributed here under the same license for simplicity. Unlike `../patches/`
(the 6.18 port), no per-driver provenance ledger exists for this directory
yet -- everything here predates that convention. If one is wanted, it
belongs beside `../kernel/rv1106-enablement/PROVENANCE.md`.
## Layout
```
luckfox-sdk-patches/uboot/patches/ diffs against sysdrv/source/uboot/u-boot/
luckfox-sdk-patches/uboot/configs/ new config fragments (not patches -- whole new files)
luckfox-sdk-patches/uboot/include/ new source files
luckfox-sdk-patches/kernel/patches/ diffs against sysdrv/source/kernel/
luckfox-sdk-patches/kernel/configs/ new kernel config fragments
luckfox-sdk-patches/wifi/patches/ diffs against sysdrv/drv_ko/wifi/ (out-of-tree modules)
luckfox-sdk-patches/board/patches/ diffs against project/ and sysdrv/ build files (board .mk,
build drivers, Makefiles, init overlays); may delete files
luckfox-sdk-patches/buildroot/ our delta on the Buildroot tree (see "Buildroot" below)
```
Paths inside each patch are relative to the vendor SDK root, so apply with
`-p1` from there:
```sh
cd /path/to/vendor/sdk
for p in /path/to/warden-sdk/luckfox-sdk-patches/uboot/patches/*.patch \
/path/to/warden-sdk/luckfox-sdk-patches/kernel/patches/*.patch \
/path/to/warden-sdk/luckfox-sdk-patches/board/patches/*.patch; do
git apply --check "$p" && git apply "$p"
done
cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/configs/*.config sysdrv/source/uboot/u-boot/configs/
cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/include/*.h sysdrv/source/uboot/u-boot/include/
cp /path/to/warden-sdk/luckfox-sdk-patches/kernel/configs/*.config sysdrv/source/kernel/arch/arm/configs/
```
**You no longer have to run the above by hand.** flare-edge's
`tools/build-firmware.sh` (in the `blueflare/flare-edge` repo, which carries
this SDK as the `vendor/warden-sdk` submodule) applies everything in
`luckfox-sdk-patches/` (patches idempotently, config fragments by copy)
before it builds -- see its `apply_sdk_patches` step. The manual recipe is
kept here as documentation of *what* that step does and for one-off use against
a pristine tree. Idempotency rule the script uses per patch: if
`git apply --reverse --check` succeeds the patch is already in the tree and is
skipped; else if `git apply --check` succeeds it is applied; else it is a hand-
patched SDK carrying an equivalent (or a genuine conflict) and the script warns
and continues rather than aborting the build.
## Buildroot
The vendor checkout ships buildroot-2023.02.6; WardenOS builds against
buildroot-2025.02.8, which is not in the vendor checkout.
`board/patches/0006-buildroot-2025.patch` (project/build.sh) and
`board/patches/0009-sysdrv-buildroot-2025.patch` (sysdrv/Makefile) select it,
and `../build/unpack-buildroot.sh` puts the pristine tree at
`sysdrv/source/buildroot/buildroot-2025.02.8`: it fetches the tarball with
`../build/fetch-buildroot-tarball.sh` (sha256-pinned) and leaves an existing
tree alone. flare-edge's `tools/build-firmware.sh` runs it right after
applying the patches, then stages `buildroot/files/` and applies
`buildroot/patches/` onto the tree (issue #4).
## Completeness check
flare-edge's `tools/verify-sdk-patches.sh` replays this series onto the vendor
base and compares the result with an SDK checkout. It also fails when the SDK
has a tracked change (edit or deletion) that no patch, no fragment and no
entry in flare-edge's `tools/sdk-delta-allowlist.txt` accounts for, and when
the 86Panel board config names a kernel or U-Boot config fragment that
neither the vendor base nor this directory provides. Before that check, five
real deltas lived only in copies of one SDK tree (issue #4).
## What each patch does
### `uboot/patches/0001-display-and-boot-timing.patch`
The U-Boot boot logo never appeared at all before this, and four separate bugs
had to be fixed before it did. Each was measured on hardware, not inferred.
| file | fix |
|---|---|
| `rockchip_display.c` | `malloc` -> `calloc`. `enabled_at_spl` is only ever assigned under `#ifdef CONFIG_SPL_BUILD`, so in U-Boot proper it read uninitialised heap. Garbage read as truthy meant `display_enable()` skipped the connector pre-enable/enable path -- the only path that reaches `backlight_enable()`. |
| `pwm_backlight.c` | `args.args[2] & 1`. The DT has `pwms = <&pwm1 0 100000 50000>`; assigning `50000` to a `bool` polarity field inverted the PWM. Measured `DUTY=0x26e8` (99.6%) with `CTRL=0x13`; after the fix `CTRL=0x0b`. The backlight was running at 0.4%. |
| `clk_rv1106.c` | Two bugs. `rv1106_clk_set_rate()` returned a stale `ret` instead of the computed `rate`, so it always reported 0 Hz. And `DCLK_VOP_DIV_MASK` is 5 bits (max ÷32) while `DIV_ROUND_UP(1188 MHz, 30 MHz) = 40` wrote 39, truncated to 7 -- **the VOP was running at 125 MHz, not 30**. Now clamps to 32, picks the closest parent, and retunes CPLL 1000 -> 960 MHz when neither divides evenly, giving exactly 30.000 MHz. |
| `rockchip_panel.c` | `FLARE_PANEL_SETTLE_MS`: wait after scanout starts before switching the backlight on. See the comment in the file -- it distinguishes two artefacts that look similar and have different causes. |
| `board.c` | Release `RGB_RES` (GPIO0_A1) at the top of `board_init()` instead of `board_late_init()`, and `FLARE_TRACE` instrumentation. `setup_download_mode()` is deliberately kept **first** in `board_late_init()`: moving the logo ahead of it pushed BOOT-key sampling from 1.18 s to ~4-5 s and the key had to be held for eight seconds. |
| `rv1106-u-boot.dtsi` | `u-boot,spl-boot-order = <&emmc>`. It was `<&sdmmc, &spi_nor, &spi_nand, &emmc>` -- the only fitted medium was last. Walking the dead entries cost **267 ms** every boot: ~212 ms failing to identify a non-existent SPI-NAND (`unknown raw ID 0 0 0`) and ~57 ms probing an SD slot this board does not have (`sdmmc` is wired to the AIC8800 WiFi as SDIO). **This file is shared by every rv1106 U-Boot build in the tree**; an SD- or SPI-NAND-booting variant would no longer boot. |
| `console.c` | Timestamp every console line, including from SPL. Needed two fixes: the stock code formats with `%5lu.%06lu`, which `CONFIG_USE_TINY_PRINTF` cannot render (it supports only `%c %s %u %d %x`), and it hooked `puts()`, which SPL never calls -- tiny printf goes character-at-a-time through `putc()`. Costs 324 B of SPL. |
| `rockchip_post_csc.c` | Add `#include <common.h>`. An upstream SDK bug, not a consequence of our config -- the vendor's own `rv1106_defconfig` also lacks `CONFIG_DM_I2C`. |
### `uboot/patches/0002-boot-robustness.patch`
Unattended recovery: `spl-boot-order.c` + `spl.c` register `BOOT_DEVICE_BOOTROM`
as a last-resort SPL load method so a failed U-Boot load drops to MaskRom
instead of hanging, and `bootcount/Kconfig` exposes `BOOTCOUNT_LIMIT` so
repeated boot failures fall through to `altbootcmd`. The defconfig change adds
the bootcount variables to `CONFIG_ENVF_LIST`.
**Provenance note:** this is boot-robustness rather than display work and may
overlap with reliability work done in a parallel session. Review before merging.
### `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch`
Two hunks, both display:
- **`&panel`** -- removes `reset-gpios` and `reset-delay-ms`. GPIO0_A1 is *not*
the panel's reset. Per the 86Panel schematic, net `RGB_RES` ties SoC GPIO0_A1,
the panel RESET pin (FPC 6) and the `NRST` of a WCH **CH32V003** MCU (U6)
together; that MCU's only wired pins are SPI to the same FPC, and its sole job
is to clock the panel's initialisation sequence in. Handing the GPIO to
`panel-simple` therefore made `drm_panel_prepare()` **reboot the panel
initialiser while the VOP was already scanning out** -- which is the faint
coloured vertical banding seen for ~1-3 s on every boot, and why adding a
"reset" never cured it. Luckfox deleted these same two properties in
`e2b0ffa22`. An earlier revision of our tree re-added them, having read that
deletion as an accidental regression. **Confirmed fixed on hardware.**
`backlight` stays, because U-Boot's `rockchip_panel.c` takes its backlight
handle from this node.
- **`&route_rgb`** -- `status = "okay"`. The rest of the RGB pipeline is already
enabled in `rv1106-luckfox-pico-86panel-ipc.dtsi`; `route_rgb` was the only
piece left off, and without it U-Boot's `rockchip_display` finds no route and
skips drawing entirely.
Deliberately **excluded** from this patch, though present in the same file in
the working tree: the `model` rename, and a `dr_mode = "peripheral"` revert that
was a bench workaround to keep the USB network gadget stable for flashing. The
latter is superseded by the live USB role-switching work on `main`.
### `kernel/patches/0005-pstore-ramoops.patch`
Adds a `ramoops@0f000000` node (1 MiB @ 240 MiB) to `reserved-memory` in
`rv1106-luckfox-pico-86panel-ipc.dtsi` so pstore/ramoops has a DRAM region that
survives a reset. Pairs with the `CONFIG_PSTORE*` lines in
`kernel/configs/flare-edge.config`: the kernel console ring + oops/panic survive
into the next boot (`/sys/fs/pstore`), which is the ONLY way to diagnose a
pre-userspace hang (the c8a3 `0x40000` class) with no serial console. Placed
HIGH, above the low kernel-image/DTB/initrd zone, so the carve-out can only
remove kernel RAM -- it cannot recreate the c8a3 under-reservation collision.
Needs a `boot.img` reflash.
### `kernel/patches/0006-reboot-mode-maskrom.patch`
Adds `&reboot_mode { mode-maskrom = <0xEF08A53C>; };` (`BOOT_BROM_DOWNLOAD`) to
the 86Panel ipc.dtsi, so the OS helper `warden-maskrom maskrom`
(`reboot(RESTART2,"maskrom")`) writes that magic to the boot-mode reg
(`0xff020200`) and the next reset enters **true BootROM MaskRom** -- where
`upgrade_tool db`+`wl` / `provision-ab.sh` flash reliably. The stock
`mode-loader`/`-bootloader` only reach U-Boot rockusb "Loader" mode, whose
multi-partition WL is unreliable (writes report 100% but may not persist).
One-shot (PMU-domain reg, cleared by POR). Verified: the DTB compiles and
carries `mode-maskrom=0xEF08A53C`. Needs a `boot.img` reflash -- and the FIRST
deployment still needs one physical-MaskRom flash (chicken-and-egg), after which
remote MaskRom flashing works. Independent hunk (end of ipc.dtsi) -- applies in
any order vs 0005.
### `buildroot/files/package/mpv/0002-change-j1.patch`
Swaps mpv's `j1(x)` (video/out/filter_kernels.c, backing the EWA/jinc
scalers) for a local `BesselJ1()`. Needed because this target's uClibc-ng
does not provide `j1()`/`j0()`/`jn()` -- confirmed absent from
`libuClibc-1.0.31.so` in the arm-rockchip830-linux-uclibcgnueabihf
sysroot, the same kind of gap the bluez5_utils wordexp patch works around
for a different function.
The first version of `BesselJ1()` summed a fixed 11-term power series.
`jinc()` multiplies its argument by M_PI before calling it, and mpv's
`--scale-radius` is user-settable, so any radius reaching roughly x=20
already returns garbage: 11 terms had not converged there, so the value
was 3.1e6 instead of the correct 0.0668, growing to 3.3e42 by x=1000.
The current version sums a term-to-term-ratio series while each new term
is still negligible (stable for the range where that converges) and
falls back to the standard second-order asymptotic expansion for Bessel
functions beyond that, checked against the host's real `j1()` across
x in [0, 5000]: max absolute error 5e-8. `tools/bessel-j1-test.sh` pulls
whatever `BesselJ1()` the patch currently carries out of the diff and
checks it the same way, so a regression back to an unconverged series
is caught there instead of showing up as scaler artifacts on a panel.
### `buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch`
Adds a `wordexp.h` at the BlueZ source root: a minimal wordexp(3)/wordfree(3)
for uClibc-ng, which this toolchain does not provide. `bluetoothctl` and a few
BlueZ tools include `<wordexp.h>` unconditionally and only ever pass
`WRDE_NOCMD` ("no command substitution"), so a whitespace/quote tokenizer is a
semantically complete substitute -- the same kind of gap the mpv `j1()` patch
above works around for a different function.
`WRDE_APPEND` lets a caller accumulate words across more than one call onto
the same `wordexp_t`. An allocation failure partway through such a call used
to free the words the *earlier* call had already produced and leave
`we_wordv` pointing at memory `realloc()` had already relocated or freed --
reachable any time a second `WRDE_APPEND` call runs out of memory, not only
under theoretical low-memory conditions. Fixed by capturing the pre-call word
count and only ever freeing/relocating entries at or past it.
`tools/wordexp-test.sh` extracts `wordexp.h` from this patch's diff into a
scratch dir (nothing else in the tree has a copy -- it is a full new-file
patch, applied only during a firmware build) and runs `tools/wordexp_test.c`
against it: plain and quoted tokenizing, an unterminated quote, growth past
the initial capacity, `WRDE_APPEND` across two calls, and the allocation-
failure case above. Wired into CI's `daemons` job.
### Seatbelt build changes (docs/firmware-update.md section 6.6)
The firmware-update **seatbelt** (auto-revert of a bad remote reflash) needs a
handful of small U-Boot/OS build changes. Design section 6.6 lists six; items **1, 3,
4** are the low-risk, independently-shippable wiring, and they were -- until now -- present only in one person's hand-patched SDK, which is the exact "stale
second copy nearly reverted a day of work" trap that created this directory.
They are tracked here and applied by `tools/build-firmware.sh`, so a clean SDK
checkout plus that script reproduces them with no manual editing.
| section 6.6 | tracked as | what it does |
|---|---|---|
| **item 1** | `board/patches/0001-86panel-seatbelt-wiring.patch` (first hunk) + `uboot/configs/flare-bootcount.config` | Wires the bootcount fragment into the build: appends `flare-bootcount.config` to `RK_UBOOT_DEFCONFIG_FRAGMENT` in the 86Panel board `.mk`. The fragment itself (already tracked, see the Config-fragments table) turns on `CONFIG_BOOTCOUNT{,_LIMIT,_ENV}` and the extended `CONFIG_ENVF_LIST`. Without the wiring the fragment is inert and U-Boot never counts boots -- the seatbelt's U-Boot layer (section 6.1) is silently absent. |
| **item 3** | `board/patches/0001-86panel-seatbelt-wiring.patch` (second hunk) + `board/patches/0002-build-honor-bootargs-extra.patch` | `panic=10` on the kernel cmdline (`sys_bootargs`) so a kernel panic **reboots** after 10 s instead of hanging (section 6.4). The board `.mk` sets `RK_BOOTARGS_EXTRA="panic=10"`; the second patch teaches `project/build.sh`'s `__GET_BOOTARGS_FROM_BOARD_CFG()` to append `RK_BOOTARGS_EXTRA` verbatim to `sys_bootargs` (the same place it already appends `rk_dma_heap_cma=`). That variable flows to `RK_KERNEL_CMDLINE_FRAGMENT` -> `sysdrv/Makefile`'s `KERNEL_CMDLINE_FRAGMENT` -> the actual boot args. The hook is generic and inert: a board that never sets `RK_BOOTARGS_EXTRA` is unaffected. |
| **item 4** | `kernel/patches/0002-watchdog-enable.patch` | Enables the hardware watchdog DT node -- `&wdt { status = "okay"; };` on the 86Panel board dts. `CONFIG_DW_WATCHDOG` is already built, but `rv1106.dtsi` ships `wdt` `disabled`, so `/dev/watchdog` does not exist until this override. Once present, `warden-flared` pets it only while healthy; a post-boot hang then hard-resets and converges to `altbootcmd` -> recovery, the backstop to bootcount (section 6.7). Needs a `boot.img` reflash. |
Items **2** (provision recovery env at flash time), **5** (recovery partition +
image) and **6** (`CONFIG_ENV_OFFSET_REDUND`) are *not* build-time source
changes: item 2 is a provisioning-step env write (see `tools/envf.py` and the
flash scripts), item 5 is a partition-table + recovery-FIT change scheduled with
a hardware-validation pass, and item 6 is a hardening nice-to-have. They are
tracked where they live, not here.
**Apply-order note.** `kernel/patches/0002-watchdog-enable.patch` and the
existing `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch` both edit
the same board dts, but at non-overlapping anchors (0002 inserts after the
`&gmac` block near the top; 0001 appends `&panel`/`&route_rgb` at the tail), so
they apply in either order. Verified with `git apply --check` against the
pristine vendor base and by applying both in sequence.
**Precise apply targets** (relative to the SDK root -- the same `-p1` convention
as every other patch here):
- `board/patches/0001-86panel-seatbelt-wiring.patch` -> `project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk`
- `board/patches/0002-build-honor-bootargs-extra.patch` -> `project/build.sh` (function `__GET_BOOTARGS_FROM_BOARD_CFG`)
- `board/patches/0003-build-fix-rkvar-grep-quote.patch` -> `project/build.sh` (functions `unset_env_config_rk`, `unset_board_config_all`)
- `kernel/patches/0002-watchdog-enable.patch` -> `sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts`
**`board/patches/0003-build-fix-rkvar-grep-quote.patch`** -- required by item 3.
`unset_board_config_all()` reset-sources every `RK_*` var out of the board `.mk`s
with a greedy `grep -oh "^export.*RK_.*="`, whose `.*=` runs to the *last* `=` on
the line. Once item 3 adds `export RK_BOOTARGS_EXTRA="panic=10"`, that grep yields
`export RK_BOOTARGS_EXTRA="panic=` -- an unbalanced quote that makes the sourced
temp file a syntax error and aborts **every** `build.sh` invocation on a clean SDK
(`unexpected EOF while looking for matching '"'`). The fix narrows both greps
(here and `unset_env_config_rk`) to the variable **name** only,
`^export RK_[A-Za-z0-9_]*=`, dropping the value. Without this, a from-scratch
checkout cannot build the 86Panel firmware at all; the runner's hand-patched SDK
had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close).
- `uboot/configs/flare-bootcount.config` is **copied** into
`sysdrv/source/uboot/u-boot/configs/` (it is a whole new file, not a diff);
the board `.mk` patch is what references it by name.
### `board/patches/0009` to `0013` (issue #4)
Deltas that lived only in the workstation SDK until issue #4. Each patch
header explains its change.
| patch | file | what it does |
|---|---|---|
| `0009-sysdrv-buildroot-2025.patch` | `sysdrv/Makefile` | `BUILDROOT_VER` to 2025.02.8 (the tree the `buildroot` target builds); relaxes the vendor unpack fallback's `cp` lines |
| `0010-drop-2023-buildroot-package-patches.patch` | `sysdrv/tools/board/buildroot/{busybox,hcitool}_patch/` | deletes five 2023-era package patches the fallback would copy into Buildroot |
| `0011-oem-flare-minimize.patch` | `project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh` | `flare_minimize`: strips camera/ISP files and modules from /oem |
| `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 |
|---|---|
| `uboot/flare-display.config` | the DRM/panel/PWM symbols the logo path needs |
| `uboot/flare-verbose.config` | `CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y` -- µs timestamps on every line. ~15 chars/line ~ 1.3 ms/line at 115200, so read instrumented timings as an upper bound |
| `uboot/flare-bootcount.config` | boot-failure fallback to `altbootcmd=download` -> MaskRom |
| `uboot/flare-spl-brom.config` | builds `spl_bootrom.o`; does *not* set `SPL_ROCKCHIP_BACK_TO_BROM`, which would flip `SPL_MMC_SUPPORT` off |
| `kernel/flare-backlight.config` | `CONFIG_BACKLIGHT_PWM=y`. As `=m` the backlight class device does not exist until userspace `insmod`s it at ~3.3-3.7 s, which is when the logo is being replaced anyway |
| `kernel/flare-wireguard.config` | `CONFIG_WIREGUARD=y` for the vendor 5.10 kernel, which builds the recovery image. Named by the 86Panel board `.mk`; untracked in the workstation SDK until issue #4 |
| `kernel/rv1106-usb-host-ethernet.config` | USB-Ethernet class drivers (with the `USB_NET_DRIVERS` menu gate) for the vendor 5.10 kernel. Same history as `flare-wireguard.config` |
| `kernel/flare-fbcon.config` | `# CONFIG_LOGO is not set` (the SDK ships the LuckFox fox-head over our logo) plus `FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y` (fbcon seizing the fb destroyed the `drm_logo` image U-Boot handed over) |
## Measured boot timeline
Instrumented boot, t=0 at the BootROM DDR banner:
| milestone | before this work | after |
|---|---|---|
| SPL total (self-reported) | 420.6 ms | 153.6 ms |
| U-Boot logo drawn | 0.866 s | 0.604 s |
| backlight on (logo visible) | 1.157 s | 0.695 s |
| kernel handoff | 1.757 s | 1.292 s |
| userspace colour splash | 4.335 s | 3.87 s |
`tools/boot-trace.py` produces this table from a UART capture. It splits U-Boot
from kernel at the `Starting kernel` line rather than at the kernel banner,
because with `ignore_loglevel` at 115200 the banner is regularly lost to
`** N printk messages dropped **`.
## Still open
- The white logo starts **inverted and fades to correct** in its first instant.
Believed to be the CH32V003's init still completing when the backlight lands,
so we see the tail of the driver IC's internal rail ramp; `FLARE_PANEL_SETTLE_MS`
is currently `250` as a test of that. The cost-free fix, if confirmed, is to
release `RGB_RES` in SPL (~0.03 s) instead of `board_init()` (~0.21 s) and take
the settle back toward zero -- that needs an `idblock` flash.
- No display-driver-IC part number has been identified. The panel is a 4-inch
720x720 RGB666 module, flex marked `BV-FPC39510A-N-V0`. Note the GT911 on this
board is the **touch** controller on `i2c3@0x14` and has nothing to do with the
display path.
@@ -0,0 +1,107 @@
diff --git a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
index c8687187c..01e95378d 100755
--- a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
+++ b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
@@ -13,6 +13,13 @@ export RK_APP_TYPE=RK_WIFI_APP
# Config CMA size in environment
export RK_BOOTARGS_CMA_SIZE="1M"
+# flare-edge (docs/firmware-update.md §6.6 item 3): extra kernel cmdline
+# args, appended verbatim to sys_bootargs by __GET_BOOTARGS_FROM_BOARD_CFG
+# in project/build.sh. panic=10 makes a kernel panic REBOOT after 10 s
+# instead of hanging, so a bad `major` update is counted by U-Boot's
+# bootcount and falls through to altbootcmd -> recovery (§6.4).
+export RK_BOOTARGS_EXTRA="panic=10"
+
# Kernel dts
export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts
@@ -24,7 +31,7 @@ export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts
export RK_BOOT_MEDIUM=emmc
# Uboot defconfig fragment
-export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config"
+export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config flare-spl-brom.config flare-bootcount.config flare-display.config flare-verbose.config flare-ab.config flare-usb-gadget.config flare-touch.config"
# specify post.sh for delete/overlay files
# export RK_PRE_BUILD_OEM_SCRIPT=rv1103-spi_nor-post.sh
@@ -35,7 +42,13 @@ export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.conf
# <partdef> := <size>[@<offset>](part-name)
# Note:
# If the first partition offset is not 0x0, it must be added. Otherwise, it needn't adding.
-export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot),512M(oem),256M(userdata),6G(rootfs)"
+#
+# flare-edge A/B layout (docs/decisions/0003-partition-layout.md in the repo):
+# env/idblock/uboot offsets are fixed (BootROM scans LBA 0x40; SPL reads the
+# FIT at byte 0x88000); uboot grows 256K->512K for headroom; misc carries the
+# A/B slot metadata (byte 2048) and an INERT BCB (16K); boot/oem/rootfs are
+# slotted; recovery holds the never-updated rescue FIT.
+export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),512K(uboot),512K(misc),32M(boot_a),32M(boot_b),128M(oem_a),128M(oem_b),1G(rootfs_a),1G(rootfs_b),32M(recovery),1G(userdata)"
# config partition's filesystem type (squashfs is readonly)
# emmc: squashfs/ext4
@@ -46,7 +59,9 @@ export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot)
# AAAA ----------> partition name
# /BBBB/CCCC ----> partition mount point
# ext4 ----------> partition filesystem type
-export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/oem@ext4
+# The _a names key image GENERATION (the build strips _[ab]); runtime mounting
+# resolves the ACTIVE slot from warden.slot on the cmdline (mount_part patch).
+export RK_PARTITION_FS_TYPE_CFG=rootfs_a@IGNORE@ext4,userdata@/userdata@ext4,oem_a@/oem@ext4
# config filesystem compress (Just for squashfs or ubifs)
# squashfs: lz4/lzo/lzma/xz/gzip, default xz
@@ -62,7 +77,7 @@ export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/
export LF_TARGET_ROOTFS=buildroot
# Buildroot defconfig
-export RK_BUILDROOT_DEFCONFIG=luckfox_pico_w_defconfig
+export RK_BUILDROOT_DEFCONFIG=flare_warden_defconfig
#################################################
# Defconfig
@@ -75,7 +90,19 @@ export RK_ARCH=arm
export RK_TOOLCHAIN_CROSS=arm-rockchip830-linux-uclibcgnueabihf
#misc image
-export RK_MISC=wipe_all-misc.img
+# NEVER the SDK default (recovery-misc.img: BCB says boot-recovery --wipe_all).
+# warden-misc.img is generated by tools/mk-misc.py (flare-edge repo): inert
+# BCB + A/B metadata with both slots successful, A preferred.
+export RK_MISC=warden-misc.img
+
+# Rescue image: a never-updated kernel+initramfs FIT in the recovery
+# partition, booted by U-Boot when both slots are exhausted (or on a BCB
+# 'boot-recovery' command). Same kernel fragments as the main image (keep in
+# sync with RK_KERNEL_DEFCONFIG_FRAGMENT below: referenced literally here
+# because this line exports first): ethernet and WireGuard are built-in, so
+# the rescue can get the device reachable.
+export RK_ENABLE_RECOVERY=y
+export RK_RECOVERY_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config"
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig
@@ -84,7 +111,7 @@ export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig
export RK_KERNEL_DEFCONFIG=luckfox_rv1106_linux_defconfig
# Kernel defconfig fragment
-export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config"
+export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config"
# Config sensor IQ files
# RK_CAMERA_SENSOR_IQFILES format:
@@ -104,7 +131,7 @@ export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config
export RK_BUILD_APP_TO_OEM_PARTITION=y
# enable rockchip test
-export RK_ENABLE_ROCKCHIP_TEST=y
+export RK_ENABLE_ROCKCHIP_TEST=n
# enable rockchip wifi
export RK_ENABLE_WIFI=y
@@ -125,4 +152,4 @@ export RK_PRE_BUILD_OEM_SCRIPT=luckfox-buildroot-oem-pre.sh
export RK_PRE_BUILD_USERDATA_SCRIPT=luckfox-userdata-pre.sh
# declare overlay directory
-export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel"
+export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel overlay-flare-warden-ui"
@@ -0,0 +1,21 @@
diff --git a/project/build.sh b/project/build.sh
index 18552ca28..6fab50104 100755
--- a/project/build.sh
+++ b/project/build.sh
@@ -2161,6 +2161,16 @@ __GET_BOOTARGS_FROM_BOARD_CFG() {
if [ -n "$RK_BOOTARGS_CMA_SIZE" ]; then
SYS_BOOTARGS="$SYS_BOOTARGS rk_dma_heap_cma=$RK_BOOTARGS_CMA_SIZE"
fi
+ # flare-edge (docs/firmware-update.md §6.6 item 3): append any extra
+ # kernel bootargs the board .mk asks for, verbatim, to sys_bootargs.
+ # The 86Panel board sets RK_BOOTARGS_EXTRA="panic=10" so a kernel
+ # panic REBOOTS after 10 s instead of hanging -- which is what turns a
+ # bad `major` update into a bootcount++ that U-Boot can count toward
+ # ${bootlimit} -> ${altbootcmd} -> recovery. Generic + inert: a board
+ # that never sets the var is completely unaffected.
+ if [ -n "$RK_BOOTARGS_EXTRA" ]; then
+ SYS_BOOTARGS="$SYS_BOOTARGS $RK_BOOTARGS_EXTRA"
+ fi
}
__LINK_DEFCONFIG_FROM_BOARD_CFG() {
@@ -0,0 +1,403 @@
Recovery partitions and the recovery ramdisk, in project/.
The BoardConfig hunks that used to head this patch were removed: patch 0001
carries that file's whole delta, and both patches adding RK_BOOTARGS_EXTRA at
the same line meant the two could never apply in sequence. What is left here is
the part 0001 does not cover.
--- a/project/build.sh
+++ b/project/build.sh
@@ -1826,7 +1826,18 @@
root_dev=\$(mountpoint -n /)
root_dev=\${root_dev%% *}
partname=\$1
-part_dev=/dev/block/by-name/\$1
+# flare-edge A/B: a slotted partition name resolves against the slot U-Boot
+# actually booted (warden.slot on the cmdline), so /oem always matches the
+# running kernel's slot. Falls through unchanged on a non-A/B image.
+case "\$partname" in
+ *_a|*_b)
+ wslot=\$(sed -n 's/.*warden\.slot=\(_[ab]\).*/\1/p' /proc/cmdline)
+ if [ -n "\$wslot" ]; then
+ partname="\${partname%_[ab]}\$wslot"
+ fi
+ ;;
+esac
+part_dev=/dev/block/by-name/\$partname
mountpt=\$2
part_fstype=\$3
part_realdev=\$(realpath \$part_dev)
diff --git a/project/scripts/RkLunch-recovery.sh b/project/scripts/RkLunch-recovery.sh
index 92c33ac29..9c5160b5f 100755
--- a/project/scripts/RkLunch-recovery.sh
+++ b/project/scripts/RkLunch-recovery.sh
@@ -1,115 +1,270 @@
#!/bin/sh
+# WardenOS rescue image — runs as the recovery initramfs' RkLunch.sh.
+#
+# The rescue's ONE job (fota spec §8.2): become reachable and let a human
+# recover the device. It is entered when both A/B slots are exhausted, or on
+# a BCB 'boot-recovery' command. It restores nothing on its own initiative —
+# a technician (or the ops team over the network) drives recovery with the
+# helpers this script lays down in /usr/bin. Runbook:
+# flare-edge docs/recovery-runbook.md.
+#
+# Two access paths, both authenticated (getty/telnetd via /bin/login against the
+# pinned root credential), kept up together:
+# 1. PRIMARY: a CDC-ACM serial console over USB (host opens /dev/ttyACM0). No
+# IP — this is the reliable floor that survives the RNDIS usb0 flakiness (#26).
+# 2. SECONDARY (network, for bulk image staging): usb0 RNDIS (172.32.0.93/16),
+# plus eth0 DHCP -> /userdata/warden/rescue-net static -> link-local
+# 169.254.86.86/16, with telnetd on top.
+# The 'boot-recovery' BCB is cleared on entry so a failed rescue reboots to
+# normal instead of looping.
+#
+# Source of truth: flare-edge sdk-patches/board/ — edit there, not in a
+# built image.
-SD_DEVICES="mmcblk1 mmcblk2"
-DEV_NAME=""
-MOUNT_PATH=""
-UPDATE_PACKAGE=""
-UPDATE_OTA_DIR_PATH=""
-delay_time=""
-input_file="$1"
-input_path="$2"
+echo "==== WardenOS rescue image ===="
+cat /proc/cmdline
-sleep 1
-echo "Ready to update."
+# S15linkmount_recovery already ran linkdev + mounted /userdata (if intact).
+mkdir -p /userdata 2>/dev/null
+mountpoint -q /userdata || mount /dev/block/by-name/userdata /userdata 2>/dev/null
-# Use the specified update package in preference.
-if [ -f "$input_file" ]; then
- UPDATE_PACKAGE=$(realpath $input_file)
- UPDATE_OTA_DIR_PATH=$(dirname $UPDATE_PACKAGE)/update
- [ -d "$input_path" ] && UPDATE_OTA_DIR_PATH="$input_path/update"
+# ONE-SHOT recovery: clear the 'boot-recovery' BCB command (misc @16384) right
+# now, so even if this rescue boot goes wrong (unreachable, wedged), a plain
+# power-cycle returns to NORMAL boot instead of looping in recovery. The A/B
+# slot metadata (misc @2048) is left untouched — this touches only the BCB
+# command field. (If recovery was entered via exhausted slots rather than a BCB
+# command there is nothing to clear; harmless.) This is the safety net that
+# turns a failed rescue from a stranding into a reboot.
+_MISC=$(realpath /dev/block/by-name/misc 2>/dev/null)
+[ -n "$_MISC" ] && (
+ # Backgrounded on purpose: a conv=fsync write to a degraded eMMC (a plausible
+ # state on a device that needed recovery) can block in uninterruptible sleep
+ # for the block layer's whole command-timeout/retry chain. Do NOT stall the
+ # access paths below (ACM console / RNDIS / telnet) waiting on it — one-shot
+ # only needs the BCB cleared before the NEXT reboot, and the rescue session
+ # outlives a slow write. Report honestly if the write fails.
+ if dd if=/dev/zero of="$_MISC" bs=1 seek=16384 count=32 \
+ conv=notrunc,fsync 2>/dev/null && sync; then
+ echo "rescue: boot-recovery BCB cleared (recovery is one-shot)"
+ else
+ echo "rescue: WARNING boot-recovery BCB clear FAILED — recovery may re-trigger next boot"
+ fi
+) &
+
+# ---- USB gadget: reachable over the same USB port as the main system, NO
+# Ethernet cable / disassembly. A COMPOSITE gadget exposing TWO functions:
+# - acm.gs0 (CDC-ACM serial): the RELIABLE console. The host just opens
+# /dev/ttyACM0 — no netdev, no IP negotiation, none of the RNDIS
+# usb0-netdev/IP race that left a rescue boot unreachable (#26). getty
+# on /dev/ttyGS0 (below) gives an authenticated login over it.
+# - rndis.gs0 (network at 172.32.0.93/16): the BULK path (staging images
+# for rescue-restore). Best-effort — when it comes up, telnet works too.
+# All built-in (USB_LIBCOMPOSITE / USB_F_ACM / USB_F_RNDIS / USB_CONFIGFS_* /
+# USB_DWC3) on the built-in DWC3 UDC (ffb00000.usb).
+setup_usb_gadget() {
+ CFG=/sys/kernel/config
+ mkdir -p $CFG 2>/dev/null
+ mount -t configfs none $CFG 2>/dev/null
+ G=$CFG/usb_gadget/rescue
+ [ -d "$G" ] && return 0
+ mkdir -p "$G" 2>/dev/null || return 1
+ echo 0x2207 > "$G/idVendor" 2>/dev/null
+ echo 0x0019 > "$G/idProduct" 2>/dev/null
+ mkdir -p "$G/strings/0x409" 2>/dev/null
+ echo "rescue" > "$G/strings/0x409/serialnumber" 2>/dev/null
+ echo "BlueFlare" > "$G/strings/0x409/manufacturer" 2>/dev/null
+ echo "Warden Rescue" > "$G/strings/0x409/product" 2>/dev/null
+ # acm FIRST so the serial console is the primary interface; rndis second.
+ mkdir -p "$G/functions/acm.gs0" 2>/dev/null
+ mkdir -p "$G/functions/rndis.gs0" 2>/dev/null
+ mkdir -p "$G/configs/b.1/strings/0x409" 2>/dev/null
+ echo "rescue-acm+rndis" > "$G/configs/b.1/strings/0x409/configuration" 2>/dev/null
+ ln -s "$G/functions/acm.gs0" "$G/configs/b.1/" 2>/dev/null
+ ln -s "$G/functions/rndis.gs0" "$G/configs/b.1/" 2>/dev/null
+ udc=$(ls /sys/class/udc/ 2>/dev/null | head -1)
+ [ -n "$udc" ] && echo "$udc" > "$G/UDC" 2>/dev/null
+ # ttyGS0 (the ACM console) appears the instant the gadget binds — no netdev,
+ # so no race; the getty respawn below just waits for it. The RNDIS usb0
+ # netdev is created ASYNCHRONOUSLY and is best-effort (its flakiness, #26, is
+ # exactly why the ACM console exists). Poll for it and set the static IP.
+ i=0
+ while [ $i -lt 20 ]; do
+ [ -e /sys/class/net/usb0 ] && break
+ sleep 1; i=$((i + 1))
+ done
+ if [ -e /sys/class/net/usb0 ]; then
+ ip link set usb0 up 2>/dev/null
+ ip addr add 172.32.0.93/16 dev usb0 2>/dev/null
+ echo "rescue: usb0 RNDIS up at 172.32.0.93 (UDC $udc, waited ${i}s)"
+ else
+ echo "rescue: usb0 netdev never appeared (UDC $udc) — use the /dev/ttyACM0 serial console"
+ fi
+}
+setup_usb_gadget &
- echo "Update package: $UPDATE_PACKAGE"
- mkdir -p $UPDATE_OTA_DIR_PATH
- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH
- if [ $? -ne 0 ]; then
- echo "Error: Decompression failed, please check the update package(tar)."
- exit 1
- fi
+# ---- network up ----
+ip link set lo up 2>/dev/null
+if ip link set eth0 up 2>/dev/null; then
+ # DHCP in the background; static/link-local addresses coexist with it.
+ udhcpc -i eth0 -b -t 10 -T 3 2>/dev/null &
- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh
- if [ $? -eq 0 ]; then
- echo "Upgrade successfully."
- rm -rf $UPDATE_OTA_DIR_PATH
- reboot
- return
- else
- echo "Error: Upgrade failed, please check the partition."
- rm -rf $UPDATE_OTA_DIR_PATH
- exit 1
- fi
-else
- echo "Warning: Update package ($1) was not found, checking SD card..."
+ NETCFG=/userdata/warden/rescue-net
+ if [ -r "$NETCFG" ]; then
+ # PARSE strictly as ip=<cidr> / gw=<addr> — do NOT dot-source. `.`ing this
+ # file would EXECUTE it as root: /userdata is writable, so a prior
+ # compromise (or any file-write bug) could plant arbitrary shell that runs
+ # on every rescue entry, before the telnet credential-pin below, defeating
+ # it entirely. Restrict values to IP/CIDR characters.
+ ip=$(sed -n 's/^ip=\([0-9./]\{1,32\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1)
+ gw=$(sed -n 's/^gw=\([0-9.]\{1,15\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1)
+ [ -n "$ip" ] && ip addr add "$ip" dev eth0 2>/dev/null
+ [ -n "$gw" ] && ip route add default via "$gw" 2>/dev/null
+ fi
+
+ # Link-local last resort — a technician with a laptop and a cable can
+ # always reach 169.254.86.86.
+ ip addr add 169.254.86.86/16 dev eth0 2>/dev/null
fi
-# Check SD card when not input update package path.
-for DEV_NAME in $SD_DEVICES
-do
- echo "************** DEV_NAME=$DEV_NAME **************"
- delay_time=1
- mount | grep -i "$DEV_NAME"
- if [ $? -eq 0 ]; then
- MOUNT_PATH=`mount | grep -i "$DEV_NAME" | awk '{printf $3}'`
- echo "SDcard is already mounted in $MOUNT_PATH"
- else
- MOUNT_PATH=/mnt/sdcard
- fi
+# WireGuard phone-home if the identity and a rescue peer config survive on
+# /userdata (WireGuard is built into this kernel; wg tool if present).
+WGCONF=/userdata/warden/rescue-wg.conf
+if [ -r "$WGCONF" ] && command -v wg >/dev/null 2>&1; then
+ ip link add wg0 type wireguard 2>/dev/null &&
+ wg setconf wg0 "$WGCONF" 2>/dev/null &&
+ ip link set wg0 up 2>/dev/null &&
+ echo "rescue: wg0 up from $WGCONF"
+fi
- while [ $delay_time -le 5 ]
- do
- usleep 200000
- dev=$(ls /dev/$DEV_NAME*)
- if [ -n "$dev" ]; then
- echo Find the device: $dev
- break 2
- fi
- echo "Find $DEV_NAME failed $delay_time times"
- delay_time=$(($delay_time+1))
- done
-done
+# ---- remote access ----
+# Authenticated telnet. The recovery ramdisk ships busybox's skeleton
+# /etc/shadow (root == the SDK-wide public default "rockchip"), so pin root to a
+# known device credential and run telnetd THROUGH /bin/login. Do NOT use
+# `telnetd -l /bin/sh`: that execs a root shell on connect with no password
+# prompt (reachable over eth0/link-local/usb0), defeating the credential the
+# runbook documents.
+#
+# Credential source, in order: (1) a per-device override on /userdata
+# (rescue-shadow, a single "root:<hash>:..." line — the same runtime-override
+# pattern as rescue-net/rescue-wg.conf, so production password rotation reaches
+# the rescue), else (2) the compiled-in default password 'root'
+# (openssl passwd -1 -salt wardenrs root; matches the main firmware).
+DEFAULT_ROOT_LINE='root:$1$wardenrs$F.aYwbBz69WjSvwa3RNRF1:19664::::::'
+ROOT_LINE=""
+RESCUE_SHADOW=/userdata/warden/rescue-shadow
+[ -r "$RESCUE_SHADOW" ] && ROOT_LINE=$(grep '^root:' "$RESCUE_SHADOW" 2>/dev/null | head -1)
+[ -n "$ROOT_LINE" ] || ROOT_LINE="$DEFAULT_ROOT_LINE"
+WANT_HASH=$(printf '%s' "$ROOT_LINE" | cut -d: -f2)
-if [ -z "$dev" ]; then
- echo "Error: Not found device, skipping upgrade."
- sh /usr/bin/RK_OTA_erase_misc.sh
- [ $? -eq 0 ] && reboot
- exit 1
+if [ -f /etc/shadow ]; then
+ grep -v '^root:' /etc/shadow > /etc/shadow.new 2>/dev/null
+ { printf '%s\n' "$ROOT_LINE"; cat /etc/shadow.new; } > /etc/shadow
+ rm -f /etc/shadow.new
+ chmod 600 /etc/shadow 2>/dev/null
fi
-mkdir -p $MOUNT_PATH
-UPDATE_OTA_DIR_PATH=$MOUNT_PATH/update
-UPDATE_PACKAGE=$MOUNT_PATH/update_ota.tar
+# Fail CLOSED: expose access only if the intended root hash actually landed.
+# Exposing a shell over the ramdisk's public 'rockchip' default would be worse
+# than no access at all (recover via USB/MaskRom instead). Both the serial
+# console (getty->login) and telnet (telnetd -l /bin/login) authenticate against
+# this same pinned credential.
+GOT_HASH=$(grep '^root:' /etc/shadow 2>/dev/null | head -1 | cut -d: -f2)
+if [ -n "$WANT_HASH" ] && [ "$GOT_HASH" = "$WANT_HASH" ]; then
+ # PRIMARY, always-reachable path: an authenticated login on the CDC-ACM
+ # serial console. The host opens /dev/ttyACM0 (no IP). getty runs /bin/login;
+ # the respawn loop waits for ttyGS0 (created when the acm gadget binds) and
+ # re-runs getty after each logout, so the console is durable.
+ ( while true; do
+ [ -e /dev/ttyGS0 ] && getty -L 115200 ttyGS0 vt100
+ sleep 1
+ done ) &
+ echo "rescue: serial console up on /dev/ttyGS0 (host: /dev/ttyACM0), authenticated"
+ # SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up.
+ telnetd -l /bin/login
+ echo "rescue: telnetd up (authenticated: root / device password)"
+else
+ echo "rescue: root-credential pin FAILED — NO shell exposed; recover via USB/MaskRom"
+fi
-for SD_DEV in $dev
-do
- echo "************** SD_DEV=$SD_DEV **************"
- if mount -t vfat $SD_DEV $MOUNT_PATH ; then
- if [ -f $UPDATE_PACKAGE ]; then
- echo "Update package: $UPDATE_PACKAGE"
- mkdir -p $UPDATE_OTA_DIR_PATH
- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH
- if [ $? -ne 0 ]; then
- echo "Error: Decompression failed, please check the update package(tar)."
- exit 1
- fi
+# ---- recovery helpers ----
+cat >/usr/bin/rescue-status <<'HLP'
+#!/bin/sh
+echo "== slots (misc AB metadata @2048) =="
+MISC=$(realpath /dev/block/by-name/misc)
+dd if=$MISC bs=1 skip=2048 count=32 2>/dev/null | hexdump -C
+echo "== partitions =="
+ls -l /dev/block/by-name/
+echo "== staged images (if any) =="
+ls -l /userdata/warden/rescue/ 2>/dev/null || echo none
+HLP
+chmod +x /usr/bin/rescue-status
- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh
- if [ $? -eq 0 ]; then
- echo "Upgrade successfully."
- rm -rf $UPDATE_OTA_DIR_PATH
- reboot
- return
- else
- echo "Error: Upgrade failed, please check the partition."
- rm -rf $UPDATE_OTA_DIR_PATH
- exit 1
- fi
- else
- echo "Warning: Not found update package: $UPDATE_PACKAGE"
- fi
- umount $MOUNT_PATH
- fi
+cat >/usr/bin/rescue-slot-reset <<'HLP'
+#!/bin/sh
+# Reset A/B metadata to provision defaults (A 15/0/1 preferred, B 14/0/1) —
+# use after restoring slot images. Bytes generated by (and kept in sync
+# with) flare-edge tools/mk-misc.py; CRC32-BE over the first 28 bytes.
+set -e
+MISC=$(realpath /dev/block/by-name/misc)
+printf '\x00\x41\x42\x30\x01\x00\x00\x00\x0f\x00\x01\x00\x0e\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x93\x36\x79' >/tmp/absector
+dd if=/tmp/absector of=$MISC bs=1 seek=2048 conv=notrunc,fsync 2>/dev/null
+sync
+echo "slot metadata reset to provision defaults"
+HLP
+chmod +x /usr/bin/rescue-slot-reset
+
+cat >/usr/bin/rescue-restore <<'HLP'
+#!/bin/sh
+# rescue-restore: write staged images from /userdata/warden/rescue/ onto BOTH
+# slots, reset the A/B metadata to provision defaults, reboot.
+# Stage boot.img / oem.img / rootfs.img there first (over the rescue
+# network), then run this.
+#
+# `rescue-restore wipe-config` ALSO clears the /userdata rescue overrides
+# (rescue-shadow / rescue-net / rescue-wg.conf). A plain restore preserves them
+# (they survive reflash by design), but a planted rescue-shadow backdoor or a
+# rogue rescue-wg peer would then outlive the reflash — so use wipe-config when
+# recovering from a suspected COMPROMISE rather than a plain hardware fault.
+set -e
+if [ "$1" = "wipe-config" ]; then
+ rm -f /userdata/warden/rescue-shadow /userdata/warden/rescue-net \
+ /userdata/warden/rescue-wg.conf
+ echo "rescue: cleared /userdata rescue overrides (compromise recovery)"
+fi
+D=/userdata/warden/rescue
+for img in boot oem rootfs; do
+ [ -r "$D/$img.img" ] || { echo "missing $D/$img.img"; exit 1; }
+done
+for slot in _a _b; do
+ for img in boot oem rootfs; do
+ dev=$(realpath /dev/block/by-name/$img$slot)
+ sz=$(wc -c < "$D/$img.img")
+ echo "writing $img.img -> $dev ($sz bytes)"
+ dd if="$D/$img.img" of="$dev" bs=1M conv=fsync
+ sync
+ # Read-back verify BEFORE the slot-reset below commits both slots as
+ # successful. dd alone reports only its own write, not what landed
+ # (bad USB stick, dropped transfer, eMMC glitch); writing a truncated
+ # image and then stamping the slot "successful" is precisely how a
+ # Level-1-recoverable device becomes a Level-2 (MaskRom-only) brick.
+ # head -c stops the read at the image length, so this is cheap even for
+ # the 1G rootfs (no byte-at-a-time dd).
+ src_sum=$(md5sum "$D/$img.img" | cut -d' ' -f1)
+ dev_sum=$(dd if="$dev" bs=1M 2>/dev/null | head -c "$sz" | md5sum | cut -d' ' -f1)
+ if [ "$src_sum" != "$dev_sum" ]; then
+ echo "VERIFY FAILED for $img$slot ($src_sum != $dev_sum)"
+ echo "ABORTING: slots NOT committed; re-stage a good $img.img and retry."
+ exit 2
+ fi
+ echo " verified $img$slot ($src_sum)"
+ done
done
+rescue-slot-reset
+echo "restore complete; rebooting"
+sync
+devmem 0xff3b0c08 32 0xfdb9 2>/dev/null || true
+reboot -f
+HLP
+chmod +x /usr/bin/rescue-restore
-echo "Recovery upgrade failed, skipping."
-sh /usr/bin/RK_OTA_erase_misc.sh
-[ $? -eq 0 ] && reboot
-exit 1
+echo "==== rescue ready: telnet in; rescue-status / rescue-restore ===="
@@ -0,0 +1,18 @@
diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice
index d29c2334b..b175b77fb 100755
--- a/sysdrv/tools/board/android-tools/S50usbdevice
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
@@ -6,6 +6,13 @@
# 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
+# 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
+
UMS_EN=off
ADB_EN=on
MTP_EN=off
@@ -0,0 +1,22 @@
diff --git a/project/build.sh b/project/build.sh
index 6fab501..6adbe35 100755
--- a/project/build.sh
+++ b/project/build.sh
@@ -7,7 +7,7 @@ RECORD_IFS="$IFS"
function unset_env_config_rk() {
local tmp_file=$(mktemp)
- env | grep -oh "^RK_.*=" >$tmp_file || true
+ env | grep -oh "^RK_[A-Za-z0-9_]*=" >$tmp_file || true
source $tmp_file
rm -f $tmp_file
}
@@ -383,7 +383,7 @@ function save_board_config() {
function unset_board_config_all() {
local tmp_file=$(mktemp)
- grep -oh "^export.*RK_.*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file
+ grep -oh "^export RK_[A-Za-z0-9_]*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file
source $tmp_file
rm -f $tmp_file
}
@@ -0,0 +1,22 @@
Point the build at buildroot-2025.02.8.
The vendor SDK ships buildroot-2023.02.6 and build.sh pointed at it. The tree we
actually build against is 2025.02.8, and nothing recorded the switch: a rebuild
from a pristine vendor checkout plus this patch series silently produced a
different userspace.
The 2.6 GB tree itself cannot live in this repo and is NOT in the vendor
checkout either; obtaining it is covered by the SDK's build/vendor.manifest.
This patch records only the one line that selects it.
--- a/project/build.sh
+++ b/project/build.sh
@@ -34,7 +34,7 @@
GLOBAL_SDK_VERSION=""
WIFI_NEW_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant_new.conf
WIFI_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant.conf
-BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6
+BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2025.02.8
BUILDROOT_CONFIG_FILE=${BUILDROOT_PATH}/.config
SDK_CONFIG_DIR=${SDK_ROOT_DIR}/config
DTS_CONFIG=${SDK_CONFIG_DIR}/dts_config
@@ -0,0 +1,60 @@
Authenticate the recovery console (#27).
The busybox tiny_rootfs skeleton runs `::respawn:-/bin/sh` on /dev/console,
which on this board is ttyFIQ0, the debug UART. That is a root prompt with no
login for anyone who opens the case, and it bypasses the fail-closed credential
pin RkLunch-recovery.sh enforces for every other rescue path. The skeleton's own
ttyFIQ0 getty line is commented out directly below it, so the bare shell was the
only console and the unauthenticated one.
build.sh now deletes that line when it stages the ramdisk, and the recovery
script spawns an authenticated getty on the console inside its gated block, so
a failed pin exposes nothing on the UART either.
--- a/project/build.sh
+++ b/project/build.sh
@@ -956,6 +956,24 @@
cp -fa $PROJECT_TOP_DIR/scripts/RkLunch-recovery.sh $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/usr/bin/RkLunch.sh
cp -fa $PROJECT_TOP_DIR/scripts/boot4recovery.its $RK_PROJECT_PATH_RAMDISK
+ # flare-edge (#27): the busybox tiny_rootfs skeleton runs an
+ # UNAUTHENTICATED root shell on /dev/console -- which on this board is
+ # ttyFIQ0, the debug UART:
+ #
+ # ::respawn:-/bin/sh
+ #
+ # That hands a root prompt with no login to anyone who opens the case,
+ # bypassing the fail-closed credential pin RkLunch-recovery.sh enforces for
+ # every other rescue path (ttyGS0 getty, telnetd -l /bin/login). Note the
+ # skeleton's own ttyFIQ0 getty line is commented out right below it, so the
+ # bare shell was the only console -- and the unauthenticated one.
+ #
+ # Removed here; RkLunch-recovery.sh spawns an authenticated getty on the
+ # console INSIDE its gated block instead, so the debug UART now answers to
+ # the same pinned credential as everything else.
+ sed -i '/^::respawn:-\/bin\/sh$/d' \
+ $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/etc/inittab
+
mkdir -p $(dirname $RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT)
cat >$RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT <<EOF
#!/bin/sh
--- a/project/scripts/RkLunch-recovery.sh
+++ b/project/scripts/RkLunch-recovery.sh
@@ -179,6 +179,17 @@
sleep 1
done ) &
echo "rescue: serial console up on /dev/ttyGS0 (host: /dev/ttyACM0), authenticated"
+ # The DEBUG UART (/dev/console -> ttyFIQ0). The ramdisk skeleton used to run
+ # `::respawn:-/bin/sh` from its inittab here: a root shell with no login,
+ # reachable by anyone who opened the case, bypassing this entire gate (#27).
+ # project/build.sh now deletes that line, so the console is owned HERE and
+ # authenticates against the same pinned credential as every other path.
+ # Inside the gate, so a failed pin exposes nothing on the UART either.
+ ( while true; do
+ getty -L console 0 vt100
+ sleep 1
+ done ) &
+ echo "rescue: debug-UART console up on /dev/console, authenticated"
# SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up.
telnetd -l /bin/login
echo "rescue: telnetd up (authenticated: root / device password)"
@@ -0,0 +1,77 @@
flare-edge: compose the USB gadget once, instead of rebinding twice.
Every unbind/rebind of a live gadget is a full controller teardown; the
host loses usb0 and ttyACM0 and the halt times out (issue #145).
--- a/sysdrv/tools/board/android-tools/S50usbdevice
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
@@ -17,7 +17,13 @@
ADB_EN=on
MTP_EN=off
NTB_EN=off
-ACM_EN=off
+# flare-edge: composed here rather than linked afterwards by S52usbacm. Every
+# unbind/rebind of a live gadget is a full teardown -- the host loses usb0 and
+# ttyACM0, and the controller logs "Host halt failed, -110" on the way down --
+# so the panel's console function is built into the gadget before it is ever
+# bound (issue #145). S52usbacm still runs; it now finds acm already linked,
+# skips its rebind, and only starts the ttyGS0 getty.
+ACM_EN=on
UAC1_EN=off
UAC2_EN=off
UVC_EN=off
@@ -73,6 +79,46 @@
mkdir ${USB_FUNCTIONS_DIR}/hid.usb0
}
+# flare-edge: the stable, serial-derived RNDIS MAC. MUST be applied before
+# bind_functions links rndis.gs0 into the config, NOT merely before the UDC
+# bind: rndis_alloc() runs at link time, takes opts->refcnt and immediately
+# captures the MAC via gether_get_host_addr_u8(). After that the configfs
+# store returns -EBUSY (u_ether_configfs.h guards on opts->refcnt), so a write
+# here is silently discarded and the gadget enumerates with the kernel's
+# random MAC (issue #157).
+#
+# S51usbmac used to repair that afterwards by tearing down a live gadget purely
+# to change two strings (issue #145), which is the second enumeration a host
+# sees on every boot. It still runs and is now a no-op that confirms the result.
+#
+# The writes are checked. Losing the stable MAC is not fatal, so this does not
+# abort the boot, but it must never fail silently again: silence is exactly how
+# #157 survived.
+flare_stamp_rndis_mac()
+{
+ RN=${USB_FUNCTIONS_DIR}/rndis.gs0
+ [ -d "$RN" ] || return 0
+ SER=$(tr -d '\000' < /proc/device-tree/serial-number 2>/dev/null)
+ [ -n "$SER" ] || return 0
+ H=$(printf '%s' "$SER" | md5sum | cut -c1-10)
+ A=$(echo "$H" | cut -c1-2); B=$(echo "$H" | cut -c3-4)
+ C=$(echo "$H" | cut -c5-6); D=$(echo "$H" | cut -c7-8)
+ E=$(echo "$H" | cut -c9-10)
+ WANT="02:$A:$B:$C:$D:$E"
+ # Already ours: S26usbhost re-runs this script on a role switch, and the
+ # second run finds configfs present, so configfs_init is skipped and the
+ # function is still linked from the first run. The MAC was set correctly
+ # then, so writing it again would be refused with -EBUSY and warn about a
+ # random MAC that is not in use. Nothing to do, and nothing to report.
+ [ "$(cat "$RN/host_addr" 2>/dev/null)" = "$WANT" ] && return 0
+ if ! echo "$WANT" > "$RN/host_addr" 2>/dev/null; then
+ echo "S50usbdevice: rndis host_addr write refused and the MAC is NOT already correct; the function is linked, so the gadget will use a random MAC (#157)" > /dev/kmsg 2>/dev/null
+ return 1
+ fi
+ echo "06:$A:$B:$C:$D:$E" > "$RN/dev_addr" 2>/dev/null ||
+ echo "S50usbdevice: rndis dev_addr write refused (#157)" > /dev/kmsg 2>/dev/null
+}
+
configfs_init()
{
echo "Debug: configfs_init"
@@ -426,6 +450,7 @@
use_os_desc
echo $PID > ${USB_CONFIGFS_DIR}/idProduct
+ flare_stamp_rndis_mac
bind_functions
pre_run_binary
sleep 1
UDC=`ls /sys/class/udc/| awk '{print $1}'`
@@ -0,0 +1,65 @@
Build buildroot-2025.02.8 from sysdrv/Makefile too.
0006-buildroot-2025.patch points project/build.sh at buildroot-2025.02.8, but
sysdrv/Makefile has its own default, BUILDROOT_VER, and that is the one the
`buildroot` target actually builds. Left at the vendor's 2023.02.6, a clean
checkout configures and builds the old tree.
The same Makefile carries the vendor's fallback that unpacks
tools/board/buildroot/$(BUILDROOT_VER).tar.gz when the tree is missing and
copies the vendor defconfigs and package patches into it. Two relaxations
keep that fallback usable with 2025.02.8:
- `*_defconfig` instead of only luckfox_pico_w_defconfig, so any defconfig
staged beside the vendor ones is copied too.
- `|| true` on the busybox and hcitool patch copies, because
0010-drop-2023-buildroot-package-patches.patch empties those directories.
The WardenOS build does not use the fallback: flare-edge's
tools/build-firmware.sh unpacks the pinned, sha256-verified tarball with
build/unpack-buildroot.sh before the SDK build runs, so the Makefile's
`test -d` finds the tree and skips its own unpack and copies.
diff --git a/sysdrv/Makefile b/sysdrv/Makefile
index 5edb8f875..c173c219e 100644
--- a/sysdrv/Makefile
+++ b/sysdrv/Makefile
@@ -281,7 +281,7 @@ BUSYBOX_DIR := $(SYSDRV_DIR)/source/busybox
SYSDRV_BUSYBOX_OBJS_OUTPUT_DIR ?= $(BUSYBOX_DIR)/objs_$(BUSYBOX_CFG)
BUILDROOT_CFG ?= config_normal
-BUILDROOT_VER ?= buildroot-2023.02.6
+BUILDROOT_VER ?= buildroot-2025.02.8
BUILDROOT_DIR := $(SYSDRV_DIR)/source/buildroot
CUSTOM_VER ?= custom
@@ -599,11 +599,11 @@ buildroot_create:
mkdir -p $(BUILDROOT_DIR)
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR)
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true
buildroot: prepare
@echo -e "$(C_GREEN) ==sysdrv== build buildroot $(C_NORMAL)"
@@ -611,11 +611,11 @@ buildroot: prepare
mkdir -p $(BUILDROOT_DIR) ;\
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR) ;\
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ ;\
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true ;\
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/ ;\
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true ;\
);
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) $(BUILDROOT_DEFCONFIG) -C $(BUILDROOT_DIR)/$(BUILDROOT_VER)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,55 @@
Strip camera and ISP payload from /oem.
luckfox-buildroot-oem-pre.sh runs over the OEM staging tree before it is
packed. flare_minimize() removes what WardenOS never uses because no image
sensor is fitted: the ISP tuning files (about 32 MB), the rkaiq 3A library
and servers, the camera capture kernel modules, and the camera and MPI
sample binaries.
NPU, video codec, RGA and rockit are kept on purpose. WiFi/BT, touch and the
insmod scripts are not touched.
diff --git a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
index 4187457d4..de2bf74e6 100755
--- a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
+++ b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
@@ -46,4 +46,37 @@ function remove_data()
#=========================
# run
#=========================
-remove_data
\ No newline at end of file
+remove_data
+#=========================
+# flare-edge: drop camera / ISP from /oem
+#
+# Camera is out of scope for the Warden gateway role (no sensor attached).
+# NPU, video codec, RGA and rockit are KEPT deliberately - they are onboard
+# hardware we chose to retain. WiFi/BT (aic8800*), touch (goodix) and the
+# insmod scripts are never touched here.
+#=========================
+function flare_minimize()
+{
+ KO=$RK_PROJECT_PACKAGE_OEM_DIR/usr/ko
+
+ # ISP tuning data - by far the biggest item in /oem (~32MB)
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/share/iqfiles
+
+ # ISP 3A library and its servers
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/lib/librkaiq*
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_3A_server
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_tool_server
+
+ # camera capture path: ISP, CIF, MIPI CSI-2 D-PHY, and the sensor drivers
+ lf_rm $KO/video_rkisp.ko $KO/video_rkcif.ko
+ lf_rm $KO/phy-rockchip-csi2-dphy.ko $KO/phy-rockchip-csi2-dphy-hw.ko
+ lf_rm $KO/sc3336.ko $KO/mis5001.ko $KO/gspca_main.ko
+
+ # camera/ISP demo + sample binaries (keep luckfox_*_test and modetest:
+ # those are the GPIO/UART/I2C/SPI/PWM/display bring-up tools we want)
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/sample_*
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rk_mpi_*
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/simple_*
+}
+
+flare_minimize
@@ -0,0 +1,65 @@
Remove the generic S50sshd init script.
overlay-luckfox-buildroot-init is in the 86Panel board's RK_POST_OVERLAY.
Its S50sshd runs `ssh-keygen -A` inline. With no hardware RNG and no saved
seed on a freshly written rootfs, getrandom() blocks, and rcS is sequential,
so every init script sorting after it (S50usbdevice among them) never ran
and the board came up with no reachable interface.
WardenOS gets its SSH server from Buildroot's dropbear package, selected by
flare_warden_defconfig, which installs its own init script.
diff --git a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd b/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
deleted file mode 100755
index e5b9c4451..000000000
--- a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-#
-# sshd Starts sshd.
-#
-
-# Make sure the ssh-keygen progam exists
-[ -f /usr/bin/ssh-keygen ] || exit 0
-
-umask 077
-
-start() {
- chown root:root /var/empty/
- # Create any missing keys
- /usr/bin/ssh-keygen -A
-
- printf "Starting sshd: "
- /usr/sbin/sshd
- touch /var/lock/sshd
- echo "OK"
-}
-stop() {
- printf "Stopping sshd: "
- killall sshd
- rm -f /var/lock/sshd
- echo "OK"
-}
-restart() {
- stop
- start
-}
-
-case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart|reload)
- restart
- ;;
- *)
- echo "Usage: $0 {start|stop|restart}"
- exit 1
-esac
-
-exit $?
-
@@ -0,0 +1,21 @@
Build e2fsprogs host helpers with gcc 14.
The vendor's e2fsprogs 1.43.9 compiles a few helper programs for the build
host (BUILD_CC) while cross-building the target tools. That source relies on
implicit function declarations and implicit int, which gcc 14 turns into
errors, so the host helper build fails. BUILD_CFLAGS demotes those two back
to warnings for the host helpers only; the target CFLAGS are unchanged.
diff --git a/sysdrv/tools/board/e2fsprogs/Makefile b/sysdrv/tools/board/e2fsprogs/Makefile
index 14ab9e503..baa541093 100644
--- a/sysdrv/tools/board/e2fsprogs/Makefile
+++ b/sysdrv/tools/board/e2fsprogs/Makefile
@@ -20,7 +20,7 @@ all:
mkdir -p $(CURRENT_DIR)/$(PKG_BIN)/usr/; \
pushd $(CURRENT_DIR)/$(PKG_NAME)/; \
./configure --host=$(SYSDRV_CROSS) --target=$(SYSDRV_CROSS) CFLAGS="$(SYSDRV_CROSS_CFLAGS)" \
- LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
+ LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" BUILD_CFLAGS="-Wno-implicit-function-declaration -Wno-implicit-int" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
--disable-nls \
--disable-debugfs --disable-imager --disable-defrag --enable-fsck --enable-resizer \
--disable-testio-debug --disable-rpath --enable-symlink-install --disable-fuse2fs; \
@@ -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
@@ -0,0 +1,76 @@
BR2_arm=y
BR2_cortex_a7=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
BR2_TOOLCHAIN_EXTERNAL_WCHAR=y
BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_PRIMARY_SITE="http://sources.buildroot.net"
BR2_OPTIMIZE_3=y
BR2_TARGET_GENERIC_HOSTNAME="luckfox pico"
BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico"
BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox"
BR2_SYSTEM_ENABLE_NLS=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_GZIP=y
BR2_PACKAGE_P7ZIP=y
BR2_PACKAGE_UNZIP=y
BR2_PACKAGE_XZ=y
BR2_PACKAGE_ZIP=y
BR2_PACKAGE_E2FSPROGS=y
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
BR2_PACKAGE_EVTEST=y
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_PYTHON3_SSL=y
BR2_PACKAGE_PYTHON_AIOHTTP=y
BR2_PACKAGE_PYTHON_CLICK=y
BR2_PACKAGE_PYTHON_ITSDANGEROUS=y
BR2_PACKAGE_PYTHON_JINJA2=y
BR2_PACKAGE_PYTHON_PERIPHERY=y
BR2_PACKAGE_PYTHON_PILLOW=y
BR2_PACKAGE_PYTHON_SERIAL=y
BR2_PACKAGE_PYTHON_SETUPTOOLS=y
BR2_PACKAGE_PYTHON_SMBUS_CFFI=y
BR2_PACKAGE_PYTHON_SPIDEV=y
BR2_PACKAGE_PYTHON_WERKZEUG=y
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_GNUTLS=y
BR2_PACKAGE_LIBMD=y
BR2_PACKAGE_FREETYPE=y
BR2_PACKAGE_LIBDRM=y
BR2_PACKAGE_DTC=y
BR2_PACKAGE_DTC_PROGRAMS=y
BR2_PACKAGE_LIBV4L=y
BR2_PACKAGE_LIBV4L_UTILS=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_LIBCURL_CURL=y
BR2_PACKAGE_LIBCURL_VERBOSE=y
BR2_PACKAGE_LIBRSYNC=y
BR2_PACKAGE_PCRE2=y
BR2_PACKAGE_PCRE2_16=y
BR2_PACKAGE_PCRE2_32=y
BR2_PACKAGE_BMON=y
BR2_PACKAGE_DHCPCD=y
BR2_PACKAGE_IPERF=y
BR2_PACKAGE_IPERF3=y
BR2_PACKAGE_IPTABLES=y
BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
BR2_PACKAGE_IPTABLES_NFTABLES=y
BR2_PACKAGE_LRZSZ=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_RSYNC=y
BR2_PACKAGE_SOCAT=y
BR2_PACKAGE_WGET=y
BR2_PACKAGE_BASH=y
BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y
BR2_PACKAGE_DIALOG=y
BR2_PACKAGE_TIME=y
BR2_PACKAGE_HTOP=y
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
BR2_PACKAGE_NANO=y
BR2_PACKAGE_HOST_DTC=y
@@ -0,0 +1,113 @@
BR2_arm=y
BR2_cortex_a7=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
BR2_TOOLCHAIN_EXTERNAL_WCHAR=y
BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_PRIMARY_SITE="http://sources.buildroot.net"
BR2_OPTIMIZE_3=y
BR2_TARGET_GENERIC_HOSTNAME="luckfox pico"
BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico"
BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox"
BR2_SYSTEM_ENABLE_NLS=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_ALSA_UTILS=y
BR2_PACKAGE_ALSA_UTILS_ALSACONF=y
BR2_PACKAGE_ALSA_UTILS_ACONNECT=y
BR2_PACKAGE_ALSA_UTILS_AMIXER=y
BR2_PACKAGE_ALSA_UTILS_APLAY=y
BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y
BR2_PACKAGE_BLUEZ_ALSA=y
BR2_PACKAGE_BLUEZ_ALSA_HCITOP=y
BR2_PACKAGE_BLUEZ_ALSA_RFCOMM=y
BR2_PACKAGE_FFMPEG_FFPLAY=y
BR2_PACKAGE_FFMPEG_FFPROBE=y
BR2_PACKAGE_FFMPEG_AVRESAMPLE=y
BR2_PACKAGE_JACK2=y
BR2_PACKAGE_JACK2_LEGACY=y
BR2_PACKAGE_JACK2_DBUS=y
BR2_PACKAGE_MADPLAY=y
BR2_PACKAGE_MPV=y
BR2_PACKAGE_PULSEAUDIO=y
BR2_PACKAGE_SOX=y
BR2_PACKAGE_GZIP=y
BR2_PACKAGE_P7ZIP=y
BR2_PACKAGE_UNZIP=y
BR2_PACKAGE_XZ=y
BR2_PACKAGE_ZIP=y
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
BR2_PACKAGE_SDL2_GFX=y
BR2_PACKAGE_SDL2_IMAGE=y
BR2_PACKAGE_SDL2_MIXER=y
BR2_PACKAGE_SDL2_NET=y
BR2_PACKAGE_SDL2_TTF=y
BR2_PACKAGE_VULKAN_HEADERS=y
BR2_PACKAGE_DBUS_CPP=y
BR2_PACKAGE_DBUS_TRIGGERD=y
BR2_PACKAGE_EVTEST=y
BR2_PACKAGE_PYTHON3_SSL=y
BR2_PACKAGE_PYTHON_AIOHTTP=y
BR2_PACKAGE_PYTHON_CLICK=y
BR2_PACKAGE_PYTHON_ITSDANGEROUS=y
BR2_PACKAGE_PYTHON_JINJA2=y
BR2_PACKAGE_PYTHON_PERIPHERY=y
BR2_PACKAGE_PYTHON_PILLOW=y
BR2_PACKAGE_PYTHON_SERIAL=y
BR2_PACKAGE_PYTHON_SETUPTOOLS=y
BR2_PACKAGE_PYTHON_SMBUS_CFFI=y
BR2_PACKAGE_PYTHON_SPIDEV=y
BR2_PACKAGE_PYTHON_WERKZEUG=y
BR2_PACKAGE_LIBAO=y
BR2_PACKAGE_PORTAUDIO=y
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_LIBDRM=y
BR2_PACKAGE_DTC=y
BR2_PACKAGE_DTC_PROGRAMS=y
BR2_PACKAGE_LIBV4L=y
BR2_PACKAGE_LIBV4L_UTILS=y
BR2_PACKAGE_CJSON=y
BR2_PACKAGE_CJSON_UTILS=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_LIBCURL_CURL=y
BR2_PACKAGE_LIBCURL_VERBOSE=y
BR2_PACKAGE_LIBRSYNC=y
BR2_PACKAGE_PCRE2=y
BR2_PACKAGE_PCRE2_16=y
BR2_PACKAGE_PCRE2_32=y
BR2_PACKAGE_BLUEZ_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y
BR2_PACKAGE_BMON=y
BR2_PACKAGE_DHCPCD=y
BR2_PACKAGE_IPERF=y
BR2_PACKAGE_IPERF3=y
BR2_PACKAGE_IPTABLES=y
BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
BR2_PACKAGE_IPTABLES_NFTABLES=y
BR2_PACKAGE_IW=y
BR2_PACKAGE_LRZSZ=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_PPPD_FILTER=y
BR2_PACKAGE_PPPD_RADIUS=y
BR2_PACKAGE_RSYNC=y
BR2_PACKAGE_SAMBA4=y
BR2_PACKAGE_SOCAT=y
BR2_PACKAGE_WGET=y
BR2_PACKAGE_BASH=y
BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y
BR2_PACKAGE_DIALOG=y
BR2_PACKAGE_TIME=y
BR2_PACKAGE_HTOP=y
BR2_PACKAGE_PROCPS_NG=y
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
BR2_PACKAGE_NANO=y
BR2_PACKAGE_HOST_DTC=y
@@ -0,0 +1,185 @@
Add a minimal wordexp(3) for uClibc-ng, which the Rockchip toolchain
builds without. BlueZ (bluetoothctl via src/shared/shell.c, and a few
tools) includes <wordexp.h> unconditionally; DEFAULT_INCLUDES=-I. makes
this top-level header resolve. WRDE_NOCMD is always passed, so a
whitespace/quote tokenizer is a semantically complete substitute.
Signed-off-by: BlueFlare Warden <noah@wildrosemining.com>
diff --git a/wordexp.h b/wordexp.h
new file mode 100644
index 0000000..1111111
--- /dev/null
+++ b/wordexp.h
@@ -0,0 +1,171 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Minimal wordexp(3) for uClibc-ng.
+ *
+ * The Rockchip external toolchain's uClibc-ng is built without wordexp, so it
+ * ships no <wordexp.h>. Several BlueZ sources (src/shared/shell.c, which is
+ * bluetoothctl's command reader, plus a few tools) include <wordexp.h>
+ * unconditionally and call wordexp()/wordfree(). They always pass WRDE_NOCMD
+ * -- "no command substitution" -- and use the result only to split a command
+ * line into words, so a whitespace/quote tokenizer is a semantically complete
+ * substitute. This is deliberately NOT a general shell expander: no globbing,
+ * no variable or command substitution (WRDE_NOCMD is precisely the request to
+ * omit those). Placed at the BlueZ source root, where DEFAULT_INCLUDES = -I.
+ * makes <wordexp.h> resolve to it.
+ */
+#ifndef _WORDEXP_H_
+#define _WORDEXP_H_
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#define WRDE_DOOFFS 0x0001
+#define WRDE_APPEND 0x0002
+#define WRDE_NOCMD 0x0004
+#define WRDE_REUSE 0x0008
+#define WRDE_SHOWERR 0x0010
+#define WRDE_UNDEF 0x0020
+
+enum {
+ WRDE_SUCCESS = 0,
+ WRDE_NOSPACE = 1,
+ WRDE_BADCHAR = 2,
+ WRDE_BADVAL = 3,
+ WRDE_CMDSUB = 4,
+ WRDE_SYNTAX = 5,
+};
+
+typedef struct {
+ size_t we_wordc; /* number of words */
+ char **we_wordv; /* NULL-terminated vector of words */
+ size_t we_offs; /* reserved-slot count; also used as a scratch flag
+ by shell.c, which never passes WRDE_DOOFFS */
+} wordexp_t;
+
+__attribute__((unused))
+static int wordexp(const char *words, wordexp_t *we, int flags)
+{
+ size_t n, i;
+ char **vec;
+ const char *p;
+ int appending;
+ size_t orig_n; /* we->we_wordc as of function entry, so a failure
+ partway through a WRDE_APPEND call can put the
+ vector back to exactly its pre-call length rather
+ than leaving it part-grown or short a
+ terminator */
+
+ if (words == NULL || we == NULL)
+ return WRDE_BADCHAR;
+
+ appending = (flags & WRDE_APPEND) && we->we_wordv != NULL;
+ if (appending) {
+ n = we->we_wordc; /* append to the existing vector */
+ vec = we->we_wordv;
+ } else {
+ n = 0;
+ vec = calloc(1, sizeof(char *));
+ if (vec == NULL)
+ return WRDE_NOSPACE;
+ }
+ orig_n = n;
+
+ for (p = words; *p != '\0'; ) {
+ size_t cap = 16, len = 0;
+ char *w, *tw, **t;
+
+ while (*p != '\0' && isspace((unsigned char)*p))
+ p++;
+ if (*p == '\0')
+ break;
+
+ w = malloc(cap);
+ if (w == NULL)
+ goto nospace;
+
+ while (*p != '\0' && !isspace((unsigned char)*p)) {
+ char c;
+
+ if (*p == '\'' || *p == '"') {
+ char q = *p++;
+ while (*p != '\0' && *p != q) {
+ if (len + 1 >= cap) {
+ cap *= 2;
+ tw = realloc(w, cap);
+ if (tw == NULL) { free(w); goto nospace; }
+ w = tw;
+ }
+ w[len++] = *p++;
+ }
+ if (*p == q)
+ p++;
+ continue;
+ }
+ if (*p == '\\' && p[1] != '\0')
+ p++;
+ c = *p++;
+ if (len + 1 >= cap) {
+ cap *= 2;
+ tw = realloc(w, cap);
+ if (tw == NULL) { free(w); goto nospace; }
+ w = tw;
+ }
+ w[len++] = c;
+ }
+ w[len] = '\0';
+
+ t = (char **)realloc(vec, (n + 2) * sizeof(char *));
+ if (t == NULL) { free(w); goto nospace; }
+ vec = t;
+ vec[n++] = w;
+ vec[n] = NULL;
+ }
+
+ if (n == 0)
+ vec[0] = NULL; /* keep the vector NULL-terminated */
+
+ we->we_wordv = vec;
+ we->we_wordc = n;
+ return WRDE_SUCCESS;
+
+nospace:
+ if (appending) {
+ /* vec already carries every word from before this call --
+ realloc() preserves existing contents whether it
+ relocates the block. Only entries at orig_n and above are
+ this call's own; free those and put the vector back to
+ exactly its pre-call length. vec, not we->we_wordv, is what
+ still points at that data: realloc() may already have
+ relocated or freed the pointer we->we_wordv held on entry,
+ which is exactly why the old cleanup here could free the
+ caller's pre-existing words and leave we->we_wordv
+ dangling. */
+ for (i = orig_n; i < n; i++)
+ free(vec[i]);
+ vec[orig_n] = NULL;
+ we->we_wordv = vec;
+ we->we_wordc = orig_n;
+ } else {
+ for (i = 0; i < n; i++)
+ free(vec[i]);
+ free(vec);
+ }
+ return WRDE_NOSPACE;
+}
+
+__attribute__((unused))
+static void wordfree(wordexp_t *we)
+{
+ size_t i;
+
+ if (we == NULL || we->we_wordv == NULL)
+ return;
+ for (i = 0; i < we->we_wordc; i++)
+ free(we->we_wordv[i]);
+ free(we->we_wordv);
+ we->we_wordv = NULL;
+ we->we_wordc = 0;
+}
+
+#endif /* _WORDEXP_H_ */
@@ -0,0 +1,84 @@
Bessel J1 for mpv's EWA/jinc scaler. The Rockchip external toolchain's
uClibc-ng does not provide j1()/j0()/jn() -- confirmed absent from
libuClibc-1.0.31.so in the arm-rockchip830-linux-uclibcgnueabihf sysroot
this SDK builds against, the same gap the bluez5_utils wordexp patch in
this series works around for a different function. jinc() (video/out/
filter_kernels.c) scales its argument by M_PI before calling this, and
mpv's --scale-radius is user-settable, so BesselJ1 has to be accurate
over the whole double range a real j1() would cover, not just small
arguments -- the version this replaces summed a fixed 11-term power
series whose terms have not converged by the time n runs out for any
x much past 6 or 7, and are off by 7+ orders of magnitude by x=20.
--- a/video/out/filter_kernels.c 2024-04-26 11:14:00.377199103 +0800
+++ b/video/out/filter_kernels.c 2024-04-26 11:13:50.217202856 +0800
@@ -32,6 +32,60 @@
// NOTE: all filters are designed for discrete convolution
+/*
+ * mpv's libm on this target is uClibc-ng, which does not provide
+ * j1()/j0()/jn() -- confirmed absent from libuClibc-1.0.31.so in the
+ * arm-rockchip830-linux-uclibcgnueabihf sysroot this SDK builds
+ * against. jinc() (below) scales its argument by M_PI before calling
+ * this, and --scale-radius is user-settable, so this has to hold up
+ * over the whole double range, not just small arguments.
+ *
+ * A plain power series is only exact up to about x=20 in double
+ * precision: past that, terms grow before they shrink, and summing
+ * large alternating terms loses precision to cancellation. So this
+ * sums the series -- by a term-to-term ratio rather than separate
+ * factorial()/power() calls, which also keeps it from overflowing at
+ * large n -- only while each new term is still negligible against the
+ * running sum, and falls back to the standard second-order asymptotic
+ * expansion for Bessel functions (Abramowitz & Stegun 9.2.5/9.2.6,
+ * order 1) once x passes that point. Checked against libm's j1() on
+ * the build host across x in [0, 5000]: max absolute error 5e-8, max
+ * relative error 5e-5 away from J1's zero crossings, where any finite
+ * error reads large against a reference near zero.
+ */
+static double warden_j1_series(double x)
+{
+ double half = x / 2.0;
+ double term = half;
+ double sum = term;
+ double xsq = -(half * half);
+ for (int n = 1; n < 80; n++) {
+ term *= xsq / ((double)n * (double)(n + 1));
+ sum += term;
+ if (fabs(term) < 1e-18 * fabs(sum))
+ break;
+ }
+ return sum;
+}
+
+static double warden_j1_asymptotic(double x)
+{
+ double omega = x - 3.0 * M_PI / 4.0;
+ double x2 = x * x;
+ double p = 1.0 + 15.0 / (128.0 * x2) - 4725.0 / (32768.0 * x2 * x2);
+ double q = 3.0 / (8.0 * x) - 105.0 / (1024.0 * x2 * x)
+ + 363825.0 / (1310720.0 * x2 * x2 * x);
+ return sqrt(2.0 / (M_PI * x)) * (p * cos(omega) - q * sin(omega));
+}
+
+static double BesselJ1(double x)
+{
+ int neg = x < 0;
+ double ax = fabs(x);
+ double r = (ax < 12.0) ? warden_j1_series(ax) : warden_j1_asymptotic(ax);
+ return neg ? -r : r;
+}
+
const struct filter_window *mp_find_filter_window(const char *name)
{
if (!name)
@@ -324,7 +378,7 @@
if (fabs(x) < 1e-8)
return 1.0;
x *= M_PI;
- return 2.0 * j1(x) / x;
+ return 2.0 * BesselJ1(x) / x;
}
static double sphinx(params *p, double x)
@@ -0,0 +1,74 @@
The busybox applet set this image ships.
Not a preference: two things in the firmware depend on it directly.
CONFIG_FEATURE_FANCY_SLEEP=y is why `sleep 0.1` works in the init scripts, and
`# CONFIG_TIMEOUT is not set` is why S09splash's touch probe cannot use
timeout(1) and backgrounds a reader instead. It also builds telnetd in.
This file lived only in the vendor SDK's unpacked buildroot tree, which is not
in the vendor checkout and not in any manifest, so none of that was recorded
anywhere (#135).
--- a/package/busybox/busybox.config
+++ b/package/busybox/busybox.config
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
# Busybox version: 1.36.1
-# Wed May 8 17:25:31 2024
+# Sat Dec 9 10:36:18 2023
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -782,7 +782,7 @@
# CONFIG_FEATURE_CROND_D is not set
# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
CONFIG_FEATURE_CROND_SPECIAL_TIMES=y
-CONFIG_FEATURE_CROND_DIR="/etc/cron"
+CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
CONFIG_CRONTAB=y
# CONFIG_DEVFSD is not set
# CONFIG_DEVFSD_MODLOAD is not set
@@ -835,7 +835,7 @@
CONFIG_PARTPROBE=y
# CONFIG_RAIDAUTORUN is not set
# CONFIG_READAHEAD is not set
-# CONFIG_RFKILL is not set
+CONFIG_RFKILL=y
CONFIG_RUNLEVEL=y
# CONFIG_RX is not set
CONFIG_SEEDRNG=y
@@ -968,18 +968,18 @@
CONFIG_ROUTE=y
# CONFIG_SLATTACH is not set
# CONFIG_SSL_CLIENT is not set
-# CONFIG_TC is not set
-# CONFIG_FEATURE_TC_INGRESS is not set
+CONFIG_TC=y
+CONFIG_FEATURE_TC_INGRESS=y
# CONFIG_TCPSVD is not set
# CONFIG_UDPSVD is not set
CONFIG_TELNET=y
CONFIG_FEATURE_TELNET_TTYPE=y
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
CONFIG_FEATURE_TELNET_WIDTH=y
-# CONFIG_TELNETD is not set
-# CONFIG_FEATURE_TELNETD_STANDALONE is not set
-CONFIG_FEATURE_TELNETD_PORT_DEFAULT=0
-# CONFIG_FEATURE_TELNETD_INETD_WAIT is not set
+CONFIG_TELNETD=y
+CONFIG_FEATURE_TELNETD_STANDALONE=y
+CONFIG_FEATURE_TELNETD_PORT_DEFAULT=23
+CONFIG_FEATURE_TELNETD_INETD_WAIT=y
CONFIG_TFTP=y
# CONFIG_FEATURE_TFTP_PROGRESS_BAR is not set
CONFIG_FEATURE_TFTP_HPA_COMPAT=y
@@ -1016,7 +1016,7 @@
CONFIG_FEATURE_UDHCPC_ARPING=y
CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
-CONFIG_UDHCPC6_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
+CONFIG_UDHCPC6_DEFAULT_SCRIPT=""
# CONFIG_UDHCPC6 is not set
# CONFIG_FEATURE_UDHCPC6_RFC3646 is not set
# CONFIG_FEATURE_UDHCPC6_RFC4704 is not set
@@ -0,0 +1,9 @@
# flare-edge: build the PWM backlight driver in, not as a module.
#
# Building the PWM backlight as a module means its class device does not exist
# until userspace insmods pwm_bl.ko (~3.3-3.7s, via S25backlight). The
# U-Boot -> kernel drm_logo boot-splash handoff replaces its framebuffer
# at almost exactly that same time, so there is effectively no window
# where a backlight device exists AND the logo is still on screen.
# Built-in makes the device exist from early kernel boot instead.
CONFIG_BACKLIGHT_PWM=y
@@ -0,0 +1,104 @@
# flare-edge kernel config fragment
#
# Merged by the RK build: BoardConfig-...-86Panel-IPC.mk names this file in
# the kernel fragment list (".mk:88"), and tools/build-firmware.sh's
# copy_fragments step installs it into arch/arm/configs/ before the kernel
# build. (It had, until now, existed ONLY as an untracked hand-edit in the SDK
# working copy at arch/arm/configs/flare-edge.config -- the exact stale-copy
# trap sdk-patches/ exists to close. This tracked form is authoritative.)
# --- kexec (SSH-side kernel swap, no flash writes) -------------------------
# Enable kexec so a new kernel can be booted from a running SSH session
# with zero writes to flash. The stock image has this stubbed out: all of
# sys_kexec_load / sys_kexec_file_load / compat_sys_kexec_load resolve to
# the same sys_ni_syscall address, so the syscall is absent.
#
# KEXEC depends on (!SMP || PM_SLEEP_SMP) && MMU. RV1106 is a single-core
# Cortex-A7 and symmetric multiprocessing is disabled in the base defconfig,
# so the dependency is satisfied.
CONFIG_KEXEC=y
# --- RGA2 2D engine + CMA dma-buf heaps (graph-scroll offload) --------------
# warden: enable the RV1106 RGA2 2D engine (/dev/rga) for graph-scroll offload.
# Builtin (not =m) so devtmpfs auto-creates the node at boot; the rga2 DT node is
# already status="okay" via rv1106-evb.dtsi, so no device-tree change is needed.
CONFIG_ROCKCHIP_MULTI_RGA=y
# Portable CMA dma-buf allocator (/dev/dma_heap/cma) for contiguous, RGA-safe
# (no-IOMMU) graph canvas buffers; reuses the existing 10MB linux,cma pool.
CONFIG_DMABUF_HEAPS=y
CONFIG_DMABUF_HEAPS_CMA=y
# --- host-side USB-Ethernet class drivers (router mode adds a LAN port) ------
# In router mode S26usbhost flips the OTG port to USB HOST so a USB-Ethernet
# adapter enumerates as an extra network port. The stock defconfig ships
# the USB network driver menu disabled, so even once the DTS dr_mode="otg" host
# switch (sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch) brings xHCI
# up, no ethN netdev would be created. Build these in (=y, not =m) so a NIC works
# with zero userspace insmod, from early boot. Covers the common adapter silicon:
# CDC-ECM/NCM (generic), ASIX AX88xxx (2.0 + gigabit), Realtek RTL8152/8153.
# Trim to the adapters actually deployed if image size matters.
CONFIG_USB_NET_DRIVERS=y
CONFIG_USB_USBNET=y
CONFIG_USB_NET_CDCETHER=y
CONFIG_USB_NET_CDC_NCM=y
CONFIG_USB_NET_AX8817X=y
CONFIG_USB_NET_AX88179_178A=y
CONFIG_USB_RTL8152=y
# --- WireGuard (FLARE management mesh) --------------------------------------
# Kernel WireGuard is the chosen mesh transport (module + userspace `wg`, not
# boringtun). The base luckfox_rv1106_linux_defconfig ALREADY builds it in
# (built in at line ~212), and =y Kconfig-selects its crypto/UDP-tunnel
# deps (CHACHA20POLY1305, CURVE25519, NET_UDP_TUNNEL), so nothing is missing and
# no dep lines are needed here. We PIN =y (rather than the =m the task named, or
# omitting it) so a future defconfig drift cannot silently drop the mesh
# transport -- and so this fragment documents that WireGuard is a hard build
# requirement. =y > =m here: no insmod, present from boot. Do NOT set =m: that
# would DOWNGRADE the built-in to a module and merge_config would flag the
# conflict.
CONFIG_WIREGUARD=y
# --- 802.1Q VLAN (per-port router subnets, MikroTik switch termination) --------
# router.c terminates each per-port subnet as an eth1.<vid> 802.1Q subinterface
# (`ip link add link eth1 name eth1.<vid> type vlan id <vid>`), which needs 8021q
# in the kernel; without it that call returns EOPNOTSUPP, so the VLAN config
# screen + MikroTik app could program a switch the warden itself cannot route.
#
# ABI NOTE (root-caused on hardware 2026-08-13): enabling this inserts a
# `struct vlan_info *vlan_info;` into `struct net_device`
# (include/linux/netdevice.h, under the VLAN feature guard), which
# shifts the offset of every field after it. The out-of-tree aic8800 wifi driver
# and the modular cfg80211.ko MUST be rebuilt against this config or they read
# net_device at stale offsets and NULL-deref at boot (crash in rwnx_interface_add
# -> the "white logo" hang). A clean image build does this correctly:
# build.sh kernel (mrproper -> clean VLAN kernel)
# build.sh rootfs (rebuilds drv_ko/aic8800 + cfg80211.ko against that kernel)
# build.sh firmware
# so boot.img and the /oem modules always ship as a consistent set. NEVER flash a
# VLAN boot.img over non-VLAN modules (that is what produced the hang during
# incremental testing). =y (not =m): =m also flips IS_ENABLED, so it changes the
# ABI identically while adding an insmod step for no benefit here.
CONFIG_VLAN_8021Q=y
# --- pstore/ramoops: persistent crash/boot log across a reset -----------------
# The debug UART is unwirable (under the daughterboard) and the USB CDC-ACM
# console (S52usbacm) only comes up in userspace, so NEITHER can capture a
# pre-userspace kernel hang -- which is exactly the class that bricked c8a3
# (a load address in unreserved kernel RAM, hung before eth0). pstore/ramoops
# keeps the kernel console ring + any oops/panic in a reserved DRAM region that
# survives the reset (warm reset preserves DRAM), so the NEXT boot can read
# /sys/fs/pstore and see the last words before the hang. Pairs with the already-
# shipped `panic=10` cmdline + enabled watchdog (a hang -> reset -> log persists)
# and the warden-flight recorder (which drains /sys/fs/pstore to /userdata, so
# the log is also MaskRom-`dd`-recoverable off a brick).
#
# The DRAM region is carved by a `ramoops@0f000000` reserved-memory node
# (sdk-patches/kernel/patches/0005-pstore-ramoops.patch): 1 MiB at 240 MiB, HIGH
# above the low kernel/DTB/initrd load zone, so reserving it can only remove RAM
# from the kernel -- it CANNOT recreate the c8a3 under-reservation collision.
# console-size captures dmesg (the boot log); record-size captures oops/panic.
CONFIG_PSTORE=y
CONFIG_PSTORE_DEFLATE_COMPRESS=y
CONFIG_PSTORE_CONSOLE=y
CONFIG_PSTORE_PMSG=y
CONFIG_PSTORE_RAM=y
@@ -0,0 +1,24 @@
# flare-edge: fbcon display policy -- keep OUR splash on screen, uninterrupted.
#
# Two separate problems, both fbcon, both fixed here.
#
# 1) The generic Linux logo option draws
# drivers/video/logo/logo_linux_clut224.ppm whenever fbcon takes over a
# framebuffer. This is NOT Rockchip's drm_logo handoff -- it is the
# kernel's generic boot-logo feature, and the LuckFox SDK ships that file
# replaced with their own fox-head + "LUCKFOX" wordmark. It painted over
# our white BlueFlare logo on every boot.
#
# 2) The takeover itself. Even with no logo to draw, fbcon seizing the
# framebuffer destroys the drm_logo image U-Boot handed us -- measured at
# 1.895s, only 0.83s after the backlight came on at 1.068s, so the white
# logo appeared as a brief flash and then the panel went blank until the
# userspace colour splash. DEFERRED_TAKEOVER makes fbcon wait until
# something actually writes text to the console before claiming the fb.
# Our console is ttyFIQ0 (serial), so in practice nothing ever does, and
# the U-Boot logo survives until S09splash draws over it deliberately.
#
# Deps for DEFERRED_TAKEOVER (FB=y, FRAMEBUFFER_CONSOLE, DUMMY_CONSOLE) are
# all already satisfied in this defconfig -- verified before enabling.
# CONFIG_LOGO is not set
CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y
@@ -0,0 +1,10 @@
# WireGuard, built in rather than as a module.
#
# =y not =m deliberately: modules live on the oem partition and must be
# reflashed in lockstep with the kernel, and this one is ~40KB. Paying that in
# boot.img is cheaper than another matched-pair failure mode.
#
# Everything WireGuard needs it "select"s for itself (NET_UDP_TUNNEL,
# DST_CACHE, CRYPTO_LIB_CURVE25519, CRYPTO_LIB_CHACHA20POLY1305), so unlike the
# USB-Ethernet fragment there is no menu gate to open first. Verify anyway.
CONFIG_WIREGUARD=y
@@ -0,0 +1,20 @@
# USB host + USB-Ethernet class drivers (flare-edge).
#
# The first symbol is the MENU GATE. Every driver below lives inside the
# USB_NET_DRIVERS menuconfig, so without it kconfig discards the lot in
# silence -- no warning, and not even the usual "not in final .config" from
# merge_config.sh.
#
# Do not begin a comment line here with a hash followed by CONFIG_. That is
# exactly the "is not set" syntax, so merge_config.sh parses the prose as a
# directive and reports it as a redefinition of the symbol it names.
CONFIG_USB_NET_DRIVERS=y
CONFIG_USB_USBNET=y
CONFIG_USB_NET_CDCETHER=y
CONFIG_USB_NET_CDC_NCM=y
CONFIG_USB_NET_CDC_EEM=y
CONFIG_USB_RTL8152=y
CONFIG_USB_NET_AX8817X=y
CONFIG_USB_NET_AX88179_178A=y
CONFIG_USB_NET_SMSC95XX=y
CONFIG_USB_NET_MCS7830=y
@@ -0,0 +1,82 @@
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
index 8c07a90d3..ece8d149f 100755
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
@@ -147,3 +158,77 @@ &uart4 {
pinctrl-names = "default";
pinctrl-0 = <&uart4m0_xfer>;
};
+
+/**********PANEL RESET + BACKLIGHT LINK**********/
+/*
+ * Restored from the FACTORY device tree (extracted from the stock boot.img of
+ * this unit and diffed against current SDK HEAD, which had silently dropped
+ * both properties). Without them the panel is never taken out of reset: DRM
+ * sets 720x720@48.87Hz, the connector reports "connected", the VOP streams
+ * pixels and the PWM backlight lights — but the panel controller is
+ * unconfigured, so the screen stays black. Even a `modetest` test pattern is
+ * invisible, which is what proved the fault sits BELOW DRM rather than in
+ * fbdev or the app.
+ *
+ * gpio0 RK_PA1 is the same line U-Boot drives via `gpio set 1 1` when
+ * CONFIG_LUCKFOX_EXECUTE_CMD is set (rv1106-luckfox-rgb-reset.config) — that
+ * "Luckfox Pico RGB MCU reset" is the RGB panel's reset, not an LED.
+ *
+ * Factory values: reset-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>, reset-delay-ms = 200
+ */
+&panel {
+ /*
+ * flare-edge: backlight ONLY. reset-gpios and reset-delay-ms are
+ * deliberately absent -- do not "restore" them.
+ *
+ * GPIO0_A1 is not the panel's reset. The schematic (U6 on
+ * Luckfox-Pico-86-Panel.pdf) shows a WCH CH32V003 RISC-V MCU whose sole
+ * job is to clock this panel's SPI init sequence into it, and the net
+ * RGB_RES ties SoC GPIO0_A1, the panel RESET pin (FPC 6) and the MCU's
+ * NRST (pin 1) together. Luckfox's own U-Boot comment says as much:
+ * "Luckfox Pico RGB MCU reset gpio".
+ *
+ * So giving panel-simple this GPIO makes drm_panel_prepare() assert it
+ * for reset-delay-ms and release it -- REBOOTING THE INIT MCU while the
+ * VOP is already scanning pixels. The panel is then clocked with RGB
+ * data before its power/gamma/VCOM registers are written, which is
+ * exactly the faint coloured vertical banding seen for ~1-3 s on every
+ * boot, and why a GPIO "reset" never cleared it (it re-ran the race).
+ *
+ * Luckfox removed these two properties in commit e2b0ffa22 for this
+ * reason. An earlier revision of this file re-added them, having read
+ * the deletion as an accidental regression -- see 40-kernel-stack.md,
+ * which recorded them as "silently dropped" by SDK HEAD. They were not
+ * dropped; they were the fix.
+ *
+ * The MCU is released exactly once, early, by U-Boot: board_init()
+ * drives GPIO0_A1 high, and luckfox_execute_cmd() does the same again
+ * harmlessly. At power-on the pin is input-with-pulldown, so the MCU is
+ * held in reset until then, which is the intended sequencing.
+ *
+ * backlight is kept because U-Boot's rockchip_panel.c takes its
+ * backlight handle from this node, and our boot logo needs it.
+ */
+ backlight = <&backlight>;
+};
+
+/*
+ * flare-edge: enable the U-Boot/kernel boot logo route.
+ *
+ * The whole RGB pipeline (display_subsystem, rgb, rgb_in_vop, vop) is already
+ * "okay" in rv1106-luckfox-pico-86panel-ipc.dtsi, and that file also wires
+ * logo-memory-region = <&drm_logo>. route_rgb was the only piece left
+ * disabled, and without it U-Boot's rockchip_display finds no route and skips
+ * drawing entirely.
+ *
+ * The node itself (rv1106.dtsi) already carries logo,uboot = "logo.bmp",
+ * logo,kernel = "logo_kernel.bmp" and logo,mode = "center". Those files come
+ * from resource.img, which scripts/mkmultidtb.py builds with
+ * `resource_tool logo.bmp logo_kernel.bmp <dtbs>` out of the kernel source
+ * directory -- so replacing sysdrv/source/kernel/logo.bmp is what changes the
+ * splash. Setting logo,kernel to the same image keeps it on screen from
+ * U-Boot through kernel handover until LVGL takes over.
+ */
+&route_rgb {
+ status = "okay";
+};
@@ -0,0 +1,28 @@
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
index 8c07a90d3..a9eb6c9d0 100755
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
@@ -114,6 +114,23 @@ &gmac {
status = "okay";
};
+/**********WATCHDOG (flare-edge: docs/firmware-update.md §6.6 item 4, §6.7)**********/
+/*
+ * flare-edge: enable the RV1106 designware watchdog.
+ *
+ * The kernel already builds CONFIG_DW_WATCHDOG, but rv1106.dtsi ships this
+ * `wdt` node status = "disabled", so /dev/watchdog never appears. Once it is
+ * "okay", warden-flared opens /dev/watchdog, sets a timeout (<= ~89 s on this
+ * core) and pets it ONLY while the UI is proven live (ui_alive_fresh), after a
+ * short unconditional boot grace. A post-boot hang then stops the pets, the SoC hard-resets,
+ * and that reset is another boot U-Boot's bootcount sees -- so a wedged new
+ * image converges to bootlimit -> altbootcmd -> recovery, exactly like a kernel
+ * panic (docs §6.7). One line; needs a boot.img reflash.
+ */
+&wdt {
+ status = "okay";
+};
+
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
@@ -0,0 +1,28 @@
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
index 8c07a90d3..efc27c0b8 100755
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
@@ -117,8 +117,21 @@ &gmac {
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
- dr_mode = "peripheral";
- //dr_mode = "host";
+ /*
+ * flare-edge: dual-role (OTG), not peripheral-only.
+ *
+ * router mode switches the port to USB HOST at runtime (S26usbhost writes
+ * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates
+ * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the
+ * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the
+ * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles
+ * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime
+ * host switch actually hosts. It still boots peripheral-by-default (ID floats
+ * device until `host` asserts it), so the usb0 RNDIS recovery gadget that
+ * client mode + net-flash rely on continues to bind. "host" alone would break
+ * that recovery gadget, so "otg" is the correct value.
+ */
+ dr_mode = "otg";
};
/**********RTC**********/
@@ -0,0 +1,26 @@
--- a/sysdrv/source/kernel/scripts/mkimg
+++ b/sysdrv/source/kernel/scripts/mkimg
@@ -51,6 +51,11 @@
LOGO_KERNEL_PATH=${srctree}/logo_kernel.bmp
[ -f ${LOGO_KERNEL_PATH} ] && LOGO_KERNEL=logo_kernel.bmp
+# flare-edge: USB-recovery splash, drawn by U-Boot's download path
+# (cmd/download.c rockchip_show_bmp("logo_recovery.bmp"))
+LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp
+[ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp
+
KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image
KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}"
if [ "${ARCH}" == "arm" ]; then
@@ -243,8 +248,9 @@
cp -a ${LOGO_KERNEL_PATH} ${objtree}/;
fi
fi
-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} >/dev/null
-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL}) is ready"
+[ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}"
+scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null
+echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready"
if [ -f "${BOOT_IMG}" ]; then
if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then
@@ -0,0 +1,25 @@
--- a/sysdrv/source/kernel/scripts/mkimg
+++ b/sysdrv/source/kernel/scripts/mkimg
@@ -55,7 +55,10 @@
# (cmd/download.c rockchip_show_bmp("logo_recovery.bmp"))
LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp
[ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp
+# flare-edge: tapped verbose-boot acknowledgement, selected by U-Boot
+LOGO_VERBOSE_PATH=${srctree}/logo_verbose.bmp
+[ -f ${LOGO_VERBOSE_PATH} ] && LOGO_VERBOSE=logo_verbose.bmp
KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image
KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}"
if [ "${ARCH}" == "arm" ]; then
@@ -248,8 +251,9 @@
fi
fi
[ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}"
-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null
-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready"
+[ -n "${LOGO_VERBOSE}" ] && cp -f "${LOGO_VERBOSE_PATH}" "${LOGO_VERBOSE}"
+scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE} >/dev/null
+echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE}) is ready"
if [ -f "${BOOT_IMG}" ]; then
if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then
@@ -0,0 +1,32 @@
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
index f4e6fb77e..202710496 100755
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
@@ -108,6 +108,27 @@ linux,cma {
mmc_ecsd: mmc@3f000 {
reg = <0x3f000 0x00001000>;
};
+
+ /*
+ * flare-edge: pstore/ramoops persistent crash region. 1 MiB at
+ * 240 MiB (of 256 MiB DRAM: reg = <0x0 0x10000000>). Placed HIGH,
+ * far above the low kernel-image/DTB/initrd load zone, so this
+ * carve-out can only REMOVE RAM from the kernel -- it cannot cause
+ * the c8a3-class collision (which was an UN-reserved 0x40000 used
+ * by both the boot MCU and the kernel). Kept below the very top of
+ * DRAM (U-Boot self-relocates there) so the log is more likely to
+ * survive into the recovery boot. console-size captures the kernel
+ * console ring (the boot log before a hang); record-size captures
+ * oops/panic. No ECC (no reed-solomon dep); no no-map (ramoops
+ * memremaps the region itself). See kernel cfg flare-edge.config.
+ */
+ ramoops@0f000000 {
+ compatible = "ramoops";
+ reg = <0x0f000000 0x00100000>;
+ console-size = <0x00040000>;
+ record-size = <0x00020000>;
+ pmsg-size = <0x00020000>;
+ };
};
acodec_sound: acodec-sound {
@@ -0,0 +1,23 @@
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
index f4e6fb77e..dc08f6256 100755
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
@@ -302,3 +302,18 @@ tp_irq: tp-irq {
};
};
};
+
+/*********************** on-demand MaskRom ************************/
+/*
+ * flare-edge: let the OS reach TRUE BootROM MaskRom (USB 2207:110c, reliably
+ * flashable) via `warden-maskrom maskrom` -> reboot(RESTART2,"maskrom") ->
+ * syscon-reboot-mode writes BOOT_BROM_DOWNLOAD to the boot-mode reg 0xff020200.
+ * One-shot: a power-on-reset clears the PMU-domain reg. The stock
+ * mode-loader/-bootloader only reach U-Boot rockusb "Loader" mode, whose WL is
+ * unreliable for multi-partition flashing (writes report 100% but do not
+ * persist); this reaches the BootROM proper, where db+wl are reliable.
+ * 0xEF08A53C == U-Boot BOOT_BROM_DOWNLOAD (arch-rockchip/boot_mode.h).
+ */
+&reboot_mode {
+ mode-maskrom = <0xEF08A53C>;
+};
@@ -0,0 +1,55 @@
The panel DTS as the SDK actually has it.
Replaying patches 0001-0006 onto a pristine vendor tree did not reproduce this
file: the board model string is "Luckfox Pico 86Panel W" in the SDK, and the
watchdog block 0002 adds sits in a different place. Both were hand-edits made
directly in the SDK checkout and never captured here, so a rebuild from a clean
vendor tree plus this series produced a DTS that differed from the one every
shipped image was built with.
This patch is the remainder, generated by diffing the replayed result against
the live SDK. It has no intent of its own beyond making the series faithful.
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
@@ -10,7 +10,7 @@
#include <dt-bindings/display/media-bus-format.h>
/ {
- model = "Luckfox Pico 86Panel";
+ model = "Luckfox Pico 86Panel W";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106g3";
restart-poweroff {
@@ -134,21 +134,17 @@
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
- /*
- * flare-edge: dual-role (OTG), not peripheral-only.
- *
- * router mode switches the port to USB HOST at runtime (S26usbhost writes
- * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates
- * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the
- * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the
- * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles
- * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime
- * host switch actually hosts. It still boots peripheral-by-default (ID floats
- * device until `host` asserts it), so the usb0 RNDIS recovery gadget that
- * client mode + net-flash rely on continues to bind. "host" alone would break
- * that recovery gadget, so "otg" is the correct value.
- */
+ /* otg, not host: CONFIG_USB_DWC3_DUAL_ROLE is built in, so the port can
+ * still come up as a gadget (usb0) when cabled to a PC while also being
+ * able to host a USB Ethernet adapter. host would work for the adapter
+ * but would remove the gadget link permanently. */
dr_mode = "otg";
+ //dr_mode = "peripheral";
+ //dr_mode = "host";
+ /* flare-edge: set to otg for the host/client live-switch test — a stable
+ * network path (onboard eth0) is now in hand, so the usb0-gadget-inconsistency
+ * that motivated the earlier peripheral revert no longer blocks us. This
+ * matches sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch. */
};
/**********RTC**********/
@@ -0,0 +1,10 @@
# flare-edge: A/B slot boot in U-Boot proper.
#
# Lean port of the vendor SPL A/B engine (common/flare_ab.c): AOSP
# AvbABData metadata in one CRC32-protected sector at misc+2048, slot
# suffixing hooked into part_get_info_by_name() (covers boot_fit AND the
# board_init()-time kernel-DTB/resource load), one tries decrement per
# boot attempt while a slot is unconfirmed, recovery-FIT fallback when
# both slots are exhausted, MaskRom when even that fails.
# Design: docs/decisions/0001-slot-machine.md (flare-edge repo).
CONFIG_FLARE_AB=y
@@ -0,0 +1,35 @@
# flare-edge: the env bootcount escalation layer is RETIRED.
#
# History: this fragment used to enable U-Boot's env bootcount
# options: autoboot.c incremented a counter in the 32 KiB env on
# every boot and, once it passed ${bootlimit}, ran ${altbootcmd}=download to
# drop into USB download/MaskRom. Two properties made it dangerous:
# 1. The counter lived in the env, so it PERSISTED across power cycles.
# 2. It escalated to USB download, not to the recovery FIT.
# A panel that lost power mid-boot several times therefore walked the counter
# past the limit and then booted straight into the USB-download screen on EVERY
# power-on, with no way to clear it from the device (issue #123, seen on a real
# panel at the warehouse 2026-09-02).
#
# Replacement: the A/B engine (common/flare_ab.c) now drives boot-failure
# escalation from a PMU register (OS_REG4), gated on the CRU reset-status
# register. It survives a warm reset (so in-session retries accumulate) but is
# cleared by a power-on reset, so escalation is: selected slot for a couple of
# attempts, then the other committed slot, then the recovery FIT, then USB
# download -- and a POWER CYCLE always restarts at the selected slot. flared
# clears OS_REG4 once a boot proves healthy and before a deliberate reboot. No
# per-boot flash writes, and no state that can strand a device across a power
# cycle. See docs/boot-flow.md and docs/decisions/0001-slot-machine.md.
#
# The filename is kept so the board makefile fragment-list reference
# (sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch) still resolves.
# This fragment is merged last, so it disables bootcount and sets the env
# whitelist authoritatively.
# CONFIG_BOOTCOUNT is not set
# CONFIG_BOOTCOUNT_LIMIT is not set
# CONFIG_BOOTCOUNT_ENV is not set
# Env whitelist WITHOUT the retired escalation keys (bootcount, bootlimit,
# altbootcmd, upgrade_available) -- a stale env carrying them can no longer feed
# the retired layer. bootcmd/bootdelay/preboot stay so a provisioned env can
# still override the compiled-in boot command.
CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr bootcmd bootdelay preboot"
@@ -0,0 +1,78 @@
# CONFIG_ATMEL_HLCD is not set
# CONFIG_BACKLIGHT_GPIO is not set
CONFIG_BACKLIGHT_PWM=y
# CONFIG_CMD_BMP is not set
# CONFIG_CMD_REGULATOR is not set
CONFIG_CONSOLE_NORMAL=y
# CONFIG_CONSOLE_ROTATION is not set
CONFIG_CONSOLE_SCROLL_LINES=1
# CONFIG_CONSOLE_TRUETYPE is not set
CONFIG_DISPLAY=y
CONFIG_DM_PWM=y
# CONFIG_DM_REGULATOR_FIXED is not set
# CONFIG_DM_REGULATOR_GPIO is not set
CONFIG_DM_REGULATOR=y
CONFIG_DM_VIDEO=y
# CONFIG_DRM_MAXIM_MAX96745 is not set
# CONFIG_DRM_MAXIM_MAX96752F is not set
# CONFIG_DRM_MAXIM_MAX96755F is not set
CONFIG_DRM_MEM_RESERVED_SIZE_MBYTES=32
CONFIG_DRM_MIPI_DSI=y
# CONFIG_DRM_PANEL_MAXIM_DESERIALIZER is not set
# CONFIG_DRM_ROCKCHIP_ANALOGIX_DP is not set
# CONFIG_DRM_ROCKCHIP_DW_DP is not set
# CONFIG_DRM_ROCKCHIP_DW_HDMI is not set
# CONFIG_DRM_ROCKCHIP_DW_HDMI_QP is not set
# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI2 is not set
# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI is not set
# CONFIG_DRM_ROCKCHIP_INNO_HDMI is not set
# CONFIG_DRM_ROCKCHIP_INNO_MIPI_PHY is not set
# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_COMBO_PHY is not set
# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_PHY is not set
# CONFIG_DRM_ROCKCHIP_LVDS is not set
CONFIG_DRM_ROCKCHIP_PANEL=y
CONFIG_DRM_ROCKCHIP_RGB=y
# CONFIG_DRM_ROCKCHIP_RK1000 is not set
# CONFIG_DRM_ROCKCHIP_RK618 is not set
# CONFIG_DRM_ROCKCHIP_SAMSUNG_MIPI_DCPHY is not set
CONFIG_DRM_ROCKCHIP=y
CONFIG_I2C_EDID=y
# CONFIG_NOP_PHY is not set
# CONFIG_PHY_ROCKCHIP_SAMSUNG_HDPTX_HDMI is not set
CONFIG_PHY=y
# CONFIG_PWM_EXYNOS is not set
CONFIG_PWM_ROCKCHIP=y
# CONFIG_PWM_TEGRA is not set
# CONFIG_REGULATOR_FAN53555 is not set
# CONFIG_REGULATOR_PWM is not set
# CONFIG_REGULATOR_RK860X is not set
CONFIG_ROCKCHIP_CUBIC_LUT_SIZE=0
# CONFIG_DRM_ROCKCHIP_TVE is not set
# CONFIG_ROCKCHIP_INNO_HDMI_PHY is not set
# CONFIG_SPL_DM_REGULATOR is not set
# CONFIG_VIDCONSOLE_AS_LCD is not set
CONFIG_VIDEO_BPP16=y
CONFIG_VIDEO_BPP32=y
CONFIG_VIDEO_BPP8=y
# CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345 is not set
# CONFIG_VIDEO_BRIDGE_NXP_PTN3460 is not set
# CONFIG_VIDEO_BRIDGE_PARADE_PS862X is not set
CONFIG_VIDEO_BRIDGE=y
# CONFIG_VIDEO_ROCKCHIP is not set
# CONFIG_VIDEO_TEGRA124 is not set
# flare-edge: BMP logo support for the boot splash. The rockchip_display logo
# path accepts 16/24/32bpp (display_logo() in drivers/video/drm/rockchip_display.c);
# our logo.bmp is 720x720 24bpp uncompressed, which matches the panel exactly.
# flare-edge: keep USING_KERNEL_DTB=y (the proven flow: envf import, fixups),
# but adopt an EMBEDDED kernel-style DTB instead of the booted slot's one. The
# 6.18 slot's mainline-style DTB has no vendor display nodes, which silenced
# the boot logo there; embedding the proven 5.10 board DTB (extracted from the
# vendor-built boot.img resource) makes U-Boot's own device world -- display
# included -- identical on every slot. Each slot's FIT still hands the real
# kernel its own fdt; fdt_addr_r stays reserved for it (see kernel_dtb.c).
# A DISABLED USING_KERNEL_DTB was tried first and broke the envf whitelist
# import (no blkdevparts on the cmdline -> no eMMC partitions -> rootwait
# hang on both slots); do not retry that route without fixing envf.
CONFIG_EMBED_KERNEL_DTB=y
CONFIG_EMBED_KERNEL_DTB_ALWAYS=y
CONFIG_EMBED_KERNEL_DTB_PATH="dts/rv1106-warden-kernel.dtb"
@@ -0,0 +1,7 @@
# flare-edge: build spl_bootrom.o so BOOT_DEVICE_BOOTROM is a registered SPL
# load method. Paired with the board_boot_order() change in
# arch/arm/mach-rockchip/spl-boot-order.c, this makes a failed U-Boot load drop
# to MaskRom instead of hanging. Does NOT set SPL_ROCKCHIP_BACK_TO_BROM: that
# would flip SPL_MMC_SUPPORT off (see mach-rockchip/Kconfig) and hand the whole
# load path to the BROM, which is a behaviour change we do not want.
CONFIG_SPL_BOOTROM_SUPPORT=y
@@ -0,0 +1,12 @@
# flare-edge: let U-Boot read the panel's touchscreen.
#
# The verbose-boot choice is made in the bootloader (see
# arch/arm/mach-rockchip/flare_touch.c), so it is on the kernel command line
# before the kernel prints its first line. That needs I2C, which this board's
# U-Boot did not have: only the EDID I2C helper was set, and that is the display
# path's EDID parser, not a controller driver.
#
# The GT911 sits on i2c3 (i2c@ff460000). Both symbols are required: the
# Rockchip controller driver depends on the DM I2C uclass.
CONFIG_DM_I2C=y
CONFIG_SYS_I2C_ROCKCHIP=y
@@ -0,0 +1,54 @@
# flare-edge: USB device-mode recovery from U-Boot (rockusb gadget).
#
# WHY: the BootROM only self-enters MaskRom when it cannot LOAD idblock/uboot.
# A U-Boot that loads but then fails to boot (a bug in our display/FLARE_AB
# code, an exhausted A/B set, a corrupt recovery FIT) never reaches Linux, so
# the software MaskRom trigger and the rescue-image RNDIS gadget are both
# unavailable, leaving only the daughterboard-blocked BOOT button. Enabling
# the DWC3 USB gadget + rockusb closes that gap: `download` (which FLARE_AB and
# altbootcmd already invoke on failure) runs `rockusb` FROM U-BOOT
# (cmd/download.c), exposing the Rockchip flashing protocol on the existing USB
# port (2207:110c, same as MaskRom to upgrade_tool). Recover or reflash without
# opening the case. Falls through to `rbrom` (BootROM MaskRom) only if the
# gadget can't start.
#
# RV1106 USB = DWC3 (rv1106.dtsi usb@ffb00000 snps,dwc3) + Innosilicon USB2
# PHY, dr_mode=otg. Symbols below mirror the vendor rv1106-usb.config /
# rv1106-dfu.config references. Fits the 512K uboot partition (A/B layout).
CONFIG_USB=y
CONFIG_DM_USB=y
CONFIG_USB_DWC3=y
CONFIG_USB_DWC3_GENERIC=y
CONFIG_USB_DWC3_GADGET=y
# dwc3-generic unconditionally compiles its host (xHCI) probe in non-SPL
# builds (it calls xhci_register), so the xHCI host core must link even though
# we only use gadget mode; the vendor rv1106-usb.config pairs them the same
# way. Harmless in peripheral/otg mode; the host driver is simply never probed.
CONFIG_USB_HOST=y
CONFIG_USB_XHCI_HCD=y
CONFIG_PHY_ROCKCHIP_INNO_USB2=y
CONFIG_DM_REGULATOR=y
CONFIG_DM_REGULATOR_FIXED=y
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_DUALSPEED=y
CONFIG_USB_GADGET_DOWNLOAD=y
# Fastboot is a separate download function whose FASTBOOT_BUF_ADDR symbol has
# no default and would make `yes "" | make oldconfig` loop forever (it produced
# a 16 GB log). We only want rockusb, so disable fastboot explicitly, exactly
# as the vendor rv1106-dfu.config does. rockusb coexists fine without it.
# CONFIG_FASTBOOT is not set
CONFIG_USB_GADGET_MANUFACTURER="Rockchip"
CONFIG_USB_GADGET_PRODUCT_NUM=0x110c
CONFIG_USB_GADGET_VENDOR_NUM=0x2207
CONFIG_USB_GADGET_VBUS_DRAW=2
# rockusb has no dedicated Kconfig symbol. f_rockusb.c is #include'd by
# f_mass_storage.c and gated purely by CMD_ROCKUSB + the UMS/gadget framework
# (the mass-storage function, already defined in rv1106_common.h).
CONFIG_CMD_ROCKUSB=y
# The display stack + this USB gadget push uboot.itb past the old 256K limit
# (287K). scripts/fit-core.sh uses SPL_FIT_IMAGE_KB as BOTH the pack ceiling
# and how many KB SPL reads for the FIT. Raise it to 512 to match the A/B
# layout's 512K `uboot` partition (docs/decisions/0003-partition-layout.md).
# This is an SPL/idblock change (self-recovering to MaskRom if wrong), taken in
# the same MaskRom re-provision as the repartition.
CONFIG_SPL_FIT_IMAGE_KB=512
@@ -0,0 +1,12 @@
# flare-edge: boot instrumentation.
#
# Prefixes EVERY U-Boot console line with [ssss.uuuuuu] microseconds since
# power-on, using the timestamping puts() that already exists in this Rockchip
# fork (common/console.c, guarded by this symbol). Same time base as the
# FLARE_TRACE macro and as Rockchip's own "Total: x/y ms" line, so U-Boot,
# SPL and the kernel can all be put on one axis.
#
# Cost is ~15 characters per line. At 115200 baud that is ~1.3 ms per line, so
# a verbose boot IS measurably slower than a production one -- read timings
# from an instrumented boot as an upper bound, not as production numbers.
CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y
+49
View File
@@ -0,0 +1,49 @@
# rv1106-warden-kernel.dtb -- provenance and regeneration
This binary is U-Boot's embedded control DTB (`CONFIG_EMBED_KERNEL_DTB_PATH`,
set in `../configs/flare-display.config`). With `CONFIG_EMBED_KERNEL_DTB_ALWAYS`
U-Boot adopts it in `board_init()` instead of reading the booted slot's DTB out
of `resource`, so the display bring-up (boot logo included) is identical on
every slot regardless of the slot kernel's own device tree.
## Where this exact blob came from
Extracted 2026-09-01 from the vendor-built 5.10 firmware image
`sdk/output/image/boot.img` (build of 2026-08-24, WardenOS 0.3.x line): the
`rk-kernel.dtb` entry of its `resource` sub-image, 73379 bytes, dtb magic
`d00dfeed`. That is byte-for-byte the DTB U-Boot's display stack was proven
against when it adopted the slot DTB directly.
## Regenerating after a kernel DTS change
Run this from a `blueflare/flare-edge` worktree with this SDK checked out at
`vendor/warden-sdk` (the normal layout). The 5.10 board DTS is the source of
truth (`sdk/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts`
plus its ipc dtsi, where `sdk/` is flare-edge's own vendor-SDK checkout, not
this repo). After any display-relevant change there, rebuild the firmware
once and re-extract:
```python
import struct, subprocess, re
fit = open('sdk/output/image/boot.img','rb').read()
open('/tmp/fitmeta.dtb','wb').write(fit[:4096])
def fdtget(node, prop):
r = subprocess.run(['fdtget','-ti','/tmp/fitmeta.dtb',node,prop],
capture_output=True, text=True)
return int(r.stdout.split()[0])
pos, size = fdtget('/images/resource','data-position'), fdtget('/images/resource','data-size')
res = fit[pos:pos+size]
for m in re.finditer(b'ENTR', res):
e = res[m.start():m.start()+272]
name = e[4:260].split(b'\0')[0].decode()
blk_off, sz = struct.unpack('<II', e[260:268])
if name == 'rk-kernel.dtb':
open('vendor/warden-sdk/luckfox-sdk-patches/uboot/dts/rv1106-warden-kernel.dtb','wb').write(
res[blk_off*512: blk_off*512+sz])
```
Then rebuild U-Boot and confirm the boot log prints
`DTB: dts/rv1106-warden-kernel.dtb`. A stale blob here silently diverges from
the kernel-side display timings; this file must be regenerated in the same
change that edits them. flare-edge's `tools/build-firmware.sh` hard-fails if
the file is missing while `EMBED_KERNEL_DTB_ALWAYS` is configured.
@@ -0,0 +1,68 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* flare-edge: bootloader-side touch probe for the verbose-boot choice.
* See arch/arm/mach-rockchip/flare_touch.c for why the decision is made here
* rather than in userspace, and why it costs no boot time.
*/
#ifndef __FLARE_TOUCH_H
#define __FLARE_TOUCH_H
/**
* struct flare_touch_state - what the controller said, for the boot report
*
* @addr: I2C address that answered, or 0 if the controller was never
* reached
* @status: raw value of the coordinate/status register, sampled at the
* read this struct reports (i.e. after the splash appeared)
* @arm_status: raw value of the same register, sampled by flare_touch_arm()
* before it cleared any power-on report -- lets the two reads be
* told apart, one from before the splash and one from after
* @armed: whether flare_touch_arm() ran and reached the controller
* before this read, so @arm_status can be trusted
* @id: product id string the controller reports ("911" on this
* panel), NUL-terminated, empty if it could not be read
*
* A panel in the field has no serial console, so every one of these ends up on
* the kernel command line. "No touchscreen", "touchscreen present but silent"
* and "not touched" are three different faults that look identical without it.
*/
struct flare_touch_state {
int addr;
unsigned char status;
unsigned char arm_status;
bool armed;
char id[8];
};
/**
* flare_touch_arm() - discard whatever the controller is holding right now
*
* Call once, early, as soon as the splash is up. The GT911 publishes a report
* when it powers up, so on a COLD boot there is already one waiting before
* anybody has touched anything -- and a later read cannot tell that apart from
* a tap that has since been released, because both read as "ready, zero
* fingers". Clearing here makes the later read mean something precise: a
* report that arrived AFTER the splash appeared.
*
* Costs one I2C transaction and no delay. Safe if the controller is absent.
*/
void flare_touch_arm(void);
/**
* flare_touch_tapped() - is a touch report waiting?
*
* ONE I2C read, no polling and no delay. The controller latches a report and
* holds it until the host acknowledges it, so a single late read catches a
* touch that happened any time earlier in the boot. Watching for a window
* would add that window to every boot, touched or not, which is not a price
* worth paying for a diagnostic escape hatch.
*
* Safe on a board with no reachable controller: reports "not touched" rather
* than failing, so no boot path depends on the hardware answering.
*
* @st: filled in with what was observed; may be NULL
* @return 1 if a touch was waiting, 0 otherwise
*/
int flare_touch_tapped(struct flare_touch_state *st);
#endif /* __FLARE_TOUCH_H */
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* flare-edge boot instrumentation.
*
* Emits "FLARE-T <microseconds-since-power-on> <label>" on the console at
* interesting points in the boot, so tools/boot-trace.py can build a single
* timeline spanning BootROM -> SPL -> U-Boot -> kernel -> userspace.
*
* The time expression is deliberately the same one Rockchip's own
* "Total: x/y ms" line uses (arch/arm/lib/bootm.c, common/spl/spl.c): the
* secure timer is started in TPL/SPL and free-runs from power-on, so
* get_ticks() is ticks-since-power-on and COUNTER_FREQUENCY is 24 MHz.
* That makes these values directly comparable to that existing line, and
* immune to UART transmit latency (unlike host-side timestamps, which lag
* by ~5 ms per line at 115200 and much more when the port is flooded).
*
* Cost is a handful of printf calls. Note the uboot partition has only
* ~12.8 KB spare (see wiki 30-uboot.md), so do not add these liberally.
*/
#ifndef _FLARE_TRACE_H_
#define _FLARE_TRACE_H_
#define FLARE_USEC() \
((ulong)(get_ticks() / (COUNTER_FREQUENCY / 1000000)))
#define FLARE_TRACE(label) \
printf("FLARE-T %lu %s\n", \
FLARE_USEC(), label)
#endif /* _FLARE_TRACE_H_ */
@@ -0,0 +1,647 @@
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
index 8821862db..ab2c45239 100644
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
@@ -12,7 +12,34 @@
chosen {
stdout-path = &uart2;
- u-boot,spl-boot-order = &sdmmc, &spi_nor, &spi_nand, &emmc;
+ /*
+ * flare-edge: eMMC first -- it is the only boot medium fitted.
+ *
+ * Stock order was <&sdmmc, &spi_nor, &spi_nand, &emmc>, i.e. the
+ * one device that actually works came last. MEASURED cost of
+ * walking the three dead entries first, from the timestamped SPL
+ * log: ~212 ms resolving spi_nand (it fails with "unknown raw ID
+ * 0 0 0" from drivers/mtd/nand/spi/core.c) plus ~57 ms probing
+ * sdmmc twice ("Card did not respond to voltage select",
+ * mmc_init: -95). That is ~270 ms of a ~450 ms SPL, spent on
+ * hardware this board does not have: sdmmc is wired to the
+ * AIC8800 WiFi as SDIO (non-removable, supports-sdio), there is
+ * no SD slot, and nothing is fitted on the SFC.
+ *
+ * Recovery is unaffected. VERIFIED on hardware: BOOT-key recovery
+ * runs in U-Boot proper via SARADC at ~1.18 s ("download key
+ * pressed... entering download mode"), so it only needs SPL to
+ * reach U-Boot -- which is exactly what booting eMMC first does,
+ * sooner. If eMMC itself fails, board_boot_order() still appends
+ * BOOT_DEVICE_BOOTROM, and a corrupt idblock drops to MaskRom via
+ * the BootROM regardless. See 80-open-questions.md §8.
+ *
+ * NOTE: this dtsi is shared by every rv1106 U-Boot build in this
+ * tree. Only the eMMC 86Panel is built here; if an SD- or
+ * SPI-NAND-booting variant is ever built, restore the stock order
+ * from rv1106-u-boot.dtsi.flare-orig.
+ */
+ u-boot,spl-boot-order = &emmc;
};
secure-otp@ff3fd8000 {
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
index 067176a9b..25972c645 100644
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
@@ -16,6 +16,7 @@
#include <cli.h>
#include <clk.h>
#include <console.h>
+#include <flare_trace.h>
#include <debug_uart.h>
#include <dm.h>
#include <dvfs.h>
@@ -461,10 +462,67 @@ static void scan_run_cmd(void)
}
}
+/*
+ * flare-edge: the VOP frame/underrun watcher lived here and has been removed.
+ *
+ * It enabled the VOP's own interrupt sources and polled them, which is the only
+ * way to learn what the display hardware is actually doing rather than when our
+ * code ran. Its verdict, MEASURED on hardware: 150 frames in 3.08 s (48.7 Hz,
+ * exactly the designed rate) with ZERO bus_error, ZERO win1_empty and ZERO
+ * post_buf_empty. So the SoC emits a perfect, never-starved raster from ~0.9 s,
+ * and the ~3 s before the panel shows a stable image is the glass failing to
+ * lock onto a signal that is already valid -- not anything on our side.
+ *
+ * It cost exactly its own duration (3 s) in added boot time, because U-Boot is
+ * single-threaded and the counters have to be polled. Removed now that it has
+ * answered the question.
+ *
+ * To bring it back, the expensive part is the register map, so it is recorded
+ * here. VOP base 0xff990000: INTR_EN 0x34, INTR_CLEAR 0x38, INTR_STATUS 0x3c,
+ * all write-masked (value in the low half word, write-enable mask in the high).
+ * Bit order is rk3366-lite (= rv1106), and array index IS the hardware bit, per
+ * rk3366_vop_lit_intrs[] in the kernel's rockchip_vop_reg.c:
+ * bit0 FS (frame start) bit5 BUS_ERROR
+ * bit7 WIN1_EMPTY bit11 POST_BUF_EMPTY
+ * Poll INTR_STATUS & 0xffff, count set bits, write them back to INTR_CLEAR.
+ * See 80-open-questions.md 1f.
+ */
+
int board_late_init(void)
{
+ FLARE_TRACE("board_late_init entry");
#ifdef CONFIG_LUCKFOX_EXECUTE_CMD
luckfox_execute_cmd();
+ FLARE_TRACE("panel MCU reset released (gpio set 1 1)");
+#endif
+ /*
+ * flare-edge: sample the BOOT key BEFORE the display work.
+ *
+ * setup_download_mode() is this board's primary recovery path -- it is
+ * how a held BOOT key reaches run_command("download") -> rbrom ->
+ * MaskRom (VERIFIED on hardware, 80-open-questions.md 8). It is a cheap
+ * SARADC read when the key is not pressed.
+ *
+ * An earlier revision of this reorder put rockchip_show_logo() first and
+ * left this call after it, which pushed the key sample from ~1.18 s to
+ * ~1.5 s -- and when a 3 s diagnostic briefly sat between them, out past
+ * 4 s. A recovery mechanism that silently requires an 8 second hold is a
+ * trap, so the safety check goes first and the logo follows it. The logo
+ * still runs well before ethaddr/serialno/scan_run_cmd, which is what
+ * the reorder was for.
+ */
+ setup_download_mode();
+
+ /* Logo as early as possible, but never ahead of the recovery path. */
+#ifdef CONFIG_DRM_ROCKCHIP
+ if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) {
+ FLARE_TRACE("rockchip_show_logo start");
+ rockchip_show_logo();
+ FLARE_TRACE("rockchip_show_logo done");
+ }
+#endif
+#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
+ rockchip_eink_show_uboot_logo();
#endif
#ifdef CONFIG_ROCKCHIP_SET_ETHADDR
rockchip_set_ethaddr();
@@ -472,7 +530,6 @@ int board_late_init(void)
#ifdef CONFIG_ROCKCHIP_SET_SN
rockchip_set_serialno();
#endif
- setup_download_mode();
scan_run_cmd();
#ifdef CONFIG_ROCKCHIP_USB_BOOT
boot_from_udisk();
@@ -485,13 +542,6 @@ int board_late_init(void)
rk_minidump_init();
#endif
-#ifdef CONFIG_DRM_ROCKCHIP
- if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT)
- rockchip_show_logo();
-#endif
-#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
- rockchip_eink_show_uboot_logo();
-#endif
#if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
setup_boot_mode();
#endif
@@ -539,9 +589,52 @@ static void board_debug_init(void)
printf("Cmd interface: disabled\n");
}
+/*
+ * flare-edge: set once we have released the panel reset ourselves, read by
+ * drivers/video/drm/rockchip_panel.c so it does not reset the panel a second
+ * time and restart its initialisation.
+ */
+int flare_panel_reset_early;
+
+/*
+ * flare-edge: release GPIO0_A1 (net RGB_RES) as early as possible.
+ *
+ * This is NOT simply "the panel reset". Per the 86Panel schematic, RGB_RES
+ * ties three things together: SoC GPIO0_A1, the panel's RESET pin (FPC 6),
+ * and the NRST of a WCH CH32V003 MCU (U6) whose only wired pins are SPI
+ * (CS/SCK/SDI) to that same FPC. That MCU exists to clock the panel's
+ * initialisation sequence in; Luckfox's own comment calls it the "RGB MCU".
+ *
+ * So holding this line low holds the *initialiser* in reset, and the panel
+ * cannot come up until it is released and the MCU has run. At power-on the
+ * pin is input-with-pulldown, i.e. asserted, so the sooner we drive it high
+ * the sooner the panel becomes usable. MEASURED: the glass takes ~2-3 s from
+ * release before it displays a stable image, so this is the long pole in the
+ * whole boot -- every millisecond of head start counts.
+ *
+ * A previous revision of this function ASSERTED the line here and held it
+ * ~540 ms across init_kernel_dtb(), on the theory that the panel needed a
+ * longer reset pulse. That was backwards: it delayed the initialiser by half
+ * a second. Do not reintroduce it.
+ *
+ * Register-level rather than DM/pinctrl because this runs before the kernel
+ * DTB is adopted and before most of the driver model exists. RV1106 GPIO v2
+ * at 0xff380000: swport_dr_l 0x00, swport_ddr_l 0x08, both write-masked with
+ * the enable bits in the upper half word, so only bit 1 is touched.
+ */
+static void flare_release_panel_reset(void)
+{
+ writel(0x00020002, (void *)0xff380008); /* bit 1 -> output */
+ writel(0x00020002, (void *)0xff380000); /* bit 1 -> high: MCU + panel
+ * out of reset */
+ flare_panel_reset_early = 1;
+}
+
+
int board_init(void)
{
board_debug_init();
+ flare_release_panel_reset();
#ifdef DEBUG
soc_clk_dump();
#endif
diff --git a/sysdrv/source/uboot/u-boot/common/console.c b/sysdrv/source/uboot/u-boot/common/console.c
index 629c2a645..bce3e51b6 100644
--- a/sysdrv/source/uboot/u-boot/common/console.c
+++ b/sysdrv/source/uboot/u-boot/common/console.c
@@ -515,11 +515,72 @@ static inline void pre_console_putc(const char c) {}
static inline void print_pre_console_buffer(int flushpoint) {}
#endif
+#ifdef CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP
+/*
+ * flare-edge: prefix every console line with "[ s.uuuuuu] ", microseconds
+ * since power-on.
+ *
+ * Hooked into putc() rather than puts() on purpose. With
+ * CONFIG_USE_TINY_PRINTF (required for SPL size) printf() emits one character
+ * at a time through putc_normal() -> putc() and never calls puts(), so a
+ * puts()-level hook is invisible to SPL -- which is precisely the ~0.42 s of
+ * boot we most wanted to see. putc() catches both paths.
+ *
+ * Formatted by hand because tiny printf supports only %c %s %u %d %x: no
+ * field width, no zero padding, so "%5lu.%06lu" would not render. get_ticks()
+ * is the free-running secure timer started in TPL at 24 MHz, so this shares a
+ * clock with Rockchip's own "Total: x/y ms" lines and with FLARE_TRACE.
+ */
+static int flare_in_ts;
+
+static void flare_putc_ts(void)
+{
+ unsigned long ticks = (unsigned long)(get_ticks() / 24ULL);
+ unsigned long sec = ticks / 1000000UL;
+ unsigned long us = ticks % 1000000UL;
+ unsigned long div;
+ char d[12];
+ int n = 0;
+
+ putc('[');
+ if (!sec) {
+ d[n++] = '0';
+ } else {
+ while (sec) {
+ d[n++] = '0' + (char)(sec % 10);
+ sec /= 10;
+ }
+ }
+ for (div = n; div < 5; div++)
+ putc(' ');
+ while (n--)
+ putc(d[n]);
+ putc('.');
+ for (div = 100000UL; div; div /= 10)
+ putc('0' + (char)((us / div) % 10));
+ putc(']');
+ putc(' ');
+}
+#endif
+
void putc(const char c)
{
if (!gd || gd->flags & GD_FLG_DISABLE_CONSOLE)
return;
+#ifdef CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP
+ if (!flare_in_ts) {
+ if (c == '\n') {
+ gd->new_line = 1;
+ } else if (gd->new_line) {
+ gd->new_line = 0;
+ flare_in_ts = 1;
+ flare_putc_ts();
+ flare_in_ts = 0;
+ }
+ }
+#endif
+
#ifdef CONFIG_PSTORE
putc_to_ram(c);
#endif
@@ -553,51 +614,11 @@ void putc(const char c)
}
}
-#if ((!defined(CONFIG_SPL_BUILD) || !defined(CONFIG_USE_TINY_PRINTF)) && \
- defined(CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP))
-static void vspfunc(char *buf, size_t size, char *format, ...)
-{
- va_list ap;
-
- va_start(ap, format);
- vsnprintf(buf, size, format, ap);
- va_end(ap);
-}
-
-void puts(const char *s)
-{
- unsigned long ts_sec, ts_msec, ticks;
- char pr_timestamp[32], *p;
-
- while (*s) {
- if (*s == '\n') {
- gd->new_line = 1;
- putc(*s++);
- continue;
- }
-
- if (gd->new_line) {
- gd->new_line = 0;
- ticks = (get_ticks() / 24ULL);
- ts_sec = ticks / 1000000;
- ts_msec = ticks % 1000000;
- vspfunc(pr_timestamp, sizeof(pr_timestamp),
- "[%5lu.%06lu] ", ts_sec, ts_msec);
- p = pr_timestamp;
- while (*p)
- putc(*p++);
- }
-
- putc(*s++);
- }
-}
-#else
void puts(const char *s)
{
while (*s)
putc(*s++);
}
-#endif
#ifdef CONFIG_CONSOLE_RECORD
diff --git a/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c b/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
index a99846f4e..4fc64f33d 100644
--- a/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
+++ b/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
@@ -976,20 +976,93 @@ static ulong rv1106_vop_set_clk(struct rv1106_clk_priv *priv,
sel << ACLK_VOP_SEL_SHIFT);
break;
case DCLK_VOP_SRC:
- case DCLK_VOP:
- if ((priv->cpll_hz % rate) == 0) {
+ case DCLK_VOP: {
+ /*
+ * flare-edge: the divider field is 5 bits (DCLK_VOP_DIV_MASK
+ * = 0x1f << 3), so the largest divisor the hardware can encode
+ * is 32. The original code took DIV_ROUND_UP() of the parent
+ * rate and wrote (div - 1) straight into that field with no
+ * range check. For this panel -- 30 MHz pixel clock from a
+ * 1188 MHz GPLL -- that is a divisor of 40, i.e. 39 = 0b100111
+ * written into 5 bits, which truncates to 7. MEASURED result:
+ * the VOP ran at 125 MHz instead of 30 MHz, so the panel was
+ * fed a signal it cannot lock to and showed coloured vertical
+ * lines / black while U-Boot happily turned the backlight on.
+ *
+ * Neither PLL can actually reach 30 MHz through a /32 divider
+ * (1188/32 = 37.125, 1000/32 = 31.25), so clamp to the field
+ * maximum and choose whichever parent lands closest to the
+ * request rather than silently corrupting the register.
+ */
+ ulong c_div, g_div, c_rate, g_rate, c_err, g_err;
+
+ /*
+ * flare-edge: if neither PLL can divide down to the requested
+ * pixel clock exactly, retune CPLL so that it can.
+ *
+ * Stock rates give 1188/32 = 37.125 MHz and 1000/32 = 31.25 MHz
+ * against the 30 MHz this panel wants, so the best achievable
+ * was 4.2% fast. An already-locked panel copes with that --
+ * Linux never notices, because it inherits a display U-Boot has
+ * already started -- but U-Boot is the ONLY stage that locks the
+ * panel from cold, and at 31.25 MHz that took 1-2 seconds of
+ * visible coloured banding before the image settled.
+ *
+ * CPLL is safe to move here: within this driver only the VOP and
+ * UART (as a secondary parent) derive from it. The eMMC, peri and
+ * bus roots do not, and the debug UART runs from the 24 MHz
+ * oscillator, so neither the boot media nor the console is
+ * affected. rkclk_init() pins CPLL to CPLL_HZ and has already run
+ * by this point, so nothing puts it back underneath us.
+ */
+ if ((priv->cpll_hz % rate) && (priv->gpll_hz % rate)) {
+ ulong want = rate * 32;
+
+ if (want >= 300 * MHz && want <= 1200 * MHz &&
+ !rockchip_pll_set_rate(&rv1106_pll_clks[CPLL],
+ priv->cru, CPLL, want)) {
+ printf("dclk_vop: cpll %luHz -> %luHz for an exact /32\n",
+ priv->cpll_hz, want);
+ priv->cpll_hz = want;
+ }
+ }
+
+ c_div = DIV_ROUND_UP(priv->cpll_hz, rate);
+ g_div = DIV_ROUND_UP(priv->gpll_hz, rate);
+ if (c_div > 32)
+ c_div = 32;
+ if (g_div > 32)
+ g_div = 32;
+ if (c_div < 1)
+ c_div = 1;
+ if (g_div < 1)
+ g_div = 1;
+
+ c_rate = priv->cpll_hz / c_div;
+ g_rate = priv->gpll_hz / g_div;
+ c_err = (c_rate > rate) ? (c_rate - rate) : (rate - c_rate);
+ g_err = (g_rate > rate) ? (g_rate - rate) : (rate - g_rate);
+
+ if (c_err <= g_err) {
sel = DCLK_VOP_SEL_CPLL;
- div = DIV_ROUND_UP(priv->cpll_hz, rate);
+ div = c_div;
} else {
sel = DCLK_VOP_SEL_GPLL;
- div = DIV_ROUND_UP(priv->gpll_hz, rate);
+ div = g_div;
}
+
+ printf("dclk_vop: want %luHz, cpll=%luHz/%lu=%luHz gpll=%luHz/%lu=%luHz -> %s/%d\n",
+ rate, priv->cpll_hz, c_div, c_rate,
+ priv->gpll_hz, g_div, g_rate,
+ sel == DCLK_VOP_SEL_CPLL ? "cpll" : "gpll", div);
+
rk_clrsetreg(&cru->clksel_con[23],
DCLK_VOP_SEL_MASK |
DCLK_VOP_DIV_MASK,
sel << DCLK_VOP_SEL_SHIFT |
(div - 1) << DCLK_VOP_DIV_SHIFT);
break;
+ }
default:
return -ENOENT;
}
@@ -1226,10 +1299,17 @@ static ulong rv1106_clk_set_rate(struct clk *clk, ulong rate)
case DCLK_VOP:
case ACLK_VOP_ROOT:
case ACLK_VOP:
- rate = rv1106_vop_set_clk(priv, clk->id, rate);
+ /* flare-edge: was "rate = ...", but this function returns `ret`,
+ * so the actual rate was discarded and clk_set_rate() always
+ * reported 0. The hardware was still programmed, which is why
+ * this stayed hidden -- but it made the VOP's own
+ * "set crtc_clock to 30000KHz, get 0Hz" line useless as a
+ * diagnostic, and 0 is indistinguishable from a dead clock when
+ * you are trying to work out why a panel shows nothing. */
+ ret = rv1106_vop_set_clk(priv, clk->id, rate);
break;
case DCLK_DECOM:
- rate = rv1106_decom_set_clk(priv, rate);
+ ret = rv1106_decom_set_clk(priv, rate);
break;
#endif
default:
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
index 69e9a1dfa..fe09efe09 100644
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
@@ -2106,7 +2106,12 @@ static int rockchip_display_probe(struct udevice *dev)
}
split_conn = rockchip_get_split_connector(conn);
- s = malloc(sizeof(*s));
+ /* flare-edge: calloc, not malloc -- enabled_at_spl and other fields
+ * are only explicitly initialised under CONFIG_SPL_BUILD, which does
+ * not apply here (this file runs in U-Boot proper). Uninitialised
+ * heap garbage in enabled_at_spl silently skips panel prepare/enable
+ * (and therefore backlight_enable) in display_enable() below. */
+ s = calloc(1, sizeof(*s));
if (!s)
continue;
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
index 9ddb4d819..44c31945c 100644
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
@@ -12,6 +12,31 @@
#include <malloc.h>
#include <video.h>
#include <backlight.h>
+
+/*
+ * Milliseconds to wait after the CRTC starts scanning out, before switching
+ * the backlight on, when the devicetree gives no enable-delay-ms.
+ *
+ * This hides the panel's own wake, which is driven by the CH32V003 (U6)
+ * clocking the init sequence in over SPI once RGB_RES is released at the top
+ * of board_init(). Two artefacts have been seen here with DIFFERENT causes --
+ * do not conflate them:
+ *
+ * coloured vertical banding -- NOT a settle problem. That was Linux
+ * rebooting the CH32V003 mid-scanout via reset-gpios on &panel; fixed in
+ * the kernel DTS. Raising this constant only ever masked it.
+ * inverted image that fades to correct -- the driver IC is still coming up
+ * when the backlight lands, so we see the tail of its internal rail ramp.
+ * This constant is the right tool for that one.
+ *
+ * Trade-off is explicit: first light moves later, but what you see first is
+ * the logo rather than garbage. The better fix is to release RGB_RES earlier
+ * (SPL/TPL) so the initialiser is done before we get here -- same margin,
+ * without delaying the logo. That needs an idblock flash, hence not done yet.
+ */
+#define FLARE_PANEL_SETTLE_MS 250
+
+extern int flare_panel_reset_early;
#include <spi.h>
#include <asm/gpio.h>
#include <dm/device.h>
@@ -302,6 +327,24 @@ static void panel_simple_prepare(struct rockchip_panel *panel)
if (priv->prepared)
return;
+ /*
+ * flare-edge: force the backlight OFF before touching the panel.
+ *
+ * The PWM block is not reset by a warm reboot, so after `reboot` from
+ * Linux the backlight is still lit from the previous session for the
+ * whole of U-Boot. Delaying our own backlight_enable() therefore did
+ * nothing -- the lamp was already on, and the panel's 1-2 s cold-lock
+ * banding was plainly visible through it. Only a cold power-cycle hid
+ * the problem, which is exactly why it looked inconsistent.
+ *
+ * Explicitly blanking here means the settle happens in the dark on
+ * both warm and cold boots, and the first thing the user sees is the
+ * finished logo. panel_simple_enable() switches it back on once the
+ * panel has locked.
+ */
+ if (priv->backlight)
+ backlight_disable(priv->backlight);
+
if (priv->power_supply)
regulator_set_enable(priv->power_supply, !plat->power_invert);
@@ -311,6 +354,15 @@ static void panel_simple_prepare(struct rockchip_panel *panel)
if (plat->delay.prepare)
mdelay(plat->delay.prepare);
+ /*
+ * flare-edge: board_init() asserted this reset back at ~0.47 s and has
+ * been holding it ever since, so by the time we get here the panel has
+ * already had a ~540 ms low pulse -- far longer than the 200 ms
+ * reset-delay-ms below, and the closest we can get to the full
+ * power-down that this panel demonstrably needs. Run the normal cycle
+ * anyway: it is harmless (the line is already low) and it is what
+ * actually releases the reset.
+ */
if (dm_gpio_is_valid(&priv->reset_gpio))
dm_gpio_set_value(&priv->reset_gpio, 1);
@@ -388,6 +440,26 @@ static void panel_simple_enable(struct rockchip_panel *panel)
if (plat->delay.enable)
mdelay(plat->delay.enable);
+ /*
+ * flare-edge: this panel needs 1-2 s to lock onto the RGB signal from
+ * cold, and until it does it shows faint coloured vertical banding.
+ * U-Boot is the only stage that ever starts it from cold -- Linux
+ * inherits an already-running display -- so this is the only place the
+ * problem appears. Lighting the backlight before the panel has locked
+ * just makes the garbage visible.
+ *
+ * Ruled out as causes, each MEASURED rather than assumed: memory
+ * bandwidth contention (the image is rock steady through sustained
+ * 8 MB eMMC reads at the U-Boot prompt), and pixel-clock accuracy
+ * (retuning CPLL to 960 MHz for an exact 30.000 MHz changed nothing).
+ * It is simply the panel's own lock time.
+ *
+ * Prefer the devicetree's enable-delay-ms above if a value is set;
+ * this is the fallback for a DT that specifies none.
+ */
+ if (!plat->delay.enable)
+ mdelay(FLARE_PANEL_SETTLE_MS);
+
if (priv->backlight)
backlight_enable(priv->backlight);
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
index 240910395..675ac1580 100755
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
@@ -4,6 +4,20 @@
* Author: Zhang yubing <yubing.zhang@rock-chips.com>
*/
+/*
+ * flare-edge: <common.h> must come first.
+ *
+ * rockchip_post_csc.h pulls in <edid.h>, which includes <i2c.h>
+ * unconditionally (edid.h:20). With CONFIG_DM_I2C unset -- which is the case
+ * in rv1106_defconfig and ours -- i2c.h takes its legacy branch (i2c.h:554),
+ * and those prototypes use `uchar`. That typedef lives in <common.h>, which
+ * this file never included, so the prototypes failed to parse and the later
+ * inline users of i2c_read()/i2c_write() then became implicit-declaration
+ * errors. Including common.h first resolves the whole cascade, and is far
+ * cheaper than enabling the DM I2C stack purely to dodge a header ordering
+ * bug (the uboot partition is 256K with ~64K spare).
+ */
+#include <common.h>
#include <stdio.h>
#include <linux/errno.h>
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c b/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
index 718b2fd04..83dbd7e56 100644
--- a/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
+++ b/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
@@ -11,6 +11,7 @@
#include <pwm.h>
#include <asm/gpio.h>
#include <power/regulator.h>
+#include <flare_trace.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -66,6 +67,19 @@ static int pwm_backlight_enable(struct udevice *dev)
if (dm_gpio_is_valid(&priv->enable))
dm_gpio_set_value(&priv->enable, 1);
+ /*
+ * Report the values that actually determine whether the panel lights
+ * up, not just "we got here". The previous message claimed "panel now
+ * visible", which was untrue for a long time: the PWM was enabled at
+ * 99.6%% duty but INVERTED, so the real brightness was ~0.4%% and the
+ * screen looked dead. A trace marker that asserts an outcome it cannot
+ * observe is worse than no marker at all.
+ */
+ printf("FLARE-T %lu backlight pwm enabled: duty=%u/%u ns (%lu%%), polarity=%s\n",
+ (ulong)(get_ticks() / (COUNTER_FREQUENCY / 1000000)),
+ duty_cycle, priv->period_ns,
+ priv->period_ns ? (ulong)duty_cycle * 100 / priv->period_ns : 0,
+ priv->polarity ? "inverted" : "normal");
return 0;
}
@@ -143,7 +157,20 @@ static int pwm_backlight_ofdata_to_platdata(struct udevice *dev)
}
priv->channel = args.args[0];
priv->period_ns = args.args[1];
- priv->polarity = args.args[2];
+ /*
+ * flare-edge: the third pwm cell is a FLAGS word, not a boolean.
+ * Only bit 0 (PWM_POLARITY_INVERTED) selects polarity; the kernel
+ * masks it and ignores everything else.
+ *
+ * This board's DTS carries pwms = <&pwm1 0 100000 50000>. Assigning
+ * 50000 straight into a bool made U-Boot invert the PWM while Linux
+ * did not, so a 99.6% duty cycle (PERIOD=10000, DUTY=9960) came out
+ * as ~0.4% on. MEASURED: PWM_CTRL read back 0x13, i.e. DUTY_NEGATIVE
+ * + INACTIVE_POSITIVE. The backlight reported itself enabled and was
+ * to the eye completely dark -- while the logo was rendering into the
+ * framebuffer perfectly the whole time.
+ */
+ priv->polarity = args.args[2] & 1;
index = dev_read_u32_default(dev, "default-brightness-level", 255);
cell = dev_read_prop(dev, "brightness-levels", &len);
@@ -0,0 +1,108 @@
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
index 3b943079d..bdc6876e0 100644
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
@@ -197,7 +197,28 @@ void board_boot_order(u32 *spl_boot_list)
/* If we had no matches, fall back to spl_boot_device */
if (idx == 0)
- spl_boot_list[0] = spl_boot_device();
+ spl_boot_list[idx++] = spl_boot_device();
+
+#ifdef CONFIG_SPL_BOOTROM_SUPPORT
+ /*
+ * flare-edge: last-resort recovery entry.
+ *
+ * boot_from_devices() walks this list in order and, if every entry
+ * fails, common/spl/spl.c does puts("SPL: failed to boot from all
+ * boot devices") followed by hang(). A hung SPL presents nothing on
+ * USB, and the BOOT key is sampled by U-Boot proper (SARADC, in
+ * board_late_init) -- so it cannot rescue a failure that happens
+ * before U-Boot runs. The board would then need hardware recovery.
+ *
+ * Appending the BROM here costs nothing on a healthy boot (MMC is
+ * tried first and succeeds), but turns "unbootable uboot.img" from a
+ * hang into an automatic drop to MaskRom, which upgrade_tool can talk
+ * to. See board_return_to_bootrom() in mach-rockchip/spl.c: with
+ * SPL_ROCKCHIP_BACK_TO_BROM off this issues BROM_BOOT_ENTER_DNL.
+ */
+ if (idx < 5)
+ spl_boot_list[idx++] = BOOT_DEVICE_BOOTROM;
+#endif
}
#endif
#endif
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
index 9f882ca14..430302c38 100644
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
@@ -31,7 +31,23 @@ DECLARE_GLOBAL_DATA_PTR;
void board_return_to_bootrom(void)
{
+#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
+ /* Normal flow: the BROM is expected to load the next stage for us. */
back_to_bootrom(BROM_BOOT_NEXTSTAGE);
+#else
+ /*
+ * flare-edge: SPL loads U-Boot from MMC itself, so this is only
+ * reached as the final entry of board_boot_order() -- i.e. every real
+ * boot device already failed. Asking the BROM to continue the boot
+ * sequence would just fail again, so request download mode instead
+ * and let MaskRom recovery take over.
+ *
+ * This file is obj-spl-y only (TPL uses tpl.o), so TPL's own
+ * back-to-BROM path, which must stay BROM_BOOT_NEXTSTAGE, is
+ * unaffected.
+ */
+ back_to_bootrom(BROM_BOOT_ENTER_DNL);
+#endif
}
__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
diff --git a/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig b/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
index 0fe5c20b3..ac74ec7f1 100644
--- a/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
+++ b/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
@@ -78,7 +78,7 @@ CONFIG_OF_LIVE=y
CONFIG_OF_SPL_REMOVE_PROPS="interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
CONFIG_OF_U_BOOT_REMOVE_PROPS="interrupt-parent"
CONFIG_ENVF=y
-CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr"
+CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr bootcmd bootdelay preboot altbootcmd bootlimit bootcount"
CONFIG_REGMAP=y
CONFIG_SPL_REGMAP=y
CONFIG_SYSCON=y
diff --git a/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig b/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
index c9d627cce..a71a7e421 100644
--- a/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
+++ b/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
@@ -13,6 +13,28 @@ config BOOTCOUNT
if BOOTCOUNT
+config BOOTCOUNT_LIMIT
+ bool "Enable boot count limit (altbootcmd fallback)"
+ help
+ Used by common/autoboot.c: each boot increments the counter and, once
+ it exceeds ${bootlimit}, U-Boot runs ${altbootcmd} instead of
+ ${bootcmd}. The code has always referenced CONFIG_BOOTCOUNT_LIMIT but
+ this tree never declared it in Kconfig, so it could only be set via a
+ board config header. Declared here so it can come from a defconfig
+ fragment. (flare-edge)
+
+config BOOTCOUNT_ENV
+ bool "Store boot counter in the environment"
+ help
+ Keeps the counter in the environment (drivers/bootcount/bootcount_env.c).
+ Note both load and store are gated on ${upgrade_available}, so the
+ counter only runs during an upgrade window -- which is the behaviour we
+ want: arm it when flashing, clear it once userspace confirms a good
+ boot. Requires an environment backend that implements save(); ENVF does
+ (env/envf.c: .save = env_save_ptr(envf_save)). The Makefile already
+ builds bootcount_env.o for this symbol; only the Kconfig entry was
+ missing. (flare-edge)
+
config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
help
@@ -0,0 +1,953 @@
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
index 7c5681a02..b8787dda1 100644
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
@@ -10,6 +10,9 @@
#include <sysmem.h>
#include <asm/arch/fit.h>
#include <asm/arch/resource_img.h>
+#ifdef CONFIG_FLARE_AB
+#include <flare_ab.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -145,10 +148,28 @@ static void *fit_get_blob(struct blk_desc *dev_desc,
char *part_name = PART_BOOT;
void *fit, *fdt;
int blk_num;
+ __maybe_unused int recovery = 0;
#ifndef CONFIG_ANDROID_AB
- if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY)
+ if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY) {
+ part_name = PART_RECOVERY;
+ recovery = 1;
+ }
+#endif
+
+#ifdef CONFIG_FLARE_AB
+ /*
+ * BCB-commanded recovery (above) and no-bootable-slot fallback
+ * both boot the shared recovery FIT; either way the A/B layer
+ * must know, so it stops decrementing slot tries and escalates
+ * to MaskRom if the recovery FIT itself will not boot.
+ */
+ if (!recovery && flare_ab_enabled() && !flare_ab_have_bootable()) {
part_name = PART_RECOVERY;
+ recovery = 1;
+ }
+ if (recovery)
+ flare_ab_set_recovery_mode();
#endif
if (part_get_info_by_name(dev_desc, part_name, &part) < 0) {
diff --git a/sysdrv/source/uboot/u-boot/cmd/bootfit.c b/sysdrv/source/uboot/u-boot/cmd/bootfit.c
index 3a8b75bf7..6335cbf39 100644
--- a/sysdrv/source/uboot/u-boot/cmd/bootfit.c
+++ b/sysdrv/source/uboot/u-boot/cmd/bootfit.c
@@ -12,6 +12,9 @@
#include <malloc.h>
#include <sysmem.h>
#include <asm/arch/fit.h>
+#ifdef CONFIG_FLARE_AB
+#include <flare_ab.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -69,6 +72,20 @@ static int do_boot_fit(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
printf("## Booting FIT Image ");
+#ifdef CONFIG_FLARE_AB
+ /*
+ * Count this boot attempt against the selected slot BEFORE trying
+ * to load its FIT (the SPL engine's "decrease before load" rule):
+ * a slot whose FIT is corrupt must still burn tries on every failed
+ * attempt, or the failure path below would reset forever without
+ * ever falling back to the other slot. Writes one sector, and only
+ * while the slot is not yet marked successful; no-op in recovery
+ * fallback mode (the earlier kernel-DTB load already resolved it).
+ */
+ if (argc == 1)
+ flare_ab_boot_attempt();
+#endif
+
if (argc == 1)
fit = do_boot_fit_storage(&size);
else
@@ -120,8 +137,24 @@ static int do_boot_fit(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
goto out;
}
+#ifdef CONFIG_FLARE_AB
+ if (ret && argc == 1)
+ goto out;
+#endif
+
return CMD_RET_SUCCESS;
out:
+#ifdef CONFIG_FLARE_AB
+ /*
+ * A storage boot that reached this point failed to load or boot
+ * the selected slot's FIT. On an A/B layout this resets so the
+ * next boot makes progress (retries burn down, then the other
+ * slot, then recovery, then MaskRom); on a legacy layout it
+ * returns and stock behavior continues.
+ */
+ if (argc == 1)
+ flare_ab_boot_failed();
+#endif
return CMD_RET_FAILURE;
}
diff --git a/sysdrv/source/uboot/u-boot/common/Kconfig b/sysdrv/source/uboot/u-boot/common/Kconfig
index c276f701a..31b5c712d 100644
--- a/sysdrv/source/uboot/u-boot/common/Kconfig
+++ b/sysdrv/source/uboot/u-boot/common/Kconfig
@@ -620,6 +620,21 @@ config ANDROID_AB
allows a bootloader to try a new version of the system but roll back
to previous version if the new one didn't boot all the way.
+config FLARE_AB
+ bool "flare-edge A/B slot boot (lean, misc-based, no libavb)"
+ depends on !ANDROID_AB
+ default n
+ help
+ A/B slot selection for U-Boot proper using the same AOSP
+ AvbABData metadata (single CRC32-protected sector at
+ misc + 2048 bytes) as the vendor SPL A/B engine, without the
+ libavb stack CONFIG_ANDROID_AB pulls in. Slot suffixing hooks
+ part_get_info_by_name(), so boot_a/boot_b (and the early
+ kernel-DTB/resource load) resolve transparently; tries are
+ decremented once per boot attempt only while a slot is not yet
+ marked successful; with no bootable slot the recovery FIT is
+ booted, and failing that the board drops to MaskRom.
+
config ANDROID_WRITE_KEYBOX
bool "Support Write Keybox"
default y
diff --git a/sysdrv/source/uboot/u-boot/common/Makefile b/sysdrv/source/uboot/u-boot/common/Makefile
index 52cd612d1..a81071566 100644
--- a/sysdrv/source/uboot/u-boot/common/Makefile
+++ b/sysdrv/source/uboot/u-boot/common/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SUPPORT_USBPLUG) += usbplug/
obj-y += main.o
obj-y += exports.o
+obj-$(CONFIG_FLARE_AB) += flare_ab.o
obj-$(CONFIG_HASH) += hash.o
obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
obj-$(CONFIG_AUTOBOOT) += autoboot.o
diff --git a/sysdrv/source/uboot/u-boot/common/flare_ab.c b/sysdrv/source/uboot/u-boot/common/flare_ab.c
new file mode 100644
index 000000000..6a5a07e37
--- /dev/null
+++ b/sysdrv/source/uboot/u-boot/common/flare_ab.c
@@ -0,0 +1,642 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * flare-edge A/B slot boot for U-Boot proper.
+ *
+ * Core metadata engine adapted from the vendor's common/spl/spl_ab.c
+ * (Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd) so U-Boot
+ * proper and SPL agree byte-for-byte on the AvbABData struct at
+ * `misc` + AB_METADATA_OFFSET blocks, without pulling in libavb.
+ *
+ * Semantics (AOSP A/B, unchanged from the SPL engine):
+ * - a slot is bootable iff priority>0 && (successful_boot || tries>0)
+ * - selection prefers the higher-priority bootable slot
+ * - one tries_remaining decrement per boot attempt, ONLY while the
+ * slot is not yet successful; metadata is written only if changed,
+ * so a confirmed steady-state device never writes flash at boot
+ * - corrupt metadata self-reinitializes (both slots bootable, A first)
+ * - when no slot is bootable, selection falls back to last_boot and
+ * fit_get_blob() redirects to the recovery FIT instead
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <blk.h>
+#include <boot_rkimg.h>
+#include <command.h>
+#include <malloc.h>
+#include <part.h>
+#include <flare_ab.h>
+#include <android_avb/avb_ab_flow.h>
+
+/*
+ * Per-power-session boot-attempt escalation (warehouse deployment).
+ *
+ * The AvbABData tries above are PERSISTENT (in the misc sector) and exist for
+ * the UPDATE case: a freshly written slot gets a tries budget, and a bad update
+ * burns it down and reverts to the other slot even across power cycles (a bad
+ * image must not come back after a brownout). That is correct for updates and
+ * is left unchanged.
+ *
+ * The STEADY-STATE case (both slots already committed, no update in flight) has
+ * a different requirement: retry the selected slot a couple of times, then the
+ * other slot, then recovery -- and RESET on every power cycle, so a device that
+ * merely lost power mid-boot always comes back up on its selected slot instead
+ * of walking itself into recovery. A persistent counter cannot express "reset
+ * on power cycle"; this needs a store that survives a WARM reset (so in-session
+ * escalation accumulates) but is cleared by a power-on reset.
+ *
+ * Two PMU-domain registers give exactly that, both hardware-validated on a real
+ * 86-panel 2026-09-02:
+ * - CRU glb_rst_st (0xff3b0c04): reads 0 after a power-on reset, nonzero
+ * (bit0 set) after a warm/software reset. It survives the boot chain into
+ * Linux and no vendor code clears it, so U-Boot can read it as the
+ * cold-vs-warm discriminator.
+ * - PMU GRF OS_REG4 (0xff020210): a free scratch register (OS_REG2/3 hold DDR
+ * info, OS_REG8+ are used by the PM code, OS_REG0/1 are boot-mode/chip-ver).
+ * It survives a warm reset (the attempt count accumulates) and, being in the
+ * always-on PMU domain like the boot-mode register, is cleared by a power-on
+ * reset. We additionally gate on glb_rst_st, so a power cycle restarts the
+ * count even if the register somehow retained a value.
+ *
+ * flared clears OS_REG4 once a boot proves healthy (UI live for a sustained
+ * hold) and before any deliberate reboot -- the same discipline the retired env
+ * bootcount used, moved to a register that costs no flash wear and resets for
+ * free on power loss. So only CONSECUTIVE unhealthy boots within one power
+ * session escalate; a healthy boot, or a power cycle, restarts at the selected
+ * slot.
+ */
+#define FLARE_AB_GLB_RST_ST 0xff3b0c04u /* CRU reset-status: 0 on POR */
+#define FLARE_AB_SESSION_REG 0xff020210u /* PMU GRF OS_REG4: attempt count */
+/*
+ * Attempts on the selected committed slot before failing over to the other
+ * committed slot; the other slot then gets the same budget before recovery.
+ * Keep in sync with the runbook and flared's docs.
+ */
+#define FLARE_AB_SLOT_TRIES 2
+/* Clamp against a garbage register value (validated free, so belt-only). */
+#define FLARE_AB_MAX_SESSION 250
+
+static u32 flare_ab_reg_read(u32 addr)
+{
+ return readl((void __iomem *)(uintptr_t)addr);
+}
+
+static void flare_ab_reg_write(u32 addr, u32 val)
+{
+ writel(val, (void __iomem *)(uintptr_t)addr);
+}
+
+/*
+ * Slot selection is resolved once per boot and memoized: the first
+ * caller is init_kernel_dtb() at board_init() time (via the part-name
+ * hook), and the per-attempt decrement must never flip the selection
+ * mid-boot (the "boundary problem" the SPL engine documents).
+ *
+ * cached state: -1 unknown, -2 no A/B layout, 0 slot A, 1 slot B
+ */
+static int flare_ab_cached_slot = -1;
+static int flare_ab_recovery;
+
+/*
+ * Set during slot selection when the per-power-session escalation has burned
+ * through both committed slots and the boot must fall to the recovery FIT.
+ * Resolved once (inside ab_select_slot, via the flare_ab_cached_slot memo) and
+ * read by flare_ab_have_bootable()/boot_attempt()/update_root_partition(), so
+ * every consumer agrees for the whole boot. Distinct from flare_ab_recovery,
+ * which fit_get_blob sets once it has actually redirected to the recovery FIT.
+ */
+static int flare_ab_force_recovery;
+
+/*
+ * The serialized metadata must fit in the single 512-byte sector we read and
+ * write. This is a build invariant, not a runtime condition (the struct is a
+ * fixed 32 bytes), so assert it at compile time instead of branching on it.
+ */
+_Static_assert(sizeof(AvbABData) <= 512, "AvbABData must fit in one sector");
+
+/*
+ * Whether any slot is bootable is resolved once per boot and memoized, exactly
+ * like the slot selection above: fit_get_blob() reads it BOTH at the early
+ * kernel-DTB load and again at the FIT load, and flare_ab_boot_attempt()'s
+ * tries decrement runs between those two reads. An uncached re-read could flip
+ * on the last-try boot (tries 1->0) and source U-Boot's own control FDT from a
+ * slot we then abandon for the recovery FIT. -1 unknown, 0 none, 1 bootable.
+ */
+static int flare_ab_cached_bootable = -1;
+
+static uint32_t flare_htobe32(uint32_t in)
+{
+ union {
+ uint32_t word;
+ uint8_t bytes[4];
+ } ret;
+
+ ret.bytes[0] = (in >> 24) & 0xff;
+ ret.bytes[1] = (in >> 16) & 0xff;
+ ret.bytes[2] = (in >> 8) & 0xff;
+ ret.bytes[3] = in & 0xff;
+
+ return ret.word;
+}
+
+static uint32_t flare_be32toh(uint32_t in)
+{
+ uint8_t *d = (uint8_t *)&in;
+ uint32_t ret;
+
+ ret = ((uint32_t)d[0]) << 24;
+ ret |= ((uint32_t)d[1]) << 16;
+ ret |= ((uint32_t)d[2]) << 8;
+ ret |= ((uint32_t)d[3]);
+
+ return ret;
+}
+
+static bool ab_data_verify_and_byteswap(const AvbABData *src, AvbABData *dest)
+{
+ if (memcmp(src->magic, AVB_AB_MAGIC, AVB_AB_MAGIC_LEN) != 0) {
+ printf("FLARE-AB: magic is incorrect\n");
+ return false;
+ }
+
+ memcpy(dest, src, sizeof(AvbABData));
+ dest->crc32 = flare_be32toh(dest->crc32);
+
+ if (dest->version_major > AVB_AB_MAJOR_VERSION) {
+ printf("FLARE-AB: no support for given major version\n");
+ return false;
+ }
+
+ if (dest->crc32 != crc32(0, (const uint8_t *)dest,
+ sizeof(AvbABData) - sizeof(uint32_t))) {
+ printf("FLARE-AB: CRC32 does not match\n");
+ return false;
+ }
+
+ return true;
+}
+
+static void ab_data_update_crc_and_byteswap(const AvbABData *src,
+ AvbABData *dest)
+{
+ memcpy(dest, src, sizeof(AvbABData));
+ dest->crc32 = flare_htobe32(crc32(0, (const uint8_t *)dest,
+ sizeof(AvbABData) - sizeof(uint32_t)));
+}
+
+static void ab_data_init(AvbABData *data)
+{
+ memset(data, '\0', sizeof(AvbABData));
+ memcpy(data->magic, AVB_AB_MAGIC, AVB_AB_MAGIC_LEN);
+ data->version_major = AVB_AB_MAJOR_VERSION;
+ data->version_minor = AVB_AB_MINOR_VERSION;
+ data->last_boot = 0;
+ data->slots[0].priority = AVB_AB_MAX_PRIORITY;
+ data->slots[0].tries_remaining = AVB_AB_MAX_TRIES_REMAINING;
+ data->slots[0].successful_boot = 0;
+ data->slots[1].priority = AVB_AB_MAX_PRIORITY - 1;
+ data->slots[1].tries_remaining = AVB_AB_MAX_TRIES_REMAINING;
+ data->slots[1].successful_boot = 0;
+}
+
+static int ab_read_metadata(struct blk_desc *dev_desc, AvbABData *ab_data)
+{
+ disk_partition_t part_info;
+ char temp[512];
+ int ret;
+
+ if (!dev_desc || !ab_data)
+ return -EFAULT;
+
+ /*
+ * Strict lookup: "misc" must never itself be slot-suffixed, and
+ * this path is re-entered from the part-name hook.
+ */
+ if (part_get_info_by_name_strict(dev_desc, PART_MISC, &part_info) < 0)
+ return -ENOENT;
+
+ ret = blk_dread(dev_desc, part_info.start + AB_METADATA_OFFSET, 1,
+ temp);
+ if (ret != 1)
+ return -ENODEV;
+
+ memcpy(ab_data, temp, sizeof(AvbABData));
+
+ return 0;
+}
+
+static int ab_write_metadata(struct blk_desc *dev_desc, AvbABData *ab_data)
+{
+ disk_partition_t part_info;
+ char temp[512];
+ int ret;
+
+ if (!dev_desc || !ab_data)
+ return -EFAULT;
+
+ memset(temp, 0, sizeof(temp));
+ memcpy(temp, ab_data, sizeof(AvbABData));
+ if (part_get_info_by_name_strict(dev_desc, PART_MISC, &part_info) < 0)
+ return -ENOENT;
+
+ ret = blk_dwrite(dev_desc, part_info.start + AB_METADATA_OFFSET, 1,
+ temp);
+ if (ret != 1)
+ return -ENODEV;
+
+ return 0;
+}
+
+static int ab_data_write(struct blk_desc *dev_desc, AvbABData *ab_data)
+{
+ AvbABData serialized;
+
+ ab_data_update_crc_and_byteswap(ab_data, &serialized);
+
+ return ab_write_metadata(dev_desc, &serialized);
+}
+
+static int ab_data_read(struct blk_desc *dev_desc, AvbABData *ab_data)
+{
+ AvbABData serialized;
+ int ret;
+
+ ret = ab_read_metadata(dev_desc, &serialized);
+ if (ret)
+ return ret;
+
+ if (!ab_data_verify_and_byteswap(&serialized, ab_data)) {
+ printf("FLARE-AB: invalid metadata, resetting to defaults\n");
+ ab_data_init(ab_data);
+ ab_data_write(dev_desc, ab_data);
+ }
+
+ return 0;
+}
+
+static bool slot_is_bootable(AvbABSlotData *slot)
+{
+ return slot->priority > 0 &&
+ (slot->successful_boot || (slot->tries_remaining > 0));
+}
+
+static void slot_set_unbootable(AvbABSlotData *slot)
+{
+ slot->priority = 0;
+ slot->tries_remaining = 0;
+ slot->successful_boot = 0;
+}
+
+static void slot_normalize(AvbABSlotData *slot)
+{
+ if (slot->priority > 0) {
+ if (slot->tries_remaining == 0 && !slot->successful_boot)
+ slot_set_unbootable(slot);
+ if (slot->tries_remaining > 0 && slot->successful_boot)
+ slot_set_unbootable(slot);
+ } else {
+ slot_set_unbootable(slot);
+ }
+}
+
+/*
+ * This power session's boot-attempt number against the selected slot (>=1).
+ * glb_rst_st==0 (a power-on reset) restarts the count; a warm reset carries the
+ * prior value forward. Writes the incremented value back to OS_REG4 so the next
+ * warm reset escalates. Called exactly once per boot (from ab_select_slot, which
+ * itself runs once behind the flare_ab_cached_slot memo).
+ */
+static int flare_ab_bump_session(void)
+{
+ u32 prior;
+
+ if (flare_ab_reg_read(FLARE_AB_GLB_RST_ST) == 0)
+ prior = 0;
+ else
+ prior = flare_ab_reg_read(FLARE_AB_SESSION_REG);
+
+ if (prior > FLARE_AB_MAX_SESSION)
+ prior = FLARE_AB_MAX_SESSION;
+
+ prior += 1;
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, prior);
+
+ return (int)prior;
+}
+
+static int ab_select_slot(void)
+{
+ struct blk_desc *dev_desc;
+ AvbABData ab_data;
+ int pref, other, session;
+
+ dev_desc = rockchip_get_bootdev();
+ if (!dev_desc)
+ return -2;
+
+ if (ab_data_read(dev_desc, &ab_data))
+ return -2; /* no misc partition: legacy single-slot layout */
+
+ if (slot_is_bootable(&ab_data.slots[0]) &&
+ slot_is_bootable(&ab_data.slots[1])) {
+ if (ab_data.slots[1].priority > ab_data.slots[0].priority)
+ pref = 1;
+ else
+ pref = 0;
+ } else if (slot_is_bootable(&ab_data.slots[0])) {
+ pref = 0;
+ } else if (slot_is_bootable(&ab_data.slots[1])) {
+ pref = 1;
+ } else {
+ /*
+ * No bootable slot at all (an exhausted update). Keep a
+ * deterministic answer (last_boot) so partition lookups still
+ * resolve; the boot path falls back to the recovery FIT instead
+ * (fit_get_blob checks flare_ab_have_bootable). Session
+ * escalation does not apply here -- persistent tries already
+ * decided this -- so leave OS_REG4 alone.
+ */
+ printf("FLARE-AB: no bootable slot, lastboot=%d\n",
+ ab_data.last_boot);
+ return ab_data.last_boot ? 1 : 0;
+ }
+
+ other = 1 - pref;
+
+ if (!ab_data.slots[pref].successful_boot) {
+ /*
+ * UPDATE regime: the preferred bootable slot is an unconfirmed
+ * update. The persistent per-attempt tries decrement (in
+ * flare_ab_boot_attempt) drives the revert, and it must survive
+ * power cycles so a bad update cannot return after a brownout.
+ * The session counter plays no part here; clear it so that once
+ * the update resolves to a committed steady state the escalation
+ * starts fresh at the selected slot.
+ */
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, 0);
+ printf("FLARE-AB: slot %s (update in flight), tries-remain=%d\n",
+ pref ? "_b" : "_a",
+ ab_data.slots[pref].tries_remaining);
+ return pref;
+ }
+
+ /*
+ * STEADY-STATE regime: the selected slot is committed. Escalate per
+ * power session -- selected slot for FLARE_AB_SLOT_TRIES attempts, then
+ * the other slot if it too is committed, then the recovery FIT. A power
+ * cycle (glb_rst_st==0) restarts at the selected slot.
+ */
+ session = flare_ab_bump_session();
+
+ if (session <= FLARE_AB_SLOT_TRIES) {
+ printf("FLARE-AB: slot %s (attempt %d/%d this power session)\n",
+ pref ? "_b" : "_a", session, FLARE_AB_SLOT_TRIES);
+ return pref;
+ }
+
+ if (session <= 2 * FLARE_AB_SLOT_TRIES &&
+ slot_is_bootable(&ab_data.slots[other]) &&
+ ab_data.slots[other].successful_boot) {
+ printf("FLARE-AB: slot %s failed %d attempts this session, trying %s\n",
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES,
+ other ? "_b" : "_a");
+ return other;
+ }
+
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
+ flare_ab_force_recovery = 1;
+ return pref;
+}
+
+int flare_ab_enabled(void)
+{
+ if (flare_ab_cached_slot == -1)
+ flare_ab_cached_slot = ab_select_slot();
+
+ return flare_ab_cached_slot >= 0;
+}
+
+int flare_ab_get_current_slot(char *slot)
+{
+ if (!flare_ab_enabled())
+ return -ENOENT;
+
+ memcpy(slot, flare_ab_cached_slot ? "_b" : "_a", 2);
+ slot[2] = '\0';
+
+ return 0;
+}
+
+int flare_ab_append_part_slot(struct blk_desc *dev_desc,
+ const char *part_name, char *new_name)
+{
+ char slot_suffix[3] = {0};
+
+ /*
+ * Never suffix the slot-metadata carrier itself (also breaks
+ * the re-entrancy from ab_read_metadata), nor the shared
+ * recovery FIT.
+ */
+ if (!strcmp(part_name, PART_MISC) ||
+ !strcmp(part_name, PART_RECOVERY)) {
+ strcat(new_name, part_name);
+ return 0;
+ }
+
+ if (flare_ab_get_current_slot(slot_suffix)) {
+ /* No A/B layout: behave exactly like stock. */
+ strcat(new_name, part_name);
+ return 0;
+ }
+
+ strcpy(new_name, part_name);
+ strcat(new_name, slot_suffix);
+
+ return 0;
+}
+
+int flare_ab_have_bootable(void)
+{
+ struct blk_desc *dev_desc;
+ AvbABData ab_data;
+
+ /*
+ * Resolve selection first: the per-power-session escalation can decide
+ * both committed slots are exhausted and force the recovery FIT even
+ * though the persistent metadata still marks a slot bootable. In that
+ * case there is no bootable NORMAL slot for this boot.
+ */
+ flare_ab_enabled();
+ if (flare_ab_force_recovery)
+ return 0;
+
+ /*
+ * Memoized for the whole boot (see flare_ab_cached_bootable): the two
+ * fit_get_blob() reads straddle the per-attempt tries decrement, so an
+ * uncached answer could disagree with itself on the last-try boot.
+ */
+ if (flare_ab_cached_bootable != -1)
+ return flare_ab_cached_bootable;
+
+ flare_ab_cached_bootable = 0;
+
+ dev_desc = rockchip_get_bootdev();
+ if (!dev_desc)
+ return 0;
+
+ if (ab_data_read(dev_desc, &ab_data))
+ return 0;
+
+ flare_ab_cached_bootable = slot_is_bootable(&ab_data.slots[0]) ||
+ slot_is_bootable(&ab_data.slots[1]);
+ return flare_ab_cached_bootable;
+}
+
+void flare_ab_set_recovery_mode(void)
+{
+ if (!flare_ab_recovery) {
+ printf("FLARE-AB: recovery FIT selected\n");
+ /*
+ * One-shot, like the BCB clear RkLunch-recovery.sh does on
+ * entry to the rescue ramdisk: the per-power-session
+ * escalation has done its job (or was bypassed by a BCB
+ * command) once we are here, so reset it. Without this,
+ * OS_REG4 keeps carrying the count that forced recovery, and
+ * this SoC's `reboot` only works via the CRU global-reset
+ * poke (docs/boot-flow.md) -- itself a WARM reset -- so any
+ * reboot issued from inside recovery would re-escalate
+ * straight back into recovery on the next boot, stranding
+ * the operator until someone cycles power at the unit. This
+ * one hook covers every path that reaches PART_RECOVERY (BCB
+ * command, no-bootable-slot fallback, and this session
+ * escalation alike).
+ */
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, 0);
+ }
+ flare_ab_recovery = 1;
+}
+
+int flare_ab_in_recovery(void)
+{
+ return flare_ab_recovery;
+}
+
+void flare_ab_boot_attempt(void)
+{
+ struct blk_desc *dev_desc;
+ AvbABData ab_data, ab_data_orig;
+ int slot_index;
+
+ if (!flare_ab_enabled() || flare_ab_recovery || flare_ab_force_recovery)
+ return;
+
+ slot_index = flare_ab_cached_slot;
+
+ dev_desc = rockchip_get_bootdev();
+ if (!dev_desc)
+ return;
+
+ if (ab_data_read(dev_desc, &ab_data))
+ return;
+
+ memcpy(&ab_data_orig, &ab_data, sizeof(AvbABData));
+
+ slot_normalize(&ab_data.slots[0]);
+ slot_normalize(&ab_data.slots[1]);
+
+ if (!ab_data.slots[slot_index].successful_boot &&
+ ab_data.slots[slot_index].tries_remaining > 0)
+ ab_data.slots[slot_index].tries_remaining -= 1;
+
+ ab_data.last_boot = slot_index;
+
+ /*
+ * Single-sector write, and only while an update window is open
+ * (an unsuccessful slot): a confirmed device's ordinary boots
+ * and power cycles never write flash here.
+ */
+ if (memcmp(&ab_data, &ab_data_orig, sizeof(AvbABData)))
+ ab_data_write(dev_desc, &ab_data);
+}
+
+void flare_ab_boot_failed(void)
+{
+ if (!flare_ab_enabled())
+ return;
+
+ if (flare_ab_recovery) {
+ /*
+ * Both slots AND the recovery FIT are gone. Escalate to USB
+ * download: `download` runs `rockusb` FROM U-BOOT when
+ * CONFIG_CMD_ROCKUSB is built (flare-usb-gadget.config), so a
+ * bad-boot device is reflashable over USB with no MaskRom
+ * button / disassembly; if rockusb is absent it falls through
+ * to `rbrom` (BootROM MaskRom). Either way the host can recover
+ * it over the existing USB port.
+ */
+ printf("FLARE-AB: recovery FIT unbootable, entering USB download\n");
+ run_command("download", 0);
+ hang();
+ }
+
+ /*
+ * A storage-slot boot failed to load its FIT. Reset so the next boot
+ * makes forward progress. This is a WARM reset, so glb_rst_st stays
+ * nonzero and OS_REG4 carries the attempt count: the next boot
+ * escalates -- retry the same committed slot up to FLARE_AB_SLOT_TRIES,
+ * then the other committed slot, then the recovery FIT, then USB
+ * download. In the update regime the per-attempt persistent-tries
+ * decrement (flare_ab_boot_attempt) has already run, so the same reset
+ * drives the persistent revert to the other slot. A power cycle
+ * (glb_rst_st==0) restarts at the selected slot -- no failure state is
+ * written to flash for a committed slot.
+ */
+ printf("FLARE-AB: slot boot failed, resetting\n");
+ do_reset(NULL, 0, 0, NULL);
+ hang();
+}
+
+void flare_ab_update_root_partition(void)
+{
+ disk_partition_t part_info;
+ struct blk_desc *dev_desc;
+ char arg[64];
+ char slot_suffix[3] = {0};
+ int part_num;
+
+ if (!flare_ab_enabled())
+ return;
+
+ if (flare_ab_recovery || flare_ab_force_recovery) {
+ /*
+ * Recovery boots from its own initramfs; publish the
+ * marker and leave root= alone (unused under rdinit).
+ * flare_ab_force_recovery is set by the session escalation at
+ * selection time, before fit_get_blob has set flare_ab_recovery,
+ * so it must be honored here too.
+ */
+ env_update("bootargs", "warden.recovery=1");
+ return;
+ }
+
+ dev_desc = rockchip_get_bootdev();
+ if (!dev_desc)
+ return;
+
+ /* Auto-suffixed by the part-name hook: resolves rootfs_a/_b. */
+ part_num = part_get_info_by_name(dev_desc, "rootfs", &part_info);
+ if (part_num < 0) {
+ printf("FLARE-AB: no rootfs slot partition\n");
+ return;
+ }
+
+ if (dev_desc->if_type != IF_TYPE_MMC)
+ return;
+
+ snprintf(arg, sizeof(arg), "root=/dev/mmcblk0p%d", part_num);
+ env_update("bootargs", arg);
+
+ flare_ab_get_current_slot(slot_suffix);
+ snprintf(arg, sizeof(arg), "warden.slot=%s", slot_suffix);
+ env_update("bootargs", arg);
+}
diff --git a/sysdrv/source/uboot/u-boot/configs/flare-ab.config b/sysdrv/source/uboot/u-boot/configs/flare-ab.config
new file mode 100644
index 000000000..1404655c0
--- /dev/null
+++ b/sysdrv/source/uboot/u-boot/configs/flare-ab.config
@@ -0,0 +1,10 @@
+# flare-edge: A/B slot boot in U-Boot proper.
+#
+# Lean port of the vendor SPL A/B engine (common/flare_ab.c): AOSP
+# AvbABData metadata in one CRC32-protected sector at misc+2048, slot
+# suffixing hooked into part_get_info_by_name() (covers boot_fit AND the
+# board_init()-time kernel-DTB/resource load), one tries decrement per
+# boot attempt while a slot is unconfirmed, recovery-FIT fallback when
+# both slots are exhausted, MaskRom when even that fails.
+# Design: docs/decisions/0001-slot-machine.md (flare-edge repo).
+CONFIG_FLARE_AB=y
diff --git a/sysdrv/source/uboot/u-boot/disk/part.c b/sysdrv/source/uboot/u-boot/disk/part.c
index 182c03771..ad73662eb 100644
--- a/sysdrv/source/uboot/u-boot/disk/part.c
+++ b/sysdrv/source/uboot/u-boot/disk/part.c
@@ -14,6 +14,9 @@
#ifdef CONFIG_SPL_AB
#include <spl_ab.h>
#endif
+#ifdef CONFIG_FLARE_AB
+#include <flare_ab.h>
+#endif
#include <ubifs_uboot.h>
#ifdef CONFIG_ANDROID_AB
#include <android_avb/avb_ops_user.h>
@@ -700,7 +703,8 @@ static int part_get_info_by_name_option(struct blk_desc *dev_desc,
}
/* 1. Query partition with A/B slot suffix */
-#if defined(CONFIG_ANDROID_AB) || defined(CONFIG_SPL_AB)
+#if defined(CONFIG_ANDROID_AB) || defined(CONFIG_SPL_AB) || \
+ defined(CONFIG_FLARE_AB)
char *slot = (char *)name + strlen(name) - 2;
if (!strcmp(slot, "_a") || !strcmp(slot, "_b"))
@@ -710,6 +714,10 @@ static int part_get_info_by_name_option(struct blk_desc *dev_desc,
if (rk_avb_append_part_slot(name, name_slot))
return -1;
full_name = name_slot;
+#elif defined(CONFIG_FLARE_AB) && !defined(CONFIG_SPL_BUILD)
+ if (flare_ab_append_part_slot(dev_desc, name, name_slot))
+ return -1;
+ full_name = name_slot;
#elif defined(CONFIG_SPL_AB) && defined(CONFIG_SPL_BUILD)
if (spl_ab_append_part_slot(dev_desc, name, name_slot))
return -1;
diff --git a/sysdrv/source/uboot/u-boot/include/flare_ab.h b/sysdrv/source/uboot/u-boot/include/flare_ab.h
new file mode 100644
index 000000000..d009525e0
--- /dev/null
+++ b/sysdrv/source/uboot/u-boot/include/flare_ab.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * flare-edge A/B slot boot for U-Boot proper.
+ *
+ * A lean, libavb-free port of the vendor SPL A/B engine
+ * (common/spl/spl_ab.c) so the same AOSP AvbABData metadata (one
+ * CRC32-protected 32-byte struct in a single 512-byte sector at
+ * `misc` + AB_METADATA_OFFSET blocks) drives slot selection in U-Boot
+ * proper: boot_a/boot_b via the part_get_info_by_name() suffix hook,
+ * per-attempt tries decrement, and fallback to the recovery FIT when
+ * both slots are exhausted.
+ *
+ * Linux-side counterpart: flared's slotctl module — the ONLY writer of
+ * this metadata from userspace (CI-enforced).
+ */
+
+#ifndef _FLARE_AB_H_
+#define _FLARE_AB_H_
+
+#include <blk.h>
+
+/* Same on-disk location as the vendor SPL engine (spl_ab.h). */
+#ifndef AB_METADATA_OFFSET
+#define AB_METADATA_OFFSET 4
+#endif
+
+/*
+ * True when an A/B layout is present (a `misc` partition with valid or
+ * initializable metadata). On a legacy single-slot layout every hook
+ * below degrades to stock behavior.
+ */
+int flare_ab_enabled(void);
+
+/* Memoized for the whole boot: "_a"/"_b" into slot[3]. 0 on success. */
+int flare_ab_get_current_slot(char *slot);
+
+/* part_get_info_by_name() hook: append the active slot suffix. */
+int flare_ab_append_part_slot(struct blk_desc *dev_desc,
+ const char *part_name, char *new_name);
+
+/* Any slot with priority>0 and (successful || tries>0)? */
+int flare_ab_have_bootable(void);
+
+/*
+ * One boot attempt against the selected slot: decrement tries_remaining
+ * iff the slot is not yet successful (single-sector write, and no write
+ * at all in the successful steady state — spec fault 14 by construction).
+ * No-op in recovery fallback mode or on a non-A/B layout.
+ */
+void flare_ab_boot_attempt(void);
+
+/*
+ * Storage boot failed (FIT unreadable/unbootable). On an A/B layout:
+ * reset so the next boot re-selects (per-attempt decrement guarantees
+ * progress); once no slot is bootable the next boot falls back to the
+ * recovery FIT; if that also failed, drop to MaskRom (`download`).
+ * Returns (doing nothing) on a non-A/B layout.
+ */
+void flare_ab_boot_failed(void);
+
+/* fit_get_blob() fell back to (or was commanded into) the recovery FIT. */
+void flare_ab_set_recovery_mode(void);
+int flare_ab_in_recovery(void);
+
+/*
+ * bootargs fixup, mirrors ab_update_root_partition(): key-replace
+ * root= with the active slot's rootfs partition and publish
+ * warden.slot=_x (and warden.recovery=1 in recovery fallback) for
+ * userspace (oem mount, slotctl).
+ */
+void flare_ab_update_root_partition(void);
+
+#endif /* _FLARE_AB_H_ */
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
@@ -16,6 +16,9 @@
#include <cli.h>
#include <clk.h>
#include <console.h>
#include <flare_trace.h>
+#ifdef CONFIG_FLARE_AB
+#include <flare_ab.h>
+#endif
#include <debug_uart.h>
#include <dm.h>
@@ -1340,9 +1343,19 @@
static void bootargs_add_android(bool verbose)
{
#ifdef CONFIG_ANDROID_AB
ab_update_root_partition();
#endif
+#ifdef CONFIG_FLARE_AB
+ /*
+ * Runs after bootargs_add_partition() merged sys_bootargs, so
+ * the env_update() here key-replaces any build-time root= with
+ * the active slot's rootfs partition (and publishes warden.slot
+ * for userspace).
+ */
+ flare_ab_update_root_partition();
+#endif
+
/* Android header v4+ need this handle */
#ifdef CONFIG_ANDROID_BOOT_IMAGE
struct andr_img_hdr *hdr;
@@ -0,0 +1,35 @@
diff --git a/sysdrv/source/uboot/u-boot/cmd/download.c b/sysdrv/source/uboot/u-boot/cmd/download.c
index 528501305..77f56ea12 100644
--- a/sysdrv/source/uboot/u-boot/cmd/download.c
+++ b/sysdrv/source/uboot/u-boot/cmd/download.c
@@ -7,6 +7,9 @@
#include <common.h>
#include <command.h>
#include <console.h>
+#if defined(CONFIG_DRM_ROCKCHIP) && defined(CONFIG_FLARE_AB)
+#include <video_rockchip.h>
+#endif
__weak void do_board_download(void)
{
@@ -17,6 +20,20 @@ static int do_download(cmd_tbl_t *cmdtp, int flag,
{
disable_ctrlc(1);
+#if defined(CONFIG_DRM_ROCKCHIP) && defined(CONFIG_FLARE_AB)
+ /*
+ * flare-edge: paint the "connect USB to recover" splash before entering
+ * download mode. Reached on every download trigger — FLARE_AB slot/
+ * recovery exhaustion, altbootcmd=download, the BOOT key, Ctrl+D. The
+ * VOP keeps scanning out this framebuffer while rockusb (below) serves
+ * from U-Boot WITHOUT a reset, so the image PERSISTS on screen the whole
+ * time the device is USB-flashable. (On the rbrom fallback a CRU reset
+ * clears it — BootROM has no display — but rockusb is the primary path.)
+ * logo_recovery.bmp is packed into resource.img (kernel scripts/mkimg).
+ */
+ rockchip_show_bmp("logo_recovery.bmp");
+#endif
+
/* Allow board specific download, maybe noreturn */
do_board_download();
@@ -0,0 +1,61 @@
diff -ruN a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi 2026-09-01 15:32:39.100121610 -0600
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi 2026-09-01 15:32:39.056121549 -0600
@@ -93,7 +93,14 @@
&sdmmc {
u-boot,dm-spl;
- pwr-en-gpios = <&gpio0 RK_PA1 GPIO_ACTIVE_LOW>;
+ /* flare-edge: the EVB's SD-slot power enable was <&gpio0 RK_PA1
+ * GPIO_ACTIVE_LOW> -- on the 86-Panel that pin is RGB_RES, the
+ * CH32V003 panel-init MCU's reset (schematic-confirmed net). The
+ * sdmmc probe was driving it low in SPL on every boot, holding the
+ * panel initialiser in reset until board_init re-released it at
+ * ~0.55 s and restarting its measured, fixed 4.89 s init -- the
+ * single longest pole in time-to-first-image. The 86-Panel's SD slot
+ * has no switched rail on this line; drop the property. */
status = "okay";
};
diff -ruN a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c 2026-09-01 15:32:39.100121610 -0600
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c 2026-09-01 15:32:39.040121527 -0600
@@ -216,6 +216,23 @@
#endif
gd->flags = dummy;
rockchip_stimer_init();
+#if defined(CONFIG_ROCKCHIP_RV1106)
+ /*
+ * flare-edge: release GPIO0_A1 (net RGB_RES) at the earliest possible
+ * moment. The net holds the 86-Panel's CH32V003 init MCU (and the
+ * panel's own reset pin) in reset via the pin's power-on pulldown, and
+ * the MCU takes a MEASURED, fixed 4.89 s from release to first photons
+ * (its SPI init of the NV3052 controller) regardless of anything the
+ * SoC does. Every millisecond the release moves earlier is a
+ * millisecond off time-to-first-image, so it happens here in SPL
+ * (~0.03 s) rather than U-Boot proper's board_init() (~0.45 s), which
+ * keeps its own idempotent release as a fallback. Raw writels because
+ * no driver model exists yet: RV1106 GPIO0 v2 @0xff380000,
+ * swport_dr_l 0x00 / swport_ddr_l 0x08, write-masked upper half word.
+ */
+ writel(0x00020002, (void *)0xff380008); /* GPIO0_A1 -> output */
+ writel(0x00020002, (void *)0xff380000); /* GPIO0_A1 -> high */
+#endif
#define EARLY_UART
#if defined(EARLY_UART) && defined(CONFIG_DEBUG_UART)
/*
@@ -230,6 +247,14 @@
!(gd->flags & GD_FLG_DISABLE_CONSOLE))
debug_uart_init();
printascii("U-Boot SPL board init");
+#if defined(CONFIG_ROCKCHIP_RV1106)
+ /* flare-edge: diagnose the early GPIO0_A1 release -- print DR+DDR. */
+ printascii(" [RGB_RES dr=");
+ printhex8(readl((void *)0xff380000));
+ printascii(" ddr=");
+ printhex8(readl((void *)0xff380008));
+ printascii("] ");
+#endif
#endif
gd->sys_start_tick = get_ticks();
#ifdef CONFIG_SPL_PCIE_EP_SUPPORT
@@ -0,0 +1,109 @@
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
@@ -246,3 +246,106 @@
u-boot,dm-pre-reloc;
status = "okay";
};
+
+/*
+ * flare-edge: the 86-Panel display graph, kept in U-Boot's OWN device tree.
+ *
+ * DORMANT in the shipped configuration: flare-display.config keeps
+ * CONFIG_USING_KERNEL_DTB=y and embeds a kernel-style control DTB
+ * (CONFIG_EMBED_KERNEL_DTB_ALWAYS, dts/rv1106-warden-kernel.dtb), which
+ * board_init() adopts BEFORE any display bring-up -- so these nodes are not
+ * consulted at runtime today. They are kept as the complete, board-correct
+ * display graph for a future own-control-DTB configuration, copied verbatim
+ * from the proven 5.10 kernel DTS (rv1106-luckfox-pico-86panel-ipc.dtsi).
+ *
+ * Do NOT enable such a configuration by setting
+ * "CONFIG_USING_KERNEL_DTB is not set": that path was tried 2026-09-01 and
+ * silently breaks the ENVF whitelist import -- blkdevparts= disappears from
+ * the kernel cmdline and, with no partition table outside the cmdline, BOTH
+ * slots hang in rootwait (see flare-display.config for the full account).
+ * The logo BMPs always come from the booted slot's resource.img.
+ */
+/ {
+ backlight: backlight {
+ compatible = "pwm-backlight";
+ pwms = <&pwm1 0 100000 50000>;
+ };
+
+ panel: panel {
+ compatible = "simple-panel";
+ backlight = <&backlight>;
+ bus-format = <0x1009>; /* MEDIA_BUS_FMT_RGB666_1X18 */
+ width-mm = <85>;
+ height-mm = <85>;
+
+ display-timings {
+ native-mode = <&timing0>;
+
+ timing0: timing0 {
+ clock-frequency = <30000000>;
+ hactive = <720>;
+ vactive = <720>;
+ hback-porch = <44>;
+ hfront-porch = <46>;
+ vback-porch = <18>;
+ vfront-porch = <16>;
+ hsync-len = <2>;
+ vsync-len = <2>;
+ hsync-active = <0>;
+ vsync-active = <0>;
+ de-active = <0>;
+ pixelclk-active = <0>;
+ };
+ };
+
+ port {
+ panel_in_rgb: endpoint {
+ remote-endpoint = <&rgb_out_panel>;
+ };
+ };
+ };
+};
+
+&display_subsystem {
+ status = "okay";
+
+ route {
+ route_rgb: route-rgb {
+ status = "okay";
+ logo,uboot = "logo.bmp";
+ logo,kernel = "logo_kernel.bmp";
+ logo,mode = "center";
+ charge_logo,mode = "center";
+ connect = <&vop_out_rgb>;
+ };
+ };
+};
+
+&pwm1 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&pwm1m2_pins>;
+};
+
+&rgb {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&lcd_pins>;
+
+ ports {
+ rgb_out: port@1 {
+ reg = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ rgb_out_panel: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&panel_in_rgb>;
+ };
+ };
+ };
+};
+
+&vop {
+ status = "okay";
+};
@@ -0,0 +1,36 @@
diff -ruN a/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h b/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h
--- a/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h 2026-09-01 16:48:53.948824814 -0600
+++ b/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h 2026-09-01 16:48:53.936824778 -0600
@@ -68,18 +68,26 @@
#define ENV_MEM_LAYOUT_SETTINGS CONFIG_ENV_MEM_LAYOUT_SETTINGS
#else
/*
+ * flare-edge layout (2026-09-01): the vendor put fdt at 12M and ramdisk at
+ * 14M, which capped the zImage (loaded at 0x8000) at ~11.95MB -- sysmem
+ * rejects the boot with "slot boot failed" the moment the kernel grows past
+ * the fdt region, which our gzip-compressed 6.18 (12.25MB) did. Move fdt to
+ * 128M (matching the load address our external-data FITs already carry) and
+ * ramdisk above it; a 256MB board has the room, and the kernel can now grow
+ * to ~120MB before this bites again.
+ *
* Image: 0 - 8M
- * zImage: 8 - 12M
- * fdt: 12 - 13M
- * ramdisk: 14 ...
+ * zImage: 8 - ...
+ * fdt: 128M
+ * ramdisk: 132M ...
*/
#define ENV_MEM_LAYOUT_SETTINGS \
"scriptaddr=0x00b00000\0" \
- "pxefile_addr_r=0x00c00000\0" \
- "fdt_addr_r=0x00c00000\0" \
+ "pxefile_addr_r=0x08000000\0" \
+ "fdt_addr_r=0x08000000\0" \
"kernel_addr_c=0x00808000\0" \
"kernel_addr_r=0x00008000\0" \
- "ramdisk_addr_r=0x000e00000\0"
+ "ramdisk_addr_r=0x008400000\0"
#endif
#define CONFIG_EXTRA_ENV_SETTINGS \
@@ -0,0 +1,503 @@
flare-edge: decide the verbose boot in U-Boot, from a press on the splash.
See arch/arm/mach-rockchip/flare_touch.c for the measurements behind the
sampling design (issues #140, #143).
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
@@ -17,6 +17,7 @@
#include <clk.h>
#include <console.h>
#include <flare_trace.h>
+#include <flare_touch.h>
#ifdef CONFIG_FLARE_AB
#include <flare_ab.h>
#endif
@@ -519,9 +520,28 @@
/* Logo as early as possible, but never ahead of the recovery path. */
#ifdef CONFIG_DRM_ROCKCHIP
if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) {
+ char ubt[64];
+ ulong t0, t1;
+
FLARE_TRACE("rockchip_show_logo start");
+ t0 = FLARE_USEC();
rockchip_show_logo();
+ t1 = FLARE_USEC();
FLARE_TRACE("rockchip_show_logo done");
+ /* Milliseconds since power-on, entering and leaving the logo
+ * call. Reported on the kernel command line because that is the
+ * only place a panel with no serial console can be asked
+ * afterwards how long its splash really took. */
+ snprintf(ubt, sizeof(ubt), "warden.ubt=%lu,%lu",
+ t0 / 1000, t1 / 1000);
+ env_set("flare_ubt", ubt);
+
+ /*
+ * From here on, anything the touch controller reports is
+ * something that happened while the splash was on screen.
+ */
+ flare_touch_arm();
+
}
#endif
#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
@@ -676,6 +696,49 @@
#endif
}
+/*
+ * flare-edge: swap the splash mark and ask for a verbose boot, if the panel
+ * was tapped.
+ *
+ * The splash's bottom-right mark reads GRAPHIC. A tap swaps it for the
+ * otherwise identical VERBOSE image and puts warden.verbose=1 on the kernel
+ * command line, so what the operator is shown matches the boot they get.
+ *
+ * BOTH image calls are needed. rockchip_show_bmp() repaints what U-Boot is
+ * showing now; rockchip_set_kernel_logo() changes the separate image handed to
+ * the kernel at the display handoff. Without the second, the kernel logo
+ * paints GRAPHIC back over the first a few milliseconds later and the tap
+ * looks ignored.
+ *
+ * warden.touch is reported on EVERY boot, tapped or not. Without it, "no
+ * controller", "controller present but silent" and "not touched" are the same
+ * silence on a panel with no serial console.
+ */
+static void flare_verbose_check(void)
+{
+ struct flare_touch_state st;
+ char buf[80];
+ int tapped, shown, kset;
+
+ tapped = flare_touch_tapped(&st);
+
+ snprintf(buf, sizeof(buf), "warden.touch=0x%x,%d,%s,arm%d:0x%02x,rd0x%02x",
+ st.addr, tapped, st.id[0] ? st.id : "none",
+ st.armed, st.arm_status, st.status);
+ env_set("flare_touch", buf);
+ FLARE_TRACE(buf);
+
+ if (!tapped)
+ return;
+
+ shown = rockchip_show_bmp("logo_verbose.bmp");
+ kset = rockchip_set_kernel_logo("logo_verbose.bmp");
+ snprintf(buf, sizeof(buf), "warden.vmark=%d,%d", shown, kset);
+ env_set("flare_vmark", buf);
+ env_set("flare_verbose", "1");
+ FLARE_TRACE("verbose boot selected by touch");
+}
+
int board_fdt_fixup(void *blob)
{
/*
@@ -684,6 +747,23 @@
*/
rk_board_dm_fdt_fixup(blob);
+ /*
+ * flare-edge: the verbose-boot tap.
+ *
+ * Sampled HERE, and deliberately not earlier. The controller latches a
+ * touch report and holds it until acknowledged, so one read at this
+ * point catches a tap made at any time during the splash -- without
+ * watching for a window, which would add that window to every boot
+ * whether or not anyone touched the panel. An escape hatch is not worth
+ * paying for on boots that never use it.
+ *
+ * This is the last moment both halves can still be changed: it runs
+ * before rockchip_display_fixup() below loads the kernel logo, and
+ * arch_fixup_fdt() runs before fdt_chosen(), so the command line built
+ * by board_fdt_chosen_bootargs() still picks up what is set here.
+ */
+ flare_verbose_check();
+
/* Common fixup for DRM */
#ifdef CONFIG_DRM_ROCKCHIP
rockchip_display_fixup(blob);
@@ -1475,6 +1555,29 @@
bootargs_add_fwver(verbose);
bootargs_add_android(verbose);
+ /* flare-edge: the splash tap, carried to the kernel. Added here rather
+ * than where it is sampled because sys_bootargs is merged into bootargs
+ * after board_late_init, and an earlier append does not survive it. */
+ {
+ const char *ub = env_get("flare_ubt");
+ const char *ft = env_get("flare_touch");
+
+ if (ub)
+ env_update("bootargs", ub);
+ const char *fv = env_get("flare_verbose");
+
+ if (ft)
+ env_update("bootargs", ft);
+
+ if (fv && !strcmp(fv, "1")) {
+ const char *vm = env_get("flare_vmark");
+
+ env_update("bootargs", "warden.verbose=1");
+ if (vm)
+ env_update("bootargs", vm);
+ }
+ }
+
/*
* Initrd fixup: remove unused "initrd=0x...,0x...",
* this for compatible with legacy parameter.txt
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/Makefile
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/Makefile
@@ -37,6 +37,7 @@
obj-y += boot_mode.o
obj-y += boot_rkimg.o
obj-y += board.o
+obj-y += flare_touch.o
obj-y += iomem.o
obj-y += memblk.o
obj-$(CONFIG_ROCKCHIP_HOTKEY) += hotkey.o
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
@@ -52,7 +52,22 @@
#define RK_BLK_SIZE 512
#define BMP_PROCESSED_FLAG 8399
#define BYTES_PER_PIXEL sizeof(uint32_t)
-#define MAX_IMAGE_BYTES (8 * 1024 * 1024)
+/*
+ * flare-edge: 8 MB was too large to ask for twice.
+ *
+ * This is the transient scratch buffer a single image load takes, and it is
+ * held while the decoded bitmap (~2 MB for this panel) is also live. Against
+ * CONFIG_SYS_MALLOC_LEN of 16 MB the first load fits, but by the second the
+ * heap can no longer satisfy another 8 MB contiguous request and the load
+ * fails with -ENOMEM. That is invisible on a panel: rockchip_show_bmp() went
+ * on to report success, so a second image simply never appeared.
+ *
+ * The panel's own logos are 720x720x3 plus header = 1,555,254 bytes, so 4 MB
+ * is still 2.6x the largest image this board can display while being small
+ * enough to allocate repeatedly. An image larger than this reads short and is
+ * then rejected by the decoder rather than shown corrupt.
+ */
+#define MAX_IMAGE_BYTES (4 * 1024 * 1024)
DECLARE_GLOBAL_DATA_PTR;
static LIST_HEAD(rockchip_display_list);
@@ -1549,7 +1564,15 @@
list_for_each_entry(s, &rockchip_display_list, head) {
s->logo.mode = s->charge_logo_mode;
- if (load_bmp_logo(&s->logo, bmp))
+ /*
+ * flare-edge: report the load failure instead of swallowing it.
+ * `ret` starts at 0 and this loop used to `continue` past a
+ * failed load, so a call that displayed nothing at all still
+ * returned success -- which sent a whole debugging round after
+ * a display that had never been given an image.
+ */
+ ret = load_bmp_logo(&s->logo, bmp);
+ if (ret)
continue;
ret = display_logo(s);
}
@@ -1557,6 +1580,36 @@
return ret;
}
+/*
+ * flare-edge: change which image the KERNEL is handed at the display handoff.
+ *
+ * rockchip_show_bmp() only repaints what U-Boot itself is showing. The image
+ * the kernel keeps on screen is a separate one, loaded from klogo_name into
+ * the rockchip,drm-logo reserved memory during rockchip_display_fixup(), and
+ * it is painted over whatever U-Boot drew moments earlier. So swapping the
+ * splash for a tap without also swapping this one shows the new image for a
+ * few milliseconds and then reverts, which reads on the panel as the tap
+ * having done nothing at all.
+ */
+int rockchip_set_kernel_logo(const char *bmp)
+{
+ struct display_state *s;
+ int found = 0;
+
+ if (!bmp)
+ return -EINVAL;
+
+ list_for_each_entry(s, &rockchip_display_list, head) {
+ if (strlen(bmp) >= sizeof(s->klogo_name))
+ return -ENAMETOOLONG;
+ memset(s->klogo_name, 0, sizeof(s->klogo_name));
+ memcpy(s->klogo_name, bmp, strlen(bmp));
+ found++;
+ }
+
+ return found ? 0 : -ENODEV;
+}
+
int rockchip_show_logo(void)
{
struct display_state *s;
--- a/sysdrv/source/uboot/u-boot/include/video_rockchip.h
+++ b/sysdrv/source/uboot/u-boot/include/video_rockchip.h
@@ -23,6 +23,7 @@
int rockchip_show_bmp(const char *bmp);
int rockchip_show_logo(void);
+int rockchip_set_kernel_logo(const char *bmp);
void rockchip_display_fixup(void *blob);
#endif
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/flare_touch.c
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/flare_touch.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * flare-edge: read the panel's touchscreen from U-Boot, so the choice between
+ * the graphic splash and a verbose boot is made BEFORE the kernel starts.
+ *
+ * WHY THIS LIVES IN THE BOOTLOADER. The same decision used to be made in
+ * userspace, by S09splash watching the evdev node. That could only ever cover
+ * the part of the boot that had already happened by the time an init script
+ * ran, and it was fragile for a second reason: the window was expressed as an
+ * absolute uptime, and once the splash started later than that deadline the
+ * probe ended on its first iteration and the feature was silently dead
+ * (issue #143). Deciding here removes both problems -- the flag is on the
+ * kernel command line before the kernel prints its first line, and there is no
+ * race with when an init script happens to run.
+ *
+ * THE PANEL'S CONTROLLER. A Goodix GT911 on i2c3 (i2c@ff460000). Its I2C
+ * address is selected by the INT pin level while RESET is released: high
+ * selects 0x14, low selects 0x5d. U-Boot drives RESET (it is in the DT as
+ * reset-gpios) but NOT INT (the DT describes INT as an interrupt, not a gpio),
+ * so the address after our reset is whatever INT floats to. Rather than fight
+ * that, both addresses are probed and the one that answers is used. The kernel
+ * driver re-runs its own reset sequence later regardless, so leaving the
+ * controller in either state is safe.
+ *
+ * COST. Everything here is bounded and skipped entirely when the controller
+ * does not answer, so a panel with no touchscreen, or one whose controller is
+ * held in reset, adds only the probe attempt to boot -- not the poll window.
+ */
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/gpio.h>
+#include <dm/ofnode.h>
+#include <linux/libfdt.h>
+#include <asm/global_data.h>
+#include <flare_trace.h>
+#include <flare_touch.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define GT911_I2C_BUS 3
+#define GT911_ADDR_INT_HIGH 0x14
+#define GT911_ADDR_INT_LOW 0x5d
+
+/*
+ * Coordinate/status register. Bit 7 is "a fresh report is ready"; the low
+ * nibble counts the touch points in it. The controller does not clear this
+ * itself -- the reader must write 0 back, or the same report is returned for
+ * ever and a single stale touch would look like a finger held down.
+ */
+#define GT911_REG_STATUS 0x814e
+#define GT911_STATUS_READY 0x80
+#define GT911_STATUS_NTOUCH 0x0f
+
+/* Datasheet: >=10 ms asserted, and the controller needs ~50 ms after release
+ * before it answers on I2C. The margins here are deliberately generous: this
+ * runs once per boot and a retry costs more than the wait it saves. */
+#define GT911_RESET_HOLD_MS 20
+#define GT911_RESET_SETTLE_MS 60
+
+/* Product id lives here: four ASCII bytes, "911" on this panel. Reading it is
+ * how we tell a real controller from an address that merely ACKs. */
+#define GT911_REG_ID 0x8140
+
+/*
+ * Release the controller from reset, if the DT tells us which pin that is.
+ * Only used when nothing answered on either address: the reset latches the
+ * I2C address from the INT level, which U-Boot does not drive, so it is a last
+ * resort rather than routine initialisation.
+ *
+ * Returns 0 when the line was driven, or a negative errno when the node or the
+ * property is missing.
+ */
+static int gt911_release_reset(void)
+{
+ struct gpio_desc reset;
+ int node, ret;
+
+ node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "goodix,gt911");
+ if (node < 0)
+ return -ENODEV;
+
+ ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpios",
+ 0, &reset, GPIOD_IS_OUT);
+ if (ret)
+ return ret;
+
+ /* Asserted, then released. dm_gpio_set_value() takes the LOGICAL level,
+ * so the DT's active-low flag is already accounted for here. */
+ dm_gpio_set_value(&reset, 1);
+ mdelay(GT911_RESET_HOLD_MS);
+ dm_gpio_set_value(&reset, 0);
+ mdelay(GT911_RESET_SETTLE_MS);
+
+ dm_gpio_free(NULL, &reset);
+ return 0;
+}
+
+/* The address the controller answered on, for the boot report. */
+static int gt911_addr;
+
+/* Find the controller at whichever address it is currently on. */
+static struct udevice *gt911_probe(void)
+{
+ static const int addrs[] = { GT911_ADDR_INT_HIGH, GT911_ADDR_INT_LOW };
+ struct udevice *dev;
+ u8 status;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(addrs); i++) {
+ if (i2c_get_chip_for_busnum(GT911_I2C_BUS, addrs[i], 2, &dev))
+ continue;
+ /* A successful read is the only proof the chip is really there:
+ * i2c_get_chip_for_busnum() will hand back a device for an
+ * address nothing answers on. */
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
+ continue;
+ gt911_addr = addrs[i];
+ return dev;
+ }
+
+ return NULL;
+}
+
+/* Probe, resetting only if nothing answers on either address. */
+static struct udevice *gt911_get(bool *did_reset)
+{
+ struct udevice *dev = gt911_probe();
+
+ if (!dev) {
+ gt911_release_reset();
+ if (did_reset)
+ *did_reset = true;
+ dev = gt911_probe();
+ }
+
+ return dev;
+}
+
+/* What arm() found and cleared, for the boot report. */
+static u8 gt911_arm_status;
+static bool gt911_armed;
+
+void flare_touch_arm(void)
+{
+ struct udevice *dev = gt911_get(NULL);
+ u8 status = 0;
+ u8 clear = 0;
+
+ if (!dev)
+ return;
+
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
+ return;
+
+ gt911_arm_status = status;
+ gt911_armed = true;
+
+ if (status & GT911_STATUS_READY) {
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
+ FLARE_TRACE("touch: cleared the power-on report");
+ }
+}
+
+int flare_touch_tapped(struct flare_touch_state *st)
+{
+ struct udevice *dev;
+ bool did_reset = false;
+ u8 status = 0;
+ u8 clear = 0;
+
+ if (st) {
+ st->addr = 0;
+ st->status = 0;
+ st->armed = false;
+ st->arm_status = 0;
+ st->id[0] = '\0';
+ }
+
+ /*
+ * Probe BEFORE resetting. The controller is normally already running by
+ * the time U-Boot gets here, and resetting a working one is not free:
+ * its I2C address is latched from the INT level while RESET is released,
+ * and U-Boot does not drive INT, so a reset can move the chip to the
+ * other address or leave it mid-init. Only reset when nothing answers.
+ */
+ dev = gt911_get(&did_reset);
+ if (!dev) {
+ FLARE_TRACE("touch: no GT911 on i2c3");
+ return 0;
+ }
+
+ if (st) {
+ st->armed = gt911_armed;
+ st->arm_status = gt911_arm_status;
+ st->addr = gt911_addr;
+ if (dm_i2c_read(dev, GT911_REG_ID, (u8 *)st->id, 4) == 0)
+ st->id[4] = '\0';
+ }
+
+ /*
+ * A single read. The report is latched: bit 7 stays set until the host
+ * writes the register back to 0, so this sees a touch that happened at
+ * any point since the controller came up, without watching for one.
+ */
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
+ return 0;
+ if (st)
+ st->status = status;
+
+ if (!(status & GT911_STATUS_READY))
+ return 0;
+
+ /*
+ * A report we produced ourselves is not a tap.
+ *
+ * Bringing the controller out of reset makes it publish a report, so on
+ * a panel whose GT911 does not answer until we reset it, EVERY boot
+ * latches one and every boot would come up verbose. MEASURED on the
+ * bench panel: it answers only at 0x5d after a reset, and reported
+ * status 0x80 on a boot nobody touched.
+ *
+ * Acknowledge it and report untouched. A panel in this state cannot
+ * report a tap made before we woke its controller either -- there was
+ * nothing listening to record it.
+ */
+ if (did_reset) {
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
+ FLARE_TRACE("touch: report discarded, we caused it");
+ return 0;
+ }
+
+ /* Acknowledge, so the same report cannot be read again next boot. */
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
+
+ /*
+ * A finger must be ON THE GLASS right now. The ready bit is not enough.
+ *
+ * MEASURED on the bench panel across cold boots nobody touched: the
+ * controller had a report waiting when the splash appeared (arm 0x80,
+ * cleared), and had published ANOTHER by the time this read ran
+ * (rd 0x80). It re-arms on its own, so "a report exists" is true on
+ * every boot and cannot mean "someone touched it". Only the point count
+ * distinguishes a finger from the controller talking to itself.
+ *
+ * The cost is that the touch has to be HELD across this sample rather
+ * than tapped and released, because catching a release would mean
+ * watching for one, and watching means adding that time to every boot.
+ * A press held through the splash is the reliable, free signal.
+ */
+ return (status & GT911_STATUS_NTOUCH) ? 1 : 0;
+}
@@ -0,0 +1,57 @@
diff --git a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
index 276fc6017..b9a66c416 100755
--- a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
+++ b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
@@ -76,7 +76,7 @@ int cmd_mgr_queue_force_defer(struct rwnx_cmd_mgr *cmd_mgr,
spin_lock_bh(&cmd_mgr->lock);
if (cmd_mgr->state == RWNX_CMD_MGR_STATE_CRASHED) {
- printk(KERN_CRIT "cmd queue crashed\n");
+ printk_ratelimited(KERN_CRIT "cmd queue crashed\n");
cmd->result = -EPIPE;
spin_unlock_bh(&cmd_mgr->lock);
return -EPIPE;
@@ -168,7 +168,7 @@ static int cmd_mgr_queue(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd)
}
if (cmd_mgr->state == RWNX_CMD_MGR_STATE_CRASHED) {
- printk(KERN_CRIT "cmd queue crashed\n");
+ printk_ratelimited(KERN_CRIT "cmd queue crashed\n");
cmd->result = -EPIPE;
spin_unlock_bh(&cmd_mgr->lock);
return -EPIPE;
@@ -260,10 +260,17 @@ static int cmd_mgr_queue(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd)
/* TODO: kill the cmd at fw level */
}
#else
+ /* flare-edge: queue_sz must never scale this to zero. A zero
+ * timeout makes wait_for_completion_timeout() return
+ * immediately, so the "timeout" path runs without ever
+ * waiting -- measured as ~2000 "cmd timed-out" per second
+ * (668349 in 319s), which saturates the console and takes the
+ * whole system down with it. Clamp to at least one. */
unsigned long tout = msecs_to_jiffies(
- RWNX_80211_CMD_TIMEOUT_MS * cmd_mgr->queue_sz);
+ RWNX_80211_CMD_TIMEOUT_MS *
+ max_t(u32, cmd_mgr->queue_sz, 1));
if (!wait_for_completion_timeout(&cmd->complete, tout)) {
- printk(KERN_CRIT "cmd timed-out\n");
+ printk_ratelimited(KERN_CRIT "cmd timed-out\n");
#ifdef AICWF_SDIO_SUPPORT
ret = aicwf_sdio_writeb(
sdiodev, sdiodev->sdio_reg.wakeup_reg, 2);
@@ -395,11 +402,12 @@ void cmd_mgr_task_process(struct work_struct *work)
#endif
kfree(next->a2e_msg);
+ /* flare-edge: see above -- never a zero timeout */
tout = msecs_to_jiffies(RWNX_80211_CMD_TIMEOUT_MS *
- cmd_mgr->queue_sz);
+ max_t(u32, cmd_mgr->queue_sz, 1));
if (!wait_for_completion_timeout(&next->complete,
tout)) {
- printk(KERN_CRIT "cmd timed-out\n");
+ printk_ratelimited(KERN_CRIT "cmd timed-out\n");
#ifdef AICWF_SDIO_SUPPORT
if (aicwf_sdio_writeb(
sdiodev,
@@ -0,0 +1,73 @@
diff --git a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
index 13005ac68..d28b7127a 100755
--- a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
+++ b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
@@ -1356,6 +1356,8 @@ int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
}
if (sdiodev->state == SDIO_SLEEP_ST) {
+ int woke = 0;
+
AICWFDBG(LOGSDPWRC, "%s w\n", __func__);
//rwnx_pm_stay_awake(sdiodev);
@@ -1379,21 +1381,53 @@ int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
txrx_err(
"sdio wakeup read fail\n");
else if ((val & 0x1) == 0) {
+ woke = 1;
break;
}
read_retry--;
- udelay(200);
+ /*
+ * flare-edge: sleep, do NOT udelay()
+ * here. This is a sleepable context
+ * (reached only under pwrctl_wakeup_sema
+ * from the bustx kthread), and that
+ * thread re-enters this path on every
+ * TX. A busy-wait therefore pins the
+ * single Cortex-A7 core whenever the
+ * SDIO link wedges, starving the UI
+ * render loop -- the "extremely laggy"
+ * failure. Sleeping frees the core.
+ */
+ usleep_range(200, 400);
}
- if (read_retry != 0)
+ if (woke)
break;
}
sdio_dbg("write retry: %d \n", write_retry);
write_retry--;
- udelay(100);
+ if (write_retry)
+ usleep_range(100, 200);
+ }
+
+ /*
+ * flare-edge: never fake SDIO_ACTIVE_ST on a failed wake. The
+ * stock driver advanced state unconditionally, so a wedged link
+ * looked "awake" and every later TX hammered a dead chip forever
+ * with no recovery. Advance state only when the chip actually
+ * acknowledged; otherwise stay SLEEP and report the error so the
+ * caller (and the reset-recovery path added in a later patch)
+ * can act on it.
+ */
+ if (woke) {
+ sdiodev->state = SDIO_ACTIVE_ST;
+ aicwf_sdio_pwrctl_timer(sdiodev,
+ sdiodev->active_duration);
+ ret = 0;
+ } else {
+ printk_ratelimited(
+ KERN_WARNING
+ "aic8800: SDIO wakeup failed; chip may be wedged\n");
+ ret = -1;
}
-
- sdiodev->state = SDIO_ACTIVE_ST;
- aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
}
return ret;
}
@@ -0,0 +1,31 @@
diff --git a/sysdrv/drv_ko/wifi/insmod_wifi.sh b/sysdrv/drv_ko/wifi/insmod_wifi.sh
index f34ae1581..c70664564 100755
--- a/sysdrv/drv_ko/wifi/insmod_wifi.sh
+++ b/sysdrv/drv_ko/wifi/insmod_wifi.sh
@@ -124,8 +124,23 @@ if [ -n "$(cat /proc/device-tree/model | grep "W")" ] || \
fi
#start wifi app
+#
+# flare-edge: rkwifi_server is deliberately NOT started. WardenOS owns wlan0
+# through warden-ui, which runs its own wpa_supplicant against
+# /userdata/warden/wpa_supplicant.conf.
+#
+# rkwifi_server starts "wpa_supplicant -B -i wlan0 -c /data/wpa_supplicant.conf"
+# using the stock config, whose network block is the vendor placeholder
+# ssid="Your wifi ssid". The radio then scans forever for a network that does
+# not exist while the real one sits at -50 dBm.
+#
+# warden-ui already does "killall rkwifi_server" before taking over, but that
+# does not kill the wpa_supplicant rkwifi_server spawned, and the UI guards its
+# own launch with `if ! pidof wpa_supplicant`. So the orphan survives, the
+# guard sees it, the UI never starts its own, and the saved credentials are
+# never used. Not starting the daemon removes the race entirely.
+#
+# Re-enable only if something other than warden-ui needs to own wlan0.
if ifconfig wlan0 2>&1 | grep -q "not found"; then
- echo "wlan0 not found. Stop run rkwifi_server."
-else
- rkwifi_server start >/dev/null 2>&1 &
+ echo "wlan0 not found."
fi
@@ -0,0 +1,59 @@
diff --git a/sysdrv/drv_ko/wifi/insmod_wifi.sh b/sysdrv/drv_ko/wifi/insmod_wifi.sh
--- a/sysdrv/drv_ko/wifi/insmod_wifi.sh
+++ b/sysdrv/drv_ko/wifi/insmod_wifi.sh
@@ -33,7 +33,26 @@
if [ $? -eq 0 ]; then
insmod cfg80211.ko
insmod aic_load_fw.ko aic_fw_path=/oem/usr/ko/
- insmod aic8800_fdrv.ko
+ # flare-edge: he_on=0 -- do NOT let this radio negotiate 802.11ax (HE).
+ #
+ # The AIC8800DC associates fine in HE and negotiates high HE-MCS rates, then
+ # silently loses the unicast path while every local indicator still reads
+ # healthy (wpa_state=COMPLETED, carrier 1, lease BOUND, strong signal). Only
+ # beacons and broadcast keep arriving. See flare-edge issue #156.
+ #
+ # Measured on warden-c8a3 against an 802.11ax AP: with HE on, the driver
+ # deinit/reconnect cycle fired every ~965 s indefinitely
+ # ("deinit:macaddr" -> "rwnx_send_sm_connect_req", 154 times in 2.8 days).
+ # he_on=0 makes the chip advertise HT/VHT only (phy reports "HE supp 0") and
+ # the cycle stops.
+ #
+ # This costs Wi-Fi 6 rates, which the radio was never actually delivering
+ # usable throughput at anyway, and costs no compatibility: 802.11ax APs serve
+ # n/ac clients normally, so the panel still joins modern networks.
+ #
+ # Remove only when the HE path is actually fixed in the driver or the AIC
+ # firmware blob, and re-verify with a multi-hour soak against an ax AP.
+ insmod aic8800_fdrv.ko he_on=0
insmod bcmdhd.ko
fi
@@ -117,7 +136,26 @@
insmod aes_generic.ko
insmod aic8800_bsp.ko
sleep 0.2
- insmod aic8800_fdrv.ko
+ # flare-edge: he_on=0 -- do NOT let this radio negotiate 802.11ax (HE).
+ #
+ # The AIC8800DC associates fine in HE and negotiates high HE-MCS rates, then
+ # silently loses the unicast path while every local indicator still reads
+ # healthy (wpa_state=COMPLETED, carrier 1, lease BOUND, strong signal). Only
+ # beacons and broadcast keep arriving. See flare-edge issue #156.
+ #
+ # Measured on warden-c8a3 against an 802.11ax AP: with HE on, the driver
+ # deinit/reconnect cycle fired every ~965 s indefinitely
+ # ("deinit:macaddr" -> "rwnx_send_sm_connect_req", 154 times in 2.8 days).
+ # he_on=0 makes the chip advertise HT/VHT only (phy reports "HE supp 0") and
+ # the cycle stops.
+ #
+ # This costs Wi-Fi 6 rates, which the radio was never actually delivering
+ # usable throughput at anyway, and costs no compatibility: 802.11ax APs serve
+ # n/ac clients normally, so the panel still joins modern networks.
+ #
+ # Remove only when the HE path is actually fixed in the driver or the AIC
+ # firmware blob, and re-verify with a multi-hour soak against an ax AP.
+ insmod aic8800_fdrv.ko he_on=0
sleep 2
insmod aic8800_btlpm.ko
sleep 0.1
+128
View File
@@ -0,0 +1,128 @@
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -247,6 +247,7 @@
struct device *dev;
struct regmap *grf;
struct regmap *usbgrf;
+ void __iomem *phy_base;
struct clk_bulk_data *clks;
struct clk *clk480m;
struct clk_hw clk480m_hw;
@@ -1417,6 +1418,19 @@
return -EINVAL;
}
+ /*
+ * RV1106 tunes signal quality through the PHY's own register block, which
+ * is this node's "reg" resource and is distinct from the GRF regmap above.
+ * Map it only where a tuning callback needs it; every other SoC here tunes
+ * through the GRF and must keep working with phy_base left NULL.
+ */
+ if (of_device_is_compatible(np, "rockchip,rv1106-usb2phy")) {
+ rphy->phy_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(rphy->phy_base))
+ return dev_err_probe(dev, PTR_ERR(rphy->phy_base),
+ "failed to map phy registers\n");
+ }
+
rphy->phy_reset = devm_reset_control_get_optional(dev, "phy");
if (IS_ERR(rphy->phy_reset))
return PTR_ERR(rphy->phy_reset);
@@ -1506,6 +1520,30 @@
return ret;
}
+/*
+ * Direct PHY-register accessors. Most SoCs here tune through the GRF regmap,
+ * but the RV1106's signal-quality registers live in the PHY's own block, which
+ * is mapped separately into rphy->phy_base.
+ */
+static inline void phy_update_bits(void __iomem *reg, u32 mask, u32 val)
+{
+ u32 tmp = readl(reg);
+
+ tmp &= ~mask;
+ tmp |= val & mask;
+ writel(tmp, reg);
+}
+
+static inline void phy_set_bits(void __iomem *reg, u32 bits)
+{
+ writel(readl(reg) | bits, reg);
+}
+
+static inline void phy_clear_bits(void __iomem *reg, u32 bits)
+{
+ writel(readl(reg) & ~bits, reg);
+}
+
static int rk3128_usb2phy_tuning(struct rockchip_usb2phy *rphy)
{
/* Turn off differential receiver in suspend mode */
@@ -2291,10 +2329,65 @@
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning is
* left off for now (guarded, so NULL is safe) — the phy is functional without it.
*/
+/*
+ * RV1106 USB2 PHY signal-quality tuning, ported from the vendor 5.10 driver
+ * (drivers/phy/rockchip/phy-rockchip-inno-usb2.c, rv1106_usb2phy_tuning).
+ *
+ * The 6.18 forward-port originally omitted this ("the phy is functional without
+ * it"). It is functional, but not reliable: with these registers left at reset
+ * defaults the HS link is electrically marginal under sustained traffic. On a
+ * bench panel a USB-Ethernet dongle would stall a bulk transfer after a few
+ * minutes; the r8152 Tx-timeout recovery then issues an xHCI Stop Endpoint
+ * command which the controller never answers, and xhci-hcd declares the
+ * controller dead and tears the bus down (flare-edge issue #160). Measured
+ * carrier-on to death across four runs: 14s, 519s, 521s, 584s -- a stochastic
+ * spread, not a timer, which is what marginal signalling looks like.
+ *
+ * Pre-emphasis strength is silicon-revision dependent. The vendor driver picks
+ * it from rockchip_get_cpu_version(), which does not exist in mainline; it
+ * derives from RV1106_OS_REG1 (0xff020204) & 0x7. Our panels read 1, i.e. the
+ * non-zero branch, so 3'b001 is pinned here. If a board ever reports version 0
+ * it wants 3'b011 instead -- see the vendor driver.
+ */
+static int rv1106_usb2phy_tuning(struct rockchip_usb2phy *rphy)
+{
+ /* Mapped only for this compatible; refuse to poke a NULL base. */
+ if (!rphy->phy_base)
+ return -ENODEV;
+
+ /* Always enable pre-emphasis in SOF & EOP & chirp & non-chirp state */
+ phy_update_bits(rphy->phy_base + 0x30, GENMASK(2, 0), 0x07);
+
+ /* Set Tx HS pre_emphasize strength to 3'b001 (cpu_version != 0) */
+ phy_update_bits(rphy->phy_base + 0x40, GENMASK(5, 3), (0x01 << 3));
+
+ /* Set RX Squelch trigger point configure to 4'b0000(112.5 mV) */
+ phy_update_bits(rphy->phy_base + 0x64, GENMASK(6, 3), (0x00 << 3));
+
+ /* Turn off differential receiver by default to save power */
+ phy_clear_bits(rphy->phy_base + 0x100, BIT(6));
+
+ /* Set 45ohm HS ODT value to 5'b10111 to increase driver strength */
+ phy_update_bits(rphy->phy_base + 0x11c, GENMASK(4, 0), 0x17);
+
+ /* Set Tx HS eye height tuning to 3'b011(462 mV) */
+ phy_update_bits(rphy->phy_base + 0x124, GENMASK(4, 2), (0x03 << 2));
+
+ /* Bypass Squelch detector calibration */
+ phy_update_bits(rphy->phy_base + 0x1a4, GENMASK(7, 4), (0x01 << 4));
+ phy_update_bits(rphy->phy_base + 0x1b4, GENMASK(7, 4), (0x01 << 4));
+
+ /* Set HS disconnect detect mode to single ended detect mode */
+ phy_set_bits(rphy->phy_base + 0x70, BIT(2));
+
+ return 0;
+}
+
static const struct rockchip_usb2phy_cfg rv1106_phy_cfgs[] = {
{
.reg = 0xff3e0000,
.num_ports = 1,
+ .phy_tuning = rv1106_usb2phy_tuning,
.clkout_ctl = { 0x0058, 4, 4, 1, 0 },
.port_cfgs = {
[USB2PHY_PORT_OTG] = {
+136
View File
@@ -0,0 +1,136 @@
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -203,6 +203,7 @@
* @event_nb: hold event notification callback.
* @state: define OTG enumeration states before device reset.
* @mode: the dr_mode of the controller.
+ * @host_mode: the port is currently acting as a USB host.
*/
struct rockchip_usb2phy_port {
struct phy *phy;
@@ -222,6 +223,7 @@
struct notifier_block event_nb;
enum usb_otg_state state;
enum usb_dr_mode mode;
+ bool host_mode;
};
/**
@@ -239,6 +241,8 @@
* @dcd_retries: The retry count used to track Data contact
* detection process.
* @edev: extcon device for notification registration
+ * @edev_self_allocated: no extcon phandle in DT, so the OTG state machine
+ * has no external role signal at all
* @irq: muxed interrupt for single irq configuration
* @phy_cfg: phy register configuration, assigned by driver data.
* @ports: phy port instance.
@@ -257,6 +261,7 @@
enum power_supply_type chg_type;
u8 dcd_retries;
struct extcon_dev *edev;
+ bool edev_self_allocated;
int irq;
const struct rockchip_usb2phy_cfg *phy_cfg;
struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS];
@@ -459,6 +464,14 @@
if (ret)
return dev_err_probe(rphy->dev, ret,
"failed to register extcon device\n");
+
+ /*
+ * Nothing external drives the role on this board. The extcon
+ * below is ours, and no code ever sets a cable state on it, so
+ * the OTG state machine's view of the world is permanently
+ * blank rather than merely stale.
+ */
+ rphy->edev_self_allocated = true;
}
rphy->edev = edev;
@@ -649,11 +662,52 @@
return 0;
}
+/*
+ * The OTG port's state machines only make sense while the port is a
+ * peripheral. In host role their inputs are meaningless on a board with no
+ * ID source: charger detection drives the analog front end of a port that is
+ * already enumerating a device, and its DCP verdict ends in
+ * rockchip_usb2phy_power_off(), which suspends the phy and drops the 480M
+ * clkout that the host controller's core runs on. The controller then stops
+ * clocking with its registers still readable, so it reports itself healthy
+ * while no transfer ever completes.
+ *
+ * dwc3 already calls phy_set_mode() on every role change, but this driver
+ * implemented no .set_mode, so the phy never learned the role. Track it and
+ * keep both state machines out of host role.
+ */
+static int rockchip_usb2phy_set_mode(struct phy *phy, enum phy_mode mode,
+ int submode)
+{
+ struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
+
+ if (rport->port_id != USB2PHY_PORT_OTG)
+ return 0;
+
+ switch (mode) {
+ case PHY_MODE_USB_HOST:
+ if (!rport->host_mode) {
+ rport->host_mode = true;
+ cancel_delayed_work_sync(&rport->otg_sm_work);
+ cancel_delayed_work_sync(&rport->chg_work);
+ }
+ break;
+ case PHY_MODE_USB_DEVICE:
+ rport->host_mode = false;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
static const struct phy_ops rockchip_usb2phy_ops = {
.init = rockchip_usb2phy_init,
.exit = rockchip_usb2phy_exit,
.power_on = rockchip_usb2phy_power_on,
.power_off = rockchip_usb2phy_power_off,
+ .set_mode = rockchip_usb2phy_set_mode,
.owner = THIS_MODULE,
};
@@ -667,6 +721,15 @@
unsigned long delay;
bool vbus_attach, sch_work, notify_charger;
+ /*
+ * This machine can only get the answer wrong here. In host role its
+ * verdict suspends a phy that is enumerating a device (#160); with a
+ * self-allocated extcon it has no role signal in EITHER direction, and
+ * in device role it strands the gadget the same way (#168).
+ */
+ if (rport->host_mode || rphy->edev_self_allocated)
+ return;
+
vbus_attach = property_enabled(rphy->grf,
&rport->port_cfg->utmi_bvalid);
@@ -825,6 +888,15 @@
bool is_dcd, tmout, vout, vbus_attach;
unsigned long delay;
+ /*
+ * Never probe the front end of a port that is hosting a device, and
+ * never at all on a board whose bvalid is pinned high by the VBUS
+ * bypass: charger detection cannot be meaningful there, and its DCP
+ * verdict powers the phy off underneath a working link (#160, #168).
+ */
+ if (rport->host_mode || rphy->edev_self_allocated)
+ return;
+
vbus_attach = property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid);
dev_dbg(&rport->phy->dev, "chg detection work state = %d\n",
+2
View File
@@ -18,6 +18,8 @@ with `../build/warden_defconfig` -> `zImage` + `rv1106-warden.dtb`).
| `15-pinctrl.patch` | `pinctrl-rockchip` RV1106 iomux |
| `20-arch-dts-bindings.patch` | `arch/arm` DTs (`rv1106.dtsi`, `rv1106-warden.dts`, pinctrl), mach, configs, `include/dt-bindings` |
| `25-usb-phy.patch` | inno-usb2 phy |
| `27-usb-phy-tuning.patch` | inno-usb2 phy: RV1106 signal-quality register tuning |
| `29-usb2phy-no-blind-otg-sm.patch` | inno-usb2 phy: stop the OTG/charger state machines running blind |
| `30-drm-vop-panel-rgb.patch` | VOP (`rgb_dclk_pol`=0 + WIN1 scanout), panel-simple bus-format, rockchip_rgb |
| `35-mailbox-hpmcu.patch` | rockchip-mailbox (rv1106 num_chans=1) |
| `40-pvtm-soc.patch` | PVTM (core+pmu) + `include/soc/rockchip/pvtm.h` |
+5
View File
@@ -85,6 +85,11 @@ does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
the executable bit, so the checked-out source file's own mode depends on the
checking-out umask and cannot be trusted to arrive non-world-readable.
A flow seed may contain `qemu-flow-setup.sh`. Stage-2 init runs it inside the
disposable guest after mounting userdata and before starting daemons or the
UI. A nonzero exit stops the boot. Use it only for test devices and commands
that the virt machine does not provide.
## Scenarios
All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
+52 -3
View File
@@ -106,8 +106,9 @@ if [ -n "${SEED_DIR:-}" ]; then
# on the first bad entry the same way --state fails closed above, rather
# than copy it into the image and let it surface as a confusing read
# later. Only a top-level plain file matches "one file per settings key"
# (the Env note above) -- seed-fixtures.py never nests a subdirectory, and
# neither should anything else pointed at this hook.
# (the Env note above), with one exception, profiles/rs485/<slug>.w485p
# (installed device profiles, checked below); seed-fixtures.py nests
# nothing else, and neither should anything else pointed at this hook.
#
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
@@ -126,6 +127,28 @@ if [ -n "${SEED_DIR:-}" ]; then
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
exit 1
fi
# The one directory allowed: installed RS485 device profiles, as
# warden-modbus keeps them (/userdata/warden/profiles/rs485/<slug>.w485p),
# so a flow can boot with a profile already installed (flare-edge#387).
# Nothing in it but plain <slug>.w485p files directly under rs485/.
if [ "$base" = profiles ] && [ -d "$entry" ]; then
while IFS= read -r -d '' p; do
rel="${p#"$entry"/}"
if [ "$rel" = rs485 ] && [ -d "$p" ] && [ ! -L "$p" ]; then continue; fi
case "$rel" in
rs485/*/*) ok=0 ;;
rs485/*.w485p) ok=1 ;;
*) ok=0 ;;
esac
name="${rel#rs485/}"
case "${name%.w485p}" in ''|*[!a-z0-9-]*) ok=0 ;; esac
if [ "$ok" -ne 1 ] || [ -L "$p" ] || [ ! -f "$p" ]; then
echo "FATAL: SEED_DIR entry 'profiles/$rel' is not a plain profiles/rs485/<slug>.w485p file" >&2
exit 1
fi
done < <(find "$entry" -mindepth 1 -print0)
continue
fi
[ -f "$entry" ] || {
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
exit 1
@@ -186,10 +209,16 @@ place_partition() {
# scenarios. Bytes mirror flare-edge tools/mk-misc.py provisioning
# defaults (A: prio 15 successful, B: prio 14 successful, CRC32-BE).
misc) stage="__misc__" ;;
# env carries a REAL U-Boot environment: flared clears bootcount there
# before an intentional reboot, and treats a zeroed (bad-CRC) env as
# "bookkeeping not durable", so a factory reset on the rig was always
# refused (flare-edge#62). Format mirrors flare-edge flared/src/envf.rs
# and tools/envf.py: LE CRC32 of the rest, NUL-separated entries.
env) stage="__env__" ;;
# Boot-chain partitions the VM never reads: present at the right offsets,
# left zeroed. Enumerated (not a wildcard) so a typo'd name in
# blkdevparts.conf fails HERE, not as a confusing mount error at boot.
env|idblock|uboot|boot_a|boot_b|recovery) stage="" ;;
idblock|uboot|boot_a|boot_b|recovery) stage="" ;;
*) echo "FATAL: unknown partition name '$name' in blkdevparts.conf" >&2; exit 1 ;;
esac
DISK_END_TRACK "$off" "$size"
@@ -220,6 +249,26 @@ PYMISC
qemu_log " $name: AvbABData provisioned @ +2048"
return 0
fi
if [ "$stage" = "__env__" ]; then
python3 - "$img" "$size" <<'PYENV'
import struct, sys, zlib
img, size = sys.argv[1], int(sys.argv[2])
ENV_SIZE = 0x8000 # CONFIG_ENV_SIZE; flared refuses any other length
if size < ENV_SIZE:
sys.exit(f"FATAL: env partition is {size} bytes, need {ENV_SIZE}")
body = bytearray(ENV_SIZE - 4)
entries = b"bootcount=0\0\0" # one entry, then the empty terminator
body[:len(entries)] = entries
env = struct.pack("<I", zlib.crc32(bytes(body)) & 0xFFFFFFFF) + bytes(body)
buf = bytearray(size)
buf[:ENV_SIZE] = env
open(img, "wb").write(buf)
PYENV
dd if="$img" of="$DISK" bs=4096 seek=$((off / 4096)) \
conv=notrunc,sparse status=none
qemu_log " $name: U-Boot env provisioned (bootcount=0)"
return 0
fi
mkfs_part "$stage" "$size" "$img"
dd if="$img" of="$DISK" bs=4096 seek=$((off / 4096)) \
conv=notrunc,sparse status=none
+21
View File
@@ -41,3 +41,24 @@ warden_slot() {
esac
echo "$slot"
}
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
# handler for. A panel's busybox init handles them; without this the rig
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
# the kernel still prints its orderly "reboot: Restarting system" line.
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
warden_trap_power_signals() {
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
}
# Idle forever in a way a trapped signal interrupts at once: a foreground
# `sleep` would hold the trap until it returned, up to an hour later.
warden_idle_forever() {
while :; do
sleep 3600 &
wait $!
done
}
+18 -6
View File
@@ -57,6 +57,16 @@ mount_fatal userdata /userdata
mount_fatal "oem${slot}" /oem
mkdir -p /userdata/warden
# A flow may seed an opt-in guest fixture before the UI and payload daemons
# start. The file lives only in this disposable QEMU disk image. Fail the
# boot if setup fails so a flow cannot pass against an unprepared guest.
if [ -f /userdata/warden/qemu-flow-setup.sh ]; then
if ! /bin/busybox sh /userdata/warden/qemu-flow-setup.sh; then
echo "FATAL: QEMU flow setup failed"
poweroff -f
fi
fi
# RS485: warden-modbus hardcodes /dev/ttyS4 at compile time; alias it to the
# VM's RS485 pci-serial UART (needs the virt.fragment kernel). run.sh lists
# the control channel's port first when there is one (warden.ctl on the
@@ -105,14 +115,14 @@ if grep -qw warden.fwapply /proc/cmdline; then
echo "init: OTA APPLY ENABLED (warden.fwapply)"
fi
# The same daemons the panel's SysV scripts start, in their S-number order
# (S92 ai, S93 automation, S94 modbus, S95 mikrotik, S96 asic/starlink/
# stratum, S97 flared), each with no arguments and no environment, exactly
# as start-stop-daemon runs them there. A daemon that cannot live on -M virt
# (S21 modbus, S22 automation, S92 ai, S95 mikrotik, S96 asic/starlink/
# stratum, S97 flared; flare-edge#348), each with no arguments and no
# environment, exactly as start-stop-daemon runs them there. A daemon that cannot live on -M virt
# (warden-ai wants the NPU) exits into its log and the UI shows the same
# "not running" it would show on a panel whose daemon died; that is the
# panel's behaviour, not a rig substitute for it. warden-watchdog stays out:
# it and a payload flared do not mix (README).
for d in /usr/bin/warden-ai /usr/bin/warden-automation /usr/bin/warden-modbus \
for d in /usr/bin/warden-modbus /usr/bin/warden-automation /usr/bin/warden-ai \
/usr/bin/warden-mikrotik /usr/bin/warden-asic /usr/bin/warden-starlink \
/usr/bin/warden-stratum /usr/bin/warden-flared; do
if [ -x "$d" ]; then
@@ -239,5 +249,7 @@ if grep -qw warden.shell /proc/cmdline; then
poweroff -f
fi
# Hold: daemons run, console idles, scenarios drive the VM from outside.
while :; do sleep 3600; done
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
warden_trap_power_signals
warden_idle_forever
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# The rig's /sbin/init starts the Warden daemons in the panel's S-number
# order (flare-edge#348): warden-modbus (S21modbus) before warden-automation
# (S22automation), since an automation's device command goes through
# warden-modbus, and both before the other app backends and flared. Reads
# the daemon list from the init script's own start loop.
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
INIT="$HERE/../rootfs/sbin/init"
FAIL=0
order=$(awk '
/^for d in \/usr\/bin\/warden-/ { on = 1 }
on {
last = ($0 ~ /; do$/)
for (i = 1; i <= NF; i++) if ($i ~ /^\/usr\/bin\/warden-/) { w = $i; sub(/;$/, "", w); print w }
if (last) exit
}' "$INIT")
want="/usr/bin/warden-modbus
/usr/bin/warden-automation
/usr/bin/warden-ai
/usr/bin/warden-mikrotik
/usr/bin/warden-asic
/usr/bin/warden-starlink
/usr/bin/warden-stratum
/usr/bin/warden-flared"
if [ "$order" = "$want" ]; then
echo "PASS: rig init starts the daemons in the panel's S-number order"
else
echo "FAIL: rig init daemon order differs from the panel's S-number order"
diff <(printf '%s\n' "$want") <(printf '%s\n' "$order")
FAIL=1
fi
exit "$FAIL"
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
# commands, idles it the way /sbin/init does, sends each signal and requires
# the matching action within two seconds. Each signal goes out only once the
# shell has its handler installed (SigCgt), so a slow start cannot turn the
# signal's default action into a false failure (bfe-core1106-sdk#22).
set -uo pipefail
# Job control: each case's shell leads its own process group, so cleanup can
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
# script's output pipe open for an hour when a case fails.
set -m
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d)" || exit 1
trap 'rm -rf "$WORK"' EXIT
FAIL=0
# Hang backstop for the handler install; a quiet host takes milliseconds.
TRAP_WAIT_S="${WARDEN_TEST_TRAP_WAIT_S:-10}"
# Succeeds once <pid> catches <signal>: its bit is set in /proc SigCgt.
catches() { # catches <pid> <signal name>
local mask num
mask="$(awk '/^SigCgt:/ { print $2 }' "/proc/$1/status" 2>/dev/null)"
num="$(kill -l "$2")" || return 1
[ -n "$mask" ] && (( (16#$mask >> (num - 1)) & 1 ))
}
# Waits up to TRAP_WAIT_S for <pid> to catch <signal>.
wait_trapped() { # wait_trapped <pid> <signal name>
local n=0 limit=$((TRAP_WAIT_S * 10))
until catches "$1" "$2"; do
[ "$n" -ge "$limit" ] && return 1
sleep 0.1; n=$((n + 1))
done
}
# <delay> holds the handler install back, as a loaded runner does.
run_case() { # run_case <signal> <expected marker> <label> [delay s]
local sig="$1" want="$2" label="$3" delay="${4:-0}" out="$WORK/$1.out"
: > "$out"
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
"$SH" -c "sleep $delay; . '$LIB'; warden_trap_power_signals; warden_idle_forever" &
local pid=$!
if ! wait_trapped "$pid" "$sig"; then
echo "[FAIL] $label (SIG$sig handler not installed within ${TRAP_WAIT_S} s)"
FAIL=1
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
return
fi
kill -"$sig" "$pid"
local n=0
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
sleep 0.1; n=$((n + 1))
done
if grep -qx "$want" "$out"; then
echo "[PASS] $label"
else
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
fi
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
}
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
# Regression for bfe-core1106-sdk#22: the old fixed 0.5 s sleep sent SIGTERM
# before this shell installed its trap, killing it with nothing written.
run_case TERM reboot "SIGTERM after a slow handler install still reboots" 1.5
# The wait itself must fail, not hang or pass, when no handler ever appears.
"$SH" -c 'sleep 3600' &
pid=$!
if TRAP_WAIT_S=1 wait_trapped "$pid" TERM; then
echo "[FAIL] wait_trapped reported a handler a plain shell never installs"; FAIL=1
else
echo "[PASS] wait_trapped gives up on a shell without a handler"
fi
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
exit "$FAIL"
+128 -14
View File
@@ -154,7 +154,13 @@ def _load_imgtools():
AXIS_MAX = 32767
TAP_HOLD_S = 0.35
TAP_OBSERVE_TIMEOUT_S = 2.0
# How long the runner waits for the guest to count an injected press or
# release. A behaviour check, not a budget: a loaded runner (two TCG VMs on a
# shared host) has taken longer than 2 s to count the release that opens the
# drawer (flare-edge#1138), so the wait is a hang backstop. A wait longer than
# INPUT_SLOW_NOTE_S still passes and says so in the step's detail.
TAP_OBSERVE_TIMEOUT_S = 20.0
INPUT_SLOW_NOTE_S = 2.0
# Bounds every blocking read on the QMP socket -- the greeting banner, the
# qmp_capabilities handshake, and every screendump/tap/quit round trip --
@@ -223,19 +229,36 @@ def do_tap(s, f, ax, ay, hold=TAP_HOLD_S):
def wait_input_count(ctx, field, before):
"""Wait until one guest input counter advances."""
"""Wait until one guest input counter advances.
Records the longest wait of the current verb in ctx.input_wait_s, so a
slow guest shows in the results without failing the step."""
if before is None:
time.sleep(0.05)
return True
deadline = time.monotonic() + TAP_OBSERVE_TIMEOUT_S
start = time.monotonic()
deadline = start + TAP_OBSERVE_TIMEOUT_S
while time.monotonic() < deadline:
now = parse_stats(ctx.ctl.send("stats")).get(field)
if now is not None and now != before:
waited = time.monotonic() - start
ctx.input_wait_s = max(getattr(ctx, "input_wait_s", 0.0), waited)
return True
time.sleep(0.02)
return False
def input_verdict(ctx, observed):
"""The (status, detail) of a tap, swipe or fling from its observation."""
if not observed:
return ("fail", "input press or release was not consumed within "
f"{TAP_OBSERVE_TIMEOUT_S:g} seconds")
waited = getattr(ctx, "input_wait_s", 0.0)
if waited > INPUT_SLOW_NOTE_S:
return "ok", f"slow guest: input consumed after {waited:.1f} s"
return "ok", ""
def do_observed_tap(ctx, ax, ay):
"""Wait until the guest consumes both halves of a tap."""
before = parse_stats(ctx.ctl.send("stats"))
@@ -244,6 +267,7 @@ def do_observed_tap(ctx, ax, ay):
return True
send_events(ctx.s, ctx.f, [abs_ev("x", ax), abs_ev("y", ay), btn_ev(True)])
ctx.tap_sent = True
pressed = False
try:
pressed = wait_input_count(ctx, "presses", before.get("presses"))
@@ -716,7 +740,9 @@ class Ctx:
need_ctl, need_imgtools and fresh_region move here since verb handlers,
not drive(), are what call them now). One instance per run."""
def __init__(self, s, f, size, ctl, refs, refs_path, rs485_control, outdir, script_path):
def __init__(self, s, f, size, ctl, refs, refs_path, rs485_control, outdir, script_path,
console_path=None):
self.console_path = console_path
self.s = s
self.f = f
self.size = size
@@ -726,6 +752,12 @@ class Ctx:
self.rs485_control = rs485_control
self.outdir = outdir
self.script_path = script_path
# Set by drive() before each step: the command after this one, and the
# console size when the step before this one began (flare-edge#233).
self.next_cmd = None
self.prev_step_console = 0
# The longest input-count wait of the current tap, swipe or fling.
self.input_wait_s = 0.0
def need_ctl(self, lineno, cmd):
if self.ctl is None:
@@ -784,24 +816,36 @@ def verb_shot(ctx, lineno, cmd, args, line):
def verb_tap(ctx, lineno, cmd, args, line):
x, y = int(args[0]), int(args[1])
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
ctx.tap_sent = False
ctx.input_wait_s = 0.0
try:
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
except (RuntimeError, OSError):
# A tap whose correct outcome is a reboot (the next step is
# expect_reboot) can lose the control channel while its press/release
# counts are still being polled: init tears warden-ui down first. Once
# the press went out that is the tap working, not failing; the reboot
# step judges the outcome (flare-edge#233). Anywhere else, or before
# anything was sent, it stays a fatal step.
if ctx.next_cmd == "expect_reboot" and ctx.tap_sent:
return "ok", "tap sent; the control channel closed as the guest went down"
raise
return input_verdict(ctx, observed)
def verb_swipe(ctx, lineno, cmd, args, line):
ms = int(args[4]) if len(args) > 4 else 400
ctx.input_wait_s = 0.0
observed = do_observed_swipe(
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms)
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
return input_verdict(ctx, observed)
def verb_fling(ctx, lineno, cmd, args, line):
ctx.input_wait_s = 0.0
observed = do_observed_swipe(
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms=120)
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
return input_verdict(ctx, observed)
def verb_sleep(ctx, lineno, cmd, args, line):
@@ -809,6 +853,62 @@ def verb_sleep(ctx, lineno, cmd, args, line):
return "ok", ""
REBOOT_MARKER = b"reboot: Restarting system"
PANIC_MARKER = b"Kernel panic"
def verb_expect_reboot(ctx, lineno, cmd, args, line):
"""expect_reboot TIMEOUT_S: the guest reboots, in an orderly way, within
TIMEOUT_S seconds (flare-edge#62). For an action whose correct outcome IS a
reboot (factory reset, Reboot, the A/B Boot button), which used to be
untestable here: run.sh boots with -no-reboot, so the reboot ends the VM.
Passes only when both hold: the console shows the kernel's orderly restart
line, written after this step began, and QEMU is gone (QMP closed or
reporting shutdown). A kernel panic, a VM that exits without the orderly
line, and a VM still running at the deadline all fail. It must be a
script's last command: nothing can run on a VM that has left."""
timeout = float(args[0])
if not ctx.console_path:
sys.exit(f"FATAL: {ctx.script_path}:{lineno}: '{cmd}' needs --console")
# From the start of the step BEFORE this one, not this one: the action
# that reboots (a tap, usually) runs in that step, and a fast guest can
# print its restart line before expect_reboot even begins (flare-edge#233).
# A line from any earlier step still does not count.
start = ctx.prev_step_console
deadline = time.monotonic() + timeout
def console_since_start():
try:
with open(ctx.console_path, "rb") as fh:
fh.seek(start)
return fh.read()
except OSError:
return b""
while True:
try:
gone = rpc(ctx.s, ctx.f, {"execute": "query-status"}).get("status") == "shutdown"
except (RuntimeError, OSError, ValueError):
gone = True
# Read the console AFTER asking whether QEMU is gone: the guest's last
# lines (the restart line, or a panic) arrive just before it exits,
# and a read taken first would judge a finished reboot on stale text.
tail = console_since_start()
if PANIC_MARKER in tail:
return "fail", "kernel panic, not an orderly reboot"
restarted = REBOOT_MARKER in tail
if gone:
if restarted:
return "ok", ""
return "fail", "the VM exited without the kernel's orderly restart line"
if time.monotonic() >= deadline:
if restarted:
return "fail", f"the guest restarted but QEMU was still running after {timeout:g}s"
return "fail", f"no reboot within {timeout:g}s"
time.sleep(0.2)
def verb_echo(ctx, lineno, cmd, args, line):
print(f" [{lineno}] {' '.join(args)}", flush=True)
return None
@@ -1098,6 +1198,7 @@ VERBS = {
"assert_region": verb_assert_region,
"wait_region": verb_wait_region,
"assert_ocr": verb_assert_ocr,
"expect_reboot": verb_expect_reboot,
}
@@ -1120,15 +1221,28 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
print(f" [{lineno}] {tag}{cmd}{(' -- ' + detail) if detail else ''}", flush=True)
refs_path = refs_path or os.path.join(outdir, "refs.json")
ctx = Ctx(s, f, size, ctl, load_refs(refs_path), refs_path, rs485_control, outdir, script_path)
ctx = Ctx(s, f, size, ctl, load_refs(refs_path), refs_path, rs485_control, outdir, script_path,
console_path)
console = ConsoleWatch(console_path)
def console_size():
try:
return os.path.getsize(console_path) if console_path else 0
except OSError:
return 0
steps = []
for lineno, raw in enumerate(lines, 1):
line = raw.split("#", 1)[0].strip()
if not line:
continue
if line:
steps.append((lineno, line))
step_console = console_size()
for i, (lineno, line) in enumerate(steps):
parts = line.split()
cmd, args = parts[0], parts[1:]
ctx.next_cmd = steps[i + 1][1].split()[0] if i + 1 < len(steps) else None
ctx.prev_step_console, step_console = step_console, console_size()
handler = VERBS.get(cmd)
if handler is None:
+37
View File
@@ -186,5 +186,42 @@ else
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
fi
# --- scenario 7: an installed RS485 profile, profiles/rs485/<slug>.w485p,
# seeds into userdata/warden/profiles/rs485/ (flare-edge#387) ---
SEED7="$SCRATCH/seed7"
mkdir -p "$SEED7/profiles/rs485"
printf '{"w485p_version":1}\n' > "$SEED7/profiles/rs485/acme-gen-ctl.w485p"
OUT7="$SCRATCH/out7"
if OUT="$OUT7" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED7" \
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage7.log" 2>&1; then
UIMG7="$SCRATCH/userdata7.img"
extract_userdata "$OUT7/disk.img" "$UIMG7"
prof="$(debugfs -R "cat /warden/profiles/rs485/acme-gen-ctl.w485p" "$UIMG7" 2>/dev/null)"
if [ "$prof" = '{"w485p_version":1}' ]; then
pass "SEED_DIR: an installed profile seeds into profiles/rs485/"
else
fail "SEED_DIR: profiles/rs485/acme-gen-ctl.w485p = '$prof'"
fi
else
fail "SEED_DIR: mkimage.sh rejected a profiles/rs485/<slug>.w485p seed (see $SCRATCH/mkimage7.log)"
fi
# --- scenario 8: anything else under profiles/ fails closed ---
for bad in "rs485/x.json" "rs485/Bad.w485p" "other/x.w485p" "rs485/sub/x.w485p" "rs485/link.w485p"; do
SEED8="$SCRATCH/seed8"
rm -rf "$SEED8"
mkdir -p "$SEED8/profiles/$(dirname "$bad")"
if [ "$bad" = rs485/link.w485p ]; then ln -s /etc/passwd "$SEED8/profiles/$bad"; else printf 'x\n' > "$SEED8/profiles/$bad"; fi
OUT8="$SCRATCH/out8"
rm -rf "$OUT8"
err8="$(OUT="$OUT8" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED8" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
rc8=$?
if [ "$rc8" -ne 0 ] && printf '%s' "$err8" | grep -qF "is not a plain profiles/rs485/<slug>.w485p file"; then
pass "SEED_DIR: profiles/$bad fails closed"
else
fail "SEED_DIR: profiles/$bad gave rc=$rc8, stderr='$err8'"
fi
done
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
[ "$FAIL" -eq 0 ]
+40 -24
View File
@@ -98,15 +98,21 @@ printf '#!/usr/bin/env python3\nimport sys; sys.exit(1)\n' > "$FLARE_EDGE/tools/
# without a subshell: run_rig's RIG_OUT/RIG_RC writes land here directly, so
# nothing needs to be re-serialized as text and re-parsed back out below.
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK='' run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)" \
|| fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared' \
&& pass "case A: FATAL names the missing rs.sock" \
|| fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:' \
&& fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT" \
|| pass "case A: never claims the bus is live"
if [ "$RIG_RC" -ne 0 ]; then
pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)"
else
fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared'; then
pass "case A: FATAL names the missing rs.sock"
else
fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:'; then
fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT"
else
pass "case A: never claims the bus is live"
fi
# --- case B: rs.sock is up but socat never creates rs.pty -------------------
work="$SCRATCH/b"; build_rig "$work"
@@ -117,12 +123,16 @@ FAKEBIN="$SCRATCH/fakebin-b"; mkdir -p "$FAKEBIN"
printf '#!/usr/bin/env bash\necho "FAKE SOCAT: simulated failure" >&2\nexit 1\n' > "$FAKEBIN/socat"
chmod +x "$FAKEBIN/socat"
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 PATH="$FAKEBIN:$PATH" run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)" \
|| fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty' \
&& pass "case B: FATAL names the missing rs.pty" \
|| fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
if [ "$RIG_RC" -ne 0 ]; then
pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)"
else
fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty'; then
pass "case B: FATAL names the missing rs.pty"
else
fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
fi
# --- case C: rs.sock+rs.pty are up but mbsim.py crashes before rs.ctl -------
work="$SCRATCH/c"; build_rig "$work"
@@ -135,15 +145,21 @@ sys.stderr.write("FAKE MBSIM: simulated crash before opening the control socket\
sys.exit(1)
EOS
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 TEST_MBSIM_PID_FILE='' run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)" \
|| fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up' \
&& pass "case C: FATAL names the dead simulator" \
|| fail "case C: FATAL names the dead simulator: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash' \
&& pass "case C: mbsim.log is dumped on failure" \
|| fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
if [ "$RIG_RC" -ne 0 ]; then
pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)"
else
fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up'; then
pass "case C: FATAL names the dead simulator"
else
fail "case C: FATAL names the dead simulator: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash'; then
pass "case C: mbsim.log is dumped on failure"
else
fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
fi
# --- case D: a sim process that ignores SIGTERM is still reaped ------------
work="$SCRATCH/d"; build_rig "$work"
+174
View File
@@ -339,6 +339,52 @@ class PureHelpers(unittest.TestCase):
self.assertEqual(len(calls), 2)
self.assertEqual(calls[-1], [qmp.btn_ev(False)])
def _swipe_on_fake_clock(self, release_at_s):
"""verb_swipe against a guest that counts the press at once and the
release only once release_at_s of fake time has passed (None: never).
Returns the verdict and the fake time the verb took."""
clock = [0.0]
replies = iter(["presses: 0\nreleases: 0"]) # the baseline read
def send(cmd):
late = release_at_s is not None and clock[0] >= release_at_s
return next(replies, f"presses: 1\nreleases: {1 if late else 0}")
ctx = SimpleNamespace(s=None, f=None, size=720,
ctl=SimpleNamespace(send=send), input_wait_s=0.0)
def sleep(seconds):
clock[0] += seconds
saved = qmp.send_events, qmp.time.sleep, qmp.time.monotonic
qmp.send_events = lambda _s, _f, _events: None
qmp.time.sleep = sleep
qmp.time.monotonic = lambda: clock[0]
try:
verdict = qmp.verb_swipe(ctx, 1, "swipe", ["2", "350", "520", "352", "3000"], "")
finally:
qmp.send_events, qmp.time.sleep, qmp.time.monotonic = saved
return verdict, clock[0]
def test_swipe_release_counted_late_on_a_loaded_guest_passes(self):
# flare-edge#1138: the release that opens the drawer was counted
# after more than 2 s on a loaded runner; the old 2 s bound failed
# the swipe although the guest handled it. It passes, with a note.
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 2.5)
self.assertEqual(status, "ok")
self.assertIn("slow guest: input consumed after 2.5 s", detail)
def test_swipe_release_counted_promptly_has_no_note(self):
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 0.5)
self.assertEqual((status, detail), ("ok", ""))
def test_swipe_release_never_counted_fails_at_the_backstop(self):
(status, detail), took = self._swipe_on_fake_clock(release_at_s=None)
self.assertEqual(status, "fail")
self.assertIn(f"within {qmp.TAP_OBSERVE_TIMEOUT_S:g} seconds", detail)
# Bounded: the 3 s drag plus the backstop, and not much more.
self.assertLess(took, 3.0 + qmp.TAP_OBSERVE_TIMEOUT_S + 1.0)
def test_every_pixel_round_trips_through_lvgl_calibration(self):
# lv_evdev.c _evdev_calibrate: px = axis * (width - 1) / AXIS_MAX,
# integer division. A tap requested at px must land at px, for every
@@ -858,6 +904,134 @@ class DriveConsoleCheck(unittest.TestCase):
self.assertTrue(all(r["line"] == 1 for r in rows))
class ExpectReboot(unittest.TestCase):
"""expect_reboot (flare-edge#62): an action whose correct outcome is a
reboot ends the VM on this rig (-no-reboot), so the reboot itself is the
thing to assert. QEMU's behaviour is scripted through the fake rpc: each
query-status call can append console output and then report the VM gone."""
def run_reboot(self, steps, before=b"", timeout="2"):
d = tempfile.mkdtemp(prefix="console.")
console = os.path.join(d, "console.log")
with open(console, "wb") as fh:
fh.write(before)
calls = []
def rpc(sock, sock_file, obj):
if obj.get("execute") != "query-status":
return fake_rpc(sock, sock_file, obj)
step = steps[min(len(calls), len(steps) - 1)]
calls.append(step)
text, state = step
if text:
with open(console, "ab") as fh:
fh.write(text)
if state == "gone":
raise RuntimeError("QMP connection closed")
return {"status": state}
return run_script(f"expect_reboot {timeout}\n", rpc_fn=rpc, console_path=console)
def test_orderly_reboot_passes(self):
rc, by, rows = self.run_reboot([
(b"", "running"),
(b"[ 12.3] reboot: Restarting system\n", "running"),
(b"", "gone"),
])
self.assertIsNone(rc)
self.assertEqual(rows[-1]["status"], "ok", rows)
def test_qmp_reporting_shutdown_counts_as_gone(self):
rc, by, rows = self.run_reboot([(b"reboot: Restarting system\n", "shutdown")])
self.assertEqual(rows[-1]["status"], "ok", rows)
def test_no_reboot_before_the_deadline_fails(self):
rc, by, rows = self.run_reboot([(b"", "running")], timeout="0.5")
self.assertEqual(rc, 1)
self.assertIn("no reboot within", rows[-1]["detail"])
def test_a_kernel_panic_is_not_a_reboot(self):
rc, by, rows = self.run_reboot([
(b"Kernel panic - not syncing: Attempted to kill init!\n"
b"reboot: Restarting system\n", "gone"),
])
self.assertEqual(rc, 1)
self.assertIn("kernel panic", rows[-1]["detail"])
def test_exiting_without_the_orderly_line_fails(self):
rc, by, rows = self.run_reboot([(b"", "gone")])
self.assertEqual(rc, 1)
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
def test_a_restart_line_from_before_the_step_does_not_count(self):
rc, by, rows = self.run_reboot([(b"", "gone")],
before=b"reboot: Restarting system\n")
self.assertEqual(rc, 1)
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
class RebootTapRace(unittest.TestCase):
"""flare-edge#233: a tap whose outcome is a reboot races init tearing
warden-ui down. The control channel can close while the tap's press and
release counts are still being polled, and the guest can print its restart
line before expect_reboot starts. Both are the tap working."""
CONSOLE_LINE = b"init: reboot requested\n[ 17.8] reboot: Restarting system\n"
def run_race(self, script, console_before=b""):
d = tempfile.mkdtemp(prefix="console.")
console = os.path.join(d, "console.log")
with open(console, "wb") as fh:
fh.write(console_before)
line = self.CONSOLE_LINE
class RebootingCtl(FakeCtl):
"""First stats answers (the tap's baseline); the next one, the
press poll, finds the guest already going down: the restart line
is on the console and the channel is closed."""
def send(self, cmd):
if cmd == "stats" and self.stats_calls >= 1:
with open(console, "ab") as fh:
fh.write(line)
raise RuntimeError("control channel closed")
return super().send(cmd)
def rpc(sock, sock_file, obj):
if obj.get("execute") == "query-status":
raise RuntimeError("QMP connection closed")
return fake_rpc(sock, sock_file, obj)
return run_script(script, ctl_cls=RebootingCtl, rpc_fn=rpc, console_path=console)
def test_reboot_tap_losing_the_channel_then_expect_reboot_passes(self):
rc, by, rows = self.run_race("tap 10 10\nexpect_reboot 2\n")
self.assertIsNone(rc, rows)
self.assertEqual([r["status"] for r in rows], ["ok", "ok"], rows)
self.assertIn("control channel closed", rows[0]["detail"])
def test_the_same_channel_loss_before_any_other_step_is_still_fatal(self):
rc, by, rows = self.run_race("tap 10 10\nsleep 0\n")
self.assertEqual(rows[0]["status"], "fatal", rows)
def test_a_restart_line_from_two_steps_back_still_does_not_count(self):
# The restart line is already on the console before the script; the
# reboot step may look back one step, not to the start of the run.
d = tempfile.mkdtemp(prefix="console.")
console = os.path.join(d, "console.log")
with open(console, "wb") as fh:
fh.write(b"reboot: Restarting system\n")
def rpc(sock, sock_file, obj):
if obj.get("execute") == "query-status":
raise RuntimeError("QMP connection closed")
return fake_rpc(sock, sock_file, obj)
rc, by, rows = run_script("sleep 0\nexpect_reboot 1\n", rpc_fn=rpc,
console_path=console)
self.assertEqual(rc, 1)
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
class FullscreenToggleTracksRealState(unittest.TestCase):
"""qemu/tests/scripts/fullscreen-toggle-tracks-real-state.txt, offline:
`home` clears the dashboard's real fullscreen state directly, and a
+1 -1
View File
@@ -195,7 +195,7 @@ if [ -n "$RS485_DEVICES" ]; then
# simulator the serial device it expects; mbsim then answers the guest's
# Modbus polls with the corpus profiles' own register maps.
command -v socat >/dev/null || { echo "FATAL: --rs485-devices needs socat" >&2; exit 1; }
[ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ] || {
{ [ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ]; } || {
echo "FATAL: --rs485-devices needs FLARE_EDGE to point at a flare-edge checkout (mbsim.py)" >&2; exit 1; }
wait_for_path "$WORK/rs.sock"
[ -S "$WORK/rs.sock" ] || {
+1
View File
@@ -37,6 +37,7 @@ scripts=(
"qemu/tests/stage-rootfs-perms.sh"
"tests/fetch-vendor/run-fetch-vendor-tests.sh"
"tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh"
"tests/unpack-buildroot/run-unpack-buildroot-tests.sh"
"tests/mk-bootimg/run-boot-img-validate-tests.sh"
"tests/mk-bootimg/run-help-tests.sh"
"tests/mk-bootimg/run-ci-wiring-tests.sh"
+138
View File
@@ -0,0 +1,138 @@
#!/usr/bin/env bash
# Regression tests for build/unpack-buildroot.sh (blueflare/bfe-core1106-sdk#4).
#
# A clean vendor checkout plus luckfox-sdk-patches/ could not build WardenOS
# because nothing put buildroot-2025.02.8 where the SDK builds it. The unpack
# script is now the thing that does, and the persistent CI SDK depends on it
# leaving an existing tree alone. These cases pin both halves: a fresh SDK
# gets a complete tree, an existing tree is never touched or re-fetched, and
# every refusal (unpatched selectors, a bad tarball, a half-present tree, a
# failed fetch) leaves no tree and no scratch directory behind.
#
# Runs the real script, copied beside a stub fetch-buildroot-tarball.sh that
# copies a local fixture tarball instead of downloading. No network, no SDK.
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$HERE/../../build/unpack-buildroot.sh"
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
FAIL=0
ok() { printf '[PASS] %s\n' "$1"; }
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
TMP="$(mktemp -d)" || { echo "FAIL: mktemp -d failed"; exit 1; }
[ -d "$TMP" ] || { echo "FAIL: mktemp -d failed"; exit 1; }
trap 'rm -rf "$TMP"' EXIT
VER=2025.02.8
# Fixture tarballs: a minimal Buildroot-shaped tree, and one without Makefile.
mk_tarball() { # mk_tarball <out.tar.xz> <with-makefile:0|1>
local out="$1" mf="$2" src
src="$(mktemp -d "$TMP/src.XXXXXX")"
mkdir -p "$src/buildroot-$VER/configs" "$src/buildroot-$VER/package/busybox"
printf 'CONFIG\n' > "$src/buildroot-$VER/package/busybox/busybox.config"
[ "$mf" = 1 ] && printf 'all:\n' > "$src/buildroot-$VER/Makefile"
tar -cJf "$out" -C "$src" "buildroot-$VER"
}
mk_tarball "$TMP/good.tar.xz" 1
mk_tarball "$TMP/nomakefile.tar.xz" 0
# setup <case> <tarball-or-FAIL> -> fixture dir holding build/ and sdk/
setup() {
local dir="$TMP/$1" src="$2"
mkdir -p "$dir/build" "$dir/sdk/project" "$dir/sdk/sysdrv/source/buildroot"
cp "$SCRIPT" "$dir/build/unpack-buildroot.sh"
{
echo '#!/usr/bin/env bash'
echo "BRVER=$VER"
echo "echo fetch-called >> \"$dir/fetch-calls\""
if [ "$src" = FAIL ]; then echo 'exit 1'; else echo "cp \"$src\" \"\$1\""; fi
} > "$dir/build/fetch-buildroot-tarball.sh"
# shellcheck disable=SC2016 # build.sh carries the literal text
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-%s\n' "$VER" \
> "$dir/sdk/project/build.sh"
printf 'BUILDROOT_VER ?= buildroot-%s\n' "$VER" > "$dir/sdk/sysdrv/Makefile"
printf '%s' "$dir"
}
run() { # run <dir> -> $OUT, $RC
OUT="$(bash "$1/build/unpack-buildroot.sh" "$1/sdk" 2>&1)"; RC=$?
}
tree() { printf '%s' "$1/sdk/sysdrv/source/buildroot/buildroot-$VER"; }
fetches() { [ -f "$1/fetch-calls" ] && wc -l < "$1/fetch-calls" || echo 0; }
no_scratch() { ! compgen -G "$1/sdk/sysdrv/source/buildroot/.unpack-buildroot.*" >/dev/null; }
# A. Fresh SDK: fetched once, unpacked to the selected path, no scratch left.
d="$(setup fresh "$TMP/good.tar.xz")"; run "$d"
if [ "$RC" -eq 0 ] && [ -f "$(tree "$d")/Makefile" ] && [ -f "$(tree "$d")/package/busybox/busybox.config" ] \
&& [ "$(fetches "$d")" -eq 1 ] && no_scratch "$d"; then
ok "fresh SDK: tree unpacked, one fetch, no scratch left"
else
bad "fresh SDK: tree unpacked, one fetch, no scratch left (rc=$RC, out=$OUT)"
fi
# B. Rerun on that SDK: already present, no second fetch, content untouched.
printf 'LOCAL\n' > "$(tree "$d")/package/busybox/busybox.config"
run "$d"
if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q 'tree already present' \
&& [ "$(fetches "$d")" -eq 1 ] && grep -qx LOCAL "$(tree "$d")/package/busybox/busybox.config"; then
ok "existing tree: left alone, not re-fetched"
else
bad "existing tree: left alone, not re-fetched (rc=$RC, out=$OUT)"
fi
# C. project/build.sh still selects the vendor tree: refuse, fetch nothing.
d="$(setup unpatched-build "$TMP/good.tar.xz")"
# shellcheck disable=SC2016 # build.sh carries the literal text
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6\n' > "$d/sdk/project/build.sh"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'project/build.sh selects' \
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
ok "unpatched project/build.sh: refused before fetching"
else
bad "unpatched project/build.sh: refused before fetching (rc=$RC, out=$OUT)"
fi
# D. sysdrv/Makefile still selects the vendor tree: refuse, fetch nothing.
d="$(setup unpatched-make "$TMP/good.tar.xz")"
printf 'BUILDROOT_VER ?= buildroot-2023.02.6\n' > "$d/sdk/sysdrv/Makefile"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'sysdrv/Makefile selects' \
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
ok "unpatched sysdrv/Makefile: refused before fetching"
else
bad "unpatched sysdrv/Makefile: refused before fetching (rc=$RC, out=$OUT)"
fi
# E. Tarball without a Buildroot Makefile: refuse, no tree, no scratch.
d="$(setup bad-tarball "$TMP/nomakefile.tar.xz")"; run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'did not contain' \
&& [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
ok "tarball without Makefile: refused, nothing left behind"
else
bad "tarball without Makefile: refused, nothing left behind (rc=$RC, out=$OUT)"
fi
# F. A half-present tree (an interrupted hand unpack): refuse, keep it as is.
d="$(setup half-tree "$TMP/good.tar.xz")"
mkdir -p "$(tree "$d")/output"; printf 'keep\n' > "$(tree "$d")/output/marker"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'not a complete Buildroot tree' \
&& [ -f "$(tree "$d")/output/marker" ] && [ "$(fetches "$d")" -eq 0 ]; then
ok "half-present tree: refused and left untouched"
else
bad "half-present tree: refused and left untouched (rc=$RC, out=$OUT)"
fi
# G. Fetch fails (network down, sha256 mismatch): nonzero, no tree.
d="$(setup fetch-fails FAIL)"; run "$d"
if [ "$RC" -ne 0 ] && [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
ok "failed fetch: nonzero, no tree"
else
bad "failed fetch: nonzero, no tree (rc=$RC, out=$OUT)"
fi
if [ "$FAIL" -eq 0 ]; then echo "ALL UNPACK-BUILDROOT TESTS PASSED"; else echo "UNPACK-BUILDROOT TESTS FAILED"; fi
exit "$FAIL"