Forum: DSL Tips and Tricks
Topic: compiling drivers
started by: clacker
Posted by clacker on May 03 2006,16:50Here 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:
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
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
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
patch -p1 -d linux-2.4.26 < knoppix-kernel.patch
Now you should be able to cd to your driver's source directory and compile.
Posted by clivesay on May 03 2006,17:02What a great tutorial, clacker!
Posted by doobit on May 03 2006,17:16Yeah! put this in the Wiki!
Posted by meo on May 04 2006,19:11Thanks a lot clacker for a nice post! It will keep me busy for a while trying to compile my own extensions.
Posted by WDef on May 16 2006,12:40
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  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.
Posted by Amn on May 16 2006,12:44Thanks for the excelent post Clacker!
I've been beaten by a few of the gotchas you pointed out in the past, but I think it's time I tried again!
Posted by WDef on May 16 2006,13:05
'make dep' won't be enough to prepare sources for building some modules.
To correctly prepare sources for module building you need to begin to compile the kernel ie run 'make'. But you can cntrl-C very early in the process, just after the 'split' line in fact. All kernel source files needed for module building with then be correctly prepared.
I made a .uci out of my prepared sources with user.tar.gz placing a symlink from /opt/prepared_sources to /usr/src/linux-2.4.26 or something like that. As long as another .dsl has been installed first (so that mkwriteable has been run), the symlink will get placed on installing the uci. So I can mount the sources without risking maxing out my ramdisk.
I haven't posted it to the repo because:
1. I'm not convinced the resulting sources exactly match the running knoppix 2.4.26 kernel ie I'm not sure I trust the knoppix config file. If they don't, some modules built could be dangerously borked if they don't exactly match the running kernel.
2. A very few progs during compile seem to want the kernel sources to be writeable - I think that might be a hangover from the very early days of linux when, unless I'm mistaken, for example, some prog headers went into the kernel source directory.
Posted by phonky on Mar. 27 2009,12:56
This does not work for me on dsl 3.4/2.4.26.
I get errors about unmet dependencies with libncurses5, libc6...
Posted by phonky on Mar. 31 2009,18:52I do a last try.
How do I compile drivers in DSL?
I'm trying to compile a network driver,
there's a post on this:
< rtl8187b >
I haven't been able to find out how to compile drivers in DSL. This thread is dated and I can't follow it, as stated in the previous post, something is broken.
I'd be very grateful if someone could help. Can't think I'm the only one who's trying to compile a driver in DSL....
Posted by bartgrefte on April 26 2009,19:05Also having trouble compiling a driver, for two onboard Intel 82574L Gb NIC's...
< http://damnsmalllinux.org/cgi-bin....y105871 >