Stefan Tauner (stefan.tauner@gmx.at) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9305
-gerrit
commit d0544acfa24c6f83a411a3ef76ee050bae1ee57b Author: Stefan Tauner stefan.tauner@gmx.at Date: Sun Apr 5 14:48:06 2015 +0200
find_usbdebug: introduce script to help find USB debug ports
Carl-Daniel made this script a long time ago but it never was picked up in the tree. Now that USB debugging is way more common it makes sense to include it.
I have made a number of changes to the original version: * -h help text * check for running as root * removed bashism * enhanced readability (test -> if) * new execution flow and refined output that better shows the device(s) attached to the debug port(s)
Signed-off-by: Stefan Tauner stefan.tauner@gmx.at Change-Id: Iadf775e990f5c5f91a28d57e3331d1f59acee305 --- util/find_usbdebug/find_usbdebug.sh | 140 ++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+)
diff --git a/util/find_usbdebug/find_usbdebug.sh b/util/find_usbdebug/find_usbdebug.sh new file mode 100755 index 0000000..56ecfc8 --- /dev/null +++ b/util/find_usbdebug/find_usbdebug.sh @@ -0,0 +1,140 @@ +#!/bin/sh + +# Copyright 2008 Carl-Daniel Hailfinger +# Copyright 2015 Stefan Tauner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc. + +LANG=C + +if [ "$1" = "-h" ]; then + printf "Usage: $0 [-h | path to dmesg log] + +This script tries to find USB ports compatible with USB2/EHCI debug devices and +helps you to find their physical locations. To that end, attach at least one +uniquely identifiable device to a USB port and run this script. The device needs +to be visible in the output of "lsusb -t" (debug devices are often *not*!). + +After determining compatibility of the USB controllers the script will print the +devices attached to the debug port as shown by lsusb. If nothing shows up simply +switch ports and repeat the process. + +Note: usually only one port is supported for debugging.\n" + exit 0 +fi +uid=`id -u` +if [ "$uid" -ne 0 ]; then + echo "Must be run as root. Exiting." + exit 1 +fi +dmesgfile=$1 + +find_devs_in_tree () { + bus=$1 + port=$2 + busstr=`printf "Bus %02d" "$bus"` + portstr="Port $port" + + found= + # Iterate over the output of lsusb -t because it contains the physical port names + while IFS='' read -r line; do + # We need to keep track of the current bus "branch" + if [ "${line#*$busstr}" != "$line" ]; then + if [ -z "$found" -a -n "$cur_bus" ]; then + echo "none" + fi + cur_bus=$busstr + found= + continue + fi + + # Skip all lines not belonging to the wanted bus number + if [ "$cur_bus" != "$busstr" ]; then + continue; + fi + + # check for matching physical USB port, and take only IF 0 into account + if [ "${line#*$portstr}" != "$line" -a "${line#*If 0}" != "$line" ]; then + dev=`echo ${line#*Dev } | cut -d ',' -f 1` + lsusb -s "$bus":"$dev" + found=1 + fi + done<< EOF +$(lsusb -t 2>/dev/null) +EOF +} + +debug_lspci_devs=`lspci -nvvD | + grep -i "^[0-9a-f]|debug port" | + grep -iB1 --no-group-separator "debug port" | + grep -vi "debug port" | + cut -f 1 -d" " | + sort | + xargs echo` + +if [ -z "$debug_lspci_devs" ]; then + printf "No USB controller with debug capability found by lspci.\n +Possible reasons: lspci too old, USB controller does not support a debug device, ... Exiting.\n" + exit 1 +fi +printf "The following PCI devices support a USB debug port (says lspci): $debug_lspci_devs\n" + +debug_dmesg_devs_with_port=`( test -z "$dmesgfile" && + dmesg || + cat "$dmesgfile") | + grep -i "ehci.*debug port" | + sed "s/.* ([0-9a-f]*:*[0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]).*ebug port /\1 /" | + sort` + +debug_dmesg_devs=`echo "$debug_dmesg_devs_with_port" | + cut -f 1 -d" " | + xargs echo` + +if [ -z "$debug_dmesg_devs" ]; then + printf "dmesg does not show any supported ports.\n +Possible reasons: dmesg scrolled off, kernel too old, USB controller does not support a debug device, ... Exiting.\n +Note: You can specify a file containing kernel messages as argument to this program (e.g. /var/log/dmesg)." + exit 1 +fi + +if [ "$debug_lspci_devs" != "$debug_dmesg_devs" ]; then + echo "lspci and the kernel do not agree on USB debug device support. Exiting." + exit 1 +fi + +printf "and the kernel agrees, good.\n\n" + +while true; do + for dev in $debug_dmesg_devs; do + bus=`lsusb -v | + grep "^Bus|iSerial.*" | + grep -B1 --no-group-separator "iSerial.*$dev" | + grep "^Bus" | + sed "s/Bus *0*([0-9a-f]*).*/\1/"` + port=`echo "$debug_dmesg_devs_with_port" | + grep "^$dev" | + cut -f 2 -d" "` + + echo "Device(s) currently connected to the debug-capable port $port on PCI device $dev, USB bus $bus:" + + find_devs_in_tree $bus $port + echo + done + + echo "Press any key to repeat or 'q' to abort" + read r + if [ $? -ne 0 -o "$r" = "q" ]; then + break; + fi +done