Skip to contentSkip to conversation

How to enforce saveenv at boot

U-Boot Jonas Mark (BT-FIR/ENG1) 2 participants 2 messages Apr 5, 2019

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Hi Mark,

Quoted 8 lines · 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).

Quoted 5 lines

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.

Quoted 3 lines

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

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================