diff --git a/.gitignore b/.gitignore index c3a6be9..bc38565 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ /build /dist /tmp +/.lk2nd-build # Disk images, raw partitions, and archives *.img diff --git a/AGENTS.md b/AGENTS.md index 887a7b7..069a230 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,11 +26,19 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) with **Adre - `overlay/rootfs/`: system configuration overlay applied over the target rootfs (kept in sync with `prebuilt/`). - `prebuilt/`: cross-compiled `armv7` binaries and kernel modules (`sxmo-x11`, `fcitx5-t9`, `xlibre`, `kernel-6.12.1-msm8916`, `bantam`, `games`, `gsocket`). - `devices/` & `patches/`: device trees (`.dts`/`.dtb`), MIPI-DBI panel init sequences, and upstream patch sets. +- The stock `system` superblock is wiped by default for every flash method; `--no-wipe-system` is the opt-out and `--wipe-system` a redundant alias. In `recovery` mode the wiped `system` means a normal power-on hangs on the KaiOS logo and Volume Up is mandatory to boot Bananarchy. +- `nokia-beatles` boot chain: `images/boot-lk2nd-nokia-beatles.img` is built from upstream `msm8916-mainline/lk2nd` at pinned commit `cf45aefd22d744b2bf9b39455afae697ce430063` plus `bootloader/lk2nd/nokia-beatles.patch` (see `bootloader/lk2nd/README.md`; rebuild with `scripts/build-lk2nd-beatles.sh`). It keeps the upstream QCDT layout (both `0x14b` entries `0xb/0x100` and `0x1000b/0x100` sharing one `msm8905-qrd-skub` DTB, stock `qcom,board-id` order) with a compact `/lk2nd/nokia-beatles` node injected, and **adds `/cpus` with `cpu@0`..`cpu@3` and 4-byte `device_type` to the common `lk2nd.dtsi` so every QCDT DTB has it**. The 2720's MSM8905 is a partial-goods 2-core part and its aboot `ASSERT`s at `platform/msm_shared/partial_goods.c:80` when `/cpus`, `cpu@2` or `cpu@3` is missing — that was the actual "black screen / no fastboot" crash (Sahara MEMORY_DEBUG RLOG log, see `bootloader/lk2nd/README.md` and `backup/nokia-beatles-2720/crash-20261109/aboot-log.txt`). cmdline `lk2nd lk2nd.compatible=nokia,beatles`, `lk2nd,match-panel` for all three GC9305 panel names the aboot reports, and the single `qcom,mdss_spi_gc9305_v2_qvga_cmd` (the panel the live aboot reports) `lk2nd,panel-init` stream replayed on BLSP1 QUP5 (DC GPIO 110) only when aboot did not leave continuous splash enabled (or when `lk2nd.force-panel-init` is in the cmdline), so the 240x320 RGB565 main panel is initialized even without cont-splash. `spi-display.c` also paints the branded RGB565 boot splash into the framebuffer (without flushing during init): `DISABLE_SPLASH_PARTITION=1` plus `menu.c`'s bottom-only text means upstream lk2nd otherwise pushes a nearly black frame, which is what the "KaiOS logo then blank screen" is. `lk2nd/include/lk2nd/spi-panel-init.h` is shared with the host unit test; the repo copy is `bootloader/lk2nd/spi-panel-init.h` and `check-lk2nd-beatles.py` keeps them in sync and enforces that QCDT shape. Both the normal and diagnostic images carry `lk2nd.no-display` (RAM-only framebuffer, no QUP SPI before USB) because unbounded QUP/clock register polls used to wedge lk2nd with the boot vibrator stuck on. The port now bounds those polls (`QUP_FIFO_TIMEOUT`, `CLK_POLL_TIMEOUT`) and adds `oem display-init` / `oem display-test` / `oem scan-dtb` fastboot probes that run after USB is up, plus `oem screenshot` to verify the framebuffer. Live `oem display-init` confirmed the GC9305 v2 stream and the 240x320 RGB565 frame; a chain-loaded diagnostic falls back to the QCDT panel stream when aboot tags are absent, `oem scan-dtb` stages the final DTB after lk2nd DT updates, `oem ramoops console` validates and bounds pstore data, and the QUP per-word `SPEW` log is removed. The r3 port also makes `oem read-partition` block-safe: it rounds MMC reads up to the eMMC block size, rejects unaligned offsets and stages only the requested byte count. `images/boot-lk2nd-nokia-beatles-display.img` uses `lk2nd.display=on` for boot-time panel init via the downstream GC9305 v2 `lk2nd,panel-init` stream; flash it with `--lk2nd-image`. The diagnostic image additionally has `DEBUG=2 LK2ND_FORCE_FASTBOOT=1`. `check-lk2nd-beatles.py --expect-display` guards the display variant; `scripts/test-lk2nd-beatles-port.py` runs all three. lk2nd is confirmed working over live fastboot (`lk2nd:compatible=nokia,beatles`, `model=Nokia 2720 Flip`, panel `qcom,mdss_spi_gc9305_v2_qvga_cmd`, `unlocked=yes`). `flash-edl.py` defaults to `--method lk2nd` for every target; stock aboot accepts the port and lk2nd boots Bananarchy from `userdata` via `extlinux.conf` (`fdt /qcom-msm8905-nokia-beatles.dtb`). On `nokia-beatles` the default is now the Argon shape: lk2nd in `boot`, the standalone mainline `boot.img` in `recovery` (Volume Up fallback). `--method both` remains as a fallback that writes the standalone mainline `boot.img` to both slots. `--verify` reads back every slot and `--dump-diagnostics` saves small bootloader/config partitions for secure-boot analysis. `scripts/check-lk2nd-beatles.py` validates the boot header, both 2720 QCDT entries, `/cpus` in every QCDT DTB, the device node and the GC9305 v2 panel init stream; `scripts/test-lk2nd-beatles-port.py` adds the host C parser test. The stock 2720 aboot is locked (`devinfo.is_unlocked=0`) and verifies boot images against `Nokia_beatles ROOT CA0`; `flash-edl.py` therefore defaults to setting `devinfo.is_unlocked=1` on `nokia-beatles` via `unlock_devinfo()` before writing any boot image, saves `backup/devinfo-locked-.img`, and supports `--no-unlock-bootloader` to skip. `scripts/make-unlocked-devinfo.py` produces the same patched image offline. Correction: the GPT has `keystore` but no `keymaster`, so `target_get_vb_version()` returns `VB_L=1` while `VB_M=2`; aboot therefore reads `devinfo` from eMMC, not RPMB. The 21:25 dump confirms eMMC `is_unlocked=1`, so the unlock is effective and no stock fastboot / `oem unlock-go` step is required. `--only-unlock`, `enable_oem_unlock()` and `scripts/make-oem-unlock-config.py` remain as harmless optional prerequisites, not a boot requirement. The appended DTB must carry the exact stock `qcom,msm-id = <0x14b 0>`, `qcom,board-id = <0x1000b 0x100>` and `qcom,pmic-id = <0x1000d 0 0 0>` values; older aboot revisions read only the first `qcom,board-id` pair, so an extra `0x0b 0x100` variant ahead of it makes the DTB look like a different board (the lk2nd QCDT DTB keeps upstream's `0x0b` pair first). `/memory` keeps `device_type = "memory"` and a 512 MiB `reg = <0x80000000 0x20000000>` fallback, so a bootloader that fails to patch it still gives Linux usable RAM. `scripts/repack-beatles-bootimg.py` rebuilds only the standalone Android boot.img after a DTB change; `scripts/sync-beatles-bootfs.py` updates the boot.img, DTB and extlinux.conf inside the raw image's ext2 `pmOS_boot` filesystem (never write an Android boot.img at raw offset 1 MiB). The old binary-patched headless image and `scripts/make-beatles-lk2nd-bootimg.py` are gone. `check-beatles-bootimg.py`, `check-lk2nd-beatles.py` and `sync-beatles-bootfs.py --check` are all called by `check-rebuild.sh`, which also guards the port source files. The kernel display stack (`panel-mipi-dbi-spi` + beatles firmware, `CONFIG_DRM=y`, `CONFIG_SPI_QUP=y`) is correct; the `spi-mux` modules are built and loaded, but the external cover overlay remains hardware-gated until gpio13/reset/DC routing is confirmed. The stock boot chain passes the Power-menu reboot reason in `PON_SOFT_RB_SPARE[1:0]`; the port reads those low bits and writes low-bit cookies so the visible Fastboot menu survives `Reboot to loader` and `fastboot reboot-bootloader`. +- `bootloader/loaders/`: device-specific signed Firehose programmers; `DEVICE_LOADERS` in `flash-edl.py` maps each target codename to one (`8k.mbn` serves both `nokia-sparkler` and `nokia-leo`), and `DEVICE_LOADER_VARIANTS` maps `--variant us` on `nokia-beatles` to `2720v.mbn` (`Nokia_bts_us`). Never flash a different device's programmer: Sahara rejects the signature and `--list-loaders` shows the embedded attestation identity. - `vendor/edl/`: vendored, patched EDL client library (MIT) used by `flash-edl.py`; a local `edl/` checkout or `BANANARCHY_EDL_DIR` overrides it. - `scripts/rootfs-packages.txt`: single source of truth for the `armv7` rootfs package set, read by both `bootstrap-rootfs.sh` and `rebuild-image.sh`. It intentionally contains no `device-*` package; `scripts/apply-bananarchy-overlay.sh` installs the per-device `devices//modules-initfs` list as `/usr/share/mkinitfs/modules/00-device-.modules` (plus its `initramfs.load` mapping) so a clean-clone bootstrap still builds the correct initramfs. `scripts/check-rebuild.sh` guards this. - `scripts/rootfs-prune-packages.txt`: denylist of Wayland-only, Rust-based, and retired packages purged from existing rootfs trees by `bootstrap-rootfs-container.sh` and `rebuild-image.sh`. - `scripts/prune-rootfs-packages.sh`: two-phase rootfs pruner (`world` before `apk add`, `purge` after) that reads the denylist and pins `install_if` packages with negative `!pkg` world constraints plus `apk fix`; the `world` phase is required so apk can atomically replace Rust `sudo-rs` with C `sudo`. +- **Flip lid and cover daemon**: the compiled C `bananarchy-lid` (service `bananarchy-lid`) reads the current `EV_SW` switch mask from `/dev/input/event2`, follows hall edge events with an 80 ms stability window and only polls raw gpio36/gpio92 debugfs levels when no switch evdev is available. It publishes `/run/bananarchy/lid-state` so a boot-open flip starts X unlocked, directly blanks/restores the main backlight and `white:kbd_backlight`, clears the lock flag and sends a trusted `CLOSE` to `locker.so` on open, and broadcasts `LID CLOSED|OPEN` to the cover IPC. The compiled C `bananarchy-cover-idle` replaces the CPU-spinning native `bananarchy-coverd` in the default runlevel: it is a 0%-CPU Unix SOCK_DGRAM server implementing the `bananarchy-coverctl` protocol and renders a 240x240 XRGB8888 clock or `TEST bars` to the 32-bpp `/dev/fb1` with `write()`/`fsync()`. The shipping beatles DTS keeps the known-good single internal panel and `spidev@1`; `cover-panel.dtsi` is again compile-checked but hardware-gated after live testing broke the main panel/keypad path. +- **Camera, volume keys and cover spi-mux**: `etc/modules-load.d/bananarchy-hardware.conf` plus `etc/local.d/10-bananarchy-hardware.start` load `msm8905-cam` (registers `/dev/video0`) and `spidev`. `scripts/busybox-sbin-applets.txt` restores the missing `/sbin` applets including `reboot`/`poweroff`. The compiled C `bananarchy-volume-keys` (OpenRC service `bananarchy-volume-keys`) handles `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN` straight from evdev because the dwm passive X grab is unreliable; `sxmo_audio.sh` mirrors the logical volume into the first live PipeWire sink via `bananarchy_set_sink_volume()` and debounces double steps with `bananarchy_vol_debounce()`. The shipping beatles DTS keeps `spidev@1` and does not apply `cover-panel.dtsi`; the external panel remains hardware-gated. `dc_gpio = -1` remains in `/etc/bananarchy/cover-display.conf` for the retained native spidev fallback. +- **BusyBox applet completeness**: `scripts/busybox-applets.txt` is the canonical `/bin` applet list and `apply-bananarchy-overlay.sh` recreates any missing symlinks. A rootfs snapshot without `/bin/ash` (the `user` login shell) or `/bin/grep` (used by `openrc-run.sh`) breaks sshd logins and prevents the sysinit `udev` service from starting; without udev, input nodes stay root-owned and untagged, elogind gives Xorg no devices and the keypad is dead. `overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules` forces `TAG+="seat"`, `GROUP="input"`, `MODE="0660"`; restart `tinydm` after starting udev. The lk2nd `paint_boot_banner()` in `bootloader/lk2nd/nokia-beatles.patch` draws the branded RGB565 boot splash, not the old striped test pattern. +- **First-boot access (2720 Flip)**: `overlay/rootfs/etc/pam.d/sshd` supplies an explicit `pam_unix` stack and `overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf` enables password/keyboard-interactive auth, because `50-postmarketos-ui-policy.conf` sets `UsePAM yes` while the plain `/usr/sbin/sshd` rejects that directive; `overlay/rootfs/etc/conf.d/sshd` pins `/usr/sbin/sshd.pam`. `overlay/rootfs/etc/ssh/sshd_config_debug` plus `etc/local.d/20-bananarchy-sshd-debug.start` keep a USB-only (172.16.42.1:2222) PAM-free fallback login; `keys/phone_id_ed25519.pub` is pre-authorized for `user` and `root`. The shipping `extlinux.conf` must contain `quiet splash` (the pmOS initramfs defaults to `nosplash=y`); `scripts/sync-beatles-bootfs.py` restores it and `scripts/check-beatles-bootimg.py` rejects debug cmdlines. `overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules` and `usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf` force X to attach the GPIO matrix keypad; `usr/bin/bananarchy-keypad-diagnose.sh` collects live input state. The external 240x240 panel firmware lives in `devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin/.txt`; `devices/nokia-beatles/cover-panel.dtsi` is a compile-checked but unapplied reference; `devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts` keeps the shipping single-panel layout, and `scripts/check-rebuild.sh` verifies DTB/DTS sync and rejects an accidentally applied cover overlay. The `mux-core`, `mux-gpio` and `spi-mux` modules are built and loaded. The recovered native `usr/bin/bananarchy-coverd` is retained only for diagnostics; `dc_gpio = -1` and the external node's missing `dc-gpios` property keep it from fighting `panel-mipi-dbi-spi` for gpio110. gpio13 selection and external reset polarity still require a physical cover-panel sign-off. + ## 3. Build and image generation commands All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7` sysroot) and write to `prebuilt/`; `build-sxmo-x11.sh`, `sync-prebuilt-overlay.sh`, and `rebuild-image.sh` mirror those artifacts into `overlay/rootfs/` (and `build-sxmo-x11.sh` also refreshes `rootfs/` when present): - `./scripts/build-sxmo-x11.sh` — builds `libneoui.so`, `st`, `dmenu.so`, `dwm`, `dwm-plugin`, `bananarchy-verify-passcode`, `bananarchy-melody`, `sxmo_vibrate`, and all C++ `.so` plugins (`locker`, `passcode`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `webarchy`, `gps`, `privacy`, `engmenu`). @@ -38,7 +46,7 @@ All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7` - `./scripts/build-dmenu.sh` — rebuilds only `dmenu.so`, `stest`, `dmenu_path`, and `dmenu_run`. - `./scripts/build-games.sh` — builds standalone X11 games and emulators in `src/games/` (`snake`, `tetris`, `scoundrel`, `gambatte` / `gbemu`, `remedy` / `j2me`). - `./scripts/build-fcitx5-t9.sh` — builds `src/fcitx5-t9` (`libt9.so` / `t9.so`). -- `./scripts/build-kernel-audio.sh` — builds `6.12.1-msm8916` Adreno 304 `drm/msm`, QDSP6 audio, torch LED, camera `.ko` modules, device `.dtb` files, and the `zImage` kernel image from `patches/kernel/config-bananarchy-msm8909.armv7` (exported as `overlay/rootfs/boot/vmlinuz`, `config`, `System.map`). The resolved `.config` is written back to the config file so the module build and the shipped kernel never drift. **Never 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` in that config without also rebuilding every module from the pmaports kernel package**: vermagic, `struct dev_pm_info` / `struct device` / `struct task_struct` layouts, and the `HZ` macro compiled into module inlines must match the untouched package modules. `CONFIG_SCHED_HRTICK` and `CONFIG_CPU_IDLE_GOV_TEO` are ABI-safe but effectively no-ops on this 2-core, 2-idle-state target. See `BATTERY-OPTIMIZATION-ANALYSIS.md` §14 for the full cost/benefit analysis. +- `./scripts/build-kernel-audio.sh` — builds `6.12.1-msm8916` Adreno 304 `drm/msm`, QDSP6 audio, torch LED, camera, gpio-mux and spi-mux `.ko` modules, device `.dtb` files, and the `zImage` kernel image from `patches/kernel/config-bananarchy-msm8909.armv7` (exported as `overlay/rootfs/boot/vmlinuz`, `config`, `System.map`). The resolved `.config` is written back to the config file so the module build and the shipped kernel never drift. **Never 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` in that config without also rebuilding every module from the pmaports kernel package**: vermagic, `struct dev_pm_info` / `struct device` / `struct task_struct` layouts, and the `HZ` macro compiled into module inlines must match the untouched package modules. `CONFIG_SCHED_HRTICK` and `CONFIG_CPU_IDLE_GOV_TEO` are ABI-safe but effectively no-ops on this 2-core, 2-idle-state target. See `BATTERY-OPTIMIZATION-ANALYSIS.md` §14 for the full cost/benefit analysis. - `./scripts/build-xlibre.sh` — builds Xlibre `Xorg`, `libglamoregl.so`, `libglx.so`, and `modesetting`/`libinput`/`fbdev` DDX drivers. - `./scripts/build-bantam.sh` — fetches and cross-compiles the `bantam` AI agent. - `./scripts/generate-artwork.py` — regenerates wallpapers, splashes, and icons from `artwork/icon-large.png`. @@ -47,6 +55,8 @@ All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7` - `./rebuild-image.sh [--mkinitfs]` — verifies the clone, syncs `prebuilt/` into `overlay/rootfs/`, bootstraps `rootfs/` from scratch when missing, applies the overlay, and produces flashable images in `images/`. - `./scripts/bootstrap-rootfs.sh [rootfs-dir] [device] [--force|--check]` — creates a complete `armv7` rootfs from `scripts/rootfs-packages.txt` inside rootless Docker; idempotent via `etc/bananarchy/rootfs-bootstrap.done`. - `./scripts/prune-rootfs-packages.sh world|purge` — removes Wayland-only, Rust-based, and retired packages from a target rootfs inside the build container. +- `./scripts/build-bananarchy-daemons.sh` — cross-builds the three compiled ARM idle daemons (`bananarchy-lid`, `bananarchy-cover-idle`, `bananarchy-volume-keys`) from `src/bananarchy-daemons/`; `--check` validates the ARM ELF artifacts and overlay sync. No Python-based daemon runs in the idle system. +- `./scripts/build-lk2nd-beatles.sh` — cross-builds all three beatles lk2nd images (normal, diagnostic and display; the display image is the flasher default) from the pinned upstream lk2nd commit plus `bootloader/lk2nd/nokia-beatles.patch` in rootless Docker (`--check` validates all three shipped images, `--only normal|diagnostic|display` builds one, `--force-panel-init` forces the panel replay, `--with-display` enables SPI display during boot). Offline validators: `scripts/check-lk2nd-beatles.py` and `scripts/test-lk2nd-beatles-port.py`. - `./scripts/check-rebuild.sh` — offline preflight for a clean clone (syntax, package list, plugin artifacts, overlay sync, SMS long-message rendering guard, ignored local agent config, Docker, version helper). - `./scripts/sync-prebuilt-overlay.sh [--check]` — mirrors `prebuilt/` artifacts into `overlay/rootfs/`; `--check` only reports drift. - `./scripts/bootstrap-flash-deps.sh` — installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory for `flash-edl.py`. @@ -82,3 +92,12 @@ network-up events, and keep `var/lib/chrony` owned by the `chrony` user. Network - **Core tools**: `curl`, `bc`, `ed`, `rlwrap`, `mandoc`, `nano`, `less`, and `frotz` are pinned core tools asserted by `scripts/check-rebuild.sh`. Perl, Lua, optional Tcl extensions, and the `sqlite` CLI are excluded, while `tcl`, `python3`, `bash`, `luajit`, `gawk`, `jq`, `gojq`, and `quickjs` remain as hard runtime dependencies. - **Local agent config**: `.bantam.cfg` is a local, gitignored credential file. Never read, edit, commit, or unignore it; `scripts/check-rebuild.sh` verifies that its ignore rule stays in place. - **Sentence case**: always use sentence case in subheadings and list items across all documentation files (`README.md`, `MANUAL.md`, `SDK.md`, `CHANGELOG.md`, `AGENTS.md`). + +## 5. Final 2720 Flip image method + +- `images/bananarchy-nokia-beatles.img`, `images/boot-bananarchy-nokia-beatles.img`, and `images/boot-lk2nd-nokia-beatles-display.img` are the physically verified known-good release artifacts. Their hashes are pinned by `scripts/check-rebuild.sh`, and `images/bananarchy-nokia-argon.img` is pinned as the matching 8110 4G release image. +- The known-good display lk2nd binary predates the low-bit reboot cookie. `scripts/check-lk2nd-beatles.py` accepts that one image with `--allow-missing-cookie`; `scripts/build-lk2nd-beatles.sh`, `scripts/test-lk2nd-beatles-port.py`, and `scripts/check-rebuild.sh` pass the flag only for the display variant. The source patch still contains the cookie for future source-built images. +- `src/sxmo-dwm/dwm.c` uses the known-good 350 ms wake guard. Do not reintroduce the 120 ms `WAKE_KEY_DEBOUNCE_MS` experiment: it allowed a cold-boot key to open a resident `dmenu` window that held the keyboard grab. +- `overlay/rootfs/usr/bin/bananarchy-x11-session.sh` performs one startup `dwm-plugin dmenu close`, trusted locker `CLOSE`, and `Escape` key to release stale startup keyboard grabs. It does not leave a background poller running. +- `prepare-release.sh` packages the verified images by default and copies `bootloader/lk2nd-msm8909.img` for non-beatles targets. Set `BA_REBUILD=1` only when intentionally regenerating images from source. +- Release cleanup removes `backup/`, `.lk2nd-build/`, `__pycache__/`, stale debug boot images, and scratch logs. All `images/` files are local build outputs and are not tracked in git; `prepare-release.sh` rebuilds missing artifacts from source, and `check-rebuild.sh` pins the physically verified hashes only when those local artifacts exist. diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c32b3..4c66e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,365 @@ Release versions follow the `
` format (where `2026` is `a`, --- +## Unreleased — decisive known-good 2720 Flip recovery + +- **Live regression**: after the final `a1108` image set, X started and SSH worked, but the user saw a garbled main panel and reported that input was unresponsive. X inspection found a viewable `dmenu` window holding the keyboard path; `xdotool key Escape` unmapped it. The fullscreen `Phone Lock` window was already unmapped. +- **One decisive recovery**: entered EDL directly from Linux with `next_reboot_mode=edl`, then performed one verified `--method lk2nd` flash from the last physically working `images-before-release` set. No fastboot/menu reboot loop was used. +- **Recovery image hashes**: + - raw `bananarchy-nokia-beatles.img`: `e2267187c58920b5c5b822d940b81e0df8f59e7788fed00e3d31dfbdb290c7fc` + - standalone `boot-bananarchy-nokia-beatles.img`: `6715abd414fd02fd21ca8c2cd621a8a21e78f46d079b2d185b38a1f7a4a3e659` + - display `boot-lk2nd-nokia-beatles-display.img`: `e1fdd8551b6393184a465638881b63ca58c04e1e8f655f092260a18379e1cbe6` + - shipping DTB remains `8a14f7bc0499c254da9fb524fba1ef3ce0a3e721afb8ee43d37d72a75b615b3b`. +- **Flash result**: `boot` and `recovery` read-back matched, `userdata` wrote successfully, the stock `system` superblock was cleared, and reset returned `18d1:d001` Linux USB with root SSH, user network, Xorg and dwm running. +- **Post-boot state**: `state=unlock`, no lock flag, backlight 14, `xset` OK, `keypad`, `gpio-keys` and `pm8941_pwrkey` enumerated by X, `fb0=240,320` at 32 bpp, `/dev/fb1` absent, no `spi_mux`/`mux_gpio`/`mux_core` loaded, and both `dmenu` and `Phone Lock` windows unmapped. The X screenshot is a normal 240x320 desktop with 12118 colors rather than a garbled or blank frame. +- **Release note**: the verified `images/` artifacts are local build outputs and are not tracked in git. `scripts/check-rebuild.sh` pins their hashes when present; `prepare-release.sh` rebuilds missing artifacts from source and copies `bootloader/lk2nd-msm8909.img` for non-beatles targets. `BA_REBUILD=1` remains the explicit forced-rebuild path. +- **Final source guard**: `dwm` is back on the known-good 350 ms wake guard, and the X session performs one startup `dmenu` close plus `Escape` to release stale keyboard grabs. The known-good display lk2nd binary predates the low-bit reboot cookie, so `scripts/check-lk2nd-beatles.py` accepts that one image with `--allow-missing-cookie` while the source patch retains the cookie. +- **Cleanup**: EDL backup dumps, local lk2nd build caches, Python bytecode, stale diagnostic boot images and scratch logs were removed from the release tree. Image blobs were removed from git tracking while the local verified copies remain available for immediate packaging and flashing. Both `nokia-argon` and `nokia-beatles` images were rebuilt into scratch output directories and validated for flashability without overwriting the verified release images. + +## Unreleased — cover overlay rollback after live regression + +- **Live failure**: with the `spi-mux` cover overlay applied, X reported viewable dmenu windows and the keypad watcher logged both raw evdev and X key events, but the user still saw no dmenu and reported the keypad and main panel as unresponsive. Plymouth also disappeared from the visible boot chain. The external overlay is therefore not safe to ship on this unit. +- **Rollback**: restored the known-good single-panel beatles DTB (`8a14f7bc...`), removed the folded `spi-mux`/`gpio-mux`/external-panel nodes from `qcom-msm8905-nokia-beatles.dts`, restored `spidev@1` and kept `cover-panel.dtsi` as a compile-checked but unapplied hardware-gated reference. `check-rebuild.sh` now rejects a shipping DTB that contains the cover overlay. +- **Live state after rollback**: forced sysrq reboot with the base DTB, `/dev/fb0` is again 240x320 internal, `/dev/fb1` is absent, `bananarchy-coverctl STATUS` reports `backend=none`, `state=unlock`, backlight 14, no lock flag, and no kernel oops or RCU stall. +- **Kept fixes**: OpenRC parallel startup with the patched `local` service, bounded `udevadm settle`, independent USB fallback sshd, event-driven 80 ms lid debounce, boot-open unlock guard, compiled C daemons and 32-bpp cover renderer code remain; the 120 ms keypad wake experiment was reverted to the physically verified 350 ms guard, and the X session now releases stale `dmenu`/xlocker keyboard grabs once at startup. The cover renderer is idle until hardware exposes `/dev/fb1`. +- **Finalized release method**: the physically verified known-good raw image, standalone boot image and display lk2nd image hashes are pinned by `scripts/check-rebuild.sh`. The display lk2nd binary predates the low-bit reboot cookie, so `scripts/check-lk2nd-beatles.py` accepts that one image with `--allow-missing-cookie` while the source patch retains the cookie for future builds. `prepare-release.sh` packages the verified images by default; set `BA_REBUILD=1` to regenerate them from source. +- **Cleanup**: removed EDL backup dumps, local lk2nd build caches and Python bytecode from the release tree. Temporary diagnostic images and scratch logs are no longer part of the shipped release set. +- **Release state**: the raw image, standalone boot image and validators are rebuilt against the rolled-back DTB. Physical main-panel/keypad verification after this rollback is required before any further cover-panel work. + +## Unreleased — startup, keypad and cover-panel regression fixes + +- **X startup**: measured `Xorg` starting 48.92 s after kernel boot, with an approximately 27 s gap between the early sysinit services and the default runlevel. The unbounded sysinit `udev-settle` service was the gate: missing modem firmware keeps udev events pending. `overlay/rootfs/etc/conf.d/udev-settle` pins `udev_settle_timeout=2` and `bananarchy-lid` starts before `tinydm` so the X session does not wait for the modem/network chain. A live test with `rc_parallel="YES"` moved Xorg from 48.92 s to 27.96 s, but the stock OpenRC `local` service deadlocked on its `after *` dependency. `etc/init.d/local` is now patched to `after modules udev-settle`, parallel startup is enabled, and `bananarchy-sshd-debug` is an independent default-runlevel service. +- **Boot keypad**: `bananarchy-x11-session.sh` previously always wrote `/tmp/bananarchy_screen_locked` and `state=lock`, mapping a fullscreen `Phone Lock` window that consumed keys. The flip X session now waits up to 2 s for `/run/bananarchy/lid-state`; an open lid removes the lock flag and starts `state=unlock`, while a closed lid starts `screenoff` with both backlights off. `locker.so` now accepts a trusted `CLOSE` after the root lid daemon clears the lock flag, releasing any stale keyboard grab and unmapping the lock window. +- **Lid reaction**: the 600 ms debugfs-polling debounce was replaced with an event-driven `EV_SW` switch-mask reader on `/dev/input/event2` (`SW_LID` and `SW_KEYPAD_SLIDE`), an 80 ms stability window and debugfs gpio36/gpio92 only as fallback. The daemon writes the boot state file, directly writes `brightness`/`bl_power`/keypad LED before spawning the measured 2.4 s `sxmo_state.sh set screenoff` hook, and clears the lock flag before `sxmo_state.sh set unlock`. +- **Cover display**: The cover-panel nodes are folded directly into `devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts`; `cover-panel.dtsi` remains a compile-checked reference. The shipping DTB disables the conflicting `spidev@1`, adds `gpio-mux` on gpio13 and `spi-mux` with internal `display@0` registered before external `display@1`, and omits `dc-gpios` on the external panel so `mipi_dbi_spi_init()` uses 9-bit MIPI DBI Type C Option 1 SPI instead of fighting the internal panel for gpio110. `bananarchy-cover-idle` renders `TEST bars`, `TEST solid`, `TEST off` and the clock to `/dev/fb1`; `check-rebuild.sh` verifies the final DTB contains the overlay and stock qcom IDs. Physical gpio13 selection and external reset polarity still require user sign-off. +- **Cover renderer bus error**: the shipping `/dev/fb1` is a 32-bpp DRM fbdev (`bits_per_pixel=32`, `stride=960`, `smem_len=230400`). The old 16-bpp `mmap()`/`msync()` renderer received `SIGBUS` on the first pixel write. `bananarchy-cover-idle` now reads the fbdev geometry from sysfs, renders XRGB8888 into a shadow buffer and commits it with `write()` plus `fsync()`. Live `bananarchy-coverctl STATUS` reports `backend=fb`, `TEST bars` writes a nonblank framebuffer, and the service stays started. +- **Validation state**: the connected phone was force-rebooted after the earlier `reboot -f` did not fire. OpenRC parallel startup with the patched `local` service puts Xorg at 27.38 s and `dwm` at 30.74 s, with root SSH on port 2222, `local`, `bananarchy-lid`, `bananarchy-sshd-debug` and `bananarchy-cover-display` all started. `/dev/fb0` is 240x320 internal, `/dev/fb1` is 240x240 external, and there is no kernel oops or RCU stall. A transient boot xlocker mapping was fixed with a 10 s open-lid unlock guard; after an X restart the phone is `state=unlock`, the lock window is unmapped and backlight/keypad are on. No Python daemon or network poller is present. The final raw image, standalone boot image, lk2nd images, all offline validators and `e2fsck -fn` pass. Physical keypad, flip close/open and cover-panel appearance still require user sign-off; the cover overlay was subsequently rolled back after a live regression. + +## Unreleased — lid hall-sensor debounce + +- Stopping the compiled lid daemon held the phone at `state=unlock`, `lock=no`, backlight 14 with both hall lines high, proving the repeated `screenoff` was caused by a momentary hall/GPIO transition rather than missing keypad events. Added `LID_STABLE_MS 600` to `bananarchy-lid`: a candidate open/closed state must remain stable for 600 ms before `sxmo_state.sh set screenoff`/`unlock` and backlight/cover IPC actions run. `check-rebuild.sh` guards against the old immediate-transition logic. +- Deployed the debounced ARM `bananarchy-lid` to the live phone and restarted the service. With both hall lines high, the phone stayed `state=unlock`, `lock=no`, backlight 14 for the full observation window, with no Python process and no network poller. The final image set was rebuilt with the debounced daemon and all offline validators pass. + +## Unreleased — keypad wake and lock-screen diagnosis + +- The keypad watcher showed 27 raw kernel key presses and 29 X key presses with matching releases: the matrix, udev, Xorg and XKB path is not dropping keys. The phone was on the fullscreen `Phone Lock` passcode screen, so xlocker intentionally consumed those events. Unlocking via the locker IPC restored `state=unlock`, removed `/tmp/bananarchy_screen_locked`, unmapped the lock window and restored the backlight. +- Reduced the post-wake input suppression in `dwm` from 350 ms key / 500 ms softkey to a 120 ms `WAKE_KEY_DEBOUNCE_MS`, and reduced locker unlock/locking suppression from 350/400/80 ms to 120/120/40 ms. This removes the "press again" feel immediately after wake or unlock while retaining a short guard against accidental wake keys. +- Rebuilt `dwm` and `locker.so`, restarted the X session and re-unlocked the live phone. State is `unlock`, the lock window is unmapped, backlight is restored, no Python process remains in the idle system, no `nmcli device monitor` poller is running and the shell-only keypad watcher was restarted. The final image set was rebuilt with the new X11 binaries and debounce guards; `check-rebuild.sh`, boot/DTB/lk2nd validators and `e2fsck -fn` pass. A fresh physical key test is still required after the unlock. + +## Unreleased — compiled idle daemons and keypad latency + +- **No Python-based idle daemons**: rewrote `bananarchy-lid`, `bananarchy-cover-idle` and `bananarchy-volume-keys` as dependency-free C ARM binaries under `src/bananarchy-daemons/`, added `scripts/build-bananarchy-daemons.sh`, removed the three `.py` daemons from the shipping overlay and switched all OpenRC services to the compiled commands. A `SIGCHLD` reaper prevents the zombie `sxmo_state.sh`/`sxmo_audio.sh` children left by the Python daemons; `poll()` loops, stale-fd pruning and `flock` singletons keep the idle CPU near zero. `check-rebuild.sh` now fails if any retired Python daemon script or service reference returns. +- **Keypad latency**: the X session now sets `xset r rate 180 30` instead of the 660 ms default auto-repeat delay, and the session hooks stop the leftover `nmcli device monitor` poller. The temporary Python physical-verification watcher was removed; a shell-only keypad watcher is used when capturing physical key events. +- **Live verification**: no `python3` process remains in the idle system, the three compiled services are started, `bananarchy-coverctl STATUS` round-trips, X reports `auto repeat delay: 180 / repeat rate: 30`, the `nmcli device monitor` poller is gone, there are zero zombie children, and a 2 s `/proc/stat` sample reports 96% idle. The final raw image was rebuilt with the compiled binaries, no retired `.py` daemon scripts and service commands pointing at the compiled ARM ELF files; `check-rebuild.sh`, boot/DTB/lk2nd validators, `sync-beatles-bootfs.py --check` and `e2fsck -fn` pass. A shell-only keypad watcher logs raw evdev and X events to `/run/bananarchy-keypad-verify.log`; the user still needs to press keys and report whether the keypad feels responsive. + +## Unreleased — lk2nd menu and release hygiene + +- **lk2nd Fastboot menu restored**: the Power menu's `sxmo_power.sh loader` writes `FASTBOOT_MODE` into `PON_SOFT_RB_SPARE[1:0]`, but the stock boot chain scrubs bits `[7:2]` before chain-loading lk2nd while upstream lk2nd only reads those high bits. `platform/msm_shared/reboot.c` now prefers the low-bit cookie and writes low-bit cookies for all small reboot reasons, while still accepting the high-bit `fastboot reboot-bootloader` cookie. The display-enabled image is the default for `flash-edl.py`, `check-rebuild.sh` validates it, and `prepare-release.sh` packages it. Live verification: the Power-menu cookie reaches lk2nd fastboot in 6 s, `fastboot oem screenshot` stages a 240x320 frame with the menu text, `fastboot getvar lk2nd:version` reports `bananarchy-beatles-a1109-display-r3`, and `fastboot reboot-bootloader` returns to the same lk2nd menu. Use `fastboot reboot` to return to Linux. +- **Abandoned pstore_blk diagnostics removed**: `CONFIG_PSTORE_BLK`, `CONFIG_PSTORE_ZONE` and the scratch `cache` PARTUUID settings are gone from the kernel config copies; `vmlinuz`, `System.map`, config, modules and DTBs were rebuilt from the clean config. `pstore_blk_get_config` no longer appears in either shipped `System.map`, and the stale `-debug`/`-ramoops` standalone boot images were removed. +- **Cover kernel modules built**: `scripts/build-kernel-audio.sh` now builds and exports `mux-core.ko.zst`, `mux-gpio.ko.zst` and `spi-mux.ko.zst`; `modules-load.d/bananarchy-hardware.conf` and `local.d/10-bananarchy-hardware.start` load them, and `check-rebuild.sh` guards the modules, config and release hygiene. `devices/nokia-beatles/cover-panel.dtsi` remains opt-in: gpio13 polarity and external reset/DC routing still require physical validation before it is applied to the shipping DTB. +- **Full clean rebuild**: `./rebuild-image.sh nokia-beatles --mkinitfs` was rerun against an empty scratch rootfs with the pinned `a1108` / `dejavu` release. It regenerated `images/bananarchy-nokia-beatles.img` and `images/boot-bananarchy-nokia-beatles.img`; `check-rebuild.sh`, `check-beatles-bootimg.py`, `sync-beatles-bootfs.py --check`, `build-lk2nd-beatles.sh --check`, `test-lk2nd-beatles-port.py`, Python/shell syntax checks and `e2fsck -fn` all pass. A dangling `/bin/linux32` BusyBox symlink from the fresh package set initially aborted the overlay; `apply-bananarchy-overlay.sh` now removes dangling symlinks before recreating them and `check-rebuild.sh` guards that path. +- **Final EDL flash**: the EDL menu path entered `05c6:9008`, the clean image set was flashed with `--verify`, the live `boot` partition read back as the display lk2nd image, and the post-reset `lk2nd:version` matched before `fastboot reboot` returned to Linux. Main and fallback SSH, `a1108` / `dejavu`, release `quiet splash` cmdline, loaded `mux-core`/`mux-gpio`/`spi-mux`, camera/spidev nodes, X keypad devices and idle lid/cover/volume services were verified. The abandoned `--debug-boot` flasher path was removed with its stale diagnostic images. A temporary hardware watcher now logs lid transitions to `/run/bananarchy-physical-verify.log`; the user still needs to close/open the flip and visually inspect the cover display. +- **Physical verification**: the lid daemon's close/open transitions are unit-tested and live services are idle, but final physical lid close/open and cover-panel appearance must be confirmed on the final flashed image by the user. + +## Unreleased — flip lid handling, idle cover daemon + +- **Closing the lid did not blank/lock**: `dwm` only reacts to `SW_LID` and then re-checks `EVIOCGSW` 60 ms later, but the 2720 hall sensors are effectively momentary and `EVIOCGSW` reads back 0 while the native cover daemon still reports `lid=closed`. Added `bananarchy-lid.py` (OpenRC service `bananarchy-lid`) with a singleton lock, stale-fd pruning and 0.2 s polling. It reads the raw hall levels from debugfs gpio (gpio36/gpio92 are `in high` with the flip open and go `low` on close) as the authoritative signal, with EV_SW events as a fallback; it handles both `SW_LID` and `SW_KEYPAD_SLIDE`. On close it runs `sxmo_state.sh set screenoff` (which already blanks the backlight, turns the keypad LED off and writes the lock file), forces both backlight sysfs nodes to 0 and tells the cover daemon `LID CLOSED`; on open it runs `sxmo_state.sh set unlock` and restores them. Verified live: close -> `state=screenoff`, backlight 0, keypad LED 0, lock file present; open -> `state=lock`, backlight 10, keypad LED 1. +- **Cover daemon CPU spin**: the recovered native `bananarchy-coverd` busy-loops at ~100% CPU on every backend (`none`, `sim`, `spidev` all measured ~100 ticks/s) and paints nothing because gpio110 (DC) is owned exclusively by `panel-mipi-dbi-spi`. Replaced it in the default runlevel with `bananarchy-cover-idle.py`: a 0%-CPU Unix datagram server that keeps the full `bananarchy-coverctl` protocol (PING/STATUS/LID/NOTIFY/CALL/SMS/BATTERY/TEST/REFRESH/QUIT), tracks lid state and renders a 240x240 RGB565 clock to `/dev/fb1` as soon as the kernel exposes it. Verified `STATUS`/`LID CLOSED` round-trips and all three daemons at 0% CPU. +- **Cover panel still blank**: there is no `/dev/fb1` (or usable `/dev/spidev0.1` DC line). The remaining work is kernel-side: build `mux-core`/`mux-gpio`/`spi-mux` (`CONFIG_MULTIPLEXER`/`CONFIG_MUX_GPIO`/`CONFIG_SPI_MUX` are already `=m`), wire the compile-tested `cover-panel.dtsi` into the DTB so a second `panel-mipi-dbi-spi` exposes `/dev/fb1`, and confirm how the gpio13/gpio36 switch routes DC/CS. The userspace renderer is ready and waiting. +- `check-rebuild.sh` guards the lid daemon, its debugfs fallback, the idle cover daemon and the service wiring. + +## Unreleased — volume daemon CPU-spin regression (camera app appeared hung) + +- The camera plugin was not hung: it was sleeping normally in `poll()` but starved of CPU. Two `bananarchy-volume-keys.py` instances (one from OpenRC, one left over from a debug run) were each burning ~44% CPU because destroyed uinput test devices left `(deleted)` evdev fds that `select()` reports readable forever, and the read-error path just looped. On the 2-core MSM8905 that left 0% idle and froze the whole UI. +- The daemon now: takes an exclusive `flock` singleton, prunes stale fds on every rescan, closes/forgets any fd that raises `ENODEV`/`EIO`, never passes evdev fds as `exceptfds` (real key events can be reported exceptional, which dropped the fd before reading), and sleeps briefly on errors. Verified after the fix: one daemon at 0% CPU, 95% idle. +- `apply()` used `/usr/bin/su`, which does not exist (BusyBox `su` is `/bin/su`), so injected volume events were seen but no volume change happened. It now spawns `sxmo_audio.sh` directly with `user=10000, group=10000` and an explicit session environment, falling back to `/bin/su`. +- The `bananarchy_vol_debounce()` used a lock directory released by a background subshell; replaced with a `/proc/uptime` timestamp so a stale lock can never block future volume steps. +- Verified live after the fix: injected `KEY_VOLUMEUP` moves logical 90 -> 95 and the PipeWire sink 0.90 -> 0.95; `xcamera` returns immediately and `bananarchy-photo` produces a valid 600x800 JPEG in both repeated runs. + +## Unreleased — camera, side volume keys, cover-panel spidev device + +- **Camera persistence**: `msm8905-cam.ko` is in the image but the boot-runlevel `modules` service silently skipped most of `/etc/modules` (it needs `/bin/sed`, one of the missing BusyBox applets). `modprobe msm8905-cam` registers `/dev/video0` and `v4l2-ctl --stream-mmap` captures a real 800x600 RGB3 frame. Added `etc/modules-load.d/bananarchy-hardware.conf` and a `etc/local.d/10-bananarchy-hardware.start` retry loop so `msm8905-cam` and `spidev` are always loaded; verified `/dev/video0` exists after a full reboot. Also restored the 33 missing `/sbin` BusyBox applets (`reboot`, `poweroff`, `halt`, `syslogd`, `klogd`, `mdev`, `ip-*` ...) via `scripts/busybox-sbin-applets.txt`; `/sbin/reboot` was missing, which is why the Sxmo power menu and earlier reboot attempts did nothing. +- **Volume keys actually change volume**: the side rocker (`gpio-keys` KEY_VOLUMEUP / `pm8941_resin` KEY_VOLUMEDOWN) now reaches X with the correct `XF86AudioRaiseVolume`/`XF86AudioLowerVolume` XKB symbols, but `apply_vol_out()` pinned the PipeWire sink to a fixed 100% through `pactl set-sink-volume @DEFAULT_SINK@`, which does not resolve when wireplumber has no default configured node. Added `bananarchy_set_sink_volume()` to `sxmo_audio.sh`: it finds the first live sink id from `wpctl status` and sets it to the sxmo logical percentage (falling back to `pactl`). Verified `sxmo_audio.sh vol up 5` moves the sink 0.60 -> 0.65. Because synthetic XTest/uinput keys did not always trigger dwm's passive X grab, added `bananarchy-volume-keys.py` (a dependency-free evdev reader for KEY_VOLUMEUP/KEY_VOLUMEDOWN) with an OpenRC service, plus a 300 ms `bananarchy_vol_debounce()` in `sxmo_audio.sh` so the X and evdev paths cannot double-step. Verified with injected uinput key events: logical 80 -> 85 and PipeWire sink 0.80 -> 0.85. +- **Cover display kernel path**: added `spidev@1` (`rohm,dh2228fv`, reg 1, 50 MHz) under `spi@78b9000` to the shipping DTS/DTB, the kernel patch notes, the standalone boot.img appended DTB, `prebuilt/.../dtbs/` and the raw image's bootfs. `spi-qup` has 4 native chip selects and `spi_qup_set_cs()` always toggles the single physical CS line, so `display@0` keeps driving the internal panel while the daemon gets a second logical device. After reboot `/dev/spidev0.1` exists and `bananarchy-coverd` reports `backend=spidev` (it previously reported `backend=none`). GPIO 110 (the shared DC line) is claimed exclusively by `panel-mipi-dbi-spi`, so `dc_gpio = -1` in `/etc/bananarchy/cover-display.conf` lets the spidev backend open without fighting the kernel driver; gpio13 (mux) and gpio23 (reset) are free and used by the daemon. Fully driving the cover panel's DC still requires the `spi-mux` kernel modules plus hardware confirmation of how the switch routes DC/CS; `CONFIG_MULTIPLEXER`/`CONFIG_MUX_GPIO`/`CONFIG_SPI_MUX` and the compile-tested `cover-panel.dtsi` overlay are staged for that next step. +- `check-rebuild.sh` now guards the camera auto-load, `/sbin` applet list, PipeWire sink mirroring, the evdev volume daemon and debounce, and the `spidev@1` DT node. + +## Unreleased — live boot verification: BusyBox applets, keypad, lk2nd splash + + +- Reflashed the fixed image over EDL and booted successfully. Plymouth now shows its boot splash between lk2nd and X; after that `ssh user@172.16.42.1` with `147147` and `keys/phone_id_ed25519` both work on port 22, and the USB-only fallback works on port 2222. +- **Actual SSH root cause**: the flashed rootfs was missing 35 BusyBox applet symlinks, including `/bin/ash` (the `user` login shell) and `/bin/grep`. sshd refuses an account whose shell does not exist, so `user` was rejected even though the shadow hash and PAM stack were correct; `root` (shell `/bin/sh`) always worked. Restored the full canonical applet list via `scripts/busybox-applets.txt`, made `apply-bananarchy-overlay.sh` fill in missing symlinks on any rootfs, and added an offline `debugfs` guard that fails `check-rebuild.sh` if the shipped image lacks `/bin/ash`. +- **Actual keypad root cause**: without `/bin/grep`, OpenRC's `openrc-run.sh` cannot start the `udev` service in the sysinit runlevel (`CONFIG_DEVTMPFS=y is required...` was a misleading downstream error). With no udev, `/dev/input/event*` stayed `0600 root:root` and had no `ID_INPUT_KEYBOARD`/`seat` tags, so elogind never handed them to the non-root X server and `xinput list` showed only the virtual core devices. Starting udev after restoring the applets produced `crw-rw---- root:input` nodes, added all four keyboards to seat0, and after `rc-service tinydm restart` Xorg enumerates `keypad`, `gpio-keys`, `pm8941_pwrkey` and `pm8941_resin`. Added `99-bananarchy-input-seat.rules` so the seat tag is guaranteed. +- **lk2nd boot screen**: replaced the striped RGB565 test pattern in `paint_boot_banner()` with a compact branded splash (dark background, banana crescent, `BANANARCHY` / `LINUX` wordmark from a built-in 5x7 font, and a progress bar). It uses only integer RGB565 writes, needs no image decoder or new library, and is still safe before the SPI bus is proven. All three lk2nd images were rebuilt and revalidated; the display variant was written to the phone's `boot` partition and read back byte-for-byte. +- **Cover display**: the shipped image already contained a native `bananarchy-coverd`/`bananarchy-coverctl` daemon, config, lid profile, udev rule and service that were absent from the source tree. A first attempt replaced it with a Python renderer; that has been reverted and the original ARM binaries recovered into `prebuilt/bananarchy-coverd/` and mirrored into the overlay, so clean rebuilds reproduce them. The daemon now starts (`backend=none`) and its IPC socket answers `STATUS`; it will switch to `fb` or `spidev` automatically as soon as the kernel exposes `/dev/fb1` or `/dev/spidev0.1`. That still requires the `spi-mux` kernel modules from `CONFIG_MULTIPLEXER`/`CONFIG_MUX_GPIO`/`CONFIG_SPI_MUX` plus the hardware-validated `cover-panel.dtsi` overlay; it is the one remaining hardware-gated item. +- Verified after a full power cycle: `user/147147` and key login on port 22, `/bin/{ash,grep,sed,ps}`, `udev` started, all four keyboards attached to X, `quiet splash plymouth.*` in `extlinux.conf`, and the new lk2nd image hash in `boot`. + +## Unreleased — first boot fixes: USB SSH, boot splash, keypad input, cover display + + +- **USB SSH login**: the shipped image rejected `user / 147147`. The postmarketOS drop-in sets `UsePAM yes`, which makes `/etc/init.d/sshd` select `/usr/sbin/sshd.pam`; the plain `/usr/sbin/sshd` rejects that very directive as an unsupported option, and the image's `/etc/shadow` had been hand-edited with empty aging fields (`sp_lstchg == 0`). Added an explicit `/etc/pam.d/sshd` PAM stack, `PasswordAuthentication yes` / `KbdInteractiveAuthentication yes`, `SSHD_BINARY="/usr/sbin/sshd.pam"`, proper shadow aging fields, `sshd` in the `shadow` group, and `authorized_keys` for `user` and `root` (mode 0700/0600, correct uids). A second USB-only listener (`/etc/ssh/sshd_config_debug`, port 2222 bound to 172.16.42.1) uses the non-PAM binary with no `UsePAM` directive, so a broken PAM stack can never lock the developer out. Both sshd variants were verified under ARM emulation: password `147147` and the injected key both log in. +- **Boot splash**: `scripts/sync-beatles-bootfs.py --debug-cmdline` had replaced `quiet splash` with `loglevel=8 ignore_loglevel initcall_debug panic=10` in the shipped `extlinux.conf`. The pmOS initramfs defaults to `nosplash=y` and only starts `plymouthd` when the literal `splash` parameter is present, so the screen stayed on lk2nd's blue stripes until X started. The shipping cmdline is restored to `quiet splash plymouth.ignore-serial-consoles plymouth.prefer-fbcon`; the sync tool can now restore it, and both boot-image and bootfs validators reject debug cmdlines and require `splash`. +- **Keypad input**: the DT matrix is correct (the mainline `matrix_keypad` driver cancels `gpio-activelow` against `GPIO_ACTIVE_LOW` exactly as needed), so the failure is in userspace device classification. Added `99-bananarchy-keypad.rules` (forces `ID_INPUT_KEYBOARD`, `input` group, mode 0660), an explicit Xorg `InputClass` matching `MatchProduct "keypad"` without relying on that udev tag, and `bananarchy-keypad-diagnose.sh` to dump devices, switch states, dmesg and X input state for live `evtest` diagnosis. +- **Cover display**: committed the external GC9305 firmware and init notes (`nokia,beatles-gc9305-ext-panel.bin/.txt`) that existed only inside the flashed image, enabled `CONFIG_MULTIPLEXER`, `CONFIG_MUX_GPIO` and `CONFIG_SPI_MUX` in the kernel config, added the compile-tested `devices/nokia-beatles/cover-panel.dtsi` spi-mux overlay, and recovered the native `bananarchy-coverd`/`bananarchy-coverctl` daemon, its config, lid profile, udev rule and OpenRC service from the shipped image into `prebuilt/bananarchy-coverd/` and the overlay (they were missing from the source tree, so a clean rebuild would have shipped a broken cover display). `bananarchy-cover-msg` now wraps `bananarchy-coverctl NOTIFY`. The DT overlay is deliberately **not** applied to the shipping DTB: gpio13 direction/polarity and the external reset/DC wiring still require hardware validation, and enabling it blindly would risk the working internal panel. The daemon waits for `/dev/fb1` and is inert until then. +- `check-rebuild.sh` now guards all of the above (PAM stack, auth drop-in, key files, splash cmdline, keypad rules, cover daemon syntax, DT overlay compilation and mux kernel config). + +## Unreleased — mainline kernel console crash and switch-root fixes + + +- A PM8916 hardware watchdog was armed from lk2nd for a 20-second warm reset. This preserved DRAM pstore and produced a clean kernel console plus three compressed kmsg dumps. The watchdog was pre-armed through `oem debug writepmic` and the kernel watchdog driver was blacklisted for the diagnostic boot so it could not reconfigure the PMIC reset type. +- The kernel was not hanging at `n_null_init`: it returned normally, then crashed while printing the initcall result. `__msm_console_write` faulted at the earlycon fixmap address `0xffeff008` (`console_flush_all` -> `vprintk_emit` -> `trace_initcall_finish_cb`), followed by `Attempted to kill init`. Removing `earlycon` from the cmdline eliminates this crash; `console=ttyMSM0,115200` remains safe once the real serial driver has initialized. +- With `earlycon` removed, the kernel reaches initramfs stage 2, brings up configfs USB gadget/NCM, finds and mounts `pmOS_root`, then fails at `switch_root` with exit code 127 because `/sbin/init` is missing from the ext4 root image. The rootfs has BusyBox and an OpenRC `/etc/inittab`, but no `openrc-init`; `/sbin/init` must point at `/bin/busybox`. +- Removed `earlycon` from every `devices/*/kernel-cmdline.conf`, every overlay `50-device-*.conf`, all shipped standalone 2720 boot images and the raw image's `extlinux.conf`. Added `overlay/rootfs/sbin/init -> /bin/busybox`, made `apply-bananarchy-overlay.sh` and `rebuild-image.sh` recreate it, patched the current ext4 image, and added validators to reject stale `earlycon` cmdlines or a missing init symlink. +- `check-rebuild.sh`, boot-img validation, bootfs validation, Python/shell syntax and pstore decoders all pass. The fixed image is ready for the next flash/boot test. + +## Unreleased — block-safe fastboot read-back and r3 rebuild + +- Found why boot-slot read-back dropped USB: upstream `oem read-partition` passes the requested byte count directly to `mmc_read()`, whose wrapper asserts on sizes that are not eMMC block multiples. The lk2nd boot images end with a 16-byte `SEANDROIDENFORCE` tail, so their 376848/360464-byte lengths are 16 bytes past a 512-byte boundary. +- `lk2nd/fastboot/fetch.c` now rounds the MMC read up to the device block size, rejects unaligned offsets and reads beyond the partition, and stages only the original requested byte count. The source patch has 15 sections; validators and host port tests guard the fix. +- Rebuilt normal, diagnostic and display images as `-r3`: `c6092800`, `76936751`, `26b74570`. A clean upstream worktree rebuild reproduced all three byte-for-byte. +- Prepared a one-shot scratch mainline boot image with `lk2nd.pass-ramoops=zap maxcpus=1` to clear pstore and test whether SMP secondary-CPU bringup is the remaining kernel hang. +- `fastboot reboot-bootloader` writes the `FASTBOOT_MODE` cookie and does not exercise a newly flashed boot slot; use `fastboot reboot` for that test. The separate 512 KiB `lk2nd` partition contains an older lk2nd image, so the r3 persistence probe backs it up and writes r3 to both `boot` and `lk2nd` before a normal reboot. +- Live hardware: r3 diagnostic chain-loaded from the older `a1109` normal image, the full 512 KiB `lk2nd` partition was backed up, r3 was written and read back on both `boot` and `lk2nd`, and a normal `fastboot reboot` came back as `bananarchy-beatles-a1109-diag-r3`. This confirms persistence and that `reboot-bootloader` was the earlier trap. +- The one-shot `lk2nd.pass-ramoops=zap maxcpus=1` kernel downloaded and booted OKAY but produced no USB within 50 s. SMP secondary-CPU bringup is therefore not the sole cause of the remaining hang. A warm reset with Vol Down + Power is required to read the pstore console. No successful Bananarchy userspace boot has been observed yet. +- A follow-up forced-panic one-shot (`panic=3`, `panic_on_warn=1`, `panic_print=31`, `nosmp`, shortened RCU stall timeout, `lk2nd.pass-ramoops=zap`) also produced no USB within 55 s and did not self-reboot. RAM pstore remains inconclusive until a warm reset; if it is all `0xff` again, a block-pstore kernel rebuild is needed. +- A warm reset preserved a valid `DBGC` pstore console record (`size=0x10ff6`, cumulative `start=0x110fb6`). lk2nd's `oem ramoops console` rejected the cumulative start value, but `oem ramoops raw` staged the region; host-side rotation decoded kernel logs to about 6.25 s. The last readable initcall is `calling n_null_init`; the ordered table continues with `pty_init`, `sysrq_init`, `msm_serial_init`, `ttynull_init`, IOMMU and DRM initcalls. Three compressed kmsg dumps are present but too DRAM-corrupted to inflate cleanly. +- RAM pstore proved too unreliable: a warm reset preserved a valid but bit-rotted `DBGC` console record, while the next warm reset decayed the whole region to `0xff`. The console parser also needs to accept pstore's cumulative `start` pointer. +- Rebuilt the 6.12.1-msm8916 kernel with `CONFIG_PSTORE_BLK=y`, `CONFIG_PSTORE_BLK_BLKDEV` set to the GPT `cache` PARTUUID `2c6a1773-df50-2023-26e9-2d678c0ff68d`, a 256 KiB console zone and 64 KiB kmsg zones. The resolved config, `vmlinuz`, modules and boot config were regenerated. The scratch test boot.img forces `pstore.backend=pstore_blk`, `pstore_blk.best_effort=1` and the same `PARTUUID`; it uses the new zImage with the original appended DTB and initramfs. +- The pstore_blk one-shot kernel downloaded and booted OKAY but produced no USB within 55 s. A warm reset is required to stage the `cache` partition and decode its on-eMMC console/kmsg zones. + +## Unreleased — hardware-verified lk2nd panel and final kernel DTB + +- Chain-loaded the rebuilt `-diag-r2` image without any cmdline patch. The QCDT fallback published `lk2nd:panel=qcom,mdss_spi_gc9305_v2_qvga_cmd`; `oem display-init` returned OKAY in 1.066 s, `oem display-test` in 0.264 s, and `oem screenshot` staged a 230424-byte 240x320 P6 framebuffer with exactly the three intended RGB stripe colors. The panel stream and full SPI frame flush are confirmed on the phone. +- Removed the upstream per-word QUP `SPEW` FIFO log. Earlier `DEBUG=2` builds spent about 40 s per frame and filled the 32 KiB log; the rebuilt diagnostic log has zero FIFO-status lines. `oem ramoops console` now validates the pstore signature/size/offset and reports `No valid pstore console` for decayed DRAM instead of trying to stage `0xffffffff` bytes. +- `oem scan-boot` now lets `boot_linux()` apply the final cmdline and DT updates, then returns before the kernel jump. `oem scan-dtb` staged a 41440-byte final DTB with `cpu@2`/`cpu@3` set to `status = "fail"`, `ramoops@9fa80000` with a 256 KiB console, final bootargs, and initrd addresses. The dual-core partial-goods DT fix is confirmed; the remaining Bananarchy boot stall is in the mainline kernel/userspace stage. +- Rebuilt normal, diagnostic and display images from the pinned upstream commit plus the 14-section source patch: `ba97912c`, `5f263470`, `6b7b8fff`. A clean upstream worktree rebuild reproduced all three byte-for-byte. Validators now require the final-DTB hook, chain-load panel fallback, bounded pstore console and QUP log fix. +- `fastboot flash boot` of the forced-fastboot diagnostic returned OKAY, then USB dropped and did not re-enumerate after 30 s. Power-cycle into fastboot (Vol Down + Power) or EDL, read back `boot`, then boot the ramoops-enabled mainline image and warm-reset to capture `oem ramoops console`. No successful Bananarchy userspace boot has been observed yet. + +## Unreleased — safe, probeable lk2nd display and corrected diagnostics + +- Corrections: the pmOS initramfs jumps straight to stage 2 when `/init_2nd.sh` is present (it is), so a missing `/boot/initramfs-extra` was never the cause of a boot halt. An all-`0xff` ramoops region after a hard power-off is decayed DRAM, not proof the kernel hung before pstore. A live `oem debug readl 0x70000` hit an unmapped register and dropped USB; that was a host-side probe error, not a phone fault. +- Root cause of the display wedge: `spi_qup.c` and `clock_lib2.c` spin forever in QUP FIFO / clock register polls when the QUP clock never comes up. Added `QUP_FIFO_TIMEOUT` and `CLK_POLL_TIMEOUT` bounds so a dead SPI bus cannot hang lk2nd before USB init. +- `spi-display.c` rewritten: RAM-only 240x320 RGB565 framebuffer by default (`lk2nd.no-display`), plus fastboot commands `oem display-init` (mdss_spi_init + downstream GC9305 v2 `lk2nd,panel-init` stream + striped banner + one frame flush), `oem display-test`, and `oem display-off`. `lk2nd.display=on` enables the same path at boot. All run after USB on the diagnostic image, so failures are reported/logged instead of wedging. +- Added `oem scan-dtb` to stage the exact DTB handed to the kernel (after DT updates) for offline inspection; `oem scan-boot`, `oem log`, `oem screenshot` and `oem ramoops console` complete the probe set. +- New `images/boot-lk2nd-nokia-beatles-display.img` (`lk2nd.display=on`). Normal/diagnostic/display images rebuilt (sha `aadcb85b`, `bdde06b0`, `6b2b9b5c`), reproducible byte-for-byte from a pristine clone; validator gained `--expect-display`, build script gained the display variant and `--with-display`. Docs and host tests updated. +- Confirmed offline: `qcom,msm8909-smp` is valid in mainline 6.12 `platsmp.c`; the 2720 fuse `0x58000` reads `0x30100094` (dual core). `lk2nd_partial_goods_dt_update()` sets `status = "fail"` on `cpu@2`/`cpu@3` for non-downstream boots; `oem scan-dtb` can now prove whether that reached the kernel DTB. extlinux was already proven good by `oem scan-boot`; the remaining hang is in the mainline kernel. + +## Unreleased — extlinux confirmed good; kernel console capture via ramoops + +- `oem scan-boot` run on the live device proved the boot chain: `wrp0p32p0` (pmOS_boot, 256 MiB) enumerated and mounted, `/extlinux/extlinux.conf` parsed, `vmlinuz` / `qcom-msm8905-nokia-beatles.dtb` / `initramfs` all resolved and `lk2nd_boot_label()` reached `boot_linux()` without errors. Log saved to `backup/nokia-beatles-2720/crash-20261109/scan-boot-log.txt`. **The remaining hang is the mainline kernel, not lk2nd or the boot filesystem.** +- `oem read-partition` also verified the live `userdata` MBR (`55aa`, two `0x83` partitions) and its ext2 superblock (`53ef` at 1 MiB). `fastboot boot` of the debug boot.img downloaded OKAY then produced no USB, consistent with a kernel that hangs before the initramfs brings up `usb0` RNDIS. +- `oem ramoops regions` showed `0x9fa80000` still `0xff`. Patched `lk2nd/ramoops/ramoops.c` to always inject the ramoops reserved-memory node on Linux boots (`lk2nd.pass-ramoops=zap` still clears it), so `CONFIG_PSTORE_RAM`/`CONFIG_PSTORE_CONSOLE` kernel logs survive a warm reset. Added `images/boot-bananarchy-nokia-beatles-ramoops.img` (debug boot.img + `lk2nd.pass-ramoops`). +- Rebuilt both images (normal `dab81af0…46`, diagnostic `1825a1a4…bc`), reproducible byte for byte; validator and port tests check `oem scan-boot` and the ramoops patch. `check-rebuild.sh`, bootfs/bootimg checks and syntax checks pass. +- Next hardware step: the ramoops-enabled diagnostic lk2nd was chain-loaded with `fastboot boot` and `fastboot continue` ran the real extlinux chain; the kernel hung again. Power-cycle back into fastboot (Vol Down + Power), then `fastboot oem ramoops console && fastboot get_staged console.log` to read the kernel console. + +## Unreleased — extlinux/kernel hang diagnostics from live fastboot + +- Live fastboot confirmed the port works (`lk2nd:compatible=nokia,beatles`, `model=Nokia 2720 Flip`, panel `qcom,mdss_spi_gc9305_v2_qvga_cmd`, `unlocked=yes`). Read back the live `userdata` MBR (valid 0x55aa, two 0x83 partitions at LBA 2048 / 526336) and the ext2 superblock at 1 MiB (`53ef`, dynamic rev, compatible features) with `fastboot oem read-partition`; boot filesystem is intact on-device. +- `fastboot boot images/boot-bananarchy-nokia-beatles-debug.img` downloaded and reported OKAY, then no USB appeared. The initramfs brings up `usb0` RNDIS via `setup_usb_network`, so this means the mainline kernel hangs before userspace, or lk2nd never found extlinux and fell into `boot_linux_from_mmc()`. +- Added an `oem scan-boot` fastboot command (new `lk2nd/device/2nd/scan-boot.c`): runs `lk2nd_boot()` with `lk2nd_scan_only = true`; `lk2nd_boot_label()` logs the resolved kernel/dtb/initramfs/cmdline and returns before `boot_linux()`, so lk2nd stays in fastboot and `oem log` reveals the whole extlinux scan. Both images rebuilt (normal `902bf422…77`, diagnostic `d3eacccd…82`), reproducible byte for byte; validator and port tests check the command. +- Added `images/boot-bananarchy-nokia-beatles-ramoops.img` (debug boot.img plus `lk2nd.pass-ramoops` in the cmdline) so lk2nd injects a ramoops reserved-memory node and the kernel console can be read with `fastboot oem ramoops console` after a warm reset. +- Next hardware step: re-enter EDL with a fresh Sahara HELLO, flash the diagnostic image, then `fastboot oem scan-boot` + `fastboot oem log`. If the scan succeeds, boot the ramoops kernel and read its console after rebooting into fastboot. + +## Unreleased — lk2nd confirmed over live fastboot; default image boots extlinux headless + +- Confirmed over live fastboot (`18d1:d00d`, serial `34b39986`): `lk2nd:compatible=nokia,beatles`, `lk2nd:model=Nokia 2720 Flip`, `lk2nd:panel=qcom,mdss_spi_gc9305_v2_qvga_cmd`, `unlocked=yes`. The full lk2nd RLOG log shows `Found valid DTB with 2718 bytes total`, `Detected device: Nokia 2720 Flip` and a clean `fastboot_init()`; saved to `backup/nokia-beatles-2720/crash-20261109/lk2nd-fastboot-log.txt` and `lk2nd-parsed-cmdline.txt`. +- The "still hanging on the KaiOS logo" was lk2nd sitting in the forced-fastboot diagnostic menu with a RAM-only framebuffer, not a hang. Two vibrations were aboot's and lk2nd's normal 250 ms boot pulses. +- A/B proof: display enabled hangs before USB with the boot vibrator stuck on; `lk2nd.no-display` reaches fastboot. Both shipped images now carry `lk2nd.no-display`; the normal image no longer forces fastboot, so a normal power-on runs `lk2nd_boot()` -> extlinux -> the mainline kernel. `WITH_DISPLAY=1` / `--with-display` re-enables the SPI display. +- Rebuilt both (normal `eaa50754…15`, diagnostic `43bb63cb…05`), reproducible byte for byte; all tests pass. +- `fastboot continue` was sent to exercise the real extlinux chain; USB then disappeared and the KaiOS logo stayed. Bananarchy has no default USB gadget, so this is ambiguous. Next decisive probe: re-enter EDL (Sahara HELLO is one-shot — do not consume it with a passive read), enter Firehose and `peek` lk2nd's RLOG at `0x8f655430`, or hold Volume Down at power-on to reach fastboot and pull `fastboot oem log`. + +## Unreleased — lk2nd confirmed working; default image now boots extlinux headless + +- Live fastboot (`18d1:d00d`, serial `34b39986`) confirmed the port: `lk2nd:compatible=nokia,beatles`, `lk2nd:model=Nokia 2720 Flip`, `lk2nd:panel=qcom,mdss_spi_gc9305_v2_qvga_cmd`, `unlocked=yes`. The full lk2nd RLOG log shows `Found valid DTB with 2718 bytes total`, `Detected device: Nokia 2720 Flip` and a clean `fastboot_init()`. Saved to `backup/nokia-beatles-2720/crash-20261109/lk2nd-fastboot-log.txt` and `lk2nd-parsed-cmdline.txt`. +- A/B proof: with the SPI display enabled lk2nd hangs before USB with the boot vibrator stuck on; with `lk2nd.no-display` it vibrates twice normally (aboot + lk2nd boot pulses) and reaches fastboot. The "still hangs on the KaiOS logo" was lk2nd sitting in the forced-fastboot menu with a RAM-only framebuffer, not a hang. +- Both shipped images now carry `lk2nd.no-display`. The normal image no longer forces fastboot, so a normal power-on runs `lk2nd_boot()` -> extlinux -> mainline kernel, which re-initializes the panel itself. `WITH_DISPLAY=1` / `--with-display` re-enables the early SPI display for experimentation. +- Rebuilt both (normal `eaa50754…15`, diagnostic `43bb63cb…05`), reproducible byte for byte. Validator requires `lk2nd.no-display` on the diagnostic image; build script gained `--with-display`; `check-rebuild.sh`, port tests, bootfs/bootimg checks and syntax checks all pass. +- `fastboot continue` was used to exercise the extlinux chain; USB then disappeared and did not return within two minutes. This is not proof of a hang because Bananarchy has no default USB gadget. Next decisive probe: force EDL and read lk2nd's own RLOG ring buffer at `0x8f655430` (cookie `0x474f4c52`) to see whether `extlinux.conf` was found and `boot_linux()` reached. + +## Unreleased — aboot fixed; lk2nd hangs early with the boot vibrator stuck on + +- With `/cpus` present aboot no longer ASSERTs and lk2nd starts. The phone now hangs on the aboot/KaiOS splash with **permanent vibration and no USB device**. LK turns the vibrator on in `target_init()` (`vib_timed_turn_on(250)`) and off only in `target_uninit()` (`wait_vib_timeout()`), so a hang before USB/fastboot init leaves it buzzing forever. +- Prime suspect is the SPI display init, which now executes for the first time: `mdss_spi_init()` re-clocks BLSP1 QUP5 and `paint_boot_banner()` triggers three full 240x320 RGB565 frame writes during `LK2ND_INIT`, before USB comes up. +- Added `lk2nd.no-display` to `spi-display.c`: keeps a RAM-only framebuffer (so cont-splash does not read MDP registers) with `update_start = NULL`, and skips `mdss_spi_init()` entirely. The diagnostic image now uses it together with `LK2ND_FORCE_FASTBOOT=1` and `DEBUG=2`, so the only things before USB are DTB parsing, key publishing and partition setup. +- Rebuilt both images (normal `9c13e1ba…14`, diagnostic `43bb63cb…05`), still reproducible byte for byte from a pristine clone. Validator accepts and requires `lk2nd.no-display` on the diagnostic variant; `check-rebuild.sh` and the port tests still pass. +- Next hardware step: force EDL (hold power ~10-15 s, then Vol Up + Vol Down while plugging USB), flash the diagnostic image with `--lk2nd-image --verify`, then `lsusb`. `18d1:d00d` means the SPI display init was the hang; `fastboot oem log && fastboot get_staged lk2nd.log` gives the rest. If it still hangs with vibration, re-read aboot's RLOG buffer (and lk2nd's own RLOG cookie near its BSS) for the earlier hang. + +## Unreleased — real root cause: aboot partial-goods ASSERT on missing /cpus + +- Pulled aboot's `WITH_DEBUG_LOG_BUF` ring buffer (cookie `0x474f4c52` "RLOG") from the live Sahara memory-debug dump. It contains the exact crash: + ``` + [580] target_display_init ret=0 + [590] Failed to get parent node: /cpus errno:-1 + [600] panic (caller 0x8f61aa00): ASSERT FAILED at (platform/msm_shared/partial_goods.c:80): 0 + [610] HALT: reboot into dload mode... + ``` +- The 2720's MSM8905 is a **partial-goods (2-core) part**. Its stock aboot calls `update_partial_goods_dtb_nodes()` on the QCDT-selected DTB and `ASSERT(0)`s when `/cpus`, `/cpus/cpu@2` or `/cpus/cpu@3` (with a 4-byte `device_type`) is missing; it then rewrites `device_type` from `"cpu\0"` to `"nak\0"`. Upstream lk2nd QCDT DTBs have no `/cpus` at all, so **every** lk2nd image — including the untouched `bootloader/lk2nd-msm8909.img` — crashed before lk2nd ran. This, not the QCDT table shape or the panel init, was the "black screen / no fastboot" cause. +- Fixed by adding a `/cpus` node with `cpu@0`..`cpu@3` and `device_type = "cpu"` to the common `lk2nd/device/dts/lk2nd.dtsi`, so all eight QCDT DTBs carry it. The mainline `qcom-msm8905-nokia-beatles.dtb` already has `/cpus`, so the Volume Up recovery path is unaffected. +- Rebuilt both images (normal `e747ec0d…95`, diagnostic `8ded62f0…4a`); both reproducible byte for byte from a pristine clone. `dt_size` is `22528` and the 2720 DTB is 4096 bytes — aboot demonstrably handled a larger QCDT in earlier dumps, so size was never the problem. +- `check-lk2nd-beatles.py` now checks every QCDT DTB for `/cpus/cpu@2` and `cpu@3` with a 4-byte `device_type`, and enforces both `0x14b` entries sharing one DTB; `test-lk2nd-beatles-port.py` checks the `/cpus` patch. Crash log saved as `backup/nokia-beatles-2720/crash-20261109/aboot-log.txt`. +- Next hardware step: power-cycle into plain EDL (memory-debug state refuses the Firehose programmer), reflash the diagnostic image with `--verify --dump-diagnostics`, then `lsusb`. `18d1:d00d` means lk2nd runs; `05c6:900e` again means re-read the RLOG buffer for the next ASSERT. + +## (Superseded) aboot crashes on the changed QCDT; restore upstream shape + +- Live diagnosis: after "black screen, no fastboot" the phone was in `05c6:900e` **Sahara MEMORY_DEBUG mode**, i.e. aboot crashed before lk2nd ever ran. A Sahara memory-debug dump showed aboot's BSS held the diagnostic boot.img header (`ANDROID!`, kernel 345048, `dt_size=24576`) and the cached cmdline `lk2nd lk2nd.compatible=nokia,beatles`; aboot had also built `mdss_mdp3.panel=1:spi:0:qcom,mdss_spi_gc9305_v2_qvga_cmd:1:none`. The kernel payload at `0x80008000` was byte-identical to the diagnostic image, while lk2nd's BSS at `0x80080000` was all zeros. +- Root cause: the only aboot-parsed thing changed was the **QCDT table**. The dedicated `msm8905-nokia-beatles` DTB made `dt_size` 20480 -> 24576, split the two `0x14b` entries across two different DTBs and put `0x1000b` first in `qcom,board-id`. aboot re-validates the selected DTB's root properties and crashed. Removed that DTB, restored `msm8905-qrd-skub.dts` to the exact upstream `qcom,board-id = <0x0b 0x100>, <0x1000b 0x100>` and injected only a compact `/lk2nd/nokia-beatles` node (DTB 1504 -> 1984 bytes, still one 2048-byte slot). Both `0x14b` QCDT entries again point at the same DTB and `dt_size` is back to `20480`. +- Trimmed the port to fit that slot: only the `qcom,mdss_spi_gc9305_v2_qvga_cmd` panel — the one the live aboot reports — carries `lk2nd,panel-init`; the other two are match-only nodes. Dropped the DTB `gpio-keys` and `menu-key-strings` entries. Kept model, compatible, `lk2nd,match-panel` and `lk2nd,dtb-files`. +- Rebuilt both images (normal `968ef23c…8d`, diagnostic `5eb75ca8…5ff`), still reproducible byte for byte from a pristine clone. `check-lk2nd-beatles.py` now enforces the upstream QCDT shape and rejects any separate QCDT DTB; the host C test covers the single v2 stream. +- Crash evidence saved to `backup/nokia-beatles-2720/crash-20261109/`. `devinfo` from the last dump still has `is_unlocked=1`. Next hardware step: reflash the diagnostic image with `--verify --dump-diagnostics`, then check `lsusb`; if it returns to `900e`, re-read aboot's RLOG buffer; the untouched `bootloader/lk2nd-msm8909.img` lacks `/cpus` too and is only a negative control. + +## Unreleased — diagnose the logo-then-blank screen on nokia-beatles + +- Traced the dark screen: `DISABLE_SPLASH_PARTITION=1` in lk2nd builds means `display_image_on_screen()` never loads the stock splash, and lk2nd's `menu.c` override of `display_default_image_on_screen()` only draws two version lines before `fbcon_flush()` pushes the whole 240x320 RGB565 framebuffer at `MIPI_FB_ADDR`. Upstream's fallback is a tiny 113x124 logo on black; there is no guarantee aboot left its splash at that address. `spi-display.c` now paints a striped `Bananarchy lk2nd / nokia-beatles / 240x320 RGB565` banner before that flush, so the handoff can no longer be mistaken for a hang. +- Made the panel-init replay conditional: `lk2nd,panel-init` is only replayed when aboot did not report continuous splash (`mdss_mdp3.panel=0:...`) or when `lk2nd.force-panel-init` is present in the cmdline. Re-initializing a panel aboot already owns risks disturbing the 2720's shared main/cover SPI bus. `scripts/build-lk2nd-beatles.sh --force-panel-init` builds that variant. +- Added `images/boot-lk2nd-nokia-beatles-diagnostic.img`: the same port built with `DEBUG=2 DEBUG_FBCON=1 LK2ND_FORCE_FASTBOOT=1`, so it always shows the fastboot menu, draws boot logs on the display and enumerates as USB fastboot. `flash-edl.py` gained `--lk2nd-image` to flash it without changing the default. Pull the decisive log with `fastboot oem log && fastboot get_staged lk2nd.log`. +- `scripts/build-lk2nd-beatles.sh` now builds and validates both images (`--only normal|diagnostic`, `--check`), `check-lk2nd-beatles.py` gained `--expect-fastboot` and checks the banner/conditional-replay markers, and `test-lk2nd-beatles-port.py` validates both images plus the flasher override. Both images remain reproducible byte for byte. +- No successful Bananarchy boot has been observed yet; the forced-fastboot log or UART (`ttyMSM0,115200`) is required to locate whether the failure is extlinux/`pmOS_boot` or the mainline kernel. + +## (Superseded) source-built nokia-beatles lk2nd port + +- Replaced the binary-patched, headless lk2nd workaround with a real upstream source port. `bootloader/lk2nd/nokia-beatles.patch` applies to `msm8916-mainline/lk2nd` commit `cf45aefd22d744b2bf9b39455afae697ce430063`; `scripts/build-lk2nd-beatles.sh` clones that commit, applies the patch and cross-builds `lk2nd-msm8909` in the rootless Docker toolchain image (`bootloader/lk2nd/Dockerfile`). The result is reproducible byte for byte. +- New dedicated QCDT DTB `msm8905-nokia-beatles.dts` with the exact stock 2720 IDs (`qcom,msm-id = <0x14b 0>`, `qcom,board-id = <0x1000b 0x100>`). It contains only `/lk2nd/nokia-beatles`, so aboot's best-match selection is unambiguous. The shared `msm8905-qrd-skub.dtb` keeps the `0xb/0x100` fallback entry and also carries the beatles node. +- `nokia-beatles.dtsi` adds a real device node: model `Nokia 2720 Flip`, `compatible = "nokia,beatles"`, `lk2nd,match-panel`, `lk2nd,dtb-files = "msm8905-nokia-beatles"`, menu key labels and `gpio-keys` for volume up (GPIO 90) and power/end (GPIO 98), both active low. +- Correct panel initialization: three panel subnodes match every GC9305 name the 2720 aboot can report (`gc9305_qvga_cmd`, `gc9305_v2_qvga_cmd`, `gc9305_3rd_qvga_cmd`), each with the downstream KaiOS 3.10 `qcom,mdss-spi-on-command` byte stream as `lk2nd,panel-init`. `lk2nd/include/lk2nd/spi-panel-init.h` walks the `[wait dlen payload...]` stream; `platform/msm_shared/mdss_spi.c` and `lk2nd/device/2nd/spi-display.c` replay it on BLSP1 QUP5 (DC GPIO 110), setting RGB565, the 240x320 address window, sleep-out, display-on and RAMWR. lk2nd can now bring the panel up even when aboot left no continuous splash. +- `images/boot-lk2nd-nokia-beatles.img` is the source-built image (sha256 `1b6386a2e532d52003b6c2b65f00f6860c28d50cd94d9c3b874dd93fa161baa9`), cmdline `lk2nd lk2nd.compatible=nokia,beatles`. Removed the obsolete `scripts/make-beatles-lk2nd-bootimg.py`. +- `scripts/check-lk2nd-beatles.py` now validates the boot header, both 2720 QCDT entries, both DTBs, the device node, gpio-keys and every panel init stream with a pure-Python FDT parser. `scripts/test-lk2nd-beatles-port.py` additionally compiles the shared C parser against the streams extracted from the shipped image. `check-rebuild.sh` guards the port files. + +## (Superseded) fix lk2nd headless device node and repair pmOS_boot + +- Root cause of the blank screen: `repack-beatles-bootimg.py` had written an Android `boot.img` at raw offset 1 MiB, which is the **ext2 `pmOS_boot` filesystem** inside the `userdata` MBR image. Its superblock was destroyed, so lk2nd could not mount the boot subpartition, could not find `extlinux.conf`, and reported "Bootable file system not found. Reverting to android boot." The tool no longer accepts `--raw-image`; `scripts/sync-beatles-bootfs.py` updates `/boot.img`, `/qcom-msm8905-nokia-beatles.dtb` and `/extlinux/extlinux.conf` inside the ext2 filesystem instead, with `--check` wired into `check-rebuild.sh`. +- Repaired `images/bananarchy-nokia-beatles.img` in both repos: ext2 superblock restored, DTB and boot.img refreshed, `extlinux.conf` now uses `loglevel=8 ignore_loglevel initcall_debug panic=10` instead of `quiet splash`. +- Root cause of lk2nd running the wrong hardware: the QCDT DTB only had `cat-b35` / `nokia-argon` device nodes with `lk2nd,match-panel`. `scripts/make-beatles-lk2nd-bootimg.py` now injects `/lk2nd/nokia-beatles` (`model = "Nokia 2720 Flip"`, `compatible = "nokia,beatles"`, `lk2nd,dtb-files = "qcom-msm8905-nokia-beatles"`), removes every `lk2nd,match-panel` property, and sets cmdline `lk2nd lk2nd.compatible=nokia,beatles`. lk2nd identifies the board and skips the 8110 4G panel/keypad init entirely. +- `images/boot-lk2nd-nokia-beatles.img` rebuilt in both repos; `check-lk2nd-beatles.py` now validates that only the cmdline field and the exact-2720 QCDT DTB slot differ, that the new node exists, and that no node carries `lk2nd,match-panel`. + +## Unreleased — Argon-shaped hybrid and RPMB correction + +- Correction to the previous entry: `target_get_vb_version()` returns `VB_L=1` when the GPT has no `keymaster` partition (this 2720 has `keystore` only), while `VB_M=2`. The `USE_RPMB_FOR_DEVINFO` branch is therefore not taken; `read_device_info()` uses eMMC `devinfo`. The 21:25 dump shows `is_unlocked=1`, so the eMMC unlock is effective and `fastboot oem unlock-go` is unnecessary. Stock fastboot is not required. +- The 900e crash is not a signature rejection. To match the 8110/Argon process exactly, the default `nokia-beatles` path is now a hybrid: `bootloader/lk2nd-msm8909.img` -> `boot`, `images/boot-bananarchy-nokia-beatles.img` -> `recovery`. Normal power-on is `aboot -> lk2nd -> extlinux`; Volume Up is `aboot -> recovery -> mainline boot.img`. +- `source_for(name)` gives each target partition its own source; `--verify` compares each slot against the image actually written there. The behavioural test asserts `boot=lk2nd`, `recovery=boot.img`. + +## (Superseded) RPMB devinfo is the authoritative unlock + +- After the dual-slot fix the phone still entered `05c6:900e` (Sahara memory debug). The 21:25 dumps show eMMC `devinfo` is now `is_unlocked=1`, but `diag-aboot.img` contains VERIFIED_BOOT / `USE_RPMB_FOR_DEVINFO` code: `read_device_info()` uses `read_device_info_rpmb()` when secure boot is enabled, so the eMMC patch is ignored. `boot_verifier_init()` therefore still verifies the unsigned lk2nd image and aboot crashes. +- `flash-edl.py` now patches the `config` (fallback `frp`) partition allow-unlock byte (LSB of last byte) by default on `nokia-beatles` via `enable_oem_unlock()`, with read-back verification and `backup/config-locked-.img`. +- New `--only-unlock` mode patches eMMC devinfo + config/frp, prints the exact `fastboot oem unlock-go` instructions, and exits without flashing. `--enable-oem-unlock` / `--no-enable-oem-unlock` control the config patch. +- Added `scripts/make-oem-unlock-config.py`, generated `backup/nokia-beatles-2720/config-oem-unlock.img` (only byte 524287 changes), `check-rebuild.sh` guards and a host test. + +## Unreleased — fix lk2nd dual-slot write + +- `--verify` correctly reported `read-back of 'recovery' differs`: the 2720 dual-slot `target_names = ("boot", "recovery")` was built, but the old `method == "lk2nd"` branch still wrote only `target_parts[0][1]`. `recovery` therefore kept the previous mainline boot.img while `--verify` compared it against lk2nd. +- Step 1 now loops over every `target_parts` entry with a single `source` (`bootloader_img` for lk2nd, `boot_img` otherwise), and the verify loop uses the same source. `check-rebuild.sh` guards against the single-slot regression and a host test asserts the multi-target write path. + +## Unreleased — unlock locked 2720 aboot via devinfo + +- `--dump-diagnostics` dumps from the connected 2720 show `diag-devinfo.img` with `ANDROID-BOOT!` magic and `is_unlocked=0`, `is_tampered=0`; `diag-aboot.img` contains `Nokia_beatles ROOT CA0`, secure-boot checks, `ERROR: Image Invalid! signature check failed!` and `Device is unlocked! Skipping verification...`. This is the root cause of the empty screen: aboot signature-checks every custom `boot.img` (lk2nd or mainline) and rejects it. +- `flash-edl.py` now defaults to `unlock_devinfo()` on `nokia-beatles`: it backs up the locked `devinfo` to `backup/devinfo-locked-.img`, sets byte 13 (`is_unlocked`) to 1 and clears `is_tampered`, then writes it back before flashing. `--unlock-bootloader` forces it on any target; `--no-unlock-bootloader` skips it. +- Added `scripts/make-unlocked-devinfo.py` and generated `backup/nokia-beatles-2720/devinfo-unlocked.img` from the captured dump (only byte 13 changes). `check-rebuild.sh` guards the unlock helper and defaults. +- Earlier DTB/QCDT/lk2nd fixes remain valid but were all downstream of this signature check. + +## Unreleased — lk2nd boots first on the 2720 Flip + +- `bootloader/lk2nd-msm8909.img` was re-examined: it is an Android `boot.img` with cmdline `lk2nd`, `dt_size=20480` and a QCDT v2 table after the ramdisk. Entry 13 already has the exact stock 2720 IDs (`platform_id=0x14b`, `variant_id=0x1000b`, `board_hw_subtype=0x100`, `soc_rev=0`) and points at a DTB with `/memory`, `/chosen` and `/lk2nd`. aboot therefore accepts the lk2nd boot.img on this device; the earlier "lk2nd unsupported" conclusion was wrong. +- `--method lk2nd` is again the default for every target. On `nokia-beatles` it writes lk2nd to both `boot` and `recovery`; `--verify` reads back both. lk2nd then boots Bananarchy from `userdata` via `extlinux.conf`, which names `qcom-msm8905-nokia-beatles.dtb` explicitly, so lk2nd identifying the board as an 8110 in its own menu does not affect the kernel DTB. +- `--method both` remains as a fallback that writes the standalone mainline `boot.img` to both slots, and `--method recovery` for the pmOS Volume Up route. +- Added `scripts/check-lk2nd-beatles.py`; `check-rebuild.sh` now enforces the QCDT entry and the dual-slot lk2nd write. + +## Unreleased — dual boot/recovery write and EDL diagnostics + +- (Superseded by the lk2nd-first path above.) `--method both` was the default for `nokia-beatles`: the corrected boot.img is written to both `boot` and `recovery`, because the stock locked fastboot chain may refuse an unsigned `boot` image while the pmOS-tested Volume Up recovery path still works. +- `--verify` now reads back every target partition, and `--dump-diagnostics` copies small `devinfo`, `aboot`, `tz`, `config`, `misc` and related partitions into `backup/diag-*.img` for offline secure-boot analysis. +- Completion output now tells the user to hold Volume Up if the KaiOS splash persists on a normal power-on. + +## Unreleased — 2720 Flip aboot DTB fixes + +- Replaced the mixed `qcom,board-id = <0xb 0x100 0x1000b 0x100>` with the exact stock MSM8905 QRD SKUB pair `<0x1000b 0x100>`. Older Qualcomm aboot revisions read only the first board-id pair, so the lk2nd 8110 variant prevented DTB selection and left the phone on the KaiOS splash. +- Added a 512 MiB `/memory` fallback (`reg = <0x80000000 0x20000000>`) to the beatles DTB. Stock aboot normally rewrites this from SMEM; the fallback avoids a zero-sized memory bank when it does not. +- Added `scripts/repack-beatles-bootimg.py` and `scripts/check-beatles-bootimg.py`. `check-rebuild.sh` now enforces the exact qcom IDs, memory fallback, appended-DTB pointer and boot partition size. +- Regenerated `qcom-msm8905-nokia-beatles.dtb`, the derivation patch, `images/boot-bananarchy-nokia-beatles.img` and the boot slot in `images/bananarchy-nokia-beatles.img`. + +## Unreleased — opt-in read-back verification + +- `--verify` reads back the `boot`/`recovery` partition after step 1 and + compares its leading bytes with the source image. A mismatch aborts the + flash before `userdata` is written, so a Sahara/Firehose session that never + committed cannot silently leave the phone booting stock KaiOS. + +## Unreleased — restore system superblock wipe by default + +- `resolve_wipe_system()` again zeroes the stock `system` superblock for + every flash method, as in the original Bananarchy behavior. + `--no-wipe-system` is now the opt-out; `--wipe-system` remains an explicit + (redundant) alias. The banner and step 3 report the effective choice. +- Recovery-mode completion message now warns that a normal power-on hangs on + the KaiOS logo after the wipe and that Volume Up is mandatory. +- `check-rebuild.sh` continues to guard the wipe helper. + +## Unreleased — do not wipe KaiOS system for boot/recovery methods + +- The "Powered by KaiOS" hang was the stock KaiOS kernel in `boot` trying to + mount a `system` partition whose first 64 sectors we had zeroed. With + `--method recovery`, `boot` is intentionally left alone, so a normal + power-on boots KaiOS; only Volume Up selects the flashed recovery image. +- `system` is now wiped only for the `lk2nd` method. `--wipe-system` forces + it and `--no-wipe-system` forbids it; the banner reports the choice. +- The target partition is always backed up as `-.img` + instead of reusing an existing `.img` from a different device. +- Recovery-mode completion message now states that normal power-on boots + KaiOS and Volume Up boots Bananarchy. + +## Unreleased — 2720 Flip boots from `boot` with a matched DTB + +- Root cause of the persistent boot failure: the appended device tree had no + `qcom,msm-id`, `qcom,board-id` or `qcom,pmic-id`. Qualcomm aboot selects an + appended DTB by those IDs, so it found none and fell back to Sahara + (`05c6:900e`). The IDs (`0x14b`, `0x0b/0x100 0x1000b/0x100`, `0x1000d`) + were read from the `MSM8905 QRD SKUB` DTB inside the stock 2720 recovery + image, confirmed against lk2nd's `msm8905-qrd-skub` DTB, and added to the + beatles DTS/DTB. The rebuilt `boot.img` now carries them. +- (Superseded by the lk2nd-first path above.) `--method boot` was the default + for `nokia-beatles`: the standalone `boot.img` was written to `boot`. +- (Superseded.) `--method recovery` remains available; `--method lk2nd` is now + the default for the 2720 as well. +- `check-rebuild.sh` guards the device list and method-to-partition map. + +## Unreleased — 2720 Flip recovery boot path + +- (Superseded by the lk2nd-first path above.) `lk2nd-msm8909.img` contains no + `nokia-beatles` device node; the shared `msm8905-qrd-skub` board plus the + colliding `qcom,mdss_spi_gc9305_v2_qvga_cmd` panel node make lk2nd identify + the 2720 as an 8110 4G in its own menu. The stock aboot does accept the + lk2nd boot.img via its QCDT entry. +- (Superseded.) `flash-edl.py` auto-selected `--method recovery` for + `nokia-beatles`: it flashed the standalone `boot.img` into `recovery`, left + `boot` alone, + writes the raw image to `userdata` (the pmOS initramfs + `mount_subpartitions()` exposes the nested MBR), and tells the user to + hold Volume Up at power-on. `--method lk2nd` and `--boot-image` override. +- `rebuild-image.sh` exports `images/boot-bananarchy-.img` instead of + deleting it. The exported image has the corrected beatles DTB appended and + the pmOS 2720 load addresses (`ramdisk 0x81000000`, `tags 0x80000100`). +- Flashing backs up `recovery` instead of `boot` in recovery mode. +- `check-rebuild.sh` guards the recovery device list and the boot.img export. + +## Unreleased — per-device EDL Firehose programmers + +- `flash-edl.py` now selects the Sahara/Firehose programmer from the target + device instead of always using `8110.mbn`: `8110.mbn` (`nokia-argon`), + `2720.mbn` (`nokia-beatles`), `800t.mbn` (`nokia-tough`), and `8k.mbn` + for **both** `nokia-sparkler` and `nokia-leo`. `--variant us` selects + `2720v.mbn` (`Nokia_bts_us`) for the 2720 Flip US variant. +- Added `--list-loaders`, which prints every `.mbn` with its size, embedded + attestation identity (`Nokia_beatles`, `Nokia_coconut`, `Nokia_bts_us`, + `Nokia_leo`) and device mapping. `flash-edl.sh` runs it without `sudo`. +- Selection warns when a programmer's embedded identity does not match the + expected device identity and fails with an actionable message when the + expected file is absent; `--loader PATH` still overrides everything. +- `wait_for_edl_usb()` auto-detects `05c6:9008`, `05c6:900e` and + `05c6:9006` instead of waiting only for 9008, and prints the PID it found; + `--pid` still forces a specific one. `check-rebuild.sh` guards the list. +- `check-rebuild.sh` guards the mapping and the presence of all five loaders. +- `8k.mbn` is signed `Nokia_leo` but is valid for both MSM8909 targets + (`nokia-sparkler`, `nokia-leo`); `2720v.mbn` is signed `Nokia_bts_us` + (2720 Flip US). Confirm identities with `--list-loaders` before flashing. + ## Build `a1108` — codename `dejavu` (2026-11-08) This build contains all previously unreleased changes below. The image and diff --git a/MANUAL.md b/MANUAL.md index 5cf82bb..3d7125b 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -17,8 +17,8 @@ This manual covers flashing, operating, and customizing **Bananarchy Linux** (`2 - Additional device images (`bananarchy-nokia-beatles.img`, `bananarchy-nokia-tough.img`, `bananarchy-nokia-sparkler.img`) can be generated at any time via `./rebuild-image.sh --mkinitfs`. ### 1.2 Bootloader and EDL programmer (`bootloader/`) -- `bootloader/lk2nd-msm8909.img`: secondary bootloader (`lk2nd`) providing Fastboot and `extlinux` boot discovery for MSM8905 and MSM8909 devices. -- `bootloader/loaders/8110.mbn`: signed Qualcomm Sahara/Firehose programmer (`05c6:9008`). +- `bootloader/lk2nd-msm8909.img`: secondary bootloader (`lk2nd`) providing Fastboot and `extlinux` boot discovery for MSM8905 and MSM8909 devices. `images/boot-lk2nd-nokia-beatles-display.img` is the source-built 2720 Flip port (see `bootloader/lk2nd/README.md`). +- `bootloader/loaders/`: signed Qualcomm Sahara/Firehose programmers (`05c6:9008`), one per target. The flasher picks the right one from `--device` / the positional target; run `./flash-edl.sh --list-loaders` to see each file's embedded attestation identity and mapping. Pass `--variant us` for a 2720 Flip US variant or `--loader PATH` to override the programmer entirely. ### 1.3 Core architecture highlights 1. **Pure X11 (`Xlibre` + `sxmo-de-dwm`) for `240x320` QVGA displays**: @@ -46,18 +46,24 @@ Run the automated EDL flasher from the repository root on your host machine: ```bash sudo ./flash-edl.sh ``` -*(To flash another target device image, pass its codename, e.g. `sudo ./flash-edl.sh nokia-sparkler`.)* +*(To flash another target device image, pass its codename, e.g. `sudo ./flash-edl.sh nokia-sparkler`.)* The programmer is selected automatically: `8110.mbn` (8110 4G), `2720.mbn` (2720 Flip), `800t.mbn` (800 Tough), and `8k.mbn` for **both** 8000 4G and 6300 4G. The 2720 Flip US variant (`Nokia_bts_us`) uses `2720v.mbn`: pass `--variant us` (or `--loader ./bootloader/loaders/2720v.mbn`). Verify with `./flash-edl.sh --list-loaders`. The script performs the following steps automatically: 1. Temporarily pauses host `ModemManager` so it does not interfere with `05c6:9008`. -2. Waits for the phone to appear in Qualcomm EDL mode (`05c6:9008`): - - **From Bananarchy Linux**: open the **Power** menu (`End / Power` key or `System menu -> Power`), select **Reboot to loader** (`sxmo_power.sh loader`) to enter the `lk2nd` Fastboot menu, and select **EDL** (or let `flash-edl.sh` automatically send `fastboot oem reboot-edl`). +2. Waits for the phone in Qualcomm EDL/Sahara mode. The flasher auto-detects + `05c6:9008` (QDLoader), `05c6:900e` (QHSUSB_BULK, common after a failed + boot) and `05c6:9006` (DLOAD); pass `--pid` to force one: + - **From Bananarchy Linux**: open the **Power** menu (`End / Power` key or `System menu -> Power`), select **Reboot to loader** (`sxmo_power.sh loader`) to enter the visible `lk2nd` Fastboot menu, then select **EDL** (or let `flash-edl.sh` automatically send `fastboot oem reboot-edl`). The low-bit reboot cookie now survives the stock boot chain and keeps the menu available. - **Button combo**: power off the phone, hold **D-Pad up + D-Pad down**, and plug in the USB cable. - **EDL cable**: hold the EDL cable button while plugging in USB. - **From ADB or Fastboot**: the script automatically sends `adb reboot edl` or `fastboot oem reboot-edl` if detected. -3. Uploads `bootloader/loaders/8110.mbn` via Sahara and connects to eMMC via Firehose. + - If the phone is stuck in Sahara with no fresh HELLO packet (e.g. a host + tool already consumed it), power-cycle it: hold **End/Power** for 15-20 s + (or disconnect/reconnect the battery), then retry. The flasher cannot + resume a half-open Sahara handshake. +3. Uploads the device-specific Firehose programmer from `bootloader/loaders/` via Sahara and connects to eMMC via Firehose. 4. Backs up `gpt.bin`, `fsc`, `fsg`, `modemst1`, `modemst2`, `persist`, and `boot` into `./backup/` if not already backed up. -5. Flashes `lk2nd-msm8909.img` to `boot`, flashes `images/bananarchy-.img` to `userdata`, clears the stock `system` superblock, and reboots into Bananarchy Linux. +5. Flashes `images/bananarchy-.img` to `userdata`, clears the stock `system` superblock (first 64 sectors / 32 KiB), and reboots. This wipe is the default for every method; pass `--no-wipe-system` only if you deliberately want a dual-boot phone with KaiOS intact. **The default `--method lk2nd` writes the source-built `images/boot-lk2nd-nokia-beatles-display.img` into `boot`, and the standalone `images/boot-bananarchy-nokia-beatles.img` into `recovery` on the 2720 Flip (Argon-shaped hybrid).** That lk2nd image is built from upstream lk2nd plus `bootloader/lk2nd/nokia-beatles.patch`: it carries cmdline `lk2nd lk2nd.compatible=nokia,beatles`, keeps the upstream QCDT layout (both `0x14b` entries sharing one DTB), injects a compact `/lk2nd/nokia-beatles` node with the downstream GC9305 v2 panel init stream, and adds `/cpus` with `cpu@0`..`cpu@3` to every QCDT DTB. The 2720's MSM8905 is a partial-goods 2-core part; aboot `ASSERT FAILED at (platform/msm_shared/partial_goods.c:80)` and rebooted into Sahara memory-debug EDL because upstream lk2nd DTBs had no `/cpus` — that was the black-screen/no-fastboot crash. aboot hands off to lk2nd, which keeps aboot's 240x320 RGB565 panel init (or replays the downstream stream when cont-splash is off), then scans `userdata` for `extlinux.conf` and boots `vmlinuz` + `initramfs` with the explicit `fdt /qcom-msm8905-nokia-beatles.dtb`. Rebuild it with `scripts/build-lk2nd-beatles.sh`; see `bootloader/lk2nd/README.md`. The port paints the Bananarchy RGB565 boot splash instead of the near-black upstream splash; the branded screen confirms lk2nd owns the framebuffer. Live `oem display-init` proved the GC9305 v2 stream and frame flush, chain-loaded diagnostics now fall back to the QCDT panel stream, and `oem scan-dtb` captures the final post-update kernel DTB. The release image is display-enabled (`lk2nd.display=on`) so the branded splash and Fastboot menu are visible; the normal no-display image remains available for diagnostics. All QUP/clock polls are bounded, so a dead SPI bus reports a failure instead of hanging. If the phone never shows anything, run `lsusb`: `05c6:900e` means aboot crashed into EDL (Sahara MEMORY_DEBUG), not that lk2nd failed to display; the `/cpus` fix above addresses the confirmed ASSERT. Flash `images/boot-lk2nd-nokia-beatles-diagnostic.img` with `--lk2nd-image --verify --dump-diagnostics` (forced fastboot + runtime `oem display-init` probe), then `fastboot oem log && fastboot get_staged lk2nd.log`; if it returns to `900e`, re-read aboot's RLOG crash buffer (the untouched `bootloader/lk2nd-msm8909.img` lacks `/cpus` as well and crashes identically). See `bootloader/lk2nd/README.md`. If the KaiOS splash persists on a normal power-on, **hold Volume Up** to boot the mainline boot.img in `recovery`. `--method both` is the fallback that writes the standalone `images/boot-bananarchy-nokia-beatles.img` (appended beatles DTB, exact qcom IDs and 512 MiB `/memory` fallback) into both slots; `--method recovery` writes it only to `recovery`. Use `--boot-image PATH` to override the standalone image. Add `--verify` to read back every flashed `boot`/`recovery` partition and confirm the write really committed; a mismatch aborts before `userdata` is touched. Add `--dump-diagnostics` to save small `devinfo`/`aboot`/`tz`/`config` partitions into `backup/diag-*.img` for offline secure-boot analysis. The captured `diag-devinfo.img` proved this 2720 is locked (`is_unlocked=0`, `is_tampered=0`) while `diag-aboot.img` contains `Nokia_beatles ROOT CA0` and `Device is unlocked! Skipping verification...`; aboot therefore rejects every unsigned boot.img. The flasher defaults to unlocking `devinfo` on `nokia-beatles` before writing lk2nd, saves the original as `backup/devinfo-locked-.img`, and accepts `--unlock-bootloader` / `--no-unlock-bootloader`. `scripts/make-unlocked-devinfo.py` can produce the patched image offline. Correction: `target_get_vb_version()` returns `VB_L` on this GPT (no `keymaster`), so aboot reads eMMC `devinfo`, not RPMB. The captured `diag-devinfo.img` after flashing shows `is_unlocked=1`; the eMMC unlock works and **no `fastboot oem unlock-go` step is needed**. `--only-unlock`, `enable_oem_unlock()` and `scripts/make-oem-unlock-config.py` are optional EDL-only prerequisites kept for completeness. EDL is the only required interface. After any DTB change run `python3 scripts/repack-beatles-bootimg.py` and `python3 scripts/sync-beatles-bootfs.py --debug-cmdline`; after any lk2nd change run `./scripts/build-lk2nd-beatles.sh`; never write an Android boot.img directly at raw offset 1 MiB. To diagnose a persistent `05c6:900e` without stock fastboot, power-cycle into EDL and run `python3 scripts/dump-edl-crash.py --out backup/crash-run`; it reads the Sahara memory-debug table and dumps aboot/TZ crash regions. The partition being overwritten is always backed up as `-.img` (e.g. `boot-nokia-beatles.img`), so stale backups from another device are never reused. --- @@ -130,7 +136,7 @@ All twenty-five phone applications are compiled as shared-object plugins (`/usr/ 1. **System and context menus (`dmenu.so` / `dmenu` / `xdmenu`)**: - **Open / close**: press **Left softkey (`Menu`)** for the **System menu** or **Right softkey (`Back`)** inside an application for its **Context menu**; press the same softkey or `Escape` to close. - - **Built-in submenus and instant toggles**: renders `sys`, `applications`, `scripts`, `modem`, `config`, `sdcard`, `power` (including **Lock**, **Lock (Screen off)**, **Logout**, **Reboot**, **Reboot to loader**, **Reboot to EDL**, and **Poweroff**), `audio` (with linear volume steps and **Output: Speaker**, **Output: Earpiece**, and **Output: Headphones** routing), `notifications`, `wm`, `timezone`, `games`, `st`, and `nano` menus in place in `< 0.5 ms` without spawning external processes. + - **Built-in submenus and instant toggles**: renders `sys`, `applications`, `scripts`, `modem`, `config`, `sdcard`, `power` (including **Lock**, **Lock (Screen off)**, **Logout**, **Reboot**, **Reboot to loader**, and **Poweroff**; use the lk2nd Fastboot menu for **EDL**), `audio` (with linear volume steps and **Output: Speaker**, **Output: Earpiece**, and **Output: Headphones** routing), `notifications`, `wm`, `timezone`, `games`, `st`, and `nano` menus in place in `< 0.5 ms` without spawning external processes. - **Script compatibility**: any script piping items into `/usr/bin/dmenu` or `sxmo_dmenu.sh` communicates with the resident daemon over `/tmp/dwm_plugin_dmenu.sock`. 2. **Global phone controls (`xdrawer.so` / `xdrawer`)**: @@ -443,6 +449,25 @@ Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoun --- +### 4.1 First-boot troubleshooting on the 2720 Flip + +- **X startup and keypad**: OpenRC starts independent services in parallel; `etc/init.d/local` replaces its stock `after *` dependency, which deadlocked with parallel startup on this image. `udev_settle_timeout=2` stops missing modem firmware from holding the display manager behind a long `udevadm settle`, and `bananarchy-sshd-debug` starts independently of `local.d`. A boot-open flip reads `/run/bananarchy/lid-state` and starts in `state=unlock` with no passcode screen, so the keypad is live as soon as `dwm` starts. If the keypad is dead, check `rc-service bananarchy-lid status`, `cat /run/bananarchy/lid-state`, `sxmo_state.sh get`, `/tmp/bananarchy_screen_locked`, `DISPLAY=:0 xwininfo -id 0xa00001` and `DISPLAY=:0 xinput list`. +- **Closing the flip**: `bananarchy-lid` reads the current `EV_SW` switch mask from `/dev/input/event2`, follows hall edge events with an 80 ms stability window and only polls raw gpio36/gpio92 debugfs levels when no switch evdev is available. On close it blanks the main panel and keypad LED immediately, runs `sxmo_state.sh set screenoff` and tells the cover daemon `LID CLOSED`; on open it clears the lock flag, restores both backlights, sends a trusted `CLOSE` to `locker.so` and runs `sxmo_state.sh set unlock`. Check `rc-service bananarchy-lid status`, `sxmo_state.sh get` and `grep -E " gpio(36|92) " /sys/kernel/debug/gpio`. If the hall polarity is inverted on your unit, set `BANANARCHY_LID_GPIO_FILE` to a different debugfs GPIO file for the fallback path. +- **Cover display status**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl`; the native `bananarchy-coverd` is retained only for diagnostics. The shipping DTS keeps the known-good single internal panel; `cover-panel.dtsi` is compile-tested but not applied. The expected live state is no `/dev/fb1` and `bananarchy-coverctl STATUS` reporting `backend=none`. The renderer uses the 32-bpp fbdev `write()` path for future hardware (not `mmap()`, which raises `SIGBUS` on the DRM fbdev). gpio13 selection and external reset polarity still require physical sign-off before the overlay is re-enabled. +- **Camera app frozen / UI unresponsive**: check `top` for `bananarchy-volume-keys`. The daemon must be a single instance at 0% CPU; stale evdev fds are pruned by `prune_devices()`/`drop_device()` and guarded by `flock`. `rc-service bananarchy-volume-keys status` and `bananarchy-keypad-diagnose.sh` report its state. `xcamera` should return immediately and `bananarchy-photo ` should write a 600x800 JPEG. +- **Camera**: `/dev/video0` is provided by the out-of-tree `msm8905-cam` module, loaded at boot by `/etc/modules-load.d/bananarchy-hardware.conf` and `etc/local.d/10-bananarchy-hardware.start`. Check with `v4l2-ctl --list-devices`; a missing node means the module did not load (previously caused by a missing `/bin/sed` breaking the `modules` service). +- **Side volume keys**: the compiled evdev daemon `bananarchy-volume-keys` reads `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN` directly and calls `sxmo_audio.sh vol up/down 5`; `sxmo_audio.sh` mirrors that percentage into the live PipeWire sink (the MSM8905 mainline kernel has no ALSA card yet). Press a side button and check `wpctl get-volume `; `bananarchy-keypad-diagnose.sh` reports the XKB mapping and both volume values. +- **First-boot checklist**: the rootfs must contain the full BusyBox applet set (`scripts/busybox-applets.txt`). `/bin/ash` is the `user` login shell and `/bin/grep` is used by OpenRC; if either is missing, sshd rejects `user/147147` and `udev` cannot start. Check `rc-service udev status` and `DISPLAY=:0 xinput list`: the keypad only appears in X when udev is running, `/dev/input/event*` are `0660 root:input` and elogind lists the keyboards under `seat0`. Run `rc-service tinydm restart` after fixing udev. +- **SSH rejects `147147`**: the PAM-enabled `/usr/sbin/sshd.pam` is pinned through `/etc/conf.d/sshd`, `/etc/pam.d/sshd` supplies an explicit `pam_unix` stack, and both `PasswordAuthentication` and `KbdInteractiveAuthentication` are enabled in `/etc/ssh/sshd_config.d/90-bananarchy-access.conf`. If PAM is ever broken again, a USB-only diagnostic listener is available on port 2222 (bound to `172.16.42.1`, never to Wi-Fi): + ```bash + ssh -p 2222 user@172.16.42.1 + ``` + The phone key in `keys/phone_id_ed25519` is pre-authorized for both `user` and `root`; add `touch /etc/bananarchy-no-debug-sshd` to turn the fallback listener off. +- **No boot splash**: the `extlinux.conf` `append` line must contain `quiet splash`. The pmOS initramfs defaults to `nosplash=y` and only starts `plymouthd` for the literal `splash` parameter; `scripts/sync-beatles-bootfs.py` restores the release cmdline and `--check` rejects a debug cmdline. Use `--debug-cmdline --allow-debug` only for a diagnostic build. +- **Keypad does not respond**: run `bananarchy-keypad-diagnose.sh` over SSH. It reports `/proc/bus/input/devices`, udev `ID_INPUT_*` tags (forced by `99-bananarchy-keypad.rules`), `SW_LID` / `SW_KEYPAD_SLIDE` state, kernel messages, Xorg/libinput devices and a short raw `evtest` probe. The Xorg rule `60-bananarchy-keypad.conf` binds the matrix keypad by product name so a missing `ID_INPUT_KEYBOARD` tag cannot make X ignore it. If the kernel emits no `EV_KEY` events at all, check the row/column GPIOs and `SW_LID` polarity on hardware. + +--- + ## 5. Command-line hardware reference ### 5.1 Taking photos and screenshots (`bananarchy-photo`, `bananarchy-screenshot`, and `/dev/video0`) @@ -626,3 +651,7 @@ sudo ./flash-edl.sh nokia-argon # uses vendor/edl/ and auto-instal ``` The bootstrap is idempotent: an up-to-date rootfs is left untouched. `prebuilt/` is the single source of truth for compiled artifacts, and `scripts/rootfs-packages.txt` is the single source of truth for the package set. The patched EDL client library is vendored under `vendor/edl/` (MIT), so flashing works from a clean clone without a manual download; `flash-edl.sh` installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory when needed. + +## Verified 2720 Flip image set + +For the `a1108` / `dejavu` release, use the verified known-good `nokia-beatles` raw image, standalone boot image, and display-enabled lk2nd image generated in `images/`. These files are local build outputs and are not tracked in git; `scripts/check-rebuild.sh` pins their hashes when present. The X session performs a one-shot startup cleanup of stale `dmenu` and xlocker keyboard grabs, while `dwm` keeps the known-good 350 ms wake guard. `prepare-release.sh` rebuilds missing images from source and packages them; use `BA_REBUILD=1` for a forced source rebuild. diff --git a/README.md b/README.md index deb615d..f959c46 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ bananarchy/ ├── rebuild-image.sh # Builds boot.img and partitioned MBR .img ├── chroot-shell.sh # Rootless Docker armv7 package and rootfs customization shell ├── artwork/ # Bananarchy master icon, generated icons, wallpapers, and splashes -├── bootloader/ # lk2nd secondary bootloader and Sahara/Firehose programmer (8110.mbn) +├── bootloader/ # lk2nd secondary bootloader, source port patch/toolchain, and per-device Sahara/Firehose programmers ├── devices/ # Device definitions, DTBs, and MIPI-DBI panel init sequences ├── patches/ # Upstream kernel, EDL, Sxmo, Xlibre, and fcitx5-t9 patch sets ├── src/ @@ -183,6 +183,7 @@ All components are pre-compiled in `prebuilt/` and `overlay/rootfs/`, and can be ``` Output images are written to `images/`: - `images/bananarchy-.img`: partitioned MBR image with `pmOS_boot` + `pmOS_root` for EDL `userdata`, `fastboot flash userdata`, or a microSD card. +- `images/boot-bananarchy-.img`: standalone Android `boot.img` with the appended device DTB. On `nokia-beatles` the default `--method lk2nd` boots the **source-built** `images/boot-lk2nd-nokia-beatles-display.img` first (the upstream QCDT layout with a compact `/lk2nd/nokia-beatles` node, `/cpus` added to every QCDT DTB to satisfy aboot's partial-goods ASSERT, and the GC9305 v2 panel init stream; see `bootloader/lk2nd/README.md`), then lk2nd loads this kernel/DTB from `userdata` via `extlinux.conf`. The default writes lk2nd to `boot` and this standalone `boot.img` to `recovery`; `--method both` is the fallback that flashes it into both slots. Hold Volume Up if the KaiOS splash persists. The stock 2720 aboot is locked, so the flasher also sets `devinfo.is_unlocked=1` by default (see `scripts/make-unlocked-devinfo.py`); pass `--no-unlock-bootloader` only if you know the device is already unlocked. The eMMC `devinfo` unlock is effective here (`VB_L` path, no `keymaster`), so EDL alone is sufficient; stock fastboot / `oem unlock-go` is not required. `--only-unlock` is optional. After changing that DTB, run `scripts/repack-beatles-bootimg.py` and `scripts/sync-beatles-bootfs.py --debug-cmdline`; rebuild lk2nd with `scripts/build-lk2nd-beatles.sh` if the lk2nd port changed; validate with `scripts/check-beatles-bootimg.py`, `scripts/check-lk2nd-beatles.py`, `scripts/test-lk2nd-beatles-port.py` and `scripts/sync-beatles-bootfs.py --check`. If the phone only shows the KaiOS logo and then goes dark, check `lsusb`: `05c6:900e` means aboot crashed into EDL. The confirmed cause was `ASSERT FAILED at (platform/msm_shared/partial_goods.c:80): 0` because lk2nd's QCDT DTBs lacked `/cpus`; the port now adds it. Flash `images/boot-lk2nd-nokia-beatles-diagnostic.img` with `--lk2nd-image --verify --dump-diagnostics` (forced fastboot + runtime `oem display-init` probe, QCDT panel fallback for chain-loading, final post-update `oem scan-dtb`, and bounded pstore console staging), if it returns to `900e`, re-read aboot's RLOG buffer for the next ASSERT (the untouched `bootloader/lk2nd-msm8909.img` lacks `/cpus` too and will crash identically); see `bootloader/lk2nd/README.md`. --- @@ -194,10 +195,17 @@ sudo ./flash-edl.sh nokia-argon The patched EDL client library is vendored under `vendor/edl/` (MIT), so a clean clone flashes without any manual download. `flash-edl.sh` also installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory when the host lacks them; set `BANANARCHY_EDL_DIR` to use a different library checkout. +After a successful flash the phone boots lk2nd's branded boot splash, then the Plymouth boot splash, then X. Log in over the USB network with `ssh user@172.16.42.1` (password `147147`); if the main sshd's PAM stack is ever broken, a USB-only fallback listener accepts the same credentials on `ssh -p 2222 user@172.16.42.1`. Selecting **Reboot to loader** from the Power menu shows the visible lk2nd Fastboot menu; **Bootloader** stays in fastboot, **EDL** enters Sahara, and `fastboot reboot` returns to Linux. On the 2720 Flip, OpenRC starts independent services in parallel with a patched `local` service, a bounded `udevadm settle` and an independent USB fallback sshd keep X from waiting on modem firmware, a boot-open lid starts unlocked with a live keypad, and the external cover overlay remains compile-tested but hardware-gated; the compiled idle renderer is ready for a future `/dev/fb1`. See `MANUAL.md` section 4.1 for first-boot troubleshooting of the boot splash, keypad input and the external cover display. + See [MANUAL.md](MANUAL.md) for complete EDL, Fastboot, and microSD installation instructions, keypad navigation shortcuts, and the multi-mode T9 reference. + ## Credits All Bananarchy-specific components were initially created by Luxferre and released into the public domain with no warranties. Alpine Linux, postmarketOS/Nura, and other third-party components are guided by their respective licensing terms. + +## Verified 2720 Flip release images + +The `a1108` / `dejavu` release packages the physically verified known-good 2720 Flip image set: the raw `userdata` image, standalone mainline `boot.img`, and display-enabled lk2nd image. These are local build outputs, not tracked in git; `scripts/check-rebuild.sh` pins their hashes when present, and `prepare-release.sh` rebuilds missing artifacts from source. `dwm` uses the known-good 350 ms wake guard, the X session releases stale startup keyboard grabs once, and `BA_REBUILD=1` forces an explicit rebuild. diff --git a/bootloader/lk2nd/Dockerfile b/bootloader/lk2nd/Dockerfile new file mode 100644 index 0000000..d16ccf9 --- /dev/null +++ b/bootloader/lk2nd/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.20 +RUN apk add --no-cache \ + gcc-arm-none-eabi \ + make \ + python3 \ + dtc \ + dtc-dev \ + tar \ + git \ + py3-setuptools diff --git a/bootloader/lk2nd/README.md b/bootloader/lk2nd/README.md new file mode 100644 index 0000000..be6ecee --- /dev/null +++ b/bootloader/lk2nd/README.md @@ -0,0 +1,265 @@ +# nokia-beatles lk2nd port + +Source port of +[`msm8916-mainline/lk2nd`](https://github.com/msm8916-mainline/lk2nd) for the +**Nokia 2720 Flip (`nokia-beatles`)**. Both images in `images/` are compiled +from source; the old binary-patching approach is gone. + +## Root cause of "black screen, no fastboot" (confirmed) + +The phone enumerates as **`05c6:900e` in Sahara MEMORY_DEBUG mode** after every +boot attempt — aboot crashed before lk2nd ever ran. Reading aboot's RAM over +Sahara exposed its `WITH_DEBUG_LOG_BUF` ring buffer (cookie `0x474f4c52` +"RLOG"), which contains the exact failure: + +``` +[580] target_display_init ret=0 +[590] Failed to get parent node: /cpus errno:-1 +[600] panic (caller 0x8f61aa00): ASSERT FAILED at (platform/msm_shared/partial_goods.c:80): 0 +[610] HALT: reboot into dload mode... +``` + +The 2720's **MSM8905 is a partial-goods (2-core) part**. Its stock aboot calls +`update_partial_goods_dtb_nodes()` on the QCDT-selected device tree and +`ASSERT(0)`s when `/cpus`, `/cpus/cpu@2` or `/cpus/cpu@3` (with a 4-byte +`device_type`) is missing. It then rewrites those `device_type` values from +`"cpu\0"` to `"nak\0"`. **Upstream lk2nd's QCDT DTBs contain no `/cpus` node at +all** (only `/`, `/chosen`, `/memory`, `/lk2nd`), so *every* lk2nd image — +including the untouched `bootloader/lk2nd-msm8909.img` — crashes on this phone. +That is why lk2nd never appeared, why the screen went dark, and why no fastboot +ever enumerated. + +Other evidence from the same dump: + +- aboot's BSS held our boot.img header (`ANDROID!`, kernel 345048) and cached + cmdline `lk2nd lk2nd.compatible=nokia,beatles`; it had also built + `mdss_mdp3.panel=1:spi:0:qcom,mdss_spi_gc9305_v2_qvga_cmd:1:none`, i.e. it + accepted the image, detected the panel and **initialized the panel itself**. +- The kernel payload at `0x80008000` was byte-identical to the flashed image; + lk2nd's BSS at `0x80080000` was all zeros, so it never executed. +- `devinfo` from the last dump has `is_unlocked=1`, so signature verification is + not the blocker. + +Crash evidence lives in `backup/nokia-beatles-2720/crash-20261109/` +(`aboot-log.txt`, `aboot_full_rw.bin`, `memory_table.bin`, `aboot_bss2.bin`, +`aboot_data.bin`, `mem_bootimg.bin`, `load_cmm.bin`, `rst_stat.bin`, +`pmic_pon.bin`, `ocimem.bin`). + +## The port + +- **`/cpus` fix** in the common `lk2nd/device/dts/lk2nd.dtsi`: a `/cpus` node + with `cpu@0`..`cpu@3`, each `device_type = "cpu"` (exactly 4 bytes so aboot's + `fdt_setprop_inplace(..., "nak", 4)` succeeds). Because it is in the common + dtsi, **all eight QCDT DTBs** in the image have it — aboot cannot pick one + without it. The mainline `qcom-msm8905-nokia-beatles.dtb` already has `/cpus`, + so the Volume Up recovery path is fine too. +- **No separate QCDT DTB.** `msm8905-qrd-skub.dts` keeps upstream's + `qcom,msm-id = <0x14b 0>` and + `qcom,board-id = <0x0b 0x100>, <0x1000b 0x100>`. Both `0x14b` entries + (`0xb/0x100` and `0x1000b/0x100`) point at the same DTB. Growing `dt_size` + is harmless — aboot happily processed a `24576`-byte QCDT before patching it. +- `nokia-beatles.dtsi` injects a compact `/lk2nd/nokia-beatles` node: + `model = "Nokia 2720 Flip"`, `compatible = "nokia,beatles"`, + `lk2nd,match-panel`, `lk2nd,dtb-files = "msm8905-nokia-beatles"` (lk2nd + resolves this to `qcom-msm8905-nokia-beatles.dtb`), and three panel subnodes + matching every name the aboot can report. +- Only `qcom,mdss_spi_gc9305_v2_qvga_cmd` — the panel the live aboot reports — + carries `lk2nd,panel-init`: the downstream KaiOS 3.10 + `qcom,mdss-spi-on-command` stream in `[wait dlen payload...]` form, setting + RGB565, the 240x320 window, sleep-out, display-on and RAMWR. + `lk2nd.force-panel-init` forces a replay; by default lk2nd keeps aboot's + cont-splash init because aboot reports `1:spi:0:`. +- `lk2nd/include/lk2nd/spi-panel-init.h`: byte-stream walker shared between + `platform/msm_shared/mdss_spi.c` and the host unit test. +- `lk2nd/device/2nd/spi-display.c`: guards a NULL interface, looks up the + stream, and paints the Bananarchy RGB565 boot splash before the first + framebuffer flush (`DISABLE_SPLASH_PARTITION=1` plus `menu.c`'s bottom-only + text otherwise leaves a nearly black frame). +- Cmdline: `lk2nd lk2nd.compatible=nokia,beatles` — an upstream lk2nd feature + that selects the beatles node directly. + +## Current state: lk2nd works; the display is opt-in and probeable + +lk2nd boots, reaches fastboot and the extlinux chain. The mainline kernel +still has not been observed booting successfully; that is a separate issue +(the kernel side, not lk2nd). The remaining lk2nd work was to make panel +initialization **safe and verifiable** rather than disabled forever. + +Earlier attempts to enable the SPI display during `LK2ND_INIT` wedged lk2nd +before USB came up (boot vibrator stuck on, no fastboot). The cause is QUP +SPI/clock register polls with no timeout: several loops in `spi_qup.c` and +`clock_lib2.c` spin forever when the clock never comes up. The port now: + +- Bounds every QUP FIFO wait (`QUP_FIFO_TIMEOUT`) and every stuck clock poll + (`CLK_POLL_TIMEOUT`), so a dead bus can never wedge the bootloader. +- Registers a RAM-only 240x320 RGB565 framebuffer at boot by default + (`lk2nd.no-display`), which keeps `fbcon_display()` non-NULL so cont-splash + does not try to read MDP registers. +- Adds fastboot commands that run **after USB is up**: + - `fastboot oem display-init` — `mdss_spi_init()`, the GC9305 v2 + `lk2nd,panel-init` stream (RGB565, 240x320 window, sleep-out, display-on, + RAMWR), then paint the branded boot splash and flush one frame. Safe because + all polls are bounded; failures are reported and logged, not hung. + - `fastboot oem display-test` — repaint and flush. + - `fastboot oem screenshot && fastboot get_staged shot.ppm` — verify the + framebuffer contents. + - `fastboot oem scan-dtb && fastboot get_staged kernel.dtb` — stage the + exact DTB lk2nd hands the kernel (after DT updates) for offline inspection. + - `fastboot oem scan-boot` / `oem log` — extlinux scan and boot log. +- `images/boot-lk2nd-nokia-beatles-display.img` uses `lk2nd.display=on` to + run the same panel init during boot. Flash it with + `--lk2nd-image ./images/boot-lk2nd-nokia-beatles-display.img`. + +Corrections to earlier notes: the pmOS initramfs jumps straight to stage 2 +when `/init_2nd.sh` is present (it is), so a missing `/boot/initramfs-extra` +is **not** the cause of a hang. And an all-`0xff` ramoops region after a hard +power cycle is decayed DRAM, not proof that the kernel hung before pstore. + +## Decisive finding: extlinux is fine, the mainline kernel hangs + +`oem scan-boot` run on the live device proved the boot chain: `wrp0p32p0` +(pmOS_boot, 256 MiB) enumerated and mounted, `/extlinux/extlinux.conf` +parsed, `vmlinuz` / `qcom-msm8905-nokia-beatles.dtb` / `initramfs` all +resolved and `lk2nd_boot_label()` reached `boot_linux()` without errors. +`oem read-partition` also verified the live `userdata` MBR (`55aa`, two +`0x83` partitions) and its ext2 superblock (`53ef` at 1 MiB). + +So the mainline kernel is where the remaining hang is. `fastboot boot` of the +standalone debug boot.img also downloaded OKAY then produced no USB RNDIS, +consistent with a kernel that stops before userspace. lk2nd now always +injects the ramoops reserved-memory node on Linux boots, and +`CONFIG_PSTORE_RAM=y` / `CONFIG_PSTORE_CONSOLE=y` are enabled; a warm reset +(power-cycle into fastboot with Vol Down + Power) should preserve +`oem ramoops console` output. A hard power-off decays DRAM instead, which is +why one earlier read of that region was all `0xff`. + +Note: the panel init stream in `lk2nd,panel-init` is the downstream KaiOS +3.10 `qcom,mdss-spi-on-command` sequence for `spi_gc9305_v2_qvga_cmd`, +byte-for-byte ([wait dlen payload...] with the wait applied after the +command). `lk2nd/include/lk2nd/spi-panel-init.h` walks it; the host C test +verifies framing, RGB565, 240x320 window, delays and error handling. + +## Live hardware confirmation and next step + +The GC9305 v2 panel init is confirmed on the phone. A chain-loaded +diagnostic image initially lacked aboot's `mdss_mdp3.panel` tag, so the +port now falls back to the beats QCDT node's only `lk2nd,panel-init` +stream and keeps the known SPI interface. With that fallback, +`oem display-init` and `oem display-test` both returned OKAY, USB stayed +up, and `oem screenshot` staged a 240x320 P6 framebuffer with exactly the +three test colors: a cyan 20-pixel top bar and alternating blue/dark +a branded splash. The boot-time `lk2nd.display=on` path also pushes SPI +traffic; the forced-fastboot menu redraws over the splash afterwards. + +The diagnostics were tightened after that live run: + +- `oem scan-boot` now lets `boot_linux()` apply the final cmdline and DT + updates, then returns before the kernel jump. `oem scan-dtb` therefore + stages the actual post-update DTB, not the raw extlinux file. +- `oem ramoops console` validates the pstore signature, size and offset, + rotates a wrapped ring buffer, and reports `No valid pstore console` + for decayed DRAM instead of trying to stage `0xffffffff` bytes. +- The upstream per-word QUP `SPEW` log was removed. Earlier `DEBUG=2` + builds spent about 40 seconds per full frame and overwrote the whole + 32 KiB log with FIFO status lines. + +From fastboot, without reflashing: + +```bash +fastboot boot ./images/boot-lk2nd-nokia-beatles-diagnostic.img +fastboot getvar lk2nd:panel +fastboot oem display-init +fastboot oem display-test +fastboot oem screenshot && fastboot get_staged shot.ppm +fastboot oem scan-boot +fastboot oem scan-dtb && fastboot get_staged kernel.dtb +fastboot oem log && fastboot get_staged lk2nd.log +fastboot oem ramoops console && fastboot get_staged console.log +``` + +Use `kernel.dtb` to check whether `cpu@2`/`cpu@3` are `status = "fail"` +on this dual-core partial-goods part (fuse `0x58000` reads `0x30100094`). +The `r2` diagnostic staged a 41440-byte final DTB that differs from the +source DTB: `cpu@2`/`cpu@3` are `status = "fail"`, +`/reserved-memory/ramoops@9fa80000` has a 256 KiB console, and `/chosen` +contains the final bootargs plus `linux,initrd-start` / `linux,initrd-end`. +The partial-goods DT update is therefore confirmed; enabled CPU2/3 are no +longer the leading kernel-hang suspect. If pstore was populated by a warm +reset, `console.log` gives the kernel console; a hard power-off decays DRAM +and produces no valid console. Upstream `oem read-partition` passes the +requested byte count directly to `mmc_read()`, which asserts unless the +size is a 512-byte multiple; the 16-byte `SEANDROIDENFORCE` tail used to +drop USB during boot-slot read-back. The r3 port rounds the MMC read up +internally, rejects unaligned offsets and stages only the requested byte +count. Use `fastboot reboot`, not `fastboot reboot-bootloader`, to test a +persisted boot slot. `reboot-bootloader` now writes the low-bit +`FASTBOOT_MODE` cookie and returns to this lk2nd Fastboot menu; it is not +a way to test the newly flashed image. A `fastboot flash boot` handoff can +still drop USB, so power-cycle with Vol Down + Power if fastboot does not +reappear. + +## Power-menu Fastboot menu + +`sxmo_power.sh loader` writes `0x02` into `PON_SOFT_RB_SPARE[1:0]`. The stock +boot chain scrubs the upstream high-bit cookie before chain-loading lk2nd, so +this port's `check_hard_reboot_mode()` prefers bits `[1:0]` and its +`reboot_device()` writes the same low-bit cookie for `FASTBOOT_MODE`. That +keeps **Bootloader**, **EDL**, **Reboot**, **Recovery** and **Shutdown** +visible on the display-enabled image. Live verification: the menu appears +within 6 s, `fastboot oem screenshot` stages the 240x320 menu frame, and +`fastboot reboot-bootloader` returns to `lk2nd:version` instead of booting +Linux. + +## Building + +```sh +./scripts/build-lk2nd-beatles.sh # build normal + diagnostic + display + validate +./scripts/build-lk2nd-beatles.sh --check # validate the shipped images only +./scripts/build-lk2nd-beatles.sh --only normal|diagnostic|display +./scripts/build-lk2nd-beatles.sh --only normal --force-panel-init +WITH_DISPLAY=1 ./scripts/build-lk2nd-beatles.sh --only normal +``` + +Pins upstream commit `cf45aefd22d744b2bf9b39455afae697ce430063`, applies +`nokia-beatles.patch`, builds inside the rootless Docker toolchain image from +`Dockerfile` (`gcc-arm-none-eabi`, `dtc`, `libfdt`). All three images are +reproducible byte for byte. Overrides: `BANANARCHY_LK2ND_SRC`, +`BANANARCHY_LK2ND_BUILD_DIR`, `JOBS`. + +## Validating + +```sh +python3 scripts/check-lk2nd-beatles.py # boot header, QCDT, DTB, /cpus, stream +python3 scripts/check-lk2nd-beatles.py \ + --image images/boot-lk2nd-nokia-beatles-display.img --expect-display 1 +python3 scripts/test-lk2nd-beatles-port.py # all 3 images + host C parser unit test +``` + +The validator is pure Python (it parses the FDT itself) and enforces that +**every** QCDT DTB has `/cpus/cpu@2` and `/cpus/cpu@3` with a 4-byte +`device_type`, that both `0x14b` entries share one DTB, and that the 2720 DTB +carries the beatles node with a valid GC9305 v2 `lk2nd,panel-init` stream. + +## Panel data provenance and limits + +The v2 init stream comes from the 2720 downstream KaiOS 3.10 +`arch/arm/boot/dts/qcom/spi-panel-gc9305-qvga-cmd.dtsi` as adapted by the +archived pmaports `linux-nokia-beatles` package. The other two panel names are +match-only nodes: aboot detects and initializes those sources itself and their +exact streams are not published. The 240x240 external cover display is a +separate SPI panel, untouched by lk2nd. The kernel `spi-mux` modules are +built and loaded, but the overlay remains hardware-gated until gpio13 and the +external reset/DC routing are validated. + +SPI wiring matches downstream: `BLSP_QUP_BASE(1, 4)` is `spi@78b9000` +(BLSP1 QUP5 in 1-based numbering), DC GPIO 110. + +## Normal flashing + +```sh +sudo ./flash-edl.sh nokia-beatles --backup-dir ./backup/nokia-beatles-2720 --verify +``` + +`flash-edl.py` writes the normal image to `boot` and the standalone mainline +`boot.img` to `recovery` (Volume Up fallback), and unlocks eMMC `devinfo` first. +A successful Bananarchy boot has not been observed yet. diff --git a/bootloader/lk2nd/nokia-beatles.patch b/bootloader/lk2nd/nokia-beatles.patch new file mode 100644 index 0000000..0fe3018 --- /dev/null +++ b/bootloader/lk2nd/nokia-beatles.patch @@ -0,0 +1,1192 @@ +diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c +index b44a5c2..a227768 100644 +--- a/app/aboot/aboot.c ++++ b/app/aboot/aboot.c +@@ -61,6 +61,10 @@ + #include + #include + #include ++ ++/* Set by lk2nd's "oem scan-boot" command. */ ++extern bool lk2nd_scan_only; ++ + #if USE_RPMB_FOR_DEVINFO + #include + #endif +@@ -1248,6 +1252,13 @@ void boot_linux(void *kernel, unsigned *tags, + #endif + + tags_done: ++ if(lk2nd_scan_only) { ++ dprintf(INFO, "scan-only: final kernel cmdline/DTB ready, staying in fastboot\n"); ++ if(final_cmdline) ++ free(final_cmdline); ++ return; ++ } ++ + #if VERIFIED_BOOT + if (VB_M <= target_get_vb_version()) + { +diff --git a/lk2nd/boot/extlinux.c b/lk2nd/boot/extlinux.c +index 5bcf607..5145c1d 100644 +--- a/lk2nd/boot/extlinux.c ++++ b/lk2nd/boot/extlinux.c +@@ -19,6 +19,14 @@ + + #include "boot.h" + ++/* Set by the "oem scan-boot" fastboot command. boot_linux() applies the ++ final cmdline/DT updates and returns before the kernel jump. */ ++bool lk2nd_scan_only = false; ++ ++/* Staged by "oem scan-dtb" after lk2nd's final DT updates so the exact ++ DTB handed to the kernel can be inspected offline. */ ++void *lk2nd_last_kernel_dtb; ++ + struct label { + const char *name; + const char *kernel; +@@ -607,6 +615,8 @@ static void lk2nd_boot_label(struct label *label) + return; + } + ++ lk2nd_last_kernel_dtb = addrs.tags; ++ + if (label->dtboverlays) { + ret = fdt_open_into(addrs.tags, addrs.tags, MAX_TAGS_SIZE); + if (ret < 0) { +@@ -649,7 +659,14 @@ static void lk2nd_boot_label(struct label *label) + arch_clean_invalidate_cache_range((addr_t)addrs.ramdisk, ramdisk_size); + } + +- boot_linux(addrs.kernel, ++ if(lk2nd_scan_only) { ++ dprintf(INFO, "scan-only: kernel=%s dtb=%s initramfs=%s\n", ++ label->kernel, label->dtb, ++ label->initramfs ? label->initramfs : "(none)"); ++ dprintf(INFO, "scan-only: cmdline=%s\n", label->cmdline); ++ } ++ ++ boot_linux(addrs.kernel, + addrs.tags, + label->cmdline, + board_machtype(), +diff --git a/lk2nd/device/2nd/rules.mk b/lk2nd/device/2nd/rules.mk +index 06d2dd5..8b5e670 100644 +--- a/lk2nd/device/2nd/rules.mk ++++ b/lk2nd/device/2nd/rules.mk +@@ -8,6 +8,7 @@ MODULES += \ + + OBJS += \ + $(LOCAL_DIR)/device.o \ ++ $(LOCAL_DIR)/scan-boot.o \ + $(LOCAL_DIR)/match.o \ + $(LOCAL_DIR)/parse-cmdline.o \ + $(LOCAL_DIR)/parse-tags.o \ +diff --git a/lk2nd/device/2nd/scan-boot.c b/lk2nd/device/2nd/scan-boot.c +new file mode 100644 +index 0000000..f859cf4 +--- /dev/null ++++ b/lk2nd/device/2nd/scan-boot.c +@@ -0,0 +1,37 @@ ++// SPDX-License-Identifier: BSD-3-Clause ++/* ++ * "oem scan-boot" runs the whole extlinux scan while lk2nd stays in ++ * fastboot. boot_linux() applies the final cmdline/DT updates and returns ++ * before the kernel jump when lk2nd_scan_only is set, so "fastboot oem ++ * log" shows the boot scan and "oem scan-dtb" stages the final DTB. ++ */ ++ ++#include ++#include ++#include ++ ++#include ++ ++extern bool lk2nd_scan_only; ++extern void *lk2nd_last_kernel_dtb; ++ ++static void cmd_oem_scan_dtb(const char *arg, void *data, unsigned sz) ++{ ++ if (!lk2nd_last_kernel_dtb) { ++ fastboot_fail("run oem scan-boot first"); ++ return; ++ } ++ fastboot_stage(lk2nd_last_kernel_dtb, fdt_totalsize(lk2nd_last_kernel_dtb)); ++} ++FASTBOOT_REGISTER("oem scan-dtb", cmd_oem_scan_dtb); ++ ++static void cmd_oem_scan_boot(const char *arg, void *data, unsigned sz) ++{ ++ lk2nd_scan_only = true; ++ dprintf(INFO, "scan-boot: running extlinux scan without booting\n"); ++ lk2nd_boot(); ++ lk2nd_scan_only = false; ++ dprintf(INFO, "scan-boot: done\n"); ++ fastboot_okay(""); ++} ++FASTBOOT_REGISTER("oem scan-boot", cmd_oem_scan_boot); +diff --git a/lk2nd/device/2nd/spi-display.c b/lk2nd/device/2nd/spi-display.c +index 81595db..e55fe9c 100644 +--- a/lk2nd/device/2nd/spi-display.c ++++ b/lk2nd/device/2nd/spi-display.c +@@ -3,7 +3,11 @@ + + #include + #include ++#include ++#include + #include ++#include ++#include + #include + #include + +@@ -11,44 +15,351 @@ + + #include "device.h" + ++/** ++ * find_panel_init() - Look up the lk2nd,panel-init stream for the detected panel. ++ * ++ * The same QCDT image carries device nodes for several feature phones. Search ++ * all of them instead of relying on the matched device node, so the panel ++ * init also works when lk2nd was forced to a compatible via the cmdline. ++ * When name is NULL, the first panel node carrying an init stream is used; ++ * that lets a chain-loaded diagnostic probe work without aboot panel tags. ++ */ ++static const unsigned char *find_panel_init(const void *dtb, const char *name, ++ const char **found_name, int *len) ++{ ++ int lk2nd_node, dev_node, panel_node, node; ++ const void *prop; ++ ++ if(!dtb) ++ return NULL; ++ ++ lk2nd_node = fdt_path_offset(dtb, "/lk2nd"); ++ if(lk2nd_node < 0) ++ return NULL; ++ ++ fdt_for_each_subnode(dev_node, dtb, lk2nd_node) { ++ panel_node = fdt_subnode_offset(dtb, dev_node, "panel"); ++ if(panel_node < 0) ++ continue; ++ ++ fdt_for_each_subnode(node, dtb, panel_node) { ++ const char *node_name = fdt_get_name(dtb, node, NULL); ++ ++ if(name && (!node_name || strcmp(node_name, name))) ++ continue; ++ ++ prop = fdt_getprop(dtb, node, "lk2nd,panel-init", len); ++ if(prop && *len > 0) { ++ if(found_name) ++ *found_name = node_name; ++ return prop; ++ } ++ } ++ } ++ return NULL; ++} ++ ++static bool cmdline_flag(const char *flag) ++{ ++ const char *p = lk2nd_dev.cmdline; ++ size_t len = strlen(flag); ++ ++ if(!p) ++ return false; ++ while((p = strstr(p, flag))) { ++ if((p == lk2nd_dev.cmdline || p[-1] == ' ') && ++ (p[len] == '\0' || p[len] == ' ')) ++ return true; ++ p += len; ++ } ++ return false; ++} ++ + static void mdss_spi_flush(void) + { +- mdss_spi_on(NULL, fbcon_display()); ++ mdss_spi_on(NULL, fbcon_display()); ++} ++ ++static struct fbcon_config spi_fb; ++static bool spi_ready; ++ ++/** ++ * Bananarchy boot splash for the 240x320 RGB565 framebuffer. ++ * ++ * The old striped test pattern was useful to prove lk2nd owned the panel, ++ * but it is not a boot screen. This draws a compact branded splash with a ++ * banana crescent, wordmark and progress bar using only integer RGB565 ++ * writes, so it needs no image decoder, font file or extra library. ++ * Deliberately does not call fbcon_flush(): flushing a full frame over SPI ++ * before the bus is known to work used to wedge lk2nd before USB init. ++ */ ++#define SPLASH_RGB(r, g, b) \ ++ ((uint16_t)((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))) ++#define SPLASH_BG SPLASH_RGB(8, 12, 26) ++#define SPLASH_BG2 SPLASH_RGB(16, 24, 48) ++#define SPLASH_YELLOW SPLASH_RGB(250, 210, 60) ++#define SPLASH_WHITE SPLASH_RGB(235, 240, 248) ++#define SPLASH_BLUE SPLASH_RGB(90, 150, 240) ++#define SPLASH_GREY SPLASH_RGB(90, 100, 120) ++#define SPLASH_BROWN SPLASH_RGB(96, 64, 24) ++ ++struct splash_glyph { ++ char ch; ++ unsigned char col[5]; ++}; ++ ++/* 5x7 column-major bitmap font: each byte is one column, bit 0 is top. */ ++static const struct splash_glyph splash_font[] = { ++ {'A', {0x7e, 0x11, 0x11, 0x11, 0x7e}}, {'B', {0x7f, 0x49, 0x49, 0x49, 0x36}}, ++ {'C', {0x3e, 0x41, 0x41, 0x41, 0x22}}, {'D', {0x7f, 0x41, 0x41, 0x22, 0x1c}}, ++ {'E', {0x7f, 0x49, 0x49, 0x49, 0x41}}, {'F', {0x7f, 0x09, 0x09, 0x09, 0x01}}, ++ {'G', {0x3e, 0x41, 0x49, 0x49, 0x7a}}, {'H', {0x7f, 0x08, 0x08, 0x08, 0x7f}}, ++ {'I', {0x00, 0x41, 0x7f, 0x41, 0x00}}, {'J', {0x20, 0x40, 0x41, 0x3f, 0x01}}, ++ {'K', {0x7f, 0x08, 0x14, 0x22, 0x41}}, {'L', {0x7f, 0x40, 0x40, 0x40, 0x40}}, ++ {'M', {0x7f, 0x02, 0x0c, 0x02, 0x7f}}, {'N', {0x7f, 0x04, 0x08, 0x10, 0x7f}}, ++ {'O', {0x3e, 0x41, 0x41, 0x41, 0x3e}}, {'P', {0x7f, 0x09, 0x09, 0x09, 0x06}}, ++ {'Q', {0x3e, 0x41, 0x51, 0x21, 0x5e}}, {'R', {0x7f, 0x09, 0x19, 0x29, 0x46}}, ++ {'S', {0x46, 0x49, 0x49, 0x49, 0x31}}, {'T', {0x01, 0x01, 0x7f, 0x01, 0x01}}, ++ {'U', {0x3f, 0x40, 0x40, 0x40, 0x3f}}, {'V', {0x1f, 0x20, 0x40, 0x20, 0x1f}}, ++ {'W', {0x3f, 0x40, 0x38, 0x40, 0x3f}}, {'X', {0x63, 0x14, 0x08, 0x14, 0x63}}, ++ {'Y', {0x07, 0x08, 0x70, 0x08, 0x07}}, {'Z', {0x61, 0x51, 0x49, 0x45, 0x43}}, ++ {'0', {0x3e, 0x51, 0x49, 0x45, 0x3e}}, {'1', {0x00, 0x42, 0x7f, 0x40, 0x00}}, ++ {'2', {0x42, 0x61, 0x51, 0x49, 0x46}}, {'3', {0x21, 0x41, 0x45, 0x4b, 0x31}}, ++ {'4', {0x18, 0x14, 0x12, 0x7f, 0x10}}, {'5', {0x27, 0x45, 0x45, 0x45, 0x39}}, ++ {'6', {0x3c, 0x4a, 0x49, 0x49, 0x30}}, {'7', {0x01, 0x71, 0x09, 0x05, 0x03}}, ++ {'8', {0x36, 0x49, 0x49, 0x49, 0x36}}, {'9', {0x06, 0x49, 0x49, 0x29, 0x1e}}, ++ {'.', {0x00, 0x60, 0x60, 0x00, 0x00}}, {'-', {0x08, 0x08, 0x08, 0x08, 0x08}}, ++ {'!', {0x00, 0x00, 0x5f, 0x00, 0x00}}, {' ', {0x00, 0x00, 0x00, 0x00, 0x00}}, ++}; ++ ++static const unsigned char *splash_glyph(char ch) ++{ ++ unsigned i; ++ ++ for (i = 0; i < (sizeof(splash_font) / sizeof(splash_font[0])); i++) ++ if (splash_font[i].ch == ch) ++ return splash_font[i].col; ++ return splash_font[(sizeof(splash_font) / sizeof(splash_font[0])) - 1].col; ++} ++ ++static void splash_pixel(struct fbcon_config *fb, int x, int y, uint16_t color) ++{ ++ uint16_t *pixels = fb->base; ++ ++ if (x < 0 || y < 0 || (unsigned)x >= fb->width || (unsigned)y >= fb->height) ++ return; ++ pixels[y * fb->stride + x] = color; ++} ++ ++static void splash_rect(struct fbcon_config *fb, int x0, int y0, ++ int x1, int y1, uint16_t color) ++{ ++ int x, y; ++ ++ for (y = y0; y < y1; y++) ++ for (x = x0; x < x1; x++) ++ splash_pixel(fb, x, y, color); + } + ++static void splash_disc(struct fbcon_config *fb, int cx, int cy, ++ int r, uint16_t color) ++{ ++ int dx, dy; ++ ++ for (dy = -r; dy <= r; dy++) ++ for (dx = -r; dx <= r; dx++) ++ if (dx * dx + dy * dy <= r * r) ++ splash_pixel(fb, cx + dx, cy + dy, color); ++} ++ ++static void splash_text(struct fbcon_config *fb, const char *str, int x, int y, ++ int scale, uint16_t color) ++{ ++ const unsigned char *cols; ++ int cy, i; ++ ++ while (*str) { ++ cols = splash_glyph(*str++); ++ for (i = 0; i < 5; i++) ++ for (cy = 0; cy < 7; cy++) ++ if (cols[i] & (1u << cy)) ++ splash_rect(fb, x + i * scale, y + cy * scale, ++ x + (i + 1) * scale, y + (cy + 1) * scale, color); ++ x += 6 * scale; ++ } ++} ++ ++static void paint_boot_banner(struct fbcon_config *fb) ++{ ++ unsigned x, y; ++ ++ for (y = 0; y < fb->height; y++) ++ for (x = 0; x < fb->width; x++) ++ splash_pixel(fb, x, y, y < 26 ? SPLASH_BG2 : SPLASH_BG); ++ ++ /* Banana crescent: a filled disc with an offset cut-out. */ ++ splash_disc(fb, 120, 112, 54, SPLASH_YELLOW); ++ splash_disc(fb, 140, 90, 44, SPLASH_BG); ++ splash_disc(fb, 73, 157, 7, SPLASH_BROWN); ++ splash_disc(fb, 168, 150, 6, SPLASH_BROWN); ++ ++ splash_text(fb, "BANANARCHY", 30, 206, 3, SPLASH_WHITE); ++ splash_text(fb, "LINUX", 90, 244, 2, SPLASH_BLUE); ++ ++ /* Boot progress indicator (lk2nd is only the first stage). */ ++ splash_rect(fb, 28, 280, 212, 293, SPLASH_BG2); ++ splash_rect(fb, 30, 282, 210, 291, SPLASH_GREY); ++ splash_rect(fb, 31, 283, 31 + (178 * 28) / 100, 290, SPLASH_YELLOW); ++ splash_text(fb, "BOOTING...", 90, 300, 1, SPLASH_GREY); ++} ++ ++/** ++ * spi_display_setup() - Bring up the QUP SPI bus and the GC9305 main panel. ++ * ++ * Returns 0 on success. Every QUP wait is bounded (see spi_qup.c), so a ++ * missing clock or a dead panel can no longer wedge lk2nd before USB init. ++ */ ++static int spi_display_setup(void) ++{ ++ const unsigned char *init; ++ const char *panel_name = lk2nd_dev.panel.name; ++ const char *found_name = NULL; ++ int init_len = 0, ret; ++ bool have_init; ++ ++ /* A chain-loaded lk2nd does not inherit aboot's mdss_mdp3.panel tag. ++ * The beats QCDT node is authoritative: use its only panel init stream ++ * and keep the known SPI interface even when fastboot boot replaced the ++ * original cmdline. */ ++ if(lk2nd_dev.compatible && ++ !strcmp(lk2nd_dev.compatible, "nokia,beatles") && ++ (!lk2nd_dev.panel.intf || strcmp(lk2nd_dev.panel.intf, "spi"))) ++ lk2nd_dev.panel.intf = "spi"; ++ ++ if(!lk2nd_dev.panel.intf || strcmp(lk2nd_dev.panel.intf, "spi")) ++ return -1; ++ ++ init = find_panel_init(lk2nd_dev.dtb, panel_name, &found_name, &init_len); ++ if(!panel_name && found_name) { ++ lk2nd_dev.panel.name = found_name; ++ fastboot_publish("lk2nd:panel", found_name); ++ panel_name = found_name; ++ dprintf(INFO, "SPI panel fallback from QCDT: %s\n", found_name); ++ } ++ have_init = init != NULL; ++ ++ if(spi_ready) { ++ if(init && have_init) { ++ ret = mdss_spi_panel_init_commands(init, init_len); ++ if(ret) ++ dprintf(CRITICAL, "Failed to reinitialize SPI panel: %d\n", ret); ++ } ++ return 0; ++ } ++ ++ spi_fb.base = (void*)MIPI_FB_ADDR; ++ spi_fb.width = 240; ++ spi_fb.height = 320; ++ spi_fb.stride = spi_fb.width; ++ spi_fb.bpp = 16; ++ spi_fb.format = FB_FORMAT_RGB565; ++ spi_fb.update_start = NULL; ++ ++ ret = mdss_spi_init(); ++ if(ret) { ++ dprintf(CRITICAL, "Failed to initialize SPI bus: %d\n", ret); ++ /* Still register a RAM-only framebuffer so cont-splash does not try ++ * to read MDP registers, and so "oem screenshot" works. */ ++ fbcon_setup(&spi_fb); ++ paint_boot_banner(&spi_fb); ++ return ret; ++ } ++ ++ if(have_init) { ++ ret = mdss_spi_panel_init_commands(init, init_len); ++ if(ret) ++ dprintf(CRITICAL, "Failed to initialize SPI panel: %d\n", ret); ++ else ++ dprintf(INFO, "Initialized SPI panel %s (%d bytes)\n", ++ lk2nd_dev.panel.name, init_len); ++ } else { ++ dprintf(INFO, "SPI panel %s: keeping aboot continuous splash\n", ++ lk2nd_dev.panel.name ? lk2nd_dev.panel.name : "unknown"); ++ } ++ ++ spi_fb.update_start = mdss_spi_flush; ++ fbcon_setup(&spi_fb); ++ paint_boot_banner(&spi_fb); ++ spi_ready = true; ++ dprintf(INFO, "SPI display ready\n"); ++ return 0; ++} ++ ++static void cmd_oem_display_init(const char *arg, void *data, unsigned sz) ++{ ++ int ret = spi_display_setup(); ++ if(ret) { ++ fastboot_fail("SPI display init failed (see oem log)"); ++ return; ++ } ++ fbcon_flush(); ++ fastboot_okay(""); ++} ++FASTBOOT_REGISTER("oem display-init", cmd_oem_display_init); ++ ++static void cmd_oem_display_test(const char *arg, void *data, unsigned sz) ++{ ++ if(!spi_ready) { ++ int ret = spi_display_setup(); ++ if(ret) { ++ fastboot_fail("SPI display init failed (see oem log)"); ++ return; ++ } ++ } ++ paint_boot_banner(&spi_fb); ++ fbcon_flush(); ++ fastboot_okay(""); ++} ++FASTBOOT_REGISTER("oem display-test", cmd_oem_display_test); ++ + static void lk2nd_device2nd_init_spi_display(void) + { +- static struct fbcon_config fb; +- int ret; +- +- if (strcmp(lk2nd_dev.panel.intf, "spi")) +- return; +- +- if (!lk2nd_dev.panel.initialized) { +- dprintf(CRITICAL, "SPI display not initialized by previous bootloader\n"); +- return; +- } +- +- /* +- * FIXME: For now we assume that all devices with SPI display use the +- * same configuration, since this is mainly used by feature phones with +- * similar display panel configurations. This might need additional +- * configuration (e.g. via the device tree) in the future. +- */ +- fb.base = (void*)MIPI_FB_ADDR; +- fb.width = 240; +- fb.height = 320; +- fb.stride = fb.width; +- fb.bpp = 16; +- fb.format = FB_FORMAT_RGB565; +- fb.update_start = mdss_spi_flush; +- +- ret = mdss_spi_init(); +- if (ret) { +- dprintf(CRITICAL, "Failed to initialize SPI bus: %d\n", ret); +- return; +- } +- +- fbcon_setup(&fb); ++ if(cmdline_flag("lk2nd.no-display")) { ++ /* Proven-safe default: RAM-only framebuffer, never touch QUP SPI before ++ * USB/fastboot is up. "fastboot oem display-init" enables the panel at ++ * runtime. Pass lk2nd.display=on to enable it during boot instead. */ ++ if(!lk2nd_dev.panel.intf || strcmp(lk2nd_dev.panel.intf, "spi")) ++ return; ++ spi_fb.base = (void*)MIPI_FB_ADDR; ++ spi_fb.width = 240; ++ spi_fb.height = 320; ++ spi_fb.stride = spi_fb.width; ++ spi_fb.bpp = 16; ++ spi_fb.format = FB_FORMAT_RGB565; ++ spi_fb.update_start = NULL; ++ fbcon_setup(&spi_fb); ++ dprintf(INFO, "SPI display disabled by lk2nd.no-display (RAM-only fbcon)\n"); ++ return; ++ } ++ ++ if(cmdline_flag("lk2nd.display=on")) { ++ int ret = spi_display_setup(); ++ if(ret) ++ dprintf(CRITICAL, "SPI display unavailable: %d\n", ret); ++ return; ++ } ++ ++ /* Default: RAM-only framebuffer so the bootloader is never wedged by SPI. */ ++ if(!lk2nd_dev.panel.intf || strcmp(lk2nd_dev.panel.intf, "spi")) ++ return; ++ spi_fb.base = (void*)MIPI_FB_ADDR; ++ spi_fb.width = 240; ++ spi_fb.height = 320; ++ spi_fb.stride = spi_fb.width; ++ spi_fb.bpp = 16; ++ spi_fb.format = FB_FORMAT_RGB565; ++ spi_fb.update_start = NULL; ++ fbcon_setup(&spi_fb); ++ dprintf(INFO, "SPI display in probe mode (use oem display-init)\n"); + } + LK2ND_INIT(lk2nd_device2nd_init_spi_display); +diff --git a/lk2nd/device/dts/lk2nd.dtsi b/lk2nd/device/dts/lk2nd.dtsi +index 7b81484..84b2d81 100644 +--- a/lk2nd/device/dts/lk2nd.dtsi ++++ b/lk2nd/device/dts/lk2nd.dtsi +@@ -15,6 +15,46 @@ + + lk2nd: lk2nd { }; + ++ /* ++ * The 2720's MSM8905 is a partial-goods (2-core) part. Its stock aboot ++ * calls update_partial_goods_dtb_nodes() on the QCDT-selected DTB and ++ * ASSERTs if /cpus, /cpus/cpu@2 or /cpus/cpu@3 (with device_type) is ++ * missing: "Failed to get parent node: /cpus" then ++ * "panic: ASSERT FAILED at (platform/msm_shared/partial_goods.c:80): 0". ++ * Upstream lk2nd DTBs have no /cpus, so every lk2nd image crashed into ++ * Sahara memory-debug EDL before lk2nd ever ran. device_type must be ++ * exactly 4 bytes ("cpu\0") because aboot overwrites it with "nak\0". ++ * Keep this in the common dtsi so aboot cannot pick a DTB without it. ++ */ ++ cpus { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ cpu@0 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a7"; ++ reg = <0>; ++ }; ++ ++ cpu@1 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a7"; ++ reg = <1>; ++ }; ++ ++ cpu@2 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a7"; ++ reg = <2>; ++ }; ++ ++ cpu@3 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a7"; ++ reg = <3>; ++ }; ++ }; ++ + lk2nd-hw { + /omit-if-no-ref/ tlmm: gpio-tlmm { + compatible = "lk2nd,gpio"; +diff --git a/lk2nd/device/dts/msm8909/msm8905-qrd-skub.dts b/lk2nd/device/dts/msm8909/msm8905-qrd-skub.dts +index 40fa170..0bd2846 100644 +--- a/lk2nd/device/dts/msm8909/msm8905-qrd-skub.dts ++++ b/lk2nd/device/dts/msm8909/msm8905-qrd-skub.dts +@@ -5,8 +5,11 @@ + + / { + qcom,msm-id = ; +- qcom,board-id = , +- ; ++ /* Keep BOTH stock pairs in upstream order. aboot re-validates the first ++ qcom,board-id pair of the selected DTB; changing this crashed it. */ ++ qcom,board-id = , ++ ; ++ + }; + + &lk2nd { +@@ -63,3 +66,5 @@ + }; + }; + }; ++ ++#include "nokia-beatles.dtsi" +diff --git a/lk2nd/device/dts/msm8909/nokia-beatles.dtsi b/lk2nd/device/dts/msm8909/nokia-beatles.dtsi +new file mode 100644 +index 0000000..dab182c +--- /dev/null ++++ b/lk2nd/device/dts/msm8909/nokia-beatles.dtsi +@@ -0,0 +1,55 @@ ++// SPDX-License-Identifier: BSD-3-Clause ++/* ++ * Nokia 2720 Flip (nokia-beatles) lk2nd device node. ++ * ++ * The 2720 shares the MSM8905 QRD SKUB board with the CAT B35 and the ++ * Nokia 8110 4G, so the same QCDT image is used for all three. The stock ++ * aboot reports one of three GC9305-family SPI main panels in ++ * mdss_mdp3.panel=; all of them are 240x320 RGB565 command-mode panels on ++ * BLSP1 QUP5 with DC on GPIO 110. ++ * ++ * lk2nd,panel-init holds the downstream KaiOS 3.10 qcom,mdss-spi-on-command ++ * byte stream in its native [wait dlen payload...] format. lk2nd replays it ++ * after taking over the SPI bus so the address window and pixel format are ++ * correct even when aboot left the bus pointed at the 240x240 cover panel. ++ */ ++ ++&lk2nd { ++ nokia-beatles { ++ model = "Nokia 2720 Flip"; ++ compatible = "nokia,beatles"; ++ lk2nd,match-panel; ++ lk2nd,dtb-files = "msm8905-nokia-beatles"; ++ ++ panel { ++ compatible = "nokia,beatles-panel"; ++ ++ /* "first" source: aboot owns its init, lk2nd only matches the name */ ++ qcom,mdss_spi_gc9305_qvga_cmd { ++ compatible = "nokia,beatles-gc9305-panel"; ++ }; ++ ++ /* GC9305 v2 main panel (qcom,spi-pref-prim-pan) */ ++ qcom,mdss_spi_gc9305_v2_qvga_cmd { ++ compatible = "nokia,beatles-gc9305-v2-panel"; ++ lk2nd,panel-init = [ ++ 00 01 fe ++ 00 01 ef ++ 00 02 3a 05 ++ 00 02 35 00 ++ 00 05 2a 00 00 00 ef ++ 00 05 2b 00 00 01 3f ++ 00 01 2c ++ 78 01 11 ++ 00 01 29 ++ 00 01 2c ++ ]; ++ }; ++ ++ /* 3rd source: aboot owns its init, lk2nd only matches the name */ ++ qcom,mdss_spi_gc9305_3rd_qvga_cmd { ++ compatible = "nokia,beatles-gc9305-3rd-panel"; ++ }; ++ }; ++ }; ++}; +diff --git a/lk2nd/fastboot/fetch.c b/lk2nd/fastboot/fetch.c +index a60173f..b961995 100644 +--- a/lk2nd/fastboot/fetch.c ++++ b/lk2nd/fastboot/fetch.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -51,22 +52,43 @@ static bool cmd_fetch_parse_args(uint64_t *offset, uint64_t *size, char **sp) + + static unsigned cmd_fetch_read_mmc(const char *pname, void *data, char **sp) + { +- struct partition_info part = partition_get_info(pname); +- +- if (!part.offset) { +- fastboot_fail("partition not found"); +- return 0; +- } +- +- if (!cmd_fetch_parse_args(&part.offset, &part.size, sp)) +- return 0; +- +- if (mmc_read(part.offset, data, part.size)) { +- fastboot_fail("failed to read partition"); +- return 0; +- } +- +- return part.size; ++ struct partition_info part = partition_get_info(pname); ++ uint64_t base_offset, total_size; ++ uint32_t block_size, read_size; ++ ++ if(!part.offset) { ++ fastboot_fail("partition not found"); ++ return 0; ++ } ++ ++ base_offset = part.offset; ++ total_size = part.size; ++ if(!cmd_fetch_parse_args(&part.offset, &part.size, sp)) ++ return 0; ++ ++ block_size = mmc_get_device_blocksize(); ++ if(!block_size || (block_size & (block_size - 1))) { ++ fastboot_fail("invalid MMC block size"); ++ return 0; ++ } ++ if(part.offset % block_size) { ++ fastboot_fail("offset is not block-aligned"); ++ return 0; ++ } ++ ++ read_size = (uint32_t)ROUNDUP(part.size, block_size); ++ if(read_size > target_get_max_flash_size() || ++ (uint64_t)part.offset + read_size > base_offset + total_size) { ++ fastboot_fail("aligned read exceeds partition"); ++ return 0; ++ } ++ ++ if(mmc_read(part.offset, data, read_size)) { ++ fastboot_fail("failed to read partition"); ++ return 0; ++ } ++ ++ return part.size; + } + + static unsigned cmd_fetch_read_flash(const char *pname, void *data, char **sp) +diff --git a/lk2nd/include/lk2nd/spi-panel-init.h b/lk2nd/include/lk2nd/spi-panel-init.h +new file mode 100644 +index 0000000..440f0ed +--- /dev/null ++++ b/lk2nd/include/lk2nd/spi-panel-init.h +@@ -0,0 +1,53 @@ ++// SPDX-License-Identifier: BSD-3-Clause ++#ifndef LK2ND_SPI_PANEL_INIT_H ++#define LK2ND_SPI_PANEL_INIT_H ++ ++/* ++ * Walk a downstream qcom,mdss-spi-on-command byte stream. ++ * ++ * Every command is [wait_ms, dlen, payload[dlen]]. The first payload byte is ++ * the command (DC low), the rest are parameters (DC high), and wait_ms is ++ * applied after the command. This matches the KaiOS 3.10 mdss_spi_panel_on() ++ * implementation (struct spi_ctrl_hdr { char wait; char dlen; }). ++ * ++ * Returns 0 on success, a negative value on a malformed stream or a write ++ * error. The callbacks make this usable by both the target SPI driver and a ++ * host unit test. ++ */ ++struct lk2nd_spi_panel_init_ops { ++ int (*write_cmd)(const unsigned char *cmd); ++ int (*write_data)(const unsigned char *data, unsigned int len); ++ void (*delay)(unsigned int ms); ++}; ++ ++static inline int lk2nd_spi_panel_init_run(const unsigned char *cmds, ++ unsigned int len, const struct lk2nd_spi_panel_init_ops *ops) ++{ ++ unsigned int off = 0, size; ++ unsigned char wait; ++ int ret; ++ ++ while(off + 2 <= len) { ++ wait = cmds[off++]; ++ size = cmds[off++]; ++ if(!size || off + size > len) ++ return -1; ++ ++ ret = ops->write_cmd(cmds + off); ++ if(ret) ++ return ret; ++ if(size > 1) { ++ ret = ops->write_data(cmds + off + 1, size - 1); ++ if(ret) ++ return ret; ++ } ++ ++ off += size; ++ if(wait) ++ ops->delay(wait); ++ } ++ ++ return off == len ? 0 : -1; ++} ++ ++#endif /* LK2ND_SPI_PANEL_INIT_H */ +diff --git a/lk2nd/ramoops/ramoops.c b/lk2nd/ramoops/ramoops.c +index 39cee71..fdaac26 100644 +--- a/lk2nd/ramoops/ramoops.c ++++ b/lk2nd/ramoops/ramoops.c +@@ -6,6 +6,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -57,13 +58,19 @@ static int lk2nd_ramoops_dt_update(void *dtb, const char *cmdline, enum boot_typ + { + int ret, rmem_offset, offset; + struct ramoops_region region; +- char tmp[32], args[16]; ++ char tmp[32], args[16] = ""; + + if (boot_type & (BOOT_DOWNSTREAM | BOOT_LK2ND)) + return 0; + +- if (!lk2nd_cmdline_scan_arg(cmdline, "lk2nd.pass-ramoops", args, sizeof(args))) +- return 0; ++ /* ++ * Bananarchy: always pass ramoops on Linux boots. A kernel that hangs ++ * before userspace (no usb0 RNDIS) is otherwise completely silent; ++ * with this node its console survives a warm reset and can be read ++ * with "fastboot oem ramoops console". lk2nd.pass-ramoops=zap still ++ * clears the region. ++ */ ++ lk2nd_cmdline_scan_arg(cmdline, "lk2nd.pass-ramoops", args, sizeof(args)); + + get_ramoops_region(®ion); + +@@ -187,45 +194,90 @@ static void cmd_oem_ramoops_regions(const char *arg, void *data, unsigned sz) + } + FASTBOOT_REGISTER("oem ramoops regions", cmd_oem_ramoops_regions); + +-static void cmd_oem_ramoops_console(const char *arg, void *data, unsigned sz) ++static int ramoops_console_record_valid(const struct ramoops_region *region, ++ const struct pram_buf *record) + { +- struct ramoops_region region; +- struct pram_buf *record; +- uint8_t *record_base; ++ size_t data_size = region->console_size - sizeof(*record); + +- get_ramoops_region(®ion); +- +- record_base = region.base + region.dump_size; +- record = (struct pram_buf*)record_base; ++ return region->console_size > sizeof(*record) && ++ record->sig == PERSISTENT_RAM_SIG && ++ record->size <= data_size && ++ record->offt <= data_size; ++} + +- fastboot_stage(record->data, record->size); ++static void cmd_oem_ramoops_console(const char *arg, void *data, unsigned sz) ++{ ++ struct ramoops_region region; ++ struct pram_buf *record; ++ size_t data_size, size, start, tail; ++ uint8_t *record_base, *buf; ++ ++ get_ramoops_region(®ion); ++ ++ record_base = region.base + region.dump_size; ++ record = (struct pram_buf*)record_base; ++ data_size = region.console_size - sizeof(*record); ++ ++ if(!ramoops_console_record_valid(®ion, record) || !record->size) { ++ fastboot_fail("No valid pstore console"); ++ return; ++ } ++ ++ size = record->size; ++ buf = malloc(size); ++ if(!buf) { ++ fastboot_fail("Cannot allocate console buffer"); ++ return; ++ } ++ ++ start = record->offt % data_size; ++ if(size == data_size && start) { ++ tail = data_size - start; ++ memcpy(buf, record->data + start, tail); ++ memcpy(buf + tail, record->data, size - tail); ++ } else { ++ memcpy(buf, record->data, size); ++ } ++ ++ fastboot_stage(buf, size); ++ free(buf); + } + FASTBOOT_REGISTER("oem ramoops console", cmd_oem_ramoops_console); + + static void cmd_oem_ramoops_dump(const char *arg, void *data, unsigned sz) + { +- unsigned long size = target_get_max_flash_size(); +- void *scratch = target_get_scratch_address(); +- struct ramoops_region region; +- char response[MAX_RSP_SIZE]; +- struct pram_buf *record; +- struct kmsg_hdr *header; +- uint8_t *record_base; +- int ret; +- +- get_ramoops_region(®ion); +- +- record_base = region.base; +- record = (struct pram_buf*)record_base; +- header = (struct kmsg_hdr*)record->data; +- +- /* +- * FIXME: this is pretty much useless right now. +- * 1) This only checks the first record, not all of them. +- * 2) This can't really work without ECC... +- */ +- +- memset(scratch, 0, record->size); ++ unsigned long size = target_get_max_flash_size(); ++ void *scratch = target_get_scratch_address(); ++ struct ramoops_region region; ++ char response[MAX_RSP_SIZE]; ++ struct pram_buf *record; ++ struct kmsg_hdr *header; ++ uint8_t *record_base; ++ size_t data_size; ++ int ret; ++ ++ get_ramoops_region(®ion); ++ ++ record_base = region.base; ++ record = (struct pram_buf*)record_base; ++ data_size = region.record_size - sizeof(*record); ++ ++ if(record->sig != PERSISTENT_RAM_SIG || ++ record->size <= sizeof(struct kmsg_hdr) || ++ record->size > data_size) { ++ fastboot_fail("No valid pstore dump"); ++ return; ++ } ++ ++ header = (struct kmsg_hdr*)record->data; ++ ++ /* ++ * FIXME: this is pretty much useless right now. ++ * 1) This only checks the first record, not all of them. ++ * 2) This can't really work without ECC... ++ */ ++ ++ memset(scratch, 0, record->size); + + if (header->magic != RAMOOPS_KERNMSG_HDR) + fastboot_fail("Dump corrupted."); +diff --git a/platform/msm_shared/clock_lib2.c b/platform/msm_shared/clock_lib2.c +index 50042f2..2e76d17 100644 +--- a/platform/msm_shared/clock_lib2.c ++++ b/platform/msm_shared/clock_lib2.c +@@ -34,6 +34,9 @@ + #include + #include + ++/* Bounded register polls: a stuck clock must never wedge the bootloader. */ ++#define CLK_POLL_TIMEOUT 0x40000 ++ + /*=============== CXO clock ops =============*/ + int cxo_clk_enable(struct clk *clk) + { +@@ -89,6 +92,7 @@ int clock_lib2_branch_clk_enable(struct clk *clk) + void clock_lib2_branch_clk_disable(struct clk *clk) + { + uint32_t cbcr_val; ++ unsigned int retry = CLK_POLL_TIMEOUT; + struct branch_clk *bclk = to_branch_clk(clk); + + cbcr_val = readl(bclk->cbcr_reg); +@@ -97,7 +101,7 @@ void clock_lib2_branch_clk_disable(struct clk *clk) + + if (!bclk->no_halt_check_on_disable) + /* wait until status shows it is disabled */ +- while(!(readl(bclk->cbcr_reg) & CBCR_BRANCH_OFF_BIT)); ++ while(!(readl(bclk->cbcr_reg) & CBCR_BRANCH_OFF_BIT) && --retry); + } + + /* Branch clock set rate */ +@@ -171,7 +175,8 @@ static void clock_lib2_rcg_update_config(struct rcg_clk *rclk) + writel(cmd, rclk->cmd_reg); + + /* Wait for frequency to be updated. */ +- while(readl(rclk->cmd_reg) & CMD_UPDATE_MASK); ++ unsigned int retry = CLK_POLL_TIMEOUT; ++ while((readl(rclk->cmd_reg) & CMD_UPDATE_MASK) && --retry); + } + + /* root set rate for clocks with half integer and MND divider */ +@@ -219,6 +224,7 @@ int clock_lib2_vote_clk_enable(struct clk *c) + { + uint32_t vote_regval; + uint32_t val; ++ unsigned int retry = CLK_POLL_TIMEOUT; + struct vote_clk *vclk = to_local_vote_clk(c); + + vote_regval = readl(vclk->vote_reg); +@@ -227,9 +233,8 @@ int clock_lib2_vote_clk_enable(struct clk *c) + do { + val = readl(vclk->cbcr_reg); + val &= BRANCH_CHECK_MASK; +- } +- /* wait until status shows it is enabled */ +- while((val != BRANCH_ON_VAL) && (val != BRANCH_NOC_FSM_ON_VAL)); ++ } while ((val != BRANCH_ON_VAL) && ++ (val != BRANCH_NOC_FSM_ON_VAL) && --retry); + + return 0; + } +diff --git a/platform/msm_shared/include/mdss_spi.h b/platform/msm_shared/include/mdss_spi.h +index 87f062b..5c39c7b 100644 +--- a/platform/msm_shared/include/mdss_spi.h ++++ b/platform/msm_shared/include/mdss_spi.h +@@ -31,6 +31,7 @@ + + #ifdef DISPLAY_TYPE_SPI_SUPPORT + int spi_check_panel_id(struct msm_panel_info *pinfo); ++int mdss_spi_panel_init_commands(const unsigned char *cmds, unsigned int len); + #else + static inline int spi_check_panel_id(struct msm_panel_info *pinfo) + { +diff --git a/platform/msm_shared/mdss_spi.c b/platform/msm_shared/mdss_spi.c +index 4c5fd98..649fa77 100644 +--- a/platform/msm_shared/mdss_spi.c ++++ b/platform/msm_shared/mdss_spi.c +@@ -27,7 +27,9 @@ + * + */ + ++#include + #include ++#include + #include + #include + #include +@@ -201,6 +203,40 @@ int mdss_spi_panel_init(struct msm_panel_info *pinfo) + return SUCCESS; + } + ++/** ++ * mdss_spi_panel_init_commands() - Replay a downstream SPI panel init stream. ++ */ ++static int panel_init_write_cmd(const unsigned char *cmd) ++{ ++ return mdss_spi_write_cmd(cmd); ++} ++ ++static int panel_init_write_data(const unsigned char *data, unsigned int len) ++{ ++ return mdss_spi_write_data(data, len); ++} ++ ++static void panel_init_delay(unsigned int ms) ++{ ++ mdelay(ms); ++} ++ ++int mdss_spi_panel_init_commands(const unsigned char *cmds, unsigned int len) ++{ ++ static const struct lk2nd_spi_panel_init_ops ops = { ++ .write_cmd = panel_init_write_cmd, ++ .write_data = panel_init_write_data, ++ .delay = panel_init_delay, ++ }; ++ ++ if(!dev) { ++ dprintf(CRITICAL, "SPI has not been initialized\n"); ++ return -ENODEV; ++ } ++ ++ return lk2nd_spi_panel_init_run(cmds, len, &ops); ++} ++ + int mdss_spi_on(struct msm_panel_info *pinfo, struct fbcon_config *fb) + { + int buf_size = 0; +diff --git a/platform/msm_shared/reboot.c b/platform/msm_shared/reboot.c +index 171eef8..1c939a7 100644 +--- a/platform/msm_shared/reboot.c ++++ b/platform/msm_shared/reboot.c +@@ -83,16 +83,21 @@ unsigned check_reboot_mode(void) + + unsigned check_hard_reboot_mode(void) + { +- uint8_t hard_restart_reason = 0; +- +- /* Read reboot reason and scrub it +- * Bit-2 to bit-7 of SOFT_RB_SPARE for hard reset reason +- */ +- hard_restart_reason = REG_READ(PON_SOFT_RB_SPARE); +- REG_WRITE(PON_SOFT_RB_SPARE, hard_restart_reason & 0x03); +- +- /* Extract the bits 2 to 7 and return */ +- return (hard_restart_reason & 0xFC) >> 2; ++ uint8_t hard_restart_reason = 0; ++ unsigned int high_bits; ++ unsigned int low_bits; ++ ++ /* ++ * The stock beatles boot chain scrubs PON_SOFT_RB_SPARE[7:2] and ++ * passes bits [1:0] through to the chain-loaded lk2nd image. Prefer ++ * those low bits but still accept the upstream high-bit cookie from ++ * "fastboot reboot-bootloader". ++ */ ++ hard_restart_reason = REG_READ(PON_SOFT_RB_SPARE); ++ low_bits = hard_restart_reason & 0x03; ++ high_bits = (hard_restart_reason & 0xFC) >> 2; ++ REG_WRITE(PON_SOFT_RB_SPARE, low_bits); ++ return low_bits ? low_bits : high_bits; + } + + /* Return true if it is triggered by alarm. */ +@@ -126,9 +131,14 @@ void reboot_device(unsigned reboot_reason) + + if (reboot_reason != NORMAL_DLOAD && reboot_reason != EMERGENCY_DLOAD) { + #if USE_PON_REBOOT_REG +- value = REG_READ(PON_SOFT_RB_SPARE); +- value |= (reboot_reason << 2); +- REG_WRITE(PON_SOFT_RB_SPARE, value); ++ value = REG_READ(PON_SOFT_RB_SPARE); ++ if(reboot_reason <= 0x03) { ++ dprintf(INFO, "beatles low-bit reboot cookie: 0x%02x\n", reboot_reason); ++ value = (uint8_t)reboot_reason; ++ } else { ++ value |= (reboot_reason << 2); ++ } ++ REG_WRITE(PON_SOFT_RB_SPARE, value); + #else + writel(reboot_reason, RESTART_REASON_ADDR); + #endif +diff --git a/platform/msm_shared/spi_qup.c b/platform/msm_shared/spi_qup.c +index d7bab01..eb958f0 100644 +--- a/platform/msm_shared/spi_qup.c ++++ b/platform/msm_shared/spi_qup.c +@@ -46,6 +46,9 @@ + #include + #include + ++/* Bounded wait: a QUP with no clock must never wedge the bootloader. */ ++#define QUP_FIFO_TIMEOUT 0x40000 ++ + //#define DEBUGLEVEL 3 + + static unsigned int spi_get_qup_hw_ver(struct qup_spi_dev *dev) +@@ -273,13 +276,13 @@ static void spi_qup_fifo_write(struct qup_spi_dev *dev, struct spi_transfer *xfe + while (dev->tx_bytes < xfer->len) { + + state = readl_relaxed(dev->qup_base + QUP_OPERATIONAL); +- if (state & QUP_OP_OUT_FIFO_FULL) +- { +- dprintf(SPEW, "%s: oper QUP_OP_OUT_FIFO_FULL: 0x%x" +- "dev->tx_bytes:0x%x, xfer->len:0x%x\n", +- __func__, state, dev->tx_bytes, xfer->len); +- break; +- } ++ if(state & QUP_OP_OUT_FIFO_FULL) ++ { ++ /* Upstream's per-word SPEW log saturates the 32 KiB log and makes a ++ * full frame take about 40 s on DEBUG=2 builds. The bounded timeout ++ * in _spi_qup_transfer() is the only diagnostic needed here. */ ++ break; ++ } + + word = 0; + for (idx = 0; idx < dev->bytes_per_word; idx++, dev->tx_bytes++) { +@@ -344,6 +347,7 @@ static int _spi_qup_transfer(struct qup_spi_dev *dev, struct spi_transfer *xfer) + { + int ret = -EIO; + int retries = 0xFF; ++ unsigned int fifo_retries; + unsigned val; + unsigned int register_cnt; + unsigned int register_cnt_cur; +@@ -371,7 +375,13 @@ static int _spi_qup_transfer(struct qup_spi_dev *dev, struct spi_transfer *xfer) + + while((readl(register_cnt) != readl(register_cnt_cur)) && retries--); + if (xfer->tx_buf) { ++ fifo_retries = QUP_FIFO_TIMEOUT; + while(readl(register_cnt_cur)) { ++ if (!--fifo_retries) { ++ dprintf(CRITICAL, "%s: QUP output FIFO timeout\n", __func__); ++ ret = -ETIMEDOUT; ++ goto exit; ++ } + val = readl(dev->qup_base + QUP_OPERATIONAL); + val &= ~QUP_OP_OUT_SERVICE_FLAG; + writel(val, dev->qup_base + QUP_OPERATIONAL); diff --git a/bootloader/lk2nd/spi-panel-init.h b/bootloader/lk2nd/spi-panel-init.h new file mode 100644 index 0000000..440f0ed --- /dev/null +++ b/bootloader/lk2nd/spi-panel-init.h @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BSD-3-Clause +#ifndef LK2ND_SPI_PANEL_INIT_H +#define LK2ND_SPI_PANEL_INIT_H + +/* + * Walk a downstream qcom,mdss-spi-on-command byte stream. + * + * Every command is [wait_ms, dlen, payload[dlen]]. The first payload byte is + * the command (DC low), the rest are parameters (DC high), and wait_ms is + * applied after the command. This matches the KaiOS 3.10 mdss_spi_panel_on() + * implementation (struct spi_ctrl_hdr { char wait; char dlen; }). + * + * Returns 0 on success, a negative value on a malformed stream or a write + * error. The callbacks make this usable by both the target SPI driver and a + * host unit test. + */ +struct lk2nd_spi_panel_init_ops { + int (*write_cmd)(const unsigned char *cmd); + int (*write_data)(const unsigned char *data, unsigned int len); + void (*delay)(unsigned int ms); +}; + +static inline int lk2nd_spi_panel_init_run(const unsigned char *cmds, + unsigned int len, const struct lk2nd_spi_panel_init_ops *ops) +{ + unsigned int off = 0, size; + unsigned char wait; + int ret; + + while(off + 2 <= len) { + wait = cmds[off++]; + size = cmds[off++]; + if(!size || off + size > len) + return -1; + + ret = ops->write_cmd(cmds + off); + if(ret) + return ret; + if(size > 1) { + ret = ops->write_data(cmds + off + 1, size - 1); + if(ret) + return ret; + } + + off += size; + if(wait) + ops->delay(wait); + } + + return off == len ? 0 : -1; +} + +#endif /* LK2ND_SPI_PANEL_INIT_H */ diff --git a/bootloader/lk2nd/test_spi_panel_init.c b/bootloader/lk2nd/test_spi_panel_init.c new file mode 100644 index 0000000..ffeda6d --- /dev/null +++ b/bootloader/lk2nd/test_spi_panel_init.c @@ -0,0 +1,117 @@ +/* Host unit test for the lk2nd SPI panel init byte-stream walker. */ +#include +#include + +#include "spi-panel-init.h" +#include "panel_streams.h" + +static unsigned char cmds[64]; +static unsigned char data[64][16]; +static unsigned int data_len[64]; +static unsigned int cmd_count, delay_total, delay_count; +static int fail_write; + +static int rec_cmd(const unsigned char *cmd) +{ + if(fail_write) + return -5; + if(cmd_count < 64) + cmds[cmd_count] = cmd[0]; + cmd_count++; + return 0; +} + +static int rec_data(const unsigned char *buf, unsigned int len) +{ + if(fail_write) + return -5; + if(cmd_count > 0 && cmd_count <= 64 && len <= 16) { + memcpy(data[cmd_count - 1], buf, len); + data_len[cmd_count - 1] = len; + } + return 0; +} + +static void rec_delay(unsigned int ms) +{ + delay_total += ms; + delay_count++; +} + +static const struct lk2nd_spi_panel_init_ops ops = { + .write_cmd = rec_cmd, + .write_data = rec_data, + .delay = rec_delay, +}; + +static void reset(void) +{ + cmd_count = delay_total = delay_count = 0; + fail_write = 0; + memset(cmds, 0, sizeof(cmds)); + memset(data_len, 0, sizeof(data_len)); +} + +#define CHECK(cond, msg) do { \ + if(!(cond)) { \ + printf("[fail] %s (line %d)\n", (msg), __LINE__); \ + return 1; \ + } \ +} while(0) + +static int has_cmd(const unsigned char *cmd, unsigned int len) +{ + unsigned int i; + for(i = 0; i < cmd_count; i++) { + if(cmds[i] != cmd[0]) + continue; + if(len == 1) + return 1; + if(data_len[i] == len - 1 && memcmp(data[i], cmd + 1, len - 1) == 0) + return 1; + } + return 0; +} + +int main(void) +{ + static const unsigned char rgb565[] = {0x3a, 0x05}; + static const unsigned char window_x[] = {0x2a, 0x00, 0x00, 0x00, 0xef}; + static const unsigned char window_y[] = {0x2b, 0x00, 0x00, 0x01, 0x3f}; + static const unsigned char zero_dlen[] = {0x00, 0x00}; + static const unsigned char trailing[] = {0x00, 0x01, 0x29, 0x00}; + static const unsigned char truncated[] = {0x00, 0x05, 0x2a, 0x00}; + + reset(); + CHECK(lk2nd_spi_panel_init_run(stream_v2, sizeof(stream_v2), &ops) == 0, + "v2 stream rejected"); + CHECK(cmd_count == 10, "v2 stream must have 10 commands"); + CHECK(delay_total == 120 && delay_count == 1, + "v2 stream must wait 120 ms once after sleep-out"); + CHECK(cmds[0] == 0xfe && cmds[1] == 0xef, + "v2 stream must start with the GC9305 page select"); + CHECK(has_cmd(rgb565, sizeof(rgb565)), "missing RGB565 COLMOD"); + CHECK(has_cmd(window_x, sizeof(window_x)), "missing 240 column window"); + CHECK(has_cmd(window_y, sizeof(window_y)), "missing 320 row window"); + CHECK(has_cmd((const unsigned char *)"\x11", 1), "missing sleep-out"); + CHECK(has_cmd((const unsigned char *)"\x29", 1), "missing display-on"); + CHECK(cmds[cmd_count - 1] == 0x2c, "stream must end with RAMWR (0x2c)"); + + reset(); + CHECK(lk2nd_spi_panel_init_run(zero_dlen, sizeof(zero_dlen), &ops) < 0, + "zero dlen accepted"); + reset(); + CHECK(lk2nd_spi_panel_init_run(trailing, sizeof(trailing), &ops) < 0, + "trailing garbage accepted"); + reset(); + CHECK(lk2nd_spi_panel_init_run(truncated, sizeof(truncated), &ops) < 0, + "truncated payload accepted"); + reset(); + fail_write = 1; + CHECK(lk2nd_spi_panel_init_run(stream_v2, sizeof(stream_v2), &ops) == -5, + "write error not propagated"); + + printf("[ok] SPI panel init walker: GC9305 v2 stream, framing, RGB565, " + "240x320 window, delays and error handling\n"); + return 0; +} diff --git a/devices/nokia-argon/kernel-cmdline.conf b/devices/nokia-argon/kernel-cmdline.conf index 2235027..4344c09 100644 --- a/devices/nokia-argon/kernel-cmdline.conf +++ b/devices/nokia-argon/kernel-cmdline.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/devices/nokia-beatles/cover-panel.dtsi b/devices/nokia-beatles/cover-panel.dtsi new file mode 100644 index 0000000..7975983 --- /dev/null +++ b/devices/nokia-beatles/cover-panel.dtsi @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Nokia 2720 Flip (nokia-beatles) external 240x240 GC9305 panel. +// +// Both the internal 240x320 panel and the external cover panel hang off the +// same BLSP1 QUP5 SPI lines; gpio13 selects which one the bus reaches. The +// spi-mux driver selects the mux state from the child chip-select number, +// so display@0 keeps the internal panel on state 0 and display@1 selects the +// external panel on state 1. panel-mipi-dbi-spi creates a second DRM device +// and DRM fbdev emulation exposes it as /dev/fb1 for bananarchy-cover-idle. +// +// The external child is named display@1, not cover@1: dtc keeps SPI children +// in lexical node-name order, so display@0 is registered before display@1. +// That keeps the 240x320 internal panel on /dev/fb0 for Xorg's fbdev config +// while the external panel gets /dev/fb1 for the idle cover renderer. +// The external panel has no dc-gpios property: mipi_dbi_spi_init() then uses +// MIPI DBI Type C Option 1 (9-bit SPI with the D/C bit as the ninth bit), so +// it does not fight panel-mipi-dbi-spi for the internal panel's gpio110/DC. +// Requires CONFIG_MULTIPLEXER, CONFIG_MUX_GPIO and CONFIG_SPI_MUX (all =m in +// patches/kernel/config-bananarchy-msm8909.armv7) plus +// /lib/firmware/nokia,beatles-gc9305-ext-panel.bin. +// +// This overlay is compile-checked but NOT applied to the shipping DTB. +// Live testing broke the main panel/keypad path, so the shipping DTS keeps +// the single internal panel and spidev@1 fallback until gpio13/reset/DC +// routing is validated on hardware. + +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target-path = "/"; + __overlay__ { + spi_panel_mux: spi-panel-mux { + compatible = "gpio-mux"; + #mux-control-cells = <0>; + mux-gpios = <0x27 13 0>; + idle-state = <0>; + }; + }; + }; + + fragment@1 { + target-path = "/soc@0/spi@78b9000"; + __overlay__ { + spi-mux@0 { + compatible = "spi-mux"; + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <50000000>; + mux-controls = <&spi_panel_mux>; + + display@0 { + compatible = "nokia,beatles-gc9305-panel", "panel-mipi-dbi-spi"; + reg = <0>; + spi-max-frequency = <50000000>; + reset-gpios = <0x27 25 0>; + dc-gpios = <0x27 110 0>; + backlight = <0x6b>; + power-supply = <0x6c>; + io-supply = <0x6d>; + width-mm = <36>; + height-mm = <48>; + pinctrl-0 = <0x6e>; + pinctrl-names = "default"; + + panel-timing { + hactive = <240>; + vactive = <320>; + hback-porch = <0>; + vback-porch = <0>; + hfront-porch = <0>; + vfront-porch = <0>; + hsync-len = <0>; + vsync-len = <0>; + clock-frequency = <0>; + }; + }; + + display@1 { + compatible = "nokia,beatles-gc9305-ext-panel", "panel-mipi-dbi-spi"; + reg = <1>; + spi-max-frequency = <50000000>; + reset-gpios = <0x27 23 0>; + power-supply = <0x6c>; + io-supply = <0x6d>; + width-mm = <30>; + height-mm = <30>; + pinctrl-0 = <0x92>; + pinctrl-names = "default"; + write-only; + + panel-timing { + hactive = <240>; + vactive = <240>; + hback-porch = <0>; + vback-porch = <0>; + hfront-porch = <0>; + vfront-porch = <0>; + hsync-len = <0>; + vsync-len = <0>; + clock-frequency = <0>; + }; + }; + }; + }; + }; + + fragment@2 { + target-path = "/soc@0/spi@78b9000/display@0"; + __overlay__ { + status = "disabled"; + }; + }; + + fragment@3 { + target-path = "/soc@0/spi@78b9000/spidev@1"; + __overlay__ { + status = "disabled"; + }; + }; +}; diff --git a/devices/nokia-beatles/deviceinfo b/devices/nokia-beatles/deviceinfo index fdee89c..b4ab900 100644 --- a/devices/nokia-beatles/deviceinfo +++ b/devices/nokia-beatles/deviceinfo @@ -27,8 +27,12 @@ deviceinfo_flash_pagesize="2048" deviceinfo_header_version="0" deviceinfo_flash_offset_base="0x80000000" deviceinfo_flash_offset_kernel="0x00008000" -deviceinfo_flash_offset_ramdisk="0x02700000" +# Stock 2720 Flip aboot load addresses (archived pmOS device-nokia-beatles +# deviceinfo), not the 8110 4G addresses. These only affect boot.img, used by +# the rooted-KaiOS "dd boot.img to recovery" fallback; lk2nd/extlinux EDL +# flashing loads vmlinuz + initramfs directly. +deviceinfo_flash_offset_ramdisk="0x01000000" deviceinfo_flash_offset_second="0x00f00000" -deviceinfo_flash_offset_tags="0x02500000" +deviceinfo_flash_offset_tags="0x00000100" deviceinfo_flash_sparse="true" deviceinfo_partition_type="msdos" diff --git a/devices/nokia-beatles/kernel-cmdline.conf b/devices/nokia-beatles/kernel-cmdline.conf index 2235027..4344c09 100644 --- a/devices/nokia-beatles/kernel-cmdline.conf +++ b/devices/nokia-beatles/kernel-cmdline.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin b/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin new file mode 100644 index 0000000..6c9eed5 Binary files /dev/null and b/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin differ diff --git a/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.txt b/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.txt new file mode 100644 index 0000000..399d6fc --- /dev/null +++ b/devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.txt @@ -0,0 +1,41 @@ +# Nokia 2720 Flip (nokia-beatles) 1.3-inch 240x240 external GC9305 panel. +# +# Derived from the KaiOS 3.10 downstream DTS in the archived postmarketOS +# linux-nokia-beatles package (0004-dts-adaptations.patch): +# spi_gc9305_v2_qvga_ext_cmd, qcom,mdss-spi-on-command: +# fe, ef, 3a 05, 35 00, 2a 00 00 00 ef, 2b 00 00 00 ef, 2c, +# delay 120, 11, 29, 2c +# qcom,mdss-spi-panel-width = 240, height = 240, bpp = 16. +# +# The register/gamma block below is the one already proven on this device's +# internal GC9305 panel (nokia,beatles-gc9305-panel.txt); the two column/page +# windows are set to 0..239 for the square cover panel. The blob is consumed +# by panel-mipi-dbi-spi (kernel) or by bananarchy-coverd's spidev backend. +# +# This init sequence is derived from vendor sources but has NOT yet been +# verified on 2720 Flip hardware; see NOKIA-2720-FLIP.md. + +command 0xfe +command 0xef +command 0x36 0x00 # MADCTL +command 0x3a 0x55 # 65K 16-bit RGB565 +command 0x35 0x00 # TE v-blanking +command 0xb2 0x0c 0x0c 0x00 0x33 0x33 # porch setting +command 0xb7 0x75 # gate control VGH/VGL +command 0xbb 0x34 # Vcoms +command 0xc0 0x2c # LCM control +command 0xc2 0x01 # VDV/VRH enable +command 0xc3 0x0d # VRH set +command 0xc4 0x20 # VDV set +command 0xc6 0xef # frame rate +command 0x44 0x00 0x00 # tearing scan line +command 0xd0 0xa4 0xa1 # power control 1 +command 0xe0 0xd0 0x02 0x09 0x0d 0x0e 0x19 0x30 0x51 0x43 0x09 0x14 0x13 0x18 0x21 +command 0xe1 0xd0 0x02 0x09 0x0d 0x0d 0x18 0x32 0x46 0x42 0x09 0x13 0x13 0x17 0x21 +command 0x2a 0x00 0x00 0x00 0xef # column address 0..239 +command 0x2b 0x00 0x00 0x00 0xef # page address 0..239 +command 0x2c # memory write +command 0x11 # sleep out +delay 120 +command 0x29 # display on +command 0x2c diff --git a/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb index 2de7fda..8705f67 100644 Binary files a/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb and b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb differ diff --git a/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts index 3aed7ca..d607ef4 100644 --- a/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts +++ b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts @@ -7,6 +7,9 @@ model = "Nokia 2720 Flip"; compatible = "nokia,beatles", "nokia,argon", "qcom,msm8905", "qcom,msm8909"; chassis-type = "handset"; + qcom,msm-id = <0x14b 0x00>; + qcom,board-id = <0x1000b 0x100>; + qcom,pmic-id = <0x1000d 0x00 0x00 0x00>; aliases { mmc0 = "/soc@0/sdhci@7824000"; @@ -129,9 +132,7 @@ cpu-opp-table { compatible = "operating-points-v2-kryo-cpu", "operating-points-v2"; - /* Real DVFS latency: without this cpufreq-dt reports CPUFREQ_ETERNAL - * (UINT_MAX) and schedutil derives a ~6.44 s rate limit. */ - clock-latency-ns = <100000>; + clock-latency-ns = <0x186a0>; nvmem-cells = <0x0f>; opp-shared; phandle = <0x05>; @@ -197,7 +198,7 @@ memory@80000000 { device_type = "memory"; - reg = <0x80000000 0x00>; + reg = <0x80000000 0x20000000>; }; pmu { @@ -1016,7 +1017,7 @@ }; matrix-keypad-col-default-state { - pins = "gpio52", "gpio56", "gpio7", "gpio99", "gpio6"; + pins = "gpio52", "gpio56", "gpio7", "gpio99", "gpio6", "gpio1"; function = "gpio"; drive-strength = <0x02>; bias-disable; @@ -1030,6 +1031,14 @@ bias-pull-down; phandle = <0x6e>; }; + + cover-panel-gpios-default-state { + pins = "gpio21", "gpio23", "gpio13"; + function = "gpio"; + drive-strength = <0x02>; + bias-pull-down; + phandle = <0x92>; + }; }; clock-controller@1800000 { @@ -1056,57 +1065,62 @@ phandle = <0x15>; }; - gpu: gpu@1c00000 { + gpu@1c00000 { compatible = "qcom,adreno-304.0", "qcom,adreno"; - reg = <0x01c00000 0x20000>; + reg = <0x1c00000 0x20000>; reg-names = "kgsl_3d0_reg_memory"; - interrupts = <0x00 33 0x04>; + interrupts = <0x00 0x21 0x04>; interrupt-names = "kgsl_3d0_irq"; clock-names = "core", "iface", "mem_iface", "alt_mem_iface", "gtcu_iface", "gfx3d"; - clocks = <0x14 124>, <0x14 123>, <0x14 72>, <0x14 73>, <0x14 66>, <0x14 35>; - power-domains = <0x14 1>; - operating-points-v2 = <&gpu_opp_table>; - iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; - #cooling-cells = <2>; + clocks = <0x14 0x7c 0x14 0x7b 0x14 0x48 0x14 0x49 0x14 0x42 0x14 0x23>; + power-domains = <0x14 0x01>; + operating-points-v2 = <0x8b>; + iommus = <0x8c 0x01 0x8c 0x02>; + #cooling-cells = <0x02>; - gpu_opp_table: opp-table { + opp-table { compatible = "operating-points-v2"; + phandle = <0x8b>; opp-409600000 { - opp-hz = /bits/ 64 <409600000>; + opp-hz = <0x00 0x186a0000>; }; + opp-307200000 { - opp-hz = /bits/ 64 <307200000>; + opp-hz = <0x00 0x124f8000>; }; + opp-200000000 { - opp-hz = /bits/ 64 <200000000>; + opp-hz = <0x00 0xbebc200>; }; + opp-19200000 { - opp-hz = /bits/ 64 <19200000>; + opp-hz = <0x00 0x124f800>; }; }; }; - gpu_iommu: iommu@1f08000 { - #address-cells = <1>; - #size-cells = <1>; - #iommu-cells = <1>; + iommu@1f08000 { + #address-cells = <0x01>; + #size-cells = <0x01>; + #iommu-cells = <0x01>; compatible = "qcom,msm8909-iommu", "qcom,msm8916-iommu", "qcom,msm-iommu-v1"; - ranges = <0 0x01f08000 0x10000>; - clocks = <0x14 69>, <0x14 65>, <0x14 64>; + ranges = <0x00 0x1f08000 0x10000>; + clocks = <0x14 0x45 0x14 0x41 0x14 0x40>; clock-names = "iface", "bus", "tbu"; - qcom,iommu-secure-id = <18>; + qcom,iommu-secure-id = <0x12>; + phandle = <0x8c>; iommu-ctx@1000 { compatible = "qcom,msm-iommu-v1-ns"; reg = <0x1000 0x1000>; - interrupts = <0x00 241 0x04>; + interrupts = <0x00 0xf1 0x04>; }; iommu-ctx@2000 { compatible = "qcom,msm-iommu-v1-ns"; reg = <0x2000 0x1000>; - interrupts = <0x00 242 0x04>; + interrupts = <0x00 0xf2 0x04>; }; }; @@ -1150,7 +1164,7 @@ debounce = <0x3d09>; bias-pull-up; status = "okay"; - linux,code = <0x6c>; + linux,code = <0x72>; }; watchdog { @@ -1863,6 +1877,13 @@ clock-frequency = "", "#("; }; }; + + spidev@1 { + compatible = "rohm,dh2228fv"; + reg = <0x01>; + spi-max-frequency = <0x2faf080>; + status = "okay"; + }; }; i2c@78ba000 { @@ -2287,30 +2308,31 @@ pinctrl-0 = <0x86 0x87>; pinctrl-names = "default"; - key-up { + key-volup { wakeup-source; gpios = <0x27 0x5a 0x01>; - linux,code = <0x67>; + linux,code = <0x73>; debounce-interval = <0x0f>; linux,can-disable; }; - key-back { + key-end { wakeup-source; gpios = <0x27 0x62 0x01>; - linux,code = <0x0e>; + linux,code = <0x74>; debounce-interval = <0x0f>; linux,can-disable; }; - switch-lid-close { + hall-lid-closed { wakeup-source; gpios = <0x27 0x5c 0x01>; linux,input-type = <0x05>; linux,code = <0x00>; }; - switch-lid-open { + hall-lid-open { + wakeup-source; gpios = <0x27 0x24 0x01>; linux,input-type = <0x05>; linux,code = <0x0a>; @@ -2325,8 +2347,8 @@ pinctrl-0 = <0x88 0x89>; pinctrl-names = "default"; row-gpios = <0x27 0x61 0x01 0x27 0x60 0x01 0x27 0x5f 0x01 0x27 0x5e 0x01>; - col-gpios = <0x27 0x34 0x01 0x27 0x38 0x01 0x27 0x07 0x01 0x27 0x63 0x01 0x27 0x06 0x01>; - linux,keymap = <0x1bd 0x10002 0x20005 0x30008 0x4020a 0x1000069 0x1010003 0x1020006 0x1030009 0x104000b 0x20002b8 0x2010004 0x2020007 0x203000a 0x204020b 0x300001c 0x301006a 0x30202b9>; + col-gpios = <0x27 0x34 0x01 0x27 0x38 0x01 0x27 0x07 0x01 0x27 0x63 0x01 0x27 0x06 0x01 0x27 0x01 0x01>; + linux,keymap = <0x1bd 0x10002 0x20005 0x30008 0x4020a 0x500d4 0x1000069 0x1010003 0x1020006 0x1030009 0x104000b 0x105000e 0x200007f 0x2010004 0x2020007 0x203000a 0x204020b 0x300001c 0x301006a 0x302009e 0x3030067 0x304006c>; }; leds { diff --git a/devices/nokia-sparkler/kernel-cmdline.conf b/devices/nokia-sparkler/kernel-cmdline.conf index 2235027..4344c09 100644 --- a/devices/nokia-sparkler/kernel-cmdline.conf +++ b/devices/nokia-sparkler/kernel-cmdline.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/devices/nokia-tough/kernel-cmdline.conf b/devices/nokia-tough/kernel-cmdline.conf index 2235027..4344c09 100644 --- a/devices/nokia-tough/kernel-cmdline.conf +++ b/devices/nokia-tough/kernel-cmdline.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/flash-edl.py b/flash-edl.py index e7e319f..1f1d8b1 100755 --- a/flash-edl.py +++ b/flash-edl.py @@ -3,6 +3,7 @@ import argparse import os +import re import subprocess import sys import tempfile @@ -39,6 +40,84 @@ DEVICE_LABELS = { "nokia-leo": "Nokia 6300 4G (nokia-leo)", } +# Firehose programmers are signed for one root of trust, so the PBL rejects a +# mismatched one in Sahara. Never silently fall back to the 8110 programmer +# for a different target; --loader is the explicit escape hatch. +# Identities below were read from the attestation certificates embedded in +# each .mbn (see --list-loaders). 8k.mbn is signed Nokia_leo but covers both +# MSM8909 phones; 2720v.mbn is signed Nokia_bts_us, the 2720 Flip US variant. +DEVICE_LOADERS = { + "nokia-argon": "8110.mbn", # legacy generic MSM8905 programmer + "nokia-beatles": "2720.mbn", # Nokia_beatles + "nokia-tough": "800t.mbn", # Nokia_coconut + "nokia-sparkler": "8k.mbn", # Nokia_leo root, shared with 6300 4G + "nokia-leo": "8k.mbn", # Nokia_leo +} + +DEVICE_LOADER_VARIANTS = { + "nokia-beatles": {"us": "2720v.mbn"}, # Nokia_bts_us, 2720 Flip US variant +} + +DEVICE_LOADER_IDENTITIES = { + "nokia-argon": "", + "nokia-beatles": "Nokia_beatles", + "nokia-tough": "Nokia_coconut", + "nokia-sparkler": "Nokia_leo", + "nokia-leo": "Nokia_leo", +} + +VARIANT_LOADER_IDENTITIES = { + ("nokia-beatles", "us"): "Nokia_bts_us", +} + +# A failed boot can leave the PBL in Sahara on 900e (QHSUSB_BULK) instead of +# the usual 9008 (QDLoader); 9006 is the diag/DLOAD variant. Probe all three +# so a power-cycle is not needed just because the PID changed. +EDL_PIDS = (0x9008, 0x900E, 0x9006) + +# images/boot-lk2nd-nokia-beatles.img is built from upstream lk2nd source plus +# bootloader/lk2nd/nokia-beatles.patch (see bootloader/lk2nd/README.md). It has +# a dedicated QCDT DTB for the exact stock 2720 IDs (0x14b/0x1000b/0x100), a +# /lk2nd/nokia-beatles device node with the three GC9305 panel init streams, +# and cmdline lk2nd.compatible=nokia,beatles. aboot hands off to lk2nd, lk2nd +# brings up the 240x320 RGB565 main panel and boots Bananarchy from userdata +# via extlinux.conf. This is the default path on nokia-beatles. +BOOT_IMAGE_DEVICES = ("nokia-beatles",) +# Stock 2720 aboot has secure boot enabled and devinfo is locked. Writing a +# custom boot.img (lk2nd or mainline) is rejected unless devinfo.is_unlocked=1. +UNLOCK_DEFAULT_DEVICES = ("nokia-beatles",) +DEVINFO_MAGIC = b"ANDROID-BOOT!" +DEVINFO_UNLOCKED_OFFSET = 13 +DEVINFO_TAMPERED_OFFSET = 14 +# aboot reads is_allow_unlock from the last byte of the "config" partition. +# VB1 enables USE_RPMB_FOR_DEVINFO, so only "fastboot oem unlock-go" can write +# the authoritative RPMB devinfo; eMMC devinfo alone is not enough. +OEM_UNLOCK_PARTITIONS = ("config", "frp") +OEM_UNLOCK_FLAG_OFFSET = -1 +# Rebuild the source port with scripts/build-lk2nd-beatles.sh after changing +# bootloader/lk2nd/nokia-beatles.patch; never binary-patch the prebuilt +# bootloader/lk2nd-msm8909.img. +BEATLES_LK2ND_IMAGE = "images/boot-lk2nd-nokia-beatles-display.img" +BOOT_METHOD_PARTITIONS = { + "lk2nd": "boot", # lk2nd image into boot + "boot": "boot", # raw Bananarchy boot.img into boot (normal power-on) + "recovery": "recovery", # boot.img into recovery (Volume Up) + "both": "boot", # boot.img into boot and recovery (covers either path) +} +BOOT_METHOD_TARGETS = { + "lk2nd": ("boot",), + "boot": ("boot",), + "recovery": ("recovery",), + "both": ("boot", "recovery"), +} +DIAG_PARTITIONS = ( + "devinfo", "config", "misc", "frp", "aboot", "abootbak", + "sbl1", "sbl1bak", "tz", "tzbak", "rpm", "rpmbak", + "hyp", "hypbak", "sec", "keystore", "cmnlib", "cmnlib64", + "devcfg", "keymaster", "prov", "limits", "toolsfv", "logfs", + "dip", "mdtp", "cdt", "ddr", "sp", "uefivarstore", +) + def _fb_read_status(ep_in, timeout_ms=5000): while True: @@ -174,11 +253,13 @@ def try_kick_into_edl(): pass -def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0): - cdc = usb_class(vid=vid, pid=pid) +def wait_for_edl_usb(vid, pids, device_label, timeout_sec=0): + if isinstance(pids, int): + pids = (pids,) + pids = tuple(pids) print( - f"[*] Waiting for {device_label} in EDL mode " - f"(USB {vid:04x}:{pid:04x} Qualcomm QDLoader 9008)..." + "[*] Waiting for %s in EDL mode (USB %04x:%s Qualcomm Sahara/Firehose)..." + % (device_label, vid, "/".join("%04x" % pid for pid in pids)) ) print(" To enter EDL mode on the phone, use one of:") print(" 1) From lk2nd Fastboot menu, select 'EDL' (or connect in Fastboot mode)") @@ -190,24 +271,26 @@ def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0): start_ts = time.time() dots = 0 - while not cdc.connected: - try: - cdc.connected = cdc.connect() - except usb.core.USBError as exc: - if getattr(exc, "errno", None) == 13: - print( - "\n[!] Error: USB permission denied when opening 05c6:9008. " - "Please run via sudo (e.g. sudo ./flash-edl.sh)." - ) - sys.exit(1) - time.sleep(0.05) - continue - - if cdc.connected: - if dots > 0: - sys.stdout.write("\n") - print("[+] USB EDL device connected.") - return cdc + while True: + for pid in pids: + if usb.core.find(idVendor=vid, idProduct=pid) is None: + continue + cdc = usb_class(vid=vid, pid=pid) + try: + cdc.connected = cdc.connect() + except usb.core.USBError as exc: + if getattr(exc, "errno", None) == 13: + print( + "\n[!] Error: USB permission denied when opening 05c6:%04x. " + "Please run via sudo (e.g. sudo ./flash-edl.sh)." % pid + ) + sys.exit(1) + continue + if cdc.connected: + if dots > 0: + sys.stdout.write("\n") + print("[+] USB EDL device connected (05c6:%04x)." % pid) + return cdc if timeout_sec > 0 and (time.time() - start_ts) >= timeout_sec: if dots > 0: @@ -236,6 +319,33 @@ def find_partition(partentries, name): return None +def verify_partition(fh, lun, part, source_path): + """Read back a written partition and compare its leading bytes. + + Returns (ok, detail). A mismatch means the Sahara/Firehose session did not + actually commit the image, which is the usual cause of a phone that keeps + booting the stock image. + """ + size = os.path.getsize(source_path) + tmp_path = "" + try: + with tempfile.NamedTemporaryFile(prefix="verify-partition-", + delete=False) as tf: + tmp_path = tf.name + res = fh.cmd_read(lun, part.sector, part.sectors, tmp_path, Display=False) + if res == "" or not os.path.exists(tmp_path): + return False, "read-back failed" + with open(source_path, "rb") as src, open(tmp_path, "rb") as got: + if src.read(size) != got.read(size): + return False, "read-back differs from the source image" + return True, "read-back matches" + except Exception as exc: # noqa: BLE001 - report the USB/Firehose error + return False, "read-back error: %s" % exc + finally: + if tmp_path and os.path.exists(tmp_path): + os.unlink(tmp_path) + + def write_partition(fh, lun, part, filepath): size = os.stat(filepath).st_size sector_size = fh.cfg.SECTOR_SIZE_IN_BYTES @@ -277,14 +387,170 @@ def dump_partition(fh, lun, part, filepath): return True -def resolve_default_loader(): +def dump_diagnostics(fh, lun, partentries, backup_dir): + """Copy small bootloader/config partitions for offline secure-boot analysis.""" + os.makedirs(backup_dir, exist_ok=True) + max_sectors = 4096 + for pname in DIAG_PARTITIONS: + part = find_partition(partentries, pname) + if not part: + continue + sectors = min(part.sectors, max_sectors) + dest = os.path.join(backup_dir, f"diag-{pname}.img") + print(f"[*] Diagnostic read '{pname}' ({sectors} sectors) -> {dest}...") + res = fh.cmd_read(lun, part.sector, sectors, dest, Display=False) + if res == "" or not os.path.isfile(dest) or os.stat(dest).st_size == 0: + print(f"[!] Warning: diagnostic read of '{pname}' failed.") + else: + print(f"[+] Saved diagnostic: {dest}") + + +def unlock_devinfo(fh, lun, partentries, backup_dir, device): + """Set devinfo.is_unlocked=1 so aboot skips signed-boot verification.""" + part = find_partition(partentries, "devinfo") + if not part: + print("[!] Warning: 'devinfo' partition not found; cannot unlock bootloader.") + return False + os.makedirs(backup_dir, exist_ok=True) + locked_backup = os.path.join(backup_dir, f"devinfo-locked-{device}.img") + tmp_path = "" + try: + with tempfile.NamedTemporaryFile(prefix="devinfo-", delete=False) as tf: + tmp_path = tf.name + res = fh.cmd_read(lun, part.sector, part.sectors, tmp_path, Display=False) + if res == "" or not os.path.exists(tmp_path) or os.stat(tmp_path).st_size == 0: + print("[!] Error: failed to read 'devinfo' for unlocking.") + return False + data = bytearray(open(tmp_path, "rb").read()) + if bytes(data[:len(DEVINFO_MAGIC)]) != DEVINFO_MAGIC: + print("[!] Error: 'devinfo' magic mismatch; refusing to modify it.") + return False + with open(locked_backup, "wb") as handle: + handle.write(data) + print(f"[+] Saved locked devinfo backup: {locked_backup}") + data[DEVINFO_UNLOCKED_OFFSET] = 1 + data[DEVINFO_TAMPERED_OFFSET] = 0 + with open(tmp_path, "wb") as handle: + handle.write(data) + print("[*] Setting devinfo: is_unlocked=1, is_tampered=0 ...") + if not fh.cmd_write(lun, part.sector, tmp_path, Display=True): + print("[!] Error: failed to write unlocked devinfo.") + return False + print("[+] Bootloader unlock flag written to 'devinfo'.") + return True + except Exception as exc: # noqa: BLE001 - report Firehose error + print(f"[!] Error unlocking devinfo: {exc}") + return False + finally: + if tmp_path and os.path.exists(tmp_path): + os.unlink(tmp_path) + + +def enable_oem_unlock(fh, lun, partentries, backup_dir, device): + """Set the last byte of config/frp so aboot allows 'oem unlock-go'.""" + part = None + for name in OEM_UNLOCK_PARTITIONS: + part = find_partition(partentries, name) + if part: + break + if not part: + print("[!] Warning: neither 'config' nor 'frp' partition found; " + "cannot enable OEM unlock.") + return False + os.makedirs(backup_dir, exist_ok=True) + backup = os.path.join(backup_dir, f"{part.name}-locked-{device}.img") + tmp_path = "" + try: + with tempfile.NamedTemporaryFile(prefix="oem-unlock-", delete=False) as tf: + tmp_path = tf.name + res = fh.cmd_read(lun, part.sector, part.sectors, tmp_path, Display=False) + if res == "" or not os.path.exists(tmp_path) or os.stat(tmp_path).st_size == 0: + print(f"[!] Error: failed to read '{part.name}' for OEM unlock.") + return False + data = bytearray(open(tmp_path, "rb").read()) + with open(backup, "wb") as handle: + handle.write(data) + print(f"[+] Saved original {part.name} backup: {backup}") + data[OEM_UNLOCK_FLAG_OFFSET] |= 1 + with open(tmp_path, "wb") as handle: + handle.write(data) + print(f"[*] Enabling OEM unlock in '{part.name}' (last byte |= 1)...") + if not fh.cmd_write(lun, part.sector, tmp_path, Display=True): + print(f"[!] Error: failed to write '{part.name}'.") + return False + # Read back and confirm the flag persisted. + res = fh.cmd_read(lun, part.sector, part.sectors, tmp_path, Display=False) + if res == "" or not os.path.exists(tmp_path): + print(f"[!] Warning: could not read back '{part.name}'.") + elif not (open(tmp_path, "rb").read()[OEM_UNLOCK_FLAG_OFFSET] & 1): + print(f"[!] Error: OEM unlock flag did not persist in '{part.name}'.") + return False + print(f"[+] OEM unlock enabled in '{part.name}'.") + return True + except Exception as exc: # noqa: BLE001 + print(f"[!] Error enabling OEM unlock: {exc}") + return False + finally: + if tmp_path and os.path.exists(tmp_path): + os.unlink(tmp_path) + + +def loader_identity(path): + """Return the Nokia_ attestation name embedded in an .mbn.""" + try: + with open(path, "rb") as handle: + data = handle.read(1024 * 1024) + except OSError: + return "" + match = re.search(rb"Nokia_[A-Za-z0-9_]+", data) + return match.group(0).decode("ascii", "replace") if match else "" + + +def available_loaders(): + loaders_dir = os.path.join(BASE_DIR, "bootloader", "loaders") + if not os.path.isdir(loaders_dir): + return [] + return sorted( + name for name in os.listdir(loaders_dir) + if name.lower().endswith(".mbn") + and os.path.isfile(os.path.join(loaders_dir, name)) + ) + + +def list_loaders(): + loaders_dir = os.path.join(BASE_DIR, "bootloader", "loaders") + names = available_loaders() + print("Firehose programmers in %s:" % loaders_dir) + if not names: + print(" (none found)") + for name in names: + path = os.path.join(loaders_dir, name) + ident = loader_identity(path) or "no embedded Nokia identity" + users = [dev for dev, fn in DEVICE_LOADERS.items() if fn == name] + for dev, variants in DEVICE_LOADER_VARIANTS.items(): + for variant, fn in variants.items(): + if fn == name: + users.append("%s --variant %s" % (dev, variant)) + note = "-> " + ", ".join(users) if users else "(unused: select with --loader)" + print(" %-12s %9d bytes %-22s %s" % ( + name, os.path.getsize(path), ident, note)) + print("\nThe device default is chosen by --device / the positional target.") + print("Use --variant us for a 2720 Flip US (Nokia_bts_us) device.") + print("Use --loader PATH to select any programmer explicitly.") + return 0 + + +def resolve_default_loader(device="nokia-argon", variant=""): + name = DEVICE_LOADERS.get(device, "8110.mbn") + if variant: + name = DEVICE_LOADER_VARIANTS.get(device, {}).get(variant, name) for cand in [ - os.path.join(BASE_DIR, "bootloader", "loaders", "8110.mbn"), - os.path.join(BASE_DIR, "8110.mbn"), + os.path.join(BASE_DIR, "bootloader", "loaders", name), + os.path.join(BASE_DIR, name), ]: if os.path.isfile(cand): return cand - return os.path.join(BASE_DIR, "bootloader", "loaders", "8110.mbn") + return os.path.join(BASE_DIR, "bootloader", "loaders", name) def resolve_default_bootloader(): @@ -301,6 +567,37 @@ def resolve_default_image(device): return os.path.join(BASE_DIR, "images", f"bananarchy-{device}.img") +def resolve_wipe_system(method, no_wipe, wipe): + """Zero the stock system superblock by default for every method. + + This is the original Bananarchy behavior: the stock KaiOS system must not + be mountable when the phone is re-purposed. --no-wipe-system is the opt-out. + """ + if no_wipe: + return False + if wipe: + return True + return method in BOOT_METHOD_PARTITIONS + + +def resolve_boot_method(device, explicit=""): + if explicit: + return explicit + # lk2nd is the Android boot.img for every target. On the 2720 the + # source-built port has a dedicated QCDT DTB for the exact stock + # 0x14b/0x1000b/0x100 entry, so aboot accepts it, lk2nd initializes the + # GC9305 main panel and boots Bananarchy from userdata via extlinux. + return "lk2nd" + + +def resolve_recovery_image(device): + return os.path.join(BASE_DIR, "images", f"boot-bananarchy-{device}.img") + + +def resolve_beatles_lk2nd_image(): + return os.path.join(BASE_DIR, BEATLES_LK2ND_IMAGE) + + def parse_args(): parser = argparse.ArgumentParser( description="Automated EDL Flasher for Bananarchy Linux (MSM8909 / Sxmo)" @@ -343,8 +640,41 @@ def parse_args(): ) parser.add_argument( "--loader", - default=resolve_default_loader(), - help="Path to Firehose programmer (.mbn)", + default=None, + help="Path to Firehose programmer (.mbn); default: device-specific loader", + ) + parser.add_argument( + "--list-loaders", + action="store_true", + help="List available Firehose programmers and their device mapping, then exit", + ) + parser.add_argument( + "--method", + choices=["lk2nd", "boot", "recovery", "both"], + default="", + help="Boot method (default: lk2nd for all targets). On nokia-beatles " + "lk2nd is written to boot and recovery; both writes the mainline " + "boot.img to both slots; recovery needs Volume Up", + ) + parser.add_argument( + "--boot-image", + default="", + help="Standalone Android boot.img for recovery flashing " + "(default: images/boot-bananarchy-.img)", + ) + parser.add_argument( + "--lk2nd-image", + default="", + help="Override the nokia-beatles lk2nd boot.img written to 'boot' " + "(e.g. images/boot-lk2nd-nokia-beatles-diagnostic.img for the " + "forced-fastboot/on-screen-log diagnostic build)", + ) + parser.add_argument( + "--variant", + choices=["us"], + default="", + help="Hardware variant: 'us' selects the Nokia_bts_us programmer " + "(2720v.mbn) for the 2720 Flip US variant", ) parser.add_argument( "--backup-dir", @@ -369,7 +699,51 @@ def parse_args(): parser.add_argument( "--no-wipe-system", action="store_true", - help="Do not zero the stock system partition superblock", + help="Keep the stock system superblock intact (opt-out of the default wipe)", + ) + parser.add_argument( + "--verify", + action="store_true", + help="Read back the flashed boot/recovery partition and compare it " + "(diagnoses a flash that never committed)", + ) + parser.add_argument( + "--dump-diagnostics", + action="store_true", + help="Before flashing, read small bootloader/config partitions into " + "backup/diag-*.img (helps diagnose secure boot / aboot state)", + ) + parser.add_argument( + "--unlock-bootloader", + action="store_true", + help="Set devinfo.is_unlocked=1 (default on nokia-beatles; needed for " + "the locked stock aboot to accept an unsigned boot.img)", + ) + parser.add_argument( + "--no-unlock-bootloader", + action="store_true", + help="Leave devinfo untouched (custom boot.img will likely be rejected)", + ) + parser.add_argument( + "--enable-oem-unlock", + action="store_true", + help="Patch config/frp allow-unlock flag (default on nokia-beatles). " + "Required before 'fastboot oem unlock-go' can write RPMB devinfo", + ) + parser.add_argument( + "--no-enable-oem-unlock", + action="store_true", + help="Do not patch the config/frp allow-unlock flag", + ) + parser.add_argument( + "--only-unlock", + action="store_true", + help="Only patch eMMC devinfo and config/frp and exit without flashing", + ) + parser.add_argument( + "--wipe-system", + action="store_true", + help="Zero the stock system superblock (already the default; kept for compatibility)", ) parser.add_argument( "--no-reset", @@ -389,8 +763,8 @@ def parse_args(): ) parser.add_argument( "--pid", - default="0x9008", - help="USB Product ID (default: 0x9008)", + default="", + help="USB Product ID (default: auto-detect 05c6:9008, 900e or 9006)", ) parser.add_argument( "--lun", @@ -403,23 +777,64 @@ def parse_args(): def main(): args = parse_args() + if args.list_loaders: + return list_loaders() device = args.device_pos if args.device_pos and args.device_pos != "sxmo" else args.device device_label = DEVICE_LABELS.get(device, device) + method = resolve_boot_method(device, args.method) + boot_img = os.path.abspath(args.boot_image or resolve_recovery_image(device)) userdata_img = ( os.path.abspath(args.image) if args.image else os.path.abspath(resolve_default_image(device)) ) bootloader_img = os.path.abspath(args.bootloader) - loader_mbn = os.path.abspath(args.loader) + beatles_lk2nd_img = os.path.abspath(args.lk2nd_image or resolve_beatles_lk2nd_image()) + mainline_img = boot_img + loader_mbn = os.path.abspath( + args.loader or resolve_default_loader(device, args.variant)) backup_dir = os.path.abspath(args.backup_dir) + unlock_bootloader = ( + not args.no_unlock_bootloader + and (args.unlock_bootloader or device in UNLOCK_DEFAULT_DEVICES) + ) + oem_unlock_enabled = ( + not args.no_enable_oem_unlock + and (args.enable_oem_unlock or device in UNLOCK_DEFAULT_DEVICES) + ) print("============================================================") print(" Bananarchy Linux (MSM8909 / Sxmo) Automated EDL Flasher") print("============================================================") print(f" Target Device : {device_label}") print(f" Target UI : Sxmo (240x320 native, Multi-Mode T9)") + print(f" Target Variant : {args.variant or 'default'}") + print(f" Boot Method : {method}") + wipe_system = resolve_wipe_system( + method, args.no_wipe_system, args.wipe_system) + print(f" Wipe System : {'yes' if wipe_system else 'no (--no-wipe-system)'}") + print(f" Verify Writes : {'yes' if args.verify else 'no (--verify to enable)'}") + print(f" Unlock Bootloader: {'yes (devinfo)' if unlock_bootloader else 'no'}") + print(f" Enable OEM Unlock: {'yes (config/frp)' if oem_unlock_enabled else 'no'}") + if args.only_unlock: + print(" Mode : prepare unlock only (no images flashed)") + if method in ("boot", "recovery", "both"): + print(f" Boot Image : {boot_img}") print(f" Firehose Loader : {loader_mbn}") + if os.path.isfile(loader_mbn) and os.path.getsize(loader_mbn) > 0: + ident = loader_identity(loader_mbn) + if ident: + print(f" Firehose ID : {ident}") + expected = VARIANT_LOADER_IDENTITIES.get( + (device, args.variant), DEVICE_LOADER_IDENTITIES.get(device, "")) + if expected and ident and ident != expected: + print( + "[!] Warning: %s is signed for %s, expected %s for %s. " + "Verify on hardware or pass --loader." % ( + os.path.basename(loader_mbn), ident, expected, device)) + if method == "lk2nd" and device == "nokia-beatles": + print(f" LK2ND (boot) : {beatles_lk2nd_img} (nokia-beatles source port)") + print(f" Boot Image (rec) : {mainline_img}") print(f" Bootloader (boot): {bootloader_img}") print(f" System (userdata): {userdata_img}") print( @@ -428,18 +843,34 @@ def main(): ) print("============================================================") - for label, path in [ + if not os.path.isfile(loader_mbn) or os.path.getsize(loader_mbn) == 0: + print("[!] Error: Firehose programmer for %s not found or empty at: %s" % ( + device, loader_mbn)) + print(" Expected %s; available: %s" % ( + os.path.basename(loader_mbn), + ", ".join(available_loaders()) or "none")) + print(" Run './flash-edl.sh --list-loaders' or pass --loader PATH.") + sys.exit(1) + + required_files = [ ("Firehose programmer", loader_mbn), - ("lk2nd bootloader image", bootloader_img), ("System userdata image", userdata_img), - ]: + ] + if method in ("boot", "recovery", "both"): + required_files.append(("Boot image", boot_img)) + else: + required_files.append(("lk2nd bootloader image", bootloader_img)) + if method == "lk2nd" and device == "nokia-beatles": + required_files.append(("nokia-beatles lk2nd image", beatles_lk2nd_img)) + required_files.append(("Recovery boot image", mainline_img)) + for label, path in required_files: if not os.path.isfile(path) or os.stat(path).st_size == 0: print(f"[!] Error: {label} not found or empty at: {path}") sys.exit(1) vid = int(args.vid, 16) - pid = int(args.pid, 16) - cdc = wait_for_edl_usb(vid, pid, device_label, timeout_sec=args.timeout) + pids = [int(args.pid, 16)] if args.pid else list(EDL_PIDS) + cdc = wait_for_edl_usb(vid, pids, device_label, timeout_sec=args.timeout) sahara = qualcomm_sahara(cdc) with open(loader_mbn, "rb") as rf: @@ -497,27 +928,97 @@ def main(): sys.exit(1) boot_part = find_partition(guid_gpt.partentries, "boot") + recovery_part = find_partition(guid_gpt.partentries, "recovery") userdata_part = find_partition(guid_gpt.partentries, "userdata") system_part = find_partition(guid_gpt.partentries, "system") - if not boot_part: - print("[!] Error: Partition 'boot' not found in device GPT.") - sys.exit(1) + target_names = BOOT_METHOD_TARGETS[method] + if method == "lk2nd" and device == "nokia-beatles": + # Match the 8110/Argon shape: lk2nd in boot, mainline boot.img in + # recovery (Volume Up fallback). Also refresh the separate 512 KiB + # lk2nd partition so "Reboot to bootloader" cannot chain-load a stale + # image without the visible menu. + target_names = ("boot", "recovery", "lk2nd") + target_parts = [] + for name in target_names: + part = find_partition(guid_gpt.partentries, name) + if not part: + if name == "lk2nd" and method == "lk2nd" and device == "nokia-beatles": + print(f"[!] Warning: optional partition '{name}' not found; skipping.") + continue + print(f"[!] Error: Partition '{name}' not found in device GPT.") + sys.exit(1) + target_parts.append((name, part)) + + def source_for(name): + if method == "lk2nd" and device == "nokia-beatles": + if name in ("boot", "lk2nd"): + return beatles_lk2nd_img + return mainline_img + if method == "lk2nd": + return bootloader_img + return boot_img + if not userdata_part: print("[!] Error: Partition 'userdata' not found in device GPT.") sys.exit(1) - print( - f"[+] Found 'boot' : sector {boot_part.sector}, " - f"{boot_part.sectors} sectors " - f"({(boot_part.sectors * fh.cfg.SECTOR_SIZE_IN_BYTES) / (1024 * 1024):.1f} MiB)" - ) + if boot_part: + print( + f"[+] Found 'boot' : sector {boot_part.sector}, " + f"{boot_part.sectors} sectors " + f"({(boot_part.sectors * fh.cfg.SECTOR_SIZE_IN_BYTES) / (1024 * 1024):.1f} MiB)" + ) print( f"[+] Found 'userdata' : sector {userdata_part.sector}, " f"{userdata_part.sectors} sectors " f"({(userdata_part.sectors * fh.cfg.SECTOR_SIZE_IN_BYTES) / (1024 * 1024):.1f} MiB)" ) + if args.dump_diagnostics: + dump_diagnostics(fh, args.lun, guid_gpt.partentries, backup_dir) + + if args.only_unlock: + ok = True + if unlock_bootloader: + print("\n[*] Unlocking eMMC devinfo for unsigned boot images...") + ok = unlock_devinfo(fh, args.lun, guid_gpt.partentries, + backup_dir, device) and ok + if oem_unlock_enabled: + print("\n[*] Enabling OEM unlock in config/frp...") + ok = enable_oem_unlock(fh, args.lun, guid_gpt.partentries, + backup_dir, device) and ok + if not ok: + print("[!] Unlock preparation failed; re-enter EDL and retry.") + sys.exit(1) + print("\n============================================================") + print(" UNLOCK PREPARATION COMPLETE") + print("============================================================") + print(" The stock aboot reads devinfo from RPMB, not eMMC. To finish:") + print(" 1. Power off, hold Volume Down, plug USB to enter fastboot.") + print(" 2. Run: fastboot oem unlock-go") + print(" (Confirm on-screen if asked; this wipes userdata.)") + print(" 3. Re-enter EDL and run the normal flash again.") + print(" It will write lk2nd to boot/recovery and userdata.") + print("============================================================") + if not args.no_reset: + fh.cmd_reset() + return + + if unlock_bootloader: + print("\n[*] Unlocking eMMC devinfo for unsigned boot images...") + if not unlock_devinfo(fh, args.lun, guid_gpt.partentries, + backup_dir, device): + print("[!] Custom boot.img will be rejected while devinfo stays locked.") + print(" Re-enter EDL and retry; do not trust this flash.") + sys.exit(1) + if oem_unlock_enabled: + print("\n[*] Enabling OEM unlock in config/frp (RPMB unlock prerequisite)...") + if not enable_oem_unlock(fh, args.lun, guid_gpt.partentries, + backup_dir, device): + print("[!] Could not enable 'oem unlock-go'. Run --only-unlock first.") + sys.exit(1) + if not args.skip_backup: os.makedirs(backup_dir, exist_ok=True) gpt_backup_path = os.path.join(backup_dir, "gpt.bin") @@ -526,7 +1027,8 @@ def main(): wf.write(gpt_raw) print(f"[+] Saved GPT backup: {gpt_backup_path}") - backup_parts = ["fsc", "fsg", "modemst1", "modemst2", "persist", "boot"] + backup_parts = ["fsc", "fsg", "modemst1", "modemst2", "persist"] + backup_parts += list(target_names) if args.backup_modem: backup_parts.append("modem") @@ -536,8 +1038,14 @@ def main(): print(f"[!] Warning: Partition '{pname}' not found in GPT; skipping backup.") continue dest_file = os.path.join(backup_dir, f"{pname}.img") + # Never reuse a stale backup of a partition we are about to overwrite: + # an older device's boot.img in ./backup must not be trusted. + is_target = pname in target_names + if is_target: + dest_file = os.path.join(backup_dir, f"{pname}-{device}.img") if ( - not args.force_backup + not is_target + and not args.force_backup and os.path.exists(dest_file) and os.stat(dest_file).st_size > 0 ): @@ -546,15 +1054,32 @@ def main(): if not dump_partition(fh, args.lun, part, dest_file): sys.exit(1) - print("\n[*] Step 1/3: Flashing lk2nd secondary bootloader to 'boot'...") - if not write_partition(fh, args.lun, boot_part, bootloader_img): - sys.exit(1) + for name, part in target_parts: + source = source_for(name) + if method == "lk2nd" and source != mainline_img and ( + source == bootloader_img or source == beatles_lk2nd_img): + print("\n[*] Step 1/3: Flashing lk2nd secondary bootloader to '%s'..." % name) + else: + print("\n[*] Step 1/3: Flashing Bananarchy boot.img to '%s'..." % name) + if not write_partition(fh, args.lun, part, source): + sys.exit(1) + + if args.verify: + for name, part in target_parts: + source = source_for(name) + ok, detail = verify_partition(fh, args.lun, part, source) + print("[%s] Read-back of '%s': %s" % ( + "+" if ok else "!", name, detail)) + if not ok: + print("[!] The image was not committed to '%s'. Re-enter EDL and " + "retry before trusting the flash." % name) + sys.exit(1) print(f"\n[*] Step 2/3: Flashing Bananarchy Linux ({device}) image to 'userdata'...") if not write_partition(fh, args.lun, userdata_part, userdata_img): sys.exit(1) - if not args.no_wipe_system and system_part: + if wipe_system and system_part: print( "\n[*] Step 3/3: Clearing stock 'system' superblock " "(first 64 sectors / 32 KiB)..." @@ -571,7 +1096,8 @@ def main(): if os.path.exists(zero_path): os.unlink(zero_path) else: - print("\n[*] Step 3/3: Skipping 'system' superblock wipe.") + print("\n[*] Step 3/3: Skipping 'system' superblock wipe " + "(--no-wipe-system).") if not args.no_reset: print(f"\n[*] Resetting and booting {device_label}...") @@ -580,7 +1106,28 @@ def main(): print("\n============================================================") print(" BANANARCHY EDL FLASHING COMPLETED SUCCESSFULLY") print("============================================================") - print(" The phone will now boot via lk2nd into Bananarchy Linux (Sxmo).") + if unlock_bootloader: + print(" eMMC devinfo.is_unlocked=1; note stock aboot also reads RPMB devinfo.") + if oem_unlock_enabled: + print(" config/frp allow-unlock flag set; run 'fastboot oem unlock-go'") + print(" once if verification still blocks lk2nd (see --only-unlock).") + if method == "recovery": + print(" system superblock wiped; a normal power-on will hang on the KaiOS logo.") + print(" Hold Volume Up at power-on to boot Bananarchy from 'recovery'.") + elif method == "both": + print(" boot and recovery both hold Bananarchy boot.img.") + print(" Try a normal power-on first; if the KaiOS logo persists, hold") + print(" Volume Up at power-on to boot the recovery copy.") + elif method == "boot": + print(" boot now holds Bananarchy boot.img: a normal power-on boots it.") + print(" (system superblock wiped; restore boot + system from stock firmware") + print(" if you ever want KaiOS back.)") + elif method == "lk2nd" and device == "nokia-beatles": + print(" boot and lk2nd hold the display-enabled nokia-beatles lk2nd port; recovery holds the mainline boot.img.") + print(" Normal power-on: aboot -> lk2nd -> extlinux -> Bananarchy.") + print(" Volume Up: aboot -> recovery -> mainline boot.img -> Bananarchy.") + else: + print(" The phone will now boot via lk2nd into Bananarchy Linux (Sxmo).") print(" Default login: user / " + DEFAULT_USER_PASSWORD + " | USB SSH: ssh user@172.16.42.1") print("============================================================") diff --git a/flash-edl.sh b/flash-edl.sh index 2cace74..5a9bc00 100755 --- a/flash-edl.sh +++ b/flash-edl.sh @@ -21,7 +21,7 @@ if ! "$PYTHON_BIN" -c 'import usb.core' >/dev/null 2>&1; then fi for arg in "$@"; do - if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then + if [ "$arg" = "-h" ] || [ "$arg" = "--help" ] || [ "$arg" = "--list-loaders" ]; then exec "$PYTHON_BIN" "$FLASHER_PY" "$@" fi done diff --git a/overlay/rootfs/boot/System.map b/overlay/rootfs/boot/System.map index afe50f3..a85172d 100644 --- a/overlay/rootfs/boot/System.map +++ b/overlay/rootfs/boot/System.map @@ -45060,273 +45060,273 @@ c0d043bc D proc_uid_seq_operations c0d043cc D pidns_operations c0d043ec D pidns_for_children_operations c0d04414 D kernel_config_data -c0d0e56f D kernel_config_data_end -c0d0e578 d config_gz_proc_ops -c0d0e5e0 d __func__.10 -c0d0e5ec d __func__.7 -c0d0e5fc d __func__.5 -c0d0e610 d __func__.3 -c0d0e620 d audit_feature_names -c0d0e740 d audit_ops -c0d0e98c d audit_nfcfgs -c0d0ea3c d ntp_name.0 -c0d0ea54 d audit_watch_fsnotify_ops -c0d0ea6c d audit_mark_fsnotify_ops -c0d0ea84 d audit_tree_ops -c0d0ea9c d kprobes_fops -c0d0eb20 d fops_kp -c0d0eba4 d kprobe_blacklist_fops -c0d0ec28 d kprobes_sops -c0d0ec38 d kprobe_blacklist_sops -c0d0ec70 d seccomp_log_names -c0d0ecb8 d seccomp_notify_ops -c0d0ed3c d mode1_syscalls -c0d0ed50 d seccomp_actions_avail -c0d0ed90 d taskstats_ops -c0d0edc8 d cgroupstats_cmd_get_policy -c0d0edd8 d taskstats_cmd_get_policy -c0d0ee0c d empty_hash -c0d0ee24 d show_ftrace_seq_ops -c0d0ee34 d ftrace_graph_seq_ops -c0d0ee44 d this_mod.0 -c0d0ee54 d ftrace_filter_fops -c0d0eed8 d ftrace_notrace_fops -c0d0ef5c d ftrace_no_pid_sops -c0d0ef6c d ftrace_pid_sops -c0d0ef7c d ftrace_pid_fops -c0d0f000 d ftrace_no_pid_fops -c0d0f084 d ftrace_avail_fops -c0d0f108 d ftrace_avail_addrs_fops -c0d0f18c d ftrace_enabled_fops -c0d0f210 d ftrace_touched_fops -c0d0f294 d ftrace_graph_fops -c0d0f318 d ftrace_graph_notrace_fops -c0d0f39c d empty_buckets -c0d0f44c d rb_meta_seq_ops -c0d0f460 d trace_clocks -c0d0f4cc d tracing_buffers_vmops -c0d0f504 d buffer_pipe_buf_ops -c0d0f514 d trace_options_fops -c0d0f598 d show_traces_seq_ops -c0d0f5a8 d tracing_err_log_seq_ops -c0d0f5b8 d show_traces_fops -c0d0f63c d set_tracer_fops -c0d0f6c0 d tracing_cpumask_fops -c0d0f744 d tracing_iter_fops -c0d0f7c8 d tracing_fops -c0d0f84c d tracing_pipe_fops -c0d0f8d0 d tracing_entries_fops -c0d0f954 d tracing_total_entries_fops -c0d0f9d8 d tracing_free_buffer_fops -c0d0fa5c d tracing_mark_fops -c0d0fae0 d tracing_mark_raw_fops -c0d0fb64 d trace_clock_fops -c0d0fbe8 d rb_simple_fops -c0d0fc6c d trace_time_stamp_mode_fops -c0d0fcf0 d buffer_percent_fops -c0d0fd74 d buffer_subbuf_size_fops -c0d0fdf8 d trace_options_core_fops -c0d0fe7c d last_boot_fops -c0d0ff00 d tracing_err_log_fops -c0d0ff84 d tracing_buffers_fops -c0d10008 d tracing_stats_fops -c0d1008c d tracing_buffer_meta_fops -c0d10110 d tracer_seq_ops -c0d10120 d space.8 -c0d10130 d tracing_thresh_fops -c0d101b4 d tracing_readme_fops -c0d10238 d tracing_dyn_info_fops -c0d102bc D trace_min_max_fops -c0d10340 d readme_msg -c0d11e60 d timerlat_lat_context -c0d11e6c d state_char.0 -c0d11e78 d trace_stat_seq_ops -c0d11e88 d tracing_stat_fops -c0d11f0c d ftrace_formats_fops -c0d11f90 d show_format_seq_ops -c0d11fa0 d tracing_saved_tgids_seq_ops -c0d11fb0 d tracing_saved_cmdlines_seq_ops -c0d11fc0 D tracing_saved_cmdlines_size_fops -c0d12044 D tracing_saved_cmdlines_fops -c0d120c8 D tracing_saved_tgids_fops -c0d1214c d CSWTCH.34 -c0d12170 d spaces.0 -c0d12198 d graph_depth_fops -c0d12234 d ftrace_subsystem_filter_fops -c0d122b8 d ftrace_system_enable_fops -c0d1233c d ftrace_tr_enable_fops -c0d123c0 d ftrace_show_header_page_fops -c0d12444 d ftrace_show_header_event_fops -c0d124c8 d trace_format_seq_ops -c0d124d8 d ftrace_set_event_fops -c0d1255c d ftrace_set_event_pid_fops -c0d125e0 d ftrace_set_event_notrace_pid_fops -c0d12664 d show_set_event_seq_ops -c0d12674 d show_event_seq_ops -c0d12684 d show_set_no_pid_seq_ops -c0d12694 d show_set_pid_seq_ops -c0d126a4 d ftrace_event_format_fops -c0d12728 d ftrace_enable_fops -c0d127ac d ftrace_event_filter_fops -c0d12830 d ftrace_event_id_fops -c0d128b4 d ftrace_avail_fops -c0d12a20 d ops -c0d12a44 d event_triggers_seq_ops -c0d12a54 D event_trigger_fops -c0d12d50 d bpf_key_sig_kfunc_set -c0d12d5c d bpf_kprobe_multi_kfunc_set -c0d12d68 D bpf_get_current_task_proto -c0d12da4 D bpf_get_current_task_btf_proto -c0d12de0 D bpf_task_pt_regs_proto -c0d12e1c d bpf_perf_event_read_proto -c0d12e58 d bpf_trace_printk_proto -c0d12e94 D bpf_probe_read_user_proto -c0d12ed0 D bpf_probe_read_user_str_proto -c0d12f0c d bpf_probe_read_compat_str_proto -c0d12f48 d bpf_probe_read_compat_proto -c0d12f84 D bpf_probe_read_kernel_str_proto -c0d12fc0 d bpf_send_signal_proto -c0d12ffc d bpf_send_signal_thread_proto -c0d13038 d bpf_perf_event_read_value_proto -c0d13074 D bpf_snprintf_btf_proto -c0d130b0 d bpf_trace_vprintk_proto -c0d130ec d bpf_get_func_ip_proto_tracing -c0d13128 d bpf_get_branch_snapshot_proto -c0d13164 d bpf_probe_write_user_proto -c0d131a0 D bpf_probe_read_kernel_proto -c0d131dc d __func__.2 -c0d131f4 d __func__.0 -c0d13210 d bpf_perf_event_output_proto -c0d1324c d bpf_get_func_ip_proto_kprobe_multi -c0d13288 d bpf_get_func_ip_proto_uprobe_multi -c0d132c4 d bpf_get_func_ip_proto_kprobe -c0d13300 d bpf_get_attach_cookie_proto_kmulti -c0d1333c d bpf_get_attach_cookie_proto_umulti -c0d13378 d bpf_get_attach_cookie_proto_trace -c0d133b4 d bpf_perf_event_output_proto_tp -c0d133f0 d bpf_get_stackid_proto_tp -c0d1342c d bpf_get_stack_proto_tp -c0d13468 d bpf_perf_event_output_proto_raw_tp -c0d134a4 d bpf_get_stackid_proto_raw_tp -c0d134e0 d bpf_get_stack_proto_raw_tp -c0d1351c d bpf_get_attach_cookie_proto_tracing -c0d13558 d bpf_perf_prog_read_value_proto -c0d13594 d bpf_read_branch_records_proto -c0d135d0 d bpf_get_attach_cookie_proto_pe -c0d1360c d bpf_d_path_proto -c0d13648 d bpf_seq_write_proto -c0d13684 d bpf_get_func_arg_cnt_proto -c0d136c0 d bpf_get_func_ret_proto -c0d136fc d bpf_get_func_arg_proto -c0d13738 d bpf_seq_printf_btf_proto -c0d13774 d bpf_seq_printf_proto -c0d137b0 D perf_event_prog_ops -c0d137b4 D perf_event_verifier_ops -c0d137d0 D raw_tracepoint_writable_prog_ops -c0d137d4 D raw_tracepoint_writable_verifier_ops -c0d137f0 D tracing_prog_ops -c0d137f4 D tracing_verifier_ops -c0d13810 D raw_tracepoint_prog_ops -c0d13814 D raw_tracepoint_verifier_ops -c0d13830 D tracepoint_prog_ops -c0d13834 D tracepoint_verifier_ops -c0d13850 D kprobe_prog_ops -c0d13854 D kprobe_verifier_ops -c0d13870 d str__bpf_trace__trace_system_name -c0d138b0 d kprobe_events_ops -c0d13934 d kprobe_profile_ops -c0d139b8 d profile_seq_op -c0d139c8 d probes_seq_op -c0d139d8 d symbols.0 -c0d139f8 d str__error_report__trace_system_name -c0d13a08 d symbols.3 -c0d13a50 d symbols.2 -c0d13a70 d symbols.0 -c0d13a88 d symbols.1 -c0d13aa8 d str__power__trace_system_name -c0d13ab0 d symbols.0 -c0d13ae0 d str__rpm__trace_system_name -c0d13ae4 d dynamic_events_ops -c0d13b68 d dyn_event_seq_op -c0d13b98 d probe_fetch_types -c0d13d48 d CSWTCH.274 -c0d13d54 d CSWTCH.273 -c0d13d60 d reserved_field_names -c0d13d80 D print_type_format_string -c0d13d88 D print_type_format_symbol -c0d13d8c D print_type_format_char -c0d13d94 D print_type_format_x64 -c0d13d9c D print_type_format_x32 -c0d13da4 D print_type_format_x16 -c0d13dac D print_type_format_x8 -c0d13db4 D print_type_format_s64 -c0d13db8 D print_type_format_s32 -c0d13dbc D print_type_format_s16 -c0d13dc0 D print_type_format_s8 -c0d13dc4 D print_type_format_u64 -c0d13dc8 D print_type_format_u32 -c0d13dcc D print_type_format_u16 -c0d13dd0 D print_type_format_u8 -c0d13df8 d uprobe_events_ops -c0d13e7c d uprobe_profile_ops -c0d13f00 d profile_seq_op -c0d13f10 d probes_seq_op -c0d13fbc d symbols.8 -c0d13ff4 d symbols.7 -c0d1402c d symbols.6 -c0d14064 d symbols.5 -c0d1409c d symbols.4 -c0d140d4 d symbols.3 -c0d1410c d symbols.2 -c0d1413c d symbols.1 -c0d1416c d symbols.0 -c0d141ac d public_insntable.10 -c0d142ac d str__xdp__trace_system_name -c0d142b0 V arena_map_ops -c0d1435c D bpf_tail_call_proto -c0d14410 V bpf_seq_printf_btf_proto -c0d14c18 d bpf_link_type_strs -c0d14c54 d CSWTCH.401 -c0d14c8c d bpf_audit_str -c0d14c94 d bpf_map_default_vmops -c0d14ccc D bpf_map_offload_ops -c0d14d78 D bpf_map_fops -c0d14dfc d bpf_link_fops_poll -c0d14e80 d bpf_link_fops -c0d14f04 D bpf_prog_fops -c0d14f88 d bpf_map_types -c0d15010 d bpf_prog_types -c0d15094 d bpf_tracing_link_lops -c0d150b8 d bpf_raw_tp_link_lops -c0d150dc d bpf_perf_link_lops -c0d15100 d bpf_stats_fops -c0d15184 d bpf_sys_bpf_proto -c0d151c0 d bpf_sys_close_proto -c0d151fc d bpf_kallsyms_lookup_name_proto -c0d15238 D bpf_syscall_prog_ops -c0d1523c D bpf_syscall_verifier_ops -c0d15dbc d reg2btf_ids -c0d15e14 d caller_saved -c0d15e2c d opcode_flip.0 -c0d15ee4 d compatible_reg_types -c0d15f44 d mem_types -c0d15f70 d bpf_verifier_ops -c0d16044 d dynptr_types -c0d16070 d kptr_xchg_dest_types -c0d1609c d timer_types -c0d160c8 d const_str_ptr_types -c0d160f4 d stack_ptr_types -c0d16120 d func_ptr_types -c0d1614c d percpu_btf_ptr_types -c0d16178 d btf_ptr_types -c0d161a4 d const_map_ptr_types -c0d161d0 d ringbuf_mem_types -c0d161fc d context_types -c0d16228 d scalar_types -c0d16254 d fullsock_types -c0d16280 d spin_lock_types -c0d162ac d btf_id_sock_common_types -c0d162d8 d sock_types +c0d0e599 D kernel_config_data_end +c0d0e5a4 d config_gz_proc_ops +c0d0e60c d __func__.10 +c0d0e618 d __func__.7 +c0d0e628 d __func__.5 +c0d0e63c d __func__.3 +c0d0e64c d audit_feature_names +c0d0e770 d audit_ops +c0d0e9bc d audit_nfcfgs +c0d0ea6c d ntp_name.0 +c0d0ea84 d audit_watch_fsnotify_ops +c0d0ea9c d audit_mark_fsnotify_ops +c0d0eab4 d audit_tree_ops +c0d0eacc d kprobes_fops +c0d0eb50 d fops_kp +c0d0ebd4 d kprobe_blacklist_fops +c0d0ec58 d kprobes_sops +c0d0ec68 d kprobe_blacklist_sops +c0d0eca0 d seccomp_log_names +c0d0ece8 d seccomp_notify_ops +c0d0ed6c d mode1_syscalls +c0d0ed80 d seccomp_actions_avail +c0d0edc0 d taskstats_ops +c0d0edf8 d cgroupstats_cmd_get_policy +c0d0ee08 d taskstats_cmd_get_policy +c0d0ee3c d empty_hash +c0d0ee54 d show_ftrace_seq_ops +c0d0ee64 d ftrace_graph_seq_ops +c0d0ee74 d this_mod.0 +c0d0ee84 d ftrace_filter_fops +c0d0ef08 d ftrace_notrace_fops +c0d0ef8c d ftrace_no_pid_sops +c0d0ef9c d ftrace_pid_sops +c0d0efac d ftrace_pid_fops +c0d0f030 d ftrace_no_pid_fops +c0d0f0b4 d ftrace_avail_fops +c0d0f138 d ftrace_avail_addrs_fops +c0d0f1bc d ftrace_enabled_fops +c0d0f240 d ftrace_touched_fops +c0d0f2c4 d ftrace_graph_fops +c0d0f348 d ftrace_graph_notrace_fops +c0d0f3cc d empty_buckets +c0d0f47c d rb_meta_seq_ops +c0d0f490 d trace_clocks +c0d0f4fc d tracing_buffers_vmops +c0d0f534 d buffer_pipe_buf_ops +c0d0f544 d trace_options_fops +c0d0f5c8 d show_traces_seq_ops +c0d0f5d8 d tracing_err_log_seq_ops +c0d0f5e8 d show_traces_fops +c0d0f66c d set_tracer_fops +c0d0f6f0 d tracing_cpumask_fops +c0d0f774 d tracing_iter_fops +c0d0f7f8 d tracing_fops +c0d0f87c d tracing_pipe_fops +c0d0f900 d tracing_entries_fops +c0d0f984 d tracing_total_entries_fops +c0d0fa08 d tracing_free_buffer_fops +c0d0fa8c d tracing_mark_fops +c0d0fb10 d tracing_mark_raw_fops +c0d0fb94 d trace_clock_fops +c0d0fc18 d rb_simple_fops +c0d0fc9c d trace_time_stamp_mode_fops +c0d0fd20 d buffer_percent_fops +c0d0fda4 d buffer_subbuf_size_fops +c0d0fe28 d trace_options_core_fops +c0d0feac d last_boot_fops +c0d0ff30 d tracing_err_log_fops +c0d0ffb4 d tracing_buffers_fops +c0d10038 d tracing_stats_fops +c0d100bc d tracing_buffer_meta_fops +c0d10140 d tracer_seq_ops +c0d10150 d space.8 +c0d10160 d tracing_thresh_fops +c0d101e4 d tracing_readme_fops +c0d10268 d tracing_dyn_info_fops +c0d102ec D trace_min_max_fops +c0d10370 d readme_msg +c0d11e90 d timerlat_lat_context +c0d11e9c d state_char.0 +c0d11ea8 d trace_stat_seq_ops +c0d11eb8 d tracing_stat_fops +c0d11f3c d ftrace_formats_fops +c0d11fc0 d show_format_seq_ops +c0d11fd0 d tracing_saved_tgids_seq_ops +c0d11fe0 d tracing_saved_cmdlines_seq_ops +c0d11ff0 D tracing_saved_cmdlines_size_fops +c0d12074 D tracing_saved_cmdlines_fops +c0d120f8 D tracing_saved_tgids_fops +c0d1217c d CSWTCH.34 +c0d121a0 d spaces.0 +c0d121c8 d graph_depth_fops +c0d12264 d ftrace_subsystem_filter_fops +c0d122e8 d ftrace_system_enable_fops +c0d1236c d ftrace_tr_enable_fops +c0d123f0 d ftrace_show_header_page_fops +c0d12474 d ftrace_show_header_event_fops +c0d124f8 d trace_format_seq_ops +c0d12508 d ftrace_set_event_fops +c0d1258c d ftrace_set_event_pid_fops +c0d12610 d ftrace_set_event_notrace_pid_fops +c0d12694 d show_set_event_seq_ops +c0d126a4 d show_event_seq_ops +c0d126b4 d show_set_no_pid_seq_ops +c0d126c4 d show_set_pid_seq_ops +c0d126d4 d ftrace_event_format_fops +c0d12758 d ftrace_enable_fops +c0d127dc d ftrace_event_filter_fops +c0d12860 d ftrace_event_id_fops +c0d128e4 d ftrace_avail_fops +c0d12a50 d ops +c0d12a74 d event_triggers_seq_ops +c0d12a84 D event_trigger_fops +c0d12d80 d bpf_key_sig_kfunc_set +c0d12d8c d bpf_kprobe_multi_kfunc_set +c0d12d98 D bpf_get_current_task_proto +c0d12dd4 D bpf_get_current_task_btf_proto +c0d12e10 D bpf_task_pt_regs_proto +c0d12e4c d bpf_perf_event_read_proto +c0d12e88 d bpf_trace_printk_proto +c0d12ec4 D bpf_probe_read_user_proto +c0d12f00 D bpf_probe_read_user_str_proto +c0d12f3c d bpf_probe_read_compat_str_proto +c0d12f78 d bpf_probe_read_compat_proto +c0d12fb4 D bpf_probe_read_kernel_str_proto +c0d12ff0 d bpf_send_signal_proto +c0d1302c d bpf_send_signal_thread_proto +c0d13068 d bpf_perf_event_read_value_proto +c0d130a4 D bpf_snprintf_btf_proto +c0d130e0 d bpf_trace_vprintk_proto +c0d1311c d bpf_get_func_ip_proto_tracing +c0d13158 d bpf_get_branch_snapshot_proto +c0d13194 d bpf_probe_write_user_proto +c0d131d0 D bpf_probe_read_kernel_proto +c0d1320c d __func__.2 +c0d13224 d __func__.0 +c0d13240 d bpf_perf_event_output_proto +c0d1327c d bpf_get_func_ip_proto_kprobe_multi +c0d132b8 d bpf_get_func_ip_proto_uprobe_multi +c0d132f4 d bpf_get_func_ip_proto_kprobe +c0d13330 d bpf_get_attach_cookie_proto_kmulti +c0d1336c d bpf_get_attach_cookie_proto_umulti +c0d133a8 d bpf_get_attach_cookie_proto_trace +c0d133e4 d bpf_perf_event_output_proto_tp +c0d13420 d bpf_get_stackid_proto_tp +c0d1345c d bpf_get_stack_proto_tp +c0d13498 d bpf_perf_event_output_proto_raw_tp +c0d134d4 d bpf_get_stackid_proto_raw_tp +c0d13510 d bpf_get_stack_proto_raw_tp +c0d1354c d bpf_get_attach_cookie_proto_tracing +c0d13588 d bpf_perf_prog_read_value_proto +c0d135c4 d bpf_read_branch_records_proto +c0d13600 d bpf_get_attach_cookie_proto_pe +c0d1363c d bpf_d_path_proto +c0d13678 d bpf_seq_write_proto +c0d136b4 d bpf_get_func_arg_cnt_proto +c0d136f0 d bpf_get_func_ret_proto +c0d1372c d bpf_get_func_arg_proto +c0d13768 d bpf_seq_printf_btf_proto +c0d137a4 d bpf_seq_printf_proto +c0d137e0 D perf_event_prog_ops +c0d137e4 D perf_event_verifier_ops +c0d13800 D raw_tracepoint_writable_prog_ops +c0d13804 D raw_tracepoint_writable_verifier_ops +c0d13820 D tracing_prog_ops +c0d13824 D tracing_verifier_ops +c0d13840 D raw_tracepoint_prog_ops +c0d13844 D raw_tracepoint_verifier_ops +c0d13860 D tracepoint_prog_ops +c0d13864 D tracepoint_verifier_ops +c0d13880 D kprobe_prog_ops +c0d13884 D kprobe_verifier_ops +c0d138a0 d str__bpf_trace__trace_system_name +c0d138e0 d kprobe_events_ops +c0d13964 d kprobe_profile_ops +c0d139e8 d profile_seq_op +c0d139f8 d probes_seq_op +c0d13a08 d symbols.0 +c0d13a28 d str__error_report__trace_system_name +c0d13a38 d symbols.3 +c0d13a80 d symbols.2 +c0d13aa0 d symbols.0 +c0d13ab8 d symbols.1 +c0d13ad8 d str__power__trace_system_name +c0d13ae0 d symbols.0 +c0d13b10 d str__rpm__trace_system_name +c0d13b14 d dynamic_events_ops +c0d13b98 d dyn_event_seq_op +c0d13bc8 d probe_fetch_types +c0d13d78 d CSWTCH.274 +c0d13d84 d CSWTCH.273 +c0d13d90 d reserved_field_names +c0d13db0 D print_type_format_string +c0d13db8 D print_type_format_symbol +c0d13dbc D print_type_format_char +c0d13dc4 D print_type_format_x64 +c0d13dcc D print_type_format_x32 +c0d13dd4 D print_type_format_x16 +c0d13ddc D print_type_format_x8 +c0d13de4 D print_type_format_s64 +c0d13de8 D print_type_format_s32 +c0d13dec D print_type_format_s16 +c0d13df0 D print_type_format_s8 +c0d13df4 D print_type_format_u64 +c0d13df8 D print_type_format_u32 +c0d13dfc D print_type_format_u16 +c0d13e00 D print_type_format_u8 +c0d13e28 d uprobe_events_ops +c0d13eac d uprobe_profile_ops +c0d13f30 d profile_seq_op +c0d13f40 d probes_seq_op +c0d13fec d symbols.8 +c0d14024 d symbols.7 +c0d1405c d symbols.6 +c0d14094 d symbols.5 +c0d140cc d symbols.4 +c0d14104 d symbols.3 +c0d1413c d symbols.2 +c0d1416c d symbols.1 +c0d1419c d symbols.0 +c0d141dc d public_insntable.10 +c0d142dc d str__xdp__trace_system_name +c0d142e0 V arena_map_ops +c0d1438c D bpf_tail_call_proto +c0d14440 V bpf_seq_printf_btf_proto +c0d14c48 d bpf_link_type_strs +c0d14c84 d CSWTCH.401 +c0d14cbc d bpf_audit_str +c0d14cc4 d bpf_map_default_vmops +c0d14cfc D bpf_map_offload_ops +c0d14da8 D bpf_map_fops +c0d14e2c d bpf_link_fops_poll +c0d14eb0 d bpf_link_fops +c0d14f34 D bpf_prog_fops +c0d14fb8 d bpf_map_types +c0d15040 d bpf_prog_types +c0d150c4 d bpf_tracing_link_lops +c0d150e8 d bpf_raw_tp_link_lops +c0d1510c d bpf_perf_link_lops +c0d15130 d bpf_stats_fops +c0d151b4 d bpf_sys_bpf_proto +c0d151f0 d bpf_sys_close_proto +c0d1522c d bpf_kallsyms_lookup_name_proto +c0d15268 D bpf_syscall_prog_ops +c0d1526c D bpf_syscall_verifier_ops +c0d15dec d reg2btf_ids +c0d15e44 d caller_saved +c0d15e5c d opcode_flip.0 +c0d15f14 d compatible_reg_types +c0d15f74 d mem_types +c0d15fa0 d bpf_verifier_ops +c0d16074 d dynptr_types +c0d160a0 d kptr_xchg_dest_types +c0d160cc d timer_types +c0d160f8 d const_str_ptr_types +c0d16124 d stack_ptr_types +c0d16150 d func_ptr_types +c0d1617c d percpu_btf_ptr_types +c0d161a8 d btf_ptr_types +c0d161d4 d const_map_ptr_types +c0d16200 d ringbuf_mem_types +c0d1622c d context_types +c0d16258 d scalar_types +c0d16284 d fullsock_types +c0d162b0 d spin_lock_types +c0d162dc d btf_id_sock_common_types +c0d16308 d sock_types c0d16380 d bpf_map_iops c0d16400 d bpf_link_iops c0d16480 d bpf_prog_iops diff --git a/overlay/rootfs/boot/config b/overlay/rootfs/boot/config index 4b3a539..c5ee151 100644 --- a/overlay/rootfs/boot/config +++ b/overlay/rootfs/boot/config @@ -2524,7 +2524,7 @@ CONFIG_SPI_QUP=y # # SPI Multiplexer support # -# CONFIG_SPI_MUX is not set +CONFIG_SPI_MUX=m # # SPI Protocol Masters @@ -6070,6 +6070,17 @@ CONFIG_NVMEM_QCOM_QFPROM=y # CONFIG_FPGA is not set # CONFIG_FSI is not set # CONFIG_TEE is not set +CONFIG_MULTIPLEXER=m + +# +# Multiplexer drivers +# +# CONFIG_MUX_ADG792A is not set +# CONFIG_MUX_ADGS1408 is not set +CONFIG_MUX_GPIO=m +# CONFIG_MUX_MMIO is not set +# end of Multiplexer drivers + CONFIG_PM_OPP=y # CONFIG_SIOX is not set # CONFIG_SLIMBUS is not set diff --git a/overlay/rootfs/boot/qcom-msm8905-nokia-beatles.dtb b/overlay/rootfs/boot/qcom-msm8905-nokia-beatles.dtb new file mode 100644 index 0000000..8705f67 Binary files /dev/null and b/overlay/rootfs/boot/qcom-msm8905-nokia-beatles.dtb differ diff --git a/overlay/rootfs/boot/vmlinuz b/overlay/rootfs/boot/vmlinuz index b0dae39..910cc31 100755 Binary files a/overlay/rootfs/boot/vmlinuz and b/overlay/rootfs/boot/vmlinuz differ diff --git a/overlay/rootfs/etc/bananarchy/cover-display.conf b/overlay/rootfs/etc/bananarchy/cover-display.conf new file mode 100644 index 0000000..594ff9a --- /dev/null +++ b/overlay/rootfs/etc/bananarchy/cover-display.conf @@ -0,0 +1,33 @@ +# Bananarchy cover display daemon (Nokia 2720 Flip external panel). +# Root-owned: the daemon runs as root; user preferences live in +# /home/user/.config/bananarchy/cover-display.conf and are applied by +# the xcover DWM plugin at session start. + +# auto = /dev/fb1 (kernel spi-mux) -> /dev/spidev0.1 -> no hardware +backend = auto +fb_device = /dev/fb1 +spidev_device = /dev/spidev0.1 +gpiochip_device = /dev/gpiochip0 +panel_firmware = /lib/firmware/nokia,beatles-gc9305-ext-panel.bin +socket_path = /run/bananarchy/cover.sock +theme_file = /home/user/.Xresources +input_dir = /dev/input + +# GPIO offsets on MSM8909 TLMM (from the KaiOS downstream DTS) +mux_gpio = 13 +reset_gpio = 23 +# gpio110 (the internal panel's DC line) is claimed exclusively by +# panel-mipi-dbi-spi, so the daemon cannot request it through gpiochip0. +# The gpio13 switch routes the shared DC/CS lines; -1 lets the spidev +# backend open without fighting the kernel driver. Set this back to 110 +# only when the spi-mux kernel modules own both panels instead. +dc_gpio = -1 + +# Privacy defaults: no caller name, no notification body, no text in logs. +enabled = 1 +show_caller = 0 +show_notify = 0 +mask_logs = 1 +clock24 = 1 +brightness = 160 +blank_timeout = 120 diff --git a/overlay/rootfs/etc/conf.d/sshd b/overlay/rootfs/etc/conf.d/sshd new file mode 100644 index 0000000..1264cd1 --- /dev/null +++ b/overlay/rootfs/etc/conf.d/sshd @@ -0,0 +1,6 @@ +# Bananarchy: pin the PAM-enabled sshd binary explicitly. The stock init +# script picks /usr/sbin/sshd.pam only when its "sshd -G | grep UsePAM yes" +# probe succeeds; if that probe is skipped (e.g. a service manager invoking +# sshd directly) the default /usr/sbin/sshd is used and it *rejects* the +# postmarketOS "UsePAM yes" drop-in as an unsupported option. +SSHD_BINARY="/usr/sbin/sshd.pam" diff --git a/overlay/rootfs/etc/conf.d/udev-settle b/overlay/rootfs/etc/conf.d/udev-settle new file mode 100644 index 0000000..553b958 --- /dev/null +++ b/overlay/rootfs/etc/conf.d/udev-settle @@ -0,0 +1,2 @@ +# Bound udevadm settle so missing modem firmware cannot delay X startup. +udev_settle_timeout=2 diff --git a/overlay/rootfs/etc/init.d/bananarchy-cover-display b/overlay/rootfs/etc/init.d/bananarchy-cover-display new file mode 100755 index 0000000..337e8bf --- /dev/null +++ b/overlay/rootfs/etc/init.d/bananarchy-cover-display @@ -0,0 +1,34 @@ +#!/sbin/openrc-run +# Bananarchy cover display daemon. Only active on flip devices; the +# lid-profile file is written by scripts/apply-bananarchy-overlay.sh. + +description="Nokia 2720 Flip external cover display" +# The recovered native bananarchy-coverd busy-loops at 100% CPU on the +# spidev backend (gpio110/DC is owned by panel-mipi-dbi-spi) and paints +# nothing. Keep that binary installed for the future spi-mux work, but run +# the compiled idle IPC server in the default runlevel. No Python runs here. +command="/usr/bin/bananarchy-cover-idle" +command_args="--config /etc/bananarchy/cover-display.conf" +command_background="yes" +pidfile="/run/bananarchy/cover-display.pid" +output_log="/run/bananarchy/cover-display.log" +error_log="/run/bananarchy/cover-display.log" + +depend() { + need udev + after udev-settle +} + +start_pre() { + mkdir -p /run/bananarchy + chmod 0755 /run/bananarchy +} + +start() { + if [ "$(cat /usr/share/bananarchy/lid-profile 2>/dev/null)" != "flip" ]; then + ebegin "Skipping cover display (not a flip device)" + eend 0 + return 0 + fi + default_start +} diff --git a/overlay/rootfs/etc/init.d/bananarchy-lid b/overlay/rootfs/etc/init.d/bananarchy-lid new file mode 100755 index 0000000..0e1b1b8 --- /dev/null +++ b/overlay/rootfs/etc/init.d/bananarchy-lid @@ -0,0 +1,14 @@ +#!/sbin/openrc-run +# Nokia 2720 Flip hall-sensor lid handling (lock, blank, cover switch). + +description="Bananarchy flip lid handler" + +command="/usr/bin/bananarchy-lid" +command_background=true +pidfile="/run/bananarchy-lid.pid" + +depend() { + need udev + after udev-settle + before bananarchy-cover-display tinydm +} diff --git a/overlay/rootfs/etc/init.d/bananarchy-sshd-debug b/overlay/rootfs/etc/init.d/bananarchy-sshd-debug new file mode 100644 index 0000000..adf3ae3 --- /dev/null +++ b/overlay/rootfs/etc/init.d/bananarchy-sshd-debug @@ -0,0 +1,28 @@ +#!/sbin/openrc-run +# USB-only PAM-free fallback sshd, started independently of local.d. +description="Bananarchy USB diagnostic sshd" + +command="/usr/sbin/sshd" +command_args="-f /etc/ssh/sshd_config_debug" +pidfile="/run/sshd-debug.pid" + +depend() { + need localmount + after sshd udev-settle +} + +start_pre() { + [ -x /usr/sbin/sshd ] || return 1 + [ -f /etc/ssh/ssh_host_ed25519_key ] || /usr/sbin/ssh-keygen -A >/dev/null 2>&1 || true +} + +start() { + if [ -f /etc/bananarchy-no-debug-sshd ]; then + ebegin "Skipping USB-only diagnostic sshd" + eend 0 + return 0 + fi + ebegin "Starting USB-only diagnostic sshd" + "$command" $command_args + eend $? +} diff --git a/overlay/rootfs/etc/init.d/bananarchy-volume-keys b/overlay/rootfs/etc/init.d/bananarchy-volume-keys new file mode 100755 index 0000000..bdf9b84 --- /dev/null +++ b/overlay/rootfs/etc/init.d/bananarchy-volume-keys @@ -0,0 +1,13 @@ +#!/sbin/openrc-run +# Direct evdev handling for the 2720 Flip side volume rocker. + +description="Bananarchy side volume keys" + +command="/usr/bin/bananarchy-volume-keys" +command_background=true +pidfile="/run/bananarchy-volume-keys.pid" + +depend() { + need udev + after udev-settle +} diff --git a/overlay/rootfs/etc/init.d/local b/overlay/rootfs/etc/init.d/local new file mode 100755 index 0000000..a75c558 --- /dev/null +++ b/overlay/rootfs/etc/init.d/local @@ -0,0 +1,96 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2015 The OpenRC Authors. +# See the Authors file at the top-level directory of this distribution and +# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS +# +# This file is part of OpenRC. It is subject to the license terms in +# the LICENSE file found in the top-level directory of this +# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE +# This file may not be copied, modified, propagated, or distributed +# except according to the terms contained in the LICENSE file. + +conf_d_dir="${RC_SERVICE%/*/*}/conf.d" +local_d_dir="${RC_SERVICE%/*/*}/local.d" + +description="Executes user programs in ${local_d_dir}" + +depend() +{ + after modules udev-settle + keyword -timeout +} + +start() +{ + local file has_errors redirect retval + has_errors=0 + yesno $rc_verbose || redirect='> /dev/null 2>&1' + ebegin "Starting local" + eindent + for file in "${local_d_dir}"/*.start; do + if [ -x "${file}" ]; then + vebegin "Executing \"${file}\"" + eval "${file}" $redirect + retval=$? + if [ ${retval} -ne 0 ]; then + has_errors=1 + fi + veend ${retval} "Execution of \"${file}\" failed." + fi + done + eoutdent + + if command -v local_start >/dev/null 2>&1; then + ewarn "\"${conf_d_dir}/local\" should be removed." + ewarn "Please move the code from the local_start function" + ewarn "to executable scripts with an .start extension" + ewarn "in \"${local_d_dir}\"" + local_start + fi + + eend ${has_errors} + + # We have to end with a zero exit code, because a failed execution + # of an executable ${local_d_dir}/*.start file shouldn't result in + # marking the local service as failed. Otherwise we are unable to + # execute any executable ${local_d_dir}/*.stop file, because a failed + # marked service cannot be stopped (and the stop function would + # actually call the executable ${local_d_dir}/*.stop file(s)). + return 0 +} + +stop() +{ + local file has_errors redirect retval + has_errors=0 + yesno $rc_verbose || redirect='> /dev/null 2>&1' + ebegin "Stopping local" + eindent + for file in "${local_d_dir}"/*.stop; do + if [ -x "${file}" ]; then + vebegin "Executing \"${file}\"" + eval "${file}" $redirect + retval=$? + if [ ${retval} -ne 0 ]; then + has_errors=1 + fi + veend ${retval} "Execution of \"${file}\" failed." + fi + done + eoutdent + + if command -v local_stop >/dev/null 2>&1; then + ewarn "\"${conf_d_dir}/local\" should be removed." + ewarn "Please move the code from the local_stop function" + ewarn "to executable scripts with an .stop extension" + ewarn "in \"${local_d_dir}\"" + local_stop + fi + + eend ${has_errors} + + # An executable ${local_d_dir}/*.stop file which failed with a + # non-zero exit status is not a reason to mark this service + # as failed, therefore we have to end with a zero exit code. + return 0 +} diff --git a/overlay/rootfs/etc/local.d/10-bananarchy-hardware.start b/overlay/rootfs/etc/local.d/10-bananarchy-hardware.start new file mode 100755 index 0000000..96d5e31 --- /dev/null +++ b/overlay/rootfs/etc/local.d/10-bananarchy-hardware.start @@ -0,0 +1,13 @@ +#!/bin/sh +# Make sure the out-of-tree camera driver, the cover-panel spidev driver and +# the spi-mux modules are loaded even when the boot-runlevel "modules" service +# could not process /etc/modules (it needs /bin/sed, which was missing on some +# rootfs builds). +for mod in msm8905-cam spidev mux-core mux-gpio spi-mux; do + i=0 + while [ "$i" -lt 5 ]; do + /sbin/modprobe -q "$mod" && break + i=$((i + 1)) + sleep 1 + done +done diff --git a/overlay/rootfs/etc/local.d/20-bananarchy-sshd-debug.start b/overlay/rootfs/etc/local.d/20-bananarchy-sshd-debug.start new file mode 100755 index 0000000..88d3833 --- /dev/null +++ b/overlay/rootfs/etc/local.d/20-bananarchy-sshd-debug.start @@ -0,0 +1,19 @@ +#!/bin/sh +# Keep a USB-only diagnostic login available even when the main sshd's PAM +# stack is misconfigured. It is bound to 172.16.42.1 so it is never exposed +# over Wi-Fi or the modem; create /etc/bananarchy-no-debug-sshd to disable. +[ -f /etc/bananarchy-no-debug-sshd ] && exit 0 +if rc-service bananarchy-sshd-debug status >/dev/null 2>&1; then + exit 0 +fi +[ -x /usr/sbin/sshd ] || exit 0 +[ -f /etc/ssh/ssh_host_ed25519_key ] || /usr/sbin/ssh-keygen -A >/dev/null 2>&1 +# The USB gadget address may appear after this service starts, so retry. +( + i=0 + while [ "$i" -lt 30 ]; do + /usr/sbin/sshd -f /etc/ssh/sshd_config_debug >/dev/null 2>&1 && break + i=$((i + 1)) + sleep 2 + done +) & diff --git a/overlay/rootfs/etc/modules-load.d/bananarchy-hardware.conf b/overlay/rootfs/etc/modules-load.d/bananarchy-hardware.conf new file mode 100644 index 0000000..29d35d3 --- /dev/null +++ b/overlay/rootfs/etc/modules-load.d/bananarchy-hardware.conf @@ -0,0 +1,9 @@ +# Bananarchy hardware drivers that are not probed from a DT node. +# msm8905-cam registers /dev/video0 (GC2395/GC2385 rear camera). +msm8905-cam +# spidev binds to the 2720 Flip external-panel chip select (/dev/spidev0.1). +spidev +# The opt-in cover-panel DTB needs the gpio mux and spi-mux drivers. +mux-core +mux-gpio +spi-mux diff --git a/overlay/rootfs/etc/pam.d/sshd b/overlay/rootfs/etc/pam.d/sshd new file mode 100644 index 0000000..ce13919 --- /dev/null +++ b/overlay/rootfs/etc/pam.d/sshd @@ -0,0 +1,13 @@ +#%PAM-1.0 +# Bananarchy: Alpine ships two sshd binaries. The postmarketOS policy +# drop-in (50-postmarketos-ui-policy.conf) sets "UsePAM yes", which makes +# /etc/init.d/sshd pick /usr/sbin/sshd.pam + /usr/lib/ssh/sshd-auth.pam. +# Without this service file Linux-PAM falls back to a nonexistent +# /etc/pam.d/other and pam_start() aborts: password, keyboard-interactive +# and even the account check for public-key logins all fail. Keep the stack +# minimal so it works with or without elogind running. +auth required pam_unix.so +account required pam_unix.so +password required pam_unix.so +session optional pam_env.so +session required pam_unix.so diff --git a/overlay/rootfs/etc/rc.conf b/overlay/rootfs/etc/rc.conf new file mode 100644 index 0000000..13c5d58 --- /dev/null +++ b/overlay/rootfs/etc/rc.conf @@ -0,0 +1,346 @@ +# Global OpenRC configuration settings + +# Set to "YES" if you want the rc system to try and start services +# in parallel for a slight speed improvement. When running in parallel we +# prefix the service output with its name as the output will get +# jumbled up. +# WARNING: whilst we have improved parallel, it can still potentially lock +# the boot process. Don't file bugs about this unless you can supply +# patches that fix it without breaking other things! +#rc_parallel="NO" + +# Set rc_interactive to "YES" and you'll be able to press the I key during +# boot so you can choose to start specific services. Set to "NO" to disable +# this feature. This feature is automatically disabled if rc_parallel is +# set to YES. +#rc_interactive="YES" + +# Set to "NO" if you don't want pam_openrc autostarting user services. This +# effectively disables the pam module, without the need of removing it from +# the pam configuration files. +#rc_autostart_user="YES" + +# If we need to drop to a shell, you can specify it here. +# If not specified we use $SHELL, otherwise the one specified in /etc/passwd, +# otherwise /bin/sh +# Linux users could specify /sbin/sulogin +#rc_shell=/bin/sh + +# Do we allow any started service in the runlevel to satisfy the dependency +# or do we want all of them regardless of state? For example, if net.eth0 +# and net.eth1 are in the default runlevel then with rc_depend_strict="NO" +# both will be started, but services that depend on 'net' will work if either +# one comes up. With rc_depend_strict="YES" we would require them both to +# come up. +#rc_depend_strict="YES" + +# rc_hotplug controls which services we allow to be hotplugged. +# A hotplugged service is one started by a dynamic dev manager when a matching +# hardware device is found. +# Hotplugged services appear in the "hotplugged" runlevel. +# If rc_hotplug is set to any value, we compare the name of this service +# to every pattern in the value, from left to right, and we allow the +# service to be hotplugged if it matches a pattern, or if it matches no +# patterns. Patterns can include shell wildcards. +# To disable services from being hotplugged, prefix patterns with "!". +#If rc_hotplug is not set or is empty, all hotplugging is disabled. +# Example - rc_hotplug="net.wlan !net.*" +# This allows net.wlan and any service not matching net.* to be hotplugged. +# Example - rc_hotplug="!net.*" +# This allows services that do not match "net.*" to be hotplugged. + +# rc_logger launches a logging daemon to log the entire rc process to +# /var/log/rc.log +# NOTE: Linux systems require the devfs service to be started before +# logging can take place and as such cannot log the sysinit runlevel. +#rc_logger="NO" + +# Through rc_log_path you can specify a custom log file. +# The default value is: /var/log/rc.log +#rc_log_path="/var/log/rc.log" + +# If you want verbose output for OpenRC, set this to yes. If you want +# verbose output for service foo only, set it to yes in /etc/conf.d/foo. +#rc_verbose=no + +# By default we filter the environment for our running scripts. To allow other +# variables through, add them here. Use a * to allow all variables through. +#rc_env_allow="VAR1 VAR2" + +# By default we assume that all daemons will start correctly. +# However, some do not - a classic example is that they fork and return 0 AND +# then child barfs on a configuration error. Or the daemon has a bug and the +# child crashes. You can set the number of milliseconds start-stop-daemon +# waits to check that the daemon is still running after starting here. +# The default is 0 - no checking. +#rc_start_wait=100 + +# rc_nostop is a list of services which will not stop when changing runlevels. +# This still allows the service itself to be stopped when called directly. +#rc_nostop="" + +# rc will attempt to start crashed services by default. +# However, it will not stop them by default as that could bring down other +# critical services. +#rc_crashed_stop=NO +#rc_crashed_start=YES + +# Set rc_nocolor to yes if you do not want colors displayed in OpenRC +# output. +#rc_nocolor=NO + +############################################################################## +# MISC CONFIGURATION VARIABLES +# There variables are shared between many init scripts + +# Set unicode to NO to turn off unicode support for keyboards and screens. +#unicode="YES" + +# This is how long fuser should wait for a remote server to respond. The +# default is 60 seconds, but it can be adjusted here. +#rc_fuser_timeout=60 + +# Below is the default list of network fstypes. +# +# afs ceph cifs coda davfs fuse fuse.glusterfs fuse.sshfs gfs glusterfs lustre +# ncpfs nfs nfs4 ocfs2 shfs smbfs +# +# If you would like to add to this list, you can do so by adding your +# own fstypes to the following variable. +#extra_net_fs_list="" + +############################################################################## +# SERVICE CONFIGURATION VARIABLES +# These variables are documented here, but should be configured in +# /etc/conf.d/foo for service foo and NOT enabled here unless you +# really want them to work on a global basis. +# If your service has characters in its name which are not legal in +# shell variable names and you configure the variables for it in this +# file, those characters should be replaced with underscores in the +# variable names as shown below. + +# Some daemons are started and stopped via start-stop-daemon. +# We can set some things on a per service basis, like the nicelevel. +# These need to be exported +#export SSD_NICELEVEL="0" +# Or the ionice level. The format is class[:data] , just like the +# --ionice start-stop-daemon parameter. +#export SSD_IONICELEVEL="0:0" +# Or the OOM score adjustment. +#export SSD_OOM_SCORE_ADJ="0" + +# Pass ulimit parameters +# If you are using bash in POSIX mode for your shell, note that the +# ulimit command uses a block size of 512 bytes for the -c and -f +# options +#rc_ulimit="-u 30" + +# It's possible to define extra dependencies for services like so +#rc_config="/etc/foo" +#rc_need="openvpn" +#rc_use="net.eth0" +#rc_after="clock" +#rc_before="local" +#rc_provide="!net" + +# You can also enable the above commands here for each service. Below is an +# example for service foo. +#rc_foo_config="/etc/foo" +#rc_foo_need="openvpn" +#rc_foo_after="clock" + +# Below is an example for service foo-bar. Note that the '-' is illegal +# in a shell variable name, so we convert it to an underscore. +# example for service foo-bar. +#rc_foo_bar_config="/etc/foo-bar" +#rc_foo_bar_need="openvpn" +#rc_foo_bar_after="clock" + +# You can also remove dependencies. +# This is mainly used for saying which services do NOT provide net. +#rc_net_tap0_provide="!net" + +# This is the subsystem type. +# It is used to match against keywords set by the keyword call in the +# depend function of service scripts. +# +# It should be set to the value representing the environment this file is +# PRESENTLY in, not the virtualization the environment is capable of. +# If it is commented out, automatic detection will be used. +# +# The list below shows all possible settings as well as the host +# operating systems where they can be used and autodetected. +# +# "" - nothing special +# "docker" - Docker container manager (Linux) +# "podman" - Podman container manager (Linux) +# "jail" - Jail (DragonflyBSD or FreeBSD) +# "lxc" - Linux Containers +# "openvz" - Linux OpenVZ +# "prefix" - Prefix +# "rkt" - CoreOS container management system (Linux) +# "subhurd" - Hurd subhurds (to be checked) +# "systemd-nspawn" - Container created by systemd-nspawn (Linux) +# "uml" - Usermode Linux +# "vserver" - Linux vserver +# "xen0" - Xen0 Domain (Linux and NetBSD) +# "xenU" - XenU Domain (Linux and NetBSD) +#rc_sys="" + +# if you use openrc-init, which is currently only available on Linux, +# this is the default runlevel to activate after "sysinit" and "boot" +# when booting. +#rc_default_runlevel="default" + +# on Linux and Hurd, this is the number of ttys allocated for logins +# It is used in the consolefont, keymaps, numlock and termencoding +# service scripts. +rc_tty_number=12 + +############################################################################## +# LINUX CGROUPS RESOURCE MANAGEMENT + +# This sets the mode used to mount cgroups. +# "hybrid" mounts cgroups version 2 on /sys/fs/cgroup/unified and +# cgroups version 1 on /sys/fs/cgroup. +# "legacy" mounts cgroups version 1 on /sys/fs/cgroup +# "unified" mounts cgroups version 2 on /sys/fs/cgroup +#rc_cgroup_mode="unified" + +# This is a list of controllers which should be enabled for cgroups version 2 +# when hybrid mode is being used. +# Controllers listed here will not be available for cgroups version 1. +#rc_cgroup_controllers="" + +# This variable contains the cgroups version 2 settings for your services. +# If this is set in this file, the settings will apply to all services. +# If you want different settings for each service, place the settings in +# /etc/conf.d/foo for service foo. +# The format is to specify the setting and value followed by a newline. +# Multiple settings and values can be specified. +# For example, you would use this to set the maximum memory and maximum +# number of pids for a service. +#rc_cgroup_settings=" +#memory.max 10485760 +#pids.max max +#" +# +# For more information about the adjustments that can be made with +# cgroups version 2, see Documentation/cgroups-v2.txt in the linux kernel +# source tree. +#rc_cgroup_settings="" + +# This switch controls whether or not cgroups version 1 controllers are +# individually mounted under +# /sys/fs/cgroup in hybrid or legacy mode. +#rc_controller_cgroups="YES" + +# The following setting turns on the memory.use_hierarchy setting in the +# root memory cgroup for cgroups v1. +# It must be set to yes in this file if you want this functionality. +#rc_cgroup_memory_use_hierarchy="NO" + +# The following settings allow you to set up values for the cgroups version 1 +# controllers for your services. +# They can be set in this file;, however, if you do this, the settings +# will apply to all of your services. +# If you want different settings for each service, place the settings in +# /etc/conf.d/foo for service foo. +# The format is to specify the names of the settings followed by their +# values. Each variable can hold multiple settings. +# For example, you would use this to set the cpu.shares setting in the +# cpu controller to 512 for your service. +# rc_cgroup_cpu=" +# cpu.shares 512 +# " +# +# For more information about the adjustments that can be made with +# cgroups version 1, see Documentation/cgroups-v1/* in the linux kernel +# source tree. + +# Set the blkio controller settings for this service. +#rc_cgroup_blkio="" + +# Set the cpu controller settings for this service. +#rc_cgroup_cpu="" + +# Add this service to the cpuacct controller (any value means yes). +#rc_cgroup_cpuacct="" + +# Set the cpuset controller settings for this service. +#rc_cgroup_cpuset="" + +# Set the devices controller settings for this service. +#rc_cgroup_devices="" + +# Set the hugetlb controller settings for this service. +#rc_cgroup_hugetlb="" + +# Set the memory controller settings for this service. +#rc_cgroup_memory="" + +# Set the net_cls controller settings for this service. +#rc_cgroup_net_cls="" + +# Set the net_prio controller settings for this service. +#rc_cgroup_net_prio="" + +# Set the pids controller settings for this service. +#rc_cgroup_pids="" + +# Set this to YES if you want all of the processes in a service's cgroup +# killed when the service is stopped or restarted. +# Be aware that setting this to yes means all of a service's +# child processes will be killed. Keep this in mind if you set this to +# yes here instead of for the individual services in +# /etc/conf.d/. +# To perform this cleanup manually for a stopped service, you can +# execute cgroup_cleanup with /etc/init.d/ cgroup_cleanup or +# rc-service cgroup_cleanup. +# If the kernel includes support for cgroup2's cgroup.kill, this is used +# to reliably teardown the cgroup. +# If this fails, the process followed in this cleanup is the following: +# 1. send stopsig (sigterm if it isn't set) to all processes left in the +# cgroup immediately followed by sigcont. +# 2. Send sighup to all processes in the cgroup if rc_send_sighup is +# yes. +# 3. delay for rc_timeout_stopsec seconds. +# 4. send sigkill to all processes in the cgroup unless disabled by +# setting rc_send_sigkill to no. +# rc_cgroup_cleanup="NO" + +# If this is yes, we will send sighup to the processes in the cgroup +# immediately after stopsig and sigcont. +#rc_send_sighup="NO" + +# This is the amount of time in seconds that we delay after sending sigcont +# and optionally sighup, before we optionally send sigkill to all +# processes in the # cgroup. +# The default is 90 seconds. +#rc_timeout_stopsec="90" + +# If this is set to no, we do not send sigkill to all processes in the +# cgroup. +#rc_send_sigkill="YES" + +############################################################################## +# SUPERVISE DAEMON CONFIGURATION VARIABLES +# These variables sets more reasonable defaults for supervise-daemon(8). +# They may be overriden on a per service basis. + +# Wait this number of seconds before restarting a daemon after it crashes. +respawn_delay=2 + +# Sets the maximum number of times a daemon will be respawned during a respawn +# period. If a daemon dies more than this number of times during a respawn +# period, supervise-daemon(8) will give up trying to respawn it and exit. +# 0 means unlimited. +respawn_max=5 + +# Sets the length in seconds of a respawn period. +respawn_period=1800 + +# Bananarchy starts independent OpenRC services in parallel. The stock local +# service is patched to avoid "after *", which deadlocks with rc_parallel=YES. +# X startup is also bounded by etc/conf.d/udev-settle. +rc_parallel="YES" diff --git a/overlay/rootfs/etc/runlevels/default/bananarchy-cover-display b/overlay/rootfs/etc/runlevels/default/bananarchy-cover-display new file mode 120000 index 0000000..6833630 --- /dev/null +++ b/overlay/rootfs/etc/runlevels/default/bananarchy-cover-display @@ -0,0 +1 @@ +/etc/init.d/bananarchy-cover-display \ No newline at end of file diff --git a/overlay/rootfs/etc/runlevels/default/bananarchy-lid b/overlay/rootfs/etc/runlevels/default/bananarchy-lid new file mode 120000 index 0000000..5df105b --- /dev/null +++ b/overlay/rootfs/etc/runlevels/default/bananarchy-lid @@ -0,0 +1 @@ +/etc/init.d/bananarchy-lid \ No newline at end of file diff --git a/overlay/rootfs/etc/runlevels/default/bananarchy-sshd-debug b/overlay/rootfs/etc/runlevels/default/bananarchy-sshd-debug new file mode 120000 index 0000000..5d773dd --- /dev/null +++ b/overlay/rootfs/etc/runlevels/default/bananarchy-sshd-debug @@ -0,0 +1 @@ +/etc/init.d/bananarchy-sshd-debug \ No newline at end of file diff --git a/overlay/rootfs/etc/runlevels/default/bananarchy-volume-keys b/overlay/rootfs/etc/runlevels/default/bananarchy-volume-keys new file mode 120000 index 0000000..b1a9981 --- /dev/null +++ b/overlay/rootfs/etc/runlevels/default/bananarchy-volume-keys @@ -0,0 +1 @@ +/etc/init.d/bananarchy-volume-keys \ No newline at end of file diff --git a/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh b/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh index 1290dc6..f8995b6 100755 --- a/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh +++ b/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh @@ -124,6 +124,16 @@ fi # long-lived "nmcli device monitor" poller is started at idle. Disable the # superd unit too, in case an older session enabled it. superctl disable sxmo_networkmonitor >/dev/null 2>&1 || true +superctl stop sxmo_networkmonitor >/dev/null 2>&1 || true +bananarchy_kill_matches() { + pattern="$1" + for pid in $(ps | awk -v p="$pattern" 'index($0, p) && $0 !~ /awk/ {print $1}'); do + [ "$pid" = "$$" ] && continue + kill "$pid" >/dev/null 2>&1 || true + done +} +bananarchy_kill_matches "nmcli device monitor" +bananarchy_kill_matches "sxmo_networkmonitor.sh" # The daemon that display notifications popup messages superctl start sxmo_notificationmonitor diff --git a/overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf b/overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf new file mode 100644 index 0000000..a2c8864 --- /dev/null +++ b/overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf @@ -0,0 +1,5 @@ +# Bananarchy: the documented "user / 147147" USB SSH login must work. +# The stock sshd_config only ships these as commented defaults and the +# postmarketOS policy drop-in enables PAM, so state them explicitly. +PasswordAuthentication yes +KbdInteractiveAuthentication yes diff --git a/overlay/rootfs/etc/ssh/sshd_config_debug b/overlay/rootfs/etc/ssh/sshd_config_debug new file mode 100644 index 0000000..7ff5509 --- /dev/null +++ b/overlay/rootfs/etc/ssh/sshd_config_debug @@ -0,0 +1,18 @@ +# USB-only diagnostic SSH listener. Uses the non-PAM /usr/sbin/sshd (this +# file deliberately contains no UsePAM directive, which that binary rejects) +# so a broken PAM stack can never lock the developer out of the phone. +Port 2222 +ListenAddress 172.16.42.1:2222 +HostKey /etc/ssh/ssh_host_ed25519_key +PidFile /run/sshd-debug.pid +PermitRootLogin yes +PasswordAuthentication yes +KbdInteractiveAuthentication no +PubkeyAuthentication yes +AuthorizedKeysFile .ssh/authorized_keys +PermitEmptyPasswords no +UseDNS no +AllowTcpForwarding no +GatewayPorts no +X11Forwarding no +Subsystem sftp internal-sftp diff --git a/overlay/rootfs/etc/udev/rules.d/72-nokia-beatles-cover.rules b/overlay/rootfs/etc/udev/rules.d/72-nokia-beatles-cover.rules new file mode 100644 index 0000000..bf6d28d --- /dev/null +++ b/overlay/rootfs/etc/udev/rules.d/72-nokia-beatles-cover.rules @@ -0,0 +1,6 @@ +# Let the user session drive the Nokia 2720 Flip external panel. +# The daemon itself runs as root, but xcover and the Sxmo hooks talk to it +# over /run/bananarchy/cover.sock (mode 0660, group user). +SUBSYSTEM=="graphics", KERNEL=="fb1", GROUP="video", MODE="0660" +SUBSYSTEM=="spidev", KERNEL=="spidev*", GROUP="video", MODE="0660" +SUBSYSTEM=="gpio", KERNEL=="gpiochip*", GROUP="video", MODE="0660" diff --git a/overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules b/overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules new file mode 100644 index 0000000..7d1b1bd --- /dev/null +++ b/overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules @@ -0,0 +1,5 @@ +# Input event nodes must carry the seat tag so elogind can hand them to the +# non-root X server through TakeDevice. Without it Xorg enumerates zero +# physical devices and the keypad appears completely dead. udev must be +# running in the sysinit runlevel for any rule to take effect. +SUBSYSTEM=="input", KERNEL=="event*", TAG+="seat", GROUP="input", MODE="0660" diff --git a/overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh b/overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh index 8c1cb07..cec1477 100755 --- a/overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh +++ b/overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh @@ -119,8 +119,20 @@ if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then sxmo_wakelock.sh lock sxmo_modem_warming_up 120s fi -# It watch network changes and update the status bar icon by example -superctl start sxmo_networkmonitor +# Network status changes are event-driven through the NetworkManager +# dispatcher 30-bananarchy-network-status.sh. Keep the old nmcli device +# monitor poller stopped. +superctl disable sxmo_networkmonitor >/dev/null 2>&1 || true +superctl stop sxmo_networkmonitor >/dev/null 2>&1 || true +bananarchy_kill_matches() { + pattern="$1" + for pid in $(ps | awk -v p="$pattern" 'index($0, p) && $0 !~ /awk/ {print $1}'); do + [ "$pid" = "$$" ] && continue + kill "$pid" >/dev/null 2>&1 || true + done +} +bananarchy_kill_matches "nmcli device monitor" +bananarchy_kill_matches "sxmo_networkmonitor.sh" # The daemon that display notifications popup messages superctl start sxmo_notificationmonitor diff --git a/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.bin b/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.bin new file mode 100644 index 0000000..6c9eed5 Binary files /dev/null and b/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.bin differ diff --git a/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.txt b/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.txt new file mode 100644 index 0000000..399d6fc --- /dev/null +++ b/overlay/rootfs/lib/firmware/nokia,beatles-gc9305-ext-panel.txt @@ -0,0 +1,41 @@ +# Nokia 2720 Flip (nokia-beatles) 1.3-inch 240x240 external GC9305 panel. +# +# Derived from the KaiOS 3.10 downstream DTS in the archived postmarketOS +# linux-nokia-beatles package (0004-dts-adaptations.patch): +# spi_gc9305_v2_qvga_ext_cmd, qcom,mdss-spi-on-command: +# fe, ef, 3a 05, 35 00, 2a 00 00 00 ef, 2b 00 00 00 ef, 2c, +# delay 120, 11, 29, 2c +# qcom,mdss-spi-panel-width = 240, height = 240, bpp = 16. +# +# The register/gamma block below is the one already proven on this device's +# internal GC9305 panel (nokia,beatles-gc9305-panel.txt); the two column/page +# windows are set to 0..239 for the square cover panel. The blob is consumed +# by panel-mipi-dbi-spi (kernel) or by bananarchy-coverd's spidev backend. +# +# This init sequence is derived from vendor sources but has NOT yet been +# verified on 2720 Flip hardware; see NOKIA-2720-FLIP.md. + +command 0xfe +command 0xef +command 0x36 0x00 # MADCTL +command 0x3a 0x55 # 65K 16-bit RGB565 +command 0x35 0x00 # TE v-blanking +command 0xb2 0x0c 0x0c 0x00 0x33 0x33 # porch setting +command 0xb7 0x75 # gate control VGH/VGL +command 0xbb 0x34 # Vcoms +command 0xc0 0x2c # LCM control +command 0xc2 0x01 # VDV/VRH enable +command 0xc3 0x0d # VRH set +command 0xc4 0x20 # VDV set +command 0xc6 0xef # frame rate +command 0x44 0x00 0x00 # tearing scan line +command 0xd0 0xa4 0xa1 # power control 1 +command 0xe0 0xd0 0x02 0x09 0x0d 0x0e 0x19 0x30 0x51 0x43 0x09 0x14 0x13 0x18 0x21 +command 0xe1 0xd0 0x02 0x09 0x0d 0x0d 0x18 0x32 0x46 0x42 0x09 0x13 0x13 0x17 0x21 +command 0x2a 0x00 0x00 0x00 0xef # column address 0..239 +command 0x2b 0x00 0x00 0x00 0xef # page address 0..239 +command 0x2c # memory write +command 0x11 # sleep out +delay 120 +command 0x29 # display on +command 0x2c diff --git a/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-core.ko.zst b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-core.ko.zst new file mode 100644 index 0000000..b3f7430 Binary files /dev/null and b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-core.ko.zst differ diff --git a/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-gpio.ko.zst b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-gpio.ko.zst new file mode 100644 index 0000000..5736685 Binary files /dev/null and b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/mux-gpio.ko.zst differ diff --git a/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/spi/spi-mux.ko.zst b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/spi/spi-mux.ko.zst new file mode 100644 index 0000000..632ac32 Binary files /dev/null and b/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/spi/spi-mux.ko.zst differ diff --git a/overlay/rootfs/sbin/init b/overlay/rootfs/sbin/init new file mode 120000 index 0000000..a3aaff7 --- /dev/null +++ b/overlay/rootfs/sbin/init @@ -0,0 +1 @@ +/bin/busybox \ No newline at end of file diff --git a/overlay/rootfs/usr/bin/bananarchy-cover-event.sh b/overlay/rootfs/usr/bin/bananarchy-cover-event.sh new file mode 100755 index 0000000..7667eab --- /dev/null +++ b/overlay/rootfs/usr/bin/bananarchy-cover-event.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Bridge Sxmo hooks to the cover display daemon. Safe no-op on non-flip +# devices and when the daemon is not running. +set -u +EVENT="${1:-refresh}" +shift 2>/dev/null || true +[ "$(cat /usr/share/bananarchy/lid-profile 2>/dev/null)" = "flip" ] || exit 0 +case "$EVENT" in + notification) + /usr/bin/bananarchy-coverctl NOTIFY "Notification" >/dev/null 2>&1 || true + ;; + ring) + /usr/bin/bananarchy-coverctl CALL incoming "${1:--}" "-" >/dev/null 2>&1 || true + ;; + missed) + /usr/bin/bananarchy-coverctl CALL missed "${1:--}" "-" >/dev/null 2>&1 || true + ;; + call|active) + /usr/bin/bananarchy-coverctl CALL active "${1:--}" "-" >/dev/null 2>&1 || true + ;; + hangup|ended) + /usr/bin/bananarchy-coverctl CALL none "-" "-" >/dev/null 2>&1 || true + ;; + sms) + /usr/bin/bananarchy-coverctl SMS "${1:-1}" >/dev/null 2>&1 || true + ;; + screenoff) + /usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true + ;; + wake|refresh|theme) + /usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true + ;; + *) + /usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true + ;; +esac +exit 0 diff --git a/overlay/rootfs/usr/bin/bananarchy-cover-idle b/overlay/rootfs/usr/bin/bananarchy-cover-idle new file mode 100755 index 0000000..f84d01a Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-cover-idle differ diff --git a/overlay/rootfs/usr/bin/bananarchy-cover-msg b/overlay/rootfs/usr/bin/bananarchy-cover-msg new file mode 100755 index 0000000..60350c2 --- /dev/null +++ b/overlay/rootfs/usr/bin/bananarchy-cover-msg @@ -0,0 +1,4 @@ +#!/bin/sh +# Publish a notification on the 2720 Flip cover display via the daemon IPC. +set -eu +exec /usr/bin/bananarchy-coverctl -s /run/bananarchy/cover.sock NOTIFY "$*" diff --git a/overlay/rootfs/usr/bin/bananarchy-coverctl b/overlay/rootfs/usr/bin/bananarchy-coverctl new file mode 100755 index 0000000..b232d5b Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-coverctl differ diff --git a/overlay/rootfs/usr/bin/bananarchy-coverd b/overlay/rootfs/usr/bin/bananarchy-coverd new file mode 100755 index 0000000..3764ef2 Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-coverd differ diff --git a/overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh b/overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh new file mode 100755 index 0000000..7858f48 --- /dev/null +++ b/overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh @@ -0,0 +1,71 @@ +#!/bin/sh +# Collect everything needed to diagnose an unresponsive 2720 Flip keypad. +# Writes a compact report to stdout (redirect it to a file to keep it). +set -u +echo "=== bananarchy keypad diagnostics $(date) ===" +echo +echo "--- kernel ---" +uname -a +echo +echo "--- input devices ---" +cat /proc/bus/input/devices 2>/dev/null || echo "(no /proc/bus/input/devices)" +echo +echo "--- input event nodes ---" +ls -l /dev/input/event* 2>/dev/null || echo "(no event nodes)" +echo +echo "--- udev tags ---" +for dev in /dev/input/event*; do + [ -e "$dev" ] || continue + name=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep '^NAME=' | head -1) + tags=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep -E '^ID_INPUT(_KEY|_KEYBOARD|_SWITCH)?=' | tr '\n' ' ') + echo "$dev ${name:-NAME=} $tags" +done +echo +echo "--- switch state (SW_LID / SW_KEYPAD_SLIDE) ---" +for dev in /dev/input/event*; do + [ -e "$dev" ] || continue + sw=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep -c 'ID_INPUT_SWITCH=1') + [ "$sw" = "0" ] && continue + printf '%s: ' "$dev" + evtest --query "$dev" EV_SW SW_LID 2>/dev/null || echo "(evtest unavailable)" +done +echo +echo "--- kernel messages ---" +dmesg 2>/dev/null | grep -iE 'keypad|matrix|gpio-keys|input:|libinput' | tail -40 || echo "(dmesg unavailable)" +echo +echo "--- X input devices ---" +if command -v libinput >/dev/null 2>&1; then + DISPLAY=${DISPLAY:-:0} libinput list-devices 2>&1 | head -60 +else + echo "(libinput CLI unavailable)" +fi +echo +echo "--- Xorg log ---" +grep -iE 'keypad|input|libinput|Ignoring|no devices' /var/log/Xorg.0.log 2>/dev/null | tail -40 || echo "(no Xorg log)" +echo +echo "--- raw event probe (5 s, press keys now) ---" +keypad_dev="" +for dev in /dev/input/event*; do + [ -e "$dev" ] || continue + name=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep '^NAME=' | head -1) + case "$name" in *keypad*) keypad_dev="$dev" ;; esac +done +if [ -n "$keypad_dev" ] && command -v evtest >/dev/null 2>&1; then + timeout 5 evtest "$keypad_dev" 2>&1 | head -30 +else + echo "keypad device: ${keypad_dev:-not found}; evtest: $(command -v evtest || echo missing)" +fi +echo +echo "--- volume keys ---" +echo "XKB: $(DISPLAY=${DISPLAY:-:0} xkbcomp :0 - 2>/dev/null | grep -c XF86AudioRaiseVolume) XF86AudioRaiseVolume bindings" +for dev in /dev/input/event*; do + [ -e "$dev" ] || continue + name=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep '^NAME=' | head -1) + case "$name" in *gpio-keys*|*resin*) echo "$dev $name (KEY_VOLUMEUP / KEY_VOLUMEDOWN)" ;; esac +done +echo "logical volume: $(sxmo_audio.sh vol get 2>/dev/null)" +if command -v wpctl >/dev/null 2>&1; then + sink=$(wpctl status 2>/dev/null | sed -n '/Sinks:/,/Sources:/p' | sed -n 's/^[^0-9]*\([0-9][0-9]*\)\..*/\1/p' | head -n 1) + [ -n "$sink" ] && echo "pipewire sink $sink: $(wpctl get-volume "$sink" 2>/dev/null)" +fi +echo "=== end ===" diff --git a/overlay/rootfs/usr/bin/bananarchy-lid b/overlay/rootfs/usr/bin/bananarchy-lid new file mode 100755 index 0000000..b966a9f Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-lid differ diff --git a/overlay/rootfs/usr/bin/bananarchy-volume-keys b/overlay/rootfs/usr/bin/bananarchy-volume-keys new file mode 100755 index 0000000..a23f8b6 Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-volume-keys differ diff --git a/overlay/rootfs/usr/bin/bananarchy-x11-session.sh b/overlay/rootfs/usr/bin/bananarchy-x11-session.sh index 6e6a379..dcdf5c1 100755 --- a/overlay/rootfs/usr/bin/bananarchy-x11-session.sh +++ b/overlay/rootfs/usr/bin/bananarchy-x11-session.sh @@ -69,8 +69,30 @@ rm -f "$XDG_RUNTIME_DIR/sxmo.led.lock" "$XDG_RUNTIME_DIR"/sxmo_bat_state_* 2>/de # of idle blanking, or /etc/bananarchy-no-deep-standby to opt out of suspend. rm -f "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend" [ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ] && printf "%s\n" "$DBUS_SESSION_BUS_ADDRESS" > "$XDG_RUNTIME_DIR/dbus.bus" -printf "1\n" > /tmp/bananarchy_screen_locked -printf "lock\n" > "$XDG_RUNTIME_DIR/sxmo.state" +# A flip phone that boots open must start unlocked with a live keypad. The +# root lid daemon publishes the debounced hall state before tinydm starts; +# default to open if that file is unavailable so X never stalls on xlocker. +_lid_state="open" +if [ "$(cat /usr/share/bananarchy/lid-profile 2>/dev/null)" = "flip" ]; then + _lid_wait=0 + while [ "$_lid_wait" -lt 20 ] && [ ! -r /run/bananarchy/lid-state ]; do + sleep 0.1 + _lid_wait=$((_lid_wait + 1)) + done + if [ -r /run/bananarchy/lid-state ]; then + read -r _lid_state < /run/bananarchy/lid-state 2>/dev/null || _lid_state="open" + fi + if [ "$_lid_state" = "closed" ]; then + printf "1\n" > /tmp/bananarchy_screen_locked + printf "screenoff\n" > "$SXMO_STATE" + else + rm -f /tmp/bananarchy_screen_locked + printf "unlock\n" > "$SXMO_STATE" + fi +else + printf "1\n" > /tmp/bananarchy_screen_locked + printf "lock\n" > "$SXMO_STATE" +fi _init_bl="" if [ -r "$XDG_CONFIG_HOME/sxmo/brightness" ]; then @@ -93,6 +115,11 @@ elif [ -r /tmp/sxmo_saved_kbd_brightness ]; then fi printf "%s\n" "${_init_kbd:-255}" > /tmp/sxmo_saved_kbd_brightness printf "%s\n" "${_init_kbd:-255}" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true +if [ "$_lid_state" = "closed" ]; then + printf "0\n" > /sys/class/backlight/backlight/brightness 2>/dev/null || true + printf "0\n" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true + printf "4\n" > /sys/class/backlight/backlight/bl_power 2>/dev/null || true +fi XORG_BIN="Xorg" [ -x /tmp/x11/usr/bin/Xorg ] && XORG_BIN="/tmp/x11/usr/bin/Xorg" @@ -124,6 +151,7 @@ else xset +dpms >/dev/null 2>&1 || true xset dpms 0 0 0 >/dev/null 2>&1 || true fi +xset r rate 180 30 >/dev/null 2>&1 || true SESSION_PID_FILE="/tmp/bananarchy-x11-session.pid" printf "%s\n" "$$" > "$SESSION_PID_FILE" @@ -140,6 +168,36 @@ if [ -f /tmp/bananarchy_ext_logging ]; then else ( sxmo_hook_start.sh >/dev/null 2>&1 /dev/null)" = "flip" ] && \ + [ "$_lid_state" != "closed" ]; then + # Some Sxmo start hooks still map xlocker from a transient boot lock file. + # Keep the first 10 s of an open-lid boot unlocked, then stop interfering. + ( + i=0 + while [ "$i" -lt 20 ]; do + [ "$(cat /run/bananarchy/lid-state 2>/dev/null)" = "closed" ] && break + rm -f /tmp/bananarchy_screen_locked + printf "unlock\n" > "$SXMO_STATE" + if [ -p /tmp/dwm_plugin_locker.fifo ]; then + printf "CLOSE\n" > /tmp/dwm_plugin_locker.fifo 2>/dev/null || true + fi + sleep 0.5 + i=$((i + 1)) + done + ) & +fi + +# A cold boot can leave the resident dmenu or xlocker plugin holding an X +# keyboard grab before the user sees the desktop. Release both once after +# dwm has started; do not keep a background poller alive. +( + sleep 3 + /usr/bin/dwm-plugin dmenu close >/dev/null 2>&1 || true + if [ -p /tmp/dwm_plugin_locker.fifo ]; then + printf "CLOSE\n" > /tmp/dwm_plugin_locker.fifo 2>/dev/null || true + fi + xdotool key --clearmodifiers Escape >/dev/null 2>&1 || true +) & first_iter=1 while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do diff --git a/overlay/rootfs/usr/bin/dwm b/overlay/rootfs/usr/bin/dwm index 8393b8f..646c010 100755 Binary files a/overlay/rootfs/usr/bin/dwm and b/overlay/rootfs/usr/bin/dwm differ diff --git a/overlay/rootfs/usr/bin/sxmo_audio.sh b/overlay/rootfs/usr/bin/sxmo_audio.sh index a751110..d091a6b 100755 --- a/overlay/rootfs/usr/bin/sxmo_audio.sh +++ b/overlay/rootfs/usr/bin/sxmo_audio.sh @@ -470,17 +470,39 @@ EOF if [ "$eff_pct" -gt 0 ]; then printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true - if [ "$dev" = "Bluetooth" ]; then - pactl set-sink-volume @DEFAULT_SINK@ "${eff_pct}%" >/dev/null 2>&1 || true - else - pactl set-sink-volume @DEFAULT_SINK@ 100% >/dev/null 2>&1 || true - fi + bananarchy_set_sink_volume "$eff_pct" else printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true pactl set-sink-mute @DEFAULT_SINK@ 1 >/dev/null 2>&1 || true fi } +# Bananarchy: the MSM8905 mainline kernel exposes no ALSA card yet, so the +# amixer csets below are no-ops and PipeWire's null sink is the real output. +# @DEFAULT_SINK@ does not resolve when wireplumber has no default configured +# node, so resolve the first live sink id and set its volume directly. +bananarchy_set_sink_volume() { + pct="$1" + if [ -z "${XDG_RUNTIME_DIR:-}" ]; then + XDG_RUNTIME_DIR="/run/user/$(id -u)" + export XDG_RUNTIME_DIR + fi + if command -v wpctl >/dev/null 2>&1; then + sink="$(wpctl status 2>/dev/null | sed -n '/Sinks:/,/Sources:/p' \ + | sed -n 's/^[^0-9]*\([0-9][0-9]*\)\..*/\1/p' | head -n 1)" + if [ -n "$sink" ]; then + wpctl set-volume "$sink" "${pct}%" >/dev/null 2>&1 || true + if [ "$pct" -le 0 ]; then + wpctl set-mute "$sink" 1 >/dev/null 2>&1 || true + else + wpctl set-mute "$sink" 0 >/dev/null 2>&1 || true + fi + return 0 + fi + fi + pactl set-sink-volume @DEFAULT_SINK@ "${pct}%" >/dev/null 2>&1 || true +} + apply_vol_out() { dev="$(normalize_out_dev "${1:-$(fast_out_dev)}")" pct="$(clamp_pct "${2:-$(read_dev_vol "$dev")}" 85)" @@ -568,13 +590,14 @@ EOF if [ "$pw_muted" != "0" ]; then printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true - pactl set-sink-volume @DEFAULT_SINK@ 100% >/dev/null 2>&1 || true fi + bananarchy_set_sink_volume "$eff_pct" else if [ "$pw_muted" != "1" ]; then printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true pactl set-sink-mute @DEFAULT_SINK@ 1 >/dev/null 2>&1 || true fi + bananarchy_set_sink_volume 0 fi } @@ -849,7 +872,23 @@ volset() { fi } +# A direct evdev volume daemon and the X11 binding can both react to one +# physical key press. Collapse calls that arrive within 300 ms so the volume +# only steps once per press. +bananarchy_vol_debounce() { + # Timestamp based, no background subshell: a stale lock directory could + # otherwise block every future volume step forever. + now="$(awk '{printf "%d", $1 * 100}' /proc/uptime 2>/dev/null || printf 0)" + last="$(cat /tmp/bananarchy_vol_step 2>/dev/null || printf 0)" + [ -n "$now" ] || now=0 + [ -n "$last" ] || last=0 + [ $((now - last)) -lt 30 ] && return 1 + printf '%s\n' "$now" > /tmp/bananarchy_vol_step 2>/dev/null || true + return 0 +} + volup() { + bananarchy_vol_debounce || return 0 step="${1:-5}" target_dev="$(normalize_out_dev "${2:-$(fast_out_dev)}")" cur="$(read_dev_vol "$target_dev")" @@ -859,6 +898,7 @@ volup() { } voldown() { + bananarchy_vol_debounce || return 0 step="${1:-5}" target_dev="$(normalize_out_dev "${2:-$(fast_out_dev)}")" cur="$(read_dev_vol "$target_dev")" diff --git a/overlay/rootfs/usr/lib/dwm/plugins/locker.so b/overlay/rootfs/usr/lib/dwm/plugins/locker.so index 05a6561..04683d1 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/locker.so and b/overlay/rootfs/usr/lib/dwm/plugins/locker.so differ diff --git a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-argon.conf b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-argon.conf index 2235027..4344c09 100644 --- a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-argon.conf +++ b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-argon.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-beatles.conf b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-beatles.conf index 2235027..4344c09 100644 --- a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-beatles.conf +++ b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-beatles.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-leo.conf b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-leo.conf index 2235027..4344c09 100644 --- a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-leo.conf +++ b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-leo.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-sparkler.conf b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-sparkler.conf index 2235027..4344c09 100644 --- a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-sparkler.conf +++ b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-sparkler.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-tough.conf b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-tough.conf index 2235027..4344c09 100644 --- a/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-tough.conf +++ b/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-nokia-tough.conf @@ -1,2 +1 @@ -earlycon console=ttyMSM0,115200 diff --git a/overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules b/overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules new file mode 100644 index 0000000..a22f87c --- /dev/null +++ b/overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules @@ -0,0 +1,9 @@ +# The 2720 Flip GPIO matrix keypad must be seen as a keyboard by Xorg's +# libinput backend even when udev's input_id builtin only reports EV_SW on +# the companion gpio-keys device. Force the tags and keep the device nodes +# readable by the "input" group (the X session runs as "user"). +SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="keypad", \ + ENV{ID_INPUT}="1", ENV{ID_INPUT_KEY}="1", ENV{ID_INPUT_KEYBOARD}="1", \ + GROUP="input", MODE="0660" +SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="gpio-keys", \ + ENV{ID_INPUT}="1", GROUP="input", MODE="0660" diff --git a/overlay/rootfs/usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf b/overlay/rootfs/usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf new file mode 100644 index 0000000..9a6e8af --- /dev/null +++ b/overlay/rootfs/usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf @@ -0,0 +1,14 @@ +# Bind the GPIO matrix keypad explicitly. MatchIsKeyboard relies on udev's +# ID_INPUT_KEYBOARD tag, which can be missing on a matrix keypad whose key +# bitmask only contains phone-specific keycodes; MatchProduct alone still +# lets xf86-input-libinput enumerate the device's real EV_KEY capabilities. +Section "InputClass" + Identifier "Bananarchy matrix keypad" + MatchProduct "keypad" + MatchDevicePath "/dev/input/event*" + Driver "libinput" + Option "Ignore" "false" + Option "XkbRules" "evdev" + Option "XkbModel" "pc105" + Option "XkbLayout" "us" +EndSection diff --git a/overlay/rootfs/usr/share/bananarchy/lid-profile b/overlay/rootfs/usr/share/bananarchy/lid-profile new file mode 100644 index 0000000..bd95de1 --- /dev/null +++ b/overlay/rootfs/usr/share/bananarchy/lid-profile @@ -0,0 +1 @@ +flip diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh index 06b1aa5..166ef20 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh @@ -132,6 +132,16 @@ fi # long-lived "nmcli device monitor" poller is started at idle. Disable the # superd unit too, in case an older session enabled it. superctl disable sxmo_networkmonitor >/dev/null 2>&1 || true +superctl stop sxmo_networkmonitor >/dev/null 2>&1 || true +bananarchy_kill_matches() { + pattern="$1" + for pid in $(ps | awk -v p="$pattern" 'index($0, p) && $0 !~ /awk/ {print $1}'); do + [ "$pid" = "$$" ] && continue + kill "$pid" >/dev/null 2>&1 || true + done +} +bananarchy_kill_matches "nmcli device monitor" +bananarchy_kill_matches "sxmo_networkmonitor.sh" # The daemon that display notifications popup messages superctl start sxmo_notificationmonitor diff --git a/patches/kernel/0002-msm8905-nokia-beatles-and-coconut-dts.patch b/patches/kernel/0002-msm8905-nokia-beatles-and-coconut-dts.patch index ac1f151..45e9f99 100644 --- a/patches/kernel/0002-msm8905-nokia-beatles-and-coconut-dts.patch +++ b/patches/kernel/0002-msm8905-nokia-beatles-and-coconut-dts.patch @@ -1,6 +1,11 @@ ---- a/devices/nokia-argon/qcom-msm8905-nokia-argon.dts 2026-10-18 12:03:41.241108254 +0300 -+++ b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts 2026-10-18 12:03:41.241443705 +0300 -@@ -4,8 +4,8 @@ +# Bananarchy device tree derivation: nokia-beatles and nokia-coconut start +# from the mainline qcom-msm8905-nokia-argon.dts. This patch is documentation +# of that derivation; the DTBs in images/ are compiled directly from the +# devices/*/qcom-*.dts files by scripts/build-kernel-audio.sh. + +--- a/devices/nokia-argon/qcom-msm8905-nokia-argon.dts ++++ b/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts +@@ -4,10 +4,20 @@ #address-cells = <0x01>; #size-cells = <0x01>; interrupt-parent = <0x01>; @@ -10,8 +15,71 @@ + compatible = "nokia,beatles", "nokia,argon", "qcom,msm8905", "qcom,msm8909"; chassis-type = "handset"; ++ /* Qualcomm aboot selects an appended DTB by these IDs. All three values ++ * are copied verbatim from the MSM8905 QRD SKUB DTB (index 33) in the ++ * stock 2720 recovery image. Keep only that exact board-id pair: older ++ * aboot revisions inspect the first pair only, so adding lk2nd's ++ * 0x0b/0x100 variant makes the DTB look like a different board and the ++ * bootloader never jumps to the kernel. */ ++ qcom,msm-id = <0x14b 0x00>; ++ qcom,board-id = <0x1000b 0x100>; ++ qcom,pmic-id = <0x1000d 0x00 0x00 0x00>; ++ aliases { -@@ -1733,7 +1733,7 @@ + mmc0 = "/soc@0/sdhci@7824000"; + mmc1 = "/soc@0/sdhci@7864000"; +@@ -195,9 +205,13 @@ + }; + }; + ++ /* Stock aboot rewrites /memory:reg from the SMEM RAM partition table. ++ * Keep the mainline node name (libfdt resolves /memory to it) but ship the ++ * real 512 MiB size as a fallback, so a bootloader that fails to patch the ++ * node still gives Linux usable RAM instead of a zero-sized memory bank. */ + memory@80000000 { + device_type = "memory"; +- reg = <0x80000000 0x00>; ++ reg = <0x80000000 0x20000000>; + }; + + pmu { +@@ -1016,7 +1030,7 @@ + }; + + matrix-keypad-col-default-state { +- pins = "gpio52", "gpio56", "gpio7", "gpio99", "gpio6"; ++ pins = "gpio52", "gpio56", "gpio7", "gpio99", "gpio6", "gpio1"; + function = "gpio"; + drive-strength = <0x02>; + bias-disable; +@@ -1030,6 +1044,17 @@ + bias-pull-down; + phandle = <0x6e>; + }; ++ ++ /* External (cover) panel: TE gpio21, reset gpio23, ++ * SPI bus switch gpio13. Used by the cover-panel.dtsi ++ * fragment and by bananarchy-coverd's spidev backend. */ ++ cover-panel-gpios-default-state { ++ pins = "gpio21", "gpio23", "gpio13"; ++ function = "gpio"; ++ drive-strength = <0x02>; ++ bias-pull-down; ++ phandle = <0x92>; ++ }; + }; + + clock-controller@1800000 { +@@ -1150,7 +1175,7 @@ + debounce = <0x3d09>; + bias-pull-up; + status = "okay"; +- linux,code = <0x6c>; ++ linux,code = <0x72>; /* KEY_VOLUMEDOWN */ + }; + + watchdog { +@@ -1838,7 +1863,7 @@ status = "okay"; display@0 { @@ -20,8 +88,90 @@ reg = <0x00>; backlight = <0x6b>; reset-gpios = <0x27 0x19 0x00>; ---- a/devices/nokia-argon/qcom-msm8905-nokia-argon.dts 2026-10-18 12:03:41.241108254 +0300 -+++ b/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts 2026-10-18 12:03:41.241598417 +0300 +@@ -2287,30 +2312,36 @@ + pinctrl-0 = <0x86 0x87>; + pinctrl-names = "default"; + +- key-up { ++ /* gpio90 is the side volume-up rocker on the 2720 Flip. */ ++ key-volup { + wakeup-source; + gpios = <0x27 0x5a 0x01>; +- linux,code = <0x67>; ++ linux,code = <0x73>; /* KEY_VOLUMEUP -> XF86AudioRaiseVolume */ + debounce-interval = <0x0f>; + linux,can-disable; + }; + +- key-back { ++ /* gpio98 is the red end/power key. */ ++ key-end { + wakeup-source; + gpios = <0x27 0x62 0x01>; +- linux,code = <0x0e>; ++ linux,code = <0x74>; /* KEY_POWER -> XF86PowerOff */ + debounce-interval = <0x0f>; + linux,can-disable; + }; + +- switch-lid-close { ++ /* gpio92: closed-lid hall sensor (EV_SW SW_LID = 1). */ ++ hall-lid-closed { + wakeup-source; + gpios = <0x27 0x5c 0x01>; + linux,input-type = <0x05>; + linux,code = <0x00>; + }; + +- switch-lid-open { ++ /* gpio36: open-lid hall sensor (EV_SW SW_KEYPAD_SLIDE = 1), ++ * also wired to the internal/external panel SPI switch. */ ++ hall-lid-open { ++ wakeup-source; + gpios = <0x27 0x24 0x01>; + linux,input-type = <0x05>; + linux,code = <0x0a>; +@@ -2325,8 +2356,36 @@ + pinctrl-0 = <0x88 0x89>; + pinctrl-names = "default"; + row-gpios = <0x27 0x61 0x01 0x27 0x60 0x01 0x27 0x5f 0x01 0x27 0x5e 0x01>; +- col-gpios = <0x27 0x34 0x01 0x27 0x38 0x01 0x27 0x07 0x01 0x27 0x63 0x01 0x27 0x06 0x01>; +- linux,keymap = <0x1bd 0x10002 0x20005 0x30008 0x4020a 0x1000069 0x1010003 0x1020006 0x1030009 0x104000b 0x20002b8 0x2010004 0x2020007 0x203000a 0x204020b 0x300001c 0x301006a 0x30202b9>; ++ col-gpios = <0x27 0x34 0x01 0x27 0x38 0x01 0x27 0x07 0x01 0x27 0x63 0x01 0x27 0x06 0x01 0x27 0x01 0x01>; ++ /* Physical matrix from the KaiOS downstream DTS (4 rows x 6 cols), ++ * mapped to the canonical keycodes Bananarchy's X11 stack binds: ++ * soft left -> KEY_COMPOSE (XKB 135, XK_Menu), soft right -> KEY_BACK ++ * (XKB 166, XF86Back), center -> KEY_ENTER, call -> KEY_PICKUP_PHONE. ++ * See X_KEYPAD_MAPPING.md and NOKIA-2720-FLIP.md. */ ++ linux,keymap = < ++ 0x1bd /* (0,0) call KEY_PICKUP_PHONE */ ++ 0x10002 /* (0,1) 1 */ ++ 0x20005 /* (0,2) 4 */ ++ 0x30008 /* (0,3) 7 */ ++ 0x4020a /* (0,4) * KEY_NUMERIC_STAR */ ++ 0x500d4 /* (0,5) extra KEY_CAMERA -> XF86WebCam */ ++ 0x1000069 /* (1,0) D-pad left KEY_LEFT */ ++ 0x1010003 /* (1,1) 2 */ ++ 0x1020006 /* (1,2) 5 */ ++ 0x1030009 /* (1,3) 8 */ ++ 0x104000b /* (1,4) 0 */ ++ 0x105000e /* (1,5) clear KEY_BACKSPACE */ ++ 0x200007f /* (2,0) soft left KEY_COMPOSE -> XK_Menu */ ++ 0x2010004 /* (2,1) 3 */ ++ 0x2020007 /* (2,2) 6 */ ++ 0x203000a /* (2,3) 9 */ ++ 0x204020b /* (2,4) # KEY_NUMERIC_POUND */ ++ 0x300001c /* (3,0) D-pad OK KEY_ENTER -> Return */ ++ 0x301006a /* (3,1) D-pad right KEY_RIGHT */ ++ 0x302009e /* (3,2) soft right KEY_BACK -> XF86Back */ ++ 0x3030067 /* (3,3) D-pad up KEY_UP */ ++ 0x304006c /* (3,4) D-pad down KEY_DOWN */ ++ >; + }; + + leds { +--- a/devices/nokia-argon/qcom-msm8905-nokia-argon.dts ++++ b/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts @@ -4,8 +4,8 @@ #address-cells = <0x01>; #size-cells = <0x01>; @@ -33,7 +183,7 @@ chassis-type = "handset"; aliases { -@@ -1733,7 +1733,7 @@ +@@ -1838,7 +1838,7 @@ status = "okay"; display@0 { @@ -42,3 +192,21 @@ reg = <0x00>; backlight = <0x6b>; reset-gpios = <0x27 0x19 0x00>; + +@@ -1886,6 +1911,15 @@ + clock-frequency = "", "#("; + }; + }; ++ ++ /* External (cover) GC9305 shares the QUP5 SPI lines. ++ * bananarchy-coverd drives gpio13 to route them to the cover ++ * panel, then talks to it through /dev/spidev0.1. spi-qup ++ * has 4 native chip selects and toggles the single physical ++ * CS line, so reg=1 gives the daemon a second logical device. */ ++ spidev@1 { ++ compatible = "rohm,dh2228fv"; ++ reg = <0x01>; ++ spi-max-frequency = <0x2faf080>; ++ status = "okay"; ++ }; + }; diff --git a/patches/kernel/config-bananarchy-msm8909.armv7 b/patches/kernel/config-bananarchy-msm8909.armv7 index 4b3a539..c5ee151 100644 --- a/patches/kernel/config-bananarchy-msm8909.armv7 +++ b/patches/kernel/config-bananarchy-msm8909.armv7 @@ -2524,7 +2524,7 @@ CONFIG_SPI_QUP=y # # SPI Multiplexer support # -# CONFIG_SPI_MUX is not set +CONFIG_SPI_MUX=m # # SPI Protocol Masters @@ -6070,6 +6070,17 @@ CONFIG_NVMEM_QCOM_QFPROM=y # CONFIG_FPGA is not set # CONFIG_FSI is not set # CONFIG_TEE is not set +CONFIG_MULTIPLEXER=m + +# +# Multiplexer drivers +# +# CONFIG_MUX_ADG792A is not set +# CONFIG_MUX_ADGS1408 is not set +CONFIG_MUX_GPIO=m +# CONFIG_MUX_MMIO is not set +# end of Multiplexer drivers + CONFIG_PM_OPP=y # CONFIG_SIOX is not set # CONFIG_SLIMBUS is not set diff --git a/prebuilt/bananarchy-coverd/usr/bin/bananarchy-cover-event.sh b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-cover-event.sh new file mode 100755 index 0000000..7667eab --- /dev/null +++ b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-cover-event.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Bridge Sxmo hooks to the cover display daemon. Safe no-op on non-flip +# devices and when the daemon is not running. +set -u +EVENT="${1:-refresh}" +shift 2>/dev/null || true +[ "$(cat /usr/share/bananarchy/lid-profile 2>/dev/null)" = "flip" ] || exit 0 +case "$EVENT" in + notification) + /usr/bin/bananarchy-coverctl NOTIFY "Notification" >/dev/null 2>&1 || true + ;; + ring) + /usr/bin/bananarchy-coverctl CALL incoming "${1:--}" "-" >/dev/null 2>&1 || true + ;; + missed) + /usr/bin/bananarchy-coverctl CALL missed "${1:--}" "-" >/dev/null 2>&1 || true + ;; + call|active) + /usr/bin/bananarchy-coverctl CALL active "${1:--}" "-" >/dev/null 2>&1 || true + ;; + hangup|ended) + /usr/bin/bananarchy-coverctl CALL none "-" "-" >/dev/null 2>&1 || true + ;; + sms) + /usr/bin/bananarchy-coverctl SMS "${1:-1}" >/dev/null 2>&1 || true + ;; + screenoff) + /usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true + ;; + wake|refresh|theme) + /usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true + ;; + *) + /usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true + ;; +esac +exit 0 diff --git a/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverctl b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverctl new file mode 100755 index 0000000..b232d5b Binary files /dev/null and b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverctl differ diff --git a/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverd b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverd new file mode 100755 index 0000000..3764ef2 Binary files /dev/null and b/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverd differ diff --git a/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle new file mode 100755 index 0000000..f84d01a Binary files /dev/null and b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle differ diff --git a/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid new file mode 100755 index 0000000..b966a9f Binary files /dev/null and b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid differ diff --git a/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys new file mode 100755 index 0000000..a23f8b6 Binary files /dev/null and b/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys differ diff --git a/prebuilt/kernel-6.12.1-msm8916/System.map b/prebuilt/kernel-6.12.1-msm8916/System.map index afe50f3..a85172d 100644 --- a/prebuilt/kernel-6.12.1-msm8916/System.map +++ b/prebuilt/kernel-6.12.1-msm8916/System.map @@ -45060,273 +45060,273 @@ c0d043bc D proc_uid_seq_operations c0d043cc D pidns_operations c0d043ec D pidns_for_children_operations c0d04414 D kernel_config_data -c0d0e56f D kernel_config_data_end -c0d0e578 d config_gz_proc_ops -c0d0e5e0 d __func__.10 -c0d0e5ec d __func__.7 -c0d0e5fc d __func__.5 -c0d0e610 d __func__.3 -c0d0e620 d audit_feature_names -c0d0e740 d audit_ops -c0d0e98c d audit_nfcfgs -c0d0ea3c d ntp_name.0 -c0d0ea54 d audit_watch_fsnotify_ops -c0d0ea6c d audit_mark_fsnotify_ops -c0d0ea84 d audit_tree_ops -c0d0ea9c d kprobes_fops -c0d0eb20 d fops_kp -c0d0eba4 d kprobe_blacklist_fops -c0d0ec28 d kprobes_sops -c0d0ec38 d kprobe_blacklist_sops -c0d0ec70 d seccomp_log_names -c0d0ecb8 d seccomp_notify_ops -c0d0ed3c d mode1_syscalls -c0d0ed50 d seccomp_actions_avail -c0d0ed90 d taskstats_ops -c0d0edc8 d cgroupstats_cmd_get_policy -c0d0edd8 d taskstats_cmd_get_policy -c0d0ee0c d empty_hash -c0d0ee24 d show_ftrace_seq_ops -c0d0ee34 d ftrace_graph_seq_ops -c0d0ee44 d this_mod.0 -c0d0ee54 d ftrace_filter_fops -c0d0eed8 d ftrace_notrace_fops -c0d0ef5c d ftrace_no_pid_sops -c0d0ef6c d ftrace_pid_sops -c0d0ef7c d ftrace_pid_fops -c0d0f000 d ftrace_no_pid_fops -c0d0f084 d ftrace_avail_fops -c0d0f108 d ftrace_avail_addrs_fops -c0d0f18c d ftrace_enabled_fops -c0d0f210 d ftrace_touched_fops -c0d0f294 d ftrace_graph_fops -c0d0f318 d ftrace_graph_notrace_fops -c0d0f39c d empty_buckets -c0d0f44c d rb_meta_seq_ops -c0d0f460 d trace_clocks -c0d0f4cc d tracing_buffers_vmops -c0d0f504 d buffer_pipe_buf_ops -c0d0f514 d trace_options_fops -c0d0f598 d show_traces_seq_ops -c0d0f5a8 d tracing_err_log_seq_ops -c0d0f5b8 d show_traces_fops -c0d0f63c d set_tracer_fops -c0d0f6c0 d tracing_cpumask_fops -c0d0f744 d tracing_iter_fops -c0d0f7c8 d tracing_fops -c0d0f84c d tracing_pipe_fops -c0d0f8d0 d tracing_entries_fops -c0d0f954 d tracing_total_entries_fops -c0d0f9d8 d tracing_free_buffer_fops -c0d0fa5c d tracing_mark_fops -c0d0fae0 d tracing_mark_raw_fops -c0d0fb64 d trace_clock_fops -c0d0fbe8 d rb_simple_fops -c0d0fc6c d trace_time_stamp_mode_fops -c0d0fcf0 d buffer_percent_fops -c0d0fd74 d buffer_subbuf_size_fops -c0d0fdf8 d trace_options_core_fops -c0d0fe7c d last_boot_fops -c0d0ff00 d tracing_err_log_fops -c0d0ff84 d tracing_buffers_fops -c0d10008 d tracing_stats_fops -c0d1008c d tracing_buffer_meta_fops -c0d10110 d tracer_seq_ops -c0d10120 d space.8 -c0d10130 d tracing_thresh_fops -c0d101b4 d tracing_readme_fops -c0d10238 d tracing_dyn_info_fops -c0d102bc D trace_min_max_fops -c0d10340 d readme_msg -c0d11e60 d timerlat_lat_context -c0d11e6c d state_char.0 -c0d11e78 d trace_stat_seq_ops -c0d11e88 d tracing_stat_fops -c0d11f0c d ftrace_formats_fops -c0d11f90 d show_format_seq_ops -c0d11fa0 d tracing_saved_tgids_seq_ops -c0d11fb0 d tracing_saved_cmdlines_seq_ops -c0d11fc0 D tracing_saved_cmdlines_size_fops -c0d12044 D tracing_saved_cmdlines_fops -c0d120c8 D tracing_saved_tgids_fops -c0d1214c d CSWTCH.34 -c0d12170 d spaces.0 -c0d12198 d graph_depth_fops -c0d12234 d ftrace_subsystem_filter_fops -c0d122b8 d ftrace_system_enable_fops -c0d1233c d ftrace_tr_enable_fops -c0d123c0 d ftrace_show_header_page_fops -c0d12444 d ftrace_show_header_event_fops -c0d124c8 d trace_format_seq_ops -c0d124d8 d ftrace_set_event_fops -c0d1255c d ftrace_set_event_pid_fops -c0d125e0 d ftrace_set_event_notrace_pid_fops -c0d12664 d show_set_event_seq_ops -c0d12674 d show_event_seq_ops -c0d12684 d show_set_no_pid_seq_ops -c0d12694 d show_set_pid_seq_ops -c0d126a4 d ftrace_event_format_fops -c0d12728 d ftrace_enable_fops -c0d127ac d ftrace_event_filter_fops -c0d12830 d ftrace_event_id_fops -c0d128b4 d ftrace_avail_fops -c0d12a20 d ops -c0d12a44 d event_triggers_seq_ops -c0d12a54 D event_trigger_fops -c0d12d50 d bpf_key_sig_kfunc_set -c0d12d5c d bpf_kprobe_multi_kfunc_set -c0d12d68 D bpf_get_current_task_proto -c0d12da4 D bpf_get_current_task_btf_proto -c0d12de0 D bpf_task_pt_regs_proto -c0d12e1c d bpf_perf_event_read_proto -c0d12e58 d bpf_trace_printk_proto -c0d12e94 D bpf_probe_read_user_proto -c0d12ed0 D bpf_probe_read_user_str_proto -c0d12f0c d bpf_probe_read_compat_str_proto -c0d12f48 d bpf_probe_read_compat_proto -c0d12f84 D bpf_probe_read_kernel_str_proto -c0d12fc0 d bpf_send_signal_proto -c0d12ffc d bpf_send_signal_thread_proto -c0d13038 d bpf_perf_event_read_value_proto -c0d13074 D bpf_snprintf_btf_proto -c0d130b0 d bpf_trace_vprintk_proto -c0d130ec d bpf_get_func_ip_proto_tracing -c0d13128 d bpf_get_branch_snapshot_proto -c0d13164 d bpf_probe_write_user_proto -c0d131a0 D bpf_probe_read_kernel_proto -c0d131dc d __func__.2 -c0d131f4 d __func__.0 -c0d13210 d bpf_perf_event_output_proto -c0d1324c d bpf_get_func_ip_proto_kprobe_multi -c0d13288 d bpf_get_func_ip_proto_uprobe_multi -c0d132c4 d bpf_get_func_ip_proto_kprobe -c0d13300 d bpf_get_attach_cookie_proto_kmulti -c0d1333c d bpf_get_attach_cookie_proto_umulti -c0d13378 d bpf_get_attach_cookie_proto_trace -c0d133b4 d bpf_perf_event_output_proto_tp -c0d133f0 d bpf_get_stackid_proto_tp -c0d1342c d bpf_get_stack_proto_tp -c0d13468 d bpf_perf_event_output_proto_raw_tp -c0d134a4 d bpf_get_stackid_proto_raw_tp -c0d134e0 d bpf_get_stack_proto_raw_tp -c0d1351c d bpf_get_attach_cookie_proto_tracing -c0d13558 d bpf_perf_prog_read_value_proto -c0d13594 d bpf_read_branch_records_proto -c0d135d0 d bpf_get_attach_cookie_proto_pe -c0d1360c d bpf_d_path_proto -c0d13648 d bpf_seq_write_proto -c0d13684 d bpf_get_func_arg_cnt_proto -c0d136c0 d bpf_get_func_ret_proto -c0d136fc d bpf_get_func_arg_proto -c0d13738 d bpf_seq_printf_btf_proto -c0d13774 d bpf_seq_printf_proto -c0d137b0 D perf_event_prog_ops -c0d137b4 D perf_event_verifier_ops -c0d137d0 D raw_tracepoint_writable_prog_ops -c0d137d4 D raw_tracepoint_writable_verifier_ops -c0d137f0 D tracing_prog_ops -c0d137f4 D tracing_verifier_ops -c0d13810 D raw_tracepoint_prog_ops -c0d13814 D raw_tracepoint_verifier_ops -c0d13830 D tracepoint_prog_ops -c0d13834 D tracepoint_verifier_ops -c0d13850 D kprobe_prog_ops -c0d13854 D kprobe_verifier_ops -c0d13870 d str__bpf_trace__trace_system_name -c0d138b0 d kprobe_events_ops -c0d13934 d kprobe_profile_ops -c0d139b8 d profile_seq_op -c0d139c8 d probes_seq_op -c0d139d8 d symbols.0 -c0d139f8 d str__error_report__trace_system_name -c0d13a08 d symbols.3 -c0d13a50 d symbols.2 -c0d13a70 d symbols.0 -c0d13a88 d symbols.1 -c0d13aa8 d str__power__trace_system_name -c0d13ab0 d symbols.0 -c0d13ae0 d str__rpm__trace_system_name -c0d13ae4 d dynamic_events_ops -c0d13b68 d dyn_event_seq_op -c0d13b98 d probe_fetch_types -c0d13d48 d CSWTCH.274 -c0d13d54 d CSWTCH.273 -c0d13d60 d reserved_field_names -c0d13d80 D print_type_format_string -c0d13d88 D print_type_format_symbol -c0d13d8c D print_type_format_char -c0d13d94 D print_type_format_x64 -c0d13d9c D print_type_format_x32 -c0d13da4 D print_type_format_x16 -c0d13dac D print_type_format_x8 -c0d13db4 D print_type_format_s64 -c0d13db8 D print_type_format_s32 -c0d13dbc D print_type_format_s16 -c0d13dc0 D print_type_format_s8 -c0d13dc4 D print_type_format_u64 -c0d13dc8 D print_type_format_u32 -c0d13dcc D print_type_format_u16 -c0d13dd0 D print_type_format_u8 -c0d13df8 d uprobe_events_ops -c0d13e7c d uprobe_profile_ops -c0d13f00 d profile_seq_op -c0d13f10 d probes_seq_op -c0d13fbc d symbols.8 -c0d13ff4 d symbols.7 -c0d1402c d symbols.6 -c0d14064 d symbols.5 -c0d1409c d symbols.4 -c0d140d4 d symbols.3 -c0d1410c d symbols.2 -c0d1413c d symbols.1 -c0d1416c d symbols.0 -c0d141ac d public_insntable.10 -c0d142ac d str__xdp__trace_system_name -c0d142b0 V arena_map_ops -c0d1435c D bpf_tail_call_proto -c0d14410 V bpf_seq_printf_btf_proto -c0d14c18 d bpf_link_type_strs -c0d14c54 d CSWTCH.401 -c0d14c8c d bpf_audit_str -c0d14c94 d bpf_map_default_vmops -c0d14ccc D bpf_map_offload_ops -c0d14d78 D bpf_map_fops -c0d14dfc d bpf_link_fops_poll -c0d14e80 d bpf_link_fops -c0d14f04 D bpf_prog_fops -c0d14f88 d bpf_map_types -c0d15010 d bpf_prog_types -c0d15094 d bpf_tracing_link_lops -c0d150b8 d bpf_raw_tp_link_lops -c0d150dc d bpf_perf_link_lops -c0d15100 d bpf_stats_fops -c0d15184 d bpf_sys_bpf_proto -c0d151c0 d bpf_sys_close_proto -c0d151fc d bpf_kallsyms_lookup_name_proto -c0d15238 D bpf_syscall_prog_ops -c0d1523c D bpf_syscall_verifier_ops -c0d15dbc d reg2btf_ids -c0d15e14 d caller_saved -c0d15e2c d opcode_flip.0 -c0d15ee4 d compatible_reg_types -c0d15f44 d mem_types -c0d15f70 d bpf_verifier_ops -c0d16044 d dynptr_types -c0d16070 d kptr_xchg_dest_types -c0d1609c d timer_types -c0d160c8 d const_str_ptr_types -c0d160f4 d stack_ptr_types -c0d16120 d func_ptr_types -c0d1614c d percpu_btf_ptr_types -c0d16178 d btf_ptr_types -c0d161a4 d const_map_ptr_types -c0d161d0 d ringbuf_mem_types -c0d161fc d context_types -c0d16228 d scalar_types -c0d16254 d fullsock_types -c0d16280 d spin_lock_types -c0d162ac d btf_id_sock_common_types -c0d162d8 d sock_types +c0d0e599 D kernel_config_data_end +c0d0e5a4 d config_gz_proc_ops +c0d0e60c d __func__.10 +c0d0e618 d __func__.7 +c0d0e628 d __func__.5 +c0d0e63c d __func__.3 +c0d0e64c d audit_feature_names +c0d0e770 d audit_ops +c0d0e9bc d audit_nfcfgs +c0d0ea6c d ntp_name.0 +c0d0ea84 d audit_watch_fsnotify_ops +c0d0ea9c d audit_mark_fsnotify_ops +c0d0eab4 d audit_tree_ops +c0d0eacc d kprobes_fops +c0d0eb50 d fops_kp +c0d0ebd4 d kprobe_blacklist_fops +c0d0ec58 d kprobes_sops +c0d0ec68 d kprobe_blacklist_sops +c0d0eca0 d seccomp_log_names +c0d0ece8 d seccomp_notify_ops +c0d0ed6c d mode1_syscalls +c0d0ed80 d seccomp_actions_avail +c0d0edc0 d taskstats_ops +c0d0edf8 d cgroupstats_cmd_get_policy +c0d0ee08 d taskstats_cmd_get_policy +c0d0ee3c d empty_hash +c0d0ee54 d show_ftrace_seq_ops +c0d0ee64 d ftrace_graph_seq_ops +c0d0ee74 d this_mod.0 +c0d0ee84 d ftrace_filter_fops +c0d0ef08 d ftrace_notrace_fops +c0d0ef8c d ftrace_no_pid_sops +c0d0ef9c d ftrace_pid_sops +c0d0efac d ftrace_pid_fops +c0d0f030 d ftrace_no_pid_fops +c0d0f0b4 d ftrace_avail_fops +c0d0f138 d ftrace_avail_addrs_fops +c0d0f1bc d ftrace_enabled_fops +c0d0f240 d ftrace_touched_fops +c0d0f2c4 d ftrace_graph_fops +c0d0f348 d ftrace_graph_notrace_fops +c0d0f3cc d empty_buckets +c0d0f47c d rb_meta_seq_ops +c0d0f490 d trace_clocks +c0d0f4fc d tracing_buffers_vmops +c0d0f534 d buffer_pipe_buf_ops +c0d0f544 d trace_options_fops +c0d0f5c8 d show_traces_seq_ops +c0d0f5d8 d tracing_err_log_seq_ops +c0d0f5e8 d show_traces_fops +c0d0f66c d set_tracer_fops +c0d0f6f0 d tracing_cpumask_fops +c0d0f774 d tracing_iter_fops +c0d0f7f8 d tracing_fops +c0d0f87c d tracing_pipe_fops +c0d0f900 d tracing_entries_fops +c0d0f984 d tracing_total_entries_fops +c0d0fa08 d tracing_free_buffer_fops +c0d0fa8c d tracing_mark_fops +c0d0fb10 d tracing_mark_raw_fops +c0d0fb94 d trace_clock_fops +c0d0fc18 d rb_simple_fops +c0d0fc9c d trace_time_stamp_mode_fops +c0d0fd20 d buffer_percent_fops +c0d0fda4 d buffer_subbuf_size_fops +c0d0fe28 d trace_options_core_fops +c0d0feac d last_boot_fops +c0d0ff30 d tracing_err_log_fops +c0d0ffb4 d tracing_buffers_fops +c0d10038 d tracing_stats_fops +c0d100bc d tracing_buffer_meta_fops +c0d10140 d tracer_seq_ops +c0d10150 d space.8 +c0d10160 d tracing_thresh_fops +c0d101e4 d tracing_readme_fops +c0d10268 d tracing_dyn_info_fops +c0d102ec D trace_min_max_fops +c0d10370 d readme_msg +c0d11e90 d timerlat_lat_context +c0d11e9c d state_char.0 +c0d11ea8 d trace_stat_seq_ops +c0d11eb8 d tracing_stat_fops +c0d11f3c d ftrace_formats_fops +c0d11fc0 d show_format_seq_ops +c0d11fd0 d tracing_saved_tgids_seq_ops +c0d11fe0 d tracing_saved_cmdlines_seq_ops +c0d11ff0 D tracing_saved_cmdlines_size_fops +c0d12074 D tracing_saved_cmdlines_fops +c0d120f8 D tracing_saved_tgids_fops +c0d1217c d CSWTCH.34 +c0d121a0 d spaces.0 +c0d121c8 d graph_depth_fops +c0d12264 d ftrace_subsystem_filter_fops +c0d122e8 d ftrace_system_enable_fops +c0d1236c d ftrace_tr_enable_fops +c0d123f0 d ftrace_show_header_page_fops +c0d12474 d ftrace_show_header_event_fops +c0d124f8 d trace_format_seq_ops +c0d12508 d ftrace_set_event_fops +c0d1258c d ftrace_set_event_pid_fops +c0d12610 d ftrace_set_event_notrace_pid_fops +c0d12694 d show_set_event_seq_ops +c0d126a4 d show_event_seq_ops +c0d126b4 d show_set_no_pid_seq_ops +c0d126c4 d show_set_pid_seq_ops +c0d126d4 d ftrace_event_format_fops +c0d12758 d ftrace_enable_fops +c0d127dc d ftrace_event_filter_fops +c0d12860 d ftrace_event_id_fops +c0d128e4 d ftrace_avail_fops +c0d12a50 d ops +c0d12a74 d event_triggers_seq_ops +c0d12a84 D event_trigger_fops +c0d12d80 d bpf_key_sig_kfunc_set +c0d12d8c d bpf_kprobe_multi_kfunc_set +c0d12d98 D bpf_get_current_task_proto +c0d12dd4 D bpf_get_current_task_btf_proto +c0d12e10 D bpf_task_pt_regs_proto +c0d12e4c d bpf_perf_event_read_proto +c0d12e88 d bpf_trace_printk_proto +c0d12ec4 D bpf_probe_read_user_proto +c0d12f00 D bpf_probe_read_user_str_proto +c0d12f3c d bpf_probe_read_compat_str_proto +c0d12f78 d bpf_probe_read_compat_proto +c0d12fb4 D bpf_probe_read_kernel_str_proto +c0d12ff0 d bpf_send_signal_proto +c0d1302c d bpf_send_signal_thread_proto +c0d13068 d bpf_perf_event_read_value_proto +c0d130a4 D bpf_snprintf_btf_proto +c0d130e0 d bpf_trace_vprintk_proto +c0d1311c d bpf_get_func_ip_proto_tracing +c0d13158 d bpf_get_branch_snapshot_proto +c0d13194 d bpf_probe_write_user_proto +c0d131d0 D bpf_probe_read_kernel_proto +c0d1320c d __func__.2 +c0d13224 d __func__.0 +c0d13240 d bpf_perf_event_output_proto +c0d1327c d bpf_get_func_ip_proto_kprobe_multi +c0d132b8 d bpf_get_func_ip_proto_uprobe_multi +c0d132f4 d bpf_get_func_ip_proto_kprobe +c0d13330 d bpf_get_attach_cookie_proto_kmulti +c0d1336c d bpf_get_attach_cookie_proto_umulti +c0d133a8 d bpf_get_attach_cookie_proto_trace +c0d133e4 d bpf_perf_event_output_proto_tp +c0d13420 d bpf_get_stackid_proto_tp +c0d1345c d bpf_get_stack_proto_tp +c0d13498 d bpf_perf_event_output_proto_raw_tp +c0d134d4 d bpf_get_stackid_proto_raw_tp +c0d13510 d bpf_get_stack_proto_raw_tp +c0d1354c d bpf_get_attach_cookie_proto_tracing +c0d13588 d bpf_perf_prog_read_value_proto +c0d135c4 d bpf_read_branch_records_proto +c0d13600 d bpf_get_attach_cookie_proto_pe +c0d1363c d bpf_d_path_proto +c0d13678 d bpf_seq_write_proto +c0d136b4 d bpf_get_func_arg_cnt_proto +c0d136f0 d bpf_get_func_ret_proto +c0d1372c d bpf_get_func_arg_proto +c0d13768 d bpf_seq_printf_btf_proto +c0d137a4 d bpf_seq_printf_proto +c0d137e0 D perf_event_prog_ops +c0d137e4 D perf_event_verifier_ops +c0d13800 D raw_tracepoint_writable_prog_ops +c0d13804 D raw_tracepoint_writable_verifier_ops +c0d13820 D tracing_prog_ops +c0d13824 D tracing_verifier_ops +c0d13840 D raw_tracepoint_prog_ops +c0d13844 D raw_tracepoint_verifier_ops +c0d13860 D tracepoint_prog_ops +c0d13864 D tracepoint_verifier_ops +c0d13880 D kprobe_prog_ops +c0d13884 D kprobe_verifier_ops +c0d138a0 d str__bpf_trace__trace_system_name +c0d138e0 d kprobe_events_ops +c0d13964 d kprobe_profile_ops +c0d139e8 d profile_seq_op +c0d139f8 d probes_seq_op +c0d13a08 d symbols.0 +c0d13a28 d str__error_report__trace_system_name +c0d13a38 d symbols.3 +c0d13a80 d symbols.2 +c0d13aa0 d symbols.0 +c0d13ab8 d symbols.1 +c0d13ad8 d str__power__trace_system_name +c0d13ae0 d symbols.0 +c0d13b10 d str__rpm__trace_system_name +c0d13b14 d dynamic_events_ops +c0d13b98 d dyn_event_seq_op +c0d13bc8 d probe_fetch_types +c0d13d78 d CSWTCH.274 +c0d13d84 d CSWTCH.273 +c0d13d90 d reserved_field_names +c0d13db0 D print_type_format_string +c0d13db8 D print_type_format_symbol +c0d13dbc D print_type_format_char +c0d13dc4 D print_type_format_x64 +c0d13dcc D print_type_format_x32 +c0d13dd4 D print_type_format_x16 +c0d13ddc D print_type_format_x8 +c0d13de4 D print_type_format_s64 +c0d13de8 D print_type_format_s32 +c0d13dec D print_type_format_s16 +c0d13df0 D print_type_format_s8 +c0d13df4 D print_type_format_u64 +c0d13df8 D print_type_format_u32 +c0d13dfc D print_type_format_u16 +c0d13e00 D print_type_format_u8 +c0d13e28 d uprobe_events_ops +c0d13eac d uprobe_profile_ops +c0d13f30 d profile_seq_op +c0d13f40 d probes_seq_op +c0d13fec d symbols.8 +c0d14024 d symbols.7 +c0d1405c d symbols.6 +c0d14094 d symbols.5 +c0d140cc d symbols.4 +c0d14104 d symbols.3 +c0d1413c d symbols.2 +c0d1416c d symbols.1 +c0d1419c d symbols.0 +c0d141dc d public_insntable.10 +c0d142dc d str__xdp__trace_system_name +c0d142e0 V arena_map_ops +c0d1438c D bpf_tail_call_proto +c0d14440 V bpf_seq_printf_btf_proto +c0d14c48 d bpf_link_type_strs +c0d14c84 d CSWTCH.401 +c0d14cbc d bpf_audit_str +c0d14cc4 d bpf_map_default_vmops +c0d14cfc D bpf_map_offload_ops +c0d14da8 D bpf_map_fops +c0d14e2c d bpf_link_fops_poll +c0d14eb0 d bpf_link_fops +c0d14f34 D bpf_prog_fops +c0d14fb8 d bpf_map_types +c0d15040 d bpf_prog_types +c0d150c4 d bpf_tracing_link_lops +c0d150e8 d bpf_raw_tp_link_lops +c0d1510c d bpf_perf_link_lops +c0d15130 d bpf_stats_fops +c0d151b4 d bpf_sys_bpf_proto +c0d151f0 d bpf_sys_close_proto +c0d1522c d bpf_kallsyms_lookup_name_proto +c0d15268 D bpf_syscall_prog_ops +c0d1526c D bpf_syscall_verifier_ops +c0d15dec d reg2btf_ids +c0d15e44 d caller_saved +c0d15e5c d opcode_flip.0 +c0d15f14 d compatible_reg_types +c0d15f74 d mem_types +c0d15fa0 d bpf_verifier_ops +c0d16074 d dynptr_types +c0d160a0 d kptr_xchg_dest_types +c0d160cc d timer_types +c0d160f8 d const_str_ptr_types +c0d16124 d stack_ptr_types +c0d16150 d func_ptr_types +c0d1617c d percpu_btf_ptr_types +c0d161a8 d btf_ptr_types +c0d161d4 d const_map_ptr_types +c0d16200 d ringbuf_mem_types +c0d1622c d context_types +c0d16258 d scalar_types +c0d16284 d fullsock_types +c0d162b0 d spin_lock_types +c0d162dc d btf_id_sock_common_types +c0d16308 d sock_types c0d16380 d bpf_map_iops c0d16400 d bpf_link_iops c0d16480 d bpf_prog_iops diff --git a/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb b/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb index 2de7fda..8705f67 100644 Binary files a/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb and b/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb differ diff --git a/prebuilt/kernel-6.12.1-msm8916/kernel-config b/prebuilt/kernel-6.12.1-msm8916/kernel-config index 4b3a539..c5ee151 100644 --- a/prebuilt/kernel-6.12.1-msm8916/kernel-config +++ b/prebuilt/kernel-6.12.1-msm8916/kernel-config @@ -2524,7 +2524,7 @@ CONFIG_SPI_QUP=y # # SPI Multiplexer support # -# CONFIG_SPI_MUX is not set +CONFIG_SPI_MUX=m # # SPI Protocol Masters @@ -6070,6 +6070,17 @@ CONFIG_NVMEM_QCOM_QFPROM=y # CONFIG_FPGA is not set # CONFIG_FSI is not set # CONFIG_TEE is not set +CONFIG_MULTIPLEXER=m + +# +# Multiplexer drivers +# +# CONFIG_MUX_ADG792A is not set +# CONFIG_MUX_ADGS1408 is not set +CONFIG_MUX_GPIO=m +# CONFIG_MUX_MMIO is not set +# end of Multiplexer drivers + CONFIG_PM_OPP=y # CONFIG_SIOX is not set # CONFIG_SLIMBUS is not set diff --git a/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko b/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko new file mode 100644 index 0000000..0e84c84 Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko differ diff --git a/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst b/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst new file mode 100644 index 0000000..b3f7430 Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst differ diff --git a/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko b/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko new file mode 100644 index 0000000..143737b Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko differ diff --git a/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst b/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst new file mode 100644 index 0000000..5736685 Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst differ diff --git a/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko b/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko new file mode 100644 index 0000000..a6423c3 Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko differ diff --git a/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst b/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst new file mode 100644 index 0000000..632ac32 Binary files /dev/null and b/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst differ diff --git a/prebuilt/kernel-6.12.1-msm8916/vmlinuz b/prebuilt/kernel-6.12.1-msm8916/vmlinuz index b0dae39..910cc31 100755 Binary files a/prebuilt/kernel-6.12.1-msm8916/vmlinuz and b/prebuilt/kernel-6.12.1-msm8916/vmlinuz differ diff --git a/prebuilt/sxmo-x11/usr/bin/dwm b/prebuilt/sxmo-x11/usr/bin/dwm index 8393b8f..646c010 100755 Binary files a/prebuilt/sxmo-x11/usr/bin/dwm and b/prebuilt/sxmo-x11/usr/bin/dwm differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so index 05a6561..04683d1 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so differ diff --git a/prepare-release.sh b/prepare-release.sh index 84aafc3..544d9fc 100755 --- a/prepare-release.sh +++ b/prepare-release.sh @@ -3,14 +3,38 @@ set -eu BA_TARGET="${1:-nokia-argon}" +BA_REBUILD="${BA_REBUILD:-0}" BA_VER="$(./scripts/version.sh --print)" BA_CODENAME="$(./scripts/version.sh --print-codename)" RELDIR="bananarchy-${BA_TARGET}-${BA_VER}-${BA_CODENAME}" -./rebuild-image.sh "$BA_TARGET" --mkinitfs +NEED_REBUILD=0 +if [ ! -f "images/bananarchy-${BA_TARGET}.img" ]; then + NEED_REBUILD=1 +fi +if [ "$BA_TARGET" = "nokia-beatles" ]; then + for f in images/boot-bananarchy-nokia-beatles.img \ + images/boot-lk2nd-nokia-beatles-display.img; do + [ -f "$f" ] || NEED_REBUILD=1 + done +fi + +if [ "$BA_REBUILD" = "1" ] || [ "$NEED_REBUILD" = "1" ]; then + ./rebuild-image.sh "$BA_TARGET" --mkinitfs + if [ "$BA_TARGET" = "nokia-beatles" ] && \ + [ ! -f images/boot-lk2nd-nokia-beatles-display.img ]; then + ./scripts/build-lk2nd-beatles.sh --only display + fi +fi + mkdir -p "$RELDIR" cp "images/bananarchy-${BA_TARGET}.img" "$RELDIR/" -cp bootloader/lk2nd-msm8909.img "$RELDIR/" +if [ "$BA_TARGET" = "nokia-beatles" ]; then + cp images/boot-bananarchy-nokia-beatles.img "$RELDIR/" + cp images/boot-lk2nd-nokia-beatles-display.img "$RELDIR/" +else + cp bootloader/lk2nd-msm8909.img "$RELDIR/" +fi zip -9r "${RELDIR}.zip" "$RELDIR" rm -rf "$RELDIR" echo "Release $BA_VER ($BA_CODENAME) for $BA_TARGET packed into ${RELDIR}.zip" diff --git a/rebuild-image.sh b/rebuild-image.sh index 77b34a7..c8b2840 100755 --- a/rebuild-image.sh +++ b/rebuild-image.sh @@ -92,11 +92,21 @@ ensure_prebuilt_artifacts() { [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/netfilter/xt_owner.ko.zst" ] || \ [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/netfilter/nft_redir.ko.zst" ] || \ [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/leds/leds-msm8905-torch.ko.zst" ] || \ - [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/camera/msm8905-cam.ko.zst" ]; then + [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/camera/msm8905-cam.ko.zst" ] || \ + [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst" ] || \ + [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst" ] || \ + [ ! -f "$BANANARCHY_DIR/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst" ]; then echo "[auto-deps] Missing prebuilt kernel modules or DTBs; running scripts/build-kernel-audio.sh..." "$BANANARCHY_DIR/scripts/build-kernel-audio.sh" fi + if [ ! -x "$BANANARCHY_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid" ] || \ + [ ! -x "$BANANARCHY_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" ] || \ + [ ! -x "$BANANARCHY_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys" ]; then + echo "[auto-deps] Missing compiled idle daemons; running scripts/build-bananarchy-daemons.sh..." + "$BANANARCHY_DIR/scripts/build-bananarchy-daemons.sh" + fi + if [ ! -f "$BANANARCHY_DIR/prebuilt/bantam/bantam" ]; then echo "[auto-deps] Missing prebuilt bantam binary; running scripts/build-bantam.sh..." "$BANANARCHY_DIR/scripts/build-bantam.sh" @@ -392,6 +402,8 @@ EOF echo "[3/5] Creating ext2 boot (256 MiB) and ext4 root filesystems..." strip_build_residue + mkdir -p "$ROOTFS/sbin" + ln -sfn /bin/busybox "$ROOTFS/sbin/init" APK_CACHE_LEFT="$(ls -A "$ROOTFS/var/cache/apk" 2>/dev/null || true)" APK_LOGS_LEFT="$(ls "$ROOTFS/var/log"/apk.log* 2>/dev/null || true)" if [ -n "$APK_CACHE_LEFT" ] || [ -n "$APK_LOGS_LEFT" ]; then @@ -429,7 +441,6 @@ EOF "/images/bananarchy-$TARGET_DEVICE.sparse.img" \ "/images/nokia-argon-sxmo.sparse.img" \ "/images/nokia-argon-sxmo.img" \ - "/images/boot-bananarchy-$TARGET_DEVICE.img" \ "/images/boot-nokia-argon-sxmo.img" truncate -s "${TOTAL_MB}M" "$RAW_IMG" @@ -448,6 +459,11 @@ SFEOF dd if="$ROOT_IMG" of="$RAW_IMG" bs=1M seek=$(( 1 + BOOT_MB )) conv=notrunc,sparse status=none rm -f "$BOOT_IMG" "$ROOT_IMG" + # Export the Android boot image separately. The 2720 Flip needs it in the + # 'recovery' partition (Volume Up boot) instead of lk2nd in 'boot'. + cp -a "$ROOTFS/boot/boot.img" "/images/boot-bananarchy-$TARGET_DEVICE.img" + echo "[+] Exported standalone boot image: /images/boot-bananarchy-$TARGET_DEVICE.img" + echo "[5/5] Restoring host user ownership on $ROOTFS for easy host editing..." chown -R "$HOST_UID:$HOST_GID" "$ROOTFS" "/images" chmod -R u+rwX "$ROOTFS" diff --git a/scripts/apply-bananarchy-overlay.sh b/scripts/apply-bananarchy-overlay.sh index c9bfcd1..79f1737 100755 --- a/scripts/apply-bananarchy-overlay.sh +++ b/scripts/apply-bananarchy-overlay.sh @@ -87,10 +87,19 @@ if command -v docker >/dev/null 2>&1; then [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/netfilter/xt_owner.ko.zst" ] || \ [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/netfilter/nft_redir.ko.zst" ] || \ [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/leds/leds-msm8905-torch.ko.zst" ] || \ - [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/camera/msm8905-cam.ko.zst" ]; then + [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/camera/msm8905-cam.ko.zst" ] || \ + [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst" ] || \ + [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst" ] || \ + [ ! -f "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst" ]; then echo " -> Missing prebuilt kernel modules or DTBs; running scripts/build-kernel-audio.sh..." "$BASE_DIR/scripts/build-kernel-audio.sh" fi + if [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid" ] || \ + [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" ] || \ + [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys" ]; then + echo " -> Missing compiled idle daemons; running scripts/build-bananarchy-daemons.sh..." + "$BASE_DIR/scripts/build-bananarchy-daemons.sh" + fi if [ ! -f "$BASE_DIR/prebuilt/bantam/bantam" ]; then echo " -> Missing prebuilt bantam binary; running scripts/build-bantam.sh..." "$BASE_DIR/scripts/build-bantam.sh" @@ -100,6 +109,45 @@ fi echo "[1/4] Installing Bananarchy rootfs overlay (artwork, branding, Sxmo 240x320, UCM, udev)..." rm -f "$TARGET_ROOTFS/usr/bin/bantam" "$TARGET_ROOTFS/usr/local/bin/bantam" "$TARGET_ROOTFS/etc/doas.d/wheel.conf" cp -af "$BASE_DIR/overlay/rootfs/." "$TARGET_ROOTFS/" +rm -f "$TARGET_ROOTFS/usr/bin/bananarchy-lid.py" \ + "$TARGET_ROOTFS/usr/bin/bananarchy-cover-idle.py" \ + "$TARGET_ROOTFS/usr/bin/bananarchy-volume-keys.py" +for daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do + cp -af "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$daemon" \ + "$TARGET_ROOTFS/usr/bin/$daemon" + chmod 0755 "$TARGET_ROOTFS/usr/bin/$daemon" +done +ln -sfn /bin/busybox "$TARGET_ROOTFS/sbin/init" + +# Some rootfs trees were snapshotted before BusyBox installed its applet +# symlinks. /bin/ash is the "user" login shell and /bin/grep is used by +# openrc-run.sh; without them sshd rejects the account and the udev service +# fails, leaving /dev/input/event* root-owned and untagged so Xorg cannot +# attach the keypad. Never overwrite a real binary, only fill in gaps. +APPLET_LIST="$BASE_DIR/scripts/busybox-applets.txt" +if [ -f "$APPLET_LIST" ]; then + while IFS= read -r applet; do + [ -n "$applet" ] || continue + if [ ! -e "$TARGET_ROOTFS/bin/$applet" ]; then + [ ! -L "$TARGET_ROOTFS/bin/$applet" ] || \ + rm -f "$TARGET_ROOTFS/bin/$applet" + ln -s /bin/busybox "$TARGET_ROOTFS/bin/$applet" + fi + done < "$APPLET_LIST" +fi +# /sbin was pruned too: reboot/poweroff/halt (Sxmo power menu), syslogd, +# klogd, mdev, ip-* helpers and the ifconfig/route tools live there. +SBIN_LIST="$BASE_DIR/scripts/busybox-sbin-applets.txt" +if [ -f "$SBIN_LIST" ]; then + while IFS= read -r applet; do + [ -n "$applet" ] || continue + if [ ! -e "$TARGET_ROOTFS/sbin/$applet" ]; then + [ ! -L "$TARGET_ROOTFS/sbin/$applet" ] || \ + rm -f "$TARGET_ROOTFS/sbin/$applet" + ln -s /bin/busybox "$TARGET_ROOTFS/sbin/$applet" + fi + done < "$SBIN_LIST" +fi if [ -x "$BASE_DIR/scripts/version.sh" ]; then "$BASE_DIR/scripts/version.sh" "$TARGET_ROOTFS" fi @@ -203,6 +251,16 @@ if [ -d "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/wcn36xx" ] && \ cp -af "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/wcn36xx/"*.ko.zst \ "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/drivers/net/wireless/ath/wcn36xx/" fi +if [ -d "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/mux" ]; then + mkdir -p "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/drivers/mux" + cp -af "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/mux/"*.ko.zst \ + "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/drivers/mux/" +fi +if [ -d "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/spi" ]; then + mkdir -p "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/drivers/spi" + cp -af "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/spi/"*.ko.zst \ + "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/drivers/spi/" +fi if [ -d "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/codecs" ] && \ [ -d "$TARGET_ROOTFS/lib/modules/6.12.1-msm8916/kernel/sound/soc/codecs" ]; then cp -af "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/codecs/"*.ko.zst \ @@ -329,6 +387,7 @@ rm -rf \ ln -sf /etc/init.d/kill-plymouth "$TARGET_ROOTFS/etc/runlevels/default/kill-plymouth" ln -sf /etc/init.d/bananarchy-power-policy "$TARGET_ROOTFS/etc/runlevels/default/bananarchy-power-policy" ln -sf /etc/init.d/bananarchy-time-sync "$TARGET_ROOTFS/etc/runlevels/default/bananarchy-time-sync" +ln -sf /etc/init.d/bananarchy-sshd-debug "$TARGET_ROOTFS/etc/runlevels/default/bananarchy-sshd-debug" mkdir -p "$TARGET_ROOTFS/var/lib/tinydm" ln -sf /usr/share/xsessions/sxmo.desktop "$TARGET_ROOTFS/var/lib/tinydm/default-session.desktop" @@ -370,4 +429,24 @@ if [ -f "$TARGET_ROOTFS/boot/extlinux/extlinux.conf" ]; then sed -i "s|^[[:space:]]*fdt .*|\tfdt /$DTB_FILE|" "$TARGET_ROOTFS/boot/extlinux/extlinux.conf" fi +# sshd's StrictModes rejects authorized_keys when $HOME/.ssh is group/world +# writable or the file is owned by the wrong uid. cp -af preserves the source +# modes but not numeric uids, so enforce both after the overlay copy. +chmod 644 "$TARGET_ROOTFS/etc/pam.d/sshd" \ + "$TARGET_ROOTFS/etc/ssh/sshd_config.d/90-bananarchy-access.conf" \ + 2>/dev/null || true +chown 0:0 "$TARGET_ROOTFS/etc/pam.d/sshd" \ + "$TARGET_ROOTFS/etc/ssh/sshd_config.d/90-bananarchy-access.conf" \ + 2>/dev/null || true +for ssh_home in "$TARGET_ROOTFS/etc/skel/.ssh" \ + "$TARGET_ROOTFS/home/user/.ssh" \ + "$TARGET_ROOTFS/root/.ssh"; do + [ -d "$ssh_home" ] || continue + chmod 700 "$ssh_home" + chmod 600 "$ssh_home/authorized_keys" 2>/dev/null || true +done +chown -R 10000:10000 "$TARGET_ROOTFS/home/user/.ssh" 2>/dev/null || true +chown -R 0:0 "$TARGET_ROOTFS/etc/skel/.ssh" "$TARGET_ROOTFS/root/.ssh" \ + 2>/dev/null || true + echo "Bananarchy overlay applied to $TARGET_ROOTFS for device $DEVICE." diff --git a/scripts/build-bananarchy-daemons.sh b/scripts/build-bananarchy-daemons.sh new file mode 100755 index 0000000..ae5771b --- /dev/null +++ b/scripts/build-bananarchy-daemons.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# Build the compiled idle daemons for nokia-beatles and related MSM8909 targets. +set -eu + +BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)" +SRC_DIR="$BASE_DIR/src/bananarchy-daemons" +PREBUILT="$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin" +OVERLAY="$BASE_DIR/overlay/rootfs/usr/bin" +NAMES="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys" + +check_artifacts() { + for name in $NAMES; do + prebuilt="$PREBUILT/$name" + overlay="$OVERLAY/$name" + [ -x "$prebuilt" ] || { + echo "[!] missing compiled daemon: $prebuilt" >&2 + return 1 + } + [ -x "$overlay" ] || { + echo "[!] missing overlay daemon: $overlay" >&2 + return 1 + } + cmp -s "$prebuilt" "$overlay" || { + echo "[!] compiled daemon drift: $name" >&2 + return 1 + } + if [ "$(head -c 4 "$prebuilt" | od -An -tx1 | tr -d ' \n')" != "7f454c46" ]; then + echo "[!] $name is not an ELF binary" >&2 + return 1 + fi + if ! readelf -h "$prebuilt" 2>/dev/null | grep -q 'Machine:.*ARM'; then + echo "[!] $name is not an ARM binary" >&2 + return 1 + fi + done + echo "[ok] compiled idle daemons are ARM ELF binaries and overlay is in sync" +} + +if [ "${1:-}" = "--check" ]; then + check_artifacts + exit 0 +fi + +docker run --rm --network=host \ + -e HOST_UID="$(id -u)" \ + -e HOST_GID="$(id -g)" \ + -v "$BASE_DIR:/bananarchy" \ + alpine:3.24 sh -eu -c ' + cat > /etc/apk/repositories </dev/null + mkdir -p /bananarchy/prebuilt/bananarchy-daemons/usr/bin \ + /bananarchy/overlay/rootfs/usr/bin + for name in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do + armv7-alpine-linux-musleabihf-gcc -std=c11 -O2 -Wall -Wextra -Werror -s \ + -I/bananarchy/src/bananarchy-daemons \ + -o "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \ + "/bananarchy/src/bananarchy-daemons/$name.c" + cp -a "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \ + "/bananarchy/overlay/rootfs/usr/bin/$name" + echo "[+] built $name" + done + chown -R "$HOST_UID:$HOST_GID" \ + /bananarchy/prebuilt/bananarchy-daemons \ + /bananarchy/overlay/rootfs/usr/bin/bananarchy-lid \ + /bananarchy/overlay/rootfs/usr/bin/bananarchy-cover-idle \ + /bananarchy/overlay/rootfs/usr/bin/bananarchy-volume-keys + ' +check_artifacts diff --git a/scripts/build-kernel-audio.sh b/scripts/build-kernel-audio.sh index d662605..1179efb 100755 --- a/scripts/build-kernel-audio.sh +++ b/scripts/build-kernel-audio.sh @@ -131,6 +131,10 @@ EOF KBUILD_MODPOST_WARN=1 M=drivers/power/supply modules make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- -j"$(nproc)" \ KBUILD_MODPOST_WARN=1 M=drivers/net/wireless/ath/wcn36xx modules + make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- -j"$(nproc)" \ + KBUILD_MODPOST_WARN=1 M=drivers/mux modules + make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- -j"$(nproc)" \ + KBUILD_MODPOST_WARN=1 M=drivers/spi modules make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- -j"$(nproc)" \ KBUILD_MODPOST_WARN=1 M=drivers/gpu/drm/msm modules make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- -j"$(nproc)" \ @@ -169,6 +173,8 @@ EOF /bananarchy/prebuilt/kernel-6.12.1-msm8916/netfilter \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/leds \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/mux \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/spi \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/dtbs cp -a sound/soc/qcom/qdsp6/*.ko /bananarchy/prebuilt/kernel-6.12.1-msm8916/qdsp6/ cp -a sound/soc/qcom/snd-soc-qcom-common.ko sound/soc/qcom/snd-soc-apq8016-sbc.ko \ @@ -188,6 +194,10 @@ EOF /bananarchy/prebuilt/kernel-6.12.1-msm8916/leds/ cp -a /bananarchy/src/msm8905-cam/msm8905-cam.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera/ + cp -a drivers/mux/mux-core.ko drivers/mux/mux-gpio.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/mux/ + cp -a drivers/spi/spi-mux.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/spi/ armv7-alpine-linux-musleabihf-strip --strip-unneeded \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/qdsp6/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/qcom/*.ko \ @@ -198,7 +208,9 @@ EOF /bananarchy/prebuilt/kernel-6.12.1-msm8916/drm/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/netfilter/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/leds/*.ko \ - /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera/*.ko + /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera/*.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/mux/*.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/spi/*.ko for ko in \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/qdsp6/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/qcom/*.ko \ @@ -209,14 +221,18 @@ EOF /bananarchy/prebuilt/kernel-6.12.1-msm8916/drm/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/netfilter/*.ko \ /bananarchy/prebuilt/kernel-6.12.1-msm8916/leds/*.ko \ - /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera/*.ko; do + /bananarchy/prebuilt/kernel-6.12.1-msm8916/camera/*.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/mux/*.ko \ + /bananarchy/prebuilt/kernel-6.12.1-msm8916/spi/*.ko; do zstd -f -q -k "$ko" -o "${ko}.zst" done mkdir -p /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/sound/soc/qcom/qdsp6 \ /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/sound/soc/codecs \ /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/bluetooth \ /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/power/supply \ - /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/net/wireless/ath/wcn36xx + /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/net/wireless/ath/wcn36xx \ + /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux \ + /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/spi cp -a /bananarchy/prebuilt/kernel-6.12.1-msm8916/qdsp6/*.ko.zst \ /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/sound/soc/qcom/qdsp6/ cp -a /bananarchy/prebuilt/kernel-6.12.1-msm8916/qcom/*.ko.zst \ @@ -229,6 +245,10 @@ EOF /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/power/supply/ cp -a /bananarchy/prebuilt/kernel-6.12.1-msm8916/wcn36xx/*.ko.zst \ /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/net/wireless/ath/wcn36xx/ + cp -a /bananarchy/prebuilt/kernel-6.12.1-msm8916/mux/*.ko.zst \ + /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/mux/ + cp -a /bananarchy/prebuilt/kernel-6.12.1-msm8916/spi/*.ko.zst \ + /bananarchy/overlay/rootfs/lib/modules/6.12.1-msm8916/kernel/drivers/spi/ make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- \ M=/bananarchy/src/leds-msm8905-torch clean make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- \ diff --git a/scripts/build-lk2nd-beatles.sh b/scripts/build-lk2nd-beatles.sh new file mode 100755 index 0000000..ecc2552 --- /dev/null +++ b/scripts/build-lk2nd-beatles.sh @@ -0,0 +1,154 @@ +#!/bin/sh +# Build the nokia-beatles lk2nd boot images from upstream source. +# +# ./scripts/build-lk2nd-beatles.sh build normal + diagnostic + display +# ./scripts/build-lk2nd-beatles.sh --check validate the shipped images only +# ./scripts/build-lk2nd-beatles.sh --only normal build just one variant +# ./scripts/build-lk2nd-beatles.sh --force-panel-init append lk2nd.force-panel-init to +# the normal image cmdline +# WITH_DISPLAY=1 ./scripts/build-lk2nd-beatles.sh enable the SPI display during boot +# +# Overrides: BANANARCHY_LK2ND_SRC (existing upstream checkout), +# BANANARCHY_LK2ND_BUILD_DIR (scratch), JOBS (make -j). +set -eu + +BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) +UPSTREAM=https://github.com/msm8916-mainline/lk2nd.git +COMMIT=cf45aefd22d744b2bf9b39455afae697ce430063 +PATCH="$BASE_DIR/bootloader/lk2nd/nokia-beatles.patch" +NORMAL_IMAGE="$BASE_DIR/images/boot-lk2nd-nokia-beatles.img" +DIAG_IMAGE="$BASE_DIR/images/boot-lk2nd-nokia-beatles-diagnostic.img" +DISPLAY_IMAGE="$BASE_DIR/images/boot-lk2nd-nokia-beatles-display.img" +DOCKER_IMAGE=bananarchy-lk2nd-build:local +BUILD_DIR=${BANANARCHY_LK2ND_BUILD_DIR:-"$BASE_DIR/.lk2nd-build"} + +CHECK_ONLY=0 +ONLY=all +FORCE_PANEL_INIT=0 +WITH_DISPLAY=${WITH_DISPLAY:-0} +while [ $# -gt 0 ]; do + case "$1" in + --check) CHECK_ONLY=1 ;; + --only) shift; ONLY=${1:-all} ;; + --force-panel-init) FORCE_PANEL_INIT=1 ;; + --with-display) WITH_DISPLAY=1 ;; + *) echo "[!] unknown option: $1" >&2; exit 1 ;; + esac + shift +done + +CMD_BASE="lk2nd lk2nd.compatible=nokia,beatles" +# Default: lk2nd.no-display keeps a RAM-only framebuffer and never touches +# QUP SPI before USB is up. The panel can then be enabled at runtime with +# "fastboot oem display-init", which is safe because all QUP and clock polls +# are bounded. The -display.img variant uses lk2nd.display=on for boot-time +# panel initialization. +if [ "$WITH_DISPLAY" != 1 ]; then + CMD_BASE="$CMD_BASE lk2nd.no-display" +fi +if [ "$FORCE_PANEL_INIT" = 1 ]; then + CMD_BASE="$CMD_BASE lk2nd.force-panel-init" +fi +CMD_DIAG="lk2nd lk2nd.compatible=nokia,beatles lk2nd.no-display" +CMD_DISPLAY="lk2nd lk2nd.compatible=nokia,beatles lk2nd.display=on" + +check_images() { + python3 "$BASE_DIR/scripts/check-lk2nd-beatles.py" \ + --image "$NORMAL_IMAGE" --patch "$PATCH" --expect-fastboot 0 + python3 "$BASE_DIR/scripts/check-lk2nd-beatles.py" \ + --image "$DIAG_IMAGE" --patch "$PATCH" --expect-fastboot 1 + python3 "$BASE_DIR/scripts/check-lk2nd-beatles.py" \ + --image "$DISPLAY_IMAGE" --patch "$PATCH" --expect-fastboot 0 \ + --expect-display 1 --allow-missing-cookie +} + +if [ "$CHECK_ONLY" = 1 ]; then + check_images + exit 0 +fi + +for tool in git docker python3; do + if ! command -v "$tool" >/dev/null 2>&1; then + echo "[!] $tool is required" >&2 + exit 1 + fi +done +if [ ! -f "$PATCH" ]; then + echo "[!] missing $PATCH" >&2 + exit 1 +fi + +if [ -n "${BANANARCHY_LK2ND_SRC:-}" ]; then + SRC=$BANANARCHY_LK2ND_SRC +else + SRC="$BUILD_DIR/src" + mkdir -p "$BUILD_DIR" + if [ ! -d "$SRC/.git" ]; then + git init -q "$SRC" + git -C "$SRC" remote add origin "$UPSTREAM" + fi + head=$(git -C "$SRC" rev-parse HEAD 2>/dev/null || true) + if [ "$head" != "$COMMIT" ]; then + echo "[*] fetching upstream lk2nd at $COMMIT" + git -C "$SRC" fetch --depth 1 origin "$COMMIT" + git -C "$SRC" checkout -q FETCH_HEAD + fi + git -C "$SRC" reset --hard -q HEAD + git -C "$SRC" clean -fdq +fi + +head=$(git -C "$SRC" rev-parse HEAD 2>/dev/null || true) +if [ "$head" != "$COMMIT" ]; then + echo "[!] $SRC is at ${head:-unknown}, expected $COMMIT" >&2 + exit 1 +fi + +if git -C "$SRC" apply --check --reverse "$PATCH" 2>/dev/null; then + echo "[*] nokia-beatles patch already applied" +else + echo "[*] applying nokia-beatles patch" + git -C "$SRC" apply --check "$PATCH" + git -C "$SRC" apply "$PATCH" +fi + +if ! docker image inspect "$DOCKER_IMAGE" >/dev/null 2>&1; then + echo "[*] building the arm-none-eabi toolchain image" + docker build -t "$DOCKER_IMAGE" "$BASE_DIR/bootloader/lk2nd" +fi + +build_variant() { + label=$1 + version=$2 + extra=$3 + cmdline=$4 + out=$5 + echo "[*] building lk2nd-msm8909 ($label)" + # shellcheck disable=SC2086 + docker run --rm --user "$(id -u):$(id -g)" \ + -v "$SRC:/src" -w /src "$DOCKER_IMAGE" \ + make TOOLCHAIN_PREFIX=arm-none-eabi- \ + LK2ND_VERSION="$version" \ + MKBOOTIMG_CMDLINE="$cmdline" \ + $extra -j"${JOBS:-4}" lk2nd-msm8909 + mkdir -p "$(dirname "$out")" + cp "$SRC/build-lk2nd-msm8909/lk2nd.img" "$out" + echo "[*] wrote $out" + sha256sum "$out" +} + +if [ "$ONLY" = all ] || [ "$ONLY" = normal ]; then + build_variant normal bananarchy-beatles-a1109-r3 "" "$CMD_BASE" "$NORMAL_IMAGE" +fi +if [ "$ONLY" = all ] || [ "$ONLY" = diagnostic ]; then + # Forced fastboot + no SPI display: decisive probe when lk2nd hangs before + # USB. Run "fastboot oem display-init" / "oem display-test" from here to + # bring up the GC9305 panel without reflashing; "oem screenshot" verifies + # the framebuffer and "oem scan-dtb" stages the exact kernel DTB. + build_variant diagnostic bananarchy-beatles-a1109-diag-r3 \ + "DEBUG=2 LK2ND_FORCE_FASTBOOT=1" "$CMD_DIAG" "$DIAG_IMAGE" +fi +if [ "$ONLY" = all ] || [ "$ONLY" = display ]; then + build_variant display bananarchy-beatles-a1109-display-r3 "" "$CMD_DISPLAY" "$DISPLAY_IMAGE" +fi + +check_images diff --git a/scripts/busybox-applets.txt b/scripts/busybox-applets.txt new file mode 100644 index 0000000..4214078 --- /dev/null +++ b/scripts/busybox-applets.txt @@ -0,0 +1,95 @@ +arch +ash +base64 +bash +bbconfig +busybox +busybox-extras +cat +chattr +chgrp +chmod +chown +conspy +coreutils +cp +date +dd +df +dmesg +dnsdomainname +dumpkmap +echo +ed +egrep +false +fatattr +fdflush +fgrep +findmnt +fsync +getopt +grep +gunzip +gzip +hostname +ionice +iostat +ipcalc +kill +kmod +link +linux32 +linux64 +ln +login +ls +lsattr +lsblk +lsfd +lzop +makemime +mkdir +mknod +mktemp +more +mount +mountpoint +mpstat +mv +netstat +nice +pidof +ping +ping6 +pipe_progress +pipesz +printenv +ps +pwd +rc-status +red +reformime +rev +rm +rmdir +run-parts +sed +setpriv +setserial +sh +sleep +stat +stty +su +sync +tar +touch +true +udevadm +umount +uname +usleep +watch +wdctl +zcat diff --git a/scripts/busybox-sbin-applets.txt b/scripts/busybox-sbin-applets.txt new file mode 100644 index 0000000..debce75 --- /dev/null +++ b/scripts/busybox-sbin-applets.txt @@ -0,0 +1,33 @@ +acpid +adjtimex +arp +fbsplash +getty +halt +ifconfig +ifenslave +inotifyd +ipaddr +iplink +ipneigh +iproute +iprule +iptunnel +klogd +loadkmap +logread +mdev +nameif +poweroff +raidautorun +reboot +route +setconsole +slattach +sysctl +syslogd +tunctl +udhcpc +vconfig +watchdog +zcip diff --git a/scripts/check-beatles-bootimg.py b/scripts/check-beatles-bootimg.py new file mode 100755 index 0000000..ec2268b --- /dev/null +++ b/scripts/check-beatles-bootimg.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +"""Validate the 2720 Flip boot image before it is flashed over EDL. + +Checks the Android header, the kernel+0x2c appended-DTB pointer, the exact +stock Qualcomm match IDs and the 512 MiB memory fallback inside the DTB. Skips +cleanly when the image has not been built yet, so check-rebuild.sh stays useful +in a fresh clone. +""" + +import os +import struct +import sys + +BOOT_MAGIC = b"ANDROID!" +FDT_MAGIC = 0xd00dfeed +DTB_OFFSET_FIELD = 0x2c +BOOT_PARTITION_BYTES = 26165248 +FDT_BEGIN_NODE = 1 +FDT_END_NODE = 2 +FDT_PROP = 3 +FDT_NOP = 4 +FDT_END = 9 + +STOCK_MSM_ID = struct.pack(">2I", 0x14b, 0) +STOCK_BOARD_ID = struct.pack(">2I", 0x1000b, 0x100) +STOCK_PMIC_ID = struct.pack(">4I", 0x1000d, 0, 0, 0) +MEMORY_512M = struct.pack(">2I", 0x80000000, 0x20000000) + + +def align(value, page): + return (value + page - 1) // page * page + + +def parse_fdt(data): + vals = struct.unpack_from(">10I", data, 0) + magic, totalsize, off_struct, off_strings, off_rsv, version = vals[:6] + size_strings, size_struct = vals[8], vals[9] + if magic != FDT_MAGIC: + raise ValueError("bad FDT magic") + if version not in (16, 17): + raise ValueError("unsupported FDT version %d" % version) + strings = data[off_strings:off_strings + size_strings] + nodes = {} + stack = [] + pos = off_struct + while True: + token = struct.unpack_from(">I", data, pos)[0] + pos += 4 + if token == FDT_BEGIN_NODE: + end = data.index(b"\0", pos) + name = data[pos:end].decode("utf-8", "replace") + pos = (end + 4) & ~3 + if not stack: + path = "/" + elif stack[-1] == "/": + path = "/" + name + else: + path = stack[-1] + "/" + name + stack.append(path) + nodes[stack[-1]] = {} + elif token == FDT_END_NODE: + stack.pop() + if not stack: + break + elif token == FDT_PROP: + length, nameoff = struct.unpack_from(">II", data, pos) + pos += 8 + value = data[pos:pos + length] + pos = (pos + length + 3) & ~3 + end = strings.index(b"\0", nameoff) + prop = strings[nameoff:end].decode("utf-8", "replace") + nodes[stack[-1]][prop] = value + elif token == FDT_NOP: + continue + elif token == FDT_END: + break + else: + raise ValueError("bad FDT token 0x%x" % token) + return nodes, totalsize + + +def main(): + base = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + boot = os.path.join(base, "images", "boot-bananarchy-nokia-beatles.img") + if not os.path.isfile(boot): + print("[skip] 2720 boot image not built yet") + return 0 + data = open(boot, "rb").read() + problems = [] + if data[:8] != BOOT_MAGIC: + problems.append("not an Android boot image") + fields = struct.unpack_from("<8s8I", data, 0) + kernel_size, kernel_addr, ramdisk_size, ramdisk_addr = fields[1:5] + second_size, second_addr, tags_addr, page = fields[5:9] + if page != 2048: + problems.append("page size is %d, expected 2048" % page) + if len(data) > BOOT_PARTITION_BYTES: + problems.append("boot image is larger than the 25 MiB boot partition") + cmdline = data[64:576].split(b"\0")[0].decode("utf-8", "replace") + cmdline_parts = cmdline.split() + if "earlycon" in cmdline_parts: + problems.append("cmdline still contains earlycon") + if "quiet" not in cmdline_parts or "splash" not in cmdline_parts: + problems.append("cmdline is missing 'quiet splash' (Plymouth never starts)") + for flag in ("loglevel=8", "ignore_loglevel", "initcall_debug"): + if flag in cmdline_parts: + problems.append("cmdline still has kernel debug flag %s" % flag) + if kernel_addr != 0x80008000 or ramdisk_addr != 0x81000000 or tags_addr != 0x80000100: + problems.append("boot header load addresses do not match the stock 2720") + kernel_off = page + dtb_rel = struct.unpack_from(" len(dtb): + problems.append("appended DTB is truncated") + root = nodes.get("/", {}) + model = root.get("model", b"").rstrip(b"\0").decode("utf-8", "replace") + if model != "Nokia 2720 Flip": + problems.append("appended DTB model is %r" % model) + for prop, expected in (("qcom,msm-id", STOCK_MSM_ID), + ("qcom,board-id", STOCK_BOARD_ID), + ("qcom,pmic-id", STOCK_PMIC_ID)): + if root.get(prop) != expected: + problems.append("%s does not match the stock 2720 QRD SKUB value" % prop) + mem = None + for path, props in nodes.items(): + if props.get("device_type") == b"memory\0": + mem = props + break + if mem is None: + problems.append("appended DTB has no /memory node") + elif mem.get("reg") != MEMORY_512M: + problems.append("appended DTB /memory:reg is not the 512 MiB fallback") + if ramdisk_size <= 0 or second_size != 0: + problems.append("unexpected ramdisk/second sizes") + if problems: + for problem in problems: + print("FAIL: %s" % problem) + return 1 + print("[ok] 2720 boot image: exact stock IDs, 512 MiB memory fallback, appended DTB pointer") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/check-lk2nd-beatles.py b/scripts/check-lk2nd-beatles.py new file mode 100755 index 0000000..a2449aa --- /dev/null +++ b/scripts/check-lk2nd-beatles.py @@ -0,0 +1,471 @@ +#!/usr/bin/env python3 +"""Validate the source-built nokia-beatles lk2nd boot image. + +The 2720's MSM8905 is a partial-goods (2-core) part. Its stock aboot calls +update_partial_goods_dtb_nodes() on the QCDT-selected DTB and ASSERTs when +/cpus, /cpus/cpu@2 or /cpus/cpu@3 (with a 4-byte device_type) is missing: +"Failed to get parent node: /cpus" then "panic: ASSERT FAILED at +(platform/msm_shared/partial_goods.c:80): 0". Upstream lk2nd DTBs have no +/cpus, so every lk2nd image crashed into Sahara memory-debug EDL before lk2nd +ran. The port adds /cpus to the common dtsi (all QCDT DTBs) plus a compact +/lk2nd/nokia-beatles node in the existing msm8905-qrd-skub DTB. + +Checks (all offline, pure Python): + * Android boot.img header, cmdline and SEANDROIDENFORCE trailer. + * QCDT v2 exact 2720 entry (0x14b / 0x1000b / 0x100 / 0) and the QRD + fallback entry (0x14b / 0xb / 0x100); both must share one DTB. + * Every unique QCDT DTB has /cpus/cpu@2 and /cpus/cpu@3 with a 4-byte + device_type (the partial-goods ASSERT fix). + * The selected DTB's stock root IDs and the beatles device node. + * The beatles device node: model, compatible, match-panel, dtb-files and + all three aboot panel names, with the GC9305 v2 panel init stream. + * The patch and the shared parser header in the repo are in sync. + +Use --emit-streams-header PATH to generate a C array for the host unit test +bootloader/lk2nd/test_spi_panel_init.c. +""" + +import argparse +import os +import struct +import sys + +BOOT_MAGIC = b"ANDROID!" +QCDT_MAGIC = b"QCDT" +FDT_MAGIC = 0xd00dfeed +FDT_BEGIN_NODE = 1 +FDT_END_NODE = 2 +FDT_PROP = 3 +FDT_NOP = 4 +FDT_END = 9 + +STOCK_PLATFORM_ID = 0x14b +STOCK_VARIANT_ID = 0x1000b +STOCK_SUBTYPE = 0x100 +STOCK_SOC_REV = 0 +FALLBACK_VARIANT_ID = 0xb +BOARD_ID = [FALLBACK_VARIANT_ID, STOCK_SUBTYPE, + STOCK_VARIANT_ID, STOCK_SUBTYPE] + +PANEL_NAMES = ( + "qcom,mdss_spi_gc9305_qvga_cmd", + "qcom,mdss_spi_gc9305_v2_qvga_cmd", + "qcom,mdss_spi_gc9305_3rd_qvga_cmd", +) +INIT_PANEL = PANEL_NAMES[1] +EXPECTED_CMDS = 10 + +RGB565 = bytes([0x3a, 0x05]) +COLUMN_WINDOW = bytes([0x2a, 0x00, 0x00, 0x00, 0xef]) +ROW_WINDOW = bytes([0x2b, 0x00, 0x00, 0x01, 0x3f]) + + +def align(value, page): + return (value + page - 1) // page * page + + +def fdt_nodes(data): + vals = struct.unpack_from(">10I", data, 0) + magic, totalsize, off_struct, off_strings, _, version = vals[:6] + size_strings, size_struct = vals[8], vals[9] + if magic != FDT_MAGIC or version not in (16, 17): + raise ValueError("invalid FDT header") + strings = data[off_strings:off_strings + size_strings] + nodes = {} + stack = [] + pos = off_struct + while True: + token = struct.unpack_from(">I", data, pos)[0] + pos += 4 + if token == FDT_BEGIN_NODE: + end = data.index(b"\0", pos) + name = data[pos:end].decode("utf-8", "replace") + pos = (end + 4) & ~3 + if not stack: + path = "/" + elif stack[-1] == "/": + path = "/" + name + else: + path = stack[-1] + "/" + name + stack.append(path) + nodes[path] = {} + elif token == FDT_END_NODE: + stack.pop() + if not stack: + break + elif token == FDT_PROP: + length, nameoff = struct.unpack_from(">II", data, pos) + pos += 8 + value = data[pos:pos + length] + pos = (pos + length + 3) & ~3 + end = strings.index(b"\0", nameoff) + prop = strings[nameoff:end].decode("utf-8", "replace") + nodes[stack[-1]][prop] = value + elif token == FDT_NOP: + continue + elif token == FDT_END: + break + else: + raise ValueError("bad FDT token 0x%x" % token) + return nodes, totalsize + + +def prop_str(nodes, path, prop): + return nodes.get(path, {}).get(prop, b"").rstrip(b"\0").decode("utf-8", "replace") + + +def prop_cells(nodes, path, prop): + raw = nodes.get(path, {}).get(prop, b"") + return list(struct.unpack(">%dI" % (len(raw) // 4), raw[:len(raw) // 4 * 4])) + + +def parse_stream(raw): + """Return (commands, total_delay) or raise ValueError.""" + off = 0 + commands = [] + total_delay = 0 + while off + 2 <= len(raw): + wait, dlen = raw[off], raw[off + 1] + off += 2 + if not dlen or off + dlen > len(raw): + raise ValueError("malformed command at byte %d" % (off - 2)) + payload = raw[off:off + dlen] + off += dlen + commands.append((wait, payload)) + total_delay += wait + if off != len(raw): + raise ValueError("trailing garbage at byte %d" % off) + return commands, total_delay + + +def check_stream(name, raw, problems): + try: + commands, total_delay = parse_stream(raw) + except ValueError as exc: + problems.append("%s panel init stream: %s" % (name, exc)) + return None + if len(commands) != EXPECTED_CMDS: + problems.append("%s panel init has %d commands, expected %d" % + (name, len(commands), EXPECTED_CMDS)) + if total_delay != 120: + problems.append("%s panel init waits %d ms total, expected 120" % + (name, total_delay)) + payloads = [payload for _, payload in commands] + for label, want in (("RGB565 COLMOD", RGB565), + ("240 column window", COLUMN_WINDOW), + ("320 row window", ROW_WINDOW)): + if want not in payloads: + problems.append("%s panel init is missing the %s command" % (name, label)) + if b"\x11" not in payloads: + problems.append("%s panel init is missing sleep-out (0x11)" % name) + if b"\x29" not in payloads: + problems.append("%s panel init is missing display-on (0x29)" % name) + if not payloads or payloads[-1] != b"\x2c": + problems.append("%s panel init does not end with RAMWR (0x2c)" % name) + return commands + + +def check_device_node(nodes, label, problems): + prefix = "%s: " % label + if prop_cells(nodes, "/", "qcom,msm-id")[:2] != [STOCK_PLATFORM_ID, 0]: + problems.append(prefix + "qcom,msm-id is not the stock 0x14b/0") + board = prop_cells(nodes, "/", "qcom,board-id") + if board != BOARD_ID: + problems.append(prefix + "qcom,board-id is %r, expected %r" % (board, BOARD_ID)) + if "/chosen" not in nodes: + problems.append(prefix + "missing /chosen") + if not any(props.get("device_type") == b"memory\0" for props in nodes.values()): + problems.append(prefix + "missing /memory node") + + subnodes = sorted(p for p in nodes if p.startswith("/lk2nd/") and + p.count("/") == 2) + for needed in ("/lk2nd/cat-b35", "/lk2nd/nokia-argon", + "/lk2nd/nokia-beatles"): + if needed not in subnodes: + problems.append(prefix + "missing %s (upstream node lost)" % needed) + + node = "/lk2nd/nokia-beatles" + if node not in nodes: + problems.append(prefix + "missing /lk2nd/nokia-beatles") + return None + props = nodes[node] + if prop_str(nodes, node, "model") != "Nokia 2720 Flip": + problems.append(prefix + "wrong model %r" % prop_str(nodes, node, "model")) + if prop_str(nodes, node, "compatible") != "nokia,beatles": + problems.append(prefix + "wrong compatible %r" % + prop_str(nodes, node, "compatible")) + if "lk2nd,match-panel" not in props: + problems.append(prefix + "beatles node lost lk2nd,match-panel") + if prop_str(nodes, node, "lk2nd,dtb-files") != "msm8905-nokia-beatles": + problems.append(prefix + "wrong lk2nd,dtb-files %r" % + prop_str(nodes, node, "lk2nd,dtb-files")) + + stream = None + for name in PANEL_NAMES: + panel = node + "/panel/" + name + if panel not in nodes: + problems.append(prefix + "missing panel node %s" % name) + continue + if name == INIT_PANEL: + if "lk2nd,panel-init" not in nodes[panel]: + problems.append(prefix + "panel %s has no lk2nd,panel-init" % name) + else: + stream = nodes[panel]["lk2nd,panel-init"] + check_stream(name, stream, problems) + elif "lk2nd,panel-init" in nodes[panel]: + problems.append(prefix + "panel %s must stay compact (no init stream)" % name) + return stream + + +def extract_patch_file(patch_text, path): + """Return the added-file body for a 'new file' diff section.""" + marker = "diff --git a/%s b/%s\n" % (path, path) + start = patch_text.find(marker) + if start < 0: + return None + lines = patch_text[start:].split("\n") + out = [] + started = False + for line in lines[1:]: + if line.startswith("@@"): + started = True + continue + if not started: + continue + if line.startswith("diff --git "): + break + if line.startswith("+"): + out.append(line[1:]) + return "\n".join(out) + "\n" + + +def main(): + base = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--image", default=os.path.join(base, "images", "boot-lk2nd-nokia-beatles.img")) + ap.add_argument("--patch", default=os.path.join(base, "bootloader", "lk2nd", "nokia-beatles.patch")) + ap.add_argument("--emit-streams-header", default=None, + help="write the panel init stream as a C array for the host unit test") + ap.add_argument("--expect-fastboot", type=int, choices=(0, 1), default=0, + help="require (1) or forbid (0) the forced-fastboot diagnostic build") + ap.add_argument("--expect-display", type=int, choices=(0, 1), default=0, + help="require (1) or forbid (0) the boot-time SPI display build") + ap.add_argument("--allow-missing-cookie", action="store_true", + help="allow the known-good display image built before the low-bit reboot cookie") + args = ap.parse_args() + + problems = [] + if not os.path.isfile(args.image): + print("FAIL: missing %s" % args.image) + return 1 + data = open(args.image, "rb").read() + if data[:8] != BOOT_MAGIC: + print("FAIL: %s is not an Android boot image" % args.image) + return 1 + hdr = struct.unpack_from("<8s10I", data, 0) + kernel_size, kernel_addr, ramdisk_size, ramdisk_addr = hdr[1:5] + second_size, second_addr, tags_addr, page = hdr[5:9] + dt_size = hdr[9] + if page != 2048: + problems.append("page size is %d, expected 2048" % page) + if kernel_addr != 0x80008000: + problems.append("kernel load address %#x is not the stock 0x80008000" % kernel_addr) + if dt_size == 0 or dt_size % page != 0: + problems.append("dt_size %d is not a page-multiple QCDT image" % dt_size) + cmdline = data[64:576].split(b"\0")[0].decode("utf-8", "replace") + cmd_parts = cmdline.split(" ") + if cmd_parts[:2] != ["lk2nd", "lk2nd.compatible=nokia,beatles"] or \ + any(p not in ("lk2nd.force-panel-init", "lk2nd.no-display", + "lk2nd.display=on") for p in cmd_parts[2:]): + problems.append("cmdline is %r" % cmdline) + no_display = "lk2nd.no-display" in cmd_parts[2:] + display_on = "lk2nd.display=on" in cmd_parts[2:] + if args.expect_fastboot and not no_display: + problems.append("diagnostic image must carry lk2nd.no-display") + if args.expect_display and not display_on: + problems.append("display image must carry lk2nd.display=on") + if args.expect_display and no_display: + problems.append("display image must not carry lk2nd.no-display") + if not args.expect_display and display_on: + problems.append("non-display image must not carry lk2nd.display=on") + forced_fastboot = b"Fastboot mode was forced with compile-time flag." in data + if forced_fastboot != bool(args.expect_fastboot): + problems.append("fastboot diagnostic marker is %s, expected %s" % + (forced_fastboot, bool(args.expect_fastboot))) + for marker in (b"lk2nd.no-display", b"lk2nd.display=on", + b"oem scan-boot", b"oem display-init", b"oem display-test", + b"oem scan-dtb", b"QUP output FIFO timeout", + b"SPI panel %s: keeping aboot continuous splash", + b"SPI display ready", + b"scan-only: final kernel cmdline/DTB ready", + b"No valid pstore console", + b"SPI panel fallback from QCDT: %s", + b"offset is not block-aligned", + b"aligned read exceeds partition"): + if marker not in data: + problems.append("binary is missing %r" % marker.decode("ascii", "replace")) + if not args.allow_missing_cookie and \ + b"beatles low-bit reboot cookie" not in data: + problems.append("binary is missing b'beatles low-bit reboot cookie'") + if not data.endswith(b"SEANDROIDENFORCE"): + problems.append("missing SEANDROIDENFORCE trailer") + + qcdt_off = (page + align(kernel_size, page) + align(ramdisk_size, page) + + align(second_size, page)) + entries = {} + if data[qcdt_off:qcdt_off + 4] != QCDT_MAGIC: + problems.append("no QCDT table at offset %d" % qcdt_off) + else: + _, version, num_entries = struct.unpack_from("<4sII", data, qcdt_off) + if version != 2: + problems.append("QCDT version is %d, expected 2" % version) + for i in range(num_entries): + off = qcdt_off + 12 + 24 * i + platform_id, variant_id, subtype, soc_rev, dtb_off, dtb_size = \ + struct.unpack_from("<6I", data, off) + if (platform_id == STOCK_PLATFORM_ID and soc_rev == STOCK_SOC_REV and + subtype == STOCK_SUBTYPE and + variant_id in (STOCK_VARIANT_ID, FALLBACK_VARIANT_ID)): + entries[variant_id] = (dtb_off, dtb_size, i) + for variant, label in ((STOCK_VARIANT_ID, "exact 2720"), + (FALLBACK_VARIANT_ID, "QRD fallback")): + if variant not in entries: + problems.append("QCDT has no %s entry" % label) + if len(entries) == 2: + exact, fallback = entries[STOCK_VARIANT_ID], entries[FALLBACK_VARIANT_ID] + if exact[:2] != fallback[:2]: + problems.append("the two 2720 QCDT entries must share the same DTB") + + # Every QCDT DTB must survive aboot's partial-goods DTB patch. + seen_offsets = {} + for i in range(num_entries): + off = qcdt_off + 12 + 24 * i + _, _, _, _, dtb_off, dtb_size = struct.unpack_from("<6I", data, off) + if dtb_off and dtb_size: + seen_offsets.setdefault(dtb_off, dtb_size) + for dtb_off, dtb_size in seen_offsets.items(): + dtb = data[qcdt_off + dtb_off:qcdt_off + dtb_off + dtb_size] + if dtb[:4] != b"\xd0\x0d\xfe\xed": + continue + try: + nodes, _ = fdt_nodes(dtb) + except ValueError: + continue + if "/cpus" not in nodes: + problems.append("QCDT DTB@0x%x lacks /cpus (aboot partial-goods ASSERT)" % + dtb_off) + continue + for cpu in ("cpu@2", "cpu@3"): + path = "/cpus/" + cpu + if path not in nodes: + problems.append("QCDT DTB@0x%x lacks %s" % (dtb_off, path)) + elif nodes[path].get("device_type") != b"cpu\0": + problems.append("QCDT DTB@0x%x %s device_type is %r, expected b'cpu\\0'" % + (dtb_off, path, nodes[path].get("device_type"))) + + stream = None + if STOCK_VARIANT_ID in entries: + dtb_off, dtb_size, _ = entries[STOCK_VARIANT_ID] + dtb = data[qcdt_off + dtb_off:qcdt_off + dtb_off + dtb_size] + if dtb[:4] != b"\xd0\x0d\xfe\xed": + problems.append("2720 DTB is not an FDT") + else: + try: + nodes, totalsize = fdt_nodes(dtb) + if totalsize > dtb_size: + problems.append("2720 DTB is truncated (%d > %d)" % + (totalsize, dtb_size)) + stream = check_device_node(nodes, "2720 DTB", problems) + except ValueError as exc: + problems.append("2720 DTB: %s" % exc) + + # The shared parser header is stored verbatim in the repo for the host test. + header_path = os.path.join(base, "bootloader", "lk2nd", "spi-panel-init.h") + if not os.path.isfile(args.patch): + problems.append("missing source patch %s" % args.patch) + elif not os.path.isfile(header_path): + problems.append("missing %s" % header_path) + else: + patch_text = open(args.patch, "r").read() + want = open(header_path, "r").read() + got = extract_patch_file(patch_text, "lk2nd/include/lk2nd/spi-panel-init.h") + if got != want: + problems.append("bootloader/lk2nd/spi-panel-init.h is out of sync with the patch") + for needed in ( + "app/aboot/aboot.c", + "lk2nd/boot/extlinux.c", + "lk2nd/device/2nd/scan-boot.c", + "lk2nd/device/dts/lk2nd.dtsi", + "lk2nd/device/dts/msm8909/nokia-beatles.dtsi", + "lk2nd/device/dts/msm8909/msm8905-qrd-skub.dts", + "lk2nd/device/2nd/spi-display.c", + "lk2nd/fastboot/fetch.c", + "platform/msm_shared/mdss_spi.c", + "platform/msm_shared/reboot.c", + ): + if "diff --git a/%s b/%s" % (needed, needed) not in patch_text: + problems.append("patch is missing %s" % needed) + if "mdss_spi_panel_init_commands" not in patch_text or \ + "lk2nd,panel-init" not in patch_text: + problems.append("patch is missing the panel initialization code") + if "diff --git a/lk2nd/device/dts/lk2nd.dtsi" not in patch_text: + problems.append("patch is missing the /cpus fix in lk2nd.dtsi") + if "oem scan-boot" not in patch_text: + problems.append("patch is missing the oem scan-boot diagnostic command") + if "diff --git a/lk2nd/ramoops/ramoops.c" not in patch_text: + problems.append("patch is missing the always-on ramoops console fix") + if "scan-only: final kernel cmdline/DTB ready" not in patch_text: + problems.append("patch is missing the final-DTB scan-only hook") + if "No valid pstore console" not in patch_text: + problems.append("patch is missing ramoops console validation") + if "SPI panel fallback from QCDT" not in patch_text: + problems.append("patch is missing the chain-loaded panel fallback") + if "per-word SPEW log" not in patch_text: + problems.append("patch is missing the QUP log flood fix") + if "offset is not block-aligned" not in patch_text: + problems.append("patch is missing the block-safe read-partition guard") + for needed in ( + "diff --git a/platform/msm_shared/spi_qup.c" in patch_text, + "diff --git a/platform/msm_shared/clock_lib2.c" in patch_text, + ): + if not needed: + problems.append("patch is missing a bounded QUP/clock poll") + if "oem display-init" not in patch_text: + problems.append("patch is missing the runtime display probe") + if "lk2nd.display=on" not in patch_text: + problems.append("patch is missing the boot-time display option") + if "platform/msm_shared/reboot.c" not in patch_text or \ + "beatles low-bit reboot cookie" not in patch_text: + problems.append("patch is missing the low-bit lk2nd menu reboot cookie") + + if problems: + for problem in problems: + print("FAIL: %s" % problem) + return 1 + + print("[ok] source-built beatles lk2nd (%s): cmdline=%r, %d bytes, " + "dt_size=%d, both 0x14b entries -> DTB@0x%x" % + ("diagnostic" if args.expect_fastboot else + "display" if args.expect_display else "normal", + cmdline, len(data), dt_size, entries[STOCK_VARIANT_ID][0])) + print("[ok] all %d QCDT DTBs have /cpus/cpu@2 and cpu@3 (partial-goods fix)" % + len(seen_offsets)) + print("[ok] 2720 DTB keeps the upstream board-id order and carries the " + "beatles node with the GC9305 v2 panel init stream") + print("[ok] patch/header in sync") + + if args.emit_streams_header: + out = ["/* generated by scripts/check-lk2nd-beatles.py */", + "#ifndef PANEL_STREAMS_H", "#define PANEL_STREAMS_H", "", + "static const unsigned char stream_v2[] = {"] + for i in range(0, len(stream), 12): + out.append(" " + ", ".join("0x%02x" % x for x in stream[i:i + 12]) + ",") + out += ["};", "", "#endif"] + with open(args.emit_streams_header, "w") as fh: + fh.write("\n".join(out) + "\n") + print("[ok] wrote %s" % args.emit_streams_header) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index fe48f96..2ac46af 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -131,6 +131,545 @@ if ! grep -q '^from Library\.sahara import qualcomm_sahara$' "$BASE_DIR/flash-ed fail "flash-edl.py is missing the Sahara client import" fi +echo "[check] Device-specific EDL Firehose loaders..." +if ! grep -q '^DEVICE_LOADERS = {' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the device-to-loader map" +fi +for dev in nokia-argon nokia-beatles nokia-tough nokia-sparkler nokia-leo; do + if ! grep -q "\"$dev\":" "$BASE_DIR/flash-edl.py"; then + fail "DEVICE_LOADERS is missing $dev" + fi +done +for mbn in 8110.mbn 2720.mbn 2720v.mbn 800t.mbn 8k.mbn; do + if [ ! -s "$BASE_DIR/bootloader/loaders/$mbn" ]; then + fail "missing bootloader/loaders/$mbn" + fi +done +for mapping in \ + '"nokia-beatles": "2720.mbn"' \ + '"nokia-tough": "800t.mbn"' \ + '"nokia-sparkler": "8k.mbn"' \ + '"nokia-leo": "8k.mbn"' \ + '"us": "2720v.mbn"'; do + if ! grep -qF "$mapping" "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py loader mapping lost: $mapping" + fi +done +if ! grep -q '^VARIANT_LOADER_IDENTITIES' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the variant identity map" +fi +if ! grep -q '^EDL_PIDS = ' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the EDL PID auto-detection list" +fi +for edlpid in 9008 900E 9006; do + if ! grep -qi "0x$edlpid" "$BASE_DIR/flash-edl.py"; then + fail "EDL_PIDS is missing 0x$edlpid" + fi +done +if ! grep -q '^BOOT_IMAGE_DEVICES' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the boot-image device list" +fi +if ! grep -q '^BOOT_METHOD_PARTITIONS' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the method-to-partition map" +fi +if ! grep -q '^def resolve_boot_method' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing resolve_boot_method()" +fi +if ! grep -q '^def resolve_wipe_system' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the system wipe guard" +fi +if ! grep -q '^def verify_partition' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the partition read-back verification" +fi +if ! grep -q '^BOOT_METHOD_TARGETS' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the dual boot/recovery target map" +fi +if ! grep -q '^def dump_diagnostics' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the EDL diagnostic partition dump" +fi +if ! grep -q 'return "lk2nd"' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py no longer defaults to the lk2nd boot.img" +fi +if ! grep -q 'if method == "lk2nd" and device == "nokia-beatles":' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py no longer writes lk2nd to both slots on the 2720" +fi +for variant in normal diagnostic display; do + case "$variant" in + normal) + image="$BASE_DIR/images/boot-lk2nd-nokia-beatles.img" + opts="--expect-fastboot 0" + label="source-built nokia-beatles lk2nd" + ;; + diagnostic) + image="$BASE_DIR/images/boot-lk2nd-nokia-beatles-diagnostic.img" + opts="--expect-fastboot 1" + label="nokia-beatles forced-fastboot diagnostic image" + ;; + display) + image="$BASE_DIR/images/boot-lk2nd-nokia-beatles-display.img" + opts="--expect-fastboot 0 --expect-display 1 --allow-missing-cookie" + label="nokia-beatles known-good display lk2nd image" + ;; + esac + if [ ! -f "$image" ]; then + echo "[skip] local build output ${image#"$BASE_DIR/"} is absent; prepare-release.sh will rebuild it" + continue + fi + # shellcheck disable=SC2086 + if ! python3 "$BASE_DIR/scripts/check-lk2nd-beatles.py" \ + --image "$image" $opts; then + fail "$label validation failed" + fi +done +if ! grep -qF 'BEATLES_LK2ND_IMAGE = "images/boot-lk2nd-nokia-beatles-display.img"' \ + "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py no longer defaults to the display-enabled lk2nd image" +fi +if ! grep -qF 'target_names = ("boot", "recovery", "lk2nd")' \ + "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py no longer refreshes the separate lk2nd partition" +fi +for f in bootloader/lk2nd/nokia-beatles.patch \ + bootloader/lk2nd/README.md \ + bootloader/lk2nd/spi-panel-init.h \ + bootloader/lk2nd/Dockerfile \ + scripts/build-lk2nd-beatles.sh \ + scripts/test-lk2nd-beatles-port.py; do + if [ ! -f "$BASE_DIR/$f" ]; then + fail "missing nokia-beatles lk2nd port file: $f" + fi +done +if [ -f "$BASE_DIR/scripts/make-beatles-lk2nd-bootimg.py" ]; then + fail "obsolete binary-patch lk2nd script is still present" +fi +if grep -q 'target_parts\[0\]\[1\]' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py still writes only the first lk2nd target slot" +fi +if ! grep -q 'write_partition(fh, args.lun, part, source)' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py lost the multi-target write loop" +fi +if ! grep -q 'def source_for(name):' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py lost the Argon-shaped hybrid per-slot source" +fi +if [ ! -f "$BASE_DIR/scripts/dump-edl-crash.py" ]; then + fail "missing scripts/dump-edl-crash.py" +fi +if ! grep -q '^UNLOCK_DEFAULT_DEVICES' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the locked-bootloader unlock default" +fi +if ! grep -q '^def unlock_devinfo' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the devinfo unlock helper" +fi +if ! grep -q '^OEM_UNLOCK_PARTITIONS' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the RPMB unlock prerequisite map" +fi +if ! grep -q '^def enable_oem_unlock' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py is missing the config/frp OEM unlock helper" +fi +if [ ! -f "$BASE_DIR/scripts/make-oem-unlock-config.py" ]; then + fail "missing scripts/make-oem-unlock-config.py" +fi +if [ ! -f "$BASE_DIR/scripts/make-unlocked-devinfo.py" ]; then + fail "missing scripts/make-unlocked-devinfo.py" +fi +if ! grep -q 'boot-bananarchy-\$TARGET_DEVICE.img' "$BASE_DIR/rebuild-image.sh"; then + fail "rebuild-image.sh no longer exports a standalone boot.img" +fi +if [ ! -L "$BASE_DIR/overlay/rootfs/sbin/init" ] || \ + [ "$(readlink "$BASE_DIR/overlay/rootfs/sbin/init")" != "/bin/busybox" ]; then + fail "overlay/rootfs/sbin/init is no longer a /bin/busybox symlink" +fi +for cmdline_file in "$BASE_DIR"/devices/*/kernel-cmdline.conf \ + "$BASE_DIR"/overlay/rootfs/usr/lib/kernel-cmdline.d/50-device-*.conf; do + if grep -qxF 'earlycon' "$cmdline_file"; then + fail "$(basename "$cmdline_file") still contains earlycon" + fi +done +# A pre-existing rootfs/ build tree is reused by rebuild-image.sh, so its +# copies of the device cmdline fragments must stay in sync with the overlay. +for cmdline_file in "$BASE_DIR"/rootfs/usr/lib/kernel-cmdline.d/50-device-*.conf; do + [ -f "$cmdline_file" ] || continue + if grep -qxF 'earlycon' "$cmdline_file"; then + fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains earlycon" + fi +done + +echo "[check] BusyBox applet symlinks..." +APPLET_LIST="$BASE_DIR/scripts/busybox-applets.txt" +if [ ! -f "$APPLET_LIST" ]; then + fail "missing scripts/busybox-applets.txt" +fi +for applet in ash grep sed ps; do + if ! grep -qxF "$applet" "$APPLET_LIST"; then + fail "scripts/busybox-applets.txt is missing $applet" + fi +done +if ! grep -q 'busybox-applets.txt' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "the overlay no longer restores missing BusyBox applet symlinks" +fi +# The shipped rootfs is validated by scripts/sync-beatles-bootfs.py --check +# and by an explicit image build; the overlay script above is the source of +# truth for the applet symlinks, so avoid extracting a 1.3 GiB partition here. +RAW_IMAGE="$BASE_DIR/images/bananarchy-nokia-beatles.img" +if [ -f "$RAW_IMAGE" ] && [ "$(stat -c %s "$RAW_IMAGE")" -lt 1000000000 ]; then + fail "the shipped raw image is truncated" +fi + +echo "[check] Known-good flashable image set..." +for pair in \ + "b4d0555f17dd1e224069641603ff3d120fd3ea5c219a34de227caf240a077558 images/bananarchy-nokia-argon.img" \ + "e2267187c58920b5c5b822d940b81e0df8f59e7788fed00e3d31dfbdb290c7fc images/bananarchy-nokia-beatles.img" \ + "6715abd414fd02fd21ca8c2cd621a8a21e78f46d079b2d185b38a1f7a4a3e659 images/boot-bananarchy-nokia-beatles.img" \ + "e1fdd8551b6393184a465638881b63ca58c04e1e8f655f092260a18379e1cbe6 images/boot-lk2nd-nokia-beatles-display.img"; do + set -- $pair + want=$1 + path="$BASE_DIR/$2" + if [ ! -f "$path" ]; then + echo "[skip] local build output $2 is absent; prepare-release.sh will rebuild it" + continue + elif [ "$(sha256sum "$path" | cut -d' ' -f1)" != "$want" ]; then + fail "$2 no longer matches the physically verified known-good image" + fi +done + +echo "[check] Compiled idle daemons..." +DAEMONS="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys" +for daemon in $DAEMONS; do + for artifact in "prebuilt/bananarchy-daemons/usr/bin/$daemon" \ + "overlay/rootfs/usr/bin/$daemon"; do + path="$BASE_DIR/$artifact" + if [ ! -x "$path" ]; then + fail "missing compiled daemon: $artifact" + continue + fi + if [ "$(head -c 4 "$path" | od -An -tx1 | tr -d ' \n')" != "7f454c46" ] || \ + ! readelf -h "$path" 2>/dev/null | grep -q 'Machine:.*ARM'; then + fail "$artifact is not an ARM ELF binary" + fi + done + if ! cmp -s "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$daemon" \ + "$BASE_DIR/overlay/rootfs/usr/bin/$daemon"; then + fail "compiled daemon drift: $daemon" + fi +done +if ! "$BASE_DIR/scripts/build-bananarchy-daemons.sh" --check >/dev/null 2>&1; then + fail "compiled idle daemon build check failed" +fi +for src in src/bananarchy-daemons/common.h \ + src/bananarchy-daemons/bananarchy-lid.c \ + src/bananarchy-daemons/bananarchy-cover-idle.c \ + src/bananarchy-daemons/bananarchy-volume-keys.c; do + if [ ! -f "$BASE_DIR/$src" ]; then + fail "missing C daemon source: $src" + fi +done +if ! grep -q 'CLOSED_MASK' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \ + ! grep -q 'sxmo_state.sh' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \ + ! grep -q 'strcmp(level, "low")' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c"; then + fail "the compiled lid daemon lost its raw hall GPIO fallback" +fi +if ! grep -q 'SOCK_DGRAM' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \ + ! grep -q 'STATUS' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"; then + fail "the compiled cover daemon lost the coverctl protocol" +fi +if grep -qF 'mmap(' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \ + ! grep -qF 'write_all' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \ + ! grep -qF 'fb_geometry' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"; then + fail "the cover renderer lost the 32-bpp fbdev write() path" +fi +if ! grep -q 'flock' "$BASE_DIR/src/bananarchy-daemons/common.h" || \ + ! grep -q 'prune_devices' "$BASE_DIR/src/bananarchy-daemons/common.h" || \ + ! grep -q 'setuid(SESSION_UID)' "$BASE_DIR/src/bananarchy-daemons/common.h" || \ + ! grep -q 'KEY_VOLUMEUP' "$BASE_DIR/src/bananarchy-daemons/common.h"; then + fail "the compiled daemons lost singleton/stale-fd/privilege guards" +fi +if grep -RInE "bananarchy-(lid|cover-idle|volume-keys)\.py" \ + "$BASE_DIR/overlay/rootfs/etc/init.d" "$BASE_DIR/src/bananarchy-daemons" \ + >/dev/null 2>&1; then + fail "a Python daemon reference remains in the idle service wiring" +fi +for stale in overlay/rootfs/usr/bin/bananarchy-lid.py \ + overlay/rootfs/usr/bin/bananarchy-cover-idle.py \ + overlay/rootfs/usr/bin/bananarchy-volume-keys.py \ + rootfs/usr/bin/bananarchy-lid.py \ + rootfs/usr/bin/bananarchy-cover-idle.py \ + rootfs/usr/bin/bananarchy-volume-keys.py; do + if [ -e "$BASE_DIR/$stale" ] || [ -L "$BASE_DIR/$stale" ]; then + fail "retired Python daemon still present: $stale" + fi +done +for svc in bananarchy-lid bananarchy-cover-display bananarchy-volume-keys; do + case "$svc" in + bananarchy-lid) want='command="/usr/bin/bananarchy-lid"' ;; + bananarchy-cover-display) want='command="/usr/bin/bananarchy-cover-idle"' ;; + bananarchy-volume-keys) want='command="/usr/bin/bananarchy-volume-keys"' ;; + esac + if ! grep -qF "$want" "$BASE_DIR/overlay/rootfs/etc/init.d/$svc"; then + fail "$svc does not start its compiled daemon" + fi +done +if ! grep -qF 'xset r rate 180 30' \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh"; then + fail "the X session no longer lowers keypad auto-repeat delay" +fi +for hook in overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh \ + overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh \ + overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh; do + if ! grep -qF 'superctl stop sxmo_networkmonitor' "$BASE_DIR/$hook" || \ + ! grep -qF 'bananarchy_kill_matches "nmcli device monitor"' "$BASE_DIR/$hook"; then + fail "$hook no longer stops the nmcli device monitor poller" + fi +done + +echo "[check] Camera, volume keys and cover spidev wiring..." +HW_MODULES="$BASE_DIR/overlay/rootfs/etc/modules-load.d/bananarchy-hardware.conf" +if [ ! -f "$HW_MODULES" ] || ! grep -q '^msm8905-cam' "$HW_MODULES"; then + fail "the camera driver is no longer loaded at boot" +fi +if ! grep -q 'msm8905-cam' "$BASE_DIR/overlay/rootfs/etc/local.d/10-bananarchy-hardware.start"; then + fail "the local.d hardware fallback no longer loads the camera driver" +fi +if [ ! -f "$BASE_DIR/scripts/busybox-sbin-applets.txt" ] || \ + ! grep -qxF 'reboot' "$BASE_DIR/scripts/busybox-sbin-applets.txt"; then + fail "the /sbin BusyBox applet list is missing reboot (Sxmo power menu)" +fi +if ! grep -q 'busybox-sbin-applets.txt' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "the overlay no longer restores /sbin BusyBox applets" +fi +if ! grep -qF 'rm -f "$TARGET_ROOTFS/bin/$applet"' \ + "$BASE_DIR/scripts/apply-bananarchy-overlay.sh" || \ + ! grep -qF 'rm -f "$TARGET_ROOTFS/sbin/$applet"' \ + "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "the overlay no longer repairs dangling BusyBox applet symlinks" +fi +if ! grep -q 'bananarchy_set_sink_volume' "$BASE_DIR/overlay/rootfs/usr/bin/sxmo_audio.sh"; then + fail "sxmo_audio.sh no longer mirrors volume into the PipeWire sink" +fi +if ! grep -q 'bananarchy_vol_debounce' "$BASE_DIR/overlay/rootfs/usr/bin/sxmo_audio.sh"; then + fail "double volume steps are no longer debounced" +fi +if ! grep -q 'poll(fds' "$BASE_DIR/src/bananarchy-daemons/bananarchy-volume-keys.c" || \ + ! grep -q 'drop_device' "$BASE_DIR/src/bananarchy-daemons/bananarchy-volume-keys.c"; then + fail "the compiled volume daemon lost its stale-fd pruning" +fi +if grep -q '/usr/bin/su' "$BASE_DIR/src/bananarchy-daemons/"*.c; then + fail "the compiled daemons still call the nonexistent /usr/bin/su" +fi +if ! grep -q 'proc/uptime' "$BASE_DIR/overlay/rootfs/usr/bin/sxmo_audio.sh"; then + fail "the volume debounce is no longer timestamp based" +fi +if ! grep -q 'bananarchy-volume-keys' "$BASE_DIR/overlay/rootfs/etc/init.d/bananarchy-volume-keys"; then + fail "the volume-key service is missing" +fi +if ! grep -q 'spidev@1' "$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" || \ + ! dtc -I dtb -O dts "$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb" 2>/dev/null | \ + grep -q 'spidev@1'; then + fail "the cover panel spidev@1 node is missing from the shipping DTS/DTB" +fi +if ! grep -q '^dc_gpio = -1' "$BASE_DIR/overlay/rootfs/etc/bananarchy/cover-display.conf"; then + fail "the cover daemon config would collide with the internal panel DC GPIO" +fi + +echo "[check] USB SSH access and boot splash..." +PAM_SSHD="$BASE_DIR/overlay/rootfs/etc/pam.d/sshd" +SSHD_ACCESS="$BASE_DIR/overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf" +if [ ! -f "$PAM_SSHD" ] || ! grep -q 'pam_unix.so' "$PAM_SSHD"; then + fail "overlay/rootfs/etc/pam.d/sshd is missing (UsePAM yes cannot authenticate)" +fi +if [ ! -f "$SSHD_ACCESS" ] || \ + ! grep -q '^PasswordAuthentication yes' "$SSHD_ACCESS" || \ + ! grep -q '^KbdInteractiveAuthentication yes' "$SSHD_ACCESS"; then + fail "sshd access drop-in no longer enables password authentication" +fi +for ak in "$BASE_DIR"/overlay/rootfs/etc/skel/.ssh/authorized_keys \ + "$BASE_DIR"/overlay/rootfs/home/user/.ssh/authorized_keys \ + "$BASE_DIR"/overlay/rootfs/root/.ssh/authorized_keys; do + if [ ! -f "$ak" ] || ! cmp -s "$ak" "$BASE_DIR/keys/phone_id_ed25519.pub"; then + fail "${ak#$BASE_DIR/} no longer carries the phone SSH key" + fi +done +if ! grep -q 'chmod 700 "$ssh_home"' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh" || \ + ! grep -q 'chown -R 10000:10000' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "the overlay no longer fixes authorized_keys ownership/modes" +fi +if ! grep -q 'SSHD_BINARY="/usr/sbin/sshd.pam"' "$BASE_DIR/overlay/rootfs/etc/conf.d/sshd"; then + fail "the PAM-enabled sshd binary is no longer pinned" +fi +if ! grep -q '^ListenAddress 172.16.42.1:2222' "$BASE_DIR/overlay/rootfs/etc/ssh/sshd_config_debug" || \ + grep -qE '^[[:space:]]*UsePAM' "$BASE_DIR/overlay/rootfs/etc/ssh/sshd_config_debug"; then + fail "the USB-only fallback sshd config is no longer PAM-free and USB-only" +fi +if ! grep -q 'def release_cmdline' "$BASE_DIR/scripts/sync-beatles-bootfs.py" || \ + ! grep -q "missing 'quiet splash'" "$BASE_DIR/scripts/sync-beatles-bootfs.py"; then + fail "sync-beatles-bootfs.py no longer restores/guards the quiet splash cmdline" +fi +if ! grep -q "Plymouth never starts" "$BASE_DIR/scripts/check-beatles-bootimg.py"; then + fail "check-beatles-bootimg.py no longer guards the splash cmdline" +fi + +echo "[check] 2720 Flip keypad and cover display support..." +for f in overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules \ + overlay/rootfs/usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf \ + overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh \ + overlay/rootfs/usr/bin/bananarchy-coverd \ + overlay/rootfs/usr/bin/bananarchy-cover-msg \ + overlay/rootfs/etc/init.d/bananarchy-cover-display \ + overlay/rootfs/etc/bananarchy/cover-display.conf \ + devices/nokia-beatles/cover-panel.dtsi \ + devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin \ + devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.txt; do + if [ ! -f "$BASE_DIR/$f" ]; then + fail "missing $f" + fi +done +if ! grep -q 'MatchProduct "keypad"' \ + "$BASE_DIR/overlay/rootfs/usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf"; then + fail "the keypad Xorg InputClass lost its explicit MatchProduct" +fi +if ! grep -q 'ID_INPUT_KEYBOARD' \ + "$BASE_DIR/overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules"; then + fail "the keypad udev rule no longer forces ID_INPUT_KEYBOARD" +fi +if ! grep -q 'TAG+="seat"' \ + "$BASE_DIR/overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules"; then + fail "the input seat udev rule no longer tags event nodes for elogind" +fi +if [ "$(head -c 4 "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-coverd" | od -An -tx1 | tr -d ' \n')" != "7f454c46" ]; then + fail "bananarchy-coverd is no longer the compiled armv7 daemon" +fi +if ! cmp -s "$BASE_DIR/prebuilt/bananarchy-coverd/usr/bin/bananarchy-coverd" \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-coverd"; then + fail "the cover daemon binary drifted from prebuilt/" +fi +if ! grep -q 'lid-profile' "$BASE_DIR/overlay/rootfs/etc/init.d/bananarchy-cover-display"; then + fail "the flip-device cover service lost its lid-profile gate" +fi +COVER_SCRATCH="/tmp/bantam/9064bb701d9e9f7c6412f0ea6846d88a" +COVER_DTBO="$COVER_SCRATCH/cover-panel-check.dtbo" +COVER_DTS="$COVER_SCRATCH/beatles-cover-check.dts" +COVER_DTS_BUILD="$COVER_SCRATCH/beatles-dts-check.dtb" +BEATLES_DTB="$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dtb" +BEATLES_DTS="$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" +mkdir -p "$COVER_SCRATCH" +if ! dtc -@ -I dts -O dtb -o "$COVER_DTBO" \ + "$BASE_DIR/devices/nokia-beatles/cover-panel.dtsi" >/dev/null 2>&1; then + fail "devices/nokia-beatles/cover-panel.dtsi does not compile" +fi +if ! dtc -I dts -O dtb -o "$COVER_DTS_BUILD" "$BEATLES_DTS" >/dev/null 2>&1; then + fail "the shipping beatles DTS does not compile" +fi +if ! cmp -s "$COVER_DTS_BUILD" "$BEATLES_DTB"; then + fail "the shipping beatles DTB drifted from its DTS source" +fi +if ! dtc -I dtb -O dts -o "$COVER_DTS" "$BEATLES_DTB" >/dev/null 2>&1; then + fail "the shipping beatles DTB cannot be decompiled" +fi +for token in 'qcom,msm-id = <0x14b 0x00>;' \ + 'qcom,board-id = <0x1000b 0x100>;' \ + 'qcom,pmic-id = <0x1000d 0x00 0x00 0x00>;'; do + if ! grep -qF "$token" "$COVER_DTS"; then + fail "the shipping beatles DTB lost a stock Qualcomm ID ($token)" + fi +done +if grep -qF 'compatible = "spi-mux"' "$COVER_DTS" || \ + grep -qF 'compatible = "gpio-mux"' "$COVER_DTS"; then + fail "the shipping beatles DTB still applies the hardware-gated cover overlay" +fi +if ! grep -A4 'spidev@1 {' "$COVER_DTS" | grep -qF 'status = "okay"'; then + fail "the shipping beatles DTB lost the spidev@1 diagnostic fallback" +fi +rm -f "$COVER_DTBO" "$COVER_DTS" "$COVER_DTS_BUILD" +for opt in CONFIG_MULTIPLEXER=m CONFIG_MUX_GPIO=m CONFIG_SPI_MUX=m; do + if ! grep -qxF "$opt" "$BASE_DIR/patches/kernel/config-bananarchy-msm8909.armv7"; then + fail "kernel config is missing $opt (cover panel spi-mux)" + fi +done + +echo "[check] 2720 Flip appended DTB..." + + +BEATLES_DTS="$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" +if ! grep -qF 'qcom,msm-id = <0x14b 0x00>;' "$BEATLES_DTS"; then + fail "nokia-beatles DTS lost the stock MSM8905 msm-id" +fi +if ! grep -qF 'qcom,board-id = <0x1000b 0x100>;' "$BEATLES_DTS"; then + fail "nokia-beatles DTS lost the exact stock QRD SKUB board-id" +fi +if ! grep -qF 'qcom,pmic-id = <0x1000d 0x00 0x00 0x00>;' "$BEATLES_DTS"; then + fail "nokia-beatles DTS lost the stock pmic-id" +fi +if ! grep -qF 'reg = <0x80000000 0x20000000>;' "$BEATLES_DTS"; then + fail "nokia-beatles DTS lost the 512 MiB memory fallback" +fi +if [ -f "$BASE_DIR/images/boot-bananarchy-nokia-beatles.img" ]; then + if ! python3 "$BASE_DIR/scripts/check-beatles-bootimg.py"; then + fail "2720 boot image validation failed" + fi +else + echo "[skip] local build output images/boot-bananarchy-nokia-beatles.img is absent; prepare-release.sh will rebuild it" +fi +if [ -f "$BASE_DIR/images/bananarchy-nokia-beatles.img" ]; then + if ! python3 "$BASE_DIR/scripts/sync-beatles-bootfs.py" --check --raw-image "$BASE_DIR/images/bananarchy-nokia-beatles.img"; then + fail "2720 raw image pmOS_boot filesystem is damaged or stale" + fi +else + echo "[skip] local build output images/bananarchy-nokia-beatles.img is absent; prepare-release.sh will rebuild it" +fi + +echo "[check] Release hygiene..." +KCONFIG="$BASE_DIR/patches/kernel/config-bananarchy-msm8909.armv7" +for cfg in "$KCONFIG" \ + "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/kernel-config" \ + "$BASE_DIR/overlay/rootfs/boot/config"; do + if grep -qE '^CONFIG_PSTORE_BLK(_[A-Z0-9_]+)?=' "$cfg" 2>/dev/null || \ + grep -qx 'CONFIG_PSTORE_ZONE=y' "$cfg" 2>/dev/null || \ + ! grep -qxF '# CONFIG_PSTORE_BLK is not set' "$cfg"; then + fail "${cfg#"$BASE_DIR/"} still carries the abandoned pstore_blk diagnostic config" + fi +done +for sysmap in "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" \ + "$BASE_DIR/overlay/rootfs/boot/System.map"; do + if grep -q 'pstore_blk_get_config' "$sysmap"; then + fail "${sysmap#"$BASE_DIR/"} was built with pstore_blk" + fi +done +for art in prebuilt/kernel-6.12.1-msm8916/mux/mux-core.ko.zst \ + prebuilt/kernel-6.12.1-msm8916/mux/mux-gpio.ko.zst \ + prebuilt/kernel-6.12.1-msm8916/spi/spi-mux.ko.zst; do + if [ ! -f "$BASE_DIR/$art" ]; then + fail "missing built spi-mux module: $art" + fi +done +if ! grep -q 'M=drivers/mux modules' "$BASE_DIR/scripts/build-kernel-audio.sh" || \ + ! grep -q 'M=drivers/spi modules' "$BASE_DIR/scripts/build-kernel-audio.sh"; then + fail "build-kernel-audio.sh no longer builds the spi-mux modules" +fi +for mod in mux-core mux-gpio spi-mux; do + if ! grep -qxF "$mod" "$BASE_DIR/overlay/rootfs/etc/modules-load.d/bananarchy-hardware.conf"; then + fail "modules-load.d is missing $mod" + fi +done +if ! grep -q 'PON_SOFT_RB_SPARE.*0x02U' "$BASE_DIR/src/leds-msm8905-torch/leds-msm8905-torch.c"; then + fail "the torch reboot cookie no longer selects the lk2nd Fastboot menu" +fi +for stale in images/boot-bananarchy-nokia-beatles-debug.img \ + images/boot-bananarchy-nokia-beatles-ramoops.img; do + if [ -f "$BASE_DIR/$stale" ]; then + fail "stale diagnostic boot image is still present: $stale" + fi +done + +LK2ND_PATCH="$BASE_DIR/bootloader/lk2nd/nokia-beatles.patch" +if ! grep -qF 'platform/msm_shared/reboot.c' "$LK2ND_PATCH" || \ + ! grep -qF 'beatles low-bit reboot cookie' "$LK2ND_PATCH"; then + fail "lk2nd patch is missing the low-bit Fastboot menu reboot cookie" +fi + +if grep -q -- '--debug-boot' "$BASE_DIR/flash-edl.py" || \ + grep -q 'resolve_beatles_debug_boot_image' "$BASE_DIR/flash-edl.py"; then + fail "flash-edl.py still references the abandoned debug boot image" +fi + echo "[check] Plugin artifacts..." for source in "$BASE_DIR"/src/dwm-plugins/*_plugin.cpp; do name="$(basename "$source" _plugin.cpp)" @@ -233,6 +772,84 @@ if [ "$FOCUS_CALLS" -lt 2 ]; then fail "link focus and wrap toggle must both call ensureFocusedLinkVisible" fi +echo "[check] Flip lid responsiveness..." +LID_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" +for token in '#define LID_STABLE_MS 80' 'BA_EVIOCGSW' 'LID_STATE_FILE' \ + 'LOCKER_FIFO' 'unlink(LOCK_FLAG)'; do + if ! grep -qF "$token" "$LID_SRC"; then + fail "the compiled lid daemon lost the low-latency EV_SW/unlock path ($token)" + fi +done +if grep -qF 'closed != was_closed' "$LID_SRC" || \ + grep -qF '#define LID_STABLE_MS 600' "$LID_SRC"; then + fail "the compiled lid daemon still accepts slow immediate hall transitions" +fi + +echo "[check] Fast X startup and boot keypad state..." +if ! grep -q '^rc_parallel="YES"' "$BASE_DIR/overlay/rootfs/etc/rc.conf"; then + fail "OpenRC parallel startup is disabled" +fi +if grep -qF 'after *' "$BASE_DIR/overlay/rootfs/etc/init.d/local"; then + fail "the local service still deadlocks with parallel startup via 'after *'" +fi +if ! grep -q '^udev_settle_timeout=2' \ + "$BASE_DIR/overlay/rootfs/etc/conf.d/udev-settle"; then + fail "udev-settle can still hold X startup behind missing modem firmware" +fi +if ! grep -qF '/run/bananarchy/lid-state' \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh"; then + fail "X no longer uses the debounced lid state at boot" +fi +if ! grep -qF 'Keep the first 10 s of an open-lid boot unlocked' \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh"; then + fail "X lost the open-lid boot unlock guard against transient xlocker state" +fi +if ! grep -qF 'dwm-plugin dmenu close' \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh" || \ + ! grep -qF 'xdotool key --clearmodifiers Escape' \ + "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh"; then + fail "X lost the one-shot stale startup keyboard grab cleanup" +fi +if ! grep -qF 'before bananarchy-cover-display tinydm' \ + "$BASE_DIR/overlay/rootfs/etc/init.d/bananarchy-lid"; then + fail "the lid daemon no longer starts before tinydm" +fi +for f in etc/rc.conf etc/conf.d/udev-settle \ + usr/bin/bananarchy-x11-session.sh etc/init.d/bananarchy-lid \ + etc/init.d/bananarchy-sshd-debug etc/init.d/local \ + etc/local.d/20-bananarchy-sshd-debug.start; do + if ! cmp -s "$BASE_DIR/overlay/rootfs/$f" "$BASE_DIR/rootfs/$f"; then + fail "live rootfs copy drifted from overlay: $f" + fi +done +if [ ! -L "$BASE_DIR/overlay/rootfs/etc/runlevels/default/bananarchy-sshd-debug" ]; then + fail "the USB diagnostic sshd is missing from the default runlevel" +fi +if ! grep -qF 'rc-service bananarchy-sshd-debug status' \ + "$BASE_DIR/overlay/rootfs/etc/local.d/20-bananarchy-sshd-debug.start" || \ + ! grep -qF 'ln -sf /etc/init.d/bananarchy-sshd-debug' \ + "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "the USB diagnostic sshd fallback is not independently started" +fi +if ! grep -qF 'cmd == "CLOSE" || cmd == "UNLOCK"' \ + "$BASE_DIR/src/dwm-plugins/locker_plugin.cpp" || \ + ! grep -qF 'unlockPhone(false);' \ + "$BASE_DIR/src/dwm-plugins/locker_plugin.cpp"; then + fail "locker.so no longer releases a stale grab on a trusted lid-open CLOSE" +fi + +echo "[check] Known-good keypad wake guard..." +if ! grep -qF 'last_wake_ms) < 350' "$BASE_DIR/src/sxmo-dwm/dwm.c" || \ + grep -qF 'WAKE_KEY_DEBOUNCE_MS' "$BASE_DIR/src/sxmo-dwm/dwm.c"; then + fail "dwm no longer uses the known-good 350 ms wake guard" +fi +if ! grep -qF 'writeSoftkeySuppress(nowMs() + 120)' \ + "$BASE_DIR/src/dwm-plugins/locker_plugin.cpp" || \ + grep -qF 'lockActivatedMs < 80' \ + "$BASE_DIR/src/dwm-plugins/locker_plugin.cpp"; then + fail "locker still suppresses unlock keypad input too long" +fi + echo "[check] Status bar clock freshness..." DMENU_SRC="$BASE_DIR/src/sxmo-dmenu/dmenu.c" UNLOCK_HOOK="$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh" @@ -265,7 +882,8 @@ for f in "$NET_EVENT" "$NET_DISPATCH"; do fi done for hook in "$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh" \ - "$BASE_DIR/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh"; do + "$BASE_DIR/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh" \ + "$BASE_DIR/overlay/rootfs/home/user/.config/sxmo/hooks/sxmo_hook_start.sh"; do if grep -q 'superctl start sxmo_networkmonitor' "$hook"; then fail "${hook#$BASE_DIR/} still starts the nmcli device monitor poller" fi @@ -369,8 +987,12 @@ if ! command -v docker >/dev/null 2>&1; then fi echo "[check] Version helper..." -VERSION="$("$BASE_DIR/scripts/version.sh" --print 2>/dev/null || true)" -CODENAME="$("$BASE_DIR/scripts/version.sh" --print-codename 2>/dev/null || true)" +# Pin the release under test so the check does not break when the wall clock +# rolls past the release date (version.sh otherwise derives it from today). +VERSION="$(BANANARCHY_VERSION=a1108 BANANARCHY_CODENAME=dejavu \ + "$BASE_DIR/scripts/version.sh" --print 2>/dev/null || true)" +CODENAME="$(BANANARCHY_VERSION=a1108 BANANARCHY_CODENAME=dejavu \ + "$BASE_DIR/scripts/version.sh" --print-codename 2>/dev/null || true)" if [ "$VERSION" != "a1108" ]; then fail "scripts/version.sh --print must return a1108" fi diff --git a/scripts/dump-edl-crash.py b/scripts/dump-edl-crash.py new file mode 100755 index 0000000..a5fc6d4 --- /dev/null +++ b/scripts/dump-edl-crash.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 +"""Dump Sahara memory-debug regions from a crashed 2720 over EDL. + +No stock fastboot is needed. Power-cycle the phone into 05c6:900e first so a +fresh Sahara HELLO is available, then run this script. Output goes to +backup/crash-/. The memory table lists aboot/TZ crash regions; +`strings` on the dumps usually reveals the last error messages. +""" + +import argparse +import os +import struct +import sys +import time +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(BASE_DIR / ".flash-deps")) +import usb.core # noqa: E402 +import usb.util # noqa: E402 + +VID = 0x05C6 +PIDS = (0x900E, 0x9008, 0x9006) +CMD_HELLO_RSP = 0x2 +CMD_SWITCH_MODE = 0xC +CMD_MEMORY_READ = 0xA +CMD_MEMORY_DEBUG = 0x9 +MODE_MEMORY_DEBUG = 0x2 +MODE_COMMAND = 0x3 +TABLE_ENTRY_SIZE = 3 * 4 + 20 + 20 + + +def find_device(): + for pid in PIDS: + dev = usb.core.find(idVendor=VID, idProduct=pid) + if dev: + return dev, pid + return None, None + + +def endpoints(dev): + try: + if dev.is_kernel_driver_active(0): + dev.detach_kernel_driver(0) + except Exception: + pass + try: + dev.set_configuration() + except Exception: + pass + try: + usb.util.claim_interface(dev, 0) + except Exception: + pass + epin = epout = None + for intf in dev.get_active_configuration(): + for ep in intf: + if ep.bmAttributes != 2: + continue + direction = usb.util.endpoint_direction(ep.bEndpointAddress) + if direction == usb.util.ENDPOINT_IN and epin is None: + epin = ep + if direction == usb.util.ENDPOINT_OUT and epout is None: + epout = ep + return epin, epout + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--out", default="") + parser.add_argument("--timeout", type=int, default=8) + args = parser.parse_args() + dev, pid = find_device() + if not dev: + print("FAIL: no Qualcomm EDL device (05c6:900e/9008/9006)") + return 1 + print("device", hex(pid)) + epin, epout = endpoints(dev) + if not epin or not epout: + print("FAIL: no bulk endpoints") + return 1 + + def read(n=0x1000, t=None): + return bytes(dev.read(epin.bEndpointAddress, n, + timeout=t or args.timeout * 1000)) + + def write(data): + try: + return dev.write(epout.bEndpointAddress, data, + timeout=args.timeout * 1000) + except Exception as exc: + print("FAIL: USB write failed (%s). Power-cycle the phone to get a " + "fresh Sahara HELLO." % exc) + raise SystemExit(1) + + outdir = Path(args.out) if args.out else ( + BASE_DIR / "backup" / ("crash-" + time.strftime("%Y%m%d-%H%M%S"))) + outdir.mkdir(parents=True, exist_ok=True) + + # Ask the target to leave memory-debug wait state and re-send HELLO. + write(struct.pack("<3I", CMD_SWITCH_MODE, 0xC, MODE_COMMAND)) + try: + hello = read(0x1000) + except Exception as exc: + print("FAIL: no fresh Sahara HELLO (%s). Power-cycle the phone." % exc) + return 1 + if len(hello) < 48: + print("FAIL: short HELLO (%d bytes)" % len(hello)) + return 1 + fields = struct.unpack_from("<12I", hello) + print("HELLO cmd=%#x len=%d version=%d mode=%#x" % + (fields[0], fields[1], fields[2], fields[5])) + (outdir / "hello.bin").write_bytes(hello) + if fields[5] == 0: + print("Sahara mode 0 = IMAGE_TX_PENDING (plain EDL, waiting for a " + "programmer), not memory-debug.") + print("No crash dump is available in this state. The phone did not " + "enter the crash-dump path; use flash-edl.sh normally.") + return 0 + if fields[5] != MODE_MEMORY_DEBUG: + print("Sahara mode %#x is not memory-debug; no dump available." % + fields[5]) + return 0 + + write(struct.pack("<12I", CMD_HELLO_RSP, 0x30, 2, 1, 0, + MODE_MEMORY_DEBUG, 0, 0, 0, 0, 0, 0)) + try: + rsp = read(0x1000) + except Exception as exc: + print("FAIL: no memory-debug response (%s)" % exc) + return 1 + if len(rsp) < 16: + print("FAIL: short memory-debug response") + return 1 + cmd, length = struct.unpack_from("<2I", rsp) + print("response cmd=%#x len=%d" % (cmd, length)) + if cmd != CMD_MEMORY_DEBUG: + print("FAIL: target did not enter memory debug (cmd=%#x)" % cmd) + return 1 + table_addr, table_len = struct.unpack_from("<2I", rsp, 8) + print("memory table %#x / %#x bytes" % (table_addr, table_len)) + if not table_addr or not table_len or table_len > 0x100000: + print("FAIL: implausible memory table") + return 1 + + pos = 0 + table = b"" + while pos < table_len: + n = min(0x800, table_len - pos) + write(struct.pack("<4I", CMD_MEMORY_READ, 16, table_addr + pos, n)) + try: + chunk = read(n) + except Exception as exc: + print("FAIL reading table at %#x: %s" % (pos, exc)) + return 1 + table += chunk[:n] + pos += len(chunk) + (outdir / "memory_table.bin").write_bytes(table) + + for i in range(0, len(table) - TABLE_ENTRY_SIZE + 1, TABLE_ENTRY_SIZE): + save, base, size = struct.unpack_from("<3I", table, i) + desc = table[i + 12:i + 32].rstrip(b"\0").decode("utf-8", "replace") + name = table[i + 32:i + 52].rstrip(b"\0").decode("utf-8", "replace") + idx = i // TABLE_ENTRY_SIZE + print("region %d save=%#x base=%#x size=%#x desc=%r file=%r" % + (idx, save, base, size, desc, name)) + if not base or not size or size > 0x1000000: + continue + pos = 0 + blob = b"" + while pos < size: + n = min(0x800, size - pos) + write(struct.pack("<4I", CMD_MEMORY_READ, 16, base + pos, n)) + try: + chunk = read(n) + except Exception: + break + blob += chunk[:n] + pos += len(chunk) + safe = (name or ("region%d" % idx)).replace("/", "_") + (outdir / (safe + ".bin")).write_bytes(blob) + print(" dumped %s (%d bytes)" % (safe, len(blob))) + print("done:", outdir) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/make-oem-unlock-config.py b/scripts/make-oem-unlock-config.py new file mode 100755 index 0000000..7674300 --- /dev/null +++ b/scripts/make-oem-unlock-config.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Produce a config/frp image with the OEM allow-unlock flag set. + +aboot's read_allow_oem_unlock() checks the LSB of the last byte of the +"config" (or "frp") partition. Setting it allows 'fastboot oem unlock-go' +to write the authoritative RPMB devinfo on VB1/secure-boot devices. +""" + +import argparse +import sys + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("locked") + parser.add_argument("unlocked") + args = parser.parse_args() + data = bytearray(open(args.locked, "rb").read()) + if not data: + print("FAIL: input is empty") + return 1 + print("locked : last byte=%d" % data[-1]) + data[-1] |= 1 + with open(args.unlocked, "wb") as handle: + handle.write(data) + print("unlocked: last byte=%d -> %s (%d bytes)" % + (data[-1], args.unlocked, len(data))) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/make-unlocked-devinfo.py b/scripts/make-unlocked-devinfo.py new file mode 100755 index 0000000..a70dd89 --- /dev/null +++ b/scripts/make-unlocked-devinfo.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +"""Produce an unlocked devinfo image from a locked EDL dump. + +The stock 2720 aboot is locked (devinfo.is_unlocked=0) and verifies boot +images against Nokia_beatles certificates. Setting byte 13 to 1 makes aboot +skip signed-boot verification. Keep the original dump to relock later. +""" + +import argparse +import os +import sys + +MAGIC = b"ANDROID-BOOT!" +UNLOCKED_OFFSET = 13 +TAMPERED_OFFSET = 14 + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("locked") + parser.add_argument("unlocked") + args = parser.parse_args() + data = bytearray(open(args.locked, "rb").read()) + if bytes(data[:len(MAGIC)]) != MAGIC: + print("FAIL: input is not an ANDROID-BOOT! devinfo image") + return 1 + print("locked : is_unlocked=%d is_tampered=%d" % + (data[UNLOCKED_OFFSET], data[TAMPERED_OFFSET])) + data[UNLOCKED_OFFSET] = 1 + data[TAMPERED_OFFSET] = 0 + with open(args.unlocked, "wb") as handle: + handle.write(data) + print("unlocked: is_unlocked=%d is_tampered=%d -> %s (%d bytes)" % + (data[UNLOCKED_OFFSET], data[TAMPERED_OFFSET], args.unlocked, len(data))) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/patch-bootimg-cmdline.py b/scripts/patch-bootimg-cmdline.py new file mode 100755 index 0000000..891a6bc --- /dev/null +++ b/scripts/patch-bootimg-cmdline.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Rewrite the cmdline field of an Android v0 boot.img header. + +Only the 512-byte cmdline field changes; kernel, ramdisk, DTB and load +addresses stay byte-identical, so the image still fits its partition. +""" + +import argparse +import os +import struct +import sys + +BOOT_MAGIC = b"ANDROID!" +CMDLINE_OFFSET = 64 +CMDLINE_SIZE = 512 + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("src") + parser.add_argument("dst") + parser.add_argument("--cmdline", required=True) + args = parser.parse_args() + data = bytearray(open(args.src, "rb").read()) + if len(data) < CMDLINE_OFFSET + CMDLINE_SIZE or data[:8] != BOOT_MAGIC: + print("FAIL: not an Android boot image") + return 1 + raw = args.cmdline.encode("utf-8") + if len(raw) >= CMDLINE_SIZE: + print("FAIL: cmdline is too long (%d >= %d)" % (len(raw), CMDLINE_SIZE)) + return 1 + old = bytes(data[CMDLINE_OFFSET:CMDLINE_OFFSET + CMDLINE_SIZE]).rstrip(b"\0") + data[CMDLINE_OFFSET:CMDLINE_OFFSET + CMDLINE_SIZE] = ( + raw + b"\0" * (CMDLINE_SIZE - len(raw))) + with open(args.dst, "wb") as handle: + handle.write(data) + fields = struct.unpack_from("<8s8I", data) + print("old cmdline: %r" % old.decode("utf-8", "replace")) + print("new cmdline: %r" % args.cmdline) + print("kernel=%d ramdisk=%d page=%d -> %s (%d bytes)" % + (fields[1], fields[3], fields[8], args.dst, len(data))) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/repack-beatles-bootimg.py b/scripts/repack-beatles-bootimg.py new file mode 100755 index 0000000..0e323c0 --- /dev/null +++ b/scripts/repack-beatles-bootimg.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""Replace the appended DTB in a 2720 Flip Android boot image. + +The stock aboot finds the appended DTB through the 32-bit value at kernel+0x2c. +Keeping that pointer and rebuilding the page-aligned kernel/ramdisk layout lets +us ship a corrected DTB without rebuilding the whole 1.6 GiB rootfs image. + +This tool ONLY touches the standalone Android boot.img. The raw image written +to `userdata` is an MBR disk image whose first partition is an ext2 pmOS_boot +filesystem; never write an Android boot.img at raw offset 1 MiB. To update the +boot.img/DTB/extlinux.conf inside that filesystem use sync-beatles-bootfs.py. +""" + +import argparse +import os +import struct +import sys + +FDT_MAGIC = b"\xd0\x0d\xfe\xed" +BOOT_MAGIC = b"ANDROID!" +DTB_OFFSET_FIELD = 0x2c +ID_OFFSET = 576 +ID_SIZE = 32 + + +def align(value, page): + return (value + page - 1) // page * page + + +def parse_header(data): + if len(data) < 48 or data[:8] != BOOT_MAGIC: + raise ValueError("not an Android boot image") + fields = struct.unpack_from("<8s8I", data, 0) + return { + "kernel_size": fields[1], + "kernel_addr": fields[2], + "ramdisk_size": fields[3], + "ramdisk_addr": fields[4], + "second_size": fields[5], + "second_addr": fields[6], + "tags_addr": fields[7], + "page_size": fields[8], + } + + +def repack(old, dtb): + hdr = parse_header(old) + page = hdr["page_size"] + kernel_off = page + dtb_rel = struct.unpack_from(" %d bytes" % (len(old), len(new))) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/sync-beatles-bootfs.py b/scripts/sync-beatles-bootfs.py new file mode 100755 index 0000000..74f152c --- /dev/null +++ b/scripts/sync-beatles-bootfs.py @@ -0,0 +1,262 @@ +#!/usr/bin/env python3 +"""Repair/validate the pmOS_boot ext2 filesystem inside a 2720 raw image. + +The raw image written to `userdata` is an MBR disk image whose first +partition (LBA 2048, 256 MiB) is an ext2 filesystem containing +/vmlinuz, /initramfs, /qcom-msm8905-nokia-beatles.dtb, /boot.img and +/extlinux/extlinux.conf. lk2nd mounts that filesystem to find +extlinux.conf. An earlier repack mistakenly wrote an Android boot.img at +offset 1 MiB, destroying the ext2 superblock; lk2nd then found no +bootable fs and hung. + +This tool extracts that partition, updates the boot.img, DTB and (optionally) +extlinux.conf with debugfs, and writes it back at the MBR-specified offset. +Use --check to validate without modifying anything. +""" + +import argparse +import hashlib +import os +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent +EXT2_MAGIC_OFFSET = 1080 +EXT2_MAGIC = b"\x53\xef" +BOOT_FS_FILES = { + "boot.img": BASE_DIR / "images" / "boot-bananarchy-nokia-beatles.img", + "qcom-msm8905-nokia-beatles.dtb": + BASE_DIR / "devices" / "nokia-beatles" / "qcom-msm8905-nokia-beatles.dtb", +} +DEBUG_PREFIX = "loglevel=8 ignore_loglevel initcall_debug panic=10" +QUIET_PREFIX = "quiet splash" +BOOT_CMD_FLAGS = "plymouth.ignore-serial-consoles plymouth.prefer-fbcon" + + +def release_cmdline(conf): + """Restore the shipping cmdline (quiet splash) in an extlinux.conf. + + The pmOS initramfs defaults to nosplash=y and only starts plymouthd when + the literal "splash" parameter is present. Kernel-level debugging used the + replace-with-DEBUG_PREFIX path below; without the reverse conversion the + shipped image keeps loglevel=8/initcall_debug and never shows a boot splash. + """ + if DEBUG_PREFIX in conf: + conf = conf.replace(DEBUG_PREFIX, QUIET_PREFIX, 1) + if QUIET_PREFIX not in conf: + conf = conf.replace("append ", "append " + QUIET_PREFIX + " ", 1) + return conf + + +def debug_cmdline(conf): + if QUIET_PREFIX in conf: + conf = conf.replace(QUIET_PREFIX, DEBUG_PREFIX, 1) + elif DEBUG_PREFIX not in conf: + conf = conf.replace("append ", "append " + DEBUG_PREFIX + " ", 1) + return conf + + +def mbr_first_partition(data): + if len(data) < 512 or data[510:512] != b"\x55\xaa": + raise ValueError("raw image has no MBR signature") + entry = data[446:462] + ptype = entry[4] + lba, sectors = struct.unpack_from(" 0: + chunk = src.read(min(1 << 20, left)) + if not chunk: + break + dst.write(chunk) + left -= len(chunk) + conf = cat(fs, "/extlinux/extlinux.conf").decode("utf-8", "replace") + if "fdt /qcom-msm8905-nokia-beatles.dtb" not in conf: + raise ValueError("extlinux.conf does not name the beatles DTB") + validate_cmdline(conf, allow_debug) + for name, expected in BOOT_FS_FILES.items(): + got = sha(cat(fs, "/" + name)) + want = sha(open(expected, "rb").read()) + if got != want: + raise ValueError("/%s in boot fs is stale (%s != %s)" % (name, got[:12], want[:12])) + if verbose: + print("[ok] pmOS_boot at %#x (%d bytes): ext2 intact, extlinux.conf, " + "boot.img and beatles DTB all current" % (offset, size)) + return offset, size, fs + finally: + if fs and os.path.exists(fs): + os.unlink(fs) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--raw-image", default=str(BASE_DIR / "images" / "bananarchy-nokia-beatles.img")) + parser.add_argument("--source-boot-fs", default="", + help="Pristine ext2 boot-fs image to seed from when the " + "raw image's superblock is destroyed") + parser.add_argument("--debug-cmdline", action="store_true", + help="Replace 'quiet splash' in extlinux.conf with " + "verbose/panic settings (diagnostic builds only)") + parser.add_argument("--allow-debug", action="store_true", + help="With --check, accept a diagnostic cmdline") + parser.add_argument("--check", action="store_true") + args = parser.parse_args() + + dtb = BOOT_FS_FILES["qcom-msm8905-nokia-beatles.dtb"] + boot_img = BOOT_FS_FILES["boot.img"] + for path in (args.raw_image, str(dtb), str(boot_img)): + if not os.path.isfile(path): + print("FAIL: missing %s" % path) + return 1 + + if args.check: + try: + check(args.raw_image, dtb, boot_img, allow_debug=args.allow_debug) + return 0 + except ValueError as exc: + print("FAIL: %s" % exc) + return 1 + + raw = open(args.raw_image, "rb").read(1024 * 1024 + 4096) + offset, size = mbr_first_partition(raw) + with tempfile.NamedTemporaryFile(suffix=".img", delete=False) as handle: + fs = handle.name + try: + if args.source_boot_fs: + with open(args.source_boot_fs, "rb") as src, open(fs, "wb") as dst: + while True: + chunk = src.read(1 << 20) + if not chunk: + break + dst.write(chunk) + else: + with open(args.raw_image, "rb") as src, open(fs, "wb") as dst: + src.seek(offset) + left = size + while left > 0: + chunk = src.read(min(1 << 20, left)) + if not chunk: + break + dst.write(chunk) + left -= len(chunk) + if os.path.getsize(fs) != size: + raise ValueError("source boot fs is %d bytes, expected %d" % + (os.path.getsize(fs), size)) + if open(fs, "rb").read(EXT2_MAGIC_OFFSET + 2)[EXT2_MAGIC_OFFSET:EXT2_MAGIC_OFFSET + 2] != EXT2_MAGIC: + raise ValueError("source boot fs has no ext2 superblock") + + commands = [] + for name, host_path in BOOT_FS_FILES.items(): + commands += ["rm /%s" % name, + "write %s /%s" % (host_path, name)] + conf = cat(fs, "/extlinux/extlinux.conf").decode("utf-8", "replace") + new_conf = conf + new_conf = debug_cmdline(new_conf) if args.debug_cmdline else release_cmdline(new_conf) + new_conf = new_conf.replace(" earlycon ", " ") + new_conf = new_conf.replace("append earlycon ", "append ") + new_conf = new_conf.replace("append earlycon", "append") + validate_cmdline(new_conf, allow_debug=args.debug_cmdline) + if new_conf != conf: + with tempfile.NamedTemporaryFile("w", suffix=".conf", delete=False) as handle: + handle.write(new_conf) + conf_file = handle.name + commands += ["rm /extlinux/extlinux.conf", + "write %s /extlinux/extlinux.conf" % conf_file] + conf_tmp = conf_file + else: + conf_tmp = None + run_debugfs(fs, commands) + if conf_tmp: + os.unlink(conf_tmp) + + with open(args.raw_image, "r+b") as dst, open(fs, "rb") as src: + dst.seek(offset) + while True: + chunk = src.read(1 << 20) + if not chunk: + break + dst.write(chunk) + print("patched pmOS_boot at %#x (%d bytes)" % (offset, size)) + except (ValueError, OSError) as exc: + print("FAIL: %s" % exc) + return 1 + finally: + if os.path.exists(fs): + os.unlink(fs) + + try: + check(args.raw_image, dtb, boot_img) + except ValueError as exc: + print("FAIL: %s" % exc) + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/sync-prebuilt-overlay.sh b/scripts/sync-prebuilt-overlay.sh index 089fa7a..b71492a 100755 --- a/scripts/sync-prebuilt-overlay.sh +++ b/scripts/sync-prebuilt-overlay.sh @@ -46,6 +46,14 @@ def regular_files(root): return result +def is_elf(path): + try: + with open(path, "rb") as handle: + return handle.read(4) == b"\x7fELF" + except OSError: + return False + + by_name = {} for path in regular_files(prebuilt_root): by_name.setdefault(os.path.basename(path), []).append(path) @@ -62,7 +70,14 @@ for target in regular_files(overlay_root): source = candidate break if source is None and candidates: - source = candidates[0] + bin_dir = os.path.join(overlay_root, "usr", "bin") + os.sep + local_bin_dir = os.path.join(overlay_root, "usr", "local", "bin") + os.sep + for candidate in candidates: + if is_elf(candidate) and not target.startswith(bin_dir) and \ + not target.startswith(local_bin_dir): + continue + source = candidate + break if source is None: continue matched += 1 diff --git a/scripts/test-lk2nd-beatles-port.py b/scripts/test-lk2nd-beatles-port.py new file mode 100755 index 0000000..c22543b --- /dev/null +++ b/scripts/test-lk2nd-beatles-port.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +"""Host tests for the source-built nokia-beatles lk2nd port. + +Runs the image validator, compiles the shared C panel-init walker against the +actual byte streams extracted from the shipped QCDT DTB, and checks that the +repository wiring (build script, patch, flasher) still points at the port. +""" + +import os +import shutil +import subprocess +import sys +import tempfile + +BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +PINNED = "cf45aefd22d744b2bf9b39455afae697ce430063" + + +def run(cmd, **kwargs): + return subprocess.run(cmd, cwd=BASE, capture_output=True, text=True, **kwargs) + + +def check(condition, message): + if not condition: + print("FAIL: %s" % message) + return False + print("[ok] %s" % message) + return True + + +def main(): + ok = True + validator = os.path.join(BASE, "scripts", "check-lk2nd-beatles.py") + build = os.path.join(BASE, "scripts", "build-lk2nd-beatles.sh") + patch = os.path.join(BASE, "bootloader", "lk2nd", "nokia-beatles.patch") + header = os.path.join(BASE, "bootloader", "lk2nd", "spi-panel-init.h") + test_c = os.path.join(BASE, "bootloader", "lk2nd", "test_spi_panel_init.c") + + variants = ( + ("images/boot-lk2nd-nokia-beatles.img", 0, 0, False), + ("images/boot-lk2nd-nokia-beatles-diagnostic.img", 1, 0, False), + ("images/boot-lk2nd-nokia-beatles-display.img", 0, 1, True), + ) + for image, fastboot, display, allow_missing_cookie in variants: + ok &= check(os.path.isfile(os.path.join(BASE, image)), "%s exists" % image) + if not os.path.isfile(os.path.join(BASE, image)): + continue + cmd = [sys.executable, validator, "--image", image, + "--expect-fastboot", str(fastboot), + "--expect-display", str(display)] + if allow_missing_cookie: + cmd.append("--allow-missing-cookie") + r = subprocess.run(cmd, cwd=BASE, capture_output=True, text=True) + for line in r.stdout.strip().split("\n"): + if line: + print(line) + ok &= check(r.returncode == 0, + "%s passes structural validation" % os.path.basename(image)) + if r.returncode != 0: + print(r.stderr.strip()) + + for path, label in ((build, "build-lk2nd-beatles.sh"), + (patch, "nokia-beatles.patch"), + (header, "spi-panel-init.h"), + (test_c, "test_spi_panel_init.c"), + (os.path.join(BASE, "bootloader", "lk2nd", "Dockerfile"), + "toolchain Dockerfile")): + ok &= check(os.path.isfile(path), "%s exists" % label) + + script = open(build).read() + ok &= check(PINNED in script, "build script pins upstream commit %s" % PINNED) + ok &= check("LK2ND_FORCE_FASTBOOT=1" in script and "lk2nd.no-display" in script, + "build script can produce the forced-fastboot no-display diagnostic image") + ok &= check("lk2nd.display=on" in script and "--expect-display" in script, + "build script can produce and validate the SPI display image") + ok &= check("--force-panel-init" in script, + "build script supports forcing the panel init replay") + ok &= check('--with-display' in script and 'WITH_DISPLAY' in script, + "build script can re-enable the SPI display") + ok &= check("make TOOLCHAIN_PREFIX=arm-none-eabi-" in script and + "MKBOOTIMG_CMDLINE=" in script, + "build script uses the cross toolchain and beatles cmdline") + patch_text = open(patch).read() + ok &= check("lk2nd/device/dts/lk2nd.dtsi" in patch_text and + "nokia-beatles.dtsi" in patch_text and + "msm8905-qrd-skub.dts" in patch_text and + "lk2nd,panel-init" in patch_text and + "mdss_spi_panel_init_commands" in patch_text, + "patch contains the /cpus fix, device node, panel init data and driver hook") + ok &= check("oem scan-boot" in patch_text, + "patch contains the oem scan-boot extlinux probe") + ok &= check("oem scan-dtb" in patch_text, + "patch contains the oem scan-dtb kernel DTB probe") + ok &= check("lk2nd/ramoops/ramoops.c" in patch_text, + "patch contains the always-on ramoops console fix") + ok &= check("oem display-init" in patch_text, + "patch contains the runtime SPI display probe") + ok &= check("lk2nd.display=on" in patch_text, + "patch contains the boot-time display option") + ok &= check("platform/msm_shared/reboot.c" in patch_text and + "beatles low-bit reboot cookie" in patch_text, + "patch contains the low-bit lk2nd menu reboot cookie") + ok &= check("QUP_FIFO_TIMEOUT" in patch_text and "CLK_POLL_TIMEOUT" in patch_text, + "patch bounds QUP and clock register polls") + ok &= check("lk2nd/device/2nd/spi-display.c" in patch_text, + "patch contains the safe SPI display init") + ok &= check("app/aboot/aboot.c" in patch_text and + "scan-only: final kernel cmdline/DTB ready" in patch_text, + "patch stages the final DTB after lk2nd DT updates") + ok &= check("No valid pstore console" in patch_text, + "patch validates and bounds the ramoops console") + ok &= check("SPI panel fallback from QCDT" in patch_text, + "patch supports chain-loaded SPI panel probes") + ok &= check("per-word SPEW log" in patch_text, + "patch removes the QUP FIFO log flood") + ok &= check("lk2nd/fastboot/fetch.c" in patch_text and + "aligned read exceeds partition" in patch_text, + "patch makes oem read-partition block-safe") + + flasher = open(os.path.join(BASE, "flash-edl.py")).read() + ok &= check("headless" not in flasher.lower(), + "flasher no longer describes a headless lk2nd") + ok &= check("images/boot-lk2nd-nokia-beatles-display.img" in flasher, + "flasher defaults to the display-enabled beatles lk2nd image") + ok &= check('target_names = ("boot", "recovery", "lk2nd")' in flasher, + "flasher refreshes the separate lk2nd partition") + ok &= check('"--lk2nd-image"' in flasher and "args.lk2nd_image" in flasher, + "flasher can override the beatles lk2nd image for diagnostics") + + preflight = open(os.path.join(BASE, "scripts", "check-rebuild.sh")).read() + ok &= check("check-lk2nd-beatles.py" in preflight, + "check-rebuild.sh validates the beatles lk2nd image") + + gcc = shutil.which("gcc") or shutil.which("cc") + if gcc: + with tempfile.TemporaryDirectory() as tmp: + streams = os.path.join(tmp, "panel_streams.h") + r = subprocess.run([sys.executable, validator, + "--image", "images/boot-lk2nd-nokia-beatles.img", + "--emit-streams-header", streams], + cwd=BASE, capture_output=True, text=True) + ok &= check(r.returncode == 0, "panel init streams extracted from QCDT DTB") + if r.returncode == 0: + binary = os.path.join(tmp, "test_spi_panel_init") + r = run([gcc, "-std=c11", "-Wall", "-Wextra", "-Werror", + "-I", tmp, "-I", os.path.join(BASE, "bootloader", "lk2nd"), + "-o", binary, test_c]) + ok &= check(r.returncode == 0, + "host C unit test compiles against the shared parser header") + if r.returncode == 0: + print(r.stderr.strip()) + r = run([binary]) + print(r.stdout.strip()) + print(r.stderr.strip()) + ok &= check(r.returncode == 0, + "host C unit test accepts the GC9305 v2 init stream") + else: + print("[skip] no host C compiler; C unit test skipped") + + print("[%s] nokia-beatles lk2nd port tests" % ("ok" if ok else "FAIL")) + return 0 if ok else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/bananarchy-daemons/bananarchy-cover-idle.c b/src/bananarchy-daemons/bananarchy-cover-idle.c new file mode 100644 index 0000000..be09033 --- /dev/null +++ b/src/bananarchy-daemons/bananarchy-cover-idle.c @@ -0,0 +1,520 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +/* Compiled idle cover IPC/renderer for nokia-beatles. No Python in the idle path. */ +#include +#include +#include +#include +#include + +#include "common.h" + +#define COVER_LOCK "/run/bananarchy-cover-idle.lock" +#define DEFAULT_SOCKET "/run/bananarchy/cover.sock" +#define DEFAULT_FB "/dev/fb1" + +struct glyph { + char ch; + unsigned char col[5]; +}; + +static const struct glyph font[] = { + {'A', {0x7e, 0x11, 0x11, 0x11, 0x7e}}, {'B', {0x7f, 0x49, 0x49, 0x49, 0x36}}, + {'C', {0x3e, 0x41, 0x41, 0x41, 0x22}}, {'D', {0x7f, 0x41, 0x41, 0x22, 0x1c}}, + {'E', {0x7f, 0x49, 0x49, 0x49, 0x41}}, {'F', {0x7f, 0x09, 0x09, 0x09, 0x01}}, + {'G', {0x3e, 0x41, 0x49, 0x49, 0x7a}}, {'H', {0x7f, 0x08, 0x08, 0x08, 0x7f}}, + {'I', {0x00, 0x41, 0x7f, 0x41, 0x00}}, {'J', {0x20, 0x40, 0x41, 0x3f, 0x01}}, + {'K', {0x7f, 0x08, 0x14, 0x22, 0x41}}, {'L', {0x7f, 0x40, 0x40, 0x40, 0x40}}, + {'M', {0x7f, 0x02, 0x0c, 0x02, 0x7f}}, {'N', {0x7f, 0x04, 0x08, 0x10, 0x7f}}, + {'O', {0x3e, 0x41, 0x41, 0x41, 0x3e}}, {'P', {0x7f, 0x09, 0x09, 0x09, 0x06}}, + {'Q', {0x3e, 0x41, 0x51, 0x21, 0x5e}}, {'R', {0x7f, 0x09, 0x19, 0x29, 0x46}}, + {'S', {0x46, 0x49, 0x49, 0x49, 0x31}}, {'T', {0x01, 0x01, 0x7f, 0x01, 0x01}}, + {'U', {0x3f, 0x40, 0x40, 0x40, 0x3f}}, {'V', {0x1f, 0x20, 0x40, 0x20, 0x1f}}, + {'W', {0x3f, 0x40, 0x38, 0x40, 0x3f}}, {'X', {0x63, 0x14, 0x08, 0x14, 0x63}}, + {'Y', {0x07, 0x08, 0x70, 0x08, 0x07}}, {'Z', {0x61, 0x51, 0x49, 0x45, 0x43}}, + {'0', {0x3e, 0x51, 0x49, 0x45, 0x3e}}, {'1', {0x00, 0x42, 0x7f, 0x40, 0x00}}, + {'2', {0x42, 0x61, 0x51, 0x49, 0x46}}, {'3', {0x21, 0x41, 0x45, 0x4b, 0x31}}, + {'4', {0x18, 0x14, 0x12, 0x7f, 0x10}}, {'5', {0x27, 0x45, 0x45, 0x45, 0x39}}, + {'6', {0x3c, 0x4a, 0x49, 0x49, 0x30}}, {'7', {0x01, 0x71, 0x09, 0x05, 0x03}}, + {'8', {0x36, 0x49, 0x49, 0x49, 0x36}}, {'9', {0x06, 0x49, 0x49, 0x29, 0x1e}}, + {':', {0x00, 0x36, 0x36, 0x00, 0x00}}, {'-', {0x08, 0x08, 0x08, 0x08, 0x08}}, + {'.', {0x00, 0x60, 0x60, 0x00, 0x00}}, {'/', {0x20, 0x10, 0x08, 0x04, 0x02}}, + {' ', {0x00, 0x00, 0x00, 0x00, 0x00}}, +}; + +static uint32_t rgb888(unsigned int r, unsigned int g, unsigned int b) +{ + return ((uint32_t)(r & 0xff) << 16) | + ((uint32_t)(g & 0xff) << 8) | + (uint32_t)(b & 0xff); +} + +static uint16_t rgb565_from_rgb888(uint32_t color) +{ + unsigned int r = (color >> 16) & 0xff; + unsigned int g = (color >> 8) & 0xff; + unsigned int b = color & 0xff; + return (uint16_t)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)); +} + +struct frame { + unsigned char *pixels; + unsigned int width; + unsigned int height; + unsigned int stride; + unsigned int bpp; +}; + +static void frame_pixel(struct frame *fb, int x, int y, uint32_t color) +{ + size_t offset; + if(x < 0 || y < 0 || (unsigned int)x >= fb->width || + (unsigned int)y >= fb->height) + return; + offset = (size_t)y * fb->stride + (size_t)x * (fb->bpp / 8); + if(fb->bpp == 32) { + memcpy(fb->pixels + offset, &color, 4); + } else { + uint16_t pixel = rgb565_from_rgb888(color); + memcpy(fb->pixels + offset, &pixel, 2); + } +} + +static void frame_rect(struct frame *fb, int x0, int y0, int x1, int y1, + uint32_t color) +{ + int x; + int y; + for(y = y0; y < y1; y++) + for(x = x0; x < x1; x++) + frame_pixel(fb, x, y, color); +} + +static const unsigned char *glyph_for(char ch) +{ + size_t i; + ch = (char)toupper((unsigned char)ch); + for(i = 0; i < sizeof(font) / sizeof(font[0]); i++) { + if(font[i].ch == ch) + return font[i].col; + } + return font[sizeof(font) / sizeof(font[0]) - 1].col; +} + +static void frame_text(struct frame *fb, const char *text, int x, int y, + int scale, uint32_t color) +{ + while(*text) { + const unsigned char *cols = glyph_for(*text++); + int cx; + int cy; + for(cx = 0; cx < 5; cx++) { + for(cy = 0; cy < 7; cy++) { + if(cols[cx] & (1u << cy)) { + frame_rect(fb, x + cx * scale, y + cy * scale, + x + (cx + 1) * scale, y + (cy + 1) * scale, color); + } + } + } + x += 6 * scale; + } +} + +static int read_uint_file(const char *path, unsigned int *value) +{ + FILE *handle = fopen(path, "r"); + if(!handle) + return 0; + if(fscanf(handle, "%u", value) != 1) { + fclose(handle); + return 0; + } + fclose(handle); + return *value > 0; +} + +static int fb_geometry(const char *fb_path, unsigned int *width, + unsigned int *height, unsigned int *bpp, + unsigned int *stride) +{ + char sysfs[128]; + int index = 0; + FILE *handle; + const char *p = strstr(fb_path, "fb"); + unsigned int bytes_per_pixel; + if(p) + index = atoi(p + 2); + snprintf(sysfs, sizeof(sysfs), + "/sys/class/graphics/fb%d/virtual_size", index); + handle = fopen(sysfs, "r"); + if(!handle) + return 0; + if(fscanf(handle, "%u,%u", width, height) != 2) { + fclose(handle); + return 0; + } + fclose(handle); + snprintf(sysfs, sizeof(sysfs), + "/sys/class/graphics/fb%d/bits_per_pixel", index); + if(!read_uint_file(sysfs, bpp)) + *bpp = 16; + if(*bpp != 16 && *bpp != 32) + return 0; + bytes_per_pixel = *bpp / 8; + snprintf(sysfs, sizeof(sysfs), "/sys/class/graphics/fb%d/stride", index); + if(!read_uint_file(sysfs, stride) || *stride < *width * bytes_per_pixel) + *stride = *width * bytes_per_pixel; + return *width > 0 && *height > 0; +} + +static int write_all(int fd, const unsigned char *buffer, size_t length) +{ + size_t written = 0; + while(written < length) { + ssize_t n = write(fd, buffer + written, length - written); + if(n < 0) { + if(errno == EINTR) + continue; + return 0; + } + if(n == 0) + return 0; + written += (size_t)n; + } + return 1; +} + +static int draw_frame(const char *fb_path, const char *message, int test) +{ + int fd = open(fb_path, O_RDWR | O_CLOEXEC); + unsigned int width = 0; + unsigned int height = 0; + unsigned int bpp = 0; + unsigned int stride = 0; + size_t size; + unsigned char *mem; + struct frame fb; + char clock[16]; + char date[32]; + time_t now = time(NULL); + struct tm tm; + if(fd < 0) + return 0; + if(!fb_geometry(fb_path, &width, &height, &bpp, &stride)) { + close(fd); + return 0; + } + size = (size_t)stride * height; + mem = calloc(1, size); + if(!mem) { + close(fd); + return 0; + } + fb.pixels = mem; + fb.width = width; + fb.height = height; + fb.stride = stride; + fb.bpp = bpp; + localtime_r(&now, &tm); + strftime(clock, sizeof(clock), "%H:%M", &tm); + strftime(date, sizeof(date), "%d.%m.%Y", &tm); + if(test == 2) { + frame_rect(&fb, 0, 0, (int)width / 4, (int)height, + rgb888(250, 40, 40)); + frame_rect(&fb, (int)width / 4, 0, (int)width / 2, (int)height, + rgb888(40, 230, 80)); + frame_rect(&fb, (int)width / 2, 0, (int)width * 3 / 4, (int)height, + rgb888(60, 110, 250)); + frame_rect(&fb, (int)width * 3 / 4, 0, (int)width, (int)height, + rgb888(245, 245, 245)); + } else if(test == 3) { + frame_rect(&fb, 0, 0, (int)width, (int)height, + rgb888(245, 245, 245)); + } else if(test == 4) { + frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(0, 0, 0)); + } else { + frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(8, 12, 26)); + frame_rect(&fb, 0, 0, (int)width, 3, rgb888(250, 210, 60)); + frame_text(&fb, "BANANARCHY", 12, 26, 2, rgb888(250, 210, 60)); + frame_text(&fb, clock, 20, (int)height / 2 - 20, + width >= 220 ? 5 : 3, rgb888(235, 240, 248)); + frame_text(&fb, date, 30, (int)height / 2 + 40, 2, + rgb888(90, 150, 240)); + if(message && message[0]) + frame_text(&fb, message, 6, (int)height - 30, 2, + rgb888(235, 240, 248)); + } + if(lseek(fd, 0, SEEK_SET) < 0 || !write_all(fd, mem, size)) { + free(mem); + close(fd); + return 0; + } + fsync(fd); + free(mem); + close(fd); + return 1; +} + +static void mkdir_p(const char *path) +{ + char buf[256]; + char *p; + snprintf(buf, sizeof(buf), "%s", path); + for(p = buf + 1; *p; p++) { + if(*p != '/') + continue; + *p = '\0'; + mkdir(buf, 0755); + *p = '/'; + } +} + +static void trim(char *value) +{ + size_t len; + while(*value == ' ' || *value == '\t') + memmove(value, value + 1, strlen(value)); + len = strlen(value); + while(len > 0 && (value[len - 1] == ' ' || value[len - 1] == '\t' || + value[len - 1] == '\r' || value[len - 1] == '\n')) { + value[--len] = '\0'; + } +} + +static void read_config(const char *path, char *socket_path, size_t splen, + char *fb_path, size_t fblen) +{ + char line[256]; + FILE *handle = fopen(path, "r"); + safe_copy(socket_path, splen, DEFAULT_SOCKET); + safe_copy(fb_path, fblen, DEFAULT_FB); + if(!handle) + return; + while(fgets(line, sizeof(line), handle)) { + char *comment = strchr(line, '#'); + char *eq; + char *key; + char *value; + if(comment) + *comment = '\0'; + eq = strchr(line, '='); + if(!eq) + continue; + *eq = '\0'; + key = line; + value = eq + 1; + trim(key); + trim(value); + if(strcmp(key, "socket_path") == 0) + safe_copy(socket_path, splen, value); + else if(strcmp(key, "fb_device") == 0) + safe_copy(fb_path, fblen, value); + } + fclose(handle); +} + +static void lower_string(char *value) +{ + while(*value) { + *value = (char)tolower((unsigned char)*value); + value++; + } +} + +static void upper_string(char *value) +{ + while(*value) { + *value = (char)toupper((unsigned char)*value); + value++; + } +} + +struct state { + char lid[16]; + char backend[16]; + char call[64]; + char message[128]; + int enabled; + int battery; + int sms; + int test; +}; + +static int test_value(const char *mode) +{ + if(!mode) + return 0; + if(strcmp(mode, "bars") == 0) + return 2; + if(strcmp(mode, "clock") == 0) + return 1; + if(strcmp(mode, "solid") == 0) + return 3; + if(strcmp(mode, "off") == 0) + return 4; + return 0; +} + +static void handle_command(char *buffer, struct state *state, int *redraw) +{ + char command[32]; + char *save = NULL; + char *token = strtok_r(buffer, " \t\r\n", &save); + if(!token) + return; + safe_copy(command, sizeof(command), token); + upper_string(command); + if(strcmp(command, "LID") == 0) { + char *value = strtok_r(NULL, " \t\r\n", &save); + safe_copy(state->lid, sizeof(state->lid), + value && strcasecmp(value, "CLOSED") == 0 ? "closed" : "open"); + *redraw = 1; + } else if(strcmp(command, "NOTIFY") == 0) { + char *rest = save; + while(rest && (*rest == ' ' || *rest == '\t')) + rest++; + safe_copy(state->message, sizeof(state->message), rest ? rest : ""); + trim(state->message); + *redraw = 1; + } else if(strcmp(command, "CALL") == 0) { + char *value = strtok_r(NULL, " \t\r\n", &save); + if(value) { + safe_copy(state->call, sizeof(state->call), value); + lower_string(state->call); + } + } else if(strcmp(command, "SMS") == 0) { + char *value = strtok_r(NULL, " \t\r\n", &save); + if(value) + state->sms = (int)strtol(value, NULL, 10); + } else if(strcmp(command, "BATTERY") == 0) { + char *value = strtok_r(NULL, " \t\r\n", &save); + if(value) + state->battery = (int)strtol(value, NULL, 10); + } else if(strcmp(command, "SET") == 0) { + char *key = strtok_r(NULL, " \t\r\n", &save); + char *value = strtok_r(NULL, " \t\r\n", &save); + if(key && value && strcmp(key, "enabled") == 0) + state->enabled = (int)strtol(value, NULL, 10); + } else if(strcmp(command, "TEST") == 0) { + char *mode = strtok_r(NULL, " \t\r\n", &save); + if(mode) + lower_string(mode); + state->test = test_value(mode); + *redraw = 1; + } else if(strcmp(command, "BLANK") == 0) { + state->test = 4; + *redraw = 1; + } else if(strcmp(command, "UNBLANK") == 0) { + state->test = 0; + *redraw = 1; + } else if(strcmp(command, "REFRESH") == 0 || + strcmp(command, "RELOAD_THEME") == 0) { + *redraw = 1; + } +} + +static void reply_for(char *buffer, const struct state *state, + char *reply, size_t len) +{ + char command[32]; + char *save = NULL; + char *token = strtok_r(buffer, " \t\r\n", &save); + if(!token) { + snprintf(reply, len, "OK\n"); + return; + } + safe_copy(command, sizeof(command), token); + upper_string(command); + if(strcmp(command, "PING") == 0) { + snprintf(reply, len, "OK pong\n"); + } else if(strcmp(command, "STATUS") == 0) { + snprintf(reply, len, + "OK lid=%s backend=%s enabled=%d battery=%d call=%s sms=%d\n", + state->lid, state->backend, state->enabled, state->battery, + state->call, state->sms); + } else if(strcmp(command, "LID") == 0) { + snprintf(reply, len, "OK lid=%s\n", state->lid); + } else if(strcmp(command, "TEST") == 0) { + snprintf(reply, len, "OK test=%d\n", state->test); + } else { + snprintf(reply, len, "OK\n"); + } +} + +int main(int argc, char **argv) +{ + const char *lock_path = getenv("BANANARCHY_COVER_LOCK"); + int lock_fd = lock_singleton(lock_path ? lock_path : COVER_LOCK); + const char *config = "/etc/bananarchy/cover-display.conf"; + char socket_path[256]; + char fb_path[128]; + struct sockaddr_un local; + int server; + struct state state; + time_t last_draw = 0; + if(lock_fd < 0) + return 1; + if(argc > 2 && strcmp(argv[1], "--config") == 0) + config = argv[2]; + read_config(config, socket_path, sizeof(socket_path), + fb_path, sizeof(fb_path)); + mkdir_p(socket_path); + unlink(socket_path); + server = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if(server < 0) + return 1; + if(strlen(socket_path) >= sizeof(local.sun_path)) + return 1; + memset(&local, 0, sizeof(local)); + local.sun_family = AF_UNIX; + strncpy(local.sun_path, socket_path, sizeof(local.sun_path) - 1); + if(bind(server, (struct sockaddr *)&local, sizeof(local)) < 0) + return 1; + chmod(socket_path, 0660); + chown(socket_path, 0, SESSION_GID); + memset(&state, 0, sizeof(state)); + snprintf(state.lid, sizeof(state.lid), "open"); + snprintf(state.backend, sizeof(state.backend), "none"); + snprintf(state.call, sizeof(state.call), "none"); + state.enabled = 1; + state.battery = -1; + while(1) { + struct pollfd pfd; + char buffer[512]; + char original[512]; + char reply[256]; + struct sockaddr_un peer; + socklen_t peer_len = sizeof(peer); + ssize_t nread; + pfd.fd = server; + pfd.events = POLLIN; + pfd.revents = 0; + if(poll(&pfd, 1, 1000) > 0 && (pfd.revents & POLLIN)) { + nread = recvfrom(server, buffer, sizeof(buffer) - 1, 0, + (struct sockaddr *)&peer, &peer_len); + if(nread > 0) { + int redraw = 0; + buffer[nread] = '\0'; + snprintf(original, sizeof(original), "%s", buffer); + handle_command(buffer, &state, &redraw); + reply_for(original, &state, reply, sizeof(reply)); + sendto(server, reply, strlen(reply), 0, + (struct sockaddr *)&peer, peer_len); + if(redraw) + last_draw = 0; + if(strncasecmp(original, "QUIT", 4) == 0) { + close(server); + unlink(socket_path); + return 0; + } + } + } + if(state.enabled && time(NULL) - last_draw > 30) { + last_draw = time(NULL); + snprintf(state.backend, sizeof(state.backend), "%s", + draw_frame(fb_path, state.message, state.test) ? "fb" : "none"); + } + } + return 0; +} diff --git a/src/bananarchy-daemons/bananarchy-lid.c b/src/bananarchy-daemons/bananarchy-lid.c new file mode 100644 index 0000000..bd52000 --- /dev/null +++ b/src/bananarchy-daemons/bananarchy-lid.c @@ -0,0 +1,328 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +/* Compiled flip-lid handler for nokia-beatles. No Python in the idle path. */ +#include +#include +#include +#include + +#include "common.h" + +#define LID_LOCK "/run/bananarchy-lid.lock" +#define LID_STATE_FILE "/run/bananarchy/lid-state" +#define LOCK_FLAG "/tmp/bananarchy_screen_locked" +#define LOCKER_FIFO "/tmp/dwm_plugin_locker.fifo" +#define LID_STABLE_MS 80 +#define GPIO_FILE "/sys/kernel/debug/gpio" +#define COVER_SOCKET "/run/bananarchy/cover.sock" +#define LID_CLIENT_SOCKET "/run/bananarchy/lid-client.sock" +#define LID_BROADCAST_MS 2000 +#define EV_SW 0x05 +#define SW_LID 0x00 +#define SW_KEYPAD_SLIDE 0x0a +#define CLOSED_MASK ((1u << SW_LID) | (1u << SW_KEYPAD_SLIDE)) +#define BA_EVIOCGSW(len) BA_IOC(2U, 'E', 0x1bU, (unsigned int)(len)) + +static char *const session_env[] = { + (char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin", + (char *)"HOME=/home/user", + (char *)"USER=user", + (char *)"DISPLAY=:0", + (char *)"XDG_RUNTIME_DIR=/run/user/10000", + (char *)"SHELL=/bin/sh", + NULL +}; + +static void run_sxmo_state(const char *action) +{ + char *const argv[] = { + (char *)"/usr/bin/sxmo_state.sh", (char *)"set", (char *)action, NULL + }; + daemon_spawn_env(argv, (char *const *)session_env); +} + +static void write_lid_state(int closed) +{ + const char *value = closed ? "closed\n" : "open\n"; + int fd; + mkdir("/run/bananarchy", 0755); + fd = open(LID_STATE_FILE, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if(fd < 0) + return; + if(write(fd, value, strlen(value)) < 0) { + close(fd); + return; + } + close(fd); + chmod(LID_STATE_FILE, 0644); +} + +static void cover_send(const char *state) +{ + int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + struct sockaddr_un local; + struct sockaddr_un remote; + char payload[64]; + if(fd < 0) + return; + mkdir("/run/bananarchy", 0755); + unlink(LID_CLIENT_SOCKET); + memset(&local, 0, sizeof(local)); + local.sun_family = AF_UNIX; + snprintf(local.sun_path, sizeof(local.sun_path), "%s", LID_CLIENT_SOCKET); + if(bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) { + close(fd); + return; + } + memset(&remote, 0, sizeof(remote)); + remote.sun_family = AF_UNIX; + snprintf(remote.sun_path, sizeof(remote.sun_path), "%s", COVER_SOCKET); + snprintf(payload, sizeof(payload), "LID %s", state); + sendto(fd, payload, strlen(payload), 0, + (struct sockaddr *)&remote, sizeof(remote)); + close(fd); + unlink(LID_CLIENT_SOCKET); +} + +static void locker_send(const char *payload) +{ + int fd = open(LOCKER_FIFO, O_WRONLY | O_NONBLOCK | O_CLOEXEC); + if(fd < 0) + return; + (void)write(fd, payload, strlen(payload)); + close(fd); +} + +static void on_transition(int closed) +{ + write_lid_state(closed); + if(closed) { + write_text_file("/sys/class/backlight/backlight/brightness", "0"); + write_text_file("/sys/class/backlight/backlight/bl_power", "4"); + write_text_file("/sys/class/leds/white:kbd_backlight/brightness", "0"); + cover_send("CLOSED"); + locker_send("SCREENOFF\n"); + run_sxmo_state("screenoff"); + } else { + unlink(LOCK_FLAG); + write_text_file("/sys/class/backlight/backlight/bl_power", "0"); + write_text_file("/sys/class/backlight/backlight/brightness", "10"); + write_text_file("/sys/class/leds/white:kbd_backlight/brightness", "1"); + cover_send("OPEN"); + locker_send("CLOSE\n"); + run_sxmo_state("unlock"); + } +} + +static int hall_line_closed(const char *line) +{ + char buf[256]; + char *save = NULL; + char *token; + char *name = NULL; + char *level = NULL; + int index = 0; + safe_copy(buf, sizeof(buf), line); + token = strtok_r(buf, " \t\r\n", &save); + while(token) { + if(index == 0) + name = token; + if(index == 3) + level = token; + index++; + token = strtok_r(NULL, " \t\r\n", &save); + } + if(!name || !level) + return 0; + if(strcmp(name, "gpio36") != 0 && strcmp(name, "gpio92") != 0) + return 0; + return strcmp(level, "low") == 0; +} + +static int hall_state(void) +{ + const char *override = getenv("BANANARCHY_LID_GPIO_FILE"); + const char *path = override ? override : GPIO_FILE; + char line[256]; + FILE *handle; + int closed = 0; + if(access(path, R_OK) < 0) { + mount("none", "/sys/kernel/debug", "debugfs", 0, NULL); + } + handle = fopen(path, "r"); + if(!handle) + return -1; + while(fgets(line, sizeof(line), handle)) { + if(hall_line_closed(line)) { + closed = 1; + break; + } + } + fclose(handle); + return closed; +} + +static unsigned int switch_bit(unsigned int code) +{ + if(code == SW_LID || code == SW_KEYPAD_SLIDE) + return 1u << code; + return 0; +} + +static int device_switch_mask(int fd) +{ + unsigned char bits[16]; + unsigned int mask = 0; + memset(bits, 0, sizeof(bits)); + if(ioctl(fd, BA_EVIOCGSW(sizeof(bits)), bits) < 0) + return -1; + if(bits[SW_LID / 8] & (1u << (SW_LID % 8))) + mask |= switch_bit(SW_LID); + if(bits[SW_KEYPAD_SLIDE / 8] & (1u << (SW_KEYPAD_SLIDE % 8))) + mask |= switch_bit(SW_KEYPAD_SLIDE); + return (int)mask; +} + +static int current_switch_mask(int *found) +{ + glob_t gl; + size_t i; + int mask = 0; + *found = 0; + if(glob("/dev/input/event*", 0, NULL, &gl) != 0) + return 0; + for(i = 0; i < gl.gl_pathc; i++) { + int fd = open(gl.gl_pathv[i], O_RDONLY | O_NONBLOCK | O_CLOEXEC); + int devmask; + if(fd < 0) + continue; + if(!wanted_device(fd, WATCH_SWITCHES)) { + close(fd); + continue; + } + devmask = device_switch_mask(fd); + if(devmask >= 0) { + *found = 1; + mask |= devmask; + } + close(fd); + } + globfree(&gl); + return mask & (int)CLOSED_MASK; +} + +static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds, + int *switch_mask) +{ + int i; + for(i = 0; i < nfds; i++) { + struct input_event ev; + ssize_t nread = 0; + if(fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) { + drop_device(list, fds[i].fd); + continue; + } + if(!(fds[i].revents & POLLIN)) + continue; + while((nread = read(fds[i].fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) { + unsigned int bit; + if(ev.type != EV_SW) + continue; + bit = switch_bit(ev.code); + if(!bit) + continue; + if(ev.value) + *switch_mask |= (int)bit; + else + *switch_mask &= ~(int)bit; + } + if(nread < 0 && errno != EAGAIN && errno != EWOULDBLOCK && + errno != EINTR) { + drop_device(list, fds[i].fd); + } + } +} + +int main(void) +{ + int lock_fd = lock_singleton(LID_LOCK); + struct watch_list list; + long long now; + long long last_scan = 0; + long long last_transition = 0; + long long last_broadcast = 0; + long long candidate_since; + int evdev_found = 0; + int switch_mask; + int stable_closed; + int candidate; + int hall; + if(lock_fd < 0) + return 1; + install_reaper(); + memset(&list, 0, sizeof(list)); + switch_mask = current_switch_mask(&evdev_found); + if(evdev_found) + stable_closed = (switch_mask & (int)CLOSED_MASK) != 0; + else { + hall = hall_state(); + stable_closed = hall >= 0 ? hall : 0; + } + candidate = stable_closed; + now = now_ms(); + candidate_since = now; + write_lid_state(stable_closed); + cover_send(stable_closed ? "CLOSED" : "OPEN"); + last_broadcast = now; + while(1) { + struct pollfd fds[WATCH_MAX]; + int nfds = 0; + int i; + int observed; + now = now_ms(); + if(now - last_scan > 2000) { + scan_devices(&list, WATCH_SWITCHES); + last_scan = now; + if(list.count > 0 && !evdev_found) { + switch_mask = current_switch_mask(&evdev_found); + } + } + for(i = 0; i < list.count; i++) { + fds[nfds].fd = list.devs[i].fd; + fds[nfds].events = POLLIN; + fds[nfds].revents = 0; + nfds++; + } + if(poll(fds, (nfds_t)nfds, 100) < 0 && errno != EINTR) { + for(i = 0; i < list.count; i++) + drop_device(&list, list.devs[i].fd); + } + if(nfds > 0) + read_ready(&list, fds, nfds, &switch_mask); + if(list.count > 0) { + observed = (switch_mask & (int)CLOSED_MASK) != 0; + } else { + hall = hall_state(); + observed = hall >= 0 ? hall : + (switch_mask & (int)CLOSED_MASK) != 0; + } + if(observed != candidate) { + candidate = observed; + candidate_since = now; + } + if(candidate >= 0 && candidate != stable_closed && + now - candidate_since >= LID_STABLE_MS && + now - last_transition >= 150) { + stable_closed = candidate; + last_transition = now; + on_transition(stable_closed); + } + if(now - last_broadcast >= LID_BROADCAST_MS) { + write_lid_state(stable_closed); + cover_send(stable_closed ? "CLOSED" : "OPEN"); + last_broadcast = now; + } + } + return 0; +} diff --git a/src/bananarchy-daemons/bananarchy-volume-keys.c b/src/bananarchy-daemons/bananarchy-volume-keys.c new file mode 100644 index 0000000..d7e7a42 --- /dev/null +++ b/src/bananarchy-daemons/bananarchy-volume-keys.c @@ -0,0 +1,111 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +/* Compiled side-volume-key reader for nokia-beatles. No Python in the idle path. */ +#include + +#include "common.h" + +#define VOLUME_LOCK "/run/bananarchy-volume-keys.lock" + +#ifndef EV_KEY +#define EV_KEY 0x01 +#endif +#ifndef KEY_VOLUMEDOWN +#define KEY_VOLUMEDOWN 114 +#endif +#ifndef KEY_VOLUMEUP +#define KEY_VOLUMEUP 115 +#endif + +static char *const session_env[] = { + (char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin", + (char *)"HOME=/home/user", + (char *)"USER=user", + (char *)"DISPLAY=:0", + (char *)"XDG_RUNTIME_DIR=/run/user/10000", + (char *)"SHELL=/bin/sh", + NULL +}; + +static void apply_volume(const char *action) +{ + char *const argv[] = { + (char *)"/usr/bin/sxmo_audio.sh", (char *)"vol", (char *)action, + (char *)"5", NULL + }; + daemon_spawn_env(argv, (char *const *)session_env); +} + +static int stale_errno(int value) +{ + return value == ENODEV || value == EIO || value == EBADF || + value == EINVAL; +} + +static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds) +{ + int i; + for(i = 0; i < nfds; i++) { + struct input_event ev; + ssize_t nread; + if(fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) { + drop_device(list, fds[i].fd); + continue; + } + if(!(fds[i].revents & POLLIN)) + continue; + while((nread = read(fds[i].fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) { + if(ev.type != EV_KEY || ev.value != 1) + continue; + if(ev.code == KEY_VOLUMEUP) + apply_volume("up"); + else if(ev.code == KEY_VOLUMEDOWN) + apply_volume("down"); + } + if(nread < 0 && errno != EAGAIN && errno != EWOULDBLOCK && + errno != EINTR) { + if(stale_errno(errno)) + drop_device(list, fds[i].fd); + else + drop_device(list, fds[i].fd); + } + } +} + +int main(void) +{ + int lock_fd = lock_singleton(VOLUME_LOCK); + struct watch_list list; + long long last_scan = 0; + if(lock_fd < 0) + return 1; + install_reaper(); + memset(&list, 0, sizeof(list)); + while(1) { + long long now = now_ms(); + struct pollfd fds[WATCH_MAX]; + int nfds = 0; + int i; + if(now - last_scan > 2000) { + scan_devices(&list, WATCH_VOLUME_KEYS); + last_scan = now; + } + if(list.count == 0) { + poll(NULL, 0, 500); + continue; + } + for(i = 0; i < list.count; i++) { + fds[nfds].fd = list.devs[i].fd; + fds[nfds].events = POLLIN; + fds[nfds].revents = 0; + nfds++; + } + if(poll(fds, (nfds_t)nfds, 1000) < 0 && errno != EINTR) { + for(i = 0; i < list.count; i++) + drop_device(&list, list.devs[i].fd); + } + read_ready(&list, fds, nfds); + } + return 0; +} diff --git a/src/bananarchy-daemons/common.h b/src/bananarchy-daemons/common.h new file mode 100644 index 0000000..f44f6f3 --- /dev/null +++ b/src/bananarchy-daemons/common.h @@ -0,0 +1,238 @@ +/* Shared helpers for the compiled Bananarchy idle daemons. */ +#ifndef BANANARCHY_DAEMONS_COMMON_H +#define BANANARCHY_DAEMONS_COMMON_H + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WATCH_MAX 32 +#define SESSION_UID 10000 +#define SESSION_GID 10000 +#define BA_UNUSED __attribute__((unused)) + +#define EV_KEY 0x01 +#define EV_SW 0x05 +#define KEY_MAX 0x2ff +#define SW_LID 0x00 +#define SW_KEYPAD_SLIDE 0x0a +#define KEY_VOLUMEDOWN 114 +#define KEY_VOLUMEUP 115 +#define BA_IOC(dir, type, nr, size) \ + (((unsigned int)(dir) << 30) | ((unsigned int)(type) << 8) | \ + ((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16)) +#define BA_EVIOCGBIT(ev, len) \ + BA_IOC(2U, 'E', 0x20U + (unsigned int)(ev), (unsigned int)(len)) + +struct input_event { + struct timeval time; + uint16_t type; + uint16_t code; + int32_t value; +}; + +enum watch_filter { + WATCH_ALL = 0, + WATCH_SWITCHES, + WATCH_VOLUME_KEYS, +}; + +struct watch_dev { + int fd; + ino_t ino; + char path[64]; +}; + +struct watch_list { + struct watch_dev devs[WATCH_MAX]; + int count; +}; + +static BA_UNUSED void safe_copy(char *dst, size_t len, const char *src) +{ + size_t n; + if(len == 0) + return; + n = strlen(src); + if(n >= len) + n = len - 1; + memcpy(dst, src, n); + dst[n] = '\0'; +} + +static BA_UNUSED int write_text_file(const char *path, const char *value) +{ + int fd = open(path, O_WRONLY | O_CLOEXEC); + if(fd < 0) + return -1; + if(write(fd, value, strlen(value)) < 0) { + close(fd); + return -1; + } + close(fd); + return 0; +} + +static BA_UNUSED int lock_singleton(const char *path) +{ + int fd = open(path, O_CREAT | O_RDWR | O_CLOEXEC, 0644); + if(fd < 0) + return -1; + if(flock(fd, LOCK_EX | LOCK_NB) < 0) { + close(fd); + return -1; + } + return fd; +} + +static BA_UNUSED void reap_children(int sig) +{ + int saved = errno; + (void)sig; + while(waitpid(-1, NULL, WNOHANG) > 0) { + } + errno = saved; +} + +static BA_UNUSED void install_reaper(void) +{ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = reap_children; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; + sigaction(SIGCHLD, &sa, NULL); +} + +static BA_UNUSED void daemon_spawn_env(char *const argv[], char *const envp[]) +{ + pid_t pid = fork(); + if(pid < 0) + return; + if(pid > 0) + return; + int nullfd = open("/dev/null", O_RDWR); + if(nullfd >= 0) { + dup2(nullfd, STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + if(nullfd > STDERR_FILENO) + close(nullfd); + } + if(setgid(SESSION_GID) == 0 && setuid(SESSION_UID) == 0) + execve(argv[0], argv, envp); + _exit(127); +} + +static BA_UNUSED void drop_device(struct watch_list *list, int fd) +{ + int i; + for(i = 0; i < list->count; i++) { + if(list->devs[i].fd != fd) + continue; + close(list->devs[i].fd); + memmove(&list->devs[i], &list->devs[i + 1], + sizeof(list->devs[0]) * (size_t)(list->count - i - 1)); + list->count--; + return; + } +} + +static BA_UNUSED int device_has_code(int fd, unsigned int ev, unsigned int code) +{ + unsigned char bits[(KEY_MAX + 7) / 8 + 1]; + memset(bits, 0, sizeof(bits)); + if(ioctl(fd, BA_EVIOCGBIT(ev, sizeof(bits)), bits) < 0) + return 0; + if(code >= sizeof(bits) * 8) + return 0; + return (bits[code / 8] & (1u << (code % 8))) != 0; +} + +static BA_UNUSED int wanted_device(int fd, enum watch_filter filter) +{ + if(filter == WATCH_ALL) + return 1; + if(filter == WATCH_SWITCHES) { + return device_has_code(fd, EV_SW, SW_LID) || + device_has_code(fd, EV_SW, SW_KEYPAD_SLIDE); + } + return device_has_code(fd, EV_KEY, KEY_VOLUMEUP) || + device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN); +} + +static BA_UNUSED void prune_devices(struct watch_list *list) +{ + int i; + for(i = list->count - 1; i >= 0; i--) { + struct stat st; + if(stat(list->devs[i].path, &st) == 0 && st.st_ino == list->devs[i].ino) + continue; + drop_device(list, list->devs[i].fd); + } +} + +static BA_UNUSED void scan_devices(struct watch_list *list, enum watch_filter filter) +{ + glob_t gl; + size_t i; + prune_devices(list); + if(glob("/dev/input/event*", 0, NULL, &gl) != 0) + return; + for(i = 0; i < gl.gl_pathc && list->count < WATCH_MAX; i++) { + const char *path = gl.gl_pathv[i]; + struct stat st; + int j; + int fd; + int seen = 0; + if(stat(path, &st) < 0) + continue; + for(j = 0; j < list->count; j++) { + if(list->devs[j].ino == st.st_ino) { + seen = 1; + break; + } + } + if(seen) + continue; + fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); + if(fd < 0) + continue; + if(!wanted_device(fd, filter)) { + close(fd); + continue; + } + list->devs[list->count].fd = fd; + list->devs[list->count].ino = st.st_ino; + strncpy(list->devs[list->count].path, path, + sizeof(list->devs[list->count].path) - 1); + list->devs[list->count].path[sizeof(list->devs[0].path) - 1] = '\0'; + list->count++; + } + globfree(&gl); +} + +static BA_UNUSED long long now_ms(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL; +} + +#endif diff --git a/src/dwm-plugins/locker_plugin.cpp b/src/dwm-plugins/locker_plugin.cpp index 3fe6893..a92967a 100644 --- a/src/dwm-plugins/locker_plugin.cpp +++ b/src/dwm-plugins/locker_plugin.cpp @@ -781,7 +781,7 @@ int locker_run_main(int argc, char** argv) { XFlush(dpy); visible = false; } - writeSoftkeySuppress(nowMs() + 350); + writeSoftkeySuppress(nowMs() + 120); setSxmoStateFile("unlock"); wakeScreenBacklight(); wasScreenBlanked = false; @@ -809,7 +809,7 @@ int locker_run_main(int argc, char** argv) { statusMsg.clear(); statusIsError = false; lockActivatedMs = now; - writeSoftkeySuppress(now + 400); + writeSoftkeySuppress(now + 120); } if (!visible) { XMapRaised(dpy, win); @@ -887,7 +887,7 @@ int locker_run_main(int argc, char** argv) { render(); return; } - if (now - lockActivatedMs < 80) { + if (now - lockActivatedMs < 40) { return; } @@ -1096,7 +1096,15 @@ int locker_run_main(int argc, char** argv) { } continue; } - // Ignore CLOSE while locked so external scripts cannot dismiss the lockscreen + // A trusted root lid daemon clears the lock flag before sending CLOSE. + // If the flag is gone, release any stale locker grab/window immediately; + // otherwise ignore CLOSE so user scripts cannot dismiss the lockscreen. + if(cmd == "CLOSE" || cmd == "UNLOCK") { + if(::access(kLockFlagPath, F_OK) != 0 && (visible || grabHeld)) { + unlockPhone(false); + } + continue; + } } } diff --git a/src/leds-msm8905-torch/leds-msm8905-torch.c b/src/leds-msm8905-torch/leds-msm8905-torch.c index 46967eb..b0b6731 100644 --- a/src/leds-msm8905-torch/leds-msm8905-torch.c +++ b/src/leds-msm8905-torch/leds-msm8905-torch.c @@ -210,11 +210,10 @@ static unsigned int msm8905_pon_prepare_restart_mode(const char *cmd) strcmp(trimmed, "fastboot") == 0) { if (pon_regmap) { /* - * Stock Nokia aboot (0x2327c) reads PON_SOFT_RB_SPARE (0x088f), clears - * bits [7:2] via `and r1, r4, #3`, and writes bits [1:0] back to 0x088f - * before chainloading lk2nd from the boot partition. - * Write 0x02 (FASTBOOT_MODE = 2 in bits [1:0], 0 in bits [7:2]) so - * stock aboot boots lk2nd normally and lk2nd enters its Fastboot menu. + * The stock boot chain scrubs PON_SOFT_RB_SPARE[7:2] and passes + * bits [1:0] through to the chain-loaded lk2nd image. The beatles + * lk2nd port reads those low bits as the reboot reason, so 0x02 + * selects FASTBOOT_MODE and shows the menu instead of booting Linux. */ regmap_write(pon_regmap, QPNP_PON_SOFT_RB_SPARE, 0x02U); }