[U-Boot] [RFD] store env size in env area (+ cookie + len)

Frans Meulenbroeks fransmeulenbroeks at gmail.com
Thu Aug 12 08:43:58 CEST 2010


I've seen a few times that people get a u-boot with their board and
want to use fw_setenv under linux to tweak with environment variables.
This requires them to come up with an fw-env.config (if not provided).
One of the things that I've seen, that some people have trouble with
it is obtaining the proper size of the environment area to be stuffed
in that file.

This is something that could be resolved quite easily by adding the
size of the environment area to the header preceding the environment
(which now contains a checksum and, in case of redundant areas, a flag
byte)

Pro: no more need to give sizes in fw-env.config
Con: uses a 2-4 more bytes (personally I'd say size is 4 bytes just to be safe)
Con: not compatible with current env layout so (without precautions) a
new u-boot cannot  use the old env and vice versa.

If compatibility is deemed important, we could extend the header also
with a magic cookie and a version number. If absent it is an old style
env, if present it is a new style env. Version number then can also be
used should there be future changes in the env layout.
(if compatibility is not deemed important of course this is not needed).

Btw thinking about cookies: if the env were to have a cookie in either
the header or e.g. as first env var, fw_setenv would not even need
fw-env.config at all. It could just seek in /dev/mtd (I'm assuming env
in flash here) for the cookie.
This seeking should not take too much time if we can assume (or have a
config var) a certain alignment (e.g. on flash page size). After
finding the cookie of course still a crc check would be done to
validate the area.

If desired I can do some implementation work for this and submit a
patch, but before investing time in it I would like to find out if
there is actual interest in this and if this is considered useful.

Summarizing the questions:
- is it desirable to have the env length added to the env header
- is it desirable to have a cookie added to the env header
- is it desirable to have a version number added to the env header

Best regards, Frans.

PS: if we are going to touch the env header, I would suggest to always
have the redundant flag in the header even if there is only  one
environment. It will probably make the code to load the env a little
bit simpler).


More information about the U-Boot mailing list