[U-Boot] U-boot env variables parsing

Detlev Zundel dzu at denx.de
Thu Apr 1 14:15:03 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.

What we usually do is something like this (example taken from an
arbitrary board):

nfsargs=setenv bootargs root=/dev/nfs rw nfsroot=${serverip}:${rootpath}
addip=setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off panic=1
addtty=setenv bootargs ${bootargs} console=tty0 console=${consdev},${baudrate}
addfb=setenv bootargs ${bootargs} fbcon=map:5 video=fslfb:800x480-32 at 60
flash_nfs=run nfsargs addip addtty addfb;bootm ${kernel_addr} - ${fdt_addr}


When "run flash_nfs" is executed, little "scripts" are called and they
assemble a full command line from different variables.  So in this
example, one could simply change ${kernel_addr} and "run flash_nfs"
would boot the new kernel.

If you don't like such constructs, you can also get more funky and start
using "if ... then .. else .." construct in the hush shell parser.

> What would be the right way to achieve this, as I want ROOT to be
> ${ROOT1} sometimes and ${ROOT2} some times?

There is more than one way to do it ;)

Cheers
  Detlev

-- 
Another helpful hint for successful MIME processing:

application/msword; rm -f %s; description="MS Word Text";
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de


More information about the U-Boot mailing list