From b4b6fc2a49a7398a7bee8477bb07c61e46f653b0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jul 2022 05:01:36 +0800 Subject: [PATCH] unbreak hosted mode --- services/root-keys/src/api.rs | 1 + services/root-keys/src/implementation.rs | 9 +------- services/root-keys/src/main.rs | 27 ++++++++++++++++++++++++ services/status/src/ecup.rs | 12 +++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/services/root-keys/src/api.rs b/services/root-keys/src/api.rs index d9a7e9052..16b8d7cb8 100644 --- a/services/root-keys/src/api.rs +++ b/services/root-keys/src/api.rs @@ -254,6 +254,7 @@ pub const BACKUP_VERSION: u32 = 0x00_01_00_00; #[repr(u32)] #[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[allow(dead_code)] pub enum BackupOp { /// This is the value that's kept inside the BackupDataPt Archive = 0, diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index 55e816951..af6816dca 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -31,7 +31,7 @@ use aes::Aes256; use aes::cipher::{KeyInit, BlockDecrypt, BlockEncrypt}; use cipher::generic_array::GenericArray; -use crate::{SignatureResult, GatewareRegion, MetadataInFlash}; +use crate::{SignatureResult, GatewareRegion, MetadataInFlash, UpdateType}; use root_keys::key2bits::*; @@ -72,13 +72,6 @@ struct PasswordCache { fpga_key_valid: u32, } -#[derive(Eq, PartialEq)] -pub(crate) enum UpdateType { - Regular, - BbramProvision, - Restore, -} - #[repr(C)] struct SignatureInFlash { pub version: u32, diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index 15990c601..fa8b7c48d 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -48,6 +48,12 @@ pub enum GatewareRegion { Staging, } +#[derive(Eq, PartialEq)] +pub(crate) enum UpdateType { + Regular, + BbramProvision, + Restore, +} /// An "easily" parseable metadata structure in flash. There's nothing that guarantees the authenticity /// of the metadata in and of itself, other than the digital signature that wraps the entire gateware record. @@ -101,6 +107,8 @@ mod implementation { use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit, generic_array::GenericArray}; use std::convert::TryInto; use crate::UpdateType; + use xous_semver::SemVer; + use crate::backups; #[derive(Debug, Copy, Clone)] #[allow(dead_code)] @@ -135,6 +143,7 @@ mod implementation { } pub fn resume(&self) { } + pub fn pddb_recycle(&self) {} pub fn update_policy(&mut self, policy: Option) { log::info!("policy updated: {:?}", policy); @@ -333,6 +342,24 @@ mod implementation { } pub fn should_prompt_for_update(&self) -> bool {true} pub fn set_prompt_for_update(&self, _state: bool) {} + pub fn write_backup(&mut self, header: BackupHeader, backup_ct: backups::BackupDataCt) -> Result<(), xous::Error> { + log::info!("backup header: {:?}", header); + log::info!("backup ciphertext: {:x?}", backup_ct.as_ref()); + Ok(()) + } + pub fn read_backup(&mut self) -> Result<(BackupHeader, backups::BackupDataCt), xous::Error> { + Err(xous::Error::InternalError) + } + pub fn erase_backup(&mut self) {} + pub fn read_backup_header(&mut self) -> Option { + None + } + pub fn get_backup_key(&mut self) -> Option<(backups::BackupKey, backups::KeyRomExport)> { + None + } + pub fn is_zero_key(&self) -> Option { Some(true) } + pub fn setup_restore_init(&mut self, _key: backups::BackupKey, _rom: backups::KeyRomExport) { + } } } diff --git a/services/status/src/ecup.rs b/services/status/src/ecup.rs index 4b328e6c4..bcf88bbbb 100644 --- a/services/status/src/ecup.rs +++ b/services/status/src/ecup.rs @@ -73,19 +73,23 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) { xous::MemoryFlags::R | xous::MemoryFlags::W, ).expect("couldn't map EC wf200 package memory range"); #[cfg(not(any(target_os = "none", target_os = "xous")))] - let ec_package = xous::syscall::map_memory( + let mut ec_package = xous::syscall::map_memory( None, None, xous::EC_FW_PKG_LEN as usize, xous::MemoryFlags::R | xous::MemoryFlags::W, ).expect("couldn't map EC firmware package memory range"); #[cfg(not(any(target_os = "none", target_os = "xous")))] - let wf_package = xous::syscall::map_memory( + for d in ec_package.as_slice_mut::().iter_mut() { *d = 0xFF } // simulate blank flash + #[cfg(not(any(target_os = "none", target_os = "xous")))] + let mut wf_package = xous::syscall::map_memory( None, None, xous::EC_WF200_PKG_LEN as usize, xous::MemoryFlags::R | xous::MemoryFlags::W, ).expect("couldn't map EC wf200 package memory range"); + #[cfg(not(any(target_os = "none", target_os = "xous")))] + for d in wf_package.as_slice_mut::().iter_mut() { *d = 0xFF } loop { let msg = xous::receive_message(sid).unwrap(); @@ -188,6 +192,10 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) { // the semver *could* be bogus at this point, but we'll validate the package (which contains the semver) before we use it. // however, this check is much less computationally expensive than the package validation. let length = u32::from_le_bytes(package[0x28..0x2c].try_into().unwrap()); + if length == 0xffff_ffff { // nothing was staged at all + xous::return_scalar(msg.sender, UpdateResult::PackageInvalid.to_usize().unwrap()).unwrap(); + continue; + } let semver_bytes = &package[0x1000 + length as usize - SEMVER_OFFSET..0x1000 + length as usize - SEMVER_OFFSET + SEMVER_LEN]; let pkg_ver = SemVer::from(&semver_bytes[..16].try_into().unwrap()); if pkg_ver > ec_reported_rev {