26
\$\begingroup\$

I have a decent amount of experience designing hardware and embedded systems in general, but I have never written a driver for an operating system.

I would like to know if there are any good guides, preferably online, although good books would interest me, that will give me a good start on what I need to know to design and implement drivers for an operating system.

This will probably have people shooting at me, and although I would love to see a good guide no matter what OS it is based on, I would like to see a guide that is windows based, mostly due to the fact that most of the people I would sell a product would have windows.

Please let me know if there is any extra information I can add to make this more clear.

\$\endgroup\$
  • 1
    \$\begingroup\$ Great question, I'm also interested in this one. \$\endgroup\$ – Mr. Hedgehog Nov 30 '10 at 16:28
  • \$\begingroup\$ I accepted on the broadest answer. For getting information for each OS, i liked the answer. Joby's answer was excellent specific to Linux. I had a hard time deciding. \$\endgroup\$ – Kortuk Dec 10 '10 at 5:02
10
\$\begingroup\$

Most of my recent experience in writing actual OS drivers has been with Linux, and the best reference IMO is Linux Device Drivers, 3rd Edition by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman (2005), which has already been mentioned. It is available on Amazon, Safari Books On-Line, and also as a free download.

A couple more books on the same subject are Essential Linux Device Drivers, by Sreekrishnan Venkateswaran (2008) (also available on Safari Books Online) and Writing Linux Device Drivers: a guide with exercises (Volume 3) by Dr Jerry Cooperstein (2009).

For Windows device drivers, the latest book on the subject (published two weeks ago) appears to be Windows 7 Device Driver, by Ronald D. Reeves, Ph.D. (2010). It is also available on Safari Books Online.

An older book, which would cover Windows XP, is: Programming the Microsoft Windows Driver Model, Second Edition, by Walter Oney (2002). It is also available on Safari Books Online.

Another book, which appears to be out of print but available on Safari Books Online, is Developing Drivers with the Windows Driver Foundation, by Penny Orwick and Guy Smith (2007). I assume it would cover Windows Vista.

Finally, Microsoft has pointers to a lot of blogs etc. discussing driver development.

\$\endgroup\$
  • \$\begingroup\$ Thanks, I would suggest you made your post also have a link to "Linux Device Drivers." Otherwise, Very thorough. \$\endgroup\$ – Kortuk Dec 1 '10 at 5:54
11
\$\begingroup\$

A good driver encapsulates the capabilities of the hardware and makes these available to the OS/applications in a natural way.

How best to do this, depends a lot on which operating system you're targetting and what sort of hardware the driver is for.

My experience is all with Linux and small custom real-time OSen.

For Linux, I'd recommend reading Linux Device Drivers. It's give a good introduction to the different flavours of Linux drivers and the abstractions the operating system provides for them.

Devices like serial ports where data is read sequentially are usually handled by character device drivers with a device node in userspace for applications to read from. cat can read from these.

Random access devices like flash storage and hard disks are handled by block devices. dd can access these. For a good example, have a look at the Linux MTD system.

Drivers which do low level fiddling with hardware will almost certainly need to be implemented in kernel space. You might choose to make a runtime loadable kernel module or to place your code in statically in the linux kernel.

Drivers which build on top of existing generic drivers, like USB, may be written in userspace. Using, for example, libusb.

\$\endgroup\$
  • 4
    \$\begingroup\$ Linux Device Drivers is a good book. Unfortunately, these things are highly OS-specific. Linux is probably easiest to write for, because there are so many drivers in the source tree already for reference. If you have written embedded code to drive a microprocessor's peripherals, you probably have a decent grasp of device driver fundamentals. \$\endgroup\$ – markrages Nov 30 '10 at 16:34
  • \$\begingroup\$ yeah, i am removing my comments. my bad. \$\endgroup\$ – Kortuk Nov 30 '10 at 17:25
  • 1
    \$\begingroup\$ As markrages mentioned, the guts of a driver, which controls the actual hardware, will be the same whether you have an OS or not. The main differences when writing drivers is 1) the interfaces need to fit in a standard model (e.g. open, close, read, write, ioctl) for the OS, and 2) the method in which the driver is installed and activated. \$\endgroup\$ – tcrosley Nov 30 '10 at 23:08
  • 1
    \$\begingroup\$ @tcrosley, If you have a lot of information about those specifics I would love to see an answer about it. \$\endgroup\$ – Kortuk Dec 1 '10 at 4:02
3
\$\begingroup\$

I don't have any experience in this issue, but I'm going to give my two cents.

You can start here http://www.osr.com/index.html or here https://www.osronline.com/index.cfm

Here in Brazil we have a good blog about this issue. It's written in Portuguese and English. Most articles are in Portuguese unfortunately.

There is a post in Portuguese about books in this blog: http://translate.google.com.br/translate?hl=pt-BR&ie=UTF-8&sl=pt&tl=en&u=http://driverentry.com.br/blog/%3Fp%3D825&twu=1

I hope I have helped a little

\$\endgroup\$
  • \$\begingroup\$ This will help alot if I ask the question, "Where do I learn portuguese online in time to learn to write drivers?" Thanks for helping out. \$\endgroup\$ – Kortuk Nov 30 '10 at 16:30
  • 2
    \$\begingroup\$ Don't worry about learn Portuguese. The links about drive development that I passed are in English. Even DriveEntry is written in English too. Unfortunately the post about books is in Portuguese, but the books are in English. And what matters most are the books, not the post. \$\endgroup\$ – Daniel Grillo Nov 30 '10 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.