Menu

#86 Cannot set alternate interface on macOS 10.14 (libusb regression)

none
closed
nobody
None
2021-04-29
2020-07-01
No

Hello people,

I've been seeing this strange issue with dfu-utils on macos. Since a few months ago (I'm guessing after an OS update), I'm getting this failure dfu-util: Cannot set alternate interface when I try to flash a EFM32 based Tomu

I have tried with various binary files including default firmware from the Tomu folks. Also tried with various boards, so definitely not an issue on that side of things.

Seems like this is something to do with my setup. I'm on macOS 10.14.6 so I borrowed a friend's older Macbook also running on macOS 10.14.6 and it worked fine!! So definitely my setup issue.

I've installed dfu-utils using MacPorts, but I also tried it with a version I compliled myself.

On another forum, someone mentioned using dfu-util bundled into the Arduino IDE works, so I tried it and it does work. I ran otool -L on both the binaries.

I get this on the one bundled with Arduino

/Users/chinmay/Library/Arduino15/packages/arduino/tools/dfu-util/0.9.0-arduino2/dfu-util:
        /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

and this on the one I installed with MacPorts is

/opt/local/bin/dfu-util:
    /opt/local/lib/libusb-1.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
 ```

 Looks like the Arduino version doesn't use libusb? but binds natively to the OSX IOKit Framework?


 Also for documentation, here's the full error.

 ```
 dfu-util -v -v -v -v -d 1209:70b1 -D draw/draw.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.010689] [00000307] libusb: debug [libusb_get_device_list]
