@@ -54,7 +54,7 @@ use sha2::{Digest, Sha256, Sha384, Sha512};
5454//use smbioslib::*; 
5555use  smbioslib:: { DefinedStruct ,  SMBiosInformation } ; 
5656
57- use  crate :: chromium_ec:: { CrosEc ,  CrosEcDriverType } ; 
57+ use  crate :: chromium_ec:: { CrosEc ,  CrosEcDriverType ,   HardwareDeviceType } ; 
5858
5959#[ cfg( feature = "uefi" ) ]  
6060use  core:: prelude:: rust_2021:: derive; 
@@ -120,6 +120,8 @@ pub struct Cli {
120120    pub  versions :  bool , 
121121    pub  version :  bool , 
122122    pub  esrt :  bool , 
123+     pub  device :  Option < HardwareDeviceType > , 
124+     pub  compare_version :  Option < String > , 
123125    pub  power :  bool , 
124126    pub  thermal :  bool , 
125127    pub  sensors :  bool , 
@@ -506,6 +508,86 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
506508    } 
507509} 
508510
511+ fn  compare_version ( device :  Option < HardwareDeviceType > ,  version :  String ,  ec :  & CrosEc )  -> i32  { 
512+     println ! ( "Target Version {:?}" ,  version) ; 
513+ 
514+     if  let  Some ( smbios)  = get_smbios ( )  { 
515+         let  bios_entries = smbios. collect :: < SMBiosInformation > ( ) ; 
516+         let  bios = bios_entries. get ( 0 ) . unwrap ( ) ; 
517+ 
518+         if  device == Some ( HardwareDeviceType :: BIOS )  { 
519+             println ! ( "Comparing BIOS version {:?}" ,  bios. version( ) . to_string( ) ) ; 
520+             if  version. to_uppercase ( )  == bios. version ( ) . to_string ( ) . to_uppercase ( )  { 
521+                 return  0 ; 
522+             }  else  { 
523+                 return  1 ; 
524+             } 
525+         } 
526+     } 
527+ 
528+     if  device == Some ( HardwareDeviceType :: EC )  { 
529+         let  ver = print_err ( ec. version_info ( ) ) . unwrap_or_else ( || "UNKNOWN" . to_string ( ) ) ; 
530+         println ! ( "Comparing EC version {:?}" ,  ver) ; 
531+ 
532+         if  ver. contains ( & version)  { 
533+             return  0 ; 
534+         }  else  { 
535+             return  1 ; 
536+         } 
537+     } 
538+     if  device == Some ( HardwareDeviceType :: PD0 )  { 
539+         if  let  Ok ( pd_versions)  = ccgx:: get_pd_controller_versions ( ec)  { 
540+             let  ver = pd_versions. controller01 . main_fw . app . to_string ( ) ; 
541+             println ! ( "Comparing PD0 version {:?}" ,  ver) ; 
542+ 
543+             if  ver. contains ( & version)  { 
544+                 return  0 ; 
545+             }  else  { 
546+                 return  1 ; 
547+             } 
548+         } 
549+     } 
550+     if  device == Some ( HardwareDeviceType :: PD1 )  { 
551+         if  let  Ok ( pd_versions)  = ccgx:: get_pd_controller_versions ( ec)  { 
552+             let  ver = pd_versions. controller23 . main_fw . app . to_string ( ) ; 
553+             println ! ( "Comparing PD1 version {:?}" ,  ver) ; 
554+ 
555+             if  ver. contains ( & version)  { 
556+                 return  0 ; 
557+             }  else  { 
558+                 return  1 ; 
559+             } 
560+         } 
561+     } 
562+ 
563+     if  let  Some ( esrt)  = esrt:: get_esrt ( )  { 
564+         for  entry in  & esrt. entries  { 
565+             match  entry. fw_class  { 
566+                 esrt:: TGL_RETIMER01_GUID  | esrt:: ADL_RETIMER01_GUID  | esrt:: RPL_RETIMER01_GUID  => { 
567+                     if  device == Some ( HardwareDeviceType :: RTM01 )  { 
568+                         println ! ( "Comparing RTM01 version {:?}" ,  entry. fw_version. to_string( ) ) ; 
569+ 
570+                         if  entry. fw_version . to_string ( ) . contains ( & version)  { 
571+                             return  0 ; 
572+                         } 
573+                     } 
574+                 } 
575+                 esrt:: TGL_RETIMER23_GUID  | esrt:: ADL_RETIMER23_GUID  | esrt:: RPL_RETIMER23_GUID  => { 
576+                     if  device == Some ( HardwareDeviceType :: RTM23 )  { 
577+                         println ! ( "Comparing RTM23 version {:?}" ,  entry. fw_version. to_string( ) ) ; 
578+                         if  entry. fw_version . to_string ( ) . contains ( & version)  { 
579+                             return  0 ; 
580+                         } 
581+                     } 
582+                 } 
583+                 _ => { } 
584+             } 
585+         } 
586+     } 
587+ 
588+     1 
589+ } 
590+ 
509591pub  fn  run_with_args ( args :  & Cli ,  _allupdate :  bool )  -> i32  { 
510592    #[ cfg( feature = "uefi" ) ]  
511593    { 
@@ -563,6 +645,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
563645        print_tool_version ( ) ; 
564646    }  else  if  args. esrt  { 
565647        print_esrt ( ) ; 
648+     }  else  if  let  Some ( compare_version_ver)  = & args. compare_version  { 
649+         let  compare_ret = compare_version ( args. device ,  compare_version_ver. to_string ( ) ,  & ec) ; 
650+         println ! ( "Compared version:   {}" ,  compare_ret) ; 
651+         return  compare_ret; 
566652    }  else  if  args. intrusion  { 
567653        println ! ( "Chassis status:" ) ; 
568654        if  let  Some ( status)  = print_err ( ec. get_intrusion_status ( ) )  { 
@@ -653,7 +739,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
653739            return  1 ; 
654740        } 
655741    }  else  if  args. power  { 
656-         power:: get_and_print_power_info ( & ec) ; 
742+         return   power:: get_and_print_power_info ( & ec) ; 
657743    }  else  if  args. thermal  { 
658744        power:: print_thermal ( & ec) ; 
659745    }  else  if  args. sensors  { 
@@ -835,6 +921,8 @@ Options:
835921      --versions             List current firmware versions 
836922      --version              Show tool version information (Add -vv for more detailed information) 
837923      --esrt                 Display the UEFI ESRT table 
924+       --device <DEVICE>      Device used to compare firmware version [possible values: bios, ec, pd0, pd1, rtm01, rtm23] 
925+       --compare-version      Version string used to match firmware version (use with --device) 
838926      --power                Show current power status (battery and AC) 
839927      --thermal              Print thermal information (Temperatures and Fan speed) 
840928      --sensors              Print sensor information (ALS, G-Sensor) 
0 commit comments