How should I get started on writing device drivers? [closed]
Asked Answered
B

4

87

I would like to learn how to write device drivers because I think it would be fun. I use a Mac OS X Macbook, but I also have an Ubuntu machine (running on a Mac Min). I am pretty familiar with C and currently am reading this book. I have found some links online such as Mac Dev Center. I am doing this because it would be fun. I think there would be real gratification to see hardware operate because of software I wrote.

I guess what I would like is some tips or advice and guidance, and does anyone know of a list of devices that don't have drivers or can I write a driver for something that's already supported (would prefer the former so I'm actually providing value). What's a good device to get started with? Am I biting off more than I can chew? I'm not afraid of low level programming or assembly or whatever amount of effort is required. I'd like a challenge really!

Bullock answered 8/2, 2010 at 15:49 Comment(8)
Since you mentioned both OS X and Linux, what OS would these device drivers be for?Smoking
Either one, I guess I'd prefer OS X since that's the laptop I use.Bullock
"devices that don't have drivers..." Any such device would not be usable! A device manufacturer has to create a driver, or else they cannot sell their product. Having said that, there are some very, very simple devices out there.Careful
eudyptula-challenge.org and github.com/agelastic/eudyptula (readme has the tasks, dont immediatly look at the solutions ;) )Ty
@Careful "In many cases, a device is designed according to a published hardware standard. This means that the driver can be written by Microsoft, and the device designer does not have to provide a driver." from docs.miscrosoft.comPrismoid
"devices that don't have drivers" -- There are (probably) a variety of SPI slave (and I2C) devices (e.g. sensors, nonvolatile memory) that might not (yet) have Linux drivers, although SPI protocol drivers are a special class of driver. Apparently @Careful is referring primarily to PC hardware rather than industrial hardware, which does get released w/o Linux drivers or any software, e.g. because the main market could be microcontroller applications.Dorset
@ElishaHabinsky The context of what I'm quoting from the OP's question is key. My point stands, regardless of who writes the driver, so didn't elaborate about it.Careful
@Dorset Yes, that is true. I'm making an assumption that the OP is also referring to PC peripherals. I don't think this application applies to the kind of hardware you're talking about; although it might be one potential application.Careful
S
51

For Linux, you might look into picking up the O'Reilly Linux Device Drivers book or reading PDFs online. In my opinion, it is one of the better texts around on the subject.

The Linux Kernel Module Programming Guide is another good resource.

You may also want to pick up a book specifically on the Linux Kernel. I picked up a copy of Robert Love's Linux Kernel Development (2nd Edition) for this purpose (3rd Edition on the way).

Smoking answered 8/2, 2010 at 15:58 Comment(3)
Thank you! How much work is it to write a device driver? Is it more or less work than writing a big complex application? I asked everyone who answered this question, because I really want an answer. Thanks again!Bullock
The difficulty and amount of work involved depends on the complexity of the device. A tty device driver may be much less complex than a usb or pci device driver.Smoking
Start by writing a Kernel module as a driver first. Basic hello world program. and inserting in your Ubuntu/mac. See the Kernel logs and understand what is happening. Then try registering a dummy driver on a bus like ( PCI or USB), and then move towards adding more functions like read write and IOCTL calls. Finally can move to implementation more complex calls of power management hooks, sleep, shutdown. Also if working on embedded, platform drivers and DMA can also is an interesting read.Ribbon
H
40

Writing a device driver can be pretty simple, or it can be almost arbitrarily complicated. For instance, I've been involved in a project where it took six of us almost three years to solve ONE bug in a device driver. Of course, we cleared out dozens of other bugs while looking for it... the code improved immensely. The fix turned out to be an eight line patch, that cost, conservatively, about a million dollars.

But, as a side project to that, I wrote an ethernet driver from the chip data sheet in a week, and took another week to debug it. Haven't needed to touch it since.

There's no way to say in general how much work a driver will be; a GPU driver could cost hundreds of millions, a driver for a single LED costs a couple of hours work at the most.

Hardman answered 8/2, 2010 at 22:1 Comment(1)
Can you share some more details. Would love to understand the patch and why it was so tough to debug. Which class of device was the driver of ?Ribbon
W
8

If you want to go for Linux device driver development, the freely available O'Reilly book Linux Device Drivers, Third Edition is a must read.

In order to find unsupported hardware pieces for which you could write a driver, ask on the Linux mailing lists. Maybe some USB 3.0 device? ;)

Wheresoever answered 8/2, 2010 at 15:58 Comment(1)
Thank you! How much work is it to write a device driver? Is it more or less work than writing a big complex application?Bullock
S
3

For Mac you might want to take a look at Mac OS X Internals book. It's think and heavy but fun to read. It is mostly about PowerPC-based Macs but has an appendix about Intel-based ones. For Linux take a look at Linux Device Drivers, 3rd Edition - it's lighter (free PDFs online :) and is really device driver-oriented, might be a better start.

Sacrament answered 8/2, 2010 at 15:57 Comment(2)
Thank you! How much work is it to write a device driver? Is it more or less work than writing a big complex application?Bullock
Hmm, in both cases you need to know what you are doing, so you need to understand the surrounding environment, and that comes from experience, which you don't get until you try :) Work through several examples from LDDv3, the source code is online but a bit outdated for current kernels, you'll get a feel of what's involved and what you'd like to learn next.Sacrament

© 2022 - 2024 — McMap. All rights reserved.