configure.ac: Check for libusb 1.0 in system location before using pkg-config

Fixes libusb 1.0 detection on FreeBSD where the library is called simply
"libusb" and resides in the system default location.

Note that pkg-config (or more precisely, its aclocal/pkg.m4) must be
installed when running autogen.sh, but pkg-config is not needed on
FreeBSD when running configure (which is included in release tarballs).

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
quirks: Add bcdDevice to quirk handling

So that we can limit quirks to specific versions of a device.

Also corrected set_quirks to use uint16_t and not unsigned long.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
quirks: Limit Maple quirk to firmware revision 2.00

Later revisions do not need this quirk, and previous revisions
always had bcdDevice 2.00.

See also corresponding commit in the Maple bootloader:
https://github.com/leaflabs/maple-bootloader/commit/c86a46008c6d87299b315d731b7ecdca690165c4

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfu-util/dfu-suffix: Show mailing list address for bug reports

Set bug report address in configure.ac for ultimate autoconf pleasure.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Update README and TODO on DFU 1.1 support

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
ChangeLog: Updated with upcoming 0.7 goodies

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfu-util.1: Major update of the man page

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
www: Add web pages for build instructions, DfuSe, and manual.

The manual page is generated from the man page using man2html
and a few fix-ups.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
www: Major update of home page

- Include links to building instructions, DfuSe page and manual.
- Explanation and links about Windows installation
- Move Supported Devices section up
- Smaller rewrites
- Tweak CSS to distinguish command line examples

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: More verbose output from special command download

For instance the Erase operation will fail if the pages are write
protected or the address is not allowed. We could be more helpful
decoding the returned status but at least we print the status codes
so that the user can look them up in the documention.

Another example is the mass-erase command on the STM32F4-Discovery
board which seems to perform the erase correctly, but returns an
unknown error in the second get_status request.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Release 0.7

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
www: Mention 0.7 release
www: Update git repo location.

We moved the official repo to gitorious.
Move functions within main.c to new dfu_util.c/.h

Signed-off-by: Roger Meier <r.meier@siemens.com>
Add CFLAG -Wextra and lot of type casts

Signed-off-by: Roger Meier <r.meier@siemens.com>
Use nanosleep instead of usleep for delays

After downloading the dfu-util 0.7 binary distribution for Windows
(MinGW), I noticed that the milli_sleep(2000) delay after a detach was
not delaying at all. Grabbing the source, and doing some debugging, I
found that MinGW now provides a usleep() implementation (HAVE_USLEEP
gets defined by configure script), but it will just return immediately
if the specified delay is 1000000 or greater. According to the usleep
man page, operation is only defined in the range [0, 1000000], with
behaviour outside of this range being undefined, so TECHNICALLY it's not
a bug.

Anyways, my "quick hack" was to just swap the order of the HAVE_USLEEP
and HAVE_WINDOWS_H checks in src/portable.h so Windows uses Sleep.  But
then I figured other platforms may have similarly restricted usleep
implementations, and the "correct" fix would be to use nanosleep for
delays instead.  Hence, this patch.

Note that MinGW doesn't currently have nanosleep, so Windows will still
fall back to using Sleep, but I've also tested this under Ubuntu 11 to
confirm the nanosleep implementation works.

The "do {...} while (0)" loop is used to "swallow the semicolon", see
http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html
Revise help messages

Signed-off-by: Roger Meier <r.meier@siemens.com>
Seek to end of file before checking length when opening upload file

Unlike Linux, under Windows, the position returned by ftell() immediately
after opening a file for append is 0, regardless of the file size. A bug
was raised in MinGW because of this difference:

http://sourceforge.net/p/mingw/bugs/1558/

But it was closed as "won't fix" because Microsoft documents its ftell()
behaviour here:

http://msdn.microsoft.com/en-us/library/0ys3hc0b

Specifically, note this paragraph:

"Note that when a file is opened for appending data, the current file
position is determined by the last I/O operation, not by where the next
write would occur. For example, if a file is opened for an append and the
last operation was a read, the file position is the point where the next
read operation would start, not where the next write would start. (When a
file is opened for appending, the file position is moved to end of file
before any write operation.) If no I/O operation has yet occurred on a
file opened for appending, the file position is the beginning of the
file."

As such, to properly determine the pre-existing length of a file opened
for append under Windows, we must first perform a seek to the end of the
file.  Hence this change to add an fseek() call when checking the length
of the output file for an upload operation.
Report the serial number of the devices found
Allow to select device by serial number