@@ -820,24 +820,26 @@ impl CrosEc {
820820 Ok ( result. valid )
821821 }
822822
823- /// Requests recent console output from EC and constantly asks for more
823+ /// Requests console output from EC and constantly asks for more
824824 /// 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+
827828 let mut cmd = EcRequestConsoleRead {
828- subcmd : ConsoleReadSubCommand :: ConsoleReadRecent as u8 ,
829+ subcmd : ConsoleReadSubCommand :: ConsoleReadNext as u8 ,
829830 } ;
830-
831- EcRequestConsoleSnapshot { } . send_command ( self ) ?;
832831 loop {
833832 match cmd. send_command_vec ( self ) {
834833 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 ;
841843 }
842844
843845 let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
@@ -846,35 +848,52 @@ impl CrosEc {
846848 . replace ( [ '\0' ] , "" ) ;
847849
848850 print ! ( "{}" , ascii) ;
849- console. push_str ( ascii. as_str ( ) ) ;
850851 }
851852 Err ( err) => {
852853 error ! ( "Err: {:?}" , err) ;
853- return Ok ( console) ;
854- //return Err(err)
854+ return Err ( err) ;
855855 }
856856 } ;
857- cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadNext as u8 ;
858857
859858 // Need to explicitly handle CTRL-C termination on UEFI Shell
860859 #[ cfg( feature = "uefi" ) ]
861860 if shell_get_execution_break_flag ( ) {
862- return Ok ( console ) ;
861+ return Ok ( ( ) ) ;
863862 }
864863 }
865864 }
866865
866+ /// Read all of EC console buffer and return it
867867 pub fn console_read_one ( & self ) -> EcResult < String > {
868868 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+ } ;
871896 }
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)
878897 }
879898
880899 /// Check features supported by the firmware
0 commit comments