mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add primitives to buram for storing slices
this is used by the key erase proof routine, but will be useful in general for storing data in the buram also, the ranges of slices are currently defined at the top of the file but might be moved somewhere more maintainable later. RRAM writing got bollards added to it, as RRAM write could be a glitch target: if a glitch could manipulate the address somehow to stick stuff at an arbitrary location, during write, that would be bad. However, it's probably also reasonably dangerous to try and glitch RRAM writes because there's a chance you spray over off-target items and thus trigger a signature check failure on your next boot.
This commit is contained in:
parent
09e68291cf
commit
15ac4d8529
3 changed files with 30 additions and 3 deletions
|
|
@ -6,6 +6,8 @@ const HASH_LOC: usize = 0;
|
|||
#[allow(dead_code)]
|
||||
const RESERVED_LOC: usize = 1;
|
||||
|
||||
pub const ERASURE_PROOF_RANGE_BYTES: Range<usize> = 0..32;
|
||||
|
||||
use crate::buram::murmur3::murmur3_32;
|
||||
|
||||
const fn range_len(r: Range<usize>) -> usize { r.end - r.start }
|
||||
|
|
@ -86,9 +88,28 @@ impl BackupManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn bu_ram_as_slice(&self) -> &[u8] { unsafe { self.bu_ram.as_slice() } }
|
||||
pub fn store_slice<T: Copy>(&mut self, input: &[T], byte_offset: usize) {
|
||||
let type_offset = byte_offset / size_of::<T>();
|
||||
// safety: safe because make_valid() is called after the slice is accessed
|
||||
let dest: &mut [T] = unsafe { &mut self.bu_ram_as_mut()[type_offset..type_offset + input.len()] };
|
||||
dest.copy_from_slice(&input);
|
||||
|
||||
pub fn bu_ram_as_mut(&mut self) -> &mut [u8] { unsafe { self.bu_ram.as_slice_mut() } }
|
||||
self.make_valid();
|
||||
}
|
||||
|
||||
pub fn get_slice<T>(&self, byte_range: core::ops::Range<usize>) -> &[T] {
|
||||
let type_offset = byte_range.start / size_of::<T>();
|
||||
let type_len = (byte_range.end - byte_range.start) / size_of::<T>();
|
||||
&self.bu_ram_as_slice()[type_offset..type_offset + type_len]
|
||||
}
|
||||
|
||||
pub fn bu_ram_as_slice<T>(&self) -> &[T] { unsafe { self.bu_ram.as_slice::<T>() } }
|
||||
|
||||
/// Safety: modifications to the backup RAM array need a follow-up call to `make_valid`
|
||||
/// in order for the boot check to pass.
|
||||
///
|
||||
/// Could try to get clever and implement a `Drop` trait which includes a make_valid() call? maybe?
|
||||
pub unsafe fn bu_ram_as_mut<T>(&mut self) -> &mut [T] { self.bu_ram.as_slice_mut::<T>() }
|
||||
}
|
||||
|
||||
pub mod murmur3 {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ impl Csprng {
|
|||
word.copy_from_slice(&ro_trng.get_raw().to_ne_bytes());
|
||||
}
|
||||
|
||||
crate::println!("seed: {:x?}", seed); // used to eyeball that things are working correctly
|
||||
// crate::println!("seed: {:x?}", seed); // used to eyeball that things are working correctly
|
||||
let mut csprng = ChaCha8Rng::from_seed(seed);
|
||||
|
||||
let entropy_bank = csprng.next_u64();
|
||||
|
|
|
|||
|
|
@ -188,8 +188,12 @@ impl<'a> Reram {
|
|||
assert!(data.len() % 8 == 0, "unaligned source data!");
|
||||
// crate::print!("@ {:x} > ", addr);
|
||||
for (outer, d) in data.chunks_exact(8).enumerate() {
|
||||
#[cfg(not(feature = "kernel"))]
|
||||
bao1x_api::bollard!(crate::sigcheck::die_no_std, 4);
|
||||
// write the data to the buffer
|
||||
for (inner, &datum) in d.iter().enumerate() {
|
||||
#[cfg(not(feature = "kernel"))]
|
||||
bao1x_api::bollard!(crate::sigcheck::die_no_std, 4);
|
||||
// crate::print!(" {:x}", datum);
|
||||
self.array
|
||||
.as_mut_ptr()
|
||||
|
|
@ -199,6 +203,8 @@ impl<'a> Reram {
|
|||
}
|
||||
// crate::println!("");
|
||||
|
||||
#[cfg(not(feature = "kernel"))]
|
||||
bao1x_api::bollard!(crate::sigcheck::die_no_std, 4);
|
||||
self.csr.rmwf(utra::rrc::SFR_RRCCR_SFR_RRCCR, RRC_CR_WRITE_CMD | SECURITY_MODE);
|
||||
self.array
|
||||
.as_mut_ptr()
|
||||
|
|
|
|||
Loading…
Reference in a new issue