2

我目前正在尝试编译 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

我将不胜感激任何帮助解决错误。

编辑

似乎usb_serial_register并且usb_serial_deregister从未在我的内核 API 中定义过。然而,usb_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[]);
4

1 回答 1

3

内核中的 API(可用的头文件、它们的内容、函数原型(或者如果它们首先存在)......)不是固定的(如果你好奇,请参阅离你最近的 Linux 源代码中的Documentation/stable_api_nonsense.txt ) ,因此驱动程序通常只能针对相当窄的内核范围进行编译。检查源代码是否(大致)与内核同时存在。

您还应该检查其驱动程序是否已包含在内核中,无论是作为官方驱动程序还是在暂存区域中。查看Linux USB以检查替代驱动程序和其他新闻。如果没有其他帮助,你应该看看LWN的内核页面(在那里搜索你在当前源代码中找不到的函数并讨论替换),可能是在使用类似 cscope 的东西来创建你的源代码的索引之后(内核和驱动程序)。请务必与负责该区域的人员取得联系,以便他们知道您正在四处摸索,也许可以提供一些指示。

于 2013-01-20T01:28:50.850 回答