博客
关于我
在linux内核里面新添加一个驱动模块
阅读量:640 次
发布时间:2019-03-14

本文共 1506 字,大约阅读时间需要 5 分钟。

构建测试模块:hello

1. 在linux-3.4/drivers/下新建目录hello

linux-3.4/drivers/目录中执行以下命令:

cd linux-3.4/drivers/mkdir hello

1.2 在hello/下新建hello.c Makefile Kconfig三个文件

hello.c
// 所有模块都需要的头文件#include 
#include
#include
#define MODULE_LICENSE "GPL"#define MODULE_AUTHOR "baoli"#define MODULE_DESCRIPTION "hello world module"static int __init hello_init(void) { printk(KERN_WARNING "hello world.\n"); return 0;}static void __exit hello_exit(void) { printk(KERN_WARNING "hello exit!\n");}module_init(hello_init);module_exit(hello_exit);
Makefile
# 如果需要在用户空间编译为模块(m)# 如果需要直接编译成内核模块(y)# 如果不需要编译(n)# 例如:make menuconfig ARCH=arm
Kconfig
menu "HELLO TEST Driver"comment "HELLO TEST Driver Config"config HELLOtristate "hello module test"default mhelp    这是hello测试驱动endmenu

1.3 修改上一级目录的Kconfig和Makefile

进入linux-3.4/drivers/目录,对MakefileKconfig进行修改:

  • 修改Makefile:
  • obj-$(CONFIG_HELLO) += hello/
    1. 修改Kconfig:
    2. source "drivers/hello/Kconfig"

      (注意:某些内核版本可能需要在arch/arm/Kconfig中添加相同内容)


      2. 编译

      完成以上设置后,进入菜单配置并进行编译:

      2.1 选择编译选项

      make menuconfig ARCH=arm

      进入“Device Drivers”选项,您可以看到新增的“HELLO TEST Driver”选项。进入该选项后,您可以选择以下编译选项:

      • 编译成模块
      • 编译进内核
      • 不编译

      2.2 编译结果

      • 编译成模块
        :编译过程会输出以下内容:

        LD drivers/hello/built-in.oCC [M] drivers/hello/hello.oCC drivers/hello/hello.mod.oLD [M] drivers/hello/hello.ko
      • 编译进内核
        :编译过程会输出以下内容:

        CC drivers/hello/hello.oLD drivers/hello/built-in.o

      编译完成后,drivers/hello/目录中会生成hello.ohello.ko文件。同时,/linux-3.4/output/lib/modules/3.4.39/目录中也会包含生成的hello.ko文件。


      希望以上内容能为您的内核开发提供帮助!如果需要进一步优化或者有其他问题,请随时联系!

    转载地址:http://mpflz.baihongyu.com/

    你可能感兴趣的文章
    NoSQL数据库概述
    查看>>
    Notadd —— 基于 nest.js 的微服务开发框架
    查看>>
    NOTE:rfc5766-turn-server
    查看>>
    Notepad ++ 安装与配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
    查看>>
    Notepad++在线和离线安装JSON格式化插件
    查看>>
    notepad++最详情汇总
    查看>>
    notepad++正则表达式替换字符串详解
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notes on Paul Irish's "Things I learned from the jQuery source" casts
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘html-webpack-plugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>