Migrate boot to runit

This commit is contained in:
Adeeb Shihadeh
2026-05-02 19:08:26 -07:00
parent ccac0cba21
commit 9d4350c6f8
107 changed files with 1181 additions and 699 deletions
+113 -8
View File
@@ -78,12 +78,14 @@ RUN /tmp/agnos/openpilot_python_dependencies.sh
FROM agnos-base
# Hardware rootfs overlay
RUN rm -f /usr/sbin/init /usr/sbin/reboot /usr/sbin/poweroff /usr/sbin/halt /usr/sbin/shutdown
COPY ./userspace/root/etc/ /etc/
COPY ./userspace/root/lib/ /usr/lib/
COPY ./userspace/root/home/ /home/
COPY ./userspace/root/sbin/ /usr/sbin/
COPY ./userspace/root/system/ /system/
COPY ./userspace/root/usr/ /usr/
RUN rm -f /usr/bin/systemctl && ln -sf /usr/comma/shims/systemctl /usr/bin/systemctl
RUN mkdir -p /dsp /firmware /persist /data /cache /rwtmp
COPY --from=agnos-compiler-libqmi /tmp/libqmi.deb /tmp/
@@ -122,6 +124,8 @@ RUN source $XDG_DATA_HOME/venv/bin/activate && \
COPY ./userspace/install_extras.sh /tmp/agnos/
RUN /tmp/agnos/install_extras.sh
# Remove systemd as an installed init/service stack. libsystemd0/libudev1 stay
# as compatibility libraries for dbus, polkit, NetworkManager, and ModemManager.
RUN chown -R $USERNAME: /home/$USERNAME/.config
RUN rm -rf /root/.config && ln -s /home/$USERNAME/.config /root/.config
@@ -137,10 +141,6 @@ RUN chown $USERNAME: /home/$USERNAME/power_burn_max
COPY ./userspace/irsc_util.c /tmp/agnos/
RUN gcc -O2 -Wall -Wextra -o /usr/bin/irsc_util /tmp/agnos/irsc_util.c
# Setup systemd services
COPY ./userspace/services.sh /tmp/agnos
RUN /tmp/agnos/services.sh
# MOTD
RUN rm -r /etc/update-motd.d/*
COPY --chown=root:root ./userspace/root/etc/update-motd.d/* /etc/update-motd.d/
@@ -150,13 +150,118 @@ RUN chmod 600 /usr/lib/NetworkManager/system-connections/*.nmconnection
# Prefer ipv4 over ipv6
RUN echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf
# Run ModemManager in debug mode to allow AT commands
COPY ./userspace/files/ModemManager.service /lib/systemd/system/
RUN systemctl enable ModemManager
# Setup hostname resolution for our custom hostname
RUN sed -i 's/hosts: files dns myhostname/hosts: files myhostname dns/g' /etc/nsswitch.conf
# The image boots under runit; remove systemd activation paths brought in by Ubuntu packages.
RUN rm -rf /etc/systemd /usr/lib/systemd /run/systemd /var/lib/systemd /usr/share/systemd && \
rm -f /usr/bin/systemd* && \
find /usr/share/dbus-1 \( \
-name '*systemd*' -o \
-name '*hostname1*' -o \
-name '*login1*' -o \
-name '*network1*' -o \
-name '*timedate1*' -o \
-name '*locale1*' -o \
-name '*machine1*' -o \
-name '*home1*' \
\) -delete && \
rm -f /usr/share/dbus-1/system-services/org.freedesktop.hostname1.service \
/usr/share/dbus-1/system-services/org.freedesktop.systemd1.service \
/usr/share/dbus-1/system.d/org.freedesktop.hostname1.conf \
/usr/share/dbus-1/system.d/org.freedesktop.systemd1.conf \
/usr/share/dbus-1/interfaces/org.freedesktop.hostname1.xml \
/usr/share/dbus-1/interfaces/org.freedesktop.systemd1*.xml && \
rm -rf /usr/include/systemd && \
rm -f /usr/lib/modprobe.d/systemd.conf \
/usr/lib/sysctl.d/50-pid-max.conf \
/usr/lib/sysusers.d/systemd-*.conf \
/usr/lib/tmpfiles.d/systemd*.conf \
/usr/lib/tmpfiles.d/credstore.conf \
/usr/lib/tmpfiles.d/debian.conf \
/usr/lib/tmpfiles.d/home.conf \
/usr/lib/tmpfiles.d/journal-nocow.conf \
/usr/lib/tmpfiles.d/legacy.conf \
/usr/lib/tmpfiles.d/provision.conf \
/usr/lib/tmpfiles.d/static-nodes-permissions.conf \
/usr/lib/tmpfiles.d/tmp.conf \
/usr/lib/tmpfiles.d/var.conf \
/usr/lib/tmpfiles.d/x11.conf \
/usr/lib/pam.d/systemd-user \
/usr/lib/lsb/init-functions.d/40-systemd \
/usr/lib/NetworkManager/conf.d/10-dns-resolved.conf \
/usr/libexec/netplan/generate \
/usr/lib/udev/rules.d/99-systemd.rules \
/usr/lib/apt/apt.systemd.daily \
/usr/bin/deb-systemd-helper \
/usr/bin/deb-systemd-invoke \
/usr/bin/journalctl \
/usr/lib/aarch64-linux-gnu/libsystemd.a \
/usr/lib/aarch64-linux-gnu/pkgconfig/libsystemd.pc \
/usr/lib/aarch64-linux-gnu/libsystemd.so \
/usr/lib/aarch64-linux-gnu/security/pam_systemd.so \
/usr/lib/aarch64-linux-gnu/security/pam_systemd_loadkey.so \
/usr/lib/aarch64-linux-gnu/cryptsetup/libcryptsetup-token-systemd-fido2.so \
/usr/lib/aarch64-linux-gnu/cryptsetup/libcryptsetup-token-systemd-pkcs11.so \
/usr/lib/aarch64-linux-gnu/cryptsetup/libcryptsetup-token-systemd-tpm2.so \
/etc/dhcp/dhclient-enter-hooks.d/resolved-enter \
/etc/dhcp/dhclient-exit-hooks.d/resolved \
/etc/network/if-up.d/resolved \
/etc/network/if-down.d/resolved \
/etc/apt/apt.conf.d/20apt-esm-hook.conf \
/etc/cron.daily/apt-compat \
/usr/share/apport/package-hooks/systemd.py \
/usr/share/dnsmasq/systemd-helper \
/usr/share/mime/text/x-systemd-unit.xml \
/usr/share/polkit-1/actions/org.freedesktop.systemd1.policy \
/usr/share/vim/vim91/ftplugin/systemd.vim \
/usr/share/vim/vim91/syntax/systemd.vim && \
rm -rf /etc/xdg/systemd \
/usr/lib/aarch64-linux-gnu/systemd \
/usr/lib/python3/dist-packages/sos/policies/init_systems/__pycache__/systemd.cpython-312.pyc \
/usr/lib/python3/dist-packages/sos/policies/init_systems/systemd.py \
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/systemd.cpython-312.pyc \
/usr/lib/python3/dist-packages/sos/report/plugins/systemd.py \
/usr/lib/python3/dist-packages/twisted/python/__pycache__/systemd.cpython-312.pyc \
/usr/lib/python3/dist-packages/twisted/python/systemd.py \
/usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_systemd.cpython-312.pyc \
/usr/lib/python3/dist-packages/twisted/python/test/test_systemd.py \
/usr/local/venv/lib/python3.12/site-packages/jedi/third_party/typeshed/stubs/gunicorn/gunicorn/systemd.pyi \
/usr/local/venv/lib/python3.12/site-packages/xvfb/install/lib/libsystemd.so.0 \
/usr/share/bug/systemd \
/usr/share/doc/systemd \
/usr/share/doc/systemd-dev \
/usr/share/doc/systemd-sysv \
/usr/share/doc/libpam-systemd \
/usr/share/doc/libsystemd-dev \
/usr/share/doc/libsystemd-shared \
/usr/share/doc/libsystemd0 \
/usr/share/lintian/overrides/systemd \
/usr/share/lintian/overrides/libpam-systemd \
/usr/share/lintian/overrides/libsystemd-shared \
/usr/share/pam-configs/systemd && \
rm -f /usr/share/bash-completion/completions/journalctl \
/usr/share/bash-completion/completions/systemctl \
/usr/share/bash-completion/completions/systemd-* \
/usr/share/pkgconfig/systemd.pc \
/usr/share/polkit-1/rules.d/systemd-networkd.rules \
/usr/share/zsh/vendor-completions/_journalctl \
/usr/share/zsh/vendor-completions/_systemctl \
/usr/share/zsh/vendor-completions/_systemd* && \
sed -i '/^SystemdService=/d' /usr/share/dbus-1/system-services/*.service && \
sed -i '/pam_systemd/d' /etc/pam.d/common-session /etc/pam.d/runuser-l && \
sed -i '/^systemd-/d' /etc/passwd /etc/group /etc/shadow /etc/gshadow && \
find /var/lib/dpkg/info -maxdepth 1 \( \
-name 'systemd*' -o \
-name 'libpam-systemd*' -o \
-name 'libsystemd-dev*' -o \
-name 'libsystemd-shared*' \
\) -delete && \
perl -0pi -e 's/(^|\n)Package: (systemd|systemd-sysv|systemd-dev|libpam-systemd|libsystemd-dev|libsystemd-shared)\n.*?(?=\nPackage: |\z)/$1/gs' /var/lib/dpkg/status && \
if [ -e /var/lib/dpkg/status-old ]; then \
perl -0pi -e 's/(^|\n)Package: (systemd|systemd-sysv|systemd-dev|libpam-systemd|libsystemd-dev|libsystemd-shared)\n.*?(?=\nPackage: |\z)/$1/gs' /var/lib/dpkg/status-old; \
fi
# keep this last
RUN ldconfig
+2 -2
View File
@@ -14,8 +14,8 @@
- [ ] corrupt userdata: `dd if=/dev/zero of=/dev/disk/by-partlabel/userdata count=10 bs=1M`
- [ ] Clean setup: factory reset -> install openpilot -> openpilot works
- [ ] Color calibration works from `/persist/comma/`
- [ ] tizi: `journalctl -u magic | grep 'Successfully setup color correction'`
- [ ] mici: `journalctl -u screen_calibration | grep -i 'Successfully setup screen calibration'`
- [ ] tizi: `grep 'Successfully setup color correction' /tmp/magic.log`
- [ ] mici: `grep -i 'Successfully setup screen calibration' /tmp/screen-calibration.log`
- [ ] AGNOS update works on warm boot
- [ ] previous -> new
- [ ] new -> previous
+2 -2
View File
@@ -116,8 +116,8 @@ set_network_stuff() {
bash -c "echo \"127.0.0.1 localhost.localdomain localhost\" > etc/hosts"
bash -c "echo \"127.0.0.1 $HOST\" >> etc/hosts"
# Fix resolv config
bash -c "ln -sf /run/systemd/resolve/stub-resolv.conf etc/resolv.conf"
# Fix resolv config. NetworkManager writes this file on the runtime tmpfs.
bash -c "ln -sf /run/NetworkManager/resolv.conf etc/resolv.conf"
# Set capability for ping
bash -c "setcap cap_net_raw+ep bin/ping"
+3 -4
View File
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
set -e
ssh tici "systemd-analyze plot > /tmp/bootchart.svg"
scp tici:/tmp/bootchart.svg /tmp/bootchart.svg
google-chrome /tmp/bootchart.svg
ssh tici "dmesg | grep 'boot.sh' > /tmp/bootchart.txt"
scp tici:/tmp/bootchart.txt /tmp/bootchart.txt
cat /tmp/bootchart.txt
+7 -3
View File
@@ -15,7 +15,8 @@ import time
import usb.core
SERIAL_DEV = "/dev/serial/by-id/usb-Microchip_Tech_USB2_Controller_Hub-if01"
PROMPT_RE = re.compile(rb"(?:login:|[#\$])$")
PROMPT_RE = re.compile(rb"(?:login:|(?:\x1b\[\?2004h)?(?:\([^)]+\) )?[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+:[^\r\n]*[#\$]\s*)$")
BOOT_DONE_RE = re.compile(rb"boot\.sh\[\d+\]: .* boot path done")
USB_RT_PORT = 0x23
USB_REQ_CLEAR_FEATURE = 1
USB_REQ_SET_FEATURE = 3
@@ -128,6 +129,7 @@ class Mdma:
# show serial console with timestamps until boot is done
pending = b""
bootsh_seen = False
while True:
if not select.select([fd], [], [], 0.25)[0]:
continue
@@ -140,11 +142,13 @@ class Mdma:
line, pending = pending.split(b"\n", 1)
line = line.rstrip()
print(f"[{time.monotonic() - start:8.3f}] {line.decode(errors='replace')}", flush=True)
if PROMPT_RE.search(line):
bootsh_seen = bootsh_seen or b"boot.sh[" in line
if BOOT_DONE_RE.search(line) or (PROMPT_RE.search(line) and not bootsh_seen):
return
if PROMPT_RE.search(pending.strip()):
print(f"[{time.monotonic() - start:8.3f}] {pending.strip().decode(errors='replace')}", flush=True)
return
if not bootsh_seen:
return
if __name__ == "__main__":
+16 -9
View File
@@ -16,14 +16,21 @@ echo "symlink /usr/comma"
sudo rm -rf /usr/comma
sudo ln -snf $ROOT/userspace/root/usr/comma/ /usr/comma
echo "cp systemd services"
for s in "$ROOT"/userspace/root/lib/systemd/system/*.{service,path,timer,mount} "$ROOT"/userspace/files/ModemManager.service; do
[ -e "$s" ] || continue
service=$(basename $s)
echo "- $service"
sudo rm -f /lib/systemd/system/$service
sudo cp "$s" /lib/systemd/system/
done
sudo $ROOT/userspace/services.sh
if ! command -v runit >/dev/null; then
sudo apt-get update
sudo apt-get install -y runit
fi
echo "cp runit init"
sudo mkdir -p /etc/runit
sudo cp "$ROOT"/userspace/root/etc/runit/[123] /etc/runit/
sudo rm -f /usr/bin/systemctl /usr/sbin/init /usr/sbin/reboot /usr/sbin/poweroff /usr/sbin/halt /usr/sbin/shutdown
sudo ln -sf /usr/comma/shims/systemctl /usr/bin/systemctl
sudo cp "$ROOT"/userspace/root/sbin/init /sbin/init
sudo cp "$ROOT"/userspace/root/sbin/reboot /sbin/reboot
sudo cp "$ROOT"/userspace/root/sbin/poweroff /sbin/poweroff
sudo cp "$ROOT"/userspace/root/sbin/halt /sbin/halt
sudo cp "$ROOT"/userspace/root/sbin/shutdown /sbin/shutdown
sudo chmod 755 /etc/runit/[123] /sbin/init /sbin/reboot /sbin/poweroff /sbin/halt /sbin/shutdown
sudo mount -o ro,remount /
+1 -10
View File
@@ -68,11 +68,9 @@ apt-fast install --no-install-recommends -yq \
openssh-server \
ppp \
rsyslog \
runit \
ssh \
sudo \
systemd \
systemd-resolved \
systemd-timesyncd \
ubuntu-minimal \
ubuntu-server \
ubuntu-standard \
@@ -83,9 +81,6 @@ apt-fast install --no-install-recommends -yq \
wpasupplicant \
zlib1g-dev
# Enable serial console on UART
systemctl enable serial-getty@ttyS0.service
# set kernel params
echo "net.ipv4.conf.all.rp_filter = 2" >> /etc/sysctl.conf
echo "vm.dirty_expire_centisecs = 200" >> /etc/sysctl.conf
@@ -98,9 +93,6 @@ echo "comma - nice -10" >> /etc/security/limits.conf
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
# Disable pstore service that moves files out of /sys/fs/pstore
systemctl disable systemd-pstore.service
# Nopasswd sudo
echo "comma ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
@@ -121,7 +113,6 @@ adduser $USERNAME audio
adduser $USERNAME disk
adduser $USERNAME netdev
adduser $USERNAME dialout
adduser $USERNAME systemd-journal
# Create dirs
mkdir /data && chown $USERNAME:$USERNAME /data
-22
View File
@@ -1,22 +0,0 @@
[Unit]
Description=Modem Manager
After=polkit.service
Requires=polkit.service
[Service]
Type=dbus
BusName=org.freedesktop.ModemManager1
ExecStart=/usr/sbin/ModemManager --filter-policy=strict --debug
StandardError=null
Restart=on-abort
CapabilityBoundingSet=CAP_SYS_ADMIN
ProtectSystem=true
ProtectHome=true
PrivateTmp=true
RestrictAddressFamilies=AF_NETLINK AF_UNIX
NoNewPrivileges=true
User=root
[Install]
WantedBy=multi-user.target
Alias=dbus-org.freedesktop.ModemManager1.service
@@ -1,6 +1,7 @@
[main]
plugins=ifupdown,keyfile
dns=systemd-resolved
dns=default
hostname-mode=none
[ifupdown]
managed=true
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
/usr/comma/boot.sh
mkdir -p /run
install -m000 /dev/null /run/runit.stopit
install -m000 /dev/null /run/runit.reboot
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
mkdir -p /run/runit/supervise /run/runit/sv /run/runit/services /usr/comma/runit/services
rm -rf /run/runit/services
mkdir -p /run/runit/services
for service in /usr/comma/runit/services/*; do
[ -d "$service" ] || continue
name="${service##*/}"
mkdir -p "/run/runit/services/$name"
ln -sf "$service/run" "/run/runit/services/$name/run"
[ -e "$service/finish" ] && ln -sf "$service/finish" "/run/runit/services/$name/finish"
done
exec runsvdir -P /run/runit/services 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'
+15
View File
@@ -0,0 +1,15 @@
#!/bin/bash
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
printf '<6>runit-shutdown[%d]: stopping services\n' "$$" >/dev/kmsg 2>/dev/null || true
sv -w 5 force-stop /run/runit/services/* 2>/dev/kmsg || true
sv exit /run/runit/services/* 2>/dev/kmsg || true
/usr/comma/lte/lte.sh stop >/tmp/lte-stop.log 2>&1 || true
if [ -d /config/usb_gadget/g1 ]; then
echo "" >/config/usb_gadget/g1/UDC 2>/dev/null || true
fi
sync
-37
View File
@@ -1,37 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See logind.conf(5) for details.
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
RemoveIPC=no
#InhibitorsMax=8192
#SessionsMax=8192
@@ -1,3 +0,0 @@
[Unit]
After=network.target
Wants=network.target
@@ -1,17 +0,0 @@
# Copyright (c) 2018 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
[Unit]
Description=CNSS Daemon Service
SourcePath=/etc/initscripts/start_cnss_daemon
[Service]
Restart=no
RemainAfterExit=yes
ExecStart=/etc/initscripts/start_cnss_daemon start
ExecStop=/etc/initscripts/start_cnss_daemon stop
[Install]
WantedBy=multi-user.target
@@ -1 +0,0 @@
/etc/systemd/system/cnss-daemon.service
@@ -1 +0,0 @@
/etc/systemd/system/pdmapper.service
@@ -1 +0,0 @@
/etc/systemd/system/qseecomd.path
@@ -1,19 +0,0 @@
# Copyright (c) 2018 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
[Unit]
Description=SS-Services Service
SourcePath=/etc/initscripts/start_pdmappersvc
After=init_sys_mss.service
Requires=init_sys_mss.service
[Service]
Restart=no
RemainAfterExit=yes
ExecStart=/etc/initscripts/start_pdmappersvc start
ExecStop=/etc/initscripts/start_pdmappersvc stop
[Install]
WantedBy=multi-user.target
@@ -1,2 +0,0 @@
[Service]
MemoryMax=50M
@@ -1,16 +0,0 @@
# Copyright (c) 2018 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
[Unit]
Description=Path watching for qseecomd.service
DefaultDependencies=no
Conflicts=shutdown.target
Before=paths.target shutdown.target systemd-udev-trigger.service
[Path]
PathModified=/dev/qseecom
[Install]
WantedBy=multi-user.target
@@ -1,19 +0,0 @@
# Copyright (c) 2017 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
[Unit]
Description=Qseecomd Service
SourcePath=/etc/initscripts/qseecomd
After=leprop.service
Requires=leprop.service
[Service]
Restart=no
RemainAfterExit=yes
ExecStart=/etc/initscripts/qseecomd start
ExecStop=/etc/initscripts/qseecomd stop
[Install]
WantedBy=multi-user.target
@@ -1,2 +0,0 @@
[Unit]
After=fs_setup.service
@@ -1,3 +0,0 @@
[Time]
# 10s is limited by timesyncd rate limit
ConnectionRetrySec=10
@@ -1,5 +0,0 @@
[Path]
PathModified=/data/params/d/AdbEnabled
[Install]
WantedBy=multi-user.target
@@ -1,10 +0,0 @@
[Unit]
Description=ADB param watcher
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/comma/set_adb.sh
[Install]
WantedBy=multi-user.target
@@ -1,6 +0,0 @@
[Unit]
Description=adbd Service
[Service]
User=root
ExecStart=/usr/comma/adbd
@@ -1,10 +0,0 @@
[Unit]
After=local-fs.target
[Service]
Type=oneshot
User=comma
ExecStart=/usr/comma/debug.py
[Install]
WantedBy=multi-user.target
@@ -1,16 +0,0 @@
[Unit]
#After=
[Service]
#Type=simple
#User=comma
Type=oneshot
Restart=no
# exit if connected to 5V
ExecStartPre=/bin/bash -c "if [ $(cat /sys/class/hwmon/hwmon1/in1_input) -le 6500 ]; then echo 'Exiting, connected to 5V'; exit 1; fi"
ExecStart=/bin/bash -c "source /etc/profile && /usr/comma/tests/test_sounds.py"
[Install]
WantedBy=multi-user.target
@@ -1,16 +0,0 @@
[Unit]
Description=Publish comma SSH service via Avahi
After=avahi-daemon.service network.target
Requires=avahi-daemon.service
Wants=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=/usr/comma/avahi-publish-service.sh
Restart=always
RestartSec=5
User=comma
[Install]
WantedBy=multi-user.target
@@ -1,9 +0,0 @@
[Unit]
Description=Limit display brightness with uptime
[Service]
Restart=on-failure
ExecStart=/usr/local/venv/bin/python -u /usr/comma/brightnessd.py
[Install]
WantedBy=multi-user.target
@@ -1,16 +0,0 @@
[Unit]
After=local-fs.target
[Service]
Type=oneshot
RemainAfterExit=true
User=comma
ExecStart=/bin/bash -c "/usr/bin/tmux new-session -s comma -d /usr/comma/comma.sh"
# TODO: send SIGTERM first, then kill after a timeout
ExecStop=/bin/bash -c "/usr/bin/tmux kill-session -t comma"
TimeoutStopSec=1
LimitRTPRIO=100
LimitNICE=-10
[Install]
WantedBy=multi-user.target
@@ -1,11 +0,0 @@
[Unit]
Description=Setup rootfs
Before=local-fs.target
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/usr/comma/fs_setup.sh
[Install]
WantedBy=multi-user.target
@@ -1,9 +0,0 @@
[Unit]
Description=GPIO export
[Service]
Type=oneshot
ExecStart=/usr/comma/gpio.sh
[Install]
WantedBy=multi-user.target
@@ -1,10 +0,0 @@
[Unit]
Description=QCOM init
After=sysinit.target
[Service]
Type=oneshot
ExecStart=/usr/comma/init.qcom.sh
[Install]
WantedBy=multi-user.target
@@ -1,39 +0,0 @@
# Copyright (c) 2016, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Unit]
SourcePath=/sbin/init_mss
Description=Modem Init Service
After=firmware-mount.service
[Service]
Restart=on-failure
RemainAfterExit=yes
ExecStart=/sbin/init_mss
[Install]
WantedBy=multi-user.target
@@ -1,12 +0,0 @@
[Unit]
SourcePath=/sbin/leprop-service
Description=leprop Service
After=systemrw-build.prop.service
Before=persist-prop.service
[Service]
Restart=always
ExecStart=/sbin/leprop-service
[Install]
WantedBy=multi-user.target
@@ -1,41 +0,0 @@
# Copyright (c) 2016, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
[Unit]
SourcePath=/etc/initscripts/logd
Description=logd Service
[Service]
Type=forking
Restart=no
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/initscripts/logd start
ExecStop=/etc/initscripts/logd stop
@@ -1,11 +0,0 @@
[Unit]
Description=Hourly rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)
[Timer]
Unit=logrotate.service
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
@@ -1,13 +0,0 @@
[Unit]
Description=LTE
After=gpio.service network.target
[Service]
Restart=no
KillSignal=SIGKILL
RemainAfterExit=true
ExecStart=/usr/comma/lte/lte.sh start
ExecStop=/usr/comma/lte/lte.sh stop
[Install]
WantedBy=multi-user.target
@@ -1,18 +0,0 @@
[Unit]
Description=Magic
[Service]
Type=simple
User=comma
PermissionsStartOnly=true
ExecStartPre=/bin/bash -c "chgrp gpu /dev/ion /dev/kgsl-3d0"
ExecStartPre=/bin/bash -c "chmod 660 /dev/ion /dev/kgsl-3d0"
ExecStartPre=/bin/bash -c "mkdir -p /data/misc/display || true"
ExecStartPre=/bin/bash -c "echo 0 > /data/misc/display/sdm_dbg_cfg.txt || true"
ExecStartPre=/bin/bash -c "echo 0 > /data/misc/display/gbm_dbg_cfg.txt || true"
ExecStart=/bin/bash -c "source /etc/profile && /usr/local/venv/bin/python -u /usr/comma/magic.py"
[Install]
WantedBy=multi-user.target
@@ -1 +0,0 @@
/lib/systemd/system/init_sys_mss.service
@@ -1 +0,0 @@
/lib/systemd/system/leprop.service
@@ -1 +0,0 @@
/lib/systemd/system/logd.service
@@ -1 +0,0 @@
/lib/systemd/system/persist-prop.service
@@ -1 +0,0 @@
/lib/systemd/system/rmt_storage.service
@@ -1,11 +0,0 @@
[Unit]
Description=persist-prop service
After=leprop.service
Requires=leprop.service
[Service]
ExecStart=/sbin/persist-prop.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
@@ -1,10 +0,0 @@
[Unit]
After=multi-user.target
[Service]
Restart=always
ExecCondition=/bin/bash -c 'grep -q -E "tici|tizi" /sys/firmware/devicetree/base/model'
ExecStart=/usr/local/venv/bin/python -u /usr/comma/power_drop_monitor.py
[Install]
WantedBy=multi-user.target
@@ -1,9 +0,0 @@
[Unit]
After=multi-user.target
[Service]
Restart=always
ExecStart=/usr/local/venv/bin/python -u /usr/comma/power_monitor.py
[Install]
WantedBy=multi-user.target
@@ -1,12 +0,0 @@
[Unit]
Description= Remote Storage Service
SourcePath=/sbin/rmt_storage
Before=init_sys_mss.service
[Service]
Restart=always
ExecStartPre=/bin/bash -c "/usr/comma/wait_for_file.sh /dev/block/bootdevice/by-name/modemst1; /usr/comma/wait_for_file.sh /dev/block/bootdevice/by-name/modemst2; /usr/comma/wait_for_file.sh /dev/block/bootdevice/by-name/fsc; /usr/comma/wait_for_file.sh /dev/block/bootdevice/by-name/fsg"
ExecStart=/sbin/rmt_storage
[Install]
WantedBy=multi-user.target
@@ -1,11 +0,0 @@
[Unit]
After=multi-user.target
Description=Set screen calibration
[Service]
Type=oneshot
User=root
ExecStart=/usr/comma/screen_calibration.py
[Install]
WantedBy=multi-user.target
@@ -1,4 +0,0 @@
# With Ubuntu 24.04 (systemd 255) and 4.9 Kernel, the console is not properly
# hung up when the serial getty for ttyMSM0 is started. Force hangup with this.
[Service]
ExecStartPre=/bin/stty -F /dev/ttyMSM0 hupcl
@@ -1,12 +0,0 @@
[Unit]
Description=Sets the hostname to the device's serial number
After=basic.target
Before=network.target
[Service]
User=root
Type=oneshot
ExecStart=/usr/comma/set-hostname.sh
[Install]
WantedBy=multi-user.target
@@ -1,9 +0,0 @@
[Unit]
Description=Sound
[Service]
Type=oneshot
ExecStart=/usr/comma/sound/sound_init.sh
[Install]
WantedBy=multi-user.target
@@ -1,5 +0,0 @@
[Path]
PathModified=/data/params/d/SshEnabled
[Install]
WantedBy=multi-user.target
@@ -1,10 +0,0 @@
[Unit]
Description=SSH param watcher
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/comma/set_ssh.sh
[Install]
WantedBy=multi-user.target
@@ -1,5 +0,0 @@
[Service]
ExecStartPre=
ExecStartPre=/bin/mkdir -p /data/etc/ssh/
ExecStartPre=/usr/bin/ssh-keygen -A -f /data
ExecStartPre=/usr/sbin/sshd -t
@@ -1,9 +0,0 @@
[Unit]
After=multi-user.target
[Service]
Restart=always
ExecStart=/usr/local/venv/bin/python -u /usr/comma/varwatch.py
[Install]
WantedBy=multi-user.target
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
exec -a "${0##*/}" /usr/lib/runit/shutdown "$@"
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
if [ "$$" = "1" ]; then
exec /sbin/runit "$@"
fi
exec /lib/runit/runit-init "$@"
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
exec -a "${0##*/}" /usr/lib/runit/shutdown "$@"
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
exec -a "${0##*/}" /usr/lib/runit/shutdown "$@"
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
exec -a "${0##*/}" /usr/lib/runit/shutdown "$@"
+332
View File
@@ -0,0 +1,332 @@
#!/bin/bash
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
BOOTSH_RUN=/run/bootsh
log() {
local ts="?"
if [ -r /proc/uptime ]; then
ts="$(cut -d' ' -f1 /proc/uptime)"
fi
printf 'boot.sh[%d]: %s %s\n' "$$" "$ts" "$*" >/dev/console 2>/dev/null || true
printf '<6>boot.sh[%d]: %s %s\n' "$$" "$ts" "$*" >/dev/kmsg 2>/dev/null || true
}
mount_one() {
local type="$1"
local what="$2"
local where="$3"
shift 3
mkdir -p "$where"
mountpoint -q "$where" && return 0
mount -t "$type" "$@" "$what" "$where" 2>/dev/kmsg
}
wait_block() {
local dev="$1"
local i
for i in $(seq 1 150); do
[ -b "$dev" ] && return 0
sleep 0.01
done
log "timeout waiting for $dev"
return 1
}
mount_block() {
local what="$1"
local where="$2"
local type="$3"
local opts="$4"
wait_block "$what" || return 1
mkdir -p "$where"
mountpoint -q "$where" && return 0
log "mount $where"
mount -t "$type" -o "$opts" "$what" "$where" 2>/dev/kmsg
}
boost_early() {
echo performance >/sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
echo performance >/sys/devices/system/cpu/cpufreq/policy4/scaling_governor 2>/dev/null || true
echo 2649600 >/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq 2>/dev/null || true
echo 2649600 >/sys/devices/system/cpu/cpufreq/policy4/scaling_max_freq 2>/dev/null || true
echo 2649600 >/sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq 2>/dev/null || true
echo 2649600 >/sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq 2>/dev/null || true
}
set_graphics_perms() {
chgrp gpu /dev/adsprpc-smd /dev/ion /dev/kgsl-3d0 /dev/dri/* 2>/dev/null || true
chmod 660 /dev/adsprpc-smd /dev/kgsl-3d0 /dev/dri/* 2>/dev/null || true
chmod 664 /dev/ion 2>/dev/null || true
}
set_device_perms() {
set_graphics_perms
chgrp gpio /dev/i2c-* 2>/dev/null || true
chmod 660 /dev/i2c-* 2>/dev/null || true
chmod 666 /dev/spidev* 2>/dev/null || true
chmod 666 /dev/input/* 2>/dev/null || true
chgrp disk /dev/sd* 2>/dev/null || true
chmod 660 /dev/sd* 2>/dev/null || true
chgrp gpio /sys/class/gpio/gpio*/direction /sys/class/gpio/gpio*/value 2>/dev/null || true
chmod 660 /sys/class/gpio/gpio*/direction /sys/class/gpio/gpio*/value 2>/dev/null || true
chgrp video /sys/class/backlight/panel0-backlight/brightness \
/sys/class/backlight/panel0-backlight/bl_power \
/sys/devices/platform/soc/soc:qcom,dsi-display@0/max_brightness_percent 2>/dev/null || true
chmod g+w /sys/class/backlight/panel0-backlight/brightness \
/sys/class/backlight/panel0-backlight/bl_power \
/sys/devices/platform/soc/soc:qcom,dsi-display@0/max_brightness_percent 2>/dev/null || true
}
create_tmpfiles() {
mkdir -p /var/crash /var/tmp /var/lib/dpkg /var/lib/logrotate \
/var/spool/cron/atjobs /var/cache/pollinate
chmod 1777 /var/tmp 2>/dev/null || true
touch /var/lib/dpkg/lock-frontend /var/lib/dpkg/status 2>/dev/null || true
}
permission_loop() {
local i
for i in $(seq 1 200); do
set_device_perms
sleep 0.025
done
}
mount_data() {
log "mount /data"
mkdir -p /data
mountpoint -q /data && return 0
wait_block /dev/sda12 || return 1
mount -t ext4 -o discard,noatime,nodiratime,nosuid,nodev /dev/sda12 /data 2>/dev/kmsg
}
data_late_setup() {
mkdir -p /data/etc/netplan /data/etc/NetworkManager/system-connections /data/ssh /data/tmp /data/media
chown comma:comma /data /data/media /data/ssh /data/tmp 2>/dev/null || true
touch /data/etc/timezone /data/etc/localtime 2>/dev/null || true
if [ ! -d /data/persist ] && [ -d /system/persist ]; then
cp -a /system/persist /data/ 2>/dev/null || true
fi
}
mount_early_state() {
mount_one tmpfs tmpfs /var -o rw,nosuid,nodev,size=128M,mode=755 || true
mount_one tmpfs tmpfs /tmp -o rw,nosuid,nodev,size=150M,mode=1777 || true
mount_one tmpfs tmpfs /run -o nosuid,nodev,mode=755,size=714M,nr_inodes=819200 || true
mount_one tmpfs tmpfs /rwtmp -o rw,nosuid,nodev,size=100M,mode=1777 || true
mkdir -p "$BOOTSH_RUN" /var/tmp/xdg /var/log /run/sudo /run/user/1000 /rwtmp/home_work /rwtmp/home_upper
chmod 1777 /var/tmp
chown comma:comma /var/tmp/xdg /run/user/1000 2>/dev/null || true
chmod 700 /run/user/1000 2>/dev/null || true
mount_one tmpfs tmpfs /var/log -o rw,nosuid,nodev,size=128M,mode=755 || true
chown root:syslog /var/log 2>/dev/null || true
chmod 775 /var/log 2>/dev/null || true
create_tmpfiles
mountpoint -q /home || mount -t overlay overlay \
-o lowerdir=/usr/default/home,upperdir=/rwtmp/home_upper,workdir=/rwtmp/home_work \
/home 2>/dev/kmsg || true
}
mount_core() {
mount_one proc proc /proc || true
mount_one sysfs sysfs /sys || true
mount_one devtmpfs devtmpfs /dev -o mode=755 || true
mkdir -p /dev/pts /dev/shm /sys/fs/cgroup /sys/fs/pstore /sys/fs/bpf /sys/kernel/debug /sys/kernel/tracing /sys/kernel/config
mount_one devpts devpts /dev/pts -o gid=5,mode=620,ptmxmode=000 || true
mount_one tmpfs tmpfs /dev/shm -o nosuid,nodev,size=1800M || true
}
mount_firmware() {
mount_block /dev/sde4 /firmware vfat ro || true
mount_block /dev/sde9 /dsp ext4 ro || true
log "firmware mounts done"
}
mount_deferred() {
mount_one tmpfs tmpfs /run/lock -o nosuid,nodev,noexec,size=5M || true
mount_one cgroup2 cgroup2 /sys/fs/cgroup -o nosuid,nodev,noexec || true
mount_one pstore pstore /sys/fs/pstore -o nosuid,nodev,noexec || true
mount_one bpf bpf /sys/fs/bpf -o nosuid,nodev,noexec || true
mount_one debugfs debugfs /sys/kernel/debug -o nosuid,nodev,noexec || true
mount_one tracefs tracefs /sys/kernel/tracing -o nosuid,nodev,noexec || true
mount_one configfs configfs /sys/kernel/config || true
ln -sf /sys/kernel/tracing /sys/kernel/debug/tracing 2>/dev/null || true
mount_firmware
mount_block /dev/sda2 /persist squashfs ro,nosuid,nodev,noexec || true
mount_block /dev/sda10 /systemrw ext4 relatime,data=ordered,noauto_da_alloc,discard,noexec,nodev || true
mount_block /dev/sda11 /cache ext4 relatime,data=ordered,noauto_da_alloc,discard,noexec,nodev,nosuid || true
chown -R comma:comma /cache 2>/dev/null || true
log "deferred mounts done"
}
setup_input_links() {
local event i name
for i in $(seq 1 250); do
for event in /sys/class/input/event*; do
[ -r "$event/device/name" ] || continue
name="$(cat "$event/device/name" 2>/dev/null || true)"
if [ "$name" = "fts_ts" ]; then
mkdir -p /dev/input/by-path
ln -sf "../$(basename "$event")" /dev/input/by-path/platform-894000.i2c-event
log "input link ready"
return 0
fi
done
sleep 0.02
done
log "timeout waiting for touch input"
}
setup_gpios() {
local p i pins
pins="30 49 134 41 50 116 124 34 33 32 52 1264"
for p in $pins; do
if [ "$p" = "41" ] && grep -q "comma tici" /sys/firmware/devicetree/base/model 2>/dev/null; then
continue
fi
[ -d "/sys/class/gpio/gpio$p" ] || echo "$p" >/sys/class/gpio/export 2>/dev/null || true
done
for p in $pins; do
if [ "$p" = "41" ] && grep -q "comma tici" /sys/firmware/devicetree/base/model 2>/dev/null; then
continue
fi
for i in $(seq 1 20); do
[ -d "/sys/class/gpio/gpio$p" ] && break
sleep 0.005
done
done
echo out >/sys/class/gpio/gpio30/direction 2>/dev/null || true
echo 1 >/sys/class/gpio/gpio30/value 2>/dev/null || true
set_device_perms
touch "$BOOTSH_RUN/gpio-ready"
log "gpio ready"
}
make_bootdevice_links() {
local dev i key part uevent value
mkdir -p /dev/block/bootdevice/by-name /dev/disk/by-partlabel
for i in $(seq 1 150); do
for uevent in /sys/class/block/sd*[0-9]*/uevent; do
[ -e "$uevent" ] || continue
dev="${uevent#/sys/class/block/}"
dev="${dev%/uevent}"
part=""
while IFS='=' read -r key value; do
if [ "$key" = "PARTNAME" ]; then
part="$value"
break
fi
done <"$uevent"
if [ -n "$part" ]; then
ln -sf "/dev/$dev" "/dev/block/bootdevice/by-name/$part"
ln -sf "/dev/$dev" "/dev/disk/by-partlabel/$part"
fi
done
[ -e /dev/block/bootdevice/by-name/modemst1 ] && break
sleep 0.02
done
log "bootdevice links ready"
}
qcom_early() {
local f
for f in /sys/bus/msm_subsys/devices/subsys*/restart_level; do
[ -e "$f" ] && echo related >"$f" 2>/dev/null || true
done
boost_early
[ -e /sys/kernel/boot_wlan/boot_wlan ] && echo 1 >/sys/kernel/boot_wlan/boot_wlan 2>/dev/null || true
[ -x /usr/bin/irsc_util ] && /usr/bin/irsc_util /etc/sec_config >/tmp/irsc_util.log 2>&1 || true
[ -e /sys/kernel/boot_cdsp/boot ] && echo 1 >/sys/kernel/boot_cdsp/boot 2>/dev/null || true
[ -e /dev/ipa ] && echo 1 >/dev/ipa 2>/dev/null || true
log "qcom early done"
}
start_magic() {
log "start magic"
/usr/comma/start-magic.sh >/tmp/magic.log 2>&1 &
touch "$BOOTSH_RUN/magic-started"
}
start_comma() {
log "start comma"
/usr/comma/start-comma.sh >/tmp/comma-start.log 2>&1
log "comma launched"
}
start_sound() {
log "start sound"
/usr/comma/sound/start-sound.sh --boot >/tmp/sound.log 2>&1 &
}
start_serial_shell() {
[ -c /dev/ttyMSM0 ] || return 0
setsid /bin/bash -l </dev/ttyMSM0 >/dev/ttyMSM0 2>&1 &
}
log "pid1 start"
mount_core
start_serial_shell
boost_early
mount_data &
data_mount_pid=$!
mount_early_state
/usr/comma/set-hostname.sh >/tmp/set-hostname.log 2>&1 || true
permission_loop &
setup_gpios &
gpio_pid=$!
setup_input_links &
start_magic
wait "$data_mount_pid" || true
data_late_setup
touch "$BOOTSH_RUN/data-ready"
start_comma
mount_deferred &
mount_deferred_pid=$!
qcom_early &
qcom_early_pid=$!
make_bootdevice_links &
bootdevice_pid=$!
wait "$mount_deferred_pid" || true
touch "$BOOTSH_RUN/fs-setup-done"
/usr/comma/debug.py >/tmp/agnos-debug.log 2>&1 || true
/usr/comma/screen_calibration.py >/tmp/screen-calibration.log 2>&1 || true
start_sound
wait "$qcom_early_pid" || true
wait "$bootdevice_pid" || true
wait "$gpio_pid" || true
set_device_perms
log "boot path done"
exit 0
+15 -2
View File
@@ -27,6 +27,11 @@ mount_fs() {
local type="$3"
local options="$4"
if mountpoint -q "$where"; then
log "$where already mounted"
return 0
fi
if [[ "$what" == /dev/* ]] && ! wait_for_block "$what"; then
failed=1
return 1
@@ -45,6 +50,11 @@ mount_fs() {
log "start"
if [[ -e /run/bootsh/fs-setup-done ]]; then
log "already done by boot.sh"
exit 0
fi
failed=0
mount_fs /dev/sde9 /dsp ext4 ro
mount_fs /dev/sde4 /firmware vfat ro
@@ -59,8 +69,11 @@ mount_fs tmpfs /rwtmp tmpfs rw,nosuid,nodev,size=100M,mode=1777
# Ensure the symlinks in the read only rootfs are
# backed by real files and directories on userdata.
# tmpfiles
systemd-tmpfiles --create /usr/comma/tmpfiles.conf
# Runtime files normally created by tmpfiles.d.
mkdir -p /var/crash /var/tmp /var/lib/dpkg /var/lib/logrotate \
/var/spool/cron/atjobs /var/cache/pollinate
chmod 1777 /var/tmp
touch /var/lib/dpkg/lock-frontend /var/lib/dpkg/status
# /var/log/ tmpfs
mkdir -p /var/log/
+27 -11
View File
@@ -2,7 +2,7 @@
import os, socket, struct, subprocess, threading, time
from array import array
import pyray as rl
rl = None
UPDATER_PATH = "/usr/comma/updater"
WESTON_RUNTIME_DIR = "/var/tmp/weston"
@@ -13,6 +13,14 @@ DRM_DEVICE = "/dev/dri/card0"
BACKLIGHT_POWER = "/sys/class/backlight/panel0-backlight/bl_power"
BACKGROUND = "/usr/comma/bg.jpg"
def log(msg):
print(f"MAGIC {time.monotonic():.2f} {msg}", flush=True)
try:
with open("/dev/kmsg", "w") as f:
f.write(f"magic: {time.monotonic():.2f} {msg}\n")
except Exception:
pass
# This is needed to keep the old updater working. Updater used to be stored in
# openpilot directly instead of in AGNOS. This will intercept the old updater
# trying to use a Weston socket and start our own.
@@ -83,6 +91,8 @@ def handle_client(client, drm_master):
pass
def main():
global rl
threading.Thread(target=updater_weston, daemon=True).start()
while True:
@@ -94,6 +104,21 @@ def main():
time.sleep(0.1)
os.environ['DRM_FD'] = str(drm_master)
try:
os.unlink(SOCK_PATH)
except FileNotFoundError:
pass
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(SOCK_PATH)
server.settimeout(0.1)
server.listen(1)
log("drmfd socket ready")
import pyray as rl
log("raylib imported")
while not os.access(BACKLIGHT_POWER, os.W_OK):
time.sleep(0.1)
@@ -105,16 +130,7 @@ def main():
pos = rl.Vector2((rl.get_screen_width() - tex.width)/2.0, (rl.get_screen_height() - tex.height)/2.0)
rl.unload_image(img)
show_background(tex, pos)
try:
os.unlink(SOCK_PATH)
except FileNotFoundError:
pass
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(SOCK_PATH)
server.settimeout(0.1)
server.listen(1)
log("splash drawn")
clients = set()
need_background = False
@@ -95,7 +95,7 @@ def perform_controlled_shutdown():
# Kill services that draw a lot of power
printk("Killing services")
subprocess.call(["/usr/bin/systemctl", "kill", "--signal=9", "comma"])
subprocess.call(["/usr/comma/shims/systemctl", "kill", "--signal=9", "comma"])
set_screen_power(False)
printk("Halt")
@@ -122,4 +122,3 @@ if __name__ == '__main__':
perform_controlled_shutdown()
except Exception:
pass
+46
View File
@@ -0,0 +1,46 @@
#!/bin/bash
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
log() {
local name ts
name="${SVDIR##*/}"
[ -n "$name" ] || name="${0##*/}"
ts="?"
[ -r /proc/uptime ] && ts="$(cut -d' ' -f1 /proc/uptime)"
printf '<6>runit-%s[%d]: %s %s\n' "$name" "$$" "$ts" "$*" >/dev/kmsg 2>/dev/null || true
printf 'runit-%s[%d]: %s %s\n' "$name" "$$" "$ts" "$*"
}
wait_path() {
local path="$1"
local i
for i in $(seq 1 300); do
[ -e "$path" ] && return 0
sleep 0.1
done
log "timeout waiting for $path"
return 1
}
wait_dbus() {
wait_path /run/dbus/system_bus_socket
}
param_enabled() {
local path="$1"
[ -f "$path" ] && [ "$(cat "$path" 2>/dev/null)" = "1" ]
}
run_as_comma() {
exec env \
HOME=/home/comma \
LOGNAME=comma \
SHELL=/bin/bash \
TERM=xterm-256color \
USER=comma \
XDG_RUNTIME_DIR=/var/tmp/xdg \
PATH="$PATH" \
setpriv --reuid=1000 --regid=1000 --init-groups "$@"
}
@@ -0,0 +1,13 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
last=""
while true; do
cur="$(cat /data/params/d/AdbEnabled 2>/dev/null || true)"
if [ "$cur" != "$last" ]; then
last="$cur"
log "AdbEnabled changed to ${cur:-unset}"
sv restart /run/runit/services/adbd 2>/dev/null || true
fi
sleep 2
done
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
if ! param_enabled /data/params/d/AdbEnabled; then
log "disabled"
[ -d /config/usb_gadget/g1 ] && echo "" >/config/usb_gadget/g1/UDC 2>/dev/null || true
while sleep 3600; do :; done
fi
mkdir -p /config /dev/usb-ffs/adb
mountpoint -q /config || mount -t configfs none /config
mkdir -p /config/usb_gadget/g1
cd /config/usb_gadget/g1
echo "" > UDC 2>/dev/null || true
mkdir -p strings/0x409 configs/c.1/strings/0x409 functions/ncm.0 functions/ffs.adb
echo 0x04D8 > idVendor
echo 0x1234 > idProduct
sed -n 's/^.*androidboot.serialno=\([^ ]*\).*$/\1/p' /proc/cmdline > strings/0x409/serialnumber
echo comma.ai > strings/0x409/manufacturer
echo "Linux USB Gadget" > strings/0x409/product
echo 250 > configs/c.1/MaxPower
echo "NCM+ADB" > configs/c.1/strings/0x409/configuration
mountpoint -q /dev/usb-ffs/adb || mount -t functionfs adb /dev/usb-ffs/adb
rm -f configs/c.1/ncm.0 configs/c.1/ffs.adb
ln -sf functions/ncm.0 configs/c.1/ncm.0
ln -sf functions/ffs.adb configs/c.1/ffs.adb
command -v setprop >/dev/null && setprop service.adb.tcp.port -1 2>/dev/null || true
/usr/comma/adbd &
pid=$!
sleep 2
for _ in $(seq 1 40); do
echo a600000.dwc3 > UDC 2>/tmp/adbd-udc.err || true
[ "$(cat UDC 2>/dev/null)" = "a600000.dwc3" ] && break
sleep 0.25
done
wait "$pid"
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_dbus || true
exec /usr/sbin/avahi-daemon -s
@@ -0,0 +1,6 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_dbus || true
sleep 1
run_as_comma /usr/comma/avahi-publish-service.sh
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
exec /usr/local/venv/bin/python -u /usr/comma/brightnessd.py
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
if ! pgrep -x cnss_daemon >/dev/null 2>&1; then
if [ -e /tmp/cnss_daemon.log ]; then
/usr/sbin/cnss_daemon -d -f /tmp/cnss_daemon.log
else
/usr/sbin/cnss_daemon
fi
fi
while sleep 5; do
pgrep -x cnss_daemon >/dev/null 2>&1 || exit 1
done
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /run/bootsh/data-ready || true
exec /usr/comma/start-comma.sh --monitor
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
mkdir -p /run/dbus /var/lib/dbus
rm -f /run/dbus/pid
exec dbus-daemon --system --nofork --nopidfile
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /firmware/verinfo/ver_info.txt || true
exec /sbin/init_mss
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /systemrw || true
exec /sbin/leprop-service
+15
View File
@@ -0,0 +1,15 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
mkdir -p /dev/socket
chmod 777 /dev/socket
echo 600 >/proc/sys/net/unix/max_dgram_qlen 2>/dev/null || true
/sbin/logd &
pid=$!
for _ in $(seq 1 50); do
[ -S /dev/socket/logd ] && break
sleep 0.02
done
chmod 0666 /dev/socket/logd /dev/socket/logdr 2>/dev/null || true
chmod 0222 /dev/socket/logdw 2>/dev/null || true
wait "$pid"
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
mkdir -p /var/lib/logrotate
while true; do
/usr/sbin/logrotate /etc/logrotate.conf || true
sleep 3600
done
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /run/bootsh/gpio-ready || true
/usr/comma/lte/lte.sh start
log "started"
trap '/usr/comma/lte/lte.sh stop' TERM INT
while sleep 3600; do :; done
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
exec /usr/comma/start-magic.sh --monitor
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_dbus || true
wait_path /run/bootsh/fs-setup-done || true
exec /usr/sbin/ModemManager --filter-policy=strict --debug
@@ -0,0 +1,6 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_dbus || true
mkdir -p /run/NetworkManager /var/lib/NetworkManager
exec /usr/sbin/NetworkManager --no-daemon
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
for _ in $(seq 1 100); do
pgrep -x init_mss >/dev/null 2>&1 && break
sleep 0.1
done
exec /usr/bin/pdmappersvc
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
for _ in $(seq 1 100); do
pgrep -x leprop-service >/dev/null 2>&1 && break
sleep 0.1
done
/sbin/persist-prop.sh
log "done"
while sleep 3600; do :; done
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_dbus || true
if ! pgrep -u polkitd -x polkitd >/dev/null 2>&1; then
setpriv --reuid=polkitd --regid=polkitd --init-groups /usr/lib/polkit-1/polkitd --no-debug
fi
while sleep 5; do
pgrep -u polkitd -x polkitd >/dev/null 2>&1 || exit 1
done
@@ -0,0 +1,8 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
if ! grep -q -E "tici|tizi" /sys/firmware/devicetree/base/model 2>/dev/null; then
log "not supported on this hardware"
while sleep 3600; do :; done
fi
exec /usr/local/venv/bin/python -u /usr/comma/power_drop_monitor.py
@@ -0,0 +1,4 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
exec /usr/local/venv/bin/python -u /usr/comma/power_monitor.py
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /dev/qseecom || true
chmod 0666 /dev/qseecom 2>/dev/null || true
chmod 0664 /dev/ion /dev/sde20 2>/dev/null || true
exec /usr/bin/qseecomd
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
wait_path /dev/block/bootdevice/by-name/modemst1 || true
wait_path /dev/block/bootdevice/by-name/modemst2 || true
wait_path /dev/block/bootdevice/by-name/fsc || true
wait_path /dev/block/bootdevice/by-name/fsg || true
exec /sbin/rmt_storage
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
mkdir -p /var/log /var/spool/rsyslog
chown root:syslog /var/log 2>/dev/null || true
chmod 775 /var/log 2>/dev/null || true
chown syslog:adm /var/spool/rsyslog 2>/dev/null || true
exec /usr/sbin/rsyslogd -n -iNONE
@@ -0,0 +1,13 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
last=""
while true; do
cur="$(cat /data/params/d/SshEnabled 2>/dev/null || true)"
if [ "$cur" != "$last" ]; then
last="$cur"
log "SshEnabled changed to ${cur:-unset}"
sv restart /run/runit/services/ssh 2>/dev/null || true
fi
sleep 2
done
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
if ! param_enabled /data/params/d/SshEnabled; then
log "disabled"
while sleep 3600; do :; done
fi
mkdir -p /data/etc/ssh /run/sshd
ssh-keygen -A -f /data
/usr/sbin/sshd -t
exec /usr/sbin/sshd -D
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
exec 2>&1
. /usr/comma/runit/common.sh
exec /usr/local/venv/bin/python -u /usr/comma/varwatch.py
+2 -2
View File
@@ -61,12 +61,12 @@ if [ -f "$ADB_PARAM" ] && [ "$(< $ADB_PARAM)" == "1" ]; then
echo "Enabling ADB"
setup
systemctl start adbd
/usr/comma/shims/systemctl start adbd
sleep 1 # adbd does some setup before we can enable the gadget
start
else
echo "Disabling ADB"
systemctl stop adbd
/usr/comma/shims/systemctl stop adbd
stop
fi
+2 -2
View File
@@ -3,8 +3,8 @@
SSH_PARAM="/data/params/d/SshEnabled"
if [ -f "$SSH_PARAM" ] && [ "$(< $SSH_PARAM)" == "1" ]; then
echo "Enabling SSH"
systemctl start ssh
/usr/comma/shims/systemctl start ssh
else
echo "Disabling SSH"
systemctl stop ssh
/usr/comma/shims/systemctl stop ssh
fi
+95
View File
@@ -0,0 +1,95 @@
#!/bin/bash
set -u
while [[ "${1:-}" == --* ]]; do
case "$1" in
--root=*|--system|--user|--global|--preset-mode=*|--no-reload|--no-ask-password|--quiet)
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
service_dir() {
local name="${1%.service}"
case "$name" in
magic) name=magic ;;
comma) name=comma ;;
ssh|sshd) name=ssh ;;
adbd) name=adbd ;;
esac
if [ -d "/run/runit/services/$name" ]; then
printf '/run/runit/services/%s\n' "$name"
else
printf '/usr/comma/runit/services/%s\n' "$name"
fi
}
case "${1:-}" in
"")
exit 0
;;
daemon-reload|daemon-reexec|preset|preset-all|enable|disable|reenable|mask|unmask|try-reload-or-restart|reload)
exit 0
;;
esac
if [ "${1:-}" = "is-enabled" ]; then
exit 1
fi
if [ "${1:-}" = "daemon-reload" ]; then
exit 0
fi
if [ "${1:-}" = "is-active" ] && [ "${2:-}" = "--quiet" ]; then
case "${3:-}" in
magic|magic.service)
pgrep -u comma -f "/usr/comma/magic.py" >/dev/null 2>&1 && [ -S /tmp/drmfd.sock ] && exit 0
exit 3
;;
comma|comma.service)
/usr/bin/tmux has-session -t comma >/dev/null 2>&1 && exit 0
exit 3
;;
esac
sv status "$(service_dir "${3:-}")" >/dev/null 2>&1 && exit 0
exit 3
fi
case "${1:-}" in
start)
exec sv up "$(service_dir "${2:-}")"
;;
stop)
exec sv down "$(service_dir "${2:-}")"
;;
restart)
exec sv restart "$(service_dir "${2:-}")"
;;
kill)
signal=TERM
shift
if [[ "${1:-}" == --signal=* ]]; then
signal="${1#--signal=}"
shift
fi
name="${1:-}"
if [ "${name%.service}" = "comma" ]; then
pkill "-$signal" -f "/usr/comma/comma.sh" 2>/dev/null || true
pkill "-$signal" -f "tmux new-session -s comma" 2>/dev/null || true
exit 0
fi
exec sv force-stop "$(service_dir "$name")"
;;
esac
echo "systemctl shim: unsupported command: $*" >&2
exit 1
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
set -u
BOOTSH_RUN=/run/bootsh
if [ "${1:-}" = "--boot" ]; then
mkdir -p "$BOOTSH_RUN"
rm -f "$BOOTSH_RUN/sound-ready" "$BOOTSH_RUN/sound-failed"
touch "$BOOTSH_RUN/sound-started"
if /usr/comma/sound/sound_init.sh; then
touch "$BOOTSH_RUN/sound-ready"
exit 0
fi
touch "$BOOTSH_RUN/sound-failed"
exit 1
fi
if [ -e "$BOOTSH_RUN/sound-started" ]; then
while pgrep -f "/usr/comma/sound/sound_init.sh" >/dev/null 2>&1; do
sleep 0.1
done
[ -e "$BOOTSH_RUN/sound-ready" ] && exit 0
exit 1
fi
exec /usr/comma/sound/sound_init.sh
+69
View File
@@ -0,0 +1,69 @@
#!/bin/bash
set -u
PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
log() {
local ts="?"
if [ -r /proc/uptime ]; then
ts="$(cut -d' ' -f1 /proc/uptime)"
fi
if [ -w /dev/kmsg ]; then
printf '<6>start-comma[%d]: %s %s\n' "$$" "$ts" "$*" >/dev/kmsg 2>/dev/null || true
fi
}
set_limits() {
ulimit -Hr 100 2>/dev/null || true
ulimit -Sr 100 2>/dev/null || true
ulimit -He 30 2>/dev/null || true
ulimit -Se 30 2>/dev/null || true
}
start_session() {
local agnos_version
agnos_version="$(cat /VERSION 2>/dev/null || true)"
export AGNOS_VERSION="$agnos_version"
export HOME=/home/comma
export LOGNAME=comma
export SHELL=/bin/bash
export TERM=xterm-256color
export USER=comma
export XDG_RUNTIME_DIR=/var/tmp/xdg
if /usr/bin/tmux has-session -t comma >/dev/null 2>&1; then
log "tmux session already running"
return 0
fi
/usr/bin/tmux new-session -s comma -d "/bin/bash -lc 'exec /bin/bash /usr/comma/comma.sh >>/tmp/comma.log 2>&1'"
log "tmux session started"
}
monitor_session() {
while /usr/bin/tmux has-session -t comma >/dev/null 2>&1; do
sleep 5
done
}
set_limits
if [ "$(id -u)" = "0" ]; then
exec env \
HOME=/home/comma \
LOGNAME=comma \
SHELL=/bin/bash \
TERM=xterm-256color \
USER=comma \
XDG_RUNTIME_DIR=/var/tmp/xdg \
PATH="$PATH" \
setpriv --reuid=1000 --regid=1000 --init-groups "$0" "$@"
fi
start_session
if [ "${1:-}" = "--monitor" ]; then
monitor_session
fi

Some files were not shown because too many files have changed in this diff Show More