From d5d6461dc551a83e5fe81d571815d2c39e0ae919 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 14 Jul 2022 02:00:06 +0800 Subject: [PATCH] fix details on forward-version autoupdate flow --- services/root-keys/locales/i18n.json | 8 ++- services/root-keys/src/api.rs | 2 + services/root-keys/src/implementation.rs | 30 ++++++++-- services/root-keys/src/lib.rs | 19 ++++++- services/root-keys/src/main.rs | 70 +++++++++++++++++++++++- 5 files changed, 120 insertions(+), 9 deletions(-) diff --git a/services/root-keys/locales/i18n.json b/services/root-keys/locales/i18n.json index e909f5ba6..2dd8bfa43 100644 --- a/services/root-keys/locales/i18n.json +++ b/services/root-keys/locales/i18n.json @@ -114,7 +114,7 @@ "en-tts": "Root keys already initialized." }, "rootkeys.confirm": { - "en": "This will initialize the root keys on your Precursor device.\n\nYou will be prompted for two passwords:\n\t1. Device unlock PIN code\n\t2. System update passphrase.\n\nAre you ready?", + "en": "🔐Create passwords for your Precursor device🔐\n\nYou will be prompted for two passwords:\n\t1. Device unlock PIN code\n\t2. System update passphrase.\n\nAre you ready?", "ja": "これにより、Precursorデバイスのルートキーが初期化されます。\n\n2つのパスワードの入力を求められます。\n\t1.デバイスのロック解除PINコード\n\t2.システムアップデートパスフレーズ。\n\n準備はいいですか?", "zh": "仅当您准备好信 任此设备时才 应继续", "en-tts": "You should only proceed with this operation if you are ready to trust this device." @@ -131,6 +131,12 @@ "zh": "我先检查一下,稍后再试", "en-tts": "I'll try again after inspecting my device." }, + "rootkeys.confirm.dont_ask": { + "en": "Stop bothering me; I know what I'm doing.", + "ja": "二度と気にしないで", + "zh": "不要再打扰我了", + "en-tts": "Stop bothering me; I know what I'm doing." + }, "rootkeys.setup_wait": { "en": "Initializing keys. This takes a few minutes. Do not reset or sleep!", "ja": "キーを初期化中です。これには数分かかります。リセットやスリープはしないでください。", diff --git a/services/root-keys/src/api.rs b/services/root-keys/src/api.rs index 16b8d7cb8..11832789d 100644 --- a/services/root-keys/src/api.rs +++ b/services/root-keys/src/api.rs @@ -97,6 +97,8 @@ pub(crate) enum Opcode { IsZeroKey = 44, /// Erase the backup block EraseBackupBlock = 45, + /// Checks to see if "don't ask me about updates" is set + IsDontAskSet = 46, } #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, PartialEq, Eq)] diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index af6816dca..5ae701e9c 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -2499,25 +2499,45 @@ impl<'a> RootKeys { } } pub fn should_prompt_for_update(&mut self) -> bool { - let soc_region = self.gateware(); - if u32::from_le_bytes(soc_region[soc_region.len() - 4..].try_into().unwrap()) == 0xFFFF_FFFF { + let soc_region = self.staging(); + let status = u32::from_le_bytes(soc_region[soc_region.len() - 4..].try_into().unwrap()); + log::info!("prompt for update: {:x?}", status); + if status == 0xFFFF_FFFF { true } else { false } } + /// the update prompt is reset every time you stage a new update pub fn set_prompt_for_update(&mut self, state: bool) { let patch_data = if state { [0xffu8; 4] } else { [0x0u8; 4] }; + self.spinor.patch( + self.staging(), + self.staging_base(), + &patch_data, + self.staging().len() as u32 - 4 + ).expect("couldn't patch update prompt"); + } + pub fn is_dont_ask_init_set(&mut self) -> bool { + let soc_region = self.gateware(); + let status = u32::from_le_bytes(soc_region[soc_region.len() - 4..].try_into().unwrap()); + log::info!("prompt for root key init: {:x?}", status); + // just check the first byte, although a full word is written for the flag + status != 0xffff_ffff + } + /// this is reset every time the gateware is updated. That's rather intentional, if someone + /// *is* updating their gateware and they haven't initialized root keys...maybe they should? + pub fn set_dont_ask_init(&mut self) { self.spinor.patch( self.gateware(), self.gateware_base(), - &patch_data, - self.gateware().len() as u32 - 4 - ).expect("couldn't patch update prompt"); + &[0u8; 4], + self.gateware().len() as u32 - 4, + ).expect("couldn't erase backup region"); } pub fn read_backup_header(&mut self) -> Option { let kernel = self.kernel(); diff --git a/services/root-keys/src/lib.rs b/services/root-keys/src/lib.rs index 0f212b54d..b442b4f6b 100644 --- a/services/root-keys/src/lib.rs +++ b/services/root-keys/src/lib.rs @@ -101,6 +101,17 @@ impl RootKeys { Err(xous::Error::InternalError) } } + pub fn is_dont_ask_set(&self) -> Result { + let response = send_message(self.conn, + Message::new_blocking_scalar(Opcode::IsDontAskSet.to_usize().unwrap(), 0, 0, 0, 0) + ).expect("couldn't send IsDontAsk check message"); + if let xous::Result::Scalar1(result) = response { + if result != 0 {return Ok(true)} else {return Ok(false)} + } else { + log::error!("unexpected return value: {:#?}", response); + Err(xous::Error::InternalError) + } + } pub fn do_update_gw_ux_flow(&self) { send_message(self.conn, @@ -108,10 +119,16 @@ impl RootKeys { 0, 0, 0, 0) ).expect("couldn't send message to root keys"); } + pub fn do_update_gw_ux_flow_blocking(&self) { + send_message(self.conn, + Message::new_blocking_scalar(Opcode::UxUpdateGateware.to_usize().unwrap(), + 0, 0, 0, 0) + ).expect("couldn't send message to root keys"); + } pub fn do_init_keys_ux_flow(&self) { send_message(self.conn, - Message::new_scalar(Opcode::UxTryInitKeys.to_usize().unwrap(), + Message::new_blocking_scalar(Opcode::UxTryInitKeys.to_usize().unwrap(), 0, 0, 0, 0) ).expect("couldn't send message to root keys"); } diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index cd97aeef2..b4e14ce20 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -360,6 +360,8 @@ mod implementation { pub fn is_zero_key(&self) -> Option { Some(true) } pub fn setup_restore_init(&mut self, _key: backups::BackupKey, _rom: backups::KeyRomExport) { } + pub fn is_dont_ask_set(&self) -> bool {false} + pub fn set_dont_ask(&self) {} } } @@ -464,6 +466,7 @@ fn main() -> ! { let mut reboot_initiated = false; let mut aes_sender: Option = None; let mut backup_header: Option = None; + let mut deferred_response: Option = None; loop { let mut msg = xous::receive_message(keys_sid).unwrap(); let opcode: Option = FromPrimitive::from_usize(msg.body.id()); @@ -507,6 +510,12 @@ fn main() -> ! { // UX flow opcodes Some(Opcode::UxTryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, { + match msg.body { + xous::Message::BlockingScalar(_) => { + deferred_response = Some(msg.sender); + } + _ => (), + } if false { // short-circuit for testing subroutines let _success = keys.test(&mut rootkeys_modal, main_cid); @@ -515,7 +524,9 @@ fn main() -> ! { send_message(main_cid, xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0) ).expect("couldn't initiate dialog box"); - + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } else { // overall flow: @@ -538,17 +549,35 @@ fn main() -> ! { #[cfg(feature="tts")] tts.tts_blocking(t!("rootkeys.already_init", xous::LANG)).unwrap(); keys.set_ux_password_type(None); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } else { modals.add_list_item(t!("rootkeys.confirm.yes", xous::LANG)).expect("modals error"); modals.add_list_item(t!("rootkeys.confirm.no", xous::LANG)).expect("modals error"); + if deferred_response.is_some() { + modals.add_list_item(t!("rootkeys.confirm.dont_ask", xous::LANG)).expect("modals error"); + } log::info!("{}ROOTKEY.CONFIRM,{}", xous::BOOKEND_START, xous::BOOKEND_END); match modals.get_radiobutton(t!("rootkeys.confirm", xous::LANG)) { Ok(response) => { if response == t!("rootkeys.confirm.no", xous::LANG) { + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } + continue; + } else if response == t!("rootkeys.confirm.dont_ask", xous::LANG) { + keys.set_dont_ask_init(); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } else if response != t!("rootkeys.confirm.yes", xous::LANG) { log::error!("Got unexpected response: {:?}", response); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } else { // do nothing, this is the forward path @@ -642,6 +671,9 @@ fn main() -> ! { modals.show_notification(t!("rootkeys.wrong_state", xous::LANG), None).expect("modals error"); } } + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } }, Some(Opcode::UxTryReboot) => { log::info!("{}ROOTKEY.INITDONE,{}", xous::BOOKEND_START, xous::BOOKEND_END); @@ -741,6 +773,12 @@ fn main() -> ! { } } Some(Opcode::UxUpdateGateware) => { + match msg.body { + xous::Message::BlockingScalar(_) => { + deferred_response = Some(msg.sender); + } + _ => (), + } // steps: // - check update signature "Inspecting gateware update, this will take a moment..." // - if no signature found: "No valid update found! (ok -> exit out)" @@ -757,6 +795,9 @@ fn main() -> ! { _ => { modals.dynamic_notification_close().expect("modals error"); modals.show_notification(t!("rootkeys.gwup.no_update_found", xous::LANG), None).expect("modals error"); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } }; @@ -803,7 +844,13 @@ fn main() -> ! { skip_confirmation = true; } } - _ => {log::error!("get_radiobutton failed"); continue;} + _ => { + log::error!("get_radiobutton failed"); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } + continue; + } } if !skip_confirmation { modals.add_list_item(t!("rootkeys.gwup.yes", xous::LANG)).expect("modals error"); @@ -811,9 +858,15 @@ fn main() -> ! { match modals.get_radiobutton(t!("rootkeys.gwup.proceed_confirm", xous::LANG)) { Ok(response) => { if response == t!("rootkeys.gwup.no", xous::LANG) { + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } if response != t!("rootkeys.gwup.yes", xous::LANG) { log::error!("got unexpected response from radio box: {:?}", response); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } else { // just proceed forward! @@ -821,6 +874,9 @@ fn main() -> ! { } _ => { log::error!("modals error, aborting"); + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } continue; } } @@ -909,6 +965,9 @@ fn main() -> ! { modals.show_notification(t!("rootkeys.wrong_state", xous::LANG), None).expect("modals error"); } } + if let Some(dr) = deferred_response.take() { + xous::return_scalar(dr, 0).unwrap(); + } } Some(Opcode::UxSelfSignXous) => { if keys.is_pcache_update_password_valid() { @@ -1485,6 +1544,13 @@ fn main() -> ! { xous::return_scalar2(msg.sender, 0, 0).ok(); } }), + Some(Opcode::IsDontAskSet) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + if keys.is_dont_ask_init_set() { + xous::return_scalar(msg.sender, 1).ok(); + } else { + xous::return_scalar(msg.sender, 0).ok(); + } + }), Some(Opcode::TestUx) => msg_blocking_scalar_unpack!(msg, _arg, _, _, _, { // dummy test for now xous::return_scalar(msg.sender, 1234).unwrap();