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

138 lines
5.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Listen for Fastboot, flash the bulletproof boot image permanently to eMMC boot partition,
reboot, wait for OpenRC with native USB handoff, and execute cellular bringup + EasyTier mesh.
"""
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_mac_network():
service = "Xiaomi Mi 8 Lite"
log(f"Configuring macOS '{service}' network service...")
try:
subprocess.run(["networksetup", "-setnetworkserviceenabled", service, "on"], capture_output=True, timeout=5)
subprocess.run(["networksetup", "-setmanual", service, "172.16.42.2", "255.255.255.0", "172.16.42.1"], capture_output=True, timeout=5)
log("macOS network configuration applied.")
except Exception as e:
log(f"Warning: {e}")
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 main():
log("=== Fastboot Auto-Flash & Bringup Initiated ===")
log("Waiting for device in Fastboot mode (press Volume-Down + Power to enter)...")
serial = None
while True:
try:
res = subprocess.run(["fastboot", "devices"], capture_output=True, text=True, timeout=3)
lines = [l.strip() for l in res.stdout.splitlines() if l.strip()]
if lines:
serial = lines[0].split()[0]
log(f">>> Fastboot device DETECTED: {serial} <<<")
break
except Exception:
pass
time.sleep(0.5)
# 1. Flash boot partition permanently
log(f"1. Flashing bulletproof kernel image to eMMC boot partition...")
res = subprocess.run(["fastboot", "flash", "boot", BOOT_IMG], capture_output=True, text=True, timeout=30)
log(f"fastboot flash output:\n{res.stdout.strip()}\n{res.stderr.strip()}")
if res.returncode != 0:
log(f"ERROR: fastboot flash boot failed!")
return 1
# 2. Reboot phone natively
log("2. Rebooting phone natively...")
res = subprocess.run(["fastboot", "reboot"], capture_output=True, text=True, timeout=10)
log(f"fastboot reboot output: {res.stdout.strip()}")
log("Phone rebooting! Waiting for OpenRC userspace...")
time.sleep(10)
reset_mac_network()
# 3. Wait for SSH port 22
log("3. Waiting for SSH port 22 on 172.16.42.1...")
start = time.time()
ssh_up = False
while time.time() - start < 120:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
try:
s.connect((TARGET_IP, 22))
s.close()
log(f"SUCCESS: 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.")
return 1
time.sleep(2)
log("4. Logging in via SSH and verifying system health...")
code, out, err = run_ssh("uname -a; uptime; cat /sys/class/power_supply/qcom-battery/voltage_now; cat /sys/class/power_supply/qcom-battery/capacity; cat /sys/class/power_supply/qcom-battery/status")
log(f"System status (code={code}):\n{out.strip()}")
log("\n--- Checking blacklisted modules (expect empty) ---")
code, out, err = run_ssh("lsmod | grep -E 'qcom_q6v5_mss|ipa'")
log(f"Loaded modem modules:\n{out.strip()}")
log("\n--- Step 1: Check Battery Gate Policy ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --battery-gate")
log(f"Battery gate result (code={code}):\n{out.strip()}")
log("\n--- Step 2: Start rmtfs and load modem/IPA modules safely ---")
code, out, err = run_ssh("sudo rc-service rmtfs start; sudo /usr/local/sbin/platina-cellular --load-modules")
log(f"Load modules result (code={code}):\n{out.strip()}")
log("\n--- Step 3: Verify IPA sysfs endpoints (expect fixed TX: 3, RX: 16) ---")
code, out, err = run_ssh("cat /sys/devices/platform/soc@0/14780000.ipa/modem/tx_endpoint_id; cat /sys/devices/platform/soc@0/14780000.ipa/modem/rx_endpoint_id")
log(f"IPA sysfs endpoints (code={code}):\n{out.strip()}")
log("\n--- Step 4: Lock RAT to LTE and bands to China Unicom (1,3), 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 result (code={code}):\n{out.strip()}")
log("\n--- Step 5: Activate cellular data connection ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --auto --once")
log(f"Cellular data setup (code={code}):\n{out.strip()}")
log("\n--- Step 6: Test cellular data path ping ---")
code, out, err = run_ssh("ip addr show rmnet_ipa0 2>/dev/null; ip route; ping -c 4 -I rmnet_ipa0 1.1.1.1 2>/dev/null || ping -c 4 1.1.1.1")
log(f"Connectivity test (code={code}):\n{out.strip()}")
log("\n--- Step 7: Check EasyTier mesh status and ping Tokyo node ---")
code, out, err = run_ssh("sudo rc-service easytier status || sudo rc-service easytier start; sudo /usr/local/sbin/platina-mesh --status; ping -c 4 192.168.20.2")
log(f"EasyTier mesh status (code={code}):\n{out.strip()}")
log("\n=== Complete Platina Bringup Successful! ===")
return 0
if __name__ == "__main__":
sys.exit(main())