v4l-compat

A Linux USB DVB driver on FreeBSD


Background

The Video4Linux project includes drivers for a fair range of DVB hardware devices (see the LinuxTV V4l-DVB wiki).

The options for native FreeBSD drivers are more limited. For USB DVB-T devices, there are two drivers that I know of:

However, there is another project, which raised the possibility of porting Linux drivers using a somewhat different approach.

Luigi Rizzo started a project, and created the linux-kmod-compat (ports/devel/linux-kmod-compat) port, to enable Linux device drivers to be built on FreeBSD. Details can be found here.

This project is an extension of the linux-kmod-compat port to allow the compilation of Linux v4l USB DVB driver code (to create a loadable kernel module for FreeBSD). Some further description of this project can be found in dvb_driver_paper.pdf (a paper written to accompany a presentation at EuroBSDCon 2009).

Although the project has not been developed particularly far, a driver for a Hauppauge WinTV Nova-TD Stick (and other dib0700 based devices) has been created from Linux V4l code, as described on the linuxtv wiki page regarding DVB-T USB devices.

The driver appears to work, at least to the limited extent to which it has been tested. It is also possible to compile several other Linux USB DVB driver sources.

Note that the drivers that can be produced using this project will be somewhat experimental in nature. The remote control handling code is unfinished (disabled) and several other areas of the code could probably do with some attention.

It is hoped that the advent of Hans Petter Selasky's video4bsd and cuse4bsd projects, which follow a similar strategy to create userland USB device drivers from Linux sources, will be a better alternative to this project and will make the core of this project largely redundant.


Requirements

The v4l-compat code is currently being developed for FreeBSD 8. However, an earlier version of the code, which has some additional requirements, is available here.


Building a driver

Download and extract this archive of the source code (and a firmware) used in this project: v4l-compat_20100306.tgz.

The Makefile for the project may be used to build and install a device driver module (a loadable kernel module). Note that a module containing debugging information (for kgdb) is currently built by default.

Currently, the only Linux driver that has been compiled is a dib0700 driver (linux/drivers/media/dvb/dvb-usb/dib0700_core.c). The Makefile for the project has been written to compile only the files required for this driver. Minor modifications (see below) to the v4l (linux) source files have, mostly, been made only to required files.

In order for the driver to work, a firmware containing module must also be built. Currently, a separate makefile, Makefile.fw, is used to do this. However, there is a minor complication. The makefile will automatically generate a particular source code file, required for registering a firmware image. An automatically generated version of this file needs some modification before it can be used to create a module that registers the firmware with the required name (required by Linux driver source).

A suitably modified version of the file dvb_usb_dib0700.c, which would be generated, and cleaned up, by using Makefile.fw, is supplied as part of the project. See the notes in Makefile.fw.

A firmware containing module will need to be built (i.e. make -f Makefile.fw), installed and loaded in order for the driver to function correctly.

Note that only the required firmware for dib0700 devices has been included in v4l-compat.tgz


Caveats, limitations and other notes

This project is a work in progress. The drivers built from the code of this project are relatively untested and (great) care should be taken when testing any such driver.

The code is not the most elegant or carefully structured. A few compromises exist and several assumptions have been made. This is, to a certain extent, inherant in creating a FreeBSD device driver by compiling Linux driver source code.

Linux code was slightly modified to resolve certain difficulties. The handling of the building of Linux source from multiple different directories and handling of certain (module_param) macros have not been implemented. Also, some warnings from the Linux code needed suppression. Some #include directives were changed, some module_param macros were replaced by module_paramx and a static was added to some function definitions.

The licensing of this project is not particularly simple. The project includes Linux driver source code. It also includes some code derived fairly directly from Linux dvb source code and some header files copied in whole or part from Linux source.

Any resulting driver modules are certainly covered by the GPL. However, various parts of the source code originate from Luigi Rizzo's linux-kmod-compat project, are derived from code from this project or are completely new. This source code should be covered by a BSD license.

I have tried to make sure that the code has the appropriate copyright notifications, attributions, licenses and other details. However, some code from other projects contained no copyright or licensing details that could have been retained and some mistakes/omissions may have been made.


Tim Borgeaud 2010 tim@tangobravo.co.uk