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>
This commit is contained in:
Kyösti Mälkki 2013-08-12 00:09:21 +03:00
parent 16c014578b
commit a2adaeb68c
1 changed files with 17 additions and 13 deletions

View File

@ -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) {