增加驱动模块到内核树

来源:互联网 发布:手机分贝测试软件 编辑:程序博客网 时间:2024/05/16 19:31

现在要把下面的驱动模块添加到内核树中:

/*   module_param.ko num.c*/#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/moduleparam.h>static int num = 0;static char* string="this is a test";static int array[3]={0};static amount=3;module_param(num, int, S_IRUGO|S_IWUSR);module_param(string, charp, S_IRUGO|S_IWUSR);module_param_array(array, int, &amount, S_IRUGO|S_IWUSR);MODULE_PARM_DESC(num,"it's a test num");MODULE_PARM_DESC(string, "it's a test string");MODULE_PARM_DESC(array, "it's a test array");static int __init module_param_init(void){printk(KERN_INFO"num=%d\n",num);printk(KERN_INFO"string=%s\n", string);printk(KERN_INFO"array=%d,%d,%d\n", array[0], array[1], array[2]);return 0;}static void __exit module_param_exit(void){printk(KERN_INFO"module param exit!\n");}module_init(module_param_init);module_exit(module_param_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("BANG");MODULE_DESCRIPTION("module study");MODULE_SUPPORTED_DEVICE("none");
步骤:

1、进入内核目录把module_param.c放到drivers/module_param/目录下

mkdir drivers/module_param

cp module_param.c  drivers/module_param/


2、修改drivers目录下的Kconfig和Makefile文件

vim Kconfig  ---------》增加 source "drivers/module_param/Kconfig" 

vim Makefile ---------》增加 obj-$(CONFIG_MODULE_PARAM) +=  module_param/


3、进入module_param 目录,增加Makefile、Kconfig文件

Kconfig内容:

config MODULE_PARAM    --------------------------(注意,这里不是写CONFIG_MODULE_PARAM)

tristate "module param"     ---------------(标签的命名是module param可以有三种选择)

default y

---help---

this is my test      

Makefile内容:

obj-$(CONFIG_MODULE_PARAM) +=module_param.o

5、make menuconfig  选择编译方式

如果是选择built-in 方式, 在make uImage时驱动会添加到uImage 镜像中

如果是选择modules的方式, make modules会在module_param目录生成.ko文件


0 0
原创粉丝点击