Previously, the Linux driver was written in plain text. Recently, I found that I could use eclipse for development. So after a long time, I finally succeeded in compiling and felt pretty good. The following uses the hello World driver as an example to describe how to use eclipse to develop the arm-Linux driver.
I will not talk about the installation of eclipse and CDT. After eclipse and CDT are installed, run eclipse, file-> New-> project and select C Project in C/C ++, for example:
Click Next, enter the project name "hello", and set the project path as follows:
Click next and then click Next. Fill in the Cross-compiler prefix and cross-compiler path, as shown below:
Click Finish. The project structure is shown in. It automatically contains several header file paths related to the Cross Compiler:
Right-click Project-> propertise, select paths and symbols in C/C ++ General, select gnu c in the program des tab, and click Add on the right, add the header file directory (which must have been compiled by the cross compiler in advance), as shown below:
Select Add to all deployments, and click OK. On the symbols tab, add a symbols with the name of _ KERNEL __and value of 1, as shown below:
Select Add to all deployments and click OK. Click OK. A dialog box is displayed, as shown in the following figure. Select Yes.
Compile the hello. c file:
1 # Include <Linux/module. h> /* Needed by all modules */ 2 # Include <Linux/kernel. h> /* Needed for kern_info */ 3 # Include <Linux/init. h> /* Needed for the macros */ 4 5 6 Static Int _ Init hello_init ( Void ) 7 { 8 Printk (kern_info " Hello, world \ n " ); 9 Return 0 ; 10 } 11 12 Static Void _ Exit hello_exit ( Void ) 13 { 14 Printk (kern_info" Goodbye, world \ n " ); 15 } 16 17 Module_init (hello_init ); 18 Module_exit (hello_exit ); 19 Module_license ( " GPL " );
Compile the MAKEFILE file:
1OBJ-M + =Hello. o2 3Pwd =$ (Shell PWD)4 5 ALL:6Make-C/gt2440/kernel/Linux-2.6.34.12M =$ (PWD) Modules7 8 Clean:9Rm-f *. O *. Ko
After completion, such:
Finally, right-click the project-> properties-> C/C ++ build, and deselect generate makefiles automatically in the builder settings tab, as shown below:
Click OK. Right-click Project> build project to compile the project. The successful compilation result is as follows:
The Hello. Ko file has been generated, and the console output is the same as the compiled output in the terminal.
Appendix:
The method to import the original C Project is file-> Import, and select existing projects into workspace under General as follows:
Click Next, Click Browse, select the root directory of the project to be imported, and click Finish.