我不明白如何使用linux内核模块spi-loopback-test
。
这个模块是从spi-loop - back-test.c编译的,并且仍然在维护。
它是为SPI回归测试目的而创建的(参见初始提交日志),但是在网络上没有任何文档或说明。
-
我能够编译和加载模块,但加载时什么也没发生。
dmesg
中没有消息,物理SPI总线上没有活动。lsmod
表示模块已加载 -
似乎模块的
spi_loopback_test_probe
函数从未被调用。
我想我少了一些"胶水"。(DT覆盖??),为模块分配一个物理SPI端口。
如何分配一个SPI端口到这个模块?
我是否应该创建DT覆盖以在现有的spi0外围节点下添加spi-loopback-test
驱动程序节点? -
另外,我注意到模块参数
compatible
可以在加载前改变。
这里可以设置什么值?
我的目标系统是Raspberry Pi 4B(但我想这个问题适用于所有linux系统)。
任何帮助/指针是感激的!
谢谢
好了,我终于找到一种运行spi-loopback-test
模块的方法。这里的技巧是使用anyspi
设备树覆盖,以避免对spidev
模块的依赖。
我从这次提交中得到了灵感。
- 首先,必须重新编译内核以包含测试特性"spi-loopback-test"。
我遵循这个指南,从Ubuntu VM交叉编译。 - 在编译前通过"menuconfig"启用SPI环回模块:
CONFIG_SPI_DEBUG=y
和CONFIG_SPI_LOOPBACK_TEST=m
- 将内核映像及其设备树加载到目标系统(RPi4)。
- 在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
参数?