From 1ef3e608a3e0d65c05024983695e3147d8605d41 Mon Sep 17 00:00:00 2001 From: Simon Nishi McCorkindale Date: Fri, 28 May 2021 19:12:21 +0800 Subject: [PATCH 1/2] Add support to compile ARM64 bit (arm64-v8a) --- README.Android | 8 +++++-- cmake/Toolchain-Android-arm64-v8a.cmake | 31 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 cmake/Toolchain-Android-arm64-v8a.cmake diff --git a/README.Android b/README.Android index ae3de45..cfa3c44 100644 --- a/README.Android +++ b/README.Android @@ -1,7 +1,11 @@ -A toolchain file is provided for cross-compiling this library to an armeabi-v7a platform. See cmake/Toolchain-Android-armeabi-v7a.cmake. +A toolchain file is provided for cross-compiling this library to an armeabi-v7a platform. See cmake/Toolchain-Android-armeabi-v7a.cmake. See cmake/Toolchain-Android-arm64-v8a.cmake for ARM 64 bit support. The Android build requires a modified version of libusb available here: https://github.com/libusb/libusb/pull/242 -Build libusb-1.0 with an Android NDK toolchain and place the resulting .so and .h files in a convenient location. See the toolchain file for more detailed instructions. +### Instructions +* Build libusb-1.0 with an Android NDK toolchain and place the resulting .so and .h files in a convenient location. See one of the toolchain files for more detailed instructions. For example, have the lib and include folders in /libusb-android/arm64-v8a/usr/. +* $ rm CMakeFiles CMakeCache.txt (to clean if you need to cmake again) +* $ cmake . -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-Android-arm64-v8a.cmake +* $ make diff --git a/cmake/Toolchain-Android-arm64-v8a.cmake b/cmake/Toolchain-Android-arm64-v8a.cmake new file mode 100644 index 0000000..d84ad13 --- /dev/null +++ b/cmake/Toolchain-Android-arm64-v8a.cmake @@ -0,0 +1,31 @@ +set(CMAKE_SYSTEM_NAME Android) +set(CMAKE_SYSTEM_VERSION 28) +set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) + +# Seems we don't need the following two with arm64-v8a, only armeabi-v7a +#set(CMAKE_ANDROID_ARM_NEON ON) +#set(CMAKE_ANDROID_ARM_MODE ON) + +# Change this path to point to ndk installation location +set(CMAKE_ANDROID_NDK /Users/soliax/Documents/android/android-ndk) +set(CMAKE_ANDROID_STL_TYPE c++_static) + +# Change this path to point to armeabi-v7a libusb-1.0.so location +# We also expect to find libusb.h here. +# armeabi-v7a +# usr +# include +# libusb-1.0 +# libusb.h +# lib +# libusb-1.0.so +# NOTE: This is a special flavor of libusb. See README for details +SET(CMAKE_FIND_ROOT_PATH /Users/soliax/MMI/codeiMac/libftdi/libusb-android/arm64-v8a) + +# Running cmake then make yielding this effort: +# android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: liblog.so, needed by /libftdi/libusb-android/arm64-v8a/usr/lib/libusb-1.0.so, not found (try using -rpath or -rpath-link) +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") + +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) From 8bd1756d6786f2ca9d19e8820233a0b7bf695e3b Mon Sep 17 00:00:00 2001 From: Simon Nishi McCorkindale Date: Fri, 28 May 2021 19:13:49 +0800 Subject: [PATCH 2/2] Update libusb_wrap_fd function call to libusb_wrap_sys_device libusb_wrap_sys_device was the requested name in the pull request to the libusb project for Android support: https://github.com/libusb/libusb/pull/242 --- src/ftdi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 9a25600..486f0b0 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -701,7 +701,7 @@ int ftdi_usb_open2(struct ftdi_context *ftdi, const char *dev_node, int fd) if (ftdi == NULL) ftdi_error_return(-8, "ftdi context invalid"); libusb_device_handle *handle; - int wrap_error = libusb_wrap_fd(ftdi->usb_ctx, fd, &handle); + int wrap_error = libusb_wrap_sys_device(ftdi->usb_ctx, fd, &handle); if (wrap_error == LIBUSB_ERROR_NO_MEM) { ftdi_error_return(LIBUSB_ERROR_NO_MEM, "LIBUSB_ERROR_NO_MEM"); } else if (wrap_error == LIBUSB_ERROR_ACCESS) { @@ -709,7 +709,7 @@ int ftdi_usb_open2(struct ftdi_context *ftdi, const char *dev_node, int fd) } else if (wrap_error == LIBUSB_ERROR_NOT_SUPPORTED) { ftdi_error_return(LIBUSB_ERROR_NOT_SUPPORTED, "LIBUSB_ERROR_NOT_SUPPORTED"); } else if (wrap_error) { - ftdi_error_return(-1, "unknown libusb_wrap_fd error"); + ftdi_error_return(-1, "unknown libusb_wrap_sys_device error"); } ftdi_set_usbdev(ftdi, handle); libusb_device *dev = libusb_get_device(handle);