Add a new driver to the android kernel and add it to the menuconfig menu.

Source: Internet
Author: User

For android
Add a new driver to the kernel and provide menuconfig
Option

For android
Linux
Kernel 2.6.25
Add a driver.

1.
In drives
Add Hello under the Directory
Directory containing hello. 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.

The above kconfig
File and the above two configurations to make the hello
Items appear in the configuration menu.

In ARCH/ARM/kconfig menu "device drivers" endmenu

Between

Source "Drivers/Hello/kconfig"


In Drivers/kconfig menu "device drivers" endmenu

Between

Source "Drivers/Hello/kconfig
"


(I do not know why ARCH/ARM/kconfig
It actually contains drivers.
In kconfig
A copy of the content,

Experiments show that only drivers/kconfig
The modified content is invalid .)

3.
Modify drivers
Makefile under the Directory
File, add the following lines,

OBJ-$ (config_hello) + = Hello/



When config_hello
Y
Or m
So that the system can find hello
Driver makefile
.

Linux-2.6.25
Make menuconfig in the directory
In Device Drivers
Select Hello driver added by Dong under the menu
Such as m
As a module
. Save the configuration and execute make
Command to see CC [m] Drivers/Hello. o
Log
Hello
The directory generates hello. O hello. Ko
.

Process:


Assume that
When configuring Hello driver added by Dong
M
(Compile as a module, rather than compile it into Linux
Kernel)


Then. config

Will have one more row
Config_hello = m


In this way, drivers/makefile
OBJ-$ (config_hello) + = Hello/
It becomes
OBJ-M + = Hello/


Execute make
When the command is executed
Directory to find makefile
, Makefile
Content obj-$ (config_hello) + = Hello. o
Changed to OBJ-M + = Hello. o
So hello. c
It is compiled into a module.

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.