Jump to content

NVIDIA Jetson - Device Tree Overlay: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
 
Line 56: Line 56:
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 <code>my-overlay.dts</code> on the target platform with the following contents:
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 <code>my-overlay.dts</code> on the target platform with the following contents:


<source lang="c">
<syntaxhighlight lang="C">
/dts-v1/;
/dts-v1/;
   
   
Line 71: Line 71:
     };
     };
};
};
</source>
</syntaxhighlight>


Enter the following command to compile the DTS source file into an overlay file:
Enter the following command to compile the DTS source file into an overlay file:
<source lang="bash">
<syntaxhighlight lang="bash">
dtc -O dtb -o my-overlay.dtbo -@ my-overlay.dts
dtc -O dtb -o my-overlay.dtbo -@ my-overlay.dts
</source>
</syntaxhighlight>
After you copy the new overlay file to the <code>/boot</code> 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.
After you copy the new overlay file to the <code>/boot</code> 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.
<source lang="bash">
<syntaxhighlight lang="bash">
sudo cp my-overlay.dtbo /boot
sudo cp my-overlay.dtbo /boot
sudo /opt/nvidia/jetson-io/config-by-hardware.py -l
sudo /opt/nvidia/jetson-io/config-by-hardware.py -l
</source>
</syntaxhighlight>
Configuration listed from Xavier NX:
Configuration listed from Xavier NX:
<source>
<syntaxhighlight lang="bash">
Configurations for the following hardware modules are available:
Configurations for the following hardware modules are available:
1. Adafruit SPH0645LM4H
1. Adafruit SPH0645LM4H
Line 89: Line 89:
3. My Jetson Overlay example
3. My Jetson Overlay example
4. ReSpeaker 4 Mic Array
4. ReSpeaker 4 Mic Array
</source>
</syntaxhighlight>
Apply the device tree overlay created
Apply the device tree overlay created


<source lang="bash">
<syntaxhighlight lang="bash">
sudo /opt/nvidia/jetson-io/config-by-hardware.py -n "My Jetson Overlay example"
sudo /opt/nvidia/jetson-io/config-by-hardware.py -n "My Jetson Overlay example"
</source>
</syntaxhighlight>


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.
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.
<source lang="bash">
<syntaxhighlight lang="bash">
cat /proc/device-tree/my-custom-property
cat /proc/device-tree/my-custom-property
</source>
</syntaxhighlight>
Output:
Output:
<source lang="bash">
<syntaxhighlight lang="bash">
This Is My Overlay
This Is My Overlay
</source>
</syntaxhighlight>
 
===Remove overlay changes applied===
===Remove overlay changes applied===


Line 112: Line 111:


This is the new entry added that is added to the <code>/boot/extlinux/extlinux.conf</code> file when the overlay support has been added:
This is the new entry added that is added to the <code>/boot/extlinux/extlinux.conf</code> file when the overlay support has been added:
<source lang="conf">
<syntaxhighlight lang="conf">
LABEL My Jetson Overlay example
LABEL My Jetson Overlay example
MENU LABEL My Jetson Overlay example
MENU LABEL My Jetson Overlay example
Line 119: Line 118:
INITRD /boot/initrd
INITRD /boot/initrd
APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyTCU0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyTCU0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
</source>
</syntaxhighlight>


To remove the new overlay support, simply delete the new entry from the <code>/boot/extlinux/extlinux.conf</code> 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.
To remove the new overlay support, simply delete the new entry from the <code>/boot/extlinux/extlinux.conf</code> 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.
<source lang="bash">
<syntaxhighlight lang="bash">
cat /proc/device-tree/my-custom-property
cat /proc/device-tree/my-custom-property
</source>
</syntaxhighlight>
Output:
Output:
<source lang="bash">
<syntaxhighlight lang="bash">
cat: /proc/device-tree/my-custom-property: No such file or directory
cat: /proc/device-tree/my-custom-property: No such file or directory
</source>
</syntaxhighlight>


