Skip to content

Commit 9d5762b

Browse files
committed
Support for cross-compilation for MacOS is added.
1 parent 78a9a66 commit 9d5762b

File tree

3 files changed

+152
-3
lines changed

3 files changed

+152
-3
lines changed

Makefile.MacOS

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
CXX = x86_64-apple-darwin15-g++
2+
CPPFLAGS = -g -O2 -Wno-narrowing -std=c++98 -mmacosx-version-min=10.8 -v
3+
INCPATH = -I. -I ../libftd2xx/D2XX
4+
LINK = x86_64-apple-darwin15-g++
5+
LFLAGS = -g -O2 -v -static-libgcc -lm -mmacosx-version-min=10.8 -lobjc -framework IOKit -framework CoreFoundation
6+
LIBS = -lftd2xx -L ../libftd2xx/D2XX
7+
8+
fireprog: butterfly.o jtag.o iobase.o ioftdi.o bitfile.o tools.o devicedb.o progalgspi.o progalgxc3s.o
9+
$(LINK) $(LFLAGS) $(LIBS) $^ -o $@
10+
11+
butterfly.o: butterfly.cpp io_exception.h jtag.h ioftdi.h devicedb.h progalgxc3s.h progalgspi.h bitfile.h
12+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o butterfly.o butterfly.cpp
13+
14+
bitfile.o: bitfile.cpp bitfile.h
15+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o bitfile.o bitfile.cpp
16+
17+
ioftdi.o: ioftdi.cpp ioftdi.h io_exception.h
18+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o ioftdi.o ioftdi.cpp
19+
20+
jtag.o: jtag.cpp jtag.h
21+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o jtag.o jtag.cpp
22+
23+
iobase.o: iobase.cpp iobase.h
24+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o iobase.o iobase.cpp
25+
26+
devicedb.o: devicedb.cpp devicedb.h devlist.h
27+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o devicedb.o devicedb.cpp
28+
29+
tools.o: tools.cpp tools.h config.h
30+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o tools.o tools.cpp
31+
32+
progalgxc3s.o: progalgxc3s.cpp progalgxc3s.h
33+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o progalgxc3s.o progalgxc3s.cpp
34+
35+
progalgspi.o: progalgspi.cpp progalgspi.h config.h
36+
$(CXX) -c $(CPPFLAGS) $(INCPATH) -o progalgspi.o progalgspi.cpp
37+
38+
clean:
39+
rm -rf *.o fireprog

README.md

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ from http://www.ftdichip.com/Drivers/D2XX.htm and unzip it into "libftd2xx" fold
4646

4747
The linker will use "../libftd2xx" folder (see the Make files). Modify the Make files to change the cross-compiler location (default is /usr/bin/i686-w64-mingw32-*).
4848

49-
After unzipping the libftd2xx driver, you can cross-compile on Linux for Windows (yields fireprog.exe, which is a PE32 or PE32+ executable).
49+
After unzipping the libftd2xx driver, you can cross-compile on Linux for Windows (yields "fireprog.exe", which is a PE32 or PE32+ executable).
5050
Depending on the architecture and linking type, one of the following commands should be executed:
5151

5252
make -f Makefile.MinGW32Static clean
@@ -61,7 +61,7 @@ Depending on the architecture and linking type, one of the following commands sh
6161
make -f Makefile.MinGW64Dynamic clean
6262
make -f Makefile.MinGW64Dynamic
6363

64-
Dynamically linked executables require some libraries from the MinGW cross-compiler. Putting these libraries in the same folder where fireprog.exe resides, allows execution without errors:
64+
Dynamically linked executables require some libraries from the MinGW cross-compiler. Putting these libraries in the same folder where "fireprog.exe" resides, allows execution without errors:
6565

6666
fireprog-win32-dynamic
6767
├── fireprog.exe
@@ -75,10 +75,117 @@ Dynamically linked executables require some libraries from the MinGW cross-compi
7575
├── libstdc++-6.dll
7676
└── libwinpthread-1.dll
7777

