@@ -822,22 +822,23 @@ impl CrosEc {
822822
823823 /// Requests recent 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
834+ // EC Buffer is empty. That means we've read everything from the snapshot
837835 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 ;
841842 }
842843
843844 let utf8 = std:: str:: from_utf8 ( & data) . unwrap ( ) ;
@@ -846,35 +847,51 @@ impl CrosEc {
846847 . replace ( [ '\0' ] , "" ) ;
847848
848849 print ! ( "{}" , ascii) ;
849- console. push_str ( ascii. as_str ( ) ) ;
850850 }
851851 Err ( err) => {
852852 error ! ( "Err: {:?}" , err) ;
853- return Ok ( console) ;
854- //return Err(err)
853+ return Err ( err) ;
855854 }
856855 } ;
857- cmd. subcmd = ConsoleReadSubCommand :: ConsoleReadNext as u8 ;
858856
859857 // Need to explicitly handle CTRL-C termination on UEFI Shell
860858 #[ cfg( feature = "uefi" ) ]
861859 if shell_get_execution_break_flag ( ) {
862- return Ok ( console ) ;
860+ return Ok ( ( ) ) ;
863861 }
864862 }
865863 }
866864
865+ /// Read all of EC console buffer and return it
867866 pub fn console_read_one ( & self ) -> EcResult < String > {
868867 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+ } ;
871894 }
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)
878895 }
879896
880897 /// Check features supported by the firmware
0 commit comments