Device tree

来自百问网嵌入式Linux wiki
Zhouyuebiao讨论 | 贡献2020年5月6日 (三) 23:15的版本 (创建页面,内容为“==Purpose== The objective of this chapter is to give general information about the device tree.<br /> An extract of the '''device tree specification'''<ref name="dt_…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Purpose

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. For more information, please refer to the device tree specification[1] <securetransclude src="ProtectedTemplate:ReviewsComments" params="W903.5 GeraldB: "A device tree..." -> "In other words, a device tree...""></securetransclude>{{#set:Has reviews comments=true}} <securetransclude src="ProtectedTemplate:ReviewsComments" params="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"></securetransclude>{{#set:Has reviews comments=true}}

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® Kernel, U-Boot and TF-A.

<securetransclude src="ProtectedTemplate:ReviewsComments" params="W903.5 GeraldB: "DTC" should be introduced (or reference to the paragraph below) since this is the first time it is mentionned"></securetransclude>{{#set:Has reviews comments=true}} <securetransclude src="ProtectedTemplate:ReviewsComments" params="W903.5 GeraldB: "This format..." -> this sentence is very (too) long, with three occurences of "device tree" inside. Can you simplify ?"></securetransclude>{{#set:Has reviews comments=true}} <securetransclude src="ProtectedTemplate:ReviewsComments" params="W904.1 NicolasLB: Maybe you should replace (here and in all the page where it is not set):

W805 GeraldB: on the first occurence, yes. But not necessarly on all occurences to avoid too many links that may lose the reader."></securetransclude>{{#set:Has reviews comments=true}}

  • .dtsi: Source files that can be included from a DTS file.

<securetransclude src="ProtectedTemplate:ReviewsComments" params="W903.5 GeraldB: .h files to be added"></securetransclude>{{#set:Has reviews comments=true}}

Bindings

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

Build


文件:Dt.png
Device tree build process



  • 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[2].

<securetransclude src="ProtectedTemplate:ReviewsComments" params="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."></securetransclude>{{#set:Has reviews comments=true}}

  • DTC source code is located here[3]. 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.



Tools

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[3]
  • Directly in software components: Kernel, u-boot, tf-a ...
  • Available in Debian package[4]

STM32

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.

How to go further

  • Device Tree for Dummies[5] - Free Electrons
  • Device Tree Reference[6] - eLinux.org
  • Device Tree usage[7] - eLinux.org

References

<securetransclude src="ProtectedTemplate:PublicationRequestId" params="10390 | 2019-01-21 | AlainF"></securetransclude>