flash-edl: block host qcserial driver and remove sleep after Fastboot EDL kick

This commit is contained in:
Luxferre
2026-10-25 10:04:47 +02:00
parent 519c25c022
commit 7a20ac08ca
2 changed files with 44 additions and 18 deletions
+20 -18
View File
@@ -110,12 +110,15 @@ def _fb_upgrade_lk2nd_and_edl(fb_dev):
time.sleep(0.3)
_fb_send_edl(new_fb)
usb.util.dispose_resources(new_fb)
time.sleep(1.0)
return
time.sleep(0.5)
_fb_edl_kicked = False
def try_kick_into_edl():
global _fb_edl_kicked
try:
res = subprocess.run(
["adb", "get-state"],
@@ -127,7 +130,6 @@ def try_kick_into_edl():
if res.returncode == 0 and "device" in res.stdout:
print("[*] Detected device in ADB mode. Sending 'adb reboot edl'...")
subprocess.run(["adb", "reboot", "edl"], timeout=5)
time.sleep(1)
return
except Exception:
pass
@@ -136,13 +138,13 @@ def try_kick_into_edl():
try:
fb_dev = usb.core.find(idVendor=0x18D1, idProduct=0xD00D)
if fb_dev is not None:
print("[*] Detected device in Fastboot mode (18d1:d00d). Sending 'oem reboot-edl'...")
_fb_send_edl(fb_dev)
usb.util.dispose_resources(fb_dev)
time.sleep(1.5)
fb_still = usb.core.find(idVendor=0x18D1, idProduct=0xD00D)
if fb_still is not None:
_fb_upgrade_lk2nd_and_edl(fb_still)
if not _fb_edl_kicked:
_fb_edl_kicked = True
print("[*] Detected device in Fastboot mode (18d1:d00d). Sending 'oem reboot-edl'...")
_fb_send_edl(fb_dev)
usb.util.dispose_resources(fb_dev)
else:
_fb_upgrade_lk2nd_and_edl(fb_dev)
return
except Exception:
pass
@@ -160,15 +162,12 @@ def try_kick_into_edl():
rc = subprocess.run(["fastboot", "oem", "reboot-edl"], timeout=5)
if rc.returncode != 0:
subprocess.run(["fastboot", "oem", "edl"], timeout=5)
time.sleep(1)
except Exception:
pass
def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0):
cdc = usb_class(vid=vid, pid=pid)
try_kick_into_edl()
print(
f"[*] Waiting for {device_label} in EDL mode "
f"(USB {vid:04x}:{pid:04x} Qualcomm QDLoader 9008)..."
@@ -179,6 +178,8 @@ def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0):
print(" 3) Plug in via an EDL deep-flash cable")
print(" 4) Run 'adb reboot edl' or 'fastboot oem reboot-edl'")
try_kick_into_edl()
start_ts = time.time()
dots = 0
while not cdc.connected:
@@ -191,7 +192,7 @@ def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0):
"Please run via sudo (e.g. sudo ./flash-edl.sh)."
)
sys.exit(1)
time.sleep(0.5)
time.sleep(0.05)
continue
if cdc.connected:
@@ -206,15 +207,16 @@ def wait_for_edl_usb(vid, pid, device_label, timeout_sec=0):
print(f"[!] Timed out after {timeout_sec} seconds waiting for EDL device.")
sys.exit(1)
if dots > 0 and dots % 10 == 0:
if dots > 0 and dots % 100 == 0:
try_kick_into_edl()
sys.stdout.write(".")
sys.stdout.flush()
if dots % 20 == 0:
sys.stdout.write(".")
sys.stdout.flush()
dots += 1
if dots % 40 == 0:
if dots % 800 == 0:
sys.stdout.write("\n")
time.sleep(1)
time.sleep(0.05)
return cdc
+24
View File
@@ -27,15 +27,39 @@ if command -v systemctl >/dev/null 2>&1; then
systemctl stop ModemManager 2>/dev/null || true
MM_WAS_ACTIVE=1
fi
elif command -v sv >/dev/null 2>&1 && [ -e /var/service/ModemManager ]; then
if sv status ModemManager 2>/dev/null | grep -q "^run:"; then
echo "[*] Temporarily stopping host ModemManager service during EDL flash..."
sv stop ModemManager 2>/dev/null || true
MM_WAS_ACTIVE=2
fi
fi
QCSERIAL_CONF="/run/modprobe.d/bananarchy-edl.conf"
if [ "$(id -u)" -eq 0 ]; then
mkdir -p /run/modprobe.d 2>/dev/null || true
printf "blacklist qcserial\ninstall qcserial /bin/true\n" > "$QCSERIAL_CONF" 2>/dev/null || true
if lsmod 2>/dev/null | grep -q "^qcserial "; then
echo "[*] Unloading host qcserial kernel module so it does not claim 05c6:9008..."
modprobe -r qcserial 2>/dev/null || rmmod qcserial 2>/dev/null || true
fi
udevadm control --reload 2>/dev/null || true
fi
cleanup() {
if [ -f "$QCSERIAL_CONF" ]; then
rm -f "$QCSERIAL_CONF" 2>/dev/null || true
udevadm control --reload 2>/dev/null || true
fi
if [ -n "${SUDO_UID:-}" ] && [ -n "${SUDO_GID:-}" ] && [ -d "$BASE_DIR/backup" ]; then
chown -R "$SUDO_UID:$SUDO_GID" "$BASE_DIR/backup" 2>/dev/null || true
fi
if [ "$MM_WAS_ACTIVE" -eq 1 ]; then
echo "[*] Restarting host ModemManager service..."
systemctl start ModemManager 2>/dev/null || true
elif [ "$MM_WAS_ACTIVE" -eq 2 ]; then
echo "[*] Restarting host ModemManager service..."
sv start ModemManager 2>/dev/null || true
fi
}
trap cleanup EXIT INT TERM