From 8593ec4bf3d00e3b355d42a011e45aacf327739b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 17 Nov 2024 20:03:20 +0800 Subject: [PATCH] Allow using thirdparty VID for reboot interface Filtering by `--vid` and `--pid` is not enough currently. I'm implementing the reboot interface for a custom device. But I'm not using the Raspberry PI vendor ID. There's no way currently to allow those third party devices to reboot. With this change I can reboot my device from application firmware into bootloader with: ``` picotool reboot --vid 0x32ac --pid 0x001f -f -u ``` Signed-off-by: Daniel Schaefer --- picoboot_connection/BUILD.bazel | 1 + picoboot_connection/picoboot_connection.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/picoboot_connection/BUILD.bazel b/picoboot_connection/BUILD.bazel index fd8b15b..b2fac4d 100644 --- a/picoboot_connection/BUILD.bazel +++ b/picoboot_connection/BUILD.bazel @@ -19,5 +19,6 @@ cc_library( "@pico-sdk//src/common/boot_picoboot_headers", "@pico-sdk//src/rp2_common/boot_bootrom_headers", "@pico-sdk//src/rp2_common/pico_bootrom:pico_bootrom_headers", + "@pico-sdk//src/rp2_common/pico_stdio_usb:reset_interface_headers", ], ) diff --git a/picoboot_connection/picoboot_connection.c b/picoboot_connection/picoboot_connection.c index 0c6c35f..265608c 100644 --- a/picoboot_connection/picoboot_connection.c +++ b/picoboot_connection/picoboot_connection.c @@ -11,6 +11,7 @@ #include "picoboot_connection.h" #include "boot/bootrom_constants.h" +#include "pico/stdio_usb/reset_interface.h" #if ENABLE_DEBUG_LOG #include @@ -142,6 +143,17 @@ enum picoboot_device_result picoboot_open_device(libusb_device *device, libusb_d } } + // Runtime reset interface with thirdparty VID + if (!ret) { + for (int i = 0; i < config->bNumInterfaces; i++) { + if (config->interface[i].altsetting[0].bInterfaceClass == 0xff && + config->interface[i].altsetting[0].bInterfaceSubClass == RESET_INTERFACE_SUBCLASS && + config->interface[i].altsetting[0].bInterfaceProtocol == RESET_INTERFACE_PROTOCOL) { + return dr_vidpid_stdio_usb; + } + } + } + if (!ret) { if (config->bNumInterfaces == 1) { interface = 0;