Hardware Drive (on) (on) (on) (Drive Configuration section) under Linux

xiaoxiao2021-03-06  109

Zhao Ming (carl__zhao@163.com)

Lenovo Software Design Center Embedded R & D system design engineer

July 2003

There are more and more USB devices, and Linux still does not completely plug and play on hardware configuration. How to configure and use them for Linux, it is increasingly bursting a big problem. This article focuses on how to drive from the device under the Linux system, explain how to use and configure and how to develop USB device drivers. For general users, we can make our clear Linux device driver, providing convenience for better configuring and using USB devices; and providing a preliminary learning USB driver architecture for programmers who want to develop USB devices under Linux systems.

Foreword

USB is an abbreviation of English "Universal Serial Bus" means "Universal Serial Bus". It is made by Compaq (Coop), DEC, IBM, Intel, NEC, Microsoft, and Northern Telecom, in November 1994, the main purpose is to solve too many drawbacks of interface standards. USB uses a 4-pin plug as a standard plug, and through this standard connector, use the chrysanthemum petal form to connect all peripherals, which transmit data in serial mode, currently maximum data transfer rate is 12Mbps, supports multi-data streams and multiple Equipment parallel operation, allowing external thermal plugging.

At present, although the USB interface has only developed 2 generations (USB 1.0 / 1.1, USB2.0), USB integrates all the advantages of multi-platform standards - including reduced costs, increasing compatibility, connecting large quantities of external devices, integration Advanced features and quality. Make it gradually become a PC interface standard and entered a high-speed development period.

Then use the Linux system to properly support and configure common USB devices, it is a key step for its use.

Related technical foundation

Module (driver)

Module is a program running in kernel space. It is actually a target object file, no link, cannot run independently, but can be loaded into a part of the kernel as part of the kernel, so that the function of the kernel can be dynamically expanded. The main use of modules is used to implement device drivers.

With a hardware driver under Linux, there can be two ways: directly load into the kernel code, the hardware device is driven when the kernel is started. The other is to compile one .o file in module. When the application needs to be loaded, the kernel space is loaded. So a hardware driver we say, usually refers to a drive module.

Device file

For a device, it can have a corresponding logic node below / dev, which exists in the form of a file, but it is not an ordinary file, it is a device file, but more precisely, it is a device node. This node is established by mknod command, which specifies the main device number and the secondary device number. The main device number indicates a certain type of device, which generally corresponds to the determined driver; the secondary device number is generally distinguishing between different properties, such as different use methods, different locations, different operations. This device number is obtained from the / proc / defics file, so it is generally in the first driver in the kernel, and there is a device node in the directory. The main role of this device number (Special Equipment Number) is to declare the drivers used by the device. Drivers and device numbers are one or one, when you open a device file, the operating system already knows the driver corresponding to this device.

SCSI equipment

SCSI is a computer standard interface that is different from IDE. Most flat-panel scanners, CD-R burner, MO-optical drives, etc. gradually tend to use SCSI interfaces, and SCSI can provide a high-speed delivery channel, so users who come into contact with SCSI devices will be more and more. Linux supports many SCSI devices, such as SCSI hard drives, SCSI drive, SCSI tape drives. More importantly, Linux provides IDE devices to SCSI analog (IDE-SCSI.O module), we usually access the IDE CD-ROM to the SCSI drive. Because many software in Linux can only operate the SCSI CD-ROM. For example, most burning software, some media play software. Usually our USB storage device also simulates access to the SCSI hard drive. Linux hardware drive architecture

For a hardware, Linux is driver: First, we must provide a .o driver module file (here we only explain the module mode, in fact, the kernel mode is similar). We want to use this driver, first load it (Insmod * .o). This drive will be based on its own type (character device type, or block device type, such as the mouse is a character device, the block device is block device), the registration success system will feedback a master number, this master number is the system to it The unique identifier (such as the main device number displayed in / proc / devices), and the main device we see with ls -l / dev / had is definitely 3). The driver is based on this master number to create a device file that is typically placed in the / dev directory (MKNOD command is used to create it, it must use the master number). When we want to access this hardware, you can perform commands for the device file via Open, Read, Write. The driver will receive the corresponding READ, WRITE operation, and according to the corresponding functions in your module.

