LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 963|回复: 2

按照教程写一个最简单的驱动模块,加载失败呢?

[复制链接]
发表于 2005-2-11 16:55:01 | 显示全部楼层 |阅读模式
我用的是FC3,2.6.10内核

写的驱动如下:

#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int init_module()
{
        printk("Hello,World!\n");
        return 0;
}

static void cleanup_module()
{
        printk("Bye!\n");
}

保存为test.c
编译:   gcc -c test.c
之后用命令: insmod test.o  , 报错,怎么也解决不了,报错信息如下:
insmod: error inserting 'test.o': -1 Invalid module format

请问这是怎么一回事呢?
或者谁能给个2.6.10内核下已经成功实现的类似的简单驱动程序代码?

谢谢
发表于 2005-2-12 20:44:18 | 显示全部楼层
2.6内核的参见Docuemnts/kbuild/里的文章
回复 支持 反对

使用道具 举报

发表于 2005-2-27 22:35:14 | 显示全部楼层
假如你地源文件名为hello。c
写一个这样地Makefile文件就可以了。


EXTRA_LDFLAGS += -t -std=c99
obj-m += hello.o

CLEAN_OBJS := built-in.o hello.ko hello.o hello.mod.c hello.mod.o

standalone:
        make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules

.PHONY: clean

clean:
        @for i in $(CLEAN_OBJS); do \
        (if [ -f $$i ] ; \
        then \
                        echo $$i; \
                        rm -f $$i ; \
                else \
        : ;\
        fi); \
        done
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表