Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9369
  • 博文数量: 13
  • 博客积分: 590
  • 博客等级: 中士
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-10 09:41
文章分类
文章存档

2010年(13)

我的朋友
最近访客

分类: LINUX

2010-11-10 09:55:18

目录:
一 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) |
给主人留下些什么吧!~~

chinaunix网友2010-11-10 19:48:42

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com