Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jun 2015 21:53:14 +0000 (UTC)
From:      Jan Beich <jbeich@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r389005 - in head/devel: . android-tools-fastboot android-tools-fastboot/files
Message-ID:  <201506092153.t59LrEBm045446@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jbeich
Date: Tue Jun  9 21:53:13 2015
New Revision: 389005
URL: https://svnweb.freebsd.org/changeset/ports/389005

Log:
  devel/android-tools-fastboot: add new port
  
  Fastboot is a diagnostic protocol primarily used to update the flash
  filesystem of Android devices over USB.
  
  This package provides the fastboot command-line tool.
  
  Inspired by:	devel/android-tools-adb
  Obtained from:	hselasky @ libusb-devel

Added:
  head/devel/android-tools-fastboot/
  head/devel/android-tools-fastboot/Makefile   (contents, props changed)
  head/devel/android-tools-fastboot/distinfo   (contents, props changed)
  head/devel/android-tools-fastboot/files/
  head/devel/android-tools-fastboot/files/Makefile   (contents, props changed)
  head/devel/android-tools-fastboot/files/usb_freebsd.c   (contents, props changed)
  head/devel/android-tools-fastboot/files/util_freebsd.c   (contents, props changed)
  head/devel/android-tools-fastboot/pkg-descr   (contents, props changed)
Modified:
  head/devel/Makefile   (contents, props changed)

Modified: head/devel/Makefile
==============================================================================
--- head/devel/Makefile	Tue Jun  9 21:34:36 2015	(r389004)
+++ head/devel/Makefile	Tue Jun  9 21:53:13 2015	(r389005)
@@ -57,6 +57,7 @@
     SUBDIR += amd64-gcc
     SUBDIR += amd64-xtoolchain-gcc
     SUBDIR += android-tools-adb
+    SUBDIR += android-tools-fastboot
     SUBDIR += anjuta
     SUBDIR += anjuta-extras
     SUBDIR += antlr

Added: head/devel/android-tools-fastboot/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/Makefile	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+PORTNAME=	android-tools-fastboot
+DISTVERSION=	4.0.4_r2.1
+CATEGORIES=	devel
+
+MAINTAINER=	jbeich@FreeBSD.org
+COMMENT=	Android Fastboot protocol CLI tool
+
+LICENSE=	APACHE20 BSD2CLAUSE
+LICENSE_COMB=	multi
+
+USE_GITHUB=	yes
+GH_ACCOUNT=	android
+GH_PROJECT=	platform_system_core
+GH_TAGNAME=	${GH_ACCOUNT}-${DISTVERSION}
+
+USES=		uidfix
+WRKSRC_SUBDIR=	fastboot
+MAKEFILE=	${FILESDIR}/Makefile
+MAKE_ENV=	FILESDIR=${FILESDIR} BINDIR=${PREFIX}/bin
+PLIST_FILES=	bin/fastboot
+
+.include <bsd.port.mk>

Added: head/devel/android-tools-fastboot/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/distinfo	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,2 @@
+SHA256 (android-platform_system_core-4.0.4_r2.1-android-4.0.4_r2.1_GH0.tar.gz) = a60b54b73ef5f739d19bde75d7d8bb3045b990591e5c9cad4c30b68ac86019f7
+SIZE (android-platform_system_core-4.0.4_r2.1-android-4.0.4_r2.1_GH0.tar.gz) = 896079

Added: head/devel/android-tools-fastboot/files/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/files/Makefile	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,27 @@
+# $FreeBSD$
+
+PROG=	fastboot
+NO_MAN=
+BINDIR?=/usr/bin
+
+SRCS+=	bootimg.c
+SRCS+=	engine.c
+SRCS+=	fastboot.c
+SRCS+=	protocol.c
+
+.PATH:	${FILESDIR}
+SRCS+=	usb_freebsd.c
+SRCS+=	util_freebsd.c
+
+.PATH:	${.CURDIR}/../libzipfile
+SRCS+=	centraldir.c
+SRCS+=	zipfile.c
+
+CFLAGS+=-I.
+CFLAGS+=-I../include
+CFLAGS+=-I../mkbootimg
+
+LDADD+=	-lusb -lz
+DPADD+=	${LIBUSB} ${LIBZ}
+
+.include <bsd.prog.mk>

Added: head/devel/android-tools-fastboot/files/usb_freebsd.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/files/usb_freebsd.c	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,197 @@
+/*
+ * 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 <unistd.h>
+#include <string.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pthread.h>
+#include <ctype.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;
+	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;
+
+	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));
+}

Added: head/devel/android-tools-fastboot/files/util_freebsd.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/files/util_freebsd.c	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,35 @@
+/*
+ * 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);
+}

Added: head/devel/android-tools-fastboot/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/android-tools-fastboot/pkg-descr	Tue Jun  9 21:53:13 2015	(r389005)
@@ -0,0 +1,4 @@
+Fastboot is a diagnostic protocol primarily used to update the flash
+filesystem of Android devices over USB.
+
+This package provides the fastboot command-line tool.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201506092153.t59LrEBm045446>