Skip to content

Commit e151d9d

Browse files
committed
--flash-ec: Check platform before flashing
Make sure that you can't flash the wrong platform EC. ``` > framework_tool --flash-rw-ec framework_lib/test_bins/adl-ec-0.0.1.bin --dry-run File Size: 524288 B Size: 512 KB EC RW Version in File: "hx30_v0.0.1-7a61a89" Error: DeviceError("RW Firmware file is for platform hx30. Currently running lotus") ``` Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 7b67f0c commit e151d9d

File tree

1 file changed

+21
-1
lines changed
  • framework_lib/src/chromium_ec

1 file changed

+21
-1
lines changed

framework_lib/src/chromium_ec/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,24 @@ impl CrosEc {
790790
/// | 79000 | 79FFF | 01000 | Flash Flags |
791791
pub fn reflash(&self, data: &[u8], ft: EcFlashType, dry_run: bool) -> EcResult<()> {
792792
let mut res = Ok(());
793+
794+
let cur_ver = self.version_info()?;
795+
let platform = if let Some(ver) = ec_binary::parse_ec_version_str(&cur_ver) {
796+
ver.platform
797+
} else {
798+
return Err(EcError::DeviceError(
799+
"Cannot determine currently running platform.".to_string()
800+
));
801+
};
802+
793803
if ft == EcFlashType::Full || ft == EcFlashType::Ro {
794804
if let Some(version) = ec_binary::read_ec_version(data, true) {
795805
println!("EC RO Version in File: {:?}", version.version);
806+
if version.details.platform != platform {
807+
return Err(EcError::DeviceError(
808+
format!("RO Firmware file is for platform {}. Currently running {}", version.details.platform, platform)
809+
));
810+
}
796811
} else {
797812
return Err(EcError::DeviceError(
798813
"File does not contain valid EC RO firmware".to_string(),
@@ -802,9 +817,14 @@ impl CrosEc {
802817
if ft == EcFlashType::Full || ft == EcFlashType::Rw {
803818
if let Some(version) = ec_binary::read_ec_version(data, false) {
804819
println!("EC RW Version in File: {:?}", version.version);
820+
if version.details.platform != platform {
821+
return Err(EcError::DeviceError(
822+
format!("RW Firmware file is for platform {}. Currently running {}", version.details.platform, platform)
823+
));
824+
}
805825
} else {
806826
return Err(EcError::DeviceError(
807-
"File does not contain valid EW RO firmware".to_string(),
827+
"File does not contain valid EW RW firmware".to_string(),
808828
));
809829
}
810830
}

0 commit comments

Comments
 (0)