Skip to content
7 changes: 5 additions & 2 deletions packages/omamobile-gnss/bin/omamobile-gnss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ AGENT=omamobile-geoclue-agent.service
LTO_TIMER=omamobile-gnss-lto.timer
LTO_FILE=/var/lib/omamobile-vendor/gnss/data/vendor/gps/lto2.dat
ROOT=/usr/lib/omamobile-vendor/gnss/root
# the Pixel 9a's image (gnss-slsi): no Broadcom orbit predictions there
[[ ! -d $ROOT && -d /usr/lib/omamobile-vendor/gnss-slsi/root ]] && ROOT=/usr/lib/omamobile-vendor/gnss-slsi/root

usage() {
sed -n '3,17s/^# \{0,1\}//p' "$0" >&2
Expand Down Expand Up @@ -95,14 +97,15 @@ status() {
none|unknown) echo "orbit predictions (LTO): $lto" ;;
*) echo "orbit predictions (LTO): ${lto} h old" ;;
esac
[[ -d $ROOT ]] || echo "vendor files: missing ($ROOT; tools/extract-vendor-chroot -p gnss)"
[[ -d $ROOT ]] || echo "vendor files: missing ($ROOT; tools/extract-vendor-chroot -p gnss, or -p gnss-slsi -d tegu)"
fi
}

case ${1:-} in
on)
as_root on
systemctl enable --now "$SOCKET" "$LTO_TIMER"
systemctl enable --now "$SOCKET"
[[ $ROOT == */gnss/root ]] && systemctl enable --now "$LTO_TIMER"
systemctl --global enable "$AGENT"
;;
off)
Expand Down
7 changes: 5 additions & 2 deletions packages/omamobile-gnss/lib/omamobile-gnss-nmea
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import sys
import time
import tty

FIFO = "/var/lib/omamobile-vendor/gnss/data/vendor/gps/nmea_out"
# the Pixel 7 Pro's gnss profile, then the Pixel 9a's gnss-slsi
FIFOS = ("/var/lib/omamobile-vendor/gnss/data/vendor/gps/nmea_out",
"/var/lib/omamobile-vendor/gnss-slsi/data/vendor/gps/nmea_out")
FIFO = FIFOS[0]
RUN = "/run/omamobile-gnss"
MAX_LINE = 1024
SD_LISTEN_FDS_START = 3
Expand Down Expand Up @@ -175,7 +178,7 @@ class Bridge:

def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--fifo", default=FIFO)
ap.add_argument("--fifo", default=next((f for f in FIFOS if os.path.exists(f)), FIFO))
ap.add_argument("--run", default=RUN)
ap.add_argument("--idle-exit", type=int, default=0, metavar="SECONDS",
help="exit after SECONDS without a client (0: never)")
Expand Down
42 changes: 42 additions & 0 deletions packages/omamobile-gnss/lib/omamobile-gnss-start
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,57 @@
set -euo pipefail

MARK=/var/lib/omamobile/gnss-bringup-started
# The 9a's session of this boot: written with the marker, in /run so that a
# reset empties it.
SESSION=/run/omamobile-gnss/session
say() { printf 'omamobile-gnss: %s\n' "$*" >&2; }

# the Pixel 9a (zumapro-tegu) runs the gnss-slsi profile, the Pixel 7 Pro gnss
# OMAMOBILE_DT lets the tests run both branches on any machine (as
# omamobile-setup-user does).
tegu() { tr -d '\0' < "${OMAMOBILE_DT:-/proc/device-tree}/compatible" 2>/dev/null | grep -c 'google,zumapro-tegu' >/dev/null; }
if [[ ${1:-} == --stop ]]; then
# A clean stop is the only place the 9a's marker is cleared: its session
# runs in the foreground until then, so a reset in between leaves the
# marker and the next boot skips GNSS until --retry. Only a session of
# this boot clears it: systemd runs ExecStop after a start that skipped
# on a leftover marker too, and that stop must leave the marker alone.
# The 7 Pro's start clears its own marker once the driver is up.
if [[ -e $SESSION ]]; then
rm -f "$MARK" "$SESSION"
sync
fi
if tegu; then profile=gnss-slsi; else profile=gnss; fi
exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot "$profile" stop
fi

