Closed karelbilek closed 5 years ago
We no longer use hidapi on linux (since this https://github.com/trezor/trezord-go/pull/108 ) and we use libusb directly.
That has been working well, but as bridge is written now, the endpoints are hardcoded here
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L29-L41
On very old bootloaders (not firmwares, even very ancient FWs are all good), the endpoints are however "wrong" - set up differently
https://github.com/trezor/trezor-mcu/blob/b5eecb30be7712855cfa76fe671ef0b2e98e4aa9/bootloader/usb.c#L136-L150
and writing will then crash, because of this line
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L543
It used to work in HIDAPI, since HIDAPI on linux automatically loads the endpoints.
To fix the old bootloaders, we will need to somehow detect them and use the "correct" endpoint.
That is, somewhere in this function
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L266
write something conceptually similar to this function, to detect those old BLs
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L80
and then use the appropriate endpoint on this line
I don't have access to the old bootloader now so I don't want to fix it :)
Other option is not to hardcode the endpoints at all and always load them from the configuration descriptor always, like HIDAPI does that. But I actually like that they are written explicitly.
We no longer use hidapi on linux (since this https://github.com/trezor/trezord-go/pull/108 ) and we use libusb directly.
That has been working well, but as bridge is written now, the endpoints are hardcoded here
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L29-L41
On very old bootloaders (not firmwares, even very ancient FWs are all good), the endpoints are however "wrong" - set up differently
https://github.com/trezor/trezor-mcu/blob/b5eecb30be7712855cfa76fe671ef0b2e98e4aa9/bootloader/usb.c#L136-L150
and writing will then crash, because of this line
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L543
It used to work in HIDAPI, since HIDAPI on linux automatically loads the endpoints.
To fix the old bootloaders, we will need to somehow detect them and use the "correct" endpoint.
That is, somewhere in this function
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L266
write something conceptually similar to this function, to detect those old BLs
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L80
and then use the appropriate endpoint on this line
https://github.com/trezor/trezord-go/blob/3bc736dbdb622b09c1a5e4ef2cedb60eb59a8e5e/usb/libusb.go#L543
I don't have access to the old bootloader now so I don't want to fix it :)