[U-Boot] How to enforce saveenv at boot

Hi,
Our board stores the U-Boot environment in an MTD partition. I would like to ensure that there is always an U-Boot environment stored in MTD so that the userspace tool fw_setenv does not need to fall back on its built in default environment or a default environment stored in a file (see https://github.com/sbabic/libubootenv).
When U-Boot starts up it checks whether the specified MTD partition contains a valid environment and loads it. In case there is no valid environment it will use the compiled in default. Is there already a feature in U-Boot which would then also write that default to the MTD partition?
Alternatively a Hush script could help. Is there an easy way to detect that U-Boot is using the compiled in environment? In that case I could simply do a saveenv (?) which would then initialize the MTD environment partition.
Greetings, Mark
Building Technologies, Panel Software Fire (BT-FIR/ENG1) Bosch Sicherheitssysteme GmbH | Postfach 11 11 | 85626 Grasbrunn | GERMANY | www.boschsecurity.com
Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart HRB 23118 Aufsichtsratsvorsitzender: Christian Fischer; Geschäftsführung: Tanja Rückert, Andreas Bartz, Thomas Quante, Bernhard Schuster

Hi Mark,
On 05/04/19 13:13, Jonas Mark (BT-FIR/ENG1) wrote:
Hi,
Our board stores the U-Boot environment in an MTD partition. I would like to ensure that there is always an U-Boot environment stored in MTD so that the userspace tool fw_setenv does not need to fall back on its built in default environment or a default environment stored in a file (see https://github.com/sbabic/libubootenv).
When U-Boot starts up it checks whether the specified MTD partition contains a valid environment and loads it. In case there is no valid environment it will use the compiled in default. Is there already a feature in U-Boot which would then also write that default to the MTD partition?
As far as I know, there is not (yet ?) a way to expose to the shell if the default environment is used, something like exporting gd->env_valid.
Alternatively a Hush script could help. Is there an easy way to detect that U-Boot is using the compiled in environment? In that case I could simply do a saveenv (?) which would then initialize the MTD environment partition.
A trick (a hack ?) could be to have a variable in the default environment and you check and delete it if exists, maybe in your "preboot".
if env_exists use_default;then setenv use_default;saveenv;fi
I do not know if there is a better way to do this.
Best regards, Stefano
participants (2)
-
Jonas Mark (BT-FIR/ENG1)
-
Stefano Babic