78+
79+
## Cross-compilation on Linux for MacOS
80+
Install OSXCross toolchain from source to an easily accessable directory (e.g. "/opt"):
81+
82+
# Make the directory readable and writable to the user first
83+
sudo chown -R $(whoami):users /opt
84+
sudo chmod 755 $(whoami):users /opt
85+
cd /opt
86+
git clone https://github.com/tpoechtrager/osxcross
87+
88+
Pack the SDK on MacOS on a real Apple computer and put the packed achive "MacOSX10.11.sdk.tar.xz" to "/opt/osxcross/tarballs".
89+
In this example, the MacOS cross-compiler is built for **OS X 10.11 El Capitan**, *Darwin version 15*.
90+
Check compatibility between SDK versions and corresdponding targets in:
91+
92+
/opt/osxcross/tools/osxcross-macports
93+
94+
If *clang* compiler is already installed, there is no need to build it. If not, then proceed as described in
95+
96+
/opt/osxcross/README.md
97+
98+
To build the cross toolchain (using *clang*), run:
99+
100+
cd /opt/osxcross
101+
./build.sh
102+
103+
Then build GCC:
104+
105+
./build_gcc.sh
106+
107+
Add OSXCross binary directory to the $PATH environment variable:
108+
109+
export PATH=$PATH:/opt/osxcross/target/bin
110+
111+
Check the cross-compiler:
112+
113+
x86_64-apple-darwin15-gcc -v
114+
Using built-in specs.
115+
COLLECT_GCC=x86_64-apple-darwin15-gcc
116+
COLLECT_LTO_WRAPPER=/opt/osxcross/target/bin/../libexec/gcc/x86_64-apple-darwin15/9.2.0/lto-wrapper
117+
Target: x86_64-apple-darwin15
118+
Configured with: ../configure --target=x86_64-apple-darwin15 --with-sysroot=/opt/osxcross/target/bin/../SDK/MacOSX10.11.sdk --disable-nls --enable-languages=c,c++,objc,obj-c++ --without-headers --enable-lto --enable-checking=release --disable-libstdcxx-pch --prefix=/opt/osxcross/target/bin/.. --with-system-zlib --with-ld=/opt/osxcross/target/bin/../bin/x86_64-apple-darwin15-ld --with-as=/opt/osxcross/target/bin/../bin/x86_64-apple-darwin15-as --with-multilib-list=m32,m64 --enable-multilib
119+
Thread model: posix
120+
gcc version 9.2.0 (GCC)
121+
122+
Once the toolchain is ready, download and unpack FTD2XX drivers for MacOS:
123+
124+
cd <path of the "fireprog" repository>
125+
# Change one directory up (important!)
126+
cd ..
127+
mkdir libftd2xx
128+
cd libftd2xx
129+
wget -vc https://www.ftdichip.com/Drivers/D2XX/MacOSX/D2XX1.4.16.dmg
130+
# Unpack archive using p7zip
131+
7z x D2XX1.4.16.dmg release/D2XX
132+
mv release/D2XX .
133+
134+
Rename the shared library file by adding some prefix:
135+
136+
mv D2XX/libftd2xx.1.4.16.dylib D2XX/backup_libftd2xx.1.4.16.dylib
137+
cd ..
138+
139+
This is needed to **enforce static linking**, so that static library *libftd2xx.a* instead of *libftd2xx.1.4.16.dylib* is used by the linker.
140+
141+
The hierarchy of the folders should look like this:
142+
143+
├── fireprog
144+
│   ├── bitfile.cpp
145+
│   ├── bitfile.h
146+
│ │...
147+
│   ├── tools.cpp
148+
│   └── tools.h
149+
150+
├── libftd2xx
151+
│   ├── D2XX
152+
│   │   ├── ftd2xx.cfg
153+
│   │   ├── ftd2xx.h
154+
│   │   ├── backup_libftd2xx.1.4.16.dylib
155+
│   │   ├── libftd2xx.a
156+
│   │   ├── libusb
157+
│   │   ├── Object
158+
│   │   ├── Samples
159+
│   │   └── WinTypes.h
160+
└── └── D2XX1.4.16.dmg
161+
162+
The corresponding Makefile is written according to this directory structure.
163+
164+
Now compile the "fireprog":
165+
166+
cd <path of the fireprog repository>
167+
make -f Makefile.MacOS
168+
169+
Check the output binary:
170+
171+
file fireprog
172+
fireprog: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>
173+
174+
The output executable should be statically linked with no dynamic dependencies such as FT2XX:
175+
176+
x86_64-apple-darwin15-otool -L fireprog
177+
fireprog:
178+
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
179+
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
180+
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1253.0.0)
181+
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
182+
183+
184+
78185
## Usage
79186

80187
In order to program the Prometheus board, plug it in the USB port, Windows OS should recognize it as a USB-to-Serial (RS232) converter and associate it with the libftd2xx driver.
81-
Now you can run fireprog.exe from the command line and supply the configuration bit-file.
188+
Now you can run "fireprog.exe" from the command line and supply the configuration bit-file.
82189

83190
Configuring FPGA with a bit-stream Circuit.bit:
84191

ioftdi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
2626
#include <windows.h>
2727
#include "ftd2xx.h"
2828
#define USE_FTD2XX
29+
#elif defined(__APPLE__)
30+
#include "ftd2xx.h"
31+
#define USE_FTD2XX
2932
#else
3033
#include <ftdi.h>
3134
#include <usb.h>

0 commit comments

Comments
 (0)