History log of /u-boot/include/env_internal.h
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# b106961c 14-Dec-2023 Tom Rini <trini@konsulko.com>

global: Restrict use of '#include <linux/kconfig.h>'

In general terms, we -include include/linux/kconfig.h and so normal
U-Boot code does not need to also #include it. However, for code which
is shared with userspace we may need to add it so that either our full
config is available or so that macros such as CONFIG_IS_ENABLED() can be
evaluated. In this case make sure that we guard these includes with a
test for USE_HOSTCC so that it clear as to why we're doing this.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# dca7a895 20-Nov-2023 Tom Rini <trini@konsulko.com>

Merge tag 'v2024.01-rc3' into next

Prepare v2024.01-rc3


# 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>

# 8819892b 21-Sep-2023 Algapally Santosh Sagar <santoshsagar.algapally@amd.com>

configs: Add support in Kconfig and convert for armada boards

Move the DEFAULT_ENV_IS_RW to Kconfig for easier configuration.
Hence, add the CONFIG_DEFAULT_ENV_IS_RW config to the defconfig files
to allow enabling them for armada boards.

Signed-off-by: Algapally Santosh Sagar <santoshsagar.algapally@amd.com>
Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20230921112043.3144726-2-venkatesh.abbarapu@amd.com
Signed-off-by: Michal Simek <michal.simek@amd.com>

# cbacacd5 05-Feb-2023 Simon Glass <sjg@chromium.org>

Correct SPL use of CMD_ERASEENV

This converts 1 usage of this option to the non-SPL form, since there is
no SPL_CMD_ERASEENV defined in Kconfig

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

# 6bd23720 02-Dec-2022 Tom Rini <trini@konsulko.com>

env: Rework ENV_IS_EMBEDDED and related logic slightly

- Drop CONFIG_BUILD_ENVCRC as this is never set directly but instead
means ENV_IS_EMBEDDED, so reference that in code and rename the Makefile
usage to BUILD_ENVCRC.
- Remove extra-$(CONFIG_ENV_IS_EMBEDDED) line as it could never be true,
and likely why there is an extra- line for CONFIG_ENV_IS_IN_FLASH (the
only use case today of embedded environments).
- With these slight changes we can then see that using the calculated
symbol of ENV_IS_EMBEDDED is the right thing to use in any code which
needs to know this situation and can remove CONFIG_ENV_IS_EMBEDDED
entirely.

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

# de70e887 05-Apr-2022 Marek Vasut <marex@denx.de>

env: Implement lower priority arch_env_get_location()

Currently there is only one way to override desired environment location,
by implementing env_get_location(). This is increasingly being conflated
both on board level and architecture level, which leads to a problem on
boards where this function is already implemented on architecture level,
since those boards have no way to override this environment location on
board level anymore.

Implement arch_env_get_location() function which is architecture specific
and should only ever be implemented in architecture code. This function
has lower priority than env_get_location(), which should only ever be
implemented in board code, and which overrides the arch_env_get_location()
architecture environment selection.

This way, architecture can define its default environment chooser, while
board can now override it as needed at all times.

There is no functional change, since env_get_location() simply returns
arch_env_get_location(), and arch_env_get_location() implements the
current env_get_location() default content.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Behún <marek.behun@nic.cz>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <kabel@kernel.org>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 This contributor prefers not to receive mails <noreply@example.com>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8819892b 21-Sep-2023 Algapally Santosh Sagar <santoshsagar.algapally@amd.com>

configs: Add support in Kconfig and convert for armada boards

Move the DEFAULT_ENV_IS_RW to Kconfig for easier configuration.
Hence, add the CONFIG_DEFAULT_ENV_IS_RW config to the defconfig files
to allow enabling them for armada boards.

Signed-off-by: Algapally Santosh Sagar <santoshsagar.algapally@amd.com>
Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20230921112043.3144726-2-venkatesh.abbarapu@amd.com
Signed-off-by: Michal Simek <michal.simek@amd.com>

# cbacacd5 05-Feb-2023 Simon Glass <sjg@chromium.org>

