Devicetree: Difference between revisions

Knuxify (talk | contribs)
Created page with "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. 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 mechan..."
 
Knuxify (talk | contribs)
No edit summary
Line 18: Line 18:


The <code>dtc</code> tool handles compiling DTS files into DTBs, as well as decompiling DTBs back into DTS.
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:
<syntaxhighlight lang="dts">
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
my_node: node1@1000 {
compatible = "vendor,foo";
reg = <0x1000 0x54>;
vendor,bar-factor = <0x2a>;
};
node2@2000 {
compatible = "vendor,bar";
reg = <0x2000 0xa4>;
vendor,baz-companion = <&my_node>;
};
i2c-controller@3000 {
compatible = "vendor,foobar-i2c";
reg = <0x3000 0x800>;
#address-cells = <1>;
#size-cells = <0>;
sensor@10 {
compatible = "vendor,baz-sensor";
reg = <0x10>;
};
};
};
</syntaxhighlight>
In this example, we define an empty DTS; in its root node (<code>/</code>), we place three nodes: a node named "node1" with a label "my_node" at address 0x1000, a node named "node2" at address 0x2000, and a node named "i2c-controller" at address 0x3000.
A node contains:
* A <code>compatible</code> value (here <code>"vendor,foo"</code>). This specifies what kind of component it is; Linux uses this information to load the correct driver.
* A <code>reg</code> value. In this case, the first parameter is the base address in memory (<code>0x1000</code>), and the second is the size it occupies (<code>0x54</code>). The amount of cells for the address and size are specified by the <code>#address-cells</code> and <code>#size-cells</code> properties of the root node, respectively.
** You might notice that the i2c-controller node defines another set of these <code>#address-cells</code> and <code>#size-cells</code> properties - this is because I2C devices contain their own subdevices with addresses ranging from 0x08 to 0x7f (todo verify), and they do not use a size.
* A custom vendor-specific property, <code>vendor,bar-factor</code>, which takes a number.
On node 2 there is also a property, <code>vendor,baz-companion</code>, which takes a pointer to another node - here the one we labeled "my_node".


== Verifying device tree bindings and device tree sources ==
== Verifying device tree bindings and device tree sources ==
Line 66: Line 114:
** [https://docs.kernel.org/devicetree/bindings/writing-bindings.html DOs and DON’Ts for designing and writing Devicetree bindings]
** [https://docs.kernel.org/devicetree/bindings/writing-bindings.html DOs and DON’Ts for designing and writing Devicetree bindings]
** [https://docs.kernel.org/devicetree/bindings/submitting-patches.html Submitting Devicetree (DT) binding patches]
** [https://docs.kernel.org/devicetree/bindings/submitting-patches.html Submitting Devicetree (DT) binding patches]
* On elinux.org:
** [https://elinux.org/Device_Tree_Reference Device Tree Reference]
** [https://elinux.org/Device_Tree_Reference Device Tree Usage]


== References ==
== References ==