Add new drivers to the Linux kernel and add them to the Menuconfig menu __linux

Source: Internet
Author: User
Tags one more line

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.

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.