[ECOS] custom code to bypass redboot abort script

Jose Vasconcellos jvasco@verizon.net
Mon Aug 25 20:39:00 GMT 2008


I have a device that does not have an easily accessible serial port.
Access to redboot is normally done via telnet from the ethernet port.
Of course, if there's a boot script installed then there's no opportunity
to abort the script. It does have a button, so I wanted the user to
power-on with the button pressed to bypass or abort the start-up script.
I had to rework packages/redboot/current/main.c

The following patch creates a function redboot_abort_script that handles
the existing console check. The idea is to be able to replace this routine
for unusual cases.

-jose

diff -r 690e1f51d092 packages/redboot/current/src/main.c
--- a/packages/redboot/current/src/main.c    Sun May 04 17:02:34 2008 -0400
+++ b/packages/redboot/current/src/main.c    Mon Aug 25 15:05:11 2008 -0400
@@ -234,6 +234,25 @@
 }
 #endif
 
+// Check for ^C on console
+bool redboot_abort_script(int script_timeout_ms)
+{
+    int res = _GETS_CTRLC;  // Treat 0 timeout as ^C
+    diag_printf("== Executing boot script in %d.%03d seconds - enter ^C 
to abort\n",
+                script_timeout_ms/1000, script_timeout_ms%1000);
+
+    while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
+        res = _rb_gets(line, sizeof(line), 
CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
+        if (res >= _GETS_OK) {
+            diag_printf("== Executing boot script in %d.%03d seconds - 
enter ^C to abort\n",
+                script_timeout_ms/1000, script_timeout_ms%1000);
+            continue;  // Ignore anything but ^C
+        }
+        if (res != _GETS_TIMEOUT) break;
+        script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
+    }
+    return res == _GETS_CTRLC;
+}
 
 //
 // This is the main entry point for RedBoot
@@ -337,26 +356,10 @@
 # endif
     if (script) {
         // Give the guy a chance to abort any boot script
-        unsigned char *hold_script = script;
         int script_timeout_ms = script_timeout * 
CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION;
-        diag_printf("== Executing boot script in %d.%03d seconds - 
enter ^C to abort\n",
-                    script_timeout_ms/1000, script_timeout_ms%1000);
-        script = (unsigned char *)0;
-        res = _GETS_CTRLC;  // Treat 0 timeout as ^C
-        while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
-            res = _rb_gets(line, sizeof(line), 
CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
-            if (res >= _GETS_OK) {
-                diag_printf("== Executing boot script in %d.%03d 
seconds - enter ^C to abort\n",
-                            script_timeout_ms/1000, 
script_timeout_ms%1000);
-                continue;  // Ignore anything but ^C
-            }
-            if (res != _GETS_TIMEOUT) break;
-            script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
-        }
-        if (res == _GETS_CTRLC) {
+        res = redboot_abort_script(script_timeout_ms);
+        if (res) {
             script = (unsigned char *)0;  // Disable script
-        } else {
-            script = hold_script;  // Re-enable script
         }
     }
 #endif


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list