bootchooser: avoid write environment
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Jul 31 10:51:00 PDT 2024
Hello Stefano,
On 31.07.24 16:35, Stefano Manni wrote:
> Hi,
>
> I'm using bootchooser to switch from a partition to another in case of
> an update done in Linux userspace using the command bareboxenv.
You will want to use the barebox-state backend, not the regular environment.
barebox-state:
- Is laid out redundantly in a power-fail safe manner
- Supports a circular storage type where the same page is written
incrementally before an erase is required
- has a defined set of variables and doesn't allow arbitrarily
code execution in barebox
See arch/arm/dts/vexpress-v2p-ca9.dts for an example.
You need to set some parameters in the nv once, see slide #26 here:
https://elinux.org/images/9/9d/Barebox-bells-n-whistles.pdf
> But I see that at every boot the barebox decrements the number of
> remaining attempts in the environment.
> I'd like to avoid continuing to write the env in order to preserve the
> spinor flash memory.
>
> Is there any already-ready mechanism to do it?
With the circular state backend, you should see considerably fewer number
of erases. The boot state is still written on every boot, because that's an easy
way to know if a boot failed: always decrement and then increment when
boot succeeded.
If you don't want to decrement on the off-chance that a boot may fail, you
need to be able to detect a successful boot by other means. There are
two built-in ways to do this:
- If a successful boot differs from a failed boot in the value of $global.system.reset,
you can set nv.bootchooser.reset_attempts="reset". This means that a regular reset
after which $global.system.reset="RST" will undo the decrement
- If you have another way to detect a successful boot, you can call either
bootchooser_last_boot_successful() from C-code or bootchooser -s from shell
If you have no way to check whether a boot was successful without decrementing, but
you still want to conserve erase cycles, you may consider placing the barebox-state
in EEPROM, if you have one available.
Cheers,
Ahmad
>
> Thanks all.
> Best,
> Stefano
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list