From acf67d4413e209ffc8c2f6ca3ce4887b2abf2b80 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Wed, 21 Feb 2024 17:14:25 -0700 Subject: [PATCH] tool: Assume ROM size is total flash size Remove the hard-coded assumption that the EC is always 128K, as ITE chips can also be 256K (which Clevo has started using since addw4). Instead assume the ROM is correctly sized, which we do since 0d83819a21f87 ("Pad binary file to total flash size") and proprietary firmware has always done. Signed-off-by: Tim Crawford --- tool/src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tool/src/main.rs b/tool/src/main.rs index cc93627..64c6430 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -63,11 +63,13 @@ unsafe fn flash_read(spi: &mut SpiRom, rom: &mut [u8], se } unsafe fn flash_inner(ec: &mut Ec>, firmware: &Firmware, target: SpiTarget, scratch: bool) -> Result<(), Error> { - let rom_size = 128 * 1024; + let new_rom = firmware.data.to_vec(); - let mut new_rom = firmware.data.to_vec(); - while new_rom.len() < rom_size { - new_rom.push(0xFF); + // XXX: Get flash size programatically? + let rom_size = new_rom.len(); + if rom_size % 1024 != 0 { + println!("ROM size of {} is not valid", rom_size); + return Err(ectool::Error::Verify); } let mut spi_bus = ec.spi(target, scratch)?;