#!/usr/bin/env python3 """ Bulletproof bringup: 1. Wait for Fastboot device (63c36adb) 2. Boot boot-bulletproof-direct.img (bypasses fsck volume up hang, vibrator pulse, removes early poweroff daemons, injects 00-usb-network.start) 3. Reset macOS network service to clear any stale REJECT routes 4. Wait for SSH port 22 on 172.16.42.1 5. Execute end-to-end cellular data bringup + EasyTier mesh """ 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-bulletproof-direct.img" def log(msg): print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True) def reset_host_network(): log("Resetting macOS 'Xiaomi Mi 8 Lite' network service to clear stale routes...") subprocess.run(["networksetup", "-setnetworkserviceenabled", "Xiaomi Mi 8 Lite", "off"], capture_output=True) time.sleep(1) subprocess.run(["networksetup", "-setnetworkserviceenabled", "Xiaomi Mi 8 Lite", "on"], capture_output=True) time.sleep(0.5) subprocess.run(["networksetup", "-setmanual", "Xiaomi Mi 8 Lite", "172.16.42.2", "255.255.255.0"], capture_output=True) log("Host network service reset completed.") def is_usb_interface_active(): res = subprocess.run(["ifconfig", "en21"], capture_output=True, text=True) return "status: active" in res.stdout 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 device boot...") # Wait 8s for kernel to initialize USB gadget time.sleep(8) reset_host_network() # Wait for SSH port 22 log("Polling SSH port 22 on 172.16.42.1...") start = time.time() ssh_up = False while time.time() - start < 90: if is_usb_interface_active(): 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 after {int(time.time() - start)}s!") 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 initial SSH login...") code, out, err = run_ssh("uname -a; uptime; cat /sys/class/power_supply/qcom-battery/voltage_now") log(f"System status (code={code}):\n{out.strip()}") # Check blacklist code, out, err = run_ssh("lsmod | grep -E 'qcom_q6v5_mss|ipa'") log(f"Check blacklisted modules (expect empty):\n{out.strip()}") # Controlled bringup 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 (expect TX:3, RX:16):\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=== Bulletproof bringup completed successfully! ===") if __name__ == "__main__": main()