2008年8月26日星期二

在kernel2.6下编译lkm

相对于2.4,init_module和cleanup_module,改名为module_init(),module_exit().
在编译时,需要编写Makefile文件,而不能直接使用gcc。
最为简单的Makefile文件
#cat Makefile
obj-m := hello.o

cat hello.c
/* for 2.6 */
#include
#include

static int myinit_module()
{
printk(”hello!This is a testing module!\n”);
return 0;
}
static void mycleanup_module()
{
printk(”Sorry ! The testing module is unloading now! \n”);
}

module_init(myinit_module);
module_exit(mycleanup_module);

编译时的命令为:make -C /usr/src/linux(源码版本) SUBDIRS=$PWD modules

加载,删除模块
sudo insmod hello.ko
sudo rmmod hello
dmesg /*查看printk打印出的信息*/

没有评论: