If You want to use the SPI periphery of the beagleV Fire from a user-space application, just like on a microcontroller, You need to modify the device tree: You must add the spidev node to the spi periphery so linux adds the /dev/spidev character device driver on boot. The device tree is located in an image file in /boot/firmware/beaglev_fire.itb This file is a “Flattened Image Tree (FIT) Format”. While booting, U-Boot is loading this file. This image contains the kernel image and the device tree blob. To add spidev node You must:
- Extract the kernel image from the FIT image
- Extract the device tree blob from the FIT image
- Decompile the device tree blob to get the device tree source
- Add the spidev node to the device tree source
- Compile the device tree source
- Add the kernel image and device tree blob to a new FIT image
- Replace the FIT image
All can be done on the beagleV Fire board using the UART terminal.
beagle@BeagleV:~$ cp /boot/firmware/beaglev_fire.itb /boot/firmware/beaglev_fire.itb_bkp
beagle@BeagleV:~$ cp /boot/firmware/beaglev_fire.itb ~/
beagle@BeagleV:~$ cd
Let’s see what's inside the FIT image:
beagle@BeagleV:~$ dumpimage -l beaglev_fire.itb
beagle@BeagleV:~$ dumpimage -T flat_dt -p 0 beaglev_fire.itb -o Image
beagle@BeagleV:~$ dumpimage -T flat_dt -p 1 beaglev_fire.itb -o beaglev_fire.dtb
beagle@BeagleV:~$ dtc -I dtb -O dts -o beaglev_fire.dts beaglev_fire.dtb
beagle@BeagleV:~$ nano beaglev_fire.dts
Press Alt-C to enable line numbers add these line after line 389:
spidev@0{
compatible = "rohm,dh2228fv";
reg = <0>;
spi-max-frequency = <4000000>;
};
Ctrl+O to save Ctrl+X to exit
beagle@BeagleV:~$ dtc -I dts -O dtb -o beaglev_fire.dtb beaglev_fire.dts
beagle@BeagleV:~$ nano beaglev_fire.its
Paste this:
/dts-v1/;
/ {
description = "U-Boot fitImage for the BeagleV-Fire";
#address-cells = <1>;
images {
kernel {
description = "Linux kernel";
data = /incbin/("./Image");
type = "kernel";
arch = "riscv";
os = "linux";
compression = "gzip";
load = <0x80200000>;
entry = <0x80200000>;
hash {
algo = "sha256";
};
};
base_fdt {
description = "Flattened Device Tree Blob";
data = /incbin/("./beaglev_fire.dtb");
type = "flat_dt";
arch = "riscv";
compression = "none";
load = <0x8a000000>;
hash {
algo = "sha256";
};
};
};
configurations {
default = "kernel_dtb";
kernel_dtb {
description = "1 Linux kernel, FDT blob";
kernel = "kernel";
fdt = "base_fdt";
};
base_dtb {
description = "Base FDT blob for BeagleV-Fire board";
kernel = "unavailable";
fdt = "base_fdt";
};
};
};
Ctrl+O to save Ctrl+X to exit
beagle@BeagleV:~$ mkimage -f beaglev_fire.its beaglev_fire.itb
beagle@BeagleV:~$ sudo cp beaglev_fire.itb /boot/firmware/
beagle@BeagleV:~$ sudo reboot
After successful boot, you should see the spidev under /dev/spidev0.0
This is very helpful, I've been trying to figure out how to do this for an mpfs-disco-kit which appears to be a bit different. Could you include the beagle_fire.dts before and after you modified it, so I can see how I need to modify the mpfs-disco-kit dts file? Thanks for posting this!