Files
bananarchy/AGENTS.md
T

124 lines
10 KiB
Markdown

# Bananarchy Linux — agent guide
Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `CHANGELOG.md`,
`BATTERY-OPTIMIZATION-ANALYSIS.md`, `bootloader/lk2nd/README.md`, and `scripts/check-rebuild.sh`.
## Project scope
- Bananarchy is an `armv7` Alpine/postmarketOS hardfork for MSM8905/MSM8909 keypad feature phones with 240x320 non-touch
SPI displays: `nokia-argon`, `nokia-beatles`, `nokia-tough`, `nokia-sparkler`, and `nokia-leo`.
- The stack is X11-only: Xlibre, patched `sxmo-de-dwm`, preloaded C/C++ DWM plugins, NeoUI, `fcitx5-t9`, and Adreno 304
Glamor/DRI3/GLX over `panel-mipi-dbi`. No Wayland compositor, backend, or viewer is shipped.
- Design targets are keypad-first 240x320 UI, <2 ms wake latency, and <95 MB idle RAM on 512 MB devices. The pinned
release is `a1108` / `dejavu`; `scripts/version.sh` and `scripts/check-rebuild.sh` are authoritative.
## Source of truth and workflow
- Treat `prebuilt/` as the single source of truth for compiled artifacts and `scripts/rootfs-packages.txt` as the single
source of truth for packages. `overlay/rootfs/` is a generated mirror; never hand-edit binaries there. Run
`./scripts/sync-prebuilt-overlay.sh` after artifact changes.
- Treat `images/`, `rootfs/`, and build caches as local, gitignored outputs. Clean clones rebuild them from source;
`scripts/check-rebuild.sh` pins physically verified hashes only when those local artifacts exist.
- Run `./scripts/check-rebuild.sh`, relevant `scripts/test-*.py` tests, `./scripts/sync-prebuilt-overlay.sh --check`,
and `git diff --check` before claiming a source, artifact, docs, or release change is complete.
- Cross-compile inside rootless Docker. Main builders are `scripts/build-sxmo-x11.sh`, `build-dmenu.sh`,
`build-bananarchy-daemons.sh`, `build-kernel-audio.sh`, `build-lk2nd-beatles.sh`, `build-games.sh`,
`build-fcitx5-t9.sh`, and `build-xlibre.sh`.
- Use `scripts/build-dmenu.sh` for dmenu-only changes. Do not run a full `build-sxmo-x11.sh` casually: the shipped `dwm`
binary contains cover IPC strings absent from source, so a full rebuild drifts `dwm`; restore or reconcile it.
- Rootfs/image tools are `scripts/bootstrap-rootfs.sh`, `scripts/apply-bananarchy-overlay.sh`,
`scripts/compile-gsettings-schemas.sh`, `rebuild-image.sh`, `scripts/sync-beatles-bootfs.py --check`,
`prepare-release.sh`, and `flash-edl.sh`.
- Rebuild the verified 2720 image with
`BANANARCHY_VERSION=a1108 BANANARCHY_CODENAME=dejavu ./rebuild-image.sh nokia-beatles`. After a verified rebuild,
update the raw hash in `scripts/check-rebuild.sh` and `CHANGELOG.md`; verify with `e2fsck -fn`, `debugfs`, bootfs
sync, artifact sync, and `check-rebuild.sh`.
- Do not push to `origin` unless explicitly requested. Do not update pinned hashes or release claims without actual
verification.
## Critical invariants
- Bluetooth requires `ControllerMode = dual` in `etc/bluetooth/main.conf`; BlueZ 5.87 rejects LE-only HOGP in `bredr`
mode. Keep `UserspaceHID=true`, `LEAutoSecurity=true`, `ClassicBondedOnly=false`, and `IdleTimeout=0` in `input.conf`.
`bananarchy-bt-obex` must power on, enable LE, select the LE bearer for HID-over-GATT devices, and pair unbonded
devices. `util-linux-misc` and `bluez-btmgmt` support the live PTY scan wrapper.
- WebKit requires explicit `glib` and `gsettings-desktop-schemas` packages. Because apk uses `--no-scripts`,
`apply-bananarchy-overlay.sh` must run `compile-gsettings-schemas.sh`; without `gschemas.compiled`, the WebKit network
process aborts. Keep the Webarchy renderer fallback.
- Do not change `CONFIG_PREEMPT*`, `CONFIG_PM_SLEEP`/`CONFIG_SUSPEND`, `CONFIG_SMP`, `CONFIG_MODVERSIONS`,
`CONFIG_MODULE_UNLOAD`, `CONFIG_ENERGY_MODEL`, `CONFIG_PERF_EVENTS`, `CONFIG_FUNCTION_GRAPH_TRACER`, or `CONFIG_HZ`
without rebuilding every pmaports module. `CONFIG_SUSPEND` stays off; deep suspend and long-lived pollers are
intentionally not planned.
- Keep package and image hygiene: no top-level Rust packages such as `sudo-rs`, no Wayland UI, no on-device compiler
(`gcc`, `g++`, `musl-dev`, `make`), no Janet runtime, no target `pkill` dependency, no `apk` call after
`rebuild-image.sh` strips caches, and no `__pycache__` under `overlay/rootfs/`.
- Keep the core tools and runtime dependencies guarded by `check-rebuild.sh`. On-device scripting uses the Yabasic FFI
SDK, so `yabasic`, `libffi`, `libneoui.so`, and `libcurl.so.4` must remain; Perl, Lua, optional Tcl extensions, and
the sqlite CLI stay excluded.
- Keep power/network behaviour event-driven: `superctl disable sxmo_networkmonitor`, no long `nmcli device monitor`, no
infinite wakelocks, no forced `sxmo.noidle`/`sxmo.nosuspend`, lz4 zram via `/usr/bin/zramstart`, and
`vm.compaction_proactiveness=0`. GPS resolves through `bananarchy-gps-modem.sh`, never `mmcli -m any`.
- Keep idle daemons as compiled C ARM ELF binaries (`bananarchy-lid`, `bananarchy-cover-idle`,
`bananarchy-volume-keys`), not Python. Preserve `/run/bananarchy/lid-state`, the cover socket protocol, `FBIOBLANK`,
cover diagnostics, and `scripts/test-cover-idle.py`.
- Keep the zero-lag plugin model: preloaded resident daemons guarded by lock/FIFO, `poll()` at 0% CPU, offscreen
`240x296` Pixmaps at `Y=24`, `PluginTheme`, `RELOAD_THEME`, idle blank/lock helpers, the 350 ms `dwm` wake guard, and
startup keyboard-grab cleanup without a background poller.
- Draw Pango/Xft wrapped text line by line with clipping and matching render rows for link focus. Use `smsTextMetrics()`
for GSM-7/UCS-2 accounting; strip `[SIM n]` tags with `parseSmsHeaderLine()` and never write them back to `sms.txt`.
## Hardware and release caveats
- The shipping 2720 Flip DTS/DTB is single-panel. The two-panel `/dev/fb1` layout is opt-in via
`scripts/build-beatles-cover-panel.py`; rollback is `scripts/build-beatles-no-cover-dtb.py`. Do not make it default
until gpio13 mux polarity and gpio21/gpio23 routing are physically probed: a live test darkened both screens.
gpio13 polarity is now TE-probed (high = cover, low = internal), but the two-panel DT remains opt-in.
The shipping image drives the external GC9305 through the kernel `panel-mipi-dbi-spi` driver while the flip is
**closed only** (`bananarchy-cover-idle`); never claim gpio13/23 or send cover SPI traffic while the flip is open,
gate initial activation on the main panel being DPMS-off, and always restore the mux on `LID OPEN`.
- The KaiOS 3.10 DTS gives both panels shared CS0, gpio110 D/C and one PWM backlight; gpio21 is TE and gpio23 is the
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
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
initramfs module lists, the Xorg `card0` pin, `bananarchy-cover-diagnose.sh`, and the
`scripts/test-cover-dt.py` / `scripts/test-cover-spidev.py` guards.
- The shipping cover backend is `backend = kernel`: keep `bananarchy-cover-dpms.sh reinit`, the gpio13 mux claim,
the 240x240 `/dev/fb0` damage rect, the 1 s repaint against Xorg, `kernel_backlight_invert = 1`,
`kernel_backlight_level = 14`, `scripts/test-cover-kernel.py`, and the `spidev`/`fb`/`none` rollback backends.
The daemon must restore the internal panel on `LID OPEN` even after a stale high gpio13 survives a restart.
- Keep the 2720 Flip lid handling event-driven and instant: sticky hall state, immediate hall re-read on `EV_SW`
edges, 20 ms debounce, and synchronous lid-state/lock/backlight/DPMS writes in `bananarchy-lid.c`. Closing locks
the desktop; opening must keep the lock flag and wake to the passcode lockscreen, never auto-unlock. Every
main-panel wake path must call `bananarchy-lid-gate.sh`; a closed flip may only light the cover.
`sxmo_state.sh set unlock` is gated too because `dwm` calls it directly. Guard `scripts/test-lid-gate.py`.
- Build the lk2nd display image from pinned `bootloader/lk2nd/nokia-beatles.patch`. Exact stock IDs, 512 MiB memory
fallback, appended DTB, `quiet splash`, and the low-bit reboot cookie matter. `check-lk2nd-beatles.py`,
`test-lk2nd-beatles-port.py`, `check-beatles-bootimg.py`, `sync-beatles-bootfs.py --check`, and `check-rebuild.sh`
guard the boot chain.
- Flash with `flash-edl.py`'s default `--method lk2nd`; stock `system` is wiped by default, so
recovery-mode 2720 boots need Volume Up. Keep the signed per-device Firehose programmers and do not mix them.
- Keep first-boot access intact: `keys/phone_id_ed25519.pub` for `user`/`root`, PAM/sshd configs, USB-only SSH fallback,
keypad udev/Xorg rules, BusyBox applet lists, and `scripts/set-bananarchy-hostname.sh`.
- The Power menu label is **Reboot to loader** and still calls `sxmo_power.sh bootloader`. Keep the compact label in
`dmenu.c`, `dmenu.so`, `sxmo_appmenu.sh`, and the context-menu hook.
- Bluetooth HOGP config and plugin load are verified, but full hardware sign-off still needs a wake-up paired keyboard
and **Connect Device** to confirm real HID key events.
## Coding and documentation rules
- Use 2-space indentation in C, C++, Python, Yabasic, and shell; tabs only in Makefiles and TSV. No emojis in code, UI
strings, logs, or commit messages; use Nerd Font PUA icons. Use sentence case in all docs.
- Keep `README.md`, `MANUAL.md`, `SDK.md` for API/SDK changes, `CHANGELOG.md`, and this guide synchronized with
user-facing features, keybindings, build changes, and verified image changes. Do not leave third-party `.md` files in
`src/` or `edl/`.
- Treat `.bantam.cfg` as local, gitignored credential data: never read, edit, commit, or unignore it. Keep other
agent scratch files outside the repo.
- Consult `SDK.md`, `MANUAL.md`, `X_KEYPAD_MAPPING.md`, `BATTERY-OPTIMIZATION-ANALYSIS.md`,
`bootloader/lk2nd/README.md`, and `CHANGELOG.md` for APIs, keymaps, flashing details, power tradeoffs, bootloader
history, and release rationale.