Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e058cac authored by David Anderson's avatar David Anderson
Browse files

fastboot: Allow fastboot to asynchronously differentiate between fastboot and fastbootd.

It's not possible to programmatically determine which fastboot mode a
device is in, without sending a getvar:is-userspace query. Unfortunately
this is not possible asynchronously, and may interrupt other queries
being processed.

This patch changes fastbootd's USB interface name to "fastbootd". Note
that tools use the protocol number/class and not this string, so it
should be safe to extend. When using "fastboot devices", the interface
name is now listed if set. Note that currently only the Linux version of
the fastboot tool is capable of reading the interface name.

Bug: 156966319
Test: fastboot devices on Linux
Change-Id: I57ccf2bec1dda573fe3ac628a646624b76f45905
parent 2e660433
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ static struct SsFuncDesc ss_descriptors = {
                },
};

#define STR_INTERFACE_ "fastboot"
#define STR_INTERFACE_ "fastbootd"

static const struct {
    struct usb_functionfs_strings_head header;
+6 −2
Original line number Diff line number Diff line
@@ -258,6 +258,10 @@ static int match_fastboot(usb_ifc_info* info) {
static int list_devices_callback(usb_ifc_info* info) {
    if (match_fastboot_with_serial(info, nullptr) == 0) {
        std::string serial = info->serial_number;
        std::string interface = info->interface;
        if (interface.empty()) {
            interface = "fastboot";
        }
        if (!info->writable) {
            serial = UsbNoPermissionsShortHelpText();
        }
@@ -266,9 +270,9 @@ static int list_devices_callback(usb_ifc_info* info) {
        }
        // output compatible with "adb devices"
        if (!g_long_listing) {
            printf("%s\tfastboot", serial.c_str());
            printf("%s\t%s", serial.c_str(), interface.c_str());
        } else {
            printf("%-22s fastboot", serial.c_str());
            printf("%-22s %s", serial.c_str(), interface.c_str());
            if (strlen(info->device_path) > 0) printf(" %s", info->device_path);
        }
        putchar('\n');
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ struct usb_ifc_info {

    char serial_number[256];
    char device_path[256];

    char interface[256];
};

class UsbTransport : public Transport {
+9 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#include <linux/version.h>
#include <linux/usb/ch9.h>

#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <chrono>
#include <memory>
#include <thread>
@@ -263,6 +265,13 @@ static int filter_usb_device(char* sysfs_name,
        info.has_bulk_in = (in != -1);
        info.has_bulk_out = (out != -1);

        std::string interface;
        auto path = android::base::StringPrintf("/sys/bus/usb/devices/%s/%s:1.%d/interface",
                                                sysfs_name, sysfs_name, ifc->bInterfaceNumber);
        if (android::base::ReadFileToString(path, &interface)) {
            snprintf(info.interface, sizeof(info.interface), "%s", interface.c_str());
        }

        if(callback(&info) == 0) {
            *ept_in_id = in;
            *ept_out_id = out;
+1 −0
Original line number Diff line number Diff line
@@ -368,6 +368,7 @@ static int try_device(io_service_t device, usb_handle *handle) {
        // device has no serial number
        handle->info.serial_number[0] = 0;
    }
    handle->info.interface[0] = 0;
    handle->info.writable = 1;

    if (try_interfaces(dev, handle)) {
Loading