[ 0.010742] [00000307] libusb: debug [discovered_devs_append] need to increase capacity
[ 0.010773] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.010776] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.010791] [00000307] libusb: debug [libusb_open] open 20.8
[ 0.010875] [00000307] libusb: debug [darwin_open] device open for access
[ 0.010887] [00000307] libusb: debug [libusb_alloc_transfer] transfer 0x7fb4d2801d48
[ 0.010889] [00000307] libusb: debug [libusb_submit_transfer] transfer 0x7fb4d2801d48
[ 0.010928] [00000307] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[ 0.010939] [00000307] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.010945] [00000307] libusb: debug [handle_events] poll fds modified, reallocating
[ 0.010954] [00000307] libusb: debug [handle_events] poll() 1 fds with timeout in 60000ms
[ 0.011188] [0000120b] libusb: debug [darwin_async_io_callback] an async io operation has completed
[ 0.011221] [00000307] libusb: debug [handle_events] poll() returned 1
[ 0.011226] [00000307] libusb: debug [handle_events] caught a fish on the event pipe
[ 0.011228] [00000307] libusb: debug [darwin_handle_transfer_completion] handling control completion with kernel status 0
[ 0.011231] [00000307] libusb: debug [usbi_handle_transfer_completion] transfer 0x7fb4d2801d48 has callback 0x10e275f7c
[ 0.011233] [00000307] libusb: debug [sync_transfer_cb] actual_length=4
[ 0.011260] [00000307] libusb: debug [libusb_free_transfer] transfer 0x7fb4d2801d48
[ 0.011288] [00000307] libusb: debug [libusb_alloc_transfer] transfer 0x7fb4d16022e8
[ 0.011289] [00000307] libusb: debug [libusb_submit_transfer] transfer 0x7fb4d16022e8
[ 0.011307] [00000307] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[ 0.011309] [00000307] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.011311] [00000307] libusb: debug [handle_events] poll() 1 fds with timeout in 60000ms
[ 0.011310] [0000120b] libusb: debug [darwin_async_io_callback] an async io operation has completed
[ 0.011320] [00000307] libusb: debug [handle_events] poll() returned 1
[ 0.011323] [00000307] libusb: debug [handle_events] caught a fish on the event pipe
[ 0.011324] [00000307] libusb: debug [darwin_handle_transfer_completion] handling control completion with kernel status 0
[ 0.011325] [00000307] libusb: debug [usbi_handle_transfer_completion] transfer 0x7fb4d16022e8 has callback 0x10e275f7c
[ 0.011327] [00000307] libusb: debug [sync_transfer_cb] actual_length=60
[ 0.011329] [00000307] libusb: debug [libusb_free_transfer] transfer 0x7fb4d16022e8
[ 0.011332] [00000307] libusb: debug [libusb_close]
[ 0.011361] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011363] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011365] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011367] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011368] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011370] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011371] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011373] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011374] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011376] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011377] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011378] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011380] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011381] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011414] [00000307] libusb: debug [parse_configuration] skipping descriptor 0xb
[ 0.011416] [00000307] libusb: debug [parse_endpoint] skipping descriptor 25
[ 0.011419] [00000307] libusb: debug [parse_endpoint] skipping descriptor b
[ 0.011421] [00000307] libusb: debug [parse_endpoint] skipping descriptor 25
[ 0.011424] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011425] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011428] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011429] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011431] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011432] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.011434] [00000307] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.011436] [00000307] libusb: debug [libusb_get_device_descriptor]
[ 0.011437] [00000307] libusb: debug [libusb_get_config_descriptor] index 0
Opening DFU capable USB device...
[ 0.011452] [00000307] libusb: debug [libusb_open] open 20.8
[ 0.011493] [00000307] libusb: debug [darwin_open] device open for access
ID 1209:70b1
Run-time device DFU version 0101
Claiming USB DFU Interface...
[ 0.011521] [00000307] libusb: debug [libusb_claim_interface] interface 0
[ 0.011825] [00000307] libusb: debug [get_endpoints] building table of endpoints.
[ 0.011880] [00000307] libusb: debug [darwin_claim_interface] interface opened
Setting Alternate Setting #0 ...
[ 0.011886] [00000307] libusb: debug [libusb_set_interface_alt_setting] interface 0 altsetting 0
[ 0.115862] [00000307] libusb: debug [darwin_reset_device] darwin/reset_device: waiting for re-enumeration to complete...
[ 0.118823] [0000120b] libusb: debug [darwin_devices_detached] detected device detatched due to re-enumeration
[ 0.121736] [0000120b] libusb: debug [darwin_get_cached_device] finding cached device for sessionID 0x278aa68bfa320
[ 0.121919] [0000120b] libusb: debug [darwin_get_cached_device] parent sessionID: 0x2788eba05a96b
[ 0.121934] [0000120b] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0x278aa68bfa320/0x14430000 against cached device with sessionID/locationID 0x278a575ef8078/0x14430000
[ 0.121960] [0000120b] libusb: debug [darwin_get_cached_device] found cached device with matching location that is being re-enumerated
[ 0.121974] [0000120b] libusb: debug [darwin_get_cached_device] caching new device with sessionID 0x278aa68bfa320
[ 1.536885] [0000120b] libusb: debug [darwin_cache_device_descriptor] cached device descriptor:
[ 1.536900] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bDescriptorType:    0x01
[ 1.536902] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bcdUSB:             0x0210
[ 1.536904] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bDeviceClass:       0x00
[ 1.536906] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bDeviceSubClass:    0x00
[ 1.536907] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bDeviceProtocol:    0x00
[ 1.536909] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bMaxPacketSize0:    0x40
[ 1.536910] [0000120b] libusb: debug [darwin_cache_device_descriptor]   idVendor:           0x1209
[ 1.536912] [0000120b] libusb: debug [darwin_cache_device_descriptor]   idProduct:          0x70b1
[ 1.536914] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bcdDevice:          0x0101
[ 1.536915] [0000120b] libusb: debug [darwin_cache_device_descriptor]   iManufacturer:      0x01
[ 1.536946] [0000120b] libusb: debug [darwin_cache_device_descriptor]   iProduct:           0x02
[ 1.536956] [0000120b] libusb: debug [darwin_cache_device_descriptor]   iSerialNumber:      0x00
[ 1.536959] [0000120b] libusb: debug [darwin_cache_device_descriptor]   bNumConfigurations: 0x01
[ 1.537981] [0000120b] libusb: debug [darwin_check_configuration] active config: 1, first config: 1
[ 1.537992] [0000120b] libusb: debug [process_new_device] re-using existing device from context 0x7fb4d1405740 for with session 0x278a575ef8078 new session 0x278aa68bfa320
[ 1.537998] [0000120b] libusb: debug [process_new_device] found device with address 8 port = 3 parent = 0x7fb4d2800460 at 0x7fb4d170168a
[ 1.538002] [0000120b] libusb: debug [darwin_devices_attached] cached device in reset state. reset complete...
[ 1.538024] [00000307] libusb: debug [darwin_reset_device] darwin/reset_device: checking whether descriptors changed
[ 1.538031] [00000307] libusb: debug [darwin_reset_device] darwin/reset_device: device reset complete. restoring state...
[ 1.538349] [00000307] libusb: debug [darwin_open] device open for access
[ 1.538359] [00000307] libusb: debug [darwin_restore_state] darwin/restore_state: reclaiming interfaces
[ 1.538363] [00000307] libusb: debug [darwin_restore_state] darwin/restore_state: re-claiming interface 0
[ 1.538848] [00000307] libusb: debug [get_endpoints] building table of endpoints.
[ 1.538898] [00000307] libusb: debug [darwin_claim_interface] interface opened
[ 1.538903] [00000307] libusb: debug [darwin_restore_state] darwin/restore_state: device state restored
[ 1.538907] [00000307] libusb: debug [get_endpoints] building table of endpoints.
dfu-util: Cannot set alternate interface

