Addressing review comments.
This commit is contained in:
39
third_party/libtock-drivers/src/crp.rs
vendored
39
third_party/libtock-drivers/src/crp.rs
vendored
@@ -5,7 +5,35 @@ const DRIVER_NUMBER: usize = 0x00008;
|
||||
|
||||
mod command_nr {
|
||||
pub const AVAILABLE: usize = 0;
|
||||
pub const PROTECT: usize = 1;
|
||||
pub const GET_PROTECTION: usize = 1;
|
||||
pub const SET_PROTECTION: usize = 2;
|
||||
}
|
||||
|
||||
#[derive(PartialOrd, PartialEq)]
|
||||
pub enum ProtectionLevel {
|
||||
/// Unsupported feature
|
||||
Unknown = 0,
|
||||
/// This should be the factory default for the chip.
|
||||
NoProtection = 1,
|
||||
/// At this level, only JTAG/SWD are disabled but other debugging
|
||||
/// features may still be enabled.
|
||||
JtagDisabled = 2,
|
||||
/// This is the maximum level of protection the chip supports.
|
||||
/// At this level, JTAG and all other features are expected to be
|
||||
/// disabled and only a full chip erase may allow to recover from
|
||||
/// that state.
|
||||
FullyLocked = 0xff,
|
||||
}
|
||||
|
||||
impl From<usize> for ProtectionLevel {
|
||||
fn from(value: usize) -> Self {
|
||||
match value {
|
||||
1 => ProtectionLevel::NoProtection,
|
||||
2 => ProtectionLevel::JtagDisabled,
|
||||
0xff => ProtectionLevel::FullyLocked,
|
||||
_ => ProtectionLevel::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_available() -> TockResult<()> {
|
||||
@@ -13,7 +41,12 @@ pub fn is_available() -> TockResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn protect() -> TockResult<()> {
|
||||
syscalls::command(DRIVER_NUMBER, command_nr::PROTECT, 0, 0)?;
|
||||
pub fn get_protection() -> TockResult<ProtectionLevel> {
|
||||
let current_level = syscalls::command(DRIVER_NUMBER, command_nr::GET_PROTECTION, 0, 0)?;
|
||||
Ok(current_level.into())
|
||||
}
|
||||
|
||||
pub fn set_protection(level: ProtectionLevel) -> TockResult<()> {
|
||||
syscalls::command(DRIVER_NUMBER, command_nr::SET_PROTECTION, level as usize, 0)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user