From 2ffb16f7b896ed8f0a9e6e86c0bbb567ede35b34 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 25 Feb 2023 22:24:49 -0800 Subject: [PATCH] weston init cleanup (#117) * weston: remove display re-init * test * init both * increase * another try * move that * test service * little more * bump kernel * fix that --- agnos-kernel-sdm845 | 2 +- userspace/files/agnos-tests.service | 11 +++++++ userspace/files/comma.service | 3 +- userspace/files/pulse.service | 1 + userspace/files/weston-ready.service | 22 +++++++++++++ userspace/files/weston.service | 39 ++++++++++++----------- userspace/services.sh | 5 +++ userspace/usr/comma/comma.sh | 9 ------ userspace/usr/comma/tests/test_agnos.py | 1 - userspace/usr/comma/tests/test_weston.py | 40 ++++++++++++++++++++++++ 10 files changed, 101 insertions(+), 32 deletions(-) create mode 100644 userspace/files/agnos-tests.service create mode 100644 userspace/files/weston-ready.service create mode 100755 userspace/usr/comma/tests/test_weston.py diff --git a/agnos-kernel-sdm845 b/agnos-kernel-sdm845 index 2b4c012..6abf340 160000 --- a/agnos-kernel-sdm845 +++ b/agnos-kernel-sdm845 @@ -1 +1 @@ -Subproject commit 2b4c01261ed5ea77c5a7dad11e812e384b4fcd67 +Subproject commit 6abf3402d69f22de1a992da8ee69ac75a3ede1c7 diff --git a/userspace/files/agnos-tests.service b/userspace/files/agnos-tests.service new file mode 100644 index 0000000..dbefb77 --- /dev/null +++ b/userspace/files/agnos-tests.service @@ -0,0 +1,11 @@ +[Unit] +After=weston-ready.service + +[Service] +Type=simple +User=comma +Restart=no +ExecStart=/bin/bash -c "source /etc/profile && /data/test_weston.py" + +[Install] +WantedBy=multi-user.target diff --git a/userspace/files/comma.service b/userspace/files/comma.service index 84ca22b..fde519a 100644 --- a/userspace/files/comma.service +++ b/userspace/files/comma.service @@ -1,6 +1,5 @@ [Unit] -Description=Comma tmux -After=weston.service gpio.service +After=weston-ready.service gpio.service [Service] Type=simple diff --git a/userspace/files/pulse.service b/userspace/files/pulse.service index 9c5435c..44c9179 100644 --- a/userspace/files/pulse.service +++ b/userspace/files/pulse.service @@ -1,5 +1,6 @@ [Unit] Description=PulseAudio system server +After=weston-ready.service [Service] Type=simple diff --git a/userspace/files/weston-ready.service b/userspace/files/weston-ready.service new file mode 100644 index 0000000..b6c4057 --- /dev/null +++ b/userspace/files/weston-ready.service @@ -0,0 +1,22 @@ +[Unit] +PartOf=weston.service + +[Service] +Type=oneshot +Restart=no +Environment="XDG_RUNTIME_DIR=/var/tmp/weston" + +ExecStart=/bin/echo "waiting for wayland socket" +ExecStart=/bin/bash -c "while [ ! -e \"$XDG_RUNTIME_DIR/wayland-0\" ]; do sleep 0.1; done" + +# still starting after socket comes up +ExecStart=/bin/sleep 0.5 + +ExecStart=/bin/echo "fixing permissions" +ExecStart=/bin/bash -c "chmod -R 770 $XDG_RUNTIME_DIR" + +ExecStart=/bin/echo "turning on display" +ExecStart=/bin/bash -c "echo 500 > /sys/class/backlight/panel0-backlight/brightness" + +[Install] +WantedBy=multi-user.target diff --git a/userspace/files/weston.service b/userspace/files/weston.service index 7017e91..c7d4955 100644 --- a/userspace/files/weston.service +++ b/userspace/files/weston.service @@ -1,28 +1,29 @@ [Unit] Description=Weston +Conflicts=getty@tty1.service +After=systemd-user-sessions.service getty@tty1.service -# If we start weston immediately it just exits without an error -# TODO: Figure out what we need to wait for (drm?) [Service] Type=simple -Restart=always -Environment="XDG_RUNTIME_DIR=/var/tmp/weston" -# TODO: detect if display was brought up by bootloader -# Setting backlight to 0 while the screen is not initialized will turn off the regulators, 1023 turns it back on -ExecStart=/bin/bash -c "sleep 4 && \ - echo 0 > /sys/class/backlight/panel0-backlight/brightness && \ - sleep 0.1 && \ - echo 1023 > /sys/class/backlight/panel0-backlight/brightness && \ - /usr/comma/modetest -M msm_drm -s 26@111:1080x2160-60 && \ - /usr/comma/modetest -M msm_drm -s 26@111:1080x2160-60 && \ - sleep 1 && \ - mkdir -p $XDG_RUNTIME_DIR && \ - chown -R comma: $XDG_RUNTIME_DIR && \ - mkdir -p /data/misc/display || true && \ - echo 0 > /data/misc/display/sdm_dbg_cfg.txt || true && \ - echo 0 > /data/misc/display/gbm_dbg_cfg.txt || true && \ - /usr/bin/weston --idle-time=0 --tty=1 --config=/usr/comma/weston.ini" +Restart=no KillSignal=SIGKILL +Environment="XDG_RUNTIME_DIR=/var/tmp/weston" + +UtmpIdentifier=tty1 +TTYPath=/dev/tty1 +TTYReset=yes +TTYVHangup=yes +TTYVTDisallocate=yes + +ExecStartPre=/bin/bash -c "mkdir -p $XDG_RUNTIME_DIR" +ExecStartPre=/bin/bash -c "chown -R comma: $XDG_RUNTIME_DIR" + +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" + +ExecStartPre=/bin/chvt 1 +ExecStart=/usr/bin/weston --idle-time=0 --tty=1 --config=/usr/comma/weston.ini [Install] WantedBy=multi-user.target diff --git a/userspace/services.sh b/userspace/services.sh index 903c3eb..a8540b4 100755 --- a/userspace/services.sh +++ b/userspace/services.sh @@ -15,6 +15,7 @@ systemctl enable lte.service systemctl enable sound.service systemctl enable pulse.service systemctl enable weston.service +systemctl enable weston-ready.service systemctl enable wifi.service systemctl enable init-qcom.service systemctl enable power_drop_monitor.service @@ -24,6 +25,10 @@ systemctl enable ssh-param-watcher.service systemctl enable home.mount systemctl enable logrotate-hourly.timer +# Disable some of our services +systemctl disable serial-hostname.service +systemctl disable agnos-tests.service + # Disable third party services systemctl disable darkstat.service systemctl disable vnstat.service diff --git a/userspace/usr/comma/comma.sh b/userspace/usr/comma/comma.sh index 890b292..5bb2a62 100755 --- a/userspace/usr/comma/comma.sh +++ b/userspace/usr/comma/comma.sh @@ -8,18 +8,9 @@ CONTINUE="/data/continue.sh" INSTALLER="/tmp/installer" RESET_TRIGGER="/data/__system_reset__" - -echo "Waiting for wayland" -while [ ! -e "$XDG_RUNTIME_DIR/wayland-0" ]; do sleep 0.1; done -sleep 0.5 # weston's still starting after the socket's created -echo "wayland ready" -sudo chmod -R 770 $XDG_RUNTIME_DIR - sudo chown comma: /data sudo chown comma: /data/media -sudo su -c "echo 500 > /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/backlight/panel0-backlight/brightness" - handle_setup_keys () { # install default SSH key while still in setup if [[ ! -e /data/params/d/GithubSshKeys && ! -e /data/continue.sh ]]; then diff --git a/userspace/usr/comma/tests/test_agnos.py b/userspace/usr/comma/tests/test_agnos.py index de55818..5acf83e 100755 --- a/userspace/usr/comma/tests/test_agnos.py +++ b/userspace/usr/comma/tests/test_agnos.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import json import time -import pytest import subprocess def run(cmd): diff --git a/userspace/usr/comma/tests/test_weston.py b/userspace/usr/comma/tests/test_weston.py new file mode 100755 index 0000000..5127a00 --- /dev/null +++ b/userspace/usr/comma/tests/test_weston.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import os +import time +import hashlib +import subprocess + +if __name__ == "__main__": + socket_exists = os.path.exists("/var/tmp/weston/wayland-0") + is_active = subprocess.check_output("systemctl is-active weston", shell=True, encoding='utf8').strip() + + d = b"" + for fn in ('/lib/systemd/system/weston.service', '/lib/systemd/system/weston-ready.service'): + with open(fn, 'rb') as f: + d += f.read() + h = hashlib.sha1(d).hexdigest() + + # weston should be ready to go at this point + proc = subprocess.Popen('/usr/comma/setup', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + for i in range(10): + r = proc.poll() + if r is not None: + break + time.sleep(1) + + rc = proc.returncode + proc.kill() + out, err = proc.stdout.read(), proc.stderr.read() + + with open('/data/weston_log', 'a') as f: + f.write(f"{is_active=}, {socket_exists=}, app={rc} / {h}\n") + if rc is not None: + f.write(f" stdout: {out}\n") + f.write(f" stderr: {err}\n") + os.sync() + + os.system("sudo su -c 'tail /data/weston_log > /dev/console'") + os.system("sudo su -c 'wc -l /data/weston_log > /dev/console'") + + time.sleep(2) + os.system("sudo reboot")