"can't send spi message" error when running Matrix Creator examples on resinOS

@jimsynz Here is my dockerfile that I was using when I got those build errors. I am using the raspberry-pi-debian.

Could the issue have something to do with using a 64 bit raspberry pi 4 instead of the raspberry pi 3?

FROM balenalib/raspberry-pi-debian-node:latest

RUN apt-get update && apt-get install -y curl wget build-essential libelf-dev awscli bc flex libssl-dev python bison
COPY . /usr/src/app
WORKDIR /usr/src/app

ENV VERSION '2.50.1+rev1.prod'
#ENV VERSION '2.29.0+rev1.prod'
RUN ./build.sh raspberrypi4-64 $VERSION matrixio-kernel-modules/src
#RUN ./build.sh --list
CMD ./run.sh


Well there goes that idea then.

Nothing particularly useful is coming up when I google the error message either.

I’ll ask the team here if anyone has any ideas and get back to you.

Cheers,
James.

Wait, more reading suggests that the error you’re getting may be because you’re trying to build a 64 bit kernel module in a 32 bit runtime. So, one option is setting the CROSS_COMPILE=aarch64-linux-gnu environment variable, and the other is basing your build environment around a 64 bit userspace.

FROM balenalib/raspberry-pi-debian-node:latest

RUN apt-get update && apt-get install -y curl wget build-essential libelf-dev awscli bc flex libssl-dev python bison
COPY . /usr/src/app
WORKDIR /usr/src/app

ENV CROSS_COMPILE aarch64-linux-gnu
ENV VERSION '2.50.1+rev1.prod'
#ENV VERSION '2.29.0+rev1.prod'
RUN ./build.sh raspberrypi4-64 $VERSION matrixio-kernel-modules/src
#RUN ./build.sh --list
CMD ./run.sh

I added that environment variable and these are the error messages

2020-06-01 22:01:31 (30.9 MB/s) - ‘kernel_modules_headers.tar.gz’ saved [11436144/11436144]
[main]     
[main]     make: Entering directory '/tmp/tmp.ZaKgB0TJGm'
[main]     arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
[main]     
[main]     arch/arm64/Makefile:40: LSE atomics not supported by binutils
[main]     
[main]     arch/arm64/Makefile:48: Detected assembler with broken .inst; disassembly will be unreliable
[main]     
[main]     ./scripts/gcc-version.sh: line 26: aarch64-linux-gnugcc: command not found
[main]     
[main]     ./scripts/gcc-version.sh: line 27: aarch64-linux-gnugcc: command not found
[main]     
[main]     make: aarch64-linux-gnugcc: Command not found
[main]     
[main]     make: aarch64-linux-gnugcc: Command not found
[main]     
[main]     make: aarch64-linux-gnugcc: Command not found
[main]     
[main]     make: aarch64-linux-gnugcc: Command not found
[main]     
[main]       CC [M]  /usr/src/app/matrixio-kernel-modules/src_raspberrypi4-64_2.50.1+rev1.prod/matrixio-core.o
[main]     /bin/sh: 1: aarch64-linux-gnugcc: not found
[main]     
[main]     make[1]: *** [scripts/Makefile.build:310: /usr/src/app/matrixio-kernel-modules/src_raspberrypi4-64_2.50.1+rev1.prod/matrixio-core.o] Error 127
[main]     
[main]     make: *** [Makefile:1519: _module_/usr/src/app/matrixio-kernel-modules/src_raspberrypi4-64_2.50.1+rev1.prod] Error 2
[main]     
[main]     make: Leaving directory '/tmp/tmp.ZaKgB0TJGm'
[main]     Removing intermediate container 69fb096a29f2
[main]     The command '/bin/sh -c ./build.sh raspberrypi4-64 $VERSION matrixio-kernel-modules/src' returned a non-zero code: 2
[Info]     Uploading images

I have a raspberry pi 3 I can test this setup on. Ill try compiling it on there but hopefully I can get the pi 4 working.

Ahh yes, I see. We’d need to put all the cross-compilation tools in the build image too. Taking a step back (and I may have missed this in the history of this thread) why aren’t you building it in a 64-bit container? (ie replace FROM balenalib/raspberry-pi-debian-node:latest with FROM balenalib/rraspberrypi4-64-debian-node:latest)

No reason, I wasnt aware the 64 bit containers existed. Ill try that now

Typo warning: I meant FROM balenalib/raspberrypi4-64-debian-node:latest. Also, if you rename your Dockerfile to Dockerfile.template you can just do FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:latest and it’ll use the right one for the app arch.

Alright, the kernel modules are built now using this Dockerfile.template file:

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:latest

RUN apt-get update && apt-get install -y curl wget build-essential libelf-dev awscli bc flex libssl-dev python bison
COPY . /usr/src/app
WORKDIR /usr/src/app

