Files
geminux/ARCHITECTURE.md
T

117 lines
16 KiB
Markdown
Raw Normal View History

# Architecture
Geminux combines a custom-patched Linux `7.3.5` kernel, pure-Linux MTK flasher, XLibre graphics server, patched suckless desktop, unified `.Xresources` + wallpaper engine, and zero-poll C11 daemons packaged as signed Alpine APKs so standard Alpine Edge updates continue working cleanly.
## Kernel and MediaTek MT6797X support
Vanilla Linux `7.3.5` is built from [patches/kernel/](patches/kernel/) with built-in IPsec (`CONFIG_XFRM_USER=y`, `esp4`, `esp6`, `af_key`, `xfrm_interface`) for 3GPP IMS alongside Gemini PDA hardware support:
| Patch | Purpose |
| --- | --- |
| `0001-ixoo-gemini-pda-mainline-7.3.5.patch` | Core MT6797X / Gemini PDA mainline `7.3.5` platform, DRM, keypad, PMIC, and fuel-gauge base |
| `0002-mt6797-ccci-cldma-and-md1-domain.patch` | Staged `mt6797-ccci-cldma` baseband transport and MD1 power-domain support |
| `0003-arm64-dts-mediatek-geminux-gemini-pda.patch` | Geminux Device Tree bindings, pinmux, regulators, and peripheral wiring |
| `0004-gemini-ssd2092-display-and-touch.patch` | Solomon Systech `SSD2092` DSI FHD+ panel and multi-touch controller fixes |
| `0005-mt6797-consys-wifi-factory-firmware.patch` | MT6797 CONSYS Wi-Fi/BT driver and factory firmware/NVRAM loading |
| `0006-mt6797-boot-cleanups.patch` | Early boot and console noise cleanups |
| `0007-mt6797-wlan-peer-deauth-and-rekey.patch` | WLAN station deauth recovery and GTK rekey stability |
| `0008-gemini-resume-wake-and-spm-standby.patch` | S3 resume wake handling, `mt6797-spm-sleep` standby, `mtk-eint` debounce clear, and `mtk-pmic-keys` wakeups |
| `0009-mt6797-wlan-drop-free-stability.patch` | CONSYS WLAN RX/TX buffer drop-free stability under load |
| `0010-mt6797-ccci-md1-boot-hs-v2-and-rpc.patch` | MD1 boot handshake v2 and CCCI RPC stabilization |
| `0011-gemini-lid-sync-filter-and-debounce.patch` | Synchronous Hall `GPIO66` lid-close keystroke/touch filtering, `1 ms` Hall EINT & `10 ms` keypad debounce, and touch inhibit |
| `0012-gemini-lid-wake-and-fg-taper-fix.patch` | `gemini-lid` `PM_POST_SUSPEND` + raw-GPIO reconciliation (`BL_CORE_SUSPENDED`/input lockout fix) and `mt6351` + `bq25890` zero-current OCV calibration, CV-taper checks, `+1%` cap, and `180 mV` `ADC21` sag tolerance |
| `0013-gemini-pmic-wake-and-spm-safety.patch` | Moves `mt6397_irq_suspend`/`mt6397_irq_resume` from `PM_SUSPEND_PREPARE` into `LATE_SYSTEM_SLEEP_PM_OPS` so child `enable_irq_wake()` settings arm cleanly before deep sleep; hardens `mt6797-spm-sleep` `s.sleep` with `WAKE_PCM_WDT`, `pcm_wdt`, `im_wait` (`1000 us`), and a `5000 ms` `cntp` physical timer backstop (`100 ms` on `s.sodi`) |
### Hardware subsystems
- **Graphics & display**: MediaTek DRM (`mediatek-drm`), `SSD2092` DSI FHD+ panel/touch, early-boot `simpledrm` (`DRM_SIMPLEDRM=y` + rotated `TER16x32` console), Mali-T880 `panfrost` GPU, and `sii902x` Slimport/HDMI bridge.
- **Wi-Fi / Bluetooth CONSYS**: Staged `mt6797_wlan_core` and `btmt6797` drivers backed by NVRAM/factory firmware provisioning (`geminux-wifi-nvram` and `firmware-cache/mt6797/`), hardened by `0007` and `0009`.
- **Modem / Telephony / eSIM / IMS**: `mt6797-ccci-cldma` exposes `/dev/ccci_md_ctl`, `/dev/ccci_fs`, `/dev/ccci_rpc`, `/dev/ttyC0..3`, and `ccmni*` via the 16-byte `struct mt6797_ccci_header` UAPI ([prebuilt/kernel/include/linux/mt6797_ccci.h](prebuilt/kernel/include/linux/mt6797_ccci.h)):
- [geminux-ccci-fs.c](src/geminux-daemons/geminux-ccci-fs.c) (`geminux-ccci-daemon`): MD1 boot HS v2, NVRAM/CCCI_FS I/O, and RPC (`MD_STATE=READY`).
- [geminux-cellctl.c](src/geminux-daemons/geminux-cellctl.c) (`geminux-cellctl`): physical SIM vs. ST33 eUICC `AT+ESIMS` switching, `lpac` AT-`CSIM`/`CGLA` APDU bridging, and `ccmni*` LTE PDN bring-up.
- [geminux-imsd.c](src/geminux-daemons/geminux-imsd.c) (`geminux-imsd`): 3GPP VoLTE (`ccmni*`) & VoWiFi (`SWu` IKEv2/IPsec via `strongswan`), MILENAGE AKA, kernel XFRM `ipsec-3gpp` (with RFC 4303 userspace ESP fallback), SIP signaling, `RP-DATA` SMS, and 20 ms `timerfd` AMR-NB/AMR-WB/G.711/DTMF RTP bridged to PipeWire/ALSA `VoiceCall`.
- **Boot, LUKS2 FDE & recovery**: LK-compatible images (`images/boot-geminux.img`, `images/recovery-geminux.img`) built with `mkbootimg-osm0sis` (`16 MiB` boot ceiling, `512 KiB` DTB ceiling). Built-in `BLK_DEV_DM=y`, `DM_CRYPT=y`, and ARMv8 AES-CE (`CRYPTO_AES_ARM64_CE_BLK=y`) power initramfs unlock (`cryptsetup` + `/etc/gemini-us.kmap`, `DM_DISABLE_UDEV=1`). [src/initramfs/init](src/initramfs/init) runs the off-mode charger guard, optionally unlocks `PARTLABEL=linux` -> `/dev/mapper/geminux_root`, checks ext4 (`e2fsck -p </dev/null`), and expands the filesystem on first boot (`resize2fs -f </dev/null`). [src/initramfs/init-recovery](src/initramfs/init-recovery) provides a USB NCM/RNDIS shell (`172.16.42.1/24`) with LUKS2-aware `unlock-root`, `check-fs`, and `mount-root`.
## Graphics, window management, and stability
### XLibre (`25.x`)
Cross-compiled against pure Alpine Edge `aarch64` sysroots with `modesetting_drv.so`, `fbdev_drv.so`, `libinput_drv.so`, and Panfrost Glamor EGL (`libglamoregl.so`) via [scripts/build-xlibre.sh](scripts/build-xlibre.sh). [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf) sets `AccelMethod "none"`, `ShadowFB "true"`, `TearFree "true"`, `PageFlip "false"`, `SWcursor "true"`, and `Rotate "left"` to prevent rotated DSI tearing and Glamor fence spin-wait overhead while keeping Panfrost EGL/OpenGL 3D active for applications. Zero Wayland compositors are installed.
### Patched suckless desktop
- **`dwm`**:
- **Systray & stacking**: 32-bit ARGB XEmbed systray (`_NET_SYSTEM_TRAY_S0`), XEmbed reparent/input race protection, and automatic restacking below fullscreen lockscreen windows.
- **EWMH / ICCCM / NETWM**: `_NET_WORKAREA` dock struts, `_NET_WM_STATE_{FOCUSED,STICKY,ABOVE,HIDDEN}`, desktop/PID atoms, `WM_CHANGE_STATE`, `nofocuswin` fallback, and Wine/DXVK focus recovery.
- **X11 / Pango hardening**: `in_xerror` recursion guard with rate-limited non-fatal `RENDER` error ignoring, bounded `200 ms` `getservertime()` polling, async grab safety (`AsyncBoth` / `GrabModeAsync`), and Pango `PANGO_ELLIPSIZE_END` + `FC_COLOR=FcFalse` + UTF-8 sanitization in `drw.c` (avoiding XRender `BadLength` faults on color emoji glyphs).
- **Gemini UX**: `>= 78 px` touch top bar, `Mod4 = Fn+Alt` + one-shot `Super_L` tap-latch, `Fn+F` Airplane Mode binding, `Mod4 + Shift + r` & `SIGUSR1` `.Xresources` reload, and `SIGHUP` self-reexec.
- **`dmenu`**: Pango/HarfBuzz rendering with `82 px` touch rows, `dmenu_xerror` recursion & non-fatal `RENDER` guards, `FC_COLOR=FcFalse` + UTF-8 sanitization, and direct mouse/touch selection. Pairs with `geminux-launcher` pinning the 11 GUI apps alongside `Wallpaper`, `Webarchy Browser`, `Bantam AI agent`, and `Lynx Web Browser` in `st` (wrapping `Terminal=true` `.desktop` entries in `st -e`).
- **`st`**: HarfBuzz Fira Code ligatures (`hb.c`), Nerd Font fallback, mouse/two-finger wheel scrollback, immediate cursor redraw on `FocusIn`/`FocusOut` + unfocused blink gating, and live theme reloading via both direct `XA_RESOURCE_MANAGER` `PropertyNotify` and `SIGUSR1`.
- **Notifications**: Pure-X11 zero-`gdk-pixbuf` `dunst v1.12.2` (`WAYLAND=0 DUNSTIFY=0`) with custom pure-C PNG/JPEG icon loader ([src/dunst-notify/](src/dunst-notify/)) and lightweight GDBus `notify-send` / `dunstify`.
## Unified theming and native X11 wallpaper engine
Geminux defaults to the **Anodized** theme (`192 DPI`, `baseFontSize: 32`, `Xcursor.size: 64`) across `/etc/skel/.Xresources` and all compiled-in and script fallbacks. On login, `geminux-session` non-destructively copies newly added `/etc/skel/.xthemes/*.xth` themes into `~/.xthemes/` and loads `~/.Xresources` cleanly via `xrdb -nocpp -load`.
### Theme editor, importer & toolkit synchronization
- **Editor & Importer**: [geminux-xth.h](src/geminux-apps/geminux-xth.h) provides shared `.xth` parsing/serialization for `geminux-themes` (`Edit`, `Duplicate`, `New`, `Reset`/`Delete`, live WCAG contrast ratio against `bgMain`, and `Import .xth` stored under `~/.config/geminux/themes/`).
- **Synced targets**: `geminux-apply-theme` (`.xth` -> `~/.Xresources` + `xrdb -nocpp -load`) synchronizes:
- **Dunst**: `~/.config/dunst/dunstrc` via `geminux-sync-dunst-theme`
- **GTK2 / GTK3 / `xsettingsd`**: `Geminux-<Theme>` light/dark styling in `~/.gtkrc-2.0`, `~/.config/gtk-3.0/{settings.ini,gtk.css}`, and `~/.config/xsettingsd/xsettingsd.conf` (`SIGHUP` reload)
- **GTK4 & `libadwaita`**: `~/.config/gtk-4.0/{settings.ini,gtk.css}` + `dconf` `color-scheme` (`ADW_DISABLE_PORTAL=1` in [10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh))
- **Qt5 / Qt6**: `qt6ct` 21-role `QPalette` (`QT_QPA_PLATFORMTHEME=qt6ct:gtk3`) and Kvantum (`QT_STYLE_OVERRIDE=kvantum`)
- **Tcl/Tk (`gtkTtk 0.9`)**: `*TkTheme: gtkTtk` + DPI-scaled widget geometry against `~/.gtkrc-2.0` with pure-X11 XImage blitting and zero-poll `XA_RESOURCE_MANAGER` live reload ([src/gtkTtk/](src/gtkTtk/))
- **X11 clients**: Instant redraw via `XA_RESOURCE_MANAGER` `PropertyNotify` and `SIGUSR1` (`dwm`, `st`, `webarchy`, `libgemui`)
### Native X11 + Cairo wallpaper engine
- **Core engine**: [geminux-wallpaper.h](src/geminux-apps/geminux-wallpaper.h) (pure-C11 config & placement geometry) + [geminux-wallpaper-x11.h](src/geminux-apps/geminux-wallpaper-x11.h) (X11/Cairo renderer) integrated into `geminux-themes` and exposed to CLI via `geminux-apply-wallpaper`.
- **Image decoders**: Decodes via runtime `dlopen("libgdk_pixbuf-2.0.so.0")` (EXIF auto-orientation + PNG/JPEG/GIF/BMP/ICO/XPM/XBM/TGA/PNM powered by `geminux-gdk-pixbuf`), Cairo PNG, `libjpeg-turbo`, `libwebp`, and optional `magick`/`convert` fallback.
- **Root Pixmap protocol**: Renders onto an X11 root `Pixmap` using a dedicated `Display` connection with `XSetCloseDownMode(..., RetainPermanent)`, publishing `_XROOTPMAP_ID` and `ESETROOT_PMAP_ID` and cleaning up previous clients via `XKillClient`. Supports multi-monitor geometry via XRandR and Xinerama.
- **Persistence & hooks**: Saves state to `~/.config/geminux/wallpaper.conf` and restores automatically on login (`geminux-session`), on theme changes when `USE_THEME_BG=1` (`geminux-apply-theme`), and after external HDMI `xrandr` layout switches (`geminux-net`).
### Webarchy, pure-C `gdk-pixbuf` & media stack
- **Webarchy**: [src/webarchy/webarchy.cpp](src/webarchy/webarchy.cpp) is a C++20 `GTK3` + `WebKit2GTK-4.1` browser tuned for `2160x1080` (`1080x506` logical @ `GDK_SCALE=2`) with a collapsible right-side vertical tab bar, `SIGUSR1` `.Xresources` reloading, SQLite cookies/bookmarks, single-instance FIFO forwarding, and WebProcess crash software fallback.
- **Pure-C `gdk-pixbuf` & schemas**: [scripts/build-webarchy.sh](scripts/build-webarchy.sh) cross-compiles pure-C GNOME `gdk-pixbuf 2.42.12` (`-Dbuiltin_loaders=all`, zero `libglycin`/`librsvg`), and [scripts/compile-gsettings-schemas.sh](scripts/compile-gsettings-schemas.sh) builds `/usr/share/glib-2.0/schemas/gschemas.compiled`.
- **Media & `yt-dlp`**: Native Alpine Edge `mpv` ([overlay/rootfs/etc/mpv/mpv.conf](overlay/rootfs/etc/mpv/mpv.conf) — Panfrost X11 EGL, PipeWire/Pulse/ALSA, `/tmp/geminux-mpv.sock` IPC), `ffmpeg`/`ffprobe`, `gst-libav`, `mpg123`, `openmpt123`, `python3`/`py3-pip`, and `yt-dlp` (`quickjs`, avoiding `deno`/`py3-cryptography`).
## Custom UI toolkit and zero-poll C11 daemons
- **`libgemui.so`** ([src/libgemui/](src/libgemui/)): Double-buffered Cairo + Pango/HarfBuzz Xlib toolkit with direct `XA_RESOURCE_MANAGER` `PropertyNotify` and `SIGUSR1` `.Xresources` live reloads, fullscreen lockscreen visibility restacking, button contrast guards, X11 clipboard paste, dynamic timers, `MSG_NOSIGNAL` socket IPC (`gemui_unix_cmd`), and non-blocking extra FDs.
- **11 landscape HiDPI apps** ([src/geminux-apps/](src/geminux-apps/)): `geminux-control`, `geminux-audio`, `geminux-datetime`, `geminux-net` (Wi-Fi, Cellular/ST33 eSIM, Bluetooth, HDMI, `DNS` tab, Airplane Mode), `geminux-dialer`, `geminux-callscreen`, `geminux-sms`, `geminux-contacts`, `geminux-camera`, `geminux-themes` (Themes, Theme Editor, `.xth` Importer & Wallpaper), and `geminux-lock`.
- **Zero-poll C11 daemons** ([src/geminux-daemons/](src/geminux-daemons/)):
- **`geminux-powerd`**: `epoll` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC`), filtered `KOBJECT_UEVENT` (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and `timerfd`:
- Enforces `inhibit_ac_lid` (locks/blanks without unloading CONSYS or calling `/sys/power/state` while on USB/AC).
- Tears down `mt6797_consys` and parks `cpu1..9` offline before battery `mem` suspend or zero-thrash `low_power_standby` when `MD1` is active (never `freeze`/`s2idle`).
- Polls post-resume input/lid events (`90 ms`) even when the lid is open so only a `closed -> open` lid transition, real `EV_KEY`/`EV_REL`/`EV_ABS` activity, or USB/AC attach counts as a wake; internal timer wakes during open-lid idle lock re-suspend cleanly (`quiet_timer_resleep`) without reloading CONSYS or waking the backlight.
- Persists hardware Airplane Mode (`/var/lib/geminux/airplane-mode`) and resolves UID `10000` dynamically.
- **`geminux-statusd`**: `epoll` over `signalfd` (`SIGUSR1`), `RTMGRP_LINK`/`RTMGRP_IPV4_IFADDR`, filtered `KOBJECT_UEVENT` (`power_supply`, `net`), `inotify`, and minute-aligned `timerfd`; shows `AIRPLANE` status and deduplicates `WM_NAME` updates with zero shell forks.
- **`geminux-touchd`**: XInput 2.2 multi-touch gesture recognizer.
- **`geminux-leds`**: AW9120 back cover RGB controller (`/run/geminux/leds.sock`, off when idle/100%, amber `rgb:indicator-6` while charging, persistent manual override).
- **`geminux-ccci-daemon`, `geminux-cellctl`, `geminux-imsd`, `geminux-modem-ctl`, `geminux-bt-obex`, `geminux-dnsctl`, `geminux-power-ctl`, `geminux-power-audit`, `geminux-tzctl`, `geminux-wifi-nvram`, `geminux-checkpw`**: Event-driven platform daemons and control helpers.
## APK package pinning and package policy
1. **Pure Edge rootfs**: Host Docker containers use `postmarketos/v26.06` only for `gcc-aarch64`, `binutils-aarch64`, and `mkbootimg-osm0sis`. Both `$SYSROOT` and target `$ROOTFS` come strictly from **Alpine Edge** (`main`, `community`, `testing`) plus the RSA-4096 signed local `@geminux` repo (`/var/lib/geminux/apk-repo`).
2. **Eleven signed local packages**: [scripts/package-local-apks.sh](scripts/package-local-apks.sh) builds and indexes:
- `geminux-kernel-modules`
- `geminux-xlibre`
- `geminux-suckless`
- `geminux-dunst`
- `geminux-ui`
- `geminux-bantam` ([scripts/build-bantam.sh](scripts/build-bantam.sh))
- `geminux-gsocket` ([scripts/build-gsocket.sh](scripts/build-gsocket.sh))
- `geminux-gdk-pixbuf` ([scripts/build-webarchy.sh](scripts/build-webarchy.sh))
- `geminux-webarchy` ([scripts/build-webarchy.sh](scripts/build-webarchy.sh))
- `geminux-gtkttk` ([scripts/build-gtkttk.sh](scripts/build-gtkttk.sh))
- `geminux-config` (`/etc/mpv/mpv.conf`, `/etc/htoprc`, `~/.lynx.cfg`, `~/.apexrc`, `~/.bashrc` with `GPG_TTY`, `/etc/profile.d/10-geminux-env.sh`, `/etc/init.d/geminux-sdcard` + `95-geminux-sdcard.rules` + `/usr/sbin/geminux-sdcard-mount`)
3. **World pins & exclusions**: `/etc/apk/world` exact-pins all 11 with `name@geminux=version` and blocks Rust/Wayland/override packages via `!` constraints from [scripts/rootfs-prune-packages.txt](scripts/rootfs-prune-packages.txt) (`librsvg`, `rav1e`/`rav1e-libs`, `libdovi` whitelisted). Enforced by ELF Rust scans, `apk upgrade --simulate`, and 9 host Python test suites in [scripts/check-rebuild.sh](scripts/check-rebuild.sh).
4. **Config protection**: `/etc/apk/protected_paths.d/geminux.list` shields Geminux config directories across `apk upgrade`.
## Pure-Linux flasher and eMMC layout
[flash-mtk.py](flash-mtk.py) embeds vendored GPLv3 `mtkclient` + `MTK_DA_V5_MT6797.bin` to communicate directly over USB BROM/DA. Protected partitions in `LBA 0..0x6FFFF` (`preloader`, `nvram`, `proinfo`, `lk`, `tee1`, `md1img`, etc.) are backed up and write-blocked by default (`0x0E000000` boundary verified in [scripts/test-flash-mtk-gpt.py](scripts/test-flash-mtk-gpt.py)).
On staged copies of `geminux-rootfs.img` (without modifying `images/geminux-rootfs.img`), [scripts/geminux_accounts.py](scripts/geminux_accounts.py) handles offline `$6$` SHA-512 `/etc/{passwd,group,shadow}` and `/home/<username>` provisioning via `debugfs`/`e2fsck`, and [scripts/geminux_luks.py](scripts/geminux_luks.py) optionally wraps the staged ext4 image in LUKS2 via unprivileged host `cryptsetup reencrypt --encrypt --disable-locks`.