#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Range {
pub name: &'static str,
pub start: usize,
pub len: usize,
}
impl Range {
pub const fn end(&self) -> usize {
self.start + self.len
}
pub fn of<'a>(&self, image: &'a [u8]) -> Option<&'a [u8]> {
image.get(self.start..self.end())
}
}
pub const IMAGE_SIZE: usize = 0x20_0000;
pub const BOOT_PAGE: Range = Range {
name: "boot page",
start: 0,
len: 0x400,
};
pub const BOOT_MIRROR: Range = Range {
name: "boot mirror",
start: 0x1_0000,
len: 0x400,
};
pub const BOOT_AREA: Range = Range {
name: "boot area",
start: 0,
len: 0x1000,
};
pub const CMAC_TABLE: Range = Range {
name: "integrity table",
start: 0x1_0400,
len: 16 * 28,
};
pub const BANNER: Range = Range {
name: "boot banner",
start: 0x3000,
len: 0x20,
};
pub const DESCRIPTOR: Range = Range {
name: "identity descriptor",
start: 0x1E_C000,
len: 0x100,
};
pub const UHD_REVOCATION: Range = Range {
name: "UHD revocation list",
start: 0x1D_8000,
len: 0x8000,
};
pub const BD_REVOCATION: Range = Range {
name: "BD revocation list",
start: 0x1E_0000,
len: 0x8000,
};
pub const SETTINGS: Range = Range {
name: "settings",
start: 0x1E_8000,
len: 0x4000,
};
pub const CALIBRATION: Range = Range {
name: "calibration",
start: 0x1F_0000,
len: 0x1_0000,
};
pub const DRIVE_WRITTEN: [Range; 4] = [UHD_REVOCATION, BD_REVOCATION, SETTINGS, CALIBRATION];
pub fn is_erased(bytes: &[u8]) -> bool {
bytes.iter().all(|&b| b == 0xFF)
}
#[cfg(test)]
#[path = "layout_tests.rs"]
mod tests;