[U-Boot] U-boot env variables parsing

Joakim Tjernlund joakim.tjernlund at transmode.se
Thu Apr 1 14:31:57 CEST 2010


>
> Hi Nitin,
>
> > Hi!
> >
> > I am doing env settings some thing like this,
> >
> > ROOT1=/dev/mmcblk0p1
> > ROOT2=/dev/mmcblk0p2
> > ROOT=${ROOT1}
> > bootargs1=console=ttyS0,115200n8 mem=256M noinitrd rw rootdelay=1 ${ROOT}
> >
> > when I say 'setenv bootargs ${bootargs1}', ${ROOT} gets resolved to 'ROOT1',
> it does not get completely resolved to '/dev/mmcblk0p1'.
> >
> > Is there something fundamentally wrong in setting the env variables
> > this way?
>
> There is nothing fundamentally wrong - it will simply not work ;)  No,
> seriously, you want U-Boot to do two evaluation passes over bootargs,
> which we cannot do.  In a regular shell this would be done by a separate
> "eval" or backtick round, but we lack this.

I recall impl. something like this for the old shell. It enabled me
to do:

 linuxip=ip=$(ipaddr)::$(gatewayip):$(netmask):$(hostname):$(linuxif):off
 tboot=setenv bootargs $(linuxroot) $(linuxip) $(extra);tftp 100000; bootm 100000

it was fairly simple to do but I don't think WD applied it since the old shell was obsolete

I guess it would not be hard to do the same for hush. If I fund the correct commit
it looked like this for the old shell:

Index: main.c
===================================================================
--- main.c	(revision 15)
+++ main.c	(revision 16)
@@ -463,9 +463,9 @@

 /****************************************************************************/

-static void process_macros (const char *input, char *output)
+static int process_macros (const char *input, char *output)
 {
-	char c, prev;
+	char c, prev, macro_processed =0;
 	const char *varname_start;
 	int inputcnt  = strlen (input);
 	int outputcnt = CFG_CBSIZE;
@@ -540,6 +540,7 @@
 				}
 			/* Look for another '$' */
 			state = 0;
+			macro_processed = 1;
 		}
 		break;
 	    }
@@ -549,7 +550,7 @@

 	if (outputcnt)
 		*output = 0;
-
+	return macro_processed;
 #ifdef DEBUG_PARSER
 	printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
 		strlen(output_start), output_start);
@@ -580,6 +581,7 @@
 	char *token;			/* start of token in cmdbuf	*/
 	char *sep;			/* end of token (separator) in cmdbuf */
 	char finaltoken[CFG_CBSIZE];
+	char tmptoken[CFG_CBSIZE];
 	char *str = cmdbuf;
 	char *argv[CFG_MAXARGS + 1];	/* NULL terminated	*/
 	int argc;
@@ -631,7 +633,11 @@
 #endif

 		/* find macros in this token and replace them */
-		process_macros (token, finaltoken);
+		if(process_macros (token, finaltoken)){
+		  strcpy(tmptoken,finaltoken);
+		  while(process_macros (tmptoken, finaltoken))
+			strcpy(tmptoken,finaltoken);
+		}

 		/* Extract arguments */
 		argc = parse_line (finaltoken, argv);


    Jocke



More information about the U-Boot mailing list