在 linux 源代码中添加新的驱动程序代码 [英] Adding new driver code to linux source code

查看:18
本文介绍了在 linux 源代码中添加新的驱动程序代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 Linux 设备驱动程序.到目前为止,我正在使用 arm 的交叉编译器在 Ubuntu 12.04 上编译它,然后将它嵌入我的 arm Linux 映像中.但是我想学习如何在Linux源代码中添加它,并通过arm Linux的配置给出添加/删除选项,以便我可以用Linux源代码编译来编译它?

I have developed a Linux device driver. As of now I am compiling it on Ubuntu 12.04 with cross-compiler for arm and then insmoding it in my arm Linux image. But I want to learn how I can add it in Linux source code and give and option to add/remove through configuration of arm Linux, so that I can compile it with Linux source code compilation?

有什么想法吗?

推荐答案

要在 arm 架构中交叉编译您自己的驱动程序,您必须遵循以下提到的一些步骤.

To cross compile your own driver in the arm architecture you have to follow some steps as mentioned below.

  1. 在驱动程序中创建一个类似 my_drvr 的目录(在 Linux 源代码中)为您的驱动程序,并将您的驱动程序 (my_driver.c) 文件放在此目录中.它看起来像/linux_source_code/drivers/my_drvr/my_driver.c

在您的驱动程序目录中创建一个 Makefile(使用 vi 任何编辑器)并在此放入 obj-$(CONFIG_MY_DRIVER) += my_driver.o并保存此文件.这将显示为 /linux_source_code/drivers/my_drvr/Makefile

Create one Makefile inside your driver directory (using vi any editor) and inside this put obj-$(CONFIG_MY_DRIVER) += my_driver.o and save this file. This will appears like /linux_source_code/drivers/my_drvr/Makefile

在您的驱动程序目录中创建一个 Kconfig 文件(使用 vi 任何编辑器)并在此放置

Create one Kconfig file inside your driver directory (using vi any editor) and inside this put

config MY_DRIVER
tristate "my driver" //gives your driver description like vendor name etc.
depends on ARM
default y if ARM
help
  my driver module.

  • 保存这个文件,它看起来像/linux_source_code/drivers/my_drvr/Kconfig

    在Linux源驱动MakefileKconfig文件中同时添加MakefileKconfig文件位于 /linux_source_code/drivers/Makefile/linux_source_code/drivers/Kconfig

    Add both Makefile and Kconfig file in the Linux source drivers Makefile and Kconfig file which are at /linux_source_code/drivers/Makefile and /linux_source_code/drivers/Kconfig

    在 Makefile 的最后一行添加以下内容

    In the Makefile add below in last line

     obj-y    += my_drvr/ 

     obj-$(CONFIG_MY_DRIVER)   += my_drvr/

  • 在 Kconfig 文件的最后一行添加以下内容

  • In Kconfig file add below in last line

    source "drivers/my_drvr/Kconfig"

  • 最后必须将 Kconfig 文件添加到体系结构特定的配置文件中,该文件将位于 kernel_source/arch/arm/configs/--defconfig 在下面的这个添加中最后一行

  • Finally have to add Kconfig file into architecture specific config file which will be at kernel_source/arch/arm/configs/--defconfig in this add below line in the last

    CONFIG_MY_DRIVER=y

  • 注意:- 最后一步将根据您的架构而有所不同,因此您要小心.现在您可以使用 make 命令编译您的驱动程序.(例如:sun7i_defconfig)

    Note:- Last step will differ according to your architecture, so that you have take care. Now you can compile your driver by using make command. (eg: sun7i_defconfig)

    这篇关于在 linux 源代码中添加新的驱动程序代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