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
34 changes: 34 additions & 0 deletions packages/omamobile-modem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- SPDX-License-Identifier: MIT -->
# Modem link modules

The default link remains `modprobe pcie-gs201-cp allow_hw=1` when no device
configuration exists. The Pixel 9 Pro XL needs a separate PHY before its PCIe
host; its device package may supply the ordered list as
`/usr/lib/omamobile-modem/link.conf`. This directory is staged by this package
and is separate from extracted vendor files. This package does not install
link.conf or enable another device's drivers. The device package owns its file.

The file is data, never a shell fragment. Each nonempty, noncomment line is:

```
module key=value key=value
```

A module starts with an ASCII letter and contains only letters, digits,
underscores and hyphens. Parameter names start with a letter or underscore;
remaining characters are letters, digits or underscores. Values are nonempty
and contain only letters, digits, underscore, period, comma, colon, plus,
slash or hyphen. Arguments are separated by spaces or tabs; a module without
parameters is valid. Blank lines and whole-line comments are allowed. Shell
quotes, substitutions, assignments, functions, options and inline comments
are refused, as are empty configurations, symlinks and unreadable/nonregular
files. A raw ASCII-text check rejects NUL and other non-text bytes before
Bash reads lines; both passes use the same opened file. A missing file preserves the default; a present invalid file refuses.

