Video Screencast Help

Compiling Drivers for Linux and Adding Them to your Linux Automation Image

Created: 23 Oct 2006 • Updated: 27 Nov 2007 | 7 comments
Language Translations
lordmithrandir's picture
0 0 Votes
Login to vote

This How To explains how to compile drivers for Linux automation and add them to your Linux image. Compiling drivers for Linux automation can be a daunting task, but once your environment is set up and you've done it a few times, it becomes quite easy.

To complete this How To, you will need access to a computer running Linux (most any distro will work; these steps were written using Ubuntu). You will also need to access a DS server, and be able to boot a computer into automation. It is presumed you have a basic understanding of Linux and Deployment Solution. Deployment Solution 6.8, along with Linux kernel version 2.6.16.20, were used in the creation of this document. You should be able to follow these same steps with Deployment Solution 6.5 as well.

Preparing Your Linux Computer

First, you will need to setup your Linux computer to compile drivers for Linux automation. This involves installing the correct compiler, downloading the kernel source code, adding the configuration information from your Linux automation image, and compiling the source code. You should only have to do this part once, after you have everything set up you can skip to the compiling drivers section.

  1. Determine the Linux kernel version your are using for automation. You can do this using Boot Disk Creator. From the DS Console click Tools > Boot Disk Creator. From Boot Disk Creator click Tools > Installed Pre-boot Operating Systems. In the box labeled Linux, the version number will be the kernel version you are using. Make sure you get the kernel version for the architecture you are using (that is, x86, x64, or IA64).

    Figure 1

    Click to view.

  2. Now go to http://www.kernel.org/pub/linux/kernel/v2.6/. Scroll down to the ZIP file that corresponds to the kernel version you are using. Make sure you get the correct file—do not get one of the patch or changelog files. The file you want ends in a .tar.gz extension. So if you had kernel version 2.6.16.20 then you would download linux-2.6.16.20.tar.gz.

    Figure 2

    Click to view.

  3. Copy the file to your Linux computer (if it isn't there already) and extract it to a permanent location. You can keep yours in /usr/src. So if you were going to put yours there, you would copy it to /usr/src then type "tar xfz linux-2.6.16.20.tar.gz" (if your kernel version is 2.6.16.20). You may need root access to use that directory, so if you don't have root access then you can put the files somewhere else (in your home directory, for example).

    Figure 3

    Click to view.

  4. Now you need to verify the version of gcc you have. You can do this by typing gcc --version from the command prompt. You need to make sure you have version 3.4.x. Many Linux distros come with 4.0, so if you have one of these you'll need to get 3.4 as well. You will need root access in order to install another version of gcc. Many package managers can get gcc for you and install all the dependencies. Ubuntu and other Debian distros use apt-get, SUSE uses yast, and RedHat and Fedora use yum. A simple Internet search will guide you in the right direction as to what package you need to install. For Ubuntu the command is "apt-get install gcc-3.4" You may also want to get g++ while you're at it, but you shouldn't need it to complete this how to. (Ubuntu command: "apt-get install g++-3.4")

    Figure 4

    Click to view.

  5. Now that gcc 3.4 is installed you need to make sure it is the default compiler. The easiest way to do this is to use symlinks. The gcc binary itself should be in /usr/bin. In Ubuntu when gcc is installed the binary is named gcc-X.Y, where X.Y is the version number. In our example we have gcc-3.4 and gcc-4.0 in our /usr/bin directory. We want to create a symlink so when we run gcc we get the 3.4 version. From the /usr/bin directory use the following command to do this: "ln -sf gcc-3.4 gcc". If you already have a binary named gcc, this command won't work. You may have to rename the existing binary (you can name it after the version number, so if it is version 4.0, name it gcc-4.0) then create the symlink. Once all of this is done verify you have the correct compiler by typing gcc --version. If it still isn't version 3.4 go through this step again.

    Figure 5

    Click to view.

  6. Now you need to boot a computer into Linux automation and copy the config file from it. You will need this so any drivers you compile are compiled with the same kernel options that the automation kernel has been compiled with. Create a simple Run Script task in DS with the following command: "cp /proc/config.gz /mnt/ds" The file config.gz will now be in at the root of your deployment share on your DS server. Copy it to your Linux computer.

    Figure 6

    Click to view.

  7. With the config.gz file on your linux computer, copy it into the directory where your kernel source files are located. So if you copied your kernel source to /usr/src, and your kernel version was 2.6.16.20, then you would copy the config.gz file to /usr/src/linux-2.6.16.20. Now change to that directory and unzip the file with the following command: "gzip -d config.gz". You should now have a file named confg. Rename it to .config (notice the period in front of config) and use the command "mv config .config". If you do an ls, you'll notice that the config file has disappeared. In Linux, files with a period (.) prefix are hidden files, so they won't show up when you do an ls. If you really want to make sure it is there use "ls -a" and it will show up.

    Figure 7

    Click to view.

  8. Now you need to build the kernel; change to the directory you created the kernel in (in this example you would change to /usr/src/linux-2.6.16.20). Type one of the following commands (depending on your architecture):

    Figure 8

    Click to view.

    • "make bzImage modules" (x86 and x64)
    • "make compressed modules" (IA64)
  9. This will take awhile, depending on the speed of your computer.

Compiling the Driver

Now everything should be set up and ready to go, from here on out you can skip the preparation steps and just compile drivers anytime you like. For this example, we will compile a driver called bnx2, located in the /usr/src/drives/bnx2b folder. To actually compile drivers do the following:

  1. Copy the driver source files to a location of your choice. We'll use /usr/src/drivers, but you can choose whatever location is preferable to you.
  2. Change to the directory containing the driver source files; this is usually a directory with .c, and .h files in it.
  3. To make the drivers, type "make -C /path/to/kernel/source SUBDIRS=$PWD modules". Where /path/to/kernel/source is the path to the kernel source you downloaded in the preparation steps. So in this example, you would type: "make -C /usr/src/linux-2.6.16.20 SUBDIRS=$PWD modules"
  4. Now copy the .ko files that were generated from the compilation process. These are the driver files you need to use.

Figure 9

Click to view.

Note: The compilation process may fail with errors. If you are sure you did everything correctly then it is possible the driver source code is not compatible with the kernel version you are using. In this case you will have to find a different version of the driver source code. It is not uncommon for a variable declaration or function call that the driver expects the kernel to provide to be missing in later kernel releases. Linux kernels are released very frequently and anything is fair game for changing each time. For a particular driver that was needed once, 20 different versions were gone through before the one was found that worked. Even when a driver compiles that doesn't mean it will load properly, it may still complain about missing variables/function calls when it is loaded. That is the joy of working in Linux—you just have to keep trying. The advantage is someone else has probably had your same problem, and you can find how to fix it using the Internet.

Note: If the compilation succeeds, but has warnings this may not be a problem, try loading the driver to see how it goes.

Adding Drivers to the Linux Automation Image

To use the drivers, you need to copy them to the correct location on your DS server and then regenerate your image. To do so do the following:

  1. Copy the .ko files to the correct folder as follows:
    • Deployment Solution 6.5: .\Bootwiz\platforms\Linux\x86\Drivers\CUSTOM\lib\modules\add
    • Deployment Solution 6.8: .\Boozwiz\platforms\Linux\x86\Drivers\CUSTOM\lib\modules\ _ver_\kernel\opt\bdc

    Note: The folders may have to be created. The paths above are relative to the deployment share. Change the x86 folder to correspond to the architecture you are using (x86, x64, IA64).

    Figure 10 (DS 6.5)

    Click to view.

    Figure 11 (DS 6.8)

    Click to view.

  2. Regenerate your Linux image, this can be done in PXE Configuration Manager. Edit the boot image and click next until the image regenerates. Then click Save on the main PXE Configuration Manager menu to save the changes.

If you don't want to add the driver to your image or want to load it using a script you, can load it with the following commands:

  1. Copy the driver to the Linux automation local file system (after it boots)
  2. Change to the directory where you copied the driver to
  3. Type depmod -ae
  4. Type modprobe drivername, and omit the .ko extension, so for the bnx2 driver type "modprobe bnx2". If you get an error, you can try the -f parameter, which tries to force the driver to load. You may get a warning about a tainted kernel but this isn't a huge deal.

Figure 12

Click to view.

Important: The drivers you just compiled will only work with the kernel version they were compiled with. If you upgrade your Linux automation kernel, you will have to resetup your Linux machine and recompile the drivers.

Comments 7 CommentsJump to latest comment

jjesse's picture

Just curious, if for some reason it's my build of ubuntu, but once I compile a driver, I have problems compiling a different driver.
For example, I've compiled the newest broadcom tg3.ko drivers and yet each time I try to compilie a driver for the new e100s I get errors about not finding the correct modules.

Jonathan Jesse Practice Principal ITS Partners

0
Login to vote
jjesse's picture

Ok, I may have figured out some of my problem, but it leads me to another issue. The new Intel Pro100 which uses driver e100-3.5.14 is looking specifically for the kernel source and doesn't appear to allow for the redirection of -C /home/jjesse/linux-2.6.15.1 for building against DS 6.5

Any help?

Jonathan Jesse Practice Principal ITS Partners

0
Login to vote
jgo's picture

Same issue... any love?

John Golembiewski
Midwest Practice Principal
ITS Partners
Jgo@itsdelivers

0
Login to vote
lordmithrandir's picture

Have you tried editing the makefile to enter the path to your source files? Many makefiles use variables such as LINUXSRC, or just LINUX. Some will look for /usr/src/linux so if that doesn't exist you can create a symlink that points to your real source files. So you'd type

ln-sf /home/jjesse/linux-2.6.15.1 /usr/src/linux

So just crack open the makefile to see if you can see anything that looks like a source files path. If you need more help on makefiles I'm sure a google search will steer you in the right direction.

0
Login to vote
jgo's picture

Thanks for the help.

Also is ...

I'm sure a google search will steer you in the right direction.

the equivalent of RTFM??

John Golembiewski
Midwest Practice Principal
ITS Partners
Jgo@itsdelivers

0
Login to vote
jjesse's picture

Thanks for the help. Now I just have to figure how to build the driver for the new Intel Q965 chipset and I'll be all set.

I guess I'll have to google, or RTFM :)

Jonathan Jesse Practice Principal ITS Partners

0
Login to vote
LiquidSpikes's picture

Hello guys,

Thanks so much for the great article.

but I am still having difficultly making the e100 or e1000 drivers from intel.

I am currently running Debian 4.0 (etch)

here is what I get when I try the last step....
-------------------------------------------------
B65829:/usr/src/Drivers/e1000-7.6.9.1/src# make -C /usr/src/linux-2.6.16.20 SUBDIRS=$PWD modules
make: Entering directory `/usr/src/linux-2.6.16.20'
/usr/src/Drivers/e1000-7.6.9.1/src/Makefile:71: *** Linux kernel source not found. Stop.
make: *** [_module_/usr/src/Drivers/e1000-7.6.9.1/src] Error 2
make: Leaving directory `/usr/src/linux-2.6.16.20'
B65829:/usr/src/Drivers/e1000-7.6.9.1/src#
-------------------------------------------------

Any ideas?

Thanks!

0
Login to vote