# Arch Linux ARM + GNOME on the Redmi Note 8 Pro (begonia)

Native **Arch Linux ARM** (aarch64, systemd, GNOME 51 on Wayland) running on the same mainline-based 6.16.4
postmarketOS kernel, boot image and device tree as the Alpine build in this repository. Nothing in userspace
depends on Alpine/pmOS packages; only the kernel, DTB and initramfs come from the pmOS build.

Date of this port: 2026-11-21.

## Status

| Area | State | Notes |
| --- | --- | --- |
| Boot | works | pmOS initramfs finds the Arch root by UUID, `switch_root` to systemd |
| USB networking | works | `usb0` = `172.16.42.1/24`, DHCP server for the host (`172.16.42.x`) |
| Wi-Fi | works | MediaTek gen4m driver; NetworkManager; reconnects after reboot |
| Bluetooth | works | `hci0` up, scanning/pairing via BlueZ |
| Audio | works | speaker, headphones, mic via PulseAudio + the UCM profile from `patches/audio/` |
| GPU | works | Panfrost: `Mali-G76 MC4`, OpenGL 3.x / GLES 3.1 on `/dev/dri/renderD128`; no Vulkan (PanVK not supported on this part) |
| Desktop | works | GNOME Shell 51 (Wayland), GDM auto-login, screen rotation (iio-sensor-proxy) |
| Hardware keys | works | Vol Up + Power = screenshot, power alone does nothing (see below) |
| Settings > About | works | CPU name via `scripts/begonia-device-identity.*`, disk capacity fixed (see below) |
| IPv6 | disabled | sysctl + NetworkManager + networkd |
| Modem / LTE / SMS | **not done** | CCCI/ECCCI port still in progress, see `docs/handoff-and-todo.md` |
| Fuel gauge | as before | voltage-based percentage, see `docs/fuel-gauge-2026-10-13.md` |

## How it boots

* `boot` partition: the known-good pmOS boot image (kernel 6.16.4 + DTB + initramfs). Only its command line changes
  (`arch/boot-cmdline.txt`: verbose, no splash). The cmdline carries `pmos_boot_uuid` / `pmos_root_uuid`.
* `userdata` partition: a **raw disk image** with an MBR and two partitions, `pmOS_boot` (ext2) and `pmOS_root`
  (ext4), whose UUIDs match that cmdline. UFS uses 4096-byte sectors, so the image must be partitioned with
  4096-byte logical sectors (`losetup --sector-size 4096`), exactly like `deviceinfo_rootfs_image_sector_size`.
* The pmOS initramfs `losetup -P`s `userdata`, finds the partitions by UUID, grows the root filesystem to fill the
  partition, and runs `/sbin/init` (systemd). Arch's `/sbin/init` works unmodified.
* The vbmeta must have verification disabled (`vbmeta.img` flags = 3), as for the Alpine build.

## Build and flash

On the build host (needs root, `losetup`, `sfdisk`, `mkfs.ext4`, `zstd`, `llvm-objcopy`, `img2simg`):

1. `build-image.sh` — creates the 4K-sector disk image, unpacks the Arch Linux ARM tarball
   (<http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz>), sets up users/SSH, USB networking and the
   first-boot services. It needs two private files next to it: `pw.txt` (password for `root` and `user`) and
   `authorized_keys.txt`. It deletes `pw.txt` when done.
2. `strip-module-btf.sh` on the kernel's module tree (see **Kernel modules**).
3. `update-image.sh` — copies `rootfs-overlay/`, the stripped modules, stock firmware and the audio UCM profile into
   the image and produces `arch-begonia.sparse.img`.
4. `flash.sh <boot.img> <arch-begonia.sparse.img>` from the host with the phone in fastboot.
5. On the phone (over `ssh user@172.16.42.1`): run `install-userspace.sh` as root (needs internet; Wi-Fi works once
   NetworkManager is installed, or tunnel pacman through a SOCKS proxy for the first run).

## Things that were non-obvious (so you do not rediscover them)

### Kernel modules need their BTF stripped
The kernel has `CONFIG_DEBUG_INFO_BTF_MODULES=y` and **no** `CONFIG_MODULE_ALLOW_BTF_MISMATCH`. Any module built
in a slightly different build of the same tree fails to load with `insmod: Invalid argument` and
`failed to validate module [...] BTF: -22`. Only the modules inside the initramfs (built with the exact kernel)
load. `strip-module-btf.sh` removes `.BTF` from every module; rewriting the ELF also drops the appended signature,
which is fine because `CONFIG_MODULE_SIG_FORCE` is off. The full 651-module tree used here is the pmbootstrap staging
tree `work/chroot_native/tmp/staging_modules/lib/modules/6.16.4` on the build host (`vermagic 6.16.4 SMP preempt
mod_unload aarch64`), plus the newer out-of-tree audio modules from `patches/audio/mt6785`.