#ENV CROSS_COMPILE aarch64-linux-gnu
ENV VERSION '2.50.1+rev1.prod'
#ENV VERSION '2.29.0+rev1.prod'
RUN ./build.sh raspberrypi4-64 $VERSION matrixio-kernel-modules/src
#RUN ./build.sh --list
CMD ./run.sh

The next step is combining this with my existing repo and testing to see if the microphone is now working. I will post the outcome here

That’s great news. You should also be able to replace the instance of raspberrypi4-64 in your build.sh line with %%BALENA_MACHINE_NAME%% too, as it just does a simple search and replace. I look forward to hearing how it went.

Apparently the matrix creator packages dont support 64 bit arm.

When performing these steps to install it:

apt-get install lsb-release apt-transport-https && \
echo "deb https://apt.matrix.one/raspbian $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/matrixlabs.list && \
apt-get update

I get this error message:
N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'https://apt.matrix.one/raspbian buster InRelease' doesn't support architecture 'arm64'

So I think I need a 32 bit system running in either the container or a 32bit balenaOS installation. Im not sure which. Or if these packages are open source I think I will need to compile them myself.

I’ve started this thread over in the matrix forums for this issue: https://community.matrix.one/t/repository-https-apt-matrix-one-raspbian-buster-inrelease-doesn-t-support-architecture-arm64/2989

Hi,
Thanks for the update. You could certainly try a 32-bit container (on the x86_64 hardware with a 64-bit balenaOS foundation) first since that’s likely faster than re-imaging the device. An example can be found here.

Let us know how you make out.

John

jimsynz had pointed out earlier in the thread that compiling kernel modules for a 64 bit OS must be done in a 64 bit container. I clicked add device in the balenaCloud dashboard and there weren’t any options for downloading a 32bit OS for the raspberry pi. Do you have any 32 bit images?

Hi, if you want to use a 32 bit OS image then you need to create another app. There is a different device type for the 32 bits os image for the rpi3. Let us know if that works for you

I’ve switched to a 32 bit OS per floion’s suggestion, which allowed me to install the apt packages as normal. Also, I’ve done the steps @zvin recommended. The kernel modules build and the sound device shows up in alsa now, but none of the mic examples work now and I get errors when I try recording through arecord. Is it possible that I am missing some other kernel module related to sound?

These are the errors I am getting:
Using arecord:

root@5a54ff0:/usr/src/app# arecord -Dhw:2,0 test.wav
arecord: main:828: audio open error: Invalid argument

Using sox:

root@5a54ff0:/usr/src/app# rec test.wav 
rec WARN alsa: can't encode 0-bit Unknown or not applicable
rec FAIL formats: can't open input  `default': snd_pcm_open error: Invalid argument

Matrix-hal-examples mic demos:

root@5a54ff0:/usr/src/app/matrix-creator-hal/build/demos# ./direction_of_arrival_demo_direct 
INFO: [/dev/matrixio_regmap] was opened
Kernel Modules has been loaded. Use ALSA examples 
Segmentation fault (core dumped)
root@5a54ff0:/usr/src/app/matrix-creator-hal/build/demos# ./micarray_recorder_direct 
INFO: [/dev/matrixio_regmap] was opened
Kernel Modules has been loaded. Use ALSA implementation

In the demos, while its not longer saying can’t send spi message, its still not receiving any audio data.

My complete setup is here: https://github.com/airfield20/Matrix-Creator-BalenaOS/blob/32bit/app/Dockerfile.template

Did you try to modprobe for the matrix kernel modules? They are listed here:

In my run.sh file I have this:

#!/bin/bash

echo "Installing Kernel Modules for matrix mic"

echo "Installing matrixio-core"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-core.ko 
echo "Installing matrixio-uart"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-uart.ko 
echo "Installing matrixio-everloop"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-everloop.ko 
echo "Installing matrixio-codec"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-codec.ko 
echo "Installing matrixio-mic"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-mic.ko 
echo "Installing matrixio-playback"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-playback.ko 
echo "Installing matrixio-gpio"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-gpio.ko
echo "Installing matrixio-env"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-env.ko  
echo "Installing matrixio-imu"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-imu.ko 
echo "Installing matrixio-regmap"
insmod matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-regmap.ko

And at the bottom of my Dockerfile I have this:

CMD modprobe spi-bcm2835 && modprobe snd_bcm2835 && modprobe snd-dummy && modprobe snd_pcm && \
    modprobe snd_soc_core && modprobe industrialio && bash run.sh && bash start.sh

All the modules load correctly when I ran this script

Hi @airfield20 – thanks for the additional info. There are a couple of things I would suggest checking:

  • How are you checking that the modules are being loaded successfully? Are you able to share the output from that check?
  • I might suggest that you append lsmod at the end of your run.sh script; that way, it will be logged at container startup, and you’ll be able to check it on the device dashboard.
  • I’d also suggest changing the shebang at the top to #!/bin/bash -x so that it will log the commands it’s running; if one particular module is failing, you’ll be able to easily see what’s going on.
  • I might suggest also including the modprobe commands in that script as well, just to simplify things a bit.

