From 90358704de07b8808c8a304132e1b8608a3895b9 Mon Sep 17 00:00:00 2001 From: Thierry Thomas Date: Mon, 4 Nov 2024 22:03:16 +0100 Subject: [PATCH] devel/android-tools: upgrade to 35.0.2 - Fetch tarball from nmeum; - Releases notes at . --- devel/android-tools/Makefile | 24 +- devel/android-tools/distinfo | 6 +- .../files/patch-vendor_CMakeLists.adb.txt | 21 + .../patch-vendor_CMakeLists.fastboot.txt | 29 + .../files/patch-vendor_CMakeLists.mke2fs.txt | 19 + .../files/patch-vendor_CMakeLists.txt | 22 + .../files/patch-vendor_adb_Android.bp | 23 + ...h-vendor_adb_client_file__sync__client.cpp | 6 +- .../patch-vendor_adb_client_usb__freebsd.cpp | 638 ++++++++++++++++++ .../patch-vendor_adb_client_usb__libusb.cpp | 61 ++ ...airing__connection_pairing__connection.cpp | 13 + .../files/patch-vendor_adb_sysdeps.h | 15 + ..._adb_tls_include_adb_tls_tls__connection.h | 6 +- ...tch-vendor_boringssl_crypto_x509_t__x509.c | 45 -- .../patch-vendor_core_fastboot_Android.bp | 13 + .../patch-vendor_core_fastboot_filesystem.cpp | 20 + ...atch-vendor_core_fastboot_usb__freebsd.cpp | 268 ++++++++ ..._private_android__filesystem__capability.h | 122 ++++ ...ore_libcutils_include_private_fs__config.h | 14 + ...atch-vendor_core_libsparse_append2simg.cpp | 14 + .../patch-vendor_core_libsparse_img2simg.cpp | 11 + ...tch-vendor_core_libsparse_output__file.cpp | 11 + ...tch-vendor_core_libsparse_sparse__read.cpp | 11 + .../patch-vendor_core_libutils_FileMap.cpp | 13 + ...patch-vendor_e2fsprogs_lib_blkid_devname.c | 11 + .../patch-vendor_e2fsprogs_lib_blkid_devno.c | 11 + ...ch-vendor_e2fsprogs_lib_ext2fs_ismounted.c | 11 + ...atch-vendor_e2fsprogs_misc_create__inode.c | 11 + ...atch-vendor_e2fsprogs_misc_mk__hugefiles.c | 11 + ...-vendor_extras_libjsonpb_parse_jsonpb.cpp} | 16 +- .../patch-vendor_f2fs-tools_fsck_xattr.c | 13 + .../patch-vendor_f2fs-tools_lib_libf2fs.c | 63 ++ .../files/patch-vendor_libbase_file.cpp | 30 + ...ndor_libbase_include_android-base_endian.h | 11 + .../files/patch-vendor_libbase_logging.cpp | 20 + ...patch-vendor_libziparchive_zip__archive.cc | 11 + ...ch-vendor_logging_liblog_logger__write.cpp | 29 + ...endor_selinux_libselinux_src_label__file.h | 15 + devel/android-tools/pkg-plist | 8 + 39 files changed, 1623 insertions(+), 73 deletions(-) create mode 100644 devel/android-tools/files/patch-vendor_CMakeLists.adb.txt create mode 100644 devel/android-tools/files/patch-vendor_CMakeLists.fastboot.txt create mode 100644 devel/android-tools/files/patch-vendor_CMakeLists.mke2fs.txt create mode 100644 devel/android-tools/files/patch-vendor_CMakeLists.txt create mode 100644 devel/android-tools/files/patch-vendor_adb_Android.bp create mode 100644 devel/android-tools/files/patch-vendor_adb_client_usb__freebsd.cpp create mode 100644 devel/android-tools/files/patch-vendor_adb_client_usb__libusb.cpp create mode 100644 devel/android-tools/files/patch-vendor_adb_pairing__connection_pairing__connection.cpp create mode 100644 devel/android-tools/files/patch-vendor_adb_sysdeps.h delete mode 100644 devel/android-tools/files/patch-vendor_boringssl_crypto_x509_t__x509.c create mode 100644 devel/android-tools/files/patch-vendor_core_fastboot_Android.bp create mode 100644 devel/android-tools/files/patch-vendor_core_fastboot_filesystem.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_fastboot_usb__freebsd.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_libcutils_include_private_android__filesystem__capability.h create mode 100644 devel/android-tools/files/patch-vendor_core_libcutils_include_private_fs__config.h create mode 100644 devel/android-tools/files/patch-vendor_core_libsparse_append2simg.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_libsparse_img2simg.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_libsparse_output__file.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_libsparse_sparse__read.cpp create mode 100644 devel/android-tools/files/patch-vendor_core_libutils_FileMap.cpp create mode 100644 devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devname.c create mode 100644 devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devno.c create mode 100644 devel/android-tools/files/patch-vendor_e2fsprogs_lib_ext2fs_ismounted.c create mode 100644 devel/android-tools/files/patch-vendor_e2fsprogs_misc_create__inode.c create mode 100644 devel/android-tools/files/patch-vendor_e2fsprogs_misc_mk__hugefiles.c rename devel/android-tools/files/{patch-abseil => patch-vendor_extras_libjsonpb_parse_jsonpb.cpp} (72%) create mode 100644 devel/android-tools/files/patch-vendor_f2fs-tools_fsck_xattr.c create mode 100644 devel/android-tools/files/patch-vendor_f2fs-tools_lib_libf2fs.c create mode 100644 devel/android-tools/files/patch-vendor_libbase_file.cpp create mode 100644 devel/android-tools/files/patch-vendor_libbase_include_android-base_endian.h create mode 100644 devel/android-tools/files/patch-vendor_libbase_logging.cpp create mode 100644 devel/android-tools/files/patch-vendor_libziparchive_zip__archive.cc create mode 100644 devel/android-tools/files/patch-vendor_logging_liblog_logger__write.cpp create mode 100644 devel/android-tools/files/patch-vendor_selinux_libselinux_src_label__file.h diff --git a/devel/android-tools/Makefile b/devel/android-tools/Makefile index c74937c6acc5..ddc71ea8a564 100644 --- a/devel/android-tools/Makefile +++ b/devel/android-tools/Makefile @@ -1,35 +1,37 @@ PORTNAME= android-tools -PORTVERSION= 31.0.3p2.0 -PORTREVISION= 28 +PORTVERSION= 35.0.2 CATEGORIES= devel -MASTER_SITES= GH +MASTER_SITES= https://github.com/nmeum/android-tools/releases/download/${PORTVERSION}/ MAINTAINER= nc@FreeBSD.org COMMENT= Android debugging tools -WWW= https://github.com/neelchauhan/freebsd-android-tools +WWW= https://github.com/nmeum/android-tools LICENSE= APACHE20 LICENSE_FILE= ${WRKSRC}/LICENSE BROKEN_aarch64= ld: error: undefined symbol: OPENSSL_cpuid_setup -LIB_DEPENDS= libbrotlicommon.so:archivers/brotli \ +LIB_DEPENDS= libabsl_status.so:devel/abseil \ + libbrotlicommon.so:archivers/brotli \ libgmock.so:devel/googletest \ + libfmt.so:devel/libfmt \ liblz4.so:archivers/liblz4 \ libpcre2-8.so:devel/pcre2 \ libprotobuf.so:devel/protobuf \ libzstd.so:archivers/zstd -USES= cmake compiler:c++17-lang go:no_targets localbase:ldflags perl5 python shebangfix +USES= cmake compiler:c++17-lang go:no_targets localbase:ldflags \ + perl5 pkgconfig python shebangfix tar:xz -USE_GITHUB= yes -GH_ACCOUNT= neelchauhan -GH_PROJECT= freebsd-${PORTNAME} -GH_TAGNAME= 271d7a26c8daf4b9fe412d360a2edfaca327efdd +#USE_GITHUB= yes +#GH_ACCOUNT= nmeum SHEBANG_FILES= vendor/mkbootimg/repack_bootimg.py \ vendor/mkbootimg/mkbootimg.py \ - vendor/mkbootimg/unpack_bootimg.py + vendor/mkbootimg/unpack_bootimg.py \ + vendor/libufdt/utils/src/mkdtboimg.py \ + vendor/avb/avbtool.py MAKE_ENV+= GOFLAGS=-mod=vendor \ GOPATH=${WRKSRC}/vendor/boringssl/vendor \ diff --git a/devel/android-tools/distinfo b/devel/android-tools/distinfo index b7d1ef2c124f..ef81e9d5de14 100644 --- a/devel/android-tools/distinfo +++ b/devel/android-tools/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1659823195 -SHA256 (neelchauhan-freebsd-android-tools-31.0.3p2.0-271d7a26c8daf4b9fe412d360a2edfaca327efdd_GH0.tar.gz) = 12003a3d9b1d476994a8484c489cfb227b2a34391c856389af50249b96618ec8 -SIZE (neelchauhan-freebsd-android-tools-31.0.3p2.0-271d7a26c8daf4b9fe412d360a2edfaca327efdd_GH0.tar.gz) = 40959086 +TIMESTAMP = 1730747839 +SHA256 (android-tools-35.0.2.tar.xz) = d2c3222280315f36d8bfa5c02d7632b47e365bfe2e77e99a3564fb6576f04097 +SIZE (android-tools-35.0.2.tar.xz) = 18847376 diff --git a/devel/android-tools/files/patch-vendor_CMakeLists.adb.txt b/devel/android-tools/files/patch-vendor_CMakeLists.adb.txt new file mode 100644 index 000000000000..417e236d57f5 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_CMakeLists.adb.txt @@ -0,0 +1,21 @@ +--- vendor/CMakeLists.adb.txt.orig 2024-08-29 17:46:57 UTC ++++ vendor/CMakeLists.adb.txt +@@ -43,6 +43,9 @@ if(APPLE) + if(APPLE) + list(APPEND libadb_SOURCES + adb/client/usb_osx.cpp) ++elseif(FREEBSD) ++ list(APPEND libadb_SOURCES ++ adb/client/usb_freebsd.cpp) + else() + list(APPEND libadb_SOURCES + adb/client/usb_linux.cpp) +@@ -103,7 +106,7 @@ target_compile_definitions(liblog PRIVATE + logging/liblog/logprint.cpp) + + target_compile_definitions(liblog PRIVATE +- -DLIBLOG_LOG_TAG=1006 -D_XOPEN_SOURCE=700 -DFAKE_LOG_DEVICE=1) ++ -DLIBLOG_LOG_TAG=1006 -D_XOPEN_SOURCE -DFAKE_LOG_DEVICE=1) + target_include_directories(liblog PUBLIC + core/include + logging/liblog/include diff --git a/devel/android-tools/files/patch-vendor_CMakeLists.fastboot.txt b/devel/android-tools/files/patch-vendor_CMakeLists.fastboot.txt new file mode 100644 index 000000000000..1913446c3f15 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_CMakeLists.fastboot.txt @@ -0,0 +1,29 @@ +--- vendor/CMakeLists.fastboot.txt.orig 2024-08-29 17:46:57 UTC ++++ vendor/CMakeLists.fastboot.txt +@@ -119,6 +119,9 @@ if(APPLE) + if(APPLE) + list(APPEND fastboot_SOURCES + core/fastboot/usb_osx.cpp) ++elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ++ list(APPEND fastboot_SOURCES ++ core/fastboot/usb_freebsd.cpp) + else() + list(APPEND fastboot_SOURCES + core/fastboot/usb_linux.cpp) +@@ -131,7 +134,7 @@ target_compile_definitions(fastboot PRIVATE + core/libziparchive/include mkbootimg/include/bootimg + core/fs_mgr/liblp/include core/fs_mgr/libstorage_literals avb) + target_compile_definitions(fastboot PRIVATE +- -D_GNU_SOURCE -D_XOPEN_SOURCE=700 -DUSE_F2FS ++ -D_GNU_SOURCE -D_XOPEN_SOURCE -DUSE_F2FS + -DANDROID_MKE2FS_NAME="${ANDROID_MKE2FS_NAME}") + target_link_libraries(fastboot + libsparse libzip libcutils liblog liblp libutil +@@ -142,4 +145,7 @@ if(APPLE) + target_link_libraries(fastboot + "-framework CoreFoundation" + "-framework IOKit") ++elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ++ target_link_libraries(fastboot ++ usb) + endif() diff --git a/devel/android-tools/files/patch-vendor_CMakeLists.mke2fs.txt b/devel/android-tools/files/patch-vendor_CMakeLists.mke2fs.txt new file mode 100644 index 000000000000..32bc701480b8 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_CMakeLists.mke2fs.txt @@ -0,0 +1,19 @@ +--- vendor/CMakeLists.mke2fs.txt.orig 2024-08-29 17:46:57 UTC ++++ vendor/CMakeLists.mke2fs.txt +@@ -1,3 +1,7 @@ ++if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") ++ set(FREEBSD TRUE) ++endif() ++ + add_library(libext2_uuid STATIC + e2fsprogs/lib/uuid/clear.c + e2fsprogs/lib/uuid/compare.c +@@ -130,7 +134,7 @@ target_include_directories("${ANDROID_MKE2FS_NAME}" PR + e2fsprogs/lib) + + # fails to build due to https://android-review.googlesource.com/c/platform/system/core/+/2760169 +-if(NOT APPLE) ++if(NOT APPLE AND NOT FREEBSD) + add_executable(e2fsdroid + e2fsprogs/contrib/android/e2fsdroid.c + e2fsprogs/contrib/android/basefs_allocator.c diff --git a/devel/android-tools/files/patch-vendor_CMakeLists.txt b/devel/android-tools/files/patch-vendor_CMakeLists.txt new file mode 100644 index 000000000000..83106d407434 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_CMakeLists.txt @@ -0,0 +1,22 @@ +--- vendor/CMakeLists.txt.orig 2024-08-29 17:46:57 UTC ++++ vendor/CMakeLists.txt +@@ -11,6 +11,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS ON) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + ++if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") ++ set(FREEBSD TRUE) ++endif() ++ + if(APPLE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL") +@@ -139,7 +143,7 @@ install(TARGETS + ext2simg + DESTINATION bin) + +-if(NOT APPLE) ++if(NOT APPLE AND NOT FREEBSD) + install(TARGETS + e2fsdroid + DESTINATION bin) diff --git a/devel/android-tools/files/patch-vendor_adb_Android.bp b/devel/android-tools/files/patch-vendor_adb_Android.bp new file mode 100644 index 000000000000..4a7e9f632f3b --- /dev/null +++ b/devel/android-tools/files/patch-vendor_adb_Android.bp @@ -0,0 +1,23 @@ +--- vendor/adb/Android.bp.orig 2024-08-29 17:46:57 UTC ++++ vendor/adb/Android.bp +@@ -248,6 +248,10 @@ libadb_linux_srcs = [ + "fdevent/fdevent_epoll.cpp", + ] + ++libadb_freebsd_srcs = [ ++ "fdevent/fdevent_epoll.cpp", ++] ++ + libadb_test_srcs = [ + "adb_io_test.cpp", + "adb_listeners_test.cpp", +@@ -288,6 +292,9 @@ cc_library_host_static { + target: { + linux: { + srcs: ["client/usb_linux.cpp"] + libadb_linux_srcs, ++ }, ++ freebsd: { ++ srcs: ["client/usb_freebsd.cpp"] + libadb_freebsd_srcs, + }, + darwin: { + srcs: ["client/usb_osx.cpp"] + libadb_darwin_srcs, diff --git a/devel/android-tools/files/patch-vendor_adb_client_file__sync__client.cpp b/devel/android-tools/files/patch-vendor_adb_client_file__sync__client.cpp index 4883dd619897..dc8480f4fb33 100644 --- a/devel/android-tools/files/patch-vendor_adb_client_file__sync__client.cpp +++ b/devel/android-tools/files/patch-vendor_adb_client_file__sync__client.cpp @@ -1,6 +1,6 @@ ---- vendor/adb/client/file_sync_client.cpp.orig 2022-06-09 20:52:06 UTC +--- vendor/adb/client/file_sync_client.cpp.orig 2024-08-29 17:46:57 UTC +++ vendor/adb/client/file_sync_client.cpp -@@ -394,9 +394,16 @@ class SyncConnection { +@@ -398,9 +398,16 @@ class SyncConnection { void* p = buf.data(); @@ -17,7 +17,7 @@ return WriteFdExactly(fd, buf.data(), buf.size()); } -@@ -441,9 +448,16 @@ class SyncConnection { +@@ -445,9 +452,16 @@ class SyncConnection { void* p = buf.data(); diff --git a/devel/android-tools/files/patch-vendor_adb_client_usb__freebsd.cpp b/devel/android-tools/files/patch-vendor_adb_client_usb__freebsd.cpp new file mode 100644 index 000000000000..ef0be40c9336 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_adb_client_usb__freebsd.cpp @@ -0,0 +1,638 @@ +--- vendor/adb/client/usb_freebsd.cpp.orig 1970-01-01 01:00:00 UTC ++++ vendor/adb/client/usb_freebsd.cpp +@@ -0,0 +1,635 @@ ++/* ++ * Copyright (C) 2016 The Android Open Source Project ++ * ++ * Licensed under the Apache License, Version 2.0 (the "License"); ++ * you may not use this file except in compliance with the License. ++ * You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++#include "sysdeps.h" ++ ++#include "client/usb.h" ++ ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++ ++#include ++#include ++#include ++#include ++ ++#include "adb.h" ++#include "adb_utils.h" ++#include "transport.h" ++ ++using android::base::StringPrintf; ++ ++// RAII wrappers for libusb. ++struct ConfigDescriptorDeleter { ++ void operator()(libusb_config_descriptor* desc) { ++ libusb_free_config_descriptor(desc); ++ } ++}; ++ ++using unique_config_descriptor = std::unique_ptr; ++ ++struct DeviceHandleDeleter { ++ void operator()(libusb_device_handle* h) { ++ libusb_close(h); ++ } ++}; ++ ++using unique_device_handle = std::unique_ptr; ++ ++struct transfer_info { ++ transfer_info(const char* name, uint16_t zero_mask, bool is_bulk_out) ++ : name(name), ++ transfer(libusb_alloc_transfer(0)), ++ is_bulk_out(is_bulk_out), ++ zero_mask(zero_mask) {} ++ ++ ~transfer_info() { ++ libusb_free_transfer(transfer); ++ } ++ ++ const char* name; ++ libusb_transfer* transfer; ++ bool is_bulk_out; ++ bool transfer_complete; ++ std::condition_variable cv; ++ std::mutex mutex; ++ uint16_t zero_mask; ++ ++ void Notify() { ++ LOG(DEBUG) << "notifying " << name << " transfer complete"; ++ transfer_complete = true; ++ cv.notify_one(); ++ } ++}; ++ ++struct usb_handle { ++ usb_handle(const std::string& device_address, const std::string& serial, ++ unique_device_handle&& device_handle, uint8_t interface, uint8_t bulk_in, ++ uint8_t bulk_out, size_t zero_mask, size_t max_packet_size) ++ : device_address(device_address), ++ serial(serial), ++ closing(false), ++ device_handle(device_handle.release()), ++ read("read", zero_mask, false), ++ write("write", zero_mask, true), ++ interface(interface), ++ bulk_in(bulk_in), ++ bulk_out(bulk_out), ++ max_packet_size(max_packet_size) {} ++ ++ ~usb_handle() { ++ Close(); ++ } ++ ++ void Close() { ++ std::unique_lock lock(device_handle_mutex); ++ // Cancelling transfers will trigger more Closes, so make sure this only happens once. ++ if (closing) { ++ return; ++ } ++ closing = true; ++ ++ // Make sure that no new transfers come in. ++ libusb_device_handle* handle = device_handle; ++ if (!handle) { ++ return; ++ } ++ ++ device_handle = nullptr; ++ ++ // Cancel already dispatched transfers. ++ libusb_cancel_transfer(read.transfer); ++ libusb_cancel_transfer(write.transfer); ++ ++ libusb_release_interface(handle, interface); ++ libusb_close(handle); ++ } ++ ++ std::string device_address; ++ std::string serial; ++ ++ std::atomic closing; ++ std::mutex device_handle_mutex; ++ libusb_device_handle* device_handle; ++ ++ transfer_info read; ++ transfer_info write; ++ ++ uint8_t interface; ++ uint8_t bulk_in; ++ uint8_t bulk_out; ++ ++ size_t max_packet_size; ++}; ++ ++static auto& usb_handles = *new std::unordered_map>(); ++static auto& usb_handles_mutex = *new std::mutex(); ++ ++static libusb_hotplug_callback_handle hotplug_handle; ++ ++static std::string get_device_address(libusb_device* device) { ++ return StringPrintf("usb:%d:%d", libusb_get_bus_number(device), ++ libusb_get_device_address(device)); ++} ++ ++#if defined(__linux__) ++static std::string get_device_serial_path(libusb_device* device) { ++ uint8_t ports[7]; ++ int port_count = libusb_get_port_numbers(device, ports, 7); ++ if (port_count < 0) return ""; ++ ++ std::string path = ++ StringPrintf("/sys/bus/usb/devices/%d-%d", libusb_get_bus_number(device), ports[0]); ++ for (int port = 1; port < port_count; ++port) { ++ path += StringPrintf(".%d", ports[port]); ++ } ++ path += "/serial"; ++ return path; ++} ++ ++static std::string get_device_dev_path(libusb_device* device) { ++ uint8_t ports[7]; ++ int port_count = libusb_get_port_numbers(device, ports, 7); ++ if (port_count < 0) return ""; ++ return StringPrintf("/dev/bus/usb/%03u/%03u", libusb_get_bus_number(device), ports[0]); ++} ++#endif ++ ++static bool endpoint_is_output(uint8_t endpoint) { ++ return (endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT; ++} ++ ++static bool should_perform_zero_transfer(uint8_t endpoint, size_t write_length, uint16_t zero_mask) { ++ return endpoint_is_output(endpoint) && write_length != 0 && zero_mask != 0 && ++ (write_length & zero_mask) == 0; ++} ++ ++static void process_device(libusb_device* device) { ++ std::string device_address = get_device_address(device); ++ std::string device_serial; ++ ++ // Figure out if we want to open the device. ++ libusb_device_descriptor device_desc; ++ int rc = libusb_get_device_descriptor(device, &device_desc); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to get device descriptor for device at " << device_address << ": " ++ << libusb_error_name(rc); ++ return; ++ } ++ ++ if (device_desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE) { ++ // Assume that all Android devices have the device class set to per interface. ++ // TODO: Is this assumption valid? ++ LOG(VERBOSE) << "skipping device with incorrect class at " << device_address; ++ return; ++ } ++ ++ libusb_config_descriptor* config_raw; ++ rc = libusb_get_active_config_descriptor(device, &config_raw); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to get active config descriptor for device at " << device_address ++ << ": " << libusb_error_name(rc); ++ return; ++ } ++ const unique_config_descriptor config(config_raw); ++ ++ // Use size_t for interface_num so s don't mangle it. ++ size_t interface_num; ++ uint16_t zero_mask = 0; ++ uint8_t bulk_in = 0, bulk_out = 0; ++ size_t packet_size = 0; ++ bool found_adb = false; ++ ++ for (interface_num = 0; interface_num < config->bNumInterfaces; ++interface_num) { ++ const libusb_interface& interface = config->interface[interface_num]; ++ if (interface.num_altsetting != 1) { ++ // Assume that interfaces with alternate settings aren't adb interfaces. ++ // TODO: Is this assumption valid? ++ LOG(VERBOSE) << "skipping interface with incorrect num_altsetting at " << device_address ++ << " (interface " << interface_num << ")"; ++ continue; ++ } ++ ++ const libusb_interface_descriptor& interface_desc = interface.altsetting[0]; ++ if (!is_adb_interface(interface_desc.bInterfaceClass, interface_desc.bInterfaceSubClass, ++ interface_desc.bInterfaceProtocol)) { ++ LOG(VERBOSE) << "skipping non-adb interface at " << device_address << " (interface " ++ << interface_num << ")"; ++ continue; ++ } ++ ++ LOG(VERBOSE) << "found potential adb interface at " << device_address << " (interface " ++ << interface_num << ")"; ++ ++ bool found_in = false; ++ bool found_out = false; ++ for (size_t endpoint_num = 0; endpoint_num < interface_desc.bNumEndpoints; ++endpoint_num) { ++ const auto& endpoint_desc = interface_desc.endpoint[endpoint_num]; ++ const uint8_t endpoint_addr = endpoint_desc.bEndpointAddress; ++ const uint8_t endpoint_attr = endpoint_desc.bmAttributes; ++ ++ const uint8_t transfer_type = endpoint_attr & LIBUSB_TRANSFER_TYPE_MASK; ++ ++ if (transfer_type != LIBUSB_TRANSFER_TYPE_BULK) { ++ continue; ++ } ++ ++ if (endpoint_is_output(endpoint_addr) && !found_out) { ++ found_out = true; ++ bulk_out = endpoint_addr; ++ zero_mask = endpoint_desc.wMaxPacketSize - 1; ++ } else if (!endpoint_is_output(endpoint_addr) && !found_in) { ++ found_in = true; ++ bulk_in = endpoint_addr; ++ } ++ ++ size_t endpoint_packet_size = endpoint_desc.wMaxPacketSize; ++ CHECK(endpoint_packet_size != 0); ++ if (packet_size == 0) { ++ packet_size = endpoint_packet_size; ++ } else { ++ CHECK(packet_size == endpoint_packet_size); ++ } ++ } ++ ++ if (found_in && found_out) { ++ found_adb = true; ++ break; ++ } else { ++ LOG(VERBOSE) << "rejecting potential adb interface at " << device_address ++ << "(interface " << interface_num << "): missing bulk endpoints " ++ << "(found_in = " << found_in << ", found_out = " << found_out << ")"; ++ } ++ } ++ ++ if (!found_adb) { ++ LOG(VERBOSE) << "skipping device with no adb interfaces at " << device_address; ++ return; ++ } ++ ++ { ++ std::unique_lock lock(usb_handles_mutex); ++ if (usb_handles.find(device_address) != usb_handles.end()) { ++ LOG(VERBOSE) << "device at " << device_address ++ << " has already been registered, skipping"; ++ return; ++ } ++ } ++ ++ bool writable = true; ++ libusb_device_handle* handle_raw = nullptr; ++ rc = libusb_open(device, &handle_raw); ++ unique_device_handle handle(handle_raw); ++ if (rc == 0) { ++ LOG(DEBUG) << "successfully opened adb device at " << device_address << ", " ++ << StringPrintf("bulk_in = %#x, bulk_out = %#x", bulk_in, bulk_out); ++ ++ device_serial.resize(255); ++ rc = libusb_get_string_descriptor_ascii(handle_raw, device_desc.iSerialNumber, ++ reinterpret_cast(&device_serial[0]), ++ device_serial.length()); ++ if (rc == 0) { ++ LOG(WARNING) << "received empty serial from device at " << device_address; ++ return; ++ } else if (rc < 0) { ++ LOG(WARNING) << "failed to get serial from device at " << device_address ++ << libusb_error_name(rc); ++ return; ++ } ++ device_serial.resize(rc); ++ ++ // WARNING: this isn't released via RAII. ++ rc = libusb_claim_interface(handle.get(), interface_num); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to claim adb interface for device '" << device_serial << "'" ++ << libusb_error_name(rc); ++ return; ++ } ++ ++ for (uint8_t endpoint : {bulk_in, bulk_out}) { ++ rc = libusb_clear_halt(handle.get(), endpoint); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to clear halt on device '" << device_serial ++ << "' endpoint 0x" << std::hex << endpoint << ": " ++ << libusb_error_name(rc); ++ libusb_release_interface(handle.get(), interface_num); ++ return; ++ } ++ } ++ } else { ++ LOG(WARNING) << "failed to open usb device at " << device_address << ": " ++ << libusb_error_name(rc); ++ writable = false; ++ ++#if defined(__linux__) ++ // libusb doesn't think we should be messing around with devices we don't have ++ // write access to, but Linux at least lets us get the serial number anyway. ++ if (!android::base::ReadFileToString(get_device_serial_path(device), &device_serial)) { ++ // We don't actually want to treat an unknown serial as an error because ++ // devices aren't able to communicate a serial number in early bringup. ++ // http://b/20883914 ++ device_serial = "unknown"; ++ } ++ device_serial = android::base::Trim(device_serial); ++#else ++ // On Mac OS and Windows, we're screwed. But I don't think this situation actually ++ // happens on those OSes. ++ return; ++#endif ++ } ++ ++ std::unique_ptr result(new usb_handle(device_address, device_serial, ++ std::move(handle), interface_num, bulk_in, ++ bulk_out, zero_mask, packet_size)); ++ usb_handle* usb_handle_raw = result.get(); ++ ++ { ++ std::unique_lock lock(usb_handles_mutex); ++ usb_handles[device_address] = std::move(result); ++ ++ register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), ++ writable); ++ } ++ LOG(INFO) << "registered new usb device '" << device_serial << "'"; ++} ++ ++static std::atomic connecting_devices(0); ++ ++static void device_connected(libusb_device* device) { ++#if defined(__linux__) ++ // Android's host linux libusb uses netlink instead of udev for device hotplug notification, ++ // which means we can get hotplug notifications before udev has updated ownership/perms on the ++ // device. Since we're not going to be able to link against the system's libudev any time soon, ++ // hack around this by inserting a sleep. ++ auto thread = std::thread([device]() { ++ std::string device_path = get_device_dev_path(device); ++ std::this_thread::sleep_for(std::chrono::seconds(1)); ++ ++ process_device(device); ++ if (--connecting_devices == 0) { ++ adb_notify_device_scan_complete(); ++ } ++ }); ++ thread.detach(); ++#else ++ process_device(device); ++#endif ++} ++ ++static void device_disconnected(libusb_device* device) { ++ std::string device_address = get_device_address(device); ++ ++ LOG(INFO) << "device disconnected: " << device_address; ++ std::unique_lock lock(usb_handles_mutex); ++ auto it = usb_handles.find(device_address); ++ if (it != usb_handles.end()) { ++ if (!it->second->device_handle) { ++ // If the handle is null, we were never able to open the device. ++ ++ // Temporarily release the usb handles mutex to avoid deadlock. ++ std::unique_ptr handle = std::move(it->second); ++ usb_handles.erase(it); ++ lock.unlock(); ++ unregister_usb_transport(handle.get()); ++ lock.lock(); ++ } else { ++ // Closure of the transport will erase the usb_handle. ++ } ++ } ++} ++ ++static auto& hotplug_queue = *new BlockingQueue>(); ++static void hotplug_thread() { ++ adb_thread_setname("libusb hotplug"); ++ while (true) { ++ hotplug_queue.PopAll([](std::pair pair) { ++ libusb_hotplug_event event = pair.first; ++ libusb_device* device = pair.second; ++ if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) { ++ device_connected(device); ++ } else if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT) { ++ device_disconnected(device); ++ } ++ }); ++ } ++} ++ ++static LIBUSB_CALL int hotplug_callback(libusb_context*, libusb_device* device, ++ libusb_hotplug_event event, void*) { ++ // We're called with the libusb lock taken. Call these on a separate thread outside of this ++ // function so that the usb_handle mutex is always taken before the libusb mutex. ++ static std::once_flag once; ++ std::call_once(once, []() { std::thread(hotplug_thread).detach(); }); ++ ++ if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) { ++ ++connecting_devices; ++ } ++ hotplug_queue.Push({event, device}); ++ return 0; ++} ++ ++void usb_init() { ++ LOG(DEBUG) << "initializing libusb..."; ++ int rc = libusb_init(nullptr); ++ if (rc != 0) { ++ LOG(FATAL) << "failed to initialize libusb: " << libusb_error_name(rc); ++ } ++ ++ // Register the hotplug callback. ++ rc = libusb_hotplug_register_callback( ++ nullptr, static_cast(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | ++ LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), ++ LIBUSB_HOTPLUG_ENUMERATE, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, ++ LIBUSB_CLASS_PER_INTERFACE, hotplug_callback, nullptr, &hotplug_handle); ++ ++ if (rc != LIBUSB_SUCCESS) { ++ LOG(FATAL) << "failed to register libusb hotplug callback"; ++ } ++ ++ // Spawn a thread for libusb_handle_events. ++ std::thread([]() { ++ adb_thread_setname("libusb"); ++ while (true) { ++ libusb_handle_events(nullptr); ++ } ++ }).detach(); ++} ++ ++void usb_cleanup() { ++ libusb_hotplug_deregister_callback(nullptr, hotplug_handle); ++} ++ ++static LIBUSB_CALL void transfer_callback(libusb_transfer* transfer) { ++ transfer_info* info = static_cast(transfer->user_data); ++ ++ LOG(DEBUG) << info->name << " transfer callback entered"; ++ ++ // Make sure that the original submitter has made it to the condition_variable wait. ++ std::unique_lock lock(info->mutex); ++ ++ LOG(DEBUG) << info->name << " callback successfully acquired lock"; ++ ++ if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { ++ LOG(WARNING) << info->name << " transfer failed: " << libusb_error_name(transfer->status); ++ info->Notify(); ++ return; ++ } ++ ++ // usb_read() can return when receiving some data. ++ if (info->is_bulk_out && transfer->actual_length != transfer->length) { ++ LOG(DEBUG) << info->name << " transfer incomplete, resubmitting"; ++ transfer->length -= transfer->actual_length; ++ transfer->buffer += transfer->actual_length; ++ int rc = libusb_submit_transfer(transfer); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to submit " << info->name ++ << " transfer: " << libusb_error_name(rc); ++ transfer->status = LIBUSB_TRANSFER_ERROR; ++ info->Notify(); ++ } ++ return; ++ } ++ ++ if (should_perform_zero_transfer(transfer->endpoint, transfer->length, info->zero_mask)) { ++ LOG(DEBUG) << "submitting zero-length write"; ++ transfer->length = 0; ++ int rc = libusb_submit_transfer(transfer); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to submit zero-length write: " << libusb_error_name(rc); ++ transfer->status = LIBUSB_TRANSFER_ERROR; ++ info->Notify(); ++ } ++ return; ++ } ++ ++ LOG(VERBOSE) << info->name << "transfer fully complete"; ++ info->Notify(); ++} ++ ++// Dispatch a libusb transfer, unlock |device_lock|, and then wait for the result. ++static int perform_usb_transfer(usb_handle* h, transfer_info* info, ++ std::unique_lock device_lock) { ++ libusb_transfer* transfer = info->transfer; ++ ++ transfer->user_data = info; ++ transfer->callback = transfer_callback; ++ ++ LOG(DEBUG) << "locking " << info->name << " transfer_info mutex"; ++ std::unique_lock lock(info->mutex); ++ info->transfer_complete = false; ++ LOG(DEBUG) << "submitting " << info->name << " transfer"; ++ int rc = libusb_submit_transfer(transfer); ++ if (rc != 0) { ++ LOG(WARNING) << "failed to submit " << info->name << " transfer: " << libusb_error_name(rc); ++ errno = EIO; ++ return -1; ++ } ++ ++ LOG(DEBUG) << info->name << " transfer successfully submitted"; ++ device_lock.unlock(); ++ info->cv.wait(lock, [info]() { return info->transfer_complete; }); ++ if (transfer->status != 0) { ++ errno = EIO; ++ return -1; ++ } ++ ++ return 0; ++} ++ ++int usb_write(usb_handle* h, const void* d, int len) { ++ LOG(DEBUG) << "usb_write of length " << len; ++ ++ std::unique_lock lock(h->device_handle_mutex); ++ if (!h->device_handle) { ++ errno = EIO; ++ return -1; ++ } ++ ++ transfer_info* info = &h->write; ++ info->transfer->dev_handle = h->device_handle; ++ info->transfer->flags = 0; ++ info->transfer->endpoint = h->bulk_out; ++ info->transfer->type = LIBUSB_TRANSFER_TYPE_BULK; ++ info->transfer->length = len; ++ info->transfer->buffer = reinterpret_cast(const_cast(d)); ++ info->transfer->num_iso_packets = 0; ++ ++ int rc = perform_usb_transfer(h, info, std::move(lock)); ++ LOG(DEBUG) << "usb_write(" << len << ") = " << rc; ++ return info->transfer->actual_length; ++} ++ ++int usb_read(usb_handle* h, void* d, int len) { ++ LOG(DEBUG) << "usb_read of length " << len; ++ ++ std::unique_lock lock(h->device_handle_mutex); ++ if (!h->device_handle) { ++ errno = EIO; ++ return -1; ++ } ++ ++ transfer_info* info = &h->read; ++ info->transfer->dev_handle = h->device_handle; ++ info->transfer->flags = 0; ++ info->transfer->endpoint = h->bulk_in; ++ info->transfer->type = LIBUSB_TRANSFER_TYPE_BULK; ++ info->transfer->length = len; ++ info->transfer->buffer = reinterpret_cast(d); ++ info->transfer->num_iso_packets = 0; ++ ++ int rc = perform_usb_transfer(h, info, std::move(lock)); ++ LOG(DEBUG) << "usb_read(" << len << ") = " << rc << ", actual_length " ++ << info->transfer->actual_length; ++ if (rc < 0) { ++ return rc; ++ } ++ return info->transfer->actual_length; ++} ++ ++int usb_close(usb_handle* h) { ++ std::unique_lock lock(usb_handles_mutex); ++ auto it = usb_handles.find(h->device_address); ++ if (it == usb_handles.end()) { ++ LOG(FATAL) << "attempted to close unregistered usb_handle for '" << h->serial << "'"; ++ } ++ usb_handles.erase(h->device_address); ++ return 0; ++} ++ ++void usb_reset(usb_handle* h) { ++ libusb_reset_device(h->device_handle); ++ usb_kick(h); ++} ++ ++void usb_kick(usb_handle* h) { ++ h->Close(); ++} ++ ++size_t usb_get_max_packet_size(usb_handle* h) { ++ CHECK(h->max_packet_size != 0); ++ return h->max_packet_size; ++} diff --git a/devel/android-tools/files/patch-vendor_adb_client_usb__libusb.cpp b/devel/android-tools/files/patch-vendor_adb_client_usb__libusb.cpp new file mode 100644 index 000000000000..f541b82de223 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_adb_client_usb__libusb.cpp @@ -0,0 +1,61 @@ +--- vendor/adb/client/usb_libusb.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/adb/client/usb_libusb.cpp +@@ -38,6 +38,13 @@ + + #ifdef ANDROID_TOOLS_USE_BUNDLED_LIBUSB + #include ++#elif defined(__FreeBSD__) ++#include ++#define LIBUSB_LOW_SPEED_OPERATION LIBUSB_SPEED_LOW ++#define LIBUSB_FULL_SPEED_OPERATION LIBUSB_SPEED_FULL ++#define LIBUSB_HIGH_SPEED_OPERATION LIBUSB_SPEED_HIGH ++#define LIBUSB_SUPER_SPEED_OPERATION LIBUSB_SPEED_SUPER ++#define bNumDeviceCaps bNumDeviceCapabilities + #else + #include + #endif +@@ -505,10 +512,12 @@ struct LibusbConnection : public Connection { + return 480; + case LIBUSB_SPEED_SUPER: + return 5000; ++#ifndef __FreeBSD__ + case LIBUSB_SPEED_SUPER_PLUS: + return 10000; + case LIBUSB_SPEED_SUPER_PLUS_X2: + return 20000; ++#endif + case LIBUSB_SPEED_UNKNOWN: + default: + return 0; +@@ -540,6 +549,7 @@ struct LibusbConnection : public Connection { + } + } + ++#ifndef __FreeBSD__ + static uint64_t ExtractMaxSuperSpeedPlus(libusb_ssplus_usb_device_capability_descriptor* cap) { + // The exponents is one of {bytes, kB, MB, or GB}. We express speed in MB so we use a 0 + // multiplier for value which would result in 0MB anyway. +@@ -552,6 +562,7 @@ struct LibusbConnection : public Connection { + } + return max_speed; + } ++#endif + + void RetrieveSpeeds() { + negotiated_speed_ = ToConnectionSpeed(libusb_get_device_speed(device_.get())); +@@ -574,6 +585,7 @@ struct LibusbConnection : public Connection { + libusb_free_ss_usb_device_capability_descriptor(cap); + } + } break; ++#ifndef __FreeBSD__ + case LIBUSB_BT_SUPERSPEED_PLUS_CAPABILITY: { + libusb_ssplus_usb_device_capability_descriptor* cap = nullptr; + if (!libusb_get_ssplus_usb_device_capability_descriptor( +@@ -582,6 +594,7 @@ struct LibusbConnection : public Connection { + libusb_free_ssplus_usb_device_capability_descriptor(cap); + } + } break; ++#endif + default: + break; + } diff --git a/devel/android-tools/files/patch-vendor_adb_pairing__connection_pairing__connection.cpp b/devel/android-tools/files/patch-vendor_adb_pairing__connection_pairing__connection.cpp new file mode 100644 index 000000000000..06f9678a1697 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_adb_pairing__connection_pairing__connection.cpp @@ -0,0 +1,13 @@ +--- vendor/adb/pairing_connection/pairing_connection.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/adb/pairing_connection/pairing_connection.cpp +@@ -25,6 +25,10 @@ + #include + #include + ++#ifdef __FreeBSD__ ++#include ++#endif ++ + #include + #include + #include diff --git a/devel/android-tools/files/patch-vendor_adb_sysdeps.h b/devel/android-tools/files/patch-vendor_adb_sysdeps.h new file mode 100644 index 000000000000..204f0da81d8d --- /dev/null +++ b/devel/android-tools/files/patch-vendor_adb_sysdeps.h @@ -0,0 +1,15 @@ +--- vendor/adb/sysdeps.h.orig 2024-08-29 17:46:57 UTC ++++ vendor/adb/sysdeps.h +@@ -53,6 +53,12 @@ static inline void* mempcpy(void* dst, const void* src + } + #endif + ++#ifdef __FreeBSD__ ++#define lseek64 lseek ++#define pread64 pread ++#define pwrite64 pwrite ++#endif ++ + std::optional network_peek(borrowed_fd fd); + + // Clang-only nullability specifiers diff --git a/devel/android-tools/files/patch-vendor_adb_tls_include_adb_tls_tls__connection.h b/devel/android-tools/files/patch-vendor_adb_tls_include_adb_tls_tls__connection.h index afc4ed589316..738d2cf75ac6 100644 --- a/devel/android-tools/files/patch-vendor_adb_tls_include_adb_tls_tls__connection.h +++ b/devel/android-tools/files/patch-vendor_adb_tls_include_adb_tls_tls__connection.h @@ -1,7 +1,7 @@ ---- vendor/adb/tls/include/adb/tls/tls_connection.h.orig 2024-02-11 15:40:31 UTC +--- vendor/adb/tls/include/adb/tls/tls_connection.h.orig 2024-08-29 17:46:57 UTC +++ vendor/adb/tls/include/adb/tls/tls_connection.h -@@ -21,6 +21,7 @@ - +@@ -22,6 +22,7 @@ + #include #include #include +#include diff --git a/devel/android-tools/files/patch-vendor_boringssl_crypto_x509_t__x509.c b/devel/android-tools/files/patch-vendor_boringssl_crypto_x509_t__x509.c deleted file mode 100644 index d860df822689..000000000000 --- a/devel/android-tools/files/patch-vendor_boringssl_crypto_x509_t__x509.c +++ /dev/null @@ -1,45 +0,0 @@ -https://github.com/google/boringssl/commit/af34f6460f0bf99dc267818f02b2936f60a30de7 - -From af34f6460f0bf99dc267818f02b2936f60a30de7 Mon Sep 17 00:00:00 2001 -From: Kent Ross -Date: Wed, 30 Mar 2022 14:11:02 -0700 -Subject: [PATCH] Remove unused variable - -This is causing -Werror failures with recent Clang builds. - -Change-Id: I0f82d99ae51d02037f5f614a8fadfb3efc0da2da -Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52145 -Reviewed-by: Adam Langley -Commit-Queue: Adam Langley ---- - crypto/x509/t_x509.c | 6 +----- - 1 file changed, 1 insertion(+), 5 deletions(-) - -diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c -index 4f9d40979a..5e633a9d87 100644 ---- vendor/boringssl/crypto/x509/t_x509.c -+++ vendor/boringssl/crypto/x509/t_x509.c -@@ -322,9 +322,7 @@ int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, - int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase) - { - char *s, *c, *b; -- int ret = 0, l, i; -- -- l = 80 - 2 - obase; -+ int ret = 0, i; - - b = X509_NAME_oneline(name, NULL, 0); - if (!b) -@@ -351,12 +349,10 @@ int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase) - if (BIO_write(bp, ", ", 2) != 2) - goto err; - } -- l--; - } - if (*s == '\0') - break; - s++; -- l--; - } - - ret = 1; diff --git a/devel/android-tools/files/patch-vendor_core_fastboot_Android.bp b/devel/android-tools/files/patch-vendor_core_fastboot_Android.bp new file mode 100644 index 000000000000..de52f4a185e9 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_fastboot_Android.bp @@ -0,0 +1,13 @@ +--- vendor/core/fastboot/Android.bp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/fastboot/Android.bp +@@ -92,6 +92,10 @@ cc_library_host_static { + srcs: ["usb_linux.cpp"], + }, + ++ freebsd: { ++ srcs: ["usb_freebsd.cpp"], ++ }, ++ + darwin: { + srcs: ["usb_osx.cpp"], + diff --git a/devel/android-tools/files/patch-vendor_core_fastboot_filesystem.cpp b/devel/android-tools/files/patch-vendor_core_fastboot_filesystem.cpp new file mode 100644 index 000000000000..8673e15b3bb1 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_fastboot_filesystem.cpp @@ -0,0 +1,20 @@ +--- vendor/core/fastboot/filesystem.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/fastboot/filesystem.cpp +@@ -32,6 +32,10 @@ + + #include "filesystem.h" + ++#ifndef LOCK_EX ++#define LOCK_EX 2 ++#endif ++ + namespace { + + int LockFile(int fd) { +@@ -102,4 +106,4 @@ FileLock::FileLock(const std::string& path) : fd_(open + if (LockFile(fd_.get()) != 0) { + LOG(FATAL) << "Failed to acquire a lock on " << path; + } +-} +\ No newline at end of file ++} diff --git a/devel/android-tools/files/patch-vendor_core_fastboot_usb__freebsd.cpp b/devel/android-tools/files/patch-vendor_core_fastboot_usb__freebsd.cpp new file mode 100644 index 000000000000..7ff224d0592f --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_fastboot_usb__freebsd.cpp @@ -0,0 +1,268 @@ +--- vendor/core/fastboot/usb_freebsd.cpp.orig 2024-11-11 20:53:02 UTC ++++ vendor/core/fastboot/usb_freebsd.cpp +@@ -0,0 +1,265 @@ ++/* ++ * Copyright (C) 2008 The Android Open Source Project ++ * All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * * Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * * Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in ++ * the documentation and/or other materials provided with the ++ * distribution. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ++ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ++ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ++ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ++ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ++ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ++ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "usb.h" ++#include "util.h" ++ ++using namespace std::chrono_literals; ++ ++#define MAX_RETRIES 2 ++#define WAIT_FOR_DISCONNECT_TIMEOUT 3 ++ ++#ifdef TRACE_USB ++#define DBG1(x...) fprintf(stderr, x) ++#define DBG(x...) fprintf(stderr, x) ++#else ++#define DBG(x...) ++#define DBG1(x...) ++#endif ++ ++#define ERR(x...) fprintf(stderr, "ERROR: " x) ++ ++#define MAX_USBFS_BULK_WRITE_SIZE (256 * 1024) ++#define MAX_USBFS_BULK_READ_SIZE (16 * 1024) ++#define MIN_USBFS_BULK_WRITE_SIZE (16 * 1024) ++ ++struct usb_handle { ++ libusb_device_handle *handle; ++ unsigned char ep_in; ++ unsigned char ep_out; ++}; ++ ++class FreeBSDUsbTransport : public UsbTransport { ++public: ++ explicit FreeBSDUsbTransport(std::unique_ptr handle, uint32_t ms_timeout = 0) ++ : handle_(std::move(handle)), ms_timeout_(ms_timeout) {} ++ ~FreeBSDUsbTransport() override; ++ ssize_t Read(void* data, size_t len) override; ++ ssize_t Write(const void* data, size_t len) override; ++ int Close() override; ++ int Reset() override; ++ int WaitForDisconnect() override; ++ ++private: ++ std::unique_ptr handle_; ++ const uint32_t ms_timeout_; ++ size_t max_usbfs_bulk_write_size_ = MAX_USBFS_BULK_WRITE_SIZE; ++ DISALLOW_COPY_AND_ASSIGN(FreeBSDUsbTransport); ++}; ++ ++FreeBSDUsbTransport::~FreeBSDUsbTransport() { ++ Close(); ++} ++ ++ssize_t FreeBSDUsbTransport::Write(const void* data, size_t len) { ++ unsigned char* data_ptr = (unsigned char*)data; ++ int transferred = 0; ++ int total_transferred = 0; ++ int ret; ++ ++ if (handle_->ep_out == 0 || handle_->handle == nullptr) { ++ return -1; ++ } ++ ++ while (len > 0) { ++ int xfer = (len > max_usbfs_bulk_write_size_) ? max_usbfs_bulk_write_size_ : len; ++ ret = libusb_bulk_transfer(handle_->handle, handle_->ep_out, data_ptr, xfer, &transferred, ms_timeout_); ++ ++ if (ret != 0) { ++ if (ret == LIBUSB_ERROR_NO_MEM && max_usbfs_bulk_write_size_ > MIN_USBFS_BULK_WRITE_SIZE) { ++ max_usbfs_bulk_write_size_ /= 2; ++ continue; ++ } ++ DBG("libusb_bulk_transfer failed with error %d\n", ret); ++ return -1; ++ } ++ ++ total_transferred += transferred; ++ len -= transferred; ++ data_ptr += transferred; ++ } ++ ++ return total_transferred; ++} ++ ++ssize_t FreeBSDUsbTransport::Read(void* data, size_t len) { ++ unsigned char* data_ptr = (unsigned char*)data; ++ int transferred = 0; ++ int total_transferred = 0; ++ int ret; ++ ++ if (handle_->ep_in == 0 || handle_->handle == nullptr) { ++ return -1; ++ } ++ ++ while (len > 0) { ++ int xfer = (len > MAX_USBFS_BULK_READ_SIZE) ? MAX_USBFS_BULK_READ_SIZE : len; ++ ret = libusb_bulk_transfer(handle_->handle, handle_->ep_in, data_ptr, xfer, &transferred, ms_timeout_); ++ ++ if (ret != 0) { ++ DBG("libusb_bulk_transfer failed with error %d\n", ret); ++ return -1; ++ } ++ ++ total_transferred += transferred; ++ len -= transferred; ++ data_ptr += transferred; ++ ++ if (transferred < xfer) { ++ // Short read, no more data available ++ break; ++ } ++ } ++ ++ return total_transferred; ++} ++ ++int FreeBSDUsbTransport::Close() { ++ if (handle_->handle) { ++ libusb_close(handle_->handle); ++ handle_->handle = nullptr; ++ } ++ return 0; ++} ++ ++int FreeBSDUsbTransport::Reset() { ++ if (handle_->handle == nullptr) { ++ return -1; ++ } ++ ++ int ret = libusb_reset_device(handle_->handle); ++ if (ret != 0) { ++ DBG("libusb_reset_device failed with error %d\n", ret); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++/* Wait for the system to notice the device is gone, so that a subsequent ++ * fastboot command won't try to access the device before it's rebooted. ++ * Returns 0 for success, -1 for timeout. ++ */ ++int FreeBSDUsbTransport::WaitForDisconnect() { ++ auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(WAIT_FOR_DISCONNECT_TIMEOUT); ++ ++ while (std::chrono::steady_clock::now() < deadline) { ++ if (libusb_get_device(handle_->handle) == nullptr) { ++ return 0; ++ } ++ std::this_thread::sleep_for(std::chrono::milliseconds(50)); ++ } ++ ++ return -1; ++} ++ ++std::unique_ptr usb_open(ifc_match_func callback, uint32_t timeout_ms) { ++ libusb_context* context = nullptr; ++ libusb_device** list = nullptr; ++ libusb_device_handle* handle = nullptr; ++ ssize_t count; ++ int ret; ++ ++ ret = libusb_init(&context); ++ if (ret < 0) { ++ ERR("libusb_init failed with error %d\n", ret); ++ return nullptr; ++ } ++ ++ count = libusb_get_device_list(context, &list); ++ if (count < 0) { ++ ERR("libusb_get_device_list failed with error %d\n", (int)count); ++ libusb_exit(context); ++ return nullptr; ++ } ++ ++ std::unique_ptr usb_handle_ptr; ++ for (ssize_t i = 0; i < count; ++i) { ++ libusb_device* device = list[i]; ++ libusb_device_descriptor desc; ++ ++ ret = libusb_get_device_descriptor(device, &desc); ++ if (ret < 0) { ++ ERR("libusb_get_device_descriptor failed with error %d\n", ret); ++ continue; ++ } ++ ++ usb_ifc_info info = {}; ++ info.dev_vendor = desc.idVendor; ++ info.dev_product = desc.idProduct; ++ info.dev_class = desc.bDeviceClass; ++ info.dev_subclass = desc.bDeviceSubClass; ++ info.dev_protocol = desc.bDeviceProtocol; ++ ++ if (callback(&info) == 0) { ++ ret = libusb_open(device, &handle); ++ if (ret < 0) { ++ ERR("libusb_open failed with error %d\n", ret); ++ continue; ++ } ++ ++ usb_handle_ptr = std::make_unique(); ++ usb_handle_ptr->handle = handle; ++ usb_handle_ptr->ep_in = 0; ++ usb_handle_ptr->ep_out = 0; ++ ++ ret = libusb_claim_interface(handle, 0); ++ if (ret < 0) { ++ ERR("libusb_claim_interface failed with error %d\n", ret); ++ libusb_close(handle); ++ usb_handle_ptr.reset(); ++ continue; ++ } ++ ++ break; ++ } ++ } ++ ++ libusb_free_device_list(list, 1); ++ ++ if (!usb_handle_ptr) { ++ libusb_exit(context); ++ return nullptr; ++ } ++ ++ return std::make_unique(std::move(usb_handle_ptr), timeout_ms); ++} ++ diff --git a/devel/android-tools/files/patch-vendor_core_libcutils_include_private_android__filesystem__capability.h b/devel/android-tools/files/patch-vendor_core_libcutils_include_private_android__filesystem__capability.h new file mode 100644 index 000000000000..0cea2527a764 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libcutils_include_private_android__filesystem__capability.h @@ -0,0 +1,122 @@ +--- vendor/core/libcutils/include/private/android_filesystem_capability.h.orig 1970-01-01 01:00:00 UTC ++++ vendor/core/libcutils/include/private/android_filesystem_capability.h +@@ -0,0 +1,119 @@ ++/* ++ * Copyright (C) 2013 The Android Open Source Project ++ * ++ * Licensed under the Apache License, Version 2.0 (the "License"); ++ * you may not use this file except in compliance with the License. ++ * You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++/* ++ * Taken from linux/capability.h, with minor modifications ++ */ ++ ++#ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_FILESYSTEM_CAPABILITY_H ++#define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_FILESYSTEM_CAPABILITY_H ++ ++#include ++ ++#define __user ++#define __u32 uint32_t ++#define __le32 uint32_t ++ ++#define _LINUX_CAPABILITY_VERSION_1 0x19980330 ++#define _LINUX_CAPABILITY_U32S_1 1 ++#define _LINUX_CAPABILITY_VERSION_2 0x20071026 ++#define _LINUX_CAPABILITY_U32S_2 2 ++#define _LINUX_CAPABILITY_VERSION_3 0x20080522 ++#define _LINUX_CAPABILITY_U32S_3 2 ++ ++typedef struct __user_cap_header_struct { ++ __u32 version; ++ int pid; ++} __user* cap_user_header_t; ++ ++typedef struct __user_cap_data_struct { ++ __u32 effective; ++ __u32 permitted; ++ __u32 inheritable; ++} __user* cap_user_data_t; ++ ++#define VFS_CAP_REVISION_MASK 0xFF000000 ++#define VFS_CAP_REVISION_SHIFT 24 ++#define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK ++#define VFS_CAP_FLAGS_EFFECTIVE 0x000001 ++#define VFS_CAP_REVISION_1 0x01000000 ++#define VFS_CAP_U32_1 1 ++#define XATTR_CAPS_SZ_1 (sizeof(__le32) * (1 + 2 * VFS_CAP_U32_1)) ++#define VFS_CAP_REVISION_2 0x02000000 ++#define VFS_CAP_U32_2 2 ++#define XATTR_CAPS_SZ_2 (sizeof(__le32) * (1 + 2 * VFS_CAP_U32_2)) ++#define XATTR_CAPS_SZ XATTR_CAPS_SZ_2 ++#define VFS_CAP_U32 VFS_CAP_U32_2 ++#define VFS_CAP_REVISION VFS_CAP_REVISION_2 ++ ++struct vfs_cap_data { ++ __le32 magic_etc; ++ struct { ++ __le32 permitted; ++ __le32 inheritable; ++ } data[VFS_CAP_U32]; ++}; ++ ++#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1 ++#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1 ++#define CAP_CHOWN 0 ++#define CAP_DAC_OVERRIDE 1 ++#define CAP_DAC_READ_SEARCH 2 ++#define CAP_FOWNER 3 ++#define CAP_FSETID 4 ++#define CAP_KILL 5 ++#define CAP_SETGID 6 ++#define CAP_SETUID 7 ++#define CAP_SETPCAP 8 ++#define CAP_LINUX_IMMUTABLE 9 ++#define CAP_NET_BIND_SERVICE 10 ++#define CAP_NET_BROADCAST 11 ++#define CAP_NET_ADMIN 12 ++#define CAP_NET_RAW 13 ++#define CAP_IPC_LOCK 14 ++#define CAP_IPC_OWNER 15 ++#define CAP_SYS_MODULE 16 ++#define CAP_SYS_RAWIO 17 ++#define CAP_SYS_CHROOT 18 ++#define CAP_SYS_PTRACE 19 ++#define CAP_SYS_PACCT 20 ++#define CAP_SYS_ADMIN 21 ++#define CAP_SYS_BOOT 22 ++#define CAP_SYS_NICE 23 ++#define CAP_SYS_RESOURCE 24 ++#define CAP_SYS_TIME 25 ++#define CAP_SYS_TTY_CONFIG 26 ++#define CAP_MKNOD 27 ++#define CAP_LEASE 28 ++#define CAP_AUDIT_WRITE 29 ++#define CAP_AUDIT_CONTROL 30 ++#define CAP_SETFCAP 31 ++#define CAP_MAC_OVERRIDE 32 ++#define CAP_MAC_ADMIN 33 ++#define CAP_SYSLOG 34 ++#define CAP_WAKE_ALARM 35 ++#define CAP_BLOCK_SUSPEND 36 ++#define CAP_AUDIT_READ 37 ++#define CAP_LAST_CAP CAP_AUDIT_READ ++#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP) ++#define CAP_TO_INDEX(x) ((x) >> 5) ++#define CAP_TO_MASK(x) (1 << ((x)&31)) ++ ++#undef __user ++#undef __u32 ++#undef __le32 ++ ++#endif diff --git a/devel/android-tools/files/patch-vendor_core_libcutils_include_private_fs__config.h b/devel/android-tools/files/patch-vendor_core_libcutils_include_private_fs__config.h new file mode 100644 index 000000000000..805bfe0b53ea --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libcutils_include_private_fs__config.h @@ -0,0 +1,14 @@ +--- vendor/core/libcutils/include/private/fs_config.h.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libcutils/include/private/fs_config.h +@@ -26,7 +26,11 @@ + #include + #include + ++#if defined(__BIONIC__) + #include ++#else ++#include ++#endif + + /* Rules for directories and files has moved to system/code/libcutils/fs_config.c */ + diff --git a/devel/android-tools/files/patch-vendor_core_libsparse_append2simg.cpp b/devel/android-tools/files/patch-vendor_core_libsparse_append2simg.cpp new file mode 100644 index 000000000000..8f261de27507 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libsparse_append2simg.cpp @@ -0,0 +1,14 @@ +--- vendor/core/libsparse/append2simg.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libsparse/append2simg.cpp +@@ -32,10 +32,7 @@ + #define O_BINARY 0 + #endif + +-#if defined(__APPLE__) && defined(__MACH__) +-#define lseek64 lseek +-#endif +-#if defined(__APPLE__) && defined(__MACH__) ++#if defined(__APPLE__) && defined(__MACH__) || defined(__FreeBSD__) + #define lseek64 lseek + #define off64_t off_t + #endif diff --git a/devel/android-tools/files/patch-vendor_core_libsparse_img2simg.cpp b/devel/android-tools/files/patch-vendor_core_libsparse_img2simg.cpp new file mode 100644 index 000000000000..d0820e567bc7 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libsparse_img2simg.cpp @@ -0,0 +1,11 @@ +--- vendor/core/libsparse/img2simg.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libsparse/img2simg.cpp +@@ -32,7 +32,7 @@ + #define O_BINARY 0 + #endif + +-#if defined(__APPLE__) && defined(__MACH__) ++#if defined(__APPLE__) && defined(__MACH__) || defined(__FreeBSD__) + #define lseek64 lseek + #define off64_t off_t + #endif diff --git a/devel/android-tools/files/patch-vendor_core_libsparse_output__file.cpp b/devel/android-tools/files/patch-vendor_core_libsparse_output__file.cpp new file mode 100644 index 000000000000..36ea75dc5766 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libsparse_output__file.cpp @@ -0,0 +1,11 @@ +--- vendor/core/libsparse/output_file.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libsparse/output_file.cpp +@@ -43,7 +43,7 @@ + #define ftruncate64 ftruncate + #endif + +-#if defined(__APPLE__) && defined(__MACH__) ++#if defined(__APPLE__) && defined(__MACH__) || defined(__FreeBSD__) + #define lseek64 lseek + #define ftruncate64 ftruncate + #define off64_t off_t diff --git a/devel/android-tools/files/patch-vendor_core_libsparse_sparse__read.cpp b/devel/android-tools/files/patch-vendor_core_libsparse_sparse__read.cpp new file mode 100644 index 000000000000..71dc8f20271c --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libsparse_sparse__read.cpp @@ -0,0 +1,11 @@ +--- vendor/core/libsparse/sparse_read.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libsparse/sparse_read.cpp +@@ -37,7 +37,7 @@ + #include "sparse_file.h" + #include "sparse_format.h" + +-#if defined(__APPLE__) && defined(__MACH__) ++#if defined(__APPLE__) && defined(__MACH__) || defined(__FreeBSD__) + #define lseek64 lseek + #define off64_t off_t + #endif diff --git a/devel/android-tools/files/patch-vendor_core_libutils_FileMap.cpp b/devel/android-tools/files/patch-vendor_core_libutils_FileMap.cpp new file mode 100644 index 000000000000..edd84ddf03e9 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_core_libutils_FileMap.cpp @@ -0,0 +1,13 @@ +--- vendor/core/libutils/FileMap.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/core/libutils/FileMap.cpp +@@ -42,6 +42,10 @@ + #include + #include + ++#ifdef __FreeBSD__ ++#define mmap64 mmap ++#endif ++ + using namespace android; + + /*static*/ long FileMap::mPageSize = -1; diff --git a/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devname.c b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devname.c new file mode 100644 index 000000000000..118c7edcf5a3 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devname.c @@ -0,0 +1,11 @@ +--- vendor/e2fsprogs/lib/blkid/devname.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/e2fsprogs/lib/blkid/devname.c +@@ -36,7 +36,7 @@ + #if HAVE_SYS_MKDEV_H + #include + #endif +-#ifdef HAVE_SYS_SYSMACROS_H ++#if defined(HAVE_SYS_SYSMACROS_H) && !defined(__FreeBSD__) + #include + #endif + #include diff --git a/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devno.c b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devno.c new file mode 100644 index 000000000000..99568baf54dc --- /dev/null +++ b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_blkid_devno.c @@ -0,0 +1,11 @@ +--- vendor/e2fsprogs/lib/blkid/devno.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/e2fsprogs/lib/blkid/devno.c +@@ -31,7 +31,7 @@ + #if HAVE_SYS_MKDEV_H + #include + #endif +-#ifdef HAVE_SYS_SYSMACROS_H ++#if defined(HAVE_SYS_SYSMACROS_H) && !defined(__FreeBSD__) + #include + #endif + diff --git a/devel/android-tools/files/patch-vendor_e2fsprogs_lib_ext2fs_ismounted.c b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_ext2fs_ismounted.c new file mode 100644 index 000000000000..70d39b263775 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_e2fsprogs_lib_ext2fs_ismounted.c @@ -0,0 +1,11 @@ +--- vendor/e2fsprogs/lib/ext2fs/ismounted.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/e2fsprogs/lib/ext2fs/ismounted.c +@@ -49,7 +49,7 @@ + #if HAVE_SYS_TYPES_H + #include + #endif +-#ifdef HAVE_SYS_SYSMACROS_H ++#if defined(HAVE_SYS_SYSMACROS_H) && !defined(__FreeBSD__) + #include + #endif + diff --git a/devel/android-tools/files/patch-vendor_e2fsprogs_misc_create__inode.c b/devel/android-tools/files/patch-vendor_e2fsprogs_misc_create__inode.c new file mode 100644 index 000000000000..92f1a92a09f0 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_e2fsprogs_misc_create__inode.c @@ -0,0 +1,11 @@ +--- vendor/e2fsprogs/misc/create_inode.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/e2fsprogs/misc/create_inode.c +@@ -28,7 +28,7 @@ + #ifdef HAVE_SYS_IOCTL_H + #include + #endif +-#ifdef HAVE_SYS_SYSMACROS_H ++#if defined(HAVE_SYS_SYSMACROS_H) && !defined(__FreeBSD__) + #include + #endif + diff --git a/devel/android-tools/files/patch-vendor_e2fsprogs_misc_mk__hugefiles.c b/devel/android-tools/files/patch-vendor_e2fsprogs_misc_mk__hugefiles.c new file mode 100644 index 000000000000..c5d77f9779f0 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_e2fsprogs_misc_mk__hugefiles.c @@ -0,0 +1,11 @@ +--- vendor/e2fsprogs/misc/mk_hugefiles.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/e2fsprogs/misc/mk_hugefiles.c +@@ -32,7 +32,7 @@ extern int optind; + #endif + #include + #include +-#ifdef HAVE_SYS_SYSMACROS_H ++#if defined(HAVE_SYS_SYSMACROS_H) && !defined(__FreeBSD__) + #include + #endif + #include diff --git a/devel/android-tools/files/patch-abseil b/devel/android-tools/files/patch-vendor_extras_libjsonpb_parse_jsonpb.cpp similarity index 72% rename from devel/android-tools/files/patch-abseil rename to devel/android-tools/files/patch-vendor_extras_libjsonpb_parse_jsonpb.cpp index be949a6aa119..5c2742cab129 100644 --- a/devel/android-tools/files/patch-abseil +++ b/devel/android-tools/files/patch-vendor_extras_libjsonpb_parse_jsonpb.cpp @@ -1,4 +1,4 @@ ---- vendor/extras/libjsonpb/parse/jsonpb.cpp.orig 2022-06-10 23:11:16 UTC +--- vendor/extras/libjsonpb/parse/jsonpb.cpp.orig 2024-08-29 17:46:57 UTC +++ vendor/extras/libjsonpb/parse/jsonpb.cpp @@ -49,9 +49,9 @@ ErrorOr MessageToJsonString(const Message @@ -6,21 +6,21 @@ #if GOOGLE_PROTOBUF_VERSION < 3016000 - return MakeError(status.error_message().as_string()); + return MakeError(std::string(status.error_message())); - #else + #elif GOOGLE_PROTOBUF_VERSION < 4022000 - return MakeError(status.message().as_string()); + return MakeError(std::string(status.message())); + #else + return MakeError(std::string(status.message())); #endif - } - return ErrorOr(std::move(json)); -@@ -66,9 +66,9 @@ ErrorOr JsonStringToMessage(const std: +@@ -68,9 +68,9 @@ ErrorOr JsonStringToMessage(const std: auto status = JsonToBinaryString(resolver.get(), GetTypeUrl(*message), content, &binary); if (!status.ok()) { #if GOOGLE_PROTOBUF_VERSION < 3016000 - return MakeError(status.error_message().as_string()); + return MakeError(std::string(status.error_message())); - #else + #elif GOOGLE_PROTOBUF_VERSION < 4022000 - return MakeError(status.message().as_string()); + return MakeError(std::string(status.message())); + #else + return MakeError(std::string(status.message())); #endif - } - if (!message->ParseFromString(binary)) { diff --git a/devel/android-tools/files/patch-vendor_f2fs-tools_fsck_xattr.c b/devel/android-tools/files/patch-vendor_f2fs-tools_fsck_xattr.c new file mode 100644 index 000000000000..242cc262096a --- /dev/null +++ b/devel/android-tools/files/patch-vendor_f2fs-tools_fsck_xattr.c @@ -0,0 +1,13 @@ +--- vendor/f2fs-tools/fsck/xattr.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/f2fs-tools/fsck/xattr.c +@@ -17,6 +17,10 @@ + #include "node.h" + #include "xattr.h" + ++#ifndef ENODATA ++#define ENODATA EPIPE ++#endif ++ + void *read_all_xattrs(struct f2fs_sb_info *sbi, struct f2fs_node *inode, + bool sanity_check) + { diff --git a/devel/android-tools/files/patch-vendor_f2fs-tools_lib_libf2fs.c b/devel/android-tools/files/patch-vendor_f2fs-tools_lib_libf2fs.c new file mode 100644 index 000000000000..b5a3f7cdf927 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_f2fs-tools_lib_libf2fs.c @@ -0,0 +1,63 @@ +--- vendor/f2fs-tools/lib/libf2fs.c.orig 2024-08-29 17:46:57 UTC ++++ vendor/f2fs-tools/lib/libf2fs.c +@@ -43,6 +43,10 @@ + #ifdef HAVE_LINUX_LIMITS_H + #include + #endif ++#ifdef __FreeBSD__ ++#include ++#include ++#endif + + /* SCSI command for standard inquiry*/ + #define MODELINQUIRY 0x12,0x00,0x00,0x00,0x4A,0x00 +@@ -946,6 +950,11 @@ void get_kernel_uname_version(__u8 *version) + #define BLKSSZGET DKIOCGETBLOCKCOUNT + #endif /* APPLE_DARWIN */ + ++#if defined(__FreeBSD__) ++#include /* for offsetof() */ ++#include /* for DIOCG{MEDIA,SECTOR}SIZE */ ++#endif ++ + #ifndef _WIN32 + static int open_check_fs(char *path, int flag) + { +@@ -981,6 +990,10 @@ int get_device_info(int i) + #endif + struct device_info *dev = c.devices + i; + int flags = O_RDWR; ++#if defined(__FreeBSD__) ++ int res; ++ off_t mediasize; ++#endif + + if (c.sparse_mode) { + fd = open(dev->path, O_RDWR | O_CREAT | O_BINARY, 0644); +@@ -1070,14 +1083,25 @@ int get_device_info(int i) + return -1; + } + #else ++#if defined(__FreeBSD__) ++ res = ioctl(fd, DIOCGMEDIASIZE, &mediasize); ++ if (!res) ++ res = ioctl(fd, DIOCGSECTORSIZE, &total_sectors); ++ else { ++ MSG(0, "\tError: Cannot get the device size\n"); ++ free(stat_buf); ++ return -1; ++ } ++#else + if (ioctl(fd, BLKGETSIZE, &total_sectors) < 0) { + MSG(0, "\tError: Cannot get the device size\n"); + free(stat_buf); + return -1; + } +- dev->total_sectors = total_sectors; + #endif ++ dev->total_sectors = total_sectors; + dev->total_sectors /= dev->sector_size; ++#endif + + if (i == 0) { + #ifdef HDIO_GETGIO diff --git a/devel/android-tools/files/patch-vendor_libbase_file.cpp b/devel/android-tools/files/patch-vendor_libbase_file.cpp new file mode 100644 index 000000000000..565d5271a4b2 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_libbase_file.cpp @@ -0,0 +1,30 @@ +--- vendor/libbase/file.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/libbase/file.cpp +@@ -33,6 +33,9 @@ + #include + #include + ++#if defined(__FreeBSD__) ++#include ++#endif + #if defined(__APPLE__) + #include + #endif +@@ -490,6 +493,17 @@ std::string GetExecutablePath() { + std::string path; + android::base::Readlink("/proc/self/exe", &path); + return path; ++#elif defined(__FreeBSD__) ++ int mib[4]; ++ mib[0] = CTL_KERN; ++ mib[1] = KERN_PROC; ++ mib[2] = KERN_PROC_PATHNAME; ++ mib[3] = -1; ++ char path[PATH_MAX + 1]; ++ size_t path_len = sizeof(path); ++ if (sysctl(mib, 4, path, &path_len, nullptr, 0) < 0) ++ return ""; ++ return (path); + #elif defined(__APPLE__) + char path[PATH_MAX + 1]; + uint32_t path_len = sizeof(path); diff --git a/devel/android-tools/files/patch-vendor_libbase_include_android-base_endian.h b/devel/android-tools/files/patch-vendor_libbase_include_android-base_endian.h new file mode 100644 index 000000000000..32174f9ff29c --- /dev/null +++ b/devel/android-tools/files/patch-vendor_libbase_include_android-base_endian.h @@ -0,0 +1,11 @@ +--- vendor/libbase/include/android-base/endian.h.orig 2024-08-29 17:46:57 UTC ++++ vendor/libbase/include/android-base/endian.h +@@ -52,6 +52,8 @@ + #if defined(__APPLE__) + /* macOS has some of the basics. */ + #include ++#elif defined(__FreeBSD__) ++#include + #else + /* Windows has some of the basics as well. */ + #include diff --git a/devel/android-tools/files/patch-vendor_libbase_logging.cpp b/devel/android-tools/files/patch-vendor_libbase_logging.cpp new file mode 100644 index 000000000000..56369750d7a3 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_libbase_logging.cpp @@ -0,0 +1,20 @@ +--- vendor/libbase/logging.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/libbase/logging.cpp +@@ -26,7 +26,7 @@ + #include + + // For getprogname(3) or program_invocation_short_name. +-#if defined(__ANDROID__) || defined(__APPLE__) ++#if defined(__ANDROID__) || defined(__APPLE__) || defined(__FreeBSD__) + #include + #elif defined(__GLIBC__) + #include +@@ -62,7 +62,7 @@ namespace base { + namespace base { + + // BSD-based systems like Android/macOS have getprogname(). Others need us to provide one. +-#if !defined(__APPLE__) && !defined(__BIONIC__) ++#if !defined(__APPLE__) && !defined(__BIONIC__) && !defined(__FreeBSD__) + static const char* getprogname() { + #ifdef _WIN32 + static bool first = true; diff --git a/devel/android-tools/files/patch-vendor_libziparchive_zip__archive.cc b/devel/android-tools/files/patch-vendor_libziparchive_zip__archive.cc new file mode 100644 index 000000000000..c2c55211ffc0 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_libziparchive_zip__archive.cc @@ -0,0 +1,11 @@ +--- vendor/libziparchive/zip_archive.cc.orig 2024-08-29 17:46:57 UTC ++++ vendor/libziparchive/zip_archive.cc +@@ -42,7 +42,7 @@ + #include + #include + +-#if defined(__APPLE__) ++#if defined(__APPLE__) || defined(__FreeBSD__) + #define lseek64 lseek + #endif + diff --git a/devel/android-tools/files/patch-vendor_logging_liblog_logger__write.cpp b/devel/android-tools/files/patch-vendor_logging_liblog_logger__write.cpp new file mode 100644 index 000000000000..c86b33cc1ac0 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_logging_liblog_logger__write.cpp @@ -0,0 +1,29 @@ +--- vendor/logging/liblog/logger_write.cpp.orig 2024-08-29 17:46:57 UTC ++++ vendor/logging/liblog/logger_write.cpp +@@ -48,6 +48,8 @@ + + #if defined(__APPLE__) + #include ++#elif defined(__FreeBSD__) ++#include + #elif defined(__linux__) && !defined(__ANDROID__) + #include + #elif defined(_WIN32) +@@ -120,7 +122,7 @@ void __android_log_close() { + } + + // BSD-based systems like Android/macOS have getprogname(). Others need us to provide one. +-#if !defined(__APPLE__) && !defined(__BIONIC__) ++#if !defined(__APPLE__) && !defined(__BIONIC__) && !defined(__FreeBSD__) + static const char* getprogname() { + #ifdef _WIN32 + static bool first = true; +@@ -246,6 +248,8 @@ static uint64_t GetThreadId() { + uint64_t tid; + pthread_threadid_np(NULL, &tid); + return tid; ++#elif defined(__FreeBSD__) ++ return pthread_getthreadid_np(); + #elif defined(__linux__) + return syscall(__NR_gettid); + #elif defined(_WIN32) diff --git a/devel/android-tools/files/patch-vendor_selinux_libselinux_src_label__file.h b/devel/android-tools/files/patch-vendor_selinux_libselinux_src_label__file.h new file mode 100644 index 000000000000..48a9a8fd9b70 --- /dev/null +++ b/devel/android-tools/files/patch-vendor_selinux_libselinux_src_label__file.h @@ -0,0 +1,15 @@ +--- vendor/selinux/libselinux/src/label_file.h.orig 2024-08-29 17:46:57 UTC ++++ vendor/selinux/libselinux/src/label_file.h +@@ -6,7 +6,12 @@ + #include + + #include ++#ifdef __FreeBSD__ ++#include ++#include ++#else + #include ++#endif + + /* + * regex.h/c were introduced to hold all dependencies on the regular diff --git a/devel/android-tools/pkg-plist b/devel/android-tools/pkg-plist index 34592897be55..1e5dc032acd8 100644 --- a/devel/android-tools/pkg-plist +++ b/devel/android-tools/pkg-plist @@ -1,5 +1,7 @@ bin/adb bin/append2simg +bin/avbtool +bin/ext2simg bin/fastboot bin/img2simg bin/lpadd @@ -7,12 +9,18 @@ bin/lpdump bin/lpflash bin/lpmake bin/lpunpack +bin/make_f2fs bin/mkbootimg +bin/mkdtboimg bin/mke2fs.android bin/repack_bootimg bin/simg2img +bin/sload_f2fs bin/unpack_bootimg %%DATADIR%%/completions/adb %%DATADIR%%/completions/fastboot +%%DATADIR%%/mkbootimg/gki/generate_gki_certificate.py +%%DATADIR%%/mkbootimg/mkbootimg.py share/bash-completion/completions/adb share/bash-completion/completions/fastboot +share/man/man1/adb.1.gz -- 2.47.0