To help with this task, I decided to start working on an emulation layer that would let us recompile the linux source code on FreeBSD, and provide a sufficiently complete emulation of the kernel APIs so that device drivers (or at least certain classes) could be used without modifications to their source code.
The methodology is not new - FreeBSD has always offered emulation of different APIs at the syscall level, and also some emulation of the Windows API is available for network device drivers. So I am just repplying the concept to another area which is currently lacking native support. My initial focus was on usb webcam drivers, and so this emulation layer contains enough to create a character driver using the services of the USB stack.
Current status (updated 18 Nov. 2008): The project has reached a usable form with three webcam drivers ('gspca', 'spca', 'ov') rebuilt under FreeBSD and working. What remains to do is some cleanup of the locking, and add support for BULK and other transfer types as the need arises. The most recent version of the code is now available as three Freebsd ports:
Emulation strategy This project is made of several components, not all of them needed in all drivers, nor all implemented so far. These are:
Finally, some cases are even harder because the equivalence is not on single functions but on sets of them - in which case we need to record the sequence of calls done by the linux driver, and when we have enough information to perform the equivalent FreeBSD functions, issue a number of FreeBSD calls to perform the task, possibly storing the results and returning them to the linux driver a few at a time. We had to follow this approach when emulating the functions of the USB stack. The details are described in linux/usb.h and in the source file (at the moment, linux_compat.c) |
Common porting problems The problems in building a linux driver on FreeBSD are described in more detail in the README included in the tarball. However some of the problem you may encounter are:
|