就是驱动模块加载传递参数给我们的驱动
驱动传参的作用?
1、设置驱动的相关参数,驱动程序更灵活 ,比如 缓冲区大小
2、设置安全校验,防止驱动被别人盗用
怎么给驱动传参
驱动传递的参数类型:
基本类型:char /bool/int /long/short/byte/ushort/uint.
数组:array
字符串:string
传递普通参数
Module_param()
传递数组
Module_param_array()
传递参数
例程
#include <linux/module.h>
#include <linux/init.h>
static int a;
static int b[10];
static int array_size;
static char str1[10];
module_param(a,int,S_IRUGO);
MODULE_PARAM_DESC(a,"e.g:a=1");
module_param_array(b,int,&array_size,S_IRUGO);
MODULE_PARAM_DESC(b,"e.g:b=1,2,3");
module_param_string(str,str1,sizeof(str1),S_IRUGO);
MODULE_PARAM_DESC(str,"e.g:str=hello");
static int hello_init(void)
{
printk("input a=%d\n",a);
for(int i=0; i< array_size;i++)
{
printk("input b[%d]=%d \n",,i,b[i]);
}
printk("hello word init\n");
return 0;
}
static void hello_exit(void)
{
printk("hello word exit\n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("SONG");
MODULE_VERSION("v1.0");
通过命令可以查看 传参的描述信息
modinfo hello.ko
执行命令
insmod hello.ko a=125 b=1,2,7,9 str="hhhh"