fix(#5): add USB retry logic for LIBUSB_ERROR_PIPE

Resolves #5: LIBUSB_ERROR_PIPE

Root cause: USB control transfers had zero retry logic. LIBUSB_ERROR_PIPE
(-9) is a transient STALL that commonly occurs on A12+ devices during DFU
operations and typically clears on retry. Additionally, path_b_identity.c
called libusb_control_transfer directly, bypassing the usb_helpers wrapper
entirely.

Changes:
- usb_ctrl_transfer/usb_ctrl_transfer_no_data now retry up to 3 times on
  PIPE and TIMEOUT errors with 50ms delay between attempts
- usb_print_error provides actionable troubleshooting steps for PIPE errors
- path_b_identity.c now uses usb_ctrl_transfer (retry-aware) instead of
  calling libusb_control_transfer directly
- usb_dfu_read_info adds retry logic for serial descriptor reads
- start.sh: handle_dfu_requirement now guides A12+ Path B devices into DFU
  (previously only guided checkm8 Path A devices)
- start.sh: DFU-mode detection now queries CPID to correctly identify
  Path A vs Path B (previously assumed all DFU devices were Path A)

Files modified:
- src/util/usb_helpers.c
- src/bypass/path_b_identity.c
- src/device/usb_dfu.c
- start.sh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-12 20:02:14 +02:00
parent 92e9f99f25
commit 58f04f2be0
4 changed files with 110 additions and 51 deletions

View file

@ -482,13 +482,24 @@ main() {
display_device_info
gate_support
else
# DFU mode -- limited info, but checkm8 path is implied
# DFU mode -- query CPID from serial descriptor to determine path
msg_info "Device in DFU mode. Querying chip info..."
parse_device_info
local dfu_bypass="auto-detect"
if [ "$DEV_CHECKM8" = "YES" ]; then
dfu_bypass="Path A (checkm8, A5-A11)"
elif [ -n "$DEV_CPID" ] && [ "$DEV_CPID" != "0x0000" ]; then
dfu_bypass="Path B (identity, A12+)"
fi
echo ""
echo "========================================"
echo " Device Information"
echo "========================================"
printf " %-12s %s\n" "Mode:" "DFU"
printf " %-12s %s\n" "Bypass:" "Path A (checkm8)"
printf " %-12s %s\n" "Chip:" "${DEV_CHIP_NAME:-(unknown)} (CPID: ${DEV_CPID:-(unknown)})"
printf " %-12s %s\n" "Bypass:" "$dfu_bypass"
printf " %-12s %s\n" "Status:" "SUPPORTED (DFU detected)"
echo "========================================"
echo ""