Declare the parameter name, type and permission you want to pass in the driver module module_param(variable name, type, permissions); #include <linux/init.h> #include <linux/module.h> static char *p_name = "Usr"; module_param(p_name, charp, S_IRUGO); MODULE_PARM_DESC(p_name, "This is a char * string."); static int __init hi_init(void) { printk(KERN_INFO "Hi enter %s\n",p_name); return 0; } module_init(hi_init); static void __exit hi_exit(void) { printk(KERN_INFO "Hi exit %s\n ",p_name); } module_exit(hi_exit); MODULE_AUTHOR("libra13179"); MODULE_LICENSE("GPL v2"); KVERS = $(shell uname -r) # Kernel modules obj-m += hi.o # Specify flags for the module compilation. #EXTRA_CFLAGS=-g -O0 build: kernel_modules kernel_modules: make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules # @echo $(KVERS) clean: make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean If not set, the default value is used. root@lin-virtual-machine:/home/lin/hi# insmod ./hi.ko root@lin-virtual-machine:/home/lin/hi# cat /var/log/syslog | grep Hi ... Jul 25 15:11:38 lin-virtual-machine kernel: [ 203.238178] Hi enter Usr ... When using settings root@lin-virtual-machine:/home/lin/hi# insmod hi.ko p_name='God' After loading the module, a module folder will be generated under /sys/modules, and there will be a parameters folder under the folder. It contains the file node named after the parameter name, which stores the value we set, for example, in p_name
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Additional instructions for using getters and actions in Vuex
>>: A detailed guide to custom directives in Vue
This article shares the specific code for JavaScr...
1. Introduction to Linux .NET Core Microsoft has ...
Linux uses files as the basis to manage the devic...
This article example shares the specific code of ...
<br />A year ago, there were no articles abo...
First, let’s look at the GIF operation: Case 1: S...
This article example shares the specific code of ...
Table of contents Written in front Requirements A...
Preface A classmate is investigating MLSQL Stack&...
In the case of complete separation of the front-e...
When we are writing a page, we often encounter a ...
Table of contents Initialize computed Dependency ...
This article example shares the specific code of ...
Recently, the company has begun to evaluate all s...
Table of contents Breaking down components Left P...