Fix and improve recovery script
authorPiotr Dymacz <pepe2k@gmail.com>
Wed, 5 Apr 2017 21:46:50 +0000 (23:46 +0200)
committerPiotr Dymacz <pepe2k@gmail.com>
Wed, 5 Apr 2017 21:46:50 +0000 (23:46 +0200)
- use itest for comparison
- don't loop longer than for 10 seconds
  (in extreme cases that could result in endless loop)
- show that counter variable value is hex
- clear cnt variable at script end
- clear stop_boot variable before loop

u-boot/include/env_scripts.h

index 558d079b15962ececf0104112ba325a38cb1f528..0888b63fb153e7dc176d134d0136d9b276a3a085 100644 (file)
        #if !defined(CONFIG_CMD_BUTTON) ||\
            !defined(CONFIG_CMD_SLEEP)  ||\
            !defined(CONFIG_CMD_LED)    ||\
+           !defined(CONFIG_CMD_ITEST)  ||\
            !defined(CONFIG_CMD_SETEXPR)
-               #error "Commands setexpr, sleep, button and led{on, off} are required for recovery"
+               #error "Commands setexpr, itest, sleep, button and led{on, off} are required for recovery"
        #endif
 
        #if !defined(CONFIG_GPIO_RESET_BTN)
                "echo - 3s for web based recovery;"
 
                #define SCRIPT_HTTP_PART_2      \
-               "elif test $cnt -ge 3; then " \
+               "elif itest $cnt >= 3; then " \
                        "echo HTTP server is starting for firmware update...;" \
                        "setenv stop_boot 1;" \
                        "echo;" \
                        "httpd;" \
-               "elif test $cnt -lt 3; then "
+               "elif itest $cnt < 3; then "
        #else
                #define SCRIPT_HTTP_PART_1      ""
                #define SCRIPT_HTTP_PART_2      \
-               "elif test $cnt -lt 5; then "
+               "elif itest $cnt < 5; then "
        #endif
 
        #define CONFIG_ENV_BTN_RECOVERY_SCRIPT  \
                "if button; then " \
                        "sleep 600;" \
                        "setenv cnt 0;" \
+                       "setenv stop_boot;" \
                        "echo Keep button pressed for at least:;" \
                        SCRIPT_HTTP_PART_1 \
                        "echo - 5s for U-Boot console;" \
                        "echo - 7s for network console;" \
                        "echo;" \
-                       "while button; do " \
+                       "while button && itest $cnt < 0xA; do " \
                                "ledon;" \
                                "sleep 300;" \
                                "echo . \'\\\\c\';" \
                                "sleep 600;" \
                                "setexpr cnt $cnt + 1;" \
                        "done;" \
-                       "echo $cnt seconds;" \
+                       "echo 0x$cnt seconds;" \
                        "echo;" \
-                       "if test $cnt -ge 7; then " \
+                       "if itest $cnt >= 0xA; then " \
+                               "echo \\#\\# Error: 10s limit reached!;" \
+                               "echo Continuing normal boot...;" \
+                               "echo;" \
+                       "elif itest $cnt >= 7; then " \
                                "echo Starting network console...;" \
                                "setenv stop_boot 1;" \
                                "echo;" \
                                "startnc;" \
-                       "elif test $cnt -ge 5; then " \
+                       "elif itest $cnt >= 5; then " \
                                "echo Starting U-Boot console...;" \
                                "setenv stop_boot 1;" \
                                "echo;" \
                                "echo \\#\\# Error: button was not pressed long enough!;" \
                                "echo Continuing normal boot...;" \
                                "echo;" \
-                       "fi;"\
+                       "fi;" \
+                       "setenv cnt;" \
                "fi\0"
 
 #endif /* CONFIG_BTN_RECOVERY_SCRIPT */