Reputation: 19182
I want to evaluate a u-boot environment variable as a function of other environment variables. My thought was to make a template, and then get that evaluated, but the variable is never substituted:
setenv a "1"
setenv b "2"
setenv c_tpl "'\${a}' '\${b}'"
setenv eval_c "setenv c '\${c_tpl}'"
printenv
run eval_c
printenv
printenv
output:
a=1
b=2
c=${a} ${b}
c_tpl=${a} ${b}
eval_c=setenv c ${c_tpl}
Upvotes: 0
Views: 3716
Reputation: 12502
On my Creator CI20, I had to setup something equivalent.
The original printenv would read as:
baudrate=115200
board_date=20140704
board_mfr=NP
bootargs=console=ttyS4,115200 console=tty0 mem=256M@0x0 mem=768M@0x30000000 rootwait quiet rw ubi.mtd=3 ubi.mtd=4 ubi.fm_autoconvert=1 root=ubi1:root rootfstype=ubifs
bootcmd=run ethargs; mtdparts default; ubi part boot; ubifsmount ubi:boot; ubifsload 0x88000000 uImage; bootm 0x88000000
bootdelay=1
ethact=dm9000
ethaddr=d0:31:10:ff:7d:20
ethargs=env set bootargs ${bootargs} dm9000.mac_addr=${ethaddr}
loads_echo=1
serial#=1255
stderr=eserial0,eserial4
stdin=eserial0,eserial4
stdout=eserial0,eserial4
Environment size: 582/32764 bytes
So during u-boot, you simply have to type:
setenv ethargs env set bootargs \${bootargs} dm9000.mac_addr=\${ethaddr}
Upvotes: 1
Reputation: 2173
Part of the problem you will run into is that the U-Boot shell is NOT as complete as say bash or even POSIX sh. So what you really need to do is re-think your functions to not rely on this behavior or to apply this patch https://patchwork.ozlabs.org/patch/552864/ which also has a more lengthy discussion on why we do things the way we do and an example of how you have to re-think what you wish to do so that it does work within the U-Boot (well, our HUSH version) limitations today.
Upvotes: 0
Reputation: 916
The syntax looks a bit different from what I'd use. Eg. something like this ought to work:
set a 1
set b 2
set c_tpl $(a) $(b)
set eval_c set c $(c_tpl)
run eval_c
Maybe with some well placed """
I'm not fully sure what you're trying to do though. The above "run eval_c" ought to create a "c" with the value "1 2".
Upvotes: 0