54

I have a device tree file (.dts) and I want to compile the file for my powerpc based board.

How can I do it on my machine, which is not powerpc based?? Can I do it with the DTC installed on my Ubuntu system? Or will it be more like using a separate compiler and passing ARCH information (like using a toolchain)?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
mdsingh
  • 973
  • 2
  • 13
  • 20

3 Answers3

79

Device trees do not need to be compiled with "architecture-aware" tools. The dtc compiler on your ubuntu machine is probably current enough to compile your device tree. Or you can download the latest source and compile it yourself. The dtc compiler can be found here:

https://git.kernel.org/pub/scm/utils/dtc/dtc.git

There are some good documents in that package that will help you better understand device trees in general.

It's pretty easy to compile (and disassemble) device trees. For example

$ dtc -O dtb -o p4080ds.dtb p4080ds.dts

To get the device tree in text from from the device tree blob, do this:

$ dtc -I dtb -O dts p4080ds.dtb

Hope this helps!

Jeremy Wong
  • 1,030
  • 1
  • 10
  • 9
challinan
  • 2,584
  • 18
  • 13
  • yeah thats true what you said there challinan. They don't need to be compiled with "architecture-aware" tools. Though i am not pretty sure why exactly? – mdsingh Feb 12 '14 at 04:31
  • 1
    something which is compiled to run on a machine should be arch aware of the machine... isn't it? – mdsingh Feb 12 '14 at 04:31
  • 2
    @mdsingh: "Compiling" a DTS to DTB does not generate a binary which run on a CPU. DTB files are just a binary representation of DTS file (just like serializing an XML) which helps the kernel to the devices available on the architecture and their configuration. This helps to have a kernel source less dependent on the hard configuration. So as you can see, device trees are **intended*8 to be be architecture *ignorant*. – Isaac Apr 08 '15 at 04:46
  • So its _not loaded into the memory_ but just _read_ (well sort of _parsed_) by kernel. Thats what makes it arch independent, as it is intended to be. Thanks. – mdsingh Apr 09 '15 at 05:46
  • you should probably try updating the git link for dtc.It seems dead ! – Raulp Jul 25 '16 at 10:40
  • @mdsingh, The kernel is passed a data structure from the bootloader that informs it of the DTB's location. It could still be on disk or it may have been loaded into memory. – sherrellbc Mar 16 '17 at 18:43
31
  • dtc can be installed by this command on linux:

    sudo apt-get install device-tree-compiler

  • you can compile dts or dtsi files by this command:

    dtc -I dts -O dtb -o devicetree_file_name.dtb devicetree_file_name.dts

  • you can convert dts to dtb by this command:

    dtc -I dts -O dtb -f devicetree_file_name.dts -o devicetree_file_name.dtb

  • you can convert dtb to dts by this command:

    dtc -I dtb -O dts -f devicetree_file_name.dtb -o devicetree_file_name.dts

Mojtaba Ahmadi
  • 1,044
  • 19
  • 38
  • Oh, but now dts files can have includes so you need cpp and makefiles. – Alan Corey Apr 13 '21 at 01:12
  • I might be late to ask this, but what is the difference between `compile` and `convert` dts to dtb in this case? – elhe Jan 12 '22 at 08:34
  • 1
    @elhe Basically Compiling would gather other files and all the symbols on them to create the resulting DTB file. Converting from DTB to DTS would just get the already compiled DTB and convert it back to a DTS(Which is in a readable form). – Bybit360 Mar 01 '23 at 18:59
24

make dtbs

Doing this from the kernel tree is another common way to compile them, since the standard place to put dts is under the kernel tree in directories of the form ./arch/<arch>/boot/dts/.

This ends up calling dtc, but might work better because potential includes will be in the right place.

dtb files are placed in the same directory as the dts.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985