diff --git a/services/jtag/src/api.rs b/services/jtag/src/api.rs index e5f2ae2dc..28dc20958 100644 --- a/services/jtag/src/api.rs +++ b/services/jtag/src/api.rs @@ -1,5 +1,8 @@ pub(crate) const SERVER_NAME_JTAG: &str = "_JTAG Server_"; +#[allow(dead_code)] +pub const XCS750_IDCODE: u32 = 0x362F093; + #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub struct EfuseRecord { pub key: [u8; 32], diff --git a/services/jtag/src/lib.rs b/services/jtag/src/lib.rs index 9166d1e39..a4514a964 100644 --- a/services/jtag/src/lib.rs +++ b/services/jtag/src/lib.rs @@ -101,6 +101,10 @@ impl Jtag { let erec = self.efuse_fetch().expect("couldn't read efuse record"); if (erec.cntl & 0x20) != 0 { Ok(true) } else { Ok(false) } } + pub fn get_raw_control_bits(&self) -> Result { + let erec = self.efuse_fetch().expect("couldn't read efuse record"); + Ok(erec.cntl) + } fn mod_ctl_efuse(&self, bits_to_set: u8) -> Result { let erec = self.efuse_fetch().expect("couldn't read efuse record"); let response = send_message(self.conn, diff --git a/services/root-keys/src/api.rs b/services/root-keys/src/api.rs index 9c2092fd7..aa4551d25 100644 --- a/services/root-keys/src/api.rs +++ b/services/root-keys/src/api.rs @@ -11,6 +11,10 @@ pub(crate) enum Opcode { KeysInitialized, /// check that the digital signature on the gateware CheckGatewareSignature, + /// check if the efuse has been locked down + IsEfuseSecured, + /// quick check to see if the JTAG can read its IDCODE + IsJtagWorking, TestUx, diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index e8c8e7ed5..dde1ee2c1 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -501,6 +501,31 @@ impl<'a> RootKeys { } pub fn kernel_base(&self) -> u32 { self.kernel_base } + /// returns None if there is an obvious problem with the JTAG interface + /// otherwise returns the result. "secured" would be the most paranoid setting + /// which is all the bits burned. There are other combinations that are also + /// totally valid based on your usage scenario, however, but the have yet to + /// be implemented (see the JTAG crate for more info); however, we reflect + /// all of the calls through rootkeys so we aren't exposing JTAG attack surface + /// to the rest of the world. + pub fn is_efuse_secured(&self) -> Option { + if self.jtag.get_id().unwrap() != jtag::XCS750_IDCODE { + return None; + } + if (self.jtag.get_raw_control_bits().expect("couldn't get control bits") & 0x3f) != 0x3F { + return Some(false) + } else { + return Some(true) + } + } + pub fn is_jtag_working(&self) -> bool { + if self.jtag.get_id().unwrap() == jtag::XCS750_IDCODE { + true + } else { + false + } + } + fn xns_interlock(&self) { loop { if self.xns.trusted_init_done().expect("couldn't query init done status") { diff --git a/services/root-keys/src/lib.rs b/services/root-keys/src/lib.rs index 5c2521dd5..6ed53b217 100644 --- a/services/root-keys/src/lib.rs +++ b/services/root-keys/src/lib.rs @@ -131,6 +131,37 @@ impl RootKeys { } } + pub fn is_efuse_secured(&self) -> Result, xous::Error> { + let response = send_message(self.conn, + Message::new_blocking_scalar(Opcode::IsEfuseSecured.to_usize().unwrap(), 0, 0, 0, 0) + )?; + if let xous::Result::Scalar1(result) = response { + if result == 2 { + Ok(None) + } else if result == 1 { + Ok(Some(true)) + } else { + Ok(Some(false)) + } + } else { + Err(xous::Error::InternalError) + } + } + pub fn is_jtag_working(&self) -> Result { + let response = send_message(self.conn, + Message::new_blocking_scalar(Opcode::IsJtagWorking.to_usize().unwrap(), 0, 0, 0, 0) + )?; + if let xous::Result::Scalar1(result) = response { + if result == 1 { + Ok(true) + } else { + Ok(false) + } + } else { + Err(xous::Error::InternalError) + } + } + pub fn test_ux(&mut self, arg: usize) { send_message(self.conn, Message::new_scalar(Opcode::TestUx.to_usize().unwrap(), diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index c9ffd26ea..9d79e3127 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -100,6 +100,8 @@ mod implementation { pub fn test(&mut self, rootkeys_modal: &mut Modal, main_cid: xous::CID) -> Result<(), RootkeyResult> { Ok(()) } + pub fn is_jtag_working(&self) -> bool {false} + pub fn is_efuse_secured(&self) -> Option {None} } } @@ -208,6 +210,24 @@ fn xmain() -> ! { xous::return_scalar(msg.sender, 0).unwrap(); } }), + Some(Opcode::IsEfuseSecured) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + if let Some(secured) = keys.is_efuse_secured() { + if secured { + xous::return_scalar(msg.sender, 1).unwrap(); + } else { + xous::return_scalar(msg.sender, 0).unwrap(); + } + } else { + xous::return_scalar(msg.sender, 2).unwrap(); + } + }), + Some(Opcode::IsJtagWorking) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + if keys.is_jtag_working() { + xous::return_scalar(msg.sender, 1).unwrap(); + } else { + xous::return_scalar(msg.sender, 0).unwrap(); + } + }), // UX flow opcodes Some(Opcode::UxTryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {