编译驱动程序时出错 - 初始化程序中指定的未知字段

时间:2012-09-28 12:26:43

标签: c compilation linux-device-driver

我正在尝试在Ubuntu 10.04 LTS上编译视频驱动程序,这是错误:

**************************************************************************
* Building Techwell TW686x driver...                                     *
* Type "make help" for a list of available targets.                      *
**************************************************************************

make -C /lib/modules/`uname -r`/build M="/home/v4/driver-686x-0.1.1" clean
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-43-generic'
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-43-generic'
make -C /lib/modules/`uname -r`/build M="/home/v4/driver-686x-0.1.1" modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-43-generic'
  CC [M]  /home/v4/driver-686x-0.1.1/tw686x-core.o
  CC [M]  /home/v4/driver-686x-0.1.1/tw686x-video.o
  CC [M]  /home/v4/driver-686x-0.1.1/tw686x-i2c.o
  CC [M]  /home/v4/driver-686x-0.1.1/tw686x-device.o
  CC [M]  /home/v4/driver-686x-0.1.1/i2c-sw.o
  CC [M]  /home/v4/driver-686x-0.1.1/tw686x-alsa.o
  CC [M]  /home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.o
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:341: warning: initialization from incompatible pointer type
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:343: warning: initialization from incompatible pointer type
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: error: unknown field ‘vaddr’ specified in initializer
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: warning: excess elements in struct initializer
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: warning: (near initialization for ‘qops’)
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c: In function ‘videobuf_queue_dma_contig_init_tw’:
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:357: warning: passing argument 2 of ‘videobuf_queue_core_init’ discards qualifiers from pointer target type
include/media/videobuf-core.h:197: note: expected ‘struct videobuf_queue_ops *’ but argument is of type ‘const struct videobuf_queue_ops *’
make[2]: *** [/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.o] Error 1
make[1]: *** [_module_/home/v4/driver-686x-0.1.1] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-43-generic'
make: *** [modules] Error 2

我的内核是2.6.32-43。我的C非常生疏,所以我问大师们。 从我所看到的,问题是指文件videobuf-core.h中的变量videobuf_queue_ops,我在这些位置找到了:

/usr/src/linux-headers-2.6.24-24/include/media/videobuf-core.h
/usr/src/linux-headers-2.6.32-43/include/media/videobuf-core.h
/usr/src/linux-headers-2.6.24-32/include/media/videobuf-core.h

这是令人讨厌的文件(摘录)videobuf-dma-contig-tw.c:

static struct videobuf_qtype_ops qops = {
    .magic        = MAGIC_QTYPE_OPS,

    .alloc        = __videobuf_alloc,
    .iolock       = __videobuf_iolock,
    .mmap_mapper  = __videobuf_mmap_mapper,
    .vaddr        = __videobuf_to_vaddr,
};

头文件中videobuf_qtype_ops的定义如下所示:

struct videobuf_queue_ops {
    int (*buf_setup)(struct videobuf_queue *q,
             unsigned int *count, unsigned int *size);
    int (*buf_prepare)(struct videobuf_queue *q,
               struct videobuf_buffer *vb,
               enum v4l2_field field);
    void (*buf_queue)(struct videobuf_queue *q,
              struct videobuf_buffer *vb);
    void (*buf_release)(struct videobuf_queue *q,
                struct videobuf_buffer *vb);
};

#define MAGIC_QTYPE_OPS 0x12261003

/* Helper operations - device type dependent */
struct videobuf_qtype_ops {
    u32                     magic;

    void *(*alloc)      (size_t size);
    void *(*vmalloc)    (struct videobuf_buffer *buf);
    int (*iolock)       (struct videobuf_queue* q,
                 struct videobuf_buffer *vb,
                 struct v4l2_framebuffer *fbuf);
    int (*mmap)     (struct videobuf_queue *q,
                 unsigned int *count,
                 unsigned int *size,
                 enum v4l2_memory memory);
    int (*sync)     (struct videobuf_queue* q,
                 struct videobuf_buffer *buf);
    int (*video_copy_to_user)(struct videobuf_queue *q,
                 char __user *data,
                 size_t count,
                 int nonblocking);
    int (*copy_stream)  (struct videobuf_queue *q,
                 char __user *data,
                 size_t count,
                 size_t pos,
                 int vbihack,
                 int nonblocking);
    int (*mmap_free)    (struct videobuf_queue *q);
    int (*mmap_mapper)  (struct videobuf_queue *q,
                struct vm_area_struct *vma);
};

我应该更改此头文件吗?我不确定修复是什么,或者我是否应该更改Linux文件 - 可怕的东西!

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

仅此部分

  

/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:343:警告:从不兼容的指针类型初始化
  /home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344:错误:初始化程序中指定的未知字段'vaddr'   /home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344:警告:struct initializer中的多余元素

告诉我们初始化器和结构体使用不同的类型,不同的字段名称和不同数量的元素。

绝对不是正确的包含文件。 : - )

您必须弄清楚应该使用哪个版本,并确保其中一个版本位于包含路径中(而不是其他版本)。

答案 1 :(得分:1)

由于某种原因,编译器不喜欢这部分:

static struct videobuf_qtype_ops qops = {
    .magic        = MAGIC_QTYPE_OPS,

    .alloc        = __videobuf_alloc,
    .iolock       = __videobuf_iolock,
    .mmap_mapper  = __videobuf_mmap_mapper,
    .vaddr        = __videobuf_to_vaddr,
};

编译器告诉您发生错误的行号:

videobuf-dma-contig-tw.c: 344 :错误:初始化程序中指定的未知字段'vaddr'

现在的问题是为什么vaddr中没有struct videobuf_qtype_ops成员。它可能在#if之下,但我不确定。此文件中未定义struct videobuf_qtype_ops

你自己应该看看这个。发布大量不相关的代码并不能很好地利用人们的时间。