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.
- Download and install Eclipse plus the CDT.
- Configure and build your kernel to define
CONFIG_*
and generateautoconf.h
. This can be done before or after downloading and installing Eclipse. - 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.
- Start up Eclipse.
- Click
File
->New
->C Project
- Fill in a project name like
my_kernel
- Uncheck the Use default location box and type in the root directory of your kernel into the Location box.
- In the Project type: pane, click the Makefile project and select Empty Project
- On the right side, select
Linux GCC
- Click
Advanced settings
... and a Properties dialog will pop up. - 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 - Open the
C/C++ General
selection on the left. - Click on
Preprocessor Include Paths
- Select
GNU C
in the Languages list - Select
CDT User Setting Entries
in the Setting Entries list - Click on
Add
.... Choose Preprocessor Macros File from the top left dropdown, Project Path from the top right dropdown, and enterinclude/generated/autoconf.h
into the File text box. (Note: for older kernels [pre-2.6.36?], the location ofautoconf.h
isinclude/linux/autoconf.h
) - Also add any other macros files you are using.
- Click on Indexer
- Checkmark the Enable project specific setttings box.
- Uncheck Index source files not included in the build
- Clear out the Files to index up-front box.
- Click on Paths and Symbols on the left.
- Select the Includes tab and then select
GNU C
- Click
Add
... - Click
Workspace
... then select your kernel's include directory - Do another Add, Workspace and add
arch/architecture/include
, e.g.,arch/powerpc/include
- Click the
# Symbols
tab - Click
Add
... - Set the name to
__KERNEL__
- Set the value to
1
and click OK - Click the Source Location tab
- Click the twisty for your project.
- Select the Filter item and click Edit Filter...
- 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)
- Click OK and OK again to dismiss that dialog.
- Click OK on the Properties dialog.
- Click Finish on the C Project dialog.
- Right click on the project and select Index then select Rebuild
- It will take about 20 minutes or so to complete.
- Open your project setting, go to the
C/C++ build -> Behaviour (tab)
- Check the
Build (Incremental buil)
checkbox and add your module path to the textbox (in my caseM=drivers/servo/dynamixel
). - When you're module is ready and you want to compile kernel, repeat 41 and replace
M=..
withall
.
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