Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

3.5 Flattened Device Tree (DTB) Format

The Device Tree source text file (.dts) is formatted as plaintext, which is inefficient for the operating system to parse directly. Therefore, it must be compiled into a binary format (.dtb) using the Device Tree Compiler (dtc). This optimization flattens the source tree text into a structured binary payload commonly referred to as a "blob." During the boot sequence, the bootloader loads this binary blob alongside the kernel executable image into distinct regions of physical memory. Operating system device drivers parse this runtime memory block to resolve registered peripherals, device constraints, and low-level parameters, ensuring precise hardware initialization.

The DTB file features a strict, linear architectural topology consisting of a standardized file header followed by three sequential block modules: the memory reservation block, the structure block, and the strings block. The memory reservation block catalogs explicitly protected physical memory margins, providing an architecture-enforced mechanism to prevent user-space applications or general kernel allocations from corrupting critical software or hardware buffers. The structure block stores the actual hierarchical arrangement of the Device Tree; by executing a linear traversal across this module, the kernel reconstructs and accesses all nodes within the hardware tree. The strings block aggregates the explicit names of all properties utilized across the Device Tree into a single contiguous pool; individual nodes inside the structure block map to their textual property keys by maintaining numerical offset vectors pointing into this string database.

3.5.1 DTB File Header

The DTB file header occupies exactly 40 bytes of memory, divided into ten sequential 32-bit (4-byte) fields. The structural layout is mapped out in the following schematic:

Figure 3-2 DTB File Header

  • Magic Number: A constant signature used by parsing routines to validate the payload as a definitive DTB structure. Its value is fixed to 0xD00DFEED and is encoded strictly in big-endian format.

  • Total Size: Defines the absolute linear length of the DTB payload in bytes, encompassing the 40-byte header block.

  • Offset to Structure Block: The explicit byte offset from the start of the file header to the baseline memory address hosting the structure block.

  • Offset to Strings Block: The explicit byte offset from the start of the file header to the baseline memory address hosting the strings block.

  • Offset to Memory Reservation Block: The explicit byte offset from the start of the file header to the baseline memory address hosting the memory reservation block.

  • Version Number: Specifies the version of the Device Tree Specification governing the compiled blob layout. The current baseline version tracks to 17.

  • Last Compatible Version: Defines the lowest historical specification version with which the current blob format maintains structural backward compatibility (typically fixed to version 16). Versions below 16 are deprecated and unparseable.

  • Boot CPU ID: Specifies the physical hardware index or core ID of the primary CPU core tasked with coordinating system boot routines. This value maps directly to the reg property assigned to that specific execution core under the /cpus tree path.

  • Size of Strings Block: The absolute linear width of the strings database module measured in bytes.

  • Size of Structure Block: The absolute linear width of the node structure module measured in bytes.

3.5.2 Memory Reservation Block

This module maintains an array of physical memory margins reserved for explicit use cases; all allocations specified within upstream memory-reserved nodes are consolidated here. The memory reservation layout is structured as an array of <physical_address region_size> coordinate pairs, where both the base address boundaries and length fields are stored as 64-bit unsigned integers. The following diagram shows the sequential binary formatting for a payload enclosing exactly three distinct memory isolation windows:

Figure 3-3 Memory Reservation Block Format

3.5.3 Structure Block Format

The structure block describes the actual topology and contents of the Device Tree, composed of a series of contiguous data fragments that are initialized via specific token markers. Each token identifier can be followed by a variable payload data segment whose structural formatting rules are governed entirely by the token class. The linear byte displacement linking any token back to the baseline origin of the structure block must be aligned precisely to a 32-bit (4-byte) word boundary. If a variable-length token sequence leaves a trailing address misaligned, compiler routines insert null-byte (0x00) padding to enforce explicit alignment.

The structure block relies on five primitive 32-bit token constants: FDT_BEGIN_NODE (0x00000001), FDT_END_NODE (0x00000002), FDT_PROP (0x00000003), FDT_NOP (0x00000004), and FDT_END (0x00000009).

  • FDT_BEGIN_NODE: Marks the structural initialization entry of a new Device Tree node. It is followed immediately by the node's name stored as a null-terminated ASCII string. If the node includes an explicit unit address identifier, the coordinate string is appended directly after the name block (e.g., name@address). A FDT_BEGIN_NODE token can accept any subsequent tokens except FDT_END_NODE. This allows a child node statement to open nested inside a parent block by injecting a nested FDT_BEGIN_NODE token sequence. The DTB architecture leverages this nesting rule to linearly map out the multi-dimensional tree topology.

  • FDT_END_NODE: Marks the termination boundary of the active node description block. It accepts no parameter arguments; the next contiguous byte region corresponds directly to the subsequent token.

  • FDT_PROP: Used to embed an explicit hardware attribute block into the active node context. It is followed by two mandatory 32-bit parameter words. The first word defines the payload length of the property data segment in bytes. The second word contains the numerical byte offset referencing the precise location of the attribute's text key inside the strings block. The raw property data payload is written directly after this second parameter word; its storage configuration within physical memory is detailed in the diagram below:

Figure 3-4 Storage Format of FDT_PROP in DTB

  • FDT_NOP: A structural no-operation marker. It carries no operational meaning and is skipped by kernel parsing engines.

  • FDT_END: Explicitly marks the termination of the entire structure block. The structure module must contain exactly one FDT_END token, which is required to reside at the absolute end of the block. The physical tracking layout of the structure block within memory is presented in the following schematic:

Figure 3-5 Storage Format of the Structure Block in DTB

Within the upstream Linux kernel source tree, the following C structural definitions describe the binary layout of the FDT_BEGIN_NODE header and the FDT_PROP components:
struct fdt_node_header {
	fdt32_t tag;
	char name[0];
};
struct fdt_property {
	fdt32_t tag;
	fdt32_t len;
	fdt32_t nameoff;
	char data[0];
};

3.5.4 Strings Block

The property names utilized across all hardware descriptors are structured as standard, null-terminated ASCII strings. The strings block is formed by concatenating these text keys sequentially into a contiguous memory pool. The baseline starting memory address allocated to store each discrete string identifier must be aligned to a 4-byte boundary.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com