From 9d4350c6f8d8f6f94c0bf9322abf31b4b8f678fa Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 2 May 2026 19:08:26 -0700 Subject: [PATCH] Migrate boot to runit --- Dockerfile.agnos | 121 ++++++- TESTING.md | 4 +- build_system.sh | 4 +- scripts/bootchart.sh | 7 +- scripts/mdma.py | 10 +- scripts/setup-on-device.sh | 25 +- userspace/base_setup.sh | 11 +- userspace/files/ModemManager.service | 22 -- .../etc/NetworkManager/NetworkManager.conf | 3 +- userspace/root/etc/runit/1 | 10 + userspace/root/etc/runit/2 | 18 + userspace/root/etc/runit/3 | 15 + userspace/root/etc/systemd/logind.conf | 37 -- .../avahi-daemon.service.d/override.conf | 3 - .../etc/systemd/system/cnss-daemon.service | 17 - .../cnss-daemon.service | 1 - .../multi-user.target.wants/pdmapper.service | 1 - .../multi-user.target.wants/qseecomd.path | 1 - .../root/etc/systemd/system/pdmapper.service | 19 - .../system/polkit.service.d/override.conf | 2 - .../root/etc/systemd/system/qseecomd.path | 16 - .../root/etc/systemd/system/qseecomd.service | 19 - .../override.conf | 2 - userspace/root/etc/systemd/timesyncd.conf | 3 - .../lib/systemd/system/adb-param-watcher.path | 5 - .../systemd/system/adb-param-watcher.service | 10 - .../root/lib/systemd/system/adbd.service | 6 - .../lib/systemd/system/agnos-debug.service | 10 - .../lib/systemd/system/agnos-tests.service | 16 - .../systemd/system/avahi-ssh-publish.service | 16 - .../lib/systemd/system/brightnessd.service | 9 - .../root/lib/systemd/system/comma.service | 16 - .../root/lib/systemd/system/fs_setup.service | 11 - .../root/lib/systemd/system/gpio.service | 9 - .../root/lib/systemd/system/init-qcom.service | 10 - .../lib/systemd/system/init_sys_mss.service | 39 -- .../root/lib/systemd/system/leprop.service | 12 - .../root/lib/systemd/system/logd.service | 41 --- .../lib/systemd/system/logrotate-hourly.timer | 11 - userspace/root/lib/systemd/system/lte.service | 13 - .../root/lib/systemd/system/magic.service | 18 - .../init_sys_mss.service | 1 - .../multi-user.target.wants/leprop.service | 1 - .../multi-user.target.wants/logd.service | 1 - .../persist-prop.service | 1 - .../rmt_storage.service | 1 - .../lib/systemd/system/persist-prop.service | 11 - .../systemd/system/power_drop_monitor.service | 10 - .../lib/systemd/system/power_monitor.service | 9 - .../lib/systemd/system/rmt_storage.service | 12 - .../systemd/system/screen_calibration.service | 11 - .../serial-getty@ttyMSM0_override.conf | 4 - .../systemd/system/serial-hostname.service | 12 - .../root/lib/systemd/system/sound.service | 9 - .../lib/systemd/system/ssh-param-watcher.path | 5 - .../systemd/system/ssh-param-watcher.service | 10 - .../system/ssh.service.d/override.conf | 5 - .../root/lib/systemd/system/varwatch.service | 9 - userspace/root/sbin/halt | 2 + userspace/root/sbin/init | 7 + userspace/root/sbin/poweroff | 2 + userspace/root/sbin/reboot | 2 + userspace/root/sbin/shutdown | 2 + userspace/root/usr/comma/boot.sh | 332 ++++++++++++++++++ userspace/root/usr/comma/fs_setup.sh | 17 +- userspace/root/usr/comma/magic.py | 38 +- .../root/usr/comma/power_drop_monitor.py | 3 +- userspace/root/usr/comma/runit/common.sh | 46 +++ .../runit/services/adb-param-watcher/run | 13 + .../root/usr/comma/runit/services/adbd/run | 37 ++ .../usr/comma/runit/services/avahi-daemon/run | 5 + .../runit/services/avahi-ssh-publish/run | 6 + .../usr/comma/runit/services/brightnessd/run | 4 + .../usr/comma/runit/services/cnss-daemon/run | 13 + .../root/usr/comma/runit/services/comma/run | 5 + .../root/usr/comma/runit/services/dbus/run | 6 + .../usr/comma/runit/services/init-mss/run | 5 + .../root/usr/comma/runit/services/leprop/run | 5 + .../root/usr/comma/runit/services/logd/run | 15 + .../usr/comma/runit/services/logrotate/run | 10 + .../root/usr/comma/runit/services/lte/run | 8 + .../root/usr/comma/runit/services/magic/run | 4 + .../usr/comma/runit/services/modemmanager/run | 6 + .../comma/runit/services/networkmanager/run | 6 + .../usr/comma/runit/services/pdmapper/run | 8 + .../usr/comma/runit/services/persist-prop/run | 10 + .../root/usr/comma/runit/services/polkit/run | 11 + .../runit/services/power-drop-monitor/run | 8 + .../comma/runit/services/power-monitor/run | 4 + .../usr/comma/runit/services/qseecomd/run | 7 + .../usr/comma/runit/services/rmt-storage/run | 8 + .../root/usr/comma/runit/services/rsyslog/run | 8 + .../runit/services/ssh-param-watcher/run | 13 + .../root/usr/comma/runit/services/ssh/run | 11 + .../usr/comma/runit/services/varwatch/run | 4 + userspace/root/usr/comma/set_adb.sh | 4 +- userspace/root/usr/comma/set_ssh.sh | 4 +- userspace/root/usr/comma/shims/systemctl | 95 +++++ userspace/root/usr/comma/sound/start-sound.sh | 30 ++ userspace/root/usr/comma/start-comma.sh | 69 ++++ userspace/root/usr/comma/start-magic.sh | 81 +++++ .../root/usr/comma/tests/analyze-boot-time.py | 28 +- userspace/root/usr/comma/tests/test_agnos.py | 23 +- userspace/root/usr/comma/tests/test_sounds.py | 20 +- userspace/root/usr/comma/tests/varspam.sh | 8 +- userspace/root/usr/comma/tmpfiles.conf | 23 -- userspace/services.sh | 69 ---- 107 files changed, 1181 insertions(+), 699 deletions(-) delete mode 100644 userspace/files/ModemManager.service create mode 100755 userspace/root/etc/runit/1 create mode 100755 userspace/root/etc/runit/2 create mode 100755 userspace/root/etc/runit/3 delete mode 100644 userspace/root/etc/systemd/logind.conf delete mode 100644 userspace/root/etc/systemd/system/avahi-daemon.service.d/override.conf delete mode 100644 userspace/root/etc/systemd/system/cnss-daemon.service delete mode 120000 userspace/root/etc/systemd/system/multi-user.target.wants/cnss-daemon.service delete mode 120000 userspace/root/etc/systemd/system/multi-user.target.wants/pdmapper.service delete mode 120000 userspace/root/etc/systemd/system/multi-user.target.wants/qseecomd.path delete mode 100644 userspace/root/etc/systemd/system/pdmapper.service delete mode 100644 userspace/root/etc/systemd/system/polkit.service.d/override.conf delete mode 100644 userspace/root/etc/systemd/system/qseecomd.path delete mode 100644 userspace/root/etc/systemd/system/qseecomd.service delete mode 100644 userspace/root/etc/systemd/system/systemd-random-seed.service.d/override.conf delete mode 100644 userspace/root/etc/systemd/timesyncd.conf delete mode 100644 userspace/root/lib/systemd/system/adb-param-watcher.path delete mode 100644 userspace/root/lib/systemd/system/adb-param-watcher.service delete mode 100644 userspace/root/lib/systemd/system/adbd.service delete mode 100644 userspace/root/lib/systemd/system/agnos-debug.service delete mode 100644 userspace/root/lib/systemd/system/agnos-tests.service delete mode 100644 userspace/root/lib/systemd/system/avahi-ssh-publish.service delete mode 100644 userspace/root/lib/systemd/system/brightnessd.service delete mode 100644 userspace/root/lib/systemd/system/comma.service delete mode 100644 userspace/root/lib/systemd/system/fs_setup.service delete mode 100644 userspace/root/lib/systemd/system/gpio.service delete mode 100644 userspace/root/lib/systemd/system/init-qcom.service delete mode 100644 userspace/root/lib/systemd/system/init_sys_mss.service delete mode 100644 userspace/root/lib/systemd/system/leprop.service delete mode 100644 userspace/root/lib/systemd/system/logd.service delete mode 100644 userspace/root/lib/systemd/system/logrotate-hourly.timer delete mode 100644 userspace/root/lib/systemd/system/lte.service delete mode 100644 userspace/root/lib/systemd/system/magic.service delete mode 120000 userspace/root/lib/systemd/system/multi-user.target.wants/init_sys_mss.service delete mode 120000 userspace/root/lib/systemd/system/multi-user.target.wants/leprop.service delete mode 120000 userspace/root/lib/systemd/system/multi-user.target.wants/logd.service delete mode 120000 userspace/root/lib/systemd/system/multi-user.target.wants/persist-prop.service delete mode 120000 userspace/root/lib/systemd/system/multi-user.target.wants/rmt_storage.service delete mode 100644 userspace/root/lib/systemd/system/persist-prop.service delete mode 100644 userspace/root/lib/systemd/system/power_drop_monitor.service delete mode 100644 userspace/root/lib/systemd/system/power_monitor.service delete mode 100644 userspace/root/lib/systemd/system/rmt_storage.service delete mode 100644 userspace/root/lib/systemd/system/screen_calibration.service delete mode 100644 userspace/root/lib/systemd/system/serial-getty@ttyMSM0.service.d/serial-getty@ttyMSM0_override.conf delete mode 100644 userspace/root/lib/systemd/system/serial-hostname.service delete mode 100644 userspace/root/lib/systemd/system/sound.service delete mode 100644 userspace/root/lib/systemd/system/ssh-param-watcher.path delete mode 100644 userspace/root/lib/systemd/system/ssh-param-watcher.service delete mode 100644 userspace/root/lib/systemd/system/ssh.service.d/override.conf delete mode 100644 userspace/root/lib/systemd/system/varwatch.service create mode 100755 userspace/root/sbin/halt create mode 100755 userspace/root/sbin/init create mode 100755 userspace/root/sbin/poweroff create mode 100755 userspace/root/sbin/reboot create mode 100755 userspace/root/sbin/shutdown create mode 100755 userspace/root/usr/comma/boot.sh create mode 100755 userspace/root/usr/comma/runit/common.sh create mode 100755 userspace/root/usr/comma/runit/services/adb-param-watcher/run create mode 100755 userspace/root/usr/comma/runit/services/adbd/run create mode 100755 userspace/root/usr/comma/runit/services/avahi-daemon/run create mode 100755 userspace/root/usr/comma/runit/services/avahi-ssh-publish/run create mode 100755 userspace/root/usr/comma/runit/services/brightnessd/run create mode 100755 userspace/root/usr/comma/runit/services/cnss-daemon/run create mode 100755 userspace/root/usr/comma/runit/services/comma/run create mode 100755 userspace/root/usr/comma/runit/services/dbus/run create mode 100755 userspace/root/usr/comma/runit/services/init-mss/run create mode 100755 userspace/root/usr/comma/runit/services/leprop/run create mode 100755 userspace/root/usr/comma/runit/services/logd/run create mode 100755 userspace/root/usr/comma/runit/services/logrotate/run create mode 100755 userspace/root/usr/comma/runit/services/lte/run create mode 100755 userspace/root/usr/comma/runit/services/magic/run create mode 100755 userspace/root/usr/comma/runit/services/modemmanager/run create mode 100755 userspace/root/usr/comma/runit/services/networkmanager/run create mode 100755 userspace/root/usr/comma/runit/services/pdmapper/run create mode 100755 userspace/root/usr/comma/runit/services/persist-prop/run create mode 100755 userspace/root/usr/comma/runit/services/polkit/run create mode 100755 userspace/root/usr/comma/runit/services/power-drop-monitor/run create mode 100755 userspace/root/usr/comma/runit/services/power-monitor/run create mode 100755 userspace/root/usr/comma/runit/services/qseecomd/run create mode 100755 userspace/root/usr/comma/runit/services/rmt-storage/run create mode 100755 userspace/root/usr/comma/runit/services/rsyslog/run create mode 100755 userspace/root/usr/comma/runit/services/ssh-param-watcher/run create mode 100755 userspace/root/usr/comma/runit/services/ssh/run create mode 100755 userspace/root/usr/comma/runit/services/varwatch/run create mode 100755 userspace/root/usr/comma/shims/systemctl create mode 100755 userspace/root/usr/comma/sound/start-sound.sh create mode 100755 userspace/root/usr/comma/start-comma.sh create mode 100755 userspace/root/usr/comma/start-magic.sh delete mode 100644 userspace/root/usr/comma/tmpfiles.conf delete mode 100755 userspace/services.sh diff --git a/Dockerfile.agnos b/Dockerfile.agnos index 2e55d1c..c0916c1 100644 --- a/Dockerfile.agnos +++ b/Dockerfile.agnos @@ -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 diff --git a/TESTING.md b/TESTING.md index fe3b708..f2cade3 100644 --- a/TESTING.md +++ b/TESTING.md @@ -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 diff --git a/build_system.sh b/build_system.sh index 514abaf..bbfc475 100755 --- a/build_system.sh +++ b/build_system.sh @@ -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" diff --git a/scripts/bootchart.sh b/scripts/bootchart.sh index 100526b..2f9ad35 100755 --- a/scripts/bootchart.sh +++ b/scripts/bootchart.sh @@ -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 diff --git a/scripts/mdma.py b/scripts/mdma.py index d7369da..2e636a9 100755 --- a/scripts/mdma.py +++ b/scripts/mdma.py @@ -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__": diff --git a/scripts/setup-on-device.sh b/scripts/setup-on-device.sh index c69e561..e729901 100755 --- a/scripts/setup-on-device.sh +++ b/scripts/setup-on-device.sh @@ -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 / diff --git a/userspace/base_setup.sh b/userspace/base_setup.sh index b6c1e03..206a3d6 100755 --- a/userspace/base_setup.sh +++ b/userspace/base_setup.sh @@ -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 diff --git a/userspace/files/ModemManager.service b/userspace/files/ModemManager.service deleted file mode 100644 index 8884248..0000000 --- a/userspace/files/ModemManager.service +++ /dev/null @@ -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 diff --git a/userspace/root/etc/NetworkManager/NetworkManager.conf b/userspace/root/etc/NetworkManager/NetworkManager.conf index f2b5d98..b829ce1 100644 --- a/userspace/root/etc/NetworkManager/NetworkManager.conf +++ b/userspace/root/etc/NetworkManager/NetworkManager.conf @@ -1,6 +1,7 @@ [main] plugins=ifupdown,keyfile -dns=systemd-resolved +dns=default +hostname-mode=none [ifupdown] managed=true diff --git a/userspace/root/etc/runit/1 b/userspace/root/etc/runit/1 new file mode 100755 index 0000000..8d606e5 --- /dev/null +++ b/userspace/root/etc/runit/1 @@ -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 diff --git a/userspace/root/etc/runit/2 b/userspace/root/etc/runit/2 new file mode 100755 index 0000000..0626bfa --- /dev/null +++ b/userspace/root/etc/runit/2 @@ -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: ...........................................................................................................................................................................................................................................................................................................................................................................................................' diff --git a/userspace/root/etc/runit/3 b/userspace/root/etc/runit/3 new file mode 100755 index 0000000..e30da78 --- /dev/null +++ b/userspace/root/etc/runit/3 @@ -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 diff --git a/userspace/root/etc/systemd/logind.conf b/userspace/root/etc/systemd/logind.conf deleted file mode 100644 index 6bc799c..0000000 --- a/userspace/root/etc/systemd/logind.conf +++ /dev/null @@ -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 diff --git a/userspace/root/etc/systemd/system/avahi-daemon.service.d/override.conf b/userspace/root/etc/systemd/system/avahi-daemon.service.d/override.conf deleted file mode 100644 index 308da73..0000000 --- a/userspace/root/etc/systemd/system/avahi-daemon.service.d/override.conf +++ /dev/null @@ -1,3 +0,0 @@ -[Unit] -After=network.target -Wants=network.target \ No newline at end of file diff --git a/userspace/root/etc/systemd/system/cnss-daemon.service b/userspace/root/etc/systemd/system/cnss-daemon.service deleted file mode 100644 index 81fe956..0000000 --- a/userspace/root/etc/systemd/system/cnss-daemon.service +++ /dev/null @@ -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 diff --git a/userspace/root/etc/systemd/system/multi-user.target.wants/cnss-daemon.service b/userspace/root/etc/systemd/system/multi-user.target.wants/cnss-daemon.service deleted file mode 120000 index e4c15ca..0000000 --- a/userspace/root/etc/systemd/system/multi-user.target.wants/cnss-daemon.service +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/cnss-daemon.service \ No newline at end of file diff --git a/userspace/root/etc/systemd/system/multi-user.target.wants/pdmapper.service b/userspace/root/etc/systemd/system/multi-user.target.wants/pdmapper.service deleted file mode 120000 index a41928f..0000000 --- a/userspace/root/etc/systemd/system/multi-user.target.wants/pdmapper.service +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/pdmapper.service \ No newline at end of file diff --git a/userspace/root/etc/systemd/system/multi-user.target.wants/qseecomd.path b/userspace/root/etc/systemd/system/multi-user.target.wants/qseecomd.path deleted file mode 120000 index 7a49553..0000000 --- a/userspace/root/etc/systemd/system/multi-user.target.wants/qseecomd.path +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/qseecomd.path \ No newline at end of file diff --git a/userspace/root/etc/systemd/system/pdmapper.service b/userspace/root/etc/systemd/system/pdmapper.service deleted file mode 100644 index 299aad8..0000000 --- a/userspace/root/etc/systemd/system/pdmapper.service +++ /dev/null @@ -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 diff --git a/userspace/root/etc/systemd/system/polkit.service.d/override.conf b/userspace/root/etc/systemd/system/polkit.service.d/override.conf deleted file mode 100644 index 512c319..0000000 --- a/userspace/root/etc/systemd/system/polkit.service.d/override.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Service] -MemoryMax=50M diff --git a/userspace/root/etc/systemd/system/qseecomd.path b/userspace/root/etc/systemd/system/qseecomd.path deleted file mode 100644 index 84a09ca..0000000 --- a/userspace/root/etc/systemd/system/qseecomd.path +++ /dev/null @@ -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 diff --git a/userspace/root/etc/systemd/system/qseecomd.service b/userspace/root/etc/systemd/system/qseecomd.service deleted file mode 100644 index 90f4182..0000000 --- a/userspace/root/etc/systemd/system/qseecomd.service +++ /dev/null @@ -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 diff --git a/userspace/root/etc/systemd/system/systemd-random-seed.service.d/override.conf b/userspace/root/etc/systemd/system/systemd-random-seed.service.d/override.conf deleted file mode 100644 index b36d511..0000000 --- a/userspace/root/etc/systemd/system/systemd-random-seed.service.d/override.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Unit] -After=fs_setup.service diff --git a/userspace/root/etc/systemd/timesyncd.conf b/userspace/root/etc/systemd/timesyncd.conf deleted file mode 100644 index b0cbf16..0000000 --- a/userspace/root/etc/systemd/timesyncd.conf +++ /dev/null @@ -1,3 +0,0 @@ -[Time] -# 10s is limited by timesyncd rate limit -ConnectionRetrySec=10 diff --git a/userspace/root/lib/systemd/system/adb-param-watcher.path b/userspace/root/lib/systemd/system/adb-param-watcher.path deleted file mode 100644 index ca7327f..0000000 --- a/userspace/root/lib/systemd/system/adb-param-watcher.path +++ /dev/null @@ -1,5 +0,0 @@ -[Path] -PathModified=/data/params/d/AdbEnabled - -[Install] -WantedBy=multi-user.target diff --git a/userspace/root/lib/systemd/system/adb-param-watcher.service b/userspace/root/lib/systemd/system/adb-param-watcher.service deleted file mode 100644 index e71306b..0000000 --- a/userspace/root/lib/systemd/system/adb-param-watcher.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/adbd.service b/userspace/root/lib/systemd/system/adbd.service deleted file mode 100644 index e4c4100..0000000 --- a/userspace/root/lib/systemd/system/adbd.service +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=adbd Service - -[Service] -User=root -ExecStart=/usr/comma/adbd diff --git a/userspace/root/lib/systemd/system/agnos-debug.service b/userspace/root/lib/systemd/system/agnos-debug.service deleted file mode 100644 index 8dbb59e..0000000 --- a/userspace/root/lib/systemd/system/agnos-debug.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -After=local-fs.target - -[Service] -Type=oneshot -User=comma -ExecStart=/usr/comma/debug.py - -[Install] -WantedBy=multi-user.target diff --git a/userspace/root/lib/systemd/system/agnos-tests.service b/userspace/root/lib/systemd/system/agnos-tests.service deleted file mode 100644 index e925dec..0000000 --- a/userspace/root/lib/systemd/system/agnos-tests.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/avahi-ssh-publish.service b/userspace/root/lib/systemd/system/avahi-ssh-publish.service deleted file mode 100644 index 108563d..0000000 --- a/userspace/root/lib/systemd/system/avahi-ssh-publish.service +++ /dev/null @@ -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 \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/brightnessd.service b/userspace/root/lib/systemd/system/brightnessd.service deleted file mode 100644 index 18beace..0000000 --- a/userspace/root/lib/systemd/system/brightnessd.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/comma.service b/userspace/root/lib/systemd/system/comma.service deleted file mode 100644 index e2e3cce..0000000 --- a/userspace/root/lib/systemd/system/comma.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/fs_setup.service b/userspace/root/lib/systemd/system/fs_setup.service deleted file mode 100644 index 9b68650..0000000 --- a/userspace/root/lib/systemd/system/fs_setup.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/gpio.service b/userspace/root/lib/systemd/system/gpio.service deleted file mode 100644 index cb214ec..0000000 --- a/userspace/root/lib/systemd/system/gpio.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=GPIO export - -[Service] -Type=oneshot -ExecStart=/usr/comma/gpio.sh - -[Install] -WantedBy=multi-user.target diff --git a/userspace/root/lib/systemd/system/init-qcom.service b/userspace/root/lib/systemd/system/init-qcom.service deleted file mode 100644 index 430fe95..0000000 --- a/userspace/root/lib/systemd/system/init-qcom.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/init_sys_mss.service b/userspace/root/lib/systemd/system/init_sys_mss.service deleted file mode 100644 index f5b670f..0000000 --- a/userspace/root/lib/systemd/system/init_sys_mss.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/leprop.service b/userspace/root/lib/systemd/system/leprop.service deleted file mode 100644 index ad3d788..0000000 --- a/userspace/root/lib/systemd/system/leprop.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/logd.service b/userspace/root/lib/systemd/system/logd.service deleted file mode 100644 index da6657d..0000000 --- a/userspace/root/lib/systemd/system/logd.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/logrotate-hourly.timer b/userspace/root/lib/systemd/system/logrotate-hourly.timer deleted file mode 100644 index 2955428..0000000 --- a/userspace/root/lib/systemd/system/logrotate-hourly.timer +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/lte.service b/userspace/root/lib/systemd/system/lte.service deleted file mode 100644 index b1805d9..0000000 --- a/userspace/root/lib/systemd/system/lte.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/magic.service b/userspace/root/lib/systemd/system/magic.service deleted file mode 100644 index 4136749..0000000 --- a/userspace/root/lib/systemd/system/magic.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/multi-user.target.wants/init_sys_mss.service b/userspace/root/lib/systemd/system/multi-user.target.wants/init_sys_mss.service deleted file mode 120000 index 6b3e25b..0000000 --- a/userspace/root/lib/systemd/system/multi-user.target.wants/init_sys_mss.service +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/init_sys_mss.service \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/multi-user.target.wants/leprop.service b/userspace/root/lib/systemd/system/multi-user.target.wants/leprop.service deleted file mode 120000 index 4be59b3..0000000 --- a/userspace/root/lib/systemd/system/multi-user.target.wants/leprop.service +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/leprop.service \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/multi-user.target.wants/logd.service b/userspace/root/lib/systemd/system/multi-user.target.wants/logd.service deleted file mode 120000 index 0c5ddb2..0000000 --- a/userspace/root/lib/systemd/system/multi-user.target.wants/logd.service +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/logd.service \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/multi-user.target.wants/persist-prop.service b/userspace/root/lib/systemd/system/multi-user.target.wants/persist-prop.service deleted file mode 120000 index 0ee7b30..0000000 --- a/userspace/root/lib/systemd/system/multi-user.target.wants/persist-prop.service +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/persist-prop.service \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/multi-user.target.wants/rmt_storage.service b/userspace/root/lib/systemd/system/multi-user.target.wants/rmt_storage.service deleted file mode 120000 index 777636e..0000000 --- a/userspace/root/lib/systemd/system/multi-user.target.wants/rmt_storage.service +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/rmt_storage.service \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/persist-prop.service b/userspace/root/lib/systemd/system/persist-prop.service deleted file mode 100644 index 0654527..0000000 --- a/userspace/root/lib/systemd/system/persist-prop.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/power_drop_monitor.service b/userspace/root/lib/systemd/system/power_drop_monitor.service deleted file mode 100644 index 45a0a6b..0000000 --- a/userspace/root/lib/systemd/system/power_drop_monitor.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/power_monitor.service b/userspace/root/lib/systemd/system/power_monitor.service deleted file mode 100644 index 3b57ee0..0000000 --- a/userspace/root/lib/systemd/system/power_monitor.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/rmt_storage.service b/userspace/root/lib/systemd/system/rmt_storage.service deleted file mode 100644 index 32896d2..0000000 --- a/userspace/root/lib/systemd/system/rmt_storage.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/screen_calibration.service b/userspace/root/lib/systemd/system/screen_calibration.service deleted file mode 100644 index c78705b..0000000 --- a/userspace/root/lib/systemd/system/screen_calibration.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/serial-getty@ttyMSM0.service.d/serial-getty@ttyMSM0_override.conf b/userspace/root/lib/systemd/system/serial-getty@ttyMSM0.service.d/serial-getty@ttyMSM0_override.conf deleted file mode 100644 index 479c998..0000000 --- a/userspace/root/lib/systemd/system/serial-getty@ttyMSM0.service.d/serial-getty@ttyMSM0_override.conf +++ /dev/null @@ -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 \ No newline at end of file diff --git a/userspace/root/lib/systemd/system/serial-hostname.service b/userspace/root/lib/systemd/system/serial-hostname.service deleted file mode 100644 index 29f309d..0000000 --- a/userspace/root/lib/systemd/system/serial-hostname.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/sound.service b/userspace/root/lib/systemd/system/sound.service deleted file mode 100644 index fffb2ad..0000000 --- a/userspace/root/lib/systemd/system/sound.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Sound - -[Service] -Type=oneshot -ExecStart=/usr/comma/sound/sound_init.sh - -[Install] -WantedBy=multi-user.target diff --git a/userspace/root/lib/systemd/system/ssh-param-watcher.path b/userspace/root/lib/systemd/system/ssh-param-watcher.path deleted file mode 100644 index c7a2130..0000000 --- a/userspace/root/lib/systemd/system/ssh-param-watcher.path +++ /dev/null @@ -1,5 +0,0 @@ -[Path] -PathModified=/data/params/d/SshEnabled - -[Install] -WantedBy=multi-user.target diff --git a/userspace/root/lib/systemd/system/ssh-param-watcher.service b/userspace/root/lib/systemd/system/ssh-param-watcher.service deleted file mode 100644 index 08d09d5..0000000 --- a/userspace/root/lib/systemd/system/ssh-param-watcher.service +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/ssh.service.d/override.conf b/userspace/root/lib/systemd/system/ssh.service.d/override.conf deleted file mode 100644 index 27849fb..0000000 --- a/userspace/root/lib/systemd/system/ssh.service.d/override.conf +++ /dev/null @@ -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 diff --git a/userspace/root/lib/systemd/system/varwatch.service b/userspace/root/lib/systemd/system/varwatch.service deleted file mode 100644 index 1e306d6..0000000 --- a/userspace/root/lib/systemd/system/varwatch.service +++ /dev/null @@ -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 diff --git a/userspace/root/sbin/halt b/userspace/root/sbin/halt new file mode 100755 index 0000000..1d2ff10 --- /dev/null +++ b/userspace/root/sbin/halt @@ -0,0 +1,2 @@ +#!/bin/bash +exec -a "${0##*/}" /usr/lib/runit/shutdown "$@" diff --git a/userspace/root/sbin/init b/userspace/root/sbin/init new file mode 100755 index 0000000..42eaa0a --- /dev/null +++ b/userspace/root/sbin/init @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ "$$" = "1" ]; then + exec /sbin/runit "$@" +fi + +exec /lib/runit/runit-init "$@" diff --git a/userspace/root/sbin/poweroff b/userspace/root/sbin/poweroff new file mode 100755 index 0000000..1d2ff10 --- /dev/null +++ b/userspace/root/sbin/poweroff @@ -0,0 +1,2 @@ +#!/bin/bash +exec -a "${0##*/}" /usr/lib/runit/shutdown "$@" diff --git a/userspace/root/sbin/reboot b/userspace/root/sbin/reboot new file mode 100755 index 0000000..1d2ff10 --- /dev/null +++ b/userspace/root/sbin/reboot @@ -0,0 +1,2 @@ +#!/bin/bash +exec -a "${0##*/}" /usr/lib/runit/shutdown "$@" diff --git a/userspace/root/sbin/shutdown b/userspace/root/sbin/shutdown new file mode 100755 index 0000000..1d2ff10 --- /dev/null +++ b/userspace/root/sbin/shutdown @@ -0,0 +1,2 @@ +#!/bin/bash +exec -a "${0##*/}" /usr/lib/runit/shutdown "$@" diff --git a/userspace/root/usr/comma/boot.sh b/userspace/root/usr/comma/boot.sh new file mode 100755 index 0000000..cb189c3 --- /dev/null +++ b/userspace/root/usr/comma/boot.sh @@ -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 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 diff --git a/userspace/root/usr/comma/fs_setup.sh b/userspace/root/usr/comma/fs_setup.sh index d912b10..d17159b 100755 --- a/userspace/root/usr/comma/fs_setup.sh +++ b/userspace/root/usr/comma/fs_setup.sh @@ -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/ diff --git a/userspace/root/usr/comma/magic.py b/userspace/root/usr/comma/magic.py index 9c905f2..a3496f5 100755 --- a/userspace/root/usr/comma/magic.py +++ b/userspace/root/usr/comma/magic.py @@ -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 diff --git a/userspace/root/usr/comma/power_drop_monitor.py b/userspace/root/usr/comma/power_drop_monitor.py index c4c3d45..4c213fa 100755 --- a/userspace/root/usr/comma/power_drop_monitor.py +++ b/userspace/root/usr/comma/power_drop_monitor.py @@ -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 - diff --git a/userspace/root/usr/comma/runit/common.sh b/userspace/root/usr/comma/runit/common.sh new file mode 100755 index 0000000..74696ba --- /dev/null +++ b/userspace/root/usr/comma/runit/common.sh @@ -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 "$@" +} diff --git a/userspace/root/usr/comma/runit/services/adb-param-watcher/run b/userspace/root/usr/comma/runit/services/adb-param-watcher/run new file mode 100755 index 0000000..15b1388 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/adb-param-watcher/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/adbd/run b/userspace/root/usr/comma/runit/services/adbd/run new file mode 100755 index 0000000..ce6513c --- /dev/null +++ b/userspace/root/usr/comma/runit/services/adbd/run @@ -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" diff --git a/userspace/root/usr/comma/runit/services/avahi-daemon/run b/userspace/root/usr/comma/runit/services/avahi-daemon/run new file mode 100755 index 0000000..86b1f87 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/avahi-daemon/run @@ -0,0 +1,5 @@ +#!/bin/bash +exec 2>&1 +. /usr/comma/runit/common.sh +wait_dbus || true +exec /usr/sbin/avahi-daemon -s diff --git a/userspace/root/usr/comma/runit/services/avahi-ssh-publish/run b/userspace/root/usr/comma/runit/services/avahi-ssh-publish/run new file mode 100755 index 0000000..275007c --- /dev/null +++ b/userspace/root/usr/comma/runit/services/avahi-ssh-publish/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/brightnessd/run b/userspace/root/usr/comma/runit/services/brightnessd/run new file mode 100755 index 0000000..6bbb677 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/brightnessd/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/cnss-daemon/run b/userspace/root/usr/comma/runit/services/cnss-daemon/run new file mode 100755 index 0000000..7b1f162 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/cnss-daemon/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/comma/run b/userspace/root/usr/comma/runit/services/comma/run new file mode 100755 index 0000000..25dd92c --- /dev/null +++ b/userspace/root/usr/comma/runit/services/comma/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/dbus/run b/userspace/root/usr/comma/runit/services/dbus/run new file mode 100755 index 0000000..fc54153 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/dbus/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/init-mss/run b/userspace/root/usr/comma/runit/services/init-mss/run new file mode 100755 index 0000000..ce9a50f --- /dev/null +++ b/userspace/root/usr/comma/runit/services/init-mss/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/leprop/run b/userspace/root/usr/comma/runit/services/leprop/run new file mode 100755 index 0000000..9e192ca --- /dev/null +++ b/userspace/root/usr/comma/runit/services/leprop/run @@ -0,0 +1,5 @@ +#!/bin/bash +exec 2>&1 +. /usr/comma/runit/common.sh +wait_path /systemrw || true +exec /sbin/leprop-service diff --git a/userspace/root/usr/comma/runit/services/logd/run b/userspace/root/usr/comma/runit/services/logd/run new file mode 100755 index 0000000..3b0956c --- /dev/null +++ b/userspace/root/usr/comma/runit/services/logd/run @@ -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" diff --git a/userspace/root/usr/comma/runit/services/logrotate/run b/userspace/root/usr/comma/runit/services/logrotate/run new file mode 100755 index 0000000..f6e0844 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/logrotate/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/lte/run b/userspace/root/usr/comma/runit/services/lte/run new file mode 100755 index 0000000..d36e5b0 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/lte/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/magic/run b/userspace/root/usr/comma/runit/services/magic/run new file mode 100755 index 0000000..eec92ea --- /dev/null +++ b/userspace/root/usr/comma/runit/services/magic/run @@ -0,0 +1,4 @@ +#!/bin/bash +exec 2>&1 +. /usr/comma/runit/common.sh +exec /usr/comma/start-magic.sh --monitor diff --git a/userspace/root/usr/comma/runit/services/modemmanager/run b/userspace/root/usr/comma/runit/services/modemmanager/run new file mode 100755 index 0000000..a21e6e8 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/modemmanager/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/networkmanager/run b/userspace/root/usr/comma/runit/services/networkmanager/run new file mode 100755 index 0000000..7b9a36d --- /dev/null +++ b/userspace/root/usr/comma/runit/services/networkmanager/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/pdmapper/run b/userspace/root/usr/comma/runit/services/pdmapper/run new file mode 100755 index 0000000..bc6572b --- /dev/null +++ b/userspace/root/usr/comma/runit/services/pdmapper/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/persist-prop/run b/userspace/root/usr/comma/runit/services/persist-prop/run new file mode 100755 index 0000000..9830464 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/persist-prop/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/polkit/run b/userspace/root/usr/comma/runit/services/polkit/run new file mode 100755 index 0000000..99d7664 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/polkit/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/power-drop-monitor/run b/userspace/root/usr/comma/runit/services/power-drop-monitor/run new file mode 100755 index 0000000..fd6ab9d --- /dev/null +++ b/userspace/root/usr/comma/runit/services/power-drop-monitor/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/power-monitor/run b/userspace/root/usr/comma/runit/services/power-monitor/run new file mode 100755 index 0000000..21ed56f --- /dev/null +++ b/userspace/root/usr/comma/runit/services/power-monitor/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/qseecomd/run b/userspace/root/usr/comma/runit/services/qseecomd/run new file mode 100755 index 0000000..18ec57e --- /dev/null +++ b/userspace/root/usr/comma/runit/services/qseecomd/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/rmt-storage/run b/userspace/root/usr/comma/runit/services/rmt-storage/run new file mode 100755 index 0000000..f319df6 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/rmt-storage/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/rsyslog/run b/userspace/root/usr/comma/runit/services/rsyslog/run new file mode 100755 index 0000000..f7d5ba8 --- /dev/null +++ b/userspace/root/usr/comma/runit/services/rsyslog/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/ssh-param-watcher/run b/userspace/root/usr/comma/runit/services/ssh-param-watcher/run new file mode 100755 index 0000000..394288b --- /dev/null +++ b/userspace/root/usr/comma/runit/services/ssh-param-watcher/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/ssh/run b/userspace/root/usr/comma/runit/services/ssh/run new file mode 100755 index 0000000..7f698ee --- /dev/null +++ b/userspace/root/usr/comma/runit/services/ssh/run @@ -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 diff --git a/userspace/root/usr/comma/runit/services/varwatch/run b/userspace/root/usr/comma/runit/services/varwatch/run new file mode 100755 index 0000000..62ed85a --- /dev/null +++ b/userspace/root/usr/comma/runit/services/varwatch/run @@ -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 diff --git a/userspace/root/usr/comma/set_adb.sh b/userspace/root/usr/comma/set_adb.sh index 924ef73..a1e6c03 100755 --- a/userspace/root/usr/comma/set_adb.sh +++ b/userspace/root/usr/comma/set_adb.sh @@ -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 diff --git a/userspace/root/usr/comma/set_ssh.sh b/userspace/root/usr/comma/set_ssh.sh index eb77e97..2955f00 100755 --- a/userspace/root/usr/comma/set_ssh.sh +++ b/userspace/root/usr/comma/set_ssh.sh @@ -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 diff --git a/userspace/root/usr/comma/shims/systemctl b/userspace/root/usr/comma/shims/systemctl new file mode 100755 index 0000000..87bd75d --- /dev/null +++ b/userspace/root/usr/comma/shims/systemctl @@ -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 diff --git a/userspace/root/usr/comma/sound/start-sound.sh b/userspace/root/usr/comma/sound/start-sound.sh new file mode 100755 index 0000000..3930f72 --- /dev/null +++ b/userspace/root/usr/comma/sound/start-sound.sh @@ -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 diff --git a/userspace/root/usr/comma/start-comma.sh b/userspace/root/usr/comma/start-comma.sh new file mode 100755 index 0000000..8cf677b --- /dev/null +++ b/userspace/root/usr/comma/start-comma.sh @@ -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 diff --git a/userspace/root/usr/comma/start-magic.sh b/userspace/root/usr/comma/start-magic.sh new file mode 100755 index 0000000..0213809 --- /dev/null +++ b/userspace/root/usr/comma/start-magic.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +set -u + +PATH=/usr/comma/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +export PATH +export HOME=/home/comma +export LOGNAME=comma +export SHELL=/bin/bash +export USER=comma +export XDG_RUNTIME_DIR=/var/tmp/xdg +export PYTHONPATH=/data/pythonpath +export UV_PYTHON_INSTALL_DIR=/usr/local/uv/python +export UV_PYTHON_PREFERENCE=only-system +export UV_LINK_MODE=copy + +log() { + local ts="?" + if [ -r /proc/uptime ]; then + ts="$(cut -d' ' -f1 /proc/uptime)" + fi + if [ -w /dev/kmsg ]; then + printf '<6>start-magic[%d]: %s %s\n' "$$" "$ts" "$*" >/dev/kmsg 2>/dev/null || true + fi +} + +magic_running() { + pgrep -u comma -f "/usr/comma/magic.py" >/dev/null 2>&1 +} + +prep_root() { + 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 + + mkdir -p /data/misc/display /var/tmp/xdg + (echo 0 >/data/misc/display/sdm_dbg_cfg.txt) 2>/dev/null || true + (echo 0 >/data/misc/display/gbm_dbg_cfg.txt) 2>/dev/null || true + chown comma:comma /var/tmp/xdg 2>/dev/null || true +} + +prep_user() { + mkdir -p /var/tmp/xdg 2>/dev/null || true +} + +monitor_magic() { + while magic_running; do + sleep 5 + done + log "magic exited" + return 1 +} + +if [ "$(id -u)" = "0" ]; then + prep_root + exec env \ + HOME="$HOME" \ + LOGNAME="$LOGNAME" \ + SHELL="$SHELL" \ + USER="$USER" \ + XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \ + PYTHONPATH="$PYTHONPATH" \ + UV_PYTHON_INSTALL_DIR="$UV_PYTHON_INSTALL_DIR" \ + UV_PYTHON_PREFERENCE="$UV_PYTHON_PREFERENCE" \ + UV_LINK_MODE="$UV_LINK_MODE" \ + PATH="$PATH" \ + setpriv --reuid=1000 --regid=1000 --init-groups "$0" "$@" +fi + +prep_user + +if magic_running; then + log "magic already running" + if [ "${1:-}" = "--monitor" ]; then + monitor_magic + fi + exit 0 +fi + +log "exec magic" +exec /usr/local/venv/bin/python -u /usr/comma/magic.py diff --git a/userspace/root/usr/comma/tests/analyze-boot-time.py b/userspace/root/usr/comma/tests/analyze-boot-time.py index 2bcd15c..539629b 100755 --- a/userspace/root/usr/comma/tests/analyze-boot-time.py +++ b/userspace/root/usr/comma/tests/analyze-boot-time.py @@ -1,22 +1,18 @@ #!/usr/bin/env python3 import subprocess +import re from tabulate import tabulate # serial with timestamps: # grabserial -d /dev/serial/by-id/usb-FTDI_FT230X* -t -# systemd-analyze critical-chain comma.service - -# boot chart: -# systemd-analyze plot > /tmp/bootup.svg - -def get_journal_time(x): - out = subprocess.check_output("journalctl -x -o short-monotonic", shell=True, encoding='utf8') - jlines = out.strip().splitlines() - for l in jlines: - if x in l: - t = l.split('[')[1].split(']')[0] - return float(t) +def get_bootsh_time(x): + out = subprocess.check_output("dmesg | grep 'boot.sh'", shell=True, encoding='utf8') + for line in out.strip().splitlines(): + if x in line: + m = re.search(r"boot\.sh\[\d+\]: ([0-9.]+)", line) + if m: + return float(m.group(1)) return None if __name__ == "__main__": @@ -30,12 +26,8 @@ if __name__ == "__main__": def tot_since_kern(): return sum(ts.values()) - (ts['PON'] + ts['XBL'] + ts['ABL']) - out = subprocess.check_output("systemd-analyze", shell=True, encoding='utf8') - l = out.splitlines()[0].split(' ') - ts['kernel'] = float(l[3][:-1]) - #ts['systemd'] = float(l[6][:-1]) - - ts['comma'] = get_journal_time("Starting comma.service") - tot_since_kern() + ts['kernel-to-pid1'] = get_bootsh_time("pid1 start") or 0.0 + ts['comma'] = (get_bootsh_time("comma launched") or 0.0) - ts['kernel-to-pid1'] # print tot = 0 diff --git a/userspace/root/usr/comma/tests/test_agnos.py b/userspace/root/usr/comma/tests/test_agnos.py index 8ca6647..178da8f 100755 --- a/userspace/root/usr/comma/tests/test_agnos.py +++ b/userspace/root/usr/comma/tests/test_agnos.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import json +import re import time import subprocess @@ -51,13 +52,21 @@ def test_dmesg(): # TODO: ensure no new errors in dmesg. would catch things like the brightness setting bug pass -def test_systemd_services(): - pass +def test_runit_services(): + assert run("cat /proc/1/comm").strip() == "runit" + assert run("pgrep -a 'systemd|journald|udevd' || true").strip() == "" + + out = run("sv status /run/runit/services/*") + failed = [line for line in out.splitlines() if not line.startswith("run:")] + assert failed == [] def test_boot_time(): - out = subprocess.check_output("systemd-analyze", shell=True, encoding='utf8') + out = run("dmesg | grep 'boot.sh'") + marks = {} + for line in out.splitlines(): + m = re.search(r"boot\.sh\[\d+\]: ([0-9.]+) (.*)", line) + if m: + marks[m.group(2)] = float(m.group(1)) - a = out.splitlines()[0] - print(out, a) - - # check comma service + assert "comma launched" in marks + print(marks) diff --git a/userspace/root/usr/comma/tests/test_sounds.py b/userspace/root/usr/comma/tests/test_sounds.py index 0c87128..3edac38 100755 --- a/userspace/root/usr/comma/tests/test_sounds.py +++ b/userspace/root/usr/comma/tests/test_sounds.py @@ -3,24 +3,20 @@ import os import time import subprocess -good = """ -Starting Sound... -[INFO] Bringing adsp out of reset -subsys4 -waiting for sound card to come online -sound card online -sound.service: Succeeded. -Finished Sound. -""".strip() +required = [ + "[INFO] Bringing adsp out of reset", + "waiting for sound card to come online", + "sound card online", +] if __name__ == "__main__": time.sleep(3) - log = subprocess.check_output("journalctl -o cat -u sound", shell=True, encoding='utf8').strip() - passed = log == good + log = subprocess.check_output("cat /tmp/sound.log 2>/dev/null || true", shell=True, encoding='utf8').strip() + passed = all(line in log for line in required) with open('/data/tmp/sound_log', 'a') as f: f.write(f"{passed}\n") - os.system("journalctl -u sound.service -o short-monotonic >> /data/tmp/sound_service_log") + os.system("cat /tmp/sound.log >> /data/tmp/sound_service_log") os.system("sudo su -c 'tail /data/tmp/sound_log > /dev/console'") os.system("sudo su -c 'wc -l /data/tmp/sound_log > /dev/console'") os.sync() diff --git a/userspace/root/usr/comma/tests/varspam.sh b/userspace/root/usr/comma/tests/varspam.sh index dab9e69..a492a93 100755 --- a/userspace/root/usr/comma/tests/varspam.sh +++ b/userspace/root/usr/comma/tests/varspam.sh @@ -5,7 +5,7 @@ RATE=${1:-1} log_message() { # /var/log/syslog - cat /usr/include/sqlite3.h | systemd-cat -t SPAM_TEST + cat /usr/include/sqlite3.h | logger -t SPAM_TEST # /var/log/kern.log #cat /usr/include/sqlite3.h | sudo tee /dev/kmsg > /dev/null @@ -15,10 +15,8 @@ log_message() { sudo logrotate -d /etc/logrotate.conf sudo rm -rf /var/log/* -sudo systemctl daemon-reload -sudo systemctl restart rsyslog -sudo systemctl restart systemd-journald -sudo systemctl restart logrotate-hourly.timer +sudo sv restart /run/runit/services/rsyslog +sudo sv restart /run/runit/services/logrotate while true; do for i in $(seq 1 $RATE); do diff --git a/userspace/root/usr/comma/tmpfiles.conf b/userspace/root/usr/comma/tmpfiles.conf deleted file mode 100644 index 84e432b..0000000 --- a/userspace/root/usr/comma/tmpfiles.conf +++ /dev/null @@ -1,23 +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. - -# See tmpfiles.d(5) for details - -# /var: rebuild enough for services to be happy -d /var/crash 0755 - - - -q /var/tmp 1777 root root 30d - -d /var/lib/dpkg 0755 - - - -f /var/lib/dpkg/lock-frontend 0755 - - - -f /var/lib/dpkg/status 0755 - - - - -d /var/lib/logrotate 0755 - - - - -d /var/spool 0755 - - - -d /var/spool/cron/atjobs 0755 - - - - -d /var/cache/pollinate 0755 pollinate daemon - diff --git a/userspace/services.sh b/userspace/services.sh deleted file mode 100755 index c05916f..0000000 --- a/userspace/services.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -e - -# Enable our services -systemctl enable fs_setup.service -systemctl enable serial-hostname.service -systemctl enable comma.service -systemctl enable agnos-debug.service -systemctl enable gpio.service -systemctl enable lte.service -systemctl enable sound.service -systemctl enable magic.service -systemctl enable init-qcom.service -systemctl enable varwatch.service -systemctl enable power_monitor.service -systemctl enable power_drop_monitor.service -systemctl enable brightnessd.service -systemctl enable ssh-param-watcher.path -systemctl enable ssh-param-watcher.service -systemctl enable adb-param-watcher.path -systemctl enable adb-param-watcher.service -systemctl enable logrotate-hourly.timer -systemctl enable avahi-daemon -systemctl enable avahi-ssh-publish.service -systemctl enable screen_calibration.service - -# Disable some of our services -systemctl disable agnos-tests.service - -# Disable SSH by default -systemctl disable ssh - -# Disable all useless systemctl services -systemctl disable hostapd.service -systemctl disable apt-daily-upgrade.service -systemctl disable apt-daily.service -systemctl disable apt-daily-upgrade.timer -systemctl disable apt-daily.timer -systemctl disable serial-getty@ttyS0.service -systemctl disable remote-fs.target -systemctl disable remote-fs-pre.target -systemctl disable e2scrub_all.timer -systemctl disable fstrim.timer -systemctl disable motd-news.service -systemctl disable motd-news.timer -systemctl disable multipathd.service -systemctl disable multipathd.socket -systemctl disable lvm2-monitor.service -systemctl mask systemd-backlight@.service -systemctl disable dpkg-db-backup.timer -systemctl disable ua-reboot-cmds.service -systemctl disable ubuntu-advantage.service -systemctl disable update-notifier-download.timer -systemctl disable update-notifier-download.service -systemctl disable update-notifier-motd.timer -systemctl disable update-notifier-motd.service -systemctl disable man-db.timer - -# Disable NFS stuff by default -systemctl disable rpcbind -systemctl disable dnsmasq.service -systemctl disable nfs-client.target -systemctl disable remote-fs-pre.target - -# Service is from ifupdown but ifupdown is managed by NetworkManager -# networking service fails with "ifup: failed to bring up lo" -# no influence on any interface, all interfaces work fine -systemctl disable networking.service - -systemctl disable console-setup.service