@@ -820,24 +820,26 @@ impl CrosEc {
820
820
Ok ( result. valid )
821
821
}
822
822
823
- /// Requests recent console output from EC and constantly asks for more
823
+ /// Requests console output from EC and constantly asks for more
824
824
/// Prints the output and returns it when an error is encountered
825
- pub fn console_read ( & self ) -> EcResult < String > {
826
- let mut console = String :: new ( ) ;
825
+ pub fn console_read ( & self ) -> EcResult < ( ) > {
826
+ EcRequestConsoleSnapshot { } . send_command ( self ) ?;
827
+
827
828
let mut cmd = EcRequestConsoleRead {
828
- subcmd : ConsoleReadSubCommand :: ConsoleReadRecent as u8 ,
829
+ subcmd : ConsoleReadSubCommand :: ConsoleReadNext as u8 ,
829
830
} ;
830
-
831
- EcRequestConsoleSnapshot { } . send_command ( self ) ?;
832
831
loop {
833
832
match cmd. send_command_vec ( self ) {
834
833
Ok ( data) => {
835
- // EC Buffer is empty. We can wait a bit and see if there's more
836
- // Can't run it too quickly, otherwise the commands might fail
837
- if data. is_empty ( ) {
838
- trace ! ( "Empty EC response" ) ;
839
- println ! ( "---" ) ;
840
- os_specific:: sleep ( 1_000_000 ) ; // 1s
834
+ // EC Buffer is empty. That means we've read everything from the snapshot
835
+ // The windows crosecbus driver returns all NULL instead of empty response
836
+ if data. is_empty ( ) || data. iter ( ) . all ( |x| * x == 0 ) {
837
+ debug ! ( "Empty EC response. Stopping console read" ) ;
838
+ // Don't read too fast, wait a second before reading more
839
+ os_specific:: sleep ( 1_000_000 ) ;
840
+ EcRequestConsoleSnapshot { } . send_command ( self ) ?;
841
+ cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadRecent as u8 ;
842
+ continue ;
841
843
}
842
844
843
845
let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
@@ -846,35 +848,52 @@ impl CrosEc {
846
848
. replace ( [ '\0' ] , "" ) ;
847
849
848
850
print ! ( "{}" , ascii) ;
849
- console. push_str ( ascii. as_str ( ) ) ;
850
851
}
851
852
Err ( err) => {
852
853
error ! ( "Err: {:?}" , err) ;
853
- return Ok ( console) ;
854
- //return Err(err)
854
+ return Err ( err) ;
855
855
}
856
856
} ;
857
- cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadNext as u8 ;
858
857
859
858
// Need to explicitly handle CTRL-C termination on UEFI Shell
860
859
#[ cfg( feature = "uefi" ) ]
861
860
if shell_get_execution_break_flag ( ) {
862
- return Ok ( console ) ;
861
+ return Ok ( ( ) ) ;
863
862
}
864
863
}
865
864
}
866
865
866
+ /// Read all of EC console buffer and return it
867
867
pub fn console_read_one ( & self ) -> EcResult < String > {
868
868
EcRequestConsoleSnapshot { } . send_command ( self ) ?;
869
- let data = EcRequestConsoleRead {
870
- subcmd : ConsoleReadSubCommand :: ConsoleReadRecent as u8 ,
869
+
870
+ let mut console = String :: new ( ) ;
871
+ let cmd = EcRequestConsoleRead {
872
+ subcmd : ConsoleReadSubCommand :: ConsoleReadNext as u8 ,
873
+ } ;
874
+ loop {
875
+ match cmd. send_command_vec ( self ) {
876
+ Ok ( data) => {
877
+ // EC Buffer is empty. That means we've read everything
878
+ // The windows crosecbus driver returns all NULL instead of empty response
879
+ if data. is_empty ( ) || data. iter ( ) . all ( |x| * x == 0 ) {
880
+ debug ! ( "Empty EC response. Stopping console read" ) ;
881
+ return Ok ( console) ;
882
+ }
883
+
884
+ let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
885
+ let ascii = utf8
886
+ . replace ( |c : char | !c. is_ascii ( ) , "" )
887
+ . replace ( [ '\0' ] , "" ) ;
888
+
889
+ console. push_str ( ascii. as_str ( ) ) ;
890
+ }
891
+ Err ( err) => {
892
+ error ! ( "Err: {:?}" , err) ;
893
+ return Err ( err) ;
894
+ }
895
+ } ;
871
896
}
872
- . send_command_vec ( self ) ?;
873
- let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
874
- let ascii = utf8
875
- . replace ( |c : char | !c. is_ascii ( ) , "" )
876
- . replace ( [ '\0' ] , "" ) ;
877
- Ok ( ascii)
878
897
}
879
898
880
899
/// Check features supported by the firmware
0 commit comments