This guide walks through building Geminux images and flashing a **Planet Computers Gemini PDA** (Wi-Fi + 4G, MT6797X) directly from Linux without MediaTek's proprietary FlashTool GUI.
On hosts running `ModemManager`, [flash-mtk.sh](flash-mtk.sh) automatically pauses `ModemManager` during flashing and restarts it on exit so `/dev/ttyACM*` is not claimed away from the BROM/Preloader handshake.
Power off the Gemini PDA completely and leave it unplugged. Run the backup command, then plug the USB-C cable into the **left** USB-C port (closest to the Esc side) while powered off to enter MediaTek BROM/Preloader mode:
Next, extract the device-owned proprietary MediaTek firmware blobs (`MT6797` Wi-Fi, Bluetooth, SPM, and MD1 radio images, never redistributed in git) either from the Gemini's existing Android `system` partition or from a local `system.img`:
Extracted blobs go into `firmware-cache/mt6797/` and are injected into `/lib/firmware/mediatek/mt6797/` on build. Re-run `./rebuild-image.sh` so `geminux-rootfs.img` bundles them:
Geminux claims all user-writable eMMC past the protected MediaTek boundary (`LBA 0x70000`, byte offset `0x0E000000`, `SYS0..SYS27`), replacing Android `system`, `cache`, and `userdata` with `boot`, `recovery`, `boot2`, and a single full-disk `linux` ext4 partition:
Implemented across [flash-mtk.py](flash-mtk.py), [scripts/geminux_accounts.py](scripts/geminux_accounts.py), [scripts/geminux_luks.py](scripts/geminux_luks.py), and [scripts/geminux_gpt.py](scripts/geminux_gpt.py):
1.**Pre-flash credential resolution**: Prompts/validates desktop `username`, desktop `password`, `root``password`, and optional `--encrypt` LUKS2 passphrase before waiting for USB (`--username`, `--user-password`, `--ask-user-password`, `--root-password`, `--ask-root-password`, `--use-default-credentials`, `--encrypt`, `--luks-password`, `--ask-luks-password`). The LUKS2 passphrase is independent of login passwords.
2.**Safety backup**: Saves an initial backup in `backup/<timestamp>/` (pass `--skip-backup --backup-dir backup/<timestamp>` on subsequent flashes to reuse one).
3.**Protected layout verification**: Verifies protected partitions before `0x0E000000` (pass `--force-gpt` only when intentionally converting a non-standard table).
4.**GPT write + readback**: Writes updated Primary (`LBA 0..33`) and Backup GPT with mandatory readback check.
5.**Staged provisioning & write**: Copies `geminux-rootfs.img` to a temporary file (leaving `images/` untouched), provisions `/etc/passwd`, `/etc/group`, `/etc/shadow`, and `/home/<username>` via `debugfs`/`e2fsck`, optionally encrypts with LUKS2 (`aes-xts-plain64`, Argon2id), flashes `boot-geminux.img` (`boot` & `boot2`), `recovery-geminux.img` (`recovery`), and `linux` with readback verification, then sends the DA reboot handshake (`--reboot` default, `--poweroff`, or `--no-reboot`).
- **eSIM persistence**: Profiles provisioned on the hardware ST33 eUICC survive full `linux` rootfs reflashes (whereas flashing `linux` replaces `/` and `/home`).
- **Power on**: Unplug the USB-C cable and hold the **Esc** (power) button until the device boots.
- **USB-attached boot fuel-gauge calibration**: When booting directly on USB power (for instance right after `--flash-full`), `bq25890` briefly holds charging disabled (`F_CHG_CFG=0`, ~15 s while `VSYS` stays powered via USB) so `mt6351-fuel-gauge` calibrates to true zero-current battery OCV rather than ~4.336 V charging voltage.
- **LUKS2 unlock**: When flashed with `--encrypt`, initramfs loads `/etc/gemini-us.kmap` on `tty1` and prompts for the LUKS2 passphrase (`cryptsetup open --allow-discards` -> `/dev/mapper/geminux_root`, mapping the full dynamic partition after any off-mode charging check).
- **First-boot resize**: Initramfs runs `e2fsck -p </dev/null` and `resize2fs -f </dev/null` to expand ext4 across the ~58 GiB `linux` partition, records `/var/lib/geminux/.rootfs-resized`, and pivots to OpenRC.
- **Desktop login & default theme**: TinyDM auto-logs into XLibre + DWM as UID `10000` (your provisioned username or `user`, default password `geminux` unless set; authorized key from `keys/geminux_id_ed25519.pub` if generated). The desktop opens in the default **Anodized** theme; customize themes with `Mod4 + t` (`geminux-themes`) and desktop wallpapers via `geminux-themes --wallpaper` or `geminux-apply-wallpaper`.
- **Rescue shell**: Plugging USB-C into a host starts USB NCM Ethernet (`usb0`) at `172.16.42.1/24`. In recovery mode, `unlock-root`, `check-fs`, and `mount-root` handle LUKS2 unlock automatically.
- **Format & Expansion**: Host `cryptsetup reencrypt --encrypt --disable-locks` wraps the staged rootfs with a 32 MiB LUKS2 header pad (`16 MiB` payload offset, whole-device segment, `aes-xts-plain64` 512-bit, Argon2id 128 MiB / 4 threads) so no plaintext rootfs touches eMMC; unlocking maps the whole device and first boot expands ext4 to ~58 GiB.
- **Security Scope**: Protects data at rest against theft or physical eMMC extraction. Because stock MediaTek `lk` does not enforce AVB verified boot on `boot`/`recovery`/`boot2`, FDE does not protect against offline tampering of the `boot` partition.