summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beich <jbeich@FreeBSD.org>2015-07-18 16:51:08 +0000
committerJan Beich <jbeich@FreeBSD.org>2015-07-18 16:51:08 +0000
commitd798c6aea83983e3d0b33bd13c293d4fbb3ddcff (patch)
tree1109b98047dd90ef44c79cc04d0230c106ea5b85
parentdevel/android-tools-{adb,fastboot}-devel: update to m.p.190 (diff)
devel/android-tools-fastboot-devel: move FreeBSD code to C++
Copy files in order to fix the following errors. files/usb_freebsd.cpp:132:4: error: assigning to 'usb_handle *' from incompatible type 'void *' h = malloc(sizeof(*h)); ^ ~~~~~~~~~~~~~~~~~~ files/usb_freebsd.cpp:162:6: error: no matching function for call to 'libusb_bulk_transfer' if (libusb_bulk_transfer(h->handle, h->ep_out, (void *)(long)_data, len, &actlen, 0) < 0) ^~~~~~~~~~~~~~~~~~~~ /usr/include/libusb.h:478:5: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'uint8_t *' (aka 'unsigned char *') int libusb_bulk_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout); ^ files/usb_freebsd.cpp:172:6: error: no matching function for call to 'libusb_bulk_transfer' if (libusb_bulk_transfer(h->handle, h->ep_in, _data, len, &actlen, 0) < 0) ^~~~~~~~~~~~~~~~~~~~ /usr/include/libusb.h:478:5: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'uint8_t *' (aka 'unsigned char *') int libusb_bulk_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout); ^ 3 errors generated. fastboot.o: In function `find_item(char const*, char const*)': fastboot.cpp:(.text+0xea): undefined reference to `get_my_path'
Notes
Notes: svn path=/head/; revision=392432
-rw-r--r--devel/android-tools-fastboot-devel/Makefile4
-rw-r--r--devel/android-tools-fastboot-devel/files/Makefile4
-rw-r--r--devel/android-tools-fastboot-devel/files/pkg-message.in7
-rw-r--r--devel/android-tools-fastboot-devel/files/usb_freebsd.cpp200
-rw-r--r--devel/android-tools-fastboot-devel/files/util_freebsd.cpp37
-rw-r--r--devel/android-tools-fastboot/Makefile2
6 files changed, 249 insertions, 5 deletions
diff --git a/devel/android-tools-fastboot-devel/Makefile b/devel/android-tools-fastboot-devel/Makefile
index d2673a348493..19802b9635f2 100644
--- a/devel/android-tools-fastboot-devel/Makefile
+++ b/devel/android-tools-fastboot-devel/Makefile
@@ -2,7 +2,7 @@
DISTVERSION= m-preview-190
DISTVERSIONSUFFIX= -g683790a
-PORTREVISION= 0
+PORTREVISION= 1
PKGNAMESUFFIX= -devel
GH_TAGNAME= m-preview-100-gdece0f9:extras \
@@ -12,7 +12,7 @@ CONFLICTS_INSTALL= ${PORTNAME}-[0-9]*
MASTERDIR= ${.CURDIR}/../android-tools-fastboot
DISTINFO_FILE= ${.CURDIR}/distinfo
-MAKEFILE= ${.CURDIR}/files/Makefile
+FILESDIR= ${.CURDIR}/files
EXTRA_PATCHES+= ${.CURDIR}/files/patch-*
USES= compiler:c++11-lib
diff --git a/devel/android-tools-fastboot-devel/files/Makefile b/devel/android-tools-fastboot-devel/files/Makefile
index 443dd2d1d5b4..27e868ac5e0c 100644
--- a/devel/android-tools-fastboot-devel/files/Makefile
+++ b/devel/android-tools-fastboot-devel/files/Makefile
@@ -11,8 +11,8 @@ SRCS+= protocol.cpp
SRCS+= util.cpp
.PATH: ${FILESDIR}
-SRCS+= usb_freebsd.c
-SRCS+= util_freebsd.c
+SRCS+= usb_freebsd.cpp
+SRCS+= util_freebsd.cpp
# required by libziparchive
.PATH: ${.CURDIR}/../base
diff --git a/devel/android-tools-fastboot-devel/files/pkg-message.in b/devel/android-tools-fastboot-devel/files/pkg-message.in
new file mode 100644
index 000000000000..32713248181a
--- /dev/null
+++ b/devel/android-tools-fastboot-devel/files/pkg-message.in
@@ -0,0 +1,7 @@
+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-devel/files/usb_freebsd.cpp b/devel/android-tools-fastboot-devel/files/usb_freebsd.cpp
new file mode 100644
index 000000000000..e85fb297b74f
--- /dev/null
+++ b/devel/android-tools-fastboot-devel/files/usb_freebsd.cpp
@@ -0,0 +1,200 @@
+/*
+ * 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(usb_handle *h, ifc_match_func callback)
+{
+ usb_ifc_info info;
+ libusb_device_descriptor ddesc;
+ 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 = reinterpret_cast<usb_handle*>(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,
+ (unsigned char *)_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,
+ (unsigned char *)_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/util_freebsd.cpp b/devel/android-tools-fastboot-devel/files/util_freebsd.cpp
new file mode 100644
index 000000000000..e962993e35a9
--- /dev/null
+++ b/devel/android-tools-fastboot-devel/files/util_freebsd.cpp
@@ -0,0 +1,37 @@
+/*
+ * 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 "fastboot.h"
+
+#include <unistd.h>
+#include <limits.h>
+
+void
+get_my_path(char *path)
+{
+ getcwd(path, PATH_MAX - 1);
+}
diff --git a/devel/android-tools-fastboot/Makefile b/devel/android-tools-fastboot/Makefile
index 5ba2bdc2100a..1487943b0782 100644
--- a/devel/android-tools-fastboot/Makefile
+++ b/devel/android-tools-fastboot/Makefile
@@ -31,7 +31,7 @@ CONFLICTS_INSTALL?= ${PORTNAME}-devel-*
USES+= uidfix
BUILD_WRKSRC= ${WRKSRC}/fastboot
INSTALL_WRKSRC= ${BUILD_WRKSRC}
-MAKEFILE= ${.CURDIR}/files/Makefile # XXX ?= when bmake-only
+MAKEFILE= ${FILESDIR}/Makefile
MAKE_ENV= FILESDIR="${FILESDIR}" BINDIR="${PREFIX}/bin" \
MANDIR="${PREFIX}/man/man" \
LIBPCRE="${LOCALBASE}/lib/libpcre.a"