How lsusb works

Source: Internet
Author: User
Tags ide hard drive
Article Title: How lsusb works. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
A module is a program running in the kernel space. It is actually a target object file and cannot be run independently without links. However, it can be loaded into the system and run as part of the kernel, in this way, the kernel functions can be dynamically expanded. The main use of the module is to implement the device driver.
  
In Linux, a hardware driver can be directly loaded into the kernel code. When the kernel is started, the hardware device can be driven. The other is to compile a. o file in the module mode. When the application needs to be added to the kernel space for running. Therefore, a hardware driver usually refers to a driver module.
  
   Device Files
For a device, it can have a corresponding logical device node under/dev. This node exists as a file, but it is not a file in the general sense. It is a device file, more specifically, it is a device node. This node is created using the mknod command, which specifies the master device number and secondary device number. The primary device number indicates a certain type of device, which generally corresponds to a specific driver. The secondary device number generally distinguishes different attributes, such as different usage methods, locations, and operations. This device number is obtained from the/proc/devices file. Therefore, the device node is in the directory only when the driver is in the kernel. The main function of this device number (especially the main device number) is to declare the driver used by the device. Drivers correspond to device numbers one by one. When you open a device file, the operating system knows the driver corresponding to the device.
  
   SCSI Device
SCSI is a standard computer interface different from IDE. Nowadays, most flat-board scanners, CD-R recorders, MO optical transceiver and so on gradually tend to use the SCSI interface, coupled with SCSI and can provide a high-speed transmission channel, so, access to SCSI devices more and more users. Linux supports many SCSI devices, such as SCSI hard drives, SCSI optical drives, and SCSI tape drives. More importantly, Linux provides an IDE device for SCSI simulation (ide-scsi.o module), we usually simulate the IDE optical drive for SCSI optical drive access. In Linux, many software can only operate the SCSI Optical Drive. For example, most of the recording software and some media playing software. Generally, our USB storage device simulates access to the SCSI hard disk.
  
   Linux hardware driver architecture
For a hardware, the Linux driver is like this: first, we must provide a. o driver module File (Here we only describe the module mode, in fact, the kernel mode is similar ). To use this driver, first load and run it (insmod *. o ). In this way, the driver will register with the system based on its own type (character device type or block device type, for example, the mouse is a character device and the hard disk is a block device, after successful registration, the system will return a primary device number, which is the unique identifier of the system, the main device we see with ls-l/dev/had must be 3 ). The driver creates a device file that is generally placed in the/dev directory based on the master device number (mknod command is used to create it, it must use the master device Number Parameter ). To access this hardware, you can run open, read, write, and other commands on the device file. The driver will receive the corresponding read and write operations and proceed according to the corresponding functions in its module.
  
There are also a few more related things: one is the/lib/modules/2.4.XX Directory, which is the module for the current kernel version. As long as your module dependency is correct (you can set it through depmod), you can load it using the modprobe command without knowing the location of the specific module File. The other is the/etc/modules. conf file, which defines aliases of some common devices. The system can find the driver module correctly when this device is needed. For example, alias eth0 e100 indicates that the driver module of the first Nic is e100.o. Their relationships are as follows:
  
Apply to Device Files> driver modules> hardware
(Open/read/wnite) | V ^ | -------- |
Kernel -->/etc/modules. conf
Insmod according to alias
  
   Configure a USB device
Kernel configuration.
  
To enable Linux USB support, first go to the "USB Support" section and enable the "support for USB" option (the corresponding module is USB core. o ). Although this step is quite straightforward, the subsequent Linux USB settings will be confusing. In particular, you now need to select the correct USB master controller driver for the system. The options are "EHCI" (ehci-hcd.o for the corresponding module), "UHCI" (usb-uhci.o for the corresponding module), "UHCI (alternate driver)", and "OHCI" (usb-ohci.o for the corresponding module ). This is where many people are confused about Linux USB.
  
To understand "EHCI" and what it is like, you must first know that each motherboard or PCI Card that supports inserting a USB device requires a USB master controller chipset. This special chipset operates with the USB device that is inserted into the system and handles all low-level details necessary to allow the USB device to communicate with other parts of the system.
  
