clean up autoupdate flow & clean up net link reset flow

We are now at a point where the EC update can be applied and the
net stack recovers gracefully, so no reboot is required in the
case of an EC update.
This commit is contained in:
bunnie 2022-07-11 15:07:53 +08:00
parent 8f3aa84e6d
commit a90b5f2554
5 changed files with 53 additions and 52 deletions

View file

@ -29,6 +29,7 @@ pub(crate) enum ConnectionManagerOpcode {
FetchSsidList,
ComInt,
SuspendResume,
EcReset,
Quit,
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
@ -177,12 +178,6 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
// it's not clear to me how we get into this state, so let's be conservative and just leave the link and restart things.
com.wlan_leave().expect("couldn't issue leave command"); // leave the previous config to reset state
netmgr.reset();
wifi_state = WifiState::Disconnected;
if scan_state == SsidScanState::Idle {
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
scan_count = 0; // we only set scan_count to 0 on resumes because we can't be sure what our previous state was
}
send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll");
}
}
@ -207,13 +202,6 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap();
buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap();
}
wifi_state = WifiState::Disconnected;
// kick off an SSID scan
if scan_state == SsidScanState::Idle {
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
scan_count = 0; // we only set scan_count to 0 on resumes because we can't be sure what our previous state was
}
}
WifiState::Error => {
// let the error handler do its thing on the next pump cycle
@ -319,18 +307,13 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
if intervals_without_activity > 3 { // we'd expect at least an ARP or something...
wifi_stats_cache = com.wlan_status().unwrap();
if wifi_stats_cache.link_state != com_rs_ref::LinkState::Connected {
log::info!("Link state mismatch: moving state to disconnected");
wifi_state = WifiState::Disconnected;
ssid_list.clear();
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
log::info!("Link state mismatch: moving state to disconnected ({:?})", wifi_stats_cache.link_state);
netmgr.reset();
} else if wifi_stats_cache.ipv4.dhcp != com_rs_ref::DhcpState::Bound {
log::info!("DHCP state mismatch: moving state to disconnected");
wifi_state = WifiState::Disconnected;
ssid_list.clear();
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
log::info!("DHCP state mismatch: moving state to disconnected ({:?})", wifi_stats_cache.ipv4.dhcp);
netmgr.reset();
}
intervals_without_activity = 0;
}
if last_wifi_state == WifiState::Connected && wifi_state != WifiState::Connected {
@ -386,23 +369,12 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
log::debug!("got Retry on connect");
com.wlan_leave().expect("couldn't issue leave command"); // leave the previous config to reset state
netmgr.reset();
wifi_state = WifiState::Disconnected;
if scan_state == SsidScanState::Idle {
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
}
send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll");
}
WifiState::Error => {
log::debug!("got error on connect, resetting wifi chip");
com.wifi_reset().expect("couldn't reset the wf200 chip");
netmgr.reset(); // this can result in a suspend failure, but the suspend timeout is currently set long enough to accommodate this possibility
wifi_state = WifiState::Disconnected;
if scan_state == SsidScanState::Idle {
ssid_list.clear();
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
}
send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll");
}
WifiState::Connected => {
@ -491,6 +463,16 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
Some(ConnectionManagerOpcode::Stop) => msg_scalar_unpack!(msg, _, _, _, _, {
run.store(false, Ordering::SeqCst);
}),
Some(ConnectionManagerOpcode::EcReset) => msg_scalar_unpack!(msg, _, _, _, _, {
// this opcode is used by other processes to inform us that the net link was reset by something other than us.
// (e.g. an update)
wifi_state = WifiState::Disconnected;
ssid_list.clear();
com.set_ssid_scanning(true).unwrap();
scan_state = SsidScanState::Scanning;
intervals_without_activity = 0;
scan_count = 0;
}),
Some(ConnectionManagerOpcode::Quit) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
send_message(run_cid, Message::new_blocking_scalar(PumpOp::Quit.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't tell Pump to quit");
unsafe{xous::disconnect(run_cid).ok()};

View file

@ -1861,6 +1861,20 @@ fn main() -> ! {
// note: ARP cache isn't reset
iface.routes_mut().remove_default_ipv4_route();
dns_allclear_hook.notify();
send_message(
cm_cid,
Message::new_scalar( // this has to be non-blocking to avoid deadlock: reset can be called from inside connection_manager
connection_manager::ConnectionManagerOpcode::EcReset
.to_usize()
.unwrap(),
0,
0,
0,
0,
),
)
.expect("couldn't send EcReset message");
xous::return_scalar(msg.sender, 1).unwrap();
}
Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {

View file

@ -13,21 +13,21 @@
},
"ecup.erasing": {
"ja": "消去...",
"en": "Erasing...",
"en": "EC Autoupdate\n\nErasing",
"zh": "擦除...",
"en-tts": "Erasing..."
"en-tts": "EC Autoupdate\n\nErasing"
},
"ecup.writing": {
"ja": "書き込み...",
"en": "Writing...",
"en": "EC Autoupdate\n\nWriting",
"zh": "写作...",
"en-tts": "Writing..."
"en-tts": "EC Autoupdate\n\nWriting"
},
"ecup.please_reboot": {
"ja": "USBロードのアップデートが適用されました:できるだけ早く再起動してください...",
"en": "USB-loaded update was applied: please reboot at your earliest convenience...",
"zh": "已应用 USB 加载更新:请尽早重启...",
"en-tts": "USB-loaded update was applied: please reboot at your earliest convenience..."
"ecup.update_applied": {
"ja": "USBロードのアップデートが適用されました.",
"en": "An EC update was successfully applied!",
"zh": "已应用 USB 加载更新.",
"en-tts": "An EC update was successfully applied!"
},
"ecup.resetting": {
"ja": "ECのリセット",

View file

@ -233,7 +233,8 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
llio.com_event_enable(false).ok();
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
if !do_update(&mut com, &modals, package, CTRL_PAGE_LEN, EC_GATEWARE_BASE,
EC_GATEWARE_LEN, "EC gateware") {
EC_GATEWARE_LEN,
"gateware") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
@ -245,7 +246,8 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
llio.com_event_enable(false).ok();
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
if !do_update(&mut com, &modals, package, EC_GATEWARE_LEN + CTRL_PAGE_LEN,
EC_FIRMWARE_BASE, length - (EC_GATEWARE_LEN), "EC firmware") {
EC_FIRMWARE_BASE, length - (EC_GATEWARE_LEN),
"firmware") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
@ -302,7 +304,8 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
let length = u32::from_le_bytes(package[0x28..0x2c].try_into().unwrap());
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
if !do_update(&mut com, &modals, package, CTRL_PAGE_LEN,
WF200_FIRMWARE_BASE, length, "WF200") {
WF200_FIRMWARE_BASE, length,
"WF200") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
@ -374,7 +377,7 @@ fn do_update(com: &mut com::Com, modals: &Modals, package: &[u8], pkg_offset: u3
// program
log::info!("init progress: {:x}->{:x}", pkg_offset, pkg_offset + image_len);
modals.start_progress(
&format!("{}\n({})", t!("ecup.writing", xous::LANG), name),
&format!("{} {}...", t!("ecup.writing", xous::LANG), name),
flash_start, flash_start + image_len, flash_start).unwrap();
// divide into 1k chunks and send over
let exact_chunks = package[pkg_offset as usize..(pkg_offset + image_len) as usize].chunks_exact(1024);
@ -398,7 +401,7 @@ fn do_update(com: &mut com::Com, modals: &Modals, package: &[u8], pkg_offset: u3
if com.flash_program(prog_addr, pages).unwrap() == false {
modals.finish_progress().unwrap();
modals.show_notification(
&format!("{}\n({})", t!("ecup.abort", xous::LANG), name), None
&format!("{} {}...", t!("ecup.abort", xous::LANG), name), None
).unwrap();
return false;
}

View file

@ -297,7 +297,7 @@ fn wrapped_main() -> ! {
});
let ecup_conn = xous::connect(ecup_sid).unwrap();
// check & automatically apply any EC updates
let mut needs_reboot = false;
let mut ec_updated = false;
match send_message(ecup_conn,
Message::new_blocking_scalar(ecup::UpdateOp::UpdateAuto.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't send auto update command") {
@ -306,7 +306,7 @@ fn wrapped_main() -> ! {
Some(ecup::UpdateResult::AutoDone) => {
// question: do we want to put something there that confirms that the reported EC firmware
// at this point matches the intended update? we /could/ do that, but if it fails then how?
needs_reboot = true;
ec_updated = true;
// restore interrupts and connection manager
llio.com_event_enable(true).ok();
netmgr.reset();
@ -363,8 +363,10 @@ fn wrapped_main() -> ! {
});
};
sec_notes.lock().unwrap().insert("current_app".to_string(), format!("Running: Shellchat").to_string()); // this is the default app on boot
if needs_reboot {
modals.show_notification(t!("ecup.please_reboot", xous::LANG), None).unwrap();
// dubious if we need to show this notification.
if ec_updated {
netmgr.reset(); // have to do this to get the net manager stack into a known state after reset
modals.show_notification(t!("ecup.update_applied", xous::LANG), None).unwrap();
}
// --------------------------- graphical loop timing