打印

嵌入式驱动问题

[复制链接]
2862|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
spirits_hyx|  楼主 | 2012-7-28 11:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
RT,小弟菜鸟一个,今天刚接触驱动,照着实验书写了代码,编译问题一堆,附上代码和问题,希望大虾能够帮帮忙!
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/module.h>
#include <asm/hardware.h>
//HELLO DEVICE MAJOR
#define SIMPLE_HELLO_MAJOR 96
#define OURS_HELLO_DEBUG
#define VERSION "PXA2700EP-hello-V1.00-06053"
void showversion(void)
{
        printk("********************************\n");
        printk("\t %s \t\n",VERSION);
        printk("********************************\n\n");
}
//-----------READ-----------------
ssize_t SIMPLE_HELLO_read(struct file * file,char * buf,size_t count,loff_t * f_ops)
{
        #ifdef OURS_HELLO_DEBUG
        printk("SIMPLE_HELLO_read[ --kernel--]\n");
        #endif
        return count;
}
//-----------WRITE----------------
ssize_t SIMPLE_HELLO_write(struct file *file,const char *buf,size_t count,loff_t *f_ops)
{
        #ifdef OURS_HELLO_DEBUG
        printk("SIMPLE_HELLO_write[ --kernel--]\n");
        #endif
        return count;
}
//----------IOCTL-----------------
ssize_t SIMPLE_HELLO_ioctl(struct inode *inode,struct file *file,unsigned int cmd,long data)
{
        #ifdef OURS_HELLO_DEBUG
        printk("SIMPLE_HELLO_ioctl[ --kernel--]\n");
        #endif
        return 0;
}
//---------OPEN--------------------
ssize_t SIMPLE_HELLO_open(struct inode *inode,struct file *file)
{
        #ifdef OURS_HELLO_DEBUG
        printk("SIMPLE_HELLO_open[ --kernel--]\n");
        #endif
        MOD_INC_USE_COUNT;
        return 0;
}
//--------RELEASE/CLOSE-------------
ssize_t SIMPLE_HELLO_release(struct inode *inode,struct file * file)
{
        #ifdef OURS_HELLO_DEBUG
        printk("SIMPLE_HELLO_release[ --kernel--]\n");
        #endif
        MOD_DEC_USE_COUNT;
        return 0;
}
//------------------------------------
struct file_operations HELLO_ctl_ops={
open:   SIMPLE_HELLO_open,
read:   SIMPLE_HELLO_read,
write:  SIMPLE_HELLO_write,
ioctl:  SIMPLE_HELLO_ioctl,
release:SIMPLE_HELLO_release,
};
//--------------INIT------------------
static int __init HW_HELLO_CTL_init(void)
{
        int ret = -ENODEV;
        ret = devfs_register_chrdev(SIMPLE_HELLO_MAJOR,"hello_ctl",&HELLO_ctl_ops);
        showversion();
        if(ret < 0)
        {
                printk("pxa270 init_module failed with %d\n [ --kernel--]",ret);
                return ret;
        }
        else
        {
                printk("pxa270 hello_driver register success!!![ --kernel--]\n");
        }
        return ret;
}
static int __init pxa270_HELLO_CTL_init(void)
{
        int ret = -ENODEV;
        #ifdef OURS_HELLO_DEBUG
        printk("pxa270_HELLO_CTL_init[ --kernel--]\n");
        #endif
        ret = HW_HELLO_CTL_init();
        if(ret)
                return ret;
        return 0;
}
static void __exit cleanup_HELLO_ctl(void)
{
        #ifdef OURS_HELLO_DEBUG
        printk("cleanup_HELLO_ctl[ --kernel--]\n");
        #endif
        devfs_unregister_chrdev(SIMPLE_HELLO_MAJOR,"hello_ctl");
}
MODULE_DESCRIPTION("simple hello driver module");
MODULE_AUTHOR("spirits");
MODULE_LICENSE("GPL");
module_init(pxa270_HELLO_CTL_init);
module_exit(cleanup_HELLO_ctl);
问题:
arm-linux-gcc -c -I.. -Wall -O -D__KERNEL__ -DMODULE -I/pxa270_linux/linux/include pxa270_hello_drv.c -o pxa270_hello_drv.o
pxa270_hello_drv.c:18: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:18: warning: its scope is only this definition or declaration, which is probably not what you want
pxa270_hello_drv.c:26: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:34: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:34: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:42: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:42: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:51: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:51: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:60: error: variable `HELLO_ctl_ops' has initializer but incomplete type
pxa270_hello_drv.c:61: error: unknown field `open' specified in initializer
pxa270_hello_drv.c:61: warning: excess elements in struct initializer
pxa270_hello_drv.c:61: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:62: error: unknown field `read' specified in initializer
pxa270_hello_drv.c:62: warning: excess elements in struct initializer
pxa270_hello_drv.c:62: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:63: error: unknown field `write' specified in initializer
pxa270_hello_drv.c:63: warning: excess elements in struct initializer
pxa270_hello_drv.c:63: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:64: error: unknown field `ioctl' specified in initializer
pxa270_hello_drv.c:64: warning: excess elements in struct initializer
pxa270_hello_drv.c:64: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:65: error: unknown field `release' specified in initializer
pxa270_hello_drv.c:65: warning: excess elements in struct initializer
pxa270_hello_drv.c:65: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c: In function `HW_HELLO_CTL_init':
pxa270_hello_drv.c:70: error: `ENODEV' undeclared (first use in this function)
pxa270_hello_drv.c:70: error: (Each undeclared identifier is reported only once
pxa270_hello_drv.c:70: error: for each function it appears in.)
pxa270_hello_drv.c:71: warning: implicit declaration of function `devfs_register_chrdev'
pxa270_hello_drv.c: In function `pxa270_HELLO_CTL_init':
pxa270_hello_drv.c:86: error: `ENODEV' undeclared (first use in this function)
pxa270_hello_drv.c: In function `cleanup_HELLO_ctl':
pxa270_hello_drv.c:100: warning: implicit declaration of function `devfs_unregister_chrdev'
pxa270_hello_drv.c: At top level:
pxa270_hello_drv.c:60: error: storage size of `HELLO_ctl_ops' isn't known
make: *** [pxa270_hello_drv.o] Error 1

