Last edited 3 years ago

Device tree: Difference between revisions

Registered User
mNo edit summary
Registered User
 
(7 intermediate revisions by 2 users not shown)
Line 7: Line 7:
''Rather than hard coding every detail of a device into an operating system, many aspect of the hardware can be described in a data structure that is passed to the operating system at boot time."''
''Rather than hard coding every detail of a device into an operating system, many aspect of the hardware can be described in a data structure that is passed to the operating system at boot time."''


In other words, a device tree describes the hardware that can not be located by probing. For more information, please refer to the device tree specification<ref name="dt_org" />
In other words, a device tree describes the hardware that can not be located by probing.
{{ReviewsComments| W903.5 GeraldB: "A device tree..." -> "In other words, a device tree..."}}
===Device tree basis===
{{ReviewsComments| W903.5 GeraldB: "For more information..." -> I propose to remove this since this create a new reference to the specification that is already referd few lines above}}
This webinar will give the foundations of device tree applied to STM32MP1 products and boards. This is highly recommended to start from this if you are beginner on this subject.
* Device Tree for STM32MP <ref>[https://www.youtube.com/watch?v=a9CZ1Uk3OYQ https://www.youtube.com/watch?v=a9CZ1Uk3OYQ], Device Tree for STM32MP</ref>


===Source files===
===Source files===
*'''.dts:''' The device tree source (DTS). This format is a textual representation of a device tree in a form that can be processed by DTC (Device Tree Compiler) into a binary device tree in the form expected by software components: Linux<sup>&reg;</sup> Kernel, U-Boot and TF-A.
*'''.dts:''' The device tree source (DTS). This format is a textual representation of a device tree in a form that can be processed by DTC (Device Tree Compiler) into a binary file expected by software components: [[STM32MP15_Linux_kernel_overview|Linux<sup>&reg;</sup> Kernel]], [[U-Boot_overview|U-Boot]] and [[TF-A overview|TF-A]].
{{ReviewsComments| W903.5 GeraldB: "DTC" should be introduced (or reference to the paragraph below) since this is the first time it is mentionned}}
{{ReviewsComments| W903.5 GeraldB: "This format..." -> this sentence is very (too) long, with three occurences of "device tree" inside. Can you simplify ?}}
{{ReviewsComments| W904.1 NicolasLB: Maybe you should replace (here and in all the page where it is not set):
* TF-A by [[TF-A overview|TF-A]]
* U-Boot SPL by [[U-Boot_overview#SPL:_FSBL_for_basic_boot|U-Boot SPL]]
* Linux® Kernel by [[STM32MP15_Linux_kernel_overview|Linux® Kernel]]
W805 GeraldB: on the first occurence, yes. But not necessarly on all occurences to avoid too many links that may lose the reader.}}
*'''.dtsi:''' Source files that can be included from a DTS file.
*'''.dtsi:''' Source files that can be included from a DTS file.
{{ReviewsComments| W903.5 GeraldB: .h files to be added}}
*'''.h:''' Header files that can be included from DTS and DTSI files.


===Bindings===
===Bindings===
Line 34: Line 28:
===Build===
===Build===


[[File: dt.png|thumb|upright=2|center|link=|Device tree build process]]


<br>
*A tool named DTC<ref>[https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/Documentation/manual.txt https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/Documentation/manual.txt(master)], DTC manual</ref>(Device Tree Compiler) allows compiling the DTS sources into a binary.
[[File: dt.png|thumb|upright=2|right|link=|Device tree build process]]
:*input file: the ''.dts'' file described in section above (that includes itself one or several .dtsi and .h files).
 
:*output file: the ''.dtb'' file described in section above.
 
 
 
 
*A tool named DTC (Device Tree Compiler) allows compiling the DTS sources into a binary.
*input file: the ''.dts'' file described in section above.
*output file: the ''.dtb'' file described in section above.
 
*More information are available in DTC manual<ref>[https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/Documentation/manual.txt https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/Documentation/manual.txt(master)] ,DTC manual</ref>.
{{ReviewsComments| W903.5 GeraldB: the bullet above is useless if you directly put the reference to the DTC manual from the first bullet. Moreover, such a reference is missing above so that would ease the reading.}}
 
*DTC source code is located here<ref name="dtc_source">[https://git.kernel.org/pub/scm/utils/dtc/dtc.git https://git.kernel.org/pub/scm/utils/dtc/dtc.git(master)] ,DTC source code</ref>. DTC tool is also available directly in particular software components: '''Linux Kernel, U-Boot, TF-A ...'''. For those components, the device tree building is directly integrated in the component build process.


DTC source code is located here<ref name="dtc_source">[https://git.kernel.org/pub/scm/utils/dtc/dtc.git https://git.kernel.org/pub/scm/utils/dtc/dtc.git(master)] ,DTC source code</ref>. DTC tool is also available directly in particular software components: '''Linux Kernel, U-Boot, TF-A ...'''. For those components, the device tree building is directly integrated in the component build process.


{{Info|If dts files use some defines, dts files should be preprocessed before being compiled by DTC.}}
{{Info|If dts files use some defines, dts files should be preprocessed before being compiled by DTC.}}


<br/>
<br/>
Line 80: Line 63:
==How to go further==
==How to go further==


* Device Tree for STM32MP <ref>[https://www.youtube.com/watch?v=a9CZ1Uk3OYQ https://www.youtube.com/watch?v=a9CZ1Uk3OYQ], Device Tree for STM32MP</ref>
* Device Tree Reference<ref>[https://elinux.org/Device_Tree_Reference Device Tree Reference], eLinux.org</ref> - eLinux.org
* Device Tree Reference<ref>[https://elinux.org/Device_Tree_Reference Device Tree Reference], eLinux.org</ref> - eLinux.org
* Device Tree usage<ref>[https://elinux.org/Device_Tree_Usage Device Tree Usage], eLinux.org</ref> - eLinux.org
* Device Tree usage<ref>[https://elinux.org/Device_Tree_Usage Device Tree Usage], eLinux.org</ref> - eLinux.org

Latest revision as of 13:05, 5 November 2021

1. Purpose[edit source]

The objective of this chapter is to give general information about the device tree.
An extract of the device tree specification[1] explains it as follows:

"A device tree is a tree data structure with nodes that describe the devices in a system. Each node has property/value pairs that describe the characteristics of the device being represented. Each node has exactly one parent except for the root node, which has no parent. ... Rather than hard coding every detail of a device into an operating system, many aspect of the hardware can be described in a data structure that is passed to the operating system at boot time."

In other words, a device tree describes the hardware that can not be located by probing.

1.1. Device tree basis[edit source]

This webinar will give the foundations of device tree applied to STM32MP1 products and boards. This is highly recommended to start from this if you are beginner on this subject.

  • Device Tree for STM32MP [2]

1.2. Source files[edit source]

  • .dts: The device tree source (DTS). This format is a textual representation of a device tree in a form that can be processed by DTC (Device Tree Compiler) into a binary file expected by software components: Linux® Kernel, U-Boot and TF-A.
  • .dtsi: Source files that can be included from a DTS file.
  • .h: Header files that can be included from DTS and DTSI files.

1.3. Bindings[edit source]

The device tree data structures and properties are named bindings. Those bindings are described in:

1.4. Build[edit source]

Device tree build process
  • A tool named DTC[3](Device Tree Compiler) allows compiling the DTS sources into a binary.
  • input file: the .dts file described in section above (that includes itself one or several .dtsi and .h files).
  • output file: the .dtb file described in section above.

DTC source code is located here[4]. DTC tool is also available directly in particular software components: Linux Kernel, U-Boot, TF-A .... For those components, the device tree building is directly integrated in the component build process.

Info.png If dts files use some defines, dts files should be preprocessed before being compiled by DTC.


1.5. Tools[edit source]

The device tree compiler offers also some tools:

  • fdtdump: Print a readable version of a flattened device tree file (dtb)
  • fdtget: Read properties from a device tree
  • fdtput: Write properties to a device tree
  • ...

There are several ways to get those tools:

  • In the device tree compiler project source code[4]
  • Directly in software components: Kernel, u-boot, tf-a ...
  • Available in Debian package[5]

2. STM32[edit source]

For STM32MP1, the device tree is used by three software components: Linux® kernel, U-Boot and TF-A.

The device tree is part of the OpenSTLinux distribution. It can also be generated by STM32CubeMX tool.

To have more information about the device tree usage on STM32MP1 (how the device tree source files are split, how to find the device tree source files per software components, how is STM32CubeMX generating the device tree ...) see STM32MP15 device tree page.

3. How to go further[edit source]

  • Device Tree Reference[6] - eLinux.org
  • Device Tree usage[7] - eLinux.org

4. References[edit source]