Files
mi8-platina-linux/scripts/boot_and_inspect.py
T
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
5.2 KiB
Python

#!/usr/bin/env python3
"""
Boot candidate r17 debug image, wait for initramfs USB gadget, connect telnet,
inspect system state and filesystem, and ensure rootfs is cleanly configured.
"""
import os
import re
import socket
import subprocess
import sys
import time
TARGET_IP = "172.16.42.1"
TARGET_PORT = 23
DEBUG_BOOT_IMG = "artifacts/candidate-20261110-r17-cellular/boot-debug-r17.img"
def log(msg):
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
def find_gadget_interface():
# Find network interface with 172.16.42.x or newly attached USB Ethernet
res = subprocess.run(["ifconfig"], capture_output=True, text=True)
for block in res.stdout.split("\n\n"):
if "172.16.42." in block:
m = re.match(r"^([a-z0-9]+):", block)
if m:
return m.group(1)
return None
def telnet_cmd(cmd, wait_time=2.0):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5.0)
s.connect((TARGET_IP, TARGET_PORT))
time.sleep(0.3)
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():
log("Checking fastboot device...")
res = subprocess.run(["fastboot", "devices"], capture_output=True, text=True)
devices = [l.split()[0] for l in res.stdout.strip().splitlines() if "fastboot" in l]
if not devices:
log("No device in fastboot mode!")
sys.exit(1)
serial = devices[0]
log(f"Found fastboot device: {serial}")
# Read battery status
res = subprocess.run(["fastboot", "-s", serial, "getvar", "battery-voltage"], capture_output=True, text=True)
log(f"Battery: {res.stderr.strip() or res.stdout.strip()}")
log(f"Booting {DEBUG_BOOT_IMG}...")
res = subprocess.run(["fastboot", "-s", serial, "boot", DEBUG_BOOT_IMG], capture_output=True, text=True)
if res.returncode != 0:
log(f"Boot failed: {res.stderr}")
sys.exit(1)
log("Boot command successful! Waiting for phone to initialize USB gadget in initramfs...")
# Wait for USB network interface to appear
start = time.time()
iface = None
while time.time() - start < 45:
iface = find_gadget_interface()
if iface:
log(f"Found network interface: {iface} with 172.16.42.x")
break
time.sleep(1)
if not iface:
log("Warning: No interface with 172.16.42.x found yet. Checking ioreg for USB devices...")
res = subprocess.run(["ioreg", "-p", "IOUSB", "-l"], capture_output=True, text=True)
for line in res.stdout.splitlines():
if any(k in line.lower() for k in ["xiaomi", "platina", "android", "qualcomm", "05c6", "gadget"]):
log(f"USB entry: {line.strip()}")
# Check all ifconfig interfaces
res = subprocess.run(["ifconfig", "-l"], capture_output=True, text=True)
log(f"All interfaces: {res.stdout.strip()}")
# Try connecting to telnet
log("Connecting to Telnet (port 23)...")
connected = False
start = time.time()
while time.time() - start < 30:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
s.connect((TARGET_IP, TARGET_PORT))
s.close()
log("SUCCESS: Telnet port 23 is open!")
connected = True
break
except Exception:
time.sleep(1)
if not connected:
log("Failed to connect to telnet port 23.")
sys.exit(1)
# Inspect device
log("\n--- Checking Battery ---")
out = telnet_cmd("cat /sys/class/power_supply/qcom-battery/capacity /sys/class/power_supply/qcom-battery/voltage_now")
log(f"Battery: {out.strip()}")
log("\n--- Checking Filesystem Integrity on /dev/mmcblk1p79 ---")
out = telnet_cmd("e2fsck -fy /dev/mmcblk1p79", wait_time=4.0)
log(f"e2fsck result:\n{out.strip()}")
log("\n--- Mounting /sysroot ---")
out = telnet_cmd("mount_root_partition 2>/dev/null || mount /dev/mmcblk1p79 /sysroot 2>/dev/null; mount | grep sysroot")
log(f"Mount: {out.strip()}")
log("\n--- Checking /sysroot/etc/modprobe.d/modem-blacklist.conf ---")
out = telnet_cmd("cat /sysroot/etc/modprobe.d/modem-blacklist.conf 2>/dev/null")
log(f"Blacklist:\n{out.strip()}")
log("\n--- Checking /sysroot/etc/modules-load.d/modem.conf ---")
out = telnet_cmd("cat /sysroot/etc/modules-load.d/modem.conf 2>/dev/null")
log(f"modules-load.d:\n{out.strip()}")
log("\n--- Checking ModemManager service disablement ---")
out = telnet_cmd("ls -la /sysroot/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1* 2>/dev/null")
log(f"ModemManager D-Bus service:\n{out.strip()}")
log("\n--- Checking /pmOS_init.log tail ---")
out = telnet_cmd("tail -n 25 /pmOS_init.log 2>/dev/null")
log(f"pmOS_init.log:\n{out.strip()}")
log("\n--- Inspection Complete! Device is alive in initramfs telnet shell. ---")
if __name__ == "__main__":
main()