if [[ ${1:-} == --retry ]]; then
rm -f "$MARK"
elif [[ -e $MARK ]]; then
say "the last bring-up ($(cat "$MARK")) never finished; skipping GNSS (run omamobile-gnss-start --retry)"
exit 0
fi

# The Pixel 9a's GNSS is the modem's Kepler core: Samsung's gnssd runs in
# the modem profile, and the gnss-slsi profile runs the HAL and our client,
# which writes NMEA to the FIFO the bridge reads. Nothing to load here.
if tegu; then
if ! grep -c '@GNSSND' /proc/net/unix >/dev/null; then
say "gnssd isn't running (the modem profile with OMAMOBILE_MODEM_GNSS=1); nothing to do"
exit 0
fi
# The hang marker goes down before the session, as on the 7 Pro, because
# a session on the 9a can still hang the SoC with the modem up
# (MODEM-PLAN G3-L1), and socket activation lets any GeoClue client start
# one: without the marker a hang could repeat at every boot. It is
# cleared by --stop, not here, since this exec never returns.
mkdir -p "$(dirname "$MARK")" "$(dirname "$SESSION")"
date -Is > "$MARK"
: > "$SESSION"
sync
say "starting the 9a's GNSS HAL and client"
OMAMOBILE_GNSS_NMEA_OUT=fifo exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start
fi
# The DT must have the GNSS node enabled (gnss overlay); otherwise nothing to do.
if ! grep -qs okay /sys/firmware/devicetree/base/soc@0/usi@109400c0/spi@10940000/status; then
say "SPI5 is not enabled in this device tree; nothing to do"
Expand Down
65 changes: 63 additions & 2 deletions packages/omamobile-gnss/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,62 @@ for f in bin/omamobile-gnss lib/omamobile-vendor-chroot lib/omamobile-gnss-start
bash -n "$f" || fail "syntax: $f"
done
python3 -c 'import ast, sys; ast.parse(open(sys.argv[1]).read())' lib/omamobile-gnss-nmea || fail "python: omamobile-gnss-nmea"
# The Pixel 9a's path: gnss-slsi from the start script, its FIFO in the bridge and the units.
grep -c 'gnss-slsi start' lib/omamobile-gnss-start >/dev/null || fail "the 9a starts gnss-slsi"
# the 9a writes the hang marker before its session and clears it only in --stop
s=lib/omamobile-gnss-start
[[ $(grep -n 'date -Is > "\$MARK"' $s | head -1 | cut -d: -f1) -lt $(grep -n 'gnss-slsi start' $s | head -1 | cut -d: -f1) ]] || fail "the 9a's marker goes down before gnss-slsi start"
[[ $(grep -n 'rm -f "\$MARK" "\$SESSION"' $s | head -1 | cut -d: -f1) -lt $(grep -n 'profile.*stop' $s | head -1 | cut -d: -f1) ]] || fail "--stop clears the marker"
grep -c 'OMAMOBILE_DT:-/proc/device-tree' $s >/dev/null || fail "the compatible is read through an overridable path"
# both branches, with a fake device tree and a stub chroot: the 9a path writes
# the marker and runs gnss-slsi, the 7 Pro path neither (no SPI5 node here)
tmp=$(mktemp -d); mkdir -p "$tmp/dt" "$tmp/bin" "$tmp/lib/omamobile-vendor" "$tmp/var/lib/omamobile"
printf 'google,zumapro-tegu\0google,zumapro\0' > "$tmp/dt/compatible"
cat > "$tmp/stub" <<'EOF'
#!/bin/sh
echo "chroot $*" >> "${STUB_LOG}"
EOF
chmod +x "$tmp/stub"
run_start() { # $1 dt dir, $2 fake unix table
STUB_LOG="$tmp/log" OMAMOBILE_DT="$1" bash -c '
MARKDIR='"$tmp"'/var/lib/omamobile
sed -e "s|/var/lib/omamobile/gnss-bringup-started|'"$tmp"'/var/lib/omamobile/gnss-bringup-started|" \
-e "s|/proc/net/unix|'"$2"'|" \
-e "s|/run/omamobile-gnss/session|'"$tmp"'/run/omamobile-gnss/session|" \
-e "s|/sys/firmware/devicetree/base/soc@0/usi@109400c0/spi@10940000/status|'"$tmp"'/no-spi5|" \
-e "s|/usr/lib/omamobile-vendor/omamobile-vendor-chroot|'"$tmp"'/stub|" lib/omamobile-gnss-start > '"$tmp"'/start
bash '"$tmp"'/start "$@"' _ "${3:-}" 2>/dev/null
}
: > "$tmp/log"; printf '@GNSSND\n' > "$tmp/unix"
run_start "$tmp/dt" "$tmp/unix"
grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "9a branch: gnss-slsi start ran"
[[ -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "9a branch: the marker was written before the session"
run_start "$tmp/dt" "$tmp/unix"
grep -c 'never finished; skipping' <(STUB_LOG="$tmp/log" OMAMOBILE_DT="$tmp/dt" bash "$tmp/start" 2>&1) >/dev/null || fail "9a branch: a leftover marker skips the next start"
# after a reset: the marker is left over and /run is empty. The start skips,
# systemd runs ExecStop anyway, and the marker must still be there afterwards
rm -rf "$tmp/run"
run_start "$tmp/dt" "$tmp/unix" --stop
[[ -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "a stop after a skipped start cleared the leftover marker"
grep -c 'chroot gnss-slsi stop' "$tmp/log" >/dev/null || fail "9a branch: --stop stops gnss-slsi"
# a session of this boot: --stop clears the marker and the session file
run_start "$tmp/dt" "$tmp/unix" --retry
[[ -e "$tmp/run/omamobile-gnss/session" ]] || fail "9a branch: the session file is written with the marker"
run_start "$tmp/dt" "$tmp/unix" --stop
[[ ! -e "$tmp/var/lib/omamobile/gnss-bringup-started" && ! -e "$tmp/run/omamobile-gnss/session" ]] || fail "--stop after a session clears the marker"
: > "$tmp/log"; printf 'google,gs201-cheetah\0google,gs201\0' > "$tmp/dt/compatible"
run_start "$tmp/dt" "$tmp/unix"
grep -c 'gnss-slsi' "$tmp/log" >/dev/null && fail "7 Pro branch: must not touch gnss-slsi"
[[ ! -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "7 Pro branch: no SPI5 node here, so no marker"
rm -rf "$tmp"
echo "ok - the 9a's start writes the marker, --stop clears it, both branches behave"
grep -c 'OMAMOBILE_GNSS_NMEA_OUT=fifo' lib/omamobile-gnss-start >/dev/null || fail "the 9a's NMEA goes to the FIFO"
grep -c 'gnss-slsi/data/vendor/gps/nmea_out' lib/omamobile-gnss-nmea >/dev/null || fail "the bridge reads the 9a's FIFO"
grep -c '^ConditionPathExists=|/usr/lib/omamobile-vendor/gnss-slsi/root$' vendor/systemd/system/omamobile-gnss.service >/dev/null || fail "the service runs with the 9a's image"
grep -c '^ExecStop=/usr/lib/omamobile-vendor/omamobile-gnss-start --stop$' vendor/systemd/system/omamobile-gnss.service >/dev/null || fail "stop picks the profile"
grep -c 'gnss-slsi/data/vendor/gps' vendor/systemd/system/omamobile-gnss-nmea.service >/dev/null || fail "the bridge may open the 9a's FIFO"
# --stop comes before the hang marker, so a leftover marker never skips a stop
[[ $(grep -n -- '--stop' lib/omamobile-gnss-start | head -1 | cut -d: -f1) -lt $(grep -n 'elif \[\[ -e \$MARK' lib/omamobile-gnss-start | cut -d: -f1) ]] || fail "--stop before the marker"
# A running stack keeps the phone awake (SUSPEND-PLAN 6.1).
grep -qx 'ExecStart=/usr/bin/systemd-inhibit --what=sleep --mode=block "--who=Omarchy Mobile GNSS" "--why=A location session is running" /usr/lib/omamobile-vendor/omamobile-gnss-start' \
vendor/systemd/system/omamobile-gnss.service || fail "the stack holds a sleep inhibitor while it runs"
Expand Down Expand Up @@ -74,8 +130,13 @@ grep -q '^\[geoclue-where-am-i\]' etc/geoclue/conf.d/90-omamobile-gnss.conf || f
# status must not print "nono" (forced suffix only when forced)
grep -q 'forced/yes' bin/omamobile-gnss && fail "status forced suffix"
grep -q 'blacklist bcm4775x_gnss' vendor/modprobe.d/omamobile-gnss.conf || fail "driver must stay blacklisted from autoload"
grep -q '^ExecStop=.*omamobile-vendor-chroot gnss stop$' vendor/systemd/system/omamobile-gnss.service ||
fail "the stack must stop gpsd's request before the stop signal"
# ExecStop runs before the stop signal, and the start script's --stop ends in
# the profile's own stop (gnss on the 7 Pro, gnss-slsi on the 9a), so gpsd's
# request is withdrawn before the chroot is killed.
grep -c '^ExecStop=/usr/lib/omamobile-vendor/omamobile-gnss-start --stop$' vendor/systemd/system/omamobile-gnss.service >/dev/null ||
fail "the stack must stop the profile before the stop signal"
grep -c 'exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot "\$profile" stop' lib/omamobile-gnss-start >/dev/null ||
fail "--stop must end in the profile's stop"
grep -q 'omamobile-gnss-lto.timer\|LTO_TIMER' bin/omamobile-gnss || fail "the Location switch must handle the LTO timer"
grep -q 'etc/omamobile/gnss.conf' PKGBUILD || fail "gnss.conf must be a backup file"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Requires=omamobile-gnss-nmea.socket
After=omamobile-gnss-nmea.socket

[Service]
ExecStartPre=/bin/sh -c 'for i in $(seq 1 150); do [ -p /var/lib/omamobile-vendor/gnss/data/vendor/gps/nmea_out ] && exit 0; sleep 0.2; done; exit 1'
ExecStartPre=/bin/sh -c 'for i in $(seq 1 150); do for f in /var/lib/omamobile-vendor/gnss/data/vendor/gps/nmea_out /var/lib/omamobile-vendor/gnss-slsi/data/vendor/gps/nmea_out; do [ -p $f ] && exit 0; done; sleep 0.2; done; exit 1'
ExecStart=/usr/lib/omamobile-vendor/omamobile-gnss-nmea --idle-exit 60
ProtectSystem=strict
ReadWritePaths=-/var/lib/omamobile-vendor/gnss/data/vendor/gps -/run/omamobile-gnss
ReadWritePaths=-/var/lib/omamobile-vendor/gnss/data/vendor/gps -/var/lib/omamobile-vendor/gnss-slsi/data/vendor/gps -/run/omamobile-gnss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# bridge does (StopWhenUnneeded), which closes /dev/ttyBCM and powers the
# chip off.
[Unit]
Description=Omarchy Mobile GNSS (BCM4775x, stock lhd and gpsd)
Description=Omarchy Mobile GNSS (Pixel 7 Pro: BCM4775x, stock lhd and gpsd; Pixel 9a: the modem's Kepler through the stock HAL)
After=network-online.target
StopWhenUnneeded=yes
ConditionPathExists=/usr/lib/omamobile-vendor/gnss/root
ConditionPathExists=|/usr/lib/omamobile-vendor/gnss/root
ConditionPathExists=|/usr/lib/omamobile-vendor/gnss-slsi/root

[Service]
# A location session keeps the phone awake: while the stack runs it holds a
Expand All @@ -17,5 +18,5 @@ ConditionPathExists=/usr/lib/omamobile-vendor/gnss/root
ExecStart=/usr/bin/systemd-inhibit --what=sleep --mode=block "--who=Omarchy Mobile GNSS" "--why=A location session is running" /usr/lib/omamobile-vendor/omamobile-gnss-start
# Before the stop signal: ask gpsd to end its request, so it saves its
# state (gldata.sto) for the next start. Bounded at ~4 s.
ExecStop=/usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss stop
ExecStop=/usr/lib/omamobile-vendor/omamobile-gnss-start --stop
TimeoutStopSec=15
2 changes: 1 addition & 1 deletion packages/omamobile-gnss/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.6
0.2.7