[U-Boot] a few questions about saving bootcount in the environment

Wolfgang Denk wd at denx.de
Tue Jul 26 14:48:15 CEST 2016


Dear Robert,

In message <alpine.LFD.2.20.1607260734020.10018 at localhost.localdomain> you wrote:
> 
>   ok, i am now *totally* confused, so let's start at the beginning.
> it's my understanding that selecting CONFIG_BOOTCOUNT_LIMIT means you

right.

> want to use the boot counter, it does *not* select what method you
> want to use to store the boot counter, correct? but here's the
> confusing part.

Which exact part is confusing?

>     #ifdef CONFIG_BOOTCOUNT_LIMIT
>           bootcount = bootcount_load();
>           bootcount++;
>           bootcount_store(bootcount);
>           setenv_ulong("bootcount", bootcount);      <----- ?????
>           bootlimit = getenv_ulong("bootlimit", 10, 0);
>     #endif /* CONFIG_BOOTCOUNT_LIMIT */

This is only the equivalent of a "setenv", so you have a variable in
the environment which you can use in scripts or compare against
"bootlimit".

There is NO automatic "saveenv" here...

> and that's what confuses the heck out of me. i thought that, depending
> on the technique i wanted to use to store the boot counter (RAM, I2C,

The key word here is "store", i. e. store in such a way that the value
survives a warm boot / reset.  The copy in RAM which is created above
does NOT survive.

> whatever), it would use *exclusively* that technique, and while i can
> see the use of the routines bootcount_load() and bootcount_store(),
> which are redefined based on the technique you select:

These methods access the persistent copy of the variable.  The
setenv_ulong() just creates a transient work copy.

> it appears that, no matter what, the environment *is* updated every
> single time because of this line in the bootdelay_process() routine:
> 
>   setenv_ulong("bootcount", bootcount);

Yes, it is.  But it is NOT saved to persistent storage.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In an organization, each person rises to the level of his own  incom-
petency                                         - The Peter Principle


More information about the U-Boot mailing list