内核模块传参问题Standard types are:byte, short, ushort, int, uint, long, ulong 注意:没有char类型!!charp: a character pointerbool: a bool, values 0/1, y/n, Y/N.invbool: the above, only sense-reversed (N = true). module_param(name, type, perm) 功能:接收命令行传的参数参数:@name:变量名@type: 变量的类型@perm: 权限 0664 0775MODULE_PARM_DESC(_parm, desc)功能:对命令行传递的参数进行描述参数:@_parm:变量@desc:描述的字符串安装驱动的时候传参:sudo insmod demo.ko light=80在运行的使用传参/sys/module/驱动命名的目录/parameters/以变量命名的文件su rootecho 70 > light
demo.c#include
#include int light=100;module_param(light,int,0664);
MODULE_PARM_DESC(light,"this is lcd light(rang 0-100,default 100)");
//入口
static int __init demo_init(void)
{printk("init :light = %d\n",light);return 0;
}//出口
static void __exit demo_exit(void)
{printk("exit :light = %d\n",light);
}module_init(demo_init);
module_exit(demo_exit);
MODULE_LICENSE("GPL");MakefileKERNELDIR:= /lib/modules/$(shell uname -r)/build/
#KERNELDIR:= /home/linux/kernel/kernel-3.4.39/
PWD:=$(shell pwd)all:make -C $(KERNELDIR) M=$(PWD) modules
clean:make -C $(KERNELDIR) M=$(PWD) cleanobj-m:=demo.o
1.通过命令行传参的形式传递字符类型
2.通过命令行传参的形式传递字符串
3.通过命令行传参的形式传递数组
module_param_array(name, type, nump, perm) module_param_array(name, type, nump, perm) 功能:接收整型的数组参数:@name :数组名@type :数组的类型@nump :命令行传递的参数的个数@perm :权限sudo insmod demo.ko light=50 tt=65 p="www.hqyj.com" ww=11,22,33demo.c#include
#include int light=100;
module_param(light,int,0664);
MODULE_PARM_DESC(light,"this is lcd light(rang 0-100,default 100)");char tt=50; //arm编译器认为char是一个无符号的类型,//ubuntu编译认识它是有符号的
module_param(tt,byte,0775);
MODULE_PARM_DESC(tt,"this is char var");char *p="hello driver";
module_param(p,charp,0664);
MODULE_PARM_DESC(p,"this is a char point");int ww[5] = {0};
int len;
module_param_array(ww,int,&len,0664);
MODULE_PARM_DESC(ww,"this is int [5] array");//入口
static int __init demo_init(void)
{int i;printk("init :light = %d\n",light);printk("tt = %c\n",tt);printk("p = %s\n",p);for(i=0;i}//出口
static void __exit demo_exit(void)
{printk("exit :light = %d\n",light);
}module_init(demo_init);
module_exit(demo_exit);
MODULE_LICENSE("GPL");MakefileKERNELDIR:= /lib/modules/$(shell uname -r)/build/
#KERNELDIR:= /home/linux/kernel/kernel-3.4.39/
PWD:=$(shell pwd)all:make -C $(KERNELDIR) M=$(PWD) modules
clean:make -C $(KERNELDIR) M=$(PWD) cleanobj-m:=demo.o