pub enum DtbError {
InvalidMagic,
MalformedHeader,
InvalidToken,
AlignmentError,
InvalidAddressCells(u32),
InvalidSizeCells(u32),
AddressTranslationError(u64),
InvalidRangesFormat,
TranslationCycle,
MaxTranslationDepthExceeded,
}
Expand description
Comprehensive error type for Device Tree Blob parsing operations.
Covers all possible failures during DTB parsing, from file format issues
to data alignment problems. All errors implement std::error::Error
when
the std
feature is enabled.
§Examples
let invalid_data = vec![0u8; 10]; // Too small for valid DTB
let parser = DeviceTreeParser::new(&invalid_data);
match parser.parse_header() {
Ok(header) => println!("Valid DTB with version {}", header.version),
Err(DtbError::InvalidMagic) => println!("File is not a valid DTB"),
Err(DtbError::MalformedHeader) => println!("DTB header is corrupted"),
Err(e) => println!("Other error: {}", e),
}
§Error Recovery
Some errors may be recoverable depending on use case:
InvalidMagic
: File is not a DTB, try other formatsMalformedHeader
: File may be truncated or corruptedInvalidToken
: Specific node/property may be malformedAlignmentError
: Data corruption or non-standard formatting
Variants§
InvalidMagic
Invalid magic number in DTB header (expected 0xd00dfeed).
This typically indicates that the file is not a valid Device Tree Blob, or the data is corrupted. The magic number is the first 4 bytes of every DTB file.
MalformedHeader
Malformed or corrupted DTB header structure.
The DTB header contains critical metadata about file layout. This error occurs when header fields contain invalid values, such as offsets pointing outside the file or impossibly large sizes.
InvalidToken
Invalid or unexpected token in the structure block.
The DTB structure block uses specific token values to represent nodes, properties, and tree structure. This error indicates corruption or non-standard formatting in the structure data.
AlignmentError
Data alignment error during parsing.
DTB format requires specific alignment for different data types. This error occurs when data is not properly aligned, typically indicating file corruption or truncation.
InvalidAddressCells(u32)
Invalid address cell specification.
Address cells must be between 1 and 4 (typically 1 or 2).
This error occurs when #address-cells
property contains an
invalid value outside this range.
InvalidSizeCells(u32)
Invalid size cell specification.
Size cells must be between 0 and 4 (typically 1 or 2).
This error occurs when #size-cells
property contains an
invalid value outside this range.
AddressTranslationError(u64)
Address translation error.
Occurs when an address cannot be translated between bus domains. This can happen when no matching range is found or when address arithmetic would overflow.
InvalidRangesFormat
Invalid ranges property format.
The ranges property must contain entries that are a multiple of
(child_address_cells
+ address_cells
+ size_cells
) * 4 bytes.
This error indicates malformed ranges data.
TranslationCycle
Translation cycle detected.
Occurs when multi-level address translation encounters a circular reference in the device tree hierarchy, which would cause infinite recursion.
MaxTranslationDepthExceeded
Maximum translation depth exceeded.
Occurs when multi-level address translation exceeds the maximum allowed recursion depth, preventing potential stack overflow.