Linux kernel driver module loading method

Source: Internet
Author: User
In unix-like operating systems, driver loading methods are generally divided into dynamic loading and static loading, which are described in detail below. 1. Dynamic Loading & nbsp; dynamic loading means to load the driver module to the kernel, instead of/lib/modules. & Nbsp; in the 2.4 kernel, the driver is loaded in unix-like operating systems by dynamic loading and static loading, the following describes in detail.
I. dynamic loading
Dynamic loading is to load the driver module to the kernel, but not to/lib/modules.
In the 2.4 kernel, the load driver command is: insmod, and the delete Module is: rmmod;
In more than 2.6 of the kernels, in addition to insmod and rmmod, the load Command also has modprobe;
Insmod differs from modprobe:
Insmod absolute path/××. o, and modprobe ××, no need to add. ko or. no path is required. The most important thing is that modprobe will load other modules on which the current module depends;
Lsmod checks all the driver modules currently loaded to the kernel and provides other information, such as whether other modules are using another module.
II. static loading
(1) concepts
When you execute the make menuconfig command to perform kernel configuration pruning, you can choose whether to compile the kernel in the window, or put it in the/lib/modules/directory of the corresponding kernel version, or not.
(2) procedure
Linux devices are generally divided into character devices, block devices, and network devices. Each device has a corresponding directory under the kernel source code directory tree drivers/. the loading method is similar, the following uses static loading of character devices as an example. assume that the driver source code is ledc. c. The procedure is as follows:
Step 1: Add the ledc. c source program to the kernel source code drivers/char;
Step 2: modify the drivers/char/Config. in file as follows:
Add the file according to the format in the open file;
Add the following code to the proper location of the file (this location is acceptable, but this location determines its location in the make menuconfig window:

Tristate LedDriver CONFIG_LEDC
If ["$ CONFIG_LEDC" = "y"]; then
Bool Support for led on h9200 board CONFIG_LEDC_CONSOLE
Fi
Note: The above code uses tristate to define a macro, indicating that the driver can be directly compiled to the kernel (use * to select ), you can also compile it under/lib/modules/(selected by M) or not compile (not selected ).
 
Bool LedDriver CONFIG_LEDC
If ["$ CONFIG_LEDC" = "y"]; then
Bool Support for led on h9200 board CONFIG_LEDC_CONSOLE
Fi
Note: The code above uses tristate to define a macro, indicating that the driver can only be directly compiled to the kernel (with * selected) or not compiled (not selected ), cannot be compiled under/lib/modules/(selected by M ).

Step 3: modify the drivers/char/Makefile file
Add the following line of code to the appropriate location:
Obj-$ (CONFIG_LEDC) + = ledc. o
Or add ledc. o to the obj-y line, for example:
Obj-y + = ledc. o mem. o is not changed;
 
OK. after the preceding settings, you can select and configure character devices ---> in the window after the make menuconfig command is executed. Select and re-compile.
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.