View source for Dfu-util-windows

From Openmoko

Jump to: navigation, search

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Administrators.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page:

Template used on this page:

Return to Dfu-util-windows.

Personal tools

dfu-util for Win32

NOTE: This has only been tested on the developer's box and with the FreeRunner.

In order to use dfu-util for Win32, you need to install a Windows driver when the device is in U-Boot. The LibUSB-Win32 driver and accompanying INF file for the OpenMoko can be found in at the link below. When the Windows New Device Wizard pops up, use this driver.

Once the driver is installed, then you can proceed and use the instructions found at the main dfu-util page.

The above mentioned files can be downloaded at:

The information below is for developers who would like to know how to compile dfu-util for Win32.

Porting dfu-util to Windows

NOTE: This is entirely work in progress. Nevertheless hopefully the information on this page will serve as a starting point for anyone who find the time to take this further. After all, as many people still use Windows PCs as their every day computers, having a convenient way to re-flash a Neo from Windows would probably open up the user base.

Potential Approaches

  • Cygwin
Not very attactive as Cygwin binaries require Cygwin in order to run. You will not get a simple, native dfu-util.exe which can be downloaded and used on any Windows machine that way.
  • MinGW/MSYS
MinGW (Minimalist GNU for Windows) seems to be the platform of choice.
  • LibUSB-Win32
Will only be able to be built on a Windows box

MinGW/MSYS port

The preferred order of installation is:

  1. Install MinGW (the core installation should be sufficient)
  2. Install MSYS (Note: make comes with MSYS while GCC comes with MinGW)

Here is step-by-step howto:

1. Download MinGW-5.1.4.exe from and execute the installer. It will download additional files required and install MinGW.

NOTE: It has often been a good idea to install into a directory that has no spaces in the filename.

2. Download MSYS-1.0.10.exe from and install.

NOTE: Make sure to open the "Current Version: 1.0.10" folder as the newer version 1.0.11 does not have an installer yet.

You will need to enter the path where you installed MinGW. It's a good idea to install MinGW and MSYS next to each other, i.e. C:\SOMEDIR\MinGW and C:\SOMEDIR\MSYS.

NOTE: For example if MinGW is installed in C:\MinGW enter 'C:/MinGW.' including the period.

3. Download msysDTK-1.0.1.exe from, which contains the autotools. Install into the same directory into which you installed MSYS itself. The installer might not automatically suggest the right directory.

That should give you an Icon in your Start menu in MinGW->MSYS with the name of msys. Open that one, and you will find yourself in a bourne compatible shell on your native Windows system.

You can try to execute some commends such as gcc, make, etc. to make sure you installed everything correctly.

4. Download autoconf 2.59 from All you need to do to install it is to use a utility like 7-Zip to extract the files into your msys installation directory.

5. You will also need pkg-config. According to, you need the following packages:


You can get all of these from the GTK+ for Windows page at: Unzip them to your msys\1.0 directory.

6. Open the file /etc/profile (C:\msys\1.0\etc\profile) with your favorite editor (make sure it uses LF line endings) and add:


7. Download libusb-win32-device-bin- from Then, copy the libusb.a file from the LibUSB-Win32\lib\gcc directory into the MinGW\lib directory and the usb.h file from LibUSB-Win32\include into MinGW\include (or you can copy it into your dfu-util\src directory).

8. Then you will need to create a libusb.pc file in the msys\1.0\lib\pkgconfig directory. I created the following:

 Name: LibUSB
 Description: USB for Win32
 Libs: -L${libdir} -lusb
 Cflags: -I${includedir}

Getting dfu-util sources

Use your favorite Subversion client to check out the dfu-util sources. The dfu-util sources can be checked out from

Apply patch to compile with MinGW

Apply the following patch to the source code:

Index: main.c
--- main.c	(revision 4553)
+++ main.c	(working copy)
@@ -26,8 +26,10 @@
 #include <getopt.h>
 #include <usb.h>
 #include <errno.h>
+#ifndef __MINGW32__
 #include <byteswap.h>
 #include <endian.h>
 #include "dfu.h"
 #include "usb_dfu.h"
@@ -37,6 +39,10 @@
 #include "config.h"
+#ifdef __MINGW32__
+#define sleep(seconds) Sleep((seconds)*1000)
 #include <usbpath.h>
