initial steps toward #335

adds the menu item and handler for a force update
revises some of the wording of the menus so they are more
self-consistent

leaves the EC update handler thread running permanently so
that force updates can be caught and handled
This commit is contained in:
bunnie 2023-04-07 16:22:22 +08:00
parent 4d118e72b8
commit f8913ac944
4 changed files with 81 additions and 11 deletions

View file

@ -174,6 +174,13 @@
"ja": "メニューを閉じる",
"zh": "关闭功能表"
},
"mainmenu.force_ecup": {
"en": "Force EC update",
"en-tts": "Force EC update",
"fr": "Forcer la mise à jour EC*MT*",
"ja": "EC の更新を強制する",
"zh": "强制 EC 更新"
},
"mainmenu.init_keys": {
"en": "Setup passwords...",
"en-tts": "Setup passwords...",
@ -210,9 +217,9 @@
"zh": "准备备份..."
},
"mainmenu.provision_gateware": {
"en": "Install gateware update",
"en-tts": "Install gateware update",
"fr": "Installer la mise à jour du gateware",
"en": "Force gateware update",
"en-tts": "Force gateware update",
"fr": "Forcer la mise à jour du gateware",
"ja": "ゲートウェアアップデートをインストールする",
"zh": "安装比特流更新"
},

View file

