Search by Tags

Device Tree Overlays (Linux)

 

Article updated at 23 Oct 2020
Subscribe for this article updates

Introduction

Warning: Device Tree Overlays were introduced in BSP 5. Therefore this information does not apply to earlier BSDs.

Device Tree Overlays (DTO) provide a way to modify the overall device tree without re-compiling the complete device tree.

Overlays are small pieces, or fragments of a complete device tree, and can be added or removed as needed, often enabling/disabling hardware components in the system.

Because of this flexible nature, overlays provide an advantageous way of describing peripheral hardware that can be added or removed from the system. It is also useful for tweaking parameters of existing hardware before committing it to a complete device tree.

In a very brief description, the process of designing a Device Tree Overlay comprises three macro steps:

  1. Write a Device Tree Overlay (.dts) file.
  2. Compile the .dts file to generate a .dtbo file.
  3. Enable the overlay (using the .dtbo file)

This article will explore these steps for the Toradex BSP Layers and Reference Images for Yocto Project. For information specific to Torizon, see the Device Tree Overlays on Torizon article.

Pre-built Device Tree Overlays for Add-on Products Provided by Toradex

To reduce complexity and also to provide you with example implementations, Toradex provides pre-built Device Tree Overlays for the add-on products (Display and Touch Controllers) available in the webshop. Notice that only for the BSP 5.0 onwards, our reference images offer these Overlays as binaries (.dtbo files).

On a Toradex SoM with the Linux BSP > 5.0 installed, you can list these files from the boot partition. As an example, using the the terminal of a Apalis iMX8:

$ ls /media/mmcblk0p1/overlays
display-edt5.7_overlay.dtbo    display-lt161010_overlay.dtbo
display-edt7_overlay.dtbo      display-lt170410_overlay.dtbo

To enable these overlays, see the Deploying a Device Tree Overlay section.

If you want to obtain the source code of the Device Tree Overlays provided by Toradex for the products available on the webshop, see the Build U-Boot and Linux Kernel from Source Code article.

Writing a Custom DTO

The most recommended way to create a new overlay is to start looking at our evaluation boards' overlays and then adapt to your project's needs. You can find those overlays in the device-tree-overlays repository.

As with normal devicetrees, overlays must get explicitly written for the correct kernel version. This depends on the BSP you are using from Toradex and can be checked on Build U-Boot and Linux Kernel from Source Code article.

As an example, here is the devicetree overlay for parallel RGB on a Colibri iMX8X (colibri-imx8x_parallel-rgb_overlay.dts):

// Enable the parallel RGB interface on Colibri iMX8X

#include "dt-bindings/gpio/gpio.h"
#include "dt-bindings/pinctrl/pads-imx8qxp.h"
#include "dt-bindings/pwm/pwm.h"

/dts-v1/;
/plugin/;
/ {
    compatible = "toradex,colibri-imx8x";
};

&adma_pwm {
        status = "okay";
};

&backlight {
        brightness-levels = <0 45 63 88 119 158 203 255>;
        default-brightness-level = <4>;
        power-supply = <&reg_3v3>;
        pwms = <&adma_pwm 0 6666667 PWM_POLARITY_INVERTED>;
        status = "okay";
};

&display_lcdif {
        status = "okay";

        #address-cells = <1>;
        #size-cells = <0>;

        port@1 {
                reg = <1>;

                lcd_display_out: endpoint {
                        remote-endpoint = <&lcd_panel_in>;
                };
        };
};

&panel_dpi {
        status = "okay";

        port {
                lcd_panel_in: endpoint {
                        remote-endpoint = <&lcd_display_out>;
                };
        };
};

This overlay, if loaded, is directly appended to imx8qxp-colibri-eval-v3.dts. This devicetree, however, includes the "System on Module Level" devicetree imx8qxp-colibri.dtsi which contains most of the devicetree nodes.

If the overlay gets loaded, it gets integrated into the already loaded devicetree. To add or overwrite properties can be achieved with the ampersand character the same way as described in section Overwriting_properties.

Devicetree overlays have to be denoted with /plugin/; in the header.

For further reading on this topic, we refer to the kernel documentation: https://www.kernel.org/doc/html/latest/devicetree/overlay-notes.html?highlight=overlays

Building a DTO

To build the Device Tree Overlay, see the Build U-Boot and Linux Kernel from Source Code article.

Deploying a Device Tree Overlay

To deploy a overlay on a Toradex SoM with the Linux BSP > 5.0 installed, copy the .dtbo file to the overlays/ directory in the boot partition and edit the overlays.txt file. This file contains a space separated list of overlays. For example:

$ cat /media/mmcblk0p1/overlays.txt 
fdt_overlays=overlays/verdin-imx8mm_lt8912_overlay.dtbo overlays/verdin-imx8mm_ov5640_overlay.dtbo

After changing the overlays, reboot the board. Do not power-cycle because the edits done may not sync to the file system.

Note: In case you find yourself with a non-working kernel after applying the overlay, see the Removing a conflicting DTO section

If you want to obtain the source code of the Device Tree Overlays provided by Toradex for the products available on the webshop, see the [Build U-Boot and Linux Kernel from Source Code] article.

Removing a conflicting DTO

In case you find yourself with a non-working kernel (normally, stuck at the "Loading kernel..." message), you can delete your custom overlays easily directly from your PC. You would need to set up a USB-OTG connection with your PC and run the UMS functionality of U-Boot by simply stopping the autoboot at U-boot and running the following commands:

ums 0 mmc 0

After this command, you should see a BOOT partition show up on your PC. Delete the conflicting .dtbo and the corresponding item in the overlays.txt file.

Note: Check your carrier board datasheet what ports and jumper configurations work with USB-OTG. In Toradex Carrier Boards, it requires using the correct port or a small jumper removal (like Ixora's JP2).