Writing a "Hello World" Device Driver for kernel 2.6 using Eclipse

I'm in almost same position with you. Following this istructions I have had success with building kernel itself, and a single module.

I added three steps (40~42) to main article to make Eclipse compile a specific driver, not whole kernel.

  1. Download and install Eclipse plus the CDT.
  2. Configure and build your kernel to define CONFIG_* and generate autoconf.h. This can be done before or after downloading and installing Eclipse.
  3. Ensure that you have the right kernel source (e.g. make sure you are on the right git branch). If you check out another branch later, that's ok, but you will need to re-index the source, and that takes about 20 minutes.
  4. Start up Eclipse.
  5. Click File->New->C Project
  6. Fill in a project name like my_kernel
  7. Uncheck the Use default location box and type in the root directory of your kernel into the Location box.
  8. In the Project type: pane, click the Makefile project and select Empty Project
  9. On the right side, select Linux GCC
  10. Click Advanced settings... and a Properties dialog will pop up.
  11. Select Resource on the left, and then in the Text file encoding section, select Other and ISO-8859-1 in the box, then click Apply
  12. Open the C/C++ General selection on the left.
  13. Click on Preprocessor Include Paths
  14. Select GNU C in the Languages list
  15. Select CDT User Setting Entries in the Setting Entries list
  16. Click on Add.... Choose Preprocessor Macros File from the top left dropdown, Project Path from the top right dropdown, and enter include/generated/autoconf.h into the File text box. (Note: for older kernels [pre-2.6.36?], the location of autoconf.h is include/linux/autoconf.h)
  17. Also add any other macros files you are using.
  18. Click on Indexer
  19. Checkmark the Enable project specific setttings box.
  20. Uncheck Index source files not included in the build
  21. Clear out the Files to index up-front box.
  22. Click on Paths and Symbols on the left.
  23. Select the Includes tab and then select GNU C
  24. Click Add...
  25. Click Workspace... then select your kernel's include directory
  26. Do another Add, Workspace and add arch/architecture/include, e.g., arch/powerpc/include
  27. Click the # Symbols tab
  28. Click Add...
  29. Set the name to __KERNEL__
  30. Set the value to 1 and click OK
  31. Click the Source Location tab
  32. Click the twisty for your project.
  33. Select the Filter item and click Edit Filter...
  34. Click Add Multiple... and then select all of the arch/* directories in your kernel source that will not be used (i.e. all the ones that are not for the architecture you are using)
  35. Click OK and OK again to dismiss that dialog.
  36. Click OK on the Properties dialog.
  37. Click Finish on the C Project dialog.
  38. Right click on the project and select Index then select Rebuild
  39. It will take about 20 minutes or so to complete.
  40. Open your project setting, go to the C/C++ build -> Behaviour (tab)
  41. Check the Build (Incremental buil) checkbox and add your module path to the textbox (in my case M=drivers/servo/dynamixel).
  42. When you're module is ready and you want to compile kernel, repeat 41 and replace M=.. with all.

If you want to do driver development with eclipse, you will have to do it the other way round.

You will need to catch up on automake, autogen, pkg-config and so on, create an autotools project and import it into eclipse. The eclipse-cdt should offer this otherwise you missed to install the 'autotools-plugin' (unsure about exact name, writing this from memory).

Just abandon the idea that eclipse-cdt could manage a decent Makefile, C isn't Java, unfortunately or thankfully.


I am new too in Linux driver programming, I found that there a new way to deploy kernel modules (which are not in the official Linux tree) called DKMS. The module will be installed as source and DKMS will take care of compiling it for each kernel. It means the Makefile for module will be written manually and it's source will be not included for autotools.

http://linux.dell.com/dkms/

updated...

DKMS moved to http://en.community.dell.com/techcenter/os-applications/w/wiki/2463.linux-projects.aspx

This tutorials/quick introduction to DKMS (links from Dell project page): Linux Journal article , Power Solutions paper , Ottawa Linux Symposium paper

DKMS used for quick driver deploying. For example kernel modules using DKMS in my Ubuntu machine:

dkms status

bcmwl, 6.20.155.1+bdcom, 3.5.0-41-generic, x86_64: installed
bcmwl, 6.20.155.1+bdcom, 3.5.0-42-generic, x86_64: installed
bcmwl, 6.20.155.1+bdcom, 3.5.0-43-generic, x86_64: installed
nvidia, 313.26, 3.5.0-42-generic, x86_64: installed
nvidia, 313.26, 3.5.0-43-generic, x86_64: installed
vboxhost, 4.3.0, 3.5.0-42-generic, x86_64: installed
vboxhost, 4.3.0, 3.5.0-43-generic, x86_64: installed

This is the code I have written before, It could be helpful as DKMS Hello World. https://github.com/sneetsher/RTD-DM5408-Driver-Port-for-Linux