zoukankan      html  css  js  c++  java
  • Linux 把自己编写的内核驱动,或者IC厂家提供的内核驱动,添加到 menuconfig 可选项 【转】

    参考链接:https://www.cnblogs.com/chenfulin5/p/6220753.html

    linux kernel 的配置系统由以下三个部分组成。

      Makefile: 分布在Linux 内核源代码中,定义Linux kernel的编译规则。

      配置文件:(kconfig) 给用户提供配置选择的功能。

      配置工具:包括配置命令解析器和配置用户界面。这些配置工具使用的都是脚本语言,如Perl。

      最常使用的,我们一般使用make menuconfig 进行配置我们自己想要的。 这里面我们看到很多可以选择的选项,那么如果我们自己要增加自己的选项该怎么办呢。 网上有很多教程都是在drivers里面添加,我这里讲一种就是直接如果自己想建一个目录,然后添加里面的模块该怎么做。

    1.首先在顶层目录建一个目录chentest,然后再建立个c 文件

    mkdir chentest
    vim chentest.c

    2.编写c文件

    chentest.c:
    #include <linux/init.h>                                                         
    #include <linux/module.h>                                                       
                                                                                                                                                                
    int __init chen_init(void)                                                      
    {                                                                               
        printk("start
    ");                                                          
        return 0;                                                                   
    }                                                                               
    module_init(chen_init);                                                         
                                                                                    
    void __exit chen_exit(void)                                                     
    {                                                                               
        printk("end
    ");                                                            
    }                                                                               
                                                                                    
    module_exit(chen_exit);                            
    
    #MODULE_ALIAS ( 模块为人所知的另一个名字 )
    # MODULE_DEVICE_TABLE ( 来告知用户空间, 模块支持那些设备 )
                                                                                    
    MODULE_AUTHOR("chenfl");    #声明谁编写了模块                                                    
    MODULE_LICENSE("GPL");      #内核认识的特定许可有, “GPL”( 适用 GNU 通用公共许可的任何版本 ), “GPL v2”( 只适用 GPL 版本 2 )                                                       
    MODULE_DESCRIPTION("This is test modules");  #模块功能声明                                   
    MODULE_VERSION("V1.0");    #代码修订版本号

    3.新建一个Makefile文件

    vim Makefile

      Makefile文件添加内容如下:

    obj-$(CONFIG_CHENTEST) += chen_test.o  #这里声明了链接需要添加的驱动,链接到Konfig里的接口名为 CHENTEST

    4.新建一个Kconfig

    vim Kconfig

      Kconfig添加内容如下:

    Kconfig:    
    menu "chentest"
    
    config CHEN_TEST  #默认直接在menuconfig显示的内容
        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.
    
    ifCHEN_TEST  #当menuconfig选Y的时候显示的内容
    
    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(64位的话是arm64)/arch/ 里的Kconfig文件添加下面内容·

    sourch  "chentest/Kconfig" #在其他类似该格式的地方添加

    5.最后执行 make ARCH=arm(64位编译器就arm64) menuconfig 查看是否添加成功

    注意:如果要添加一些厂家的驱动的话,也可以用这种方法直接添加,就只是把厂家提供的驱动当作自己编写的驱动即可

  • 相关阅读:
    random模块
    time时间模块
    module模块和包的介绍,模块的执行以及name
    函数闭包带参数装饰器
    装饰器框架,实现一个装饰器,函数闭包加上参数,解压序列,函数闭包为函数加上认证功能,装饰器闭包模拟session
    装饰器基本理论,高阶函数使用,函数闭包
    生成器函数的好处及总结,send()第三种触发生成器函数方法,生产者消费者模型
    迭代器协议和for循环工作机制;三元运算和列表解析及生成器表达式;生成器函数
    文件处理b模式与文件操作的其它方法
    文件处理
  • 原文地址:https://www.cnblogs.com/xingboy/p/14917320.html
Copyright © 2011-2022 走看看