现在的位置: 首页 > 综合 > 正文

LINUX编译ko文件

2014年09月05日 ⁄ 综合 ⁄ 共 915字 ⁄ 字号 评论关闭

makefile

#include <linux/kernel.h>

#include <linux/module.h>
//on pc you should use "tail -f /var/log/messages " to see the result
static int __init mini6410_hello_module_init(void)
{
    printk("Hello, Mini6410 module is installed !\n");
    return 0;
}

static void __exit mini6410_hello_module_cleanup(void)
{
    printk("Good-bye, Mini6410 module was removed!\n");
}

module_init(mini6410_hello_module_init);
module_exit(mini6410_hello_module_cleanup);
MODULE_LICENSE("GPL");

pc

### the ko name should be the same as the C file
### this is for gcc on PC
obj-m:=mykotest.o
mymodule-objs:=module
KDIR:=/lib/modules/2.6.27.5-117.fc10.i686/build/
MAKE:=make
default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
	rm -rf *.o *.~ *.ko  Module.*  *.mod.* modules.*

arm

### the ko name should be the same as the C file
### this is for arm-linux-gcc on ARM
A=ar
ARCH=arm
CC=arm-linux-gcc
obj-m        :=mykotest.o
mymodule-objs:=module
KDIR         :=/opt/linux-3.0.8/
PWD          :=$(shell pwd)
MAKE         :=make
all:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
	rm -rf *.o *~ *.ko *mod*

抱歉!评论已关闭.