1. Linux kernel driver module mechanism Static loading, compile the driver module into the kernel and load it when the kernel starts Dynamic loading, compile the driver module as ko, and load it when the kernel starts 2. Write kernel driver #include <linux/module.h> #include <linux/init.h> static int __init test_init(void) { return 0; //Return 0 to indicate success, return a negative number to exit loading module} //__init After the kernel initializes the driver, release the code instruction space of this function static void __exit test_exit(void) { .... } //__exit specifies that this function is only used when the driver is uninstalled and is released after usemodule_init(test_init); //Specify test_init as the module initialization functionmodule_exit(test_exit); //Specify test_exit as the module exit uninstall functionMODULE_LICENSE("GPL"); //Specify the supported protocolsMODULE_AUTHOR("Author"); MODULE_DESCRIPTION("Description"); MODULE_VERSION("version"); #define __init __section(.init.text) #define __initdata __section(.init.data) char __initdata buf[] = "hello world"; #define __exitdata __section(.exit.data) #define __exit __section(.exit.text) ///////////// test 1768 0 - Live 0xbf03c000 Module name, memory size used, number of calls, validity, memory address where the module is located 3. Makefile of driver module
4. Check the driver output message cat /var/log/messages tail /var/log/messages 5. Printk level control /usr/src/kernels/2.6.18-194.el5-i686/include/linux/kernel.h <linux/kernel.h> #define KERN_EMERG "<0>" /* system is unusable */ #define KERN_ALERT "<1>" /* action must be taken immediately */ #define KERN_CRIT "<2>" /* critical conditions */ #define KERN_ERR "<3>" /* error conditions */ #define KERN_WARNING "<4>" /* warning conditions */ #define KERN_NOTICE "<5>" /* normal but significant condition */ #define KERN_INFO "<6>" /* informational */ #define KERN_DEBUG "<7>" /* debug-level messages */ The default level is Use:
When the level used by the printk function is lower than the current Modify the level output Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Detailed explanation of replace into example in mysql
>>: Vue routing to implement login interception
1. Download the pip installation package accordin...
Table of contents Storage Engine Storage engines ...
1. Why does nginx use gzip? 1. The role of compre...
Download foreign images using Alibaba Cloud Image...
You may encounter the following problems when ins...
Installing MySQL 5.7 from TAR.GZ on Mac OS X Comp...
Previously, I introduced the use of the charAt() ...
MySQL 5.7.8 introduced the json field. This type ...
This article describes how to install php7 + ngin...
Docker only maps ports to IPv6 but not to IPv4 St...
1. Download the image docker pull selenium/hub do...
The select element creates a single-select or mult...
The GROUP BY statement is used in conjunction wit...
URL: http://hostname.com/contextPath/servletPath/...
Table of contents 1. Introduction II. Monitoring ...