编程知识 cdmana.com

Embedded Linux development---device tree

Cause: The simple and repeated board-level hardware information is written in the linux kernel, which is very redundant and bloated. They are extracted and described by a separate file. This file is dtb
Device tree composition: 1dts file + multiple dtsi files, compiled into a dtb file is the real device tree
Compatible with C language features, you can use include to include other dtsi and .h files
Tree structure

Syntax

root node tag /

/{The root node can contain child nodes and attributes......}

Child node tag

Format:

[email protected]{Child nodes can contain other descendant nodes as well as attributes......}

node-name is the node name: "uart1" indicates that this node is a UART1 peripheral
unit-address: generally indicates the address of the device or the first address of the register.Because not every device has an address, such as CPU and Intrrupt-Controller, do not write without an address

label label

The

tag is mainly convenient for reference:
Format:

label: [email protected]

It is to use label: mark the format of the above child nodes
Example:

cpu0: [email protected]

The label here is cpu0, which is referenced by &cpu0 in actual reference, no need to enter the complete node name

Attribute

Attributes are all key-value pairs
There are four cases of values:

  1. string
  2. 32-bit unsigned integer (list)
  3. List of strings
  4. Empty means nothing

Standard attributes

Attributes have their own defined attributes, which can be written freely, a bit like writing python variables. Standard attributes are already defined attributes.
Different devices require different properties, and users can customize the properties.In addition to user-defined attributes, many attributes are standard attributes. Many peripheral drivers under Linux use these standard attributes. Several commonly used standard attributes:

  1. compatible value is a string or a list of strings, compatibility, the signature used for matching between devices and drivers, can be multiple, and the priority is descending from front to back
  2. model value is a string describing device model information, etc.
  3. status is a string describing the device status information Available values: "okey" "disable" "fail" "fail-sss" (sss is the detected error content)
  4. address-cells Unsigned 32 bits Used for devices with child nodes, the word length occupied by the address information in the reg attribute describing the child nodes consists of several 32 bits
  5. size-cells Unsigned 32 bits Used for devices with child nodes, the word length occupied by the length information in the reg attribute describing the child nodes consists of several 32 bits
  6. reg means address-related space resource information, and there are two types of address-related information: starting address and address length
  7. rangers is an address translation table. Each item consists of three parts: child address, parent address and space length
  8. name is deprecated no need to know
  9. device_type describes the FCode of the device, which can only be used for some CPU and Memory nodes

Special Nodes

aliase:
Used to alias a node, the function is repeated with the label, and the &label method is also good to refer to a node

chosen:
Mainly to pass data to uboot and linux kernel, such as the value of the bootargs parameter

OF function enumeration - the function interface used in the kernel to obtain information from the device tree

The Linux kernel code can be read from this website
Get node information:

of_find_node_by_name // - Find a node by its "name" propertyof_find_node_by_type // - Find a node by its "device_type" propertyof_find_compatible_node //- Find a node based on type and one of the tokens in its "compatible" propertyof_find_matching_node_and_match // - Find a node based on an of_device_id match table.of_find_node_by_path //

Find a node's parent/child node:

of_get_parentof_get_next_child

Or the interface of the node attribute value:

of_find_property functionof_property_count_elems_of_size functionof_property_read_u32_index functionof_property_read_u8_array functionof_property_read_u16_array functionof_property_read_u32_array functionof_property_read_u64_array functionof_property_read_u8 functionof_property_read_u16 functionof_property_read_u32 functionof_property_read_u64 functionof_property_read_string functionof_n_addr_cells functionof_n_size_cells function

These are basic knowledge, see this for some usage:

https://blog.csdn.net/qq_28992301/article/details/53321610

版权声明
本文为[Three Realms]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/218/202208060629430520.html

Scroll to Top