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

时间:2022-10-03 02:09:34

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

最近,我开始开发运行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.

到目前为止,我只阅读了关于linux内部的内容。没有先前的驾驶员开发经验,我发现我的第一步很难落地。

  • I have downloaded the kernel source-code (v2.6.32).
  • 我已经下载了内核源代码(v2.6.32)。
  • I have read (skimped) Linux Device Drivers (3e)
  • 我读过(吝啬)Linux设备驱动程序(3e)
  • I read a few related posts here on *.
  • 我在*上阅读了一些相关的帖子。
  • I understand that linux has a "monolithic" approach.
  • 我知道linux有一种“单片”的方法。
  • I have built kernel (included existing driver in menuconfig etc.)
  • 我已经构建了内核(在menuconfig中包含了现有的驱动程序等)
  • I know the basics of kconfig and makefile files so that should not be a problem.
  • 我知道kconfig和makefile文件的基础知识,所以这不应该是一个问题。

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)

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

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

有人可以帮助我获得一个更好的主意吗?任何帮助将不胜感激

Thank You.

谢谢。

2 个解决方案

#1


18  

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

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

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设备驱动程序,第三版可以帮助您开始进行驱动程序开发。

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.

Linux文件本身包括基于它们的作用,它们所在的层以及它们访问调用堆栈的层的文件。 Big Picture真实地告知了每个文件与下一个文件的关系。

#2


7  

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.

我不得不修改一次内核驱动程序。我最大的提示(如果你使用vim)是用ctags设置它,这样你每次看到一个你不理解的函数时都可以用ctrl-跳转内核源代码。

#1


18  

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

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

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设备驱动程序,第三版可以帮助您开始进行驱动程序开发。

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.

Linux文件本身包括基于它们的作用,它们所在的层以及它们访问调用堆栈的层的文件。 Big Picture真实地告知了每个文件与下一个文件的关系。

#2


7  

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.

我不得不修改一次内核驱动程序。我最大的提示(如果你使用vim)是用ctags设置它,这样你每次看到一个你不理解的函数时都可以用ctrl-跳转内核源代码。