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
我將不勝感激任何幫助解決錯誤。
在最新版本的 linux 核心中,
usb_serial_register
和usb_serial_deregister
函式是靜態的。因此,這些函式僅作為文本存在於核心對象文件中。可以改為使用andusb_serial_register_drivers
。usb_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, };