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 188.8.131.52, 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.
- 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).
- 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 184.108.40.206 then you would download linux-220.127.116.11.tar.gz.
- 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-18.104.22.168.tar.gz" (if your kernel version is 22.214.171.124). 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).
- 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")
- 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.
- 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.
- 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 126.96.36.199, then you would copy the config.gz file to /usr/src/linux-188.8.131.52. 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.
- 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-184.108.40.206). Type one of the following commands (depending on your architecture):
- "make bzImage modules" (x86 and x64)
- "make compressed modules" (IA64)
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:
- 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.
- Change to the directory containing the driver source files; this is usually a directory with .c, and .h files in it.
- 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-220.127.116.11 SUBDIRS=$PWD modules"
- Now copy the .ko files that were generated from the compilation process. These are the driver files you need to use.
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:
- 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)
Figure 11 (DS 6.8)
- 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:
- Copy the driver to the Linux automation local file system (after it boots)
- Change to the directory where you copied the driver to
- Type depmod -ae
- 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.
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.