Linux 上USB 調試神器lsusb命令詳解

大家好, 我是吉阿, 今天給大家介紹Linux上USB調試工具lsusb命令。

? USB,是英文Universal Serial Bus(通用串行總線)的縮寫,是一個外部總線標準,早期用于規范電腦與外部設備的連接和通訊。

? USB連接自從首次推出到現在已經有23年,這種技術在全球電子行業中的擴展速度前所未有。USB現在已經擁有超過30億端口的年出貨量,是迄今為止最常用的接口技術,筆記本電腦、平板電腦、智能手機和其他各種設備都依賴于這種技術來進行功率和數據傳輸。今天USB已經遠遠超出其最初提供的功能,所支持的數據速率和功率水平都提高了幾個數量級。而且,由于這種不斷發展的推動,USB技術已經比任何其他連接解決方案都更加普及。

? 在Linux上,我們可以使用lsusb來列出USB設備和它的屬性。

什么是lsusb

? 在它的手冊上,lsusb定義成:

顯示系統中以及連接到系統的USB總線信息的工具。

如何運行lsusb?

? 要運行lsusb,你可以直接在命令終端里輸入lsusb

$ lsusb

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 002 Device 003: ID 17ef:4811 Lenovo Integrated Webcam [R5U877]

Bus 008 Device 002: ID 0a5c:217f Broadcom Corp. Bluetooth Controller

lsusb會顯示連接到USB總線上的設備信息和驅動信息。

下面介紹如何理解輸出。我抓取了上面輸出的最后一行:

Bus 008 Device 002 : ID 0a5c:217f Broadcom Corp. Bluetooth Controller

Bus 008?: 指明設備連接到哪條總線

Device 002?: 表明這是連接到總線上的第二臺設備

ID?: 設備的ID

Broadcom Corp. Bluetooth Controller?:生產商名字和設備名

在插入USB設備后, 使用dmesg命令可以看到USB設備加載時Linux內核輸出的調試信息。

下面是一個例子, 我們可以看到該設備同時使用了USB2.0 root hub驅動和USB 1.1 root hub驅動。

$ dmesg |grep -i usb

[ 0.353138] usbcore: registered new interface driver usbfs

[ 0.353150] usbcore: registered new interface driver hub

[ 0.353182] usbcore: registered new device driver usb

[ 0.730026] ehci_hcd: USB 2.0 ‘Enhanced’ Host Controller (EHCI) Driver

[ 0.730116] ehci_hcd 0000:00:1a.7: new USB bus registered, assigned bus number 1

[ 0.748019] ehci_hcd 0000:00:1a.7: USB 2.0 started, EHCI 1.00

[ 0.748169] hub 1-0:1.0: USB hub found

[ 0.748336] ehci_hcd 0000:00:1d.7: new USB bus registered, assigned bus number 2

[ 0.768019] ehci_hcd 0000:00:1d.7: USB 2.0 started, EHCI 1.00

[ 0.768147] hub 2-0:1.0: USB hub found

[ 0.768236] ohci_hcd: USB 1.1 ‘Open’ Host Controller (OHCI) Driver

[ 0.768251] uhci_hcd: USB Universal Host Controller Interface driver

如何列出USB詳細信息

使用-v選項來開啟USB設備的詳細信息。下面是一個例子。

$ lsusb -v

Interface Descriptor:

bLength 9

bDescriptorType 4

bInterfaceNumber 1

bAlternateSetting 5

bNumEndpoints 2

bInterfaceClass 224 Wireless

bInterfaceSubClass 1 Radio Frequency

bInterfaceProtocol 1 Bluetooth

iInterface 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0×83 EP 3 IN

bmAttributes 1

Transfer Type Isochronous

Synch Type None

Usage Type Data

wMaxPacketSize 0×0040 1x 64 bytes

bInterval 1

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0×03 EP 3 OUT

bmAttributes 1

Transfer Type Isochronous

Synch Type None

Usage Type Data

wMaxPacketSize 0×0040 1x 64 bytes

bInterval 1

找出連接了多少USB設備

使用下面的命令:

$ find /dev/bus

接著你會看到像下面的輸出:

/dev/bus

/dev/bus/usb

/dev/bus/usb/008

/dev/bus/usb/008/002

/dev/bus/usb/008/001

/dev/bus/usb/007

/dev/bus/usb/007/001

/dev/bus/usb/006

/dev/bus/usb/006/001

/dev/bus/usb/005

/dev/bus/usb/005/001

/dev/bus/usb/004

/dev/bus/usb/004/001

/dev/bus/usb/003

/dev/bus/usb/003/001

/dev/bus/usb/002

/dev/bus/usb/002/004

/dev/bus/usb/002/003

/dev/bus/usb/002/001

/dev/bus/usb/001

/dev/bus/usb/001/001

使用lsusb?命令 的-D?選項,你可以打印特定設備的詳細信息。下面是一個博通藍牙設備的示例。

$ lsusb -D /dev/bus/usb/008/002

Device: ID 0a5c:217f Broadcom Corp. Bluetooth Controller

Couldn’t open device, some information will be missing

Device Descriptor:

bLength 18

