How to build OpenOCD for windows

Hi

I can not compile the OpenOCD with the option ‘CC=“gcc -mno-cygwin”’. It says:

configure: error: unrecognized option: `-mno-cygwin’

I have read somewhere that this option is removed, but I did not found a guide how to overcome it.

If I try to build it for cygwin I have the following error:

Error: unable to open ftdi device: unable to claim usb device. Make sure the def

ault FTDI driver is not in use

in procedure ‘init’

But the drivers are OK, since I can use the one compiled by Olimex. I am using ARM-USB-OCD (manufactured by Olimex).

Please, help me to compile the OpenOCD, since I would like to support it by writing a code for one Cortex (ARM) which is not supported yet.

Thank you in advance

Drago

Hello,

here is a short tutorial how to build openocd for windows.

(Tested with SVN version 2348 of OpenOCD)

Install cygwin, but you need some additional tools from the

development package like:

  • autoconf: Wrapper scripts for autoconf commands

  • automake: Wrapper scripts for automake and aclocals

  • gcc: C compiler upgrade helper

  • libtool: A shared library generation tool

  • make: The GNU version og the ‘make’ utility

  • subversion: A version control system

see more:

http://blog.csdn.net/jordon_ah/article/details/4396866

Hello,

it is nice idea to compile under Ubuntu. Please Mr. “gibbon1” can you provide your command line args. for ./configure script for your example? Thank you.

Here’s a set of scripts I put together for cross-compiling OpenOCD for Windows via mingw32 on Debian:

[openocd-mingw32-build-scripts

I’m by no means an expert at shell scripting or cross-compiling, but hopefully someone finds this useful.](GitHub - caspencer/openocd-mingw32-build-scripts: Build scripts for cross-compiling OpenOCD for Windows (via mingw32 on Linux))

Good guide, I just would like to add this:

First, have tcl installed by the cygwin.

Second, after you start the bash, make sure PATH has nothing but /usr/bin in it. If you have some packages that might have tools with the same name in the PATH, it will give you all sorts of weird build errors. Once I removed all of those, the build went pretty smooth.

I built open OCD 0.6.1 by loading the .zip from sourceforge, and trying to follow the instructions on the first page.

./bootstrap didn’t work for me, either.

I built it for windows using cygwin’s MingW compiler, by installing MingW when I installed cygwin, and then using the following autoconf line:

./configure --enable-maintainer-mode --disable-werror --disable-shared --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=/home/openocd/ftd2xx CC=“i686-pc-mingw32-gcc -mno-cygwin”

I needed to add a flash algorithm, and it seems that to add things, one must change both the .am and .in files

in the directory where the file must live.

I still haven’t tested the new code, but it’s grossly alive; i.e. it complains about lacking a .cfg file, etc.

An update: I found that using cygwin to make windows code probably should cross compile.

The “CC” notation recommended on the first page to select a compiler is deprecated in the GNU automake documentation.

So, using cross compiling, with automake, the configure command to cross-compile to windows 32-bit is:

./configure --enable-maintainer-mode --disable-werror --disable-shared --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=/home/openocd/ftd2xx --build=i686-pc-cygwin --host=i686-pc-mingw32

A mistake in the above text: Do not edit *.in files; In a correctly-running automake, they are regenerated from the Makefile.am files.

My cygwin build environment installs the wrong version of aclocal.m4; before running make, I have to replace it with the one from the distribution files for openocd, and touch it so the make doesn’t replace it. After that, the make complains but finishes.

I also found out more about the available options. I haven’t tried them; YMMV.

The “ftd2xx” clauses, above get and use the proprietary but certified windows driver from FTDI, provider of the JTAG IC. Substituting “ftdi” into those commands with the 0.6.1 version of openocd is supposed to invoke the open-source asynchronous driver for the FTDI chip(s).

Also, it appears that the cygwin installer can install a MingW64 compiler that enables an option to cross-compile for 64-bit windows.

Has anyone had any success building OpenOCD 0.7.0 from the Git repo of late? I am trying to build it using the D2XX drivers and libusbx. I am trying to build from the Git repo because I need access to the latest TI ICDI on the LM4F devkit(s).

I have put the build script (as a Gist) at: https://gist.github.com/4599885

If I do not configure openocd with JLink and TI ICDI support enabled, everything works. But if I enable either JLink or TI ICDI support, the configuration and build seem to complete fine, but when I run openocd I get nothing on stdout, it just returns without doing anything.

This is the first time I have really tried to build OpenOCD cross-compiling under Cygwin for MinGW so it is quite possible I am not putting things where they belong.

I would appreciate any help.

It can be a pain to setup the build on windows, I generally use linux to cross build.

I am presuming you have installed the various libs, eg. libusbx into the correct compiler directory?

Anyway can you show us the build log to show what is failing.

I do have a cygwin cross build setup on my work pc and for that i have switched to using mingw64-i686 (win32) and mingw64-x86_64 (win64) compilers.

Cheers

Spen

Unfortunantly, the problem isn’t the build. I can presumably build it just fine. I configure OpenOCD and then run ‘make’ and ‘make install’ and get no errors. I get an executable and as far as I can tell any libraries that it builds and requires. When I run the executable I don’t see any output…no error message, no fault message, no unable to load library message, nothing but nothing. When I execute “openocd --version” I also get nothing.

Regarding installing the libraries to the correct location…that I do not know. As far as I can tell I have simply because during configuration everything is found, but it is possible that I haven’t done something correctly. All of my steps (downloading the various libraries, extracting, copying them to required locations, configuration, build, etc) can be found in the gist I posted at https://gist.github.com/4599885 (it is the actual script I used to try and build OpenOCD).

I am using the MinGW environment that is found in the Cygwin packages:

gcc-mingw (20040810-1)

gcc-mingw-core (20050522-3)

gcc-mingw-g++ (20050522-3)

mingw-binutils (2.21-1)

mingw-gcc-core (4.5.2-1)

mingw-pthreads (20110507-1)

mingw-runtime (3.20-1)

Hmm…looks like you are using a different MinGW? I’ll try using mingw64-i686 and see if that changes anything. I just assumed that the ones I installed where the generic version…the meta-packages, but maybe not?

Well, just install i686-w64-mingw32 and I get the same thing (I updated the script in the gist to copy things to /usr/i686-w64-mingw32/sys-root/mingw).

If I was to cross-compile under linux for windows, would I follow the same steps simply specify a different ‘–build’ option when configuring OpenOCD? I haven’t found any good information that indicates HOW to install libusbx properly when using MinGW to cross-compile.

Ah ok i misread your first post.

perhaps it is worth building OpenOCD with no adapters to check the tools are ok as no output sounds very strange.

Cheers

Spen

I actually did build it without the ‘–enable-jlink’ and ‘–enable-ti-icdi’ options and it worked fine then.

I went ahead and installed MinGW on a Mint Linux virtual machine and took my same script, updated it to use the Mint/Ubuntu MinGW installation (i.e. simply changed the location that the libraries where getting copied to to /usr/i686-w64-mingw32/…) and things are now working. Copied over the build executable to my main Windows installation and it seems to be running…though I do now have another issue.

When trying to debug a Stellaris LM4F232 devkit from TI using OpenOCD, I can connect and reset the board and I can single instruction step through the boot process but I get mostly instruction errors. I can the exact same board and debug it using a JLink using the JLink GDB server (same remote GDB client ‘arm-none-eabi-gdb’) and when I single instruction step and decode the instructions (‘display/i $pc’) I get correctly disassembled instructions.

Am I missing a configuration option?

cmeyer:
I actually did build it without the ‘–enable-jlink’ and ‘–enable-ti-icdi’ options and it worked fine then.

I went ahead and installed MinGW on a Mint Linux virtual machine and took my same script, updated it to use the Mint/Ubuntu MinGW installation (i.e. simply changed the location that the libraries where getting copied to to /usr/i686-w64-mingw32/…) and things are now working. Copied over the build executable to my main Windows installation and it seems to be running…though I do now have another issue.

That’s good news :slight_smile:

cmeyer:
When trying to debug a Stellaris LM4F232 devkit from TI using OpenOCD, I can connect and reset the board and I can single instruction step through the boot process but I get mostly instruction errors. I can the exact same board and debug it using a JLink using the JLink GDB server (same remote GDB client ‘arm-none-eabi-gdb’) and when I single instruction step and decode the instructions (‘display/i $pc’) I get correctly disassembled instructions.

Am I missing a configuration option?

Not so good, OpenOCD will only return the info requested by gdb - just a thought but try adding the following to your gdb init, it could be related to the memory map returned by OpenOCD.

set mem inaccessible-by-default off

If this does not help perhaps better move to a new thread.

Cheers

Spen

I get an error from OpenOCD regarding that syntax. Should it be “set mem-inaccessible-by-default off”?

That needs to be in your gdb init, not OpenOCD

Spen

Oops, sorry, missed that. I tried that and it didn’t fix the issue. I have posted my question to a new thread now: https://forum.sparkfun.com/viewtopic.php?f=18&t=34635

Now copy the file libusb-win32-device-bin-0.1.12.2\include\usb.h

to the following directories:

c:\cygwin\usr\include

c:\cygwin\usr\include\mingw

Even you must copy the library libusb-win32-device-bin-0.1.12.2\lib\gcc\libusb.a

to the following directories:

c:\cygwin\lib

c:\cygwin\lib\mingw

Hello,

I am trying to build OpenOCD for Olimex USB-TINY-H. I installed Cygwin, but the install directory doesn’t contain C:\Cygwin\lib\mingw and C:\cygwin\include\mingw. So where do I copy the files. Please share ur views. Thanks

Hi,

I try to build openOCD on cygWin. The bootstrap and configure seems ok and the building goes quite well.

Till it comes by the linking of the Ulink.o. It gives an error of undefined roundf() but the -lm is on the command line. If i build a small program with roundf() it works.

Any idea how to solve this? thanks.

Edit:

Perhaps a minGW bug (http://sourceforge.net/p/mingw/bugs/2155/), right now I add the roundf to the ulink code.

I found systems which are testing the roundf() in the configure and are linking the roundf if necessary.

Update:

Everything is working now and build with cygWin. I had sbrk (memory allocation) errors of aclocal with Msys so I moved to cygWin. To make it build with the current cygWin installer (9 July 2014) you have to do some more steps then the tutorials are showing which can be found on the internet. You have to select some more packages (like pkg-config) which aren’t apparently no longer installed by default. Symlink the aclocal and automake version 1.13 and apply the workaround as above.

Hi. Latest experience of building OpenOCD-0.8.0 (commit 30203b3d8b8cf77986245dc1fd331697f36b5c05).

  1. Clone OpenOCD repo: git://git.code.sf.net/p/openocd/code

  2. Download mingw http://sourceforge.net/projects/mingw-w … in32/sjlj/ This is online installer, I select compiller version 4.9.2 and architecture i686.

  3. Download msys http://cznic.dl.sourceforge.net/project … s-rev13.7z (online installer fail for me, this is end link to achcive).

  4. Copy installed mingw to msys to “local” directory (this is easiest way : ), copy OpenOCD sources to msys\home\User.

  5. Run msys console, go to source dir and run

./bootstrap
``` and got something like 

