linux动态加载驱动之一
http://www.cnblogs.com/spider33/archive/2012/01/31/2333202.html
/*
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the module ,it is necessary */
static int hello_init(void)
{
printk(KERN_EMERG "Hello World enter!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "Hello world exit!\n");
}
module_init(hello_init); /* load the module */
module_exit(hello_exit); /* unload the module */
/* before is some decription of the model,not necessary */
MODULE_AUTHOR("spider33");
MODULE_DESCRIPTION("This is an example of programming driver!");
MODULE_ALIAS("a simplest module");
保存为hello.c
Makefile内容为
obj-m := hello.o
编译指令为:
make -C /lib/modules/2.6.18-194.32.1.el5/build/ M=/opt/module/ modules
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the module ,it is necessary */
static int hello_init(void)
{
printk(KERN_EMERG "Hello World enter!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "Hello world exit!\n");
}
module_init(hello_init); /* load the module */
module_exit(hello_exit); /* unload the module */
/* before is some decription of the model,not necessary */
MODULE_AUTHOR("spider33");
MODULE_DESCRIPTION("This is an example of programming driver!");
MODULE_ALIAS("a simplest module");
保存为hello.c
Makefile内容为
obj-m := hello.o
编译指令为:
make -C /lib/modules/2.6.18-194.32.1.el5/build/ M=/opt/module/ modules
完成后生成hello.ko,使用insmod hello.ko装载,用rmmod hello卸载。