bDescriptorType 1

bcdUSB 2.00

bDeviceClass 224 Wireless

bDeviceSubClass 1 Radio Frequency

bDeviceProtocol 1 Bluetooth

bMaxPacketSize0 64

idVendor 0x0a5c Broadcom Corp.

idProduct 0x217f Bluetooth Controller

bcdDevice 3.60

iManufacturer 1

iProduct 2

iSerial 3

bNumConfigurations 1

Configuration Descriptor:

bLength 9

bDescriptorType 2

wTotalLength 216

bNumInterfaces 4

bConfigurationValue 1

iConfiguration 0

bmAttributes 0xe0

Self Powered

Remote Wakeup

MaxPower 0mA

Interface Descriptor:

bLength 9

bDescriptorType 4

bInterfaceNumber 0

bAlternateSetting 0

bNumEndpoints 3

bInterfaceClass 224 Wireless

bInterfaceSubClass 1 Radio Frequency

bInterfaceProtocol 1 Bluetooth

iInterface 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0×81 EP 1 IN

bmAttributes 3

Transfer Type Interrupt

Synch Type None

Usage Type Data

wMaxPacketSize 0×0010 1x 16 bytes

bInterval 1

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0×82 EP 2 IN

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0×0040 1x 64 bytes

bInterval 1

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0×02 EP 2 OUT

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0×0040 1x 64 bytes

bInterval 1

找出大容量存儲設備

lsusb -v給了我們很詳細的信息,如果輸出信息很多,那么你或許會錯過一些信息。我們可以使用grep命令指定特定的信息。

大容量存儲設備會有一個供應商名和ID。我們可以用它作為一個起點。

$ lsusb -v |grep -Ei ‘(idVendor|Mass\ Storage)’

idVendor 0×1005 Apacer Technology, Inc.

bInterfaceClass 8 Mass Storage

你可以看到,我們系統上有一個來自Apacer Technology, Inc的USB大容量存儲設備。

或者你可以使用-s選項來過濾你的設備

sudo lsusb -v -s [BUS_NUMBER]:[DEVICE_NUMBER]

例如:

sudo lsusb -v -s 002:006

以樹層級結構輸出USB設備

使用?-t選項來用樹形結構來輸出USB設備信息.

$ lsusb -t

/: Bus 08.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 07.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 06.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 05.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 04.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 03.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M

/: Bus 02.Port 1: Dev 1, Class=root\_hub, Driver=ehci_hcd/6p, 480M

|__ Port 1: Dev 4, If 0, Class=stor., Driver=usb-storage, 480M

|__ Port 6: Dev 3, If 0, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M

|__ Port 6: Dev 3, If 1, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M

/: Bus 01.Port 1: Dev 1, Class=root\_hub, Driver=ehci_hcd/6p, 480M

數字12M和480M?是指USB類型的傳輸速率

12M 意味著 USB 1.0 / 1.1的速率是 12Mbit/s

480M 意味著 USB 2.0的速率是 480Mbit/s

如果你找到5.0G,那意味這你有USB 3.0類型接口。它有5.0Gbit/s的傳輸速率。

Linux從/var/lib/usbutils/usb.ids識別USB設備的詳細信息。或者你可以訪問Linux-USB.org獲取最新的USB ID列表。

總結:

你可以用lsusb命令對你的系統上的USB設備做一個診斷。想要了解更全面的命令信息, 輸入man lsusb來查看它的手冊。

附錄:

USB技術標準

? 目前USB支持5種數據信號速率,USB設備應該在其外殼或者有時是自身上正確標明其使用的速率。USB-IF進行設備認證并為通過兼容測試并支付許可費用的設備提供基本速率(低速和全速)和高速的特殊商標許可。

1.5 Mbps的低速速率。主要用于低速率[人機接口設備],例如鍵盤、鼠標、游戲桿等等。

12 Mbps的全速速率。在USB 2.0之前是曾經是最高速率,后起的更高速率的高速接口應該兼容全速速率。多個全速設備間可以按照先到先得法則劃分帶寬;使用多個等時設備時會超過帶寬上限也并不罕見。所有的USB連接端口支持全速速率。

480 Mbps的高速速率。并非所有的USB 2.0設備都是高速的。高速設備插入全速連接端口時應該與全速兼容。而高速連接端口具有所謂事務翻譯器(Transaction Translator)功能,能夠隔離全速、低速設備與高速之間數據流,但是不會影響供電和串聯深度。

5Gbps的超高速速率。相較于現有USB 2.0的480Mbps最高理論速度,USB 3.0可支持到5.0Gbps,是USB 2.0的10倍。若將USB 3.0應用到外置硬盤、U盤或藍光刻錄機等存儲設備,將可大幅縮短數據傳輸時間。

10Gbps的超高速速率+。USB 3.1 Gen2最高10Gbps理論速度,是USB 3.0的兩倍。

USB4規范已于2019年9月3日正式公布, 規格和草案階段相同. 歸納如下:

物理接口只有 USB Type-C 一種.

傳輸速率 40 Gbps.

向下兼容 USB 3.2 / USB 2.0 和 Thunderbolt 3.

機械和電子標準

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。