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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2222763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:25:20  来源:igfitidea点击:

How should I get started on writing device drivers?

cassemblyhardwaredrivers

提问by Bjorn

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.

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

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!

我想我想要的是一些提示或建议和指导,有没有人知道没有驱动程序的设备列表,或者我可以为已经支持的东西编写驱动程序(更喜欢前者,所以我实际上是提供价值)。什么是入门的好设备?我咬得比我能咀嚼的多吗?我不害怕低级编程或汇编或任何需要的努力。我真的很想挑战一下!

采纳答案by jschmier

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

对于 Linux,您可能会考虑拿起 O'Reilly Linux Device Drivers一书或在线阅读PDF。在我看来,它是关于这个主题的更好的文本之一。

The Linux Kernel Module Programming Guideis another good resource.

Linux Kernel Module Programming Guide是另一个很好的资源。

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 Editionon the way).

您可能还想拿起一本专门关于 Linux 内核的书。为此,我拿起了一份 Robert Love 的Linux Kernel Development(第 2 版)(正在准备第 3 版)。

回答by Andrew McGregor

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.

没有办法大致说一个司机会有多少工作;一个 GPU 驱动器可能要花费数亿美元,一个 LED 驱动器最多需要几个小时的工作。

回答by AndiDog

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

如果您想进行 Linux 设备驱动程序开发,则必须阅读O'Reilly 免费提供的《Linux Device Drivers, Third Edition》一书。

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

为了找到您可以为其编写驱动程序的不受支持的硬件部分,请在Linux 邮件列表上询问。也许是一些 USB 3.0 设备?;)

回答by Nikolai Fetissov

For Mac you might want to take a look at Mac OS X Internalsbook. 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.

对于 Mac,您可能想看看Mac OS X Internals一书。它的思想和沉重,但读起来很有趣。它主要是关于基于 PowerPC 的 Mac,但有一个关于基于 Intel 的 Mac 的附录。对于 Linux,请查看Linux 设备驱动程序,第 3 版- 它更轻巧(在线免费 PDF :)并且真正面向设备驱动程序,可能是一个更好的开始。