On 4/06/12 11:51 AM, Andrew Leech wrote:
Hi,
I'm just starting to use dfu-util to program some hardware based on the lpc3131 processor which has a built in dfu mode. Unfortunately I can't make it work with any new dfu-util compiled from source (git).

The new versions all rely on libusb-1.0 as far as I can tell, which on windows is currently limited to WinUSB backend driver which does not support usb reset. This usb reset certainly appears to be required on my lpc3131 to start the loaded code, is this the same on other dfu device?


Apparently there's proposed patches to libusb-1.0 to support the original libusb-win32 driver somewhere too, although I couldn't find the patches myself to try them.

Hi,
To follow up on my previous post, I've got a new git compile working with libusbk.sys and the (unsupported) libusb-pbatard K branch:

$ git clone git://git.libusb.org/libusb-pbatard.git -b K

and a patch to fix the libusbk export names (attached); in libusb-pbatard the libusbk functions all have a capital 'L' in front of them, must be from an old version of libusbk. I found it useful to use "./configure --disable-shared" to ensure I din't have any dll dependencies hiding in the compiled libs.

I installed libusbk.sys vers 3.0.5.13 from http://sourceforge.net/projects/libusbk/files/
and compiled dfu-util unmodified but linked against the custom libusb:

$ USB_CFLAGS="-I../../libusb-pbatard/libusb/" USB_LIBS="-L../../libusb-pbatard/libusb/.libs/ -lusb-1.0" ./configure --host=i586-mingw32msvc

I initially cross compiled on linux (hence the --host=i586-mingw32msvc above), but as an exercise I've also compiled it with mingw/msys on windows. I had to install pkg-config to make configure work, it ignores the USB_CFLAGS/USB_LIBS without it. I had previously tried to compile with cygwin/mingw (with CC="gcc -mno-cygwin") but had lots of problems with trying to statically link libpthreads required by libusb and eventually gave up. The libraries included in mingw/msys seemed to work without any setup.

I've also been able to compile it under ms visual c, but had to add a seperate getopt library and find a couple of header files not supplied by msvc. It got a bit messy in the end, if I get a chance I'll clean that up and post my changes. I may end up re-writing some of the code to allow use from a dll rather than a standalone exe, but that will depend on project requirements at works end and looking into the gnu aspects a bit closer.

Hopefully in a few months libusbx will have libusbk.sys / libusb0.sys support and I'll be able to compile against a supported library rather than Pete Batard's old libusb-1 repo, considering he's one of the primary libusbx developers.

Cheers,
Andrew

diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 6d3da1e..3b39da4 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -2391,7 +2391,7 @@ const struct windows_usb_api_backend 
usb_api_backend[USB_API_MAX] = {
  */
 
 // TODO: This will break on MSVC6 because of the use of VA_ARGS...
-#define _WinUsb(name, ...) (((k) && (LUsbK_##name(__VA_ARGS__))) || ((!k) && 
(WinUsb_##name(__VA_ARGS__))))
+#define _WinUsb(name, ...) (((k) && (UsbK_##name(__VA_ARGS__))) || ((!k) && 
(WinUsb_##name(__VA_ARGS__))))
 
 static int winusb_init(struct libusb_context *ctx)
 {
@@ -2424,24 +2424,24 @@ static int winusb_exit(void)
 
 static int libusbk_init(struct libusb_context *ctx)
 {
-       DLL_LOAD(libusbK.dll, LUsbK_Initialize, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_Free, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_GetAssociatedInterface, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_GetDescriptor, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_QueryInterfaceSettings, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_QueryDeviceInformation, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_SetCurrentAlternateSetting, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_GetCurrentAlternateSetting, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_QueryPipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_SetPipePolicy, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_GetPipePolicy, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_ReadPipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_WritePipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_ControlTransfer, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_ResetPipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_AbortPipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_FlushPipe, TRUE);
-       DLL_LOAD(libusbK.dll, LUsbK_ResetDevice, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_Initialize, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_Free, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_GetAssociatedInterface, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_GetDescriptor, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_QueryInterfaceSettings, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_QueryDeviceInformation, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_SetCurrentAlternateSetting, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_GetCurrentAlternateSetting, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_QueryPipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_SetPipePolicy, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_GetPipePolicy, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_ReadPipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_WritePipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_ControlTransfer, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_ResetPipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_AbortPipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_FlushPipe, TRUE);
+       DLL_LOAD(libusbK.dll, UsbK_ResetDevice, TRUE);
 
        api_libusbk_available = true;
        return LIBUSB_SUCCESS;
@@ -2902,13 +2902,13 @@ static int _winusb_submit_bulk_transfer(struct 
usbi_transfer *itransfer, bool k)
                if (!k)
                        ret = WinUsb_ReadPipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
                else
-                       ret = LUsbK_ReadPipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
+                       ret = UsbK_ReadPipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
        } else {
                usbi_dbg("writing %d bytes", transfer->length);
                if (!k)
                        ret = WinUsb_WritePipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
                else
-                       ret = LUsbK_WritePipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
+                       ret = UsbK_WritePipe(wfd.handle, transfer->endpoint, 
transfer->buffer, transfer->length, NULL, wfd.overlapped);
        }
        if (!ret) {
                if(GetLastError() != ERROR_IO_PENDING) {
@@ -3086,7 +3086,7 @@ static int _winusb_reset_device(struct 
libusb_device_handle *dev_handle, bool k)
        if (k) {
                winusb_handle = handle_priv->interface_handle[0].api_handle;
                if ( (winusb_handle != 0) && (winusb_handle != 
INVALID_HANDLE_VALUE)) {
-                       LUsbK_ResetDevice(winusb_handle);
+                       UsbK_ResetDevice(winusb_handle);
                }
        }
 
 
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index fc2c5b7..a0a4e5b 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -610,21 +610,21 @@ DLL_DECLARE(WINAPI, BOOL, WinUsb_AbortPipe, 
(WINUSB_INTERFACE_HANDLE, UCHAR));
 DLL_DECLARE(WINAPI, BOOL, WinUsb_FlushPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
 
 /* libusbK.dll */
-DLL_DECLARE(WINAPI, BOOL, LUsbK_Initialize, (HANDLE, 
PWINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_Free, (WINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_GetAssociatedInterface, 
(WINUSB_INTERFACE_HANDLE, UCHAR, PWINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_GetDescriptor, (WINUSB_INTERFACE_HANDLE, 
UCHAR, UCHAR, USHORT, PUCHAR, ULONG, PULONG));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_QueryInterfaceSettings, 
(WINUSB_INTERFACE_HANDLE, UCHAR, PUSB_INTERFACE_DESCRIPTOR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_QueryDeviceInformation, 
(WINUSB_INTERFACE_HANDLE, ULONG, PULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_SetCurrentAlternateSetting, 
(WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_GetCurrentAlternateSetting, 
(WINUSB_INTERFACE_HANDLE, PUCHAR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_QueryPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
UCHAR, PWINUSB_PIPE_INFORMATION));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_SetPipePolicy, (WINUSB_INTERFACE_HANDLE, 
UCHAR, ULONG, ULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_GetPipePolicy, (WINUSB_INTERFACE_HANDLE, 
UCHAR, ULONG, PULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_ReadPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_WritePipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_ControlTransfer, (WINUSB_INTERFACE_HANDLE, 
WINUSB_SETUP_PACKET, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_ResetPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_AbortPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_FlushPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, LUsbK_ResetDevice, (WINUSB_INTERFACE_HANDLE));
+DLL_DECLARE(WINAPI, BOOL, UsbK_Initialize, (HANDLE, PWINUSB_INTERFACE_HANDLE));
+DLL_DECLARE(WINAPI, BOOL, UsbK_Free, (WINUSB_INTERFACE_HANDLE));
+DLL_DECLARE(WINAPI, BOOL, UsbK_GetAssociatedInterface, 
(WINUSB_INTERFACE_HANDLE, UCHAR, PWINUSB_INTERFACE_HANDLE));
+DLL_DECLARE(WINAPI, BOOL, UsbK_GetDescriptor, (WINUSB_INTERFACE_HANDLE, UCHAR, 
UCHAR, USHORT, PUCHAR, ULONG, PULONG));
+DLL_DECLARE(WINAPI, BOOL, UsbK_QueryInterfaceSettings, 
(WINUSB_INTERFACE_HANDLE, UCHAR, PUSB_INTERFACE_DESCRIPTOR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_QueryDeviceInformation, 
(WINUSB_INTERFACE_HANDLE, ULONG, PULONG, PVOID));
+DLL_DECLARE(WINAPI, BOOL, UsbK_SetCurrentAlternateSetting, 
(WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_GetCurrentAlternateSetting, 
(WINUSB_INTERFACE_HANDLE, PUCHAR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_QueryPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
UCHAR, PWINUSB_PIPE_INFORMATION));
+DLL_DECLARE(WINAPI, BOOL, UsbK_SetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, 
ULONG, ULONG, PVOID));
+DLL_DECLARE(WINAPI, BOOL, UsbK_GetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, 
ULONG, PULONG, PVOID));
+DLL_DECLARE(WINAPI, BOOL, UsbK_ReadPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_DECLARE(WINAPI, BOOL, UsbK_WritePipe, (WINUSB_INTERFACE_HANDLE, UCHAR, 
PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_DECLARE(WINAPI, BOOL, UsbK_ControlTransfer, (WINUSB_INTERFACE_HANDLE, 
WINUSB_SETUP_PACKET, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_DECLARE(WINAPI, BOOL, UsbK_ResetPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_AbortPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_FlushPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_DECLARE(WINAPI, BOOL, UsbK_ResetDevice, (WINUSB_INTERFACE_HANDLE));


_______________________________________________
devel mailing list
devel@lists.openmoko.org
https://lists.openmoko.org/mailman/listinfo/devel

Reply via email to