Discussion:
how to enable spi?
(too old to reply)
Sebastian Kuzminsky
2022-10-25 16:10:01 UTC
Permalink
I'm using the 2022-08-08 bookworm rpi4 image from
<https://raspi.debian.net/tested-images/>, it's got linux-image-arm64
5.18.14-1 and raspi-firmware 1.20220331+ds-2.

It's working great, except I can't use the SPI devices.

SPI works on same hardware when running Raspbian's Buster image, after
running "dtparam spi=on" (or adding "dtparam=spi=on" to the firmware
config.txt file).

Raspbian Buster's dtparam program is not available on Debian Bookworm.

On Raspbian it comes from the libraspberrypi-bin deb, which is made from
the raspberrypi/firwmware git repo on github (the same repo that
supplies all the dtb files in /boot). dtparam and the other programs
there are provided in binary form (for armhf), not source :-(

Does anyone have any advise for me on how to enable SPI on Debian?

(In case it's not obvious, I'm a noob at dealing with device tree stuff.)
--
Sebastian Kuzminsky
Sebastian Kuzminsky
2022-10-30 17:10:01 UTC
Permalink
Post by Sebastian Kuzminsky
I'm using the 2022-08-08 bookworm rpi4 image from
<https://raspi.debian.net/tested-images/>, it's got linux-image-arm64
5.18.14-1 and raspi-firmware 1.20220331+ds-2.
It's working great, except I can't use the SPI devices.
SPI works on same hardware when running Raspbian's Buster image, after
running "dtparam spi=on" (or adding "dtparam=spi=on" to the firmware
config.txt file).
Raspbian Buster's dtparam program is not available on Debian Bookworm.
On Raspbian it comes from the libraspberrypi-bin deb, which is made from
the raspberrypi/firwmware git repo on github (the same repo that
supplies all the dtb files in /boot).  dtparam and the other programs
there are provided in binary form (for armhf), not source :-(
I don't have this working yet but I've made a little bit of progress.

The Raspbian Buster armhf binaries can be made to run on Debian Bookworm
arm64 with a little bit of coaxing, but they rely on kernel features
that are not in Bookworm's arm64 kernel, so that's a bit of a dead end.

I then tried editing the dtb directly:

I "decompiled" the dtb `/boot/firmware/bcm2711-rpi-4-b.dtb` into an
editable dts with `dtc -I dtb -O dts $DTB > $DTS`.

I edited the dts to change the spi0 "status" field from "disabled" to "ok".

I "compiled" the edited dts with `dtc -I dts -O dtb $DTS > $DTB`.

I then replaced the old dtb with the new one and rebooted.

The spi port seems to be present/enabled now: dmesg includes
"spi-bcm2835 fe204000.spi: no tx-dma configuration found - not using dma
mode", and /sys/bus/platform/drivers/spi-bcm2835/fe204000.spi shows up.

But something is still wrong, there are still no /dev/spi* device files
like i get with Raspbian Buster.

So I'm closer, but I'm still missing something. The quest goes on!
--
Sebastian Kuzminsky
Diederik de Haas
2022-10-30 18:40:01 UTC
Permalink
Post by Sebastian Kuzminsky
The Raspbian Buster armhf binaries can be made to run on Debian Bookworm
arm64 with a little bit of coaxing, but they rely on kernel features
that are not in Bookworm's arm64 kernel
Do you know which kernel features?
I can then create a MR to get those enabled in Debian's Bookworm kernel.
Georg Gast
2022-10-30 19:30:01 UTC
Permalink
Am Sun, 30 Oct 2022 19:32:17 +0100
Post by Diederik de Haas
Post by Sebastian Kuzminsky
The Raspbian Buster armhf binaries can be made to run on Debian
Bookworm arm64 with a little bit of coaxing, but they rely on
kernel features that are not in Bookworm's arm64 kernel
Do you know which kernel features?
I can then create a MR to get those enabled in Debian's Bookworm kernel.
I got this working some time ago. I used a mainline kernel with PREEMPT
RT and a CAN driver over SPI.

https://forums.raspberrypi.com/viewtopic.php?t=329789
and
https://forums.raspberrypi.com/viewtopic.php?t=338859

I use uboot to apply the overlay. It is important that the DTCs are
compiled with the "-@" option. I compile the kernel on my amd64 machine
with

time ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- DTC_FLAGS="-@" make
deb-pkg -j16

With u-boot i use the extlinux boot configuration with a custom patch
that got sadly not accepted (or maybe igored) from u-boot upstream. With
that patch i can apply the overlays on raspi. The patch is based on
u-boot 2021.07. set the distro_bootcmd to your partition. This can be
tricky if you are not expierenced with u-boot. In my case it looks like

setenv distro_bootcmd="sysboot mmc 0:3 any 0x02400000
/boot/extlinux/extlinux.conf"
saveenv
reset

over the uart at the bootup.

0x02400000 is explained by the other vars. As far as i remember it is
the load address for the extlinux.conf file.

mmc 0:3 = first mmc thired partition. My layout is:
1: firmware (u-boot and the basic fdts also the u-boot environment)
2: swap
3: root

The default debian kernel works but the device tree is not compiled
with "-@". So you cant apply any overlays.

ovmerge, i downloaded from the raspi Site
https://github.com/raspberrypi/utils/blob/master/ovmerge/ovmerge

Hope that helps :)

Best regards
Georg
gene heskett
2022-10-30 21:30:01 UTC
Permalink
Post by Sebastian Kuzminsky
Post by Sebastian Kuzminsky
I'm using the 2022-08-08 bookworm rpi4 image from
<https://raspi.debian.net/tested-images/>, it's got linux-image-arm64
5.18.14-1 and raspi-firmware 1.20220331+ds-2.
It's working great, except I can't use the SPI devices.
SPI works on same hardware when running Raspbian's Buster image,
after running "dtparam spi=on" (or adding "dtparam=spi=on" to the
firmware config.txt file).
Raspbian Buster's dtparam program is not available on Debian Bookworm.
On Raspbian it comes from the libraspberrypi-bin deb, which is made
from the raspberrypi/firwmware git repo on github (the same repo that
supplies all the dtb files in /boot).  dtparam and the other programs
there are provided in binary form (for armhf), not source :-(
I don't have this working yet but I've made a little bit of progress.
The Raspbian Buster armhf binaries can be made to run on Debian
Bookworm arm64 with a little bit of coaxing, but they rely on kernel
features that are not in Bookworm's arm64 kernel, so that's a bit of a
dead end.
I "decompiled" the dtb `/boot/firmware/bcm2711-rpi-4-b.dtb` into an
editable dts with `dtc -I dtb -O dts $DTB > $DTS`.
I edited the dts to change the spi0 "status" field from "disabled" to "ok".
I "compiled" the edited dts with `dtc -I dts -O dtb $DTS > $DTB`.
I then replaced the old dtb with the new one and rebooted.
The spi port seems to be present/enabled now: dmesg includes
"spi-bcm2835 fe204000.spi: no tx-dma configuration found - not using
dma mode", and /sys/bus/platform/drivers/spi-bcm2835/fe204000.spi
shows up.
But something is still wrong, there are still no /dev/spi* device
files like i get with Raspbian Buster.
So I'm closer, but I'm still missing something.  The quest goes on!
Bored, I tried my make-debs script on the rpi4b running buster rasppios
today, but it bailed out with can't find
Documentation.de error.

Is there anything I can do?

Thanks Sebastian Kuzminsky. Take care & stay well.

Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/>
Loading...