# How to decompile a device tree in PetaLinux

## Converting a .dtb to .dts

One of the output products of a PetaLinux project is a compiled (binary) device tree. Sometimes we’d like to be able to read that compiled device tree to see exactly what is inside it. This can help with debugging a problem, or you may just want to make sure that your device tree additions are actually being pulled in. Either way, a compiled device tree can be “decompiled” using a tool that you can find hidden away in the PetaLinux build collateral.

### Device tree compiler (DTC)

DTC is a tool that can be used to interpret a compiled device tree (.dtb) and convert it into a text file (.dts). You can find DTC inside a build PetaLinux project after petalinux-build has been run, but the exact path will depend on the version of PetaLinux that you are using. The paths listed below are specifically for PetaLinux 2020.2, but the paths in earlier versions should be very similar.

### Where to find it

To find DTC in your PetaLinux project, first check the value of CONFIG_YOCTO_MACHINE_NAME in the project-spec/configs/config file. Now the path to DTC is given by the path shown below with <CONFIG_YOCTO_MACHINE_NAME> replaced with the correct value for your project. You also have to swap all of the dashes (-) for underscores (_) in the Yocto machine name.

build/
tmp/
work/
<CONFIG_YOCTO_MACHINE_NAME>-xilinx-linux/
linux-xlnx/
5.4+gitAUTOINC+62ea514294-r0/
linux-<CONFIG_YOCTO_MACHINE_NAME>-standard-build/
scripts/
dtc/


Here’s an example path to DTC in a Microblaze based design where the Yocto machine name is microblazeel-v11.0-bs-cmp-mh-div-generic:

build/
tmp/
work/
microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/
linux-xlnx/
5.4+gitAUTOINC+62ea514294-r0/
linux-microblazeel_v11.0_bs_cmp_mh_div_generic-standard-build/
scripts/
dtc/


Here’s an example path to DTC in a Zynq based design where the Yocto machine name is zynq-generic:

build/
tmp/
work/
zynq_generic-xilinx-linux-gnueabi/
linux-xlnx/
5.4+gitAUTOINC+62ea514294-r0/
linux-zynq_generic-standard-build/
scripts/
dtc/


### How to use it

The compiled device tree of a PetaLinux project is system.dtb and it can be found in the images/linux directory. DTC can be called from that directory to parse the device tree like this:

cd images/linux
../../<path-to-dtc>/dtc -I dtb -O dts -o system.dts system.dtb


The output file system.dts is a text file that you can read in a text editor.