History log of /u-boot/include/env.h
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 23c1ab92 17-Jan-2024 Quentin Schulz <quentin.schulz@theobroma-systems.com>

env: allow to copy value from default environment into a buffer

env_get_default suffers from a particular issue int that it can only
return a value truncated to gd->env_buf (32) characters. This may be
enough for most variables but it isn't for others, so let's allow users
to provide a preallocated buffer to copy the value into instead,
allowing for more control, though it'll still be truncated if the value
size is bigger than the preallocated buffer.

Cc: Quentin Schulz <foss+uboot@0leil.net>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>

# d9721925 26-Oct-2023 Tom Rini <trini@konsulko.com>

env: Move env_set() out of cmd/nvedit.c and in to env/common.c

Inside of env/common.c we already have our helper env_set_xxx functions,
and even have a comment that explains why env_set() itself wasn't moved.
We now handle that move. This requires that we rename the previous
_do_env_set() to env_do_env_set() and note it as an internal env
function. Add comments about this function to explain why we do this
when we add the prototype. Add a new function, env_inc_id() to allow for
the counter to be updated by both commands and callers, and document
this as well by the prototype.

Signed-off-by: Tom Rini <trini@konsulko.com>

# decbc818 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

env: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# a28cc807 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

cmd: nvedit: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# fbc595b4 18-Dec-2022 Marek Vasut <marex@denx.de>

doc: Fix eth_env_[gs]et_enetaddr() return value

Per env/common.c, eth_env_get_enetaddr() returns the same return
values as is_valid_ethaddr(), i.e. true if valid, false otherwise.
Per env/common.c, eth_env_set_enetaddr() may return -EEXIST is the
ethaddr is already set. Fix both.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# d9721925 26-Oct-2023 Tom Rini <trini@konsulko.com>

env: Move env_set() out of cmd/nvedit.c and in to env/common.c

Inside of env/common.c we already have our helper env_set_xxx functions,
and even have a comment that explains why env_set() itself wasn't moved.
We now handle that move. This requires that we rename the previous
_do_env_set() to env_do_env_set() and note it as an internal env
function. Add comments about this function to explain why we do this
when we add the prototype. Add a new function, env_inc_id() to allow for
the counter to be updated by both commands and callers, and document
this as well by the prototype.

Signed-off-by: Tom Rini <trini@konsulko.com>

# decbc818 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

env: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# a28cc807 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

cmd: nvedit: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# fbc595b4 18-Dec-2022 Marek Vasut <marex@denx.de>

doc: Fix eth_env_[gs]et_enetaddr() return value

Per env/common.c, eth_env_get_enetaddr() returns the same return
values as is_valid_ethaddr(), i.e. true if valid, false otherwise.
Per env/common.c, eth_env_set_enetaddr() may return -EEXIST is the
ethaddr is already set. Fix both.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# decbc818 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

env: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# a28cc807 06-Sep-2023 Marek Vasut <marek.vasut+renesas@mailbox.org>

cmd: nvedit: Remove unused NEEDS_MANUAL_RELOC code bits

The last user of the NEEDS_MANUAL_RELOC has been removed in commit
26af162ac8f8 ("arch: m68k: Implement relocation")
Remove now unused NEEDS_MANUAL_RELOC code.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# fbc595b4 18-Dec-2022 Marek Vasut <marex@denx.de>

doc: Fix eth_env_[gs]et_enetaddr() return value

Per env/common.c, eth_env_get_enetaddr() returns the same return
values as is_valid_ethaddr(), i.e. true if valid, false otherwise.
Per env/common.c, eth_env_set_enetaddr() may return -EEXIST is the
ethaddr is already set. Fix both.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# fbc595b4 18-Dec-2022 Marek Vasut <marex@denx.de>

doc: Fix eth_env_[gs]et_enetaddr() return value

Per env/common.c, eth_env_get_enetaddr() returns the same return
values as is_valid_ethaddr(), i.e. true if valid, false otherwise.
Per env/common.c, eth_env_set_enetaddr() may return -EEXIST is the
ethaddr is already set. Fix both.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <kabel@kernel.org>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 78398652 21-Oct-2021 Simon Glass <sjg@chromium.org>

bootm: Tidy up use of autostart env var

This has different semantics in different places. Go with the bootm method
and put it in a common function so that the behaviour is consistent in
U-Boot. Update the docs.

To be clear, this changes the way that 'bootelf' and standalone boot
work. Before, if autostart was set to "fred" or "YES", for example, they
would consider that a "yes". This may change behaviour for some boards,
but the only in-tree boards which mention autostart use "no" to disable
it, which will still work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>

# 3112ce0c 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 3112ce0c 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Make return value of env_get_f() behave like sprintf() on success

Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.

Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().

All users of this function in U-Boot are compatible with this change.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 52f9ed34 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Inline env_get_char() into its only user

This function is a relic from the past when environment was read from
underlying device one character at a time.

It is used only in the case when getting an environemnt variable prior
relocation, and the function is simple enough to be inlined there.

Since env_get_char() is being changed to simple access to an array, we
can drop the failing cases and simplify the code (this could have been
done before, since env_get_char() did not fail even before).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7b611ee9 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Change env_match() to static and remove from header

This function was used by other parts of U-Boot in the past when
environment was read from underlying device one character at a time.

This is not the case anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 6dc1e2f1 17-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Fix documentation for env_get_f()

