USB驱动编译错误

USB驱动编译错误

我目前正在尝试编译 Linux USB UART 驱动程序,此处提供: http://www.exar.com/connectivity/uart-and-bridging-solutions/usb-uarts/xr21v1410

该驱动程序由 2 个头文件和 1 个大型 C 文件组成。这些是 Makefile 的内容:

obj-m := vizzini.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD       := $(shell pwd)

EXTRA_CFLAGS    := -DDEBUG=0

all:
    $(MAKE) -C $(KERNELDIR) M=$(PWD)

modules_install:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions vtty

这是我运行 make 时编译器抛出的错误:

[sj755@localhost xr21v141x-lnx-2.6.35-pak]$ make
make -C /lib/modules/3.4.9-2.fc16.x86_64/build M=/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak
make[1]: Entering directory `/usr/src/kernels/3.4.9-2.fc16.x86_64'
  LD      /home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/built-in.o
  CC [M]  /home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.o
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1643:9: warning: initialization from incompatible pointer type [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1643:9: warning: (near initialization for ‘vizzini_device.ioctl’) [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1646:9: warning: initialization from incompatible pointer type [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1646:9: warning: (near initialization for ‘vizzini_device.tiocmget’) [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1647:9: warning: initialization from incompatible pointer type [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1647:9: warning: (near initialization for ‘vizzini_device.tiocmset’) [enabled by default]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c: In function ‘vizzini_init’:
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1663:9: error: implicit declaration of function ‘usb_serial_register’ [-Werror=implicit-function-declaration]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1677:9: error: implicit declaration of function ‘usb_serial_deregister’ [-Werror=implicit-function-declaration]
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c: In function ‘__check_debug’:
/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.c:1698:83: warning: return from incompatible pointer type [enabled by default]
cc1: some warnings being treated as errors
make[2]: *** [/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak/vizzini.o] Error 1
make[1]: *** [_module_/home/sj755/Downloads/xr21v141x-lnx-2.6.35-pak] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.4.9-2.fc16.x86_64'
make: *** [all] Error 2

这些是主 c 源文件中包含的标头:

#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/errno.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include <linux/serial.h>
#include <linux/slab.h>
#include <asm/unaligned.h>
#include <asm/uaccess.h>

#include <linux/usb/cdc.h>
#ifndef CDC_DATA_INTERFACE_TYPE
#define CDC_DATA_INTERFACE_TYPE 0x0a
#endif
#ifndef USB_RT_ACM
#define USB_RT_ACM      (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
#define ACM_CTRL_DTR            0x01
#define ACM_CTRL_RTS            0x02
#define ACM_CTRL_DCD            0x01
#define ACM_CTRL_DSR            0x02
#define ACM_CTRL_BRK            0x04
#define ACM_CTRL_RI             0x08
#define ACM_CTRL_FRAMING        0x10
#define ACM_CTRL_PARITY         0x20
#define ACM_CTRL_OVERRUN        0x40
#endif

#include "linux/version.h"

#include "vizzini.h"

运行Linux内核3.4.9-2.fc16.x86_64

我将非常感谢任何解决错误的帮助。

答案1

在最新版本的 Linux 内核中,usb_serial_registerusb_serial_deregister函数被设为静态。因此,这些函数仅以文本形式存在于内核对象文件中。可以使用and代替usb_serial_register_driversusb_serial_deregister_drivers

下面是两组函数的定义:

int usb_serial_register(struct usb_serial_driver *driver);
void usb_serial_deregister(struct usb_serial_driver *device);
int usb_serial_register_drivers(struct usb_driver *udriver,
                                struct usb_serial_driver * const serial_drivers[]);
void usb_serial_deregister_drivers(struct usb_driver *udriver,
                                   struct usb_serial_driver * const serial_drivers[]);

usb_serial_register_drivers采用 NULL 终止的指向要注册的 USB 串行驱动程序的指针数组以及用于匹配设备/接口的 usb_driver。两组函数的详细信息可以在这里阅读:

http://lxr.free-electrons.com/source/drivers/usb/serial/usb-serial.c?v=3.4#L1379

http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/drivers/usb/serial/usb-serial.c#L1337

在驱动程序的源代码中,诸如此类的行:

retval = usb_serial_register(&vizzini_device);

被替换为:

struct usb_serial_driver *serial_drivers[2] = {&vizzini_device,NULL};
retval = usb_serial_register_drivers(&vizzini_driver,serial_drivers);

vizzini_driver 和 vizzini_device 在代码中的其他位置定义如下:

static struct usb_driver vizzini_driver = {
        .name          = "vizzini",
        .probe         = usb_serial_probe,
        .disconnect    = vizzini_disconnect,
        .id_table      = id_table,
        .no_dynamic_id = 1,
};
static struct usb_serial_driver vizzini_device = {
        .driver = {
                .owner =    THIS_MODULE,
                .name =     "vizzini",
        },
    .usb_driver     = &vizzini_driver,
        .description        = "Vizzini USB serial port",
        .id_table           = id_table,
        .calc_num_ports     = vizzini_calc_num_ports,
        .probe              = vizzini_probe,
        .open               = vizzini_open,
        .close              = vizzini_close,
        .write              = vizzini_write,
        .write_room         = vizzini_write_room,
        .ioctl              = vizzini_ioctl,
        .set_termios        = vizzini_set_termios,
        .break_ctl          = vizzini_break_ctl,
        .tiocmget           = vizzini_tiocmget,
        .tiocmset           = vizzini_tiocmset,
        .attach             = vizzini_attach,
        .disconnect        = vizzini_serial_disconnect,
        .release           = vizzini_serial_release,
        .read_int_callback  = vizzini_int_callback,
};

答案2

内核内部的 API 远非稳定,因此除非驱动程序与内核源代码大致相同,否则它将无法工作(并且您给出的警告/错误消息指向该确切方向)。大多数树外驱动程序都是可怕的代码,所以对它持保留态度。查看当前内核是否支持这一点,无论是官方的还是在临时驱动程序中。查看Linux-USB,您可能会在那里找到一些指示。

相关内容