mirror of
https://github.com/commaai/agnos-builder.git
synced 2026-10-01 03:43:49 +08:00
Migrate boot to runit
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
ssh tici "systemd-analyze plot > /tmp/bootchart.svg"
|
||||
scp tici:/tmp/bootchart.svg /tmp/bootchart.svg
|
||||
google-chrome /tmp/bootchart.svg
|
||||
|
||||
ssh tici "dmesg | grep 'boot.sh' > /tmp/bootchart.txt"
|
||||
scp tici:/tmp/bootchart.txt /tmp/bootchart.txt
|
||||
cat /tmp/bootchart.txt
|
||||
|
||||
+7
-3
@@ -15,7 +15,8 @@ import time
|
||||
import usb.core
|
||||
|
||||
SERIAL_DEV = "/dev/serial/by-id/usb-Microchip_Tech_USB2_Controller_Hub-if01"
|
||||
PROMPT_RE = re.compile(rb"(?:login:|[#\$])$")
|
||||
PROMPT_RE = re.compile(rb"(?:login:|(?:\x1b\[\?2004h)?(?:\([^)]+\) )?[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+:[^\r\n]*[#\$]\s*)$")
|
||||
BOOT_DONE_RE = re.compile(rb"boot\.sh\[\d+\]: .* boot path done")
|
||||
USB_RT_PORT = 0x23
|
||||
USB_REQ_CLEAR_FEATURE = 1
|
||||
USB_REQ_SET_FEATURE = 3
|
||||
@@ -128,6 +129,7 @@ class Mdma:
|
||||
|
||||
# show serial console with timestamps until boot is done
|
||||
pending = b""
|
||||
bootsh_seen = False
|
||||
while True:
|
||||
if not select.select([fd], [], [], 0.25)[0]:
|
||||
continue
|
||||
@@ -140,11 +142,13 @@ class Mdma:
|
||||
line, pending = pending.split(b"\n", 1)
|
||||
line = line.rstrip()
|
||||
print(f"[{time.monotonic() - start:8.3f}] {line.decode(errors='replace')}", flush=True)
|
||||
if PROMPT_RE.search(line):
|
||||
bootsh_seen = bootsh_seen or b"boot.sh[" in line
|
||||
if BOOT_DONE_RE.search(line) or (PROMPT_RE.search(line) and not bootsh_seen):
|
||||
return
|
||||
if PROMPT_RE.search(pending.strip()):
|
||||
print(f"[{time.monotonic() - start:8.3f}] {pending.strip().decode(errors='replace')}", flush=True)
|
||||
return
|
||||
if not bootsh_seen:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -16,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 /
|
||||
|
||||
Reference in New Issue
Block a user