Linux device drivers are in the form of kernel modules, but the modules are not necessarily drivers. The driver can be compiled into the kernel, when configuring the kernel, if a configuration item is set to M, then it will be compiled with the kernel compiled into a module, but to add drivers to the kernel will make the kernel very large, and in addition, modify, delete the driver need to compile the kernel again, this is extremely troublesome. So the general driver is the modular load, when needed to use the insmod loaded into the kernel, do not need to use the Rmmod to unload the driver module.
Key related commands for kernel modules:
LSMOD: See which modules are loaded by the current kernel
Insmod: Load Module
Rmmod: Uninstalling the module
Modinfo: Viewing module information
Drivers are part of the kernel, write drivers to follow certain kernel development rules, generally write a driver from a few steps:
View schematics to learn how the device works
Finding similar development programs in the kernel, mimicking their format and usage, is really not going to start from scratch.
Implementing the initialization of the driver
Implementing the corresponding operation function of the application interface
Compiling the loader
Test
The basic framework of the driver writing is similar, is to implement the system call to the corresponding function, and in the function to implement the corresponding function, a simple LED driver, for example, according to the character device in the core data structures file_operations structure (search in the kernel), The member functions in this struct are the main content of the character device driver program, which actually uses open (), read (), write ... in application Linux. is called at the end of the system call. 650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/77/85/wKioL1ZpN9nyOSUcAADuTPfBCbo563.png "title=" capture. PNG "alt=" Wkiol1zpn9nyosucaadutpfbcbo563.png "/>
Implement the corresponding function in the driver based on the requirements of this struct and the actual application
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/77/85/wKioL1ZpOTTSVKblAAKMRiN36LU584.png "title=" capture. PNG "alt=" Wkiol1zpottsvkblaakmrin36lu584.png "/>
The above is a basic driver framework, first in the use of Insmod Mydev.ko mount driver, execution: Module_init->my_init to complete the initialization of the work, when unloaded Rmmod mydev.ko->module_exit- >my_exit Complete the cleanup work (turn off the device, etc.). After the driver is loaded successfully, the application calls to the driver's My_open, My_read, and then to the corresponding device files using open, read and other system invocations. The Last Module_license ("GPL") is a statement of the license that declares this process to prevent kernel contamination.
This article is from the "June Feng Eureka" blog, please be sure to keep this source http://10274409.blog.51cto.com/10264409/1721624
Linux Device driver basic framework (character device)