Correct SPL use of CMD_ERASEENV

This converts 1 usage of this option to the non-SPL form, since there is
no SPL_CMD_ERASEENV defined in Kconfig

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

# 6bd23720 02-Dec-2022 Tom Rini <trini@konsulko.com>

env: Rework ENV_IS_EMBEDDED and related logic slightly

- Drop CONFIG_BUILD_ENVCRC as this is never set directly but instead
means ENV_IS_EMBEDDED, so reference that in code and rename the Makefile
usage to BUILD_ENVCRC.
- Remove extra-$(CONFIG_ENV_IS_EMBEDDED) line as it could never be true,
and likely why there is an extra- line for CONFIG_ENV_IS_IN_FLASH (the
only use case today of embedded environments).
- With these slight changes we can then see that using the calculated
symbol of ENV_IS_EMBEDDED is the right thing to use in any code which
needs to know this situation and can remove CONFIG_ENV_IS_EMBEDDED
entirely.

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

# de70e887 05-Apr-2022 Marek Vasut <marex@denx.de>

env: Implement lower priority arch_env_get_location()

Currently there is only one way to override desired environment location,
by implementing env_get_location(). This is increasingly being conflated
both on board level and architecture level, which leads to a problem on
boards where this function is already implemented on architecture level,
since those boards have no way to override this environment location on
board level anymore.

Implement arch_env_get_location() function which is architecture specific
and should only ever be implemented in architecture code. This function
has lower priority than env_get_location(), which should only ever be
implemented in board code, and which overrides the arch_env_get_location()
architecture environment selection.

This way, architecture can define its default environment chooser, while
board can now override it as needed at all times.

There is no functional change, since env_get_location() simply returns
arch_env_get_location(), and arch_env_get_location() implements the
current env_get_location() default content.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Behún <marek.behun@nic.cz>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <kabel@kernel.org>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 This contributor prefers not to receive mails <noreply@example.com>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cbacacd5 05-Feb-2023 Simon Glass <sjg@chromium.org>

Correct SPL use of CMD_ERASEENV

This converts 1 usage of this option to the non-SPL form, since there is
no SPL_CMD_ERASEENV defined in Kconfig

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

# 6bd23720 02-Dec-2022 Tom Rini <trini@konsulko.com>

env: Rework ENV_IS_EMBEDDED and related logic slightly

- Drop CONFIG_BUILD_ENVCRC as this is never set directly but instead
means ENV_IS_EMBEDDED, so reference that in code and rename the Makefile
usage to BUILD_ENVCRC.
- Remove extra-$(CONFIG_ENV_IS_EMBEDDED) line as it could never be true,
and likely why there is an extra- line for CONFIG_ENV_IS_IN_FLASH (the
only use case today of embedded environments).
- With these slight changes we can then see that using the calculated
symbol of ENV_IS_EMBEDDED is the right thing to use in any code which
needs to know this situation and can remove CONFIG_ENV_IS_EMBEDDED
entirely.

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

# de70e887 05-Apr-2022 Marek Vasut <marex@denx.de>

env: Implement lower priority arch_env_get_location()

Currently there is only one way to override desired environment location,
by implementing env_get_location(). This is increasingly being conflated
both on board level and architecture level, which leads to a problem on
boards where this function is already implemented on architecture level,
since those boards have no way to override this environment location on
board level anymore.

Implement arch_env_get_location() function which is architecture specific
and should only ever be implemented in architecture code. This function
has lower priority than env_get_location(), which should only ever be
implemented in board code, and which overrides the arch_env_get_location()
architecture environment selection.

This way, architecture can define its default environment chooser, while
board can now override it as needed at all times.

There is no functional change, since env_get_location() simply returns
arch_env_get_location(), and arch_env_get_location() implements the
current env_get_location() default content.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Behún <marek.behun@nic.cz>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <kabel@kernel.org>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 6bd23720 02-Dec-2022 Tom Rini <trini@konsulko.com>

env: Rework ENV_IS_EMBEDDED and related logic slightly

