mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
Merge pull request #642 from betrusted-io/pddb-hosted-debug
Pddb hosted debug
This commit is contained in:
commit
6083c8e70c
17 changed files with 179 additions and 74 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -343,6 +343,8 @@ dependencies = [
|
||||||
"num-derive 0.4.2",
|
"num-derive 0.4.2",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"pddb",
|
"pddb",
|
||||||
|
"rand 0.8.5",
|
||||||
|
"rand_chacha 0.3.1",
|
||||||
"usb-cramium",
|
"usb-cramium",
|
||||||
"utralib 0.1.25",
|
"utralib 0.1.25",
|
||||||
"ux-api",
|
"ux-api",
|
||||||
|
|
|
||||||
6
libs/cramium-hal/src/board/hosted.rs
Normal file
6
libs/cramium-hal/src/board/hosted.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
pub const SPINOR_PAGE_LEN: u32 = 0x100;
|
||||||
|
pub const SPINOR_ERASE_SIZE: u32 = 0x1000; // this is the smallest sector size.
|
||||||
|
pub const SPINOR_BULK_ERASE_SIZE: u32 = 0x1_0000; // this is the bulk erase size.
|
||||||
|
pub const SPINOR_LEN: u32 = 16384 * 1024;
|
||||||
|
pub const PDDB_LOC: u32 = 0;
|
||||||
|
pub const PDDB_LEN: u32 = 4096 * 1024; // 4MiB data for the PDDB total
|
||||||
|
|
@ -20,3 +20,7 @@ pub use baosor::*;
|
||||||
pub mod dabao;
|
pub mod dabao;
|
||||||
#[cfg(any(feature = "board-dabao", feature = "loader-dabao"))]
|
#[cfg(any(feature = "board-dabao", feature = "loader-dabao"))]
|
||||||
pub use dabao::*;
|
pub use dabao::*;
|
||||||
|
#[cfg(feature = "hosted-baosec")]
|
||||||
|
pub mod hosted;
|
||||||
|
#[cfg(feature = "hosted-baosec")]
|
||||||
|
pub use hosted::*;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,30 @@
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
#[cfg(feature = "axp2101")]
|
#[cfg(feature = "axp2101")]
|
||||||
pub mod axp2101;
|
pub mod axp2101;
|
||||||
pub mod board;
|
pub mod board;
|
||||||
#[cfg(feature = "camera-gc2145")]
|
#[cfg(feature = "camera-gc2145")]
|
||||||
pub mod gc2145;
|
pub mod gc2145;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod ifram;
|
pub mod ifram;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod iox;
|
pub mod iox;
|
||||||
#[cfg(feature = "camera-ov2640")]
|
#[cfg(feature = "camera-ov2640")]
|
||||||
pub mod ov2640;
|
pub mod ov2640;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod sce;
|
pub mod sce;
|
||||||
#[cfg(feature = "display-sh1107")]
|
#[cfg(feature = "display-sh1107")]
|
||||||
pub mod sh1107;
|
pub mod sh1107;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod shared_csr;
|
pub mod shared_csr;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod udma;
|
pub mod udma;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod usb;
|
pub mod usb;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub use shared_csr::*;
|
pub use shared_csr::*;
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
pub mod mbox;
|
pub mod mbox;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ modals = { path = "../modals", default-features = false }
|
||||||
ux-api = { path = "../../libs/ux-api", optional = true }
|
ux-api = { path = "../../libs/ux-api", optional = true }
|
||||||
pddb = { path = "../pddb", features = ["gen2"] }
|
pddb = { path = "../pddb", features = ["gen2"] }
|
||||||
|
|
||||||
|
# pddb testing
|
||||||
|
rand = { version = "0.8.5", features = ["getrandom"], optional = true }
|
||||||
|
rand_chacha = { version = "0.3.1", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
cramium-soc = [
|
cramium-soc = [
|
||||||
"utralib/cramium-soc",
|
"utralib/cramium-soc",
|
||||||
|
|
@ -41,11 +45,12 @@ hosted-baosec = [
|
||||||
"usb-cramium/hosted-baosec",
|
"usb-cramium/hosted-baosec",
|
||||||
"cramium-emu",
|
"cramium-emu",
|
||||||
"pddb/hosted-baosec",
|
"pddb/hosted-baosec",
|
||||||
|
"cramium-hal/hosted-baosec",
|
||||||
]
|
]
|
||||||
usb = []
|
usb = []
|
||||||
pddbtest = []
|
pddbtest = []
|
||||||
test-rekey = []
|
test-rekey = []
|
||||||
autobasis = []
|
autobasis = ["rand_chacha", "rand"]
|
||||||
modal-testing = ["ux-api", "modals/modal-testing"]
|
modal-testing = ["ux-api", "modals/modal-testing"]
|
||||||
test-scrollbars = []
|
test-scrollbars = []
|
||||||
default = []
|
default = ["pddbtest"]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use String;
|
use String;
|
||||||
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
const PDDB_A_LEN: usize = cramium_emu::PDDB_LEN as usize;
|
const PDDB_A_LEN: usize = cramium_hal::board::PDDB_LEN as usize;
|
||||||
|
|
||||||
use crate::{CommonEnv, ShellCmdApi};
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
|
|
@ -1184,7 +1184,7 @@ impl<'a> ShellCmdApi<'a> for PddbCmd {
|
||||||
for i in 0..20 {
|
for i in 0..20 {
|
||||||
let mut testkey = self
|
let mut testkey = self
|
||||||
.pddb
|
.pddb
|
||||||
.get("wlan.networks", "testkey", None, false, true, None, None::<fn()>)
|
.get("wlan.networks", "testkey", None, true, true, None, None::<fn()>)
|
||||||
.expect("couldn't make test key");
|
.expect("couldn't make test key");
|
||||||
testdata.push_str(&i.to_string());
|
testdata.push_str(&i.to_string());
|
||||||
// testkey.seek(SeekFrom::Start(0)).ok();
|
// testkey.seek(SeekFrom::Start(0)).ok();
|
||||||
|
|
@ -1249,3 +1249,53 @@ fn join_tokens<'a>(buf: &mut String, tokens: impl Iterator<Item = &'a str>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
|
enum VectorType {
|
||||||
|
Small(usize),
|
||||||
|
Large(usize),
|
||||||
|
Junk,
|
||||||
|
}
|
||||||
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
|
const SMALL_SIZE: usize = 2011;
|
||||||
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
|
const LARGE_SIZE: usize = 28813;
|
||||||
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
|
const JUNK_SIZE: usize = 128 * 1024 - 2;
|
||||||
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
|
fn make_vector(basis_number: usize, vtype: VectorType) -> Vec<u8> {
|
||||||
|
use rand::prelude::*;
|
||||||
|
use rand_chacha::ChaCha8Rng;
|
||||||
|
|
||||||
|
let mut vector = Vec::<u8>::new();
|
||||||
|
// seed format:
|
||||||
|
// bottom 0xFFFF is reserved for the basis_number
|
||||||
|
// next 0xFFF is resrved for the vector number
|
||||||
|
// 0x8000_0000 when set means small, not set means large
|
||||||
|
let typemod = match vtype {
|
||||||
|
VectorType::Small(n) => 0x1_0000 * (n as u64) + 0x8000_0000,
|
||||||
|
VectorType::Large(n) => 0x1_0000 * (n as u64) + 0x0000_0000,
|
||||||
|
VectorType::Junk => 0x1_0000_000,
|
||||||
|
};
|
||||||
|
let mut rng = ChaCha8Rng::seed_from_u64(basis_number as u64 + typemod);
|
||||||
|
match vtype {
|
||||||
|
VectorType::Small(n) => {
|
||||||
|
// multiply the vector number by some odd value so the vectors are not same-sized
|
||||||
|
for _ in 0..SMALL_SIZE + 7 * n + basis_number {
|
||||||
|
vector.push(rng.gen());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VectorType::Large(n) => {
|
||||||
|
// multiply the vector number by some odd value so the vectors are not same-sized
|
||||||
|
for _ in 0..LARGE_SIZE + 1117 * n + basis_number {
|
||||||
|
vector.push(rng.gen());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VectorType::Junk => {
|
||||||
|
for _ in 0..JUNK_SIZE + basis_number {
|
||||||
|
vector.push(rng.gen());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vector
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,19 +70,26 @@ fn main() {
|
||||||
log::set_max_level(log::LevelFilter::Debug);
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
modals::tests::spawn_test();
|
modals::tests::spawn_test();
|
||||||
}
|
}
|
||||||
use cramium_api::I2cApi;
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
let mut i2c = cram_hal_service::I2c::new();
|
{
|
||||||
use cramium_hal::axp2101::*;
|
use cramium_api::I2cApi;
|
||||||
let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)];
|
let mut i2c = cram_hal_service::I2c::new();
|
||||||
let mut buf = [0u8, 0u8];
|
use cramium_hal::axp2101::*;
|
||||||
loop {
|
let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)];
|
||||||
tt.sleep_ms(2_000).ok();
|
let mut buf = [0u8, 0u8];
|
||||||
for (name, offset) in measurements {
|
loop {
|
||||||
i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap();
|
tt.sleep_ms(2_000).ok();
|
||||||
let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32;
|
for (name, offset) in measurements {
|
||||||
log::info!("{}: {:0.3}V", name, v as f32 / 1000.0);
|
i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap();
|
||||||
i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap();
|
let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32;
|
||||||
log::info!("SOC: {}%", buf[0]);
|
log::info!("{}: {:0.3}V", name, v as f32 / 1000.0);
|
||||||
|
i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap();
|
||||||
|
log::info!("SOC: {}%", buf[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "hosted-baosec")]
|
||||||
|
loop {
|
||||||
|
tt.sleep_ms(2_000).ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,3 @@ pub mod i2c;
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod trng;
|
pub mod trng;
|
||||||
pub mod udma;
|
pub mod udma;
|
||||||
|
|
||||||
pub const SPINOR_PAGE_LEN: u32 = 0x100;
|
|
||||||
pub const SPINOR_ERASE_SIZE: u32 = 0x1000; // this is the smallest sector size.
|
|
||||||
pub const SPINOR_BULK_ERASE_SIZE: u32 = 0x1_0000; // this is the bulk erase size.
|
|
||||||
pub const SPINOR_LEN: u32 = 16384 * 1024;
|
|
||||||
pub const PDDB_LOC: u32 = 4096 * 1024; // located 4MiB in, after the swap image
|
|
||||||
pub const PDDB_LEN: u32 = 4096 * 1024; // 4MiB data for the PDDB total
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ impl Keystore {
|
||||||
Message::new_blocking_scalar(Opcode::GetDna.to_usize().unwrap(), 0, 0, 0, 0),
|
Message::new_blocking_scalar(Opcode::GetDna.to_usize().unwrap(), 0, 0, 0, 0),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if let xous::Result::Scalar5(val1, val2, _, _, _) = response {
|
if let xous::Result::Scalar5(_, val1, val2, _, _) = response {
|
||||||
(val1 as u64) | ((val2 as u64) << 32)
|
(val1 as u64) | ((val2 as u64) << 32)
|
||||||
} else {
|
} else {
|
||||||
panic!("get_dna() failed with internal error");
|
panic!("get_dna() failed with internal error");
|
||||||
|
|
@ -71,7 +71,10 @@ impl Keystore {
|
||||||
self.conn,
|
self.conn,
|
||||||
Message::new_blocking_scalar(Opcode::EnsurePassword.to_usize().unwrap(), 0, 0, 0, 0),
|
Message::new_blocking_scalar(Opcode::EnsurePassword.to_usize().unwrap(), 0, 0, 0, 0),
|
||||||
) {
|
) {
|
||||||
Ok(xous::Result::Scalar5(arg1, arg2, arg3, _arg4, _arg5)) => (arg1, arg2, arg3).into(),
|
Ok(xous::Result::Scalar5(_arg0, arg1, arg2, arg3, _arg4)) => {
|
||||||
|
log::info!("got {:x}, {:x}, {:x}", arg1, arg2, arg3);
|
||||||
|
(arg1, arg2, arg3).into()
|
||||||
|
}
|
||||||
_ => panic!("ensure_password() failed with internal error"),
|
_ => panic!("ensure_password() failed with internal error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ pub fn keystore(sid: SID) -> ! {
|
||||||
AesOpType::Encrypt => AesOpType::Encrypt,
|
AesOpType::Encrypt => AesOpType::Encrypt,
|
||||||
};
|
};
|
||||||
let mut ikm = [0u8; 32];
|
let mut ikm = [0u8; 32];
|
||||||
hex::encode_to_slice(WELL_KNOWN_KEY, &mut ikm).unwrap();
|
ikm.copy_from_slice(&hex::decode(WELL_KNOWN_KEY).unwrap());
|
||||||
let hk = Hkdf::<Sha256>::new(None, &ikm);
|
let hk = Hkdf::<Sha256>::new(None, &ikm);
|
||||||
let mut okm = [0u8; 32];
|
let mut okm = [0u8; 32];
|
||||||
hk.expand(&aes_op.domain.as_bytes(), &mut okm)
|
hk.expand(&aes_op.domain.as_bytes(), &mut okm)
|
||||||
|
|
@ -68,7 +68,7 @@ pub fn keystore(sid: SID) -> ! {
|
||||||
}
|
}
|
||||||
Opcode::AesKwp => {
|
Opcode::AesKwp => {
|
||||||
let mut ikm = [0u8; 32];
|
let mut ikm = [0u8; 32];
|
||||||
hex::encode_to_slice(WELL_KNOWN_KEY, &mut ikm).unwrap();
|
ikm.copy_from_slice(&hex::decode(WELL_KNOWN_KEY).unwrap());
|
||||||
let mut buffer =
|
let mut buffer =
|
||||||
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
let mut kwp = buffer.to_original::<KeyWrapper, _>().unwrap();
|
let mut kwp = buffer.to_original::<KeyWrapper, _>().unwrap();
|
||||||
|
|
@ -149,8 +149,8 @@ pub fn keystore(sid: SID) -> ! {
|
||||||
Opcode::GetDna => {
|
Opcode::GetDna => {
|
||||||
// dummy DNA value
|
// dummy DNA value
|
||||||
if let Some(scalar) = msg.body.scalar_message_mut() {
|
if let Some(scalar) = msg.body.scalar_message_mut() {
|
||||||
scalar.arg1 = 0x1234_5678;
|
scalar.arg1 = 0;
|
||||||
scalar.arg2 = 0xface_cafe;
|
scalar.arg2 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::InvalidCall => {
|
Opcode::InvalidCall => {
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ hosted-baosec = [
|
||||||
"gen2",
|
"gen2",
|
||||||
"cramium-emu",
|
"cramium-emu",
|
||||||
"modals/hosted-baosec",
|
"modals/hosted-baosec",
|
||||||
|
"cramium-hal/hosted-baosec",
|
||||||
] # emulated hardware on x86 platform
|
] # emulated hardware on x86 platform
|
||||||
board-baosor = [
|
board-baosor = [
|
||||||
"gen2",
|
"gen2",
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,23 @@ pub(crate) const PDDB_VERSION: u32 = 0x00_00_02_01;
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// PDDB_A_LEN may be shorter than xous::PDDB_LEN, to speed up testing.
|
// PDDB_A_LEN may be shorter than xous::PDDB_LEN, to speed up testing.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(not(any(feature = "pddbtest", feature = "autobasis", feature = "ci", feature = "smalldb")))]
|
#[cfg(all(
|
||||||
|
not(any(feature = "pddbtest", feature = "autobasis", feature = "ci", feature = "smalldb")),
|
||||||
|
not(feature = "gen2")
|
||||||
|
))]
|
||||||
pub(crate) const PDDB_A_LEN: usize = xous::PDDB_LEN as usize;
|
pub(crate) const PDDB_A_LEN: usize = xous::PDDB_LEN as usize;
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(any(feature = "pddbtest", feature = "autobasis", feature = "ci", feature = "smalldb"))]
|
#[cfg(all(
|
||||||
|
any(feature = "pddbtest", feature = "autobasis", feature = "ci", feature = "smalldb"),
|
||||||
|
not(feature = "gen2")
|
||||||
|
))]
|
||||||
pub const PDDB_A_LEN: usize = 4 * 1024 * 1024;
|
pub const PDDB_A_LEN: usize = 4 * 1024 * 1024;
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
pub const PDDB_A_LEN: usize = cramium_hal::board::PDDB_LEN as usize;
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
|
pub const PDDB_A_LOC: u32 = xous::PDDB_LOC as u32;
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
pub const PDDB_A_LOC: u32 = cramium_hal::board::PDDB_LOC as u32;
|
||||||
|
|
||||||
/// range for the starting point of a journal number, picked from a random seed
|
/// range for the starting point of a journal number, picked from a random seed
|
||||||
/// the goal is to reduce info leakage about the age of structures relative to each other
|
/// the goal is to reduce info leakage about the age of structures relative to each other
|
||||||
|
|
@ -163,7 +175,7 @@ pub(crate) enum Opcode {
|
||||||
#[cfg(not(target_os = "xous"))]
|
#[cfg(not(target_os = "xous"))]
|
||||||
DangerousDebug = 25,
|
DangerousDebug = 25,
|
||||||
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
#[cfg(all(feature = "pddbtest", feature = "autobasis"))]
|
||||||
BasisTesting = 26,
|
BasisTesting = 65536,
|
||||||
|
|
||||||
ListBasisStd = 26,
|
ListBasisStd = 26,
|
||||||
CreateBasisStd = 27,
|
CreateBasisStd = 27,
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ impl HostedSpinor {
|
||||||
|
|
||||||
pub fn bulk_erase(&self, start: u32, len: u32) -> Result<(), xous::Error> {
|
pub fn bulk_erase(&self, start: u32, len: u32) -> Result<(), xous::Error> {
|
||||||
for b in flashmem().memory.as_mut_slice()
|
for b in flashmem().memory.as_mut_slice()
|
||||||
[(start - xous::PDDB_LOC) as usize..(start - xous::PDDB_LOC + len) as usize]
|
[(start - PDDB_A_LOC) as usize..(start - PDDB_A_LOC + len) as usize]
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
{
|
{
|
||||||
*b = 0xFF;
|
*b = 0xFF;
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ use aes::{Aes256, BLOCK_SIZE, Block};
|
||||||
use aes_gcm_siv::aead::{Aead, Payload};
|
use aes_gcm_siv::aead::{Aead, Payload};
|
||||||
use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag};
|
use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag};
|
||||||
use backend::bcrypt::*;
|
use backend::bcrypt::*;
|
||||||
#[cfg(all(feature = "gen2", feature = "cramium-emu"))]
|
#[cfg(all(feature = "gen2"))]
|
||||||
use cramium_emu::{SPINOR_BULK_ERASE_SIZE, SPINOR_ERASE_SIZE};
|
|
||||||
#[cfg(all(feature = "gen2", not(feature = "cramium-emu")))]
|
|
||||||
use cramium_hal::board::{SPINOR_BULK_ERASE_SIZE, SPINOR_ERASE_SIZE};
|
use cramium_hal::board::{SPINOR_BULK_ERASE_SIZE, SPINOR_ERASE_SIZE};
|
||||||
#[cfg(feature = "gen1")]
|
#[cfg(feature = "gen1")]
|
||||||
use keystore_api::AesRootkeyType;
|
use keystore_api::AesRootkeyType;
|
||||||
|
|
@ -28,6 +26,7 @@ use sha2::{Digest, Sha512_256Hw, Sha512_256Sw};
|
||||||
use spinor::{SPINOR_BULK_ERASE_SIZE, SPINOR_ERASE_SIZE};
|
use spinor::{SPINOR_BULK_ERASE_SIZE, SPINOR_ERASE_SIZE};
|
||||||
use subtle::ConstantTimeEq;
|
use subtle::ConstantTimeEq;
|
||||||
|
|
||||||
|
use crate::api::PDDB_A_LOC;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[cfg(not(feature = "deterministic"))]
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
|
@ -208,7 +207,7 @@ impl PddbOs {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
#[cfg(any(feature = "precursor", feature = "renode"))]
|
#[cfg(any(feature = "precursor", feature = "renode"))]
|
||||||
let pddb = xous::syscall::map_memory(
|
let pddb = xous::syscall::map_memory(
|
||||||
xous::MemoryAddress::new(xous::PDDB_LOC as usize + xous::FLASH_PHYS_BASE as usize),
|
xous::MemoryAddress::new(PDDB_A_LOC as usize + xous::FLASH_PHYS_BASE as usize),
|
||||||
None,
|
None,
|
||||||
PDDB_A_LEN as usize,
|
PDDB_A_LEN as usize,
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::RESERVE,
|
xous::MemoryFlags::R | xous::MemoryFlags::RESERVE,
|
||||||
|
|
@ -428,7 +427,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
&data,
|
&data,
|
||||||
offset + self.data_phys_base.as_u32(),
|
offset + self.data_phys_base.as_u32(),
|
||||||
)
|
)
|
||||||
|
|
@ -452,7 +451,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
&mbbb,
|
&mbbb,
|
||||||
self.pt_phys_base.as_u32() + erased_offset,
|
self.pt_phys_base.as_u32() + erased_offset,
|
||||||
)
|
)
|
||||||
|
|
@ -490,7 +489,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
&blank,
|
&blank,
|
||||||
self.pt_phys_base.as_u32() + base_page as u32,
|
self.pt_phys_base.as_u32() + base_page as u32,
|
||||||
)
|
)
|
||||||
|
|
@ -507,12 +506,7 @@ impl PddbOs {
|
||||||
"attempt to patch past page table end"
|
"attempt to patch past page table end"
|
||||||
);
|
);
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(unsafe { self.pddb_mr.as_slice() }, PDDB_A_LOC, &data, self.pt_phys_base.as_u32() + offset)
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
|
||||||
xous::PDDB_LOC,
|
|
||||||
&data,
|
|
||||||
self.pt_phys_base.as_u32() + offset,
|
|
||||||
)
|
|
||||||
.expect("couldn't write to page table");
|
.expect("couldn't write to page table");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -523,12 +517,7 @@ impl PddbOs {
|
||||||
);
|
);
|
||||||
log::info!("patching keys area with {} bytes", data.len());
|
log::info!("patching keys area with {} bytes", data.len());
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(unsafe { self.pddb_mr.as_slice() }, PDDB_A_LOC, data, self.key_phys_base.as_u32() + offset)
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
|
||||||
xous::PDDB_LOC,
|
|
||||||
data,
|
|
||||||
self.key_phys_base.as_u32() + offset,
|
|
||||||
)
|
|
||||||
.expect("couldn't burn keys");
|
.expect("couldn't burn keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -537,7 +526,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
data,
|
data,
|
||||||
self.mbbb_phys_base.as_u32() + offset,
|
self.mbbb_phys_base.as_u32() + offset,
|
||||||
)
|
)
|
||||||
|
|
@ -551,7 +540,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
data,
|
data,
|
||||||
self.fscb_phys_base.as_u32() + offset,
|
self.fscb_phys_base.as_u32() + offset,
|
||||||
)
|
)
|
||||||
|
|
@ -807,7 +796,10 @@ impl PddbOs {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gen2")]
|
#[cfg(feature = "gen2")]
|
||||||
pub(crate) fn ensure_password(&self) -> PasswordState { self.rootkeys.ensure_password() }
|
pub(crate) fn ensure_password(&mut self) -> PasswordState {
|
||||||
|
self.rootkeys.ensure_password();
|
||||||
|
self.try_login()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn try_login(&mut self) -> PasswordState {
|
pub(crate) fn try_login(&mut self) -> PasswordState {
|
||||||
use aes::cipher::KeyInit;
|
use aes::cipher::KeyInit;
|
||||||
|
|
@ -2098,27 +2090,27 @@ impl PddbOs {
|
||||||
modals
|
modals
|
||||||
.start_progress(
|
.start_progress(
|
||||||
t!("pddb.erase", locales::LANG),
|
t!("pddb.erase", locales::LANG),
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
xous::PDDB_LOC + PDDB_A_LEN as u32,
|
PDDB_A_LOC + PDDB_A_LEN as u32,
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
)
|
)
|
||||||
.expect("couldn't raise progress bar");
|
.expect("couldn't raise progress bar");
|
||||||
// retain this delay, because the next section is so compute-intensive, it may take a
|
// retain this delay, because the next section is so compute-intensive, it may take a
|
||||||
// while for the GAM to catch up.
|
// while for the GAM to catch up.
|
||||||
self.tt.sleep_ms(100).unwrap();
|
self.tt.sleep_ms(100).unwrap();
|
||||||
}
|
}
|
||||||
for offset in (xous::PDDB_LOC..(xous::PDDB_LOC + PDDB_A_LEN as u32))
|
for offset in
|
||||||
.step_by(SPINOR_BULK_ERASE_SIZE as usize)
|
(PDDB_A_LOC..(PDDB_A_LOC + PDDB_A_LEN as u32)).step_by(SPINOR_BULK_ERASE_SIZE as usize)
|
||||||
{
|
{
|
||||||
if (offset / SPINOR_BULK_ERASE_SIZE) % 4 == 0 {
|
if (offset / SPINOR_BULK_ERASE_SIZE) % 4 == 0 {
|
||||||
log::info!("Initial erase: {}/{}", offset - xous::PDDB_LOC, PDDB_A_LEN as u32);
|
log::info!("Initial erase: {}/{}", offset - PDDB_A_LOC, PDDB_A_LEN as u32);
|
||||||
if let Some(modals) = progress {
|
if let Some(modals) = progress {
|
||||||
modals.update_progress(offset as u32).expect("couldn't update progress bar");
|
modals.update_progress(offset as u32).expect("couldn't update progress bar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do a blank check first to see if the sector really needs erasing
|
// do a blank check first to see if the sector really needs erasing
|
||||||
let mut blank = true;
|
let mut blank = true;
|
||||||
let slice_start = (offset - xous::PDDB_LOC) as usize / size_of::<u32>();
|
let slice_start = (offset - PDDB_A_LOC) as usize / size_of::<u32>();
|
||||||
for word in unsafe {
|
for word in unsafe {
|
||||||
self.pddb_mr.as_slice::<u32>()
|
self.pddb_mr.as_slice::<u32>()
|
||||||
[slice_start..slice_start + SPINOR_BULK_ERASE_SIZE as usize / size_of::<u32>()]
|
[slice_start..slice_start + SPINOR_BULK_ERASE_SIZE as usize / size_of::<u32>()]
|
||||||
|
|
@ -2134,9 +2126,7 @@ impl PddbOs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(modals) = progress {
|
if let Some(modals) = progress {
|
||||||
modals
|
modals.update_progress(PDDB_A_LOC + PDDB_A_LEN as u32).expect("couldn't update progress bar");
|
||||||
.update_progress(xous::PDDB_LOC + PDDB_A_LEN as u32)
|
|
||||||
.expect("couldn't update progress bar");
|
|
||||||
modals.finish_progress().expect("couldn't dismiss progress bar");
|
modals.finish_progress().expect("couldn't dismiss progress bar");
|
||||||
#[cfg(feature = "ux-swap-delay")]
|
#[cfg(feature = "ux-swap-delay")]
|
||||||
self.tt.sleep_ms(100).unwrap();
|
self.tt.sleep_ms(100).unwrap();
|
||||||
|
|
@ -2332,7 +2322,7 @@ impl PddbOs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(unsafe { self.pddb_mr.as_slice() }, xous::PDDB_LOC, &temp, offset as u32)
|
.patch(unsafe { self.pddb_mr.as_slice() }, PDDB_A_LOC, &temp, offset as u32)
|
||||||
.expect("couldn't fill in disk with random datax");
|
.expect("couldn't fill in disk with random datax");
|
||||||
}
|
}
|
||||||
if let Some(modals) = progress {
|
if let Some(modals) = progress {
|
||||||
|
|
@ -2503,7 +2493,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
unsafe { self.pddb_mr.as_slice() },
|
unsafe { self.pddb_mr.as_slice() },
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
&mbbb,
|
&mbbb,
|
||||||
self.pt_phys_base.as_u32() + erased_offset,
|
self.pt_phys_base.as_u32() + erased_offset,
|
||||||
)
|
)
|
||||||
|
|
@ -3087,7 +3077,7 @@ impl PddbOs {
|
||||||
pub(crate) fn pddb_get_all_keys<'a>(
|
pub(crate) fn pddb_get_all_keys<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
cache: &'a Vec<BasisCacheEntry>,
|
cache: &'a Vec<BasisCacheEntry>,
|
||||||
_op: GetKeyOp,
|
// _op: GetKeyOp,
|
||||||
) -> Option<Vec<(BasisKeys, String)>> {
|
) -> Option<Vec<(BasisKeys, String)>> {
|
||||||
// populate the "known" entries
|
// populate the "known" entries
|
||||||
let mut ret = Vec::<(BasisKeys, String)>::new();
|
let mut ret = Vec::<(BasisKeys, String)>::new();
|
||||||
|
|
@ -3240,7 +3230,7 @@ impl PddbOs {
|
||||||
self.spinor
|
self.spinor
|
||||||
.patch(
|
.patch(
|
||||||
self.pddb_mr.as_slice(),
|
self.pddb_mr.as_slice(),
|
||||||
xous::PDDB_LOC,
|
PDDB_A_LOC,
|
||||||
&page,
|
&page,
|
||||||
self.pt_phys_base.as_u32() + (page_index * PAGE_SIZE) as u32,
|
self.pt_phys_base.as_u32() + (page_index * PAGE_SIZE) as u32,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ impl DerefMut for Pte {
|
||||||
|
|
||||||
pub const PDDB_SIZE_PAGES: usize = crate::PDDB_A_LEN as usize / PAGE_SIZE;
|
pub const PDDB_SIZE_PAGES: usize = crate::PDDB_A_LEN as usize / PAGE_SIZE;
|
||||||
/// This structure is mapped into the top of FLASH memory, starting at
|
/// This structure is mapped into the top of FLASH memory, starting at
|
||||||
/// xous::PDDB_LOC. This actually slightly over-sizes the page table,
|
/// PDDB_A_LOC. This actually slightly over-sizes the page table,
|
||||||
/// because the page table does not map the locations for the page table
|
/// because the page table does not map the locations for the page table
|
||||||
/// itself, the MBBB, or the FSCB. However, the 0th entry of the page table
|
/// itself, the MBBB, or the FSCB. However, the 0th entry of the page table
|
||||||
/// always corresponds to the base of data in FLASH, which means the excess
|
/// always corresponds to the base of data in FLASH, which means the excess
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use core::mem::size_of;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use aes_gcm_siv::Nonce;
|
use aes_gcm_siv::Nonce;
|
||||||
#[cfg(feature = "cramium-hal")]
|
#[cfg(all(feature = "cramium-hal", not(feature = "hosted-baosec")))]
|
||||||
use cram_hal_service::trng::Trng;
|
use cram_hal_service::trng::Trng;
|
||||||
#[cfg(feature = "hosted-baosec")]
|
#[cfg(feature = "hosted-baosec")]
|
||||||
use cramium_emu::trng::Trng;
|
use cramium_emu::trng::Trng;
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ extern crate bitfield;
|
||||||
-[x] Rewrite pddb to use 'keystore' server instead of rootkeys/modals/ux integrations.
|
-[x] Rewrite pddb to use 'keystore' server instead of rootkeys/modals/ux integrations.
|
||||||
-[x] Fill in 'keystore' server for hosted mode emulation
|
-[x] Fill in 'keystore' server for hosted mode emulation
|
||||||
-[x] Make a simple PDDB test in the baosec console app
|
-[x] Make a simple PDDB test in the baosec console app
|
||||||
-[ ] Fix the bugs in hosted mode
|
-[x] Fix the bugs in hosted mode
|
||||||
-[ ] Rewrite xous-swapper/swap layer to understand virtual pages mapped to SPI flash (see notes below)
|
-[ ] Rewrite xous-swapper/swap layer to understand virtual pages mapped to SPI flash (see notes below)
|
||||||
-[ ] Fix the bugs in real hardware
|
-[ ] Fix the bugs in real hardware
|
||||||
|
|
||||||
|
|
@ -395,7 +395,7 @@ extern crate bitfield;
|
||||||
If the virtual address is in the magic range for SPINOR, the contents are fetched using the
|
If the virtual address is in the magic range for SPINOR, the contents are fetched using the
|
||||||
SPINOR interface based on the linear mapping of the lower bits of the address onto the SPINOR
|
SPINOR interface based on the linear mapping of the lower bits of the address onto the SPINOR
|
||||||
memory space.
|
memory space.
|
||||||
- WHnever a write happens inside Xous-Swapper to a location in FLASH, the page table entry for
|
- Whenever a write happens inside Xous-Swapper to a location in FLASH, the page table entry for
|
||||||
the mapped FLASH location needs to be marked as invalid and returned to the free pool. This
|
the mapped FLASH location needs to be marked as invalid and returned to the free pool. This
|
||||||
uses the swap system to keep the read-view of FLASH in sync with hte write-view. This also
|
uses the swap system to keep the read-view of FLASH in sync with hte write-view. This also
|
||||||
means that Xous-Swapper's SPINOR map has to keep a scoreboard of what pages are mapped to
|
means that Xous-Swapper's SPINOR map has to keep a scoreboard of what pages are mapped to
|
||||||
|
|
@ -405,6 +405,29 @@ extern crate bitfield;
|
||||||
tries to map the SPINOR and read some contents out, and perhaps update a sector. This will
|
tries to map the SPINOR and read some contents out, and perhaps update a sector. This will
|
||||||
exercise the path in isolation and allow us to test this routine as a separate primitive
|
exercise the path in isolation and allow us to test this routine as a separate primitive
|
||||||
from the PDDB.
|
from the PDDB.
|
||||||
|
|
||||||
|
- Development takes an incremental strategy:
|
||||||
|
1. Write the code that maps the proposed space with the proposed flags; need to implement
|
||||||
|
(a) "swap" flag which indicates the page is allocated in VM but not physically; and
|
||||||
|
(b) also make sure that the "dirty" flag is implemented correctly as it will actually
|
||||||
|
take on meaning for flushing pages to SPINOR
|
||||||
|
2. implement the kernel hooks to catch it, and test that
|
||||||
|
3. Attempt a read on the space, show the page fault, and hand-off to the swapper
|
||||||
|
4. implement the swapper hardware read interface
|
||||||
|
5. test reading to a range of data
|
||||||
|
6. implement the swapper *write* interface (with "patching" of unaligned writes)
|
||||||
|
7. add SwapOp to sync an in-memory page to FLASH
|
||||||
|
8. implement flush-on-release semantics for in-memory flash pages
|
||||||
|
9. test writing to a ranges of data (aligned, unaligned)
|
||||||
|
10. redo the 10 instances of spinor.patch() in pddb/backend/hw.rs to use straight-up
|
||||||
|
page writes as the method for writing. If we always sync after write, we can skip 11.
|
||||||
|
11. add swap flush call to the sync() method in PDDB
|
||||||
|
|
||||||
|
The merit of sync after write is we reduce the chance of inconsistent device state
|
||||||
|
on power loss. The downside is we end up writing a lot more? on the other hand,
|
||||||
|
writes aren't *that* common in this implementation, we may update a key record with
|
||||||
|
a timestamp every time it's accessed. Anyways, keep it flexible, I think this is
|
||||||
|
something we can tune later.
|
||||||
*/
|
*/
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue