« Updating the IPW2200 Driver & Firmware | Main | Some "Security" Measures are Just Plain Worthless »

June 10, 2005

Linux Device Drivers Really Are Easy to Write

In the process of updating Guru Labs GL250 Enterprise Linux Administration course, I have learned many new and interesting things. This past week, I updated the kernel compilation lab exercises.

We wanted students to learn the different ways they can build and install additional drivers for the kernel. To accomplish this goal, we needed a driver that could be built & installed as well as applied as a patch to the kernel trees for all the distributions that our course supports. This presents many challenges which were most easily solved by writing a new driver from scratch, which I did.

"Come on, Lamont; why couldn't you have just used some existing driver out there?" The first difficulty is finding an available driver that is neither already included with the "vanilla" kernels, but has not been added to the distribution kernels by either Red Hat or SUSE. Another issue is that we have no way of knowing what hardware will be available in classrooms around the world. Guru Labs courses are taught in over 120 countries worldwide; any driver selected for use in the lab demonstration would have to be workable in so many different classrooms on such varied hardware that it really would be impossible to use any hardware driver.

"OK. But why does it have to support hardware that really exists?" The short answer: it doesn't. However, we do want students to be able to see, from the beginning to the end of the process, that they have successfully installed the new driver. The good news here is that we do not need it to support any hardware, at all.

So, I learned how to write a device driver for the 2.6 Linux kernel. The driver supports a character device that can be read from via a device node. When read, it will output one word per line, at random. The words are from the RFC3092 list, plus a couple of others.

In the lab, students will build this driver as an "External Driver" or, in other words, it will be built outside of the kernel source tree without building the entire kernel, as well. They will also apply a patch to a kernel source tree, which they configure in other ways and build, install & test a custom kernel.

If you want to learn how to write device drivers for the 2.6 Linux kernel, I would highly recommend the book "Linux Device Drivers" (3rd Edition, O'Reilly Press). It is also available online at http://lwn.net/Kernel/LDD3/ in PDF format, one file per chapter. This book is very well written, providing excellent sample code showing many good software engineering practices with good explanations of why things should be done this way or that for almost everything covered. I will be buying a copy of this book, soon.

Now that I know how to build drivers for the 2.6 kernel, I have a couple of projects that I will be able to do. Hardware for which no Linux driver has been available will not remain useless for much longer. Wish me luck.
--
Lamont R. Peterson

Posted by lamontp at June 10, 2005 12:34 PM

Trackback Pings

TrackBack URL for this entry:
http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/61

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)