This function actually returns:
- the number of bytes written into @buf excluding the terminating
NULL-byte, if there was enough space in @buf
- the number of bytes written into @buf including the terminating
NULL-byte, if there wasn't enough space in @buf
- -1 if the variable is not found

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 95fd9772 21-Apr-2021 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env: allow environment to be amended from control dtb

It can be useful to use the same U-Boot binary for multiple purposes,
say the normal one, one for developers that allow breaking into the
U-Boot shell, and one for use during bootstrapping which runs a
special-purpose bootcmd. Or one can have several board variants that
can share almost all boot logic, but just needs a few tweaks in the
variables used by the boot script.

To that end, allow the control dtb to contain a /config/enviroment
node (or whatever one puts in fdt_env_path variable), whose
property/value pairs are used to update the run-time environment after
it has been loaded from its persistent location.

The indirection via fdt_env_path is for maximum flexibility - for
example, should the user wish (or board logic dictate) that the values
in the DTB should no longer be applied, one simply needs to delete the
fdt_env_path variable; that can even be done automatically by
including a

fdt_env_path = "";

property in the DTB node.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# b9c3052f 17-Dec-2020 Brandon Maier <brandon.maier@rockwellcollins.com>

env: increment redund flag on read fail

If one of the reads fails when importing redundant environments (a
single read failure), the env_flags wouldn't get initialized in
env_import_redund(). If a user then calls saveenv, the new environment
will have the wrong flags value. So on the next load the new environment
will be ignored.

While debugging this, I also noticed that env/sf.c was not correctly
handling a single read failure, as it would not check the crc before
assigning it to gd->env_addr.

Having a special error path for when there is a single read failure
seems unnecessary and may lead to future bugs. Instead collapse the
'single read failure' error to be the same as a 'single crc failure'.
That way env_check_redund() either passes or fails, and if it passes we
are guaranteed to have checked the CRC.

Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Wolfgang Denk <wd@denx.de>
CC: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@foss.st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 1229533a 10-Oct-2020 Heiko Schocher <hs@denx.de>

env: split env_import_redund() into 2 functions

split from env_import_redund() the part which checks
which Environment is valid into a separate function
called env_check_redund() and call it from env_import_redund().

So env_check_redund() can be used from places which also
need to do this checks.

Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 890feeca 07-Jul-2020 Marek Vasut <marex@denx.de>

env: Discern environment coming from external storage

Add another custom environment flag which discerns environment coming
from external storage from environment set by U-Boot itself.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>

# a97d22eb 28-Jul-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: add env select command

Add the new command 'env select' to force the persistent storage
of environment, saved in gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 0115dd3a 28-Jul-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: add env load command

Add the new command env load to load the environment from
the current location gd->env_load_prio.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 1ac2cb97 25-Nov-2019 Patrice Chotard <patrice.chotard@st.com>

cmd: Migrate from_env() from pxe.c to nvedit.c

Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# 664689f1 26-Aug-2019 Pierre-Jean Texier <pjtexier@koncepto.io>

env: add missing <compiler.h> header file

Since commit af95f20 ("env: Create a new file for environment functions"),
a new header file exists.

So, this commit add a missing header file.

Fixes:

include/env.h:158:1: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);
^~~~~
long
include/env.h:158:49: error: unknown type name ‘ulong’; did you mean ‘long’?
ulong env_get_ulong(const char *name, int base, ulong default_val);

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Joris Offouga <offougajoris@gmail.com>
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d3716dd6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename the redundancy flags

Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 02cf9334 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move callback definitions to env.h

These definitions are effectively part of the 'public' API of the
environment implementation since they do not require access to any
internal variables. Move them to the env.h header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# db197010 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_valid to env.h

This enum is somewhat widely used to determine if the environment is valid
or not. Move it to the common environment header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c62f62b0 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_reloc() to env.h

Move env_reloc() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# b5f449e8 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_char() to env.h

Move env_get_char() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0ac7d722 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get/set_default_env() to env.h

Move these functions to the new header file and rename set_default_env()
to env_set_default() so that it has a consistent env_ prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4e9ce8a6 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env import/export functions to env.h

Move these functions to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 4be490ae 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_load/save functions to env.h

Move these function to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b9d8a05 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move set_default_vars to env.h

Move this function to the new header file and rename it so it has an env_
prefix.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 03ed9188 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_fix_drivers() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b79cf1af 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move eth_env_get/set_enetaddr() to env.h

Move these two functions over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 7b51b576 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get() to env.h

Move env_get() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# cdbff9fc 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_hex() to env.h

Move env_get_hex() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6bf6dbee 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_yesno() to env.h

Move env_get_yesno() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9eef56db 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_ulong() to env.h

Move env_get_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 168068fb 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_ulong() to env.h

Move env_set_ulong() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b9ca02c2 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move envmatch() to env.h

Move envmatch() over to the new header file. Also rename it to env_match()
to better line up with other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3f989e7b 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_relocate() to env.h

Move env_relocate() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 4bfd1f5d 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_init() to env.h

Move env_init() over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a7d5571 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_get_f() to env.h

Move this function over to the new header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f1f0ae6a 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move get_env_id() to env.h

Move this function over to the new header file. Also rename it to have an
env_ prefix like the other functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# af95f206 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Create a new file for environment functions

At present we have environment.h but this file includes all the
environment-related header files as well as internals such as
default_environment.

It seems desirable to have a new header to hold the commonly used
environment functions, so that most files can avoid including all of this
unnecessary stuff.

Create a new env.h header and move one function over to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>