为生存而奔跑

   :: 首页 :: 联系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我参与的团队

搜索

  •  

积分与排名

  • 积分 - 319519
  • 排名 - 75

最新评论

阅读排行榜

评论排行榜


如下测试模块

#include <linux/module.h> 
#include 
<linux/init.h> 
MODULE_LICENSE(
"GPL"); 
static int __init hello_init (void)
{
    printk(
"Hello module init\n");
    
return 0;
}
static void __exit hello_exit (void)
{
    printk(
"Hello module exit\n");
}
module_init(hello_init);

module_exit(hello_exit);

Makefile文件如下

obj-m := hellomodule.o

KDIR :
= /lib/modules/$(shell uname -r)/build

PWD :
= $(shell pwd)

all:
    make 
-C $(KDIR) M=$(PWD) modules

clean:
    rm 
*.o *.ko *.mod.c Modules.symvers modules.order -f

KDIR时编译内核模块需要的Makefile的路径。
make -C $(DIR) M=$(shell pwd) modules 编译内核模块。-C 将工作目录转到KDIR,调用该目录下的Makefile,并向这个Makefile传递参数M的值是$(shell pwd) modules。

之后,sudo make 编译模块

然后,sudo insmode ./hellomodule.ko 加载模块
sudo rmmod ./hellomodule.ko 删除模块

用dmesg | tail 可以看到输出信息。
或者看日志文件/var/log/kern.log


posted on 2011-03-29 22:06 baby-fly 阅读(1284) 评论(0)  编辑 收藏 引用 所属分类: Ubuntu&Linux

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理