First Steps with Device Tree Overlays
Introduction
In this article, we will guide you through the first steps of working with Device Tree Overlays. You will learn how to chose a ready-to-use Device Tree Overlay or write/customize one to your specific need.
Prerequisites
- If you aim to manually compile and deploy, set up the build environment described at Build Device Tree Overlays From Source Code.
- If you aim to use Yocto to compile and deploy, set up the Yocto Project build environment Build a Reference Image with Yocto Project/OpenEmbedded.
- If you aim to use Torizon OS, download and set TorizonCore Builder. Refer to TorizonCore Builder Tool - Customizing Torizon OS Images
Get Started with Device Tree Overlays
Device tree overlays are binary files that contain modifications to the device tree structure. Instead of modifying the original device tree source (DTS) file directly, overlays allow you to apply changes dynamically without recompiling or rebooting the system. An overlay file (*.dtbo) is generated by compiling a device tree overlay source (DTO) file. The DTO file describes the modifications to be applied, including device additions, deletions, property changes, and even complete device tree substitutions. These modifications can be applied to specific sections of the device tree or the entire tree itself.
Toradex offer a series of articles to aiming to provide a wide understanding of device trees and device tree overlays on its computer on modules:
You can refer to the kernel.org archives to find oficial documentation about the topic: Device Tree Overlay Notes - kernel.org
Use a Provided Device Tree Overlay
You can chose a readily-available Device Tree Overlay if it covers the hardware configuration you need.
- Refer to Device Tree Overlays on Toradex System on Modules to check if an existing pre-compiled device tree overlay provided by Toradex already fulfil your requirements.
They are already deployed to Torizon OS and Reference Images, you would need just to enable/disable the desired ones. If the Device Tree Overlay is provided compiled, you can jump straight into the deploy part of the process. If not, check how to compile it before.
However, in some cases, you will have to write your Device Tree Overlay or modify a base Device Tree Overlay.
If this is the case, identify and understand the customizations needed and follow the next sections.
The provided Device Tree Overlays are also available as .dts
(source file) so you can use one as starting point when writing your own DTOs.
You can check how to get the sources in the Toradex Resources section.
Identify and Understand Customizations
Before writing your overlays, it's crucial to identify the specific customization requirements for your system. Determine the dynamic modifications you wish to make to the hardware configuration. This could involve enabling or disabling devices, adjusting pin assignments, configuring peripherals, or modifying device properties on-the-fly. By clearly understanding your customization needs, you can effectively leverage device tree overlays to achieve the desired hardware configuration changes without rebuilding or rebooting the system.
Device Tree Binding Documentation
To understand the structure and syntax of the DTS file, it is crucial to refer to the device tree binding documentation specific to your hardware platform. The device tree binding documentation provides detailed information on the available device tree nodes, properties, and their valid values.
Toradex Resources
If you want to obtain the source code of the Device Tree Overlays provided by Toradex for the products available in the webshop, see the Build U-Boot and Linux Kernel from Source Code article.
Toradex offer a series of articles to aiming to provide a wide understanding of pinmuxing and pin assignments on its computer on modules:
- Customizing Nodes and Properties
- Pinmuxing Guide Overview.
- Pinmuxing with i.MX 6/6ULL Based Modules.
- Pinmuxing with i.MX 7 Based Modules.
- Pinmuxing with i.MX 8/8X Based Modules.
- Pinmuxing with i.MX 8M Mini/Plus Based Modules.
Write a Device Tree Overlay
To create a device tree overlay, you will need the original device tree source (DTS) file and the device tree overlay source (DTO) file. The DTS file represents the base device tree, while the DTO file describes the modifications to be applied.
Clone the Toradex Device Tree Overlays repository (branch
toradex_5.15-2.1.x-imx
for BSP 6) and find an overlay for you to base yourself. The most recommended way to create a new overlay is to start looking at similar overlays and then adapt to your project's needs.$ git clone -b <branch> git://git.toradex.com/device-tree-overlays.git
$ cd overlaysCreate your custom
.dts
on your work directory.$ touch custom-overlay.dts
Copy and paste this template for an overlay to change the default pin muxing, or base yourself on the already existing ones from the
device-trees/overlays/
repository. The content of thecustom-overlay.dts
should be simillar to the following template.View template overlay
/dts-v1/;
/plugin/; //Indicates a Device Tree Overlay
// Header file with pin definitions
#include <soc-pinfunc.h>
/ {
compatible = "toradex,apalis-imx8"; // Set hardware compatibility
};
&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl-originally-in-device-tree>, <&pinctrl_my_pins>; // Pin group available in userspace i.e. as GPIO
name-of-som {
pinctrl_my_pins: my_muxgrp {
fsl,pins = <
PIN_NAME_PIN_MUX PAD_CTRL // PINS
>;
};
};
};
&node {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_my_pins>; // Pin group used in genericPeripheral
status = "okay";
};
Build a Device Tree Overlay
Manual Build
To build the Device Tree Overlay manually, see the Build Device Tree Overlays from Source Code article.
Build with Torizon OS
For evaluation, early development or troubleshooting, it can be convenient to use the dto command
of TorizonCore Builder.
For later development stages and when preparing the production image, you can leverage the build command
, which provides an easy Device Tree Customization process.
Under the device-tree
customization section of the build.yaml
file, you should add an overlays
section, including the .dts
files of the DTOs you want to add, as follows:
customization:
device-tree:
include-dirs:
- device-trees/include/
overlays:
add:
- device-trees/overlays/<your-custom-device-tree-overlay.dts
This will enable the build command
to compile and deploy the DTOs to your customized image.
Deploy a Device Tree Overlay
Testing and Development: Manual Deployment
To deploy a custom overlay on a Toradex SoM:
Copy the
.dtbo
file to theoverlays/
directory in the boot partition.Add the file name (
<custom-overlay>.dtbo
) to theoverlays.txt
file. This file contains a space separated list of overlays. For example:$ cat /boot/overlays.txt
fdt_overlays=verdin-imx8mm_lt8912_overlay.dtbo verdin-imx8mm_ov5640_overlay.dtbo custom-overlay.dtboAfter changing the
overlays.txt
, run the commandsync
and reboot the board. Do not power-cycle because the edits done may not sync to the file system.$ sync
$ reboot
Production: Yocto Project
If you decide to deploy the overlays, two steps are required and explained below:
- Add your overlays, making sure they are compiled and deployed to the image.
- Have the overlays listed in
overlays.txt
, making sure they are enabled.
Raw NAND modules don't support device tree overlays
Add Your Overlays to the Yocto Project: There are currently two recipes that handle device tree overlays:
- Upstream-based images: meta-toradex-bsp-common/recipes-kernel/linux/device-tree-overlays-mainline_git.bb.
- Downstream-based images: meta-toradex-nxp/recipes-kernel/linux/device-tree-overlays_git.bb.
You can, for instance, write your own bbappends to add your device tree overlays repository.
Enable Your Overlays in the Yocto Project: The class meta-toradex-bsp-common/classes/image_type_tezi.bbclass is responsible for adding overlays that will be applied during boot time. It uses the variable
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT
that is set by default in our machine configuration files, eithermachine.conf
ormachine.inc
. You can find them usinggrep
inside thelayers
directory:$ cd ~/oe-core/layers
$ grep -nre "TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT"Then you need to either append to or override the variable. One possibility is to use a
<machine>-extra.conf
file. You can find an example on Custom meta layers, recipes and images in Yocto Project (hello-world examples).
Device Tree Overlays on Torizon
The build and deployment on Torizon OS can be done in a single step, as explained in the Deploy section. For more Torizon-related information, refer to Device Tree Overlays on Torizon.
Next Steps
The next step is create and edit your device tree overlay in a case oriented way.
For this, follow the steps at How to Write Device Tree Overlays.