raspberrypi / usbboot

Raspberry Pi USB booting code, moved from tools repository
Apache License 2.0
878 stars 221 forks source link

When launched with udev rule the boot does not complete with Raspberry pi zero #130

Closed pgodiani closed 6 months ago

pgodiani commented 2 years ago

I'm attempting to usbboot a raspberry pi zero from a raspberry pi 4. This works perfectly when usbboot is run from command line. However, when adding the following rule to udev rules:

SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{ID_VENDOR_ID}=="0a5c", ENV{ID_MODEL_ID}=="2763" RUN="/usr/bin/rpiboot -d /slave/boot"

the boot never completes unexpectedly, I've amended the code and added traces to syslog.

rpiboot[10229]: RPIBOOT: build-date Apr 12 2022 version 20220315~121405 1e27dd85 rpiboot[10229]: Boot directory '/slave/boot' ... rpiboot[10229]: Found candidate device 4 idVendor=0x0a5c idProduct=0x2763 ... rpiboot[10229]: libusb_bulk_transfer sent 52456 bytes; returned 0 rpiboot[10229]: Successful read 4 bytes kernel: [5254411.325898] usb 1-1.3: USB disconnect, device number 81 rpiboot[10229]: Waiting for BCM2835/6/7/2711... rpiboot[10229]: Found candidate device 4 idVendor=0x0a5c idProduct=0x2763 rpiboot[10229]: Bus: 1, Device: 81 Path: rpiboot[10229]: Found /slave/boot/bootcode.bin rpiboot[10229]: Second stage files loaded into memory rpiboot[10229]: Device located on port 3 kernel: [5254412.614048] usb 1-1.3: new full-speed USB device number 82 using xhci_hcd kernel: [5254412.745911] usb 1-1.3: not running at top speed; connect to a high speed hub kernel: [5254412.751910] usb 1-1.3: New USB device found, idVendor=0a5c, idProduct=2764, bcdDevice= 0.00 kernel: [5254412.751925] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=1 kernel: [5254412.751938] usb 1-1.3: Product: BCM2710 Boot kernel: [5254412.751950] usb 1-1.3: Manufacturer: Broadcom kernel: [5254412.751962] usb 1-1.3: SerialNumber: Broadcom rpiboot[10229]: Device vanished between detection and opening

Then, nothing happens, just udev stating that the spawn process takes too long to complete (>50s). From my understanding, when the device that triggered the rule is disconnected, the usb enumeration from libusb does not detect new connections. Hence, when the pi zero comes back with 2764 the second stage boot never goes forward.

This is apparently solved by just terminating usbboot when libusb_open returns LIBUSB_ERROR_NO_DEVICE instead of nulling the handle and reenter the detection loop.

Would it be possible to make that change or to adjust usbboot to work with RaspiZ & udev ?

timg236 commented 6 months ago

Closed due to inactivity.