Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 775 of 93611. Introduction to Embedded LinuxFree lesson

Configuring the Device Tree for Hardware Description

Master the use of Device Tree source files to communicate hardware configuration details to the kernel without recompiling the entire source.

In this lesson, you will learn how to use the Device Tree (DT) to decouple hardware configuration from kernel code, allowing you to describe system topology without recompiling the Linux kernel.

The Problem of Hardware Variation

In a bare-metal environment, hardware details like memory addresses, interrupt lines, and GPIO mappings are often hardcoded directly into your C source files. If you change a component—such as switching from an I2C sensor to a different model—you must recompile the entire binary. Embedded Linux solves this via the Device Tree, a data structure (passed to the kernel by the bootloader) that acts as a blueprint for the hardware.

Structuring the Device Tree

The Device Tree Source (.dts) file uses a tree-based hierarchy of nodes. Each node represents a hardware component, and properties within those nodes define its characteristics. For example, to describe a simple LED connected to a GPIO controller, you define the node like this:

leds {
    compatible = "gpio-leds";
    
    status_led {
        label = "system-status";
        gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
        linux,default-trigger = "heartbeat";
    };
};

In this snippet, the kernel reads the compatible property to determine which driver to bind to this node. The gpios property explicitly links the LED to a specific pin on gpio1. Because this information resides in an external file, you can modify the hardware layout or add peripherals simply by updating the .dts file and recompiling it into a binary blob (.dtb).

Why This Matters

By offloading hardware description to the Device Tree, you maintain a single, generic kernel image that can support multiple board variants. Instead of recompiling the kernel, you point the bootloader to a different .dtb file tailored to your specific hardware revision. This separation of concerns is essential for scaling production, as it keeps your software stack portable while reflecting the physical realities of your PCB design, such as pinmuxing and interrupt routing.

Key Takeaway: The Device Tree provides a hardware-agnostic way to describe system peripherals to the kernel, allowing you to update hardware configurations without recompiling the entire Linux operating system.