Best practices for modifying device tree

Hello,

I have a very simple device tree change that I want to do.

/ {

	aliases {
		rtc2  = &ds1339;
	};

	bus@0 {
		i2c@c240000 {
			status = "okay";
			ds1339: rtc@68 {
				compatible = "dallas,ds1339";
				trickle-resistor-ohms = <2000>;
				reg = <0x68>;
			};
		};
	};
};

What I discovered by reading the documentation and forum is that I either create a device tree overlay or directly modify the provided device tree.

1. Device Tree Overlay

/dts-v1/;
/plugin/;

/ {
    overlay-name = "Test Overlay";
	
	aliases {
		rtc2  = &ds1339;
	};

	fragment@0 {
		target-path = "/";
		__overlay__ {
			bus@0 {
				i2c@c240000 {
					status = "okay";
					ds1339: rtc@68 {
						compatible = "dallas,ds1339";
						trickle-resistor-ohms = <2000>;
						reg = <0x68>;
					};
				};
			};
		};
	};
};
  • When I take a look at the existing overlays /Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/overlay some do have overlay-name and compatible and some do not. Is this property therefore not required?
  • Is there a documentation what we need to add into compatible when we want to support for example Jetson Orin Nano and Jetson Orin NX or can we leave compatible out when it does not matter?

After creating the .dts file compile it with:

dtc -O dtb -o some_overlay.dtbo -@ some_overlay.dts

And copy it:

cp some_overlay.dtbo Linux_for_Tegra/kernel/dtb/

And add it to my custom.conf file used for flashing:

...
OVERLAY_DTB_FILE+=",some_overlay.dtbo";
...

2. Adding it to existing device tree

  • which of the device tree files should I edit in Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public?
    • probably different ones when I want to make changes for example only to Orin Nano or common for all
  • how can I do it modular and keep my device tree files separate (f.i. by including it as a .dtsi file)
  • are there additional steps required like for the device tree overlay?

To sum it up. What is the recommended way to add a custom device tree (L4T 36.4.3)? Which of the two ways is easier and less prone to errors?

Hi Xennor,

Are you using the devkit or custom board for Orin Nano?
What’s the Jetpack version in use?

It depends on your use case and what do you want to update? The configuration of i2c@c240000 node?

Hi KevinFFF,

I am using JetPack 6.2 on a custom carrier board which has a lot of similarities to the dev board. I want to modify the i2c@c240000 node which is the i2c1 bus.

Please refer to Device Tree Overlays to apply the dtb overlay since you want to keep your device tree configuration seperate.

Sure, you can also add custom dtsi in source and let it be included in device tree.

Which device tree file would I need to add the dtsi file to? This here? I want to make sure that I do not use a file which might be changed by your side in future releases.

Regarding the Device Tree Overlay. There is also this guide to apply an device tree overlay. So what is the difference?

Please create your own dtsi to use custom dtbo as overlay.

They should be similar process and the one in this link is specific to camera use case.

What I mean is in which dts file should I include my custom dtsi file for it to be build when I run make dtbs (Building DTBS) f.i. #include "custom.dtsi"?
There are a lot of device tree files in /hardware/nvidia/t23x/nv-public but which one is the right one?

Am I right assuming that the config-by-hardware.py script is only useable when the device is already flashed? It needs to be executed directly on the Jetson? My use case is to apply it beforehand.

You can include in tegra234-p3768-0000+p3767-xxxx-nv-common.dtsi

Or you can simply add OVERLAYS option in extlinux.conf to specify your custom overlay dtbo.

If you want to apply the change before flash the board, please just include your dts in tegra234-p3768-0000+p3767-xxxx-nv-common.dtsi.