From: Guo-Fu Tseng <[email protected]>

Currently we do nothing while polling user input when shell banner
waiting. I modified it to do something like in shell, scheduling
processes while waiting for user input.

We can have two improvements in this way.

First:
        Increase the key response in shell banner. It is much more
        likely to successful get into shell then before. By former
        experience, I sometimes did pressed the CTRL_B, but fail to get
        into shell. It might caused by waiting too long in mdelay(100).

Second:
        While using scripts, if the downloaded image is not bootable,
        the gPXE exits faster than it have the opportunity to gracefully
        closing the TCP connection. Which might lead the TCP state of
        remote server not closed.

        It actually waits for user to input for 2 seconds by default
        before returning control to BIOS. This commit let TCP have the
        opportunity to gracefully close while waiting for user to hit
        keys in shell banner.

Referenced: Michael Brown <[email protected]>
Signed-off-by: Guo-Fu Tseng <[email protected]>
---
 src/core/getkey.c      |    2 +-
 src/hci/shell_banner.c |   19 ++++---------------
 src/include/console.h  |    1 +
 3 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/src/core/getkey.c b/src/core/getkey.c
index dbd074c..15c57e5 100644
--- a/src/core/getkey.c
+++ b/src/core/getkey.c
@@ -38,7 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @v timeout          Timeout period, in ticks
  * @ret character      Character read from console
  */
-static int getchar_timeout ( unsigned long timeout ) {
+int getchar_timeout ( unsigned long timeout ) {
        unsigned long expiry = ( currticks() + timeout );
 
        while ( currticks() < expiry ) {
diff --git a/src/hci/shell_banner.c b/src/hci/shell_banner.c
index dbe3767..f435b45 100644
--- a/src/hci/shell_banner.c
+++ b/src/hci/shell_banner.c
@@ -37,29 +37,18 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @ret        enter_shell             User wants to enter shell
  */
 int shell_banner ( void ) {
-       int enter_shell = 0;
-       int wait_count;
        int key;
 
-       if ( BANNER_TIMEOUT <=  0 ) {
-               return enter_shell;
-       }
+       if ( BANNER_TIMEOUT <=  0 )
+               return 0;
 
        printf ( "\nPress Ctrl-B for the gPXE command line..." );
 
        /* Wait for key */
-       for ( wait_count = 0 ; wait_count < BANNER_TIMEOUT ; wait_count++ ) {
-               if ( iskey() ) {
-                       key = getchar();
-                       if ( key == CTRL_B )
-                               enter_shell = 1;
-                       break;
-               }
-               mdelay(100);
-       }
+       key = getchar_timeout( BANNER_TIMEOUT * TICKS_PER_SEC / 10 );
 
        /* Clear the "Press Ctrl-B" line */
        printf ( "\r                                         \r" );
 
-       return enter_shell;
+       return ( key == CTRL_B );
 }
diff --git a/src/include/console.h b/src/include/console.h
index 62fedf5..49a898b 100644
--- a/src/include/console.h
+++ b/src/include/console.h
@@ -112,6 +112,7 @@ struct console_driver {
 /* Function prototypes */
 
 extern void putchar ( int character );
+extern int getchar_timeout ( unsigned long timeout );
 extern int getchar ( void );
 extern int iskey ( void );
 extern int getkey ( void );
-- 
1.7.1

_______________________________________________
gPXE-devel mailing list
[email protected]
http://etherboot.org/mailman/listinfo/gpxe-devel

Reply via email to