From 84e9d4221168cbce48d9ed6a60e33efa841c16b8 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 1 Oct 2025 19:16:26 -0700 Subject: [PATCH] persistent boot debug logs (#491) * store debug logs * lil more * py --- userspace/files/agnos-debug.service | 10 +++++++++ userspace/services.sh | 1 + userspace/usr/comma/debug.py | 32 +++++++++++++++++++++++++++++ userspace/usr/comma/fs_setup.sh | 3 +++ 4 files changed, 46 insertions(+) create mode 100644 userspace/files/agnos-debug.service create mode 100755 userspace/usr/comma/debug.py diff --git a/userspace/files/agnos-debug.service b/userspace/files/agnos-debug.service new file mode 100644 index 0000000..8dbb59e --- /dev/null +++ b/userspace/files/agnos-debug.service @@ -0,0 +1,10 @@ +[Unit] +After=local-fs.target + +[Service] +Type=oneshot +User=comma +ExecStart=/usr/comma/debug.py + +[Install] +WantedBy=multi-user.target diff --git a/userspace/services.sh b/userspace/services.sh index 300a088..093b0a6 100755 --- a/userspace/services.sh +++ b/userspace/services.sh @@ -10,6 +10,7 @@ systemctl enable cdsprpcd 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 diff --git a/userspace/usr/comma/debug.py b/userspace/usr/comma/debug.py new file mode 100755 index 0000000..8bce256 --- /dev/null +++ b/userspace/usr/comma/debug.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import os +import shutil +from pathlib import Path + +ROOT = Path("/cache/debug/") + + +if __name__ == "__main__": + boots = sorted(list(ROOT.iterdir()), key=lambda p: int(p.stem, 16), reverse=True) + + # limit to 100 boots + for d in boots[100:]: + print("cleaning up", d) + shutil.rmtree(d) + + # make a directory for this boot + n = 0 + if len(boots): + n = int(boots[0].stem, 16) + 1 + boot_dir = ROOT / f"{n:08x}" + boot_dir.mkdir(parents=True) + + # log some stuff + pstore = boot_dir / "pstore" + pstore.mkdir() + os.system(f"cp /sys/fs/pstore/* {pstore} 2>/dev/null") + + os.system(f"uname -a > {boot_dir / 'uname'}") + shutil.copyfile("/VERSION", boot_dir / "VERSION") + diff --git a/userspace/usr/comma/fs_setup.sh b/userspace/usr/comma/fs_setup.sh index 50e9a0f..5a033a1 100755 --- a/userspace/usr/comma/fs_setup.sh +++ b/userspace/usr/comma/fs_setup.sh @@ -24,6 +24,9 @@ touch /data/etc/localtime mkdir -p /data/etc/netplan mkdir -p /data/etc/NetworkManager/system-connections +# /cache +chown -R comma:comma /cache/ + # /data/ssh mkdir -p /data/ssh chown comma: /data/ssh