红联Linux门户
Linux帮助

Linux kernel4.4.12添加make menuconfig可选项

发布时间:2016-12-27 10:40:33来源:linux网站作者:陈富林
Linux kernel 源码添加可选项
闲来无事,顺便记录一篇在Linux kernel make menuconfig 内添加一个可选项。
说不定将来就要用到这个东西呢。
linux kernel 的配置系统由以下三个部分组成。
Makefile:分布在Linux 内核源代码中,定义Linux kernel的编译规则。
配置文件:(kconfig) 给用户提供配置选择的功能。
配置工具包括配置命令解析器和配置用户界面。这些配置工具使用的都是脚本语言,如Perl。
最常使用的,我们一般使用make menuconfig 进行配置我们自己想要的。
这里面我们看到很多可以选择的选项,那么如果我们自己要增加自己的选项该怎么办呢。
网上有很多教程都是在drivers里面添加,我这里讲一种就是直接如果自己想建一个目录,然后添加里面的模块该怎么做。
 
过程:
我首先在顶层目录建一个目录chentest
cd $KERNEL_DIR
mkdir chentest
vim chentest.c
######################### 
chentest.c:
#include <linux/init.h> 
#include <linux/module.h>
int __init chen_init(void)
{
printk("start\n");  
return 0;   
}   
module_init(chen_init);
void __exit chen_exit(void) 
{   
printk("end\n");
}
module_exit(chen_exit);
MODULE_AUTHOR("chenfl");
MODULE_LICENSE("GPL");  
MODULE_DESCRIPTION("This is test modules"); 
MODULE_VERSION("V1.0");
######################### 
vim Makefile
Makefile:
obj-$(CONFIG_CHENTEST) += chen_test.o
#########################   
vim Kconfig
Kconfig:
menu "chentest"
config CHEN_TEST
tristate "This is a test"
default y
help
Say Y here if you have any input device (mouse, keyboard, tablet,
joystick, steering wheel ...) connected to your system and want
it to be available to applications. This includes standard PS/2
keyboard and mouse.
Say N here if you have a headless (no monitor, no keyboard) system.
More information is available: <file:Documentation/input/input.txt>
If unsure, say Y.
To compile this driver as a module, choose M here: the
module will be called input.
if CHEN_TEST
config CONFIG_CHENTEST
tristate "chentest"
help
Say Y here if you have memoryless force-feedback input device
such as Logitech WingMan Force 3D, ThrustMaster FireStorm Dual
Power 2, or similar. You will also need to enable hardware-specific
driver.
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called ff-memless.
endif
endmenu
 
好了大概到了这一步,准备工作差不多做好了,然后你的arm架构的话,需要在arm/arch/Kconfig
里面添加一句话。
大概在 这个位置添加:sourch "chentest/Kconfig"
2167 source "drivers/Kconfig"
2168 
2169 source "chentest/Kconfig"
2170 
2171 source "drivers/firmware/Kconfig
make ARCH=arm menuconfig  
看 Device Drivers 下面是不是多了个选项 chentest
 
本文永久更新地址:http://www.linuxdiyf.com/linux/27290.html