DTB又称Flattened Devicetree(FDT),在内存中的结构如下图所示:
大端字节序结构体:
struct fdt_header { uint32_t magic; /* contain the value 0xd00dfeed (big-endian) */ uint32_t totalsize; /* the total size of the devicetree data structure */ uint32_t off_dt_struct; /* offset in bytes of the structure block */ uint32_t off_dt_strings; /* offset in bytes of the strings block */ uint32_t off_mem_rsvmap; /* offset in bytes of the memory reservation block */ uint32_t version; /* the version of the devicetree data structure */ uint32_t last_comp_version; /* the lowest version used is backwards compatible */ uint32_t boot_cpuid_phys; /* the physical ID of the system’s boot CPU */ uint32_t size_dt_strings; /* the length in bytes of the strings block */ uint32_t size_dt_struct; /* the length in bytes of the structure block */ }; Memory Reservation Block
Purpose
为系统保留一些特殊用途的memory。这些保留内存不会进入内存管理系统。
Format
struct fdt_reserve_entry { uint64_t address; uint64_t size; }; Structure BlockDevicetree结构体存放的位置。由一行行“token+内容”片段线性组成。
token
每一行内容都由一个32位的整形token起始。token指明了其后内容的属性及格式。共有以下5种token:
FDT_BEGIN_NODE (0x00000001) 节点起始,其后内容为节点名
FDT_END_NODE (0x00000002) 节点结束
FDT_PROP (0x00000003) 描述属性
FDT_NOP (0x00000004) nothing,devicetree解析器忽略它
FDT_END (0x00000009) block结束
tree structure
(optionally) any number of FDT_NOP tokens
FDT_BEGIN_NODE
The node’s name as a null-terminated string
[zeroed padding bytes to align to a 4-byte boundary]
For each property of the node:
(optionally) any number of FDT_NOP tokens
FDT_PROP token
property information
[zeroed padding bytes to align to a 4-byte boundary]
Representations of all child nodes in this format
(optionally) any number of FDT_NOP tokens
FDT_END_NODE token
Devicetree Source (DTS) Format Node and property definitions [label:] node-name[@unit-address] { [properties definitions] [child nodes] }; File layoutVersion 1 DTS files have the overall layout:
/dts-v1/; /* dts 版本1 */ [memory reservations] /* DTB中内存保留表的入口 */ / { [property definitions] [child nodes] };