Files
bananarchy/scripts/test-cover-kernel.py
T
Luxferre c939687138 Drive the 2720 Flip cover panel through the kernel panel driver
Autonomous testing (clean reboot, kernel SPI statistics, kHz GPIO sweeps,
CS0/CS1 register reads, battery/ALS/hwmon checks, host webcam differential
imaging) showed all twelve userspace PROBE cases delivered complete,
error-free SPI traffic while the cover stayed dark. The QUP5 pinctrl group
has one CS line and gpio110 (the kernel panel-mipi-dbi-spi driver's D/C) is
shared behind the gpio13 bus switch, so no userspace D/C framing can work.

backend = kernel is now the default. While the flip is closed the compiled
cover daemon claims only gpio13 (mux) and gpio23 (cover reset), switches the
bus to the cover and forces a DPMS off/on cycle through
bananarchy-cover-dpms.sh reinit; mipi_dbi_enable() then replays the kernel's
firmware init sequence onto the external panel with CS0 and gpio110 D/C. The
cover UI is rendered as a 240x240 XR24 damage rect at the top of /dev/fb0
using the fbdev stride, which makes mipi_dbi set a 240x240 address window.
The main backlight and keypad stay at 0, so only the outer panel can light.
On open the mux returns to the internal panel and the lid daemon requests a
reinit after an 80 ms settle.

Live verification: closed -> backend=kernel-dark (DPMS off); BUTTON ->
backend=kernel, dpms=On, gpio13 high, 172800 non-zero bytes of cover UI in
/dev/fb0, kernel spi0.0 +460899 bytes and userspace spi0.1 +0, zero SPI
errors; BLANK -> kernel-dark/DPMS off; LID OPEN -> mux=free, gpio13 low.
Main backlight and keypad stayed at 0 throughout.

All spidev/8-bit/9-bit paths, PROBE, bananarchy-cover-probe.sh and
backend = fb|spidev|none remain as runtime rollback paths. New host test
scripts/test-cover-kernel.py plus check-rebuild.sh guards.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
ce0542321990a8cff8ab122c0a47c0684fcc7e3d5f6fc97e74b3b0ea4c4826b5 in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms the
rebuilt daemons, helper and config byte-for-byte, and the bootfs sync, boot
image check, artifact sync, host tests and rebuild preflight all pass.

Limitation: Xorg shares /dev/fb0, so its repaints can still overwrite part
of the cover UI; a dedicated override-redirect cover compositor is next.
Physical illumination is still unverified from the host.
2026-11-10 21:54:53 +02:00

184 lines
6.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""Host test for the kernel-owned 2720 Flip cover panel path.
The daemon runs in SPI simulation mode against a fake /dev/fb0, fake main
backlight and a logged DPMS helper. It verifies that the mux is only claimed
while closed, that a wake forces a kernel DPMS re-init and renders a frame,
that blanking powers the panel down, that opening restores the mux, and that
a lit main backlight blocks the whole path.
"""
import os
import pathlib
import socket
import subprocess
import sys
import tempfile
import time
BASE = pathlib.Path(__file__).resolve().parent.parent
SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
CONF = BASE / "overlay/rootfs/etc/bananarchy/cover-display.conf"
HELPER = BASE / "overlay/rootfs/usr/bin/bananarchy-cover-dpms.sh"
class Daemon:
def __init__(self, root, exe, log, fb, bl, config):
self.log = log
self.fb = fb
self.bl = bl
self.sock = root / "cover.sock"
self.client_path = root / "client.sock"
env = dict(os.environ)
env.update({
"BANANARCHY_COVER_LOCK": str(root / "daemon.lock"),
"BANANARCHY_COVER_MAIN_BLANK_CFG": str(root / "idle_blank"),
"BANANARCHY_COVER_SPI_SIM": str(log),
"BANANARCHY_COVER_MAIN_FB": str(fb),
"BANANARCHY_COVER_DPMS_HELPER": "/bin/true",
"BANANARCHY_COVER_BL_PATH": str(bl),
"BANANARCHY_COVER_DPMS_PATH": str(root / "dpms"),
})
(root / "dpms").write_text("Off\n")
self.proc = subprocess.Popen([str(exe), "--config", str(config)],
env=env, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.client.bind(str(self.client_path))
self.client.settimeout(2)
end = time.time() + 3
while time.time() < end and not self.sock.exists():
time.sleep(0.05)
def send(self, command):
self.client.sendto(command.encode(), str(self.sock))
try:
return self.client.recv(512).decode().strip()
except socket.timeout:
return ""
def events(self):
return self.log.read_text(encoding="utf-8", errors="replace").splitlines() \
if self.log.is_file() else []
def wait(self, text, timeout=3.0):
end = time.time() + timeout
while time.time() < end:
if any(text in line for line in self.events()):
return True
time.sleep(0.05)
return False
def close(self):
try:
self.send("QUIT")
except OSError:
pass
self.client.close()
try:
self.proc.wait(timeout=3)
except subprocess.TimeoutExpired:
self.proc.kill()
self.proc.wait()
def fail(message):
sys.stderr.write("FAIL: %s\n" % message)
return 1
def main():
if not SRC.is_file() or not CONF.is_file() or not HELPER.is_file():
return fail("missing cover daemon source, config or DPMS helper")
conf = CONF.read_text(encoding="utf-8")
for token in ("backend = kernel", "main_fb_device = /dev/fb0",
"kernel_dpms_helper = /usr/bin/bananarchy-cover-dpms.sh"):
if token not in conf:
return fail("shipping config lost %s" % token)
helper = HELPER.read_text(encoding="utf-8")
if "dpms force off" not in helper or "dpms force on" not in helper:
return fail("the DPMS helper no longer performs an off/on re-init")
source = SRC.read_text(encoding="utf-8")
for token in ("cover_kernel_draw", "cover_kernel_frame",
"cover_main_backlight_is_off", "reinit"):
if token not in source:
return fail("cover daemon lost the kernel backend: %s" % token)
print("[ok] kernel backend wiring is present")
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-kernel-") as tmp:
root = pathlib.Path(tmp)
exe = root / "cover-idle"
build = subprocess.run(
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I" + str(SRC.parent), str(SRC), "-o", str(exe)],
capture_output=True, text=True)
if build.returncode:
sys.stderr.write(build.stderr)
return 1
print("[ok] host build of the compiled cover daemon")
fb = root / "fb0"
fb.write_bytes(b"\x00" * (240 * 320 * 4))
bl = root / "brightness"
bl.write_text("0\n")
log = root / "spi.log"
(root / "idle_blank").write_text("300\n")
config = root / "cover.conf"
config.write_text(
"socket_path = %s\nfb_device = %s\nbacklight_path = %s\n"
"blank_timeout = 2\nbackend = kernel\nmain_fb_device = %s\n"
"kernel_dpms_helper = /bin/true\nmux_closed_level = 1\n"
"mux_open_level = 0\nreset_assert_level = 0\nreset_idle_level = 1\n" %
(root / "cover.sock", root / "no-fb1", root / "backlight", fb))
daemon = Daemon(root, exe, log, fb, bl, config)
try:
time.sleep(0.3)
if daemon.events():
return fail("an open flip claimed the mux or touched DPMS: %s" %
daemon.events()[:4])
print("[ok] open flip: no mux claim, no DPMS, no frame")
daemon.send("LID CLOSED")
if not daemon.wait("dpms off"):
return fail("closing the flip did not blank the cover")
if not any(e == "gpio 1 1" for e in daemon.events()):
return fail("the mux was not switched to the external panel")
print("[ok] closed flip: mux to cover, panel blanked")
daemon.send("BUTTON")
if not daemon.wait("dpms reinit") or not daemon.wait("kernel frame lit=1"):
return fail("BUTTON did not force a kernel re-init and draw a frame")
if not any(fb.read_bytes()):
return fail("the cover UI was not rendered into the main framebuffer")
if "kernel" not in daemon.send("STATUS"):
return fail("STATUS does not report the kernel backend")
print("[ok] BUTTON: DPMS re-init and cover UI rendered to fbdev")
daemon.send("BLANK")
if not daemon.wait("dpms off"):
return fail("blanking did not power the cover down")
daemon.send("LID OPEN")
if not daemon.wait("release"):
return fail("opening the flip did not release the mux")
if not any(e == "gpio 0 1" for e in daemon.events()):
return fail("the mux was not restored to the internal panel")
print("[ok] blank and open: panel off, mux restored")
# A lit main backlight must block the whole kernel path.
tail = len(daemon.events())
daemon.send("LID CLOSED")
bl.write_text("14\n")
daemon.send("BUTTON")
time.sleep(0.3)
if "pending" not in daemon.send("STATUS"):
return fail("a lit main backlight did not block the kernel backend")
if any(e.startswith("kernel frame") or e.startswith("dpms reinit")
for e in daemon.events()[tail:]):
return fail("the kernel backend drew with the main backlight lit")
print("[ok] lit main backlight blocks the kernel backend")
finally:
daemon.close()
print("kernel-owned cover panel: all checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())