Part 1
요약·해설
Compatible matching의 우선순위, child·bus binding, 검색 경로와 파일 위치 제한을 공식 예제 4개와 함께 보존했습니다.
compatible 순서
필수값 · 형식
C macro
dts/bindings
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
32C4939C98D5383D71FDC8C3A1BE1D9EC4E89C1A95A339A696A2E38D393B35F6
.. _dt-binding-compat:
Introduction to Devicetree Bindings
###################################
.. note::
For a detailed syntax reference, see :ref:`dt-bindings-file-syntax`.
Devicetree nodes are matched to bindings using their :ref:`compatible
properties <dt-important-props>`.
During the :ref:`build_configuration_phase`, the build system tries to match
each node in the devicetree to a binding file. When this succeeds, the build
system uses the information in the binding file both when validating the node's
contents and when generating macros for the node.
.. _dt-bindings-simple-example:
A simple example
****************
Here is an example devicetree node:
.. code-block:: devicetree
/* Node in a DTS file */
bar-device {
compatible = "foo-company,bar-device";
num-foos = <3>;
};
Here is a minimal binding file which matches the node:
.. code-block:: yaml
# A YAML binding matching the node
compatible: "foo-company,bar-device"
properties:
num-foos:
type: int
required: true
The build system matches the ``bar-device`` node to its YAML binding because
the node's ``compatible`` property matches the binding's ``compatible:`` line.
What the build system does with bindings
****************************************
The build system uses bindings both to validate devicetree nodes and to convert
the devicetree's contents into the generated :ref:`devicetree_generated.h
<dt-outputs>` header file.
For example, the build system would use the above binding to check that the
required ``num-foos`` property is present in the ``bar-device`` node, and that
its value, ``<3>``, has the correct type.
The build system will then generate a macro for the ``bar-device`` node's
``num-foos`` property, which will expand to the integer literal ``3``. This
macro lets you get the value of the property in C code using the API which is
discussed later in this guide in :ref:`dt-from-c`.
For another example, the following node would cause a build error, because it
has no ``num-foos`` property, and this property is marked required in the
binding:
.. code-block:: devicetree
bad-node {
compatible = "foo-company,bar-device";
};
Other ways nodes are matched to bindings
****************************************
If a node has more than one string in its ``compatible`` property, the build
system looks for compatible bindings in the listed order and uses the first
match.
Take this node as an example:
.. code-block:: devicetree
baz-device {
compatible = "foo-company,baz-device", "generic-baz-device";
};
The ``baz-device`` node would get matched to a binding with a ``compatible:
"generic-baz-device"`` line if the build system can't find a binding with a
``compatible: "foo-company,baz-device"`` line.
Nodes without compatible properties can be matched to bindings associated with
their parent nodes. These are called "child bindings". If a node describes
hardware on a bus, like I2C or SPI, then the bus type is also taken into
account when matching nodes to bindings. (See :ref:`dt-bindings-on-bus` for
details).
See :ref:`dt-zephyr-user` for information about a special node that doesn't
require any binding.
.. _dt-where-bindings-are-located:
Where bindings are located
**************************
Binding file names usually match their ``compatible:`` lines. For example, the
above example binding would be named :file:`foo-company,bar-device.yaml` by
convention.
The build system looks for bindings in :file:`dts/bindings`
subdirectories of the following places:
- the zephyr repository
- your :ref:`application source directory <application>`
- your :ref:`board directory <board_porting_guide>`
- any :ref:`shield directories <shields>`
- any directories manually included in the :ref:`DTS_ROOT <dts_root>`
CMake variable
- any :ref:`module <modules>` that defines a ``dts_root`` in its
:ref:`modules_build_settings`
The build system will consider any YAML file in any of these, including in any
subdirectories, when matching nodes to bindings. A file is considered YAML if
its name ends with ``.yaml`` or ``.yml``.
.. warning::
The binding files must be located somewhere inside the :file:`dts/bindings`
subdirectory of the above places.
For example, if :file:`my-app` is your application directory, then you must
place application-specific bindings inside :file:`my-app/dts/bindings`. So
:file:`my-app/dts/bindings/serial/my-company,my-serial-port.yaml` would be
found, but :file:`my-app/my-company,my-serial-port.yaml` would be ignored.
Part 3
한국어 전문 번역
Devicetree binding 소개
Devicetree node는 자신의 compatible property를 이용해 binding과 연결됩니다. Build configuration 단계에서 build system은 devicetree의 각 node와 일치하는 binding 파일을 찾습니다. 일치 항목을 찾으면 binding의 정보를 두 곳에 사용합니다. 첫째, node에 필요한 property와 값의 형식을 검증합니다. 둘째, C 코드가 node의 값을 읽을 수 있도록 macro를 생성합니다.
간단한 예제
다음 DTS node는 foo-company,bar-device라는 compatible과 정수 property num-foos를 가집니다.
/* Node in a DTS file */
bar-device {
compatible = "foo-company,bar-device";
num-foos = <3>;
};이 node와 일치하는 최소 YAML binding은 다음과 같습니다.
# A YAML binding matching the node
compatible: "foo-company,bar-device"
properties:
num-foos:
type: int
required: trueBuild system은 DTS의 compatible = "foo-company,bar-device"와 YAML의 compatible: "foo-company,bar-device"가 같으므로 두 항목을 연결합니다.
Build system이 binding으로 하는 일
Binding은 devicetree node의 유효성을 검사하고 devicetree 내용을 생성된 devicetree_generated.h 헤더로 변환하는 데 함께 쓰입니다. 위 예에서는 num-foos가 필수인지, 값 <3>이 올바른 정수 형식인지 검사합니다.
검증에 성공하면 num-foos 값을 나타내는 macro가 생성되고 그 macro는 정수 literal 3으로 확장됩니다. 따라서 이후 C용 Devicetree API에서 이 property 값을 읽을 수 있습니다.
반대로 다음 node는 같은 compatible을 사용하면서 필수 num-foos를 갖지 않으므로 build error를 일으킵니다.
bad-node {
compatible = "foo-company,bar-device";
};그 밖의 binding 연결 방식
한 node의 compatible에 문자열이 둘 이상 있으면 build system은 DTS에 적힌 순서대로 binding을 찾고 첫 번째 일치 항목을 사용합니다.
baz-device {
compatible = "foo-company,baz-device", "generic-baz-device";
};따라서 foo-company,baz-device 전용 binding을 찾지 못한 경우에만 generic-baz-device binding이 fallback으로 사용됩니다.
compatible이 없는 node도 parent node에 연결된 child binding으로 검증할 수 있습니다. Node가 I2C나 SPI 같은 bus 위의 hardware라면 binding을 찾을 때 bus 종류도 함께 고려합니다. 예외적으로 zephyr,user 특수 node는 binding을 요구하지 않습니다.
Binding 파일을 두는 위치
Binding 파일 이름은 관례상 compatible: 값과 같습니다. 예를 들어 앞의 binding은 foo-company,bar-device.yaml이라는 이름을 사용합니다.
Build system은 다음 위치의 dts/bindings 하위 디렉터리를 검색합니다.
- Zephyr repository
- Application source directory
- Board directory
- Shield directory
- CMake 변수
DTS_ROOT에 수동으로 넣은 directory - Build setting에서
dts_root를 정의한 Zephyr module
이 디렉터리와 모든 하위 디렉터리에서 이름이 .yaml 또는 .yml로 끝나는 파일을 binding 후보로 봅니다.
Source
출처
원문 파일의 단락, directive, 표, 코드, symbol, 경로는 영어 원문 영역에 그대로 보존했습니다.