Skip to content

Commit

Permalink
ec: Assume ROM size is total flash size
Browse files Browse the repository at this point in the history
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
system76/ec@0d83819a21f87 ("Pad binary file to total flash size") and
proprietary firmware has always done.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Feb 16, 2024
1 parent ecd5fcf commit 5fb9563
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/app/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ impl EcComponent {
// Special case for pang12, pang13, and pang14
match &self.ec {
EcKind::Pang(_pmc, _system_version) => {
return data.len() == 128 * 1024
&& &data[0x50 ..= 0x05F] == b"ITE EC-V14.6 \0";
},
// XXX: Get flash size programatically?
return (data.len() == 128 * 1024 || data.len() == 256 * 1024)
&& &data[0x50..=0x05F] == b"ITE EC-V14.6 \0";
}
_ => (),
}

Expand Down Expand Up @@ -314,12 +315,10 @@ impl<T: Timeout> SpiLegacy<T> {
}
}

fn rom_size(&self) -> usize {
128 * 1024
}
fn block_size(&self) -> usize {
64 * 1024
}

fn page_size(&self) -> usize {
256
}
Expand Down Expand Up @@ -401,10 +400,13 @@ impl<T: Timeout> SpiLegacy<T> {
unsafe fn flash_legacy(firmware_data: &[u8]) -> core::result::Result<(), ectool::Error> {
let mut spi = SpiLegacy::new(UefiTimeout::new(1_000_000));

let rom_size = spi.rom_size();
let mut new_rom = firmware_data.to_vec();
while new_rom.len() < rom_size {
new_rom.push(0xFF);
let new_rom = firmware_data.to_vec();

// 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);
}

println!("Entering scratch ROM");
Expand Down Expand Up @@ -534,11 +536,13 @@ unsafe fn flash(
println!("ec version: {:?}", str::from_utf8(ec_version));
}

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(SpiTarget::Main, true)?;
Expand Down

0 comments on commit 5fb9563

Please sign in to comment.