Skip to content

Commit f9afcfe

Browse files
committed
Improve --dump-gpu-descriptor-file
`--dump-gpu-descriptor-file -` now prints to stdout instead of writing to a file for easier debugging. If the structure is corrupt, we can still dump all 256 bytes. More error reporting to figure out what's wrong if something is wrong. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 72af966 commit f9afcfe

2 files changed

Lines changed: 58 additions & 8 deletions

File tree

framework_lib/src/chromium_ec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ impl CrosEc {
13121312
data.extend(i2c_response.data);
13131313
}
13141314

1315-
Ok(data)
1315+
Ok(data[..(len.into())].to_vec())
13161316
}
13171317

13181318
pub fn write_ec_gpu_chunk(&self, offset: u16, data: &[u8]) -> EcResult<()> {

framework_lib/src/commandline/mod.rs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -899,18 +899,66 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
899899
}
900900

901901
fn dump_dgpu_eeprom(ec: &CrosEc, dump_path: &str) {
902-
let flash_bin = ec.read_gpu_descriptor().unwrap();
902+
// Read raw bytes from EEPROM
903+
let raw_bytes = match ec.read_ec_gpu_chunk(0x00, 256) {
904+
Ok(data) => data,
905+
Err(err) => {
906+
error!("Failed to read EEPROM: {:?}", err);
907+
return;
908+
}
909+
};
910+
911+
// For stdout, just print the raw bytes
912+
if dump_path == "-" {
913+
println!("{:02X?}", raw_bytes);
914+
println!("Read {} bytes from EEPROM", raw_bytes.len());
915+
return;
916+
}
917+
918+
// Check if header is valid by examining magic bytes
919+
let expected_magic = [0x32, 0xAC, 0x00, 0x00];
920+
let has_valid_header = raw_bytes.len() >= 4 && raw_bytes[0..4] == expected_magic;
921+
922+
let flash_bin = if has_valid_header {
923+
// Header looks valid, try to read the full descriptor
924+
match ec.read_gpu_descriptor() {
925+
Ok(data) => data,
926+
Err(err) => {
927+
error!("GPU descriptor read failed: {:?}", err);
928+
println!("Falling back to raw EEPROM dump (256 bytes)");
929+
raw_bytes
930+
}
931+
}
932+
} else {
933+
error!(
934+
"GPU descriptor invalid: magic {:02X?} != expected {:02X?}",
935+
&raw_bytes[0..4],
936+
expected_magic
937+
);
938+
println!("Dumping raw EEPROM (256 bytes)");
939+
raw_bytes
940+
};
903941

904942
#[cfg(not(feature = "uefi"))]
905943
{
906-
let mut file = fs::File::create(dump_path).unwrap();
907-
file.write_all(&flash_bin).unwrap();
944+
match fs::File::create(dump_path) {
945+
Ok(mut file) => {
946+
if let Err(err) = file.write_all(&flash_bin) {
947+
error!("Failed to write file: {:?}", err);
948+
return;
949+
}
950+
}
951+
Err(err) => {
952+
error!("Failed to create file: {:?}", err);
953+
return;
954+
}
955+
}
908956
}
909957
#[cfg(feature = "uefi")]
910958
{
911-
let ret = crate::uefi::fs::shell_write_file(dump_path, &flash_bin);
912-
if ret.is_err() {
913-
println!("Failed to dump EC FW image.");
959+
if let Err(err) = crate::uefi::fs::shell_write_file(dump_path, &flash_bin) {
960+
error!("Failed to dump EC FW image: {:?}", err);
961+
return;
914962
}
915963
}
916964
println!("Wrote {} bytes to {}", flash_bin.len(), dump_path);
@@ -1531,7 +1579,9 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
15311579
println!("Unsupported on this platform");
15321580
}
15331581
} else if let Some(dump_path) = &args.dump_gpu_descriptor_file {
1534-
println!("Dumping to {}", dump_path);
1582+
if dump_path != "-" {
1583+
println!("Dumping to {}", dump_path);
1584+
}
15351585
dump_dgpu_eeprom(&ec, dump_path);
15361586
}
15371587

0 commit comments

Comments
 (0)