From 4910ec769a54197d0b3b9e996469d3d735bebeb5 Mon Sep 17 00:00:00 2001 From: Joe Alicata Date: Mon, 26 Oct 2026 18:22:14 -0400 Subject: [PATCH] flame 0.1.0: hooks for shell 0.2.24 and firstboot 0.1.3 Package the guarded native runtime and marker-gated hooks independently of boot metadata writes. Keep Wi-Fi startup owner-gated and preserve upstream agent selection. Refresh versions over main and require the versions supplying these hooks. Host package fixtures pass; a fresh package deployment remains a hardware gate. Co-Authored-By: Codex --- packages/omamobile-device-flame/LICENSE | 21 ++++ packages/omamobile-device-flame/PKGBUILD | 11 ++ packages/omamobile-device-flame/README.md | 29 +++++ .../bin/omamobile-flame-configure-user | 70 ++++++++++++ packages/omamobile-device-flame/install | 16 +++ packages/omamobile-device-flame/test/all | 54 +++++++++ .../test/storage-guard.py | 25 +++++ .../vendor/bin/flame-partition-links | 20 ++++ .../vendor/bin/flame-storage-guard | 38 +++++++ .../vendor/bin/flame-wifi-start | 103 ++++++++++++++++++ .../NetworkManager/conf.d/10-flame-usb.conf | 4 + .../90-flame-software-rendering.conf | 5 + .../lib/modprobe.d/omamobile-flame.conf | 7 ++ .../journald.conf.d/90-flame-standalone.conf | 5 + .../lib/systemd/network/10-flame-usb.network | 15 +++ .../system.conf.d/10-flame-watchdog.conf | 5 + .../system/flame-storage-guard.service | 15 +++ .../lib/systemd/system/flame-wifi.service | 19 ++++ .../flame-software-rendering.conf | 4 + .../lib/udev/rules.d/10-flame-storage.rules | 3 + packages/omamobile-device-flame/version | 1 + .../bin/omamobile-firstboot | 6 + packages/omamobile-firstboot/test/all | 12 ++ packages/omamobile-firstboot/version | 2 +- .../omamobile-shell/bin/omamobile-setup-user | 10 +- packages/omamobile-shell/version | 2 +- tests/rootfs-smoke | 12 ++ 27 files changed, 510 insertions(+), 4 deletions(-) create mode 100644 packages/omamobile-device-flame/LICENSE create mode 100644 packages/omamobile-device-flame/PKGBUILD create mode 100644 packages/omamobile-device-flame/README.md create mode 100755 packages/omamobile-device-flame/bin/omamobile-flame-configure-user create mode 100755 packages/omamobile-device-flame/install create mode 100755 packages/omamobile-device-flame/test/all create mode 100644 packages/omamobile-device-flame/test/storage-guard.py create mode 100755 packages/omamobile-device-flame/vendor/bin/flame-partition-links create mode 100755 packages/omamobile-device-flame/vendor/bin/flame-storage-guard create mode 100755 packages/omamobile-device-flame/vendor/bin/flame-wifi-start create mode 100644 packages/omamobile-device-flame/vendor/lib/NetworkManager/conf.d/10-flame-usb.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/environment.d/90-flame-software-rendering.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/modprobe.d/omamobile-flame.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/journald.conf.d/90-flame-standalone.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/network/10-flame-usb.network create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/system.conf.d/10-flame-watchdog.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/system/flame-storage-guard.service create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/system/flame-wifi.service create mode 100644 packages/omamobile-device-flame/vendor/lib/systemd/system/sddm.service.d/flame-software-rendering.conf create mode 100644 packages/omamobile-device-flame/vendor/lib/udev/rules.d/10-flame-storage.rules create mode 100644 packages/omamobile-device-flame/version diff --git a/packages/omamobile-device-flame/LICENSE b/packages/omamobile-device-flame/LICENSE new file mode 100644 index 000000000..f407f722f --- /dev/null +++ b/packages/omamobile-device-flame/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Derek Ross and Omarchy Mobile contributors + +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-flame/PKGBUILD b/packages/omamobile-device-flame/PKGBUILD new file mode 100644 index 000000000..2f843f3b7 --- /dev/null +++ b/packages/omamobile-device-flame/PKGBUILD @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: MIT +pkgname=omamobile-device-flame +pkgver=$(cat "${startdir:-.}/version") +pkgrel=1 +pkgdesc="Experimental guarded native-root support for Google Pixel 4 (flame)" +arch=(aarch64) +url="https://github.com/derekross/omarchy-mobile" +license=(MIT) +depends=(bash python systemd util-linux e2fsprogs 'omamobile-shell>=0.2.24' 'omamobile-firstboot>=0.1.3' foot xdg-terminal-exec udiskie) +check() { "$startdir/test/all"; } +package() { "$startdir/install" "$pkgdir"; } diff --git a/packages/omamobile-device-flame/README.md b/packages/omamobile-device-flame/README.md new file mode 100644 index 000000000..3c007e883 --- /dev/null +++ b/packages/omamobile-device-flame/README.md @@ -0,0 +1,29 @@ + +# omamobile-device-flame + +Experimental Pixel 4 native-root policy. Install only into the opt-in flame +root described in [the native runbook (review snapshot)](https://github.com/wirelessjoe/omarchy-mobile/blob/c6ce0c41f58a387f18e4f06a6de1a283698c9500/device/flame/native/README.md). +The runtime must be available before using the separate native boot/root +plumbing. This split itself installs no boot image or GPT writer. +The package enables the storage guard, hides protected partitions from desktop +disk tools, keeps the journal off USB, and selects the tested software-rendering +fallback for SDDM and user services. PID 1 feeds the 30-second watchdog; USB +networkd/DHCP stays separate from NetworkManager, and first-boot 0.1.3 adds +USB-only recovery/DHCP firewall rules. It does not mark a boot slot successful. + +Foot, xdg-terminal-exec and udiskie are explicit dependencies so hand-built +roots cannot omit the terminal or disk helpers used by upstream Omarchy. +The existing AI Agent shortcut and chooser remain upstream's; no separate +Codex desktop app or agent selection is installed by this package. + +`omamobile-flame-configure-user` seeds the tested 2.5 display scale. Its optional +`--chrome` switch merges the tested Wayland/software-rendering/0.6 scale flags +for an already installed Chrome browser. Other flags are preserved and prior +files are backed up under the owner's private state directory. It never +accepts a browser license or starts the browser. Chrome is not a dependency. +Normal mobile user setup calls `--chrome-if-installed` once for flame roots. + +Wi-Fi's unit is shipped **disabled**. Before enabling it, supply the owner's +matching firmware and current verified private manifests/NV shadows and pass +the native Wi-Fi gates. No firmware, calibration, host keys or credentials +are in this package. Keep `ftm5_fw.ftb` absent before the first touch test. diff --git a/packages/omamobile-device-flame/bin/omamobile-flame-configure-user b/packages/omamobile-device-flame/bin/omamobile-flame-configure-user new file mode 100755 index 000000000..d20d36aa1 --- /dev/null +++ b/packages/omamobile-device-flame/bin/omamobile-flame-configure-user @@ -0,0 +1,70 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: MIT +"""Seed the measured flame scale; optionally fix an owner-installed Chrome.""" +import argparse +from pathlib import Path +import os +import re +import shutil +import tempfile + + +def replace(home, path, content): + if path.exists() and path.read_text() == content: + return + backup = home / '.local/state/omamobile/flame-config-backups' + if path.exists(): + backup.mkdir(parents=True, exist_ok=True, mode=0o700) + saved = backup / path.name + if not saved.exists(): + shutil.copy2(path, saved) + saved.chmod(0o600) + path.parent.mkdir(parents=True, exist_ok=True) + fd, name = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent) + try: + with os.fdopen(fd, 'w') as stream: + stream.write(content) + os.replace(name, path) + finally: + Path(name).unlink(missing_ok=True) + + +def configure(home, chrome=False): + monitors = home / '.config/hypr/monitors.lua' + if not monitors.exists(): + raise RuntimeError('Run normal Omarchy Mobile user setup first') + original = monitors.read_text() + content, count = re.subn(r'^local omarchy_monitor_scale = .*$', + 'local omarchy_monitor_scale = 2.5', original, + flags=re.MULTILINE) + if count != 1: + raise RuntimeError('Expected one Omarchy monitor-scale declaration') + replace(home, monitors, content) + if chrome: + flags = home / '.config/chrome-flags.conf' + lines = flags.read_text().splitlines() if flags.exists() else [] + keys = ('--disable-gpu', '--ozone-platform', '--force-device-scale-factor') + kept = [line for line in lines if not any( + line.strip() == key or line.strip().startswith(key + '=') for key in keys)] + kept += ['--disable-gpu', '--ozone-platform=wayland', + '--force-device-scale-factor=0.6'] + replace(home, flags, '\n'.join(kept) + '\n') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--chrome', action='store_true', help='merge the tested Chrome flags') + parser.add_argument('--chrome-if-installed', action='store_true') + args = parser.parse_args() + if os.getuid() == 0: + parser.error('run as the desktop owner, not root') + if not Path('/usr/share/omamobile/flame-root').is_file(): + parser.error('not a flame native root') + chrome = args.chrome or (args.chrome_if_installed and bool( + shutil.which('google-chrome-stable') or shutil.which('google-chrome'))) + configure(Path.home(), chrome) + print('Flame display defaults configured' + ('; Chrome flags merged' if chrome else '')) + + +if __name__ == '__main__': + main() diff --git a/packages/omamobile-device-flame/install b/packages/omamobile-device-flame/install new file mode 100755 index 000000000..2e4ccff3e --- /dev/null +++ b/packages/omamobile-device-flame/install @@ -0,0 +1,16 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")" +destination=${1:?Usage: install ABSOLUTE_STAGING_DIRECTORY} +[[ $destination == /* && $destination != / ]] || exit 1 +for file in bin/*; do install -Dm755 "$file" "$destination/usr/bin/${file##*/}"; done +for file in vendor/bin/*; do install -Dm755 "$file" "$destination/usr/bin/${file##*/}"; done +while IFS= read -r -d '' file; do + install -Dm644 "$file" "$destination/usr/lib/${file#vendor/lib/}" +done < <(find vendor/lib -type f -print0) +install -d "$destination/usr/lib/systemd/system/sysinit.target.wants" +ln -sfn ../flame-storage-guard.service "$destination/usr/lib/systemd/system/sysinit.target.wants/flame-storage-guard.service" +install -Dm644 version "$destination/usr/share/omamobile/device-flame/version" +install -Dm644 LICENSE "$destination/usr/share/licenses/omamobile-device-flame/LICENSE" +install -Dm644 /dev/null "$destination/usr/share/omamobile/flame-root" diff --git a/packages/omamobile-device-flame/test/all b/packages/omamobile-device-flame/test/all new file mode 100755 index 000000000..d5541ebb7 --- /dev/null +++ b/packages/omamobile-device-flame/test/all @@ -0,0 +1,54 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +set -euo pipefail +export PYTHONDONTWRITEBYTECODE=1 +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +bash -n install +python3 -B test/storage-guard.py +sh -n vendor/bin/flame-storage-guard +bash -n vendor/bin/flame-wifi-start vendor/bin/flame-partition-links +./install "$scratch/root" +test -f "$scratch/root/usr/share/omamobile/flame-root" +test -L "$scratch/root/usr/lib/systemd/system/sysinit.target.wants/flame-storage-guard.service" +test ! -e "$scratch/root/usr/lib/systemd/system/multi-user.target.wants/flame-wifi.service" +test -f "$scratch/root/usr/lib/systemd/journald.conf.d/90-flame-standalone.conf" +grep -q '^ForwardToConsole=no$' "$scratch/root/usr/lib/systemd/journald.conf.d/90-flame-standalone.conf" +grep -qx 'RuntimeWatchdogSec=30s' "$scratch/root/usr/lib/systemd/system.conf.d/10-flame-watchdog.conf" +grep -qx 'RebootWatchdogSec=1min' "$scratch/root/usr/lib/systemd/system.conf.d/10-flame-watchdog.conf" +grep -qx 'Name=usb0' "$scratch/root/usr/lib/systemd/network/10-flame-usb.network" +grep -qx 'EmitRouter=no' "$scratch/root/usr/lib/systemd/network/10-flame-usb.network" +if grep -q '^Gateway=' "$scratch/root/usr/lib/systemd/network/10-flame-usb.network"; then + echo 'not ok - USB must not become the default gateway' >&2 + exit 1 +fi +python3 - <<'PY' +from pathlib import Path +import importlib.machinery,importlib.util,tempfile +path=Path('bin/omamobile-flame-configure-user') +loader=importlib.machinery.SourceFileLoader('flame_user',str(path)) +spec=importlib.util.spec_from_loader(loader.name,loader) +module=importlib.util.module_from_spec(spec);loader.exec_module(module) +with tempfile.TemporaryDirectory() as folder: + home=Path(folder);monitor=home/'.config/hypr/monitors.lua' + monitor.parent.mkdir(parents=True);monitor.write_text('local omarchy_monitor_scale = 3\n-- owner setting\n') + chrome=home/'.config/chrome-flags.conf' + chrome.write_text('--force-device-scale-factor=0.83\n--ozone-platform=x11\n--lang=fr\n# owner comment\n') + module.configure(home,chrome=True) + assert monitor.read_text()=='local omarchy_monitor_scale = 2.5\n-- owner setting\n' + assert chrome.read_text()=='--lang=fr\n# owner comment\n--disable-gpu\n--ozone-platform=wayland\n--force-device-scale-factor=0.6\n' + backup=home/'.local/state/omamobile/flame-config-backups/chrome-flags.conf' + assert '--force-device-scale-factor=0.83' in backup.read_text() + before=chrome.read_bytes();saved=backup.read_bytes() + module.configure(home,chrome=True) + assert chrome.read_bytes()==before and backup.read_bytes()==saved + assert chrome.stat().st_mode & 0o777==0o600 + # A manually maintained monitor layout must not be overwritten by guesswork. + monitor.write_text('-- custom layout\n') + try:module.configure(home,chrome=True) + except RuntimeError:pass + else:raise AssertionError('unknown monitor configuration accepted') + assert monitor.read_text()=='-- custom layout\n' +print('ok - flame package stages guard-only activation; user settings merge, backup and repeat safely') +PY diff --git a/packages/omamobile-device-flame/test/storage-guard.py b/packages/omamobile-device-flame/test/storage-guard.py new file mode 100644 index 000000000..1a49b4e2a --- /dev/null +++ b/packages/omamobile-device-flame/test/storage-guard.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +from pathlib import Path +import tempfile,subprocess,os +source=(Path(__file__).resolve().parents[1]/'vendor/bin/flame-storage-guard').read_text() +body='UFS_RW="boot_b userdata"'+source.split('UFS_RW="boot_b userdata"',1)[1].split('\nwhile :; do',1)[0] +with tempfile.TemporaryDirectory() as d: + p=Path(d); sys=p/'sys';dev=p/'dev';bin=p/'bin' + for x in (sys,dev,bin):x.mkdir() + body=body.replace('/sys/class/block/',str(sys)+'/').replace('/dev/',str(dev)+'/').replace('[ -b ','[ -f ') + (p/'guard').write_text('say() { echo "$*" >&2; }\n'+body+'\nstorage_guard\n') + (bin/'blockdev').write_text('#!/bin/sh\n[ "$1" = --setro ] || exit 92\n[ "${MODE:-}" != fail ] || exit 1\n[ "${MODE:-}" != lie ] || exit 0\necho 1 > "$SYS/${2##*/}/ro"\n') + (bin/'blockdev').chmod(0o755) + def add(n,part='',ro='0'): + (sys/n).mkdir();(sys/n/'ro').write_text(ro+'\n');(sys/n/'uevent').write_text('PARTNAME='+part+'\n' if part else '');(dev/n).touch() + def run(mode=''): + return subprocess.run(['sh',str(p/'guard')],env=dict(os.environ,PATH=str(bin)+':'+os.environ['PATH'],SYS=str(sys),MODE=mode),capture_output=True) + for n,part in [('sda',''),('sda2','persist'),('sda6','boot_a'),('sda7','boot_b'),('sda15','userdata'),('sdb',''),('sde33','devinfo'),('sdf2','modemst1'),('sdf3','userdata')]:add(n,part) + assert run().returncode==0 + assert not (dev/'sda').exists() + for n in ['sda2','sda6','sdb','sde33','sdf2','sdf3']:assert (sys/n/'ro').read_text().strip()=='1',n + for n in ['sda7','sda15']:assert (sys/n/'ro').read_text().strip()=='0',n + (sys/'sda7'/'ro').write_text('1\n');(dev/'sda').touch();assert run().returncode==0;assert not (dev/'sda').exists();assert (sys/'sda7'/'ro').read_text().strip()=='1' + add('sdg');assert run('fail').returncode!=0;assert run('lie').returncode!=0 + print('Root guard: exact sda allowlist, all calibration protected, other-LUN userdata rejected, whole node removed, existing RO preserved, failure closed') diff --git a/packages/omamobile-device-flame/vendor/bin/flame-partition-links b/packages/omamobile-device-flame/vendor/bin/flame-partition-links new file mode 100755 index 000000000..d883cc972 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/bin/flame-partition-links @@ -0,0 +1,20 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# UFS LUN discovery order can change across boots. Never persist /dev/sdX paths. +set -euo pipefail +test -f /usr/share/omamobile/flame-root +test ! -e /dev/sda +directory=/run/omamobile/flame-partitions +install -d -m 700 "$directory" +for part in persist modemst1 modemst2 fsg fsc modem_a modem_b devinfo; do + target='' + for candidate in /sys/class/block/sd*/uevent; do + if grep -Fx "PARTNAME=$part" "$candidate" >/dev/null; then + [[ -z $target ]] || { echo 'Ambiguous protected partition' >&2; exit 1; } + target=/dev/$(basename "$(dirname "$candidate")") + fi + done + [[ -n $target && -b $target ]] || { echo 'Protected partition absent' >&2; exit 1; } + [[ $(blockdev --getro "$target") == 1 ]] || { echo 'Protected partition is writable' >&2; exit 1; } + ln -sfn "$target" "$directory/$part" +done diff --git a/packages/omamobile-device-flame/vendor/bin/flame-storage-guard b/packages/omamobile-device-flame/vendor/bin/flame-storage-guard new file mode 100755 index 000000000..effd2549d --- /dev/null +++ b/packages/omamobile-device-flame/vendor/bin/flame-storage-guard @@ -0,0 +1,38 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Development storage guard; never clear an existing read-only flag. +export PATH=/usr/bin:/bin +say() { echo "omamobile-flame-guard: $*" >/dev/kmsg; } +UFS_RW="boot_b userdata" +part_name() { sed -n 's/^PARTNAME=//p' "$1/uevent"; } +storage_guard() { + for s in /sys/class/block/sd*; do + [ -r "$s/ro" ] || continue + name=${s##*/} + if [ "$name" = sda ]; then + rm -f /dev/sda + continue + fi + [ -b "/dev/$name" ] || continue + part=$(part_name "$s") + case "$name" in + sda[0-9]*) + # A previously read-only device stays so; never use --setrw. + case " $UFS_RW " in *" $part "*) continue ;; esac ;; + esac + [ "$(cat "$s/ro")" = 1 ] && continue + if ! blockdev --setro "/dev/$name" || [ "$(cat "$s/ro")" != 1 ]; then + say "FAILED to protect /dev/$name" + return 1 + fi + done + [ ! -e /dev/sda ] +} +while :; do + if ! storage_guard; then + say 'Storage protection failed; forcing recovery' + echo c >/proc/sysrq-trigger + exit 1 + fi + sleep 0.2 +done diff --git a/packages/omamobile-device-flame/vendor/bin/flame-wifi-start b/packages/omamobile-device-flame/vendor/bin/flame-wifi-start new file mode 100755 index 000000000..1dff1d6cc --- /dev/null +++ b/packages/omamobile-device-flame/vendor/bin/flame-wifi-start @@ -0,0 +1,103 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Experimental flame radio startup. Owner firmware and NV stay off-repository. +set -euo pipefail + +fail() { echo "flame Wi-Fi: $*" >&2; exit 1; } +test -f /usr/share/omamobile/flame-root || fail 'wrong root' +[[ $(tr -d '\0' /dev/null || fail 'wrong device' +systemctl is-active --quiet flame-storage-guard.service +test ! -e /dev/sda || fail 'whole-disk node exists' +blockdev --setro /dev/sda7 +for node in /sys/class/block/sd*; do + case ${node##*/} in sda|sda15) continue;; esac + [[ $(cat "$node/ro") == 1 ]] || fail 'protected storage is writable' +done + +/usr/bin/flame-partition-links +sha256sum --check --status /etc/omamobile/flame-calibration.sha256 +sha256sum --check --status /etc/omamobile/flame-firmware.sha256 +# Firmware API 2 wins over the factory API 1 board file, including compressed +# copies and files restored by a linux-firmware upgrade. Fail before MPSS starts. +[[ -z $(cat /sys/module/firmware_class/parameters/path) ]] || fail 'custom firmware search path' +for root in /usr/lib/firmware/updates/"$(uname -r)" /usr/lib/firmware/updates \ + /usr/lib/firmware/"$(uname -r)" /usr/lib/firmware; do + for file in "$root"/ath10k/WCN3990/hw1.0/board-2.bin{,.xz,.zst}; do + [[ ! -e $file ]] || fail 'generic API 2 board data overrides factory board.bin' + done +done + +# Verify each shadow against the currently protected partition, not merely an +# older shadow manifest. rmtfs receives RAM files and never the real NV nodes. +for pair in modemst1:modem_fs1 modemst2:modem_fs2 fsg:modem_fsg fsc:modem_fsc; do + part=${pair%%:*}; file=${pair#*:}; source_node='' + for candidate in /sys/class/block/sd*/uevent; do + if grep -Fx "PARTNAME=$part" "$candidate" >/dev/null; then + [[ -z $source_node ]] || fail 'ambiguous NV partition' + source_node=/dev/$(basename "$(dirname "$candidate")") + fi + done + [[ -n $source_node ]] || fail 'NV partition is absent' + [[ $(sha256sum "$source_node" | cut -d' ' -f1) == \ + $(sha256sum "/var/lib/omamobile/flame/nv/$file" | cut -d' ' -f1) ]] || fail 'stale NV shadow' +done + +wifi_ready() { + # systemd may rename wlan0 (wld0 on the tested native root). + for iface in /sys/class/net/*; do + [[ ! -d $iface/wireless ]] || return 0 + done + return 1 +} +wifi_ready && exit 0 +state=/var/lib/omamobile/flame/wifi-starting +[[ ! -e $state ]] || fail 'previous startup did not complete; inspect logs before clearing marker' +install -d -m 700 /var/lib/omamobile/flame +touch "$state" +sync -f "$state" + +for program in rmtfs tqftpserv; do test -x "/usr/local/sbin/$program"; done +install -d -m 700 /run/rmtfs +for file in modem_fs1 modem_fs2 modem_fsg modem_fsc; do + install -m 600 "/var/lib/omamobile/flame/nv/$file" "/run/rmtfs/$file" +done +modprobe qrtr_smd +modprobe qcom_q6v5_pas +test -c /dev/qcom_rmtfs_mem1 +rm -f /dev/mem +# Refuse existing filesystem servers: their options and backing data are unknown. +! pgrep -x rmtfs >/dev/null || fail 'rmtfs already running' +! pgrep -x tqftpserv >/dev/null || fail 'tqftpserv already running' +install -d -m 700 /var/log/omamobile +/usr/local/sbin/tqftpserv >>/var/log/omamobile/flame-tqftp.log 2>&1 & +/usr/local/sbin/rmtfs -r -v -o /run/rmtfs >>/var/log/omamobile/flame-rmtfs.log 2>&1 & +sleep 1 +pgrep -x tqftpserv >/dev/null +pgrep -x rmtfs >/dev/null +mpss='' +for candidate in /sys/class/remoteproc/remoteproc*; do + [[ -f $candidate/name ]] || continue + [[ $(cat "$candidate/name") == modem ]] || continue + [[ -z $mpss ]] || fail 'ambiguous modem processor' + mpss=$candidate +done +[[ -n $mpss ]] || fail 'MPSS is absent' +# Repeated resets after a WLAN firmware fault previously stalled UFS. +echo disabled >"$mpss/recovery" +[[ $(cat "$mpss/state") == offline ]] || fail 'MPSS is already started' +echo start >"$mpss/state" +[[ $(cat "$mpss/state") == running ]] +modprobe ath10k_snoc +modprobe qcom_pd_mapper +for _ in {1..45}; do + if wifi_ready; then + rm "$state" + sync -f /var/lib/omamobile/flame + echo 'WLAN ready; modem filesystem uses verified read-only RAM shadows' + exit 0 + fi + sleep 1 +done +fail 'no WLAN interface after firmware startup' diff --git a/packages/omamobile-device-flame/vendor/lib/NetworkManager/conf.d/10-flame-usb.conf b/packages/omamobile-device-flame/vendor/lib/NetworkManager/conf.d/10-flame-usb.conf new file mode 100644 index 000000000..dfdd6d916 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/NetworkManager/conf.d/10-flame-usb.conf @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT +# systemd-networkd owns the USB gadget; NetworkManager owns Wi-Fi. +[keyfile] +unmanaged-devices=interface-name:usb0 diff --git a/packages/omamobile-device-flame/vendor/lib/environment.d/90-flame-software-rendering.conf b/packages/omamobile-device-flame/vendor/lib/environment.d/90-flame-software-rendering.conf new file mode 100644 index 000000000..0e69be034 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/environment.d/90-flame-software-rendering.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# Hardware acceleration faulted on the tested A640 setup. Keep the tested fallback. +LIBGL_ALWAYS_SOFTWARE=1 +GALLIUM_DRIVER=llvmpipe +__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json diff --git a/packages/omamobile-device-flame/vendor/lib/modprobe.d/omamobile-flame.conf b/packages/omamobile-device-flame/vendor/lib/modprobe.d/omamobile-flame.conf new file mode 100644 index 000000000..e292865d0 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/modprobe.d/omamobile-flame.conf @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# Wi-Fi is loaded only by the separately gated firmware/NV-shadow helper. +blacklist ath10k_snoc +# No Bluetooth firmware download/pairing pass. No UART pin experiment is shipped. +blacklist hci_uart +# The uninitialized RTC reset the clock during initial provisioning. +blacklist rtc_pm8xxx diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/journald.conf.d/90-flame-standalone.conf b/packages/omamobile-device-flame/vendor/lib/systemd/journald.conf.d/90-flame-standalone.conf new file mode 100644 index 000000000..29b42513b --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/journald.conf.d/90-flame-standalone.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# Forwarding journal messages to ttyGS0 can feed USB wakeup errors back into +# the same suspended connection after unplugging. Keep logs in the journal. +[Journal] +ForwardToConsole=no diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/network/10-flame-usb.network b/packages/omamobile-device-flame/vendor/lib/systemd/network/10-flame-usb.network new file mode 100644 index 000000000..8f782dfb4 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/network/10-flame-usb.network @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +[Match] +Name=usb0 + +[Network] +Address=172.16.42.1/24 +DHCPServer=yes +LinkLocalAddressing=ipv6 +ConfigureWithoutCarrier=yes + +[DHCPServer] +PoolOffset=2 +PoolSize=1 +EmitRouter=no +EmitDNS=no diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/system.conf.d/10-flame-watchdog.conf b/packages/omamobile-device-flame/vendor/lib/systemd/system.conf.d/10-flame-watchdog.conf new file mode 100644 index 000000000..8ffdecac9 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/system.conf.d/10-flame-watchdog.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +# The initramfs takes over the Qualcomm watchdog before the Arch handoff. +[Manager] +RuntimeWatchdogSec=30s +RebootWatchdogSec=1min diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-storage-guard.service b/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-storage-guard.service new file mode 100644 index 000000000..b4a52a3ab --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-storage-guard.service @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=Pixel 4 protected storage guard +DefaultDependencies=no +Before=systemd-udevd.service sysinit.target shutdown.target +Conflicts=shutdown.target + +[Service] +Type=exec +ExecStart=/usr/bin/flame-storage-guard +Restart=always +RestartSec=0 + +[Install] +WantedBy=sysinit.target diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-wifi.service b/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-wifi.service new file mode 100644 index 000000000..b1a79b479 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/system/flame-wifi.service @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=Experimental Pixel 4 Wi-Fi with protected NV shadows +Requires=flame-storage-guard.service +After=flame-storage-guard.service systemd-udev-settle.service +Before=NetworkManager.service +ConditionPathExists=/etc/omamobile/flame-firmware.sha256 + +[Service] +Type=oneshot +ExecStart=/usr/bin/flame-wifi-start +RemainAfterExit=yes +TimeoutStartSec=75 +# Keep the filesystem servers for the lifetime of this boot. Do not restart a +# failed processor or stop/unload drivers during bring-up. +KillMode=process + +[Install] +WantedBy=multi-user.target diff --git a/packages/omamobile-device-flame/vendor/lib/systemd/system/sddm.service.d/flame-software-rendering.conf b/packages/omamobile-device-flame/vendor/lib/systemd/system/sddm.service.d/flame-software-rendering.conf new file mode 100644 index 000000000..aba362ba3 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/systemd/system/sddm.service.d/flame-software-rendering.conf @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT +[Service] +Environment=LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe +Environment=__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json diff --git a/packages/omamobile-device-flame/vendor/lib/udev/rules.d/10-flame-storage.rules b/packages/omamobile-device-flame/vendor/lib/udev/rules.d/10-flame-storage.rules new file mode 100644 index 000000000..637f88f90 --- /dev/null +++ b/packages/omamobile-device-flame/vendor/lib/udev/rules.d/10-flame-storage.rules @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: MIT +SUBSYSTEM=="block", KERNEL=="sda", MODE="0000", ENV{UDISKS_IGNORE}="1", RUN+="/usr/bin/rm -f /dev/%k" +SUBSYSTEM=="block", KERNEL=="sd*[0-9]*", ENV{ID_PART_ENTRY_NAME}!="userdata", ENV{UDISKS_IGNORE}="1" diff --git a/packages/omamobile-device-flame/version b/packages/omamobile-device-flame/version new file mode 100644 index 000000000..6e8bf73aa --- /dev/null +++ b/packages/omamobile-device-flame/version @@ -0,0 +1 @@ +0.1.0 diff --git a/packages/omamobile-firstboot/bin/omamobile-firstboot b/packages/omamobile-firstboot/bin/omamobile-firstboot index f951476b1..8a3d7404c 100755 --- a/packages/omamobile-firstboot/bin/omamobile-firstboot +++ b/packages/omamobile-firstboot/bin/omamobile-firstboot @@ -336,6 +336,12 @@ s_services() { ufw allow 53317/udp ufw allow 53317/tcp ufw allow in on usb0 to any port 22 proto tcp + if [[ -f $ROOT/usr/share/omamobile/flame-root ]]; then + # Native flame keeps an independent RAM rescue listener and a USB DHCP + # server. These rules apply only to the physical gadget, never Wi-Fi. + ufw allow in on usb0 to any port 2222 proto tcp + ufw allow in on usb0 to any port 67 proto udp + fi # Active from the next boot, as Omarchy's installer leaves it sed -i 's/^ENABLED=.*/ENABLED=yes/' "$ROOT/etc/ufw/ufw.conf" } diff --git a/packages/omamobile-firstboot/test/all b/packages/omamobile-firstboot/test/all index 429925390..d52fbe5e0 100755 --- a/packages/omamobile-firstboot/test/all +++ b/packages/omamobile-firstboot/test/all @@ -186,6 +186,18 @@ grep -q '^usermod -aG wheel,audio,video,input' "$CALLS" || fail "a second run up [[ $(grep -cxF "$KEY" "$R/home/alice/.ssh/authorized_keys") == 1 ]] || fail "a second run doesn't duplicate the key" pass "running again is safe" +# Only the explicit native-root marker opens RAM rescue and DHCP, on USB. +if grep -Eq '^ufw allow .*port (2222|67) ' "$CALLS"; then fail "normal roots get no flame recovery/DHCP rules"; fi +mkdir -p "$R/usr/share/omamobile" +touch "$R/usr/share/omamobile/flame-root" +: > "$CALLS" +good > "$R/etc/omamobile/firstboot.conf" +run || { cat "$t/run.out"; fail "flame services run"; } +grep -qx 'ufw allow in on usb0 to any port 2222 proto tcp' "$CALLS" || fail "flame recovery is USB-only" +grep -qx 'ufw allow in on usb0 to any port 67 proto udp' "$CALLS" || fail "flame DHCP is USB-only" +rm "$R/usr/share/omamobile/flame-root" +pass "native flame recovery and DHCP rules are marker-gated and USB-only" + # An essential step failing keeps the conf (minus the Wi-Fi secret) for the next boot rm -f "$R/var/lib/omamobile/firstboot/user" sed -i '/^alice:/d' "$R/etc/passwd" diff --git a/packages/omamobile-firstboot/version b/packages/omamobile-firstboot/version index d917d3e26..b1e80bb24 100644 --- a/packages/omamobile-firstboot/version +++ b/packages/omamobile-firstboot/version @@ -1 +1 @@ -0.1.2 +0.1.3 diff --git a/packages/omamobile-shell/bin/omamobile-setup-user b/packages/omamobile-shell/bin/omamobile-setup-user index 2e671b278..1ce0f6bca 100755 --- a/packages/omamobile-shell/bin/omamobile-setup-user +++ b/packages/omamobile-shell/bin/omamobile-setup-user @@ -100,9 +100,15 @@ if omarchy-done ensure omamobile-credential-type; then fi fi -# Phone scale: 1440x3120 at 3 is 480x1040 logical, seeded once +# Phone scale, seeded once: 3 normally; flame uses the measured 2.5 scale. if omarchy-done ensure omamobile-monitor-scale; then - sed -i 's/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = 3/' ~/.config/hypr/monitors.lua + scale=3 + [[ ! -f /usr/share/omamobile/flame-root ]] || scale=2.5 + sed -i "s/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = $scale/" ~/.config/hypr/monitors.lua +fi + +if [[ -f /usr/share/omamobile/flame-root ]] && omarchy-done ensure omamobile-flame-user-defaults; then + omamobile-flame-configure-user --chrome-if-installed fi # Touch phone: no pointer on screen (it still hides on touch if a USB mouse is diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 521eb3d6e..ac1661553 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.23 +0.2.24 diff --git a/tests/rootfs-smoke b/tests/rootfs-smoke index 09ff148c9..277800fc1 100755 --- a/tests/rootfs-smoke +++ b/tests/rootfs-smoke @@ -67,6 +67,18 @@ release=$(sed -n 's/^kernel modules: \([^ ]*\) .*/\1/p' <<<"$manifest") grep -q '^omamobile-device-[a-z0-9]* .* omamobile$' <<<"$manifest" || fail "a device package from [omamobile] in the MANIFEST" pass "MANIFEST, device package, modules for $release" +if grep -q '^device: flame (omamobile-device-flame)$' <<<"$manifest"; then + for path in /usr/share/omamobile/flame-root /usr/bin/flame-storage-guard \ + /usr/lib/systemd/system/sysinit.target.wants/flame-storage-guard.service \ + /usr/lib/udev/rules.d/10-flame-storage.rules /usr/bin/xdg-terminal-exec /usr/bin/foot /usr/bin/udiskie; do + exists "$path" || fail "flame runtime dependency: $path" + done + grep -q '^ForwardToConsole=no$' <<<"$(cat_ /usr/lib/systemd/journald.conf.d/90-flame-standalone.conf)" || fail "flame journal must stay off USB" + exists /usr/lib/firmware/ftm5_fw.ftb && fail "flame touch firmware-update gate" + exists /usr/lib/systemd/system/multi-user.target.wants/flame-wifi.service && fail "Wi-Fi must remain owner-gated" + pass "flame guard and desktop dependencies; Wi-Fi/touch firmware gates" +fi + # Images from before omamobile-omarchy patched Omarchy in build-inside if exists /usr/bin/omamobile-omarchy-patches; then exists /usr/share/libalpm/hooks/95-omamobile-omarchy-patches.hook || fail "the Omarchy re-patch hook is installed"