File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 8
8
//! - `portio` - It uses raw port I/O. This works on UEFI and on Linux if the system isn't in lockdown mode (SecureBoot disabled).
9
9
//! - `windows` - It uses [DHowett's Windows driver](https://github.com/DHowett/FrameworkWindowsUtils)
10
10
11
+ use crate :: ec_binary;
11
12
use crate :: os_specific;
12
13
use crate :: smbios;
13
14
#[ cfg( feature = "uefi" ) ]
@@ -399,6 +400,25 @@ impl CrosEc {
399
400
/// | 40000 | 3C000 | 39000 | RO Region |
400
401
/// | 79000 | 79FFF | 01000 | Flash Flags |
401
402
pub fn reflash ( & self , data : & [ u8 ] , ft : EcFlashType ) -> EcResult < ( ) > {
403
+ if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
404
+ if let Some ( version) = ec_binary:: read_ec_version ( data, true ) {
405
+ println ! ( "EC RO Version in File: {:?}" , version. version) ;
406
+ } else {
407
+ return Err ( EcError :: DeviceError (
408
+ "File does not contain valid EC RO firmware" . to_string ( ) ,
409
+ ) ) ;
410
+ }
411
+ }
412
+ if ft == EcFlashType :: Full || ft == EcFlashType :: Rw {
413
+ if let Some ( version) = ec_binary:: read_ec_version ( data, false ) {
414
+ println ! ( "EC RW Version in File: {:?}" , version. version) ;
415
+ } else {
416
+ return Err ( EcError :: DeviceError (
417
+ "File does not contain valid EW RO firmware" . to_string ( ) ,
418
+ ) ) ;
419
+ }
420
+ }
421
+
402
422
if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
403
423
println ! ( "For safety reasons flashing RO firmware is disabled." ) ;
404
424
return Ok ( ( ) ) ;
Original file line number Diff line number Diff line change @@ -182,6 +182,9 @@ pub fn read_ec_version(data: &[u8], ro: bool) -> Option<ImageVersionData> {
182
182
EC_RW_VER_OFFSET_ZEPHYR
183
183
} ;
184
184
185
+ if data. len ( ) < offset + core:: mem:: size_of :: < _ImageVersionData > ( ) {
186
+ return None ;
187
+ }
185
188
let v: _ImageVersionData = unsafe { std:: ptr:: read ( data[ offset..] . as_ptr ( ) as * const _ ) } ;
186
189
if v. cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
187
190
debug ! ( "Failed to find Cookie 1. Found: {:X?}" , { v. cookie1 } ) ;
@@ -191,6 +194,9 @@ pub fn read_ec_version(data: &[u8], ro: bool) -> Option<ImageVersionData> {
191
194
return parse_ec_version ( & v) ;
192
195
}
193
196
197
+ if data. len ( ) < offset_zephyr + core:: mem:: size_of :: < _ImageVersionData > ( ) {
198
+ return None ;
199
+ }
194
200
let v: _ImageVersionData =
195
201
unsafe { std:: ptr:: read ( data[ offset_zephyr..] . as_ptr ( ) as * const _ ) } ;
196
202
if v. cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
You can’t perform that action at this time.
0 commit comments