Skip to content

Commit 7908b3a

Browse files
committed
Add libftdi build and add mingw64 build.
1 parent 14010f8 commit 7908b3a

File tree

5 files changed

+273
-7
lines changed

5 files changed

+273
-7
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff -Naur a/ft245r.c b/ft245r.c
2+
--- a/ft245r.c 2014-09-16 03:01:09.000000000 +0800
3+
+++ b/ft245r.c 2020-02-22 21:00:23.381036600 +0800
4+
@@ -653,14 +653,22 @@
5+
6+
7+
static void ft245r_close(PROGRAMMER * pgm) {
8+
+ int retry_times = 0;
9+
if (handle) {
10+
// I think the switch to BB mode and back flushes the buffer.
11+
ftdi_set_bitmode(handle, 0, BITMODE_SYNCBB); // set Synchronous BitBang, all in puts
12+
ftdi_set_bitmode(handle, 0, BITMODE_RESET); // disable Synchronous BitBang
13+
ftdi_usb_close(handle);
14+
- ftdi_deinit (handle);
15+
- pthread_cancel(readerthread);
16+
+ while(pthread_cancel(readerthread) && retry_times < 100) {
17+
+ retry_times++;
18+
+ usleep(100);
19+
+ }
20+
+ if (retry_times >= 100) {
21+
+ avrdude_message(MSG_INFO, "Too many retry to close reader thread\n");
22+
+ }
23+
+
24+
pthread_join(readerthread, NULL);
25+
+ ftdi_deinit (handle);
26+
free(handle);
27+
handle = NULL;
28+
}

avrdude-6.3.build.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ git clone https://github.com/facchinm/avrdude.git avrdude-6.3 --depth 1
2525
cd avrdude-6.3
2626

2727
patch -p1 < ../avrdude-6.3-patches/90*
28+
patch -p1 < ../avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch
2829

2930
export CFLAGS="-I$PREFIX/include -I$PREFIX/include/hidapi -I$PREFIX/include/libelf -I$PREFIX/include/ncurses -I$PREFIX/include/ncursesw -I$PREFIX/include/readline -I$PREFIX/include/libusb-1.0 $CFLAGS"
3031
export LDFLAGS="-L$PREFIX/lib $LDFLAGS"

libftdi-1.4.build.bash

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash -ex
2+
# Copyright (c) 2014-2016 Arduino LLC
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
18+
mkdir -p objdir
19+
cd objdir
20+
PREFIX=`pwd`
21+
cd -
22+
23+
if [[ ! -f libftdi1-1.4.tar.bz2 ]] ;
24+
then
25+
wget https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.4.tar.bz2
26+
fi
27+
28+
tar xfv libftdi1-1.4.tar.bz2
29+
30+
rm -rf libftdi1-1.4/build
31+
mkdir libftdi1-1.4/build
32+
33+
cd libftdi1-1.4/
34+
if [[ $OS == "Msys" ]] ; then
35+
patch -p1 < ../libftdi1-1.4-patches/01-add_sharedlibs_flag.patch
36+
fi
37+
cd build/
38+
39+
CMAKE_EXTRA_FLAG=""
40+
41+
if [[ $OS == "Msys" ]] ; then
42+
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DBUILD_TESTS=OFF -DSHAREDLIBS=OFF"
43+
fi
44+
45+
cmake $CMAKE_EXTRA_FLAG -DCMAKE_INSTALL_PREFIX="$PREFIX" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../
46+
make -j 1
47+
make install
48+
cd ../..
49+
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
diff -Naur a/CMakeLists.txt b/CMakeLists.txt
2+
--- a/CMakeLists.txt 2020-03-07 12:26:19.922659700 +0800
3+
+++ b/CMakeLists.txt 2020-03-07 15:11:57.839140900 +0800
4+
@@ -46,6 +46,7 @@
5+
set(CPACK_COMPONENT_STATICLIBS_GROUP "Development")
6+
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
7+
8+
+option ( SHAREDLIBS "Build ㄎ libraries" ON )
9+
option ( STATICLIBS "Build static libraries" ON )
10+
11+
# guess LIB_SUFFIX, don't take debian multiarch into account
12+
diff -Naur a/examples/CMakeLists.txt b/examples/CMakeLists.txt
13+
--- a/examples/CMakeLists.txt 2020-03-07 12:26:20.208196700 +0800
14+
+++ b/examples/CMakeLists.txt 2020-03-07 15:18:03.493009700 +0800
15+
@@ -8,29 +8,31 @@
16+
17+
message(STATUS "Building example programs.")
18+
19+
- # Targets
20+
- add_executable(simple simple.c)
21+
- add_executable(bitbang bitbang.c)
22+
- add_executable(bitbang2 bitbang2.c)
23+
- add_executable(bitbang_cbus bitbang_cbus.c)
24+
- add_executable(bitbang_ft2232 bitbang_ft2232.c)
25+
- add_executable(find_all find_all.c)
26+
- add_executable(serial_test serial_test.c)
27+
- add_executable(baud_test baud_test.c)
28+
- add_executable(stream_test stream_test.c)
29+
- add_executable(eeprom eeprom.c)
30+
-
31+
- # Linkage
32+
- target_link_libraries(simple ftdi1)
33+
- target_link_libraries(bitbang ftdi1)
34+
- target_link_libraries(bitbang2 ftdi1)
35+
- target_link_libraries(bitbang_cbus ftdi1)
36+
- target_link_libraries(bitbang_ft2232 ftdi1)
37+
- target_link_libraries(find_all ftdi1)
38+
- target_link_libraries(serial_test ftdi1)
39+
- target_link_libraries(baud_test ftdi1)
40+
- target_link_libraries(stream_test ftdi1)
41+
- target_link_libraries(eeprom ftdi1)
42+
+ if ( SHAREDLIBS )
43+
+ # Targets
44+
+ add_executable(simple simple.c)
45+
+ add_executable(bitbang bitbang.c)
46+
+ add_executable(bitbang2 bitbang2.c)
47+
+ add_executable(bitbang_cbus bitbang_cbus.c)
48+
+ add_executable(bitbang_ft2232 bitbang_ft2232.c)
49+
+ add_executable(find_all find_all.c)
50+
+ add_executable(serial_test serial_test.c)
51+
+ add_executable(baud_test baud_test.c)
52+
+ add_executable(stream_test stream_test.c)
53+
+ add_executable(eeprom eeprom.c)
54+
+
55+
+ # Linkage
56+
+ target_link_libraries(simple ftdi1)
57+
+ target_link_libraries(bitbang ftdi1)
58+
+ target_link_libraries(bitbang2 ftdi1)
59+
+ target_link_libraries(bitbang_cbus ftdi1)
60+
+ target_link_libraries(bitbang_ft2232 ftdi1)
61+
+ target_link_libraries(find_all ftdi1)
62+
+ target_link_libraries(serial_test ftdi1)
63+
+ target_link_libraries(baud_test ftdi1)
64+
+ target_link_libraries(stream_test ftdi1)
65+
+ target_link_libraries(eeprom ftdi1)
66+
+ endif()
67+
68+
# libftdi++ examples
69+
if(FTDI_BUILD_CPP)
70+
@@ -39,11 +41,13 @@
71+
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/ftdipp
72+
${Boost_INCLUDE_DIRS})
73+
74+
- # Target
75+
- add_executable(find_all_pp find_all_pp.cpp)
76+
-
77+
- # Linkage
78+
- target_link_libraries(find_all_pp ftdipp1)
79+
+ if ( SHAREDLIBS )
80+
+ # Target
81+
+ add_executable(find_all_pp find_all_pp.cpp)
82+
+
83+
+ # Linkage
84+
+ target_link_libraries(find_all_pp ftdipp1)
85+
+ endif()
86+
endif(Boost_FOUND)
87+
endif(FTDI_BUILD_CPP)
88+
89+
diff -Naur a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt
90+
--- a/ftdipp/CMakeLists.txt 2020-03-07 12:26:20.229190200 +0800
91+
+++ b/ftdipp/CMakeLists.txt 2020-03-07 15:13:30.150838600 +0800
92+
@@ -22,25 +22,26 @@
93+
94+
set(FTDI_BUILD_CPP True PARENT_SCOPE)
95+
message(STATUS "Building libftdi1++")
96+
-
97+
- # Shared library
98+
- add_library(ftdipp1 SHARED ${cpp_sources})
99+
-
100+
- math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
101+
- set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3)
102+
-
103+
- # Prevent clobbering each other during the build
104+
- set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1)
105+
-
106+
- # Dependencies
107+
- target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES})
108+
-
109+
-
110+
- install ( TARGETS ftdipp1
111+
- RUNTIME DESTINATION bin
112+
- LIBRARY DESTINATION lib${LIB_SUFFIX}
113+
- ARCHIVE DESTINATION lib${LIB_SUFFIX}
114+
- )
115+
+ if ( SHAREDLIBS )
116+
+ # Shared library
117+
+ add_library(ftdipp1 SHARED ${cpp_sources})
118+
+
119+
+ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
120+
+ set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3)
121+
+
122+
+ # Prevent clobbering each other during the build
123+
+ set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1)
124+
+
125+
+ # Dependencies
126+
+ target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES})
127+
+
128+
+
129+
+ install ( TARGETS ftdipp1
130+
+ RUNTIME DESTINATION bin
131+
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
132+
+ ARCHIVE DESTINATION lib${LIB_SUFFIX}
133+
+ )
134+
+ endif ()
135+
136+
# Static library
137+
if ( STATICLIBS )
138+
diff -Naur a/src/CMakeLists.txt b/src/CMakeLists.txt
139+
--- a/src/CMakeLists.txt 2020-03-07 12:26:20.257181000 +0800
140+
+++ b/src/CMakeLists.txt 2020-03-07 15:13:02.108714300 +0800
141+
@@ -21,22 +21,24 @@
142+
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" )
143+
set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" )
144+
145+
-add_library(ftdi1 SHARED ${c_sources})
146+
+if ( SHAREDLIBS )
147+
+ add_library(ftdi1 SHARED ${c_sources})
148+
149+
-math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
150+
-set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2)
151+
-# Prevent clobbering each other during the build
152+
-set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 )
153+
-
154+
-
155+
-# Dependencies
156+
-target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES})
157+
-
158+
-install ( TARGETS ftdi1
159+
- RUNTIME DESTINATION bin
160+
- LIBRARY DESTINATION lib${LIB_SUFFIX}
161+
- ARCHIVE DESTINATION lib${LIB_SUFFIX}
162+
- )
163+
+ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
164+
+ set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2)
165+
+ # Prevent clobbering each other during the build
166+
+ set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 )
167+
+
168+
+
169+
+ # Dependencies
170+
+ target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES})
171+
+
172+
+ install ( TARGETS ftdi1
173+
+ RUNTIME DESTINATION bin
174+
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
175+
+ ARCHIVE DESTINATION lib${LIB_SUFFIX}
176+
+ )
177+
+endif ()
178+
179+
if ( STATICLIBS )
180+
add_library(ftdi1-static STATIC ${c_sources})

