From: wdenk Date: Sat, 20 Oct 2001 09:41:35 +0000 (+0000) Subject: Fix some HUSH problems. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=232965042c6d0bab439810bde2c80e38eca64803;p=users%2Frw%2Fppcboot.git Fix some HUSH problems. In the current implementation, the local variables space and global environment variables space are separated. Local variables are those you define by simply typing like `name=value'. To access a local variable later on, you have write `$name' or `${name}'; variable directly by typing say `$name' at the command prompt. Global environment variables are those you use setenv/printenv to work with. To run a command stored in such a variable, you need to use the run command, and you must not use the '$' sign to access them. To store commands and special characters in a variable, please use double quotation marks surrounding the whole text of the variable, instead of the backslashes before semicolons and special symbols. NOTE: still serious quoting problems! cannot access env vars in commands! --- diff --git a/CHANGELOG b/CHANGELOG index 2a932e3..f36606e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -56,6 +56,9 @@ To do: Modifications for 1.1.0: ====================================================================== +* Add support for Fujitsu flash on TQM8260 + Patch by Franz Sirl, 19 Oct 2001 + * Updated GTH Board Patch by Thomas Lange, 18 Oct 2001 @@ -67,6 +70,8 @@ Modifications for 1.1.0: if...then...else...fi conditionals or `&&' and '||' constructs ("shell scripts"). + See the README file for information about implementation and usage. + * Modified all commands to provide return codes that can be used for conditional command execution diff --git a/README b/README index b436f01..8c0d406 100644 --- a/README +++ b/README @@ -648,6 +648,28 @@ The following options need to be configured: printed when the command interpreter needs more input to complete a command. Usually "> ". + Note: + + In the current implementation, the local variables + space and global environment variables space are + separated. Local variables are those you define by + simply typing like `name=value'. To access a local + variable later on, you have write `$name' or + `${name}'; variable directly by typing say `$name' at + the command prompt. + + Global environment variables are those you use + setenv/printenv to work with. To run a command stored + in such a variable, you need to use the run command, + and you must not use the '$' sign to access them. + + To store commands and special characters in a + variable, please use double quotation marks + surrounding the whole text of the variable, instead + of the backslashes before semicolons and special + symbols. + + Configuration Settings: ----------------------- diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index da8b52b..ec73a02 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -45,6 +45,10 @@ #if defined(CONFIG_AUTOSCRIPT) || \ (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) +#ifdef CFG_HUSH_PARSER +extern int parse_string_outer(char *s); +#endif + extern image_header_t header; /* from cmd_bootm.c */ int autoscript(bd_t *bd, ulong addr) @@ -111,7 +115,11 @@ autoscript(bd_t *bd, ulong addr) } } } +#ifndef CFG_HUSH_PARSER rcode = run_command(cmd, bd, 0); +#else + rcode = parse_string_outer(cmd); +#endif free(cmd); return rcode; } diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index ebd098b..798bc75 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -34,6 +34,9 @@ #include #endif +#ifdef CFG_HUSH_PARSER +extern int parse_string_outer(char *s); +#endif int gunzip (void *, int, unsigned char *, int *); static void *zalloc(void *, unsigned, unsigned); @@ -583,8 +586,11 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[], int do_bootd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { int rcode = 0; - +#ifndef CFG_HUSH_PARSER if (run_command (getenv ("bootcmd"), bd, flag) == -1) rcode = 1; +#else + if (parse_string_outer(getenv("bootcmd")) != 0 ) rcode = 1; +#endif return rcode; } #endif diff --git a/common/hush.c b/common/hush.c index 9a71af9..4a3ac86 100644 --- a/common/hush.c +++ b/common/hush.c @@ -290,11 +290,12 @@ static unsigned int last_jobid; static unsigned int shell_terminal; static char *PS1; static char *PS2; -#else -static bd_t *BD; -#endif struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 }; struct variables *top_vars = &shell_ver; +#else +static bd_t *BD; +static struct variables *top_vars ; +#endif /*__PPCBOOT__ */ #define B_CHUNK (100) #define B_NOSPAC 1 @@ -450,11 +451,13 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i static int parse_string(o_string *dest, struct p_context *ctx, const char *src); static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, int end_trigger); /* setup: */ -static int parse_stream_outer(struct in_str *inp); #ifndef __PPCBOOT__ +static int parse_stream_outer(struct in_str *inp); static int parse_string_outer(const char *s); static int parse_file_outer(FILE *f); #else +static int parse_stream_outer(struct in_str *inp, int end); +int parse_string_outer(char *s); int ppcboot_hush_start(bd_t *bd); static int parse_file_outer(void); #endif @@ -870,11 +873,13 @@ static void b_free(o_string *o) */ static int b_addqchr(o_string *o, int ch, int quote) { +#ifndef __PPCBOOT__ if (quote && strchr("*?[\\",ch)) { int rc; rc = b_addchr(o, '\\'); if (rc) return rc; } +#endif /* __PPCBOOT__ */ return b_addchr(o, ch); } @@ -2814,12 +2819,17 @@ void update_ifs_map(void) /* most recursion does not come through here, the exeception is * from builtin_source() */ +#ifndef __PPCBOOT__ int parse_stream_outer(struct in_str *inp) +#else +int parse_stream_outer(struct in_str *inp, int end) +#endif /* __PPCBOOT__ */ { struct p_context ctx; o_string temp=NULL_O_STRING; int rcode; + do { initialize_context(&ctx); update_ifs_map(); @@ -2842,18 +2852,31 @@ int parse_stream_outer(struct in_str *inp) free_pipe_list(ctx.list_head,0); b_free(&temp); } -#endif + } while (end != 1); + return (rcode != 1) ? 0 : 1; +#else } while (rcode != -1); /* loop on syntax errors, return on EOF */ return 0; +#endif /* __PPCBOOT__ */ } #ifndef __PPCBOOT__ static int parse_string_outer(const char *s) +#else +int parse_string_outer(char *s) +#endif /* __PPCBOOT__ */ { struct in_str input; + setup_string_in_str(&input, s); +#ifdef __PPCBOOT__ + if ( !s || !*s) + return 1; + return parse_stream_outer(&input, 1); +#else return parse_stream_outer(&input); +#endif /* __PPCBOOT__ */ } -#endif + #ifndef __PPCBOOT__ static int parse_file_outer(FILE *f) #else @@ -2864,23 +2887,31 @@ static int parse_file_outer(void) struct in_str input; #ifndef __PPCBOOT__ setup_file_in_str(&input, f); -#else - setup_file_in_str(&input); -#endif rcode = parse_stream_outer(&input); +#else + setup_file_in_str(&input); + rcode = parse_stream_outer(&input, 0); +#endif /* __PPCBOOT__ */ return rcode; } -#ifdef __PPCBOOT__ +#ifdef __PPCBOOT__ int ppcboot_hush_start(bd_t *bd) { - extern bd_t *BD; + extern bd_t *BD; - BD = bd; - parse_file_outer(); - return 1; -} -#endif + BD = bd; + top_vars = malloc(sizeof(struct variables)); + top_vars->name = "HUSH_VERSION"; + top_vars->value = "0.01"; + top_vars->next = 0; + top_vars->flg_export = 0; + top_vars->flg_read_only = 1; + parse_file_outer(); + return 1; +} +#endif /* __PPCBOOT__ */ + #ifndef __PPCBOOT__ /* Make sure we have a controlling tty. If we get started under a job * aware app (like bash for example), make sure we are now in charge so diff --git a/common/main.c b/common/main.c index c575202..18d0e5b 100644 --- a/common/main.c +++ b/common/main.c @@ -25,12 +25,14 @@ #include #include #include +#include #if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) #include /* for do_reset() prototype */ #endif #ifdef CFG_HUSH_PARSER -int ppcboot_hush_start(bd_t *bd); +extern int ppcboot_hush_start(bd_t *bd); +extern int parse_string_outer(char *s); #endif static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen); @@ -710,9 +712,12 @@ int do_run (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) } for (i=1; i " /* Monitor Command Prompt */ -#define CFG_HUSH_PARSER +#define CFG_HUSH_PARSER 1 /* use "hush" command parser */ #ifdef CFG_HUSH_PARSER #define CFG_PROMPT_HUSH_PS2 "> " #endif