Search code examples
shellu-boot

U-boot scripting : How can I check if a variable exists in u-boot?


In a u-boot script, I'm trying to write a simple script that checks if a variable exists such as :

if test -z $var; then
    setenv var 1;
fi
saveenv

So that on next boots, the variable var does not get set again.

It seems that u-boot script are responding to a Hush shell syntax but I can't find a way to do this as if you would do this in a regular shell.

Anyone has an idea on how to do this ? Or another idea to replicate this behavior ?

Thanks


Solution

  • You can use option -n of test command:

    if test -n "$var"; then
        setenv var 1;
    fi
    saveenv
    

    See also this answer from Wolfgang Denk, original creator of U-Boot:

    https://lists.denx.de/pipermail/u-boot/2005-August/011446.html