Files
geminux/ARCHITECTURE.md
T

57 lines
9.9 KiB
Markdown

# Architecture
Geminux pairs a custom-patched Linux `7.3.5` kernel with XLibre X11, a hardened suckless desktop, unified `.Xresources` + native wallpaper rendering, zero-poll C11 daemons, pure-Linux MTK flashing/packaging tooling, and signed local APK pinning.
## Kernel and MediaTek MT6797X support
Vanilla Linux `7.3.5` builds from [patches/kernel/](patches/kernel/) with `CONFIG_XFRM_USER=y` and IPsec modules (`esp4`, `esp6`, `af_key`, `xfrm_interface`) for 3GPP IMS:
| Patch | Summary |
| --- | --- |
| `0001-ixoo-gemini-pda-mainline-7.3.5.patch` | Core MT6797X / Gemini PDA `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 domains |
| `0003-arm64-dts-mediatek-geminux-gemini-pda.patch` | Device Tree pinmux, regulators, and peripheral bindings |
| `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` | CONSYS Wi-Fi/BT drivers and NVRAM/factory firmware loading |
| `0006-mt6797-boot-cleanups.patch` | Early boot and console cleanups |
| `0007-mt6797-wlan-peer-deauth-and-rekey.patch` | WLAN peer deauth recovery and GTK rekey stability |
| `0008-gemini-resume-wake-and-spm-standby.patch` | S3 resume wakes, `mt6797-spm-sleep` standby, `mtk-eint` debounce clear, `mtk-pmic-keys` |
| `0009-mt6797-wlan-drop-free-stability.patch` | CONSYS WLAN RX/TX buffer drop-free handling 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` | Hall `GPIO66` synchronous lid filtering, `1 ms` Hall / `10 ms` keypad debounce, touch inhibit |
| `0012-gemini-lid-wake-and-fg-taper-fix.patch` | `PM_POST_SUSPEND` + raw-GPIO lid reconciliation and `mt6351`+`bq25890` zero-current OCV/taper fuel gauge |
| `0013-gemini-pmic-wake-and-spm-safety.patch` | Moves `mt6397_irq_suspend`/`resume` to `LATE_SYSTEM_SLEEP_PM_OPS` and adds SPM `WAKE_PCM_WDT` + `5000 ms` `cntp` backstop |
| `0014-gemini-deep-sleep-power-drainers.patch` | PMIC sleep modes (`pmic_modes=1`, `0.700 V` VCORE clamp), MD1-active SPM `mem` suspend (`allow_md1=1`, `CCIF0`/`CLDMA`/`MD1_WDT` wakes, RF LDO low-IQ), Panfrost `VGPU`/LDO/`MFGPLL` suspend rail-off, and MD1 stage-0 clock/PLL gating |
- **Graphics & Radios**: `mediatek-drm` + `SSD2092` DSI/touch, early `simpledrm` (`DRM_SIMPLEDRM=y` + rotated `TER16x32` console), Mali-T880 `panfrost`, `sii902x` HDMI bridge, and `mt6797_wlan_core`/`btmt6797` CONSYS.
- **Modem / eSIM / IMS**: `mt6797-ccci-cldma` exposes `/dev/ccci_*`, `/dev/ttyC0..3`, and `ccmni*` via `struct mt6797_ccci_header` ([mt6797_ccci.h](prebuilt/kernel/include/linux/mt6797_ccci.h)). [geminux-ccci-fs.c](src/geminux-daemons/geminux-ccci-fs.c) serves MD1 boot HS v2 / NVRAM / RPC; [geminux-cellctl.c](src/geminux-daemons/geminux-cellctl.c) manages SIM/ST33 eUICC (`lpac`) & `ccmni*` PDNs; [geminux-imsd.c](src/geminux-daemons/geminux-imsd.c) implements VoLTE/VoWiFi (`strongswan` `SWu`), MILENAGE AKA, XFRM `ipsec-3gpp`, SIP, `RP-DATA` SMS, and 20 ms RTP.
- **Boot, LUKS2 FDE & Recovery**: `mkbootimg-osm0sis` packs LK images (`<= 16 MiB` boot/recovery, `<= 512 KiB` DTB). Built-in `BLK_DEV_DM=y`, `DM_CRYPT=y`, and ARMv8 AES-CE (`CRYPTO_AES_ARM64_CE_BLK=y`) power LUKS2 unlock in [src/initramfs/init](src/initramfs/init) (`cryptsetup` + `/etc/gemini-us.kmap`, `DM_DISABLE_UDEV=1`, `e2fsck -p`, `resize2fs -f`). [src/initramfs/init-recovery](src/initramfs/init-recovery) provides a USB NCM shell (`172.16.42.1/24`) with LUKS2-aware helpers. See [POWER-OPTIMIZATION.md](POWER-OPTIMIZATION.md) for suspend and CPU/power architecture.
## Graphics, window management, and stability
- **XLibre (`25.x`)**: Cross-compiled against pure Alpine Edge `aarch64` sysroots ([scripts/build-xlibre.sh](scripts/build-xlibre.sh)). [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf) uses `AccelMethod "none"`, `ShadowFB "true"`, `TearFree "true"`, `PageFlip "false"`, `SWcursor "true"`, and `Rotate "left"` to avoid rotated DSI tearing while keeping Panfrost EGL/OpenGL 3D enabled. Zero Wayland compositors are installed.
- **`dwm`**: 32-bit ARGB XEmbed systray (`_NET_SYSTEM_TRAY_S0`, reparent/input race fixes, restacked under fullscreen lockscreen); EWMH/ICCCM/NETWM (`_NET_WORKAREA` struts, `_NET_WM_STATE_{FOCUSED,STICKY,ABOVE,HIDDEN}`, `WM_CHANGE_STATE`, `nofocuswin`, Wine/DXVK focus recovery); `in_xerror` recursion & non-fatal `RENDER` error guards, bounded `200 ms` `getservertime()`, async pointer/button grabs; Pango `PANGO_ELLIPSIZE_END`, `FC_COLOR=FcFalse`, and UTF-8 sanitization in `drw.c`; `>= 78 px` bar, `Mod4` tap-latch, `Fn+F`, `Mod4+Shift+r`/`SIGUSR1` `.Xresources` reload, and `SIGHUP` self-reexec.
- **`dmenu` & `st` & `dunst`**: `dmenu` uses Pango/HarfBuzz `82 px` rows, `dmenu_xerror`/`RENDER` guards, `FC_COLOR=FcFalse`, UTF-8 sanitization, and pairs with `geminux-launcher`. `st` adds HarfBuzz Fira Code ligatures (`hb.c`), wheel scrollback, `FocusIn`/`FocusOut` cursor sync + unfocused blink gating, and `XA_RESOURCE_MANAGER` + `SIGUSR1` reloads. `dunst v1.12.2` ([src/dunst-notify/](src/dunst-notify/)) runs pure-X11 without `gdk-pixbuf`.
## Unified theming, wallpaper engine, and media
- **Unified Theming**: Defaults to **Anodized** (`192 DPI`, `baseFontSize: 32`, `Xcursor.size: 64`). `geminux-session` merges new `/etc/skel/.xthemes/*.xth` files into `~/.xthemes/`, seeds `/etc/skel/.config/geminux/wallpaper.conf` on first boot, and loads `~/.Xresources` via `xrdb -nocpp -load`. [geminux-xth.h](src/geminux-apps/geminux-xth.h) powers `geminux-themes` interactive Editor & `.xth` Importer (`~/.config/geminux/themes/`). `geminux-apply-theme` syncs Dunst, GTK2/GTK3/GTK4/`libadwaita` (`ADW_DISABLE_PORTAL=1` + `dconf` in [10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh)), `xsettingsd`, Qt5/Qt6 (`qt6ct` `QT_QPA_PLATFORMTHEME=qt6ct:gtk3` + Kvantum), Tk/Ttk (`gtkTtk 0.9` in [src/gtkTtk/](src/gtkTtk/)), live X11 clients, and wallpaper mattes (`USE_THEME_BG=1`).
- **Native X11 Wallpaper Engine**: [geminux-wallpaper.h](src/geminux-apps/geminux-wallpaper.h) + [geminux-wallpaper-x11.h](src/geminux-apps/geminux-wallpaper-x11.h) decode images in pure C via `dlopen("libgdk_pixbuf-2.0.so.0")` (`geminux-gdk-pixbuf`, EXIF orientation), Cairo PNG, `libjpeg-turbo`, `libwebp`, and `magick`/`convert` fallback; draw to a retained root `Pixmap` (`_XROOTPMAP_ID`, `ESETROOT_PMAP_ID`, `RetainPermanent`, `XKillClient`, XRandR/Xinerama multi-monitor); and bundle `artwork/wallpapers/` into `/usr/share/geminux/wallpapers/`.
- **Webarchy & Media**: [webarchy.cpp](src/webarchy/webarchy.cpp) (`GTK3` + `WebKit2GTK-4.1`, software crash fallback), pure-C `gdk-pixbuf 2.42.12` + GSettings schemas ([scripts/build-webarchy.sh](scripts/build-webarchy.sh), [scripts/compile-gsettings-schemas.sh](scripts/compile-gsettings-schemas.sh)), native `mpv` ([mpv.conf](overlay/rootfs/etc/mpv/mpv.conf)), `ffmpeg`/`gst-libav`, and `yt-dlp` (`quickjs`).
## Custom UI toolkit and zero-poll C11 daemons
- **`libgemui.so`** ([src/libgemui/](src/libgemui/)): Double-buffered Cairo + Pango/HarfBuzz X11 toolkit with `XA_RESOURCE_MANAGER` + `SIGUSR1` live reloads, lockscreen restacking, contrast guards, clipboard paste, and socket IPC.
- **11 HiDPI apps** ([src/geminux-apps/](src/geminux-apps/)): `geminux-control`, `geminux-audio`, `geminux-datetime`, `geminux-net`, `geminux-dialer`, `geminux-callscreen`, `geminux-sms`, `geminux-contacts`, `geminux-camera`, `geminux-themes`, and `geminux-lock`.
- **Zero-poll daemons** ([src/geminux-daemons/](src/geminux-daemons/)): `geminux-powerd`, `geminux-statusd`, `geminux-touchd`, `geminux-leds`, `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`, and `geminux-checkpw` (detailed in [POWER-OPTIMIZATION.md](POWER-OPTIMIZATION.md)).
## APK package policy
Target `$ROOTFS` installs only pure **Alpine Edge** (`main`, `community`, `testing`) plus 11 RSA-4096 signed `@geminux` APKs built by [scripts/package-local-apks.sh](scripts/package-local-apks.sh): `geminux-kernel-modules`, `geminux-xlibre`, `geminux-suckless`, `geminux-dunst`, `geminux-ui`, `geminux-bantam` ([build-bantam.sh](scripts/build-bantam.sh)), `geminux-gsocket` ([build-gsocket.sh](scripts/build-gsocket.sh)), `geminux-gdk-pixbuf`, `geminux-webarchy`, `geminux-gtkttk` ([build-gtkttk.sh](scripts/build-gtkttk.sh)), and `geminux-config` (including bundled wallpapers, `/etc/mpv/mpv.conf`, `geminux-sdcard` udev/OpenRC units). `/etc/apk/world` pins all 11 with `name@geminux=version` and blocks disallowed Rust/Wayland overrides via [scripts/rootfs-prune-packages.txt](scripts/rootfs-prune-packages.txt), enforced by [scripts/check-rebuild.sh](scripts/check-rebuild.sh). `/etc/apk/protected_paths.d/geminux.list` shields configs across upgrades.
## Flasher, offline provisioning, and release ZIP packager
- **BROM/DA Flasher**: [flash-mtk.py](flash-mtk.py) uses vendored `mtkclient` + `MTK_DA_V5_MT6797.bin`, write-blocking protected factory partitions (`LBA 0..0x6FFFF` / `0x0E000000`, verified in [scripts/test-flash-mtk-gpt.py](scripts/test-flash-mtk-gpt.py)).
- **Staged ext4 Customization**: On temporary ext4 copies, [scripts/extract-vendor-fw.py](scripts/extract-vendor-fw.py) injects MT6797 firmware blobs via `debugfs`/`e2fsck`, [scripts/geminux_accounts.py](scripts/geminux_accounts.py) provisions SHA-512 `/etc/{passwd,group,shadow}` + `/home/<user>`, and [scripts/geminux_luks.py](scripts/geminux_luks.py) optionally applies offline LUKS2 encryption (`cryptsetup reencrypt`).
- **Release ZIP Packager**: [package-image.sh](package-image.sh) ([scripts/package-release-zip.py](scripts/package-release-zip.py)) clones and sanitizes `geminux-rootfs.img` (stripping SSH keys and proprietary MT6797 blobs by default), runs `e2fsck -fn`, generates `SHA256SUMS.txt` + `FLASH-INSTRUCTIONS.txt`, and writes a verified ZIP64 release archive + `.sha256`.