diff --git a/AGENTS.md b/AGENTS.md index 08de58a..1bd78d5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -80,8 +80,10 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, ` external reset. The shared PWM is active-low for the cover and active-high for the main panel: duty 0 lights the cover, duty 14 lights the internal panel. Keep the exact vendor external init firmware, the debugfs command replay, the gpio23 reset pulse, `/run/bananarchy/cover-backlight` (`1` = cover lit, `0` = cover dark), - `kernel_power_sync_helper` and the `/run/bananarchy/cover-bl-force` nested-udev guard. On open, restore - gpio13 low, duty 14, `bl_power=0`, DPMS On and re-init the internal panel. The legacy 8-bit/9-bit userspace paths, `PROBE` and `bananarchy-cover-probe.sh` remain + `kernel_power_sync_helper` and the `/run/bananarchy/cover-bl-force` nested-udev guard. Plain udev events must stay + idempotent; only the daemon's `force` mode may do the two-step PWM update, and every `xset dpms force` call must be + bounded with `timeout 1` or a hung X client will flicker the active panel. On open, restore gpio13 low, duty 14, + `bl_power=0`, DPMS On and re-init the internal panel. The legacy 8-bit/9-bit userspace paths, `PROBE` and `bananarchy-cover-probe.sh` remain rollback/sign-off tooling. `SET mux_closed_level 0` selects the internal panel, not the cover; use `SET kernel_backlight_invert 0|1` only if a unit's backlight polarity differs. - Keep the internal beatles panel at 25 MHz, `dc_gpio = -1` for the spidev fallback, external-panel firmware and diff --git a/CHANGELOG.md b/CHANGELOG.md index 772139a..c9bca89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,27 @@ Release versions follow the `
` format (where `2026` is `a`, Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here. +### Bounded DPMS helper and final flicker fix + +- **Root cause**: after reboot, two orphaned `bananarchy-display-power-sync` shells and two `xset dpms force on` processes were stuck in `pipe_read`; each new udev event spawned more helpers. The forced PWM update was still reachable from plain udev events, so the active panel flickered heavily. +- **Switch**: plain udev events are now strictly idempotent and never toggle `bl_power`; only the cover daemon's `force` mode performs the two-step PWM update. Every `xset dpms force` call in `bananarchy-display-power-sync` and `bananarchy-cover-dpms.sh` is bounded with `timeout 1`, so a hung X client cannot leave orphaned helpers behind. The cover service clears stale transition guards on every boot. +- **Live verification**: killed the stuck helper/`xset` processes, restored open/unlocked state, deployed the rebuilt daemon/helpers/init script and re-ran a 10 s sysfs/process monitor: 158 samples, 0 brightness/bl_power/DPMS/PWM changes, 0 helper processes, PWM duty 100000 ns, DPMS On, `state=unlock` and `fb0` non-white. The closed→lit→blank→open sequence still produced external TE toggles, zero SPI errors and restored normal internal brightness. `e2fsck -fn` passed on both partitions; `debugfs` confirms all rebuilt artifacts byte-for-byte; bootfs sync, boot image check, artifact sync, six host tests and `check-rebuild.sh` pass. The standalone boot image hash is unchanged. +- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `f3f7ab1be04622a9554f0614080b7323689338710d711bfa3de0ee3bcbbbd6f1`, pinned by `scripts/check-rebuild.sh`. + +### Flicker-free boot and udev power state + +- **Root cause**: the forced two-step PWM update ran from every backlight udev event. Because `/run` is tmpfs, the state cache was empty after reboot, so each helper invocation toggled `bl_power` 4→0 and rewrote brightness; the nested udev events spawned up to four concurrent `bananarchy-display-power-sync` processes and produced heavy flicker on the active panel. The 1 s cover repaint also invoked the helper periodically. +- **Switch**: `bananarchy-display-power-sync` now has an explicit `force` mode used only by the compiled cover daemon on real state transitions; plain udev events use idempotent `set_if_changed` writes and never toggle `bl_power`. The 1 s repaint only redraws the framebuffer. `bananarchy-cover-display` clears stale `cover-bl-force` / `cover-power-state` guards in `start_pre()` after every reboot. `scripts/check-rebuild.sh` guards the force-mode helper. +- **Live verification**: stopped the reboot loop by seeding the open-state cache, restoring brightness 14 / `bl_power=0` / DPMS On and killing the stuck helper processes. The rebuilt daemon, helper and init script were deployed and a 5 s sysfs/process monitor confirmed no repeated PWM/DPMS changes and no runaway helper processes. `e2fsck -fn` passed on both partitions; `debugfs` confirms the rebuilt artifacts byte-for-byte; bootfs sync, boot image check, artifact sync, six host tests and `check-rebuild.sh` pass. The standalone boot image hash is unchanged. +- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `abd1886df851688e20cbce35afbe88062b878d1d9d7980a16123cf42e4ee3e7a`, pinned by `scripts/check-rebuild.sh` Superseded by the bounded-xset rebuild below. + ### Active-low cover backlight and reliable internal-panel handover - **Root cause**: eyes-on testing confirmed the outer display lights only with PWM **duty 0** while gpio13 selects the cover; the main panel uses the same PMIC PWM with the opposite polarity and needs duty 14. Leaving the cover daemon frozen with duty 0 and gpio13 high made the outer display work but left the internal panel all-white, and a daemon restart could leave gpio13 latched high because the fresh process had no linehandle to drive low. `SET mux_closed_level 0` selects the internal panel, not the cover. - **Switch**: `kernel_backlight_invert = 1`, `kernel_backlight_level = 14`, `kernel_backlight_power_path` and `kernel_power_sync_helper` are shipped. `/run/bananarchy/cover-backlight` contains `1` while the cover is lit (duty 0, `bl_power=0`, DPMS On) and `0` while the cover owns the bus but is dark (duty 14, `bl_power=0`, DPMS On). `bananarchy-display-power-sync` reads that marker and the invert/level keys, uses `/run/bananarchy/cover-bl-force` to suppress nested udev events during a forced two-step PWM update, and is also invoked directly by the daemon after marker changes. `cover_kernel_restore_internal()` explicitly drives gpio13 low, removes the marker, restores duty 14, `bl_power=0`, DPMS On and re-initialises the internal panel on `LID OPEN`, even after a stale high mux survives a daemon restart. `SET kernel_backlight_invert 0|1` remains a runtime rollback knob. - **Guards**: `scripts/test-cover-kernel.py` now checks the dark/lit marker contents, the active-low duty, the OFF duty on blank, normal brightness on open, mux restore, 1 s repaint and the DPMS gate. `scripts/check-rebuild.sh` guards the new config keys, source functions and the active-low display-power-sync paths. README, MANUAL and `AGENTS.md` document the polarity and handover. - **Live verification**: the user confirmed the outer display works with duty 0. The restore sequence returned the phone to `lid=open`, `state=unlock`, brightness 14, `bl_power=0`, DPMS On and all services started; a separate gpio13 probe drove the latched mux low. The rebuilt ARM daemon, config and scripts were deployed and the closed→lit→blank→open sequence was rechecked: cover lit showed `marker=1`, `br=0`, external TE toggles, 1382586 extra `spi0.0` bytes and zero SPI errors; cover dark showed `marker=0`; `LID OPEN` removed the marker and restored gpio13 low; the final open state showed `br=14`, `bl_power=0`, DPMS On, PWM duty 100000 ns, `l17/l6` enabled and a non-white `/dev/fb0` (0 white bytes, mean 20.7). `e2fsck -fn` passed on both partitions; `debugfs` confirms all rebuilt artifacts byte-for-byte; bootfs sync, boot image check, artifact sync, six host tests and `check-rebuild.sh` pass. The standalone boot image hash is unchanged. Eyes-on confirmation of both screens after this final deployment is still pending. -- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `3fc34741cbe9a2e68ab77e7133393bd7f93c7fec1c938680405760e8d02dfa08`, pinned by `scripts/check-rebuild.sh`. +- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `3fc34741cbe9a2e68ab77e7133393bd7f93c7fec1c938680405760e8d02dfa08`, pinned by `scripts/check-rebuild.sh` Superseded by the flicker-free rebuild below. ### Vendor-init kernel cover path and persistent flip lock diff --git a/overlay/rootfs/etc/init.d/bananarchy-cover-display b/overlay/rootfs/etc/init.d/bananarchy-cover-display index 594936d..999fa50 100755 --- a/overlay/rootfs/etc/init.d/bananarchy-cover-display +++ b/overlay/rootfs/etc/init.d/bananarchy-cover-display @@ -24,6 +24,9 @@ depend() { start_pre() { mkdir -p /run/bananarchy chmod 0755 /run/bananarchy + # /run is tmpfs: clear stale transition guards after every reboot. + rm -f /run/bananarchy/cover-bl-force \ + /run/bananarchy/cover-power-state 2>/dev/null || true } start() { diff --git a/overlay/rootfs/usr/bin/bananarchy-cover-dpms.sh b/overlay/rootfs/usr/bin/bananarchy-cover-dpms.sh index ae4afa1..ccd4040 100755 --- a/overlay/rootfs/usr/bin/bananarchy-cover-dpms.sh +++ b/overlay/rootfs/usr/bin/bananarchy-cover-dpms.sh @@ -7,15 +7,15 @@ set -u export DISPLAY="${DISPLAY:-:0}" case "${1:-}" in reinit) - xset dpms force off >/dev/null 2>&1 || true + timeout 1 xset dpms force off >/dev/null 2>&1 || true sleep 0.08 - xset dpms force on >/dev/null 2>&1 || true + timeout 1 xset dpms force on >/dev/null 2>&1 || true ;; on) - xset dpms force on >/dev/null 2>&1 || true + timeout 1 xset dpms force on >/dev/null 2>&1 || true ;; off) - xset dpms force off >/dev/null 2>&1 || true + timeout 1 xset dpms force off >/dev/null 2>&1 || true ;; *) printf 'Usage: %s [reinit|on|off]\n' "${0##*/}" >&2; exit 1 ;; diff --git a/overlay/rootfs/usr/bin/bananarchy-cover-idle b/overlay/rootfs/usr/bin/bananarchy-cover-idle index 64c112c..aaffe92 100755 Binary files a/overlay/rootfs/usr/bin/bananarchy-cover-idle and b/overlay/rootfs/usr/bin/bananarchy-cover-idle differ diff --git a/overlay/rootfs/usr/bin/bananarchy-display-power-sync b/overlay/rootfs/usr/bin/bananarchy-display-power-sync index 6e41a33..d1289e7 100755 --- a/overlay/rootfs/usr/bin/bananarchy-display-power-sync +++ b/overlay/rootfs/usr/bin/bananarchy-display-power-sync @@ -3,6 +3,10 @@ # Invoked by the backlight udev rule (as root) and by sxmo_wm.sh display on # (via doas). The 2720 Flip shares one PWM backlight between both panels: # it is active-low for the cover and active-high for the main panel. +# +# The daemon calls this helper with "force" only on a real cover-state +# transition. Plain udev events are idempotent and must never toggle bl_power, +# or they create a feedback loop that flickers the active panel. set -u BR_PATH=/sys/class/backlight/backlight/brightness @@ -11,14 +15,17 @@ KBD_PATH=/sys/class/leds/white:kbd_backlight/brightness RL_PATH=/sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us COVER_MARKER=/run/bananarchy/cover-backlight FORCE_MARKER=/run/bananarchy/cover-bl-force +STATE_CACHE=/run/bananarchy/cover-power-state LID_STATE=/run/bananarchy/lid-state CONF=/etc/bananarchy/cover-display.conf COVER_BL_LEVEL=14 COVER_BL_INVERT=1 +FORCE=0 -# A forced PWM update rewrites brightness/bl_power itself. Ignore the nested -# udev events so the two-step update cannot recurse. -if [ -f "$FORCE_MARKER" ]; then +[ "${1:-}" = "force" ] && FORCE=1 + +# Nested udev events during a forced update must not re-enter the helper. +if [ "$FORCE" -eq 0 ] && [ -f "$FORCE_MARKER" ]; then exit 0 fi @@ -48,14 +55,7 @@ set_if_changed() { [ "$_cur" = "$_want" ] || printf '%s\n' "$_want" > "$_path" 2>/dev/null || true } -force_backlight() { - _want_br="$1" - _want_blp="$2" - printf '1\n' > "$FORCE_MARKER" 2>/dev/null || true - set_if_changed "$BL_POWER_PATH" "4" - printf '%s\n' "$_want_br" > "$BR_PATH" 2>/dev/null || true - set_if_changed "$BL_POWER_PATH" "$_want_blp" - printf '%s\n' "$_want_br" > "$BR_PATH" 2>/dev/null || true +cleanup_force() { rm -f "$FORCE_MARKER" 2>/dev/null || true } @@ -64,11 +64,12 @@ force_dpms() { _cur="$(read_value "$DPMS_PATH")" [ "$_cur" = "$_want" ] && return 0 _mode="$(printf '%s' "$_want" | tr 'A-Z' 'a-z')" - DISPLAY=:0 xset dpms force "$_mode" >/dev/null 2>&1 || true + DISPLAY=:0 timeout 1 xset dpms force "$_mode" >/dev/null 2>&1 || true } br="$(read_value "$BR_PATH")" case "$br" in ''|*[!0-9]*) br=1 ;; esac +blp="$(read_value "$BL_POWER_PATH")" lid="$(read_value "$LID_STATE")" marker="" [ -r "$COVER_MARKER" ] && marker="$(read_value "$COVER_MARKER")" @@ -83,49 +84,62 @@ else DARK_BLP=4 fi -# An open flip always wins: remove a stale cover marker and restore the -# active-high internal-panel backlight before applying normal DPMS rules. +DESIRED_BR="$br" +DESIRED_BLP="$blp" +DESIRED_DPMS="On" +DESIRED_KBD="" +DESIRED_KEY="normal" + if [ "$lid" = "open" ]; then + DESIRED_KEY="open:$COVER_BL_LEVEL:0:On:absent:$COVER_BL_INVERT" + DESIRED_BR="$COVER_BL_LEVEL" + DESIRED_BLP="0" + DESIRED_DPMS="On" rm -f "$COVER_MARKER" 2>/dev/null || true - force_backlight "$COVER_BL_LEVEL" "0" - force_dpms "On" - if [ -w "$RL_PATH" ]; then - printf '40000\n' > "$RL_PATH" 2>/dev/null || true - fi - exit 0 -fi - -# While the cover owns the bus, the marker content selects its state: -# 1 = cover lit, 0 = cover dark. Never let the closed-lid hard gate force -# brightness 0 here, because that would turn the active-low cover backlight on. -if [ -f "$COVER_MARKER" ]; then - set_if_changed "$KBD_PATH" "0" +elif [ -f "$COVER_MARKER" ]; then + DESIRED_KBD="0" + DESIRED_DPMS="On" if [ "$marker" = "1" ]; then - force_backlight "$LIT_BR" "0" - force_dpms "On" + DESIRED_KEY="lit:$LIT_BR:0:On:1:$COVER_BL_INVERT" + DESIRED_BR="$LIT_BR" + DESIRED_BLP="0" else - force_backlight "$DARK_BR" "$DARK_BLP" - force_dpms "On" + DESIRED_KEY="dark:$DARK_BR:$DARK_BLP:On:0:$COVER_BL_INVERT" + DESIRED_BR="$DARK_BR" + DESIRED_BLP="$DARK_BLP" fi - exit 0 -fi - -# Hard gate: while the flip is closed no path may relight the main panel or -# the keypad backlight. The cover daemon keeps gpio13 low in this state. -if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}"; then - set_if_changed "$KBD_PATH" "0" - force_backlight "0" "4" - force_dpms "Off" - exit 0 -fi - -if [ "$br" -eq 0 ]; then - force_dpms "Off" +elif ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}"; then + DESIRED_KEY="closed:0:4:Off:absent:$COVER_BL_INVERT" + DESIRED_BR="0" + DESIRED_BLP="4" + DESIRED_DPMS="Off" + DESIRED_KBD="0" else - force_dpms "On" + [ "$br" -eq 0 ] && DESIRED_DPMS="Off" + DESIRED_KEY="normal:$br:$blp:$DESIRED_DPMS:absent:$COVER_BL_INVERT" fi -if [ "$br" -ne 0 ] && [ -w "$RL_PATH" ]; then +if [ "$FORCE" -eq 1 ]; then + cleanup_force + printf '1\n' > "$FORCE_MARKER" 2>/dev/null || true + trap cleanup_force EXIT INT TERM HUP + set_if_changed "$BL_POWER_PATH" "4" + set_if_changed "$BR_PATH" "$DESIRED_BR" + set_if_changed "$BL_POWER_PATH" "$DESIRED_BLP" + set_if_changed "$BR_PATH" "$DESIRED_BR" +else + set_if_changed "$BL_POWER_PATH" "$DESIRED_BLP" + set_if_changed "$BR_PATH" "$DESIRED_BR" +fi + +[ -n "$DESIRED_KBD" ] && set_if_changed "$KBD_PATH" "$DESIRED_KBD" +force_dpms "$DESIRED_DPMS" + +if [ "$FORCE" -eq 1 ]; then + printf '%s\n' "$DESIRED_KEY" > "$STATE_CACHE" 2>/dev/null || true + cleanup_force + trap - EXIT INT TERM HUP +elif [ "$br" -ne 0 ] && [ -w "$RL_PATH" ]; then printf '40000\n' > "$RL_PATH" 2>/dev/null || true fi diff --git a/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle index 64c112c..aaffe92 100755 Binary files a/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle and b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle differ diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index a19d9c3..57d1c82 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -373,7 +373,7 @@ fi echo "[check] Known-good flashable image set..." for pair in \ "69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \ - "3fc34741cbe9a2e68ab77e7133393bd7f93c7fec1c938680405760e8d02dfa08 images/bananarchy-nokia-beatles.img" \ + "f3f7ab1be04622a9554f0614080b7323689338710d711bfa3de0ee3bcbbbd6f1 images/bananarchy-nokia-beatles.img" \ "2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \ "b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do set -- $pair @@ -929,7 +929,8 @@ fi DPMS_SYNC="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync" if ! grep -qF 'COVER_MARKER=/run/bananarchy/cover-backlight' "$DPMS_SYNC" || \ ! grep -qF 'kernel_backlight_invert' "$DPMS_SYNC" || \ - ! grep -qF 'force_backlight' "$DPMS_SYNC" || \ + ! grep -qF 'FORCE=0' "$DPMS_SYNC" || \ + ! grep -qF 'STATE_CACHE' "$DPMS_SYNC" || \ ! grep -qF 'LIT_BR=0' "$DPMS_SYNC" || \ ! grep -qF 'exit 0' "$DPMS_SYNC"; then fail "display-power-sync no longer handles the active-low cover backlight" diff --git a/scripts/test-cover-kernel.py b/scripts/test-cover-kernel.py index 2dc888c..888a6e8 100755 --- a/scripts/test-cover-kernel.py +++ b/scripts/test-cover-kernel.py @@ -211,12 +211,13 @@ def main(): print("[ok] kernel UI is repainted every second") daemon.send("BLANK") + time.sleep(0.1) if not daemon.wait("kernel cmd 28") or not daemon.wait("dpms reinit") or \ not daemon.wait("kernel marker 0") or \ not daemon.wait("kernel backlight 14 power=0"): return fail("blanking did not power the cover down") if marker.read_text().strip() != "0" or bl.read_text().strip() != "14": - return fail("the cover backlight was not returned to the OFF duty") + return fail("the cover backlight was not returned to the OFF duty: marker=%r bl=%r blp=%r events=%r" % (marker.read_text() if marker.exists() else None, bl.read_text(), bl_power.read_text(), daemon.events()[-12:])) print("[ok] BLANK: display-off, external backlight OFF duty") daemon.send("LID OPEN") diff --git a/src/bananarchy-daemons/bananarchy-cover-idle.c b/src/bananarchy-daemons/bananarchy-cover-idle.c index cb720cc..e709f1b 100644 --- a/src/bananarchy-daemons/bananarchy-cover-idle.c +++ b/src/bananarchy-daemons/bananarchy-cover-idle.c @@ -962,7 +962,7 @@ static void cover_kernel_power_sync(struct cover_hw *hw) if(!hw->kernel_sync[0]) return; { - char *const argv[] = { hw->kernel_sync, NULL }; + char *const argv[] = { hw->kernel_sync, (char *)"force", NULL }; daemon_spawn_env(argv, (char *const *)session_env); } } @@ -1311,10 +1311,6 @@ static const char *cover_kernel_draw(struct cover_hw *hw, cover_kernel_power_sync(hw); } hw->kernel_lit = lit; - } else if(lit) { - cover_kernel_backlight(hw, 1); - hw_dpms(hw, "on"); - cover_kernel_power_sync(hw); } if(lit && !cover_kernel_frame(hw, state)) return "none";