diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 2b3d7e9..bdac200 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -1526,6 +1526,24 @@ impl CrosEc { return_val } + pub fn validate_gpu_descriptor(&self, reference_desc: &[u8]) -> EcResult { + let current_desc = self.read_gpu_descriptor()?; + let max_len = core::cmp::max(current_desc.len(), reference_desc.len()); + let mut valid = true; + for i in 0..max_len { + let expected = reference_desc.get(i); + let actual = current_desc.get(i); + if expected != actual { + println!( + " Offset 0x{:04X}: expected {:02X?}, got {:02X?}", + i, expected, actual + ); + valid = false; + } + } + Ok(valid) + } + pub fn read_gpu_descriptor(&self) -> EcResult> { let header = self.read_gpu_desc_header()?; if header.magic != [0x32, 0xAC, 0x00, 0x00] { diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 829b27d..b218364 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -309,6 +309,10 @@ struct ClapCli { #[arg(long)] dump_gpu_descriptor_file: Option, + /// File to validate the gpu EEPROM against + #[arg(long)] + validate_gpu_descriptor_file: Option, + /// Show NVIDIA GPU information (Framework 16 only) #[arg(long)] nvidia: bool, @@ -564,6 +568,9 @@ pub fn parse(args: &[String]) -> Cli { dump_gpu_descriptor_file: args .dump_gpu_descriptor_file .map(|x| x.into_os_string().into_string().unwrap()), + validate_gpu_descriptor_file: args + .validate_gpu_descriptor_file + .map(|x| x.into_os_string().into_string().unwrap()), nvidia: args.nvidia, host_command, } diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 7114c7a..2ff067a 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -227,6 +227,7 @@ pub struct Cli { pub flash_gpu_descriptor: Option<(u8, String)>, pub flash_gpu_descriptor_file: Option, pub dump_gpu_descriptor_file: Option, + pub validate_gpu_descriptor_file: Option, pub nvidia: bool, // UEFI only pub allupdate: bool, @@ -1807,7 +1808,15 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { println!(" Size: {:>20} KB", data.len() / 1024); let res = ec.set_gpu_descriptor(&data, args.dry_run); match res { - Ok(()) => println!("GPU Descriptor successfully written"), + Ok(()) => { + println!("GPU Descriptor successfully written"); + println!("Validating GPU Descriptor..."); + match ec.validate_gpu_descriptor(&data) { + Ok(true) => println!(" Validation passed"), + Ok(false) => println!(" Validation FAILED: read-back mismatch"), + Err(err) => println!(" Validation error: {:?}", err), + } + } Err(err) => println!("GPU Descriptor write failed with error: {:?}", err), } } @@ -1819,6 +1828,25 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { println!("Dumping to {}", dump_path); } dump_dgpu_eeprom(&ec, dump_path); + } else if let Some(validate_path) = &args.validate_gpu_descriptor_file { + #[cfg(feature = "uefi")] + let data: Option> = crate::fw_uefi::fs::shell_read_file(validate_path); + #[cfg(not(feature = "uefi"))] + let data = match fs::read(validate_path) { + Ok(data) => Some(data), + Err(e) => { + println!("Error {:?}", e); + None + } + }; + if let Some(data) = data { + println!("Validating GPU Descriptor against {}", validate_path); + match ec.validate_gpu_descriptor(&data) { + Ok(true) => println!(" Validation passed"), + Ok(false) => println!(" Validation FAILED: read-back mismatch"), + Err(err) => println!(" Validation error: {:?}", err), + } + } } 0 diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index e86c517..5d9eae2 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -101,6 +101,7 @@ pub fn parse(args: &[String]) -> Cli { flash_gpu_descriptor: None, flash_gpu_descriptor_file: None, dump_gpu_descriptor_file: None, + validate_gpu_descriptor_file: None, allupdate: false, info: false, meinfo: None, @@ -859,6 +860,14 @@ pub fn parse(args: &[String]) -> Cli { None }; found_an_option = true; + } else if arg == "--validate-gpu-descriptor-file" { + cli.validate_gpu_descriptor_file = if args.len() > i + 1 { + Some(args[i + 1].clone()) + } else { + println!("Need to provide a value for --validate-gpu-descriptor-file. PATH"); + None + }; + found_an_option = true; } } diff --git a/framework_tool/completions/bash/framework_tool b/framework_tool/completions/bash/framework_tool index 8a3d515..da6bc45 100755 --- a/framework_tool/completions/bash/framework_tool +++ b/framework_tool/completions/bash/framework_tool @@ -23,7 +23,7 @@ _framework_tool() { case "${cmd}" in framework_tool) - 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" + 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" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -201,6 +201,10 @@ _framework_tool() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --validate-gpu-descriptor-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --host-command) COMPREPLY=($(compgen -f "${cur}")) return 0 diff --git a/framework_tool/completions/fish/framework_tool.fish b/framework_tool/completions/fish/framework_tool.fish index 47df44a..1d88e9b 100644 --- a/framework_tool/completions/fish/framework_tool.fish +++ b/framework_tool/completions/fish/framework_tool.fish @@ -65,6 +65,7 @@ complete -c framework_tool -l pd-addrs -d 'Specify I2C addresses of the PD chips complete -c framework_tool -l pd-ports -d 'Specify I2C ports of the PD chips (Advanced)' -r complete -c framework_tool -l flash-gpu-descriptor-file -d 'File to write to the gpu EEPROM' -r -F complete -c framework_tool -l dump-gpu-descriptor-file -d 'File to dump the gpu EEPROM to' -r -F +complete -c framework_tool -l validate-gpu-descriptor-file -d 'File to validate the gpu EEPROM against' -r -F complete -c framework_tool -l host-command -d 'Send an EC host command. Args: [DATA...]' -r complete -c framework_tool -l generate-completions -d 'Generate shell completions and print to stdout' -r -f -a "bash\t'' elvish\t'' diff --git a/framework_tool/completions/zsh/_framework_tool b/framework_tool/completions/zsh/_framework_tool index cb3230d..ee7de09 100644 --- a/framework_tool/completions/zsh/_framework_tool +++ b/framework_tool/completions/zsh/_framework_tool @@ -58,6 +58,7 @@ _framework_tool() { '*--pd-ports=[Specify I2C ports of the PD chips (Advanced)]:PD_PORTS:_default:PD_PORTS:_default:PD_PORTS:_default' \ '--flash-gpu-descriptor-file=[File to write to the gpu EEPROM]:FLASH_GPU_DESCRIPTOR_FILE:_files' \ '--dump-gpu-descriptor-file=[File to dump the gpu EEPROM to]:DUMP_GPU_DESCRIPTOR_FILE:_files' \ +'--validate-gpu-descriptor-file=[File to validate the gpu EEPROM against]:VALIDATE_GPU_DESCRIPTOR_FILE:_files' \ '*--host-command=[Send an EC host command. Args\: \[DATA...\]]:HOST_COMMAND:_default:HOST_COMMAND:_default' \ '--generate-completions=[Generate shell completions and print to stdout]:SHELL:(bash elvish fish powershell zsh)' \ '*-v[Increase logging verbosity]' \