Skip to content

Add libftdi build and add mingw64 build. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian

RUN apt-get update && apt-get install -y gcc-mingw-w64-i686 g++-mingw-w64-i686 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 libtool pkg-config bzip2 zip make autoconf gperf wget patch git gcc g++ automake flex bison cmake xsltproc && rm -rf /var/lib/apt/lists/*

COPY . /avrdude-build-script

WORKDIR /avrdude-build-script

ENTRYPOINT ["/avrdude-build-script/package-avrdude.bash"]
18 changes: 17 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ Just run:
Setup has been done on partially set up development machines.
If you find any package missing from the following list, please open an issue at once!

### Docker Building

Run:
```
mkdir dist
docker build . -t avrdude-builder
# cross compile i686
docker run --rm -it -v $PWD/dist:/avrdude-build-script/dist -e CROSS_COMPILE=mingw avrdude-builder
# cross compile x86_64
docker run --rm -it -v $PWD/dist:/avrdude-build-script/dist -e CROSS_COMPILE=mingw64 avrdude-builder
# remove container
docker rmi avrdude-builder
```

If you do not need cross compile, just remove `-e CROSS_COMPILE=mingw`.

#### Debian requirements

```bash
Expand Down Expand Up @@ -47,7 +63,7 @@ sudo apt-get install gcc-mingw-w64-i686
When building you must set the env var `CROSS_COMPILE` to `mingw` for example:

```
CROSS_COMPILE=mingw ./package_avrdude.bash
CROSS_COMPILE=mingw ./package-avrdude.bash
```

cross compile with mingw has been tested on Ubuntu 14.04 (mingw-w64 4.8), different versions of mingw may behave differently and fail to build.
Expand Down
28 changes: 28 additions & 0 deletions avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff -Naur a/ft245r.c b/ft245r.c
--- a/ft245r.c 2014-09-16 03:01:09.000000000 +0800
+++ b/ft245r.c 2020-02-22 21:00:23.381036600 +0800
@@ -653,14 +653,22 @@


static void ft245r_close(PROGRAMMER * pgm) {
+ int retry_times = 0;
if (handle) {
// I think the switch to BB mode and back flushes the buffer.
ftdi_set_bitmode(handle, 0, BITMODE_SYNCBB); // set Synchronous BitBang, all in puts
ftdi_set_bitmode(handle, 0, BITMODE_RESET); // disable Synchronous BitBang
ftdi_usb_close(handle);
- ftdi_deinit (handle);
- pthread_cancel(readerthread);
+ while(pthread_cancel(readerthread) && retry_times < 100) {
+ retry_times++;
+ usleep(100);
+ }
+ if (retry_times >= 100) {
+ avrdude_message(MSG_INFO, "Too many retry to close reader thread\n");
+ }
+
pthread_join(readerthread, NULL);
+ ftdi_deinit (handle);
free(handle);
handle = NULL;
}
8 changes: 5 additions & 3 deletions avrdude-6.3.build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ cd objdir
PREFIX=`pwd`
cd -

rm -rf avrdude-6.3
git clone https://github.com/facchinm/avrdude.git avrdude-6.3 --depth 1

cd avrdude-6.3

patch -p1 < ../avrdude-6.3-patches/90*
patch -p1 < ../avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch

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"
export LDFLAGS="-L$PREFIX/lib $LDFLAGS"
Expand All @@ -38,9 +40,9 @@ fi

COMMON_FLAGS=""

if [[ $CROSS_COMPILE == "mingw" ]] ; then
CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS"
LIBS="-lhidapi -lsetupapi"
if [[ $CROSS_COMPILE == "mingw" || $CROSS_COMPILE == "mingw64" || $OS == "Msys" ]] ; then
CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS"
LIBS="-lhidapi -lsetupapi -Wl,-Bstatic -lwinpthread"
fi

if [[ $OS == "Darwin" ]] ; then
Expand Down
51 changes: 51 additions & 0 deletions libftdi-1.4.build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash -ex
# Copyright (c) 2014-2016 Arduino LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

mkdir -p objdir
cd objdir
PREFIX=`pwd`
cd -

if [[ ! -f libftdi1-1.4.tar.bz2 ]] ;
then
wget https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.4.tar.bz2
fi

tar xfv libftdi1-1.4.tar.bz2

rm -rf libftdi1-1.4/build
mkdir libftdi1-1.4/build

cd libftdi1-1.4/
patch -p1 < ../libftdi1-1.4-patches/01-add_sharedlibs_flag.patch
cd build/

CMAKE_EXTRA_FLAG="-DSHAREDLIBS=OFF -DBUILD_TESTS=OFF"

if [[ $OS == "GNU/Linux" && $CROSS_COMPILE == "mingw" ]] ; then
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-i686-w64-mingw32.cmake"
fi

if [[ $OS == "GNU/Linux" && $CROSS_COMPILE == "mingw64" ]] ; then
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-x86_64-w64-mingw32.cmake"
fi

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" ../
make -j 1
make install
cd ../..

180 changes: 180 additions & 0 deletions libftdi1-1.4-patches/01-add_sharedlibs_flag.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
diff -Naur a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2020-03-07 12:26:19.922659700 +0800
+++ b/CMakeLists.txt 2020-03-07 15:11:57.839140900 +0800
@@ -46,6 +46,7 @@
set(CPACK_COMPONENT_STATICLIBS_GROUP "Development")
set(CPACK_COMPONENT_HEADERS_GROUP "Development")

+option ( SHAREDLIBS "Build ㄎ libraries" ON )
option ( STATICLIBS "Build static libraries" ON )

# guess LIB_SUFFIX, don't take debian multiarch into account
diff -Naur a/examples/CMakeLists.txt b/examples/CMakeLists.txt
--- a/examples/CMakeLists.txt 2020-03-07 12:26:20.208196700 +0800
+++ b/examples/CMakeLists.txt 2020-03-07 15:18:03.493009700 +0800
@@ -8,29 +8,31 @@

message(STATUS "Building example programs.")

- # Targets
- add_executable(simple simple.c)
- add_executable(bitbang bitbang.c)
- add_executable(bitbang2 bitbang2.c)
- add_executable(bitbang_cbus bitbang_cbus.c)
- add_executable(bitbang_ft2232 bitbang_ft2232.c)
- add_executable(find_all find_all.c)
- add_executable(serial_test serial_test.c)
- add_executable(baud_test baud_test.c)
- add_executable(stream_test stream_test.c)
- add_executable(eeprom eeprom.c)
-
- # Linkage
- target_link_libraries(simple ftdi1)
- target_link_libraries(bitbang ftdi1)
- target_link_libraries(bitbang2 ftdi1)
- target_link_libraries(bitbang_cbus ftdi1)
- target_link_libraries(bitbang_ft2232 ftdi1)
- target_link_libraries(find_all ftdi1)
- target_link_libraries(serial_test ftdi1)
- target_link_libraries(baud_test ftdi1)
- target_link_libraries(stream_test ftdi1)
- target_link_libraries(eeprom ftdi1)
+ if ( SHAREDLIBS )
+ # Targets
+ add_executable(simple simple.c)
+ add_executable(bitbang bitbang.c)
+ add_executable(bitbang2 bitbang2.c)
+ add_executable(bitbang_cbus bitbang_cbus.c)
+ add_executable(bitbang_ft2232 bitbang_ft2232.c)
+ add_executable(find_all find_all.c)
+ add_executable(serial_test serial_test.c)
+ add_executable(baud_test baud_test.c)
+ add_executable(stream_test stream_test.c)
+ add_executable(eeprom eeprom.c)
+
+ # Linkage
+ target_link_libraries(simple ftdi1)
+ target_link_libraries(bitbang ftdi1)
+ target_link_libraries(bitbang2 ftdi1)
+ target_link_libraries(bitbang_cbus ftdi1)
+ target_link_libraries(bitbang_ft2232 ftdi1)
+ target_link_libraries(find_all ftdi1)
+ target_link_libraries(serial_test ftdi1)
+ target_link_libraries(baud_test ftdi1)
+ target_link_libraries(stream_test ftdi1)
+ target_link_libraries(eeprom ftdi1)
+ endif()

# libftdi++ examples
if(FTDI_BUILD_CPP)
@@ -39,11 +41,13 @@
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/ftdipp
${Boost_INCLUDE_DIRS})

- # Target
- add_executable(find_all_pp find_all_pp.cpp)
-
- # Linkage
- target_link_libraries(find_all_pp ftdipp1)
+ if ( SHAREDLIBS )
+ # Target
+ add_executable(find_all_pp find_all_pp.cpp)
+
+ # Linkage
+ target_link_libraries(find_all_pp ftdipp1)
+ endif()
endif(Boost_FOUND)
endif(FTDI_BUILD_CPP)

diff -Naur a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt
--- a/ftdipp/CMakeLists.txt 2020-03-07 12:26:20.229190200 +0800
+++ b/ftdipp/CMakeLists.txt 2020-03-07 15:13:30.150838600 +0800
@@ -22,25 +22,26 @@

set(FTDI_BUILD_CPP True PARENT_SCOPE)
message(STATUS "Building libftdi1++")
-
- # Shared library
- add_library(ftdipp1 SHARED ${cpp_sources})
-
- math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
- set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3)
-
- # Prevent clobbering each other during the build
- set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1)
-
- # Dependencies
- target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES})
-
-
- install ( TARGETS ftdipp1
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib${LIB_SUFFIX}
- ARCHIVE DESTINATION lib${LIB_SUFFIX}
- )
+ if ( SHAREDLIBS )
+ # Shared library
+ add_library(ftdipp1 SHARED ${cpp_sources})
+
+ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
+ set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3)
+
+ # Prevent clobbering each other during the build
+ set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1)
+
+ # Dependencies
+ target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES})
+
+
+ install ( TARGETS ftdipp1
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
+ ARCHIVE DESTINATION lib${LIB_SUFFIX}
+ )
+ endif ()

# Static library
if ( STATICLIBS )
diff -Naur a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt 2020-03-07 12:26:20.257181000 +0800
+++ b/src/CMakeLists.txt 2020-03-07 15:13:02.108714300 +0800
@@ -21,22 +21,24 @@
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" )
set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" )

-add_library(ftdi1 SHARED ${c_sources})
+if ( SHAREDLIBS )
+ add_library(ftdi1 SHARED ${c_sources})

-math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
-set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2)
-# Prevent clobbering each other during the build
-set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 )
-
-
-# Dependencies
-target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES})
-
-install ( TARGETS ftdi1
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib${LIB_SUFFIX}
- ARCHIVE DESTINATION lib${LIB_SUFFIX}
- )
+ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases
+ set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2)
+ # Prevent clobbering each other during the build
+ set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 )
+
+
+ # Dependencies
+ target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES})
+
+ install ( TARGETS ftdi1
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
+ ARCHIVE DESTINATION lib${LIB_SUFFIX}
+ )
+endif ()

if ( STATICLIBS )
add_library(ftdi1-static STATIC ${c_sources})
2 changes: 1 addition & 1 deletion libncurses-5.9.build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cd objdir
PREFIX=`pwd`
cd -

if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "aarch64-linux-gnu" ]] ; then
if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "x86_64-w64-mingw32" || $CROSS_COMPILE_HOST == "aarch64-linux-gnu" ]] ; then
#Avoid compiling ncurses in Windows platform
exit 0
fi
Expand Down
3 changes: 2 additions & 1 deletion libusb-compat-0.1.5.build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw
wget http://download.sourceforge.net/project/libusb-win32/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip
fi
unzip libusb-win32-bin-1.2.6.0.zip
#mkdir -p $PREFIX/bin/
#cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll $PREFIX/bin/libusb0.dll
cp libusb-win32-bin-1.2.6.0/include/lusb0_usb.h $PREFIX/include
cp libusb-win32-bin-1.2.6.0/lib/gcc/libusb.a $PREFIX/lib
Expand All @@ -40,7 +41,7 @@ fi
tar xfv libusb-compat-0.1.5.tar.bz2

cd libusb-compat-0.1.5
if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" ]] ; then
if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "x86_64-w64-mingw32" ]] ; then
patch -p1 < ../libusb-compat-0.1.5-patches/01-mingw-build.patch
autoreconf --force --install
fi
Expand Down
Loading