) Add a new driver to the android kernel and add it to the menuconfig menu. [Practice Notes]

Source: Internet
Author: User

Add a new driver for the android kernel and provide menuconfig options

Add a driver for Linux kernel 2.6.25 of Android.

1. Add the hello directory under the drives directory, containingHello. c kconfig makefile

Hello. C content:
# Include <Linux/init. h>
# Include <Linux/module. h>
Module_license ("dual BSD/GPL ");

Static int hello_init (void)
{
Printk (kern_alert "Hello, world \ n ");
Return 0;
}
Static void hello_exit (void)
{

Printk (kern_alert "Goodbye, cruel world \ n ");
}

Module_init (hello_init );
Module_exit (hello_exit );

Kconfig content:
Config hello
Tristate "Hello driver added by Dong"
Default n
Help
Test for adding driver to menuconfig.

Makefile content:
OBJ-$ (config_hello) + = Hello. o


2. Add the preceding kconfig file and the preceding two configurations to make the hello item appear in the configuration menu.
Add
Source "Drivers/Hello/kconfig"

Add between drivers/kconfig menu "device drivers" endmenu
Source "Drivers/Hello/kconfig"

(I wonder why ARCH/ARM/kconfig contains a copy of the kconfig content in drivers,
The experiment proves that only the modified content in drivers/kconfig is invalid .)

3.Modify the MAKEFILE file in the DRIVERS directory and add the following lines,
OBJ-$ (config_hello) + = Hello/
When config_hello is Y or m, the system can find the makefile of the Hello driver.

Make menuconfig in the linux-2.6.25 directory, and select the hello driver added by Dong item under the device drivers menu, such as m, as the module. Save the configuration and execute the make command. Then you can see CC [m] Drivers/Hello/hello. O log. Hello is generated in the hello directory. O hello. ko files.

Process:
For example, when making menuconfig, set Hello driver added by Dong to M (that is, compile as a module rather than compile it into the Linux kernel)
In. config, a row of config_hello = m is added.
In this way, the obj-$ (config_hello) + = Hello/in drivers/makefile becomes obj-M + = Hello/
When you execute the make command, you will go to the hello directory to find the makefile, And the makefile content obj-$ (config_hello) + = hello. O is changed to OBJ-M + = hello. o, So hello. C is compiled into a module.

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.