Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 18790  / 12 Months ago, sun, may 28, 2023, 4:29:54

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!
" );
return 0;
}

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

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 by all'. 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?


More From » drivers

 Answers
5

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.


[#43261] Sunday, May 28, 2023, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
termetalli

Total Points: 326
Total Questions: 127
Total Answers: 110

Location: Sao Tome and Principe
Member since Sat, Sep 12, 2020
4 Years ago
termetalli questions
Sat, Apr 30, 22, 17:54, 2 Years ago
Mon, Dec 6, 21, 05:24, 2 Years ago
Thu, Jun 30, 22, 00:32, 2 Years ago
Mon, Dec 19, 22, 00:15, 1 Year ago
;