Skip to content

Commit 2ecd1ae

Browse files
committed
chromium_ec: Check EC firmware file length before unlocking flash
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent ff3cfd4 commit 2ecd1ae

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

  • framework_lib/src/chromium_ec

‎framework_lib/src/chromium_ec/mod.rs‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,20 @@ impl CrosEc {
943943
}
944944
}
945945

946+
// Make sure the file covers all regions we're going to write, before touching the flash
947+
let required_len = match ft {
948+
EcFlashType::Full => FLASH_SIZE,
949+
EcFlashType::Both | EcFlashType::Rw => FLASH_RW_BASE + flash_rw_size,
950+
EcFlashType::Ro => FLASH_RO_BASE + flash_ro_size,
951+
} as usize;
952+
if data.len() < required_len {
953+
return Err(EcError::DeviceError(format!(
954+
"Firmware file too small. Expected at least {} bytes, got {}",
955+
required_len,
956+
data.len()
957+
)));
958+
}
959+
946960
// Determine recommended flash parameters
947961
let info = EcRequestFlashInfo {}.send_command(self)?;
948962

@@ -1018,13 +1032,6 @@ impl CrosEc {
10181032
// 3. Write each row (128B) individually
10191033

10201034
if ft == EcFlashType::Full {
1021-
if data.len() < FLASH_SIZE as usize {
1022-
return Err(EcError::DeviceError(format!(
1023-
"Firmware file too small for full flash. Expected {} bytes, got {}",
1024-
FLASH_SIZE,
1025-
data.len()
1026-
)));
1027-
}
10281035
let data = &data[..FLASH_SIZE as usize];
10291036

10301037
println!(

0 commit comments

Comments
 (0)