Linux USB drivers have three different USB master controller options because there are three different types of USB chips on the motherboard and PCI Card. The "EHCI" driver is designed to support new high-speed USB 2.0 chips. The "OHCI" driver is used to provide support for USB chips on non-PC systems (as well as on PC boards with SiS and ALi chipsets. The "UHCI" driver is used to support USB implementations on most other PC boards, including Intel and. You only need to select the type corresponding to the USB support you want to enable "? HCI driver. If you are confused, you can enable "EHCI", "UHCI" (either of them, there is no obvious difference between them) and "OHCI" for the sake of insurance ". (Zhao Ming Note: According to the document, EHCI already includes UHCI and OHCI. However, in my personal test, it is impossible to add EHCI separately, generally, I load UHCI or OHCI Based on the motherboard type, and then load EHCI to support the USB2.0 device ).
  
Enable "USB support" and appropriate "? After HCI "USB master controller driver, you only need to perform a few steps to enable and run USB. You should enable "Preliminary USB device filesystem" and ensure that all drivers specific to the actual USB Peripheral that will be used with Linux are enabled. For example, to enable support for USB game controllers, I enabled "USB Human Interface Device (full HID) support ". I also enabled "Input core support" and "Joystick support" under the main "Input core support" section ".
  
If no USB device information is available under/proc/bus/usb, enter the following command to manually mount the USB device file system to/proc/bus/usb:
  
# Mount-t usbdevfs none/proc/bus/usb
  
To automatically mount the USB file system during system boot, add the following line to the/proc mounting line in/etc/fstab:
  
None/proc/bus/usb usbdevfs defaults 0 0
  
   Module configuration method.
In many cases, our USB driver is not included in the kernel. In fact, we only need to load them one by one based on the modules it needs. You can enable it.
  
First, make sure that the corresponding support is selected in the module mode during kernel compilation. In this way, we can see the corresponding. o file in the/lib/modules/2.4.XX directory. When loading a module, we only need to run modprobe xxx. o. (modprobe mainly loads the modules that have been registered by the depmod system. insmod is generally used to load specific. o files)
  
It is critical to correspond to some modules under the USB device.
  
Usb core. o the most basic module required to support usb
Usb-uhci.o (already mentioned)
Usb-ohci.o (already mentioned)
Uhci. o another uhci driver. I Don't Know What To use. Generally, I don't want to load it. It will crash.
Ehci-hcd.o (usb2.0 already mentioned)
Hid. o USB man-machine interface device, like a mouse or a keyboard
Usb-storage.o USB storage equipment, U disk and other use
  
   Related modules
Ide-disk.o IDE Hard Drive
Ide-scsi.o simulate SCSI interface for IDE Devices
Scsi_mod.o SCSI support
  
Note one of the following:
  
Probe all LUNs on each SCSI device
  
It is recommended that you choose not to display only one card reader that supports multiple ports at the same time. If the module mode is used, install it with parameters or add the following items to/etc/modules. conf in advance to support multiple Luns.
  
Add options scsi_mod max_scsi_luns = 9
  
Sd_mod.o SCSI hard drive
Sr_mod.o SCSI Disc
General support for sg. o SCSI (used in some USB flash drives and SCSI probes)
  
Common USB devices and their configurations
Linux 2.4 kernel supports no more than 20 devices. It supports almost all general-purpose devices, such as the keyboard, mouse, modem, and printer, and constantly adds new devices from the manufacturer, such as digital cameras, MP3, and NICs. The following describes how to use the most common devices:
  
   USB mouse:
The keyboard and mouse are low-speed input devices. For PS/2 interfaces that have been recognized by the user, the USB keyboard and USB mouse do not seem to be much more advantageous. Most of the current mouse uses the PS/2 interface, but the USB interface also has more and more mouse, the two have their own advantages: Generally, the bandwidth of the USB mouse interface is greater than the PS/2 mouse, that is to say, in the same period of time, the number of USB mouse scans is more than PS/2, so that the USB mouse is more precise in positioning. At the same time, the default sampling rate of USB interface mouse is also relatively high, up to 125 HZ, while the PS/2 interface only has 40 HZ (Windows 9x/Me) or 60 HZ (Windows NT/2000 ).
  
For USB devices you must first Insert the corresponding USB controller module: usb-uhci.o or usb-ohci.o
  
Modprobe usb-uhci
  
To make the USB mouse work properly, you must first Insert the module USB mouse. o and mousedev. o
  
Modprobe USB mouse
Modprobe mousedev
  
If you install the HID input layer and input core as modules, it is also necessary to start the hid and input modules.
  
Modprobe hid
Modprobe input
  
   USB keyboard:
  
Generally, most of the keyboards we use today are PS/2, and USB keyboards are rare. However, the development of the keyboard will move closer to the USB interface. There are basically no many requirements for using a USB keyboard. You only need to set the support for the USB keyboard in the BIOS of the motherboard, and then you can use the USB keyboard completely in various systems, it can also be used in plug-and-play and hot swapping, and provides two USB ports: allowing you to easily connect devices with USB connectors to your keyboard, rather than counting
Related Article

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.