@@ -201,6 +201,8 @@ pub struct Cli {
201201 pub help : bool ,
202202 pub info : bool ,
203203 pub flash_gpu_descriptor : Option < ( u8 , String ) > ,
204+ pub flash_gpu_descriptor_file : Option < String > ,
205+ pub dump_gpu_descriptor_file : Option < String > ,
204206 // UEFI only
205207 pub allupdate : bool ,
206208 pub paginate : bool ,
@@ -679,6 +681,24 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
679681 }
680682}
681683
684+ fn dump_dgpu_eeprom ( ec : & CrosEc , dump_path : & str ) {
685+ let flash_bin = ec. read_gpu_descriptor ( ) . unwrap ( ) ;
686+
687+ #[ cfg( not( feature = "uefi" ) ) ]
688+ {
689+ let mut file = fs:: File :: create ( dump_path) . unwrap ( ) ;
690+ file. write_all ( & flash_bin) . unwrap ( ) ;
691+ }
692+ #[ cfg( feature = "uefi" ) ]
693+ {
694+ let ret = crate :: uefi:: fs:: shell_write_file ( dump_path, & flash_bin) ;
695+ if ret. is_err ( ) {
696+ println ! ( "Failed to dump EC FW image." ) ;
697+ }
698+ }
699+ println ! ( "Wrote {} bytes to {}" , flash_bin. len( ) , dump_path) ;
700+ }
701+
682702fn compare_version ( device : Option < HardwareDeviceType > , version : String , ec : & CrosEc ) -> i32 {
683703 println ! ( "Target Version {:?}" , version) ;
684704
@@ -883,6 +903,26 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
883903 if let Err ( err) = ec. check_bay_status ( ) {
884904 error ! ( "{:?}" , err) ;
885905 }
906+ if let Ok ( header) = ec. read_gpu_desc_header ( ) {
907+ println ! ( " Expansion Bay EEPROM" ) ;
908+ println ! (
909+ " Valid: {:?}" ,
910+ header. magic == [ 0x32 , 0xAC , 0x00 , 0x00 ]
911+ ) ;
912+ println ! ( " HW Version: {}.{}" , { header. hardware_version } , {
913+ header. hardware_revision
914+ } ) ;
915+ if log_enabled ! ( Level :: Info ) {
916+ println ! ( " Hdr Length {} B" , { header. length } ) ;
917+ println ! ( " Desc Ver: {}.{}" , { header. desc_ver_major } , {
918+ header. desc_ver_minor
919+ } ) ;
920+ println ! ( " Serialnumber:{:X?}" , { header. serial } ) ;
921+ println ! ( " Desc Length: {} B" , { header. descriptor_length } ) ;
922+ println ! ( " Desc CRC: {:X}" , { header. descriptor_crc32 } ) ;
923+ println ! ( " Hdr CRC: {:X}" , { header. crc32 } ) ;
924+ }
925+ }
886926 } else if let Some ( maybe_limit) = args. charge_limit {
887927 print_err ( handle_charge_limit ( & ec, maybe_limit) ) ;
888928 } else if let Some ( ( limit, soc) ) = args. charge_current_limit {
@@ -1220,6 +1260,38 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
12201260 Ok ( x) => println ! ( "GPU Descriptor write failed with status code: {}" , x) ,
12211261 Err ( err) => println ! ( "GPU Descriptor write failed with error: {:?}" , err) ,
12221262 }
1263+ } else if let Some ( gpu_descriptor_file) = & args. flash_gpu_descriptor_file {
1264+ if matches ! (
1265+ smbios:: get_family( ) ,
1266+ Some ( PlatformFamily :: Framework16 ) | None
1267+ ) {
1268+ #[ cfg( feature = "uefi" ) ]
1269+ let data: Option < Vec < u8 > > = crate :: uefi:: fs:: shell_read_file ( gpu_descriptor_file) ;
1270+ #[ cfg( not( feature = "uefi" ) ) ]
1271+ let data = match fs:: read ( gpu_descriptor_file) {
1272+ Ok ( data) => Some ( data) ,
1273+ // TODO: Perhaps a more user-friendly error
1274+ Err ( e) => {
1275+ println ! ( "Error {:?}" , e) ;
1276+ None
1277+ }
1278+ } ;
1279+ if let Some ( data) = data {
1280+ println ! ( "File" ) ;
1281+ println ! ( " Size: {:>20} B" , data. len( ) ) ;
1282+ println ! ( " Size: {:>20} KB" , data. len( ) / 1024 ) ;
1283+ let res = ec. set_gpu_descriptor ( & data, args. dry_run ) ;
1284+ match res {
1285+ Ok ( ( ) ) => println ! ( "GPU Descriptor successfully written" ) ,
1286+ Err ( err) => println ! ( "GPU Descriptor write failed with error: {:?}" , err) ,
1287+ }
1288+ }
1289+ } else {
1290+ println ! ( "Unsupported on this platform" ) ;
1291+ }
1292+ } else if let Some ( dump_path) = & args. dump_gpu_descriptor_file {
1293+ println ! ( "Dumping to {}" , dump_path) ;
1294+ dump_dgpu_eeprom ( & ec, dump_path) ;
12231295 }
12241296
12251297 0
@@ -1275,6 +1347,7 @@ Options:
12751347 --console <CONSOLE> Get EC console, choose whether recent or to follow the output [possible values: recent, follow]
12761348 --hash <HASH> Hash a file of arbitrary data
12771349 --flash-gpu-descriptor <MAGIC> <18 DIGIT SN> Overwrite the GPU bay descriptor SN and type.
1350+ --flash-gpu-descriptor-file <DESCRIPTOR_FILE> Write the GPU bay descriptor with a descriptor file.
12781351 -f, --force Force execution of an unsafe command - may render your hardware unbootable!
12791352 --dry-run Simulate execution of a command (e.g. --flash-ec)
12801353 -t, --test Run self-test to check if interaction with EC is possible
0 commit comments