diff options
31 files changed, 949 insertions, 425 deletions
diff --git a/devel/android-tools-adb-devel/Makefile b/devel/android-tools-adb-devel/Makefile index 19379f74cef9..dac702b436a9 100644 --- a/devel/android-tools-adb-devel/Makefile +++ b/devel/android-tools-adb-devel/Makefile @@ -11,19 +11,9 @@ CONFLICTS_INSTALL= ${PORTNAME}-[0-9]* MASTERDIR= ${.CURDIR}/../android-tools-adb DISTINFO_FILE= ${.CURDIR}/distinfo FILESDIR= ${.CURDIR}/files -PATCHDIR= ${.CURDIR}/files +EXTRA_PATCHES= ${.CURDIR}/files/patch-* -USES= compiler:c++11-lib -BUILD_WRKSRC= ${WRKSRC}/adb -INSTALL_WRKSRC= ${BUILD_WRKSRC} -MAKE_ENV= FILESDIR="${FILESDIR}" -CPPFLAGS+= -DADB_REVISION='\"${DISTVERSIONSUFFIX:S/-g//}-android\"' -ALL_TARGET= all - -OPTIONS_DEFINE= TEST TEST_PYTHON - -TEST_BUILD_DEPENDS= googletest>=1.6.0:${PORTSDIR}/devel/googletest -TEST_ALL_TARGET= adb_test +OPTIONS_DEFINE= TEST_PYTHON TEST_PYTHON_DESC= ${TEST_DESC:S/tests/python &/} TEST_PYTHON_GH_PROJECT= platform_development:development @@ -31,23 +21,6 @@ TEST_PYTHON_GH_TAGNAME= ${DISTVERSIONFULL:C/-[0-9].*//}-66-ge4cded6:development TEST_PYTHON_BUILD_DEPENDS=${PYTHON_PKGNAMEPREFIX}mock>0:${PORTSDIR}/devel/py-mock TEST_PYTHON_USES= python:2.7,build -post-patch: slave-post-patch -slave-post-patch: -# XXX C++ exception with description "regex_error" thrown in the test body. - @if [ ${OPSYS} = FreeBSD -a ${OSREL:R} -lt 10 ]; then \ - ${REINPLACE_CMD} -Ee '/^TEST/\ - s/ (LOG|PLOG|UNIMPLEMENTED)/ DISABLED_\1/' \ - ${WRKSRC}/base/logging_test.cpp; \ - fi -.if defined(PACKAGE_BUILDING) -# XXX /dev/full isn't mounted by poudriere/tinderbox - @${REINPLACE_CMD} -e '/^TEST/s/[^ ]*ENOSPC/DISABLED_&/' \ - ${WRKSRC}/adb/adb_io_test.cpp -.endif - -pre-install-TEST-on: - ${BUILD_WRKSRC}/adb_test - pre-install-TEST_PYTHON-on: # XXX python tests may leave behind running adb server # test_adb.py remains in core repository for some reason diff --git a/devel/android-tools-adb/Makefile b/devel/android-tools-adb/Makefile index 6eef27436874..83350790ad4c 100644 --- a/devel/android-tools-adb/Makefile +++ b/devel/android-tools-adb/Makefile @@ -2,15 +2,15 @@ PORTNAME= android-tools-adb DISTVERSIONPREFIX= android- -DISTVERSION?= 5.1.1_r4 -PORTREVISION?= 1 +DISTVERSION?= 6.0.0_r1 +PORTREVISION?= 0 CATEGORIES= devel MASTER_SITES= https://anonscm.debian.org/cgit/android-tools/android-tools.git/plain/debian/:bashcomp DISTFILES= ${DISTNAME}${EXTRACT_SUFX} \ bash_completion.d/adb?id=2b8cfec:bashcomp EXTRACT_ONLY= ${DISTFILES:N*\:bashcomp:C/:.*//} -MAINTAINER= kevlo@FreeBSD.org +MAINTAINER= jbeich@FreeBSD.org COMMENT= Android debug bridge command line tool LICENSE= APACHE20 @@ -19,25 +19,56 @@ USE_GITHUB= yes GH_ACCOUNT= android GH_PROJECT= platform_system_core +# Emulate GH_COMMIT without causing desync +.ifdef DISTVERSIONSUFFIX +GH_REVISION= ${DISTVERSIONSUFFIX:S/-g//} # snapshot +.else +GH_REVISION= bb0c180e6270 # generated by: make update-revision +.endif + CONFLICTS_INSTALL?= ${PORTNAME}-devel-* -USES+= uidfix -USE_OPENSSL= yes -.ifndef BUILD_WRKSRC -WRKSRC_SUBDIR= adb +.ifndef EXTRA_PATCHES +EXTRA_PATCHES+= ${PATCHDIR}/extra-patch-base_file__test.cpp .endif + +USES= compiler:c++11-lib uidfix +USE_OPENSSL= yes +BUILD_WRKSRC= ${WRKSRC}/adb +INSTALL_WRKSRC= ${BUILD_WRKSRC} MAKEFILE= ${FILESDIR}/Makefile -MAKE_ENV+= BINDIR="${PREFIX}/bin" +MAKE_ENV= BINDIR="${PREFIX}/bin" FILESDIR="${FILESDIR}" +ALL_TARGET= all +CPPFLAGS+= -DADB_REVISION='\"${GH_REVISION}-android\"' PLIST_FILES= bin/adb \ %%BASH%%etc/bash_completion.d/adb PORTDOCS= *.txt *.TXT -OPTIONS_DEFINE+=BASH DOCS +OPTIONS_DEFINE+=BASH DOCS TEST OPTIONS_SUB= yes BASH_VARS= LICENSE+=MIT LICENSE_COMB=multi # debian/copyright +TEST_BUILD_DEPENDS= googletest>=1.6.0:${PORTSDIR}/devel/googletest +TEST_ALL_TARGET= adb_test + +pre-install-TEST-on: + ${BUILD_WRKSRC}/adb_test + +post-patch: +# XXX C++ exception with description "regex_error" thrown in the test body. + @if [ ${OPSYS} = FreeBSD -a ${OSREL:R} -lt 10 ]; then \ + ${REINPLACE_CMD} -Ee '/^TEST/\ + s/ (LOG|PLOG|UNIMPLEMENTED)/ DISABLED_\1/' \ + ${WRKSRC}/base/logging_test.cpp; \ + fi +.if defined(PACKAGE_BUILDING) +# XXX /dev/full isn't mounted by poudriere/tinderbox + @${REINPLACE_CMD} -e '/^TEST/s/[^ ]*ENOSPC/DISABLED_&/' \ + ${WRKSRC}/adb/adb_io_test.cpp +.endif + post-install: ${MKDIR} ${STAGEDIR}${PREFIX}/${PLIST_FILES:M%%BASH%%*:C/%%.*%%//:H} ${INSTALL_DATA} ${_DISTDIR}/${DISTFILES:M*\:bashcomp:C/:.*//} \ @@ -45,4 +76,19 @@ post-install: (cd ${INSTALL_WRKSRC} && ${COPYTREE_SHARE} \ "${PORTDOCS}" ${STAGEDIR}${DOCSDIR}) +update-revision: +# https://developer.github.com/v3/repos/commits/#get-a-single-commit +# Pretend to be curl(1) for pretty-printed JSON to help parse with sed(1) + @${REINPLACE_CMD} -i '' -e "/^GH_REVISION.*$@/s/=.*/= $$(\ + ${SETENV} HTTP_USER_AGENT=curl ${FETCH_CMD} -qo- \ + https://api.github.com/repos/${GH_ACCOUNT}/${GH_PROJECT}/commits/${GH_TAGNAME} | \ + ${SED} -n '/sha/ { s/.*\"\([0-9a-f]\{12\}\).*/\1/p; q; }' \ + ) # generated by: make $@/" \ + ${.CURDIR}/Makefile + .include <bsd.port.mk> + +# XXX Work around !target(makesum) +.ifndef DISTVERSIONSUFFIX +makesum: update-revision +.endif diff --git a/devel/android-tools-adb/distinfo b/devel/android-tools-adb/distinfo index 7009150acd5b..f95fc4c8ec2c 100644 --- a/devel/android-tools-adb/distinfo +++ b/devel/android-tools-adb/distinfo @@ -1,4 +1,4 @@ -SHA256 (android-platform_system_core-android-5.1.1_r4_GH0.tar.gz) = 076421a742ef98158d5ea290b8aed007f2115521f1e39832d8be3560e990ea13 -SIZE (android-platform_system_core-android-5.1.1_r4_GH0.tar.gz) = 1210714 +SHA256 (android-platform_system_core-android-6.0.0_r1_GH0.tar.gz) = 3027e73c8f23d8348c76bc558987ecd10c07ed7c89b60a2a76be9e0ef7c84dd5 +SIZE (android-platform_system_core-android-6.0.0_r1_GH0.tar.gz) = 1186291 SHA256 (bash_completion.d/adb?id=2b8cfec) = 0d7989596a3e4937834d582eb0ddc88b8186505570772304fe51870d473916a7 SIZE (bash_completion.d/adb?id=2b8cfec) = 5198 diff --git a/devel/android-tools-adb/files/Makefile b/devel/android-tools-adb/files/Makefile index 330c0c4d99e4..292beacb4ff1 100644 --- a/devel/android-tools-adb/files/Makefile +++ b/devel/android-tools-adb/files/Makefile @@ -1,24 +1,46 @@ # $FreeBSD$ -PROG= adb +PROG_CXX=adb NO_MAN= BINDIR?=/usr/bin -SRCS+= adb.c -SRCS+= adb_client.c -SRCS+= adb_auth_host.c -SRCS+= commandline.c -SRCS+= console.c -SRCS+= file_sync_client.c -SRCS+= fdevent.c -SRCS+= get_my_path_freebsd.c -SRCS+= services.c -SRCS+= sockets.c -SRCS+= transport.c -SRCS+= transport_local.c -SRCS+= transport_usb.c -SRCS+= usb_libusb.c -SRCS+= usb_vendors.c +SRCS+= adb.cpp +SRCS+= adb_auth.cpp +SRCS+= adb_auth_host.cpp +SRCS+= adb_client.cpp +SRCS+= adb_io.cpp +SRCS+= adb_listeners.cpp +SRCS+= adb_main.cpp +SRCS+= adb_utils.cpp +SRCS+= commandline.cpp +SRCS+= console.cpp +SRCS+= fdevent.cpp +SRCS+= file_sync_client.cpp +SRCS+= services.cpp +SRCS+= sockets.cpp +SRCS+= transport.cpp +SRCS+= transport_local.cpp +SRCS+= transport_usb.cpp + +TEST_SRCS+= adb_io_test.cpp +TEST_SRCS+= adb_utils_test.cpp +TEST_SRCS+= transport_test.cpp + +.PATH: ${FILESDIR} +SRCS+= get_my_path_freebsd.cpp +SRCS+= usb_libusb.cpp + +.PATH: ${.CURDIR}/../base +SRCS+= file.cpp +SRCS+= logging.cpp +SRCS+= strings.cpp +SRCS+= stringprintf.cpp +TEST_SRCS+= file_test.cpp +TEST_SRCS+= logging_test.cpp +TEST_SRCS+= stringprintf_test.cpp +TEST_SRCS+= strings_test.cpp +TEST_SRCS+= test_main.cpp +TEST_SRCS+= test_utils.cpp .PATH: ${.CURDIR}/../libcutils SRCS+= socket_inaddr_any_server.c @@ -28,10 +50,13 @@ SRCS+= socket_loopback_client.c SRCS+= socket_loopback_server.c SRCS+= socket_network_client.c SRCS+= load_file.c +SRCS+= threads.c -.PATH: ${.CURDIR}/../libzipfile -SRCS+= centraldir.c -SRCS+= zipfile.c +# required by base/file.cpp +.PATH: ${.CURDIR}/../liblog +SRCS+= fake_log_device.c +SRCS+= logd_write.c +CPPFLAGS.logd_write.c+= -DFAKE_LOG_DEVICE=1 CPPFLAGS+= -DADB_HOST=1 CPPFLAGS+= -DHAVE_FORKEXEC=1 @@ -41,12 +66,27 @@ CPPFLAGS+= -DHAVE_SYS_SOCKET_H CPPFLAGS+= -D_FILE_OFFSET_BITS=64 CPPFLAGS+= -I${.CURDIR} CPPFLAGS+= -I${.CURDIR}/../include +CPPFLAGS+= -I${.CURDIR}/../base/include +CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}} +CXXFLAGS+= -std=gnu++11 .ifndef COMPILE.c CFLAGS+= ${CPPFLAGS} +CXXFLAGS+= ${CPPFLAGS} .endif +TEST_CPPFLAGS+= $$(${GTEST_CONFIG} --cppflags) +.for f in ${TEST_SRCS} +CPPFLAGS.${f}+= ${TEST_CPPFLAGS} +.endfor + LDADD+= -lcrypto -lpthread -lusb -lz DPADD+= ${LIBCRYPTO} ${LIBPTHREAD} ${LIBUSB} ${LIBZ} +TEST_LDADD+= $$(${GTEST_CONFIG} --libs --ldflags) + +GTEST_CONFIG?= gtest-config + +adb_test: ${SRCS:R:S/$/.o/:Nadb_main.o:Ncommandline.o} ${TEST_SRCS:R:S/$/.o/} + ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${LDFLAGS} -o $@ $> ${LDADD} ${TEST_LDADD} .include <bsd.prog.mk> diff --git a/devel/android-tools-adb/files/extra-patch-base_file__test.cpp b/devel/android-tools-adb/files/extra-patch-base_file__test.cpp new file mode 100644 index 000000000000..d0f287da3d7f --- /dev/null +++ b/devel/android-tools-adb/files/extra-patch-base_file__test.cpp @@ -0,0 +1,68 @@ +commit cf168a8 + cbf26b7 +Author: Spencer Low <CompareAndSwap@gmail.com> +Date: Mon Aug 3 20:43:24 2015 -0700 + + libbase_test: win32: get some tests working +[...] + - enh's edit to my previous change deleted a test that used + /proc/version, but I think another test was missed. Merge that test into + another. + +--- base/file_test.cpp.orig 2015-08-27 08:07:53 UTC ++++ base/file_test.cpp +@@ -34,16 +34,7 @@ TEST(file, ReadFileToString_ENOENT) { + EXPECT_EQ("", s); // s was cleared. + } + +-TEST(file, ReadFileToString_success) { +- std::string s("hello"); +- ASSERT_TRUE(android::base::ReadFileToString("/proc/version", &s)) << errno; +- EXPECT_GT(s.length(), 6U); +- EXPECT_EQ('\n', s[s.length() - 1]); +- s[5] = 0; +- EXPECT_STREQ("Linux", s.c_str()); +-} +- +-TEST(file, WriteStringToFile) { ++TEST(file, ReadFileToString_WriteStringToFile) { + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + ASSERT_TRUE(android::base::WriteStringToFile("abc", tf.filename)) << errno; +@@ -80,27 +71,20 @@ TEST(file, WriteStringToFd) { + EXPECT_EQ("abc", s); + } + +-TEST(file, ReadFully) { +- int fd = open("/proc/version", O_RDONLY); +- ASSERT_NE(-1, fd) << strerror(errno); +- +- char buf[1024]; +- memset(buf, 0, sizeof(buf)); +- ASSERT_TRUE(android::base::ReadFully(fd, buf, 5)); +- ASSERT_STREQ("Linux", buf); +- +- ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno); +- +- ASSERT_FALSE(android::base::ReadFully(fd, buf, sizeof(buf))); +- +- close(fd); +-} +- + TEST(file, WriteFully) { + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + ASSERT_TRUE(android::base::WriteFully(tf.fd, "abc", 3)); ++ ++ ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << errno; ++ + std::string s; +- ASSERT_TRUE(android::base::ReadFileToString(tf.filename, &s)) << errno; ++ s.resize(3); ++ ASSERT_TRUE(android::base::ReadFully(tf.fd, &s[0], s.size())) << errno; + EXPECT_EQ("abc", s); ++ ++ ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << errno; ++ ++ s.resize(1024); ++ ASSERT_FALSE(android::base::ReadFully(tf.fd, &s[0], s.size())); + } diff --git a/devel/android-tools-adb/files/get_my_path_freebsd.cpp b/devel/android-tools-adb/files/get_my_path_freebsd.cpp new file mode 100644 index 000000000000..c935adf1292a --- /dev/null +++ b/devel/android-tools-adb/files/get_my_path_freebsd.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009 bsdroid project + * Alexey Tarasov <tarasov@dodologics.com> + * + * Copyright (C) 2007 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 <sys/types.h> +#include <sys/sysctl.h> +#include <unistd.h> + +void +get_my_path(char *exe, size_t maxLen) +{ + int mib[4] = { + CTL_KERN, + KERN_PROC, + KERN_PROC_PATHNAME, + getpid() + }; + + sysctl(mib, 4, exe, &maxLen, NULL, 0); +} diff --git a/devel/android-tools-adb-devel/files/patch-adb_adb__io__test.cpp b/devel/android-tools-adb/files/patch-adb_adb__io__test.cpp index 5473120eff45..5473120eff45 100644 --- a/devel/android-tools-adb-devel/files/patch-adb_adb__io__test.cpp +++ b/devel/android-tools-adb/files/patch-adb_adb__io__test.cpp diff --git a/devel/android-tools-adb-devel/files/patch-adb_commandline.cpp b/devel/android-tools-adb/files/patch-adb_commandline.cpp index 20e9bea6545d..20e9bea6545d 100644 --- a/devel/android-tools-adb-devel/files/patch-adb_commandline.cpp +++ b/devel/android-tools-adb/files/patch-adb_commandline.cpp diff --git a/devel/android-tools-adb-devel/files/patch-base_file.cpp b/devel/android-tools-adb/files/patch-base_file.cpp index 29638851e71d..29638851e71d 100644 --- a/devel/android-tools-adb-devel/files/patch-base_file.cpp +++ b/devel/android-tools-adb/files/patch-base_file.cpp diff --git a/devel/android-tools-adb-devel/files/patch-base_include_base_logging.h b/devel/android-tools-adb/files/patch-base_include_base_logging.h index 4770e9e0b411..4770e9e0b411 100644 --- a/devel/android-tools-adb-devel/files/patch-base_include_base_logging.h +++ b/devel/android-tools-adb/files/patch-base_include_base_logging.h diff --git a/devel/android-tools-adb-devel/files/patch-base_logging.cpp b/devel/android-tools-adb/files/patch-base_logging.cpp index 53bf6fdd0537..53bf6fdd0537 100644 --- a/devel/android-tools-adb-devel/files/patch-base_logging.cpp +++ b/devel/android-tools-adb/files/patch-base_logging.cpp diff --git a/devel/android-tools-adb-devel/files/patch-base_stringprintf__test.cpp b/devel/android-tools-adb/files/patch-base_stringprintf__test.cpp index a367b9d5c540..a367b9d5c540 100644 --- a/devel/android-tools-adb-devel/files/patch-base_stringprintf__test.cpp +++ b/devel/android-tools-adb/files/patch-base_stringprintf__test.cpp diff --git a/devel/android-tools-adb/files/patch-commandline.c b/devel/android-tools-adb/files/patch-commandline.c deleted file mode 100644 index 9f86db94645f..000000000000 --- a/devel/android-tools-adb/files/patch-commandline.c +++ /dev/null @@ -1,24 +0,0 @@ ---- commandline.c.orig 2014-09-27 22:55:45.000000000 +0800 -+++ commandline.c 2014-09-27 22:58:14.000000000 +0800 -@@ -591,7 +591,7 @@ - - // copy args - ppp_args = (const char **) alloca(sizeof(char *) * argc + 1); -- ppp_args[0] = "pppd"; -+ ppp_args[0] = "ppp"; - for (i = 2 ; i < argc ; i++) { - //argv[2] and beyond become ppp_args[1] and beyond - ppp_args[i - 1] = argv[i]; -@@ -605,10 +605,10 @@ - adb_close(STDERR_FILENO); - adb_close(fd); - -- err = execvp("pppd", (char * const *)ppp_args); -+ err = execvp("ppp", (char * const *)ppp_args); - - if (err < 0) { -- perror("execing pppd"); -+ perror("execing ppp"); - } - exit(-1); - } else { diff --git a/devel/android-tools-adb/files/patch-get_my_path_freebsd.c b/devel/android-tools-adb/files/patch-get_my_path_freebsd.c deleted file mode 100644 index 6a212df3f0ed..000000000000 --- a/devel/android-tools-adb/files/patch-get_my_path_freebsd.c +++ /dev/null @@ -1,30 +0,0 @@ ---- get_my_path_freebsd.c.orig 2013-09-03 17:33:27.000000000 +0800 -+++ get_my_path_freebsd.c 2013-09-03 17:41:13.000000000 +0800 -@@ -18,19 +18,18 @@ - */ - - #include <sys/types.h> -+#include <sys/sysctl.h> - #include <unistd.h> --#include <limits.h> --#include <stdio.h> - - void - get_my_path(char *exe, size_t maxLen) - { -- char proc[64]; -+ int mib[4] = { -+ CTL_KERN, -+ KERN_PROC, -+ KERN_PROC_PATHNAME, -+ getpid() -+ }; - -- snprintf(proc, sizeof(proc), "/proc/%d/file", getpid()); -- -- int err = readlink(proc, exe, maxLen - 1); -- -- exe[err > 0 ? err : 0] = '\0'; -+ sysctl(mib, 4, exe, &maxLen, NULL, 0); - } -- diff --git a/devel/android-tools-adb-devel/files/patch-libcutils_threads.c b/devel/android-tools-adb/files/patch-libcutils_threads.c index a275276f095d..a275276f095d 100644 --- a/devel/android-tools-adb-devel/files/patch-libcutils_threads.c +++ b/devel/android-tools-adb/files/patch-libcutils_threads.c diff --git a/devel/android-tools-adb-devel/files/patch-liblog_logd__write.c b/devel/android-tools-adb/files/patch-liblog_logd__write.c index d9a8890325d4..d9a8890325d4 100644 --- a/devel/android-tools-adb-devel/files/patch-liblog_logd__write.c +++ b/devel/android-tools-adb/files/patch-liblog_logd__write.c diff --git a/devel/android-tools-adb/files/patch-usb_libusb.c b/devel/android-tools-adb/files/patch-usb_libusb.c deleted file mode 100644 index 0c39a437a9d8..000000000000 --- a/devel/android-tools-adb/files/patch-usb_libusb.c +++ /dev/null @@ -1,24 +0,0 @@ ---- usb_libusb.c.orig 2013-08-01 17:14:17.000000000 +0800 -+++ usb_libusb.c 2013-08-01 17:14:46.000000000 +0800 -@@ -37,7 +37,7 @@ - #define TRACE_TAG TRACE_USB - #include "adb.h" - --static adb_mutex_t usb_lock = ADB_MUTEX_INITIALIZER; -+ADB_MUTEX_DEFINE( usb_lock ); - static libusb_context *ctx = NULL; - - struct usb_handle -@@ -347,7 +347,11 @@ register_device(struct usb_handle *uh, c - - adb_mutex_unlock(&usb_lock); - -- register_usb_transport(usb, serial, NULL, 1); -+ char devpath[64]; -+ snprintf(devpath, sizeof(devpath), "ugen%d.%d", -+ uh->dev_bus, uh->dev_addr); -+ -+ register_usb_transport(usb, serial, devpath, 1); - - return (1); - } diff --git a/devel/android-tools-adb/files/usb_libusb.cpp b/devel/android-tools-adb/files/usb_libusb.cpp new file mode 100644 index 000000000000..b7033259d8c5 --- /dev/null +++ b/devel/android-tools-adb/files/usb_libusb.cpp @@ -0,0 +1,656 @@ +/* + * Copyright (C) 2009 bsdroid project + * Alexey Tarasov <tarasov@dodologics.com> + * + * Copyright (C) 2007 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. + */ + +#define TRACE_TAG TRACE_USB + +#include "sysdeps.h" + +#include <libusb.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "adb.h" +#include "transport.h" + +ADB_MUTEX_DEFINE( usb_lock ); +static libusb_context *ctx = NULL; + +struct usb_handle +{ + usb_handle *prev; + usb_handle *next; + + libusb_device *dev; + libusb_device_handle *devh; + int interface; + uint8_t dev_bus; + uint8_t dev_addr; + + int zero_mask; + unsigned char end_point_address[2]; + char serial[128]; + + adb_cond_t notify; + adb_mutex_t lock; +}; + +static usb_handle handle_list = { + .prev = &handle_list, + .next = &handle_list, +}; + +void +usb_cleanup() +{ + libusb_exit(ctx); +} + +static void +report_bulk_libusb_error(int r) +{ + switch (r) { + case LIBUSB_ERROR_TIMEOUT: + D("Transfer timeout"); + break; + + case LIBUSB_ERROR_PIPE: + D("Control request is not supported"); + break; + + case LIBUSB_ERROR_OVERFLOW: + D("Device offered more data"); + break; + + case LIBUSB_ERROR_NO_DEVICE : + D("Device was disconnected"); + break; + + default: + D("Error %d during transfer", r); + break; + }; +} + +static int +usb_bulk_write(usb_handle *uh, const void *data, int len) +{ + int r = 0; + int transferred = 0; + + r = libusb_bulk_transfer(uh->devh, uh->end_point_address[1], + (unsigned char *)data, len, &transferred, 0); + + if (r != 0) { + D("usb_bulk_write(): "); + report_bulk_libusb_error(r); + return r; + } + + return (transferred); +} + +static int +usb_bulk_read(usb_handle *uh, void *data, int len) +{ + int r = 0; + int transferred = 0; + + r = libusb_bulk_transfer(uh->devh, uh->end_point_address[0], + (unsigned char *)data, len, + &transferred, 0); + + if (r != 0) { + D("usb_bulk_read(): "); + report_bulk_libusb_error(r); + return r; + } + + return (transferred); +} + +int +usb_write(usb_handle *uh, const void *_data, int len) +{ + unsigned char *data = (unsigned char*) _data; + int n; + int need_zero = 0; + + if (uh->zero_mask == 1) { + if (!(len & uh->zero_mask)) { + need_zero = 1; + } + } + + D("usb_write(): %p:%d -> transport %p", _data, len, uh); + + while (len > 0) { + int xfer = (len > 4096) ? 4096 : len; + + n = usb_bulk_write(uh, data, xfer); + + if (n != xfer) { + D("usb_write(): failed for transport %p (%d bytes left)", uh, len); + return -1; + } + + len -= xfer; + data += xfer; + } + + if (need_zero){ + n = usb_bulk_write(uh, _data, 0); + + if (n < 0) { + D("usb_write(): failed to finish operation for transport %p", uh); + } + return n; + } + + return 0; +} + +int +usb_read(usb_handle *uh, void *_data, int len) +{ + unsigned char *data = (unsigned char*)_data; + int n; + + D("usb_read(): %p:%d <- transport %p", _data, len, uh); + + while (len > 0) { + int xfer = (len > 4096) ? 4096 : len; + + n = usb_bulk_read(uh, data, xfer); + + if (n != xfer) { + if (n > 0) { + data += n; + len -= n; + continue; + } + + D("usb_read(): failed for transport %p (%d bytes left)", uh, len); + return -1; + } + + len -= xfer; + data += xfer; + } + + return 0; +} + +int +usb_close(usb_handle *h) +{ + D("usb_close(): closing transport %p", h); + adb_mutex_lock(&usb_lock); + + h->next->prev = h->prev; + h->prev->next = h->next; + h->prev = NULL; + h->next = NULL; + + libusb_release_interface(h->devh, h->interface); + libusb_close(h->devh); + libusb_unref_device(h->dev); + + adb_mutex_unlock(&usb_lock); + + free(h); + + return (0); +} + +void +usb_kick(usb_handle *h) +{ + D("usb_kick(): kicking transport %p", h); + + adb_mutex_lock(&h->lock); + unregister_usb_transport(h); + adb_mutex_unlock(&h->lock); + + h->next->prev = h->prev; + h->prev->next = h->next; + h->prev = NULL; + h->next = NULL; + + libusb_release_interface(h->devh, h->interface); + libusb_close(h->devh); + libusb_unref_device(h->dev); + free(h); +} + +static int +check_usb_interface(libusb_interface const *interface, + libusb_device_descriptor const *desc, + usb_handle *uh) +{ + int e; + + if (interface->num_altsetting == 0) { + D("check_usb_interface(): No interface settings"); + return -1; + } + + libusb_interface_descriptor const *idesc = &interface->altsetting[0]; + + if (idesc->bNumEndpoints != 2) { + D("check_usb_interface(): Interface have not 2 endpoints, ignoring"); + return -1; + } + + for (e = 0; e < idesc->bNumEndpoints; e++) { + libusb_endpoint_descriptor const *edesc = &idesc->endpoint[e]; + + if (edesc->bmAttributes != LIBUSB_TRANSFER_TYPE_BULK) { + D("check_usb_interface(): Endpoint (%u) is not bulk (%u), ignoring", + edesc->bmAttributes, LIBUSB_TRANSFER_TYPE_BULK); + return -1; + } + + if (edesc->bEndpointAddress & LIBUSB_ENDPOINT_IN) + uh->end_point_address[0] = edesc->bEndpointAddress; + else + uh->end_point_address[1] = edesc->bEndpointAddress; + + /* aproto 01 needs 0 termination */ + if (idesc->bInterfaceProtocol == 0x01) { + uh->zero_mask = edesc->wMaxPacketSize - 1; + D("check_usb_interface(): Forced Android interface protocol v.1"); + } + } + + D("check_usb_interface(): Device: %04x:%04x " + "iclass: %x, isclass: %x, iproto: %x ep: %x/%x-> ", + desc->idVendor, desc->idProduct, idesc->bInterfaceClass, + idesc->bInterfaceSubClass, idesc->bInterfaceProtocol, + uh->end_point_address[0], uh->end_point_address[1]); + + if (!is_adb_interface(desc->idVendor, desc->idProduct, + idesc->bInterfaceClass, idesc->bInterfaceSubClass, + idesc->bInterfaceProtocol)) + { + D("not matches"); + return -1; + } + + D("matches"); + return 1; +} + +static int +check_usb_interfaces(libusb_config_descriptor *config, + libusb_device_descriptor *desc, + usb_handle *uh) +{ + int i; + + for (i = 0; i < config->bNumInterfaces; ++i) { + if (check_usb_interface(&config->interface[i], desc, uh) != -1) { + /* found some interface and saved information about it */ + D("check_usb_interfaces(): Interface %d of %04x:%04x " + "matches Android device", i, desc->idVendor, + desc->idProduct); + + return i; + } + } + + return -1; +} + +static int +register_device(usb_handle *uh, const char *serial) +{ + D("register_device(): Registering %p [%s] as USB transport", + uh, serial); + + usb_handle* usb = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle))); + if (usb == nullptr) fatal("couldn't allocate usb_handle"); + memcpy(usb, uh, sizeof(usb_handle)); + strcpy(usb->serial, uh->serial); + + adb_cond_init(&usb->notify, 0); + adb_mutex_init(&usb->lock, 0); + + adb_mutex_lock(&usb_lock); + + usb->next = &handle_list; + usb->prev = handle_list.prev; + usb->prev->next = usb; + usb->next->prev = usb; + + adb_mutex_unlock(&usb_lock); + + char devpath[64]; + snprintf(devpath, sizeof(devpath), "ugen%d.%d", + uh->dev_bus, uh->dev_addr); + + register_usb_transport(usb, serial, devpath, 1); + + return (1); +} + +static int +already_registered(usb_handle *uh) +{ + usb_handle *usb = NULL; + int exists = 0; + + adb_mutex_lock(&usb_lock); + + for (usb = handle_list.next; usb != &handle_list; usb = usb->next) { + if ((usb->dev_bus == uh->dev_bus) && + (usb->dev_addr == uh->dev_addr)) + { + exists = 1; + break; + } + } + + adb_mutex_unlock(&usb_lock); + + return exists; +} + +static void +check_device(libusb_device *dev) +{ + usb_handle uh; + int i = 0; + int found = -1; + char serial[256] = {0}; + + libusb_device_descriptor desc; + libusb_config_descriptor *config = NULL; + + int r = libusb_get_device_descriptor(dev, &desc); + + if (r != LIBUSB_SUCCESS) { + D("check_device(): Failed to get device descriptor"); + return; + } + + if ((desc.idVendor == 0) && (desc.idProduct == 0)) + return; + + D("check_device(): Probing usb device %04x:%04x", + desc.idVendor, desc.idProduct); + + if (!is_adb_interface(desc.idVendor, desc.idProduct, + ADB_CLASS, ADB_SUBCLASS, ADB_PROTOCOL)) + { + D("check_device(): Ignored due unknown vendor id"); + return; + } + + uh.dev_bus = libusb_get_bus_number(dev); + uh.dev_addr = libusb_get_device_address(dev); + + if (already_registered(&uh)) { + D("check_device(): Device (bus: %d, address: %d) " + "is already registered", uh.dev_bus, uh.dev_addr); + return; + } + + D("check_device(): Device bus: %d, address: %d", + uh.dev_bus, uh.dev_addr); + + r = libusb_get_active_config_descriptor(dev, &config); + + if (r != 0) { + if (r == LIBUSB_ERROR_NOT_FOUND) { + D("check_device(): Device %4x:%4x is unconfigured", + desc.idVendor, desc.idProduct); + return; + } + + D("check_device(): Failed to get configuration for %4x:%4x", + desc.idVendor, desc.idProduct); + return; + } + + if (config == NULL) { + D("check_device(): Sanity check failed after " + "getting active config"); + return; + } + + if (config->interface != NULL) { + found = check_usb_interfaces(config, &desc, &uh); + } + + /* not needed anymore */ + libusb_free_config_descriptor(config); + + r = libusb_open(dev, &uh.devh); + uh.dev = dev; + + if (r != 0) { + switch (r) { + case LIBUSB_ERROR_NO_MEM: + D("check_device(): Memory allocation problem"); + break; + + case LIBUSB_ERROR_ACCESS: + D("check_device(): Permissions problem, " + "current user priveleges are messed up?"); + break; + + case LIBUSB_ERROR_NO_DEVICE: + D("check_device(): Device disconected, bad cable?"); + break; + + default: + D("check_device(): libusb triggered error %d", r); + } + // skip rest + found = -1; + } + + if (found >= 0) { + D("check_device(): Device matches Android interface"); + // read the device's serial number + memset(serial, 0, sizeof(serial)); + uh.interface = found; + + r = libusb_claim_interface(uh.devh, uh.interface); + + if (r < 0) { + D("check_device(): Failed to claim interface %d", + uh.interface); + + goto fail; + } + + if (desc.iSerialNumber) { + // reading serial + uint16_t buffer[128] = {0}; + uint16_t languages[128] = {0}; + int languageCount = 0; + + memset(languages, 0, sizeof(languages)); + r = libusb_control_transfer(uh.devh, + LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE, + LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_DT_STRING << 8, + 0, (uint8_t *)languages, sizeof(languages), 0); + + if (r <= 0) { + D("check_device(): Failed to get languages count"); + goto fail; + } + + languageCount = (r - 2) / 2; + + for (i = 1; i <= languageCount; ++i) { + memset(buffer, 0, sizeof(buffer)); + + r = libusb_control_transfer(uh.devh, + LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE, + LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc.iSerialNumber, + languages[i], (uint8_t *)buffer, sizeof(buffer), 0); + + if (r > 0) { /* converting serial */ + int j = 0; + r /= 2; + + for (j = 1; j < r; ++j) + serial[j - 1] = buffer[j]; + + serial[j - 1] = '\0'; + break; /* languagesCount cycle */ + } + } + + if (register_device(&uh, serial) == 0) { + D("check_device(): Failed to register device"); + goto fail_interface; + } + + libusb_ref_device(dev); + } + } + + return; + +fail_interface: + libusb_release_interface(uh.devh, uh.interface); + +fail: + libusb_close(uh.devh); + uh.devh = NULL; +} + +static int +check_device_connected(usb_handle *uh) +{ + int r = libusb_kernel_driver_active(uh->devh, uh->interface); + + if (r == LIBUSB_ERROR_NO_DEVICE) + return 0; + + if (r < 0) + return -1; + + return 1; +} + +static void +kick_disconnected() +{ + usb_handle *usb = NULL; + + adb_mutex_lock(&usb_lock); + + for (usb = handle_list.next; usb != &handle_list; usb = usb->next) { + if (check_device_connected(usb) == 0) { + D("kick_disconnected(): Transport %p is not online anymore", + usb); + + usb_kick(usb); + } + } + + adb_mutex_unlock(&usb_lock); +} + +static void +scan_usb_devices() +{ + D("scan_usb_devices(): started"); + + libusb_device **devs= NULL; + libusb_device *dev= NULL; + ssize_t cnt = libusb_get_device_list(ctx, &devs); + + if (cnt < 0) { + D("scan_usb_devices(): Failed to get device list (error: %zd)", + cnt); + + return; + } + + int i = 0; + + while ((dev = devs[i++]) != NULL) { + check_device(dev); + } + + libusb_free_device_list(devs, 1); +} + +static void * +device_poll_thread(void* unused) +{ + D("device_poll_thread(): Created USB scan thread"); + + for (;;) { + sleep(5); + kick_disconnected(); + scan_usb_devices(); + } + + /* never reaching this point */ + return (NULL); +} + +static void +sigalrm_handler(int signo) +{ + /* nothing */ +} + +void +usb_init() +{ + D("usb_init(): started"); + adb_thread_t tid; + struct sigaction actions; + + atexit(usb_cleanup); + int r = libusb_init(&ctx); + + if (r != LIBUSB_SUCCESS) { + fatal_errno("Failed to init libusb"); + } + + memset(&actions, 0, sizeof(actions)); + + sigemptyset(&actions.sa_mask); + + actions.sa_flags = 0; + actions.sa_handler = sigalrm_handler; + + sigaction(SIGALRM, &actions, NULL); + + /* initial device scan */ + scan_usb_devices(); + + /* starting USB event polling thread */ + if (adb_thread_create(&tid, device_poll_thread, nullptr)) { + fatal_errno("cannot create USB scan thread"); + } + + D("usb_init(): finished"); +} diff --git a/devel/android-tools-fastboot-devel/Makefile b/devel/android-tools-fastboot-devel/Makefile index 0ac7bd4f6dfc..b31d46787830 100644 --- a/devel/android-tools-fastboot-devel/Makefile +++ b/devel/android-tools-fastboot-devel/Makefile @@ -13,10 +13,5 @@ CONFLICTS_INSTALL= ${PORTNAME}-[0-9]* MASTERDIR= ${.CURDIR}/../android-tools-fastboot DISTINFO_FILE= ${.CURDIR}/distinfo -FILESDIR= ${.CURDIR}/files -EXTRA_PATCHES+= ${.CURDIR}/files/patch-* - -USES= compiler:c++11-lib -CPPFLAGS+= -DFASTBOOT_REVISION='\"${DISTVERSIONSUFFIX:S/-g//}-android\"' .include "${MASTERDIR}/Makefile" diff --git a/devel/android-tools-fastboot-devel/files/patch-ext4__utils_ext4__utils.c b/devel/android-tools-fastboot-devel/files/patch-ext4__utils_ext4__utils.c deleted file mode 100644 index 7df08e5904c9..000000000000 --- a/devel/android-tools-fastboot-devel/files/patch-ext4__utils_ext4__utils.c +++ /dev/null @@ -1,22 +0,0 @@ -Avoid conflict with slightly different |struct uuid| in <sys/uuid.h>. - - ext4_utils/ext4_utils.c:64:8: error: redefinition of 'struct uuid' - struct uuid { - ^ - In file included from /usr/include/sys/disklabel.h:47:0, - from /usr/include/sys/diskslice.h:70, - from ext4_utils/ext4_utils.c:53: - /usr/include/sys/uuid.h:45:8: note: originally defined here - struct uuid { - ^ - ---- ext4_utils/ext4_utils.c.orig 2015-07-18 11:53:50 UTC -+++ ext4_utils/ext4_utils.c -@@ -53,6 +61,7 @@ struct sparse_file *ext4_sparse_file; - jmp_buf setjmp_env; - - /* Definition from RFC-4122 */ -+#define uuid ext4_uuid - struct uuid { - u32 time_low; - u16 time_mid; diff --git a/devel/android-tools-fastboot-devel/files/pkg-message.in b/devel/android-tools-fastboot-devel/files/pkg-message.in deleted file mode 100644 index 32713248181a..000000000000 --- a/devel/android-tools-fastboot-devel/files/pkg-message.in +++ /dev/null @@ -1,7 +0,0 @@ -The port installed fastboot(1) under %%PREFIX%%/bin. However, there's -a different fastboot(8) under /sbin. To avoid accidentally invoking -the wrong command make sure either to - -- adjust PATH environment variable to have fastboot(1) found first -- create a shell alias with absolute path to fastboot(1) -- create a symlink with different name in PATH e.g., under ~/bin diff --git a/devel/android-tools-fastboot/Makefile b/devel/android-tools-fastboot/Makefile index 87d8defbd0d1..9a6f978ebb1f 100644 --- a/devel/android-tools-fastboot/Makefile +++ b/devel/android-tools-fastboot/Makefile @@ -2,8 +2,8 @@ PORTNAME= android-tools-fastboot DISTVERSIONPREFIX= android- -DISTVERSION?= 5.1.1_r4 -PORTREVISION?= 5 +DISTVERSION?= 6.0.0_r1 +PORTREVISION?= 0 CATEGORIES= devel MASTER_SITES= https://anonscm.debian.org/cgit/android-tools/android-tools.git/plain/debian/:bashcomp,manpage DISTFILES= bash_completion.d/fastboot?id=2b8cfec:bashcomp \ @@ -26,15 +26,23 @@ GH_ACCOUNT= android jbeich:extras,libselinux GH_PROJECT= platform_system_core platform_system_extras:extras \ platform_external_libselinux:libselinux +# Emulate GH_COMMIT without causing desync +.ifdef DISTVERSIONSUFFIX +GH_REVISION= ${DISTVERSIONSUFFIX:S/-g//} # snapshot +.else +GH_REVISION= bb0c180e6270 # generated by: make update-revision +.endif + CONFLICTS_INSTALL?= ${PORTNAME}-devel-* -USES+= localbase uidfix +USES= compiler:c++11-lib localbase uidfix BUILD_WRKSRC= ${WRKSRC}/fastboot INSTALL_WRKSRC= ${BUILD_WRKSRC} -MAKEFILE= ${FILESDIR}/Makefile +MAKEFILE= ${.CURDIR}/files/Makefile # XXX ?= when bmake-only MAKE_ENV= FILESDIR="${FILESDIR}" BINDIR="${PREFIX}/bin" \ MANDIR="${PREFIX}/man/man" \ LIBPCRE="${LOCALBASE}/lib/libpcre.a" +CPPFLAGS+= -DFASTBOOT_REVISION='\"${GH_REVISION}-android\"' PLIST_FILES= bin/fastboot \ %%BASH%%etc/bash_completion.d/fastboot \ man/man1/fastboot.1.gz @@ -60,4 +68,19 @@ post-install: (cd ${INSTALL_WRKSRC} && ${COPYTREE_SHARE} \ "${PORTDOCS}" ${STAGEDIR}${DOCSDIR}) +update-revision: +# https://developer.github.com/v3/repos/commits/#get-a-single-commit +# Pretend to be curl(1) for pretty-printed JSON to help parse with sed(1) + @${REINPLACE_CMD} -i '' -e "/^GH_REVISION.*$@/s/=.*/= $$(\ + ${SETENV} HTTP_USER_AGENT=curl ${FETCH_CMD} -qo- \ + https://api.github.com/repos/${GH_ACCOUNT}/${GH_PROJECT}/commits/${GH_TAGNAME} | \ + ${SED} -n '/sha/ { s/.*\"\([0-9a-f]\{12\}\).*/\1/p; q; }' \ + ) # generated by: make $@/" \ + ${.CURDIR}/Makefile + .include <bsd.port.mk> + +# XXX Work around !target(makesum) +.ifndef DISTVERSIONSUFFIX +makesum: update-revision +.endif diff --git a/devel/android-tools-fastboot/distinfo b/devel/android-tools-fastboot/distinfo index a4b3e132c329..f395a986c52e 100644 --- a/devel/android-tools-fastboot/distinfo +++ b/devel/android-tools-fastboot/distinfo @@ -2,9 +2,9 @@ SHA256 (bash_completion.d/fastboot?id=2b8cfec) = 12ef37bff8230e5e164e4ef5b9c1be1 SIZE (bash_completion.d/fastboot?id=2b8cfec) = 3051 SHA256 (fastboot.1?id=706e754) = 2af01b064440952a82f1602691a0fecc030302722a71444946fb70d9c423d283 SIZE (fastboot.1?id=706e754) = 5906 -SHA256 (android-platform_system_core-android-5.1.1_r4_GH0.tar.gz) = 076421a742ef98158d5ea290b8aed007f2115521f1e39832d8be3560e990ea13 -SIZE (android-platform_system_core-android-5.1.1_r4_GH0.tar.gz) = 1210714 -SHA256 (jbeich-platform_system_extras-android-5.1.1_r4_GH0.tar.gz) = 43230a03c166b4000336a3bf13a73b91b69b672a9522efcd6d346cdc7e52e154 -SIZE (jbeich-platform_system_extras-android-5.1.1_r4_GH0.tar.gz) = 282780 -SHA256 (jbeich-platform_external_libselinux-android-5.1.1_r4_GH0.tar.gz) = 81bda8ddee4830c62415f308eaea85736b0c2c02324801fe67a712ce192360df -SIZE (jbeich-platform_external_libselinux-android-5.1.1_r4_GH0.tar.gz) = 49185 +SHA256 (android-platform_system_core-android-6.0.0_r1_GH0.tar.gz) = 3027e73c8f23d8348c76bc558987ecd10c07ed7c89b60a2a76be9e0ef7c84dd5 +SIZE (android-platform_system_core-android-6.0.0_r1_GH0.tar.gz) = 1186291 +SHA256 (jbeich-platform_system_extras-android-6.0.0_r1_GH0.tar.gz) = 84877e2e17a57a2832b6992073691124ad817b013132594313f3e74f8c32aa39 +SIZE (jbeich-platform_system_extras-android-6.0.0_r1_GH0.tar.gz) = 650275 +SHA256 (jbeich-platform_external_libselinux-android-6.0.0_r1_GH0.tar.gz) = ed9ad172dd78591d4f0400c092d8151154a75cc244b6c53ccbb3ae0b165322e4 +SIZE (jbeich-platform_external_libselinux-android-6.0.0_r1_GH0.tar.gz) = 50961 diff --git a/devel/android-tools-fastboot/files/Makefile b/devel/android-tools-fastboot/files/Makefile index 72eadb098245..8426d4af708d 100644 --- a/devel/android-tools-fastboot/files/Makefile +++ b/devel/android-tools-fastboot/files/Makefile @@ -1,19 +1,24 @@ # $FreeBSD$ -PROG= fastboot +PROG_CXX=fastboot BINDIR?=/usr/bin -SRCS+= bootimg.c +SRCS+= bootimg_utils.cpp SRCS+= engine.c -SRCS+= fastboot.c +SRCS+= fastboot.cpp SRCS+= fs.c SRCS+= protocol.c SRCS+= util.c .PATH: ${FILESDIR} -SRCS+= usb_freebsd.c -SRCS+= util_freebsd.c +SRCS+= usb_freebsd.cpp +SRCS+= util_freebsd.cpp +# required by libziparchive +.PATH: ${.CURDIR}/../base +SRCS+= file.cpp + +# required by fastboot .PATH: ${.CURDIR}/../ext4_utils SRCS+= allocate.c SRCS+= contents.c @@ -25,9 +30,15 @@ SRCS+= extent.c SRCS+= indirect.c SRCS+= make_ext4fs.c SRCS+= sha1.c -SRCS+= uuid.c SRCS+= wipe.c +# required by base and libutils +.PATH: ${.CURDIR}/../liblog +SRCS+= fake_log_device.c +SRCS+= logd_write.c +CPPFLAGS.logd_write.c+= -DFAKE_LOG_DEVICE=1 + +# required by ext4_utils .PATH: ${.CURDIR}/../libselinux/src SRCS+= callbacks.c SRCS+= check_context.c @@ -38,6 +49,7 @@ SRCS+= label_android_property.c SRCS+= label_file.c CPPFLAGS.init.c+= -DDARWIN # statfs +# required by fastboot and ext4_utils .PATH: ${.CURDIR}/../libsparse SRCS+= backed_block.c SRCS+= output_file.c @@ -46,27 +58,34 @@ SRCS+= sparse_crc32.c SRCS+= sparse_err.c SRCS+= sparse_read.c -.PATH: ${.CURDIR}/../libzipfile -SRCS+= centraldir.c -SRCS+= zipfile.c -CPPFLAGS.centraldir.c+= -Ulseek64 # utils/Compat.h +# required by libziparchive +.PATH: ${.CURDIR}/../libutils +SRCS+= FileMap.cpp + +# required by fastboot +.PATH: ${.CURDIR}/../libziparchive +SRCS+= zip_archive.cc -CPPFLAGS+= -D_FILE_OFFSET_BITS=64 # utils/Compat.h CPPFLAGS+= -Doff64_t=off_t CPPFLAGS+= -Dftruncate64=ftruncate CPPFLAGS+= -Dlseek64=lseek CPPFLAGS+= -Dmmap64=mmap +CPPFLAGS+= -Dpread64=pread CPPFLAGS+= -I${.CURDIR} CPPFLAGS+= -I${.CURDIR}/../include CPPFLAGS+= -I${.CURDIR}/../mkbootimg +CPPFLAGS+= -I${.CURDIR}/../base/include CPPFLAGS+= -I${.CURDIR}/../ext4_utils CPPFLAGS+= -I${.CURDIR}/../f2fs_utils CPPFLAGS+= -I${.CURDIR}/../libselinux/include CPPFLAGS+= -I${.CURDIR}/../libsparse/include CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}} +CXXFLAGS+= -D__STDC_LIMIT_MACROS # DragonFly +CXXFLAGS+= -std=gnu++11 .ifndef COMPILE.c CFLAGS+= ${CPPFLAGS} +CXXFLAGS+= ${CPPFLAGS} .endif LDADD+= -lpcre -lusb -lz diff --git a/devel/android-tools-fastboot-devel/files/patch-base_file.cpp b/devel/android-tools-fastboot/files/patch-base_file.cpp index 29638851e71d..29638851e71d 100644 --- a/devel/android-tools-fastboot-devel/files/patch-base_file.cpp +++ b/devel/android-tools-fastboot/files/patch-base_file.cpp diff --git a/devel/android-tools-fastboot/files/patch-ext4__utils_ext4__utils.c b/devel/android-tools-fastboot/files/patch-ext4__utils_ext4__utils.c index a5b8fe96dd5f..842ee8d8a484 100644 --- a/devel/android-tools-fastboot/files/patch-ext4__utils_ext4__utils.c +++ b/devel/android-tools-fastboot/files/patch-ext4__utils_ext4__utils.c @@ -18,6 +18,15 @@ #endif #include "ext4.h" +@@ -53,6 +61,8 @@ struct sparse_file *ext4_sparse_file; + jmp_buf setjmp_env; + + /* Definition from RFC-4122 */ ++/* XXX <sys/uuid.h> defines slightly different |struct uuid| */ ++#define uuid ext4_uuid + struct uuid { + u32 time_low; + u16 time_mid; @@ -383,10 +391,24 @@ static u64 get_block_device_size(int fd) u64 size = 0; int ret; diff --git a/devel/android-tools-fastboot-devel/files/patch-liblog_logd__write.c b/devel/android-tools-fastboot/files/patch-liblog_logd__write.c index d9a8890325d4..d9a8890325d4 100644 --- a/devel/android-tools-fastboot-devel/files/patch-liblog_logd__write.c +++ b/devel/android-tools-fastboot/files/patch-liblog_logd__write.c diff --git a/devel/android-tools-fastboot/files/usb_freebsd.c b/devel/android-tools-fastboot/files/usb_freebsd.c deleted file mode 100644 index c21a0bea6f8a..000000000000 --- a/devel/android-tools-fastboot/files/usb_freebsd.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2011 Hans Petter Selasky. 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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libusb.h> - -#include "usb.h" - -struct usb_handle { - libusb_device_handle *handle; - libusb_device *dev; - unsigned char ep_in; - unsigned char ep_out; - unsigned char iface; -}; - -static int -probe(struct usb_handle *h, ifc_match_func callback) -{ - struct usb_ifc_info info; - struct libusb_device_descriptor ddesc; - struct libusb_config_descriptor *pcfg; - int i, j; - - if (libusb_open(h->dev, &h->handle) < 0) - return (-1); - - if (libusb_get_device_descriptor(h->dev, &ddesc) < 0) { - libusb_close(h->handle); - return (-1); - } - memset(&info, 0, sizeof(info)); - - info.dev_vendor = ddesc.idVendor; - info.dev_product = ddesc.idProduct; - info.dev_class = ddesc.bDeviceClass; - info.dev_subclass = ddesc.bDeviceSubClass; - info.dev_protocol = ddesc.bDeviceProtocol; - info.writable = 1; - - snprintf(info.device_path, sizeof(info.device_path), "ugen%d.%d", - libusb_get_bus_number(h->dev), libusb_get_device_address(h->dev)); - - if (ddesc.iSerialNumber != 0) { - libusb_get_string_descriptor_ascii(h->handle, ddesc.iSerialNumber, - (unsigned char *)info.serial_number, sizeof(info.serial_number)); - } - if (libusb_get_active_config_descriptor(h->dev, &pcfg)) { - libusb_close(h->handle); - return (-1); - } - - for (i = 0; i < pcfg->bNumInterfaces; i++) { - - h->ep_in = 0; - h->ep_out = 0; - h->iface = i; - - for (j = 0; j < pcfg->interface[i].altsetting[0].bNumEndpoints; j++) { - - unsigned char temp = pcfg->interface[i].altsetting[0]. - endpoint[j].bEndpointAddress; - unsigned char type = pcfg->interface[i].altsetting[0]. - endpoint[j].bmAttributes & 0x03; - - /* check for BULK endpoint */ - if ((type & 0x03) == 0x02) { - /* check for IN endpoint */ - if (temp & 0x80) - h->ep_in = temp; - else - h->ep_out = temp; - } - } - - info.ifc_class = pcfg->interface[i].altsetting[0].bInterfaceClass; - info.ifc_subclass = pcfg->interface[i].altsetting[0].bInterfaceSubClass; - info.ifc_protocol = pcfg->interface[i].altsetting[0].bInterfaceProtocol; - info.has_bulk_in = (h->ep_in != 0); - info.has_bulk_out = (h->ep_out != 0); - - if (libusb_claim_interface(h->handle, h->iface) < 0) - continue; - - if (callback(&info) == 0) { - libusb_free_config_descriptor(pcfg); - return (0); - } - libusb_release_interface(h->handle, h->iface); - } - - libusb_free_config_descriptor(pcfg); - libusb_close(h->handle); - return (-1); -} - -static usb_handle * -enumerate(ifc_match_func callback) -{ - static libusb_context *ctx = NULL; - usb_handle *h; - libusb_device **ppdev; - ssize_t ndev; - ssize_t x; - - h = malloc(sizeof(*h)); - if (h == NULL) - return (h); - - if (ctx == NULL) - libusb_init(&ctx); - - ndev = libusb_get_device_list(ctx, &ppdev); - for (x = 0; x < ndev; x++) { - - memset(h, 0, sizeof(*h)); - - h->dev = ppdev[x]; - - if (probe(h, callback) == 0) { - libusb_ref_device(h->dev); - libusb_free_device_list(ppdev, 1); - return (h); - } - } - free(h); - libusb_free_device_list(ppdev, 1); - return (NULL); -} - -int -usb_write(usb_handle * h, const void *_data, int len) -{ - int actlen; - - if (libusb_bulk_transfer(h->handle, h->ep_out, (void *)(long)_data, len, &actlen, 0) < 0) - return (-1); - return (actlen); -} - -int -usb_read(usb_handle * h, void *_data, int len) -{ - int actlen; - - if (libusb_bulk_transfer(h->handle, h->ep_in, _data, len, &actlen, 0) < 0) - return (-1); - return (actlen); -} - -int -usb_close(usb_handle * h) -{ - libusb_close(h->handle); - h->handle = NULL; - libusb_unref_device(h->dev); - free(h); - return (0); -} - -usb_handle * -usb_open(ifc_match_func callback) -{ - return (enumerate(callback)); -} - -int -usb_wait_for_disconnect(usb_handle * h) -{ - /* TODO: Punt for now */ - return 0; -} diff --git a/devel/android-tools-fastboot-devel/files/usb_freebsd.cpp b/devel/android-tools-fastboot/files/usb_freebsd.cpp index e85fb297b74f..e85fb297b74f 100644 --- a/devel/android-tools-fastboot-devel/files/usb_freebsd.cpp +++ b/devel/android-tools-fastboot/files/usb_freebsd.cpp diff --git a/devel/android-tools-fastboot/files/util_freebsd.c b/devel/android-tools-fastboot/files/util_freebsd.c deleted file mode 100644 index 4e928c61492d..000000000000 --- a/devel/android-tools-fastboot/files/util_freebsd.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2011 Hans Petter Selasky. 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 <unistd.h> -#include <limits.h> - -void -get_my_path(char *path) -{ - getcwd(path, PATH_MAX - 1); -} diff --git a/devel/android-tools-fastboot-devel/files/util_freebsd.cpp b/devel/android-tools-fastboot/files/util_freebsd.cpp index e962993e35a9..e962993e35a9 100644 --- a/devel/android-tools-fastboot-devel/files/util_freebsd.cpp +++ b/devel/android-tools-fastboot/files/util_freebsd.cpp |