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 查看是否添加成功

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

  • 相关阅读:
    [书目20160620]自媒体时代,我们该如何做营销
    [转]Oracle Form 触发器执行顺序
    [转]在ASP.NET开发中容易忽略的2个小问题 Cookie乱码存取异常 和 iframe弹框的login跳转
    [转]菜鸟程序员之Asp.net MVC Session过期异常的处理
    [转]Asp.net MVC使用Filter解除Session, Cookie等依赖
    [转]异步、多线程、任务、并行编程之一:选择合适的多线程模型
    [转]Membership 到 .NET4.5 之 ASP.NET Identity
    [转]前后端分离开发模式下后端质量的保证 —— 单元测试
    [转]Asp.net MVC 利用PartialView 构造自定义菜单
    [转]Membership三步曲之入门篇
  • 原文地址:https://www.cnblogs.com/xingboy/p/14917320.html
Copyright © 2011-2022 走看看