How to view USB devices

Source: Internet
Author: User
Tags dmesg

1. Introduction

What is USB?

USB stands for the universal serial bus, which is an extended interface standard used for communication between different computers or peripheral devices. Some popular USB devices include keyboards, mice, USB flash drives, digital cameras, CD and DVD external readers, and printers.

Currently, there are two USB standard versions: USB 1.1 and USB 2.0. Because the previous version of USB is always backward compatible, USB 2.0 is compatible with USB 1.1. The latest USB devices generally support USB 2.0. USB 2.0 supports a maximum data transmission rate of 480 Mbps and 60 Mbps, which is the data transmission rate of USB 2.0 compatible with USB 1.1. USB also supports hot swapping of devices, which means you do not have to restart the system to use the USB device.

Technical Analysis

Before configuring the USB Kernel, let's take a look at some of its knowledge details. If you do not have much time or want to read this section, you can directly read the section on Kernel configuration.

The USB system has a host controller, some hubs (not the "Hub" in the network tool), and one root hub ), the maximum number of USB devices that the root hub can connect to is 127. The master controller is only a hardware interface between the USB device and the operating system. There are currently two main controller interfaces (HCI, Host Controller Interface): Compaq OHCI (Open HCI), Intel uhci (Universal HCI) and EHCI (enhanced HCI ). OHCI/uhci is an industrial standard for USB 1.1, while EHCI is for USB 2.0.

Hardware vendors provide developers with interfaces, known as HCD (host controller device ). With HCD, USB devices can interact with system software. The figure below makes it easier to understand this.

Code 1.1: general USB Architecture

(The software layer also has components such as device drivers, but for the purpose of simplifying the problem, I will skip it here) + ---- hardware ---- + ---- software ---- + | [USB Dev]-+-> {EHCI}-+ ---> (ehcd) | user | '-> {uhci}-+ ---> (uhcd) | + ---- hardware ---- + ---- software ---- +

USB devices can have independent drivers or use the drivers provided by the system, depending on the device category. That is to say, if a USB device belongs to a certain category, other devices belonging to this category can use the same device driver. Some USB device categories are USB hid (Human Interface Device) categories, which include: input devices, such as keyboards and mice, USB block storage devices, such as USB flash drives, digital cameras, and audio players; usb cdc (communication devices Class, communication device category), such as USB port modem or other similar devices.

What's on your machine?

You can use lspci to check whether your machine supports USB 2.0.

Note:The lspci tool is part of the Sys-apps/pciutils package. If this package is not installed, please emerge pciutils. Note that the root user must be authorized to execute the lspci command.

Code 1.2: lspci output

(The system is compatible with USB 1.1, that is, the uhci Interface) # lspci-v | grep usb0000: 00: 04.2 USB controller: Intel Corp. 82371ab/EB/MB piix4 USB (Rev 01) (prog-If 00 [uhci]) (a system that is USB 2.0 compliant, note the EHCI and uhci) 00: 1D. 0 USB controller: Intel Corp. 82801db USB (hub #1) (Rev 01) (prog-If 00 [uhci]) 00: 1D. 1 USB controller: Intel Corp. 82801db USB (hub #2) (Rev 01) (prog-If 00 [uhci]) 00: 1D. 2 USB controller: Intel Corp. 82801db USB (hub #3) (Rev 01) (prog-If 00 [uhci]) 00: 1D. 7 USB controller: Intel Corp. 82801db usb ehci controller (Rev 01) (prog-if 20 [EHCI])

Using lspci, you can determine whether the system supports USB 2.0, which is useful when configuring kernel compilation options.

 

3. view the working status of the USB device

Dmesg is your friend!

Now it's time to dance with USB devices. :) In this chapter, we will see how the system responds to various USB devices. Start with a m USB flash drive. You can also use other similar devices. We mainly use dmesg to check what happened after the USB flash disk is inserted and how the system responds.

Note:Dmesg outputs a large amount of redundant information before displaying the required information, because it needs to read the kernel's ring buffer and output a lot of startup information. In the following example, only a portion of the output information is provided. For better reading, some blank lines are added. It is better to use dmesg | more or dmesg | less to view output information.

Code 3.1: dmesg output of the memory stick

