Using FTDI-based devices with ftd2xx.dll under wine

I have pretty good USB oscilloscope (http://pv65.ru/), that unfortunately does not come with software for GNU/Linux. I’ve got it working inside of KVM Windows-VM. But it’s not the best solution and performance is worst in this case too.

I’ve seen previously some posts (in English and in Russian) about wine wrapper for ftd2xx.dll. Unfortunately I haven’t much lock with this wrapper. Source seems to be not available anymore. But I liked the idea. I’ve found another much newer wine wrapper on github. Here I’ll try to describe shortly how I’ve built it on Debian Testing (Stretch) x86_64 architecture.

The main problem is that my system is x86_64 and I need to build for i386.

Firstly to  compile source code is used winegcc, that “emulates” mingw compiler under Linux. It’s included in wine64-tools and wine32-tools. For i386 I need wine32-tools package, but I couldn’t install it, because of broken dependencies (perl and some other stuff). I could only install wine64-tools. Additionally I installed gcc-multilib to compile for 32 bit.

Good. Now we have winegcc. Winegcc is not in PATH. To fix that add winegcc to the PATH.

$ export PATH=/usr/lib/x86_64-linux-gnu/wine:$PATH

Another problem is that winegcc64 generates code for x86_64. To fix that in Makefile add ‘-m32’ to all invocation of winegcc (it’s not enough to add ‘-m32’ to CFLAGS only in one place).

Next trouble is, that linker couldn’t find.

ld: Relocatable linking with relocations from format elf64-x86-64 (/usr/lib/x86_64-linux-gnu/wine/libwinecrt0.a(dll_entry.o)) to format elf32-i386 (ftd2xx.Y3kKUq.o) is not supported

To fix that install libwine-development-dev:i386 package and add to LIBS variable in Makefile full path to 32-bit libraries (-L/usr/lib/i386-linux-gnu/wine-development/).

The build succeeded. Now it’s time to install the binaries. Unfortunately install target is broken to with latest wine on Debian, because of moving to the multilib environment. winedllpath from the git-repository doesn’t detect path correct. wine libraries are moved to /usr/lib/i386-linux-gnu/wine. To fix install target I’ve just replace definition of  WINEDLLPATH with ‘/usr/lib/$(ARCH)-linux-gnu/wine’.

I created deb package using checkinstall to manage binaries afterwards.

All was good and fun. Now check all this together. Oscilloscope software started, ftd2xx.dll was replaced with wrapper, but unfortunately segmentation fault happened as soon as the application tried to access FTDI device. I’ve not investigated this problem yet. Maybe later or maybe I’ll just write driver for sigrok / pulseview to support this oscilloscope.

Here there are all modification that I’ve done to build wine wrapper in patch format:

diff –git a/Makefile b/Makefile
index ee3d594..ceb15e7 100644
— a/Makefile
+++ b/Makefile
@@ -1,12 +1,13 @@
#Makefile for wineftd2xx<->ftd2xx shim dll
#Revised: 9/30/14 brent@mbari.org
#WARNING: omitting frame pointer causes crashes
+ARCH=i386
CFLAGS = -g -O0 -Wall
-LIBS=libxftd2xx.a -ldl -lrt -lpthread
+LIBS=-L/usr/lib/i386-linux-gnu/wine-development/ libxftd2xx.a -ldl -lrt -lpthread

RELEASE=wineftd2xx1.1.1

-WINEDLLPATH := $(shell ./winedllpath $(ARCH))
+WINEDLLPATH := /usr/lib/$(ARCH)-linux-gnu/wine
ifeq (“$(WINEDLLPATH)”, “”)
$(error Can’t guess WINEDLLPATH — \
specify it with make WINEDLLPATH={path_to_dll.so directory})
@@ -49,11 +50,11 @@ xftd2xx.h: $(IDIR)/ftd2xx.h Makefile
sed “s/WINAPI FT_/WINAPI xFT_/g” $(IDIR)/ftd2xx.h >$@

ftd2xx.o: ftd2xx.c xftd2xx.h WinTypes.h
– winegcc -D_REENTRANT -D__WINESRC__ -c $(CFLAGS) \
+ winegcc -m32 -D_REENTRANT -D__WINESRC__ -c $(CFLAGS) \
-I$(IDIR) -fno-omit-frame-pointer -o $@ ftd2xx.c

ftd2xx.dll.so: ftd2xx.o ftd2xx.spec libxftd2xx.a
– winegcc $(LIBS) -mwindows -lntdll -lkernel32 \
+ winegcc -m32 $(LIBS) -mwindows -lntdll -lkernel32 \
-o ftd2xx.dll ftd2xx.o libxftd2xx.a -shared ftd2xx.spec

libftd2xx.def: ftd2xx.spec ftd2xx.dll.so

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s