Drive the 2720 Flip cover panel from userspace while closed
The shipping single-panel DTB left the external GC9305 unused because bananarchy-cover-idle only knew /dev/fb1. The compiled daemon now owns the shared QUP5 bus while the flip is closed: it claims gpio13/21/23 through the gpiochip ABI, replays the external firmware over /dev/spidev0.1 at the verified 25 MHz and pushes 240x240 RGB565 frames. LID OPEN restores the mux and releases the panel lines; activation also requires the main panel to be DPMS-off. Polarities are config keys and live SET knobs, with SET backend none as a rollback. /dev/fb1 keeps precedence and the two-panel spi-mux DT stays opt-in. Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac in check-rebuild.sh. e2fsck -fn passes on both partitions, debugfs confirms the four updated rootfs files byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight all pass. This is an intermediate checkpoint: eyes-on confirmation that the cover lights up and several more polarity/CS fixes are still required.
This commit is contained in:
1 parent
d402a53221
commit
40a840b49b
12 files changed
+1085
-72
No files matched your search
@@ -373,7 +373,7 @@ fi
|
||||
echo "[check] Known-good flashable image set..."
|
||||
for pair in \
|
||||
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
|
||||
"16cc68cbfa9908dd42a36e1e4dd18149f9d8e43f7c5af30839695a89a5e60783 images/bananarchy-nokia-beatles.img" \
|
||||
"ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac images/bananarchy-nokia-beatles.img" \
|
||||
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
|
||||
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
|
||||
set -- $pair
|
||||
@@ -1442,6 +1442,45 @@ if command -v gcc >/dev/null 2>&1 && \
|
||||
fail "host cover display behaviour test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Closed-flip external panel backend..."
|
||||
for token in 'cover_hw_release' 'cover_spi_draw' 'hw_init_panel' \
|
||||
'mux_closed_level' 'reset_assert_level' 'spi_speed_hz' \
|
||||
'BANANARCHY_COVER_SPI_SIM' 'BA_GPIO_GET_LINEHANDLE' \
|
||||
'BA_SPI_IOC_MESSAGE' 'MIPI DBI' \
|
||||
'cover_main_panel_is_off'; do
|
||||
if ! grep -qF -- "$token" "$COVER_SRC"; then
|
||||
fail "bananarchy-cover-idle.c lost the closed-flip spidev backend: $token"
|
||||
fi
|
||||
done
|
||||
for token in 'backend = auto' 'spi_device = /dev/spidev0.1' \
|
||||
'spi_mux_gpio = 13' 'spi_dc_gpio = 21' 'spi_reset_gpio = 23' \
|
||||
'mux_closed_level = 1' 'mux_open_level = 0' \
|
||||
'dc_command_level = 0' 'dc_data_level = 1' \
|
||||
'reset_assert_level = 0' 'reset_idle_level = 1' \
|
||||
'spi_speed_hz = 25000000'; do
|
||||
if ! grep -qF -- "$token" "$COVER_CONF"; then
|
||||
fail "cover display config lost the spidev polarity key: $token"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF 'flip_open' "$COVER_SRC" || \
|
||||
! grep -qF 'cover_hw_release(hw)' "$COVER_SRC" || \
|
||||
! grep -qF 'cover_draw(&hw, fb_path, &state)' "$COVER_SRC"; then
|
||||
fail "the cover daemon no longer gates the shared bus on the flip state"
|
||||
fi
|
||||
if [ ! -x "$BASE_DIR/scripts/test-cover-spidev.py" ]; then
|
||||
fail "missing host test scripts/test-cover-spidev.py"
|
||||
fi
|
||||
if command -v gcc >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-cover-spidev.py" >/dev/null 2>&1; then
|
||||
fail "host closed-flip external panel backend test failed"
|
||||
fi
|
||||
for f in "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-idle"; do
|
||||
if ! strings "$f" 2>/dev/null | grep -qF 'frame lit=%d size=%zu'; then
|
||||
fail "${f#"$BASE_DIR/"} is stale: rebuild with scripts/build-bananarchy-daemons.sh"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[check] 2720 Flip external panel (opt-in DT)..."
|
||||
if [ ! -f "$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts" ] || \
|
||||
[ ! -x "$BASE_DIR/scripts/build-beatles-cover-panel.py" ] || \
|
||||
@@ -1464,8 +1503,10 @@ if [ ! -x "$COVER_DIAG" ] || ! sh -n "$COVER_DIAG" 2>/dev/null; then
|
||||
fi
|
||||
if ! grep -qF '/dev/fb1' "$COVER_DIAG" || \
|
||||
! grep -qF '/sys/class/graphics/fb1' "$COVER_DIAG" || \
|
||||
! grep -qF '/dev/spidev0.1' "$COVER_DIAG" || \
|
||||
! grep -qF 'spi_mux_gpio' "$COVER_DIAG" || \
|
||||
! grep -qF 'bananarchy-coverctl' "$COVER_DIAG"; then
|
||||
fail "cover diagnostics no longer inspect fb1 and the daemon"
|
||||
fail "cover diagnostics no longer inspect fb1, spidev and the daemon"
|
||||
fi
|
||||
if ! grep -qF 'bananarchy-cover-diagnose.sh' \
|
||||
"$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
|
||||
|
||||
Executable
+323
@@ -0,0 +1,323 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host test for the 2720 Flip closed-flip-only external panel backend.
|
||||
|
||||
Compiles bananarchy-cover-idle.c on the host and runs it in SPI simulation
|
||||
mode (BANANARCHY_COVER_SPI_SIM). The shared QUP5 bus must be untouched while
|
||||
the flip is open, claimed only while closed, released before Xorg can flush
|
||||
another main-panel frame, and the external firmware must be replayed before
|
||||
the first frame. Polarity knobs and the /dev/fb1 precedence are also checked.
|
||||
"""
|
||||
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"
|
||||
FIRMWARE = BASE / "devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin"
|
||||
CONFIG = BASE / "overlay/rootfs/etc/bananarchy/cover-display.conf"
|
||||
|
||||
|
||||
class Cover:
|
||||
def __init__(self, root, exe, config, log, env_extra=None):
|
||||
self.root = root
|
||||
self.log = log
|
||||
self.sock_path = root / "cover.sock"
|
||||
self.client_path = root / "client.sock"
|
||||
self.env = dict(os.environ)
|
||||
self.env.update({
|
||||
"BANANARCHY_COVER_LOCK": str(root / "daemon.lock"),
|
||||
"BANANARCHY_COVER_MAIN_BLANK_CFG": str(root / "idle_blank_timeout"),
|
||||
"BANANARCHY_COVER_SPI_SIM": str(log),
|
||||
})
|
||||
if env_extra:
|
||||
self.env.update(env_extra)
|
||||
self.proc = subprocess.Popen([str(exe), "--config", str(config)],
|
||||
env=self.env, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
self.client.bind(str(self.client_path))
|
||||
self.client.settimeout(2)
|
||||
deadline = time.time() + 3
|
||||
while time.time() < deadline and not self.sock_path.exists():
|
||||
time.sleep(0.05)
|
||||
|
||||
def send(self, command):
|
||||
self.client.sendto(command.encode(), str(self.sock_path))
|
||||
try:
|
||||
return self.client.recv(512).decode().strip()
|
||||
except socket.timeout:
|
||||
return ""
|
||||
|
||||
def events(self):
|
||||
if not self.log.is_file():
|
||||
return []
|
||||
return self.log.read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
|
||||
def wait_event(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()
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
|
||||
|
||||
def write_config(path, root, extra):
|
||||
lines = [
|
||||
"socket_path = %s" % (root / "cover.sock"),
|
||||
"fb_device = %s" % (root / "no-fb1"),
|
||||
"backlight_path = %s" % (root / "backlight"),
|
||||
"brightness = 160",
|
||||
"blank_timeout = 2",
|
||||
"backend = spidev",
|
||||
"spi_device = /dev/spidev0.1",
|
||||
"gpiochip_device = /dev/gpiochip0",
|
||||
"panel_firmware = %s" % FIRMWARE,
|
||||
"spi_mux_gpio = 13",
|
||||
"spi_dc_gpio = 21",
|
||||
"spi_reset_gpio = 23",
|
||||
"mux_closed_level = 1",
|
||||
"mux_open_level = 0",
|
||||
"dc_command_level = 0",
|
||||
"dc_data_level = 1",
|
||||
"reset_assert_level = 0",
|
||||
"reset_idle_level = 1",
|
||||
"spi_speed_hz = 25000000",
|
||||
]
|
||||
lines.extend("%s = %s" % item for item in extra.items())
|
||||
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
def check(ok, message):
|
||||
if not ok:
|
||||
sys.stderr.write("FAIL: %s\n" % message)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def run_case(root, exe, extra, prepare=None, env_extra=None, dpms="Off"):
|
||||
case = root / ("case%d" % len(list(root.glob("case*"))))
|
||||
case.mkdir()
|
||||
log = case / "spi.log"
|
||||
conf = case / "cover.conf"
|
||||
(case / "idle_blank_timeout").write_text("300\n")
|
||||
(case / "dpms").write_text(dpms + "\n")
|
||||
write_config(conf, case, extra)
|
||||
if prepare:
|
||||
prepare(case)
|
||||
env = {"BANANARCHY_COVER_DPMS_PATH": str(case / "dpms")}
|
||||
if env_extra:
|
||||
env.update(env_extra)
|
||||
return Cover(case, exe, conf, log, env), case
|
||||
|
||||
|
||||
def main():
|
||||
if not SRC.is_file() or not FIRMWARE.is_file() or not CONFIG.is_file():
|
||||
sys.stderr.write("FAIL: missing cover sources or firmware\n")
|
||||
return 1
|
||||
source = SRC.read_text(encoding="utf-8")
|
||||
for token in ("cover_hw_release", "cover_spi_draw", "hw_init_panel",
|
||||
"mux_closed_level", "spi_speed_hz", "FBIOBLANK",
|
||||
"BANANARCHY_COVER_SPI_SIM", "cover_main_panel_is_off",
|
||||
"0x28", "0x29"):
|
||||
if token not in source:
|
||||
sys.stderr.write("FAIL: cover daemon lost %s\n" % token)
|
||||
return 1
|
||||
conf = CONFIG.read_text(encoding="utf-8")
|
||||
for token in ("backend = auto", "spi_device = /dev/spidev0.1",
|
||||
"spi_mux_gpio", "spi_dc_gpio", "spi_reset_gpio",
|
||||
"mux_closed_level", "spi_speed_hz = 25000000", "dc_gpio = -1"):
|
||||
if token not in conf:
|
||||
sys.stderr.write("FAIL: cover config lost %s\n" % token)
|
||||
return 1
|
||||
print("[ok] closed-flip spidev wiring and config are present")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-spi-") 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")
|
||||
|
||||
daemon, case = run_case(root, exe, {})
|
||||
try:
|
||||
if "pong" not in daemon.send("PING"):
|
||||
sys.stderr.write("FAIL: daemon did not answer PING\n")
|
||||
return 1
|
||||
time.sleep(0.3)
|
||||
if daemon.events():
|
||||
return not check(False, "an open flip touched the shared SPI bus: %s" %
|
||||
daemon.events()[:4])
|
||||
status = daemon.send("STATUS")
|
||||
if "spi=1" not in status or "mux=free" not in status:
|
||||
return not check(False, "STATUS does not report the idle bus: %s" % status)
|
||||
print("[ok] open flip: no GPIO claim, no SPI transfer")
|
||||
|
||||
daemon.send("LID CLOSED")
|
||||
if not daemon.wait_event("claim"):
|
||||
return not check(False, "closing the flip did not claim the mux")
|
||||
if not daemon.wait_event("cmd fe 0") or not daemon.wait_event("cmd 29 0"):
|
||||
return not check(False, "external panel firmware was not replayed")
|
||||
if not daemon.wait_event("frame lit=0 size=115200"):
|
||||
return not check(False, "no dark frame after closing")
|
||||
events = daemon.events()
|
||||
mux_closed = [i for i, line in enumerate(events) if line == "gpio 1"]
|
||||
first_cmd = next((i for i, line in enumerate(events)
|
||||
if line.startswith("cmd ")), len(events))
|
||||
if not mux_closed or mux_closed[0] >= first_cmd:
|
||||
return not check(False, "mux was not switched before the first SPI command")
|
||||
if "backend=spidev" not in daemon.send("STATUS") or \
|
||||
"mux=closed" not in daemon.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the spidev backend")
|
||||
print("[ok] closed flip: mux, reset, firmware init and dark frame")
|
||||
|
||||
daemon.send("BUTTON")
|
||||
if not daemon.wait_event("frame lit=1 size=115200"):
|
||||
return not check(False, "BUTTON did not light the external panel")
|
||||
if "cmd 29 0" not in daemon.events():
|
||||
return not check(False, "display-on command missing")
|
||||
print("[ok] external button: lit RGB565 frame on the cover")
|
||||
|
||||
daemon.send("BLANK")
|
||||
if not daemon.wait_event("cmd 28 0"):
|
||||
return not check(False, "display-off command missing when dark")
|
||||
print("[ok] blank: external panel is powered down again")
|
||||
|
||||
daemon.send("LID OPEN")
|
||||
if not daemon.wait_event("release"):
|
||||
return not check(False, "opening the flip did not release the panel lines")
|
||||
events = daemon.events()
|
||||
last_release = max(i for i, line in enumerate(events) if line == "release")
|
||||
tail = events[last_release + 1:]
|
||||
if any(line.startswith(("cmd ", "frame ", "claim")) for line in tail):
|
||||
return not check(False, "SPI activity continued after LID OPEN: %s" % tail)
|
||||
if "gpio 0" not in events[:last_release + 1]:
|
||||
return not check(False, "mux was not restored to the internal panel")
|
||||
if "mux=open" not in daemon.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the restored mux")
|
||||
print("[ok] LID OPEN: mux restored, panel lines released, bus idle")
|
||||
finally:
|
||||
daemon.close()
|
||||
|
||||
# Polarity knobs must be honoured without a rebuild.
|
||||
rev, _ = run_case(root, exe, {"mux_closed_level": "0",
|
||||
"mux_open_level": "1"})
|
||||
try:
|
||||
rev.send("LID CLOSED")
|
||||
if not rev.wait_event("claim"):
|
||||
return not check(False, "inverted-polarity daemon did not activate")
|
||||
rev.send("LID OPEN")
|
||||
if not rev.wait_event("release"):
|
||||
return not check(False, "inverted-polarity daemon did not release")
|
||||
events = rev.events()
|
||||
if events.count("gpio 0") < 1 or events.count("gpio 1") < 1:
|
||||
return not check(False, "inverted mux polarity was ignored: %s" % events)
|
||||
print("[ok] mux polarity is a config knob, not a rebuild")
|
||||
finally:
|
||||
rev.close()
|
||||
|
||||
# The opt-in /dev/fb1 DT keeps precedence over the userspace backend.
|
||||
fb, fbcase = run_case(root, exe, {"backend": "auto"},
|
||||
prepare=lambda d: (d / "no-fb1").write_bytes(
|
||||
b"\x00" * (240 * 240 * 4)),
|
||||
env_extra={"BANANARCHY_COVER_FB_GEOM": "240,240,32"})
|
||||
try:
|
||||
fb.send("LID CLOSED")
|
||||
fb.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(line.startswith(("claim", "cmd ", "frame ")) for line in fb.events()):
|
||||
return not check(False, "spidev backend overrode the /dev/fb1 path")
|
||||
if "backend=fb" not in fb.send("STATUS"):
|
||||
return not check(False, "fbdev backend not selected when /dev/fb1 exists")
|
||||
print("[ok] /dev/fb1 takes precedence when the opt-in DT is installed")
|
||||
finally:
|
||||
fb.close()
|
||||
|
||||
# Explicitly disabled backend must stay completely inert.
|
||||
off, _ = run_case(root, exe, {"backend": "none"})
|
||||
try:
|
||||
off.send("LID CLOSED")
|
||||
off.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if off.events():
|
||||
return not check(False, "backend=none still touched the bus: %s" %
|
||||
off.events()[:4])
|
||||
if "spi=0" not in off.send("STATUS"):
|
||||
return not check(False, "backend=none did not disable spidev")
|
||||
print("[ok] backend=none keeps the shared bus untouched")
|
||||
finally:
|
||||
off.close()
|
||||
|
||||
# A transient lid flap must never steal the bus from a live main panel.
|
||||
live, _ = run_case(root, exe, {}, dpms="On")
|
||||
try:
|
||||
live.send("LID CLOSED")
|
||||
live.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(e.startswith(("claim", "cmd ", "frame ")) for e in live.events()):
|
||||
return not check(False, "cover took the bus while the main panel was On")
|
||||
if "backend=pending" not in live.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the DPMS gate")
|
||||
print("[ok] main panel DPMS-On blocks the closed-flip bus takeover")
|
||||
finally:
|
||||
live.close()
|
||||
|
||||
# Runtime SET knobs: polarity re-init and a one-command rollback.
|
||||
knobs, _ = run_case(root, exe, {})
|
||||
try:
|
||||
knobs.send("LID CLOSED")
|
||||
if not knobs.wait_event("cmd fe 0"):
|
||||
return not check(False, "runtime-knob daemon did not init the panel")
|
||||
before = len([e for e in knobs.events() if e == "cmd fe 0"])
|
||||
knobs.send("SET mux_closed_level 0")
|
||||
if not knobs.wait_event("release"):
|
||||
return not check(False, "SET polarity did not release the panel lines")
|
||||
if not check(any(e == "gpio 0" for e in knobs.events()),
|
||||
"SET mux_closed_level was ignored"):
|
||||
return 1
|
||||
after = len([e for e in knobs.events() if e == "cmd fe 0"])
|
||||
if after <= before:
|
||||
return not check(False, "SET polarity did not re-init the panel")
|
||||
knobs.send("SET backend none")
|
||||
if "spi=0" not in knobs.send("STATUS"):
|
||||
return not check(False, "SET backend none did not disable spidev")
|
||||
tail_start = len(knobs.events())
|
||||
knobs.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(e.startswith("frame ") for e in knobs.events()[tail_start:]):
|
||||
return not check(False, "SET backend none still drew a frame")
|
||||
print("[ok] SET polarity and SET backend none are live sign-off knobs")
|
||||
finally:
|
||||
knobs.close()
|
||||
|
||||
print("closed-flip external panel backend: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user