Linux 内核/驱动程序开发新手

发布于 2024-08-29 12:40:29 字数 580 浏览 14 评论 0原文

最近,我开始开发运行Linux的嵌入式设备的驱动程序。

到目前为止,我只阅读有关 Linux 内部结构的内容。
由于没有驱动程序开发经验,我发现迈出第一步有点困难。

  • 我已经下载了内核源代码(v2.6.32)。
  • 我已阅读(略读)Linux 设备驱动程序 (3e)
  • 我在 StackOverflow 上阅读了一些相关帖子。
  • 我知道linux有一个“整体”方法。
  • 我已经构建了内核(包括 menuconfig 等中的现有驱动程序)
  • 我知道 kconfig 和 makefile 文件的基础知识,所以这应该不是问题。

有人可以描述一下结构(即内部链接)
内核源代码中的各个目录。

换句话说,给定一个源代码文件,
相关代码会引用哪些其他文件

(“#include”提供了部分想法)

有人可以帮助我获得更好的想法吗?
任何帮助将不胜感激,

谢谢。

Recently, i began developing a driver of an embedded device running linux.

Until now i have only read about linux internals.
Having no prior experience in driver devlopment, i am finding it a tad difficult to land my first step.

  • I have downloaded the kernel source-code (v2.6.32).
  • I have read (skimped) Linux Device Drivers (3e)
  • I read a few related posts here on StackOverflow.
  • I understand that linux has a "monolithic" approach.
  • I have built kernel (included existing driver in menuconfig etc.)
  • I know the basics of kconfig and makefile files so that should not be a problem.

Can someone describe the structure (i.e. the inter-links)
of the various directories in the kernel-source code.

In other words, given a source-code file,
which other files would it refer to for related code

(The "#include"-s provide a partial idea)

Could someone please help me in getting a better idea?
Any help will be greatly appreciated

Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角迷惘 2024-09-05 12:40:29

给定一个 C 文件,您必须查看它调用的函数和它使用的数据结构,而不是担心特定的文件。

开发自己的设备驱动程序有两种基本途径:

  • 采用与您的驱动程序相似的驱动程序;删除不适用于您的设备的代码,然后填写适合您的设备的新代码。
  • 从设备驱动程序的最基本部分开始,然后一次添加一些部分,直到您的设备开始运行。

当您完成此过程时,组成驱动程序的文件将更有意义。请务必考虑每个文件属于什么内容,但在某种程度上,在文件之间划分驱动程序更像是一门艺术,而不是一门科学。较小的驱动程序通常只适合一两个文件。

一点设计也可能是好的。考虑您的设备做什么,以及您的驱动程序需要做什么。基于此,您应该能够确定设备驱动程序需要具有哪些功能。

我还相信 Linux 设备驱动程序,第三版 可能会帮助您开始驱动程序开发。

Linux 文件本身包括基于其用途、所在层以及访问调用堆栈的哪一层的文件。大图真实地告诉了每个文件与下一个文件的关系。

Given a C file, you have to look at the functions it calls and data structures it uses, rather than worrying about particular files.

There are two basic routes to developing your own device driver:

  • Take a driver that is similar to yours; strip out the code that isn't applicable to your device, and fill in new code for your device.
  • Start with the very basic pieces of a device driver, and add pieces a little at a time until your device begins to function.

The files that compose your driver will make more sense as you complete this process. Do consider what belongs in each file, but to some extent, dividing a driver among files is more an art than a science. Smaller drivers often fit into just one or two files.

A bit of design may also be good. Consider what you device does, and what your driver will need to do. Based on that, you should be able to map out what functions a device driver will need to have.

I also believe Linux Device Drivers, Third Edition may help you get on your way to driver development.

Linux files themselves include files based on what they do, what layer they are in, and what layer they access of the call stack. The Big Picture truly informs how each file is related to the next.

一萌ing 2024-09-05 12:40:29

我必须修复一次内核驱动程序。我最大的技巧(如果你使用 vim)是使用 ctags 进行设置,这样每次你看到一个你不理解的函数时,你就可以使用 ctrl-] 跳转内核源代码。

I had to fix a kernel driver once. My biggest tip (if you use vim) is to set it up with ctags so you can jump around the kernel source with ctrl-] every time you see a function you don't understand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文