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
181 lines
6.8 KiB
Python
181 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Interactive telnet session with prompt matching, to cleanly configure
|
|
sysroot USB gadget service and continue boot to OpenRC.
|
|
"""
|
|
import http.server
|
|
import socket
|
|
import socketserver
|
|
import subprocess
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
TARGET_IP = "172.16.42.1"
|
|
HOST_IP = "172.16.42.2"
|
|
HTTP_PORT = 9879
|
|
SSH_KEY = "/Users/shenlei/Work/sshKey/oracle_tokyo_ARM.key"
|
|
|
|
def log(msg):
|
|
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
|
|
|
|
class QuietHandler(http.server.SimpleHTTPRequestHandler):
|
|
def log_message(self, format, *args):
|
|
pass
|
|
|
|
def start_http_server():
|
|
server = socketserver.TCPServer(("0.0.0.0", HTTP_PORT), QuietHandler)
|
|
t = threading.Thread(target=server.serve_forever, daemon=True)
|
|
t.start()
|
|
return server
|
|
|
|
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 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_interact():
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.connect((TARGET_IP, 23))
|
|
time.sleep(0.3)
|
|
telnet_read_until_prompt(s, timeout=3)
|
|
|
|
http_srv = start_http_server()
|
|
log(f"HTTP server running on port {HTTP_PORT}")
|
|
|
|
commands = [
|
|
# Check battery
|
|
"cat /sys/class/power_supply/qcom-battery/capacity /sys/class/power_supply/qcom-battery/voltage_now",
|
|
# Ensure root partition is mounted
|
|
"mountpoint -q /sysroot || mount_root_partition || mount /dev/mmcblk1p79 /sysroot",
|
|
# 1. Disarm rules in modprobe.d
|
|
"mkdir -p /sysroot/etc/modprobe.d",
|
|
"cat << 'EOF' > /sysroot/etc/modprobe.d/modem-blacklist.conf\ninstall qcom_q6v5_mss /bin/true\ninstall ipa /bin/true\nblacklist qcom_q6v5_mss\nblacklist ipa\nEOF",
|
|
"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",
|
|
# 2. Disable ModemManager D-Bus autostart
|
|
"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 || true",
|
|
"rm -f /sysroot/etc/runlevels/default/modemmanager",
|
|
# 3. Remove broken usb-moded from runlevel
|
|
"rm -f /sysroot/etc/runlevels/default/usb-moded",
|
|
# 4. Create robust userspace USB gadget service
|
|
f"wget -O /tmp/setup_gadget.sh http://{HOST_IP}:{HTTP_PORT}/scripts/setup_usb_gadget_service.sh",
|
|
"sh /tmp/setup_gadget.sh",
|
|
"ls -la /sysroot/etc/runlevels/boot/*gadget* /sysroot/usr/local/sbin/*gadget*",
|
|
# 5. Deploy updated cellular script
|
|
f"wget -O /sysroot/usr/local/sbin/platina-cellular http://{HOST_IP}:{HTTP_PORT}/scripts/phone-cellular-setup.py",
|
|
"chmod +x /sysroot/usr/local/sbin/platina-cellular",
|
|
# 6. Verify filesystem and clean unmount
|
|
"sync",
|
|
"umount /sysroot",
|
|
"e2fsck -p /dev/mmcblk1p79",
|
|
# 7. Continue boot
|
|
"/sbin/pmos_continue_boot"
|
|
]
|
|
|
|
for cmd in commands:
|
|
log(f"CMD: {cmd.splitlines()[0]}")
|
|
s.sendall((cmd + "\n").encode("utf-8"))
|
|
if cmd == "/sbin/pmos_continue_boot":
|
|
time.sleep(1)
|
|
break
|
|
res = telnet_read_until_prompt(s, timeout=8)
|
|
log(f"OUT:\n{res.strip()}\n")
|
|
|
|
s.close()
|
|
http_srv.shutdown()
|
|
log("Telnet configuration complete! Disconnected telnet.")
|
|
|
|
def main():
|
|
log("1. Interacting with initramfs over Telnet...")
|
|
telnet_interact()
|
|
|
|
log("2. Waiting for OpenRC userspace boot (SSH port 22)...")
|
|
start = time.time()
|
|
ssh_ready = False
|
|
while time.time() - start < 60:
|
|
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_ready = True
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(1)
|
|
|
|
if not ssh_ready:
|
|
log("ERROR: Timed out waiting for SSH port 22.")
|
|
sys.exit(1)
|
|
|
|
time.sleep(3)
|
|
log("3. 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()}")
|
|
|
|
# Verify blacklisted modules are NOT loaded
|
|
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:\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 3 -I rmnet_ipa0 1.1.1.1 2>&1 || ping -c 3 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=== Controlled bringup completed successfully! ===")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|