@@ -97,65 +97,75 @@ pub(crate) fn ecupdate_thread(sid: xous::SID) {
9797 match FromPrimitive :: from_usize ( msg. body . id ( ) ) {
9898 #[ cfg( feature="dbg-ecupdate" ) ]
9999 Some ( UpdateOp :: UpdateGateware ) => { // blocking scalar
100- netmgr. connection_manager_stop ( ) . unwrap ( ) ;
101- com. wlan_leave ( ) . ok ( ) ;
102- 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...
103-
104100 let package = unsafe { core:: slice:: from_raw_parts ( ec_package. as_ptr ( ) as * const u8 , xous:: EC_FW_PKG_LEN as usize ) } ;
105101 if !validate_package ( package, PackageType :: Ec ) {
106102 log:: error!( "firmware package did not pass validation" ) ;
107103 modals. show_notification (
108104 & format ! ( "{} gateware" , t!( "ecup.invalid" , xous:: LANG ) ) , None ) . unwrap ( ) ;
109105 } else {
106+ log:: info!( "updating GW" ) ;
107+ netmgr. connection_manager_stop ( ) . ok ( ) ;
108+ llio. com_event_enable ( false ) . ok ( ) ;
110109 susres. set_suspendable ( false ) . unwrap ( ) ; // block suspend/resume operations
111- do_update ( & mut com, & modals, package, CTRL_PAGE_LEN , EC_GATEWARE_BASE , EC_GATEWARE_LEN , "gateware" ) ;
110+ if !do_update ( & mut com, & modals, package, CTRL_PAGE_LEN , EC_GATEWARE_BASE ,
111+ EC_GATEWARE_LEN ,
112+ "gateware" ) {
113+ xous:: return_scalar ( msg. sender , UpdateResult :: Abort . to_usize ( ) . unwrap ( ) ) . unwrap ( ) ;
114+ continue ;
115+ }
112116 susres. set_suspendable ( true ) . unwrap ( ) ; // resume suspend/resume operations
113117 }
114118 xous:: return_scalar ( msg. sender , 0 ) . unwrap ( ) ;
115119 } ,
116120 #[ cfg( feature="dbg-ecupdate" ) ]
117121 Some ( UpdateOp :: UpdateFirmware ) => { // blocking scalar
118- netmgr. connection_manager_stop ( ) . unwrap ( ) ;
119- com. wlan_leave ( ) . ok ( ) ;
120- 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...
121-
122122 let package = unsafe { core:: slice:: from_raw_parts ( ec_package. as_ptr ( ) as * const u8 , xous:: EC_FW_PKG_LEN as usize ) } ;
123- let mut temp: [ u8 ; 4 ] = Default :: default ( ) ;
124- temp. copy_from_slice ( & package[ 0x28 ..0x2c ] ) ;
125- let length = u32:: from_le_bytes ( temp) ; // total length of package
126-
127123 if !validate_package ( package, PackageType :: Ec ) {
128124 log:: error!( "firmware package did not pass validation" ) ;
129125 modals. show_notification (
130126 & format ! ( "{} firmware" , t!( "ecup.invalid" , xous:: LANG ) ) , None ) . unwrap ( ) ;
131127 } else {
128+ let length = u32:: from_le_bytes ( package[ 0x28 ..0x2c ] . try_into ( ) . unwrap ( ) ) ;
129+ if length == 0xffff_ffff { // nothing was staged at all
130+ xous:: return_scalar ( msg. sender , UpdateResult :: PackageInvalid . to_usize ( ) . unwrap ( ) ) . unwrap ( ) ;
131+ continue ;
132+ }
133+ log:: info!( "updating FW" ) ;
134+ netmgr. connection_manager_stop ( ) . unwrap ( ) ;
135+ llio. com_event_enable ( false ) . ok ( ) ;
132136 susres. set_suspendable ( false ) . unwrap ( ) ; // block suspend/resume operations
133- do_update ( & mut com, & modals, package, EC_GATEWARE_LEN + CTRL_PAGE_LEN ,
134- EC_FIRMWARE_BASE , length - ( EC_GATEWARE_LEN ) , "firmware" ) ;
137+ if !do_update ( & mut com, & modals, package, EC_GATEWARE_LEN + CTRL_PAGE_LEN ,
138+ EC_FIRMWARE_BASE , length - ( EC_GATEWARE_LEN ) ,
139+ "firmware" ) {
140+ xous:: return_scalar ( msg. sender , UpdateResult :: Abort . to_usize ( ) . unwrap ( ) ) . unwrap ( ) ;
141+ continue ;
142+ }
135143 susres. set_suspendable ( true ) . unwrap ( ) ; // resume suspend/resume operations
136144 }
137145 xous:: return_scalar ( msg. sender , 0 ) . unwrap ( ) ;
138146 } ,
139147 #[ cfg( feature="dbg-ecupdate" ) ]
140148 Some ( UpdateOp :: UpdateWf200 ) => { // blocking scalar
141- netmgr. connection_manager_stop ( ) . unwrap ( ) ;
142- com. wlan_leave ( ) . ok ( ) ;
143- 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...
144-
145149 let package = unsafe { core:: slice:: from_raw_parts ( wf_package. as_ptr ( ) as * const u8 , xous:: EC_WF200_PKG_LEN as usize ) } ;
146- let mut temp: [ u8 ; 4 ] = Default :: default ( ) ;
147- temp. copy_from_slice ( & package[ 0x28 ..0x2c ] ) ;
148- let length = u32:: from_le_bytes ( temp) ; // total length of package
149-
150- if !validate_package ( package, PackageType :: Wf200 ) {
151- log:: error!( "WF200 firmware package did not pass validation" ) ;
152- modals. show_notification (
153- & format ! ( "{} wf200" , t!( "ecup.invalid" , xous:: LANG ) ) , None ) . unwrap ( ) ;
154- } else {
150+ if validate_package ( package, PackageType :: Wf200 ) {
151+ log:: info!( "updating Wf200" ) ;
152+ netmgr. connection_manager_stop ( ) . unwrap ( ) ;
153+ llio. com_event_enable ( false ) . ok ( ) ;
154+ let length = u32:: from_le_bytes ( package[ 0x28 ..0x2c ] . try_into ( ) . unwrap ( ) ) ;
155155 susres. set_suspendable ( false ) . unwrap ( ) ; // block suspend/resume operations
156- do_update ( & mut com, & modals, package, CTRL_PAGE_LEN ,
157- WF200_FIRMWARE_BASE , length, "wf200" ) ;
156+ if !do_update ( & mut com, & modals, package, CTRL_PAGE_LEN ,
157+ WF200_FIRMWARE_BASE , length,
158+ "WF200" ) {
159+ xous:: return_scalar ( msg. sender , UpdateResult :: Abort . to_usize ( ) . unwrap ( ) ) . unwrap ( ) ;
160+ continue ;
161+ }
158162 susres. set_suspendable ( true ) . unwrap ( ) ; // resume suspend/resume operations
163+ } else {
164+ log:: error!( "wf200 package did not pass validation" ) ;
165+ modals. show_notification (
166+ & format ! ( "{} WF200" , t!( "ecup.invalid" , xous:: LANG ) ) , None ) . unwrap ( ) ;
167+ xous:: return_scalar ( msg. sender , UpdateResult :: PackageInvalid . to_usize ( ) . unwrap ( ) ) . unwrap ( ) ;
168+ continue ;
159169 }
160170
161171 xous:: return_scalar ( msg. sender , 0 ) . unwrap ( ) ;
0 commit comments