Files
mi8-platina-linux/scripts/deploy_and_verify_r17.py
shenlei 530a3690da
Offline project checks / check (push) Canceled after 0s
feat: add WCN3990 Wi-Fi bringup service, battery protection, and bringup automation
- Add phone-dsp.openrc to initialize Hexagon DSP, rmtfs, pd-mapper, and ath10k_snoc
- Update phone-battery-guard threshold to 80% with power supply node fallbacks
- Enhance phone-cellular-setup with battery gate checks, RF locks, and unit tests
- Include bringup, flashing, and inspection automation scripts for platina
- Update candidate IPA v2.6 patches and package locks
2026-11-12 14:54:23 +09:00

147 lines
4.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Deploy and verify candidate r17 kernel with IPA cellular support.
"""
import os
import sys
import time
import subprocess
import socket
SSH_KEY = "/Users/shenlei/Work/sshKey/oracle_tokyo_ARM.key"
TARGET_IP = "172.16.42.1"
TARGET_USER = "server"
ROOT_DIR = "/Users/shenlei/Work/mi8-platina-linux"
ARTIFACTS_DIR = os.path.join(ROOT_DIR, "artifacts/candidate-20261110-r17-cellular")
BOOT_IMG = os.path.join(ARTIFACTS_DIR, "boot-verified-r17.img")
APK_PKG = os.path.join(ARTIFACTS_DIR, "linux-postmarketos-qcom-sdm660-7.2.12-r17.apk")
def log(msg):
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
def run(cmd, check=True, capture=True):
log(f"CMD: {cmd}")
res = subprocess.run(cmd, shell=True, text=True, capture_output=capture)
if check and res.returncode != 0:
log(f"ERROR ({res.returncode}):\nSTDOUT: {res.stdout}\nSTDERR: {res.stderr}")
raise RuntimeError(f"Command failed: {cmd}")
return res
def wait_for_fastboot():
log("Waiting for Fastboot device (hold Volume Down + Power if needed)...")
while True:
res = subprocess.run("fastboot devices", shell=True, text=True, capture_output=True)
lines = [line.strip() for line in res.stdout.strip().splitlines() if line.strip()]
for l in lines:
if "fastboot" in l:
log(f"Found Fastboot device: {l}")
return l.split()[0]
time.sleep(1)
def flash_and_reboot(serial):
log(f"Flashing boot partition with {BOOT_IMG}...")
run(f"fastboot -s {serial} flash boot '{BOOT_IMG}'")
log("Rebooting device...")
run(f"fastboot -s {serial} reboot")
def wait_for_ssh(timeout=180):
log(f"Waiting for SSH on {TARGET_IP}:22 (timeout: {timeout}s)...")
start = time.time()
while time.time() - start < timeout:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
try:
s.connect((TARGET_IP, 22))
s.close()
log("SSH port 22 is OPEN!")
# Give sshd 2 seconds to be fully ready
time.sleep(2)
return True
except Exception:
pass
time.sleep(2)
raise TimeoutError("Timed out waiting for SSH")
def ssh_exec(cmd, check=True):
ssh_cmd = (
f"ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 "
f"-i '{SSH_KEY}' {TARGET_USER}@{TARGET_IP} '{cmd}'"
)
return run(ssh_cmd, check=check)
def main():
if not os.path.exists(BOOT_IMG):
log(f"Missing {BOOT_IMG}")
sys.exit(1)
if not os.path.exists(APK_PKG):
log(f"Missing {APK_PKG}")
sys.exit(1)
# 1. Wait for Fastboot
serial = wait_for_fastboot()
# 2. Flash and Reboot
flash_and_reboot(serial)
# 3. Wait for SSH
wait_for_ssh()
# 4. Verify booted kernel version
res = ssh_exec("uname -a; uptime")
log(f"Kernel info:\n{res.stdout.strip()}")
# 5. Upload and install r17 package
log("Uploading r17 apk package...")
scp_cmd = (
f"scp -o StrictHostKeyChecking=no -i '{SSH_KEY}' "
f"'{APK_PKG}' {TARGET_USER}@{TARGET_IP}:/tmp/"
)
run(scp_cmd)
log("Installing r17 apk package...")
ssh_exec("sudo apk add --allow-untrusted /tmp/linux-postmarketos-qcom-sdm660-7.2.12-r17.apk")
# 6. Verify modprobe blacklist and configure ipa
log("Configuring /etc/modprobe.d/...")
ssh_exec(
"sudo rm -f /etc/modprobe.d/blacklist-ipa.conf && "
"sudo rm -f /etc/modprobe.d/blacklist-ipa.conf.disabled || true"
)
# 7. Modprobe IPA
log("Loading IPA kernel module...")
ssh_exec("sudo modprobe -v ipa")
# 8. Wait 65s for autosuspend verification (runtime PM timeout test)
log("Testing IPA runtime suspend resilience (sleeping 65s)...")
time.sleep(65)
# 9. Check dmesg for any oops/panics
log("Checking dmesg for crashes or errors...")
res = ssh_exec("sudo dmesg | tail -n 50")
log(f"Recent dmesg:\n{res.stdout.strip()}")
# 10. Check rmnet_ipa0 network device
log("Checking rmnet_ipa0...")
res = ssh_exec("ip link show rmnet_ipa0")
log(f"rmnet_ipa0 info:\n{res.stdout.strip()}")
# 11. Check ModemManager status
log("Checking ModemManager...")
res = ssh_exec("mmcli -L; mmcli -m 0", check=False)
log(f"ModemManager info:\n{res.stdout.strip()}")
# 12. Bring up cellular network connection
log("Bringing up 4G cellular data connection...")
ssh_exec("nmcli connection up platina-cellular || sudo platina-cellular --up || true", check=False)
# 13. Verify connectivity
log("Verifying 4G data routing...")
res = ssh_exec("ip route; ping -I rmnet_ipa0 -c 4 1.1.1.1 || ping -c 4 1.1.1.1", check=False)
log(f"Ping output:\n{res.stdout.strip()}")
log("=== Candidate r17 Deployment and Cellular Restoration Complete! ===")
if __name__ == "__main__":
main()