There are also a few more relationships: one is a /lib/modules/2.4.xx directory, which is the module for the current kernel version. As long as your module dependencies are correct (can be set via DEPMOD), you can load through the ModProbe command without having to know the specific module file location. The other is a /etc/modules.conf file, which defines some alias for common devices. The system can be used to properly find the drive module when you need this device. For example, Alias ​​Eth0 E100, representing the driver module of the first network card is E100.O. Their relationship diagram is as follows: (see Figure 1)

Configure USB devices

Configuration in the kernel.

To enable Linux USB support, first enter the USB Support section and enable the "Support for USB" option (the corresponding module is USBCore.O). Although this step is quite straightforward, the next Linux USB setting step will make people feel confused. In particular, you need to choose the correct USB main controller driver for the system. The option is "EHCI" (corresponding module for ehci-hcd.o), "UHCI" (corresponding module is USB-UHCI.O), "ALTERNATE DRIVER" and "OHCI" (corresponding module is USB-OHCI.O ). This is where many people have been confused about the USB of Linux.

To understand what "EHCI" and its similarity, you must first know that the USB main controller chipset must be required each of the motherboard or PCI card that supports the USB device. This special chipset is interoperable with the USB device of the insertion system and is responsible for processing all low-level details that allow USB devices to communicate with other part of the system. The Linux USB driver has three different USB main controller options because there are three different types of USB chips on the motherboard and PCI cards. "EHCI" driver is designed to provide support for chips that implement new high-speed USB 2.0 protocols. The "OHCI" driver is used to provide support for the USB chip on the non-PC system (and the PC motherboard with SIS and Ali chipsets). "UHCI" driver is used to support most other PC motherboards (including Intel and Via). Simply select the "? HCI" driver corresponding to the type of USB support you want to enable. If you have doubts, you can enable "EHCI", "UHCI" for your insurance, and there is no obvious difference between them, and "OHCI". (Zhao Ming Note: According to the document, EHCI already contains UHCI and OHCI, but now I have a personal test, I will add EHCI alone, usually, I will load UHCI or OHCI according to the motherboard type, then load EHCI. USB2.0 devices can be supported.

After the "USB Support" and the appropriate "? HCI" USB main controller driver, the USB starts and runs only a few steps. "Preliminary USB Device FileSystem" should be enabled, then make sure that all drivers specific to the actual USB peripheral device that will be used with Linux are enabled. For example, in order to enable support for the USB game controller, I enable "USB Human Interface Device Support". I also enable "INPUT CORE Support" and "Joystick Support" under the main "Input Core Support" section.

Once you use the newly enabled kernel to reboot, if there is no corresponding USB device information under / proc / bus / usb, you should enter the following command to manually mount the USB device file system to / proc / bus / usb:

# Mount -t USBDEVFS NONE / PROC / BUS / USB

In order to automatically pin up the USB device file system when the system is booted, add the following line to the / PROC mount row in / etc / fstab:

None / Proc / Bus / USB USBDEVFS Defaults 0 0 0

Module configuration method.

In many cases, our USB device driver is not included in the kernel. In fact, we will load one by one according to the modules it needs. You can make it up.

First, make sure that the corresponding support is selected in the module mode when compiling in the kernel. This way we should be able to see the corresponding .o file in the /lib/modules/2.4.xx directory. When loading the module, we only need to run ModProbe XXX.O (ModProbe's primary load system has passed DEPMOD), INSMOD is generally loaded for specific .o files)

Some of the modules below for the USB device are critical.

USBCore.O to support the most basic modules required for USB

USB-UHCI.O (already mentioned)

USB-OHCI.O (already mentioned) UHCI.o another UHCI driver, I don't know what to use, generally don't load, will crash

EHCI-HCD.O (already mentioned USB2.0)

Hid.o USB human-machine interface equipment, like a mouse, keyboard

USB-Storage.o USB storage device, U disk, etc.

Related module

IDE-Disk.o IDE hard drive

IDE-SCSI.O puts the IDE device simulates the SCSI interface

SCSI_MOD.O SCSI support

Note one of the Kernel Config:

Probe All Luns on Each SCSI Device

It is best to select, you can only support multiple port readers simultaneously, you can only display one. If the module mode is to be installed with parameters or add the following in /etc/modules.conf to support multiple LUNs.

Add Options SCSI_MOD MAX_SCSI_LUNS = 9

SD_MOD.O SCSI hard disk

SR_MOD.O SCSI CD

SG.O SCSI General Support (used in some probe U disk, the SCSI detection)

Common USB device and its configuration

20 devices have been supported in the kernel of Linux 2.4. It supports almost all universal devices such as keyboard, mouse, modem, printer, etc., and constantly adds vendors' new equipment like digital cameras, MP3, NIC, etc. Here is a few most common equipment introductions and how to use:

USB mouse:

The keyboard and mouse are low-speed input devices, and the USB keyboard and USB mouse do not seem to be more superior place for the PS / 2 interface approved by the user. Most of the mouse now uses the PS / 2 interface, but the USB interface has more and more, the two have advantages: Generally, the bandwidth of the USB mouse interface is greater than the PS / 2 mouse, that is It is more precise than the PS / 2 mouse in the same time, so the USB mouse is more accurate in the positioning of the USB mouse; the default sampling rate of the USB interface mouse is relatively high, reaching 125 Hz, and PS / 2 The interface is only 40Hz (Windows 9X / ME) or 60 Hz (Windows NT / 2000).

You must of course insert the appropriate USB controller module for a USB device: USB-UHCI.O or USB-OHCI.O

Modprobe USB-UHCI

Usb mouse In order to make it working properly, you must first insert module USBMouse.o and MouseDev.o

Modprobe USBMOUSE

Modprobe MouseDev

If you use HID INPUT LAYER support and Input Core support as a module mode, it is also necessary to start the HID module and the INPUT module.

Modprobe hid

Modprobe INPUT

USB keyboard:

In general, the keyboard we use now is PS / 2, the USB keyboard is relatively rare, but the development, the keyboard will be close to the USB interface. With the USB keyboard basically do not have much requirement, just need to support the USB keyboard on the BIOS setting of the motherboard, you can use it all in the system, and you can really do in plug and play and hot plug. To use, and provide two USB connections: allowing you to easily connect the device with USB connector directly on your keyboard instead of apertorter.

You must of course you must first insert the corresponding USB controller module: USB-UHCI.O or USB-OHCI.O

Modprobe USB-UHCI

You must then insert the keyboard module USBKBD.O, as well as KeybDev.o, so the USB keyboard can work properly. At this point, the running system command: modprobe usbkbd

Modprobe KeyBDEV

Similarly if you use HID Input Layer Support and Input Core support as a module mode, it is also necessary to start the HID module and the INPUT module.

U disk and USB card reader:

Digital storage devices are now quite common for us. CF cards, SD cards, Memory Stick, etc. have spread around us, usually, their card readers are USB interfaces. In addition, many MP3, digital cameras are also USB interfaces and computers for data delivery. More U disk, USB hard drive, as a mobile storage device, has become our must be equipped.

These devices under Linux are typically driven in a way known as USB-Storage. To use them must load this module

Modprobe USB-Storage

Of course, USBCore.O and USB-UHCI.O or USB-OHCI are definitely indispensable. Also, if SCSI support is also a module, then the following modules should be loaded.

Modprobe SCSI_MOD

Modprobe SD_MOD

After loading these modules, we will find a SCSI hard drive in the system, you can use it in the system, you can use it (SCSI hard drive is usually / DEV / SD?] Frequently Asked Question

Mount / DEV / SDA1 / MNT

Other USB devices supported by Linux.

Modem - Comparable)

Internet equipment

Camera - (more common), for example ov511.o

Online line - you can make your two computers to realize network functions in USB cable. USBNET.O

Display - (I have never seen)

Jam

TV box - (more common)

Handwriting board - (more common)

Scanner - (more common)

Strambler - (more common)

Printer - (more common)

Note: Every drive module mentioned above is not manually loaded. There are many systems that will be automatically loaded when they are started or your application needs, which is convenient for you to use USB devices. You can check it yourself. As long as you use lsmod to ensure that the above modules have been loaded, your device should work properly. Of course, some modules have existed when they have kernel in kernel (these module files) are not found in /lib/modules/2.4.xx).

