【问题标题】:How to use spi-loopback-test linux kernel module?如何使用 spi-loopback-test linux 内核模块?
【发布时间】:2021-04-29 13:27:57
【问题描述】:

我不明白如何使用linux内核模块spi-loopback-test

这个模块是从spi-loopback-test.c编译的,是still maintained
它是为 SPI 回归测试目的而创建的(请参阅 initial commit log),但网络上没有任何文档或说明。

  1. 我能够编译和加载模块,但加载时没有任何反应。
    dmesg 中没有消息,物理 SPI 总线上没有活动。 lsmod 表示模块已加载。

  2. 似乎模块的spi_loopback_test_probe function 从未被调用过。
    我想我在设备树中缺少一些“胶水”(DT 覆盖??),用于为模块分配物理 SPI 端口。
    如何给这个模块分配一个SPI端口?
    我是否应该创建一个 DT 覆盖以在现有的 spi0 peripheral node 下添加一个 spi-loopback-test 驱动程序节点?

  3. 另外,我注意到模块 parameter compatible 可以在加载前更改。
    这里可以设置什么值?

我的目标系统是 Raspberry Pi 4B(但我猜这个问题适用于所有 linux 系统)。

感谢任何帮助/指针!
谢谢

【问题讨论】:

    标签: linux module linux-kernel raspberry-pi spi


    【解决方案1】:

    好的,我终于找到了一种方法来运行spi-loopback-test 模块。
    这里的诀窍是使用anyspi Device-Tree overlay,以避免依赖spidev module
    我的灵感来自this commit

    1. 首先,必须重新编译内核以包含测试功能“spi-loopback-test”。
      我关注了this guide,从 Ubuntu 虚拟机进行交叉编译。
    2. 编译前通过“menuconfig”启用SPI环回模块:CONFIG_SPI_DEBUG=yCONFIG_SPI_LOOPBACK_TEST=m
    3. 将内核映像及其设备树加载到目标系统 (RPi4)。
    4. 在 RPi4 上运行以下命令:
    $ sudo dmesg -n 8
    
    $ lsmod | grep spi
    
    $ sudo dtoverlay anyspi spi0-1 dev="linux,spi-loopback-test" speed=125000000
    
    $ lsmod | grep spi
    spi_loopback_test      28672  0
    spidev                 20480  0
    spi_bcm2835            24576  0
    
    $ dmesg | grep spi > spi-loopback-test.log
    
    $ $ head spi-loopback-test.log -n 15
    [   48.170758] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/spi@7e204000/spidev@1/status
    [   48.170785] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/spi@7e204000/status
    [   48.182921] spi-bcm2835 fe204000.spi: registered master spi0
    [   48.183056] spi spi0.1: setup: forcing CS_HIGH (use_gpio_descriptors)
    [   48.183075] spi spi0.1: setup mode 0, cs_high, 8 bits/w, 125000000 Hz max --> 0
    [   48.183187] spi-bcm2835 fe204000.spi: registered child spi0.1
    [   48.183217] spi spi0.0: setup: forcing CS_HIGH (use_gpio_descriptors)
    [   48.183232] spi spi0.0: setup mode 0, cs_high, 8 bits/w, 125000000 Hz max --> 0
    [   48.183327] spi-bcm2835 fe204000.spi: registered child spi0.0
    [   48.269732] spi-loopback-test spi0.1: Executing spi-loopback-tests
    [   48.269946] spi-loopback-test spi0.1: Running test tx/rx-transfer - start of page
    [   48.270204] spi-loopback-test spi0.1:   with iteration values: len = 0, tx_off = 0, rx_off = 1
    [   48.270431] spi-loopback-test spi0.1:   with iteration values: len = 0, tx_off = 0, rx_off = 2
    [   48.270657] spi-loopback-test spi0.1:   with iteration values: len = 0, tx_off = 0, rx_off = 3
    [   48.270883] spi-loopback-test spi0.1:   with iteration values: len = 0, tx_off = 1, rx_off = 0
    
    $ tail spi-loopback-test.log
    [   51.878516] spi-loopback-test spi0.1:   with iteration values: len = 1024, tx_off = 0, rx_off = 0
    [   51.881159] spi-loopback-test spi0.1:   with iteration values: len = 1031, tx_off = 0, rx_off = 0
    [   51.883826] spi-loopback-test spi0.1:   with iteration values: len = 4093, tx_off = 0, rx_off = 0
    [   51.886892] spi-loopback-test spi0.1:   with iteration values: len = 4096, tx_off = 0, rx_off = 0
    [   51.889950] spi-loopback-test spi0.1:   with iteration values: len = 4099, tx_off = 0, rx_off = 0
    [   51.893862] spi-loopback-test spi0.1:   with iteration values: len = 65536, tx_off = 0, rx_off = 0
    [   51.905280] spi-loopback-test spi0.1:   with iteration values: len = 65537, tx_off = 0, rx_off = 0
    [   51.916708] spi-loopback-test spi0.1:   with iteration values: len = 131071, tx_off = 0, rx_off = 0
    [   51.937417] spi-loopback-test spi0.1:   with iteration values: len = 131072, tx_off = 0, rx_off = 0
    [   52.057851] spi-loopback-test spi0.1: Finished spi-loopback-tests with return: 0
    

    所以看起来 SPI 测试成功了,正如预期的那样。现在我知道如何将内核模块连接到硬件了。
    我希望这对其他人也有用。

    但是,我想知道是否有更简单的解决方案来加载和运行这个内核模块??
    是否可以不依赖anyspi DT覆盖,只设置spi-loopback-mode模块的compatible参数?

    【讨论】:

    • 为什么需要模块?用户空间程序还不够elixir.bootlin.com/linux/latest/source/tools/spi/spidev_test.c
    • 您最终找到了上一个问题的答案吗?我目前正在经历相同的学习过程,到目前为止,您的帖子在阐明 spi_bcm2835、spidev 和使用 spi 的模块如何与设备树交互方面最有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2013-12-17
    • 2012-02-22
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多