In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of the Linux kernel foundation of the Linux kernel device driver, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
1. Linux kernel driver module mechanism
Static loading, the driver module is programmed into the kernel and loaded when the kernel starts
Dynamic loading, compiling the driver module as ko, and loading when needed after the kernel starts.
two。 Write kernel drivers
# include # include static int _ _ init test_init (void) {return 0; / / return 0 indicates success. Add a negative number to exit the loading module} / / _ init when the kernel initializes the driver, release the code instruction space of this function static void _ _ exit test_exit (void) {....} / / _ exit specify that this function is used only when the driver is unloaded, and release module_init (test_init) after use / / specify test_init as the module initialization function module_exit (test_exit); / / specify test_exit as the uninstall function MODULE_LICENSE ("GPL") when the module exits; / / specify the supported protocol MODULE_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) /
Modinfo test.ko views the module's information
Cat / proc/modules View the dynamic loading module of the current system is equivalent to lsmod
Test 1768 0-Live 0xbf03c000
Module name, memory size used, number of calls, valid, memory address where the module is located
Ls / sys/module view all modules
3. Makefile of driver module
Obj-m + = test.o / / Source file is test.c
Modules:make-C kernel source code directory M = modules where the driver code is located
Modules install:make-C kernel source code directory M = directory where the driver code is located modules_install INSTALL_MOD_PATH=/ file system path
Clean:make-C kernel source code directory M = modules clean where the driver code is located
4. View the message of the driver output
Cat / var/log/messagestail / var/log/messages
5. Level control of printk
/ usr/src/kernels/2.6.18-194.el5-i686/include/linux/kernel.h
# define KERN_EMERG "/ * system is unusable * / # define KERN_ALERT" / * action must be taken immediately * / # define KERN_CRIT "/ * critical conditions * / # define KERN_ERR" / * error conditions * / # define KERN_WARNING "/ * warning conditions * / # define KERN_NOTICE" / * normal but significant condition * / # define KERN_INFO "/ * informational * / # define KERN_DEBUG" / * debug-level messages * /
The default level is KERN_WARNING ""
Use: printk (KERN_INFO "content")
View the output level cat / proc/sys/kernel/printk of the current kernel
7 4 1 7
7:console_loglevel
4:default_message_loglevel
1:minimum_console_loglevel
7:default_console_loglevel
When the printk function uses a level less than the current console_loglevel level, it can export, otherwise it will not
Modify level output echo 8 > / proc/sys/kernel/printk
Thank you for reading this article carefully. I hope the article "sample Analysis of the Linux Kernel basis of Linux Kernel device drivers" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.