Linux kernel4.4.12 添加make menuconfig 可選項

Linux kernel 源碼添加可選項


閒來無事,順便記錄一篇在Linux kernel make menuconfig 內添加一個可選項。
說不定未來就要用到這個東西呢。

linux kernel 的配置系統由如下三個部分組成。
Makefile: 分佈在Linux 內核源代碼中,定義Linux kernel的編譯規則。
配置文件:(kconfig) 給用戶提供配置選擇的功能。
配置工具:包括配置命令解析器和配置用戶界面。這些配置工具使用的都是腳本語言,如Perl。

最常使用的,咱們通常使用make menuconfig 進行配置咱們本身想要的。
這裏面咱們看到不少能夠選擇的選項,那麼若是咱們本身要增長本身的選項該怎麼辦呢。
網上有不少教程都是在drivers裏面添加,我這裏講一種就是直接若是本身想建一個目錄,而後添加里面的模塊該怎麼作。


過程:

我首先在頂層目錄建一個目錄chentestlinux

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
裏面添加一句話。git

大概在 這個位置添加: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
相關文章
相關標籤/搜索