User@MaxL ~/OpenOCD_src/code
$ ./bootstrap

  • aclocal
  • libtoolize --automake --copy
  • autoconf
  • autoheader
  • automake --gnu --add-missing --copy
    Makefile.am:23: warning: wildcard $(srcdir: non-POSIX variable name
    Makefile.am:23: (probably a GNU make extension)
    Setting up submodules
    Bootstrap complete. Quick build instructions:
    ./configure …

Download libraries: [http://citylan.dl.sourceforge.net/proje ... .14-win.7z](http://citylan.dl.sourceforge.net/project/libusbx/releases/1.0.14/Windows/libusbx-1.0.14-win.7z) and [http://sourceforge.net/projects/libusb- ... t/download](http://sourceforge.net/projects/libusb-win32/files/latest/download) .

Take libusbx-1.0.14-win\MinGW32\static\libusb-1.0.a and put to msys+7za+wget+svn+git+mercurial+cvs-rev13\msys\local\lib

Take libusb-win32-bin-1.2.6.0\libusb-win32-bin-1.2.6.0\lib\gcc\libusb.a and put to same location

Create a new file "libusb-1.0.pc" with next content:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: libusb-1.0
Description: C API for USB device access from Linux userspace
Version: 1.0.18
Libs: -L${libdir} -lusb
Cflags: -I${includedir}


Put it to msys\local\lib\pkgconfig (create if not exists)

Do in console

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig


Put header \libusbx-1.0.14-win\include\libusbx-1.0\libusb.h to msys\local\include

Run configure:

LDFLAGS=“-lusb-1.0” ./configure --prefix= --disable-shared --enable-aice --enable-jlink --enable-stlink

OpenOCD need only library libusb-1.0, but for for some reason it try to link old version libusb (not 1.0). LDFLAGS need to link proper version - libusb-1.0.

after configure have got

OpenOCD configuration summary

MPSSE mode of FTDI based devices yes (auto)
ST-Link JTAG Programmer yes
TI ICDI JTAG Programmer yes (auto)
Keil ULINK JTAG Programmer yes (auto)
Altera USB-Blaster II Compatible yes (auto)
Versaloon-Link JTAG Programmer yes (auto)
Segger J-Link JTAG Programmer yes
OSBDM (JTAG only) Programmer yes (auto)
eStick/opendous JTAG Programmer yes (auto)
Andes JTAG Programmer yes
USBProg JTAG Programmer no
Raisonance RLink JTAG Programmer no
Olimex ARM-JTAG-EW Programmer no
CMSIS-DAP Compliant Debugger no


and run

make

after make check openocd.exe in /home/User/OpenOCD_src/code/src

do ```
make install

and collect new openocd:

openocd.exe you cat take in /home/User/OpenOCD_src/code/src, scripts and other in msys\share\openocd.