Files
mi8-platina-linux/scripts/boot_direct_and_verify.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

145 lines
5.4 KiB
Python

#!/usr/bin/env python3
"""
Boot candidate direct boot image (with disabled vibrator motor and robust UDC),
wait for local USB network interface, SSH in, and run controlled cellular bringup.
"""
import os
import re
import socket
import subprocess
import sys
import time
TARGET_IP = "172.16.42.1"
SSH_KEY = "/Users/shenlei/Work/sshKey/oracle_tokyo_ARM.key"
BOOT_IMG = "artifacts/candidate-20261110-r17-cellular/boot-patched-direct-r17.img"
def log(msg):
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
def find_usb_net_interface():
res = subprocess.run(["ifconfig"], capture_output=True, text=True)
for block in res.stdout.split("\n\n"):
if "172.16.42." in block and "status: active" in block:
m = re.match(r"^([a-z0-9]+):", block)
if m:
return m.group(1)
return None
def run_ssh(cmd, timeout=30):
ssh_cmd = [
"ssh",
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "ConnectTimeout=5",
"-i", SSH_KEY,
f"server@{TARGET_IP}",
cmd
]
res = subprocess.run(ssh_cmd, capture_output=True, text=True, timeout=timeout)
return res.returncode, res.stdout, res.stderr
def wait_for_fastboot():
log("Waiting for Fastboot device (63c36adb)...")
while True:
res = subprocess.run(["fastboot", "devices"], capture_output=True, text=True)
for line in res.stdout.strip().splitlines():
if "fastboot" in line:
serial = line.split()[0]
log(f"Found Fastboot device: {serial}")
return serial
time.sleep(1)
def main():
serial = wait_for_fastboot()
res = subprocess.run(["fastboot", "-s", serial, "getvar", "battery-voltage"], capture_output=True, text=True)
log(f"Battery Voltage: {res.stderr.strip() or res.stdout.strip()}")
log(f"Booting {BOOT_IMG} directly to OpenRC...")
res = subprocess.run(["fastboot", "-s", serial, "boot", BOOT_IMG], capture_output=True, text=True)
if res.returncode != 0:
log(f"Boot failed: {res.stderr}")
sys.exit(1)
log("Boot command sent! Waiting for USB network interface to become active on Mac...")
# Wait for USB network interface on Mac
start = time.time()
iface = None
while time.time() - start < 45:
iface = find_usb_net_interface()
if iface:
log(f"SUCCESS: Host network interface {iface} is active with 172.16.42.x!")
break
time.sleep(1)
if not iface:
log("Warning: Specific active interface not detected yet. Checking routing...")
# Wait for SSH port 22 ONLY after host interface is up
log("Polling SSH port 22...")
start = time.time()
ssh_up = False
while time.time() - start < 60:
# Check that interface is up first to prevent utun70 leakage
if find_usb_net_interface():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
try:
s.connect((TARGET_IP, 22))
s.close()
log(f"SUCCESS: Phone SSH port 22 is OPEN!")
ssh_up = True
break
except Exception:
pass
time.sleep(1)
if not ssh_up:
log("ERROR: Timed out waiting for SSH port 22.")
sys.exit(1)
time.sleep(2)
log("Testing SSH login to server@172.16.42.1...")
code, out, err = run_ssh("uname -a; uptime; cat /sys/class/power_supply/qcom-battery/voltage_now")
log(f"SSH test (code={code}):\n{out.strip()}\n{err.strip()}")
log("\n--- Check blacklisted modules (expect empty) ---")
code, out, err = run_ssh("lsmod | grep -E 'qcom_q6v5_mss|ipa'")
log(f"lsmod:\n{out.strip() or 'CLEAN (no modules loaded)'}")
log("\n--- Step 1: Check battery gate ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --battery-check")
log(f"Battery gate:\n{out.strip()}")
log("\n--- Step 2: Start rmtfs and load modules safely ---")
code, out, err = run_ssh("sudo rc-service rmtfs start; sudo /usr/local/sbin/platina-cellular --load-modules")
log(f"Load modules:\n{out.strip()}")
time.sleep(3)
log("\n--- Step 3: Check IPA sysfs endpoints ---")
code, out, err = run_ssh("cat /sys/devices/platform/soc@0/14780000.ipa/modem/tx_endpoint_id 2>/dev/null; echo '---'; cat /sys/devices/platform/soc@0/14780000.ipa/modem/rx_endpoint_id 2>/dev/null")
log(f"IPA endpoints:\n{out.strip()}")
log("\n--- Step 4: Lock RF bands (LTE B1,B3) and bring online ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --optimize-rf --rat lte --bands 1,3; sudo /usr/local/sbin/platina-cellular --online")
log(f"RF lock and online:\n{out.strip()}")
time.sleep(3)
log("\n--- Step 5: Activate cellular data ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --auto --once")
log(f"Cellular data setup:\n{out.strip()}")
log("\n--- Step 6: Check ip route and ping ---")
code, out, err = run_ssh("ip route; ping -c 4 -I rmnet_ipa0 1.1.1.1 2>&1 || ping -c 4 1.1.1.1 2>&1")
log(f"Connectivity test:\n{out.strip()}")
log("\n--- Step 7: Check EasyTier mesh status ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-mesh --status 2>&1")
log(f"EasyTier mesh status:\n{out.strip()}")
log("\n=== Direct boot and controlled bringup completed successfully! ===")
if __name__ == "__main__":
main()