[PATCH] RFC: nvedit: support doing one (extra) expansion of the value in "env set"

Rasmus Villemoes rasmus.villemoes at prevas.dk
Thu Feb 2 16:15:30 CET 2023


On 14/02/2020 12.54, Rasmus Villemoes wrote:
> 
> Assume BOOT_ORDER contains some permutation of "A B C", and for each
> letter x, there's a BOOT_x_LEFT counter telling how many boot attempts
> that slot has left. Now I want to find the first x in $BOOT_ORDER for
> which $BOOT_x_LEFT is positive. If all BOOT_x_LEFT are 0, say I want the
> sentinel value 'none'.
> 
> So in bash, that might be written
> 
> slot=none
> for x in $BOOT_ORDER ; do
>   eval "left=\${BOOT_${x}_LEFT}"
>   if [ $left -gt 0 ] ; then
>     slot=$x
>     break
>   fi
> done
> 
> Now we can work around the lack of break in the [U-Boot] shell by writing
> the loop so that the main body is skipped if we've found a valid slot:
> 
> slot=none
> for x in $BOOT_ORDER ; do
>   if [ $slot != 'none' ] ; then
>     true
>   else
>     eval "left=\${BOOT_${x}_LEFT}"
>     if [ $left -gt 0 ] ; then
>       slot=$x
>     fi
>   fi
> done
> 
> But we still can't translate this to [U-Boot] shell, because there's no
> eval. Now, I can do this with a hypothetical "env get" command which I
> just implemented to test that it works, and then the above becomes
> 
> env set slot none;
> for x in $BOOT_ORDER ; do
>   if test $slot != 'none' ; then
>     true ;
>   else
>     env get left BOOT_${x}_LEFT ; # magic
>     if test $left -gt 0 ; then
>       env set slot $x ;
>     fi;
>   fi;
> done;

For the benefit of people stumbling on this thread in the future, that
#magic line is actually possible as of v2022.07 and is called "env
indirect", guarded by CONFIG_CMD_NVEDIT_INDIRECT .

Rasmus



More information about the U-Boot mailing list