我应该如何开始编写设备驱动程序?

我想学习如何编写设备驱动程序,因为我认为这会很有趣。我使用 Mac OS X Macbook,但我也有一台 Ubuntu 机器(运行在 Mac Min 上)。我非常熟悉 C 语言,目前正在阅读 这本书。我在网上找到了一些链接,比如 Mac Dev 中心。我这么做是因为这会很有趣。我认为看到硬件因为我编写的软件而运行会有真正的满足感。

我想我需要的是一些技巧、建议和指导,有没有人知道一些没有驱动程序的设备,或者我可以为一些已经支持的设备编写驱动程序(我更喜欢前者,所以我实际上提供了价值)。什么是一个好的开始设备?我是不是贪多嚼不烂?我不害怕低级别的编程或者组装或者任何需要的努力。我真的很喜欢挑战!

99293 次浏览

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.

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? ;)

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).

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.