package-avrdude.bash

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ elif [[ $OS == "Msys" || $OS == "Cygwin" ]] ; then
6565
echo you may experience build failure or weird behaviour
6666
echo *************************************************************
6767

68-
export PATH=$PATH:/c/MinGW/bin/:/c/cygwin/bin/
69-
export CC="mingw32-gcc -m32"
70-
export CXX="mingw32-g++ -m32"
71-
export TARGET_OS="Windows"
72-
OUTPUT_TAG=i686-mingw32
73-
68+
export MACHINE=`uname -m`
69+
if [[ $MACHINE == "x86_64" ]] ; then
70+
export CC="gcc"
71+
export CXX="g++"
72+
export TARGET_OS="Windows"
73+
OUTPUT_TAG=x86_64-mingw64
74+
else
75+
export PATH=$PATH:/c/MinGW/bin/:/c/cygwin/bin/
76+
export CC="mingw32-gcc -m32"
77+
export CXX="mingw32-g++ -m32"
78+
export TARGET_OS="Windows"
79+
OUTPUT_TAG=i686-mingw32
80+
fi
7481
elif [[ $OS == "Darwin" ]] ; then
7582

7683
export PATH=/opt/local/libexec/gnubin/:/opt/local/bin:$PATH
@@ -92,13 +99,14 @@ rm -rf avrdude-6.3 libusb-1.0.20 libusb-compat-0.1.5 libusb-win32-bin-1.2.6.0 li
9299
./libelf-0.8.13.build.bash
93100
./libncurses-5.9.build.bash
94101
./libhidapi.build.bash
102+
./libftdi-1.4.build.bash
95103
./avrdude-6.3.build.bash
96104

97105
# if producing a windows build, compress as zip and
98106
# copy *toolchain-precompiled* content to any folder containing a .exe
99107
if [[ ${OUTPUT_TAG} == *"mingw"* ]] ; then
100108

101-
cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll objdir/bin/libusb0.dll
109+
#cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll objdir/bin/libusb0.dll
102110
rm -f avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip
103111
cp -a objdir avrdude
104112
zip -r avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip avrdude/bin/ avrdude/etc/avrdude.conf

0 commit comments

Comments
 (0)