summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/Android.mk21
-rw-r--r--fastboot/bootimg_utils.cpp (renamed from fastboot/bootimg.c)10
-rw-r--r--fastboot/bootimg_utils.h49
-rw-r--r--fastboot/fastboot.cpp (renamed from fastboot/fastboot.c)190
-rw-r--r--fastboot/fastboot.h10
-rw-r--r--fastboot/fastboot_protocol.txt4
-rw-r--r--fastboot/fs.h8
-rw-r--r--fastboot/protocol.c7
-rw-r--r--fastboot/usb.h8
-rw-r--r--fastboot/usb_linux.c7
-rw-r--r--fastboot/usb_osx.c3
11 files changed, 197 insertions, 120 deletions
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index e11691f..7b2975b 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -19,10 +19,11 @@ include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../mkbootimg \
$(LOCAL_PATH)/../../extras/ext4_utils \
$(LOCAL_PATH)/../../extras/f2fs_utils
-LOCAL_SRC_FILES := protocol.c engine.c bootimg.c fastboot.c util.c fs.c
+LOCAL_SRC_FILES := protocol.c engine.c bootimg_utils.cpp fastboot.cpp util.c fs.c
LOCAL_MODULE := fastboot
LOCAL_MODULE_TAGS := debug
-LOCAL_CFLAGS += -std=gnu99 -Werror
+LOCAL_CONLYFLAGS += -std=gnu99
+LOCAL_CFLAGS += -Wall -Wextra -Werror
ifeq ($(HOST_OS),linux)
LOCAL_SRC_FILES += usb_linux.c util_linux.c
@@ -32,6 +33,7 @@ ifeq ($(HOST_OS),darwin)
LOCAL_SRC_FILES += usb_osx.c util_osx.c
LOCAL_LDLIBS += -lpthread -framework CoreFoundation -framework IOKit \
-framework Carbon
+ LOCAL_CFLAGS += -Wno-unused-parameter
endif
ifeq ($(HOST_OS),windows)
@@ -51,10 +53,11 @@ endif
LOCAL_STATIC_LIBRARIES := \
$(EXTRA_STATIC_LIBS) \
- libzipfile \
- libunz \
+ libziparchive-host \
libext4_utils_host \
libsparse_host \
+ libutils \
+ liblog \
libz
ifneq ($(HOST_OS),windows)
@@ -71,6 +74,16 @@ LOCAL_REQUIRED_MODULES := libf2fs_fmt_host_dyn
LOCAL_STATIC_LIBRARIES += libf2fs_utils_host libf2fs_ioutils_host libf2fs_dlutils_host
endif
+# libc++ not available on windows yet
+ifneq ($(HOST_OS),windows)
+ LOCAL_CXX_STL := libc++_static
+endif
+
+# Don't add anything here, we don't want additional shared dependencies
+# on the host fastboot tool, and shared libraries that link against libc++
+# will violate ODR
+LOCAL_SHARED_LIBRARIES :=
+
include $(BUILD_HOST_EXECUTABLE)
my_dist_files := $(LOCAL_BUILT_MODULE)
diff --git a/fastboot/bootimg.c b/fastboot/bootimg_utils.cpp
index 240784f..d8905a6 100644
--- a/fastboot/bootimg.c
+++ b/fastboot/bootimg_utils.cpp
@@ -26,12 +26,12 @@
* SUCH DAMAGE.
*/
+#include "bootimg_utils.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <bootimg.h>
-
void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline)
{
strcpy((char*) h->cmdline, cmdline);
@@ -47,7 +47,6 @@ boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, unsigned kernel_offs
unsigned ramdisk_actual;
unsigned second_actual;
unsigned page_mask;
- boot_img_hdr *hdr;
page_mask = page_size - 1;
@@ -57,9 +56,8 @@ boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, unsigned kernel_offs
*bootimg_size = page_size + kernel_actual + ramdisk_actual + second_actual;
- hdr = calloc(*bootimg_size, 1);
-
- if(hdr == 0) {
+ boot_img_hdr* hdr = reinterpret_cast<boot_img_hdr*>(calloc(*bootimg_size, 1));
+ if (hdr == 0) {
return hdr;
}
diff --git a/fastboot/bootimg_utils.h b/fastboot/bootimg_utils.h
new file mode 100644
index 0000000..b1a86cd
--- /dev/null
+++ b/fastboot/bootimg_utils.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#ifndef _FASTBOOT_BOOTIMG_UTILS_H_
+#define _FASTBOOT_BOOTIMG_UTILS_H_
+
+#include <bootimg.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline);
+boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, unsigned kernel_offset,
+ void *ramdisk, unsigned ramdisk_size, unsigned ramdisk_offset,
+ void *second, unsigned second_size, unsigned second_offset,
+ unsigned page_size, unsigned base, unsigned tags_offset,
+ unsigned *bootimg_size);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.cpp
index 43d05aa..e139bcd 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.cpp
@@ -44,10 +44,10 @@
#include <sys/types.h>
#include <unistd.h>
-#include <bootimg.h>
#include <sparse/sparse.h>
-#include <zipfile/zipfile.h>
+#include <ziparchive/zip_archive.h>
+#include "bootimg_utils.h"
#include "fastboot.h"
#include "fs.h"
@@ -59,14 +59,6 @@
char cur_product[FB_RESPONSE_SZ + 1];
-void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline);
-
-boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, unsigned kernel_offset,
- void *ramdisk, unsigned ramdisk_size, unsigned ramdisk_offset,
- void *second, unsigned second_size, unsigned second_offset,
- unsigned page_size, unsigned base, unsigned tags_offset,
- unsigned *bootimg_size);
-
static usb_handle *usb = 0;
static const char *serial = 0;
static const char *product = 0;
@@ -106,12 +98,10 @@ static struct {
{"vendor.img", "vendor.sig", "vendor", true},
};
-void get_my_path(char *path);
-
char *find_item(const char *item, const char *product)
{
char *dir;
- char *fn;
+ const char *fn;
char path[PATH_MAX + 128];
if(!strcmp(item,"boot")) {
@@ -234,7 +224,7 @@ int match_fastboot(usb_ifc_info *info)
int list_devices_callback(usb_ifc_info *info)
{
if (match_fastboot_with_serial(info, NULL) == 0) {
- char* serial = info->serial_number;
+ const char* serial = info->serial_number;
if (!info->writable) {
serial = "no permissions"; // like "adb devices"
}
@@ -244,7 +234,7 @@ int list_devices_callback(usb_ifc_info *info)
// output compatible with "adb devices"
if (!long_listing) {
printf("%s\tfastboot\n", serial);
- } else if (!info->device_path) {
+ } else if (strcmp("", info->device_path) == 0) {
printf("%-22s fastboot\n", serial);
} else {
printf("%-22s fastboot %s\n", serial, info->device_path);
@@ -300,7 +290,7 @@ void usage(void)
" flash it\n"
" devices list all connected devices\n"
" continue continue with autoboot\n"
- " reboot reboot device normally\n"
+ " reboot [bootloader] reboot device, optionally into bootloader\n"
" reboot-bootloader reboot device into bootloader\n"
" help show this help message\n"
"\n"
@@ -389,30 +379,26 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
return bdata;
}
-void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
+static void* unzip_file(ZipArchiveHandle zip, const char* entry_name, unsigned* sz)
{
- void *data;
- zipentry_t entry;
- unsigned datasz;
-
- entry = lookup_zipentry(zip, name);
- if (entry == NULL) {
- fprintf(stderr, "archive does not contain '%s'\n", name);
+ ZipEntryName zip_entry_name(entry_name);
+ ZipEntry zip_entry;
+ if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
+ fprintf(stderr, "archive does not contain '%s'\n", entry_name);
return 0;
}
- *sz = get_zipentry_size(entry);
+ *sz = zip_entry.uncompressed_length;
- datasz = *sz * 1.001;
- data = malloc(datasz);
-
- if(data == 0) {
- fprintf(stderr, "failed to allocate %d bytes\n", *sz);
+ uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
+ if (data == NULL) {
+ fprintf(stderr, "failed to allocate %u bytes for '%s'\n", *sz, entry_name);
return 0;
}
- if (decompress_zipentry(entry, data, datasz)) {
- fprintf(stderr, "failed to unzip '%s' from archive\n", name);
+ int error = ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length);
+ if (error != 0) {
+ fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
free(data);
return 0;
}
@@ -420,27 +406,28 @@ void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
return data;
}
-static int unzip_to_file(zipfile_t zip, char *name)
-{
- int fd;
- char *data;
- unsigned sz;
-
- fd = fileno(tmpfile());
- if (fd < 0) {
+static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) {
+ FILE* fp = tmpfile();
+ if (fp == NULL) {
+ fprintf(stderr, "failed to create temporary file for '%s': %s\n",
+ entry_name, strerror(errno));
return -1;
}
- data = unzip_file(zip, name, &sz);
- if (data == 0) {
+ ZipEntryName zip_entry_name(entry_name);
+ ZipEntry zip_entry;
+ if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
+ fprintf(stderr, "archive does not contain '%s'\n", entry_name);
return -1;
}
- if (write(fd, data, sz) != (ssize_t)sz) {
- fd = -1;
+ int fd = fileno(fp);
+ int error = ExtractEntryToFile(zip, &zip_entry, fd);
+ if (error != 0) {
+ fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
+ return -1;
}
- free(data);
lseek(fd, 0, SEEK_SET);
return fd;
}
@@ -461,7 +448,6 @@ static char *strip(char *s)
static int setup_requirement_line(char *name)
{
char *val[MAX_OPTIONS];
- const char **out;
char *prod = NULL;
unsigned n, count;
char *x;
@@ -501,10 +487,11 @@ static int setup_requirement_line(char *name)
name = strip(name);
if (name == 0) return -1;
- /* work around an unfortunate name mismatch */
- if (!strcmp(name,"board")) name = "product";
+ const char* var = name;
+ // Work around an unfortunate name mismatch.
+ if (!strcmp(name,"board")) var = "product";
- out = malloc(sizeof(char*) * count);
+ const char** out = reinterpret_cast<const char**>(malloc(sizeof(char*) * count));
if (out == 0) return -1;
for(n = 0; n < count; n++) {
@@ -518,7 +505,7 @@ static int setup_requirement_line(char *name)
}
}
- fb_queue_require(prod, name, invert, n, out);
+ fb_queue_require(prod, var, invert, n, out);
return 0;
}
@@ -551,21 +538,17 @@ void queue_info_dump(void)
static struct sparse_file **load_sparse_files(int fd, int max_size)
{
- struct sparse_file *s;
- int files;
- struct sparse_file **out_s;
-
- s = sparse_file_import_auto(fd, false);
+ struct sparse_file* s = sparse_file_import_auto(fd, false, true);
if (!s) {
die("cannot sparse read file\n");
}
- files = sparse_file_resparse(s, max_size, NULL, 0);
+ int files = sparse_file_resparse(s, max_size, NULL, 0);
if (files < 0) {
die("Failed to resparse\n");
}
- out_s = calloc(sizeof(struct sparse_file *), files + 1);
+ sparse_file** out_s = reinterpret_cast<sparse_file**>(calloc(sizeof(struct sparse_file *), files + 1));
if (!out_s) {
die("Failed to allocate sparse file array\n");
}
@@ -682,11 +665,11 @@ static int load_buf(usb_handle *usb, const char *fname,
static void flash_buf(const char *pname, struct fastboot_buffer *buf)
{
- struct sparse_file **s;
+ sparse_file** s;
switch (buf->type) {
case FB_BUFFER_SPARSE:
- s = buf->data;
+ s = reinterpret_cast<sparse_file**>(buf->data);
while (*s) {
int64_t sz64 = sparse_file_len(*s, true, false);
fb_queue_flash_sparse(pname, *s++, sz64);
@@ -710,63 +693,44 @@ void do_flash(usb_handle *usb, const char *pname, const char *fname)
flash_buf(pname, &buf);
}
-void do_update_signature(zipfile_t zip, char *fn)
+void do_update_signature(ZipArchiveHandle zip, char *fn)
{
- void *data;
unsigned sz;
- data = unzip_file(zip, fn, &sz);
+ void* data = unzip_file(zip, fn, &sz);
if (data == 0) return;
fb_queue_download("signature", data, sz);
fb_queue_command("signature", "installing signature");
}
-void do_update(usb_handle *usb, char *fn, int erase_first)
+void do_update(usb_handle *usb, const char *filename, int erase_first)
{
- void *zdata;
- unsigned zsize;
- void *data;
- unsigned sz;
- zipfile_t zip;
- int fd;
- int rc;
- struct fastboot_buffer buf;
- size_t i;
-
queue_info_dump();
fb_queue_query_save("product", cur_product, sizeof(cur_product));
- zdata = load_file(fn, &zsize);
- if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));
-
- zip = init_zipfile(zdata, zsize);
- if(zip == 0) die("failed to access zipdata in '%s'");
+ ZipArchiveHandle zip;
+ int error = OpenArchive(filename, &zip);
+ if (error != 0) {
+ die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
+ }
- data = unzip_file(zip, "android-info.txt", &sz);
+ unsigned sz;
+ void* data = unzip_file(zip, "android-info.txt", &sz);
if (data == 0) {
- char *tmp;
- /* fallback for older zipfiles */
- data = unzip_file(zip, "android-product.txt", &sz);
- if ((data == 0) || (sz < 1)) {
- die("update package has no android-info.txt or android-product.txt");
- }
- tmp = malloc(sz + 128);
- if (tmp == 0) die("out of memory");
- sprintf(tmp,"board=%sversion-baseband=0.66.04.19\n",(char*)data);
- data = tmp;
- sz = strlen(tmp);
+ die("update package '%s' has no android-info.txt", filename);
}
- setup_requirements(data, sz);
+ setup_requirements(reinterpret_cast<char*>(data), sz);
- for (i = 0; i < ARRAY_SIZE(images); i++) {
- fd = unzip_to_file(zip, images[i].img_name);
+ for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
+ int fd = unzip_to_file(zip, images[i].img_name);
if (fd < 0) {
if (images[i].is_optional)
continue;
die("update package missing %s", images[i].img_name);
}
- rc = load_buf_fd(usb, fd, &buf);
+ fastboot_buffer buf;
+ int rc = load_buf_fd(usb, fd, &buf);
if (rc) die("cannot load %s from flash", images[i].img_name);
do_update_signature(zip, images[i].sig_name);
if (erase_first && needs_erase(images[i].part_name)) {
@@ -778,6 +742,8 @@ void do_update(usb_handle *usb, char *fn, int erase_first)
* program exits.
*/
}
+
+ CloseArchive(zip);
}
void do_send_signature(char *fn)
@@ -800,24 +766,22 @@ void do_send_signature(char *fn)
void do_flashall(usb_handle *usb, int erase_first)
{
- char *fname;
- void *data;
- unsigned sz;
- struct fastboot_buffer buf;
- size_t i;
-
queue_info_dump();
fb_queue_query_save("product", cur_product, sizeof(cur_product));
- fname = find_item("info", product);
+ char* fname = find_item("info", product);
if (fname == 0) die("cannot find android-info.txt");
- data = load_file(fname, &sz);
+
+ unsigned sz;
+ void* data = load_file(fname, &sz);
if (data == 0) die("could not load android-info.txt: %s", strerror(errno));
- setup_requirements(data, sz);
- for (i = 0; i < ARRAY_SIZE(images); i++) {
+ setup_requirements(reinterpret_cast<char*>(data), sz);
+
+ for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
fname = find_item(images[i].part_name, product);
+ fastboot_buffer buf;
if (load_buf(usb, fname, &buf)) {
if (images[i].is_optional)
continue;
@@ -988,6 +952,7 @@ int main(int argc, char **argv)
unsigned sz;
int status;
int c;
+ int longindex;
const struct option longopts[] = {
{"base", required_argument, 0, 'b'},
@@ -996,13 +961,14 @@ int main(int argc, char **argv)
{"ramdisk_offset", required_argument, 0, 'r'},
{"tags_offset", required_argument, 0, 't'},
{"help", 0, 0, 'h'},
+ {"unbuffered", 0, 0, 0},
{0, 0, 0, 0}
};
serial = getenv("ANDROID_SERIAL");
while (1) {
- c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:h", longopts, NULL);
+ c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:h", longopts, &longindex);
if (c < 0) {
break;
}
@@ -1063,6 +1029,12 @@ int main(int argc, char **argv)
break;
case '?':
return 1;
+ case 0:
+ if (strcmp("unbuffered", longopts[longindex].name) == 0) {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
+ break;
default:
abort();
}
@@ -1145,6 +1117,14 @@ int main(int argc, char **argv)
} else if(!strcmp(*argv, "reboot")) {
wants_reboot = 1;
skip(1);
+ if (argc > 0) {
+ if (!strcmp(*argv, "bootloader")) {
+ wants_reboot = 0;
+ wants_reboot_bootloader = 1;
+ skip(1);
+ }
+ }
+ require(0);
} else if(!strcmp(*argv, "reboot-bootloader")) {
wants_reboot_bootloader = 1;
skip(1);
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index fc5d4f4..1786e49 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -31,6 +31,10 @@
#include "usb.h"
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
struct sparse_file;
/* protocol.c - fastboot protocol */
@@ -67,7 +71,13 @@ double now();
char *mkmsg(const char *fmt, ...);
void die(const char *fmt, ...);
+void get_my_path(char *path);
+
/* Current product */
extern char cur_product[FB_RESPONSE_SZ + 1];
+#if defined(__cplusplus)
+}
+#endif
+
#endif
diff --git a/fastboot/fastboot_protocol.txt b/fastboot/fastboot_protocol.txt
index 2248992..37b1959 100644
--- a/fastboot/fastboot_protocol.txt
+++ b/fastboot/fastboot_protocol.txt
@@ -12,8 +12,8 @@ Basic Requirements
------------------
* Two bulk endpoints (in, out) are required
-* Max packet size must be 64 bytes for full-speed and 512 bytes for
- high-speed USB
+* Max packet size must be 64 bytes for full-speed, 512 bytes for
+ high-speed and 1024 bytes for Super Speed USB.
* The protocol is entirely host-driven and synchronous (unlike the
multi-channel, bi-directional, asynchronous ADB protocol)
diff --git a/fastboot/fs.h b/fastboot/fs.h
index 8444081..307772b 100644
--- a/fastboot/fs.h
+++ b/fastboot/fs.h
@@ -3,10 +3,18 @@
#include <stdint.h>
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
struct fs_generator;
const struct fs_generator* fs_get_generator(const char *fs_type);
int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize);
+#if defined(__cplusplus)
+}
+#endif
+
#endif
diff --git a/fastboot/protocol.c b/fastboot/protocol.c
index 84e9837..5b97600 100644
--- a/fastboot/protocol.c
+++ b/fastboot/protocol.c
@@ -216,7 +216,7 @@ int fb_download_data(usb_handle *usb, const void *data, unsigned size)
}
}
-#define USB_BUF_SIZE 512
+#define USB_BUF_SIZE 1024
static char usb_buf[USB_BUF_SIZE];
static int usb_buf_len;
@@ -305,7 +305,10 @@ int fb_download_data_sparse(usb_handle *usb, struct sparse_file *s)
return -1;
}
- fb_download_data_sparse_flush(usb);
+ r = fb_download_data_sparse_flush(usb);
+ if (r < 0) {
+ return -1;
+ }
return _command_end(usb);
}
diff --git a/fastboot/usb.h b/fastboot/usb.h
index 17cf0a9..c7b748e 100644
--- a/fastboot/usb.h
+++ b/fastboot/usb.h
@@ -29,6 +29,10 @@
#ifndef _USB_H_
#define _USB_H_
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
typedef struct usb_handle usb_handle;
typedef struct usb_ifc_info usb_ifc_info;
@@ -64,4 +68,8 @@ int usb_read(usb_handle *h, void *_data, int len);
int usb_write(usb_handle *h, const void *_data, int len);
int usb_wait_for_disconnect(usb_handle *h);
+#if defined(__cplusplus)
+}
+#endif
+
#endif
diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c
index fabbd51..022f364 100644
--- a/fastboot/usb_linux.c
+++ b/fastboot/usb_linux.c
@@ -223,6 +223,13 @@ static int filter_usb_device(char* sysfs_name,
} else {
out = ept->bEndpointAddress;
}
+
+ // For USB 3.0 devices skip the SS Endpoint Companion descriptor
+ if (check((struct usb_descriptor_hdr *)ptr, len,
+ USB_DT_SS_ENDPOINT_COMP, USB_DT_SS_EP_COMP_SIZE) == 0) {
+ len -= USB_DT_SS_EP_COMP_SIZE;
+ ptr += USB_DT_SS_EP_COMP_SIZE;
+ }
}
info.has_bulk_in = (in != -1);
diff --git a/fastboot/usb_osx.c b/fastboot/usb_osx.c
index 0f55e0d..0b6c515 100644
--- a/fastboot/usb_osx.c
+++ b/fastboot/usb_osx.c
@@ -328,7 +328,8 @@ static int try_device(io_service_t device, usb_handle *handle) {
ERR("GetLocationId");
goto error;
}
- snprintf(handle->info.device_path, sizeof(handle->info.device_path), "usb:%lX", locationId);
+ snprintf(handle->info.device_path, sizeof(handle->info.device_path),
+ "usb:%" PRIu32 "X", (unsigned int)locationId);
kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);