Skip to content

Commit e1a4c5d

Browse files
committed
Add --validate-gpu-descriptor command
To purely validate that the current EEPROM matches a local file and print the diff if not. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 44f1501 commit e1a4c5d

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

framework_lib/src/commandline/clap_std.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ struct ClapCli {
309309
#[arg(long)]
310310
dump_gpu_descriptor_file: Option<std::path::PathBuf>,
311311

312+
/// File to validate the gpu EEPROM against
313+
#[arg(long)]
314+
validate_gpu_descriptor_file: Option<std::path::PathBuf>,
315+
312316
/// Show NVIDIA GPU information (Framework 16 only)
313317
#[arg(long)]
314318
nvidia: bool,
@@ -564,6 +568,9 @@ pub fn parse(args: &[String]) -> Cli {
564568
dump_gpu_descriptor_file: args
565569
.dump_gpu_descriptor_file
566570
.map(|x| x.into_os_string().into_string().unwrap()),
571+
validate_gpu_descriptor_file: args
572+
.validate_gpu_descriptor_file
573+
.map(|x| x.into_os_string().into_string().unwrap()),
567574
nvidia: args.nvidia,
568575
host_command,
569576
}

framework_lib/src/commandline/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ pub struct Cli {
227227
pub flash_gpu_descriptor: Option<(u8, String)>,
228228
pub flash_gpu_descriptor_file: Option<String>,
229229
pub dump_gpu_descriptor_file: Option<String>,
230+
pub validate_gpu_descriptor_file: Option<String>,
230231
pub nvidia: bool,
231232
// UEFI only
232233
pub allupdate: bool,
@@ -1827,6 +1828,25 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
18271828
println!("Dumping to {}", dump_path);
18281829
}
18291830
dump_dgpu_eeprom(&ec, dump_path);
1831+
} else if let Some(validate_path) = &args.validate_gpu_descriptor_file {
1832+
#[cfg(feature = "uefi")]
1833+
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(validate_path);
1834+
#[cfg(not(feature = "uefi"))]
1835+
let data = match fs::read(validate_path) {
1836+
Ok(data) => Some(data),
1837+
Err(e) => {
1838+
println!("Error {:?}", e);
1839+
None
1840+
}
1841+
};
1842+
if let Some(data) = data {
1843+
println!("Validating GPU Descriptor against {}", validate_path);
1844+
match ec.validate_gpu_descriptor(&data) {
1845+
Ok(true) => println!(" Validation passed"),
1846+
Ok(false) => println!(" Validation FAILED: read-back mismatch"),
1847+
Err(err) => println!(" Validation error: {:?}", err),
1848+
}
1849+
}
18301850
}
18311851

18321852
0

framework_lib/src/commandline/uefi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn parse(args: &[String]) -> Cli {
101101
flash_gpu_descriptor: None,
102102
flash_gpu_descriptor_file: None,
103103
dump_gpu_descriptor_file: None,
104+
validate_gpu_descriptor_file: None,
104105
allupdate: false,
105106
info: false,
106107
meinfo: None,
@@ -859,6 +860,14 @@ pub fn parse(args: &[String]) -> Cli {
859860
None
860861
};
861862
found_an_option = true;
863+
} else if arg == "--validate-gpu-descriptor-file" {
864+
cli.validate_gpu_descriptor_file = if args.len() > i + 1 {
865+
Some(args[i + 1].clone())
866+
} else {
867+
println!("Need to provide a value for --validate_gpu_descriptor_file. PATH");
868+
None
869+
};
870+
found_an_option = true;
862871
}
863872
}
864873

0 commit comments

Comments
 (0)