[UPDATED 2009.10.11 - GIT information and better approach to x86_64 detection]
Remember: The PREFERRED way of compiling and running OpenOCD with an FT2232 device on Windows 64 bit systems should be using libftdi/libusb-win32, as the resulting executable below is not GPL compliant. You can find a complete guide on how to build a better version of OpenOCD that uses libftdi here
Since I finally managed to get an OpenOCD version working on Vista 64, with the proprietary 64 it version of the FTDI drivers/library, I thought I'd share the compilation process I used with MinGW x64.
I tested this with OpenOCD rev. 2826 and an FT2232 based ShevaPlug.
First of all, let me state that I wholeheartedly support the OpenOCD developers decision to try to enforce the use of the GLP'd libftdi vs. the proprietary FTDI library, but, as you all know, getting libftdi to work in Vista 64 is a bit of a headache, and I know there are quite a few of you longing for the convenience of using OpenOCD on your Vista 64 systems.
Of course, if I manage to get OpenOCD to work in Vista 64 with libftdi, I'll let you know.
I will also request that, if you do manage to compile an OpenOCD.exe version that runs on Vista 64 by following the instructions below, you do NOT publish it on the internet, as this would be a breach of the GPL License (and obviously, don't bother asking me to share my binaries)
This being said, be also warned that this is a very crude guide: We'll be doing some quick and dirty stuff in there and you'll also need to fill in some gaps. Hopefully someone will come along and produce a better version of a compilation guide for Windows x64 and submit the needed MinGW x64 patches to the OpenOCD tree (as I have no plans to do so myself). The goal here is to get an OpenOCD executable that works on Windows x64 as quickly as possible.
Compiling OpenOCD with WPG System64
Alright, that was a long preamble enough, let's jump in.
The toolchain we're going to use to compile OpenOCD is MinGW, because currently that's the only GNU Like toolchain that can produce x86_64 binaries on Windows (will cygwin ever get there? Who knows...).
And of course, we're not going to bother recompiling our own toolchain - instead we're going to use the ready made WPG System64 because:
1. It's up to date
2. It's a doodle to install: No need for an installer - just extract the files to C: and you're done!
I used the "WPG System64 1.99-preview" version (WPG_System64-1.99p.7z), which you can find by following the previous link. Just be warned that it takes 2 GB once extracted, and it is configured to run on the C: drive.
Once extracted, you should have a C:\msys directory. In there you will find a "WPG System64 (Bash shell)" shortcut, which you should run to get a command prompt.
Now, before you can compile OpenOCD, you'll need the FTDI proprietary drivers, which you can download from the FTDI website.
For the purpose of this exercise, we will extract these files in C:\msys\src (create the "src" directory if it doesn't exist), and then rename the "C:\msys\src\CDM 2.04.16 WHQL Certified" to "C:\msys\src\ftd2xx".
STEP 0: Retrieving the OpenOCD source.
As the latest GIT sources includes patches needed for successful MinGW-W64 compilation, this is what you should use. For the time being (see below) yopu will need to install a separate GIT client for WPG System64 but that should change with an updated release). You can find a GIT client for MSYS here. Then download the latest sources with:
git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
Do not use the SVN or archives earlier than 0.3.0, as the SVN tree is no longer maintained, and the archives do not contain the required patches.
STEP 1: (This where the quick & dirty part start) Edit openocd/configure.in and change the section (line #683)
# And calculate the LDFLAGS for the machine case "$host_cpu" in i?86|x86_*) LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/i386" LIBS="$LIBS -lftd2xx" f=$with_ftd2xx_win32_zipdir/i386/ftd2xx.lib ;; amd64) LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/amd64" LIBS="$LIBS -lftd2xx" f=$with_ftd2xx_win32_zipdir/amd64/ftd2xx.lib ;;
# And calculate the LDFLAGS for the machine case "$host_cpu" in i?86|x86_32) LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/i386" LIBS="$LIBS -lftd2xx" f=$with_ftd2xx_win32_zipdir/i386/ftd2xx.lib ;; amd64|x86_64) LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/amd64" LIBS="$LIBS -lftd2xx" f=$with_ftd2xx_win32_zipdir/amd64/ftd2xx.lib ;;
STEP 2: In the command prompt, run
#error THIS IS AN OBSOLETE VERSION OF OpenOCD ... latest is in GIT
Not sure what's going on between the berlios and SourceForge repository (has there been a fork or something?)
STEP 4: [NOT NEEDED IF DOWNLOADED FROM GIT] Edit openocd/src/Makefile.in and change the line (line #300):
@IS_MINGW_TRUE@MINGWLDADD = -lwsock32
@IS_MINGW_TRUE@MINGWLDADD = -lws2_32
STEP 5: If you try to run "./configure ..." at this stage, you will find that eventhough the process does find the right library, you still get the ominous
configure: error: Cannot build & run test program using ftd2xx.lib
C:\Users\nil\AppData\Local\Temp\ccOBXOer.o:conftest.c:(.text+0x1e): undefined reference to `_imp__FT_GetLibraryVersion'
Now, because the library has been stripped, you would normally need to use the Visual Studio tool command "dumpbin /exports ftd2xx64.dll > exports.txt" and use it to create a .def file with the library members, that you can then use with MinGW's dlltool, but the truth is, with the current FTDI lib, the following command will give you what you want, thus:
cd /usr/src/ftd2xx/amd64 echo "LIBRARY ftd2xx64.dll" > ftd2xx64.def echo "EXPORTS" >> ftd2xx64.def strings ftd2xx64.dll | grep FT_ >> ftd2xx64.def mv ftd2xx.lib ftd2xx.lib.old dlltool.exe -d ftd2xx64.def -l ftd2xx.lib
Note: Don't forget the "LIBRARY" line in your def file, otherwise any executable created with the FTDI library will fail with the error
the application failed to start because "(null).dll" was not found
STEP 7: This time, everything should be set for configure to work, so:
cd /usr/src/openocd ./configure --enable-maintainer-mode --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=/usr/src/ftd2xx --build=x86_64-w64-mingw32
If you want to change the default install locations for openocd (default to /usr/local...) now is probably a good time to do so by specifying additional configure options.
STEP 8: [NOT NEEDED IF DOWNLOADED FROM GIT] And now the fun part begins... If you thought all the above was painful enough to setup, think again. The problem is that openocd sure wasn't designed with MinGW x64 in mind, and there are about 12-16 source files in there that are going to choke on (apparently nonstandard) "%lld" printfs and the like... So you have to patch them one after another.
And if you think I'm gonna help you on this one, sorry but no.
It's time consuming but it should be easy enough to figure out. As far as I'm concerned, I replaced problematic "long" variables with "unsigned long long", "%lld" or "%i" with "%I64d", and removed %hh or %j prefixes here and there.
To be truly platform independent, you'd probably want to use the C99 "PRIi64" "PRIu64" "conventions", but whoever came up with these cumbersome macros should be put in a cubicle without any windows to reflect on how non-intuitive these "conventions" are.
Oh, and for that armv7a.c comparison error, I just used a temporary variable.
STEP 9: After all this, at long last, you should have a working 64 bit version of openocd.exe. At this stage, you want to finalize your installation with "make install"
STEP 10: Time for a test. You should of course have previously installed the FTDI USB drivers. And if you get a firewall exception warning from Vista on the first launch of openOCD, accept it!
$ cd /usr/local/share/openocd/scripts/ $ /usr/local/bin/openocd -f board/sheevaplug.cfg Open On-Chip Debugger 0.3.0-dev-svn2826 (2009-10-08-19:11) $URL: svn://svn.berlios.de/openocd/trunk/src/openocd.c $ For bug reports, read http://openocd.berlios.de/doc/doxygen/bugs.html 2000 kHz trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain jtag_nsrst_delay: 200 jtag_ntrst_delay: 200 dcc downloads are enabled Warn : use 'feroceon.cpu' as target identifier, not '0' Info : device: 4 "2232C" Info : deviceID: 2659753615 Info : SerialNumber: ******** Info : Description: SheevaPlug JTAGKey FT2232D B A Info : clock speed 2000 kHz Info : JTAG tap: feroceon.cpu tap/device found: 0x20a023d3 (mfg: 0x1e9, part: 0x 0a02, ver: 0x2)
Open On-Chip Debugger > sheevaplug_init target state: halted target halted in ARM state due to debug-request, current mode: Supervisor cpsr: 0x000000d3 pc: 0xffff0000 MMU: disabled, D-Cache: disabled, I-Cache: disabled 0 0 1 0: 00052078 > scan_chain TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ---|--------------------|---------|------------|------------|------|------|------|--------- 0 | feroceon.cpu | Y | 0x20a023d3 | 0x20a023d3 | 0x04 | 0x01 | 0x0f | 0x0c > nand probe 0 NAND flash device 'NAND 512MiB 3,3V 8-bit' found > nand list #0: NAND 512MiB 3,3V 8-bit (Hynix) pagesize: 2048, buswidth: 8, blocksize: 131072, blocks: 4096 >