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
5 changes: 5 additions & 0 deletions device/cheetah/MODEM-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,11 @@ What the packages now do, opt-in and nothing enabled by them:
with the modem on has never run on this phone, 6.3). The start script
refuses to load a driver until the lock shows in `systemd-inhibit
--list`. With the stack at boot the phone never sleeps.
Since 2026-11-10 (#424) a start that refuses with none of the modem's
drivers loaded (a stale `modem-up` marker, the bring-up latch, a link
driver that didn't load) kills the lock, so the phone sleeps that boot
as it would without a modem; once a driver has loaded, the lock stays
until the reboot.
- **`omamobile-modem.service` is `Type=notify`**: ready once CPIF's ports
exist and the profile's read-only check has passed, before the CP is
powered on. The device's sitd drop-in
Expand Down
36 changes: 31 additions & 5 deletions packages/omamobile-modem/lib/omamobile-modem-start
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,39 @@ PROPS=${OMAMOBILE_MODEM_PROPS:-/var/lib/omamobile-vendor/modem/props.conf}
# for it. Suspend with the modem on has never run on this phone (MODEM-PLAN
# section 6.3), so nothing may sleep once they are loaded.
INHIBITOR=omamobile-modem
# Where a refusal looks for the modem's drivers, and what releases the
# inhibitor (overridden by the test).
SYSMODULE=${OMAMOBILE_MODEM_SYSMODULE:-/sys/module}
SYSTEMCTL=${OMAMOBILE_MODEM_SYSTEMCTL:-systemctl}
say() { printf 'omamobile-modem: %s\n' "$*" >&2; }
boot_id() { cat /proc/sys/kernel/random/boot_id; }

# A refusal's one-line reason for the shell (short: it is a tile's status
# line), then exit 1. Nothing else is written by a refusal.
# line), then exit 1. Nothing else is written by a refusal. A refusal with
# none of the modem's drivers loaded never touched the modem, so the sleep
# block has nothing to guard this boot: release it (a kill, since the
# inhibitor refuses a manual stop). Once a driver has loaded, it stays until
# the reboot, as before.
refuse() {
mkdir -p "$(dirname "$REFUSED")" 2>/dev/null && printf '%s\n' "$1" > "$REFUSED" 2>/dev/null || true
release_inhibitor
exit 1
}
release_inhibitor() {
local m entry mods=(pcie_gs201_cp shm_ipc cpif)
# The device's link stack too, once link.conf is read (refusals come
# before it as well).
for entry in ${LINK_MODULES[@]+"${LINK_MODULES[@]}"}; do
mods+=("${entry%%[[:blank:]]*}")
done
for m in "${mods[@]}"; do
[[ -d $SYSMODULE/${m//-/_} ]] && return 0
done
"$SYSTEMCTL" is-active -q omamobile-modem-inhibit.service 2>/dev/null || return 0
"$SYSTEMCTL" kill omamobile-modem-inhibit.service >/dev/null 2>&1 &&
say "no modem driver loaded: sleep is no longer blocked this boot"
return 0
}

# The refused copies a stale marker leaves (the retry counter), as words.
refused_copies() { local c; c=$(compgen -G "$UP.refused-*" 2>/dev/null) || true; printf '%s' "${c//$'\n'/ }"; }
Expand Down Expand Up @@ -223,13 +247,15 @@ sync

# CPIF and the regions are blacklisted by the device's modem policy (the
# package providing omamobile-modem-policy): only this loads them. Never
# unload cpif (it is permanent by design).
# unload cpif (it is permanent by design). A module that doesn't load is a
# refusal: with none of them loaded the sleep block goes, and one that
# loaded before it keeps the block (refuse()). The latch stays either way.
for entry in "${LINK_MODULES[@]}"; do
read -r -a words <<< "$entry"
modprobe "${words[@]}"
modprobe "${words[@]}" || refuse "Off: ${words[0]} didn't load"
done
modprobe shm_ipc
modprobe cpif
modprobe shm_ipc || refuse "Off: shm_ipc didn't load"
modprobe cpif || refuse "Off: cpif didn't load"
# The link to the modem with ASPM off, as every link test so far ran
# (M3.1); the endpoint's own L1 substates are never enabled (the link API's
# l1ss control is a no-op).
Expand Down
14 changes: 9 additions & 5 deletions packages/omamobile-modem/systemd/omamobile-modem-inhibit.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# modem on has never run on the Pixel 7 Pro (device/cheetah/MODEM-PLAN.md
# 6.3), and the one 9a try with the CP up never woke. omamobile-modem.service
# requires this and starts after it, and its start script refuses to load
# a driver until the lock shows in `systemd-inhibit --list`. Nothing stops
# it but the reboot: stopping the modem unit by hand leaves it (Requires=
# is one way), and a manual stop is refused. A phone with the modem at boot
# therefore never sleeps; the shell's auto-sleep and upower's critical
# action are told so by logind ("Operation inhibited"). The modem unit's
# a driver until the lock shows in `systemd-inhibit --list`. Once a driver
# has loaded, nothing stops it but the reboot: stopping the modem unit by
# hand leaves it (Requires= is one way), and a manual stop is refused. A
# phone with the modem up therefore never sleeps; the shell's auto-sleep
# and upower's critical action are told so by logind ("Operation
# inhibited"). A start that refuses with none of the modem's drivers loaded
# (a stale marker, the latch, a link driver that didn't load) kills it, and
# the phone sleeps as without a modem (omamobile-modem-start's refuse()).
# The modem unit's
# Requires= pulls this in even when that unit's own conditions skip it, so
# the same three conditions are here: a phone that isn't provisioned (no
# modem files, checksums or board id) keeps sleeping.
Expand Down
4 changes: 3 additions & 1 deletion packages/omamobile-modem/systemd/omamobile-modem.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# boot the whole stack comes from omamobile-modem-boot.target (M4.6), which
# the Pixel 7 Pro's device package enables. It starts the modem after the
# audio stack (the AoC carries call audio) and behind the sleep inhibitor
# (omamobile-modem-inhibit.service), which stays until the reboot.
# (omamobile-modem-inhibit.service), which stays until the reboot once a
# modem driver has loaded; since 2026-11-10 a start refused before that
# releases it.
#
# The three conditions are what tools/phone-provision puts on the phone:
# Google's modem files, the NV checksums from the owner's backup and the
Expand Down
27 changes: 27 additions & 0 deletions packages/omamobile-modem/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ pass "start script: markers before the drivers, the check after them, READY befo
m=$t/markers; mkdir -p "$m/root"; : > "$m/nv.sha256"; printf 'ro.boot.cdt_hwid=TESTID\n' > "$m/props.conf"
export OMAMOBILE_MODEM_LATCH=$m/latch OMAMOBILE_MODEM_UP_MARK=$m/up OMAMOBILE_MODEM_HOLD=$m/hold OMAMOBILE_MODEM_REFUSED=$m/run/refused
export OMAMOBILE_MODEM_CHROOT=$m/root OMAMOBILE_MODEM_NV_SUMS=$m/nv.sha256 OMAMOBILE_MODEM_PROPS=$m/props.conf
# What a refusal releases: a fake systemctl that logs its arguments, and an
# empty module directory (no modem driver loaded) unless a test adds one.
mkdir -p "$m/sysmodule"
printf '#!/bin/sh\ncase $1 in is-active) [ -e %s/inhibit-active ];; *) echo "$*" >> %s/systemctl.log;; esac\n' "$m" "$m" > "$m/systemctl"; chmod +x "$m/systemctl"
export OMAMOBILE_MODEM_SYSMODULE=$m/sysmodule OMAMOBILE_MODEM_SYSTEMCTL=$m/systemctl
start() { timeout 20 bash $s "$@" 2>&1; }
past() { OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS=1 start "$@"; }
stop_line='past the marker checks, stopping here (test only)'
Expand Down Expand Up @@ -281,6 +286,28 @@ out=$(start) && fail "a bring-up latch is refused"
[[ -e $m/latch && $(cat "$m/run/refused") == "Off: last bring-up hung" ]] || fail "the latch stays, with its reason for the tile"
out=$(start) && fail "the latch refuses the boot after too"
rm -f "$m/latch"
# A refusal before any modem driver loads releases the sleep block; with a
# driver loaded (here cpif) it stays until the reboot, and an inhibitor that
# isn't running (an unprovisioned phone skips it) is left alone.
rm -f "$m/systemctl.log"; printf 'x boot y\n' > "$m/latch"
out=$(start) && fail "a latch refusal fails"
[[ ! -e $m/systemctl.log ]] || fail "no inhibitor running: nothing to release"
: > "$m/inhibit-active"
out=$(start) && fail "a latch refusal fails"
[[ $(cat "$m/systemctl.log" 2>/dev/null) == "kill omamobile-modem-inhibit.service" && $out == *"sleep is no longer blocked"* ]] ||
fail "a refusal with no modem driver loaded kills the inhibitor: $(cat "$m/systemctl.log" 2>/dev/null) / $out"
rm -f "$m/systemctl.log"; mkdir -p "$m/sysmodule/cpif"
out=$(start) && fail "a latch refusal fails"
[[ ! -e $m/systemctl.log && $out != *"no longer blocked"* ]] || fail "with a modem driver loaded the inhibitor stays: $(cat "$m/systemctl.log" 2>/dev/null)"
rmdir "$m/sysmodule/cpif"; mkdir -p "$m/sysmodule/pcie_gs201_cp"
out=$(start) && fail "a latch refusal fails"
[[ ! -e $m/systemctl.log ]] || fail "with the link driver loaded (pcie-gs201-cp as pcie_gs201_cp) the inhibitor stays"
rmdir "$m/sysmodule/pcie_gs201_cp"; rm -f "$m/latch" "$m/systemctl.log" "$m/inhibit-active"
# A driver that doesn't load is a refusal too (so it can release the block),
# not an exit through set -e.
[[ $(grep -c '^[[:space:]]*modprobe .*|| refuse "Off: ' $s) -eq 3 ]] || fail "every modprobe refuses when it fails"
grep -q 'release_inhibitor$' $s && [[ $(grep -c 'release_inhibitor' $s) -eq 2 ]] || fail "only refuse() releases the inhibitor"
pass "a refusal before any modem driver loads releases the sleep block; after one, it stays"
# A stale modem-up marker (a boot that ended with the modem up and no clean
# stop: a flat battery, or an owner who held the keys on a frozen phone) is
# counted and the modem starts all the same (0.1.19; before, it cost that
Expand Down
34 changes: 31 additions & 3 deletions packages/omamobile-modem/test/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_mismatched_values_refuse(self):
self.assertNotEqual(self.run_value(value, wanted), 0)

def test_device_modules_load_in_order_with_arguments(self):
loop = re.search(r'for entry in "\$\{LINK_MODULES\[@\]\}"; do\n read -r -a words <<< "\$entry"\n modprobe "\$\{words\[@\]\}"\ndone', SOURCE).group()
loop = re.search(r'for entry in "\$\{LINK_MODULES\[@\]\}"; do\n read -r -a words <<< "\$entry"\n modprobe "\$\{words\[@\]\}" \|\| refuse "Off: \$\{words\[0\]\} didn\'t load"\ndone', SOURCE).group()
script = ('LINK_MODULES=("first allow_hw=1" "second cpif=1")\n'
'modprobe() { printf "%s " "$@"; printf "\\n"; }\n' + loop)
result = subprocess.run(['bash', '-c', script], text=True, capture_output=True, check=True)
Expand All @@ -61,7 +61,7 @@ def test_loaded_module_mismatch_refuses_before_loading(self):
self.assertEqual(result.returncode, 0 if value == 'Y' else 7)
self.assertEqual('load-reached' in result.stdout, value == 'Y')

def run_starter(self, config, loaded=None):
def run_starter(self, config, loaded=None, fail_module=None, inhibitor=False):
"""Run actual starter with only paths redirected and inert external tools."""
config_path = self.root / 'link.conf'
if config is not None:
Expand All @@ -86,7 +86,9 @@ def run_starter(self, config, loaded=None):
for name, body in {
'systemd-inhibit': 'echo inhibitor >> "$TRACE"; echo "omamobile-modem held"',
'sync': ':',
'modprobe': 'test -f "$OMAMOBILE_MODEM_LATCH" || exit 23; echo "load:$*" >> "$TRACE"',
'modprobe': 'test -f "$OMAMOBILE_MODEM_LATCH" || exit 23; echo "load:$*" >> "$TRACE"; '
'[[ $1 != "${FAIL_MODULE:-}" ]] || exit 1; mkdir -p "$SYSMODULE/${1//-/_}"',
'systemctl': 'case $1 in is-active) test -e "$INHIBIT_ACTIVE";; *) echo "systemctl:$*" >> "$TRACE";; esac',
}.items():
tool = tools / name
tool.write_text('#!/bin/bash\n' + body + '\n')
Expand All @@ -109,6 +111,14 @@ def run_starter(self, config, loaded=None):
OMAMOBILE_MODEM_CHROOT=str(provision),
OMAMOBILE_MODEM_NV_SUMS=str(provision),
OMAMOBILE_MODEM_PROPS=str(provision))
modules = self.root / 'loaded'
modules.mkdir()
if inhibitor:
(self.root / 'inhibit-active').touch()
env.update(OMAMOBILE_MODEM_SYSMODULE=str(modules), SYSMODULE=str(modules),
OMAMOBILE_MODEM_SYSTEMCTL=str(tools / 'systemctl'),
INHIBIT_ACTIVE=str(self.root / 'inhibit-active'),
FAIL_MODULE=fail_module or '')
env.pop('OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS', None)
result = subprocess.run(['bash', str(starter)], env=env,
capture_output=True, text=True, timeout=5)
Expand All @@ -120,6 +130,24 @@ def test_data_list_reaches_inhibitor_then_ordered_loads_with_latch(self):
self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1',
'load:second cpif=1', 'load:shm_ipc', 'load:cpif', 'profile-check'])

def test_first_module_failing_refuses_and_releases_the_sleep_block(self):
result, trace = self.run_starter('first allow_hw=1\nsecond cpif=1\n', 'Y',
fail_module='first', inhibitor=True)
self.assertEqual(result.returncode, 1)
self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1',
'systemctl:kill omamobile-modem-inhibit.service'])
self.assertEqual((self.root / 'refused').read_text().strip(), "Off: first didn't load")
self.assertTrue((self.root / 'latch').exists())

def test_later_module_failing_keeps_the_sleep_block(self):
# Only first is loaded, a module known by its name in link.conf alone.
result, trace = self.run_starter('first allow_hw=1\nsecond cpif=1\n', 'Y',
fail_module='second', inhibitor=True)
self.assertEqual(result.returncode, 1)
self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1',
'load:second cpif=1'])
self.assertEqual((self.root / 'refused').read_text().strip(), "Off: second didn't load")

def test_no_config_preserves_real_default_load(self):
result, trace = self.run_starter(None)
self.assertEqual(result.returncode, 1)
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-modem/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.19
0.1.20