### USB device mode needs three modules first
`11201000.usb` waits for the charger's `usb-otg-vbus-regulator`; the (built-in) MT6360 charger waits for the
`mt6360-adc` IIO channel. Until `mt6360-adc`, `mt6360-regulator` and `tcpci_mt6360` are loaded there is no UDC at
all, so there is no USB gadget. `usb-gadget.sh` loads them, waits for a UDC, then creates the NCM gadget
(`usb_f_ncm` is a module too). `etc/modules-load.d/begonia.conf` also loads them early.

### Landlock
The kernel has no Landlock, so pacman's download sandbox (`DownloadUser`) fails with
`restricting filesystem access failed because Landlock is not supported`. `DisableSandbox` in `pacman.conf` is the
standard workaround and is set by `install-userspace.sh`.

### GNOME bits
* **App grid size.** On a 1080x2340 panel GNOME picks 4 columns and then the largest icon tier that fits
  (96 px at 2.0x scale, 48 px at 2.5x), with nothing in between. The tiny extension in
  `rootfs-overlay/home/user/.local/share/gnome-shell/extensions/appgrid-tuner@begonia/` pins the icon size and the
  column count (`ICON_SIZE`, `COLUMNS`, `ROWS` at the top of `extension.js`). Scale is 2.0x.
* **Hardware keys.** `usr/local/sbin/begonia-keys.py` (service `begonia-keys`) grabs `mt6779-keypad` (volume) and
  `mtk-pmic-keys` (power), detects Vol Up + Power within 0.3 s in either order, and re-emits every other key through
  uinput unchanged. The chord runs `usr/local/bin/begonia-screenshot`, which uses the standard
  `org.freedesktop.portal.Screenshot` portal (GNOME blocks the shell's own screenshot D-Bus API for arbitrary
  callers) and saves `~/Pictures/Screenshot-<date>.png`. GNOME's power-button action is `nothing` and logind
  ignores the power key.
* **Disk capacity showed 4.2 MB.** UFS exposes three LUNs behind one SCSI target (two 4 MB boot LUNs and the data
  LUN). UDisks merges them into one drive and reports the first LUN's size. `99-hide-ufs-boot-luns.rules` detaches
  `sda`/`sdb` at boot; Linux never needs them and fastboot flashing is unaffected.
* **CPU name.** `scripts/begonia-device-identity.sh` bind-mounts a patched `/proc/cpuinfo` (`model name`,
  `Hardware`) and the device-tree model; `update-image.sh` installs it.
* **Clock.** The RTC year decodes differently in different kernels, so `fix-clock.sh` never lets the clock run
  earlier than the image's build time. Once Wi-Fi is up, `systemd-timesyncd` takes over.

### Debug dump
`debug-dump.service` writes `/boot/boot-debug.txt` (modules, deferred probes, failed units, USB messages) every
30 s for the first minutes after boot. It is invaluable when the phone has no network: boot into recovery, mount the
`pmOS_boot` partition (offset 1 MiB, 128 MiB) and read it. Disable it once things are stable.

## Android on this unit

Stock MIUI and Lineage do not boot on the author's unit: the vendor keymaster (Microtrust TEE) rejects every session
with `0xFFFF0008` even with byte-identical stock firmware, TAs and an erased RPMB, so Android cannot finish
`vold`/keystore setup. Linux does not use the TEE, so this port is unaffected. The identity partitions
(`nvram`, `nvdata`, `persist`, `protect1/2`, `proinfo`) were left intact and backed up outside this repository.

## Not in this repository (private)

Stock firmware blobs (`/vendor/firmware`), partition backups, Wi-Fi credentials, the user password and SSH keys.
`update-image.sh` expects the firmware under `$WORK/vendor-extract/firmware`; extract it from your own stock vendor
image.

## Open work

* Modem (CCCI/CLDMA/ECCCI) — see `docs/handoff-and-todo.md`.
* Reproducible kernel+modules build for the exact boot image (the module tree currently comes from a pmbootstrap
  staging directory on the build host).
* Optional: haptic feedback on screenshot, lock/blank on a short power press.
