Linux kernel4.4.12 添加make menuconfig 可选项

本文介绍如何在Linux内核源码中添加自定义模块并实现配置选项。通过创建目录、编写模块代码、配置Makefile及Kconfig文件,最终在内核配置工具makemenuconfig中显示新增选项。

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

转载于:https://www.cnblogs.com/chenfulin5/p/6220753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值