1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-03 15:03:22 +02:00

flashrom_tester: Add positive check to verify_fail_test

In verify_fail_test test that verify works when expected, as well as
fails when expected. A verify_region_from_file function is added to
support this.

BUG=b:235916336
BRANCH=None
TEST=None

Change-Id: Ibbcc97086466b67cfab4f6c32140bb5f2c456beb
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71974
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
Evan Benn
2023-01-16 16:16:42 +11:00
committed by Edward O'Callaghan
parent 72e62750c8
commit 5735529d62
4 changed files with 50 additions and 2 deletions

View File

@ -269,6 +269,18 @@ impl crate::Flashrom for FlashromCmd {
Ok(())
}
fn verify_region_from_file(&self, path: &Path, region: &str) -> Result<(), FlashromError> {
let opts = FlashromOpt {
io_opt: Some(IOOpt::Verify(OperationArgs::RegionFileRegion(
region, path, None,
))),
..Default::default()
};
self.dispatch(opts, "verify_region_from_file")?;
Ok(())
}
fn erase(&self) -> Result<(), FlashromError> {
let opts = FlashromOpt {
io_opt: Some(IOOpt::Erase),

View File

@ -152,6 +152,27 @@ impl crate::Flashrom for FlashromLib {
Ok(())
}
fn verify_region_from_file(&self, path: &Path, region: &str) -> Result<(), FlashromError> {
let mut layout = self.flashrom.borrow_mut().layout_read_fmap_from_rom()?;
layout.include_region(region)?;
let range = layout.get_region_range(region)?;
let region_data = fs::read(path).map_err(|error| error.to_string())?;
if region_data.len() != range.len() {
return Err(format!(
"verify region range ({}) does not match provided file size ({})",
range.len(),
region_data.len()
)
.into());
}
let mut buf = vec![0; self.get_size()? as usize];
buf[range].copy_from_slice(&region_data);
self.flashrom
.borrow_mut()
.image_verify(&buf, Some(layout))?;
Ok(())
}
fn erase(&self) -> Result<(), FlashromError> {
self.flashrom.borrow_mut().erase()?;
Ok(())

View File

@ -133,7 +133,8 @@ pub trait Flashrom {
/// Read the whole flash to the file specified by `path`.
fn read_into_file(&self, path: &Path) -> Result<(), FlashromError>;
/// Read only a region of the flash.
/// Read only a region of the flash into the file specified by `path`. Note
/// the first byte written to the file is the first byte from the region.
fn read_region_into_file(&self, path: &Path, region: &str) -> Result<(), FlashromError>;
/// Write the whole flash to the file specified by `path`.
@ -152,6 +153,10 @@ pub trait Flashrom {
/// Verify the whole flash against the file specified by `path`.
fn verify_from_file(&self, path: &Path) -> Result<(), FlashromError>;
/// Verify only the region against the file specified by `path`.
/// Note the first byte in the file is matched against the first byte of the region.
fn verify_region_from_file(&self, path: &Path, region: &str) -> Result<(), FlashromError>;
/// Erase the whole flash.
fn erase(&self) -> Result<(), FlashromError>;