use thiserror::Error;
#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
pub enum StandardError {
#[error("error occurred when converting the property value: {0}")]
PropertyConversion(#[from] PropertyError),
#[error("Invalid status value")]
InvalidStatus,
#[error("/cpus node missing")]
CpusMissing,
#[error("/cpus/cpu node missing reg property")]
CpuMissingReg,
#[error("/memory node missing")]
MemoryMissing,
#[error("prop-encoded-array field too big for chosen type ({cells} cells)")]
TooManyCells {
cells: usize,
},
}
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[non_exhaustive]
#[error("{kind} at offset {offset}")]
pub struct FdtParseError {
offset: usize,
pub kind: FdtErrorKind,
}
impl FdtParseError {
pub(crate) fn new(kind: FdtErrorKind, offset: usize) -> Self {
Self { offset, kind }
}
}
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[non_exhaustive]
pub enum FdtErrorKind {
#[error("Invalid FDT magic number")]
InvalidMagic,
#[error("FDT version {0} is not supported")]
UnsupportedVersion(u32),
#[error("Invalid FDT length")]
InvalidLength,
#[error("FDT header has failed validation: {0}")]
InvalidHeader(&'static str),
#[error("Bad FDT token: {0:#x}")]
BadToken(u32),
#[error("Invalid offset in FDT")]
InvalidOffset,
#[error("Invalid string in FDT")]
InvalidString,
#[error("Memory reservation block was not terminated with a null entry")]
MemReserveNotTerminated,
#[error("Memory reservation block has an entry that is unaligned or has invalid size")]
MemReserveInvalid,
}
#[derive(Debug, Clone, Copy, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum PropertyError {
#[error("property has an invalid length")]
InvalidLength,
#[error("property is not a valid string")]
InvalidString,
#[error(
"prop-encoded-array property was {size} bytes, but should have been a multiple of {chunk} cells"
)]
PropEncodedArraySizeMismatch {
size: usize,
chunk: usize,
},
}