Usb problem most often

1. System for USB device is installed with RedHat 7.3 launching crash problem

There are USB devices, when you just started RedHat 7.3, it will always die. The main reason is that Linux detects two controllers with USB-UHCI and EHCI-HCDs during installation, but when starting, the USB-UHCI will conflict with the USB-UHCI. Analysis believes that the REDHAT7.3 system kernel has problems in supporting USB 2.0 standards. This problem does not exist in other versions of Linux.

Workaround: Parameters init = / sbin / init when LILO or GRUB starts. This will not run other services directly after startup. Then run

Mount -o remount, RW / write, INIT directly started system default mount / for read-only

Then vi /etc/modules.config file

Remove the Alias ​​USB-Controller1 EHCI-HCD. Or front plus # 注释 然后 然后 m o o o / 读 读 读 读 读 读 读 读 系统 系统

Then you can press Ctrl-alt-delete directly to directly

Perhaps you have a simpler way: Change the USB keyboard and the mouse to the PS2 interface, start the /etc/modules.config file after startup.

2. We already know that the U disk will simulate access to SCSI devices in Linux. How do you know that it corresponds to that SCSI device?

Method 1: Speculating. Usually you first insert an SCSI device, which is SDA, the second is that SDB is pushed. You start Linux inserting a U disk, try SDA, change one may be SDB. Here is to pay attention to two special examples: 1) You use the Lenovo USB flash drive, it may exist in two device area (a computer for encryption or start the computer), which may take two SDAs, SDBs once again, change the U disk is SDC SDD. 2) Lenovo digital computers may already have a six-in-one card reader. It is also a USB storage device. It will occupy one or two SCSI device numbers.

Method 2: See information. In fact, as long as you put USB-storage.o, SCSI_MOD.O, SD_MOD.O module in advance (you can directly in Kernel), when you insert and unplug the U disk, the system will automatically play information as follows:

SCSI Device SDA: 60928 512-BYTE HDWR SECTORS (31 MB

SDA: WRITE PROTECT IS ON

According to this information, you know that it is on the SDA. Of course, it may be relatively high in your system information, and the above information may not be played, this time you can see it as long as tail / var / log / messages.

Method 3: Similarly, CAT / Proc / Partitions can also see partition information, where SD is the U disk. If there is no SD device at all, check if your SCSI module and the USB-Storage module are loaded correctly.

3. When using a U disk or a memory card, what do I or / DEV / SDA1?

This is a historical legacy problem. The initial size of the memory card is small. Many vendors are in use, they are directly used, and they do not contain partition table information. As the memory card size continues to expand, it also introduces the concept of a hard disk partition. For example / dev / hda, you can divide the primary partition HDA1, HDA2 extension partition HDA3, and then divide the extended partition HDA3 into logical partitions HDA5, HDA6, HDA7, etc. Thus, the usual U disk is divided into one partition SDA1, and similar to the entire partition of the hard disk into a primary partition HDA1. In fact, we can completely be divided into SDA1, SDA2 or even logical partitions SDA5, SDA6 by FDISK / DEV / SDA. In fact, you do this for USB hard drives, because it is usually how much G's capacity. And usually, it is a laptop hard drive.

A fun question. You have made multi-partitions with FDISK / DEV / SDA under Linux. At this time, go to Windows, you will find how to find, how to format it, the U disk can only find the first partition size size, and use There is no problem. This is mainly because Windows drivers are only supported by the U disk. Can you use it to do some files hide and protect? Are you playing with some people who haven't played Linux: Your U disk capacity is smaller J.

Now more digital devices are also like Windows, which is divided into one of all USD plates into one, so when the U disk is treated, usually your mount is SDA1. But for some special digital devices format the U disk or memory card (currently I found a Lenovo support to simulate the USB floppy U disk and one of my digital cameras), you have to mount / dev / sda. Because it does not have a partition table (if the mount / dev / sda1 usual effect is dead). In fact, this information, as long as you pay attention to the / proc / partitions file, you should notice. 4. Each time you insert a U disk, you must find the name of the corresponding device file, you have to manually MOUNT, I can use it if you are inserting like Windows.

Of course, you need to do some work. I only provide some information here to help you try to complete the settings: Linux kernel provides something called HotPlug support, which allows you to do something when PCI device, USB and other devices. The Automount function can automatically mount and automatically uninstall your floppy drive, disc mount and automatically uninstall of devices such as discs. You can even create a corresponding icon in the KDE desktop, so that you can operate. The specific setting method will try it yourself. Anyway, I use Linux has numb, it is not a command.

Reference

1. "Linux device driver"

Alessandro Rubini

Lisoleg translation

2. "Linux System Analysis and Advanced Programming Technology"

Zhou Wei

3. Linux kernel-2.4.20 source code and document description

转载请注明原文地址:https://www.9cbs.com/read-97643.html

New Post(0)