1. Add the Hello directory under the drives 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 Kconfig file above, plus the following two configurations, allows the hello item to appear in the configuration menu.
Add between Arch/arm/kconfig menu "Device Drivers" Endmenu
SOURCE "Drivers/hello/kconfig"
Add between Drivers/kconfig menu "Device Drivers" Endmenu
SOURCE "Drivers/hello/kconfig"
(Somehow arch/arm/kconfig contains a copy of the Kconfig content in drivers,
The experimental results show that only the modified content in Drivers/kconfig is invalid. )
3. Modify the Makefile file in the drivers directory, add the following line,
obj-$ (Config_hello) + + hello/
When Config_hello is Y or M, the system can find the Hello-driven makefile.
Under the linux-2.6.25 directory, make menuconfig, select the Hello Driver added by Dong item, such as M, under the device Drivers menu as module. Then save the configuration, execute make command, you can see the CC [M] drivers/hello/hello.o log, the Hello directory generated hello.o hello.ko files.
Process:
If you configure the Hello Driver added by Dong to M (that is, as a module, rather than into the Linux kernel) in make Menuconfig
, there will be one more line in. config Config_ HELLO = M
This way, obj-$ (config_hello) + = hello/in Drivers/makefile becomes obj-m +=hello/
So when you execute the make command, Will go into the HELLO directory to find Makefile,makefile content obj-$ (Config_hello) + + hello.o into obj-m +=hello.o, so hello.c was compiled into a module.