Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Goal

I am trying to write a simple device driver on Ubuntu. I want to do this using Eclipse (or a better IDE that is suitable for driver programming). Here is the code:

#include <linux/module.h>

static int __init hello_world( void )
{
  printk( "hello world!\n" );
  return 0;
}

static void __exit goodbye_world( void )
{
  printk( "goodbye world!\n" );
}

module_init( hello_world );
module_exit( goodbye_world );

My effort

After some research, I decided to use Eclipse CTD for developing the driver (while I am still not sure if it supports multi-threading debugging tools). So I:

  1. Installed Ubuntu 11.04 desktop x86 on a VMWare virtual machine,
  2. Installed eclipse-cdt and linux-headers-2.6.38-8 using Synaptic Package Manager,
  3. Created a C Project named TestDriver1 and copy-pasted above code to it,
  4. Changed the default build command, make, to the following customized build command:

make -C /lib/modules/2.6.38-8-generic/build M=/home/isaac/workspace/TestDriver1

The problem

I get an error when I try to build this project using eclipse. Here is the log for the build:

**** Build of configuration Debug for project TestDriver1 ****

make -C /lib/modules/2.6.38-8-generic/build M=/home/isaac/workspace/TestDriver1 all

make: Entering directory '/usr/src/linux-headers-2.6.38-8-generic'

make: *** No rule to make target vmlinux', needed byall'. Stop.

make: Leaving directory '/usr/src/linux-headers-2.6.38-8-generic'

Interestingly, I get no error when I use shell instead of eclipse to build this project. To use shell, I just create a Makefile containing obj-m += TestDriver1.o and use the above make command to build.

So, something must be wrong with the eclipse Makefile. Maybe it is looking for the vmlinux architecture (?) or something while current architecture is x86. Maybe it's because of VMWare?

As I understood, eclipse creates the makefiles automatically and modifying it manually would cause errors in the future OR make managing makefile difficult.

So, how can I compile this project on eclipse?

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

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.
share|improve this answer
add comment

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.

share|improve this answer
    
Thanks. I will check the autotools plugin soon. Do you know any better IDE for driver programming? Do you think I (a lazy VS user who have no experience in linux) can manage makefile? Is makefiles really manageable in big projects? –  Isaac Oct 1 '11 at 20:10
    
I was a lazy VS user too and I must admit mastering the autotools has a steep learning curve but it's very worthwhile, not only for linux. Eclipse is one of the best IDEs around, but autotools projects are so diverse that no IDE can parse all the possibilities. Try geany if you want to do it right, try anjuta and codelite if you liked VS6 but always be proficient at command line compile. –  aquaherd Oct 4 '11 at 19:39
add comment

1> you can try with this command

"make" --> "/usr/bin/make"

/usr/bin/make -C /lib/modules/2.6.38-8-generic/build M=/home/isaac/workspace/TestDriver1

2> in directory store your hello word code,creat file name "Makefile"

obj-m := NameofyourHelloWold.o

KDIR := /lib/modules/2.6.38-8-generic/build

PWD := $(shell pwd)

default: $(MAKE) -C $(KDIR) M=$(PWD) modules

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.