Skip to content

Commit 3f20827

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 836f725 commit 3f20827

6 files changed

Lines changed: 44 additions & 2 deletions

File tree

framework_lib/src/commandline/clap_std.rs

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

330+
/// File to validate the gpu EEPROM against
331+
#[arg(long)]
332+
validate_gpu_descriptor_file: Option<std::path::PathBuf>,
333+
330334
/// Show NVIDIA GPU information (Laptop 16 only)
331335
#[arg(long)]
332336
nvidia: bool,
@@ -584,6 +588,9 @@ pub fn parse(args: &[String]) -> Cli {
584588
dump_gpu_descriptor_file: args
585589
.dump_gpu_descriptor_file
586590
.map(|x| x.into_os_string().into_string().unwrap()),
591+
validate_gpu_descriptor_file: args
592+
.validate_gpu_descriptor_file
593+
.map(|x| x.into_os_string().into_string().unwrap()),
587594
nvidia: args.nvidia,
588595
host_command,
589596
}

framework_lib/src/commandline/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ pub struct Cli {
250250
pub flash_gpu_descriptor: Option<(u8, String)>,
251251
pub flash_gpu_descriptor_file: Option<String>,
252252
pub dump_gpu_descriptor_file: Option<String>,
253+
pub validate_gpu_descriptor_file: Option<String>,
253254
pub nvidia: bool,
254255
// UEFI only
255256
pub allupdate: bool,
@@ -1878,6 +1879,25 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
18781879
println!("Dumping to {}", dump_path);
18791880
}
18801881
dump_dgpu_eeprom(&ec, dump_path);
1882+
} else if let Some(validate_path) = &args.validate_gpu_descriptor_file {
1883+
#[cfg(feature = "uefi")]
1884+
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(validate_path);
1885+
#[cfg(not(feature = "uefi"))]
1886+
let data = match fs::read(validate_path) {
1887+
Ok(data) => Some(data),
1888+
Err(e) => {
1889+
println!("Error {:?}", e);
1890+
None
1891+
}
1892+
};
1893+
if let Some(data) = data {
1894+
println!("Validating GPU Descriptor against {}", validate_path);
1895+
match ec.validate_gpu_descriptor(&data) {
1896+
Ok(true) => println!(" Validation passed"),
1897+
Ok(false) => println!(" Validation FAILED: read-back mismatch"),
1898+
Err(err) => println!(" Validation error: {:?}", err),
1899+
}
1900+
}
18811901
}
18821902

18831903
0

framework_lib/src/commandline/uefi.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn parse(args: &[String]) -> Cli {
103103
flash_gpu_descriptor: None,
104104
flash_gpu_descriptor_file: None,
105105
dump_gpu_descriptor_file: None,
106+
validate_gpu_descriptor_file: None,
106107
allupdate: false,
107108
info: false,
108109
meinfo: None,
@@ -859,7 +860,15 @@ pub fn parse(args: &[String]) -> Cli {
859860
cli.dump_gpu_descriptor_file = if args.len() > i + 1 {
860861
Some(args[i + 1].clone())
861862
} else {
862-
println!("Need to provide a value for --dump_gpu_descriptor_file. PATH");
863+
println!("Need to provide a value for --dump-gpu-descriptor-file. PATH");
864+
None
865+
};
866+
found_an_option = true;
867+
} else if arg == "--validate-gpu-descriptor-file" {
868+
cli.validate_gpu_descriptor_file = if args.len() > i + 1 {
869+
Some(args[i + 1].clone())
870+
} else {
871+
println!("Need to provide a value for --validate-gpu-descriptor-file. PATH");
863872
None
864873
};
865874
found_an_option = true;

framework_tool/completions/bash/framework_tool

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _framework_tool() {
2323

2424
case "${cmd}" in
2525
framework_tool)
26-
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
26+
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --validate-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
2727
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2828
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2929
return 0
@@ -209,6 +209,10 @@ _framework_tool() {
209209
COMPREPLY=($(compgen -f "${cur}"))
210210
return 0
211211
;;
212+
--validate-gpu-descriptor-file)
213+
COMPREPLY=($(compgen -f "${cur}"))
214+
return 0
215+
;;
212216
--host-command)
213217
COMPREPLY=($(compgen -f "${cur}"))
214218
return 0

framework_tool/completions/fish/framework_tool.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ complete -c framework_tool -l pd-addrs -d 'Specify I2C addresses of the PD chips
7474
complete -c framework_tool -l pd-ports -d 'Specify I2C ports of the PD chips (Advanced)' -r
7575
complete -c framework_tool -l flash-gpu-descriptor-file -d 'File to write to the gpu EEPROM' -r -F
7676
complete -c framework_tool -l dump-gpu-descriptor-file -d 'File to dump the gpu EEPROM to' -r -F
77+
complete -c framework_tool -l validate-gpu-descriptor-file -d 'File to validate the gpu EEPROM against' -r -F
7778
complete -c framework_tool -l host-command -d 'Send an EC host command. Args: <CMD_ID> <VERSION> [DATA...]' -r
7879
complete -c framework_tool -l generate-completions -d 'Generate shell completions and print to stdout' -r -f -a "bash\t''
7980
elvish\t''

framework_tool/completions/zsh/_framework_tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ _framework_tool() {
6060
'*--pd-ports=[Specify I2C ports of the PD chips (Advanced)]:PD_PORTS:_default:PD_PORTS:_default:PD_PORTS:_default' \
6161
'--flash-gpu-descriptor-file=[File to write to the gpu EEPROM]:FLASH_GPU_DESCRIPTOR_FILE:_files' \
6262
'--dump-gpu-descriptor-file=[File to dump the gpu EEPROM to]:DUMP_GPU_DESCRIPTOR_FILE:_files' \
63+
'--validate-gpu-descriptor-file=[File to validate the gpu EEPROM against]:VALIDATE_GPU_DESCRIPTOR_FILE:_files' \
6364
'*--host-command=[Send an EC host command. Args\: <CMD_ID> <VERSION> \[DATA...\]]:HOST_COMMAND:_default:HOST_COMMAND:_default' \
6465
'--generate-completions=[Generate shell completions and print to stdout]:SHELL:(bash elvish fish powershell zsh)' \
6566
'*-v[Increase logging verbosity]' \

0 commit comments

Comments
 (0)