2
votes

I have a basic understand of the following:

  • How to read hardware device Data Sheets
  • How hardware devices work in theory
  • What does a device driver do
  • General concepts of C programming
  • Linux OS

I have always believed that if I can understand all the code of a given device driver and can ultimately write the same code from scratch just with the help of above (without looking at the source code), I will be able to get a very good understand of C language and how device drivers work and interact with OS. For me, this would be like a major milestone in my career.

So, over the last few years, I have always thought to learn how to write device drivers (mostly for Linux OS). I always start (this has happened at least 6-7 times) with great enthusiasm and pick a few good online resources and read them. I then take an existing driver code from the Linux kernel (say an Ethernet driver code), obtain a datasheet and start to read the driver code but after reading few lines I kind of get confused and then ultimately give up because I could not follow the rest of the code.

My Question: I know such a tutorial is too good to be true but I still want to ask - Does anybody know a good resource which explains how a Linux device driver was written from starting with detailed references to data sheet and how the existing line of code related with it and then explaining each function/block of code as to why it exists and what does it do exactly.

2

2 Answers

2
votes

There are at least two good books on Linux device drivers development:

I have personally read LDD3 and use it as a reference, but the second one is also very good according to other fellow developers.

When (and if) you read LDD3, it describes everything in good details and has code snippets following the development process from step #1 and to the end. The book, however, doesn't have the full code itself (which as a good thing, or else it becomes bloated), but I recommend you actually download and look at examples.

It will most definitely not only get you started, you will be able to write any device. Be that an Ethernet network driver, a fancy kernel extension for your specialized user application, or a fully-blown kernel bypass strategy with DMA buffers mapped into the user space.

However, you will probably not be able to a full step by step story of any real-world device driver. This is because of a few things — it is a lot harder to write a book like that, harder then writing a driver itself. Chances are that it won't sell well due to being extremely device specific. So when it comes to details like working nicely with a DMA engine of some device, or Ethernet LSO, you will have either have experience in this, learn some existing device and its driver, or at least ask specific questions (here or somewhere else).

I'd say that the most straight forward way for you when you come to that point is to join a team that does exactly that, work closely with people, keep getting more and more experience. Until one day you would be able to sit down, pull off your 10G NIC off the shelf, sit down and write an industrial grade driver (well, or until your interests change).

You may also try some open source projects too. For example, take a look at PF_RING DNA or similar projects. It is very interesting because you can take existing drivers and have to make a few adjustments to make it work with PF_RING infrastructure. In my personal opinion though, open-source projects are usually a little bit less effective in teaching and helping you gain real-world experience useful because in there people don't sit next to you, etc.

So... just do it!

0
votes

I have the same experience as you before, although I can not say I am an kernel expert now. But I can share something with you.

(1)Before one start to study/development one Linux device driver, one should be familiar with the common APIs in the linux kernel which is related to the specific Linux device driver. As one knows that different kinds of device drivers are with totally different implementation, and using different APIs.

(2)There are good books to get familiar with kernel implementation and device driver develpment; such as: Understanding.the.Linux.Kernel.3rd.Edition; Linux.Kernel.Development.3rd.Edition; Linux.Device.Driver.Development.3rd.Edition;

(3)The last suggestion is that it's better that your study is related to project which will give you some pressure and push you forward daily.