目录:
一 hello.ko
二 内核模块和application的不同
三 内核模块的参数
正文:
一 hello.ko
1. 模块代码:
/*都为常用的头文件*/
#include
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
static int __init hello_init(void){
printk(KERN_DEBUG "hello from hello world\n");
return 0;
}
static void __exit hello_exit(void){
printk(KERN_DEBUG "goodbye from hello world\n");
}
/*标记入口 出口*/
module_init(hello_init);
module_exit(hello_exit);
2. makefile
obj-m := hello.o
modules:
make -C /usr/src/linux-headers-2.6.32-21-generic M=`pwd` modules
用的是系统自己的内核
注意:
1. 文件夹要和模块名字相同,否则编译无法通过
二 .内核模块和应用程序的不同:
1 . 内核模块全部为事件驱动
2 . 不支持浮点数
3 . 内核模块的exit中必须显式的将init 建立的所有空间释放
4. __ 开始的函数为底层组件,不要轻易使用。
三 . 模块参数
类型: bool charp int long shrot uint ulong ushort
定义 : module_param(name,type,perm)
数组 : module_param_array(name,type,len,perm)
阅读(177) | 评论(1) | 转发(0) |