NVIDIA Jetson - Device Tree Overlay

From RidgeRun Developer Wiki
Revision as of 04:33, 24 February 2022 by Mleiva (talk | contribs) (→‎References)


Introduction to Device Tree Overlay

This wiki is intended to be used as a reference if you want to create a Device Tree (DT) overlay for a custom hardware module. DT overlays are used to configure various hardware devices that may be attached to the system.

NVIDIA Jetson kernels use a device tree to describe the hardware present in the NVIDIA Jetson board. You can use Jetson‑IO tool to support a custom hardware module by creating a device tree overlay for the hardware module to allow optional external hardware to be described and configured.

Create a device tree overlay

Jetson‑IO

NVIDIA provides the Jetson Expansion Header Tool (also known as Jetson‑IO). It is a Python script that runs on a Jetson developer kit and lets you apply a DT overlay configuration through a graphic user interface. Jetson‑IO finds the overlay file and allows you to apply it.

You can use Jetson‑IO to perform 2 tasks:

  1. Configure header pins manually: displays the expansion header configuration screen, which lets you specify which functions to enable on the header. The application creates the DT overlay and it is applied.
  2. Configure for compatible hardware: displays the compatible hardware screen, which lets you select from a list of configurations for hardware modules that can be attached to the header. You can use a pre-created DT overlay for certain hardware or create your custom DT overlay and select it from the list.

This guide uses the second option to apply a custom DT overlay.

Device tree overlay structure

A device tree overlay for a hardware module must define the property:

  • overlay-name: specifies a name for the hardware module.
  • jetson-header-name: specifies the expansion header to which the hardware module is associated; it must specify one of the values described in the table jetson-header-name property values.
  • compatible: indicates which combination of Jetson module and carrier board the overlay supports; t must specify one or more of the values described in the table compatible property values.
  • fragment: a DT overlay comprises a number of fragments, each of them indicates child nodes and the target.
  • target: phandle target of the overlay.
  • target-path: target path of the overlay.

Creating a Simple Device Tree Overlay

To create a simple device tree overlay to add a new custom property for Jetson Xavier NX Developer Kit and attach it to the 40‑pin expansion header, create a file named my-overlay.dts on the target platform with the following contents:

/dts-v1/;
 
/ {
    overlay-name = "My Jetson Overlay Example";
    jetson-header-name = "Jetson 40pin Header";
    compatible = "nvidia,p3509-0000+p3668-0001";
 
    fragment@0 {
        target-path = "/";
        __overlay__ {
            my-custom-property = "This Is My Overlay";
        };
    };
};

Enter the following command to compile the DTS source file into an overlay file:

dtc -O dtb -o my-overlay.dtbo -@ my-overlay.dts

After you copy the new overlay file to the /boot directory, the Jetson‑IO tool finds the overlay file and allows you to apply it. If you use an incorrect compatible value the DT overlay will not be listed.

sudo cp my-overlay.dtbo /boot
sudo /opt/nvidia/jetson-io/config-by-hardware.py -l

Configuration listed from Xavier NX:

Configurations for the following hardware modules are available:
1. Adafruit SPH0645LM4H
2. FE-PI Audio V1 and Z V2
3. My Jetson Overlay example
4. ReSpeaker 4 Mic Array

Apply the device tree overlay created

sudo /opt/nvidia/jetson-io/config-by-hardware.py -n "My Jetson Overlay example"

To apply the changes, the board needs to be rebooted. After rebooting the board, you can read the new property defined in the device tree using the DT overlay.

cat /proc/device-tree/my-custom-property

Output:

This Is My Overlay

Remove overlay changes applied

The changes of the DT overlay are applied over the original DT and a new device tree is created. The name of the resulting device tree combines the original DT name and the overlay name. /boot/kernel_tegra194-p3668-all-p3509-0000-my-jetson-overlay-example.dtb

To use the new DT, Jetson‑IO creates a new entry in /boot/extlinux/extlinux.conf

This is the new entry added that is added to the /boot/extlinux/extlinux.conf file when the overlay support has been added:

LABEL My Jetson Overlay example
	MENU LABEL My Jetson Overlay example
	LINUX /boot/Image
	FDT /boot/kernel_tegra194-p3668-all-p3509-0000-my-jetson-overlay-example.dtb
	INITRD /boot/initrd
	APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyTCU0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0

To remove the new overlay support, simply delete the new entry from the /boot/extlinux/extlinux.conf file, and then reboot the board. After rebooting the board, you can confirm that the property defined in the DT overlay is no longer defined since now we are using the original device tree.

cat /proc/device-tree/my-custom-property

Output:

cat: /proc/device-tree/my-custom-property: No such file or directory

Device tree overlay nodes

Since in a device tree overlay some symbols can not be defined, since they are defined in the device tree, then is required overlay nodes to manage this cases. To show the device tree node, we are going to create a device tree overlay to add a change the GPIO configuration for Jetson TX2 Developer Kit as example. Create a file named tx2-uart-overlay.dts on the target platform with the following contents:

/dts-v1/;
/plugin/;
/ {
    overlay-name = "tx2_uart_overlay";
    compatible = "nvidia,p2597-0000+p3310-1000";

    fragment@0 {
        target = <&pinmux>;

        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&hdr40_pinmux>;

            hdr40_pinmux: header-40pin-pinmux {

                pin8 {
                    nvidia,function = "uarta";
                    nvidia,pins = "uart1_tx_pt0";
                    nvidia,pull = <0x00000000>;
                    nvidia,tristate = <0x00000000>;
                    nvidia,enable-input = <0x00000000>;
                    nvidia,lpdr = <0x00000000>;
                };
                pin10 {
                    nvidia,function = "uarta";
                    nvidia,pins = "uart1_rx_pt1";
                    nvidia,pull = <0x00000002>;
                    nvidia,tristate = <0x00000001>;
                    nvidia,enable-input = <0x00000001>;
                    nvidia,lpdr = <0x00000000>;
                };

            };
        };
    };
};


  • __overlay__: contains the body of which is added to the target node.
  • __symbols__: This node is only required for the target=<phandle> method, since it contains the information required to map from a phandle to a tree location.
  • __fixups__: contains a list of properties mapping the names of unresolved symbols to lists of paths to cells within the fragments that need patching with the phandle of the target node. This section only is created if the device tree contains /plugin/ tag.
  • __local_fixups__: holds the locations of any references to labels that exist within the overlay

References


RidgeRun Resources

Quick Start Client Engagement Process RidgeRun Blog Homepage
Technical and Sales Support RidgeRun Online Store RidgeRun Videos Contact Us
RidgeRun.ai: Artificial Intelligence | Generative AI | Machine Learning

Contact Us

Visit our Main Website for the RidgeRun Products and Online Store. RidgeRun Engineering information is available at RidgeRun Engineering Services, RidgeRun Professional Services, RidgeRun Subscription Model and Client Engagement Process wiki pages. Please email to support@ridgerun.com for technical questions and contactus@ridgerun.com for other queries. Contact details for sponsoring the RidgeRun GStreamer projects are available in Sponsor Projects page.