用insmod插入hello.ko模块出错
刚接触linux驱动编程,买了本《Linux设备驱动程序》第三版,但是在第二章中的HelloWorld示例就卡住了,求各位大神指点。原码如下:
/* hello.c */
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
/* Makefile */
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
试验平台是Fedora14,内核是自己编译的2.6.39.2,可以顺利编译成hello.ko文件。但是在运行
# insmod ./hello.ko
时,弹出如下错误
这些错误能看懂个大概,应该是内核返回的一些错误信息,但是不知道如何解决,初次接触,各种蛋疼啊:dizzy:
希望大神们赐教,如何学习linux驱动编程来得快些,接下来的项目就要写驱动了。
非常感谢! :'(怎么没有人回我啊,伤心了 # Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
# Add your debugging flag (or not) to CFLAGS
#ifeq ($(DEBUG),y)
# DEBFLAGS = -O -g -DSEAN_DEBUG # "-O" is needed to expand inlines
#else
# DEBFLAGS = -O2
#endif
#CFLAGS += $(DEBFLAGS)
obj-m := hello.o
#KERNELDIR := /lib/modules/2.6.32.17/build
#KERNELDIR := /usr/src/linux-2.6.32.17
KERNELDIR := /usr/src/linux-headers-2.6.39-2-generic
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
把makefile改成这个试试 无法重现。。。 没有遇到过这个问题,可能是你编译内核的问题。 回复 1# darain888
貌似你的Makefile的问题,注意内核版本的兼容性
页:
[1]