use core::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum DtbError {
InvalidMagic,
MalformedHeader,
InvalidToken,
AlignmentError,
InvalidAddressCells(u32),
InvalidSizeCells(u32),
AddressTranslationError(u64),
InvalidRangesFormat,
TranslationCycle,
MaxTranslationDepthExceeded,
}
impl fmt::Display for DtbError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DtbError::InvalidMagic => write!(f, "Invalid magic number in DTB header"),
DtbError::MalformedHeader => write!(f, "Malformed DTB header structure"),
DtbError::InvalidToken => write!(f, "Invalid token in structure block"),
DtbError::AlignmentError => write!(f, "Data alignment error"),
DtbError::InvalidAddressCells(cells) => {
write!(f, "Invalid #address-cells value: {cells} (must be 1-4)")
}
DtbError::InvalidSizeCells(cells) => {
write!(f, "Invalid #size-cells value: {cells} (must be 0-4)")
}
DtbError::AddressTranslationError(addr) => {
write!(f, "Cannot translate address 0x{addr:x}")
}
DtbError::InvalidRangesFormat => {
write!(f, "Invalid ranges property format")
}
DtbError::TranslationCycle => {
write!(f, "Translation cycle detected in device tree hierarchy")
}
DtbError::MaxTranslationDepthExceeded => {
write!(f, "Maximum translation depth exceeded")
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for DtbError {}