Attach a GPS in preboot mode

Hello everyone and best wishes for 2023 :) I have an old *Garmin Drive Smart 50 GPS* and I want to be able to attach it when it is in preboot mode to a VM hosted by a *Debian 11 host*. From what I understand, the preboot mode allows us to flash a firmware before the GPS actually starts (used among other things when the GPS is soft bricked). When I connect the GPS to the host it gives: |root@host:~# journalctl -kf|| ||# GPS in MTP storage mode (default when reset)|| ||...|| ||janv. 23 23:02:51 host kernel: usb 2-4: New USB device found, idVendor=091e, idProduct=48db, bcdDevice= 0.01|| ||janv. 23 23:02:51 host kernel: usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=5|| ||...|| ||# GPS in mass storage mode|| ||...|| ||janv. 23 23:01:29 host kernel: usb 2-4: New USB device found, idVendor=091e, idProduct=28db, bcdDevice= 5.09|| ||janv. 23 23:01:29 host kernel: usb 2-4: New USB device strings: Mfr=0, Product=0, SerialNumber=5|| ||...|| ||# GPS in preboot mode|| ||...|| ||janv. 23 23:09:05 host kernel: usb 2-4: New USB device found, idVendor=091e, idProduct=0003, bcdDevice= 0.01|| ||janv. 23 23:09:05 host kernel: usb 2-4: New USB device strings: Mfr=0, Product=0, SerialNumber=0|| ||janv. 23 23:09:13 host kernel: garmin_gps ttyUSB0: Garmin GPS usb/tty converter now disconnected from ttyUSB0| ... We see that *idVendor*, *idProduct*, *bcdDevice*, *Mfr*, *Product* and *SerialNumber* vary according to the modes.We also see that the GPS is seen as a *ttyUSB0* serial device. I managed to attach the GPS in preboot mode, thanks to a script which waits for the GPS to be detected in this mode (not detailed here so as not to overload, but I can publish it if necessary) and which attaches to a VM in running (*successfully tested on Debian 11 **and**Windows 7 guests*). Here is the code that generates the XML before attaching it : |...|| ||echo "<serial type='dev'> \|| || <source path='"$( \|| || ls -1 /dev/tty* | grep -Ev "tty(|S?[0-9]+)$" \|| || )"'/> \|| || <target type='usb-serial'> \|| || <vendor id='0x"$( \|| || echo 091e \|| || )"'/> \|| || <product id='0x"$( \|| || echo 28db \|| || )"'/> \|| || </target> \|| || </serial>" > serial_device.xml|| ||virsh attach-device vm-bullseye --file serial_device.xml &|| ||...| But once attached, this is what I see in the XML configuration of my VM (from *virt-manager*) : |<serial type="dev">|| || <source path="/dev/ttyUSB1"/>|| || <target type="usb-serial" port="1">|| || <model name="usb-serial"/>|| || </target>|| || <alias name="serial1"/>|| || <address type="usb" bus="0" port="4"/>|| ||</serial>| We see that libvirt has removed the *vendor/product id* from the XML. Also here is what I get from a *Debian 11 guest* : |root@vm-bullseye:~# journalctl -k -f|| ||...|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: new full-speed USB device number 2 using uhci_hcd|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 4.00|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=4|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: Product: QEMU USB SERIAL|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: Manufacturer: QEMU|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: SerialNumber: 1-0000:00:05.7-4|| ||janv. 23 21:26:22 vm-bullseye kernel: usbcore: registered new interface driver usbserial_generic|| ||janv. 23 21:26:22 vm-bullseye kernel: usbserial: USB Serial support registered for generic|| ||janv. 23 21:26:22 vm-bullseye kernel: usbcore: registered new interface driver ftdi_sio|| ||janv. 23 21:26:22 vm-bullseye kernel: usbserial: USB Serial support registered for FTDI USB Serial Device|| ||janv. 23 21:26:22 vm-bullseye kernel: ftdi_sio 3-2:1.0: FTDI USB Serial Device converter detected|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: Detected FT232BM|| ||janv. 23 21:26:22 vm-bullseye kernel: usb 3-2: FTDI USB Serial Device converter now attached to ttyUSB0|| ||janv. 23 21:26:25 vm-bullseye kernel: usb 3-2: USB disconnect, device number 2|| ||janv. 23 21:26:25 vm-bullseye kernel: ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0|| ||janv. 23 21:26:25 vm-bullseye kernel: ftdi_sio 3-2:1.0: device disconnected|| ||...| The guest sees the GPS well but idVendor=*0403*, idProduct=*6001*, bcdDevice=4.00, Mfr=1, Product=2, SerialNumber=4 ... do not correspond to anything, and tools that expect GPS in preboot mode do not see it. My questions : Q1 : Is it possible ? Q2 : Am I doing it the right way ? Q3 : Is there a method to pass such a device directly (pass-through) ? Thank you in advance for the time you are going to devote to me :) With Adelphity, lnj

On Tue, Jan 24, 2023 at 00:10:46 +0100, lnj.sam@gmail.com wrote:
Hello everyone and best wishes for 2023 :)
I have an old *Garmin Drive Smart 50 GPS* and I want to be able to attach it when it is in preboot mode to a VM hosted by a *Debian 11 host*.
From what I understand, the preboot mode allows us to flash a firmware before the GPS actually starts (used among other things when the GPS is soft bricked).
When I connect the GPS to the host it gives:
[...]
My questions :
Q1 : Is it possible ?
It shpi;d be/
Q2 : Am I doing it the right way ?
I don't think so. You are using a serial device emulated which is then connected to the host side USB-tty device. A better way is simply to use USB-assignment/passthrough and have the guest OS handle also the USB side
Q3 : Is there a method to pass such a device directly (pass-through) ?
To pass a USB device use the following XML: <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x1a86'/> <product id='0x55d4'/> </source> <address type='usb' bus='0' port='4'/> </hostdev> Obviously tweak vendor/product. Alternatively when you are using virt-manager GUI there's a menu to pass any device, or by default when you have a VM window active and plug in a USB device it's passed to the VM. (It can be disabled though).

