1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-02 06:23:18 +02:00

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>
This commit is contained in:
Evan Benn
2022-06-01 12:45:01 +10:00
committed by Edward O'Callaghan
parent b41bb5622c
commit f6d9a2847e
4 changed files with 210 additions and 10 deletions

View File

@ -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