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.