LinuxCommandLibrary

dtc

Compile device tree source files

TLDR

Compile a device tree source .dts file into a binary device tree blob .dtb file

$ dtc -I dts -O dtb -o [path/to/output_file.dtb] [path/to/input_file.dts]
copy

Compile a device tree source .dts file into a binary device tree blob overlay .dtbo file
$ dtc -@ -I dts -O dtb -o [path/to/output_file.dtbo] [path/to/input_file.dts]
copy

Decompile a device tree blob .dtb file into a readable device tree source .dts file
$ dtc -I dtb -O dts -o [path/to/output_file.dts] [path/to/input_file.dtb]
copy

Decompile the current device tree from the system into a readable device tree source .dts file
$ dtc -I fs -O dts /proc/device-tree
copy

SYNOPSIS

dtc [options] input_file

PARAMETERS

-I
    Specifies the input format. Common formats include dts (Device Tree Source), dtb (Device Tree Blob), fs (Flattened Structure), dts.txt (plain text DTS).

-O
    Specifies the output format. Common formats include dtb (Device Tree Blob), dts (Device Tree Source), asm (assembly code).

-o
    Specifies the name of the output file. If not provided, dtc prints to standard output.

-b
    Output boot_cpuid_phys property for a given CPU ID. Used for creating dtb files for specific CPUs in a multi-CPU system.

-f
    Force overwrite of the output file if it already exists.

-R
    Add a reserve map entry, useful for specifying memory regions for bootloaders.

-S
    Pad the output .dtb file to a minimum size of bytes.

-p
    Pad the output .dtb file to a multiple of bytes (e.g., a page size).

-v
    Prints the dtc version information and exits.

-V
    Sets the verbosity level for output messages. Higher levels provide more detailed information.

-H
    Set the maximum header output level (for warnings and errors).

-s
    Sort nodes and properties in the output DTS for consistent formatting.

-W
    Enable or disable specific warnings by name (e.g., -W no-superfluous-labels).

-E
    Enable or disable specific errors by name (e.g., -E no-unit-address-vs-reg).

-d
    Generate a dependency file similar to gcc -M, listing all included files.

-@
    Add an __symbols__ node to the output .dtb, mapping labels to their paths. Useful for debugging and tools.

DESCRIPTION

The dtc (Device Tree Compiler) command is a crucial utility in the Linux ecosystem, especially for embedded systems development. It serves as a bridge between the human-readable Device Tree Source (.dts) files and the binary Device Tree Blob (.dtb) format that the Linux kernel consumes at boot time.

A Device Tree is a data structure used to describe hardware components of a system that are not discoverable by the operating system, such as interrupt controllers, GPIOs, and peripheral devices. This abstraction allows the kernel to be more generic, reducing the need for hardcoded board-specific information within the kernel source itself.

dtc can compile a .dts file into a .dtb file, which is then passed to the kernel by the bootloader. Conversely, it can decompile a binary .dtb file back into its source .dts representation, which is invaluable for debugging, analysis, or reverse-engineering existing Device Trees.

It supports various input and output formats beyond just .dts and .dtb, including .dts.txt (raw text) and .fs (flattened structure).

CAVEATS

dtc is primarily a developer tool used in the context of embedded Linux kernel development. It is not a command typically used by general Linux users for system administration or daily tasks.

Understanding its use requires familiarity with Device Trees and the specifics of hardware description. Incorrect usage or malformed Device Tree source can lead to unbootable systems or hardware not being recognized correctly by the kernel.

DEVICE TREE FORMATS

dtc supports several input and output formats:
Input: dts (Device Tree Source), dtb (Device Tree Blob), fs (Flattened Structure), dts.txt (plain text DTS, useful for debugging).
Output: dtb (binary blob for kernel), dts (source form for human readability), asm (assembly code for the blob).

ROLE IN EMBEDDED SYSTEMS

For embedded Linux, dtc is indispensable. It allows hardware designers and kernel developers to describe complex board layouts and peripheral configurations in a standardized, external data structure. This greatly simplifies the process of porting the Linux kernel to new hardware platforms, as board-specific code is replaced by a simple .dtb file loaded at boot.

HISTORY

The dtc utility emerged as an essential component of the Linux kernel's Device Tree project. The concept of Device Trees originated with Open Firmware and gained significant traction in the Linux kernel starting with ARM architecture support, where it became a mandatory part of the ARM boot process from kernel version 3.7 onwards. dtc was developed to manage the compilation and decompilation of these critical hardware description files, evolving alongside the Device Tree Specification to support new features and address complexities in hardware representation.

SEE ALSO

make(1), kexec(8), device-tree(7), bootloader (e.g., U-Boot, GRUB, often loads .dtb)

Copied to clipboard