← Zephyr Documents build/dts/intro-input-output.html · build/dts/intro-input-output.rst 공식 원문 ↗

Zephyr 3.7.0 · Build · Devicetree · Files

Devicetree 입력과 출력 파일

Board DTS가 include와 overlay, binding을 거쳐 최종 DTS와 C header가 되는 과정입니다.

Official pathbuild/dts/intro-input-output.html
Source filebuild/dts/intro-input-output.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

Part 1

요약·해설

공식 SVG 1개, 코드 2개, 네 입력 형식과 세 출력 파일, preprocessing·merge 우선순위를 보존했습니다.

Input

DTS · DTSI · overlay · YAML

Tools

dtlib · edtlib

Generate

gen_defines.py

Output

DTS · C header

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 55A905B9D29666A469D5CEE142A39A1F6757311C617A09EEB85FB9653017ABC5
.. _devicetree-in-out-files:

Input and output files
######################

This section describes the input and output files shown in the figure in
:ref:`devicetree-scope-purpose` in more detail.

.. figure:: ../../../../build/dts/zephyr_dt_inputs_outputs.svg
   :figclass: align-center

   Devicetree input (green) and output (yellow) files

.. _dt-input-files:

Input files
***********

There are four types of devicetree input files:

- sources (``.dts``)
- includes (``.dtsi``)
- overlays (``.overlay``)
- bindings (``.yaml``)

The devicetree files inside the :file:`zephyr` directory look like this:

.. code-block:: none

  boards/<ARCH>/<BOARD>/<BOARD>.dts
  dts/common/skeleton.dtsi
  dts/<ARCH>/.../<SOC>.dtsi
  dts/bindings/.../binding.yaml

Generally speaking, every supported board has a :file:`BOARD.dts` file
describing its hardware. For example, the ``reel_board`` has
:zephyr_file:`boards/phytec/reel_board/reel_board.dts`.

:file:`BOARD.dts` includes one or more ``.dtsi`` files. These ``.dtsi`` files
describe the CPU or system-on-chip Zephyr runs on, perhaps by including other
``.dtsi`` files. They can also describe other common hardware features shared by
multiple boards. In addition to these includes, :file:`BOARD.dts` also describes
the board's specific hardware.

The :file:`dts/common` directory contains :file:`skeleton.dtsi`, a minimal
include file for defining a complete devicetree. Architecture-specific
subdirectories (:file:`dts/<ARCH>`) contain ``.dtsi`` files for CPUs or SoCs
which extend :file:`skeleton.dtsi`.

The C preprocessor is run on all devicetree files to expand macro references,
and includes are generally done with ``#include <filename>`` directives, even
though DTS has a ``/include/ "<filename>"`` syntax.

:file:`BOARD.dts` can be extended or modified using *overlays*. Overlays are
also DTS files; the :file:`.overlay` extension is just a convention which makes
their purpose clear. Overlays adapt the base devicetree for different purposes:

- Zephyr applications can use overlays to enable a peripheral that is disabled
  by default, select a sensor on the board for an application specific purpose,
  etc. Along with :ref:`kconfig`, this makes it possible to reconfigure the
  kernel and device drivers without modifying source code.

- Overlays are also used when defining :ref:`shields`.

The build system automatically picks up :file:`.overlay` files stored in
certain locations. It is also possible to explicitly list the overlays to
include, via the :makevar:`DTC_OVERLAY_FILE` CMake variable. See
:ref:`set-devicetree-overlays` for details.

The build system combines :file:`BOARD.dts` and any :file:`.overlay` files by
concatenating them, with the overlays put last. This relies on DTS syntax which
allows merging overlapping definitions of nodes in the devicetree. See
:ref:`dt_k6x_example` for an example of how this works (in the context of
``.dtsi`` files, but the principle is the same for overlays). Putting the
contents of the :file:`.overlay` files last allows them to override
:file:`BOARD.dts`.

:ref:`dt-bindings` (which are YAML files) are essentially glue. They describe
the contents of devicetree sources, includes, and overlays in a way that allows
the build system to generate C macros usable by device drivers and
applications. The :file:`dts/bindings` directory contains bindings.

.. _dt-scripts:

Scripts and tools
*****************

The following libraries and scripts, located in :zephyr_file:`scripts/dts/`,
create output files from input files. Their sources have extensive
documentation.

:zephyr_file:`dtlib.py <scripts/dts/python-devicetree/src/devicetree/dtlib.py>`
    A low-level DTS parsing library.

:zephyr_file:`edtlib.py <scripts/dts/python-devicetree/src/devicetree/edtlib.py>`
    A library layered on top of dtlib that uses bindings to interpret
    properties and give a higher-level view of the devicetree. Uses dtlib to do
    the DTS parsing.

:zephyr_file:`gen_defines.py <scripts/dts/python-devicetree/src/devicetree/edtlib.py>`
    A script that uses edtlib to generate C preprocessor macros from the
    devicetree and bindings.

In addition to these, the standard ``dtc`` (devicetree compiler) tool is run on
the final devicetree if it is installed on your system. This is just to catch
errors or warnings. The output is unused. Boards may need to pass ``dtc``
additional flags, e.g. for warning suppression. Board directories can contain a
file named :file:`pre_dt_board.cmake` which configures these extra flags, like
this:

.. code-block:: cmake

   list(APPEND EXTRA_DTC_FLAGS "-Wno-simple_bus_reg")

.. _dt-outputs:

Output files
************

These are created in your application's build directory.

.. warning::

   Don't include the header files directly. :ref:`dt-from-c` explains
   what to do instead.

:file:`<build>/zephyr/zephyr.dts.pre`
   The preprocessed DTS source. This is an intermediate output file, which is
   input to :file:`gen_defines.py` and used to create :file:`zephyr.dts` and
   :file:`devicetree_generated.h`.

:file:`<build>/zephyr/include/generated/zephyr/devicetree_generated.h`
   The generated macros and additional comments describing the devicetree.
   Included by ``devicetree.h``.

:file:`<build>/zephyr/zephyr.dts`
   The final merged devicetree. This file is output by :file:`gen_defines.py`.
   It is useful for debugging any issues. If the devicetree compiler ``dtc`` is
   installed, it is also run on this file, to catch any additional warnings or
   errors.

Part 3

한국어 전문 번역

입력과 출력 파일

다음 공식 도식은 Devicetree 입력 파일을 녹색, build가 만드는 출력 파일을 노란색으로 구분합니다.

Zephyr Devicetree 입력 파일과 출력 파일
Devicetree 입력(녹색)과 출력(노란색) 파일

입력 파일

Devicetree 입력에는 네 종류가 있습니다.

  • Source .dts
  • Include .dtsi
  • Overlay .overlay
  • Binding .yaml

Zephyr tree의 대표 경로는 다음과 같습니다.

boards/<ARCH>/<BOARD>/<BOARD>.dts
dts/common/skeleton.dtsi
dts/<ARCH>/.../<SOC>.dtsi
dts/bindings/.../binding.yaml

일반적으로 지원 board마다 hardware를 설명하는 BOARD.dts가 있습니다. 예를 들어 reel_board는 boards/phytec/reel_board/reel_board.dts를 사용합니다.

BOARD.dts는 하나 이상의 .dtsi를 include합니다. 이 파일들은 Zephyr가 실행될 CPU나 SoC를 설명하고 다시 다른 dtsi를 포함할 수 있으며, 여러 board가 공유하는 hardware도 기술합니다. Board 전용 hardware는 BOARD.dts가 덧붙입니다.

dts/common/skeleton.dtsi는 완전한 devicetree를 구성하기 위한 최소 골격입니다. Architecture별 dts/<ARCH>의 CPU·SoC dtsi가 이를 확장합니다.

모든 devicetree 입력은 C preprocessor를 거쳐 macro reference를 확장합니다. DTS 자체의 /include/ "filename" 문법도 있지만 Zephyr에서는 보통 #include <filename>을 사용합니다.

Overlay

Overlay는 BOARD.dts를 확장하거나 수정하는 DTS 파일이며 .overlay 확장자는 용도를 드러내는 관례입니다. Application은 기본 disabled peripheral을 enable하거나 특정 sensor를 application 용도로 선택할 수 있습니다. Kconfig와 함께 source code를 고치지 않고 kernel과 driver 구성을 바꿀 수 있고 shield 정의에도 사용합니다.

Build system은 정해진 위치의 overlay를 자동 검색하고, CMake DTC_OVERLAY_FILE로 명시 목록도 받을 수 있습니다. BOARD.dts 뒤에 overlay를 이어 붙여 겹치는 node 정의를 DTS merge semantics로 합치므로 뒤의 overlay가 board 기본값을 덮어씁니다.

Binding

YAML binding은 source·include·overlay의 내용을 build system이 이해하게 하는 접착층입니다. 이를 이용해 driver와 application이 쓸 C macro를 생성하며 파일은 dts/bindings에 있습니다.

Script와 tool

  • dtlib.py: 저수준 DTS parsing library
  • edtlib.py: dtlib 위에서 binding으로 property 의미를 해석하고 더 높은 수준의 tree view를 제공
  • gen_defines.py: edtlib 결과에서 C preprocessor macro 생성

System에 표준 Devicetree compiler dtc가 있으면 최종 tree에 추가로 실행해 error와 warning을 찾습니다. 그 출력은 사용하지 않습니다. Board가 warning suppression 등의 flag를 더해야 하면 board directory의 pre_dt_board.cmake에서 다음처럼 설정합니다.

list(APPEND EXTRA_DTC_FLAGS "-Wno-simple_bus_reg")

출력 파일

  • <build>/zephyr/zephyr.dts.pre: preprocessing된 중간 DTS. gen_defines.py의 입력이며 최종 DTS와 header 생성에 사용
  • <build>/zephyr/include/generated/zephyr/devicetree_generated.h: 생성 macro와 tree 설명 comment. devicetree.h가 내부에서 include
  • <build>/zephyr/zephyr.dts: gen_defines.py가 출력한 최종 merged tree. Debugging에 유용하고 dtc가 있으면 추가 검사 대상

Source

출처

원문 파일의 단락, directive, 표, 코드, symbol, 경로는 영어 원문 영역에 그대로 보존했습니다.