Can you give that those things a try and let us know how it goes?

All the best,
Hugh

When I ssh into the running container and do lsmod I get this output:

root@5a54ff0:/usr/src/app# lsmod
Module                  Size  Used by
ip6t_REJECT            16384  1
nf_reject_ipv6         16384  1 ip6t_REJECT
ipt_REJECT             16384  1
nf_reject_ipv4         16384  1 ipt_REJECT
xt_state               16384  0
ip6table_filter        16384  1
matrixio_regmap        61440  0
matrixio_imu           16384  0
matrixio_env           16384  0
matrixio_gpio          16384  0
matrixio_playback      49152  0
matrixio_mic           16384  0
matrixio_codec         16384  2
matrixio_everloop      16384  0
matrixio_uart          16384  0
matrixio_core          16384  7 matrixio_everloop,matrixio_regmap,matrixio_playback,matrixio_imu,matrixio_mic,matrixio_uart,matrixio_env
industrialio           73728  2 matrixio_imu,matrixio_env
snd_soc_core          192512  3 matrixio_playback,matrixio_codec,matrixio_mic
snd_compress           20480  1 snd_soc_core
snd_pcm_dmaengine      16384  1 snd_soc_core
snd_dummy              24576  1
dummy                  16384  0
ip6_tables             24576  1 ip6table_filter
bnep                   20480  2
hci_uart               40960  1
btbcm                  16384  1 hci_uart
serdev                 20480  1 hci_uart
ipt_MASQUERADE         16384  3
bluetooth             397312  24 hci_uart,bnep,btbcm
nf_conntrack_netlink    40960  0
nfnetlink              16384  2 nf_conntrack_netlink
ecdh_generic           28672  1 bluetooth
br_netfilter           24576  0
xt_owner               16384  0
i2c_dev                20480  0
spidev                 20480  0
brcmfmac              319488  0
brcmutil               20480  1 brcmfmac
bcm2835_v4l2           49152  0
bcm2835_codec          36864  0
v4l2_mem2mem           24576  1 bcm2835_codec
bcm2835_mmal_vchiq     32768  2 bcm2835_codec,bcm2835_v4l2
sha256_generic         20480  0
v4l2_common            16384  1 bcm2835_v4l2
videobuf2_dma_contig    20480  1 bcm2835_codec
videobuf2_vmalloc      16384  1 bcm2835_v4l2
snd_bcm2835            24576  1
videobuf2_memops       16384  2 videobuf2_dma_contig,videobuf2_vmalloc
videobuf2_v4l2         24576  3 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem
cfg80211              630784  1 brcmfmac
lan78xx                49152  0
raspberrypi_hwmon      16384  0
videobuf2_common       45056  4 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem,videobuf2_v4l2
hwmon                  16384  1 raspberrypi_hwmon
snd_pcm                98304  6 matrixio_playback,snd_pcm_dmaengine,matrixio_mic,snd_bcm2835,snd_soc_core,snd_dummy
rfkill                 28672  6 bluetooth,cfg80211
snd_timer              32768  1 snd_pcm
videodev              200704  6 bcm2835_codec,v4l2_common,videobuf2_common,bcm2835_v4l2,v4l2_mem2mem,videobuf2_v4l2
snd                    73728  13 snd_compress,matrixio_playback,snd_timer,snd_bcm2835,snd_soc_core,snd_dummy,snd_pcm
media                  36864  3 bcm2835_codec,videodev,v4l2_mem2mem
i2c_bcm2835            16384  0
vc_sm_cma              36864  1 bcm2835_mmal_vchiq
spi_bcm2835            20480  0
uio_pdrv_genirq        16384  0
uio                    20480  1 uio_pdrv_genirq
fixed                  16384  0
sch_fq_codel           20480  4
root@5a54ff0:/usr/src/app# 

So it looks like those kernel modules are loading.

After adding the modprobe commands to my run.sh script, I get this on startup:

04.06.20 16:49:46 (-0400)  app  Installing Kernel Modules for matrix mic
04.06.20 16:49:46 (-0400)  app  Installing matrixio-core
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-core.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-uart
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-uart.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-everloop
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-everloop.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-codec
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-codec.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-mic
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-mic.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-playback
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-playback.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-gpio
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-gpio.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-env
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-env.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-imu
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-imu.ko: File exists
04.06.20 16:49:46 (-0400)  app  Installing matrixio-regmap
04.06.20 16:49:46 (-0400)  app  insmod: ERROR: could not insert module matrixio-kernel-modules/src_raspberrypi3_2.50.4+rev1.prod/matrixio-regmap.ko: File exists
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-regmap not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-everloop not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-gpio not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-imu not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-env not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-mic not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-playback not found in directory /lib/modules/4.19.75
04.06.20 16:49:46 (-0400)  app  modprobe: FATAL: Module matrixio-codec not found in directory /lib/modules/4.19.75

I’m not sure why it says file exists but doesn’t show up in modprobe, but lsmod still shows the modules loaded.