videohome 发表于 2006-12-1 21:58:20

Hello驱动程序编译OK,在insmod时报错,怎么回事?

hellodrv.c
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("jj");
MODULE_DESCRIPTION("my first driver");
static int hello_init(void)
{
   //printk(KERN_ALERT,"Hello, world\n");
   printk("Hello,world\n");
   return 0;
}
static void hello_exit(void)
{
   printk("Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

Makefile
CC = /opt/eldk/usr/bin/arm-linux-gcc
LD = /opt/eldk/usr/bin/arm-linux-ld
#CFLAGS = -D__KERNEL__-I/HHARM9-EDU/kernel/include -Wall   -DMODULE
#CFLAGS = -D__KERNEL__ -DMODULE
#CFLAGS = -D__KERNEL__ -DMODULE -I/disk/linux/linux-2.6.17.9/include
CFLAGS = -D__KERNEL__ -I/disk/linux/linux-2.6.17.9/include -Wall -Wstrict-prototypes -Wno-trigraphs -Os -mapcs -fno-strict-aliasing -fno-common -fno-common -pipe-march=armv4 -mtune=arm9tdmi-msoft-float -DMODULE
                                                                              
                                                                              
hellodrv.o: hellodrv.c
       $(CC) $(CFLAGS) -c $^ -o $@

                                                                              
                                                                              
.PHONY: clean
clean:
       -rm -f *.o
                                                                              
distclean:
       @make clean
       rm -f tags *~
编译输出信息:
# make
/opt/eldk/usr/bin/arm-linux-gcc-D__KERNEL__ -I/disk/linux/linux-2.6.17.9/include -Wall -Wstrict-prototypes -Wno-trigraphs -Os -mapcs -fno-strict-aliasing -fno-common -fno-common -pipe-march=armv4 -mtune=arm9tdmi-msoft-float -DMODULE -c hellodrv.c -o hellodrv.o
#

将hellodrv.otftp到9200板子上,运行insmod就出现错误:

# insmod -f hellodrv.o
No module found in object
insmod: cannot insert `hellodrv.o': Invalid module format (-1): Exec format errr

Linux是2.6.17.9

ma100 发表于 2006-12-1 22:06:59

#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("jj");

#include什么都不写怎么编

videohome 发表于 2006-12-2 13:42:00

#include 后面的没COPY到,是有东西的,不然编译不通的。

#include <linux/init.h>
#include <linux/module.h>

videohome 发表于 2006-12-3 00:37:44

原来是Makefile文件写错了,应该这样写

obj-m += hellodrv.o

然后:
# make -C /disk/linux/linux-2.6.17.9/ SUBDIRS=$PWD modules
make: Entering directory `/disk/linux/linux-2.6.17.9'
Building modules, stage 2.
MODPOST
make: Leaving directory `/disk/linux/linux-2.6.17.9'
#

-C 后面跟源代码的目录就OK了
页: [1]
查看完整版本: Hello驱动程序编译OK,在insmod时报错,怎么回事?