From 01d6c61bb6062892b683f60b5d33cc725f6bc189 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 3 Aug 2021 16:54:42 +0800 Subject: [PATCH] commit before merging main stuff want to capture in the libstd improvements before we get too much version drift --- Cargo.lock | 1 + services/root-keys/Cargo.toml | 1 + services/root-keys/src/implementation.rs | 15 +++++++++++++++ services/spinor/src/main.rs | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a9e3cd31..a8e048b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1640,6 +1640,7 @@ dependencies = [ "rand_core 0.5.1", "rkyv 0.4.3", "sha2", + "spinor", "susres", "ticktimer-server", "trng", diff --git a/services/root-keys/Cargo.toml b/services/root-keys/Cargo.toml index 5bcfa83fb..3f6e18d80 100644 --- a/services/root-keys/Cargo.toml +++ b/services/root-keys/Cargo.toml @@ -13,6 +13,7 @@ xous-names = { path = "../xous-names" } log = "0.4" susres = {path = "../susres"} trng = {path= "../trng"} +spinor = {path="../spinor"} xous-ipc = {path = "../../xous-ipc"} num-derive = {version = "0.3", default-features = false} diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index 7e2170fc9..86cc63e34 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -109,6 +109,7 @@ pub(crate) struct RootKeys { trng: trng::Trng, gam: gam::Gam, // for raising UX elements directly gfx: graphics_server::Gfx, // for reading out font planes for signing verification + spinor: spinor::Spinor, } impl RootKeys { @@ -160,6 +161,9 @@ impl RootKeys { xous::MemoryFlags::R | xous::MemoryFlags::W, ).expect("couldn't map sensitive data page"); + let spinor = spinor::Spinor::new(&xns).expect("couldn't connect to spinor server"); + spinor.register_soc_token().expect("couldn't register rootkeys as the one authorized writer to the gateware update area!"); + let keys = RootKeys { keyrom: CSR::new(keyrom.as_mut_ptr() as *mut u32), gateware, @@ -175,6 +179,7 @@ impl RootKeys { trng: trng::Trng::new(&xns).expect("couldn't connect to TRNG server"), gam: gam::Gam::new(&xns).expect("couldn't connect to GAM"), gfx: graphics_server::Gfx::new(&xns).expect("couldn't connect to gfx"), + spinor }; keys @@ -512,6 +517,12 @@ impl RootKeys { log::info!("Self public key: {:x?}", keypair.public.to_bytes()); self.debug_staging(); } + + // Because we're initializing keys for the *first* time, make a backup copy of the bitstream to + // the staging area. Note that if we're doing an update, the update target would already be + // in the staging area, so this step should be skipped. + self.make_gateware_backup(60, 70, progress_modal, progress_action); + // compute the keyrom patch set for the bitstream // at this point the KEYROM as replicated in sensitive_slice should have all its assets in place patch::should_patch(42); @@ -521,6 +532,10 @@ impl RootKeys { true } + fn make_gateware_backup(&mut self, prog_start: u32, prog_end: u32, progress_modal: &mut Modal, progress_action: &mut Slider) { + + } + #[cfg(feature = "hazardous-debug")] fn debug_staging(&self) { self.debug_print_key(KeyRomLocs::FPGA_KEY as usize, 256, "FPGA key: "); diff --git a/services/spinor/src/main.rs b/services/spinor/src/main.rs index fda2bfc50..4bd3a035b 100644 --- a/services/spinor/src/main.rs +++ b/services/spinor/src/main.rs @@ -536,10 +536,10 @@ fn xmain() -> ! { Here is the list of servers allowed to access, and why: - shellchat (for testing ONLY, remove once done) - suspend/resume (for suspend locking/unlocking calls) + - keystore - PDDB (not yet written) - - keystore (not yet written) */ - let spinor_sid = xns.register_name(api::SERVER_NAME_SPINOR, Some(2)).expect("can't register server"); + let spinor_sid = xns.register_name(api::SERVER_NAME_SPINOR, Some(3)).expect("can't register server"); log::trace!("registered with NS -- {:?}", spinor_sid); let handler_conn = xous::connect(spinor_sid).expect("couldn't create interrupt handler callback connection");