diff --git a/packages/omamobile-device-tegu/LICENSE b/packages/omamobile-device-tegu/LICENSE new file mode 100644 index 000000000..aecd59624 --- /dev/null +++ b/packages/omamobile-device-tegu/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Derek Ross + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/omamobile-device-tegu/PKGBUILD b/packages/omamobile-device-tegu/PKGBUILD new file mode 100644 index 000000000..a35c8d62b --- /dev/null +++ b/packages/omamobile-device-tegu/PKGBUILD @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: MIT +# Maintainer: Derek Ross +pkgname=omamobile-device-tegu +pkgver=$(cat "${startdir:-.}/version") +pkgrel=1 +pkgdesc="Omarchy Mobile support for the Google Pixel 9a (tegu): storage guard, USB networking, hang-safe graphics start" +arch=(aarch64) +url="https://github.com/derekross/omarchy-mobile" +license=(MIT) +depends=(bash systemd kmod bluez-utils omamobile-keyring) +provides=(omamobile-device) +conflicts=(omamobile-device) +backup=(etc/pacman.d/omamobile-mirrorlist) +install=omamobile-device-tegu.install +makedepends=(gcc) +checkdepends=(diffutils) + +build() { + "$startdir/build" "$srcdir/build" +} + +check() { + "$startdir/test/all" +} + +package() { + "$startdir/install" "$pkgdir" "$srcdir/build" +} diff --git a/packages/omamobile-device-tegu/README.md b/packages/omamobile-device-tegu/README.md new file mode 100644 index 000000000..97591b17a --- /dev/null +++ b/packages/omamobile-device-tegu/README.md @@ -0,0 +1,145 @@ + +# omamobile-device-tegu + +Omarchy Mobile's system support for the Google Pixel 9a (codename tegu, +Tensor G4 / zumapro). It sits beside Omarchy's own packages the way +`omarchy-mac` adds Apple Silicon support, and does for the 9a what +`omamobile-device-cheetah` does for the Pixel 7 Pro, with one difference: +the 9a's kernel is still being upstreamed, so part of its bring-up cannot be +packaged yet. What is here is what runs on in-tree drivers. + +| Path | Installs to | What it does | +| --- | --- | --- | +| `bin/omamobile-tegu-graphics-start` + `vendor/systemd/system/omamobile-tegu-graphics.service` + `display-manager.service.d/10-omamobile-tegu.conf` | `/usr/bin`, `/usr/lib/systemd/system` (enabled by a vendor wants link) | Loads the GPU (panthor), the display controller (gs_decon), haptics (cs40l26_vibra), the torch (leds_lm3644), the battery gauge (max77779_battery) and the Bluetooth controller (hci_uart) at boot, in that order, after writing and syncing a marker. Each step keys on its own device node (`1f000000.gpu`, `19470000.display-controller`, the device-tree nodes of the rest), and the unit runs when the GPU or the display controller exists, so a DTB with the display but no GPU still gets its display. A load or bind that returns but fails (panthor without `mali_csffw.bin`, say) is logged and skipped, the rest still loads, and the marker is cleared; the unit then ends failed, and `--retry` tries the skipped steps again. Only a boot that hangs in a step leaves the marker: the next boot keeps all six off and says so, and `omamobile-tegu-graphics-start --retry` goes on from the step that failed (on the same boot too: the drivers already loaded stay as they are). Before `gs_decon`, and only when the command line says `exynos_drm.panel_name=google-tg4c`, it turns `gs_dsim_cmd.allow_tx` on, so the panel's DSI commands (brightness, sleep, 120 Hz; kernel #90) go to the panel the bring-up tested and no other: on another panel the display stays read-only at 60 Hz. The display manager waits for it. It also writes `/run/omamobile-tegu-display-card` (the display controller's DRM node by path, since the GPU may take card0) and, when the GPU came up, `/run/omamobile-tegu-gpu-ready.json` | +| `uwsm/env.d/omamobile-tegu-graphics` | `/usr/share/uwsm/env.d` | The session's side of the graphics start, sourced by uwsm (it walks `XDG_DATA_DIRS` too; a user's `~/.config/uwsm/env` runs after it): the KMS device from `/run/omamobile-tegu-display-card`, hardware GL when `/run/omamobile-tegu-gpu-ready.json` exists and llvmpipe otherwise, so a phone whose GPU did not come up still gets a desktop | +| `vendor/modprobe.d/omamobile-tegu-guards.conf` | `/usr/lib/modprobe.d` | Keeps those drivers (and the Wi-Fi, PCIe and NFC ones, for the day they are in tree) from autoloading ahead of the guard. No `install` lines: they would break the guard's own modprobe | +| `vendor/modprobe.d/omamobile-tegu-display.conf`, `omamobile-tegu-clk-acpm.conf` | `/usr/lib/modprobe.d` | 120 Hz as the ceiling and the panel really off on DPMS (the DSI commands themselves are allowed by the graphics start, for google-tg4c only); the GPU DVFS ceiling at 890 MHz | +| `bin/omamobile-tegu-aoc-start` + `vendor/systemd/system/omamobile-tegu-aoc.service` + `vendor/modprobe.d/omamobile-tegu-aoc.conf` | `/usr/bin`, `/usr/lib/systemd/system` (not enabled), `/usr/lib/modprobe.d` | Boots the AoC (audio and sensor DSP) hang-safe: Trusty, the GSA, the AoC drivers, `aoc-tegu.bin`, then waits for its 93 services. Ships disabled: see below | +| `bin/omamobile-bt-addr` + `vendor/systemd/system/omamobile-bt-addr@.service` + `vendor/udev/rules.d/80-omamobile-bt-addr.rules` | `/usr/bin`, `/usr/lib/systemd/system`, `/usr/lib/udev/rules.d` | Gives the BCM4383 its real Bluetooth address from the bootloader's device tree when the controller appears, powering it on once first (set on a never-powered controller, the kernel withdraws the index for good). The Pixel 7 Pro's script, with the extra waits the 9a needed | +| `bin/omamobile-tegu-usb-rescue` + `src/tegu-tcpc-switch.c` + `vendor/systemd/system/omamobile-tegu-usb-rescue.service` | `/usr/bin`, `/usr/lib/systemd/system` (enabled by a vendor wants link) | Closes the MAX77779's USB data switch after a cable replug while no Type-C driver owns the chip; with one loaded it exits. The helper reads the chip's identity and VBUS before its one write and never forces an address a driver holds | +| `bin/omamobile-tegu-charge-limit` + `vendor/udev/rules.d/75-omamobile-tegu-charger.rules` | `/usr/bin`, `/usr/lib/udev/rules.d` | Applies `/etc/omamobile/charge-limit` (a percentage, say `80`) to the charger when it appears; charging stops there and starts again 5 below. No file: charge to 100 % | +| `vendor/systemd/system-sleep/omamobile-tegu-wifi` | `/usr/lib/systemd/system-sleep` | Keeps Wi-Fi loaded across s2idle when `/etc/omamobile/wifi-keep-across-sleep` exists (the chip reloads its firmware on resume and iwd reconnects), otherwise unloads and reloads brcmfmac around the sleep; after a sleep that lost Wi-Fi it unloads for the rest of the boot. It reloads the in-tree `brcmfmac`; a phone still running an out-of-tree build of it keeps its own hook until the Wi-Fi series lands | +| `vendor/systemd/system-sleep/omamobile-tegu-nfc` | `/usr/lib/systemd/system-sleep` | Stops neard's poll loop before a sleep (polling through s2idle reset the palmtop; with it stopped, 35 of 35 cycles woke), reads `Polling` back and logs it, and starts the loop again after the wake if it was on. Powering the ST54L off as well, the workaround for a controller that did not answer on I2C after a wake (issue #132; fixed by linux-omarchy-mobile #131), runs only while `/etc/omamobile/nfc-power-off-across-sleep` exists: off by default, since its record is one wake that needed the power key and one that worked. Log: `/var/log/omamobile/nfc-sleep.log` | +| `vendor/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf` | `/usr/lib/systemd/system` | Holds off Arch's old-module cleanup: our kernels come as module tarballs, not pacman packages, and the next-boot and rollback trees must stay | +| `vendor/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf`, `sleep.conf.d/10-omamobile.conf` | `/usr/lib/systemd` | A hung shutdown resets the phone after a minute; suspend means s2idle (no SoC sleep sequence yet, and `deep` does not wake) | +| `vendor/udev/rules.d/10-omamobile-storage.rules` | `/usr/lib/udev/rules.d` | Continues the initramfs storage guard: Android partitions stay hidden and the whole-disk node unusable | +| `vendor/udev/rules.d/20-omamobile-torch.rules`, `70-omamobile-dma-heap.rules`, `72-omamobile-feedbackd.rules` | `/usr/lib/udev/rules.d` | The torch tile may set the LED's brightness; libcamera's software ISP gets the DMA-BUF heaps; feedbackd gets the haptics | +| `vendor/systemd/network/20-usb-gadget.network`, `vendor/NetworkManager/conf.d/10-omamobile-usb.conf` | `/usr/lib/systemd/network`, `/usr/lib/NetworkManager/conf.d` | USB networking to a host (172.16.42.1, the host as a fallback route behind Wi-Fi); NetworkManager stays off the link | +| `src/reboot-to.c` | `/usr/bin/reboot-to` | Reboot with a reason the bootloader understands. One source with the cheetah package | +| `device.conf`, `etc/omamobile-mirrorlist` | `/usr/share/omamobile`, `/etc/pacman.d` | The device descriptor (a copy of `device/tegu/device.conf`) and the `[omamobile]` repository | + +Bluetooth comes up powered at every boot, as on the Pixel 7 Pro +(`omamobile-bt-addr@` powers the controller on to set its address, and +leaves it on). + +`./build [DIR]` compiles the C tools, `./install DESTDIR [DIR]` stages +everything and enables nothing beyond the two wants links, and `test/all` +runs the package tests in a scratch root (`OMAMOBILE_TEGU_ROOT`), with no +phone and no hardware. + +The package does not mark the boot slot successful (Derek decides how that +works on the 9a), does not start Wi-Fi, NFC, the modem, the charger driver +or the cameras, and carries no vendor files and no per-phone data. + +## What the kernel command line has to stop carrying + +The bring-up boots with a command line that masks units and gates its own +start scripts. The package's units cannot run under it. For the package to +take over, `/chosen/bootargs` has to lose: + +- `systemd.unit=multi-user.target` (graphical.target is the default again); +- every `systemd.mask=` for `sddm`, `display-manager`, `NetworkManager`, + `bluetooth`, the `omamobile-*` units and the `tegu-*` units; +- `systemd.wants=tegu-curated-root-guard.service`, + `systemd.wants=tegu-curated-autostart.service` and + `systemd.wants=bluetooth.service`; +- the flags `omamobile.tegu-curated-root`, `omamobile.tegu-curated-autostart`, + `omamobile.tegu-standard-reboot` and `omamobile.tegu-native-bluetooth`; +- `modprobe.blacklist=gs_decon,panthor,cs40l26_vibra,hci_uart,leds_lm3644` + (`omamobile-tegu-guards.conf` does this now). + +`mem_sleep_default=s2idle`, `panic=10`, `s3c2410_wdt.tmr_atboot=1` and +`cs40l26_vibra.max_buzz_ms=100` stay. Whether and when that DTB change +happens is the owner's call. + +`s3c2410_wdt.tmr_atboot=1` is what resets the palmtop after a hang: the +watchdog runs from boot, so a hung graphics start ends in a reset and the +marker. The public tegu DTS carries `panic=10` but not that, so on it a +hang that does not panic ends at the power key (held about 30 s). + +## The AoC start ships disabled + +`omamobile-tegu-aoc-start` is the Pixel 7 Pro's AoC start with the 9a's +names (`154b0000.aoc`, `aoc-tegu.bin`, 93 services, the sensors' USF +channel through `aoc_channel_dev`). It needs a kernel whose device tree +enables the AoC, GSA and Trusty nodes; today the bring-up turns them on +with out-of-tree overlay modules, and so `omamobile-tegu-aoc.service` has +no wants link. Once a kernel enables them, `systemctl enable +omamobile-tegu-aoc.service` and reboot. A step that returns and fails is +named in the journal and clears the marker (a load that came back is not a +hang; `test/aoc-start` checks this). Only a boot that hangs in the start +leaves the marker, and then the next boot leaves the AoC off until +`omamobile-tegu-aoc-start --retry`. + +## Firmware the phone needs + +Nothing here is in the package; `tools/extract-vendor-firmware` and +`tools/phone-provision` take it from the owner's own factory image: + +- `aoc-tegu.bin` (the AoC), `Top-tas2572RCA1.bin` and + `Bottom-tas2572RCA1.bin` (the speaker amplifiers); +- `brcm/brcmfmac4383-pcie.bin`, `.clm_blob`, `.txcap_blob` and `.txt` (Wi-Fi); +- `updates/brcm/BCM.google,zumapro-tegu.hcd` (Bluetooth); +- `updates/cs40l26.wmfw` and `cs40l26.bin` (haptics); +- `arm/mali/arch11.8/mali_csffw.bin` (the GPU's firmware, from Mesa's + packaging or the factory image). + +## Moving from the bring-up + +The bring-up on the first 9a lives in `/usr/local` and `/etc`, outside any +package. After installing 0.2.0 and before the reboot that drops the +command line above, take these off the phone by hand; the package cannot, +and a leftover copy in `/etc` wins over the package's file of the same name. + +- Units and drop-ins in `/etc/systemd/system`: `tegu-curated-autostart`, + `tegu-curated-root-guard`, `tegu-curated-session`, + `tegu-curated-bluetooth-prepare`, `bluetooth.service.d/20-tegu-curated.conf`, + `omamobile-tegu-audio` (keep it only while the AoC still needs the + out-of-tree start; it conflicts with nothing in the package), + `tegu-dtb-deadman`, `tegu-rt9470-early-read`, and the retired + `tegu-battery`, `tegu-battery-hold`, `tegu-display`, `tegu-display-confirm`, + `tegu-gpu`, `tegu-touch` (with `tegu-touch.service.d`), `tegu-normal-reboot`, + `tegu-native-root-verify`, `tegu-native-root-deadman`, with their links + in `multi-user.target.wants`, `graphical.target.wants` and + `sysinit.target.wants`. `systemctl disable` each first. +- `/etc/modprobe.d/omamobile-tegu-*.conf` and + `tegu-battery-gauge-bringup.conf` (the package's `omamobile-tegu-guards.conf`, + `-display.conf` and `-clk-acpm.conf` replace them; + `omamobile-tegu-fp-lhbm.conf` belongs to omamobile-fingerprint). +- `/etc/udev/rules.d/20-omamobile-tegu-gpu-always-on.rules` (the GPU's + runtime suspend is qualified), `20-omamobile-tegu-torch-bringup.rules` and + `70-omamobile-dma-heap.rules` (the package has them). +- `/etc/systemd/system.conf.d/10-tegu-bringup-watchdog.conf` (the package + sets the reboot watchdog; the 10 s runtime watchdog was the bring-up's). +- `/etc/systemd/network/20-usb-gadget.network` (same content as the package's). +- `/usr/lib/systemd/system-sleep/omamobile-tegu-wifi` and `-nfc` (the + package installs its own under the same names: pacman will refuse to + overwrite unowned files, so remove them first). +- `/usr/local/bin/reboot-to`, `g7-*`, `nfc-ab`; `/usr/local/sbin/tegu-*`; + `/usr/local/libexec/tegu-*`; `/usr/local/lib/omamobile-tegu` + (`tegu-tcpc-switch` is `/usr/bin/tegu-tcpc-switch` now) and + `/usr/local/lib/omamobile-tegu-curated`. +- `/var/lib/omamobile-tegu/curated` and the old per-kernel state + directories (`battery`, `display`, `gpu`, `touch`, `keys`, `pmu`, `time`, + `ui`, `wifi*`, `module-backup`); keep `audio`, `nfc` and `modem` while + `omamobile-tegu-audio-up` and `omamobile-tegu-modem-up` still load from them. + +`omamobile-tegu-audio-up`, `omamobile-tegu-modem-up` and the out-of-tree +modules they load stay until the kernel carries their drivers and device +tree nodes; the package's guards and theirs do not load the same modules. +So when a smoke report from the palmtop (`tools/phone-smoke`) lists Wi-Fi +and NFC as loaded beside this package, it was `omamobile-tegu-audio-up` +that loaded them, from its own staged copies, not the package: the package +blacklists both and starts neither. + +Licence: MIT. diff --git a/packages/omamobile-device-tegu/bin/omamobile-bt-addr b/packages/omamobile-device-tegu/bin/omamobile-bt-addr new file mode 100755 index 000000000..e52d00f60 --- /dev/null +++ b/packages/omamobile-device-tegu/bin/omamobile-bt-addr @@ -0,0 +1,69 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Give the Bluetooth controller the phone's real address, as Android does. +# The bootloader writes it into the device tree at every boot +# (/chosen/config/bt_addr); the BCM4383 otherwise comes up with a +# placeholder (43:89:00:00:..). +# omamobile-bt-addr hciN (started by udev through omamobile-bt-addr@.service) +set -euo pipefail + +hci=${1:?Usage: omamobile-bt-addr hciN} +index=${hci#hci} +[[ $index =~ ^[0-9]+$ ]] || { echo "not a controller: $hci" >&2; exit 1; } +source=/proc/device-tree/chosen/config/bt_addr +[[ -s $source ]] || exit 0 +addr=$(tr -d '\0' < "$source" | tr 'a-f' 'A-F') + +# A unicast, globally administered address only, like the Wi-Fi one. +[[ $addr =~ ^[0-9A-F]{2}(:[0-9A-F]{2}){5}$ ]] || exit 0 +(( (16#${addr:0:2} & 3) == 0 )) || exit 0 + +# udev starts us when the controller appears, before hci_bcm has finished +# downloading its firmware (about 7 s); it answers info only after that. +for _ in {1..60}; do + info=$(btmgmt --index "$index" info 2> /dev/null || true) + [[ $info == *"current settings:"* ]] && break + sleep 0.5 +done +[[ $info == *"current settings:"* ]] || { echo "$hci never finished its setup" >&2; exit 1; } + +# Set Public Address needs the controller powered off. Set on a controller +# that has never been powered, though, the kernel withdraws the index to +# reconfigure it and it never comes back (seen at every boot). So power it +# on once first, then cycle it around the change, and leave it on. +powered=$(grep -c 'current settings:.*powered' <<< "$info" || true) +if ((!powered)); then + btmgmt --index "$index" power on > /dev/null + info=$(btmgmt --index "$index" info 2> /dev/null || true) + grep -q 'current settings:.*powered' <<< "$info" || { + echo "$hci did not power on before address configuration" >&2 + exit 1 + } +fi +btmgmt --index "$index" power off > /dev/null +btmgmt --index "$index" public-addr "$addr" > /dev/null + +# Set Public Address acknowledges before HCI_CONFIG work finishes. The +# management index is absent until that work has added it again. btmgmt +# can exit zero even for Invalid Index, so wait for a real Read Info reply. +for _ in {1..100}; do + info=$(btmgmt --index "$index" info 2> /dev/null || true) + [[ $info == *"current settings:"* ]] && break + sleep 0.1 +done +[[ $info == *"current settings:"* ]] || { + echo "$hci did not return after address configuration" >&2 + exit 1 +} + +btmgmt --index "$index" power on > /dev/null +info=$(btmgmt --index "$index" info 2> /dev/null || true) +grep -q 'current settings:.*powered' <<< "$info" || { + echo "$hci did not power on after address configuration" >&2 + exit 1 +} +[[ ${info^^} == *"ADDR $addr "* ]] || { + echo "$hci address does not match the bootloader" >&2 + exit 1 +} +exit 0 diff --git a/packages/omamobile-device-tegu/bin/omamobile-tegu-aoc-start b/packages/omamobile-device-tegu/bin/omamobile-tegu-aoc-start new file mode 100755 index 000000000..b81e28fd5 --- /dev/null +++ b/packages/omamobile-device-tegu/bin/omamobile-tegu-aoc-start @@ -0,0 +1,122 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Boot the Pixel 9a's AoC (audio and sensor DSP), hang-safe, in the order +# the bring-up proved on the palmtop (its omamobile-tegu-audio-up, still +# outside the package; device/tegu/NOTES.md 2026-10-26) and the Pixel 7 +# Pro's omamobile-aoc-start uses: +# 1. Trusty (trusty_core, trusty_log, trusty_ipc, then trusty_virtio): +# the AoC is started by Trusty's hwmgr.aoc service. +# 2. The GSA mailbox (gsa), which authenticates the image. +# 3. The AoC System MMU, mailboxes, core and service front ends +# (aoc_channel_dev for the sensors' USF channel and the sound card's +# aoc_alsa_dev before aoc_char_dev, which takes every service still free). +# 4. The firmware load (aoc-tegu.bin), then wait for the 93 services and +# the sensor channel. +# The TAS2572 amplifiers come up from the device tree through the tas2781 +# codec driver; the card's UCM profile (omamobile-audio) does the routing. +# +# This waits for a kernel whose device tree enables the AoC, GSA and Trusty +# nodes: today they are turned on by out-of-tree overlay modules that no +# package can ship, so the unit has no wants link (README.md). +# A marker is written and synced before any of it, and removed at the end, +# after a step that returned and failed too (that is not a hang). If a boot +# hangs here, the next one finds the marker and leaves the AoC off; +# "omamobile-tegu-aoc-start --retry" tries again. +# omamobile-tegu-aoc-start [--retry] +set -uo pipefail + +root=${OMAMOBILE_TEGU_ROOT:-} +if [[ -n $root ]]; then + [[ $root == /* && $root != / && -d $root ]] || exit 2 +fi +state=$root/var/lib/omamobile +marker=$state/tegu-aoc-started +# Set right before the firmware load, gone after a reboot (tmpfs) +loaded=$root/run/omamobile/tegu-aoc-firmware-loaded +node=$root/sys/bus/platform/devices/154b0000.aoc +trusty=$root/proc/device-tree/trusty/status + +log() { echo "omamobile-tegu-aoc: $*"; } + +case ${1:-} in + '') ;; + --retry) rm -f "$marker" ;; + *) log "usage: omamobile-tegu-aoc-start [--retry]"; exit 2 ;; +esac + +if [[ -e $marker ]]; then + log "the last start ($(cat "$marker" 2>/dev/null)) never finished; the AoC stays off this boot." + log "after checking the previous boot's log, retry with: omamobile-tegu-aoc-start --retry" + exit 0 +fi +if [[ ! -e $node ]]; then + log "the AoC is not enabled in this DTB; nothing to do" + exit 0 +fi +# The AoC starts once per boot: a second firmware load takes the running AoC +# down (the GSA refuses the image while it runs, and there is no AoC reset). +if grep -q '^Services : [1-9]' "$node/services" 2>/dev/null; then + log "already online: $(head -1 "$node/services")" + exit 0 +fi +if [[ -e $loaded ]]; then + log "the AoC was already started this boot but is not online; reboot to start it again" + exit 1 +fi +if [[ ! -e $trusty ]] || [[ $(tr -d '\0' < "$trusty") != okay ]]; then + log "Trusty is not enabled in this DTB; the AoC cannot be started" + exit 1 +fi +fw= +for d in "$root/usr/lib/firmware/updates" "$root/usr/lib/firmware"; do + [[ -e $d/aoc-tegu.bin ]] && fw=$d/aoc-tegu.bin && break +done +if [[ -z $fw ]]; then + log "no aoc-tegu.bin (install it from the phone's vendor partition: tools/extract-vendor-firmware)" + exit 1 +fi + +mkdir -p "$state" +date -Is > "$marker" +sync -f "$marker" 2>/dev/null || sync + +finish() { rm -f "$marker"; sync -f "$state" 2>/dev/null || sync; } +fail() { log "$*"; finish; exit 1; } + +# 1. Trusty +for m in trusty_core trusty_log trusty_ipc trusty_virtio; do + modprobe "$m" || fail "$m failed" +done +for _ in $(seq 50); do [[ -e $root/dev/trusty-ipc-dev0 ]] && break; sleep 0.2; done +[[ -e $root/dev/trusty-ipc-dev0 ]] || fail "no /dev/trusty-ipc-dev0" + +# 2. GSA +modprobe gsa || fail "gsa failed" + +# 3. AoC drivers +for m in gs201_aoc_sysmmu mailbox_wc aoc_core aoc_channel_dev aoc_alsa_dev aoc_char_dev; do + modprobe "$m" || fail "$m failed" +done +[[ -w $node/firmware ]] || fail "the AoC core did not bind ($node/firmware missing)" + +# 4. Firmware; the core loads, authenticates and starts it in the background. +# The bring-up saw the service count flap before it settled, so wait for it +# to hold for 3 s. +mkdir -p "${loaded%/*}" && date -Is > "$loaded" +echo aoc-tegu.bin > "$node/firmware" || fail "firmware load request failed" +stable=0 +for _ in $(seq 150); do + if grep -q '^Services : [1-9]' "$node/services" 2>/dev/null; then + stable=$((stable + 1)) + else + stable=0 + fi + if ((stable >= 15)); then + log "up: $(head -1 "$node/services"), firmware $(head -1 "$node/revision" 2>/dev/null)" + for _ in $(seq 25); do [[ -e $root/dev/acd-com.google.usf ]] && break; sleep 0.2; done + [[ -e $root/dev/acd-com.google.usf ]] || log "no /dev/acd-com.google.usf (sensors unavailable)" + finish; exit 0 + fi + sleep 0.2 +done +fail "no stable AoC services after 30 s (see dmesg and /dev/acd-logging)" diff --git a/packages/omamobile-device-tegu/bin/omamobile-tegu-charge-limit b/packages/omamobile-device-tegu/bin/omamobile-tegu-charge-limit new file mode 100755 index 000000000..ed95353a3 --- /dev/null +++ b/packages/omamobile-device-tegu/bin/omamobile-tegu-charge-limit @@ -0,0 +1,26 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Pixel 9a charge limit: /etc/omamobile/charge-limit holds the percentage at +# which charging stops (say 80); the charger starts again 5 below it. No +# file, or not a number from 1 to 100: charge to 100 %. Run by udev when the +# MAX77779 charger appears (75-omamobile-tegu-charger.rules), and by hand +# after editing the file. +set -uo pipefail + +root=${OMAMOBILE_TEGU_ROOT:-} +if [[ -n $root ]]; then + [[ $root == /* && $root != / && -d $root ]] || exit 2 +fi +file=$root/etc/omamobile/charge-limit +threshold=$root/sys/class/power_supply/max77779-charger/charge_control_end_threshold +log() { echo "omamobile-tegu-charge-limit: $*"; } + +[[ -s $file ]] || exit 0 +[[ -w $threshold ]] || { log "no charger threshold to set"; exit 0; } +limit=$(tr -d ' \t\n' < "$file") +if [[ ! $limit =~ ^[0-9]+$ ]] || (( 10#$limit < 1 || 10#$limit > 100 )); then + log "$file is not a percentage from 1 to 100; no limit" + exit 1 +fi +echo "$((10#$limit))" > "$threshold" || { log "the charger refused $limit"; exit 1; } +log "charge limit $(cat "$threshold") %" diff --git a/packages/omamobile-device-tegu/bin/omamobile-tegu-graphics-start b/packages/omamobile-device-tegu/bin/omamobile-tegu-graphics-start new file mode 100755 index 000000000..4550601ce --- /dev/null +++ b/packages/omamobile-device-tegu/bin/omamobile-tegu-graphics-start @@ -0,0 +1,209 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Bring up the Pixel 9a's GPU, display, haptics, torch, battery gauge and +# Bluetooth controller at boot, hang-safe. All six drivers are in the kernel +# tree and blacklisted for autoload (modprobe.d/omamobile-tegu-guards.conf), +# so this script is the only thing that loads them, in this order, after a +# marker has been written and synced. Each step keys on its own device node +# (the GPU on 1f000000.gpu, the display on 19470000.display-controller, the +# rest on their device-tree nodes), so a DTB without the GPU still gets its +# display. A load or bind that returns but fails is logged and skipped, and +# the start goes on to the next step: panthor without mali_csffw.bin must not +# take the display with it. Only a step that never comes back keeps the +# marker: the next boot finds it, leaves all of it alone and says so; after +# reading the previous boot's log, run "omamobile-tegu-graphics-start --retry". +# +# The panel's DSI commands (gs_dsim_cmd.allow_tx, for brightness, sleep and +# 120 Hz) are allowed only when the bootloader names the google-tg4c panel +# on the command line (exynos_drm.panel_name=google-tg4c, with the panel's +# id appended by the bootloader, kernel #90), and +# before gs_decon loads, since gs-decon decides on 120 Hz at probe. +# +# This is the curated start of the bring-up (device/tegu/bringup) without its +# file-hash manifest, EGL smoke test, mask checks, sddm start and bootloader +# dead-man: the marker is the safety net, as on the Pixel 7 Pro. +# omamobile-tegu-graphics-start [--retry] +# OMAMOBILE_TEGU_ROOT: a scratch root for the package tests (fake /sys, /proc). +set -uo pipefail + +root=${OMAMOBILE_TEGU_ROOT:-} +if [[ -n $root ]]; then + [[ $root == /* && $root != / && -d $root ]] || exit 2 +fi +state=$root/var/lib/omamobile +marker=$state/tegu-graphics-started +dt=$root/proc/device-tree +cmdline=$root/proc/cmdline +gpu=$root/sys/bus/platform/devices/1f000000.gpu +decon=$root/sys/bus/platform/devices/19470000.display-controller +allow_tx=$root/sys/module/gs_dsim_cmd/parameters/allow_tx +torch=$root/sys/class/leds/white:torch +gauge=$root/sys/class/power_supply/max77779-battery +haptics_node=$dt/soc/usi@10c900c0/i2c@10c90000/haptic-driver@43 +torch_node=$dt/soc/usi@108b00c0/i2c@108b0000/led-controller@63 +bluetooth_node=$dt/soc/usi@155d00c0/serial@155d0000/bluetooth + +log() { echo "omamobile-tegu-graphics: $*"; } +loaded() { [[ -d $root/sys/module/$1 ]]; } +# A device-tree node is enabled when it exists and has no status or "okay". +enabled() { + [[ -d $1 ]] || return 1 + [[ -e $1/status ]] || return 0 + case $(tr -d '\0' < "$1/status") in okay|ok) return 0 ;; *) return 1 ;; esac +} +# Wait for a device to bind to a driver: device dir, driver name, quarter seconds. +bound() { + local i + for ((i = 0; i < $3; i++)); do + [[ $(readlink -f "$1/driver" 2>/dev/null) == */$2 ]] && return 0 + sleep 0.25 + done + return 1 +} +# The panel the bootloader named on the kernel command line, or nothing. +panel_name() { + local word + for word in $(cat "$cmdline" 2>/dev/null); do + [[ $word == exynos_drm.panel_name=* ]] && { echo "${word#*=}"; return 0; } + done + echo "" +} + +case ${1:-} in + '') ;; + --retry) rm -f "$marker" ;; + *) log "usage: omamobile-tegu-graphics-start [--retry]"; exit 2 ;; +esac + +if [[ -e $marker ]]; then + log "the last start ($(cat "$marker" 2>/dev/null)) never finished; the GPU, display, haptics, torch, gauge and Bluetooth stay off this boot." + log "after checking the previous boot's log, retry with: omamobile-tegu-graphics-start --retry" + exit 0 +fi +if [[ ! -e $gpu && ! -e $decon ]]; then + log "no GPU and no display controller in this DTB; nothing to do" + exit 0 +fi +# Once per boot: a loaded driver is never unloaded or retried (AGENTS.md). +# --retry goes on from where the last start stopped: modprobe leaves a +# loaded driver as it is, so the steps already done cost nothing. +if [[ ${1:-} != --retry ]] && { loaded panthor || loaded gs_decon; }; then + log "already started this boot" + exit 0 +fi + +mkdir -p "$state" "$root/run" +# The marker names the step in progress, so a hang is easy to place. +phase() { printf '%s %s\n' "$(date -Is)" "$1" > "$marker"; sync -f "$marker" 2>/dev/null || sync; } +finish() { rm -f "$marker"; sync -f "$state" 2>/dev/null || sync; } +# A step that returned and failed: logged, skipped, the start goes on to the +# next one. The marker is cleared at the end as after a good start: it is for +# a step that never comes back, not for one that said no. +up= +failed= +skip() { log "$2; skipped"; failed+="${failed:+, }$1"; } + +if [[ -e $gpu ]]; then + phase gpu + if ! modprobe panthor; then + skip GPU "panthor failed (no mali_csffw.bin yet? see dmesg)" + elif ! bound "$gpu" panthor 60; then + skip GPU "the GPU did not bind to panthor (see dmesg)" + else + # The session's environment (uwsm/env.d/omamobile-tegu-graphics) reads + # this and picks hardware GL. + printf '{"gpu": "panthor", "by": "omamobile-tegu-graphics-start"}\n' > "$root/run/omamobile-tegu-gpu-ready.json" + up+="GPU" + fi +else + log "no GPU in this DTB; skipped" +fi + +if [[ -e $decon ]]; then + phase display + # gs_dsim_cmd is not guarded: it autoloads from its node ahead of this + # start and sends nothing until allow_tx is on. Loading it here (a no-op + # when it already is) makes the parameter file exist before the write. + modprobe gs_dsim_cmd 2>/dev/null || true + panel=$(panel_name) + # the bootloader appends the panel's id (google-tg4c.2d008004 on the palmtop) + if [[ $panel == google-tg4c || $panel == google-tg4c.* ]]; then + if echo 1 > "$allow_tx" 2>/dev/null; then + log "panel $panel: DSI commands allowed (gs_dsim_cmd.allow_tx=1)" + else + log "panel $panel: could not write $allow_tx; the display stays read-only at 60 Hz" + fi + else + log "panel ${panel:-unnamed}: DSI commands stay off; the display stays read-only at 60 Hz" + fi + # stage=2 is the full driver (the lower stages are bring-up probes); the + # refresh rate and the panel-off behaviour come from modprobe.d. + if ! modprobe gs_decon stage=2 fbdev=0; then + skip display "gs_decon failed (see dmesg)" + elif ! bound "$decon" gs-decon 60; then + skip display "the display controller did not bind to gs-decon (see dmesg)" + else + # The session's environment reads the display controller's DRM node, + # whichever card number it got (the GPU may take card0). + card=$(readlink -f "$root/dev/dri/by-path/platform-19470000.display-controller-card" 2>/dev/null || true) + [[ -n $card ]] && printf '%s\n' "${card#"$root"}" > "$root/run/omamobile-tegu-display-card" + up+="${up:+, }display" + fi +else + log "no display controller in this DTB; skipped" +fi + +if enabled "$haptics_node"; then + phase haptics + if modprobe cs40l26_vibra; then up+="${up:+, }haptics"; else skip haptics "cs40l26_vibra failed (see dmesg)"; fi +else + log "no haptics in this DTB; skipped" +fi + +if enabled "$torch_node"; then + phase torch + if ! modprobe leds_lm3644; then + skip torch "leds_lm3644 failed (see dmesg)" + else + for _ in $(seq 40); do [[ -e $torch/brightness ]] && break; sleep 0.25; done + if [[ ! -e $torch/brightness ]]; then + log "no white:torch LED after the driver loaded (see dmesg)" + elif [[ $(cat "$torch/brightness") != 0 ]]; then + # It must start off: turn it off here and say so. + echo 0 > "$torch/brightness" 2>/dev/null + skip torch "the torch came up lit; turned off (brightness now $(cat "$torch/brightness" 2>/dev/null))" + else + up+="${up:+, }torch" + fi + fi +else + log "no torch in this DTB; skipped" +fi + +phase gauge +if ! modprobe max77779_battery; then + skip gauge "max77779_battery failed (see dmesg)" +else + for _ in $(seq 40); do [[ -e $gauge/capacity ]] && break; sleep 0.25; done + if [[ -e $gauge/capacity ]]; then + up+="${up:+, }gauge $(cat "$gauge/capacity") %" + else + log "no max77779-battery supply after the driver loaded (see dmesg)" + fi +fi + +# The address and the power-on are omamobile-bt-addr@'s, started by udev. +if enabled "$bluetooth_node"; then + phase bluetooth + if modprobe hci_uart; then up+="${up:+, }Bluetooth"; else skip Bluetooth "hci_uart failed (see dmesg)"; fi +else + log "no Bluetooth in this DTB; skipped" +fi + +finish +log "up: ${up:-nothing}" +if [[ -n $failed ]]; then + log "failed: $failed (these loads returned, so the marker is clear; --retry tries them again)" + exit 1 +fi +exit 0 diff --git a/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue b/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue new file mode 100755 index 000000000..ad5f3aea8 --- /dev/null +++ b/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue @@ -0,0 +1,61 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Pixel 9a: close the MAX77779's USB data switch after a cable replug. The +# chip opens USBSW_CTRL (0x93) on unplug and leaves it open when VBUS +# returns, so the phone never re-enumerates (device/tegu/NOTES.md 2026-10-26). +# While the gadget is not configured, VBUS is present and the switch is open, +# tegu-tcpc-switch connect (identity and VBUS checked, I2C_SLAVE never +# forced) writes 0x09 back. With the cable out (no VBUS) the switch is open +# too, and the helper would refuse: the power register is read first, so a +# day on battery costs I2C reads, not journal lines. A Type-C driver that +# owns the chip (tcpci_maxim, since kernel #124) closes the switch itself: +# then this exits and leaves the chip to it. +# omamobile-tegu-usb-rescue [--once] (--once: one pass, for the tests) +# OMAMOBILE_TEGU_ROOT: a scratch root for the package tests; +# OMAMOBILE_TEGU_RESCUE_GRACE: seconds the gadget may stay unconfigured +# before the chip is read (default 4; then once per grace period). +set -uo pipefail + +root=${OMAMOBILE_TEGU_ROOT:-} +if [[ -n $root ]]; then + [[ $root == /* && $root != / && -d $root ]] || exit 2 +fi +tool=${TEGU_TCPC_SWITCH:-/usr/bin/tegu-tcpc-switch} +grace=${OMAMOBILE_TEGU_RESCUE_GRACE:-4} +once=0 +[[ ${1:-} == --once ]] && once=1 +log() { echo "omamobile-tegu-usb-rescue: $*"; } + +[[ -x $tool ]] || { log "no $tool"; exit 0; } +tcpm_owns() { local d; for d in "$root"/sys/bus/i2c/devices/*-0025; do [[ -e $d/driver ]] && return 0; done; return 1; } +gadget_state() { cat "$root"/sys/class/udc/*/state 2>/dev/null | head -1; } +# TCPC_POWER_STATUS (0x1e) bit 2: VBUS present +vbus_present() { local p; p=$("$tool" power 2>/dev/null | tail -1); [[ -n $p ]] && (( (p & 4) != 0 )); } + +open_since=0 +log "watching the gadget state and the TCPC data switch" +while :; do + if tcpm_owns; then + log "a Type-C driver owns the chip; nothing to do" + exit 0 + fi + state=$(gadget_state) + if [[ $state == configured ]]; then + open_since=0 + else + now=$(date +%s) + (( open_since == 0 )) && open_since=$now + if (( now - open_since >= grace )); then + open_since=$now + if vbus_present; then + sw=$("$tool" switch 2>/dev/null | tail -1) + if [[ -n $sw && $sw != 0x09 ]]; then + log "gadget ${state:-absent}, VBUS present, USBSW_CTRL $sw: closing the data switch" + "$tool" connect 2>&1 | tail -1 + fi + fi + fi + fi + ((once)) && exit 0 + sleep 2 +done diff --git a/packages/omamobile-device-tegu/build b/packages/omamobile-device-tegu/build new file mode 100755 index 000000000..dbbae3421 --- /dev/null +++ b/packages/omamobile-device-tegu/build @@ -0,0 +1,9 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Compile the C tools into BUILDDIR (default: build). +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")" +out=${1:-build} +mkdir -p "$out" +${CC:-cc} ${CFLAGS:--O2} -Wall -Wextra -o "$out/reboot-to" src/reboot-to.c ${LDFLAGS:-} +${CC:-cc} ${CFLAGS:--O2} -Wall -Wextra -o "$out/tegu-tcpc-switch" src/tegu-tcpc-switch.c ${LDFLAGS:-} diff --git a/packages/omamobile-device-tegu/device.conf b/packages/omamobile-device-tegu/device.conf new file mode 100644 index 000000000..80bc14ffc --- /dev/null +++ b/packages/omamobile-device-tegu/device.conf @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: MIT +# Pixel 9a first-light descriptor. See NOTES.md. +# Data only: this is a staged port, not an installable release. +CODENAME=tegu +NAME="Pixel 9a" +USB_PRODUCT="Pixel 9a (M1)" +SOC=zumapro +COMPATIBLE="google,zumapro-tegu" +PACKAGE=omamobile-device-tegu + +DTB=exynos/google/zumapro-tegu.dtb +# Deliberately no SOC_IDS: this loader uses /soc_compatible matching. +# Stock IPOP candidates: product_id 0x9875, major 0, minor 0/1, pkg_mode 1 +# (NOTES.md). Shared support is reviewed separately in #27. +# SOC_COMPATIBLE="a0-ipop:0x9875:0:0:1 a1-ipop:0x9875:0:1:1" +# Keep both selector keys unset: #27 accepts either one. Activate only +# with the public DTB and required AVB footer values in a later PR. +# Do not use a dummy soc_id or borrow gs201's values to bypass the check. + +DTBO_SOURCE=tegu-m1-overlay.dts +DTBO_BOARD_ID=0x60b06 +DTBO_BOARD_REV=0x10000 +VENDOR_CMDLINE="console=tty0 clk_ignore_unused pd_ignore_unused printk.devkmsg=on bootconfig" +VENDOR_PAGESIZE=0x800 +# Official BP3A init_boot header; both OTA/AVB and stock-A checks: NOTES.md. +OS_VERSION=16.0.0 +OS_PATCH_LEVEL=2025-09 +BOOT_METHOD=android-v4 +BOOT_IMAGES="boot init_boot vendor_boot vendor_kernel_boot dtbo" +UFS_RW="boot_b init_boot_b vendor_boot_b vendor_kernel_boot_b dtbo_b userdata" + +INITRAMFS_INIT=/initramfs/init +PANEL_SIZE=1080x2424 +# No BRINGUP_PROBE or SIMPLEFB_TRIG_CON: those gs201 display accesses do +# not apply here. The prototype's G4 trigger handling needs its own change. diff --git a/packages/omamobile-device-tegu/etc/omamobile-mirrorlist b/packages/omamobile-device-tegu/etc/omamobile-mirrorlist new file mode 100644 index 000000000..b272b8fca --- /dev/null +++ b/packages/omamobile-device-tegu/etc/omamobile-mirrorlist @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +# Where pacman gets Omarchy Mobile's packages ([omamobile] in /etc/pacman.conf). +# While the project is private, the repository lives on the phone and is +# filled from the build machine (tools/repo-push). Once it's public, this +# becomes a URL, delivered by a package update. +Server = file:///var/lib/omamobile/repo/$arch diff --git a/packages/omamobile-device-tegu/install b/packages/omamobile-device-tegu/install new file mode 100755 index 000000000..0d6921be2 --- /dev/null +++ b/packages/omamobile-device-tegu/install @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Stage omamobile-device-tegu into DESTDIR. Never activates anything: the +# graphics start and the USB rescue are enabled by vendor wants links, as +# omarchy-mac does; the AoC start ships with no link (see README.md). +# ./install DESTDIR [BUILDDIR] (BUILDDIR holds the compiled C tools) +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")" +destination=${1:?Usage: ./install DESTDIR [BUILDDIR]} +build=${2:-build} +[[ $destination == /* && $destination != "/" ]] || { echo "Use an absolute staging directory" >&2; exit 1; } +for file in bin/*; do install -Dm755 "$file" "$destination/usr/bin/${file##*/}"; done +for tool in reboot-to tegu-tcpc-switch; do install -Dm755 "$build/$tool" "$destination/usr/bin/$tool"; done +while IFS= read -r -d '' file; do + mode=644 + [[ $file == vendor/systemd/system-sleep/* ]] && mode=755 + install -Dm$mode "$file" "$destination/usr/lib/${file#vendor/}" +done < <(find vendor -type f -print0) +while IFS= read -r -d '' file; do + install -d "$destination/usr/lib/$(dirname "${file#vendor/}")" + ln -sfn "$(readlink "$file")" "$destination/usr/lib/${file#vendor/}" +done < <(find vendor -type l -print0) +# The session's side of the graphics start, sourced by uwsm from the XDG +# data dirs (uwsm-libexec/prepare-env.sh walks XDG_DATA_DIRS too). +install -Dm644 uwsm/env.d/omamobile-tegu-graphics "$destination/usr/share/uwsm/env.d/omamobile-tegu-graphics" +install -Dm644 device.conf "$destination/usr/share/omamobile/device.conf" +install -Dm644 etc/omamobile-mirrorlist "$destination/etc/pacman.d/omamobile-mirrorlist" +install -Dm644 LICENSE "$destination/usr/share/licenses/omamobile-device-tegu/LICENSE" +install -Dm644 version "$destination/usr/share/omamobile/device-tegu/version" diff --git a/packages/omamobile-device-tegu/omamobile-device-tegu.install b/packages/omamobile-device-tegu/omamobile-device-tegu.install new file mode 100644 index 000000000..60517fa32 --- /dev/null +++ b/packages/omamobile-device-tegu/omamobile-device-tegu.install @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# Add the [omamobile] repository to pacman.conf, before [omarchy] so its +# builds (e.g. Mesa with Mali-G710 support) win. Added once; never removed +# automatically, so a user's edits stay. +add_repository() { + local conf=/etc/pacman.conf + grep -q '^\[omamobile\]' "$conf" && return + local entry='[omamobile]\nInclude = /etc/pacman.d/omamobile-mirrorlist\n' + if grep -q '^\[omarchy\]' "$conf"; then + sed -i "0,/^\[omarchy\]/s//${entry//\//\\/}\n[omarchy]/" "$conf" + elif grep -q '^\[core\]' "$conf"; then + sed -i "0,/^\[core\]/s//${entry//\//\\/}\n[core]/" "$conf" + else + printf '\n[omamobile]\nInclude = /etc/pacman.d/omamobile-mirrorlist\n' >>"$conf" + fi +} + +post_install() { + add_repository +} + +post_upgrade() { + add_repository +} diff --git a/packages/omamobile-device-tegu/src/reboot-to.c b/packages/omamobile-device-tegu/src/reboot-to.c new file mode 100644 index 000000000..f79e948ed --- /dev/null +++ b/packages/omamobile-device-tegu/src/reboot-to.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +// reboot-to: reboot with a reason the Pixel bootloader understands, +// e.g. "reboot-to bootloader" lands in fastboot. +// The kernel's syscon-reboot-mode driver stores the reason in the PMU +// before the reset; busybox reboot can't pass one. +#include +#include +#include + +/* From (stable ABI); musl's sysroot has no kernel headers */ +#define LINUX_REBOOT_MAGIC1 0xfee1dead +#define LINUX_REBOOT_MAGIC2 672274793 +#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 + +int main(int argc, char **argv) +{ + const char *reason = argc > 1 ? argv[1] : "bootloader"; + + sync(); + syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_RESTART2, reason); + perror("reboot"); + return 1; +} diff --git a/packages/omamobile-device-tegu/src/tegu-tcpc-switch.c b/packages/omamobile-device-tegu/src/tegu-tcpc-switch.c new file mode 100644 index 000000000..ebfc0c2b2 --- /dev/null +++ b/packages/omamobile-device-tegu/src/tegu-tcpc-switch.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: MIT +/* Fixed MAX77779 observations and one guarded USB data-switch restoration. */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TCPC_ADDR 0x25 + +static void fail(const char *message) +{ + perror(message); + exit(EXIT_FAILURE); +} + +static uint8_t read_byte(int fd, uint8_t reg) +{ + uint8_t value; + struct i2c_msg messages[] = { + { .addr = TCPC_ADDR, .len = 1, .buf = ® }, + { .addr = TCPC_ADDR, .flags = I2C_M_RD, .len = 1, .buf = &value }, + }; + struct i2c_rdwr_ioctl_data transfer = { + .msgs = messages, + .nmsgs = 2, + }; + int ret; + + ret = ioctl(fd, I2C_RDWR, &transfer); + if (ret != 2) { + if (ret >= 0) + errno = EIO; + fail("one-byte TCPC read"); + } + return value; +} + +static void connect_data(int fd) +{ + uint8_t bytes[] = { 0x93, 0x09 }; + struct i2c_msg message = { + .addr = TCPC_ADDR, .len = sizeof(bytes), .buf = bytes, + }; + struct i2c_rdwr_ioctl_data transfer = { + .msgs = &message, .nmsgs = 1, + }; + uint8_t value; + int ret; + + if (read_byte(fd, 0x02) != 0x79 || read_byte(fd, 0x00) != 0x56 || + read_byte(fd, 0x01) != 0x04 || !(read_byte(fd, 0x1e) & 4)) { + fputs("MAX77779 identity or present VBUS not confirmed; no write\n", stderr); + exit(EXIT_FAILURE); + } + value = read_byte(fd, 0x93); + if (value == 0x09) + return; + if (value != 0x00) { + fputs("Unexpected USB switch state; no write\n", stderr); + exit(EXIT_FAILURE); + } + if (!(read_byte(fd, 0x1e) & 4)) { + fputs("VBUS disappeared; no write\n", stderr); + exit(EXIT_FAILURE); + } + fputs("Fixed USB data-switch restoration: register 0x93 <- 0x09\n", stderr); + ret = ioctl(fd, I2C_RDWR, &transfer); + if (ret != 1) { + if (ret >= 0) + errno = EIO; + fail("fixed TCPC data-switch write"); + } + if (read_byte(fd, 0x93) != 0x09) { + fputs("USB data-switch readback failed\n", stderr); + exit(EXIT_FAILURE); + } +} + +int main(int argc, char **argv) +{ + static const struct { + const char *name; + uint8_t reg; + } reads[] = { + { "vendor-low", 0x00 }, + { "vendor-high", 0x01 }, + { "product", 0x02 }, + { "power", 0x1e }, + { "switch", 0x93 }, + }; + char path[PATH_MAX], compatible[128] = { 0 }; + FILE *file; + unsigned long functions; + size_t i; + int fd, selected = -1; + int connect = argc == 2 && !strcmp(argv[1], "connect"); + + if (argc == 2) { + for (i = 0; i < sizeof(reads) / sizeof(reads[0]); i++) { + if (!strcmp(argv[1], reads[i].name)) + selected = (int)i; + } + } + if (selected < 0 && !connect) { + fputs("Usage: tegu-tcpc-switch vendor-low|vendor-high|product|power|switch|connect\n", + stderr); + return 64; + } + file = fopen("/proc/device-tree/compatible", "rb"); + if (!file) + fail("machine compatible"); + if (!fread(compatible, 1, sizeof(compatible) - 1, file) || + strcmp(compatible, "google,zumapro-tegu")) { + fputs("Expected Pixel 9a compatible\n", stderr); + return EXIT_FAILURE; + } + fclose(file); + /* + * The USI6 adapter's number depends on probe order (it was i2c-0 on + * the curated boots and is not after the integration DT): find the + * adapter whose device is 108d0000.i2c instead of assuming i2c-0. + */ + { + char dev[64] = { 0 }; + int n; + + for (n = 0; n < 64 && !dev[0]; n++) { + char link[64]; + + snprintf(link, sizeof(link), "/sys/bus/i2c/devices/i2c-%d", n); + if (realpath(link, path) && strstr(path, "/108d0000.i2c/i2c-")) + snprintf(dev, sizeof(dev), "/dev/i2c-%d", n); + } + if (!dev[0]) { + fputs("Expected USI6 I2C adapter (108d0000.i2c)\n", stderr); + return EXIT_FAILURE; + } + fd = open(dev, O_RDWR | O_CLOEXEC); + } + if (fd < 0) + fail("open qualified I2C adapter"); + /* I2C_SLAVE, never I2C_SLAVE_FORCE: refuse an address owned by a driver. */ + if (ioctl(fd, I2C_SLAVE, TCPC_ADDR) < 0) + fail("claim unbound TCPC address"); + if (ioctl(fd, I2C_FUNCS, &functions) < 0) + fail("I2C adapter functionality"); + if (!(functions & I2C_FUNC_I2C)) { + fputs("I2C combined transfers unavailable\n", stderr); + return EXIT_FAILURE; + } + if (connect) { + connect_data(fd); + puts("0x09"); + } else { + printf("0x%02x\n", read_byte(fd, reads[selected].reg)); + } + close(fd); + return EXIT_SUCCESS; +} diff --git a/packages/omamobile-device-tegu/test/all b/packages/omamobile-device-tegu/test/all new file mode 100755 index 000000000..62bab9a55 --- /dev/null +++ b/packages/omamobile-device-tegu/test/all @@ -0,0 +1,176 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Tests for omamobile-device-tegu: the package stages what it says, enables +# only the hang-safe guards, and the scripts behave in a scratch root +# (test/graphics-start and friends, no phone, no hardware). reboot-to and +# tegu-tcpc-switch are compiled from src/, so a copied package still builds. +# Do not execute reboot-to. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } +pass() { printf 'ok - %s\n' "$1"; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT + +for script in build install bin/* vendor/systemd/system-sleep/* test/*; do + bash -n "$script" || fail "$script parses" +done +# uwsm sources the env.d file with a POSIX shell +sh -n uwsm/env.d/omamobile-tegu-graphics || fail "the uwsm env.d file parses as POSIX shell" +pass "scripts parse" + +grep -q '\.\./\.\.' build install && fail "build or install reaches outside the package directory" +pass "build and install stay inside the package directory" + +if [[ -f ../omamobile-device-cheetah/src/reboot-to.c ]]; then + cmp -s src/reboot-to.c ../omamobile-device-cheetah/src/reboot-to.c \ + || fail "reboot-to.c drifted from the cheetah package" + pass "reboot-to.c matches the cheetah source" + cmp -s vendor/udev/rules.d/10-omamobile-storage.rules \ + ../omamobile-device-cheetah/vendor/udev/rules.d/10-omamobile-storage.rules \ + || fail "the storage rule drifted from the cheetah package" + pass "the storage rule matches the cheetah package" + cmp -s etc/omamobile-mirrorlist ../omamobile-device-cheetah/etc/omamobile-mirrorlist \ + || fail "the mirrorlist drifted from the cheetah package" + pass "the mirrorlist matches the cheetah package" + cmp -s omamobile-device-tegu.install \ + ../omamobile-device-cheetah/omamobile-device-cheetah.install \ + || fail "the pacman install script drifted from the cheetah package" + pass "the pacman install script matches the cheetah package" + cmp -s vendor/systemd/sleep.conf.d/10-omamobile.conf \ + ../omamobile-device-cheetah/vendor/systemd/sleep.conf.d/10-omamobile.conf \ + || fail "the sleep drop-in drifted from the cheetah package" + pass "the sleep drop-in matches the cheetah package" +fi +grep -q 'omamobile-keyring' PKGBUILD || fail "pacman needs omamobile-keyring" +grep -q '^install=omamobile-device-tegu.install$' PKGBUILD \ + || fail "the pacman install script is not named" +for dep in kmod bluez-utils; do + grep -qE "^depends=.*\b$dep\b" PKGBUILD || fail "the scripts need $dep (depends)" +done +[[ -f etc/omamobile-mirrorlist && -f omamobile-device-tegu.install ]] \ + || fail "the pacman mirrorlist or install script is missing" +pass "pacman gets the keyring, the mirrorlist, the install script and the tools' dependencies" +if [[ -f ../../device/tegu/device.conf ]]; then + cmp -s device.conf ../../device/tegu/device.conf \ + || fail "device.conf drifted from the descriptor" + pass "device.conf matches the descriptor" +fi + +# Nothing that must come from the user's own phone or a kernel build +# makepkg's pkg/ and src/build/ are not the package (check() runs beside them) +blobs=$(find . \( -path ./pkg -o -path ./src/build \) -prune -o -type f \( -name '*.ko' -o -name '*.bin' -o -name '*.hcd' -o -name '*.img' -o -name '*.wmfw' \) -print) +[[ -z $blobs ]] || fail "binaries in the package: $blobs" +macs=$(grep -rEn '\b([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}\b' --exclude-dir=build . || true) +[[ -z $macs ]] || fail "a MAC or Bluetooth address in the package: $macs" +pass "no blobs, no addresses" + +./build "$tmp/build" || fail "the C tools compile" +[[ -x $tmp/build/reboot-to && -x $tmp/build/tegu-tcpc-switch ]] || fail "the C tools are not executable" +pass "the C tools compile" + +./install "$tmp/root" "$tmp/build" +for f in usr/bin/reboot-to usr/bin/tegu-tcpc-switch \ + usr/bin/omamobile-tegu-graphics-start usr/lib/systemd/system/omamobile-tegu-graphics.service \ + usr/lib/systemd/system/display-manager.service.d/10-omamobile-tegu.conf \ + usr/bin/omamobile-tegu-aoc-start usr/lib/systemd/system/omamobile-tegu-aoc.service \ + usr/bin/omamobile-tegu-usb-rescue usr/lib/systemd/system/omamobile-tegu-usb-rescue.service \ + usr/bin/omamobile-bt-addr usr/lib/systemd/system/omamobile-bt-addr@.service \ + usr/lib/udev/rules.d/80-omamobile-bt-addr.rules \ + usr/bin/omamobile-tegu-charge-limit usr/lib/udev/rules.d/75-omamobile-tegu-charger.rules \ + usr/lib/modprobe.d/omamobile-tegu-guards.conf usr/lib/modprobe.d/omamobile-tegu-aoc.conf \ + usr/lib/modprobe.d/omamobile-tegu-display.conf usr/lib/modprobe.d/omamobile-tegu-clk-acpm.conf \ + usr/lib/systemd/system-sleep/omamobile-tegu-wifi usr/lib/systemd/system-sleep/omamobile-tegu-nfc \ + usr/lib/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf \ + usr/lib/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf \ + usr/lib/systemd/sleep.conf.d/10-omamobile.conf \ + usr/lib/udev/rules.d/10-omamobile-storage.rules usr/lib/udev/rules.d/20-omamobile-torch.rules \ + usr/lib/udev/rules.d/70-omamobile-dma-heap.rules usr/lib/udev/rules.d/72-omamobile-feedbackd.rules \ + usr/lib/systemd/network/20-usb-gadget.network \ + usr/lib/NetworkManager/conf.d/10-omamobile-usb.conf \ + usr/share/uwsm/env.d/omamobile-tegu-graphics \ + usr/share/omamobile/device.conf \ + usr/share/omamobile/device-tegu/version \ + usr/share/licenses/omamobile-device-tegu/LICENSE \ + etc/pacman.d/omamobile-mirrorlist; do + [[ -f $tmp/root/$f ]] || fail "install stages $f" +done +[[ -x $tmp/root/usr/lib/systemd/system-sleep/omamobile-tegu-wifi && -x $tmp/root/usr/lib/systemd/system-sleep/omamobile-tegu-nfc ]] \ + || fail "the sleep hooks are not executable" +for unit in omamobile-tegu-graphics omamobile-tegu-usb-rescue; do + [[ $(readlink "$tmp/root/usr/lib/systemd/system/multi-user.target.wants/$unit.service") == ../$unit.service ]] \ + || fail "$unit is enabled by a vendor wants link" +done +[[ ! -e $tmp/root/usr/lib/systemd/system/multi-user.target.wants/omamobile-tegu-aoc.service ]] \ + || fail "the AoC start ships disabled (no wants link)" +grep -q 'KERNEL=="sda", MODE="0000"' "$tmp/root/usr/lib/udev/rules.d/10-omamobile-storage.rules" \ + || fail "the whole-disk node is made inaccessible" +grep -q 'ID_PART_ENTRY_NAME}!="userdata"' "$tmp/root/usr/lib/udev/rules.d/10-omamobile-storage.rules" \ + || fail "userdata is the only partition desktop tools may see" +grep -q 'Address=172.16.42.1/24' "$tmp/root/usr/lib/systemd/network/20-usb-gadget.network" \ + || fail "usb0 keeps the initramfs address" +grep -q 'Gateway=172.16.42.2' "$tmp/root/usr/lib/systemd/network/20-usb-gadget.network" \ + || fail "the host stays the fallback gateway" +grep -q '^PACKAGE=omamobile-device-tegu$' "$tmp/root/usr/share/omamobile/device.conf" \ + || fail "the installed descriptor is tegu" +grep -qx 'ConditionPathExists=!/usr/share/omamobile/device-tegu/version' \ + "$tmp/root/usr/lib/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf" \ + || fail "the module cleanup is held off by the package's version file" +grep -qx 'RebootWatchdogSec=1min' "$tmp/root/usr/lib/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf" \ + || fail "a hung shutdown resets the phone after a minute" +grep -q 'RuntimeWatchdogSec' "$tmp/root/usr/lib/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf" \ + && fail "no runtime watchdog from the package" +grep -q 'Before=display-manager.service' "$tmp/root/usr/lib/systemd/system/omamobile-tegu-graphics.service" \ + || fail "the graphics start runs before the display manager" +for node in 1f000000.gpu 19470000.display-controller; do + grep -qx "ConditionPathExists=|/sys/bus/platform/devices/$node" "$tmp/root/usr/lib/systemd/system/omamobile-tegu-graphics.service" \ + || fail "the graphics start runs when $node exists (ORed condition)" +done +grep -q 'omamobile-tegu-display-card' "$tmp/root/usr/share/uwsm/env.d/omamobile-tegu-graphics" \ + && grep -q 'omamobile-tegu-gpu-ready.json' "$tmp/root/usr/share/uwsm/env.d/omamobile-tegu-graphics" \ + || fail "the session reads the graphics start's two files" +grep -q 'After=omamobile-tegu-graphics.service' "$tmp/root/usr/lib/systemd/system/display-manager.service.d/10-omamobile-tegu.conf" \ + || fail "the display manager waits for the graphics start" +for absent in usr/bin/omamobile-boot-success usr/bin/omamobile-bootctl \ + usr/lib/systemd/system/omamobile-boot-success.service \ + usr/bin/omamobile-wifi-start usr/bin/omamobile-charge-guard \ + usr/bin/omamobile-camera-start usr/bin/omamobile-aoc-start \ + usr/lib/udev/rules.d/20-omamobile-gpu-always-on.rules; do + [[ ! -e $tmp/root/$absent ]] || fail "install includes $absent" +done +pass "install stages the package, enables only the guards, and nothing that marks a slot" + +# Every driver the graphics guard loads is kept from autoloading (gs_dsim_cmd +# aside: it autoloads from its node and sends nothing until allow_tx is on, +# which only the guard sets), and nothing in modprobe.d would break the +# guard's own modprobe. +for m in $(grep -v '^ *#' bin/omamobile-tegu-graphics-start | grep -oE '\bmodprobe [a-z0-9_]+' | cut -d' ' -f2 | sort -u); do + [[ $m == gs_dsim_cmd ]] && continue + grep -qx "blacklist $m" vendor/modprobe.d/omamobile-tegu-guards.conf \ + || fail "$m is loaded by the graphics guard but not blacklisted" +done +for m in panthor gs_decon cs40l26_vibra leds_lm3644 max77779_battery hci_uart; do + grep -qE "modprobe $m\b" bin/omamobile-tegu-graphics-start || fail "the graphics guard no longer loads $m" +done +for m in gsa gs201_aoc_sysmmu mailbox_wc aoc_core aoc_channel_dev aoc_alsa_dev aoc_char_dev; do + grep -qx "blacklist $m" vendor/modprobe.d/omamobile-tegu-aoc.conf \ + || fail "$m is loaded by the AoC guard but not blacklisted" +done +grep -qE '^install ' vendor/modprobe.d/*.conf && fail "an install line in modprobe.d would break a guard's modprobe" +grep -qE '^options gs_dsim_cmd' vendor/modprobe.d/omamobile-tegu-display.conf \ + && fail "allow_tx belongs to the graphics start (google-tg4c only), not modprobe.d" +grep -q 'exynos_drm.panel_name=google-tg4c' bin/omamobile-tegu-graphics-start \ + || fail "the graphics start keys allow_tx on the bootloader's panel name" +[[ $(grep -c 'max_refresh=' vendor/modprobe.d/omamobile-tegu-display.conf) == 1 ]] \ + || fail "exactly one refresh-rate ceiling" +grep -qE '^options clk_acpm zumapro_gpu_max_khz=[0-9]+' vendor/modprobe.d/omamobile-tegu-clk-acpm.conf \ + || fail "the GPU DVFS ceiling is set" +pass "modprobe.d keeps the guarded drivers from autoloading and sets the display and GPU options" + +grep -q 'chosen/config/bt_addr' bin/omamobile-bt-addr || fail "the Bluetooth address comes from the bootloader's DT" +grep -q 'HandlePowerKey' -r vendor && fail "no power-key policy from this package (omamobile-shell owns it on tegu)" +pass "the Bluetooth address is read at run time" + +for t in test/graphics-start test/aoc-start test/usb-rescue test/sleep-hooks test/charge-limit; do + "$t" || fail "$t" +done +pass "the scripts behave in a scratch root" diff --git a/packages/omamobile-device-tegu/test/aoc-start b/packages/omamobile-device-tegu/test/aoc-start new file mode 100755 index 000000000..d83cd0ff2 --- /dev/null +++ b/packages/omamobile-device-tegu/test/aoc-start @@ -0,0 +1,83 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-tegu-aoc-start in a scratch root: the marker first, Trusty before +# the GSA before the AoC drivers, the firmware request, and the ways out +# (no node, no firmware, a leftover marker, a second start on the same boot). +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +script=$PWD/bin/omamobile-tegu-aoc-start +fail() { printf 'not ok - aoc-start: %s\n' "$1" >&2; exit 1; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +export OMAMOBILE_TEGU_ROOT=$tmp/root +export TEST_LOG=$tmp/calls +export TEST_ROOT=$OMAMOBILE_TEGU_ROOT +marker=$OMAMOBILE_TEGU_ROOT/var/lib/omamobile/tegu-aoc-started +export TEST_MARKER=$marker +node=$OMAMOBILE_TEGU_ROOT/sys/bus/platform/devices/154b0000.aoc +mkdir -p "$tmp/bin" "$node" "$OMAMOBILE_TEGU_ROOT/proc/device-tree/trusty" "$OMAMOBILE_TEGU_ROOT/usr/lib/firmware" "$OMAMOBILE_TEGU_ROOT/dev" +printf 'okay\0' > "$OMAMOBILE_TEGU_ROOT/proc/device-tree/trusty/status" +: > "$OMAMOBILE_TEGU_ROOT/usr/lib/firmware/aoc-tegu.bin" +export PATH=$tmp/bin:$PATH +cat > "$tmp/bin/modprobe" <<'EOF' +#!/bin/bash +set -euo pipefail +test -s "$TEST_MARKER" +grep -qx synced "$TEST_LOG" +echo "$1" >> "$TEST_LOG" +[[ ${FAIL_MODULE:-} != "$1" ]] || exit 1 +case $1 in + trusty_virtio) : > "$TEST_ROOT/dev/trusty-ipc-dev0" ;; + aoc_core) : > "$TEST_ROOT/sys/bus/platform/devices/154b0000.aoc/firmware" ;; + aoc_char_dev) echo 'Services : 93' > "$TEST_ROOT/sys/bus/platform/devices/154b0000.aoc/services"; : > "$TEST_ROOT/dev/acd-com.google.usf" ;; +esac +EOF +printf '#!/bin/bash\necho synced >> "$TEST_LOG"\n' > "$tmp/bin/sync" +printf '#!/bin/bash\nexit 0\n' > "$tmp/bin/sleep" +chmod +x "$tmp/bin/"* +reset() { + : > "$TEST_LOG" + rm -rf "$marker" "$OMAMOBILE_TEGU_ROOT/run" "$node/firmware" "$OMAMOBILE_TEGU_ROOT/dev/"* + echo 'Services : 0' > "$node/services" +} +loads() { grep -v '^synced$' "$TEST_LOG" | tr '\n' ' ' | sed 's/ $//'; } + +reset +out=$("$script") +[[ $(loads) == "trusty_core trusty_log trusty_ipc trusty_virtio gsa gs201_aoc_sysmmu mailbox_wc aoc_core aoc_channel_dev aoc_alsa_dev aoc_char_dev" ]] \ + || fail "load order: $(loads)" +[[ $(cat "$node/firmware") == aoc-tegu.bin ]] || fail "the firmware request names aoc-tegu.bin" +[[ ! -e $marker ]] || fail "a finished start leaves the marker" +[[ -e $OMAMOBILE_TEGU_ROOT/run/omamobile/tegu-aoc-firmware-loaded ]] || fail "no firmware-loaded note for this boot" +[[ $out == *"up: Services : 93"* ]] || fail "summary: $out" + +# Started again on the same boot while not online: refuse, no loads +echo 'Services : 0' > "$node/services"; : > "$TEST_LOG" +"$script" >/dev/null && fail "a second start on the same boot was accepted" +[[ -z $(loads) ]] || fail "a second start loaded drivers" + +# A leftover marker keeps the AoC off +reset +echo stale > "$marker" +out=$("$script") +[[ -z $(loads) && $out == *"--retry"* ]] || fail "a leftover marker did not keep the AoC off" + +# A failed GSA load: exit 1, the marker is cleared (the load returned, no hang) +reset +FAIL_MODULE=gsa "$script" >/dev/null && fail "a failed load exits 0" +[[ $(loads) == "trusty_core trusty_log trusty_ipc trusty_virtio gsa" && ! -e $marker ]] \ + || fail "a failed load went on or kept the marker: $(loads)" + +# No firmware: refuse before anything loads +reset +mv "$OMAMOBILE_TEGU_ROOT/usr/lib/firmware/aoc-tegu.bin" "$tmp/fw" +"$script" >/dev/null && fail "a missing firmware was accepted" +[[ -z $(loads) && ! -e $marker ]] || fail "a missing firmware loaded drivers" +mv "$tmp/fw" "$OMAMOBILE_TEGU_ROOT/usr/lib/firmware/aoc-tegu.bin" + +# No AoC node: nothing to do, exit 0 +reset +mv "$node" "$tmp/node" +out=$("$script") +[[ -z $(loads) && $out == *"not enabled"* ]] || fail "a missing node was not skipped" +mv "$tmp/node" "$node" +echo 'ok - aoc-start: marker first, Trusty then GSA then the AoC, firmware named, refusals in place' diff --git a/packages/omamobile-device-tegu/test/charge-limit b/packages/omamobile-device-tegu/test/charge-limit new file mode 100755 index 000000000..6e9c3d16e --- /dev/null +++ b/packages/omamobile-device-tegu/test/charge-limit @@ -0,0 +1,32 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-tegu-charge-limit in a scratch root: a percentage is written to +# the charger, anything else is refused and leaves the charger alone. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +script=$PWD/bin/omamobile-tegu-charge-limit +fail() { printf 'not ok - charge-limit: %s\n' "$1" >&2; exit 1; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +export OMAMOBILE_TEGU_ROOT=$tmp/root +file=$OMAMOBILE_TEGU_ROOT/etc/omamobile/charge-limit +threshold=$OMAMOBILE_TEGU_ROOT/sys/class/power_supply/max77779-charger/charge_control_end_threshold +mkdir -p "${file%/*}" "${threshold%/*}" +echo 100 > "$threshold" + +"$script" || fail "no file is not an error" +[[ $(cat "$threshold") == 100 ]] || fail "no file changed the charger" +echo 80 > "$file" +out=$("$script") || fail "80 is refused" +[[ $(cat "$threshold") == 80 && $out == *"charge limit 80 %"* ]] || fail "80 was not written: $out" +printf ' 090\n' > "$file" +"$script" >/dev/null || fail "a padded number is refused" +[[ $(cat "$threshold") == 90 ]] || fail "090 was not written as 90" +for bad in abc 0 101 -5 8.5; do + echo "$bad" > "$file" + "$script" >/dev/null 2>&1 && fail "$bad was accepted" + [[ $(cat "$threshold") == 90 ]] || fail "$bad changed the charger" +done +rm -f "$threshold" +echo 80 > "$file" +"$script" >/dev/null || fail "a missing charger is an error" +echo 'ok - charge-limit: percentages only, the charger otherwise untouched' diff --git a/packages/omamobile-device-tegu/test/graphics-start b/packages/omamobile-device-tegu/test/graphics-start new file mode 100755 index 000000000..e214d690e --- /dev/null +++ b/packages/omamobile-device-tegu/test/graphics-start @@ -0,0 +1,180 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-tegu-graphics-start in a scratch root: the marker goes down and +# is synced before the first driver loads, the drivers load in order, a load +# that returns and fails is logged, skipped and clears the marker (the rest +# still loads), each step keys on its own device node, the panel's DSI +# commands are allowed for google-tg4c only and before gs_decon, and a +# marker from a previous boot keeps every driver off until --retry. No +# hardware is touched: modprobe, sync and sleep are fakes on PATH. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +script=$PWD/bin/omamobile-tegu-graphics-start +fail() { printf 'not ok - graphics-start: %s\n' "$1" >&2; exit 1; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +export OMAMOBILE_TEGU_ROOT=$tmp/root +export TEST_LOG=$tmp/calls +export TEST_ROOT=$OMAMOBILE_TEGU_ROOT +marker=$OMAMOBILE_TEGU_ROOT/var/lib/omamobile/tegu-graphics-started +export TEST_MARKER=$marker +dt=$OMAMOBILE_TEGU_ROOT/proc/device-tree +devices=$OMAMOBILE_TEGU_ROOT/sys/bus/platform/devices +allow_tx=$OMAMOBILE_TEGU_ROOT/sys/module/gs_dsim_cmd/parameters/allow_tx +mkdir -p "$tmp/bin" "$devices/1f000000.gpu" "$devices/19470000.display-controller" \ + "$OMAMOBILE_TEGU_ROOT/sys/bus/platform/drivers/panthor" "$OMAMOBILE_TEGU_ROOT/sys/bus/platform/drivers/gs-decon" \ + "$dt/soc/usi@10c900c0/i2c@10c90000/haptic-driver@43" \ + "$dt/soc/usi@108b00c0/i2c@108b0000/led-controller@63" \ + "$dt/soc/usi@155d00c0/serial@155d0000/bluetooth" +printf 'okay\0' > "$dt/soc/usi@10c900c0/i2c@10c90000/haptic-driver@43/status" +export PATH=$tmp/bin:$PATH +# modprobe: the marker must already be on disk; a module "binds" by creating +# what the script waits for; FAIL_MODULE fails that one load. gs_dsim_cmd +# brings its allow_tx parameter (0, the kernel's default), and gs_decon's +# line records what allow_tx read when it loaded. +cat > "$tmp/bin/modprobe" <<'EOF' +#!/bin/bash +set -euo pipefail +test -s "$TEST_MARKER" +grep -qx synced "$TEST_LOG" +[[ ${FAIL_MODULE:-} != "$1" ]] || { echo "$*" >> "$TEST_LOG"; exit 1; } +case $1 in + panthor) ln -sfn "$TEST_ROOT/sys/bus/platform/drivers/panthor" "$TEST_ROOT/sys/bus/platform/devices/1f000000.gpu/driver" ;; + gs_dsim_cmd) p=$TEST_ROOT/sys/module/gs_dsim_cmd/parameters; [[ -e $p/allow_tx ]] || { mkdir -p "$p"; echo 0 > "$p/allow_tx"; } ;; + gs_decon) ln -sfn "$TEST_ROOT/sys/bus/platform/drivers/gs-decon" "$TEST_ROOT/sys/bus/platform/devices/19470000.display-controller/driver" + set -- "$@" "allow_tx=$(cat "$TEST_ROOT/sys/module/gs_dsim_cmd/parameters/allow_tx" 2>/dev/null || echo none)" ;; + leds_lm3644) mkdir -p "$TEST_ROOT/sys/class/leds/white:torch"; echo "${TORCH_LIT:-0}" > "$TEST_ROOT/sys/class/leds/white:torch/brightness" ;; + max77779_battery) mkdir -p "$TEST_ROOT/sys/class/power_supply/max77779-battery"; echo 77 > "$TEST_ROOT/sys/class/power_supply/max77779-battery/capacity" ;; +esac +echo "$*" >> "$TEST_LOG" +EOF +printf '#!/bin/bash\necho synced >> "$TEST_LOG"\n' > "$tmp/bin/sync" +printf '#!/bin/bash\nexit 0\n' > "$tmp/bin/sleep" +chmod +x "$tmp/bin/"* +# The command line the bootloader built, with its panel name +cmdline() { mkdir -p "$OMAMOBILE_TEGU_ROOT/proc"; echo "console=null panic=10 ${1:+exynos_drm.panel_name=$1 }mem_sleep_default=s2idle" > "$OMAMOBILE_TEGU_ROOT/proc/cmdline"; } +reset() { + : > "$TEST_LOG" + rm -rf "$marker" "$devices/1f000000.gpu/driver" "$devices/19470000.display-controller/driver" \ + "$OMAMOBILE_TEGU_ROOT/sys/class" "$OMAMOBILE_TEGU_ROOT/sys/module" "$OMAMOBILE_TEGU_ROOT/run" + cmdline google-tg4c +} +loads() { grep -v '^synced$' "$TEST_LOG" | cut -d' ' -f1 | tr '\n' ' ' | sed 's/ $//'; } +all="panthor gs_dsim_cmd gs_decon cs40l26_vibra leds_lm3644 max77779_battery hci_uart" + +# A full start: the order, the gs_decon options, the marker gone, the summary, +# the session's two files +reset +out=$("$script") +[[ ! -e $marker ]] || fail "a finished start leaves the marker" +[[ $(loads) == "$all" ]] || fail "load order: $(loads)" +grep -q '^gs_decon stage=2 fbdev=0 ' "$TEST_LOG" || fail "gs_decon gets the full driver stage" +[[ $out == *"up: GPU, display, haptics, torch, gauge 77 %, Bluetooth"* ]] || fail "summary: $out" +[[ -s $OMAMOBILE_TEGU_ROOT/run/omamobile-tegu-gpu-ready.json ]] || fail "no gpu-ready file for the session" + +# google-tg4c on the command line: allow_tx reads 1 when gs_decon loads +grep -q '^gs_decon .*allow_tx=1$' "$TEST_LOG" || fail "allow_tx was not 1 before gs_decon loaded: $(grep '^gs_decon' "$TEST_LOG")" +[[ $(cat "$allow_tx") == 1 ]] || fail "allow_tx was not written" +[[ $out == *"panel google-tg4c: DSI commands allowed"* ]] || fail "the allow is not logged: $out" + +# The bootloader's form, the name with the panel's id appended (the palmtop's +# command line): allowed too +reset; cmdline google-tg4c.2d008004 +out=$("$script") +grep -q '^gs_decon .*allow_tx=1$' "$TEST_LOG" || fail "the suffixed panel name was not allowed: $(grep '^gs_decon' "$TEST_LOG")" +[[ $out == *"panel google-tg4c.2d008004: DSI commands allowed"* ]] || fail "the suffixed allow is not logged: $out" + +# Another panel: allow_tx stays 0, gs_decon still loads +reset; cmdline google-xyz9 +out=$("$script") +grep -q '^gs_decon .*allow_tx=0$' "$TEST_LOG" || fail "another panel got allow_tx: $(grep '^gs_decon' "$TEST_LOG")" +[[ $(cat "$allow_tx") == 0 ]] || fail "allow_tx was touched for another panel" +[[ $out == *"panel google-xyz9: DSI commands stay off"* ]] || fail "the other panel is not named: $out" +[[ $(loads) == "$all" ]] || fail "another panel changed the loads: $(loads)" + +# No panel name at all: the same, and said so +reset; cmdline "" +out=$("$script") +grep -q '^gs_decon .*allow_tx=0$' "$TEST_LOG" || fail "an unnamed panel got allow_tx" +[[ $out == *"panel unnamed: DSI commands stay off"* ]] || fail "an unnamed panel is not reported: $out" + +# A failed display load: exit 1, logged and skipped, the rest still loads, +# the marker is cleared (the load returned, no hang) +reset +out=$(FAIL_MODULE=gs_decon "$script") && fail "a failed load exits 0" +[[ ! -e $marker ]] || fail "a failed load kept the marker: $(cat "$marker")" +[[ $(loads) == "$all" ]] || fail "a failed load stopped the rest: $(loads)" +[[ $out == *"gs_decon failed"*"skipped"* && $out == *"failed: display"* ]] || fail "the failed step is not named: $out" +[[ $out == *"up: GPU, haptics, torch, gauge 77 %, Bluetooth"* ]] || fail "summary after a failed display: $out" +[[ ! -e $OMAMOBILE_TEGU_ROOT/run/omamobile-tegu-display-card ]] || fail "a display that did not come up left a card file" + +# panthor fails (no mali_csffw.bin yet): the display still comes up, and the +# session gets no gpu-ready file +reset +out=$(FAIL_MODULE=panthor "$script") && fail "a failed GPU exits 0" +[[ ! -e $marker ]] || fail "a failed GPU kept the marker" +[[ $(loads) == "$all" ]] || fail "a failed GPU took the display with it: $(loads)" +[[ $out == *"panthor failed"* && $out == *"up: display, haptics, torch, gauge 77 %, Bluetooth"* ]] || fail "panthor fails: $out" +[[ ! -e $OMAMOBILE_TEGU_ROOT/run/omamobile-tegu-gpu-ready.json ]] || fail "a GPU that did not come up was reported ready" + +# No GPU in the DTB: the display and the rest still come up, the unit's own +# condition aside +reset +mv "$devices/1f000000.gpu" "$tmp/gpu" +out=$("$script") || fail "no GPU node is not a failure" +[[ $(loads) == "gs_dsim_cmd gs_decon cs40l26_vibra leds_lm3644 max77779_battery hci_uart" ]] || fail "no GPU node: $(loads)" +[[ ! -e $marker && $out == *"no GPU in this DTB"* && $out == *"up: display, haptics"* ]] || fail "no GPU node: $out" +mv "$tmp/gpu" "$devices/1f000000.gpu" + +# No display controller in the DTB: the GPU and the rest still come up +reset +mv "$devices/19470000.display-controller" "$tmp/decon" +out=$("$script") || fail "no display node is not a failure" +[[ $(loads) == "panthor cs40l26_vibra leds_lm3644 max77779_battery hci_uart" ]] || fail "no display node: $(loads)" +[[ $out == *"no display controller in this DTB"* ]] || fail "no display node: $out" +mv "$tmp/decon" "$devices/19470000.display-controller" + +# Neither: nothing to do +reset +mv "$devices/1f000000.gpu" "$tmp/gpu"; mv "$devices/19470000.display-controller" "$tmp/decon" +out=$("$script") +[[ -z $(loads) && ! -e $marker && $out == *"nothing to do"* ]] || fail "no GPU and no display were not skipped" +mv "$tmp/gpu" "$devices/1f000000.gpu"; mv "$tmp/decon" "$devices/19470000.display-controller" + +# A marker left by a boot that hung: nothing loads, the hint is printed +reset +printf '%s display\n' "$(date -Is)" > "$marker" +out=$("$script") +[[ -s $marker && -z $(loads) ]] || fail "a leftover marker did not keep the drivers off" +[[ $out == *"--retry"* ]] || fail "no retry hint" + +# --retry clears it and starts again +out=$("$script" --retry) +[[ ! -e $marker && $(loads) == "$all" ]] || fail "--retry did not start again: $(loads)" + +# A torch that comes up lit is turned off and counted as failed; the rest +# still loads +reset +out=$(TORCH_LIT=1 "$script") && fail "a lit torch passed" +[[ $(cat "$OMAMOBILE_TEGU_ROOT/sys/class/leds/white:torch/brightness") == 0 ]] || fail "a lit torch was left lit" +[[ $out == *"came up lit"* && $out == *"failed: torch"* && $(loads) == "$all" ]] || fail "lit torch: $out" +[[ ! -e $marker ]] || fail "a lit torch kept the marker" + +# A disabled haptics node is skipped, a missing Bluetooth node too +reset +printf 'disabled\0' > "$dt/soc/usi@10c900c0/i2c@10c90000/haptic-driver@43/status" +mv "$dt/soc/usi@155d00c0" "$tmp/bt-node" +out=$("$script") +[[ $(loads) == "panthor gs_dsim_cmd gs_decon leds_lm3644 max77779_battery" ]] || fail "disabled nodes were loaded: $(loads)" +[[ $out == *"no haptics in this DTB"* && $out == *"no Bluetooth in this DTB"* ]] || fail "skips are not reported" +printf 'okay\0' > "$dt/soc/usi@10c900c0/i2c@10c90000/haptic-driver@43/status" +mv "$tmp/bt-node" "$dt/soc/usi@155d00c0" + +# A driver already loaded this boot is never retried +reset +mkdir -p "$OMAMOBILE_TEGU_ROOT/sys/module/panthor" +out=$("$script") +[[ -z $(loads) && ! -e $marker && $out == *"already started"* ]] || fail "a loaded driver was retried" + +# A bad argument +"$script" --bogus >/dev/null 2>&1 && fail "a bad argument is accepted" +echo 'ok - graphics-start: marker first, order kept, failures skipped and named, allow_tx for google-tg4c only, --retry works' diff --git a/packages/omamobile-device-tegu/test/sleep-hooks b/packages/omamobile-device-tegu/test/sleep-hooks new file mode 100755 index 000000000..11dd15a38 --- /dev/null +++ b/packages/omamobile-device-tegu/test/sleep-hooks @@ -0,0 +1,113 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# The sleep hooks in a scratch root with fake lsmod, modprobe, rmmod, +# systemctl, logger and busctl: Wi-Fi is left alone when kept and present, +# unloaded and reloaded otherwise, and falls back after a lost sleep; NFC's +# poll loop is stopped before the sleep and started again after it, and the +# adapter is powered off only behind the flag file. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +wifi=$PWD/vendor/systemd/system-sleep/omamobile-tegu-wifi +nfc=$PWD/vendor/systemd/system-sleep/omamobile-tegu-nfc +fail() { printf 'not ok - sleep-hooks: %s\n' "$1" >&2; exit 1; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +export OMAMOBILE_TEGU_ROOT=$tmp/root +export TEST_LOG=$tmp/calls +export TEST_LOADED=$tmp/loaded +export TEST_NFC=$tmp/nfc +mkdir -p "$tmp/bin" "$OMAMOBILE_TEGU_ROOT/etc/omamobile" "$TEST_NFC" +export PATH=$tmp/bin:$PATH +printf '#!/bin/bash\n[[ -e $TEST_LOADED ]] && echo "brcmfmac 1 0"\nexit 0\n' > "$tmp/bin/lsmod" +printf '#!/bin/bash\necho "modprobe $*" >> "$TEST_LOG"; : > "$TEST_LOADED"\n' > "$tmp/bin/modprobe" +printf '#!/bin/bash\necho "rmmod $*" >> "$TEST_LOG"; rm -f "$TEST_LOADED"\n' > "$tmp/bin/rmmod" +printf '#!/bin/bash\necho "systemctl $*" >> "$TEST_LOG"\n' > "$tmp/bin/systemctl" +printf '#!/bin/bash\necho "logger $*" >> "$TEST_LOG"\n' > "$tmp/bin/logger" +printf '#!/bin/bash\nshift; exec "$@"\n' > "$tmp/bin/timeout" +printf '#!/bin/bash\nexit 0\n' > "$tmp/bin/sleep" +printf '#!/bin/bash\nexit 0\n' > "$tmp/bin/sync" +# busctl: Polling and Powered are files in TEST_NFC; calls and sets are logged +cat > "$tmp/bin/busctl" <<'EOF' +#!/bin/bash +case $1 in + get-property) [[ -e $TEST_NFC/$5 ]] && echo 'b true' || echo 'b false' ;; + call) echo "busctl call $5" >> "$TEST_LOG" + [[ $5 == StopPollLoop ]] && rm -f "$TEST_NFC/Polling" + [[ $5 == StartPollLoop ]] && : > "$TEST_NFC/Polling" ;; + set-property) echo "busctl set $5 $7" >> "$TEST_LOG" + [[ $7 == true ]] && : > "$TEST_NFC/Powered" || rm -f "$TEST_NFC/Powered" + [[ $7 == true ]] || rm -f "$TEST_NFC/Polling" ;; +esac +exit 0 +EOF +chmod +x "$tmp/bin/"* +calls() { tr '\n' ';' < "$TEST_LOG" | sed 's/;$//'; } +run=$OMAMOBILE_TEGU_ROOT/run/omamobile +keep=$OMAMOBILE_TEGU_ROOT/etc/omamobile/wifi-keep-across-sleep +power_off=$OMAMOBILE_TEGU_ROOT/etc/omamobile/nfc-power-off-across-sleep +nfc_log=$OMAMOBILE_TEGU_ROOT/var/log/omamobile/nfc-sleep.log +iface() { mkdir -p "$OMAMOBILE_TEGU_ROOT/sys/bus/pci/drivers/brcmfmac/0000:01:00.0" "$OMAMOBILE_TEGU_ROOT/sys/class/ieee80211/phy0"; } +no_iface() { rm -rf "$OMAMOBILE_TEGU_ROOT/sys"; } + +# Wi-Fi never loaded this boot: the hook does nothing +: > "$TEST_LOG"; rm -f "$TEST_LOADED" "$keep" +"$wifi" pre; "$wifi" post +[[ -z $(calls) ]] || fail "an unloaded Wi-Fi was touched: $(calls)" + +# Loaded, no keep flag: unload before, reload after +: > "$TEST_LOG"; : > "$TEST_LOADED" +"$wifi" pre +[[ $(calls) == "systemctl stop iwd;rmmod brcmfmac_wcc brcmfmac" && -e $run/wifi-unloaded-for-sleep ]] \ + || fail "no keep flag: not unloaded before the sleep: $(calls)" +"$wifi" post +[[ $(calls) == "systemctl stop iwd;rmmod brcmfmac_wcc brcmfmac;modprobe brcmfmac;systemctl start iwd" && ! -e $run/wifi-unloaded-for-sleep ]] \ + || fail "no keep flag: not reloaded after the sleep: $(calls)" + +# Kept and back after the sleep: nothing happens +: > "$TEST_LOG"; : > "$TEST_LOADED"; : > "$keep"; iface +"$wifi" pre; "$wifi" post +[[ -z $(calls) ]] || fail "kept Wi-Fi was touched: $(calls)" + +# Kept but lost in the sleep: fall back to unloading for the rest of the boot +: > "$TEST_LOG"; no_iface +"$wifi" post +[[ $(calls) == "logger -t omamobile-tegu-wifi Wi-Fi lost across sleep; unloading it around sleeps until reboot;systemctl stop iwd;rmmod brcmfmac_wcc brcmfmac;modprobe brcmfmac;systemctl start iwd" ]] \ + || fail "a lost Wi-Fi was not reloaded: $(calls)" +[[ -e $run/wifi-unload-across-sleep ]] || fail "no fallback flag after a lost sleep" +: > "$TEST_LOG" +"$wifi" pre +[[ $(calls) == "systemctl stop iwd;rmmod brcmfmac_wcc brcmfmac" ]] || fail "the fallback flag is not honoured: $(calls)" + +# NFC powered and polling, no flag file: the poll loop is stopped before and +# started again after; the adapter stays powered; both readings are logged +: > "$TEST_LOG"; rm -f "$power_off" "$nfc_log"; : > "$TEST_NFC/Polling"; : > "$TEST_NFC/Powered" +"$nfc" pre +[[ $(calls) == "busctl call StopPollLoop" ]] || fail "NFC pre: $(calls)" +[[ -e $run/nfc-was-polling && ! -e $run/nfc-was-powered ]] || fail "NFC pre notes: polling only" +[[ -e $TEST_NFC/Powered ]] || fail "NFC pre powered the adapter off without the flag" +"$nfc" post +[[ $(calls) == "busctl call StopPollLoop;busctl call StartPollLoop" ]] || fail "NFC post: $(calls)" +[[ ! -e $run/nfc-was-polling && ! -e $run/nfc-was-powered ]] || fail "NFC post left its notes" +grep -q ' pre: polling=b false powered=b true$' "$nfc_log" || fail "NFC pre is not logged: $(cat "$nfc_log")" +grep -q ' post: polling=b true powered=b true$' "$nfc_log" || fail "NFC post is not logged: $(cat "$nfc_log")" + +# Powered but not polling: nothing to stop, nothing to restart, still logged +: > "$TEST_LOG"; rm -f "$nfc_log" "$TEST_NFC/Polling" +"$nfc" pre; "$nfc" post +[[ -z $(calls) ]] || fail "an idle NFC adapter was touched: $(calls)" +grep -q ' pre: polling=b false powered=b true$' "$nfc_log" || fail "an idle adapter is not logged" + +# With the flag file: stopped and powered off before, powered on and polling after +: > "$TEST_LOG"; : > "$power_off"; : > "$TEST_NFC/Polling" +"$nfc" pre +[[ $(calls) == "busctl call StopPollLoop;busctl set Powered false" ]] || fail "NFC pre with the flag: $(calls)" +[[ -e $run/nfc-was-polling && -e $run/nfc-was-powered ]] || fail "NFC pre with the flag left no notes" +"$nfc" post +[[ $(calls) == "busctl call StopPollLoop;busctl set Powered false;busctl set Powered true;busctl call StartPollLoop" ]] || fail "NFC post with the flag: $(calls)" +[[ -e $TEST_NFC/Powered && -e $TEST_NFC/Polling ]] || fail "NFC post with the flag did not bring the adapter back" +rm -f "$power_off" + +# NFC off (no neard): nothing is called +: > "$TEST_LOG"; rm -f "$TEST_NFC"/* +"$nfc" pre; "$nfc" post +[[ -z $(calls) ]] || fail "an off NFC adapter was touched: $(calls)" +echo 'ok - sleep-hooks: Wi-Fi kept or reloaded as flagged, NFC polling stopped and restored, power-off behind the flag' diff --git a/packages/omamobile-device-tegu/test/usb-rescue b/packages/omamobile-device-tegu/test/usb-rescue new file mode 100755 index 000000000..377d7eaa3 --- /dev/null +++ b/packages/omamobile-device-tegu/test/usb-rescue @@ -0,0 +1,55 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-tegu-usb-rescue in a scratch root, one pass at a time: a +# configured gadget is left alone, an open switch on an unconfigured gadget +# with VBUS is closed once, a closed switch is not written, the cable out +# (no VBUS) costs one register read and no log line, and a Type-C driver +# that owns the chip ends the watch before the chip is read. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +script=$PWD/bin/omamobile-tegu-usb-rescue +fail() { printf 'not ok - usb-rescue: %s\n' "$1" >&2; exit 1; } +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +export OMAMOBILE_TEGU_ROOT=$tmp/root +export OMAMOBILE_TEGU_RESCUE_GRACE=0 +export TEST_LOG=$tmp/calls +export TEGU_TCPC_SWITCH=$tmp/bin/tegu-tcpc-switch +udc=$OMAMOBILE_TEGU_ROOT/sys/class/udc/11110000.dwc3 +mkdir -p "$tmp/bin" "$udc" "$OMAMOBILE_TEGU_ROOT/sys/bus/i2c/devices/21-0025" +# power: TCPC_POWER_STATUS, bit 2 VBUS present (0x04 unless PW says otherwise) +cat > "$tmp/bin/tegu-tcpc-switch" <<'EOF' +#!/bin/bash +echo "$1" >> "$TEST_LOG" +case $1 in power) echo "${PW:-0x04}" ;; switch) echo "${SW:-0x09}" ;; connect) echo 0x09 ;; esac +EOF +chmod +x "$tmp/bin/tegu-tcpc-switch" +calls() { tr '\n' ' ' < "$TEST_LOG" | sed 's/ $//'; } + +: > "$TEST_LOG"; echo configured > "$udc/state" +SW=0x00 "$script" --once >/dev/null +[[ -z $(calls) ]] || fail "a configured gadget was touched: $(calls)" + +: > "$TEST_LOG"; echo 'not attached' > "$udc/state" +out=$(SW=0x00 "$script" --once) +[[ $(calls) == "power switch connect" ]] || fail "an open switch was not closed once: $(calls)" +[[ $out == *"closing the data switch"* ]] || fail "the close is not logged" + +: > "$TEST_LOG" +out=$(SW=0x09 "$script" --once) +[[ $(calls) == "power switch" ]] || fail "a closed switch was written: $(calls)" +[[ $out != *"closing"* ]] || fail "a closed switch was logged as closed again" + +# The cable out: the switch reads open (as the chip leaves it), but with no +# VBUS nothing is written and nothing is logged beyond the watch line +: > "$TEST_LOG" +out=$(PW=0x00 SW=0x00 "$script" --once) +[[ $(calls) == "power" ]] || fail "the cable out still read or wrote the switch: $(calls)" +[[ $(printf '%s\n' "$out" | grep -c .) == 1 && $out == *"watching"* ]] || fail "the cable out wrote to the journal: $out" + +: > "$TEST_LOG"; ln -s /dev/null "$OMAMOBILE_TEGU_ROOT/sys/bus/i2c/devices/21-0025/driver" +out=$(SW=0x00 "$script" --once) +[[ -z $(calls) && $out == *"owns the chip"* ]] || fail "a Type-C driver did not end the watch: $(calls)" + +rm -f "$TEGU_TCPC_SWITCH" +"$script" --once >/dev/null || fail "a missing helper is not fatal" +echo 'ok - usb-rescue: closes an open switch once with VBUS, quiet with the cable out, defers to a Type-C driver' diff --git a/packages/omamobile-device-tegu/uwsm/env.d/omamobile-tegu-graphics b/packages/omamobile-device-tegu/uwsm/env.d/omamobile-tegu-graphics new file mode 100644 index 000000000..7b953365a --- /dev/null +++ b/packages/omamobile-device-tegu/uwsm/env.d/omamobile-tegu-graphics @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: MIT +# The session's side of omamobile-tegu-graphics-start, sourced by uwsm from +# /usr/share/uwsm/env.d (POSIX shell; a user's ~/.config/uwsm/env runs after +# it and may override). The display controller's DRM node is the one the +# start wrote to /run/omamobile-tegu-display-card, whichever card number it +# got (the GPU may take card0); hardware GL only when the start reported the +# GPU up in /run/omamobile-tegu-gpu-ready.json, otherwise llvmpipe, so a +# phone whose GPU did not come up still gets a desktop. +if [ -r /run/omamobile-tegu-display-card ]; then + read -r tegu_display_card < /run/omamobile-tegu-display-card + case "$tegu_display_card" in + /dev/dri/card[0-9]*) + if [ -c "$tegu_display_card" ]; then + export AQ_DRM_DEVICES="$tegu_display_card" + fi + ;; + esac + unset tegu_display_card +fi +if [ -c /dev/dri/renderD128 ] && [ -s /run/omamobile-tegu-gpu-ready.json ]; then + export LIBGL_ALWAYS_SOFTWARE=0 + unset GALLIUM_DRIVER QT_QUICK_BACKEND + export QSG_RHI_BACKEND=opengl +else + export LIBGL_ALWAYS_SOFTWARE=1 + export GALLIUM_DRIVER=llvmpipe + export QT_QUICK_BACKEND=software + unset QSG_RHI_BACKEND +fi diff --git a/packages/omamobile-device-tegu/vendor/NetworkManager/conf.d/10-omamobile-usb.conf b/packages/omamobile-device-tegu/vendor/NetworkManager/conf.d/10-omamobile-usb.conf new file mode 100644 index 000000000..252de6e15 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/NetworkManager/conf.d/10-omamobile-usb.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: the USB gadget link to the host (usb0) is configured by +# systemd-networkd; NetworkManager manages everything else (Wi-Fi later). +[keyfile] +unmanaged-devices=interface-name:usb0 diff --git a/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-aoc.conf b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-aoc.conf new file mode 100644 index 000000000..ef470fc35 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-aoc.conf @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: MIT +# AoC: only omamobile-tegu-aoc-start (or a bring-up runbook) loads these, in +# order. Explicit modprobe still works. +blacklist gsa +blacklist gs201_aoc_sysmmu +blacklist mailbox_wc +blacklist aoc_core +blacklist aoc_channel_dev +blacklist aoc_char_dev +# The sound card's driver would load at boot and pull aoc_core, gsa and Trusty +# in ahead of the order above; the start script loads it with the others. +blacklist aoc_alsa_dev +blacklist aoc_alsa_dev_util diff --git a/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-clk-acpm.conf b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-clk-acpm.conf new file mode 100644 index 000000000..59c99ab55 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-clk-acpm.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# GPU DVFS top level through the ACPM clocks (kernel #84): 890 MHz, the +# highest level the bring-up ran under its thermal throttle; 940 MHz is +# still untested. +options clk_acpm zumapro_gpu_max_khz=890000 diff --git a/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-display.conf b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-display.conf new file mode 100644 index 000000000..083e7232a --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-display.conf @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: MIT +# The panel's DSI commands (brightness, sleep, the refresh rate) are not +# allowed here: omamobile-tegu-graphics-start turns gs_dsim_cmd.allow_tx on +# only when the bootloader names the google-tg4c panel (kernel #90), before +# gs_decon loads. On any other panel the 120 Hz ceiling falls back to 60 Hz. +# 120 Hz (kernel #88) and the panel really off on DPMS, as the owner's phone +# runs it. omamobile-tegu-graphics-start adds stage=2 (the full driver) and +# fbdev=0 on its modprobe line. +options gs_decon max_refresh=120 screen_off=2 diff --git a/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-guards.conf b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-guards.conf new file mode 100644 index 000000000..c1f91e335 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/modprobe.d/omamobile-tegu-guards.conf @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Loaded only by the package's hang-safe scripts, in their order, after a +# marker is written: omamobile-tegu-graphics-start (the first six) and, once +# a kernel ships them in tree, the Wi-Fi and NFC starts. Blacklisting only +# stops udev from autoloading them ahead of the guard; "modprobe panthor" +# still works. No "install X /bin/false" lines: those break the guard's own +# modprobe. +blacklist panthor +blacklist gs_decon +blacklist cs40l26_vibra +blacklist leds_lm3644 +blacklist max77779_battery +blacklist hci_uart +blacklist pcie_zumapro +blacklist brcmfmac +blacklist nxp_nci_i2c diff --git a/packages/omamobile-device-tegu/vendor/systemd/network/20-usb-gadget.network b/packages/omamobile-device-tegu/vendor/systemd/network/20-usb-gadget.network new file mode 100644 index 000000000..0dc179bd0 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/network/20-usb-gadget.network @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: USB networking to the host. The initramfs sets up the USB +# gadget (CDC NCM) before handing over to Arch; this gives it an address. +# The host shares its internet over this link (NetworkManager "shared" +# mode on 172.16.42.2), so it is also the gateway. DNS goes to public resolvers. +[Match] +Name=usb0 + +[Network] +Address=172.16.42.1/24 +DNS=1.1.1.1 +DNS=9.9.9.9 +ConfigureWithoutCarrier=yes + +# Prefer Wi-Fi (NetworkManager's metric 600) when it is available. Keep the +# host's shared connection as a fallback for initial setup over USB. +[Route] +Destination=0.0.0.0/0 +Gateway=172.16.42.2 +Metric=2048 diff --git a/packages/omamobile-device-tegu/vendor/systemd/sleep.conf.d/10-omamobile.conf b/packages/omamobile-device-tegu/vendor/systemd/sleep.conf.d/10-omamobile.conf new file mode 100644 index 000000000..d5f37e34c --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/sleep.conf.d/10-omamobile.conf @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: MIT +# The firmware advertises PSCI SYSTEM_SUSPEND, so the kernel offers "deep" +# sleep, but Linux has no gs201 SoC sleep sequence yet: entering it without +# one doesn't wake. Suspend means suspend-to-idle until SYS_SLEEP exists +# (device/cheetah/SUSPEND-PLAN.md, sections 1 and 5). There is no swap to +# hibernate to. +[Sleep] +MemorySleepMode=s2idle +AllowHibernation=no +AllowHybridSleep=no +AllowSuspendThenHibernate=no diff --git a/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-nfc b/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-nfc new file mode 100755 index 000000000..7f8705cd9 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-nfc @@ -0,0 +1,62 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# systemd-sleep hook for the Pixel 9a's NFC (ST54L on nxp-nci). Polling +# through s2idle reset the palmtop (2026-10-27); with the poll loop stopped +# first, every cycle since has woken (35 of 35 that day). So before the +# sleep: stop neard's poll loop, read Polling back and log it. After the +# wake: start the poll loop again if it was polling. Nothing happens +# without neard, or with the adapter off. +# +# Powering the adapter off as well (the kernel refuses a device-down while +# polling, EBUSY, so the poll loop stops first) was the workaround for a +# controller that didn't answer on I2C after a wake: the symptom is +# https://github.com/derekross/omarchy-mobile/issues/132, the fix +# https://github.com/derekross/linux-omarchy-mobile/pull/131. That step is +# off by default: it runs only while /etc/omamobile/nfc-power-off-across-sleep +# exists (its record is one wake that needed the power key and one that +# worked), and then the adapter is powered on again after the wake. +# Logs every step to /var/log/omamobile/nfc-sleep.log. +# OMAMOBILE_TEGU_ROOT: a scratch root for the package tests. +root=${OMAMOBILE_TEGU_ROOT:-} +A=/org/neard/nfc0 +D=$root/run/omamobile +L=$root/var/log/omamobile/nfc-sleep.log +POWER_OFF=$root/etc/omamobile/nfc-power-off-across-sleep +mkdir -p "$D" "${L%/*}" +log() { echo "$(date -Is) $1: $2" >> "$L"; } +prop() { busctl get-property org.neard $A org.neard.Adapter "$1" 2>/dev/null; } +is_true() { prop "$1" | grep -c true >/dev/null; } +case "$1" in + pre) + rm -f "$D/nfc-was-polling" "$D/nfc-was-powered" + if ! is_true Powered; then + log pre "adapter off or no neard; nothing to do" + exit 0 + fi + if is_true Polling; then + : > "$D/nfc-was-polling" + out=$(busctl call org.neard $A org.neard.Adapter StopPollLoop 2>&1) || log pre "StopPollLoop: $out" + for i in 1 2 3 4 5; do is_true Polling || break; sleep 0.2; done + fi + if [[ -e $POWER_OFF ]]; then + : > "$D/nfc-was-powered" + out=$(busctl set-property org.neard $A org.neard.Adapter Powered b false 2>&1) || log pre "Powered false: $out" + for i in 1 2 3 4 5; do is_true Powered || break; sleep 0.2; done + fi + log pre "polling=$(prop Polling) powered=$(prop Powered)" + sync + ;; + post) + if [[ -e $D/nfc-was-powered ]]; then + rm -f "$D/nfc-was-powered" + out=$(busctl set-property org.neard $A org.neard.Adapter Powered b true 2>&1) || log post "Powered true: $out" + for i in 1 2 3 4 5 6 7 8 9 10; do is_true Powered && break; sleep 0.3; done + fi + if [[ -e $D/nfc-was-polling ]]; then + rm -f "$D/nfc-was-polling" + out=$(busctl call org.neard $A org.neard.Adapter StartPollLoop s Initiator 2>&1) || log post "StartPollLoop: $out" + fi + log post "polling=$(prop Polling) powered=$(prop Powered)" + ;; +esac +exit 0 diff --git a/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-wifi b/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-wifi new file mode 100755 index 000000000..d1d8bf663 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system-sleep/omamobile-tegu-wifi @@ -0,0 +1,70 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# systemd-sleep hook for the Pixel 9a's BCM4383 (device/tegu/WIFI-PLAN.md). +# +# Wi-Fi survives s2idle loaded: brcmfmac sends D3, the chip loses its +# firmware in sleep, and on resume brcmfmac finds that and probes it again +# ("device lost its state in sleep, probing again"); iwd reconnects within +# seconds. So when /etc/omamobile/wifi-keep-across-sleep exists the hook +# leaves Wi-Fi alone and only reloads it afterwards if it didn't come back. +# Without the flag, or after a sleep that lost Wi-Fi, it unloads brcmfmac +# before the sleep and reloads it afterwards. Nothing happens on a boot +# where Wi-Fi was never loaded. +# OMAMOBILE_TEGU_ROOT: a scratch root for the package tests. +root=${OMAMOBILE_TEGU_ROOT:-} +KEEP=$root/etc/omamobile/wifi-keep-across-sleep +RUNDIR=$root/run/omamobile +FALLBACK=$RUNDIR/wifi-unload-across-sleep +UNLOADED=$RUNDIR/wifi-unloaded-for-sleep + +loaded() { lsmod | grep -c '^brcmfmac ' >/dev/null; } + +wifi_up() { + local i + for i in $(seq 1 20); do + ls "$root"/sys/bus/pci/drivers/brcmfmac/ 2>/dev/null | grep -c '^0000:' >/dev/null && + ls "$root"/sys/class/ieee80211/ 2>/dev/null | grep -c . >/dev/null && return 0 + sleep 1 + done + return 1 +} + +unload() { + systemctl stop iwd + timeout 20 rmmod brcmfmac_wcc brcmfmac 2>/dev/null || true +} + +reload() { + loaded || modprobe brcmfmac + systemctl start iwd +} + +mkdir -p "$RUNDIR" +case "$1" in + pre) + rm -f "$UNLOADED" + loaded || exit 0 + if [[ -e $KEEP && ! -e $FALLBACK ]]; then + exit 0 + fi + unload + : > "$UNLOADED" + ;; + post) + if [[ -e $UNLOADED ]]; then + rm -f "$UNLOADED" + reload + exit 0 + fi + loaded || exit 0 + if wifi_up; then + exit 0 + fi + # Wi-Fi didn't come back: unload around sleeps for the rest of this boot. + : > "$FALLBACK" + logger -t omamobile-tegu-wifi "Wi-Fi lost across sleep; unloading it around sleeps until reboot" + unload + reload + ;; +esac +exit 0 diff --git a/packages/omamobile-device-tegu/vendor/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf b/packages/omamobile-device-tegu/vendor/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf new file mode 100644 index 000000000..9764faba8 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system.conf.d/10-omamobile-reboot-watchdog.conf @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: if shutdown hangs (a driver stuck in remove(), say), let the +# hardware watchdog reset the phone after a minute instead of leaving it +# on the shutdown splash until someone holds Power. systemd's default is +# 10 minutes. Nothing holds the watchdog while the system runs. +[Manager] +RebootWatchdogSec=1min diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/display-manager.service.d/10-omamobile-tegu.conf b/packages/omamobile-device-tegu/vendor/systemd/system/display-manager.service.d/10-omamobile-tegu.conf new file mode 100644 index 000000000..919c7e7cd --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/display-manager.service.d/10-omamobile-tegu.conf @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# The display manager needs the GPU and the display controller, which the +# hang-safe graphics start loads; without this it would come up on no DRM +# device and give up. +[Unit] +Wants=omamobile-tegu-graphics.service +After=omamobile-tegu-graphics.service diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf b/packages/omamobile-device-tegu/vendor/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf new file mode 100644 index 000000000..cc48a8901 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +[Unit] +# Our slot-B kernels come as modules tarballs (bin/omamobile push), not as +# pacman-owned kernel packages. Arch's cleanup would remove the running, +# next-boot and rollback module trees; keep them while this package exists. +ConditionPathExists=!/usr/share/omamobile/device-tegu/version diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-graphics.service b/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-graphics.service new file mode 120000 index 000000000..f93023ce6 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-graphics.service @@ -0,0 +1 @@ +../omamobile-tegu-graphics.service \ No newline at end of file diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-usb-rescue.service b/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-usb-rescue.service new file mode 120000 index 000000000..5619acf9c --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/multi-user.target.wants/omamobile-tegu-usb-rescue.service @@ -0,0 +1 @@ +../omamobile-tegu-usb-rescue.service \ No newline at end of file diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-bt-addr@.service b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-bt-addr@.service new file mode 100644 index 000000000..e6d7b652d --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-bt-addr@.service @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: MIT +# Started by 80-omamobile-bt-addr.rules for the BCM4383 Bluetooth controller. +# A service rather than a udev RUN, because udev's sandbox has no Bluetooth +# sockets. +[Unit] +Description=Set the Bluetooth address of %i from the bootloader +Before=bluetooth.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/omamobile-bt-addr %i diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-aoc.service b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-aoc.service new file mode 100644 index 000000000..87966fd84 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-aoc.service @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT +# The AoC (audio and sensor DSP) at boot, through the hang-safe +# omamobile-tegu-aoc-start. Not enabled by the package: the Pixel 9a kernel +# does not yet enable the AoC, GSA and Trusty nodes in its device tree (they +# are turned on by out-of-tree overlay modules in the bring-up), so the +# script would find nothing to do. Once a kernel enables them: +# systemctl enable omamobile-tegu-aoc.service +# The AoC modules are blacklisted for autoload (modprobe.d/omamobile-tegu-aoc.conf). +[Unit] +Description=Boot the Pixel 9a AoC audio and sensor DSP (hang-safe) +After=local-fs.target systemd-modules-load.service +ConditionPathExists=/sys/bus/platform/devices/154b0000.aoc + +[Service] +Type=oneshot +ExecStart=/usr/bin/omamobile-tegu-aoc-start +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-graphics.service b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-graphics.service new file mode 100644 index 000000000..b14a5d188 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-graphics.service @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# The GPU, display, haptics, torch, gauge and Bluetooth controller at boot, +# enabled by the vendor multi-user.target.wants link. The drivers are +# blacklisted for autoload (modprobe.d/omamobile-tegu-guards.conf), so this +# hang-safe script is the only thing that loads them; if a start hangs, the +# next boot leaves them off (see the script). Runs before the display +# manager (display-manager.service.d/10-omamobile-tegu.conf). The two +# ConditionPathExists=| lines are ORed by systemd: a DTB with the display +# but no GPU still gets its display. +[Unit] +Description=Bring up the Pixel 9a GPU, display, haptics, torch, gauge and Bluetooth (hang-safe) +After=local-fs.target systemd-modules-load.service +Before=display-manager.service +ConditionPathExists=|/sys/bus/platform/devices/1f000000.gpu +ConditionPathExists=|/sys/bus/platform/devices/19470000.display-controller + +[Service] +Type=oneshot +ExecStart=/usr/bin/omamobile-tegu-graphics-start +RemainAfterExit=yes +TimeoutStartSec=120 + +[Install] +WantedBy=multi-user.target diff --git a/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-usb-rescue.service b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-usb-rescue.service new file mode 100644 index 000000000..76ea62860 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/systemd/system/omamobile-tegu-usb-rescue.service @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +# Close the USB data switch after each replug (omamobile-tegu-usb-rescue). +# Exits by itself when a Type-C driver owns the MAX77779. +[Unit] +Description=Reconnect USB after a replug (MAX77779 data switch) +After=systemd-modules-load.service + +[Service] +ExecStartPre=-/usr/bin/modprobe i2c-dev +ExecStart=/usr/bin/omamobile-tegu-usb-rescue +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/10-omamobile-storage.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/10-omamobile-storage.rules new file mode 100644 index 000000000..89c02cf30 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/10-omamobile-storage.rules @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile storage guard, continued in Arch. The initramfs marks every UFS +# partition read-only except slot B's boot images and userdata, and removes +# the whole-disk node of the main LUN. udev would recreate /dev/sda, so make +# the whole-disk node inaccessible and keep desktop tools from touching any +# Android partition. +SUBSYSTEM=="block", KERNEL=="sda", MODE="0000", ENV{UDISKS_IGNORE}="1" +SUBSYSTEM=="block", KERNEL=="sd[a-d][0-9]*", ENV{ID_PART_ENTRY_NAME}!="userdata", ENV{UDISKS_IGNORE}="1" diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/20-omamobile-torch.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/20-omamobile-torch.rules new file mode 100644 index 000000000..7104ff66c --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/20-omamobile-torch.rules @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# The rear torch tile uses brightnessctl as the desktop user. Grant the +# existing video group access only to this driver's brightness attribute; +# the kernel's board current cap still limits every request. +ACTION=="add", SUBSYSTEM=="leds", KERNEL=="white:torch", DRIVERS=="lm3644", RUN+="/usr/bin/chgrp video /sys%p/brightness", RUN+="/usr/bin/chmod g+w /sys%p/brightness" diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/70-omamobile-dma-heap.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/70-omamobile-dma-heap.rules new file mode 100644 index 000000000..2341cae32 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/70-omamobile-dma-heap.rules @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# libcamera's software ISP (and so PipeWire's libcamera plugin, which runs in +# the user's WirePlumber) allocates its output buffers from the DMA-BUF heaps. +# They are root-only by default, so without this a user session saw the +# cameras but got no debayered stream ("Could not open any dma-buf provider", +# device/cheetah/CAMERA-PLAN.md CAM5.4). Give the video group and the seat's +# user the general heaps; the camera and display pools stay the kernel's. +SUBSYSTEM=="dma_heap", KERNEL=="system|reserved|default_cma_region", GROUP="video", MODE="0660", TAG+="uaccess" diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/72-omamobile-feedbackd.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/72-omamobile-feedbackd.rules new file mode 100644 index 000000000..88ad325a3 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/72-omamobile-feedbackd.rules @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: let feedbackd drive the Cirrus Logic CS40L26 haptics +# (cs40l26-vibra), in the same form as feedbackd's own 72-feedbackd.rules. +# Before 73-seat-late.rules, which turns the uaccess tag into an ACL. +ACTION=="remove", GOTO="omamobile_feedbackd_end" +SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", SUBSYSTEMS=="input", ATTRS{name}=="cs40l26_vibra", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="vibra" +LABEL="omamobile_feedbackd_end" diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/75-omamobile-tegu-charger.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/75-omamobile-tegu-charger.rules new file mode 100644 index 000000000..ed60bab49 --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/75-omamobile-tegu-charger.rules @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: apply /etc/omamobile/charge-limit when the MAX77779 charger +# appears (omamobile-tegu-charge-limit). +ACTION=="add", SUBSYSTEM=="power_supply", KERNEL=="max77779-charger", RUN+="/usr/bin/omamobile-tegu-charge-limit" diff --git a/packages/omamobile-device-tegu/vendor/udev/rules.d/80-omamobile-bt-addr.rules b/packages/omamobile-device-tegu/vendor/udev/rules.d/80-omamobile-bt-addr.rules new file mode 100644 index 000000000..e53bd1bbb --- /dev/null +++ b/packages/omamobile-device-tegu/vendor/udev/rules.d/80-omamobile-bt-addr.rules @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT +# Omarchy Mobile: give the BCM4383 Bluetooth controller its real address +# (omamobile-bt-addr@.service). +ACTION=="add", SUBSYSTEM=="bluetooth", KERNEL=="hci[0-9]*", DRIVERS=="hci_uart_bcm", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omamobile-bt-addr@%k.service" diff --git a/packages/omamobile-device-tegu/version b/packages/omamobile-device-tegu/version new file mode 100644 index 000000000..0ea3a944b --- /dev/null +++ b/packages/omamobile-device-tegu/version @@ -0,0 +1 @@ +0.2.0