Skip to content

Commit

Permalink
clean up bitrot in dbg-ecupdate configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Nov 6, 2022
1 parent 69cf629 commit 5a0e3e5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
22 changes: 13 additions & 9 deletions services/shellchat/src/cmds/ecup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {

fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
let mut ret = String::<1024>::new();
let helpstring = "ecup [gw] [fw] [wf200] [reset] [auto]";
let helpstring = "ecup [gw] [fw] [wf200] [auto]";

log::debug!("ecup handling {}", args.as_str().unwrap());
let mut tokens = args.as_str().unwrap().split(' ');
Expand All @@ -26,41 +26,45 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"fw" => {
xous::send_message(ecup_conn,
let result = xous::send_message(ecup_conn,
xous::Message::new_blocking_scalar(
1, // hard coded to match UpdateOp
0, 0, 0, 0
)
).unwrap();
write!(ret, "Starting EC firmware update").unwrap();
env.ticktimer.sleep_ms(200).unwrap();
write!(ret, "EC firmware update: {:?}", result).unwrap();
}
"gw" => {
xous::send_message(ecup_conn,
let result = xous::send_message(ecup_conn,
xous::Message::new_blocking_scalar(
0, // hard coded to match UpdateOp
0, 0, 0, 0
)
).unwrap();
write!(ret, "Starting EC gateware update").unwrap();
env.ticktimer.sleep_ms(200).unwrap();
write!(ret, "EC gateware update: {:?}", result).unwrap();
}
// note: "reset" has been moved to `ver ecreset`
"wf200" => {
xous::send_message(ecup_conn,
let result = xous::send_message(ecup_conn,
xous::Message::new_blocking_scalar(
2, // hard coded to match UpdateOp
0, 0, 0, 0
)
).unwrap();
write!(ret, "Starting EC wf200 update").unwrap();
env.ticktimer.sleep_ms(200).unwrap();
write!(ret, "EC wf200 update: {:?}", result).unwrap();
}
"auto" => {
xous::send_message(ecup_conn,
let result = xous::send_message(ecup_conn,
xous::Message::new_blocking_scalar(
3, // hard coded to match UpdateOp
0, 0, 0, 0
)
).unwrap();
write!(ret, "Starting full EC firmware update").unwrap();
env.ticktimer.sleep_ms(200).unwrap();
write!(ret, "Full EC firmware update: {:?}", result).unwrap();
}
_ => {
write!(ret, "{}", helpstring).unwrap();
Expand Down
70 changes: 40 additions & 30 deletions services/status/src/ecup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,65 +97,75 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
match FromPrimitive::from_usize(msg.body.id()) {
#[cfg(feature="dbg-ecupdate")]
Some(UpdateOp::UpdateGateware) => { // blocking scalar
netmgr.connection_manager_stop().unwrap();
com.wlan_leave().ok();
ticktimer.sleep_ms(4000).unwrap(); // give a few seconds for any packets/updates to clear so we don't tigger panics as the EC is about to disappear...

let package = unsafe{ core::slice::from_raw_parts(ec_package.as_ptr() as *const u8, xous::EC_FW_PKG_LEN as usize)};
if !validate_package(package,PackageType::Ec) {
log::error!("firmware package did not pass validation");
modals.show_notification(
&format!("{} gateware", t!("ecup.invalid", xous::LANG)), None).unwrap();
} else {
log::info!("updating GW");
netmgr.connection_manager_stop().ok();
llio.com_event_enable(false).ok();
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
do_update(&mut com, &modals, package, CTRL_PAGE_LEN, EC_GATEWARE_BASE, EC_GATEWARE_LEN, "gateware");
if !do_update(&mut com, &modals, package, CTRL_PAGE_LEN, EC_GATEWARE_BASE,
EC_GATEWARE_LEN,
"gateware") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
susres.set_suspendable(true).unwrap(); // resume suspend/resume operations
}
xous::return_scalar(msg.sender, 0).unwrap();
},
#[cfg(feature="dbg-ecupdate")]
Some(UpdateOp::UpdateFirmware) => { // blocking scalar
netmgr.connection_manager_stop().unwrap();
com.wlan_leave().ok();
ticktimer.sleep_ms(4000).unwrap(); // give a few seconds for any packets/updates to clear so we don't tigger panics as the EC is about to disappear...

let package = unsafe{ core::slice::from_raw_parts(ec_package.as_ptr() as *const u8, xous::EC_FW_PKG_LEN as usize)};
let mut temp: [u8; 4] = Default::default();
temp.copy_from_slice(&package[0x28..0x2c]);
let length = u32::from_le_bytes(temp); // total length of package

if !validate_package(package,PackageType::Ec) {
log::error!("firmware package did not pass validation");
modals.show_notification(
&format!("{} firmware", t!("ecup.invalid", xous::LANG)), None).unwrap();
} else {
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;
}
log::info!("updating FW");
netmgr.connection_manager_stop().unwrap();
llio.com_event_enable(false).ok();
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
do_update(&mut com, &modals, package, EC_GATEWARE_LEN + CTRL_PAGE_LEN,
EC_FIRMWARE_BASE, length - (EC_GATEWARE_LEN), "firmware");
if !do_update(&mut com, &modals, package, EC_GATEWARE_LEN + CTRL_PAGE_LEN,
EC_FIRMWARE_BASE, length - (EC_GATEWARE_LEN),
"firmware") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
susres.set_suspendable(true).unwrap(); // resume suspend/resume operations
}
xous::return_scalar(msg.sender, 0).unwrap();
},
#[cfg(feature="dbg-ecupdate")]
Some(UpdateOp::UpdateWf200) => { // blocking scalar
netmgr.connection_manager_stop().unwrap();
com.wlan_leave().ok();
ticktimer.sleep_ms(4000).unwrap(); // give a few seconds for any packets/updates to clear so we don't tigger panics as the EC is about to disappear...

let package = unsafe{ core::slice::from_raw_parts(wf_package.as_ptr() as *const u8, xous::EC_WF200_PKG_LEN as usize)};
let mut temp: [u8; 4] = Default::default();
temp.copy_from_slice(&package[0x28..0x2c]);
let length = u32::from_le_bytes(temp); // total length of package

if !validate_package(package,PackageType::Wf200) {
log::error!("WF200 firmware package did not pass validation");
modals.show_notification(
&format!("{} wf200", t!("ecup.invalid", xous::LANG)), None).unwrap();
} else {
if validate_package(package,PackageType::Wf200) {
log::info!("updating Wf200");
netmgr.connection_manager_stop().unwrap();
llio.com_event_enable(false).ok();
let length = u32::from_le_bytes(package[0x28..0x2c].try_into().unwrap());
susres.set_suspendable(false).unwrap(); // block suspend/resume operations
do_update(&mut com, &modals, package, CTRL_PAGE_LEN,
WF200_FIRMWARE_BASE, length, "wf200");
if !do_update(&mut com, &modals, package, CTRL_PAGE_LEN,
WF200_FIRMWARE_BASE, length,
"WF200") {
xous::return_scalar(msg.sender, UpdateResult::Abort.to_usize().unwrap()).unwrap();
continue;
}
susres.set_suspendable(true).unwrap(); // resume suspend/resume operations
} else {
log::error!("wf200 package did not pass validation");
modals.show_notification(
&format!("{} WF200", t!("ecup.invalid", xous::LANG)), None).unwrap();
xous::return_scalar(msg.sender, UpdateResult::PackageInvalid.to_usize().unwrap()).unwrap();
continue;
}

xous::return_scalar(msg.sender, 0).unwrap();
Expand Down

0 comments on commit 5a0e3e5

Please sign in to comment.