==Device tree overlay nodes==
==Device tree overlay nodes==
Line 144: Line 143:
Create a file named tx2-uart-overlay.dts on the target platform with the following contents:
Create a file named tx2-uart-overlay.dts on the target platform with the following contents:


<source lang="c">
<syntaxhighlight lang="C">
/dts-v1/;
/dts-v1/;
/plugin/;
/plugin/;
Line 179: Line 178:
     };
     };
};
};
</source>
</syntaxhighlight>
The device tree overlays contains:
The device tree overlays contains:


Line 188: Line 187:
To see how the compiler dynamically resolves these labels and symbols, you can see the dtbo file generated. Compile the device tree and use <code>fdtdump</code> to see the device tree overlay content.
To see how the compiler dynamically resolves these labels and symbols, you can see the dtbo file generated. Compile the device tree and use <code>fdtdump</code> to see the device tree overlay content.


<source lang="bash">
<syntaxhighlight lang="bash">
dtc -O dtb -o tx2-uart-overlay.dtbo -@ tx2-uart-overlay.dts
dtc -O dtb -o tx2-uart-overlay.dtbo -@ tx2-uart-overlay.dts
fdtdump tx2-uart-overlay.dtbo
fdtdump tx2-uart-overlay.dtbo
</source>
</syntaxhighlight>


This is the <code>fdtdump</code> tool output, since the tag <code>/plugin/</code> was added to the overlay, the nodes <code>__symbols__</code>, <code>__fixups__</code> and <code>__local_fixups__</code> are created automatically.
This is the <code>fdtdump</code> tool output, since the tag <code>/plugin/</code> was added to the overlay, the nodes <code>__symbols__</code>, <code>__fixups__</code> and <code>__local_fixups__</code> are created automatically.


<source lang="bash">
<syntaxhighlight lang="bash">
/dts-v1/;
/dts-v1/;
// magic: 0xd00dfeed
// magic: 0xd00dfeed
Line 251: Line 250:
     };
     };
};
};
</source>
</syntaxhighlight>


=== Notes===
=== Notes===
Line 276: Line 275:
}}
}}
Example: Since <code>ub953_0</code> is created and used also as a target, This will produce an error when is applied the overlay.
Example: Since <code>ub953_0</code> is created and used also as a target, This will produce an error when is applied the overlay.
<source lang="c">
<syntaxhighlight lang="C">
     fragment@0 {
     fragment@0 {
         target = <&i2c_fpdlink>; // i2c2 = "i2c_fpdlink: i2c@0"
         target = <&i2c_fpdlink>; // i2c2 = "i2c_fpdlink: i2c@0"
Line 297: Line 296:
    }; /* End __overlay__ */
    }; /* End __overlay__ */
     }; /* End fragment@1 */
     }; /* End fragment@1 */
</source>
</syntaxhighlight>


==Pre-process the DT overlay file with the C preprocessor (cpp)==
==Pre-process the DT overlay file with the C preprocessor (cpp)==
Line 305: Line 304:
Example: This is the same previous device tree but using pinctrl tegra definitions to set GPIO configuration:
Example: This is the same previous device tree but using pinctrl tegra definitions to set GPIO configuration:


<source lang="c">
<syntaxhighlight lang="C">
/dts-v1/;
/dts-v1/;
/plugin/;
/plugin/;
Line 350: Line 349:
     };
     };
};
};
</source>
</syntaxhighlight>


Use the C Pre-process (cpp) to replace Constants in the device tree overlay
Use the C Pre-process (cpp) to replace Constants in the device tree overlay
<source lang="bash">
<syntaxhighlight lang="bash">
cpp -nostdinc -I kernel/kernel-4.9/include/ -undef -x assembler-with-cpp tx2-uart-overlay.dts  tx2-uart-overlay.dts.preprocessed
cpp -nostdinc -I kernel/kernel-4.9/include/ -undef -x assembler-with-cpp tx2-uart-overlay.dts  tx2-uart-overlay.dts.preprocessed
</source>
</syntaxhighlight>


Parameter description:
Parameter description:
Cookies help us deliver our services. By using our services, you agree to our use of cookies.