- Drop CONFIG_BUILD_ENVCRC as this is never set directly but instead
means ENV_IS_EMBEDDED, so reference that in code and rename the Makefile
usage to BUILD_ENVCRC.
- Remove extra-$(CONFIG_ENV_IS_EMBEDDED) line as it could never be true,
and likely why there is an extra- line for CONFIG_ENV_IS_IN_FLASH (the
only use case today of embedded environments).
- With these slight changes we can then see that using the calculated
symbol of ENV_IS_EMBEDDED is the right thing to use in any code which
needs to know this situation and can remove CONFIG_ENV_IS_EMBEDDED
entirely.

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

# de70e887 05-Apr-2022 Marek Vasut <marex@denx.de>

env: Implement lower priority arch_env_get_location()

Currently there is only one way to override desired environment location,
by implementing env_get_location(). This is increasingly being conflated
both on board level and architecture level, which leads to a problem on
boards where this function is already implemented on architecture level,
since those boards have no way to override this environment location on
board level anymore.

Implement arch_env_get_location() function which is architecture specific
and should only ever be implemented in architecture code. This function
has lower priority than env_get_location(), which should only ever be
implemented in board code, and which overrides the arch_env_get_location()
architecture environment selection.

This way, architecture can define its default environment chooser, while
board can now override it as needed at all times.

There is no functional change, since env_get_location() simply returns
arch_env_get_location(), and arch_env_get_location() implements the
current env_get_location() default content.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Behún <marek.behun@nic.cz>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <kabel@kernel.org>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# de70e887 05-Apr-2022 Marek Vasut <marex@denx.de>

env: Implement lower priority arch_env_get_location()

Currently there is only one way to override desired environment location,
by implementing env_get_location(). This is increasingly being conflated
both on board level and architecture level, which leads to a problem on
boards where this function is already implemented on architecture level,
since those boards have no way to override this environment location on
board level anymore.

Implement arch_env_get_location() function which is architecture specific
and should only ever be implemented in architecture code. This function
has lower priority than env_get_location(), which should only ever be
implemented in board code, and which overrides the arch_env_get_location()
architecture environment selection.

This way, architecture can define its default environment chooser, while
board can now override it as needed at all times.

There is no functional change, since env_get_location() simply returns
arch_env_get_location(), and arch_env_get_location() implements the
current env_get_location() default content.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Behún <marek.behun@nic.cz>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# eb68ead2 17-Feb-2022 He Yong <hyyoxhk@163.com>

env: fat: Allow overriding interface, device and partition

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.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>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 27480e0a 07-Nov-2021 Tom Rini <trini@konsulko.com>

Convert CONFIG_ENV_IS_IN_SPI_FLASH et al to Kconfig

This converts the following to Kconfig:
CONFIG_ENV_IS_IN_SPI_FLASH
CONFIG_ENV_IS_NOWHERE
CONFIG_ENV_OFFSET
CONFIG_ENV_OVERWRITE
CONFIG_ENV_SECT_SIZE
CONFIG_SYS_MMC_ENV_DEV
CONFIG_SYS_MMC_ENV_PART

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

# c5cbbe35 22-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# c5cbbe35 22-Oct-2021 Marek Behún <marek.behun@nic.cz>

env: Always use char for default_environment

Sometimes we use uchar and sometimes char for the default environment
array. By always using char, we can get rid of some explicit casts.

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

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 1af031ac 09-Feb-2021 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add ENV_ERASE_PTR macro

Add ENV_ERASE_PTR macro to handle erase opts and remove the associated
ifdef.

