Skip to content

Commit c46e7e4

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 c46e7e4

6 files changed

Lines changed: 43 additions & 1 deletion

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

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 --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 --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
@@ -201,6 +201,10 @@ _framework_tool() {
201201
COMPREPLY=($(compgen -f "${cur}"))
202202
return 0
203203
;;
204+
--validate-gpu-descriptor-file)
205+
COMPREPLY=($(compgen -f "${cur}"))
206+
return 0
207+
;;
204208
--host-command)
205209
COMPREPLY=($(compgen -f "${cur}"))
206210
return 0

framework_tool/completions/fish/framework_tool.fish

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

framework_tool/completions/zsh/_framework_tool

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

0 commit comments

Comments
 (0)