@ -182,7 +182,7 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
xous::return_scalar(msg.sender, 1).unwrap();
}
}),
Some(UpdateOp::UpdateAuto) => { // blocking scalar
Some(UpdateOp::UpdateAuto) => msg_blocking_scalar_unpack!(msg, force_arg, _, _, _, {
const GW_HASH_OFFSET: usize = 0x58;
const FW_HASH_OFFSET: usize = 0x38;
const HASH_LEN: usize = 32;
@ -194,8 +194,11 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
};
const WF200_HASH_LEN: usize = 0x48; // this is actually hash + signature + keyset
let force = force_arg != 0;
log::debug!("force update argument: {:?}", force);
let ec_reported_rev = com.get_ec_sw_tag().unwrap(); // fetch the purported rev from the EC. We take it at face value.
if ec_reported_rev.maj == 0 && ec_reported_rev.min == 0 && ec_reported_rev.rev == 0 {
if ec_reported_rev.maj == 0 && ec_reported_rev.min == 0 && ec_reported_rev.rev == 0 && !force {
log::error!("EC rev report seems bogus: {:?}; aborting autoupdate process.", ec_reported_rev);
// this will trigger a dialog box "EC update aborted due to error!"
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
@ -209,12 +212,17 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
// 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 > xous::EC_FW_PKG_LEN { // nothing was staged, or it is bogus (blank FLASH is 0xFFFF_FFFF "length")
// only show the warning if the update was forced; otherwise we shouldn't show the warning because it'll pop up every time on a new unit
if force {
modals.show_notification(
&format!("{} gateware", t!("ecup.invalid", xous::LANG)), None).unwrap();
}
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 {
if (pkg_ver > ec_reported_rev) || force {
if validate_package(package,PackageType::Ec) {
// check to see if we need to do an update
// read the length of the package
@ -292,7 +300,7 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
let mut run_wf200_update = false;
// check to see if we need to do an update. For the WF200, we can only say if the hash is *different*, we don't know if it's newer
// we assume if it's different, we meant to update it.
if ec_reported_rev >= MIN_EC_VER_WITH_HASHES {
if (ec_reported_rev >= MIN_EC_VER_WITH_HASHES) && !force {
let mut ver_wf200_raw = [0u8; 256];
match com.flash_verify(
EC_FLASH_BASE +
@ -321,7 +329,7 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
// ancient version of EC, must run all the updates if any update was run before on the GW
run_wf200_update = did_something;
}
if run_wf200_update {
if run_wf200_update || force {
if validate_package(package,PackageType::Wf200) {
log::info!("updating Wf200");
did_something = true;
@ -363,7 +371,7 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
} else {
xous::return_scalar(msg.sender, UpdateResult::NothingToDo.to_usize().unwrap()).unwrap();
}
},
}),
Some(UpdateOp::Quit) => {
log::info!("quitting updater thread");
xous::return_scalar(msg.sender, 1).unwrap();

View file

@ -91,6 +91,9 @@ pub(crate) enum StatusOpcode {
/// for returning wifi stats
WifiStats,
/// Forces EC update
ForceEcUpdate,
/// Raise the preferences menu
Preferences,
Quit,
@ -399,6 +402,7 @@ fn wrapped_main() -> ! {
}
_ => log::error!("Invalid return type from UpdateAuto"),
}
/* // leave this running, so we can force updates...costs some extra RAM but seems we need it as a matter of customer service
#[cfg(not(feature="dbg-ecupdate"))]
{ // if we're not debugging, quit the updater thread -- might as well free up the memory and connections if the thread is not callable
// this frees up 28-40k runtime RAM + 1 connection in the status thread.
@ -406,7 +410,7 @@ fn wrapped_main() -> ! {
Message::new_blocking_scalar(ecup::UpdateOp::Quit.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't quit updater thread");
unsafe{xous::disconnect(ecup_conn).ok()};
}
} */
// check for backups after EC updates, but before we check for gateware updates
let mut backup_time: Option<DateTime::<Utc>> = None;
@ -1375,6 +1379,44 @@ fn wrapped_main() -> ! {
keys.lock().unwrap().do_create_backup_ux_flow(metadata, None);
}
}
Some(StatusOpcode::ForceEcUpdate) => {
// wrap in thread so the status loop doesn't crash due to event back-pressure during the potentially
// very long running EC update process (which blocks the event handler while it runs)...
thread::spawn({
let ecup_conn = ecup_conn.clone();
move || {
let xns = xous_names::XousNames::new().unwrap();
// send with an argument of '1', which forces the update
match send_message(ecup_conn,
Message::new_blocking_scalar(ecup::UpdateOp::UpdateAuto.to_usize().unwrap(), 1, 0, 0, 0)
).expect("couldn't send auto update command") {
xous::Result::Scalar1(r) => {
match FromPrimitive::from_usize(r) {
Some(ecup::UpdateResult::AutoDone) => {
let llio = llio::Llio::new(&xns);
let netmgr = net::NetManager::new();
// restore interrupts and connection manager
llio.com_event_enable(true).ok();
netmgr.reset();
}
Some(ecup::UpdateResult::NothingToDo) => {
log::error!("Got 'NothingToDo' on force argument. This is a hard error.");
panic!("Force update responded with nothing to do. This is a bug, please report it in xous-core issues, and note the results of `ver ec`, `ver xous`, `ver soc`, `ver wf200`.");
},
Some(ecup::UpdateResult::Abort) => {
let modals = modals::Modals::new(&xns).unwrap();
modals.show_notification(t!("ecup.abort", xous::LANG), None).unwrap();
}
// note: invalid package triggers a pop-up in the update procedure, so we don't need to pop one up here.
Some(ecup::UpdateResult::PackageInvalid) => log::error!("EC firmware package did not validate"),
None => log::error!("invalid return code from EC update check"),
}
}
_ => log::error!("Invalid return type from UpdateAuto"),
}
}
});
}
Some(StatusOpcode::Quit) => {
xous::return_scalar(msg.sender, 1).ok();
break;

View file

@ -8,7 +8,12 @@ use num_traits::*;
use crate::StatusOpcode;
#[allow(unused_variables)] // quiets a warning about unused com that is emitted in tts config. Would be nice to make this more targeted...
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::SID, status_conn: xous::CID, com: &com::Com) -> MenuMatic {
pub fn create_main_menu(
keys: Arc<Mutex<RootKeys>>,
menu_management_sid: xous::SID,
status_conn: xous::CID,
com: &com::Com,
) -> MenuMatic {
let key_conn = keys.lock().unwrap().conn();
let mut menuitems = Vec::<MenuItem>::new();
@ -84,6 +89,14 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::S
close_on_select: true,
});
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.force_ecup", xous::LANG)),
action_conn: Some(status_conn),
action_opcode: StatusOpcode::ForceEcUpdate.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
});
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.selfsign", xous::LANG)),
action_conn: Some(key_conn),