diff options
author | Evan Benn <evanbenn@chromium.org> | 2022-06-01 12:45:01 +1000 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2022-08-26 05:07:09 +0000 |
commit | f6d9a2847e6b66a8f1415e04dc2bd13cc1d7e555 (patch) | |
tree | 857f5cd26ecdd05007114228d95284031fca4bd4 /util/flashrom_tester/src | |
parent | b41bb5622c08edb33cd83aa05973513db3869af0 (diff) | |
download | flashrom-f6d9a2847e6b66a8f1415e04dc2bd13cc1d7e555.tar.gz flashrom-f6d9a2847e6b66a8f1415e04dc2bd13cc1d7e555.tar.bz2 flashrom-f6d9a2847e6b66a8f1415e04dc2bd13cc1d7e555.zip |
flashrom_tester: Add an implementation using libflashrom
flashrom_tester 'flashrom' crate was implemented using the flashrom
commandline. Add a second implementation using the libflashrom interface
via the libflashrom and libflashrom-sys rust bindings.
BUG=b:230545739
BRANCH=None
TEST=cargo test
TEST=on grunt (AMD)
TEST=/usr/bin/flashrom_tester --libflashrom host
TEST=/usr/bin/flashrom_tester --flashrom_binary /usr/sbin/flashrom host
Change-Id: Ic4db6c829d7e8dc707a10c10e1ca0d9b8abccdec
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65282
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'util/flashrom_tester/src')
-rw-r--r-- | util/flashrom_tester/src/main.rs | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/util/flashrom_tester/src/main.rs b/util/flashrom_tester/src/main.rs index dd09f9a30..129d1a9b7 100644 --- a/util/flashrom_tester/src/main.rs +++ b/util/flashrom_tester/src/main.rs @@ -39,7 +39,7 @@ extern crate log; mod logger; use clap::{App, Arg}; -use flashrom::{FlashChip, Flashrom, FlashromCmd}; +use flashrom::{FlashChip, Flashrom, FlashromCmd, FlashromLib}; use flashrom_tester::{tester, tests}; use std::path::PathBuf; use std::sync::atomic::AtomicBool; @@ -65,7 +65,21 @@ fn main() { built_info::BUILT_TIME_UTC, built_info::RUSTC_VERSION, )) - .arg(Arg::with_name("flashrom_binary").required(true)) + .arg( + Arg::with_name("libflashrom") + .long("libflashrom") + .takes_value(false) + .help("Test the flashrom library instead of a binary"), + ) + .arg( + Arg::with_name("flashrom_binary") + .long("flashrom_binary") + .short("b") + .takes_value(true) + .required_unless("libflashrom") + .conflicts_with("libflashrom") + .help("Path to flashrom binary to test"), + ) .arg( Arg::with_name("ccd_target_type") .required(true) @@ -117,9 +131,6 @@ fn main() { let crossystem = flashrom_tester::utils::collect_crosssystem(&[]).expect("could not run crossystem"); - let flashrom_path = matches - .value_of("flashrom_binary") - .expect("flashrom_binary should be required"); let ccd_type = FlashChip::from( matches .value_of("ccd_target_type") @@ -127,10 +138,24 @@ fn main() { ) .expect("ccd_target_type should admit only known types"); - let cmd: Box<dyn Flashrom> = Box::new(FlashromCmd { - path: flashrom_path.to_string(), - fc: ccd_type, - }); + let cmd: Box<dyn Flashrom> = if matches.is_present("libflashrom") { + Box::new(FlashromLib::new( + ccd_type, + if matches.is_present("log_debug") { + flashrom::FLASHROM_MSG_DEBUG + } else { + flashrom::FLASHROM_MSG_WARN + }, + )) + } else { + Box::new(FlashromCmd { + path: matches + .value_of("flashrom_binary") + .expect("flashrom_binary is required") + .to_string(), + fc: ccd_type, + }) + }; let print_layout = matches.is_present("print-layout"); let output_format = matches |