Thank you Peter and sorry for the delay ! You put me in the correct direction and the problem is now resolved :) I wrongly assumed that attaching the device to the guest in "preboot mode" should be only made in the "serial" way because I supposed that we can not attach the device as a "hostdev" before the host really detect the device as a USB device listed by "lsusb" which can take a moment. But simply attach with "hostdev" with the idVendor/idProduct given in "preboot mode" did the trick : echo "<hostdev mode='subsystem' type='usb' managed='yes'> \ <source> \ <vendor id='0x091e'/> \ <product id='0x0003'/> \ </source> \ </hostdev>" > serial_device.xml From the host (here Debian 11) when I plug the GPS, I see this : root@host:~# journalctl -kf ... févr. 04 13:11:46 host kernel: usb 2-11: new high-speed USB device number 34 using xhci_hcd févr. 04 13:11:46 host kernel: usb 2-11: New USB device found, idVendor=091e, idProduct=0003, bcdDevice= 0.01 févr. 04 13:11:46 host kernel: usb 2-11: New USB device strings: Mfr=0, Product=0, SerialNumber=0 févr. 04 13:11:46 host kernel: garmin_gps 2-11:1.0: Garmin GPS usb/tty converter detected févr. 04 13:11:46 host kernel: usb 2-11: Garmin GPS usb/tty converter now attached to ttyUSB0 févr. 04 13:11:54 host kernel: usb 2-11: USB disconnect, device number 34 févr. 04 13:11:54 host kernel: garmin_gps ttyUSB0: Garmin GPS usb/tty converter now disconnected from ttyUSB0 févr. 04 13:11:54 host kernel: garmin_gps 2-11:1.0: device disconnected ... From a guest (here Debian 11 too) when the script attach the GPS, I see this : root@guest:~# journalctl -kf ... févr. 04 13:25:58 guest kernel: usb 2-6: new high-speed USB device number 8 using ehci-pci févr. 04 13:25:58 guest kernel: usb 2-6: New USB device found, idVendor=091e, idProduct=0003, bcdDevice= 0.01 févr. 04 13:25:58 guest kernel: usb 2-6: New USB device strings: Mfr=0, Product=0, SerialNumber=0 févr. 04 13:25:58 guest kernel: garmin_gps 2-6:1.0: Garmin GPS usb/tty converter detected févr. 04 13:25:58 guest kernel: usb 2-6: Garmin GPS usb/tty converter now attached to ttyUSB0 févr. 04 13:26:03 guest kernel: usb 2-6: USB disconnect, device number 8 févr. 04 13:26:03 guest kernel: garmin_gps ttyUSB0: Garmin GPS usb/tty converter now disconnected from ttyUSB0 févr. 04 13:26:03 guest kernel: garmin_gps 2-6:1.0: device disconnected ... So the device is correctly transferred, and it is confirmed as the "preboot tools" detect the device in a "Windows 7"**guest I want to add that, as far as I know we can not use the "virt-manager" GUI to do the same, for two reasons : - the USB host device window do not refresh itself when the items are added or removed - the delay to attach this device is pretty short (5 to 8 seconds) and just after, from the guest we must trigger the tools which can manage the device in "preboot mode" (typically a flash tool) That is why the solution I found, is to automate this with a script which detects the kernel events and automatically attach the devices. The host versions : root@host:~# cat /etc/os-release | grep -E "^(NAME|VERSION)=" | tr '\n' ' ' ; uname -a ; kvm --version | grep version ; libvirtd --version ; virt-manager --version NAME="Debian GNU/Linux" VERSION="11 (bullseye)" Linux host 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux QEMU emulator version 5.2.0 (Debian 1:5.2+dfsg-11) libvirtd (libvirt) 7.0.0 3.2.0 As I want to post the complete method I used, I will certainly make a feedback in this thread later ;) Le 25/01/2023 à 15:24, Peter Krempa a écrit :
On Tue, Jan 24, 2023 at 00:10:46 +0100,lnj.sam@gmail.com wrote:
Hello everyone and best wishes for 2023 :)
I have an old *Garmin Drive Smart 50 GPS* and I want to be able to attach it when it is in preboot mode to a VM hosted by a *Debian 11 host*.
From what I understand, the preboot mode allows us to flash a firmware before the GPS actually starts (used among other things when the GPS is soft bricked).
When I connect the GPS to the host it gives: [...]
My questions :
Q1 : Is it possible ? It shpi;d be/
Q2 : Am I doing it the right way ? I don't think so. You are using a serial device emulated which is then connected to the host side USB-tty device.
A better way is simply to use USB-assignment/passthrough and have the guest OS handle also the USB side
Q3 : Is there a method to pass such a device directly (pass-through) ? To pass a USB device use the following XML:
<hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x1a86'/> <product id='0x55d4'/> </source> <address type='usb' bus='0' port='4'/> </hostdev>
Obviously tweak vendor/product.
Alternatively when you are using virt-manager GUI there's a menu to pass any device, or by default when you have a VM window active and plug in a USB device it's passed to the VM. (It can be disabled though).
participants (2)
-
lnj.sam@gmail.com
-
Peter Krempa