running the following script in u-boot:
setenv error 'if true; then
        echo **** ERROR ****
        exit;
fi'

setenv foo echo "****************This should not be printed"
setenv loadubi

setenv updfs 'if true; then
        echo; echo ========== Updating rootfs ==========; echo;
        if run loadubi; then
                echo ***************loadubi
        else;
                run error
        fi
fi'

echo ========== start ==========

run updfs foo
echo **** end

with:

=> source 80008000
========== start ==========

========== Updating rootfs ==========

## Error: "loadubi" not defined
**** ERROR ****
****************This should not be printed
**** end
=>

should not continue after printing "**** ERROR ****", as exit should
skip the hole script. Fix this! I get with this patch:

=> source 80008000
========== start ==========

========== Updating rootfs ==========

## Error: "loadubi" not defined
**** ERROR ****
=>

Signed-off-by: Heiko Schocher <h...@denx.de>
Cc: Tom Rini <tr...@ti.com>
Cc: Jeroen Hofstee <jhofs...@victronenergy.com>
---
 common/cmd_source.c |    4 ++++
 common/hush.c       |    4 +++-
 common/main.c       |    7 ++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/common/cmd_source.c b/common/cmd_source.c
index c4cde98..0d54641 100644
--- a/common/cmd_source.c
+++ b/common/cmd_source.c
@@ -174,6 +174,10 @@ do_source (cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[])
 
        printf ("## Executing script at %08lx\n", addr);
        rcode = source (addr, fit_uname);
+       if (rcode == -2) {
+               debug("Hit exit in script\n");
+               rcode = 0;
+       }
        return rcode;
 }
 
diff --git a/common/hush.c b/common/hush.c
index 4c84c2f..aa76fc7 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -3192,12 +3192,12 @@ int parse_stream_outer(struct in_str *inp, int flag)
                        code = run_list(ctx.list_head);
                        if (code == -2) {       /* exit */
                                b_free(&temp);
-                               code = 0;
                                /* XXX hackish way to not allow exit from main 
loop */
                                if (inp->peek == file_peek) {
                                        printf("exit not allowed from main 
input shell.\n");
                                        continue;
                                }
+                               flag |= FLAG_EXIT_FROM_LOOP;
                                break;
                        }
                        if (code == -1)
@@ -3222,6 +3222,8 @@ int parse_stream_outer(struct in_str *inp, int flag)
 #ifndef __U_BOOT__
        return 0;
 #else
+       if (code == -2)
+               return -2;
        return (code != 0) ? 1 : 0;
 #endif /* __U_BOOT__ */
 }
diff --git a/common/main.c b/common/main.c
index 81984ac..0cfb6e7 100644
--- a/common/main.c
+++ b/common/main.c
@@ -1469,6 +1469,7 @@ int run_command_list(const char *cmd, int len, int flag)
 int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
        int i;
+       int ret;
 
        if (argc < 2)
                return CMD_RET_USAGE;
@@ -1481,7 +1482,11 @@ int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char 
* const argv[])
                        return 1;
                }
 
-               if (run_command(arg, flag) != 0)
+               ret = run_command(arg, flag);
+               /* in case we hit an exit in a script */
+               if (ret == -2)
+                       return -2;
+               if (ret != 0)
                        return 1;
        }
        return 0;
-- 
1.7.7.6

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to