greatscottgadgets / pyfwup

Python FirmWare UPgrader -- a DFU (and similar) utility for python
BSD 3-Clause "New" or "Revised" License
22 stars 7 forks source link

OSError: exception: access violation writing 0x0000000000000000 on Windows #14

Open mossmann opened 1 month ago

mossmann commented 1 month ago

Cynthion example copied from https://github.com/greatscottgadgets/cynthion/issues/158#issuecomment-2267108513:

C:\Users\Admin\Documents>cynthion update --mcu-firmware
Updating device firmware with 13876 bytes...
Operation complete!
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\weakref.py", line 666, in _exitfunc
    f()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\_objfinalizer.py", line 106, in _do_finalize_object_ref
    obj._do_finalize_object()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\_objfinalizer.py", line 73, in _do_finalize_object
    self._finalize_object()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\backend\libusb1.py", line 613, in _finalize_object
    _lib.libusb_unref_device(self.devid)
OSError: exception: access violation writing 0x0000000000000000

This exception is ignored by pyusb, so it actually has no effect other than looking like a failure and confusing the user. The firmware update actually completes. The exception only occurs if the Saturn-V iSerialNumber matches Apollo's iSerialNumber.

It happens after a DFU_DETACH, and it has to do with the defunct Apollo device, not the Saturn-V device that is present after DFU_DETACH. In the case above, the user presumably has Saturn-V 1.0 (with mangled serial number), and that access violation happened when updating from Apollo firmware with mangled serial number to newer Apollo firmware with unmangled serial number. The serial numbers no longer match, so they don't see the error anymore.

This means that anyone with Saturn-V 1.1 introduces the access violation by updating Apollo.