转载请注明出处: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