@@ -899,18 +899,66 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
899899}
900900
901901fn 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