Offline project checks / check (push) Canceled after 0s
- 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
149 lines
5.6 KiB
Python
Executable File
149 lines
5.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Watch for phone reconnection (Fastboot, Telnet, or SSH).
|
|
Automatically disarms modem autoloading and ModemManager to prevent RF burst brownout.
|
|
"""
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
TARGET_IP = "172.16.42.1"
|
|
SSH_KEY = "/Users/shenlei/Work/sshKey/oracle_tokyo_ARM.key"
|
|
|
|
def log(msg):
|
|
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
|
|
|
|
def check_fastboot():
|
|
try:
|
|
res = subprocess.run(["fastboot", "devices"], stdout=subprocess.PIPE, text=True, timeout=1)
|
|
fb = res.stdout.strip()
|
|
if fb:
|
|
return fb
|
|
except Exception:
|
|
pass
|
|
return None
|
|
|
|
def check_usb_device():
|
|
try:
|
|
res = subprocess.run(["ioreg", "-p", "IOUSB", "-l"], stdout=subprocess.PIPE, text=True, timeout=2)
|
|
for line in res.stdout.splitlines():
|
|
if any(k in line.lower() for k in ["xiaomi", "platina", "android", "qualcomm", "05c6", "gadget"]):
|
|
return line.strip()
|
|
except Exception:
|
|
pass
|
|
return None
|
|
|
|
def check_interface_up():
|
|
try:
|
|
res = subprocess.run(["ifconfig"], stdout=subprocess.PIPE, text=True, timeout=2)
|
|
return "172.16.42." in res.stdout
|
|
except Exception:
|
|
return False
|
|
|
|
def telnet_exec(cmds):
|
|
try:
|
|
s = socket.socket()
|
|
s.settimeout(5.0)
|
|
s.connect((TARGET_IP, 23))
|
|
time.sleep(0.5)
|
|
for cmd in cmds:
|
|
s.sendall((cmd + "\n").encode("utf-8"))
|
|
time.sleep(0.3)
|
|
time.sleep(1.0)
|
|
out = ""
|
|
try:
|
|
out = s.recv(4096).decode("utf-8", errors="replace")
|
|
except socket.timeout:
|
|
pass
|
|
s.close()
|
|
return out
|
|
except Exception as e:
|
|
return f"Telnet error: {e}"
|
|
|
|
def ssh_exec(cmd):
|
|
ssh_cmd = [
|
|
"ssh",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "ConnectTimeout=5",
|
|
"-i", SSH_KEY,
|
|
f"server@{TARGET_IP}",
|
|
cmd
|
|
]
|
|
try:
|
|
res = subprocess.run(ssh_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=15)
|
|
return res.returncode, res.stdout, res.stderr
|
|
except Exception as e:
|
|
return -1, "", str(e)
|
|
|
|
def main():
|
|
log("Waiting for phone to appear on USB / Fastboot / Network...")
|
|
last_reported = 0
|
|
|
|
while True:
|
|
fb = check_fastboot()
|
|
if fb:
|
|
log(f"Detected FASTBOOT device: {fb}")
|
|
|
|
usb = check_usb_device()
|
|
if usb:
|
|
log(f"Detected USB device: {usb}")
|
|
|
|
if check_interface_up():
|
|
log("Host network interface (172.16.42.x) is UP!")
|
|
# Check telnet first (initramfs debug shell)
|
|
try:
|
|
s = socket.socket()
|
|
s.settimeout(1.0)
|
|
s.connect((TARGET_IP, 23))
|
|
s.close()
|
|
log("Initramfs Telnet (port 23) is OPEN! Mounting root and disarming rootfs autoload...")
|
|
disarm_cmds = [
|
|
"cat /sys/class/power_supply/qcom-battery/capacity /sys/class/power_supply/qcom-battery/voltage_now",
|
|
"mount_root_partition 2>/dev/null || mount /dev/disk/by-label/pmOS_root /sysroot 2>/dev/null",
|
|
"if [ -d /sysroot/etc ]; then "
|
|
"mkdir -p /sysroot/etc/modprobe.d && "
|
|
"echo 'blacklist qcom_q6v5_mss' > /sysroot/etc/modprobe.d/modem-blacklist.conf && "
|
|
"echo 'blacklist ipa' >> /sysroot/etc/modprobe.d/modem-blacklist.conf && "
|
|
"sed -i '/qcom_q6v5_mss/d' /sysroot/etc/modules-load.d/modem.conf 2>/dev/null; "
|
|
"sed -i '/ipa/d' /sysroot/etc/modules-load.d/modem.conf 2>/dev/null; "
|
|
"rm -f /sysroot/etc/runlevels/default/modemmanager 2>/dev/null; "
|
|
"mv /sysroot/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service /sysroot/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service.disabled 2>/dev/null; "
|
|
"echo 'UseDNS no' >> /sysroot/etc/ssh/sshd_config 2>/dev/null; "
|
|
"echo '===PERFECT_DISARM_SUCCESS==='; "
|
|
"cat /sysroot/etc/modprobe.d/modem-blacklist.conf 2>/dev/null; "
|
|
"sync; "
|
|
"umount /sysroot 2>/dev/null; "
|
|
"fi",
|
|
"sync",
|
|
"umount /mnt 2>/dev/null",
|
|
"/sbin/pmos_continue_boot"
|
|
]
|
|
out = telnet_exec(disarm_cmds)
|
|
log(f"Telnet disarm response:\n{out}")
|
|
time.sleep(3)
|
|
continue
|
|
except Exception:
|
|
pass
|
|
|
|
# Check SSH
|
|
try:
|
|
s = socket.socket()
|
|
s.settimeout(1.0)
|
|
s.connect((TARGET_IP, 22))
|
|
s.close()
|
|
log("SSH (port 22) is OPEN! Disarming via SSH...")
|
|
ret, out, err = ssh_exec("sudo rc-service modemmanager stop 2>/dev/null; sudo qmicli -d qrtr://0 --dms-set-operating-mode=low-power 2>/dev/null; sudo sed -i '/qcom_q6v5_mss/d' /etc/modules-load.d/modem.conf 2>/dev/null; sudo sed -i '/ipa/d' /etc/modules-load.d/modem.conf 2>/dev/null; sudo rc-update del modemmanager default 2>/dev/null; echo 'SSH_DISARM_COMPLETE'")
|
|
log(f"SSH disarm ret={ret}, out={out.strip()}, err={err.strip()}")
|
|
if ret == 0:
|
|
log("Successfully disarmed modem via SSH! Ready for controlled bringup.")
|
|
break
|
|
except Exception:
|
|
pass
|
|
|
|
time.sleep(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|