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
195 lines
8.5 KiB
Python
195 lines
8.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Live patch running initramfs and sysroot via Telnet, then continue boot into OpenRC:
|
|
1. Replace beebzzr with exit 0 (eliminate motor inrush current brownout)
|
|
2. Replace check_filesystem with return 0 (eliminate Volume Up hang)
|
|
3. Fix setup_usb_configfs_udc so it preserves UDC link
|
|
4. Clean up sysroot services (remove broken platina-usb-gadget, usb-moded, battery-guard, power-chord)
|
|
5. Install 00-usb-network.start for guaranteed usb0 network bringup in OpenRC
|
|
6. Verify modem blacklist
|
|
7. Sync and unmount /sysroot
|
|
8. Trigger /sbin/pmos_continue_boot
|
|
9. Reset Mac network service to clear any stale REJECT routes
|
|
10. Connect SSH and execute full cellular 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"
|
|
|
|
def log(msg):
|
|
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
|
|
|
|
def telnet_read_until_prompt(s, timeout=15):
|
|
s.settimeout(timeout)
|
|
buf = ""
|
|
start = time.time()
|
|
while time.time() - start < timeout:
|
|
try:
|
|
chunk = s.recv(4096).decode("utf-8", errors="replace")
|
|
if not chunk:
|
|
break
|
|
buf += chunk
|
|
if "~ # " in buf or "/ # " in buf:
|
|
return buf
|
|
except socket.timeout:
|
|
break
|
|
return buf
|
|
|
|
def telnet_cmd(s, cmd, timeout=15):
|
|
log(f"Telnet -> {cmd}")
|
|
s.sendall((cmd + "\n").encode("utf-8"))
|
|
out = telnet_read_until_prompt(s, timeout)
|
|
log(f"Telnet <- {out.strip()}")
|
|
return out
|
|
|
|
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 reset_mac_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("macOS network service reset completed.")
|
|
|
|
def main():
|
|
log("Connecting to live Telnet session at 172.16.42.1:23...")
|
|
s = socket.socket()
|
|
s.settimeout(5)
|
|
s.connect((TARGET_IP, 23))
|
|
telnet_read_until_prompt(s, timeout=3)
|
|
|
|
log("1. Disabling vibrator motor (beebzzr)...")
|
|
telnet_cmd(s, "echo -e '#!/bin/sh\\nexit 0' > /usr/bin/beebzzr; chmod +x /usr/bin/beebzzr")
|
|
telnet_cmd(s, "sed -i 's/beebzzr &# beebzzr disabled/' /init_2nd.sh 2>/dev/null || true")
|
|
|
|
log("2. Patching check_filesystem to eliminate Volume-Up hang...")
|
|
telnet_cmd(s, "sed -i '/check_filesystem() {/,/^}/c\\check_filesystem() {\\n\\treturn 0\\n}' /init_functions.sh")
|
|
|
|
log("3. Patching setup_usb_configfs_udc to prevent UDC flapping...")
|
|
telnet_cmd(s, "sed -i 's/echo \"\" > \"$CONFIGFS\"\\/g1\\/UDC/# echo \"\" > \"$CONFIGFS\"\\/g1\\/UDC/' /init_functions.sh 2>/dev/null || true")
|
|
|
|
log("4. Mounting /sysroot...")
|
|
telnet_cmd(s, "mount_root_partition 2>/dev/null || mount /dev/mmcblk1p79 /sysroot 2>/dev/null")
|
|
|
|
log("5. Cleaning up sysroot services...")
|
|
telnet_cmd(s, "rm -f /sysroot/etc/runlevels/boot/platina-usb-gadget /sysroot/etc/init.d/platina-usb-gadget /sysroot/usr/local/sbin/platina-usb-gadget 2>/dev/null || true")
|
|
telnet_cmd(s, "rm -f /sysroot/etc/runlevels/default/platina-battery-guard /sysroot/etc/runlevels/boot/platina-battery-guard 2>/dev/null || true")
|
|
telnet_cmd(s, "rm -f /sysroot/etc/runlevels/default/platina-power-chord /sysroot/etc/runlevels/boot/platina-power-chord 2>/dev/null || true")
|
|
telnet_cmd(s, "rm -f /sysroot/etc/runlevels/default/usb-moded /sysroot/etc/runlevels/boot/usb-moded 2>/dev/null || true")
|
|
telnet_cmd(s, "rm -f /sysroot/etc/runlevels/default/modemmanager 2>/dev/null || true")
|
|
|
|
log("6. Installing 00-usb-network.start for robust OpenRC userspace networking...")
|
|
telnet_cmd(s, "mkdir -p /sysroot/etc/local.d")
|
|
telnet_cmd(s, "echo -e '#!/bin/sh\\nip addr add 172.16.42.1/24 dev usb0 2>/dev/null || true\\nip link set usb0 up 2>/dev/null || true' > /sysroot/etc/local.d/00-usb-network.start")
|
|
telnet_cmd(s, "chmod +x /sysroot/etc/local.d/00-usb-network.start")
|
|
|
|
log("7. Ensuring modem blacklist...")
|
|
telnet_cmd(s, "mkdir -p /sysroot/etc/modprobe.d")
|
|
telnet_cmd(s, "echo 'install qcom_q6v5_mss /bin/true' > /sysroot/etc/modprobe.d/modem-blacklist.conf")
|
|
telnet_cmd(s, "echo 'install ipa /bin/true' >> /sysroot/etc/modprobe.d/modem-blacklist.conf")
|
|
telnet_cmd(s, "echo 'blacklist qcom_q6v5_mss' >> /sysroot/etc/modprobe.d/modem-blacklist.conf")
|
|
telnet_cmd(s, "echo 'blacklist ipa' >> /sysroot/etc/modprobe.d/modem-blacklist.conf")
|
|
|
|
log("8. Ensuring critical runlevel links...")
|
|
telnet_cmd(s, "ln -sf /etc/init.d/local /sysroot/etc/runlevels/default/local 2>/dev/null || true")
|
|
telnet_cmd(s, "ln -sf /etc/init.d/sshd /sysroot/etc/runlevels/default/sshd 2>/dev/null || true")
|
|
telnet_cmd(s, "ln -sf /etc/init.d/networkmanager /sysroot/etc/runlevels/default/networkmanager 2>/dev/null || true")
|
|
|
|
log("9. Syncing and cleanly unmounting /sysroot...")
|
|
telnet_cmd(s, "sync")
|
|
telnet_cmd(s, "umount /sysroot 2>/dev/null || true")
|
|
|
|
log("10. Triggering /sbin/pmos_continue_boot...")
|
|
s.sendall(b"/sbin/pmos_continue_boot\n")
|
|
time.sleep(1)
|
|
s.close()
|
|
log("pmos_continue_boot sent! Telnet closed.")
|
|
|
|
# Wait 6s then reset Mac network to ensure clean routing
|
|
time.sleep(6)
|
|
reset_mac_network()
|
|
|
|
log("11. Waiting for SSH port 22 on 172.16.42.1...")
|
|
start = time.time()
|
|
ssh_up = False
|
|
while time.time() - start < 90:
|
|
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("12. Logging in via SSH...")
|
|
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=== Complete Platina Bringup Successful! ===")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|