How lsusb works

Source: Internet
Author: User
Tags ide hard drive

Http://www.bitscn.com/ OS /linux/200604/7305.html

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 is generally
Differentiate different attributes, such as different usage methods, different locations, and different operations. This device number is obtained from the/proc/devices file, so the driver is usually in the kernel first,
In the directory. 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 different from
A standard computer interface of IDE. Nowadays, most flat-board scanners, CD-R recorders, MO optical transceiver and so on gradually tend to use the SCSI interface, and SCSI can provide a high-speed transmission
Therefore, more and more users will be exposed to SCSI devices. Linux supports many SCSI devices, such as SCSI hard disks, SCSI optical drives, and SCSI
Tape drive. 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.
Q.
  
  Linux hardware driver architecture
For a hardware, Linux is driven like this: first
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 registers 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 report a master device.
ID, which is the unique identifier of the system.
The main device that/dev/had sees must be 3 ). The driver is to create 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
Master device number ). To access this hardware, you can run open, read, write, and other commands on the device file. The driver will receive the corresponding read,
Write operations are performed according to the corresponding functions in the module.
  
There are also a few more related things: one is/lib/modules
/2.4.xx Directory, which contains the modules for the current kernel version. As long as your module dependency is correct (you can set it through depmod), you can use modprobe
You do not need to know the file location of a specific module. The other is the/etc/modules. conf file, which defines aliases of some common devices. The system can,
Find the driver module correctly. 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 "support
USB "option (corresponding module is USB core. O ). Although this step is quite straightforward, the next Linux USB
The setup steps are confusing. In particular, you now need to select the correct USB master controller driver for the system. The option is "EHCI"
(Corresponding module is ehci-hcd.o), "uhci" (corresponding module is usb-uhci.o), "uhci (Alternate)
Driver) "and" OHCI "(corresponding module is usb-ohci.o ). 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
Chip. The "EHCI" driver is designed to support new high-speed USB 2.0 chips. The "OHCI" driver is used for non-PC systems (and
Supported by USB chips on the PC motherboard of the SIS and Ali chipset. The "uhci" driver is used for most other PC boards (including Intel and
Via. You only need to select the USB
The supported types correspond "? HCI driver. Enable "EHCI" and "uhci" for the sake of insurance"
(Either of them has no obvious difference) and "OHCI ". (Zhao Ming Note: According to the document, EHCI already includes uhci and OHCI, but currently I am personally testing it, separately adding
EHCI does not work. Generally, I load uhci or OHCI Based on the motherboard type, and then load EHCI to support the USB2.0 device ).
  
Qi
"USB support" and appropriate "? After HCI "USB master controller driver, Enable USB
Start and run in just a few steps. You should enable "Preliminary USB device filesystem" and ensure that all
Driver of the actual USB peripheral device used in Linux. For example, to enable support for USB game controllers, I enabled USB human
Interface Device (full hid) support ". I also enabled the master "input core support"
"Input core support" and "joystick support" under 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 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
PS/2 interfaces, 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 PS/2 mouse, that is, in the same time,
The number of USB mouse scans is more than PS/2, so that the USB mouse is more precise on positioning. At the same time, the default sampling rate of USB mouse is also relatively high, reaching 125Hz, PS/2 Interfaces
Only 40Hz (Windows 9x/ME) or 60Hz (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 requirements for using a USB keyboard,
You only need to set the support for the USB keyboard in the BIOS of the motherboard, so that you can use the USB keyboard completely in various systems, and can be used in plug-and-play and hot swapping, two USB connections are available.
Port: allows you to easily connect devices with USB connectors to your keyboard instead

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.