This patch is a extension of previous commit 82b2f4135719 ("env_internal.h:
add alternative ENV_SAVE_PTR macro").

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

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 93f4048b 22-Dec-2020 Pali Rohár <pali@kernel.org>

env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Andre Heider <a.heider@gmail.com>

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

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 466d9855 28-Jul-2020 Patrick Delaunay <patrick.delaunay@st.com>

env: the ops driver load becomes mandatory in struct env_driver

The ops driver load becomes mandatory in struct env_drive,
change the comment for this ops and remove unnecessary test.

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

# 879369ea 15-Jun-2020 Patrick Delaunay <patrick.delaunay@st.com>

env: add prototypes for weak function

This patch adds prototypes for several weak functions:
- env_ext4_get_intf
- env_ext4_get_dev_part
- env_get_location

It solves the following warnings when compiling with W=1
on stm32mp1 board:

board/st/stm32mp1/stm32mp1.c:849:19: warning: no previous prototype for 'env_get_location' [-Wmissing-prototypes]
enum env_location env_get_location(enum env_operation op, int prio)
^~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:876:13: warning: no previous prototype for 'env_ext4_get_intf' [-Wmissing-prototypes]
const char *env_ext4_get_intf(void)
^~~~~~~~~~~~~~~~~
board/st/stm32mp1/stm32mp1.c:889:13: warning: no previous prototype for 'env_ext4_get_dev_part' [-Wmissing-prototypes]
const char *env_ext4_get_dev_part(void)
^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f96b323 19-Jun-2020 Patrick Delaunay <patrick.delaunay@st.com>

cmd: env: check real location for env info command

Check the current ENV location, dynamically provided by the weak
function env_get_location to be sure that the environment can be
persistent.

The compilation flag ENV_IS_IN_DEVICE is not enough when the board
dynamically select the available storage location (according boot
device for example).

This patch solves issue for stm32mp1 platform, when the boot device
is USB.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 82b2f413 19-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

env_internal.h: add alternative ENV_SAVE_PTR macro

The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# a09fea1d 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Finish migration of common ENV options

- In ARMv8 NXP Layerscape platforms we also need to make use of
CONFIG_SYS_RELOC_GD_ENV_ADDR now, do so.
- On ENV_IS_IN_REMOTE, CONFIG_ENV_OFFSET is never used, drop the define
to 0.
- Add Kconfig entry for ENV_ADDR.
- Make ENV_ADDR / ENV_OFFSET depend on the env locations that use it.
- Add ENV_xxx_REDUND options that depend on their primary option and
SYS_REDUNDAND_ENVIRONMENT
- On a number of PowerPC platforms, use SPL_ENV_ADDR not CONFIG_ENV_ADDR
for the pre-main-U-Boot environment location.
- On ENV_IS_IN_SPI_FLASH, check not for CONFIG_ENV_ADDR being set but
rather it being non-zero, as it will now be zero by default.
- Rework the env_offset absolute in env/embedded.o to not use
CONFIG_ENV_OFFSET as it was the only use of ENV_OFFSET within
ENV_IS_IN_FLASH.
- Migrate all platforms.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: uboot-stm32@st-md-mailman.stormreply.com
Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

# a8992e78 18-Nov-2019 Tom Rini <trini@konsulko.com>

env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND check

We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one
board where we can simply multiple CONFIG_ENV_SIZE by two for the same
result. The other place where we could but were not previously using
this is for where env_internal.h checks for if we should set
ENV_IS_EMBEDDED. This seems like the most likely use, historically, of
the variable, but it was not used. Add logic to check for this now.

Cc: Wolfgang Denk <wd@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cb6617a7 10-Nov-2019 Tom Rini <trini@konsulko.com>

defconfigs: Migrate CONFIG_SYS_REDUNDAND_ENVIRONMENT

Move this symbol to Kconfig. As part of this we can drop a UBI-specific
symbol that was a stop-gap for not having this particular symbol in
Kconfig.

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

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 61162341 14-Oct-2019 Philippe Reynes <philippe.reynes@softathome.com>

ubi: env: fix redundand management

We check (with a #if defined()) the config ENV_UBI_VOLUME_REDUND
to know if there is a redundant env. But this config is a string
and is always defined with env is in ubi, so we always consider
that a redundand env is used.

To fix this issue, I've added a hidden flag ENV_UBI_IS_VOLUME_REDUND
that is true when ENV_UBI_VOLUME_REDUND is not "". Then, I check
this flag in the code, instead of the string ENV_UBI_VOLUME_REDUND.

hs: fixed typo s/condider/consider

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Heiko Schocher <hs@denx.de>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

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

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

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>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>