summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2013-08-12 00:09:21 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2013-08-24 05:52:03 +0200
commita2adaeb68cdecc2bc1185613a11b7d49915883ec (patch)
tree468bff7b597e1b5cc491e6ce224688ebce8d9555
parent16c014578b9662bc2a0f099b77410e7ea3a793d1 (diff)
downloadcoreboot-a2adaeb68cdecc2bc1185613a11b7d49915883ec.tar.xz
usbdebug: Only test two possible USB device numbers
After an USB device sees USB bus reset on the bus, it will reset to device number 0. Per the EHCI debug port specification, a debug dongle device may reset to the fixed debug device number of 127 instead. Thus there is no need to try device numbers from 1 to 126. Do a sanity-check on a returned debug descriptor as I experienced some USB flash memory to respond on this request with zero-fill data. Change-Id: I78d58f3dc049cd8c20c6e2aa3a4207ad7e6a6d33 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/3861 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com>
-rw-r--r--src/lib/usbdebug.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c
index a9a7e17597..4a1228f158 100644
--- a/src/lib/usbdebug.c
+++ b/src/lib/usbdebug.c
@@ -540,24 +540,28 @@ try_next_port:
dbgp_mdelay(100);
/* Find the debug device and make it device number 127 */
- for (devnum = 0; devnum <= 127; devnum++) {
- ret = dbgp_control_msg(ehci_debug, devnum,
- USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
- USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0,
- &dbgp_desc, sizeof(dbgp_desc));
- if (ret > 0)
- break;
+ devnum = 0;
+debug_dev_retry:
+ memset(&dbgp_desc, 0, sizeof(dbgp_desc));
+ ret = dbgp_control_msg(ehci_debug, devnum,
+ USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
+ USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0,
+ &dbgp_desc, sizeof(dbgp_desc));
+ if (ret == sizeof(dbgp_desc)) {
+ if (dbgp_desc.bLength == sizeof(dbgp_desc) && dbgp_desc.bDescriptorType==USB_DT_DEBUG)
+ goto debug_dev_found;
+ else
+ dprintk(BIOS_INFO, "Invalid debug device descriptor.\n");
}
- if (devnum > 127) {
+ if (devnum == 0) {
+ devnum = USB_DEBUG_DEVNUM;
+ goto debug_dev_retry;
+ } else {
dprintk(BIOS_INFO, "Could not find attached debug device.\n");
ret = -5;
goto err;
}
- if (ret < 0) {
- dprintk(BIOS_INFO, "Attached device is not a debug device.\n");
- ret = -6;
- goto err;
- }
+debug_dev_found:
/* Move the device to 127 if it isn't already there */
if (devnum != USB_DEBUG_DEVNUM) {