Skip to content

Commit

Permalink
Eliminate from_u32 with TryFrom<u32>; add todo about set_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
swenson committed Jan 30, 2025
1 parent 9b7e450 commit 0eade71
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
3 changes: 2 additions & 1 deletion drivers/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ impl<'a> Mmio for &DmaMmio<'a> {
let offset = src as usize;
let a = self.dma.read_dword(self.base + offset);
self.set_error(a.err());
T::from_u32(a.unwrap_or_default())
// try_into() will always succeed since we only support u32
a.unwrap_or_default().try_into().unwrap_or_default()
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/src/recovery_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl RecoveryFlow {
};
// [TODO][CAP2]: authenticate SoC manifest using keys available through Caliptra Image
// TODO: switch to ref_from method when we upgrade zerocopy
// [TODO][CAP2]: replace this copy with set_manifest
drivers
.persistent_data
.get_mut()
Expand Down
15 changes: 1 addition & 14 deletions ureg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ pub enum UintType {
U64,
}

pub trait Uint: Clone + Copy + TryInto<u32> + private::Sealed {
pub trait Uint: Clone + Copy + Default + TryInto<u32> + TryFrom<u32> + private::Sealed {
const TYPE: UintType;
fn from_u32(val: u32) -> Self;
}

mod private {
Expand All @@ -33,33 +32,21 @@ mod private {

impl Uint for u8 {
const TYPE: UintType = UintType::U8;
fn from_u32(val: u32) -> Self {
(val & 0xff) as u8
}
}
impl private::Sealed for u8 {}

impl Uint for u16 {
const TYPE: UintType = UintType::U16;
fn from_u32(val: u32) -> Self {
(val & 0xffff) as u16
}
}
impl private::Sealed for u16 {}

impl Uint for u32 {
const TYPE: UintType = UintType::U32;
fn from_u32(val: u32) -> Self {
val
}
}
impl private::Sealed for u32 {}

impl Uint for u64 {
const TYPE: UintType = UintType::U64;
fn from_u32(val: u32) -> Self {
val as u64
}
}
impl private::Sealed for u64 {}

Expand Down

0 comments on commit 0eade71

Please sign in to comment.