Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38854
  • 博文数量: 34
  • 博客积分: 1773
  • 博客等级: 上尉
  • 技术积分: 360
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-10 16:40
文章分类
文章存档

2011年(5)

2010年(19)

2009年(10)

我的朋友

分类:

2010-07-16 16:24:22

内核版本:2.6.10

在/home/tmp/下建立两个文件hello.c,Makefile

hello.c
------------
#include
#include
#include

MODULE_LICENSE("GPL");

static int hello_init(void)
{
printk(KERN_ALERT "hello module init\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "hello module exit\n");
}

module_init(hello_init);
module_exit(hello_exit);

--------------

Makefile
----------
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

clean:
rm -f *.ko *.mod.c *.mod.o *.o

-----------
编译模块

#make

清除

#make clean

-----------

为了能够在终端显示信息,要修改
/lib/modules/2.6.10/build/include/linux/kernel.h
文件的KERN_ALERT宏。
#define KERN_ALERT "<1>"
修改为
#define KERN_ALERT "<0>"

------------

......

点击查看原文:

阅读(207) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~