Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions device/cheetah/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,48 @@ the same day on this phone: installed from release 2026.11.08, it took
Omarchy 4.5 and a new boot image from its Updates sheet, the hook wrote and
read back slot B, and the phone restarted into it.

## 2026-11-09: power off restarted the phone (the PMIC's WTSR), and the charger boot

On a second Pixel 7 Pro (a release install with `AUTO_WRITE=yes`), not the
reference phone.

Kernel `7.3.0-rc6-omamobile-g2219cc6cda77` (the packaged release) and a test
build of it with one change, `7.3.0-rc6-omamobile-push1-g0e3da55c9e9f`
("rtc: s5m: disarm the S2MPG12's WTSR and SMPL restarts at power off");
`omamobile-device-cheetah` 0.1.45 test builds (0.1.55 here) of the off-mode charging below.
NV partitions checked against the backup first (all SAME).

- **The PMIC's warm-reset restart is armed** [V]: the RTC regmap
(`firmware:power-management:pmic-1-rtc`, ACPM, one register per read)
reads `0x02` (SMPL) `0x0e`, SMPL_EN 0, and `0x03` (WTSR) `0x0f`, WTSR_EN 1,
on a running phone. Google's `rtc-s2mpg12.c` clears SMPL_EN, WTSR_EN and
COLDRST_EN in its shutdown callback before a power off; `rtc-s5m` didn't.
- **Power off, by the kernel that shuts down** [V]:
| kernel at shutdown | cable | next |
|---|---|---|
| release | in | a normal boot at once (no `androidboot.mode`) |
| test (WTSR disarmed) | in | off, then the bootloader's charger boot (`androidboot.mode = "charger"`) |
| test | out | stayed off for 3 minutes, until Power |
Earlier power offs on the release kernel restarted with the cable out too
(by the owner's memory, not logged). Volume Down + Power forced a reset
into a normal boot: the bootloader enters fastboot only while Volume Down
is still held as it starts (the maintainer's 7 Pro, 2026-11-10), so that
is ordinary, not a fault.
- **The charger boot started the whole phone** [V]: with the cable in, the
bootloader starts slot B with `androidboot.mode = "charger"` (stock runs
only its charging screen then), and we ignored it. With device-cheetah's
`omamobile-charger.target` (0.1.55) that boot runs only charging and SSH:
the panel off (`bl_power` 4), no Plymouth, Bluetooth or camera timer,
nothing failed; Power held for a second restarted into a normal boot, and
the cable out powered it off 5 s later (`charger unplugged: poweroff`).
- **Lesson** [V]: on a phone with `AUTO_WRITE=yes`, installing any package
the boot hook watches (device-cheetah here) rewrote slot B from the
packaged kernel, replacing a pushed test kernel without a word in the
session (`pacman.log`: "Saving slot B (…push1-g0e3da55c9e9f)", then
`boot_b` and `vendor_kernel_boot_b` written). `omamobile-boot-update
rollback` put the test kernel back. Check `omamobile-boot-update status`
before a test that depends on a pushed kernel.

## 2026-11-09: the 2026.11.08 test install, and an update run as root

The release's signed bundle, `omamobile-cheetah-2026.11.08`, installed on the
Expand Down
3 changes: 2 additions & 1 deletion packages/omamobile-device-cheetah/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pkgdesc="Omarchy Mobile support for the Google Pixel 7 Pro (cheetah): boot-slot
arch=(aarch64)
url="https://github.com/derekross/omarchy-mobile"
license=(MIT Apache-2.0)
depends=(bash systemd util-linux omamobile-keyring i2c-tools)
depends=(bash systemd util-linux omamobile-keyring i2c-tools
python) # omamobile-charger-mode
# Keep CPIF and its link driver behind the modem's guarded startup.
provides=(omamobile-modem-policy omamobile-sitd-policy)
backup=(etc/pacman.d/omamobile-mirrorlist)
Expand Down
185 changes: 185 additions & 0 deletions packages/omamobile-device-cheetah/bin/omamobile-charger-mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""omamobile-charger-mode: the bootloader's off-mode charging boot, on Linux.

A Pixel that is off and gets a charger (or is powered off with the cable in)
is started by its bootloader with androidboot.mode = "charger", which on
stock runs only a charging screen. Our boot used to ignore it and start the
whole phone, so a phone powered off on its cable came straight back up.
omamobile-charger-mode-generator makes omamobile-charger.target the default
target of such a boot, and this service runs in it:

- the panel off (bl_power 4: the display-off set; systemd-backlight
doesn't save it, so the next boot's brightness is untouched), checked
every poll, since the panel driver is a module udev may load after this
starts;
- Power held for a second: restart into the phone (a restart isn't a
charger boot, so the next boot is the normal one);
- the cable out for a few seconds: power off, as stock does.

It does nothing outside a charger boot, nor in one that started the phone
anyway (multi-user.target active: before this package, or with
/etc/omamobile/charger-mode-disable), where it would turn a running
phone's panel off and restart it on a press of Power. One battery line a minute goes to
the journal. SSH over USB comes up as usual (omamobile-charger.target).
"""
import glob
import os
import select
import shutil
import struct
import subprocess
import sys
import time

SYS = os.environ.get('OMAMOBILE_SYSFS', '/sys')
BOOTCONFIG = os.environ.get('OMAMOBILE_BOOTCONFIG', '/proc/bootconfig')
SYSTEMCTL = os.environ.get('OMAMOBILE_SYSTEMCTL', 'systemctl')
INPUT = os.environ.get('OMAMOBILE_CHARGER_INPUT', '')
HOLD = float(os.environ.get('OMAMOBILE_CHARGER_HOLD', '1.0'))
UNPLUGGED = float(os.environ.get('OMAMOBILE_CHARGER_UNPLUGGED', '5'))
POLL = float(os.environ.get('OMAMOBILE_CHARGER_POLL', '1'))
REPORT = float(os.environ.get('OMAMOBILE_CHARGER_REPORT', '60'))

CHARGER = 'max77759-charger'
BATTERY = 'max170xx_battery'
EV_KEY, KEY_POWER = 1, 116
EVENT = struct.Struct('llHHi') # struct input_event on a 64-bit kernel


def log(*words):
print('omamobile-charger-mode:', *words, flush=True)


def read(path, default=''):
try:
with open(path) as f:
return f.read().strip()
except OSError:
return default


def charger_boot():
for line in read(BOOTCONFIG).splitlines():
key, _, value = line.partition('=')
if key.strip() == 'androidboot.mode':
return value.strip().strip('"') == 'charger'
return False


def panel_off(failed):
"""bl_power 4 on every backlight that doesn't read it yet; a backlight
that refused is logged once (failed) and tried again each poll."""
for d in sorted(glob.glob(f'{SYS}/class/backlight/*')):
if read(f'{d}/bl_power') == '4':
continue
name = os.path.basename(d)
try:
with open(f'{d}/bl_power', 'w') as f:
f.write('4')
log('panel off:', name)
except OSError as e:
if name not in failed:
log('panel', name, e)
failed.add(name)


def has_key(caps, code):
# capabilities/key: hex words, the highest first, 64 bits each.
words = caps.split()
index = len(words) - 1 - code // 64
return 0 <= index < len(words) and bool(int(words[index], 16) >> (code % 64) & 1)


def power_key():
if INPUT:
return INPUT
for d in sorted(glob.glob(f'{SYS}/class/input/event*')):
if has_key(read(f'{d}/device/capabilities/key'), KEY_POWER):
return f'/dev/input/{os.path.basename(d)}'
return ''


def battery():
b = f'{SYS}/class/power_supply/{BATTERY}'
return f"battery {read(b + '/capacity', '?')}% {read(b + '/status', '?')}"


def finish(command, why):
log(why + ':', command)
# systemctl's status, so a refused reboot or power off fails the unit
# and Restart=on-failure brings the loop back instead of a dark phone.
return subprocess.run([SYSTEMCTL, command], check=False).returncode


def main(argv):
if not charger_boot():
log('not a charger boot (androidboot.mode), nothing to do')
return 0
if subprocess.run([SYSTEMCTL, 'is-active', '--quiet', 'multi-user.target'],
check=False).returncode == 0:
log('the phone is up (multi-user.target), nothing to do')
return 0
if shutil.which('plymouth'):
subprocess.run(['plymouth', 'quit'], check=False)
failed = set()
panel_off(failed)
path = power_key()
fd = None
if path:
try:
fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK)
except OSError as e:
log('no power key:', path, e)
else:
log('no power key found')
log('charging; hold Power to start the phone,', battery())

pending = b''
pressed = None # when Power went down
seen_online = False # the charger must report once before an unplug counts
unplugged = None # since when it reads offline
reported = time.monotonic()
while True:
now = time.monotonic()
wait = POLL if pressed is None else max(0.0, min(POLL, pressed + HOLD - now))
if fd is not None and select.select([fd], [], [], wait)[0]:
try:
data = os.read(fd, EVENT.size * 16)
except BlockingIOError:
data = None
if data:
pending += data
while len(pending) >= EVENT.size:
_, _, kind, code, value = EVENT.unpack_from(pending)
pending = pending[EVENT.size:]
if kind == EV_KEY and code == KEY_POWER:
if value == 1 and pressed is None:
pressed = time.monotonic()
elif value == 0:
pressed = None
elif data == b'':
time.sleep(POLL)
elif fd is None:
time.sleep(wait)

panel_off(failed)
now = time.monotonic()
if pressed is not None and now - pressed >= HOLD:
return finish('reboot', 'Power held')

online = read(f'{SYS}/class/power_supply/{CHARGER}/online')
if online == '1':
seen_online, unplugged = True, None
elif online == '0' and seen_online:
unplugged = unplugged or now
if now - unplugged >= UNPLUGGED:
return finish('poweroff', 'charger unplugged')

if now - reported >= REPORT:
log(battery())
reported = now


if __name__ == '__main__':
sys.exit(main(sys.argv))
2 changes: 2 additions & 0 deletions packages/omamobile-device-cheetah/install
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ for tool in omamobile-bootctl reboot-to; do install -Dm755 "$build/$tool" "$dest
while IFS= read -r -d '' file; do
install -Dm644 "$file" "$destination/usr/lib/${file#vendor/}"
done < <(find vendor -type f -print0)
# systemd runs generators only when they are executable.
chmod 755 "$destination"/usr/lib/systemd/system-generators/*
while IFS= read -r -d '' file; do
install -d "$destination/usr/lib/$(dirname "${file#vendor/}")"
ln -sfn "$(readlink "$file")" "$destination/usr/lib/${file#vendor/}"
Expand Down
107 changes: 106 additions & 1 deletion packages/omamobile-device-cheetah/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ 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 bin/*; do bash -n "$script" || fail "$script parses"; done
for script in bin/*; do
if head -1 "$script" | grep -c python3 >/dev/null; then
python3 -c 'import ast,sys; ast.parse(open(sys.argv[1]).read())' "$script" || fail "$script parses"
else
bash -n "$script" || fail "$script parses"
fi
done
sh -n vendor/systemd/system-generators/omamobile-charger-mode-generator || fail "the charger-mode generator parses"
pass "scripts parse"

grep -q '\.\./\.\.' build && fail "build reaches outside the package directory"
Expand Down Expand Up @@ -376,3 +383,101 @@ grep -A1 -F 'systemctl is-enabled -q omamobile-gnss-nmea.socket' bin/omamobile-s
grep -cF -- '--global enable omamobile-geoclue-agent.service' >/dev/null ||
fail "omamobile-setup-system enables GeoClue's agent with the Location socket"
pass "the setup step turns GeoClue's agent on with the Location socket"
# Off-mode charging (0.1.55). The generator makes omamobile-charger.target
# the default of a charger boot only, from the early folder (before /etc),
# and /etc/omamobile/charger-mode-disable turns it off.
gen=vendor/systemd/system-generators/omamobile-charger-mode-generator
[[ -x $tmp/root/usr/lib/systemd/system-generators/omamobile-charger-mode-generator ]] || fail "the generator is staged executable"
c=$tmp/charger; mkdir -p "$c/etc/omamobile"
printf 'androidboot.slot_suffix = "_b"\nandroidboot.mode = "charger"\n' > "$c/charger.bc"
printf 'androidboot.slot_suffix = "_b"\nandroidboot.mode = "normal"\n' > "$c/normal.bc"
OMAMOBILE_ETC=$c/etc OMAMOBILE_BOOTCONFIG=$c/charger.bc sh "$gen" "$c/n1" "$c/e1" "$c/l1"
[[ $(readlink "$c/e1/default.target") == /usr/lib/systemd/system/omamobile-charger.target ]] || fail "a charger boot defaults to omamobile-charger.target"
[[ ! -e $c/n1 && ! -e $c/l1 ]] || fail "the generator writes only its early folder"
for u in plymouth-start.service bluetooth.service omamobile-bt-addr@.service omamobile-camera.timer omamobile-camera.service; do
[[ $(readlink "$c/e1/$u") == /dev/null ]] || fail "a charger boot masks $u"
done
OMAMOBILE_ETC=$c/etc OMAMOBILE_BOOTCONFIG=$c/normal.bc sh "$gen" "$c/n2" "$c/e2" "$c/l2"
[[ ! -e $c/e2/default.target && ! -e $c/e2/bluetooth.service ]] || fail "a normal boot keeps its default target and masks nothing"
OMAMOBILE_ETC=$c/etc OMAMOBILE_BOOTCONFIG=$c/missing sh "$gen" "$c/n3" "$c/e3" "$c/l3"
[[ ! -e $c/e3/default.target ]] || fail "no bootconfig, no change"
touch "$c/etc/omamobile/charger-mode-disable"
OMAMOBILE_ETC=$c/etc OMAMOBILE_BOOTCONFIG=$c/charger.bc sh "$gen" "$c/n4" "$c/e4" "$c/l4"
[[ ! -e $c/e4/default.target ]] || fail "charger-mode-disable turns it off"
t=vendor/systemd/system/omamobile-charger.target
grep -qx 'AllowIsolate=yes' "$t" && grep -qx 'Requires=basic.target' "$t" || fail "the charger target is a basic.target system"
wants=$(sed -n 's/^Wants=//p' "$t")
for u in omamobile-charger.service omamobile-usb-rescue.service omamobile-usb-mac.service sshd.service ufw.service; do
[[ " $wants " == *" $u "* ]] || fail "the charger target wants $u (SSH over USB as on a normal boot)"
done
for u in multi-user graphical omamobile-modem omamobile-wifi omamobile-aoc sddm; do
[[ $wants == *"$u"* ]] && fail "the charger target starts nothing of the phone ($u)"
done
grep -qx 'Restart=on-failure' vendor/systemd/system/omamobile-charger.service || fail "the charger service restarts if it dies"
pass "a charger boot defaults to omamobile-charger.target (early folder, opt-out file) and masks Plymouth, Bluetooth and the camera timer; the target starts only charging and SSH"

# The service: a fake sysfs, a FIFO for the power key, a systemctl that logs.
s=$c/sys; mkdir -p "$s/class/backlight/panel" "$s/class/power_supply/max77759-charger" "$s/class/power_supply/max170xx_battery" "$c/bin"
echo 0 > "$s/class/backlight/panel/bl_power"; echo 1 > "$s/class/power_supply/max77759-charger/online"
echo 42 > "$s/class/power_supply/max170xx_battery/capacity"; echo Charging > "$s/class/power_supply/max170xx_battery/status"
printf '#!/bin/sh\nif [ "$1" = is-active ]; then [ -e %s ]; exit; fi\necho "$@" >> %s\n[ -e %s ] && exit 1; exit 0\n' "$c/up" "$c/systemctl.log" "$c/refuse" > "$c/bin/systemctl"; chmod +x "$c/bin/systemctl"
# plymouth: a fake, so the test never quits the host's own
printf '#!/bin/sh\necho "$@" >> %s\n' "$c/plymouth.log" > "$c/bin/plymouth"; chmod +x "$c/bin/plymouth"
mkfifo "$c/key"; exec 3<>"$c/key"
key() { python3 -c 'import struct,sys,os; os.write(1, struct.pack("llHHi",0,0,1,116,int(sys.argv[1])))' "$1" >&3; }
charger() {
PATH=$c/bin:/usr/bin:/bin OMAMOBILE_SYSFS=$s OMAMOBILE_BOOTCONFIG=${BC:-$c/charger.bc} OMAMOBILE_SYSTEMCTL=$c/bin/systemctl \
OMAMOBILE_CHARGER_INPUT=$c/key OMAMOBILE_CHARGER_HOLD=0.4 OMAMOBILE_CHARGER_UNPLUGGED=0.4 OMAMOBILE_CHARGER_POLL=0.05 \
timeout 10 python3 -I bin/omamobile-charger-mode
}
waitlog() { local i; for i in $(seq 1 60); do [[ -s $c/systemctl.log ]] && return 0; sleep 0.1; done; return 1; }
# Not a charger boot: nothing at all.
out=$(BC=$c/normal.bc charger) || fail "outside a charger boot it exits 0"
[[ ! -e $c/systemctl.log && $(cat "$s/class/backlight/panel/bl_power") == 0 ]] || fail "outside a charger boot it touches nothing: $out"
# A charger boot that started the phone anyway: nothing at all either.
touch "$c/up"; out=$(charger) || fail "with the phone up it exits 0"
[[ ! -e $c/systemctl.log && $(cat "$s/class/backlight/panel/bl_power") == 0 && $out == *"phone is up"* ]] || fail "with the phone up it touches nothing: $out"
rm "$c/up"
# A short press does nothing; Power held restarts; the panel goes off first.
charger > "$c/run1.log" & pid=$!
sleep 0.5; [[ $(cat "$s/class/backlight/panel/bl_power") == 4 ]] || fail "the panel goes off (bl_power 4)"
key 1; sleep 0.1; key 0; sleep 0.6
[[ ! -e $c/systemctl.log ]] || fail "a short press of Power does nothing"
key 1; waitlog || fail "Power held restarts the phone"; key 0
wait "$pid" || fail "the service exits 0 after the restart"
[[ $(cat "$c/systemctl.log") == reboot ]] || fail "Power held runs systemctl reboot: $(cat "$c/systemctl.log")"
grep -q 'battery 42% Charging' "$c/run1.log" || fail "the battery goes to the journal"
# Unplugged: offline before the charger ever reported doesn't count; offline
# after it did powers the phone off.
rm -f "$c/systemctl.log"; echo 0 > "$s/class/power_supply/max77759-charger/online"
charger > "$c/run2.log" & pid=$!
sleep 1; [[ ! -e $c/systemctl.log ]] || fail "an offline charger that never reported online is not an unplug"
echo 1 > "$s/class/power_supply/max77759-charger/online"; sleep 0.3
echo 0 > "$s/class/power_supply/max77759-charger/online"
waitlog || fail "unplugged, the phone powers off"
wait "$pid" || fail "the service exits 0 after the power off"
[[ $(cat "$c/systemctl.log") == poweroff ]] || fail "unplugged runs systemctl poweroff: $(cat "$c/systemctl.log")"
grep -qx quit "$c/plymouth.log" || fail "the boot splash is quit (through the fake plymouth)"
# A refused reboot fails the service (Restart=on-failure brings it back).
rm -f "$c/systemctl.log"; touch "$c/refuse"; echo 1 > "$s/class/power_supply/max77759-charger/online"
charger > "$c/run3.log" & pid=$!
sleep 0.3; key 1; waitlog || fail "Power held asks for the restart"; key 0
wait "$pid" && fail "a refused restart fails the service"
rm -f "$c/refuse" "$c/systemctl.log"
# The panel driver loads after the service starts: its backlight still goes off.
rm -rf "$s/class/backlight/panel"
charger > "$c/run4.log" & pid=$!
sleep 0.5; mkdir -p "$s/class/backlight/late"; echo 0 > "$s/class/backlight/late/bl_power"
sleep 0.5; [[ $(cat "$s/class/backlight/late/bl_power") == 4 ]] || fail "a backlight that appears late goes off too"
key 1; waitlog || fail "Power held restarts (late backlight run)"; key 0; wait "$pid"
grep -q 'panel off: late' "$c/run4.log" || fail "the late panel's off is logged"
exec 3>&-
# The power key is found from the input devices' key capabilities (gpio-keys
# on the 7 Pro: VOLUMEDOWN, VOLUMEUP and POWER, 114-116).
python3 -I -B - bin/omamobile-charger-mode <<'PY' || fail "KEY_POWER is read from the capability words"
import importlib.machinery, sys
m = importlib.machinery.SourceFileLoader('cm', sys.argv[1]).load_module()
assert m.has_key('1c000000000000 0', 116) and m.has_key('1c000000000000 0', 114)
assert not m.has_key('1c000000000000 0', 113) and not m.has_key('0', 116) and not m.has_key('', 116)
PY
pass "off-mode charging: the panel off, a short press ignored, Power held restarts, unplugged powers off, nothing outside a charger boot or with the phone up"
Loading