驱动参数传递

驱动参数传递

直接看代码

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值