@@ -579,6 +585,20 @@
 		/* FIXME: check if the selected device really has only one */
+#ifdef __MINGW32__
+		int configuration = dif->configuration;
+		if (configuration == 0) {
+			dif->configuration = 1;
+		}
+		printf("Setting Configuration %u...\n", dif->configuration);
+		if (usb_set_configuration(dif->dev_handle, dif->configuration) < 0) {
+			fprintf(stderr, "Cannot set configuration: %s\n", usb_strerror());
+			exit(1);
+		}
+		dif->configuration = configuration;
 		printf("Claiming USB DFU Runtime Interface...\n");
 		if (usb_claim_interface(_rt_dif.dev_handle, _rt_dif.interface) < 0) {
 			fprintf(stderr, "Cannot claim interface: %s\n", usb_strerror());
@@ -700,12 +720,18 @@
-#if 0
+#ifdef __MINGW32__
+	int configuration = dif->configuration;
+	if (configuration == 0) {
+		dif->configuration = 1;
+	}
 	printf("Setting Configuration %u...\n", dif->configuration);
 	if (usb_set_configuration(dif->dev_handle, dif->configuration) < 0) {
 		fprintf(stderr, "Cannot set configuration: %s\n", usb_strerror());
+	dif->configuration = configuration;
 	printf("Claiming USB DFU Interface...\n");
 	if (usb_claim_interface(dif->dev_handle, dif->interface) < 0) {
Index: sam7dfu.c
--- sam7dfu.c	(revision 4553)
+++ sam7dfu.c	(working copy)
@@ -20,6 +20,11 @@
 #define O_BINARY 0
+#ifdef __MINGW32__
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(microseconds) Sleep((microseconds)/1000)
 int sam7dfu_do_upload(struct usb_dev_handle *usb_handle, int interface, 
 		      int xfer_size, const char *fname)
Index: usb_dfu.h
--- usb_dfu.h	(revision 4553)
+++ usb_dfu.h	(working copy)
@@ -12,6 +12,13 @@
 #include <sys/types.h>
+#ifdef __MINGW32__
+#include <stdint.h>
+#define u_int8_t uint8_t
+#define u_int16_t uint16_t
+#define u_int32_t uint32_t
 #define USB_DT_DFU			0x21
 struct usb_dfu_func_descriptor {

Build dfu-util

In the Msys shell inside the dfu-util directory, run the following command:


dfu-util should successfully compile and you should have the .exe files in the src directory. In case you get the following error

 checking for USB... configure: error: *** Required libusb >= 0.1.4 not installed ***

It means that it could not find the libusb.pc file mentioned earlier. Your PKG_CONFIG_PATH may not be set up properly. Try the following:

Open the file /etc/profile (C:\msys\1.0\etc\profile) with your favorite editor (make sure it uses LF line endings) and add:


as described here: (modify the path to point to your pkgconfig directory of course), and restart your MSYS shell.

If that doesn't work, you can try running the following command (if you are sure that libusb is correctly installed):

 ./configure USB_CFLAGS=-Iinclude USB_LIBS=-lusb

Preparing to use dfu-util

A Windows driver needs to be installed when the device is in U-Boot and connected through the USB. Windows does not come with a DFU class driver and Jungo seems to be the only one that has created a DFU class driver, but it is non-free. You can use LibUSB-Win32 as the driver for the device by creating an INF file for it for this device. Use inf-wizard.exe, which is a part of the LibUSB-Win32 binaries distribution. Run the wizard, select the following device:

 Vendor ID  Product ID  Description
 0x1D50      0x5119      USB Device

Insert the Manufacturer name: OpenMoko, or FIC?

Insert device description: Device Firmware Upgrade

Then save the INF file along with the auto generated CAT files.

When you get the New Device Wizard when plugging in the device in U-Boot mode into Windows, select this newly generated INF file.

Running dfu-util

Once the Windows driver is successfully installed, you can try some commands:

 dfu-util --list

and you should be able to list the device. Example:

 Found Runtime: [0x1d50:0x5119] devnum=7, cfg=0, intf=2, alt=0, name="USB Device Firmware Upgrade"  


Outstanding issues

Had to call usb_set_configuration() with configuration set to 1 before attempting to claim the device instead of using configuration 0 that the device returns. It sounds like DFU implementation in U-Boot might not be compliant with USB spec. A similar issue and discussion can be found here: