Devicetree: Difference between revisions

Knuxify (talk | contribs)
No edit summary
Knuxify (talk | contribs)
No edit summary
Line 1: Line 1:
The '''devicetree''' (device tree, DT (DTS/DTB)) is a data structure which holds information about all components present on a device. This data is structured in nested nodes with key/value property pairs for configuration.
The '''devicetree''' (device tree, DT) is a data structure which holds information about all components present on a device. This data is structured in nested nodes with key/value property pairs for configuration.


In simpler terms - a devicetree tells the kernel (or another DT-compatible piece of software/firmware like a bootloader) where each component is in register space/on an I2C or similar bus, and what settings to use to set it up. It is the basic mechanism for discovering components on embedded platforms, including ARM.
In simpler terms - a devicetree tells the kernel (or another DT-compatible piece of software/firmware like a bootloader) where each component is in register space/on an I2C or similar bus, and what settings to use to set it up. It is the basic mechanism for discovering components on embedded platforms, including ARM.
Devicetrees are written in a plaintext format known as the '''Device Tree Source (DTS)''' format. The DTS is later compiled into a '''Device Tree Blob (DTB)'''; in this form, it can be loaded by software/firmware.


Devicetrees are validated using '''devicetree schema''', which is described by bindings; see [[/Bindings]] for more information.
Devicetrees are validated using '''devicetree schema''', which is described by bindings; see [[/Bindings]] for more information.
Line 13: Line 15:
Before the introduction of devicetrees, ARM kernels used '''board files'''. These were C files stored in <code>arch/arm/mach-*</code> which served a similar purpose to devicetrees - they contained structures for defining component configuration ("platform data"). Unlike device trees however, they could also define C functions, since they were regular C sources compiled into the kernel. Board files technically still exist (citation needed?), but are no longer in wide use.
Before the introduction of devicetrees, ARM kernels used '''board files'''. These were C files stored in <code>arch/arm/mach-*</code> which served a similar purpose to devicetrees - they contained structures for defining component configuration ("platform data"). Unlike device trees however, they could also define C functions, since they were regular C sources compiled into the kernel. Board files technically still exist (citation needed?), but are no longer in wide use.


== Device Tree Source (DTS) and Device Tree Blob (DTB) ==
== Device Tree Source (DTS) basics ==
 
Devicetrees are written in a plaintext format known as the '''Device Tree Source (DTS)''' format. The DTS is later compiled into a '''Device Tree Blob (DTB)'''; in this form, it can be loaded by software/firmware.
 
The <code>dtc</code> tool handles compiling DTS files into DTBs, as well as decompiling DTBs back into DTS.
 
=== Device Tree Source basics ===


Here is a very simple DTS file to explain the basics of what you might see in a device tree source file:
Here is a very simple DTS file to explain the basics of what you might see in a device tree source file:
Line 89: Line 85:
$ make CHECK_DTBS=y DT_SCHEMA_FILES=trivial-devices.yaml qcom/sm8450-hdk.dtb
$ make CHECK_DTBS=y DT_SCHEMA_FILES=trivial-devices.yaml qcom/sm8450-hdk.dtb
</syntaxhighlight>
</syntaxhighlight>
== Working with DTC ==
The <code>dtc</code> tool handles compiling DTS files into DTBs, as well as decompiling DTBs back into DTS. (TODO: add instructions)


== See also ==
== See also ==