Device Trees and Overlays
A device tree describes the hardware on a board so that the kernel can bind drivers to it. A Modalix board boots a base device tree and then applies overlays for what you attach to it, such as a camera. This page shows how to select an overlay that ships with the release, how to write your own, and how to check the result.
This page is written from the kernel and U-Boot sources for platform release 2.1.3 and from the other guides on this site. The steps have not been run on a board as they are written here.
How the Board Loads a Device Tree
- U-Boot loads the base device tree for the board from the active boot
directory,
boot-0orboot-1. - U-Boot applies each overlay named in its
dtbosvariable, in the order listed. - The kernel starts with the merged device tree.
A device tree describes hardware. It does not add a driver. The driver for a device must already be in the kernel or be installed as a module. See the device tree usage model in the kernel documentation.
Select an Overlay from the Release
The release has overlays for the supported cameras and for PCIe and flash configurations. Their sources are in the overlays directory of the kernel tree.
-
List the overlays on the board:
sima@modalix:~$ ls /boot/boot-*/*.dtbo -
Interrupt U-Boot, set
dtbosto the overlay, and boot:sima$ setenv dtbos modalix-som-waveshare-ARDU-IMX477-1CAM.dtbosima$ saveenvsima$ boot
To apply more than one overlay, separate the names with spaces. For camera overlays, see Supported MIPI Cameras.
Write Your Own Overlay
Write an overlay when you attach a device that the release has no overlay for.
This example adds an I2C GPIO expander at address 0x27 on I2C bus 0:
/dts-v1/;
/plugin/;
&i2c00 {
status = "okay";
clock-frequency = <400000>;
#address-cells = <1>;
#size-cells = <0>;
pcf8574: gpio@27 {
compatible = "nxp,pcf8574";
reg = <0x27>;
gpio-controller;
#gpio-cells = <2>;
};
};
&i2c00selects the node to change by its label in the base device tree.status = "okay"enables a node that the base device tree leaves disabled.#address-cellsand#size-cellsrepeat the values of the bus in the base device tree. Without them,dtcwarns that it cannot checkreg.- The child node is the device.
compatibleselects the driver, andregis the address of the device on the bus.
Before you write the overlay, check that the kernel has the driver. The
compatible string must belong to a driver that
simaai_modalix_defconfig
enables, or to a module that you build and install.
For a larger example, read a camera overlay from the kernel tree, such as
modalix-som-waveshare-ARDU-IMX477-1CAM.dtso.
It adds a clock for the sensor, sets up the I2C bus and the power-down pin,
enables the CSI interface and its video nodes, and connects the sensor to the
CSI interface over two data lanes.
Build and Install the Overlay
-
Compile the overlay source to a
.dtbofile, as described in Build the BSP from Source. -
Copy the
.dtbofile to the active boot directory of the board. -
Add the file to
dtbosin U-Boot, after the overlays that are already listed:sima$ env set dtbos $dtbos my-device.dtbosima$ saveenvsima$ boot
Check the Result
Check in this order. Each step depends on the one before it.
-
The overlay was applied. Find the new node in the device tree that the kernel is using:
root@modalix:~# find /proc/device-tree -name "gpio@27" -
The driver bound to the device. Look for the driver in the kernel log:
root@modalix:~# dmesg | grep -i pcf857x -
The device works. Use the tool for that kind of device. For the GPIO expander,
gpiodetectlists a new chip. For a camera,cam -llists the camera.
If It Does Not Work
| What you see | Likely cause | What to check |
|---|---|---|
The node is not in /proc/device-tree | U-Boot did not apply the overlay | printenv dtbos in U-Boot, the file in the active boot directory, and errors on the U-Boot console |
| The node is there, but no driver binds | The kernel has no driver for the compatible string | The kernel configuration, and dmesg |
| The driver reports an error | The bus or the address is wrong, or a clock, supply, reset, or GPIO is missing | dmesg, and i2cdetect for an I2C device |
| Another device stops working | Two overlays change the same node or the same pin | Apply one overlay at a time |
Next Steps
- Build the BSP from Source: build the kernel, the device trees, and overlays.
- Low-Speed I/O: pin mapping and device-tree nodes for GPIO, UART, I2C, and SPI.
- Modalix DevKit Interface Support: which interfaces the release device tree enables.