import of upstream version 1.17
[mw/micromonitor-lm32.git] / umon_main / target / common / env.c
1 /* shell variable functions:
2  *      Used to load or retrieve shell variable information from the
3  *      shell variable table.
4  *
5  *      General notice:
6  *      This code is part of a boot-monitor package developed as a generic base
7  *      platform for embedded system designs.  As such, it is likely to be
8  *      distributed to various projects beyond the control of the original
9  *      author.  Please notify the author of any enhancements made or bugs found
10  *      so that all may benefit from the changes.  In addition, notification back
11  *      to the author will allow the new user to pick up changes that may have
12  *      been made by other users after this version of the code was distributed.
13  *
14  *      Note1: the majority of this code was edited with 4-space tabs.
15  *      Note2: as more and more contributions are accepted, the term "author"
16  *                 is becoming a mis-representation of credit.
17  *
18  *      Original author:        Ed Sutter
19  *      Email:                          esutter@lucent.com
20  *      Phone:                          908-582-2351
21  */
22 #include <stdarg.h>
23 #include "config.h"
24 #include "tfs.h"
25 #include "tfsprivate.h"
26 #include "ether.h"
27 #include "genlib.h"
28 #include "stddefs.h"
29 #include "cli.h"
30 #include "version.h"
31 #include "boardinfo.h"
32 #include "ee.h"
33 #include "timer.h"
34
35 #if INCLUDE_SHELLVARS
36
37 #ifdef TARGET_ENV_SETUP
38 extern void TARGET_ENV_SETUP(void);
39 #endif
40
41 #ifndef PROMPT
42 #define PROMPT "uMON>"
43 #endif
44
45 int     shell_print(void);
46 int     envToExec(char *);
47 void clearenv(void);
48
49 /* Structure used for the shell variables: */
50 struct s_shell {
51         char    *val;           /* Value stored in shell variable */
52         char    *name;          /* Name of shell variable */
53         int             vsize;          /* Size of storage allocated for value */
54         struct  s_shell *next;
55 };
56
57 struct s_shell *shell_vars;
58
59 /* If no malloc, then use locally defined env_alloc() and env_free()...
60  */
61 #if INCLUDE_MALLOC
62
63 #define env_alloc       malloc
64 #define env_free        free
65
66 #else
67
68 #define ENV_ALLOC_TOT   48
69 #define ENV_ALLOC_SIZE  (sizeof(struct s_shell)+8)
70
71 struct env_space {
72         int inuse;
73         char space[ENV_ALLOC_SIZE];
74 } envSpace[ENV_ALLOC_TOT];
75
76
77 char *
78 env_alloc(int size)
79 {
80         int      i;
81
82         if (size > ENV_ALLOC_SIZE)
83                 return(0);
84
85         for(i=0;i<ENV_ALLOC_TOT;i++) {
86                 if (envSpace[i].inuse == 0) {
87                         envSpace[i].inuse = 1;
88                         memset(envSpace[i].space,0,ENV_ALLOC_SIZE);
89                         return(envSpace[i].space);
90                 }
91         }
92         return(0);
93 }
94
95 void
96 env_free(char *space)
97 {
98         int i;
99
100         for(i=0;i<ENV_ALLOC_TOT;i++) {
101                 if (envSpace[i].space == space) {
102                         envSpace[i].inuse = 0;
103                         break;
104                 }
105         }
106         return;
107 }
108 #endif
109
110 /*
111  *  Set()
112  *
113  *      Syntax:
114  *              set var                         clears the variable 'var'
115  *              set var value           assign "value" to variable 'var'
116  *              set -a var value        AND 'var' with 'value'
117  *              set -o var value        OR 'var' with 'value'
118  *              set -i var [value]      increment 'var' by 'value' (or 1 if no value)
119  *              set -d var [value]      decrement 'var' by 'value' (or 1 if no value)
120  *              set -x                          result of -i/-d is in hex
121  */
122 char *SetHelp[] = {
123         "Shell variable operations",
124 #if INCLUDE_EE
125         "-[ab:cdef:iox] [varname[=expression]] [value]",
126 #else
127         "-[ab:cdef:iox] [varname] [value]",
128 #endif
129 #if INCLUDE_VERBOSEHELP
130         " -a        AND var with value",
131         " -b        set console baudrate",
132         " -c        clear the environment",
133         " -d        decrease var by value (or 1)",
134         " -e        build an environ string",
135 #if INCLUDE_TFS
136         " -f{file}  create script from environment",
137 #endif
138         " -i        increase var by value (or 1)",
139         " -o        OR var with value",
140         " -x        result in hex (NA with expressions, use hex())",
141 #endif
142         0,
143 };
144
145 #define SET_NOOP        0
146 #define SET_INCR        1
147 #define SET_DECR        2
148 #define SET_OR          3
149 #define SET_AND         4
150
151 int
152 Set(int argc,char *argv[])
153 {
154         char    *file, *envp, buf[CMDLINESIZE];
155         int             opt, decimal, setop, i;
156
157         setop = SET_NOOP;
158         file = (char *)0;
159         envp = (char *)0;
160         decimal = 1;
161         while((opt=getopt(argc,argv,"ab:cdef:iox")) != -1) {
162                 switch(opt) {
163                 case 'a':               /* logical and */
164                         setop = SET_AND;
165                         decimal = 0;
166                         break;
167                 case 'b':
168                         ChangeConsoleBaudrate(atoi(optarg));
169                         return(CMD_SUCCESS);
170                 case 'c':               /* clear environment */
171                         clearenv();
172                         break;
173                 case 'd':               /* decrement */
174                         setop = SET_DECR;
175                         break;
176                 case 'e':       
177                         envp = getenvp();
178                         break;
179 #if INCLUDE_TFS 
180                 case 'f':               /* build script from environment */
181                         envToExec(optarg);
182                         return(0);
183 #endif
184                 case 'i':               /* increment */
185                         setop = SET_INCR;
186                         break;
187                 case 'o':               /* logical or */
188                         setop = SET_OR;
189                         decimal = 0;
190                         break;
191                 case 'x':
192                         decimal = 0;
193                         break;
194                 default:
195                         return(CMD_PARAM_ERROR);
196                 }
197         }
198
199         if (!shell_vars) {
200                 printf("No memory allocated for environment.\n");
201                 return(CMD_FAILURE);
202         }
203
204         if (setop != SET_NOOP) {        /* Do some operation on a shell variable */
205                 char    *varval;
206                 unsigned long   value, opval;
207
208                 /* For -i & -d, if value is not specified, then assume 1. */
209                 if (argc == optind+1) {
210                         if ((setop == SET_INCR) || (setop == SET_DECR))
211                                 opval = 1;
212                         else
213                                 return(CMD_PARAM_ERROR);
214                 }
215                 else if (argc == optind+2)
216                         opval = strtoul(argv[optind+1],0,0);
217                 else
218                         return(CMD_PARAM_ERROR);
219
220                 varval = getenv(argv[optind]);
221                 if (!varval) {
222                         printf("%s: not found\n", argv[optind]);
223                         return(CMD_FAILURE);
224                 }
225                         
226                 value = strtoul(varval,(char **)0,0);
227                 switch(setop) {
228                         case SET_INCR:
229                                 value += opval;
230                                 break;
231                         case SET_DECR:
232                                 value -= opval;
233                                 break;
234                         case SET_AND:
235                                 value &= opval;
236                                 break;
237                         case SET_OR:
238                                 value |= opval;
239                                 break;
240                 }
241                 if (decimal)
242                         sprintf(buf,"%ld",value);
243                 else
244                         sprintf(buf,"0x%lx",value);
245                 setenv(argv[optind],buf);
246         }
247         else if (argc == optind) {      /* display all variables */
248                 shell_print();
249         }
250         else if (argc == (optind+1)) {  /* run EE or clear one var or set envp */
251 #if INCLUDE_EE
252                 switch(setEE(argv[optind])) {
253                         case 1:
254                                 return(CMD_SUCCESS);
255                         case -1:
256                                 return(CMD_FAILURE);
257                 }
258 #endif
259                 if (envp) 
260                         shell_sprintf(argv[optind],"0x%lx",(ulong)envp);
261                 else
262                         setenv(argv[optind],0);
263         }
264         else if (argc >= (optind+2)) {  /* Set a specific variable */
265                 buf[0] = 0;
266                 for(i=optind+1;i<argc;i++) {
267                         if ((strlen(buf) + strlen(argv[i]) + 2) >= sizeof(buf)) {
268                                 printf("String too large\n");
269                                 break;
270                         }
271                         strcat(buf,argv[i]);
272                         if (i != (argc-1))
273                                 strcat(buf," ");
274                 }
275                 if (!decimal)
276                         shell_sprintf(argv[optind],"0x%lx",atoi(buf));
277                 else
278                         setenv(argv[optind],buf);
279         }
280         else 
281                 return(CMD_PARAM_ERROR);
282
283         return(CMD_SUCCESS);
284 }
285
286 /* Shell variable support routines...
287  *      The basic scheme is to malloc in the space needed for the variable
288  *      name and the value of that variable.  For each variable that 
289  *      exists there is one s_shell structure that is in the linked list.
290  *      As shell variables are removed, their corresonding s_shell structure
291  *      is NOT removed, but the data pointed to within the structure is
292  *      freed.  This keeps the linked list implementation extremely simple
293  *      but maintains the versatility gained by using malloc for the 
294  *      variables instead of some limted set of static arrays.
295  */
296
297
298 /* shell_alloc():
299  *      First scan through the entire list to see if the requested
300  *      shell variable name already exists in the list; if it does,
301  *      then just use the same s_shell entry but change the value.
302  *      Also, if the new value fits in the same space as the older value,
303  *      then just use the same memory space (don't do the free/malloc).
304  *      If it doesn't, then scan through the list again.  If there
305  *      is one that has no variable assigned to it (name = 0), then
306  *      use it for the new allocation.  If all s_shell structures do 
307  *      have valid entries, then malloc a new s_shell structure and then
308  *      place the new shell variable data in that structure.
309  */
310
311 static int
312 shell_alloc(char *name,char *value)
313 {
314         int     namelen, valuelen;
315         struct s_shell *sp;
316
317         sp = shell_vars;
318         namelen = strlen(name);
319         valuelen = strlen(value);
320         while(1) {
321                 if (sp->name == (char *)0) {
322                         if (sp->next != (struct s_shell *)0) {
323                                 sp = sp->next;
324                                 continue;
325                         }
326                         else
327                                 break;
328                 }
329                 if (strcmp(sp->name,name) == 0) {
330                         if (sp->vsize < valuelen+1) {           /* If new value is smaller      */
331                                 env_free(sp->val);                              /* than the old value, then */
332                                 sp->val = env_alloc(valuelen+1);/* don't re-allocate any        */
333                                 if (!sp->val)                                   /* memory, just copy into       */
334                                         return(-1);                                     /* the space used by the        */
335                                 sp->vsize = valuelen+1;                 /* previous value.                      */
336                         }
337                         strcpy(sp->val,value);
338                         return(0);
339                 }
340                 if (sp->next == (struct s_shell *)0) 
341                         break;
342                 sp = sp->next;
343         }
344         sp = shell_vars;
345         while(1) {
346                 if (sp->name == (char *)0) {
347                         sp->name = env_alloc(namelen+1);
348                         if (!sp->name)
349                                 return(-1);
350                         strcpy(sp->name,name);
351                         sp->val = env_alloc(valuelen+1);
352                         if (!sp->val)
353                                 return(-1);
354                         sp->vsize = valuelen+1;
355                         strcpy(sp->val,value);
356                         return(0);
357                 }
358                 if (sp->next != (struct s_shell *)0)
359                         sp = sp->next;
360                 else {
361                         sp->next = (struct s_shell *)env_alloc(sizeof(struct s_shell));
362                         if (!sp->next)
363                                 return(-1);
364                         sp = sp->next;
365                         sp->name = env_alloc(namelen+1);
366                         if (!sp->name)
367                                 return(-1);
368                         strcpy(sp->name,name);
369                         sp->val = env_alloc(valuelen+1);
370                         if (!sp->val)
371                                 return(-1);
372                         sp->vsize = valuelen+1;
373                         strcpy(sp->val,value);
374                         sp->next = (struct s_shell *)0;
375                         return(0);
376                 }
377         }
378 }
379
380 /* shell_dealloc():
381  *      Remove the requested shell variable from the list.  Return 0 if
382  *      the variable was removed successfully, otherwise return -1.
383  */
384 static int
385 shell_dealloc(char *name)
386 {
387         struct  s_shell *sp;
388
389         sp = shell_vars;
390         while(1) {
391                 if (sp->name == (char *)0) {
392                         if (sp->next == (struct s_shell *)0)
393                                 return(-1);
394                         else {
395                                 sp = sp->next;
396                                 continue;
397                         }
398                 }
399                 if (strcmp(name,sp->name) == 0) {
400                         env_free(sp->name);
401                         env_free(sp->val);
402                         sp->name = (char *)0;
403                         sp->val = (char *)0;
404                         return(0);
405                 }
406                 
407                 if (sp->next == (struct s_shell *)0)
408                         return(-1);
409                 else
410                         sp = sp->next;
411         }
412 }
413
414 /* ConsoleBaudEnvSet():
415  * Called by to load/reload the CONSOLEBAUD shell variable based on
416  * the content of the global variable 'ConsoleBaudRate'.
417  */
418 void
419 ConsoleBaudEnvSet(void)
420 {
421         char    buf[16];
422
423         sprintf(buf,"%d",ConsoleBaudRate);
424         setenv("CONSOLEBAUD",buf);
425 }
426
427 /* ShellVarInit();
428  *      Setup the shell_vars pointer appropriately for additional
429  *      shell variable assignments that will be made through shell_alloc().
430  */
431 int
432 ShellVarInit()
433 {
434         char    buf[16];
435
436 #if !INCLUDE_MALLOC
437         memset((char *)&envSpace,0,sizeof(envSpace));
438 #endif
439
440         shell_vars = (struct s_shell *)env_alloc(sizeof(struct s_shell));
441         if (!shell_vars) {
442                 printf("No memory for environment initialization\n");
443                 return(-1);
444         }
445         shell_vars->next = (struct s_shell *)0;
446         shell_vars->name = (char *)0;
447         setenv("PROMPT",PROMPT);
448         sprintf(buf,"0x%lx",APPLICATION_RAMSTART);
449         setenv("APPRAMBASE",buf);
450         sprintf(buf,"0x%lx",BOOTROM_BASE);
451         setenv("BOOTROMBASE",buf);
452         setenv("PLATFORM",PLATFORM_NAME);
453         setenv("MONITORBUILT",monBuilt());
454         shell_sprintf("MONCOMPTR","0x%lx",(ulong)&moncomptr);
455 #if INCLUDE_HWTMR
456         shell_sprintf("TARGETTIMER","0x%x",target_timer);
457         shell_sprintf("TICKSPERMSEC","0x%x",TIMER_TICKS_PER_MSEC);
458 #endif
459
460         /* Support the ability to have additional target-specific 
461          * shell variables initialized at startup...
462          */
463 #ifdef TARGET_ENV_SETUP
464         TARGET_ENV_SETUP();
465 #endif
466
467         shell_sprintf("VERSION_MAJ","%d",MAJOR_VERSION);
468         shell_sprintf("VERSION_MIN","%d",MINOR_VERSION);
469         shell_sprintf("VERSION_TGT","%d",TARGET_VERSION);
470         return(0);
471 }
472
473 /* getenv:
474  *      Return the pointer to the value entry if the shell variable
475  *      name is currently set; otherwise, return a null pointer.
476  */
477 char *
478 getenv(char *name)
479 {
480         register struct s_shell *sp;
481
482         for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) {
483                 if (sp->name != (char *)0) {
484                         if (strcmp(sp->name,name) == 0)
485                                 return(sp->val);
486                 }
487         }
488         return((char *)0);
489 }
490
491 /* getenvp:
492  *      Build an environment string consisting of all shell variables and
493  *      their values concatenated into one string.  The format is
494  *
495  *        NAME=VALUE LF NAME=VALUE LF NAME=VALUE LF NULL
496  *
497  *      with the limit in size being driven only by the space
498  *      available on the heap.  Note that this uses malloc, and it
499  *      the responsibility of the caller to free the pointer when done.
500  */
501 char *
502 getenvp(void)
503 {
504         int size;
505         char *envp, *cp;
506         register struct s_shell *sp;
507
508         size = 0;
509
510         /* Get total size of the current environment vars */
511         for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) {
512                 if (sp->name != (char *)0) {
513                         size += (strlen(sp->name) + strlen(sp->val) + 2);
514                 }
515         }
516         if (size == 0)
517                 return((char *)0);
518
519         envp = env_alloc(size+1);       /* leave room for final NULL */
520         if (envp == 0)
521                 return((char *)0);
522
523         cp = envp;
524         for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) {
525                 if (sp->name != (char *)0)
526                         cp += sprintf(cp,"%s=%s\n",sp->name,sp->val);
527         }
528         *cp = 0;                /* Append NULL after final separator */
529         return(envp);
530 }
531
532 /* clearenv():
533  * Clear out the entire environment.
534  */
535 void
536 clearenv(void)
537 {
538         struct  s_shell *sp;
539
540         for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) {
541                 if (sp->name != (char *)0) {
542                         env_free(sp->name);
543                         env_free(sp->val);
544                         sp->name = (char *)0;
545                         sp->val = (char *)0;
546                 }
547         }
548 }
549
550 /* setenv:
551  *      Interface to shell_dealloc() and shell_alloc().
552  */
553 int
554 setenv(char *name,char *value)
555 {
556         if (!shell_vars)
557                 return(-1);
558         if ((value == (char *)0) || (*value == 0))
559                 return(shell_dealloc(name));
560         else
561                 return(shell_alloc(name,value));
562 }
563
564 /* shell_print():
565  *      Print out all of the current shell variables and their values.
566  */
567 int
568 shell_print(void)
569 {
570         int     maxlen, len;
571         char format[8];
572         register struct s_shell *sp;
573
574         /* Before printing the list, pass through the list to determine the
575          * largest variable name.  This is used to create a format string
576          * that is then passed to printf() when printing the list of
577          * name/value pairs.  It guarantees that regardless of the length
578          * of the name, the format of the printed out put will be consistent
579          * for all variables.
580          */
581         maxlen = 0;
582         sp = shell_vars;
583         while(1) {
584                 if (sp->name) {
585                         len = strlen(sp->name);
586                         if (len > maxlen)
587                                 maxlen = len;
588                 }
589                 if (sp->next != (struct s_shell *)0)
590                         sp = sp->next;
591                 else
592                         break;
593         }
594         sprintf(format,"%%%ds = ",maxlen+1);
595
596         /* Now that we know the size of the largest variable, we can 
597          * print the list cleanly...
598          */
599         sp = shell_vars;
600         while(1) {
601                 if (sp->name != (char *)0) {
602                         printf(format, sp->name);
603                         puts(sp->val);          /* sp->val may overflow printf, so use puts */
604                 }
605                 if (sp->next != (struct s_shell *)0)
606                         sp = sp->next;
607                 else
608                         break;
609         }
610         return(0);
611 }
612
613 /* shell_sprintf():
614  *      Simple way to turn a printf-like formatted string into a shell variable.
615  */
616 int
617 shell_sprintf(char *varname, char *fmt, ...)
618 {
619         int     tot;
620         char buf[CMDLINESIZE];
621         va_list argp;
622
623         va_start(argp,fmt);
624         tot = vsnprintf(buf,CMDLINESIZE-1,fmt,argp);
625         va_end(argp);
626         setenv(varname,buf);
627         return(tot);
628 }
629
630
631 #if INCLUDE_TFS
632 /* validEnvToExecVar():
633  * Return 1 if the variable should be included in the script
634  * generated by envToExec(); else return 0.
635  * Specifically... if the variable is generated internally
636  * then we don't want to include it in the script.
637  */
638 int
639 validEnvToExecVar(char *varname)
640 {
641         char **vp;
642         static char *invalid_varprefixes[] = {
643                 "ARG",                  "TFS_PREFIX_",  "TFS_START_",
644                 "TFS_END_",             "TFS_SPARE_",   "TFS_SPARESZ_",
645                 "TFS_SCNT_",    "TFS_DEVINFO_", "FLASH_BASE_",
646                 "FLASH_SCNT_",  "FLASH_END_",
647                 0
648         };
649         static char *invalid_varnames[] = {
650                 "APPRAMBASE",   "BOOTROMBASE",  "CMDSTAT",
651                 "CONSOLEBAUD",  "MALLOC",               "MONCOMPTR",
652                 "MONITORBUILT", "PLATFORM",             "PROMPT",
653                 "TFS_DEVTOT",   "FLASH_DEVTOT", "PROMPT",
654                 "VERSION_MAJ",  "VERSION_MIN",  "VERSION_TGT",
655                 "MONCMD_SRCIP", "MONCMD_SRCPORT",
656 #if INCLUDE_HWTMR
657                 "TARGETTIMER",  "TICKSPERMSEC",
658 #endif
659                 0
660         };
661
662         if (varname == 0)
663                 return(0);
664
665         if (strncmp(varname,"ARG",3) == 0)
666                 return(0);
667
668 #if INCLUDE_BOARDINFO
669         if (BoardInfoVar(varname))
670                 return(0);
671 #endif
672
673         for(vp=invalid_varnames;*vp;vp++) {
674                 if (!strcmp(varname,*vp))
675                         return(0);
676         }
677         for(vp=invalid_varprefixes;*vp;vp++) {
678                 if (!strncmp(varname,*vp,strlen(*vp)))
679                         return(0);
680         }
681         return(1);
682 }
683
684 /* envToExec():
685    Create a file of "set" commands that can be run to recreate the
686    current environment.
687    Changed Oct 2008 to eliminate use of getAppRamStart().
688 */
689 int
690 envToExec(char *filename)
691 {
692         int             err, vartot, size, rc;
693         char    *buf, *bp, *cp;
694         register struct s_shell *sp;
695
696         sp = shell_vars;
697         vartot = size = rc = 0;
698
699         /* First go through the list to see how much space we need
700          * to allocate...
701          */
702         while(1) {
703                 if (validEnvToExecVar(sp->name)) {
704                         size += strlen(sp->name) + 6;
705                         cp = sp->val;
706                         while(*cp) {
707                                 if (*cp == '$')
708                                         size++;
709                                 size++;
710                                 cp++;
711                         }
712                         size += 3;
713                         vartot++;
714                 }
715                 if (sp->next != (struct s_shell *)0)
716                         sp = sp->next;
717                 else
718                         break;
719         }
720         if (size == 0)
721                 return(0);
722
723         /* Now that we know the space needed (stored in 'size' variable),
724          * allocate it and build the new file in that space, then use tfsadd()
725          * to create the file...
726          */
727         vartot = 0;
728         sp = shell_vars;
729         buf = bp = (char *)env_alloc(size);
730         while(1) {
731                 /* Note: if this code changes, then the code above that is used to
732                  * allocate the buffer size may also need to change...
733                  */
734                 if (validEnvToExecVar(sp->name)) {
735                         bp += sprintf(bp,"set %s \"",sp->name);
736                         cp = sp->val;
737                         while(*cp) {
738                                 if (*cp == '$')
739                                         *bp++ = '\\';
740                                 *bp++ = *cp++;
741                         }
742                         *bp++ = '\"';
743                         *bp++ = '\n';
744                         *bp = 0;
745                         vartot++;
746                 }
747                 if (sp->next != (struct s_shell *)0)
748                         sp = sp->next;
749                 else
750                         break;
751         }
752         if (vartot > 0) {
753                 err = tfsadd(filename,"envsetup","e",(unsigned char *)buf,strlen(buf));
754                 if (err != TFS_OKAY) {
755                         printf("%s: %s\n",filename,(char *)tfsctrl(TFS_ERRMSG,err,0));
756                         rc = -1;
757                 }
758         }
759         env_free(buf);
760         return(rc);
761 }
762 #endif
763
764 #else
765
766 /* The 'set' command is part of the build even if INCLUDE_SHELLVARS
767  * is false.  This allows the user to still access teh "set -b ###"
768  * facility for changing the baudrate.
769  */
770 char *SetHelp[] = {
771         "Set baud",
772         "-[b:] (no args)",
773 #if INCLUDE_VERBOSEHELP
774         " -b        set console baudrate",
775 #endif
776         0,
777 };
778
779 int
780 Set(int argc,char *argv[])
781 {
782         int             opt;
783
784         while((opt=getopt(argc,argv,"b:")) != -1) {
785                 switch(opt) {
786                 case 'b':
787                         ChangeConsoleBaudrate(atoi(optarg));
788                         return(CMD_SUCCESS);
789                         break;
790                 default:
791                         return(CMD_PARAM_ERROR);
792                 }
793         }
794         printf("Shell vars not included in build.\n");
795         return(CMD_FAILURE);
796 }
797
798 int
799 setenv(char *name,char *value)
800 {
801         return(-1);
802 }
803
804 char *
805 getenv(char *name)
806 {
807         return(0);
808 }
809
810 int
811 shell_sprintf(char *varname, char *fmt, ...)
812 {
813         return(0);
814 }
815
816 void
817 ConsoleBaudEnvSet(void)
818 {
819 }
820
821 char *
822 getenvp(void)
823 {
824         return(0);
825 }
826
827 #endif
828
829 /* ChangeConsoleBaudrate():
830  * Called to attempt to adjust the console baudrate.
831  */
832 int
833 ChangeConsoleBaudrate(int baud)
834 {
835         if (ConsoleBaudSet(baud) < 0) {
836                 printf("Baud=%d failed\n",baud);
837                 return(-1);
838         }
839         ConsoleBaudRate = baud;
840         ConsoleBaudEnvSet();
841         return(0);
842 }
843