From a2fc6185e68c1b5639abe2bfbfc915731cb2c5a9 Mon Sep 17 00:00:00 2001 From: Evan Benn Date: Wed, 15 Jun 2022 10:02:21 +1000 Subject: 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/65278 Reviewed-by: Edward O'Callaghan Reviewed-by: Peter Marheine Tested-by: build bot (Jenkins) --- util/flashrom_tester/src/tests.rs | 16 ++++++++++++++-- util/flashrom_tester/src/utils.rs | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'util/flashrom_tester/src') 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, -- cgit v1.2.3