views:

186

answers:

3

Recently, i began developing a driver of an embedded device running linux.

Until now i have only read about linux internals.
Having no prior experience in driver devlopment, i am finding it a tad difficult to land my first step.

  • I have downloaded the kernel source-code (v2.6.32).
  • I have read (skimped) Linux Device Drivers (3e)
  • I read a few related posts here on StackOverflow.
  • I understand that linux has a "monolithic" approach.
  • I have built kernel (included existing driver in menuconfig etc.)
  • I know the basics of kconfig and makefile files so that should not be a problem.

Can someone describe the structure (i.e. the inter-links)
of the various folders in the kernel-source code.

In other words given a source-code file,
which other files would it refer to for related code

(The "#include"-s provide a partial idea)

Could someone please help me in getting a better idea?
Any help will be greatly appreciated

Thank You.

+4  A: 

Given a C file, you have to look at the functions it calls and data structures it uses, rather than worrying about particular files.

There are two basic routes to developing your own device driver:

  • Take a driver that is similar to yours; strip out the code that isn't applicable to your device, and fill in new code for your device.
  • Start with the very basic pieces of a device driver, and add pieces a little at a time until your device begins to function.

The files that compose your driver will make more sense as you complete this process. Do consider what belongs in each file, but to some extent, dividing a driver among files is more an art than a science. Smaller drivers often fit into just one or two files.

A bit of design may also be good. Consider what you device does, and what your driver will need to do. Based on that, you should be able to map out what functions a device driver will need to have.

I also believe Linux Device Drivers, Third Edition may help you get on your way to driver development.

Linux files themselves include files based on what they do, what layer they are in, and what layer they access of the call stack. The Big Picture truly informs how each file is related to the next.

WhirlWind
+1 on the Linux Device Driver recommendation
ctuffli
Thanks for the recommendation. will go thru the book carefully tonight. What else?? A practical walkthrough anyone??...
CVS-2600Hertz
It takes a real expert more than a few pages to walk through the kernel... on top of that, many parts of the kernel change rapidly, so it is out of data once it's written. Your best bet is to read and understand subsystems that interest you.
WhirlWind
+1  A: 

I had to fix a kernel driver once. My biggest tip (if you use vim) is to set it up with ctags so you can jump around the kernel source with ctrl-] every time you see a function you don't understand.

frankster
A: 

Best thing to navigate if you are connected online is http://lxr.linux.no/

As suggested, use cscope with Vim or if you could by SourceInsight, it will be the best to move around.

Also, most of the directories will have a README or start from HOWTOs directory.

subbul