研究设备驱动源文件?

Study device driver source files?

我想研究在 raspberry pi(raspian)、beaglebone(debian) 或我的笔记本电脑 (ubuntu) 上安装和加载的一些设备驱动程序的源文件.

我的目标是通过研究一些实际可用的驱动程序的源文件来学习如何正确实现我自己的模块。

我对与实际硬件(USB、I2C、SPI、UART 等)通信的驱动程序特别感兴趣。

谁能告诉我如何找到这些资源?它们是否在某些特定文件夹中可用,例如 /usr/src/**** 或我是否必须从特定内核版本下载所有内核源文件?

非常感谢所有建议、意见和建议。

p.s 我已经阅读 "Linux Kernel Development 3rd edition" 但请告诉我是否 你知道关于这个主题的任何其他 free/open-source 本书。

此致 亨里克

没关系,我在

下找到了源文件
~/linux/drivers/

示例:

nano ~/linux/drivers/spi/spi-bitbang.c

抱歉,给您带来的不便!

我使用了几种不同的方法来查看与内核相关的源代码,而且我相信还有一些其他的好方法。你会发现方法大同小异

  1. 前往 kernel.org 并下载您选择的内核。您将在 /<path to your downloaded kernel>/drivers 下找到与驱动程序相关的源代码。例如,我已将内核 4.5.5 下载并提取到 /usr/src/linux-4.5.5,并通过 /usr/src/linux-4.5.5/drivers.

  2. 访问我的驱动程序的源代码
  3. 使用 linux 交叉引用网站。就个人而言,我使用 free-electrons 上托管的那个。这些网站非常适合自由文本或标识符搜索。

  4. 浏览 Linus Torvalds 在 github 上托管的 linux repo

Linux 源目录及说明:

  • arch/- arch 子目录包含所有架构特定的内核代码。

    Example :
    1. 'arch/arm/' will have your board related configuration file.
        like 'arch/arm/mach-omap/' will have omap specific source code.
    2. 'arch/arm/config' Generates a new kernel configuration with the
        default answer being used for all options. The default values
        are taken from a file located in the arch/$ARCH/defconfig
        file,where $ARCH refers to the specific architecture for which
        the kernel is being built.
    3. arch/arm/boot have kernel zImage, dtb image after compilation.
    
  • 块/- 此文件夹包含块设备驱动程序的代码。块设备是以块为单位接受和发送数据的设备。数据块是数据块而不是连续的流。

  • 加密/- 此文件夹包含许多加密算法的源代码。

     example, “sha1_generic.c” is the file that contains the code for
               the sha1 encryption algorithm.
    
  • 文档/- 它有文本格式的内核相关信息。

  • drivers/ - 系统的所有设备驱动程序都位于此目录中。它们进一步细分为设备驱动程序类。

     Example,
     1. drivers/video/backlight/ has blacklight driver source which
        will control display brightness.
     2. drivers/video/display/ has display driver source. 
     3. drivers/input/ has input driver source code. like touch,
        keyboard and mouse driver.
     4. drivers/char/ has charter driver source code.
     5. drivers/i2c/ has i2c subsystem and driver source code.
     6. drivers/pci/ has pci subsytem and driver related source code.
     7. drivers/bluetooth  has Bluetooth driver file.
     8. drivers/power has power and battery driver.
    
  • 固件/- 固件文件夹包含允许计算机读取和理解来自设备的信号的代码。例如,网络摄像头管理自己的硬件,但计算机必须理解网络摄像头向计算机发送的信号。

  • fs/- 所有的文件系统代码。这进一步细分为目录,每个支持的文件系统一个,例如 vfat 和 ext2。

  • 内核/- 此文件夹中的代码控制内核本身。例如,如果调试器需要跟踪问题,内核将使用源自此文件夹中源文件的代码来通知调试器内核执行的所有操作。这里还有用于跟踪时间的代码。在内核文件夹中有一个名为 "power" 的目录。此文件夹中的一些代码提供了计算机重启、关机和挂起的功能。

  • 净/- 网 内核的网络代码。 库 该目录包含内核的库代码。体系结构特定的库代码可以在 arch/*/lib/ 中找到。 剧本 此目录包含配置内核时使用的脚本(例如 awk 和 tk 脚本)。

  • lib/- 该目录包含内核的库代码。体系结构特定的库代码可以在 arch/*/lib/.

  • 中找到
  • 脚本/- 此目录包含配置内核时使用的脚本(例如 awk 和 tk 脚本)。

  • mm/- 该目录包含所有内存管理代码。体系结构特定的内存管理代码位于 arch/*/mm/ 中,例如 arch/i386/mm/fault.c.

  • ipc/- 此目录包含内核进程间通信代码。

  • **init/ -**init 文件夹中有处理内核启动 (INITiation) 的代码。 main.c 文件是内核的核心。这是连接所有其他文件的主要源代码文件。

  • sound/ - 这是所有声卡驱动程序所在的位置。

还有一些目录证书、加密、安全、包含、virt 和 usr 等....