In this lesson, you will learn how to use the Device Tree Compiler (DTC) to convert human-readable source files into the machine-parseable binary format required by your bootloader.
The Bridge Between Source and Silicon
In previous lessons, we discussed how Device Tree Source (.dts) files describe your hardware topology—such as memory regions, GPIO pin mappings, and peripheral addresses. However, the bootloader (like U-Boot) cannot interpret this text file directly. It requires a compact, serialized format known as a Device Tree Blob (.dtb).
The conversion process is handled by the Device Tree Compiler (dtc). This tool performs syntax validation and resolves references (labels) between different parts of the tree, ensuring that the hardware description is consistent and ready for the Linux kernel to interpret at boot time.
Invoking the Compiler
While build systems like the Linux Kernel Makefile automate this, it is helpful to understand the manual invocation. You typically compile a .dts file into a .dtb using the following syntax:
dtc -I dts -O dtb -o my_board.dtb my_board.dts
-I dts: Specifies the input format as Device Tree Source.-O dtb: Specifies the output format as a Device Tree Blob.-o my_board.dtb: Defines the output filename.
If you have a binary blob and need to verify its contents, you can perform the reverse operation, known as "decompiling":
dtc -I dtb -O dts -o reconstructed.dts my_board.dtb
Why Binary Matters
The binary format is optimized for performance and size, which is critical during the initial boot sequence. Because the bootloader has limited memory and resources before the kernel is fully initialized, the flattened blob allows the bootloader to simply copy the memory region containing the .dtb and pass its address to the kernel entry point. The kernel then uses this structure to dynamically discover hardware at runtime without hard-coding board-specific details into the kernel binary itself.
Key Takeaway: The Device Tree Compiler (dtc) transforms human-readable .dts hardware descriptions into flattened, binary .dtb files, providing an efficient format for the bootloader to pass system configuration to the Linux kernel.