@@ -822,22 +822,23 @@ impl CrosEc {
822
822
823
823
/// Requests recent 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
834
+ // EC Buffer is empty. That means we've read everything from the snapshot
837
835
if data. is_empty ( ) {
838
- trace ! ( "Empty EC response" ) ;
839
- println ! ( "---" ) ;
840
- os_specific:: sleep ( 1_000_000 ) ; // 1s
836
+ debug ! ( "Empty EC response. Stopping console read" ) ;
837
+ // Don't read too fast, wait a second before reading more
838
+ os_specific:: sleep ( 1_000_000 ) ;
839
+ EcRequestConsoleSnapshot { } . send_command ( self ) ?;
840
+ cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadRecent as u8 ;
841
+ continue ;
841
842
}
842
843
843
844
let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
@@ -846,35 +847,51 @@ impl CrosEc {
846
847
. replace ( [ '\0' ] , "" ) ;
847
848
848
849
print ! ( "{}" , ascii) ;
849
- console. push_str ( ascii. as_str ( ) ) ;
850
850
}
851
851
Err ( err) => {
852
852
error ! ( "Err: {:?}" , err) ;
853
- return Ok ( console) ;
854
- //return Err(err)
853
+ return Err ( err) ;
855
854
}
856
855
} ;
857
- cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadNext as u8 ;
858
856
859
857
// Need to explicitly handle CTRL-C termination on UEFI Shell
860
858
#[ cfg( feature = "uefi" ) ]
861
859
if shell_get_execution_break_flag ( ) {
862
- return Ok ( console ) ;
860
+ return Ok ( ( ) ) ;
863
861
}
864
862
}
865
863
}
866
864
865
+ /// Read all of EC console buffer and return it
867
866
pub fn console_read_one ( & self ) -> EcResult < String > {
868
867
EcRequestConsoleSnapshot { } . send_command ( self ) ?;
869
- let data = EcRequestConsoleRead {
870
- subcmd : ConsoleReadSubCommand :: ConsoleReadRecent as u8 ,
868
+
869
+ let mut console = String :: new ( ) ;
870
+ let cmd = EcRequestConsoleRead {
871
+ subcmd : ConsoleReadSubCommand :: ConsoleReadNext as u8 ,
872
+ } ;
873
+ loop {
874
+ match cmd. send_command_vec ( self ) {
875
+ Ok ( data) => {
876
+ // EC Buffer is empty. That means we've read everything
877
+ if data. is_empty ( ) {
878
+ debug ! ( "Empty EC response. Stopping console read" ) ;
879
+ return Ok ( console) ;
880
+ }
881
+
882
+ let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
883
+ let ascii = utf8
884
+ . replace ( |c : char | !c. is_ascii ( ) , "" )
885
+ . replace ( [ '\0' ] , "" ) ;
886
+
887
+ console. push_str ( ascii. as_str ( ) ) ;
888
+ }
889
+ Err ( err) => {
890
+ error ! ( "Err: {:?}" , err) ;
891
+ return Err ( err) ;
892
+ }
893
+ } ;
871
894
}
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
895
}
879
896
880
897
/// Check features supported by the firmware
0 commit comments