summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/cmd_date.c5
-rw-r--r--common/hush.c62
-rw-r--r--common/main.c19
3 files changed, 55 insertions, 31 deletions
diff --git a/common/cmd_date.c b/common/cmd_date.c
index 1472e3f..2139ceb 100644
--- a/common/cmd_date.c
+++ b/common/cmd_date.c
@@ -34,10 +34,13 @@ const char *weekdays[] = {
"Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
};
+#define RELOC(a) ((typeof(a))((unsigned long)(a) + gd->reloc_off))
+
int mk_date (char *, struct rtc_time *);
int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
+ DECLARE_GLOBAL_DATA_PTR;
struct rtc_time tm;
int rcode = 0;
@@ -64,7 +67,7 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
printf ("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
(tm.tm_wday<0 || tm.tm_wday>6) ?
- "unknown " : weekdays[tm.tm_wday],
+ "unknown " : RELOC(weekdays[tm.tm_wday]),
tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0;
diff --git a/common/hush.c b/common/hush.c
index fcc3559..1993398 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -2357,34 +2357,35 @@ static void initialize_context(struct p_context *ctx)
* should handle if, then, elif, else, fi, for, while, until, do, done.
* case, function, and select are obnoxious, save those for later.
*/
+struct reserved_combo {
+ char *literal;
+ int code;
+ long flag;
+};
+/* Mostly a list of accepted follow-up reserved words.
+ * FLAG_END means we are done with the sequence, and are ready
+ * to turn the compound list into a command.
+ * FLAG_START means the word must start a new compound list.
+ */
+static struct reserved_combo reserved_list[] = {
+ { "if", RES_IF, FLAG_THEN | FLAG_START },
+ { "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
+ { "elif", RES_ELIF, FLAG_THEN },
+ { "else", RES_ELSE, FLAG_FI },
+ { "fi", RES_FI, FLAG_END },
+ { "for", RES_FOR, FLAG_IN | FLAG_START },
+ { "while", RES_WHILE, FLAG_DO | FLAG_START },
+ { "until", RES_UNTIL, FLAG_DO | FLAG_START },
+ { "in", RES_IN, FLAG_DO },
+ { "do", RES_DO, FLAG_DONE },
+ { "done", RES_DONE, FLAG_END }
+};
+#define NRES (sizeof(reserved_list)/sizeof(struct reserved_combo))
+
int reserved_word(o_string *dest, struct p_context *ctx)
{
- struct reserved_combo {
- char *literal;
- int code;
- long flag;
- };
- /* Mostly a list of accepted follow-up reserved words.
- * FLAG_END means we are done with the sequence, and are ready
- * to turn the compound list into a command.
- * FLAG_START means the word must start a new compound list.
- */
- static struct reserved_combo reserved_list[] = {
- { "if", RES_IF, FLAG_THEN | FLAG_START },
- { "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
- { "elif", RES_ELIF, FLAG_THEN },
- { "else", RES_ELSE, FLAG_FI },
- { "fi", RES_FI, FLAG_END },
- { "for", RES_FOR, FLAG_IN | FLAG_START },
- { "while", RES_WHILE, FLAG_DO | FLAG_START },
- { "until", RES_UNTIL, FLAG_DO | FLAG_START },
- { "in", RES_IN, FLAG_DO },
- { "do", RES_DO, FLAG_DONE },
- { "done", RES_DONE, FLAG_END }
- };
struct reserved_combo *r;
for (r=reserved_list;
-#define NRES sizeof(reserved_list)/sizeof(struct reserved_combo)
r<reserved_list+NRES; r++) {
if (strcmp(dest->data, r->literal) == 0) {
debug_printf("found reserved word %s, code %d\n",r->literal,r->code);
@@ -3169,6 +3170,18 @@ int parse_file_outer(void)
}
#ifdef __U_BOOT__
+static void u_boot_hush_reloc(void)
+{
+ DECLARE_GLOBAL_DATA_PTR;
+ unsigned long addr;
+ struct reserved_combo *r;
+
+ for (r=reserved_list; r<reserved_list+NRES; r++) {
+ addr = (ulong) (r->literal) + gd->reloc_off;
+ r->literal = (char *)addr;
+ }
+}
+
int u_boot_hush_start(void)
{
top_vars = malloc(sizeof(struct variables));
@@ -3177,6 +3190,7 @@ int u_boot_hush_start(void)
top_vars->next = 0;
top_vars->flg_export = 0;
top_vars->flg_read_only = 1;
+ u_boot_hush_reloc();
return 0;
}
diff --git a/common/main.c b/common/main.c
index e32845e..33d8717 100644
--- a/common/main.c
+++ b/common/main.c
@@ -862,7 +862,6 @@ int run_command (const char *cmd, int flag)
int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int i;
- int rcode = 1;
if (argc < 2) {
printf ("Usage:\n%s\n", cmdtp->usage);
@@ -870,13 +869,21 @@ int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
}
for (i=1; i<argc; ++i) {
+ char *arg;
+
+ if ((arg = getenv (argv[i])) == NULL) {
+ printf ("## Error: \"%s\" not defined\n", argv[i]);
+ return 1;
+ }
#ifndef CFG_HUSH_PARSER
- if (run_command (getenv (argv[i]), flag) != -1) ++rcode;
+ if (run_command (arg, flag) == -1)
+ return 1;
#else
- if (parse_string_outer(getenv (argv[i]),
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) == 0) ++rcode;
+ if (parse_string_outer(arg,
+ FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) == 0)
+ return 1;
#endif
}
- return ((rcode == i) ? 0 : 1);
+ return 0;
}
-#endif
+#endif /* CFG_CMD_RUN */