From 20431a14dbfdc333624db5b0f67e3deb1f4fb965 Mon Sep 17 00:00:00 2001 From: Rick Mark Date: Tue, 21 Apr 2026 21:42:30 -0700 Subject: [PATCH] Android support --- fx3_firmware/CMakeLists.txt | 3 ++ host/CMakeLists.txt | 21 +++++++++-- host/common/include/host_config.h.in | 36 +++++++++++++++++-- host/libraries/CMakeLists.txt | 4 +++ host/libraries/libbladeRF/CMakeLists.txt | 5 +-- .../libbladeRF/src/device_calibration.c | 4 +++ host/libraries/libbladeRF/src/helpers/file.c | 4 +-- 7 files changed, 69 insertions(+), 8 deletions(-) diff --git a/fx3_firmware/CMakeLists.txt b/fx3_firmware/CMakeLists.txt index 278592d2f..011d5c4e2 100644 --- a/fx3_firmware/CMakeLists.txt +++ b/fx3_firmware/CMakeLists.txt @@ -58,6 +58,9 @@ option(ENABLE_BLADERF_FIRMWARE "Build firmware for the bladeRF 1.0" ON ) +if(BLADERF_OS_ANDROID) + set(ENABLE_BLADERF_FIRMWARE OFF) +endif() ################################################################################ # Build Configuration diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 69aded1c1..f4e987c64 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -51,6 +51,14 @@ option(BUILD_DOCUMENTATION "Enable build and install of manpages and other documentation." OFF) +option(BUILD_BLADERF_UTILITIES + "Build bladeRF utilities (e.g. bladeRF-cli)." + ON) + +if(BLADERF_OS_ANDROID) + set(BUILD_BLADERF_UTILITIES OFF) +endif() + option(TREAT_WARNINGS_AS_ERRORS "Treat compiler warnings as errors." ON) @@ -86,7 +94,9 @@ option(BUILD_AD936X_DEBUG OFF) # We do this prior to the rest of host/common, as the compile options are # going to be different. -add_subdirectory(common/thirdparty/ad936x) +if(BUILD_AD936X) + add_subdirectory(common/thirdparty/ad936x) +endif(BUILD_AD936X) ################################################################################ # Compiler configuration @@ -161,6 +171,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR CYGWIN) endif() endif(NOT CMAKE_CROSSCOMPILING AND NOT CYGWIN) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") + set(BLADERF_OS_ANDROID 1) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") set(BLADERF_OS_FREEBSD 1) @@ -211,7 +224,11 @@ endif() ################################################################################ add_subdirectory(libraries) add_subdirectory(misc) -add_subdirectory(utilities) + +if(BUILD_BLADERF_UTILITIES) + add_subdirectory(utilities) +endif() + add_subdirectory(common) ################################################################################ diff --git a/host/common/include/host_config.h.in b/host/common/include/host_config.h.in index fc94a777d..553e09853 100644 --- a/host/common/include/host_config.h.in +++ b/host/common/include/host_config.h.in @@ -31,9 +31,11 @@ #cmakedefine01 BLADERF_OS_FREEBSD #cmakedefine01 BLADERF_OS_OSX #cmakedefine01 BLADERF_OS_WINDOWS +#cmakedefine01 BLADERF_OS_ANDROID #cmakedefine01 BLADERF_BIG_ENDIAN -#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD) + +#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD || BLADERF_OS_ANDROID) # error "Build not configured for any supported operating systems" #endif @@ -41,6 +43,32 @@ #error "Build configured for multiple operating systems" #endif +#ifdef BLADERF_OS_ANDROID +#include +#include +#include +#include +#include +#include + +static inline struct passwd *bladerf_android_getpwuid_stub(uid_t uid) +{ + static struct passwd pwd; + static char fallback_dir[] = "/"; + const char *home; + + (void)uid; + + home = getenv("HOME"); + pwd.pw_dir = (char *)(home != NULL ? home : fallback_dir); + + return &pwd; +} + +#define getpwuid(uid) bladerf_android_getpwuid_stub(uid) + +#endif + #cmakedefine01 HAVE_CLOCK_GETTIME /******************************************************************************* @@ -61,7 +89,7 @@ /*----------------------- * Linux *---------------------*/ -#if BLADERF_OS_LINUX +#if BLADERF_OS_LINUX || BLADERF_OS_ANDROID #include #define HOST_TO_LE16(val) htole16(val) @@ -153,6 +181,10 @@ #error "Encountered an OS that we do not have endian wrappers for?" #endif +#if BLADERF_OS_ANDROID +#define pthread_cancel(val) pthread_kill(val, SIGTERM) +#endif + /******************************************************************************* * Endianness conversions for constants * diff --git a/host/libraries/CMakeLists.txt b/host/libraries/CMakeLists.txt index b70d1f44d..afd46b1df 100644 --- a/host/libraries/CMakeLists.txt +++ b/host/libraries/CMakeLists.txt @@ -3,6 +3,10 @@ add_subdirectory(libbladeRF) # Conditionally add the test directory option(TEST_LIBBLADERF "Enables libbladeRF test output" ON) +if(BLADERF_OS_ANDROID) + set(TEST_LIBBLADERF OFF) +endif() + if(TEST_LIBBLADERF) message(STATUS "libbladeRF_test: enabled") add_subdirectory(libbladeRF_test) diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index 009ab65fa..1848039d6 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -265,7 +265,7 @@ if(ENABLE_BACKEND_LIBUSB) else() message(WARNING "Not checking libbladeRF/libusb compatibility because LIBUSB_VERSION is not defined.") endif() - set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${LIBUSB_INCLUDE_DIRS}) + set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${LIBUSB_INCLUDE_DIRS} "${LIBUSB_INCLUDE_DIR}") endif(NOT LIBUSB_FOUND) endif(ENABLE_BACKEND_LIBUSB) @@ -290,7 +290,8 @@ if(BUILD_AD936X) set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ad936x) endif(BUILD_AD936X) -include_directories(${LIBBLADERF_INCLUDES}) +message(STATUS "libbladeRF includes: ${LIBBLADERF_INCLUDES}") +include_directories(${LIBBLADERF_INCLUDES} ) ################################################################################ diff --git a/host/libraries/libbladeRF/src/device_calibration.c b/host/libraries/libbladeRF/src/device_calibration.c index 7e8e81bb2..4a3061bd7 100644 --- a/host/libraries/libbladeRF/src/device_calibration.c +++ b/host/libraries/libbladeRF/src/device_calibration.c @@ -22,7 +22,11 @@ #include #include +#ifndef BLADERF_OS_ANDROID #include "common.h" +#else +#include +#endif #include "libbladeRF.h" #include "board/board.h" #include "helpers/version.h" diff --git a/host/libraries/libbladeRF/src/helpers/file.c b/host/libraries/libbladeRF/src/helpers/file.c index 4a8023d45..1ce05f3b9 100644 --- a/host/libraries/libbladeRF/src/helpers/file.c +++ b/host/libraries/libbladeRF/src/helpers/file.c @@ -178,7 +178,7 @@ static size_t strip_last_path_entry(char *buf, char dir_delim) return len; } -#if BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_FREEBSD +#if BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_FREEBSD || BLADERF_OS_ANDROID #define ACCESS_FILE_EXISTS F_OK #define DIR_DELIMETER '/' @@ -229,7 +229,7 @@ static inline size_t get_install_dir(char *buf, size_t max_len) return 0; } -#if BLADERF_OS_LINUX +#if BLADERF_OS_LINUX || BLADERF_OS_ANDROID static inline size_t get_binary_dir(char *buf, size_t max_len) { ssize_t result = readlink("/proc/self/exe", buf, max_len);