#!/usr/bin/env python3 """ Debug boot candidate r17 kernel with pmos.debug-shell and inspect initramfs/eMMC. """ import os import sys import time import subprocess import socket ROOT_DIR = "/Users/shenlei/Work/mi8-platina-linux" ARTIFACTS_DIR = os.path.join(ROOT_DIR, "artifacts/candidate-20261110-r17-cellular") DEBUG_BOOT_IMG = os.path.join(ARTIFACTS_DIR, "boot-debug-r17.img") TARGET_IP = "172.16.42.1" TARGET_PORT = 23 def log(msg): print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True) def run(cmd, check=True): log(f"CMD: {cmd}") res = subprocess.run(cmd, shell=True, text=True, capture_output=True) if check and res.returncode != 0: log(f"ERROR ({res.returncode}):\n{res.stderr}\n{res.stdout}") raise RuntimeError(f"Command failed: {cmd}") return res def wait_for_fastboot(): log("Waiting for Fastboot device (hold Volume Down + Power)...") 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(0.5) def boot_image(serial): log(f"Booting {DEBUG_BOOT_IMG} on {serial}...") run(f"fastboot -s {serial} boot '{DEBUG_BOOT_IMG}'") log("Kernel sent! Waiting 5s before polling telnet...") time.sleep(5) def wait_for_telnet(timeout=60): log(f"Waiting for Telnet on {TARGET_IP}:{TARGET_PORT} (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, TARGET_PORT)) s.close() log("Telnet port 23 is OPEN!") time.sleep(1) return True except Exception: pass time.sleep(1) raise TimeoutError("Timed out waiting for telnet") def telnet_cmd(cmd, wait_time=2.0): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(3.0) s.connect((TARGET_IP, TARGET_PORT)) time.sleep(0.5) try: s.recv(4096) except socket.timeout: pass s.sendall((cmd + "\n").encode("utf-8")) time.sleep(wait_time) output = b"" while True: try: chunk = s.recv(4096) if not chunk: break output += chunk except socket.timeout: break s.close() return output.decode("utf-8", errors="replace") def main(): if not os.path.exists(DEBUG_BOOT_IMG): log(f"Missing {DEBUG_BOOT_IMG}") sys.exit(1) # 1. Wait for Fastboot serial = wait_for_fastboot() # 2. Boot debug image boot_image(serial) # 3. Wait for Telnet wait_for_telnet() # 4. Read /pmOS_init.log log("Reading /pmOS_init.log...") out = telnet_cmd("cat /pmOS_init.log") log(f"=== /pmOS_init.log ===\n{out.strip()}\n") # 5. Read blkid and partitions log("Reading blkid and partitions...") out = telnet_cmd("blkid; echo '=== PARTITIONS ==='; cat /proc/partitions") log(f"=== blkid & partitions ===\n{out.strip()}\n") # 6. Check dmesg tail log("Reading dmesg tail...") out = telnet_cmd("dmesg | tail -n 40") log(f"=== dmesg tail ===\n{out.strip()}\n") # 7. Mount eMMC root partition log("Mounting eMMC root partition (/dev/mmcblk1p79)...") out = telnet_cmd("mkdir -p /mnt && mount /dev/mmcblk1p79 /mnt && echo MOUNT_OK || echo MOUNT_FAIL") log(f"=== Mount result ===\n{out.strip()}\n") # 8. Inspect /mnt/etc/fstab and /mnt OpenRC services log("Inspecting /mnt/etc/fstab and runlevels...") out = telnet_cmd("cat /mnt/etc/fstab; echo '=== RUNLEVEL DEFAULT ==='; ls -la /mnt/etc/runlevels/default/") log(f"=== /mnt config ===\n{out.strip()}\n") # 9. Test ipa module in chroot log("Testing ipa module with fixed r17...") out = telnet_cmd("uname -a; modinfo /mnt/lib/modules/7.2.12-sdm660/kernel/drivers/net/ipa/ipa.ko* 2>/dev/null || true") log(f"=== ipa module info ===\n{out.strip()}\n") if __name__ == "__main__": main()