您的位置:首页 > 运维架构 > Linux

嵌入式Linux模块的参数传递与多文件模块Makefile

2015-07-19 09:34 621 查看
通过宏module_param指定保存模块参数的变量。模块参数

用于在加载模块时传递参数给模块。

module_param(name,type,perm)

 name:变量的名称

 type:变量类型,bool:布尔型 int:整型 charp:字符串型

 perm是访问权限。 S_IRUGO:读权限 S_IWUSR:写权限

 例:

int a = 3;

char *st;

module_param(a,int, S_IRUGO);

module_param(st,charp, S_IRUGO);

一个简单的例子:(hello.ko)

#include <linux/init.h>

#include <linux/module.h>

int a = 0 ;

module_param(a,int,S_IRUGO);  //读权限

static int hello_init( void )

{

  printk("hello world\n");

  printk("a = %d",a); 

  return 0 ;

}

static int hello_exit( void )

{

  printk("goodbye!!\n");

  return 0 ;

}

module_init(hello_init);   //申明模块加载函数

module_exit(hello_exit);   //申明模块卸载函数

MODULE_AUTHOR("bmonky<1129584094@qq.com>");

MODULE_DESCRIPTION("简单的hello module");

MODULE_LICENSE("GPL");

加载过程中参数的传递:

# insmod hello.ko a=10 

显示打印的信息:

# dmesg | tail -5 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: