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

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

问题描述

我已经开发了Linux设备驱动程序.到目前为止,我正在Ubuntu 12.04上使用交叉编译器将其编译为arm,然后将其插入到我的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. 在驱动程序(位于Linux源代码中)的驱动程序内部为您的驱动程序创建一个目录,例如my_drvr,并将您的驱动程序(my_driver.c)文件放入此目录中.看起来像 /linux_source_code/drivers/my_drvr/my_driver.c

  1. Create a directory like my_drvr inside drivers(which is in the Linux source code) for your driver and put your driver (my_driver.c) file inside this directory. It will looks like /linux_source_code/drivers/my_drvr/my_driver.c

在驱动程序目录中(使用vi任何编辑器)并在此put obj-$(CONFIG_MY_DRIVER) += my_driver.o中创建一个Makefile 并保存此文件.这将显示为/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_source_code/drivers/Makefile的Linux源驱动程序MakefileKconfig文件中添加MakefileKconfig文件 和/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天全站免登陆