Use eclipse to develop a Linux driver

Source: Internet
Author: User

Eclipse has a powerful auto-completion function, which is handy when you browse code and edit code. Next I will introduce how to configure eclipse to help us open the Linux driver.

(Note that eclipse is called Eclipse IDE for C/C ++ developers. Instead of Eclipse IDE for Java developers after installing the CDT plug-in ).

1. Create a new C Project. This project is specially designed for drivers.

In the project explorer list on the right, right-click the project you just created and select Properties.
Select C/C ++ General> paths and symbols, select the des tab on the right, and select GNU C
The default include path of the compiler is displayed on the right.
/Path/of/kernel/DIR/include
/Path/of/kernel/DIR/ARCH/ARM/include

(If you are writing an x86 driver, use/path/of/kernel/DIR/ARCH/x86/include)

Select the symbols tab and click Export settings below to export the settings as an XML file.
Open the XML file and add
<Macro> <name >__ kernel __</Name> <value> 1 </value> </macro>

Then we need to add the macro definition in Autoconf. h to eclipse and perform the following steps:

  1. CD/path/of/kernel/DIR/include/Linux/
  2. Cat Autoconf. H | grep define | awk '{print "<macro> <Name>" $2 "</Name> <value>" $3 "</value> </macro>"} '> symbol. XML

Open symbol. xml and copy all the content to the end of the XML file </macro>.

Save the file and click Import settings to import the file. (If a parsing error is frequently prompted during import, the XML format is incorrect, make sure to check the error .)

Click OK to exit properties, right-click the project, and select index-> rebuild

However, there is still no way to compile automatically after configuration. You have to use your own makefile for compiling.

Select project properties.
Select C/C ++ build-> makefile generation, and set build direcotry as the makefile location. For example, $ {workspace_loc:/hellodriver }. The hellodriver is the root directory of my project.

Then manually write the MAKEFILE file. And place it in the root directory of the project.

Makefile example

pwd = $(shell pwd)KERNEL_SRC = /lib/modules/$(shell uname -r)/buildobj-m := hello.omodule-objs := hello.oall:        $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modulesclean:         rm -f *o *~ .*cmd *o *ko *~ .*cmd  hello.mod.c

Right-click the project and choose make target> create. In the displayed dialog box, enter target name. The name here is generally the name of the target in your own makefile. In my MAKEFILE file, I generally write all. You can also add clean in the same way.

In this case, you can use eclipse to compile your own driver and use make to automatically compile the driver.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.