[UPDATED 2009.10.20 - To reflect the current patch status of OpenOCD/GIT]
[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
Preamble
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:
-
It’s up to date
-
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.
<B>**STEP 1:**</B> (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
;;
to
# 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
;;
The reason we do that on x86_64 system, the first case is still used (matches x86_*), which is plain wrong as we need to use the 64 bit version of the FTDI lib!. I will try to submit a patch to address this. Note that the configure script also appears not to be able to report 64 bit x86 CPUs properly (but we can fix that with the --build=x86_64-w64-mingw32 below).
<B>**STEP 2:**</B> In the command prompt, run```
./bootstrap
STEP 3: [NOT NEEDED IF DOWNLOADED FROM GIT] If you downloaded from SVN, edit openocd/src/openocd.c and remove or comment the line (line #50):```
#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?)
<B>**STEP 4: [NOT NEEDED IF DOWNLOADED FROM GIT]**</B> Edit openocd/src/Makefile.in and change the line (line #300):```
@IS_MINGW_TRUE@MINGWLDADD = -lwsock32
```to```
@IS_MINGW_TRUE@MINGWLDADD = -lws2_32
```If you don't do that, your compilation will fail on -lwsock32 not found near the end
<B>**STEP 5:**</B> 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
```A look at the config.log will report the error ```
C:\Users\nil\AppData\Local\Temp\ccOBXOer.o:conftest.c:(.text+0x1e): undefined reference to `_imp__FT_GetLibraryVersion'
```The problem here is that MinGW does expect DLL translated names from .lib files to begin with __imp__ (eg: __imp__FT_GetLibraryVersion) whereas Visual C++ libraries provide names beginning with __imp_ (eg: __imp_FT_GetLibraryVersion). The problem really is something as stupid as using one or two underscores to declare the names of the DLL functions in the relevant .lib file, but because of that we can't use the .lib provided by FTDI. Instead we need to recreate one.
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
This should create a new "ftd2xx.lib" that MinGW can understand.
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 6: At this stage, you want to make ftd2xx64.dll available to the system (else you’re going to get "ftd2xx64.dll not found). The easiest way is to simply copy the DLL file to your C:\Windows\System32\ folder (Yes, I know it’s a 64 bit library, but copying it ot C:\Windows\SysWOW64\ doesn’t seem to work)
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
Make sure you specify amd64_w64-mingw32 to either --build or --host, as otherwise the configure script will still report your CPU as 686, and thus will look for the 32 bit version of the FTD2xx libraries (see step 1)
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)
and from a telnet window (eg putty) to localhost:4444
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
>
PS: For those interested, I also have a guide on how to compile OpenOCD (with libftdi or ftd2xx.lib) for a Linux x64 system. Can’t link to it because of this forum’s restrictions though… Oh well.](OpenOCD - Open On-Chip Debugger - Browse Files at SourceForge.net)](Google Code Archive - Long-term storage for Google Code Project Hosting.)](http://www.ftdichip.com/Drivers/D2XX.htm)](http://www.cadforte.com/system64.html)](Building OpenOCD with libfti/libusb for Windows 64 - SparkFun Electronics Forum)