驱动参数传递
直接看代码
root@zhangji16vm:/home/zhangji16/c_study/ko_study/prj1# cat hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
MODULE_LICENSE("Dual BSD/GPL");
static char *who;
static int times;
module_param(times,int,S_IRUSR);
module_param(who,charp,S_IRUSR);
static int hello_init(void)
{
int i;
for(i=0;i<times;i++)
printk(KERN_ALERT "(%d) hello, %s!\n",i,who);
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT"Goodbye, %s!\n",who);
}
module_init(hello_init);
module_exit(hello_exit);
module_param
声明可以传递参数了 参数名称 参数类型 权限8进制 4 2 1 读 写 执行
root@zhangji16vm:/home/zhangji16/c_study/ko_study/prj1# cat Makefile
KBUILD_CFLAGS +=
KERN_DIR = /usr/src/linux-headers-$(shell uname -r)/
all:
make -C $(KERN_DIR) M=`pwd` modules
obj-m += hello.o
执行
root@zhangji16vm:/home/zhangji16/c_study/ko_study/prj1# insmod hello.ko who=hhhhh times=10
then $ dmesg
[ 7677.802407] (0) hello, hhhhh!
[ 7677.802409] (1) hello, hhhhh!
[ 7677.802410] (2) hello, hhhhh!
[ 7677.802411] (3) hello, hhhhh!
[ 7677.802411] (4) hello, hhhhh!
[ 7677.802412] (5) hello, hhhhh!
[ 7677.802413] (6) hello, hhhhh!
[ 7677.802413] (7) hello, hhhhh!
[ 7677.802414] (8) hello, hhhhh!
[ 7677.802415] (9) hello, hhhhh!