相关帖子

沙发
spirits_hyx|  楼主 | 2012-7-28 11:39 | 只看该作者
自己顶一下,期待高手出现~~~

使用特权

评论回复
板凳
shell.albert| | 2012-7-28 11:46 | 只看该作者
你的程序中引用了许多结构体等数据类型的定义,但是你使用gcc编译的时候却没有使用-I  dir 来指定包含这些结构体的头文件的位置。导致编译器找不到。故报错。

你虽然指定了 -I  dir
但是程序中引用的头文件却不在此目录下,先查找一下所使用的头文件,再在gcc编译命令行,后面使用-I dir1 -I dir2...指定即可。

使用特权

评论回复
地板
ycz9999| | 2012-7-28 11:50 | 只看该作者
1、struct file_operations HELLO_ctl_ops={
open:   SIMPLE_HELLO_open,
....
};改为:
struct file_operations HELLO_ctl_ops={
.open=SIMPLE_HELLO_open,
....(其他结构体成员同理)
};
2、添加头文件:
#include <linux/errno.h>        /* error codes */

再次编译试试...

使用特权

评论回复
5
spirits_hyx|  楼主 | 2012-7-28 12:25 | 只看该作者
4# ycz9999
这个我试过了,可是还是不行!!!

使用特权

评论回复
6
spirits_hyx|  楼主 | 2012-7-28 12:50 | 只看该作者
你的程序中引用了许多结构体等数据类型的定义,但是你使用gcc编译的时候却没有使用-I  dir 来指定包含这些结构体的头文件的位置。导致编译器找不到。故报错。

你虽然指定了 -I  dir
但是程序中引用的头文件却不在此 ...
shell.albert 发表于 2012-7-28 11:46

#TOPDIR  := $(shell cd ..; pwd)
TOPDIR  := .

KERNELDIR = /pxa270_linux/linux
INCLUDEDIR = $(KERNELDIR)/include
CROSS_COMPILE=arm-linux-
AS      =$(CROSS_COMPILE)as
LD      =$(CROSS_COMPILE)ld
CC      =$(CROSS_COMPILE)gcc
CPP     =$(CC) -E
AR      =$(CROSS_COMPILE)ar
NM      =$(CROSS_COMPILE)nm
STRIP   =$(CROSS_COMPILE)strip
OBJCOPY =$(CROSS_COMPILE)objcopy
OBJDUMP =$(CROSS_COMPILE)objdump

CFLAGS += -I..
CFLAGS += -Wall -O -D__KERNEL__ -DMODULE -I$(INCLUDEDIR)

TARGET = pxa270_hello_drv.o
modules:$(TARGET)
all: $(TARGET)
pxa270_hello_drv.o:pxa270_hello_drv.c
        $(CC) -c $(CFLAGS) $^ -o $@
clean:
        rm -f *.o *~ core .depend
这个是Makefile的内容,上面应该已经指定完路径了,是吧?

使用特权

评论回复
7
ycz9999| | 2012-7-28 15:55 | 只看该作者
本帖最后由 ycz9999 于 2012-7-28 16:02 编辑

5# spirits_hyx 把现在的错误以及Makefile贴出来看看~~~

使用特权

评论回复
8
ycz9999| | 2012-7-28 16:03 | 只看该作者
2# spirits_hyx 还有  你这编译的应该是2.4的kernel吧?

使用特权

评论回复
9
spirits_hyx|  楼主 | 2012-7-28 16:53 | 只看该作者
8# ycz9999
是的,这个内核是2.4的,而我宿主机时2.6的

使用特权

评论回复
10
spirits_hyx|  楼主 | 2012-7-28 16:53 | 只看该作者
7# ycz9999
都贴出来了,都在上面

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

25

帖子

0

粉丝