闲来无事,顺便记录一篇在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