diff options
author | Evan Benn <evanbenn@chromium.org> | 2022-06-15 10:02:21 +1000 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2022-07-21 23:29:30 +0000 |
commit | a2fc6185e68c1b5639abe2bfbfc915731cb2c5a9 (patch) | |
tree | 2b76bd8c3f160f436fdb43bc5a2ad38d35be7a32 /util | |
parent | c42ae261ae299ea932403a6081fdfc8aa606e8fb (diff) | |
download | flashrom-a2fc6185e68c1b5639abe2bfbfc915731cb2c5a9.tar.gz flashrom-a2fc6185e68c1b5639abe2bfbfc915731cb2c5a9.tar.bz2 flashrom-a2fc6185e68c1b5639abe2bfbfc915731cb2c5a9.zip |
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>
Diffstat (limited to 'util')
-rw-r--r-- | util/flashrom_tester/src/tests.rs | 16 | ||||
-rw-r--r-- | util/flashrom_tester/src/utils.rs | 12 |
2 files changed, 26 insertions, 2 deletions
diff --git a/util/flashrom_tester/src/tests.rs b/util/flashrom_tester/src/tests.rs index e0824283..8d5f19e8 100644 --- a/util/flashrom_tester/src/tests.rs +++ b/util/flashrom_tester/src/tests.rs @@ -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(()) } } diff --git a/util/flashrom_tester/src/utils.rs b/util/flashrom_tester/src/utils.rs index 8d3c3191..5a932a06 100644 --- a/util/flashrom_tester/src/utils.rs +++ b/util/flashrom_tester/src/utils.rs @@ -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, |