All entries are validated before checking already-loaded parameters, checking
the sleep inhibitor, creating the bring-up latch or loading modules. Missing
or mismatched parameters on loaded modules still require a reboot; the
configuration cannot reassign MARK/HOLD or redefine refuse. The normal marker,
unclean-stop and hold decisions remain unchanged. Device-specific configuration
does not authorize starting a modem or replace its watchdog/backup/recovery
qualification. The maintainer allocates the package version at merge.
4 changes: 4 additions & 0 deletions packages/omamobile-modem/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
d=${1:?Usage: ./install DESTDIR}
[[ $d == /* && $d != "/" ]] || { echo "Use an absolute staging directory" >&2; exit 1; }
# Device packages may install a data-only link.conf here. Vendor extraction
# never populates this directory; no config is needed for the gs201 default.
install -dm755 "$d/usr/lib/omamobile-modem"
v=$d/usr/lib/omamobile-vendor
install -Dm755 lib/omamobile-modem-start "$v/omamobile-modem-start"
install -Dm755 lib/omamobile-modem-cp "$v/omamobile-modem-cp"
Expand All @@ -25,5 +28,6 @@ for u in omamobile-modem.service omamobile-modem-inhibit.service omamobile-modem
done
install -Dm644 udev/60-omamobile-modem-nv-ro.rules "$d/usr/lib/udev/rules.d/60-omamobile-modem-nv-ro.rules"
install -Dm644 udev/61-omamobile-vendor-udisks-ignore.rules "$d/usr/lib/udev/rules.d/61-omamobile-vendor-udisks-ignore.rules"
install -Dm644 README.md "$d/usr/share/doc/omamobile-modem/README.md"
install -Dm644 LICENSE "$d/usr/share/licenses/omamobile-modem/LICENSE"
install -Dm644 version "$d/usr/share/omamobile/modem/version"
61 changes: 54 additions & 7 deletions packages/omamobile-modem/lib/omamobile-modem-start
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,57 @@ if [[ ${OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS:-} == 1 ]]; then
exit 0
fi

# The Pixel 9 Pro XL needs its PHY loaded before its PCIe host. Device
# packages can provide this ordered, data-only list outside vendor extraction.
# Without a file, retain the Pixel 7 Pro's existing gs201 invocation.
LINK_CONFIG=/usr/lib/omamobile-modem/link.conf
LINK_MODULES=("pcie-gs201-cp allow_hw=1")
read_link_config() {
local path=$1 entry config_fd LC_ALL=C
[[ -e $path || -L $path ]] || return 0
[[ -f $path && -r $path && ! -L $path ]] || refuse "Off: invalid link configuration"
# Bash read discards NUL bytes. Reject binary/non-ASCII bytes first,
# through the same opened file, before read can normalize their contents.
exec {config_fd}< "$path" || refuse "Off: invalid link configuration"
if LC_ALL=C grep -aq '[^[:print:][:blank:]]' "/proc/self/fd/$config_fd"; then
refuse "Off: invalid link configuration"
else
[[ $? == 1 ]] || refuse "Off: invalid link configuration"
fi
LINK_MODULES=()
while IFS= read -r entry || [[ -n $entry ]]; do
[[ $entry =~ ^[[:blank:]]*$ || $entry =~ ^[[:blank:]]*# ]] && continue
# A module followed by zero or more key=value arguments. No shell syntax,
# quotes, substitutions, options or inline comments are accepted.
[[ $entry =~ ^[a-zA-Z][a-zA-Z0-9_-]*([[:blank:]]+[a-zA-Z_][a-zA-Z0-9_]*=[a-zA-Z0-9_.,:+/-]+)*[[:blank:]]*$ ]] ||
refuse "Off: invalid link configuration"
LINK_MODULES+=("$entry")
done <&"$config_fd"
exec {config_fd}<&-
((${#LINK_MODULES[@]})) || refuse "Off: empty link configuration"
}
read_link_config "$LINK_CONFIG"

# The link driver must allow hardware access, or cbd's power-on is refused
# (-EPERM). allow_hw is fixed at load time: a copy loaded without it (by
# hand, M3.3-B) needs a reboot.
if [[ -d /sys/module/pcie_gs201_cp ]]; then
[[ $(cat /sys/module/pcie_gs201_cp/parameters/allow_hw) == Y ]] ||
{ say "pcie_gs201_cp is loaded without allow_hw=1: reboot first"; refuse "Off: reboot needed"; }
fi
# (-EPERM), and parameters are fixed at load time: a copy already loaded
# with other values (by hand, M3.3-B, or a hardware-disabled test this boot)
# needs a reboot. Booleans read back as Y/N.
link_param_ok() {
local mod=$1 kv=$2 key val have
key=${kv%%=*} val=${kv#*=}
[[ -r /sys/module/$mod/parameters/$key ]] || return 1
have=$(cat "/sys/module/$mod/parameters/$key")
[[ $have == "$val" ]] || { [[ $val == 1 && $have == Y ]]; } || { [[ $val == 0 && $have == N ]]; }
}
for entry in "${LINK_MODULES[@]}"; do
read -r -a words <<< "$entry"
mod=${words[0]//-/_}
[[ -d /sys/module/$mod ]] || continue
for kv in "${words[@]:1}"; do
link_param_ok "$mod" "$kv" ||
{ say "$mod is loaded without $kv: reboot first"; refuse "Off: reboot needed"; }
done
done

# The sleep inhibitor before the drivers: the unit requires and orders after
# omamobile-modem-inhibit.service, but a Type=simple unit is "started" at
Expand All @@ -178,7 +222,10 @@ 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).
modprobe pcie-gs201-cp allow_hw=1
for entry in "${LINK_MODULES[@]}"; do
read -r -a words <<< "$entry"
modprobe "${words[@]}"
done
modprobe shm_ipc
modprobe cpif
# The link to the modem with ASPM off, as every link test so far ran
Expand Down
11 changes: 7 additions & 4 deletions packages/omamobile-modem/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if command -v shellcheck >/dev/null; then
shellcheck -S warning lib/omamobile-modem-start install || fail "shellcheck"
fi
pass "scripts parse"
python3 test/test_link.py || fail "device link module parameters and load order"

# spawn_optional keeps its job alive whatever the daemon's exit: run the
# function from modem.conf under the library's errexit and pipefail with a
Expand Down Expand Up @@ -84,7 +85,9 @@ pass "NV checksums"

stage=$t/stage
./install "$stage"
for f in usr/lib/omamobile-vendor/omamobile-modem-start usr/lib/omamobile-vendor/omamobile-modem-cp \
[[ -d $stage/usr/lib/omamobile-modem ]] || fail "package-owned link configuration directory"
[[ ! -e $stage/usr/lib/omamobile-modem/link.conf ]] || fail "default needs no device link configuration"
for f in usr/share/doc/omamobile-modem/README.md usr/lib/omamobile-vendor/omamobile-modem-start usr/lib/omamobile-vendor/omamobile-modem-cp \
usr/lib/omamobile-vendor/profiles/modem.conf usr/lib/omamobile-vendor/modem/props.conf \
usr/lib/systemd/system/omamobile-modem.service usr/lib/udev/rules.d/60-omamobile-modem-nv-ro.rules \
usr/lib/omamobile-vendor/omamobile-modem-nv-overlay usr/bin/omamobile-modem \
Expand Down Expand Up @@ -165,7 +168,7 @@ s=lib/omamobile-modem-start
lineof() { grep -n "$1" $s | head -1 | cut -d: -f1; }
l_prov_refuse=$(lineof "isn't provisioned"); l_mark_refuse=$(lineof 'never reached ONLINE; skipping'); l_up_refuse=$(lineof 'refuse_unclean$')
l_inhibit=$(lineof 'no sleep inhibitor held'); l_latch=$(lineof '> "\$MARK"'); l_latch_sync=$(awk -v n="$l_latch" 'NR == n + 1' $s)
l_modprobe=$(lineof '^modprobe '); l_check=$(lineof 'omamobile-vendor-chroot" modem check'); l_rm=$(lineof '^ rm -f "\$MARK"')
l_modprobe=$(lineof '^[[:space:]]*modprobe '); l_check=$(lineof 'omamobile-vendor-chroot" modem check'); l_rm=$(lineof '^ rm -f "\$MARK"')
l_ready=$(lineof 'systemd-notify --ready'); l_exec=$(lineof 'exec "\$LIB/omamobile-vendor-chroot" modem start')
l_reason_rm=$(lineof '^rm -f "\$REFUSED"')
for v in l_prov_refuse l_mark_refuse l_up_refuse l_inhibit l_reason_rm l_latch l_modprobe l_check l_rm l_ready l_exec; do
Expand All @@ -175,7 +178,7 @@ done
[[ $l_prov_refuse -lt $l_mark_refuse && $l_mark_refuse -lt $l_up_refuse && $l_up_refuse -lt $l_inhibit && $l_inhibit -lt $l_reason_rm && $l_reason_rm -lt $l_latch && $l_latch -lt $l_modprobe &&
$l_modprobe -lt $l_check && $l_check -lt $l_rm && $l_rm -lt $l_ready && $l_ready -lt $l_exec ]] ||
fail "start script order: refuse($l_prov_refuse,$l_mark_refuse,$l_up_refuse) inhibit($l_inhibit) reason-rm($l_reason_rm) latch($l_latch) modprobe($l_modprobe) check($l_check) rm($l_rm) ready($l_ready) exec($l_exec)"
[[ $(grep -c '^modprobe ' $s) -eq 3 && $(grep -c 'modprobe' <(sed -n "1,${l_latch}p" $s) ) -eq 0 ]] ||
[[ $(grep -c '^[[:space:]]*modprobe ' $s) -eq 3 && $(grep -c 'modprobe' <(sed -n "1,${l_latch}p" $s) ) -eq 0 ]] ||
fail "no modprobe before the latch"
grep -q 'OMAMOBILE_MODEM_MARK=\$MARK OMAMOBILE_MODEM_UP_MARK=\${INVOCATION_ID:+\$UP} exec' $s || fail "both markers go to the profile's watcher (the modem-up one only under the unit)"
grep -q "OMAMOBILE_MODEM_UP_MARK" $cp || fail "the watcher writes the modem-up marker"
Expand All @@ -201,7 +204,7 @@ past() { OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS=1 start "$@"; }
stop_line='past the marker checks, stopping here (test only)'
! grep -rq 'OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS' systemd install || fail "the test stop point is set by no unit or install step"
l_stop=$(lineof 'OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS:-')
[[ $l_up_refuse -lt $l_stop && $l_stop -lt $(lineof '/sys/module/pcie_gs201_cp') && $l_stop -lt $l_inhibit && $l_stop -lt $l_latch ]] ||
[[ $l_up_refuse -lt $l_stop && $l_stop -lt $(lineof '^link_param_ok()') && $l_stop -lt $l_inhibit && $l_stop -lt $l_latch ]] ||
fail "the test stop point sits after the marker decision and before the sysfs read, the inhibitor and the latch (stop=$l_stop)"
# Not provisioned (a fresh install before tools/phone-provision): one line
# per missing file, no latch, the reason says so. The unit itself is skipped
Expand Down
Loading