Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174103
  • 博文数量: 96
  • 博客积分: 4060
  • 博客等级: 上校
  • 技术积分: 1040
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-12 13:13
文章分类

全部博文(96)

文章存档

2011年(3)

2010年(76)

2009年(17)

我的朋友

分类: 嵌入式

2010-08-18 21:34:06

hello.c:

#include
#include
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Veritastry");
static int many = 0;
module_param(many, int, S_IRUGO);
static int hello_init(void)
{
     printk(KERN_ALERT "Hello, world mod %d\n",many);
     return 0;
}
static void hello_exit(void)
{
     printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);


Makefile



#if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
 obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
 KERNELDIR ?= /lib/modules/$(shell uname -r)/build
 PWD := $(shell pwd)
default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

 这个简单的程序告诉大家应该怎么写一个模块,MODULE_LICENSE告诉内核该模块的版权信息,很多情况下,用GPL或者BSD,或者两个,因为 一个私有模块一般很难得到社区的帮助。module_init和module_exit用于向内核注册模块的初始化函数和模块推出函数。如程序所示,初始 化函数是hello_init,而退出函数是hello_exit。
阅读(398) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~