Linux kernel4.4.12 添加make menuconfig 可選項


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM