Wednesday, May 2, 2007

Compiling a Device Driver Module

Compiling a Device Driver Module

You may skip this step if a pre-compiled module is available for your Linux distribution. In many cases drivers compiled for similar kernel versions will work. Pre-compiled modules in the form of RPMS for popular distributions are frequently available.

If a pre-compiled module is not available, you'll have to compile one from the driver source code, or the source code RPM (SRPM). In the instructions below driver.c refers to the name of the driver source file for your device e.g. 3c59x.c, and driver.o refers to the compiled driver module binary.

  • Verify that the source code for your current kernel version is installed.
  • If you don't have a /usr/include/linux/version.h file, do
    cd /usr/src/linux; make include/linux/version.h
  • Copy the driver source code to a source directory. I usually use /usr/src/modules/driver.c.
  • Compile the file using the compile-command at the bottom of the driver source file. If a compile-command is not there use the following compile command: gcc -DMODULE -D__KERNEL__ -O6 -c driver.c
  • As 'root', test the module by doing "insmod driver.o".
  • Install the driver module in the proper location for your distribution. This is usually /lib/modules/kernel-version/net/driver.o. The command to do this is install -m 644 driver.o /lib/modules/`uname -r`/net/

No comments: