1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 15:33:42 +02:00

flashrom_tester: Add write_file_with_layout positive test

write_file_with_layout test was checking that writing to a region was
failing, and assuming that was because write protect is working as
expected. Other failures are possible, so check that a write to a non
write protected region can succeed.

BUG=b:235916336
BRANCH=None
TEST=/usr/bin/flashrom_tester --debug host Lock_top_quad

Change-Id: I2b220f323e259f5c7bfae06f6cf996b22e264555
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65278
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Evan Benn 2022-06-15 10:02:21 +10:00 committed by Edward O'Callaghan
parent c42ae261ae
commit a2fc6185e6
2 changed files with 26 additions and 2 deletions

View File

@ -289,17 +289,18 @@ fn partial_lock_test(section: LayoutNames) -> impl Fn(&mut TestEnv) -> TestResul
// Need a clean image for verification
env.ensure_golden()?;
let (name, start, len) = utils::layout_section(env.layout(), section);
let (wp_section_name, start, len) = utils::layout_section(env.layout(), section);
// Disable software WP so we can do range protection, but hardware WP
// must remain enabled for (most) range protection to do anything.
env.wp.set_hw(false)?.set_sw(false)?;
env.cmd.wp_range((start, len), true)?;
env.wp.set_hw(true)?;
// Check that we cannot write to the protected region.
let rws = flashrom::ROMWriteSpecifics {
layout_file: Some(LAYOUT_FILE),
write_file: Some(env.random_data_file()),
name_file: Some(name),
name_file: Some(wp_section_name),
};
if env.cmd.write_file_with_layout(&rws).is_ok() {
return Err(
@ -310,6 +311,17 @@ fn partial_lock_test(section: LayoutNames) -> impl Fn(&mut TestEnv) -> TestResul
if !env.is_golden() {
return Err("Section didn't lock, has been overwritten with random data!".into());
}
// Check that we can write to the non protected region.
let (non_wp_section_name, _, _) =
utils::layout_section(env.layout(), section.get_non_overlapping_section());
let rws = flashrom::ROMWriteSpecifics {
layout_file: Some(LAYOUT_FILE),
write_file: Some(env.random_data_file()),
name_file: Some(non_wp_section_name),
};
env.cmd.write_file_with_layout(&rws)?;
Ok(())
}
}

View File

@ -44,6 +44,18 @@ pub enum LayoutNames {
BottomQuad,
}
impl LayoutNames {
// Return a section that does not overlap
pub fn get_non_overlapping_section(&self) -> LayoutNames {
match self {
LayoutNames::TopQuad => LayoutNames::BottomQuad,
LayoutNames::TopHalf => LayoutNames::BottomHalf,
LayoutNames::BottomHalf => LayoutNames::TopHalf,
LayoutNames::BottomQuad => LayoutNames::TopQuad,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct LayoutSizes {
half_sz: i64,