DSL Tips and Tricks :: compiling drivers



Here are some things I do when compiling drivers and modules for dsl.

The first step is to download and install two packages from the System section of the dsl repository: gcc1.dsl and kernelsource.dsl.  I would also recommend gnu-utils.dsl because some programs require it and it makes finding the newly created files easier.  You can use the mydsl icon on the desktop, or load them by hand by highlighting the file in emelfm and pressing the top middle "MyDSL" button for each file.  If you are on a liveCD or frugal install, it doesn't hurt to download them beforehand and save them and the driver source code to a CD or other drive you can see from dsl so that you can reload again as needed.

Once you use tar -xzvf mydrivers.tar.gz to unpack the driver sources (replace mydrivers.tar.gz with your package's file name), read all of the README and INSTALL files.  That will help since the steps are slightly different from driver to driver in terms of compiling, installation, and testing.  Most programs use the following three steps:

./configure
make
sudo make install


If you are running from a liveCD or a frugal install, you might need to run these two lines before you run your "sudo make install" step:

sudo rm /lib/modules/2.4.26/modules.*
sudo cp /KNOPPIX/lib/modules/2.4.26/modules.* /lib/modules/2.4.26

These two lines prevent the "sudo depmod -a" step that many installs need to run from failing due to the read only nature of the modules.* files.  You might see an error that says "depmod: Can't open /lib/modules/2.4.26/modules.dep for writing" if you omit this step and your driver may not load correctly.  If you see that error, try the above 2 lines and run the "sudo make install" command again.

Now try your driver out.  Is it working?  Did the README or INSTALL require a "sudo insmod some_driver.o" command to be run?

If you get errors about missing libraries or packages, you can install the dsl-dpkg.dsl package and run:

sudo apt-get update
sudo apt-get install whatever-package

You can often easily find what packages your missing components are in yourself using the Debian package search.  If make or gcc complains about a missing something.h then search for something.h on the Debian packages site and then use "sudo apt-get install whatever" to load the missing package.  I've found in my own experience that libncurses5-dev and libreadline4-dev are the most common packages I need to load by far.

----------------------------------------------------

One trick I use a lot to create *.dsl packages for drivers is to create a dummy marker file, install the drivers, and then use find to see what files were added or changed.  If you want to try this you do need to have gnu-utils loaded.  Replace the "sudo make install" command with these five commands:

lsmod > old_modules
touch mymarker
sudo make install
sudo find / -not -type 'd' -cnewer mymarker | grep -v "\/proc\/" | tee files
lsmod > new_modules

This creates a file called "files" that contains a list of all of the files that were added or changed during the installation.  I then edit that file and remove the leading "/ramdisk" from the lines and also look for things that shouldn't get backed up like any /etc/mtab or /etc/fstab files.  Also avoid saving the /lib/modules/2.4.26/modules.* files.  I can see what modules were loaded by looking for anything that is different between the old_modules and new_modules files.  Then I use the following command to pack up the drivers in a neat little package:

tar -czvf mydriver.dsl --numeric-owner --no-recursion -T files

Then you can load the drivers again from a frugal or liveCD reboot.  You will need to load the drivers by hand using sudo insmod mydriver.o so you'll need to look at the output from lsmod to see what drivers you have running before you reboot.

----------------------------------------------------

I have had problems with some drivers and packages not finding things they need in the kernelsource.dsl.  If that's the case, you may need to download the full kernel sources from www.kernel.org as the file linux-2.4.26.tar.gz, create a /usr/src directory, and untar the kernel sources there.  Create a /usr/src directory:

sudo mkdir /usr/src
sudo chown dsl /usr/src
sudo chgrp staff /usr/src
tar -xzvf linux-2.4.26.tar.gz -C /usr/src

You could also download the smaller linux-2.4.26.tar.bz2 sources which are compressed with bzip.  To unpack them use the line tar -xjvf linux-2.4.26.tar.bz2 -C /usr/src (uses a 'j' instead of a 'z').  You can use the j option for bzipped driver sources as well.


Then you need to load the dsl-dpkg.dsl package and run:

sudo apt-get update
sudo apt-get install libncurses5-dev patch

Put the .config and knoppix-kernel.patch files in the /usr/src directory.  Untar the kernel sources into /usr/src and cd to the /usr/src/linux-2.4.26 directory that gets created.  Run

make menuconfig

When it starts use the arrow key to go to the bottom and use the load option (second from the bottom) to load the ../.config file (which is the /usr/src/.config file).  Exit and save.  Then run

cd ../
patch -p1 -d linux-2.4.26 < knoppix-kernel.patch
cd linux-2.4.26
make dep

Now you should be able to cd to your driver's source directory and compile.

What a great tutorial, clacker!

Bookmark

Yeah! put this in the Wiki!
Thanks a lot clacker for a nice post! It will keep me busy for a while trying to compile my own extensions.

Have fun,
meo

Quote
This creates a file called "files" that contains a list of all of the files that were added or changed during the installation.


Another tip: one way to capture all files that would be installed after a compile is to try checkinstall.dsl (requires dsl-dpkg.dsl and gnu-utils.dsl).

Instead of sudo make install, run (as root):

# checkinstall -D

and correct the numbered fields as asked (usually just change [2] to the name of your prog)

In most cases this will build a quasi-Debian package from your newly-compiled prog.  Won't work on some things (eg perl modules I think).

Install the deb package and test.

Then run deb2dsl

I usually use checkinstall with all compiles on hd installed distros so I can cleanly uninstall with dpkg or yum. No more hunting for files.

Next Page...
original here.