Showing posts with label kernel. Show all posts
Showing posts with label kernel. Show all posts

Friday, 25 May 2012

Develop Linux kernel module using eclipse


Here is how I did on my Ubuntu 12.04.

First I have downloaded and installed Eclipse IDE for C/C++ Linux Developers in /opt/eclipse .
Just download and extract the archive, and simply run /opt/eclipse/eclipse .

The one provided by Ubuntu should work too, but require some more packages, at least eclipse-cdt.

As a module sample, I chose the one from article  A Simple Block Driver for Linux Kernel 2.6.31
Download or Cut&Paste sbd.c and Makefile in directory ~workspace/sdb (I prefer ~/Documents/workspace/sdb).
Be careful if you Cut&Paste, Makefile expect TAB instead of spaces !

Then create a new project in eclipse


And import the sources


Now when sdb.c is open in eclipse, you should see a lot of syntax errors !

To avoid these messages, you must add some paths and symbols to the project :
Right-click on your project and select properties at the bottom, then add the path of your Linux header files:





/usr/src/linux-headers-3.2.0-24-generic/include is where Ubuntu put the headers of my kernel. I found it doing a

# ls /lib/modules/`uname -r`/build
Don't forget the include at the end of both entries.

Then add symbols __KERNEL__ with value 1 and CONFIG_BLOCK without value. Maybe more variables could be required for more complex module.




After this, I still have problem with the macro module_param.
If you find the solution, please tell me !