Modifications for 1.1.2:
======================================================================
+* Add "sleep" command
+
+* Add loop constructs (for, while, until) to hush command interpreter
+
+* Fix (most) variable problems with hush command interpreter
+
* Series of patches by Erik Theisen, 25 Nov 2001:
Patch 1 of 9:
errata about the serial divisor on all 405s.
- Add watchdog support to cpu/ppc4xx/serial.c
+ Patch 8 of 9:
+ - Add support for multiple i2c EEPROMs
+ - Modified saveenv() handling
+
+ Patch 9 of 9:
+ - Various Wave 7 Optic specific configuration changes
+
* Add I2C support for Xicor X40430 EEPROM (ICU862 board)
* Fix comment and change overly conservative value in
}
memset(data, 0, HYMOD_EEPROM_SIZE);
- if (eeprom_write(offset, data, HYMOD_EEPROM_SIZE) != 0) rcode = 1;
+ if (eeprom_write(CFG_DEF_EEPROM_ADDR, offset, data, HYMOD_EEPROM_SIZE) != 0) rcode = 1;
return rcode;
}
crc = 0;
hp = (hymod_eehdr_t *)data;
- eeprom_read(offset, (uchar *)hp, sizeof (*hp));
+ eeprom_read(CFG_DEF_EEPROM_ADDR, offset, (uchar *)hp, sizeof (*hp));
offset += sizeof (*hp);
if (hp->id != HYMOD_EEPROM_ID || hp->ver > HYMOD_EEPROM_VER ||
return (0);
dp = (uchar *)(hp + 1); edp = dp + len;
- eeprom_read(offset, dp, len);
+ eeprom_read(CFG_DEF_EEPROM_ADDR, offset, dp, len);
offset += len;
- eeprom_read(offset, (uchar *)&crc, sizeof (ulong));
+ eeprom_read(CFG_DEF_EEPROM_ADDR, offset, (uchar *)&crc, sizeof (ulong));
if (crc32(0, data, edp - data) != crc)
return (0);
memcpy(dp, &crc, sizeof (ulong));
dp += sizeof (ulong);
- eeprom_write(offset, data, dp - data);
+ eeprom_write(CFG_DEF_EEPROM_ADDR, offset, data, dp - data);
return (1);
}
#
#TEXT_BASE = 0xFFFE0000
-TEXT_BASE = 0xFFF80000
+#TEXT_BASE = 0xFFF80000
+TEXT_BASE = 0xFFFD0000
cmd_date.o cmd_dcr.o cmd_eeprom.o cmd_elf.o \
cmd_fdc.o cmd_flash.o cmd_i2c.o \
cmd_ide.o cmd_immap.o cmd_mem.o \
- cmd_mii.o cmd_net.o cmd_nvedit.o \
- cmd_pcmcia.o cmd_reginfo.o cmd_scsi.o \
+ cmd_mii.o cmd_misc.o cmd_net.o \
+ cmd_nvedit.o cmd_pcmcia.o \
+ cmd_reginfo.o cmd_scsi.o \
console.o devices.o dlmalloc.o \
flash.o hush.o kgdb.o \
lists.o miiphybb.o miiphyutil.o \
#if (CONFIG_COMMANDS & CFG_CMD_EEPROM) || defined(CFG_ENV_IS_IN_EEPROM)
extern void eeprom_init (void);
-extern int eeprom_read (unsigned offset, uchar *buffer, unsigned cnt);
-extern int eeprom_write (unsigned offset, uchar *buffer, unsigned cnt);
-
+extern int eeprom_read (unsigned dev_addr, unsigned offset,
+ uchar *buffer, unsigned cnt);
+extern int eeprom_write (unsigned dev_addr, unsigned offset,
+ uchar *buffer, unsigned cnt);
#endif
/* ------------------------------------------------------------------------- */
#if (CONFIG_COMMANDS & CFG_CMD_EEPROM)
-int do_eeprom (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+int do_eeprom (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc,
+ char *argv[])
{
- int rcode = 0;
-
- switch (argc) {
- default:
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- case 5:
- /* 4 args */
-
- if (strcmp(argv[1],"read") == 0) {
- ulong addr = simple_strtoul(argv[2], NULL, 16);
- ulong off = simple_strtoul(argv[3], NULL, 16);
- ulong cnt = simple_strtoul(argv[4], NULL, 16);
-
- printf ("\nEEPROM read: addr %08lx off %04lx count %ld ... ",
- addr, off, cnt);
+ const char *const fmt =
+ "\nEEPROM %s: dev_addr %lx addr %08lx off %04lx count %ld ... ";
-#ifndef CONFIG_SPI
+#if defined(CFG_I2C_MULTI_EEPROMS)
+ if (argc == 6) {
+ ulong dev_addr = simple_strtoul (argv[2], NULL, 16);
+#else
+ if (argc == 5) {
+ ulong dev_addr = CFG_DEF_EEPROM_ADDR;
+#endif /* CFG_I2C_MULTI_EEPROMS */
+ ulong addr = simple_strtoul (argv[3], NULL, 16);
+ ulong off = simple_strtoul (argv[4], NULL, 16);
+ ulong cnt = simple_strtoul (argv[5], NULL, 16);
+
+# ifndef CONFIG_SPI
eeprom_init ();
-#endif
- rcode = eeprom_read (off, (uchar *)addr, cnt);
+# endif /* !CONFIG_SPI */
- printf ("done\n");
- return rcode;
+ if (strcmp (argv[1], "read") == 0) {
+ int rcode;
- } else if (strcmp(argv[1],"write") == 0) {
- ulong addr = simple_strtoul(argv[2], NULL, 16);
- ulong off = simple_strtoul(argv[3], NULL, 16);
- ulong cnt = simple_strtoul(argv[4], NULL, 16);
+ printf (fmt, argv[1], dev_addr, addr, off, cnt);
- printf ("\nEEPROM write: addr %08lx off %04lx count %ld ... ",
- addr, off, cnt);
+ rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt);
-#ifndef CONFIG_SPI
- eeprom_init ();
-#endif
- rcode = eeprom_write(off, (uchar *)addr, cnt);
+ printf ("done\n");
+ return rcode;
+ } else if (strcmp (argv[2], "write") == 0) {
+ int rcode;
- printf ("done\n");
- return rcode;
+ printf (fmt, argv[1], dev_addr, addr, off, cnt);
- } else {
- printf ("Usage:\n%s\n", cmdtp->usage);
+ rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt);
+
+ printf ("done\n");
+ return rcode;
+ }
}
+
+ printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
- }
}
#endif /* CFG_CMD_EEPROM */
#if (CONFIG_COMMANDS & CFG_CMD_EEPROM) || defined(CFG_ENV_IS_IN_EEPROM)
-int eeprom_read (unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
{
unsigned end = offset + cnt;
unsigned blk_off;
alen = 3;
#endif /* CONFIG_I2C_X, CONFIG_SPI_X */
-#ifdef CFG_I2C_EEPROM_ADDR
- addr[0] |= CFG_I2C_EEPROM_ADDR; /* insert device address */
-#endif
+ addr[0] |= dev_addr; /* insert device address */
maxlen = 0x100 - blk_off;
if (maxlen > I2C_RXTX_LEN)
* 0x00000nxx for EEPROM address selectors and page number at n.
*/
-int eeprom_write (unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
{
unsigned end = offset + cnt;
unsigned blk_off;
alen = 3;
#endif /* CONFIG_I2C_X, CONFIG_SPI_X */
-#ifdef CFG_I2C_EEPROM_ADDR
- addr[0] |= CFG_I2C_EEPROM_ADDR; /* insert device address */
-#endif
+ addr[0] |= dev_addr; /* insert device address */
#if defined(CFG_EEPROM_PAGE_WRITE_BITS)
--- /dev/null
+/*
+ * (C) Copyright 2001
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * Misc functions
+ */
+#include <ppcboot.h>
+#include <command.h>
+
+#if (CONFIG_COMMANDS & CFG_CMD_MISC)
+
+int do_sleep (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+{
+ ulong delay;
+
+ if (argc != 2) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ delay = simple_strtoul(argv[1], NULL, 10);
+
+ while (delay) {
+ int i;
+ for (i=0; i<1000; ++i) {
+ if (ctrlc ()) {
+ return (-1);
+ }
+ udelay (1000);
+ }
+ --delay;
+ }
+ return 0;
+}
+
+#endif /* CFG_CMD_MISC */
/*
- * (C) Copyright 2000
+ * (C) Copyright 2000, 2001
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
DEBUGF ("%s[%d] ENV is valid\n", __FUNCTION__,__LINE__);
# if defined(CFG_ENV_IS_IN_EEPROM)
DEBUGF ("%s[%d] read ENV from EEPROM\n", __FUNCTION__,__LINE__);
- eeprom_read (CFG_ENV_OFFSET+offsetof(env_t,data),
+ eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+offsetof(env_t,data),
env_ptr->data,
ENV_SIZE);
#elif defined(CFG_ENV_IS_IN_NVRAM) && defined(CFG_NVRAM_ACCESS_ROUTINE)
init_data_t *idata = (init_data_t*)(CFG_INIT_RAM_ADDR+CFG_INIT_DATA_OFFSET);
/* if the EEPROM crc was bad, use the default environment */
- if (idata->env_valid)
- eeprom_read (CFG_ENV_OFFSET+index+offsetof(env_t,data), &c, 1);
- else
+ if (idata->env_valid) {
+ eeprom_read (CFG_DEF_EEPROM_ADDR,
+ CFG_ENV_OFFSET+index+offsetof(env_t,data),
+ &c, 1);
+ } else {
c = default_environment[index];
+ }
return (c);
}
break;
default: /* askenv envname message1 ... messagen size */
- {
- int i;
- int pos = 0;
-
- for (i = 2; i < argc - 1; i++) {
- if (pos) {
- message[pos++] = ' ';
- }
- strcpy (message+pos, argv[i]);
- pos += strlen(argv[i]);
+ {
+ int i;
+ int pos = 0;
+
+ for (i = 2; i < argc - 1; i++) {
+ if (pos) {
+ message[pos++] = ' ';
}
- message[pos] = '\0';
- size = simple_strtoul (argv[argc - 1], NULL, 10);
+ strcpy (message+pos, argv[i]);
+ pos += strlen(argv[i]);
}
+ message[pos] = '\0';
+ size = simple_strtoul (argv[argc - 1], NULL, 10);
+ }
+ break;
}
if (size >= CFG_CBSIZE)
len = 3;
}
- // Continue calling setenv code
+ /* Continue calling setenv code */
return _do_setenv (bd, flag, len, local_args);
}
#endif /* CFG_CMD_ASKENV */
return(-1);
}
+#define SAVESTR(type) "Saving Enviroment to " #type "...\n"
#ifdef CFG_ENV_IS_IN_NVRAM
+#define NVRAM_SAVESTR SAVESTR(NVRAM)
-int do_saveenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
-{
+int saveenv(void)
+{
int rcode = 0;
- printf ("Saving Environment to NVRAM...\n");
#ifdef CFG_NVRAM_ACCESS_ROUTINE
nvram_write((short)CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE);
- rcode = 0;
#else
if (memcpy ((char *)CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE) == NULL)
rcode = 1 ;
}
#elif CFG_ENV_IS_IN_EEPROM
+#define NVRAM_SAVESTR SAVESTR(EEPROM)
-int do_saveenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+int saveenv(void)
{
- printf ("Saving Environment to EEPROM...\n");
- return eeprom_write (CFG_ENV_OFFSET, (uchar *)env_ptr, CFG_ENV_SIZE);
+ return (eeprom_write (CFG_DEF_EEPROM_ADDR,
+ CFG_ENV_OFFSET,
+ (uchar *)env_ptr, CFG_ENV_SIZE)
+ );
}
#else /* !CFG_ENV_IS_IN_NVRAM, !CFG_ENV_IS_IN_EEPROM => Must be flash, then */
+#define NVRAM_SAVESTR SAVESTR(Flash)
/* need both ENV and flash */
#if ((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_FLASH)) == (CFG_CMD_ENV|CFG_CMD_FLASH))
-int do_saveenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+int saveenv(void)
{
int len, rc;
ulong end_addr;
#else
flash_sect_addr = flash_addr;
len = CFG_ENV_SIZE;
-# endif /* CFG_ENV_SECT_SIZE */
+#endif /* CFG_ENV_SECT_SIZE */
end_addr = (ulong)flash_sect_addr + len - 1;
if (flash_sect_protect (0, (ulong)flash_sect_addr, end_addr))
return 1;
- printf ("Erasing Flash...");
if (flash_sect_erase ((ulong)flash_sect_addr, end_addr))
return 1;
- printf ("Saving Environment to Flash...\n");
switch (rc = flash_write(env_buffer, (ulong)flash_sect_addr, len)) {
case 0: break;
case 1: printf ("Timeout writing to Flash\n");
#endif /* CFG_ENV_IS_IN_NVRAM */
+#if defined(CFG_ENV_IS_IN_NVRAM) || defined(CFG_ENV_IS_IN_EEPROM) || \
+ ((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_FLASH)) == \
+ (CFG_CMD_ENV|CFG_CMD_FLASH))
+int do_saveenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+{
+ int rcode = 0;
+
+ printf (NVRAM_SAVESTR);
+ if (!saveenv())
+ rcode = 1;
+
+ return rcode;
+}
+#endif
+
/************************************************************************
* Initialize Environment use
*
eeprom_init (); /* prepare for EEPROM read/write */
/* read old CRC */
- eeprom_read (CFG_ENV_OFFSET+offsetof(env_t,crc), (uchar *)&crc,
- sizeof(ulong));
+ eeprom_read (CFG_DEF_EEPROM_ADDR,
+ CFG_ENV_OFFSET+offsetof(env_t,crc),
+ (uchar *)&crc, sizeof(ulong));
new = 0;
len = ENV_SIZE;
while (len > 0) {
int n = (len > sizeof(buf)) ? sizeof(buf) : len;
- eeprom_read (CFG_ENV_OFFSET+off, buf, n);
+ eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, buf, n);
new = crc32 (new, buf, n);
len -= n;
off += n;
CMD_TBL_SCCINFO
CMD_TBL_SCSIBOOT
CMD_TBL_SCSI
+ CMD_TBL_SETDCR
+ CMD_TBL_SETENV
CMD_TBL_SIINFO
CMD_TBL_SITINFO
CMD_TBL_SIUINFO
- CMD_TBL_SETDCR
- CMD_TBL_SETENV
+ CMD_TBL_MISC /* sleep */
CMD_TBL_SMCINFO
CMD_TBL_SPIINFO
CMD_TBL_STACK
#include <signal.h>
/* #include <dmalloc.h> */
-#define DEBUG_SHELL
+/* #define DEBUG_SHELL */
#ifdef BB_VER
#include "busybox.h"
#undef BB_FEATURE_SH_FANCY_PROMPT
#endif
#endif
+#define SPECIAL_VAR_SYMBOL 03
#ifdef __PPCBOOT__
#define EXIT_SUCCESS 0
#define EOF -1
#define syntax() syntax_err()
#define xstrdup strdup
-#define xmalloc malloc
-#define xrealloc realloc
#define error_msg printf
#else
typedef enum {
REDIRECT_HEREIS = 4,
REDIRECT_IO = 5
} redir_type;
+
/* The descrip member of this structure is only used to make debugging
* output pretty */
struct {int mode; int default_fd; char *descrip;} redir_table[] = {
RES_DO = 9,
RES_DONE = 10,
RES_XXXX = 11,
- RES_SNTX = 12
+ RES_IN = 12,
+ RES_SNTX = 13
} reserved_style;
#define FLAG_END (1<<RES_NONE)
#define FLAG_IF (1<<RES_IF)
#define FLAG_UNTIL (1<<RES_UNTIL)
#define FLAG_DO (1<<RES_DO)
#define FLAG_DONE (1<<RES_DONE)
+#define FLAG_IN (1<<RES_IN)
#define FLAG_START (1<<RES_XXXX)
/* This holds pointers to the various results of parsing */
struct p_context *stack;
/* How about quoting status? */
};
+
#ifndef __PPCBOOT__
struct redir_struct {
redir_type type; /* type of redirection */
glob_t word; /* *word.gl_pathv is the filename */
};
#endif
+
struct child_prog {
#ifndef __PPCBOOT__
pid_t pid; /* 0 if exited */
int argc; /* number of program arguments */
#endif
struct pipe *group; /* if non-NULL, first in group or subshell */
-#ifndef __PPCBOOT__
+#ifndef __PPCBOOT__
int subshell; /* flag, non-zero if group must be forked */
struct redir_struct *redirects; /* I/O redirections */
glob_t glob_result; /* result of parameter globbing */
- int is_stopped; /* is the program currently running? */
+ int is_stopped; /* is the program currently running? */
struct pipe *family; /* pointer back to the child's parent pipe */
-#endif
+#endif
+ int sp; /* number of SPECIAL_VAR_SYMBOL */
};
struct pipe {
pipe_style followup; /* PIPE_BG, PIPE_SEQ, PIPE_OR, PIPE_AND */
reserved_style r_mode; /* supports if, for, while, until */
};
+
#ifndef __PPCBOOT__
struct close_me {
int fd;
struct close_me *next;
};
#endif
+
struct variables {
char *name;
char *value;
struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 };
struct variables *top_vars = &shell_ver;
#else
+static int flag_repeat = 0;
static bd_t *BD;
static struct variables *top_vars ;
#endif /*__PPCBOOT__ */
};
#define b_getch(input) ((input)->get(input))
#define b_peek(input) ((input)->peek(input))
+
#ifndef __PPCBOOT__
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
+
struct built_in_command {
char *cmd; /* name */
char *descr; /* description */
int (*function) (struct child_prog *); /* function ptr */
};
#endif
+
/* belongs in busybox.h */
static inline int max(int a, int b) {
return (a>b)?a:b;
}
-/* This should be in utility.c */
+/* This should be in utility.c */
#ifdef DEBUG_SHELL
#ifndef __PPCBOOT__
static void debug_printf(const char *format, ...)
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
- printf(stderr, format, args);\r
va_end(args);
}
#else
static inline void debug_printf(const char *format, ...) { }
#endif
#define final_printf debug_printf
+
#ifdef __PPCBOOT__
static void syntax_err(void) {
printf("syntax error\n");
error_msg("syntax error %s:%d", file, line);
}
#define syntax() __syntax(__FILE__, __LINE__)
+#endif
+
+#ifdef __PPCBOOT__
+static void *xmalloc(size_t size);
+static void *xrealloc(void *ptr, size_t size);
+#else
/* Index of subroutines: */
/* function prototypes for builtins */
static int builtin_cd(struct child_prog *child);
static int process_command_subs(o_string *dest, struct p_context *ctx, struct in_str *input, int subst_end);
static int parse_group(o_string *dest, struct p_context *ctx, struct in_str *input, int ch);
#endif
-static void lookup_param(o_string *dest, struct p_context *ctx, o_string *src);
+static char *lookup_param(char *src);
static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input);
+#ifndef __PPCBOOT__
static int parse_string(o_string *dest, struct p_context *ctx, const char *src);
+#endif
static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, int end_trigger);
/* setup: */
#ifndef __PPCBOOT__
static void remove_bg_job(struct pipe *pi);
#endif
/* local variable support */
+static char **make_list_in(char **inp, char *name);
+static char *insert_var_value(char *inp);
static char *get_local_var(const char *var);
#ifndef __PPCBOOT__
static void unset_local_var(const char *name);
#endif
static int set_local_var(const char *s, int flg_export);
+
#ifndef __PPCBOOT__
/* Table of built-in functions. They can be forked or not, depending on
* context: within pipes, they fork. As simple commands, they do not.
return EXIT_FAILURE;
}
#endif
+
static int b_check_space(o_string *o, int len)
{
/* It would be easy to drop a more restrictive policy
{
return *i->p;
}
+
#ifndef __PPCBOOT__
static inline void cmdedit_set_initial_prompt(void)
{
debug_printf("result %s\n",*prompt_str);
}
#endif
+
static void get_user_input(struct in_str *i)
{
-
#ifndef __PPCBOOT__
char *prompt_str;
static char the_command[BUFSIZ];
-
+
setup_prompt_string(i->promptmode, &prompt_str);
#ifdef BB_FEATURE_COMMAND_EDITING
/*
the_command[1]='\0';
#endif
fflush(stdout);
- i->p = the_command;
+ i->p = the_command;
#else
extern char console_buffer[CFG_CBSIZE];
int n;
- static int flag_repeat = 0;
static char the_command[CFG_CBSIZE];
-
+
+ i->__promptme = 1;
if (i->promptmode == 1) {
n = readline(CFG_PROMPT);
} else {
n = readline(CFG_PROMPT_HUSH_PS2);
}
if (n == -1 ) {
+ flag_repeat = 0;
i->__promptme = 0;
}
n = strlen(console_buffer);
console_buffer[n] = '\n';
console_buffer[n+1]= '\0';
+ if (had_ctrlc()) flag_repeat = 0;
+ clear_ctrlc();
if (i->promptmode == 1) {
if (console_buffer[0] == '\n'&& flag_repeat == 0) {
- i->p = console_buffer;
+ strcpy(the_command,console_buffer);
}
else {
if (console_buffer[0] != '\n') {
strcpy(the_command,console_buffer);
flag_repeat = 1;
}
- else {
- flag_repeat = 0;
- }
- i->p = the_command;
}
+ i->p = the_command;
}
else {
if (console_buffer[0] != '\n') {
else {
the_command[0] = '\n';
the_command[1] = '\0';
+ flag_repeat = 0;
}
}
if (i->__promptme == 0) {
the_command[0] = '\n';
the_command[1] = '\0';
}
- i->p = console_buffer;
- }
+ i->p = console_buffer;
+ }
#endif
}
static int file_get(struct in_str *i)
{
int ch;
+
ch = 0;
-
/* If there is data waiting, eat it up */
if (i->p && *i->p) {
ch=*i->p++;
} else {
/* need to double check i->file because we might be doing something
- * more complicated by now, like sourcing or substituting. */
+ * more complicated by now, like sourcing or substituting. */
#ifndef __PPCBOOT__
if (i->__promptme && interactive && i->file == stdin) {
- while(! i->p || (interactive && strlen(i->p)==0) ) {
+ while(! i->p || (interactive && strlen(i->p)==0) ) {
#else
while(! i->p || strlen(i->p)==0 ) {
#endif
i->__promptme = 0;
#endif
if (i->p && *i->p) {
- ch=*i->p++;
+ ch=*i->p++;
}
#ifndef __PPCBOOT__
} else {
ch = fgetc(i->file);
}
-#endif
+
+#endif
debug_printf("b_getch: got a %d\n", ch);
}
#ifndef __PPCBOOT__
}
#endif
}
+
#ifndef __PPCBOOT__
static void setup_file_in_str(struct in_str *i, FILE *f)
#else
}
static void setup_string_in_str(struct in_str *i, const char *s)
-{
+{
i->peek = static_peek;
i->get = static_get;
i->__promptme=1;
i->promptmode=1;
i->p = s;
}
+
#ifndef __PPCBOOT__
static void mark_open(int fd)
{
}
close_me_head = NULL;
}
+
/* squirrel != NULL means we squirrel away copies of stdin, stdout,
* and stderr if they are redirected. */
static int setup_redirects(struct child_prog *prog, int squirrel[])
static void pseudo_exec(struct child_prog *child)
{
int i, rcode;
+ char *p;
struct built_in_command *x;
if (child->argv) {
for (i=0; is_assignment(child->argv[i]); i++) {
debug_printf("pid %d environment modification: %s\n",getpid(),child->argv[i]);
- putenv(strdup(child->argv[i]));
+ p = insert_var_value(child->argv[i]);
+ putenv(strdup(p));
+ if (p != child->argv[i]) free(p);
}
child->argv+=i; /* XXX this hack isn't so horrible, since we are about
to exit, and therefore don't need to keep data
return;
}
#endif
+
/* run_pipe_real() starts all the jobs, but doesn't wait for anything
* to finish. See checkjobs().
*
* now has its stdout directed to the input of the appropriate pipe,
* so this routine is noticeably simpler.
*/
-
static int run_pipe_real(struct pipe *pi)
{
-
int i;
#ifndef __PPCBOOT__
int nextin, nextout;
int pipefds[2]; /* pipefds[0] is for reading */
struct child_prog *child;
struct built_in_command *x;
+ char *p;
+ int n;
#else
int nextin;
int flag = 0;
struct child_prog *child;
cmd_tbl_t *cmdtp;
+ char *p;
+ int n;
#endif
nextin = 0;
#ifndef __PPCBOOT__
pi->pgrp = -1;
#endif
+
/* Check if this is a simple builtin (not part of a pipe).
* Builtins within pipes have to fork anyway, and are handled in
* pseudo_exec. "echo foo | read bar" doesn't work on bash, either.
if (i!=0 && child->argv[i]==NULL) {
/* assignments, but no command: set the local environment */
for (i=0; child->argv[i]!=NULL; i++) {
+
/* Ok, this case is tricky. We have to decide if this is a
* local variable, or an already exported variable. If it is
* already exported, we have to export the new value. If it is
}
#endif
free(name);
- set_local_var(child->argv[i], export_me);
+ p = insert_var_value(child->argv[i]);
+ set_local_var(p, export_me);
+ if (p != child->argv[i]) free(p);
}
return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
}
+ for (i = 0; is_assignment(child->argv[i]); i++) {
+ p = insert_var_value(child->argv[i]);
+#ifndef __PPCBOOT__
+ putenv(strdup(p));
+#else
+ set_local_var(p, 0);
+#endif
+ if (p != child->argv[i]) {
+ child->sp--;
+ free(p);
+ }
+ }
+ if (child->sp) {
+ char *p1 = NULL, *p2;
+ int len = 0;
+ /* make new string for parser */
+ for (n = i; child->argv[n]; n++) {
+ p2 = insert_var_value(child->argv[n]);
+ p1 = xrealloc(p1, (len + 2 + strlen(p2)));
+ strcpy(p1 + len, p2);
+ strcat(p1, " ");
+ len = strlen(p1);
+ if (p2 != child->argv[n]) free(p2);
+ }
+ parse_string_outer(p1);
+ free(p1);
+ return last_return_code;
+ }
#ifndef __PPCBOOT__
for (x = bltins; x->cmd; x++) {
if (strcmp(child->argv[i], x->cmd) == 0 ) {
-
- int squirrel[] = {-1, -1, -1};
- int rcode;
+ int squirrel[] = {-1, -1, -1};
+ int rcode;
if (x->function == builtin_exec && child->argv[i+1]==NULL) {
debug_printf("magic exec\n");
setup_redirects(child,NULL);
/* XXX setup_redirects acts on file descriptors, not FILEs.
* This is perfect for work that comes after exec().
* Is it really safe for inline use? Experimentally,
- * things seem to work with glibc. */
+ * things seem to work with glibc. */
setup_redirects(child, squirrel);
#else
/* Look up command in command table */
if ((cmdtp = find_cmd(child->argv[i])) == NULL) {
printf ("Unknown command '%s' - try 'help'\n", child->argv[i]);
- return 1; /* give up after bad command */
+ return -1; /* give up after bad command */
} else {
int rcode;
#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
if (cmdtp->cmd == do_bootd) {
if (flag & CMD_FLAG_BOOTD) {
printf ("'bootd' recursion detected\n");
- return 1;
+ return -1;
}
else
flag |= CMD_FLAG_BOOTD;
/* found - check max args */
if ((child->argc - i) > cmdtp->maxargs) {
printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
+ return -1;
}
#endif
- for (i=0; is_assignment(child->argv[i]); i++) {
-#ifndef __PPCBOOT__
- putenv(strdup(child->argv[i]));
-#else
- set_local_var(child->argv[i], 0);
-#endif
- }
child->argv+=i; /* XXX horrible hack */
#ifndef __PPCBOOT__
rcode = x->function(child);
}
#ifndef __PPCBOOT__
}
-
+
for (i = 0; i < pi->num_progs; i++) {
child = & (pi->progs[i]);
static int run_list_real(struct pipe *pi)
{
+ char *save_name = NULL;
+ char **list = NULL;
+ char **save_list = NULL;
+ struct pipe *rpipe;
+ int flag_rep = 0;
+#ifndef __PPCBOOT__
+ int save_num_progs;
+#endif
int rcode=0;
+ int flag_restore = 0;
int if_code=0, next_if_code=0; /* need double-buffer to handle elif */
reserved_style rmode, skip_more_in_this_rmode=RES_XXXX;
- for (;pi;pi=pi->next) {
+ /* check syntax for "for" */
+ for (rpipe = pi; rpipe; rpipe = rpipe->next) {
+ if ((rpipe->r_mode == RES_IN ||
+ rpipe->r_mode == RES_FOR) &&
+ (rpipe->next == NULL)) {
+ syntax();
+#ifdef __PPCBOOT__
+ flag_repeat = 0;
+#endif
+ return 1;
+ }
+ if ((rpipe->r_mode == RES_IN &&
+ (rpipe->next->r_mode == RES_IN &&
+ rpipe->next->progs->argv != NULL))||
+ (rpipe->r_mode == RES_FOR &&
+ rpipe->next->r_mode != RES_IN)) {
+ syntax();
+#ifdef __PPCBOOT__
+ flag_repeat = 0;
+#endif
+ return 1;
+ }
+ }
+ for (; pi; pi = (flag_restore != 0) ? rpipe : pi->next) {
+ if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL ||
+ pi->r_mode == RES_FOR) {
+#ifdef __PPCBOOT__
+ /* check Ctrl-C */
+ ctrlc();
+ if ((had_ctrlc())) {
+ return 1;
+ }
+#endif
+ flag_restore = 0;
+ if (!rpipe) {
+ flag_rep = 0;
+ rpipe = pi;
+ }
+ }
rmode = pi->r_mode;
debug_printf("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", rmode, if_code, next_if_code, skip_more_in_this_rmode);
if (rmode == skip_more_in_this_rmode) continue;
if (rmode == RES_THEN && if_code) continue;
if (rmode == RES_ELSE && !if_code) continue;
if (rmode == RES_ELIF && !if_code) continue;
+ if (rmode == RES_FOR && pi->num_progs) {
+ if (!list) {
+ /* if no variable values after "in" we skip "for" */
+ if (!pi->next->progs->argv) continue;
+ /* create list of variable values */
+ list = make_list_in(pi->next->progs->argv,
+ pi->progs->argv[0]);
+ save_list = list;
+ save_name = pi->progs->argv[0];
+ pi->progs->argv[0] = NULL;
+ flag_rep = 1;
+ }
+ if (!(*list)) {
+ free(pi->progs->argv[0]);
+ free(save_list);
+ list = NULL;
+ flag_rep = 0;
+ pi->progs->argv[0] = save_name;
+#ifndef __PPCBOOT__
+ pi->progs->glob_result.gl_pathv[0] =
+ pi->progs->argv[0];
+#endif
+ continue;
+ } else {
+ /* insert new value from list for variable */
+ if (pi->progs->argv[0])
+ free(pi->progs->argv[0]);
+ pi->progs->argv[0] = *list++;
+#ifndef __PPCBOOT__
+ pi->progs->glob_result.gl_pathv[0] =
+ pi->progs->argv[0];
+#endif
+ }
+ }
+ if (rmode == RES_IN) continue;
+ if (rmode == RES_DO) {
+ if (!flag_rep) continue;
+ }
+ if ((rmode == RES_DONE)) {
+ if (flag_rep) {
+ flag_restore = 1;
+ } else {
+ rpipe = NULL;
+ }
+ }
if (pi->num_progs == 0) continue;
+#ifndef __PPCBOOT__
+ save_num_progs = pi->num_progs; /* save number of programs */
+#endif
rcode = run_pipe_real(pi);
debug_printf("run_pipe_real returned %d\n",rcode);
#ifndef __PPCBOOT__
}
debug_printf("checkjobs returned %d\n",rcode);
}
-#endif
last_return_code=rcode;
+#else
+ last_return_code=(rcode == 0) ? 0 : 1;
+#endif
+#ifndef __PPCBOOT__
+ pi->num_progs = save_num_progs; /* restore number of programs */
+#endif
if ( rmode == RES_IF || rmode == RES_ELIF )
next_if_code=rcode; /* can be overwritten a number of times */
+ if (rmode == RES_WHILE)
+ flag_rep = !last_return_code;
+ if (rmode == RES_UNTIL)
+ flag_rep = last_return_code;
if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) ||
(rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) )
skip_more_in_this_rmode=rmode;
#ifndef __PPCBOOT__
checkjobs(NULL);
-#endif
+#endif
}
return rcode;
}
struct redir_struct *r, *rnext;
#endif
int a, i, ret_code=0;
- char *ind = indenter(indent);
+ char *ind = indenter(indent);
+
#ifndef __PPCBOOT__
if (pi->stopped_progs > 0)
return ret_code;
if (child->argv) {
for (a=0,p=child->argv; *p; a++,p++) {
final_printf("%s argv[%d] = %s\n",ind,a,*p);
- }
+ }
#ifndef __PPCBOOT__
globfree(&child->glob_result);
#else
child->argc = 0;
#endif
child->argv=NULL;
- } else if (child->group) {
+ } else if (child->group) {
#ifndef __PPCBOOT__
- final_printf("%s begin group (subshell:%d)\n",ind, child->subshell);
+ final_printf("%s begin group (subshell:%d)\n",ind, child->subshell);
#endif
ret_code = free_pipe_list(child->group,indent+3);
final_printf("%s end group\n",ind);
}
#ifndef __PPCBOOT__
for (r=child->redirects; r; r=rnext) {
-
final_printf("%s redirect %d%s", ind, r->fd, redir_table[r->type].descrip);
-
if (r->dup == -1) {
/* guard against the case >$FOO, where foo is unset or blank */
if (r->word.gl_pathv) {
}
} else {
final_printf("&%d\n", r->dup);
- }
+ }
rnext=r->next;
free(r);
}
pglob->gl_pathv[i], pglob->gl_pathv[i]);
}
#endif
+
static int xglob(o_string *dest, int flags, glob_t *pglob)
{
int gr;
return gr;
}
#endif
+
/* This is used to get/check local shell variables */
static char *get_local_var(const char *s)
{
struct variables *cur;
name=strdup(s);
+
#ifdef __PPCBOOT__
if (getenv(name) != NULL) {
printf ("ERROR: "
}
}
}
+
#ifndef __PPCBOOT__
if(result==0 && cur->flg_export==1) {
*(value-1) = '=';
#endif
return result;
}
+
#ifndef __PPCBOOT__
static void unset_local_var(const char *name)
{
}
}
#endif
+
static int is_assignment(const char *s)
{
if (s==NULL || !isalpha(*s)) return 0;
while(isalnum(*s) || *s=='_') ++s;
return *s=='=';
}
+
#ifndef __PPCBOOT__
/* the src parameter allows us to peek forward to a possible &n syntax
* for file descriptor duplication, e.g., "2>&1".
return 0;
}
#endif
+
struct pipe *new_pipe(void) {
struct pipe *pi;
pi = xmalloc(sizeof(struct pipe));
{ "elif", RES_ELIF, FLAG_THEN },
{ "else", RES_ELSE, FLAG_FI },
{ "fi", RES_FI, FLAG_END },
-#ifndef __PPCBOOT__
- { "for", RES_FOR, FLAG_DO | FLAG_START },
+ { "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 }
-#endif
};
struct reserved_combo *r;
for (r=reserved_list;
if (r->flag & FLAG_START) {
struct p_context *new = xmalloc(sizeof(struct p_context));
debug_printf("push stack\n");
+ if (ctx->w == RES_IN || ctx->w == RES_FOR) {
+ syntax();
+ free(new);
+ ctx->w = RES_SNTX;
+ b_reset(dest);
+ return 1;
+ }
*new = *ctx; /* physical copy */
initialize_context(ctx);
ctx->stack=new;
if (ctx->old_flag & FLAG_END) {
struct p_context *old;
debug_printf("pop stack\n");
+ done_pipe(ctx,PIPE_SEQ);
old = ctx->stack;
old->child->group = ctx->list_head;
#ifndef __PPCBOOT__
gr = xglob(dest, flags, glob_target);
if (gr != 0) return 1;
#endif
+
b_reset(dest);
#ifndef __PPCBOOT__
if (ctx->pending_redirect) {
child->argv = glob_target->gl_pathv;
}
#endif
+ if (ctx->w == RES_FOR) {
+ done_word(dest,ctx);
+ done_pipe(ctx,PIPE_SEQ);
+ }
return 0;
}
debug_printf("done_command: initializing\n");
}
pi->progs = xrealloc(pi->progs, sizeof(*pi->progs) * (pi->num_progs+1));
+
prog = pi->progs + pi->num_progs;
#ifndef __PPCBOOT__
prog->redirects = NULL;
prog->glob_result.gl_pathv = NULL;
prog->family = pi;
#endif
- ctx->child=prog;
+ prog->sp = 0;
+ ctx->child = prog;
+
/* but ctx->pipe and ctx->list_head remain unchanged */
return 0;
}
done_command(ctx); /* set up new pipe to accept commands */
return 0;
}
+
#ifndef __PPCBOOT__
/* peek ahead in the in_str to find out if we have a "&n" construct,
* as in "2>&1", that represents duplicating a file descriptor.
/* basically useful version until someone wants to get fancier,
* see the bash man page under "Parameter Expansion" */
-static void lookup_param(o_string *dest, struct p_context *ctx, o_string *src)
+static char *lookup_param(char *src)
{
- const char *p=NULL;
-
- if (src->data) {
- p = getenv(src->data);
+ char *p=NULL;
+ if (src) {
+ p = getenv(src);
if (!p)
- p = get_local_var(src->data);
+ p = get_local_var(src);
}
- if (p) parse_string(dest, ctx, p); /* recursion */
- b_free(src);
+ return p;
}
/* return code: 0 for OK, 1 for syntax error */
#else
int advance=0;
#endif
- o_string alt=NULL_O_STRING;
#ifndef __PPCBOOT__
char sep[]=" ";
#endif
int ch = input->peek(input); /* first character after the $ */
debug_printf("handle_dollar: ch=%c\n",ch);
if (isalpha(ch)) {
+ b_addchr(dest, SPECIAL_VAR_SYMBOL);
+ ctx->child->sp++;
while(ch=b_peek(input),isalnum(ch) || ch=='_') {
b_getch(input);
- b_addchr(&alt,ch);
+ b_addchr(dest,ch);
}
- lookup_param(dest, ctx, &alt);
+ b_addchr(dest, SPECIAL_VAR_SYMBOL);
#ifndef __PPCBOOT__
} else if (isdigit(ch)) {
i = ch-'0'; /* XXX is $0 special? */
break;
#endif
case '{':
+ b_addchr(dest, SPECIAL_VAR_SYMBOL);
+ ctx->child->sp++;
b_getch(input);
/* XXX maybe someone will try to escape the '}' */
while(ch=b_getch(input),ch!=EOF && ch!='}') {
- b_addchr(&alt,ch);
+ b_addchr(dest,ch);
}
if (ch != '}') {
syntax();
return 1;
}
- lookup_param(dest, ctx, &alt);
+ b_addchr(dest, SPECIAL_VAR_SYMBOL);
break;
#ifndef __PPCBOOT__
case '(':
return 0;
}
+#ifndef __PPCBOOT__
int parse_string(o_string *dest, struct p_context *ctx, const char *src)
{
struct in_str foo;
setup_string_in_str(&foo, src);
return parse_stream(dest, ctx, &foo, '\0');
}
+#endif
/* return code is 0 for normal exit, 1 for syntax error */
int parse_stream(o_string *dest, struct p_context *ctx,
b_addqchr(dest, ch, dest->quote);
} else {
if (m==2) { /* unquoted IFS */
-#ifndef __PPCBOOT__
- done_word(dest, ctx);
-#else
- if (done_word(dest, ctx)) {
+ if (done_word(dest, ctx)) {
return 1;
}
-#endif
/* If we aren't performing a substitution, treat a newline as a
* command separator. */
if (end_trigger != '\0' && ch=='\n')
struct p_context ctx;
o_string temp=NULL_O_STRING;
int rcode;
-
do {
initialize_context(&ctx);
update_ifs_map();
- inp->promptmode=1;
+ inp->promptmode=1;
rcode = parse_stream(&temp, &ctx, inp, '\n');
#ifdef __PPCBOOT__
- if (rcode != 1) {
-#endif
- done_word(&temp, &ctx);
- done_pipe(&ctx,PIPE_SEQ);
- run_list(ctx.list_head);
- b_free(&temp);
-#ifdef __PPCBOOT__
- } else {
- if (ctx.old_flag != 0) {
- free(ctx.stack);
- b_reset(&temp);
- }
- if (inp->__promptme == 0) printf("<INTERRUPT>\n");
- inp->__promptme = 1;
- temp.nonnull = 0;
- temp.quote = 0;
- inp->p = NULL;
- free_pipe_list(ctx.list_head,0);
- b_free(&temp);
+ if (rcode == 1) flag_repeat = 0;
+#endif
+ if (rcode != 1) {
+ done_word(&temp, &ctx);
+ done_pipe(&ctx,PIPE_SEQ);
+#ifndef __PPCBOOT__
+ run_list(ctx.list_head);
+#else
+ rcode = run_list(ctx.list_head);
+ if (rcode == -1) flag_repeat = 0;
+#endif
+ } else {
+ if (ctx.old_flag != 0) {
+ free(ctx.stack);
+ b_reset(&temp);
+ }
+#ifdef __PPCBOOT__
+ if (inp->__promptme == 0) printf("<INTERRUPT>\n");
+ inp->__promptme = 1;
+#endif
+ temp.nonnull = 0;
+ temp.quote = 0;
+ inp->p = NULL;
+ free_pipe_list(ctx.list_head,0);
}
+ b_free(&temp);
+#ifndef __PPCBOOT__
+ } while (rcode != -1); /* loop on syntax errors, return on EOF */
+ return 0;
+#else
} 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
#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__ */
parse_file_outer();
return 1;
}
+
+static void *xmalloc(size_t size)
+{
+ void *p = NULL;
+
+ if (!(p = malloc(size))) {
+ printf("ERROR : memory not allocated\n");
+ for(;;);
+ }
+ return p;
+}
+
+static void *xrealloc(void *ptr, size_t size)
+{
+ void *p = NULL;
+
+ if (!(p = realloc(ptr, size))) {
+ printf("ERROR : memory not allocated\n");
+ for(;;);
+ }
+ return p;
+}
#endif /* __PPCBOOT__ */
#ifndef __PPCBOOT__
return(opt?opt:last_return_code);
}
#endif
+
+static char *insert_var_value(char *inp)
+{
+ int res_str_len = 0;
+ int len;
+ int done = 0;
+ char *p, *p1, *res_str = NULL;
+
+ while ((p = strchr(inp, SPECIAL_VAR_SYMBOL))) {
+ if (p != inp) {
+ len = p - inp;
+ res_str = xrealloc(res_str, (res_str_len + len));
+ strncpy((res_str + res_str_len), inp, len);
+ res_str_len += len;
+ }
+ inp = ++p;
+ p = strchr(inp, SPECIAL_VAR_SYMBOL);
+ *p = '\0';
+ if ((p1 = lookup_param(inp))) {
+ len = res_str_len + strlen(p1);
+ res_str = xrealloc(res_str, (1 + len));
+ strcpy((res_str + res_str_len), p1);
+ res_str_len = len;
+ }
+ *p = SPECIAL_VAR_SYMBOL;
+ inp = ++p;
+ done = 1;
+ }
+ if (done) {
+ res_str = xrealloc(res_str, (1 + res_str_len + strlen(inp)));
+ strcat(res_str, inp);
+ }
+ return (res_str == NULL) ? inp : res_str;
+}
+
+static char **make_list_in(char **inp, char *name)
+{
+ int len, i;
+ int name_len = strlen(name);
+ int n = 0;
+ char **list = NULL;
+ char *p1, *p2, *p3;
+
+ /* create list of variable values */
+ for (i = 0; inp[i]; i++) {
+ p3 = insert_var_value(inp[i]);
+ p1 = p3;
+ while (*p1) {
+ if ((*p1 == ' ')) {
+ p1++;
+ continue;
+ }
+ if ((p2 = strchr(p1, ' '))) {
+ len = p2 - p1;
+ } else {
+ len = strlen(p1);
+ p2 = p1 + len;
+ }
+ /* we use n + 2 in realloc for list,because we add
+ * new element and then we will add NULL element */
+ list = xrealloc(list, sizeof(*list) * (n + 2));
+ list[n] = xmalloc(2 + name_len + len);
+ strcpy(list[n], name);
+ strcat(list[n], "=");
+ strncat(list[n], p1, len);
+ list[n++][name_len + len + 1] = '\0';
+ p1 = p2;
+ }
+ if (p3 != inp[i]) free(p3);
+ }
+ list[n] = NULL;
+ return list;
+}
+
#endif /* CFG_HUSH_PARSER */
/****************************************************************************/
/*
* Configurable monitor commands
*/
-#define CFG_CMD_BDI 0x00000001 /* bdinfo */
-#define CFG_CMD_LOADS 0x00000002 /* loads */
-#define CFG_CMD_LOADB 0x00000004 /* loadb */
-#define CFG_CMD_IMI 0x00000008 /* iminfo */
-#define CFG_CMD_CACHE 0x00000010 /* icache, dcache */
-#define CFG_CMD_FLASH 0x00000020 /* flinfo, erase, protect */
-#define CFG_CMD_MEMORY 0x00000040 /* md, mm, nm, mw, cp, cmp, */
- /* crc, base, loop, mtest */
-#define CFG_CMD_NET 0x00000080 /* bootp, tftpboot, rarpboot */
-#define CFG_CMD_ENV 0x00000100 /* saveenv */
-#define CFG_CMD_KGDB 0x00000200 /* kgdb */
-#define CFG_CMD_PCMCIA 0x00000400 /* PCMCIA support */
-#define CFG_CMD_IDE 0x00000800 /* IDE harddisk support */
-#define CFG_CMD_PCI 0x00001000 /* pciinfo */
-#define CFG_CMD_IRQ 0x00002000 /* irqinfo */
-#define CFG_CMD_BOOTD 0x00004000 /* bootd */
-#define CFG_CMD_CONSOLE 0x00008000 /* coninfo */
-#define CFG_CMD_EEPROM 0x00010000 /* EEPROM read/write support */
-#define CFG_CMD_ASKENV 0x00020000 /* ask for env variable */
-#define CFG_CMD_RUN 0x00040000 /* run command in env variable */
-#define CFG_CMD_ECHO 0x00080000 /* echo arguments */
-#define CFG_CMD_I2C 0x00100000 /* I2C serial bus support */
-#define CFG_CMD_REGINFO 0x00200000 /* Register dump */
-#define CFG_CMD_IMMAP 0x00400000 /* IMMR dump support */
-#define CFG_CMD_DATE 0x00800000 /* support for RTC, date/time...*/
-#define CFG_CMD_DHCP 0x01000000 /* DHCP Support */
-#define CFG_CMD_BEDBUG 0x02000000 /* Include BedBug Debugger */
-#define CFG_CMD_FDC 0x04000000 /* Floppy Disk Support */
-#define CFG_CMD_SCSI 0x08000000 /* SCSI Support */
-#define CFG_CMD_AUTOSCRIPT 0x10000000 /* Autoscript Support */
-#define CFG_CMD_MII 0x20000000 /* MII support */
-#define CFG_CMD_SETGETDCR 0x40000000 /* DCR support on 4xx */
-#define CFG_CMD_BSP 0x80000000 /* Board Specific functions */
-
-#define CFG_CMD_ELF 0x0000000100000000 /* ELF (VxWorks) load/boot cmd */
+#define CFG_CMD_BDI 0x00000001 /* bdinfo */
+#define CFG_CMD_LOADS 0x00000002 /* loads */
+#define CFG_CMD_LOADB 0x00000004 /* loadb */
+#define CFG_CMD_IMI 0x00000008 /* iminfo */
+#define CFG_CMD_CACHE 0x00000010 /* icache, dcache */
+#define CFG_CMD_FLASH 0x00000020 /* flinfo, erase, protect */
+#define CFG_CMD_MEMORY 0x00000040 /* md, mm, nm, mw, cp, cmp, */
+ /* crc, base, loop, mtest */
+#define CFG_CMD_NET 0x00000080 /* bootp, tftpboot, rarpboot */
+#define CFG_CMD_ENV 0x00000100 /* saveenv */
+#define CFG_CMD_KGDB 0x00000200 /* kgdb */
+#define CFG_CMD_PCMCIA 0x00000400 /* PCMCIA support */
+#define CFG_CMD_IDE 0x00000800 /* IDE harddisk support */
+#define CFG_CMD_PCI 0x00001000 /* pciinfo */
+#define CFG_CMD_IRQ 0x00002000 /* irqinfo */
+#define CFG_CMD_BOOTD 0x00004000 /* bootd */
+#define CFG_CMD_CONSOLE 0x00008000 /* coninfo */
+#define CFG_CMD_EEPROM 0x00010000 /* EEPROM read/write support */
+#define CFG_CMD_ASKENV 0x00020000 /* ask for env variable */
+#define CFG_CMD_RUN 0x00040000 /* run command in env variable */
+#define CFG_CMD_ECHO 0x00080000 /* echo arguments */
+#define CFG_CMD_I2C 0x00100000 /* I2C serial bus support */
+#define CFG_CMD_REGINFO 0x00200000 /* Register dump */
+#define CFG_CMD_IMMAP 0x00400000 /* IMMR dump support */
+#define CFG_CMD_DATE 0x00800000 /* support for RTC, date/time...*/
+#define CFG_CMD_DHCP 0x01000000 /* DHCP Support */
+#define CFG_CMD_BEDBUG 0x02000000 /* Include BedBug Debugger */
+#define CFG_CMD_FDC 0x04000000 /* Floppy Disk Support */
+#define CFG_CMD_SCSI 0x08000000 /* SCSI Support */
+#define CFG_CMD_AUTOSCRIPT 0x10000000 /* Autoscript Support */
+#define CFG_CMD_MII 0x20000000 /* MII support */
+#define CFG_CMD_SETGETDCR 0x40000000 /* DCR support on 4xx */
+#define CFG_CMD_BSP 0x80000000 /* Board Specific functions */
+
+#define CFG_CMD_ELF 0x0000000100000000 /* ELF (VxWorks) load/boot cmd */
+#define CFG_CMD_MISC 0x0000000200000000 /* Misc functions like sleep etc*/
#define CFG_CMD_ALL 0xFFFFFFFFFFFFFFFF /* ALL commands */
#if (CONFIG_COMMANDS & CFG_CMD_EEPROM)
+#ifdef CFG_I2C_MULTI_EEPROMS
+#define CMD_TBL_EEPROM MK_CMD_TBL_ENTRY( \
+ "eeprom", 3, 6, 1, do_eeprom, \
+ "eeprom - EEPROM sub-system\n", \
+ "read devaddr addr off cnt\n" \
+ "eeprom write devaddr addr off cnt\n" \
+ " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'\n" \
+),
+#else /* One EEPROM */
#define CMD_TBL_EEPROM MK_CMD_TBL_ENTRY( \
"eeprom", 3, 5, 1, do_eeprom, \
- "eeprom - EEPROM sub-system\n", \
+ "eeprom - EEPROM sub-system\n", \
"read addr off cnt\n" \
"eeprom write addr off cnt\n" \
" - read/write `cnt' bytes at EEPROM offset `off'\n" \
),
+#endif /* CFG_I2C_MULTI_EEPROMS */
int do_eeprom (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]);
#else
#define CMD_TBL_IRQINFO
#endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */
+#if (CONFIG_COMMANDS & CFG_CMD_MISC)
+#define CMD_TBL_MISC MK_CMD_TBL_ENTRY( \
+ "sleep", 5, 2, 2, do_sleep, \
+ "sleep - delay execution for some time\n", \
+ "N\n" \
+ " - delay execution for N seconds (N is _decimal_ !!!)\n" \
+),
+
+/* Implemented in common/cmd_misc.c */
+int do_sleep (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]);
+#else
+#define CMD_TBL_MISC
+#endif /* CFG_CMD_MISC */
+
#endif /* _CMD_MISC_H */
#define CFG_LONGHELP /* undef to save memory */
#define CFG_PROMPT "=> " /* Monitor Command Prompt */
-#undef CFG_HUSH_PARSER /* use "hush" command parser */
+#define CFG_HUSH_PARSER 1 /* use "hush" command parser */
#ifdef CFG_HUSH_PARSER
#define CFG_PROMPT_HUSH_PS2 "> "
#endif
#define CONFIG_BOOTDELAY 3 /* autoboot after 3 seconds */
#if 1
-#define CONFIG_BOOTCOMMAND "bootvx" /* autoboot command */
+#define CONFIG_BOOTCOMMAND "bootvx" /* VxWorks boot command */
#else
#define CONFIG_BOOTCOMMAND "bootp" /* autoboot command */
#endif
#undef CONFIG_BOOTARGS
-#define CONFIG_LOADADDR 0x10000
+#define CONFIG_LOADADDR F0080000
+
+#undef CONFIG_ETHADDR /* Default, overridden at boot */
+#define CONFIG_IPADDR 192.168.1.1
+#define CONFIG_NETMASK 255.255.255.0
+#define CONFIG_SERVERIP 192.168.1.2
#define CONFIG_LOADS_ECHO 1 /* echo on for serial download */
-#define CFG_LOADS_BAUD_CHANGE 1 /* allow baudrate change */
+#undef CFG_LOADS_BAUD_CHANGE /* disallow baudrate change */
#define CONFIG_MII 1 /* MII PHY management */
#define CONFIG_PHY_ADDR 0 /* PHY address */
#include <cmd_confdefs.h>
#undef CONFIG_WATCHDOG /* watchdog disabled */
+#undef CONFIG_HW_WATCHDOG /* HW Watchdog, board specific */
/*
* Miscellaneous configurable options
*/
#define CFG_LONGHELP /* undef to save memory */
#define CFG_PROMPT "Wave7Optics> " /* Monitor Command Prompt */
+#define CFG_HUSH_PARSER /* Hush parse for ppcboot */
+#ifdef CFG_HUSH_PARSER
+#define CFG_PROMPT_HUSH_PS2 "> "
+#endif
#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
#define CFG_CBSIZE 1024 /* Console I/O Buffer Size */
#else
#define CFG_EXT_SERIAL_CLOCK 11059200 /* use external serial clock */
/* The following table includes the supported baudrates */
-#define CFG_BAUDRATE_TABLE \
- {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 7200, \
- 9600, 19200, 14400, 28800, 33600, 38400, 57600, 76800, 115200, \
- 153600, 230400, 307200, 691200}
+#define CFG_BAUDRATE_TABLE {9600}
#define CFG_CLKS_IN_HZ 1 /* everything, incl board info, in Hz */
#define CFG_LOAD_ADDR 0x100000 /* default load address */
-#define CFG_EXTBDINFO 1 /* To use extended board_info (bd_t) */
+#define CFG_EXTBDINFO 1 /* use extended board_info (bd_t) */
#define CFG_HZ 1000 /* decrementer freq: 1 ms ticks */
#define CONFIG_PCI /* include pci support */
#define CONFIG_PCI_HOST PCI_HOST_AUTO /* select pci host function */
-#define CONFIG_PCI_PNP /* no pci plug-and-play */
+#define CONFIG_PCI_PNP /* pci plug-and-play */
/* resource configuration */
#define CFG_PCI_SUBSYS_VENDORID 0x1014 /* PCI Vendor ID: IBM */
#define CFG_PCI_SUBSYS_DEVICEID 0x0156 /* PCI Device ID: 405GP */
#define CFG_PCI_PTM1LA 0x00000000 /* point to sdram */
#define CFG_PCI_PTM1MS 0x80000001 /* 2GB, enable hard-wired to 1 */
-#define CFG_PCI_PTM2LA 0xfff00000 /* point to flash */
-#define CFG_PCI_PTM2MS 0xfff00001 /* 1MB, enable */
+#define CFG_PCI_PTM2LA 0x00000000 /* disabled */
+#define CFG_PCI_PTM2MS 0x00000000 /* disabled */
/*-----------------------------------------------------------------------
* Start addresses for the final memory configuration
* Please note that CFG_SDRAM_BASE _must_ start at 0
*/
#define CFG_SDRAM_BASE 0x00000000
-#define CFG_FLASH_BASE 0xFFF80000
+#define CFG_FLASH_BASE 0xFFFD0000
#define CFG_MONITOR_BASE CFG_FLASH_BASE
#define CFG_MONITOR_LEN (192 * 1024) /* Reserve 196 kB for Monitor */
#define CFG_MALLOC_LEN (128 * 1024) /* Reserve 128 kB for malloc() */
* Flash EEPROM for environment
*/
#define CFG_ENV_IS_IN_FLASH 1
-#define CFG_ENV_OFFSET 0x00050000 /* Offset of Environment Sector */
+#define CFG_ENV_OFFSET 0x00040000 /* Offset of Environment Sector */
#define CFG_ENV_SIZE 0x10000 /* Total Size of env. sector */
#define CFG_ENV_SECT_SIZE 0x10000 /* see README - env sec tot sze */
#endif
/*-----------------------------------------------------------------------
- * I2C EEPROM (ATMEL 24C04N)
+ * I2C EEPROM (Catalyst CAT24WC08)
*/
#undef CONFIG_I2C_X /* 8 bit access */
-#define CFG_I2C_EEPROM_ADDR 0x50 /* EEPROM ATMEL 24C04N */
+#define CFG_I2C_EEPROM_ADDR 0x50 /* EEPROM Catalyst CAT24WC08 */
+#define CFG_I2C_MULTI_EEPROMS
#define CONFIG_I2C
#define CFG_INIT_RAM_ADDR 0x00df0000 /* inside of SDRAM */
#define CFG_INIT_RAM_END 0x0f00 /* End of used area in RAM */
#define CFG_INIT_DATA_SIZE 64 /* size in bytes reserved for initial data */
-#define CFG_INIT_DATA_OFFSET (CFG_INIT_RAM_END - CFG_INIT_DATA_SIZE)
-#define CFG_INIT_SP_OFFSET CFG_INIT_DATA_OFFSET
+#define CFG_INIT_DATA_OFFSET (CFG_INIT_RAM_END - CFG_INIT_DATA_SIZE)
+#define CFG_INIT_SP_OFFSET CFG_INIT_DATA_OFFSET
/*
#define CONFIG_BOOTDELAY 3 /* autoboot after 3 seconds */
#if 1
-#define CONFIG_BOOTCOMMAND "bootvx" /* autoboot command */
+#define CONFIG_BOOTCOMMAND "bootvx" /* VxWorks boot command */
#else
#define CONFIG_BOOTCOMMAND "bootp" /* autoboot command */
#endif
#undef CONFIG_BOOTARGS
-#define CONFIG_LOADADDR 0x10000
+#define CONFIG_LOADADDR F0080000
+
+#undef CONFIG_ETHADDR /* Default, overridden at boot */
+#define CONFIG_IPADDR 192.168.1.1
+#define CONFIG_NETMASK 255.255.255.0
+#define CONFIG_SERVERIP 192.168.1.2
#define CONFIG_LOADS_ECHO 1 /* echo on for serial download */
-#define CFG_LOADS_BAUD_CHANGE 1 /* allow baudrate change */
+#undef CFG_LOADS_BAUD_CHANGE /* disallow baudrate change */
#define CONFIG_MII 1 /* MII PHY management */
#define CONFIG_PHY_ADDR 0 /* PHY address */
-#define CONFIG_RTC_M48T35A 1 /* ST Electronics M48 timekeeper*/
+#define CONFIG_RTC_M48T35A 1 /* ST Electronics M48 timekeeper */
#define CONFIG_COMMANDS \
(CONFIG_CMD_DFL | CFG_CMD_PCI | CFG_CMD_IRQ | CFG_CMD_ASKENV | \
#include <cmd_confdefs.h>
#undef CONFIG_WATCHDOG /* watchdog disabled */
+#undef CONFIG_HW_WATCHDOG /* HW Watchdog, board specific */
/*
* Miscellaneous configurable options
*/
#define CFG_LONGHELP /* undef to save memory */
#define CFG_PROMPT "Wave7Optics> " /* Monitor Command Prompt */
+#define CFG_HUSH_PARSER /* Hush parse for ppcboot */
+#ifdef CFG_HUSH_PARSER
+#define CFG_PROMPT_HUSH_PS2 "> "
+#endif
#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
#define CFG_CBSIZE 1024 /* Console I/O Buffer Size */
#else
#define CFG_EXT_SERIAL_CLOCK 11059200 /* use external serial clock */
/* The following table includes the supported baudrates */
-#define CFG_BAUDRATE_TABLE \
- {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 7200, \
- 9600, 19200, 14400, 28800, 33600, 38400, 57600, 76800, 115200, \
- 153600, 230400, 307200, 691200}
+#define CFG_BAUDRATE_TABLE {9600}
#define CFG_CLKS_IN_HZ 1 /* everything, incl board info, in Hz */
#define CONFIG_PCI /* include pci support */
#define CONFIG_PCI_HOST PCI_HOST_AUTO /* select pci host function */
-#define CONFIG_PCI_PNP /* no pci plug-and-play */
-/* resource configuration */
+#define CONFIG_PCI_PNP /* pci plug-and-play */
+/* resource configuration */
#define CFG_PCI_SUBSYS_VENDORID 0x1014 /* PCI Vendor ID: IBM */
#define CFG_PCI_SUBSYS_DEVICEID 0x0156 /* PCI Device ID: 405GP */
#define CFG_PCI_PTM1LA 0x00000000 /* point to sdram */
#define CFG_PCI_PTM1MS 0x80000001 /* 2GB, enable hard-wired to 1 */
-#define CFG_PCI_PTM2LA 0xfff00000 /* point to flash */
-#define CFG_PCI_PTM2MS 0xfff00001 /* 1MB, enable */
+#define CFG_PCI_PTM2LA 0x00000000 /* disabled */
+#define CFG_PCI_PTM2MS 0x00000000 /* disabled */
/*-----------------------------------------------------------------------
* Start addresses for the final memory configuration
* Please note that CFG_SDRAM_BASE _must_ start at 0
*/
#define CFG_SDRAM_BASE 0x00000000
-#define CFG_FLASH_BASE 0xFFF80000
+#define CFG_FLASH_BASE 0xFFFD0000
#define CFG_MONITOR_BASE CFG_FLASH_BASE
#define CFG_MONITOR_LEN (192 * 1024) /* Reserve 196 kB for Monitor */
#define CFG_MALLOC_LEN (128 * 1024) /* Reserve 128 kB for malloc() */
* Flash EEPROM for environment
*/
#define CFG_ENV_IS_IN_FLASH 1
-#define CFG_ENV_OFFSET 0x00050000 /* Offset of Environment Sector */
+#define CFG_ENV_OFFSET 0x00040000 /* Offset of Environment Sector */
#define CFG_ENV_SIZE 0x10000 /* Total Size of env. sector */
#define CFG_ENV_SECT_SIZE 0x10000 /* see README - env sec tot sze */
*/
#undef CONFIG_I2C_X /* 8 bit access */
#define CFG_I2C_EEPROM_ADDR 0x50 /* EEPROM ATMEL 24C04N */
+#define CFG_I2C_MULTI_EEPROMS
#define CONFIG_I2C
#define CONFIG_PORT_ADDR 0xF0000500
/*-----------------------------------------------------------------------
- * Definitions for initial stack pointer and data area
+ * Definitions for initial stack pointer and data area (in RAM)
*/
#define CFG_INIT_RAM_ADDR 0x00df0000 /* inside of SDRAM */
#define CFG_INIT_RAM_END 0x0f00 /* End of used area in RAM */
char *getenv (uchar *);
int getenv_r (uchar *name, uchar *buf, unsigned len);
void inline setenv (char *, char *);
+int saveenv(void);
#if defined(CONFIG_CPCI405) || \
defined(CONFIG_AR405) || \
defined(CONFIG_WALNUT405)
/* $(BOARD)/eeprom.c */
void eeprom_init (void);
-int eeprom_read (unsigned offset, uchar *buffer, unsigned cnt);
-int eeprom_write (unsigned offset, uchar *buffer, unsigned cnt);
+int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
+int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
# ifdef CONFIG_LWMON
extern uchar pic_read (uchar reg);
extern void pic_write (uchar reg, uchar val);
# endif
#endif
+/*
+ * Set this up regardless of board
+ * type, to prevent errors.
+ */
+#if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
+# define CFG_DEF_EEPROM_ADDR 0
+#else
+# define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
+#endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
+
#if defined(CONFIG_PCU_E) || defined(CONFIG_CCM)
extern void spi_init_f (void);
extern void spi_init_r (void);
int checkdcache (void);
void upmconfig (unsigned int, unsigned int *, unsigned int);
ulong get_tbclk (void);
-#if defined(CONFIG_WATCHDOG)
-void watchdog_reset(void);
-#endif /* CONFIG_WATCHDOG */
/* $(CPU)/speed.c */
#if defined(CONFIG_8260)
void get_sys_info (PPC405_SYS_INFO *);
#endif
-/* $(CPU)/cpu.c */
-#if defined(CONFIG_8xx)
-void reset_8xx_watchdog(volatile immap_t *immr);
-#endif
-
-/* $(CPU)/cpu.c */
-#if defined(CONFIG_4xx)
-void reset_4xx_watchdog(void);
-#endif
-
/* $(CPU)/cpu_init.c */
#if defined(CONFIG_8xx) || defined(CONFIG_8260)
void cpu_init_f (volatile immap_t *immr);