(First insert the USB flash drive into the available USB port, then...) # dmesg | less (the current device is identified as USB 1.1 and assigned an address for it. This also shows which HCd is being used) USB 1-1: new full speed USB device using uhci_hcd and address 2 (the SCSI simulator will automatically load) scsi0: SCSI emulation for USB Mass Storage devicesusb-storage: device found at 2 (currently, device information, including module numbers, can be retrieved) USB-storage: waiting for device to settle before scanning vendor: jetflash model: ts512mjf2a Rev: 1.00 type: Direct-access ansi scsi revision: 02 SCSI device SDA: 1003600 512-byte hdwr sectors (514 MB) (write protection statement is the experimental code of the new kernel version in the future) SDA: write protect is offsda: Mode sense: 0b 00 08sda: Assuming drive cache: Write throughscsi device SDA: 1003600 512-byte hdwr sectors (514 MB)/dev/SCSI/host0/bus0/target0/lun0: p1attached SCSI removable disk SDA at scsi0, channel 0, Id 0, lun 0 Attached SCSI generic sg0 at scsi0, channel 0, Id 0, Lun 0, type 0usb-storage: Device scan complete (here, devices can usually be accessed through mounting/dev/sda1) (when the device is disconnected, the system will provide such feedback) USB 1-1: USB disconnect, address 2

Once the device is connected and mounted, it can be accessed as a normal hard disk. Some popular operations, such as CP, MV, and RM, can be executed normally. You can also create a file system on a USB flash drive.

Code 3.2: access a USB flash drive

# mount /dev/sda1 /mnt/usb# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/hda8             9.4G  7.5G  1.9G  80% //dev/hda9              11G  8.1G  2.4G  78% /usrnone                  189M     0  189M   0% /dev/shm/dev/sda1             490M   34M  457M   7% /mnt/usb

Note:You can also access a digital camera like a USB flash drive. I once had a Nikon coolpix 5200, And I accessed it in this way. There are usually two computer-oriented transmission modes for images in digital cameras: USB Block Storage and PTP (picture transfer protocol ). If the camera is set to a USB block storage mode, it will be the same as the USB flash drive access process described above, but you should also note that this is not universally applicable.

What is the case for a USB mouse? It should be displayed as a HID device.

Code 3.3: USB Optical Mouse

# dmesg | grep USBdrivers/usb/input/hid-core.c: v2.0:USB HID core driverusb 1-1: new low speed USB device using address 2input: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:00:07.2-1

Another trendy command, lsusb, allows you to view your USB port. This command is part of the Sys-apps/usbutils software package, which will be introduced in the next chapter.

4. user-level USB

Trendy tools

The kernel/system has seen a lot of support for USB. Now we will look at the user-level support provided by Gentoo for USB.

Lsusb is a very useful tool. It can list all USB devices connected to the system, and it is easy to install.

Code 4.1: Install usbutils

# emerge usbutils

After installation, run lsusb to obtain brief information about the USB device connected to the machine.

Note:Generally, you must run lsusb as the root user.

Warning:Lsusb reads USB device information from/proc/bus/USB. lsusb will not work if the corresponding configuration is not performed during kernel compilation. Therefore, be sure to enable/proc file system support for your Kernel configuration and ensure that usb fs is mounted on/proc/bus/USB (this is the case by default ).

Code 4.2: Execute lsusb

# lsusb(This is the 512 MB Memory Stick from Transcend)Bus 001 Device 003: ID 0c76:0005 JMTek, LLC. USBdisk(This is the Optical Mouse)Bus 001 Device 002: ID 046d:c00e Logitech, Inc. Optical Mouse(This is the root hub)Bus 001 Device 001: ID 0000:0000

If you like to read a lot of output information, running lsusb-V can satisfy your desire. Another useful option for lsusb is to give the tree information of the current USB physical hierarchy, which makes it easier for you to accurately understand the device architecture. This command is lsusb-T, for example:

Code 4.3: lsusb display USB Physical Layer

# lsusb -tBus#  1`-Dev#   1 Vendor 0x0000 Product 0x0000  |-Dev#   2 Vendor 0x046d Product 0xc00e  `-Dev#   3 Vendor 0x0c76 Product 0x0005

It is easy to associate lsusb with lsusb-T output information, which helps debugging and understanding the working mechanism of USB.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.