mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* bootchooser: avoid write environment
@ 2024-07-31 14:35 Stefano Manni
  2024-07-31 17:51 ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Manni @ 2024-07-31 14:35 UTC (permalink / raw)
  To: barebox

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.

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? 

Thanks all.
Best,
Stefano




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bootchooser: avoid write environment
  2024-07-31 14:35 bootchooser: avoid write environment Stefano Manni
@ 2024-07-31 17:51 ` Ahmad Fatoum
  2024-08-05 13:36   ` Stefano Manni
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-31 17:51 UTC (permalink / raw)
  To: Stefano Manni, barebox

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 |




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bootchooser: avoid write environment
  2024-07-31 17:51 ` Ahmad Fatoum
@ 2024-08-05 13:36   ` Stefano Manni
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Manni @ 2024-08-05 13:36 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hi Ahmad,

On Wed, 2024-07-31 at 19:51 +0200, Ahmad Fatoum wrote:
> 
> 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 with a circular backend on spinor turned to be the best
solution.

Thanks for your hint,
Stefano




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-05 13:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-31 14:35 bootchooser: avoid write environment Stefano Manni
2024-07-31 17:51 ` Ahmad Fatoum
2024-08-05 13:36   ` Stefano Manni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox