Linuxdevicedrivermodule is automatically loaded by default.

Source: Internet
Author: User
By default, linuxdevicedrivermodule automatically loads Linux general technology-Linux programming and kernel information. For details, see the following. It is often found that many driver/device loading rules are not specified in udev, but udev can insert the device into the system
Load the driver correctly. After careful analysis, we found that this was the case.

1. udev ignores the default rule

/Etc/udev/rules. d/50-udev.rules in ora 6 is as follows:
ACTION = "add", SUBSYSTEM = "? * ", ENV {MODALIAS} = "? * ", RUN + ="/sbin/modprobe $ env {MODALIAS }".
Indicates that an add event occurs in the system, and the SUBSYSTEM and MODALIAS key of the device that generates the event are both
When a string contains at least one character
/Sbin/modprobe $ env {MODALIAS}
$ Env {MODALIAS} is the value of key MODALIAS in the matching rule. It can be seen that this rule is very easy to match and can be understood
A default rule.

In addition, if udev specifies that multiple rules can be matched, the action corresponding to each matching rule will be executed.

2. How modules. alias is generated
The format of the/lib/modules/KERNEL_VERSION/modules. alias file is as follows:
...
Alias pci: v20171412d20171712sv * sd * bc * SC * I * snd-ice1712
...
Alias usb: v * p * d * dc * dsc * dp * ic01isc01ip * snd-usb-audio
Alias usb: v * p * d * dc * dsc * dp * ic01isc03ip * snd-usb-audio
...

In the modpost phase of make modules, the modpost tool is called from the elf format of. ko.
And generate the modules. alias file. module source code
MODULE_DEVICE_TABLE (type, table)
Define the corresponding data information. type indicates pci/usb/ieee1394/pcmcia /...
Device type. table defines the specific devices that the module matches,
Generally, different types of devices have different matching structures. For example, the usb matching structure is struct.
Usb_device_id type. The pci device is struct pci_device_id.
Generally, different types of devices define different matching structures.
The format of module alias is also different. MODULE_DEVICE_TABLE (type, table) of a module)
The number of corresponding module alias generated by the module when the table has multiple elements.
Module alias corresponds to the module name. The format of each type of module alias is the same,
":" Type name (usb/pci/...), ":" is related to the specific type, but the format is:
Key_namekey_value |...
Key_name is the name of an id, and key_value is the matched value (* indicates any value ).

3. modalias information in sysfs
The modalias attribute in sysfs is generally provided by the bus driver of the device and generated.
For example:
[Root @ localhost/] # find/sys/devices-name modalias
/Sys/devices/pci0000: 00/0000: 00: 12.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 11.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 10.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 0f. 0/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.3/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.2/usb1/1-1/1-. 1/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.2/usb1/1-1/1-. 0/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.2/usb1/1-0:1. 0/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.2/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.1/ide1/1.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.1/modalias
/Sys/devices/pci0000: 00/0000: 00: 07.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 01.0/modalias
/Sys/devices/pci0000: 00/0000: 00: 00.0/modalias
/Sys/devices/platform/bluetooth/modalias
/Sys/devices/platform/floppy.0/modalias
/Sys/devices/platform/i8042/serio1/modalias
/Sys/devices/platform/i8042/serio0/modalias
/Sys/devices/platform/i8042/modalias
/Sys/devices/platform/serial8250/modalias
/Sys/devices/platform/vesafb.0/modalias
/Sys/devices/platform/pcspkr/modalias

4. Complete Loading Process
1) the device is inserted into the system. The device's bus calls the device driver model interface to generate
Netlink event, which contains the modalias key and corresponding values;

2) udevd receives the netlink event from the kernel and finds that
Then, the corresponding action is executed:
/Sbin/modprobe $ env {MODALIAS}
$ Env {MODALIAS} and a line in/lib/modules/KERNEL_VERSION/modules. alias
Therefore, it is equivalent to modprobe module_name, and the corresponding module is loaded.

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.