Skip to content
Merged
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
5 changes: 3 additions & 2 deletions packages/omamobile-device-cheetah/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ 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)
backup=(etc/pacman.d/omamobile-mirrorlist etc/UPower/UPower.conf.d/50-omamobile-critical.conf)
install=omamobile-device-cheetah.install
optdepends=('omamobile-boot-update: writes kernel package updates to slot B from the boot files this package ships')
makedepends=(gcc python)
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))
10 changes: 10 additions & 0 deletions packages/omamobile-device-cheetah/etc/upower-critical.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Omarchy Mobile (Pixel 7 Pro): at a critical battery, power off cleanly.
# upower's default action is a suspend, and suspended at 2 % the phone runs
# flat asleep (about 20 minutes at 312 mA): a brown-out with the root file
# system mounted. Power off works on kernels with linux-omarchy-mobile#233
# (kernel-2026.11.13 on), and an off phone on a charger starts the dark
# charging boot (omamobile-charger.target) instead of the whole phone.
# device/cheetah/SUSPEND-PLAN.md 6.6, P7.
[UPower]
PercentageAction=3
CriticalPowerAction=PowerOff
6 changes: 6 additions & 0 deletions packages/omamobile-device-cheetah/install
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ 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/}"
done < <(find vendor -type l -print0)
install -Dm644 wireplumber/50-omamobile-cameras.conf "$destination/usr/share/wireplumber/wireplumber.conf.d/50-omamobile-cameras.conf"
install -Dm644 etc/omamobile-mirrorlist "$destination/etc/pacman.d/omamobile-mirrorlist"
install -Dm644 etc/upower-critical.conf "$destination/etc/UPower/UPower.conf.d/50-omamobile-critical.conf"
install -Dm644 LICENSE "$destination/usr/share/licenses/omamobile-device-cheetah/LICENSE"
install -Dm644 LICENSE.Apache-2.0 "$destination/usr/share/licenses/omamobile-device-cheetah/LICENSE.Apache-2.0"
install -Dm644 version "$destination/usr/share/omamobile/device-cheetah/version"
# Suspend is verified on this phone (device/cheetah/SUSPEND-PLAN.md): the
# shell's user setup turns auto-sleep on once where this file exists.
install -Dm644 /dev/null "$destination/usr/share/omamobile/auto-sleep-default"

# The boot files omamobile-boot-update builds slot B's images from
# (docs/RELEASES.md §5.1): the descriptor, the board dtbo, the compiled DTB
Expand Down
Loading