fdt_rs/
spec.rs

1//! Definitions of structs and enums from the device tree specification.
2use endian_type::types::{u32_be, u64_be};
3use num_derive::FromPrimitive;
4
5/// Magic number used to denote the beginning of a device tree (as a native machine number).
6pub const FDT_MAGIC: u32 = 0xd00d_feed;
7/// Maximum length of a device tree node name (including null byte)
8pub const MAX_NODE_NAME_LEN: usize = 31;
9
10/// Definition of the parsed phandle as a native machine number
11pub type Phandle = u32;
12
13/// An enumeration of the tokens used to separate sections within the `dt_struct` section of the FDT.
14#[derive(FromPrimitive)]
15pub enum FdtTok {
16    BeginNode = 0x1,
17    EndNode = 0x2,
18    Prop = 0x3,
19    Nop = 0x4,
20    End = 0x9,
21}
22
23/// The `fdt_header` (Flattened Device Tree Header) as described by the specification
24#[repr(C)]
25pub struct fdt_header {
26    pub magic: u32_be,
27    pub totalsize: u32_be,
28    pub off_dt_struct: u32_be,
29    pub off_dt_strings: u32_be,
30    pub off_mem_rsvmap: u32_be,
31    pub version: u32_be,
32    pub last_comp_version: u32_be,
33    pub boot_cpuid_phys: u32_be,
34    pub size_dt_strings: u32_be,
35    pub size_dt_struct: u32_be,
36}
37
38/// The `fdt_prop_header` (Flattened Device Tree Property header) as described by the specification
39#[repr(C)]
40pub struct fdt_prop_header {
41    /// Length of the property data
42    pub len: u32_be,
43    /// Offset of the property name string within the dt_strings section
44    pub nameoff: u32_be,
45}
46
47#[repr(C)]
48pub struct fdt_reserve_entry {
49    /// Starting address of the reserved memory region
50    pub address: u64_be,
51    /// Size of the reserved memory region
52    pub size: u64_be,
53}