Declare the parameter names, types, and permissions you want to pass in the driver's module.
Module_param (name, type, permission) of the variable;
The first example
#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 Modulesobj-M + = for the module compilation. #EXTRA_CFLAGS =-g-o0build:kernel_moduleskernel_modules: -c/lib/modules/$ (kvers)/build m=$ (CURDIR) modules# @echo $ (kvers) Clean: -c/lib/modules/$ (kvers)/build m=$ (CURDIR) Clean
Do not set the time to use the default
[Email protected] virtual-machine:/home/lin/hi# insmod./Hi.ko[email protected]-virtual-machine:/home/ lin/hi# CAT/var/log/syslog | all: lin-virtual-machine kernel: [ 203.238178] Hi enter USR ...
When using settings
[Email protected] virtual-machine:/home/lin/hi# insmod hi.ko p_name='God'
After the module is loaded, a module's folder will be generated under/sys/modules, with a parameters folder under the folder.
It contains a file node named after the parameter name, which holds the values we set, for example, in p_name .
[Email protected] virtual-machine:/home/lin/hi# cat/sys/module/hi/parameters/p_name God
Linux Driver Development Second-step driver module Transfer (Module_param function use)