From e7a2c97ca3409dcaefd07569861b2cc6106b47c2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 29 Apr 2025 22:32:59 +0800 Subject: [PATCH] some progress on compatibility --- services/pddb/Cargo.toml | 14 ++++++++++++-- services/pddb/src/backend/hw.rs | 5 ++++- services/pddb/src/lib.rs | 4 +++- services/pddb/src/main.rs | 27 ++++++++++++--------------- services/pddb/src/ux.rs | 5 ++++- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/services/pddb/Cargo.toml b/services/pddb/Cargo.toml index fb62d206d..0add0ea46 100644 --- a/services/pddb/Cargo.toml +++ b/services/pddb/Cargo.toml @@ -37,6 +37,8 @@ subtle = { version = "2.4.1", default-features = false } tts-frontend = { path = "../tts", optional = true } rand_core = "0.6.4" cram-hal-service = { path = "../cram-hal-service", optional = true } +cramium-emu = { path = "../cramium-emu", optional = true } +cramium-api = { path = "../../libs/cramium-api", optional = true } # passwords sha2 = { version = "0.10.8" } @@ -52,6 +54,7 @@ blowfish = { version = "0.9.1", features = ["bcrypt"] } gam = { path = "../gam", optional = true } locales = { path = "../../locales", optional = true } modals = { path = "../modals", optional = true } +ux-api = { path = "../../libs/ux-api", optional = true, features = ["std"] } utralib = { version = "0.1.25", optional = true, default-features = false } @@ -71,6 +74,13 @@ precursor = ["utralib/precursor", "sha2/precursor", "gen1"] hosted = ["utralib/hosted", "sha2/hosted", "gen1"] renode = ["utralib/renode", "sha2/renode", "gen1"] cramium-soc = ["utralib/cramium-soc", "gen2", "cram-hal-service"] +hosted-baosec = [ + "gen2", + "modals/hosted-baosec", + "cramium-emu", + "ux-api/hosted-baosec", + "cramium-api", +] # gen1 PDDB pulls in the graphical libraries for direct capture of passwords # from users. This gives maximum control over the flow of sensitive password data, @@ -95,9 +105,9 @@ gen1 = [ ] # gen-2 features -gen2 = [] +gen2 = ["locales", "modals"] # gen-2 boards -board-baosec = [] +board-baosec = ["ux-api/board-baosec", "cramium-api"] # when selected, physical disk addresses are set to 64 bits, otherwise, they are 32 bits. # 32 bit addressing is recommended for Precursor, as its disk is only 128MiB and it has limited RAM for bookkeeping. diff --git a/services/pddb/src/backend/hw.rs b/services/pddb/src/backend/hw.rs index da26ed03a..b55161c81 100644 --- a/services/pddb/src/backend/hw.rs +++ b/services/pddb/src/backend/hw.rs @@ -15,7 +15,8 @@ use aes::{Aes256, BLOCK_SIZE, Block}; use aes_gcm_siv::aead::{Aead, Payload}; use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag}; use backend::bcrypt::*; -#[cfg(feature = "gen1")] +#[cfg(not(any(feature = "hosted-baosec", feature = "board-baosec")))] +use gam::modal::*; use modals::Modals; #[cfg(feature = "gen1")] use root_keys::api::AesRootkeyType; @@ -24,6 +25,8 @@ use root_keys::api::KeywrapError; use sha2::{Digest, Sha512_256Hw, Sha512_256Sw}; use spinor::SPINOR_BULK_ERASE_SIZE; use subtle::ConstantTimeEq; +#[cfg(any(feature = "hosted-baosec", feature = "board-baosec"))] +use ux_api::widgets::*; use crate::*; diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index 2e5cd8429..ab662824d 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -21,8 +21,10 @@ use core::ops::DerefMut; use std::cell::RefCell; use std::convert::TryInto; -#[cfg(feature = "gen2")] +#[cfg(all(feature = "gen2", feature = "cramium-soc"))] use cram_hal_service::trng; +#[cfg(all(feature = "gen2", feature = "hosted-baosec"))] +use cramium_emu::trng; #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] pub enum CbOp { diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 9161e480d..ce6976b7f 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -366,10 +366,8 @@ mod api; use api::*; mod backend; use backend::*; -#[cfg(feature = "gen1")] mod ux; use rkyv::with::Identity; -#[cfg(feature = "gen1")] use ux::*; #[cfg(feature = "gen1")] mod menu; @@ -403,8 +401,10 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; -#[cfg(feature = "gen1")] +#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))] +use gam::*; use locales::t; +use modals::Modals; use num_traits::*; use rkyv::{ Archive, Place, Serialize, @@ -413,6 +413,8 @@ use rkyv::{ ser::{Positional, allocator::SubAllocator, writer::Buffer as RkyvBuffer}, with::{ArchiveWith, SerializeWith}, }; +#[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))] +use ux_api::widgets::*; use xous::{Message, msg_blocking_scalar_unpack, send_message}; use xous_ipc::Buffer; @@ -509,16 +511,12 @@ fn wrapped_main() -> ! { let entropy = Rc::new(RefCell::new(TrngPool::new())); // for less-secured user prompts (everything but password entry) - #[cfg(feature = "gen1")] - let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); + let modals = Modals::new(&xns).expect("can't connect to Modals server"); // our very own password modal. Password modals are precious and privately owned, to avoid // other processes from crafting them. - #[cfg(feature = "gen1")] let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler"); - #[cfg(feature = "gen1")] let pw_cid = xous::connect(pw_sid).expect("couldn't connect to the password UX handler"); - #[cfg(feature = "gen1")] let pw_handle = thread::spawn({ // this comment keeps rustfmt from flattening this block move || password_ux_manager(xous::connect(pddb_sid).unwrap(), pw_sid) @@ -726,13 +724,10 @@ fn wrapped_main() -> ! { // retries. // If we need more nuance out of this routine, consider creating a custom public enum type to help // marshall this. - #[cfg(feature = "gen2")] - Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { - unimplemented!(); - }), - #[cfg(feature = "gen1")] Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { + #[cfg(feature = "gen1")] let llio = llio::Llio::new(&xns); + #[cfg(feature = "gen1")] while !llio.is_ec_ready() { // spin-wait while the EC is not ready -- so that a PDDB mount does not interfere with // on-going EC updates. Also causes the mount dialog to delay until the EC status has been @@ -746,7 +741,9 @@ fn wrapped_main() -> ! { // can't mount if we have no root keys log::info!("{}PDDB.SKIPMOUNT,{}", xous::BOOKEND_START, xous::BOOKEND_END); // allow the main menu to be used in this case + #[cfg(feature = "gen1")] let gam = gam::Gam::new(&xns).unwrap(); + #[cfg(feature = "gen1")] gam.allow_mainmenu().expect("couldn't allow main menu activation"); xous::return_scalar2(msg.sender, 1, 0).expect("could't return scalar"); } else { @@ -816,7 +813,9 @@ fn wrapped_main() -> ! { } // get a handle to the GAM and inform it that main menu should be allowed. The handle // is dropped when this routine finishes. + #[cfg(feature = "gen1")] let gam = gam::Gam::new(&xns).unwrap(); + #[cfg(feature = "gen1")] gam.allow_mainmenu().expect("couldn't allow main menu activation"); // setup the heap initial_heap = heap_usage(); @@ -2346,7 +2345,6 @@ fn wrapped_main() -> ! { xous::terminate_process(0) } -#[cfg(feature = "gen1")] fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous::CID) -> PasswordState { log::info!("Requesting login password"); loop { @@ -2407,7 +2405,6 @@ fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous: } } -#[cfg(feature = "gen1")] fn try_mount_or_format( modals: &modals::Modals, pddb_os: &mut PddbOs, diff --git a/services/pddb/src/ux.rs b/services/pddb/src/ux.rs index dbcfe92ad..0765cd892 100644 --- a/services/pddb/src/ux.rs +++ b/services/pddb/src/ux.rs @@ -1,6 +1,9 @@ +#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))] use gam::modal::*; use locales::t; use num_traits::*; +#[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))] +use ux_api::widgets::*; use xous::msg_scalar_unpack; use xous::{CID, SID}; use xous_ipc::Buffer; @@ -116,7 +119,7 @@ pub(crate) fn password_ux_manager( } Some(PwManagerOpcode::PwReturn) => { let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let pw = buf.to_original::().unwrap(); + let pw = buf.to_original::().unwrap(); if let Some(mut response) = dr.take() { let mut buffer = unsafe {