DtbError

Enum DtbError 

Source
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 formats
  • MalformedHeader: File may be truncated or corrupted
  • InvalidToken: Specific node/property may be malformed
  • AlignmentError: 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.

Trait Implementations§

Source§

impl Clone for DtbError

Source§

fn clone(&self) -> DtbError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DtbError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DtbError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DtbError

Source§

fn eq(&self, other: &DtbError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DtbError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.