Discussion

<< < 1 2 3 (Page 3 of 3)
  • Freek Dijkstra

    Freek Dijkstra - 2021-01-13

    Here is a better lsusb output, run on both Linux and macOS. Indeed similar. Both when the device is in normal mode and DFU mode. As you can see, if has a different USB product ID in DFU mode.

    To make it a bit frustrating for me, the device switches back from DFU mode to normal mode in 7 or 10 seconds. So it gets a different Device ID on the bus. That's why I used sudo instead of chown/chmod on /dev/bus/usb/xxx/yyy -- the yyy changed too often (whyyyy indeed)

    For whatever reason, dfu-util fails on Linux (I must apologise, but will not pursue this issue too). lsusb sees the device, both in normal and DFU mode.

    The error when running lsusb is:
    Couldn't open device, some information will be missing

    When attempting a DFU, the following error was printed on the tty terminal:

    usb 3-1: config index 0 descriptor too short (expected 9, got 3)
    usb 3-1: can't read configuration, error -22
    

    And dmesg contains the following message:

    [16059.267301] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
    [17174.401439] perf: interrupt took too long (2517 > 2500), lowering kernel.perf_event_max_sample_rate to 79250
    

    I have not closely recorded the circumstances when each message was printed. I briefly hypothesised that the DFU failed because the device snapped back to normal mode (not unlikely due to the 5-second wait on Linux). However, I could confirm that this was not yet the case, not even after dfu-util failed and exited.

    Since this issue is different from this bug, I propose not to discuss it here. I'm willing to open a new bug report, but as I said, I unfortunately won't pursue this. My hobby project was tinkering with some hardware (for which I needed a DFU). Debugging libusb was a fun side-track, but not more than that. I prefer to get back the my original tinkering plan.

     

    Last edit: Freek Dijkstra 2021-01-13
  • Tormod Volden

    Tormod Volden - 2021-01-14

    The Linux problem, failing to read descriptors correctly, looks like this issue
    https://github.com/libusb/libusb/issues/825 that has been fixed in latest git. However from your lsusb output it doesn't look like a multi-configuration device. Of course, this bug might affect lsusb also but you ran it on macOS with same results so it should be correct.

     
  • Tormod Volden

    Tormod Volden - 2021-02-07
    • status: needsinfo --> closed
     
  • Tormod Volden

    Tormod Volden - 2021-02-07

    I believe the macOS issue will be resolved in libusb 1.0.25 when it is released. However, I have also changed the dfu-util code to not attempt to set alternate setting in most cases where it seems unnecessary. This should also cover the case of this device where there DFU interface is the first listed and there is only one alternate setting available in DFU mode.

     
<< < 1 2 3 (Page 3 of 3)

Anonymous
Anonymous

Add attachments
Cancel