模块的编写

 转载请注明出处:http://blog.youkuaiyun.com/charistain_huang      
     文章中有什么不正确的地方恳请请各位网友指点
********************************************************
*****作者:黄仁军                                                                     *******
*****联系email:957626485@qq.com                                      *******
********************************************************

 

写了一个简单的hello world 模块程序

1.在driver/char/Kconfig中添加模块的编译选项

config MINI2440_HELLO_MODULE

tristae "mini2440 hello world module test"

depend on ARCH_S3C2410

default m if ARCH_SMDK_2440

help

"dddd"

 

 2. 将mini2440_hello_world.c放在driver/char/下同时在makefile中添加

obj-$(MINI2440_HELLO_WORLD) +=mini2440_hello_world.o

 

3.make modules  将生成的。ko文件下载到开发板的/lib/modules/$(uname -r)/目录下  如果没有$(uname -r)/这个文件需要新建,否则无法卸载模块
 /*
  * A simple hello module test programer
  *
  * Written by huang renjun
  * All Rights Reserved
  * /
  
#include <linux/init.h>
#include <linux/module.h>

static int __init hello_init()
{
	printk(KERN_INFO "Hello World module enter\n");
	return 0;
}


static void  __exit hello_exit()
{
  printk(KERN_INFO "Hello world module exit!\n");

}

module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("Charistain_huang");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("A simple Hello world Module");

Makefile:
KVERS = $(shell uname -r)

# Kernel modules
obj-m += hello.o

# Specify flags for the module compilation.
#EXTRA_CFLAGS=-g -O0

build: kernel_modules

kernel_modules:
	make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules

clean:
	make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值