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.