jacobrosenthal / hf2-rs

Microsoft HF2 HID Flashing Format for UF2 Bootloaders
49 stars 14 forks source link

Linux can't find device (presumably libusb/hidapi) #9

Closed jacobrosenthal closed 4 years ago

jacobrosenthal commented 4 years ago

Reports from atsamd gitter that linux flashing isnt finding devices

we could more explicitly link the linux deps https://github.com/libusb/hidapi#linux

but even that hasnt seemed to help

@jacobrosenthal Ubuntu mate 18.04, I had libusb-1.0.0 already installed but just installed libudev and libfox as per the libusb/hidapi install instructions. I'll update if it works when I get in front of my device in a few hours I've only just installed those deps and force reinstalled cargo-hf2 (not sure if there's something else I need to do). I'm still getting the same error message with these logs: https://gist.github.com/tekulvw/d9db07633c213145c093c2b1668a932b

twitchyliquid64 commented 4 years ago

I had this for yonks. You need to disable the Getty serial service (systemd) as well as the modem systemd service. Lastly, you need to run bossac with sudo or fix the perms on /dev/ttyACMx.

Let me see if I can find the commands in my bash history.

twitchyliquid64 commented 4 years ago
sudo systemctl disable serial-getty@ttyACM0
sudo systemctl disable ModemManager.service
sudo systemctl stop ModemManager.service

I also needed a reboot, and to update the permissions on the ttyACMx file.

jacobrosenthal commented 4 years ago

Hopefully someone else can confirm on a clean system.

also Just googling some of these keywords. What about this modemmanager flag to ignore a device https://github.com/Benjamin-Dobell/Heimdall/issues/286#issuecomment-174228046 https://linux-tips.com/t/prevent-modem-manager-to-capture-usb-serial-devices/284/2

On Tue, Jan 21, 2020 at 3:55 PM Twitch notifications@github.com wrote:

sudo systemctl disable serial-getty@ttyACM0 sudo systemctl disable ModemManager.service sudo systemctl stop ModemManager.service

I also needed a reboot, and to update the permissions on the ttyACMx file.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jacobrosenthal/hf2-rs/issues/9?email_source=notifications&email_token=AADPI5BWVHYAPZG4VFYI4FLQ654MPA5CNFSM4KFMOEH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJRS2SY#issuecomment-576925003, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADPI5CHIHMXLBDECR2BEQDQ654MPANCNFSM4KFMOEHQ .

twitchyliquid64 commented 4 years ago

https://linux-tips.com/t/prevent-modem-manager-to-capture-usb-serial-devices/284/2

Ooooo, thats an awesome solution. Are the product/vendor IDs for adafruit stuff stable?

jacobrosenthal commented 4 years ago

Yeah I have them hardcoded, though not named https://github.com/jacobrosenthal/hf2-rs/blob/master/hf2-cli/src/main.rs#L26 I pulled them from https://github.com/adafruit/uf2-samdx1

On Tue, Jan 21, 2020 at 4:34 PM Twitch notifications@github.com wrote:

https://linux-tips.com/t/prevent-modem-manager-to-capture-usb-serial-devices/284/2

Ooooo, thats an awesome solution. Are the product/vendor IDs for adafruit stuff stable?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jacobrosenthal/hf2-rs/issues/9?email_source=notifications&email_token=AADPI5H4MCS3MHLSLSSSQILQ66BB5A5CNFSM4KFMOEH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJRV2BA#issuecomment-576937220, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADPI5AG4ZJJKIOHFYAZYKLQ66BB5ANCNFSM4KFMOEHQ .

sajattack commented 4 years ago

Udev prevents this from working without sudo. Put this in /etc/udev/rules.d, name it something like 99-adafruit-boards.rules

ATTRS{idVendor}=="239a", ENV{ID_MM_DEVICE_IGNORE}="1"
SUBSYSTEM=="usb", ATTRS{idVendor}=="239a", MODE="0666"
SUBSYSTEM=="tty", ATTRS{idVendor}=="239a", MODE="0666"

Then reboot or run

sudo udevadm control --reload-rules
sudo udevadm trigger

That gets you a bit further, but cargo-hf2 errors here:

    Searching for a connected device with known vid/pid pair.
    Trying  Ok(Some("Adafruit Industries")) Ok(Some("Metro M4 Express"))
    Flashing "/home/paul/projects/rust/atsamd/boards/metro_m4/target/thumbv7em-none-eabihf/debug/examples/blinky_basic"
 DEBUG hf2::command  > Command { id: 1, tag: 0, _reserved0: 0, _reserved1: 0, data: [] }
 DEBUG hf2::command  > tx: [48, 01, 00, 00, 00, 00, 00, 00, 00]
 DEBUG hf2::command  > rx header: 54 (ptype: Final len: 20) data: [00, 00, 00, 00, 01, 00, 00, 00, 00, 01, 00, 00, 00, 08, 00, 00, 40, 01, 00, 00]
 DEBUG hf2::command  > CommandResponse { tag: 0, status: Success, status_info: 0, data: [1, 0, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 64, 1, 0, 0] }
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parse', src/libcore/result.rs:1084:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Tested with hidapi-0.9.0 and libusb 1.0.23

jacobrosenthal commented 4 years ago

we got further in the https://github.com/jacobrosenthal/hf2-rs/tree/bininfo branch But now dying getting zero bytes from the rx

 DEBUG hf2::command  > Command { id: 1, tag: 0, _reserved0: 0, _reserved1: 0, data: [] }
 DEBUG hf2::command  > tx: [48, 01, 00, 00, 00, 00, 00, 00, 00]
 DEBUG hf2::command  > rx count: 64)
 DEBUG hf2::command  > rx ptype: Final
 DEBUG hf2::command  > rx len: 20
 DEBUG hf2::command  > rx header: 54 (ptype: Final len: 20) data: [00, 00, 00, 00, 01, 00, 00, 00, 00, 01, 00, 00, 00, 04, 00, 00, 40, 01, 00, 00]
 DEBUG hf2::command  > CommandResponse { tag: 0, status: Success, status_info: 0, data: [1, 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 64, 1, 0, 0] }
 DEBUG cargo_hf2     > BinInfoResponse { mode: Bootloader, flash_page_size: 256, flash_num_pages: 1024, max_message_size: 320, family_id: None }
 DEBUG cargo_hf2     > binary is 13240 bytes, padding to 13312 bytes
 DEBUG hf2::command  > Command { id: 7, tag: 0, _reserved0: 0, _reserved1: 0, data: [0, 32, 0, 0, 52, 0, 0, 0] }
 DEBUG hf2::command  > tx: [50, 07, 00, 00, 00, 00, 00, 00, 00, 00, 20, 00, 00, 34, 00, 00, 00]
 DEBUG hf2::command  > rx count: 0)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parse', /home/paul/.cargo/git/checkouts/hf2-rs-a61dddb906db8068/5c4b01a/cargo-hf2/src/main.rs:137:5
stack backtrace: