mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Stefano Manni <stefano.manni@gmail.com>, barebox@lists.infradead.org
Subject: Re: bootchooser: avoid write environment
Date: Wed, 31 Jul 2024 19:51:00 +0200	[thread overview]
Message-ID: <ec161afa-115a-4c2c-a9de-9279e3b8344e@pengutronix.de> (raw)
In-Reply-To: <7abdbc190f22b62372d0ae76a943d6e5a1467b05.camel@gmail.com>

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 |




  reply	other threads:[~2024-07-31 17:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31 14:35 Stefano Manni
2024-07-31 17:51 ` Ahmad Fatoum [this message]
2024-08-05 13:36   ` Stefano Manni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec161afa-115a-4c2c-a9de-9279e3b8344e@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=stefano.manni@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox