All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
@ 2019-09-05  8:21 AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 01/19] env: extend interfaces allowing for env contexts AKASHI Takahiro
                   ` (20 more replies)
  0 siblings, 21 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

# In version 5 of this patch set, the implementation is changed again.
#
# I believe that this is NOT intrusive, and that my approach here is NOT
# selfish at all. If Wolfgang doesn't accept this approach, however,
# I would like to go for "Plan B" for UEFI variables implementation, in
# which EFI will have its own drivers for storage instead of env/*.

This patch set is an attempt to implement non-volatile attribute for
UEFI variables. Under the current implementation,
* SetVariable API doesn't recognize non-volatile attribute
* While some variables are defined non-volatile in UEFI specification,
  they are NOT marked as non-volatile in the code.
* env_save() (or "env save" command) allows us to save all the variables
  into persistent storage, but it may cause volatile UEFI variables,
  along with irrelevant U-Boot variables, to be saved unconditionally.

Those observation rationalizes that the implementation of UEFI variables
should be revamped utilizing dedicated storage for them.


Basic ideas:
* Sub-system users of U-Boot environment variables may have their own
  "env contexts". More than one contexts allowed.

  See Patch#2 and Patch#18.

* Each context is isolated from other contexts with different name spaces.
* Each context is associated with one backing storage driver and media
  location.
* Different contexts may use different drivers and locations.

* To access (get or set) a variable, associated context must be presented.
  So, almost of all existing env interfaces are changed to accept one
  extra argument, ctx.
  (I believe that this is Wolfgang's *requirement*.)

  From viewpoint of APIs, env context is a pointer to opaque structure.

* Non-volatile feature is not implemented in a general form and must be
  implemented by users in their sub-systems.

  In version 4, U-Boot environment's attributes are extended to support
  non-volatile (or auto-save capability), but Wolfgang rejected
  my approach.
  As modifying attributes for this purpose would cause bunch of
  incompatibility issues (as far as I said in my cover letter and
  the discussions in ML), I would prefer a much simple approach.

  See patch#19 about how it is easily implemented for UEFI variables.

* Each backing storage driver must be converted to be aligned with
  new env interfaces to handle multiple contexts in parallel and
  provide context-specific Kconfig configurations for driver parameters.

  In this version, only FAT file system and flash devices are supported,
  but it is quite straightforward to modify other drivers.

  See Patch#4 and Patch#5 about how drivers can shift to new interfaces.

* Finally, all existing U-Boot variables hold the same semantics
  as before.


Known issues/restriction/TODO:
* The current form of patchset is not 'bisect'able.
  Not to break 'bisect,' all the patches in this patch set must be
  put into a single commit when merging.
  (This can be mitigated by modifying/splitting Patch#18/#19 though.)

* Unfortunately, this code fails to read U-Boot environment from flash
  at boot time due to incomprehensible memory corruption.
  See murky workaround, which is marked as FIXME, in env/flash.c.

  Despite this bug, I was still be able to run/test my patch by hacking
  the code with gdb.
  (modifying data to correct value on the fly :)
  I hope that it won't affect code review in most places for now.

* Some minor issues for better coding.
  They are also marked as FIXME in the source code.

* Only FAT file system and flash are supported.

* The whole area of storage will be saved at *every* update of
  one UEFI variable. It should be optimized if possible.

* An error during "save" operation may cause inconsistency between
  cache (hash table) and the storage.
    -> This is not UEFI specific though.

* Add tests if necessary.

* I cannot test all the platforms affected by this patchset.


Note:
If we need "secure storage" for UEFI variables, efi_get_variable/
efi_get_next_variable_name/efi_set_variable() should be completely
replaced with stub functions to communicate with secure world.
This patchset has nothing to do with such an implementation.


Usage:
To enable this feature for example with FAT file system, the following
configs must be enabled:
  CONFIG_ENV_IS_IN_FAT
  CONFIG_ENV_FAT_INTERFACE
  CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
  CONFIG_ENV_EFI_FAT_FILE

You may define a non-volatile variable from command interface:
=> setenv -e -nv FOO baa
=> printenv -e FOO
FOO: NV|BS|RT, DataSize = 0x3
    00000000: 62 61 61                                         baa


Patch#1 and #2 are to add multiples 'context' support to env interfaces
  and to provide new env interfaces.
Patch#3 to #5 are to show how the existing drivers for U-Boot environment
  should be modified to be aligned with new env interfaces.
  (Only FAT file system and flash in this version of patch set.)
Patch#6 to #17 are to shift all the existing users of old env interfaces
  to new ones. (But not tested for all the platforms.)
Patch#18 and #19 are to modify UEFI variable implementation to utilize
  new env interfaces.

Changes in v5 (September 4, 2019)
* rebased to v2019.10-rc3
* revamp the implementation, removing changes on environment variable's
  attributes (See above)

Changes in v4 (July 17, 2019)
* remove already-merged patches
* revamp after Wolfgang's suggestion

Changes in v3 (June 4, 2019)
* remove already-merged patches
* revamp the code again
* introduce CONFIG_EFI_VARIABLE_USE_ENV for this configuration.
  Once another backing storage, i.e. StMM services for secure boot,
  is supported, another option will be added.

Changes in v2 (Apr 24, 2019)
* rebased on efi-2019-07
* revamp the implementation

v1 (Nov 28, 2018)
* initial

AKASHI Takahiro (19):
  env: extend interfaces allowing for env contexts
  env: define env context for U-Boot environment
  env: nowhere: rework with new env interfaces
  env: flash: support multiple env contexts
  env: fat: support multiple env contexts
  hashtable: support multiple env contexts
  api: converted with new env interfaces
  arch: converted with new env interfaces
  board: converted with new env interfaces
  cmd: converted with new env interfaces
  common: converted with new env interfaces
  disk: converted with new env interfaces
  drivers: converted with new env interfaces
  fs: converted with new env interfaces
  lib: converted with new env interfaces (except efi_loader)
  net: converted with new env interfaces
  post: converted with new env interfaces
  env,efi_loader: define env context for UEFI variables
  efi_loader: variable: rework with new env interfaces

 api/api.c                                     |   8 +-
 arch/arc/lib/bootm.c                          |   2 +-
 arch/arm/cpu/arm926ejs/spear/spr_misc.c       |   8 +-
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c       |   5 +-
 arch/arm/cpu/armv8/fsl-layerscape/soc.c       |  14 +-
 arch/arm/lib/bootm.c                          |   6 +-
 arch/arm/lib/semihosting.c                    |   2 +-
 arch/arm/mach-imx/mx6/opos6ul.c               |   4 +-
 arch/arm/mach-imx/mx7/soc.c                   |   4 +-
 arch/arm/mach-imx/video.c                     |   2 +-
 arch/arm/mach-keystone/ddr3.c                 |   2 +-
 arch/arm/mach-keystone/keystone.c             |   2 +-
 arch/arm/mach-kirkwood/cpu.c                  |   4 +-
 arch/arm/mach-meson/board-common.c            |   2 +-
 arch/arm/mach-omap2/utils.c                   |  20 +-
 arch/arm/mach-rmobile/cpu_info.c              |   2 +-
 arch/arm/mach-rockchip/boot_mode.c            |   4 +-
 arch/arm/mach-rockchip/rk3288/rk3288.c        |   2 +-
 arch/arm/mach-socfpga/misc_gen5.c             |   5 +-
 arch/arm/mach-socfpga/misc_s10.c              |   2 +-
 arch/arm/mach-stm32mp/cpu.c                   |  35 +-
 arch/arm/mach-tegra/board2.c                  |   4 +-
 arch/arm/mach-tegra/cboot.c                   |  18 +-
 arch/arm/mach-uniphier/board_late_init.c      |  19 +-
 arch/arm/mach-uniphier/mmc-first-dev.c        |   2 +-
 arch/m68k/lib/bootm.c                         |   2 +-
 arch/microblaze/lib/bootm.c                   |   2 +-
 arch/mips/lib/bootm.c                         |   6 +-
 arch/nds32/lib/bootm.c                        |   4 +-
 arch/powerpc/cpu/mpc85xx/cpu_init.c           |  10 +-
 arch/powerpc/cpu/mpc85xx/fdt.c                |   2 +-
 arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |   2 +-
 arch/powerpc/lib/bootm.c                      |   2 +-
 arch/sh/lib/bootm.c                           |   2 +-
 arch/sh/lib/zimageboot.c                      |   2 +-
 arch/x86/lib/zimage.c                         |  11 +-
 arch/xtensa/lib/bootm.c                       |   2 +-
 board/Arcturus/ucp1020/cmd_arc.c              |  40 +-
 board/Arcturus/ucp1020/ucp1020.c              |  16 +-
 board/BuR/brppt1/board.c                      |   4 +-
 board/BuR/brxre1/board.c                      |   9 +-
 board/BuR/common/br_resetc.c                  |   2 +-
 board/BuR/common/common.c                     |  47 +-
 board/BuS/eb_cpu5282/eb_cpu5282.c             |   8 +-
 board/CZ.NIC/turris_mox/turris_mox.c          |   4 +-
 board/CZ.NIC/turris_omnia/turris_omnia.c      |   6 +-
 board/CarMediaLab/flea3/flea3.c               |   2 +-
 board/LaCie/net2big_v2/net2big_v2.c           |   2 +-
 board/LaCie/netspace_v2/netspace_v2.c         |   2 +-
 board/Synology/ds414/cmd_syno.c               |   6 +-
 board/alliedtelesis/x530/x530.c               |   2 +-
 board/amazon/kc1/kc1.c                        |   4 +-
 board/amlogic/p200/p200.c                     |   4 +-
 board/amlogic/p201/p201.c                     |   4 +-
 board/amlogic/p212/p212.c                     |   4 +-
 board/amlogic/q200/q200.c                     |   4 +-
 board/aristainetos/aristainetos-v2.c          |   8 +-
 board/armltd/integrator/integrator.c          |   2 +-
 board/atmel/common/board.c                    |   4 +-
 board/atmel/common/mac_eeprom.c               |   2 +-
 board/atmel/sama5d3xek/sama5d3xek.c           |   2 +-
 board/bachmann/ot1200/ot1200.c                |   4 +-
 board/birdland/bav335x/board.c                |   8 +-
 board/bluegiga/apx4devkit/apx4devkit.c        |   5 +-
 board/bluewater/gurnard/gurnard.c             |   6 +-
 board/bosch/shc/board.c                       |   2 +-
 board/boundary/nitrogen6x/nitrogen6x.c        |  14 +-
 board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |   2 +-
 board/broadcom/bcm28155_ap/bcm28155_ap.c      |   2 +-
 board/broadcom/bcmstb/bcmstb.c                |   2 +-
 board/buffalo/lsxl/lsxl.c                     |   2 +-
 board/cadence/xtfpga/xtfpga.c                 |   4 +-
 board/ccv/xpress/xpress.c                     |   2 +-
 board/compulab/cl-som-imx7/cl-som-imx7.c      |   2 +-
 board/compulab/cm_fx6/cm_fx6.c                |  10 +-
 board/compulab/common/omap3_display.c         |   4 +-
 board/congatec/cgtqmx6eval/cgtqmx6eval.c      |   8 +-
 board/cssi/MCR3000/MCR3000.c                  |   2 +-
 board/davinci/da8xxevm/da850evm.c             |   2 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |   6 +-
 board/dhelectronics/dh_imx6/dh_imx6.c         |   2 +-
 board/eets/pdu001/board.c                     |   8 +-
 board/el/el6x/el6x.c                          |   2 +-
 board/emulation/qemu-riscv/qemu-riscv.c       |   2 +-
 board/engicam/common/board.c                  |  32 +-
 board/esd/meesc/meesc.c                       |   6 +-
 board/freescale/b4860qds/b4860qds.c           |   5 +-
 board/freescale/common/cmd_esbc_validate.c    |   2 +-
 board/freescale/common/fsl_chain_of_trust.c   |   6 +-
 board/freescale/common/sys_eeprom.c           |   4 +-
 board/freescale/common/vid.c                  |   4 +-
 board/freescale/imx8mq_evk/imx8mq_evk.c       |   4 +-
 board/freescale/imx8qm_mek/imx8qm_mek.c       |   4 +-
 board/freescale/imx8qxp_mek/imx8qxp_mek.c     |   4 +-
 board/freescale/ls1088a/eth_ls1088aqds.c      |   4 +-
 board/freescale/ls1088a/ls1088a.c             |   2 +-
 board/freescale/ls2080aqds/eth.c              |   6 +-
 board/freescale/ls2080aqds/ls2080aqds.c       |   2 +-
 board/freescale/ls2080ardb/ls2080ardb.c       |   6 +-
 board/freescale/lx2160a/eth_lx2160aqds.c      |   2 +-
 board/freescale/mpc8323erdb/mpc8323erdb.c     |   3 +-
 board/freescale/mpc837xemds/pci.c             |   2 +-
 board/freescale/mpc837xerdb/mpc837xerdb.c     |   2 +-
 board/freescale/mx51evk/mx51evk_video.c       |   2 +-
 board/freescale/mx53loco/mx53loco.c           |   4 +-
 board/freescale/mx53loco/mx53loco_video.c     |   2 +-
 board/freescale/mx6sabreauto/mx6sabreauto.c   |   8 +-
 board/freescale/mx6sabresd/mx6sabresd.c       |   8 +-
 board/freescale/mx6sxsabresd/mx6sxsabresd.c   |   2 +-
 .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |   6 +-
 board/freescale/mx6ullevk/mx6ullevk.c         |   4 +-
 board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |   2 +-
 board/freescale/qemu-ppce500/qemu-ppce500.c   |   4 +-
 board/freescale/t4qds/t4240qds.c              |   2 +-
 board/gardena/smart-gateway-at91sam/board.c   |   2 +-
 board/gardena/smart-gateway-mt7688/board.c    |  16 +-
 board/gateworks/gw_ventana/common.c           |   2 +-
 board/gateworks/gw_ventana/gw_ventana.c       |  61 +-
 board/gateworks/gw_ventana/gw_ventana_spl.c   |   4 +-
 board/gdsys/a38x/keyprogram.c                 |   4 +-
 board/gdsys/mpc8308/gazerbeam.c               |   4 +-
 board/gdsys/mpc8308/hrcon.c                   |   2 +-
 board/gdsys/mpc8308/strider.c                 |   2 +-
 board/gdsys/p1022/controlcenterd-id.c         |  10 +-
 board/gdsys/p1022/controlcenterd.c            |   2 +-
 board/ge/bx50v3/bx50v3.c                      |  13 +-
 board/ge/common/ge_common.c                   |   4 +-
 board/ge/mx53ppd/mx53ppd.c                    |   2 +-
 board/grinn/chiliboard/board.c                |   4 +-
 board/grinn/liteboard/board.c                 |   6 +-
 board/highbank/highbank.c                     |   9 +-
 board/hisilicon/poplar/poplar.c               |   2 +-
 board/imgtec/ci20/ci20.c                      |   6 +-
 board/intel/edison/edison.c                   |  14 +-
 board/isee/igep003x/board.c                   |   6 +-
 board/isee/igep00x0/igep00x0.c                |   4 +-
 board/k+p/kp_imx53/kp_id_rev.c                |  20 +-
 board/k+p/kp_imx53/kp_imx53.c                 |   4 +-
 board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |   4 +-
 board/keymile/common/common.c                 |  26 +-
 board/keymile/common/ivm.c                    |   8 +-
 board/keymile/km83xx/km83xx.c                 |   2 +-
 board/keymile/km_arm/km_arm.c                 |   6 +-
 board/keymile/kmp204x/kmp204x.c               |   4 +-
 board/kosagi/novena/novena.c                  |   2 +-
 board/laird/wb50n/wb50n.c                     |   2 +-
 board/lg/sniper/sniper.c                      |   4 +-
 board/liebherr/display5/spl.c                 |   4 +-
 board/liebherr/mccmon6/mccmon6.c              |   6 +-
 board/logicpd/imx6/imx6logic.c                |   8 +-
 board/menlo/m53menlo/m53menlo.c               |   2 +-
 board/micronas/vct/vct.c                      |   2 +-
 board/nokia/rx51/rx51.c                       |  10 +-
 board/overo/overo.c                           |  45 +-
 board/phytec/pcm052/pcm052.c                  |   4 +-
 board/phytec/pfla02/pfla02.c                  |   2 +-
 .../dragonboard410c/dragonboard410c.c         |   6 +-
 .../dragonboard820c/dragonboard820c.c         |   2 +-
 board/raspberrypi/rpi/rpi.c                   |  26 +-
 board/renesas/alt/alt.c                       |   3 +-
 board/renesas/gose/gose.c                     |   3 +-
 board/renesas/koelsch/koelsch.c               |   3 +-
 board/renesas/lager/lager.c                   |   3 +-
 board/renesas/porter/porter.c                 |   3 +-
 board/renesas/sh7752evb/sh7752evb.c           |   4 +-
 board/renesas/sh7753evb/sh7753evb.c           |   4 +-
 board/renesas/sh7757lcr/sh7757lcr.c           |   6 +-
 board/renesas/silk/silk.c                     |   3 +-
 board/renesas/stout/stout.c                   |   3 +-
 board/rockchip/kylin_rk3036/kylin_rk3036.c    |   2 +-
 board/samsung/common/exynos5-dt.c             |   2 +-
 board/samsung/common/misc.c                   |  14 +-
 board/samsung/odroid/odroid.c                 |   2 +-
 board/samsung/trats/trats.c                   |   2 +-
 board/samsung/universal_c210/universal.c      |   2 +-
 board/samtec/vining_fpga/socfpga.c            |  16 +-
 board/siemens/common/board.c                  |   4 +-
 board/siemens/draco/board.c                   |   6 +-
 board/siemens/pxm2/board.c                    |   4 +-
 board/siemens/rut/board.c                     |   2 +-
 board/siemens/taurus/taurus.c                 |  50 +-
 board/socrates/socrates.c                     |   4 +-
 board/softing/vining_2000/vining_2000.c       |   8 +-
 board/solidrun/mx6cuboxi/mx6cuboxi.c          |  16 +-
 .../stm32f429-discovery/stm32f429-discovery.c |   4 +-
 .../stm32f429-evaluation.c                    |   4 +-
 .../stm32f469-discovery/stm32f469-discovery.c |   4 +-
 board/st/stm32mp1/stm32mp1.c                  |  11 +-
 board/sunxi/board.c                           |  25 +-
 board/synopsys/hsdk/env-lib.c                 |  11 +-
 board/synopsys/hsdk/hsdk.c                    |   6 +-
 board/syteco/zmx25/zmx25.c                    |   8 +-
 board/tcl/sl50/board.c                        |   6 +-
 .../puma_rk3399/puma-rk3399.c                 |   8 +-
 board/ti/am335x/board.c                       |  18 +-
 board/ti/am43xx/board.c                       |   6 +-
 board/ti/am57xx/board.c                       |  14 +-
 board/ti/beagle/beagle.c                      |  43 +-
 board/ti/common/board_detect.c                |  14 +-
 board/ti/dra7xx/evm.c                         |  12 +-
 board/ti/evm/evm.c                            |   2 +-
 board/ti/ks2_evm/board.c                      |  10 +-
 board/ti/ks2_evm/board_k2g.c                  |   8 +-
 board/ti/panda/panda.c                        |   4 +-
 board/toradex/apalis-imx8/apalis-imx8.c       |   4 +-
 board/toradex/apalis_imx6/apalis_imx6.c       |  12 +-
 .../toradex/colibri-imx6ull/colibri-imx6ull.c |   6 +-
 board/toradex/colibri-imx8x/colibri-imx8x.c   |   4 +-
 board/toradex/colibri_imx6/colibri_imx6.c     |   8 +-
 board/toradex/colibri_vf/colibri_vf.c         |   2 +-
 board/toradex/common/tdx-cfg-block.c          |   2 +-
 board/toradex/common/tdx-common.c             |   2 +-
 board/tqc/tqma6/tqma6.c                       |   2 +-
 board/udoo/neo/neo.c                          |   2 +-
 board/udoo/udoo.c                             |   4 +-
 board/varisys/common/sys_eeprom.c             |   6 +-
 board/vscom/baltos/board.c                    |   6 +-
 board/wandboard/wandboard.c                   |  12 +-
 board/warp7/warp7.c                           |   6 +-
 .../work_92105/work_92105_display.c           |   2 +-
 board/xes/common/board.c                      |   6 +-
 board/xilinx/zynq/board.c                     |  16 +-
 board/xilinx/zynqmp/cmds.c                    |   2 +-
 board/xilinx/zynqmp/zynqmp.c                  |  24 +-
 cmd/ab_select.c                               |   2 +-
 cmd/avb.c                                     |   2 +-
 cmd/bdinfo.c                                  |   6 +-
 cmd/binop.c                                   |   4 +-
 cmd/bootefi.c                                 |   8 +-
 cmd/bootm.c                                   |   4 +-
 cmd/bootmenu.c                                |   6 +-
 cmd/cbfs.c                                    |   2 +-
 cmd/cramfs.c                                  |   8 +-
 cmd/dtimg.c                                   |   2 +-
 cmd/elf.c                                     |  29 +-
 cmd/fdt.c                                     |  22 +-
 cmd/fpga.c                                    |   4 +-
 cmd/gpt.c                                     |   8 +-
 cmd/ini.c                                     |   6 +-
 cmd/itest.c                                   |   2 +-
 cmd/jffs2.c                                   |   4 +-
 cmd/load.c                                    |  10 +-
 cmd/lzmadec.c                                 |   2 +-
 cmd/md5sum.c                                  |   4 +-
 cmd/mtdparts.c                                |  41 +-
 cmd/mvebu/bubt.c                              |   2 +-
 cmd/nand.c                                    |  12 +-
 cmd/net.c                                     |  46 +-
 cmd/nvedit.c                                  | 394 +++++++---
 cmd/part.c                                    |   6 +-
 cmd/pxe.c                                     |  33 +-
 cmd/qfw.c                                     |   6 +-
 cmd/reiser.c                                  |   8 +-
 cmd/setexpr.c                                 |   8 +-
 cmd/spl.c                                     |   5 +-
 cmd/ti/ddr3.c                                 |   2 +-
 cmd/tpm-common.c                              |   2 +-
 cmd/tpm-v1.c                                  |   2 +-
 cmd/trace.c                                   |  18 +-
 cmd/ubi.c                                     |   2 +-
 cmd/unzip.c                                   |   2 +-
 cmd/ximg.c                                    |   4 +-
 cmd/zfs.c                                     |   6 +-
 cmd/zip.c                                     |   2 +-
 common/autoboot.c                             |  22 +-
 common/board_f.c                              |   3 +-
 common/board_r.c                              |  10 +-
 common/bootm.c                                |  12 +-
 common/bootm_os.c                             |  12 +-
 common/bootretry.c                            |   2 +-
 common/cli.c                                  |   2 +-
 common/cli_hush.c                             |  14 +-
 common/cli_simple.c                           |   2 +-
 common/command.c                              |   2 +-
 common/console.c                              |  14 +-
 common/fdt_support.c                          |   6 +-
 common/hash.c                                 |   4 +-
 common/hwconfig.c                             |   5 +-
 common/image-android.c                        |   4 +-
 common/image-fdt.c                            |   4 +-
 common/image.c                                |  15 +-
 common/main.c                                 |   5 +-
 common/spl/spl_dfu.c                          |   6 +-
 common/spl/spl_ext.c                          |   4 +-
 common/spl/spl_fat.c                          |   4 +-
 common/spl/spl_net.c                          |   4 +-
 common/splash.c                               |   4 +-
 common/splash_source.c                        |   8 +-
 common/update.c                               |  10 +-
 common/usb_hub.c                              |   2 +-
 common/usb_kbd.c                              |   6 +-
 disk/part.c                                   |   2 +-
 disk/part_amiga.c                             |   4 +-
 drivers/bootcount/bootcount_env.c             |  12 +-
 drivers/ddr/fsl/fsl_ddr_gen4.c                |   2 +-
 drivers/ddr/fsl/interactive.c                 |   5 +-
 drivers/ddr/fsl/options.c                     |   4 +-
 drivers/dfu/dfu.c                             |   6 +-
 drivers/fastboot/fb_command.c                 |   4 +-
 drivers/fastboot/fb_common.c                  |   2 +-
 drivers/fastboot/fb_getvar.c                  |   8 +-
 drivers/fastboot/fb_mmc.c                     |   2 +-
 drivers/input/i8042.c                         |   2 +-
 drivers/input/input.c                         |   2 +-
 drivers/misc/fs_loader.c                      |   8 +-
 drivers/mtd/cfi_flash.c                       |   2 +-
 drivers/mtd/mtd_uboot.c                       |  11 +-
 drivers/net/fec_mxc.c                         |   2 +-
 drivers/net/fm/b4860.c                        |   3 +-
 drivers/net/fm/fdt.c                          |   2 +-
 drivers/net/fm/fm.c                           |   4 +-
 drivers/net/fsl-mc/mc.c                       |   7 +-
 drivers/net/netconsole.c                      |  14 +-
 drivers/net/phy/micrel_ksz90x1.c              |   4 +-
 drivers/net/sandbox-raw.c                     |   4 +-
 drivers/pci/pci.c                             |   4 +-
 drivers/pci/pci_common.c                      |   2 +-
 drivers/reset/reset-socfpga.c                 |   2 +-
 drivers/rtc/m41t60.c                          |   2 +-
 drivers/scsi/scsi.c                           |   2 +-
 drivers/serial/usbtty.c                       |   4 +-
 drivers/usb/gadget/designware_udc.c           |   2 +-
 drivers/usb/gadget/ether.c                    |  13 +-
 drivers/usb/gadget/f_dfu.c                    |   2 +-
 drivers/usb/gadget/f_fastboot.c               |   2 +-
 drivers/usb/gadget/f_rockusb.c                |   2 +-
 drivers/usb/gadget/f_sdp.c                    |   2 +-
 drivers/usb/host/ehci-fsl.c                   |   2 +-
 drivers/video/ati_radeon_fb.c                 |   2 +-
 drivers/video/cfb_console.c                   |   2 +-
 drivers/video/mb862xx.c                       |   2 +-
 drivers/video/mx3fb.c                         |   2 +-
 drivers/video/mxsfb.c                         |   2 +-
 drivers/video/videomodes.c                    |   4 +-
 env/Kconfig                                   | 683 +-----------------
 env/Kconfig.efi                               | 152 ++++
 env/Kconfig.uboot                             | 671 +++++++++++++++++
 env/Makefile                                  |  33 +-
 env/callback.c                                |  40 +-
 env/common.c                                  | 255 ++++---
 env/env.c                                     | 158 ++--
 env/env_ctx_efi.c                             | 131 ++++
 env/env_ctx_uboot.c                           | 292 ++++++++
 env/fat.c                                     | 102 ++-
 env/flags.c                                   |  35 +-
 env/flash.c                                   | 397 ++++++----
 env/nowhere.c                                 |   7 +-
 fs/fs.c                                       |  14 +-
 fs/ubifs/ubifs.c                              |   2 +-
 include/_exports.h                            |   6 +-
 include/common.h                              |   6 +-
 include/env.h                                 | 114 ++-
 include/env_internal.h                        |  89 ++-
 include/exports.h                             |   5 +-
 include/search.h                              |   6 +-
 lib/efi_loader/efi_console.c                  |   2 +-
 lib/efi_loader/efi_variable.c                 |  91 ++-
 lib/fdtdec.c                                  |   2 +-
 lib/hashtable.c                               |  14 +-
 lib/smbios.c                                  |   2 +-
 lib/uuid.c                                    |   2 +-
 net/bootp.c                                   |  17 +-
 net/dns.c                                     |   2 +-
 net/eth-uclass.c                              |   6 +-
 net/eth_common.c                              |  18 +-
 net/eth_legacy.c                              |   2 +-
 net/link_local.c                              |   2 +-
 net/net.c                                     |  11 +-
 net/tftp.c                                    |  10 +-
 net/wol.c                                     |   2 +-
 post/post.c                                   |   2 +-
 371 files changed, 3690 insertions(+), 2337 deletions(-)
 create mode 100644 env/Kconfig.efi
 create mode 100644 env/Kconfig.uboot
 create mode 100644 env/env_ctx_efi.c
 create mode 100644 env/env_ctx_uboot.c

-- 
2.21.0

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 01/19] env: extend interfaces allowing for env contexts
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment AKASHI Takahiro
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

The notion of "env context" (or simply "context") will provide users
of env interfaces to manage their own domain of variables, which is
separated from other contexts and can be loaded/stored with dedicated
backing storage device.

With this patch, almost of all env interfaces are extended to accept
additional argument of a pointer to env context to identify targeted
domain after Wolfgang's requirement.

Optionally, a context may have no backing storage, in this case,
all the entries associated with this context will be lost after reboot
and env_save() returns -ENODEV.

In addition, "env" command is also modified to allow for specifying
a context with "-C <context name>" option.
Please note "-e" in "env set" and "env print" is still maintained
not only for backward compatibility but also for usefullness
at non-U-Boot-environment-based UEFI variables implementation,
in particular, secure storage solution in the future.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 cmd/nvedit.c           | 394 +++++++++++++++++-------
 env/Kconfig            | 682 ++---------------------------------------
 env/Makefile           |  30 +-
 env/callback.c         |  40 ++-
 env/common.c           | 255 ++++++++-------
 env/env.c              | 158 ++++++----
 env/flags.c            |  35 ++-
 include/_exports.h     |   6 +-
 include/common.h       |   6 +-
 include/env.h          |  95 ++++--
 include/env_internal.h |  89 +++++-
 include/exports.h      |   5 +-
 12 files changed, 802 insertions(+), 993 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 1cb0bc1460b9..04af78d71b47 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -40,34 +40,24 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if	defined(CONFIG_ENV_IS_IN_EEPROM)	|| \
-	defined(CONFIG_ENV_IS_IN_FLASH)		|| \
-	defined(CONFIG_ENV_IS_IN_MMC)		|| \
-	defined(CONFIG_ENV_IS_IN_FAT)		|| \
-	defined(CONFIG_ENV_IS_IN_EXT4)		|| \
-	defined(CONFIG_ENV_IS_IN_NAND)		|| \
-	defined(CONFIG_ENV_IS_IN_NVRAM)		|| \
-	defined(CONFIG_ENV_IS_IN_ONENAND)	|| \
-	defined(CONFIG_ENV_IS_IN_SATA)		|| \
-	defined(CONFIG_ENV_IS_IN_SPI_FLASH)	|| \
-	defined(CONFIG_ENV_IS_IN_REMOTE)	|| \
-	defined(CONFIG_ENV_IS_IN_UBI)
-
-#define ENV_IS_IN_DEVICE
-
-#endif
-
-#if	!defined(ENV_IS_IN_DEVICE)		&& \
-	!defined(CONFIG_ENV_IS_NOWHERE)
-# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
-NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
-#endif
-
 /*
  * Maximum expected input data size for import command
  */
 #define	MAX_ENV_SIZE	(1 << 20)	/* 1 MiB */
 
+static struct env_context *get_env_context(const char *arg)
+{
+	struct env_context *ctx;
+	int i;
+
+	for (i = 0, ctx = U_BOOT_ENV_CTX_START; i < U_BOOT_ENV_CTX_COUNT;
+	     i++, ctx++)
+		if (!strcmp(arg, ctx->name))
+			return ctx;
+
+	return NULL;
+}
+
 /*
  * This variable is incremented on each do_env_set(), so it can
  * be used via env_get_id() as an indication, if the environment
@@ -75,11 +65,9 @@ NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
  * variable only if the environment was changed ... done so for
  * example in NetInitLoop()
  */
-static int env_id = 1;
-
-int env_get_id(void)
+int env_get_id(struct env_context *ctx)
 {
-	return env_id;
+	return ctx->env_id;
 }
 
 #ifndef CONFIG_SPL_BUILD
@@ -88,7 +76,7 @@ int env_get_id(void)
  *
  * Returns 0 in case of error, or length of printed string
  */
-static int env_print(char *name, int flag)
+static int env_print(struct env_context *ctx, char *name, int flag)
 {
 	char *res = NULL;
 	ssize_t len;
@@ -96,9 +84,10 @@ static int env_print(char *name, int flag)
 	if (name) {		/* print a single name */
 		struct env_entry e, *ep;
 
+		e.ctx = ctx;
 		e.key = name;
 		e.data = NULL;
-		hsearch_r(e, ENV_FIND, &ep, &env_htab, flag);
+		hsearch_r(e, ENV_FIND, &ep, ctx->htab, flag);
 		if (ep == NULL)
 			return 0;
 		len = printf("%s=%s\n", ep->key, ep->data);
@@ -106,7 +95,7 @@ static int env_print(char *name, int flag)
 	}
 
 	/* print whole list */
-	len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
+	len = hexport_r(ctx->htab, '\n', flag, &res, 0, 0, NULL);
 
 	if (len > 0) {
 		puts(res);
@@ -122,24 +111,48 @@ static int env_print(char *name, int flag)
 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
 			char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	int i;
 	int rcode = 0;
 	int env_flag = H_HIDE_DOT;
 
+	while (argc > 1 && argv[1][0] == '-') {
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e')
-		return do_env_print_efi(cmdtp, flag, --argc, ++argv);
+		if (!strcmp(argv[1], "-e")) {
+			argc--;
+			argv++;
+
+			return do_env_print_efi(cmdtp, flag, argc, argv);
+		}
 #endif
 
-	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
-		argc--;
-		argv++;
-		env_flag &= ~H_HIDE_DOT;
+		if (!strcmp(argv[1], "-a")) {
+			argc--;
+			argv++;
+			env_flag &= ~H_HIDE_DOT;
+			continue;
+		}
+
+		if (!strcmp(argv[1], "-C")) {
+			if (argc == 2) {
+				printf("\nNo context specified\n");
+				return 0;
+			}
+			ctx = get_env_context(argv[2]);
+			if (!ctx) {
+				printf("\nInvalid context: %s\n", argv[2]);
+				return 0;
+			}
+			argc -= 2;
+			argv += 2;
+
+			continue;
+		}
 	}
 
 	if (argc == 1) {
 		/* print all env vars */
-		rcode = env_print(NULL, env_flag);
+		rcode = env_print(ctx, NULL, env_flag);
 		if (!rcode)
 			return 1;
 		printf("\nEnvironment size: %d/%ld bytes\n",
@@ -150,7 +163,7 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
 	/* print selected env vars */
 	env_flag &= ~H_HIDE_DOT;
 	for (i = 1; i < argc; ++i) {
-		int rc = env_print(argv[i], env_flag);
+		int rc = env_print(ctx, argv[i], env_flag);
 		if (!rc) {
 			printf("## Error: \"%s\" not defined\n", argv[i]);
 			++rcode;
@@ -164,12 +177,23 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
 		       int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	char *res = NULL;
 	int len, grep_how, grep_what;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	if (argc >= 5 && !strcmp(argc[0], "-C")) {
+		ctx = get_env_context(argv[1]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
 	grep_how  = H_MATCH_SUBSTR;	/* default: substring search	*/
 	grep_what = H_MATCH_BOTH;	/* default: grep names and values */
 
@@ -200,7 +224,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
 	}
 
 DONE:
-	len = hexport_r(&env_htab, '\n',
+	len = hexport_r(ctx->htab, '\n',
 			flag | grep_what | grep_how,
 			&res, 0, argc, argv);
 
@@ -223,6 +247,7 @@ DONE:
  */
 static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 {
+	struct env_context *ctx = ctx_uboot;
 	int   i, len;
 	char  *name, *value, *s;
 	struct env_entry e, *ep;
@@ -230,9 +255,23 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 	debug("Initial value for argc=%d\n", argc);
 
 #if CONFIG_IS_ENABLED(CMD_NVEDIT_EFI)
-	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e')
-		return do_env_set_efi(NULL, flag, --argc, ++argv);
+	if (argc > 1 && !strcmp(argv[1], "-e")) {
+		argc--;
+		argv++;
+
+		/* FIXME: env_flag */
+		return do_env_set_efi(NULL, flag, argc, argv);
+	}
 #endif
+	if (argc >= 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
 
 	while (argc > 1 && **(argv + 1) == '-') {
 		char *arg = *++argv;
@@ -257,11 +296,11 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 		return 1;
 	}
 
-	env_id++;
+	ctx->env_id++;
 
 	/* Delete only ? */
 	if (argc < 3 || argv[2] == NULL) {
-		int rc = hdelete_r(name, &env_htab, env_flag);
+		int rc = hdelete_r(name, ctx->htab, env_flag);
 		return !rc;
 	}
 
@@ -286,9 +325,10 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 	if (s != value)
 		*--s = '\0';
 
+	e.ctx	= ctx;
 	e.key	= name;
 	e.data	= value;
-	hsearch_r(e, ENV_ENTER, &ep, &env_htab, env_flag);
+	hsearch_r(e, ENV_ENTER, &ep, ctx->htab, env_flag);
 	free(value);
 	if (!ep) {
 		printf("## Error inserting \"%s\" variable, errno=%d\n",
@@ -299,18 +339,19 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 	return 0;
 }
 
-int env_set(const char *varname, const char *varvalue)
+int env_set(struct env_context *ctx, const char *varname, const char *varvalue)
 {
-	const char * const argv[4] = { "setenv", varname, varvalue, NULL };
+	const char * const argv[6] = { "setenv", "-C", ctx->name,
+					varname, varvalue, NULL };
 
 	/* before import into hashtable */
-	if (!(gd->flags & GD_FLG_ENV_READY))
+	if (!env_is_ready(ctx))
 		return 1;
 
 	if (varvalue == NULL || varvalue[0] == '\0')
-		return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
+		return _do_env_set(0, 4, (char * const *)argv, H_PROGRAMMATIC);
 	else
-		return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
+		return _do_env_set(0, 5, (char * const *)argv, H_PROGRAMMATIC);
 }
 
 /**
@@ -320,12 +361,12 @@ int env_set(const char *varname, const char *varvalue)
  * @param value		Value to set it to
  * @return 0 if ok, 1 on error
  */
-int env_set_ulong(const char *varname, ulong value)
+int env_set_ulong(struct env_context *ctx, const char *varname, ulong value)
 {
 	/* TODO: this should be unsigned */
 	char *str = simple_itoa(value);
 
-	return env_set(varname, str);
+	return env_set(ctx, varname, str);
 }
 
 /**
@@ -335,21 +376,22 @@ int env_set_ulong(const char *varname, ulong value)
  * @param value		Value to set it to
  * @return 0 if ok, 1 on error
  */
-int env_set_hex(const char *varname, ulong value)
+int env_set_hex(struct env_context *ctx, const char *varname, ulong value)
 {
 	char str[17];
 
 	sprintf(str, "%lx", value);
-	return env_set(varname, str);
+	return env_set(ctx, varname, str);
 }
 
-ulong env_get_hex(const char *varname, ulong default_val)
+ulong env_get_hex(struct env_context *ctx, const char *varname,
+		  ulong default_val)
 {
 	const char *s;
 	ulong value;
 	char *endp;
 
-	s = env_get(varname);
+	s = env_get(ctx, varname);
 	if (s)
 		value = simple_strtoul(s, &endp, 16);
 	if (!s || endp == s)
@@ -360,7 +402,7 @@ ulong env_get_hex(const char *varname, ulong default_val)
 
 int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr)
 {
-	eth_parse_enetaddr(env_get(name), enetaddr);
+	eth_parse_enetaddr(env_get(ctx_uboot, name), enetaddr);
 	return is_valid_ethaddr(enetaddr);
 }
 
@@ -373,7 +415,7 @@ int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr)
 
 	sprintf(buf, "%pM", enetaddr);
 
-	return env_set(name, buf);
+	return env_set(ctx_uboot, name, buf);
 }
 
 #ifndef CONFIG_SPL_BUILD
@@ -509,10 +551,21 @@ static int print_active_callback(struct env_entry *entry)
  */
 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	struct env_clbk_tbl *clbkp;
 	int i;
 	int num_callbacks;
 
+	if (argc > 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
 	/* Print the available callbacks */
 	puts("Available callbacks:\n");
 	puts("\tCallback Name\n");
@@ -535,7 +588,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	puts("Active callback bindings:\n");
 	printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
 	printf("\t%-20s %-20s\n", "-------------", "-------------");
-	hwalk_r(&env_htab, print_active_callback);
+	hwalk_r(ctx->htab, print_active_callback);
 	return 0;
 }
 #endif
@@ -577,6 +630,18 @@ static int print_active_flags(struct env_entry *entry)
  */
 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
+
+	if (argc > 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
 	/* Print the available variable types */
 	printf("Available variable type flags (position %d):\n",
 		ENV_FLAGS_VARTYPE_LOC);
@@ -608,7 +673,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		"Variable Access");
 	printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
 		"---------------");
-	hwalk_r(&env_htab, print_active_flags);
+	hwalk_r(ctx->htab, print_active_flags);
 	return 0;
 }
 #endif
@@ -620,18 +685,31 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	char buffer[CONFIG_SYS_CBSIZE];
 	char *init_val;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	if (argc > 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+		if (argc < 2)
+			return CMD_RET_USAGE;
+	}
+
 	/* before import into hashtable */
-	if (!(gd->flags & GD_FLG_ENV_READY))
+	if (!ctx->is_ready(ctx))
 		return 1;
 
 	/* Set read buffer to initial value or empty sting */
-	init_val = env_get(argv[1]);
+	init_val = env_get(ctx, argv[1]);
 	if (init_val)
 		snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val);
 	else
@@ -641,14 +719,15 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 		return 1;
 
 	if (buffer[0] == '\0') {
-		const char * const _argv[3] = { "setenv", argv[1], NULL };
+		const char * const _argv[5] = { "setenv", "-C", ctx->name,
+						argv[1], NULL };
 
-		return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE);
+		return _do_env_set(0, 4, (char * const *)_argv, H_INTERACTIVE);
 	} else {
-		const char * const _argv[4] = { "setenv", argv[1], buffer,
-			NULL };
+		const char * const _argv[6] = { "setenv", "-C", ctx->name,
+						argv[1], buffer, NULL };
 
-		return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE);
+		return _do_env_set(0, 5, (char * const *)_argv, H_INTERACTIVE);
 	}
 }
 #endif /* CONFIG_CMD_EDITENV */
@@ -659,22 +738,28 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
  * return address of storage for that variable,
  * or NULL if not found
  */
-char *env_get(const char *name)
+char *env_get(struct env_context *ctx, const char *name)
 {
-	if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
+	if (env_is_ready(ctx)) { /* after import into hashtable */
 		struct env_entry e, *ep;
 
 		WATCHDOG_RESET();
 
+		e.ctx	= ctx;
 		e.key	= name;
 		e.data	= NULL;
-		hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
+		hsearch_r(e, ENV_FIND, &ep, ctx->htab, 0);
 
 		return ep ? ep->data : NULL;
 	}
 
+	/* FIXME: env_buf should be place in env_context? */
+	if (ctx != ctx_uboot)
+		return NULL;
+
 	/* restricted capabilities before import */
-	if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
+	if (env_get_f(ctx, name, (char *)gd->env_buf, sizeof(gd->env_buf))
+	    > 0)
 		return (char *)(gd->env_buf);
 
 	return NULL;
@@ -683,27 +768,28 @@ char *env_get(const char *name)
 /*
  * Look up variable from environment for restricted C runtime env.
  */
-int env_get_f(const char *name, char *buf, unsigned len)
+int env_get_f(struct env_context *ctx, const char *name, char *buf,
+	      unsigned int len)
 {
 	int i, nxt, c;
 
-	for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
+	for (i = 0; env_get_char(ctx, i) != '\0'; i = nxt + 1) {
 		int val, n;
 
-		for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) {
+		for (nxt = i; (c = env_get_char(ctx, nxt)) != '\0'; ++nxt) {
 			if (c < 0)
 				return c;
-			if (nxt >= CONFIG_ENV_SIZE)
+			if (nxt >= ctx->env_size)
 				return -1;
 		}
 
-		val = env_match((uchar *)name, i);
+		val = env_match(ctx, (uchar *)name, i);
 		if (val < 0)
 			continue;
 
 		/* found; copy out */
 		for (n = 0; n < len; ++n, ++buf) {
-			c = env_get_char(val++);
+			c = env_get_char(ctx, val++);
 			if (c < 0)
 				return c;
 			*buf = c;
@@ -732,13 +818,14 @@ int env_get_f(const char *name, char *buf, unsigned len)
  *			found
  * @return the decoded value, or default_val if not found
  */
-ulong env_get_ulong(const char *name, int base, ulong default_val)
+ulong env_get_ulong(struct env_context *ctx, const char *name, int base,
+		    ulong default_val)
 {
 	/*
 	 * We can use env_get() here, even before relocation, since the
 	 * environment variable value is an integer and thus short.
 	 */
-	const char *str = env_get(name);
+	const char *str = env_get(ctx, name);
 
 	return str ? simple_strtoul(str, NULL, base) : default_val;
 }
@@ -748,11 +835,23 @@ ulong env_get_ulong(const char *name, int base, ulong default_val)
 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
-	return env_save() ? 1 : 0;
+	struct env_context *ctx = ctx_uboot;
+
+	if (argc >= 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
+	return env_save(ctx) ? 1 : 0;
 }
 
 U_BOOT_CMD(
-	saveenv, 1, 0,	do_env_save,
+	saveenv, 3, 0,	do_env_save,
 	"save environment variables to persistent storage",
 	""
 );
@@ -761,11 +860,21 @@ U_BOOT_CMD(
 static int do_env_erase(cmd_tbl_t *cmdtp, int flag, int argc,
 			char * const argv[])
 {
-	return env_erase() ? 1 : 0;
+	if (argc >= 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
+	return env_erase(ctx) ? 1 : 0;
 }
 
 U_BOOT_CMD(
-	eraseenv, 1, 0,	do_env_erase,
+	eraseenv, 3, 0,	do_env_erase,
 	"erase environment variables from persistent storage",
 	""
 );
@@ -773,16 +882,16 @@ U_BOOT_CMD(
 #endif
 #endif /* CONFIG_SPL_BUILD */
 
-int env_match(uchar *s1, int i2)
+int env_match(struct env_context *ctx, uchar *s1, int i2)
 {
 	if (s1 == NULL)
 		return -1;
 
-	while (*s1 == env_get_char(i2++))
+	while (*s1 == env_get_char(ctx, i2++))
 		if (*s1++ == '=')
 			return i2;
 
-	if (*s1 == '\0' && env_get_char(i2-1) == '=')
+	if (*s1 == '\0' && env_get_char(ctx, i2 - 1) == '=')
 		return i2;
 
 	return -1;
@@ -792,9 +901,20 @@ int env_match(uchar *s1, int i2)
 static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 			  int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	int all = 0, env_flag = H_INTERACTIVE;
 
 	debug("Initial value for argc=%d\n", argc);
+	if (argc >= 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
 	while (--argc > 0 && **++argv == '-') {
 		char *arg = *argv;
 
@@ -814,13 +934,13 @@ static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 	debug("Final value for argc=%d\n", argc);
 	if (all && (argc == 0)) {
 		/* Reset the whole environment */
-		env_set_default("## Resetting to default environment\n",
+		env_set_default(ctx, "## Resetting to default environment\n",
 				env_flag);
 		return 0;
 	}
 	if (!all && (argc > 0)) {
 		/* Reset individual variables */
-		env_set_default_vars(argc, argv, env_flag);
+		env_set_default_vars(ctx, argc, argv, env_flag);
 		return 0;
 	}
 
@@ -830,10 +950,21 @@ static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
 			 int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	int env_flag = H_INTERACTIVE;
 	int ret = 0;
 
 	debug("Initial value for argc=%d\n", argc);
+	if (argc >= 3 && !strcmp(argv[1], "-C")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+	}
+
 	while (argc > 1 && **(argv + 1) == '-') {
 		char *arg = *++argv;
 
@@ -850,12 +981,12 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
 	}
 	debug("Final value for argc=%d\n", argc);
 
-	env_id++;
+	ctx->env_id++;
 
 	while (--argc > 0) {
 		char *name = *++argv;
 
-		if (!hdelete_r(name, &env_htab, env_flag))
+		if (!hdelete_r(name, ctx->htab, env_flag))
 			ret = 1;
 	}
 
@@ -911,12 +1042,13 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
 			 int argc, char * const argv[])
 {
+	struct  env_context *ctx = ctx_uboot;
 	char	buf[32];
 	ulong	addr;
 	char	*ptr, *cmd, *res;
 	size_t	size = 0;
 	ssize_t	len;
-	env_t	*envp;
+	env_hdr_t *envp;
 	char	sep = '\n';
 	int	chk = 0;
 	int	fmt = 0;
@@ -927,6 +1059,18 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag,
 		char *arg = *argv;
 		while (*++arg) {
 			switch (*arg) {
+			case 'C':
+				if (--argc <= 0)
+					return cmd_usage(cmdtp);
+
+				++argv;
+				ctx = get_env_context(argv[0]);
+				if (!ctx) {
+					printf("\nInvalid context: %s\n",
+					       argv[0]);
+					return CMD_RET_FAILURE;
+				}
+				break;
 			case 'b':		/* raw binary format */
 				if (fmt++)
 					goto sep_err;
@@ -968,7 +1112,7 @@ NXTARG:		;
 	argv++;
 
 	if (sep) {		/* export as text file */
-		len = hexport_r(&env_htab, sep,
+		len = hexport_r(ctx->htab, sep,
 				H_MATCH_KEY | H_MATCH_IDENT,
 				&ptr, size, argc, argv);
 		if (len < 0) {
@@ -977,21 +1121,21 @@ NXTARG:		;
 			return 1;
 		}
 		sprintf(buf, "%zX", (size_t)len);
-		env_set("filesize", buf);
+		env_set(ctx_uboot, "filesize", buf);
 
 		return 0;
 	}
 
-	envp = (env_t *)ptr;
+	envp = (env_hdr_t *)ptr;
 
 	if (chk)		/* export as checksum protected block */
 		res = (char *)envp->data;
 	else			/* export as raw binary data */
 		res = ptr;
 
-	len = hexport_r(&env_htab, '\0',
+	len = hexport_r(ctx->htab, '\0',
 			H_MATCH_KEY | H_MATCH_IDENT,
-			&res, ENV_SIZE, argc, argv);
+			&res, ctx->env_size, argc, argv);
 	if (len < 0) {
 		pr_err("## Error: Cannot export environment: errno = %d\n",
 		       errno);
@@ -1000,12 +1144,13 @@ NXTARG:		;
 
 	if (chk) {
 		envp->crc = crc32(0, envp->data,
-				size ? size - offsetof(env_t, data) : ENV_SIZE);
+				size ? size - offsetof(env_t, data)
+					: ctx->env_size);
 #ifdef CONFIG_ENV_ADDR_REDUND
 		envp->flags = ENV_REDUND_ACTIVE;
 #endif
 	}
-	env_set_hex("filesize", len + offsetof(env_t, data));
+	env_set_hex(ctx_uboot, "filesize", len + offsetof(env_t, data));
 
 	return 0;
 
@@ -1044,6 +1189,7 @@ sep_err:
 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
 			 int argc, char * const argv[])
 {
+	struct env_context *ctx = ctx_uboot;
 	ulong	addr;
 	char	*cmd, *ptr;
 	char	sep = '\n';
@@ -1060,6 +1206,18 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
 		char *arg = *argv;
 		while (*++arg) {
 			switch (*arg) {
+			case 'C':
+				if (--argc <= 0)
+					return cmd_usage(cmdtp);
+
+				++argv;
+				ctx = get_env_context(argv[0]);
+				if (!ctx) {
+					printf("\nInvalid context: %s\n",
+					       argv[0]);
+					return CMD_RET_FAILURE;
+				}
+				break;
 			case 'b':		/* raw binary format */
 				if (fmt++)
 					goto sep_err;
@@ -1129,9 +1287,9 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
 
 	if (chk) {
 		uint32_t crc;
-		env_t *ep = (env_t *)ptr;
+		env_hdr_t *ep = (env_hdr_t *)ptr;
 
-		size -= offsetof(env_t, data);
+		size -= offsetof(env_hdr_t, data);
 		memcpy(&crc, &ep->crc, sizeof(crc));
 
 		if (crc32(0, ep->data, size) != crc) {
@@ -1141,13 +1299,13 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
 		ptr = (char *)ep->data;
 	}
 
-	if (!himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
+	if (!himport_r(ctx->htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
 		       crlf_is_lf, wl ? argc - 2 : 0, wl ? &argv[2] : NULL)) {
 		pr_err("## Error: Environment import failed: errno = %d\n",
 		       errno);
 		return 1;
 	}
-	gd->flags |= GD_FLG_ENV_READY;
+	env_set_ready(ctx);
 
 	return 0;
 
@@ -1262,14 +1420,28 @@ static int do_env_info(cmd_tbl_t *cmdtp, int flag,
 static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	struct env_context *ctx =  ctx_uboot;
 	struct env_entry e, *ep;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	if (argc >= 3 && !strcmp(argv[1], "-c")) {
+		ctx = get_env_context(argv[2]);
+		if (!ctx) {
+			printf("\nInvalid context: %s\n", argv[2]);
+			return CMD_RET_FAILURE;
+		}
+		argc -= 2;
+		argv += 2;
+		if (argc < 2)
+			return CMD_RET_USAGE;
+	}
+
+	e.ctx = ctx;
 	e.key = argv[1];
 	e.data = NULL;
-	hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
+	hsearch_r(e, ENV_FIND, &ep, ctx->htab, 0);
 
 	return (ep == NULL) ? 1 : 0;
 }
@@ -1285,22 +1457,22 @@ static cmd_tbl_t cmd_env_sub[] = {
 	U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
 	U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
 #if defined(CONFIG_CMD_EDITENV)
-	U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
+	U_BOOT_CMD_MKENT(edit, 4, 0, do_env_edit, "", ""),
 #endif
 #if defined(CONFIG_CMD_ENV_CALLBACK)
-	U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
+	U_BOOT_CMD_MKENT(callbacks, 3, 0, do_env_callback, "", ""),
 #endif
 #if defined(CONFIG_CMD_ENV_FLAGS)
-	U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
+	U_BOOT_CMD_MKENT(flags, 3, 0, do_env_flags, "", ""),
 #endif
 #if defined(CONFIG_CMD_EXPORTENV)
-	U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
+	U_BOOT_CMD_MKENT(export, 6, 0, do_env_export, "", ""),
 #endif
 #if defined(CONFIG_CMD_GREPENV)
 	U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
 #endif
 #if defined(CONFIG_CMD_IMPORTENV)
-	U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
+	U_BOOT_CMD_MKENT(import, 7, 0, do_env_import, "", ""),
 #endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
 	U_BOOT_CMD_MKENT(info, 2, 0, do_env_info, "", ""),
@@ -1310,14 +1482,14 @@ static cmd_tbl_t cmd_env_sub[] = {
 	U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
 #endif
 #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
-	U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
+	U_BOOT_CMD_MKENT(save, 3, 0, do_env_save, "", ""),
 #if defined(CONFIG_CMD_ERASEENV)
-	U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
+	U_BOOT_CMD_MKENT(erase, 3, 0, do_env_erase, "", ""),
 #endif
 #endif
 	U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
 #if defined(CONFIG_CMD_ENV_EXISTS)
-	U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
+	U_BOOT_CMD_MKENT(exists, 4, 0, do_env_exists, "", ""),
 #endif
 };
 
@@ -1415,7 +1587,7 @@ U_BOOT_CMD(
 
 #if defined(CONFIG_CMD_EDITENV)
 U_BOOT_CMD_COMPLETE(
-	editenv, 2, 0,	do_env_edit,
+	editenv, 4, 0,	do_env_edit,
 	"edit environment variable",
 	"name\n"
 	"    - edit environment variable 'name'",
diff --git a/env/Kconfig b/env/Kconfig
index 74db2f38cc19..ae96cf75bbaa 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -1,667 +1,51 @@
 menu "Environment"
 
-config ENV_IS_NOWHERE
-	bool "Environment is not stored"
-	default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
-		     !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
-		     !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
-		     !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
-		     !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
-		     !ENV_IS_IN_UBI
-	help
-	  Define this if you don't want to or can't have an environment stored
-	  on a storage medium. In this case the environment will still exist
-	  while U-Boot is running, but once U-Boot exits it will not be
-	  stored. U-Boot will therefore always start up with a default
-	  environment.
-
-config ENV_IS_IN_EEPROM
-	bool "Environment in EEPROM"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Use this if you have an EEPROM or similar serial access
-	  device and a driver for it.
-
-	  - CONFIG_ENV_OFFSET:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines specify the offset and size of the
-	  environment area within the total memory of your EEPROM.
-
-	  Note that we consider the length of the address field to
-	  still be one byte because the extra address bits are hidden
-	  in the chip address.
-
-	  - CONFIG_ENV_EEPROM_IS_ON_I2C
-	  define this, if you have I2C and SPI activated, and your
-	  EEPROM, which holds the environment, is on the I2C bus.
-
-	  - CONFIG_I2C_ENV_EEPROM_BUS
-	  if you have an Environment on an EEPROM reached over
-	  I2C muxes, you can define here, how to reach this
-	  EEPROM. For example:
-
-	  #define CONFIG_I2C_ENV_EEPROM_BUS	  1
-
-	  EEPROM which holds the environment, is reached over
-	  a pca9547 i2c mux with address 0x70, channel 3.
-
-config ENV_IS_IN_FAT
-	bool "Environment is in a FAT filesystem"
-	depends on !CHAIN_OF_TRUST
-	default y if ARCH_BCM283X
-	default y if ARCH_SUNXI && MMC
-	default y if MMC_OMAP_HS && TI_COMMON_CMD_OPTIONS
+config ENV_DRV_NONE
+	bool
+	default y if !ENV_DRV_EEPROM && !ENV_DRV_EXT4 && \
+		     !ENV_DRV_FAT && !ENV_DRV_FLASH && \
+		     !ENV_DRV_MMC && !ENV_DRV_NAND && \
+		     !ENV_DRV_NVRAM && !ENV_DRV_ONENAND && \
+		     !ENV_DRV_REMOTE && !ENV_DRV_SPI_FLASH && \
+		     !ENV_DRV_UBI
+
+config ENV_DRV_EEPROM
+	bool
+
+config ENV_DRV_FAT
+	bool
 	select FS_FAT
 	select FAT_WRITE
-	help
-	  Define this if you want to use the FAT file system for the environment.
 
-config ENV_IS_IN_EXT4
-	bool "Environment is in a EXT4 filesystem"
-	depends on !CHAIN_OF_TRUST
+config ENV_DRV_EXT4
+	bool
 	select EXT4_WRITE
-	help
-	  Define this if you want to use the EXT4 file system for the environment.
-
-config ENV_IS_IN_FLASH
-	bool "Environment in flash memory"
-	depends on !CHAIN_OF_TRUST
-	default y if ARCH_CINTEGRATOR
-	default y if ARCH_INTEGRATOR_CP
-	default y if M548x || M547x || M5282 || MCF547x_8x
-	default y if MCF532x || MCF52x2
-	default y if MPC86xx || MPC83xx
-	default y if ARCH_MPC8572 || ARCH_MPC8548 || ARCH_MPC8641
-	default y if SH && !CPU_SH4
-	help
-	  Define this if you have a flash device which you want to use for the
-	  environment.
-
-	  a) The environment occupies one whole flash sector, which is
-	   "embedded" in the text segment with the U-Boot code. This
-	   happens usually with "bottom boot sector" or "top boot
-	   sector" type flash chips, which have several smaller
-	   sectors at the start or the end. For instance, such a
-	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
-	   such a case you would place the environment in one of the
-	   4 kB sectors - with U-Boot code before and after it. With
-	   "top boot sector" type flash chips, you would put the
-	   environment in one of the last sectors, leaving a gap
-	   between U-Boot and the environment.
-
-	  CONFIG_ENV_OFFSET:
-
-	   Offset of environment data (variable area) to the
-	   beginning of flash memory; for instance, with bottom boot
-	   type flash chips the second sector can be used: the offset
-	   for this sector is given here.
-
-	   CONFIG_ENV_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
 
-	  CONFIG_ENV_ADDR:
+config ENV_DRV_FLASH
+	bool
 
-	   This is just another way to specify the start address of
-	   the flash sector containing the environment (instead of
-	   CONFIG_ENV_OFFSET).
-
-	  CONFIG_ENV_SECT_SIZE:
-
-	   Size of the sector containing the environment.
-
-
-	  b) Sometimes flash chips have few, equal sized, BIG sectors.
-	   In such a case you don't want to spend a whole sector for
-	   the environment.
-
-	  CONFIG_ENV_SIZE:
-
-	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
-	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
-	   of this flash sector for the environment. This saves
-	   memory for the RAM copy of the environment.
-
-	   It may also save flash memory if you decide to use this
-	   when your environment is "embedded" within U-Boot code,
-	   since then the remainder of the flash sector could be used
-	   for U-Boot code. It should be pointed out that this is
-	   STRONGLY DISCOURAGED from a robustness point of view:
-	   updating the environment in flash makes it always
-	   necessary to erase the WHOLE sector. If something goes
-	   wrong before the contents has been restored from a copy in
-	   RAM, your target system will be dead.
-
-	  CONFIG_ENV_ADDR_REDUND
-	  CONFIG_ENV_SIZE_REDUND
-
-	   These settings describe a second storage area used to hold
-	   a redundant copy of the environment data, so that there is
-	   a valid backup copy in case there is a power failure during
-	   a "saveenv" operation.
-
-	  BE CAREFUL! Any changes to the flash layout, and some changes to the
-	  source code will make it necessary to adapt <board>/u-boot.lds*
-	  accordingly!
-
-config ENV_IS_IN_MMC
-	bool "Environment in an MMC device"
-	depends on !CHAIN_OF_TRUST
+config ENV_DRV_MMC
+	bool
 	depends on MMC
-	default y if ARCH_EXYNOS4
-	default y if MX6SX || MX7D
-	default y if TEGRA30 || TEGRA124
-	default y if TEGRA_ARMV8_COMMON
-	help
-	  Define this if you have an MMC device which you want to use for the
-	  environment.
-
-	  CONFIG_SYS_MMC_ENV_DEV:
-
-	  Specifies which MMC device the environment is stored in.
-
-	  CONFIG_SYS_MMC_ENV_PART (optional):
-
-	  Specifies which MMC partition the environment is stored in. If not
-	  set, defaults to partition 0, the user area. Common values might be
-	  1 (first MMC boot partition), 2 (second MMC boot partition).
-
-	  CONFIG_ENV_OFFSET:
-	  CONFIG_ENV_SIZE:
-
-	  These two #defines specify the offset and size of the environment
-	  area within the specified MMC device.
-
-	  If offset is positive (the usual case), it is treated as relative to
-	  the start of the MMC partition. If offset is negative, it is treated
-	  as relative to the end of the MMC partition. This can be useful if
-	  your board may be fitted with different MMC devices, which have
-	  different sizes for the MMC partitions, and you always want the
-	  environment placed at the very end of the partition, to leave the
-	  maximum possible space before it, to store other data.
-
-	  These two values are in units of bytes, but must be aligned to an
-	  MMC sector boundary.
-
-	  CONFIG_ENV_OFFSET_REDUND (optional):
-
-	  Specifies a second storage area, of CONFIG_ENV_SIZE size, used to
-	  hold a redundant copy of the environment data. This provides a
-	  valid backup copy in case the other copy is corrupted, e.g. due
-	  to a power failure during a "saveenv" operation.
-
-	  This value may also be positive or negative; this is handled in the
-	  same way as CONFIG_ENV_OFFSET.
-
-	  This value is also in units of bytes, but must also be aligned to
-	  an MMC sector boundary.
-
-	  CONFIG_ENV_SIZE_REDUND (optional):
-
-	  This value need not be set, even when CONFIG_ENV_OFFSET_REDUND is
-	  set. If this value is set, it must be set to the same value as
-	  CONFIG_ENV_SIZE.
-
-config ENV_IS_IN_NAND
-	bool "Environment in a NAND device"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Define this if you have a NAND device which you want to use for the
-	  environment.
-
-	  - CONFIG_ENV_OFFSET:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines specify the offset and size of the environment
-	  area within the first NAND device.  CONFIG_ENV_OFFSET must be
-	  aligned to an erase block boundary.
-
-	  - CONFIG_ENV_OFFSET_REDUND (optional):
-
-	  This setting describes a second storage area of CONFIG_ENV_SIZE
-	  size used to hold a redundant copy of the environment data, so
-	  that there is a valid backup copy in case there is a power failure
-	  during a "saveenv" operation.	 CONFIG_ENV_OFFSET_REDUND must be
-	  aligned to an erase block boundary.
-
-	  - CONFIG_ENV_RANGE (optional):
-
-	  Specifies the length of the region in which the environment
-	  can be written.  This should be a multiple of the NAND device's
-	  block size.  Specifying a range with more erase blocks than
-	  are needed to hold CONFIG_ENV_SIZE allows bad blocks within
-	  the range to be avoided.
-
-	  - CONFIG_ENV_OFFSET_OOB (optional):
-
-	  Enables support for dynamically retrieving the offset of the
-	  environment from block zero's out-of-band data.  The
-	  "nand env.oob" command can be used to record this offset.
-	  Currently, CONFIG_ENV_OFFSET_REDUND is not supported when
-	  using CONFIG_ENV_OFFSET_OOB.
-
-config ENV_IS_IN_NVRAM
-	bool "Environment in a non-volatile RAM"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Define this if you have some non-volatile memory device
-	  (NVRAM, battery buffered SRAM) which you want to use for the
-	  environment.
-
-	  - CONFIG_ENV_ADDR:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines are used to determine the memory area you
-	  want to use for environment. It is assumed that this memory
-	  can just be read and written to, without any special
-	  provision.
-
-config ENV_IS_IN_ONENAND
-	bool "Environment is in OneNAND"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Define this if you want to put your local device's environment in
-	  OneNAND.
-
-	  - CONFIG_ENV_ADDR:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines are used to determine the device range you
-	  want to use for environment. It is assumed that this memory
-	  can just be read and written to, without any special
-	  provision.
-
-config ENV_IS_IN_REMOTE
-	bool "Environment is in remote memory space"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Define this if you have a remote memory space which you
-	  want to use for the local device's environment.
-
-	  - CONFIG_ENV_ADDR:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines specify the address and size of the
-	  environment area within the remote memory space. The
-	  local device can get the environment from remote memory
-	  space by SRIO or PCIE links.
-
-config ENV_IS_IN_SPI_FLASH
-	bool "Environment is in SPI flash"
-	depends on !CHAIN_OF_TRUST && SPI
-	default y if ARMADA_XP
-	default y if INTEL_BAYTRAIL
-	default y if INTEL_BRASWELL
-	default y if INTEL_BROADWELL
-	default y if NORTHBRIDGE_INTEL_IVYBRIDGE
-	default y if INTEL_QUARK
-	default y if INTEL_QUEENSBAY
-	help
-	  Define this if you have a SPI Flash memory device which you
-	  want to use for the environment.
-
-	  - CONFIG_ENV_OFFSET:
-	  - CONFIG_ENV_SIZE:
-
-	  These two #defines specify the offset and size of the
-	  environment area within the SPI Flash. CONFIG_ENV_OFFSET must be
-	  aligned to an erase sector boundary.
-
-	  - CONFIG_ENV_SECT_SIZE:
-
-	  Define the SPI flash's sector size.
-
-	  - CONFIG_ENV_OFFSET_REDUND (optional):
-
-	  This setting describes a second storage area of CONFIG_ENV_SIZE
-	  size used to hold a redundant copy of the environment data, so
-	  that there is a valid backup copy in case there is a power failure
-	  during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
-	  aligned to an erase sector boundary.
-
-config USE_ENV_SPI_BUS
-	bool "SPI flash bus for environment"
-	depends on ENV_IS_IN_SPI_FLASH
-	help
-	  Force the SPI bus for environment.
-	  If not defined, use CONFIG_SF_DEFAULT_BUS.
-
-config ENV_SPI_BUS
-	int "Value of SPI flash bus for environment"
-	depends on USE_ENV_SPI_BUS
-	help
-	  Value the SPI bus and chip select for environment.
-
-config USE_ENV_SPI_CS
-	bool "SPI flash chip select for environment"
-	depends on ENV_IS_IN_SPI_FLASH
-	help
-	  Force the SPI chip select for environment.
-	  If not defined, use CONFIG_SF_DEFAULT_CS.
-
-config ENV_SPI_CS
-	int "Value of SPI flash chip select for environment"
-	depends on USE_ENV_SPI_CS
-	help
-	  Value of the SPI chip select for environment.
-
-config USE_ENV_SPI_MAX_HZ
-	bool "SPI flash max frequency for environment"
-	depends on ENV_IS_IN_SPI_FLASH
-	help
-	  Force the SPI max work clock for environment.
-	  If not defined, use CONFIG_SF_DEFAULT_SPEED.
-
-config ENV_SPI_MAX_HZ
-	int "Value of SPI flash max frequency for environment"
-	depends on USE_ENV_SPI_MAX_HZ
-	help
-	  Value of the SPI max work clock for environment.
-
-config USE_ENV_SPI_MODE
-	bool "SPI flash mode for environment"
-	depends on ENV_IS_IN_SPI_FLASH
-	help
-	  Force the SPI work mode for environment.
-
-config ENV_SPI_MODE
-	hex "Value of SPI flash work mode for environment"
-	depends on USE_ENV_SPI_MODE
-	help
-	  Value of the SPI work mode for environment.
-	  See include/spi.h for value.
-
-config ENV_IS_IN_UBI
-	bool "Environment in a UBI volume"
-	depends on !CHAIN_OF_TRUST
-	help
-	  Define this if you have an UBI volume that you want to use for the
-	  environment.  This has the benefit of wear-leveling the environment
-	  accesses, which is important on NAND.
-
-	  - CONFIG_ENV_UBI_PART:
-
-	  Define this to a string that is the mtd partition containing the UBI.
-
-	  - CONFIG_ENV_UBI_VOLUME:
-
-	  Define this to the name of the volume that you want to store the
-	  environment in.
-
-	  - CONFIG_ENV_UBI_VOLUME_REDUND:
-
-	  Define this to the name of another volume to store a second copy of
-	  the environment in.  This will enable redundant environments in UBI.
-	  It is assumed that both volumes are in the same MTD partition.
-
-config ENV_FAT_INTERFACE
-	string "Name of the block device for the environment"
-	depends on ENV_IS_IN_FAT
-	default "mmc" if ARCH_SUNXI
-	default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
-	help
-	  Define this to a string that is the name of the block device.
-
-config ENV_FAT_DEVICE_AND_PART
-	string "Device and partition for where to store the environemt in FAT"
-	depends on ENV_IS_IN_FAT
-	default "0:1" if TI_COMMON_CMD_OPTIONS
-	default "0:auto" if ARCH_ZYNQMP
-	default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
-	default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
-	default "0" if ARCH_AT91
-	help
-	  Define this to a string to specify the partition of the device. It can
-	  be as following:
-
-	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
-	       - "D:P": device D partition P. Error occurs if device D has no
-	                partition table.
-	       - "D:0": device D.
-	       - "D" or "D:": device D partition 1 if device D has partition
-	                      table, or the whole device D if has no partition
-	                      table.
-	       - "D:auto": first partition in device D with bootable flag set.
-	                   If none, first valid partition in device D. If no
-	                   partition table then means device D.
-
-config ENV_FAT_FILE
-	string "Name of the FAT file to use for the environment"
-	depends on ENV_IS_IN_FAT
-	default "uboot.env"
-	help
-	  It's a string of the FAT file name. This file use to store the
-	  environment.
-
-config ENV_EXT4_INTERFACE
-	string "Name of the block device for the environment"
-	depends on ENV_IS_IN_EXT4
-	help
-	  Define this to a string that is the name of the block device.
-
-config ENV_EXT4_DEVICE_AND_PART
-	string "Device and partition for where to store the environemt in EXT4"
-	depends on ENV_IS_IN_EXT4
-	help
-	  Define this to a string to specify the partition of the device. It can
-	  be as following:
-
-	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
-	       - "D:P": device D partition P. Error occurs if device D has no
-	                partition table.
-	       - "D:0": device D.
-	       - "D" or "D:": device D partition 1 if device D has partition
-	                      table, or the whole device D if has no partition
-	                      table.
-	       - "D:auto": first partition in device D with bootable flag set.
-	                   If none, first valid partition in device D. If no
-	                   partition table then means device D.
-
-config ENV_EXT4_FILE
-	string "Name of the EXT4 file to use for the environment"
-	depends on ENV_IS_IN_EXT4
-	default "uboot.env"
-	help
-	  It's a string of the EXT4 file name. This file use to store the
-	  environment (explicit path to the file)
-
-if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC || ARCH_STM32MP || ARCH_OMAP2PLUS || ARCH_AT91
-
-config ENV_OFFSET
-	hex "Environment Offset"
-	depends on (!ENV_IS_IN_UBI && !ENV_IS_NOWHERE) || ARCH_STM32MP
-	default 0x3f8000 if ARCH_ROCKCHIP
-	default 0x88000 if ARCH_SUNXI
-	default 0xE0000 if ARCH_ZYNQ
-	default 0x1E00000 if ARCH_ZYNQMP
-	default 0 if ARC
-	default 0x140000 if ARCH_AT91
-	default 0x260000 if ARCH_OMAP2PLUS
-	help
-	  Offset from the start of the device (or partition)
-
-config ENV_SIZE
-	hex "Environment Size"
-	default 0x40000 if ENV_IS_IN_SPI_FLASH && ARCH_ZYNQMP
-	default 0x20000 if ARCH_SUNXI || ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
-	default 0x8000 if ARCH_ROCKCHIP || ARCH_ZYNQMP || ARCH_VERSAL
-	default 0x4000 if ARC
-	default 0x1f000
-	help
-	  Size of the environment storage area
-
-config ENV_SECT_SIZE
-	hex "Environment Sector-Size"
-	depends on (!ENV_IS_NOWHERE && (ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_OMAP2PLUS || ARCH_AT91) )|| ARCH_STM32MP
-	default 0x40000 if ARCH_ZYNQMP
-	default 0x20000 if ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
-	help
-	  Size of the sector containing the environment.
-
-config ENV_UBI_PART
-	string "UBI partition name"
-	depends on ENV_IS_IN_UBI
-	help
-	  MTD partition containing the UBI device
-
-config ENV_UBI_VOLUME
-	string "UBI volume name"
-	depends on ENV_IS_IN_UBI
-	help
-	  Name of the volume that you want to store the environment in.
-
-config ENV_UBI_VOLUME_REDUND
-	string "UBI redundant volume name"
-	depends on ENV_IS_IN_UBI
-	help
-	  Name of the redundant volume that you want to store the environment in.
-
-config ENV_UBI_VID_OFFSET
-	int "ubi environment VID offset"
-	depends on ENV_IS_IN_UBI
-	default 0
-	help
-	  UBI VID offset for environment. If 0, no custom VID offset is used.
-
-endif
-
-config USE_DEFAULT_ENV_FILE
-	bool "Create default environment from file"
-	help
-	  Normally, the default environment is automatically generated
-	  based on the settings of various CONFIG_* options, as well
-	  as the CONFIG_EXTRA_ENV_SETTINGS. By selecting this option,
-	  you can instead define the entire default environment in an
-	  external file.
-
-config DEFAULT_ENV_FILE
-	string "Path to default environment file"
-	depends on USE_DEFAULT_ENV_FILE
-	help
-	  The path containing the default environment. The format is
-	  the same as accepted by the mkenvimage tool: lines
-	  containing key=value pairs, blank lines and lines beginning
-	  with # are ignored.
-
-config ENV_VARS_UBOOT_RUNTIME_CONFIG
-	bool "Add run-time information to the environment"
-	help
-	  Enable this in order to add variables describing certain
-	  run-time determined information about the hardware to the
-	  environment.  These will be named board_name, board_rev.
-
-if SPL_ENV_SUPPORT
-config SPL_ENV_IS_NOWHERE
-	bool "SPL Environment is not stored"
-	default y if ENV_IS_NOWHERE
-	help
-	  Similar to ENV_IS_NOWHERE, used for SPL environment.
-
-config SPL_ENV_IS_IN_MMC
-	bool "SPL Environment in an MMC device"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_MMC
-	default y
-	help
-	  Similar to ENV_IS_IN_MMC, used for SPL environment.
-
-config SPL_ENV_IS_IN_FAT
-	bool "SPL Environment is in a FAT filesystem"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_FAT
-	default y
-	help
-	  Similar to ENV_IS_IN_FAT, used for SPL environment.
-
-config SPL_ENV_IS_IN_EXT4
-	bool "SPL Environment is in a EXT4 filesystem"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_EXT4
-	default y
-	help
-	  Similar to ENV_IS_IN_EXT4, used for SPL environment.
-
-config SPL_ENV_IS_IN_NAND
-	bool "SPL Environment in a NAND device"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_NAND
-	default y
-	help
-	  Similar to ENV_IS_IN_NAND, used for SPL environment.
-
-config SPL_ENV_IS_IN_SPI_FLASH
-	bool "SPL Environment is in SPI flash"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_SPI_FLASH
-	default y
-	help
-	  Similar to ENV_IS_IN_SPI_FLASH, used for SPL environment.
-
-config SPL_ENV_IS_IN_FLASH
-	bool "SPL Environment in flash memory"
-	depends on !SPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_FLASH
-	default y
-	help
-	  Similar to ENV_IS_IN_FLASH, used for SPL environment.
-
-endif
-
-if TPL_ENV_SUPPORT
-
-config TPL_ENV_IS_NOWHERE
-	bool "TPL Environment is not stored"
-	default y if ENV_IS_NOWHERE
-	help
-	  Similar to ENV_IS_NOWHERE, used for TPL environment.
 
-config TPL_ENV_IS_IN_MMC
-	bool "TPL Environment in an MMC device"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_MMC
-	default y
-	help
-	  Similar to ENV_IS_IN_MMC, used for TPL environment.
+config ENV_DRV_NAND
+	bool
 
-config TPL_ENV_IS_IN_FAT
-	bool "TPL Environment is in a FAT filesystem"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_FAT
-	default y
-	help
-	  Similar to ENV_IS_IN_FAT, used for TPL environment.
+config ENV_DRV_NVRAM
+	bool
 
-config TPL_ENV_IS_IN_EXT4
-	bool "TPL Environment is in a EXT4 filesystem"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_EXT4
-	default y
-	help
-	  Similar to ENV_IS_IN_EXT4, used for TPL environment.
+config ENV_DRV_ONENAND
+	bool
 
-config TPL_ENV_IS_IN_NAND
-	bool "TPL Environment in a NAND device"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_NAND
-	default y
-	help
-	  Similar to ENV_IS_IN_NAND, used for TPL environment.
+config ENV_DRV_REMOTE
+	bool
 
-config TPL_ENV_IS_IN_SPI_FLASH
-	bool "TPL Environment is in SPI flash"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_SPI_FLASH
-	default y
-	help
-	  Similar to ENV_IS_IN_SPI_FLASH, used for TPL environment.
+config ENV_DRV_SPI_FLASH
+	bool
 
-config TPL_ENV_IS_IN_FLASH
-	bool "TPL Environment in flash memory"
-	depends on !TPL_ENV_IS_NOWHERE
-	depends on ENV_IS_IN_FLASH
-	default y
-	help
-	  Similar to ENV_IS_IN_FLASH, used for TPL environment.
+config ENV_DRV_UBI
+	bool
 
-endif
+source "env/Kconfig.uboot"
 
 endmenu
diff --git a/env/Makefile b/env/Makefile
index 90144d6caf34..ee37cc822024 100644
--- a/env/Makefile
+++ b/env/Makefile
@@ -9,16 +9,16 @@ ifndef CONFIG_SPL_BUILD
 obj-y += attr.o
 obj-y += callback.o
 obj-y += flags.o
-obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
+obj-$(CONFIG_ENV_DRV_EEPROM) += eeprom.o
 extra-$(CONFIG_ENV_IS_EMBEDDED) += embedded.o
-obj-$(CONFIG_ENV_IS_IN_EEPROM) += embedded.o
-extra-$(CONFIG_ENV_IS_IN_FLASH) += embedded.o
-obj-$(CONFIG_ENV_IS_IN_NVRAM) += embedded.o
-obj-$(CONFIG_ENV_IS_IN_NVRAM) += nvram.o
-obj-$(CONFIG_ENV_IS_IN_ONENAND) += onenand.o
-obj-$(CONFIG_ENV_IS_IN_SATA) += sata.o
-obj-$(CONFIG_ENV_IS_IN_REMOTE) += remote.o
-obj-$(CONFIG_ENV_IS_IN_UBI) += ubi.o
+obj-$(CONFIG_ENV_DRV_EEPROM) += embedded.o
+extra-$(CONFIG_ENV_DRV_FLASH) += embedded.o
+obj-$(CONFIG_ENV_DRV_NVRAM) += embedded.o
+obj-$(CONFIG_ENV_DRV_NVRAM) += nvram.o
+obj-$(CONFIG_ENV_DRV_ONENAND) += onenand.o
+obj-$(CONFIG_ENV_DRV_SATA) += sata.o
+obj-$(CONFIG_ENV_DRV_REMOTE) += remote.o
+obj-$(CONFIG_ENV_DRV_UBI) += ubi.o
 else
 obj-$(CONFIG_$(SPL_TPL_)ENV_SUPPORT) += attr.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_SUPPORT) += flags.o
@@ -26,11 +26,11 @@ obj-$(CONFIG_$(SPL_TPL_)ENV_SUPPORT) += callback.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_NOWHERE) += nowhere.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_MMC) += mmc.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_FAT) += fat.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_EXT4) += ext4.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_NAND) += nand.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_SPI_FLASH) += sf.o
-obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_FLASH) += flash.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_MMC) += mmc.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_FAT) += fat.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_EXT4) += ext4.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_NAND) += nand.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_SPI_FLASH) += sf.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_DRV_FLASH) += flash.o
 
 CFLAGS_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)
diff --git a/env/callback.c b/env/callback.c
index f0904cfdc535..4c7b0103f286 100644
--- a/env/callback.c
+++ b/env/callback.c
@@ -15,7 +15,8 @@ DECLARE_GLOBAL_DATA_PTR;
 /*
  * Look up a callback function pointer by name
  */
-static struct env_clbk_tbl *find_env_callback(const char *name)
+static struct env_clbk_tbl *find_env_callback(struct env_context *ctx,
+					      const char *name)
 {
 	struct env_clbk_tbl *clbkp;
 	int i;
@@ -28,13 +29,18 @@ static struct env_clbk_tbl *find_env_callback(const char *name)
 	for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
 	     i < num_callbacks;
 	     i++, clbkp++) {
-		if (strcmp(name, clbkp->name) == 0)
+		if (!strcmp(name, clbkp->name))
 			return clbkp;
 	}
 
 	return NULL;
 }
 
+/*
+ * TODO
+ * Should we provide per-context callback list,
+ * either for ".callbacks"(default) or "callbacks"(user defined)?
+ */
 static int first_call = 1;
 static const char *callback_list;
 
@@ -51,7 +57,7 @@ void env_callback_init(struct env_entry *var_entry)
 	int ret = 1;
 
 	if (first_call) {
-		callback_list = env_get(ENV_CALLBACK_VAR);
+		callback_list = env_get(ctx_uboot, ENV_CALLBACK_VAR);
 		first_call = 0;
 	}
 
@@ -66,7 +72,7 @@ void env_callback_init(struct env_entry *var_entry)
 
 	/* if an association was found, set the callback pointer */
 	if (!ret && strlen(callback_name)) {
-		clbkp = find_env_callback(callback_name);
+		clbkp = find_env_callback(var_entry->ctx, callback_name);
 		if (clbkp != NULL)
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 			var_entry->callback = clbkp->callback + gd->reloc_off;
@@ -92,13 +98,15 @@ static int clear_callback(struct env_entry *entry)
  */
 static int set_callback(const char *name, const char *value, void *priv)
 {
+	struct env_context *ctx = priv;
 	struct env_entry e, *ep;
 	struct env_clbk_tbl *clbkp;
 
 	e.key	= name;
+	e.ctx	= ctx;
 	e.data	= NULL;
 	e.callback = NULL;
-	hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
+	hsearch_r(e, ENV_FIND, &ep, ctx->htab, 0);
 
 	/* does the env variable actually exist? */
 	if (ep != NULL) {
@@ -107,7 +115,7 @@ static int set_callback(const char *name, const char *value, void *priv)
 			ep->callback = NULL;
 		else {
 			/* assign the requested callback */
-			clbkp = find_env_callback(value);
+			clbkp = find_env_callback(ctx, value);
 			if (clbkp != NULL)
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 				ep->callback = clbkp->callback + gd->reloc_off;
@@ -121,15 +129,21 @@ static int set_callback(const char *name, const char *value, void *priv)
 }
 
 static int on_callbacks(const char *name, const char *value, enum env_op op,
-	int flags)
+			int flags)
 {
-	/* remove all callbacks */
-	hwalk_r(&env_htab, clear_callback);
+	struct env_context *ctx;
+	int i;
 
-	/* configure any static callback bindings */
-	env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback, NULL);
-	/* configure any dynamic callback bindings */
-	env_attr_walk(value, set_callback, NULL);
+	for (i = 0, ctx = U_BOOT_ENV_CTX_START; i < U_BOOT_ENV_CTX_COUNT;
+	     i++, ctx++) {
+		/* remove all callbacks */
+		hwalk_r(ctx->htab, clear_callback);
+
+		/* configure any static callback bindings */
+		env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback, ctx);
+		/* configure any dynamic callback bindings */
+		env_attr_walk(value, set_callback, ctx);
+	}
 
 	return 0;
 }
diff --git a/env/common.c b/env/common.c
index 3fb60509dd85..6cf481c36d8f 100644
--- a/env/common.c
+++ b/env/common.c
@@ -18,25 +18,13 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/************************************************************************
- * Default settings to be used when no valid environment is found
- */
-#include <env_default.h>
-
-struct hsearch_data env_htab = {
-#if CONFIG_IS_ENABLED(ENV_SUPPORT)
-	/* defined in flags.c, only compile with ENV_SUPPORT */
-	.change_ok = env_flags_validate,
-#endif
-};
-
 /*
  * Read an environment variable as a boolean
  * Return -1 if variable does not exist (default to true)
  */
 int env_get_yesno(const char *var)
 {
-	char *s = env_get(var);
+	char *s = env_get(ctx_uboot, var);
 
 	if (s == NULL)
 		return -1;
@@ -44,109 +32,124 @@ int env_get_yesno(const char *var)
 		1 : 0;
 }
 
-/*
- * Look up the variable from the default environment
- */
-char *env_get_default(const char *name)
+char *env_get_default(struct env_context *ctx, const char *name)
 {
-	char *ret_val;
-	unsigned long really_valid = gd->env_valid;
-	unsigned long real_gd_flags = gd->flags;
-
-	/* Pretend that the image is bad. */
-	gd->flags &= ~GD_FLG_ENV_READY;
-	gd->env_valid = ENV_INVALID;
-	ret_val = env_get(name);
-	gd->env_valid = really_valid;
-	gd->flags = real_gd_flags;
-	return ret_val;
+	if (ctx->get_default)
+		return ctx->get_default(ctx, name);
+
+	/* no default action */
+	return NULL;
 }
 
-void env_set_default(const char *s, int flags)
+void env_set_default(struct env_context *ctx, const char *s, int flags)
 {
-	if (sizeof(default_environment) > ENV_SIZE) {
-		puts("*** Error - default environment is too large\n\n");
-		return;
-	}
+	if (ctx->set_default)
+		return ctx->set_default(ctx, s, flags);
 
-	if (s) {
-		if ((flags & H_INTERACTIVE) == 0) {
-			printf("*** Warning - %s, "
-				"using default environment\n\n", s);
-		} else {
-			puts(s);
-		}
-	} else {
-		debug("Using default environment\n");
-	}
+	/* no default action */
+}
 
-	if (himport_r(&env_htab, (char *)default_environment,
-			sizeof(default_environment), '\0', flags, 0,
-			0, NULL) == 0)
-		pr_err("## Error: Environment import failed: errno = %d\n",
-		       errno);
+/* [re]set individual variables to their value in the default environment */
+int env_set_default_vars(struct env_context *ctx, int nvars,
+			 char * const vars[], int flags)
+{
+	if (ctx->set_default_vars)
+		return ctx->set_default_vars(ctx, nvars, vars, flags);
 
-	gd->flags |= GD_FLG_ENV_READY;
-	gd->flags |= GD_FLG_ENV_DEFAULT;
+	/* no default action */
+	return 1;
 }
 
+void env_set_ready(struct env_context *ctx)
+{
+	if (ctx->set_ready)
+		ctx->set_ready(ctx);
+	else
+		/* TODO: define another macro? */
+		ctx->flags |= GD_FLG_ENV_READY;
+}
 
-/* [re]set individual variables to their value in the default environment */
-int env_set_default_vars(int nvars, char * const vars[], int flags)
+bool env_is_ready(struct env_context *ctx)
+{
+	if (ctx->is_ready)
+		return ctx->is_ready(ctx);
+
+	return ctx->flags & GD_FLG_ENV_READY;
+}
+
+void env_set_valid(struct env_context *ctx, enum env_valid valid)
+{
+	if (ctx->set_ready)
+		ctx->set_valid(ctx, valid);
+	else
+		ctx->valid = valid;
+}
+
+enum env_valid env_get_valid(struct env_context *ctx)
+{
+	if (ctx->get_valid)
+		return ctx->get_valid(ctx);
+
+	return ctx->valid;
+}
+
+void env_set_env_addr(struct env_context *ctx, ulong env_addr)
+{
+	if (ctx->set_addr)
+		ctx->set_addr(ctx, env_addr);
+}
+
+ulong env_get_env_addr(struct env_context *ctx)
 {
-	/*
-	 * Special use-case: import from default environment
-	 * (and use \0 as a separator)
-	 */
-	flags |= H_NOCLEAR;
-	return himport_r(&env_htab, (const char *)default_environment,
-				sizeof(default_environment), '\0',
-				flags, 0, nvars, vars);
+	if (ctx->get_addr)
+		return ctx->get_addr(ctx);
+
+	return 0; /* FIXME: invalid value */
 }
 
 /*
  * Check if CRC is valid and (if yes) import the environment.
  * Note that "buf" may or may not be aligned.
  */
-int env_import(const char *buf, int check)
+int env_import(struct env_context *ctx, const char *buf, int check)
 {
-	env_t *ep = (env_t *)buf;
+	struct environment_hdr *ep = (struct environment_hdr *)buf;
 
 	if (check) {
 		uint32_t crc;
 
 		memcpy(&crc, &ep->crc, sizeof(crc));
 
-		if (crc32(0, ep->data, ENV_SIZE) != crc) {
-			env_set_default("bad CRC", 0);
+		if (crc32(0, ep->data, ctx->env_size) != crc) {
+			env_set_default(ctx, "bad CRC", 0);
 			return -ENOMSG; /* needed for env_load() */
 		}
 	}
 
-	if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
-			0, NULL)) {
-		gd->flags |= GD_FLG_ENV_READY;
+	ctx->htab->ctx = ctx; /* FIXME: why needed here? */
+	if (himport_r(ctx->htab, (char *)ep->data, ctx->env_size, '\0', 0, 0,
+		      0, NULL)) {
+		env_set_ready(ctx);
 		return 0;
 	}
 
 	pr_err("Cannot import environment: errno = %d\n", errno);
 
-	env_set_default("import failed", 0);
+	env_set_default(ctx, "import failed", 0);
 
 	return -EIO;
 }
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-static unsigned char env_flags;
-
-int env_import_redund(const char *buf1, int buf1_read_fail,
+int env_import_redund(struct env_context *ctx,
+		      const char *buf1, int buf1_read_fail,
 		      const char *buf2, int buf2_read_fail)
 {
 	int crc1_ok, crc2_ok;
-	env_t *ep, *tmp_env1, *tmp_env2;
+	struct environment_hdr *ep, *tmp_env1, *tmp_env2;
 
-	tmp_env1 = (env_t *)buf1;
-	tmp_env2 = (env_t *)buf2;
+	tmp_env1 = (struct environment_hdr *)buf1;
+	tmp_env2 = (struct environment_hdr *)buf2;
 
 	if (buf1_read_fail && buf2_read_fail) {
 		puts("*** Error - No Valid Environment Area found\n");
@@ -156,69 +159,70 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
 	}
 
 	if (buf1_read_fail && buf2_read_fail) {
-		env_set_default("bad env area", 0);
+		env_set_default(ctx, "bad env area", 0);
 		return -EIO;
 	} else if (!buf1_read_fail && buf2_read_fail) {
-		gd->env_valid = ENV_VALID;
-		return env_import((char *)tmp_env1, 1);
+		env_set_valid(ctx, ENV_VALID);
+		return env_import(ctx, (char *)tmp_env1, 1);
 	} else if (buf1_read_fail && !buf2_read_fail) {
-		gd->env_valid = ENV_REDUND;
-		return env_import((char *)tmp_env2, 1);
+		env_set_valid(ctx, ENV_REDUND);
+		return env_import(ctx, (char *)tmp_env2, 1);
 	}
 
-	crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) ==
+	crc1_ok = crc32(0, tmp_env1->data, ctx->env_size) ==
 			tmp_env1->crc;
-	crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) ==
+	crc2_ok = crc32(0, tmp_env2->data, ctx->env_size) ==
 			tmp_env2->crc;
 
 	if (!crc1_ok && !crc2_ok) {
-		env_set_default("bad CRC", 0);
+		env_set_default(ctx, "bad CRC", 0);
 		return -ENOMSG; /* needed for env_load() */
 	} else if (crc1_ok && !crc2_ok) {
-		gd->env_valid = ENV_VALID;
+		env_set_valid(ctx, ENV_VALID);
 	} else if (!crc1_ok && crc2_ok) {
-		gd->env_valid = ENV_REDUND;
+		env_set_valid(ctx, ENV_REDUND);
 	} else {
 		/* both ok - check serial */
 		if (tmp_env1->flags == 255 && tmp_env2->flags == 0)
-			gd->env_valid = ENV_REDUND;
+			env_set_valid(ctx, ENV_REDUND);
 		else if (tmp_env2->flags == 255 && tmp_env1->flags == 0)
-			gd->env_valid = ENV_VALID;
+			env_set_valid(ctx, ENV_VALID);
 		else if (tmp_env1->flags > tmp_env2->flags)
-			gd->env_valid = ENV_VALID;
+			env_set_valid(ctx, ENV_VALID);
 		else if (tmp_env2->flags > tmp_env1->flags)
-			gd->env_valid = ENV_REDUND;
+			env_set_valid(ctx, ENV_REDUND);
 		else /* flags are equal - almost impossible */
-			gd->env_valid = ENV_VALID;
+			env_set_valid(ctx, ENV_VALID);
 	}
 
-	if (gd->env_valid == ENV_VALID)
+	if (env_get_valid(ctx) == ENV_VALID)
 		ep = tmp_env1;
 	else
 		ep = tmp_env2;
 
-	env_flags = ep->flags;
-	return env_import((char *)ep, 0);
+	/* FIXME: functionize? */
+	ctx->env_flags = ep->flags;
+	return env_import(ctx, (char *)ep, 0);
 }
 #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
 
 /* Export the environment and generate CRC for it. */
-int env_export(env_t *env_out)
+int env_export(struct env_context *ctx, struct environment_hdr *env_out)
 {
 	char *res;
 	ssize_t	len;
 
 	res = (char *)env_out->data;
-	len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
+	len = hexport_r(ctx->htab, '\0', 0, &res, ctx->env_size, 0, NULL);
 	if (len < 0) {
 		pr_err("Cannot export environment: errno = %d\n", errno);
 		return 1;
 	}
 
-	env_out->crc = crc32(0, env_out->data, ENV_SIZE);
+	env_out->crc = crc32(0, env_out->data, ctx->env_size);
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-	env_out->flags = ++env_flags; /* increase the serial */
+	env_out->flags = ++ctx->env_flags; /* increase the serial */
 #endif
 
 	return 0;
@@ -226,27 +230,60 @@ int env_export(env_t *env_out)
 
 void env_relocate(void)
 {
+	struct env_context *ctx;
+	int i;
+
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 	env_reloc();
 	env_fix_drivers();
 
-	if (env_htab.change_ok)
-		env_htab.change_ok += gd->reloc_off;
-#endif
-	if (gd->env_valid == ENV_INVALID) {
-#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
-		/* Environment not changable */
-		env_set_default(NULL, 0);
-#else
-		bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
-		env_set_default("bad CRC", 0);
-#endif
-	} else {
-		env_load();
+	for (i = 0; i < U_BOOT_ENV_CTX_COUNT; i++) {
+		if (ctx->htab.change_ok)
+			ctx->htab.change_ok += gd->reloc_off;
+
+		/*
+		 * TODO:
+		 * Some of functions may not be called after relocation
+		 */
+		if (ctx->has_inited)
+			ctx->has_inited += gd->reloc_off;
+		if (ctx->set_inited)
+			ctx->set_inited += gd->reloc_off;
+		if (ctx->get_location)
+			ctx->get_location += gd->reloc_off;
+		if (ctx->get_char)
+			ctx->get_char += gd->reloc_off;
+		if (ctx->get_char_default)
+			ctx->get_char_default += gd->reloc_off;
+		if (ctx->get_char_spec)
+			ctx->get_char_spec += gd->reloc_off;
+		if (ctx->init)
+			ctx->init += gd->reloc_off;
+		if (ctx->get_default)
+			ctx->get_default += gd->reloc_off;
+		if (ctx->set_default)
+			ctx->set_default += gd->reloc_off;
+		if (ctx->set_default_vars)
+			ctx->set_default_vars += gd->reloc_off;
+		if (ctx->set_ready)
+			ctx->set_ready += gd->reloc_off;
+		if (ctx->set_valid)
+			ctx->set_valid += gd->reloc_off;
+		if (ctx->get_valid)
+			ctx->get_valid += gd->reloc_off;
 	}
+#endif
+
+	for (i = 0, ctx = U_BOOT_ENV_CTX_START; i < U_BOOT_ENV_CTX_COUNT;
+	     i++, ctx++)
+		if (ctx->post_relocate)
+			ctx->post_relocate(ctx);
 }
 
 #ifdef CONFIG_AUTO_COMPLETE
+/*
+ * TODO: Currently U-Boot environment context only
+ */
 int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf,
 		 bool dollar_comp)
 {
diff --git a/env/env.c b/env/env.c
index 9237bb9c742a..b47e97972b50 100644
--- a/env/env.c
+++ b/env/env.c
@@ -49,51 +49,54 @@ static struct env_driver *_env_driver_lookup(enum env_location loc)
 	return NULL;
 }
 
-static enum env_location env_locations[] = {
-#ifdef CONFIG_ENV_IS_IN_EEPROM
+enum env_location env_locations[] = {
+#ifdef CONFIG_ENV_DRV_EEPROM
 	ENVL_EEPROM,
 #endif
-#ifdef CONFIG_ENV_IS_IN_EXT4
+#ifdef CONFIG_ENV_DRV_EXT4
 	ENVL_EXT4,
 #endif
-#ifdef CONFIG_ENV_IS_IN_FAT
+#ifdef CONFIG_ENV_DRV_FAT
 	ENVL_FAT,
 #endif
-#ifdef CONFIG_ENV_IS_IN_FLASH
+#ifdef CONFIG_ENV_DRV_FLASH
 	ENVL_FLASH,
 #endif
-#ifdef CONFIG_ENV_IS_IN_MMC
+#ifdef CONFIG_ENV_DRV_MMC
 	ENVL_MMC,
 #endif
-#ifdef CONFIG_ENV_IS_IN_NAND
+#ifdef CONFIG_ENV_DRV_NAND
 	ENVL_NAND,
 #endif
-#ifdef CONFIG_ENV_IS_IN_NVRAM
+#ifdef CONFIG_ENV_DRV_NVRAM
 	ENVL_NVRAM,
 #endif
-#ifdef CONFIG_ENV_IS_IN_REMOTE
+#ifdef CONFIG_ENV_DRV_REMOTE
 	ENVL_REMOTE,
 #endif
-#ifdef CONFIG_ENV_IS_IN_SATA
+#ifdef CONFIG_ENV_DRV_SATA
 	ENVL_ESATA,
 #endif
-#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
+#ifdef CONFIG_ENV_DRV_SPI_FLASH
 	ENVL_SPI_FLASH,
 #endif
-#ifdef CONFIG_ENV_IS_IN_UBI
+#ifdef CONFIG_ENV_DRV_UBI
 	ENVL_UBI,
 #endif
-#ifdef CONFIG_ENV_IS_NOWHERE
+#ifdef CONFIG_ENV_DRV_NONE
 	ENVL_NOWHERE,
 #endif
 };
 
-static bool env_has_inited(enum env_location location)
+static bool env_has_inited(struct env_context *ctx, enum env_location location)
 {
-	return gd->env_has_init & BIT(location);
+	if (ctx->has_inited)
+		return ctx->has_inited(ctx, location);
+
+	return ctx->has_init & BIT(location);
 }
 
-static void env_set_inited(enum env_location location)
+static void env_set_inited(struct env_context *ctx, enum env_location location)
 {
 	/*
 	 * We're using a 32-bits bitmask stored in gd (env_has_init)
@@ -102,11 +105,25 @@ static void env_set_inited(enum env_location location)
 	 */
 	BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG);
 
-	gd->env_has_init |= BIT(location);
+	if (ctx->set_inited) {
+		ctx->set_inited(ctx, location);
+		return;
+	}
+
+	ctx->has_init |= BIT(location);
+}
+
+static int env_get_load_prio(struct env_context *ctx)
+{
+	if (ctx->get_load_prio)
+		return ctx->get_load_prio(ctx);
+
+	return ctx->load_prio;
 }
 
 /**
  * env_get_location() - Returns the best env location for a board
+ * @ctx: pointer to environment context
  * @op: operations performed on the environment
  * @prio: priority between the multiple environments, 0 being the
  *        highest priority
@@ -123,19 +140,23 @@ static void env_set_inited(enum env_location location)
  * Returns:
  * an enum env_location value on success, a negative error code otherwise
  */
-__weak enum env_location env_get_location(enum env_operation op, int prio)
+__weak enum env_location env_get_location(struct env_context *ctx,
+					  enum env_operation op, int prio)
 {
 	if (prio >= ARRAY_SIZE(env_locations))
 		return ENVL_UNKNOWN;
 
-	gd->env_load_prio = prio;
+	if (ctx->get_location)
+		return ctx->get_location(ctx, op, prio);
+
+	ctx->load_prio = prio;
 
 	return env_locations[prio];
 }
 
-
 /**
  * env_driver_lookup() - Finds the most suited environment location
+ * @ctx: pointer to environment context
  * @op: operations performed on the environment
  * @prio: priority between the multiple environments, 0 being the
  *        highest priority
@@ -146,9 +167,10 @@ __weak enum env_location env_get_location(enum env_operation op, int prio)
  * Returns:
  * NULL on error, a pointer to a struct env_driver otherwise
  */
-static struct env_driver *env_driver_lookup(enum env_operation op, int prio)
+struct env_driver *env_driver_lookup(struct env_context *ctx,
+				     enum env_operation op, int prio)
 {
-	enum env_location loc = env_get_location(op, prio);
+	enum env_location loc = env_get_location(ctx, op, prio);
 	struct env_driver *drv;
 
 	if (loc == ENVL_UNKNOWN)
@@ -164,32 +186,43 @@ static struct env_driver *env_driver_lookup(enum env_operation op, int prio)
 	return drv;
 }
 
-__weak int env_get_char_spec(int index)
+__weak int env_get_char_spec(struct env_context *ctx, int index)
 {
-	return *(uchar *)(gd->env_addr + index);
+	if (ctx->get_char_spec)
+		return ctx->get_char_spec(ctx, index);
+
+	return 0; /* FIXME: invalid value */
 }
 
-int env_get_char(int index)
+int env_get_char(struct env_context *ctx, int index)
 {
-	if (gd->env_valid == ENV_INVALID)
-		return default_environment[index];
-	else
-		return env_get_char_spec(index);
+	if (ctx->get_char)
+		return ctx->get_char(ctx, index);
+
+	if (ctx->get_valid(ctx) == ENV_INVALID) {
+		if (ctx->get_char_default)
+			return ctx->get_char_default(ctx, index);
+
+		return 0; /* FIXME: invalid value */
+	} else {
+		return env_get_char_spec(ctx, index);
+	}
 }
 
-int env_load(void)
+int env_load(struct env_context *ctx)
 {
 	struct env_driver *drv;
 	int best_prio = -1;
 	int prio;
 
-	for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
+	for (prio = 0; (drv = env_driver_lookup(ctx, ENVOP_LOAD, prio));
+	     prio++) {
 		int ret;
 
 		if (!drv->load)
 			continue;
 
-		if (!env_has_inited(drv->location))
+		if (!env_has_inited(ctx, drv->location))
 			continue;
 
 		printf("Loading Environment from %s... ", drv->name);
@@ -198,7 +231,7 @@ int env_load(void)
 		 * drv->load() in some underlying API, and it must be exactly
 		 * one message.
 		 */
-		ret = drv->load();
+		ret = drv->load(ctx);
 		if (!ret) {
 			printf("OK\n");
 			return 0;
@@ -224,27 +257,27 @@ int env_load(void)
 		debug("Selecting environment with bad CRC\n");
 	else
 		best_prio = 0;
-	env_get_location(ENVOP_LOAD, best_prio);
+	env_get_location(ctx, ENVOP_LOAD, best_prio);
 
 	return -ENODEV;
 }
 
-int env_save(void)
+int env_save(struct env_context *ctx)
 {
 	struct env_driver *drv;
 
-	drv = env_driver_lookup(ENVOP_SAVE, gd->env_load_prio);
+	drv = env_driver_lookup(ctx, ENVOP_SAVE, env_get_load_prio(ctx));
 	if (drv) {
 		int ret;
 
 		if (!drv->save)
 			return -ENODEV;
 
-		if (!env_has_inited(drv->location))
+		if (!env_has_inited(ctx, drv->location))
 			return -ENODEV;
 
 		printf("Saving Environment to %s... ", drv->name);
-		ret = drv->save();
+		ret = drv->save(ctx);
 		if (ret)
 			printf("Failed (%d)\n", ret);
 		else
@@ -257,22 +290,22 @@ int env_save(void)
 	return -ENODEV;
 }
 
-int env_erase(void)
+int env_erase(struct env_context *ctx)
 {
 	struct env_driver *drv;
 
-	drv = env_driver_lookup(ENVOP_ERASE, gd->env_load_prio);
+	drv = env_driver_lookup(ctx, ENVOP_ERASE, env_get_load_prio(ctx));
 	if (drv) {
 		int ret;
 
 		if (!drv->erase)
 			return -ENODEV;
 
-		if (!env_has_inited(drv->location))
+		if (!env_has_inited(ctx, drv->location))
 			return -ENODEV;
 
 		printf("Erasing Environment on %s... ", drv->name);
-		ret = drv->erase();
+		ret = drv->erase(ctx);
 		if (ret)
 			printf("Failed (%d)\n", ret);
 		else
@@ -285,29 +318,46 @@ int env_erase(void)
 	return -ENODEV;
 }
 
-int env_init(void)
+int env_ctx_init(struct env_context *ctx)
 {
 	struct env_driver *drv;
 	int ret = -ENOENT;
-	int prio;
+	int prio, drv_count;
 
-	for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
-		if (!drv->init || !(ret = drv->init()))
-			env_set_inited(drv->location);
+	ctx->htab->ctx = ctx;
+	ctx->env_id = 1;
+	env_set_valid(ctx, ENV_INVALID);
+
+	if (ctx->init)
+		return ctx->init(ctx);
+
+	for (prio = 0, drv_count = 0;
+	     (drv = env_driver_lookup(ctx, ENVOP_INIT, prio)); prio++) {
+		if (!drv->init || !(ret = drv->init(ctx))) {
+			env_set_inited(ctx, drv->location);
+			drv_count++;
+		}
 
 		debug("%s: Environment %s init done (ret=%d)\n", __func__,
 		      drv->name, ret);
 	}
 
-	if (!prio)
+	if (!drv_count)
 		return -ENODEV;
 
-	if (ret == -ENOENT) {
-		gd->env_addr = (ulong)&default_environment[0];
-		gd->env_valid = ENV_VALID;
-
-		return 0;
+	/* Dummy table creation, or hcreate_r()? */
+	if (!himport_r(ctx->htab, NULL, 0, 0, 0, 0, 0, NULL)) {
+		debug("%s: Creating entry tables failed (ret=%d)\n", __func__,
+		      errno);
+		return errno;
 	}
 
-	return ret;
+	env_set_ready(ctx);
+
+	return 0;
+}
+
+int env_init(void)
+{
+	return env_ctx_init(ctx_uboot);
 }
diff --git a/env/flags.c b/env/flags.c
index 418d6cc7425a..334bb08c88db 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -308,7 +308,7 @@ static inline int env_flags_lookup(const char *flags_list, const char *name,
  */
 enum env_flags_vartype env_flags_get_type(const char *name)
 {
-	const char *flags_list = env_get(ENV_FLAGS_VAR);
+	const char *flags_list = env_get(ctx_uboot, ENV_FLAGS_VAR);
 	char flags[ENV_FLAGS_ATTR_MAX_LEN + 1];
 
 	if (env_flags_lookup(flags_list, name, flags))
@@ -325,7 +325,7 @@ enum env_flags_vartype env_flags_get_type(const char *name)
  */
 enum env_flags_varaccess env_flags_get_varaccess(const char *name)
 {
-	const char *flags_list = env_get(ENV_FLAGS_VAR);
+	const char *flags_list = env_get(ctx_uboot, ENV_FLAGS_VAR);
 	char flags[ENV_FLAGS_ATTR_MAX_LEN + 1];
 
 	if (env_flags_lookup(flags_list, name, flags))
@@ -411,6 +411,11 @@ static int env_parse_flags_to_bin(const char *flags)
 	return binflags;
 }
 
+/*
+ * TODO
+ * Should we provide per-context flags list,
+ * either for ".flags"(default) or "flags"(user defined)?
+ */
 static int first_call = 1;
 static const char *flags_list;
 
@@ -426,7 +431,7 @@ void env_flags_init(struct env_entry *var_entry)
 	int ret = 1;
 
 	if (first_call) {
-		flags_list = env_get(ENV_FLAGS_VAR);
+		flags_list = env_get(ctx_uboot, ENV_FLAGS_VAR);
 		first_call = 0;
 	}
 	/* look in the ".flags" and static for a reference to this variable */
@@ -453,12 +458,14 @@ static int clear_flags(struct env_entry *entry)
  */
 static int set_flags(const char *name, const char *value, void *priv)
 {
+	struct env_context *ctx = priv;
 	struct env_entry e, *ep;
 
 	e.key	= name;
+	e.ctx	= ctx;
 	e.data	= NULL;
 	e.callback = NULL;
-	hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
+	hsearch_r(e, ENV_FIND, &ep, ctx->htab, 0);
 
 	/* does the env variable actually exist? */
 	if (ep != NULL) {
@@ -476,13 +483,19 @@ static int set_flags(const char *name, const char *value, void *priv)
 static int on_flags(const char *name, const char *value, enum env_op op,
 	int flags)
 {
-	/* remove all flags */
-	hwalk_r(&env_htab, clear_flags);
+	struct env_context *ctx;
+	int i;
 
-	/* configure any static flags */
-	env_attr_walk(ENV_FLAGS_LIST_STATIC, set_flags, NULL);
-	/* configure any dynamic flags */
-	env_attr_walk(value, set_flags, NULL);
+	for (i = 0, ctx = U_BOOT_ENV_CTX_START; i < U_BOOT_ENV_CTX_COUNT;
+	     i++, ctx++) {
+		/* remove all flags */
+		hwalk_r(ctx->htab, clear_flags);
+
+		/* configure any static flags */
+		env_attr_walk(ENV_FLAGS_LIST_STATIC, set_flags, ctx);
+		/* configure any dynamic flags */
+		env_attr_walk(value, set_flags, ctx);
+	}
 
 	return 0;
 }
@@ -541,7 +554,7 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
 			return 1;
 		} else if (item->flags &
 		    ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR) {
-			const char *defval = env_get_default(name);
+			const char *defval = env_get_default(item->ctx, name);
 
 			if (defval == NULL)
 				defval = "";
diff --git a/include/_exports.h b/include/_exports.h
index 0dee05f077a6..8e072668d198 100644
--- a/include/_exports.h
+++ b/include/_exports.h
@@ -31,8 +31,10 @@
 	EXPORT_FUNC(vprintf, int, vprintf, const char *, va_list)
 	EXPORT_FUNC(do_reset, int, do_reset, cmd_tbl_t *,
 		    int , int , char * const [])
-	EXPORT_FUNC(env_get, char  *, env_get, const char*)
-	EXPORT_FUNC(env_set, int, env_set, const char *, const char *)
+	EXPORT_FUNC(env_get, char  *, env_get, struct env_context *,
+		    const char*)
+	EXPORT_FUNC(env_set, int, env_set, struct env_context *, const char *,
+		    const char *)
 	EXPORT_FUNC(simple_strtoul, unsigned long, simple_strtoul,
 		    const char *, char **, unsigned int)
 	EXPORT_FUNC(strict_strtoul, int, strict_strtoul,
diff --git a/include/common.h b/include/common.h
index d8f302ea92f0..cdc0bf7042c2 100644
--- a/include/common.h
+++ b/include/common.h
@@ -46,6 +46,8 @@ typedef volatile unsigned char	vu_char;
 
 #include <log.h>
 
+struct env_context;
+
 typedef void (interrupt_handler_t)(void *);
 
 #include <asm/u-boot.h> /* boot information for Linux kernel */
@@ -340,9 +342,9 @@ int	serial_printf (const char *fmt, ...)
 
 /* lib/net_utils.c */
 #include <net.h>
-static inline struct in_addr env_get_ip(char *var)
+static inline struct in_addr env_get_ip(struct env_context *ctx, char *var)
 {
-	return string_to_ip(env_get(var));
+	return string_to_ip(env_get(ctx, var));
 }
 
 #ifdef CONFIG_LED_STATUS
diff --git a/include/env.h b/include/env.h
index a74a261337e6..203605e5e778 100644
--- a/include/env.h
+++ b/include/env.h
@@ -12,7 +12,9 @@
 #include <stdbool.h>
 #include <linux/types.h>
 
+struct env_context;
 struct environment_s;
+enum env_operation; /* TODO: move it from env_internal.h? */
 
 /* Value for environment validity */
 enum env_valid {
@@ -61,15 +63,24 @@ enum env_redund_flags {
 	ENV_REDUND_ACTIVE = 1,
 };
 
+/* Accessor functions */
+void env_set_ready(struct env_context *ctx);
+bool env_is_ready(struct env_context *ctx);
+void env_set_valid(struct env_context *ctx, enum env_valid valid);
+enum env_valid env_get_valid(struct env_context *ctx);
+void env_set_env_addr(struct env_context *ctx, ulong env_addr);
+ulong env_get_env_addr(struct env_context *ctx);
+
 /**
  * env_get_id() - Gets a sequence number for the environment
  *
  * This value increments every time the environment changes, so can be used an
  * an indication of this
  *
+ * @ctx: Context
  * @return environment ID
  */
-int env_get_id(void);
+int env_get_id(struct env_context *ctx);
 
 /**
  * env_init() - Set up the pre-relocation environment
@@ -98,7 +109,7 @@ void env_relocate(void);
  * @index: The environment index for a 'name2=value2' pair.
  * @return index for the value if the names match, else -1.
  */
-int env_match(unsigned char *name, int index);
+int env_match(struct env_context *ctx, unsigned char *name, int index);
 
 /**
  * env_get() - Look up the value of an environment variable
@@ -107,10 +118,11 @@ int env_match(unsigned char *name, int index);
  * environment is loaded from storage, i.e. GD_FLG_ENV_READY is 0). In that
  * case this function calls env_get_f().
  *
+ * @ctx:	Context
  * @varname:	Variable to look up
  * @return value of variable, or NULL if not found
  */
-char *env_get(const char *varname);
+char *env_get(struct env_context *ctx, const char *varname);
 
 /**
  * env_get_f() - Look up the value of an environment variable (early)
@@ -119,10 +131,12 @@ char *env_get(const char *varname);
  * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will
  * support reading the value (slowly) and some will not.
  *
+ * @ctx:	Context
  * @varname:	Variable to look up
  * @return value of variable, or NULL if not found
  */
-int env_get_f(const char *name, char *buf, unsigned int len);
+int env_get_f(struct env_context *ctx, const char *name, char *buf,
+	      unsigned int len);
 
 /**
  * env_get_yesno() - Read an environment variable as a boolean
@@ -138,11 +152,12 @@ int env_get_yesno(const char *var);
  * This sets or deletes the value of an environment variable. For setting the
  * value the variable is created if it does not already exist.
  *
+ * @ctx: Context
  * @varname: Variable to adjust
  * @value: Value to set for the variable, or NULL or "" to delete the variable
  * @return 0 if OK, 1 on error
  */
-int env_set(const char *varname, const char *value);
+int env_set(struct env_context *ctx, const char *varname, const char *value);
 
 /**
  * env_get_ulong() - Return an environment variable as an integer value
@@ -150,21 +165,24 @@ int env_set(const char *varname, const char *value);
  * Most U-Boot environment variables store hex values. For those which store
  * (e.g.) base-10 integers, this function can be used to read the value.
  *
+ * @ctx:	Context
  * @name:	Variable to look up
  * @base:	Base to use (e.g. 10 for base 10, 2 for binary)
  * @default_val: Default value to return if no value is found
  * @return the value found, or @default_val if none
  */
-ulong env_get_ulong(const char *name, int base, ulong default_val);
+ulong env_get_ulong(struct env_context *ctx, const char *name, int base,
+		    ulong default_val);
 
 /**
  * env_set_ulong() - set an environment variable to an integer
  *
+ * @ctx: Context
  * @varname: Variable to adjust
  * @value: Value to set for the variable (will be converted to a string)
  * @return 0 if OK, 1 on error
  */
-int env_set_ulong(const char *varname, ulong value);
+int env_set_ulong(struct env_context *ctx, const char *varname, ulong value);
 
 /**
  * env_get_hex() - Return an environment variable as a hex value
@@ -173,30 +191,35 @@ int env_set_ulong(const char *varname, ulong value);
  * prefix). If the environment variable cannot be found, or does not start
  * with hex digits, the default value is returned.
  *
+ * @ctx:		Context
  * @varname:		Variable to decode
  * @default_val:	Value to return on error
  */
-ulong env_get_hex(const char *varname, ulong default_val);
+ulong env_get_hex(struct env_context *ctx, const char *varname,
+		  ulong default_val);
 
 /**
  * env_set_hex() - set an environment variable to a hex value
  *
+ * @ctx: Context
  * @varname: Variable to adjust
  * @value: Value to set for the variable (will be converted to a hex string)
  * @return 0 if OK, 1 on error
  */
-int env_set_hex(const char *varname, ulong value);
+int env_set_hex(struct env_context *ctx, const char *varname, ulong value);
 
 /**
  * env_set_addr - Set an environment variable to an address in hex
  *
+ * @ctx:	Context
  * @varname:	Environment variable to set
  * @addr:	Value to set it to
  * @return 0 if ok, 1 on error
  */
-static inline int env_set_addr(const char *varname, const void *addr)
+static inline int env_set_addr(struct env_context *ctx, const char *varname,
+			       const void *addr)
 {
-	return env_set_hex(varname, (ulong)addr);
+	return env_set_hex(ctx, varname, (ulong)addr);
 }
 
 /**
@@ -241,32 +264,56 @@ void env_fix_drivers(void);
  *
  * This resets individual variables to their value in the default environment
  *
+ * @ctx: Context
  * @nvars: Number of variables to set/reset
  * @vars: List of variables to set/reset
  * @flags: Flags controlling matching (H_... - see search.h)
  */
-int env_set_default_vars(int nvars, char *const vars[], int flags);
+int env_set_default_vars(struct env_context *ctx,
+			 int nvars, char *const vars[], int flags);
+
+/**
+ * env_driver_looup()
+ *
+ * @ctx: Context
+ * @op: Operation
+ * @prio: Priority
+ * @return pointer to env_driver if found, otherwise NULL
+ */
+struct env_driver *env_driver_lookup(struct env_context *ctx,
+				     enum env_operation op, int prio);
 
 /**
  * env_load() - Load the environment from storage
  *
+ * @ctx: Context
  * @return 0 if OK, -ve on error
  */
-int env_load(void);
+int env_load(struct env_context *ctx);
 
 /**
  * env_save() - Save the environment to storage
  *
+ * @ctx: Context
+ * @return 0 if OK, -ve on error
+ */
+int env_save(struct env_context *ctx);
+
+/**
+ * env_ctx_init() - initialize the context environment
+ *
+ * @ctx: Context
  * @return 0 if OK, -ve on error
  */
-int env_save(void);
+int env_ctx_init(struct env_context *ctx);
 
 /**
  * env_erase() - Erase the environment on storage
  *
+ * @ctx: Context
  * @return 0 if OK, -ve on error
  */
-int env_erase(void);
+int env_erase(struct env_context *ctx);
 
 /**
  * env_import() - Import from a binary representation into hash table
@@ -274,56 +321,62 @@ int env_erase(void);
  * This imports the environment from a buffer. The format for each variable is
  * var=value\0 with a double \0 at the end of the buffer.
  *
+ * @ctx: Context
  * @buf: Buffer containing the environment (struct environemnt_s *)
  * @check: non-zero to check the CRC at the start of the environment, 0 to
  *	ignore it
  * @return 0 if imported successfully, -ENOMSG if the CRC was bad, -EIO if
  *	something else went wrong
  */
-int env_import(const char *buf, int check);
+int env_import(struct env_context *ctx, const char *buf, int check);
 
 /**
  * env_export() - Export the environment to a buffer
  *
  * Export from hash table into binary representation
  *
+ * @ctx: Context
  * @env_out: Buffer to contain the environment (must be large enough!)
  * @return 0 if OK, 1 on error
  */
-int env_export(struct environment_s *env_out);
+int env_export(struct env_context *ctx, struct environment_hdr *env_out);
 
 /**
  * env_import_redund() - Select and import one of two redundant environments
  *
+ * @ctx: Context
  * @buf1: First environment (struct environemnt_s *)
  * @buf1_read_fail: 0 if buf1 is valid, non-zero if invalid
  * @buf2: Second environment (struct environemnt_s *)
  * @buf2_read_fail: 0 if buf2 is valid, non-zero if invalid
  * @return 0 if OK, -EIO if no environment is valid, -ENOMSG if the CRC was bad
  */
-int env_import_redund(const char *buf1, int buf1_read_fail,
+int env_import_redund(struct env_context *ctx,
+		      const char *buf1, int buf1_read_fail,
 		      const char *buf2, int buf2_read_fail);
 
 /**
  * env_get_default() - Look up a variable from the default environment
  *
+ * @ctx: Context
  * @name: Variable to look up
  * @return value if found, NULL if not found in default environment
  */
-char *env_get_default(const char *name);
+char *env_get_default(struct env_context *ctx, const char *name);
 
 /* [re]set to the default environment */
-void env_set_default(const char *s, int flags);
+void env_set_default(struct env_context *ctx, const char *s, int flags);
 
 /**
  * env_get_char() - Get a character from the early environment
  *
  * This reads from the pre-relocation environment
  *
+ * @ctx: Context
  * @index: Index of character to read (0 = first)
  * @return character read, or -ve on error
  */
-int env_get_char(int index);
+int env_get_char(struct env_context *ctx, int index);
 
 /**
  * env_reloc() - Relocate the 'env' sub-commands
diff --git a/include/env_internal.h b/include/env_internal.h
index b1ddcb5adfd3..9514f6649c3e 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -15,6 +15,7 @@
 #ifndef _ENV_INTERNAL_H_
 #define _ENV_INTERNAL_H_
 
+#include <stdbool.h>
 #include <linux/kconfig.h>
 
 /**************************************************************************
@@ -163,6 +164,14 @@ extern unsigned long nand_env_oob_offset;
 #define	TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
 #endif
 
+typedef struct environment_hdr {
+	uint32_t	crc;		/* CRC32 over data bytes	*/
+#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
+	unsigned char	flags;		/* active/obsolete flags	*/
+#endif
+	unsigned char	data[];		/* Environment data		*/
+} env_hdr_t;
+
 typedef struct environment_s {
 	uint32_t	crc;		/* CRC32 over data bytes	*/
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
@@ -182,6 +191,7 @@ extern const unsigned char default_environment[];
 #include <env_attr.h>
 #include <env_callback.h>
 #include <env_flags.h>
+#include <linker_lists.h>
 #include <search.h>
 
 enum env_location {
@@ -211,6 +221,67 @@ enum env_operation {
 	ENVOP_ERASE,	/* we want to call the erase function */
 };
 
+#if	defined(CONFIG_ENV_DRV_EEPROM)		|| \
+	defined(CONFIG_ENV_DRV_FLASH)		|| \
+	defined(CONFIG_ENV_DRV_MMC)		|| \
+	defined(CONFIG_ENV_DRV_FAT)		|| \
+	defined(CONFIG_ENV_DRV_EXT4)		|| \
+	defined(CONFIG_ENV_DRV_NAND)		|| \
+	defined(CONFIG_ENV_DRV_NVRAM)		|| \
+	defined(CONFIG_ENV_DRV_ONENAND)		|| \
+	defined(CONFIG_ENV_DRV_SATA)		|| \
+	defined(CONFIG_ENV_DRV_SPI_FLASH)	|| \
+	defined(CONFIG_ENV_DRV_REMOTE)		|| \
+	defined(CONFIG_ENV_DRV_UBI)
+
+#define ENV_IS_IN_DEVICE
+
+#endif
+
+/* defined in search.h */
+struct hsearch_data;
+
+struct env_context {
+	const char *name;
+	int env_id;
+	/* TODO: Some flag bits can be assembled into single flag */
+	unsigned long valid;
+	unsigned long flags;
+#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
+	unsigned char env_flags;
+#endif
+	int has_init;
+	int load_prio;
+	void *drv_params[ENVL_COUNT];
+	struct hsearch_data *htab;	/* hash table on memory */
+	uint32_t env_size;		/* data bytes in env */
+
+	/* driver-related functions in env/env.c */
+	bool (*has_inited)(struct env_context *ctx, enum env_location location);
+	void (*set_inited)(struct env_context *ctx, enum env_location location);
+	int (*get_load_prio)(struct env_context *ctx);
+	enum env_location (*get_location)(struct env_context *ctx,
+					  enum env_operation op, int prio);
+	int (*get_char)(struct env_context *ctx, int index);
+	int (*get_char_default)(struct env_context *ctx, int index);
+	int (*get_char_spec)(struct env_context *ctx, int index);
+	int (*init)(struct env_context *ctx);
+	int (*drv_init)(struct env_context *ctx, enum env_location loc);
+
+	/* save/load-related functions in env/common.c */
+	char *(*get_default)(struct env_context *ctx, const char *name);
+	void (*set_default)(struct env_context *ctx, const char *s, int flags);
+	int (*set_default_vars)(struct env_context *ctx,
+				int nvars, char * const vars[], int flags);
+	void (*set_ready)(struct env_context *ctx);
+	bool (*is_ready)(struct env_context *ctx);
+	void (*set_valid)(struct env_context *ctx, enum env_valid valid);
+	enum env_valid (*get_valid)(struct env_context *ctx);
+	void (*set_addr)(struct env_context *ctx, ulong env_addr);
+	ulong (*get_addr)(struct env_context *ctx);
+	void (*post_relocate)(struct env_context *ctx);
+};
+
 struct env_driver {
 	const char *name;
 	enum env_location location;
@@ -221,18 +292,20 @@ struct env_driver {
 	 * This method is optional. If not provided, no environment will be
 	 * loaded.
 	 *
+	 * @ctx:   pointer to environment context
 	 * @return 0 if OK, -ve on error
 	 */
-	int (*load)(void);
+	int (*load)(struct env_context *ctx);
 
 	/**
 	 * save() - Save the environment to storage
 	 *
 	 * This method is required for 'saveenv' to work.
 	 *
+	 * @ctx:   pointer to environment context
 	 * @return 0 if OK, -ve on error
 	 */
-	int (*save)(void);
+	int (*save)(struct env_context *ctx);
 
 	/**
 	 * erase() - Erase the environment on storage
@@ -241,23 +314,30 @@ struct env_driver {
 	 *
 	 * @return 0 if OK, -ve on error
 	 */
-	int (*erase)(void);
+	int (*erase)(struct env_context *ctx);
 
 	/**
 	 * init() - Set up the initial pre-relocation environment
 	 *
 	 * This method is optional.
 	 *
+	 * @ctx:   pointer to environment context
 	 * @return 0 if OK, -ENOENT if no initial environment could be found,
 	 * other -ve on error
 	 */
-	int (*init)(void);
+	int (*init)(struct env_context *ctx);
 };
 
 /* Declare a new environment location driver */
 #define U_BOOT_ENV_LOCATION(__name)					\
 	ll_entry_declare(struct env_driver, __name, env_driver)
 
+/* Declare a new environment context */
+#define U_BOOT_ENV_CONTEXT(__name) \
+	ll_entry_declare(struct env_context, __name, env_contexts)
+#define U_BOOT_ENV_CTX_START ll_entry_start(struct env_context, env_contexts)
+#define U_BOOT_ENV_CTX_COUNT ll_entry_count(struct env_context, env_contexts)
+
 /* Declare the name of a location */
 #ifdef CONFIG_CMD_SAVEENV
 #define ENV_NAME(_name) .name = _name,
@@ -271,6 +351,7 @@ struct env_driver {
 #define env_save_ptr(x) NULL
 #endif
 
+extern enum env_location env_locations[];
 extern struct hsearch_data env_htab;
 
 #endif /* DO_DEPS_ONLY */
diff --git a/include/exports.h b/include/exports.h
index 147a00f860b0..60a482de1313 100644
--- a/include/exports.h
+++ b/include/exports.h
@@ -27,8 +27,9 @@ unsigned long get_timer(unsigned long);
 int vprintf(const char *, va_list);
 unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base);
 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
-char *env_get(const char *name);
-int env_set(const char *varname, const char *value);
+struct env_context;
+char *env_get(struct env_context *ctx, const char *name);
+int env_set(struct env_context *ctx, const char *varname, const char *value);
 long simple_strtol(const char *cp, char **endp, unsigned int base);
 int strcmp(const char *cs, const char *ct);
 unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 01/19] env: extend interfaces allowing for env contexts AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05 19:43   ` Heinrich Schuchardt
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 03/19] env: nowhere: rework with new env interfaces AKASHI Takahiro
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

In this patch, env context fo U-Boot environment is defined to utilize
new env interfaces, maintaining the compatibility with the existing
semantics and Kconfig configuration.

In this commit, FAT file system and flash device are only supported
devices for backing storages, but extending to other devices will be
quite straightforward.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 env/Kconfig.uboot   | 671 ++++++++++++++++++++++++++++++++++++++++++++
 env/Makefile        |   2 +-
 env/env_ctx_uboot.c | 292 +++++++++++++++++++
 include/env.h       |   3 +
 4 files changed, 967 insertions(+), 1 deletion(-)
 create mode 100644 env/Kconfig.uboot
 create mode 100644 env/env_ctx_uboot.c

diff --git a/env/Kconfig.uboot b/env/Kconfig.uboot
new file mode 100644
index 000000000000..e4334f7f2878
--- /dev/null
+++ b/env/Kconfig.uboot
@@ -0,0 +1,671 @@
+config ENV_IS_NOWHERE
+	bool "U-Boot Environment is not stored"
+	default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
+		     !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
+		     !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
+		     !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
+		     !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
+		     !ENV_IS_IN_UBI
+	help
+	  Define this if you don't want to or can't have an environment stored
+	  on a storage medium. In this case the environment will still exist
+	  while U-Boot is running, but once U-Boot exits it will not be
+	  stored. U-Boot will therefore always start up with a default
+	  environment.
+
+config ENV_IS_IN_EEPROM
+	bool "Environment in EEPROM"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_EEPROM
+	help
+	  Use this if you have an EEPROM or similar serial access
+	  device and a driver for it.
+
+	  - CONFIG_ENV_OFFSET:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines specify the offset and size of the
+	  environment area within the total memory of your EEPROM.
+
+	  Note that we consider the length of the address field to
+	  still be one byte because the extra address bits are hidden
+	  in the chip address.
+
+	  - CONFIG_ENV_EEPROM_IS_ON_I2C
+	  define this, if you have I2C and SPI activated, and your
+	  EEPROM, which holds the environment, is on the I2C bus.
+
+	  - CONFIG_I2C_ENV_EEPROM_BUS
+	  if you have an Environment on an EEPROM reached over
+	  I2C muxes, you can define here, how to reach this
+	  EEPROM. For example:
+
+	  #define CONFIG_I2C_ENV_EEPROM_BUS	  1
+
+	  EEPROM which holds the environment, is reached over
+	  a pca9547 i2c mux with address 0x70, channel 3.
+
+config ENV_IS_IN_FAT
+	bool "Environment is in a FAT filesystem"
+	depends on !CHAIN_OF_TRUST
+	default y if ARCH_BCM283X
+	default y if ARCH_SUNXI && MMC
+	default y if MMC_OMAP_HS && TI_COMMON_CMD_OPTIONS
+	select ENV_DRV_FAT
+	help
+	  Define this if you want to use the FAT file system for the environment.
+
+config ENV_IS_IN_EXT4
+	bool "Environment is in a EXT4 filesystem"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_EXT4
+	help
+	  Define this if you want to use the EXT4 file system for the environment.
+
+config ENV_IS_IN_FLASH
+	bool "Environment in flash memory"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_FLASH
+	default y if ARCH_CINTEGRATOR
+	default y if ARCH_INTEGRATOR_CP
+	default y if M548x || M547x || M5282 || MCF547x_8x
+	default y if MCF532x || MCF52x2
+	default y if MPC86xx || MPC83xx
+	default y if ARCH_MPC8572 || ARCH_MPC8548 || ARCH_MPC8641
+	default y if SH && !CPU_SH4
+	help
+	  Define this if you have a flash device which you want to use for the
+	  environment.
+
+	  a) The environment occupies one whole flash sector, which is
+	   "embedded" in the text segment with the U-Boot code. This
+	   happens usually with "bottom boot sector" or "top boot
+	   sector" type flash chips, which have several smaller
+	   sectors at the start or the end. For instance, such a
+	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
+	   such a case you would place the environment in one of the
+	   4 kB sectors - with U-Boot code before and after it. With
+	   "top boot sector" type flash chips, you would put the
+	   environment in one of the last sectors, leaving a gap
+	   between U-Boot and the environment.
+
+	  CONFIG_ENV_OFFSET:
+
+	   Offset of environment data (variable area) to the
+	   beginning of flash memory; for instance, with bottom boot
+	   type flash chips the second sector can be used: the offset
+	   for this sector is given here.
+
+	   CONFIG_ENV_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
+
+	  CONFIG_ENV_ADDR:
+
+	   This is just another way to specify the start address of
+	   the flash sector containing the environment (instead of
+	   CONFIG_ENV_OFFSET).
+
+	  CONFIG_ENV_SECT_SIZE:
+
+	   Size of the sector containing the environment.
+
+
+	  b) Sometimes flash chips have few, equal sized, BIG sectors.
+	   In such a case you don't want to spend a whole sector for
+	   the environment.
+
+	  CONFIG_ENV_SIZE:
+
+	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
+	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
+	   of this flash sector for the environment. This saves
+	   memory for the RAM copy of the environment.
+
+	   It may also save flash memory if you decide to use this
+	   when your environment is "embedded" within U-Boot code,
+	   since then the remainder of the flash sector could be used
+	   for U-Boot code. It should be pointed out that this is
+	   STRONGLY DISCOURAGED from a robustness point of view:
+	   updating the environment in flash makes it always
+	   necessary to erase the WHOLE sector. If something goes
+	   wrong before the contents has been restored from a copy in
+	   RAM, your target system will be dead.
+
+	  CONFIG_ENV_ADDR_REDUND
+	  CONFIG_ENV_SIZE_REDUND
+
+	   These settings describe a second storage area used to hold
+	   a redundant copy of the environment data, so that there is
+	   a valid backup copy in case there is a power failure during
+	   a "saveenv" operation.
+
+	  BE CAREFUL! Any changes to the flash layout, and some changes to the
+	  source code will make it necessary to adapt <board>/u-boot.lds*
+	  accordingly!
+
+config ENV_IS_IN_MMC
+	bool "Environment in an MMC device"
+	depends on !CHAIN_OF_TRUST
+	depends on MMC
+	select ENV_DRV_MMC
+	default y if ARCH_EXYNOS4
+	default y if MX6SX || MX7D
+	default y if TEGRA30 || TEGRA124
+	default y if TEGRA_ARMV8_COMMON
+	help
+	  Define this if you have an MMC device which you want to use for the
+	  environment.
+
+	  CONFIG_SYS_MMC_ENV_DEV:
+
+	  Specifies which MMC device the environment is stored in.
+
+	  CONFIG_SYS_MMC_ENV_PART (optional):
+
+	  Specifies which MMC partition the environment is stored in. If not
+	  set, defaults to partition 0, the user area. Common values might be
+	  1 (first MMC boot partition), 2 (second MMC boot partition).
+
+	  CONFIG_ENV_OFFSET:
+	  CONFIG_ENV_SIZE:
+
+	  These two #defines specify the offset and size of the environment
+	  area within the specified MMC device.
+
+	  If offset is positive (the usual case), it is treated as relative to
+	  the start of the MMC partition. If offset is negative, it is treated
+	  as relative to the end of the MMC partition. This can be useful if
+	  your board may be fitted with different MMC devices, which have
+	  different sizes for the MMC partitions, and you always want the
+	  environment placed at the very end of the partition, to leave the
+	  maximum possible space before it, to store other data.
+
+	  These two values are in units of bytes, but must be aligned to an
+	  MMC sector boundary.
+
+	  CONFIG_ENV_OFFSET_REDUND (optional):
+
+	  Specifies a second storage area, of CONFIG_ENV_SIZE size, used to
+	  hold a redundant copy of the environment data. This provides a
+	  valid backup copy in case the other copy is corrupted, e.g. due
+	  to a power failure during a "saveenv" operation.
+
+	  This value may also be positive or negative; this is handled in the
+	  same way as CONFIG_ENV_OFFSET.
+
+	  This value is also in units of bytes, but must also be aligned to
+	  an MMC sector boundary.
+
+	  CONFIG_ENV_SIZE_REDUND (optional):
+
+	  This value need not be set, even when CONFIG_ENV_OFFSET_REDUND is
+	  set. If this value is set, it must be set to the same value as
+	  CONFIG_ENV_SIZE.
+
+config ENV_IS_IN_NAND
+	bool "Environment in a NAND device"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_NAND
+	help
+	  Define this if you have a NAND device which you want to use for the
+	  environment.
+
+	  - CONFIG_ENV_OFFSET:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines specify the offset and size of the environment
+	  area within the first NAND device.  CONFIG_ENV_OFFSET must be
+	  aligned to an erase block boundary.
+
+	  - CONFIG_ENV_OFFSET_REDUND (optional):
+
+	  This setting describes a second storage area of CONFIG_ENV_SIZE
+	  size used to hold a redundant copy of the environment data, so
+	  that there is a valid backup copy in case there is a power failure
+	  during a "saveenv" operation.	 CONFIG_ENV_OFFSET_REDUND must be
+	  aligned to an erase block boundary.
+
+	  - CONFIG_ENV_RANGE (optional):
+
+	  Specifies the length of the region in which the environment
+	  can be written.  This should be a multiple of the NAND device's
+	  block size.  Specifying a range with more erase blocks than
+	  are needed to hold CONFIG_ENV_SIZE allows bad blocks within
+	  the range to be avoided.
+
+	  - CONFIG_ENV_OFFSET_OOB (optional):
+
+	  Enables support for dynamically retrieving the offset of the
+	  environment from block zero's out-of-band data.  The
+	  "nand env.oob" command can be used to record this offset.
+	  Currently, CONFIG_ENV_OFFSET_REDUND is not supported when
+	  using CONFIG_ENV_OFFSET_OOB.
+
+config ENV_IS_IN_NVRAM
+	bool "Environment in a non-volatile RAM"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_NVRAM
+	help
+	  Define this if you have some non-volatile memory device
+	  (NVRAM, battery buffered SRAM) which you want to use for the
+	  environment.
+
+	  - CONFIG_ENV_ADDR:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines are used to determine the memory area you
+	  want to use for environment. It is assumed that this memory
+	  can just be read and written to, without any special
+	  provision.
+
+config ENV_IS_IN_ONENAND
+	bool "Environment is in OneNAND"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_ONENAND
+	help
+	  Define this if you want to put your local device's environment in
+	  OneNAND.
+
+	  - CONFIG_ENV_ADDR:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines are used to determine the device range you
+	  want to use for environment. It is assumed that this memory
+	  can just be read and written to, without any special
+	  provision.
+
+config ENV_IS_IN_REMOTE
+	bool "Environment is in remote memory space"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_REMOTE
+	help
+	  Define this if you have a remote memory space which you
+	  want to use for the local device's environment.
+
+	  - CONFIG_ENV_ADDR:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines specify the address and size of the
+	  environment area within the remote memory space. The
+	  local device can get the environment from remote memory
+	  space by SRIO or PCIE links.
+
+config ENV_IS_IN_SPI_FLASH
+	bool "Environment is in SPI flash"
+	depends on !CHAIN_OF_TRUST && SPI
+	select ENV_DRV_SPI_FLASH
+	default y if ARMADA_XP
+	default y if INTEL_BAYTRAIL
+	default y if INTEL_BRASWELL
+	default y if INTEL_BROADWELL
+	default y if NORTHBRIDGE_INTEL_IVYBRIDGE
+	default y if INTEL_QUARK
+	default y if INTEL_QUEENSBAY
+	help
+	  Define this if you have a SPI Flash memory device which you
+	  want to use for the environment.
+
+	  - CONFIG_ENV_OFFSET:
+	  - CONFIG_ENV_SIZE:
+
+	  These two #defines specify the offset and size of the
+	  environment area within the SPI Flash. CONFIG_ENV_OFFSET must be
+	  aligned to an erase sector boundary.
+
+	  - CONFIG_ENV_SECT_SIZE:
+
+	  Define the SPI flash's sector size.
+
+	  - CONFIG_ENV_OFFSET_REDUND (optional):
+
+	  This setting describes a second storage area of CONFIG_ENV_SIZE
+	  size used to hold a redundant copy of the environment data, so
+	  that there is a valid backup copy in case there is a power failure
+	  during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
+	  aligned to an erase sector boundary.
+
+config USE_ENV_SPI_BUS
+	bool "SPI flash bus for environment"
+	depends on ENV_IS_IN_SPI_FLASH
+	help
+	  Force the SPI bus for environment.
+	  If not defined, use CONFIG_SF_DEFAULT_BUS.
+
+config ENV_SPI_BUS
+	int "Value of SPI flash bus for environment"
+	depends on USE_ENV_SPI_BUS
+	help
+	  Value the SPI bus and chip select for environment.
+
+config USE_ENV_SPI_CS
+	bool "SPI flash chip select for environment"
+	depends on ENV_IS_IN_SPI_FLASH
+	help
+	  Force the SPI chip select for environment.
+	  If not defined, use CONFIG_SF_DEFAULT_CS.
+
+config ENV_SPI_CS
+	int "Value of SPI flash chip select for environment"
+	depends on USE_ENV_SPI_CS
+	help
+	  Value of the SPI chip select for environment.
+
+config USE_ENV_SPI_MAX_HZ
+	bool "SPI flash max frequency for environment"
+	depends on ENV_IS_IN_SPI_FLASH
+	help
+	  Force the SPI max work clock for environment.
+	  If not defined, use CONFIG_SF_DEFAULT_SPEED.
+
+config ENV_SPI_MAX_HZ
+	int "Value of SPI flash max frequency for environment"
+	depends on USE_ENV_SPI_MAX_HZ
+	help
+	  Value of the SPI max work clock for environment.
+
+config USE_ENV_SPI_MODE
+	bool "SPI flash mode for environment"
+	depends on ENV_IS_IN_SPI_FLASH
+	help
+	  Force the SPI work mode for environment.
+
+config ENV_SPI_MODE
+	hex "Value of SPI flash work mode for environment"
+	depends on USE_ENV_SPI_MODE
+	help
+	  Value of the SPI work mode for environment.
+	  See include/spi.h for value.
+
+config ENV_IS_IN_UBI
+	bool "Environment in a UBI volume"
+	depends on !CHAIN_OF_TRUST
+	select ENV_DRV_UBI
+	help
+	  Define this if you have an UBI volume that you want to use for the
+	  environment.  This has the benefit of wear-leveling the environment
+	  accesses, which is important on NAND.
+
+	  - CONFIG_ENV_UBI_PART:
+
+	  Define this to a string that is the mtd partition containing the UBI.
+
+	  - CONFIG_ENV_UBI_VOLUME:
+
+	  Define this to the name of the volume that you want to store the
+	  environment in.
+
+	  - CONFIG_ENV_UBI_VOLUME_REDUND:
+
+	  Define this to the name of another volume to store a second copy of
+	  the environment in.  This will enable redundant environments in UBI.
+	  It is assumed that both volumes are in the same MTD partition.
+
+config ENV_FAT_INTERFACE
+	string "Name of the block device for the environment"
+	depends on ENV_IS_IN_FAT
+	default "mmc" if ARCH_SUNXI
+	default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
+	help
+	  Define this to a string that is the name of the block device.
+
+config ENV_FAT_DEVICE_AND_PART
+	string "Device and partition for where to store the environment in FAT"
+	depends on ENV_IS_IN_FAT
+	default "0:1" if TI_COMMON_CMD_OPTIONS
+	default "0:auto" if ARCH_ZYNQMP
+	default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
+	default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
+	default "0" if ARCH_AT91
+	help
+	  Define this to a string to specify the partition of the device. It can
+	  be as following:
+
+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
+	       - "D:P": device D partition P. Error occurs if device D has no
+	                partition table.
+	       - "D:0": device D.
+	       - "D" or "D:": device D partition 1 if device D has partition
+	                      table, or the whole device D if has no partition
+	                      table.
+	       - "D:auto": first partition in device D with bootable flag set.
+	                   If none, first valid partition in device D. If no
+	                   partition table then means device D.
+
+config ENV_FAT_FILE
+	string "Name of the FAT file to use for the environment"
+	depends on ENV_IS_IN_FAT
+	default "uboot.env"
+	help
+	  It's a string of the FAT file name. This file use to store the
+	  environment.
+
+config ENV_EXT4_INTERFACE
+	string "Name of the block device for the environment"
+	depends on ENV_IS_IN_EXT4
+	help
+	  Define this to a string that is the name of the block device.
+
+config ENV_EXT4_DEVICE_AND_PART
+	string "Device and partition for where to store the environment in EXT4"
+	depends on ENV_IS_IN_EXT4
+	help
+	  Define this to a string to specify the partition of the device. It can
+	  be as following:
+
+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
+	       - "D:P": device D partition P. Error occurs if device D has no
+	                partition table.
+	       - "D:0": device D.
+	       - "D" or "D:": device D partition 1 if device D has partition
+	                      table, or the whole device D if has no partition
+	                      table.
+	       - "D:auto": first partition in device D with bootable flag set.
+	                   If none, first valid partition in device D. If no
+	                   partition table then means device D.
+
+config ENV_EXT4_FILE
+	string "Name of the EXT4 file to use for the environment"
+	depends on ENV_IS_IN_EXT4
+	default "uboot.env"
+	help
+	  It's a string of the EXT4 file name. This file use to store the
+	  environment (explicit path to the file)
+
+if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC || ARCH_STM32MP || ARCH_OMAP2PLUS || ARCH_AT91
+
+config ENV_OFFSET
+	hex "Environment Offset"
+	depends on (!ENV_IS_IN_UBI && !ENV_IS_NOWHERE) || ARCH_STM32MP
+	default 0x3f8000 if ARCH_ROCKCHIP
+	default 0x88000 if ARCH_SUNXI
+	default 0xE0000 if ARCH_ZYNQ
+	default 0x1E00000 if ARCH_ZYNQMP
+	default 0 if ARC
+	default 0x140000 if ARCH_AT91
+	default 0x260000 if ARCH_OMAP2PLUS
+	help
+	  Offset from the start of the device (or partition)
+
+config ENV_SIZE
+	hex "Environment Size"
+	default 0x40000 if ENV_IS_IN_SPI_FLASH && ARCH_ZYNQMP
+	default 0x20000 if ARCH_SUNXI || ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
+	default 0x8000 if ARCH_ROCKCHIP || ARCH_ZYNQMP || ARCH_VERSAL
+	default 0x4000 if ARC
+	default 0x1f000
+	help
+	  Size of the environment storage area
+
+config ENV_SECT_SIZE
+	hex "Environment Sector-Size"
+	depends on (!ENV_IS_NOWHERE && (ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_OMAP2PLUS || ARCH_AT91) )|| ARCH_STM32MP
+	default 0x40000 if ARCH_ZYNQMP
+	default 0x20000 if ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
+	help
+	  Size of the sector containing the environment.
+
+config ENV_UBI_PART
+	string "UBI partition name"
+	depends on ENV_IS_IN_UBI
+	help
+	  MTD partition containing the UBI device
+
+config ENV_UBI_VOLUME
+	string "UBI volume name"
+	depends on ENV_IS_IN_UBI
+	help
+	  Name of the volume that you want to store the environment in.
+
+config ENV_UBI_VOLUME_REDUND
+	string "UBI redundant volume name"
+	depends on ENV_IS_IN_UBI
+	help
+	  Name of the redundant volume that you want to store the environment in.
+
+config ENV_UBI_VID_OFFSET
+	int "ubi environment VID offset"
+	depends on ENV_IS_IN_UBI
+	default 0
+	help
+	  UBI VID offset for environment. If 0, no custom VID offset is used.
+
+endif
+
+config USE_DEFAULT_ENV_FILE
+	bool "Create default environment from file"
+	help
+	  Normally, the default environment is automatically generated
+	  based on the settings of various CONFIG_* options, as well
+	  as the CONFIG_EXTRA_ENV_SETTINGS. By selecting this option,
+	  you can instead define the entire default environment in an
+	  external file.
+
+config DEFAULT_ENV_FILE
+	string "Path to default environment file"
+	depends on USE_DEFAULT_ENV_FILE
+	help
+	  The path containing the default environment. The format is
+	  the same as accepted by the mkenvimage tool: lines
+	  containing key=value pairs, blank lines and lines beginning
+	  with # are ignored.
+
+config ENV_VARS_UBOOT_RUNTIME_CONFIG
+	bool "Add run-time information to the environment"
+	help
+	  Enable this in order to add variables describing certain
+	  run-time determined information about the hardware to the
+	  environment.  These will be named board_name, board_rev.
+
+if SPL_ENV_SUPPORT
+config SPL_ENV_IS_NOWHERE
+	bool "SPL Environment is not stored"
+	default y if ENV_IS_NOWHERE
+	help
+	  Similar to ENV_IS_NOWHERE, used for SPL environment.
+
+config SPL_ENV_IS_IN_MMC
+	bool "SPL Environment in an MMC device"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_MMC
+	default y
+	help
+	  Similar to ENV_IS_IN_MMC, used for SPL environment.
+
+config SPL_ENV_IS_IN_FAT
+	bool "SPL Environment is in a FAT filesystem"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_FAT
+	default y
+	help
+	  Similar to ENV_IS_IN_FAT, used for SPL environment.
+
+config SPL_ENV_IS_IN_EXT4
+	bool "SPL Environment is in a EXT4 filesystem"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_EXT4
+	default y
+	help
+	  Similar to ENV_IS_IN_EXT4, used for SPL environment.
+
+config SPL_ENV_IS_IN_NAND
+	bool "SPL Environment in a NAND device"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_NAND
+	default y
+	help
+	  Similar to ENV_IS_IN_NAND, used for SPL environment.
+
+config SPL_ENV_IS_IN_SPI_FLASH
+	bool "SPL Environment is in SPI flash"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_SPI_FLASH
+	default y
+	help
+	  Similar to ENV_IS_IN_SPI_FLASH, used for SPL environment.
+
+config SPL_ENV_IS_IN_FLASH
+	bool "SPL Environment in flash memory"
+	depends on !SPL_ENV_IS_NOWHERE
+	select ENV_DRV_FLASH
+	default y
+	help
+	  Similar to ENV_IS_IN_FLASH, used for SPL environment.
+
+endif
+
+if TPL_ENV_SUPPORT
+
+config TPL_ENV_IS_NOWHERE
+	bool "TPL Environment is not stored"
+	default y if ENV_IS_NOWHERE
+	help
+	  Similar to ENV_IS_NOWHERE, used for TPL environment.
+
+config TPL_ENV_IS_IN_MMC
+	bool "TPL Environment in an MMC device"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_MMC
+	default y
+	help
+	  Similar to ENV_IS_IN_MMC, used for TPL environment.
+
+config TPL_ENV_IS_IN_FAT
+	bool "TPL Environment is in a FAT filesystem"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_FAT
+	default y
+	help
+	  Similar to ENV_IS_IN_FAT, used for TPL environment.
+
+config TPL_ENV_IS_IN_EXT4
+	bool "TPL Environment is in a EXT4 filesystem"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_EXT4
+	default y
+	help
+	  Similar to ENV_IS_IN_EXT4, used for TPL environment.
+
+config TPL_ENV_IS_IN_NAND
+	bool "TPL Environment in a NAND device"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_NAND
+	default y
+	help
+	  Similar to ENV_IS_IN_NAND, used for TPL environment.
+
+config TPL_ENV_IS_IN_SPI_FLASH
+	bool "TPL Environment is in SPI flash"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_SPI_FLASH
+	default y
+	help
+	  Similar to ENV_IS_IN_SPI_FLASH, used for TPL environment.
+
+config TPL_ENV_IS_IN_FLASH
+	bool "TPL Environment in flash memory"
+	depends on !TPL_ENV_IS_NOWHERE
+	select ENV_DRV_FLASH
+	default y
+	help
+	  Similar to ENV_IS_IN_FLASH, used for TPL environment.
+
+endif
diff --git a/env/Makefile b/env/Makefile
index ee37cc822024..0168eb47f00d 100644
--- a/env/Makefile
+++ b/env/Makefile
@@ -3,7 +3,7 @@
 # (C) Copyright 2004-2006
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 
-obj-y += common.o env.o
+obj-y += common.o env.o env_ctx_uboot.o
 
 ifndef CONFIG_SPL_BUILD
 obj-y += attr.o
diff --git a/env/env_ctx_uboot.c b/env/env_ctx_uboot.c
new file mode 100644
index 000000000000..5ca645599347
--- /dev/null
+++ b/env/env_ctx_uboot.c
@@ -0,0 +1,292 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Linaro Limited
+ *		Author: AKASHI Takahiro
+ */
+
+#include <common.h>
+#include <env_default.h>
+#include <env_flags.h>
+#include <env_internal.h>
+#include <search.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if !defined(ENV_IS_IN_DEVICE) && !defined(CONFIG_ENV_IS_NOWHERE)
+# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
+NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
+#endif
+
+struct hsearch_data env_htab = {
+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
+	/* defined in flags.c, only compile with ENV_SUPPORT */
+	.change_ok = env_flags_validate,
+#endif
+};
+
+/*
+ * NOTE: extracted from env/env.c
+ */
+static bool env_has_inited_uboot(struct env_context *ctx,
+				 enum env_location location)
+{
+	return gd->env_has_init & BIT(location);
+}
+
+static void env_set_inited_uboot(struct env_context *ctx,
+				 enum env_location location)
+{
+	gd->env_has_init |= BIT(location);
+}
+
+static int env_get_load_prio_uboot(struct env_context *ctx)
+{
+	return gd->env_load_prio;
+}
+
+static enum env_location env_get_location_uboot(struct env_context *ctx,
+						enum env_operation op, int prio)
+{
+	gd->env_load_prio = prio;
+
+	return env_locations[prio];
+}
+
+int env_get_char_default_uboot(struct env_context *ctx, int index)
+{
+	return default_environment[index];
+}
+
+int env_get_char_spec_uboot(struct env_context *ctx, int index)
+{
+	return *(uchar *)(gd->env_addr + index);
+}
+
+static int env_init_uboot(struct env_context *ctx)
+{
+	struct env_driver *drv;
+	int ret = -ENOENT;
+	int prio;
+
+	for (prio = 0; (drv = env_driver_lookup(ctx, ENVOP_INIT, prio));
+	     prio++) {
+		if (!drv->init || !(ret = drv->init(ctx)))
+			gd->env_has_init |= BIT(drv->location);
+
+		debug("%s: Environment %s init done (ret=%d)\n", __func__,
+		      drv->name, ret);
+	}
+
+	if (!prio)
+		return -ENODEV;
+
+	if (ret == -ENOENT) {
+		gd->env_addr = (ulong)&default_environment[0];
+		gd->env_valid = ENV_VALID;
+
+		return 0;
+	}
+
+	return ret;
+}
+
+static int env_drv_init_uboot(struct env_context *ctx, enum env_location loc)
+{
+	__maybe_unused int ret;
+
+	switch (loc) {
+#ifdef CONFIG_ENV_IS_IN_FLASH
+	case ENVL_FLASH: {
+		env_hdr_t *env_ptr;
+		env_hdr_t *flash_addr;
+		ulong end_addr;
+		env_hdr_t *flash_addr_new;
+		ulong end_addr_new;
+
+#ifdef ENV_IS_EMBEDDED
+		env_ptr = &embedded_environment;
+#else /* ! ENV_IS_EMBEDDED */
+		env_ptr = (env_hdr_t *)CONFIG_ENV_ADDR;
+#endif /* ENV_IS_EMBEDDED */
+		flash_addr = (env_hdr_t *)CONFIG_ENV_ADDR;
+
+/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
+		end_addr = CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
+
+#ifdef CONFIG_ENV_ADDR_REDUND
+		flash_addr_new = (env_hdr_t *)CONFIG_ENV_ADDR_REDUND;
+/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
+		end_addr_new = CONFIG_ENV_ADDR_REDUND
+					+ CONFIG_ENV_SECT_SIZE - 1;
+#else
+		flash_addr_new = NULL;
+		end_addr_new = 0;
+#endif /* CONFIG_ENV_ADDR_REDUND */
+
+		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
+					    flash_addr_new, end_addr_new,
+					    (ulong)&default_environment[0]);
+		if (ret)
+			return -ENOENT;
+
+		return 0;
+		}
+#endif
+#ifdef CONFIG_ENV_IS_IN_FAT
+	case ENVL_FAT: {
+		ret = env_fat_init_params(ctx,
+					  CONFIG_ENV_FAT_INTERFACE,
+					  CONFIG_ENV_FAT_DEVICE_AND_PART,
+					  CONFIG_ENV_FAT_FILE);
+
+		return -ENOENT;
+		}
+#endif
+#ifdef CONFIG_ENV_DRV_NONE
+	case ENVL_NOWHERE:
+#ifdef CONFIG_ENV_IS_NOWHERE
+		gd->env_addr = (ulong)&default_environment[0];
+		gd->env_valid = ENV_INVALID;
+
+		return 0;
+#else
+		return -ENOENT;
+#endif
+#endif
+	default:
+		return -ENOENT;
+	}
+}
+
+/*
+ * NOTE: extracted from env/common.c
+ */
+void env_set_ready_uboot(struct env_context *ctx)
+{
+	gd->flags |= GD_FLG_ENV_READY;
+}
+
+bool env_is_ready_uboot(struct env_context *ctx)
+{
+	return (gd->flags & GD_FLG_ENV_READY);
+}
+
+void env_set_valid_uboot(struct env_context *ctx, enum env_valid valid)
+{
+	gd->env_valid = valid;
+}
+
+enum env_valid env_get_valid_uboot(struct env_context *ctx)
+{
+	return gd->env_valid;
+}
+
+void env_set_addr_uboot(struct env_context *ctx, ulong env_addr)
+{
+	gd->env_addr = env_addr;
+}
+
+ulong env_get_addr_uboot(struct env_context *ctx)
+{
+	return gd->env_addr;
+}
+
+/*
+ * Look up the variable from the default environment
+ */
+char *env_get_default_uboot(struct env_context *ctx, const char *name)
+{
+	char *ret_val;
+	unsigned long really_valid = gd->env_valid;
+	unsigned long real_gd_flags = gd->flags;
+
+	/* Pretend that the image is bad. */
+	gd->flags &= ~GD_FLG_ENV_READY;
+	gd->env_valid = ENV_INVALID;
+	ret_val = env_get(ctx, name);
+	gd->env_valid = really_valid;
+	gd->flags = real_gd_flags;
+	return ret_val;
+}
+
+void env_set_default_env_uboot(struct env_context *ctx, const char *s,
+			       int flags)
+{
+	if (sizeof(default_environment) > ctx->env_size) {
+		puts("*** Error - default environment is too large\n\n");
+		return;
+	}
+
+	if (s) {
+		if ((flags & H_INTERACTIVE) == 0)
+			printf("*** Warning - %s, using default environment\n\n", s);
+		else
+			puts(s);
+	} else {
+		debug("Using default environment\n");
+	}
+
+	env_htab.ctx = ctx;
+	if (himport_r(&env_htab, (char *)default_environment,
+		      sizeof(default_environment), '\0', flags, 0,
+		      0, NULL) == 0)
+		pr_err("## Error: Environment import failed: errno = %d\n",
+		       errno);
+
+	gd->flags |= GD_FLG_ENV_READY;
+	gd->flags |= GD_FLG_ENV_DEFAULT;
+}
+
+/* [re]set individual variables to their value in the default environment */
+int env_set_default_vars_uboot(struct env_context *ctx, int nvars,
+			       char * const vars[], int flags)
+{
+	/*
+	 * Special use-case: import from default environment
+	 * (and use \0 as a separator)
+	 */
+	flags |= H_NOCLEAR;
+	env_htab.ctx = ctx;
+	return himport_r(&env_htab, (const char *)default_environment,
+				sizeof(default_environment), '\0',
+				flags, 0, nvars, vars);
+}
+
+void env_post_relocate_uboot(struct env_context *ctx)
+{
+	if (gd->env_valid == ENV_INVALID) {
+#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
+		/* Environment not changeable */
+		env_set_default(ctx, NULL, 0);
+#else
+		bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
+		env_set_default(ctx, "bad CRC", 0);
+#endif
+	} else {
+		env_load(ctx);
+	}
+}
+
+U_BOOT_ENV_CONTEXT(uboot) = {
+	.name = "uboot",
+	.htab = &env_htab,
+	.env_size = ENV_SIZE,
+	.has_inited = env_has_inited_uboot,
+	.set_inited = env_set_inited_uboot,
+	.get_load_prio = env_get_load_prio_uboot,
+	.get_location = env_get_location_uboot,
+	.get_char_default = env_get_char_default_uboot,
+	.get_char_spec = env_get_char_spec_uboot,
+	.init = env_init_uboot,
+	.drv_init = env_drv_init_uboot,
+	.get_default = env_get_default_uboot,
+	.set_default = env_set_default_env_uboot,
+	.set_default_vars = env_set_default_vars_uboot,
+	.set_ready = env_set_ready_uboot,
+	.is_ready = env_is_ready_uboot,
+	.set_valid = env_set_valid_uboot,
+	.get_valid = env_get_valid_uboot,
+	.set_addr = env_set_addr_uboot,
+	.get_addr = env_get_addr_uboot,
+	.post_relocate = env_post_relocate_uboot,
+};
diff --git a/include/env.h b/include/env.h
index 203605e5e778..26abae2a5c42 100644
--- a/include/env.h
+++ b/include/env.h
@@ -9,6 +9,7 @@
 #ifndef __ENV_H
 #define __ENV_H
 
+#include <linker_lists.h>
 #include <stdbool.h>
 #include <linux/types.h>
 
@@ -63,6 +64,8 @@ enum env_redund_flags {
 	ENV_REDUND_ACTIVE = 1,
 };
 
+#define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)
+
 /* Accessor functions */
 void env_set_ready(struct env_context *ctx);
 bool env_is_ready(struct env_context *ctx);
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 03/19] env: nowhere: rework with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 01/19] env: extend interfaces allowing for env contexts AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 04/19] env: flash: support multiple env contexts AKASHI Takahiro
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

Make this function a place holder.
Managing default values, in particular for U-Boot environment, should go
into context-specific initialization.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 env/nowhere.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/env/nowhere.c b/env/nowhere.c
index f5b0a17652c5..1a4d40f4a2de 100644
--- a/env/nowhere.c
+++ b/env/nowhere.c
@@ -19,12 +19,11 @@ DECLARE_GLOBAL_DATA_PTR;
  * Because we only ever have the default environment available we must mark
  * it as invalid.
  */
-static int env_nowhere_init(void)
+static int env_nowhere_init(struct env_context *ctx)
 {
-	gd->env_addr	= (ulong)&default_environment[0];
-	gd->env_valid	= ENV_INVALID;
+	/* Just a placeholder */
 
-	return 0;
+	return -ENOENT;
 }
 
 U_BOOT_ENV_LOCATION(nowhere) = {
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 04/19] env: flash: support multiple env contexts
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (2 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 03/19] env: nowhere: rework with new env interfaces AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 05/19] env: fat: " AKASHI Takahiro
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

To support multiple env contexts in this backing store driver,
all the necessary parameters to load/save context data with will
be contained in dedicated structure, env_flash_context.

All the contexts that want to support their own context must
provide its own Kconfig to fill in the parameters.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 env/flash.c   | 397 ++++++++++++++++++++++++++++++--------------------
 include/env.h |  11 ++
 2 files changed, 249 insertions(+), 159 deletions(-)

diff --git a/env/flash.c b/env/flash.c
index 231a5fdf24d0..0338e1be7a5a 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -45,73 +45,95 @@ DECLARE_GLOBAL_DATA_PTR;
 #define INITENV
 #endif
 
-#if defined(CONFIG_ENV_ADDR_REDUND) && defined(CMD_SAVEENV) || \
-	!defined(CONFIG_ENV_ADDR_REDUND) && defined(INITENV)
-#ifdef ENV_IS_EMBEDDED
-static env_t *env_ptr = &embedded_environment;
-#else /* ! ENV_IS_EMBEDDED */
-
-static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
-#endif /* ENV_IS_EMBEDDED */
-#endif
-static __maybe_unused env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
-
-/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
-static ulong __maybe_unused end_addr =
-		CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
-
-#ifdef CONFIG_ENV_ADDR_REDUND
+struct env_flash_context {
+	env_hdr_t *env_ptr;
+	env_hdr_t *flash_addr;
+	ulong end_addr;
+	env_hdr_t *flash_addr_new;
+	ulong end_addr_new;
+	ulong default_env_addr;
+};
 
-static env_t __maybe_unused *flash_addr_new = (env_t *)CONFIG_ENV_ADDR_REDUND;
+int env_flash_init_params(struct env_context *ctx,
+			  env_hdr_t *env_ptr,
+			  env_hdr_t *flash_addr, ulong end_addr,
+			  env_hdr_t *flash_addr_new, ulong end_addr_new,
+			  ulong default_env_addr)
+{
+	struct env_flash_context *params;
+
+	params = calloc(sizeof(*params), 1);
+	if (!params)
+		return -1;
+
+	params->env_ptr = env_ptr;
+	params->flash_addr = flash_addr;
+	params->end_addr = end_addr;
+	params->flash_addr_new = flash_addr_new;
+	params->end_addr_new = end_addr_new;
+	params->default_env_addr = default_env_addr;
+#if 1 /* FIXME: cause hang-up */
+	ctx->drv_params[ENVL_FLASH] = NULL;
+#else
+	ctx->drv_params[ENVL_FLASH] = params;
+#endif
 
-/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
-static ulong __maybe_unused end_addr_new =
-		CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
-#endif /* CONFIG_ENV_ADDR_REDUND */
+	return 0;
+}
 
 #ifdef CONFIG_ENV_ADDR_REDUND
 #ifdef INITENV
-static int env_flash_init(void)
+static int env_flash_init(struct env_context *ctx)
 {
+	struct env_flash_context *params;
 	int crc1_ok = 0, crc2_ok = 0;
 
-	uchar flag1 = flash_addr->flags;
-	uchar flag2 = flash_addr_new->flags;
+	if (ctx->drv_init)
+		if (ctx->drv_init(ctx, ENVL_FLASH))
+			return -ENOENT;
+
+	params = ctx->drv_params[ENVL_FLASH];
+	if (!params)
+		return -ENODEV;
+
+	uchar flag1 = params->flash_addr->flags;
+	uchar flag2 = params->flash_addr_new->flags;
 
-	ulong addr_default = (ulong)&default_environment[0];
-	ulong addr1 = (ulong)&(flash_addr->data);
-	ulong addr2 = (ulong)&(flash_addr_new->data);
+	ulong addr_default = params->default_env_addr;
+	ulong addr1 = (ulong)&params->flash_addr->data;
+	ulong addr2 = (ulong)&params->flash_addr_new->data;
 
-	crc1_ok = crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc;
-	crc2_ok =
-		crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc;
+	crc1_ok = crc32(0, params->flash_addr->data, ctx->env_size)
+			== params->flash_addr->crc;
+	crc2_ok = crc32(0, params->flash_addr_new->data, ctx->env_size)
+			== params->flash_addr_new->crc;
 
 	if (crc1_ok && !crc2_ok) {
-		gd->env_addr	= addr1;
-		gd->env_valid	= ENV_VALID;
+		env_set_env_addr(ctx, addr1);
+		env_set_valid(ctx, ENV_VALID);
 	} else if (!crc1_ok && crc2_ok) {
-		gd->env_addr	= addr2;
-		gd->env_valid	= ENV_VALID;
+		env_set_env_addr(ctx, addr2);
+		env_set_valid(ctx, ENV_VALID);
 	} else if (!crc1_ok && !crc2_ok) {
-		gd->env_addr	= addr_default;
-		gd->env_valid	= ENV_INVALID;
+		env_set_env_addr(ctx, addr_default);
+		env_set_valid(ctx, ENV_INVALID);
 	} else if (flag1 == ENV_REDUND_ACTIVE &&
 		   flag2 == ENV_REDUND_OBSOLETE) {
-		gd->env_addr	= addr1;
-		gd->env_valid	= ENV_VALID;
+		env_set_env_addr(ctx, addr1);
+		env_set_valid(ctx, ENV_VALID);
 	} else if (flag1 == ENV_REDUND_OBSOLETE &&
 		   flag2 == ENV_REDUND_ACTIVE) {
-		gd->env_addr	= addr2;
-		gd->env_valid	= ENV_VALID;
+		env_set_env_addr(ctx, addr2);
+		env_set_valid(ctx, ENV_VALID);
 	} else if (flag1 == flag2) {
-		gd->env_addr	= addr1;
-		gd->env_valid	= ENV_REDUND;
+		env_set_env_addr(ctx, addr1);
+		env_set_valid(ctx, ENV_REDUND);
 	} else if (flag1 == 0xFF) {
-		gd->env_addr	= addr1;
-		gd->env_valid	= ENV_REDUND;
+		env_set_env_addr(ctx, addr1);
+		env_set_valid(ctx, ENV_REDUND);
 	} else if (flag2 == 0xFF) {
-		gd->env_addr	= addr2;
-		gd->env_valid	= ENV_REDUND;
+		env_set_env_addr(ctx, addr2);
+		env_set_valid(ctx, ENV_REDUND);
 	}
 
 	return 0;
@@ -119,91 +141,107 @@ static int env_flash_init(void)
 #endif
 
 #ifdef CMD_SAVEENV
-static int env_flash_save(void)
+static int env_flash_save(struct env_context *ctx)
 {
-	env_t	env_new;
+	struct env_flash_context *params = ctx->drv_params[ENVL_FLASH];
+	env_hdr_t *env_new = NULL;
+	size_t	env_size;
 	char	*saved_data = NULL;
 	char	flag = ENV_REDUND_OBSOLETE, new_flag = ENV_REDUND_ACTIVE;
 	int	rc = 1;
-#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
 	ulong	up_data = 0;
-#endif
 
-	debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr);
+	debug("Protect off %08lX ... %08lX\n", (ulong)params->flash_addr,
+	      params->end_addr);
+
+	if (!params)
+		return 1;
 
-	if (flash_sect_protect(0, (ulong)flash_addr, end_addr))
+	env_size = sizeof(env_hdr_t) + ctx->env_size;
+	env_new = malloc(env_size);
+	if (!env_new)
+		return 1;
+
+	if (flash_sect_protect(0, (ulong)params->flash_addr, params->end_addr))
 		goto done;
 
 	debug("Protect off %08lX ... %08lX\n",
-		(ulong)flash_addr_new, end_addr_new);
+		(ulong)params->flash_addr_new, params->end_addr_new);
 
-	if (flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new))
+	if (flash_sect_protect(0, (ulong)params->flash_addr_new,
+			       params->end_addr_new))
 		goto done;
 
-	rc = env_export(&env_new);
+	rc = env_export(ctx, env_new);
 	if (rc)
-		return rc;
-	env_new.flags	= new_flag;
-
-#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
-	up_data = end_addr_new + 1 - ((long)flash_addr_new + CONFIG_ENV_SIZE);
-	debug("Data to save 0x%lX\n", up_data);
-	if (up_data) {
-		saved_data = malloc(up_data);
-		if (saved_data == NULL) {
-			printf("Unable to save the rest of sector (%ld)\n",
-				up_data);
-			goto done;
+		goto done;
+	env_new->flags	= new_flag;
+
+	if (env_size < CONFIG_ENV_SECT_SIZE) {
+		up_data = params->end_addr_new + 1
+				- ((long)params->flash_addr_new + env_size);
+		debug("Data to save 0x%lX\n", up_data);
+		if (up_data) {
+			saved_data = malloc(up_data);
+			if (!saved_data) {
+				printf("Unable to save the rest of sector (%ld)\n",
+				       up_data);
+				goto done;
+			}
+			memcpy(saved_data,
+			       (void *)
+			       ((long)params->flash_addr_new + env_size),
+			       up_data);
+			debug("Data (start 0x%lX, len 0x%lX) saved at 0x%p\n",
+			      (long)params->flash_addr_new + env_size,
+			      up_data, saved_data);
 		}
-		memcpy(saved_data,
-			(void *)((long)flash_addr_new + CONFIG_ENV_SIZE),
-			up_data);
-		debug("Data (start 0x%lX, len 0x%lX) saved at 0x%p\n",
-			(long)flash_addr_new + CONFIG_ENV_SIZE,
-			up_data, saved_data);
 	}
-#endif
+
 	puts("Erasing Flash...");
-	debug(" %08lX ... %08lX ...", (ulong)flash_addr_new, end_addr_new);
+	debug(" %08lX ... %08lX ...", (ulong)params->flash_addr_new,
+	      params->end_addr_new);
 
-	if (flash_sect_erase((ulong)flash_addr_new, end_addr_new))
+	if (flash_sect_erase((ulong)params->flash_addr_new,
+			     params->end_addr_new))
 		goto done;
 
 	puts("Writing to Flash... ");
 	debug(" %08lX ... %08lX ...",
-		(ulong)&(flash_addr_new->data),
-		sizeof(env_ptr->data) + (ulong)&(flash_addr_new->data));
-	rc = flash_write((char *)&env_new, (ulong)flash_addr_new,
-			 sizeof(env_new));
+	      (ulong)&params->flash_addr_new->data,
+	      ctx->env_size + (ulong)&params->flash_addr_new->data);
+	rc = flash_write((char *)env_new, (ulong)params->flash_addr_new,
+			 sizeof(*env_new) + ctx->env_size);
 	if (rc)
 		goto perror;
 
-	rc = flash_write(&flag, (ulong)&(flash_addr->flags),
-			 sizeof(flash_addr->flags));
+	rc = flash_write(&flag, (ulong)&params->flash_addr->flags,
+			 sizeof(params->flash_addr->flags));
 	if (rc)
 		goto perror;
 
-#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
-	if (up_data) { /* restore the rest of sector */
-		debug("Restoring the rest of data to 0x%lX len 0x%lX\n",
-			(long)flash_addr_new + CONFIG_ENV_SIZE, up_data);
-		if (flash_write(saved_data,
-				(long)flash_addr_new + CONFIG_ENV_SIZE,
-				up_data))
-			goto perror;
+	if (env_size < CONFIG_ENV_SECT_SIZE) {
+		if (up_data) { /* restore the rest of sector */
+			debug("Restoring the rest of data to 0x%lX len 0x%lX\n",
+			      (long)params->flash_addr_new + env_size, up_data);
+			if (flash_write(saved_data,
+					(long)params->flash_addr_new + env_size,
+					up_data))
+				goto perror;
+		}
 	}
-#endif
+
 	puts("done\n");
 
 	{
-		env_t *etmp = flash_addr;
-		ulong ltmp = end_addr;
+		env_hdr_t *etmp = params->flash_addr;
+		ulong ltmp = params->end_addr;
 
-		flash_addr = flash_addr_new;
-		flash_addr_new = etmp;
+		params->flash_addr = params->flash_addr_new;
+		params->flash_addr_new = etmp;
 
-		end_addr = end_addr_new;
-		end_addr_new = ltmp;
+		params->end_addr = params->end_addr_new;
+		params->end_addr_new = ltmp;
 	}
 
 	rc = 0;
@@ -214,8 +252,11 @@ done:
 	if (saved_data)
 		free(saved_data);
 	/* try to re-protect */
-	flash_sect_protect(1, (ulong)flash_addr, end_addr);
-	flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
+	flash_sect_protect(1, (ulong)params->flash_addr, params->end_addr);
+	flash_sect_protect(1, (ulong)params->flash_addr_new,
+			   params->end_addr_new);
+
+	free(env_new);
 
 	return rc;
 }
@@ -224,75 +265,100 @@ done:
 #else /* ! CONFIG_ENV_ADDR_REDUND */
 
 #ifdef INITENV
-static int env_flash_init(void)
+static int env_flash_init(struct env_context *ctx)
 {
-	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
-		gd->env_addr	= (ulong)&(env_ptr->data);
-		gd->env_valid	= ENV_VALID;
+	struct env_flash_context *params;
+
+	if (ctx->drv_init)
+		if (ctx->drv_init(ctx, ENVL_FLASH))
+			return -ENOENT;
+
+	params = ctx->drv_params[ENVL_FLASH];
+	if (!params)
+		return -ENODEV;
+
+	if (crc32(0, params->env_ptr->data, ctx->env_size)
+	    == params->env_ptr->crc) {
+		env_set_env_addr(ctx, (ulong)&params->env_ptr->data);
+		env_set_valid(ctx, ENV_VALID);
+
 		return 0;
 	}
 
-	gd->env_addr	= (ulong)&default_environment[0];
-	gd->env_valid	= ENV_INVALID;
+	env_set_env_addr(ctx, params->default_env_addr);
+	env_set_valid(ctx, ENV_INVALID);
+
 	return 0;
 }
 #endif
 
 #ifdef CMD_SAVEENV
-static int env_flash_save(void)
+static int env_flash_save(struct env_context *ctx)
 {
-	env_t	env_new;
+	struct env_flash_context *params = ctx->drv_params[ENVL_FLASH];
+	env_hdr_t *env_new;
 	int	rc = 1;
 	char	*saved_data = NULL;
-#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
 	ulong	up_data = 0;
-
-	up_data = end_addr + 1 - ((long)flash_addr + CONFIG_ENV_SIZE);
-	debug("Data to save 0x%lx\n", up_data);
-	if (up_data) {
-		saved_data = malloc(up_data);
-		if (saved_data == NULL) {
-			printf("Unable to save the rest of sector (%ld)\n",
-				up_data);
-			goto done;
+	size_t	env_size;
+
+	if (!params)
+		return 1;
+
+	env_size = sizeof(env_hdr_t) + ctx->env_size;
+	env_new = malloc(env_size);
+	if (!env_new)
+		return 1;
+
+	if (env_size < CONFIG_ENV_SECT_SIZE) {
+		up_data = params->end_addr + 1
+				- ((long)params->flash_addr + env_size);
+		debug("Data to save 0x%lx\n", up_data);
+		if (up_data) {
+			saved_data = malloc(up_data);
+			if (!saved_data) {
+				printf("Unable to save the rest of sector (%ld)\n",
+				       up_data);
+				goto done;
+			}
+			memcpy(saved_data,
+			       (void *)((long)params->flash_addr + env_size),
+			       up_data);
+			debug("Data (start 0x%lx, len 0x%lx) saved at 0x%lx\n",
+			      (ulong)params->flash_addr + env_size,
+			      up_data,
+			      (ulong)saved_data);
 		}
-		memcpy(saved_data,
-			(void *)((long)flash_addr + CONFIG_ENV_SIZE), up_data);
-		debug("Data (start 0x%lx, len 0x%lx) saved at 0x%lx\n",
-			(ulong)flash_addr + CONFIG_ENV_SIZE,
-			up_data,
-			(ulong)saved_data);
 	}
-#endif	/* CONFIG_ENV_SECT_SIZE */
 
-	debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr);
+	debug("Protect off %08lX ... %08lX\n", (ulong)params->flash_addr,
+	      params->end_addr);
 
-	if (flash_sect_protect(0, (long)flash_addr, end_addr))
+	if (flash_sect_protect(0, (long)params->flash_addr, params->end_addr))
 		goto done;
 
-	rc = env_export(&env_new);
+	rc = env_export(ctx, env_new);
 	if (rc)
 		goto done;
 
 	puts("Erasing Flash...");
-	if (flash_sect_erase((long)flash_addr, end_addr))
+	if (flash_sect_erase((long)params->flash_addr, params->end_addr))
 		goto done;
 
 	puts("Writing to Flash... ");
-	rc = flash_write((char *)&env_new, (long)flash_addr, CONFIG_ENV_SIZE);
+	rc = flash_write((char *)env_new, (long)params->flash_addr, env_size);
 	if (rc != 0)
 		goto perror;
 
-#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
-	if (up_data) {	/* restore the rest of sector */
+	if ((env_size < CONFIG_ENV_SECT_SIZE) && up_data) {
+		/* restore the rest of sector */
 		debug("Restoring the rest of data to 0x%lx len 0x%lx\n",
-			(ulong)flash_addr + CONFIG_ENV_SIZE, up_data);
-		if (flash_write(saved_data,
-				(long)flash_addr + CONFIG_ENV_SIZE,
+			(ulong)params->flash_addr + env_size, up_data);
+		if (flash_write(saved_data, (long)params->flash_addr + env_size,
 				up_data))
 			goto perror;
 	}
-#endif
+
 	puts("done\n");
 	rc = 0;
 	goto done;
@@ -302,7 +368,9 @@ done:
 	if (saved_data)
 		free(saved_data);
 	/* try to re-protect */
-	flash_sect_protect(1, (long)flash_addr, end_addr);
+	flash_sect_protect(1, (long)params->flash_addr, params->end_addr);
+	free(env_new);
+
 	return rc;
 }
 #endif /* CMD_SAVEENV */
@@ -310,50 +378,61 @@ done:
 #endif /* CONFIG_ENV_ADDR_REDUND */
 
 #ifdef LOADENV
-static int env_flash_load(void)
+static int env_flash_load(struct env_context *ctx)
 {
+	struct env_flash_context *params = ctx->drv_params[ENVL_FLASH];
+
+	if (!params)
+		return -ENODEV;
+
 #ifdef CONFIG_ENV_ADDR_REDUND
-	if (gd->env_addr != (ulong)&(flash_addr->data)) {
-		env_t *etmp = flash_addr;
-		ulong ltmp = end_addr;
+	if (env_get_env_addr(ctx) != (ulong)&params->flash_addr->data) {
+		struct environment_hdr *etmp = params->flash_addr;
+		ulong ltmp = params->end_addr;
 
-		flash_addr = flash_addr_new;
-		flash_addr_new = etmp;
+		params->flash_addr = params->flash_addr_new;
+		params->flash_addr_new = etmp;
 
-		end_addr = end_addr_new;
-		end_addr_new = ltmp;
+		params->end_addr = params->end_addr_new;
+		params->end_addr_new = ltmp;
 	}
 
 	if (flash_addr_new->flags != ENV_REDUND_OBSOLETE &&
-	    crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc) {
+	    crc32(0, params->flash_addr_new->data, ctx->env_size)
+			== params->flash_addr_new->crc) {
 		char flag = ENV_REDUND_OBSOLETE;
 
-		gd->env_valid = ENV_REDUND;
-		flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new);
+		env_set_valid(ctx, ENV_REDUND);
+		flash_sect_protect(0, (ulong)params->flash_addr_new,
+				   params->end_addr_new);
 		flash_write(&flag,
-			    (ulong)&(flash_addr_new->flags),
-			    sizeof(flash_addr_new->flags));
-		flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
+			    (ulong)&params->flash_addr_new->flags,
+			    sizeof(params->flash_addr_new->flags));
+		flash_sect_protect(1, (ulong)params->flash_addr_new,
+				   params->end_addr_new);
 	}
 
-	if (flash_addr->flags != ENV_REDUND_ACTIVE &&
-	    (flash_addr->flags & ENV_REDUND_ACTIVE) == ENV_REDUND_ACTIVE) {
+	if (params->flash_addr->flags != ENV_REDUND_ACTIVE &&
+	    (params->flash_addr->flags & ENV_REDUND_ACTIVE)
+			== ENV_REDUND_ACTIVE) {
 		char flag = ENV_REDUND_ACTIVE;
 
-		gd->env_valid = ENV_REDUND;
-		flash_sect_protect(0, (ulong)flash_addr, end_addr);
+		env_set_valid(ctx, ENV_REDUND);
+		flash_sect_protect(0, (ulong)params->flash_addr,
+				   params->end_addr);
 		flash_write(&flag,
-			    (ulong)&(flash_addr->flags),
-			    sizeof(flash_addr->flags));
-		flash_sect_protect(1, (ulong)flash_addr, end_addr);
+			    (ulong)&params->flash_addr->flags,
+			    sizeof(params->flash_addr->flags));
+		flash_sect_protect(1, (ulong)params->flash_addr,
+				   params->end_addr);
 	}
 
-	if (gd->env_valid == ENV_REDUND)
+	if (env_get_valid(ctx) == ENV_REDUND)
 		puts("*** Warning - some problems detected "
 		     "reading environment; recovered successfully\n\n");
 #endif /* CONFIG_ENV_ADDR_REDUND */
 
-	return env_import((char *)flash_addr, 1);
+	return env_import(ctx, (char *)params->flash_addr, 1);
 }
 #endif /* LOADENV */
 
diff --git a/include/env.h b/include/env.h
index 26abae2a5c42..9b4b9debc36d 100644
--- a/include/env.h
+++ b/include/env.h
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 
 struct env_context;
+struct environment_hdr;
 struct environment_s;
 enum env_operation; /* TODO: move it from env_internal.h? */
 
@@ -388,4 +389,14 @@ int env_get_char(struct env_context *ctx, int index);
  */
 void env_reloc(void);
 
+/*
+ * driver parameters initialization
+ */
+int env_flash_init_params(struct env_context *ctx,
+			  struct environment_hdr *env_ptr,
+			  struct environment_hdr *flash_addr, ulong end_addr,
+			  struct environment_hdr *flash_addr_new,
+			  ulong end_addr_new,
+			  ulong default_env_addr);
+
 #endif
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 05/19] env: fat: support multiple env contexts
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (3 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 04/19] env: flash: support multiple env contexts AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 06/19] hashtable: " AKASHI Takahiro
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

To support multiple env contexts in this backing store driver,
all the necessary parameters to load/save context data with will
be contained in dedicated structure, env_fat_context.

All the contexts that want to support their own context must
provide its own Kconfig to fill in the parameters.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 env/fat.c     | 102 +++++++++++++++++++++++++++++++++++++-------------
 include/env.h |   2 +
 2 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/env/fat.c b/env/fat.c
index 1836556f361d..0236c82849b3 100644
--- a/env/fat.c
+++ b/env/fat.c
@@ -31,25 +31,57 @@
 # endif
 #endif
 
+struct env_fat_context {
+	const char *interface;
+	const char *dev_and_part;
+	const char *file;
+};
+
+int env_fat_init_params(struct env_context *ctx, const char *interface,
+			const char *dev_part, const char *file)
+{
+	struct env_fat_context *params;
+
+	params = calloc(sizeof(*params), 1);
+	if (!params)
+		return -1;
+
+	params->interface = interface;
+	params->dev_and_part = dev_part;
+	params->file = file;
+	ctx->drv_params[ENVL_FAT] = params;
+
+	return 0;
+}
+
 #ifdef CMD_SAVEENV
-static int env_fat_save(void)
+static int env_fat_save(struct env_context *ctx)
 {
-	env_t __aligned(ARCH_DMA_MINALIGN) env_new;
+	env_hdr_t *env_new;
 	struct blk_desc *dev_desc = NULL;
 	disk_partition_t info;
 	int dev, part;
+	struct env_fat_context *params = ctx->drv_params[ENVL_FAT];
 	int err;
 	loff_t size;
 
-	err = env_export(&env_new);
+	if (!params)
+		return 1;
+
+	env_new = malloc_cache_aligned(sizeof(env_hdr_t) + ctx->env_size);
+	if (!env_new)
+		return 1;
+
+	err = env_export(ctx, env_new);
 	if (err)
-		return err;
+		goto out;
+	err = 1;
 
-	part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
-					CONFIG_ENV_FAT_DEVICE_AND_PART,
-					&dev_desc, &info, 1);
+	part = blk_get_device_part_str(params->interface,
+				       params->dev_and_part,
+				       &dev_desc, &info, 1);
 	if (part < 0)
-		return 1;
+		goto out;
 
 	dev = dev_desc->devnum;
 	if (fat_set_blk_dev(dev_desc, &info) != 0) {
@@ -58,43 +90,51 @@ static int env_fat_save(void)
 		 * will calling it. The missing \n is intentional.
 		 */
 		printf("Unable to use %s %d:%d... ",
-		       CONFIG_ENV_FAT_INTERFACE, dev, part);
-		return 1;
+		       params->interface, dev, part);
+		goto out;
 	}
 
-	err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
-			     &size);
+	err = file_fat_write(params->file, (void *)env_new, 0,
+			     sizeof(env_hdr_t) + ctx->env_size, &size);
 	if (err == -1) {
 		/*
 		 * This printf is embedded in the messages from env_save that
 		 * will calling it. The missing \n is intentional.
 		 */
 		printf("Unable to write \"%s\" from %s%d:%d... ",
-			CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
-		return 1;
+			params->file, params->interface, dev, part);
+		err = 1;
+		goto out;
 	}
+	err = 0;
+out:
+	free(env_new);
 
-	return 0;
+	return err;
 }
 #endif /* CMD_SAVEENV */
 
 #ifdef LOADENV
-static int env_fat_load(void)
+static int env_fat_load(struct env_context *ctx)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
+	struct env_fat_context *params = ctx->drv_params[ENVL_FAT];
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, sizeof(env_hdr_t) + ctx->env_size);
 	struct blk_desc *dev_desc = NULL;
 	disk_partition_t info;
 	int dev, part;
 	int err;
 
+	if (!params)
+		return -ENODEV;
+
 #ifdef CONFIG_MMC
-	if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
+	if (!strcmp(params->interface, "mmc"))
 		mmc_initialize(NULL);
 #endif
 
-	part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
-					CONFIG_ENV_FAT_DEVICE_AND_PART,
-					&dev_desc, &info, 1);
+	part = blk_get_device_part_str(params->interface,
+				       params->dev_and_part,
+				       &dev_desc, &info, 1);
 	if (part < 0)
 		goto err_env_relocate;
 
@@ -105,30 +145,39 @@ static int env_fat_load(void)
 		 * will calling it. The missing \n is intentional.
 		 */
 		printf("Unable to use %s %d:%d... ",
-		       CONFIG_ENV_FAT_INTERFACE, dev, part);
+		       params->interface, dev, part);
 		goto err_env_relocate;
 	}
 
-	err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
+	err = file_fat_read(params->file, buf,
+			    sizeof(env_hdr_t) + ctx->env_size);
 	if (err == -1) {
 		/*
 		 * This printf is embedded in the messages from env_save that
 		 * will calling it. The missing \n is intentional.
 		 */
 		printf("Unable to read \"%s\" from %s%d:%d... ",
-			CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
+			params->file, params->interface, dev, part);
 		goto err_env_relocate;
 	}
 
-	return env_import(buf, 1);
+	return env_import(ctx, buf, 1);
 
 err_env_relocate:
-	env_set_default(NULL, 0);
+	env_set_default(ctx, NULL, 0);
 
 	return -EIO;
 }
 #endif /* LOADENV */
 
+static int env_fat_init(struct env_context *ctx)
+{
+	if (ctx->drv_init)
+		return ctx->drv_init(ctx, ENVL_FAT);
+
+	return -ENOENT;
+}
+
 U_BOOT_ENV_LOCATION(fat) = {
 	.location	= ENVL_FAT,
 	ENV_NAME("FAT")
@@ -138,4 +187,5 @@ U_BOOT_ENV_LOCATION(fat) = {
 #ifdef CMD_SAVEENV
 	.save		= env_save_ptr(env_fat_save),
 #endif
+	.init		= env_fat_init,
 };
diff --git a/include/env.h b/include/env.h
index 9b4b9debc36d..8045dda9f811 100644
--- a/include/env.h
+++ b/include/env.h
@@ -398,5 +398,7 @@ int env_flash_init_params(struct env_context *ctx,
 			  struct environment_hdr *flash_addr_new,
 			  ulong end_addr_new,
 			  ulong default_env_addr);
+int env_fat_init_params(struct env_context *ctx, const char *interface,
+			const char *dev_part, const char *file);
 
 #endif
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 06/19] hashtable: support multiple env contexts
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (4 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 05/19] env: fat: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 07/19] api: converted with new env interfaces AKASHI Takahiro
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

With this patch, variable's context is always honored in all operations,
FIND/ENTER (including delete).

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 include/search.h |  6 +++++-
 lib/hashtable.c  | 14 +++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/search.h b/include/search.h
index 0469a852e07c..202cf652de5f 100644
--- a/include/search.h
+++ b/include/search.h
@@ -25,13 +25,16 @@ enum env_action {
 	ENV_ENTER,
 };
 
+struct env_context;
+
 /** struct env_entry - An entry in the environment hashtable */
 struct env_entry {
 	const char *key;
 	char *data;
 	int (*callback)(const char *name, const char *value, enum env_op op,
-		int flags);
+			int flags);
 	int flags;
+	struct env_context *ctx;
 };
 
 /*
@@ -45,6 +48,7 @@ struct hsearch_data {
 	struct env_entry_node *table;
 	unsigned int size;
 	unsigned int filled;
+	struct env_context *ctx;
 /*
  * Callback function which will check whether the given change for variable
  * "item" to "newval" may be applied or not, and possibly apply such change.
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 2caab0a4c6d3..8fe017470256 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -231,6 +231,7 @@ static inline int _compare_and_overwrite_entry(struct env_entry item,
 		unsigned int idx)
 {
 	if (htab->table[idx].used == hval
+	    && (item.ctx && (item.ctx == htab->table[idx].entry.ctx))
 	    && strcmp(item.key, htab->table[idx].entry.key) == 0) {
 		/* Overwrite existing value? */
 		if (action == ENV_ENTER && item.data) {
@@ -247,8 +248,9 @@ static inline int _compare_and_overwrite_entry(struct env_entry item,
 
 			/* If there is a callback, call it */
 			if (htab->table[idx].entry.callback &&
-			    htab->table[idx].entry.callback(item.key,
-			    item.data, env_op_overwrite, flag)) {
+			    htab->table[idx].entry.callback(item.key, item.data,
+							    env_op_overwrite,
+							    flag)) {
 				debug("callback() rejected setting variable "
 					"%s, skipping it!\n", item.key);
 				__set_errno(EINVAL);
@@ -340,6 +342,9 @@ int hsearch_r(struct env_entry item, enum env_action action,
 			if (idx == hval)
 				break;
 
+			if (htab->table[idx].used == USED_FREE)
+				break;
+
 			if (htab->table[idx].used == USED_DELETED
 			    && !first_deleted)
 				first_deleted = idx;
@@ -381,6 +386,7 @@ int hsearch_r(struct env_entry item, enum env_action action,
 			*retval = NULL;
 			return 0;
 		}
+		htab->table[idx].entry.ctx = item.ctx;
 
 		++htab->filled;
 
@@ -403,7 +409,7 @@ int hsearch_r(struct env_entry item, enum env_action action,
 		/* If there is a callback, call it */
 		if (htab->table[idx].entry.callback &&
 		    htab->table[idx].entry.callback(item.key, item.data,
-		    env_op_create, flag)) {
+						    env_op_create, flag)) {
 			debug("callback() rejected setting variable "
 				"%s, skipping it!\n", item.key);
 			_hdelete(item.key, htab, &htab->table[idx].entry, idx);
@@ -454,6 +460,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag)
 
 	debug("hdelete: DELETE key \"%s\"\n", key);
 
+	e.ctx = htab->ctx;
 	e.key = (char *)key;
 
 	idx = hsearch_r(e, ENV_FIND, &ep, htab, 0);
@@ -928,6 +935,7 @@ int himport_r(struct hsearch_data *htab,
 			continue;
 
 		/* enter into hash table */
+		e.ctx = htab->ctx;
 		e.key = name;
 		e.data = value;
 
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 07/19] api: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (5 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 06/19] hashtable: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 08/19] arch: " AKASHI Takahiro
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 api/api.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/api/api.c b/api/api.c
index bc9454eb4b63..d1dd8bfc60af 100644
--- a/api/api.c
+++ b/api/api.c
@@ -458,7 +458,8 @@ static int API_env_get(va_list ap)
 	if ((value = (char **)va_arg(ap, uintptr_t)) == NULL)
 		return API_EINVAL;
 
-	*value = env_get(name);
+	/* TODO: context */
+	*value = env_get(ctx_uboot, name);
 
 	return 0;
 }
@@ -481,7 +482,8 @@ static int API_env_set(va_list ap)
 	if ((value = (char *)va_arg(ap, uintptr_t)) == NULL)
 		return API_EINVAL;
 
-	env_set(name, value);
+	/* TODO: context */
+	env_set(ctx_uboot, name, value);
 
 	return 0;
 }
@@ -663,7 +665,7 @@ void api_init(void)
 		return;
 	}
 
-	env_set_hex("api_address", (unsigned long)sig);
+	env_set_hex(ctx_uboot, "api_address", (unsigned long)sig);
 	debugf("API sig @ 0x%lX\n", (unsigned long)sig);
 	memcpy(sig->magic, API_SIG_MAGIC, 8);
 	sig->version = API_SIG_VERSION;
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 08/19] arch: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (6 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 07/19] api: converted with new env interfaces AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 09/19] board: " AKASHI Takahiro
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 arch/arc/lib/bootm.c                          |  2 +-
 arch/arm/cpu/arm926ejs/spear/spr_misc.c       |  8 ++---
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c       |  5 +--
 arch/arm/cpu/armv8/fsl-layerscape/soc.c       | 14 ++++----
 arch/arm/lib/bootm.c                          |  6 ++--
 arch/arm/lib/semihosting.c                    |  2 +-
 arch/arm/mach-imx/mx6/opos6ul.c               |  4 +--
 arch/arm/mach-imx/mx7/soc.c                   |  4 +--
 arch/arm/mach-imx/video.c                     |  2 +-
 arch/arm/mach-keystone/ddr3.c                 |  2 +-
 arch/arm/mach-keystone/keystone.c             |  2 +-
 arch/arm/mach-kirkwood/cpu.c                  |  4 +--
 arch/arm/mach-meson/board-common.c            |  2 +-
 arch/arm/mach-omap2/utils.c                   | 20 +++++------
 arch/arm/mach-rmobile/cpu_info.c              |  2 +-
 arch/arm/mach-rockchip/boot_mode.c            |  4 +--
 arch/arm/mach-rockchip/rk3288/rk3288.c        |  2 +-
 arch/arm/mach-socfpga/misc_gen5.c             |  5 +--
 arch/arm/mach-socfpga/misc_s10.c              |  2 +-
 arch/arm/mach-stm32mp/cpu.c                   | 35 ++++++++++---------
 arch/arm/mach-tegra/board2.c                  |  4 +--
 arch/arm/mach-tegra/cboot.c                   | 18 +++++-----
 arch/arm/mach-uniphier/board_late_init.c      | 19 +++++-----
 arch/arm/mach-uniphier/mmc-first-dev.c        |  2 +-
 arch/m68k/lib/bootm.c                         |  2 +-
 arch/microblaze/lib/bootm.c                   |  2 +-
 arch/mips/lib/bootm.c                         |  6 ++--
 arch/nds32/lib/bootm.c                        |  4 +--
 arch/powerpc/cpu/mpc85xx/cpu_init.c           | 10 +++---
 arch/powerpc/cpu/mpc85xx/fdt.c                |  2 +-
 arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |  2 +-
 arch/powerpc/lib/bootm.c                      |  2 +-
 arch/sh/lib/bootm.c                           |  2 +-
 arch/sh/lib/zimageboot.c                      |  2 +-
 arch/x86/lib/zimage.c                         | 11 +++---
 arch/xtensa/lib/bootm.c                       |  2 +-
 36 files changed, 111 insertions(+), 106 deletions(-)

diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c
index 254e0284b3fb..fb11d6c8c08b 100644
--- a/arch/arc/lib/bootm.c
+++ b/arch/arc/lib/bootm.c
@@ -91,7 +91,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 		r2 = (unsigned int)images->ft_addr;
 	} else {
 		r0 = 1;
-		r2 = (unsigned int)env_get("bootargs");
+		r2 = (unsigned int)env_get(ctx_uboot, "bootargs");
 	}
 
 	cleanup_before_linux();
diff --git a/arch/arm/cpu/arm926ejs/spear/spr_misc.c b/arch/arm/cpu/arm926ejs/spear/spr_misc.c
index d36484c9d69a..78ef0650dd1f 100644
--- a/arch/arm/cpu/arm926ejs/spear/spr_misc.c
+++ b/arch/arm/cpu/arm926ejs/spear/spr_misc.c
@@ -56,12 +56,12 @@ int misc_init_r(void)
 	if (!eth_env_get_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
 		eth_env_set_enetaddr("ethaddr", mac_id);
 #endif
-	env_set("verify", "n");
+	env_set(ctx_uboot, "verify", "n");
 
 #if defined(CONFIG_SPEAR_USBTTY)
-	env_set("stdin", "usbtty");
-	env_set("stdout", "usbtty");
-	env_set("stderr", "usbtty");
+	env_set(ctx_uboot, "stdin", "usbtty");
+	env_set(ctx_uboot, "stdout", "usbtty");
+	env_set(ctx_uboot, "stderr", "usbtty");
 
 #ifndef CONFIG_SYS_NO_DCACHE
 	dcache_enable();
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 26f4fdacdb82..f42ce1f9aefb 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -801,7 +801,8 @@ int mmc_get_env_dev(void)
 }
 #endif
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	enum boot_src src = get_boot_src();
 	enum env_location env_loc = ENVL_NOWHERE;
@@ -1067,7 +1068,7 @@ static void config_core_prefetch(void)
 	unsigned int mask;
 	struct pt_regs regs;
 
-	if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
+	if (env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer)) > 0)
 		buf = buffer;
 
 	prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable",
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/soc.c b/arch/arm/cpu/armv8/fsl-layerscape/soc.c
index 3fd34e3a435d..9300e8de8e04 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/soc.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/soc.c
@@ -761,7 +761,7 @@ int fsl_setenv_bootcmd(void)
 		break;
 	}
 
-	ret = env_set("bootcmd", bootcmd_str);
+	ret = env_set(ctx_uboot, "bootcmd", bootcmd_str);
 	if (ret) {
 		printf("Failed to set bootcmd: ret = %d\n", ret);
 		return ret;
@@ -778,34 +778,34 @@ int fsl_setenv_mcinitcmd(void)
 #ifdef IFC_MC_INIT_CMD
 	case BOOT_SOURCE_IFC_NAND:
 	case BOOT_SOURCE_IFC_NOR:
-	ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", IFC_MC_INIT_CMD);
 		break;
 #endif
 #ifdef QSPI_MC_INIT_CMD
 	case BOOT_SOURCE_QSPI_NAND:
 	case BOOT_SOURCE_QSPI_NOR:
-	ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", QSPI_MC_INIT_CMD);
 		break;
 #endif
 #ifdef XSPI_MC_INIT_CMD
 	case BOOT_SOURCE_XSPI_NAND:
 	case BOOT_SOURCE_XSPI_NOR:
-	ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", XSPI_MC_INIT_CMD);
 		break;
 #endif
 #ifdef SD_MC_INIT_CMD
 	case BOOT_SOURCE_SD_MMC:
-	ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", SD_MC_INIT_CMD);
 		break;
 #endif
 #ifdef SD2_MC_INIT_CMD
 	case BOOT_SOURCE_SD_MMC2:
-	ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", SD2_MC_INIT_CMD);
 		break;
 #endif
 	default:
 #ifdef QSPI_MC_INIT_CMD
-	ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
+	ret = env_set(ctx_uboot, "mcinitcmd", QSPI_MC_INIT_CMD);
 #endif
 		break;
 	}
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 1638f1e81d70..df105bc6da72 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -227,7 +227,7 @@ static void do_nonsec_virt_switch(void)
 /* Subcommand: PREP */
 static void boot_prep_linux(bootm_headers_t *images)
 {
-	char *commandline = env_get("bootargs");
+	char *commandline = env_get(ctx_uboot, "bootargs");
 
 	if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
@@ -284,7 +284,7 @@ __weak bool armv7_boot_nonsec_default(void)
 #ifdef CONFIG_ARMV7_NONSEC
 bool armv7_boot_nonsec(void)
 {
-	char *s = env_get("bootm_boot_mode");
+	char *s = env_get(ctx_uboot, "bootm_boot_mode");
 	bool nonsec = armv7_boot_nonsec_default();
 
 	if (s && !strcmp(s, "sec"))
@@ -372,7 +372,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 	ulong addr = (ulong)kernel_entry | 1;
 	kernel_entry = (void *)addr;
 #endif
-	s = env_get("machid");
+	s = env_get(ctx_uboot, "machid");
 	if (s) {
 		if (strict_strtoul(s, 16, &machid) < 0) {
 			debug("strict_strtoul failed!\n");
diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 2658026cf49e..73d18053a1c8 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -199,7 +199,7 @@ static int do_smhload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		/* Optionally save returned end to the environment */
 		if (argc == 4) {
 			sprintf(end_str, "0x%08lx", end_addr);
-			env_set(argv[3], end_str);
+			env_set(ctx_uboot, argv[3], end_str);
 		}
 	} else {
 		return CMD_RET_USAGE;
diff --git a/arch/arm/mach-imx/mx6/opos6ul.c b/arch/arm/mach-imx/mx6/opos6ul.c
index 3ab9a3f022f7..a1eb8bbe8417 100644
--- a/arch/arm/mach-imx/mx6/opos6ul.c
+++ b/arch/arm/mach-imx/mx6/opos6ul.c
@@ -127,8 +127,8 @@ int board_late_init(void)
 
 	/* In bootstrap don't use the env vars */
 	if (((reg & 0x3000000) >> 24) == 0x1) {
-		env_set_default(NULL, 0);
-		env_set("preboot", "");
+		env_set_default(ctx_uboot, NULL, 0);
+		env_set(ctx_uboot, "preboot", "");
 	}
 
 	return opos6ul_board_late_init();
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c
index 3b8e1ba9c3ac..365488858d39 100644
--- a/arch/arm/mach-imx/mx7/soc.c
+++ b/arch/arm/mach-imx/mx7/soc.c
@@ -307,9 +307,9 @@ int arch_misc_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (is_mx7d())
-		env_set("soc", "imx7d");
+		env_set(ctx_uboot, "soc", "imx7d");
 	else
-		env_set("soc", "imx7s");
+		env_set(ctx_uboot, "soc", "imx7s");
 #endif
 
 #ifdef CONFIG_FSL_CAAM
diff --git a/arch/arm/mach-imx/video.c b/arch/arm/mach-imx/video.c
index 1bc9b7cc7e15..2deb5b1f9382 100644
--- a/arch/arm/mach-imx/video.c
+++ b/arch/arm/mach-imx/video.c
@@ -20,7 +20,7 @@ int board_video_skip(void)
 {
 	int i;
 	int ret = 0;
-	char const *panel = env_get("panel");
+	char const *panel = env_get(ctx_uboot, "panel");
 
 	if (!panel) {
 		for (i = 0; i < display_count; i++) {
diff --git a/arch/arm/mach-keystone/ddr3.c b/arch/arm/mach-keystone/ddr3.c
index 863ae6321ba3..04559e015bb8 100644
--- a/arch/arm/mach-keystone/ddr3.c
+++ b/arch/arm/mach-keystone/ddr3.c
@@ -330,7 +330,7 @@ void ddr3_check_ecc_int(u32 base)
 	int ecc_test = 0;
 	u32 value = __raw_readl(base + KS2_DDR3_ECC_INT_STATUS_OFFSET);
 
-	env = env_get("ecc_test");
+	env = env_get(ctx_uboot, "ecc_test");
 	if (env)
 		ecc_test = simple_strtol(env, NULL, 0);
 
diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
index 7441052a5539..7b1f9e209670 100644
--- a/arch/arm/mach-keystone/keystone.c
+++ b/arch/arm/mach-keystone/keystone.c
@@ -45,7 +45,7 @@ int misc_init_r(void)
 	char *env;
 	long ks2_debug = 0;
 
-	env = env_get("ks2_debug");
+	env = env_get(ctx_uboot, "ks2_debug");
 
 	if (env)
 		ks2_debug = simple_strtol(env, NULL, 0);
diff --git a/arch/arm/mach-kirkwood/cpu.c b/arch/arm/mach-kirkwood/cpu.c
index 6ad254343867..31ee6714458a 100644
--- a/arch/arm/mach-kirkwood/cpu.c
+++ b/arch/arm/mach-kirkwood/cpu.c
@@ -91,7 +91,7 @@ static struct mbus_win windows[] = {
 static void kw_sysrst_action(void)
 {
 	int ret;
-	char *s = env_get("sysrstcmd");
+	char *s = env_get(ctx_uboot, "sysrstcmd");
 
 	if (!s) {
 		debug("Error.. %s failed, check sysrstcmd\n",
@@ -115,7 +115,7 @@ static void kw_sysrst_check(void)
 	/*
 	 * no action if sysrstdelay environment variable is not defined
 	 */
-	s = env_get("sysrstdelay");
+	s = env_get(ctx_uboot, "sysrstdelay");
 	if (s == NULL)
 		return;
 
diff --git a/arch/arm/mach-meson/board-common.c b/arch/arm/mach-meson/board-common.c
index d261b4ea331c..4f005e97fc75 100644
--- a/arch/arm/mach-meson/board-common.c
+++ b/arch/arm/mach-meson/board-common.c
@@ -132,7 +132,7 @@ static void meson_set_boot_source(void)
 		source = "unknown";
 	}
 
-	env_set("boot_source", source);
+	env_set(ctx_uboot, "boot_source", source);
 }
 
 __weak int meson_board_late_init(void)
diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c
index 0d5ca20e8e87..0d0f33c5e576 100644
--- a/arch/arm/mach-omap2/utils.c
+++ b/arch/arm/mach-omap2/utils.c
@@ -48,7 +48,7 @@ static void omap_set_fastboot_cpu(void)
 		printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
 	}
 
-	env_set("fastboot.cpu", cpu);
+	env_set(ctx_uboot, "fastboot.cpu", cpu);
 }
 
 static void omap_set_fastboot_secure(void)
@@ -71,18 +71,18 @@ static void omap_set_fastboot_secure(void)
 		printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
 	}
 
-	env_set("fastboot.secure", secure);
+	env_set(ctx_uboot, "fastboot.secure", secure);
 }
 
 static void omap_set_fastboot_board_rev(void)
 {
 	const char *board_rev;
 
-	board_rev = env_get("board_rev");
+	board_rev = env_get(ctx_uboot, "board_rev");
 	if (board_rev == NULL)
 		printf("Warning: fastboot.board_rev: unknown board revision\n");
 
-	env_set("fastboot.board_rev", board_rev);
+	env_set(ctx_uboot, "fastboot.board_rev", board_rev);
 }
 
 #ifdef CONFIG_FASTBOOT_FLASH_MMC
@@ -122,7 +122,7 @@ static void omap_set_fastboot_userdata_size(void)
 		return; /* probably it's not Android partition table */
 
 	sprintf(buf, "%u", sz_kb);
-	env_set("fastboot.userdata_size", buf);
+	env_set(ctx_uboot, "fastboot.userdata_size", buf);
 }
 #else
 static inline void omap_set_fastboot_userdata_size(void)
@@ -186,11 +186,11 @@ void omap_die_id_serial(void)
 
 	omap_die_id((unsigned int *)&die_id);
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		snprintf(serial_string, sizeof(serial_string),
 			"%08x%08x", die_id[0], die_id[3]);
 
-		env_set("serial#", serial_string);
+		env_set(ctx_uboot, "serial#", serial_string);
 	}
 }
 
@@ -199,7 +199,7 @@ void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
 	char *serial_string;
 	unsigned long long serial;
 
-	serial_string = env_get("serial#");
+	serial_string = env_get(ctx_uboot, "serial#");
 
 	if (serial_string) {
 		serial = simple_strtoull(serial_string, NULL, 16);
@@ -219,7 +219,7 @@ void omap_die_id_usbethaddr(void)
 
 	omap_die_id((unsigned int *)&die_id);
 
-	if (!env_get("usbethaddr")) {
+	if (!env_get(ctx_uboot, "usbethaddr")) {
 		/*
 		 * Create a fake MAC address from the processor ID code.
 		 * First byte is 0x02 to signify locally administered.
@@ -233,7 +233,7 @@ void omap_die_id_usbethaddr(void)
 
 		eth_env_set_enetaddr("usbethaddr", mac);
 
-		if (!env_get("ethaddr"))
+		if (!env_get(ctx_uboot, "ethaddr"))
 			eth_env_set_enetaddr("ethaddr", mac);
 	}
 }
diff --git a/arch/arm/mach-rmobile/cpu_info.c b/arch/arm/mach-rmobile/cpu_info.c
index 9ef94a489935..35528a3b90f8 100644
--- a/arch/arm/mach-rmobile/cpu_info.c
+++ b/arch/arm/mach-rmobile/cpu_info.c
@@ -92,7 +92,7 @@ int arch_misc_init(void)
 	for (i = 0; i < sizeof(cpu); i++)
 		cpu[i] = tolower(rmobile_cpuinfo[idx].cpu_name[i]);
 
-	env_set("platform", cpu);
+	env_set(ctx_uboot, "platform", cpu);
 
 	return 0;
 }
diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c
index 08f80bd91aae..158f01e830f5 100644
--- a/arch/arm/mach-rockchip/boot_mode.c
+++ b/arch/arm/mach-rockchip/boot_mode.c
@@ -72,11 +72,11 @@ int setup_boot_mode(void)
 	switch (boot_mode) {
 	case BOOT_FASTBOOT:
 		debug("%s: enter fastboot!\n", __func__);
-		env_set("preboot", "setenv preboot; fastboot usb0");
+		env_set(ctx_uboot, "preboot", "setenv preboot; fastboot usb0");
 		break;
 	case BOOT_UMS:
 		debug("%s: enter UMS!\n", __func__);
-		env_set("preboot", "setenv preboot; ums mmc 0");
+		env_set(ctx_uboot, "preboot", "setenv preboot; ums mmc 0");
 		break;
 	}
 
diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c b/arch/arm/mach-rockchip/rk3288/rk3288.c
index 057ce920809e..83a7ebc4c1a1 100644
--- a/arch/arm/mach-rockchip/rk3288/rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/rk3288.c
@@ -129,7 +129,7 @@ static void rk3288_detect_reset_reason(void)
 		reason = "unknown reset";
 	}
 
-	env_set("reset_reason", reason);
+	env_set(ctx_uboot, "reset_reason", reason);
 
 	/*
 	 * Clear cru_glb_rst_st, so we can determine the last reset cause
diff --git a/arch/arm/mach-socfpga/misc_gen5.c b/arch/arm/mach-socfpga/misc_gen5.c
index 31681b799d46..f56c86ee4500 100644
--- a/arch/arm/mach-socfpga/misc_gen5.c
+++ b/arch/arm/mach-socfpga/misc_gen5.c
@@ -134,9 +134,10 @@ int arch_misc_init(void)
 {
 	const u32 bsel = readl(&sysmgr_regs->bootinfo) & 0x7;
 	const int fpga_id = socfpga_fpga_id(0);
-	env_set("bootmode", bsel_str[bsel].mode);
+	env_set(ctx_uboot, "bootmode", bsel_str[bsel].mode);
 	if (fpga_id >= 0)
-		env_set("fpgatype", socfpga_fpga_model[fpga_id].var);
+		env_set(ctx_uboot, "fpgatype",
+			socfpga_fpga_model[fpga_id].var);
 	return 0;
 }
 #endif
diff --git a/arch/arm/mach-socfpga/misc_s10.c b/arch/arm/mach-socfpga/misc_s10.c
index 0a5fab11c0de..c7bec59aff94 100644
--- a/arch/arm/mach-socfpga/misc_s10.c
+++ b/arch/arm/mach-socfpga/misc_s10.c
@@ -138,7 +138,7 @@ int arch_misc_init(void)
 	char qspi_string[13];
 
 	sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz());
-	env_set("qspi_clock", qspi_string);
+	env_set(ctx_uboot, "qspi_clock", qspi_string);
 
 	socfpga_set_phymode();
 	return 0;
diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index a46e8438f7c2..6aa7d26bf87b 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -380,8 +380,8 @@ static void setup_boot_mode(void)
 					 dev_of_offset(dev), &alias))
 			break;
 		sprintf(cmd, "%d", alias);
-		env_set("boot_device", "serial");
-		env_set("boot_instance", cmd);
+		env_set(ctx_uboot, "boot_device", "serial");
+		env_set(ctx_uboot, "boot_instance", cmd);
 
 		/* restore console on uart when not used */
 		if (gd->cur_serial_dev != dev) {
@@ -391,22 +391,22 @@ static void setup_boot_mode(void)
 		}
 		break;
 	case BOOT_SERIAL_USB:
-		env_set("boot_device", "usb");
-		env_set("boot_instance", "0");
+		env_set(ctx_uboot, "boot_device", "usb");
+		env_set(ctx_uboot, "boot_instance", "0");
 		break;
 	case BOOT_FLASH_SD:
 	case BOOT_FLASH_EMMC:
 		sprintf(cmd, "%d", instance);
-		env_set("boot_device", "mmc");
-		env_set("boot_instance", cmd);
+		env_set(ctx_uboot, "boot_device", "mmc");
+		env_set(ctx_uboot, "boot_instance", cmd);
 		break;
 	case BOOT_FLASH_NAND:
-		env_set("boot_device", "nand");
-		env_set("boot_instance", "0");
+		env_set(ctx_uboot, "boot_device", "nand");
+		env_set(ctx_uboot, "boot_instance", "0");
 		break;
 	case BOOT_FLASH_NOR:
-		env_set("boot_device", "nor");
-		env_set("boot_instance", "0");
+		env_set(ctx_uboot, "boot_device", "nor");
+		env_set(ctx_uboot, "boot_instance", "0");
 		break;
 	default:
 		pr_debug("unexpected boot mode = %x\n", boot_mode);
@@ -416,11 +416,11 @@ static void setup_boot_mode(void)
 	switch (forced_mode) {
 	case BOOT_FASTBOOT:
 		printf("Enter fastboot!\n");
-		env_set("preboot", "env set preboot; fastboot 0");
+		env_set(ctx_uboot, "preboot", "env set preboot; fastboot 0");
 		break;
 	case BOOT_STM32PROG:
-		env_set("boot_device", "usb");
-		env_set("boot_instance", "0");
+		env_set(ctx_uboot, "boot_device", "usb");
+		env_set(ctx_uboot, "boot_instance", "0");
 		break;
 	case BOOT_UMS_MMC0:
 	case BOOT_UMS_MMC1:
@@ -428,10 +428,11 @@ static void setup_boot_mode(void)
 		printf("Enter UMS!\n");
 		instance = forced_mode - BOOT_UMS_MMC0;
 		sprintf(cmd, "env set preboot; ums 0 mmc %d", instance);
-		env_set("preboot", cmd);
+		env_set(ctx_uboot, "preboot", cmd);
 		break;
 	case BOOT_RECOVERY:
-		env_set("preboot", "env set preboot; run altbootcmd");
+		env_set(ctx_uboot, "preboot",
+			"env set preboot; run altbootcmd");
 		break;
 	case BOOT_NORMAL:
 		break;
@@ -496,7 +497,7 @@ static int setup_serial_number(void)
 	struct udevice *dev;
 	int ret;
 
-	if (env_get("serial#"))
+	if (env_get(ctx_uboot, "serial#"))
 		return 0;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
@@ -511,7 +512,7 @@ static int setup_serial_number(void)
 		return ret;
 
 	sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
-	env_set("serial#", serial_string);
+	env_set(ctx_uboot, "serial#", serial_string);
 
 	return 0;
 }
diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c
index f13bd256cc2a..1711424151ca 100644
--- a/arch/arm/mach-tegra/board2.c
+++ b/arch/arm/mach-tegra/board2.c
@@ -240,9 +240,9 @@ int board_late_init(void)
 #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
 	if (tegra_cpu_is_non_secure()) {
 		printf("CPU is in NS mode\n");
-		env_set("cpu_ns_mode", "1");
+		env_set(ctx_uboot, "cpu_ns_mode", "1");
 	} else {
-		env_set("cpu_ns_mode", "");
+		env_set(ctx_uboot, "cpu_ns_mode", "");
 	}
 #endif
 	start_cpu_fan();
diff --git a/arch/arm/mach-tegra/cboot.c b/arch/arm/mach-tegra/cboot.c
index 0433081c6c55..ec24447a6b4a 100644
--- a/arch/arm/mach-tegra/cboot.c
+++ b/arch/arm/mach-tegra/cboot.c
@@ -315,7 +315,7 @@ static void set_calculated_aliases(char *aliases, u64 address)
 		if (!alias)
 			break;
 		debug("%s: alias: %s\n", __func__, alias);
-		err = env_set_hex(alias, address);
+		err = env_set_hex(ctx_uboot, alias, address);
 		if (err)
 			pr_err("Could not set %s\n", alias);
 	}
@@ -349,17 +349,17 @@ static void set_calculated_env_var(const char *var)
 	if (!var_aliases)
 		goto out_free_var_offset;
 
-	size = env_get_hex(var_size, 0);
+	size = env_get_hex(ctx_uboot, var_size, 0);
 	if (!size) {
 		pr_err("%s not set or zero\n", var_size);
 		goto out_free_var_aliases;
 	}
-	align = env_get_hex(var_align, 1);
+	align = env_get_hex(ctx_uboot, var_align, 1);
 	/* Handle extant variables, but with a value of 0 */
 	if (!align)
 		align = 1;
-	offset = env_get_hex(var_offset, 0);
-	aliases = env_get(var_aliases);
+	offset = env_get_hex(ctx_uboot, var_offset, 0);
+	aliases = env_get(ctx_uboot, var_aliases);
 
 	debug("%s: Calc var %s; size=%llx, align=%llx, offset=%llx\n",
 	      __func__, var, size, align, offset);
@@ -373,7 +373,7 @@ static void set_calculated_env_var(const char *var)
 	}
 	debug("%s: Address %llx\n", __func__, address);
 
-	err = env_set_hex(var, address);
+	err = env_set_hex(ctx_uboot, var, address);
 	if (err)
 		pr_err("Could not set %s\n", var);
 	if (aliases)
@@ -423,7 +423,7 @@ static void set_calculated_env_vars(void)
 	dump_ram_banks();
 #endif
 
-	vars = env_get("calculated_vars");
+	vars = env_get(ctx_uboot, "calculated_vars");
 	if (!vars) {
 		debug("%s: No env var calculated_vars\n", __func__);
 		return;
@@ -455,7 +455,7 @@ static int set_fdt_addr(void)
 {
 	int ret;
 
-	ret = env_set_hex("fdt_addr", cboot_boot_x0);
+	ret = env_set_hex(ctx_uboot, "fdt_addr", cboot_boot_x0);
 	if (ret) {
 		printf("Failed to set fdt_addr to point at DTB: %d\n", ret);
 		return ret;
@@ -612,7 +612,7 @@ int cboot_late_init(void)
 
 	bootargs = cboot_get_bootargs(fdt);
 	if (bootargs) {
-		env_set("cbootargs", bootargs);
+		env_set(ctx_uboot, "cbootargs", bootargs);
 		free(bootargs);
 	}
 
diff --git a/arch/arm/mach-uniphier/board_late_init.c b/arch/arm/mach-uniphier/board_late_init.c
index 14b61fc7dfda..4eefe85c539d 100644
--- a/arch/arm/mach-uniphier/board_late_init.c
+++ b/arch/arm/mach-uniphier/board_late_init.c
@@ -40,7 +40,7 @@ static void uniphier_set_env_fdt_file(void)
 	int buf_len = sizeof(dtb_name);
 	int ret;
 
-	if (env_get("fdtfile"))
+	if (env_get(ctx_uboot, "fdtfile"))
 		return;		/* do nothing if it is already set */
 
 	compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
@@ -58,7 +58,7 @@ static void uniphier_set_env_fdt_file(void)
 
 	strncat(dtb_name, ".dtb", buf_len);
 
-	ret = env_set("fdtfile", dtb_name);
+	ret = env_set(ctx_uboot, "fdtfile", dtb_name);
 	if (ret)
 		goto fail;
 
@@ -74,11 +74,11 @@ static void uniphier_set_env_addr(const char *env, const char *offset_env)
 	char *end;
 	int ret;
 
-	if (env_get(env))
+	if (env_get(ctx_uboot, env))
 		return;		/* do nothing if it is already set */
 
 	if (offset_env) {
-		str = env_get(offset_env);
+		str = env_get(ctx_uboot, offset_env);
 		if (!str)
 			goto fail;
 
@@ -87,7 +87,7 @@ static void uniphier_set_env_addr(const char *env, const char *offset_env)
 			goto fail;
 	}
 
-	ret = env_set_hex(env, gd->ram_base + offset);
+	ret = env_set_hex(ctx_uboot, env, gd->ram_base + offset);
 	if (ret)
 		goto fail;
 
@@ -95,6 +95,7 @@ static void uniphier_set_env_addr(const char *env, const char *offset_env)
 
 fail:
 	pr_warn("\"%s\" environment variable was not set correctly\n", env);
+	return env_set(ctx_uboot, "fdtfile", dtb_name);
 }
 
 int board_late_init(void)
@@ -104,7 +105,7 @@ int board_late_init(void)
 	switch (uniphier_boot_device_raw()) {
 	case BOOT_DEVICE_MMC1:
 		printf("eMMC Boot");
-		env_set("bootdev", "emmc");
+		env_set(ctx_uboot, "bootdev", "emmc");
 		break;
 	case BOOT_DEVICE_MMC2:
 		printf("SD Boot");
@@ -112,16 +113,16 @@ int board_late_init(void)
 		break;
 	case BOOT_DEVICE_NAND:
 		printf("NAND Boot");
-		env_set("bootdev", "nand");
+		env_set(ctx_uboot, "bootdev", "nand");
 		nand_denali_wp_disable();
 		break;
 	case BOOT_DEVICE_NOR:
 		printf("NOR Boot");
-		env_set("bootdev", "nor");
+		env_set(ctx_uboot, "bootdev", "nor");
 		break;
 	case BOOT_DEVICE_USB:
 		printf("USB Boot");
-		env_set("bootdev", "usb");
+		env_set(ctx_uboot, "bootdev", "usb");
 		break;
 	default:
 		printf("Unknown");
diff --git a/arch/arm/mach-uniphier/mmc-first-dev.c b/arch/arm/mach-uniphier/mmc-first-dev.c
index 149e662070ff..0298813303ba 100644
--- a/arch/arm/mach-uniphier/mmc-first-dev.c
+++ b/arch/arm/mach-uniphier/mmc-first-dev.c
@@ -35,7 +35,7 @@ static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (dev < 0)
 		return CMD_RET_FAILURE;
 
-	env_set_ulong("mmc_first_dev", dev);
+	env_set_ulong(ctx_uboot, "mmc_first_dev", dev);
 	return CMD_RET_SUCCESS;
 }
 
diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c
index 19445b3fc7a5..9160dc4ca50b 100644
--- a/arch/m68k/lib/bootm.c
+++ b/arch/m68k/lib/bootm.c
@@ -112,7 +112,7 @@ static void set_clocks_in_mhz (bd_t *kbd)
 {
 	char *s;
 
-	s = env_get("clocks_in_mhz");
+	s = env_get(ctx_uboot, "clocks_in_mhz");
 	if (s) {
 		/* convert all clock information to MHz */
 		kbd->bi_intfreq /= 1000000L;
diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c
index ec332944d8e8..95ee555edb53 100644
--- a/arch/microblaze/lib/bootm.c
+++ b/arch/microblaze/lib/bootm.c
@@ -20,7 +20,7 @@ int do_bootm_linux(int flag, int argc, char * const argv[],
 {
 	/* First parameter is mapped to $r5 for kernel boot args */
 	void	(*thekernel) (char *, ulong, ulong);
-	char	*commandline = env_get("bootargs");
+	char	*commandline = env_get(ctx_uboot, "bootargs");
 	ulong	rd_data_start, rd_data_end;
 
 	/*
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 8c0d7672f24c..07c9582cc847 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -80,7 +80,7 @@ static void linux_cmdline_legacy(bootm_headers_t *images)
 
 	linux_cmdline_init();
 
-	bootargs = env_get("bootargs");
+	bootargs = env_get(ctx_uboot, "bootargs");
 	if (!bootargs)
 		return;
 
@@ -202,11 +202,11 @@ static void linux_env_legacy(bootm_headers_t *images)
 	sprintf(env_buf, "0x%X", (uint) (gd->bd->bi_flashsize));
 	linux_env_set("flash_size", env_buf);
 
-	cp = env_get("ethaddr");
+	cp = env_get(ctx_uboot, "ethaddr");
 	if (cp)
 		linux_env_set("ethaddr", cp);
 
-	cp = env_get("eth1addr");
+	cp = env_get(ctx_uboot, "eth1addr");
 	if (cp)
 		linux_env_set("eth1addr", cp);
 
diff --git a/arch/nds32/lib/bootm.c b/arch/nds32/lib/bootm.c
index a472f6a18737..1a50a8b5aefb 100644
--- a/arch/nds32/lib/bootm.c
+++ b/arch/nds32/lib/bootm.c
@@ -43,7 +43,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
 	void	(*theKernel)(int zero, int arch, uint params);
 
 #ifdef CONFIG_CMDLINE_TAG
-	char *commandline = env_get("bootargs");
+	char *commandline = env_get(ctx_uboot, "bootargs");
 #endif
 
 	/*
@@ -57,7 +57,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
 
 	theKernel = (void (*)(int, int, uint))images->ep;
 
-	s = env_get("machid");
+	s = env_get(ctx_uboot, "machid");
 	if (s) {
 		machid = simple_strtoul(s, NULL, 16);
 		printf("Using machid 0x%x from environment\n", machid);
diff --git a/arch/powerpc/cpu/mpc85xx/cpu_init.c b/arch/powerpc/cpu/mpc85xx/cpu_init.c
index cac928079042..c4800f2c410f 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu_init.c
@@ -255,7 +255,7 @@ static void enable_tdm_law(void)
 	 * is not setup properly yet. Search for tdm entry in
 	 * hwconfig.
 	 */
-	ret = env_get_f("hwconfig", buffer, sizeof(buffer));
+	ret = env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer));
 	if (ret > 0) {
 		tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
 		/* If tdm is defined in hwconfig, set law for tdm workaround */
@@ -279,7 +279,7 @@ void enable_cpc(void)
 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
 
 	/* Extract hwconfig from environment */
-	ret = env_get_f("hwconfig", buffer, sizeof(buffer));
+	ret = env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer));
 	if (ret > 0) {
 		/*
 		 * If "en_cpc" is not defined in hwconfig then by default all
@@ -753,7 +753,7 @@ int cpu_init_r(void)
 	char *buf = NULL;
 	int n, res;
 
-	n = env_get_f("hwconfig", buffer, sizeof(buffer));
+	n = env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer));
 	if (n > 0)
 		buf = buffer;
 
@@ -793,7 +793,7 @@ int cpu_init_r(void)
 #endif
 
 #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
-	spin = env_get("spin_table_compat");
+	spin = env_get(ctx_uboot, "spin_table_compat");
 	if (spin && (*spin == 'n'))
 		spin_table_compat = 0;
 	else
@@ -844,7 +844,7 @@ int cpu_init_r(void)
 #ifdef CONFIG_SYS_SRIO
 	srio_init();
 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
-	char *s = env_get("bootmaster");
+	char *s = env_get(ctx_uboot, "bootmaster");
 	if (s) {
 		if (!strcmp(s, "SRIO1")) {
 			srio_boot_master(1);
diff --git a/arch/powerpc/cpu/mpc85xx/fdt.c b/arch/powerpc/cpu/mpc85xx/fdt.c
index db12aefb2903..096019073a24 100644
--- a/arch/powerpc/cpu/mpc85xx/fdt.c
+++ b/arch/powerpc/cpu/mpc85xx/fdt.c
@@ -93,7 +93,7 @@ void ft_fixup_cpu(void *blob, u64 memory_limit)
 	 * Extract hwconfig from environment.
 	 * Search for tdm entry in hwconfig.
 	 */
-	ret = env_get_f("hwconfig", buffer, sizeof(buffer));
+	ret = env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer));
 	if (ret > 0)
 		tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
 
diff --git a/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c b/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
index fcfa73023347..7aac230f3fee 100644
--- a/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
+++ b/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
@@ -514,7 +514,7 @@ void fsl_serdes_init(void)
 	 * Extract hwconfig from environment since we have not properly setup
 	 * the environment but need it for ddr config params
 	 */
-	if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
+	if (env_get_f(ctx_uboot, "hwconfig", buffer, sizeof(buffer)) > 0)
 		buf = buffer;
 #endif
 	if (serdes_prtcl_map & (1 << NONE))
diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index 84691b755463..16dbe520afcb 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -269,7 +269,7 @@ static void set_clocks_in_mhz (bd_t *kbd)
 {
 	char	*s;
 
-	s = env_get("clocks_in_mhz");
+	s = env_get(ctx_uboot, "clocks_in_mhz");
 	if (s) {
 		/* convert all clock information to MHz */
 		kbd->bi_intfreq /= 1000000L;
diff --git a/arch/sh/lib/bootm.c b/arch/sh/lib/bootm.c
index 2896e45f0df8..86aa49d0d0ba 100644
--- a/arch/sh/lib/bootm.c
+++ b/arch/sh/lib/bootm.c
@@ -60,7 +60,7 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *ima
 	char *cmdline = (char *)param + COMMAND_LINE;
 	/* PAGE_SIZE */
 	unsigned long size = images->ep - (unsigned long)param;
-	char *bootargs = env_get("bootargs");
+	char *bootargs = env_get(ctx_uboot, "bootargs");
 
 	/*
 	 * allow the PREP bootm subcommand, it is required for bootm to work
diff --git a/arch/sh/lib/zimageboot.c b/arch/sh/lib/zimageboot.c
index 93933b7931d7..769535e1a3c8 100644
--- a/arch/sh/lib/zimageboot.c
+++ b/arch/sh/lib/zimageboot.c
@@ -41,7 +41,7 @@ int do_sh_zimageboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	/* Linux kernel command line */
 	cmdline = (char *)param + COMMAND_LINE;
-	bootargs = env_get("bootargs");
+	bootargs = env_get(ctx_uboot, "bootargs");
 
 	/* Clear zero page */
 	/* cppcheck-suppress nullPointer */
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 6a6258a5057a..996fb015871f 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -49,15 +49,15 @@ static void build_command_line(char *command_line, int auto_boot)
 
 	command_line[0] = '\0';
 
-	env_command_line =  env_get("bootargs");
+	env_command_line =  env_get(ctx_uboot, "bootargs");
 
 	/* set console= argument if we use a serial console */
 	if (!strstr(env_command_line, "console=")) {
-		if (!strcmp(env_get("stdout"), "serial")) {
+		if (!strcmp(env_get(ctx_uboot, "stdout"), "serial")) {
 
 			/* We seem to use serial console */
 			sprintf(command_line, "console=ttyS0,%s ",
-				env_get("baudrate"));
+				env_get(ctx_uboot, "baudrate"));
 		}
 	}
 
@@ -288,7 +288,8 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
 #endif
 
-	setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
+	setup_device_tree(hdr, (const void *)env_get_hex(ctx_uboot, "fdtaddr",
+							 0));
 	setup_video(&setup_base->screen_info);
 
 #ifdef CONFIG_EFI_STUB
@@ -324,7 +325,7 @@ int do_zboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 		/* argv[1] holds the address of the bzImage */
 		s = argv[1];
 	} else {
-		s = env_get("fileaddr");
+		s = env_get(ctx_uboot, "fileaddr");
 	}
 
 	if (s)
diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c
index 93eea53c5f29..d41b544faa9a 100644
--- a/arch/xtensa/lib/bootm.c
+++ b/arch/xtensa/lib/bootm.c
@@ -136,7 +136,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
 {
 	struct bp_tag *params, *params_start;
 	ulong initrd_start, initrd_end;
-	char *commandline = env_get("bootargs");
+	char *commandline = env_get(ctx_uboot, "bootargs");
 
 	if (!(flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)))
 		return 0;
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 09/19] board: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (7 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 08/19] arch: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05 12:02   ` Lukasz Majewski
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 10/19] cmd: " AKASHI Takahiro
                   ` (11 subsequent siblings)
  20 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 board/Arcturus/ucp1020/cmd_arc.c              | 40 ++++++------
 board/Arcturus/ucp1020/ucp1020.c              | 16 ++---
 board/BuR/brppt1/board.c                      |  4 +-
 board/BuR/brxre1/board.c                      |  9 +--
 board/BuR/common/br_resetc.c                  |  2 +-
 board/BuR/common/common.c                     | 47 +++++++-------
 board/BuS/eb_cpu5282/eb_cpu5282.c             |  8 +--
 board/CZ.NIC/turris_mox/turris_mox.c          |  4 +-
 board/CZ.NIC/turris_omnia/turris_omnia.c      |  6 +-
 board/CarMediaLab/flea3/flea3.c               |  2 +-
 board/LaCie/net2big_v2/net2big_v2.c           |  2 +-
 board/LaCie/netspace_v2/netspace_v2.c         |  2 +-
 board/Synology/ds414/cmd_syno.c               |  6 +-
 board/alliedtelesis/x530/x530.c               |  2 +-
 board/amazon/kc1/kc1.c                        |  4 +-
 board/amlogic/p200/p200.c                     |  4 +-
 board/amlogic/p201/p201.c                     |  4 +-
 board/amlogic/p212/p212.c                     |  4 +-
 board/amlogic/q200/q200.c                     |  4 +-
 board/aristainetos/aristainetos-v2.c          |  8 +--
 board/armltd/integrator/integrator.c          |  2 +-
 board/atmel/common/board.c                    |  4 +-
 board/atmel/common/mac_eeprom.c               |  2 +-
 board/atmel/sama5d3xek/sama5d3xek.c           |  2 +-
 board/bachmann/ot1200/ot1200.c                |  4 +-
 board/birdland/bav335x/board.c                |  8 +--
 board/bluegiga/apx4devkit/apx4devkit.c        |  5 +-
 board/bluewater/gurnard/gurnard.c             |  6 +-
 board/bosch/shc/board.c                       |  2 +-
 board/boundary/nitrogen6x/nitrogen6x.c        | 14 ++---
 board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |  2 +-
 board/broadcom/bcm28155_ap/bcm28155_ap.c      |  2 +-
 board/broadcom/bcmstb/bcmstb.c                |  2 +-
 board/buffalo/lsxl/lsxl.c                     |  2 +-
 board/cadence/xtfpga/xtfpga.c                 |  4 +-
 board/ccv/xpress/xpress.c                     |  2 +-
 board/compulab/cl-som-imx7/cl-som-imx7.c      |  2 +-
 board/compulab/cm_fx6/cm_fx6.c                | 10 +--
 board/compulab/common/omap3_display.c         |  4 +-
 board/congatec/cgtqmx6eval/cgtqmx6eval.c      |  8 +--
 board/cssi/MCR3000/MCR3000.c                  |  2 +-
 board/davinci/da8xxevm/da850evm.c             |  2 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |  6 +-
 board/dhelectronics/dh_imx6/dh_imx6.c         |  2 +-
 board/eets/pdu001/board.c                     |  8 +--
 board/el/el6x/el6x.c                          |  2 +-
 board/emulation/qemu-riscv/qemu-riscv.c       |  2 +-
 board/engicam/common/board.c                  | 32 +++++-----
 board/esd/meesc/meesc.c                       |  6 +-
 board/freescale/b4860qds/b4860qds.c           |  5 +-
 board/freescale/common/cmd_esbc_validate.c    |  2 +-
 board/freescale/common/fsl_chain_of_trust.c   |  6 +-
 board/freescale/common/sys_eeprom.c           |  4 +-
 board/freescale/common/vid.c                  |  4 +-
 board/freescale/imx8mq_evk/imx8mq_evk.c       |  4 +-
 board/freescale/imx8qm_mek/imx8qm_mek.c       |  4 +-
 board/freescale/imx8qxp_mek/imx8qxp_mek.c     |  4 +-
 board/freescale/ls1088a/eth_ls1088aqds.c      |  4 +-
 board/freescale/ls1088a/ls1088a.c             |  2 +-
 board/freescale/ls2080aqds/eth.c              |  6 +-
 board/freescale/ls2080aqds/ls2080aqds.c       |  2 +-
 board/freescale/ls2080ardb/ls2080ardb.c       |  6 +-
 board/freescale/lx2160a/eth_lx2160aqds.c      |  2 +-
 board/freescale/mpc8323erdb/mpc8323erdb.c     |  3 +-
 board/freescale/mpc837xemds/pci.c             |  2 +-
 board/freescale/mpc837xerdb/mpc837xerdb.c     |  2 +-
 board/freescale/mx51evk/mx51evk_video.c       |  2 +-
 board/freescale/mx53loco/mx53loco.c           |  4 +-
 board/freescale/mx53loco/mx53loco_video.c     |  2 +-
 board/freescale/mx6sabreauto/mx6sabreauto.c   |  8 +--
 board/freescale/mx6sabresd/mx6sabresd.c       |  8 +--
 board/freescale/mx6sxsabresd/mx6sxsabresd.c   |  2 +-
 .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |  6 +-
 board/freescale/mx6ullevk/mx6ullevk.c         |  4 +-
 board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |  2 +-
 board/freescale/qemu-ppce500/qemu-ppce500.c   |  4 +-
 board/freescale/t4qds/t4240qds.c              |  2 +-
 board/gardena/smart-gateway-at91sam/board.c   |  2 +-
 board/gardena/smart-gateway-mt7688/board.c    | 16 ++---
 board/gateworks/gw_ventana/common.c           |  2 +-
 board/gateworks/gw_ventana/gw_ventana.c       | 61 ++++++++++---------
 board/gateworks/gw_ventana/gw_ventana_spl.c   |  4 +-
 board/gdsys/a38x/keyprogram.c                 |  4 +-
 board/gdsys/mpc8308/gazerbeam.c               |  4 +-
 board/gdsys/mpc8308/hrcon.c                   |  2 +-
 board/gdsys/mpc8308/strider.c                 |  2 +-
 board/gdsys/p1022/controlcenterd-id.c         | 10 +--
 board/gdsys/p1022/controlcenterd.c            |  2 +-
 board/ge/bx50v3/bx50v3.c                      | 13 ++--
 board/ge/common/ge_common.c                   |  4 +-
 board/ge/mx53ppd/mx53ppd.c                    |  2 +-
 board/grinn/chiliboard/board.c                |  4 +-
 board/grinn/liteboard/board.c                 |  6 +-
 board/highbank/highbank.c                     |  9 +--
 board/hisilicon/poplar/poplar.c               |  2 +-
 board/imgtec/ci20/ci20.c                      |  6 +-
 board/intel/edison/edison.c                   | 14 ++---
 board/isee/igep003x/board.c                   |  6 +-
 board/isee/igep00x0/igep00x0.c                |  4 +-
 board/k+p/kp_imx53/kp_id_rev.c                | 20 +++---
 board/k+p/kp_imx53/kp_imx53.c                 |  4 +-
 board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |  4 +-
 board/keymile/common/common.c                 | 26 ++++----
 board/keymile/common/ivm.c                    |  8 +--
 board/keymile/km83xx/km83xx.c                 |  2 +-
 board/keymile/km_arm/km_arm.c                 |  6 +-
 board/keymile/kmp204x/kmp204x.c               |  4 +-
 board/kosagi/novena/novena.c                  |  2 +-
 board/laird/wb50n/wb50n.c                     |  2 +-
 board/lg/sniper/sniper.c                      |  4 +-
 board/liebherr/display5/spl.c                 |  4 +-
 board/liebherr/mccmon6/mccmon6.c              |  6 +-
 board/logicpd/imx6/imx6logic.c                |  8 +--
 board/menlo/m53menlo/m53menlo.c               |  2 +-
 board/micronas/vct/vct.c                      |  2 +-
 board/nokia/rx51/rx51.c                       | 10 +--
 board/overo/overo.c                           | 45 +++++++-------
 board/phytec/pcm052/pcm052.c                  |  4 +-
 board/phytec/pfla02/pfla02.c                  |  2 +-
 .../dragonboard410c/dragonboard410c.c         |  6 +-
 .../dragonboard820c/dragonboard820c.c         |  2 +-
 board/raspberrypi/rpi/rpi.c                   | 26 ++++----
 board/renesas/alt/alt.c                       |  3 +-
 board/renesas/gose/gose.c                     |  3 +-
 board/renesas/koelsch/koelsch.c               |  3 +-
 board/renesas/lager/lager.c                   |  3 +-
 board/renesas/porter/porter.c                 |  3 +-
 board/renesas/sh7752evb/sh7752evb.c           |  4 +-
 board/renesas/sh7753evb/sh7753evb.c           |  4 +-
 board/renesas/sh7757lcr/sh7757lcr.c           |  6 +-
 board/renesas/silk/silk.c                     |  3 +-
 board/renesas/stout/stout.c                   |  3 +-
 board/rockchip/kylin_rk3036/kylin_rk3036.c    |  2 +-
 board/samsung/common/exynos5-dt.c             |  2 +-
 board/samsung/common/misc.c                   | 14 ++---
 board/samsung/odroid/odroid.c                 |  2 +-
 board/samsung/trats/trats.c                   |  2 +-
 board/samsung/universal_c210/universal.c      |  2 +-
 board/samtec/vining_fpga/socfpga.c            | 16 ++---
 board/siemens/common/board.c                  |  4 +-
 board/siemens/draco/board.c                   |  6 +-
 board/siemens/pxm2/board.c                    |  4 +-
 board/siemens/rut/board.c                     |  2 +-
 board/siemens/taurus/taurus.c                 | 50 +++++++--------
 board/socrates/socrates.c                     |  4 +-
 board/softing/vining_2000/vining_2000.c       |  8 +--
 board/solidrun/mx6cuboxi/mx6cuboxi.c          | 16 ++---
 .../stm32f429-discovery/stm32f429-discovery.c |  4 +-
 .../stm32f429-evaluation.c                    |  4 +-
 .../stm32f469-discovery/stm32f469-discovery.c |  4 +-
 board/st/stm32mp1/stm32mp1.c                  | 11 ++--
 board/sunxi/board.c                           | 25 ++++----
 board/synopsys/hsdk/env-lib.c                 | 11 ++--
 board/synopsys/hsdk/hsdk.c                    |  6 +-
 board/syteco/zmx25/zmx25.c                    |  8 ++-
 board/tcl/sl50/board.c                        |  6 +-
 .../puma_rk3399/puma-rk3399.c                 |  8 +--
 board/ti/am335x/board.c                       | 18 +++---
 board/ti/am43xx/board.c                       |  6 +-
 board/ti/am57xx/board.c                       | 14 ++---
 board/ti/beagle/beagle.c                      | 43 ++++++-------
 board/ti/common/board_detect.c                | 14 ++---
 board/ti/dra7xx/evm.c                         | 12 ++--
 board/ti/evm/evm.c                            |  2 +-
 board/ti/ks2_evm/board.c                      | 10 +--
 board/ti/ks2_evm/board_k2g.c                  |  8 +--
 board/ti/panda/panda.c                        |  4 +-
 board/toradex/apalis-imx8/apalis-imx8.c       |  4 +-
 board/toradex/apalis_imx6/apalis_imx6.c       | 12 ++--
 .../toradex/colibri-imx6ull/colibri-imx6ull.c |  6 +-
 board/toradex/colibri-imx8x/colibri-imx8x.c   |  4 +-
 board/toradex/colibri_imx6/colibri_imx6.c     |  8 +--
 board/toradex/colibri_vf/colibri_vf.c         |  2 +-
 board/toradex/common/tdx-cfg-block.c          |  2 +-
 board/toradex/common/tdx-common.c             |  2 +-
 board/tqc/tqma6/tqma6.c                       |  2 +-
 board/udoo/neo/neo.c                          |  2 +-
 board/udoo/udoo.c                             |  4 +-
 board/varisys/common/sys_eeprom.c             |  6 +-
 board/vscom/baltos/board.c                    |  6 +-
 board/wandboard/wandboard.c                   | 12 ++--
 board/warp7/warp7.c                           |  6 +-
 .../work_92105/work_92105_display.c           |  2 +-
 board/xes/common/board.c                      |  6 +-
 board/xilinx/zynq/board.c                     | 16 ++---
 board/xilinx/zynqmp/cmds.c                    |  2 +-
 board/xilinx/zynqmp/zynqmp.c                  | 24 ++++----
 187 files changed, 677 insertions(+), 649 deletions(-)

diff --git a/board/Arcturus/ucp1020/cmd_arc.c b/board/Arcturus/ucp1020/cmd_arc.c
index 2e8477ed3b7a..fbe1f2dba123 100644
--- a/board/Arcturus/ucp1020/cmd_arc.c
+++ b/board/Arcturus/ucp1020/cmd_arc.c
@@ -252,8 +252,8 @@ static int read_arc_info(void)
 static int do_get_arc_info(void)
 {
 	int l = read_arc_info();
-	char *oldserial = env_get("SERIAL");
-	char *oldversion = env_get("VERSION");
+	char *oldserial = env_get(ctx_uboot, "SERIAL");
+	char *oldversion = env_get(ctx_uboot, "VERSION");
 
 	if (oldversion != NULL)
 		if (strcmp(oldversion, U_BOOT_VERSION) != 0)
@@ -269,13 +269,13 @@ static int do_get_arc_info(void)
 		printf("<not found>\n");
 	} else {
 		printf("%s\n", smac[0]);
-		env_set("SERIAL", smac[0]);
+		env_set(ctx_uboot, "SERIAL", smac[0]);
 	}
 
 	if (strcmp(smac[1], "00:00:00:00:00:00") == 0) {
-		env_set("ethaddr", NULL);
-		env_set("eth1addr", NULL);
-		env_set("eth2addr", NULL);
+		env_set(ctx_uboot, "ethaddr", NULL);
+		env_set(ctx_uboot, "eth1addr", NULL);
+		env_set(ctx_uboot, "eth2addr", NULL);
 		goto done;
 	}
 
@@ -283,13 +283,13 @@ static int do_get_arc_info(void)
 	if (smac[1][0] == EMPY_CHAR) {
 		printf("<not found>\n");
 	} else {
-		char *ret = env_get("ethaddr");
+		char *ret = env_get(ctx_uboot, "ethaddr");
 
 		if (ret == NULL) {
-			env_set("ethaddr", smac[1]);
+			env_set(ctx_uboot, "ethaddr", smac[1]);
 			printf("%s\n", smac[1]);
 		} else if (strcmp(ret, __stringify(CONFIG_ETHADDR)) == 0) {
-			env_set("ethaddr", smac[1]);
+			env_set(ctx_uboot, "ethaddr", smac[1]);
 			printf("%s (factory)\n", smac[1]);
 		} else {
 			printf("%s\n", ret);
@@ -297,8 +297,8 @@ static int do_get_arc_info(void)
 	}
 
 	if (strcmp(smac[2], "00:00:00:00:00:00") == 0) {
-		env_set("eth1addr", NULL);
-		env_set("eth2addr", NULL);
+		env_set(ctx_uboot, "eth1addr", NULL);
+		env_set(ctx_uboot, "eth2addr", NULL);
 		goto done;
 	}
 
@@ -306,13 +306,13 @@ static int do_get_arc_info(void)
 	if (smac[2][0] == EMPY_CHAR) {
 		printf("<not found>\n");
 	} else {
-		char *ret = env_get("eth1addr");
+		char *ret = env_get(ctx_uboot, "eth1addr");
 
 		if (ret == NULL) {
-			env_set("ethaddr", smac[2]);
+			env_set(ctx_uboot, "ethaddr", smac[2]);
 			printf("%s\n", smac[2]);
 		} else if (strcmp(ret, __stringify(CONFIG_ETH1ADDR)) == 0) {
-			env_set("eth1addr", smac[2]);
+			env_set(ctx_uboot, "eth1addr", smac[2]);
 			printf("%s (factory)\n", smac[2]);
 		} else {
 			printf("%s\n", ret);
@@ -320,7 +320,7 @@ static int do_get_arc_info(void)
 	}
 
 	if (strcmp(smac[3], "00:00:00:00:00:00") == 0) {
-		env_set("eth2addr", NULL);
+		env_set(ctx_uboot, "eth2addr", NULL);
 		goto done;
 	}
 
@@ -328,13 +328,13 @@ static int do_get_arc_info(void)
 	if (smac[3][0] == EMPY_CHAR) {
 		printf("<not found>\n");
 	} else {
-		char *ret = env_get("eth2addr");
+		char *ret = env_get(ctx_uboot, "eth2addr");
 
 		if (ret == NULL) {
-			env_set("ethaddr", smac[3]);
+			env_set(ctx_uboot, "ethaddr", smac[3]);
 			printf("%s\n", smac[3]);
 		} else if (strcmp(ret, __stringify(CONFIG_ETH2ADDR)) == 0) {
-			env_set("eth2addr", smac[3]);
+			env_set(ctx_uboot, "eth2addr", smac[3]);
 			printf("%s (factory)\n", smac[3]);
 		} else {
 			printf("%s\n", ret);
@@ -343,8 +343,8 @@ static int do_get_arc_info(void)
 done:
 	if (oldserial == NULL || oldversion == NULL) {
 		if (oldversion == NULL)
-			env_set("VERSION", U_BOOT_VERSION);
-		env_save();
+			env_set(ctx_uboot, "VERSION", U_BOOT_VERSION);
+		env_save(ctx_uboot);
 	}
 
 	return 0;
diff --git a/board/Arcturus/ucp1020/ucp1020.c b/board/Arcturus/ucp1020/ucp1020.c
index 6a880c97bcb7..1aa7f96b5e1c 100644
--- a/board/Arcturus/ucp1020/ucp1020.c
+++ b/board/Arcturus/ucp1020/ucp1020.c
@@ -64,7 +64,7 @@ void board_gpio_init(void)
 
 	for (i = 0; i < GPIO_MAX_NUM; i++) {
 		sprintf(envname, "GPIO%d", i);
-		val = env_get(envname);
+		val = env_get(ctx_uboot, envname);
 		if (val) {
 			char direction = toupper(val[0]);
 			char level = toupper(val[1]);
@@ -82,7 +82,7 @@ void board_gpio_init(void)
 		}
 	}
 
-	val = env_get("PCIE_OFF");
+	val = env_get(ctx_uboot, "PCIE_OFF");
 	if (val) {
 		gpio_direction_input(GPIO_PCIE1_EN);
 		gpio_direction_input(GPIO_PCIE2_EN);
@@ -91,7 +91,7 @@ void board_gpio_init(void)
 		gpio_direction_output(GPIO_PCIE2_EN, 1);
 	}
 
-	val = env_get("SDHC_CDWP_OFF");
+	val = env_get(ctx_uboot, "SDHC_CDWP_OFF");
 	if (!val) {
 		ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
 
@@ -218,7 +218,7 @@ int last_stage_init(void)
 	else
 		printf("NCT72(0x%x): ready\n", id2);
 
-	kval = env_get("kernelargs");
+	kval = env_get(ctx_uboot, "kernelargs");
 
 #ifdef CONFIG_MMC
 	mmc = find_mmc_device(0);
@@ -235,22 +235,22 @@ int last_stage_init(void)
 				strcat(newkernelargs, mmckargs);
 				strcat(newkernelargs, " ");
 				strcat(newkernelargs, &tmp[n]);
-				env_set("kernelargs", newkernelargs);
+				env_set(ctx_uboot, "kernelargs", newkernelargs);
 			} else {
-				env_set("kernelargs", mmckargs);
+				env_set(ctx_uboot, "kernelargs", mmckargs);
 			}
 		}
 #endif
 	get_arc_info();
 
 	if (kval) {
-		sval = env_get("SERIAL");
+		sval = env_get(ctx_uboot, "SERIAL");
 		if (sval) {
 			strcpy(newkernelargs, "SN=");
 			strcat(newkernelargs, sval);
 			strcat(newkernelargs, " ");
 			strcat(newkernelargs, kval);
-			env_set("kernelargs", newkernelargs);
+			env_set(ctx_uboot, "kernelargs", newkernelargs);
 		}
 	} else {
 		printf("Error reading kernelargs env variable!\n");
diff --git a/board/BuR/brppt1/board.c b/board/BuR/brppt1/board.c
index ef4f5c950140..4278dda5988f 100644
--- a/board/BuR/brppt1/board.c
+++ b/board/BuR/brppt1/board.c
@@ -180,10 +180,10 @@ int board_late_init(void)
 		bmode = 4;
 
 	printf("Mode:  %s\n", bootmodeascii[bmode & 0x0F]);
-	env_set_ulong("b_mode", bmode);
+	env_set_ulong(ctx_uboot, "b_mode", bmode);
 
 	/* get sure that bootcmd isn't affected by any bootcount value */
-	env_set_ulong("bootlimit", 0);
+	env_set_ulong(ctx_uboot, "bootlimit", 0);
 
 	return 0;
 }
diff --git a/board/BuR/brxre1/board.c b/board/BuR/brxre1/board.c
index 873208c668d7..69bcccbc5a0d 100644
--- a/board/BuR/brxre1/board.c
+++ b/board/BuR/brxre1/board.c
@@ -165,10 +165,11 @@ int board_late_init(void)
 	snprintf(othbootargs, sizeof(othbootargs),
 		 "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x",
 		 (u32)gd->fb_base - 0x20,
-		 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base - 0x20),
-		 (u32)env_get_ulong("vx_romfsbase", 16, 0),
-		 (u32)env_get_ulong("vx_romfssize", 16, 0));
-	env_set("othbootargs", othbootargs);
+		 (u32)env_get_ulong(ctx_uboot, "vx_memtop", 16,
+				    gd->fb_base - 0x20),
+		 (u32)env_get_ulong(ctx_uboot, "vx_romfsbase", 16, 0),
+		 (u32)env_get_ulong(ctx_uboot, "vx_romfssize", 16, 0));
+	env_set(ctx_uboot, "othbootargs", othbootargs);
 	/*
 	 * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does
 	 * expect that vectors are there, original u-boot moves them to _start
diff --git a/board/BuR/common/br_resetc.c b/board/BuR/common/br_resetc.c
index c0e7fb65b298..36d49967dd82 100644
--- a/board/BuR/common/br_resetc.c
+++ b/board/BuR/common/br_resetc.c
@@ -230,7 +230,7 @@ int br_resetc_bmode(void)
 		printf("Reset: STM32 controller\n");
 
 	printf("Mode:  %s\n", bootmodeascii[regw & 0x0F]);
-	env_set_ulong("b_mode", regw & 0x0F);
+	env_set_ulong(ctx_uboot, "b_mode", regw & 0x0F);
 
 	return rc;
 }
diff --git a/board/BuR/common/common.c b/board/BuR/common/common.c
index 148fc9075e4f..f3bc87daf19f 100644
--- a/board/BuR/common/common.c
+++ b/board/BuR/common/common.c
@@ -29,9 +29,12 @@ DECLARE_GLOBAL_DATA_PTR;
 
 void lcdbacklight(int on)
 {
-	unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL);
-	unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50);
-	unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
+	unsigned int driver = env_get_ulong(ctx_uboot, "ds1_bright_drv", 16,
+					    0UL);
+	unsigned int bright = env_get_ulong(ctx_uboot, "ds1_bright_def", 10,
+					    50);
+	unsigned int pwmfrq = env_get_ulong(ctx_uboot, "ds1_pwmfreq", 10,
+					    ~0UL);
 	unsigned int tmp;
 	struct gptimer *timerhw;
 
@@ -87,20 +90,20 @@ int load_lcdtiming(struct am335x_lcdpanel *panel)
 {
 	struct am335x_lcdpanel pnltmp;
 
-	pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
-	pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
-	pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
-	pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
-	pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
-	pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
-	pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
-	pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
-	pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
-	pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
-	pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
-	pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
-	pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
-	panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
+	pnltmp.hactive = env_get_ulong(ctx_uboot, "ds1_hactive", 10, ~0UL);
+	pnltmp.vactive = env_get_ulong(ctx_uboot, "ds1_vactive", 10, ~0UL);
+	pnltmp.bpp = env_get_ulong(ctx_uboot, "ds1_bpp", 10, ~0UL);
+	pnltmp.hfp = env_get_ulong(ctx_uboot, "ds1_hfp", 10, ~0UL);
+	pnltmp.hbp = env_get_ulong(ctx_uboot, "ds1_hbp", 10, ~0UL);
+	pnltmp.hsw = env_get_ulong(ctx_uboot, "ds1_hsw", 10, ~0UL);
+	pnltmp.vfp = env_get_ulong(ctx_uboot, "ds1_vfp", 10, ~0UL);
+	pnltmp.vbp = env_get_ulong(ctx_uboot, "ds1_vbp", 10, ~0UL);
+	pnltmp.vsw = env_get_ulong(ctx_uboot, "ds1_vsw", 10, ~0UL);
+	pnltmp.pxl_clk = env_get_ulong(ctx_uboot, "ds1_pxlclk", 10, ~0UL);
+	pnltmp.pol = env_get_ulong(ctx_uboot, "ds1_pol", 16, ~0UL);
+	pnltmp.pup_delay = env_get_ulong(ctx_uboot, "ds1_pupdelay", 10, ~0UL);
+	pnltmp.pon_delay = env_get_ulong(ctx_uboot, "ds1_tondelay", 10, ~0UL);
+	panel_info.vl_rot = env_get_ulong(ctx_uboot, "ds1_rotation", 10, 0);
 
 	if (
 	   ~0UL == (pnltmp.hactive) ||
@@ -151,11 +154,11 @@ static void br_summaryscreen_printenv(char *prefix,
 				       char *name, char *altname,
 				       char *suffix)
 {
-	char *envval = env_get(name);
+	char *envval = env_get(ctx_uboot, name);
 	if (0 != envval) {
 		lcd_printf("%s %s %s", prefix, envval, suffix);
 	} else if (0 != altname) {
-		envval = env_get(altname);
+		envval = env_get(ctx_uboot, altname);
 		if (0 != envval)
 			lcd_printf("%s %s %s", prefix, envval, suffix);
 	} else {
@@ -178,7 +181,7 @@ void lcdpower(int on)
 	u32 pin, swval, i;
 	char buf[16] = { 0 };
 
-	pin = env_get_ulong("ds1_pwr", 16, ~0UL);
+	pin = env_get_ulong(ctx_uboot, "ds1_pwr", 16, ~0UL);
 
 	if (pin == ~0UL) {
 		puts("no pwrpin in dtb/env, cannot powerup display!\n");
@@ -295,8 +298,8 @@ int brdefaultip_setup(int bus, int chip)
 			"if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;",
 			sizeof(defip));
 
-	env_set("brdefaultip", defip);
-	env_set_hex("board_id", u8buf);
+	env_set(ctx_uboot, "brdefaultip", defip);
+	env_set_hex(ctx_uboot, "board_id", u8buf);
 
 	return 0;
 }
diff --git a/board/BuS/eb_cpu5282/eb_cpu5282.c b/board/BuS/eb_cpu5282/eb_cpu5282.c
index 0b916d2482c5..03d2b276a132 100644
--- a/board/BuS/eb_cpu5282/eb_cpu5282.c
+++ b/board/BuS/eb_cpu5282/eb_cpu5282.c
@@ -139,7 +139,7 @@ void hw_watchdog_init(void)
 	int enable;
 
 	enable = 1;
-	s = env_get("watchdog");
+	s = env_get(ctx_uboot, "watchdog");
 	if (s != NULL)
 		if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0))
 			enable = 0;
@@ -191,13 +191,13 @@ int drv_video_init(void)
 	unsigned long splash;
 #endif
 	printf("Init Video as ");
-	s = env_get("displaywidth");
+	s = env_get(ctx_uboot, "displaywidth");
 	if (s != NULL)
 		display_width = simple_strtoul(s, NULL, 10);
 	else
 		display_width = 256;
 
-	s = env_get("displayheight");
+	s = env_get(ctx_uboot, "displayheight");
 	if (s != NULL)
 		display_height = simple_strtoul(s, NULL, 10);
 	else
@@ -211,7 +211,7 @@ int drv_video_init(void)
 	vcxk_init(display_width, display_height);
 
 #ifdef CONFIG_SPLASH_SCREEN
-	s = env_get("splashimage");
+	s = env_get(ctx_uboot, "splashimage");
 	if (s != NULL) {
 		splash = simple_strtoul(s, NULL, 16);
 		vcxk_acknowledge_wait();
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c
index 946e20ab492f..b23ecb3fefaa 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -362,10 +362,10 @@ int misc_init_r(void)
 		return 0;
 	}
 
-	if (is_valid_ethaddr(mac1) && !env_get("ethaddr"))
+	if (is_valid_ethaddr(mac1) && !env_get(ctx_uboot, "ethaddr"))
 		eth_env_set_enetaddr("ethaddr", mac1);
 
-	if (is_valid_ethaddr(mac2) && !env_get("eth1addr"))
+	if (is_valid_ethaddr(mac2) && !env_get(ctx_uboot, "eth1addr"))
 		eth_env_set_enetaddr("eth1addr", mac2);
 
 	return 0;
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 1d8d08a847d9..bbbeaf75fc97 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -326,7 +326,7 @@ static int set_regdomain(void)
 		puts("EEPROM regdomain read failed.\n");
 
 	printf("Regdomain set to %s\n", rd);
-	return env_set("regdomain", rd);
+	return env_set(ctx_uboot, "regdomain", rd);
 }
 
 /*
@@ -359,11 +359,11 @@ static void handle_reset_button(void)
 		return;
 	}
 
-	env_set_ulong("omnia_reset", reset_status);
+	env_set_ulong(ctx_uboot, "omnia_reset", reset_status);
 
 	if (reset_status) {
 		printf("RESET button was pressed, overwriting bootcmd!\n");
-		env_set("bootcmd", OMNIA_FACTORY_RESET_BOOTCMD);
+		env_set(ctx_uboot, "bootcmd", OMNIA_FACTORY_RESET_BOOTCMD);
 	}
 }
 #endif
diff --git a/board/CarMediaLab/flea3/flea3.c b/board/CarMediaLab/flea3/flea3.c
index be0bc228ec71..9a5fe1e2252d 100644
--- a/board/CarMediaLab/flea3/flea3.c
+++ b/board/CarMediaLab/flea3/flea3.c
@@ -211,7 +211,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 		{ "mxc_nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
 	};
 
-	if (env_get("fdt_noauto")) {
+	if (env_get(ctx_uboot, "fdt_noauto")) {
 		puts("   Skiping ft_board_setup (fdt_noauto defined)\n");
 		return 0;
 	}
diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c
index 686608d25a5a..659a351deaea 100644
--- a/board/LaCie/net2big_v2/net2big_v2.c
+++ b/board/LaCie/net2big_v2/net2big_v2.c
@@ -221,7 +221,7 @@ int misc_init_r(void)
 {
 	init_fan();
 #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		uchar mac[6];
 		if (lacie_read_mac_address(mac) == 0)
 			eth_env_set_enetaddr("ethaddr", mac);
diff --git a/board/LaCie/netspace_v2/netspace_v2.c b/board/LaCie/netspace_v2/netspace_v2.c
index bd7ab22948b2..83b07300354e 100644
--- a/board/LaCie/netspace_v2/netspace_v2.c
+++ b/board/LaCie/netspace_v2/netspace_v2.c
@@ -83,7 +83,7 @@ int board_init(void)
 int misc_init_r(void)
 {
 #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		uchar mac[6];
 		if (lacie_read_mac_address(mac) == 0)
 			eth_env_set_enetaddr("ethaddr", mac);
diff --git a/board/Synology/ds414/cmd_syno.c b/board/Synology/ds414/cmd_syno.c
index 777948f90f58..abd38b24fff0 100644
--- a/board/Synology/ds414/cmd_syno.c
+++ b/board/Synology/ds414/cmd_syno.c
@@ -80,7 +80,7 @@ static int do_syno_populate(int argc, char * const argv[])
 		         ethaddr[0], ethaddr[1], ethaddr[2],
 			 ethaddr[3], ethaddr[4], ethaddr[5]);
 		printf("parsed %s = %s\n", var, val);
-		env_set(var, val);
+		env_set(ctx_uboot, var, val);
 	}
 	if (!strncmp(buf + 32, SYNO_SN_TAG, strlen(SYNO_SN_TAG))) {
 		char *snp, *csump;
@@ -110,7 +110,7 @@ static int do_syno_populate(int argc, char * const argv[])
 			goto out_unmap;
 		}
 		printf("parsed SN = %s\n", snp);
-		env_set("SN", snp);
+		env_set(ctx_uboot, "SN", snp);
 	} else {	/* old style format */
 		unsigned char csum = 0;
 
@@ -124,7 +124,7 @@ static int do_syno_populate(int argc, char * const argv[])
 		}
 		bufp[n] = '\0';
 		printf("parsed SN = %s\n", buf + 32);
-		env_set("SN", buf + 32);
+		env_set(ctx_uboot, "SN", buf + 32);
 	}
 out_unmap:
 	unmap_physmem(buf, len);
diff --git a/board/alliedtelesis/x530/x530.c b/board/alliedtelesis/x530/x530.c
index e0fa8067c1c5..53bc9dd286e2 100644
--- a/board/alliedtelesis/x530/x530.c
+++ b/board/alliedtelesis/x530/x530.c
@@ -157,7 +157,7 @@ int misc_init_r(void)
 	gpio_hog(&led_en, "atl,led-enable", "enable-gpio", 1);
 
 #ifdef MTDPARTS_MTDOOPS
-	env_set("mtdoops", MTDPARTS_MTDOOPS);
+	env_set(ctx_uboot, "mtdoops", MTDPARTS_MTDOOPS);
 #endif
 
 	led_7seg_init(0xff);
diff --git a/board/amazon/kc1/kc1.c b/board/amazon/kc1/kc1.c
index 9034c4fbfff0..9f183da00a9e 100644
--- a/board/amazon/kc1/kc1.c
+++ b/board/amazon/kc1/kc1.c
@@ -118,8 +118,8 @@ int misc_init_r(void)
 	}
 
 	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
-		if (!env_get("reboot-mode"))
-			env_set("reboot-mode", (char *)reboot_mode);
+		if (!env_get(ctx_uboot, "reboot-mode"))
+			env_set(ctx_uboot, "reboot-mode", (char *)reboot_mode);
 	}
 
 	omap_reboot_mode_clear();
diff --git a/board/amlogic/p200/p200.c b/board/amlogic/p200/p200.c
index 41d331dda2d4..4b1a158f1750 100644
--- a/board/amlogic/p200/p200.c
+++ b/board/amlogic/p200/p200.c
@@ -32,11 +32,11 @@ int misc_init_r(void)
 			eth_env_set_enetaddr("ethaddr", mac_addr);
 	}
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
 			EFUSE_SN_SIZE);
 		if (len == EFUSE_SN_SIZE)
-			env_set("serial#", serial);
+			env_set(ctx_uboot, "serial#", serial);
 	}
 
 	return 0;
diff --git a/board/amlogic/p201/p201.c b/board/amlogic/p201/p201.c
index e46fcaea6dcd..ba2a5387a120 100644
--- a/board/amlogic/p201/p201.c
+++ b/board/amlogic/p201/p201.c
@@ -32,11 +32,11 @@ int misc_init_r(void)
 			eth_env_set_enetaddr("ethaddr", mac_addr);
 	}
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
 			EFUSE_SN_SIZE);
 		if (len == EFUSE_SN_SIZE)
-			env_set("serial#", serial);
+			env_set(ctx_uboot, "serial#", serial);
 	}
 
 	return 0;
diff --git a/board/amlogic/p212/p212.c b/board/amlogic/p212/p212.c
index 094ab5478d00..3fabf79a4b41 100644
--- a/board/amlogic/p212/p212.c
+++ b/board/amlogic/p212/p212.c
@@ -36,11 +36,11 @@ int misc_init_r(void)
 			meson_generate_serial_ethaddr();
 	}
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
 			EFUSE_SN_SIZE);
 		if (len == EFUSE_SN_SIZE)
-			env_set("serial#", serial);
+			env_set(ctx_uboot, "serial#", serial);
 	}
 
 	return 0;
diff --git a/board/amlogic/q200/q200.c b/board/amlogic/q200/q200.c
index f1faa7418e07..2cf2af3e1899 100644
--- a/board/amlogic/q200/q200.c
+++ b/board/amlogic/q200/q200.c
@@ -35,11 +35,11 @@ int misc_init_r(void)
 			meson_generate_serial_ethaddr();
 	}
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
 					  EFUSE_SN_SIZE);
 		if (len == EFUSE_SN_SIZE)
-			env_set("serial#", serial);
+			env_set(ctx_uboot, "serial#", serial);
 	}
 
 	return 0;
diff --git a/board/aristainetos/aristainetos-v2.c b/board/aristainetos/aristainetos-v2.c
index c0a2e41f02e8..061baf0255db 100644
--- a/board/aristainetos/aristainetos-v2.c
+++ b/board/aristainetos/aristainetos-v2.c
@@ -651,7 +651,7 @@ int board_late_init(void)
 {
 	char *my_bootdelay;
 	char bootmode = 0;
-	char const *panel = env_get("panel");
+	char const *panel = env_get(ctx_uboot, "panel");
 
 	/*
 	 * Check the boot-source. If booting from NOR Flash,
@@ -668,11 +668,11 @@ int board_late_init(void)
 	bootmode |= (gpio_get_value(IMX_GPIO_NR(7, 1)) ? 1 : 0) << 2;
 
 	if (bootmode == 7) {
-		my_bootdelay = env_get("nor_bootdelay");
+		my_bootdelay = env_get(ctx_uboot, "nor_bootdelay");
 		if (my_bootdelay != NULL)
-			env_set("bootdelay", my_bootdelay);
+			env_set(ctx_uboot, "bootdelay", my_bootdelay);
 		else
-			env_set("bootdelay", "-2");
+			env_set(ctx_uboot, "bootdelay", "-2");
 	}
 
 	/* if we have the lg panel, we can initialze it now */
diff --git a/board/armltd/integrator/integrator.c b/board/armltd/integrator/integrator.c
index 0a2baa72976c..72c9678218ae 100644
--- a/board/armltd/integrator/integrator.c
+++ b/board/armltd/integrator/integrator.c
@@ -116,7 +116,7 @@ extern void cm_remap(void);
 
 int misc_init_r (void)
 {
-	env_set("verify", "n");
+	env_set(ctx_uboot, "verify", "n");
 	return (0);
 }
 
diff --git a/board/atmel/common/board.c b/board/atmel/common/board.c
index c41706c4005c..aef6babfd37a 100644
--- a/board/atmel/common/board.c
+++ b/board/atmel/common/board.c
@@ -64,7 +64,7 @@ void at91_pda_detect(void)
 	}
 
 pda_detect_err:
-	env_set("pda", (const char *)buf);
+	env_set(ctx_uboot, "pda", (const char *)buf);
 }
 #else
 void at91_pda_detect(void)
@@ -74,5 +74,5 @@ void at91_pda_detect(void)
 
 void at91_prepare_cpu_var(void)
 {
-	env_set("cpu", get_cpu_name());
+	env_set(ctx_uboot, "cpu", get_cpu_name());
 }
diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c
index 83a7778e9954..4c9a5c0b0d0e 100644
--- a/board/atmel/common/mac_eeprom.c
+++ b/board/atmel/common/mac_eeprom.c
@@ -18,7 +18,7 @@ int at91_set_ethaddr(int offset)
 	struct udevice *dev;
 	int ret;
 
-	if (env_get(ETHADDR_NAME))
+	if (env_get(ctx_uboot, ETHADDR_NAME))
 		return 0;
 
 	ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
diff --git a/board/atmel/sama5d3xek/sama5d3xek.c b/board/atmel/sama5d3xek/sama5d3xek.c
index acf61486d20b..6c27c3dbe148 100644
--- a/board/atmel/sama5d3xek/sama5d3xek.c
+++ b/board/atmel/sama5d3xek/sama5d3xek.c
@@ -187,7 +187,7 @@ int board_late_init(void)
 		*p = tolower(*p);
 
 	strcat(name, "ek.dtb");
-	env_set("dtb_name", name);
+	env_set(ctx_uboot, "dtb_name", name);
 #endif
 #ifdef CONFIG_DM_VIDEO
 	at91_video_show_board_info();
diff --git a/board/bachmann/ot1200/ot1200.c b/board/bachmann/ot1200/ot1200.c
index 36f37084b36c..baf7b7cdf7f3 100644
--- a/board/bachmann/ot1200/ot1200.c
+++ b/board/bachmann/ot1200/ot1200.c
@@ -301,9 +301,9 @@ int board_eth_init(bd_t *bis)
 
 	/* depending on the phy address we can detect our board version */
 	if (phydev->addr == 0)
-		env_set("boardver", "");
+		env_set(ctx_uboot, "boardver", "");
 	else
-		env_set("boardver", "mr");
+		env_set(ctx_uboot, "boardver", "mr");
 
 	printf("using phy at %d\n", phydev->addr);
 	ret = fec_probe(bis, -1, base, bus, phydev);
diff --git a/board/birdland/bav335x/board.c b/board/birdland/bav335x/board.c
index 8811583ac628..9a8b69df3891 100644
--- a/board/birdland/bav335x/board.c
+++ b/board/birdland/bav335x/board.c
@@ -161,7 +161,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
+	env_load(ctx_uboot);
 	if (env_get_yesno("boot_os") != 1)
 		return 1;
 #endif
@@ -300,8 +300,8 @@ int board_init(void)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "BAV335xB");
-	env_set("board_rev", "B"); /* Fix me, but why bother.. */
+	env_set(ctx_uboot, "board_name", "BAV335xB");
+	env_set(ctx_uboot, "board_rev", "B"); /* Fix me, but why bother.. */
 #endif
 	return 0;
 }
@@ -391,7 +391,7 @@ int board_eth_init(bd_t *bis)
 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
 	(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
diff --git a/board/bluegiga/apx4devkit/apx4devkit.c b/board/bluegiga/apx4devkit/apx4devkit.c
index 9268aa0daafc..a7116e8c0c06 100644
--- a/board/bluegiga/apx4devkit/apx4devkit.c
+++ b/board/bluegiga/apx4devkit/apx4devkit.c
@@ -133,8 +133,9 @@ void get_board_serial(struct tag_serialnr *serialnr)
 #ifdef CONFIG_REVISION_TAG
 u32 get_board_rev(void)
 {
-	if (env_get("revision#") != NULL)
-		return simple_strtoul(env_get("revision#"), NULL, 10);
+	if (env_get(ctx_uboot, "revision#"))
+		return simple_strtoul(env_get(ctx_uboot, "revision#"), NULL,
+				      10);
 	return 0;
 }
 #endif
diff --git a/board/bluewater/gurnard/gurnard.c b/board/bluewater/gurnard/gurnard.c
index 48e31d9065a2..560db5fee639 100644
--- a/board/bluewater/gurnard/gurnard.c
+++ b/board/bluewater/gurnard/gurnard.c
@@ -340,7 +340,7 @@ int board_init(void)
 	at91_set_A_periph(AT91_PIN_PE6, 1);	/* power up */
 
 	/* Select the second timing index for board rev 2 */
-	rev_str = env_get("board_rev");
+	rev_str = env_get(ctx_uboot, "board_rev");
 	if (rev_str && !strncmp(rev_str, "2", 1)) {
 		struct udevice *dev;
 
@@ -367,7 +367,7 @@ int board_late_init(void)
 	 * Set MAC address so we do not need to init Ethernet before Linux
 	 * boot
 	 */
-	env_str = env_get("ethaddr");
+	env_str = env_get(ctx_uboot, "ethaddr");
 	if (env_str) {
 		struct at91_emac *emac = (struct at91_emac *)ATMEL_BASE_EMAC;
 		/* Parse MAC address */
@@ -384,7 +384,7 @@ int board_late_init(void)
 		       &emac->sa2l);
 		writel((env_enetaddr[4] | env_enetaddr[5] << 8), &emac->sa2h);
 
-		printf("MAC:   %s\n", env_get("ethaddr"));
+		printf("MAC:   %s\n", env_get(ctx_uboot, "ethaddr"));
 	} else {
 		/* Not set in environment */
 		printf("MAC:   not set\n");
diff --git a/board/bosch/shc/board.c b/board/bosch/shc/board.c
index a96fdef992d2..6afbdb9737ac 100644
--- a/board/bosch/shc/board.c
+++ b/board/bosch/shc/board.c
@@ -246,7 +246,7 @@ static void check_button_status(void)
 
 	if (value == 0) {
 		printf("front button activated !\n");
-		env_set("harakiri", "1");
+		env_set(ctx_uboot, "harakiri", "1");
 	}
 }
 
diff --git a/board/boundary/nitrogen6x/nitrogen6x.c b/board/boundary/nitrogen6x/nitrogen6x.c
index 26af3f710250..e9a1cde72390 100644
--- a/board/boundary/nitrogen6x/nitrogen6x.c
+++ b/board/boundary/nitrogen6x/nitrogen6x.c
@@ -749,7 +749,7 @@ size_t display_count = ARRAY_SIZE(displays);
 
 int board_cfb_skip(void)
 {
-	return NULL != env_get("novideo");
+	return env_get(ctx_uboot, "novideo") != NULL;
 }
 
 static void setup_display(void)
@@ -954,7 +954,7 @@ static int do_kbd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	char envvalue[ARRAY_SIZE(buttons)+1];
 	int numpressed = read_keys(envvalue);
-	env_set("keybd", envvalue);
+	env_set(ctx_uboot, "keybd", envvalue);
 	return numpressed == 0;
 }
 
@@ -974,7 +974,7 @@ static void preboot_keys(void)
 	char keypress[ARRAY_SIZE(buttons)+1];
 	numpressed = read_keys(keypress);
 	if (numpressed) {
-		char *kbd_magic_keys = env_get("magic_keys");
+		char *kbd_magic_keys = env_get(ctx_uboot, "magic_keys");
 		char *suffix;
 		/*
 		 * loop over all magic keys
@@ -983,7 +983,7 @@ static void preboot_keys(void)
 			char *keys;
 			char magic[sizeof(kbd_magic_prefix) + 1];
 			sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
-			keys = env_get(magic);
+			keys = env_get(ctx_uboot, magic);
 			if (keys) {
 				if (!strcmp(keys, keypress))
 					break;
@@ -993,9 +993,9 @@ static void preboot_keys(void)
 			char cmd_name[sizeof(kbd_command_prefix) + 1];
 			char *cmd;
 			sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
-			cmd = env_get(cmd_name);
+			cmd = env_get(ctx_uboot, cmd_name);
 			if (cmd) {
-				env_set("preboot", cmd);
+				env_set(ctx_uboot, "preboot", cmd);
 				return;
 			}
 		}
@@ -1021,6 +1021,6 @@ int misc_init_r(void)
 #ifdef CONFIG_CMD_BMODE
 	add_board_boot_modes(board_boot_modes);
 #endif
-	env_set_hex("reset_cause", get_imx_reset_cause());
+	env_set_hex(ctx_uboot, "reset_cause", get_imx_reset_cause(void));
 	return 0;
 }
diff --git a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c
index ce9f0494ee59..51e7f2c0c847 100644
--- a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c
+++ b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c
@@ -103,7 +103,7 @@ int board_usb_init(int index, enum usb_init_type init)
 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
 {
 	debug("%s\n", __func__);
-	if (!env_get("serial#"))
+	if (!env_get(ctx_uboot, "serial#"))
 		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
 	return 0;
 }
diff --git a/board/broadcom/bcm28155_ap/bcm28155_ap.c b/board/broadcom/bcm28155_ap/bcm28155_ap.c
index 87616386cb84..d9240cf35c8c 100644
--- a/board/broadcom/bcm28155_ap/bcm28155_ap.c
+++ b/board/broadcom/bcm28155_ap/bcm28155_ap.c
@@ -110,7 +110,7 @@ int board_usb_init(int index, enum usb_init_type init)
 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
 {
 	debug("%s\n", __func__);
-	if (!env_get("serial#"))
+	if (!env_get(ctx_uboot, "serial#"))
 		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
 	return 0;
 }
diff --git a/board/broadcom/bcmstb/bcmstb.c b/board/broadcom/bcmstb/bcmstb.c
index 5fc2c0591b84..494c03d3eb79 100644
--- a/board/broadcom/bcmstb/bcmstb.c
+++ b/board/broadcom/bcmstb/bcmstb.c
@@ -120,7 +120,7 @@ int board_late_init(void)
 	 * Set fdtcontroladdr in the environment so that scripts can
 	 * refer to it, for example, to reuse it for fdtaddr.
 	 */
-	env_set_hex("fdtcontroladdr", prior_stage_fdt_address);
+	env_set_hex(ctx_uboot, "fdtcontroladdr", prior_stage_fdt_address);
 
 	/*
 	 * Do not set machid to the machine identifier value provided
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
index 95d3a5e1f579..f1baed84e268 100644
--- a/board/buffalo/lsxl/lsxl.c
+++ b/board/buffalo/lsxl/lsxl.c
@@ -229,7 +229,7 @@ static void erase_environment(void)
 static void rescue_mode(void)
 {
 	printf("Entering rescue mode..\n");
-	env_set("bootsource", "rescue");
+	env_set(ctx_uboot, "bootsource", "rescue");
 }
 
 static void check_push_button(void)
diff --git a/board/cadence/xtfpga/xtfpga.c b/board/cadence/xtfpga/xtfpga.c
index 256611638a55..1aee9c6f95a0 100644
--- a/board/cadence/xtfpga/xtfpga.c
+++ b/board/cadence/xtfpga/xtfpga.c
@@ -86,14 +86,14 @@ int misc_init_r(void)
 	 * Default MAC address comes from CONFIG_ETHADDR + DIP switches 1-6.
 	 */
 
-	char *s = env_get("ethaddr");
+	char *s = env_get(ctx_uboot, "ethaddr");
 	if (s == 0) {
 		unsigned int x;
 		char s[] = __stringify(CONFIG_ETHBASE);
 		x = (*(volatile u32 *)CONFIG_SYS_FPGAREG_DIPSW)
 			& FPGAREG_MAC_MASK;
 		sprintf(&s[15], "%02x", x);
-		env_set("ethaddr", s);
+		env_set(ctx_uboot, "ethaddr", s);
 	}
 #endif /* CONFIG_CMD_NET */
 
diff --git a/board/ccv/xpress/xpress.c b/board/ccv/xpress/xpress.c
index 05286e643c0e..9518307f7a76 100644
--- a/board/ccv/xpress/xpress.c
+++ b/board/ccv/xpress/xpress.c
@@ -324,7 +324,7 @@ static const struct boot_mode board_boot_modes[] = {
 int board_late_init(void)
 {
 	add_board_boot_modes(board_boot_modes);
-	env_set("board_name", "xpress");
+	env_set(ctx_uboot, "board_name", "xpress");
 
 	return 0;
 }
diff --git a/board/compulab/cl-som-imx7/cl-som-imx7.c b/board/compulab/cl-som-imx7/cl-som-imx7.c
index 395d5dce1785..d05a0dcf32f5 100644
--- a/board/compulab/cl-som-imx7/cl-som-imx7.c
+++ b/board/compulab/cl-som-imx7/cl-som-imx7.c
@@ -311,7 +311,7 @@ void cl_som_imx7_setup_wdog(void)
 
 int board_late_init(void)
 {
-	env_set("board_name", "CL-SOM-iMX7");
+	env_set(ctx_uboot, "board_name", "CL-SOM-iMX7");
 	cl_som_imx7_setup_wdog();
 	return 0;
 }
diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c
index feb7a71f007d..50564fde2ba6 100644
--- a/board/compulab/cm_fx6/cm_fx6.c
+++ b/board/compulab/cm_fx6/cm_fx6.c
@@ -117,10 +117,10 @@ int board_video_skip(void)
 {
 	int ret;
 	struct display_info_t *preset;
-	char const *panel = env_get("displaytype");
+	char const *panel = env_get(ctx_uboot, "displaytype");
 
 	if (!panel) /* Also accept panel for backward compatibility */
-		panel = env_get("panel");
+		panel = env_get(ctx_uboot, "panel");
 
 	if (!panel)
 		return -ENOENT;
@@ -628,16 +628,16 @@ int board_late_init(void)
 	int err;
 
 	if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else if (is_mx6dl())
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 
 	err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
 	if (err)
 		return 0;
 
 	if (!strncmp("SB-FX6m", baseboard_name, 7))
-		env_set("board_name", "Utilite");
+		env_set(ctx_uboot, "board_name", "Utilite");
 #endif
 	return 0;
 }
diff --git a/board/compulab/common/omap3_display.c b/board/compulab/common/omap3_display.c
index cb9ebae7f964..9215a37d982a 100644
--- a/board/compulab/common/omap3_display.c
+++ b/board/compulab/common/omap3_display.c
@@ -398,7 +398,7 @@ void lcd_ctrl_init(void *lcdbase)
 {
 	struct prcm *prcm = (struct prcm *)PRCM_BASE;
 	char *custom_lcd;
-	char *displaytype = env_get("displaytype");
+	char *displaytype = env_get(ctx_uboot, "displaytype");
 
 	if (displaytype == NULL)
 		return;
@@ -406,7 +406,7 @@ void lcd_ctrl_init(void *lcdbase)
 	lcd_def = env_parse_displaytype(displaytype);
 	/* If we did not recognize the preset, check if it's an env variable */
 	if (lcd_def == NONE) {
-		custom_lcd = env_get(displaytype);
+		custom_lcd = env_get(ctx_uboot, displaytype);
 		if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
 			return;
 	}
diff --git a/board/congatec/cgtqmx6eval/cgtqmx6eval.c b/board/congatec/cgtqmx6eval/cgtqmx6eval.c
index 6b3d5b833f44..8143f7680e7b 100644
--- a/board/congatec/cgtqmx6eval/cgtqmx6eval.c
+++ b/board/congatec/cgtqmx6eval/cgtqmx6eval.c
@@ -236,7 +236,7 @@ int power_init_board(void)
 		return 0;
 
 	/* set level of MIPI if specified */
-	lv_mipi = env_get("lv_mipi");
+	lv_mipi = env_get(ctx_uboot, "lv_mipi");
 	if (lv_mipi)
 		return 0;
 
@@ -584,7 +584,7 @@ int board_video_skip(void)
 {
 	int i;
 	int ret;
-	char const *panel = env_get("panel");
+	char const *panel = env_get(ctx_uboot, "panel");
 	if (!panel) {
 		for (i = 0; i < ARRAY_SIZE(displays); i++) {
 			struct display_info_t const *dev = displays + i;
@@ -756,9 +756,9 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 #endif
 
 	return 0;
diff --git a/board/cssi/MCR3000/MCR3000.c b/board/cssi/MCR3000/MCR3000.c
index 445b84c180fe..0f7ba71bb647 100644
--- a/board/cssi/MCR3000/MCR3000.c
+++ b/board/cssi/MCR3000/MCR3000.c
@@ -127,7 +127,7 @@ int misc_init_r(void)
 
 	/* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */
 	if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
-		env_set("bootdelay", "60");
+		env_set(ctx_uboot, "bootdelay", "60");
 
 	return 0;
 }
diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index d9019de6e006..31a380275553 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -280,7 +280,7 @@ u32 get_board_rev(void)
 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
 	u32 rev = 0;
 
-	s = env_get("maxcpuclk");
+	s = env_get(ctx_uboot, "maxcpuclk");
 	if (s)
 		maxcpuclk = simple_strtoul(s, NULL, 10);
 
diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c b/board/davinci/da8xxevm/omapl138_lcdk.c
index 27a51d6a7802..0856b25c16e4 100644
--- a/board/davinci/da8xxevm/omapl138_lcdk.c
+++ b/board/davinci/da8xxevm/omapl138_lcdk.c
@@ -275,7 +275,7 @@ static void dspwake(void)
 	if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
 		return;
 
-	if (!strcmp(env_get("dspwake"), "no"))
+	if (!strcmp(env_get(ctx_uboot, "dspwake"), "no"))
 		return;
 
 	*resetvect++ = 0x1E000; /* DSP Idle */
@@ -305,7 +305,7 @@ int misc_init_r(void)
 	uint8_t tmp[20], addr[10];
 
 
-	if (env_get("ethaddr") == NULL) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		/* Read Ethernet MAC address from EEPROM */
 		if (dvevm_read_mac_address(addr)) {
 			/* Set Ethernet MAC address from EEPROM */
@@ -319,7 +319,7 @@ int misc_init_r(void)
 				addr[0], addr[1], addr[2], addr[3], addr[4],
 				addr[5]);
 
-			env_set("ethaddr", (char *)tmp);
+			env_set(ctx_uboot, "ethaddr", (char *)tmp);
 		} else {
 			printf("Invalid MAC address read.\n");
 		}
diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c b/board/dhelectronics/dh_imx6/dh_imx6.c
index 2d0f78da118f..d904ab4170d3 100644
--- a/board/dhelectronics/dh_imx6/dh_imx6.c
+++ b/board/dhelectronics/dh_imx6/dh_imx6.c
@@ -251,7 +251,7 @@ int board_late_init(void)
 		break;
 	}
 
-	env_set("dhcom", buf);
+	env_set(ctx_uboot, "dhcom", buf);
 
 #ifdef CONFIG_CMD_BMODE
 	add_board_boot_modes(board_boot_modes);
diff --git a/board/eets/pdu001/board.c b/board/eets/pdu001/board.c
index 8a3d0ada270e..104dc1d3c6f7 100644
--- a/board/eets/pdu001/board.c
+++ b/board/eets/pdu001/board.c
@@ -79,15 +79,15 @@ static void env_set_boot_device(void)
 {
 	switch (boot_device()) {
 		case BOOT_DEVICE_MMC1: {
-			env_set("boot_device", "emmc");
+			env_set(ctx_uboot, "boot_device", "emmc");
 			break;
 		}
 		case BOOT_DEVICE_MMC2: {
-			env_set("boot_device", "sdcard");
+			env_set(ctx_uboot, "boot_device", "sdcard");
 			break;
 		}
 		default: {
-			env_set("boot_device", "unknown");
+			env_set(ctx_uboot, "boot_device", "unknown");
 			break;
 		}
 	}
@@ -117,7 +117,7 @@ static void env_set_serial(struct udevice *dev)
 		sprintf(serial + n, "%02X", val);
 	}
 	serial[2 * NODE_ID_BYTE_COUNT] = '\0';
-	env_set("serial#", serial);
+	env_set(ctx_uboot, "serial#", serial);
 }
 
 static void set_mpu_and_core_voltage(void)
diff --git a/board/el/el6x/el6x.c b/board/el/el6x/el6x.c
index 18d69a7da388..606fe1530728 100644
--- a/board/el/el6x/el6x.c
+++ b/board/el/el6x/el6x.c
@@ -467,7 +467,7 @@ int board_late_init(void)
 	add_board_boot_modes(board_boot_modes);
 #endif
 
-	env_set("board_name", BOARD_NAME);
+	env_set(ctx_uboot, "board_name", BOARD_NAME);
 	return 0;
 }
 
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
index 37d48d04f2d0..6cb571ba036c 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -46,7 +46,7 @@ int board_late_init(void)
 		return 0;
 	}
 
-	env_set_hex("kernel_start", kernel_start);
+	env_set_hex(ctx_uboot, "kernel_start", kernel_start);
 
 	return 0;
 }
diff --git a/board/engicam/common/board.c b/board/engicam/common/board.c
index 0c47afe5b566..b338c364efd0 100644
--- a/board/engicam/common/board.c
+++ b/board/engicam/common/board.c
@@ -22,11 +22,11 @@ static void mmc_late_init(void)
 	char mmcblk[32];
 	u32 dev_no = mmc_get_env_dev();
 
-	env_set_ulong("mmcdev", dev_no);
+	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
 
 	/* Set mmcblk env */
 	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
-	env_set("mmcroot", mmcblk);
+	env_set(ctx_uboot, "mmcroot", mmcblk);
 
 	sprintf(cmd, "mmc dev %d", dev_no);
 	run_command(cmd, 0);
@@ -39,25 +39,25 @@ static void setenv_fdt_file(void)
 
 	if (!strcmp(cmp_dtb, "imx6q-icore")) {
 		if (is_mx6dq())
-			env_set("fdt_file", "imx6q-icore.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6q-icore.dtb");
 		else if (is_mx6dl() || is_mx6solo())
-			env_set("fdt_file", "imx6dl-icore.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6dl-icore.dtb");
 	} else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
 		if (is_mx6dq())
-			env_set("fdt_file", "imx6q-icore-mipi.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6q-icore-mipi.dtb");
 		else if (is_mx6dl() || is_mx6solo())
-			env_set("fdt_file", "imx6dl-icore-mipi.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6dl-icore-mipi.dtb");
 	} else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
 		if (is_mx6dq())
-			env_set("fdt_file", "imx6q-icore-rqs.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6q-icore-rqs.dtb");
 		else if (is_mx6dl() || is_mx6solo())
-			env_set("fdt_file", "imx6dl-icore-rqs.dtb");
+			env_set(ctx_uboot, "fdt_file", "imx6dl-icore-rqs.dtb");
 	} else if (!strcmp(cmp_dtb, "imx6ul-geam"))
-		env_set("fdt_file", "imx6ul-geam.dtb");
+		env_set(ctx_uboot, "fdt_file", "imx6ul-geam.dtb");
 	else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
-		env_set("fdt_file", "imx6ul-isiot-emmc.dtb");
+		env_set(ctx_uboot, "fdt_file", "imx6ul-isiot-emmc.dtb");
 	else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
-		env_set("fdt_file", "imx6ul-isiot-nand.dtb");
+		env_set(ctx_uboot, "fdt_file", "imx6ul-isiot-nand.dtb");
 }
 
 int board_late_init(void)
@@ -71,20 +71,20 @@ int board_late_init(void)
 #ifdef CONFIG_ENV_IS_IN_MMC
 		mmc_late_init();
 #endif
-		env_set("modeboot", "mmcboot");
+		env_set(ctx_uboot, "modeboot", "mmcboot");
 		break;
 	case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
-		env_set("modeboot", "nandboot");
+		env_set(ctx_uboot, "modeboot", "nandboot");
 		break;
 	default:
-		env_set("modeboot", "");
+		env_set(ctx_uboot, "modeboot", "");
 		break;
 	}
 
 	if (is_mx6ul())
-		env_set("console", "ttymxc0");
+		env_set(ctx_uboot, "console", "ttymxc0");
 	else
-		env_set("console", "ttymxc3");
+		env_set(ctx_uboot, "console", "ttymxc3");
 
 	setenv_fdt_file();
 
diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
index b0d2f7b6f87b..c9c1d77410cc 100644
--- a/board/esd/meesc/meesc.c
+++ b/board/esd/meesc/meesc.c
@@ -181,7 +181,7 @@ int checkboard(void)
 		puts("Board: EtherCAN/2 Gateway");
 		break;
 	}
-	if (env_get_f("serial#", str, sizeof(str)) > 0) {
+	if (env_get_f("serial#", str, sizeof(ctx_uboot, str)) > 0) {
 		puts(", serial# ");
 		puts(str);
 	}
@@ -198,7 +198,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
 {
 	char *str;
 
-	char *serial = env_get("serial#");
+	char *serial = env_get(ctx_uboot, "serial#");
 	if (serial) {
 		str = strchr(serial, '_');
 		if (str && (strlen(str) >= 4)) {
@@ -231,7 +231,7 @@ int misc_init_r(void)
 	 * In some cases this this needs to be set to 4.
 	 * Check the user has set environment mdiv to 4 to change the divisor.
 	 */
-	str = env_get("mdiv");
+	str = env_get(ctx_uboot, "mdiv");
 	if (str && (strcmp(str, "4") == 0)) {
 		writel((readl(&pmc->mckr) & ~AT91_PMC_MDIV) |
 			AT91SAM9_PMC_MDIV_4, &pmc->mckr);
diff --git a/board/freescale/b4860qds/b4860qds.c b/board/freescale/b4860qds/b4860qds.c
index 33cd4b496489..a8168e60a58a 100644
--- a/board/freescale/b4860qds/b4860qds.c
+++ b/board/freescale/b4860qds/b4860qds.c
@@ -195,7 +195,7 @@ static int adjust_vdd(ulong vdd_override)
 	      vid, vdd_target/10);
 
 	/* check override variable for overriding VDD */
-	vdd_string = env_get("b4qds_vdd_mv");
+	vdd_string = env_get(ctx_uboot, "b4qds_vdd_mv");
 	if (vdd_override == 0 && vdd_string &&
 	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
 		vdd_override = vdd_string_override;
@@ -542,7 +542,8 @@ int configure_vsc3316_3308(void)
 			 * Extract hwconfig from environment since environment
 			 * is not setup properly yet
 			 */
-			env_get_f("hwconfig", buffer, sizeof(buffer));
+			env_get_f(ctx_uboot, "hwconfig", buffer,
+				  sizeof(buffer));
 			buf = buffer;
 
 			if (hwconfig_subarg_cmp_f("fsl_b4860_serdes2",
diff --git a/board/freescale/common/cmd_esbc_validate.c b/board/freescale/common/cmd_esbc_validate.c
index 36b620ca23a0..14ce924b8684 100644
--- a/board/freescale/common/cmd_esbc_validate.c
+++ b/board/freescale/common/cmd_esbc_validate.c
@@ -53,7 +53,7 @@ static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
 	 * to continue U-Boot
 	 */
 	sprintf(buf, "%lx", img_addr);
-	env_set("img_addr", buf);
+	env_set(ctx_uboot, "img_addr", buf);
 
 	if (ret)
 		return 1;
diff --git a/board/freescale/common/fsl_chain_of_trust.c b/board/freescale/common/fsl_chain_of_trust.c
index a024e7239e6e..9e216c3f51d7 100644
--- a/board/freescale/common/fsl_chain_of_trust.c
+++ b/board/freescale/common/fsl_chain_of_trust.c
@@ -80,12 +80,12 @@ int fsl_setenv_chain_of_trust(void)
 	 * bootdelay = 0 (To disable Boot Prompt)
 	 * bootcmd = CONFIG_CHAIN_BOOT_CMD (Validate and execute Boot script)
 	 */
-	env_set("bootdelay", "-2");
+	env_set(ctx_uboot, "bootdelay", "-2");
 
 #ifdef CONFIG_ARM
-	env_set("secureboot", "y");
+	env_set(ctx_uboot, "secureboot", "y");
 #else
-	env_set("bootcmd", CONFIG_CHAIN_BOOT_CMD);
+	env_set(ctx_uboot, "bootcmd", CONFIG_CHAIN_BOOT_CMD);
 #endif
 
 	return 0;
diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c
index bb655ca7447c..88640958c79d 100644
--- a/board/freescale/common/sys_eeprom.c
+++ b/board/freescale/common/sys_eeprom.c
@@ -538,8 +538,8 @@ int mac_read_from_eeprom(void)
 			/* Only initialize environment variables that are blank
 			 * (i.e. have not yet been set)
 			 */
-			if (!env_get(enetvar))
-				env_set(enetvar, ethaddr);
+			if (!env_get(ctx_uboot, enetvar))
+				env_set(ctx_uboot, enetvar, ethaddr);
 		}
 	}
 
diff --git a/board/freescale/common/vid.c b/board/freescale/common/vid.c
index b37f3bf4f8fe..db23c8387e5c 100644
--- a/board/freescale/common/vid.c
+++ b/board/freescale/common/vid.c
@@ -617,7 +617,7 @@ int adjust_vdd(ulong vdd_override)
 	vdd_target = vdd[vid];
 
 	/* check override variable for overriding VDD */
-	vdd_string = env_get(CONFIG_VID_FLS_ENV);
+	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
 	if (vdd_override == 0 && vdd_string &&
 	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
 		vdd_override = vdd_string_override;
@@ -824,7 +824,7 @@ int adjust_vdd(ulong vdd_override)
 	vdd_target = vdd[vid];
 
 	/* check override variable for overriding VDD */
-	vdd_string = env_get(CONFIG_VID_FLS_ENV);
+	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
 	if (vdd_override == 0 && vdd_string &&
 	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
 		vdd_override = vdd_string_override;
diff --git a/board/freescale/imx8mq_evk/imx8mq_evk.c b/board/freescale/imx8mq_evk/imx8mq_evk.c
index 1463e6e6963b..1822df9f32e8 100644
--- a/board/freescale/imx8mq_evk/imx8mq_evk.c
+++ b/board/freescale/imx8mq_evk/imx8mq_evk.c
@@ -123,8 +123,8 @@ int board_mmc_get_env_dev(int devno)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "EVK");
-	env_set("board_rev", "iMX8MQ");
+	env_set(ctx_uboot, "board_name", "EVK");
+	env_set(ctx_uboot, "board_rev", "iMX8MQ");
 #endif
 
 	return 0;
diff --git a/board/freescale/imx8qm_mek/imx8qm_mek.c b/board/freescale/imx8qm_mek/imx8qm_mek.c
index 76634a3a28ad..34ed03c3dec1 100644
--- a/board/freescale/imx8qm_mek/imx8qm_mek.c
+++ b/board/freescale/imx8qm_mek/imx8qm_mek.c
@@ -126,8 +126,8 @@ int board_mmc_get_env_dev(int devno)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "MEK");
-	env_set("board_rev", "iMX8QM");
+	env_set(ctx_uboot, "board_name", "MEK");
+	env_set(ctx_uboot, "board_rev", "iMX8QM");
 #endif
 
 	return 0;
diff --git a/board/freescale/imx8qxp_mek/imx8qxp_mek.c b/board/freescale/imx8qxp_mek/imx8qxp_mek.c
index 4ba83142841a..0d6152ac9551 100644
--- a/board/freescale/imx8qxp_mek/imx8qxp_mek.c
+++ b/board/freescale/imx8qxp_mek/imx8qxp_mek.c
@@ -139,8 +139,8 @@ int board_mmc_get_env_dev(int devno)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "MEK");
-	env_set("board_rev", "iMX8QXP");
+	env_set(ctx_uboot, "board_name", "MEK");
+	env_set(ctx_uboot, "board_rev", "iMX8QXP");
 #endif
 
 	return 0;
diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
index 237088a53710..f618db490f00 100644
--- a/board/freescale/ls1088a/eth_ls1088aqds.c
+++ b/board/freescale/ls1088a/eth_ls1088aqds.c
@@ -529,7 +529,7 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
 	serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
 
 	int *riser_phy_addr;
-	char *env_hwconfig = env_get("hwconfig");
+	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	if (hwconfig_f("xqsgmii", env_hwconfig))
 		riser_phy_addr = &xqsgii_riser_phy_addr[0];
@@ -670,7 +670,7 @@ int board_eth_init(bd_t *bis)
 	int error = 0, i;
 #ifdef CONFIG_FSL_MC_ENET
 	struct memac_mdio_info *memac_mdio0_info;
-	char *env_hwconfig = env_get("hwconfig");
+	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	initialize_dpmac_to_slot();
 
diff --git a/board/freescale/ls1088a/ls1088a.c b/board/freescale/ls1088a/ls1088a.c
index f1592982a348..cdbfd90c19fa 100644
--- a/board/freescale/ls1088a/ls1088a.c
+++ b/board/freescale/ls1088a/ls1088a.c
@@ -984,7 +984,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 #ifdef CONFIG_MTD_NOR_FLASH
 int is_flash_available(void)
 {
-	char *env_hwconfig = env_get("hwconfig");
+	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
 	enum boot_src src = get_boot_src();
 	int is_nor_flash_available = 1;
 
diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
index 6a8788c31254..1103ca1d430c 100644
--- a/board/freescale/ls2080aqds/eth.c
+++ b/board/freescale/ls2080aqds/eth.c
@@ -506,7 +506,7 @@ static void initialize_dpmac_to_slot(void)
 		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
 
 	char *env_hwconfig;
-	env_hwconfig = env_get("hwconfig");
+	env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	switch (serdes1_prtcl) {
 	case 0x07:
@@ -660,7 +660,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
 
 	int *riser_phy_addr;
-	char *env_hwconfig = env_get("hwconfig");
+	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	if (hwconfig_f("xqsgmii", env_hwconfig))
 		riser_phy_addr = &xqsgii_riser_phy_addr[0];
@@ -906,7 +906,7 @@ int board_eth_init(bd_t *bis)
 	unsigned int i;
 	char *env_hwconfig;
 
-	env_hwconfig = env_get("hwconfig");
+	env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	initialize_dpmac_to_slot();
 
diff --git a/board/freescale/ls2080aqds/ls2080aqds.c b/board/freescale/ls2080aqds/ls2080aqds.c
index 91c80353edd6..6eef0536d162 100644
--- a/board/freescale/ls2080aqds/ls2080aqds.c
+++ b/board/freescale/ls2080aqds/ls2080aqds.c
@@ -212,7 +212,7 @@ int board_init(void)
 
 	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
 
-	env_hwconfig = env_get("hwconfig");
+	env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	if (hwconfig_f("dspi", env_hwconfig) &&
 	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
diff --git a/board/freescale/ls2080ardb/ls2080ardb.c b/board/freescale/ls2080ardb/ls2080ardb.c
index e20267f27ce0..d7ea56a6613a 100644
--- a/board/freescale/ls2080ardb/ls2080ardb.c
+++ b/board/freescale/ls2080ardb/ls2080ardb.c
@@ -265,7 +265,7 @@ int misc_init_r(void)
 
 	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
 
-	env_hwconfig = env_get("hwconfig");
+	env_hwconfig = env_get(ctx_uboot, "hwconfig");
 
 	if (hwconfig_f("dspi", env_hwconfig) &&
 	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
@@ -295,10 +295,10 @@ int misc_init_r(void)
 	 */
 	if ((SVR_SOC_VER(svr) == SVR_LS2088A) ||
 	    (SVR_SOC_VER(svr) == SVR_LS2048A))
-		env_set("board", "ls2088ardb");
+		env_set(ctx_uboot, "board", "ls2088ardb");
 	else if ((SVR_SOC_VER(svr) == SVR_LS2081A) ||
 	    (SVR_SOC_VER(svr) == SVR_LS2041A))
-		env_set("board", "ls2081ardb");
+		env_set(ctx_uboot, "board", "ls2081ardb");
 
 	return 0;
 }
diff --git a/board/freescale/lx2160a/eth_lx2160aqds.c b/board/freescale/lx2160a/eth_lx2160aqds.c
index 92c06e5060f1..40fb5092c337 100644
--- a/board/freescale/lx2160a/eth_lx2160aqds.c
+++ b/board/freescale/lx2160a/eth_lx2160aqds.c
@@ -484,7 +484,7 @@ int board_eth_init(bd_t *bis)
 	 * defining "dpmac_override" in hwconfig environment variable.
 	 */
 	if (hwconfig("dpmac_override")) {
-		env_dpmac = env_get("dpmac");
+		env_dpmac = env_get(ctx_uboot, "dpmac");
 		if (env_dpmac) {
 			ret = hwconfig_arg_f("srds", &len, env_dpmac);
 			if (ret) {
diff --git a/board/freescale/mpc8323erdb/mpc8323erdb.c b/board/freescale/mpc8323erdb/mpc8323erdb.c
index e5aecc4e1f28..aa19a1b8534d 100644
--- a/board/freescale/mpc8323erdb/mpc8323erdb.c
+++ b/board/freescale/mpc8323erdb/mpc8323erdb.c
@@ -217,7 +217,8 @@ int mac_read_from_eeprom(void)
 						buf[i * 6 + 4], buf[i * 6 + 5]);
 					sprintf((char *)enetvar,
 						i ? "eth%daddr" : "ethaddr", i);
-					env_set((char *)enetvar, str);
+					env_set(ctx_uboot, (char *)enetvar,
+						str);
 				}
 			}
 		}
diff --git a/board/freescale/mpc837xemds/pci.c b/board/freescale/mpc837xemds/pci.c
index 41b78cf5e4de..c6f734ef2625 100644
--- a/board/freescale/mpc837xemds/pci.c
+++ b/board/freescale/mpc837xemds/pci.c
@@ -67,7 +67,7 @@ static struct pci_region pcie_regions_1[] = {
 
 static int is_pex_x2(void)
 {
-	const char *pex_x2 = env_get("pex_x2");
+	const char *pex_x2 = env_get(ctx_uboot, "pex_x2");
 
 	if (pex_x2 && !strcmp(pex_x2, "yes"))
 		return 1;
diff --git a/board/freescale/mpc837xerdb/mpc837xerdb.c b/board/freescale/mpc837xerdb/mpc837xerdb.c
index 4ad62bcf1d6b..71939b240dae 100644
--- a/board/freescale/mpc837xerdb/mpc837xerdb.c
+++ b/board/freescale/mpc837xerdb/mpc837xerdb.c
@@ -173,7 +173,7 @@ int board_mmc_init(bd_t *bd)
 	char buffer[HWCONFIG_BUFFER_SIZE] = {0};
 	int esdhc_hwconfig_enabled = 0;
 
-	if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
+	if (env_get_f("hwconfig", buffer, sizeof(ctx_uboot, buffer)) > 0)
 		esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
 
 	if (esdhc_hwconfig_enabled == 0)
diff --git a/board/freescale/mx51evk/mx51evk_video.c b/board/freescale/mx51evk/mx51evk_video.c
index 3715c5d738f9..ed2a58ea4a9a 100644
--- a/board/freescale/mx51evk/mx51evk_video.c
+++ b/board/freescale/mx51evk/mx51evk_video.c
@@ -76,7 +76,7 @@ void setup_iomux_lcd(void)
 int board_video_skip(void)
 {
 	int ret;
-	char const *e = env_get("panel");
+	char const *e = env_get(ctx_uboot, "panel");
 
 	if (e) {
 		if (strcmp(e, "claa") == 0) {
diff --git a/board/freescale/mx53loco/mx53loco.c b/board/freescale/mx53loco/mx53loco.c
index a177815bb8aa..a3328a134fb8 100644
--- a/board/freescale/mx53loco/mx53loco.c
+++ b/board/freescale/mx53loco/mx53loco.c
@@ -208,7 +208,7 @@ static int power_init(void)
 		if (!p)
 			return -ENODEV;
 
-		env_set("fdt_file", "imx53-qsb.dtb");
+		env_set(ctx_uboot, "fdt_file", "imx53-qsb.dtb");
 
 		/* Set VDDA to 1.25V */
 		val = DA9052_BUCKCORE_BCOREEN | DA_BUCKCORE_VBCORE_1_250V;
@@ -251,7 +251,7 @@ static int power_init(void)
 		if (!p)
 			return -ENODEV;
 
-		env_set("fdt_file", "imx53-qsrb.dtb");
+		env_set(ctx_uboot, "fdt_file", "imx53-qsrb.dtb");
 
 		/* Set VDDGP to 1.25V for 1GHz on SW1 */
 		pmic_reg_read(p, REG_SW_0, &val);
diff --git a/board/freescale/mx53loco/mx53loco_video.c b/board/freescale/mx53loco/mx53loco_video.c
index ff3fc8ce3e6f..061c990bcfb5 100644
--- a/board/freescale/mx53loco/mx53loco_video.c
+++ b/board/freescale/mx53loco/mx53loco_video.c
@@ -92,7 +92,7 @@ void setup_iomux_lcd(void)
 int board_video_skip(void)
 {
 	int ret;
-	char const *e = env_get("panel");
+	char const *e = env_get(ctx_uboot, "panel");
 
 	if (e) {
 		if (strcmp(e, "seiko") == 0) {
diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c b/board/freescale/mx6sabreauto/mx6sabreauto.c
index dc156efbbcbc..a1cd8f4bc52e 100644
--- a/board/freescale/mx6sabreauto/mx6sabreauto.c
+++ b/board/freescale/mx6sabreauto/mx6sabreauto.c
@@ -623,14 +623,14 @@ int board_late_init(void)
 #endif
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "SABREAUTO");
+	env_set(ctx_uboot, "board_name", "SABREAUTO");
 
 	if (is_mx6dqp())
-		env_set("board_rev", "MX6QP");
+		env_set(ctx_uboot, "board_rev", "MX6QP");
 	else if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else if (is_mx6sdl())
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 #endif
 
 	return 0;
diff --git a/board/freescale/mx6sabresd/mx6sabresd.c b/board/freescale/mx6sabresd/mx6sabresd.c
index b0c0117968bf..fb4c03a428c8 100644
--- a/board/freescale/mx6sabresd/mx6sabresd.c
+++ b/board/freescale/mx6sabresd/mx6sabresd.c
@@ -606,14 +606,14 @@ int board_late_init(void)
 #endif
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "SABRESD");
+	env_set(ctx_uboot, "board_name", "SABRESD");
 
 	if (is_mx6dqp())
-		env_set("board_rev", "MX6QP");
+		env_set(ctx_uboot, "board_rev", "MX6QP");
 	else if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else if (is_mx6sdl())
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 #endif
 
 	return 0;
diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c b/board/freescale/mx6sxsabresd/mx6sxsabresd.c
index 1c10958879b1..b4bc682a5160 100644
--- a/board/freescale/mx6sxsabresd/mx6sxsabresd.c
+++ b/board/freescale/mx6sxsabresd/mx6sxsabresd.c
@@ -309,7 +309,7 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (is_reva())
-		env_set("board_rev", "REVA");
+		env_set(ctx_uboot, "board_rev", "REVA");
 #endif
 	return 0;
 }
diff --git a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
index ccbe4044786c..913b2c6c57b8 100644
--- a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
+++ b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
@@ -545,12 +545,12 @@ int board_late_init(void)
 #endif
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "EVK");
+	env_set(ctx_uboot, "board_name", "EVK");
 
 	if (is_mx6ul_9x9_evk())
-		env_set("board_rev", "9X9");
+		env_set(ctx_uboot, "board_rev", "9X9");
 	else
-		env_set("board_rev", "14X14");
+		env_set(ctx_uboot, "board_rev", "14X14");
 #endif
 
 	return 0;
diff --git a/board/freescale/mx6ullevk/mx6ullevk.c b/board/freescale/mx6ullevk/mx6ullevk.c
index e11934780262..8dc5511e245f 100644
--- a/board/freescale/mx6ullevk/mx6ullevk.c
+++ b/board/freescale/mx6ullevk/mx6ullevk.c
@@ -84,8 +84,8 @@ int board_late_init(void)
 #endif
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", "EVK");
-	env_set("board_rev", "14X14");
+	env_set(ctx_uboot, "board_name", "EVK");
+	env_set(ctx_uboot, "board_rev", "14X14");
 #endif
 
 	return 0;
diff --git a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
index a04a73528f8d..4a21c148b696 100644
--- a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
+++ b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
@@ -350,7 +350,7 @@ int board_eth_init(bd_t *bis)
 
 #ifdef CONFIG_VSC7385_ENET
 	/* If a VSC7385 microcode image is present, then upload it. */
-	tmp = env_get("vscfw_addr");
+	tmp = env_get(ctx_uboot, "vscfw_addr");
 	if (tmp) {
 		vscfw_addr = simple_strtoul(tmp, NULL, 16);
 		printf("uploading VSC7385 microcode from %x\n", vscfw_addr);
diff --git a/board/freescale/qemu-ppce500/qemu-ppce500.c b/board/freescale/qemu-ppce500/qemu-ppce500.c
index fb36d8366c98..38608234b7d5 100644
--- a/board/freescale/qemu-ppce500/qemu-ppce500.c
+++ b/board/freescale/qemu-ppce500/qemu-ppce500.c
@@ -211,10 +211,10 @@ int last_stage_init(void)
 	/* -kernel boot */
 	prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len);
 	if (prop && (len >= 8))
-		env_set_hex("qemu_kernel_addr", *prop);
+		env_set_hex(ctx_uboot, "qemu_kernel_addr", *prop);
 
 	/* Give the user a variable for the host fdt */
-	env_set_hex("fdt_addr_r", (ulong)fdt);
+	env_set_hex("fdt_addr_r", (ctx_uboot, ulong)fdt);
 
 	return 0;
 }
diff --git a/board/freescale/t4qds/t4240qds.c b/board/freescale/t4qds/t4240qds.c
index bb18b97e6a2e..d4e92d6c8d51 100644
--- a/board/freescale/t4qds/t4240qds.c
+++ b/board/freescale/t4qds/t4240qds.c
@@ -265,7 +265,7 @@ static int adjust_vdd(ulong vdd_override)
 	vdd_target = vdd[vid];
 
 	/* check override variable for overriding VDD */
-	vdd_string = env_get("t4240qds_vdd_mv");
+	vdd_string = env_get(ctx_uboot, "t4240qds_vdd_mv");
 	if (vdd_override == 0 && vdd_string &&
 	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
 		vdd_override = vdd_string_override;
diff --git a/board/gardena/smart-gateway-at91sam/board.c b/board/gardena/smart-gateway-at91sam/board.c
index 3e2da0d6f8e0..499605d5b6a1 100644
--- a/board/gardena/smart-gateway-at91sam/board.c
+++ b/board/gardena/smart-gateway-at91sam/board.c
@@ -15,7 +15,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static void at91_prepare_cpu_var(void)
 {
-	env_set("cpu", get_cpu_name());
+	env_set(ctx_uboot, "cpu", get_cpu_name());
 }
 
 int board_late_init(void)
diff --git a/board/gardena/smart-gateway-mt7688/board.c b/board/gardena/smart-gateway-mt7688/board.c
index bd494c84fc80..fe39187d0738 100644
--- a/board/gardena/smart-gateway-mt7688/board.c
+++ b/board/gardena/smart-gateway-mt7688/board.c
@@ -70,9 +70,9 @@ static bool prepare_uuid_var(const char *fd_ptr, const char *env_var_name,
 			str[i] = errorchar;
 	}
 
-	env = env_get(env_var_name);
+	env = env_get(ctx_uboot, env_var_name);
 	if (strcmp(env, str)) {
-		env_set(env_var_name, str);
+		env_set(ctx_uboot, env_var_name, str);
 		env_updated = true;
 	}
 
@@ -134,9 +134,9 @@ static void factory_data_env_config(void)
 	if (!is_valid_ethaddr(ptr))
 		printf("F-Data:Invalid MAC addr: wifi_mac %s\n", str);
 
-	env = env_get("wifiaddr");
+	env = env_get(ctx_uboot, "wifiaddr");
 	if (strcmp(env, str)) {
-		env_set("wifiaddr", str);
+		env_set(ctx_uboot, "wifiaddr", str);
 		env_updated = 1;
 	}
 
@@ -146,9 +146,9 @@ static void factory_data_env_config(void)
 	if (!is_valid_ethaddr(ptr))
 		printf("F-Data:Invalid MAC addr: eth_mac %s\n", str);
 
-	env = env_get("ethaddr");
+	env = env_get(ctx_uboot, "ethaddr");
 	if (strcmp(env, str)) {
-		env_set("ethaddr", str);
+		env_set(ctx_uboot, "ethaddr", str);
 		env_updated = 1;
 	}
 
@@ -161,7 +161,7 @@ static void factory_data_env_config(void)
 	/* Check if the environment was updated and needs to get stored */
 	if (env_updated != 0) {
 		printf("F-Data:Values don't match env values -> saving\n");
-		env_save();
+		env_save(ctx_uboot);
 	} else {
 		debug("F-Data:Values match current env values\n");
 	}
@@ -189,7 +189,7 @@ static void copy_or_generate_uuid(char *fd_ptr, const char *env_var_name)
 	char *env;
 
 	/* Don't use the UUID dest place, as the \0 char won't fit */
-	env = env_get(env_var_name);
+	env = env_get(ctx_uboot, env_var_name);
 	if (env)
 		strncpy(str, env, UUID_STR_LEN);
 	else
diff --git a/board/gateworks/gw_ventana/common.c b/board/gateworks/gw_ventana/common.c
index 1240a9da174f..0be40c2336ad 100644
--- a/board/gateworks/gw_ventana/common.c
+++ b/board/gateworks/gw_ventana/common.c
@@ -1477,7 +1477,7 @@ void setup_board_gpio(int board, struct ventana_board_info *info)
 	char arg[10];
 	size_t len;
 	int i;
-	int quiet = simple_strtol(env_get("quiet"), NULL, 10);
+	int quiet = simple_strtol(env_get(ctx_uboot, "quiet"), NULL, 10);
 
 	if (board >= GW_UNKNOWN)
 		return;
diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
index 8a694a71c90b..6782e6327978 100644
--- a/board/gateworks/gw_ventana/gw_ventana.c
+++ b/board/gateworks/gw_ventana/gw_ventana.c
@@ -299,11 +299,12 @@ int board_eth_init(bd_t *bis)
 #endif
 
 	/* default to the first detected enet dev */
-	if (!env_get("ethprime")) {
+	if (!env_get(ctx_uboot, "ethprime")) {
 		struct eth_device *dev = eth_get_dev_by_index(0);
 		if (dev) {
-			env_set("ethprime", dev->name);
-			printf("set ethprime to %s\n", env_get("ethprime"));
+			env_set(ctx_uboot, "ethprime", dev->name);
+			printf("set ethprime to %s\n",
+			       env_get(ctx_uboot, "ethprime"));
 		}
 	}
 
@@ -602,7 +603,7 @@ void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
  */
 void get_board_serial(struct tag_serialnr *serialnr)
 {
-	char *serial = env_get("serial#");
+	char *serial = env_get(ctx_uboot, "serial#");
 
 	if (serial) {
 		serialnr->high = 0;
@@ -685,11 +686,11 @@ int checkboard(void)
 	int quiet; /* Quiet or minimal output mode */
 
 	quiet = 0;
-	p = env_get("quiet");
+	p = env_get(ctx_uboot, "quiet");
 	if (p)
 		quiet = simple_strtol(p, NULL, 10);
 	else
-		env_set("quiet", "0");
+		env_set(ctx_uboot, "quiet", "0");
 
 	puts("\nGateworks Corporation Copyright 2014\n");
 	if (info->model[0]) {
@@ -764,26 +765,26 @@ int misc_init_r(void)
 		else if (is_cpu_type(MXC_CPU_MX6DL) ||
 			 is_cpu_type(MXC_CPU_MX6SOLO))
 			cputype = "imx6dl";
-		env_set("soctype", cputype);
+		env_set(ctx_uboot, "soctype", cputype);
 		if (8 << (ventana_info.nand_flash_size-1) >= 2048)
-			env_set("flash_layout", "large");
+			env_set(ctx_uboot, "flash_layout", "large");
 		else
-			env_set("flash_layout", "normal");
+			env_set(ctx_uboot, "flash_layout", "normal");
 		memset(str, 0, sizeof(str));
 		for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
 			str[i] = tolower(info->model[i]);
-		env_set("model", str);
-		if (!env_get("fdt_file")) {
+		env_set(ctx_uboot, "model", str);
+		if (!env_get(ctx_uboot, "fdt_file")) {
 			sprintf(fdt, "%s-%s.dtb", cputype, str);
-			env_set("fdt_file", fdt);
+			env_set(ctx_uboot, "fdt_file", fdt);
 		}
 		p = strchr(str, '-');
 		if (p) {
 			*p++ = 0;
 
-			env_set("model_base", str);
+			env_set(ctx_uboot, "model_base", str);
 			sprintf(fdt, "%s-%s.dtb", cputype, str);
-			env_set("fdt_file1", fdt);
+			env_set(ctx_uboot, "fdt_file1", fdt);
 			if (board_type != GW551x &&
 			    board_type != GW552x &&
 			    board_type != GW553x &&
@@ -792,30 +793,30 @@ int misc_init_r(void)
 			str[5] = 'x';
 			str[6] = 0;
 			sprintf(fdt, "%s-%s.dtb", cputype, str);
-			env_set("fdt_file2", fdt);
+			env_set(ctx_uboot, "fdt_file2", fdt);
 		}
 
 		/* initialize env from EEPROM */
 		if (test_bit(EECONFIG_ETH0, info->config) &&
-		    !env_get("ethaddr")) {
+		    !env_get(ctx_uboot, "ethaddr")) {
 			eth_env_set_enetaddr("ethaddr", info->mac0);
 		}
 		if (test_bit(EECONFIG_ETH1, info->config) &&
-		    !env_get("eth1addr")) {
+		    !env_get(ctx_uboot, "eth1addr")) {
 			eth_env_set_enetaddr("eth1addr", info->mac1);
 		}
 
 		/* board serial-number */
 		sprintf(str, "%6d", info->serial);
-		env_set("serial#", str);
+		env_set(ctx_uboot, "serial#", str);
 
 		/* memory MB */
 		sprintf(str, "%d", (int) (gd->ram_size >> 20));
-		env_set("mem_mb", str);
+		env_set(ctx_uboot, "mem_mb", str);
 	}
 
 	/* Set a non-initialized hwconfig based on board configuration */
-	if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
+	if (!strcmp(env_get(ctx_uboot, "hwconfig"), "_UNKNOWN_")) {
 		buf[0] = 0;
 		if (gpio_cfg[board_type].rs232_en)
 			strcat(buf, "rs232;");
@@ -825,7 +826,7 @@ int misc_init_r(void)
 			if (strlen(buf) + strlen(buf1) < sizeof(buf))
 				strcat(buf, buf1);
 		}
-		env_set("hwconfig", buf);
+		env_set(ctx_uboot, "hwconfig", buf);
 	}
 
 	/* setup baseboard specific GPIO based on board and env */
@@ -1040,7 +1041,7 @@ int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
 	int j;
 
 	sprintf(mac, "eth1addr");
-	tmp = env_get(mac);
+	tmp = env_get(ctx_uboot, mac);
 	if (tmp) {
 		for (j = 0; j < 6; j++) {
 			mac_addr[j] = tmp ?
@@ -1128,8 +1129,8 @@ int ft_board_setup(void *blob, bd_t *bd)
 		{ "sst,w25q256",          MTD_DEV_TYPE_NOR, },  /* SPI flash */
 		{ "fsl,imx6q-gpmi-nand",  MTD_DEV_TYPE_NAND, }, /* NAND flash */
 	};
-	const char *model = env_get("model");
-	const char *display = env_get("display");
+	const char *model = env_get(ctx_uboot, "model");
+	const char *display = env_get(ctx_uboot, "display");
 	int i;
 	char rev = 0;
 
@@ -1141,7 +1142,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 		}
 	}
 
-	if (env_get("fdt_noauto")) {
+	if (env_get(ctx_uboot, "fdt_noauto")) {
 		puts("   Skiping ft_board_setup (fdt_noauto defined)\n");
 		return 0;
 	}
@@ -1162,15 +1163,15 @@ int ft_board_setup(void *blob, bd_t *bd)
 	printf("   Adjusting FDT per EEPROM for %s...\n", model);
 
 	/* board serial number */
-	fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
-		    strlen(env_get("serial#")) + 1);
+	fdt_setprop(blob, 0, "system-serial", env_get(ctx_uboot, "serial#"),
+		    strlen(env_get(ctx_uboot, "serial#")) + 1);
 
 	/* board (model contains model from device-tree) */
 	fdt_setprop(blob, 0, "board", info->model,
 		    strlen((const char *)info->model) + 1);
 
 	/* set desired digital video capture format */
-	ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
+	ft_sethdmiinfmt(blob, env_get(ctx_uboot, "hdmiinfmt"));
 
 	/*
 	 * Board model specific fixups
@@ -1340,7 +1341,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 	}
 
 #if defined(CONFIG_CMD_PCI)
-	if (!env_get("nopcifixup"))
+	if (!env_get(ctx_uboot, "nopcifixup"))
 		ft_board_pci_fixup(blob, bd);
 #endif
 
@@ -1349,7 +1350,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 	 *  remove nodes by alias path if EEPROM config tells us the
 	 *  peripheral is not loaded on the board.
 	 */
-	if (env_get("fdt_noconfig")) {
+	if (env_get(ctx_uboot, "fdt_noconfig")) {
 		puts("   Skiping periperhal config (fdt_noconfig defined)\n");
 		return 0;
 	}
diff --git a/board/gateworks/gw_ventana/gw_ventana_spl.c b/board/gateworks/gw_ventana/gw_ventana_spl.c
index b0891379a170..a689ec16d98c 100644
--- a/board/gateworks/gw_ventana/gw_ventana_spl.c
+++ b/board/gateworks/gw_ventana/gw_ventana_spl.c
@@ -758,8 +758,8 @@ int spl_start_uboot(void)
 	debug("%s\n", __func__);
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
-	debug("boot_os=%s\n", env_get("boot_os"));
+	env_load(ctx_uboot);
+	debug("boot_os=%s\n", env_get(ctx_uboot, "boot_os"));
 	if (env_get_yesno("boot_os") == 1)
 		ret = 0;
 #else
diff --git a/board/gdsys/a38x/keyprogram.c b/board/gdsys/a38x/keyprogram.c
index 000897984a6e..f65190d814c2 100644
--- a/board/gdsys/a38x/keyprogram.c
+++ b/board/gdsys/a38x/keyprogram.c
@@ -131,12 +131,12 @@ int load_and_run_keyprog(struct udevice *tpm)
 	char *hexprog;
 	struct key_program *prog;
 
-	cmd = env_get("loadkeyprogram");
+	cmd = env_get(ctx_uboot, "loadkeyprogram");
 
 	if (!cmd || run_command(cmd, 0))
 		return 1;
 
-	hexprog = env_get("keyprogram");
+	hexprog = env_get(ctx_uboot, "keyprogram");
 
 	if (decode_hexstr(hexprog, &binprog))
 		return 1;
diff --git a/board/gdsys/mpc8308/gazerbeam.c b/board/gdsys/mpc8308/gazerbeam.c
index ddd6ee895384..4929296364b3 100644
--- a/board/gdsys/mpc8308/gazerbeam.c
+++ b/board/gdsys/mpc8308/gazerbeam.c
@@ -85,7 +85,7 @@ int board_early_init_r(void)
 int checkboard(void)
 {
 	struct udevice *board;
-	char *s = env_get("serial#");
+	char *s = env_get(ctx_uboot, "serial#");
 	int mc = 0;
 	int con = 0;
 
@@ -137,7 +137,7 @@ int last_stage_init(void)
 			printf("Could not determind FPGA HW revision (res = %d)\n", res);
 	}
 
-	env_set_ulong("fpga_hw_rev", fpga_hw_rev);
+	env_set_ulong(ctx_uboot, "fpga_hw_rev", fpga_hw_rev);
 
 	ret = get_tpm(&tpm);
 	if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c
index 60faa4688cf8..666eb25c809c 100644
--- a/board/gdsys/mpc8308/hrcon.c
+++ b/board/gdsys/mpc8308/hrcon.c
@@ -101,7 +101,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
 
 int checkboard(void)
 {
-	char *s = env_get("serial#");
+	char *s = env_get(ctx_uboot, "serial#");
 	bool hw_type_cat = pca9698_get_value(0x20, 20);
 
 	puts("Board: ");
diff --git a/board/gdsys/mpc8308/strider.c b/board/gdsys/mpc8308/strider.c
index 886bc2b035de..cc3fcd7de172 100644
--- a/board/gdsys/mpc8308/strider.c
+++ b/board/gdsys/mpc8308/strider.c
@@ -104,7 +104,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
 
 int checkboard(void)
 {
-	char *s = env_get("serial#");
+	char *s = env_get(ctx_uboot, "serial#");
 	bool hw_type_cat = pca9698_get_value(0x20, 18);
 
 	puts("Board: ");
diff --git a/board/gdsys/p1022/controlcenterd-id.c b/board/gdsys/p1022/controlcenterd-id.c
index 43f5404231f0..db7c92446e75 100644
--- a/board/gdsys/p1022/controlcenterd-id.c
+++ b/board/gdsys/p1022/controlcenterd-id.c
@@ -231,7 +231,7 @@ static u8 *get_2nd_stage_bl_location(ulong target_addr)
 {
 	ulong addr;
 #ifdef CCDM_SECOND_STAGE
-	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
+	addr = env_get_ulong(ctx_uboot, "loadaddr", 16, CONFIG_LOADADDR);
 #else
 	addr = target_addr;
 #endif
@@ -249,7 +249,7 @@ static u8 *get_image_location(void)
 {
 	ulong addr;
 	/* TODO use other area? */
-	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
+	addr = env_get_ulong(ctx_uboot, "loadaddr", 16, CONFIG_LOADADDR);
 	return (u8 *)(addr);
 }
 #endif
@@ -1072,13 +1072,13 @@ static int second_stage_init(void)
 		goto failure;
 
 	/* run "prepboot" from env to get "mmcdev" set */
-	cptr = env_get("prepboot");
+	cptr = env_get(ctx_uboot, "prepboot");
 	if (cptr && !run_command(cptr, 0))
-		mmcdev = env_get("mmcdev");
+		mmcdev = env_get(ctx_uboot, "mmcdev");
 	if (!mmcdev)
 		goto failure;
 
-	cptr = env_get("ramdiskimage");
+	cptr = env_get(ctx_uboot, "ramdiskimage");
 	if (cptr)
 		image_path = cptr;
 
diff --git a/board/gdsys/p1022/controlcenterd.c b/board/gdsys/p1022/controlcenterd.c
index 6eb3d6c5d06e..ec349d61ee33 100644
--- a/board/gdsys/p1022/controlcenterd.c
+++ b/board/gdsys/p1022/controlcenterd.c
@@ -222,7 +222,7 @@ void hw_watchdog_reset(void)
 #ifdef CONFIG_TRAILBLAZER
 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	return run_command(env_get("bootcmd"), flag);
+	return run_command(env_get(ctx_uboot, "bootcmd"), flag);
 }
 
 int board_early_init_r(void)
diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
index 917ecc4c1816..3262a73d0b80 100644
--- a/board/ge/bx50v3/bx50v3.c
+++ b/board/ge/bx50v3/bx50v3.c
@@ -470,17 +470,17 @@ static void process_vpd(struct vpd_cache *vpd)
 
 	switch (vpd->product_id) {
 	case VPD_PRODUCT_B450:
-		env_set("confidx", "1");
+		env_set(ctx_uboot, "confidx", "1");
 		i210_index = 0;
 		fec_index = 1;
 		break;
 	case VPD_PRODUCT_B650:
-		env_set("confidx", "2");
+		env_set(ctx_uboot, "confidx", "2");
 		i210_index = 0;
 		fec_index = 1;
 		break;
 	case VPD_PRODUCT_B850:
-		env_set("confidx", "3");
+		env_set(ctx_uboot, "confidx", "3");
 		i210_index = 1;
 		fec_index = 2;
 		break;
@@ -647,9 +647,10 @@ int board_late_init(void)
 #endif
 
 	if (is_b850v3())
-		env_set("videoargs", "video=DP-1:1024x768 at 60 video=HDMI-A-1:1024x768 at 60");
+		env_set(ctx_uboot, "videoargs",
+			"video=DP-1:1024x768 at 60 video=HDMI-A-1:1024x768 at 60");
 	else
-		env_set("videoargs", "video=LVDS-1:1024x768 at 65");
+		env_set(ctx_uboot, "videoargs", "video=LVDS-1:1024x768 at 65");
 
 	/* board specific pmic init */
 	pmic_init();
@@ -669,7 +670,7 @@ static void remove_ethaddr_env_var(int index)
 	char env_var_name[9];
 
 	sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index);
-	env_set(env_var_name, NULL);
+	env_set(ctx_uboot, env_var_name, NULL);
 }
 
 int last_stage_init(void)
diff --git a/board/ge/common/ge_common.c b/board/ge/common/ge_common.c
index 501c8b2daf2a..1d5f7ac39350 100644
--- a/board/ge/common/ge_common.c
+++ b/board/ge/common/ge_common.c
@@ -29,7 +29,7 @@ void check_time(void)
 	}
 
 	if (ret < 0)
-		env_set("rtc_status", "RTC_ERROR");
+		env_set(ctx_uboot, "rtc_status", "RTC_ERROR");
 
 	if (tm.tm_year > 2037) {
 		tm.tm_sec  = 0;
@@ -47,7 +47,7 @@ void check_time(void)
 		}
 
 		if (ret < 0)
-			env_set("rtc_status", "RTC_ERROR");
+			env_set(ctx_uboot, "rtc_status", "RTC_ERROR");
 	}
 
 	i2c_set_bus_num(current_i2c_bus);
diff --git a/board/ge/mx53ppd/mx53ppd.c b/board/ge/mx53ppd/mx53ppd.c
index 544856729821..f2a76dc1ded8 100644
--- a/board/ge/mx53ppd/mx53ppd.c
+++ b/board/ge/mx53ppd/mx53ppd.c
@@ -274,7 +274,7 @@ int misc_init_r(void)
 	else
 		cause = "POR";
 
-	env_set("bootcause", cause);
+	env_set(ctx_uboot, "bootcause", cause);
 
 	return 0;
 }
diff --git a/board/grinn/chiliboard/board.c b/board/grinn/chiliboard/board.c
index c6d53600fa1c..933bdc779601 100644
--- a/board/grinn/chiliboard/board.c
+++ b/board/grinn/chiliboard/board.c
@@ -117,7 +117,7 @@ int board_late_init(void)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
@@ -133,7 +133,7 @@ int board_late_init(void)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
diff --git a/board/grinn/liteboard/board.c b/board/grinn/liteboard/board.c
index 1558ea4b84f5..53eabe2e4b3b 100644
--- a/board/grinn/liteboard/board.c
+++ b/board/grinn/liteboard/board.c
@@ -127,7 +127,7 @@ int board_mmc_init(bd_t *bis)
 
 static int check_mmc_autodetect(void)
 {
-	char *autodetect_str = env_get("mmcautodetect");
+	char *autodetect_str = env_get(ctx_uboot, "mmcautodetect");
 
 	if ((autodetect_str != NULL) &&
 	    (strcmp(autodetect_str, "yes") == 0)) {
@@ -146,12 +146,12 @@ void board_late_mmc_init(void)
 	if (!check_mmc_autodetect())
 		return;
 
-	env_set_ulong("mmcdev", dev_no);
+	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
 
 	/* Set mmcblk env */
 	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
 		dev_no);
-	env_set("mmcroot", mmcblk);
+	env_set(ctx_uboot, "mmcroot", mmcblk);
 
 	sprintf(cmd, "mmc dev %d", dev_no);
 	run_command(cmd, 0);
diff --git a/board/highbank/highbank.c b/board/highbank/highbank.c
index 9563763dfa53..ef2f6f1f16a8 100644
--- a/board/highbank/highbank.c
+++ b/board/highbank/highbank.c
@@ -80,11 +80,12 @@ int misc_init_r(void)
 
 	boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
 	sprintf(envbuffer, "bootcmd%d", boot_choice);
-	if (env_get(envbuffer)) {
+	if (env_get(ctx_uboot, envbuffer)) {
 		sprintf(envbuffer, "run bootcmd%d", boot_choice);
-		env_set("bootcmd", envbuffer);
-	} else
-		env_set("bootcmd", "");
+		env_set(ctx_uboot, "bootcmd", envbuffer);
+	} else {
+		env_set(ctx_uboot, "bootcmd", "");
+	}
 
 	return 0;
 }
diff --git a/board/hisilicon/poplar/poplar.c b/board/hisilicon/poplar/poplar.c
index 4926419a905a..1177e91a688a 100644
--- a/board/hisilicon/poplar/poplar.c
+++ b/board/hisilicon/poplar/poplar.c
@@ -177,7 +177,7 @@ int board_usb_init(int index, enum usb_init_type init)
 
 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
 {
-	if (!env_get("serial#"))
+	if (!env_get(ctx_uboot, "serial#"))
 		g_dnl_set_serialnumber("0123456789POPLAR");
 	return 0;
 }
diff --git a/board/imgtec/ci20/ci20.c b/board/imgtec/ci20/ci20.c
index 5368b67b38b6..a34553a7bb3b 100644
--- a/board/imgtec/ci20/ci20.c
+++ b/board/imgtec/ci20/ci20.c
@@ -181,12 +181,12 @@ int misc_init_r(void)
 	eth_env_set_enetaddr("ethaddr", otp.mac);
 
 	/* Put other board information into the environment */
-	env_set_ulong("serial#", otp.serial_number);
-	env_set_ulong("board_date", otp.date);
+	env_set_ulong(ctx_uboot, "serial#", otp.serial_number);
+	env_set_ulong(ctx_uboot, "board_date", otp.date);
 	manufacturer[0] = otp.manufacturer[0];
 	manufacturer[1] = otp.manufacturer[1];
 	manufacturer[2] = 0;
-	env_set("board_mfr", manufacturer);
+	env_set(ctx_uboot, "board_mfr", manufacturer);
 
 	return 0;
 }
diff --git a/board/intel/edison/edison.c b/board/intel/edison/edison.c
index f56b5b1affef..2de8a4936286 100644
--- a/board/intel/edison/edison.c
+++ b/board/intel/edison/edison.c
@@ -71,14 +71,14 @@ static void assign_serial(void)
 
 	snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
 		 ssn[13], ssn[14], ssn[15]);
-	env_set("usb0addr", usb0addr);
+	env_set(ctx_uboot, "usb0addr", usb0addr);
 
 	for (i = 0; i < 16; i++)
 		snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
-	env_set("serial#", serial);
+	env_set(ctx_uboot, "serial#", serial);
 
 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-	env_save();
+	env_save(ctx_uboot);
 #endif
 }
 
@@ -93,19 +93,19 @@ static void assign_hardware_id(void)
 		printf("Can't retrieve hardware revision\n");
 
 	snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
-	env_set("hardware_id", hardware_id);
+	env_set(ctx_uboot, "hardware_id", hardware_id);
 
 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-	env_save();
+	env_save(ctx_uboot);
 #endif
 }
 
 int board_late_init(void)
 {
-	if (!env_get("serial#"))
+	if (!env_get(ctx_uboot, "serial#"))
 		assign_serial();
 
-	if (!env_get("hardware_id"))
+	if (!env_get(ctx_uboot, "hardware_id"))
 		assign_hardware_id();
 
 	return 0;
diff --git a/board/isee/igep003x/board.c b/board/isee/igep003x/board.c
index a8c2b121a476..56ecf3497245 100644
--- a/board/isee/igep003x/board.c
+++ b/board/isee/igep003x/board.c
@@ -193,13 +193,13 @@ int board_late_init(void)
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	switch (get_board_revision()) {
 		case 0:
-			env_set("board_name", "igep0034-lite");
+			env_set(ctx_uboot, "board_name", "igep0034-lite");
 			break;
 		case 1:
-			env_set("board_name", "igep0034");
+			env_set(ctx_uboot, "board_name", "igep0034");
 			break;
 		default:
-			env_set("board_name", "igep0033");
+			env_set(ctx_uboot, "board_name", "igep0033");
 			break;
 	}
 #endif
diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
index 74fc5f08900a..42476b2b657b 100644
--- a/board/isee/igep00x0/igep00x0.c
+++ b/board/isee/igep00x0/igep00x0.c
@@ -199,8 +199,8 @@ void set_boardname(void)
 	int i = get_board_revision();
 
 	rev[i+1] = 0;
-	env_set("board_rev", rev + i);
-	env_set("board_name", i < 2 ? "igep0020" : "igep0030");
+	env_set(ctx_uboot, "board_rev", rev + i);
+	env_set(ctx_uboot, "board_name", i < 2 ? "igep0020" : "igep0030");
 }
 
 /*
diff --git a/board/k+p/kp_imx53/kp_id_rev.c b/board/k+p/kp_imx53/kp_id_rev.c
index 9dae54dda5fc..5c9258912c89 100644
--- a/board/k+p/kp_imx53/kp_id_rev.c
+++ b/board/k+p/kp_imx53/kp_id_rev.c
@@ -31,7 +31,7 @@ void show_eeprom(void)
 
 	if (!strncmp(safe_string, "TQM", 3)) {
 		printf("  ID: %s\n", safe_string);
-		env_set("boardtype", safe_string);
+		env_set(ctx_uboot, "boardtype", safe_string);
 	} else {
 		puts("  unknown hardware variant\n");
 	}
@@ -45,7 +45,7 @@ void show_eeprom(void)
 
 	if (strlen(safe_string) == 8) {
 		printf("  SN: %s\n", safe_string);
-		env_set("serial#", safe_string);
+		env_set(ctx_uboot, "serial#", safe_string);
 	} else {
 		puts("  unknown serial number\n");
 	}
@@ -103,18 +103,18 @@ int read_board_id(void)
 	sprintf(rev_str, "%02X", rev_id);
 	if (rev_id & 0x80) {
 		printf("BBoard:4x00 Rev:%s\n", rev_str);
-		env_set("boardtype", "ddc");
-		env_set("fit_config", "imx53_kb_conf");
+		env_set(ctx_uboot, "boardtype", "ddc");
+		env_set(ctx_uboot, "fit_config", "imx53_kb_conf");
 	} else {
 		printf("BBoard:40x0 Rev:%s\n", rev_str);
-		env_set("boardtype", "hsc");
-		env_set("fit_config", "imx53_kb_40x0_conf");
+		env_set(ctx_uboot, "boardtype", "hsc");
+		env_set(ctx_uboot, "fit_config", "imx53_kb_40x0_conf");
 	}
 
-	sprintf(buf, "kp-%s", env_get("boardtype"));
-	env_set("boardname", buf);
-	env_set("boardsoc", "imx53");
-	env_set("kb53_rev", rev_str);
+	sprintf(buf, "kp-%s", env_get(ctx_uboot, "boardtype"));
+	env_set(ctx_uboot, "boardname", buf);
+	env_set(ctx_uboot, "boardsoc", "imx53");
+	env_set(ctx_uboot, "kb53_rev", rev_str);
 
 	return 0;
 }
diff --git a/board/k+p/kp_imx53/kp_imx53.c b/board/k+p/kp_imx53/kp_imx53.c
index 84cddd489490..36b9b9377f03 100644
--- a/board/k+p/kp_imx53/kp_imx53.c
+++ b/board/k+p/kp_imx53/kp_imx53.c
@@ -124,9 +124,9 @@ void board_misc_setup(void)
 	gpio_direction_input(KEY1);
 
 	if (gpio_get_value(KEY1))
-		env_set("key1", "off");
+		env_set(ctx_uboot, "key1", "off");
 	else
-		env_set("key1", "on");
+		env_set(ctx_uboot, "key1", "on");
 }
 
 int board_late_init(void)
diff --git a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c
index 2c541ace0210..9536ae2171d2 100644
--- a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c
+++ b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c
@@ -290,8 +290,8 @@ int board_late_init(void)
 	add_board_boot_modes(board_boot_modes);
 #endif
 
-	env_set("boardname", "kp-tpc");
-	env_set("boardsoc", "imx6q");
+	env_set(ctx_uboot, "boardname", "kp-tpc");
+	env_set(ctx_uboot, "boardsoc", "imx6q");
 	return 0;
 }
 
diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 08f7f8d88451..3e15a063b34a 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -51,24 +51,24 @@ int set_km_env(void)
 	pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
 			- CONFIG_KM_PNVRAM;
 	sprintf((char *)buf, "0x%x", pnvramaddr);
-	env_set("pnvramaddr", (char *)buf);
+	env_set(ctx_uboot, "pnvramaddr", (char *)buf);
 
 	/* try to read rootfssize (ram image) from environment */
-	p = env_get("rootfssize");
+	p = env_get(ctx_uboot, "rootfssize");
 	if (p != NULL)
 		strict_strtoul(p, 16, &rootfssize);
 	pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
 		CONFIG_KM_PNVRAM) / 0x400;
 	sprintf((char *)buf, "0x%x", pram);
-	env_set("pram", (char *)buf);
+	env_set(ctx_uboot, "pram", (char *)buf);
 
 	varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
 	sprintf((char *)buf, "0x%x", varaddr);
-	env_set("varaddr", (char *)buf);
+	env_set(ctx_uboot, "varaddr", (char *)buf);
 
 	kernelmem = gd->ram_size - 0x400 * pram;
 	sprintf((char *)buf, "0x%x", kernelmem);
-	env_set("kernelmem", (char *)buf);
+	env_set(ctx_uboot, "kernelmem", (char *)buf);
 
 	return 0;
 }
@@ -169,7 +169,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
 		return 1;
 	}
 	strcpy((char *)buf, p);
-	env_set("boardid", (char *)buf);
+	env_set(ctx_uboot, "boardid", (char *)buf);
 	printf("set boardid=%s\n", buf);
 
 	p = get_local_var("IVM_HWKey");
@@ -178,7 +178,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
 		return 1;
 	}
 	strcpy((char *)buf, p);
-	env_set("hwkey", (char *)buf);
+	env_set(ctx_uboot, "hwkey", (char *)buf);
 	printf("set hwkey=%s\n", buf);
 	printf("Execute manually saveenv for persistent storage.\n");
 
@@ -236,10 +236,10 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
 	}
 
 	/* now try to read values from environment if available */
-	p = env_get("boardid");
+	p = env_get(ctx_uboot, "boardid");
 	if (p != NULL)
 		rc = strict_strtoul(p, 16, &envbid);
-	p = env_get("hwkey");
+	p = env_get(ctx_uboot, "hwkey");
 	if (p != NULL)
 		rc = strict_strtoul(p, 16, &envhwkey);
 
@@ -253,7 +253,7 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
 		 * BoardId/HWkey not available in the environment, so try the
 		 * environment variable for BoardId/HWkey list
 		 */
-		char *bidhwklist = env_get("boardIdListHex");
+		char *bidhwklist = env_get(ctx_uboot, "boardIdListHex");
 
 		if (bidhwklist) {
 			int found = 0;
@@ -311,9 +311,9 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
 					envbid   = bid;
 					envhwkey = hwkey;
 					sprintf(buf, "%lx", bid);
-					env_set("boardid", buf);
+					env_set(ctx_uboot, "boardid", buf);
 					sprintf(buf, "%lx", hwkey);
-					env_set("hwkey", buf);
+					env_set(ctx_uboot, "hwkey", buf);
 				}
 			} /* end while( ! found ) */
 		}
@@ -355,7 +355,7 @@ static int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc,
 #if defined(CONFIG_POST)
 	testpin = post_hotkeys_pressed();
 #endif
-	s = env_get("test_bank");
+	s = env_get(ctx_uboot, "test_bank");
 	/* when test_bank is not set, act as if testpin is not asserted */
 	testboot = (testpin != 0) && (s);
 	if (verbose) {
diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c
index 50df44d1c110..d255a34ae677 100644
--- a/board/keymile/common/ivm.c
+++ b/board/keymile/common/ivm.c
@@ -261,7 +261,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int len)
 
 	GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8)
 	GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64)
-	tmp = (unsigned char *)env_get("IVM_DeviceName");
+	tmp = (unsigned char *)env_get(ctx_uboot, "IVM_DeviceName");
 	if (tmp) {
 		int	len = strlen((char *)tmp);
 		int	i = 0;
@@ -310,16 +310,16 @@ static int ivm_populate_env(unsigned char *buf, int len)
 #ifndef CONFIG_KMTEGR1
 	/* if an offset is defined, add it */
 	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, true);
-	env_set((char *)"ethaddr", (char *)valbuf);
+	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
 #else
 /* KMTEGR1 has a special setup. eth0 has no connection to the outside and
  * gets an locally administred MAC address, eth1 is the debug interface and
  * gets the official MAC address from the IVM
  */
 	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, false);
-	env_set((char *)"ethaddr", (char *)valbuf);
+	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
 	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, true);
-	env_set((char *)"eth1addr", (char *)valbuf);
+	env_set(ctx_uboot, (char *)"eth1addr", (char *)valbuf);
 #endif
 
 	return 0;
diff --git a/board/keymile/km83xx/km83xx.c b/board/keymile/km83xx/km83xx.c
index 8846b64f7d79..68a1ddb886b9 100644
--- a/board/keymile/km83xx/km83xx.c
+++ b/board/keymile/km83xx/km83xx.c
@@ -199,7 +199,7 @@ int last_stage_init(void)
 	if (dip_switch != 0) {
 		/* start bootloader */
 		puts("DIP:   Enabled\n");
-		env_set("actual_bank", "0");
+		env_set(ctx_uboot, "actual_bank", "0");
 	}
 #endif
 	set_km_env();
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c
index 922cc621f780..0c2ede5231bb 100644
--- a/board/keymile/km_arm/km_arm.c
+++ b/board/keymile/km_arm/km_arm.c
@@ -193,7 +193,7 @@ static void set_bootcount_addr(void)
 	unsigned int bootcountaddr;
 	bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
 	sprintf((char *)buf, "0x%x", bootcountaddr);
-	env_set("bootcountaddr", (char *)buf);
+	env_set(ctx_uboot, "bootcountaddr", (char *)buf);
 }
 
 int misc_init_r(void)
@@ -201,7 +201,7 @@ int misc_init_r(void)
 #if defined(CONFIG_KM_MGCOGE3UN)
 	char *wait_for_ne;
 	u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
-	wait_for_ne = env_get("waitforne");
+	wait_for_ne = env_get(ctx_uboot, "waitforne");
 
 	if ((wait_for_ne != NULL) && (dip_switch == 0)) {
 		if (strcmp(wait_for_ne, "true") == 0) {
@@ -299,7 +299,7 @@ int board_late_init(void)
 	if (dip_switch != 0) {
 		/* start bootloader */
 		puts("DIP:   Enabled\n");
-		env_set("actual_bank", "0");
+		env_set(ctx_uboot, "actual_bank", "0");
 	}
 #endif
 
diff --git a/board/keymile/kmp204x/kmp204x.c b/board/keymile/kmp204x/kmp204x.c
index 4d1e38aa3a7a..f4901f6bed9d 100644
--- a/board/keymile/kmp204x/kmp204x.c
+++ b/board/keymile/kmp204x/kmp204x.c
@@ -220,7 +220,7 @@ int last_stage_init(void)
 	if (dip_switch != 0) {
 		/* start bootloader */
 		puts("DIP:   Enabled\n");
-		env_set("actual_bank", "0");
+		env_set(ctx_uboot, "actual_bank", "0");
 	}
 #endif
 	set_km_env();
@@ -237,7 +237,7 @@ void fdt_fixup_fman_mac_addresses(void *blob)
 	unsigned char mac_addr[6];
 
 	/* get the mac addr from env */
-	tmp = env_get("ethaddr");
+	tmp = env_get(ctx_uboot, "ethaddr");
 	if (!tmp) {
 		printf("ethaddr env variable not defined\n");
 		return;
diff --git a/board/kosagi/novena/novena.c b/board/kosagi/novena/novena.c
index b7b747d19658..968d455b45c6 100644
--- a/board/kosagi/novena/novena.c
+++ b/board/kosagi/novena/novena.c
@@ -201,7 +201,7 @@ int misc_init_r(void)
 	int ret;
 
 	/* If 'ethaddr' is already set, do nothing. */
-	if (env_get("ethaddr"))
+	if (env_get(ctx_uboot, "ethaddr"))
 		return 0;
 
 	/* EEPROM is at bus 2. */
diff --git a/board/laird/wb50n/wb50n.c b/board/laird/wb50n/wb50n.c
index a2f8eaf0ba34..cc7cd3cf7250 100644
--- a/board/laird/wb50n/wb50n.c
+++ b/board/laird/wb50n/wb50n.c
@@ -122,7 +122,7 @@ int board_late_init(void)
 	for (p = name; *p != '\0'; *p = tolower(*p), p++)
 		;
 	strcat(name, "-wb50n");
-	env_set(LAIRD_NAME, name);
+	env_set(ctx_uboot, LAIRD_NAME, name);
 
 #endif
 
diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c
index b4205d6ed4c1..0dff96ef02aa 100644
--- a/board/lg/sniper/sniper.c
+++ b/board/lg/sniper/sniper.c
@@ -133,8 +133,8 @@ int misc_init_r(void)
 	}
 
 	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
-		if (!env_get("reboot-mode"))
-			env_set("reboot-mode", (char *)reboot_mode);
+		if (!env_get(ctx_uboot, "reboot-mode"))
+			env_set(ctx_uboot, "reboot-mode", (char *)reboot_mode);
 	}
 
 	omap_reboot_mode_clear();
diff --git a/board/liebherr/display5/spl.c b/board/liebherr/display5/spl.c
index 354b63e431f6..6ce1554e044d 100644
--- a/board/liebherr/display5/spl.c
+++ b/board/liebherr/display5/spl.c
@@ -284,10 +284,10 @@ void board_boot_order(u32 *spl_boot_list)
 	/* 'fastboot' */
 	const char *s;
 
-	if (env_init() || env_load())
+	if (env_init() || env_load(ctx_uboot))
 		return;
 
-	s = env_get("BOOT_FROM");
+	s = env_get(ctx_uboot, "BOOT_FROM");
 	if (s && !bootcount_error() && strcmp(s, "ACTIVE") == 0) {
 		spl_boot_list[0] = BOOT_DEVICE_MMC1;
 		spl_boot_list[1] = spl_boot_device();
diff --git a/board/liebherr/mccmon6/mccmon6.c b/board/liebherr/mccmon6/mccmon6.c
index 7d2751ab0393..6164317e607c 100644
--- a/board/liebherr/mccmon6/mccmon6.c
+++ b/board/liebherr/mccmon6/mccmon6.c
@@ -367,7 +367,7 @@ int board_init(void)
 
 int board_late_init(void)
 {
-	env_set("board_name", "mccmon6");
+	env_set(ctx_uboot, "board_name", "mccmon6");
 
 	return 0;
 }
@@ -467,7 +467,7 @@ int spl_start_uboot(void)
 		return 1;
 
 	env_init();
-	ret = env_get_f("boot_os", s, sizeof(s));
+	ret = env_get_f("boot_os", s, sizeof(ctx_uboot, s));
 	if ((ret != -1) && (strcmp(s, "no") == 0))
 		return 1;
 
@@ -481,7 +481,7 @@ int spl_start_uboot(void)
 	 * recovery_status = <any value> -> start SWUpdate
 	 *
 	 */
-	ret = env_get_f("recovery_status", s, sizeof(s));
+	ret = env_get_f("recovery_status", s, sizeof(ctx_uboot, s));
 	if (ret != -1)
 		return 1;
 
diff --git a/board/logicpd/imx6/imx6logic.c b/board/logicpd/imx6/imx6logic.c
index 7a59b89d94a2..204a92761459 100644
--- a/board/logicpd/imx6/imx6logic.c
+++ b/board/logicpd/imx6/imx6logic.c
@@ -149,12 +149,12 @@ int board_init(void)
 
 int board_late_init(void)
 {
-	env_set("board_name", "imx6logic");
+	env_set(ctx_uboot, "board_name", "imx6logic");
 
 	if (is_mx6dq()) {
-		env_set("board_rev", "MX6DQ");
-		if (!env_get("fdt_file"))
-			env_set("fdt_file", "imx6q-logicpd.dtb");
+		env_set(ctx_uboot, "board_rev", "MX6DQ");
+		if (!env_get(ctx_uboot, "fdt_file"))
+			env_set(ctx_uboot, "fdt_file", "imx6q-logicpd.dtb");
 	}
 
 	return 0;
diff --git a/board/menlo/m53menlo/m53menlo.c b/board/menlo/m53menlo/m53menlo.c
index bda5f0df5bce..f84e0f7d5928 100644
--- a/board/menlo/m53menlo/m53menlo.c
+++ b/board/menlo/m53menlo/m53menlo.c
@@ -339,7 +339,7 @@ int board_late_init(void)
 
 	splash_get_pos(&xpos, &ypos);
 
-	s = env_get("splashimage");
+	s = env_get(ctx_uboot, "splashimage");
 	if (!s)
 		return 0;
 
diff --git a/board/micronas/vct/vct.c b/board/micronas/vct/vct.c
index e73d16db3eaf..6ae3dceaef87 100644
--- a/board/micronas/vct/vct.c
+++ b/board/micronas/vct/vct.c
@@ -72,7 +72,7 @@ int dram_init(void)
 int checkboard(void)
 {
 	char buf[64];
-	int i = env_get_f("serial#", buf, sizeof(buf));
+	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
 	u32 config0 = read_c0_prid();
 
 	if ((config0 & 0xff0000) == PRID_COMP_LEGACY
diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
index 71ca79deab7f..ca486eab1e29 100644
--- a/board/nokia/rx51/rx51.c
+++ b/board/nokia/rx51/rx51.c
@@ -234,18 +234,18 @@ void setup_board_tags(struct tag **in_params)
 	params->u.core.rootdev = 0x0;
 
 	/* append omap atag only if env setup_omap_atag is set to 1 */
-	str = env_get("setup_omap_atag");
+	str = env_get(ctx_uboot, "setup_omap_atag");
 	if (!str || str[0] != '1')
 		return;
 
-	str = env_get("setup_console_atag");
+	str = env_get(ctx_uboot, "setup_console_atag");
 	if (str && str[0] == '1')
 		setup_console_atag = 1;
 	else
 		setup_console_atag = 0;
 
-	setup_boot_reason_atag = env_get("setup_boot_reason_atag");
-	setup_boot_mode_atag = env_get("setup_boot_mode_atag");
+	setup_boot_reason_atag = env_get(ctx_uboot, "setup_boot_reason_atag");
+	setup_boot_mode_atag = env_get(ctx_uboot, "setup_boot_mode_atag");
 
 	params = *in_params;
 	t = (struct tag_omap *)&params->u;
@@ -413,7 +413,7 @@ int misc_init_r(void)
 
 	/* set env variable attkernaddr for relocated kernel */
 	sprintf(buf, "%#x", KERNEL_ADDRESS);
-	env_set("attkernaddr", buf);
+	env_set(ctx_uboot, "attkernaddr", buf);
 
 	/* initialize omap tags */
 	init_omap_tags();
diff --git a/board/overo/overo.c b/board/overo/overo.c
index 442028a764c7..f0b230eabb13 100644
--- a/board/overo/overo.c
+++ b/board/overo/overo.c
@@ -170,47 +170,47 @@ int misc_init_r(void)
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "dvi");
-		env_set("expansionname", "summit");
+		env_set(ctx_uboot, "defaultdisplay", "dvi");
+		env_set(ctx_uboot, "expansionname", "summit");
 		break;
 	case GUMSTIX_TOBI:
 		printf("Recognized Tobi expansion board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "dvi");
-		env_set("expansionname", "tobi");
+		env_set(ctx_uboot, "defaultdisplay", "dvi");
+		env_set(ctx_uboot, "expansionname", "tobi");
 		break;
 	case GUMSTIX_TOBI_DUO:
 		printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("expansionname", "tobiduo");
+		env_set(ctx_uboot, "expansionname", "tobiduo");
 		break;
 	case GUMSTIX_PALO35:
 		printf("Recognized Palo35 expansion board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "lcd35");
-		env_set("expansionname", "palo35");
+		env_set(ctx_uboot, "defaultdisplay", "lcd35");
+		env_set(ctx_uboot, "expansionname", "palo35");
 		break;
 	case GUMSTIX_PALO43:
 		printf("Recognized Palo43 expansion board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "lcd43");
-		env_set("expansionname", "palo43");
+		env_set(ctx_uboot, "defaultdisplay", "lcd43");
+		env_set(ctx_uboot, "expansionname", "palo43");
 		break;
 	case GUMSTIX_CHESTNUT43:
 		printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "lcd43");
-		env_set("expansionname", "chestnut43");
+		env_set(ctx_uboot, "defaultdisplay", "lcd43");
+		env_set(ctx_uboot, "expansionname", "chestnut43");
 		break;
 	case GUMSTIX_PINTO:
 		printf("Recognized Pinto expansion board (rev %d %s)\n",
@@ -223,8 +223,8 @@ int misc_init_r(void)
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
-		env_set("defaultdisplay", "lcd43");
-		env_set("expansionname", "gallop43");
+		env_set(ctx_uboot, "defaultdisplay", "lcd43");
+		env_set(ctx_uboot, "expansionname", "gallop43");
 		break;
 	case GUMSTIX_ALTO35:
 		printf("Recognized Alto35 expansion board (rev %d %s)\n",
@@ -232,8 +232,8 @@ int misc_init_r(void)
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
 		MUX_ALTO35();
-		env_set("defaultdisplay", "lcd35");
-		env_set("expansionname", "alto35");
+		env_set(ctx_uboot, "defaultdisplay", "lcd35");
+		env_set(ctx_uboot, "expansionname", "alto35");
 		break;
 	case GUMSTIX_STAGECOACH:
 		printf("Recognized Stagecoach expansion board (rev %d %s)\n",
@@ -259,8 +259,8 @@ int misc_init_r(void)
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
 		MUX_ARBOR43C();
-		env_set("defaultdisplay", "lcd43");
-		env_set("expansionname", "arbor43c");
+		env_set(ctx_uboot, "defaultdisplay", "lcd43");
+		env_set(ctx_uboot, "expansionname", "arbor43c");
 		break;
 	case ETTUS_USRP_E:
 		printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
@@ -268,13 +268,13 @@ int misc_init_r(void)
 			expansion_config.fab_revision);
 		MUX_GUMSTIX();
 		MUX_USRP_E();
-		env_set("defaultdisplay", "dvi");
+		env_set(ctx_uboot, "defaultdisplay", "dvi");
 		break;
 	case GUMSTIX_NO_EEPROM:
 	case GUMSTIX_EMPTY_EEPROM:
 		puts("No or empty EEPROM on expansion board\n");
 		MUX_GUMSTIX();
-		env_set("expansionname", "tobi");
+		env_set(ctx_uboot, "expansionname", "tobi");
 		break;
 	default:
 		printf("Unrecognized expansion board 0x%08x\n", expansion_id);
@@ -282,14 +282,15 @@ int misc_init_r(void)
 	}
 
 	if (expansion_config.content == 1)
-		env_set(expansion_config.env_var, expansion_config.env_setting);
+		env_set(ctx_uboot, expansion_config.env_var,
+			expansion_config.env_setting);
 
 	omap_die_id_display();
 
 	if (get_cpu_family() == CPU_OMAP34XX)
-		env_set("boardname", "overo");
+		env_set(ctx_uboot, "boardname", "overo");
 	else
-		env_set("boardname", "overo-storm");
+		env_set(ctx_uboot, "boardname", "overo-storm");
 
 	return 0;
 }
diff --git a/board/phytec/pcm052/pcm052.c b/board/phytec/pcm052/pcm052.c
index e1ebe8e75d00..f66bacfb2172 100644
--- a/board/phytec/pcm052/pcm052.c
+++ b/board/phytec/pcm052/pcm052.c
@@ -376,8 +376,8 @@ int board_late_init(void)
 	if ((reg & SRC_SBMR1_BOOTCFG1_SDMMC) &&
 	    !(reg & SRC_SBMR1_BOOTCFG1_MMC)) {
 		printf("------ SD card boot -------\n");
-		env_set_default("!LVFBootloader", 0);
-		env_set("bootcmd",
+		env_set_default(ctx_uboot, "!LVFBootloader", 0);
+		env_set(ctx_uboot, "bootcmd",
 			"run prepare_install_bk4r1_envs; run install_bk4r1rs");
 	}
 
diff --git a/board/phytec/pfla02/pfla02.c b/board/phytec/pfla02/pfla02.c
index ae9ffe0390c3..bbcd8cf934d3 100644
--- a/board/phytec/pfla02/pfla02.c
+++ b/board/phytec/pfla02/pfla02.c
@@ -392,7 +392,7 @@ int board_late_init(void)
 #endif
 
 	snprintf(buf, sizeof(buf), "%d", get_board_rev());
-	env_set("board_rev", buf);
+	env_set(ctx_uboot, "board_rev", buf);
 
 	return 0;
 }
diff --git a/board/qualcomm/dragonboard410c/dragonboard410c.c b/board/qualcomm/dragonboard410c/dragonboard410c.c
index d7f0f93fb109..bdf6e13ad06f 100644
--- a/board/qualcomm/dragonboard410c/dragonboard410c.c
+++ b/board/qualcomm/dragonboard410c/dragonboard410c.c
@@ -139,8 +139,8 @@ int misc_init_r(void)
 	}
 
 	if (dm_gpio_get_value(&resin)) {
-		env_set("bootdelay", "-1");
-		env_set("bootcmd", "fastboot 0");
+		env_set(ctx_uboot, "bootdelay", "-1");
+		env_set(ctx_uboot, "bootcmd", "fastboot 0");
 		printf("key_vol_down pressed - Starting fastboot.\n");
 	}
 
@@ -158,7 +158,7 @@ int board_late_init(void)
 
 	memset(serial, 0, 16);
 	snprintf(serial, 13, "%x", msm_board_serial());
-	env_set("serial#", serial);
+	env_set(ctx_uboot, "serial#", serial);
 	return 0;
 }
 
diff --git a/board/qualcomm/dragonboard820c/dragonboard820c.c b/board/qualcomm/dragonboard820c/dragonboard820c.c
index 7a889646df8d..475e1aa64560 100644
--- a/board/qualcomm/dragonboard820c/dragonboard820c.c
+++ b/board/qualcomm/dragonboard820c/dragonboard820c.c
@@ -155,7 +155,7 @@ int misc_init_r(void)
 	}
 
 	if (dm_gpio_get_value(&resin)) {
-		env_set("bootdelay", "-1");
+		env_set(ctx_uboot, "bootdelay", "-1");
 		printf("Power button pressed - dropping to console.\n");
 	}
 
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 7a6ca8f759e6..5d4d59fd25ca 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -290,11 +290,11 @@ static void set_fdtfile(void)
 {
 	const char *fdtfile;
 
-	if (env_get("fdtfile"))
+	if (env_get(ctx_uboot, "fdtfile"))
 		return;
 
 	fdtfile = model->fdtfile;
-	env_set("fdtfile", fdtfile);
+	env_set(ctx_uboot, "fdtfile", fdtfile);
 }
 
 /*
@@ -303,13 +303,13 @@ static void set_fdtfile(void)
  */
 static void set_fdt_addr(void)
 {
-	if (env_get("fdt_addr"))
+	if (env_get(ctx_uboot, "fdt_addr"))
 		return;
 
 	if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
 		return;
 
-	env_set_hex("fdt_addr", fw_dtb_pointer);
+	env_set_hex(ctx_uboot, "fdt_addr", fw_dtb_pointer);
 }
 
 /*
@@ -330,7 +330,7 @@ static void set_usbethaddr(void)
 	if (!model->has_onboard_eth)
 		return;
 
-	if (env_get("usbethaddr"))
+	if (env_get(ctx_uboot, "usbethaddr"))
 		return;
 
 	BCM2835_MBOX_INIT_HDR(msg);
@@ -345,8 +345,8 @@ static void set_usbethaddr(void)
 
 	eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
 
-	if (!env_get("ethaddr"))
-		env_set("ethaddr", env_get("usbethaddr"));
+	if (!env_get(ctx_uboot, "ethaddr"))
+		env_set(ctx_uboot, "ethaddr", env_get("usbethaddr"));
 
 	return;
 }
@@ -357,13 +357,13 @@ static void set_board_info(void)
 	char s[11];
 
 	snprintf(s, sizeof(s), "0x%X", revision);
-	env_set("board_revision", s);
+	env_set(ctx_uboot, "board_revision", s);
 	snprintf(s, sizeof(s), "%d", rev_scheme);
-	env_set("board_rev_scheme", s);
+	env_set(ctx_uboot, "board_rev_scheme", s);
 	/* Can't rename this to board_rev_type since it's an ABI for scripts */
 	snprintf(s, sizeof(s), "0x%X", rev_type);
-	env_set("board_rev", s);
-	env_set("board_name", model->name);
+	env_set(ctx_uboot, "board_rev", s);
+	env_set(ctx_uboot, "board_name", model->name);
 }
 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
 
@@ -373,7 +373,7 @@ static void set_serial_number(void)
 	int ret;
 	char serial_string[17] = { 0 };
 
-	if (env_get("serial#"))
+	if (env_get(ctx_uboot, "serial#"))
 		return;
 
 	BCM2835_MBOX_INIT_HDR(msg);
@@ -388,7 +388,7 @@ static void set_serial_number(void)
 
 	snprintf(serial_string, sizeof(serial_string), "%016llx",
 		 msg->get_board_serial.body.resp.serial);
-	env_set("serial#", serial_string);
+	env_set(ctx_uboot, "serial#", serial_string);
 }
 
 int misc_init_r(void)
diff --git a/board/renesas/alt/alt.c b/board/renesas/alt/alt.c
index 10ef7f931b1f..bc94a22e9603 100644
--- a/board/renesas/alt/alt.c
+++ b/board/renesas/alt/alt.c
@@ -128,7 +128,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/gose/gose.c b/board/renesas/gose/gose.c
index f86c9f1a6350..d3ec352e2a03 100644
--- a/board/renesas/gose/gose.c
+++ b/board/renesas/gose/gose.c
@@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/koelsch/koelsch.c b/board/renesas/koelsch/koelsch.c
index 841d337f4d3c..871308e405d3 100644
--- a/board/renesas/koelsch/koelsch.c
+++ b/board/renesas/koelsch/koelsch.c
@@ -136,7 +136,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/lager/lager.c b/board/renesas/lager/lager.c
index 3cb1a56142a9..6867ae5c4008 100644
--- a/board/renesas/lager/lager.c
+++ b/board/renesas/lager/lager.c
@@ -145,7 +145,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/porter/porter.c b/board/renesas/porter/porter.c
index 86f79da7fdb4..3dc9310e0fc4 100644
--- a/board/renesas/porter/porter.c
+++ b/board/renesas/porter/porter.c
@@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/sh7752evb/sh7752evb.c b/board/renesas/sh7752evb/sh7752evb.c
index d0b850f35d49..540ec9bfd019 100644
--- a/board/renesas/sh7752evb/sh7752evb.c
+++ b/board/renesas/sh7752evb/sh7752evb.c
@@ -223,10 +223,10 @@ static void init_ethernet_mac(void)
 	for (i = 0; i < SH7752EVB_ETHERNET_NUM_CH; i++) {
 		get_sh_eth_mac(i, mac_string, buf);
 		if (i == 0)
-			env_set("ethaddr", mac_string);
+			env_set(ctx_uboot, "ethaddr", mac_string);
 		else {
 			sprintf(env_string, "eth%daddr", i);
-			env_set(env_string, mac_string);
+			env_set(ctx_uboot, env_string, mac_string);
 		}
 		set_mac_to_sh_giga_eth_register(i, mac_string);
 	}
diff --git a/board/renesas/sh7753evb/sh7753evb.c b/board/renesas/sh7753evb/sh7753evb.c
index e1bed7dcc371..3ec2591cb7ed 100644
--- a/board/renesas/sh7753evb/sh7753evb.c
+++ b/board/renesas/sh7753evb/sh7753evb.c
@@ -239,10 +239,10 @@ static void init_ethernet_mac(void)
 	for (i = 0; i < SH7753EVB_ETHERNET_NUM_CH; i++) {
 		get_sh_eth_mac(i, mac_string, buf);
 		if (i == 0)
-			env_set("ethaddr", mac_string);
+			env_set(ctx_uboot, "ethaddr", mac_string);
 		else {
 			sprintf(env_string, "eth%daddr", i);
-			env_set(env_string, mac_string);
+			env_set(ctx_uboot, env_string, mac_string);
 		}
 		set_mac_to_sh_giga_eth_register(i, mac_string);
 	}
diff --git a/board/renesas/sh7757lcr/sh7757lcr.c b/board/renesas/sh7757lcr/sh7757lcr.c
index d2671202e981..4b06387d5f22 100644
--- a/board/renesas/sh7757lcr/sh7757lcr.c
+++ b/board/renesas/sh7757lcr/sh7757lcr.c
@@ -285,10 +285,10 @@ static void init_ethernet_mac(void)
 	for (i = 0; i < SH7757LCR_ETHERNET_NUM_CH; i++) {
 		get_sh_eth_mac(i, mac_string, buf);
 		if (i == 0)
-			env_set("ethaddr", mac_string);
+			env_set(ctx_uboot, "ethaddr", mac_string);
 		else {
 			sprintf(env_string, "eth%daddr", i);
-			env_set(env_string, mac_string);
+			env_set(ctx_uboot, env_string, mac_string);
 		}
 
 		set_mac_to_sh_eth_register(i, mac_string);
@@ -298,7 +298,7 @@ static void init_ethernet_mac(void)
 	for (i = 0; i < SH7757LCR_GIGA_ETHERNET_NUM_CH; i++) {
 		get_sh_eth_mac(i + SH7757LCR_ETHERNET_NUM_CH, mac_string, buf);
 		sprintf(env_string, "eth%daddr", i + SH7757LCR_ETHERNET_NUM_CH);
-		env_set(env_string, mac_string);
+		env_set(ctx_uboot, env_string, mac_string);
 
 		set_mac_to_sh_giga_eth_register(i, mac_string);
 	}
diff --git a/board/renesas/silk/silk.c b/board/renesas/silk/silk.c
index 25221e3c55cc..946232e3ba7b 100644
--- a/board/renesas/silk/silk.c
+++ b/board/renesas/silk/silk.c
@@ -129,7 +129,8 @@ void reset_cpu(ulong addr)
 		hang();
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/renesas/stout/stout.c b/board/renesas/stout/stout.c
index 0a0ff5ff76d2..d0b20f3c5902 100644
--- a/board/renesas/stout/stout.c
+++ b/board/renesas/stout/stout.c
@@ -125,7 +125,8 @@ int board_phy_config(struct phy_device *phydev)
 	return 0;
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	const u32 load_magic = 0xb33fc0de;
 
diff --git a/board/rockchip/kylin_rk3036/kylin_rk3036.c b/board/rockchip/kylin_rk3036/kylin_rk3036.c
index 2faeab9baf51..6481f6c11633 100644
--- a/board/rockchip/kylin_rk3036/kylin_rk3036.c
+++ b/board/rockchip/kylin_rk3036/kylin_rk3036.c
@@ -41,7 +41,7 @@ int rk_board_late_init(void)
 {
 	if (fastboot_key_pressed()) {
 		printf("enter fastboot!\n");
-		env_set("preboot", "setenv preboot; fastboot usb0");
+		env_set(ctx_uboot, "preboot", "setenv preboot; fastboot usb0");
 	}
 
 	return 0;
diff --git a/board/samsung/common/exynos5-dt.c b/board/samsung/common/exynos5-dt.c
index 387d1b91809c..1c44effe7224 100644
--- a/board/samsung/common/exynos5-dt.c
+++ b/board/samsung/common/exynos5-dt.c
@@ -154,7 +154,7 @@ char *get_dfu_alt_system(char *interface, char *devstr)
 	if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
 		return info;
 
-	return env_get("dfu_alt_system");
+	return env_get(ctx_uboot, "dfu_alt_system");
 }
 
 char *get_dfu_alt_boot(char *interface, char *devstr)
diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
index 3ef1e7998013..3086df745fe5 100644
--- a/board/samsung/common/misc.c
+++ b/board/samsung/common/misc.c
@@ -51,7 +51,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
 
 	alt_setting = get_dfu_alt_boot(interface, devstr);
 	if (alt_setting) {
-		env_set("dfu_alt_boot", alt_setting);
+		env_set(ctx_uboot, "dfu_alt_boot", alt_setting);
 		offset = snprintf(buf, buf_size, "%s", alt_setting);
 	}
 
@@ -71,7 +71,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
 		status = "done\n";
 	}
 
-	env_set("dfu_alt_info", alt_info);
+	env_set(ctx_uboot, "dfu_alt_info", alt_info);
 	puts(status);
 }
 #endif
@@ -83,14 +83,14 @@ void set_board_info(void)
 
 	snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
 		 s5p_cpu_rev & 0xf);
-	env_set("soc_rev", info);
+	env_set(ctx_uboot, "soc_rev", info);
 
 	snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
-	env_set("soc_id", info);
+	env_set(ctx_uboot, "soc_id", info);
 
 #ifdef CONFIG_REVISION_TAG
 	snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
-	env_set("board_rev", info);
+	env_set(ctx_uboot, "board_rev", info);
 #endif
 #ifdef CONFIG_OF_LIBFDT
 	const char *bdtype = "";
@@ -102,11 +102,11 @@ void set_board_info(void)
 		bdtype = "";
 
 	sprintf(info, "%s%s", bdname, bdtype);
-	env_set("board_name", info);
+	env_set(ctx_uboot, "board_name", info);
 #endif
 	snprintf(info, ARRAY_SIZE(info),  "%s%x-%s%s.dtb",
 		 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
-	env_set("fdtfile", info);
+	env_set(ctx_uboot, "fdtfile", info);
 #endif
 }
 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
diff --git a/board/samsung/odroid/odroid.c b/board/samsung/odroid/odroid.c
index 9aa97f0f2cad..472dce81f680 100644
--- a/board/samsung/odroid/odroid.c
+++ b/board/samsung/odroid/odroid.c
@@ -74,7 +74,7 @@ const char *get_board_type(void)
 #ifdef CONFIG_SET_DFU_ALT_INFO
 char *get_dfu_alt_system(char *interface, char *devstr)
 {
-	return env_get("dfu_alt_system");
+	return env_get(ctx_uboot, "dfu_alt_system");
 }
 
 char *get_dfu_alt_boot(char *interface, char *devstr)
diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
index ec85f707c19a..d4540a2ac932 100644
--- a/board/samsung/trats/trats.c
+++ b/board/samsung/trats/trats.c
@@ -467,7 +467,7 @@ void exynos_lcd_misc_init(vidinfo_t *vid)
 #endif
 #ifdef CONFIG_S6E8AX0
 	s6e8ax0_init();
-	env_set("lcdinfo", "lcd=s6e8ax0");
+	env_set(ctx_uboot, "lcdinfo", "lcd=s6e8ax0");
 #endif
 }
 #endif
diff --git a/board/samsung/universal_c210/universal.c b/board/samsung/universal_c210/universal.c
index ed9c5b50d927..9fea29e965bd 100644
--- a/board/samsung/universal_c210/universal.c
+++ b/board/samsung/universal_c210/universal.c
@@ -397,6 +397,6 @@ void exynos_lcd_misc_init(vidinfo_t *vid)
 	vid->pclk_name = 1;	/* MPLL */
 	vid->sclk_div = 1;
 
-	env_set("lcdinfo", "lcd=ld9040");
+	env_set(ctx_uboot, "lcdinfo", "lcd=ld9040");
 }
 #endif
diff --git a/board/samtec/vining_fpga/socfpga.c b/board/samtec/vining_fpga/socfpga.c
index 1e095a4e7db0..75ddbcf07fa7 100644
--- a/board/samtec/vining_fpga/socfpga.c
+++ b/board/samtec/vining_fpga/socfpga.c
@@ -62,30 +62,30 @@ int misc_init_r(void)
 	/* Check EEPROM signature. */
 	if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
 		puts("Invalid I2C EEPROM signature.\n");
-		env_set("unit_serial", "invalid");
-		env_set("unit_ident", "VINing-xxxx-STD");
-		env_set("hostname", "vining-invalid");
+		env_set(ctx_uboot, "unit_serial", "invalid");
+		env_set(ctx_uboot, "unit_ident", "VINing-xxxx-STD");
+		env_set(ctx_uboot, "hostname", "vining-invalid");
 		return 0;
 	}
 
 	/* If 'unit_serial' is already set, do nothing. */
-	if (!env_get("unit_serial")) {
+	if (!env_get(ctx_uboot, "unit_serial")) {
 		/* This field is Big Endian ! */
 		serial = (data[0x54] << 24) | (data[0x55] << 16) |
 			 (data[0x56] << 8) | (data[0x57] << 0);
 		memset(str, 0, sizeof(str));
 		sprintf(str, "%07i", serial);
-		env_set("unit_serial", str);
+		env_set(ctx_uboot, "unit_serial", str);
 	}
 
-	if (!env_get("unit_ident")) {
+	if (!env_get(ctx_uboot, "unit_ident")) {
 		memset(str, 0, sizeof(str));
 		memcpy(str, &data[0x2e], 18);
-		env_set("unit_ident", str);
+		env_set(ctx_uboot, "unit_ident", str);
 	}
 
 	/* Set ethernet address from EEPROM. */
-	if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
+	if (!env_get(ctx_uboot, "ethaddr") && is_valid_ethaddr(&data[0x62]))
 		eth_env_set_enetaddr("ethaddr", &data[0x62]);
 
 	return 0;
diff --git a/board/siemens/common/board.c b/board/siemens/common/board.c
index 676935a84321..63dcf2b83132 100644
--- a/board/siemens/common/board.c
+++ b/board/siemens/common/board.c
@@ -121,7 +121,7 @@ unsigned char get_button_state(char * const envname, unsigned char def)
 	char *ptr_env;
 
 	/* If button is not found we take default */
-	ptr_env = env_get(envname);
+	ptr_env = env_get(ctx_uboot, envname);
 	if (NULL == ptr_env) {
 		gpio = def;
 	} else {
@@ -199,7 +199,7 @@ void set_env_gpios(unsigned char state)
 		strcat(str_tmp, num);
 
 		/* If env var is not found we stop */
-		ptr_env = env_get(str_tmp);
+		ptr_env = env_get(ctx_uboot, str_tmp);
 		if (NULL == ptr_env)
 			break;
 
diff --git a/board/siemens/draco/board.c b/board/siemens/draco/board.c
index a6840b895b27..9cb1b1301855 100644
--- a/board/siemens/draco/board.c
+++ b/board/siemens/draco/board.c
@@ -270,13 +270,13 @@ int board_late_init(void)
 #ifdef CONFIG_FACTORYSET
 	/* Set ASN in environment*/
 	if (factory_dat.asn[0] != 0) {
-		env_set("dtb_name", (char *)factory_dat.asn);
+		env_set(ctx_uboot, "dtb_name", (char *)factory_dat.asn);
 	} else {
 		/* dtb suffix gets added in load script */
-		env_set("dtb_name", "am335x-draco");
+		env_set(ctx_uboot, "dtb_name", "am335x-draco");
 	}
 #else
-	env_set("dtb_name", "am335x-draco");
+	env_set(ctx_uboot, "dtb_name", "am335x-draco");
 #endif
 
 	return 0;
diff --git a/board/siemens/pxm2/board.c b/board/siemens/pxm2/board.c
index 30f0902701ee..e57ab33da88b 100644
--- a/board/siemens/pxm2/board.c
+++ b/board/siemens/pxm2/board.c
@@ -444,12 +444,12 @@ int board_late_init(void)
 			factory_dat.pxm50 = 0;
 		sprintf(tmp, "%s_%s", factory_dat.asn,
 			factory_dat.comp_version);
-		ret = env_set("boardid", tmp);
+		ret = env_set(ctx_uboot, "boardid", tmp);
 		if (ret)
 			printf("error setting board id\n");
 	} else {
 		factory_dat.pxm50 = 1;
-		ret = env_set("boardid", "PXM50_1.0");
+		ret = env_set(ctx_uboot, "boardid", "PXM50_1.0");
 		if (ret)
 			printf("error setting board id\n");
 	}
diff --git a/board/siemens/rut/board.c b/board/siemens/rut/board.c
index 539ecef22cb4..809cea42f86b 100644
--- a/board/siemens/rut/board.c
+++ b/board/siemens/rut/board.c
@@ -480,7 +480,7 @@ int board_late_init(void)
 	else
 		strcpy(tmp, "QMX7.E38_4.0");
 
-	ret = env_set("boardid", tmp);
+	ret = env_set(ctx_uboot, "boardid", tmp);
 	if (ret)
 		printf("error setting board id\n");
 
diff --git a/board/siemens/taurus/taurus.c b/board/siemens/taurus/taurus.c
index 1cf1f9e1f7ca..980d773a77bb 100644
--- a/board/siemens/taurus/taurus.c
+++ b/board/siemens/taurus/taurus.c
@@ -350,36 +350,36 @@ static int upgrade_failure_fallback(void)
 	char *kern_size;
 	char *kern_size_fb;
 
-	partitionset_active = env_get("partitionset_active");
+	partitionset_active = env_get(ctx_uboot, "partitionset_active");
 	if (partitionset_active) {
 		if (partitionset_active[0] == 'A')
-			env_set("partitionset_active", "B");
+			env_set(ctx_uboot, "partitionset_active", "B");
 		else
-			env_set("partitionset_active", "A");
+			env_set(ctx_uboot, "partitionset_active", "A");
 	} else {
 		printf("partitionset_active missing.\n");
 		return -ENOENT;
 	}
 
-	rootfs = env_get("rootfs");
-	rootfs_fallback = env_get("rootfs_fallback");
-	env_set("rootfs", rootfs_fallback);
-	env_set("rootfs_fallback", rootfs);
+	rootfs = env_get(ctx_uboot, "rootfs");
+	rootfs_fallback = env_get(ctx_uboot, "rootfs_fallback");
+	env_set(ctx_uboot, "rootfs", rootfs_fallback);
+	env_set(ctx_uboot, "rootfs_fallback", rootfs);
 
-	kern_size = env_get("kernel_size");
-	kern_size_fb = env_get("kernel_size_fallback");
-	env_set("kernel_size", kern_size_fb);
-	env_set("kernel_size_fallback", kern_size);
+	kern_size = env_get(ctx_uboot, "kernel_size");
+	kern_size_fb = env_get(ctx_uboot, "kernel_size_fallback");
+	env_set(ctx_uboot, "kernel_size", kern_size_fb);
+	env_set(ctx_uboot, "kernel_size_fallback", kern_size);
 
-	kern_off = env_get("kernel_Off");
-	kern_off_fb = env_get("kernel_Off_fallback");
-	env_set("kernel_Off", kern_off_fb);
-	env_set("kernel_Off_fallback", kern_off);
+	kern_off = env_get(ctx_uboot, "kernel_Off");
+	kern_off_fb = env_get(ctx_uboot, "kernel_Off_fallback");
+	env_set(ctx_uboot, "kernel_Off", kern_off_fb);
+	env_set(ctx_uboot, "kernel_Off_fallback", kern_off);
 
-	env_set("bootargs", '\0');
-	env_set("upgrade_available", '\0');
-	env_set("boot_retries", '\0');
-	env_save();
+	env_set(ctx_uboot, "bootargs", '\0');
+	env_set(ctx_uboot, "upgrade_available", '\0');
+	env_set(ctx_uboot, "boot_retries", '\0');
+	env_save(ctx_uboot);
 
 	return 0;
 }
@@ -391,14 +391,16 @@ static int do_upgrade_available(cmd_tbl_t *cmdtp, int flag, int argc,
 	unsigned long boot_retry = 0;
 	char boot_buf[10];
 
-	upgrade_available = simple_strtoul(env_get("upgrade_available"), NULL,
-					   10);
+	upgrade_available = simple_strtoul(env_get(ctx_uboot,
+						   "upgrade_available"),
+					   NULL, 10);
 	if (upgrade_available) {
-		boot_retry = simple_strtoul(env_get("boot_retries"), NULL, 10);
+		boot_retry = simple_strtoul(env_get(ctx_uboot, "boot_retries"),
+					    NULL, 10);
 		boot_retry++;
 		sprintf(boot_buf, "%lx", boot_retry);
-		env_set("boot_retries", boot_buf);
-		env_save();
+		env_set(ctx_uboot, "boot_retries", boot_buf);
+		env_save(ctx_uboot);
 
 		/*
 		 * Here the boot_retries count is checked, and if the
diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
index da9ae5bebb7e..277f9e107080 100644
--- a/board/socrates/socrates.c
+++ b/board/socrates/socrates.c
@@ -38,7 +38,7 @@ int checkboard (void)
 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
 	char buf[64];
 	int f;
-	int i = env_get_f("serial#", buf, sizeof(buf));
+	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
 #ifdef CONFIG_PCI
 	char *src;
 #endif
@@ -409,7 +409,7 @@ void board_backlight_switch (int flag)
 		printf ("hwmon IC init failed\n");
 
 	if (flag) {
-		param = env_get("brightness");
+		param = env_get(ctx_uboot, "brightness");
 		rc = param ? simple_strtol(param, NULL, 10) : -1;
 		if (rc < 0)
 			rc = DEFAULT_BRIGHTNESS;
diff --git a/board/softing/vining_2000/vining_2000.c b/board/softing/vining_2000/vining_2000.c
index 51985b91c226..5d4d0f29c44f 100644
--- a/board/softing/vining_2000/vining_2000.c
+++ b/board/softing/vining_2000/vining_2000.c
@@ -102,7 +102,7 @@ int board_eth_init(bd_t *bis)
 
 	/* just to get secound mac address */
 	imx_get_mac_from_fuse(1, eth1addr);
-	if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
+	if (!env_get(ctx_uboot, "eth1addr") && is_valid_ethaddr(eth1addr))
 		eth_env_set_enetaddr("eth1addr", eth1addr);
 
 	imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));
@@ -385,11 +385,11 @@ static int set_pin_state(void)
 		return ret;
 
 	if (val >= VAL_UPPER)
-		env_set("pin_state", "connected");
+		env_set(ctx_uboot, "pin_state", "connected");
 	else if (val < VAL_UPPER && val > VAL_LOWER)
-		env_set("pin_state", "open");
+		env_set(ctx_uboot, "pin_state", "open");
 	else
-		env_set("pin_state", "button");
+		env_set(ctx_uboot, "pin_state", "button");
 
 	return ret;
 }
diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c b/board/solidrun/mx6cuboxi/mx6cuboxi.c
index f82fb0786a94..52177b918d83 100644
--- a/board/solidrun/mx6cuboxi/mx6cuboxi.c
+++ b/board/solidrun/mx6cuboxi/mx6cuboxi.c
@@ -569,29 +569,29 @@ int board_late_init(void)
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	switch (board_type()) {
 	case CUBOXI:
-		env_set("board_name", "CUBOXI");
+		env_set(ctx_uboot, "board_name", "CUBOXI");
 		break;
 	case HUMMINGBOARD:
-		env_set("board_name", "HUMMINGBOARD");
+		env_set(ctx_uboot, "board_name", "HUMMINGBOARD");
 		break;
 	case HUMMINGBOARD2:
-		env_set("board_name", "HUMMINGBOARD2");
+		env_set(ctx_uboot, "board_name", "HUMMINGBOARD2");
 		break;
 	case UNKNOWN:
 	default:
-		env_set("board_name", "CUBOXI");
+		env_set(ctx_uboot, "board_name", "CUBOXI");
 	}
 
 	if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 
 	if (is_rev_15_som())
-		env_set("som_rev", "V15");
+		env_set(ctx_uboot, "som_rev", "V15");
 
 	if (has_emmc())
-		env_set("has_emmc", "yes");
+		env_set(ctx_uboot, "has_emmc", "yes");
 
 #endif
 
diff --git a/board/st/stm32f429-discovery/stm32f429-discovery.c b/board/st/stm32f429-discovery/stm32f429-discovery.c
index 500dc5fe3a6b..3ae0c17d7720 100644
--- a/board/st/stm32f429-discovery/stm32f429-discovery.c
+++ b/board/st/stm32f429-discovery/stm32f429-discovery.c
@@ -65,13 +65,13 @@ int misc_init_r(void)
 	char serialno[25];
 	uint32_t u_id_low, u_id_mid, u_id_high;
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		u_id_low  = readl(&STM32_U_ID->u_id_low);
 		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
 		u_id_high = readl(&STM32_U_ID->u_id_high);
 		sprintf(serialno, "%08x%08x%08x",
 			u_id_high, u_id_mid, u_id_low);
-		env_set("serial#", serialno);
+		env_set(ctx_uboot, "serial#", serialno);
 	}
 
 	return 0;
diff --git a/board/st/stm32f429-evaluation/stm32f429-evaluation.c b/board/st/stm32f429-evaluation/stm32f429-evaluation.c
index 8ab2fa5d59ab..3a1c578cdad8 100644
--- a/board/st/stm32f429-evaluation/stm32f429-evaluation.c
+++ b/board/st/stm32f429-evaluation/stm32f429-evaluation.c
@@ -59,13 +59,13 @@ int misc_init_r(void)
 	char serialno[25];
 	u32 u_id_low, u_id_mid, u_id_high;
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		u_id_low  = readl(&STM32_U_ID->u_id_low);
 		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
 		u_id_high = readl(&STM32_U_ID->u_id_high);
 		sprintf(serialno, "%08x%08x%08x",
 			u_id_high, u_id_mid, u_id_low);
-		env_set("serial#", serialno);
+		env_set(ctx_uboot, "serial#", serialno);
 	}
 
 	return 0;
diff --git a/board/st/stm32f469-discovery/stm32f469-discovery.c b/board/st/stm32f469-discovery/stm32f469-discovery.c
index 70d23d90f4ca..e475296919e0 100644
--- a/board/st/stm32f469-discovery/stm32f469-discovery.c
+++ b/board/st/stm32f469-discovery/stm32f469-discovery.c
@@ -59,13 +59,13 @@ int misc_init_r(void)
 	char serialno[25];
 	u32 u_id_low, u_id_mid, u_id_high;
 
-	if (!env_get("serial#")) {
+	if (!env_get(ctx_uboot, "serial#")) {
 		u_id_low  = readl(&STM32_U_ID->u_id_low);
 		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
 		u_id_high = readl(&STM32_U_ID->u_id_high);
 		sprintf(serialno, "%08x%08x%08x",
 			u_id_high, u_id_mid, u_id_low);
-		env_set("serial#", serialno);
+		env_set(ctx_uboot, "serial#", serialno);
 	}
 
 	return 0;
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 279c7b779799..188f4a7eae12 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -544,9 +544,9 @@ int board_late_init(void)
 				 &fdt_compat_len);
 	if (fdt_compat && fdt_compat_len) {
 		if (strncmp(fdt_compat, "st,", 3) != 0)
-			env_set("board_name", fdt_compat);
+			env_set(ctx_uboot, "board_name", fdt_compat);
 		else
-			env_set("board_name", fdt_compat + 3);
+			env_set(ctx_uboot, "board_name", fdt_compat + 3);
 	}
 #endif
 
@@ -623,7 +623,8 @@ int board_interface_eth_init(phy_interface_t interface_type,
 	return 0;
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	u32 bootmode = get_bootmode();
 
@@ -688,8 +689,8 @@ const char *env_ext4_get_dev_part(void)
 static const char *env_get_mtdparts(const char *str, char *buf)
 {
 	if (gd->flags & GD_FLG_ENV_READY)
-		return env_get(str);
-	if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
+		return env_get(ctx_uboot, str);
+	if (env_get_f(ctx_uboot, str, buf, MTDPARTS_LEN) != -1)
 		return buf;
 
 	return NULL;
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index e3b2d13892c8..d5f172eb8082 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -194,7 +194,8 @@ void i2c_init_board(void)
 }
 
 #if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
-enum env_location env_get_location(enum env_operation op, int prio)
+enum env_location env_get_location(struct env_context *ctx,
+				   enum env_operation op, int prio)
 {
 	switch (prio) {
 	case 0:
@@ -725,7 +726,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
 	char *serial_string;
 	unsigned long long serial;
 
-	serial_string = env_get("serial#");
+	serial_string = env_get(ctx_uboot, "serial#");
 
 	if (serial_string) {
 		serial = simple_strtoull(serial_string, NULL, 16);
@@ -764,7 +765,7 @@ static void parse_spl_header(const uint32_t spl_addr)
 		return;
 	}
 	/* otherwise assume .scr format (mkimage-type script) */
-	env_set_hex("fel_scriptaddr", spl->fel_script_address);
+	env_set_hex(ctx_uboot, "fel_scriptaddr", spl->fel_script_address);
 }
 
 /*
@@ -812,7 +813,7 @@ static void setup_environment(const void *fdt)
 			else
 				sprintf(ethaddr, "eth%daddr", i);
 
-			if (env_get(ethaddr))
+			if (env_get(ctx_uboot, ethaddr))
 				continue;
 
 			/* Non OUI / registered MAC address */
@@ -826,11 +827,11 @@ static void setup_environment(const void *fdt)
 			eth_env_set_enetaddr(ethaddr, mac_addr);
 		}
 
-		if (!env_get("serial#")) {
+		if (!env_get(ctx_uboot, "serial#")) {
 			snprintf(serial_string, sizeof(serial_string),
 				"%08x%08x", sid[0], sid[3]);
 
-			env_set("serial#", serial_string);
+			env_set(ctx_uboot, "serial#", serial_string);
 		}
 	}
 }
@@ -839,20 +840,20 @@ int misc_init_r(void)
 {
 	uint boot;
 
-	env_set("fel_booted", NULL);
-	env_set("fel_scriptaddr", NULL);
-	env_set("mmc_bootdev", NULL);
+	env_set(ctx_uboot, "fel_booted", NULL);
+	env_set(ctx_uboot, "fel_scriptaddr", NULL);
+	env_set(ctx_uboot, "mmc_bootdev", NULL);
 
 	boot = sunxi_get_boot_device();
 	/* determine if we are running in FEL mode */
 	if (boot == BOOT_DEVICE_BOARD) {
-		env_set("fel_booted", "1");
+		env_set(ctx_uboot, "fel_booted", "1");
 		parse_spl_header(SPL_ADDR);
 	/* or if we booted from MMC, and which one */
 	} else if (boot == BOOT_DEVICE_MMC1) {
-		env_set("mmc_bootdev", "0");
+		env_set(ctx_uboot, "mmc_bootdev", "0");
 	} else if (boot == BOOT_DEVICE_MMC2) {
-		env_set("mmc_bootdev", "1");
+		env_set(ctx_uboot, "mmc_bootdev", "1");
 	}
 
 	setup_environment(gd->fdt_blob);
diff --git a/board/synopsys/hsdk/env-lib.c b/board/synopsys/hsdk/env-lib.c
index f443c21e6d99..eca2211246b4 100644
--- a/board/synopsys/hsdk/env-lib.c
+++ b/board/synopsys/hsdk/env-lib.c
@@ -21,10 +21,12 @@ static int env_read_common(u32 index, const struct env_map_common *map)
 
 	if (!env_get_yesno(map[index].env_name)) {
 		if (map[index].type == ENV_HEX) {
-			val = (u32)env_get_hex(map[index].env_name, 0);
+			val = (u32)env_get_hex(ctx_uboot, map[index].env_name,
+					       0);
 			debug("ENV: %s: = %#x\n", map[index].env_name, val);
 		} else {
-			val = (u32)env_get_ulong(map[index].env_name, 10, 0);
+			val = (u32)env_get_ulong(ctx_uboot,
+						 map[index].env_name, 10, 0);
 			debug("ENV: %s: = %d\n", map[index].env_name, val);
 		}
 
@@ -52,10 +54,11 @@ static int env_read_core(u32 index, const struct env_map_percpu *map)
 		sprintf(command, "%s_%u", map[index].env_name, i);
 		if (!env_get_yesno(command)) {
 			if (map[index].type == ENV_HEX) {
-				val = (u32)env_get_hex(command, 0);
+				val = (u32)env_get_hex(ctx_uboot, command, 0);
 				debug("ENV: %s: = %#x\n", command, val);
 			} else {
-				val = (u32)env_get_ulong(command, 10, 0);
+				val = (u32)env_get_ulong(ctx_uboot, command,
+							 10, 0);
 				debug("ENV: %s: = %d\n", command, val);
 			}
 
diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c
index 8a7642a0aaaa..ab97b97bcde3 100644
--- a/board/synopsys/hsdk/hsdk.c
+++ b/board/synopsys/hsdk/hsdk.c
@@ -854,19 +854,19 @@ static int do_hsdk_clock_get(cmd_tbl_t *cmdtp, int flag, int argc,
 	if (soc_clk_ctl("cpu-clk", &rate, CLK_GET | CLK_MHZ))
 		return CMD_RET_FAILURE;
 
-	if (env_set_ulong("cpu_freq", rate))
+	if (env_set_ulong(ctx_uboot, "cpu_freq", rate))
 		return CMD_RET_FAILURE;
 
 	if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
 		return CMD_RET_FAILURE;
 
-	if (env_set_ulong("tun_freq", rate))
+	if (env_set_ulong(ctx_uboot, "tun_freq", rate))
 		return CMD_RET_FAILURE;
 
 	if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
 		return CMD_RET_FAILURE;
 
-	if (env_set_ulong("axi_freq", rate))
+	if (env_set_ulong(ctx_uboot, "axi_freq", rate))
 		return CMD_RET_FAILURE;
 
 	printf("Clock values are saved to environment\n");
diff --git a/board/syteco/zmx25/zmx25.c b/board/syteco/zmx25/zmx25.c
index d2318457b431..c49ac35c2933 100644
--- a/board/syteco/zmx25/zmx25.c
+++ b/board/syteco/zmx25/zmx25.c
@@ -145,7 +145,7 @@ int board_late_init(void)
 	udelay(5000);
 #endif
 
-	e = env_get("gs_base_board");
+	e = env_get(ctx_uboot, "gs_base_board");
 	if (e != NULL) {
 		if (strcmp(e, "G283") == 0) {
 			int key = gpio_get_value(IMX_GPIO_NR(2, 29));
@@ -155,9 +155,11 @@ int board_late_init(void)
 				gpio_set_value(IMX_GPIO_NR(1, 29), 0);
 				gpio_set_value(IMX_GPIO_NR(4, 21), 0);
 
-				env_set("preboot", "run gs_slow_boot");
+				env_set(ctx_uboot, "preboot",
+					"run gs_slow_boot");
 			} else
-				env_set("preboot", "run gs_fast_boot");
+				env_set(ctx_uboot, "preboot",
+					"run gs_fast_boot");
 		}
 	}
 
diff --git a/board/tcl/sl50/board.c b/board/tcl/sl50/board.c
index c7eed319461a..79598cd36a5e 100644
--- a/board/tcl/sl50/board.c
+++ b/board/tcl/sl50/board.c
@@ -75,7 +75,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
+	env_load(ctx_uboot);
 	if (env_get_yesno("boot_os") != 1)
 		return 1;
 #endif
@@ -321,7 +321,7 @@ int board_eth_init(bd_t *bis)
 
 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
 	(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
@@ -339,7 +339,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index 47259b714961..d0150a127dd6 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -58,8 +58,8 @@ static int setup_boottargets(void)
 	}
 	debug("%s: booted from %s\n", __func__, boot_device);
 
-	env_default = env_get_default("boot_targets");
-	env = env_get("boot_targets");
+	env_default = env_get_default(ctx_uboot, "boot_targets");
+	env = env_get(ctx_uboot, "boot_targets");
 	if (!env) {
 		debug("%s: boot_targets does not exist\n", __func__);
 		return -1;
@@ -102,7 +102,7 @@ static int setup_boottargets(void)
 			mmc0[3] = '1';
 			mmc1[3] = '0';
 			debug("%s: set boot_targets to: %s\n", __func__, env);
-			env_set("boot_targets", env);
+			env_set(ctx_uboot, "boot_targets", env);
 		}
 	}
 
@@ -140,7 +140,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
 	char *serial_string;
 	u64 serial = 0;
 
-	serial_string = env_get("serial#");
+	serial_string = env_get(ctx_uboot, "serial#");
 
 	if (serial_string)
 		serial = simple_strtoull(serial_string, NULL, 16);
diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index 7eaa6cd96d60..b1f432332d8c 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -251,7 +251,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
+	env_load(ctx_uboot);
 	if (env_get_yesno("boot_os") != 1)
 		return 1;
 #endif
@@ -825,7 +825,7 @@ int board_late_init(void)
 	 * on HS devices.
 	 */
 	if (get_device_type() == HS_DEVICE)
-		env_set("boot_fit", "1");
+		env_set(ctx_uboot, "boot_fit", "1");
 #endif
 
 #if !defined(CONFIG_SPL_BUILD)
@@ -839,7 +839,7 @@ int board_late_init(void)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
@@ -855,20 +855,20 @@ int board_late_init(void)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
 #endif
 
-	if (!env_get("serial#")) {
-		char *board_serial = env_get("board_serial");
-		char *ethaddr = env_get("ethaddr");
+	if (!env_get(ctx_uboot, "serial#")) {
+		char *board_serial = env_get(ctx_uboot, "board_serial");
+		char *ethaddr = env_get(ctx_uboot, "ethaddr");
 
 		if (!board_serial || !strncmp(board_serial, "unknown", 7))
-			env_set("serial#", ethaddr);
+			env_set(ctx_uboot, "serial#", ethaddr);
 		else
-			env_set("serial#", board_serial);
+			env_set(ctx_uboot, "serial#", board_serial);
 	}
 
 	return 0;
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index 2e09cc20e8c2..7eb71cd4d8d1 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -728,7 +728,7 @@ int board_late_init(void)
 	 * on HS devices.
 	 */
 	if (get_device_type() == HS_DEVICE)
-		env_set("boot_fit", "1");
+		env_set(ctx_uboot, "boot_fit", "1");
 #endif
 
 #if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
@@ -902,7 +902,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		puts("<ethaddr> not set. Validating first E-fuse MAC\n");
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("ethaddr", mac_addr);
@@ -917,7 +917,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = mac_lo & 0xFF;
 	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
index f78e6c2e1f6e..222049d541de 100644
--- a/board/ti/am57xx/board.c
+++ b/board/ti/am57xx/board.c
@@ -668,7 +668,7 @@ void am57x_idk_lcd_detect(void)
 		/* we will let default be "no lcd" */
 	}
 out:
-	env_set("idk_lcd", idk_lcd);
+	env_set(ctx_uboot, "idk_lcd", idk_lcd);
 	return;
 }
 
@@ -701,7 +701,7 @@ int board_late_init(void)
 	 * on HS devices.
 	 */
 	if (get_device_type() == HS_DEVICE)
-		env_set("boot_fit", "1");
+		env_set(ctx_uboot, "boot_fit", "1");
 
 	/*
 	 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
@@ -871,7 +871,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
+	env_load(ctx_uboot);
 	if (env_get_yesno("boot_os") != 1)
 		return 1;
 #endif
@@ -975,7 +975,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
 	mac_addr[5] = mac_lo & 0xFF;
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
@@ -991,7 +991,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
 	mac_addr[5] = mac_lo & 0xFF;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
@@ -1100,8 +1100,8 @@ int board_fit_config_name_match(const char *name)
 int fastboot_set_reboot_flag(void)
 {
 	printf("Setting reboot to fastboot flag ...\n");
-	env_set("dofastboot", "1");
-	env_save();
+	env_set(ctx_uboot, "dofastboot", "1");
+	env_save(ctx_uboot);
 	return 0;
 }
 #endif
diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
index 0138fc91fcbe..7ee36aff7c45 100644
--- a/board/ti/beagle/beagle.c
+++ b/board/ti/beagle/beagle.c
@@ -340,16 +340,16 @@ int misc_init_r(void)
 	switch (get_board_revision()) {
 	case REVISION_AXBX:
 		printf("Beagle Rev Ax/Bx\n");
-		env_set("beaglerev", "AxBx");
+		env_set(ctx_uboot, "beaglerev", "AxBx");
 		break;
 	case REVISION_CX:
 		printf("Beagle Rev C1/C2/C3\n");
-		env_set("beaglerev", "Cx");
+		env_set(ctx_uboot, "beaglerev", "Cx");
 		MUX_BEAGLE_C();
 		break;
 	case REVISION_C4:
 		printf("Beagle Rev C4\n");
-		env_set("beaglerev", "C4");
+		env_set(ctx_uboot, "beaglerev", "C4");
 		MUX_BEAGLE_C();
 		/* Set VAUX2 to 1.8V for EHCI PHY */
 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
@@ -359,7 +359,7 @@ int misc_init_r(void)
 		break;
 	case REVISION_XM_AB:
 		printf("Beagle xM Rev A/B\n");
-		env_set("beaglerev", "xMAB");
+		env_set(ctx_uboot, "beaglerev", "xMAB");
 		MUX_BEAGLE_XM();
 		/* Set VAUX2 to 1.8V for EHCI PHY */
 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
@@ -370,7 +370,7 @@ int misc_init_r(void)
 		break;
 	case REVISION_XM_C:
 		printf("Beagle xM Rev C\n");
-		env_set("beaglerev", "xMC");
+		env_set(ctx_uboot, "beaglerev", "xMC");
 		MUX_BEAGLE_XM();
 		/* Set VAUX2 to 1.8V for EHCI PHY */
 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
@@ -396,14 +396,14 @@ int misc_init_r(void)
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_TINCANTOOLS_ZIPPY();
-		env_set("buddy", "zippy");
+		env_set(ctx_uboot, "buddy", "zippy");
 		break;
 	case TINCANTOOLS_ZIPPY2:
 		printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		MUX_TINCANTOOLS_ZIPPY();
-		env_set("buddy", "zippy2");
+		env_set(ctx_uboot, "buddy", "zippy2");
 		break;
 	case TINCANTOOLS_TRAINER:
 		printf("Recognized Tincantools Trainer board (rev %d %s)\n",
@@ -411,37 +411,37 @@ int misc_init_r(void)
 			expansion_config.fab_revision);
 		MUX_TINCANTOOLS_ZIPPY();
 		MUX_TINCANTOOLS_TRAINER();
-		env_set("buddy", "trainer");
+		env_set(ctx_uboot, "buddy", "trainer");
 		break;
 	case TINCANTOOLS_SHOWDOG:
 		printf("Recognized Tincantools Showdow board (rev %d %s)\n",
 			expansion_config.revision,
 			expansion_config.fab_revision);
 		/* Place holder for DSS2 definition for showdog lcd */
-		env_set("defaultdisplay", "showdoglcd");
-		env_set("buddy", "showdog");
+		env_set(ctx_uboot, "defaultdisplay", "showdoglcd");
+		env_set(ctx_uboot, "buddy", "showdog");
 		break;
 	case KBADC_BEAGLEFPGA:
 		printf("Recognized KBADC Beagle FPGA board\n");
 		MUX_KBADC_BEAGLEFPGA();
-		env_set("buddy", "beaglefpga");
+		env_set(ctx_uboot, "buddy", "beaglefpga");
 		break;
 	case LW_BEAGLETOUCH:
 		printf("Recognized Liquidware BeagleTouch board\n");
-		env_set("buddy", "beagletouch");
+		env_set(ctx_uboot, "buddy", "beagletouch");
 		break;
 	case BRAINMUX_LCDOG:
 		printf("Recognized Brainmux LCDog board\n");
-		env_set("buddy", "lcdog");
+		env_set(ctx_uboot, "buddy", "lcdog");
 		break;
 	case BRAINMUX_LCDOGTOUCH:
 		printf("Recognized Brainmux LCDog Touch board\n");
-		env_set("buddy", "lcdogtouch");
+		env_set(ctx_uboot, "buddy", "lcdogtouch");
 		break;
 	case BBTOYS_WIFI:
 		printf("Recognized BeagleBoardToys WiFi board\n");
 		MUX_BBTOYS_WIFI()
-		env_set("buddy", "bbtoys-wifi");
+		env_set(ctx_uboot, "buddy", "bbtoys-wifi");
 		break;
 	case BBTOYS_VGA:
 		printf("Recognized BeagleBoardToys VGA board\n");
@@ -458,20 +458,21 @@ int misc_init_r(void)
 	case LSR_COM6L_ADPT:
 		printf("Recognized LSR COM6L Adapter Board\n");
 		MUX_BBTOYS_WIFI()
-		env_set("buddy", "lsr-com6l-adpt");
+		env_set(ctx_uboot, "buddy", "lsr-com6l-adpt");
 		break;
 	case BEAGLE_NO_EEPROM:
 		printf("No EEPROM on expansion board\n");
-		env_set("buddy", "none");
+		env_set(ctx_uboot, "buddy", "none");
 		break;
 	default:
 		printf("Unrecognized expansion board: %x\n",
 			expansion_config.device_vendor);
-		env_set("buddy", "unknown");
+		env_set(ctx_uboot, "buddy", "unknown");
 	}
 
 	if (expansion_config.content == 1)
-		env_set(expansion_config.env_var, expansion_config.env_setting);
+		env_set(ctx_uboot, expansion_config.env_var,
+			expansion_config.env_setting);
 
 	twl4030_power_init();
 	switch (get_board_revision()) {
@@ -511,10 +512,10 @@ int misc_init_r(void)
 
 #if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
 	if (strlen(CONFIG_MTDIDS_DEFAULT))
-		env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
+		env_set(ctx_uboot, "mtdids", CONFIG_MTDIDS_DEFAULT);
 
 	if (strlen(CONFIG_MTDPARTS_DEFAULT))
-		env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
+		env_set(ctx_uboot, "mtdparts", CONFIG_MTDPARTS_DEFAULT);
 #endif
 
 	return 0;
diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
index bc89cc57bd78..fe776f2428d2 100644
--- a/board/ti/common/board_detect.c
+++ b/board/ti/common/board_detect.c
@@ -580,21 +580,21 @@ void __maybe_unused set_board_info_env(char *name)
 	struct ti_common_eeprom *ep = TI_EEPROM_DATA;
 
 	if (name)
-		env_set("board_name", name);
+		env_set(ctx_uboot, "board_name", name);
 	else if (ep->name)
-		env_set("board_name", ep->name);
+		env_set(ctx_uboot, "board_name", ep->name);
 	else
-		env_set("board_name", unknown);
+		env_set(ctx_uboot, "board_name", unknown);
 
 	if (ep->version)
-		env_set("board_rev", ep->version);
+		env_set(ctx_uboot, "board_rev", ep->version);
 	else
-		env_set("board_rev", unknown);
+		env_set(ctx_uboot, "board_rev", unknown);
 
 	if (ep->serial)
-		env_set("board_serial", ep->serial);
+		env_set(ctx_uboot, "board_serial", ep->serial);
 	else
-		env_set("board_serial", unknown);
+		env_set(ctx_uboot, "board_serial", unknown);
 }
 
 void __maybe_unused set_board_info_env_am6(char *name)
diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
index 74d04bb1e393..63ac5b1988bf 100644
--- a/board/ti/dra7xx/evm.c
+++ b/board/ti/dra7xx/evm.c
@@ -691,7 +691,7 @@ int board_late_init(void)
 	 * on HS devices.
 	 */
 	if (get_device_type() == HS_DEVICE)
-		env_set("boot_fit", "1");
+		env_set(ctx_uboot, "boot_fit", "1");
 
 	omap_die_id_serial();
 	omap_set_fastboot_vars();
@@ -980,7 +980,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 	env_init();
-	env_load();
+	env_load(ctx_uboot);
 	if (env_get_yesno("boot_os") != 1)
 		return 1;
 #endif
@@ -1048,7 +1048,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
 	mac_addr[5] = mac_lo & 0xFF;
 
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
@@ -1064,7 +1064,7 @@ int board_eth_init(bd_t *bis)
 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
 	mac_addr[5] = mac_lo & 0xFF;
 
-	if (!env_get("eth1addr")) {
+	if (!env_get(ctx_uboot, "eth1addr")) {
 		if (is_valid_ethaddr(mac_addr))
 			eth_env_set_enetaddr("eth1addr", mac_addr);
 	}
@@ -1152,8 +1152,8 @@ int board_fit_config_name_match(const char *name)
 int fastboot_set_reboot_flag(void)
 {
 	printf("Setting reboot to fastboot flag ...\n");
-	env_set("dofastboot", "1");
-	env_save();
+	env_set(ctx_uboot, "dofastboot", "1");
+	env_save(ctx_uboot);
 	return 0;
 }
 #endif
diff --git a/board/ti/evm/evm.c b/board/ti/evm/evm.c
index d0b9bafbd1b6..4053eb7448a6 100644
--- a/board/ti/evm/evm.c
+++ b/board/ti/evm/evm.c
@@ -283,7 +283,7 @@ static void reset_net_chip(void)
 int board_eth_init(bd_t *bis)
 {
 #if defined(CONFIG_SMC911X)
-	env_set("ethaddr", NULL);
+	env_set(ctx_uboot, "ethaddr", NULL);
 	return smc911x_initialize(0, CONFIG_SMC911X_BASE);
 #else
 	return 0;
diff --git a/board/ti/ks2_evm/board.c b/board/ti/ks2_evm/board.c
index e9bc68049b4b..aa447fd886cc 100644
--- a/board/ti/ks2_evm/board.c
+++ b/board/ti/ks2_evm/board.c
@@ -113,7 +113,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 	u64 start[2];
 	u32 ddr3a_size;
 
-	env = env_get("mem_lpae");
+	env = env_get(ctx_uboot, "mem_lpae");
 	lpae = env && simple_strtol(env, NULL, 0);
 
 	ddr3a_size = 0;
@@ -140,13 +140,13 @@ int ft_board_setup(void *blob, bd_t *bd)
 	}
 
 	/* reserve memory at start of bank */
-	env = env_get("mem_reserve_head");
+	env = env_get(ctx_uboot, "mem_reserve_head");
 	if (env) {
 		start[0] += ustrtoul(env, &endp, 0);
 		size[0] -= ustrtoul(env, &endp, 0);
 	}
 
-	env = env_get("mem_reserve");
+	env = env_get(ctx_uboot, "mem_reserve");
 	if (env)
 		size[0] -= ustrtoul(env, &endp, 0);
 
@@ -163,9 +163,9 @@ void ft_board_setup_ex(void *blob, bd_t *bd)
 	u64 *reserve_start;
 	int unitrd_fixup = 0;
 
-	env = env_get("mem_lpae");
+	env = env_get(ctx_uboot, "mem_lpae");
 	lpae = env && simple_strtol(env, NULL, 0);
-	env = env_get("uinitrd_fixup");
+	env = env_get(ctx_uboot, "uinitrd_fixup");
 	unitrd_fixup = env && simple_strtol(env, NULL, 0);
 
 	/* Fix up the initrd */
diff --git a/board/ti/ks2_evm/board_k2g.c b/board/ti/ks2_evm/board_k2g.c
index 4ff9a44b3712..49c09b88bd83 100644
--- a/board/ti/ks2_evm/board_k2g.c
+++ b/board/ti/ks2_evm/board_k2g.c
@@ -353,11 +353,11 @@ int board_late_init(void)
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (board_is_k2g_gp())
-		env_set("board_name", "66AK2GGP\0");
+		env_set(ctx_uboot, "board_name", "66AK2GGP\0");
 	else if (board_is_k2g_g1())
-		env_set("board_name", "66AK2GG1\0");
+		env_set(ctx_uboot, "board_name", "66AK2GG1\0");
 	else if (board_is_k2g_ice())
-		env_set("board_name", "66AK2GIC\0");
+		env_set(ctx_uboot, "board_name", "66AK2GIC\0");
 #endif
 	return 0;
 }
@@ -384,7 +384,7 @@ void spl_init_keystone_plls(void)
 #ifdef CONFIG_TI_SECURE_DEVICE
 void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
 {
-	int id = env_get_ulong("dev_pmmc", 10, 0);
+	int id = env_get_ulong(ctx_uboot, "dev_pmmc", 10, 0);
 	int ret;
 
 	if (!rproc_is_initialized())
diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
index 20199da390ec..9d42123de9cc 100644
--- a/board/ti/panda/panda.c
+++ b/board/ti/panda/panda.c
@@ -103,7 +103,7 @@ int get_board_revision(void)
 		board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-		env_set("board_name", "panda-es");
+		env_set(ctx_uboot, "board_name", "panda-es");
 #endif
 		board_id = ((board_id4 << 4) | (board_id3 << 3) |
 			(board_id2 << 2) | (board_id1 << 1) | (board_id0));
@@ -117,7 +117,7 @@ int get_board_revision(void)
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 		if ((board_id >= 0x3) && (processor_rev == OMAP4430_ES2_3))
-			env_set("board_name", "panda-a4");
+			env_set(ctx_uboot, "board_name", "panda-a4");
 #endif
 	}
 
diff --git a/board/toradex/apalis-imx8/apalis-imx8.c b/board/toradex/apalis-imx8/apalis-imx8.c
index af48b560952e..7e0f01534a9e 100644
--- a/board/toradex/apalis-imx8/apalis-imx8.c
+++ b/board/toradex/apalis-imx8/apalis-imx8.c
@@ -117,8 +117,8 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 /* TODO move to common */
-	env_set("board_name", "Apalis iMX8QM");
-	env_set("board_rev", "v1.0");
+	env_set(ctx_uboot, "board_name", "Apalis iMX8QM");
+	env_set(ctx_uboot, "board_rev", "v1.0");
 #endif
 
 	return 0;
diff --git a/board/toradex/apalis_imx6/apalis_imx6.c b/board/toradex/apalis_imx6/apalis_imx6.c
index 6421a22c25a7..c40ccedc4c9d 100644
--- a/board/toradex/apalis_imx6/apalis_imx6.c
+++ b/board/toradex/apalis_imx6/apalis_imx6.c
@@ -701,7 +701,7 @@ int board_late_init(void)
 
 	rev = get_board_rev();
 	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
-	env_set("board_rev", env_str);
+	env_set(ctx_uboot, "board_rev", env_str);
 
 #ifndef CONFIG_TDX_APALIS_IMX6_V1_0
 	if ((rev & 0xfff0) == 0x0100) {
@@ -711,12 +711,12 @@ int board_late_init(void)
 		setup_iomux_dce_uart();
 
 		/* if using the default device tree, use version for V1.0 HW */
-		fdt_env = env_get("fdt_file");
+		fdt_env = env_get(ctx_uboot, "fdt_file");
 		if ((fdt_env != NULL) && (strcmp(FDT_FILE, fdt_env) == 0)) {
-			env_set("fdt_file", FDT_FILE_V1_0);
+			env_set(ctx_uboot, "fdt_file", FDT_FILE_V1_0);
 			printf("patching fdt_file to " FDT_FILE_V1_0 "\n");
 #ifndef CONFIG_ENV_IS_NOWHERE
-			env_save();
+			env_save(ctx_uboot);
 #endif
 		}
 	}
@@ -726,8 +726,8 @@ int board_late_init(void)
 #ifdef CONFIG_CMD_USB_SDP
 	if (is_boot_from_usb()) {
 		printf("Serial Downloader recovery mode, using sdp command\n");
-		env_set("bootdelay", "0");
-		env_set("bootcmd", "sdp 0");
+		env_set(ctx_uboot, "bootdelay", "0");
+		env_set(ctx_uboot, "bootcmd", "sdp 0");
 	}
 #endif /* CONFIG_CMD_USB_SDP */
 
diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
index d1ae463941ae..160b79ba0b27 100644
--- a/board/toradex/colibri-imx6ull/colibri-imx6ull.c
+++ b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
@@ -178,7 +178,7 @@ int board_late_init(void)
 	 */
 	if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
 	    tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT)
-		env_set("variant", "-wifi");
+		env_set(ctx_uboot, "variant", "-wifi");
 #endif
 
 	/*
@@ -196,8 +196,8 @@ int board_late_init(void)
 #ifdef CONFIG_CMD_USB_SDP
 	if (is_boot_from_usb()) {
 		printf("Serial Downloader recovery mode, using sdp command\n");
-		env_set("bootdelay", "0");
-		env_set("bootcmd", "sdp 0");
+		env_set(ctx_uboot, "bootdelay", "0");
+		env_set(ctx_uboot, "bootcmd", "sdp 0");
 	}
 #endif /* CONFIG_CMD_USB_SDP */
 
diff --git a/board/toradex/colibri-imx8x/colibri-imx8x.c b/board/toradex/colibri-imx8x/colibri-imx8x.c
index eae3c591a164..ef52f95dc93e 100644
--- a/board/toradex/colibri-imx8x/colibri-imx8x.c
+++ b/board/toradex/colibri-imx8x/colibri-imx8x.c
@@ -129,8 +129,8 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 /* TODO move to common */
-	env_set("board_name", "Colibri iMX8QXP");
-	env_set("board_rev", "v1.0");
+	env_set(ctx_uboot, "board_name", "Colibri iMX8QXP");
+	env_set(ctx_uboot, "board_rev", "v1.0");
 #endif
 
 	return 0;
diff --git a/board/toradex/colibri_imx6/colibri_imx6.c b/board/toradex/colibri_imx6/colibri_imx6.c
index ad40b589c1ed..1c1c1577eb1f 100644
--- a/board/toradex/colibri_imx6/colibri_imx6.c
+++ b/board/toradex/colibri_imx6/colibri_imx6.c
@@ -661,14 +661,14 @@ int board_late_init(void)
 
 	rev = get_board_rev();
 	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
-	env_set("board_rev", env_str);
+	env_set(ctx_uboot, "board_rev", env_str);
 #endif
 
 #ifdef CONFIG_CMD_USB_SDP
 	if (is_boot_from_usb()) {
 		printf("Serial Downloader recovery mode, using sdp command\n");
-		env_set("bootdelay", "0");
-		env_set("bootcmd", "sdp 0");
+		env_set(ctx_uboot, "bootdelay", "0");
+		env_set(ctx_uboot, "bootcmd", "sdp 0");
 	}
 #endif /* CONFIG_CMD_USB_SDP */
 
@@ -702,7 +702,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 
 	ft_common_board_setup(blob, bd);
 
-	cma_size = env_get_ulong("cma-size", 10, 320 * 1024 * 1024);
+	cma_size = env_get_ulong(ctx_uboot, "cma-size", 10, 320 * 1024 * 1024);
 	cma_size = min((u32)(gd->ram_size >> 1), cma_size);
 
 	fdt_setprop_u32(blob,
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c
index 04d8ffd1e666..e466d8aad6e1 100644
--- a/board/toradex/colibri_vf/colibri_vf.c
+++ b/board/toradex/colibri_vf/colibri_vf.c
@@ -392,7 +392,7 @@ int board_late_init(void)
 	if (((src->sbmr2 & SRC_SBMR2_BMOD_MASK) >> SRC_SBMR2_BMOD_SHIFT)
 			== SRC_SBMR2_BMOD_SERIAL) {
 		printf("Serial Downloader recovery mode, disable autoboot\n");
-		env_set("bootdelay", "-1");
+		env_set(ctx_uboot, "bootdelay", "-1");
 	}
 
 	return 0;
diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
index 9c86230595b9..6897ced0f7fe 100644
--- a/board/toradex/common/tdx-cfg-block.c
+++ b/board/toradex/common/tdx-cfg-block.c
@@ -314,7 +314,7 @@ static int get_cfgblock_interactive(void)
 	wb = console_buffer[0];
 #endif
 
-	soc = env_get("soc");
+	soc = env_get(ctx_uboot, "soc");
 	if (!strcmp("mx6", soc)) {
 #ifdef CONFIG_TARGET_APALIS_IMX6
 		if (it == 'y' || it == 'Y') {
diff --git a/board/toradex/common/tdx-common.c b/board/toradex/common/tdx-common.c
index e9441a7979d2..a51749dd78c2 100644
--- a/board/toradex/common/tdx-common.c
+++ b/board/toradex/common/tdx-common.c
@@ -81,7 +81,7 @@ int show_board_info(void)
 			tdx_hw_tag.ver_minor,
 			(char)tdx_hw_tag.ver_assembly + 'A');
 
-		env_set("serial#", tdx_serial_str);
+		env_set(ctx_uboot, "serial#", tdx_serial_str);
 
 		printf("Model: Toradex %s %s, Serial# %s\n",
 		       toradex_modules[tdx_hw_tag.prodid],
diff --git a/board/tqc/tqma6/tqma6.c b/board/tqc/tqma6/tqma6.c
index 5b20afd48814..f13126c2ee59 100644
--- a/board/tqc/tqma6/tqma6.c
+++ b/board/tqc/tqma6/tqma6.c
@@ -253,7 +253,7 @@ int power_init_board(void)
 
 int board_late_init(void)
 {
-	env_set("board_name", tqma6_get_boardname());
+	env_set(ctx_uboot, "board_name", tqma6_get_boardname());
 
 	tqma6_bb_board_late_init();
 
diff --git a/board/udoo/neo/neo.c b/board/udoo/neo/neo.c
index 5c468a6a973e..2a61dc29ef92 100644
--- a/board/udoo/neo/neo.c
+++ b/board/udoo/neo/neo.c
@@ -437,7 +437,7 @@ int checkboard(void)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
-	env_set("board_name", board_string());
+	env_set(ctx_uboot, "board_name", board_string());
 #endif
 
 	return 0;
diff --git a/board/udoo/udoo.c b/board/udoo/udoo.c
index f2c2bf47b0fd..88bc24b2b475 100644
--- a/board/udoo/udoo.c
+++ b/board/udoo/udoo.c
@@ -254,9 +254,9 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (is_cpu_type(MXC_CPU_MX6Q))
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 #endif
 	return 0;
 }
diff --git a/board/varisys/common/sys_eeprom.c b/board/varisys/common/sys_eeprom.c
index 77772a6923e4..5b248f8b0f44 100644
--- a/board/varisys/common/sys_eeprom.c
+++ b/board/varisys/common/sys_eeprom.c
@@ -401,7 +401,7 @@ int mac_read_from_generic_eeprom(const char *envvar, int chip,
 			mac[5]);
 
 		printf("MAC: %s\n", ethaddr);
-		env_set(envvar, ethaddr);
+		env_set(ctx_uboot, envvar, ethaddr);
 	}
 
 	return ret;
@@ -486,8 +486,8 @@ int mac_read_from_eeprom_common(void)
 			/* Only initialize environment variables that are blank
 			 * (i.e. have not yet been set)
 			 */
-			if (!env_get(enetvar))
-				env_set(enetvar, ethaddr);
+			if (!env_get(ctx_uboot, enetvar))
+				env_set(ctx_uboot, enetvar, ethaddr);
 		}
 	}
 
diff --git a/board/vscom/baltos/board.c b/board/vscom/baltos/board.c
index 1ba58d0f11dd..5e799d546786 100644
--- a/board/vscom/baltos/board.c
+++ b/board/vscom/baltos/board.c
@@ -65,7 +65,7 @@ static int baltos_set_console(void)
 	printf("DIPs: 0x%1x\n", (~dips) & 0xf);
 
 	if ((dips & 0xf) == 0xe)
-		env_set("console", "ttyUSB0,115200n8");
+		env_set(ctx_uboot, "console", "ttyUSB0,115200n8");
 
 	return 0;
 }
@@ -367,7 +367,7 @@ int board_late_init(void)
 		return -ENODEV;
 	}
 
-	env_set("board_name", model);
+	env_set(ctx_uboot, "board_name", model);
 #endif
 
 	return 0;
@@ -447,7 +447,7 @@ int board_eth_init(bd_t *bis)
 
 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
 	(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
-	if (!env_get("ethaddr")) {
+	if (!env_get(ctx_uboot, "ethaddr")) {
 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
 		if (is_valid_ethaddr(mac_addr))
diff --git a/board/wandboard/wandboard.c b/board/wandboard/wandboard.c
index 69cdf3e9c96b..4ba472cae9b8 100644
--- a/board/wandboard/wandboard.c
+++ b/board/wandboard/wandboard.c
@@ -451,18 +451,18 @@ int board_late_init(void)
 
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	if (is_mx6dqp())
-		env_set("board_rev", "MX6QP");
+		env_set(ctx_uboot, "board_rev", "MX6QP");
 	else if (is_mx6dq())
-		env_set("board_rev", "MX6Q");
+		env_set(ctx_uboot, "board_rev", "MX6Q");
 	else
-		env_set("board_rev", "MX6DL");
+		env_set(ctx_uboot, "board_rev", "MX6DL");
 
 	if (is_revd1())
-		env_set("board_name", "D1");
+		env_set(ctx_uboot, "board_name", "D1");
 	else if (is_revc1())
-		env_set("board_name", "C1");
+		env_set(ctx_uboot, "board_name", "C1");
 	else
-		env_set("board_name", "B1");
+		env_set(ctx_uboot, "board_name", "B1");
 #endif
 	return 0;
 }
diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c
index 39ae98225738..549d65b3469d 100644
--- a/board/warp7/warp7.c
+++ b/board/warp7/warp7.c
@@ -148,9 +148,9 @@ int board_late_init(void)
 
 #ifdef CONFIG_SECURE_BOOT
 	/* Determine HAB state */
-	env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
+	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
 #else
-	env_set_ulong(HAB_ENABLED_ENVNAME, 0);
+	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME, 0);
 #endif
 
 #ifdef CONFIG_SERIAL_TAG
@@ -158,7 +158,7 @@ int board_late_init(void)
 	get_board_serial(&serialnr);
 	snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x",
 		 serialnr.low, serialnr.high);
-	env_set("serial#", serial_string);
+	env_set(ctx_uboot, "serial#", serial_string);
 #endif
 
 	return 0;
diff --git a/board/work-microwave/work_92105/work_92105_display.c b/board/work-microwave/work_92105/work_92105_display.c
index db04dcabc7bc..e673921b7bbc 100644
--- a/board/work-microwave/work_92105/work_92105_display.c
+++ b/board/work-microwave/work_92105/work_92105_display.c
@@ -228,7 +228,7 @@ void work_92105_display_init(void)
 	i2c_write(0x2c, 0x01, 1, &enable_backlight, 1);
 
 	/* set display contrast */
-	display_contrast_str = env_get("fwopt_dispcontrast");
+	display_contrast_str = env_get(ctx_uboot, "fwopt_dispcontrast");
 	if (display_contrast_str)
 		display_contrast = simple_strtoul(display_contrast_str,
 			NULL, 10);
diff --git a/board/xes/common/board.c b/board/xes/common/board.c
index 43575bc302d6..b5cc9a69508a 100644
--- a/board/xes/common/board.c
+++ b/board/xes/common/board.c
@@ -51,13 +51,13 @@ int checkboard(void)
 
 	/* Display board specific information */
 	puts("       ");
-	i = env_get_f("board_rev", buf, sizeof(buf));
+	i = env_get_f("board_rev", buf, sizeof(ctx_uboot, buf));
 	if (i > 0)
 		printf("Rev %s, ", buf);
-	i = env_get_f("serial#", buf, sizeof(buf));
+	i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
 	if (i > 0)
 		printf("Serial# %s, ", buf);
-	i = env_get_f("board_cfg", buf, sizeof(buf));
+	i = env_get_f("board_cfg", buf, sizeof(ctx_uboot, buf));
 	if (i > 0)
 		printf("Cfg %s", buf);
 	puts("\n");
diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
index 35191b2f813b..509834c679ab 100644
--- a/board/xilinx/zynq/board.c
+++ b/board/xilinx/zynq/board.c
@@ -41,27 +41,27 @@ int board_late_init(void)
 	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
 	case ZYNQ_BM_QSPI:
 		mode = "qspi";
-		env_set("modeboot", "qspiboot");
+		env_set(ctx_uboot, "modeboot", "qspiboot");
 		break;
 	case ZYNQ_BM_NAND:
 		mode = "nand";
-		env_set("modeboot", "nandboot");
+		env_set(ctx_uboot, "modeboot", "nandboot");
 		break;
 	case ZYNQ_BM_NOR:
 		mode = "nor";
-		env_set("modeboot", "norboot");
+		env_set(ctx_uboot, "modeboot", "norboot");
 		break;
 	case ZYNQ_BM_SD:
 		mode = "mmc";
-		env_set("modeboot", "sdboot");
+		env_set(ctx_uboot, "modeboot", "sdboot");
 		break;
 	case ZYNQ_BM_JTAG:
 		mode = "pxe dhcp";
-		env_set("modeboot", "jtagboot");
+		env_set(ctx_uboot, "modeboot", "jtagboot");
 		break;
 	default:
 		mode = "";
-		env_set("modeboot", "");
+		env_set(ctx_uboot, "modeboot", "");
 		break;
 	}
 
@@ -69,7 +69,7 @@ int board_late_init(void)
 	 * One terminating char + one byte for space between mode
 	 * and default boot_targets
 	 */
-	env_targets = env_get("boot_targets");
+	env_targets = env_get(ctx_uboot, "boot_targets");
 	if (env_targets)
 		env_targets_len = strlen(env_targets);
 
@@ -80,7 +80,7 @@ int board_late_init(void)
 	sprintf(new_targets, "%s %s", mode,
 		env_targets ? env_targets : "");
 
-	env_set("boot_targets", new_targets);
+	env_set(ctx_uboot, "boot_targets", new_targets);
 
 	return 0;
 }
diff --git a/board/xilinx/zynqmp/cmds.c b/board/xilinx/zynqmp/cmds.c
index ed7ba58c6475..e5c1dab091ca 100644
--- a/board/xilinx/zynqmp/cmds.c
+++ b/board/xilinx/zynqmp/cmds.c
@@ -57,7 +57,7 @@ static int do_zynqmp_verify_secure(cmd_tbl_t *cmdtp, int flag, int argc,
 	} else {
 		addr = (u64)ret_payload[1] << 32 | ret_payload[2];
 		printf("Verified image@0x%llx\n", addr);
-		env_set_hex("zynqmp_verified_img_addr", addr);
+		env_set_hex(ctx_uboot, "zynqmp_verified_img_addr", addr);
 	}
 
 	return ret;
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index d649daba96d4..31e26fb097a4 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -479,7 +479,7 @@ static int reset_reason(void)
 
 	puts("\n");
 
-	env_set("reset_reason", reason);
+	env_set(ctx_uboot, "reset_reason", reason);
 
 	ret = zynqmp_mmio_write(~0, ~0, (ulong)&crlapb_base->reset_reason);
 	if (ret)
@@ -494,7 +494,7 @@ static int set_fdtfile(void)
 	const char *suffix = ".dtb";
 	const char *vendor = "xilinx/";
 
-	if (env_get("fdtfile"))
+	if (env_get(ctx_uboot, "fdtfile"))
 		return 0;
 
 	compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
@@ -511,7 +511,7 @@ static int set_fdtfile(void)
 
 		sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
 
-		env_set("fdtfile", fdtfile);
+		env_set(ctx_uboot, "fdtfile", fdtfile);
 		free(fdtfile);
 	}
 
@@ -558,23 +558,23 @@ int board_late_init(void)
 	case USB_MODE:
 		puts("USB_MODE\n");
 		mode = "usb";
-		env_set("modeboot", "usb_dfu_spl");
+		env_set(ctx_uboot, "modeboot", "usb_dfu_spl");
 		break;
 	case JTAG_MODE:
 		puts("JTAG_MODE\n");
 		mode = "pxe dhcp";
-		env_set("modeboot", "jtagboot");
+		env_set(ctx_uboot, "modeboot", "jtagboot");
 		break;
 	case QSPI_MODE_24BIT:
 	case QSPI_MODE_32BIT:
 		mode = "qspi0";
 		puts("QSPI_MODE\n");
-		env_set("modeboot", "qspiboot");
+		env_set(ctx_uboot, "modeboot", "qspiboot");
 		break;
 	case EMMC_MODE:
 		puts("EMMC_MODE\n");
 		mode = "mmc0";
-		env_set("modeboot", "emmcboot");
+		env_set(ctx_uboot, "modeboot", "emmcboot");
 		break;
 	case SD_MODE:
 		puts("SD_MODE\n");
@@ -589,7 +589,7 @@ int board_late_init(void)
 
 		mode = "mmc";
 		bootseq = dev->seq;
-		env_set("modeboot", "sdboot");
+		env_set(ctx_uboot, "modeboot", "sdboot");
 		break;
 	case SD1_LSHFT_MODE:
 		puts("LVL_SHFT_");
@@ -607,12 +607,12 @@ int board_late_init(void)
 
 		mode = "mmc";
 		bootseq = dev->seq;
-		env_set("modeboot", "sdboot");
+		env_set(ctx_uboot, "modeboot", "sdboot");
 		break;
 	case NAND_MODE:
 		puts("NAND_MODE\n");
 		mode = "nand0";
-		env_set("modeboot", "nandboot");
+		env_set(ctx_uboot, "modeboot", "nandboot");
 		break;
 	default:
 		mode = "";
@@ -629,7 +629,7 @@ int board_late_init(void)
 	 * One terminating char + one byte for space between mode
 	 * and default boot_targets
 	 */
-	env_targets = env_get("boot_targets");
+	env_targets = env_get(ctx_uboot, "boot_targets");
 	if (env_targets)
 		env_targets_len = strlen(env_targets);
 
@@ -645,7 +645,7 @@ int board_late_init(void)
 		sprintf(new_targets, "%s %s", mode,
 			env_targets ? env_targets : "");
 
-	env_set("boot_targets", new_targets);
+	env_set(ctx_uboot, "boot_targets", new_targets);
 
 	reset_reason();
 
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 10/19] cmd: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (8 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 09/19] board: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 11/19] common: " AKASHI Takahiro
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 cmd/ab_select.c  |  2 +-
 cmd/avb.c        |  2 +-
 cmd/bdinfo.c     |  6 +++---
 cmd/binop.c      |  4 ++--
 cmd/bootefi.c    |  8 ++++----
 cmd/bootm.c      |  4 ++--
 cmd/bootmenu.c   |  6 +++---
 cmd/cbfs.c       |  2 +-
 cmd/cramfs.c     |  8 ++++----
 cmd/dtimg.c      |  2 +-
 cmd/elf.c        | 29 ++++++++++++++++-------------
 cmd/fdt.c        | 22 +++++++++++-----------
 cmd/fpga.c       |  4 ++--
 cmd/gpt.c        |  8 ++++----
 cmd/ini.c        |  6 +++---
 cmd/itest.c      |  2 +-
 cmd/jffs2.c      |  4 ++--
 cmd/load.c       | 10 +++++-----
 cmd/lzmadec.c    |  2 +-
 cmd/md5sum.c     |  4 ++--
 cmd/mtdparts.c   | 41 +++++++++++++++++++++--------------------
 cmd/mvebu/bubt.c |  2 +-
 cmd/nand.c       | 12 ++++++------
 cmd/net.c        | 46 ++++++++++++++++++++++++----------------------
 cmd/part.c       |  6 +++---
 cmd/pxe.c        | 33 ++++++++++++++++++---------------
 cmd/qfw.c        |  6 +++---
 cmd/reiser.c     |  8 ++++----
 cmd/setexpr.c    |  8 ++++----
 cmd/spl.c        |  5 +++--
 cmd/ti/ddr3.c    |  2 +-
 cmd/tpm-common.c |  2 +-
 cmd/tpm-v1.c     |  2 +-
 cmd/trace.c      | 18 +++++++++---------
 cmd/ubi.c        |  2 +-
 cmd/unzip.c      |  2 +-
 cmd/ximg.c       |  4 ++--
 cmd/zfs.c        |  6 +++---
 cmd/zip.c        |  2 +-
 39 files changed, 176 insertions(+), 166 deletions(-)

diff --git a/cmd/ab_select.c b/cmd/ab_select.c
index 7c8f2ee8eb3a..ff7408d7640e 100644
--- a/cmd/ab_select.c
+++ b/cmd/ab_select.c
@@ -32,7 +32,7 @@ static int do_ab_select(cmd_tbl_t *cmdtp, int flag, int argc,
 	/* Android standard slot names are 'a', 'b', ... */
 	slot[0] = BOOT_SLOT_NAME(ret);
 	slot[1] = '\0';
-	env_set(argv[1], slot);
+	env_set(ctx_uboot, argv[1], slot);
 	printf("ANDROID: Booting slot: %s\n", slot);
 	return CMD_RET_SUCCESS;
 }
diff --git a/cmd/avb.c b/cmd/avb.c
index 5bc158252b30..3cb49edbeca0 100644
--- a/cmd/avb.c
+++ b/cmd/avb.c
@@ -283,7 +283,7 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag,
 		else
 			cmdline = out_data->cmdline;
 
-		env_set(AVB_BOOTARGS, cmdline);
+		env_set(ctx_uboot, AVB_BOOTARGS, cmdline);
 
 		res = CMD_RET_SUCCESS;
 		break;
diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index ae6006f85ffa..2a4e5546a29a 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -28,7 +28,7 @@ static void print_eth(int idx)
 		sprintf(name, "eth%iaddr", idx);
 	else
 		strcpy(name, "ethaddr");
-	val = env_get(name);
+	val = env_get(ctx_uboot, name);
 	if (!val)
 		val = "(not set)";
 	printf("%-12s= %s\n", name, val);
@@ -51,7 +51,7 @@ static void print_eths(void)
 	} while (dev);
 
 	printf("current eth = %s\n", eth_get_name());
-	printf("ip_addr     = %s\n", env_get("ipaddr"));
+	printf("ip_addr     = %s\n", env_get(ctx_uboot, "ipaddr"));
 }
 #endif
 
@@ -141,7 +141,7 @@ static inline void print_eth_ip_addr(void)
 #if defined(CONFIG_HAS_ETH5)
 	print_eth(5);
 #endif
-	printf("IP addr     = %s\n", env_get("ipaddr"));
+	printf("IP addr     = %s\n", env_get(ctx_uboot, "ipaddr"));
 #endif
 }
 
diff --git a/cmd/binop.c b/cmd/binop.c
index 6d2df5f3dd4f..16dbb3f50649 100644
--- a/cmd/binop.c
+++ b/cmd/binop.c
@@ -28,7 +28,7 @@ void write_to_env_var(char *varname, u8 *result, ulong len)
 		str_ptr += 2;
 	}
 	*str_ptr = '\0';
-	env_set(varname, str_output);
+	env_set(ctx_uboot, varname, str_output);
 
 	free(str_output);
 }
@@ -37,7 +37,7 @@ void read_from_env_var(char *varname, u8 *result)
 {
 	char *str_value;
 
-	str_value = env_get(varname);
+	str_value = env_get(ctx_uboot, varname);
 	if (str_value)
 		hex2bin(result, str_value, strlen(str_value) / 2);
 	else
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index f613cce7e262..f014c234b380 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -36,7 +36,7 @@ static efi_status_t set_load_options(efi_handle_t handle, const char *env_var)
 {
 	struct efi_loaded_image *loaded_image_info;
 	size_t size;
-	const char *env = env_get(env_var);
+	const char *env = env_get(ctx_uboot, env_var);
 	u16 *pos;
 	efi_status_t ret;
 
@@ -234,7 +234,7 @@ static efi_status_t efi_install_fdt(const char *fdt_opt)
 		if (get_config_table(&efi_guid_fdt))
 			return EFI_SUCCESS;
 		/* Use our own device tree as default */
-		fdt_opt = env_get("fdtcontroladdr");
+		fdt_opt = env_get(ctx_uboot, "fdtcontroladdr");
 		if (!fdt_opt) {
 			printf("ERROR: need device tree\n");
 			return EFI_NOT_FOUND;
@@ -366,7 +366,7 @@ static int do_bootefi_image(const char *image_opt)
 	if (!strcmp(image_opt, "hello")) {
 		char *saddr;
 
-		saddr = env_get("loadaddr");
+		saddr = env_get(ctx_uboot, "loadaddr");
 		size = __efi_helloworld_end - __efi_helloworld_begin;
 
 		if (saddr)
@@ -382,7 +382,7 @@ static int do_bootefi_image(const char *image_opt)
 	} else
 #endif
 	{
-		size_str = env_get("filesize");
+		size_str = env_get(ctx_uboot, "filesize");
 		if (size_str)
 			size = simple_strtoul(size_str, NULL, 16);
 		else
diff --git a/cmd/bootm.c b/cmd/bootm.c
index 8279f2b7cc63..46ee8ddbcb95 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -137,7 +137,7 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
 {
-	const char *ep = env_get("autostart");
+	const char *ep = env_get(ctx_uboot, "autostart");
 
 	if (ep && !strcmp(ep, "yes")) {
 		char *local_args[2];
@@ -201,7 +201,7 @@ U_BOOT_CMD(
 #if defined(CONFIG_CMD_BOOTD)
 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	return run_command(env_get("bootcmd"), flag);
+	return run_command(env_get(ctx_uboot, "bootcmd"), flag);
 }
 
 U_BOOT_CMD(
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 3dc2c854aca5..cc5368f090f0 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -53,7 +53,7 @@ static char *bootmenu_getoption(unsigned short int n)
 		return NULL;
 
 	sprintf(name, "bootmenu_%d", n);
-	return env_get(name);
+	return env_get(ctx_uboot, name);
 }
 
 static void bootmenu_print_entry(void *data)
@@ -265,7 +265,7 @@ static struct bootmenu_data *bootmenu_create(int delay)
 	menu->active = 0;
 	menu->first = NULL;
 
-	default_str = env_get("bootmenu_default");
+	default_str = env_get(ctx_uboot, "bootmenu_default");
 	if (default_str)
 		menu->active = (int)simple_strtol(default_str, NULL, 10);
 
@@ -494,7 +494,7 @@ int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 		delay_str = argv[1];
 
 	if (!delay_str)
-		delay_str = env_get("bootmenu_delay");
+		delay_str = env_get(ctx_uboot, "bootmenu_delay");
 
 	if (delay_str)
 		delay = (int)simple_strtol(delay_str, NULL, 10);
diff --git a/cmd/cbfs.c b/cmd/cbfs.c
index 98e652a4e7bf..9969284ee95f 100644
--- a/cmd/cbfs.c
+++ b/cmd/cbfs.c
@@ -80,7 +80,7 @@ static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc,
 
 	printf("\n%ld bytes read\n", size);
 
-	env_set_hex("filesize", size);
+	env_set_hex(ctx_uboot, "filesize", size);
 
 	return 0;
 }
diff --git a/cmd/cramfs.c b/cmd/cramfs.c
index 2188910b2a77..b7cb1d72ee8a 100644
--- a/cmd/cramfs.c
+++ b/cmd/cramfs.c
@@ -105,7 +105,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct mtdids id;
 
 	ulong addr;
-	addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
+	addr = simple_strtoul(env_get(ctx_uboot, "cramfsaddr"), NULL, 16);
 
 	/* hack! */
 	/* cramfs_* only supports NOR flash chips */
@@ -118,7 +118,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	part.offset = (u64)(uintptr_t) map_sysmem(addr - OFFSET_ADJUSTMENT, 0);
 
 	/* pre-set Boot file name */
-	filename = env_get("bootfile");
+	filename = env_get(ctx_uboot, "bootfile");
 	if (!filename)
 		filename = "uImage";
 
@@ -139,7 +139,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (size > 0) {
 		printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
 			size, offset);
-		env_set_hex("filesize", size);
+		env_set_hex(ctx_uboot, "filesize", size);
 	} else {
 		printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
 	}
@@ -170,7 +170,7 @@ int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct mtdids id;
 
 	ulong addr;
-	addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
+	addr = simple_strtoul(env_get(ctx_uboot, "cramfsaddr"), NULL, 16);
 
 	/* hack! */
 	/* cramfs_* only supports NOR flash chips */
diff --git a/cmd/dtimg.c b/cmd/dtimg.c
index 6c5d53cc6808..7f990368608e 100644
--- a/cmd/dtimg.c
+++ b/cmd/dtimg.c
@@ -82,7 +82,7 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd)
 		return CMD_RET_FAILURE;
 	}
 
-	env_set(argv[3], buf);
+	env_set(ctx_uboot, argv[3], buf);
 
 	return CMD_RET_SUCCESS;
 }
diff --git a/cmd/elf.c b/cmd/elf.c
index 538562fda581..aa3ca401fa21 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -275,7 +275,7 @@ int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	unsigned long addr; /* Address of the ELF image */
 	unsigned long rc; /* Return value from user code */
 	char *sload = NULL;
-	const char *ep = env_get("autostart");
+	const char *ep = env_get(ctx_uboot, "autostart");
 	int rcode = 0;
 
 	/* Consume 'bootelf' */
@@ -383,7 +383,8 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 * Get VxWorks's physical memory base address from environment,
 	 * if we don't specify it in the environment, use a default one.
 	 */
-	base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
+	base = env_get_hex(ctx_uboot, "vx_phys_mem_base",
+			   VXWORKS_PHYS_MEM_BASE);
 	data = (struct e820_entry *)(base + E820_DATA_OFFSET);
 	info = (struct e820_info *)(base + E820_INFO_OFFSET);
 
@@ -423,7 +424,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
 	 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
 	 */
-	tmp = env_get("bootaddr");
+	tmp = env_get(ctx_uboot, "bootaddr");
 	if (!tmp) {
 #ifdef CONFIG_X86
 		bootaddr = base + X86_BOOT_LINE_OFFSET;
@@ -440,9 +441,9 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 * Check to see if the bootline is defined in the 'bootargs' parameter.
 	 * If it is not defined, we may be able to construct the info.
 	 */
-	bootline = env_get("bootargs");
+	bootline = env_get(ctx_uboot, "bootargs");
 	if (!bootline) {
-		tmp = env_get("bootdev");
+		tmp = env_get(ctx_uboot, "bootdev");
 		if (tmp) {
 			strcpy(build_buf, tmp);
 			ptr = strlen(tmp);
@@ -450,7 +451,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			printf("## VxWorks boot device not specified\n");
 		}
 
-		tmp = env_get("bootfile");
+		tmp = env_get(ctx_uboot, "bootfile");
 		if (tmp)
 			ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
 		else
@@ -460,12 +461,14 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		 * The following parameters are only needed if 'bootdev'
 		 * is an ethernet device, otherwise they are optional.
 		 */
-		tmp = env_get("ipaddr");
+		tmp = env_get(ctx_uboot, "ipaddr");
 		if (tmp) {
 			ptr += sprintf(build_buf + ptr, "e=%s", tmp);
-			tmp = env_get("netmask");
+			tmp = env_get(ctx_uboot, "netmask");
 			if (tmp) {
-				u32 mask = env_get_ip("netmask").s_addr;
+				u32 mask;
+
+				mask = env_get_ip(ctx_uboot, "netmask").s_addr;
 				ptr += sprintf(build_buf + ptr,
 					       ":%08x ", ntohl(mask));
 			} else {
@@ -473,19 +476,19 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			}
 		}
 
-		tmp = env_get("serverip");
+		tmp = env_get(ctx_uboot, "serverip");
 		if (tmp)
 			ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
 
-		tmp = env_get("gatewayip");
+		tmp = env_get(ctx_uboot, "gatewayip");
 		if (tmp)
 			ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
 
-		tmp = env_get("hostname");
+		tmp = env_get(ctx_uboot, "hostname");
 		if (tmp)
 			ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
 
-		tmp = env_get("othbootargs");
+		tmp = env_get(ctx_uboot, "othbootargs");
 		if (tmp) {
 			strcpy(build_buf + ptr, tmp);
 			ptr += strlen(tmp);
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 25a6ed40d203..6a4dd6d664a0 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -43,7 +43,7 @@ void set_working_fdt_addr(ulong addr)
 
 	buf = map_sysmem(addr, 0);
 	working_fdt = buf;
-	env_set_hex("fdtaddr", addr);
+	env_set_hex(ctx_uboot, "fdtaddr", addr);
 }
 
 /*
@@ -52,12 +52,12 @@ void set_working_fdt_addr(ulong addr)
 static int fdt_value_env_set(const void *nodep, int len, const char *var)
 {
 	if (is_printable_string(nodep, len))
-		env_set(var, (void *)nodep);
+		env_set(ctx_uboot, var, (void *)nodep);
 	else if (len == 4) {
 		char buf[11];
 
 		sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
-		env_set(var, buf);
+		env_set(ctx_uboot, var, buf);
 	} else if (len%4 == 0 && len <= 20) {
 		/* Needed to print things like sha1 hashes. */
 		char buf[41];
@@ -66,7 +66,7 @@ static int fdt_value_env_set(const void *nodep, int len, const char *var)
 		for (i = 0; i < len; i += sizeof(unsigned int))
 			sprintf(buf + (i * 2), "%08x",
 				*(unsigned int *)(nodep + i));
-		env_set(var, buf);
+		env_set(ctx_uboot, var, buf);
 	} else {
 		printf("error: unprintable value\n");
 		return 1;
@@ -101,7 +101,7 @@ static int fdt_get_header_value(int argc, char * const argv[])
 			continue;
 
 		val = fdt32_to_cpu(fdtp[i]);
-		env_set_hex(argv[3], val);
+		env_set_hex(ctx_uboot, argv[3], val);
 		return CMD_RET_SUCCESS;
 	}
 
@@ -145,7 +145,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				return 1;
 			printf("The address of the fdt is %#08lx\n",
 			       control ? (ulong)map_to_sysmem(blob) :
-					env_get_hex("fdtaddr", 0));
+					env_get_hex(ctx_uboot, "fdtaddr", 0));
 			return 0;
 		}
 
@@ -395,7 +395,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 					node_name = fdt_get_name(working_fdt,
 								 nextNodeOffset,
 								 NULL);
-					env_set(var, node_name);
+					env_set(ctx_uboot, var, node_name);
 					return 0;
 				}
 				nextNodeOffset = fdt_next_node(
@@ -405,7 +405,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			}
 			if (subcmd[0] == 's') {
 				/* get the num nodes@this level */
-				env_set_ulong(var, curIndex + 1);
+				env_set_ulong(ctx_uboot, var, curIndex + 1);
 			} else {
 				/* node index not found */
 				printf("libfdt node not found\n");
@@ -416,7 +416,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				working_fdt, nodeoffset, prop, &len);
 			if (len == 0) {
 				/* no property value */
-				env_set(var, "");
+				env_set(ctx_uboot, var, "");
 				return 0;
 			} else if (nodep && len > 0) {
 				if (subcmd[0] == 'v') {
@@ -431,13 +431,13 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 					char buf[11];
 
 					sprintf(buf, "0x%p", nodep);
-					env_set(var, buf);
+					env_set(ctx_uboot, var, buf);
 				} else if (subcmd[0] == 's') {
 					/* Get size */
 					char buf[11];
 
 					sprintf(buf, "0x%08X", len);
-					env_set(var, buf);
+					env_set(ctx_uboot, var, buf);
 				} else
 					return CMD_RET_USAGE;
 				return 0;
diff --git a/cmd/fpga.c b/cmd/fpga.c
index b1c7b5453b3b..caa86dfdb298 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -18,7 +18,7 @@
 static long do_fpga_get_device(char *arg)
 {
 	long dev = FPGA_INVALID_DEVICE;
-	char *devstr = env_get("fpga");
+	char *devstr = env_get(ctx_uboot, "fpga");
 
 	if (devstr)
 		/* Should be strtol to handle -1 cases */
@@ -239,7 +239,7 @@ static int do_fpga_loadmk(cmd_tbl_t *cmdtp, int flag, int argc,
 	ulong fit_addr;
 #endif
 	ulong dev = do_fpga_get_device(argv[0]);
-	char *datastr = env_get("fpgadata");
+	char *datastr = env_get(ctx_uboot, "fpgadata");
 
 	debug("fpga: argc %x, dev %lx, datastr %s\n", argc, dev, datastr);
 
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 0c4349f4b249..c8c5a32e87a5 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -55,14 +55,14 @@ static int extract_env(const char *str, char **env)
 	memset(s + strlen(s) - 1, '\0', 1);
 	memmove(s, s + 2, strlen(s) - 1);
 
-	e = env_get(s);
+	e = env_get(ctx_uboot, s);
 	if (e == NULL) {
 #ifdef CONFIG_RANDOM_UUID
 		debug("%s unset. ", str);
 		gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_GUID);
-		env_set(s, uuid_str);
+		env_set(ctx_uboot, s, uuid_str);
 
-		e = env_get(s);
+		e = env_get(ctx_uboot, s);
 		if (e) {
 			debug("Set to random.\n");
 			ret = 0;
@@ -625,7 +625,7 @@ static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
 		return CMD_RET_FAILURE;
 
 	if (namestr)
-		env_set(namestr, disk_guid);
+		env_set(ctx_uboot, namestr, disk_guid);
 	else
 		printf("%s\n", disk_guid);
 
diff --git a/cmd/ini.c b/cmd/ini.c
index 0c425262d0e7..4cecaca09560 100644
--- a/cmd/ini.c
+++ b/cmd/ini.c
@@ -218,7 +218,7 @@ static int ini_handler(void *user, char *section, char *name, char *value)
 		for (i = 0; i < strlen(value); i++)
 			value[i] = tolower(value[i]);
 #endif
-		env_set(name, value);
+		env_set(ctx_uboot, name, value);
 		printf("ini: Imported %s as %s\n", name, value);
 	}
 
@@ -237,9 +237,9 @@ static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	section = argv[1];
 	file_address = (char *)simple_strtoul(
-		argc < 3 ? env_get("loadaddr") : argv[2], NULL, 16);
+		argc < 3 ? env_get(ctx_uboot, "loadaddr") : argv[2], NULL, 16);
 	file_size = (size_t)simple_strtoul(
-		argc < 4 ? env_get("filesize") : argv[3], NULL, 16);
+		argc < 4 ? env_get(ctx_uboot, "filesize") : argv[3], NULL, 16);
 
 	return ini_parse(file_address, file_size, ini_handler, (void *)section);
 }
diff --git a/cmd/itest.c b/cmd/itest.c
index 8b630d71e62d..7ffeea01ba79 100644
--- a/cmd/itest.c
+++ b/cmd/itest.c
@@ -101,7 +101,7 @@ static char * evalstr(char *s)
 			i++;
 		}
 		s[i] = 0;
-		return  env_get((const char *)&s[2]);
+		return  env_get(ctx_uboot, (const char *)&s[2]);
 	} else {
 		return s;
 	}
diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index b47cd3d98930..af9af57d4c12 100644
--- a/cmd/jffs2.c
+++ b/cmd/jffs2.c
@@ -479,7 +479,7 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ulong offset = load_addr;
 
 	/* pre-set Boot file name */
-	filename = env_get("bootfile");
+	filename = env_get(ctx_uboot, "bootfile");
 	if (!filename)
 		filename = "uImage";
 
@@ -512,7 +512,7 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (size > 0) {
 			printf("### %s load complete: %d bytes loaded to 0x%lx\n",
 				fsname, size, offset);
-			env_set_hex("filesize", size);
+			env_set_hex(ctx_uboot, "filesize", size);
 		} else {
 			printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
 		}
diff --git a/cmd/load.c b/cmd/load.c
index 713fe56b5557..7770311d314f 100644
--- a/cmd/load.c
+++ b/cmd/load.c
@@ -50,7 +50,7 @@ static int do_load_serial(cmd_tbl_t *cmdtp, int flag, int argc,
 	load_baudrate = current_baudrate = gd->baudrate;
 #endif
 
-	env_echo = env_get("loads_echo");
+	env_echo = env_get(ctx_uboot, "loads_echo");
 	if (env_echo && *env_echo == '1')
 		do_echo = 1;
 	else
@@ -182,7 +182,7 @@ static ulong load_serial(long offset)
 			    start_addr, end_addr, size, size
 		    );
 		    flush_cache(start_addr, size);
-		    env_set_hex("filesize", size);
+		    env_set_hex(ctx_uboot, "filesize", size);
 		    return (addr);
 		case SREC_START:
 		    break;
@@ -427,7 +427,7 @@ static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc,
 	offset = CONFIG_SYS_LOAD_ADDR;
 
 	/* pre-set offset from $loadaddr */
-	s = env_get("loadaddr");
+	s = env_get(ctx_uboot, "loadaddr");
 	if (s)
 		offset = simple_strtoul(s, NULL, 16);
 
@@ -529,7 +529,7 @@ static ulong load_serial_bin(ulong offset)
 	flush_cache(offset, size);
 
 	printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-	env_set_hex("filesize", size);
+	env_set_hex(ctx_uboot, "filesize", size);
 
 	return offset;
 }
@@ -1000,7 +1000,7 @@ static ulong load_serial_ymodem(ulong offset, int mode)
 	flush_cache(offset, ALIGN(size, ARCH_DMA_MINALIGN));
 
 	printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-	env_set_hex("filesize", size);
+	env_set_hex(ctx_uboot, "filesize", size);
 
 	return offset;
 }
diff --git a/cmd/lzmadec.c b/cmd/lzmadec.c
index e3b9cc75ac2b..2c9c2fe52d33 100644
--- a/cmd/lzmadec.c
+++ b/cmd/lzmadec.c
@@ -42,7 +42,7 @@ static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 		return 1;
 	printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len,
 	       (ulong)src_len);
-	env_set_hex("filesize", src_len);
+	env_set_hex(ctx_uboot, "filesize", src_len);
 
 	return 0;
 }
diff --git a/cmd/md5sum.c b/cmd/md5sum.c
index 63cbae0364c1..b1ffb298de55 100644
--- a/cmd/md5sum.c
+++ b/cmd/md5sum.c
@@ -35,7 +35,7 @@ static void store_result(const u8 *sum, const char *dest)
 			sprintf(str_ptr, "%02x", sum[i]);
 			str_ptr += 2;
 		}
-		env_set(dest, str_output);
+		env_set(ctx_uboot, dest, str_output);
 	}
 }
 
@@ -54,7 +54,7 @@ static int parse_verify_sum(char *verify_str, u8 *vsum)
 		if (strlen(verify_str) == 32)
 			vsum_str = verify_str;
 		else {
-			vsum_str = env_get(verify_str);
+			vsum_str = env_get(ctx_uboot, verify_str);
 			if (vsum_str == NULL || strlen(vsum_str) != 32)
 				return 1;
 		}
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 46155cabf66c..9f5f9f09f6f7 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -242,7 +242,8 @@ static void index_partitions(void)
 			dev = list_entry(dentry, struct mtd_device, link);
 			if (dev == current_mtd_dev) {
 				mtddevnum += current_mtd_partnum;
-				env_set_ulong("mtddevnum", mtddevnum);
+				env_set_ulong(ctx_uboot, "mtddevnum",
+					      mtddevnum);
 				debug("=> mtddevnum %d,\n", mtddevnum);
 				break;
 			}
@@ -251,17 +252,17 @@ static void index_partitions(void)
 
 		part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
 		if (part) {
-			env_set("mtddevname", part->name);
+			env_set(ctx_uboot, "mtddevname", part->name);
 
 			debug("=> mtddevname %s\n", part->name);
 		} else {
-			env_set("mtddevname", NULL);
+			env_set(ctx_uboot, "mtddevname", NULL);
 
 			debug("=> mtddevname NULL\n");
 		}
 	} else {
-		env_set("mtddevnum", NULL);
-		env_set("mtddevname", NULL);
+		env_set(ctx_uboot, "mtddevnum", NULL);
+		env_set(ctx_uboot, "mtddevname", NULL);
 
 		debug("=> mtddevnum NULL\n=> mtddevname NULL\n");
 	}
@@ -280,12 +281,12 @@ static void current_save(void)
 		sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type),
 					current_mtd_dev->id->num, current_mtd_partnum);
 
-		env_set("partition", buf);
+		env_set(ctx_uboot, "partition", buf);
 		strncpy(last_partition, buf, 16);
 
 		debug("=> partition %s\n", buf);
 	} else {
-		env_set("partition", NULL);
+		env_set(ctx_uboot, "partition", NULL);
 		last_partition[0] = '\0';
 
 		debug("=> partition NULL\n");
@@ -1214,9 +1215,9 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
 	ret = generate_mtdparts(buf, buflen);
 
 	if ((buf[0] != '\0') && (ret == 0))
-		env_set("mtdparts", buf);
+		env_set(ctx_uboot, "mtdparts", buf);
 	else
-		env_set("mtdparts", NULL);
+		env_set(ctx_uboot, "mtdparts", NULL);
 
 	return ret;
 }
@@ -1537,8 +1538,8 @@ static int spread_partitions(void)
 static const char *env_get_mtdparts(char *buf)
 {
 	if (gd->flags & GD_FLG_ENV_READY)
-		return env_get("mtdparts");
-	if (env_get_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1)
+		return env_get(ctx_uboot, "mtdparts");
+	if (env_get_f(ctx_uboot, "mtdparts", buf, MTDPARTS_MAXLEN) != -1)
 		return buf;
 	return NULL;
 }
@@ -1742,9 +1743,9 @@ int mtdparts_init(void)
 	}
 
 	/* get variables */
-	ids = env_get("mtdids");
+	ids = env_get(ctx_uboot, "mtdids");
 	parts = env_get_mtdparts(tmp_parts);
-	current_partition = env_get("partition");
+	current_partition = env_get(ctx_uboot, "partition");
 
 	/* save it for later parsing, cannot rely on current partition pointer
 	 * as 'partition' variable may be updated during init */
@@ -1766,7 +1767,7 @@ int mtdparts_init(void)
 		if (mtdids_default) {
 			debug("mtdids variable not defined, using default\n");
 			ids = mtdids_default;
-			env_set("mtdids", (char *)ids);
+			env_set(ctx_uboot, "mtdids", (char *)ids);
 		} else {
 			printf("mtdids not defined, no default present\n");
 			return 1;
@@ -1782,7 +1783,7 @@ int mtdparts_init(void)
 	if (!parts) {
 		if (mtdparts_default && use_defaults) {
 			parts = mtdparts_default;
-			if (env_set("mtdparts", (char *)parts) == 0)
+			if (env_set(ctx_uboot, "mtdparts", (char *)parts) == 0)
 				use_defaults = 0;
 		} else
 			printf("mtdparts variable not set, see 'help mtdparts'\n");
@@ -1852,7 +1853,7 @@ int mtdparts_init(void)
 			current_mtd_partnum = pnum;
 			current_save();
 		}
-	} else if (env_get("partition") == NULL) {
+	} else if (!env_get(ctx_uboot, "partition")) {
 		debug("no partition variable set, setting...\n");
 		current_save();
 	}
@@ -1958,9 +1959,9 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
 {
 	if (argc == 2) {
 		if (strcmp(argv[1], "default") == 0) {
-			env_set("mtdids", NULL);
-			env_set("mtdparts", NULL);
-			env_set("partition", NULL);
+			env_set(ctx_uboot, "mtdids", NULL);
+			env_set(ctx_uboot, "mtdparts", NULL);
+			env_set(ctx_uboot, "partition", NULL);
 			use_defaults = 1;
 
 			mtdparts_init();
@@ -1969,7 +1970,7 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
 			/* this may be the first run, initialize lists if needed */
 			mtdparts_init();
 
-			env_set("mtdparts", NULL);
+			env_set(ctx_uboot, "mtdparts", NULL);
 
 			/* mtd_devices_init() calls current_save() */
 			return mtd_devices_init();
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 84d2d531f0d4..c7fc3a7ef4e4 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -98,7 +98,7 @@ static ulong get_load_addr(void)
 	const char *addr_str;
 	unsigned long addr;
 
-	addr_str = env_get("loadaddr");
+	addr_str = env_get(ctx_uboot, "loadaddr");
 	if (addr_str)
 		addr = simple_strtoul(addr_str, NULL, 16);
 	else
diff --git a/cmd/nand.c b/cmd/nand.c
index 27efef20bc95..ba9c1071f5b5 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -306,9 +306,9 @@ static void nand_print_and_set_info(int idx)
 	printf("  bbt options 0x%08x\n", chip->bbt_options);
 
 	/* Set geometry info */
-	env_set_hex("nand_writesize", mtd->writesize);
-	env_set_hex("nand_oobsize", mtd->oobsize);
-	env_set_hex("nand_erasesize", mtd->erasesize);
+	env_set_hex(ctx_uboot, "nand_writesize", mtd->writesize);
+	env_set_hex(ctx_uboot, "nand_oobsize", mtd->oobsize);
+	env_set_hex(ctx_uboot, "nand_erasesize", mtd->erasesize);
 }
 
 static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
@@ -384,7 +384,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #else
 	int quiet = 0;
 #endif
-	const char *quiet_str = env_get("quiet");
+	const char *quiet_str = env_get(ctx_uboot, "quiet");
 	int dev = nand_curr_device;
 	int repeat = flag & CMD_FLAG_REPEAT;
 
@@ -967,11 +967,11 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
 	switch (argc) {
 	case 1:
 		addr = CONFIG_SYS_LOAD_ADDR;
-		boot_device = env_get("bootdevice");
+		boot_device = env_get(ctx_uboot, "bootdevice");
 		break;
 	case 2:
 		addr = simple_strtoul(argv[1], NULL, 16);
-		boot_device = env_get("bootdevice");
+		boot_device = env_get(ctx_uboot, "bootdevice");
 		break;
 	case 3:
 		addr = simple_strtoul(argv[1], NULL, 16);
diff --git a/cmd/net.c b/cmd/net.c
index 237403977e80..25b347077d7c 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -120,23 +120,23 @@ static void netboot_update_env(void)
 
 	if (net_gateway.s_addr) {
 		ip_to_string(net_gateway, tmp);
-		env_set("gatewayip", tmp);
+		env_set(ctx_uboot, "gatewayip", tmp);
 	}
 
 	if (net_netmask.s_addr) {
 		ip_to_string(net_netmask, tmp);
-		env_set("netmask", tmp);
+		env_set(ctx_uboot, "netmask", tmp);
 	}
 
 	if (net_hostname[0])
-		env_set("hostname", net_hostname);
+		env_set(ctx_uboot, "hostname", net_hostname);
 
 	if (net_root_path[0])
-		env_set("rootpath", net_root_path);
+		env_set(ctx_uboot, "rootpath", net_root_path);
 
 	if (net_ip.s_addr) {
 		ip_to_string(net_ip, tmp);
-		env_set("ipaddr", tmp);
+		env_set(ctx_uboot, "ipaddr", tmp);
 	}
 #if !defined(CONFIG_BOOTP_SERVERIP)
 	/*
@@ -145,32 +145,32 @@ static void netboot_update_env(void)
 	 */
 	if (net_server_ip.s_addr) {
 		ip_to_string(net_server_ip, tmp);
-		env_set("serverip", tmp);
+		env_set(ctx_uboot, "serverip", tmp);
 	}
 #endif
 	if (net_dns_server.s_addr) {
 		ip_to_string(net_dns_server, tmp);
-		env_set("dnsip", tmp);
+		env_set(ctx_uboot, "dnsip", tmp);
 	}
 #if defined(CONFIG_BOOTP_DNS2)
 	if (net_dns_server2.s_addr) {
 		ip_to_string(net_dns_server2, tmp);
-		env_set("dnsip2", tmp);
+		env_set(ctx_uboot, "dnsip2", tmp);
 	}
 #endif
 	if (net_nis_domain[0])
-		env_set("domain", net_nis_domain);
+		env_set(ctx_uboot, "domain", net_nis_domain);
 
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
 	if (net_ntp_time_offset) {
 		sprintf(tmp, "%d", net_ntp_time_offset);
-		env_set("timeoffset", tmp);
+		env_set(ctx_uboot, "timeoffset", tmp);
 	}
 #endif
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
 	if (net_ntp_server.s_addr) {
 		ip_to_string(net_ntp_server, tmp);
-		env_set("ntpserverip", tmp);
+		env_set(ctx_uboot, "ntpserverip", tmp);
 	}
 #endif
 }
@@ -187,14 +187,15 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
 	net_boot_file_name_explicit = false;
 
 	/* pre-set load_addr */
-	s = env_get("loadaddr");
+	s = env_get(ctx_uboot, "loadaddr");
 	if (s != NULL)
 		load_addr = simple_strtoul(s, NULL, 16);
 
 	switch (argc) {
 	case 1:
 		/* refresh bootfile name from env */
-		copy_filename(net_boot_file_name, env_get("bootfile"),
+		copy_filename(net_boot_file_name, env_get(ctx_uboot,
+							  "bootfile"),
 			      sizeof(net_boot_file_name));
 		break;
 
@@ -208,7 +209,8 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
 		if (end == (argv[1] + strlen(argv[1]))) {
 			load_addr = addr;
 			/* refresh bootfile name from env */
-			copy_filename(net_boot_file_name, env_get("bootfile"),
+			copy_filename(net_boot_file_name,
+				      env_get(ctx_uboot, "bootfile"),
 				      sizeof(net_boot_file_name));
 		} else {
 			net_boot_file_name_explicit = true;
@@ -307,14 +309,14 @@ static void cdp_update_env(void)
 		printf("CDP offered appliance VLAN %d\n",
 		       ntohs(cdp_appliance_vlan));
 		vlan_to_string(cdp_appliance_vlan, tmp);
-		env_set("vlan", tmp);
+		env_set(ctx_uboot, "vlan", tmp);
 		net_our_vlan = cdp_appliance_vlan;
 	}
 
 	if (cdp_native_vlan != htons(-1)) {
 		printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
 		vlan_to_string(cdp_native_vlan, tmp);
-		env_set("nvlan", tmp);
+		env_set(ctx_uboot, "nvlan", tmp);
 		net_native_vlan = cdp_native_vlan;
 	}
 }
@@ -347,7 +349,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	char *toff;
 
 	if (argc < 2) {
-		net_ntp_server = env_get_ip("ntpserverip");
+		net_ntp_server = env_get_ip(ctx_uboot, "ntpserverip");
 		if (net_ntp_server.s_addr == 0) {
 			printf("ntpserverip not set\n");
 			return CMD_RET_FAILURE;
@@ -360,7 +362,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		}
 	}
 
-	toff = env_get("timeoffset");
+	toff = env_get(ctx_uboot, "timeoffset");
 	if (toff == NULL)
 		net_ntp_time_offset = 0;
 	else
@@ -439,14 +441,14 @@ static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
 
 	net_gateway.s_addr = 0;
 	ip_to_string(net_gateway, tmp);
-	env_set("gatewayip", tmp);
+	env_set(ctx_uboot, "gatewayip", tmp);
 
 	ip_to_string(net_netmask, tmp);
-	env_set("netmask", tmp);
+	env_set(ctx_uboot, "netmask", tmp);
 
 	ip_to_string(net_ip, tmp);
-	env_set("ipaddr", tmp);
-	env_set("llipaddr", tmp); /* store this for next time */
+	env_set(ctx_uboot, "ipaddr", tmp);
+	env_set(ctx_uboot, "llipaddr", tmp); /* store this for next time */
 
 	return CMD_RET_SUCCESS;
 }
diff --git a/cmd/part.c b/cmd/part.c
index 6cfb67b27959..eb1b782901bf 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -44,7 +44,7 @@ static int do_part_uuid(int argc, char * const argv[])
 		return 1;
 
 	if (argc > 2)
-		env_set(argv[2], info.uuid);
+		env_set(ctx_uboot, argv[2], info.uuid);
 	else
 		printf("%s\n", info.uuid);
 
@@ -105,7 +105,7 @@ static int do_part_list(int argc, char * const argv[])
 			sprintf(t, "%s%x", str[0] ? " " : "", p);
 			strcat(str, t);
 		}
-		env_set(var, str);
+		env_set(ctx_uboot, var, str);
 		return 0;
 	}
 
@@ -160,7 +160,7 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
 	}
 
 	if (argc > 3)
-		env_set(argv[3], buf);
+		env_set(ctx_uboot, argv[3], buf);
 	else
 		printf("%s\n", buf);
 
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 205997544623..e26162d01dc8 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -46,7 +46,7 @@ static char *from_env(const char *envvar)
 {
 	char *ret;
 
-	ret = env_get(envvar);
+	ret = env_get(ctx_uboot, envvar);
 
 	if (!ret)
 		printf("missing environment variable: %s\n", envvar);
@@ -601,7 +601,7 @@ static int label_localboot(struct pxe_label *label)
 		char bootargs[CONFIG_SYS_CBSIZE];
 
 		cli_simple_process_macros(label->append, bootargs);
-		env_set("bootargs", bootargs);
+		env_set(ctx_uboot, "bootargs", bootargs);
 	}
 
 	debug("running: %s\n", localcmd);
@@ -660,9 +660,10 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 		}
 
 		bootm_argv[2] = initrd_str;
-		strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
+		strncpy(bootm_argv[2], env_get(ctx_uboot, "ramdisk_addr_r"),
+			18);
 		strcat(bootm_argv[2], ":");
-		strncat(bootm_argv[2], env_get("filesize"), 9);
+		strncat(bootm_argv[2], env_get(ctx_uboot, "filesize"), 9);
 	}
 
 	if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
@@ -673,8 +674,10 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 
 	if (label->ipappend & 0x1) {
 		sprintf(ip_str, " ip=%s:%s:%s:%s",
-			env_get("ipaddr"), env_get("serverip"),
-			env_get("gatewayip"), env_get("netmask"));
+			env_get(ctx_uboot, "ipaddr"),
+			env_get(ctx_uboot, "serverip"),
+			env_get(ctx_uboot, "gatewayip"),
+			env_get(ctx_uboot, "netmask"));
 	}
 
 #ifdef CONFIG_CMD_NET
@@ -706,12 +709,12 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 			strcat(bootargs, mac_str);
 
 			cli_simple_process_macros(bootargs, finalbootargs);
-			env_set("bootargs", finalbootargs);
+			env_set(ctx_uboot, "bootargs", finalbootargs);
 			printf("append: %s\n", finalbootargs);
 		}
 	}
 
-	bootm_argv[1] = env_get("kernel_addr_r");
+	bootm_argv[1] = env_get(ctx_uboot, "kernel_addr_r");
 	/* for FIT, append the configuration identifier */
 	if (label->config) {
 		int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
@@ -738,7 +741,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 	 *
 	 * Scenario 3: fdt blob is not available.
 	 */
-	bootm_argv[3] = env_get("fdt_addr_r");
+	bootm_argv[3] = env_get(ctx_uboot, "fdt_addr_r");
 
 	/* if fdt label is defined then get fdt from server */
 	if (bootm_argv[3]) {
@@ -750,7 +753,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 		} else if (label->fdtdir) {
 			char *f1, *f2, *f3, *f4, *slash;
 
-			f1 = env_get("fdtfile");
+			f1 = env_get(ctx_uboot, "fdtfile");
 			if (f1) {
 				f2 = "";
 				f3 = "";
@@ -763,9 +766,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 				 * or the boot scripts should set $fdtfile
 				 * before invoking "pxe" or "sysboot".
 				 */
-				f1 = env_get("soc");
+				f1 = env_get(ctx_uboot, "soc");
 				f2 = "-";
-				f3 = env_get("board");
+				f3 = env_get(ctx_uboot, "board");
 				f4 = ".dtb";
 			}
 
@@ -805,7 +808,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 	}
 
 	if (!bootm_argv[3])
-		bootm_argv[3] = env_get("fdt_addr");
+		bootm_argv[3] = env_get(ctx_uboot, "fdt_addr");
 
 	if (bootm_argv[3]) {
 		if (!bootm_argv[2])
@@ -1746,10 +1749,10 @@ static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	if (argc < 6)
-		filename = env_get("bootfile");
+		filename = env_get(ctx_uboot, "bootfile");
 	else {
 		filename = argv[5];
-		env_set("bootfile", filename);
+		env_set(ctx_uboot, "bootfile", filename);
 	}
 
 	if (strstr(argv[3], "ext2"))
diff --git a/cmd/qfw.c b/cmd/qfw.c
index af826627a217..0063590fe496 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -55,7 +55,7 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr)
 		 * when invoking qemu), do not update bootargs
 		 */
 		if (*data_addr != '\0') {
-			if (env_set("bootargs", data_addr) < 0)
+			if (env_set(ctx_uboot, "bootargs", data_addr) < 0)
 				printf("warning: unable to change bootargs\n");
 		}
 	}
@@ -123,7 +123,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
 	void *load_addr;
 	void *initrd_addr;
 
-	env = env_get("loadaddr");
+	env = env_get(ctx_uboot, "loadaddr");
 	load_addr = env ?
 		(void *)simple_strtoul(env, NULL, 16) :
 #ifdef CONFIG_LOADADDR
@@ -132,7 +132,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
 		NULL;
 #endif
 
-	env = env_get("ramdiskaddr");
+	env = env_get(ctx_uboot, "ramdiskaddr");
 	initrd_addr = env ?
 		(void *)simple_strtoul(env, NULL, 16) :
 #ifdef CONFIG_RAMDISK_ADDR
diff --git a/cmd/reiser.c b/cmd/reiser.c
index 7f51b927a475..af2100558982 100644
--- a/cmd/reiser.c
+++ b/cmd/reiser.c
@@ -88,18 +88,18 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	switch (argc) {
 	case 3:
-		addr_str = env_get("loadaddr");
+		addr_str = env_get(ctx_uboot, "loadaddr");
 		if (addr_str != NULL) {
 			addr = simple_strtoul (addr_str, NULL, 16);
 		} else {
 			addr = CONFIG_SYS_LOAD_ADDR;
 		}
-		filename = env_get("bootfile");
+		filename = env_get(ctx_uboot, "bootfile");
 		count = 0;
 		break;
 	case 4:
 		addr = simple_strtoul (argv[3], NULL, 16);
-		filename = env_get("bootfile");
+		filename = env_get(ctx_uboot, "bootfile");
 		count = 0;
 		break;
 	case 5:
@@ -157,7 +157,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	load_addr = addr;
 
 	printf ("\n%ld bytes read\n", filelen);
-	env_set_hex("filesize", filelen);
+	env_set_hex(ctx_uboot, "filesize", filelen);
 
 	return filelen;
 }
diff --git a/cmd/setexpr.c b/cmd/setexpr.c
index 0182f1993846..206de37b6f96 100644
--- a/cmd/setexpr.c
+++ b/cmd/setexpr.c
@@ -145,7 +145,7 @@ static int regex_sub(const char *name,
 	}
 
 	if (t == NULL) {
-		value = env_get(name);
+		value = env_get(ctx_uboot, name);
 
 		if (value == NULL) {
 			printf("## Error: variable \"%s\" not defined\n", name);
@@ -286,7 +286,7 @@ static int regex_sub(const char *name,
 
 	printf("%s=%s\n", name, data);
 
-	return env_set(name, data);
+	return env_set(ctx_uboot, name, data);
 }
 #endif
 
@@ -314,7 +314,7 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	/* plain assignment: "setexpr name value" */
 	if (argc == 3) {
-		env_set_hex(argv[1], a);
+		env_set_hex(ctx_uboot, argv[1], a);
 		return 0;
 	}
 
@@ -370,7 +370,7 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 	}
 
-	env_set_hex(argv[1], value);
+	env_set_hex(ctx_uboot, argv[1], value);
 
 	return 0;
 }
diff --git a/cmd/spl.c b/cmd/spl.c
index 56051b8a4be9..a2008b3d0f37 100644
--- a/cmd/spl.c
+++ b/cmd/spl.c
@@ -119,8 +119,9 @@ static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		case SPL_EXPORT_FDT:
 			printf("Argument image is now in RAM: 0x%p\n",
 				(void *)images.ft_addr);
-			env_set_addr("fdtargsaddr", images.ft_addr);
-			env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
+			env_set_addr(ctx_uboot, "fdtargsaddr", images.ft_addr);
+			env_set_hex(ctx_uboot, "fdtargslen",
+				    fdt_totalsize(images.ft_addr));
 #ifdef CONFIG_CMD_SPL_WRITE_SIZE
 			if (fdt_totalsize(images.ft_addr) >
 			    CONFIG_CMD_SPL_WRITE_SIZE)
diff --git a/cmd/ti/ddr3.c b/cmd/ti/ddr3.c
index b82cbe152dc9..6124e4dc8c53 100644
--- a/cmd/ti/ddr3.c
+++ b/cmd/ti/ddr3.c
@@ -164,7 +164,7 @@ static void ddr_check_ecc_status(void)
 	int ecc_test = 0;
 	char *env;
 
-	env = env_get("ecc_test");
+	env = env_get(ctx_uboot, "ecc_test");
 	if (env)
 		ecc_test = simple_strtol(env, NULL, 0);
 
diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
index 38900fb1590b..1ddf77a6a07b 100644
--- a/cmd/tpm-common.c
+++ b/cmd/tpm-common.c
@@ -224,7 +224,7 @@ int type_string_write_vars(const char *type_str, u8 *data,
 		default:
 			return -1;
 		}
-		if (env_set_ulong(*vars, value))
+		if (env_set_ulong(ctx_uboot, *vars, value))
 			return -1;
 	}
 
diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
index 2807331524aa..5cb50c58f8c9 100644
--- a/cmd/tpm-v1.c
+++ b/cmd/tpm-v1.c
@@ -430,7 +430,7 @@ static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
 				 &key_handle);
 	if (!err) {
 		printf("Key handle is 0x%x\n", key_handle);
-		env_set_hex("key_handle", key_handle);
+		env_set_hex(ctx_uboot, "key_handle", key_handle);
 	}
 
 	return report_return_code(err);
diff --git a/cmd/trace.c b/cmd/trace.c
index 392b12953617..e7b982a370ef 100644
--- a/cmd/trace.c
+++ b/cmd/trace.c
@@ -16,10 +16,10 @@ static int get_args(int argc, char * const argv[], char **buff,
 	if (argc < 2)
 		return -1;
 	if (argc < 4) {
-		*buff_size = env_get_ulong("profsize", 16, 0);
-		*buff = map_sysmem(env_get_ulong("profbase", 16, 0),
+		*buff_size = env_get_ulong(ctx_uboot, "profsize", 16, 0);
+		*buff = map_sysmem(env_get_ulong(ctx_uboot, "profbase", 16, 0),
 				   *buff_size);
-		*buff_ptr = env_get_ulong("profoffset", 16, 0);
+		*buff_ptr = env_get_ulong(ctx_uboot, "profoffset", 16, 0);
 	} else {
 		*buff_size = simple_strtoul(argv[3], NULL, 16);
 		*buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
@@ -45,9 +45,9 @@ static int create_func_list(int argc, char * const argv[])
 	used = min(avail, (size_t)needed);
 	printf("Function trace dumped to %08lx, size %#zx\n",
 	       (ulong)map_to_sysmem(buff + buff_ptr), used);
-	env_set_hex("profbase", map_to_sysmem(buff));
-	env_set_hex("profsize", buff_size);
-	env_set_hex("profoffset", buff_ptr + used);
+	env_set_hex(ctx_uboot, "profbase", map_to_sysmem(buff));
+	env_set_hex(ctx_uboot, "profsize", buff_size);
+	env_set_hex(ctx_uboot, "profoffset", buff_ptr + used);
 
 	return 0;
 }
@@ -69,9 +69,9 @@ static int create_call_list(int argc, char * const argv[])
 	printf("Call list dumped to %08lx, size %#zx\n",
 	       (ulong)map_to_sysmem(buff + buff_ptr), used);
 
-	env_set_hex("profbase", map_to_sysmem(buff));
-	env_set_hex("profsize", buff_size);
-	env_set_hex("profoffset", buff_ptr + used);
+	env_set_hex(ctx_uboot, "profbase", map_to_sysmem(buff));
+	env_set_hex(ctx_uboot, "profsize", buff_size);
+	env_set_hex(ctx_uboot, "profoffset", buff_ptr + used);
 
 	return 0;
 }
diff --git a/cmd/ubi.c b/cmd/ubi.c
index ca5dc9021b12..28d2c6b93af0 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -387,7 +387,7 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
 	} while (size);
 
 	if (!size)
-		env_set_hex("filesize", len_read);
+		env_set_hex(ctx_uboot, "filesize", len_read);
 
 	free(tbuf);
 	return err;
diff --git a/cmd/unzip.c b/cmd/unzip.c
index afd58e7cdb12..34347f111dc1 100644
--- a/cmd/unzip.c
+++ b/cmd/unzip.c
@@ -30,7 +30,7 @@ static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 
 	printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
-	env_set_hex("filesize", src_len);
+	env_set_hex(ctx_uboot, "filesize", src_len);
 
 	return 0;
 }
diff --git a/cmd/ximg.c b/cmd/ximg.c
index a9481004f036..1726a3978e4d 100644
--- a/cmd/ximg.c
+++ b/cmd/ximg.c
@@ -252,8 +252,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 
 	flush_cache(dest, ALIGN(len, ARCH_DMA_MINALIGN));
 
-	env_set_hex("fileaddr", data);
-	env_set_hex("filesize", len);
+	env_set_hex(ctx_uboot, "fileaddr", data);
+	env_set_hex(ctx_uboot, "filesize", len);
 
 	return 0;
 }
diff --git a/cmd/zfs.c b/cmd/zfs.c
index ed5402bb139e..2dc71bb93b44 100644
--- a/cmd/zfs.c
+++ b/cmd/zfs.c
@@ -51,10 +51,10 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 
 	count = 0;
 	addr = simple_strtoul(argv[3], NULL, 16);
-	filename = env_get("bootfile");
+	filename = env_get(ctx_uboot, "bootfile");
 	switch (argc) {
 	case 3:
-		addr_str = env_get("loadaddr");
+		addr_str = env_get(ctx_uboot, "loadaddr");
 		if (addr_str != NULL)
 			addr = simple_strtoul(addr_str, NULL, 16);
 		else
@@ -115,7 +115,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 	load_addr = addr;
 
 	printf("%llu bytes read\n", zfile.size);
-	env_set_hex("filesize", zfile.size);
+	env_set_hex(ctx_uboot, "filesize", zfile.size);
 
 	return 0;
 }
diff --git a/cmd/zip.c b/cmd/zip.c
index 8ef46e9815f7..73fed730703c 100644
--- a/cmd/zip.c
+++ b/cmd/zip.c
@@ -30,7 +30,7 @@ static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 
 	printf("Compressed size: %lu = 0x%lX\n", dst_len, dst_len);
-	env_set_hex("filesize", dst_len);
+	env_set_hex(ctx_uboot, "filesize", dst_len);
 
 	return 0;
 }
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 11/19] common: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (9 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 10/19] cmd: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 12/19] disk: " AKASHI Takahiro
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 common/autoboot.c      | 22 ++++++++++++----------
 common/board_f.c       |  3 ++-
 common/board_r.c       | 10 +++++-----
 common/bootm.c         | 12 +++++++-----
 common/bootm_os.c      | 12 ++++++------
 common/bootretry.c     |  2 +-
 common/cli.c           |  2 +-
 common/cli_hush.c      | 14 +++++++-------
 common/cli_simple.c    |  2 +-
 common/command.c       |  2 +-
 common/console.c       | 14 +++++++-------
 common/fdt_support.c   |  6 +++---
 common/hash.c          |  4 ++--
 common/hwconfig.c      |  5 +++--
 common/image-android.c |  4 ++--
 common/image-fdt.c     |  4 ++--
 common/image.c         | 15 ++++++++-------
 common/main.c          |  5 +++--
 common/spl/spl_dfu.c   |  6 +++---
 common/spl/spl_ext.c   |  4 ++--
 common/spl/spl_fat.c   |  4 ++--
 common/spl/spl_net.c   |  4 ++--
 common/splash.c        |  4 ++--
 common/splash_source.c |  8 ++++----
 common/update.c        | 10 +++++-----
 common/usb_hub.c       |  2 +-
 common/usb_kbd.c       |  6 +++---
 27 files changed, 97 insertions(+), 89 deletions(-)

diff --git a/common/autoboot.c b/common/autoboot.c
index b28bd6823d82..d28ea5f97a62 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -71,7 +71,7 @@ static int slow_equals(u8 *a, u8 *b, int len)
  */
 static int passwd_abort_sha256(uint64_t etime)
 {
-	const char *sha_env_str = env_get("bootstopkeysha256");
+	const char *sha_env_str = env_get(ctx_uboot, "bootstopkeysha256");
 	u8 sha_env[SHA256_SUM_LEN];
 	u8 *sha;
 	char *presskey;
@@ -146,8 +146,8 @@ static int passwd_abort_key(uint64_t etime)
 		int retry;
 	}
 	delaykey[] = {
-		{ .str = env_get("bootdelaykey"),  .retry = 1 },
-		{ .str = env_get("bootstopkey"),   .retry = 0 },
+		{ .str = env_get(ctx_uboot, "bootdelaykey"),  .retry = 1 },
+		{ .str = env_get(ctx_uboot, "bootstopkey"),   .retry = 0 },
 	};
 
 	char presskey[MAX_DELAY_STOP_STR];
@@ -308,12 +308,14 @@ static void process_fdt_options(const void *blob)
 	/* Add an env variable to point to a kernel payload, if available */
 	addr = fdtdec_get_config_int(gd->fdt_blob, "kernel-offset", 0);
 	if (addr)
-		env_set_addr("kernaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr));
+		env_set_addr(ctx_uboot, "kernaddr",
+			     (void *)(CONFIG_SYS_TEXT_BASE + addr));
 
 	/* Add an env variable to point to a root disk, if available */
 	addr = fdtdec_get_config_int(gd->fdt_blob, "rootdisk-offset", 0);
 	if (addr)
-		env_set_addr("rootaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr));
+		env_set_addr(ctx_uboot, "rootaddr",
+			     (void *)(CONFIG_SYS_TEXT_BASE + addr));
 #endif /* CONFIG_SYS_TEXT_BASE */
 }
 
@@ -324,7 +326,7 @@ const char *bootdelay_process(void)
 
 	bootcount_inc();
 
-	s = env_get("bootdelay");
+	s = env_get(ctx_uboot, "bootdelay");
 	bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
 
 	if (IS_ENABLED(CONFIG_OF_CONTROL))
@@ -339,13 +341,13 @@ const char *bootdelay_process(void)
 
 #ifdef CONFIG_POST
 	if (gd->flags & GD_FLG_POSTFAIL) {
-		s = env_get("failbootcmd");
+		s = env_get(ctx_uboot, "failbootcmd");
 	} else
 #endif /* CONFIG_POST */
 	if (bootcount_error())
-		s = env_get("altbootcmd");
+		s = env_get(ctx_uboot, "altbootcmd");
 	else
-		s = env_get("bootcmd");
+		s = env_get(ctx_uboot, "bootcmd");
 
 	if (IS_ENABLED(CONFIG_OF_CONTROL))
 		process_fdt_options(gd->fdt_blob);
@@ -375,7 +377,7 @@ void autoboot_command(const char *s)
 
 	if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY) &&
 	    menukey == AUTOBOOT_MENUKEY) {
-		s = env_get("menucmd");
+		s = env_get(ctx_uboot, "menucmd");
 		if (s)
 			run_command_list(s, -1, 0);
 	}
diff --git a/common/board_f.c b/common/board_f.c
index 6867abc8e679..cb0ccdd80cab 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -122,7 +122,8 @@ __weak void board_add_ram_info(int use_default)
 
 static int init_baud_rate(void)
 {
-	gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
+	gd->baudrate = env_get_ulong(ctx_uboot, "baudrate", 10,
+				     CONFIG_BAUDRATE);
 	return 0;
 }
 
diff --git a/common/board_r.c b/common/board_r.c
index b7f68bba4a7e..b2941c58599d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -448,14 +448,14 @@ static int initr_env(void)
 	if (should_load_env())
 		env_relocate();
 	else
-		env_set_default(NULL, 0);
+		env_set_default(ctx_uboot, NULL, 0);
 #ifdef CONFIG_OF_CONTROL
-	env_set_hex("fdtcontroladdr",
+	env_set_hex(ctx_uboot, "fdtcontroladdr",
 		    (unsigned long)map_to_sysmem(gd->fdt_blob));
 #endif
 
 	/* Initialize from environment */
-	load_addr = env_get_ulong("loadaddr", 16, load_addr);
+	load_addr = env_get_ulong(ctx_uboot, "loadaddr", 16, load_addr);
 
 	return 0;
 }
@@ -607,9 +607,9 @@ int initr_mem(void)
 	ulong pram = 0;
 	char memsz[32];
 
-	pram = env_get_ulong("pram", 10, CONFIG_PRAM);
+	pram = env_get_ulong(ctx_uboot, "pram", 10, CONFIG_PRAM);
 	sprintf(memsz, "%ldk", (long int)((gd->ram_size / 1024) - pram));
-	env_set("mem", memsz);
+	env_set(ctx_uboot, "mem", memsz);
 
 	return 0;
 }
diff --git a/common/bootm.c b/common/bootm.c
index 02295daf79f1..c367b409f29d 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -440,7 +440,7 @@ static void fixup_silent_linux(void)
 {
 	char *buf;
 	const char *env_val;
-	char *cmdline = env_get("bootargs");
+	char *cmdline = env_get(ctx_uboot, "bootargs");
 	int want_silent;
 
 	/*
@@ -485,7 +485,7 @@ static void fixup_silent_linux(void)
 		env_val = CONSOLE_ARG;
 	}
 
-	env_set("bootargs", env_val);
+	env_set(ctx_uboot, "bootargs", env_val);
 	debug("after silent fix-up: %s\n", env_val);
 	free(buf);
 }
@@ -556,8 +556,10 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		ret = boot_ramdisk_high(&images->lmb, images->rd_start,
 			rd_len, &images->initrd_start, &images->initrd_end);
 		if (!ret) {
-			env_set_hex("initrd_start", images->initrd_start);
-			env_set_hex("initrd_end", images->initrd_end);
+			env_set_hex(ctx_uboot, "initrd_start",
+				    images->initrd_start);
+			env_set_hex(ctx_uboot, "initrd_end",
+				    images->initrd_end);
 		}
 	}
 #endif
@@ -602,7 +604,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 #ifdef CONFIG_TRACE
 	/* Pretend to run the OS, then run a user command */
 	if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
-		char *cmd_list = env_get("fakegocmd");
+		char *cmd_list = env_get(ctx_uboot, "fakegocmd");
 
 		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
 				images, boot_fn);
diff --git a/common/bootm_os.c b/common/bootm_os.c
index 6fb7d658da69..19b728d2cc7c 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -22,9 +22,9 @@ static int do_bootm_standalone(int flag, int argc, char * const argv[],
 	int (*appl)(int, char *const[]);
 
 	/* Don't start if "autostart" is set to "no" */
-	s = env_get("autostart");
+	s = env_get(ctx_uboot, "autostart");
 	if ((s != NULL) && !strcmp(s, "no")) {
-		env_set_hex("filesize", images->os.image_len);
+		env_set_hex(ctx_uboot, "filesize", images->os.image_len);
 		return 0;
 	}
 	appl = (int (*)(int, char * const []))images->ep;
@@ -97,7 +97,7 @@ static int do_bootm_netbsd(int flag, int argc, char * const argv[],
 		cmdline = malloc(len);
 		copy_args(cmdline, argc, argv, ' ');
 	} else {
-		cmdline = env_get("bootargs");
+		cmdline = env_get(ctx_uboot, "bootargs");
 		if (cmdline == NULL)
 			cmdline = "";
 	}
@@ -228,14 +228,14 @@ static int do_bootm_plan9(int flag, int argc, char * const argv[],
 #endif
 
 	/* See README.plan9 */
-	s = env_get("confaddr");
+	s = env_get(ctx_uboot, "confaddr");
 	if (s != NULL) {
 		char *confaddr = (char *)simple_strtoul(s, NULL, 16);
 
 		if (argc > 0) {
 			copy_args(confaddr, argc, argv, '\n');
 		} else {
-			s = env_get("bootargs");
+			s = env_get(ctx_uboot, "bootargs");
 			if (s != NULL)
 				strcpy(confaddr, s);
 		}
@@ -282,7 +282,7 @@ static void do_bootvx_fdt(bootm_headers_t *images)
 
 		ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
 		if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
-			bootline = env_get("bootargs");
+			bootline = env_get(ctx_uboot, "bootargs");
 			if (bootline) {
 				ret = fdt_find_and_setprop(*of_flat_tree,
 						"/chosen", "bootargs",
diff --git a/common/bootretry.c b/common/bootretry.c
index 47aaaa82201e..ede7613fb9ce 100644
--- a/common/bootretry.c
+++ b/common/bootretry.c
@@ -23,7 +23,7 @@ static int      retry_time = -1; /* -1 so can call readline before main_loop */
  */
 void bootretry_init_cmd_timeout(void)
 {
-	char *s = env_get("bootretry");
+	char *s = env_get(ctx_uboot, "bootretry");
 
 	if (s != NULL)
 		retry_time = (int)simple_strtol(s, NULL, 10);
diff --git a/common/cli.c b/common/cli.c
index 49b910666b9f..4c588f862b5d 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -129,7 +129,7 @@ int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	for (i = 1; i < argc; ++i) {
 		char *arg;
 
-		arg = env_get(argv[i]);
+		arg = env_get(ctx_uboot, argv[i]);
 		if (arg == NULL) {
 			printf("## Error: \"%s\" not defined\n", argv[i]);
 			return 1;
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 8f86e4aa4a49..cf2306b76e66 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -560,7 +560,7 @@ static int builtin_cd(struct child_prog *child)
 {
 	char *newdir;
 	if (child->argv[1] == NULL)
-		newdir = env_get("HOME");
+		newdir = env_get(ctx_uboot, "HOME");
 	else
 		newdir = child->argv[1];
 	if (chdir(newdir)) {
@@ -948,7 +948,7 @@ static inline void cmdedit_set_initial_prompt(void)
 #ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
 	PS1 = NULL;
 #else
-	PS1 = env_get("PS1");
+	PS1 = env_get(ctx_uboot, "PS1");
 	if(PS1==0)
 		PS1 = "\\w \\$ ";
 #endif
@@ -987,9 +987,9 @@ static int uboot_cli_readline(struct in_str *i)
 
 #ifdef CONFIG_CMDLINE_PS_SUPPORT
 	if (i->promptmode == 1)
-		ps_prompt = env_get("PS1");
+		ps_prompt = env_get(ctx_uboot, "PS1");
 	else
-		ps_prompt = env_get("PS2");
+		ps_prompt = env_get(ctx_uboot, "PS2");
 	if (ps_prompt)
 		prompt = ps_prompt;
 #endif
@@ -2172,7 +2172,7 @@ int set_local_var(const char *s, int flg_export)
 	name=strdup(s);
 
 #ifdef __U_BOOT__
-	if (env_get(name) != NULL) {
+	if (env_get(ctx_uboot, name)) {
 		printf ("ERROR: "
 				"There is a global environment variable with the same name.\n");
 		free(name);
@@ -2793,7 +2793,7 @@ static char *lookup_param(char *src)
 		}
 	}
 
-	p = env_get(src);
+	p = env_get(ctx_uboot, src);
 	if (!p)
 		p = get_local_var(src);
 
@@ -3157,7 +3157,7 @@ static void mapset(const unsigned char *set, int code)
 static void update_ifs_map(void)
 {
 	/* char *ifs and char map[256] are both globals. */
-	ifs = (uchar *)env_get("IFS");
+	ifs = (uchar *)env_get(ctx_uboot, "IFS");
 	if (ifs == NULL) ifs=(uchar *)" \t\n";
 	/* Precompute a list of 'flow through' behavior so it can be treated
 	 * quickly up front.  Computation is necessary because of IFS.
diff --git a/common/cli_simple.c b/common/cli_simple.c
index 6c881c133c61..4c04667faa6e 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -131,7 +131,7 @@ void cli_simple_process_macros(const char *input, char *output)
 				envname[i] = 0;
 
 				/* Get its value */
-				envval = env_get(envname);
+				envval = env_get(ctx_uboot, envname);
 
 				/* Copy into the line if it exists */
 				if (envval != NULL)
diff --git a/common/command.c b/common/command.c
index 4b887a267fb6..736bedfbdeac 100644
--- a/common/command.c
+++ b/common/command.c
@@ -583,7 +583,7 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
 #if defined(CONFIG_SYS_XTRACE)
 	char *xtrace;
 
-	xtrace = env_get("xtrace");
+	xtrace = env_get(ctx_uboot, "xtrace");
 	if (xtrace) {
 		puts("+");
 		for (int i = 0; i < argc; i++) {
diff --git a/common/console.c b/common/console.c
index 89b1e9590cad..5888a6aade08 100644
--- a/common/console.c
+++ b/common/console.c
@@ -736,7 +736,7 @@ int console_assign(int file, const char *devname)
 static bool console_update_silent(void)
 {
 #ifdef CONFIG_SILENT_CONSOLE
-	if (env_get("silent")) {
+	if (env_get(ctx_uboot, "silent")) {
 		gd->flags |= GD_FLG_SILENT;
 	} else {
 		unsigned long flags = gd->flags;
@@ -829,9 +829,9 @@ int console_init_r(void)
 
 	/* stdin stdout and stderr are in environment */
 	/* scan for it */
-	stdinname  = env_get("stdin");
-	stdoutname = env_get("stdout");
-	stderrname = env_get("stderr");
+	stdinname  = env_get(ctx_uboot, "stdin");
+	stdoutname = env_get(ctx_uboot, "stdout");
+	stderrname = env_get(ctx_uboot, "stderr");
 
 	if (OVERWRITE_CONSOLE == 0) {	/* if not overwritten by config switch */
 		inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
@@ -885,7 +885,7 @@ done:
 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
 	/* set the environment variables (will overwrite previous env settings) */
 	for (i = 0; i < MAX_FILES; i++) {
-		env_set(stdio_names[i], stdio_devices[i]->name);
+		env_set(ctx_uboot, stdio_names[i], stdio_devices[i]->name);
 	}
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
@@ -925,7 +925,7 @@ int console_init_r(void)
 	 * console to serial console in this case or suppress it if
 	 * "silent" mode was requested.
 	 */
-	if (env_get("splashimage") != NULL) {
+	if (env_get(ctx_uboot, "splashimage")) {
 		if (!(gd->flags & GD_FLG_SILENT))
 			outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
 	}
@@ -969,7 +969,7 @@ int console_init_r(void)
 
 	/* Setting environment variables */
 	for (i = 0; i < MAX_FILES; i++) {
-		env_set(stdio_names[i], stdio_devices[i]->name);
+		env_set(ctx_uboot, stdio_names[i], stdio_devices[i]->name);
 	}
 
 	gd->flags |= GD_FLG_DEVINIT;	/* device initialization completed */
diff --git a/common/fdt_support.c b/common/fdt_support.c
index baf7924ff612..023e2acb5b71 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -197,7 +197,7 @@ int fdt_root(void *fdt)
 		return err;
 	}
 
-	serial = env_get("serial#");
+	serial = env_get(ctx_uboot, "serial#");
 	if (serial) {
 		err = fdt_setprop(fdt, 0, "serial-number", serial,
 				  strlen(serial) + 1);
@@ -289,7 +289,7 @@ int fdt_chosen(void *fdt)
 	if (nodeoffset < 0)
 		return nodeoffset;
 
-	str = env_get("bootargs");
+	str = env_get(ctx_uboot, "bootargs");
 	if (str) {
 		err = fdt_setprop(fdt, nodeoffset, "bootargs", str,
 				  strlen(str) + 1);
@@ -533,7 +533,7 @@ void fdt_fixup_ethernet(void *fdt)
 				continue;
 			i++;
 #endif
-			tmp = env_get(mac);
+			tmp = env_get(ctx_uboot, mac);
 			if (!tmp)
 				continue;
 
diff --git a/common/hash.c b/common/hash.c
index d33e329897e1..b87402ac1e4f 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -331,7 +331,7 @@ static void store_result(struct hash_algo *algo, const uint8_t *sum,
 			str_ptr += 2;
 		}
 		*str_ptr = '\0';
-		env_set(dest, str_output);
+		env_set(ctx_uboot, dest, str_output);
 	} else {
 		ulong addr;
 		void *buf;
@@ -391,7 +391,7 @@ static int parse_verify_sum(struct hash_algo *algo, char *verify_str,
 		if (strlen(verify_str) == digits)
 			vsum_str = verify_str;
 		else {
-			vsum_str = env_get(verify_str);
+			vsum_str = env_get(ctx_uboot, verify_str);
 			if (vsum_str == NULL || strlen(vsum_str) != digits) {
 				printf("Expected %d hex digits in env var\n",
 				       digits);
diff --git a/common/hwconfig.c b/common/hwconfig.c
index 72f3c4e0faa6..5d2fdea9c91f 100644
--- a/common/hwconfig.c
+++ b/common/hwconfig.c
@@ -81,7 +81,7 @@ static const char *__hwconfig(const char *opt, size_t *arglen,
 					"and before environment is ready\n");
 			return NULL;
 		}
-		env_hwconfig = env_get("hwconfig");
+		env_hwconfig = env_get(ctx_uboot, "hwconfig");
 	}
 
 	if (env_hwconfig) {
@@ -243,7 +243,8 @@ int main()
 	const char *ret;
 	size_t len;
 
-	env_set("hwconfig", "key1:subkey1=value1,subkey2=value2;key2:value3;;;;"
+	env_set(ctx_uboot, "hwconfig",
+		"key1:subkey1=value1,subkey2=value2;key2:value3;;;;"
 			   "key3;:,:=;key4", 1);
 
 	ret = hwconfig_arg("key1", &len);
diff --git a/common/image-android.c b/common/image-android.c
index 264bf90007e9..5d47c955df76 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -75,7 +75,7 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 		len += strlen(hdr->cmdline);
 	}
 
-	char *bootargs = env_get("bootargs");
+	char *bootargs = env_get(ctx_uboot, "bootargs");
 	if (bootargs)
 		len += strlen(bootargs);
 
@@ -93,7 +93,7 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 	if (*hdr->cmdline)
 		strcat(newbootargs, hdr->cmdline);
 
-	env_set("bootargs", newbootargs);
+	env_set(ctx_uboot, "bootargs", newbootargs);
 
 	if (os_data) {
 		if (image_get_magic(ihdr) == IH_MAGIC) {
diff --git a/common/image-fdt.c b/common/image-fdt.c
index 4247dcee0c4f..f735b3a02ff0 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -172,7 +172,7 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
 	of_len = *of_size + CONFIG_SYS_FDT_PAD;
 
 	/* If fdt_high is set use it to select the relocation address */
-	fdt_high = env_get("fdt_high");
+	fdt_high = env_get(ctx_uboot, "fdt_high");
 	if (fdt_high) {
 		void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
 
@@ -470,7 +470,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
 			debug("## Using FDT in Android image second area\n");
 		} else {
-			fdt_addr = env_get_hex("fdtaddr", 0);
+			fdt_addr = env_get_hex(ctx_uboot, "fdtaddr", 0);
 			if (!fdt_addr)
 				goto no_fdt;
 
diff --git a/common/image.c b/common/image.c
index 645584b5ba22..fca910ac5019 100644
--- a/common/image.c
+++ b/common/image.c
@@ -573,7 +573,7 @@ U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
 
 ulong env_get_bootm_low(void)
 {
-	char *s = env_get("bootm_low");
+	char *s = env_get(ctx_uboot, "bootm_low");
 	if (s) {
 		ulong tmp = simple_strtoul(s, NULL, 16);
 		return tmp;
@@ -592,7 +592,7 @@ phys_size_t env_get_bootm_size(void)
 {
 	phys_size_t tmp, size;
 	phys_addr_t start;
-	char *s = env_get("bootm_size");
+	char *s = env_get(ctx_uboot, "bootm_size");
 	if (s) {
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 		return tmp;
@@ -606,7 +606,7 @@ phys_size_t env_get_bootm_size(void)
 	size = gd->bd->bi_memsize;
 #endif
 
-	s = env_get("bootm_low");
+	s = env_get(ctx_uboot, "bootm_low");
 	if (s)
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 	else
@@ -618,7 +618,7 @@ phys_size_t env_get_bootm_size(void)
 phys_size_t env_get_bootm_mapsize(void)
 {
 	phys_size_t tmp;
-	char *s = env_get("bootm_mapsize");
+	char *s = env_get(ctx_uboot, "bootm_mapsize");
 	if (s) {
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 		return tmp;
@@ -1070,7 +1070,8 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 	 */
 	buf = map_sysmem(images->os.start, 0);
 	if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
-		select = (argc == 0) ? env_get("loadaddr") : argv[0];
+		select = (argc == 0) ? env_get(ctx_uboot, "loadaddr")
+					: argv[0];
 #endif
 
 	if (argc >= 2)
@@ -1257,7 +1258,7 @@ int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
 	ulong	initrd_high;
 	int	initrd_copy_to_ram = 1;
 
-	s = env_get("initrd_high");
+	s = env_get(ctx_uboot, "initrd_high");
 	if (s) {
 		/* a value of "no" or a similar string will act like 0,
 		 * turning the "load high" feature off. This is intentional.
@@ -1548,7 +1549,7 @@ int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
 	if (cmdline == NULL)
 		return -1;
 
-	s = env_get("bootargs");
+	s = env_get(ctx_uboot, "bootargs");
 	if (!s)
 		s = "";
 
diff --git a/common/main.c b/common/main.c
index 3a657c3d9a39..cb9bd8256413 100644
--- a/common/main.c
+++ b/common/main.c
@@ -22,7 +22,7 @@ static void run_preboot_environment_command(void)
 {
 	char *p;
 
-	p = env_get("preboot");
+	p = env_get(ctx_uboot, "preboot");
 	if (p != NULL) {
 		int prev = 0;
 
@@ -44,7 +44,8 @@ void main_loop(void)
 	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
 
 	if (IS_ENABLED(CONFIG_VERSION_VARIABLE))
-		env_set("ver", version_string);  /* set version variable */
+		/* set version variable */
+		env_set(ctx_uboot, "ver", version_string);
 
 	cli_init();
 
diff --git a/common/spl/spl_dfu.c b/common/spl/spl_dfu.c
index 5728d43ad3f2..4febdb54482f 100644
--- a/common/spl/spl_dfu.c
+++ b/common/spl/spl_dfu.c
@@ -38,14 +38,14 @@ int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr)
 	int ret;
 
 	/* set default environment */
-	env_set_default(NULL, 0);
-	str_env = env_get(dfu_alt_info);
+	env_set_default(ctx_uboot, NULL, 0);
+	str_env = env_get(ctx_uboot, dfu_alt_info);
 	if (!str_env) {
 		pr_err("\"%s\" env variable not defined!\n", dfu_alt_info);
 		return -EINVAL;
 	}
 
-	ret = env_set("dfu_alt_info", str_env);
+	ret = env_set(ctx_uboot, "dfu_alt_info", str_env);
 	if (ret) {
 		pr_err("unable to set env variable \"dfu_alt_info\"!\n");
 		return -EINVAL;
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index 2a6252229ca1..a2f0fcb89eb8 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -87,7 +87,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,
 		return -1;
 	}
 #if defined(CONFIG_SPL_ENV_SUPPORT)
-	file = env_get("falcon_args_file");
+	file = env_get(ctx_uboot, "falcon_args_file");
 	if (file) {
 		err = ext4fs_open(file, &filelen);
 		if (err < 0) {
@@ -100,7 +100,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,
 			       file, err);
 			goto defaults;
 		}
-		file = env_get("falcon_image_file");
+		file = env_get(ctx_uboot, "falcon_image_file");
 		if (file) {
 			err = spl_load_image_ext(spl_image, block_dev,
 						 partition, file);
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index aa371ab52c56..10c1d02e02fe 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -123,7 +123,7 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image,
 		return err;
 
 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
-	file = env_get("falcon_args_file");
+	file = env_get(ctx_uboot, "falcon_args_file");
 	if (file) {
 		err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
 		if (err <= 0) {
@@ -131,7 +131,7 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image,
 			       file, err);
 			goto defaults;
 		}
-		file = env_get("falcon_image_file");
+		file = env_get(ctx_uboot, "falcon_image_file");
 		if (file) {
 			err = spl_load_image_fat(spl_image, block_dev,
 						 partition, file);
diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
index 803303249c72..141014506a0a 100644
--- a/common/spl/spl_net.c
+++ b/common/spl/spl_net.c
@@ -31,14 +31,14 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
 
 	env_init();
 	env_relocate();
-	env_set("autoload", "yes");
+	env_set(ctx_uboot, "autoload", "yes");
 	rv = eth_initialize();
 	if (rv == 0) {
 		printf("No Ethernet devices found\n");
 		return -ENODEV;
 	}
 	if (bootdev->boot_device_name)
-		env_set("ethact", bootdev->boot_device_name);
+		env_set(ctx_uboot, "ethact", bootdev->boot_device_name);
 	rv = net_loop(BOOTP);
 	if (rv < 0) {
 		printf("Problem booting with BOOTP\n");
diff --git a/common/splash.c b/common/splash.c
index e15cc847b68c..439667a40f64 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -61,7 +61,7 @@ __weak int splash_screen_prepare(void)
 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
 void splash_get_pos(int *x, int *y)
 {
-	char *s = env_get("splashpos");
+	char *s = env_get(ctx_uboot, "splashpos");
 
 	if (!s)
 		return;
@@ -93,7 +93,7 @@ int splash_display(void)
 	char *s;
 	int x = 0, y = 0, ret;
 
-	s = env_get("splashimage");
+	s = env_get(ctx_uboot, "splashimage");
 	if (!s)
 		return -EINVAL;
 
diff --git a/common/splash_source.c b/common/splash_source.c
index d37b4b304c2c..a99519a1f80c 100644
--- a/common/splash_source.c
+++ b/common/splash_source.c
@@ -220,7 +220,7 @@ static int splash_load_fs(struct splash_location *location, u32 bmp_load_addr)
 	loff_t actread;
 	char *splash_file;
 
-	splash_file = env_get("splashfile");
+	splash_file = env_get(ctx_uboot, "splashfile");
 	if (!splash_file)
 		splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME;
 
@@ -286,7 +286,7 @@ static struct splash_location *select_splash_location(
 	if (!locations || size == 0)
 		return NULL;
 
-	env_splashsource = env_get("splashsource");
+	env_splashsource = env_get(ctx_uboot, "splashsource");
 	if (env_splashsource == NULL)
 		return &locations[0];
 
@@ -341,7 +341,7 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)
 	}
 
 	/* Get the splash image node */
-	splash_file = env_get("splashfile");
+	splash_file = env_get(ctx_uboot, "splashfile");
 	if (!splash_file)
 		splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME;
 
@@ -407,7 +407,7 @@ int splash_source_load(struct splash_location *locations, uint size)
 	char *env_splashimage_value;
 	u32 bmp_load_addr;
 
-	env_splashimage_value = env_get("splashimage");
+	env_splashimage_value = env_get(ctx_uboot, "splashimage");
 	if (env_splashimage_value == NULL)
 		return -ENOENT;
 
diff --git a/common/update.c b/common/update.c
index 457b29f42aa3..8ba5f70401b8 100644
--- a/common/update.c
+++ b/common/update.c
@@ -60,7 +60,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 	/* save used globals and env variable */
 	saved_timeout_msecs = tftp_timeout_ms;
 	saved_timeout_count = tftp_timeout_count_max;
-	saved_netretry = strdup(env_get("netretry"));
+	saved_netretry = strdup(env_get(ctx_uboot, "netretry"));
 	saved_bootfile = strdup(net_boot_file_name);
 
 	/* set timeouts for auto-update */
@@ -68,7 +68,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 	tftp_timeout_count_max = cnt_max;
 
 	/* we don't want to retry the connection if errors occur */
-	env_set("netretry", "no");
+	env_set(ctx_uboot, "netretry", "no");
 
 	/* download the update file */
 	load_addr = addr;
@@ -84,7 +84,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 	tftp_timeout_ms = saved_timeout_msecs;
 	tftp_timeout_count_max = saved_timeout_count;
 
-	env_set("netretry", saved_netretry);
+	env_set(ctx_uboot, "netretry", saved_netretry);
 	if (saved_netretry != NULL)
 		free(saved_netretry);
 
@@ -255,7 +255,7 @@ int update_tftp(ulong addr, char *interface, char *devstring)
 	printf("Auto-update from TFTP: ");
 
 	/* get the file name of the update file */
-	filename = env_get(UPDATE_FILE_ENV);
+	filename = env_get(ctx_uboot, UPDATE_FILE_ENV);
 	if (filename == NULL) {
 		printf("failed, env. variable '%s' not found\n",
 							UPDATE_FILE_ENV);
@@ -265,7 +265,7 @@ int update_tftp(ulong addr, char *interface, char *devstring)
 	printf("trying update file '%s'\n", filename);
 
 	/* get load address of downloaded update file */
-	env_addr = env_get("loadaddr");
+	env_addr = env_get(ctx_uboot, "loadaddr");
 	if (env_addr)
 		addr = simple_strtoul(env_addr, NULL, 16);
 	else
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 25c2ac43450d..82fe6149429f 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -187,7 +187,7 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 	 * but allow this time to be increased via env variable as some
 	 * devices break the spec and require longer warm-up times
 	 */
-	env = env_get("usb_pgood_delay");
+	env = env_get(ctx_uboot, "usb_pgood_delay");
 	if (env)
 		pgood_delay = max(pgood_delay,
 			          (unsigned)simple_strtol(env, NULL, 0));
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index 387373746147..8bba3897e239 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -540,7 +540,7 @@ static int probe_usb_keyboard(struct usb_device *dev)
 	if (error)
 		return error;
 
-	stdinname = env_get("stdin");
+	stdinname = env_get(ctx_uboot, "stdin");
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
 	error = iomux_doenv(stdin, stdinname);
 	if (error)
@@ -607,7 +607,7 @@ int usb_kbd_deregister(int force)
 		if (stdio_deregister_dev(dev, force) != 0)
 			return 1;
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-		if (iomux_doenv(stdin, env_get("stdin")) != 0)
+		if (iomux_doenv(stdin, env_get(ctx_uboot, "stdin")) != 0)
 			return 1;
 #endif
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
@@ -652,7 +652,7 @@ static int usb_kbd_remove(struct udevice *dev)
 		goto err;
 	}
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-	if (iomux_doenv(stdin, env_get("stdin"))) {
+	if (iomux_doenv(stdin, env_get(ctx_uboot, "stdin"))) {
 		ret = -ENOLINK;
 		goto err;
 	}
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 12/19] disk: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (10 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 11/19] common: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 13/19] drivers: " AKASHI Takahiro
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 disk/part.c       | 2 +-
 disk/part_amiga.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 8982ef3baed1..6bbb40c62182 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -491,7 +491,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 	/* If no dev_part_str, use bootdevice environment variable */
 	if (!dev_part_str || !strlen(dev_part_str) ||
 	    !strcmp(dev_part_str, "-"))
-		dev_part_str = env_get("bootdevice");
+		dev_part_str = env_get(ctx_uboot, "bootdevice");
 
 	/* If still no dev_part_str, it's an error */
 	if (!dev_part_str) {
diff --git a/disk/part_amiga.c b/disk/part_amiga.c
index 5a2bb718b597..c40baaeb9caf 100644
--- a/disk/part_amiga.c
+++ b/disk/part_amiga.c
@@ -132,7 +132,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)
     int limit;
     char *s;
 
-    s = env_get("amiga_scanlimit");
+    s = env_get(ctx_uboot, "amiga_scanlimit");
     if (s)
 	limit = simple_strtoul(s, NULL, 10);
     else
@@ -172,7 +172,7 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)
     int limit;
     char *s;
 
-    s = env_get("amiga_scanlimit");
+    s = env_get(ctx_uboot, "amiga_scanlimit");
     if (s)
 	limit = simple_strtoul(s, NULL, 10);
     else
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 13/19] drivers: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (11 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 12/19] disk: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 14/19] fs: " AKASHI Takahiro
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 drivers/bootcount/bootcount_env.c   | 12 +++++++-----
 drivers/ddr/fsl/fsl_ddr_gen4.c      |  2 +-
 drivers/ddr/fsl/interactive.c       |  5 +++--
 drivers/ddr/fsl/options.c           |  4 ++--
 drivers/dfu/dfu.c                   |  6 +++---
 drivers/fastboot/fb_command.c       |  4 ++--
 drivers/fastboot/fb_common.c        |  2 +-
 drivers/fastboot/fb_getvar.c        |  8 ++++----
 drivers/fastboot/fb_mmc.c           |  2 +-
 drivers/input/i8042.c               |  2 +-
 drivers/input/input.c               |  2 +-
 drivers/misc/fs_loader.c            |  8 ++++----
 drivers/mtd/cfi_flash.c             |  2 +-
 drivers/mtd/mtd_uboot.c             | 11 ++++++-----
 drivers/net/fec_mxc.c               |  2 +-
 drivers/net/fm/b4860.c              |  3 ++-
 drivers/net/fm/fdt.c                |  2 +-
 drivers/net/fm/fm.c                 |  4 ++--
 drivers/net/fsl-mc/mc.c             |  7 ++++---
 drivers/net/netconsole.c            | 14 +++++++-------
 drivers/net/phy/micrel_ksz90x1.c    |  4 ++--
 drivers/net/sandbox-raw.c           |  4 ++--
 drivers/pci/pci.c                   |  4 ++--
 drivers/pci/pci_common.c            |  2 +-
 drivers/reset/reset-socfpga.c       |  2 +-
 drivers/rtc/m41t60.c                |  2 +-
 drivers/scsi/scsi.c                 |  2 +-
 drivers/serial/usbtty.c             |  4 ++--
 drivers/usb/gadget/designware_udc.c |  2 +-
 drivers/usb/gadget/ether.c          | 13 +++++++------
 drivers/usb/gadget/f_dfu.c          |  2 +-
 drivers/usb/gadget/f_fastboot.c     |  2 +-
 drivers/usb/gadget/f_rockusb.c      |  2 +-
 drivers/usb/gadget/f_sdp.c          |  2 +-
 drivers/usb/host/ehci-fsl.c         |  2 +-
 drivers/video/ati_radeon_fb.c       |  2 +-
 drivers/video/cfb_console.c         |  2 +-
 drivers/video/mb862xx.c             |  2 +-
 drivers/video/mx3fb.c               |  2 +-
 drivers/video/mxsfb.c               |  2 +-
 drivers/video/videomodes.c          |  4 ++--
 41 files changed, 86 insertions(+), 79 deletions(-)

diff --git a/drivers/bootcount/bootcount_env.c b/drivers/bootcount/bootcount_env.c
index b75c9002b2c0..3f4ba6d8586c 100644
--- a/drivers/bootcount/bootcount_env.c
+++ b/drivers/bootcount/bootcount_env.c
@@ -9,21 +9,23 @@
 
 void bootcount_store(ulong a)
 {
-	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);
+	int upgrade_available = env_get_ulong(ctx_uboot, "upgrade_available",
+					      10, 0);
 
 	if (upgrade_available) {
-		env_set_ulong("bootcount", a);
-		env_save();
+		env_set_ulong(ctx_uboot, "bootcount", a);
+		env_save(ctx_uboot);
 	}
 }
 
 ulong bootcount_load(void)
 {
-	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);
+	int upgrade_available = env_get_ulong(ctx_uboot, "upgrade_available",
+					      10, 0);
 	ulong val = 0;
 
 	if (upgrade_available)
-		val = env_get_ulong("bootcount", 10, 0);
+		val = env_get_ulong(ctx_uboot, "bootcount", 10, 0);
 
 	return val;
 }
diff --git a/drivers/ddr/fsl/fsl_ddr_gen4.c b/drivers/ddr/fsl/fsl_ddr_gen4.c
index 17a4a8282b73..3e373607eb16 100644
--- a/drivers/ddr/fsl/fsl_ddr_gen4.c
+++ b/drivers/ddr/fsl/fsl_ddr_gen4.c
@@ -509,7 +509,7 @@ step2:
 #define BIST_CR_STAT	0x00000001
 	/* Perform build-in test on memory. Three-way interleaving is not yet
 	 * supported by this code. */
-	if (env_get_f("ddr_bist", buffer, CONFIG_SYS_CBSIZE) >= 0) {
+	if (env_get_f(ctx_uboot, "ddr_bist", buffer, CONFIG_SYS_CBSIZE) >= 0) {
 		puts("Running BIST test. This will take a while...");
 		cs0_config = ddr_in32(&ddr->cs0_config);
 		cs0_bnds = ddr_in32(&ddr->cs0_bnds);
diff --git a/drivers/ddr/fsl/interactive.c b/drivers/ddr/fsl/interactive.c
index 8e171e67fec2..2c5829cd394b 100644
--- a/drivers/ddr/fsl/interactive.c
+++ b/drivers/ddr/fsl/interactive.c
@@ -1876,7 +1876,8 @@ int fsl_ddr_interactive_env_var_exists(void)
 {
 	char buffer[CONFIG_SYS_CBSIZE];
 
-	if (env_get_f("ddr_interactive", buffer, CONFIG_SYS_CBSIZE) >= 0)
+	if (env_get_f(ctx_uboot, "ddr_interactive", buffer,
+		      CONFIG_SYS_CBSIZE) >= 0)
 		return 1;
 
 	return 0;
@@ -1906,7 +1907,7 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo, int var_is_set)
 	};
 
 	if (var_is_set) {
-		if (env_get_f("ddr_interactive", buffer2,
+		if (env_get_f(ctx_uboot, "ddr_interactive", buffer2,
 			      CONFIG_SYS_CBSIZE) > 0)
 			p = buffer2;
 		else
diff --git a/drivers/ddr/fsl/options.c b/drivers/ddr/fsl/options.c
index b9179315f252..51d27096e8f6 100644
--- a/drivers/ddr/fsl/options.c
+++ b/drivers/ddr/fsl/options.c
@@ -760,7 +760,7 @@ unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
 	 * Extract hwconfig from environment since we have not properly setup
 	 * the environment but need it for ddr config params
 	 */
-	if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
+	if (env_get_f(ctx_uboot, "hwconfig", buf, sizeof(buf)) < 0)
 		buf[0] = '\0';
 
 #if defined(CONFIG_SYS_FSL_DDR3) || \
@@ -1407,7 +1407,7 @@ int fsl_use_spd(void)
 	 * Extract hwconfig from environment since we have not properly setup
 	 * the environment but need it for ddr config params
 	 */
-	if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
+	if (env_get_f(ctx_uboot, "hwconfig", buf, sizeof(buf)) < 0)
 		buf[0] = '\0';
 
 	/* if hwconfig is not enabled, or "sdram" is not defined, use spd */
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index d2b67b18cf02..9171c1932014 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -62,7 +62,7 @@ int dfu_init_env_entities(char *interface, char *devstr)
 #ifdef CONFIG_SET_DFU_ALT_INFO
 	set_dfu_alt_info(interface, devstr);
 #endif
-	str_env = env_get("dfu_alt_info");
+	str_env = env_get(ctx_uboot, "dfu_alt_info");
 	if (!str_env) {
 		pr_err("\"dfu_alt_info\" env variable not defined!\n");
 		return -EINVAL;
@@ -103,7 +103,7 @@ unsigned char *dfu_get_buf(struct dfu_entity *dfu)
 	if (dfu_buf != NULL)
 		return dfu_buf;
 
-	s = env_get("dfu_bufsiz");
+	s = env_get(ctx_uboot, "dfu_bufsiz");
 	if (s)
 		dfu_buf_size = (unsigned long)simple_strtol(s, NULL, 0);
 
@@ -125,7 +125,7 @@ static char *dfu_get_hash_algo(void)
 {
 	char *s;
 
-	s = env_get("dfu_hash_algo");
+	s = env_get(ctx_uboot, "dfu_hash_algo");
 	if (!s)
 		return NULL;
 
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index 4864344853c2..daa8092383d9 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -250,7 +250,7 @@ void fastboot_data_complete(char *response)
 	fastboot_okay(NULL, response);
 	printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received);
 	image_size = fastboot_bytes_received;
-	env_set_hex("filesize", image_size);
+	env_set_hex(ctx_uboot, "filesize", image_size);
 	fastboot_bytes_expected = 0;
 	fastboot_bytes_received = 0;
 }
@@ -322,7 +322,7 @@ static void oem_format(char *cmd_parameter, char *response)
 {
 	char cmdbuf[32];
 
-	if (!env_get("partitions")) {
+	if (!env_get(ctx_uboot, "partitions")) {
 		fastboot_fail("partitions not set", response);
 	} else {
 		sprintf(cmdbuf, "gpt write mmc %x $partitions",
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index e76af8ecc320..f0618c983317 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -116,7 +116,7 @@ void fastboot_boot(void)
 {
 	char *s;
 
-	s = env_get("fastboot_bootcmd");
+	s = env_get(ctx_uboot, "fastboot_bootcmd");
 	if (s) {
 		run_command(s, CMD_FLAG_ENV);
 	} else {
diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index 95cb4341895f..a57a1c4b5ed5 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -141,7 +141,7 @@ static void getvar_downloadsize(char *var_parameter, char *response)
 
 static void getvar_serialno(char *var_parameter, char *response)
 {
-	const char *tmp = env_get("serial#");
+	const char *tmp = env_get(ctx_uboot, "serial#");
 
 	if (tmp)
 		fastboot_okay(tmp, response);
@@ -156,7 +156,7 @@ static void getvar_version_baseband(char *var_parameter, char *response)
 
 static void getvar_product(char *var_parameter, char *response)
 {
-	const char *board = env_get("board");
+	const char *board = env_get(ctx_uboot, "board");
 
 	if (board)
 		fastboot_okay(board, response);
@@ -166,7 +166,7 @@ static void getvar_product(char *var_parameter, char *response)
 
 static void getvar_platform(char *var_parameter, char *response)
 {
-	const char *p = env_get("platform");
+	const char *p = env_get(ctx_uboot, "platform");
 
 	if (p)
 		fastboot_okay(p, response);
@@ -276,7 +276,7 @@ void fastboot_getvar(char *cmd_parameter, char *response)
 
 		snprintf(envstr, sizeof(envstr) - 1,
 			 FASTBOOT_ENV_PREFIX "%s", cmd_parameter);
-		s = env_get(envstr);
+		s = env_get(ctx_uboot, envstr);
 		if (s) {
 			fastboot_response("OKAY", response, "%s", s);
 			return;
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index b0b19c576252..02d45b20087c 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -39,7 +39,7 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
 		/* check for alias */
 		strcpy(env_alias_name, "fastboot_partition_alias_");
 		strncat(env_alias_name, name, PART_NAME_LEN);
-		aliased_part_name = env_get(env_alias_name);
+		aliased_part_name = env_get(ctx_uboot, env_alias_name);
 		if (aliased_part_name != NULL)
 			ret = part_get_info_by_name(dev_desc,
 					aliased_part_name, info);
diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index 98015899f21d..3cdeda42c11a 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -269,7 +269,7 @@ static int i8042_start(struct udevice *dev)
 
 	/* Init keyboard device (default US layout) */
 	keymap = KBD_US;
-	penv = env_get("keymap");
+	penv = env_get(ctx_uboot, "keymap");
 	if (penv != NULL) {
 		if (strncmp(penv, "de", 3) == 0)
 			keymap = KBD_GER;
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 6ab378b979bd..6e0c4cd9bf88 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -655,7 +655,7 @@ int input_stdio_register(struct stdio_dev *dev)
 	error = stdio_register(dev);
 #if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT)
 	/* check if this is the standard input device */
-	if (!error && strcmp(env_get("stdin"), dev->name) == 0) {
+	if (!error && strcmp(env_get(ctx_uboot, "stdin"), dev->name) == 0) {
 		/* reassign the console */
 		if (OVERWRITE_CONSOLE ||
 				console_assign(stdin, dev->name))
diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
index 88e486e9d570..3959433dc419 100644
--- a/drivers/misc/fs_loader.c
+++ b/drivers/misc/fs_loader.c
@@ -142,10 +142,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)
 	char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
 	int ret;
 
-	storage_interface = env_get("storage_interface");
-	dev_part = env_get("fw_dev_part");
-	ubi_mtdpart = env_get("fw_ubi_mtdpart");
-	ubi_volume = env_get("fw_ubi_volume");
+	storage_interface = env_get(ctx_uboot, "storage_interface");
+	dev_part = env_get(ctx_uboot, "fw_dev_part");
+	ubi_mtdpart = env_get(ctx_uboot, "fw_ubi_mtdpart");
+	ubi_volume = env_get(ctx_uboot, "fw_ubi_volume");
 
 	if (storage_interface && dev_part) {
 		ret = fs_set_blk_dev(storage_interface, dev_part, FS_TYPE_ANY);
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index c59254c76e3e..a3e9d820e883 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -2374,7 +2374,7 @@ unsigned long flash_init(void)
 	/* read environment from EEPROM */
 	char s[64];
 
-	env_get_f("unlock", s, sizeof(s));
+	env_get_f(ctx_uboot, "unlock", s, sizeof(s));
 #endif
 
 #ifdef CONFIG_CFI_FLASH /* for driver model */
diff --git a/drivers/mtd/mtd_uboot.c b/drivers/mtd/mtd_uboot.c
index 557422759831..2c178ac96cd6 100644
--- a/drivers/mtd/mtd_uboot.c
+++ b/drivers/mtd/mtd_uboot.c
@@ -19,7 +19,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts);
 static const char *get_mtdids(void)
 {
 	__maybe_unused const char *mtdparts = NULL;
-	const char *mtdids = env_get("mtdids");
+	const char *mtdids = env_get(ctx_uboot, "mtdids");
 
 	if (mtdids)
 		return mtdids;
@@ -33,7 +33,7 @@ static const char *get_mtdids(void)
 #endif
 
 	if (mtdids)
-		env_set("mtdids", mtdids);
+		env_set(ctx_uboot, "mtdids", mtdids);
 
 	return mtdids;
 }
@@ -126,8 +126,9 @@ static const char *get_mtdparts(void)
 	const char *mtdparts = NULL;
 
 	if (gd->flags & GD_FLG_ENV_READY)
-		mtdparts = env_get("mtdparts");
-	else if (env_get_f("mtdparts", tmp_parts, sizeof(tmp_parts)) != -1)
+		mtdparts = env_get(ctx_uboot, "mtdparts");
+	else if (env_get_f(ctx_uboot, "mtdparts", tmp_parts,
+			   sizeof(tmp_parts)) != -1)
 		mtdparts = tmp_parts;
 
 	if (mtdparts)
@@ -142,7 +143,7 @@ static const char *get_mtdparts(void)
 #endif
 
 	if (mtdparts)
-		env_set("mtdparts", mtdparts);
+		env_set(ctx_uboot, "mtdparts", mtdparts);
 
 	return mtdparts;
 }
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index 080dbcf7db44..e6c63e60a2e7 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -1162,7 +1162,7 @@ static int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr,
 			sprintf(mac, "eth%daddr", fec->dev_id);
 		else
 			strcpy(mac, "ethaddr");
-		if (!env_get(mac))
+		if (!env_get(ctx_uboot, mac))
 			eth_env_set_enetaddr(mac, ethaddr);
 	}
 	return ret;
diff --git a/drivers/net/fm/b4860.c b/drivers/net/fm/b4860.c
index 5be0ad2ab3db..b67ce9d56fad 100644
--- a/drivers/net/fm/b4860.c
+++ b/drivers/net/fm/b4860.c
@@ -97,7 +97,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port)
 			 * Extract hwconfig from environment since environment
 			 * is not setup yet
 			 */
-			env_get_f("hwconfig", buffer, sizeof(buffer));
+			env_get_f(ctx_uboot, "hwconfig", buffer,
+				  sizeof(buffer));
 			buf = buffer;
 
 			/* check if XFI interface enable in hwconfig for 10g */
diff --git a/drivers/net/fm/fdt.c b/drivers/net/fm/fdt.c
index 72d129475145..7d891b925082 100644
--- a/drivers/net/fm/fdt.c
+++ b/drivers/net/fm/fdt.c
@@ -36,7 +36,7 @@ void fdt_fixup_fman_firmware(void *blob)
 		return;
 
 	/* If the environment variable is not set, then exit silently */
-	p = env_get("fman_ucode");
+	p = env_get(ctx_uboot, "fman_ucode");
 	if (!p)
 		return;
 
diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c
index 4c9dce8dc57b..6d946eb78b0b 100644
--- a/drivers/net/fm/fm.c
+++ b/drivers/net/fm/fm.c
@@ -428,7 +428,7 @@ int fm_init_common(int index, struct ccsr_fman *reg)
 	rc = fman_upload_firmware(index, &reg->fm_imem, addr);
 	if (rc)
 		return rc;
-	env_set_addr("fman_ucode", addr);
+	env_set_addr(ctx_uboot, "fman_ucode", addr);
 
 	fm_init_muram(index, &reg->muram);
 	fm_init_qmi(&reg->fm_qmi_common);
@@ -511,7 +511,7 @@ int fm_init_common(int index, struct ccsr_fman *reg)
 	rc = fman_upload_firmware(index, &reg->fm_imem, addr);
 	if (rc)
 		return rc;
-	env_set_addr("fman_ucode", addr);
+	env_set_addr(ctx_uboot, "fman_ucode", addr);
 
 	fm_init_muram(index, &reg->muram);
 	fm_init_qmi(&reg->fm_qmi_common);
diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index c980ba4edb98..b88d8e6627ee 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -578,7 +578,7 @@ static unsigned long get_mc_boot_timeout_ms(void)
 {
 	unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
 
-	char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
+	char *timeout_ms_env_var = env_get(ctx_uboot, MC_BOOT_TIMEOUT_ENV_VAR);
 
 	if (timeout_ms_env_var) {
 		timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
@@ -893,7 +893,8 @@ unsigned long mc_get_dram_block_size(void)
 {
 	unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
 
-	char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
+	char *dram_block_size_env_var = env_get(ctx_uboot,
+						MC_MEM_SIZE_ENV_VAR);
 
 	if (dram_block_size_env_var) {
 		dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
@@ -1668,7 +1669,7 @@ void mc_env_boot(void)
 	 * address info properly. Without MAC addresses, the MC code
 	 * can not properly initialize the DPC.
 	 */
-	mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
+	mc_boot_env_var = env_get(ctx_uboot, MC_BOOT_ENV_VAR);
 	if (mc_boot_env_var)
 		run_command_list(mc_boot_env_var, -1, 0);
 #endif /* CONFIG_FSL_MC_ENET */
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 73005ff94d9f..3e9855af48fe 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -60,8 +60,8 @@ static int is_broadcast(struct in_addr ip)
 
 	/* update only when the environment has changed */
 	if (env_changed_id != env_id) {
-		netmask = env_get_ip("netmask");
-		our_ip = env_get_ip("ipaddr");
+		netmask = env_get_ip(ctx_uboot, "netmask");
+		our_ip = env_get_ip(ctx_uboot, "ipaddr");
 
 		env_changed_id = env_id;
 	}
@@ -80,11 +80,11 @@ static int refresh_settings_from_env(void)
 
 	/* update only when the environment has changed */
 	if (env_changed_id != env_id) {
-		if (env_get("ncip")) {
-			nc_ip = env_get_ip("ncip");
+		if (env_get(ctx_uboot, "ncip")) {
+			nc_ip = env_get_ip(ctx_uboot, "ncip");
 			if (!nc_ip.s_addr)
 				return -1;	/* ncip is 0.0.0.0 */
-			p = strchr(env_get("ncip"), ':');
+			p = strchr(env_get(ctx_uboot, "ncip"), ':');
 			if (p != NULL) {
 				nc_out_port = simple_strtoul(p + 1, NULL, 10);
 				nc_in_port = nc_out_port;
@@ -93,10 +93,10 @@ static int refresh_settings_from_env(void)
 			nc_ip.s_addr = ~0; /* ncip is not set, so broadcast */
 		}
 
-		p = env_get("ncoutport");
+		p = env_get(ctx_uboot, "ncoutport");
 		if (p != NULL)
 			nc_out_port = simple_strtoul(p, NULL, 10);
-		p = env_get("ncinport");
+		p = env_get(ctx_uboot, "ncinport");
 		if (p != NULL)
 			nc_in_port = simple_strtoul(p, NULL, 10);
 
diff --git a/drivers/net/phy/micrel_ksz90x1.c b/drivers/net/phy/micrel_ksz90x1.c
index 0105fc5af1ea..6480786fa2ce 100644
--- a/drivers/net/phy/micrel_ksz90x1.c
+++ b/drivers/net/phy/micrel_ksz90x1.c
@@ -267,7 +267,7 @@ static int ksz9021_config(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
-	if (env_get("disable_giga"))
+	if (env_get(ctx_uboot, "disable_giga"))
 		features &= ~(SUPPORTED_1000baseT_Half |
 		SUPPORTED_1000baseT_Full);
 	/* force master mode for 1000BaseT due to chip errata */
@@ -353,7 +353,7 @@ static int ksz9031_config(struct phy_device *phydev)
 		return ret;
 
 	/* add an option to disable the gigabit feature of this PHY */
-	if (env_get("disable_giga")) {
+	if (env_get(ctx_uboot, "disable_giga")) {
 		unsigned features;
 		unsigned bmcr;
 
diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c
index 3707ee35eb5c..aa09fcb0ffc1 100644
--- a/drivers/net/sandbox-raw.c
+++ b/drivers/net/sandbox-raw.c
@@ -28,8 +28,8 @@ static int sb_eth_raw_start(struct udevice *dev)
 
 	ret = sandbox_eth_raw_os_start(priv, pdata->enetaddr);
 	if (priv->local) {
-		env_set("ipaddr", "127.0.0.1");
-		env_set("serverip", "127.0.0.1");
+		env_set(ctx_uboot, "ipaddr", "127.0.0.1");
+		env_set(ctx_uboot, "serverip", "127.0.0.1");
 		net_ip = string_to_ip("127.0.0.1");
 		net_server_ip = net_ip;
 	}
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 5db24f1c51d5..862452204c07 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -424,7 +424,7 @@ int pci_hose_scan(struct pci_controller *hose)
 
 	if (!gd->pcidelay_done) {
 		/* wait "pcidelay" ms (if defined)... */
-		s = env_get("pcidelay");
+		s = env_get(ctx_uboot, "pcidelay");
 		if (s) {
 			int val = simple_strtoul(s, NULL, 10);
 			for (i = 0; i < val; i++)
@@ -456,7 +456,7 @@ void pci_init(void)
 	hose_head = NULL;
 
 	/* allow env to disable pci init/enum */
-	if (env_get("pcidisable") != NULL)
+	if (env_get(ctx_uboot, "pcidisable"))
 		return;
 
 	/* now call board specific pci_init()... */
diff --git a/drivers/pci/pci_common.c b/drivers/pci/pci_common.c
index 5231b69dc9ad..007580066ca6 100644
--- a/drivers/pci/pci_common.c
+++ b/drivers/pci/pci_common.c
@@ -89,7 +89,7 @@ __weak int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev)
 		/*
 		 * Only skip configuration if "pciconfighost" is not set
 		 */
-		if (env_get("pciconfighost") == NULL)
+		if (!env_get(ctx_uboot, "pciconfighost"))
 			return 1;
 #else
 		return 1;
diff --git a/drivers/reset/reset-socfpga.c b/drivers/reset/reset-socfpga.c
index 93ec9cfdb64a..6fb7ecb97ac0 100644
--- a/drivers/reset/reset-socfpga.c
+++ b/drivers/reset/reset-socfpga.c
@@ -48,7 +48,7 @@ static bool socfpga_reset_keep_enabled(void)
 	const char *env_str;
 	long val;
 
-	env_str = env_get("socfpga_legacy_reset_compat");
+	env_str = env_get(ctx_uboot, "socfpga_legacy_reset_compat");
 	if (env_str) {
 		val = simple_strtol(env_str, NULL, 0);
 		if (val == 1)
diff --git a/drivers/rtc/m41t60.c b/drivers/rtc/m41t60.c
index 532d2105e12c..8829d2a3c2d2 100644
--- a/drivers/rtc/m41t60.c
+++ b/drivers/rtc/m41t60.c
@@ -198,7 +198,7 @@ int rtc_set(struct rtc_time *tmp)
 void rtc_reset(void)
 {
 	uchar *const data = rtc_validate();
-	char const *const s = env_get("rtccal");
+	char const *const s = env_get(ctx_uboot, "rtccal");
 
 	if (!data)
 		return;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 48cb2a2818bc..c6ca3447af19 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -681,7 +681,7 @@ int scsi_scan(bool verbose)
 
 	printf("Found %d device(s).\n", scsi_max_devs);
 #ifndef CONFIG_SPL_BUILD
-	env_set_ulong("scsidevs", scsi_max_devs);
+	env_set_ulong(ctx_uboot, "scsidevs", scsi_max_devs);
 #endif
 	return 0;
 }
diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
index 76d9c8a3a6df..cf4a37c9bb4a 100644
--- a/drivers/serial/usbtty.c
+++ b/drivers/serial/usbtty.c
@@ -526,7 +526,7 @@ int drv_usbtty_init (void)
 	int snlen;
 
 	/* Get serial number */
-	sn = env_get("serial#");
+	sn = env_get(ctx_uboot, "serial#");
 	if (!sn)
 		sn = "000000000000";
 	snlen = strlen(sn);
@@ -540,7 +540,7 @@ int drv_usbtty_init (void)
 
 	/* Decide on which type of UDC device to be.
 	 */
-	tt = env_get("usbtty");
+	tt = env_get(ctx_uboot, "usbtty");
 	if (!tt)
 		tt = "generic";
 	usbtty_init_terminal_type(strcmp(tt,"cdc_acm"));
diff --git a/drivers/usb/gadget/designware_udc.c b/drivers/usb/gadget/designware_udc.c
index 432f312cee4c..cc6bace8f639 100644
--- a/drivers/usb/gadget/designware_udc.c
+++ b/drivers/usb/gadget/designware_udc.c
@@ -601,7 +601,7 @@ void udc_setup_ep(struct usb_device_instance *device,
 	if ((ep != 0) && (udc_device->device_state < STATE_ADDRESSED))
 		return;
 
-	tt = env_get("usbtty");
+	tt = env_get(ctx_uboot, "usbtty");
 	if (!tt)
 		tt = "generic";
 
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index a118283984c2..e5cb96aa7e9d 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2355,12 +2355,12 @@ static int _usb_eth_init(struct ether_priv *priv)
 	strlcpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
 #endif
 	/* Check if the user overruled the MAC addresses */
-	if (env_get("usbnet_devaddr"))
-		strlcpy(dev_addr, env_get("usbnet_devaddr"),
+	if (env_get(ctx_uboot, "usbnet_devaddr"))
+		strlcpy(dev_addr, env_get(ctx_uboot, "usbnet_devaddr"),
 			sizeof(dev_addr));
 
-	if (env_get("usbnet_hostaddr"))
-		strlcpy(host_addr, env_get("usbnet_hostaddr"),
+	if (env_get(ctx_uboot, "usbnet_hostaddr"))
+		strlcpy(host_addr, env_get(ctx_uboot, "usbnet_hostaddr"),
 			sizeof(host_addr));
 
 	if (!is_eth_addr_valid(dev_addr)) {
@@ -2391,8 +2391,9 @@ static int _usb_eth_init(struct ether_priv *priv)
 	gadget = dev->gadget;
 	usb_gadget_connect(gadget);
 
-	if (env_get("cdc_connect_timeout"))
-		timeout = simple_strtoul(env_get("cdc_connect_timeout"),
+	if (env_get(ctx_uboot, "cdc_connect_timeout"))
+		timeout = simple_strtoul(env_get(ctx_uboot,
+						 "cdc_connect_timeout"),
 						NULL, 10) * CONFIG_SYS_HZ;
 	ts = get_timer(0);
 	while (!dev->network_started) {
diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
index 675615513304..ec730087116c 100644
--- a/drivers/usb/gadget/f_dfu.c
+++ b/drivers/usb/gadget/f_dfu.c
@@ -725,7 +725,7 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f)
 
 	cdev->req->context = f_dfu;
 
-	s = env_get("serial#");
+	s = env_get(ctx_uboot, "serial#");
 	if (s)
 		g_dnl_set_serialnumber((char *)s);
 
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index fc27dbe8de49..240b6c8936e5 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -185,7 +185,7 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
 		f->hs_descriptors = fb_hs_function;
 	}
 
-	s = env_get("serial#");
+	s = env_get(ctx_uboot, "serial#");
 	if (s)
 		g_dnl_set_serialnumber((char *)s);
 
diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c
index 1cfeabcd31ae..364da4c1d9d5 100644
--- a/drivers/usb/gadget/f_rockusb.c
+++ b/drivers/usb/gadget/f_rockusb.c
@@ -182,7 +182,7 @@ static int rockusb_bind(struct usb_configuration *c, struct usb_function *f)
 		f->hs_descriptors = rkusb_hs_function;
 	}
 
-	s = env_get("serial#");
+	s = env_get(ctx_uboot, "serial#");
 	if (s)
 		g_dnl_set_serialnumber((char *)s);
 
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index bcd1c5d47c10..ceadcc2e65c9 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -359,7 +359,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req)
 		return;
 
 #ifndef CONFIG_SPL_BUILD
-	env_set_hex("filesize", sdp->dnl_bytes);
+	env_set_hex(ctx_uboot, "filesize", sdp->dnl_bytes);
 #endif
 	printf("done\n");
 
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index ced295ef0fa4..b57d1fd6f667 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -240,7 +240,7 @@ static int ehci_fsl_init(int index, struct usb_ehci *ehci,
 				"phy_type", &len);
 #endif
 	else
-		phy_type = env_get("usb_phy_type");
+		phy_type = env_get(ctx_uboot, "usb_phy_type");
 
 	if (!phy_type) {
 #ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
diff --git a/drivers/video/ati_radeon_fb.c b/drivers/video/ati_radeon_fb.c
index 6fce03363690..76d8ec4e0b2b 100644
--- a/drivers/video/ati_radeon_fb.c
+++ b/drivers/video/ati_radeon_fb.c
@@ -637,7 +637,7 @@ void *video_hw_init(void)
 
 	videomode = CONFIG_SYS_DEFAULT_VIDEO_MODE;
 	/* get video mode via environment */
-	penv = env_get("videomode");
+	penv = env_get(ctx_uboot, "videomode");
 	if (penv) {
 		/* deceide if it is a string */
 		if (penv[0] <= '9') {
diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index e5c077e4f522..c073bd17618e 100644
--- a/drivers/video/cfb_console.c
+++ b/drivers/video/cfb_console.c
@@ -1861,7 +1861,7 @@ static void *video_logo(void)
 	splash_get_pos(&video_logo_xpos, &video_logo_ypos);
 
 #ifdef CONFIG_SPLASH_SCREEN
-	s = env_get("splashimage");
+	s = env_get(&ctx_boot, "splashimage");
 	if (s != NULL) {
 		ret = splash_screen_prepare();
 		if (ret < 0)
diff --git a/drivers/video/mb862xx.c b/drivers/video/mb862xx.c
index 301c1f0df179..18eeba4ca1ec 100644
--- a/drivers/video/mb862xx.c
+++ b/drivers/video/mb862xx.c
@@ -246,7 +246,7 @@ unsigned int card_init (void)
 	tmp = 0;
 	videomode = 0x310;
 	/* get video mode via environment */
-	penv = env_get("videomode");
+	penv = env_get(ctx_uboot, "videomode");
 	if (penv) {
 		/* decide if it is a string */
 		if (penv[0] <= '9') {
diff --git a/drivers/video/mx3fb.c b/drivers/video/mx3fb.c
index a984443ef9d7..6eda807b9da3 100644
--- a/drivers/video/mx3fb.c
+++ b/drivers/video/mx3fb.c
@@ -814,7 +814,7 @@ void *video_hw_init(void)
 
 	videomode = CONFIG_SYS_DEFAULT_VIDEO_MODE;
 	/* get video mode via environment */
-	penv = env_get("videomode");
+	penv = env_get(ctx_uboot, "videomode");
 	if (penv) {
 		/* decide if it is a string */
 		if (penv[0] <= '9') {
diff --git a/drivers/video/mxsfb.c b/drivers/video/mxsfb.c
index 6922a130c61a..5b03cead16cf 100644
--- a/drivers/video/mxsfb.c
+++ b/drivers/video/mxsfb.c
@@ -207,7 +207,7 @@ void *video_hw_init(void)
 	puts("Video: ");
 
 	/* Suck display configuration from "videomode" variable */
-	penv = env_get("videomode");
+	penv = env_get(ctx_uboot, "videomode");
 	if (!penv) {
 		puts("MXSFB: 'videomode' variable not set!\n");
 		return NULL;
diff --git a/drivers/video/videomodes.c b/drivers/video/videomodes.c
index ac25b45f8196..67130b992566 100644
--- a/drivers/video/videomodes.c
+++ b/drivers/video/videomodes.c
@@ -165,7 +165,7 @@ int video_get_params (struct ctfb_res_modes *pPar, char *penv)
 	/* first search for the environment containing the real param string */
 	s = penv;
 
-	p = env_get(s);
+	p = env_get(ctx_uboot, s);
 	if (p)
 		s = p;
 
@@ -235,7 +235,7 @@ int video_get_params (struct ctfb_res_modes *pPar, char *penv)
 int video_get_video_mode(unsigned int *xres, unsigned int *yres,
 	unsigned int *depth, unsigned int *freq, const char **options)
 {
-	char *p = env_get("video-mode");
+	char *p = env_get(ctx_uboot, "video-mode");
 	if (!p)
 		return 0;
 
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 14/19] fs: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (12 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 13/19] drivers: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 15/19] lib: converted with new env interfaces (except efi_loader) AKASHI Takahiro
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 fs/fs.c          | 14 +++++++-------
 fs/ubifs/ubifs.c |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index d8a4ced4698e..b26c94f89764 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -647,7 +647,7 @@ int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 	if (fs_size(argv[3], &size) < 0)
 		return CMD_RET_FAILURE;
 
-	env_set_hex("filesize", size);
+	env_set_hex(ctx_uboot, "filesize", size);
 
 	return 0;
 }
@@ -678,7 +678,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		if (ep == argv[3] || *ep != '\0')
 			return CMD_RET_USAGE;
 	} else {
-		addr_str = env_get("loadaddr");
+		addr_str = env_get(ctx_uboot, "loadaddr");
 		if (addr_str != NULL)
 			addr = simple_strtoul(addr_str, NULL, 16);
 		else
@@ -687,7 +687,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 	if (argc >= 5) {
 		filename = argv[4];
 	} else {
-		filename = env_get("bootfile");
+		filename = env_get(ctx_uboot, "bootfile");
 		if (!filename) {
 			puts("** No boot file defined **\n");
 			return 1;
@@ -720,8 +720,8 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 	}
 	puts("\n");
 
-	env_set_hex("fileaddr", addr);
-	env_set_hex("filesize", len_read);
+	env_set_hex(ctx_uboot, "fileaddr", addr);
+	env_set_hex(ctx_uboot, "filesize", len_read);
 
 	return 0;
 }
@@ -812,7 +812,7 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		return CMD_RET_FAILURE;
 
 	if (argc == 4)
-		env_set(argv[3], uuid);
+		env_set(ctx_uboot, argv[3], uuid);
 	else
 		printf("%s\n", uuid);
 
@@ -832,7 +832,7 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	info = fs_get_info(fs_type);
 
 	if (argc == 4)
-		env_set(argv[3], info->name);
+		env_set(ctx_uboot, argv[3], info->name);
 	else
 		printf("%s\n", info->name);
 
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 67a0e8caae70..7b16b16e068f 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -944,7 +944,7 @@ int ubifs_load(char *filename, u32 addr, u32 size)
 
 	err = ubifs_read(filename, (void *)(uintptr_t)addr, 0, size, &actread);
 	if (err == 0) {
-		env_set_hex("filesize", actread);
+		env_set_hex(ctx_uboot, "filesize", actread);
 		printf("Done\n");
 	}
 
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 15/19] lib: converted with new env interfaces (except efi_loader)
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (13 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 14/19] fs: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 16/19] net: converted with new env interfaces AKASHI Takahiro
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 lib/efi_loader/efi_console.c | 2 +-
 lib/fdtdec.c                 | 2 +-
 lib/smbios.c                 | 2 +-
 lib/uuid.c                   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index d4765afb9849..902938c9b7f0 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -260,7 +260,7 @@ out:
  */
 static void query_console_size(void)
 {
-	const char *stdout_name = env_get("stdout");
+	const char *stdout_name = env_get(ctx_uboot, "stdout");
 	int rows = 25, cols = 80;
 
 	if (stdout_name && !strcmp(stdout_name, "vidconsole") &&
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 74525c84e7bd..f0642ea61f85 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1541,7 +1541,7 @@ int fdtdec_setup(void)
 # ifndef CONFIG_SPL_BUILD
 	/* Allow the early environment to override the fdt address */
 	gd->fdt_blob = map_sysmem
-		(env_get_ulong("fdtcontroladdr", 16,
+		(env_get_ulong(ctx_uboot, "fdtcontroladdr", 16,
 			       (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
 # endif
 
diff --git a/lib/smbios.c b/lib/smbios.c
index 7b74971f6878..41a000cbd932 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -113,7 +113,7 @@ static int smbios_write_type1(ulong *current, int handle)
 {
 	struct smbios_type1 *t;
 	int len = sizeof(struct smbios_type1);
-	char *serial_str = env_get("serial#");
+	char *serial_str = env_get(ctx_uboot, "serial#");
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, sizeof(struct smbios_type1));
diff --git a/lib/uuid.c b/lib/uuid.c
index a48e19c06eaf..6498e8d6ac0e 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -299,7 +299,7 @@ int do_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (argc == 1)
 		printf("%s\n", uuid);
 	else
-		env_set(argv[1], uuid);
+		env_set(ctx_uboot, argv[1], uuid);
 
 	return CMD_RET_SUCCESS;
 }
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 16/19] net: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (14 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 15/19] lib: converted with new env interfaces (except efi_loader) AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 17/19] post: " AKASHI Takahiro
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 net/bootp.c      | 17 +++++++++--------
 net/dns.c        |  2 +-
 net/eth-uclass.c |  6 +++---
 net/eth_common.c | 18 +++++++++---------
 net/eth_legacy.c |  2 +-
 net/link_local.c |  2 +-
 net/net.c        | 11 ++++++-----
 net/tftp.c       | 10 +++++-----
 net/wol.c        |  2 +-
 9 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/net/bootp.c b/net/bootp.c
index 505489140e8a..3a9ca24e649f 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -176,7 +176,7 @@ static void store_net_params(struct bootp_hdr *bp)
 	 * not contain a new value
 	 */
 	if (*net_boot_file_name)
-		env_set("bootfile", net_boot_file_name);
+		env_set(ctx_uboot, "bootfile", net_boot_file_name);
 #endif
 	net_copy_ip(&net_ip, &bp->bp_yiaddr);
 }
@@ -395,7 +395,7 @@ static void bootp_timeout_handler(void)
 #ifdef CONFIG_BOOTP_MAY_FAIL
 		char *ethrotate;
 
-		ethrotate = env_get("ethrotate");
+		ethrotate = env_get(ctx_uboot, "ethrotate");
 		if ((ethrotate && strcmp(ethrotate, "no") == 0) ||
 		    net_restart_wrap) {
 			puts("\nRetry time exceeded\n");
@@ -427,7 +427,7 @@ static void bootp_timeout_handler(void)
 static u8 *add_vci(u8 *e)
 {
 	char *vci = NULL;
-	char *env_vci = env_get("bootp_vci");
+	char *env_vci = env_get(ctx_uboot, "bootp_vci");
 
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING)
 	vci = CONFIG_SPL_NET_VCI_STRING;
@@ -501,7 +501,7 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
 		*e++ = tmp & 0xff;
 	}
 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
-	hostname = env_get("hostname");
+	hostname = env_get(ctx_uboot, "hostname");
 	if (hostname) {
 		int hostnamelen = strlen(hostname);
 
@@ -516,8 +516,9 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
 	clientarch = CONFIG_BOOTP_PXE_CLIENTARCH;
 #endif
 
-	if (env_get("bootp_arch"))
-		clientarch = env_get_ulong("bootp_arch", 16, clientarch);
+	if (env_get(ctx_uboot, "bootp_arch"))
+		clientarch = env_get_ulong(ctx_uboot, "bootp_arch", 16,
+					   clientarch);
 
 	if (clientarch > 0) {
 		*e++ = 93;	/* Client System Architecture */
@@ -533,7 +534,7 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
 	*e++ = 0;	/* minor revision */
 
 #ifdef CONFIG_LIB_UUID
-	uuid = env_get("pxeuuid");
+	uuid = env_get(ctx_uboot, "pxeuuid");
 
 	if (uuid) {
 		if (uuid_str_valid(uuid)) {
@@ -726,7 +727,7 @@ void bootp_request(void)
 	dhcp_state = INIT;
 #endif
 
-	ep = env_get("bootpretryperiod");
+	ep = env_get(ctx_uboot, "bootpretryperiod");
 	if (ep != NULL)
 		time_taken_max = simple_strtoul(ep, NULL, 10);
 	else
diff --git a/net/dns.c b/net/dns.c
index 67d761d7c0f5..93e338e9cb22 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -185,7 +185,7 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 			ip_to_string(ip_addr, ip_str);
 			printf("%s\n", ip_str);
 			if (net_dns_env_var)
-				env_set(net_dns_env_var, ip_str);
+				env_set(ctx_uboot, net_dns_env_var, ip_str);
 		} else {
 			puts("server responded with invalid IP number\n");
 		}
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 1d5d2f03b7d9..d7bec3377e6f 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -240,8 +240,8 @@ U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
 
 int eth_init(void)
 {
-	char *ethact = env_get("ethact");
-	char *ethrotate = env_get("ethrotate");
+	char *ethact = env_get(ctx_uboot, "ethact");
+	char *ethrotate = env_get(ctx_uboot, "ethrotate");
 	struct udevice *current = NULL;
 	struct udevice *old_current;
 	int ret = -ENODEV;
@@ -401,7 +401,7 @@ int eth_initialize(void)
 		printf("No ethernet found.\n");
 		bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
 	} else {
-		char *ethprime = env_get("ethprime");
+		char *ethprime = env_get(ctx_uboot, "ethprime");
 		struct udevice *prime_dev = NULL;
 
 		if (ethprime)
diff --git a/net/eth_common.c b/net/eth_common.c
index ed26b1b69359..f845601a13b0 100644
--- a/net/eth_common.c
+++ b/net/eth_common.c
@@ -46,13 +46,13 @@ int eth_mac_skip(int index)
 	char *skip_state;
 
 	sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
-	skip_state = env_get(enetvar);
+	skip_state = env_get(ctx_uboot, enetvar);
 	return skip_state != NULL;
 }
 
 void eth_current_changed(void)
 {
-	char *act = env_get("ethact");
+	char *act = env_get(ctx_uboot, "ethact");
 	char *ethrotate;
 
 	/*
@@ -60,21 +60,21 @@ void eth_current_changed(void)
 	 * ethernet device if uc_priv->current == NULL. This is not what
 	 * we want when 'ethrotate' variable is 'no'.
 	 */
-	ethrotate = env_get("ethrotate");
+	ethrotate = env_get(ctx_uboot, "ethrotate");
 	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
 		return;
 
 	/* update current ethernet name */
 	if (eth_get_dev()) {
 		if (act == NULL || strcmp(act, eth_get_name()) != 0)
-			env_set("ethact", eth_get_name());
+			env_set(ctx_uboot, "ethact", eth_get_name());
 	}
 	/*
 	 * remove the variable completely if there is no active
 	 * interface
 	 */
 	else if (act != NULL)
-		env_set("ethact", NULL);
+		env_set(ctx_uboot, "ethact", NULL);
 }
 
 void eth_try_another(int first_restart)
@@ -86,7 +86,7 @@ void eth_try_another(int first_restart)
 	 * Do not rotate between network interfaces when
 	 * 'ethrotate' variable is set to 'no'.
 	 */
-	ethrotate = env_get("ethrotate");
+	ethrotate = env_get(ctx_uboot, "ethrotate");
 	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
 		return;
 
@@ -110,14 +110,14 @@ void eth_set_current(void)
 	static int  env_changed_id;
 	int	env_id;
 
-	env_id = env_get_id();
+	env_id = env_get_id(ctx_uboot);
 	if ((act == NULL) || (env_changed_id != env_id)) {
-		act = env_get("ethact");
+		act = env_get(ctx_uboot, "ethact");
 		env_changed_id = env_id;
 	}
 
 	if (act == NULL) {
-		char *ethprime = env_get("ethprime");
+		char *ethprime = env_get(ctx_uboot, "ethprime");
 		void *dev = NULL;
 
 		if (ethprime)
diff --git a/net/eth_legacy.c b/net/eth_legacy.c
index 850f362d873e..a166244e18bf 100644
--- a/net/eth_legacy.c
+++ b/net/eth_legacy.c
@@ -260,7 +260,7 @@ int eth_initialize(void)
 		bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
 	} else {
 		struct eth_device *dev = eth_devices;
-		char *ethprime = env_get("ethprime");
+		char *ethprime = env_get(ctx_uboot, "ethprime");
 
 		bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
 		do {
diff --git a/net/link_local.c b/net/link_local.c
index dd9fcad0874d..c0adc583fb71 100644
--- a/net/link_local.c
+++ b/net/link_local.c
@@ -105,7 +105,7 @@ static void configure_wait(void)
 
 void link_local_start(void)
 {
-	ip = env_get_ip("llipaddr");
+	ip = env_get_ip(ctx_uboot, "llipaddr");
 	if (ip.s_addr != 0 &&
 	    (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
 		puts("invalid link address");
diff --git a/net/net.c b/net/net.c
index 40511db645df..92e3c9fa8016 100644
--- a/net/net.c
+++ b/net/net.c
@@ -306,7 +306,7 @@ U_BOOT_ENV_CALLBACK(dnsip, on_dnsip);
 void net_auto_load(void)
 {
 #if defined(CONFIG_CMD_NFS)
-	const char *s = env_get("autoload");
+	const char *s = env_get(ctx_uboot, "autoload");
 
 	if (s != NULL && strcmp(s, "NFS") == 0) {
 		if (net_check_prereq(NFS)) {
@@ -635,8 +635,9 @@ restart:
 			if (net_boot_file_size > 0) {
 				printf("Bytes transferred = %d (%x hex)\n",
 				       net_boot_file_size, net_boot_file_size);
-				env_set_hex("filesize", net_boot_file_size);
-				env_set_hex("fileaddr", load_addr);
+				env_set_hex(ctx_uboot, "filesize",
+					    net_boot_file_size);
+				env_set_hex(ctx_uboot, "fileaddr", load_addr);
 			}
 			if (protocol != NETCONS)
 				eth_halt();
@@ -689,7 +690,7 @@ int net_start_again(void)
 	unsigned long retrycnt = 0;
 	int ret;
 
-	nretry = env_get("netretry");
+	nretry = env_get(ctx_uboot, "netretry");
 	if (nretry) {
 		if (!strcmp(nretry, "yes"))
 			retry_forever = 1;
@@ -1612,7 +1613,7 @@ ushort string_to_vlan(const char *s)
 
 ushort env_get_vlan(char *var)
 {
-	return string_to_vlan(env_get(var));
+	return string_to_vlan(env_get(ctx_uboot, var));
 }
 
 void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr)
diff --git a/net/tftp.c b/net/tftp.c
index 5a69bca6413c..452628dd7f8c 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -629,11 +629,11 @@ void tftp_start(enum proto_t protocol)
 	 * TFTP protocol has a minimal timeout of 1 second.
 	 */
 
-	ep = env_get("tftpblocksize");
+	ep = env_get(ctx_uboot, "tftpblocksize");
 	if (ep != NULL)
 		tftp_block_size_option = simple_strtol(ep, NULL, 10);
 
-	ep = env_get("tftptimeout");
+	ep = env_get(ctx_uboot, "tftptimeout");
 	if (ep != NULL)
 		timeout_ms = simple_strtol(ep, NULL, 10);
 
@@ -643,7 +643,7 @@ void tftp_start(enum proto_t protocol)
 		timeout_ms = 1000;
 	}
 
-	ep = env_get("tftptimeoutcountmax");
+	ep = env_get(ctx_uboot, "tftptimeoutcountmax");
 	if (ep != NULL)
 		tftp_timeout_count_max = simple_strtol(ep, NULL, 10);
 
@@ -743,10 +743,10 @@ void tftp_start(enum proto_t protocol)
 	tftp_our_port = 1024 + (get_timer(0) % 3072);
 
 #ifdef CONFIG_TFTP_PORT
-	ep = env_get("tftpdstp");
+	ep = env_get(ctx_uboot, "tftpdstp");
 	if (ep != NULL)
 		tftp_remote_port = simple_strtol(ep, NULL, 10);
-	ep = env_get("tftpsrcp");
+	ep = env_get(ctx_uboot, "tftpsrcp");
 	if (ep != NULL)
 		tftp_our_port = simple_strtol(ep, NULL, 10);
 #endif
diff --git a/net/wol.c b/net/wol.c
index 0a625668a992..9afd7149f34c 100644
--- a/net/wol.c
+++ b/net/wol.c
@@ -56,7 +56,7 @@ void wol_receive(struct ip_udp_hdr *ip, unsigned int len)
 		struct in_addr *ip = (struct in_addr *)(wol->wol_passwd);
 
 		ip_to_string(*ip, buffer);
-		env_set("wolpassword", buffer);
+		env_set(ctx_uboot, "wolpassword", buffer);
 	}
 	net_set_state(NETLOOP_SUCCESS);
 }
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 17/19] post: converted with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (15 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 16/19] net: converted with new env interfaces AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables AKASHI Takahiro
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

env_xxx(...) -> env_xxx(ctx_uboot, ...)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 post/post.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/post/post.c b/post/post.c
index fb751d9a83a5..d8a8279123cc 100644
--- a/post/post.c
+++ b/post/post.c
@@ -176,7 +176,7 @@ static void post_get_env_flags(int *test_flags)
 	int i, j;
 
 	for (i = 0; i < varnum; i++) {
-		if (env_get_f(var[i], list, sizeof(list)) <= 0)
+		if (env_get_f(ctx_uboot, var[i], list, sizeof(list)) <= 0)
 			continue;
 
 		for (j = 0; j < post_list_size; j++)
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (16 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 17/19] post: " AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05 19:37   ` Heinrich Schuchardt
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 19/19] efi_loader: variable: rework with new env interfaces AKASHI Takahiro
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

We will use two environment contexts for implementing UEFI variables,
one (ctx_efi) for non-volatile variables and the other for volatile
variables. The latter doesn't have a backing storage.

Those two contexts are currently used only in efi_variable.c and
can be moved into there if desired. But I let it under env/ for
future use elsewhere.

In this commit, FAT file system and flash device are only supported
devices for backing storages, but extending to other devices will be
quite straightforward.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 env/Kconfig       |   1 +
 env/Kconfig.efi   | 152 ++++++++++++++++++++++++++++++++++++++++++++++
 env/Makefile      |   1 +
 env/env_ctx_efi.c | 131 +++++++++++++++++++++++++++++++++++++++
 include/env.h     |   3 +
 5 files changed, 288 insertions(+)
 create mode 100644 env/Kconfig.efi
 create mode 100644 env/env_ctx_efi.c

diff --git a/env/Kconfig b/env/Kconfig
index ae96cf75bbaa..0cd3caa67376 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -47,5 +47,6 @@ config ENV_DRV_UBI
 	bool
 
 source "env/Kconfig.uboot"
+source "env/Kconfig.efi"
 
 endmenu
diff --git a/env/Kconfig.efi b/env/Kconfig.efi
new file mode 100644
index 000000000000..cd4e78989df6
--- /dev/null
+++ b/env/Kconfig.efi
@@ -0,0 +1,152 @@
+if EFI_LOADER
+
+menu "Configure UEFI context"
+
+config ENV_EFI_IS_NOWHERE
+	bool
+	default y if !ENV_EFI_IS_INFLASH && !ENV_EFI_IS_IN_FAT
+
+config ENV_EFI_IS_IN_FAT
+	bool "EFI Environment is in a FAT filesystem"
+	select ENV_DRV_FAT
+	help
+	  Define this if you want to use the FAT file system for
+	  the environment.
+
+config ENV_EFI_IS_IN_FLASH
+	bool "EFI Environment in flash memory"
+	select ENV_DRV_FLASH
+	help
+	  Define this if you have a flash device which you want to use
+	  for the environment.
+
+	  a) The environment occupies one whole flash sector, which is
+	   "embedded" in the text segment with the U-Boot code. This
+	   happens usually with "bottom boot sector" or "top boot
+	   sector" type flash chips, which have several smaller
+	   sectors at the start or the end. For instance, such a
+	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
+	   such a case you would place the environment in one of the
+	   4 kB sectors - with U-Boot code before and after it. With
+	   "top boot sector" type flash chips, you would put the
+	   environment in one of the last sectors, leaving a gap
+	   between U-Boot and the environment.
+
+	  CONFIG_ENV_EFI_OFFSET:
+
+	   Offset of environment data (variable area) to the
+	   beginning of flash memory; for instance, with bottom boot
+	   type flash chips the second sector can be used: the offset
+	   for this sector is given here.
+
+	   CONFIG_ENV_EFI_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
+
+	  CONFIG_ENV_EFI_ADDR:
+
+	   This is just another way to specify the start address of
+	   the flash sector containing the environment (instead of
+	   CONFIG_ENV_OFFSET).
+
+	  CONFIG_ENV_EFI_SECT_SIZE:
+
+	   Size of the sector containing the environment.
+
+
+	  b) Sometimes flash chips have few, equal sized, BIG sectors.
+	   In such a case you don't want to spend a whole sector for
+	   the environment.
+
+	  CONFIG_ENV_EFI_SIZE:
+
+	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
+	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
+	   of this flash sector for the environment. This saves
+	   memory for the RAM copy of the environment.
+
+	   It may also save flash memory if you decide to use this
+	   when your environment is "embedded" within U-Boot code,
+	   since then the remainder of the flash sector could be used
+	   for U-Boot code. It should be pointed out that this is
+	   STRONGLY DISCOURAGED from a robustness point of view:
+	   updating the environment in flash makes it always
+	   necessary to erase the WHOLE sector. If something goes
+	   wrong before the contents has been restored from a copy in
+	   RAM, your target system will be dead.
+
+	  CONFIG_ENV_EFI_ADDR_REDUND
+	  CONFIG_ENV_EFI_SIZE_REDUND
+
+	   These settings describe a second storage area used to hold
+	   a redundant copy of the environment data, so that there is
+	   a valid backup copy in case there is a power failure during
+	   a "saveenv" operation.
+
+	  BE CAREFUL! Any changes to the flash layout, and some changes to the
+	  source code will make it necessary to adapt <board>/u-boot.lds*
+	  accordingly!
+
+config ENV_EFI_FAT_INTERFACE
+	string "Name of the block device for the environment"
+	depends on ENV_EFI_IS_IN_FAT
+	help
+	  Define this to a string that is the name of the block device.
+
+config ENV_EFI_FAT_DEVICE_AND_PART
+	string "Device and partition for where to store the environment in FAT"
+	depends on ENV_EFI_IS_IN_FAT
+	help
+	  Define this to a string to specify the partition of the device.
+	  It can be as following:
+
+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
+	       - "D:P": device D partition P. Error occurs if device D has no
+	                partition table.
+	       - "D:0": device D.
+	       - "D" or "D:": device D partition 1 if device D has partition
+	                      table, or the whole device D if has no partition
+	                      table.
+	       - "D:auto": first partition in device D with bootable flag set.
+	                   If none, first valid partition in device D. If no
+	                   partition table then means device D.
+
+config ENV_EFI_FAT_FILE
+	string "Name of the FAT file to use for the environment"
+	depends on ENV_EFI_IS_IN_FAT
+	default "uboot_efi.env"
+	help
+	  It's a string of the FAT file name. This file use to store the
+	  environment.
+
+config ENV_EFI_ADDR
+	hex "EFI Environment Address"
+	help
+	  Start address of the device (or partition)
+
+config ENV_EFI_OFFSET
+	hex "EFI Environment Offset"
+	help
+	  Offset from the start of the device (or partition)
+
+config ENV_EFI_SIZE
+	hex "EFI Environment Size"
+	help
+	  Size of the environment storage area
+
+config ENV_EFI_SECT_SIZE
+	hex "EFI Environment Sector-Size"
+	help
+	  Size of the sector containing the environment.
+
+config ENV_EFI_ADDR_REDUND
+	hex "EFI Environment Address for second area"
+	help
+	  Start address of the device (or partition)
+
+config ENV_EFI_SIZE_REDUND
+	hex "EFI Environment Size for second area"
+	help
+	  Size of the environment second storage area
+
+endmenu
+
+endif
diff --git a/env/Makefile b/env/Makefile
index 0168eb47f00d..b6690c73b17f 100644
--- a/env/Makefile
+++ b/env/Makefile
@@ -4,6 +4,7 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 
 obj-y += common.o env.o env_ctx_uboot.o
+obj-$(CONFIG_EFI_LOADER) += env_ctx_efi.o
 
 ifndef CONFIG_SPL_BUILD
 obj-y += attr.o
diff --git a/env/env_ctx_efi.c b/env/env_ctx_efi.c
new file mode 100644
index 000000000000..9b5b2f392179
--- /dev/null
+++ b/env/env_ctx_efi.c
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Linaro Limited
+ *		Author: AKASHI Takahiro
+ */
+
+#include <common.h>
+#include <env_flags.h>
+#include <env_internal.h>
+#include <search.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct hsearch_data efi_htab = {
+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
+	/* defined in flags.c, only compile with ENV_SUPPORT */
+	.change_ok = env_flags_validate,
+#endif
+};
+
+struct hsearch_data efi_volatile_htab = {
+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
+	/* defined in flags.c, only compile with ENV_SUPPORT */
+	.change_ok = env_flags_validate,
+#endif
+};
+
+static int env_drv_init_efi(struct env_context *ctx, enum env_location loc)
+{
+	__maybe_unused int ret;
+
+	switch (loc) {
+#ifdef CONFIG_ENV_EFI_IS_IN_FLASH
+	case ENVL_FLASH: {
+		env_t *env_ptr;
+		env_t *flash_addr;
+		ulong end_addr;
+		env_t *flash_addr_new;
+		ulong end_addr_new;
+
+#if defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(CMD_SAVEENV) || \
+	!defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(INITENV)
+#ifdef ENV_IS_EMBEDDED
+		/* FIXME: not allowed */
+		env_ptr = NULL;
+#else /* ! ENV_IS_EMBEDDED */
+
+		env_ptr = (env_t *)CONFIG_ENV_EFI_ADDR;
+#endif /* ENV_IS_EMBEDDED */
+#else
+		env_ptr = NULL;
+#endif
+		flash_addr = (env_t *)CONFIG_ENV_EFI_ADDR;
+
+/* CONFIG_ENV_EFI_ADDR is supposed to be on sector boundary */
+		end_addr = CONFIG_ENV_EFI_ADDR + CONFIG_ENV_EFI_SECT_SIZE - 1;
+
+#ifdef CONFIG_ENV_EFI_ADDR_REDUND
+		flash_addr_new = (env_t *)CONFIG_ENV_EFI_ADDR_REDUND;
+/* CONFIG_ENV_EFI_ADDR_REDUND is supposed to be on sector boundary */
+		end_addr_new = CONFIG_ENV_EFI_ADDR_REDUND
+					+ CONFIG_ENV_EFI_SECT_SIZE - 1;
+#else
+		flash_addr_new = NULL;
+		end_addr_new = 0;
+#endif /* CONFIG_ENV_EFI_ADDR_REDUND */
+
+		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
+					    flash_addr_new, end_addr_new,
+					    NULL);
+		if (ret)
+			return -ENOENT;
+
+		return 0;
+		}
+#endif
+#ifdef CONFIG_ENV_EFI_IS_IN_FAT
+	case ENVL_FAT: {
+		ret = env_fat_init_params(ctx,
+					  CONFIG_ENV_EFI_FAT_INTERFACE,
+					  CONFIG_ENV_EFI_FAT_DEVICE_AND_PART,
+					  CONFIG_ENV_EFI_FAT_FILE);
+
+		return 0;
+		}
+#endif
+#ifdef CONFIG_ENV_DRV_NONE
+	case ENVL_NOWHERE:
+#ifdef CONFIG_ENV_EFI_IS_NOWHERE
+		/* TODO: what we should do */
+
+		return -ENOENT;
+#else
+		return -ENOENT;
+#endif
+#endif
+	default:
+		return -ENOENT;
+	}
+}
+
+/*
+ * Env context for UEFI variables
+ */
+U_BOOT_ENV_CONTEXT(efi) = {
+	.name = "efi",
+	.htab = &efi_htab,
+	.env_size = 0x10000, /* TODO: make this configurable */
+	.drv_init = env_drv_init_efi,
+};
+
+static int env_ctx_init_efi_volatile(struct env_context *ctx)
+{
+	/* Dummy table creation, or hcreate_r()? */
+	if (!himport_r(ctx->htab, NULL, 0, 0, 0, 0, 0, NULL)) {
+		debug("%s: Creating entry tables failed (ret=%d)\n", __func__,
+		      errno);
+		return errno;
+	}
+
+	env_set_ready(ctx);
+
+	return 0;
+}
+
+U_BOOT_ENV_CONTEXT(efi_volatile) = {
+	.name = "efi_volatile",
+	.htab = &efi_volatile_htab,
+	.env_size = 0,
+	.init = env_ctx_init_efi_volatile,
+};
diff --git a/include/env.h b/include/env.h
index 8045dda9f811..ec241d419a8a 100644
--- a/include/env.h
+++ b/include/env.h
@@ -66,6 +66,9 @@ enum env_redund_flags {
 };
 
 #define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)
+#define ctx_efi ll_entry_get(struct env_context, efi, env_contexts)
+#define ctx_efi_volatile ll_entry_get(struct env_context, efi_volatile, \
+				      env_contexts)
 
 /* Accessor functions */
 void env_set_ready(struct env_context *ctx);
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 19/19] efi_loader: variable: rework with new env interfaces
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (17 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables AKASHI Takahiro
@ 2019-09-05  8:21 ` AKASHI Takahiro
  2019-09-05  8:31 ` [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
  2019-10-01  6:28 ` AKASHI Takahiro
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:21 UTC (permalink / raw)
  To: u-boot

In the previous commit, two efi-related contexts were introduced.

With this patch, EFI variables implementation will be modified to
support volatile/non-volatile attribute properly in such away as UEFI
specification expects; If a variable is non-volatile and modified,
its value will be updated in backing storage immediately and preserved
across reboot. If volatile, it will be lost after reboot.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 lib/efi_loader/efi_variable.c | 91 ++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 8 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 6687b69a400d..18b9e9e5d9f5 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -185,7 +185,9 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
 
 	EFI_PRINT("get '%s'\n", native_name);
 
-	val = env_get(native_name);
+	val = env_get(ctx_efi, native_name);
+	if (!val)
+		val = env_get(ctx_efi_volatile, native_name);
 	free(native_name);
 	if (!val)
 		return EFI_EXIT(EFI_NOT_FOUND);
@@ -388,12 +390,48 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
 		efi_cur_variable = NULL;
 
 		snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*");
-		list_len = hexport_r(&env_htab, '\n',
+		list_len = hexport_r(ctx_efi->htab, '\n',
 				     H_MATCH_REGEX | H_MATCH_KEY,
 				     &efi_variables_list, 0, 1, regexlist);
 		/* 1 indicates that no match was found */
-		if (list_len <= 1)
-			return EFI_EXIT(EFI_NOT_FOUND);
+		if (list_len <= 1) {
+			list_len = hexport_r(ctx_efi_volatile->htab, '\n',
+					     H_MATCH_REGEX | H_MATCH_KEY,
+					     &efi_variables_list, 0, 1,
+					     regexlist);
+
+			if (list_len <= 1)
+				return EFI_EXIT(EFI_NOT_FOUND);
+		} else {
+			char *list_volatile, *list_tmp;
+			size_t total_len;
+
+			list_volatile = NULL;
+			total_len = list_len;
+			list_len = hexport_r(ctx_efi_volatile->htab, '\n',
+					     H_MATCH_REGEX | H_MATCH_KEY,
+					     &list_volatile, 0, 1,
+					     regexlist);
+
+			/* concatenate two lists */
+			if (list_len > 1) {
+				total_len += list_len - 1;
+				list_tmp = efi_variables_list;
+
+				efi_variables_list = malloc(total_len);
+				if (efi_variables_list) {
+					strcpy(efi_variables_list, list_tmp);
+					strcat(efi_variables_list,
+					       list_volatile);
+				}
+
+				free(list_tmp);
+				free(list_volatile);
+
+				if (!efi_variables_list)
+					return EFI_EXIT(EFI_OUT_OF_RESOURCES);
+			}
+		}
 
 		variable = efi_variables_list;
 	}
@@ -424,8 +462,9 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
 				     efi_uintn_t data_size, const void *data)
 {
 	char *native_name = NULL, *val = NULL, *s;
+	struct env_context *ctx;
+	u32 attr, non_volatile;
 	efi_status_t ret = EFI_SUCCESS;
-	u32 attr;
 
 	EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,
 		  data_size, data);
@@ -447,12 +486,17 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
 
 	if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
 		/* delete the variable: */
-		env_set(native_name, NULL);
+		env_set(ctx_efi, native_name, NULL);
 		ret = EFI_SUCCESS;
 		goto out;
 	}
 
-	val = env_get(native_name);
+	if (attributes & EFI_VARIABLE_NON_VOLATILE)
+		ctx = ctx_efi;
+	else
+		ctx = ctx_efi_volatile;
+
+	val = env_get(ctx, native_name);
 	if (val) {
 		parse_attr(val, &attr);
 
@@ -485,6 +529,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
 	 * store attributes
 	 * TODO: several attributes are not supported
 	 */
+	non_volatile = (attributes & EFI_VARIABLE_NON_VOLATILE);
 	attributes &= (EFI_VARIABLE_NON_VOLATILE |
 		       EFI_VARIABLE_BOOTSERVICE_ACCESS |
 		       EFI_VARIABLE_RUNTIME_ACCESS);
@@ -512,7 +557,9 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
 
 	EFI_PRINT("setting: %s=%s\n", native_name, val);
 
-	if (env_set(native_name, val))
+	if (env_set(ctx, native_name, val))
+		ret = EFI_DEVICE_ERROR;
+	else if (non_volatile && env_save(ctx))
 		ret = EFI_DEVICE_ERROR;
 
 out:
@@ -619,5 +666,33 @@ void efi_variables_boot_exit_notify(void)
  */
 efi_status_t efi_init_variables(void)
 {
+	int ret;
+
+	/*
+	 * Volatile variables:
+	 * Context for volatile variables has no backing storage
+	 */
+	ret = env_ctx_init(ctx_efi_volatile);
+	if (ret) {
+		printf("Initializing efi variables(volatile) failed\n");
+
+		return EFI_DEVICE_ERROR;
+	}
+
+	/* Non-Volatile variables */
+	ret = env_ctx_init(ctx_efi);
+	if (ret) {
+		printf("Initializing efi variables failed\n");
+
+		return EFI_DEVICE_ERROR;
+	}
+
+	ret = env_load(ctx_efi);
+	if (ret && ret != -ENODEV) {
+		printf("Loading efi variables failed\n");
+
+		return EFI_DEVICE_ERROR;
+	}
+
 	return EFI_SUCCESS;
 }
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (18 preceding siblings ...)
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 19/19] efi_loader: variable: rework with new env interfaces AKASHI Takahiro
@ 2019-09-05  8:31 ` AKASHI Takahiro
  2019-10-01  6:28 ` AKASHI Takahiro
  20 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-05  8:31 UTC (permalink / raw)
  To: u-boot

One more issue:
* Currently, Travis CI fails in lots of builds.
  I will try to fix them in the succeeding versions.

-Takahiro Akashi

On Thu, Sep 05, 2019 at 05:21:14PM +0900, AKASHI Takahiro wrote:
> # In version 5 of this patch set, the implementation is changed again.
> #
> # I believe that this is NOT intrusive, and that my approach here is NOT
> # selfish at all. If Wolfgang doesn't accept this approach, however,
> # I would like to go for "Plan B" for UEFI variables implementation, in
> # which EFI will have its own drivers for storage instead of env/*.
> 
> This patch set is an attempt to implement non-volatile attribute for
> UEFI variables. Under the current implementation,
> * SetVariable API doesn't recognize non-volatile attribute
> * While some variables are defined non-volatile in UEFI specification,
>   they are NOT marked as non-volatile in the code.
> * env_save() (or "env save" command) allows us to save all the variables
>   into persistent storage, but it may cause volatile UEFI variables,
>   along with irrelevant U-Boot variables, to be saved unconditionally.
> 
> Those observation rationalizes that the implementation of UEFI variables
> should be revamped utilizing dedicated storage for them.
> 
> 
> Basic ideas:
> * Sub-system users of U-Boot environment variables may have their own
>   "env contexts". More than one contexts allowed.
> 
>   See Patch#2 and Patch#18.
> 
> * Each context is isolated from other contexts with different name spaces.
> * Each context is associated with one backing storage driver and media
>   location.
> * Different contexts may use different drivers and locations.
> 
> * To access (get or set) a variable, associated context must be presented.
>   So, almost of all existing env interfaces are changed to accept one
>   extra argument, ctx.
>   (I believe that this is Wolfgang's *requirement*.)
> 
>   From viewpoint of APIs, env context is a pointer to opaque structure.
> 
> * Non-volatile feature is not implemented in a general form and must be
>   implemented by users in their sub-systems.
> 
>   In version 4, U-Boot environment's attributes are extended to support
>   non-volatile (or auto-save capability), but Wolfgang rejected
>   my approach.
>   As modifying attributes for this purpose would cause bunch of
>   incompatibility issues (as far as I said in my cover letter and
>   the discussions in ML), I would prefer a much simple approach.
> 
>   See patch#19 about how it is easily implemented for UEFI variables.
> 
> * Each backing storage driver must be converted to be aligned with
>   new env interfaces to handle multiple contexts in parallel and
>   provide context-specific Kconfig configurations for driver parameters.
> 
>   In this version, only FAT file system and flash devices are supported,
>   but it is quite straightforward to modify other drivers.
> 
>   See Patch#4 and Patch#5 about how drivers can shift to new interfaces.
> 
> * Finally, all existing U-Boot variables hold the same semantics
>   as before.
> 
> 
> Known issues/restriction/TODO:
> * The current form of patchset is not 'bisect'able.
>   Not to break 'bisect,' all the patches in this patch set must be
>   put into a single commit when merging.
>   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> 
> * Unfortunately, this code fails to read U-Boot environment from flash
>   at boot time due to incomprehensible memory corruption.
>   See murky workaround, which is marked as FIXME, in env/flash.c.
> 
>   Despite this bug, I was still be able to run/test my patch by hacking
>   the code with gdb.
>   (modifying data to correct value on the fly :)
>   I hope that it won't affect code review in most places for now.
> 
> * Some minor issues for better coding.
>   They are also marked as FIXME in the source code.
> 
> * Only FAT file system and flash are supported.
> 
> * The whole area of storage will be saved at *every* update of
>   one UEFI variable. It should be optimized if possible.
> 
> * An error during "save" operation may cause inconsistency between
>   cache (hash table) and the storage.
>     -> This is not UEFI specific though.
> 
> * Add tests if necessary.
> 
> * I cannot test all the platforms affected by this patchset.
> 
> 
> Note:
> If we need "secure storage" for UEFI variables, efi_get_variable/
> efi_get_next_variable_name/efi_set_variable() should be completely
> replaced with stub functions to communicate with secure world.
> This patchset has nothing to do with such an implementation.
> 
> 
> Usage:
> To enable this feature for example with FAT file system, the following
> configs must be enabled:
>   CONFIG_ENV_IS_IN_FAT
>   CONFIG_ENV_FAT_INTERFACE
>   CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
>   CONFIG_ENV_EFI_FAT_FILE
> 
> You may define a non-volatile variable from command interface:
> => setenv -e -nv FOO baa
> => printenv -e FOO
> FOO: NV|BS|RT, DataSize = 0x3
>     00000000: 62 61 61                                         baa
> 
> 
> Patch#1 and #2 are to add multiples 'context' support to env interfaces
>   and to provide new env interfaces.
> Patch#3 to #5 are to show how the existing drivers for U-Boot environment
>   should be modified to be aligned with new env interfaces.
>   (Only FAT file system and flash in this version of patch set.)
> Patch#6 to #17 are to shift all the existing users of old env interfaces
>   to new ones. (But not tested for all the platforms.)
> Patch#18 and #19 are to modify UEFI variable implementation to utilize
>   new env interfaces.
> 
> Changes in v5 (September 4, 2019)
> * rebased to v2019.10-rc3
> * revamp the implementation, removing changes on environment variable's
>   attributes (See above)
> 
> Changes in v4 (July 17, 2019)
> * remove already-merged patches
> * revamp after Wolfgang's suggestion
> 
> Changes in v3 (June 4, 2019)
> * remove already-merged patches
> * revamp the code again
> * introduce CONFIG_EFI_VARIABLE_USE_ENV for this configuration.
>   Once another backing storage, i.e. StMM services for secure boot,
>   is supported, another option will be added.
> 
> Changes in v2 (Apr 24, 2019)
> * rebased on efi-2019-07
> * revamp the implementation
> 
> v1 (Nov 28, 2018)
> * initial
> 
> AKASHI Takahiro (19):
>   env: extend interfaces allowing for env contexts
>   env: define env context for U-Boot environment
>   env: nowhere: rework with new env interfaces
>   env: flash: support multiple env contexts
>   env: fat: support multiple env contexts
>   hashtable: support multiple env contexts
>   api: converted with new env interfaces
>   arch: converted with new env interfaces
>   board: converted with new env interfaces
>   cmd: converted with new env interfaces
>   common: converted with new env interfaces
>   disk: converted with new env interfaces
>   drivers: converted with new env interfaces
>   fs: converted with new env interfaces
>   lib: converted with new env interfaces (except efi_loader)
>   net: converted with new env interfaces
>   post: converted with new env interfaces
>   env,efi_loader: define env context for UEFI variables
>   efi_loader: variable: rework with new env interfaces
> 
>  api/api.c                                     |   8 +-
>  arch/arc/lib/bootm.c                          |   2 +-
>  arch/arm/cpu/arm926ejs/spear/spr_misc.c       |   8 +-
>  arch/arm/cpu/armv8/fsl-layerscape/cpu.c       |   5 +-
>  arch/arm/cpu/armv8/fsl-layerscape/soc.c       |  14 +-
>  arch/arm/lib/bootm.c                          |   6 +-
>  arch/arm/lib/semihosting.c                    |   2 +-
>  arch/arm/mach-imx/mx6/opos6ul.c               |   4 +-
>  arch/arm/mach-imx/mx7/soc.c                   |   4 +-
>  arch/arm/mach-imx/video.c                     |   2 +-
>  arch/arm/mach-keystone/ddr3.c                 |   2 +-
>  arch/arm/mach-keystone/keystone.c             |   2 +-
>  arch/arm/mach-kirkwood/cpu.c                  |   4 +-
>  arch/arm/mach-meson/board-common.c            |   2 +-
>  arch/arm/mach-omap2/utils.c                   |  20 +-
>  arch/arm/mach-rmobile/cpu_info.c              |   2 +-
>  arch/arm/mach-rockchip/boot_mode.c            |   4 +-
>  arch/arm/mach-rockchip/rk3288/rk3288.c        |   2 +-
>  arch/arm/mach-socfpga/misc_gen5.c             |   5 +-
>  arch/arm/mach-socfpga/misc_s10.c              |   2 +-
>  arch/arm/mach-stm32mp/cpu.c                   |  35 +-
>  arch/arm/mach-tegra/board2.c                  |   4 +-
>  arch/arm/mach-tegra/cboot.c                   |  18 +-
>  arch/arm/mach-uniphier/board_late_init.c      |  19 +-
>  arch/arm/mach-uniphier/mmc-first-dev.c        |   2 +-
>  arch/m68k/lib/bootm.c                         |   2 +-
>  arch/microblaze/lib/bootm.c                   |   2 +-
>  arch/mips/lib/bootm.c                         |   6 +-
>  arch/nds32/lib/bootm.c                        |   4 +-
>  arch/powerpc/cpu/mpc85xx/cpu_init.c           |  10 +-
>  arch/powerpc/cpu/mpc85xx/fdt.c                |   2 +-
>  arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |   2 +-
>  arch/powerpc/lib/bootm.c                      |   2 +-
>  arch/sh/lib/bootm.c                           |   2 +-
>  arch/sh/lib/zimageboot.c                      |   2 +-
>  arch/x86/lib/zimage.c                         |  11 +-
>  arch/xtensa/lib/bootm.c                       |   2 +-
>  board/Arcturus/ucp1020/cmd_arc.c              |  40 +-
>  board/Arcturus/ucp1020/ucp1020.c              |  16 +-
>  board/BuR/brppt1/board.c                      |   4 +-
>  board/BuR/brxre1/board.c                      |   9 +-
>  board/BuR/common/br_resetc.c                  |   2 +-
>  board/BuR/common/common.c                     |  47 +-
>  board/BuS/eb_cpu5282/eb_cpu5282.c             |   8 +-
>  board/CZ.NIC/turris_mox/turris_mox.c          |   4 +-
>  board/CZ.NIC/turris_omnia/turris_omnia.c      |   6 +-
>  board/CarMediaLab/flea3/flea3.c               |   2 +-
>  board/LaCie/net2big_v2/net2big_v2.c           |   2 +-
>  board/LaCie/netspace_v2/netspace_v2.c         |   2 +-
>  board/Synology/ds414/cmd_syno.c               |   6 +-
>  board/alliedtelesis/x530/x530.c               |   2 +-
>  board/amazon/kc1/kc1.c                        |   4 +-
>  board/amlogic/p200/p200.c                     |   4 +-
>  board/amlogic/p201/p201.c                     |   4 +-
>  board/amlogic/p212/p212.c                     |   4 +-
>  board/amlogic/q200/q200.c                     |   4 +-
>  board/aristainetos/aristainetos-v2.c          |   8 +-
>  board/armltd/integrator/integrator.c          |   2 +-
>  board/atmel/common/board.c                    |   4 +-
>  board/atmel/common/mac_eeprom.c               |   2 +-
>  board/atmel/sama5d3xek/sama5d3xek.c           |   2 +-
>  board/bachmann/ot1200/ot1200.c                |   4 +-
>  board/birdland/bav335x/board.c                |   8 +-
>  board/bluegiga/apx4devkit/apx4devkit.c        |   5 +-
>  board/bluewater/gurnard/gurnard.c             |   6 +-
>  board/bosch/shc/board.c                       |   2 +-
>  board/boundary/nitrogen6x/nitrogen6x.c        |  14 +-
>  board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |   2 +-
>  board/broadcom/bcm28155_ap/bcm28155_ap.c      |   2 +-
>  board/broadcom/bcmstb/bcmstb.c                |   2 +-
>  board/buffalo/lsxl/lsxl.c                     |   2 +-
>  board/cadence/xtfpga/xtfpga.c                 |   4 +-
>  board/ccv/xpress/xpress.c                     |   2 +-
>  board/compulab/cl-som-imx7/cl-som-imx7.c      |   2 +-
>  board/compulab/cm_fx6/cm_fx6.c                |  10 +-
>  board/compulab/common/omap3_display.c         |   4 +-
>  board/congatec/cgtqmx6eval/cgtqmx6eval.c      |   8 +-
>  board/cssi/MCR3000/MCR3000.c                  |   2 +-
>  board/davinci/da8xxevm/da850evm.c             |   2 +-
>  board/davinci/da8xxevm/omapl138_lcdk.c        |   6 +-
>  board/dhelectronics/dh_imx6/dh_imx6.c         |   2 +-
>  board/eets/pdu001/board.c                     |   8 +-
>  board/el/el6x/el6x.c                          |   2 +-
>  board/emulation/qemu-riscv/qemu-riscv.c       |   2 +-
>  board/engicam/common/board.c                  |  32 +-
>  board/esd/meesc/meesc.c                       |   6 +-
>  board/freescale/b4860qds/b4860qds.c           |   5 +-
>  board/freescale/common/cmd_esbc_validate.c    |   2 +-
>  board/freescale/common/fsl_chain_of_trust.c   |   6 +-
>  board/freescale/common/sys_eeprom.c           |   4 +-
>  board/freescale/common/vid.c                  |   4 +-
>  board/freescale/imx8mq_evk/imx8mq_evk.c       |   4 +-
>  board/freescale/imx8qm_mek/imx8qm_mek.c       |   4 +-
>  board/freescale/imx8qxp_mek/imx8qxp_mek.c     |   4 +-
>  board/freescale/ls1088a/eth_ls1088aqds.c      |   4 +-
>  board/freescale/ls1088a/ls1088a.c             |   2 +-
>  board/freescale/ls2080aqds/eth.c              |   6 +-
>  board/freescale/ls2080aqds/ls2080aqds.c       |   2 +-
>  board/freescale/ls2080ardb/ls2080ardb.c       |   6 +-
>  board/freescale/lx2160a/eth_lx2160aqds.c      |   2 +-
>  board/freescale/mpc8323erdb/mpc8323erdb.c     |   3 +-
>  board/freescale/mpc837xemds/pci.c             |   2 +-
>  board/freescale/mpc837xerdb/mpc837xerdb.c     |   2 +-
>  board/freescale/mx51evk/mx51evk_video.c       |   2 +-
>  board/freescale/mx53loco/mx53loco.c           |   4 +-
>  board/freescale/mx53loco/mx53loco_video.c     |   2 +-
>  board/freescale/mx6sabreauto/mx6sabreauto.c   |   8 +-
>  board/freescale/mx6sabresd/mx6sabresd.c       |   8 +-
>  board/freescale/mx6sxsabresd/mx6sxsabresd.c   |   2 +-
>  .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |   6 +-
>  board/freescale/mx6ullevk/mx6ullevk.c         |   4 +-
>  board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |   2 +-
>  board/freescale/qemu-ppce500/qemu-ppce500.c   |   4 +-
>  board/freescale/t4qds/t4240qds.c              |   2 +-
>  board/gardena/smart-gateway-at91sam/board.c   |   2 +-
>  board/gardena/smart-gateway-mt7688/board.c    |  16 +-
>  board/gateworks/gw_ventana/common.c           |   2 +-
>  board/gateworks/gw_ventana/gw_ventana.c       |  61 +-
>  board/gateworks/gw_ventana/gw_ventana_spl.c   |   4 +-
>  board/gdsys/a38x/keyprogram.c                 |   4 +-
>  board/gdsys/mpc8308/gazerbeam.c               |   4 +-
>  board/gdsys/mpc8308/hrcon.c                   |   2 +-
>  board/gdsys/mpc8308/strider.c                 |   2 +-
>  board/gdsys/p1022/controlcenterd-id.c         |  10 +-
>  board/gdsys/p1022/controlcenterd.c            |   2 +-
>  board/ge/bx50v3/bx50v3.c                      |  13 +-
>  board/ge/common/ge_common.c                   |   4 +-
>  board/ge/mx53ppd/mx53ppd.c                    |   2 +-
>  board/grinn/chiliboard/board.c                |   4 +-
>  board/grinn/liteboard/board.c                 |   6 +-
>  board/highbank/highbank.c                     |   9 +-
>  board/hisilicon/poplar/poplar.c               |   2 +-
>  board/imgtec/ci20/ci20.c                      |   6 +-
>  board/intel/edison/edison.c                   |  14 +-
>  board/isee/igep003x/board.c                   |   6 +-
>  board/isee/igep00x0/igep00x0.c                |   4 +-
>  board/k+p/kp_imx53/kp_id_rev.c                |  20 +-
>  board/k+p/kp_imx53/kp_imx53.c                 |   4 +-
>  board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |   4 +-
>  board/keymile/common/common.c                 |  26 +-
>  board/keymile/common/ivm.c                    |   8 +-
>  board/keymile/km83xx/km83xx.c                 |   2 +-
>  board/keymile/km_arm/km_arm.c                 |   6 +-
>  board/keymile/kmp204x/kmp204x.c               |   4 +-
>  board/kosagi/novena/novena.c                  |   2 +-
>  board/laird/wb50n/wb50n.c                     |   2 +-
>  board/lg/sniper/sniper.c                      |   4 +-
>  board/liebherr/display5/spl.c                 |   4 +-
>  board/liebherr/mccmon6/mccmon6.c              |   6 +-
>  board/logicpd/imx6/imx6logic.c                |   8 +-
>  board/menlo/m53menlo/m53menlo.c               |   2 +-
>  board/micronas/vct/vct.c                      |   2 +-
>  board/nokia/rx51/rx51.c                       |  10 +-
>  board/overo/overo.c                           |  45 +-
>  board/phytec/pcm052/pcm052.c                  |   4 +-
>  board/phytec/pfla02/pfla02.c                  |   2 +-
>  .../dragonboard410c/dragonboard410c.c         |   6 +-
>  .../dragonboard820c/dragonboard820c.c         |   2 +-
>  board/raspberrypi/rpi/rpi.c                   |  26 +-
>  board/renesas/alt/alt.c                       |   3 +-
>  board/renesas/gose/gose.c                     |   3 +-
>  board/renesas/koelsch/koelsch.c               |   3 +-
>  board/renesas/lager/lager.c                   |   3 +-
>  board/renesas/porter/porter.c                 |   3 +-
>  board/renesas/sh7752evb/sh7752evb.c           |   4 +-
>  board/renesas/sh7753evb/sh7753evb.c           |   4 +-
>  board/renesas/sh7757lcr/sh7757lcr.c           |   6 +-
>  board/renesas/silk/silk.c                     |   3 +-
>  board/renesas/stout/stout.c                   |   3 +-
>  board/rockchip/kylin_rk3036/kylin_rk3036.c    |   2 +-
>  board/samsung/common/exynos5-dt.c             |   2 +-
>  board/samsung/common/misc.c                   |  14 +-
>  board/samsung/odroid/odroid.c                 |   2 +-
>  board/samsung/trats/trats.c                   |   2 +-
>  board/samsung/universal_c210/universal.c      |   2 +-
>  board/samtec/vining_fpga/socfpga.c            |  16 +-
>  board/siemens/common/board.c                  |   4 +-
>  board/siemens/draco/board.c                   |   6 +-
>  board/siemens/pxm2/board.c                    |   4 +-
>  board/siemens/rut/board.c                     |   2 +-
>  board/siemens/taurus/taurus.c                 |  50 +-
>  board/socrates/socrates.c                     |   4 +-
>  board/softing/vining_2000/vining_2000.c       |   8 +-
>  board/solidrun/mx6cuboxi/mx6cuboxi.c          |  16 +-
>  .../stm32f429-discovery/stm32f429-discovery.c |   4 +-
>  .../stm32f429-evaluation.c                    |   4 +-
>  .../stm32f469-discovery/stm32f469-discovery.c |   4 +-
>  board/st/stm32mp1/stm32mp1.c                  |  11 +-
>  board/sunxi/board.c                           |  25 +-
>  board/synopsys/hsdk/env-lib.c                 |  11 +-
>  board/synopsys/hsdk/hsdk.c                    |   6 +-
>  board/syteco/zmx25/zmx25.c                    |   8 +-
>  board/tcl/sl50/board.c                        |   6 +-
>  .../puma_rk3399/puma-rk3399.c                 |   8 +-
>  board/ti/am335x/board.c                       |  18 +-
>  board/ti/am43xx/board.c                       |   6 +-
>  board/ti/am57xx/board.c                       |  14 +-
>  board/ti/beagle/beagle.c                      |  43 +-
>  board/ti/common/board_detect.c                |  14 +-
>  board/ti/dra7xx/evm.c                         |  12 +-
>  board/ti/evm/evm.c                            |   2 +-
>  board/ti/ks2_evm/board.c                      |  10 +-
>  board/ti/ks2_evm/board_k2g.c                  |   8 +-
>  board/ti/panda/panda.c                        |   4 +-
>  board/toradex/apalis-imx8/apalis-imx8.c       |   4 +-
>  board/toradex/apalis_imx6/apalis_imx6.c       |  12 +-
>  .../toradex/colibri-imx6ull/colibri-imx6ull.c |   6 +-
>  board/toradex/colibri-imx8x/colibri-imx8x.c   |   4 +-
>  board/toradex/colibri_imx6/colibri_imx6.c     |   8 +-
>  board/toradex/colibri_vf/colibri_vf.c         |   2 +-
>  board/toradex/common/tdx-cfg-block.c          |   2 +-
>  board/toradex/common/tdx-common.c             |   2 +-
>  board/tqc/tqma6/tqma6.c                       |   2 +-
>  board/udoo/neo/neo.c                          |   2 +-
>  board/udoo/udoo.c                             |   4 +-
>  board/varisys/common/sys_eeprom.c             |   6 +-
>  board/vscom/baltos/board.c                    |   6 +-
>  board/wandboard/wandboard.c                   |  12 +-
>  board/warp7/warp7.c                           |   6 +-
>  .../work_92105/work_92105_display.c           |   2 +-
>  board/xes/common/board.c                      |   6 +-
>  board/xilinx/zynq/board.c                     |  16 +-
>  board/xilinx/zynqmp/cmds.c                    |   2 +-
>  board/xilinx/zynqmp/zynqmp.c                  |  24 +-
>  cmd/ab_select.c                               |   2 +-
>  cmd/avb.c                                     |   2 +-
>  cmd/bdinfo.c                                  |   6 +-
>  cmd/binop.c                                   |   4 +-
>  cmd/bootefi.c                                 |   8 +-
>  cmd/bootm.c                                   |   4 +-
>  cmd/bootmenu.c                                |   6 +-
>  cmd/cbfs.c                                    |   2 +-
>  cmd/cramfs.c                                  |   8 +-
>  cmd/dtimg.c                                   |   2 +-
>  cmd/elf.c                                     |  29 +-
>  cmd/fdt.c                                     |  22 +-
>  cmd/fpga.c                                    |   4 +-
>  cmd/gpt.c                                     |   8 +-
>  cmd/ini.c                                     |   6 +-
>  cmd/itest.c                                   |   2 +-
>  cmd/jffs2.c                                   |   4 +-
>  cmd/load.c                                    |  10 +-
>  cmd/lzmadec.c                                 |   2 +-
>  cmd/md5sum.c                                  |   4 +-
>  cmd/mtdparts.c                                |  41 +-
>  cmd/mvebu/bubt.c                              |   2 +-
>  cmd/nand.c                                    |  12 +-
>  cmd/net.c                                     |  46 +-
>  cmd/nvedit.c                                  | 394 +++++++---
>  cmd/part.c                                    |   6 +-
>  cmd/pxe.c                                     |  33 +-
>  cmd/qfw.c                                     |   6 +-
>  cmd/reiser.c                                  |   8 +-
>  cmd/setexpr.c                                 |   8 +-
>  cmd/spl.c                                     |   5 +-
>  cmd/ti/ddr3.c                                 |   2 +-
>  cmd/tpm-common.c                              |   2 +-
>  cmd/tpm-v1.c                                  |   2 +-
>  cmd/trace.c                                   |  18 +-
>  cmd/ubi.c                                     |   2 +-
>  cmd/unzip.c                                   |   2 +-
>  cmd/ximg.c                                    |   4 +-
>  cmd/zfs.c                                     |   6 +-
>  cmd/zip.c                                     |   2 +-
>  common/autoboot.c                             |  22 +-
>  common/board_f.c                              |   3 +-
>  common/board_r.c                              |  10 +-
>  common/bootm.c                                |  12 +-
>  common/bootm_os.c                             |  12 +-
>  common/bootretry.c                            |   2 +-
>  common/cli.c                                  |   2 +-
>  common/cli_hush.c                             |  14 +-
>  common/cli_simple.c                           |   2 +-
>  common/command.c                              |   2 +-
>  common/console.c                              |  14 +-
>  common/fdt_support.c                          |   6 +-
>  common/hash.c                                 |   4 +-
>  common/hwconfig.c                             |   5 +-
>  common/image-android.c                        |   4 +-
>  common/image-fdt.c                            |   4 +-
>  common/image.c                                |  15 +-
>  common/main.c                                 |   5 +-
>  common/spl/spl_dfu.c                          |   6 +-
>  common/spl/spl_ext.c                          |   4 +-
>  common/spl/spl_fat.c                          |   4 +-
>  common/spl/spl_net.c                          |   4 +-
>  common/splash.c                               |   4 +-
>  common/splash_source.c                        |   8 +-
>  common/update.c                               |  10 +-
>  common/usb_hub.c                              |   2 +-
>  common/usb_kbd.c                              |   6 +-
>  disk/part.c                                   |   2 +-
>  disk/part_amiga.c                             |   4 +-
>  drivers/bootcount/bootcount_env.c             |  12 +-
>  drivers/ddr/fsl/fsl_ddr_gen4.c                |   2 +-
>  drivers/ddr/fsl/interactive.c                 |   5 +-
>  drivers/ddr/fsl/options.c                     |   4 +-
>  drivers/dfu/dfu.c                             |   6 +-
>  drivers/fastboot/fb_command.c                 |   4 +-
>  drivers/fastboot/fb_common.c                  |   2 +-
>  drivers/fastboot/fb_getvar.c                  |   8 +-
>  drivers/fastboot/fb_mmc.c                     |   2 +-
>  drivers/input/i8042.c                         |   2 +-
>  drivers/input/input.c                         |   2 +-
>  drivers/misc/fs_loader.c                      |   8 +-
>  drivers/mtd/cfi_flash.c                       |   2 +-
>  drivers/mtd/mtd_uboot.c                       |  11 +-
>  drivers/net/fec_mxc.c                         |   2 +-
>  drivers/net/fm/b4860.c                        |   3 +-
>  drivers/net/fm/fdt.c                          |   2 +-
>  drivers/net/fm/fm.c                           |   4 +-
>  drivers/net/fsl-mc/mc.c                       |   7 +-
>  drivers/net/netconsole.c                      |  14 +-
>  drivers/net/phy/micrel_ksz90x1.c              |   4 +-
>  drivers/net/sandbox-raw.c                     |   4 +-
>  drivers/pci/pci.c                             |   4 +-
>  drivers/pci/pci_common.c                      |   2 +-
>  drivers/reset/reset-socfpga.c                 |   2 +-
>  drivers/rtc/m41t60.c                          |   2 +-
>  drivers/scsi/scsi.c                           |   2 +-
>  drivers/serial/usbtty.c                       |   4 +-
>  drivers/usb/gadget/designware_udc.c           |   2 +-
>  drivers/usb/gadget/ether.c                    |  13 +-
>  drivers/usb/gadget/f_dfu.c                    |   2 +-
>  drivers/usb/gadget/f_fastboot.c               |   2 +-
>  drivers/usb/gadget/f_rockusb.c                |   2 +-
>  drivers/usb/gadget/f_sdp.c                    |   2 +-
>  drivers/usb/host/ehci-fsl.c                   |   2 +-
>  drivers/video/ati_radeon_fb.c                 |   2 +-
>  drivers/video/cfb_console.c                   |   2 +-
>  drivers/video/mb862xx.c                       |   2 +-
>  drivers/video/mx3fb.c                         |   2 +-
>  drivers/video/mxsfb.c                         |   2 +-
>  drivers/video/videomodes.c                    |   4 +-
>  env/Kconfig                                   | 683 +-----------------
>  env/Kconfig.efi                               | 152 ++++
>  env/Kconfig.uboot                             | 671 +++++++++++++++++
>  env/Makefile                                  |  33 +-
>  env/callback.c                                |  40 +-
>  env/common.c                                  | 255 ++++---
>  env/env.c                                     | 158 ++--
>  env/env_ctx_efi.c                             | 131 ++++
>  env/env_ctx_uboot.c                           | 292 ++++++++
>  env/fat.c                                     | 102 ++-
>  env/flags.c                                   |  35 +-
>  env/flash.c                                   | 397 ++++++----
>  env/nowhere.c                                 |   7 +-
>  fs/fs.c                                       |  14 +-
>  fs/ubifs/ubifs.c                              |   2 +-
>  include/_exports.h                            |   6 +-
>  include/common.h                              |   6 +-
>  include/env.h                                 | 114 ++-
>  include/env_internal.h                        |  89 ++-
>  include/exports.h                             |   5 +-
>  include/search.h                              |   6 +-
>  lib/efi_loader/efi_console.c                  |   2 +-
>  lib/efi_loader/efi_variable.c                 |  91 ++-
>  lib/fdtdec.c                                  |   2 +-
>  lib/hashtable.c                               |  14 +-
>  lib/smbios.c                                  |   2 +-
>  lib/uuid.c                                    |   2 +-
>  net/bootp.c                                   |  17 +-
>  net/dns.c                                     |   2 +-
>  net/eth-uclass.c                              |   6 +-
>  net/eth_common.c                              |  18 +-
>  net/eth_legacy.c                              |   2 +-
>  net/link_local.c                              |   2 +-
>  net/net.c                                     |  11 +-
>  net/tftp.c                                    |  10 +-
>  net/wol.c                                     |   2 +-
>  post/post.c                                   |   2 +-
>  371 files changed, 3690 insertions(+), 2337 deletions(-)
>  create mode 100644 env/Kconfig.efi
>  create mode 100644 env/Kconfig.uboot
>  create mode 100644 env/env_ctx_efi.c
>  create mode 100644 env/env_ctx_uboot.c
> 
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 09/19] board: converted with new env interfaces
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 09/19] board: " AKASHI Takahiro
@ 2019-09-05 12:02   ` Lukasz Majewski
  2019-09-06  0:34     ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Lukasz Majewski @ 2019-09-05 12:02 UTC (permalink / raw)
  To: u-boot

On Thu,  5 Sep 2019 17:21:23 +0900
AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:

> env_xxx(...) -> env_xxx(ctx_uboot, ...)

To be honest this doesn't explain much about the issue this patch tries
to fix (however, on the mailing list only this particular patch is
present).


Could you provide more verbose description?


> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  board/Arcturus/ucp1020/cmd_arc.c              | 40 ++++++------
>  board/Arcturus/ucp1020/ucp1020.c              | 16 ++---
>  board/BuR/brppt1/board.c                      |  4 +-
>  board/BuR/brxre1/board.c                      |  9 +--
>  board/BuR/common/br_resetc.c                  |  2 +-
>  board/BuR/common/common.c                     | 47 +++++++-------
>  board/BuS/eb_cpu5282/eb_cpu5282.c             |  8 +--
>  board/CZ.NIC/turris_mox/turris_mox.c          |  4 +-
>  board/CZ.NIC/turris_omnia/turris_omnia.c      |  6 +-
>  board/CarMediaLab/flea3/flea3.c               |  2 +-
>  board/LaCie/net2big_v2/net2big_v2.c           |  2 +-
>  board/LaCie/netspace_v2/netspace_v2.c         |  2 +-
>  board/Synology/ds414/cmd_syno.c               |  6 +-
>  board/alliedtelesis/x530/x530.c               |  2 +-
>  board/amazon/kc1/kc1.c                        |  4 +-
>  board/amlogic/p200/p200.c                     |  4 +-
>  board/amlogic/p201/p201.c                     |  4 +-
>  board/amlogic/p212/p212.c                     |  4 +-
>  board/amlogic/q200/q200.c                     |  4 +-
>  board/aristainetos/aristainetos-v2.c          |  8 +--
>  board/armltd/integrator/integrator.c          |  2 +-
>  board/atmel/common/board.c                    |  4 +-
>  board/atmel/common/mac_eeprom.c               |  2 +-
>  board/atmel/sama5d3xek/sama5d3xek.c           |  2 +-
>  board/bachmann/ot1200/ot1200.c                |  4 +-
>  board/birdland/bav335x/board.c                |  8 +--
>  board/bluegiga/apx4devkit/apx4devkit.c        |  5 +-
>  board/bluewater/gurnard/gurnard.c             |  6 +-
>  board/bosch/shc/board.c                       |  2 +-
>  board/boundary/nitrogen6x/nitrogen6x.c        | 14 ++---
>  board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |  2 +-
>  board/broadcom/bcm28155_ap/bcm28155_ap.c      |  2 +-
>  board/broadcom/bcmstb/bcmstb.c                |  2 +-
>  board/buffalo/lsxl/lsxl.c                     |  2 +-
>  board/cadence/xtfpga/xtfpga.c                 |  4 +-
>  board/ccv/xpress/xpress.c                     |  2 +-
>  board/compulab/cl-som-imx7/cl-som-imx7.c      |  2 +-
>  board/compulab/cm_fx6/cm_fx6.c                | 10 +--
>  board/compulab/common/omap3_display.c         |  4 +-
>  board/congatec/cgtqmx6eval/cgtqmx6eval.c      |  8 +--
>  board/cssi/MCR3000/MCR3000.c                  |  2 +-
>  board/davinci/da8xxevm/da850evm.c             |  2 +-
>  board/davinci/da8xxevm/omapl138_lcdk.c        |  6 +-
>  board/dhelectronics/dh_imx6/dh_imx6.c         |  2 +-
>  board/eets/pdu001/board.c                     |  8 +--
>  board/el/el6x/el6x.c                          |  2 +-
>  board/emulation/qemu-riscv/qemu-riscv.c       |  2 +-
>  board/engicam/common/board.c                  | 32 +++++-----
>  board/esd/meesc/meesc.c                       |  6 +-
>  board/freescale/b4860qds/b4860qds.c           |  5 +-
>  board/freescale/common/cmd_esbc_validate.c    |  2 +-
>  board/freescale/common/fsl_chain_of_trust.c   |  6 +-
>  board/freescale/common/sys_eeprom.c           |  4 +-
>  board/freescale/common/vid.c                  |  4 +-
>  board/freescale/imx8mq_evk/imx8mq_evk.c       |  4 +-
>  board/freescale/imx8qm_mek/imx8qm_mek.c       |  4 +-
>  board/freescale/imx8qxp_mek/imx8qxp_mek.c     |  4 +-
>  board/freescale/ls1088a/eth_ls1088aqds.c      |  4 +-
>  board/freescale/ls1088a/ls1088a.c             |  2 +-
>  board/freescale/ls2080aqds/eth.c              |  6 +-
>  board/freescale/ls2080aqds/ls2080aqds.c       |  2 +-
>  board/freescale/ls2080ardb/ls2080ardb.c       |  6 +-
>  board/freescale/lx2160a/eth_lx2160aqds.c      |  2 +-
>  board/freescale/mpc8323erdb/mpc8323erdb.c     |  3 +-
>  board/freescale/mpc837xemds/pci.c             |  2 +-
>  board/freescale/mpc837xerdb/mpc837xerdb.c     |  2 +-
>  board/freescale/mx51evk/mx51evk_video.c       |  2 +-
>  board/freescale/mx53loco/mx53loco.c           |  4 +-
>  board/freescale/mx53loco/mx53loco_video.c     |  2 +-
>  board/freescale/mx6sabreauto/mx6sabreauto.c   |  8 +--
>  board/freescale/mx6sabresd/mx6sabresd.c       |  8 +--
>  board/freescale/mx6sxsabresd/mx6sxsabresd.c   |  2 +-
>  .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |  6 +-
>  board/freescale/mx6ullevk/mx6ullevk.c         |  4 +-
>  board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |  2 +-
>  board/freescale/qemu-ppce500/qemu-ppce500.c   |  4 +-
>  board/freescale/t4qds/t4240qds.c              |  2 +-
>  board/gardena/smart-gateway-at91sam/board.c   |  2 +-
>  board/gardena/smart-gateway-mt7688/board.c    | 16 ++---
>  board/gateworks/gw_ventana/common.c           |  2 +-
>  board/gateworks/gw_ventana/gw_ventana.c       | 61
> ++++++++++--------- board/gateworks/gw_ventana/gw_ventana_spl.c   |
> 4 +- board/gdsys/a38x/keyprogram.c                 |  4 +-
>  board/gdsys/mpc8308/gazerbeam.c               |  4 +-
>  board/gdsys/mpc8308/hrcon.c                   |  2 +-
>  board/gdsys/mpc8308/strider.c                 |  2 +-
>  board/gdsys/p1022/controlcenterd-id.c         | 10 +--
>  board/gdsys/p1022/controlcenterd.c            |  2 +-
>  board/ge/bx50v3/bx50v3.c                      | 13 ++--
>  board/ge/common/ge_common.c                   |  4 +-
>  board/ge/mx53ppd/mx53ppd.c                    |  2 +-
>  board/grinn/chiliboard/board.c                |  4 +-
>  board/grinn/liteboard/board.c                 |  6 +-
>  board/highbank/highbank.c                     |  9 +--
>  board/hisilicon/poplar/poplar.c               |  2 +-
>  board/imgtec/ci20/ci20.c                      |  6 +-
>  board/intel/edison/edison.c                   | 14 ++---
>  board/isee/igep003x/board.c                   |  6 +-
>  board/isee/igep00x0/igep00x0.c                |  4 +-
>  board/k+p/kp_imx53/kp_id_rev.c                | 20 +++---
>  board/k+p/kp_imx53/kp_imx53.c                 |  4 +-
>  board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |  4 +-
>  board/keymile/common/common.c                 | 26 ++++----
>  board/keymile/common/ivm.c                    |  8 +--
>  board/keymile/km83xx/km83xx.c                 |  2 +-
>  board/keymile/km_arm/km_arm.c                 |  6 +-
>  board/keymile/kmp204x/kmp204x.c               |  4 +-
>  board/kosagi/novena/novena.c                  |  2 +-
>  board/laird/wb50n/wb50n.c                     |  2 +-
>  board/lg/sniper/sniper.c                      |  4 +-
>  board/liebherr/display5/spl.c                 |  4 +-
>  board/liebherr/mccmon6/mccmon6.c              |  6 +-
>  board/logicpd/imx6/imx6logic.c                |  8 +--
>  board/menlo/m53menlo/m53menlo.c               |  2 +-
>  board/micronas/vct/vct.c                      |  2 +-
>  board/nokia/rx51/rx51.c                       | 10 +--
>  board/overo/overo.c                           | 45 +++++++-------
>  board/phytec/pcm052/pcm052.c                  |  4 +-
>  board/phytec/pfla02/pfla02.c                  |  2 +-
>  .../dragonboard410c/dragonboard410c.c         |  6 +-
>  .../dragonboard820c/dragonboard820c.c         |  2 +-
>  board/raspberrypi/rpi/rpi.c                   | 26 ++++----
>  board/renesas/alt/alt.c                       |  3 +-
>  board/renesas/gose/gose.c                     |  3 +-
>  board/renesas/koelsch/koelsch.c               |  3 +-
>  board/renesas/lager/lager.c                   |  3 +-
>  board/renesas/porter/porter.c                 |  3 +-
>  board/renesas/sh7752evb/sh7752evb.c           |  4 +-
>  board/renesas/sh7753evb/sh7753evb.c           |  4 +-
>  board/renesas/sh7757lcr/sh7757lcr.c           |  6 +-
>  board/renesas/silk/silk.c                     |  3 +-
>  board/renesas/stout/stout.c                   |  3 +-
>  board/rockchip/kylin_rk3036/kylin_rk3036.c    |  2 +-
>  board/samsung/common/exynos5-dt.c             |  2 +-
>  board/samsung/common/misc.c                   | 14 ++---
>  board/samsung/odroid/odroid.c                 |  2 +-
>  board/samsung/trats/trats.c                   |  2 +-
>  board/samsung/universal_c210/universal.c      |  2 +-
>  board/samtec/vining_fpga/socfpga.c            | 16 ++---
>  board/siemens/common/board.c                  |  4 +-
>  board/siemens/draco/board.c                   |  6 +-
>  board/siemens/pxm2/board.c                    |  4 +-
>  board/siemens/rut/board.c                     |  2 +-
>  board/siemens/taurus/taurus.c                 | 50 +++++++--------
>  board/socrates/socrates.c                     |  4 +-
>  board/softing/vining_2000/vining_2000.c       |  8 +--
>  board/solidrun/mx6cuboxi/mx6cuboxi.c          | 16 ++---
>  .../stm32f429-discovery/stm32f429-discovery.c |  4 +-
>  .../stm32f429-evaluation.c                    |  4 +-
>  .../stm32f469-discovery/stm32f469-discovery.c |  4 +-
>  board/st/stm32mp1/stm32mp1.c                  | 11 ++--
>  board/sunxi/board.c                           | 25 ++++----
>  board/synopsys/hsdk/env-lib.c                 | 11 ++--
>  board/synopsys/hsdk/hsdk.c                    |  6 +-
>  board/syteco/zmx25/zmx25.c                    |  8 ++-
>  board/tcl/sl50/board.c                        |  6 +-
>  .../puma_rk3399/puma-rk3399.c                 |  8 +--
>  board/ti/am335x/board.c                       | 18 +++---
>  board/ti/am43xx/board.c                       |  6 +-
>  board/ti/am57xx/board.c                       | 14 ++---
>  board/ti/beagle/beagle.c                      | 43 ++++++-------
>  board/ti/common/board_detect.c                | 14 ++---
>  board/ti/dra7xx/evm.c                         | 12 ++--
>  board/ti/evm/evm.c                            |  2 +-
>  board/ti/ks2_evm/board.c                      | 10 +--
>  board/ti/ks2_evm/board_k2g.c                  |  8 +--
>  board/ti/panda/panda.c                        |  4 +-
>  board/toradex/apalis-imx8/apalis-imx8.c       |  4 +-
>  board/toradex/apalis_imx6/apalis_imx6.c       | 12 ++--
>  .../toradex/colibri-imx6ull/colibri-imx6ull.c |  6 +-
>  board/toradex/colibri-imx8x/colibri-imx8x.c   |  4 +-
>  board/toradex/colibri_imx6/colibri_imx6.c     |  8 +--
>  board/toradex/colibri_vf/colibri_vf.c         |  2 +-
>  board/toradex/common/tdx-cfg-block.c          |  2 +-
>  board/toradex/common/tdx-common.c             |  2 +-
>  board/tqc/tqma6/tqma6.c                       |  2 +-
>  board/udoo/neo/neo.c                          |  2 +-
>  board/udoo/udoo.c                             |  4 +-
>  board/varisys/common/sys_eeprom.c             |  6 +-
>  board/vscom/baltos/board.c                    |  6 +-
>  board/wandboard/wandboard.c                   | 12 ++--
>  board/warp7/warp7.c                           |  6 +-
>  .../work_92105/work_92105_display.c           |  2 +-
>  board/xes/common/board.c                      |  6 +-
>  board/xilinx/zynq/board.c                     | 16 ++---
>  board/xilinx/zynqmp/cmds.c                    |  2 +-
>  board/xilinx/zynqmp/zynqmp.c                  | 24 ++++----
>  187 files changed, 677 insertions(+), 649 deletions(-)
> 
> diff --git a/board/Arcturus/ucp1020/cmd_arc.c
> b/board/Arcturus/ucp1020/cmd_arc.c index 2e8477ed3b7a..fbe1f2dba123
> 100644 --- a/board/Arcturus/ucp1020/cmd_arc.c
> +++ b/board/Arcturus/ucp1020/cmd_arc.c
> @@ -252,8 +252,8 @@ static int read_arc_info(void)
>  static int do_get_arc_info(void)
>  {
>  	int l = read_arc_info();
> -	char *oldserial = env_get("SERIAL");
> -	char *oldversion = env_get("VERSION");
> +	char *oldserial = env_get(ctx_uboot, "SERIAL");
> +	char *oldversion = env_get(ctx_uboot, "VERSION");
>  
>  	if (oldversion != NULL)
>  		if (strcmp(oldversion, U_BOOT_VERSION) != 0)
> @@ -269,13 +269,13 @@ static int do_get_arc_info(void)
>  		printf("<not found>\n");
>  	} else {
>  		printf("%s\n", smac[0]);
> -		env_set("SERIAL", smac[0]);
> +		env_set(ctx_uboot, "SERIAL", smac[0]);
>  	}
>  
>  	if (strcmp(smac[1], "00:00:00:00:00:00") == 0) {
> -		env_set("ethaddr", NULL);
> -		env_set("eth1addr", NULL);
> -		env_set("eth2addr", NULL);
> +		env_set(ctx_uboot, "ethaddr", NULL);
> +		env_set(ctx_uboot, "eth1addr", NULL);
> +		env_set(ctx_uboot, "eth2addr", NULL);
>  		goto done;
>  	}
>  
> @@ -283,13 +283,13 @@ static int do_get_arc_info(void)
>  	if (smac[1][0] == EMPY_CHAR) {
>  		printf("<not found>\n");
>  	} else {
> -		char *ret = env_get("ethaddr");
> +		char *ret = env_get(ctx_uboot, "ethaddr");
>  
>  		if (ret == NULL) {
> -			env_set("ethaddr", smac[1]);
> +			env_set(ctx_uboot, "ethaddr", smac[1]);
>  			printf("%s\n", smac[1]);
>  		} else if (strcmp(ret, __stringify(CONFIG_ETHADDR))
> == 0) {
> -			env_set("ethaddr", smac[1]);
> +			env_set(ctx_uboot, "ethaddr", smac[1]);
>  			printf("%s (factory)\n", smac[1]);
>  		} else {
>  			printf("%s\n", ret);
> @@ -297,8 +297,8 @@ static int do_get_arc_info(void)
>  	}
>  
>  	if (strcmp(smac[2], "00:00:00:00:00:00") == 0) {
> -		env_set("eth1addr", NULL);
> -		env_set("eth2addr", NULL);
> +		env_set(ctx_uboot, "eth1addr", NULL);
> +		env_set(ctx_uboot, "eth2addr", NULL);
>  		goto done;
>  	}
>  
> @@ -306,13 +306,13 @@ static int do_get_arc_info(void)
>  	if (smac[2][0] == EMPY_CHAR) {
>  		printf("<not found>\n");
>  	} else {
> -		char *ret = env_get("eth1addr");
> +		char *ret = env_get(ctx_uboot, "eth1addr");
>  
>  		if (ret == NULL) {
> -			env_set("ethaddr", smac[2]);
> +			env_set(ctx_uboot, "ethaddr", smac[2]);
>  			printf("%s\n", smac[2]);
>  		} else if (strcmp(ret, __stringify(CONFIG_ETH1ADDR))
> == 0) {
> -			env_set("eth1addr", smac[2]);
> +			env_set(ctx_uboot, "eth1addr", smac[2]);
>  			printf("%s (factory)\n", smac[2]);
>  		} else {
>  			printf("%s\n", ret);
> @@ -320,7 +320,7 @@ static int do_get_arc_info(void)
>  	}
>  
>  	if (strcmp(smac[3], "00:00:00:00:00:00") == 0) {
> -		env_set("eth2addr", NULL);
> +		env_set(ctx_uboot, "eth2addr", NULL);
>  		goto done;
>  	}
>  
> @@ -328,13 +328,13 @@ static int do_get_arc_info(void)
>  	if (smac[3][0] == EMPY_CHAR) {
>  		printf("<not found>\n");
>  	} else {
> -		char *ret = env_get("eth2addr");
> +		char *ret = env_get(ctx_uboot, "eth2addr");
>  
>  		if (ret == NULL) {
> -			env_set("ethaddr", smac[3]);
> +			env_set(ctx_uboot, "ethaddr", smac[3]);
>  			printf("%s\n", smac[3]);
>  		} else if (strcmp(ret, __stringify(CONFIG_ETH2ADDR))
> == 0) {
> -			env_set("eth2addr", smac[3]);
> +			env_set(ctx_uboot, "eth2addr", smac[3]);
>  			printf("%s (factory)\n", smac[3]);
>  		} else {
>  			printf("%s\n", ret);
> @@ -343,8 +343,8 @@ static int do_get_arc_info(void)
>  done:
>  	if (oldserial == NULL || oldversion == NULL) {
>  		if (oldversion == NULL)
> -			env_set("VERSION", U_BOOT_VERSION);
> -		env_save();
> +			env_set(ctx_uboot, "VERSION",
> U_BOOT_VERSION);
> +		env_save(ctx_uboot);
>  	}
>  
>  	return 0;
> diff --git a/board/Arcturus/ucp1020/ucp1020.c
> b/board/Arcturus/ucp1020/ucp1020.c index 6a880c97bcb7..1aa7f96b5e1c
> 100644 --- a/board/Arcturus/ucp1020/ucp1020.c
> +++ b/board/Arcturus/ucp1020/ucp1020.c
> @@ -64,7 +64,7 @@ void board_gpio_init(void)
>  
>  	for (i = 0; i < GPIO_MAX_NUM; i++) {
>  		sprintf(envname, "GPIO%d", i);
> -		val = env_get(envname);
> +		val = env_get(ctx_uboot, envname);
>  		if (val) {
>  			char direction = toupper(val[0]);
>  			char level = toupper(val[1]);
> @@ -82,7 +82,7 @@ void board_gpio_init(void)
>  		}
>  	}
>  
> -	val = env_get("PCIE_OFF");
> +	val = env_get(ctx_uboot, "PCIE_OFF");
>  	if (val) {
>  		gpio_direction_input(GPIO_PCIE1_EN);
>  		gpio_direction_input(GPIO_PCIE2_EN);
> @@ -91,7 +91,7 @@ void board_gpio_init(void)
>  		gpio_direction_output(GPIO_PCIE2_EN, 1);
>  	}
>  
> -	val = env_get("SDHC_CDWP_OFF");
> +	val = env_get(ctx_uboot, "SDHC_CDWP_OFF");
>  	if (!val) {
>  		ccsr_gur_t *gur = (void
> *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 
> @@ -218,7 +218,7 @@ int last_stage_init(void)
>  	else
>  		printf("NCT72(0x%x): ready\n", id2);
>  
> -	kval = env_get("kernelargs");
> +	kval = env_get(ctx_uboot, "kernelargs");
>  
>  #ifdef CONFIG_MMC
>  	mmc = find_mmc_device(0);
> @@ -235,22 +235,22 @@ int last_stage_init(void)
>  				strcat(newkernelargs, mmckargs);
>  				strcat(newkernelargs, " ");
>  				strcat(newkernelargs, &tmp[n]);
> -				env_set("kernelargs", newkernelargs);
> +				env_set(ctx_uboot, "kernelargs",
> newkernelargs); } else {
> -				env_set("kernelargs", mmckargs);
> +				env_set(ctx_uboot, "kernelargs",
> mmckargs); }
>  		}
>  #endif
>  	get_arc_info();
>  
>  	if (kval) {
> -		sval = env_get("SERIAL");
> +		sval = env_get(ctx_uboot, "SERIAL");
>  		if (sval) {
>  			strcpy(newkernelargs, "SN=");
>  			strcat(newkernelargs, sval);
>  			strcat(newkernelargs, " ");
>  			strcat(newkernelargs, kval);
> -			env_set("kernelargs", newkernelargs);
> +			env_set(ctx_uboot, "kernelargs",
> newkernelargs); }
>  	} else {
>  		printf("Error reading kernelargs env variable!\n");
> diff --git a/board/BuR/brppt1/board.c b/board/BuR/brppt1/board.c
> index ef4f5c950140..4278dda5988f 100644
> --- a/board/BuR/brppt1/board.c
> +++ b/board/BuR/brppt1/board.c
> @@ -180,10 +180,10 @@ int board_late_init(void)
>  		bmode = 4;
>  
>  	printf("Mode:  %s\n", bootmodeascii[bmode & 0x0F]);
> -	env_set_ulong("b_mode", bmode);
> +	env_set_ulong(ctx_uboot, "b_mode", bmode);
>  
>  	/* get sure that bootcmd isn't affected by any bootcount
> value */
> -	env_set_ulong("bootlimit", 0);
> +	env_set_ulong(ctx_uboot, "bootlimit", 0);
>  
>  	return 0;
>  }
> diff --git a/board/BuR/brxre1/board.c b/board/BuR/brxre1/board.c
> index 873208c668d7..69bcccbc5a0d 100644
> --- a/board/BuR/brxre1/board.c
> +++ b/board/BuR/brxre1/board.c
> @@ -165,10 +165,11 @@ int board_late_init(void)
>  	snprintf(othbootargs, sizeof(othbootargs),
>  		 "u=vxWorksFTP pw=vxWorks
> o=0x%08x;0x%08x;0x%08x;0x%08x", (u32)gd->fb_base - 0x20,
> -		 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base -
> 0x20),
> -		 (u32)env_get_ulong("vx_romfsbase", 16, 0),
> -		 (u32)env_get_ulong("vx_romfssize", 16, 0));
> -	env_set("othbootargs", othbootargs);
> +		 (u32)env_get_ulong(ctx_uboot, "vx_memtop", 16,
> +				    gd->fb_base - 0x20),
> +		 (u32)env_get_ulong(ctx_uboot, "vx_romfsbase", 16,
> 0),
> +		 (u32)env_get_ulong(ctx_uboot, "vx_romfssize", 16,
> 0));
> +	env_set(ctx_uboot, "othbootargs", othbootargs);
>  	/*
>  	 * reset VBAR registers to its reset location, VxWorks
> 6.9.3.2 does
>  	 * expect that vectors are there, original u-boot moves them
> to _start diff --git a/board/BuR/common/br_resetc.c
> b/board/BuR/common/br_resetc.c index c0e7fb65b298..36d49967dd82 100644
> --- a/board/BuR/common/br_resetc.c
> +++ b/board/BuR/common/br_resetc.c
> @@ -230,7 +230,7 @@ int br_resetc_bmode(void)
>  		printf("Reset: STM32 controller\n");
>  
>  	printf("Mode:  %s\n", bootmodeascii[regw & 0x0F]);
> -	env_set_ulong("b_mode", regw & 0x0F);
> +	env_set_ulong(ctx_uboot, "b_mode", regw & 0x0F);
>  
>  	return rc;
>  }
> diff --git a/board/BuR/common/common.c b/board/BuR/common/common.c
> index 148fc9075e4f..f3bc87daf19f 100644
> --- a/board/BuR/common/common.c
> +++ b/board/BuR/common/common.c
> @@ -29,9 +29,12 @@ DECLARE_GLOBAL_DATA_PTR;
>  
>  void lcdbacklight(int on)
>  {
> -	unsigned int driver = env_get_ulong("ds1_bright_drv", 16,
> 0UL);
> -	unsigned int bright = env_get_ulong("ds1_bright_def", 10,
> 50);
> -	unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
> +	unsigned int driver = env_get_ulong(ctx_uboot,
> "ds1_bright_drv", 16,
> +					    0UL);
> +	unsigned int bright = env_get_ulong(ctx_uboot,
> "ds1_bright_def", 10,
> +					    50);
> +	unsigned int pwmfrq = env_get_ulong(ctx_uboot,
> "ds1_pwmfreq", 10,
> +					    ~0UL);
>  	unsigned int tmp;
>  	struct gptimer *timerhw;
>  
> @@ -87,20 +90,20 @@ int load_lcdtiming(struct am335x_lcdpanel *panel)
>  {
>  	struct am335x_lcdpanel pnltmp;
>  
> -	pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
> -	pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
> -	pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
> -	pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
> -	pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
> -	pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
> -	pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
> -	pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
> -	pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
> -	pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
> -	pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
> -	pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
> -	pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
> -	panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
> +	pnltmp.hactive = env_get_ulong(ctx_uboot, "ds1_hactive", 10,
> ~0UL);
> +	pnltmp.vactive = env_get_ulong(ctx_uboot, "ds1_vactive", 10,
> ~0UL);
> +	pnltmp.bpp = env_get_ulong(ctx_uboot, "ds1_bpp", 10, ~0UL);
> +	pnltmp.hfp = env_get_ulong(ctx_uboot, "ds1_hfp", 10, ~0UL);
> +	pnltmp.hbp = env_get_ulong(ctx_uboot, "ds1_hbp", 10, ~0UL);
> +	pnltmp.hsw = env_get_ulong(ctx_uboot, "ds1_hsw", 10, ~0UL);
> +	pnltmp.vfp = env_get_ulong(ctx_uboot, "ds1_vfp", 10, ~0UL);
> +	pnltmp.vbp = env_get_ulong(ctx_uboot, "ds1_vbp", 10, ~0UL);
> +	pnltmp.vsw = env_get_ulong(ctx_uboot, "ds1_vsw", 10, ~0UL);
> +	pnltmp.pxl_clk = env_get_ulong(ctx_uboot, "ds1_pxlclk", 10,
> ~0UL);
> +	pnltmp.pol = env_get_ulong(ctx_uboot, "ds1_pol", 16, ~0UL);
> +	pnltmp.pup_delay = env_get_ulong(ctx_uboot, "ds1_pupdelay",
> 10, ~0UL);
> +	pnltmp.pon_delay = env_get_ulong(ctx_uboot, "ds1_tondelay",
> 10, ~0UL);
> +	panel_info.vl_rot = env_get_ulong(ctx_uboot, "ds1_rotation",
> 10, 0); 
>  	if (
>  	   ~0UL == (pnltmp.hactive) ||
> @@ -151,11 +154,11 @@ static void br_summaryscreen_printenv(char
> *prefix, char *name, char *altname,
>  				       char *suffix)
>  {
> -	char *envval = env_get(name);
> +	char *envval = env_get(ctx_uboot, name);
>  	if (0 != envval) {
>  		lcd_printf("%s %s %s", prefix, envval, suffix);
>  	} else if (0 != altname) {
> -		envval = env_get(altname);
> +		envval = env_get(ctx_uboot, altname);
>  		if (0 != envval)
>  			lcd_printf("%s %s %s", prefix, envval,
> suffix); } else {
> @@ -178,7 +181,7 @@ void lcdpower(int on)
>  	u32 pin, swval, i;
>  	char buf[16] = { 0 };
>  
> -	pin = env_get_ulong("ds1_pwr", 16, ~0UL);
> +	pin = env_get_ulong(ctx_uboot, "ds1_pwr", 16, ~0UL);
>  
>  	if (pin == ~0UL) {
>  		puts("no pwrpin in dtb/env, cannot powerup
> display!\n"); @@ -295,8 +298,8 @@ int brdefaultip_setup(int bus, int
> chip) "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1;
> setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254;
> setenv netmask 255.255.255.0; fi;", sizeof(defip)); 
> -	env_set("brdefaultip", defip);
> -	env_set_hex("board_id", u8buf);
> +	env_set(ctx_uboot, "brdefaultip", defip);
> +	env_set_hex(ctx_uboot, "board_id", u8buf);
>  
>  	return 0;
>  }
> diff --git a/board/BuS/eb_cpu5282/eb_cpu5282.c
> b/board/BuS/eb_cpu5282/eb_cpu5282.c index 0b916d2482c5..03d2b276a132
> 100644 --- a/board/BuS/eb_cpu5282/eb_cpu5282.c
> +++ b/board/BuS/eb_cpu5282/eb_cpu5282.c
> @@ -139,7 +139,7 @@ void hw_watchdog_init(void)
>  	int enable;
>  
>  	enable = 1;
> -	s = env_get("watchdog");
> +	s = env_get(ctx_uboot, "watchdog");
>  	if (s != NULL)
>  		if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0",
> 1) == 0)) enable = 0;
> @@ -191,13 +191,13 @@ int drv_video_init(void)
>  	unsigned long splash;
>  #endif
>  	printf("Init Video as ");
> -	s = env_get("displaywidth");
> +	s = env_get(ctx_uboot, "displaywidth");
>  	if (s != NULL)
>  		display_width = simple_strtoul(s, NULL, 10);
>  	else
>  		display_width = 256;
>  
> -	s = env_get("displayheight");
> +	s = env_get(ctx_uboot, "displayheight");
>  	if (s != NULL)
>  		display_height = simple_strtoul(s, NULL, 10);
>  	else
> @@ -211,7 +211,7 @@ int drv_video_init(void)
>  	vcxk_init(display_width, display_height);
>  
>  #ifdef CONFIG_SPLASH_SCREEN
> -	s = env_get("splashimage");
> +	s = env_get(ctx_uboot, "splashimage");
>  	if (s != NULL) {
>  		splash = simple_strtoul(s, NULL, 16);
>  		vcxk_acknowledge_wait();
> diff --git a/board/CZ.NIC/turris_mox/turris_mox.c
> b/board/CZ.NIC/turris_mox/turris_mox.c index
> 946e20ab492f..b23ecb3fefaa 100644 ---
> a/board/CZ.NIC/turris_mox/turris_mox.c +++
> b/board/CZ.NIC/turris_mox/turris_mox.c @@ -362,10 +362,10 @@ int
> misc_init_r(void) return 0;
>  	}
>  
> -	if (is_valid_ethaddr(mac1) && !env_get("ethaddr"))
> +	if (is_valid_ethaddr(mac1) && !env_get(ctx_uboot, "ethaddr"))
>  		eth_env_set_enetaddr("ethaddr", mac1);
>  
> -	if (is_valid_ethaddr(mac2) && !env_get("eth1addr"))
> +	if (is_valid_ethaddr(mac2) && !env_get(ctx_uboot,
> "eth1addr")) eth_env_set_enetaddr("eth1addr", mac2);
>  
>  	return 0;
> diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c
> b/board/CZ.NIC/turris_omnia/turris_omnia.c index
> 1d8d08a847d9..bbbeaf75fc97 100644 ---
> a/board/CZ.NIC/turris_omnia/turris_omnia.c +++
> b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -326,7 +326,7 @@ static
> int set_regdomain(void) puts("EEPROM regdomain read failed.\n");
>  
>  	printf("Regdomain set to %s\n", rd);
> -	return env_set("regdomain", rd);
> +	return env_set(ctx_uboot, "regdomain", rd);
>  }
>  
>  /*
> @@ -359,11 +359,11 @@ static void handle_reset_button(void)
>  		return;
>  	}
>  
> -	env_set_ulong("omnia_reset", reset_status);
> +	env_set_ulong(ctx_uboot, "omnia_reset", reset_status);
>  
>  	if (reset_status) {
>  		printf("RESET button was pressed, overwriting
> bootcmd!\n");
> -		env_set("bootcmd", OMNIA_FACTORY_RESET_BOOTCMD);
> +		env_set(ctx_uboot, "bootcmd",
> OMNIA_FACTORY_RESET_BOOTCMD); }
>  }
>  #endif
> diff --git a/board/CarMediaLab/flea3/flea3.c
> b/board/CarMediaLab/flea3/flea3.c index be0bc228ec71..9a5fe1e2252d
> 100644 --- a/board/CarMediaLab/flea3/flea3.c
> +++ b/board/CarMediaLab/flea3/flea3.c
> @@ -211,7 +211,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  		{ "mxc_nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
>  	};
>  
> -	if (env_get("fdt_noauto")) {
> +	if (env_get(ctx_uboot, "fdt_noauto")) {
>  		puts("   Skiping ft_board_setup (fdt_noauto
> defined)\n"); return 0;
>  	}
> diff --git a/board/LaCie/net2big_v2/net2big_v2.c
> b/board/LaCie/net2big_v2/net2big_v2.c index
> 686608d25a5a..659a351deaea 100644 ---
> a/board/LaCie/net2big_v2/net2big_v2.c +++
> b/board/LaCie/net2big_v2/net2big_v2.c @@ -221,7 +221,7 @@ int
> misc_init_r(void) {
>  	init_fan();
>  #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		uchar mac[6];
>  		if (lacie_read_mac_address(mac) == 0)
>  			eth_env_set_enetaddr("ethaddr", mac);
> diff --git a/board/LaCie/netspace_v2/netspace_v2.c
> b/board/LaCie/netspace_v2/netspace_v2.c index
> bd7ab22948b2..83b07300354e 100644 ---
> a/board/LaCie/netspace_v2/netspace_v2.c +++
> b/board/LaCie/netspace_v2/netspace_v2.c @@ -83,7 +83,7 @@ int
> board_init(void) int misc_init_r(void)
>  {
>  #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		uchar mac[6];
>  		if (lacie_read_mac_address(mac) == 0)
>  			eth_env_set_enetaddr("ethaddr", mac);
> diff --git a/board/Synology/ds414/cmd_syno.c
> b/board/Synology/ds414/cmd_syno.c index 777948f90f58..abd38b24fff0
> 100644 --- a/board/Synology/ds414/cmd_syno.c
> +++ b/board/Synology/ds414/cmd_syno.c
> @@ -80,7 +80,7 @@ static int do_syno_populate(int argc, char * const
> argv[]) ethaddr[0], ethaddr[1], ethaddr[2],
>  			 ethaddr[3], ethaddr[4], ethaddr[5]);
>  		printf("parsed %s = %s\n", var, val);
> -		env_set(var, val);
> +		env_set(ctx_uboot, var, val);
>  	}
>  	if (!strncmp(buf + 32, SYNO_SN_TAG, strlen(SYNO_SN_TAG))) {
>  		char *snp, *csump;
> @@ -110,7 +110,7 @@ static int do_syno_populate(int argc, char *
> const argv[]) goto out_unmap;
>  		}
>  		printf("parsed SN = %s\n", snp);
> -		env_set("SN", snp);
> +		env_set(ctx_uboot, "SN", snp);
>  	} else {	/* old style format */
>  		unsigned char csum = 0;
>  
> @@ -124,7 +124,7 @@ static int do_syno_populate(int argc, char *
> const argv[]) }
>  		bufp[n] = '\0';
>  		printf("parsed SN = %s\n", buf + 32);
> -		env_set("SN", buf + 32);
> +		env_set(ctx_uboot, "SN", buf + 32);
>  	}
>  out_unmap:
>  	unmap_physmem(buf, len);
> diff --git a/board/alliedtelesis/x530/x530.c
> b/board/alliedtelesis/x530/x530.c index e0fa8067c1c5..53bc9dd286e2
> 100644 --- a/board/alliedtelesis/x530/x530.c
> +++ b/board/alliedtelesis/x530/x530.c
> @@ -157,7 +157,7 @@ int misc_init_r(void)
>  	gpio_hog(&led_en, "atl,led-enable", "enable-gpio", 1);
>  
>  #ifdef MTDPARTS_MTDOOPS
> -	env_set("mtdoops", MTDPARTS_MTDOOPS);
> +	env_set(ctx_uboot, "mtdoops", MTDPARTS_MTDOOPS);
>  #endif
>  
>  	led_7seg_init(0xff);
> diff --git a/board/amazon/kc1/kc1.c b/board/amazon/kc1/kc1.c
> index 9034c4fbfff0..9f183da00a9e 100644
> --- a/board/amazon/kc1/kc1.c
> +++ b/board/amazon/kc1/kc1.c
> @@ -118,8 +118,8 @@ int misc_init_r(void)
>  	}
>  
>  	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
> -		if (!env_get("reboot-mode"))
> -			env_set("reboot-mode", (char *)reboot_mode);
> +		if (!env_get(ctx_uboot, "reboot-mode"))
> +			env_set(ctx_uboot, "reboot-mode", (char
> *)reboot_mode); }
>  
>  	omap_reboot_mode_clear();
> diff --git a/board/amlogic/p200/p200.c b/board/amlogic/p200/p200.c
> index 41d331dda2d4..4b1a158f1750 100644
> --- a/board/amlogic/p200/p200.c
> +++ b/board/amlogic/p200/p200.c
> @@ -32,11 +32,11 @@ int misc_init_r(void)
>  			eth_env_set_enetaddr("ethaddr", mac_addr);
>  	}
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
>  			EFUSE_SN_SIZE);
>  		if (len == EFUSE_SN_SIZE)
> -			env_set("serial#", serial);
> +			env_set(ctx_uboot, "serial#", serial);
>  	}
>  
>  	return 0;
> diff --git a/board/amlogic/p201/p201.c b/board/amlogic/p201/p201.c
> index e46fcaea6dcd..ba2a5387a120 100644
> --- a/board/amlogic/p201/p201.c
> +++ b/board/amlogic/p201/p201.c
> @@ -32,11 +32,11 @@ int misc_init_r(void)
>  			eth_env_set_enetaddr("ethaddr", mac_addr);
>  	}
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
>  			EFUSE_SN_SIZE);
>  		if (len == EFUSE_SN_SIZE)
> -			env_set("serial#", serial);
> +			env_set(ctx_uboot, "serial#", serial);
>  	}
>  
>  	return 0;
> diff --git a/board/amlogic/p212/p212.c b/board/amlogic/p212/p212.c
> index 094ab5478d00..3fabf79a4b41 100644
> --- a/board/amlogic/p212/p212.c
> +++ b/board/amlogic/p212/p212.c
> @@ -36,11 +36,11 @@ int misc_init_r(void)
>  			meson_generate_serial_ethaddr();
>  	}
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
>  			EFUSE_SN_SIZE);
>  		if (len == EFUSE_SN_SIZE)
> -			env_set("serial#", serial);
> +			env_set(ctx_uboot, "serial#", serial);
>  	}
>  
>  	return 0;
> diff --git a/board/amlogic/q200/q200.c b/board/amlogic/q200/q200.c
> index f1faa7418e07..2cf2af3e1899 100644
> --- a/board/amlogic/q200/q200.c
> +++ b/board/amlogic/q200/q200.c
> @@ -35,11 +35,11 @@ int misc_init_r(void)
>  			meson_generate_serial_ethaddr();
>  	}
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
>  					  EFUSE_SN_SIZE);
>  		if (len == EFUSE_SN_SIZE)
> -			env_set("serial#", serial);
> +			env_set(ctx_uboot, "serial#", serial);
>  	}
>  
>  	return 0;
> diff --git a/board/aristainetos/aristainetos-v2.c
> b/board/aristainetos/aristainetos-v2.c index
> c0a2e41f02e8..061baf0255db 100644 ---
> a/board/aristainetos/aristainetos-v2.c +++
> b/board/aristainetos/aristainetos-v2.c @@ -651,7 +651,7 @@ int
> board_late_init(void) {
>  	char *my_bootdelay;
>  	char bootmode = 0;
> -	char const *panel = env_get("panel");
> +	char const *panel = env_get(ctx_uboot, "panel");
>  
>  	/*
>  	 * Check the boot-source. If booting from NOR Flash,
> @@ -668,11 +668,11 @@ int board_late_init(void)
>  	bootmode |= (gpio_get_value(IMX_GPIO_NR(7, 1)) ? 1 : 0) << 2;
>  
>  	if (bootmode == 7) {
> -		my_bootdelay = env_get("nor_bootdelay");
> +		my_bootdelay = env_get(ctx_uboot, "nor_bootdelay");
>  		if (my_bootdelay != NULL)
> -			env_set("bootdelay", my_bootdelay);
> +			env_set(ctx_uboot, "bootdelay",
> my_bootdelay); else
> -			env_set("bootdelay", "-2");
> +			env_set(ctx_uboot, "bootdelay", "-2");
>  	}
>  
>  	/* if we have the lg panel, we can initialze it now */
> diff --git a/board/armltd/integrator/integrator.c
> b/board/armltd/integrator/integrator.c index
> 0a2baa72976c..72c9678218ae 100644 ---
> a/board/armltd/integrator/integrator.c +++
> b/board/armltd/integrator/integrator.c @@ -116,7 +116,7 @@ extern
> void cm_remap(void); 
>  int misc_init_r (void)
>  {
> -	env_set("verify", "n");
> +	env_set(ctx_uboot, "verify", "n");
>  	return (0);
>  }
>  
> diff --git a/board/atmel/common/board.c b/board/atmel/common/board.c
> index c41706c4005c..aef6babfd37a 100644
> --- a/board/atmel/common/board.c
> +++ b/board/atmel/common/board.c
> @@ -64,7 +64,7 @@ void at91_pda_detect(void)
>  	}
>  
>  pda_detect_err:
> -	env_set("pda", (const char *)buf);
> +	env_set(ctx_uboot, "pda", (const char *)buf);
>  }
>  #else
>  void at91_pda_detect(void)
> @@ -74,5 +74,5 @@ void at91_pda_detect(void)
>  
>  void at91_prepare_cpu_var(void)
>  {
> -	env_set("cpu", get_cpu_name());
> +	env_set(ctx_uboot, "cpu", get_cpu_name());
>  }
> diff --git a/board/atmel/common/mac_eeprom.c
> b/board/atmel/common/mac_eeprom.c index 83a7778e9954..4c9a5c0b0d0e
> 100644 --- a/board/atmel/common/mac_eeprom.c
> +++ b/board/atmel/common/mac_eeprom.c
> @@ -18,7 +18,7 @@ int at91_set_ethaddr(int offset)
>  	struct udevice *dev;
>  	int ret;
>  
> -	if (env_get(ETHADDR_NAME))
> +	if (env_get(ctx_uboot, ETHADDR_NAME))
>  		return 0;
>  
>  	ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
> diff --git a/board/atmel/sama5d3xek/sama5d3xek.c
> b/board/atmel/sama5d3xek/sama5d3xek.c index
> acf61486d20b..6c27c3dbe148 100644 ---
> a/board/atmel/sama5d3xek/sama5d3xek.c +++
> b/board/atmel/sama5d3xek/sama5d3xek.c @@ -187,7 +187,7 @@ int
> board_late_init(void) *p = tolower(*p);
>  
>  	strcat(name, "ek.dtb");
> -	env_set("dtb_name", name);
> +	env_set(ctx_uboot, "dtb_name", name);
>  #endif
>  #ifdef CONFIG_DM_VIDEO
>  	at91_video_show_board_info();
> diff --git a/board/bachmann/ot1200/ot1200.c
> b/board/bachmann/ot1200/ot1200.c index 36f37084b36c..baf7b7cdf7f3
> 100644 --- a/board/bachmann/ot1200/ot1200.c
> +++ b/board/bachmann/ot1200/ot1200.c
> @@ -301,9 +301,9 @@ int board_eth_init(bd_t *bis)
>  
>  	/* depending on the phy address we can detect our board
> version */ if (phydev->addr == 0)
> -		env_set("boardver", "");
> +		env_set(ctx_uboot, "boardver", "");
>  	else
> -		env_set("boardver", "mr");
> +		env_set(ctx_uboot, "boardver", "mr");
>  
>  	printf("using phy at %d\n", phydev->addr);
>  	ret = fec_probe(bis, -1, base, bus, phydev);
> diff --git a/board/birdland/bav335x/board.c
> b/board/birdland/bav335x/board.c index 8811583ac628..9a8b69df3891
> 100644 --- a/board/birdland/bav335x/board.c
> +++ b/board/birdland/bav335x/board.c
> @@ -161,7 +161,7 @@ int spl_start_uboot(void)
>  
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> +	env_load(ctx_uboot);
>  	if (env_get_yesno("boot_os") != 1)
>  		return 1;
>  #endif
> @@ -300,8 +300,8 @@ int board_init(void)
>  int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "BAV335xB");
> -	env_set("board_rev", "B"); /* Fix me, but why bother.. */
> +	env_set(ctx_uboot, "board_name", "BAV335xB");
> +	env_set(ctx_uboot, "board_rev", "B"); /* Fix me, but why
> bother.. */ #endif
>  	return 0;
>  }
> @@ -391,7 +391,7 @@ int board_eth_init(bd_t *bis)
>  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> diff --git a/board/bluegiga/apx4devkit/apx4devkit.c
> b/board/bluegiga/apx4devkit/apx4devkit.c index
> 9268aa0daafc..a7116e8c0c06 100644 ---
> a/board/bluegiga/apx4devkit/apx4devkit.c +++
> b/board/bluegiga/apx4devkit/apx4devkit.c @@ -133,8 +133,9 @@ void
> get_board_serial(struct tag_serialnr *serialnr) #ifdef
> CONFIG_REVISION_TAG u32 get_board_rev(void)
>  {
> -	if (env_get("revision#") != NULL)
> -		return simple_strtoul(env_get("revision#"), NULL,
> 10);
> +	if (env_get(ctx_uboot, "revision#"))
> +		return simple_strtoul(env_get(ctx_uboot,
> "revision#"), NULL,
> +				      10);
>  	return 0;
>  }
>  #endif
> diff --git a/board/bluewater/gurnard/gurnard.c
> b/board/bluewater/gurnard/gurnard.c index 48e31d9065a2..560db5fee639
> 100644 --- a/board/bluewater/gurnard/gurnard.c
> +++ b/board/bluewater/gurnard/gurnard.c
> @@ -340,7 +340,7 @@ int board_init(void)
>  	at91_set_A_periph(AT91_PIN_PE6, 1);	/* power up */
>  
>  	/* Select the second timing index for board rev 2 */
> -	rev_str = env_get("board_rev");
> +	rev_str = env_get(ctx_uboot, "board_rev");
>  	if (rev_str && !strncmp(rev_str, "2", 1)) {
>  		struct udevice *dev;
>  
> @@ -367,7 +367,7 @@ int board_late_init(void)
>  	 * Set MAC address so we do not need to init Ethernet before
> Linux
>  	 * boot
>  	 */
> -	env_str = env_get("ethaddr");
> +	env_str = env_get(ctx_uboot, "ethaddr");
>  	if (env_str) {
>  		struct at91_emac *emac = (struct at91_emac
> *)ATMEL_BASE_EMAC; /* Parse MAC address */
> @@ -384,7 +384,7 @@ int board_late_init(void)
>  		       &emac->sa2l);
>  		writel((env_enetaddr[4] | env_enetaddr[5] << 8),
> &emac->sa2h); 
> -		printf("MAC:   %s\n", env_get("ethaddr"));
> +		printf("MAC:   %s\n", env_get(ctx_uboot, "ethaddr"));
>  	} else {
>  		/* Not set in environment */
>  		printf("MAC:   not set\n");
> diff --git a/board/bosch/shc/board.c b/board/bosch/shc/board.c
> index a96fdef992d2..6afbdb9737ac 100644
> --- a/board/bosch/shc/board.c
> +++ b/board/bosch/shc/board.c
> @@ -246,7 +246,7 @@ static void check_button_status(void)
>  
>  	if (value == 0) {
>  		printf("front button activated !\n");
> -		env_set("harakiri", "1");
> +		env_set(ctx_uboot, "harakiri", "1");
>  	}
>  }
>  
> diff --git a/board/boundary/nitrogen6x/nitrogen6x.c
> b/board/boundary/nitrogen6x/nitrogen6x.c index
> 26af3f710250..e9a1cde72390 100644 ---
> a/board/boundary/nitrogen6x/nitrogen6x.c +++
> b/board/boundary/nitrogen6x/nitrogen6x.c @@ -749,7 +749,7 @@ size_t
> display_count = ARRAY_SIZE(displays); 
>  int board_cfb_skip(void)
>  {
> -	return NULL != env_get("novideo");
> +	return env_get(ctx_uboot, "novideo") != NULL;
>  }
>  
>  static void setup_display(void)
> @@ -954,7 +954,7 @@ static int do_kbd(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) {
>  	char envvalue[ARRAY_SIZE(buttons)+1];
>  	int numpressed = read_keys(envvalue);
> -	env_set("keybd", envvalue);
> +	env_set(ctx_uboot, "keybd", envvalue);
>  	return numpressed == 0;
>  }
>  
> @@ -974,7 +974,7 @@ static void preboot_keys(void)
>  	char keypress[ARRAY_SIZE(buttons)+1];
>  	numpressed = read_keys(keypress);
>  	if (numpressed) {
> -		char *kbd_magic_keys = env_get("magic_keys");
> +		char *kbd_magic_keys = env_get(ctx_uboot,
> "magic_keys"); char *suffix;
>  		/*
>  		 * loop over all magic keys
> @@ -983,7 +983,7 @@ static void preboot_keys(void)
>  			char *keys;
>  			char magic[sizeof(kbd_magic_prefix) + 1];
>  			sprintf(magic, "%s%c", kbd_magic_prefix,
> *suffix);
> -			keys = env_get(magic);
> +			keys = env_get(ctx_uboot, magic);
>  			if (keys) {
>  				if (!strcmp(keys, keypress))
>  					break;
> @@ -993,9 +993,9 @@ static void preboot_keys(void)
>  			char cmd_name[sizeof(kbd_command_prefix) +
> 1]; char *cmd;
>  			sprintf(cmd_name, "%s%c",
> kbd_command_prefix, *suffix);
> -			cmd = env_get(cmd_name);
> +			cmd = env_get(ctx_uboot, cmd_name);
>  			if (cmd) {
> -				env_set("preboot", cmd);
> +				env_set(ctx_uboot, "preboot", cmd);
>  				return;
>  			}
>  		}
> @@ -1021,6 +1021,6 @@ int misc_init_r(void)
>  #ifdef CONFIG_CMD_BMODE
>  	add_board_boot_modes(board_boot_modes);
>  #endif
> -	env_set_hex("reset_cause", get_imx_reset_cause());
> +	env_set_hex(ctx_uboot, "reset_cause",
> get_imx_reset_cause(void)); return 0;
>  }
> diff --git a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c
> b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c index
> ce9f0494ee59..51e7f2c0c847 100644 ---
> a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c +++
> b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c @@ -103,7 +103,7 @@ int
> board_usb_init(int index, enum usb_init_type init) int
> g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
> { debug("%s\n", __func__);
> -	if (!env_get("serial#"))
> +	if (!env_get(ctx_uboot, "serial#"))
>  		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
>  	return 0;
>  }
> diff --git a/board/broadcom/bcm28155_ap/bcm28155_ap.c
> b/board/broadcom/bcm28155_ap/bcm28155_ap.c index
> 87616386cb84..d9240cf35c8c 100644 ---
> a/board/broadcom/bcm28155_ap/bcm28155_ap.c +++
> b/board/broadcom/bcm28155_ap/bcm28155_ap.c @@ -110,7 +110,7 @@ int
> board_usb_init(int index, enum usb_init_type init) int
> g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
> { debug("%s\n", __func__);
> -	if (!env_get("serial#"))
> +	if (!env_get(ctx_uboot, "serial#"))
>  		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
>  	return 0;
>  }
> diff --git a/board/broadcom/bcmstb/bcmstb.c
> b/board/broadcom/bcmstb/bcmstb.c index 5fc2c0591b84..494c03d3eb79
> 100644 --- a/board/broadcom/bcmstb/bcmstb.c
> +++ b/board/broadcom/bcmstb/bcmstb.c
> @@ -120,7 +120,7 @@ int board_late_init(void)
>  	 * Set fdtcontroladdr in the environment so that scripts can
>  	 * refer to it, for example, to reuse it for fdtaddr.
>  	 */
> -	env_set_hex("fdtcontroladdr", prior_stage_fdt_address);
> +	env_set_hex(ctx_uboot, "fdtcontroladdr",
> prior_stage_fdt_address); 
>  	/*
>  	 * Do not set machid to the machine identifier value provided
> diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
> index 95d3a5e1f579..f1baed84e268 100644
> --- a/board/buffalo/lsxl/lsxl.c
> +++ b/board/buffalo/lsxl/lsxl.c
> @@ -229,7 +229,7 @@ static void erase_environment(void)
>  static void rescue_mode(void)
>  {
>  	printf("Entering rescue mode..\n");
> -	env_set("bootsource", "rescue");
> +	env_set(ctx_uboot, "bootsource", "rescue");
>  }
>  
>  static void check_push_button(void)
> diff --git a/board/cadence/xtfpga/xtfpga.c
> b/board/cadence/xtfpga/xtfpga.c index 256611638a55..1aee9c6f95a0
> 100644 --- a/board/cadence/xtfpga/xtfpga.c
> +++ b/board/cadence/xtfpga/xtfpga.c
> @@ -86,14 +86,14 @@ int misc_init_r(void)
>  	 * Default MAC address comes from CONFIG_ETHADDR + DIP
> switches 1-6. */
>  
> -	char *s = env_get("ethaddr");
> +	char *s = env_get(ctx_uboot, "ethaddr");
>  	if (s == 0) {
>  		unsigned int x;
>  		char s[] = __stringify(CONFIG_ETHBASE);
>  		x = (*(volatile u32 *)CONFIG_SYS_FPGAREG_DIPSW)
>  			& FPGAREG_MAC_MASK;
>  		sprintf(&s[15], "%02x", x);
> -		env_set("ethaddr", s);
> +		env_set(ctx_uboot, "ethaddr", s);
>  	}
>  #endif /* CONFIG_CMD_NET */
>  
> diff --git a/board/ccv/xpress/xpress.c b/board/ccv/xpress/xpress.c
> index 05286e643c0e..9518307f7a76 100644
> --- a/board/ccv/xpress/xpress.c
> +++ b/board/ccv/xpress/xpress.c
> @@ -324,7 +324,7 @@ static const struct boot_mode board_boot_modes[]
> = { int board_late_init(void)
>  {
>  	add_board_boot_modes(board_boot_modes);
> -	env_set("board_name", "xpress");
> +	env_set(ctx_uboot, "board_name", "xpress");
>  
>  	return 0;
>  }
> diff --git a/board/compulab/cl-som-imx7/cl-som-imx7.c
> b/board/compulab/cl-som-imx7/cl-som-imx7.c index
> 395d5dce1785..d05a0dcf32f5 100644 ---
> a/board/compulab/cl-som-imx7/cl-som-imx7.c +++
> b/board/compulab/cl-som-imx7/cl-som-imx7.c @@ -311,7 +311,7 @@ void
> cl_som_imx7_setup_wdog(void) 
>  int board_late_init(void)
>  {
> -	env_set("board_name", "CL-SOM-iMX7");
> +	env_set(ctx_uboot, "board_name", "CL-SOM-iMX7");
>  	cl_som_imx7_setup_wdog();
>  	return 0;
>  }
> diff --git a/board/compulab/cm_fx6/cm_fx6.c
> b/board/compulab/cm_fx6/cm_fx6.c index feb7a71f007d..50564fde2ba6
> 100644 --- a/board/compulab/cm_fx6/cm_fx6.c
> +++ b/board/compulab/cm_fx6/cm_fx6.c
> @@ -117,10 +117,10 @@ int board_video_skip(void)
>  {
>  	int ret;
>  	struct display_info_t *preset;
> -	char const *panel = env_get("displaytype");
> +	char const *panel = env_get(ctx_uboot, "displaytype");
>  
>  	if (!panel) /* Also accept panel for backward compatibility
> */
> -		panel = env_get("panel");
> +		panel = env_get(ctx_uboot, "panel");
>  
>  	if (!panel)
>  		return -ENOENT;
> @@ -628,16 +628,16 @@ int board_late_init(void)
>  	int err;
>  
>  	if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else if (is_mx6dl())
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  
>  	err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
>  	if (err)
>  		return 0;
>  
>  	if (!strncmp("SB-FX6m", baseboard_name, 7))
> -		env_set("board_name", "Utilite");
> +		env_set(ctx_uboot, "board_name", "Utilite");
>  #endif
>  	return 0;
>  }
> diff --git a/board/compulab/common/omap3_display.c
> b/board/compulab/common/omap3_display.c index
> cb9ebae7f964..9215a37d982a 100644 ---
> a/board/compulab/common/omap3_display.c +++
> b/board/compulab/common/omap3_display.c @@ -398,7 +398,7 @@ void
> lcd_ctrl_init(void *lcdbase) {
>  	struct prcm *prcm = (struct prcm *)PRCM_BASE;
>  	char *custom_lcd;
> -	char *displaytype = env_get("displaytype");
> +	char *displaytype = env_get(ctx_uboot, "displaytype");
>  
>  	if (displaytype == NULL)
>  		return;
> @@ -406,7 +406,7 @@ void lcd_ctrl_init(void *lcdbase)
>  	lcd_def = env_parse_displaytype(displaytype);
>  	/* If we did not recognize the preset, check if it's an env
> variable */ if (lcd_def == NONE) {
> -		custom_lcd = env_get(displaytype);
> +		custom_lcd = env_get(ctx_uboot, displaytype);
>  		if (custom_lcd == NULL ||
> parse_customlcd(custom_lcd) < 0) return;
>  	}
> diff --git a/board/congatec/cgtqmx6eval/cgtqmx6eval.c
> b/board/congatec/cgtqmx6eval/cgtqmx6eval.c index
> 6b3d5b833f44..8143f7680e7b 100644 ---
> a/board/congatec/cgtqmx6eval/cgtqmx6eval.c +++
> b/board/congatec/cgtqmx6eval/cgtqmx6eval.c @@ -236,7 +236,7 @@ int
> power_init_board(void) return 0;
>  
>  	/* set level of MIPI if specified */
> -	lv_mipi = env_get("lv_mipi");
> +	lv_mipi = env_get(ctx_uboot, "lv_mipi");
>  	if (lv_mipi)
>  		return 0;
>  
> @@ -584,7 +584,7 @@ int board_video_skip(void)
>  {
>  	int i;
>  	int ret;
> -	char const *panel = env_get("panel");
> +	char const *panel = env_get(ctx_uboot, "panel");
>  	if (!panel) {
>  		for (i = 0; i < ARRAY_SIZE(displays); i++) {
>  			struct display_info_t const *dev = displays
> + i; @@ -756,9 +756,9 @@ int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  #endif
>  
>  	return 0;
> diff --git a/board/cssi/MCR3000/MCR3000.c
> b/board/cssi/MCR3000/MCR3000.c index 445b84c180fe..0f7ba71bb647 100644
> --- a/board/cssi/MCR3000/MCR3000.c
> +++ b/board/cssi/MCR3000/MCR3000.c
> @@ -127,7 +127,7 @@ int misc_init_r(void)
>  
>  	/* if BTN_ACQ_AL is pressed then bootdelay is changed to 60
> second */ if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
> -		env_set("bootdelay", "60");
> +		env_set(ctx_uboot, "bootdelay", "60");
>  
>  	return 0;
>  }
> diff --git a/board/davinci/da8xxevm/da850evm.c
> b/board/davinci/da8xxevm/da850evm.c index d9019de6e006..31a380275553
> 100644 --- a/board/davinci/da8xxevm/da850evm.c
> +++ b/board/davinci/da8xxevm/da850evm.c
> @@ -280,7 +280,7 @@ u32 get_board_rev(void)
>  	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
>  	u32 rev = 0;
>  
> -	s = env_get("maxcpuclk");
> +	s = env_get(ctx_uboot, "maxcpuclk");
>  	if (s)
>  		maxcpuclk = simple_strtoul(s, NULL, 10);
>  
> diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c
> b/board/davinci/da8xxevm/omapl138_lcdk.c index
> 27a51d6a7802..0856b25c16e4 100644 ---
> a/board/davinci/da8xxevm/omapl138_lcdk.c +++
> b/board/davinci/da8xxevm/omapl138_lcdk.c @@ -275,7 +275,7 @@ static
> void dspwake(void) if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
>  		return;
>  
> -	if (!strcmp(env_get("dspwake"), "no"))
> +	if (!strcmp(env_get(ctx_uboot, "dspwake"), "no"))
>  		return;
>  
>  	*resetvect++ = 0x1E000; /* DSP Idle */
> @@ -305,7 +305,7 @@ int misc_init_r(void)
>  	uint8_t tmp[20], addr[10];
>  
>  
> -	if (env_get("ethaddr") == NULL) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		/* Read Ethernet MAC address from EEPROM */
>  		if (dvevm_read_mac_address(addr)) {
>  			/* Set Ethernet MAC address from EEPROM */
> @@ -319,7 +319,7 @@ int misc_init_r(void)
>  				addr[0], addr[1], addr[2], addr[3],
> addr[4], addr[5]);
>  
> -			env_set("ethaddr", (char *)tmp);
> +			env_set(ctx_uboot, "ethaddr", (char *)tmp);
>  		} else {
>  			printf("Invalid MAC address read.\n");
>  		}
> diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c
> b/board/dhelectronics/dh_imx6/dh_imx6.c index
> 2d0f78da118f..d904ab4170d3 100644 ---
> a/board/dhelectronics/dh_imx6/dh_imx6.c +++
> b/board/dhelectronics/dh_imx6/dh_imx6.c @@ -251,7 +251,7 @@ int
> board_late_init(void) break;
>  	}
>  
> -	env_set("dhcom", buf);
> +	env_set(ctx_uboot, "dhcom", buf);
>  
>  #ifdef CONFIG_CMD_BMODE
>  	add_board_boot_modes(board_boot_modes);
> diff --git a/board/eets/pdu001/board.c b/board/eets/pdu001/board.c
> index 8a3d0ada270e..104dc1d3c6f7 100644
> --- a/board/eets/pdu001/board.c
> +++ b/board/eets/pdu001/board.c
> @@ -79,15 +79,15 @@ static void env_set_boot_device(void)
>  {
>  	switch (boot_device()) {
>  		case BOOT_DEVICE_MMC1: {
> -			env_set("boot_device", "emmc");
> +			env_set(ctx_uboot, "boot_device", "emmc");
>  			break;
>  		}
>  		case BOOT_DEVICE_MMC2: {
> -			env_set("boot_device", "sdcard");
> +			env_set(ctx_uboot, "boot_device", "sdcard");
>  			break;
>  		}
>  		default: {
> -			env_set("boot_device", "unknown");
> +			env_set(ctx_uboot, "boot_device", "unknown");
>  			break;
>  		}
>  	}
> @@ -117,7 +117,7 @@ static void env_set_serial(struct udevice *dev)
>  		sprintf(serial + n, "%02X", val);
>  	}
>  	serial[2 * NODE_ID_BYTE_COUNT] = '\0';
> -	env_set("serial#", serial);
> +	env_set(ctx_uboot, "serial#", serial);
>  }
>  
>  static void set_mpu_and_core_voltage(void)
> diff --git a/board/el/el6x/el6x.c b/board/el/el6x/el6x.c
> index 18d69a7da388..606fe1530728 100644
> --- a/board/el/el6x/el6x.c
> +++ b/board/el/el6x/el6x.c
> @@ -467,7 +467,7 @@ int board_late_init(void)
>  	add_board_boot_modes(board_boot_modes);
>  #endif
>  
> -	env_set("board_name", BOARD_NAME);
> +	env_set(ctx_uboot, "board_name", BOARD_NAME);
>  	return 0;
>  }
>  
> diff --git a/board/emulation/qemu-riscv/qemu-riscv.c
> b/board/emulation/qemu-riscv/qemu-riscv.c index
> 37d48d04f2d0..6cb571ba036c 100644 ---
> a/board/emulation/qemu-riscv/qemu-riscv.c +++
> b/board/emulation/qemu-riscv/qemu-riscv.c @@ -46,7 +46,7 @@ int
> board_late_init(void) return 0;
>  	}
>  
> -	env_set_hex("kernel_start", kernel_start);
> +	env_set_hex(ctx_uboot, "kernel_start", kernel_start);
>  
>  	return 0;
>  }
> diff --git a/board/engicam/common/board.c
> b/board/engicam/common/board.c index 0c47afe5b566..b338c364efd0 100644
> --- a/board/engicam/common/board.c
> +++ b/board/engicam/common/board.c
> @@ -22,11 +22,11 @@ static void mmc_late_init(void)
>  	char mmcblk[32];
>  	u32 dev_no = mmc_get_env_dev();
>  
> -	env_set_ulong("mmcdev", dev_no);
> +	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
>  
>  	/* Set mmcblk env */
>  	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
> -	env_set("mmcroot", mmcblk);
> +	env_set(ctx_uboot, "mmcroot", mmcblk);
>  
>  	sprintf(cmd, "mmc dev %d", dev_no);
>  	run_command(cmd, 0);
> @@ -39,25 +39,25 @@ static void setenv_fdt_file(void)
>  
>  	if (!strcmp(cmp_dtb, "imx6q-icore")) {
>  		if (is_mx6dq())
> -			env_set("fdt_file", "imx6q-icore.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6q-icore.dtb"); else if (is_mx6dl() || is_mx6solo())
> -			env_set("fdt_file", "imx6dl-icore.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6dl-icore.dtb"); } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi"))
> { if (is_mx6dq())
> -			env_set("fdt_file", "imx6q-icore-mipi.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6q-icore-mipi.dtb"); else if (is_mx6dl() || is_mx6solo())
> -			env_set("fdt_file", "imx6dl-icore-mipi.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6dl-icore-mipi.dtb"); } else if (!strcmp(cmp_dtb,
> "imx6q-icore-rqs")) { if (is_mx6dq())
> -			env_set("fdt_file", "imx6q-icore-rqs.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6q-icore-rqs.dtb"); else if (is_mx6dl() || is_mx6solo())
> -			env_set("fdt_file", "imx6dl-icore-rqs.dtb");
> +			env_set(ctx_uboot, "fdt_file",
> "imx6dl-icore-rqs.dtb"); } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
> -		env_set("fdt_file", "imx6ul-geam.dtb");
> +		env_set(ctx_uboot, "fdt_file", "imx6ul-geam.dtb");
>  	else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
> -		env_set("fdt_file", "imx6ul-isiot-emmc.dtb");
> +		env_set(ctx_uboot, "fdt_file",
> "imx6ul-isiot-emmc.dtb"); else if (!strcmp(cmp_dtb,
> "imx6ul-isiot-nand"))
> -		env_set("fdt_file", "imx6ul-isiot-nand.dtb");
> +		env_set(ctx_uboot, "fdt_file",
> "imx6ul-isiot-nand.dtb"); }
>  
>  int board_late_init(void)
> @@ -71,20 +71,20 @@ int board_late_init(void)
>  #ifdef CONFIG_ENV_IS_IN_MMC
>  		mmc_late_init();
>  #endif
> -		env_set("modeboot", "mmcboot");
> +		env_set(ctx_uboot, "modeboot", "mmcboot");
>  		break;
>  	case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
> -		env_set("modeboot", "nandboot");
> +		env_set(ctx_uboot, "modeboot", "nandboot");
>  		break;
>  	default:
> -		env_set("modeboot", "");
> +		env_set(ctx_uboot, "modeboot", "");
>  		break;
>  	}
>  
>  	if (is_mx6ul())
> -		env_set("console", "ttymxc0");
> +		env_set(ctx_uboot, "console", "ttymxc0");
>  	else
> -		env_set("console", "ttymxc3");
> +		env_set(ctx_uboot, "console", "ttymxc3");
>  
>  	setenv_fdt_file();
>  
> diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
> index b0d2f7b6f87b..c9c1d77410cc 100644
> --- a/board/esd/meesc/meesc.c
> +++ b/board/esd/meesc/meesc.c
> @@ -181,7 +181,7 @@ int checkboard(void)
>  		puts("Board: EtherCAN/2 Gateway");
>  		break;
>  	}
> -	if (env_get_f("serial#", str, sizeof(str)) > 0) {
> +	if (env_get_f("serial#", str, sizeof(ctx_uboot, str)) > 0) {
>  		puts(", serial# ");
>  		puts(str);
>  	}
> @@ -198,7 +198,7 @@ void get_board_serial(struct tag_serialnr
> *serialnr) {
>  	char *str;
>  
> -	char *serial = env_get("serial#");
> +	char *serial = env_get(ctx_uboot, "serial#");
>  	if (serial) {
>  		str = strchr(serial, '_');
>  		if (str && (strlen(str) >= 4)) {
> @@ -231,7 +231,7 @@ int misc_init_r(void)
>  	 * In some cases this this needs to be set to 4.
>  	 * Check the user has set environment mdiv to 4 to change
> the divisor. */
> -	str = env_get("mdiv");
> +	str = env_get(ctx_uboot, "mdiv");
>  	if (str && (strcmp(str, "4") == 0)) {
>  		writel((readl(&pmc->mckr) & ~AT91_PMC_MDIV) |
>  			AT91SAM9_PMC_MDIV_4, &pmc->mckr);
> diff --git a/board/freescale/b4860qds/b4860qds.c
> b/board/freescale/b4860qds/b4860qds.c index
> 33cd4b496489..a8168e60a58a 100644 ---
> a/board/freescale/b4860qds/b4860qds.c +++
> b/board/freescale/b4860qds/b4860qds.c @@ -195,7 +195,7 @@ static int
> adjust_vdd(ulong vdd_override) vid, vdd_target/10);
>  
>  	/* check override variable for overriding VDD */
> -	vdd_string = env_get("b4qds_vdd_mv");
> +	vdd_string = env_get(ctx_uboot, "b4qds_vdd_mv");
>  	if (vdd_override == 0 && vdd_string &&
>  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
>  		vdd_override = vdd_string_override;
> @@ -542,7 +542,8 @@ int configure_vsc3316_3308(void)
>  			 * Extract hwconfig from environment since
> environment
>  			 * is not setup properly yet
>  			 */
> -			env_get_f("hwconfig", buffer,
> sizeof(buffer));
> +			env_get_f(ctx_uboot, "hwconfig", buffer,
> +				  sizeof(buffer));
>  			buf = buffer;
>  
>  			if
> (hwconfig_subarg_cmp_f("fsl_b4860_serdes2", diff --git
> a/board/freescale/common/cmd_esbc_validate.c
> b/board/freescale/common/cmd_esbc_validate.c index
> 36b620ca23a0..14ce924b8684 100644 ---
> a/board/freescale/common/cmd_esbc_validate.c +++
> b/board/freescale/common/cmd_esbc_validate.c @@ -53,7 +53,7 @@ static
> int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
>  	 * to continue U-Boot
>  	 */
>  	sprintf(buf, "%lx", img_addr);
> -	env_set("img_addr", buf);
> +	env_set(ctx_uboot, "img_addr", buf);
>  
>  	if (ret)
>  		return 1;
> diff --git a/board/freescale/common/fsl_chain_of_trust.c
> b/board/freescale/common/fsl_chain_of_trust.c index
> a024e7239e6e..9e216c3f51d7 100644 ---
> a/board/freescale/common/fsl_chain_of_trust.c +++
> b/board/freescale/common/fsl_chain_of_trust.c @@ -80,12 +80,12 @@ int
> fsl_setenv_chain_of_trust(void)
>  	 * bootdelay = 0 (To disable Boot Prompt)
>  	 * bootcmd = CONFIG_CHAIN_BOOT_CMD (Validate and execute
> Boot script) */
> -	env_set("bootdelay", "-2");
> +	env_set(ctx_uboot, "bootdelay", "-2");
>  
>  #ifdef CONFIG_ARM
> -	env_set("secureboot", "y");
> +	env_set(ctx_uboot, "secureboot", "y");
>  #else
> -	env_set("bootcmd", CONFIG_CHAIN_BOOT_CMD);
> +	env_set(ctx_uboot, "bootcmd", CONFIG_CHAIN_BOOT_CMD);
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/common/sys_eeprom.c
> b/board/freescale/common/sys_eeprom.c index
> bb655ca7447c..88640958c79d 100644 ---
> a/board/freescale/common/sys_eeprom.c +++
> b/board/freescale/common/sys_eeprom.c @@ -538,8 +538,8 @@ int
> mac_read_from_eeprom(void) /* Only initialize environment variables
> that are blank
>  			 * (i.e. have not yet been set)
>  			 */
> -			if (!env_get(enetvar))
> -				env_set(enetvar, ethaddr);
> +			if (!env_get(ctx_uboot, enetvar))
> +				env_set(ctx_uboot, enetvar, ethaddr);
>  		}
>  	}
>  
> diff --git a/board/freescale/common/vid.c
> b/board/freescale/common/vid.c index b37f3bf4f8fe..db23c8387e5c 100644
> --- a/board/freescale/common/vid.c
> +++ b/board/freescale/common/vid.c
> @@ -617,7 +617,7 @@ int adjust_vdd(ulong vdd_override)
>  	vdd_target = vdd[vid];
>  
>  	/* check override variable for overriding VDD */
> -	vdd_string = env_get(CONFIG_VID_FLS_ENV);
> +	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
>  	if (vdd_override == 0 && vdd_string &&
>  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
>  		vdd_override = vdd_string_override;
> @@ -824,7 +824,7 @@ int adjust_vdd(ulong vdd_override)
>  	vdd_target = vdd[vid];
>  
>  	/* check override variable for overriding VDD */
> -	vdd_string = env_get(CONFIG_VID_FLS_ENV);
> +	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
>  	if (vdd_override == 0 && vdd_string &&
>  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
>  		vdd_override = vdd_string_override;
> diff --git a/board/freescale/imx8mq_evk/imx8mq_evk.c
> b/board/freescale/imx8mq_evk/imx8mq_evk.c index
> 1463e6e6963b..1822df9f32e8 100644 ---
> a/board/freescale/imx8mq_evk/imx8mq_evk.c +++
> b/board/freescale/imx8mq_evk/imx8mq_evk.c @@ -123,8 +123,8 @@ int
> board_mmc_get_env_dev(int devno) int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "EVK");
> -	env_set("board_rev", "iMX8MQ");
> +	env_set(ctx_uboot, "board_name", "EVK");
> +	env_set(ctx_uboot, "board_rev", "iMX8MQ");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/imx8qm_mek/imx8qm_mek.c
> b/board/freescale/imx8qm_mek/imx8qm_mek.c index
> 76634a3a28ad..34ed03c3dec1 100644 ---
> a/board/freescale/imx8qm_mek/imx8qm_mek.c +++
> b/board/freescale/imx8qm_mek/imx8qm_mek.c @@ -126,8 +126,8 @@ int
> board_mmc_get_env_dev(int devno) int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "MEK");
> -	env_set("board_rev", "iMX8QM");
> +	env_set(ctx_uboot, "board_name", "MEK");
> +	env_set(ctx_uboot, "board_rev", "iMX8QM");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> b/board/freescale/imx8qxp_mek/imx8qxp_mek.c index
> 4ba83142841a..0d6152ac9551 100644 ---
> a/board/freescale/imx8qxp_mek/imx8qxp_mek.c +++
> b/board/freescale/imx8qxp_mek/imx8qxp_mek.c @@ -139,8 +139,8 @@ int
> board_mmc_get_env_dev(int devno) int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "MEK");
> -	env_set("board_rev", "iMX8QXP");
> +	env_set(ctx_uboot, "board_name", "MEK");
> +	env_set(ctx_uboot, "board_rev", "iMX8QXP");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c
> b/board/freescale/ls1088a/eth_ls1088aqds.c index
> 237088a53710..f618db490f00 100644 ---
> a/board/freescale/ls1088a/eth_ls1088aqds.c +++
> b/board/freescale/ls1088a/eth_ls1088aqds.c @@ -529,7 +529,7 @@ void
> ls1088a_handle_phy_interface_sgmii(int dpmac_id) serdes1_prtcl =
> serdes_get_number(FSL_SRDS_1, cfg); 
>  	int *riser_phy_addr;
> -	char *env_hwconfig = env_get("hwconfig");
> +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	if (hwconfig_f("xqsgmii", env_hwconfig))
>  		riser_phy_addr = &xqsgii_riser_phy_addr[0];
> @@ -670,7 +670,7 @@ int board_eth_init(bd_t *bis)
>  	int error = 0, i;
>  #ifdef CONFIG_FSL_MC_ENET
>  	struct memac_mdio_info *memac_mdio0_info;
> -	char *env_hwconfig = env_get("hwconfig");
> +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	initialize_dpmac_to_slot();
>  
> diff --git a/board/freescale/ls1088a/ls1088a.c
> b/board/freescale/ls1088a/ls1088a.c index f1592982a348..cdbfd90c19fa
> 100644 --- a/board/freescale/ls1088a/ls1088a.c
> +++ b/board/freescale/ls1088a/ls1088a.c
> @@ -984,7 +984,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  #ifdef CONFIG_MTD_NOR_FLASH
>  int is_flash_available(void)
>  {
> -	char *env_hwconfig = env_get("hwconfig");
> +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  	enum boot_src src = get_boot_src();
>  	int is_nor_flash_available = 1;
>  
> diff --git a/board/freescale/ls2080aqds/eth.c
> b/board/freescale/ls2080aqds/eth.c index 6a8788c31254..1103ca1d430c
> 100644 --- a/board/freescale/ls2080aqds/eth.c
> +++ b/board/freescale/ls2080aqds/eth.c
> @@ -506,7 +506,7 @@ static void initialize_dpmac_to_slot(void)
>  		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;  
>  
>  	char *env_hwconfig;
> -	env_hwconfig = env_get("hwconfig");
> +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	switch (serdes1_prtcl) {
>  	case 0x07:
> @@ -660,7 +660,7 @@ void ls2080a_handle_phy_interface_sgmii(int
> dpmac_id)
>  		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;  
>  
>  	int *riser_phy_addr;
> -	char *env_hwconfig = env_get("hwconfig");
> +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	if (hwconfig_f("xqsgmii", env_hwconfig))
>  		riser_phy_addr = &xqsgii_riser_phy_addr[0];
> @@ -906,7 +906,7 @@ int board_eth_init(bd_t *bis)
>  	unsigned int i;
>  	char *env_hwconfig;
>  
> -	env_hwconfig = env_get("hwconfig");
> +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	initialize_dpmac_to_slot();
>  
> diff --git a/board/freescale/ls2080aqds/ls2080aqds.c
> b/board/freescale/ls2080aqds/ls2080aqds.c index
> 91c80353edd6..6eef0536d162 100644 ---
> a/board/freescale/ls2080aqds/ls2080aqds.c +++
> b/board/freescale/ls2080aqds/ls2080aqds.c @@ -212,7 +212,7 @@ int
> board_init(void) 
>  	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
>  
> -	env_hwconfig = env_get("hwconfig");
> +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	if (hwconfig_f("dspi", env_hwconfig) &&
>  	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
> diff --git a/board/freescale/ls2080ardb/ls2080ardb.c
> b/board/freescale/ls2080ardb/ls2080ardb.c index
> e20267f27ce0..d7ea56a6613a 100644 ---
> a/board/freescale/ls2080ardb/ls2080ardb.c +++
> b/board/freescale/ls2080ardb/ls2080ardb.c @@ -265,7 +265,7 @@ int
> misc_init_r(void) 
>  	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
>  
> -	env_hwconfig = env_get("hwconfig");
> +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
>  
>  	if (hwconfig_f("dspi", env_hwconfig) &&
>  	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
> @@ -295,10 +295,10 @@ int misc_init_r(void)
>  	 */
>  	if ((SVR_SOC_VER(svr) == SVR_LS2088A) ||
>  	    (SVR_SOC_VER(svr) == SVR_LS2048A))
> -		env_set("board", "ls2088ardb");
> +		env_set(ctx_uboot, "board", "ls2088ardb");
>  	else if ((SVR_SOC_VER(svr) == SVR_LS2081A) ||
>  	    (SVR_SOC_VER(svr) == SVR_LS2041A))
> -		env_set("board", "ls2081ardb");
> +		env_set(ctx_uboot, "board", "ls2081ardb");
>  
>  	return 0;
>  }
> diff --git a/board/freescale/lx2160a/eth_lx2160aqds.c
> b/board/freescale/lx2160a/eth_lx2160aqds.c index
> 92c06e5060f1..40fb5092c337 100644 ---
> a/board/freescale/lx2160a/eth_lx2160aqds.c +++
> b/board/freescale/lx2160a/eth_lx2160aqds.c @@ -484,7 +484,7 @@ int
> board_eth_init(bd_t *bis)
>  	 * defining "dpmac_override" in hwconfig environment
> variable. */
>  	if (hwconfig("dpmac_override")) {
> -		env_dpmac = env_get("dpmac");
> +		env_dpmac = env_get(ctx_uboot, "dpmac");
>  		if (env_dpmac) {
>  			ret = hwconfig_arg_f("srds", &len,
> env_dpmac); if (ret) {
> diff --git a/board/freescale/mpc8323erdb/mpc8323erdb.c
> b/board/freescale/mpc8323erdb/mpc8323erdb.c index
> e5aecc4e1f28..aa19a1b8534d 100644 ---
> a/board/freescale/mpc8323erdb/mpc8323erdb.c +++
> b/board/freescale/mpc8323erdb/mpc8323erdb.c @@ -217,7 +217,8 @@ int
> mac_read_from_eeprom(void) buf[i * 6 + 4], buf[i * 6 + 5]);
>  					sprintf((char *)enetvar,
>  						i ? "eth%daddr" :
> "ethaddr", i);
> -					env_set((char *)enetvar,
> str);
> +					env_set(ctx_uboot, (char
> *)enetvar,
> +						str);
>  				}
>  			}
>  		}
> diff --git a/board/freescale/mpc837xemds/pci.c
> b/board/freescale/mpc837xemds/pci.c index 41b78cf5e4de..c6f734ef2625
> 100644 --- a/board/freescale/mpc837xemds/pci.c
> +++ b/board/freescale/mpc837xemds/pci.c
> @@ -67,7 +67,7 @@ static struct pci_region pcie_regions_1[] = {
>  
>  static int is_pex_x2(void)
>  {
> -	const char *pex_x2 = env_get("pex_x2");
> +	const char *pex_x2 = env_get(ctx_uboot, "pex_x2");
>  
>  	if (pex_x2 && !strcmp(pex_x2, "yes"))
>  		return 1;
> diff --git a/board/freescale/mpc837xerdb/mpc837xerdb.c
> b/board/freescale/mpc837xerdb/mpc837xerdb.c index
> 4ad62bcf1d6b..71939b240dae 100644 ---
> a/board/freescale/mpc837xerdb/mpc837xerdb.c +++
> b/board/freescale/mpc837xerdb/mpc837xerdb.c @@ -173,7 +173,7 @@ int
> board_mmc_init(bd_t *bd) char buffer[HWCONFIG_BUFFER_SIZE] = {0};
>  	int esdhc_hwconfig_enabled = 0;
>  
> -	if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
> +	if (env_get_f("hwconfig", buffer, sizeof(ctx_uboot, buffer))
> > 0) esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
>  
>  	if (esdhc_hwconfig_enabled == 0)
> diff --git a/board/freescale/mx51evk/mx51evk_video.c
> b/board/freescale/mx51evk/mx51evk_video.c index
> 3715c5d738f9..ed2a58ea4a9a 100644 ---
> a/board/freescale/mx51evk/mx51evk_video.c +++
> b/board/freescale/mx51evk/mx51evk_video.c @@ -76,7 +76,7 @@ void
> setup_iomux_lcd(void) int board_video_skip(void)
>  {
>  	int ret;
> -	char const *e = env_get("panel");
> +	char const *e = env_get(ctx_uboot, "panel");
>  
>  	if (e) {
>  		if (strcmp(e, "claa") == 0) {
> diff --git a/board/freescale/mx53loco/mx53loco.c
> b/board/freescale/mx53loco/mx53loco.c index
> a177815bb8aa..a3328a134fb8 100644 ---
> a/board/freescale/mx53loco/mx53loco.c +++
> b/board/freescale/mx53loco/mx53loco.c @@ -208,7 +208,7 @@ static int
> power_init(void) if (!p)
>  			return -ENODEV;
>  
> -		env_set("fdt_file", "imx53-qsb.dtb");
> +		env_set(ctx_uboot, "fdt_file", "imx53-qsb.dtb");
>  
>  		/* Set VDDA to 1.25V */
>  		val = DA9052_BUCKCORE_BCOREEN |
> DA_BUCKCORE_VBCORE_1_250V; @@ -251,7 +251,7 @@ static int
> power_init(void) if (!p)
>  			return -ENODEV;
>  
> -		env_set("fdt_file", "imx53-qsrb.dtb");
> +		env_set(ctx_uboot, "fdt_file", "imx53-qsrb.dtb");
>  
>  		/* Set VDDGP to 1.25V for 1GHz on SW1 */
>  		pmic_reg_read(p, REG_SW_0, &val);
> diff --git a/board/freescale/mx53loco/mx53loco_video.c
> b/board/freescale/mx53loco/mx53loco_video.c index
> ff3fc8ce3e6f..061c990bcfb5 100644 ---
> a/board/freescale/mx53loco/mx53loco_video.c +++
> b/board/freescale/mx53loco/mx53loco_video.c @@ -92,7 +92,7 @@ void
> setup_iomux_lcd(void) int board_video_skip(void)
>  {
>  	int ret;
> -	char const *e = env_get("panel");
> +	char const *e = env_get(ctx_uboot, "panel");
>  
>  	if (e) {
>  		if (strcmp(e, "seiko") == 0) {
> diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c
> b/board/freescale/mx6sabreauto/mx6sabreauto.c index
> dc156efbbcbc..a1cd8f4bc52e 100644 ---
> a/board/freescale/mx6sabreauto/mx6sabreauto.c +++
> b/board/freescale/mx6sabreauto/mx6sabreauto.c @@ -623,14 +623,14 @@
> int board_late_init(void) #endif
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "SABREAUTO");
> +	env_set(ctx_uboot, "board_name", "SABREAUTO");
>  
>  	if (is_mx6dqp())
> -		env_set("board_rev", "MX6QP");
> +		env_set(ctx_uboot, "board_rev", "MX6QP");
>  	else if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else if (is_mx6sdl())
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/mx6sabresd/mx6sabresd.c
> b/board/freescale/mx6sabresd/mx6sabresd.c index
> b0c0117968bf..fb4c03a428c8 100644 ---
> a/board/freescale/mx6sabresd/mx6sabresd.c +++
> b/board/freescale/mx6sabresd/mx6sabresd.c @@ -606,14 +606,14 @@ int
> board_late_init(void) #endif
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "SABRESD");
> +	env_set(ctx_uboot, "board_name", "SABRESD");
>  
>  	if (is_mx6dqp())
> -		env_set("board_rev", "MX6QP");
> +		env_set(ctx_uboot, "board_rev", "MX6QP");
>  	else if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else if (is_mx6sdl())
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c
> b/board/freescale/mx6sxsabresd/mx6sxsabresd.c index
> 1c10958879b1..b4bc682a5160 100644 ---
> a/board/freescale/mx6sxsabresd/mx6sxsabresd.c +++
> b/board/freescale/mx6sxsabresd/mx6sxsabresd.c @@ -309,7 +309,7 @@ int
> board_late_init(void) {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	if (is_reva())
> -		env_set("board_rev", "REVA");
> +		env_set(ctx_uboot, "board_rev", "REVA");
>  #endif
>  	return 0;
>  }
> diff --git a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
> b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c index
> ccbe4044786c..913b2c6c57b8 100644 ---
> a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c +++
> b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c @@ -545,12
> +545,12 @@ int board_late_init(void) #endif
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "EVK");
> +	env_set(ctx_uboot, "board_name", "EVK");
>  
>  	if (is_mx6ul_9x9_evk())
> -		env_set("board_rev", "9X9");
> +		env_set(ctx_uboot, "board_rev", "9X9");
>  	else
> -		env_set("board_rev", "14X14");
> +		env_set(ctx_uboot, "board_rev", "14X14");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/mx6ullevk/mx6ullevk.c
> b/board/freescale/mx6ullevk/mx6ullevk.c index
> e11934780262..8dc5511e245f 100644 ---
> a/board/freescale/mx6ullevk/mx6ullevk.c +++
> b/board/freescale/mx6ullevk/mx6ullevk.c @@ -84,8 +84,8 @@ int
> board_late_init(void) #endif
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", "EVK");
> -	env_set("board_rev", "14X14");
> +	env_set(ctx_uboot, "board_name", "EVK");
> +	env_set(ctx_uboot, "board_rev", "14X14");
>  #endif
>  
>  	return 0;
> diff --git a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
> b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c index
> a04a73528f8d..4a21c148b696 100644 ---
> a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c +++
> b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c @@ -350,7 +350,7 @@ int
> board_eth_init(bd_t *bis) 
>  #ifdef CONFIG_VSC7385_ENET
>  	/* If a VSC7385 microcode image is present, then upload it.
> */
> -	tmp = env_get("vscfw_addr");
> +	tmp = env_get(ctx_uboot, "vscfw_addr");
>  	if (tmp) {
>  		vscfw_addr = simple_strtoul(tmp, NULL, 16);
>  		printf("uploading VSC7385 microcode from %x\n",
> vscfw_addr); diff --git a/board/freescale/qemu-ppce500/qemu-ppce500.c
> b/board/freescale/qemu-ppce500/qemu-ppce500.c index
> fb36d8366c98..38608234b7d5 100644 ---
> a/board/freescale/qemu-ppce500/qemu-ppce500.c +++
> b/board/freescale/qemu-ppce500/qemu-ppce500.c @@ -211,10 +211,10 @@
> int last_stage_init(void) /* -kernel boot */
>  	prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len);
>  	if (prop && (len >= 8))
> -		env_set_hex("qemu_kernel_addr", *prop);
> +		env_set_hex(ctx_uboot, "qemu_kernel_addr", *prop);
>  
>  	/* Give the user a variable for the host fdt */
> -	env_set_hex("fdt_addr_r", (ulong)fdt);
> +	env_set_hex("fdt_addr_r", (ctx_uboot, ulong)fdt);
>  
>  	return 0;
>  }
> diff --git a/board/freescale/t4qds/t4240qds.c
> b/board/freescale/t4qds/t4240qds.c index bb18b97e6a2e..d4e92d6c8d51
> 100644 --- a/board/freescale/t4qds/t4240qds.c
> +++ b/board/freescale/t4qds/t4240qds.c
> @@ -265,7 +265,7 @@ static int adjust_vdd(ulong vdd_override)
>  	vdd_target = vdd[vid];
>  
>  	/* check override variable for overriding VDD */
> -	vdd_string = env_get("t4240qds_vdd_mv");
> +	vdd_string = env_get(ctx_uboot, "t4240qds_vdd_mv");
>  	if (vdd_override == 0 && vdd_string &&
>  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
>  		vdd_override = vdd_string_override;
> diff --git a/board/gardena/smart-gateway-at91sam/board.c
> b/board/gardena/smart-gateway-at91sam/board.c index
> 3e2da0d6f8e0..499605d5b6a1 100644 ---
> a/board/gardena/smart-gateway-at91sam/board.c +++
> b/board/gardena/smart-gateway-at91sam/board.c @@ -15,7 +15,7 @@
> DECLARE_GLOBAL_DATA_PTR; 
>  static void at91_prepare_cpu_var(void)
>  {
> -	env_set("cpu", get_cpu_name());
> +	env_set(ctx_uboot, "cpu", get_cpu_name());
>  }
>  
>  int board_late_init(void)
> diff --git a/board/gardena/smart-gateway-mt7688/board.c
> b/board/gardena/smart-gateway-mt7688/board.c index
> bd494c84fc80..fe39187d0738 100644 ---
> a/board/gardena/smart-gateway-mt7688/board.c +++
> b/board/gardena/smart-gateway-mt7688/board.c @@ -70,9 +70,9 @@ static
> bool prepare_uuid_var(const char *fd_ptr, const char *env_var_name,
> str[i] = errorchar; }
>  
> -	env = env_get(env_var_name);
> +	env = env_get(ctx_uboot, env_var_name);
>  	if (strcmp(env, str)) {
> -		env_set(env_var_name, str);
> +		env_set(ctx_uboot, env_var_name, str);
>  		env_updated = true;
>  	}
>  
> @@ -134,9 +134,9 @@ static void factory_data_env_config(void)
>  	if (!is_valid_ethaddr(ptr))
>  		printf("F-Data:Invalid MAC addr: wifi_mac %s\n",
> str); 
> -	env = env_get("wifiaddr");
> +	env = env_get(ctx_uboot, "wifiaddr");
>  	if (strcmp(env, str)) {
> -		env_set("wifiaddr", str);
> +		env_set(ctx_uboot, "wifiaddr", str);
>  		env_updated = 1;
>  	}
>  
> @@ -146,9 +146,9 @@ static void factory_data_env_config(void)
>  	if (!is_valid_ethaddr(ptr))
>  		printf("F-Data:Invalid MAC addr: eth_mac %s\n", str);
>  
> -	env = env_get("ethaddr");
> +	env = env_get(ctx_uboot, "ethaddr");
>  	if (strcmp(env, str)) {
> -		env_set("ethaddr", str);
> +		env_set(ctx_uboot, "ethaddr", str);
>  		env_updated = 1;
>  	}
>  
> @@ -161,7 +161,7 @@ static void factory_data_env_config(void)
>  	/* Check if the environment was updated and needs to get
> stored */ if (env_updated != 0) {
>  		printf("F-Data:Values don't match env values ->
> saving\n");
> -		env_save();
> +		env_save(ctx_uboot);
>  	} else {
>  		debug("F-Data:Values match current env values\n");
>  	}
> @@ -189,7 +189,7 @@ static void copy_or_generate_uuid(char *fd_ptr,
> const char *env_var_name) char *env;
>  
>  	/* Don't use the UUID dest place, as the \0 char won't fit */
> -	env = env_get(env_var_name);
> +	env = env_get(ctx_uboot, env_var_name);
>  	if (env)
>  		strncpy(str, env, UUID_STR_LEN);
>  	else
> diff --git a/board/gateworks/gw_ventana/common.c
> b/board/gateworks/gw_ventana/common.c index
> 1240a9da174f..0be40c2336ad 100644 ---
> a/board/gateworks/gw_ventana/common.c +++
> b/board/gateworks/gw_ventana/common.c @@ -1477,7 +1477,7 @@ void
> setup_board_gpio(int board, struct ventana_board_info *info) char
> arg[10]; size_t len;
>  	int i;
> -	int quiet = simple_strtol(env_get("quiet"), NULL, 10);
> +	int quiet = simple_strtol(env_get(ctx_uboot, "quiet"), NULL,
> 10); 
>  	if (board >= GW_UNKNOWN)
>  		return;
> diff --git a/board/gateworks/gw_ventana/gw_ventana.c
> b/board/gateworks/gw_ventana/gw_ventana.c index
> 8a694a71c90b..6782e6327978 100644 ---
> a/board/gateworks/gw_ventana/gw_ventana.c +++
> b/board/gateworks/gw_ventana/gw_ventana.c @@ -299,11 +299,12 @@ int
> board_eth_init(bd_t *bis) #endif
>  
>  	/* default to the first detected enet dev */
> -	if (!env_get("ethprime")) {
> +	if (!env_get(ctx_uboot, "ethprime")) {
>  		struct eth_device *dev = eth_get_dev_by_index(0);
>  		if (dev) {
> -			env_set("ethprime", dev->name);
> -			printf("set ethprime to %s\n",
> env_get("ethprime"));
> +			env_set(ctx_uboot, "ethprime", dev->name);
> +			printf("set ethprime to %s\n",
> +			       env_get(ctx_uboot, "ethprime"));
>  		}
>  	}
>  
> @@ -602,7 +603,7 @@ void board_pci_fixup_dev(struct pci_controller
> *hose, pci_dev_t dev, */
>  void get_board_serial(struct tag_serialnr *serialnr)
>  {
> -	char *serial = env_get("serial#");
> +	char *serial = env_get(ctx_uboot, "serial#");
>  
>  	if (serial) {
>  		serialnr->high = 0;
> @@ -685,11 +686,11 @@ int checkboard(void)
>  	int quiet; /* Quiet or minimal output mode */
>  
>  	quiet = 0;
> -	p = env_get("quiet");
> +	p = env_get(ctx_uboot, "quiet");
>  	if (p)
>  		quiet = simple_strtol(p, NULL, 10);
>  	else
> -		env_set("quiet", "0");
> +		env_set(ctx_uboot, "quiet", "0");
>  
>  	puts("\nGateworks Corporation Copyright 2014\n");
>  	if (info->model[0]) {
> @@ -764,26 +765,26 @@ int misc_init_r(void)
>  		else if (is_cpu_type(MXC_CPU_MX6DL) ||
>  			 is_cpu_type(MXC_CPU_MX6SOLO))
>  			cputype = "imx6dl";
> -		env_set("soctype", cputype);
> +		env_set(ctx_uboot, "soctype", cputype);
>  		if (8 << (ventana_info.nand_flash_size-1) >= 2048)
> -			env_set("flash_layout", "large");
> +			env_set(ctx_uboot, "flash_layout", "large");
>  		else
> -			env_set("flash_layout", "normal");
> +			env_set(ctx_uboot, "flash_layout", "normal");
>  		memset(str, 0, sizeof(str));
>  		for (i = 0; i < (sizeof(str)-1) && info->model[i];
> i++) str[i] = tolower(info->model[i]);
> -		env_set("model", str);
> -		if (!env_get("fdt_file")) {
> +		env_set(ctx_uboot, "model", str);
> +		if (!env_get(ctx_uboot, "fdt_file")) {
>  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> -			env_set("fdt_file", fdt);
> +			env_set(ctx_uboot, "fdt_file", fdt);
>  		}
>  		p = strchr(str, '-');
>  		if (p) {
>  			*p++ = 0;
>  
> -			env_set("model_base", str);
> +			env_set(ctx_uboot, "model_base", str);
>  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> -			env_set("fdt_file1", fdt);
> +			env_set(ctx_uboot, "fdt_file1", fdt);
>  			if (board_type != GW551x &&
>  			    board_type != GW552x &&
>  			    board_type != GW553x &&
> @@ -792,30 +793,30 @@ int misc_init_r(void)
>  			str[5] = 'x';
>  			str[6] = 0;
>  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> -			env_set("fdt_file2", fdt);
> +			env_set(ctx_uboot, "fdt_file2", fdt);
>  		}
>  
>  		/* initialize env from EEPROM */
>  		if (test_bit(EECONFIG_ETH0, info->config) &&
> -		    !env_get("ethaddr")) {
> +		    !env_get(ctx_uboot, "ethaddr")) {
>  			eth_env_set_enetaddr("ethaddr", info->mac0);
>  		}
>  		if (test_bit(EECONFIG_ETH1, info->config) &&
> -		    !env_get("eth1addr")) {
> +		    !env_get(ctx_uboot, "eth1addr")) {
>  			eth_env_set_enetaddr("eth1addr", info->mac1);
>  		}
>  
>  		/* board serial-number */
>  		sprintf(str, "%6d", info->serial);
> -		env_set("serial#", str);
> +		env_set(ctx_uboot, "serial#", str);
>  
>  		/* memory MB */
>  		sprintf(str, "%d", (int) (gd->ram_size >> 20));
> -		env_set("mem_mb", str);
> +		env_set(ctx_uboot, "mem_mb", str);
>  	}
>  
>  	/* Set a non-initialized hwconfig based on board
> configuration */
> -	if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
> +	if (!strcmp(env_get(ctx_uboot, "hwconfig"), "_UNKNOWN_")) {
>  		buf[0] = 0;
>  		if (gpio_cfg[board_type].rs232_en)
>  			strcat(buf, "rs232;");
> @@ -825,7 +826,7 @@ int misc_init_r(void)
>  			if (strlen(buf) + strlen(buf1) < sizeof(buf))
>  				strcat(buf, buf1);
>  		}
> -		env_set("hwconfig", buf);
> +		env_set(ctx_uboot, "hwconfig", buf);
>  	}
>  
>  	/* setup baseboard specific GPIO based on board and env */
> @@ -1040,7 +1041,7 @@ int fdt_fixup_sky2(void *blob, int np, struct
> pci_dev *dev) int j;
>  
>  	sprintf(mac, "eth1addr");
> -	tmp = env_get(mac);
> +	tmp = env_get(ctx_uboot, mac);
>  	if (tmp) {
>  		for (j = 0; j < 6; j++) {
>  			mac_addr[j] = tmp ?
> @@ -1128,8 +1129,8 @@ int ft_board_setup(void *blob, bd_t *bd)
>  		{ "sst,w25q256",          MTD_DEV_TYPE_NOR, },  /*
> SPI flash */ { "fsl,imx6q-gpmi-nand",  MTD_DEV_TYPE_NAND, }, /* NAND
> flash */ };
> -	const char *model = env_get("model");
> -	const char *display = env_get("display");
> +	const char *model = env_get(ctx_uboot, "model");
> +	const char *display = env_get(ctx_uboot, "display");
>  	int i;
>  	char rev = 0;
>  
> @@ -1141,7 +1142,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  		}
>  	}
>  
> -	if (env_get("fdt_noauto")) {
> +	if (env_get(ctx_uboot, "fdt_noauto")) {
>  		puts("   Skiping ft_board_setup (fdt_noauto
> defined)\n"); return 0;
>  	}
> @@ -1162,15 +1163,15 @@ int ft_board_setup(void *blob, bd_t *bd)
>  	printf("   Adjusting FDT per EEPROM for %s...\n", model);
>  
>  	/* board serial number */
> -	fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
> -		    strlen(env_get("serial#")) + 1);
> +	fdt_setprop(blob, 0, "system-serial", env_get(ctx_uboot,
> "serial#"),
> +		    strlen(env_get(ctx_uboot, "serial#")) + 1);
>  
>  	/* board (model contains model from device-tree) */
>  	fdt_setprop(blob, 0, "board", info->model,
>  		    strlen((const char *)info->model) + 1);
>  
>  	/* set desired digital video capture format */
> -	ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
> +	ft_sethdmiinfmt(blob, env_get(ctx_uboot, "hdmiinfmt"));
>  
>  	/*
>  	 * Board model specific fixups
> @@ -1340,7 +1341,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  	}
>  
>  #if defined(CONFIG_CMD_PCI)
> -	if (!env_get("nopcifixup"))
> +	if (!env_get(ctx_uboot, "nopcifixup"))
>  		ft_board_pci_fixup(blob, bd);
>  #endif
>  
> @@ -1349,7 +1350,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  	 *  remove nodes by alias path if EEPROM config tells us the
>  	 *  peripheral is not loaded on the board.
>  	 */
> -	if (env_get("fdt_noconfig")) {
> +	if (env_get(ctx_uboot, "fdt_noconfig")) {
>  		puts("   Skiping periperhal config (fdt_noconfig
> defined)\n"); return 0;
>  	}
> diff --git a/board/gateworks/gw_ventana/gw_ventana_spl.c
> b/board/gateworks/gw_ventana/gw_ventana_spl.c index
> b0891379a170..a689ec16d98c 100644 ---
> a/board/gateworks/gw_ventana/gw_ventana_spl.c +++
> b/board/gateworks/gw_ventana/gw_ventana_spl.c @@ -758,8 +758,8 @@ int
> spl_start_uboot(void) debug("%s\n", __func__);
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> -	debug("boot_os=%s\n", env_get("boot_os"));
> +	env_load(ctx_uboot);
> +	debug("boot_os=%s\n", env_get(ctx_uboot, "boot_os"));
>  	if (env_get_yesno("boot_os") == 1)
>  		ret = 0;
>  #else
> diff --git a/board/gdsys/a38x/keyprogram.c
> b/board/gdsys/a38x/keyprogram.c index 000897984a6e..f65190d814c2
> 100644 --- a/board/gdsys/a38x/keyprogram.c
> +++ b/board/gdsys/a38x/keyprogram.c
> @@ -131,12 +131,12 @@ int load_and_run_keyprog(struct udevice *tpm)
>  	char *hexprog;
>  	struct key_program *prog;
>  
> -	cmd = env_get("loadkeyprogram");
> +	cmd = env_get(ctx_uboot, "loadkeyprogram");
>  
>  	if (!cmd || run_command(cmd, 0))
>  		return 1;
>  
> -	hexprog = env_get("keyprogram");
> +	hexprog = env_get(ctx_uboot, "keyprogram");
>  
>  	if (decode_hexstr(hexprog, &binprog))
>  		return 1;
> diff --git a/board/gdsys/mpc8308/gazerbeam.c
> b/board/gdsys/mpc8308/gazerbeam.c index ddd6ee895384..4929296364b3
> 100644 --- a/board/gdsys/mpc8308/gazerbeam.c
> +++ b/board/gdsys/mpc8308/gazerbeam.c
> @@ -85,7 +85,7 @@ int board_early_init_r(void)
>  int checkboard(void)
>  {
>  	struct udevice *board;
> -	char *s = env_get("serial#");
> +	char *s = env_get(ctx_uboot, "serial#");
>  	int mc = 0;
>  	int con = 0;
>  
> @@ -137,7 +137,7 @@ int last_stage_init(void)
>  			printf("Could not determind FPGA HW revision
> (res = %d)\n", res); }
>  
> -	env_set_ulong("fpga_hw_rev", fpga_hw_rev);
> +	env_set_ulong(ctx_uboot, "fpga_hw_rev", fpga_hw_rev);
>  
>  	ret = get_tpm(&tpm);
>  	if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
> diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c
> index 60faa4688cf8..666eb25c809c 100644
> --- a/board/gdsys/mpc8308/hrcon.c
> +++ b/board/gdsys/mpc8308/hrcon.c
> @@ -101,7 +101,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t
> regoff, u16 *data) 
>  int checkboard(void)
>  {
> -	char *s = env_get("serial#");
> +	char *s = env_get(ctx_uboot, "serial#");
>  	bool hw_type_cat = pca9698_get_value(0x20, 20);
>  
>  	puts("Board: ");
> diff --git a/board/gdsys/mpc8308/strider.c
> b/board/gdsys/mpc8308/strider.c index 886bc2b035de..cc3fcd7de172
> 100644 --- a/board/gdsys/mpc8308/strider.c
> +++ b/board/gdsys/mpc8308/strider.c
> @@ -104,7 +104,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t
> regoff, u16 *data) 
>  int checkboard(void)
>  {
> -	char *s = env_get("serial#");
> +	char *s = env_get(ctx_uboot, "serial#");
>  	bool hw_type_cat = pca9698_get_value(0x20, 18);
>  
>  	puts("Board: ");
> diff --git a/board/gdsys/p1022/controlcenterd-id.c
> b/board/gdsys/p1022/controlcenterd-id.c index
> 43f5404231f0..db7c92446e75 100644 ---
> a/board/gdsys/p1022/controlcenterd-id.c +++
> b/board/gdsys/p1022/controlcenterd-id.c @@ -231,7 +231,7 @@ static u8
> *get_2nd_stage_bl_location(ulong target_addr) {
>  	ulong addr;
>  #ifdef CCDM_SECOND_STAGE
> -	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
> +	addr = env_get_ulong(ctx_uboot, "loadaddr", 16,
> CONFIG_LOADADDR); #else
>  	addr = target_addr;
>  #endif
> @@ -249,7 +249,7 @@ static u8 *get_image_location(void)
>  {
>  	ulong addr;
>  	/* TODO use other area? */
> -	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
> +	addr = env_get_ulong(ctx_uboot, "loadaddr", 16,
> CONFIG_LOADADDR); return (u8 *)(addr);
>  }
>  #endif
> @@ -1072,13 +1072,13 @@ static int second_stage_init(void)
>  		goto failure;
>  
>  	/* run "prepboot" from env to get "mmcdev" set */
> -	cptr = env_get("prepboot");
> +	cptr = env_get(ctx_uboot, "prepboot");
>  	if (cptr && !run_command(cptr, 0))
> -		mmcdev = env_get("mmcdev");
> +		mmcdev = env_get(ctx_uboot, "mmcdev");
>  	if (!mmcdev)
>  		goto failure;
>  
> -	cptr = env_get("ramdiskimage");
> +	cptr = env_get(ctx_uboot, "ramdiskimage");
>  	if (cptr)
>  		image_path = cptr;
>  
> diff --git a/board/gdsys/p1022/controlcenterd.c
> b/board/gdsys/p1022/controlcenterd.c index 6eb3d6c5d06e..ec349d61ee33
> 100644 --- a/board/gdsys/p1022/controlcenterd.c
> +++ b/board/gdsys/p1022/controlcenterd.c
> @@ -222,7 +222,7 @@ void hw_watchdog_reset(void)
>  #ifdef CONFIG_TRAILBLAZER
>  int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const
> argv[]) {
> -	return run_command(env_get("bootcmd"), flag);
> +	return run_command(env_get(ctx_uboot, "bootcmd"), flag);
>  }
>  
>  int board_early_init_r(void)
> diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
> index 917ecc4c1816..3262a73d0b80 100644
> --- a/board/ge/bx50v3/bx50v3.c
> +++ b/board/ge/bx50v3/bx50v3.c
> @@ -470,17 +470,17 @@ static void process_vpd(struct vpd_cache *vpd)
>  
>  	switch (vpd->product_id) {
>  	case VPD_PRODUCT_B450:
> -		env_set("confidx", "1");
> +		env_set(ctx_uboot, "confidx", "1");
>  		i210_index = 0;
>  		fec_index = 1;
>  		break;
>  	case VPD_PRODUCT_B650:
> -		env_set("confidx", "2");
> +		env_set(ctx_uboot, "confidx", "2");
>  		i210_index = 0;
>  		fec_index = 1;
>  		break;
>  	case VPD_PRODUCT_B850:
> -		env_set("confidx", "3");
> +		env_set(ctx_uboot, "confidx", "3");
>  		i210_index = 1;
>  		fec_index = 2;
>  		break;
> @@ -647,9 +647,10 @@ int board_late_init(void)
>  #endif
>  
>  	if (is_b850v3())
> -		env_set("videoargs", "video=DP-1:1024x768 at 60
> video=HDMI-A-1:1024x768 at 60");
> +		env_set(ctx_uboot, "videoargs",
> +			"video=DP-1:1024x768 at 60
> video=HDMI-A-1:1024x768 at 60"); else
> -		env_set("videoargs", "video=LVDS-1:1024x768 at 65");
> +		env_set(ctx_uboot, "videoargs",
> "video=LVDS-1:1024x768 at 65"); 
>  	/* board specific pmic init */
>  	pmic_init();
> @@ -669,7 +670,7 @@ static void remove_ethaddr_env_var(int index)
>  	char env_var_name[9];
>  
>  	sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr",
> index);
> -	env_set(env_var_name, NULL);
> +	env_set(ctx_uboot, env_var_name, NULL);
>  }
>  
>  int last_stage_init(void)
> diff --git a/board/ge/common/ge_common.c b/board/ge/common/ge_common.c
> index 501c8b2daf2a..1d5f7ac39350 100644
> --- a/board/ge/common/ge_common.c
> +++ b/board/ge/common/ge_common.c
> @@ -29,7 +29,7 @@ void check_time(void)
>  	}
>  
>  	if (ret < 0)
> -		env_set("rtc_status", "RTC_ERROR");
> +		env_set(ctx_uboot, "rtc_status", "RTC_ERROR");
>  
>  	if (tm.tm_year > 2037) {
>  		tm.tm_sec  = 0;
> @@ -47,7 +47,7 @@ void check_time(void)
>  		}
>  
>  		if (ret < 0)
> -			env_set("rtc_status", "RTC_ERROR");
> +			env_set(ctx_uboot, "rtc_status",
> "RTC_ERROR"); }
>  
>  	i2c_set_bus_num(current_i2c_bus);
> diff --git a/board/ge/mx53ppd/mx53ppd.c b/board/ge/mx53ppd/mx53ppd.c
> index 544856729821..f2a76dc1ded8 100644
> --- a/board/ge/mx53ppd/mx53ppd.c
> +++ b/board/ge/mx53ppd/mx53ppd.c
> @@ -274,7 +274,7 @@ int misc_init_r(void)
>  	else
>  		cause = "POR";
>  
> -	env_set("bootcause", cause);
> +	env_set(ctx_uboot, "bootcause", cause);
>  
>  	return 0;
>  }
> diff --git a/board/grinn/chiliboard/board.c
> b/board/grinn/chiliboard/board.c index c6d53600fa1c..933bdc779601
> 100644 --- a/board/grinn/chiliboard/board.c
> +++ b/board/grinn/chiliboard/board.c
> @@ -117,7 +117,7 @@ int board_late_init(void)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> @@ -133,7 +133,7 @@ int board_late_init(void)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
> diff --git a/board/grinn/liteboard/board.c
> b/board/grinn/liteboard/board.c index 1558ea4b84f5..53eabe2e4b3b
> 100644 --- a/board/grinn/liteboard/board.c
> +++ b/board/grinn/liteboard/board.c
> @@ -127,7 +127,7 @@ int board_mmc_init(bd_t *bis)
>  
>  static int check_mmc_autodetect(void)
>  {
> -	char *autodetect_str = env_get("mmcautodetect");
> +	char *autodetect_str = env_get(ctx_uboot, "mmcautodetect");
>  
>  	if ((autodetect_str != NULL) &&
>  	    (strcmp(autodetect_str, "yes") == 0)) {
> @@ -146,12 +146,12 @@ void board_late_mmc_init(void)
>  	if (!check_mmc_autodetect())
>  		return;
>  
> -	env_set_ulong("mmcdev", dev_no);
> +	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
>  
>  	/* Set mmcblk env */
>  	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
>  		dev_no);
> -	env_set("mmcroot", mmcblk);
> +	env_set(ctx_uboot, "mmcroot", mmcblk);
>  
>  	sprintf(cmd, "mmc dev %d", dev_no);
>  	run_command(cmd, 0);
> diff --git a/board/highbank/highbank.c b/board/highbank/highbank.c
> index 9563763dfa53..ef2f6f1f16a8 100644
> --- a/board/highbank/highbank.c
> +++ b/board/highbank/highbank.c
> @@ -80,11 +80,12 @@ int misc_init_r(void)
>  
>  	boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
>  	sprintf(envbuffer, "bootcmd%d", boot_choice);
> -	if (env_get(envbuffer)) {
> +	if (env_get(ctx_uboot, envbuffer)) {
>  		sprintf(envbuffer, "run bootcmd%d", boot_choice);
> -		env_set("bootcmd", envbuffer);
> -	} else
> -		env_set("bootcmd", "");
> +		env_set(ctx_uboot, "bootcmd", envbuffer);
> +	} else {
> +		env_set(ctx_uboot, "bootcmd", "");
> +	}
>  
>  	return 0;
>  }
> diff --git a/board/hisilicon/poplar/poplar.c
> b/board/hisilicon/poplar/poplar.c index 4926419a905a..1177e91a688a
> 100644 --- a/board/hisilicon/poplar/poplar.c
> +++ b/board/hisilicon/poplar/poplar.c
> @@ -177,7 +177,7 @@ int board_usb_init(int index, enum usb_init_type
> init) 
>  int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char
> *name) {
> -	if (!env_get("serial#"))
> +	if (!env_get(ctx_uboot, "serial#"))
>  		g_dnl_set_serialnumber("0123456789POPLAR");
>  	return 0;
>  }
> diff --git a/board/imgtec/ci20/ci20.c b/board/imgtec/ci20/ci20.c
> index 5368b67b38b6..a34553a7bb3b 100644
> --- a/board/imgtec/ci20/ci20.c
> +++ b/board/imgtec/ci20/ci20.c
> @@ -181,12 +181,12 @@ int misc_init_r(void)
>  	eth_env_set_enetaddr("ethaddr", otp.mac);
>  
>  	/* Put other board information into the environment */
> -	env_set_ulong("serial#", otp.serial_number);
> -	env_set_ulong("board_date", otp.date);
> +	env_set_ulong(ctx_uboot, "serial#", otp.serial_number);
> +	env_set_ulong(ctx_uboot, "board_date", otp.date);
>  	manufacturer[0] = otp.manufacturer[0];
>  	manufacturer[1] = otp.manufacturer[1];
>  	manufacturer[2] = 0;
> -	env_set("board_mfr", manufacturer);
> +	env_set(ctx_uboot, "board_mfr", manufacturer);
>  
>  	return 0;
>  }
> diff --git a/board/intel/edison/edison.c b/board/intel/edison/edison.c
> index f56b5b1affef..2de8a4936286 100644
> --- a/board/intel/edison/edison.c
> +++ b/board/intel/edison/edison.c
> @@ -71,14 +71,14 @@ static void assign_serial(void)
>  
>  	snprintf(usb0addr, sizeof(usb0addr),
> "02:00:86:%02x:%02x:%02x", ssn[13], ssn[14], ssn[15]);
> -	env_set("usb0addr", usb0addr);
> +	env_set(ctx_uboot, "usb0addr", usb0addr);
>  
>  	for (i = 0; i < 16; i++)
>  		snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
> -	env_set("serial#", serial);
> +	env_set(ctx_uboot, "serial#", serial);
>  
>  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
> -	env_save();
> +	env_save(ctx_uboot);
>  #endif
>  }
>  
> @@ -93,19 +93,19 @@ static void assign_hardware_id(void)
>  		printf("Can't retrieve hardware revision\n");
>  
>  	snprintf(hardware_id, sizeof(hardware_id), "%02X",
> v.hardware_id);
> -	env_set("hardware_id", hardware_id);
> +	env_set(ctx_uboot, "hardware_id", hardware_id);
>  
>  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
> -	env_save();
> +	env_save(ctx_uboot);
>  #endif
>  }
>  
>  int board_late_init(void)
>  {
> -	if (!env_get("serial#"))
> +	if (!env_get(ctx_uboot, "serial#"))
>  		assign_serial();
>  
> -	if (!env_get("hardware_id"))
> +	if (!env_get(ctx_uboot, "hardware_id"))
>  		assign_hardware_id();
>  
>  	return 0;
> diff --git a/board/isee/igep003x/board.c b/board/isee/igep003x/board.c
> index a8c2b121a476..56ecf3497245 100644
> --- a/board/isee/igep003x/board.c
> +++ b/board/isee/igep003x/board.c
> @@ -193,13 +193,13 @@ int board_late_init(void)
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	switch (get_board_revision()) {
>  		case 0:
> -			env_set("board_name", "igep0034-lite");
> +			env_set(ctx_uboot, "board_name",
> "igep0034-lite"); break;
>  		case 1:
> -			env_set("board_name", "igep0034");
> +			env_set(ctx_uboot, "board_name", "igep0034");
>  			break;
>  		default:
> -			env_set("board_name", "igep0033");
> +			env_set(ctx_uboot, "board_name", "igep0033");
>  			break;
>  	}
>  #endif
> diff --git a/board/isee/igep00x0/igep00x0.c
> b/board/isee/igep00x0/igep00x0.c index 74fc5f08900a..42476b2b657b
> 100644 --- a/board/isee/igep00x0/igep00x0.c
> +++ b/board/isee/igep00x0/igep00x0.c
> @@ -199,8 +199,8 @@ void set_boardname(void)
>  	int i = get_board_revision();
>  
>  	rev[i+1] = 0;
> -	env_set("board_rev", rev + i);
> -	env_set("board_name", i < 2 ? "igep0020" : "igep0030");
> +	env_set(ctx_uboot, "board_rev", rev + i);
> +	env_set(ctx_uboot, "board_name", i < 2 ? "igep0020" :
> "igep0030"); }
>  
>  /*
> diff --git a/board/k+p/kp_imx53/kp_id_rev.c
> b/board/k+p/kp_imx53/kp_id_rev.c index 9dae54dda5fc..5c9258912c89
> 100644 --- a/board/k+p/kp_imx53/kp_id_rev.c
> +++ b/board/k+p/kp_imx53/kp_id_rev.c
> @@ -31,7 +31,7 @@ void show_eeprom(void)
>  
>  	if (!strncmp(safe_string, "TQM", 3)) {
>  		printf("  ID: %s\n", safe_string);
> -		env_set("boardtype", safe_string);
> +		env_set(ctx_uboot, "boardtype", safe_string);
>  	} else {
>  		puts("  unknown hardware variant\n");
>  	}
> @@ -45,7 +45,7 @@ void show_eeprom(void)
>  
>  	if (strlen(safe_string) == 8) {
>  		printf("  SN: %s\n", safe_string);
> -		env_set("serial#", safe_string);
> +		env_set(ctx_uboot, "serial#", safe_string);
>  	} else {
>  		puts("  unknown serial number\n");
>  	}
> @@ -103,18 +103,18 @@ int read_board_id(void)
>  	sprintf(rev_str, "%02X", rev_id);
>  	if (rev_id & 0x80) {
>  		printf("BBoard:4x00 Rev:%s\n", rev_str);
> -		env_set("boardtype", "ddc");
> -		env_set("fit_config", "imx53_kb_conf");
> +		env_set(ctx_uboot, "boardtype", "ddc");
> +		env_set(ctx_uboot, "fit_config", "imx53_kb_conf");
>  	} else {
>  		printf("BBoard:40x0 Rev:%s\n", rev_str);
> -		env_set("boardtype", "hsc");
> -		env_set("fit_config", "imx53_kb_40x0_conf");
> +		env_set(ctx_uboot, "boardtype", "hsc");
> +		env_set(ctx_uboot, "fit_config",
> "imx53_kb_40x0_conf"); }
>  
> -	sprintf(buf, "kp-%s", env_get("boardtype"));
> -	env_set("boardname", buf);
> -	env_set("boardsoc", "imx53");
> -	env_set("kb53_rev", rev_str);
> +	sprintf(buf, "kp-%s", env_get(ctx_uboot, "boardtype"));
> +	env_set(ctx_uboot, "boardname", buf);
> +	env_set(ctx_uboot, "boardsoc", "imx53");
> +	env_set(ctx_uboot, "kb53_rev", rev_str);
>  
>  	return 0;
>  }
> diff --git a/board/k+p/kp_imx53/kp_imx53.c
> b/board/k+p/kp_imx53/kp_imx53.c index 84cddd489490..36b9b9377f03
> 100644 --- a/board/k+p/kp_imx53/kp_imx53.c
> +++ b/board/k+p/kp_imx53/kp_imx53.c
> @@ -124,9 +124,9 @@ void board_misc_setup(void)
>  	gpio_direction_input(KEY1);
>  
>  	if (gpio_get_value(KEY1))
> -		env_set("key1", "off");
> +		env_set(ctx_uboot, "key1", "off");
>  	else
> -		env_set("key1", "on");
> +		env_set(ctx_uboot, "key1", "on");
>  }
>  
>  int board_late_init(void)
> diff --git a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c
> b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c index
> 2c541ace0210..9536ae2171d2 100644 ---
> a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c +++
> b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c @@ -290,8 +290,8 @@ int
> board_late_init(void) add_board_boot_modes(board_boot_modes);
>  #endif
>  
> -	env_set("boardname", "kp-tpc");
> -	env_set("boardsoc", "imx6q");
> +	env_set(ctx_uboot, "boardname", "kp-tpc");
> +	env_set(ctx_uboot, "boardsoc", "imx6q");
>  	return 0;
>  }
>  
> diff --git a/board/keymile/common/common.c
> b/board/keymile/common/common.c index 08f7f8d88451..3e15a063b34a
> 100644 --- a/board/keymile/common/common.c
> +++ b/board/keymile/common/common.c
> @@ -51,24 +51,24 @@ int set_km_env(void)
>  	pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM -
> CONFIG_KM_PHRAM
>  			- CONFIG_KM_PNVRAM;
>  	sprintf((char *)buf, "0x%x", pnvramaddr);
> -	env_set("pnvramaddr", (char *)buf);
> +	env_set(ctx_uboot, "pnvramaddr", (char *)buf);
>  
>  	/* try to read rootfssize (ram image) from environment */
> -	p = env_get("rootfssize");
> +	p = env_get(ctx_uboot, "rootfssize");
>  	if (p != NULL)
>  		strict_strtoul(p, 16, &rootfssize);
>  	pram = (rootfssize + CONFIG_KM_RESERVED_PRAM +
> CONFIG_KM_PHRAM + CONFIG_KM_PNVRAM) / 0x400;
>  	sprintf((char *)buf, "0x%x", pram);
> -	env_set("pram", (char *)buf);
> +	env_set(ctx_uboot, "pram", (char *)buf);
>  
>  	varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM -
> CONFIG_KM_PHRAM; sprintf((char *)buf, "0x%x", varaddr);
> -	env_set("varaddr", (char *)buf);
> +	env_set(ctx_uboot, "varaddr", (char *)buf);
>  
>  	kernelmem = gd->ram_size - 0x400 * pram;
>  	sprintf((char *)buf, "0x%x", kernelmem);
> -	env_set("kernelmem", (char *)buf);
> +	env_set(ctx_uboot, "kernelmem", (char *)buf);
>  
>  	return 0;
>  }
> @@ -169,7 +169,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int
> flag, int argc, return 1;
>  	}
>  	strcpy((char *)buf, p);
> -	env_set("boardid", (char *)buf);
> +	env_set(ctx_uboot, "boardid", (char *)buf);
>  	printf("set boardid=%s\n", buf);
>  
>  	p = get_local_var("IVM_HWKey");
> @@ -178,7 +178,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int
> flag, int argc, return 1;
>  	}
>  	strcpy((char *)buf, p);
> -	env_set("hwkey", (char *)buf);
> +	env_set(ctx_uboot, "hwkey", (char *)buf);
>  	printf("set hwkey=%s\n", buf);
>  	printf("Execute manually saveenv for persistent storage.\n");
>  
> @@ -236,10 +236,10 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> int flag, int argc, }
>  
>  	/* now try to read values from environment if available */
> -	p = env_get("boardid");
> +	p = env_get(ctx_uboot, "boardid");
>  	if (p != NULL)
>  		rc = strict_strtoul(p, 16, &envbid);
> -	p = env_get("hwkey");
> +	p = env_get(ctx_uboot, "hwkey");
>  	if (p != NULL)
>  		rc = strict_strtoul(p, 16, &envhwkey);
>  
> @@ -253,7 +253,7 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> int flag, int argc,
>  		 * BoardId/HWkey not available in the environment,
> so try the
>  		 * environment variable for BoardId/HWkey list
>  		 */
> -		char *bidhwklist = env_get("boardIdListHex");
> +		char *bidhwklist = env_get(ctx_uboot,
> "boardIdListHex"); 
>  		if (bidhwklist) {
>  			int found = 0;
> @@ -311,9 +311,9 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> int flag, int argc, envbid   = bid;
>  					envhwkey = hwkey;
>  					sprintf(buf, "%lx", bid);
> -					env_set("boardid", buf);
> +					env_set(ctx_uboot,
> "boardid", buf); sprintf(buf, "%lx", hwkey);
> -					env_set("hwkey", buf);
> +					env_set(ctx_uboot, "hwkey",
> buf); }
>  			} /* end while( ! found ) */
>  		}
> @@ -355,7 +355,7 @@ static int do_checktestboot(cmd_tbl_t *cmdtp, int
> flag, int argc, #if defined(CONFIG_POST)
>  	testpin = post_hotkeys_pressed();
>  #endif
> -	s = env_get("test_bank");
> +	s = env_get(ctx_uboot, "test_bank");
>  	/* when test_bank is not set, act as if testpin is not
> asserted */ testboot = (testpin != 0) && (s);
>  	if (verbose) {
> diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c
> index 50df44d1c110..d255a34ae677 100644
> --- a/board/keymile/common/ivm.c
> +++ b/board/keymile/common/ivm.c
> @@ -261,7 +261,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int
> len) 
>  	GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8)
>  	GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64)
> -	tmp = (unsigned char *)env_get("IVM_DeviceName");
> +	tmp = (unsigned char *)env_get(ctx_uboot, "IVM_DeviceName");
>  	if (tmp) {
>  		int	len = strlen((char *)tmp);
>  		int	i = 0;
> @@ -310,16 +310,16 @@ static int ivm_populate_env(unsigned char *buf,
> int len) #ifndef CONFIG_KMTEGR1
>  	/* if an offset is defined, add it */
>  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> true);
> -	env_set((char *)"ethaddr", (char *)valbuf);
> +	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
>  #else
>  /* KMTEGR1 has a special setup. eth0 has no connection to the
> outside and
>   * gets an locally administred MAC address, eth1 is the debug
> interface and
>   * gets the official MAC address from the IVM
>   */
>  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> false);
> -	env_set((char *)"ethaddr", (char *)valbuf);
> +	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
>  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> true);
> -	env_set((char *)"eth1addr", (char *)valbuf);
> +	env_set(ctx_uboot, (char *)"eth1addr", (char *)valbuf);
>  #endif
>  
>  	return 0;
> diff --git a/board/keymile/km83xx/km83xx.c
> b/board/keymile/km83xx/km83xx.c index 8846b64f7d79..68a1ddb886b9
> 100644 --- a/board/keymile/km83xx/km83xx.c
> +++ b/board/keymile/km83xx/km83xx.c
> @@ -199,7 +199,7 @@ int last_stage_init(void)
>  	if (dip_switch != 0) {
>  		/* start bootloader */
>  		puts("DIP:   Enabled\n");
> -		env_set("actual_bank", "0");
> +		env_set(ctx_uboot, "actual_bank", "0");
>  	}
>  #endif
>  	set_km_env();
> diff --git a/board/keymile/km_arm/km_arm.c
> b/board/keymile/km_arm/km_arm.c index 922cc621f780..0c2ede5231bb
> 100644 --- a/board/keymile/km_arm/km_arm.c
> +++ b/board/keymile/km_arm/km_arm.c
> @@ -193,7 +193,7 @@ static void set_bootcount_addr(void)
>  	unsigned int bootcountaddr;
>  	bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
>  	sprintf((char *)buf, "0x%x", bootcountaddr);
> -	env_set("bootcountaddr", (char *)buf);
> +	env_set(ctx_uboot, "bootcountaddr", (char *)buf);
>  }
>  
>  int misc_init_r(void)
> @@ -201,7 +201,7 @@ int misc_init_r(void)
>  #if defined(CONFIG_KM_MGCOGE3UN)
>  	char *wait_for_ne;
>  	u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
> -	wait_for_ne = env_get("waitforne");
> +	wait_for_ne = env_get(ctx_uboot, "waitforne");
>  
>  	if ((wait_for_ne != NULL) && (dip_switch == 0)) {
>  		if (strcmp(wait_for_ne, "true") == 0) {
> @@ -299,7 +299,7 @@ int board_late_init(void)
>  	if (dip_switch != 0) {
>  		/* start bootloader */
>  		puts("DIP:   Enabled\n");
> -		env_set("actual_bank", "0");
> +		env_set(ctx_uboot, "actual_bank", "0");
>  	}
>  #endif
>  
> diff --git a/board/keymile/kmp204x/kmp204x.c
> b/board/keymile/kmp204x/kmp204x.c index 4d1e38aa3a7a..f4901f6bed9d
> 100644 --- a/board/keymile/kmp204x/kmp204x.c
> +++ b/board/keymile/kmp204x/kmp204x.c
> @@ -220,7 +220,7 @@ int last_stage_init(void)
>  	if (dip_switch != 0) {
>  		/* start bootloader */
>  		puts("DIP:   Enabled\n");
> -		env_set("actual_bank", "0");
> +		env_set(ctx_uboot, "actual_bank", "0");
>  	}
>  #endif
>  	set_km_env();
> @@ -237,7 +237,7 @@ void fdt_fixup_fman_mac_addresses(void *blob)
>  	unsigned char mac_addr[6];
>  
>  	/* get the mac addr from env */
> -	tmp = env_get("ethaddr");
> +	tmp = env_get(ctx_uboot, "ethaddr");
>  	if (!tmp) {
>  		printf("ethaddr env variable not defined\n");
>  		return;
> diff --git a/board/kosagi/novena/novena.c
> b/board/kosagi/novena/novena.c index b7b747d19658..968d455b45c6 100644
> --- a/board/kosagi/novena/novena.c
> +++ b/board/kosagi/novena/novena.c
> @@ -201,7 +201,7 @@ int misc_init_r(void)
>  	int ret;
>  
>  	/* If 'ethaddr' is already set, do nothing. */
> -	if (env_get("ethaddr"))
> +	if (env_get(ctx_uboot, "ethaddr"))
>  		return 0;
>  
>  	/* EEPROM is at bus 2. */
> diff --git a/board/laird/wb50n/wb50n.c b/board/laird/wb50n/wb50n.c
> index a2f8eaf0ba34..cc7cd3cf7250 100644
> --- a/board/laird/wb50n/wb50n.c
> +++ b/board/laird/wb50n/wb50n.c
> @@ -122,7 +122,7 @@ int board_late_init(void)
>  	for (p = name; *p != '\0'; *p = tolower(*p), p++)
>  		;
>  	strcat(name, "-wb50n");
> -	env_set(LAIRD_NAME, name);
> +	env_set(ctx_uboot, LAIRD_NAME, name);
>  
>  #endif
>  
> diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c
> index b4205d6ed4c1..0dff96ef02aa 100644
> --- a/board/lg/sniper/sniper.c
> +++ b/board/lg/sniper/sniper.c
> @@ -133,8 +133,8 @@ int misc_init_r(void)
>  	}
>  
>  	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
> -		if (!env_get("reboot-mode"))
> -			env_set("reboot-mode", (char *)reboot_mode);
> +		if (!env_get(ctx_uboot, "reboot-mode"))
> +			env_set(ctx_uboot, "reboot-mode", (char
> *)reboot_mode); }
>  
>  	omap_reboot_mode_clear();
> diff --git a/board/liebherr/display5/spl.c
> b/board/liebherr/display5/spl.c index 354b63e431f6..6ce1554e044d
> 100644 --- a/board/liebherr/display5/spl.c
> +++ b/board/liebherr/display5/spl.c
> @@ -284,10 +284,10 @@ void board_boot_order(u32 *spl_boot_list)
>  	/* 'fastboot' */
>  	const char *s;
>  
> -	if (env_init() || env_load())
> +	if (env_init() || env_load(ctx_uboot))
>  		return;
>  
> -	s = env_get("BOOT_FROM");
> +	s = env_get(ctx_uboot, "BOOT_FROM");
>  	if (s && !bootcount_error() && strcmp(s, "ACTIVE") == 0) {
>  		spl_boot_list[0] = BOOT_DEVICE_MMC1;
>  		spl_boot_list[1] = spl_boot_device();
> diff --git a/board/liebherr/mccmon6/mccmon6.c
> b/board/liebherr/mccmon6/mccmon6.c index 7d2751ab0393..6164317e607c
> 100644 --- a/board/liebherr/mccmon6/mccmon6.c
> +++ b/board/liebherr/mccmon6/mccmon6.c
> @@ -367,7 +367,7 @@ int board_init(void)
>  
>  int board_late_init(void)
>  {
> -	env_set("board_name", "mccmon6");
> +	env_set(ctx_uboot, "board_name", "mccmon6");
>  
>  	return 0;
>  }
> @@ -467,7 +467,7 @@ int spl_start_uboot(void)
>  		return 1;
>  
>  	env_init();
> -	ret = env_get_f("boot_os", s, sizeof(s));
> +	ret = env_get_f("boot_os", s, sizeof(ctx_uboot, s));
>  	if ((ret != -1) && (strcmp(s, "no") == 0))
>  		return 1;
>  
> @@ -481,7 +481,7 @@ int spl_start_uboot(void)
>  	 * recovery_status = <any value> -> start SWUpdate
>  	 *
>  	 */
> -	ret = env_get_f("recovery_status", s, sizeof(s));
> +	ret = env_get_f("recovery_status", s, sizeof(ctx_uboot, s));
>  	if (ret != -1)
>  		return 1;
>  
> diff --git a/board/logicpd/imx6/imx6logic.c
> b/board/logicpd/imx6/imx6logic.c index 7a59b89d94a2..204a92761459
> 100644 --- a/board/logicpd/imx6/imx6logic.c
> +++ b/board/logicpd/imx6/imx6logic.c
> @@ -149,12 +149,12 @@ int board_init(void)
>  
>  int board_late_init(void)
>  {
> -	env_set("board_name", "imx6logic");
> +	env_set(ctx_uboot, "board_name", "imx6logic");
>  
>  	if (is_mx6dq()) {
> -		env_set("board_rev", "MX6DQ");
> -		if (!env_get("fdt_file"))
> -			env_set("fdt_file", "imx6q-logicpd.dtb");
> +		env_set(ctx_uboot, "board_rev", "MX6DQ");
> +		if (!env_get(ctx_uboot, "fdt_file"))
> +			env_set(ctx_uboot, "fdt_file",
> "imx6q-logicpd.dtb"); }
>  
>  	return 0;
> diff --git a/board/menlo/m53menlo/m53menlo.c
> b/board/menlo/m53menlo/m53menlo.c index bda5f0df5bce..f84e0f7d5928
> 100644 --- a/board/menlo/m53menlo/m53menlo.c
> +++ b/board/menlo/m53menlo/m53menlo.c
> @@ -339,7 +339,7 @@ int board_late_init(void)
>  
>  	splash_get_pos(&xpos, &ypos);
>  
> -	s = env_get("splashimage");
> +	s = env_get(ctx_uboot, "splashimage");
>  	if (!s)
>  		return 0;
>  
> diff --git a/board/micronas/vct/vct.c b/board/micronas/vct/vct.c
> index e73d16db3eaf..6ae3dceaef87 100644
> --- a/board/micronas/vct/vct.c
> +++ b/board/micronas/vct/vct.c
> @@ -72,7 +72,7 @@ int dram_init(void)
>  int checkboard(void)
>  {
>  	char buf[64];
> -	int i = env_get_f("serial#", buf, sizeof(buf));
> +	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
>  	u32 config0 = read_c0_prid();
>  
>  	if ((config0 & 0xff0000) == PRID_COMP_LEGACY
> diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
> index 71ca79deab7f..ca486eab1e29 100644
> --- a/board/nokia/rx51/rx51.c
> +++ b/board/nokia/rx51/rx51.c
> @@ -234,18 +234,18 @@ void setup_board_tags(struct tag **in_params)
>  	params->u.core.rootdev = 0x0;
>  
>  	/* append omap atag only if env setup_omap_atag is set to 1
> */
> -	str = env_get("setup_omap_atag");
> +	str = env_get(ctx_uboot, "setup_omap_atag");
>  	if (!str || str[0] != '1')
>  		return;
>  
> -	str = env_get("setup_console_atag");
> +	str = env_get(ctx_uboot, "setup_console_atag");
>  	if (str && str[0] == '1')
>  		setup_console_atag = 1;
>  	else
>  		setup_console_atag = 0;
>  
> -	setup_boot_reason_atag = env_get("setup_boot_reason_atag");
> -	setup_boot_mode_atag = env_get("setup_boot_mode_atag");
> +	setup_boot_reason_atag = env_get(ctx_uboot,
> "setup_boot_reason_atag");
> +	setup_boot_mode_atag = env_get(ctx_uboot,
> "setup_boot_mode_atag"); 
>  	params = *in_params;
>  	t = (struct tag_omap *)&params->u;
> @@ -413,7 +413,7 @@ int misc_init_r(void)
>  
>  	/* set env variable attkernaddr for relocated kernel */
>  	sprintf(buf, "%#x", KERNEL_ADDRESS);
> -	env_set("attkernaddr", buf);
> +	env_set(ctx_uboot, "attkernaddr", buf);
>  
>  	/* initialize omap tags */
>  	init_omap_tags();
> diff --git a/board/overo/overo.c b/board/overo/overo.c
> index 442028a764c7..f0b230eabb13 100644
> --- a/board/overo/overo.c
> +++ b/board/overo/overo.c
> @@ -170,47 +170,47 @@ int misc_init_r(void)
>  			expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "dvi");
> -		env_set("expansionname", "summit");
> +		env_set(ctx_uboot, "defaultdisplay", "dvi");
> +		env_set(ctx_uboot, "expansionname", "summit");
>  		break;
>  	case GUMSTIX_TOBI:
>  		printf("Recognized Tobi expansion board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "dvi");
> -		env_set("expansionname", "tobi");
> +		env_set(ctx_uboot, "defaultdisplay", "dvi");
> +		env_set(ctx_uboot, "expansionname", "tobi");
>  		break;
>  	case GUMSTIX_TOBI_DUO:
>  		printf("Recognized Tobi Duo expansion board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("expansionname", "tobiduo");
> +		env_set(ctx_uboot, "expansionname", "tobiduo");
>  		break;
>  	case GUMSTIX_PALO35:
>  		printf("Recognized Palo35 expansion board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "lcd35");
> -		env_set("expansionname", "palo35");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd35");
> +		env_set(ctx_uboot, "expansionname", "palo35");
>  		break;
>  	case GUMSTIX_PALO43:
>  		printf("Recognized Palo43 expansion board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "lcd43");
> -		env_set("expansionname", "palo43");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> +		env_set(ctx_uboot, "expansionname", "palo43");
>  		break;
>  	case GUMSTIX_CHESTNUT43:
>  		printf("Recognized Chestnut43 expansion board (rev
> %d %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "lcd43");
> -		env_set("expansionname", "chestnut43");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> +		env_set(ctx_uboot, "expansionname", "chestnut43");
>  		break;
>  	case GUMSTIX_PINTO:
>  		printf("Recognized Pinto expansion board (rev %d
> %s)\n", @@ -223,8 +223,8 @@ int misc_init_r(void)
>  			expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
> -		env_set("defaultdisplay", "lcd43");
> -		env_set("expansionname", "gallop43");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> +		env_set(ctx_uboot, "expansionname", "gallop43");
>  		break;
>  	case GUMSTIX_ALTO35:
>  		printf("Recognized Alto35 expansion board (rev %d
> %s)\n", @@ -232,8 +232,8 @@ int misc_init_r(void)
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
>  		MUX_ALTO35();
> -		env_set("defaultdisplay", "lcd35");
> -		env_set("expansionname", "alto35");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd35");
> +		env_set(ctx_uboot, "expansionname", "alto35");
>  		break;
>  	case GUMSTIX_STAGECOACH:
>  		printf("Recognized Stagecoach expansion board (rev
> %d %s)\n", @@ -259,8 +259,8 @@ int misc_init_r(void)
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
>  		MUX_ARBOR43C();
> -		env_set("defaultdisplay", "lcd43");
> -		env_set("expansionname", "arbor43c");
> +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> +		env_set(ctx_uboot, "expansionname", "arbor43c");
>  		break;
>  	case ETTUS_USRP_E:
>  		printf("Recognized Ettus Research USRP-E (rev %d
> %s)\n", @@ -268,13 +268,13 @@ int misc_init_r(void)
>  			expansion_config.fab_revision);
>  		MUX_GUMSTIX();
>  		MUX_USRP_E();
> -		env_set("defaultdisplay", "dvi");
> +		env_set(ctx_uboot, "defaultdisplay", "dvi");
>  		break;
>  	case GUMSTIX_NO_EEPROM:
>  	case GUMSTIX_EMPTY_EEPROM:
>  		puts("No or empty EEPROM on expansion board\n");
>  		MUX_GUMSTIX();
> -		env_set("expansionname", "tobi");
> +		env_set(ctx_uboot, "expansionname", "tobi");
>  		break;
>  	default:
>  		printf("Unrecognized expansion board 0x%08x\n",
> expansion_id); @@ -282,14 +282,15 @@ int misc_init_r(void)
>  	}
>  
>  	if (expansion_config.content == 1)
> -		env_set(expansion_config.env_var,
> expansion_config.env_setting);
> +		env_set(ctx_uboot, expansion_config.env_var,
> +			expansion_config.env_setting);
>  
>  	omap_die_id_display();
>  
>  	if (get_cpu_family() == CPU_OMAP34XX)
> -		env_set("boardname", "overo");
> +		env_set(ctx_uboot, "boardname", "overo");
>  	else
> -		env_set("boardname", "overo-storm");
> +		env_set(ctx_uboot, "boardname", "overo-storm");
>  
>  	return 0;
>  }
> diff --git a/board/phytec/pcm052/pcm052.c
> b/board/phytec/pcm052/pcm052.c index e1ebe8e75d00..f66bacfb2172 100644
> --- a/board/phytec/pcm052/pcm052.c
> +++ b/board/phytec/pcm052/pcm052.c
> @@ -376,8 +376,8 @@ int board_late_init(void)
>  	if ((reg & SRC_SBMR1_BOOTCFG1_SDMMC) &&
>  	    !(reg & SRC_SBMR1_BOOTCFG1_MMC)) {
>  		printf("------ SD card boot -------\n");
> -		env_set_default("!LVFBootloader", 0);
> -		env_set("bootcmd",
> +		env_set_default(ctx_uboot, "!LVFBootloader", 0);
> +		env_set(ctx_uboot, "bootcmd",
>  			"run prepare_install_bk4r1_envs; run
> install_bk4r1rs"); }
>  
> diff --git a/board/phytec/pfla02/pfla02.c
> b/board/phytec/pfla02/pfla02.c index ae9ffe0390c3..bbcd8cf934d3 100644
> --- a/board/phytec/pfla02/pfla02.c
> +++ b/board/phytec/pfla02/pfla02.c
> @@ -392,7 +392,7 @@ int board_late_init(void)
>  #endif
>  
>  	snprintf(buf, sizeof(buf), "%d", get_board_rev());
> -	env_set("board_rev", buf);
> +	env_set(ctx_uboot, "board_rev", buf);
>  
>  	return 0;
>  }
> diff --git a/board/qualcomm/dragonboard410c/dragonboard410c.c
> b/board/qualcomm/dragonboard410c/dragonboard410c.c index
> d7f0f93fb109..bdf6e13ad06f 100644 ---
> a/board/qualcomm/dragonboard410c/dragonboard410c.c +++
> b/board/qualcomm/dragonboard410c/dragonboard410c.c @@ -139,8 +139,8
> @@ int misc_init_r(void) }
>  
>  	if (dm_gpio_get_value(&resin)) {
> -		env_set("bootdelay", "-1");
> -		env_set("bootcmd", "fastboot 0");
> +		env_set(ctx_uboot, "bootdelay", "-1");
> +		env_set(ctx_uboot, "bootcmd", "fastboot 0");
>  		printf("key_vol_down pressed - Starting
> fastboot.\n"); }
>  
> @@ -158,7 +158,7 @@ int board_late_init(void)
>  
>  	memset(serial, 0, 16);
>  	snprintf(serial, 13, "%x", msm_board_serial());
> -	env_set("serial#", serial);
> +	env_set(ctx_uboot, "serial#", serial);
>  	return 0;
>  }
>  
> diff --git a/board/qualcomm/dragonboard820c/dragonboard820c.c
> b/board/qualcomm/dragonboard820c/dragonboard820c.c index
> 7a889646df8d..475e1aa64560 100644 ---
> a/board/qualcomm/dragonboard820c/dragonboard820c.c +++
> b/board/qualcomm/dragonboard820c/dragonboard820c.c @@ -155,7 +155,7
> @@ int misc_init_r(void) }
>  
>  	if (dm_gpio_get_value(&resin)) {
> -		env_set("bootdelay", "-1");
> +		env_set(ctx_uboot, "bootdelay", "-1");
>  		printf("Power button pressed - dropping to
> console.\n"); }
>  
> diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
> index 7a6ca8f759e6..5d4d59fd25ca 100644
> --- a/board/raspberrypi/rpi/rpi.c
> +++ b/board/raspberrypi/rpi/rpi.c
> @@ -290,11 +290,11 @@ static void set_fdtfile(void)
>  {
>  	const char *fdtfile;
>  
> -	if (env_get("fdtfile"))
> +	if (env_get(ctx_uboot, "fdtfile"))
>  		return;
>  
>  	fdtfile = model->fdtfile;
> -	env_set("fdtfile", fdtfile);
> +	env_set(ctx_uboot, "fdtfile", fdtfile);
>  }
>  
>  /*
> @@ -303,13 +303,13 @@ static void set_fdtfile(void)
>   */
>  static void set_fdt_addr(void)
>  {
> -	if (env_get("fdt_addr"))
> +	if (env_get(ctx_uboot, "fdt_addr"))
>  		return;
>  
>  	if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
>  		return;
>  
> -	env_set_hex("fdt_addr", fw_dtb_pointer);
> +	env_set_hex(ctx_uboot, "fdt_addr", fw_dtb_pointer);
>  }
>  
>  /*
> @@ -330,7 +330,7 @@ static void set_usbethaddr(void)
>  	if (!model->has_onboard_eth)
>  		return;
>  
> -	if (env_get("usbethaddr"))
> +	if (env_get(ctx_uboot, "usbethaddr"))
>  		return;
>  
>  	BCM2835_MBOX_INIT_HDR(msg);
> @@ -345,8 +345,8 @@ static void set_usbethaddr(void)
>  
>  	eth_env_set_enetaddr("usbethaddr",
> msg->get_mac_address.body.resp.mac); 
> -	if (!env_get("ethaddr"))
> -		env_set("ethaddr", env_get("usbethaddr"));
> +	if (!env_get(ctx_uboot, "ethaddr"))
> +		env_set(ctx_uboot, "ethaddr", env_get("usbethaddr"));
>  
>  	return;
>  }
> @@ -357,13 +357,13 @@ static void set_board_info(void)
>  	char s[11];
>  
>  	snprintf(s, sizeof(s), "0x%X", revision);
> -	env_set("board_revision", s);
> +	env_set(ctx_uboot, "board_revision", s);
>  	snprintf(s, sizeof(s), "%d", rev_scheme);
> -	env_set("board_rev_scheme", s);
> +	env_set(ctx_uboot, "board_rev_scheme", s);
>  	/* Can't rename this to board_rev_type since it's an ABI for
> scripts */ snprintf(s, sizeof(s), "0x%X", rev_type);
> -	env_set("board_rev", s);
> -	env_set("board_name", model->name);
> +	env_set(ctx_uboot, "board_rev", s);
> +	env_set(ctx_uboot, "board_name", model->name);
>  }
>  #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
>  
> @@ -373,7 +373,7 @@ static void set_serial_number(void)
>  	int ret;
>  	char serial_string[17] = { 0 };
>  
> -	if (env_get("serial#"))
> +	if (env_get(ctx_uboot, "serial#"))
>  		return;
>  
>  	BCM2835_MBOX_INIT_HDR(msg);
> @@ -388,7 +388,7 @@ static void set_serial_number(void)
>  
>  	snprintf(serial_string, sizeof(serial_string), "%016llx",
>  		 msg->get_board_serial.body.resp.serial);
> -	env_set("serial#", serial_string);
> +	env_set(ctx_uboot, "serial#", serial_string);
>  }
>  
>  int misc_init_r(void)
> diff --git a/board/renesas/alt/alt.c b/board/renesas/alt/alt.c
> index 10ef7f931b1f..bc94a22e9603 100644
> --- a/board/renesas/alt/alt.c
> +++ b/board/renesas/alt/alt.c
> @@ -128,7 +128,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/gose/gose.c b/board/renesas/gose/gose.c
> index f86c9f1a6350..d3ec352e2a03 100644
> --- a/board/renesas/gose/gose.c
> +++ b/board/renesas/gose/gose.c
> @@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/koelsch/koelsch.c
> b/board/renesas/koelsch/koelsch.c index 841d337f4d3c..871308e405d3
> 100644 --- a/board/renesas/koelsch/koelsch.c
> +++ b/board/renesas/koelsch/koelsch.c
> @@ -136,7 +136,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/lager/lager.c b/board/renesas/lager/lager.c
> index 3cb1a56142a9..6867ae5c4008 100644
> --- a/board/renesas/lager/lager.c
> +++ b/board/renesas/lager/lager.c
> @@ -145,7 +145,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/porter/porter.c
> b/board/renesas/porter/porter.c index 86f79da7fdb4..3dc9310e0fc4
> 100644 --- a/board/renesas/porter/porter.c
> +++ b/board/renesas/porter/porter.c
> @@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/sh7752evb/sh7752evb.c
> b/board/renesas/sh7752evb/sh7752evb.c index
> d0b850f35d49..540ec9bfd019 100644 ---
> a/board/renesas/sh7752evb/sh7752evb.c +++
> b/board/renesas/sh7752evb/sh7752evb.c @@ -223,10 +223,10 @@ static
> void init_ethernet_mac(void) for (i = 0; i <
> SH7752EVB_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
>  		if (i == 0)
> -			env_set("ethaddr", mac_string);
> +			env_set(ctx_uboot, "ethaddr", mac_string);
>  		else {
>  			sprintf(env_string, "eth%daddr", i);
> -			env_set(env_string, mac_string);
> +			env_set(ctx_uboot, env_string, mac_string);
>  		}
>  		set_mac_to_sh_giga_eth_register(i, mac_string);
>  	}
> diff --git a/board/renesas/sh7753evb/sh7753evb.c
> b/board/renesas/sh7753evb/sh7753evb.c index
> e1bed7dcc371..3ec2591cb7ed 100644 ---
> a/board/renesas/sh7753evb/sh7753evb.c +++
> b/board/renesas/sh7753evb/sh7753evb.c @@ -239,10 +239,10 @@ static
> void init_ethernet_mac(void) for (i = 0; i <
> SH7753EVB_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
>  		if (i == 0)
> -			env_set("ethaddr", mac_string);
> +			env_set(ctx_uboot, "ethaddr", mac_string);
>  		else {
>  			sprintf(env_string, "eth%daddr", i);
> -			env_set(env_string, mac_string);
> +			env_set(ctx_uboot, env_string, mac_string);
>  		}
>  		set_mac_to_sh_giga_eth_register(i, mac_string);
>  	}
> diff --git a/board/renesas/sh7757lcr/sh7757lcr.c
> b/board/renesas/sh7757lcr/sh7757lcr.c index
> d2671202e981..4b06387d5f22 100644 ---
> a/board/renesas/sh7757lcr/sh7757lcr.c +++
> b/board/renesas/sh7757lcr/sh7757lcr.c @@ -285,10 +285,10 @@ static
> void init_ethernet_mac(void) for (i = 0; i <
> SH7757LCR_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
>  		if (i == 0)
> -			env_set("ethaddr", mac_string);
> +			env_set(ctx_uboot, "ethaddr", mac_string);
>  		else {
>  			sprintf(env_string, "eth%daddr", i);
> -			env_set(env_string, mac_string);
> +			env_set(ctx_uboot, env_string, mac_string);
>  		}
>  
>  		set_mac_to_sh_eth_register(i, mac_string);
> @@ -298,7 +298,7 @@ static void init_ethernet_mac(void)
>  	for (i = 0; i < SH7757LCR_GIGA_ETHERNET_NUM_CH; i++) {
>  		get_sh_eth_mac(i + SH7757LCR_ETHERNET_NUM_CH,
> mac_string, buf); sprintf(env_string, "eth%daddr", i +
> SH7757LCR_ETHERNET_NUM_CH);
> -		env_set(env_string, mac_string);
> +		env_set(ctx_uboot, env_string, mac_string);
>  
>  		set_mac_to_sh_giga_eth_register(i, mac_string);
>  	}
> diff --git a/board/renesas/silk/silk.c b/board/renesas/silk/silk.c
> index 25221e3c55cc..946232e3ba7b 100644
> --- a/board/renesas/silk/silk.c
> +++ b/board/renesas/silk/silk.c
> @@ -129,7 +129,8 @@ void reset_cpu(ulong addr)
>  		hang();
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/renesas/stout/stout.c b/board/renesas/stout/stout.c
> index 0a0ff5ff76d2..d0b20f3c5902 100644
> --- a/board/renesas/stout/stout.c
> +++ b/board/renesas/stout/stout.c
> @@ -125,7 +125,8 @@ int board_phy_config(struct phy_device *phydev)
>  	return 0;
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	const u32 load_magic = 0xb33fc0de;
>  
> diff --git a/board/rockchip/kylin_rk3036/kylin_rk3036.c
> b/board/rockchip/kylin_rk3036/kylin_rk3036.c index
> 2faeab9baf51..6481f6c11633 100644 ---
> a/board/rockchip/kylin_rk3036/kylin_rk3036.c +++
> b/board/rockchip/kylin_rk3036/kylin_rk3036.c @@ -41,7 +41,7 @@ int
> rk_board_late_init(void) {
>  	if (fastboot_key_pressed()) {
>  		printf("enter fastboot!\n");
> -		env_set("preboot", "setenv preboot; fastboot usb0");
> +		env_set(ctx_uboot, "preboot", "setenv preboot;
> fastboot usb0"); }
>  
>  	return 0;
> diff --git a/board/samsung/common/exynos5-dt.c
> b/board/samsung/common/exynos5-dt.c index 387d1b91809c..1c44effe7224
> 100644 --- a/board/samsung/common/exynos5-dt.c
> +++ b/board/samsung/common/exynos5-dt.c
> @@ -154,7 +154,7 @@ char *get_dfu_alt_system(char *interface, char
> *devstr) if (board_is_odroidxu4() || board_is_odroidhc1() ||
> board_is_odroidhc2()) return info;
>  
> -	return env_get("dfu_alt_system");
> +	return env_get(ctx_uboot, "dfu_alt_system");
>  }
>  
>  char *get_dfu_alt_boot(char *interface, char *devstr)
> diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
> index 3ef1e7998013..3086df745fe5 100644
> --- a/board/samsung/common/misc.c
> +++ b/board/samsung/common/misc.c
> @@ -51,7 +51,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
>  
>  	alt_setting = get_dfu_alt_boot(interface, devstr);
>  	if (alt_setting) {
> -		env_set("dfu_alt_boot", alt_setting);
> +		env_set(ctx_uboot, "dfu_alt_boot", alt_setting);
>  		offset = snprintf(buf, buf_size, "%s", alt_setting);
>  	}
>  
> @@ -71,7 +71,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
>  		status = "done\n";
>  	}
>  
> -	env_set("dfu_alt_info", alt_info);
> +	env_set(ctx_uboot, "dfu_alt_info", alt_info);
>  	puts(status);
>  }
>  #endif
> @@ -83,14 +83,14 @@ void set_board_info(void)
>  
>  	snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev &
> 0xf0) >> 4, s5p_cpu_rev & 0xf);
> -	env_set("soc_rev", info);
> +	env_set(ctx_uboot, "soc_rev", info);
>  
>  	snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
> -	env_set("soc_id", info);
> +	env_set(ctx_uboot, "soc_id", info);
>  
>  #ifdef CONFIG_REVISION_TAG
>  	snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
> -	env_set("board_rev", info);
> +	env_set(ctx_uboot, "board_rev", info);
>  #endif
>  #ifdef CONFIG_OF_LIBFDT
>  	const char *bdtype = "";
> @@ -102,11 +102,11 @@ void set_board_info(void)
>  		bdtype = "";
>  
>  	sprintf(info, "%s%s", bdname, bdtype);
> -	env_set("board_name", info);
> +	env_set(ctx_uboot, "board_name", info);
>  #endif
>  	snprintf(info, ARRAY_SIZE(info),  "%s%x-%s%s.dtb",
>  		 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
> -	env_set("fdtfile", info);
> +	env_set(ctx_uboot, "fdtfile", info);
>  #endif
>  }
>  #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
> diff --git a/board/samsung/odroid/odroid.c
> b/board/samsung/odroid/odroid.c index 9aa97f0f2cad..472dce81f680
> 100644 --- a/board/samsung/odroid/odroid.c
> +++ b/board/samsung/odroid/odroid.c
> @@ -74,7 +74,7 @@ const char *get_board_type(void)
>  #ifdef CONFIG_SET_DFU_ALT_INFO
>  char *get_dfu_alt_system(char *interface, char *devstr)
>  {
> -	return env_get("dfu_alt_system");
> +	return env_get(ctx_uboot, "dfu_alt_system");
>  }
>  
>  char *get_dfu_alt_boot(char *interface, char *devstr)
> diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
> index ec85f707c19a..d4540a2ac932 100644
> --- a/board/samsung/trats/trats.c
> +++ b/board/samsung/trats/trats.c
> @@ -467,7 +467,7 @@ void exynos_lcd_misc_init(vidinfo_t *vid)
>  #endif
>  #ifdef CONFIG_S6E8AX0
>  	s6e8ax0_init();
> -	env_set("lcdinfo", "lcd=s6e8ax0");
> +	env_set(ctx_uboot, "lcdinfo", "lcd=s6e8ax0");
>  #endif
>  }
>  #endif
> diff --git a/board/samsung/universal_c210/universal.c
> b/board/samsung/universal_c210/universal.c index
> ed9c5b50d927..9fea29e965bd 100644 ---
> a/board/samsung/universal_c210/universal.c +++
> b/board/samsung/universal_c210/universal.c @@ -397,6 +397,6 @@ void
> exynos_lcd_misc_init(vidinfo_t *vid) vid->pclk_name = 1;	/*
> MPLL */ vid->sclk_div = 1;
>  
> -	env_set("lcdinfo", "lcd=ld9040");
> +	env_set(ctx_uboot, "lcdinfo", "lcd=ld9040");
>  }
>  #endif
> diff --git a/board/samtec/vining_fpga/socfpga.c
> b/board/samtec/vining_fpga/socfpga.c index 1e095a4e7db0..75ddbcf07fa7
> 100644 --- a/board/samtec/vining_fpga/socfpga.c
> +++ b/board/samtec/vining_fpga/socfpga.c
> @@ -62,30 +62,30 @@ int misc_init_r(void)
>  	/* Check EEPROM signature. */
>  	if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
>  		puts("Invalid I2C EEPROM signature.\n");
> -		env_set("unit_serial", "invalid");
> -		env_set("unit_ident", "VINing-xxxx-STD");
> -		env_set("hostname", "vining-invalid");
> +		env_set(ctx_uboot, "unit_serial", "invalid");
> +		env_set(ctx_uboot, "unit_ident", "VINing-xxxx-STD");
> +		env_set(ctx_uboot, "hostname", "vining-invalid");
>  		return 0;
>  	}
>  
>  	/* If 'unit_serial' is already set, do nothing. */
> -	if (!env_get("unit_serial")) {
> +	if (!env_get(ctx_uboot, "unit_serial")) {
>  		/* This field is Big Endian ! */
>  		serial = (data[0x54] << 24) | (data[0x55] << 16) |
>  			 (data[0x56] << 8) | (data[0x57] << 0);
>  		memset(str, 0, sizeof(str));
>  		sprintf(str, "%07i", serial);
> -		env_set("unit_serial", str);
> +		env_set(ctx_uboot, "unit_serial", str);
>  	}
>  
> -	if (!env_get("unit_ident")) {
> +	if (!env_get(ctx_uboot, "unit_ident")) {
>  		memset(str, 0, sizeof(str));
>  		memcpy(str, &data[0x2e], 18);
> -		env_set("unit_ident", str);
> +		env_set(ctx_uboot, "unit_ident", str);
>  	}
>  
>  	/* Set ethernet address from EEPROM. */
> -	if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
> +	if (!env_get(ctx_uboot, "ethaddr") &&
> is_valid_ethaddr(&data[0x62])) eth_env_set_enetaddr("ethaddr",
> &data[0x62]); 
>  	return 0;
> diff --git a/board/siemens/common/board.c
> b/board/siemens/common/board.c index 676935a84321..63dcf2b83132 100644
> --- a/board/siemens/common/board.c
> +++ b/board/siemens/common/board.c
> @@ -121,7 +121,7 @@ unsigned char get_button_state(char * const
> envname, unsigned char def) char *ptr_env;
>  
>  	/* If button is not found we take default */
> -	ptr_env = env_get(envname);
> +	ptr_env = env_get(ctx_uboot, envname);
>  	if (NULL == ptr_env) {
>  		gpio = def;
>  	} else {
> @@ -199,7 +199,7 @@ void set_env_gpios(unsigned char state)
>  		strcat(str_tmp, num);
>  
>  		/* If env var is not found we stop */
> -		ptr_env = env_get(str_tmp);
> +		ptr_env = env_get(ctx_uboot, str_tmp);
>  		if (NULL == ptr_env)
>  			break;
>  
> diff --git a/board/siemens/draco/board.c b/board/siemens/draco/board.c
> index a6840b895b27..9cb1b1301855 100644
> --- a/board/siemens/draco/board.c
> +++ b/board/siemens/draco/board.c
> @@ -270,13 +270,13 @@ int board_late_init(void)
>  #ifdef CONFIG_FACTORYSET
>  	/* Set ASN in environment*/
>  	if (factory_dat.asn[0] != 0) {
> -		env_set("dtb_name", (char *)factory_dat.asn);
> +		env_set(ctx_uboot, "dtb_name", (char
> *)factory_dat.asn); } else {
>  		/* dtb suffix gets added in load script */
> -		env_set("dtb_name", "am335x-draco");
> +		env_set(ctx_uboot, "dtb_name", "am335x-draco");
>  	}
>  #else
> -	env_set("dtb_name", "am335x-draco");
> +	env_set(ctx_uboot, "dtb_name", "am335x-draco");
>  #endif
>  
>  	return 0;
> diff --git a/board/siemens/pxm2/board.c b/board/siemens/pxm2/board.c
> index 30f0902701ee..e57ab33da88b 100644
> --- a/board/siemens/pxm2/board.c
> +++ b/board/siemens/pxm2/board.c
> @@ -444,12 +444,12 @@ int board_late_init(void)
>  			factory_dat.pxm50 = 0;
>  		sprintf(tmp, "%s_%s", factory_dat.asn,
>  			factory_dat.comp_version);
> -		ret = env_set("boardid", tmp);
> +		ret = env_set(ctx_uboot, "boardid", tmp);
>  		if (ret)
>  			printf("error setting board id\n");
>  	} else {
>  		factory_dat.pxm50 = 1;
> -		ret = env_set("boardid", "PXM50_1.0");
> +		ret = env_set(ctx_uboot, "boardid", "PXM50_1.0");
>  		if (ret)
>  			printf("error setting board id\n");
>  	}
> diff --git a/board/siemens/rut/board.c b/board/siemens/rut/board.c
> index 539ecef22cb4..809cea42f86b 100644
> --- a/board/siemens/rut/board.c
> +++ b/board/siemens/rut/board.c
> @@ -480,7 +480,7 @@ int board_late_init(void)
>  	else
>  		strcpy(tmp, "QMX7.E38_4.0");
>  
> -	ret = env_set("boardid", tmp);
> +	ret = env_set(ctx_uboot, "boardid", tmp);
>  	if (ret)
>  		printf("error setting board id\n");
>  
> diff --git a/board/siemens/taurus/taurus.c
> b/board/siemens/taurus/taurus.c index 1cf1f9e1f7ca..980d773a77bb
> 100644 --- a/board/siemens/taurus/taurus.c
> +++ b/board/siemens/taurus/taurus.c
> @@ -350,36 +350,36 @@ static int upgrade_failure_fallback(void)
>  	char *kern_size;
>  	char *kern_size_fb;
>  
> -	partitionset_active = env_get("partitionset_active");
> +	partitionset_active = env_get(ctx_uboot,
> "partitionset_active"); if (partitionset_active) {
>  		if (partitionset_active[0] == 'A')
> -			env_set("partitionset_active", "B");
> +			env_set(ctx_uboot, "partitionset_active",
> "B"); else
> -			env_set("partitionset_active", "A");
> +			env_set(ctx_uboot, "partitionset_active",
> "A"); } else {
>  		printf("partitionset_active missing.\n");
>  		return -ENOENT;
>  	}
>  
> -	rootfs = env_get("rootfs");
> -	rootfs_fallback = env_get("rootfs_fallback");
> -	env_set("rootfs", rootfs_fallback);
> -	env_set("rootfs_fallback", rootfs);
> +	rootfs = env_get(ctx_uboot, "rootfs");
> +	rootfs_fallback = env_get(ctx_uboot, "rootfs_fallback");
> +	env_set(ctx_uboot, "rootfs", rootfs_fallback);
> +	env_set(ctx_uboot, "rootfs_fallback", rootfs);
>  
> -	kern_size = env_get("kernel_size");
> -	kern_size_fb = env_get("kernel_size_fallback");
> -	env_set("kernel_size", kern_size_fb);
> -	env_set("kernel_size_fallback", kern_size);
> +	kern_size = env_get(ctx_uboot, "kernel_size");
> +	kern_size_fb = env_get(ctx_uboot, "kernel_size_fallback");
> +	env_set(ctx_uboot, "kernel_size", kern_size_fb);
> +	env_set(ctx_uboot, "kernel_size_fallback", kern_size);
>  
> -	kern_off = env_get("kernel_Off");
> -	kern_off_fb = env_get("kernel_Off_fallback");
> -	env_set("kernel_Off", kern_off_fb);
> -	env_set("kernel_Off_fallback", kern_off);
> +	kern_off = env_get(ctx_uboot, "kernel_Off");
> +	kern_off_fb = env_get(ctx_uboot, "kernel_Off_fallback");
> +	env_set(ctx_uboot, "kernel_Off", kern_off_fb);
> +	env_set(ctx_uboot, "kernel_Off_fallback", kern_off);
>  
> -	env_set("bootargs", '\0');
> -	env_set("upgrade_available", '\0');
> -	env_set("boot_retries", '\0');
> -	env_save();
> +	env_set(ctx_uboot, "bootargs", '\0');
> +	env_set(ctx_uboot, "upgrade_available", '\0');
> +	env_set(ctx_uboot, "boot_retries", '\0');
> +	env_save(ctx_uboot);
>  
>  	return 0;
>  }
> @@ -391,14 +391,16 @@ static int do_upgrade_available(cmd_tbl_t
> *cmdtp, int flag, int argc, unsigned long boot_retry = 0;
>  	char boot_buf[10];
>  
> -	upgrade_available =
> simple_strtoul(env_get("upgrade_available"), NULL,
> -					   10);
> +	upgrade_available = simple_strtoul(env_get(ctx_uboot,
> +
> "upgrade_available"),
> +					   NULL, 10);
>  	if (upgrade_available) {
> -		boot_retry = simple_strtoul(env_get("boot_retries"),
> NULL, 10);
> +		boot_retry = simple_strtoul(env_get(ctx_uboot,
> "boot_retries"),
> +					    NULL, 10);
>  		boot_retry++;
>  		sprintf(boot_buf, "%lx", boot_retry);
> -		env_set("boot_retries", boot_buf);
> -		env_save();
> +		env_set(ctx_uboot, "boot_retries", boot_buf);
> +		env_save(ctx_uboot);
>  
>  		/*
>  		 * Here the boot_retries count is checked, and if the
> diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
> index da9ae5bebb7e..277f9e107080 100644
> --- a/board/socrates/socrates.c
> +++ b/board/socrates/socrates.c
> @@ -38,7 +38,7 @@ int checkboard (void)
>  	volatile ccsr_gur_t *gur = (void
> *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); char buf[64];
>  	int f;
> -	int i = env_get_f("serial#", buf, sizeof(buf));
> +	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
>  #ifdef CONFIG_PCI
>  	char *src;
>  #endif
> @@ -409,7 +409,7 @@ void board_backlight_switch (int flag)
>  		printf ("hwmon IC init failed\n");
>  
>  	if (flag) {
> -		param = env_get("brightness");
> +		param = env_get(ctx_uboot, "brightness");
>  		rc = param ? simple_strtol(param, NULL, 10) : -1;
>  		if (rc < 0)
>  			rc = DEFAULT_BRIGHTNESS;
> diff --git a/board/softing/vining_2000/vining_2000.c
> b/board/softing/vining_2000/vining_2000.c index
> 51985b91c226..5d4d0f29c44f 100644 ---
> a/board/softing/vining_2000/vining_2000.c +++
> b/board/softing/vining_2000/vining_2000.c @@ -102,7 +102,7 @@ int
> board_eth_init(bd_t *bis) 
>  	/* just to get secound mac address */
>  	imx_get_mac_from_fuse(1, eth1addr);
> -	if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
> +	if (!env_get(ctx_uboot, "eth1addr") &&
> is_valid_ethaddr(eth1addr)) eth_env_set_enetaddr("eth1addr",
> eth1addr); 
>  	imx_iomux_v3_setup_multiple_pads(fec1_pads,
> ARRAY_SIZE(fec1_pads)); @@ -385,11 +385,11 @@ static int
> set_pin_state(void) return ret;
>  
>  	if (val >= VAL_UPPER)
> -		env_set("pin_state", "connected");
> +		env_set(ctx_uboot, "pin_state", "connected");
>  	else if (val < VAL_UPPER && val > VAL_LOWER)
> -		env_set("pin_state", "open");
> +		env_set(ctx_uboot, "pin_state", "open");
>  	else
> -		env_set("pin_state", "button");
> +		env_set(ctx_uboot, "pin_state", "button");
>  
>  	return ret;
>  }
> diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c
> b/board/solidrun/mx6cuboxi/mx6cuboxi.c index
> f82fb0786a94..52177b918d83 100644 ---
> a/board/solidrun/mx6cuboxi/mx6cuboxi.c +++
> b/board/solidrun/mx6cuboxi/mx6cuboxi.c @@ -569,29 +569,29 @@ int
> board_late_init(void) #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	switch (board_type()) {
>  	case CUBOXI:
> -		env_set("board_name", "CUBOXI");
> +		env_set(ctx_uboot, "board_name", "CUBOXI");
>  		break;
>  	case HUMMINGBOARD:
> -		env_set("board_name", "HUMMINGBOARD");
> +		env_set(ctx_uboot, "board_name", "HUMMINGBOARD");
>  		break;
>  	case HUMMINGBOARD2:
> -		env_set("board_name", "HUMMINGBOARD2");
> +		env_set(ctx_uboot, "board_name", "HUMMINGBOARD2");
>  		break;
>  	case UNKNOWN:
>  	default:
> -		env_set("board_name", "CUBOXI");
> +		env_set(ctx_uboot, "board_name", "CUBOXI");
>  	}
>  
>  	if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  
>  	if (is_rev_15_som())
> -		env_set("som_rev", "V15");
> +		env_set(ctx_uboot, "som_rev", "V15");
>  
>  	if (has_emmc())
> -		env_set("has_emmc", "yes");
> +		env_set(ctx_uboot, "has_emmc", "yes");
>  
>  #endif
>  
> diff --git a/board/st/stm32f429-discovery/stm32f429-discovery.c
> b/board/st/stm32f429-discovery/stm32f429-discovery.c index
> 500dc5fe3a6b..3ae0c17d7720 100644 ---
> a/board/st/stm32f429-discovery/stm32f429-discovery.c +++
> b/board/st/stm32f429-discovery/stm32f429-discovery.c @@ -65,13 +65,13
> @@ int misc_init_r(void) char serialno[25];
>  	uint32_t u_id_low, u_id_mid, u_id_high;
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		u_id_low  = readl(&STM32_U_ID->u_id_low);
>  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
>  		u_id_high = readl(&STM32_U_ID->u_id_high);
>  		sprintf(serialno, "%08x%08x%08x",
>  			u_id_high, u_id_mid, u_id_low);
> -		env_set("serial#", serialno);
> +		env_set(ctx_uboot, "serial#", serialno);
>  	}
>  
>  	return 0;
> diff --git a/board/st/stm32f429-evaluation/stm32f429-evaluation.c
> b/board/st/stm32f429-evaluation/stm32f429-evaluation.c index
> 8ab2fa5d59ab..3a1c578cdad8 100644 ---
> a/board/st/stm32f429-evaluation/stm32f429-evaluation.c +++
> b/board/st/stm32f429-evaluation/stm32f429-evaluation.c @@ -59,13
> +59,13 @@ int misc_init_r(void) char serialno[25];
>  	u32 u_id_low, u_id_mid, u_id_high;
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		u_id_low  = readl(&STM32_U_ID->u_id_low);
>  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
>  		u_id_high = readl(&STM32_U_ID->u_id_high);
>  		sprintf(serialno, "%08x%08x%08x",
>  			u_id_high, u_id_mid, u_id_low);
> -		env_set("serial#", serialno);
> +		env_set(ctx_uboot, "serial#", serialno);
>  	}
>  
>  	return 0;
> diff --git a/board/st/stm32f469-discovery/stm32f469-discovery.c
> b/board/st/stm32f469-discovery/stm32f469-discovery.c index
> 70d23d90f4ca..e475296919e0 100644 ---
> a/board/st/stm32f469-discovery/stm32f469-discovery.c +++
> b/board/st/stm32f469-discovery/stm32f469-discovery.c @@ -59,13 +59,13
> @@ int misc_init_r(void) char serialno[25];
>  	u32 u_id_low, u_id_mid, u_id_high;
>  
> -	if (!env_get("serial#")) {
> +	if (!env_get(ctx_uboot, "serial#")) {
>  		u_id_low  = readl(&STM32_U_ID->u_id_low);
>  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
>  		u_id_high = readl(&STM32_U_ID->u_id_high);
>  		sprintf(serialno, "%08x%08x%08x",
>  			u_id_high, u_id_mid, u_id_low);
> -		env_set("serial#", serialno);
> +		env_set(ctx_uboot, "serial#", serialno);
>  	}
>  
>  	return 0;
> diff --git a/board/st/stm32mp1/stm32mp1.c
> b/board/st/stm32mp1/stm32mp1.c index 279c7b779799..188f4a7eae12 100644
> --- a/board/st/stm32mp1/stm32mp1.c
> +++ b/board/st/stm32mp1/stm32mp1.c
> @@ -544,9 +544,9 @@ int board_late_init(void)
>  				 &fdt_compat_len);
>  	if (fdt_compat && fdt_compat_len) {
>  		if (strncmp(fdt_compat, "st,", 3) != 0)
> -			env_set("board_name", fdt_compat);
> +			env_set(ctx_uboot, "board_name", fdt_compat);
>  		else
> -			env_set("board_name", fdt_compat + 3);
> +			env_set(ctx_uboot, "board_name", fdt_compat
> + 3); }
>  #endif
>  
> @@ -623,7 +623,8 @@ int board_interface_eth_init(phy_interface_t
> interface_type, return 0;
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	u32 bootmode = get_bootmode();
>  
> @@ -688,8 +689,8 @@ const char *env_ext4_get_dev_part(void)
>  static const char *env_get_mtdparts(const char *str, char *buf)
>  {
>  	if (gd->flags & GD_FLG_ENV_READY)
> -		return env_get(str);
> -	if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
> +		return env_get(ctx_uboot, str);
> +	if (env_get_f(ctx_uboot, str, buf, MTDPARTS_LEN) != -1)
>  		return buf;
>  
>  	return NULL;
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index e3b2d13892c8..d5f172eb8082 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -194,7 +194,8 @@ void i2c_init_board(void)
>  }
>  
>  #if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
> -enum env_location env_get_location(enum env_operation op, int prio)
> +enum env_location env_get_location(struct env_context *ctx,
> +				   enum env_operation op, int prio)
>  {
>  	switch (prio) {
>  	case 0:
> @@ -725,7 +726,7 @@ void get_board_serial(struct tag_serialnr
> *serialnr) char *serial_string;
>  	unsigned long long serial;
>  
> -	serial_string = env_get("serial#");
> +	serial_string = env_get(ctx_uboot, "serial#");
>  
>  	if (serial_string) {
>  		serial = simple_strtoull(serial_string, NULL, 16);
> @@ -764,7 +765,7 @@ static void parse_spl_header(const uint32_t
> spl_addr) return;
>  	}
>  	/* otherwise assume .scr format (mkimage-type script) */
> -	env_set_hex("fel_scriptaddr", spl->fel_script_address);
> +	env_set_hex(ctx_uboot, "fel_scriptaddr",
> spl->fel_script_address); }
>  
>  /*
> @@ -812,7 +813,7 @@ static void setup_environment(const void *fdt)
>  			else
>  				sprintf(ethaddr, "eth%daddr", i);
>  
> -			if (env_get(ethaddr))
> +			if (env_get(ctx_uboot, ethaddr))
>  				continue;
>  
>  			/* Non OUI / registered MAC address */
> @@ -826,11 +827,11 @@ static void setup_environment(const void *fdt)
>  			eth_env_set_enetaddr(ethaddr, mac_addr);
>  		}
>  
> -		if (!env_get("serial#")) {
> +		if (!env_get(ctx_uboot, "serial#")) {
>  			snprintf(serial_string,
> sizeof(serial_string), "%08x%08x", sid[0], sid[3]);
>  
> -			env_set("serial#", serial_string);
> +			env_set(ctx_uboot, "serial#", serial_string);
>  		}
>  	}
>  }
> @@ -839,20 +840,20 @@ int misc_init_r(void)
>  {
>  	uint boot;
>  
> -	env_set("fel_booted", NULL);
> -	env_set("fel_scriptaddr", NULL);
> -	env_set("mmc_bootdev", NULL);
> +	env_set(ctx_uboot, "fel_booted", NULL);
> +	env_set(ctx_uboot, "fel_scriptaddr", NULL);
> +	env_set(ctx_uboot, "mmc_bootdev", NULL);
>  
>  	boot = sunxi_get_boot_device();
>  	/* determine if we are running in FEL mode */
>  	if (boot == BOOT_DEVICE_BOARD) {
> -		env_set("fel_booted", "1");
> +		env_set(ctx_uboot, "fel_booted", "1");
>  		parse_spl_header(SPL_ADDR);
>  	/* or if we booted from MMC, and which one */
>  	} else if (boot == BOOT_DEVICE_MMC1) {
> -		env_set("mmc_bootdev", "0");
> +		env_set(ctx_uboot, "mmc_bootdev", "0");
>  	} else if (boot == BOOT_DEVICE_MMC2) {
> -		env_set("mmc_bootdev", "1");
> +		env_set(ctx_uboot, "mmc_bootdev", "1");
>  	}
>  
>  	setup_environment(gd->fdt_blob);
> diff --git a/board/synopsys/hsdk/env-lib.c
> b/board/synopsys/hsdk/env-lib.c index f443c21e6d99..eca2211246b4
> 100644 --- a/board/synopsys/hsdk/env-lib.c
> +++ b/board/synopsys/hsdk/env-lib.c
> @@ -21,10 +21,12 @@ static int env_read_common(u32 index, const
> struct env_map_common *map) 
>  	if (!env_get_yesno(map[index].env_name)) {
>  		if (map[index].type == ENV_HEX) {
> -			val = (u32)env_get_hex(map[index].env_name,
> 0);
> +			val = (u32)env_get_hex(ctx_uboot,
> map[index].env_name,
> +					       0);
>  			debug("ENV: %s: = %#x\n",
> map[index].env_name, val); } else {
> -			val =
> (u32)env_get_ulong(map[index].env_name, 10, 0);
> +			val = (u32)env_get_ulong(ctx_uboot,
> +
> map[index].env_name, 10, 0); debug("ENV: %s: = %d\n",
> map[index].env_name, val); }
>  
> @@ -52,10 +54,11 @@ static int env_read_core(u32 index, const struct
> env_map_percpu *map) sprintf(command, "%s_%u", map[index].env_name,
> i); if (!env_get_yesno(command)) {
>  			if (map[index].type == ENV_HEX) {
> -				val = (u32)env_get_hex(command, 0);
> +				val = (u32)env_get_hex(ctx_uboot,
> command, 0); debug("ENV: %s: = %#x\n", command, val);
>  			} else {
> -				val = (u32)env_get_ulong(command,
> 10, 0);
> +				val = (u32)env_get_ulong(ctx_uboot,
> command,
> +							 10, 0);
>  				debug("ENV: %s: = %d\n", command,
> val); }
>  
> diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c
> index 8a7642a0aaaa..ab97b97bcde3 100644
> --- a/board/synopsys/hsdk/hsdk.c
> +++ b/board/synopsys/hsdk/hsdk.c
> @@ -854,19 +854,19 @@ static int do_hsdk_clock_get(cmd_tbl_t *cmdtp,
> int flag, int argc, if (soc_clk_ctl("cpu-clk", &rate, CLK_GET |
> CLK_MHZ)) return CMD_RET_FAILURE;
>  
> -	if (env_set_ulong("cpu_freq", rate))
> +	if (env_set_ulong(ctx_uboot, "cpu_freq", rate))
>  		return CMD_RET_FAILURE;
>  
>  	if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
>  		return CMD_RET_FAILURE;
>  
> -	if (env_set_ulong("tun_freq", rate))
> +	if (env_set_ulong(ctx_uboot, "tun_freq", rate))
>  		return CMD_RET_FAILURE;
>  
>  	if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
>  		return CMD_RET_FAILURE;
>  
> -	if (env_set_ulong("axi_freq", rate))
> +	if (env_set_ulong(ctx_uboot, "axi_freq", rate))
>  		return CMD_RET_FAILURE;
>  
>  	printf("Clock values are saved to environment\n");
> diff --git a/board/syteco/zmx25/zmx25.c b/board/syteco/zmx25/zmx25.c
> index d2318457b431..c49ac35c2933 100644
> --- a/board/syteco/zmx25/zmx25.c
> +++ b/board/syteco/zmx25/zmx25.c
> @@ -145,7 +145,7 @@ int board_late_init(void)
>  	udelay(5000);
>  #endif
>  
> -	e = env_get("gs_base_board");
> +	e = env_get(ctx_uboot, "gs_base_board");
>  	if (e != NULL) {
>  		if (strcmp(e, "G283") == 0) {
>  			int key = gpio_get_value(IMX_GPIO_NR(2, 29));
> @@ -155,9 +155,11 @@ int board_late_init(void)
>  				gpio_set_value(IMX_GPIO_NR(1, 29),
> 0); gpio_set_value(IMX_GPIO_NR(4, 21), 0);
>  
> -				env_set("preboot", "run
> gs_slow_boot");
> +				env_set(ctx_uboot, "preboot",
> +					"run gs_slow_boot");
>  			} else
> -				env_set("preboot", "run
> gs_fast_boot");
> +				env_set(ctx_uboot, "preboot",
> +					"run gs_fast_boot");
>  		}
>  	}
>  
> diff --git a/board/tcl/sl50/board.c b/board/tcl/sl50/board.c
> index c7eed319461a..79598cd36a5e 100644
> --- a/board/tcl/sl50/board.c
> +++ b/board/tcl/sl50/board.c
> @@ -75,7 +75,7 @@ int spl_start_uboot(void)
>  
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> +	env_load(ctx_uboot);
>  	if (env_get_yesno("boot_os") != 1)
>  		return 1;
>  #endif
> @@ -321,7 +321,7 @@ int board_eth_init(bd_t *bis)
>  
>  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> @@ -339,7 +339,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
> diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
> b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index
> 47259b714961..d0150a127dd6 100644 ---
> a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++
> b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -58,8 +58,8 @@
> static int setup_boottargets(void) }
>  	debug("%s: booted from %s\n", __func__, boot_device);
>  
> -	env_default = env_get_default("boot_targets");
> -	env = env_get("boot_targets");
> +	env_default = env_get_default(ctx_uboot, "boot_targets");
> +	env = env_get(ctx_uboot, "boot_targets");
>  	if (!env) {
>  		debug("%s: boot_targets does not exist\n", __func__);
>  		return -1;
> @@ -102,7 +102,7 @@ static int setup_boottargets(void)
>  			mmc0[3] = '1';
>  			mmc1[3] = '0';
>  			debug("%s: set boot_targets to: %s\n",
> __func__, env);
> -			env_set("boot_targets", env);
> +			env_set(ctx_uboot, "boot_targets", env);
>  		}
>  	}
>  
> @@ -140,7 +140,7 @@ void get_board_serial(struct tag_serialnr
> *serialnr) char *serial_string;
>  	u64 serial = 0;
>  
> -	serial_string = env_get("serial#");
> +	serial_string = env_get(ctx_uboot, "serial#");
>  
>  	if (serial_string)
>  		serial = simple_strtoull(serial_string, NULL, 16);
> diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
> index 7eaa6cd96d60..b1f432332d8c 100644
> --- a/board/ti/am335x/board.c
> +++ b/board/ti/am335x/board.c
> @@ -251,7 +251,7 @@ int spl_start_uboot(void)
>  
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> +	env_load(ctx_uboot);
>  	if (env_get_yesno("boot_os") != 1)
>  		return 1;
>  #endif
> @@ -825,7 +825,7 @@ int board_late_init(void)
>  	 * on HS devices.
>  	 */
>  	if (get_device_type() == HS_DEVICE)
> -		env_set("boot_fit", "1");
> +		env_set(ctx_uboot, "boot_fit", "1");
>  #endif
>  
>  #if !defined(CONFIG_SPL_BUILD)
> @@ -839,7 +839,7 @@ int board_late_init(void)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> @@ -855,20 +855,20 @@ int board_late_init(void)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
>  #endif
>  
> -	if (!env_get("serial#")) {
> -		char *board_serial = env_get("board_serial");
> -		char *ethaddr = env_get("ethaddr");
> +	if (!env_get(ctx_uboot, "serial#")) {
> +		char *board_serial = env_get(ctx_uboot,
> "board_serial");
> +		char *ethaddr = env_get(ctx_uboot, "ethaddr");
>  
>  		if (!board_serial || !strncmp(board_serial,
> "unknown", 7))
> -			env_set("serial#", ethaddr);
> +			env_set(ctx_uboot, "serial#", ethaddr);
>  		else
> -			env_set("serial#", board_serial);
> +			env_set(ctx_uboot, "serial#", board_serial);
>  	}
>  
>  	return 0;
> diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
> index 2e09cc20e8c2..7eb71cd4d8d1 100644
> --- a/board/ti/am43xx/board.c
> +++ b/board/ti/am43xx/board.c
> @@ -728,7 +728,7 @@ int board_late_init(void)
>  	 * on HS devices.
>  	 */
>  	if (get_device_type() == HS_DEVICE)
> -		env_set("boot_fit", "1");
> +		env_set(ctx_uboot, "boot_fit", "1");
>  #endif
>  
>  #if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
> @@ -902,7 +902,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		puts("<ethaddr> not set. Validating first E-fuse
> MAC\n"); if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("ethaddr", mac_addr);
> @@ -917,7 +917,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = mac_lo & 0xFF;
>  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
> diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
> index f78e6c2e1f6e..222049d541de 100644
> --- a/board/ti/am57xx/board.c
> +++ b/board/ti/am57xx/board.c
> @@ -668,7 +668,7 @@ void am57x_idk_lcd_detect(void)
>  		/* we will let default be "no lcd" */
>  	}
>  out:
> -	env_set("idk_lcd", idk_lcd);
> +	env_set(ctx_uboot, "idk_lcd", idk_lcd);
>  	return;
>  }
>  
> @@ -701,7 +701,7 @@ int board_late_init(void)
>  	 * on HS devices.
>  	 */
>  	if (get_device_type() == HS_DEVICE)
> -		env_set("boot_fit", "1");
> +		env_set(ctx_uboot, "boot_fit", "1");
>  
>  	/*
>  	 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
> @@ -871,7 +871,7 @@ int spl_start_uboot(void)
>  
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> +	env_load(ctx_uboot);
>  	if (env_get_yesno("boot_os") != 1)
>  		return 1;
>  #endif
> @@ -975,7 +975,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
>  	mac_addr[5] = mac_lo & 0xFF;
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> @@ -991,7 +991,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
>  	mac_addr[5] = mac_lo & 0xFF;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
> @@ -1100,8 +1100,8 @@ int board_fit_config_name_match(const char
> *name) int fastboot_set_reboot_flag(void)
>  {
>  	printf("Setting reboot to fastboot flag ...\n");
> -	env_set("dofastboot", "1");
> -	env_save();
> +	env_set(ctx_uboot, "dofastboot", "1");
> +	env_save(ctx_uboot);
>  	return 0;
>  }
>  #endif
> diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
> index 0138fc91fcbe..7ee36aff7c45 100644
> --- a/board/ti/beagle/beagle.c
> +++ b/board/ti/beagle/beagle.c
> @@ -340,16 +340,16 @@ int misc_init_r(void)
>  	switch (get_board_revision()) {
>  	case REVISION_AXBX:
>  		printf("Beagle Rev Ax/Bx\n");
> -		env_set("beaglerev", "AxBx");
> +		env_set(ctx_uboot, "beaglerev", "AxBx");
>  		break;
>  	case REVISION_CX:
>  		printf("Beagle Rev C1/C2/C3\n");
> -		env_set("beaglerev", "Cx");
> +		env_set(ctx_uboot, "beaglerev", "Cx");
>  		MUX_BEAGLE_C();
>  		break;
>  	case REVISION_C4:
>  		printf("Beagle Rev C4\n");
> -		env_set("beaglerev", "C4");
> +		env_set(ctx_uboot, "beaglerev", "C4");
>  		MUX_BEAGLE_C();
>  		/* Set VAUX2 to 1.8V for EHCI PHY */
>  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> @@ -359,7 +359,7 @@ int misc_init_r(void)
>  		break;
>  	case REVISION_XM_AB:
>  		printf("Beagle xM Rev A/B\n");
> -		env_set("beaglerev", "xMAB");
> +		env_set(ctx_uboot, "beaglerev", "xMAB");
>  		MUX_BEAGLE_XM();
>  		/* Set VAUX2 to 1.8V for EHCI PHY */
>  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> @@ -370,7 +370,7 @@ int misc_init_r(void)
>  		break;
>  	case REVISION_XM_C:
>  		printf("Beagle xM Rev C\n");
> -		env_set("beaglerev", "xMC");
> +		env_set(ctx_uboot, "beaglerev", "xMC");
>  		MUX_BEAGLE_XM();
>  		/* Set VAUX2 to 1.8V for EHCI PHY */
>  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> @@ -396,14 +396,14 @@ int misc_init_r(void)
>  			expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_TINCANTOOLS_ZIPPY();
> -		env_set("buddy", "zippy");
> +		env_set(ctx_uboot, "buddy", "zippy");
>  		break;
>  	case TINCANTOOLS_ZIPPY2:
>  		printf("Recognized Tincantools Zippy2 board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		MUX_TINCANTOOLS_ZIPPY();
> -		env_set("buddy", "zippy2");
> +		env_set(ctx_uboot, "buddy", "zippy2");
>  		break;
>  	case TINCANTOOLS_TRAINER:
>  		printf("Recognized Tincantools Trainer board (rev %d
> %s)\n", @@ -411,37 +411,37 @@ int misc_init_r(void)
>  			expansion_config.fab_revision);
>  		MUX_TINCANTOOLS_ZIPPY();
>  		MUX_TINCANTOOLS_TRAINER();
> -		env_set("buddy", "trainer");
> +		env_set(ctx_uboot, "buddy", "trainer");
>  		break;
>  	case TINCANTOOLS_SHOWDOG:
>  		printf("Recognized Tincantools Showdow board (rev %d
> %s)\n", expansion_config.revision,
>  			expansion_config.fab_revision);
>  		/* Place holder for DSS2 definition for showdog lcd
> */
> -		env_set("defaultdisplay", "showdoglcd");
> -		env_set("buddy", "showdog");
> +		env_set(ctx_uboot, "defaultdisplay", "showdoglcd");
> +		env_set(ctx_uboot, "buddy", "showdog");
>  		break;
>  	case KBADC_BEAGLEFPGA:
>  		printf("Recognized KBADC Beagle FPGA board\n");
>  		MUX_KBADC_BEAGLEFPGA();
> -		env_set("buddy", "beaglefpga");
> +		env_set(ctx_uboot, "buddy", "beaglefpga");
>  		break;
>  	case LW_BEAGLETOUCH:
>  		printf("Recognized Liquidware BeagleTouch board\n");
> -		env_set("buddy", "beagletouch");
> +		env_set(ctx_uboot, "buddy", "beagletouch");
>  		break;
>  	case BRAINMUX_LCDOG:
>  		printf("Recognized Brainmux LCDog board\n");
> -		env_set("buddy", "lcdog");
> +		env_set(ctx_uboot, "buddy", "lcdog");
>  		break;
>  	case BRAINMUX_LCDOGTOUCH:
>  		printf("Recognized Brainmux LCDog Touch board\n");
> -		env_set("buddy", "lcdogtouch");
> +		env_set(ctx_uboot, "buddy", "lcdogtouch");
>  		break;
>  	case BBTOYS_WIFI:
>  		printf("Recognized BeagleBoardToys WiFi board\n");
>  		MUX_BBTOYS_WIFI()
> -		env_set("buddy", "bbtoys-wifi");
> +		env_set(ctx_uboot, "buddy", "bbtoys-wifi");
>  		break;
>  	case BBTOYS_VGA:
>  		printf("Recognized BeagleBoardToys VGA board\n");
> @@ -458,20 +458,21 @@ int misc_init_r(void)
>  	case LSR_COM6L_ADPT:
>  		printf("Recognized LSR COM6L Adapter Board\n");
>  		MUX_BBTOYS_WIFI()
> -		env_set("buddy", "lsr-com6l-adpt");
> +		env_set(ctx_uboot, "buddy", "lsr-com6l-adpt");
>  		break;
>  	case BEAGLE_NO_EEPROM:
>  		printf("No EEPROM on expansion board\n");
> -		env_set("buddy", "none");
> +		env_set(ctx_uboot, "buddy", "none");
>  		break;
>  	default:
>  		printf("Unrecognized expansion board: %x\n",
>  			expansion_config.device_vendor);
> -		env_set("buddy", "unknown");
> +		env_set(ctx_uboot, "buddy", "unknown");
>  	}
>  
>  	if (expansion_config.content == 1)
> -		env_set(expansion_config.env_var,
> expansion_config.env_setting);
> +		env_set(ctx_uboot, expansion_config.env_var,
> +			expansion_config.env_setting);
>  
>  	twl4030_power_init();
>  	switch (get_board_revision()) {
> @@ -511,10 +512,10 @@ int misc_init_r(void)
>  
>  #if defined(CONFIG_MTDIDS_DEFAULT) &&
> defined(CONFIG_MTDPARTS_DEFAULT) if (strlen(CONFIG_MTDIDS_DEFAULT))
> -		env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
> +		env_set(ctx_uboot, "mtdids", CONFIG_MTDIDS_DEFAULT);
>  
>  	if (strlen(CONFIG_MTDPARTS_DEFAULT))
> -		env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
> +		env_set(ctx_uboot, "mtdparts",
> CONFIG_MTDPARTS_DEFAULT); #endif
>  
>  	return 0;
> diff --git a/board/ti/common/board_detect.c
> b/board/ti/common/board_detect.c index bc89cc57bd78..fe776f2428d2
> 100644 --- a/board/ti/common/board_detect.c
> +++ b/board/ti/common/board_detect.c
> @@ -580,21 +580,21 @@ void __maybe_unused set_board_info_env(char
> *name) struct ti_common_eeprom *ep = TI_EEPROM_DATA;
>  
>  	if (name)
> -		env_set("board_name", name);
> +		env_set(ctx_uboot, "board_name", name);
>  	else if (ep->name)
> -		env_set("board_name", ep->name);
> +		env_set(ctx_uboot, "board_name", ep->name);
>  	else
> -		env_set("board_name", unknown);
> +		env_set(ctx_uboot, "board_name", unknown);
>  
>  	if (ep->version)
> -		env_set("board_rev", ep->version);
> +		env_set(ctx_uboot, "board_rev", ep->version);
>  	else
> -		env_set("board_rev", unknown);
> +		env_set(ctx_uboot, "board_rev", unknown);
>  
>  	if (ep->serial)
> -		env_set("board_serial", ep->serial);
> +		env_set(ctx_uboot, "board_serial", ep->serial);
>  	else
> -		env_set("board_serial", unknown);
> +		env_set(ctx_uboot, "board_serial", unknown);
>  }
>  
>  void __maybe_unused set_board_info_env_am6(char *name)
> diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
> index 74d04bb1e393..63ac5b1988bf 100644
> --- a/board/ti/dra7xx/evm.c
> +++ b/board/ti/dra7xx/evm.c
> @@ -691,7 +691,7 @@ int board_late_init(void)
>  	 * on HS devices.
>  	 */
>  	if (get_device_type() == HS_DEVICE)
> -		env_set("boot_fit", "1");
> +		env_set(ctx_uboot, "boot_fit", "1");
>  
>  	omap_die_id_serial();
>  	omap_set_fastboot_vars();
> @@ -980,7 +980,7 @@ int spl_start_uboot(void)
>  
>  #ifdef CONFIG_SPL_ENV_SUPPORT
>  	env_init();
> -	env_load();
> +	env_load(ctx_uboot);
>  	if (env_get_yesno("boot_os") != 1)
>  		return 1;
>  #endif
> @@ -1048,7 +1048,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
>  	mac_addr[5] = mac_lo & 0xFF;
>  
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> @@ -1064,7 +1064,7 @@ int board_eth_init(bd_t *bis)
>  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
>  	mac_addr[5] = mac_lo & 0xFF;
>  
> -	if (!env_get("eth1addr")) {
> +	if (!env_get(ctx_uboot, "eth1addr")) {
>  		if (is_valid_ethaddr(mac_addr))
>  			eth_env_set_enetaddr("eth1addr", mac_addr);
>  	}
> @@ -1152,8 +1152,8 @@ int board_fit_config_name_match(const char
> *name) int fastboot_set_reboot_flag(void)
>  {
>  	printf("Setting reboot to fastboot flag ...\n");
> -	env_set("dofastboot", "1");
> -	env_save();
> +	env_set(ctx_uboot, "dofastboot", "1");
> +	env_save(ctx_uboot);
>  	return 0;
>  }
>  #endif
> diff --git a/board/ti/evm/evm.c b/board/ti/evm/evm.c
> index d0b9bafbd1b6..4053eb7448a6 100644
> --- a/board/ti/evm/evm.c
> +++ b/board/ti/evm/evm.c
> @@ -283,7 +283,7 @@ static void reset_net_chip(void)
>  int board_eth_init(bd_t *bis)
>  {
>  #if defined(CONFIG_SMC911X)
> -	env_set("ethaddr", NULL);
> +	env_set(ctx_uboot, "ethaddr", NULL);
>  	return smc911x_initialize(0, CONFIG_SMC911X_BASE);
>  #else
>  	return 0;
> diff --git a/board/ti/ks2_evm/board.c b/board/ti/ks2_evm/board.c
> index e9bc68049b4b..aa447fd886cc 100644
> --- a/board/ti/ks2_evm/board.c
> +++ b/board/ti/ks2_evm/board.c
> @@ -113,7 +113,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  	u64 start[2];
>  	u32 ddr3a_size;
>  
> -	env = env_get("mem_lpae");
> +	env = env_get(ctx_uboot, "mem_lpae");
>  	lpae = env && simple_strtol(env, NULL, 0);
>  
>  	ddr3a_size = 0;
> @@ -140,13 +140,13 @@ int ft_board_setup(void *blob, bd_t *bd)
>  	}
>  
>  	/* reserve memory at start of bank */
> -	env = env_get("mem_reserve_head");
> +	env = env_get(ctx_uboot, "mem_reserve_head");
>  	if (env) {
>  		start[0] += ustrtoul(env, &endp, 0);
>  		size[0] -= ustrtoul(env, &endp, 0);
>  	}
>  
> -	env = env_get("mem_reserve");
> +	env = env_get(ctx_uboot, "mem_reserve");
>  	if (env)
>  		size[0] -= ustrtoul(env, &endp, 0);
>  
> @@ -163,9 +163,9 @@ void ft_board_setup_ex(void *blob, bd_t *bd)
>  	u64 *reserve_start;
>  	int unitrd_fixup = 0;
>  
> -	env = env_get("mem_lpae");
> +	env = env_get(ctx_uboot, "mem_lpae");
>  	lpae = env && simple_strtol(env, NULL, 0);
> -	env = env_get("uinitrd_fixup");
> +	env = env_get(ctx_uboot, "uinitrd_fixup");
>  	unitrd_fixup = env && simple_strtol(env, NULL, 0);
>  
>  	/* Fix up the initrd */
> diff --git a/board/ti/ks2_evm/board_k2g.c
> b/board/ti/ks2_evm/board_k2g.c index 4ff9a44b3712..49c09b88bd83 100644
> --- a/board/ti/ks2_evm/board_k2g.c
> +++ b/board/ti/ks2_evm/board_k2g.c
> @@ -353,11 +353,11 @@ int board_late_init(void)
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	if (board_is_k2g_gp())
> -		env_set("board_name", "66AK2GGP\0");
> +		env_set(ctx_uboot, "board_name", "66AK2GGP\0");
>  	else if (board_is_k2g_g1())
> -		env_set("board_name", "66AK2GG1\0");
> +		env_set(ctx_uboot, "board_name", "66AK2GG1\0");
>  	else if (board_is_k2g_ice())
> -		env_set("board_name", "66AK2GIC\0");
> +		env_set(ctx_uboot, "board_name", "66AK2GIC\0");
>  #endif
>  	return 0;
>  }
> @@ -384,7 +384,7 @@ void spl_init_keystone_plls(void)
>  #ifdef CONFIG_TI_SECURE_DEVICE
>  void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
>  {
> -	int id = env_get_ulong("dev_pmmc", 10, 0);
> +	int id = env_get_ulong(ctx_uboot, "dev_pmmc", 10, 0);
>  	int ret;
>  
>  	if (!rproc_is_initialized())
> diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
> index 20199da390ec..9d42123de9cc 100644
> --- a/board/ti/panda/panda.c
> +++ b/board/ti/panda/panda.c
> @@ -103,7 +103,7 @@ int get_board_revision(void)
>  		board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -		env_set("board_name", "panda-es");
> +		env_set(ctx_uboot, "board_name", "panda-es");
>  #endif
>  		board_id = ((board_id4 << 4) | (board_id3 << 3) |
>  			(board_id2 << 2) | (board_id1 << 1) |
> (board_id0)); @@ -117,7 +117,7 @@ int get_board_revision(void)
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  		if ((board_id >= 0x3) && (processor_rev ==
> OMAP4430_ES2_3))
> -			env_set("board_name", "panda-a4");
> +			env_set(ctx_uboot, "board_name", "panda-a4");
>  #endif
>  	}
>  
> diff --git a/board/toradex/apalis-imx8/apalis-imx8.c
> b/board/toradex/apalis-imx8/apalis-imx8.c index
> af48b560952e..7e0f01534a9e 100644 ---
> a/board/toradex/apalis-imx8/apalis-imx8.c +++
> b/board/toradex/apalis-imx8/apalis-imx8.c @@ -117,8 +117,8 @@ int
> board_late_init(void) {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  /* TODO move to common */
> -	env_set("board_name", "Apalis iMX8QM");
> -	env_set("board_rev", "v1.0");
> +	env_set(ctx_uboot, "board_name", "Apalis iMX8QM");
> +	env_set(ctx_uboot, "board_rev", "v1.0");
>  #endif
>  
>  	return 0;
> diff --git a/board/toradex/apalis_imx6/apalis_imx6.c
> b/board/toradex/apalis_imx6/apalis_imx6.c index
> 6421a22c25a7..c40ccedc4c9d 100644 ---
> a/board/toradex/apalis_imx6/apalis_imx6.c +++
> b/board/toradex/apalis_imx6/apalis_imx6.c @@ -701,7 +701,7 @@ int
> board_late_init(void) 
>  	rev = get_board_rev();
>  	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
> -	env_set("board_rev", env_str);
> +	env_set(ctx_uboot, "board_rev", env_str);
>  
>  #ifndef CONFIG_TDX_APALIS_IMX6_V1_0
>  	if ((rev & 0xfff0) == 0x0100) {
> @@ -711,12 +711,12 @@ int board_late_init(void)
>  		setup_iomux_dce_uart();
>  
>  		/* if using the default device tree, use version for
> V1.0 HW */
> -		fdt_env = env_get("fdt_file");
> +		fdt_env = env_get(ctx_uboot, "fdt_file");
>  		if ((fdt_env != NULL) && (strcmp(FDT_FILE, fdt_env)
> == 0)) {
> -			env_set("fdt_file", FDT_FILE_V1_0);
> +			env_set(ctx_uboot, "fdt_file",
> FDT_FILE_V1_0); printf("patching fdt_file to " FDT_FILE_V1_0 "\n");
>  #ifndef CONFIG_ENV_IS_NOWHERE
> -			env_save();
> +			env_save(ctx_uboot);
>  #endif
>  		}
>  	}
> @@ -726,8 +726,8 @@ int board_late_init(void)
>  #ifdef CONFIG_CMD_USB_SDP
>  	if (is_boot_from_usb()) {
>  		printf("Serial Downloader recovery mode, using sdp
> command\n");
> -		env_set("bootdelay", "0");
> -		env_set("bootcmd", "sdp 0");
> +		env_set(ctx_uboot, "bootdelay", "0");
> +		env_set(ctx_uboot, "bootcmd", "sdp 0");
>  	}
>  #endif /* CONFIG_CMD_USB_SDP */
>  
> diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c
> b/board/toradex/colibri-imx6ull/colibri-imx6ull.c index
> d1ae463941ae..160b79ba0b27 100644 ---
> a/board/toradex/colibri-imx6ull/colibri-imx6ull.c +++
> b/board/toradex/colibri-imx6ull/colibri-imx6ull.c @@ -178,7 +178,7 @@
> int board_late_init(void) */
>  	if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
>  	    tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT)
> -		env_set("variant", "-wifi");
> +		env_set(ctx_uboot, "variant", "-wifi");
>  #endif
>  
>  	/*
> @@ -196,8 +196,8 @@ int board_late_init(void)
>  #ifdef CONFIG_CMD_USB_SDP
>  	if (is_boot_from_usb()) {
>  		printf("Serial Downloader recovery mode, using sdp
> command\n");
> -		env_set("bootdelay", "0");
> -		env_set("bootcmd", "sdp 0");
> +		env_set(ctx_uboot, "bootdelay", "0");
> +		env_set(ctx_uboot, "bootcmd", "sdp 0");
>  	}
>  #endif /* CONFIG_CMD_USB_SDP */
>  
> diff --git a/board/toradex/colibri-imx8x/colibri-imx8x.c
> b/board/toradex/colibri-imx8x/colibri-imx8x.c index
> eae3c591a164..ef52f95dc93e 100644 ---
> a/board/toradex/colibri-imx8x/colibri-imx8x.c +++
> b/board/toradex/colibri-imx8x/colibri-imx8x.c @@ -129,8 +129,8 @@ int
> board_late_init(void) {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  /* TODO move to common */
> -	env_set("board_name", "Colibri iMX8QXP");
> -	env_set("board_rev", "v1.0");
> +	env_set(ctx_uboot, "board_name", "Colibri iMX8QXP");
> +	env_set(ctx_uboot, "board_rev", "v1.0");
>  #endif
>  
>  	return 0;
> diff --git a/board/toradex/colibri_imx6/colibri_imx6.c
> b/board/toradex/colibri_imx6/colibri_imx6.c index
> ad40b589c1ed..1c1c1577eb1f 100644 ---
> a/board/toradex/colibri_imx6/colibri_imx6.c +++
> b/board/toradex/colibri_imx6/colibri_imx6.c @@ -661,14 +661,14 @@ int
> board_late_init(void) 
>  	rev = get_board_rev();
>  	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
> -	env_set("board_rev", env_str);
> +	env_set(ctx_uboot, "board_rev", env_str);
>  #endif
>  
>  #ifdef CONFIG_CMD_USB_SDP
>  	if (is_boot_from_usb()) {
>  		printf("Serial Downloader recovery mode, using sdp
> command\n");
> -		env_set("bootdelay", "0");
> -		env_set("bootcmd", "sdp 0");
> +		env_set(ctx_uboot, "bootdelay", "0");
> +		env_set(ctx_uboot, "bootcmd", "sdp 0");
>  	}
>  #endif /* CONFIG_CMD_USB_SDP */
>  
> @@ -702,7 +702,7 @@ int ft_board_setup(void *blob, bd_t *bd)
>  
>  	ft_common_board_setup(blob, bd);
>  
> -	cma_size = env_get_ulong("cma-size", 10, 320 * 1024 * 1024);
> +	cma_size = env_get_ulong(ctx_uboot, "cma-size", 10, 320 *
> 1024 * 1024); cma_size = min((u32)(gd->ram_size >> 1), cma_size);
>  
>  	fdt_setprop_u32(blob,
> diff --git a/board/toradex/colibri_vf/colibri_vf.c
> b/board/toradex/colibri_vf/colibri_vf.c index
> 04d8ffd1e666..e466d8aad6e1 100644 ---
> a/board/toradex/colibri_vf/colibri_vf.c +++
> b/board/toradex/colibri_vf/colibri_vf.c @@ -392,7 +392,7 @@ int
> board_late_init(void) if (((src->sbmr2 & SRC_SBMR2_BMOD_MASK) >>
> SRC_SBMR2_BMOD_SHIFT) == SRC_SBMR2_BMOD_SERIAL) {
>  		printf("Serial Downloader recovery mode, disable
> autoboot\n");
> -		env_set("bootdelay", "-1");
> +		env_set(ctx_uboot, "bootdelay", "-1");
>  	}
>  
>  	return 0;
> diff --git a/board/toradex/common/tdx-cfg-block.c
> b/board/toradex/common/tdx-cfg-block.c index
> 9c86230595b9..6897ced0f7fe 100644 ---
> a/board/toradex/common/tdx-cfg-block.c +++
> b/board/toradex/common/tdx-cfg-block.c @@ -314,7 +314,7 @@ static int
> get_cfgblock_interactive(void) wb = console_buffer[0];
>  #endif
>  
> -	soc = env_get("soc");
> +	soc = env_get(ctx_uboot, "soc");
>  	if (!strcmp("mx6", soc)) {
>  #ifdef CONFIG_TARGET_APALIS_IMX6
>  		if (it == 'y' || it == 'Y') {
> diff --git a/board/toradex/common/tdx-common.c
> b/board/toradex/common/tdx-common.c index e9441a7979d2..a51749dd78c2
> 100644 --- a/board/toradex/common/tdx-common.c
> +++ b/board/toradex/common/tdx-common.c
> @@ -81,7 +81,7 @@ int show_board_info(void)
>  			tdx_hw_tag.ver_minor,
>  			(char)tdx_hw_tag.ver_assembly + 'A');
>  
> -		env_set("serial#", tdx_serial_str);
> +		env_set(ctx_uboot, "serial#", tdx_serial_str);
>  
>  		printf("Model: Toradex %s %s, Serial# %s\n",
>  		       toradex_modules[tdx_hw_tag.prodid],
> diff --git a/board/tqc/tqma6/tqma6.c b/board/tqc/tqma6/tqma6.c
> index 5b20afd48814..f13126c2ee59 100644
> --- a/board/tqc/tqma6/tqma6.c
> +++ b/board/tqc/tqma6/tqma6.c
> @@ -253,7 +253,7 @@ int power_init_board(void)
>  
>  int board_late_init(void)
>  {
> -	env_set("board_name", tqma6_get_boardname());
> +	env_set(ctx_uboot, "board_name", tqma6_get_boardname());
>  
>  	tqma6_bb_board_late_init();
>  
> diff --git a/board/udoo/neo/neo.c b/board/udoo/neo/neo.c
> index 5c468a6a973e..2a61dc29ef92 100644
> --- a/board/udoo/neo/neo.c
> +++ b/board/udoo/neo/neo.c
> @@ -437,7 +437,7 @@ int checkboard(void)
>  int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> -	env_set("board_name", board_string());
> +	env_set(ctx_uboot, "board_name", board_string());
>  #endif
>  
>  	return 0;
> diff --git a/board/udoo/udoo.c b/board/udoo/udoo.c
> index f2c2bf47b0fd..88bc24b2b475 100644
> --- a/board/udoo/udoo.c
> +++ b/board/udoo/udoo.c
> @@ -254,9 +254,9 @@ int board_late_init(void)
>  {
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	if (is_cpu_type(MXC_CPU_MX6Q))
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  #endif
>  	return 0;
>  }
> diff --git a/board/varisys/common/sys_eeprom.c
> b/board/varisys/common/sys_eeprom.c index 77772a6923e4..5b248f8b0f44
> 100644 --- a/board/varisys/common/sys_eeprom.c
> +++ b/board/varisys/common/sys_eeprom.c
> @@ -401,7 +401,7 @@ int mac_read_from_generic_eeprom(const char
> *envvar, int chip, mac[5]);
>  
>  		printf("MAC: %s\n", ethaddr);
> -		env_set(envvar, ethaddr);
> +		env_set(ctx_uboot, envvar, ethaddr);
>  	}
>  
>  	return ret;
> @@ -486,8 +486,8 @@ int mac_read_from_eeprom_common(void)
>  			/* Only initialize environment variables
> that are blank
>  			 * (i.e. have not yet been set)
>  			 */
> -			if (!env_get(enetvar))
> -				env_set(enetvar, ethaddr);
> +			if (!env_get(ctx_uboot, enetvar))
> +				env_set(ctx_uboot, enetvar, ethaddr);
>  		}
>  	}
>  
> diff --git a/board/vscom/baltos/board.c b/board/vscom/baltos/board.c
> index 1ba58d0f11dd..5e799d546786 100644
> --- a/board/vscom/baltos/board.c
> +++ b/board/vscom/baltos/board.c
> @@ -65,7 +65,7 @@ static int baltos_set_console(void)
>  	printf("DIPs: 0x%1x\n", (~dips) & 0xf);
>  
>  	if ((dips & 0xf) == 0xe)
> -		env_set("console", "ttyUSB0,115200n8");
> +		env_set(ctx_uboot, "console", "ttyUSB0,115200n8");
>  
>  	return 0;
>  }
> @@ -367,7 +367,7 @@ int board_late_init(void)
>  		return -ENODEV;
>  	}
>  
> -	env_set("board_name", model);
> +	env_set(ctx_uboot, "board_name", model);
>  #endif
>  
>  	return 0;
> @@ -447,7 +447,7 @@ int board_eth_init(bd_t *bis)
>  
>  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
> -	if (!env_get("ethaddr")) {
> +	if (!env_get(ctx_uboot, "ethaddr")) {
>  		printf("<ethaddr> not set. Validating first E-fuse
> MAC\n"); 
>  		if (is_valid_ethaddr(mac_addr))
> diff --git a/board/wandboard/wandboard.c b/board/wandboard/wandboard.c
> index 69cdf3e9c96b..4ba472cae9b8 100644
> --- a/board/wandboard/wandboard.c
> +++ b/board/wandboard/wandboard.c
> @@ -451,18 +451,18 @@ int board_late_init(void)
>  
>  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  	if (is_mx6dqp())
> -		env_set("board_rev", "MX6QP");
> +		env_set(ctx_uboot, "board_rev", "MX6QP");
>  	else if (is_mx6dq())
> -		env_set("board_rev", "MX6Q");
> +		env_set(ctx_uboot, "board_rev", "MX6Q");
>  	else
> -		env_set("board_rev", "MX6DL");
> +		env_set(ctx_uboot, "board_rev", "MX6DL");
>  
>  	if (is_revd1())
> -		env_set("board_name", "D1");
> +		env_set(ctx_uboot, "board_name", "D1");
>  	else if (is_revc1())
> -		env_set("board_name", "C1");
> +		env_set(ctx_uboot, "board_name", "C1");
>  	else
> -		env_set("board_name", "B1");
> +		env_set(ctx_uboot, "board_name", "B1");
>  #endif
>  	return 0;
>  }
> diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c
> index 39ae98225738..549d65b3469d 100644
> --- a/board/warp7/warp7.c
> +++ b/board/warp7/warp7.c
> @@ -148,9 +148,9 @@ int board_late_init(void)
>  
>  #ifdef CONFIG_SECURE_BOOT
>  	/* Determine HAB state */
> -	env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
> +	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME,
> imx_hab_is_enabled()); #else
> -	env_set_ulong(HAB_ENABLED_ENVNAME, 0);
> +	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME, 0);
>  #endif
>  
>  #ifdef CONFIG_SERIAL_TAG
> @@ -158,7 +158,7 @@ int board_late_init(void)
>  	get_board_serial(&serialnr);
>  	snprintf(serial_string, sizeof(serial_string),
> "WaRP7-0x%08x%08x", serialnr.low, serialnr.high);
> -	env_set("serial#", serial_string);
> +	env_set(ctx_uboot, "serial#", serial_string);
>  #endif
>  
>  	return 0;
> diff --git a/board/work-microwave/work_92105/work_92105_display.c
> b/board/work-microwave/work_92105/work_92105_display.c index
> db04dcabc7bc..e673921b7bbc 100644 ---
> a/board/work-microwave/work_92105/work_92105_display.c +++
> b/board/work-microwave/work_92105/work_92105_display.c @@ -228,7
> +228,7 @@ void work_92105_display_init(void) i2c_write(0x2c, 0x01, 1,
> &enable_backlight, 1); 
>  	/* set display contrast */
> -	display_contrast_str = env_get("fwopt_dispcontrast");
> +	display_contrast_str = env_get(ctx_uboot,
> "fwopt_dispcontrast"); if (display_contrast_str)
>  		display_contrast =
> simple_strtoul(display_contrast_str, NULL, 10);
> diff --git a/board/xes/common/board.c b/board/xes/common/board.c
> index 43575bc302d6..b5cc9a69508a 100644
> --- a/board/xes/common/board.c
> +++ b/board/xes/common/board.c
> @@ -51,13 +51,13 @@ int checkboard(void)
>  
>  	/* Display board specific information */
>  	puts("       ");
> -	i = env_get_f("board_rev", buf, sizeof(buf));
> +	i = env_get_f("board_rev", buf, sizeof(ctx_uboot, buf));
>  	if (i > 0)
>  		printf("Rev %s, ", buf);
> -	i = env_get_f("serial#", buf, sizeof(buf));
> +	i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
>  	if (i > 0)
>  		printf("Serial# %s, ", buf);
> -	i = env_get_f("board_cfg", buf, sizeof(buf));
> +	i = env_get_f("board_cfg", buf, sizeof(ctx_uboot, buf));
>  	if (i > 0)
>  		printf("Cfg %s", buf);
>  	puts("\n");
> diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
> index 35191b2f813b..509834c679ab 100644
> --- a/board/xilinx/zynq/board.c
> +++ b/board/xilinx/zynq/board.c
> @@ -41,27 +41,27 @@ int board_late_init(void)
>  	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
>  	case ZYNQ_BM_QSPI:
>  		mode = "qspi";
> -		env_set("modeboot", "qspiboot");
> +		env_set(ctx_uboot, "modeboot", "qspiboot");
>  		break;
>  	case ZYNQ_BM_NAND:
>  		mode = "nand";
> -		env_set("modeboot", "nandboot");
> +		env_set(ctx_uboot, "modeboot", "nandboot");
>  		break;
>  	case ZYNQ_BM_NOR:
>  		mode = "nor";
> -		env_set("modeboot", "norboot");
> +		env_set(ctx_uboot, "modeboot", "norboot");
>  		break;
>  	case ZYNQ_BM_SD:
>  		mode = "mmc";
> -		env_set("modeboot", "sdboot");
> +		env_set(ctx_uboot, "modeboot", "sdboot");
>  		break;
>  	case ZYNQ_BM_JTAG:
>  		mode = "pxe dhcp";
> -		env_set("modeboot", "jtagboot");
> +		env_set(ctx_uboot, "modeboot", "jtagboot");
>  		break;
>  	default:
>  		mode = "";
> -		env_set("modeboot", "");
> +		env_set(ctx_uboot, "modeboot", "");
>  		break;
>  	}
>  
> @@ -69,7 +69,7 @@ int board_late_init(void)
>  	 * One terminating char + one byte for space between mode
>  	 * and default boot_targets
>  	 */
> -	env_targets = env_get("boot_targets");
> +	env_targets = env_get(ctx_uboot, "boot_targets");
>  	if (env_targets)
>  		env_targets_len = strlen(env_targets);
>  
> @@ -80,7 +80,7 @@ int board_late_init(void)
>  	sprintf(new_targets, "%s %s", mode,
>  		env_targets ? env_targets : "");
>  
> -	env_set("boot_targets", new_targets);
> +	env_set(ctx_uboot, "boot_targets", new_targets);
>  
>  	return 0;
>  }
> diff --git a/board/xilinx/zynqmp/cmds.c b/board/xilinx/zynqmp/cmds.c
> index ed7ba58c6475..e5c1dab091ca 100644
> --- a/board/xilinx/zynqmp/cmds.c
> +++ b/board/xilinx/zynqmp/cmds.c
> @@ -57,7 +57,7 @@ static int do_zynqmp_verify_secure(cmd_tbl_t
> *cmdtp, int flag, int argc, } else {
>  		addr = (u64)ret_payload[1] << 32 | ret_payload[2];
>  		printf("Verified image at 0x%llx\n", addr);
> -		env_set_hex("zynqmp_verified_img_addr", addr);
> +		env_set_hex(ctx_uboot, "zynqmp_verified_img_addr",
> addr); }
>  
>  	return ret;
> diff --git a/board/xilinx/zynqmp/zynqmp.c
> b/board/xilinx/zynqmp/zynqmp.c index d649daba96d4..31e26fb097a4 100644
> --- a/board/xilinx/zynqmp/zynqmp.c
> +++ b/board/xilinx/zynqmp/zynqmp.c
> @@ -479,7 +479,7 @@ static int reset_reason(void)
>  
>  	puts("\n");
>  
> -	env_set("reset_reason", reason);
> +	env_set(ctx_uboot, "reset_reason", reason);
>  
>  	ret = zynqmp_mmio_write(~0, ~0,
> (ulong)&crlapb_base->reset_reason); if (ret)
> @@ -494,7 +494,7 @@ static int set_fdtfile(void)
>  	const char *suffix = ".dtb";
>  	const char *vendor = "xilinx/";
>  
> -	if (env_get("fdtfile"))
> +	if (env_get(ctx_uboot, "fdtfile"))
>  		return 0;
>  
>  	compatible = (char *)fdt_getprop(gd->fdt_blob, 0,
> "compatible", NULL); @@ -511,7 +511,7 @@ static int set_fdtfile(void)
>  
>  		sprintf(fdtfile, "%s%s%s", vendor, compatible,
> suffix); 
> -		env_set("fdtfile", fdtfile);
> +		env_set(ctx_uboot, "fdtfile", fdtfile);
>  		free(fdtfile);
>  	}
>  
> @@ -558,23 +558,23 @@ int board_late_init(void)
>  	case USB_MODE:
>  		puts("USB_MODE\n");
>  		mode = "usb";
> -		env_set("modeboot", "usb_dfu_spl");
> +		env_set(ctx_uboot, "modeboot", "usb_dfu_spl");
>  		break;
>  	case JTAG_MODE:
>  		puts("JTAG_MODE\n");
>  		mode = "pxe dhcp";
> -		env_set("modeboot", "jtagboot");
> +		env_set(ctx_uboot, "modeboot", "jtagboot");
>  		break;
>  	case QSPI_MODE_24BIT:
>  	case QSPI_MODE_32BIT:
>  		mode = "qspi0";
>  		puts("QSPI_MODE\n");
> -		env_set("modeboot", "qspiboot");
> +		env_set(ctx_uboot, "modeboot", "qspiboot");
>  		break;
>  	case EMMC_MODE:
>  		puts("EMMC_MODE\n");
>  		mode = "mmc0";
> -		env_set("modeboot", "emmcboot");
> +		env_set(ctx_uboot, "modeboot", "emmcboot");
>  		break;
>  	case SD_MODE:
>  		puts("SD_MODE\n");
> @@ -589,7 +589,7 @@ int board_late_init(void)
>  
>  		mode = "mmc";
>  		bootseq = dev->seq;
> -		env_set("modeboot", "sdboot");
> +		env_set(ctx_uboot, "modeboot", "sdboot");
>  		break;
>  	case SD1_LSHFT_MODE:
>  		puts("LVL_SHFT_");
> @@ -607,12 +607,12 @@ int board_late_init(void)
>  
>  		mode = "mmc";
>  		bootseq = dev->seq;
> -		env_set("modeboot", "sdboot");
> +		env_set(ctx_uboot, "modeboot", "sdboot");
>  		break;
>  	case NAND_MODE:
>  		puts("NAND_MODE\n");
>  		mode = "nand0";
> -		env_set("modeboot", "nandboot");
> +		env_set(ctx_uboot, "modeboot", "nandboot");
>  		break;
>  	default:
>  		mode = "";
> @@ -629,7 +629,7 @@ int board_late_init(void)
>  	 * One terminating char + one byte for space between mode
>  	 * and default boot_targets
>  	 */
> -	env_targets = env_get("boot_targets");
> +	env_targets = env_get(ctx_uboot, "boot_targets");
>  	if (env_targets)
>  		env_targets_len = strlen(env_targets);
>  
> @@ -645,7 +645,7 @@ int board_late_init(void)
>  		sprintf(new_targets, "%s %s", mode,
>  			env_targets ? env_targets : "");
>  
> -	env_set("boot_targets", new_targets);
> +	env_set(ctx_uboot, "boot_targets", new_targets);
>  
>  	reset_reason();
>  



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190905/8c82f8d8/attachment-0001.sig>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables AKASHI Takahiro
@ 2019-09-05 19:37   ` Heinrich Schuchardt
  2019-09-06  0:54     ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Heinrich Schuchardt @ 2019-09-05 19:37 UTC (permalink / raw)
  To: u-boot

On 9/5/19 10:21 AM, AKASHI Takahiro wrote:
> We will use two environment contexts for implementing UEFI variables,
> one (ctx_efi) for non-volatile variables and the other for volatile
> variables. The latter doesn't have a backing storage.
>
> Those two contexts are currently used only in efi_variable.c and
> can be moved into there if desired. But I let it under env/ for
> future use elsewhere.
>
> In this commit, FAT file system and flash device are only supported
> devices for backing storages, but extending to other devices will be
> quite straightforward.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   env/Kconfig       |   1 +
>   env/Kconfig.efi   | 152 ++++++++++++++++++++++++++++++++++++++++++++++
>   env/Makefile      |   1 +
>   env/env_ctx_efi.c | 131 +++++++++++++++++++++++++++++++++++++++
>   include/env.h     |   3 +
>   5 files changed, 288 insertions(+)
>   create mode 100644 env/Kconfig.efi
>   create mode 100644 env/env_ctx_efi.c
>
> diff --git a/env/Kconfig b/env/Kconfig
> index ae96cf75bbaa..0cd3caa67376 100644
> --- a/env/Kconfig
> +++ b/env/Kconfig
> @@ -47,5 +47,6 @@ config ENV_DRV_UBI
>   	bool
>
>   source "env/Kconfig.uboot"
> +source "env/Kconfig.efi"
>
>   endmenu
> diff --git a/env/Kconfig.efi b/env/Kconfig.efi
> new file mode 100644
> index 000000000000..cd4e78989df6
> --- /dev/null
> +++ b/env/Kconfig.efi
> @@ -0,0 +1,152 @@
> +if EFI_LOADER
> +
> +menu "Configure UEFI context"
> +

Essentially the 3 variable below exclude each other.

Please, use a 'choice' statement. drivers/video/Kconfig has an example.

> +config ENV_EFI_IS_NOWHERE
> +	bool
> +	default y if !ENV_EFI_IS_INFLASH && !ENV_EFI_IS_IN_FAT
> +
> +config ENV_EFI_IS_IN_FAT
> +	bool "EFI Environment is in a FAT filesystem"
> +	select ENV_DRV_FAT
> +	help
> +	  Define this if you want to use the FAT file system for
> +	  the environment.
> +
> +config ENV_EFI_IS_IN_FLASH
> +	bool "EFI Environment in flash memory"
> +	select ENV_DRV_FLASH
> +	help
> +	  Define this if you have a flash device which you want to use
> +	  for the environment.
> +
> +	  a) The environment occupies one whole flash sector, which is
> +	   "embedded" in the text segment with the U-Boot code. This

Are we really limited to exactly one sector. Or is this the minimum size?

> +	   happens usually with "bottom boot sector" or "top boot
> +	   sector" type flash chips, which have several smaller
> +	   sectors at the start or the end. For instance, such a
> +	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
> +	   such a case you would place the environment in one of the
> +	   4 kB sectors - with U-Boot code before and after it. With
> +	   "top boot sector" type flash chips, you would put the
> +	   environment in one of the last sectors, leaving a gap
> +	   between U-Boot and the environment.
> +
> +	  CONFIG_ENV_EFI_OFFSET:
> +
> +	   Offset of environment data (variable area) to the
> +	   beginning of flash memory; for instance, with bottom boot
> +	   type flash chips the second sector can be used: the offset
> +	   for this sector is given here.
> +
> +	   CONFIG_ENV_EFI_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
> +
> +	  CONFIG_ENV_EFI_ADDR:
> +
> +	   This is just another way to specify the start address of
> +	   the flash sector containing the environment (instead of
> +	   CONFIG_ENV_OFFSET).
> +
> +	  CONFIG_ENV_EFI_SECT_SIZE:
> +
> +	   Size of the sector containing the environment.
> +
> +
> +	  b) Sometimes flash chips have few, equal sized, BIG sectors.
> +	   In such a case you don't want to spend a whole sector for
> +	   the environment.
> +
> +	  CONFIG_ENV_EFI_SIZE:
> +
> +	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
> +	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
> +	   of this flash sector for the environment. This saves
> +	   memory for the RAM copy of the environment.
> +
> +	   It may also save flash memory if you decide to use this
> +	   when your environment is "embedded" within U-Boot code,
> +	   since then the remainder of the flash sector could be used
> +	   for U-Boot code. It should be pointed out that this is
> +	   STRONGLY DISCOURAGED from a robustness point of view:
> +	   updating the environment in flash makes it always
> +	   necessary to erase the WHOLE sector. If something goes
> +	   wrong before the contents has been restored from a copy in
> +	   RAM, your target system will be dead.
> +
> +	  CONFIG_ENV_EFI_ADDR_REDUND
> +	  CONFIG_ENV_EFI_SIZE_REDUND
> +
> +	   These settings describe a second storage area used to hold
> +	   a redundant copy of the environment data, so that there is
> +	   a valid backup copy in case there is a power failure during
> +	   a "saveenv" operation.
> +
> +	  BE CAREFUL! Any changes to the flash layout, and some changes to the
> +	  source code will make it necessary to adapt <board>/u-boot.lds*
> +	  accordingly!
> +
> +config ENV_EFI_FAT_INTERFACE
> +	string "Name of the block device for the environment"
> +	depends on ENV_EFI_IS_IN_FAT
> +	help
> +	  Define this to a string that is the name of the block device.
> +
> +config ENV_EFI_FAT_DEVICE_AND_PART
> +	string "Device and partition for where to store the environment in FAT"
> +	depends on ENV_EFI_IS_IN_FAT
> +	help
> +	  Define this to a string to specify the partition of the device.
> +	  It can be as following:
> +
> +	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> +	       - "D:P": device D partition P. Error occurs if device D has no
> +	                partition table.
> +	       - "D:0": device D.
> +	       - "D" or "D:": device D partition 1 if device D has partition
> +	                      table, or the whole device D if has no partition
> +	                      table.
> +	       - "D:auto": first partition in device D with bootable flag set.
> +	                   If none, first valid partition in device D. If no
> +	                   partition table then means device D.
> +
> +config ENV_EFI_FAT_FILE
> +	string "Name of the FAT file to use for the environment"
> +	depends on ENV_EFI_IS_IN_FAT
> +	default "uboot_efi.env"
> +	help
> +	  It's a string of the FAT file name. This file use to store the
> +	  environment.
> +
> +config ENV_EFI_ADDR

'depends on' is missing for this variable and all below.

> +	hex "EFI Environment Address"
> +	help
> +	  Start address of the device (or partition)
> +
> +config ENV_EFI_OFFSET
> +	hex "EFI Environment Offset"
> +	help
> +	  Offset from the start of the device (or partition)
> +
> +config ENV_EFI_SIZE
> +	hex "EFI Environment Size"
> +	help
> +	  Size of the environment storage area
> +
> +config ENV_EFI_SECT_SIZE
> +	hex "EFI Environment Sector-Size"
> +	help
> +	  Size of the sector containing the environment.
> +
> +config ENV_EFI_ADDR_REDUND
> +	hex "EFI Environment Address for second area"
> +	help
> +	  Start address of the device (or partition)
> +
> +config ENV_EFI_SIZE_REDUND
> +	hex "EFI Environment Size for second area"
> +	help
> +	  Size of the environment second storage area
> +
> +endmenu
> +
> +endif
> diff --git a/env/Makefile b/env/Makefile
> index 0168eb47f00d..b6690c73b17f 100644
> --- a/env/Makefile
> +++ b/env/Makefile
> @@ -4,6 +4,7 @@
>   # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
>
>   obj-y += common.o env.o env_ctx_uboot.o
> +obj-$(CONFIG_EFI_LOADER) += env_ctx_efi.o
>
>   ifndef CONFIG_SPL_BUILD
>   obj-y += attr.o
> diff --git a/env/env_ctx_efi.c b/env/env_ctx_efi.c
> new file mode 100644
> index 000000000000..9b5b2f392179
> --- /dev/null
> +++ b/env/env_ctx_efi.c
> @@ -0,0 +1,131 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2019 Linaro Limited
> + *		Author: AKASHI Takahiro
> + */
> +
> +#include <common.h>
> +#include <env_flags.h>
> +#include <env_internal.h>
> +#include <search.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +struct hsearch_data efi_htab = {
> +#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> +	/* defined in flags.c, only compile with ENV_SUPPORT */
> +	.change_ok = env_flags_validate,
> +#endif
> +};
> +
> +struct hsearch_data efi_volatile_htab = {
> +#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> +	/* defined in flags.c, only compile with ENV_SUPPORT */
> +	.change_ok = env_flags_validate,
> +#endif
> +};
> +
> +static int env_drv_init_efi(struct env_context *ctx, enum env_location loc)
> +{
> +	__maybe_unused int ret;
> +
> +	switch (loc) {
> +#ifdef CONFIG_ENV_EFI_IS_IN_FLASH
> +	case ENVL_FLASH: {
> +		env_t *env_ptr;
> +		env_t *flash_addr;
> +		ulong end_addr;
> +		env_t *flash_addr_new;
> +		ulong end_addr_new;
> +
> +#if defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(CMD_SAVEENV) || \
> +	!defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(INITENV)
> +#ifdef ENV_IS_EMBEDDED
> +		/* FIXME: not allowed */

Is something wrong in Kconfig that an non-allowed situation can occur?

> +		env_ptr = NULL;
> +#else /* ! ENV_IS_EMBEDDED */
> +
> +		env_ptr = (env_t *)CONFIG_ENV_EFI_ADDR;
> +#endif /* ENV_IS_EMBEDDED */
> +#else
> +		env_ptr = NULL;
> +#endif
> +		flash_addr = (env_t *)CONFIG_ENV_EFI_ADDR;
> +
> +/* CONFIG_ENV_EFI_ADDR is supposed to be on sector boundary */
> +		end_addr = CONFIG_ENV_EFI_ADDR + CONFIG_ENV_EFI_SECT_SIZE - 1;
> +
> +#ifdef CONFIG_ENV_EFI_ADDR_REDUND
> +		flash_addr_new = (env_t *)CONFIG_ENV_EFI_ADDR_REDUND;
> +/* CONFIG_ENV_EFI_ADDR_REDUND is supposed to be on sector boundary */
> +		end_addr_new = CONFIG_ENV_EFI_ADDR_REDUND
> +					+ CONFIG_ENV_EFI_SECT_SIZE - 1;
> +#else
> +		flash_addr_new = NULL;
> +		end_addr_new = 0;
> +#endif /* CONFIG_ENV_EFI_ADDR_REDUND */
> +
> +		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
> +					    flash_addr_new, end_addr_new,
> +					    NULL);

The code above needs some comments.

If one area is the old one and the other the new one, how do you toggle
between the two?

> +		if (ret)
> +			return -ENOENT;
> +
> +		return 0;
> +		}
> +#endif
> +#ifdef CONFIG_ENV_EFI_IS_IN_FAT
> +	case ENVL_FAT: {
> +		ret = env_fat_init_params(ctx,
> +					  CONFIG_ENV_EFI_FAT_INTERFACE,
> +					  CONFIG_ENV_EFI_FAT_DEVICE_AND_PART,
> +					  CONFIG_ENV_EFI_FAT_FILE);
> +
> +		return 0;
> +		}
> +#endif
> +#ifdef CONFIG_ENV_DRV_NONE
> +	case ENVL_NOWHERE:
> +#ifdef CONFIG_ENV_EFI_IS_NOWHERE
> +		/* TODO: what we should do */
> +
> +		return -ENOENT;
> +#else
> +		return -ENOENT;
> +#endif
> +#endif
> +	default:
> +		return -ENOENT;
> +	}
> +}
> +
> +/*
> + * Env context for UEFI variables
> + */
> +U_BOOT_ENV_CONTEXT(efi) = {
> +	.name = "efi",
> +	.htab = &efi_htab,
> +	.env_size = 0x10000, /* TODO: make this configurable */
> +	.drv_init = env_drv_init_efi,
> +};

 From the name of this context it is unclear that this is for the
non-volatile variables. Please, adjust the comment.

> +
> +static int env_ctx_init_efi_volatile(struct env_context *ctx)
> +{
> +	/* Dummy table creation, or hcreate_r()? */
> +	if (!himport_r(ctx->htab, NULL, 0, 0, 0, 0, 0, NULL)) {
> +		debug("%s: Creating entry tables failed (ret=%d)\n", __func__,
> +		      errno);
> +		return errno;
> +	}
> +
> +	env_set_ready(ctx);
> +
> +	return 0;
> +}
> +
> +U_BOOT_ENV_CONTEXT(efi_volatile) = {
> +	.name = "efi_volatile",
> +	.htab = &efi_volatile_htab,
> +	.env_size = 0,
> +	.init = env_ctx_init_efi_volatile,
> +};
> diff --git a/include/env.h b/include/env.h
> index 8045dda9f811..ec241d419a8a 100644
> --- a/include/env.h
> +++ b/include/env.h
> @@ -66,6 +66,9 @@ enum env_redund_flags {
>   };
>
>   #define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)
> +#define ctx_efi ll_entry_get(struct env_context, efi, env_contexts)
> +#define ctx_efi_volatile ll_entry_get(struct env_context, efi_volatile, \
> +				      env_contexts)

I do not like that ll_entry_get() is called again and again in patch
19/19. Please, call ll_entry_get() once for each context and store the
reference in a static variable. Than you do not need any of these 3 defines.

Best regards

Heinrich

>
>   /* Accessor functions */
>   void env_set_ready(struct env_context *ctx);
>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment
  2019-09-05  8:21 ` [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment AKASHI Takahiro
@ 2019-09-05 19:43   ` Heinrich Schuchardt
  2019-09-06  0:41     ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Heinrich Schuchardt @ 2019-09-05 19:43 UTC (permalink / raw)
  To: u-boot

On 9/5/19 10:21 AM, AKASHI Takahiro wrote:
> In this patch, env context fo U-Boot environment is defined to utilize
> new env interfaces, maintaining the compatibility with the existing
> semantics and Kconfig configuration.
>
> In this commit, FAT file system and flash device are only supported
> devices for backing storages, but extending to other devices will be
> quite straightforward.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   env/Kconfig.uboot   | 671 ++++++++++++++++++++++++++++++++++++++++++++
>   env/Makefile        |   2 +-
>   env/env_ctx_uboot.c | 292 +++++++++++++++++++
>   include/env.h       |   3 +
>   4 files changed, 967 insertions(+), 1 deletion(-)
>   create mode 100644 env/Kconfig.uboot
>   create mode 100644 env/env_ctx_uboot.c
>
> diff --git a/env/Kconfig.uboot b/env/Kconfig.uboot
> new file mode 100644
> index 000000000000..e4334f7f2878
> --- /dev/null
> +++ b/env/Kconfig.uboot
> @@ -0,0 +1,671 @@

Only one of the options below should be selected. So, please, use a
'choice' statement. drives/video/Kconfig has an example.

> +config ENV_IS_NOWHERE
> +	bool "U-Boot Environment is not stored"
> +	default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
> +		     !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
> +		     !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
> +		     !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
> +		     !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
> +		     !ENV_IS_IN_UBI
> +	help
> +	  Define this if you don't want to or can't have an environment stored
> +	  on a storage medium. In this case the environment will still exist
> +	  while U-Boot is running, but once U-Boot exits it will not be
> +	  stored. U-Boot will therefore always start up with a default
> +	  environment.
> +
> +config ENV_IS_IN_EEPROM
> +	bool "Environment in EEPROM"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_EEPROM
> +	help
> +	  Use this if you have an EEPROM or similar serial access
> +	  device and a driver for it.
> +
> +	  - CONFIG_ENV_OFFSET:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines specify the offset and size of the
> +	  environment area within the total memory of your EEPROM.
> +
> +	  Note that we consider the length of the address field to
> +	  still be one byte because the extra address bits are hidden
> +	  in the chip address.
> +
> +	  - CONFIG_ENV_EEPROM_IS_ON_I2C
> +	  define this, if you have I2C and SPI activated, and your
> +	  EEPROM, which holds the environment, is on the I2C bus.
> +
> +	  - CONFIG_I2C_ENV_EEPROM_BUS
> +	  if you have an Environment on an EEPROM reached over
> +	  I2C muxes, you can define here, how to reach this
> +	  EEPROM. For example:
> +
> +	  #define CONFIG_I2C_ENV_EEPROM_BUS	  1
> +
> +	  EEPROM which holds the environment, is reached over
> +	  a pca9547 i2c mux with address 0x70, channel 3.
> +
> +config ENV_IS_IN_FAT
> +	bool "Environment is in a FAT filesystem"
> +	depends on !CHAIN_OF_TRUST
> +	default y if ARCH_BCM283X
> +	default y if ARCH_SUNXI && MMC
> +	default y if MMC_OMAP_HS && TI_COMMON_CMD_OPTIONS
> +	select ENV_DRV_FAT
> +	help
> +	  Define this if you want to use the FAT file system for the environment.
> +
> +config ENV_IS_IN_EXT4
> +	bool "Environment is in a EXT4 filesystem"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_EXT4
> +	help
> +	  Define this if you want to use the EXT4 file system for the environment.
> +
> +config ENV_IS_IN_FLASH
> +	bool "Environment in flash memory"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_FLASH
> +	default y if ARCH_CINTEGRATOR
> +	default y if ARCH_INTEGRATOR_CP
> +	default y if M548x || M547x || M5282 || MCF547x_8x
> +	default y if MCF532x || MCF52x2
> +	default y if MPC86xx || MPC83xx
> +	default y if ARCH_MPC8572 || ARCH_MPC8548 || ARCH_MPC8641
> +	default y if SH && !CPU_SH4
> +	help
> +	  Define this if you have a flash device which you want to use for the
> +	  environment.
> +
> +	  a) The environment occupies one whole flash sector, which is
> +	   "embedded" in the text segment with the U-Boot code. This
> +	   happens usually with "bottom boot sector" or "top boot
> +	   sector" type flash chips, which have several smaller
> +	   sectors at the start or the end. For instance, such a
> +	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
> +	   such a case you would place the environment in one of the
> +	   4 kB sectors - with U-Boot code before and after it. With
> +	   "top boot sector" type flash chips, you would put the
> +	   environment in one of the last sectors, leaving a gap
> +	   between U-Boot and the environment.
> +
> +	  CONFIG_ENV_OFFSET:
> +
> +	   Offset of environment data (variable area) to the
> +	   beginning of flash memory; for instance, with bottom boot
> +	   type flash chips the second sector can be used: the offset
> +	   for this sector is given here.
> +
> +	   CONFIG_ENV_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
> +
> +	  CONFIG_ENV_ADDR:
> +
> +	   This is just another way to specify the start address of
> +	   the flash sector containing the environment (instead of
> +	   CONFIG_ENV_OFFSET).
> +
> +	  CONFIG_ENV_SECT_SIZE:
> +
> +	   Size of the sector containing the environment.
> +
> +
> +	  b) Sometimes flash chips have few, equal sized, BIG sectors.
> +	   In such a case you don't want to spend a whole sector for
> +	   the environment.
> +
> +	  CONFIG_ENV_SIZE:
> +
> +	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
> +	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
> +	   of this flash sector for the environment. This saves
> +	   memory for the RAM copy of the environment.
> +
> +	   It may also save flash memory if you decide to use this
> +	   when your environment is "embedded" within U-Boot code,
> +	   since then the remainder of the flash sector could be used
> +	   for U-Boot code. It should be pointed out that this is
> +	   STRONGLY DISCOURAGED from a robustness point of view:
> +	   updating the environment in flash makes it always
> +	   necessary to erase the WHOLE sector. If something goes
> +	   wrong before the contents has been restored from a copy in
> +	   RAM, your target system will be dead.
> +
> +	  CONFIG_ENV_ADDR_REDUND
> +	  CONFIG_ENV_SIZE_REDUND
> +
> +	   These settings describe a second storage area used to hold
> +	   a redundant copy of the environment data, so that there is
> +	   a valid backup copy in case there is a power failure during
> +	   a "saveenv" operation.
> +
> +	  BE CAREFUL! Any changes to the flash layout, and some changes to the
> +	  source code will make it necessary to adapt <board>/u-boot.lds*
> +	  accordingly!
> +
> +config ENV_IS_IN_MMC
> +	bool "Environment in an MMC device"
> +	depends on !CHAIN_OF_TRUST
> +	depends on MMC
> +	select ENV_DRV_MMC
> +	default y if ARCH_EXYNOS4
> +	default y if MX6SX || MX7D
> +	default y if TEGRA30 || TEGRA124
> +	default y if TEGRA_ARMV8_COMMON
> +	help
> +	  Define this if you have an MMC device which you want to use for the
> +	  environment.
> +
> +	  CONFIG_SYS_MMC_ENV_DEV:
> +
> +	  Specifies which MMC device the environment is stored in.
> +
> +	  CONFIG_SYS_MMC_ENV_PART (optional):
> +
> +	  Specifies which MMC partition the environment is stored in. If not
> +	  set, defaults to partition 0, the user area. Common values might be
> +	  1 (first MMC boot partition), 2 (second MMC boot partition).
> +
> +	  CONFIG_ENV_OFFSET:
> +	  CONFIG_ENV_SIZE:
> +
> +	  These two #defines specify the offset and size of the environment
> +	  area within the specified MMC device.
> +
> +	  If offset is positive (the usual case), it is treated as relative to
> +	  the start of the MMC partition. If offset is negative, it is treated
> +	  as relative to the end of the MMC partition. This can be useful if
> +	  your board may be fitted with different MMC devices, which have
> +	  different sizes for the MMC partitions, and you always want the
> +	  environment placed at the very end of the partition, to leave the
> +	  maximum possible space before it, to store other data.
> +
> +	  These two values are in units of bytes, but must be aligned to an
> +	  MMC sector boundary.
> +
> +	  CONFIG_ENV_OFFSET_REDUND (optional):
> +
> +	  Specifies a second storage area, of CONFIG_ENV_SIZE size, used to
> +	  hold a redundant copy of the environment data. This provides a
> +	  valid backup copy in case the other copy is corrupted, e.g. due
> +	  to a power failure during a "saveenv" operation.
> +
> +	  This value may also be positive or negative; this is handled in the
> +	  same way as CONFIG_ENV_OFFSET.
> +
> +	  This value is also in units of bytes, but must also be aligned to
> +	  an MMC sector boundary.
> +
> +	  CONFIG_ENV_SIZE_REDUND (optional):
> +
> +	  This value need not be set, even when CONFIG_ENV_OFFSET_REDUND is
> +	  set. If this value is set, it must be set to the same value as
> +	  CONFIG_ENV_SIZE.
> +
> +config ENV_IS_IN_NAND
> +	bool "Environment in a NAND device"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_NAND
> +	help
> +	  Define this if you have a NAND device which you want to use for the
> +	  environment.
> +
> +	  - CONFIG_ENV_OFFSET:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines specify the offset and size of the environment
> +	  area within the first NAND device.  CONFIG_ENV_OFFSET must be
> +	  aligned to an erase block boundary.
> +
> +	  - CONFIG_ENV_OFFSET_REDUND (optional):
> +
> +	  This setting describes a second storage area of CONFIG_ENV_SIZE
> +	  size used to hold a redundant copy of the environment data, so
> +	  that there is a valid backup copy in case there is a power failure
> +	  during a "saveenv" operation.	 CONFIG_ENV_OFFSET_REDUND must be
> +	  aligned to an erase block boundary.
> +
> +	  - CONFIG_ENV_RANGE (optional):
> +
> +	  Specifies the length of the region in which the environment
> +	  can be written.  This should be a multiple of the NAND device's
> +	  block size.  Specifying a range with more erase blocks than
> +	  are needed to hold CONFIG_ENV_SIZE allows bad blocks within
> +	  the range to be avoided.
> +
> +	  - CONFIG_ENV_OFFSET_OOB (optional):
> +
> +	  Enables support for dynamically retrieving the offset of the
> +	  environment from block zero's out-of-band data.  The
> +	  "nand env.oob" command can be used to record this offset.
> +	  Currently, CONFIG_ENV_OFFSET_REDUND is not supported when
> +	  using CONFIG_ENV_OFFSET_OOB.
> +
> +config ENV_IS_IN_NVRAM
> +	bool "Environment in a non-volatile RAM"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_NVRAM
> +	help
> +	  Define this if you have some non-volatile memory device
> +	  (NVRAM, battery buffered SRAM) which you want to use for the
> +	  environment.
> +
> +	  - CONFIG_ENV_ADDR:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines are used to determine the memory area you
> +	  want to use for environment. It is assumed that this memory
> +	  can just be read and written to, without any special
> +	  provision.
> +
> +config ENV_IS_IN_ONENAND
> +	bool "Environment is in OneNAND"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_ONENAND
> +	help
> +	  Define this if you want to put your local device's environment in
> +	  OneNAND.
> +
> +	  - CONFIG_ENV_ADDR:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines are used to determine the device range you
> +	  want to use for environment. It is assumed that this memory
> +	  can just be read and written to, without any special
> +	  provision.
> +
> +config ENV_IS_IN_REMOTE
> +	bool "Environment is in remote memory space"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_REMOTE
> +	help
> +	  Define this if you have a remote memory space which you
> +	  want to use for the local device's environment.
> +
> +	  - CONFIG_ENV_ADDR:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines specify the address and size of the
> +	  environment area within the remote memory space. The
> +	  local device can get the environment from remote memory
> +	  space by SRIO or PCIE links.
> +
> +config ENV_IS_IN_SPI_FLASH
> +	bool "Environment is in SPI flash"
> +	depends on !CHAIN_OF_TRUST && SPI
> +	select ENV_DRV_SPI_FLASH
> +	default y if ARMADA_XP
> +	default y if INTEL_BAYTRAIL
> +	default y if INTEL_BRASWELL
> +	default y if INTEL_BROADWELL
> +	default y if NORTHBRIDGE_INTEL_IVYBRIDGE
> +	default y if INTEL_QUARK
> +	default y if INTEL_QUEENSBAY
> +	help
> +	  Define this if you have a SPI Flash memory device which you
> +	  want to use for the environment.
> +
> +	  - CONFIG_ENV_OFFSET:
> +	  - CONFIG_ENV_SIZE:
> +
> +	  These two #defines specify the offset and size of the
> +	  environment area within the SPI Flash. CONFIG_ENV_OFFSET must be
> +	  aligned to an erase sector boundary.
> +
> +	  - CONFIG_ENV_SECT_SIZE:
> +
> +	  Define the SPI flash's sector size.
> +
> +	  - CONFIG_ENV_OFFSET_REDUND (optional):
> +
> +	  This setting describes a second storage area of CONFIG_ENV_SIZE
> +	  size used to hold a redundant copy of the environment data, so
> +	  that there is a valid backup copy in case there is a power failure
> +	  during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
> +	  aligned to an erase sector boundary.
> +
> +config USE_ENV_SPI_BUS
> +	bool "SPI flash bus for environment"
> +	depends on ENV_IS_IN_SPI_FLASH
> +	help
> +	  Force the SPI bus for environment.
> +	  If not defined, use CONFIG_SF_DEFAULT_BUS.
> +
> +config ENV_SPI_BUS
> +	int "Value of SPI flash bus for environment"
> +	depends on USE_ENV_SPI_BUS
> +	help
> +	  Value the SPI bus and chip select for environment.
> +
> +config USE_ENV_SPI_CS
> +	bool "SPI flash chip select for environment"
> +	depends on ENV_IS_IN_SPI_FLASH
> +	help
> +	  Force the SPI chip select for environment.
> +	  If not defined, use CONFIG_SF_DEFAULT_CS.
> +
> +config ENV_SPI_CS
> +	int "Value of SPI flash chip select for environment"
> +	depends on USE_ENV_SPI_CS
> +	help
> +	  Value of the SPI chip select for environment.
> +
> +config USE_ENV_SPI_MAX_HZ
> +	bool "SPI flash max frequency for environment"
> +	depends on ENV_IS_IN_SPI_FLASH
> +	help
> +	  Force the SPI max work clock for environment.
> +	  If not defined, use CONFIG_SF_DEFAULT_SPEED.
> +
> +config ENV_SPI_MAX_HZ
> +	int "Value of SPI flash max frequency for environment"
> +	depends on USE_ENV_SPI_MAX_HZ
> +	help
> +	  Value of the SPI max work clock for environment.
> +
> +config USE_ENV_SPI_MODE
> +	bool "SPI flash mode for environment"
> +	depends on ENV_IS_IN_SPI_FLASH
> +	help
> +	  Force the SPI work mode for environment.
> +
> +config ENV_SPI_MODE
> +	hex "Value of SPI flash work mode for environment"
> +	depends on USE_ENV_SPI_MODE
> +	help
> +	  Value of the SPI work mode for environment.
> +	  See include/spi.h for value.
> +
> +config ENV_IS_IN_UBI
> +	bool "Environment in a UBI volume"
> +	depends on !CHAIN_OF_TRUST
> +	select ENV_DRV_UBI
> +	help
> +	  Define this if you have an UBI volume that you want to use for the
> +	  environment.  This has the benefit of wear-leveling the environment
> +	  accesses, which is important on NAND.
> +
> +	  - CONFIG_ENV_UBI_PART:
> +
> +	  Define this to a string that is the mtd partition containing the UBI.
> +
> +	  - CONFIG_ENV_UBI_VOLUME:
> +
> +	  Define this to the name of the volume that you want to store the
> +	  environment in.
> +
> +	  - CONFIG_ENV_UBI_VOLUME_REDUND:
> +
> +	  Define this to the name of another volume to store a second copy of
> +	  the environment in.  This will enable redundant environments in UBI.
> +	  It is assumed that both volumes are in the same MTD partition.
> +
> +config ENV_FAT_INTERFACE
> +	string "Name of the block device for the environment"
> +	depends on ENV_IS_IN_FAT
> +	default "mmc" if ARCH_SUNXI
> +	default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
> +	help
> +	  Define this to a string that is the name of the block device.
> +
> +config ENV_FAT_DEVICE_AND_PART
> +	string "Device and partition for where to store the environment in FAT"
> +	depends on ENV_IS_IN_FAT
> +	default "0:1" if TI_COMMON_CMD_OPTIONS
> +	default "0:auto" if ARCH_ZYNQMP
> +	default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
> +	default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
> +	default "0" if ARCH_AT91
> +	help
> +	  Define this to a string to specify the partition of the device. It can
> +	  be as following:
> +
> +	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> +	       - "D:P": device D partition P. Error occurs if device D has no
> +	                partition table.
> +	       - "D:0": device D.
> +	       - "D" or "D:": device D partition 1 if device D has partition
> +	                      table, or the whole device D if has no partition
> +	                      table.
> +	       - "D:auto": first partition in device D with bootable flag set.
> +	                   If none, first valid partition in device D. If no
> +	                   partition table then means device D.
> +
> +config ENV_FAT_FILE
> +	string "Name of the FAT file to use for the environment"
> +	depends on ENV_IS_IN_FAT
> +	default "uboot.env"
> +	help
> +	  It's a string of the FAT file name. This file use to store the
> +	  environment.
> +
> +config ENV_EXT4_INTERFACE
> +	string "Name of the block device for the environment"
> +	depends on ENV_IS_IN_EXT4
> +	help
> +	  Define this to a string that is the name of the block device.
> +
> +config ENV_EXT4_DEVICE_AND_PART
> +	string "Device and partition for where to store the environment in EXT4"
> +	depends on ENV_IS_IN_EXT4
> +	help
> +	  Define this to a string to specify the partition of the device. It can
> +	  be as following:
> +
> +	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> +	       - "D:P": device D partition P. Error occurs if device D has no
> +	                partition table.
> +	       - "D:0": device D.
> +	       - "D" or "D:": device D partition 1 if device D has partition
> +	                      table, or the whole device D if has no partition
> +	                      table.
> +	       - "D:auto": first partition in device D with bootable flag set.
> +	                   If none, first valid partition in device D. If no
> +	                   partition table then means device D.
> +
> +config ENV_EXT4_FILE
> +	string "Name of the EXT4 file to use for the environment"
> +	depends on ENV_IS_IN_EXT4
> +	default "uboot.env"
> +	help
> +	  It's a string of the EXT4 file name. This file use to store the
> +	  environment (explicit path to the file)
> +
> +if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC || ARCH_STM32MP || ARCH_OMAP2PLUS || ARCH_AT91
> +
> +config ENV_OFFSET
> +	hex "Environment Offset"
> +	depends on (!ENV_IS_IN_UBI && !ENV_IS_NOWHERE) || ARCH_STM32MP
> +	default 0x3f8000 if ARCH_ROCKCHIP
> +	default 0x88000 if ARCH_SUNXI
> +	default 0xE0000 if ARCH_ZYNQ
> +	default 0x1E00000 if ARCH_ZYNQMP
> +	default 0 if ARC
> +	default 0x140000 if ARCH_AT91
> +	default 0x260000 if ARCH_OMAP2PLUS
> +	help
> +	  Offset from the start of the device (or partition)
> +
> +config ENV_SIZE
> +	hex "Environment Size"
> +	default 0x40000 if ENV_IS_IN_SPI_FLASH && ARCH_ZYNQMP
> +	default 0x20000 if ARCH_SUNXI || ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
> +	default 0x8000 if ARCH_ROCKCHIP || ARCH_ZYNQMP || ARCH_VERSAL
> +	default 0x4000 if ARC
> +	default 0x1f000
> +	help
> +	  Size of the environment storage area
> +
> +config ENV_SECT_SIZE
> +	hex "Environment Sector-Size"
> +	depends on (!ENV_IS_NOWHERE && (ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_OMAP2PLUS || ARCH_AT91) )|| ARCH_STM32MP
> +	default 0x40000 if ARCH_ZYNQMP
> +	default 0x20000 if ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
> +	help
> +	  Size of the sector containing the environment.
> +
> +config ENV_UBI_PART
> +	string "UBI partition name"
> +	depends on ENV_IS_IN_UBI
> +	help
> +	  MTD partition containing the UBI device
> +
> +config ENV_UBI_VOLUME
> +	string "UBI volume name"
> +	depends on ENV_IS_IN_UBI
> +	help
> +	  Name of the volume that you want to store the environment in.
> +
> +config ENV_UBI_VOLUME_REDUND
> +	string "UBI redundant volume name"
> +	depends on ENV_IS_IN_UBI
> +	help
> +	  Name of the redundant volume that you want to store the environment in.
> +
> +config ENV_UBI_VID_OFFSET
> +	int "ubi environment VID offset"
> +	depends on ENV_IS_IN_UBI
> +	default 0
> +	help
> +	  UBI VID offset for environment. If 0, no custom VID offset is used.
> +
> +endif
> +
> +config USE_DEFAULT_ENV_FILE
> +	bool "Create default environment from file"
> +	help
> +	  Normally, the default environment is automatically generated
> +	  based on the settings of various CONFIG_* options, as well
> +	  as the CONFIG_EXTRA_ENV_SETTINGS. By selecting this option,
> +	  you can instead define the entire default environment in an
> +	  external file.
> +
> +config DEFAULT_ENV_FILE
> +	string "Path to default environment file"
> +	depends on USE_DEFAULT_ENV_FILE
> +	help
> +	  The path containing the default environment. The format is
> +	  the same as accepted by the mkenvimage tool: lines
> +	  containing key=value pairs, blank lines and lines beginning
> +	  with # are ignored.
> +
> +config ENV_VARS_UBOOT_RUNTIME_CONFIG
> +	bool "Add run-time information to the environment"
> +	help
> +	  Enable this in order to add variables describing certain
> +	  run-time determined information about the hardware to the
> +	  environment.  These will be named board_name, board_rev.
> +
> +if SPL_ENV_SUPPORT
> +config SPL_ENV_IS_NOWHERE
> +	bool "SPL Environment is not stored"
> +	default y if ENV_IS_NOWHERE
> +	help
> +	  Similar to ENV_IS_NOWHERE, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_MMC
> +	bool "SPL Environment in an MMC device"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_MMC
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_MMC, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_FAT
> +	bool "SPL Environment is in a FAT filesystem"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_FAT
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_FAT, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_EXT4
> +	bool "SPL Environment is in a EXT4 filesystem"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_EXT4
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_EXT4, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_NAND
> +	bool "SPL Environment in a NAND device"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_NAND
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_NAND, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_SPI_FLASH
> +	bool "SPL Environment is in SPI flash"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_SPI_FLASH
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_SPI_FLASH, used for SPL environment.
> +
> +config SPL_ENV_IS_IN_FLASH
> +	bool "SPL Environment in flash memory"
> +	depends on !SPL_ENV_IS_NOWHERE
> +	select ENV_DRV_FLASH
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_FLASH, used for SPL environment.
> +
> +endif
> +
> +if TPL_ENV_SUPPORT
> +
> +config TPL_ENV_IS_NOWHERE
> +	bool "TPL Environment is not stored"
> +	default y if ENV_IS_NOWHERE
> +	help
> +	  Similar to ENV_IS_NOWHERE, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_MMC
> +	bool "TPL Environment in an MMC device"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_MMC
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_MMC, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_FAT
> +	bool "TPL Environment is in a FAT filesystem"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_FAT
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_FAT, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_EXT4
> +	bool "TPL Environment is in a EXT4 filesystem"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_EXT4
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_EXT4, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_NAND
> +	bool "TPL Environment in a NAND device"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_NAND
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_NAND, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_SPI_FLASH
> +	bool "TPL Environment is in SPI flash"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_SPI_FLASH
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_SPI_FLASH, used for TPL environment.
> +
> +config TPL_ENV_IS_IN_FLASH
> +	bool "TPL Environment in flash memory"
> +	depends on !TPL_ENV_IS_NOWHERE
> +	select ENV_DRV_FLASH
> +	default y
> +	help
> +	  Similar to ENV_IS_IN_FLASH, used for TPL environment.
> +
> +endif
> diff --git a/env/Makefile b/env/Makefile
> index ee37cc822024..0168eb47f00d 100644
> --- a/env/Makefile
> +++ b/env/Makefile
> @@ -3,7 +3,7 @@
>   # (C) Copyright 2004-2006
>   # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
>
> -obj-y += common.o env.o
> +obj-y += common.o env.o env_ctx_uboot.o
>
>   ifndef CONFIG_SPL_BUILD
>   obj-y += attr.o
> diff --git a/env/env_ctx_uboot.c b/env/env_ctx_uboot.c
> new file mode 100644
> index 000000000000..5ca645599347
> --- /dev/null
> +++ b/env/env_ctx_uboot.c
> @@ -0,0 +1,292 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2019 Linaro Limited
> + *		Author: AKASHI Takahiro
> + */
> +
> +#include <common.h>
> +#include <env_default.h>
> +#include <env_flags.h>
> +#include <env_internal.h>
> +#include <search.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#if !defined(ENV_IS_IN_DEVICE) && !defined(CONFIG_ENV_IS_NOWHERE)
> +# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
> +NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
> +#endif
> +
> +struct hsearch_data env_htab = {
> +#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> +	/* defined in flags.c, only compile with ENV_SUPPORT */
> +	.change_ok = env_flags_validate,
> +#endif
> +};
> +
> +/*
> + * NOTE: extracted from env/env.c
> + */
> +static bool env_has_inited_uboot(struct env_context *ctx,
> +				 enum env_location location)
> +{
> +	return gd->env_has_init & BIT(location);
> +}
> +
> +static void env_set_inited_uboot(struct env_context *ctx,
> +				 enum env_location location)
> +{
> +	gd->env_has_init |= BIT(location);
> +}
> +
> +static int env_get_load_prio_uboot(struct env_context *ctx)
> +{
> +	return gd->env_load_prio;
> +}
> +
> +static enum env_location env_get_location_uboot(struct env_context *ctx,
> +						enum env_operation op, int prio)
> +{
> +	gd->env_load_prio = prio;
> +
> +	return env_locations[prio];
> +}
> +
> +int env_get_char_default_uboot(struct env_context *ctx, int index)
> +{
> +	return default_environment[index];
> +}
> +
> +int env_get_char_spec_uboot(struct env_context *ctx, int index)
> +{
> +	return *(uchar *)(gd->env_addr + index);
> +}
> +
> +static int env_init_uboot(struct env_context *ctx)
> +{
> +	struct env_driver *drv;
> +	int ret = -ENOENT;
> +	int prio;
> +
> +	for (prio = 0; (drv = env_driver_lookup(ctx, ENVOP_INIT, prio));
> +	     prio++) {
> +		if (!drv->init || !(ret = drv->init(ctx)))
> +			gd->env_has_init |= BIT(drv->location);
> +
> +		debug("%s: Environment %s init done (ret=%d)\n", __func__,
> +		      drv->name, ret);
> +	}
> +
> +	if (!prio)
> +		return -ENODEV;
> +
> +	if (ret == -ENOENT) {
> +		gd->env_addr = (ulong)&default_environment[0];
> +		gd->env_valid = ENV_VALID;
> +
> +		return 0;
> +	}
> +
> +	return ret;
> +}
> +
> +static int env_drv_init_uboot(struct env_context *ctx, enum env_location loc)
> +{
> +	__maybe_unused int ret;
> +
> +	switch (loc) {
> +#ifdef CONFIG_ENV_IS_IN_FLASH
> +	case ENVL_FLASH: {
> +		env_hdr_t *env_ptr;
> +		env_hdr_t *flash_addr;
> +		ulong end_addr;
> +		env_hdr_t *flash_addr_new;
> +		ulong end_addr_new;
> +
> +#ifdef ENV_IS_EMBEDDED
> +		env_ptr = &embedded_environment;
> +#else /* ! ENV_IS_EMBEDDED */
> +		env_ptr = (env_hdr_t *)CONFIG_ENV_ADDR;
> +#endif /* ENV_IS_EMBEDDED */
> +		flash_addr = (env_hdr_t *)CONFIG_ENV_ADDR;
> +
> +/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
> +		end_addr = CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
> +
> +#ifdef CONFIG_ENV_ADDR_REDUND
> +		flash_addr_new = (env_hdr_t *)CONFIG_ENV_ADDR_REDUND;
> +/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
> +		end_addr_new = CONFIG_ENV_ADDR_REDUND
> +					+ CONFIG_ENV_SECT_SIZE - 1;
> +#else
> +		flash_addr_new = NULL;
> +		end_addr_new = 0;
> +#endif /* CONFIG_ENV_ADDR_REDUND */
> +
> +		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
> +					    flash_addr_new, end_addr_new,
> +					    (ulong)&default_environment[0]);
> +		if (ret)
> +			return -ENOENT;
> +
> +		return 0;
> +		}
> +#endif
> +#ifdef CONFIG_ENV_IS_IN_FAT
> +	case ENVL_FAT: {
> +		ret = env_fat_init_params(ctx,
> +					  CONFIG_ENV_FAT_INTERFACE,
> +					  CONFIG_ENV_FAT_DEVICE_AND_PART,
> +					  CONFIG_ENV_FAT_FILE);
> +
> +		return -ENOENT;
> +		}
> +#endif
> +#ifdef CONFIG_ENV_DRV_NONE
> +	case ENVL_NOWHERE:
> +#ifdef CONFIG_ENV_IS_NOWHERE
> +		gd->env_addr = (ulong)&default_environment[0];
> +		gd->env_valid = ENV_INVALID;
> +
> +		return 0;
> +#else
> +		return -ENOENT;
> +#endif
> +#endif
> +	default:
> +		return -ENOENT;
> +	}
> +}
> +
> +/*
> + * NOTE: extracted from env/common.c
> + */
> +void env_set_ready_uboot(struct env_context *ctx)
> +{
> +	gd->flags |= GD_FLG_ENV_READY;
> +}
> +
> +bool env_is_ready_uboot(struct env_context *ctx)
> +{
> +	return (gd->flags & GD_FLG_ENV_READY);
> +}
> +
> +void env_set_valid_uboot(struct env_context *ctx, enum env_valid valid)
> +{
> +	gd->env_valid = valid;
> +}
> +
> +enum env_valid env_get_valid_uboot(struct env_context *ctx)
> +{
> +	return gd->env_valid;
> +}
> +
> +void env_set_addr_uboot(struct env_context *ctx, ulong env_addr)
> +{
> +	gd->env_addr = env_addr;
> +}
> +
> +ulong env_get_addr_uboot(struct env_context *ctx)
> +{
> +	return gd->env_addr;
> +}
> +
> +/*
> + * Look up the variable from the default environment
> + */
> +char *env_get_default_uboot(struct env_context *ctx, const char *name)
> +{
> +	char *ret_val;
> +	unsigned long really_valid = gd->env_valid;
> +	unsigned long real_gd_flags = gd->flags;
> +
> +	/* Pretend that the image is bad. */
> +	gd->flags &= ~GD_FLG_ENV_READY;
> +	gd->env_valid = ENV_INVALID;
> +	ret_val = env_get(ctx, name);
> +	gd->env_valid = really_valid;
> +	gd->flags = real_gd_flags;
> +	return ret_val;
> +}
> +
> +void env_set_default_env_uboot(struct env_context *ctx, const char *s,
> +			       int flags)
> +{
> +	if (sizeof(default_environment) > ctx->env_size) {
> +		puts("*** Error - default environment is too large\n\n");
> +		return;
> +	}
> +
> +	if (s) {
> +		if ((flags & H_INTERACTIVE) == 0)
> +			printf("*** Warning - %s, using default environment\n\n", s);
> +		else
> +			puts(s);
> +	} else {
> +		debug("Using default environment\n");
> +	}
> +
> +	env_htab.ctx = ctx;
> +	if (himport_r(&env_htab, (char *)default_environment,
> +		      sizeof(default_environment), '\0', flags, 0,
> +		      0, NULL) == 0)
> +		pr_err("## Error: Environment import failed: errno = %d\n",
> +		       errno);
> +
> +	gd->flags |= GD_FLG_ENV_READY;
> +	gd->flags |= GD_FLG_ENV_DEFAULT;
> +}
> +
> +/* [re]set individual variables to their value in the default environment */
> +int env_set_default_vars_uboot(struct env_context *ctx, int nvars,
> +			       char * const vars[], int flags)
> +{
> +	/*
> +	 * Special use-case: import from default environment
> +	 * (and use \0 as a separator)
> +	 */
> +	flags |= H_NOCLEAR;
> +	env_htab.ctx = ctx;
> +	return himport_r(&env_htab, (const char *)default_environment,
> +				sizeof(default_environment), '\0',
> +				flags, 0, nvars, vars);
> +}
> +
> +void env_post_relocate_uboot(struct env_context *ctx)
> +{
> +	if (gd->env_valid == ENV_INVALID) {
> +#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
> +		/* Environment not changeable */
> +		env_set_default(ctx, NULL, 0);
> +#else
> +		bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
> +		env_set_default(ctx, "bad CRC", 0);
> +#endif
> +	} else {
> +		env_load(ctx);
> +	}
> +}
> +
> +U_BOOT_ENV_CONTEXT(uboot) = {
> +	.name = "uboot",
> +	.htab = &env_htab,
> +	.env_size = ENV_SIZE,
> +	.has_inited = env_has_inited_uboot,
> +	.set_inited = env_set_inited_uboot,
> +	.get_load_prio = env_get_load_prio_uboot,
> +	.get_location = env_get_location_uboot,
> +	.get_char_default = env_get_char_default_uboot,
> +	.get_char_spec = env_get_char_spec_uboot,
> +	.init = env_init_uboot,
> +	.drv_init = env_drv_init_uboot,
> +	.get_default = env_get_default_uboot,
> +	.set_default = env_set_default_env_uboot,
> +	.set_default_vars = env_set_default_vars_uboot,
> +	.set_ready = env_set_ready_uboot,
> +	.is_ready = env_is_ready_uboot,
> +	.set_valid = env_set_valid_uboot,
> +	.get_valid = env_get_valid_uboot,
> +	.set_addr = env_set_addr_uboot,
> +	.get_addr = env_get_addr_uboot,
> +	.post_relocate = env_post_relocate_uboot,
> +};
> diff --git a/include/env.h b/include/env.h
> index 203605e5e778..26abae2a5c42 100644
> --- a/include/env.h
> +++ b/include/env.h
> @@ -9,6 +9,7 @@
>   #ifndef __ENV_H
>   #define __ENV_H
>
> +#include <linker_lists.h>
>   #include <stdbool.h>
>   #include <linux/types.h>
>
> @@ -63,6 +64,8 @@ enum env_redund_flags {
>   	ENV_REDUND_ACTIVE = 1,
>   };
>
> +#define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)

Please, do not call ll_entry_get(,uboot,) multiple times. Just call it
once during initialization and store the reference in a global variable.
In this case you do not need the macro.

Best regards

Heinrich

> +
>   /* Accessor functions */
>   void env_set_ready(struct env_context *ctx);
>   bool env_is_ready(struct env_context *ctx);
>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 09/19] board: converted with new env interfaces
  2019-09-05 12:02   ` Lukasz Majewski
@ 2019-09-06  0:34     ` AKASHI Takahiro
  0 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-06  0:34 UTC (permalink / raw)
  To: u-boot

On Thu, Sep 05, 2019 at 02:02:47PM +0200, Lukasz Majewski wrote:
> On Thu,  5 Sep 2019 17:21:23 +0900
> AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:
> 
> > env_xxx(...) -> env_xxx(ctx_uboot, ...)
> 
> To be honest this doesn't explain much about the issue this patch tries
> to fix (however, on the mailing list only this particular patch is
> present).
> 
> 
> Could you provide more verbose description?

I hope that the following cover letter explains enough:
https://lists.denx.de/pipermail/u-boot/2019-September/382854.html

Thanks,
-Takahiro Akashi

> 
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  board/Arcturus/ucp1020/cmd_arc.c              | 40 ++++++------
> >  board/Arcturus/ucp1020/ucp1020.c              | 16 ++---
> >  board/BuR/brppt1/board.c                      |  4 +-
> >  board/BuR/brxre1/board.c                      |  9 +--
> >  board/BuR/common/br_resetc.c                  |  2 +-
> >  board/BuR/common/common.c                     | 47 +++++++-------
> >  board/BuS/eb_cpu5282/eb_cpu5282.c             |  8 +--
> >  board/CZ.NIC/turris_mox/turris_mox.c          |  4 +-
> >  board/CZ.NIC/turris_omnia/turris_omnia.c      |  6 +-
> >  board/CarMediaLab/flea3/flea3.c               |  2 +-
> >  board/LaCie/net2big_v2/net2big_v2.c           |  2 +-
> >  board/LaCie/netspace_v2/netspace_v2.c         |  2 +-
> >  board/Synology/ds414/cmd_syno.c               |  6 +-
> >  board/alliedtelesis/x530/x530.c               |  2 +-
> >  board/amazon/kc1/kc1.c                        |  4 +-
> >  board/amlogic/p200/p200.c                     |  4 +-
> >  board/amlogic/p201/p201.c                     |  4 +-
> >  board/amlogic/p212/p212.c                     |  4 +-
> >  board/amlogic/q200/q200.c                     |  4 +-
> >  board/aristainetos/aristainetos-v2.c          |  8 +--
> >  board/armltd/integrator/integrator.c          |  2 +-
> >  board/atmel/common/board.c                    |  4 +-
> >  board/atmel/common/mac_eeprom.c               |  2 +-
> >  board/atmel/sama5d3xek/sama5d3xek.c           |  2 +-
> >  board/bachmann/ot1200/ot1200.c                |  4 +-
> >  board/birdland/bav335x/board.c                |  8 +--
> >  board/bluegiga/apx4devkit/apx4devkit.c        |  5 +-
> >  board/bluewater/gurnard/gurnard.c             |  6 +-
> >  board/bosch/shc/board.c                       |  2 +-
> >  board/boundary/nitrogen6x/nitrogen6x.c        | 14 ++---
> >  board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |  2 +-
> >  board/broadcom/bcm28155_ap/bcm28155_ap.c      |  2 +-
> >  board/broadcom/bcmstb/bcmstb.c                |  2 +-
> >  board/buffalo/lsxl/lsxl.c                     |  2 +-
> >  board/cadence/xtfpga/xtfpga.c                 |  4 +-
> >  board/ccv/xpress/xpress.c                     |  2 +-
> >  board/compulab/cl-som-imx7/cl-som-imx7.c      |  2 +-
> >  board/compulab/cm_fx6/cm_fx6.c                | 10 +--
> >  board/compulab/common/omap3_display.c         |  4 +-
> >  board/congatec/cgtqmx6eval/cgtqmx6eval.c      |  8 +--
> >  board/cssi/MCR3000/MCR3000.c                  |  2 +-
> >  board/davinci/da8xxevm/da850evm.c             |  2 +-
> >  board/davinci/da8xxevm/omapl138_lcdk.c        |  6 +-
> >  board/dhelectronics/dh_imx6/dh_imx6.c         |  2 +-
> >  board/eets/pdu001/board.c                     |  8 +--
> >  board/el/el6x/el6x.c                          |  2 +-
> >  board/emulation/qemu-riscv/qemu-riscv.c       |  2 +-
> >  board/engicam/common/board.c                  | 32 +++++-----
> >  board/esd/meesc/meesc.c                       |  6 +-
> >  board/freescale/b4860qds/b4860qds.c           |  5 +-
> >  board/freescale/common/cmd_esbc_validate.c    |  2 +-
> >  board/freescale/common/fsl_chain_of_trust.c   |  6 +-
> >  board/freescale/common/sys_eeprom.c           |  4 +-
> >  board/freescale/common/vid.c                  |  4 +-
> >  board/freescale/imx8mq_evk/imx8mq_evk.c       |  4 +-
> >  board/freescale/imx8qm_mek/imx8qm_mek.c       |  4 +-
> >  board/freescale/imx8qxp_mek/imx8qxp_mek.c     |  4 +-
> >  board/freescale/ls1088a/eth_ls1088aqds.c      |  4 +-
> >  board/freescale/ls1088a/ls1088a.c             |  2 +-
> >  board/freescale/ls2080aqds/eth.c              |  6 +-
> >  board/freescale/ls2080aqds/ls2080aqds.c       |  2 +-
> >  board/freescale/ls2080ardb/ls2080ardb.c       |  6 +-
> >  board/freescale/lx2160a/eth_lx2160aqds.c      |  2 +-
> >  board/freescale/mpc8323erdb/mpc8323erdb.c     |  3 +-
> >  board/freescale/mpc837xemds/pci.c             |  2 +-
> >  board/freescale/mpc837xerdb/mpc837xerdb.c     |  2 +-
> >  board/freescale/mx51evk/mx51evk_video.c       |  2 +-
> >  board/freescale/mx53loco/mx53loco.c           |  4 +-
> >  board/freescale/mx53loco/mx53loco_video.c     |  2 +-
> >  board/freescale/mx6sabreauto/mx6sabreauto.c   |  8 +--
> >  board/freescale/mx6sabresd/mx6sabresd.c       |  8 +--
> >  board/freescale/mx6sxsabresd/mx6sxsabresd.c   |  2 +-
> >  .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |  6 +-
> >  board/freescale/mx6ullevk/mx6ullevk.c         |  4 +-
> >  board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |  2 +-
> >  board/freescale/qemu-ppce500/qemu-ppce500.c   |  4 +-
> >  board/freescale/t4qds/t4240qds.c              |  2 +-
> >  board/gardena/smart-gateway-at91sam/board.c   |  2 +-
> >  board/gardena/smart-gateway-mt7688/board.c    | 16 ++---
> >  board/gateworks/gw_ventana/common.c           |  2 +-
> >  board/gateworks/gw_ventana/gw_ventana.c       | 61
> > ++++++++++--------- board/gateworks/gw_ventana/gw_ventana_spl.c   |
> > 4 +- board/gdsys/a38x/keyprogram.c                 |  4 +-
> >  board/gdsys/mpc8308/gazerbeam.c               |  4 +-
> >  board/gdsys/mpc8308/hrcon.c                   |  2 +-
> >  board/gdsys/mpc8308/strider.c                 |  2 +-
> >  board/gdsys/p1022/controlcenterd-id.c         | 10 +--
> >  board/gdsys/p1022/controlcenterd.c            |  2 +-
> >  board/ge/bx50v3/bx50v3.c                      | 13 ++--
> >  board/ge/common/ge_common.c                   |  4 +-
> >  board/ge/mx53ppd/mx53ppd.c                    |  2 +-
> >  board/grinn/chiliboard/board.c                |  4 +-
> >  board/grinn/liteboard/board.c                 |  6 +-
> >  board/highbank/highbank.c                     |  9 +--
> >  board/hisilicon/poplar/poplar.c               |  2 +-
> >  board/imgtec/ci20/ci20.c                      |  6 +-
> >  board/intel/edison/edison.c                   | 14 ++---
> >  board/isee/igep003x/board.c                   |  6 +-
> >  board/isee/igep00x0/igep00x0.c                |  4 +-
> >  board/k+p/kp_imx53/kp_id_rev.c                | 20 +++---
> >  board/k+p/kp_imx53/kp_imx53.c                 |  4 +-
> >  board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |  4 +-
> >  board/keymile/common/common.c                 | 26 ++++----
> >  board/keymile/common/ivm.c                    |  8 +--
> >  board/keymile/km83xx/km83xx.c                 |  2 +-
> >  board/keymile/km_arm/km_arm.c                 |  6 +-
> >  board/keymile/kmp204x/kmp204x.c               |  4 +-
> >  board/kosagi/novena/novena.c                  |  2 +-
> >  board/laird/wb50n/wb50n.c                     |  2 +-
> >  board/lg/sniper/sniper.c                      |  4 +-
> >  board/liebherr/display5/spl.c                 |  4 +-
> >  board/liebherr/mccmon6/mccmon6.c              |  6 +-
> >  board/logicpd/imx6/imx6logic.c                |  8 +--
> >  board/menlo/m53menlo/m53menlo.c               |  2 +-
> >  board/micronas/vct/vct.c                      |  2 +-
> >  board/nokia/rx51/rx51.c                       | 10 +--
> >  board/overo/overo.c                           | 45 +++++++-------
> >  board/phytec/pcm052/pcm052.c                  |  4 +-
> >  board/phytec/pfla02/pfla02.c                  |  2 +-
> >  .../dragonboard410c/dragonboard410c.c         |  6 +-
> >  .../dragonboard820c/dragonboard820c.c         |  2 +-
> >  board/raspberrypi/rpi/rpi.c                   | 26 ++++----
> >  board/renesas/alt/alt.c                       |  3 +-
> >  board/renesas/gose/gose.c                     |  3 +-
> >  board/renesas/koelsch/koelsch.c               |  3 +-
> >  board/renesas/lager/lager.c                   |  3 +-
> >  board/renesas/porter/porter.c                 |  3 +-
> >  board/renesas/sh7752evb/sh7752evb.c           |  4 +-
> >  board/renesas/sh7753evb/sh7753evb.c           |  4 +-
> >  board/renesas/sh7757lcr/sh7757lcr.c           |  6 +-
> >  board/renesas/silk/silk.c                     |  3 +-
> >  board/renesas/stout/stout.c                   |  3 +-
> >  board/rockchip/kylin_rk3036/kylin_rk3036.c    |  2 +-
> >  board/samsung/common/exynos5-dt.c             |  2 +-
> >  board/samsung/common/misc.c                   | 14 ++---
> >  board/samsung/odroid/odroid.c                 |  2 +-
> >  board/samsung/trats/trats.c                   |  2 +-
> >  board/samsung/universal_c210/universal.c      |  2 +-
> >  board/samtec/vining_fpga/socfpga.c            | 16 ++---
> >  board/siemens/common/board.c                  |  4 +-
> >  board/siemens/draco/board.c                   |  6 +-
> >  board/siemens/pxm2/board.c                    |  4 +-
> >  board/siemens/rut/board.c                     |  2 +-
> >  board/siemens/taurus/taurus.c                 | 50 +++++++--------
> >  board/socrates/socrates.c                     |  4 +-
> >  board/softing/vining_2000/vining_2000.c       |  8 +--
> >  board/solidrun/mx6cuboxi/mx6cuboxi.c          | 16 ++---
> >  .../stm32f429-discovery/stm32f429-discovery.c |  4 +-
> >  .../stm32f429-evaluation.c                    |  4 +-
> >  .../stm32f469-discovery/stm32f469-discovery.c |  4 +-
> >  board/st/stm32mp1/stm32mp1.c                  | 11 ++--
> >  board/sunxi/board.c                           | 25 ++++----
> >  board/synopsys/hsdk/env-lib.c                 | 11 ++--
> >  board/synopsys/hsdk/hsdk.c                    |  6 +-
> >  board/syteco/zmx25/zmx25.c                    |  8 ++-
> >  board/tcl/sl50/board.c                        |  6 +-
> >  .../puma_rk3399/puma-rk3399.c                 |  8 +--
> >  board/ti/am335x/board.c                       | 18 +++---
> >  board/ti/am43xx/board.c                       |  6 +-
> >  board/ti/am57xx/board.c                       | 14 ++---
> >  board/ti/beagle/beagle.c                      | 43 ++++++-------
> >  board/ti/common/board_detect.c                | 14 ++---
> >  board/ti/dra7xx/evm.c                         | 12 ++--
> >  board/ti/evm/evm.c                            |  2 +-
> >  board/ti/ks2_evm/board.c                      | 10 +--
> >  board/ti/ks2_evm/board_k2g.c                  |  8 +--
> >  board/ti/panda/panda.c                        |  4 +-
> >  board/toradex/apalis-imx8/apalis-imx8.c       |  4 +-
> >  board/toradex/apalis_imx6/apalis_imx6.c       | 12 ++--
> >  .../toradex/colibri-imx6ull/colibri-imx6ull.c |  6 +-
> >  board/toradex/colibri-imx8x/colibri-imx8x.c   |  4 +-
> >  board/toradex/colibri_imx6/colibri_imx6.c     |  8 +--
> >  board/toradex/colibri_vf/colibri_vf.c         |  2 +-
> >  board/toradex/common/tdx-cfg-block.c          |  2 +-
> >  board/toradex/common/tdx-common.c             |  2 +-
> >  board/tqc/tqma6/tqma6.c                       |  2 +-
> >  board/udoo/neo/neo.c                          |  2 +-
> >  board/udoo/udoo.c                             |  4 +-
> >  board/varisys/common/sys_eeprom.c             |  6 +-
> >  board/vscom/baltos/board.c                    |  6 +-
> >  board/wandboard/wandboard.c                   | 12 ++--
> >  board/warp7/warp7.c                           |  6 +-
> >  .../work_92105/work_92105_display.c           |  2 +-
> >  board/xes/common/board.c                      |  6 +-
> >  board/xilinx/zynq/board.c                     | 16 ++---
> >  board/xilinx/zynqmp/cmds.c                    |  2 +-
> >  board/xilinx/zynqmp/zynqmp.c                  | 24 ++++----
> >  187 files changed, 677 insertions(+), 649 deletions(-)
> > 
> > diff --git a/board/Arcturus/ucp1020/cmd_arc.c
> > b/board/Arcturus/ucp1020/cmd_arc.c index 2e8477ed3b7a..fbe1f2dba123
> > 100644 --- a/board/Arcturus/ucp1020/cmd_arc.c
> > +++ b/board/Arcturus/ucp1020/cmd_arc.c
> > @@ -252,8 +252,8 @@ static int read_arc_info(void)
> >  static int do_get_arc_info(void)
> >  {
> >  	int l = read_arc_info();
> > -	char *oldserial = env_get("SERIAL");
> > -	char *oldversion = env_get("VERSION");
> > +	char *oldserial = env_get(ctx_uboot, "SERIAL");
> > +	char *oldversion = env_get(ctx_uboot, "VERSION");
> >  
> >  	if (oldversion != NULL)
> >  		if (strcmp(oldversion, U_BOOT_VERSION) != 0)
> > @@ -269,13 +269,13 @@ static int do_get_arc_info(void)
> >  		printf("<not found>\n");
> >  	} else {
> >  		printf("%s\n", smac[0]);
> > -		env_set("SERIAL", smac[0]);
> > +		env_set(ctx_uboot, "SERIAL", smac[0]);
> >  	}
> >  
> >  	if (strcmp(smac[1], "00:00:00:00:00:00") == 0) {
> > -		env_set("ethaddr", NULL);
> > -		env_set("eth1addr", NULL);
> > -		env_set("eth2addr", NULL);
> > +		env_set(ctx_uboot, "ethaddr", NULL);
> > +		env_set(ctx_uboot, "eth1addr", NULL);
> > +		env_set(ctx_uboot, "eth2addr", NULL);
> >  		goto done;
> >  	}
> >  
> > @@ -283,13 +283,13 @@ static int do_get_arc_info(void)
> >  	if (smac[1][0] == EMPY_CHAR) {
> >  		printf("<not found>\n");
> >  	} else {
> > -		char *ret = env_get("ethaddr");
> > +		char *ret = env_get(ctx_uboot, "ethaddr");
> >  
> >  		if (ret == NULL) {
> > -			env_set("ethaddr", smac[1]);
> > +			env_set(ctx_uboot, "ethaddr", smac[1]);
> >  			printf("%s\n", smac[1]);
> >  		} else if (strcmp(ret, __stringify(CONFIG_ETHADDR))
> > == 0) {
> > -			env_set("ethaddr", smac[1]);
> > +			env_set(ctx_uboot, "ethaddr", smac[1]);
> >  			printf("%s (factory)\n", smac[1]);
> >  		} else {
> >  			printf("%s\n", ret);
> > @@ -297,8 +297,8 @@ static int do_get_arc_info(void)
> >  	}
> >  
> >  	if (strcmp(smac[2], "00:00:00:00:00:00") == 0) {
> > -		env_set("eth1addr", NULL);
> > -		env_set("eth2addr", NULL);
> > +		env_set(ctx_uboot, "eth1addr", NULL);
> > +		env_set(ctx_uboot, "eth2addr", NULL);
> >  		goto done;
> >  	}
> >  
> > @@ -306,13 +306,13 @@ static int do_get_arc_info(void)
> >  	if (smac[2][0] == EMPY_CHAR) {
> >  		printf("<not found>\n");
> >  	} else {
> > -		char *ret = env_get("eth1addr");
> > +		char *ret = env_get(ctx_uboot, "eth1addr");
> >  
> >  		if (ret == NULL) {
> > -			env_set("ethaddr", smac[2]);
> > +			env_set(ctx_uboot, "ethaddr", smac[2]);
> >  			printf("%s\n", smac[2]);
> >  		} else if (strcmp(ret, __stringify(CONFIG_ETH1ADDR))
> > == 0) {
> > -			env_set("eth1addr", smac[2]);
> > +			env_set(ctx_uboot, "eth1addr", smac[2]);
> >  			printf("%s (factory)\n", smac[2]);
> >  		} else {
> >  			printf("%s\n", ret);
> > @@ -320,7 +320,7 @@ static int do_get_arc_info(void)
> >  	}
> >  
> >  	if (strcmp(smac[3], "00:00:00:00:00:00") == 0) {
> > -		env_set("eth2addr", NULL);
> > +		env_set(ctx_uboot, "eth2addr", NULL);
> >  		goto done;
> >  	}
> >  
> > @@ -328,13 +328,13 @@ static int do_get_arc_info(void)
> >  	if (smac[3][0] == EMPY_CHAR) {
> >  		printf("<not found>\n");
> >  	} else {
> > -		char *ret = env_get("eth2addr");
> > +		char *ret = env_get(ctx_uboot, "eth2addr");
> >  
> >  		if (ret == NULL) {
> > -			env_set("ethaddr", smac[3]);
> > +			env_set(ctx_uboot, "ethaddr", smac[3]);
> >  			printf("%s\n", smac[3]);
> >  		} else if (strcmp(ret, __stringify(CONFIG_ETH2ADDR))
> > == 0) {
> > -			env_set("eth2addr", smac[3]);
> > +			env_set(ctx_uboot, "eth2addr", smac[3]);
> >  			printf("%s (factory)\n", smac[3]);
> >  		} else {
> >  			printf("%s\n", ret);
> > @@ -343,8 +343,8 @@ static int do_get_arc_info(void)
> >  done:
> >  	if (oldserial == NULL || oldversion == NULL) {
> >  		if (oldversion == NULL)
> > -			env_set("VERSION", U_BOOT_VERSION);
> > -		env_save();
> > +			env_set(ctx_uboot, "VERSION",
> > U_BOOT_VERSION);
> > +		env_save(ctx_uboot);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/Arcturus/ucp1020/ucp1020.c
> > b/board/Arcturus/ucp1020/ucp1020.c index 6a880c97bcb7..1aa7f96b5e1c
> > 100644 --- a/board/Arcturus/ucp1020/ucp1020.c
> > +++ b/board/Arcturus/ucp1020/ucp1020.c
> > @@ -64,7 +64,7 @@ void board_gpio_init(void)
> >  
> >  	for (i = 0; i < GPIO_MAX_NUM; i++) {
> >  		sprintf(envname, "GPIO%d", i);
> > -		val = env_get(envname);
> > +		val = env_get(ctx_uboot, envname);
> >  		if (val) {
> >  			char direction = toupper(val[0]);
> >  			char level = toupper(val[1]);
> > @@ -82,7 +82,7 @@ void board_gpio_init(void)
> >  		}
> >  	}
> >  
> > -	val = env_get("PCIE_OFF");
> > +	val = env_get(ctx_uboot, "PCIE_OFF");
> >  	if (val) {
> >  		gpio_direction_input(GPIO_PCIE1_EN);
> >  		gpio_direction_input(GPIO_PCIE2_EN);
> > @@ -91,7 +91,7 @@ void board_gpio_init(void)
> >  		gpio_direction_output(GPIO_PCIE2_EN, 1);
> >  	}
> >  
> > -	val = env_get("SDHC_CDWP_OFF");
> > +	val = env_get(ctx_uboot, "SDHC_CDWP_OFF");
> >  	if (!val) {
> >  		ccsr_gur_t *gur = (void
> > *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 
> > @@ -218,7 +218,7 @@ int last_stage_init(void)
> >  	else
> >  		printf("NCT72(0x%x): ready\n", id2);
> >  
> > -	kval = env_get("kernelargs");
> > +	kval = env_get(ctx_uboot, "kernelargs");
> >  
> >  #ifdef CONFIG_MMC
> >  	mmc = find_mmc_device(0);
> > @@ -235,22 +235,22 @@ int last_stage_init(void)
> >  				strcat(newkernelargs, mmckargs);
> >  				strcat(newkernelargs, " ");
> >  				strcat(newkernelargs, &tmp[n]);
> > -				env_set("kernelargs", newkernelargs);
> > +				env_set(ctx_uboot, "kernelargs",
> > newkernelargs); } else {
> > -				env_set("kernelargs", mmckargs);
> > +				env_set(ctx_uboot, "kernelargs",
> > mmckargs); }
> >  		}
> >  #endif
> >  	get_arc_info();
> >  
> >  	if (kval) {
> > -		sval = env_get("SERIAL");
> > +		sval = env_get(ctx_uboot, "SERIAL");
> >  		if (sval) {
> >  			strcpy(newkernelargs, "SN=");
> >  			strcat(newkernelargs, sval);
> >  			strcat(newkernelargs, " ");
> >  			strcat(newkernelargs, kval);
> > -			env_set("kernelargs", newkernelargs);
> > +			env_set(ctx_uboot, "kernelargs",
> > newkernelargs); }
> >  	} else {
> >  		printf("Error reading kernelargs env variable!\n");
> > diff --git a/board/BuR/brppt1/board.c b/board/BuR/brppt1/board.c
> > index ef4f5c950140..4278dda5988f 100644
> > --- a/board/BuR/brppt1/board.c
> > +++ b/board/BuR/brppt1/board.c
> > @@ -180,10 +180,10 @@ int board_late_init(void)
> >  		bmode = 4;
> >  
> >  	printf("Mode:  %s\n", bootmodeascii[bmode & 0x0F]);
> > -	env_set_ulong("b_mode", bmode);
> > +	env_set_ulong(ctx_uboot, "b_mode", bmode);
> >  
> >  	/* get sure that bootcmd isn't affected by any bootcount
> > value */
> > -	env_set_ulong("bootlimit", 0);
> > +	env_set_ulong(ctx_uboot, "bootlimit", 0);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/BuR/brxre1/board.c b/board/BuR/brxre1/board.c
> > index 873208c668d7..69bcccbc5a0d 100644
> > --- a/board/BuR/brxre1/board.c
> > +++ b/board/BuR/brxre1/board.c
> > @@ -165,10 +165,11 @@ int board_late_init(void)
> >  	snprintf(othbootargs, sizeof(othbootargs),
> >  		 "u=vxWorksFTP pw=vxWorks
> > o=0x%08x;0x%08x;0x%08x;0x%08x", (u32)gd->fb_base - 0x20,
> > -		 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base -
> > 0x20),
> > -		 (u32)env_get_ulong("vx_romfsbase", 16, 0),
> > -		 (u32)env_get_ulong("vx_romfssize", 16, 0));
> > -	env_set("othbootargs", othbootargs);
> > +		 (u32)env_get_ulong(ctx_uboot, "vx_memtop", 16,
> > +				    gd->fb_base - 0x20),
> > +		 (u32)env_get_ulong(ctx_uboot, "vx_romfsbase", 16,
> > 0),
> > +		 (u32)env_get_ulong(ctx_uboot, "vx_romfssize", 16,
> > 0));
> > +	env_set(ctx_uboot, "othbootargs", othbootargs);
> >  	/*
> >  	 * reset VBAR registers to its reset location, VxWorks
> > 6.9.3.2 does
> >  	 * expect that vectors are there, original u-boot moves them
> > to _start diff --git a/board/BuR/common/br_resetc.c
> > b/board/BuR/common/br_resetc.c index c0e7fb65b298..36d49967dd82 100644
> > --- a/board/BuR/common/br_resetc.c
> > +++ b/board/BuR/common/br_resetc.c
> > @@ -230,7 +230,7 @@ int br_resetc_bmode(void)
> >  		printf("Reset: STM32 controller\n");
> >  
> >  	printf("Mode:  %s\n", bootmodeascii[regw & 0x0F]);
> > -	env_set_ulong("b_mode", regw & 0x0F);
> > +	env_set_ulong(ctx_uboot, "b_mode", regw & 0x0F);
> >  
> >  	return rc;
> >  }
> > diff --git a/board/BuR/common/common.c b/board/BuR/common/common.c
> > index 148fc9075e4f..f3bc87daf19f 100644
> > --- a/board/BuR/common/common.c
> > +++ b/board/BuR/common/common.c
> > @@ -29,9 +29,12 @@ DECLARE_GLOBAL_DATA_PTR;
> >  
> >  void lcdbacklight(int on)
> >  {
> > -	unsigned int driver = env_get_ulong("ds1_bright_drv", 16,
> > 0UL);
> > -	unsigned int bright = env_get_ulong("ds1_bright_def", 10,
> > 50);
> > -	unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
> > +	unsigned int driver = env_get_ulong(ctx_uboot,
> > "ds1_bright_drv", 16,
> > +					    0UL);
> > +	unsigned int bright = env_get_ulong(ctx_uboot,
> > "ds1_bright_def", 10,
> > +					    50);
> > +	unsigned int pwmfrq = env_get_ulong(ctx_uboot,
> > "ds1_pwmfreq", 10,
> > +					    ~0UL);
> >  	unsigned int tmp;
> >  	struct gptimer *timerhw;
> >  
> > @@ -87,20 +90,20 @@ int load_lcdtiming(struct am335x_lcdpanel *panel)
> >  {
> >  	struct am335x_lcdpanel pnltmp;
> >  
> > -	pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
> > -	pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
> > -	pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
> > -	pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
> > -	pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
> > -	pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
> > -	pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
> > -	pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
> > -	pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
> > -	pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
> > -	pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
> > -	pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
> > -	pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
> > -	panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
> > +	pnltmp.hactive = env_get_ulong(ctx_uboot, "ds1_hactive", 10,
> > ~0UL);
> > +	pnltmp.vactive = env_get_ulong(ctx_uboot, "ds1_vactive", 10,
> > ~0UL);
> > +	pnltmp.bpp = env_get_ulong(ctx_uboot, "ds1_bpp", 10, ~0UL);
> > +	pnltmp.hfp = env_get_ulong(ctx_uboot, "ds1_hfp", 10, ~0UL);
> > +	pnltmp.hbp = env_get_ulong(ctx_uboot, "ds1_hbp", 10, ~0UL);
> > +	pnltmp.hsw = env_get_ulong(ctx_uboot, "ds1_hsw", 10, ~0UL);
> > +	pnltmp.vfp = env_get_ulong(ctx_uboot, "ds1_vfp", 10, ~0UL);
> > +	pnltmp.vbp = env_get_ulong(ctx_uboot, "ds1_vbp", 10, ~0UL);
> > +	pnltmp.vsw = env_get_ulong(ctx_uboot, "ds1_vsw", 10, ~0UL);
> > +	pnltmp.pxl_clk = env_get_ulong(ctx_uboot, "ds1_pxlclk", 10,
> > ~0UL);
> > +	pnltmp.pol = env_get_ulong(ctx_uboot, "ds1_pol", 16, ~0UL);
> > +	pnltmp.pup_delay = env_get_ulong(ctx_uboot, "ds1_pupdelay",
> > 10, ~0UL);
> > +	pnltmp.pon_delay = env_get_ulong(ctx_uboot, "ds1_tondelay",
> > 10, ~0UL);
> > +	panel_info.vl_rot = env_get_ulong(ctx_uboot, "ds1_rotation",
> > 10, 0); 
> >  	if (
> >  	   ~0UL == (pnltmp.hactive) ||
> > @@ -151,11 +154,11 @@ static void br_summaryscreen_printenv(char
> > *prefix, char *name, char *altname,
> >  				       char *suffix)
> >  {
> > -	char *envval = env_get(name);
> > +	char *envval = env_get(ctx_uboot, name);
> >  	if (0 != envval) {
> >  		lcd_printf("%s %s %s", prefix, envval, suffix);
> >  	} else if (0 != altname) {
> > -		envval = env_get(altname);
> > +		envval = env_get(ctx_uboot, altname);
> >  		if (0 != envval)
> >  			lcd_printf("%s %s %s", prefix, envval,
> > suffix); } else {
> > @@ -178,7 +181,7 @@ void lcdpower(int on)
> >  	u32 pin, swval, i;
> >  	char buf[16] = { 0 };
> >  
> > -	pin = env_get_ulong("ds1_pwr", 16, ~0UL);
> > +	pin = env_get_ulong(ctx_uboot, "ds1_pwr", 16, ~0UL);
> >  
> >  	if (pin == ~0UL) {
> >  		puts("no pwrpin in dtb/env, cannot powerup
> > display!\n"); @@ -295,8 +298,8 @@ int brdefaultip_setup(int bus, int
> > chip) "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1;
> > setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254;
> > setenv netmask 255.255.255.0; fi;", sizeof(defip)); 
> > -	env_set("brdefaultip", defip);
> > -	env_set_hex("board_id", u8buf);
> > +	env_set(ctx_uboot, "brdefaultip", defip);
> > +	env_set_hex(ctx_uboot, "board_id", u8buf);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/BuS/eb_cpu5282/eb_cpu5282.c
> > b/board/BuS/eb_cpu5282/eb_cpu5282.c index 0b916d2482c5..03d2b276a132
> > 100644 --- a/board/BuS/eb_cpu5282/eb_cpu5282.c
> > +++ b/board/BuS/eb_cpu5282/eb_cpu5282.c
> > @@ -139,7 +139,7 @@ void hw_watchdog_init(void)
> >  	int enable;
> >  
> >  	enable = 1;
> > -	s = env_get("watchdog");
> > +	s = env_get(ctx_uboot, "watchdog");
> >  	if (s != NULL)
> >  		if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0",
> > 1) == 0)) enable = 0;
> > @@ -191,13 +191,13 @@ int drv_video_init(void)
> >  	unsigned long splash;
> >  #endif
> >  	printf("Init Video as ");
> > -	s = env_get("displaywidth");
> > +	s = env_get(ctx_uboot, "displaywidth");
> >  	if (s != NULL)
> >  		display_width = simple_strtoul(s, NULL, 10);
> >  	else
> >  		display_width = 256;
> >  
> > -	s = env_get("displayheight");
> > +	s = env_get(ctx_uboot, "displayheight");
> >  	if (s != NULL)
> >  		display_height = simple_strtoul(s, NULL, 10);
> >  	else
> > @@ -211,7 +211,7 @@ int drv_video_init(void)
> >  	vcxk_init(display_width, display_height);
> >  
> >  #ifdef CONFIG_SPLASH_SCREEN
> > -	s = env_get("splashimage");
> > +	s = env_get(ctx_uboot, "splashimage");
> >  	if (s != NULL) {
> >  		splash = simple_strtoul(s, NULL, 16);
> >  		vcxk_acknowledge_wait();
> > diff --git a/board/CZ.NIC/turris_mox/turris_mox.c
> > b/board/CZ.NIC/turris_mox/turris_mox.c index
> > 946e20ab492f..b23ecb3fefaa 100644 ---
> > a/board/CZ.NIC/turris_mox/turris_mox.c +++
> > b/board/CZ.NIC/turris_mox/turris_mox.c @@ -362,10 +362,10 @@ int
> > misc_init_r(void) return 0;
> >  	}
> >  
> > -	if (is_valid_ethaddr(mac1) && !env_get("ethaddr"))
> > +	if (is_valid_ethaddr(mac1) && !env_get(ctx_uboot, "ethaddr"))
> >  		eth_env_set_enetaddr("ethaddr", mac1);
> >  
> > -	if (is_valid_ethaddr(mac2) && !env_get("eth1addr"))
> > +	if (is_valid_ethaddr(mac2) && !env_get(ctx_uboot,
> > "eth1addr")) eth_env_set_enetaddr("eth1addr", mac2);
> >  
> >  	return 0;
> > diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c
> > b/board/CZ.NIC/turris_omnia/turris_omnia.c index
> > 1d8d08a847d9..bbbeaf75fc97 100644 ---
> > a/board/CZ.NIC/turris_omnia/turris_omnia.c +++
> > b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -326,7 +326,7 @@ static
> > int set_regdomain(void) puts("EEPROM regdomain read failed.\n");
> >  
> >  	printf("Regdomain set to %s\n", rd);
> > -	return env_set("regdomain", rd);
> > +	return env_set(ctx_uboot, "regdomain", rd);
> >  }
> >  
> >  /*
> > @@ -359,11 +359,11 @@ static void handle_reset_button(void)
> >  		return;
> >  	}
> >  
> > -	env_set_ulong("omnia_reset", reset_status);
> > +	env_set_ulong(ctx_uboot, "omnia_reset", reset_status);
> >  
> >  	if (reset_status) {
> >  		printf("RESET button was pressed, overwriting
> > bootcmd!\n");
> > -		env_set("bootcmd", OMNIA_FACTORY_RESET_BOOTCMD);
> > +		env_set(ctx_uboot, "bootcmd",
> > OMNIA_FACTORY_RESET_BOOTCMD); }
> >  }
> >  #endif
> > diff --git a/board/CarMediaLab/flea3/flea3.c
> > b/board/CarMediaLab/flea3/flea3.c index be0bc228ec71..9a5fe1e2252d
> > 100644 --- a/board/CarMediaLab/flea3/flea3.c
> > +++ b/board/CarMediaLab/flea3/flea3.c
> > @@ -211,7 +211,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  		{ "mxc_nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
> >  	};
> >  
> > -	if (env_get("fdt_noauto")) {
> > +	if (env_get(ctx_uboot, "fdt_noauto")) {
> >  		puts("   Skiping ft_board_setup (fdt_noauto
> > defined)\n"); return 0;
> >  	}
> > diff --git a/board/LaCie/net2big_v2/net2big_v2.c
> > b/board/LaCie/net2big_v2/net2big_v2.c index
> > 686608d25a5a..659a351deaea 100644 ---
> > a/board/LaCie/net2big_v2/net2big_v2.c +++
> > b/board/LaCie/net2big_v2/net2big_v2.c @@ -221,7 +221,7 @@ int
> > misc_init_r(void) {
> >  	init_fan();
> >  #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		uchar mac[6];
> >  		if (lacie_read_mac_address(mac) == 0)
> >  			eth_env_set_enetaddr("ethaddr", mac);
> > diff --git a/board/LaCie/netspace_v2/netspace_v2.c
> > b/board/LaCie/netspace_v2/netspace_v2.c index
> > bd7ab22948b2..83b07300354e 100644 ---
> > a/board/LaCie/netspace_v2/netspace_v2.c +++
> > b/board/LaCie/netspace_v2/netspace_v2.c @@ -83,7 +83,7 @@ int
> > board_init(void) int misc_init_r(void)
> >  {
> >  #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		uchar mac[6];
> >  		if (lacie_read_mac_address(mac) == 0)
> >  			eth_env_set_enetaddr("ethaddr", mac);
> > diff --git a/board/Synology/ds414/cmd_syno.c
> > b/board/Synology/ds414/cmd_syno.c index 777948f90f58..abd38b24fff0
> > 100644 --- a/board/Synology/ds414/cmd_syno.c
> > +++ b/board/Synology/ds414/cmd_syno.c
> > @@ -80,7 +80,7 @@ static int do_syno_populate(int argc, char * const
> > argv[]) ethaddr[0], ethaddr[1], ethaddr[2],
> >  			 ethaddr[3], ethaddr[4], ethaddr[5]);
> >  		printf("parsed %s = %s\n", var, val);
> > -		env_set(var, val);
> > +		env_set(ctx_uboot, var, val);
> >  	}
> >  	if (!strncmp(buf + 32, SYNO_SN_TAG, strlen(SYNO_SN_TAG))) {
> >  		char *snp, *csump;
> > @@ -110,7 +110,7 @@ static int do_syno_populate(int argc, char *
> > const argv[]) goto out_unmap;
> >  		}
> >  		printf("parsed SN = %s\n", snp);
> > -		env_set("SN", snp);
> > +		env_set(ctx_uboot, "SN", snp);
> >  	} else {	/* old style format */
> >  		unsigned char csum = 0;
> >  
> > @@ -124,7 +124,7 @@ static int do_syno_populate(int argc, char *
> > const argv[]) }
> >  		bufp[n] = '\0';
> >  		printf("parsed SN = %s\n", buf + 32);
> > -		env_set("SN", buf + 32);
> > +		env_set(ctx_uboot, "SN", buf + 32);
> >  	}
> >  out_unmap:
> >  	unmap_physmem(buf, len);
> > diff --git a/board/alliedtelesis/x530/x530.c
> > b/board/alliedtelesis/x530/x530.c index e0fa8067c1c5..53bc9dd286e2
> > 100644 --- a/board/alliedtelesis/x530/x530.c
> > +++ b/board/alliedtelesis/x530/x530.c
> > @@ -157,7 +157,7 @@ int misc_init_r(void)
> >  	gpio_hog(&led_en, "atl,led-enable", "enable-gpio", 1);
> >  
> >  #ifdef MTDPARTS_MTDOOPS
> > -	env_set("mtdoops", MTDPARTS_MTDOOPS);
> > +	env_set(ctx_uboot, "mtdoops", MTDPARTS_MTDOOPS);
> >  #endif
> >  
> >  	led_7seg_init(0xff);
> > diff --git a/board/amazon/kc1/kc1.c b/board/amazon/kc1/kc1.c
> > index 9034c4fbfff0..9f183da00a9e 100644
> > --- a/board/amazon/kc1/kc1.c
> > +++ b/board/amazon/kc1/kc1.c
> > @@ -118,8 +118,8 @@ int misc_init_r(void)
> >  	}
> >  
> >  	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
> > -		if (!env_get("reboot-mode"))
> > -			env_set("reboot-mode", (char *)reboot_mode);
> > +		if (!env_get(ctx_uboot, "reboot-mode"))
> > +			env_set(ctx_uboot, "reboot-mode", (char
> > *)reboot_mode); }
> >  
> >  	omap_reboot_mode_clear();
> > diff --git a/board/amlogic/p200/p200.c b/board/amlogic/p200/p200.c
> > index 41d331dda2d4..4b1a158f1750 100644
> > --- a/board/amlogic/p200/p200.c
> > +++ b/board/amlogic/p200/p200.c
> > @@ -32,11 +32,11 @@ int misc_init_r(void)
> >  			eth_env_set_enetaddr("ethaddr", mac_addr);
> >  	}
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
> >  			EFUSE_SN_SIZE);
> >  		if (len == EFUSE_SN_SIZE)
> > -			env_set("serial#", serial);
> > +			env_set(ctx_uboot, "serial#", serial);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/amlogic/p201/p201.c b/board/amlogic/p201/p201.c
> > index e46fcaea6dcd..ba2a5387a120 100644
> > --- a/board/amlogic/p201/p201.c
> > +++ b/board/amlogic/p201/p201.c
> > @@ -32,11 +32,11 @@ int misc_init_r(void)
> >  			eth_env_set_enetaddr("ethaddr", mac_addr);
> >  	}
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
> >  			EFUSE_SN_SIZE);
> >  		if (len == EFUSE_SN_SIZE)
> > -			env_set("serial#", serial);
> > +			env_set(ctx_uboot, "serial#", serial);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/amlogic/p212/p212.c b/board/amlogic/p212/p212.c
> > index 094ab5478d00..3fabf79a4b41 100644
> > --- a/board/amlogic/p212/p212.c
> > +++ b/board/amlogic/p212/p212.c
> > @@ -36,11 +36,11 @@ int misc_init_r(void)
> >  			meson_generate_serial_ethaddr();
> >  	}
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
> >  			EFUSE_SN_SIZE);
> >  		if (len == EFUSE_SN_SIZE)
> > -			env_set("serial#", serial);
> > +			env_set(ctx_uboot, "serial#", serial);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/amlogic/q200/q200.c b/board/amlogic/q200/q200.c
> > index f1faa7418e07..2cf2af3e1899 100644
> > --- a/board/amlogic/q200/q200.c
> > +++ b/board/amlogic/q200/q200.c
> > @@ -35,11 +35,11 @@ int misc_init_r(void)
> >  			meson_generate_serial_ethaddr();
> >  	}
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
> >  					  EFUSE_SN_SIZE);
> >  		if (len == EFUSE_SN_SIZE)
> > -			env_set("serial#", serial);
> > +			env_set(ctx_uboot, "serial#", serial);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/aristainetos/aristainetos-v2.c
> > b/board/aristainetos/aristainetos-v2.c index
> > c0a2e41f02e8..061baf0255db 100644 ---
> > a/board/aristainetos/aristainetos-v2.c +++
> > b/board/aristainetos/aristainetos-v2.c @@ -651,7 +651,7 @@ int
> > board_late_init(void) {
> >  	char *my_bootdelay;
> >  	char bootmode = 0;
> > -	char const *panel = env_get("panel");
> > +	char const *panel = env_get(ctx_uboot, "panel");
> >  
> >  	/*
> >  	 * Check the boot-source. If booting from NOR Flash,
> > @@ -668,11 +668,11 @@ int board_late_init(void)
> >  	bootmode |= (gpio_get_value(IMX_GPIO_NR(7, 1)) ? 1 : 0) << 2;
> >  
> >  	if (bootmode == 7) {
> > -		my_bootdelay = env_get("nor_bootdelay");
> > +		my_bootdelay = env_get(ctx_uboot, "nor_bootdelay");
> >  		if (my_bootdelay != NULL)
> > -			env_set("bootdelay", my_bootdelay);
> > +			env_set(ctx_uboot, "bootdelay",
> > my_bootdelay); else
> > -			env_set("bootdelay", "-2");
> > +			env_set(ctx_uboot, "bootdelay", "-2");
> >  	}
> >  
> >  	/* if we have the lg panel, we can initialze it now */
> > diff --git a/board/armltd/integrator/integrator.c
> > b/board/armltd/integrator/integrator.c index
> > 0a2baa72976c..72c9678218ae 100644 ---
> > a/board/armltd/integrator/integrator.c +++
> > b/board/armltd/integrator/integrator.c @@ -116,7 +116,7 @@ extern
> > void cm_remap(void); 
> >  int misc_init_r (void)
> >  {
> > -	env_set("verify", "n");
> > +	env_set(ctx_uboot, "verify", "n");
> >  	return (0);
> >  }
> >  
> > diff --git a/board/atmel/common/board.c b/board/atmel/common/board.c
> > index c41706c4005c..aef6babfd37a 100644
> > --- a/board/atmel/common/board.c
> > +++ b/board/atmel/common/board.c
> > @@ -64,7 +64,7 @@ void at91_pda_detect(void)
> >  	}
> >  
> >  pda_detect_err:
> > -	env_set("pda", (const char *)buf);
> > +	env_set(ctx_uboot, "pda", (const char *)buf);
> >  }
> >  #else
> >  void at91_pda_detect(void)
> > @@ -74,5 +74,5 @@ void at91_pda_detect(void)
> >  
> >  void at91_prepare_cpu_var(void)
> >  {
> > -	env_set("cpu", get_cpu_name());
> > +	env_set(ctx_uboot, "cpu", get_cpu_name());
> >  }
> > diff --git a/board/atmel/common/mac_eeprom.c
> > b/board/atmel/common/mac_eeprom.c index 83a7778e9954..4c9a5c0b0d0e
> > 100644 --- a/board/atmel/common/mac_eeprom.c
> > +++ b/board/atmel/common/mac_eeprom.c
> > @@ -18,7 +18,7 @@ int at91_set_ethaddr(int offset)
> >  	struct udevice *dev;
> >  	int ret;
> >  
> > -	if (env_get(ETHADDR_NAME))
> > +	if (env_get(ctx_uboot, ETHADDR_NAME))
> >  		return 0;
> >  
> >  	ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
> > diff --git a/board/atmel/sama5d3xek/sama5d3xek.c
> > b/board/atmel/sama5d3xek/sama5d3xek.c index
> > acf61486d20b..6c27c3dbe148 100644 ---
> > a/board/atmel/sama5d3xek/sama5d3xek.c +++
> > b/board/atmel/sama5d3xek/sama5d3xek.c @@ -187,7 +187,7 @@ int
> > board_late_init(void) *p = tolower(*p);
> >  
> >  	strcat(name, "ek.dtb");
> > -	env_set("dtb_name", name);
> > +	env_set(ctx_uboot, "dtb_name", name);
> >  #endif
> >  #ifdef CONFIG_DM_VIDEO
> >  	at91_video_show_board_info();
> > diff --git a/board/bachmann/ot1200/ot1200.c
> > b/board/bachmann/ot1200/ot1200.c index 36f37084b36c..baf7b7cdf7f3
> > 100644 --- a/board/bachmann/ot1200/ot1200.c
> > +++ b/board/bachmann/ot1200/ot1200.c
> > @@ -301,9 +301,9 @@ int board_eth_init(bd_t *bis)
> >  
> >  	/* depending on the phy address we can detect our board
> > version */ if (phydev->addr == 0)
> > -		env_set("boardver", "");
> > +		env_set(ctx_uboot, "boardver", "");
> >  	else
> > -		env_set("boardver", "mr");
> > +		env_set(ctx_uboot, "boardver", "mr");
> >  
> >  	printf("using phy at %d\n", phydev->addr);
> >  	ret = fec_probe(bis, -1, base, bus, phydev);
> > diff --git a/board/birdland/bav335x/board.c
> > b/board/birdland/bav335x/board.c index 8811583ac628..9a8b69df3891
> > 100644 --- a/board/birdland/bav335x/board.c
> > +++ b/board/birdland/bav335x/board.c
> > @@ -161,7 +161,7 @@ int spl_start_uboot(void)
> >  
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > +	env_load(ctx_uboot);
> >  	if (env_get_yesno("boot_os") != 1)
> >  		return 1;
> >  #endif
> > @@ -300,8 +300,8 @@ int board_init(void)
> >  int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "BAV335xB");
> > -	env_set("board_rev", "B"); /* Fix me, but why bother.. */
> > +	env_set(ctx_uboot, "board_name", "BAV335xB");
> > +	env_set(ctx_uboot, "board_rev", "B"); /* Fix me, but why
> > bother.. */ #endif
> >  	return 0;
> >  }
> > @@ -391,7 +391,7 @@ int board_eth_init(bd_t *bis)
> >  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> > || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > diff --git a/board/bluegiga/apx4devkit/apx4devkit.c
> > b/board/bluegiga/apx4devkit/apx4devkit.c index
> > 9268aa0daafc..a7116e8c0c06 100644 ---
> > a/board/bluegiga/apx4devkit/apx4devkit.c +++
> > b/board/bluegiga/apx4devkit/apx4devkit.c @@ -133,8 +133,9 @@ void
> > get_board_serial(struct tag_serialnr *serialnr) #ifdef
> > CONFIG_REVISION_TAG u32 get_board_rev(void)
> >  {
> > -	if (env_get("revision#") != NULL)
> > -		return simple_strtoul(env_get("revision#"), NULL,
> > 10);
> > +	if (env_get(ctx_uboot, "revision#"))
> > +		return simple_strtoul(env_get(ctx_uboot,
> > "revision#"), NULL,
> > +				      10);
> >  	return 0;
> >  }
> >  #endif
> > diff --git a/board/bluewater/gurnard/gurnard.c
> > b/board/bluewater/gurnard/gurnard.c index 48e31d9065a2..560db5fee639
> > 100644 --- a/board/bluewater/gurnard/gurnard.c
> > +++ b/board/bluewater/gurnard/gurnard.c
> > @@ -340,7 +340,7 @@ int board_init(void)
> >  	at91_set_A_periph(AT91_PIN_PE6, 1);	/* power up */
> >  
> >  	/* Select the second timing index for board rev 2 */
> > -	rev_str = env_get("board_rev");
> > +	rev_str = env_get(ctx_uboot, "board_rev");
> >  	if (rev_str && !strncmp(rev_str, "2", 1)) {
> >  		struct udevice *dev;
> >  
> > @@ -367,7 +367,7 @@ int board_late_init(void)
> >  	 * Set MAC address so we do not need to init Ethernet before
> > Linux
> >  	 * boot
> >  	 */
> > -	env_str = env_get("ethaddr");
> > +	env_str = env_get(ctx_uboot, "ethaddr");
> >  	if (env_str) {
> >  		struct at91_emac *emac = (struct at91_emac
> > *)ATMEL_BASE_EMAC; /* Parse MAC address */
> > @@ -384,7 +384,7 @@ int board_late_init(void)
> >  		       &emac->sa2l);
> >  		writel((env_enetaddr[4] | env_enetaddr[5] << 8),
> > &emac->sa2h); 
> > -		printf("MAC:   %s\n", env_get("ethaddr"));
> > +		printf("MAC:   %s\n", env_get(ctx_uboot, "ethaddr"));
> >  	} else {
> >  		/* Not set in environment */
> >  		printf("MAC:   not set\n");
> > diff --git a/board/bosch/shc/board.c b/board/bosch/shc/board.c
> > index a96fdef992d2..6afbdb9737ac 100644
> > --- a/board/bosch/shc/board.c
> > +++ b/board/bosch/shc/board.c
> > @@ -246,7 +246,7 @@ static void check_button_status(void)
> >  
> >  	if (value == 0) {
> >  		printf("front button activated !\n");
> > -		env_set("harakiri", "1");
> > +		env_set(ctx_uboot, "harakiri", "1");
> >  	}
> >  }
> >  
> > diff --git a/board/boundary/nitrogen6x/nitrogen6x.c
> > b/board/boundary/nitrogen6x/nitrogen6x.c index
> > 26af3f710250..e9a1cde72390 100644 ---
> > a/board/boundary/nitrogen6x/nitrogen6x.c +++
> > b/board/boundary/nitrogen6x/nitrogen6x.c @@ -749,7 +749,7 @@ size_t
> > display_count = ARRAY_SIZE(displays); 
> >  int board_cfb_skip(void)
> >  {
> > -	return NULL != env_get("novideo");
> > +	return env_get(ctx_uboot, "novideo") != NULL;
> >  }
> >  
> >  static void setup_display(void)
> > @@ -954,7 +954,7 @@ static int do_kbd(cmd_tbl_t *cmdtp, int flag, int
> > argc, char * const argv[]) {
> >  	char envvalue[ARRAY_SIZE(buttons)+1];
> >  	int numpressed = read_keys(envvalue);
> > -	env_set("keybd", envvalue);
> > +	env_set(ctx_uboot, "keybd", envvalue);
> >  	return numpressed == 0;
> >  }
> >  
> > @@ -974,7 +974,7 @@ static void preboot_keys(void)
> >  	char keypress[ARRAY_SIZE(buttons)+1];
> >  	numpressed = read_keys(keypress);
> >  	if (numpressed) {
> > -		char *kbd_magic_keys = env_get("magic_keys");
> > +		char *kbd_magic_keys = env_get(ctx_uboot,
> > "magic_keys"); char *suffix;
> >  		/*
> >  		 * loop over all magic keys
> > @@ -983,7 +983,7 @@ static void preboot_keys(void)
> >  			char *keys;
> >  			char magic[sizeof(kbd_magic_prefix) + 1];
> >  			sprintf(magic, "%s%c", kbd_magic_prefix,
> > *suffix);
> > -			keys = env_get(magic);
> > +			keys = env_get(ctx_uboot, magic);
> >  			if (keys) {
> >  				if (!strcmp(keys, keypress))
> >  					break;
> > @@ -993,9 +993,9 @@ static void preboot_keys(void)
> >  			char cmd_name[sizeof(kbd_command_prefix) +
> > 1]; char *cmd;
> >  			sprintf(cmd_name, "%s%c",
> > kbd_command_prefix, *suffix);
> > -			cmd = env_get(cmd_name);
> > +			cmd = env_get(ctx_uboot, cmd_name);
> >  			if (cmd) {
> > -				env_set("preboot", cmd);
> > +				env_set(ctx_uboot, "preboot", cmd);
> >  				return;
> >  			}
> >  		}
> > @@ -1021,6 +1021,6 @@ int misc_init_r(void)
> >  #ifdef CONFIG_CMD_BMODE
> >  	add_board_boot_modes(board_boot_modes);
> >  #endif
> > -	env_set_hex("reset_cause", get_imx_reset_cause());
> > +	env_set_hex(ctx_uboot, "reset_cause",
> > get_imx_reset_cause(void)); return 0;
> >  }
> > diff --git a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c
> > b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c index
> > ce9f0494ee59..51e7f2c0c847 100644 ---
> > a/board/broadcom/bcm23550_w1d/bcm23550_w1d.c +++
> > b/board/broadcom/bcm23550_w1d/bcm23550_w1d.c @@ -103,7 +103,7 @@ int
> > board_usb_init(int index, enum usb_init_type init) int
> > g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
> > { debug("%s\n", __func__);
> > -	if (!env_get("serial#"))
> > +	if (!env_get(ctx_uboot, "serial#"))
> >  		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
> >  	return 0;
> >  }
> > diff --git a/board/broadcom/bcm28155_ap/bcm28155_ap.c
> > b/board/broadcom/bcm28155_ap/bcm28155_ap.c index
> > 87616386cb84..d9240cf35c8c 100644 ---
> > a/board/broadcom/bcm28155_ap/bcm28155_ap.c +++
> > b/board/broadcom/bcm28155_ap/bcm28155_ap.c @@ -110,7 +110,7 @@ int
> > board_usb_init(int index, enum usb_init_type init) int
> > g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
> > { debug("%s\n", __func__);
> > -	if (!env_get("serial#"))
> > +	if (!env_get(ctx_uboot, "serial#"))
> >  		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
> >  	return 0;
> >  }
> > diff --git a/board/broadcom/bcmstb/bcmstb.c
> > b/board/broadcom/bcmstb/bcmstb.c index 5fc2c0591b84..494c03d3eb79
> > 100644 --- a/board/broadcom/bcmstb/bcmstb.c
> > +++ b/board/broadcom/bcmstb/bcmstb.c
> > @@ -120,7 +120,7 @@ int board_late_init(void)
> >  	 * Set fdtcontroladdr in the environment so that scripts can
> >  	 * refer to it, for example, to reuse it for fdtaddr.
> >  	 */
> > -	env_set_hex("fdtcontroladdr", prior_stage_fdt_address);
> > +	env_set_hex(ctx_uboot, "fdtcontroladdr",
> > prior_stage_fdt_address); 
> >  	/*
> >  	 * Do not set machid to the machine identifier value provided
> > diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
> > index 95d3a5e1f579..f1baed84e268 100644
> > --- a/board/buffalo/lsxl/lsxl.c
> > +++ b/board/buffalo/lsxl/lsxl.c
> > @@ -229,7 +229,7 @@ static void erase_environment(void)
> >  static void rescue_mode(void)
> >  {
> >  	printf("Entering rescue mode..\n");
> > -	env_set("bootsource", "rescue");
> > +	env_set(ctx_uboot, "bootsource", "rescue");
> >  }
> >  
> >  static void check_push_button(void)
> > diff --git a/board/cadence/xtfpga/xtfpga.c
> > b/board/cadence/xtfpga/xtfpga.c index 256611638a55..1aee9c6f95a0
> > 100644 --- a/board/cadence/xtfpga/xtfpga.c
> > +++ b/board/cadence/xtfpga/xtfpga.c
> > @@ -86,14 +86,14 @@ int misc_init_r(void)
> >  	 * Default MAC address comes from CONFIG_ETHADDR + DIP
> > switches 1-6. */
> >  
> > -	char *s = env_get("ethaddr");
> > +	char *s = env_get(ctx_uboot, "ethaddr");
> >  	if (s == 0) {
> >  		unsigned int x;
> >  		char s[] = __stringify(CONFIG_ETHBASE);
> >  		x = (*(volatile u32 *)CONFIG_SYS_FPGAREG_DIPSW)
> >  			& FPGAREG_MAC_MASK;
> >  		sprintf(&s[15], "%02x", x);
> > -		env_set("ethaddr", s);
> > +		env_set(ctx_uboot, "ethaddr", s);
> >  	}
> >  #endif /* CONFIG_CMD_NET */
> >  
> > diff --git a/board/ccv/xpress/xpress.c b/board/ccv/xpress/xpress.c
> > index 05286e643c0e..9518307f7a76 100644
> > --- a/board/ccv/xpress/xpress.c
> > +++ b/board/ccv/xpress/xpress.c
> > @@ -324,7 +324,7 @@ static const struct boot_mode board_boot_modes[]
> > = { int board_late_init(void)
> >  {
> >  	add_board_boot_modes(board_boot_modes);
> > -	env_set("board_name", "xpress");
> > +	env_set(ctx_uboot, "board_name", "xpress");
> >  
> >  	return 0;
> >  }
> > diff --git a/board/compulab/cl-som-imx7/cl-som-imx7.c
> > b/board/compulab/cl-som-imx7/cl-som-imx7.c index
> > 395d5dce1785..d05a0dcf32f5 100644 ---
> > a/board/compulab/cl-som-imx7/cl-som-imx7.c +++
> > b/board/compulab/cl-som-imx7/cl-som-imx7.c @@ -311,7 +311,7 @@ void
> > cl_som_imx7_setup_wdog(void) 
> >  int board_late_init(void)
> >  {
> > -	env_set("board_name", "CL-SOM-iMX7");
> > +	env_set(ctx_uboot, "board_name", "CL-SOM-iMX7");
> >  	cl_som_imx7_setup_wdog();
> >  	return 0;
> >  }
> > diff --git a/board/compulab/cm_fx6/cm_fx6.c
> > b/board/compulab/cm_fx6/cm_fx6.c index feb7a71f007d..50564fde2ba6
> > 100644 --- a/board/compulab/cm_fx6/cm_fx6.c
> > +++ b/board/compulab/cm_fx6/cm_fx6.c
> > @@ -117,10 +117,10 @@ int board_video_skip(void)
> >  {
> >  	int ret;
> >  	struct display_info_t *preset;
> > -	char const *panel = env_get("displaytype");
> > +	char const *panel = env_get(ctx_uboot, "displaytype");
> >  
> >  	if (!panel) /* Also accept panel for backward compatibility
> > */
> > -		panel = env_get("panel");
> > +		panel = env_get(ctx_uboot, "panel");
> >  
> >  	if (!panel)
> >  		return -ENOENT;
> > @@ -628,16 +628,16 @@ int board_late_init(void)
> >  	int err;
> >  
> >  	if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else if (is_mx6dl())
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  
> >  	err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
> >  	if (err)
> >  		return 0;
> >  
> >  	if (!strncmp("SB-FX6m", baseboard_name, 7))
> > -		env_set("board_name", "Utilite");
> > +		env_set(ctx_uboot, "board_name", "Utilite");
> >  #endif
> >  	return 0;
> >  }
> > diff --git a/board/compulab/common/omap3_display.c
> > b/board/compulab/common/omap3_display.c index
> > cb9ebae7f964..9215a37d982a 100644 ---
> > a/board/compulab/common/omap3_display.c +++
> > b/board/compulab/common/omap3_display.c @@ -398,7 +398,7 @@ void
> > lcd_ctrl_init(void *lcdbase) {
> >  	struct prcm *prcm = (struct prcm *)PRCM_BASE;
> >  	char *custom_lcd;
> > -	char *displaytype = env_get("displaytype");
> > +	char *displaytype = env_get(ctx_uboot, "displaytype");
> >  
> >  	if (displaytype == NULL)
> >  		return;
> > @@ -406,7 +406,7 @@ void lcd_ctrl_init(void *lcdbase)
> >  	lcd_def = env_parse_displaytype(displaytype);
> >  	/* If we did not recognize the preset, check if it's an env
> > variable */ if (lcd_def == NONE) {
> > -		custom_lcd = env_get(displaytype);
> > +		custom_lcd = env_get(ctx_uboot, displaytype);
> >  		if (custom_lcd == NULL ||
> > parse_customlcd(custom_lcd) < 0) return;
> >  	}
> > diff --git a/board/congatec/cgtqmx6eval/cgtqmx6eval.c
> > b/board/congatec/cgtqmx6eval/cgtqmx6eval.c index
> > 6b3d5b833f44..8143f7680e7b 100644 ---
> > a/board/congatec/cgtqmx6eval/cgtqmx6eval.c +++
> > b/board/congatec/cgtqmx6eval/cgtqmx6eval.c @@ -236,7 +236,7 @@ int
> > power_init_board(void) return 0;
> >  
> >  	/* set level of MIPI if specified */
> > -	lv_mipi = env_get("lv_mipi");
> > +	lv_mipi = env_get(ctx_uboot, "lv_mipi");
> >  	if (lv_mipi)
> >  		return 0;
> >  
> > @@ -584,7 +584,7 @@ int board_video_skip(void)
> >  {
> >  	int i;
> >  	int ret;
> > -	char const *panel = env_get("panel");
> > +	char const *panel = env_get(ctx_uboot, "panel");
> >  	if (!panel) {
> >  		for (i = 0; i < ARRAY_SIZE(displays); i++) {
> >  			struct display_info_t const *dev = displays
> > + i; @@ -756,9 +756,9 @@ int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/cssi/MCR3000/MCR3000.c
> > b/board/cssi/MCR3000/MCR3000.c index 445b84c180fe..0f7ba71bb647 100644
> > --- a/board/cssi/MCR3000/MCR3000.c
> > +++ b/board/cssi/MCR3000/MCR3000.c
> > @@ -127,7 +127,7 @@ int misc_init_r(void)
> >  
> >  	/* if BTN_ACQ_AL is pressed then bootdelay is changed to 60
> > second */ if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
> > -		env_set("bootdelay", "60");
> > +		env_set(ctx_uboot, "bootdelay", "60");
> >  
> >  	return 0;
> >  }
> > diff --git a/board/davinci/da8xxevm/da850evm.c
> > b/board/davinci/da8xxevm/da850evm.c index d9019de6e006..31a380275553
> > 100644 --- a/board/davinci/da8xxevm/da850evm.c
> > +++ b/board/davinci/da8xxevm/da850evm.c
> > @@ -280,7 +280,7 @@ u32 get_board_rev(void)
> >  	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
> >  	u32 rev = 0;
> >  
> > -	s = env_get("maxcpuclk");
> > +	s = env_get(ctx_uboot, "maxcpuclk");
> >  	if (s)
> >  		maxcpuclk = simple_strtoul(s, NULL, 10);
> >  
> > diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c
> > b/board/davinci/da8xxevm/omapl138_lcdk.c index
> > 27a51d6a7802..0856b25c16e4 100644 ---
> > a/board/davinci/da8xxevm/omapl138_lcdk.c +++
> > b/board/davinci/da8xxevm/omapl138_lcdk.c @@ -275,7 +275,7 @@ static
> > void dspwake(void) if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
> >  		return;
> >  
> > -	if (!strcmp(env_get("dspwake"), "no"))
> > +	if (!strcmp(env_get(ctx_uboot, "dspwake"), "no"))
> >  		return;
> >  
> >  	*resetvect++ = 0x1E000; /* DSP Idle */
> > @@ -305,7 +305,7 @@ int misc_init_r(void)
> >  	uint8_t tmp[20], addr[10];
> >  
> >  
> > -	if (env_get("ethaddr") == NULL) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		/* Read Ethernet MAC address from EEPROM */
> >  		if (dvevm_read_mac_address(addr)) {
> >  			/* Set Ethernet MAC address from EEPROM */
> > @@ -319,7 +319,7 @@ int misc_init_r(void)
> >  				addr[0], addr[1], addr[2], addr[3],
> > addr[4], addr[5]);
> >  
> > -			env_set("ethaddr", (char *)tmp);
> > +			env_set(ctx_uboot, "ethaddr", (char *)tmp);
> >  		} else {
> >  			printf("Invalid MAC address read.\n");
> >  		}
> > diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c
> > b/board/dhelectronics/dh_imx6/dh_imx6.c index
> > 2d0f78da118f..d904ab4170d3 100644 ---
> > a/board/dhelectronics/dh_imx6/dh_imx6.c +++
> > b/board/dhelectronics/dh_imx6/dh_imx6.c @@ -251,7 +251,7 @@ int
> > board_late_init(void) break;
> >  	}
> >  
> > -	env_set("dhcom", buf);
> > +	env_set(ctx_uboot, "dhcom", buf);
> >  
> >  #ifdef CONFIG_CMD_BMODE
> >  	add_board_boot_modes(board_boot_modes);
> > diff --git a/board/eets/pdu001/board.c b/board/eets/pdu001/board.c
> > index 8a3d0ada270e..104dc1d3c6f7 100644
> > --- a/board/eets/pdu001/board.c
> > +++ b/board/eets/pdu001/board.c
> > @@ -79,15 +79,15 @@ static void env_set_boot_device(void)
> >  {
> >  	switch (boot_device()) {
> >  		case BOOT_DEVICE_MMC1: {
> > -			env_set("boot_device", "emmc");
> > +			env_set(ctx_uboot, "boot_device", "emmc");
> >  			break;
> >  		}
> >  		case BOOT_DEVICE_MMC2: {
> > -			env_set("boot_device", "sdcard");
> > +			env_set(ctx_uboot, "boot_device", "sdcard");
> >  			break;
> >  		}
> >  		default: {
> > -			env_set("boot_device", "unknown");
> > +			env_set(ctx_uboot, "boot_device", "unknown");
> >  			break;
> >  		}
> >  	}
> > @@ -117,7 +117,7 @@ static void env_set_serial(struct udevice *dev)
> >  		sprintf(serial + n, "%02X", val);
> >  	}
> >  	serial[2 * NODE_ID_BYTE_COUNT] = '\0';
> > -	env_set("serial#", serial);
> > +	env_set(ctx_uboot, "serial#", serial);
> >  }
> >  
> >  static void set_mpu_and_core_voltage(void)
> > diff --git a/board/el/el6x/el6x.c b/board/el/el6x/el6x.c
> > index 18d69a7da388..606fe1530728 100644
> > --- a/board/el/el6x/el6x.c
> > +++ b/board/el/el6x/el6x.c
> > @@ -467,7 +467,7 @@ int board_late_init(void)
> >  	add_board_boot_modes(board_boot_modes);
> >  #endif
> >  
> > -	env_set("board_name", BOARD_NAME);
> > +	env_set(ctx_uboot, "board_name", BOARD_NAME);
> >  	return 0;
> >  }
> >  
> > diff --git a/board/emulation/qemu-riscv/qemu-riscv.c
> > b/board/emulation/qemu-riscv/qemu-riscv.c index
> > 37d48d04f2d0..6cb571ba036c 100644 ---
> > a/board/emulation/qemu-riscv/qemu-riscv.c +++
> > b/board/emulation/qemu-riscv/qemu-riscv.c @@ -46,7 +46,7 @@ int
> > board_late_init(void) return 0;
> >  	}
> >  
> > -	env_set_hex("kernel_start", kernel_start);
> > +	env_set_hex(ctx_uboot, "kernel_start", kernel_start);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/engicam/common/board.c
> > b/board/engicam/common/board.c index 0c47afe5b566..b338c364efd0 100644
> > --- a/board/engicam/common/board.c
> > +++ b/board/engicam/common/board.c
> > @@ -22,11 +22,11 @@ static void mmc_late_init(void)
> >  	char mmcblk[32];
> >  	u32 dev_no = mmc_get_env_dev();
> >  
> > -	env_set_ulong("mmcdev", dev_no);
> > +	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
> >  
> >  	/* Set mmcblk env */
> >  	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
> > -	env_set("mmcroot", mmcblk);
> > +	env_set(ctx_uboot, "mmcroot", mmcblk);
> >  
> >  	sprintf(cmd, "mmc dev %d", dev_no);
> >  	run_command(cmd, 0);
> > @@ -39,25 +39,25 @@ static void setenv_fdt_file(void)
> >  
> >  	if (!strcmp(cmp_dtb, "imx6q-icore")) {
> >  		if (is_mx6dq())
> > -			env_set("fdt_file", "imx6q-icore.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6q-icore.dtb"); else if (is_mx6dl() || is_mx6solo())
> > -			env_set("fdt_file", "imx6dl-icore.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6dl-icore.dtb"); } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi"))
> > { if (is_mx6dq())
> > -			env_set("fdt_file", "imx6q-icore-mipi.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6q-icore-mipi.dtb"); else if (is_mx6dl() || is_mx6solo())
> > -			env_set("fdt_file", "imx6dl-icore-mipi.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6dl-icore-mipi.dtb"); } else if (!strcmp(cmp_dtb,
> > "imx6q-icore-rqs")) { if (is_mx6dq())
> > -			env_set("fdt_file", "imx6q-icore-rqs.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6q-icore-rqs.dtb"); else if (is_mx6dl() || is_mx6solo())
> > -			env_set("fdt_file", "imx6dl-icore-rqs.dtb");
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6dl-icore-rqs.dtb"); } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
> > -		env_set("fdt_file", "imx6ul-geam.dtb");
> > +		env_set(ctx_uboot, "fdt_file", "imx6ul-geam.dtb");
> >  	else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
> > -		env_set("fdt_file", "imx6ul-isiot-emmc.dtb");
> > +		env_set(ctx_uboot, "fdt_file",
> > "imx6ul-isiot-emmc.dtb"); else if (!strcmp(cmp_dtb,
> > "imx6ul-isiot-nand"))
> > -		env_set("fdt_file", "imx6ul-isiot-nand.dtb");
> > +		env_set(ctx_uboot, "fdt_file",
> > "imx6ul-isiot-nand.dtb"); }
> >  
> >  int board_late_init(void)
> > @@ -71,20 +71,20 @@ int board_late_init(void)
> >  #ifdef CONFIG_ENV_IS_IN_MMC
> >  		mmc_late_init();
> >  #endif
> > -		env_set("modeboot", "mmcboot");
> > +		env_set(ctx_uboot, "modeboot", "mmcboot");
> >  		break;
> >  	case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
> > -		env_set("modeboot", "nandboot");
> > +		env_set(ctx_uboot, "modeboot", "nandboot");
> >  		break;
> >  	default:
> > -		env_set("modeboot", "");
> > +		env_set(ctx_uboot, "modeboot", "");
> >  		break;
> >  	}
> >  
> >  	if (is_mx6ul())
> > -		env_set("console", "ttymxc0");
> > +		env_set(ctx_uboot, "console", "ttymxc0");
> >  	else
> > -		env_set("console", "ttymxc3");
> > +		env_set(ctx_uboot, "console", "ttymxc3");
> >  
> >  	setenv_fdt_file();
> >  
> > diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
> > index b0d2f7b6f87b..c9c1d77410cc 100644
> > --- a/board/esd/meesc/meesc.c
> > +++ b/board/esd/meesc/meesc.c
> > @@ -181,7 +181,7 @@ int checkboard(void)
> >  		puts("Board: EtherCAN/2 Gateway");
> >  		break;
> >  	}
> > -	if (env_get_f("serial#", str, sizeof(str)) > 0) {
> > +	if (env_get_f("serial#", str, sizeof(ctx_uboot, str)) > 0) {
> >  		puts(", serial# ");
> >  		puts(str);
> >  	}
> > @@ -198,7 +198,7 @@ void get_board_serial(struct tag_serialnr
> > *serialnr) {
> >  	char *str;
> >  
> > -	char *serial = env_get("serial#");
> > +	char *serial = env_get(ctx_uboot, "serial#");
> >  	if (serial) {
> >  		str = strchr(serial, '_');
> >  		if (str && (strlen(str) >= 4)) {
> > @@ -231,7 +231,7 @@ int misc_init_r(void)
> >  	 * In some cases this this needs to be set to 4.
> >  	 * Check the user has set environment mdiv to 4 to change
> > the divisor. */
> > -	str = env_get("mdiv");
> > +	str = env_get(ctx_uboot, "mdiv");
> >  	if (str && (strcmp(str, "4") == 0)) {
> >  		writel((readl(&pmc->mckr) & ~AT91_PMC_MDIV) |
> >  			AT91SAM9_PMC_MDIV_4, &pmc->mckr);
> > diff --git a/board/freescale/b4860qds/b4860qds.c
> > b/board/freescale/b4860qds/b4860qds.c index
> > 33cd4b496489..a8168e60a58a 100644 ---
> > a/board/freescale/b4860qds/b4860qds.c +++
> > b/board/freescale/b4860qds/b4860qds.c @@ -195,7 +195,7 @@ static int
> > adjust_vdd(ulong vdd_override) vid, vdd_target/10);
> >  
> >  	/* check override variable for overriding VDD */
> > -	vdd_string = env_get("b4qds_vdd_mv");
> > +	vdd_string = env_get(ctx_uboot, "b4qds_vdd_mv");
> >  	if (vdd_override == 0 && vdd_string &&
> >  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
> >  		vdd_override = vdd_string_override;
> > @@ -542,7 +542,8 @@ int configure_vsc3316_3308(void)
> >  			 * Extract hwconfig from environment since
> > environment
> >  			 * is not setup properly yet
> >  			 */
> > -			env_get_f("hwconfig", buffer,
> > sizeof(buffer));
> > +			env_get_f(ctx_uboot, "hwconfig", buffer,
> > +				  sizeof(buffer));
> >  			buf = buffer;
> >  
> >  			if
> > (hwconfig_subarg_cmp_f("fsl_b4860_serdes2", diff --git
> > a/board/freescale/common/cmd_esbc_validate.c
> > b/board/freescale/common/cmd_esbc_validate.c index
> > 36b620ca23a0..14ce924b8684 100644 ---
> > a/board/freescale/common/cmd_esbc_validate.c +++
> > b/board/freescale/common/cmd_esbc_validate.c @@ -53,7 +53,7 @@ static
> > int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
> >  	 * to continue U-Boot
> >  	 */
> >  	sprintf(buf, "%lx", img_addr);
> > -	env_set("img_addr", buf);
> > +	env_set(ctx_uboot, "img_addr", buf);
> >  
> >  	if (ret)
> >  		return 1;
> > diff --git a/board/freescale/common/fsl_chain_of_trust.c
> > b/board/freescale/common/fsl_chain_of_trust.c index
> > a024e7239e6e..9e216c3f51d7 100644 ---
> > a/board/freescale/common/fsl_chain_of_trust.c +++
> > b/board/freescale/common/fsl_chain_of_trust.c @@ -80,12 +80,12 @@ int
> > fsl_setenv_chain_of_trust(void)
> >  	 * bootdelay = 0 (To disable Boot Prompt)
> >  	 * bootcmd = CONFIG_CHAIN_BOOT_CMD (Validate and execute
> > Boot script) */
> > -	env_set("bootdelay", "-2");
> > +	env_set(ctx_uboot, "bootdelay", "-2");
> >  
> >  #ifdef CONFIG_ARM
> > -	env_set("secureboot", "y");
> > +	env_set(ctx_uboot, "secureboot", "y");
> >  #else
> > -	env_set("bootcmd", CONFIG_CHAIN_BOOT_CMD);
> > +	env_set(ctx_uboot, "bootcmd", CONFIG_CHAIN_BOOT_CMD);
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/common/sys_eeprom.c
> > b/board/freescale/common/sys_eeprom.c index
> > bb655ca7447c..88640958c79d 100644 ---
> > a/board/freescale/common/sys_eeprom.c +++
> > b/board/freescale/common/sys_eeprom.c @@ -538,8 +538,8 @@ int
> > mac_read_from_eeprom(void) /* Only initialize environment variables
> > that are blank
> >  			 * (i.e. have not yet been set)
> >  			 */
> > -			if (!env_get(enetvar))
> > -				env_set(enetvar, ethaddr);
> > +			if (!env_get(ctx_uboot, enetvar))
> > +				env_set(ctx_uboot, enetvar, ethaddr);
> >  		}
> >  	}
> >  
> > diff --git a/board/freescale/common/vid.c
> > b/board/freescale/common/vid.c index b37f3bf4f8fe..db23c8387e5c 100644
> > --- a/board/freescale/common/vid.c
> > +++ b/board/freescale/common/vid.c
> > @@ -617,7 +617,7 @@ int adjust_vdd(ulong vdd_override)
> >  	vdd_target = vdd[vid];
> >  
> >  	/* check override variable for overriding VDD */
> > -	vdd_string = env_get(CONFIG_VID_FLS_ENV);
> > +	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
> >  	if (vdd_override == 0 && vdd_string &&
> >  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
> >  		vdd_override = vdd_string_override;
> > @@ -824,7 +824,7 @@ int adjust_vdd(ulong vdd_override)
> >  	vdd_target = vdd[vid];
> >  
> >  	/* check override variable for overriding VDD */
> > -	vdd_string = env_get(CONFIG_VID_FLS_ENV);
> > +	vdd_string = env_get(ctx_uboot, CONFIG_VID_FLS_ENV);
> >  	if (vdd_override == 0 && vdd_string &&
> >  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
> >  		vdd_override = vdd_string_override;
> > diff --git a/board/freescale/imx8mq_evk/imx8mq_evk.c
> > b/board/freescale/imx8mq_evk/imx8mq_evk.c index
> > 1463e6e6963b..1822df9f32e8 100644 ---
> > a/board/freescale/imx8mq_evk/imx8mq_evk.c +++
> > b/board/freescale/imx8mq_evk/imx8mq_evk.c @@ -123,8 +123,8 @@ int
> > board_mmc_get_env_dev(int devno) int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "EVK");
> > -	env_set("board_rev", "iMX8MQ");
> > +	env_set(ctx_uboot, "board_name", "EVK");
> > +	env_set(ctx_uboot, "board_rev", "iMX8MQ");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/imx8qm_mek/imx8qm_mek.c
> > b/board/freescale/imx8qm_mek/imx8qm_mek.c index
> > 76634a3a28ad..34ed03c3dec1 100644 ---
> > a/board/freescale/imx8qm_mek/imx8qm_mek.c +++
> > b/board/freescale/imx8qm_mek/imx8qm_mek.c @@ -126,8 +126,8 @@ int
> > board_mmc_get_env_dev(int devno) int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "MEK");
> > -	env_set("board_rev", "iMX8QM");
> > +	env_set(ctx_uboot, "board_name", "MEK");
> > +	env_set(ctx_uboot, "board_rev", "iMX8QM");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> > b/board/freescale/imx8qxp_mek/imx8qxp_mek.c index
> > 4ba83142841a..0d6152ac9551 100644 ---
> > a/board/freescale/imx8qxp_mek/imx8qxp_mek.c +++
> > b/board/freescale/imx8qxp_mek/imx8qxp_mek.c @@ -139,8 +139,8 @@ int
> > board_mmc_get_env_dev(int devno) int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "MEK");
> > -	env_set("board_rev", "iMX8QXP");
> > +	env_set(ctx_uboot, "board_name", "MEK");
> > +	env_set(ctx_uboot, "board_rev", "iMX8QXP");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c
> > b/board/freescale/ls1088a/eth_ls1088aqds.c index
> > 237088a53710..f618db490f00 100644 ---
> > a/board/freescale/ls1088a/eth_ls1088aqds.c +++
> > b/board/freescale/ls1088a/eth_ls1088aqds.c @@ -529,7 +529,7 @@ void
> > ls1088a_handle_phy_interface_sgmii(int dpmac_id) serdes1_prtcl =
> > serdes_get_number(FSL_SRDS_1, cfg); 
> >  	int *riser_phy_addr;
> > -	char *env_hwconfig = env_get("hwconfig");
> > +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	if (hwconfig_f("xqsgmii", env_hwconfig))
> >  		riser_phy_addr = &xqsgii_riser_phy_addr[0];
> > @@ -670,7 +670,7 @@ int board_eth_init(bd_t *bis)
> >  	int error = 0, i;
> >  #ifdef CONFIG_FSL_MC_ENET
> >  	struct memac_mdio_info *memac_mdio0_info;
> > -	char *env_hwconfig = env_get("hwconfig");
> > +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	initialize_dpmac_to_slot();
> >  
> > diff --git a/board/freescale/ls1088a/ls1088a.c
> > b/board/freescale/ls1088a/ls1088a.c index f1592982a348..cdbfd90c19fa
> > 100644 --- a/board/freescale/ls1088a/ls1088a.c
> > +++ b/board/freescale/ls1088a/ls1088a.c
> > @@ -984,7 +984,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  #ifdef CONFIG_MTD_NOR_FLASH
> >  int is_flash_available(void)
> >  {
> > -	char *env_hwconfig = env_get("hwconfig");
> > +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  	enum boot_src src = get_boot_src();
> >  	int is_nor_flash_available = 1;
> >  
> > diff --git a/board/freescale/ls2080aqds/eth.c
> > b/board/freescale/ls2080aqds/eth.c index 6a8788c31254..1103ca1d430c
> > 100644 --- a/board/freescale/ls2080aqds/eth.c
> > +++ b/board/freescale/ls2080aqds/eth.c
> > @@ -506,7 +506,7 @@ static void initialize_dpmac_to_slot(void)
> >  		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;  
> >  
> >  	char *env_hwconfig;
> > -	env_hwconfig = env_get("hwconfig");
> > +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	switch (serdes1_prtcl) {
> >  	case 0x07:
> > @@ -660,7 +660,7 @@ void ls2080a_handle_phy_interface_sgmii(int
> > dpmac_id)
> >  		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;  
> >  
> >  	int *riser_phy_addr;
> > -	char *env_hwconfig = env_get("hwconfig");
> > +	char *env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	if (hwconfig_f("xqsgmii", env_hwconfig))
> >  		riser_phy_addr = &xqsgii_riser_phy_addr[0];
> > @@ -906,7 +906,7 @@ int board_eth_init(bd_t *bis)
> >  	unsigned int i;
> >  	char *env_hwconfig;
> >  
> > -	env_hwconfig = env_get("hwconfig");
> > +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	initialize_dpmac_to_slot();
> >  
> > diff --git a/board/freescale/ls2080aqds/ls2080aqds.c
> > b/board/freescale/ls2080aqds/ls2080aqds.c index
> > 91c80353edd6..6eef0536d162 100644 ---
> > a/board/freescale/ls2080aqds/ls2080aqds.c +++
> > b/board/freescale/ls2080aqds/ls2080aqds.c @@ -212,7 +212,7 @@ int
> > board_init(void) 
> >  	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
> >  
> > -	env_hwconfig = env_get("hwconfig");
> > +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	if (hwconfig_f("dspi", env_hwconfig) &&
> >  	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
> > diff --git a/board/freescale/ls2080ardb/ls2080ardb.c
> > b/board/freescale/ls2080ardb/ls2080ardb.c index
> > e20267f27ce0..d7ea56a6613a 100644 ---
> > a/board/freescale/ls2080ardb/ls2080ardb.c +++
> > b/board/freescale/ls2080ardb/ls2080ardb.c @@ -265,7 +265,7 @@ int
> > misc_init_r(void) 
> >  	val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
> >  
> > -	env_hwconfig = env_get("hwconfig");
> > +	env_hwconfig = env_get(ctx_uboot, "hwconfig");
> >  
> >  	if (hwconfig_f("dspi", env_hwconfig) &&
> >  	    DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
> > @@ -295,10 +295,10 @@ int misc_init_r(void)
> >  	 */
> >  	if ((SVR_SOC_VER(svr) == SVR_LS2088A) ||
> >  	    (SVR_SOC_VER(svr) == SVR_LS2048A))
> > -		env_set("board", "ls2088ardb");
> > +		env_set(ctx_uboot, "board", "ls2088ardb");
> >  	else if ((SVR_SOC_VER(svr) == SVR_LS2081A) ||
> >  	    (SVR_SOC_VER(svr) == SVR_LS2041A))
> > -		env_set("board", "ls2081ardb");
> > +		env_set(ctx_uboot, "board", "ls2081ardb");
> >  
> >  	return 0;
> >  }
> > diff --git a/board/freescale/lx2160a/eth_lx2160aqds.c
> > b/board/freescale/lx2160a/eth_lx2160aqds.c index
> > 92c06e5060f1..40fb5092c337 100644 ---
> > a/board/freescale/lx2160a/eth_lx2160aqds.c +++
> > b/board/freescale/lx2160a/eth_lx2160aqds.c @@ -484,7 +484,7 @@ int
> > board_eth_init(bd_t *bis)
> >  	 * defining "dpmac_override" in hwconfig environment
> > variable. */
> >  	if (hwconfig("dpmac_override")) {
> > -		env_dpmac = env_get("dpmac");
> > +		env_dpmac = env_get(ctx_uboot, "dpmac");
> >  		if (env_dpmac) {
> >  			ret = hwconfig_arg_f("srds", &len,
> > env_dpmac); if (ret) {
> > diff --git a/board/freescale/mpc8323erdb/mpc8323erdb.c
> > b/board/freescale/mpc8323erdb/mpc8323erdb.c index
> > e5aecc4e1f28..aa19a1b8534d 100644 ---
> > a/board/freescale/mpc8323erdb/mpc8323erdb.c +++
> > b/board/freescale/mpc8323erdb/mpc8323erdb.c @@ -217,7 +217,8 @@ int
> > mac_read_from_eeprom(void) buf[i * 6 + 4], buf[i * 6 + 5]);
> >  					sprintf((char *)enetvar,
> >  						i ? "eth%daddr" :
> > "ethaddr", i);
> > -					env_set((char *)enetvar,
> > str);
> > +					env_set(ctx_uboot, (char
> > *)enetvar,
> > +						str);
> >  				}
> >  			}
> >  		}
> > diff --git a/board/freescale/mpc837xemds/pci.c
> > b/board/freescale/mpc837xemds/pci.c index 41b78cf5e4de..c6f734ef2625
> > 100644 --- a/board/freescale/mpc837xemds/pci.c
> > +++ b/board/freescale/mpc837xemds/pci.c
> > @@ -67,7 +67,7 @@ static struct pci_region pcie_regions_1[] = {
> >  
> >  static int is_pex_x2(void)
> >  {
> > -	const char *pex_x2 = env_get("pex_x2");
> > +	const char *pex_x2 = env_get(ctx_uboot, "pex_x2");
> >  
> >  	if (pex_x2 && !strcmp(pex_x2, "yes"))
> >  		return 1;
> > diff --git a/board/freescale/mpc837xerdb/mpc837xerdb.c
> > b/board/freescale/mpc837xerdb/mpc837xerdb.c index
> > 4ad62bcf1d6b..71939b240dae 100644 ---
> > a/board/freescale/mpc837xerdb/mpc837xerdb.c +++
> > b/board/freescale/mpc837xerdb/mpc837xerdb.c @@ -173,7 +173,7 @@ int
> > board_mmc_init(bd_t *bd) char buffer[HWCONFIG_BUFFER_SIZE] = {0};
> >  	int esdhc_hwconfig_enabled = 0;
> >  
> > -	if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
> > +	if (env_get_f("hwconfig", buffer, sizeof(ctx_uboot, buffer))
> > > 0) esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
> >  
> >  	if (esdhc_hwconfig_enabled == 0)
> > diff --git a/board/freescale/mx51evk/mx51evk_video.c
> > b/board/freescale/mx51evk/mx51evk_video.c index
> > 3715c5d738f9..ed2a58ea4a9a 100644 ---
> > a/board/freescale/mx51evk/mx51evk_video.c +++
> > b/board/freescale/mx51evk/mx51evk_video.c @@ -76,7 +76,7 @@ void
> > setup_iomux_lcd(void) int board_video_skip(void)
> >  {
> >  	int ret;
> > -	char const *e = env_get("panel");
> > +	char const *e = env_get(ctx_uboot, "panel");
> >  
> >  	if (e) {
> >  		if (strcmp(e, "claa") == 0) {
> > diff --git a/board/freescale/mx53loco/mx53loco.c
> > b/board/freescale/mx53loco/mx53loco.c index
> > a177815bb8aa..a3328a134fb8 100644 ---
> > a/board/freescale/mx53loco/mx53loco.c +++
> > b/board/freescale/mx53loco/mx53loco.c @@ -208,7 +208,7 @@ static int
> > power_init(void) if (!p)
> >  			return -ENODEV;
> >  
> > -		env_set("fdt_file", "imx53-qsb.dtb");
> > +		env_set(ctx_uboot, "fdt_file", "imx53-qsb.dtb");
> >  
> >  		/* Set VDDA to 1.25V */
> >  		val = DA9052_BUCKCORE_BCOREEN |
> > DA_BUCKCORE_VBCORE_1_250V; @@ -251,7 +251,7 @@ static int
> > power_init(void) if (!p)
> >  			return -ENODEV;
> >  
> > -		env_set("fdt_file", "imx53-qsrb.dtb");
> > +		env_set(ctx_uboot, "fdt_file", "imx53-qsrb.dtb");
> >  
> >  		/* Set VDDGP to 1.25V for 1GHz on SW1 */
> >  		pmic_reg_read(p, REG_SW_0, &val);
> > diff --git a/board/freescale/mx53loco/mx53loco_video.c
> > b/board/freescale/mx53loco/mx53loco_video.c index
> > ff3fc8ce3e6f..061c990bcfb5 100644 ---
> > a/board/freescale/mx53loco/mx53loco_video.c +++
> > b/board/freescale/mx53loco/mx53loco_video.c @@ -92,7 +92,7 @@ void
> > setup_iomux_lcd(void) int board_video_skip(void)
> >  {
> >  	int ret;
> > -	char const *e = env_get("panel");
> > +	char const *e = env_get(ctx_uboot, "panel");
> >  
> >  	if (e) {
> >  		if (strcmp(e, "seiko") == 0) {
> > diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c
> > b/board/freescale/mx6sabreauto/mx6sabreauto.c index
> > dc156efbbcbc..a1cd8f4bc52e 100644 ---
> > a/board/freescale/mx6sabreauto/mx6sabreauto.c +++
> > b/board/freescale/mx6sabreauto/mx6sabreauto.c @@ -623,14 +623,14 @@
> > int board_late_init(void) #endif
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "SABREAUTO");
> > +	env_set(ctx_uboot, "board_name", "SABREAUTO");
> >  
> >  	if (is_mx6dqp())
> > -		env_set("board_rev", "MX6QP");
> > +		env_set(ctx_uboot, "board_rev", "MX6QP");
> >  	else if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else if (is_mx6sdl())
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/mx6sabresd/mx6sabresd.c
> > b/board/freescale/mx6sabresd/mx6sabresd.c index
> > b0c0117968bf..fb4c03a428c8 100644 ---
> > a/board/freescale/mx6sabresd/mx6sabresd.c +++
> > b/board/freescale/mx6sabresd/mx6sabresd.c @@ -606,14 +606,14 @@ int
> > board_late_init(void) #endif
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "SABRESD");
> > +	env_set(ctx_uboot, "board_name", "SABRESD");
> >  
> >  	if (is_mx6dqp())
> > -		env_set("board_rev", "MX6QP");
> > +		env_set(ctx_uboot, "board_rev", "MX6QP");
> >  	else if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else if (is_mx6sdl())
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c
> > b/board/freescale/mx6sxsabresd/mx6sxsabresd.c index
> > 1c10958879b1..b4bc682a5160 100644 ---
> > a/board/freescale/mx6sxsabresd/mx6sxsabresd.c +++
> > b/board/freescale/mx6sxsabresd/mx6sxsabresd.c @@ -309,7 +309,7 @@ int
> > board_late_init(void) {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	if (is_reva())
> > -		env_set("board_rev", "REVA");
> > +		env_set(ctx_uboot, "board_rev", "REVA");
> >  #endif
> >  	return 0;
> >  }
> > diff --git a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
> > b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c index
> > ccbe4044786c..913b2c6c57b8 100644 ---
> > a/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c +++
> > b/board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c @@ -545,12
> > +545,12 @@ int board_late_init(void) #endif
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "EVK");
> > +	env_set(ctx_uboot, "board_name", "EVK");
> >  
> >  	if (is_mx6ul_9x9_evk())
> > -		env_set("board_rev", "9X9");
> > +		env_set(ctx_uboot, "board_rev", "9X9");
> >  	else
> > -		env_set("board_rev", "14X14");
> > +		env_set(ctx_uboot, "board_rev", "14X14");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/mx6ullevk/mx6ullevk.c
> > b/board/freescale/mx6ullevk/mx6ullevk.c index
> > e11934780262..8dc5511e245f 100644 ---
> > a/board/freescale/mx6ullevk/mx6ullevk.c +++
> > b/board/freescale/mx6ullevk/mx6ullevk.c @@ -84,8 +84,8 @@ int
> > board_late_init(void) #endif
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", "EVK");
> > -	env_set("board_rev", "14X14");
> > +	env_set(ctx_uboot, "board_name", "EVK");
> > +	env_set(ctx_uboot, "board_rev", "14X14");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
> > b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c index
> > a04a73528f8d..4a21c148b696 100644 ---
> > a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c +++
> > b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c @@ -350,7 +350,7 @@ int
> > board_eth_init(bd_t *bis) 
> >  #ifdef CONFIG_VSC7385_ENET
> >  	/* If a VSC7385 microcode image is present, then upload it.
> > */
> > -	tmp = env_get("vscfw_addr");
> > +	tmp = env_get(ctx_uboot, "vscfw_addr");
> >  	if (tmp) {
> >  		vscfw_addr = simple_strtoul(tmp, NULL, 16);
> >  		printf("uploading VSC7385 microcode from %x\n",
> > vscfw_addr); diff --git a/board/freescale/qemu-ppce500/qemu-ppce500.c
> > b/board/freescale/qemu-ppce500/qemu-ppce500.c index
> > fb36d8366c98..38608234b7d5 100644 ---
> > a/board/freescale/qemu-ppce500/qemu-ppce500.c +++
> > b/board/freescale/qemu-ppce500/qemu-ppce500.c @@ -211,10 +211,10 @@
> > int last_stage_init(void) /* -kernel boot */
> >  	prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len);
> >  	if (prop && (len >= 8))
> > -		env_set_hex("qemu_kernel_addr", *prop);
> > +		env_set_hex(ctx_uboot, "qemu_kernel_addr", *prop);
> >  
> >  	/* Give the user a variable for the host fdt */
> > -	env_set_hex("fdt_addr_r", (ulong)fdt);
> > +	env_set_hex("fdt_addr_r", (ctx_uboot, ulong)fdt);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/freescale/t4qds/t4240qds.c
> > b/board/freescale/t4qds/t4240qds.c index bb18b97e6a2e..d4e92d6c8d51
> > 100644 --- a/board/freescale/t4qds/t4240qds.c
> > +++ b/board/freescale/t4qds/t4240qds.c
> > @@ -265,7 +265,7 @@ static int adjust_vdd(ulong vdd_override)
> >  	vdd_target = vdd[vid];
> >  
> >  	/* check override variable for overriding VDD */
> > -	vdd_string = env_get("t4240qds_vdd_mv");
> > +	vdd_string = env_get(ctx_uboot, "t4240qds_vdd_mv");
> >  	if (vdd_override == 0 && vdd_string &&
> >  	    !strict_strtoul(vdd_string, 10, &vdd_string_override))
> >  		vdd_override = vdd_string_override;
> > diff --git a/board/gardena/smart-gateway-at91sam/board.c
> > b/board/gardena/smart-gateway-at91sam/board.c index
> > 3e2da0d6f8e0..499605d5b6a1 100644 ---
> > a/board/gardena/smart-gateway-at91sam/board.c +++
> > b/board/gardena/smart-gateway-at91sam/board.c @@ -15,7 +15,7 @@
> > DECLARE_GLOBAL_DATA_PTR; 
> >  static void at91_prepare_cpu_var(void)
> >  {
> > -	env_set("cpu", get_cpu_name());
> > +	env_set(ctx_uboot, "cpu", get_cpu_name());
> >  }
> >  
> >  int board_late_init(void)
> > diff --git a/board/gardena/smart-gateway-mt7688/board.c
> > b/board/gardena/smart-gateway-mt7688/board.c index
> > bd494c84fc80..fe39187d0738 100644 ---
> > a/board/gardena/smart-gateway-mt7688/board.c +++
> > b/board/gardena/smart-gateway-mt7688/board.c @@ -70,9 +70,9 @@ static
> > bool prepare_uuid_var(const char *fd_ptr, const char *env_var_name,
> > str[i] = errorchar; }
> >  
> > -	env = env_get(env_var_name);
> > +	env = env_get(ctx_uboot, env_var_name);
> >  	if (strcmp(env, str)) {
> > -		env_set(env_var_name, str);
> > +		env_set(ctx_uboot, env_var_name, str);
> >  		env_updated = true;
> >  	}
> >  
> > @@ -134,9 +134,9 @@ static void factory_data_env_config(void)
> >  	if (!is_valid_ethaddr(ptr))
> >  		printf("F-Data:Invalid MAC addr: wifi_mac %s\n",
> > str); 
> > -	env = env_get("wifiaddr");
> > +	env = env_get(ctx_uboot, "wifiaddr");
> >  	if (strcmp(env, str)) {
> > -		env_set("wifiaddr", str);
> > +		env_set(ctx_uboot, "wifiaddr", str);
> >  		env_updated = 1;
> >  	}
> >  
> > @@ -146,9 +146,9 @@ static void factory_data_env_config(void)
> >  	if (!is_valid_ethaddr(ptr))
> >  		printf("F-Data:Invalid MAC addr: eth_mac %s\n", str);
> >  
> > -	env = env_get("ethaddr");
> > +	env = env_get(ctx_uboot, "ethaddr");
> >  	if (strcmp(env, str)) {
> > -		env_set("ethaddr", str);
> > +		env_set(ctx_uboot, "ethaddr", str);
> >  		env_updated = 1;
> >  	}
> >  
> > @@ -161,7 +161,7 @@ static void factory_data_env_config(void)
> >  	/* Check if the environment was updated and needs to get
> > stored */ if (env_updated != 0) {
> >  		printf("F-Data:Values don't match env values ->
> > saving\n");
> > -		env_save();
> > +		env_save(ctx_uboot);
> >  	} else {
> >  		debug("F-Data:Values match current env values\n");
> >  	}
> > @@ -189,7 +189,7 @@ static void copy_or_generate_uuid(char *fd_ptr,
> > const char *env_var_name) char *env;
> >  
> >  	/* Don't use the UUID dest place, as the \0 char won't fit */
> > -	env = env_get(env_var_name);
> > +	env = env_get(ctx_uboot, env_var_name);
> >  	if (env)
> >  		strncpy(str, env, UUID_STR_LEN);
> >  	else
> > diff --git a/board/gateworks/gw_ventana/common.c
> > b/board/gateworks/gw_ventana/common.c index
> > 1240a9da174f..0be40c2336ad 100644 ---
> > a/board/gateworks/gw_ventana/common.c +++
> > b/board/gateworks/gw_ventana/common.c @@ -1477,7 +1477,7 @@ void
> > setup_board_gpio(int board, struct ventana_board_info *info) char
> > arg[10]; size_t len;
> >  	int i;
> > -	int quiet = simple_strtol(env_get("quiet"), NULL, 10);
> > +	int quiet = simple_strtol(env_get(ctx_uboot, "quiet"), NULL,
> > 10); 
> >  	if (board >= GW_UNKNOWN)
> >  		return;
> > diff --git a/board/gateworks/gw_ventana/gw_ventana.c
> > b/board/gateworks/gw_ventana/gw_ventana.c index
> > 8a694a71c90b..6782e6327978 100644 ---
> > a/board/gateworks/gw_ventana/gw_ventana.c +++
> > b/board/gateworks/gw_ventana/gw_ventana.c @@ -299,11 +299,12 @@ int
> > board_eth_init(bd_t *bis) #endif
> >  
> >  	/* default to the first detected enet dev */
> > -	if (!env_get("ethprime")) {
> > +	if (!env_get(ctx_uboot, "ethprime")) {
> >  		struct eth_device *dev = eth_get_dev_by_index(0);
> >  		if (dev) {
> > -			env_set("ethprime", dev->name);
> > -			printf("set ethprime to %s\n",
> > env_get("ethprime"));
> > +			env_set(ctx_uboot, "ethprime", dev->name);
> > +			printf("set ethprime to %s\n",
> > +			       env_get(ctx_uboot, "ethprime"));
> >  		}
> >  	}
> >  
> > @@ -602,7 +603,7 @@ void board_pci_fixup_dev(struct pci_controller
> > *hose, pci_dev_t dev, */
> >  void get_board_serial(struct tag_serialnr *serialnr)
> >  {
> > -	char *serial = env_get("serial#");
> > +	char *serial = env_get(ctx_uboot, "serial#");
> >  
> >  	if (serial) {
> >  		serialnr->high = 0;
> > @@ -685,11 +686,11 @@ int checkboard(void)
> >  	int quiet; /* Quiet or minimal output mode */
> >  
> >  	quiet = 0;
> > -	p = env_get("quiet");
> > +	p = env_get(ctx_uboot, "quiet");
> >  	if (p)
> >  		quiet = simple_strtol(p, NULL, 10);
> >  	else
> > -		env_set("quiet", "0");
> > +		env_set(ctx_uboot, "quiet", "0");
> >  
> >  	puts("\nGateworks Corporation Copyright 2014\n");
> >  	if (info->model[0]) {
> > @@ -764,26 +765,26 @@ int misc_init_r(void)
> >  		else if (is_cpu_type(MXC_CPU_MX6DL) ||
> >  			 is_cpu_type(MXC_CPU_MX6SOLO))
> >  			cputype = "imx6dl";
> > -		env_set("soctype", cputype);
> > +		env_set(ctx_uboot, "soctype", cputype);
> >  		if (8 << (ventana_info.nand_flash_size-1) >= 2048)
> > -			env_set("flash_layout", "large");
> > +			env_set(ctx_uboot, "flash_layout", "large");
> >  		else
> > -			env_set("flash_layout", "normal");
> > +			env_set(ctx_uboot, "flash_layout", "normal");
> >  		memset(str, 0, sizeof(str));
> >  		for (i = 0; i < (sizeof(str)-1) && info->model[i];
> > i++) str[i] = tolower(info->model[i]);
> > -		env_set("model", str);
> > -		if (!env_get("fdt_file")) {
> > +		env_set(ctx_uboot, "model", str);
> > +		if (!env_get(ctx_uboot, "fdt_file")) {
> >  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> > -			env_set("fdt_file", fdt);
> > +			env_set(ctx_uboot, "fdt_file", fdt);
> >  		}
> >  		p = strchr(str, '-');
> >  		if (p) {
> >  			*p++ = 0;
> >  
> > -			env_set("model_base", str);
> > +			env_set(ctx_uboot, "model_base", str);
> >  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> > -			env_set("fdt_file1", fdt);
> > +			env_set(ctx_uboot, "fdt_file1", fdt);
> >  			if (board_type != GW551x &&
> >  			    board_type != GW552x &&
> >  			    board_type != GW553x &&
> > @@ -792,30 +793,30 @@ int misc_init_r(void)
> >  			str[5] = 'x';
> >  			str[6] = 0;
> >  			sprintf(fdt, "%s-%s.dtb", cputype, str);
> > -			env_set("fdt_file2", fdt);
> > +			env_set(ctx_uboot, "fdt_file2", fdt);
> >  		}
> >  
> >  		/* initialize env from EEPROM */
> >  		if (test_bit(EECONFIG_ETH0, info->config) &&
> > -		    !env_get("ethaddr")) {
> > +		    !env_get(ctx_uboot, "ethaddr")) {
> >  			eth_env_set_enetaddr("ethaddr", info->mac0);
> >  		}
> >  		if (test_bit(EECONFIG_ETH1, info->config) &&
> > -		    !env_get("eth1addr")) {
> > +		    !env_get(ctx_uboot, "eth1addr")) {
> >  			eth_env_set_enetaddr("eth1addr", info->mac1);
> >  		}
> >  
> >  		/* board serial-number */
> >  		sprintf(str, "%6d", info->serial);
> > -		env_set("serial#", str);
> > +		env_set(ctx_uboot, "serial#", str);
> >  
> >  		/* memory MB */
> >  		sprintf(str, "%d", (int) (gd->ram_size >> 20));
> > -		env_set("mem_mb", str);
> > +		env_set(ctx_uboot, "mem_mb", str);
> >  	}
> >  
> >  	/* Set a non-initialized hwconfig based on board
> > configuration */
> > -	if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
> > +	if (!strcmp(env_get(ctx_uboot, "hwconfig"), "_UNKNOWN_")) {
> >  		buf[0] = 0;
> >  		if (gpio_cfg[board_type].rs232_en)
> >  			strcat(buf, "rs232;");
> > @@ -825,7 +826,7 @@ int misc_init_r(void)
> >  			if (strlen(buf) + strlen(buf1) < sizeof(buf))
> >  				strcat(buf, buf1);
> >  		}
> > -		env_set("hwconfig", buf);
> > +		env_set(ctx_uboot, "hwconfig", buf);
> >  	}
> >  
> >  	/* setup baseboard specific GPIO based on board and env */
> > @@ -1040,7 +1041,7 @@ int fdt_fixup_sky2(void *blob, int np, struct
> > pci_dev *dev) int j;
> >  
> >  	sprintf(mac, "eth1addr");
> > -	tmp = env_get(mac);
> > +	tmp = env_get(ctx_uboot, mac);
> >  	if (tmp) {
> >  		for (j = 0; j < 6; j++) {
> >  			mac_addr[j] = tmp ?
> > @@ -1128,8 +1129,8 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  		{ "sst,w25q256",          MTD_DEV_TYPE_NOR, },  /*
> > SPI flash */ { "fsl,imx6q-gpmi-nand",  MTD_DEV_TYPE_NAND, }, /* NAND
> > flash */ };
> > -	const char *model = env_get("model");
> > -	const char *display = env_get("display");
> > +	const char *model = env_get(ctx_uboot, "model");
> > +	const char *display = env_get(ctx_uboot, "display");
> >  	int i;
> >  	char rev = 0;
> >  
> > @@ -1141,7 +1142,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  		}
> >  	}
> >  
> > -	if (env_get("fdt_noauto")) {
> > +	if (env_get(ctx_uboot, "fdt_noauto")) {
> >  		puts("   Skiping ft_board_setup (fdt_noauto
> > defined)\n"); return 0;
> >  	}
> > @@ -1162,15 +1163,15 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  	printf("   Adjusting FDT per EEPROM for %s...\n", model);
> >  
> >  	/* board serial number */
> > -	fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
> > -		    strlen(env_get("serial#")) + 1);
> > +	fdt_setprop(blob, 0, "system-serial", env_get(ctx_uboot,
> > "serial#"),
> > +		    strlen(env_get(ctx_uboot, "serial#")) + 1);
> >  
> >  	/* board (model contains model from device-tree) */
> >  	fdt_setprop(blob, 0, "board", info->model,
> >  		    strlen((const char *)info->model) + 1);
> >  
> >  	/* set desired digital video capture format */
> > -	ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
> > +	ft_sethdmiinfmt(blob, env_get(ctx_uboot, "hdmiinfmt"));
> >  
> >  	/*
> >  	 * Board model specific fixups
> > @@ -1340,7 +1341,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  	}
> >  
> >  #if defined(CONFIG_CMD_PCI)
> > -	if (!env_get("nopcifixup"))
> > +	if (!env_get(ctx_uboot, "nopcifixup"))
> >  		ft_board_pci_fixup(blob, bd);
> >  #endif
> >  
> > @@ -1349,7 +1350,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  	 *  remove nodes by alias path if EEPROM config tells us the
> >  	 *  peripheral is not loaded on the board.
> >  	 */
> > -	if (env_get("fdt_noconfig")) {
> > +	if (env_get(ctx_uboot, "fdt_noconfig")) {
> >  		puts("   Skiping periperhal config (fdt_noconfig
> > defined)\n"); return 0;
> >  	}
> > diff --git a/board/gateworks/gw_ventana/gw_ventana_spl.c
> > b/board/gateworks/gw_ventana/gw_ventana_spl.c index
> > b0891379a170..a689ec16d98c 100644 ---
> > a/board/gateworks/gw_ventana/gw_ventana_spl.c +++
> > b/board/gateworks/gw_ventana/gw_ventana_spl.c @@ -758,8 +758,8 @@ int
> > spl_start_uboot(void) debug("%s\n", __func__);
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > -	debug("boot_os=%s\n", env_get("boot_os"));
> > +	env_load(ctx_uboot);
> > +	debug("boot_os=%s\n", env_get(ctx_uboot, "boot_os"));
> >  	if (env_get_yesno("boot_os") == 1)
> >  		ret = 0;
> >  #else
> > diff --git a/board/gdsys/a38x/keyprogram.c
> > b/board/gdsys/a38x/keyprogram.c index 000897984a6e..f65190d814c2
> > 100644 --- a/board/gdsys/a38x/keyprogram.c
> > +++ b/board/gdsys/a38x/keyprogram.c
> > @@ -131,12 +131,12 @@ int load_and_run_keyprog(struct udevice *tpm)
> >  	char *hexprog;
> >  	struct key_program *prog;
> >  
> > -	cmd = env_get("loadkeyprogram");
> > +	cmd = env_get(ctx_uboot, "loadkeyprogram");
> >  
> >  	if (!cmd || run_command(cmd, 0))
> >  		return 1;
> >  
> > -	hexprog = env_get("keyprogram");
> > +	hexprog = env_get(ctx_uboot, "keyprogram");
> >  
> >  	if (decode_hexstr(hexprog, &binprog))
> >  		return 1;
> > diff --git a/board/gdsys/mpc8308/gazerbeam.c
> > b/board/gdsys/mpc8308/gazerbeam.c index ddd6ee895384..4929296364b3
> > 100644 --- a/board/gdsys/mpc8308/gazerbeam.c
> > +++ b/board/gdsys/mpc8308/gazerbeam.c
> > @@ -85,7 +85,7 @@ int board_early_init_r(void)
> >  int checkboard(void)
> >  {
> >  	struct udevice *board;
> > -	char *s = env_get("serial#");
> > +	char *s = env_get(ctx_uboot, "serial#");
> >  	int mc = 0;
> >  	int con = 0;
> >  
> > @@ -137,7 +137,7 @@ int last_stage_init(void)
> >  			printf("Could not determind FPGA HW revision
> > (res = %d)\n", res); }
> >  
> > -	env_set_ulong("fpga_hw_rev", fpga_hw_rev);
> > +	env_set_ulong(ctx_uboot, "fpga_hw_rev", fpga_hw_rev);
> >  
> >  	ret = get_tpm(&tpm);
> >  	if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
> > diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c
> > index 60faa4688cf8..666eb25c809c 100644
> > --- a/board/gdsys/mpc8308/hrcon.c
> > +++ b/board/gdsys/mpc8308/hrcon.c
> > @@ -101,7 +101,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t
> > regoff, u16 *data) 
> >  int checkboard(void)
> >  {
> > -	char *s = env_get("serial#");
> > +	char *s = env_get(ctx_uboot, "serial#");
> >  	bool hw_type_cat = pca9698_get_value(0x20, 20);
> >  
> >  	puts("Board: ");
> > diff --git a/board/gdsys/mpc8308/strider.c
> > b/board/gdsys/mpc8308/strider.c index 886bc2b035de..cc3fcd7de172
> > 100644 --- a/board/gdsys/mpc8308/strider.c
> > +++ b/board/gdsys/mpc8308/strider.c
> > @@ -104,7 +104,7 @@ int fpga_get_reg(u32 fpga, u16 *reg, off_t
> > regoff, u16 *data) 
> >  int checkboard(void)
> >  {
> > -	char *s = env_get("serial#");
> > +	char *s = env_get(ctx_uboot, "serial#");
> >  	bool hw_type_cat = pca9698_get_value(0x20, 18);
> >  
> >  	puts("Board: ");
> > diff --git a/board/gdsys/p1022/controlcenterd-id.c
> > b/board/gdsys/p1022/controlcenterd-id.c index
> > 43f5404231f0..db7c92446e75 100644 ---
> > a/board/gdsys/p1022/controlcenterd-id.c +++
> > b/board/gdsys/p1022/controlcenterd-id.c @@ -231,7 +231,7 @@ static u8
> > *get_2nd_stage_bl_location(ulong target_addr) {
> >  	ulong addr;
> >  #ifdef CCDM_SECOND_STAGE
> > -	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
> > +	addr = env_get_ulong(ctx_uboot, "loadaddr", 16,
> > CONFIG_LOADADDR); #else
> >  	addr = target_addr;
> >  #endif
> > @@ -249,7 +249,7 @@ static u8 *get_image_location(void)
> >  {
> >  	ulong addr;
> >  	/* TODO use other area? */
> > -	addr = env_get_ulong("loadaddr", 16, CONFIG_LOADADDR);
> > +	addr = env_get_ulong(ctx_uboot, "loadaddr", 16,
> > CONFIG_LOADADDR); return (u8 *)(addr);
> >  }
> >  #endif
> > @@ -1072,13 +1072,13 @@ static int second_stage_init(void)
> >  		goto failure;
> >  
> >  	/* run "prepboot" from env to get "mmcdev" set */
> > -	cptr = env_get("prepboot");
> > +	cptr = env_get(ctx_uboot, "prepboot");
> >  	if (cptr && !run_command(cptr, 0))
> > -		mmcdev = env_get("mmcdev");
> > +		mmcdev = env_get(ctx_uboot, "mmcdev");
> >  	if (!mmcdev)
> >  		goto failure;
> >  
> > -	cptr = env_get("ramdiskimage");
> > +	cptr = env_get(ctx_uboot, "ramdiskimage");
> >  	if (cptr)
> >  		image_path = cptr;
> >  
> > diff --git a/board/gdsys/p1022/controlcenterd.c
> > b/board/gdsys/p1022/controlcenterd.c index 6eb3d6c5d06e..ec349d61ee33
> > 100644 --- a/board/gdsys/p1022/controlcenterd.c
> > +++ b/board/gdsys/p1022/controlcenterd.c
> > @@ -222,7 +222,7 @@ void hw_watchdog_reset(void)
> >  #ifdef CONFIG_TRAILBLAZER
> >  int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const
> > argv[]) {
> > -	return run_command(env_get("bootcmd"), flag);
> > +	return run_command(env_get(ctx_uboot, "bootcmd"), flag);
> >  }
> >  
> >  int board_early_init_r(void)
> > diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
> > index 917ecc4c1816..3262a73d0b80 100644
> > --- a/board/ge/bx50v3/bx50v3.c
> > +++ b/board/ge/bx50v3/bx50v3.c
> > @@ -470,17 +470,17 @@ static void process_vpd(struct vpd_cache *vpd)
> >  
> >  	switch (vpd->product_id) {
> >  	case VPD_PRODUCT_B450:
> > -		env_set("confidx", "1");
> > +		env_set(ctx_uboot, "confidx", "1");
> >  		i210_index = 0;
> >  		fec_index = 1;
> >  		break;
> >  	case VPD_PRODUCT_B650:
> > -		env_set("confidx", "2");
> > +		env_set(ctx_uboot, "confidx", "2");
> >  		i210_index = 0;
> >  		fec_index = 1;
> >  		break;
> >  	case VPD_PRODUCT_B850:
> > -		env_set("confidx", "3");
> > +		env_set(ctx_uboot, "confidx", "3");
> >  		i210_index = 1;
> >  		fec_index = 2;
> >  		break;
> > @@ -647,9 +647,10 @@ int board_late_init(void)
> >  #endif
> >  
> >  	if (is_b850v3())
> > -		env_set("videoargs", "video=DP-1:1024x768 at 60
> > video=HDMI-A-1:1024x768 at 60");
> > +		env_set(ctx_uboot, "videoargs",
> > +			"video=DP-1:1024x768 at 60
> > video=HDMI-A-1:1024x768 at 60"); else
> > -		env_set("videoargs", "video=LVDS-1:1024x768 at 65");
> > +		env_set(ctx_uboot, "videoargs",
> > "video=LVDS-1:1024x768 at 65"); 
> >  	/* board specific pmic init */
> >  	pmic_init();
> > @@ -669,7 +670,7 @@ static void remove_ethaddr_env_var(int index)
> >  	char env_var_name[9];
> >  
> >  	sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr",
> > index);
> > -	env_set(env_var_name, NULL);
> > +	env_set(ctx_uboot, env_var_name, NULL);
> >  }
> >  
> >  int last_stage_init(void)
> > diff --git a/board/ge/common/ge_common.c b/board/ge/common/ge_common.c
> > index 501c8b2daf2a..1d5f7ac39350 100644
> > --- a/board/ge/common/ge_common.c
> > +++ b/board/ge/common/ge_common.c
> > @@ -29,7 +29,7 @@ void check_time(void)
> >  	}
> >  
> >  	if (ret < 0)
> > -		env_set("rtc_status", "RTC_ERROR");
> > +		env_set(ctx_uboot, "rtc_status", "RTC_ERROR");
> >  
> >  	if (tm.tm_year > 2037) {
> >  		tm.tm_sec  = 0;
> > @@ -47,7 +47,7 @@ void check_time(void)
> >  		}
> >  
> >  		if (ret < 0)
> > -			env_set("rtc_status", "RTC_ERROR");
> > +			env_set(ctx_uboot, "rtc_status",
> > "RTC_ERROR"); }
> >  
> >  	i2c_set_bus_num(current_i2c_bus);
> > diff --git a/board/ge/mx53ppd/mx53ppd.c b/board/ge/mx53ppd/mx53ppd.c
> > index 544856729821..f2a76dc1ded8 100644
> > --- a/board/ge/mx53ppd/mx53ppd.c
> > +++ b/board/ge/mx53ppd/mx53ppd.c
> > @@ -274,7 +274,7 @@ int misc_init_r(void)
> >  	else
> >  		cause = "POR";
> >  
> > -	env_set("bootcause", cause);
> > +	env_set(ctx_uboot, "bootcause", cause);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/grinn/chiliboard/board.c
> > b/board/grinn/chiliboard/board.c index c6d53600fa1c..933bdc779601
> > 100644 --- a/board/grinn/chiliboard/board.c
> > +++ b/board/grinn/chiliboard/board.c
> > @@ -117,7 +117,7 @@ int board_late_init(void)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > @@ -133,7 +133,7 @@ int board_late_init(void)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> > diff --git a/board/grinn/liteboard/board.c
> > b/board/grinn/liteboard/board.c index 1558ea4b84f5..53eabe2e4b3b
> > 100644 --- a/board/grinn/liteboard/board.c
> > +++ b/board/grinn/liteboard/board.c
> > @@ -127,7 +127,7 @@ int board_mmc_init(bd_t *bis)
> >  
> >  static int check_mmc_autodetect(void)
> >  {
> > -	char *autodetect_str = env_get("mmcautodetect");
> > +	char *autodetect_str = env_get(ctx_uboot, "mmcautodetect");
> >  
> >  	if ((autodetect_str != NULL) &&
> >  	    (strcmp(autodetect_str, "yes") == 0)) {
> > @@ -146,12 +146,12 @@ void board_late_mmc_init(void)
> >  	if (!check_mmc_autodetect())
> >  		return;
> >  
> > -	env_set_ulong("mmcdev", dev_no);
> > +	env_set_ulong(ctx_uboot, "mmcdev", dev_no);
> >  
> >  	/* Set mmcblk env */
> >  	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
> >  		dev_no);
> > -	env_set("mmcroot", mmcblk);
> > +	env_set(ctx_uboot, "mmcroot", mmcblk);
> >  
> >  	sprintf(cmd, "mmc dev %d", dev_no);
> >  	run_command(cmd, 0);
> > diff --git a/board/highbank/highbank.c b/board/highbank/highbank.c
> > index 9563763dfa53..ef2f6f1f16a8 100644
> > --- a/board/highbank/highbank.c
> > +++ b/board/highbank/highbank.c
> > @@ -80,11 +80,12 @@ int misc_init_r(void)
> >  
> >  	boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
> >  	sprintf(envbuffer, "bootcmd%d", boot_choice);
> > -	if (env_get(envbuffer)) {
> > +	if (env_get(ctx_uboot, envbuffer)) {
> >  		sprintf(envbuffer, "run bootcmd%d", boot_choice);
> > -		env_set("bootcmd", envbuffer);
> > -	} else
> > -		env_set("bootcmd", "");
> > +		env_set(ctx_uboot, "bootcmd", envbuffer);
> > +	} else {
> > +		env_set(ctx_uboot, "bootcmd", "");
> > +	}
> >  
> >  	return 0;
> >  }
> > diff --git a/board/hisilicon/poplar/poplar.c
> > b/board/hisilicon/poplar/poplar.c index 4926419a905a..1177e91a688a
> > 100644 --- a/board/hisilicon/poplar/poplar.c
> > +++ b/board/hisilicon/poplar/poplar.c
> > @@ -177,7 +177,7 @@ int board_usb_init(int index, enum usb_init_type
> > init) 
> >  int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char
> > *name) {
> > -	if (!env_get("serial#"))
> > +	if (!env_get(ctx_uboot, "serial#"))
> >  		g_dnl_set_serialnumber("0123456789POPLAR");
> >  	return 0;
> >  }
> > diff --git a/board/imgtec/ci20/ci20.c b/board/imgtec/ci20/ci20.c
> > index 5368b67b38b6..a34553a7bb3b 100644
> > --- a/board/imgtec/ci20/ci20.c
> > +++ b/board/imgtec/ci20/ci20.c
> > @@ -181,12 +181,12 @@ int misc_init_r(void)
> >  	eth_env_set_enetaddr("ethaddr", otp.mac);
> >  
> >  	/* Put other board information into the environment */
> > -	env_set_ulong("serial#", otp.serial_number);
> > -	env_set_ulong("board_date", otp.date);
> > +	env_set_ulong(ctx_uboot, "serial#", otp.serial_number);
> > +	env_set_ulong(ctx_uboot, "board_date", otp.date);
> >  	manufacturer[0] = otp.manufacturer[0];
> >  	manufacturer[1] = otp.manufacturer[1];
> >  	manufacturer[2] = 0;
> > -	env_set("board_mfr", manufacturer);
> > +	env_set(ctx_uboot, "board_mfr", manufacturer);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/intel/edison/edison.c b/board/intel/edison/edison.c
> > index f56b5b1affef..2de8a4936286 100644
> > --- a/board/intel/edison/edison.c
> > +++ b/board/intel/edison/edison.c
> > @@ -71,14 +71,14 @@ static void assign_serial(void)
> >  
> >  	snprintf(usb0addr, sizeof(usb0addr),
> > "02:00:86:%02x:%02x:%02x", ssn[13], ssn[14], ssn[15]);
> > -	env_set("usb0addr", usb0addr);
> > +	env_set(ctx_uboot, "usb0addr", usb0addr);
> >  
> >  	for (i = 0; i < 16; i++)
> >  		snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
> > -	env_set("serial#", serial);
> > +	env_set(ctx_uboot, "serial#", serial);
> >  
> >  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
> > -	env_save();
> > +	env_save(ctx_uboot);
> >  #endif
> >  }
> >  
> > @@ -93,19 +93,19 @@ static void assign_hardware_id(void)
> >  		printf("Can't retrieve hardware revision\n");
> >  
> >  	snprintf(hardware_id, sizeof(hardware_id), "%02X",
> > v.hardware_id);
> > -	env_set("hardware_id", hardware_id);
> > +	env_set(ctx_uboot, "hardware_id", hardware_id);
> >  
> >  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
> > -	env_save();
> > +	env_save(ctx_uboot);
> >  #endif
> >  }
> >  
> >  int board_late_init(void)
> >  {
> > -	if (!env_get("serial#"))
> > +	if (!env_get(ctx_uboot, "serial#"))
> >  		assign_serial();
> >  
> > -	if (!env_get("hardware_id"))
> > +	if (!env_get(ctx_uboot, "hardware_id"))
> >  		assign_hardware_id();
> >  
> >  	return 0;
> > diff --git a/board/isee/igep003x/board.c b/board/isee/igep003x/board.c
> > index a8c2b121a476..56ecf3497245 100644
> > --- a/board/isee/igep003x/board.c
> > +++ b/board/isee/igep003x/board.c
> > @@ -193,13 +193,13 @@ int board_late_init(void)
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	switch (get_board_revision()) {
> >  		case 0:
> > -			env_set("board_name", "igep0034-lite");
> > +			env_set(ctx_uboot, "board_name",
> > "igep0034-lite"); break;
> >  		case 1:
> > -			env_set("board_name", "igep0034");
> > +			env_set(ctx_uboot, "board_name", "igep0034");
> >  			break;
> >  		default:
> > -			env_set("board_name", "igep0033");
> > +			env_set(ctx_uboot, "board_name", "igep0033");
> >  			break;
> >  	}
> >  #endif
> > diff --git a/board/isee/igep00x0/igep00x0.c
> > b/board/isee/igep00x0/igep00x0.c index 74fc5f08900a..42476b2b657b
> > 100644 --- a/board/isee/igep00x0/igep00x0.c
> > +++ b/board/isee/igep00x0/igep00x0.c
> > @@ -199,8 +199,8 @@ void set_boardname(void)
> >  	int i = get_board_revision();
> >  
> >  	rev[i+1] = 0;
> > -	env_set("board_rev", rev + i);
> > -	env_set("board_name", i < 2 ? "igep0020" : "igep0030");
> > +	env_set(ctx_uboot, "board_rev", rev + i);
> > +	env_set(ctx_uboot, "board_name", i < 2 ? "igep0020" :
> > "igep0030"); }
> >  
> >  /*
> > diff --git a/board/k+p/kp_imx53/kp_id_rev.c
> > b/board/k+p/kp_imx53/kp_id_rev.c index 9dae54dda5fc..5c9258912c89
> > 100644 --- a/board/k+p/kp_imx53/kp_id_rev.c
> > +++ b/board/k+p/kp_imx53/kp_id_rev.c
> > @@ -31,7 +31,7 @@ void show_eeprom(void)
> >  
> >  	if (!strncmp(safe_string, "TQM", 3)) {
> >  		printf("  ID: %s\n", safe_string);
> > -		env_set("boardtype", safe_string);
> > +		env_set(ctx_uboot, "boardtype", safe_string);
> >  	} else {
> >  		puts("  unknown hardware variant\n");
> >  	}
> > @@ -45,7 +45,7 @@ void show_eeprom(void)
> >  
> >  	if (strlen(safe_string) == 8) {
> >  		printf("  SN: %s\n", safe_string);
> > -		env_set("serial#", safe_string);
> > +		env_set(ctx_uboot, "serial#", safe_string);
> >  	} else {
> >  		puts("  unknown serial number\n");
> >  	}
> > @@ -103,18 +103,18 @@ int read_board_id(void)
> >  	sprintf(rev_str, "%02X", rev_id);
> >  	if (rev_id & 0x80) {
> >  		printf("BBoard:4x00 Rev:%s\n", rev_str);
> > -		env_set("boardtype", "ddc");
> > -		env_set("fit_config", "imx53_kb_conf");
> > +		env_set(ctx_uboot, "boardtype", "ddc");
> > +		env_set(ctx_uboot, "fit_config", "imx53_kb_conf");
> >  	} else {
> >  		printf("BBoard:40x0 Rev:%s\n", rev_str);
> > -		env_set("boardtype", "hsc");
> > -		env_set("fit_config", "imx53_kb_40x0_conf");
> > +		env_set(ctx_uboot, "boardtype", "hsc");
> > +		env_set(ctx_uboot, "fit_config",
> > "imx53_kb_40x0_conf"); }
> >  
> > -	sprintf(buf, "kp-%s", env_get("boardtype"));
> > -	env_set("boardname", buf);
> > -	env_set("boardsoc", "imx53");
> > -	env_set("kb53_rev", rev_str);
> > +	sprintf(buf, "kp-%s", env_get(ctx_uboot, "boardtype"));
> > +	env_set(ctx_uboot, "boardname", buf);
> > +	env_set(ctx_uboot, "boardsoc", "imx53");
> > +	env_set(ctx_uboot, "kb53_rev", rev_str);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/k+p/kp_imx53/kp_imx53.c
> > b/board/k+p/kp_imx53/kp_imx53.c index 84cddd489490..36b9b9377f03
> > 100644 --- a/board/k+p/kp_imx53/kp_imx53.c
> > +++ b/board/k+p/kp_imx53/kp_imx53.c
> > @@ -124,9 +124,9 @@ void board_misc_setup(void)
> >  	gpio_direction_input(KEY1);
> >  
> >  	if (gpio_get_value(KEY1))
> > -		env_set("key1", "off");
> > +		env_set(ctx_uboot, "key1", "off");
> >  	else
> > -		env_set("key1", "on");
> > +		env_set(ctx_uboot, "key1", "on");
> >  }
> >  
> >  int board_late_init(void)
> > diff --git a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c
> > b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c index
> > 2c541ace0210..9536ae2171d2 100644 ---
> > a/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c +++
> > b/board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c @@ -290,8 +290,8 @@ int
> > board_late_init(void) add_board_boot_modes(board_boot_modes);
> >  #endif
> >  
> > -	env_set("boardname", "kp-tpc");
> > -	env_set("boardsoc", "imx6q");
> > +	env_set(ctx_uboot, "boardname", "kp-tpc");
> > +	env_set(ctx_uboot, "boardsoc", "imx6q");
> >  	return 0;
> >  }
> >  
> > diff --git a/board/keymile/common/common.c
> > b/board/keymile/common/common.c index 08f7f8d88451..3e15a063b34a
> > 100644 --- a/board/keymile/common/common.c
> > +++ b/board/keymile/common/common.c
> > @@ -51,24 +51,24 @@ int set_km_env(void)
> >  	pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM -
> > CONFIG_KM_PHRAM
> >  			- CONFIG_KM_PNVRAM;
> >  	sprintf((char *)buf, "0x%x", pnvramaddr);
> > -	env_set("pnvramaddr", (char *)buf);
> > +	env_set(ctx_uboot, "pnvramaddr", (char *)buf);
> >  
> >  	/* try to read rootfssize (ram image) from environment */
> > -	p = env_get("rootfssize");
> > +	p = env_get(ctx_uboot, "rootfssize");
> >  	if (p != NULL)
> >  		strict_strtoul(p, 16, &rootfssize);
> >  	pram = (rootfssize + CONFIG_KM_RESERVED_PRAM +
> > CONFIG_KM_PHRAM + CONFIG_KM_PNVRAM) / 0x400;
> >  	sprintf((char *)buf, "0x%x", pram);
> > -	env_set("pram", (char *)buf);
> > +	env_set(ctx_uboot, "pram", (char *)buf);
> >  
> >  	varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM -
> > CONFIG_KM_PHRAM; sprintf((char *)buf, "0x%x", varaddr);
> > -	env_set("varaddr", (char *)buf);
> > +	env_set(ctx_uboot, "varaddr", (char *)buf);
> >  
> >  	kernelmem = gd->ram_size - 0x400 * pram;
> >  	sprintf((char *)buf, "0x%x", kernelmem);
> > -	env_set("kernelmem", (char *)buf);
> > +	env_set(ctx_uboot, "kernelmem", (char *)buf);
> >  
> >  	return 0;
> >  }
> > @@ -169,7 +169,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int
> > flag, int argc, return 1;
> >  	}
> >  	strcpy((char *)buf, p);
> > -	env_set("boardid", (char *)buf);
> > +	env_set(ctx_uboot, "boardid", (char *)buf);
> >  	printf("set boardid=%s\n", buf);
> >  
> >  	p = get_local_var("IVM_HWKey");
> > @@ -178,7 +178,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int
> > flag, int argc, return 1;
> >  	}
> >  	strcpy((char *)buf, p);
> > -	env_set("hwkey", (char *)buf);
> > +	env_set(ctx_uboot, "hwkey", (char *)buf);
> >  	printf("set hwkey=%s\n", buf);
> >  	printf("Execute manually saveenv for persistent storage.\n");
> >  
> > @@ -236,10 +236,10 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> > int flag, int argc, }
> >  
> >  	/* now try to read values from environment if available */
> > -	p = env_get("boardid");
> > +	p = env_get(ctx_uboot, "boardid");
> >  	if (p != NULL)
> >  		rc = strict_strtoul(p, 16, &envbid);
> > -	p = env_get("hwkey");
> > +	p = env_get(ctx_uboot, "hwkey");
> >  	if (p != NULL)
> >  		rc = strict_strtoul(p, 16, &envhwkey);
> >  
> > @@ -253,7 +253,7 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> > int flag, int argc,
> >  		 * BoardId/HWkey not available in the environment,
> > so try the
> >  		 * environment variable for BoardId/HWkey list
> >  		 */
> > -		char *bidhwklist = env_get("boardIdListHex");
> > +		char *bidhwklist = env_get(ctx_uboot,
> > "boardIdListHex"); 
> >  		if (bidhwklist) {
> >  			int found = 0;
> > @@ -311,9 +311,9 @@ static int do_checkboardidhwk(cmd_tbl_t *cmdtp,
> > int flag, int argc, envbid   = bid;
> >  					envhwkey = hwkey;
> >  					sprintf(buf, "%lx", bid);
> > -					env_set("boardid", buf);
> > +					env_set(ctx_uboot,
> > "boardid", buf); sprintf(buf, "%lx", hwkey);
> > -					env_set("hwkey", buf);
> > +					env_set(ctx_uboot, "hwkey",
> > buf); }
> >  			} /* end while( ! found ) */
> >  		}
> > @@ -355,7 +355,7 @@ static int do_checktestboot(cmd_tbl_t *cmdtp, int
> > flag, int argc, #if defined(CONFIG_POST)
> >  	testpin = post_hotkeys_pressed();
> >  #endif
> > -	s = env_get("test_bank");
> > +	s = env_get(ctx_uboot, "test_bank");
> >  	/* when test_bank is not set, act as if testpin is not
> > asserted */ testboot = (testpin != 0) && (s);
> >  	if (verbose) {
> > diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c
> > index 50df44d1c110..d255a34ae677 100644
> > --- a/board/keymile/common/ivm.c
> > +++ b/board/keymile/common/ivm.c
> > @@ -261,7 +261,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int
> > len) 
> >  	GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8)
> >  	GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64)
> > -	tmp = (unsigned char *)env_get("IVM_DeviceName");
> > +	tmp = (unsigned char *)env_get(ctx_uboot, "IVM_DeviceName");
> >  	if (tmp) {
> >  		int	len = strlen((char *)tmp);
> >  		int	i = 0;
> > @@ -310,16 +310,16 @@ static int ivm_populate_env(unsigned char *buf,
> > int len) #ifndef CONFIG_KMTEGR1
> >  	/* if an offset is defined, add it */
> >  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> > true);
> > -	env_set((char *)"ethaddr", (char *)valbuf);
> > +	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
> >  #else
> >  /* KMTEGR1 has a special setup. eth0 has no connection to the
> > outside and
> >   * gets an locally administred MAC address, eth1 is the debug
> > interface and
> >   * gets the official MAC address from the IVM
> >   */
> >  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> > false);
> > -	env_set((char *)"ethaddr", (char *)valbuf);
> > +	env_set(ctx_uboot, (char *)"ethaddr", (char *)valbuf);
> >  	process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET,
> > true);
> > -	env_set((char *)"eth1addr", (char *)valbuf);
> > +	env_set(ctx_uboot, (char *)"eth1addr", (char *)valbuf);
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/keymile/km83xx/km83xx.c
> > b/board/keymile/km83xx/km83xx.c index 8846b64f7d79..68a1ddb886b9
> > 100644 --- a/board/keymile/km83xx/km83xx.c
> > +++ b/board/keymile/km83xx/km83xx.c
> > @@ -199,7 +199,7 @@ int last_stage_init(void)
> >  	if (dip_switch != 0) {
> >  		/* start bootloader */
> >  		puts("DIP:   Enabled\n");
> > -		env_set("actual_bank", "0");
> > +		env_set(ctx_uboot, "actual_bank", "0");
> >  	}
> >  #endif
> >  	set_km_env();
> > diff --git a/board/keymile/km_arm/km_arm.c
> > b/board/keymile/km_arm/km_arm.c index 922cc621f780..0c2ede5231bb
> > 100644 --- a/board/keymile/km_arm/km_arm.c
> > +++ b/board/keymile/km_arm/km_arm.c
> > @@ -193,7 +193,7 @@ static void set_bootcount_addr(void)
> >  	unsigned int bootcountaddr;
> >  	bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
> >  	sprintf((char *)buf, "0x%x", bootcountaddr);
> > -	env_set("bootcountaddr", (char *)buf);
> > +	env_set(ctx_uboot, "bootcountaddr", (char *)buf);
> >  }
> >  
> >  int misc_init_r(void)
> > @@ -201,7 +201,7 @@ int misc_init_r(void)
> >  #if defined(CONFIG_KM_MGCOGE3UN)
> >  	char *wait_for_ne;
> >  	u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
> > -	wait_for_ne = env_get("waitforne");
> > +	wait_for_ne = env_get(ctx_uboot, "waitforne");
> >  
> >  	if ((wait_for_ne != NULL) && (dip_switch == 0)) {
> >  		if (strcmp(wait_for_ne, "true") == 0) {
> > @@ -299,7 +299,7 @@ int board_late_init(void)
> >  	if (dip_switch != 0) {
> >  		/* start bootloader */
> >  		puts("DIP:   Enabled\n");
> > -		env_set("actual_bank", "0");
> > +		env_set(ctx_uboot, "actual_bank", "0");
> >  	}
> >  #endif
> >  
> > diff --git a/board/keymile/kmp204x/kmp204x.c
> > b/board/keymile/kmp204x/kmp204x.c index 4d1e38aa3a7a..f4901f6bed9d
> > 100644 --- a/board/keymile/kmp204x/kmp204x.c
> > +++ b/board/keymile/kmp204x/kmp204x.c
> > @@ -220,7 +220,7 @@ int last_stage_init(void)
> >  	if (dip_switch != 0) {
> >  		/* start bootloader */
> >  		puts("DIP:   Enabled\n");
> > -		env_set("actual_bank", "0");
> > +		env_set(ctx_uboot, "actual_bank", "0");
> >  	}
> >  #endif
> >  	set_km_env();
> > @@ -237,7 +237,7 @@ void fdt_fixup_fman_mac_addresses(void *blob)
> >  	unsigned char mac_addr[6];
> >  
> >  	/* get the mac addr from env */
> > -	tmp = env_get("ethaddr");
> > +	tmp = env_get(ctx_uboot, "ethaddr");
> >  	if (!tmp) {
> >  		printf("ethaddr env variable not defined\n");
> >  		return;
> > diff --git a/board/kosagi/novena/novena.c
> > b/board/kosagi/novena/novena.c index b7b747d19658..968d455b45c6 100644
> > --- a/board/kosagi/novena/novena.c
> > +++ b/board/kosagi/novena/novena.c
> > @@ -201,7 +201,7 @@ int misc_init_r(void)
> >  	int ret;
> >  
> >  	/* If 'ethaddr' is already set, do nothing. */
> > -	if (env_get("ethaddr"))
> > +	if (env_get(ctx_uboot, "ethaddr"))
> >  		return 0;
> >  
> >  	/* EEPROM is at bus 2. */
> > diff --git a/board/laird/wb50n/wb50n.c b/board/laird/wb50n/wb50n.c
> > index a2f8eaf0ba34..cc7cd3cf7250 100644
> > --- a/board/laird/wb50n/wb50n.c
> > +++ b/board/laird/wb50n/wb50n.c
> > @@ -122,7 +122,7 @@ int board_late_init(void)
> >  	for (p = name; *p != '\0'; *p = tolower(*p), p++)
> >  		;
> >  	strcat(name, "-wb50n");
> > -	env_set(LAIRD_NAME, name);
> > +	env_set(ctx_uboot, LAIRD_NAME, name);
> >  
> >  #endif
> >  
> > diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c
> > index b4205d6ed4c1..0dff96ef02aa 100644
> > --- a/board/lg/sniper/sniper.c
> > +++ b/board/lg/sniper/sniper.c
> > @@ -133,8 +133,8 @@ int misc_init_r(void)
> >  	}
> >  
> >  	if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
> > -		if (!env_get("reboot-mode"))
> > -			env_set("reboot-mode", (char *)reboot_mode);
> > +		if (!env_get(ctx_uboot, "reboot-mode"))
> > +			env_set(ctx_uboot, "reboot-mode", (char
> > *)reboot_mode); }
> >  
> >  	omap_reboot_mode_clear();
> > diff --git a/board/liebherr/display5/spl.c
> > b/board/liebherr/display5/spl.c index 354b63e431f6..6ce1554e044d
> > 100644 --- a/board/liebherr/display5/spl.c
> > +++ b/board/liebherr/display5/spl.c
> > @@ -284,10 +284,10 @@ void board_boot_order(u32 *spl_boot_list)
> >  	/* 'fastboot' */
> >  	const char *s;
> >  
> > -	if (env_init() || env_load())
> > +	if (env_init() || env_load(ctx_uboot))
> >  		return;
> >  
> > -	s = env_get("BOOT_FROM");
> > +	s = env_get(ctx_uboot, "BOOT_FROM");
> >  	if (s && !bootcount_error() && strcmp(s, "ACTIVE") == 0) {
> >  		spl_boot_list[0] = BOOT_DEVICE_MMC1;
> >  		spl_boot_list[1] = spl_boot_device();
> > diff --git a/board/liebherr/mccmon6/mccmon6.c
> > b/board/liebherr/mccmon6/mccmon6.c index 7d2751ab0393..6164317e607c
> > 100644 --- a/board/liebherr/mccmon6/mccmon6.c
> > +++ b/board/liebherr/mccmon6/mccmon6.c
> > @@ -367,7 +367,7 @@ int board_init(void)
> >  
> >  int board_late_init(void)
> >  {
> > -	env_set("board_name", "mccmon6");
> > +	env_set(ctx_uboot, "board_name", "mccmon6");
> >  
> >  	return 0;
> >  }
> > @@ -467,7 +467,7 @@ int spl_start_uboot(void)
> >  		return 1;
> >  
> >  	env_init();
> > -	ret = env_get_f("boot_os", s, sizeof(s));
> > +	ret = env_get_f("boot_os", s, sizeof(ctx_uboot, s));
> >  	if ((ret != -1) && (strcmp(s, "no") == 0))
> >  		return 1;
> >  
> > @@ -481,7 +481,7 @@ int spl_start_uboot(void)
> >  	 * recovery_status = <any value> -> start SWUpdate
> >  	 *
> >  	 */
> > -	ret = env_get_f("recovery_status", s, sizeof(s));
> > +	ret = env_get_f("recovery_status", s, sizeof(ctx_uboot, s));
> >  	if (ret != -1)
> >  		return 1;
> >  
> > diff --git a/board/logicpd/imx6/imx6logic.c
> > b/board/logicpd/imx6/imx6logic.c index 7a59b89d94a2..204a92761459
> > 100644 --- a/board/logicpd/imx6/imx6logic.c
> > +++ b/board/logicpd/imx6/imx6logic.c
> > @@ -149,12 +149,12 @@ int board_init(void)
> >  
> >  int board_late_init(void)
> >  {
> > -	env_set("board_name", "imx6logic");
> > +	env_set(ctx_uboot, "board_name", "imx6logic");
> >  
> >  	if (is_mx6dq()) {
> > -		env_set("board_rev", "MX6DQ");
> > -		if (!env_get("fdt_file"))
> > -			env_set("fdt_file", "imx6q-logicpd.dtb");
> > +		env_set(ctx_uboot, "board_rev", "MX6DQ");
> > +		if (!env_get(ctx_uboot, "fdt_file"))
> > +			env_set(ctx_uboot, "fdt_file",
> > "imx6q-logicpd.dtb"); }
> >  
> >  	return 0;
> > diff --git a/board/menlo/m53menlo/m53menlo.c
> > b/board/menlo/m53menlo/m53menlo.c index bda5f0df5bce..f84e0f7d5928
> > 100644 --- a/board/menlo/m53menlo/m53menlo.c
> > +++ b/board/menlo/m53menlo/m53menlo.c
> > @@ -339,7 +339,7 @@ int board_late_init(void)
> >  
> >  	splash_get_pos(&xpos, &ypos);
> >  
> > -	s = env_get("splashimage");
> > +	s = env_get(ctx_uboot, "splashimage");
> >  	if (!s)
> >  		return 0;
> >  
> > diff --git a/board/micronas/vct/vct.c b/board/micronas/vct/vct.c
> > index e73d16db3eaf..6ae3dceaef87 100644
> > --- a/board/micronas/vct/vct.c
> > +++ b/board/micronas/vct/vct.c
> > @@ -72,7 +72,7 @@ int dram_init(void)
> >  int checkboard(void)
> >  {
> >  	char buf[64];
> > -	int i = env_get_f("serial#", buf, sizeof(buf));
> > +	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
> >  	u32 config0 = read_c0_prid();
> >  
> >  	if ((config0 & 0xff0000) == PRID_COMP_LEGACY
> > diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
> > index 71ca79deab7f..ca486eab1e29 100644
> > --- a/board/nokia/rx51/rx51.c
> > +++ b/board/nokia/rx51/rx51.c
> > @@ -234,18 +234,18 @@ void setup_board_tags(struct tag **in_params)
> >  	params->u.core.rootdev = 0x0;
> >  
> >  	/* append omap atag only if env setup_omap_atag is set to 1
> > */
> > -	str = env_get("setup_omap_atag");
> > +	str = env_get(ctx_uboot, "setup_omap_atag");
> >  	if (!str || str[0] != '1')
> >  		return;
> >  
> > -	str = env_get("setup_console_atag");
> > +	str = env_get(ctx_uboot, "setup_console_atag");
> >  	if (str && str[0] == '1')
> >  		setup_console_atag = 1;
> >  	else
> >  		setup_console_atag = 0;
> >  
> > -	setup_boot_reason_atag = env_get("setup_boot_reason_atag");
> > -	setup_boot_mode_atag = env_get("setup_boot_mode_atag");
> > +	setup_boot_reason_atag = env_get(ctx_uboot,
> > "setup_boot_reason_atag");
> > +	setup_boot_mode_atag = env_get(ctx_uboot,
> > "setup_boot_mode_atag"); 
> >  	params = *in_params;
> >  	t = (struct tag_omap *)&params->u;
> > @@ -413,7 +413,7 @@ int misc_init_r(void)
> >  
> >  	/* set env variable attkernaddr for relocated kernel */
> >  	sprintf(buf, "%#x", KERNEL_ADDRESS);
> > -	env_set("attkernaddr", buf);
> > +	env_set(ctx_uboot, "attkernaddr", buf);
> >  
> >  	/* initialize omap tags */
> >  	init_omap_tags();
> > diff --git a/board/overo/overo.c b/board/overo/overo.c
> > index 442028a764c7..f0b230eabb13 100644
> > --- a/board/overo/overo.c
> > +++ b/board/overo/overo.c
> > @@ -170,47 +170,47 @@ int misc_init_r(void)
> >  			expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "dvi");
> > -		env_set("expansionname", "summit");
> > +		env_set(ctx_uboot, "defaultdisplay", "dvi");
> > +		env_set(ctx_uboot, "expansionname", "summit");
> >  		break;
> >  	case GUMSTIX_TOBI:
> >  		printf("Recognized Tobi expansion board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "dvi");
> > -		env_set("expansionname", "tobi");
> > +		env_set(ctx_uboot, "defaultdisplay", "dvi");
> > +		env_set(ctx_uboot, "expansionname", "tobi");
> >  		break;
> >  	case GUMSTIX_TOBI_DUO:
> >  		printf("Recognized Tobi Duo expansion board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("expansionname", "tobiduo");
> > +		env_set(ctx_uboot, "expansionname", "tobiduo");
> >  		break;
> >  	case GUMSTIX_PALO35:
> >  		printf("Recognized Palo35 expansion board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "lcd35");
> > -		env_set("expansionname", "palo35");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd35");
> > +		env_set(ctx_uboot, "expansionname", "palo35");
> >  		break;
> >  	case GUMSTIX_PALO43:
> >  		printf("Recognized Palo43 expansion board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "lcd43");
> > -		env_set("expansionname", "palo43");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> > +		env_set(ctx_uboot, "expansionname", "palo43");
> >  		break;
> >  	case GUMSTIX_CHESTNUT43:
> >  		printf("Recognized Chestnut43 expansion board (rev
> > %d %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "lcd43");
> > -		env_set("expansionname", "chestnut43");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> > +		env_set(ctx_uboot, "expansionname", "chestnut43");
> >  		break;
> >  	case GUMSTIX_PINTO:
> >  		printf("Recognized Pinto expansion board (rev %d
> > %s)\n", @@ -223,8 +223,8 @@ int misc_init_r(void)
> >  			expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> > -		env_set("defaultdisplay", "lcd43");
> > -		env_set("expansionname", "gallop43");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> > +		env_set(ctx_uboot, "expansionname", "gallop43");
> >  		break;
> >  	case GUMSTIX_ALTO35:
> >  		printf("Recognized Alto35 expansion board (rev %d
> > %s)\n", @@ -232,8 +232,8 @@ int misc_init_r(void)
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> >  		MUX_ALTO35();
> > -		env_set("defaultdisplay", "lcd35");
> > -		env_set("expansionname", "alto35");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd35");
> > +		env_set(ctx_uboot, "expansionname", "alto35");
> >  		break;
> >  	case GUMSTIX_STAGECOACH:
> >  		printf("Recognized Stagecoach expansion board (rev
> > %d %s)\n", @@ -259,8 +259,8 @@ int misc_init_r(void)
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> >  		MUX_ARBOR43C();
> > -		env_set("defaultdisplay", "lcd43");
> > -		env_set("expansionname", "arbor43c");
> > +		env_set(ctx_uboot, "defaultdisplay", "lcd43");
> > +		env_set(ctx_uboot, "expansionname", "arbor43c");
> >  		break;
> >  	case ETTUS_USRP_E:
> >  		printf("Recognized Ettus Research USRP-E (rev %d
> > %s)\n", @@ -268,13 +268,13 @@ int misc_init_r(void)
> >  			expansion_config.fab_revision);
> >  		MUX_GUMSTIX();
> >  		MUX_USRP_E();
> > -		env_set("defaultdisplay", "dvi");
> > +		env_set(ctx_uboot, "defaultdisplay", "dvi");
> >  		break;
> >  	case GUMSTIX_NO_EEPROM:
> >  	case GUMSTIX_EMPTY_EEPROM:
> >  		puts("No or empty EEPROM on expansion board\n");
> >  		MUX_GUMSTIX();
> > -		env_set("expansionname", "tobi");
> > +		env_set(ctx_uboot, "expansionname", "tobi");
> >  		break;
> >  	default:
> >  		printf("Unrecognized expansion board 0x%08x\n",
> > expansion_id); @@ -282,14 +282,15 @@ int misc_init_r(void)
> >  	}
> >  
> >  	if (expansion_config.content == 1)
> > -		env_set(expansion_config.env_var,
> > expansion_config.env_setting);
> > +		env_set(ctx_uboot, expansion_config.env_var,
> > +			expansion_config.env_setting);
> >  
> >  	omap_die_id_display();
> >  
> >  	if (get_cpu_family() == CPU_OMAP34XX)
> > -		env_set("boardname", "overo");
> > +		env_set(ctx_uboot, "boardname", "overo");
> >  	else
> > -		env_set("boardname", "overo-storm");
> > +		env_set(ctx_uboot, "boardname", "overo-storm");
> >  
> >  	return 0;
> >  }
> > diff --git a/board/phytec/pcm052/pcm052.c
> > b/board/phytec/pcm052/pcm052.c index e1ebe8e75d00..f66bacfb2172 100644
> > --- a/board/phytec/pcm052/pcm052.c
> > +++ b/board/phytec/pcm052/pcm052.c
> > @@ -376,8 +376,8 @@ int board_late_init(void)
> >  	if ((reg & SRC_SBMR1_BOOTCFG1_SDMMC) &&
> >  	    !(reg & SRC_SBMR1_BOOTCFG1_MMC)) {
> >  		printf("------ SD card boot -------\n");
> > -		env_set_default("!LVFBootloader", 0);
> > -		env_set("bootcmd",
> > +		env_set_default(ctx_uboot, "!LVFBootloader", 0);
> > +		env_set(ctx_uboot, "bootcmd",
> >  			"run prepare_install_bk4r1_envs; run
> > install_bk4r1rs"); }
> >  
> > diff --git a/board/phytec/pfla02/pfla02.c
> > b/board/phytec/pfla02/pfla02.c index ae9ffe0390c3..bbcd8cf934d3 100644
> > --- a/board/phytec/pfla02/pfla02.c
> > +++ b/board/phytec/pfla02/pfla02.c
> > @@ -392,7 +392,7 @@ int board_late_init(void)
> >  #endif
> >  
> >  	snprintf(buf, sizeof(buf), "%d", get_board_rev());
> > -	env_set("board_rev", buf);
> > +	env_set(ctx_uboot, "board_rev", buf);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/qualcomm/dragonboard410c/dragonboard410c.c
> > b/board/qualcomm/dragonboard410c/dragonboard410c.c index
> > d7f0f93fb109..bdf6e13ad06f 100644 ---
> > a/board/qualcomm/dragonboard410c/dragonboard410c.c +++
> > b/board/qualcomm/dragonboard410c/dragonboard410c.c @@ -139,8 +139,8
> > @@ int misc_init_r(void) }
> >  
> >  	if (dm_gpio_get_value(&resin)) {
> > -		env_set("bootdelay", "-1");
> > -		env_set("bootcmd", "fastboot 0");
> > +		env_set(ctx_uboot, "bootdelay", "-1");
> > +		env_set(ctx_uboot, "bootcmd", "fastboot 0");
> >  		printf("key_vol_down pressed - Starting
> > fastboot.\n"); }
> >  
> > @@ -158,7 +158,7 @@ int board_late_init(void)
> >  
> >  	memset(serial, 0, 16);
> >  	snprintf(serial, 13, "%x", msm_board_serial());
> > -	env_set("serial#", serial);
> > +	env_set(ctx_uboot, "serial#", serial);
> >  	return 0;
> >  }
> >  
> > diff --git a/board/qualcomm/dragonboard820c/dragonboard820c.c
> > b/board/qualcomm/dragonboard820c/dragonboard820c.c index
> > 7a889646df8d..475e1aa64560 100644 ---
> > a/board/qualcomm/dragonboard820c/dragonboard820c.c +++
> > b/board/qualcomm/dragonboard820c/dragonboard820c.c @@ -155,7 +155,7
> > @@ int misc_init_r(void) }
> >  
> >  	if (dm_gpio_get_value(&resin)) {
> > -		env_set("bootdelay", "-1");
> > +		env_set(ctx_uboot, "bootdelay", "-1");
> >  		printf("Power button pressed - dropping to
> > console.\n"); }
> >  
> > diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
> > index 7a6ca8f759e6..5d4d59fd25ca 100644
> > --- a/board/raspberrypi/rpi/rpi.c
> > +++ b/board/raspberrypi/rpi/rpi.c
> > @@ -290,11 +290,11 @@ static void set_fdtfile(void)
> >  {
> >  	const char *fdtfile;
> >  
> > -	if (env_get("fdtfile"))
> > +	if (env_get(ctx_uboot, "fdtfile"))
> >  		return;
> >  
> >  	fdtfile = model->fdtfile;
> > -	env_set("fdtfile", fdtfile);
> > +	env_set(ctx_uboot, "fdtfile", fdtfile);
> >  }
> >  
> >  /*
> > @@ -303,13 +303,13 @@ static void set_fdtfile(void)
> >   */
> >  static void set_fdt_addr(void)
> >  {
> > -	if (env_get("fdt_addr"))
> > +	if (env_get(ctx_uboot, "fdt_addr"))
> >  		return;
> >  
> >  	if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
> >  		return;
> >  
> > -	env_set_hex("fdt_addr", fw_dtb_pointer);
> > +	env_set_hex(ctx_uboot, "fdt_addr", fw_dtb_pointer);
> >  }
> >  
> >  /*
> > @@ -330,7 +330,7 @@ static void set_usbethaddr(void)
> >  	if (!model->has_onboard_eth)
> >  		return;
> >  
> > -	if (env_get("usbethaddr"))
> > +	if (env_get(ctx_uboot, "usbethaddr"))
> >  		return;
> >  
> >  	BCM2835_MBOX_INIT_HDR(msg);
> > @@ -345,8 +345,8 @@ static void set_usbethaddr(void)
> >  
> >  	eth_env_set_enetaddr("usbethaddr",
> > msg->get_mac_address.body.resp.mac); 
> > -	if (!env_get("ethaddr"))
> > -		env_set("ethaddr", env_get("usbethaddr"));
> > +	if (!env_get(ctx_uboot, "ethaddr"))
> > +		env_set(ctx_uboot, "ethaddr", env_get("usbethaddr"));
> >  
> >  	return;
> >  }
> > @@ -357,13 +357,13 @@ static void set_board_info(void)
> >  	char s[11];
> >  
> >  	snprintf(s, sizeof(s), "0x%X", revision);
> > -	env_set("board_revision", s);
> > +	env_set(ctx_uboot, "board_revision", s);
> >  	snprintf(s, sizeof(s), "%d", rev_scheme);
> > -	env_set("board_rev_scheme", s);
> > +	env_set(ctx_uboot, "board_rev_scheme", s);
> >  	/* Can't rename this to board_rev_type since it's an ABI for
> > scripts */ snprintf(s, sizeof(s), "0x%X", rev_type);
> > -	env_set("board_rev", s);
> > -	env_set("board_name", model->name);
> > +	env_set(ctx_uboot, "board_rev", s);
> > +	env_set(ctx_uboot, "board_name", model->name);
> >  }
> >  #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
> >  
> > @@ -373,7 +373,7 @@ static void set_serial_number(void)
> >  	int ret;
> >  	char serial_string[17] = { 0 };
> >  
> > -	if (env_get("serial#"))
> > +	if (env_get(ctx_uboot, "serial#"))
> >  		return;
> >  
> >  	BCM2835_MBOX_INIT_HDR(msg);
> > @@ -388,7 +388,7 @@ static void set_serial_number(void)
> >  
> >  	snprintf(serial_string, sizeof(serial_string), "%016llx",
> >  		 msg->get_board_serial.body.resp.serial);
> > -	env_set("serial#", serial_string);
> > +	env_set(ctx_uboot, "serial#", serial_string);
> >  }
> >  
> >  int misc_init_r(void)
> > diff --git a/board/renesas/alt/alt.c b/board/renesas/alt/alt.c
> > index 10ef7f931b1f..bc94a22e9603 100644
> > --- a/board/renesas/alt/alt.c
> > +++ b/board/renesas/alt/alt.c
> > @@ -128,7 +128,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/gose/gose.c b/board/renesas/gose/gose.c
> > index f86c9f1a6350..d3ec352e2a03 100644
> > --- a/board/renesas/gose/gose.c
> > +++ b/board/renesas/gose/gose.c
> > @@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/koelsch/koelsch.c
> > b/board/renesas/koelsch/koelsch.c index 841d337f4d3c..871308e405d3
> > 100644 --- a/board/renesas/koelsch/koelsch.c
> > +++ b/board/renesas/koelsch/koelsch.c
> > @@ -136,7 +136,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/lager/lager.c b/board/renesas/lager/lager.c
> > index 3cb1a56142a9..6867ae5c4008 100644
> > --- a/board/renesas/lager/lager.c
> > +++ b/board/renesas/lager/lager.c
> > @@ -145,7 +145,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/porter/porter.c
> > b/board/renesas/porter/porter.c index 86f79da7fdb4..3dc9310e0fc4
> > 100644 --- a/board/renesas/porter/porter.c
> > +++ b/board/renesas/porter/porter.c
> > @@ -134,7 +134,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/sh7752evb/sh7752evb.c
> > b/board/renesas/sh7752evb/sh7752evb.c index
> > d0b850f35d49..540ec9bfd019 100644 ---
> > a/board/renesas/sh7752evb/sh7752evb.c +++
> > b/board/renesas/sh7752evb/sh7752evb.c @@ -223,10 +223,10 @@ static
> > void init_ethernet_mac(void) for (i = 0; i <
> > SH7752EVB_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
> >  		if (i == 0)
> > -			env_set("ethaddr", mac_string);
> > +			env_set(ctx_uboot, "ethaddr", mac_string);
> >  		else {
> >  			sprintf(env_string, "eth%daddr", i);
> > -			env_set(env_string, mac_string);
> > +			env_set(ctx_uboot, env_string, mac_string);
> >  		}
> >  		set_mac_to_sh_giga_eth_register(i, mac_string);
> >  	}
> > diff --git a/board/renesas/sh7753evb/sh7753evb.c
> > b/board/renesas/sh7753evb/sh7753evb.c index
> > e1bed7dcc371..3ec2591cb7ed 100644 ---
> > a/board/renesas/sh7753evb/sh7753evb.c +++
> > b/board/renesas/sh7753evb/sh7753evb.c @@ -239,10 +239,10 @@ static
> > void init_ethernet_mac(void) for (i = 0; i <
> > SH7753EVB_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
> >  		if (i == 0)
> > -			env_set("ethaddr", mac_string);
> > +			env_set(ctx_uboot, "ethaddr", mac_string);
> >  		else {
> >  			sprintf(env_string, "eth%daddr", i);
> > -			env_set(env_string, mac_string);
> > +			env_set(ctx_uboot, env_string, mac_string);
> >  		}
> >  		set_mac_to_sh_giga_eth_register(i, mac_string);
> >  	}
> > diff --git a/board/renesas/sh7757lcr/sh7757lcr.c
> > b/board/renesas/sh7757lcr/sh7757lcr.c index
> > d2671202e981..4b06387d5f22 100644 ---
> > a/board/renesas/sh7757lcr/sh7757lcr.c +++
> > b/board/renesas/sh7757lcr/sh7757lcr.c @@ -285,10 +285,10 @@ static
> > void init_ethernet_mac(void) for (i = 0; i <
> > SH7757LCR_ETHERNET_NUM_CH; i++) { get_sh_eth_mac(i, mac_string, buf);
> >  		if (i == 0)
> > -			env_set("ethaddr", mac_string);
> > +			env_set(ctx_uboot, "ethaddr", mac_string);
> >  		else {
> >  			sprintf(env_string, "eth%daddr", i);
> > -			env_set(env_string, mac_string);
> > +			env_set(ctx_uboot, env_string, mac_string);
> >  		}
> >  
> >  		set_mac_to_sh_eth_register(i, mac_string);
> > @@ -298,7 +298,7 @@ static void init_ethernet_mac(void)
> >  	for (i = 0; i < SH7757LCR_GIGA_ETHERNET_NUM_CH; i++) {
> >  		get_sh_eth_mac(i + SH7757LCR_ETHERNET_NUM_CH,
> > mac_string, buf); sprintf(env_string, "eth%daddr", i +
> > SH7757LCR_ETHERNET_NUM_CH);
> > -		env_set(env_string, mac_string);
> > +		env_set(ctx_uboot, env_string, mac_string);
> >  
> >  		set_mac_to_sh_giga_eth_register(i, mac_string);
> >  	}
> > diff --git a/board/renesas/silk/silk.c b/board/renesas/silk/silk.c
> > index 25221e3c55cc..946232e3ba7b 100644
> > --- a/board/renesas/silk/silk.c
> > +++ b/board/renesas/silk/silk.c
> > @@ -129,7 +129,8 @@ void reset_cpu(ulong addr)
> >  		hang();
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/renesas/stout/stout.c b/board/renesas/stout/stout.c
> > index 0a0ff5ff76d2..d0b20f3c5902 100644
> > --- a/board/renesas/stout/stout.c
> > +++ b/board/renesas/stout/stout.c
> > @@ -125,7 +125,8 @@ int board_phy_config(struct phy_device *phydev)
> >  	return 0;
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	const u32 load_magic = 0xb33fc0de;
> >  
> > diff --git a/board/rockchip/kylin_rk3036/kylin_rk3036.c
> > b/board/rockchip/kylin_rk3036/kylin_rk3036.c index
> > 2faeab9baf51..6481f6c11633 100644 ---
> > a/board/rockchip/kylin_rk3036/kylin_rk3036.c +++
> > b/board/rockchip/kylin_rk3036/kylin_rk3036.c @@ -41,7 +41,7 @@ int
> > rk_board_late_init(void) {
> >  	if (fastboot_key_pressed()) {
> >  		printf("enter fastboot!\n");
> > -		env_set("preboot", "setenv preboot; fastboot usb0");
> > +		env_set(ctx_uboot, "preboot", "setenv preboot;
> > fastboot usb0"); }
> >  
> >  	return 0;
> > diff --git a/board/samsung/common/exynos5-dt.c
> > b/board/samsung/common/exynos5-dt.c index 387d1b91809c..1c44effe7224
> > 100644 --- a/board/samsung/common/exynos5-dt.c
> > +++ b/board/samsung/common/exynos5-dt.c
> > @@ -154,7 +154,7 @@ char *get_dfu_alt_system(char *interface, char
> > *devstr) if (board_is_odroidxu4() || board_is_odroidhc1() ||
> > board_is_odroidhc2()) return info;
> >  
> > -	return env_get("dfu_alt_system");
> > +	return env_get(ctx_uboot, "dfu_alt_system");
> >  }
> >  
> >  char *get_dfu_alt_boot(char *interface, char *devstr)
> > diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
> > index 3ef1e7998013..3086df745fe5 100644
> > --- a/board/samsung/common/misc.c
> > +++ b/board/samsung/common/misc.c
> > @@ -51,7 +51,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
> >  
> >  	alt_setting = get_dfu_alt_boot(interface, devstr);
> >  	if (alt_setting) {
> > -		env_set("dfu_alt_boot", alt_setting);
> > +		env_set(ctx_uboot, "dfu_alt_boot", alt_setting);
> >  		offset = snprintf(buf, buf_size, "%s", alt_setting);
> >  	}
> >  
> > @@ -71,7 +71,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
> >  		status = "done\n";
> >  	}
> >  
> > -	env_set("dfu_alt_info", alt_info);
> > +	env_set(ctx_uboot, "dfu_alt_info", alt_info);
> >  	puts(status);
> >  }
> >  #endif
> > @@ -83,14 +83,14 @@ void set_board_info(void)
> >  
> >  	snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev &
> > 0xf0) >> 4, s5p_cpu_rev & 0xf);
> > -	env_set("soc_rev", info);
> > +	env_set(ctx_uboot, "soc_rev", info);
> >  
> >  	snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
> > -	env_set("soc_id", info);
> > +	env_set(ctx_uboot, "soc_id", info);
> >  
> >  #ifdef CONFIG_REVISION_TAG
> >  	snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
> > -	env_set("board_rev", info);
> > +	env_set(ctx_uboot, "board_rev", info);
> >  #endif
> >  #ifdef CONFIG_OF_LIBFDT
> >  	const char *bdtype = "";
> > @@ -102,11 +102,11 @@ void set_board_info(void)
> >  		bdtype = "";
> >  
> >  	sprintf(info, "%s%s", bdname, bdtype);
> > -	env_set("board_name", info);
> > +	env_set(ctx_uboot, "board_name", info);
> >  #endif
> >  	snprintf(info, ARRAY_SIZE(info),  "%s%x-%s%s.dtb",
> >  		 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
> > -	env_set("fdtfile", info);
> > +	env_set(ctx_uboot, "fdtfile", info);
> >  #endif
> >  }
> >  #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
> > diff --git a/board/samsung/odroid/odroid.c
> > b/board/samsung/odroid/odroid.c index 9aa97f0f2cad..472dce81f680
> > 100644 --- a/board/samsung/odroid/odroid.c
> > +++ b/board/samsung/odroid/odroid.c
> > @@ -74,7 +74,7 @@ const char *get_board_type(void)
> >  #ifdef CONFIG_SET_DFU_ALT_INFO
> >  char *get_dfu_alt_system(char *interface, char *devstr)
> >  {
> > -	return env_get("dfu_alt_system");
> > +	return env_get(ctx_uboot, "dfu_alt_system");
> >  }
> >  
> >  char *get_dfu_alt_boot(char *interface, char *devstr)
> > diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
> > index ec85f707c19a..d4540a2ac932 100644
> > --- a/board/samsung/trats/trats.c
> > +++ b/board/samsung/trats/trats.c
> > @@ -467,7 +467,7 @@ void exynos_lcd_misc_init(vidinfo_t *vid)
> >  #endif
> >  #ifdef CONFIG_S6E8AX0
> >  	s6e8ax0_init();
> > -	env_set("lcdinfo", "lcd=s6e8ax0");
> > +	env_set(ctx_uboot, "lcdinfo", "lcd=s6e8ax0");
> >  #endif
> >  }
> >  #endif
> > diff --git a/board/samsung/universal_c210/universal.c
> > b/board/samsung/universal_c210/universal.c index
> > ed9c5b50d927..9fea29e965bd 100644 ---
> > a/board/samsung/universal_c210/universal.c +++
> > b/board/samsung/universal_c210/universal.c @@ -397,6 +397,6 @@ void
> > exynos_lcd_misc_init(vidinfo_t *vid) vid->pclk_name = 1;	/*
> > MPLL */ vid->sclk_div = 1;
> >  
> > -	env_set("lcdinfo", "lcd=ld9040");
> > +	env_set(ctx_uboot, "lcdinfo", "lcd=ld9040");
> >  }
> >  #endif
> > diff --git a/board/samtec/vining_fpga/socfpga.c
> > b/board/samtec/vining_fpga/socfpga.c index 1e095a4e7db0..75ddbcf07fa7
> > 100644 --- a/board/samtec/vining_fpga/socfpga.c
> > +++ b/board/samtec/vining_fpga/socfpga.c
> > @@ -62,30 +62,30 @@ int misc_init_r(void)
> >  	/* Check EEPROM signature. */
> >  	if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
> >  		puts("Invalid I2C EEPROM signature.\n");
> > -		env_set("unit_serial", "invalid");
> > -		env_set("unit_ident", "VINing-xxxx-STD");
> > -		env_set("hostname", "vining-invalid");
> > +		env_set(ctx_uboot, "unit_serial", "invalid");
> > +		env_set(ctx_uboot, "unit_ident", "VINing-xxxx-STD");
> > +		env_set(ctx_uboot, "hostname", "vining-invalid");
> >  		return 0;
> >  	}
> >  
> >  	/* If 'unit_serial' is already set, do nothing. */
> > -	if (!env_get("unit_serial")) {
> > +	if (!env_get(ctx_uboot, "unit_serial")) {
> >  		/* This field is Big Endian ! */
> >  		serial = (data[0x54] << 24) | (data[0x55] << 16) |
> >  			 (data[0x56] << 8) | (data[0x57] << 0);
> >  		memset(str, 0, sizeof(str));
> >  		sprintf(str, "%07i", serial);
> > -		env_set("unit_serial", str);
> > +		env_set(ctx_uboot, "unit_serial", str);
> >  	}
> >  
> > -	if (!env_get("unit_ident")) {
> > +	if (!env_get(ctx_uboot, "unit_ident")) {
> >  		memset(str, 0, sizeof(str));
> >  		memcpy(str, &data[0x2e], 18);
> > -		env_set("unit_ident", str);
> > +		env_set(ctx_uboot, "unit_ident", str);
> >  	}
> >  
> >  	/* Set ethernet address from EEPROM. */
> > -	if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
> > +	if (!env_get(ctx_uboot, "ethaddr") &&
> > is_valid_ethaddr(&data[0x62])) eth_env_set_enetaddr("ethaddr",
> > &data[0x62]); 
> >  	return 0;
> > diff --git a/board/siemens/common/board.c
> > b/board/siemens/common/board.c index 676935a84321..63dcf2b83132 100644
> > --- a/board/siemens/common/board.c
> > +++ b/board/siemens/common/board.c
> > @@ -121,7 +121,7 @@ unsigned char get_button_state(char * const
> > envname, unsigned char def) char *ptr_env;
> >  
> >  	/* If button is not found we take default */
> > -	ptr_env = env_get(envname);
> > +	ptr_env = env_get(ctx_uboot, envname);
> >  	if (NULL == ptr_env) {
> >  		gpio = def;
> >  	} else {
> > @@ -199,7 +199,7 @@ void set_env_gpios(unsigned char state)
> >  		strcat(str_tmp, num);
> >  
> >  		/* If env var is not found we stop */
> > -		ptr_env = env_get(str_tmp);
> > +		ptr_env = env_get(ctx_uboot, str_tmp);
> >  		if (NULL == ptr_env)
> >  			break;
> >  
> > diff --git a/board/siemens/draco/board.c b/board/siemens/draco/board.c
> > index a6840b895b27..9cb1b1301855 100644
> > --- a/board/siemens/draco/board.c
> > +++ b/board/siemens/draco/board.c
> > @@ -270,13 +270,13 @@ int board_late_init(void)
> >  #ifdef CONFIG_FACTORYSET
> >  	/* Set ASN in environment*/
> >  	if (factory_dat.asn[0] != 0) {
> > -		env_set("dtb_name", (char *)factory_dat.asn);
> > +		env_set(ctx_uboot, "dtb_name", (char
> > *)factory_dat.asn); } else {
> >  		/* dtb suffix gets added in load script */
> > -		env_set("dtb_name", "am335x-draco");
> > +		env_set(ctx_uboot, "dtb_name", "am335x-draco");
> >  	}
> >  #else
> > -	env_set("dtb_name", "am335x-draco");
> > +	env_set(ctx_uboot, "dtb_name", "am335x-draco");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/siemens/pxm2/board.c b/board/siemens/pxm2/board.c
> > index 30f0902701ee..e57ab33da88b 100644
> > --- a/board/siemens/pxm2/board.c
> > +++ b/board/siemens/pxm2/board.c
> > @@ -444,12 +444,12 @@ int board_late_init(void)
> >  			factory_dat.pxm50 = 0;
> >  		sprintf(tmp, "%s_%s", factory_dat.asn,
> >  			factory_dat.comp_version);
> > -		ret = env_set("boardid", tmp);
> > +		ret = env_set(ctx_uboot, "boardid", tmp);
> >  		if (ret)
> >  			printf("error setting board id\n");
> >  	} else {
> >  		factory_dat.pxm50 = 1;
> > -		ret = env_set("boardid", "PXM50_1.0");
> > +		ret = env_set(ctx_uboot, "boardid", "PXM50_1.0");
> >  		if (ret)
> >  			printf("error setting board id\n");
> >  	}
> > diff --git a/board/siemens/rut/board.c b/board/siemens/rut/board.c
> > index 539ecef22cb4..809cea42f86b 100644
> > --- a/board/siemens/rut/board.c
> > +++ b/board/siemens/rut/board.c
> > @@ -480,7 +480,7 @@ int board_late_init(void)
> >  	else
> >  		strcpy(tmp, "QMX7.E38_4.0");
> >  
> > -	ret = env_set("boardid", tmp);
> > +	ret = env_set(ctx_uboot, "boardid", tmp);
> >  	if (ret)
> >  		printf("error setting board id\n");
> >  
> > diff --git a/board/siemens/taurus/taurus.c
> > b/board/siemens/taurus/taurus.c index 1cf1f9e1f7ca..980d773a77bb
> > 100644 --- a/board/siemens/taurus/taurus.c
> > +++ b/board/siemens/taurus/taurus.c
> > @@ -350,36 +350,36 @@ static int upgrade_failure_fallback(void)
> >  	char *kern_size;
> >  	char *kern_size_fb;
> >  
> > -	partitionset_active = env_get("partitionset_active");
> > +	partitionset_active = env_get(ctx_uboot,
> > "partitionset_active"); if (partitionset_active) {
> >  		if (partitionset_active[0] == 'A')
> > -			env_set("partitionset_active", "B");
> > +			env_set(ctx_uboot, "partitionset_active",
> > "B"); else
> > -			env_set("partitionset_active", "A");
> > +			env_set(ctx_uboot, "partitionset_active",
> > "A"); } else {
> >  		printf("partitionset_active missing.\n");
> >  		return -ENOENT;
> >  	}
> >  
> > -	rootfs = env_get("rootfs");
> > -	rootfs_fallback = env_get("rootfs_fallback");
> > -	env_set("rootfs", rootfs_fallback);
> > -	env_set("rootfs_fallback", rootfs);
> > +	rootfs = env_get(ctx_uboot, "rootfs");
> > +	rootfs_fallback = env_get(ctx_uboot, "rootfs_fallback");
> > +	env_set(ctx_uboot, "rootfs", rootfs_fallback);
> > +	env_set(ctx_uboot, "rootfs_fallback", rootfs);
> >  
> > -	kern_size = env_get("kernel_size");
> > -	kern_size_fb = env_get("kernel_size_fallback");
> > -	env_set("kernel_size", kern_size_fb);
> > -	env_set("kernel_size_fallback", kern_size);
> > +	kern_size = env_get(ctx_uboot, "kernel_size");
> > +	kern_size_fb = env_get(ctx_uboot, "kernel_size_fallback");
> > +	env_set(ctx_uboot, "kernel_size", kern_size_fb);
> > +	env_set(ctx_uboot, "kernel_size_fallback", kern_size);
> >  
> > -	kern_off = env_get("kernel_Off");
> > -	kern_off_fb = env_get("kernel_Off_fallback");
> > -	env_set("kernel_Off", kern_off_fb);
> > -	env_set("kernel_Off_fallback", kern_off);
> > +	kern_off = env_get(ctx_uboot, "kernel_Off");
> > +	kern_off_fb = env_get(ctx_uboot, "kernel_Off_fallback");
> > +	env_set(ctx_uboot, "kernel_Off", kern_off_fb);
> > +	env_set(ctx_uboot, "kernel_Off_fallback", kern_off);
> >  
> > -	env_set("bootargs", '\0');
> > -	env_set("upgrade_available", '\0');
> > -	env_set("boot_retries", '\0');
> > -	env_save();
> > +	env_set(ctx_uboot, "bootargs", '\0');
> > +	env_set(ctx_uboot, "upgrade_available", '\0');
> > +	env_set(ctx_uboot, "boot_retries", '\0');
> > +	env_save(ctx_uboot);
> >  
> >  	return 0;
> >  }
> > @@ -391,14 +391,16 @@ static int do_upgrade_available(cmd_tbl_t
> > *cmdtp, int flag, int argc, unsigned long boot_retry = 0;
> >  	char boot_buf[10];
> >  
> > -	upgrade_available =
> > simple_strtoul(env_get("upgrade_available"), NULL,
> > -					   10);
> > +	upgrade_available = simple_strtoul(env_get(ctx_uboot,
> > +
> > "upgrade_available"),
> > +					   NULL, 10);
> >  	if (upgrade_available) {
> > -		boot_retry = simple_strtoul(env_get("boot_retries"),
> > NULL, 10);
> > +		boot_retry = simple_strtoul(env_get(ctx_uboot,
> > "boot_retries"),
> > +					    NULL, 10);
> >  		boot_retry++;
> >  		sprintf(boot_buf, "%lx", boot_retry);
> > -		env_set("boot_retries", boot_buf);
> > -		env_save();
> > +		env_set(ctx_uboot, "boot_retries", boot_buf);
> > +		env_save(ctx_uboot);
> >  
> >  		/*
> >  		 * Here the boot_retries count is checked, and if the
> > diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
> > index da9ae5bebb7e..277f9e107080 100644
> > --- a/board/socrates/socrates.c
> > +++ b/board/socrates/socrates.c
> > @@ -38,7 +38,7 @@ int checkboard (void)
> >  	volatile ccsr_gur_t *gur = (void
> > *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); char buf[64];
> >  	int f;
> > -	int i = env_get_f("serial#", buf, sizeof(buf));
> > +	int i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
> >  #ifdef CONFIG_PCI
> >  	char *src;
> >  #endif
> > @@ -409,7 +409,7 @@ void board_backlight_switch (int flag)
> >  		printf ("hwmon IC init failed\n");
> >  
> >  	if (flag) {
> > -		param = env_get("brightness");
> > +		param = env_get(ctx_uboot, "brightness");
> >  		rc = param ? simple_strtol(param, NULL, 10) : -1;
> >  		if (rc < 0)
> >  			rc = DEFAULT_BRIGHTNESS;
> > diff --git a/board/softing/vining_2000/vining_2000.c
> > b/board/softing/vining_2000/vining_2000.c index
> > 51985b91c226..5d4d0f29c44f 100644 ---
> > a/board/softing/vining_2000/vining_2000.c +++
> > b/board/softing/vining_2000/vining_2000.c @@ -102,7 +102,7 @@ int
> > board_eth_init(bd_t *bis) 
> >  	/* just to get secound mac address */
> >  	imx_get_mac_from_fuse(1, eth1addr);
> > -	if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
> > +	if (!env_get(ctx_uboot, "eth1addr") &&
> > is_valid_ethaddr(eth1addr)) eth_env_set_enetaddr("eth1addr",
> > eth1addr); 
> >  	imx_iomux_v3_setup_multiple_pads(fec1_pads,
> > ARRAY_SIZE(fec1_pads)); @@ -385,11 +385,11 @@ static int
> > set_pin_state(void) return ret;
> >  
> >  	if (val >= VAL_UPPER)
> > -		env_set("pin_state", "connected");
> > +		env_set(ctx_uboot, "pin_state", "connected");
> >  	else if (val < VAL_UPPER && val > VAL_LOWER)
> > -		env_set("pin_state", "open");
> > +		env_set(ctx_uboot, "pin_state", "open");
> >  	else
> > -		env_set("pin_state", "button");
> > +		env_set(ctx_uboot, "pin_state", "button");
> >  
> >  	return ret;
> >  }
> > diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c
> > b/board/solidrun/mx6cuboxi/mx6cuboxi.c index
> > f82fb0786a94..52177b918d83 100644 ---
> > a/board/solidrun/mx6cuboxi/mx6cuboxi.c +++
> > b/board/solidrun/mx6cuboxi/mx6cuboxi.c @@ -569,29 +569,29 @@ int
> > board_late_init(void) #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	switch (board_type()) {
> >  	case CUBOXI:
> > -		env_set("board_name", "CUBOXI");
> > +		env_set(ctx_uboot, "board_name", "CUBOXI");
> >  		break;
> >  	case HUMMINGBOARD:
> > -		env_set("board_name", "HUMMINGBOARD");
> > +		env_set(ctx_uboot, "board_name", "HUMMINGBOARD");
> >  		break;
> >  	case HUMMINGBOARD2:
> > -		env_set("board_name", "HUMMINGBOARD2");
> > +		env_set(ctx_uboot, "board_name", "HUMMINGBOARD2");
> >  		break;
> >  	case UNKNOWN:
> >  	default:
> > -		env_set("board_name", "CUBOXI");
> > +		env_set(ctx_uboot, "board_name", "CUBOXI");
> >  	}
> >  
> >  	if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  
> >  	if (is_rev_15_som())
> > -		env_set("som_rev", "V15");
> > +		env_set(ctx_uboot, "som_rev", "V15");
> >  
> >  	if (has_emmc())
> > -		env_set("has_emmc", "yes");
> > +		env_set(ctx_uboot, "has_emmc", "yes");
> >  
> >  #endif
> >  
> > diff --git a/board/st/stm32f429-discovery/stm32f429-discovery.c
> > b/board/st/stm32f429-discovery/stm32f429-discovery.c index
> > 500dc5fe3a6b..3ae0c17d7720 100644 ---
> > a/board/st/stm32f429-discovery/stm32f429-discovery.c +++
> > b/board/st/stm32f429-discovery/stm32f429-discovery.c @@ -65,13 +65,13
> > @@ int misc_init_r(void) char serialno[25];
> >  	uint32_t u_id_low, u_id_mid, u_id_high;
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		u_id_low  = readl(&STM32_U_ID->u_id_low);
> >  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
> >  		u_id_high = readl(&STM32_U_ID->u_id_high);
> >  		sprintf(serialno, "%08x%08x%08x",
> >  			u_id_high, u_id_mid, u_id_low);
> > -		env_set("serial#", serialno);
> > +		env_set(ctx_uboot, "serial#", serialno);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/st/stm32f429-evaluation/stm32f429-evaluation.c
> > b/board/st/stm32f429-evaluation/stm32f429-evaluation.c index
> > 8ab2fa5d59ab..3a1c578cdad8 100644 ---
> > a/board/st/stm32f429-evaluation/stm32f429-evaluation.c +++
> > b/board/st/stm32f429-evaluation/stm32f429-evaluation.c @@ -59,13
> > +59,13 @@ int misc_init_r(void) char serialno[25];
> >  	u32 u_id_low, u_id_mid, u_id_high;
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		u_id_low  = readl(&STM32_U_ID->u_id_low);
> >  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
> >  		u_id_high = readl(&STM32_U_ID->u_id_high);
> >  		sprintf(serialno, "%08x%08x%08x",
> >  			u_id_high, u_id_mid, u_id_low);
> > -		env_set("serial#", serialno);
> > +		env_set(ctx_uboot, "serial#", serialno);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/st/stm32f469-discovery/stm32f469-discovery.c
> > b/board/st/stm32f469-discovery/stm32f469-discovery.c index
> > 70d23d90f4ca..e475296919e0 100644 ---
> > a/board/st/stm32f469-discovery/stm32f469-discovery.c +++
> > b/board/st/stm32f469-discovery/stm32f469-discovery.c @@ -59,13 +59,13
> > @@ int misc_init_r(void) char serialno[25];
> >  	u32 u_id_low, u_id_mid, u_id_high;
> >  
> > -	if (!env_get("serial#")) {
> > +	if (!env_get(ctx_uboot, "serial#")) {
> >  		u_id_low  = readl(&STM32_U_ID->u_id_low);
> >  		u_id_mid  = readl(&STM32_U_ID->u_id_mid);
> >  		u_id_high = readl(&STM32_U_ID->u_id_high);
> >  		sprintf(serialno, "%08x%08x%08x",
> >  			u_id_high, u_id_mid, u_id_low);
> > -		env_set("serial#", serialno);
> > +		env_set(ctx_uboot, "serial#", serialno);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/st/stm32mp1/stm32mp1.c
> > b/board/st/stm32mp1/stm32mp1.c index 279c7b779799..188f4a7eae12 100644
> > --- a/board/st/stm32mp1/stm32mp1.c
> > +++ b/board/st/stm32mp1/stm32mp1.c
> > @@ -544,9 +544,9 @@ int board_late_init(void)
> >  				 &fdt_compat_len);
> >  	if (fdt_compat && fdt_compat_len) {
> >  		if (strncmp(fdt_compat, "st,", 3) != 0)
> > -			env_set("board_name", fdt_compat);
> > +			env_set(ctx_uboot, "board_name", fdt_compat);
> >  		else
> > -			env_set("board_name", fdt_compat + 3);
> > +			env_set(ctx_uboot, "board_name", fdt_compat
> > + 3); }
> >  #endif
> >  
> > @@ -623,7 +623,8 @@ int board_interface_eth_init(phy_interface_t
> > interface_type, return 0;
> >  }
> >  
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	u32 bootmode = get_bootmode();
> >  
> > @@ -688,8 +689,8 @@ const char *env_ext4_get_dev_part(void)
> >  static const char *env_get_mtdparts(const char *str, char *buf)
> >  {
> >  	if (gd->flags & GD_FLG_ENV_READY)
> > -		return env_get(str);
> > -	if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
> > +		return env_get(ctx_uboot, str);
> > +	if (env_get_f(ctx_uboot, str, buf, MTDPARTS_LEN) != -1)
> >  		return buf;
> >  
> >  	return NULL;
> > diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> > index e3b2d13892c8..d5f172eb8082 100644
> > --- a/board/sunxi/board.c
> > +++ b/board/sunxi/board.c
> > @@ -194,7 +194,8 @@ void i2c_init_board(void)
> >  }
> >  
> >  #if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
> > -enum env_location env_get_location(enum env_operation op, int prio)
> > +enum env_location env_get_location(struct env_context *ctx,
> > +				   enum env_operation op, int prio)
> >  {
> >  	switch (prio) {
> >  	case 0:
> > @@ -725,7 +726,7 @@ void get_board_serial(struct tag_serialnr
> > *serialnr) char *serial_string;
> >  	unsigned long long serial;
> >  
> > -	serial_string = env_get("serial#");
> > +	serial_string = env_get(ctx_uboot, "serial#");
> >  
> >  	if (serial_string) {
> >  		serial = simple_strtoull(serial_string, NULL, 16);
> > @@ -764,7 +765,7 @@ static void parse_spl_header(const uint32_t
> > spl_addr) return;
> >  	}
> >  	/* otherwise assume .scr format (mkimage-type script) */
> > -	env_set_hex("fel_scriptaddr", spl->fel_script_address);
> > +	env_set_hex(ctx_uboot, "fel_scriptaddr",
> > spl->fel_script_address); }
> >  
> >  /*
> > @@ -812,7 +813,7 @@ static void setup_environment(const void *fdt)
> >  			else
> >  				sprintf(ethaddr, "eth%daddr", i);
> >  
> > -			if (env_get(ethaddr))
> > +			if (env_get(ctx_uboot, ethaddr))
> >  				continue;
> >  
> >  			/* Non OUI / registered MAC address */
> > @@ -826,11 +827,11 @@ static void setup_environment(const void *fdt)
> >  			eth_env_set_enetaddr(ethaddr, mac_addr);
> >  		}
> >  
> > -		if (!env_get("serial#")) {
> > +		if (!env_get(ctx_uboot, "serial#")) {
> >  			snprintf(serial_string,
> > sizeof(serial_string), "%08x%08x", sid[0], sid[3]);
> >  
> > -			env_set("serial#", serial_string);
> > +			env_set(ctx_uboot, "serial#", serial_string);
> >  		}
> >  	}
> >  }
> > @@ -839,20 +840,20 @@ int misc_init_r(void)
> >  {
> >  	uint boot;
> >  
> > -	env_set("fel_booted", NULL);
> > -	env_set("fel_scriptaddr", NULL);
> > -	env_set("mmc_bootdev", NULL);
> > +	env_set(ctx_uboot, "fel_booted", NULL);
> > +	env_set(ctx_uboot, "fel_scriptaddr", NULL);
> > +	env_set(ctx_uboot, "mmc_bootdev", NULL);
> >  
> >  	boot = sunxi_get_boot_device();
> >  	/* determine if we are running in FEL mode */
> >  	if (boot == BOOT_DEVICE_BOARD) {
> > -		env_set("fel_booted", "1");
> > +		env_set(ctx_uboot, "fel_booted", "1");
> >  		parse_spl_header(SPL_ADDR);
> >  	/* or if we booted from MMC, and which one */
> >  	} else if (boot == BOOT_DEVICE_MMC1) {
> > -		env_set("mmc_bootdev", "0");
> > +		env_set(ctx_uboot, "mmc_bootdev", "0");
> >  	} else if (boot == BOOT_DEVICE_MMC2) {
> > -		env_set("mmc_bootdev", "1");
> > +		env_set(ctx_uboot, "mmc_bootdev", "1");
> >  	}
> >  
> >  	setup_environment(gd->fdt_blob);
> > diff --git a/board/synopsys/hsdk/env-lib.c
> > b/board/synopsys/hsdk/env-lib.c index f443c21e6d99..eca2211246b4
> > 100644 --- a/board/synopsys/hsdk/env-lib.c
> > +++ b/board/synopsys/hsdk/env-lib.c
> > @@ -21,10 +21,12 @@ static int env_read_common(u32 index, const
> > struct env_map_common *map) 
> >  	if (!env_get_yesno(map[index].env_name)) {
> >  		if (map[index].type == ENV_HEX) {
> > -			val = (u32)env_get_hex(map[index].env_name,
> > 0);
> > +			val = (u32)env_get_hex(ctx_uboot,
> > map[index].env_name,
> > +					       0);
> >  			debug("ENV: %s: = %#x\n",
> > map[index].env_name, val); } else {
> > -			val =
> > (u32)env_get_ulong(map[index].env_name, 10, 0);
> > +			val = (u32)env_get_ulong(ctx_uboot,
> > +
> > map[index].env_name, 10, 0); debug("ENV: %s: = %d\n",
> > map[index].env_name, val); }
> >  
> > @@ -52,10 +54,11 @@ static int env_read_core(u32 index, const struct
> > env_map_percpu *map) sprintf(command, "%s_%u", map[index].env_name,
> > i); if (!env_get_yesno(command)) {
> >  			if (map[index].type == ENV_HEX) {
> > -				val = (u32)env_get_hex(command, 0);
> > +				val = (u32)env_get_hex(ctx_uboot,
> > command, 0); debug("ENV: %s: = %#x\n", command, val);
> >  			} else {
> > -				val = (u32)env_get_ulong(command,
> > 10, 0);
> > +				val = (u32)env_get_ulong(ctx_uboot,
> > command,
> > +							 10, 0);
> >  				debug("ENV: %s: = %d\n", command,
> > val); }
> >  
> > diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c
> > index 8a7642a0aaaa..ab97b97bcde3 100644
> > --- a/board/synopsys/hsdk/hsdk.c
> > +++ b/board/synopsys/hsdk/hsdk.c
> > @@ -854,19 +854,19 @@ static int do_hsdk_clock_get(cmd_tbl_t *cmdtp,
> > int flag, int argc, if (soc_clk_ctl("cpu-clk", &rate, CLK_GET |
> > CLK_MHZ)) return CMD_RET_FAILURE;
> >  
> > -	if (env_set_ulong("cpu_freq", rate))
> > +	if (env_set_ulong(ctx_uboot, "cpu_freq", rate))
> >  		return CMD_RET_FAILURE;
> >  
> >  	if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
> >  		return CMD_RET_FAILURE;
> >  
> > -	if (env_set_ulong("tun_freq", rate))
> > +	if (env_set_ulong(ctx_uboot, "tun_freq", rate))
> >  		return CMD_RET_FAILURE;
> >  
> >  	if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
> >  		return CMD_RET_FAILURE;
> >  
> > -	if (env_set_ulong("axi_freq", rate))
> > +	if (env_set_ulong(ctx_uboot, "axi_freq", rate))
> >  		return CMD_RET_FAILURE;
> >  
> >  	printf("Clock values are saved to environment\n");
> > diff --git a/board/syteco/zmx25/zmx25.c b/board/syteco/zmx25/zmx25.c
> > index d2318457b431..c49ac35c2933 100644
> > --- a/board/syteco/zmx25/zmx25.c
> > +++ b/board/syteco/zmx25/zmx25.c
> > @@ -145,7 +145,7 @@ int board_late_init(void)
> >  	udelay(5000);
> >  #endif
> >  
> > -	e = env_get("gs_base_board");
> > +	e = env_get(ctx_uboot, "gs_base_board");
> >  	if (e != NULL) {
> >  		if (strcmp(e, "G283") == 0) {
> >  			int key = gpio_get_value(IMX_GPIO_NR(2, 29));
> > @@ -155,9 +155,11 @@ int board_late_init(void)
> >  				gpio_set_value(IMX_GPIO_NR(1, 29),
> > 0); gpio_set_value(IMX_GPIO_NR(4, 21), 0);
> >  
> > -				env_set("preboot", "run
> > gs_slow_boot");
> > +				env_set(ctx_uboot, "preboot",
> > +					"run gs_slow_boot");
> >  			} else
> > -				env_set("preboot", "run
> > gs_fast_boot");
> > +				env_set(ctx_uboot, "preboot",
> > +					"run gs_fast_boot");
> >  		}
> >  	}
> >  
> > diff --git a/board/tcl/sl50/board.c b/board/tcl/sl50/board.c
> > index c7eed319461a..79598cd36a5e 100644
> > --- a/board/tcl/sl50/board.c
> > +++ b/board/tcl/sl50/board.c
> > @@ -75,7 +75,7 @@ int spl_start_uboot(void)
> >  
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > +	env_load(ctx_uboot);
> >  	if (env_get_yesno("boot_os") != 1)
> >  		return 1;
> >  #endif
> > @@ -321,7 +321,7 @@ int board_eth_init(bd_t *bis)
> >  
> >  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> > || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > @@ -339,7 +339,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> > diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
> > b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index
> > 47259b714961..d0150a127dd6 100644 ---
> > a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++
> > b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -58,8 +58,8 @@
> > static int setup_boottargets(void) }
> >  	debug("%s: booted from %s\n", __func__, boot_device);
> >  
> > -	env_default = env_get_default("boot_targets");
> > -	env = env_get("boot_targets");
> > +	env_default = env_get_default(ctx_uboot, "boot_targets");
> > +	env = env_get(ctx_uboot, "boot_targets");
> >  	if (!env) {
> >  		debug("%s: boot_targets does not exist\n", __func__);
> >  		return -1;
> > @@ -102,7 +102,7 @@ static int setup_boottargets(void)
> >  			mmc0[3] = '1';
> >  			mmc1[3] = '0';
> >  			debug("%s: set boot_targets to: %s\n",
> > __func__, env);
> > -			env_set("boot_targets", env);
> > +			env_set(ctx_uboot, "boot_targets", env);
> >  		}
> >  	}
> >  
> > @@ -140,7 +140,7 @@ void get_board_serial(struct tag_serialnr
> > *serialnr) char *serial_string;
> >  	u64 serial = 0;
> >  
> > -	serial_string = env_get("serial#");
> > +	serial_string = env_get(ctx_uboot, "serial#");
> >  
> >  	if (serial_string)
> >  		serial = simple_strtoull(serial_string, NULL, 16);
> > diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
> > index 7eaa6cd96d60..b1f432332d8c 100644
> > --- a/board/ti/am335x/board.c
> > +++ b/board/ti/am335x/board.c
> > @@ -251,7 +251,7 @@ int spl_start_uboot(void)
> >  
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > +	env_load(ctx_uboot);
> >  	if (env_get_yesno("boot_os") != 1)
> >  		return 1;
> >  #endif
> > @@ -825,7 +825,7 @@ int board_late_init(void)
> >  	 * on HS devices.
> >  	 */
> >  	if (get_device_type() == HS_DEVICE)
> > -		env_set("boot_fit", "1");
> > +		env_set(ctx_uboot, "boot_fit", "1");
> >  #endif
> >  
> >  #if !defined(CONFIG_SPL_BUILD)
> > @@ -839,7 +839,7 @@ int board_late_init(void)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > @@ -855,20 +855,20 @@ int board_late_init(void)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> >  #endif
> >  
> > -	if (!env_get("serial#")) {
> > -		char *board_serial = env_get("board_serial");
> > -		char *ethaddr = env_get("ethaddr");
> > +	if (!env_get(ctx_uboot, "serial#")) {
> > +		char *board_serial = env_get(ctx_uboot,
> > "board_serial");
> > +		char *ethaddr = env_get(ctx_uboot, "ethaddr");
> >  
> >  		if (!board_serial || !strncmp(board_serial,
> > "unknown", 7))
> > -			env_set("serial#", ethaddr);
> > +			env_set(ctx_uboot, "serial#", ethaddr);
> >  		else
> > -			env_set("serial#", board_serial);
> > +			env_set(ctx_uboot, "serial#", board_serial);
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
> > index 2e09cc20e8c2..7eb71cd4d8d1 100644
> > --- a/board/ti/am43xx/board.c
> > +++ b/board/ti/am43xx/board.c
> > @@ -728,7 +728,7 @@ int board_late_init(void)
> >  	 * on HS devices.
> >  	 */
> >  	if (get_device_type() == HS_DEVICE)
> > -		env_set("boot_fit", "1");
> > +		env_set(ctx_uboot, "boot_fit", "1");
> >  #endif
> >  
> >  #if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
> > @@ -902,7 +902,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		puts("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("ethaddr", mac_addr);
> > @@ -917,7 +917,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = mac_lo & 0xFF;
> >  	mac_addr[5] = (mac_lo & 0xFF00) >> 8;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> > diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
> > index f78e6c2e1f6e..222049d541de 100644
> > --- a/board/ti/am57xx/board.c
> > +++ b/board/ti/am57xx/board.c
> > @@ -668,7 +668,7 @@ void am57x_idk_lcd_detect(void)
> >  		/* we will let default be "no lcd" */
> >  	}
> >  out:
> > -	env_set("idk_lcd", idk_lcd);
> > +	env_set(ctx_uboot, "idk_lcd", idk_lcd);
> >  	return;
> >  }
> >  
> > @@ -701,7 +701,7 @@ int board_late_init(void)
> >  	 * on HS devices.
> >  	 */
> >  	if (get_device_type() == HS_DEVICE)
> > -		env_set("boot_fit", "1");
> > +		env_set(ctx_uboot, "boot_fit", "1");
> >  
> >  	/*
> >  	 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
> > @@ -871,7 +871,7 @@ int spl_start_uboot(void)
> >  
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > +	env_load(ctx_uboot);
> >  	if (env_get_yesno("boot_os") != 1)
> >  		return 1;
> >  #endif
> > @@ -975,7 +975,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
> >  	mac_addr[5] = mac_lo & 0xFF;
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > @@ -991,7 +991,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
> >  	mac_addr[5] = mac_lo & 0xFF;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> > @@ -1100,8 +1100,8 @@ int board_fit_config_name_match(const char
> > *name) int fastboot_set_reboot_flag(void)
> >  {
> >  	printf("Setting reboot to fastboot flag ...\n");
> > -	env_set("dofastboot", "1");
> > -	env_save();
> > +	env_set(ctx_uboot, "dofastboot", "1");
> > +	env_save(ctx_uboot);
> >  	return 0;
> >  }
> >  #endif
> > diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
> > index 0138fc91fcbe..7ee36aff7c45 100644
> > --- a/board/ti/beagle/beagle.c
> > +++ b/board/ti/beagle/beagle.c
> > @@ -340,16 +340,16 @@ int misc_init_r(void)
> >  	switch (get_board_revision()) {
> >  	case REVISION_AXBX:
> >  		printf("Beagle Rev Ax/Bx\n");
> > -		env_set("beaglerev", "AxBx");
> > +		env_set(ctx_uboot, "beaglerev", "AxBx");
> >  		break;
> >  	case REVISION_CX:
> >  		printf("Beagle Rev C1/C2/C3\n");
> > -		env_set("beaglerev", "Cx");
> > +		env_set(ctx_uboot, "beaglerev", "Cx");
> >  		MUX_BEAGLE_C();
> >  		break;
> >  	case REVISION_C4:
> >  		printf("Beagle Rev C4\n");
> > -		env_set("beaglerev", "C4");
> > +		env_set(ctx_uboot, "beaglerev", "C4");
> >  		MUX_BEAGLE_C();
> >  		/* Set VAUX2 to 1.8V for EHCI PHY */
> >  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> > @@ -359,7 +359,7 @@ int misc_init_r(void)
> >  		break;
> >  	case REVISION_XM_AB:
> >  		printf("Beagle xM Rev A/B\n");
> > -		env_set("beaglerev", "xMAB");
> > +		env_set(ctx_uboot, "beaglerev", "xMAB");
> >  		MUX_BEAGLE_XM();
> >  		/* Set VAUX2 to 1.8V for EHCI PHY */
> >  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> > @@ -370,7 +370,7 @@ int misc_init_r(void)
> >  		break;
> >  	case REVISION_XM_C:
> >  		printf("Beagle xM Rev C\n");
> > -		env_set("beaglerev", "xMC");
> > +		env_set(ctx_uboot, "beaglerev", "xMC");
> >  		MUX_BEAGLE_XM();
> >  		/* Set VAUX2 to 1.8V for EHCI PHY */
> >  		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
> > @@ -396,14 +396,14 @@ int misc_init_r(void)
> >  			expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_TINCANTOOLS_ZIPPY();
> > -		env_set("buddy", "zippy");
> > +		env_set(ctx_uboot, "buddy", "zippy");
> >  		break;
> >  	case TINCANTOOLS_ZIPPY2:
> >  		printf("Recognized Tincantools Zippy2 board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		MUX_TINCANTOOLS_ZIPPY();
> > -		env_set("buddy", "zippy2");
> > +		env_set(ctx_uboot, "buddy", "zippy2");
> >  		break;
> >  	case TINCANTOOLS_TRAINER:
> >  		printf("Recognized Tincantools Trainer board (rev %d
> > %s)\n", @@ -411,37 +411,37 @@ int misc_init_r(void)
> >  			expansion_config.fab_revision);
> >  		MUX_TINCANTOOLS_ZIPPY();
> >  		MUX_TINCANTOOLS_TRAINER();
> > -		env_set("buddy", "trainer");
> > +		env_set(ctx_uboot, "buddy", "trainer");
> >  		break;
> >  	case TINCANTOOLS_SHOWDOG:
> >  		printf("Recognized Tincantools Showdow board (rev %d
> > %s)\n", expansion_config.revision,
> >  			expansion_config.fab_revision);
> >  		/* Place holder for DSS2 definition for showdog lcd
> > */
> > -		env_set("defaultdisplay", "showdoglcd");
> > -		env_set("buddy", "showdog");
> > +		env_set(ctx_uboot, "defaultdisplay", "showdoglcd");
> > +		env_set(ctx_uboot, "buddy", "showdog");
> >  		break;
> >  	case KBADC_BEAGLEFPGA:
> >  		printf("Recognized KBADC Beagle FPGA board\n");
> >  		MUX_KBADC_BEAGLEFPGA();
> > -		env_set("buddy", "beaglefpga");
> > +		env_set(ctx_uboot, "buddy", "beaglefpga");
> >  		break;
> >  	case LW_BEAGLETOUCH:
> >  		printf("Recognized Liquidware BeagleTouch board\n");
> > -		env_set("buddy", "beagletouch");
> > +		env_set(ctx_uboot, "buddy", "beagletouch");
> >  		break;
> >  	case BRAINMUX_LCDOG:
> >  		printf("Recognized Brainmux LCDog board\n");
> > -		env_set("buddy", "lcdog");
> > +		env_set(ctx_uboot, "buddy", "lcdog");
> >  		break;
> >  	case BRAINMUX_LCDOGTOUCH:
> >  		printf("Recognized Brainmux LCDog Touch board\n");
> > -		env_set("buddy", "lcdogtouch");
> > +		env_set(ctx_uboot, "buddy", "lcdogtouch");
> >  		break;
> >  	case BBTOYS_WIFI:
> >  		printf("Recognized BeagleBoardToys WiFi board\n");
> >  		MUX_BBTOYS_WIFI()
> > -		env_set("buddy", "bbtoys-wifi");
> > +		env_set(ctx_uboot, "buddy", "bbtoys-wifi");
> >  		break;
> >  	case BBTOYS_VGA:
> >  		printf("Recognized BeagleBoardToys VGA board\n");
> > @@ -458,20 +458,21 @@ int misc_init_r(void)
> >  	case LSR_COM6L_ADPT:
> >  		printf("Recognized LSR COM6L Adapter Board\n");
> >  		MUX_BBTOYS_WIFI()
> > -		env_set("buddy", "lsr-com6l-adpt");
> > +		env_set(ctx_uboot, "buddy", "lsr-com6l-adpt");
> >  		break;
> >  	case BEAGLE_NO_EEPROM:
> >  		printf("No EEPROM on expansion board\n");
> > -		env_set("buddy", "none");
> > +		env_set(ctx_uboot, "buddy", "none");
> >  		break;
> >  	default:
> >  		printf("Unrecognized expansion board: %x\n",
> >  			expansion_config.device_vendor);
> > -		env_set("buddy", "unknown");
> > +		env_set(ctx_uboot, "buddy", "unknown");
> >  	}
> >  
> >  	if (expansion_config.content == 1)
> > -		env_set(expansion_config.env_var,
> > expansion_config.env_setting);
> > +		env_set(ctx_uboot, expansion_config.env_var,
> > +			expansion_config.env_setting);
> >  
> >  	twl4030_power_init();
> >  	switch (get_board_revision()) {
> > @@ -511,10 +512,10 @@ int misc_init_r(void)
> >  
> >  #if defined(CONFIG_MTDIDS_DEFAULT) &&
> > defined(CONFIG_MTDPARTS_DEFAULT) if (strlen(CONFIG_MTDIDS_DEFAULT))
> > -		env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
> > +		env_set(ctx_uboot, "mtdids", CONFIG_MTDIDS_DEFAULT);
> >  
> >  	if (strlen(CONFIG_MTDPARTS_DEFAULT))
> > -		env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
> > +		env_set(ctx_uboot, "mtdparts",
> > CONFIG_MTDPARTS_DEFAULT); #endif
> >  
> >  	return 0;
> > diff --git a/board/ti/common/board_detect.c
> > b/board/ti/common/board_detect.c index bc89cc57bd78..fe776f2428d2
> > 100644 --- a/board/ti/common/board_detect.c
> > +++ b/board/ti/common/board_detect.c
> > @@ -580,21 +580,21 @@ void __maybe_unused set_board_info_env(char
> > *name) struct ti_common_eeprom *ep = TI_EEPROM_DATA;
> >  
> >  	if (name)
> > -		env_set("board_name", name);
> > +		env_set(ctx_uboot, "board_name", name);
> >  	else if (ep->name)
> > -		env_set("board_name", ep->name);
> > +		env_set(ctx_uboot, "board_name", ep->name);
> >  	else
> > -		env_set("board_name", unknown);
> > +		env_set(ctx_uboot, "board_name", unknown);
> >  
> >  	if (ep->version)
> > -		env_set("board_rev", ep->version);
> > +		env_set(ctx_uboot, "board_rev", ep->version);
> >  	else
> > -		env_set("board_rev", unknown);
> > +		env_set(ctx_uboot, "board_rev", unknown);
> >  
> >  	if (ep->serial)
> > -		env_set("board_serial", ep->serial);
> > +		env_set(ctx_uboot, "board_serial", ep->serial);
> >  	else
> > -		env_set("board_serial", unknown);
> > +		env_set(ctx_uboot, "board_serial", unknown);
> >  }
> >  
> >  void __maybe_unused set_board_info_env_am6(char *name)
> > diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
> > index 74d04bb1e393..63ac5b1988bf 100644
> > --- a/board/ti/dra7xx/evm.c
> > +++ b/board/ti/dra7xx/evm.c
> > @@ -691,7 +691,7 @@ int board_late_init(void)
> >  	 * on HS devices.
> >  	 */
> >  	if (get_device_type() == HS_DEVICE)
> > -		env_set("boot_fit", "1");
> > +		env_set(ctx_uboot, "boot_fit", "1");
> >  
> >  	omap_die_id_serial();
> >  	omap_set_fastboot_vars();
> > @@ -980,7 +980,7 @@ int spl_start_uboot(void)
> >  
> >  #ifdef CONFIG_SPL_ENV_SUPPORT
> >  	env_init();
> > -	env_load();
> > +	env_load(ctx_uboot);
> >  	if (env_get_yesno("boot_os") != 1)
> >  		return 1;
> >  #endif
> > @@ -1048,7 +1048,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
> >  	mac_addr[5] = mac_lo & 0xFF;
> >  
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > @@ -1064,7 +1064,7 @@ int board_eth_init(bd_t *bis)
> >  	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
> >  	mac_addr[5] = mac_lo & 0xFF;
> >  
> > -	if (!env_get("eth1addr")) {
> > +	if (!env_get(ctx_uboot, "eth1addr")) {
> >  		if (is_valid_ethaddr(mac_addr))
> >  			eth_env_set_enetaddr("eth1addr", mac_addr);
> >  	}
> > @@ -1152,8 +1152,8 @@ int board_fit_config_name_match(const char
> > *name) int fastboot_set_reboot_flag(void)
> >  {
> >  	printf("Setting reboot to fastboot flag ...\n");
> > -	env_set("dofastboot", "1");
> > -	env_save();
> > +	env_set(ctx_uboot, "dofastboot", "1");
> > +	env_save(ctx_uboot);
> >  	return 0;
> >  }
> >  #endif
> > diff --git a/board/ti/evm/evm.c b/board/ti/evm/evm.c
> > index d0b9bafbd1b6..4053eb7448a6 100644
> > --- a/board/ti/evm/evm.c
> > +++ b/board/ti/evm/evm.c
> > @@ -283,7 +283,7 @@ static void reset_net_chip(void)
> >  int board_eth_init(bd_t *bis)
> >  {
> >  #if defined(CONFIG_SMC911X)
> > -	env_set("ethaddr", NULL);
> > +	env_set(ctx_uboot, "ethaddr", NULL);
> >  	return smc911x_initialize(0, CONFIG_SMC911X_BASE);
> >  #else
> >  	return 0;
> > diff --git a/board/ti/ks2_evm/board.c b/board/ti/ks2_evm/board.c
> > index e9bc68049b4b..aa447fd886cc 100644
> > --- a/board/ti/ks2_evm/board.c
> > +++ b/board/ti/ks2_evm/board.c
> > @@ -113,7 +113,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  	u64 start[2];
> >  	u32 ddr3a_size;
> >  
> > -	env = env_get("mem_lpae");
> > +	env = env_get(ctx_uboot, "mem_lpae");
> >  	lpae = env && simple_strtol(env, NULL, 0);
> >  
> >  	ddr3a_size = 0;
> > @@ -140,13 +140,13 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  	}
> >  
> >  	/* reserve memory at start of bank */
> > -	env = env_get("mem_reserve_head");
> > +	env = env_get(ctx_uboot, "mem_reserve_head");
> >  	if (env) {
> >  		start[0] += ustrtoul(env, &endp, 0);
> >  		size[0] -= ustrtoul(env, &endp, 0);
> >  	}
> >  
> > -	env = env_get("mem_reserve");
> > +	env = env_get(ctx_uboot, "mem_reserve");
> >  	if (env)
> >  		size[0] -= ustrtoul(env, &endp, 0);
> >  
> > @@ -163,9 +163,9 @@ void ft_board_setup_ex(void *blob, bd_t *bd)
> >  	u64 *reserve_start;
> >  	int unitrd_fixup = 0;
> >  
> > -	env = env_get("mem_lpae");
> > +	env = env_get(ctx_uboot, "mem_lpae");
> >  	lpae = env && simple_strtol(env, NULL, 0);
> > -	env = env_get("uinitrd_fixup");
> > +	env = env_get(ctx_uboot, "uinitrd_fixup");
> >  	unitrd_fixup = env && simple_strtol(env, NULL, 0);
> >  
> >  	/* Fix up the initrd */
> > diff --git a/board/ti/ks2_evm/board_k2g.c
> > b/board/ti/ks2_evm/board_k2g.c index 4ff9a44b3712..49c09b88bd83 100644
> > --- a/board/ti/ks2_evm/board_k2g.c
> > +++ b/board/ti/ks2_evm/board_k2g.c
> > @@ -353,11 +353,11 @@ int board_late_init(void)
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	if (board_is_k2g_gp())
> > -		env_set("board_name", "66AK2GGP\0");
> > +		env_set(ctx_uboot, "board_name", "66AK2GGP\0");
> >  	else if (board_is_k2g_g1())
> > -		env_set("board_name", "66AK2GG1\0");
> > +		env_set(ctx_uboot, "board_name", "66AK2GG1\0");
> >  	else if (board_is_k2g_ice())
> > -		env_set("board_name", "66AK2GIC\0");
> > +		env_set(ctx_uboot, "board_name", "66AK2GIC\0");
> >  #endif
> >  	return 0;
> >  }
> > @@ -384,7 +384,7 @@ void spl_init_keystone_plls(void)
> >  #ifdef CONFIG_TI_SECURE_DEVICE
> >  void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
> >  {
> > -	int id = env_get_ulong("dev_pmmc", 10, 0);
> > +	int id = env_get_ulong(ctx_uboot, "dev_pmmc", 10, 0);
> >  	int ret;
> >  
> >  	if (!rproc_is_initialized())
> > diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
> > index 20199da390ec..9d42123de9cc 100644
> > --- a/board/ti/panda/panda.c
> > +++ b/board/ti/panda/panda.c
> > @@ -103,7 +103,7 @@ int get_board_revision(void)
> >  		board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -		env_set("board_name", "panda-es");
> > +		env_set(ctx_uboot, "board_name", "panda-es");
> >  #endif
> >  		board_id = ((board_id4 << 4) | (board_id3 << 3) |
> >  			(board_id2 << 2) | (board_id1 << 1) |
> > (board_id0)); @@ -117,7 +117,7 @@ int get_board_revision(void)
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  		if ((board_id >= 0x3) && (processor_rev ==
> > OMAP4430_ES2_3))
> > -			env_set("board_name", "panda-a4");
> > +			env_set(ctx_uboot, "board_name", "panda-a4");
> >  #endif
> >  	}
> >  
> > diff --git a/board/toradex/apalis-imx8/apalis-imx8.c
> > b/board/toradex/apalis-imx8/apalis-imx8.c index
> > af48b560952e..7e0f01534a9e 100644 ---
> > a/board/toradex/apalis-imx8/apalis-imx8.c +++
> > b/board/toradex/apalis-imx8/apalis-imx8.c @@ -117,8 +117,8 @@ int
> > board_late_init(void) {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  /* TODO move to common */
> > -	env_set("board_name", "Apalis iMX8QM");
> > -	env_set("board_rev", "v1.0");
> > +	env_set(ctx_uboot, "board_name", "Apalis iMX8QM");
> > +	env_set(ctx_uboot, "board_rev", "v1.0");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/toradex/apalis_imx6/apalis_imx6.c
> > b/board/toradex/apalis_imx6/apalis_imx6.c index
> > 6421a22c25a7..c40ccedc4c9d 100644 ---
> > a/board/toradex/apalis_imx6/apalis_imx6.c +++
> > b/board/toradex/apalis_imx6/apalis_imx6.c @@ -701,7 +701,7 @@ int
> > board_late_init(void) 
> >  	rev = get_board_rev();
> >  	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
> > -	env_set("board_rev", env_str);
> > +	env_set(ctx_uboot, "board_rev", env_str);
> >  
> >  #ifndef CONFIG_TDX_APALIS_IMX6_V1_0
> >  	if ((rev & 0xfff0) == 0x0100) {
> > @@ -711,12 +711,12 @@ int board_late_init(void)
> >  		setup_iomux_dce_uart();
> >  
> >  		/* if using the default device tree, use version for
> > V1.0 HW */
> > -		fdt_env = env_get("fdt_file");
> > +		fdt_env = env_get(ctx_uboot, "fdt_file");
> >  		if ((fdt_env != NULL) && (strcmp(FDT_FILE, fdt_env)
> > == 0)) {
> > -			env_set("fdt_file", FDT_FILE_V1_0);
> > +			env_set(ctx_uboot, "fdt_file",
> > FDT_FILE_V1_0); printf("patching fdt_file to " FDT_FILE_V1_0 "\n");
> >  #ifndef CONFIG_ENV_IS_NOWHERE
> > -			env_save();
> > +			env_save(ctx_uboot);
> >  #endif
> >  		}
> >  	}
> > @@ -726,8 +726,8 @@ int board_late_init(void)
> >  #ifdef CONFIG_CMD_USB_SDP
> >  	if (is_boot_from_usb()) {
> >  		printf("Serial Downloader recovery mode, using sdp
> > command\n");
> > -		env_set("bootdelay", "0");
> > -		env_set("bootcmd", "sdp 0");
> > +		env_set(ctx_uboot, "bootdelay", "0");
> > +		env_set(ctx_uboot, "bootcmd", "sdp 0");
> >  	}
> >  #endif /* CONFIG_CMD_USB_SDP */
> >  
> > diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c
> > b/board/toradex/colibri-imx6ull/colibri-imx6ull.c index
> > d1ae463941ae..160b79ba0b27 100644 ---
> > a/board/toradex/colibri-imx6ull/colibri-imx6ull.c +++
> > b/board/toradex/colibri-imx6ull/colibri-imx6ull.c @@ -178,7 +178,7 @@
> > int board_late_init(void) */
> >  	if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
> >  	    tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT)
> > -		env_set("variant", "-wifi");
> > +		env_set(ctx_uboot, "variant", "-wifi");
> >  #endif
> >  
> >  	/*
> > @@ -196,8 +196,8 @@ int board_late_init(void)
> >  #ifdef CONFIG_CMD_USB_SDP
> >  	if (is_boot_from_usb()) {
> >  		printf("Serial Downloader recovery mode, using sdp
> > command\n");
> > -		env_set("bootdelay", "0");
> > -		env_set("bootcmd", "sdp 0");
> > +		env_set(ctx_uboot, "bootdelay", "0");
> > +		env_set(ctx_uboot, "bootcmd", "sdp 0");
> >  	}
> >  #endif /* CONFIG_CMD_USB_SDP */
> >  
> > diff --git a/board/toradex/colibri-imx8x/colibri-imx8x.c
> > b/board/toradex/colibri-imx8x/colibri-imx8x.c index
> > eae3c591a164..ef52f95dc93e 100644 ---
> > a/board/toradex/colibri-imx8x/colibri-imx8x.c +++
> > b/board/toradex/colibri-imx8x/colibri-imx8x.c @@ -129,8 +129,8 @@ int
> > board_late_init(void) {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  /* TODO move to common */
> > -	env_set("board_name", "Colibri iMX8QXP");
> > -	env_set("board_rev", "v1.0");
> > +	env_set(ctx_uboot, "board_name", "Colibri iMX8QXP");
> > +	env_set(ctx_uboot, "board_rev", "v1.0");
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/toradex/colibri_imx6/colibri_imx6.c
> > b/board/toradex/colibri_imx6/colibri_imx6.c index
> > ad40b589c1ed..1c1c1577eb1f 100644 ---
> > a/board/toradex/colibri_imx6/colibri_imx6.c +++
> > b/board/toradex/colibri_imx6/colibri_imx6.c @@ -661,14 +661,14 @@ int
> > board_late_init(void) 
> >  	rev = get_board_rev();
> >  	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
> > -	env_set("board_rev", env_str);
> > +	env_set(ctx_uboot, "board_rev", env_str);
> >  #endif
> >  
> >  #ifdef CONFIG_CMD_USB_SDP
> >  	if (is_boot_from_usb()) {
> >  		printf("Serial Downloader recovery mode, using sdp
> > command\n");
> > -		env_set("bootdelay", "0");
> > -		env_set("bootcmd", "sdp 0");
> > +		env_set(ctx_uboot, "bootdelay", "0");
> > +		env_set(ctx_uboot, "bootcmd", "sdp 0");
> >  	}
> >  #endif /* CONFIG_CMD_USB_SDP */
> >  
> > @@ -702,7 +702,7 @@ int ft_board_setup(void *blob, bd_t *bd)
> >  
> >  	ft_common_board_setup(blob, bd);
> >  
> > -	cma_size = env_get_ulong("cma-size", 10, 320 * 1024 * 1024);
> > +	cma_size = env_get_ulong(ctx_uboot, "cma-size", 10, 320 *
> > 1024 * 1024); cma_size = min((u32)(gd->ram_size >> 1), cma_size);
> >  
> >  	fdt_setprop_u32(blob,
> > diff --git a/board/toradex/colibri_vf/colibri_vf.c
> > b/board/toradex/colibri_vf/colibri_vf.c index
> > 04d8ffd1e666..e466d8aad6e1 100644 ---
> > a/board/toradex/colibri_vf/colibri_vf.c +++
> > b/board/toradex/colibri_vf/colibri_vf.c @@ -392,7 +392,7 @@ int
> > board_late_init(void) if (((src->sbmr2 & SRC_SBMR2_BMOD_MASK) >>
> > SRC_SBMR2_BMOD_SHIFT) == SRC_SBMR2_BMOD_SERIAL) {
> >  		printf("Serial Downloader recovery mode, disable
> > autoboot\n");
> > -		env_set("bootdelay", "-1");
> > +		env_set(ctx_uboot, "bootdelay", "-1");
> >  	}
> >  
> >  	return 0;
> > diff --git a/board/toradex/common/tdx-cfg-block.c
> > b/board/toradex/common/tdx-cfg-block.c index
> > 9c86230595b9..6897ced0f7fe 100644 ---
> > a/board/toradex/common/tdx-cfg-block.c +++
> > b/board/toradex/common/tdx-cfg-block.c @@ -314,7 +314,7 @@ static int
> > get_cfgblock_interactive(void) wb = console_buffer[0];
> >  #endif
> >  
> > -	soc = env_get("soc");
> > +	soc = env_get(ctx_uboot, "soc");
> >  	if (!strcmp("mx6", soc)) {
> >  #ifdef CONFIG_TARGET_APALIS_IMX6
> >  		if (it == 'y' || it == 'Y') {
> > diff --git a/board/toradex/common/tdx-common.c
> > b/board/toradex/common/tdx-common.c index e9441a7979d2..a51749dd78c2
> > 100644 --- a/board/toradex/common/tdx-common.c
> > +++ b/board/toradex/common/tdx-common.c
> > @@ -81,7 +81,7 @@ int show_board_info(void)
> >  			tdx_hw_tag.ver_minor,
> >  			(char)tdx_hw_tag.ver_assembly + 'A');
> >  
> > -		env_set("serial#", tdx_serial_str);
> > +		env_set(ctx_uboot, "serial#", tdx_serial_str);
> >  
> >  		printf("Model: Toradex %s %s, Serial# %s\n",
> >  		       toradex_modules[tdx_hw_tag.prodid],
> > diff --git a/board/tqc/tqma6/tqma6.c b/board/tqc/tqma6/tqma6.c
> > index 5b20afd48814..f13126c2ee59 100644
> > --- a/board/tqc/tqma6/tqma6.c
> > +++ b/board/tqc/tqma6/tqma6.c
> > @@ -253,7 +253,7 @@ int power_init_board(void)
> >  
> >  int board_late_init(void)
> >  {
> > -	env_set("board_name", tqma6_get_boardname());
> > +	env_set(ctx_uboot, "board_name", tqma6_get_boardname());
> >  
> >  	tqma6_bb_board_late_init();
> >  
> > diff --git a/board/udoo/neo/neo.c b/board/udoo/neo/neo.c
> > index 5c468a6a973e..2a61dc29ef92 100644
> > --- a/board/udoo/neo/neo.c
> > +++ b/board/udoo/neo/neo.c
> > @@ -437,7 +437,7 @@ int checkboard(void)
> >  int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> > -	env_set("board_name", board_string());
> > +	env_set(ctx_uboot, "board_name", board_string());
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/udoo/udoo.c b/board/udoo/udoo.c
> > index f2c2bf47b0fd..88bc24b2b475 100644
> > --- a/board/udoo/udoo.c
> > +++ b/board/udoo/udoo.c
> > @@ -254,9 +254,9 @@ int board_late_init(void)
> >  {
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	if (is_cpu_type(MXC_CPU_MX6Q))
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  #endif
> >  	return 0;
> >  }
> > diff --git a/board/varisys/common/sys_eeprom.c
> > b/board/varisys/common/sys_eeprom.c index 77772a6923e4..5b248f8b0f44
> > 100644 --- a/board/varisys/common/sys_eeprom.c
> > +++ b/board/varisys/common/sys_eeprom.c
> > @@ -401,7 +401,7 @@ int mac_read_from_generic_eeprom(const char
> > *envvar, int chip, mac[5]);
> >  
> >  		printf("MAC: %s\n", ethaddr);
> > -		env_set(envvar, ethaddr);
> > +		env_set(ctx_uboot, envvar, ethaddr);
> >  	}
> >  
> >  	return ret;
> > @@ -486,8 +486,8 @@ int mac_read_from_eeprom_common(void)
> >  			/* Only initialize environment variables
> > that are blank
> >  			 * (i.e. have not yet been set)
> >  			 */
> > -			if (!env_get(enetvar))
> > -				env_set(enetvar, ethaddr);
> > +			if (!env_get(ctx_uboot, enetvar))
> > +				env_set(ctx_uboot, enetvar, ethaddr);
> >  		}
> >  	}
> >  
> > diff --git a/board/vscom/baltos/board.c b/board/vscom/baltos/board.c
> > index 1ba58d0f11dd..5e799d546786 100644
> > --- a/board/vscom/baltos/board.c
> > +++ b/board/vscom/baltos/board.c
> > @@ -65,7 +65,7 @@ static int baltos_set_console(void)
> >  	printf("DIPs: 0x%1x\n", (~dips) & 0xf);
> >  
> >  	if ((dips & 0xf) == 0xe)
> > -		env_set("console", "ttyUSB0,115200n8");
> > +		env_set(ctx_uboot, "console", "ttyUSB0,115200n8");
> >  
> >  	return 0;
> >  }
> > @@ -367,7 +367,7 @@ int board_late_init(void)
> >  		return -ENODEV;
> >  	}
> >  
> > -	env_set("board_name", model);
> > +	env_set(ctx_uboot, "board_name", model);
> >  #endif
> >  
> >  	return 0;
> > @@ -447,7 +447,7 @@ int board_eth_init(bd_t *bis)
> >  
> >  #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD))
> > || \ (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
> > -	if (!env_get("ethaddr")) {
> > +	if (!env_get(ctx_uboot, "ethaddr")) {
> >  		printf("<ethaddr> not set. Validating first E-fuse
> > MAC\n"); 
> >  		if (is_valid_ethaddr(mac_addr))
> > diff --git a/board/wandboard/wandboard.c b/board/wandboard/wandboard.c
> > index 69cdf3e9c96b..4ba472cae9b8 100644
> > --- a/board/wandboard/wandboard.c
> > +++ b/board/wandboard/wandboard.c
> > @@ -451,18 +451,18 @@ int board_late_init(void)
> >  
> >  #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> >  	if (is_mx6dqp())
> > -		env_set("board_rev", "MX6QP");
> > +		env_set(ctx_uboot, "board_rev", "MX6QP");
> >  	else if (is_mx6dq())
> > -		env_set("board_rev", "MX6Q");
> > +		env_set(ctx_uboot, "board_rev", "MX6Q");
> >  	else
> > -		env_set("board_rev", "MX6DL");
> > +		env_set(ctx_uboot, "board_rev", "MX6DL");
> >  
> >  	if (is_revd1())
> > -		env_set("board_name", "D1");
> > +		env_set(ctx_uboot, "board_name", "D1");
> >  	else if (is_revc1())
> > -		env_set("board_name", "C1");
> > +		env_set(ctx_uboot, "board_name", "C1");
> >  	else
> > -		env_set("board_name", "B1");
> > +		env_set(ctx_uboot, "board_name", "B1");
> >  #endif
> >  	return 0;
> >  }
> > diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c
> > index 39ae98225738..549d65b3469d 100644
> > --- a/board/warp7/warp7.c
> > +++ b/board/warp7/warp7.c
> > @@ -148,9 +148,9 @@ int board_late_init(void)
> >  
> >  #ifdef CONFIG_SECURE_BOOT
> >  	/* Determine HAB state */
> > -	env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
> > +	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME,
> > imx_hab_is_enabled()); #else
> > -	env_set_ulong(HAB_ENABLED_ENVNAME, 0);
> > +	env_set_ulong(ctx_uboot, HAB_ENABLED_ENVNAME, 0);
> >  #endif
> >  
> >  #ifdef CONFIG_SERIAL_TAG
> > @@ -158,7 +158,7 @@ int board_late_init(void)
> >  	get_board_serial(&serialnr);
> >  	snprintf(serial_string, sizeof(serial_string),
> > "WaRP7-0x%08x%08x", serialnr.low, serialnr.high);
> > -	env_set("serial#", serial_string);
> > +	env_set(ctx_uboot, "serial#", serial_string);
> >  #endif
> >  
> >  	return 0;
> > diff --git a/board/work-microwave/work_92105/work_92105_display.c
> > b/board/work-microwave/work_92105/work_92105_display.c index
> > db04dcabc7bc..e673921b7bbc 100644 ---
> > a/board/work-microwave/work_92105/work_92105_display.c +++
> > b/board/work-microwave/work_92105/work_92105_display.c @@ -228,7
> > +228,7 @@ void work_92105_display_init(void) i2c_write(0x2c, 0x01, 1,
> > &enable_backlight, 1); 
> >  	/* set display contrast */
> > -	display_contrast_str = env_get("fwopt_dispcontrast");
> > +	display_contrast_str = env_get(ctx_uboot,
> > "fwopt_dispcontrast"); if (display_contrast_str)
> >  		display_contrast =
> > simple_strtoul(display_contrast_str, NULL, 10);
> > diff --git a/board/xes/common/board.c b/board/xes/common/board.c
> > index 43575bc302d6..b5cc9a69508a 100644
> > --- a/board/xes/common/board.c
> > +++ b/board/xes/common/board.c
> > @@ -51,13 +51,13 @@ int checkboard(void)
> >  
> >  	/* Display board specific information */
> >  	puts("       ");
> > -	i = env_get_f("board_rev", buf, sizeof(buf));
> > +	i = env_get_f("board_rev", buf, sizeof(ctx_uboot, buf));
> >  	if (i > 0)
> >  		printf("Rev %s, ", buf);
> > -	i = env_get_f("serial#", buf, sizeof(buf));
> > +	i = env_get_f("serial#", buf, sizeof(ctx_uboot, buf));
> >  	if (i > 0)
> >  		printf("Serial# %s, ", buf);
> > -	i = env_get_f("board_cfg", buf, sizeof(buf));
> > +	i = env_get_f("board_cfg", buf, sizeof(ctx_uboot, buf));
> >  	if (i > 0)
> >  		printf("Cfg %s", buf);
> >  	puts("\n");
> > diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
> > index 35191b2f813b..509834c679ab 100644
> > --- a/board/xilinx/zynq/board.c
> > +++ b/board/xilinx/zynq/board.c
> > @@ -41,27 +41,27 @@ int board_late_init(void)
> >  	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
> >  	case ZYNQ_BM_QSPI:
> >  		mode = "qspi";
> > -		env_set("modeboot", "qspiboot");
> > +		env_set(ctx_uboot, "modeboot", "qspiboot");
> >  		break;
> >  	case ZYNQ_BM_NAND:
> >  		mode = "nand";
> > -		env_set("modeboot", "nandboot");
> > +		env_set(ctx_uboot, "modeboot", "nandboot");
> >  		break;
> >  	case ZYNQ_BM_NOR:
> >  		mode = "nor";
> > -		env_set("modeboot", "norboot");
> > +		env_set(ctx_uboot, "modeboot", "norboot");
> >  		break;
> >  	case ZYNQ_BM_SD:
> >  		mode = "mmc";
> > -		env_set("modeboot", "sdboot");
> > +		env_set(ctx_uboot, "modeboot", "sdboot");
> >  		break;
> >  	case ZYNQ_BM_JTAG:
> >  		mode = "pxe dhcp";
> > -		env_set("modeboot", "jtagboot");
> > +		env_set(ctx_uboot, "modeboot", "jtagboot");
> >  		break;
> >  	default:
> >  		mode = "";
> > -		env_set("modeboot", "");
> > +		env_set(ctx_uboot, "modeboot", "");
> >  		break;
> >  	}
> >  
> > @@ -69,7 +69,7 @@ int board_late_init(void)
> >  	 * One terminating char + one byte for space between mode
> >  	 * and default boot_targets
> >  	 */
> > -	env_targets = env_get("boot_targets");
> > +	env_targets = env_get(ctx_uboot, "boot_targets");
> >  	if (env_targets)
> >  		env_targets_len = strlen(env_targets);
> >  
> > @@ -80,7 +80,7 @@ int board_late_init(void)
> >  	sprintf(new_targets, "%s %s", mode,
> >  		env_targets ? env_targets : "");
> >  
> > -	env_set("boot_targets", new_targets);
> > +	env_set(ctx_uboot, "boot_targets", new_targets);
> >  
> >  	return 0;
> >  }
> > diff --git a/board/xilinx/zynqmp/cmds.c b/board/xilinx/zynqmp/cmds.c
> > index ed7ba58c6475..e5c1dab091ca 100644
> > --- a/board/xilinx/zynqmp/cmds.c
> > +++ b/board/xilinx/zynqmp/cmds.c
> > @@ -57,7 +57,7 @@ static int do_zynqmp_verify_secure(cmd_tbl_t
> > *cmdtp, int flag, int argc, } else {
> >  		addr = (u64)ret_payload[1] << 32 | ret_payload[2];
> >  		printf("Verified image at 0x%llx\n", addr);
> > -		env_set_hex("zynqmp_verified_img_addr", addr);
> > +		env_set_hex(ctx_uboot, "zynqmp_verified_img_addr",
> > addr); }
> >  
> >  	return ret;
> > diff --git a/board/xilinx/zynqmp/zynqmp.c
> > b/board/xilinx/zynqmp/zynqmp.c index d649daba96d4..31e26fb097a4 100644
> > --- a/board/xilinx/zynqmp/zynqmp.c
> > +++ b/board/xilinx/zynqmp/zynqmp.c
> > @@ -479,7 +479,7 @@ static int reset_reason(void)
> >  
> >  	puts("\n");
> >  
> > -	env_set("reset_reason", reason);
> > +	env_set(ctx_uboot, "reset_reason", reason);
> >  
> >  	ret = zynqmp_mmio_write(~0, ~0,
> > (ulong)&crlapb_base->reset_reason); if (ret)
> > @@ -494,7 +494,7 @@ static int set_fdtfile(void)
> >  	const char *suffix = ".dtb";
> >  	const char *vendor = "xilinx/";
> >  
> > -	if (env_get("fdtfile"))
> > +	if (env_get(ctx_uboot, "fdtfile"))
> >  		return 0;
> >  
> >  	compatible = (char *)fdt_getprop(gd->fdt_blob, 0,
> > "compatible", NULL); @@ -511,7 +511,7 @@ static int set_fdtfile(void)
> >  
> >  		sprintf(fdtfile, "%s%s%s", vendor, compatible,
> > suffix); 
> > -		env_set("fdtfile", fdtfile);
> > +		env_set(ctx_uboot, "fdtfile", fdtfile);
> >  		free(fdtfile);
> >  	}
> >  
> > @@ -558,23 +558,23 @@ int board_late_init(void)
> >  	case USB_MODE:
> >  		puts("USB_MODE\n");
> >  		mode = "usb";
> > -		env_set("modeboot", "usb_dfu_spl");
> > +		env_set(ctx_uboot, "modeboot", "usb_dfu_spl");
> >  		break;
> >  	case JTAG_MODE:
> >  		puts("JTAG_MODE\n");
> >  		mode = "pxe dhcp";
> > -		env_set("modeboot", "jtagboot");
> > +		env_set(ctx_uboot, "modeboot", "jtagboot");
> >  		break;
> >  	case QSPI_MODE_24BIT:
> >  	case QSPI_MODE_32BIT:
> >  		mode = "qspi0";
> >  		puts("QSPI_MODE\n");
> > -		env_set("modeboot", "qspiboot");
> > +		env_set(ctx_uboot, "modeboot", "qspiboot");
> >  		break;
> >  	case EMMC_MODE:
> >  		puts("EMMC_MODE\n");
> >  		mode = "mmc0";
> > -		env_set("modeboot", "emmcboot");
> > +		env_set(ctx_uboot, "modeboot", "emmcboot");
> >  		break;
> >  	case SD_MODE:
> >  		puts("SD_MODE\n");
> > @@ -589,7 +589,7 @@ int board_late_init(void)
> >  
> >  		mode = "mmc";
> >  		bootseq = dev->seq;
> > -		env_set("modeboot", "sdboot");
> > +		env_set(ctx_uboot, "modeboot", "sdboot");
> >  		break;
> >  	case SD1_LSHFT_MODE:
> >  		puts("LVL_SHFT_");
> > @@ -607,12 +607,12 @@ int board_late_init(void)
> >  
> >  		mode = "mmc";
> >  		bootseq = dev->seq;
> > -		env_set("modeboot", "sdboot");
> > +		env_set(ctx_uboot, "modeboot", "sdboot");
> >  		break;
> >  	case NAND_MODE:
> >  		puts("NAND_MODE\n");
> >  		mode = "nand0";
> > -		env_set("modeboot", "nandboot");
> > +		env_set(ctx_uboot, "modeboot", "nandboot");
> >  		break;
> >  	default:
> >  		mode = "";
> > @@ -629,7 +629,7 @@ int board_late_init(void)
> >  	 * One terminating char + one byte for space between mode
> >  	 * and default boot_targets
> >  	 */
> > -	env_targets = env_get("boot_targets");
> > +	env_targets = env_get(ctx_uboot, "boot_targets");
> >  	if (env_targets)
> >  		env_targets_len = strlen(env_targets);
> >  
> > @@ -645,7 +645,7 @@ int board_late_init(void)
> >  		sprintf(new_targets, "%s %s", mode,
> >  			env_targets ? env_targets : "");
> >  
> > -	env_set("boot_targets", new_targets);
> > +	env_set(ctx_uboot, "boot_targets", new_targets);
> >  
> >  	reset_reason();
> >  
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment
  2019-09-05 19:43   ` Heinrich Schuchardt
@ 2019-09-06  0:41     ` AKASHI Takahiro
  0 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-06  0:41 UTC (permalink / raw)
  To: u-boot

On Thu, Sep 05, 2019 at 09:43:59PM +0200, Heinrich Schuchardt wrote:
> On 9/5/19 10:21 AM, AKASHI Takahiro wrote:
> >In this patch, env context fo U-Boot environment is defined to utilize
> >new env interfaces, maintaining the compatibility with the existing
> >semantics and Kconfig configuration.
> >
> >In this commit, FAT file system and flash device are only supported
> >devices for backing storages, but extending to other devices will be
> >quite straightforward.
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >---
> >  env/Kconfig.uboot   | 671 ++++++++++++++++++++++++++++++++++++++++++++
> >  env/Makefile        |   2 +-
> >  env/env_ctx_uboot.c | 292 +++++++++++++++++++
> >  include/env.h       |   3 +
> >  4 files changed, 967 insertions(+), 1 deletion(-)
> >  create mode 100644 env/Kconfig.uboot
> >  create mode 100644 env/env_ctx_uboot.c
> >
> >diff --git a/env/Kconfig.uboot b/env/Kconfig.uboot
> >new file mode 100644
> >index 000000000000..e4334f7f2878
> >--- /dev/null
> >+++ b/env/Kconfig.uboot
> >@@ -0,0 +1,671 @@
> 
> Only one of the options below should be selected. So, please, use a
> 'choice' statement. drives/video/Kconfig has an example.

I didn't change much from the original env/Kconfig.
So there may be some reason for not using 'choice' here that I don't
know yet.

> >+config ENV_IS_NOWHERE
> >+	bool "U-Boot Environment is not stored"
> >+	default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
> >+		     !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
> >+		     !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
> >+		     !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
> >+		     !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
> >+		     !ENV_IS_IN_UBI
> >+	help
> >+	  Define this if you don't want to or can't have an environment stored
> >+	  on a storage medium. In this case the environment will still exist
> >+	  while U-Boot is running, but once U-Boot exits it will not be
> >+	  stored. U-Boot will therefore always start up with a default
> >+	  environment.
> >+
> >+config ENV_IS_IN_EEPROM
> >+	bool "Environment in EEPROM"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_EEPROM
> >+	help
> >+	  Use this if you have an EEPROM or similar serial access
> >+	  device and a driver for it.
> >+
> >+	  - CONFIG_ENV_OFFSET:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines specify the offset and size of the
> >+	  environment area within the total memory of your EEPROM.
> >+
> >+	  Note that we consider the length of the address field to
> >+	  still be one byte because the extra address bits are hidden
> >+	  in the chip address.
> >+
> >+	  - CONFIG_ENV_EEPROM_IS_ON_I2C
> >+	  define this, if you have I2C and SPI activated, and your
> >+	  EEPROM, which holds the environment, is on the I2C bus.
> >+
> >+	  - CONFIG_I2C_ENV_EEPROM_BUS
> >+	  if you have an Environment on an EEPROM reached over
> >+	  I2C muxes, you can define here, how to reach this
> >+	  EEPROM. For example:
> >+
> >+	  #define CONFIG_I2C_ENV_EEPROM_BUS	  1
> >+
> >+	  EEPROM which holds the environment, is reached over
> >+	  a pca9547 i2c mux with address 0x70, channel 3.
> >+
> >+config ENV_IS_IN_FAT
> >+	bool "Environment is in a FAT filesystem"
> >+	depends on !CHAIN_OF_TRUST
> >+	default y if ARCH_BCM283X
> >+	default y if ARCH_SUNXI && MMC
> >+	default y if MMC_OMAP_HS && TI_COMMON_CMD_OPTIONS
> >+	select ENV_DRV_FAT
> >+	help
> >+	  Define this if you want to use the FAT file system for the environment.
> >+
> >+config ENV_IS_IN_EXT4
> >+	bool "Environment is in a EXT4 filesystem"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_EXT4
> >+	help
> >+	  Define this if you want to use the EXT4 file system for the environment.
> >+
> >+config ENV_IS_IN_FLASH
> >+	bool "Environment in flash memory"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_FLASH
> >+	default y if ARCH_CINTEGRATOR
> >+	default y if ARCH_INTEGRATOR_CP
> >+	default y if M548x || M547x || M5282 || MCF547x_8x
> >+	default y if MCF532x || MCF52x2
> >+	default y if MPC86xx || MPC83xx
> >+	default y if ARCH_MPC8572 || ARCH_MPC8548 || ARCH_MPC8641
> >+	default y if SH && !CPU_SH4
> >+	help
> >+	  Define this if you have a flash device which you want to use for the
> >+	  environment.
> >+
> >+	  a) The environment occupies one whole flash sector, which is
> >+	   "embedded" in the text segment with the U-Boot code. This
> >+	   happens usually with "bottom boot sector" or "top boot
> >+	   sector" type flash chips, which have several smaller
> >+	   sectors at the start or the end. For instance, such a
> >+	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
> >+	   such a case you would place the environment in one of the
> >+	   4 kB sectors - with U-Boot code before and after it. With
> >+	   "top boot sector" type flash chips, you would put the
> >+	   environment in one of the last sectors, leaving a gap
> >+	   between U-Boot and the environment.
> >+
> >+	  CONFIG_ENV_OFFSET:
> >+
> >+	   Offset of environment data (variable area) to the
> >+	   beginning of flash memory; for instance, with bottom boot
> >+	   type flash chips the second sector can be used: the offset
> >+	   for this sector is given here.
> >+
> >+	   CONFIG_ENV_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
> >+
> >+	  CONFIG_ENV_ADDR:
> >+
> >+	   This is just another way to specify the start address of
> >+	   the flash sector containing the environment (instead of
> >+	   CONFIG_ENV_OFFSET).
> >+
> >+	  CONFIG_ENV_SECT_SIZE:
> >+
> >+	   Size of the sector containing the environment.
> >+
> >+
> >+	  b) Sometimes flash chips have few, equal sized, BIG sectors.
> >+	   In such a case you don't want to spend a whole sector for
> >+	   the environment.
> >+
> >+	  CONFIG_ENV_SIZE:
> >+
> >+	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
> >+	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
> >+	   of this flash sector for the environment. This saves
> >+	   memory for the RAM copy of the environment.
> >+
> >+	   It may also save flash memory if you decide to use this
> >+	   when your environment is "embedded" within U-Boot code,
> >+	   since then the remainder of the flash sector could be used
> >+	   for U-Boot code. It should be pointed out that this is
> >+	   STRONGLY DISCOURAGED from a robustness point of view:
> >+	   updating the environment in flash makes it always
> >+	   necessary to erase the WHOLE sector. If something goes
> >+	   wrong before the contents has been restored from a copy in
> >+	   RAM, your target system will be dead.
> >+
> >+	  CONFIG_ENV_ADDR_REDUND
> >+	  CONFIG_ENV_SIZE_REDUND
> >+
> >+	   These settings describe a second storage area used to hold
> >+	   a redundant copy of the environment data, so that there is
> >+	   a valid backup copy in case there is a power failure during
> >+	   a "saveenv" operation.
> >+
> >+	  BE CAREFUL! Any changes to the flash layout, and some changes to the
> >+	  source code will make it necessary to adapt <board>/u-boot.lds*
> >+	  accordingly!
> >+
> >+config ENV_IS_IN_MMC
> >+	bool "Environment in an MMC device"
> >+	depends on !CHAIN_OF_TRUST
> >+	depends on MMC
> >+	select ENV_DRV_MMC
> >+	default y if ARCH_EXYNOS4
> >+	default y if MX6SX || MX7D
> >+	default y if TEGRA30 || TEGRA124
> >+	default y if TEGRA_ARMV8_COMMON
> >+	help
> >+	  Define this if you have an MMC device which you want to use for the
> >+	  environment.
> >+
> >+	  CONFIG_SYS_MMC_ENV_DEV:
> >+
> >+	  Specifies which MMC device the environment is stored in.
> >+
> >+	  CONFIG_SYS_MMC_ENV_PART (optional):
> >+
> >+	  Specifies which MMC partition the environment is stored in. If not
> >+	  set, defaults to partition 0, the user area. Common values might be
> >+	  1 (first MMC boot partition), 2 (second MMC boot partition).
> >+
> >+	  CONFIG_ENV_OFFSET:
> >+	  CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines specify the offset and size of the environment
> >+	  area within the specified MMC device.
> >+
> >+	  If offset is positive (the usual case), it is treated as relative to
> >+	  the start of the MMC partition. If offset is negative, it is treated
> >+	  as relative to the end of the MMC partition. This can be useful if
> >+	  your board may be fitted with different MMC devices, which have
> >+	  different sizes for the MMC partitions, and you always want the
> >+	  environment placed at the very end of the partition, to leave the
> >+	  maximum possible space before it, to store other data.
> >+
> >+	  These two values are in units of bytes, but must be aligned to an
> >+	  MMC sector boundary.
> >+
> >+	  CONFIG_ENV_OFFSET_REDUND (optional):
> >+
> >+	  Specifies a second storage area, of CONFIG_ENV_SIZE size, used to
> >+	  hold a redundant copy of the environment data. This provides a
> >+	  valid backup copy in case the other copy is corrupted, e.g. due
> >+	  to a power failure during a "saveenv" operation.
> >+
> >+	  This value may also be positive or negative; this is handled in the
> >+	  same way as CONFIG_ENV_OFFSET.
> >+
> >+	  This value is also in units of bytes, but must also be aligned to
> >+	  an MMC sector boundary.
> >+
> >+	  CONFIG_ENV_SIZE_REDUND (optional):
> >+
> >+	  This value need not be set, even when CONFIG_ENV_OFFSET_REDUND is
> >+	  set. If this value is set, it must be set to the same value as
> >+	  CONFIG_ENV_SIZE.
> >+
> >+config ENV_IS_IN_NAND
> >+	bool "Environment in a NAND device"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_NAND
> >+	help
> >+	  Define this if you have a NAND device which you want to use for the
> >+	  environment.
> >+
> >+	  - CONFIG_ENV_OFFSET:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines specify the offset and size of the environment
> >+	  area within the first NAND device.  CONFIG_ENV_OFFSET must be
> >+	  aligned to an erase block boundary.
> >+
> >+	  - CONFIG_ENV_OFFSET_REDUND (optional):
> >+
> >+	  This setting describes a second storage area of CONFIG_ENV_SIZE
> >+	  size used to hold a redundant copy of the environment data, so
> >+	  that there is a valid backup copy in case there is a power failure
> >+	  during a "saveenv" operation.	 CONFIG_ENV_OFFSET_REDUND must be
> >+	  aligned to an erase block boundary.
> >+
> >+	  - CONFIG_ENV_RANGE (optional):
> >+
> >+	  Specifies the length of the region in which the environment
> >+	  can be written.  This should be a multiple of the NAND device's
> >+	  block size.  Specifying a range with more erase blocks than
> >+	  are needed to hold CONFIG_ENV_SIZE allows bad blocks within
> >+	  the range to be avoided.
> >+
> >+	  - CONFIG_ENV_OFFSET_OOB (optional):
> >+
> >+	  Enables support for dynamically retrieving the offset of the
> >+	  environment from block zero's out-of-band data.  The
> >+	  "nand env.oob" command can be used to record this offset.
> >+	  Currently, CONFIG_ENV_OFFSET_REDUND is not supported when
> >+	  using CONFIG_ENV_OFFSET_OOB.
> >+
> >+config ENV_IS_IN_NVRAM
> >+	bool "Environment in a non-volatile RAM"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_NVRAM
> >+	help
> >+	  Define this if you have some non-volatile memory device
> >+	  (NVRAM, battery buffered SRAM) which you want to use for the
> >+	  environment.
> >+
> >+	  - CONFIG_ENV_ADDR:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines are used to determine the memory area you
> >+	  want to use for environment. It is assumed that this memory
> >+	  can just be read and written to, without any special
> >+	  provision.
> >+
> >+config ENV_IS_IN_ONENAND
> >+	bool "Environment is in OneNAND"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_ONENAND
> >+	help
> >+	  Define this if you want to put your local device's environment in
> >+	  OneNAND.
> >+
> >+	  - CONFIG_ENV_ADDR:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines are used to determine the device range you
> >+	  want to use for environment. It is assumed that this memory
> >+	  can just be read and written to, without any special
> >+	  provision.
> >+
> >+config ENV_IS_IN_REMOTE
> >+	bool "Environment is in remote memory space"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_REMOTE
> >+	help
> >+	  Define this if you have a remote memory space which you
> >+	  want to use for the local device's environment.
> >+
> >+	  - CONFIG_ENV_ADDR:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines specify the address and size of the
> >+	  environment area within the remote memory space. The
> >+	  local device can get the environment from remote memory
> >+	  space by SRIO or PCIE links.
> >+
> >+config ENV_IS_IN_SPI_FLASH
> >+	bool "Environment is in SPI flash"
> >+	depends on !CHAIN_OF_TRUST && SPI
> >+	select ENV_DRV_SPI_FLASH
> >+	default y if ARMADA_XP
> >+	default y if INTEL_BAYTRAIL
> >+	default y if INTEL_BRASWELL
> >+	default y if INTEL_BROADWELL
> >+	default y if NORTHBRIDGE_INTEL_IVYBRIDGE
> >+	default y if INTEL_QUARK
> >+	default y if INTEL_QUEENSBAY
> >+	help
> >+	  Define this if you have a SPI Flash memory device which you
> >+	  want to use for the environment.
> >+
> >+	  - CONFIG_ENV_OFFSET:
> >+	  - CONFIG_ENV_SIZE:
> >+
> >+	  These two #defines specify the offset and size of the
> >+	  environment area within the SPI Flash. CONFIG_ENV_OFFSET must be
> >+	  aligned to an erase sector boundary.
> >+
> >+	  - CONFIG_ENV_SECT_SIZE:
> >+
> >+	  Define the SPI flash's sector size.
> >+
> >+	  - CONFIG_ENV_OFFSET_REDUND (optional):
> >+
> >+	  This setting describes a second storage area of CONFIG_ENV_SIZE
> >+	  size used to hold a redundant copy of the environment data, so
> >+	  that there is a valid backup copy in case there is a power failure
> >+	  during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
> >+	  aligned to an erase sector boundary.
> >+
> >+config USE_ENV_SPI_BUS
> >+	bool "SPI flash bus for environment"
> >+	depends on ENV_IS_IN_SPI_FLASH
> >+	help
> >+	  Force the SPI bus for environment.
> >+	  If not defined, use CONFIG_SF_DEFAULT_BUS.
> >+
> >+config ENV_SPI_BUS
> >+	int "Value of SPI flash bus for environment"
> >+	depends on USE_ENV_SPI_BUS
> >+	help
> >+	  Value the SPI bus and chip select for environment.
> >+
> >+config USE_ENV_SPI_CS
> >+	bool "SPI flash chip select for environment"
> >+	depends on ENV_IS_IN_SPI_FLASH
> >+	help
> >+	  Force the SPI chip select for environment.
> >+	  If not defined, use CONFIG_SF_DEFAULT_CS.
> >+
> >+config ENV_SPI_CS
> >+	int "Value of SPI flash chip select for environment"
> >+	depends on USE_ENV_SPI_CS
> >+	help
> >+	  Value of the SPI chip select for environment.
> >+
> >+config USE_ENV_SPI_MAX_HZ
> >+	bool "SPI flash max frequency for environment"
> >+	depends on ENV_IS_IN_SPI_FLASH
> >+	help
> >+	  Force the SPI max work clock for environment.
> >+	  If not defined, use CONFIG_SF_DEFAULT_SPEED.
> >+
> >+config ENV_SPI_MAX_HZ
> >+	int "Value of SPI flash max frequency for environment"
> >+	depends on USE_ENV_SPI_MAX_HZ
> >+	help
> >+	  Value of the SPI max work clock for environment.
> >+
> >+config USE_ENV_SPI_MODE
> >+	bool "SPI flash mode for environment"
> >+	depends on ENV_IS_IN_SPI_FLASH
> >+	help
> >+	  Force the SPI work mode for environment.
> >+
> >+config ENV_SPI_MODE
> >+	hex "Value of SPI flash work mode for environment"
> >+	depends on USE_ENV_SPI_MODE
> >+	help
> >+	  Value of the SPI work mode for environment.
> >+	  See include/spi.h for value.
> >+
> >+config ENV_IS_IN_UBI
> >+	bool "Environment in a UBI volume"
> >+	depends on !CHAIN_OF_TRUST
> >+	select ENV_DRV_UBI
> >+	help
> >+	  Define this if you have an UBI volume that you want to use for the
> >+	  environment.  This has the benefit of wear-leveling the environment
> >+	  accesses, which is important on NAND.
> >+
> >+	  - CONFIG_ENV_UBI_PART:
> >+
> >+	  Define this to a string that is the mtd partition containing the UBI.
> >+
> >+	  - CONFIG_ENV_UBI_VOLUME:
> >+
> >+	  Define this to the name of the volume that you want to store the
> >+	  environment in.
> >+
> >+	  - CONFIG_ENV_UBI_VOLUME_REDUND:
> >+
> >+	  Define this to the name of another volume to store a second copy of
> >+	  the environment in.  This will enable redundant environments in UBI.
> >+	  It is assumed that both volumes are in the same MTD partition.
> >+
> >+config ENV_FAT_INTERFACE
> >+	string "Name of the block device for the environment"
> >+	depends on ENV_IS_IN_FAT
> >+	default "mmc" if ARCH_SUNXI
> >+	default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
> >+	help
> >+	  Define this to a string that is the name of the block device.
> >+
> >+config ENV_FAT_DEVICE_AND_PART
> >+	string "Device and partition for where to store the environment in FAT"
> >+	depends on ENV_IS_IN_FAT
> >+	default "0:1" if TI_COMMON_CMD_OPTIONS
> >+	default "0:auto" if ARCH_ZYNQMP
> >+	default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
> >+	default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
> >+	default "0" if ARCH_AT91
> >+	help
> >+	  Define this to a string to specify the partition of the device. It can
> >+	  be as following:
> >+
> >+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> >+	       - "D:P": device D partition P. Error occurs if device D has no
> >+	                partition table.
> >+	       - "D:0": device D.
> >+	       - "D" or "D:": device D partition 1 if device D has partition
> >+	                      table, or the whole device D if has no partition
> >+	                      table.
> >+	       - "D:auto": first partition in device D with bootable flag set.
> >+	                   If none, first valid partition in device D. If no
> >+	                   partition table then means device D.
> >+
> >+config ENV_FAT_FILE
> >+	string "Name of the FAT file to use for the environment"
> >+	depends on ENV_IS_IN_FAT
> >+	default "uboot.env"
> >+	help
> >+	  It's a string of the FAT file name. This file use to store the
> >+	  environment.
> >+
> >+config ENV_EXT4_INTERFACE
> >+	string "Name of the block device for the environment"
> >+	depends on ENV_IS_IN_EXT4
> >+	help
> >+	  Define this to a string that is the name of the block device.
> >+
> >+config ENV_EXT4_DEVICE_AND_PART
> >+	string "Device and partition for where to store the environment in EXT4"
> >+	depends on ENV_IS_IN_EXT4
> >+	help
> >+	  Define this to a string to specify the partition of the device. It can
> >+	  be as following:
> >+
> >+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> >+	       - "D:P": device D partition P. Error occurs if device D has no
> >+	                partition table.
> >+	       - "D:0": device D.
> >+	       - "D" or "D:": device D partition 1 if device D has partition
> >+	                      table, or the whole device D if has no partition
> >+	                      table.
> >+	       - "D:auto": first partition in device D with bootable flag set.
> >+	                   If none, first valid partition in device D. If no
> >+	                   partition table then means device D.
> >+
> >+config ENV_EXT4_FILE
> >+	string "Name of the EXT4 file to use for the environment"
> >+	depends on ENV_IS_IN_EXT4
> >+	default "uboot.env"
> >+	help
> >+	  It's a string of the EXT4 file name. This file use to store the
> >+	  environment (explicit path to the file)
> >+
> >+if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC || ARCH_STM32MP || ARCH_OMAP2PLUS || ARCH_AT91
> >+
> >+config ENV_OFFSET
> >+	hex "Environment Offset"
> >+	depends on (!ENV_IS_IN_UBI && !ENV_IS_NOWHERE) || ARCH_STM32MP
> >+	default 0x3f8000 if ARCH_ROCKCHIP
> >+	default 0x88000 if ARCH_SUNXI
> >+	default 0xE0000 if ARCH_ZYNQ
> >+	default 0x1E00000 if ARCH_ZYNQMP
> >+	default 0 if ARC
> >+	default 0x140000 if ARCH_AT91
> >+	default 0x260000 if ARCH_OMAP2PLUS
> >+	help
> >+	  Offset from the start of the device (or partition)
> >+
> >+config ENV_SIZE
> >+	hex "Environment Size"
> >+	default 0x40000 if ENV_IS_IN_SPI_FLASH && ARCH_ZYNQMP
> >+	default 0x20000 if ARCH_SUNXI || ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
> >+	default 0x8000 if ARCH_ROCKCHIP || ARCH_ZYNQMP || ARCH_VERSAL
> >+	default 0x4000 if ARC
> >+	default 0x1f000
> >+	help
> >+	  Size of the environment storage area
> >+
> >+config ENV_SECT_SIZE
> >+	hex "Environment Sector-Size"
> >+	depends on (!ENV_IS_NOWHERE && (ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_OMAP2PLUS || ARCH_AT91) )|| ARCH_STM32MP
> >+	default 0x40000 if ARCH_ZYNQMP
> >+	default 0x20000 if ARCH_ZYNQ || ARCH_OMAP2PLUS || ARCH_AT91
> >+	help
> >+	  Size of the sector containing the environment.
> >+
> >+config ENV_UBI_PART
> >+	string "UBI partition name"
> >+	depends on ENV_IS_IN_UBI
> >+	help
> >+	  MTD partition containing the UBI device
> >+
> >+config ENV_UBI_VOLUME
> >+	string "UBI volume name"
> >+	depends on ENV_IS_IN_UBI
> >+	help
> >+	  Name of the volume that you want to store the environment in.
> >+
> >+config ENV_UBI_VOLUME_REDUND
> >+	string "UBI redundant volume name"
> >+	depends on ENV_IS_IN_UBI
> >+	help
> >+	  Name of the redundant volume that you want to store the environment in.
> >+
> >+config ENV_UBI_VID_OFFSET
> >+	int "ubi environment VID offset"
> >+	depends on ENV_IS_IN_UBI
> >+	default 0
> >+	help
> >+	  UBI VID offset for environment. If 0, no custom VID offset is used.
> >+
> >+endif
> >+
> >+config USE_DEFAULT_ENV_FILE
> >+	bool "Create default environment from file"
> >+	help
> >+	  Normally, the default environment is automatically generated
> >+	  based on the settings of various CONFIG_* options, as well
> >+	  as the CONFIG_EXTRA_ENV_SETTINGS. By selecting this option,
> >+	  you can instead define the entire default environment in an
> >+	  external file.
> >+
> >+config DEFAULT_ENV_FILE
> >+	string "Path to default environment file"
> >+	depends on USE_DEFAULT_ENV_FILE
> >+	help
> >+	  The path containing the default environment. The format is
> >+	  the same as accepted by the mkenvimage tool: lines
> >+	  containing key=value pairs, blank lines and lines beginning
> >+	  with # are ignored.
> >+
> >+config ENV_VARS_UBOOT_RUNTIME_CONFIG
> >+	bool "Add run-time information to the environment"
> >+	help
> >+	  Enable this in order to add variables describing certain
> >+	  run-time determined information about the hardware to the
> >+	  environment.  These will be named board_name, board_rev.
> >+
> >+if SPL_ENV_SUPPORT
> >+config SPL_ENV_IS_NOWHERE
> >+	bool "SPL Environment is not stored"
> >+	default y if ENV_IS_NOWHERE
> >+	help
> >+	  Similar to ENV_IS_NOWHERE, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_MMC
> >+	bool "SPL Environment in an MMC device"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_MMC
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_MMC, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_FAT
> >+	bool "SPL Environment is in a FAT filesystem"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_FAT
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_FAT, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_EXT4
> >+	bool "SPL Environment is in a EXT4 filesystem"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_EXT4
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_EXT4, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_NAND
> >+	bool "SPL Environment in a NAND device"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_NAND
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_NAND, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_SPI_FLASH
> >+	bool "SPL Environment is in SPI flash"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_SPI_FLASH
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_SPI_FLASH, used for SPL environment.
> >+
> >+config SPL_ENV_IS_IN_FLASH
> >+	bool "SPL Environment in flash memory"
> >+	depends on !SPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_FLASH
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_FLASH, used for SPL environment.
> >+
> >+endif
> >+
> >+if TPL_ENV_SUPPORT
> >+
> >+config TPL_ENV_IS_NOWHERE
> >+	bool "TPL Environment is not stored"
> >+	default y if ENV_IS_NOWHERE
> >+	help
> >+	  Similar to ENV_IS_NOWHERE, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_MMC
> >+	bool "TPL Environment in an MMC device"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_MMC
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_MMC, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_FAT
> >+	bool "TPL Environment is in a FAT filesystem"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_FAT
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_FAT, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_EXT4
> >+	bool "TPL Environment is in a EXT4 filesystem"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_EXT4
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_EXT4, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_NAND
> >+	bool "TPL Environment in a NAND device"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_NAND
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_NAND, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_SPI_FLASH
> >+	bool "TPL Environment is in SPI flash"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_SPI_FLASH
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_SPI_FLASH, used for TPL environment.
> >+
> >+config TPL_ENV_IS_IN_FLASH
> >+	bool "TPL Environment in flash memory"
> >+	depends on !TPL_ENV_IS_NOWHERE
> >+	select ENV_DRV_FLASH
> >+	default y
> >+	help
> >+	  Similar to ENV_IS_IN_FLASH, used for TPL environment.
> >+
> >+endif
> >diff --git a/env/Makefile b/env/Makefile
> >index ee37cc822024..0168eb47f00d 100644
> >--- a/env/Makefile
> >+++ b/env/Makefile
> >@@ -3,7 +3,7 @@
> >  # (C) Copyright 2004-2006
> >  # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
> >
> >-obj-y += common.o env.o
> >+obj-y += common.o env.o env_ctx_uboot.o
> >
> >  ifndef CONFIG_SPL_BUILD
> >  obj-y += attr.o
> >diff --git a/env/env_ctx_uboot.c b/env/env_ctx_uboot.c
> >new file mode 100644
> >index 000000000000..5ca645599347
> >--- /dev/null
> >+++ b/env/env_ctx_uboot.c
> >@@ -0,0 +1,292 @@
> >+// SPDX-License-Identifier: GPL-2.0+
> >+/*
> >+ * Copyright (C) 2019 Linaro Limited
> >+ *		Author: AKASHI Takahiro
> >+ */
> >+
> >+#include <common.h>
> >+#include <env_default.h>
> >+#include <env_flags.h>
> >+#include <env_internal.h>
> >+#include <search.h>
> >+
> >+DECLARE_GLOBAL_DATA_PTR;
> >+
> >+#if !defined(ENV_IS_IN_DEVICE) && !defined(CONFIG_ENV_IS_NOWHERE)
> >+# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
> >+NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
> >+#endif
> >+
> >+struct hsearch_data env_htab = {
> >+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> >+	/* defined in flags.c, only compile with ENV_SUPPORT */
> >+	.change_ok = env_flags_validate,
> >+#endif
> >+};
> >+
> >+/*
> >+ * NOTE: extracted from env/env.c
> >+ */
> >+static bool env_has_inited_uboot(struct env_context *ctx,
> >+				 enum env_location location)
> >+{
> >+	return gd->env_has_init & BIT(location);
> >+}
> >+
> >+static void env_set_inited_uboot(struct env_context *ctx,
> >+				 enum env_location location)
> >+{
> >+	gd->env_has_init |= BIT(location);
> >+}
> >+
> >+static int env_get_load_prio_uboot(struct env_context *ctx)
> >+{
> >+	return gd->env_load_prio;
> >+}
> >+
> >+static enum env_location env_get_location_uboot(struct env_context *ctx,
> >+						enum env_operation op, int prio)
> >+{
> >+	gd->env_load_prio = prio;
> >+
> >+	return env_locations[prio];
> >+}
> >+
> >+int env_get_char_default_uboot(struct env_context *ctx, int index)
> >+{
> >+	return default_environment[index];
> >+}
> >+
> >+int env_get_char_spec_uboot(struct env_context *ctx, int index)
> >+{
> >+	return *(uchar *)(gd->env_addr + index);
> >+}
> >+
> >+static int env_init_uboot(struct env_context *ctx)
> >+{
> >+	struct env_driver *drv;
> >+	int ret = -ENOENT;
> >+	int prio;
> >+
> >+	for (prio = 0; (drv = env_driver_lookup(ctx, ENVOP_INIT, prio));
> >+	     prio++) {
> >+		if (!drv->init || !(ret = drv->init(ctx)))
> >+			gd->env_has_init |= BIT(drv->location);
> >+
> >+		debug("%s: Environment %s init done (ret=%d)\n", __func__,
> >+		      drv->name, ret);
> >+	}
> >+
> >+	if (!prio)
> >+		return -ENODEV;
> >+
> >+	if (ret == -ENOENT) {
> >+		gd->env_addr = (ulong)&default_environment[0];
> >+		gd->env_valid = ENV_VALID;
> >+
> >+		return 0;
> >+	}
> >+
> >+	return ret;
> >+}
> >+
> >+static int env_drv_init_uboot(struct env_context *ctx, enum env_location loc)
> >+{
> >+	__maybe_unused int ret;
> >+
> >+	switch (loc) {
> >+#ifdef CONFIG_ENV_IS_IN_FLASH
> >+	case ENVL_FLASH: {
> >+		env_hdr_t *env_ptr;
> >+		env_hdr_t *flash_addr;
> >+		ulong end_addr;
> >+		env_hdr_t *flash_addr_new;
> >+		ulong end_addr_new;
> >+
> >+#ifdef ENV_IS_EMBEDDED
> >+		env_ptr = &embedded_environment;
> >+#else /* ! ENV_IS_EMBEDDED */
> >+		env_ptr = (env_hdr_t *)CONFIG_ENV_ADDR;
> >+#endif /* ENV_IS_EMBEDDED */
> >+		flash_addr = (env_hdr_t *)CONFIG_ENV_ADDR;
> >+
> >+/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
> >+		end_addr = CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
> >+
> >+#ifdef CONFIG_ENV_ADDR_REDUND
> >+		flash_addr_new = (env_hdr_t *)CONFIG_ENV_ADDR_REDUND;
> >+/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
> >+		end_addr_new = CONFIG_ENV_ADDR_REDUND
> >+					+ CONFIG_ENV_SECT_SIZE - 1;
> >+#else
> >+		flash_addr_new = NULL;
> >+		end_addr_new = 0;
> >+#endif /* CONFIG_ENV_ADDR_REDUND */
> >+
> >+		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
> >+					    flash_addr_new, end_addr_new,
> >+					    (ulong)&default_environment[0]);
> >+		if (ret)
> >+			return -ENOENT;
> >+
> >+		return 0;
> >+		}
> >+#endif
> >+#ifdef CONFIG_ENV_IS_IN_FAT
> >+	case ENVL_FAT: {
> >+		ret = env_fat_init_params(ctx,
> >+					  CONFIG_ENV_FAT_INTERFACE,
> >+					  CONFIG_ENV_FAT_DEVICE_AND_PART,
> >+					  CONFIG_ENV_FAT_FILE);
> >+
> >+		return -ENOENT;
> >+		}
> >+#endif
> >+#ifdef CONFIG_ENV_DRV_NONE
> >+	case ENVL_NOWHERE:
> >+#ifdef CONFIG_ENV_IS_NOWHERE
> >+		gd->env_addr = (ulong)&default_environment[0];
> >+		gd->env_valid = ENV_INVALID;
> >+
> >+		return 0;
> >+#else
> >+		return -ENOENT;
> >+#endif
> >+#endif
> >+	default:
> >+		return -ENOENT;
> >+	}
> >+}
> >+
> >+/*
> >+ * NOTE: extracted from env/common.c
> >+ */
> >+void env_set_ready_uboot(struct env_context *ctx)
> >+{
> >+	gd->flags |= GD_FLG_ENV_READY;
> >+}
> >+
> >+bool env_is_ready_uboot(struct env_context *ctx)
> >+{
> >+	return (gd->flags & GD_FLG_ENV_READY);
> >+}
> >+
> >+void env_set_valid_uboot(struct env_context *ctx, enum env_valid valid)
> >+{
> >+	gd->env_valid = valid;
> >+}
> >+
> >+enum env_valid env_get_valid_uboot(struct env_context *ctx)
> >+{
> >+	return gd->env_valid;
> >+}
> >+
> >+void env_set_addr_uboot(struct env_context *ctx, ulong env_addr)
> >+{
> >+	gd->env_addr = env_addr;
> >+}
> >+
> >+ulong env_get_addr_uboot(struct env_context *ctx)
> >+{
> >+	return gd->env_addr;
> >+}
> >+
> >+/*
> >+ * Look up the variable from the default environment
> >+ */
> >+char *env_get_default_uboot(struct env_context *ctx, const char *name)
> >+{
> >+	char *ret_val;
> >+	unsigned long really_valid = gd->env_valid;
> >+	unsigned long real_gd_flags = gd->flags;
> >+
> >+	/* Pretend that the image is bad. */
> >+	gd->flags &= ~GD_FLG_ENV_READY;
> >+	gd->env_valid = ENV_INVALID;
> >+	ret_val = env_get(ctx, name);
> >+	gd->env_valid = really_valid;
> >+	gd->flags = real_gd_flags;
> >+	return ret_val;
> >+}
> >+
> >+void env_set_default_env_uboot(struct env_context *ctx, const char *s,
> >+			       int flags)
> >+{
> >+	if (sizeof(default_environment) > ctx->env_size) {
> >+		puts("*** Error - default environment is too large\n\n");
> >+		return;
> >+	}
> >+
> >+	if (s) {
> >+		if ((flags & H_INTERACTIVE) == 0)
> >+			printf("*** Warning - %s, using default environment\n\n", s);
> >+		else
> >+			puts(s);
> >+	} else {
> >+		debug("Using default environment\n");
> >+	}
> >+
> >+	env_htab.ctx = ctx;
> >+	if (himport_r(&env_htab, (char *)default_environment,
> >+		      sizeof(default_environment), '\0', flags, 0,
> >+		      0, NULL) == 0)
> >+		pr_err("## Error: Environment import failed: errno = %d\n",
> >+		       errno);
> >+
> >+	gd->flags |= GD_FLG_ENV_READY;
> >+	gd->flags |= GD_FLG_ENV_DEFAULT;
> >+}
> >+
> >+/* [re]set individual variables to their value in the default environment */
> >+int env_set_default_vars_uboot(struct env_context *ctx, int nvars,
> >+			       char * const vars[], int flags)
> >+{
> >+	/*
> >+	 * Special use-case: import from default environment
> >+	 * (and use \0 as a separator)
> >+	 */
> >+	flags |= H_NOCLEAR;
> >+	env_htab.ctx = ctx;
> >+	return himport_r(&env_htab, (const char *)default_environment,
> >+				sizeof(default_environment), '\0',
> >+				flags, 0, nvars, vars);
> >+}
> >+
> >+void env_post_relocate_uboot(struct env_context *ctx)
> >+{
> >+	if (gd->env_valid == ENV_INVALID) {
> >+#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
> >+		/* Environment not changeable */
> >+		env_set_default(ctx, NULL, 0);
> >+#else
> >+		bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
> >+		env_set_default(ctx, "bad CRC", 0);
> >+#endif
> >+	} else {
> >+		env_load(ctx);
> >+	}
> >+}
> >+
> >+U_BOOT_ENV_CONTEXT(uboot) = {
> >+	.name = "uboot",
> >+	.htab = &env_htab,
> >+	.env_size = ENV_SIZE,
> >+	.has_inited = env_has_inited_uboot,
> >+	.set_inited = env_set_inited_uboot,
> >+	.get_load_prio = env_get_load_prio_uboot,
> >+	.get_location = env_get_location_uboot,
> >+	.get_char_default = env_get_char_default_uboot,
> >+	.get_char_spec = env_get_char_spec_uboot,
> >+	.init = env_init_uboot,
> >+	.drv_init = env_drv_init_uboot,
> >+	.get_default = env_get_default_uboot,
> >+	.set_default = env_set_default_env_uboot,
> >+	.set_default_vars = env_set_default_vars_uboot,
> >+	.set_ready = env_set_ready_uboot,
> >+	.is_ready = env_is_ready_uboot,
> >+	.set_valid = env_set_valid_uboot,
> >+	.get_valid = env_get_valid_uboot,
> >+	.set_addr = env_set_addr_uboot,
> >+	.get_addr = env_get_addr_uboot,
> >+	.post_relocate = env_post_relocate_uboot,
> >+};
> >diff --git a/include/env.h b/include/env.h
> >index 203605e5e778..26abae2a5c42 100644
> >--- a/include/env.h
> >+++ b/include/env.h
> >@@ -9,6 +9,7 @@
> >  #ifndef __ENV_H
> >  #define __ENV_H
> >
> >+#include <linker_lists.h>
> >  #include <stdbool.h>
> >  #include <linux/types.h>
> >
> >@@ -63,6 +64,8 @@ enum env_redund_flags {
> >  	ENV_REDUND_ACTIVE = 1,
> >  };
> >
> >+#define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)
> 
> Please, do not call ll_entry_get(,uboot,) multiple times. Just call it
> once during initialization and store the reference in a global variable.
> In this case you do not need the macro.

ll_entry_get() won't hurt anything, but for efficiency I agree.

Thanks,
-Takahiro Akashi

> Best regards
> 
> Heinrich
> 
> >+
> >  /* Accessor functions */
> >  void env_set_ready(struct env_context *ctx);
> >  bool env_is_ready(struct env_context *ctx);
> >
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables
  2019-09-05 19:37   ` Heinrich Schuchardt
@ 2019-09-06  0:54     ` AKASHI Takahiro
  0 siblings, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-09-06  0:54 UTC (permalink / raw)
  To: u-boot

On Thu, Sep 05, 2019 at 09:37:37PM +0200, Heinrich Schuchardt wrote:
> On 9/5/19 10:21 AM, AKASHI Takahiro wrote:
> >We will use two environment contexts for implementing UEFI variables,
> >one (ctx_efi) for non-volatile variables and the other for volatile
> >variables. The latter doesn't have a backing storage.
> >
> >Those two contexts are currently used only in efi_variable.c and
> >can be moved into there if desired. But I let it under env/ for
> >future use elsewhere.
> >
> >In this commit, FAT file system and flash device are only supported
> >devices for backing storages, but extending to other devices will be
> >quite straightforward.
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >---
> >  env/Kconfig       |   1 +
> >  env/Kconfig.efi   | 152 ++++++++++++++++++++++++++++++++++++++++++++++
> >  env/Makefile      |   1 +
> >  env/env_ctx_efi.c | 131 +++++++++++++++++++++++++++++++++++++++
> >  include/env.h     |   3 +
> >  5 files changed, 288 insertions(+)
> >  create mode 100644 env/Kconfig.efi
> >  create mode 100644 env/env_ctx_efi.c
> >
> >diff --git a/env/Kconfig b/env/Kconfig
> >index ae96cf75bbaa..0cd3caa67376 100644
> >--- a/env/Kconfig
> >+++ b/env/Kconfig
> >@@ -47,5 +47,6 @@ config ENV_DRV_UBI
> >  	bool
> >
> >  source "env/Kconfig.uboot"
> >+source "env/Kconfig.efi"
> >
> >  endmenu
> >diff --git a/env/Kconfig.efi b/env/Kconfig.efi
> >new file mode 100644
> >index 000000000000..cd4e78989df6
> >--- /dev/null
> >+++ b/env/Kconfig.efi
> >@@ -0,0 +1,152 @@
> >+if EFI_LOADER
> >+
> >+menu "Configure UEFI context"
> >+
> 
> Essentially the 3 variable below exclude each other.
> 
> Please, use a 'choice' statement. drivers/video/Kconfig has an example.

The same comment as uboot context.

> >+config ENV_EFI_IS_NOWHERE
> >+	bool
> >+	default y if !ENV_EFI_IS_INFLASH && !ENV_EFI_IS_IN_FAT
> >+
> >+config ENV_EFI_IS_IN_FAT
> >+	bool "EFI Environment is in a FAT filesystem"
> >+	select ENV_DRV_FAT
> >+	help
> >+	  Define this if you want to use the FAT file system for
> >+	  the environment.
> >+
> >+config ENV_EFI_IS_IN_FLASH
> >+	bool "EFI Environment in flash memory"
> >+	select ENV_DRV_FLASH
> >+	help
> >+	  Define this if you have a flash device which you want to use
> >+	  for the environment.
> >+
> >+	  a) The environment occupies one whole flash sector, which is
> >+	   "embedded" in the text segment with the U-Boot code. This
> 
> Are we really limited to exactly one sector. Or is this the minimum size?

I have not changed this 'help' text from the original env/Kconfig.
So I don't know whether or not you are right.

> >+	   happens usually with "bottom boot sector" or "top boot
> >+	   sector" type flash chips, which have several smaller
> >+	   sectors at the start or the end. For instance, such a
> >+	   layout can have sector sizes of 8, 2x4, 16, Nx32 kB. In
> >+	   such a case you would place the environment in one of the
> >+	   4 kB sectors - with U-Boot code before and after it. With
> >+	   "top boot sector" type flash chips, you would put the
> >+	   environment in one of the last sectors, leaving a gap
> >+	   between U-Boot and the environment.
> >+
> >+	  CONFIG_ENV_EFI_OFFSET:
> >+
> >+	   Offset of environment data (variable area) to the
> >+	   beginning of flash memory; for instance, with bottom boot
> >+	   type flash chips the second sector can be used: the offset
> >+	   for this sector is given here.
> >+
> >+	   CONFIG_ENV_EFI_OFFSET is used relative to CONFIG_SYS_FLASH_BASE.
> >+
> >+	  CONFIG_ENV_EFI_ADDR:
> >+
> >+	   This is just another way to specify the start address of
> >+	   the flash sector containing the environment (instead of
> >+	   CONFIG_ENV_OFFSET).
> >+
> >+	  CONFIG_ENV_EFI_SECT_SIZE:
> >+
> >+	   Size of the sector containing the environment.
> >+
> >+
> >+	  b) Sometimes flash chips have few, equal sized, BIG sectors.
> >+	   In such a case you don't want to spend a whole sector for
> >+	   the environment.
> >+
> >+	  CONFIG_ENV_EFI_SIZE:
> >+
> >+	   If you use this in combination with CONFIG_ENV_IS_IN_FLASH
> >+	   and CONFIG_ENV_SECT_SIZE, you can specify to use only a part
> >+	   of this flash sector for the environment. This saves
> >+	   memory for the RAM copy of the environment.
> >+
> >+	   It may also save flash memory if you decide to use this
> >+	   when your environment is "embedded" within U-Boot code,
> >+	   since then the remainder of the flash sector could be used
> >+	   for U-Boot code. It should be pointed out that this is
> >+	   STRONGLY DISCOURAGED from a robustness point of view:
> >+	   updating the environment in flash makes it always
> >+	   necessary to erase the WHOLE sector. If something goes
> >+	   wrong before the contents has been restored from a copy in
> >+	   RAM, your target system will be dead.
> >+
> >+	  CONFIG_ENV_EFI_ADDR_REDUND
> >+	  CONFIG_ENV_EFI_SIZE_REDUND
> >+
> >+	   These settings describe a second storage area used to hold
> >+	   a redundant copy of the environment data, so that there is
> >+	   a valid backup copy in case there is a power failure during
> >+	   a "saveenv" operation.
> >+
> >+	  BE CAREFUL! Any changes to the flash layout, and some changes to the
> >+	  source code will make it necessary to adapt <board>/u-boot.lds*
> >+	  accordingly!
> >+
> >+config ENV_EFI_FAT_INTERFACE
> >+	string "Name of the block device for the environment"
> >+	depends on ENV_EFI_IS_IN_FAT
> >+	help
> >+	  Define this to a string that is the name of the block device.
> >+
> >+config ENV_EFI_FAT_DEVICE_AND_PART
> >+	string "Device and partition for where to store the environment in FAT"
> >+	depends on ENV_EFI_IS_IN_FAT
> >+	help
> >+	  Define this to a string to specify the partition of the device.
> >+	  It can be as following:
> >+
> >+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
> >+	       - "D:P": device D partition P. Error occurs if device D has no
> >+	                partition table.
> >+	       - "D:0": device D.
> >+	       - "D" or "D:": device D partition 1 if device D has partition
> >+	                      table, or the whole device D if has no partition
> >+	                      table.
> >+	       - "D:auto": first partition in device D with bootable flag set.
> >+	                   If none, first valid partition in device D. If no
> >+	                   partition table then means device D.
> >+
> >+config ENV_EFI_FAT_FILE
> >+	string "Name of the FAT file to use for the environment"
> >+	depends on ENV_EFI_IS_IN_FAT
> >+	default "uboot_efi.env"
> >+	help
> >+	  It's a string of the FAT file name. This file use to store the
> >+	  environment.
> >+
> >+config ENV_EFI_ADDR
> 
> 'depends on' is missing for this variable and all below.

Okay.

> >+	hex "EFI Environment Address"
> >+	help
> >+	  Start address of the device (or partition)
> >+
> >+config ENV_EFI_OFFSET
> >+	hex "EFI Environment Offset"
> >+	help
> >+	  Offset from the start of the device (or partition)
> >+
> >+config ENV_EFI_SIZE
> >+	hex "EFI Environment Size"
> >+	help
> >+	  Size of the environment storage area
> >+
> >+config ENV_EFI_SECT_SIZE
> >+	hex "EFI Environment Sector-Size"
> >+	help
> >+	  Size of the sector containing the environment.
> >+
> >+config ENV_EFI_ADDR_REDUND
> >+	hex "EFI Environment Address for second area"
> >+	help
> >+	  Start address of the device (or partition)
> >+
> >+config ENV_EFI_SIZE_REDUND
> >+	hex "EFI Environment Size for second area"
> >+	help
> >+	  Size of the environment second storage area
> >+
> >+endmenu
> >+
> >+endif
> >diff --git a/env/Makefile b/env/Makefile
> >index 0168eb47f00d..b6690c73b17f 100644
> >--- a/env/Makefile
> >+++ b/env/Makefile
> >@@ -4,6 +4,7 @@
> >  # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
> >
> >  obj-y += common.o env.o env_ctx_uboot.o
> >+obj-$(CONFIG_EFI_LOADER) += env_ctx_efi.o
> >
> >  ifndef CONFIG_SPL_BUILD
> >  obj-y += attr.o
> >diff --git a/env/env_ctx_efi.c b/env/env_ctx_efi.c
> >new file mode 100644
> >index 000000000000..9b5b2f392179
> >--- /dev/null
> >+++ b/env/env_ctx_efi.c
> >@@ -0,0 +1,131 @@
> >+// SPDX-License-Identifier: GPL-2.0+
> >+/*
> >+ * Copyright (C) 2019 Linaro Limited
> >+ *		Author: AKASHI Takahiro
> >+ */
> >+
> >+#include <common.h>
> >+#include <env_flags.h>
> >+#include <env_internal.h>
> >+#include <search.h>
> >+
> >+DECLARE_GLOBAL_DATA_PTR;
> >+
> >+struct hsearch_data efi_htab = {
> >+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> >+	/* defined in flags.c, only compile with ENV_SUPPORT */
> >+	.change_ok = env_flags_validate,
> >+#endif
> >+};
> >+
> >+struct hsearch_data efi_volatile_htab = {
> >+#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> >+	/* defined in flags.c, only compile with ENV_SUPPORT */
> >+	.change_ok = env_flags_validate,
> >+#endif
> >+};
> >+
> >+static int env_drv_init_efi(struct env_context *ctx, enum env_location loc)
> >+{
> >+	__maybe_unused int ret;
> >+
> >+	switch (loc) {
> >+#ifdef CONFIG_ENV_EFI_IS_IN_FLASH
> >+	case ENVL_FLASH: {
> >+		env_t *env_ptr;
> >+		env_t *flash_addr;
> >+		ulong end_addr;
> >+		env_t *flash_addr_new;
> >+		ulong end_addr_new;
> >+
> >+#if defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(CMD_SAVEENV) || \
> >+	!defined(CONFIG_ENV_EFI_ADDR_REDUND) && defined(INITENV)
> >+#ifdef ENV_IS_EMBEDDED
> >+		/* FIXME: not allowed */
> 
> Is something wrong in Kconfig that an non-allowed situation can occur?
> 
> >+		env_ptr = NULL;
> >+#else /* ! ENV_IS_EMBEDDED */
> >+
> >+		env_ptr = (env_t *)CONFIG_ENV_EFI_ADDR;
> >+#endif /* ENV_IS_EMBEDDED */
> >+#else
> >+		env_ptr = NULL;
> >+#endif
> >+		flash_addr = (env_t *)CONFIG_ENV_EFI_ADDR;
> >+
> >+/* CONFIG_ENV_EFI_ADDR is supposed to be on sector boundary */
> >+		end_addr = CONFIG_ENV_EFI_ADDR + CONFIG_ENV_EFI_SECT_SIZE - 1;
> >+
> >+#ifdef CONFIG_ENV_EFI_ADDR_REDUND
> >+		flash_addr_new = (env_t *)CONFIG_ENV_EFI_ADDR_REDUND;
> >+/* CONFIG_ENV_EFI_ADDR_REDUND is supposed to be on sector boundary */
> >+		end_addr_new = CONFIG_ENV_EFI_ADDR_REDUND
> >+					+ CONFIG_ENV_EFI_SECT_SIZE - 1;
> >+#else
> >+		flash_addr_new = NULL;
> >+		end_addr_new = 0;
> >+#endif /* CONFIG_ENV_EFI_ADDR_REDUND */
> >+
> >+		ret = env_flash_init_params(ctx, env_ptr, flash_addr, end_addr,
> >+					    flash_addr_new, end_addr_new,
> >+					    NULL);
> 
> The code above needs some comments.
> 
> If one area is the old one and the other the new one, how do you toggle
> between the two?

Again, I just mimicked the original init code in env/flash.c.
AFAIK, this is not old-or-new stuff, but *redundant* or
original-and-copy storages for robustness.
The logic exists in env/flash.c.

> >+		if (ret)
> >+			return -ENOENT;
> >+
> >+		return 0;
> >+		}
> >+#endif
> >+#ifdef CONFIG_ENV_EFI_IS_IN_FAT
> >+	case ENVL_FAT: {
> >+		ret = env_fat_init_params(ctx,
> >+					  CONFIG_ENV_EFI_FAT_INTERFACE,
> >+					  CONFIG_ENV_EFI_FAT_DEVICE_AND_PART,
> >+					  CONFIG_ENV_EFI_FAT_FILE);
> >+
> >+		return 0;
> >+		}
> >+#endif
> >+#ifdef CONFIG_ENV_DRV_NONE
> >+	case ENVL_NOWHERE:
> >+#ifdef CONFIG_ENV_EFI_IS_NOWHERE
> >+		/* TODO: what we should do */
> >+
> >+		return -ENOENT;
> >+#else
> >+		return -ENOENT;
> >+#endif
> >+#endif
> >+	default:
> >+		return -ENOENT;
> >+	}
> >+}
> >+
> >+/*
> >+ * Env context for UEFI variables
> >+ */
> >+U_BOOT_ENV_CONTEXT(efi) = {
> >+	.name = "efi",
> >+	.htab = &efi_htab,
> >+	.env_size = 0x10000, /* TODO: make this configurable */
> >+	.drv_init = env_drv_init_efi,
> >+};
> 
> From the name of this context it is unclear that this is for the
> non-volatile variables. Please, adjust the comment.

Okay.

> >+
> >+static int env_ctx_init_efi_volatile(struct env_context *ctx)
> >+{
> >+	/* Dummy table creation, or hcreate_r()? */
> >+	if (!himport_r(ctx->htab, NULL, 0, 0, 0, 0, 0, NULL)) {
> >+		debug("%s: Creating entry tables failed (ret=%d)\n", __func__,
> >+		      errno);
> >+		return errno;
> >+	}
> >+
> >+	env_set_ready(ctx);
> >+
> >+	return 0;
> >+}
> >+
> >+U_BOOT_ENV_CONTEXT(efi_volatile) = {
> >+	.name = "efi_volatile",
> >+	.htab = &efi_volatile_htab,
> >+	.env_size = 0,
> >+	.init = env_ctx_init_efi_volatile,
> >+};
> >diff --git a/include/env.h b/include/env.h
> >index 8045dda9f811..ec241d419a8a 100644
> >--- a/include/env.h
> >+++ b/include/env.h
> >@@ -66,6 +66,9 @@ enum env_redund_flags {
> >  };
> >
> >  #define ctx_uboot ll_entry_get(struct env_context, uboot, env_contexts)
> >+#define ctx_efi ll_entry_get(struct env_context, efi, env_contexts)
> >+#define ctx_efi_volatile ll_entry_get(struct env_context, efi_volatile, \
> >+				      env_contexts)
> 
> I do not like that ll_entry_get() is called again and again in patch
> 19/19. Please, call ll_entry_get() once for each context and store the
> reference in a static variable. Than you do not need any of these 3 defines.

Okay.

Thank you for your review,
-Takahiro Akashi

> Best regards
> 
> Heinrich
> 
> >
> >  /* Accessor functions */
> >  void env_set_ready(struct env_context *ctx);
> >
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
                   ` (19 preceding siblings ...)
  2019-09-05  8:31 ` [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
@ 2019-10-01  6:28 ` AKASHI Takahiro
  2019-10-23  6:53   ` AKASHI Takahiro
  20 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-10-01  6:28 UTC (permalink / raw)
  To: u-boot

Wolfgang,

I haven't seen any comments from you in the last one month.
Could you please take time to review this patch? I'd like to
confirm whether you can agree to my approach here or not
in order to take the next step.

Thanks,
-Takahiro Akashi

On Thu, Sep 05, 2019 at 05:21:14PM +0900, AKASHI Takahiro wrote:
> # In version 5 of this patch set, the implementation is changed again.
> #
> # I believe that this is NOT intrusive, and that my approach here is NOT
> # selfish at all. If Wolfgang doesn't accept this approach, however,
> # I would like to go for "Plan B" for UEFI variables implementation, in
> # which EFI will have its own drivers for storage instead of env/*.
> 
> This patch set is an attempt to implement non-volatile attribute for
> UEFI variables. Under the current implementation,
> * SetVariable API doesn't recognize non-volatile attribute
> * While some variables are defined non-volatile in UEFI specification,
>   they are NOT marked as non-volatile in the code.
> * env_save() (or "env save" command) allows us to save all the variables
>   into persistent storage, but it may cause volatile UEFI variables,
>   along with irrelevant U-Boot variables, to be saved unconditionally.
> 
> Those observation rationalizes that the implementation of UEFI variables
> should be revamped utilizing dedicated storage for them.
> 
> 
> Basic ideas:
> * Sub-system users of U-Boot environment variables may have their own
>   "env contexts". More than one contexts allowed.
> 
>   See Patch#2 and Patch#18.
> 
> * Each context is isolated from other contexts with different name spaces.
> * Each context is associated with one backing storage driver and media
>   location.
> * Different contexts may use different drivers and locations.
> 
> * To access (get or set) a variable, associated context must be presented.
>   So, almost of all existing env interfaces are changed to accept one
>   extra argument, ctx.
>   (I believe that this is Wolfgang's *requirement*.)
> 
>   From viewpoint of APIs, env context is a pointer to opaque structure.
> 
> * Non-volatile feature is not implemented in a general form and must be
>   implemented by users in their sub-systems.
> 
>   In version 4, U-Boot environment's attributes are extended to support
>   non-volatile (or auto-save capability), but Wolfgang rejected
>   my approach.
>   As modifying attributes for this purpose would cause bunch of
>   incompatibility issues (as far as I said in my cover letter and
>   the discussions in ML), I would prefer a much simple approach.
> 
>   See patch#19 about how it is easily implemented for UEFI variables.
> 
> * Each backing storage driver must be converted to be aligned with
>   new env interfaces to handle multiple contexts in parallel and
>   provide context-specific Kconfig configurations for driver parameters.
> 
>   In this version, only FAT file system and flash devices are supported,
>   but it is quite straightforward to modify other drivers.
> 
>   See Patch#4 and Patch#5 about how drivers can shift to new interfaces.
> 
> * Finally, all existing U-Boot variables hold the same semantics
>   as before.
> 
> 
> Known issues/restriction/TODO:
> * The current form of patchset is not 'bisect'able.
>   Not to break 'bisect,' all the patches in this patch set must be
>   put into a single commit when merging.
>   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> 
> * Unfortunately, this code fails to read U-Boot environment from flash
>   at boot time due to incomprehensible memory corruption.
>   See murky workaround, which is marked as FIXME, in env/flash.c.
> 
>   Despite this bug, I was still be able to run/test my patch by hacking
>   the code with gdb.
>   (modifying data to correct value on the fly :)
>   I hope that it won't affect code review in most places for now.
> 
> * Some minor issues for better coding.
>   They are also marked as FIXME in the source code.
> 
> * Only FAT file system and flash are supported.
> 
> * The whole area of storage will be saved at *every* update of
>   one UEFI variable. It should be optimized if possible.
> 
> * An error during "save" operation may cause inconsistency between
>   cache (hash table) and the storage.
>     -> This is not UEFI specific though.
> 
> * Add tests if necessary.
> 
> * I cannot test all the platforms affected by this patchset.
> 
> 
> Note:
> If we need "secure storage" for UEFI variables, efi_get_variable/
> efi_get_next_variable_name/efi_set_variable() should be completely
> replaced with stub functions to communicate with secure world.
> This patchset has nothing to do with such an implementation.
> 
> 
> Usage:
> To enable this feature for example with FAT file system, the following
> configs must be enabled:
>   CONFIG_ENV_IS_IN_FAT
>   CONFIG_ENV_FAT_INTERFACE
>   CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
>   CONFIG_ENV_EFI_FAT_FILE
> 
> You may define a non-volatile variable from command interface:
> => setenv -e -nv FOO baa
> => printenv -e FOO
> FOO: NV|BS|RT, DataSize = 0x3
>     00000000: 62 61 61                                         baa
> 
> 
> Patch#1 and #2 are to add multiples 'context' support to env interfaces
>   and to provide new env interfaces.
> Patch#3 to #5 are to show how the existing drivers for U-Boot environment
>   should be modified to be aligned with new env interfaces.
>   (Only FAT file system and flash in this version of patch set.)
> Patch#6 to #17 are to shift all the existing users of old env interfaces
>   to new ones. (But not tested for all the platforms.)
> Patch#18 and #19 are to modify UEFI variable implementation to utilize
>   new env interfaces.
> 
> Changes in v5 (September 4, 2019)
> * rebased to v2019.10-rc3
> * revamp the implementation, removing changes on environment variable's
>   attributes (See above)
> 
> Changes in v4 (July 17, 2019)
> * remove already-merged patches
> * revamp after Wolfgang's suggestion
> 
> Changes in v3 (June 4, 2019)
> * remove already-merged patches
> * revamp the code again
> * introduce CONFIG_EFI_VARIABLE_USE_ENV for this configuration.
>   Once another backing storage, i.e. StMM services for secure boot,
>   is supported, another option will be added.
> 
> Changes in v2 (Apr 24, 2019)
> * rebased on efi-2019-07
> * revamp the implementation
> 
> v1 (Nov 28, 2018)
> * initial
> 
> AKASHI Takahiro (19):
>   env: extend interfaces allowing for env contexts
>   env: define env context for U-Boot environment
>   env: nowhere: rework with new env interfaces
>   env: flash: support multiple env contexts
>   env: fat: support multiple env contexts
>   hashtable: support multiple env contexts
>   api: converted with new env interfaces
>   arch: converted with new env interfaces
>   board: converted with new env interfaces
>   cmd: converted with new env interfaces
>   common: converted with new env interfaces
>   disk: converted with new env interfaces
>   drivers: converted with new env interfaces
>   fs: converted with new env interfaces
>   lib: converted with new env interfaces (except efi_loader)
>   net: converted with new env interfaces
>   post: converted with new env interfaces
>   env,efi_loader: define env context for UEFI variables
>   efi_loader: variable: rework with new env interfaces
> 
>  api/api.c                                     |   8 +-
>  arch/arc/lib/bootm.c                          |   2 +-
>  arch/arm/cpu/arm926ejs/spear/spr_misc.c       |   8 +-
>  arch/arm/cpu/armv8/fsl-layerscape/cpu.c       |   5 +-
>  arch/arm/cpu/armv8/fsl-layerscape/soc.c       |  14 +-
>  arch/arm/lib/bootm.c                          |   6 +-
>  arch/arm/lib/semihosting.c                    |   2 +-
>  arch/arm/mach-imx/mx6/opos6ul.c               |   4 +-
>  arch/arm/mach-imx/mx7/soc.c                   |   4 +-
>  arch/arm/mach-imx/video.c                     |   2 +-
>  arch/arm/mach-keystone/ddr3.c                 |   2 +-
>  arch/arm/mach-keystone/keystone.c             |   2 +-
>  arch/arm/mach-kirkwood/cpu.c                  |   4 +-
>  arch/arm/mach-meson/board-common.c            |   2 +-
>  arch/arm/mach-omap2/utils.c                   |  20 +-
>  arch/arm/mach-rmobile/cpu_info.c              |   2 +-
>  arch/arm/mach-rockchip/boot_mode.c            |   4 +-
>  arch/arm/mach-rockchip/rk3288/rk3288.c        |   2 +-
>  arch/arm/mach-socfpga/misc_gen5.c             |   5 +-
>  arch/arm/mach-socfpga/misc_s10.c              |   2 +-
>  arch/arm/mach-stm32mp/cpu.c                   |  35 +-
>  arch/arm/mach-tegra/board2.c                  |   4 +-
>  arch/arm/mach-tegra/cboot.c                   |  18 +-
>  arch/arm/mach-uniphier/board_late_init.c      |  19 +-
>  arch/arm/mach-uniphier/mmc-first-dev.c        |   2 +-
>  arch/m68k/lib/bootm.c                         |   2 +-
>  arch/microblaze/lib/bootm.c                   |   2 +-
>  arch/mips/lib/bootm.c                         |   6 +-
>  arch/nds32/lib/bootm.c                        |   4 +-
>  arch/powerpc/cpu/mpc85xx/cpu_init.c           |  10 +-
>  arch/powerpc/cpu/mpc85xx/fdt.c                |   2 +-
>  arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |   2 +-
>  arch/powerpc/lib/bootm.c                      |   2 +-
>  arch/sh/lib/bootm.c                           |   2 +-
>  arch/sh/lib/zimageboot.c                      |   2 +-
>  arch/x86/lib/zimage.c                         |  11 +-
>  arch/xtensa/lib/bootm.c                       |   2 +-
>  board/Arcturus/ucp1020/cmd_arc.c              |  40 +-
>  board/Arcturus/ucp1020/ucp1020.c              |  16 +-
>  board/BuR/brppt1/board.c                      |   4 +-
>  board/BuR/brxre1/board.c                      |   9 +-
>  board/BuR/common/br_resetc.c                  |   2 +-
>  board/BuR/common/common.c                     |  47 +-
>  board/BuS/eb_cpu5282/eb_cpu5282.c             |   8 +-
>  board/CZ.NIC/turris_mox/turris_mox.c          |   4 +-
>  board/CZ.NIC/turris_omnia/turris_omnia.c      |   6 +-
>  board/CarMediaLab/flea3/flea3.c               |   2 +-
>  board/LaCie/net2big_v2/net2big_v2.c           |   2 +-
>  board/LaCie/netspace_v2/netspace_v2.c         |   2 +-
>  board/Synology/ds414/cmd_syno.c               |   6 +-
>  board/alliedtelesis/x530/x530.c               |   2 +-
>  board/amazon/kc1/kc1.c                        |   4 +-
>  board/amlogic/p200/p200.c                     |   4 +-
>  board/amlogic/p201/p201.c                     |   4 +-
>  board/amlogic/p212/p212.c                     |   4 +-
>  board/amlogic/q200/q200.c                     |   4 +-
>  board/aristainetos/aristainetos-v2.c          |   8 +-
>  board/armltd/integrator/integrator.c          |   2 +-
>  board/atmel/common/board.c                    |   4 +-
>  board/atmel/common/mac_eeprom.c               |   2 +-
>  board/atmel/sama5d3xek/sama5d3xek.c           |   2 +-
>  board/bachmann/ot1200/ot1200.c                |   4 +-
>  board/birdland/bav335x/board.c                |   8 +-
>  board/bluegiga/apx4devkit/apx4devkit.c        |   5 +-
>  board/bluewater/gurnard/gurnard.c             |   6 +-
>  board/bosch/shc/board.c                       |   2 +-
>  board/boundary/nitrogen6x/nitrogen6x.c        |  14 +-
>  board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |   2 +-
>  board/broadcom/bcm28155_ap/bcm28155_ap.c      |   2 +-
>  board/broadcom/bcmstb/bcmstb.c                |   2 +-
>  board/buffalo/lsxl/lsxl.c                     |   2 +-
>  board/cadence/xtfpga/xtfpga.c                 |   4 +-
>  board/ccv/xpress/xpress.c                     |   2 +-
>  board/compulab/cl-som-imx7/cl-som-imx7.c      |   2 +-
>  board/compulab/cm_fx6/cm_fx6.c                |  10 +-
>  board/compulab/common/omap3_display.c         |   4 +-
>  board/congatec/cgtqmx6eval/cgtqmx6eval.c      |   8 +-
>  board/cssi/MCR3000/MCR3000.c                  |   2 +-
>  board/davinci/da8xxevm/da850evm.c             |   2 +-
>  board/davinci/da8xxevm/omapl138_lcdk.c        |   6 +-
>  board/dhelectronics/dh_imx6/dh_imx6.c         |   2 +-
>  board/eets/pdu001/board.c                     |   8 +-
>  board/el/el6x/el6x.c                          |   2 +-
>  board/emulation/qemu-riscv/qemu-riscv.c       |   2 +-
>  board/engicam/common/board.c                  |  32 +-
>  board/esd/meesc/meesc.c                       |   6 +-
>  board/freescale/b4860qds/b4860qds.c           |   5 +-
>  board/freescale/common/cmd_esbc_validate.c    |   2 +-
>  board/freescale/common/fsl_chain_of_trust.c   |   6 +-
>  board/freescale/common/sys_eeprom.c           |   4 +-
>  board/freescale/common/vid.c                  |   4 +-
>  board/freescale/imx8mq_evk/imx8mq_evk.c       |   4 +-
>  board/freescale/imx8qm_mek/imx8qm_mek.c       |   4 +-
>  board/freescale/imx8qxp_mek/imx8qxp_mek.c     |   4 +-
>  board/freescale/ls1088a/eth_ls1088aqds.c      |   4 +-
>  board/freescale/ls1088a/ls1088a.c             |   2 +-
>  board/freescale/ls2080aqds/eth.c              |   6 +-
>  board/freescale/ls2080aqds/ls2080aqds.c       |   2 +-
>  board/freescale/ls2080ardb/ls2080ardb.c       |   6 +-
>  board/freescale/lx2160a/eth_lx2160aqds.c      |   2 +-
>  board/freescale/mpc8323erdb/mpc8323erdb.c     |   3 +-
>  board/freescale/mpc837xemds/pci.c             |   2 +-
>  board/freescale/mpc837xerdb/mpc837xerdb.c     |   2 +-
>  board/freescale/mx51evk/mx51evk_video.c       |   2 +-
>  board/freescale/mx53loco/mx53loco.c           |   4 +-
>  board/freescale/mx53loco/mx53loco_video.c     |   2 +-
>  board/freescale/mx6sabreauto/mx6sabreauto.c   |   8 +-
>  board/freescale/mx6sabresd/mx6sabresd.c       |   8 +-
>  board/freescale/mx6sxsabresd/mx6sxsabresd.c   |   2 +-
>  .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |   6 +-
>  board/freescale/mx6ullevk/mx6ullevk.c         |   4 +-
>  board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |   2 +-
>  board/freescale/qemu-ppce500/qemu-ppce500.c   |   4 +-
>  board/freescale/t4qds/t4240qds.c              |   2 +-
>  board/gardena/smart-gateway-at91sam/board.c   |   2 +-
>  board/gardena/smart-gateway-mt7688/board.c    |  16 +-
>  board/gateworks/gw_ventana/common.c           |   2 +-
>  board/gateworks/gw_ventana/gw_ventana.c       |  61 +-
>  board/gateworks/gw_ventana/gw_ventana_spl.c   |   4 +-
>  board/gdsys/a38x/keyprogram.c                 |   4 +-
>  board/gdsys/mpc8308/gazerbeam.c               |   4 +-
>  board/gdsys/mpc8308/hrcon.c                   |   2 +-
>  board/gdsys/mpc8308/strider.c                 |   2 +-
>  board/gdsys/p1022/controlcenterd-id.c         |  10 +-
>  board/gdsys/p1022/controlcenterd.c            |   2 +-
>  board/ge/bx50v3/bx50v3.c                      |  13 +-
>  board/ge/common/ge_common.c                   |   4 +-
>  board/ge/mx53ppd/mx53ppd.c                    |   2 +-
>  board/grinn/chiliboard/board.c                |   4 +-
>  board/grinn/liteboard/board.c                 |   6 +-
>  board/highbank/highbank.c                     |   9 +-
>  board/hisilicon/poplar/poplar.c               |   2 +-
>  board/imgtec/ci20/ci20.c                      |   6 +-
>  board/intel/edison/edison.c                   |  14 +-
>  board/isee/igep003x/board.c                   |   6 +-
>  board/isee/igep00x0/igep00x0.c                |   4 +-
>  board/k+p/kp_imx53/kp_id_rev.c                |  20 +-
>  board/k+p/kp_imx53/kp_imx53.c                 |   4 +-
>  board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |   4 +-
>  board/keymile/common/common.c                 |  26 +-
>  board/keymile/common/ivm.c                    |   8 +-
>  board/keymile/km83xx/km83xx.c                 |   2 +-
>  board/keymile/km_arm/km_arm.c                 |   6 +-
>  board/keymile/kmp204x/kmp204x.c               |   4 +-
>  board/kosagi/novena/novena.c                  |   2 +-
>  board/laird/wb50n/wb50n.c                     |   2 +-
>  board/lg/sniper/sniper.c                      |   4 +-
>  board/liebherr/display5/spl.c                 |   4 +-
>  board/liebherr/mccmon6/mccmon6.c              |   6 +-
>  board/logicpd/imx6/imx6logic.c                |   8 +-
>  board/menlo/m53menlo/m53menlo.c               |   2 +-
>  board/micronas/vct/vct.c                      |   2 +-
>  board/nokia/rx51/rx51.c                       |  10 +-
>  board/overo/overo.c                           |  45 +-
>  board/phytec/pcm052/pcm052.c                  |   4 +-
>  board/phytec/pfla02/pfla02.c                  |   2 +-
>  .../dragonboard410c/dragonboard410c.c         |   6 +-
>  .../dragonboard820c/dragonboard820c.c         |   2 +-
>  board/raspberrypi/rpi/rpi.c                   |  26 +-
>  board/renesas/alt/alt.c                       |   3 +-
>  board/renesas/gose/gose.c                     |   3 +-
>  board/renesas/koelsch/koelsch.c               |   3 +-
>  board/renesas/lager/lager.c                   |   3 +-
>  board/renesas/porter/porter.c                 |   3 +-
>  board/renesas/sh7752evb/sh7752evb.c           |   4 +-
>  board/renesas/sh7753evb/sh7753evb.c           |   4 +-
>  board/renesas/sh7757lcr/sh7757lcr.c           |   6 +-
>  board/renesas/silk/silk.c                     |   3 +-
>  board/renesas/stout/stout.c                   |   3 +-
>  board/rockchip/kylin_rk3036/kylin_rk3036.c    |   2 +-
>  board/samsung/common/exynos5-dt.c             |   2 +-
>  board/samsung/common/misc.c                   |  14 +-
>  board/samsung/odroid/odroid.c                 |   2 +-
>  board/samsung/trats/trats.c                   |   2 +-
>  board/samsung/universal_c210/universal.c      |   2 +-
>  board/samtec/vining_fpga/socfpga.c            |  16 +-
>  board/siemens/common/board.c                  |   4 +-
>  board/siemens/draco/board.c                   |   6 +-
>  board/siemens/pxm2/board.c                    |   4 +-
>  board/siemens/rut/board.c                     |   2 +-
>  board/siemens/taurus/taurus.c                 |  50 +-
>  board/socrates/socrates.c                     |   4 +-
>  board/softing/vining_2000/vining_2000.c       |   8 +-
>  board/solidrun/mx6cuboxi/mx6cuboxi.c          |  16 +-
>  .../stm32f429-discovery/stm32f429-discovery.c |   4 +-
>  .../stm32f429-evaluation.c                    |   4 +-
>  .../stm32f469-discovery/stm32f469-discovery.c |   4 +-
>  board/st/stm32mp1/stm32mp1.c                  |  11 +-
>  board/sunxi/board.c                           |  25 +-
>  board/synopsys/hsdk/env-lib.c                 |  11 +-
>  board/synopsys/hsdk/hsdk.c                    |   6 +-
>  board/syteco/zmx25/zmx25.c                    |   8 +-
>  board/tcl/sl50/board.c                        |   6 +-
>  .../puma_rk3399/puma-rk3399.c                 |   8 +-
>  board/ti/am335x/board.c                       |  18 +-
>  board/ti/am43xx/board.c                       |   6 +-
>  board/ti/am57xx/board.c                       |  14 +-
>  board/ti/beagle/beagle.c                      |  43 +-
>  board/ti/common/board_detect.c                |  14 +-
>  board/ti/dra7xx/evm.c                         |  12 +-
>  board/ti/evm/evm.c                            |   2 +-
>  board/ti/ks2_evm/board.c                      |  10 +-
>  board/ti/ks2_evm/board_k2g.c                  |   8 +-
>  board/ti/panda/panda.c                        |   4 +-
>  board/toradex/apalis-imx8/apalis-imx8.c       |   4 +-
>  board/toradex/apalis_imx6/apalis_imx6.c       |  12 +-
>  .../toradex/colibri-imx6ull/colibri-imx6ull.c |   6 +-
>  board/toradex/colibri-imx8x/colibri-imx8x.c   |   4 +-
>  board/toradex/colibri_imx6/colibri_imx6.c     |   8 +-
>  board/toradex/colibri_vf/colibri_vf.c         |   2 +-
>  board/toradex/common/tdx-cfg-block.c          |   2 +-
>  board/toradex/common/tdx-common.c             |   2 +-
>  board/tqc/tqma6/tqma6.c                       |   2 +-
>  board/udoo/neo/neo.c                          |   2 +-
>  board/udoo/udoo.c                             |   4 +-
>  board/varisys/common/sys_eeprom.c             |   6 +-
>  board/vscom/baltos/board.c                    |   6 +-
>  board/wandboard/wandboard.c                   |  12 +-
>  board/warp7/warp7.c                           |   6 +-
>  .../work_92105/work_92105_display.c           |   2 +-
>  board/xes/common/board.c                      |   6 +-
>  board/xilinx/zynq/board.c                     |  16 +-
>  board/xilinx/zynqmp/cmds.c                    |   2 +-
>  board/xilinx/zynqmp/zynqmp.c                  |  24 +-
>  cmd/ab_select.c                               |   2 +-
>  cmd/avb.c                                     |   2 +-
>  cmd/bdinfo.c                                  |   6 +-
>  cmd/binop.c                                   |   4 +-
>  cmd/bootefi.c                                 |   8 +-
>  cmd/bootm.c                                   |   4 +-
>  cmd/bootmenu.c                                |   6 +-
>  cmd/cbfs.c                                    |   2 +-
>  cmd/cramfs.c                                  |   8 +-
>  cmd/dtimg.c                                   |   2 +-
>  cmd/elf.c                                     |  29 +-
>  cmd/fdt.c                                     |  22 +-
>  cmd/fpga.c                                    |   4 +-
>  cmd/gpt.c                                     |   8 +-
>  cmd/ini.c                                     |   6 +-
>  cmd/itest.c                                   |   2 +-
>  cmd/jffs2.c                                   |   4 +-
>  cmd/load.c                                    |  10 +-
>  cmd/lzmadec.c                                 |   2 +-
>  cmd/md5sum.c                                  |   4 +-
>  cmd/mtdparts.c                                |  41 +-
>  cmd/mvebu/bubt.c                              |   2 +-
>  cmd/nand.c                                    |  12 +-
>  cmd/net.c                                     |  46 +-
>  cmd/nvedit.c                                  | 394 +++++++---
>  cmd/part.c                                    |   6 +-
>  cmd/pxe.c                                     |  33 +-
>  cmd/qfw.c                                     |   6 +-
>  cmd/reiser.c                                  |   8 +-
>  cmd/setexpr.c                                 |   8 +-
>  cmd/spl.c                                     |   5 +-
>  cmd/ti/ddr3.c                                 |   2 +-
>  cmd/tpm-common.c                              |   2 +-
>  cmd/tpm-v1.c                                  |   2 +-
>  cmd/trace.c                                   |  18 +-
>  cmd/ubi.c                                     |   2 +-
>  cmd/unzip.c                                   |   2 +-
>  cmd/ximg.c                                    |   4 +-
>  cmd/zfs.c                                     |   6 +-
>  cmd/zip.c                                     |   2 +-
>  common/autoboot.c                             |  22 +-
>  common/board_f.c                              |   3 +-
>  common/board_r.c                              |  10 +-
>  common/bootm.c                                |  12 +-
>  common/bootm_os.c                             |  12 +-
>  common/bootretry.c                            |   2 +-
>  common/cli.c                                  |   2 +-
>  common/cli_hush.c                             |  14 +-
>  common/cli_simple.c                           |   2 +-
>  common/command.c                              |   2 +-
>  common/console.c                              |  14 +-
>  common/fdt_support.c                          |   6 +-
>  common/hash.c                                 |   4 +-
>  common/hwconfig.c                             |   5 +-
>  common/image-android.c                        |   4 +-
>  common/image-fdt.c                            |   4 +-
>  common/image.c                                |  15 +-
>  common/main.c                                 |   5 +-
>  common/spl/spl_dfu.c                          |   6 +-
>  common/spl/spl_ext.c                          |   4 +-
>  common/spl/spl_fat.c                          |   4 +-
>  common/spl/spl_net.c                          |   4 +-
>  common/splash.c                               |   4 +-
>  common/splash_source.c                        |   8 +-
>  common/update.c                               |  10 +-
>  common/usb_hub.c                              |   2 +-
>  common/usb_kbd.c                              |   6 +-
>  disk/part.c                                   |   2 +-
>  disk/part_amiga.c                             |   4 +-
>  drivers/bootcount/bootcount_env.c             |  12 +-
>  drivers/ddr/fsl/fsl_ddr_gen4.c                |   2 +-
>  drivers/ddr/fsl/interactive.c                 |   5 +-
>  drivers/ddr/fsl/options.c                     |   4 +-
>  drivers/dfu/dfu.c                             |   6 +-
>  drivers/fastboot/fb_command.c                 |   4 +-
>  drivers/fastboot/fb_common.c                  |   2 +-
>  drivers/fastboot/fb_getvar.c                  |   8 +-
>  drivers/fastboot/fb_mmc.c                     |   2 +-
>  drivers/input/i8042.c                         |   2 +-
>  drivers/input/input.c                         |   2 +-
>  drivers/misc/fs_loader.c                      |   8 +-
>  drivers/mtd/cfi_flash.c                       |   2 +-
>  drivers/mtd/mtd_uboot.c                       |  11 +-
>  drivers/net/fec_mxc.c                         |   2 +-
>  drivers/net/fm/b4860.c                        |   3 +-
>  drivers/net/fm/fdt.c                          |   2 +-
>  drivers/net/fm/fm.c                           |   4 +-
>  drivers/net/fsl-mc/mc.c                       |   7 +-
>  drivers/net/netconsole.c                      |  14 +-
>  drivers/net/phy/micrel_ksz90x1.c              |   4 +-
>  drivers/net/sandbox-raw.c                     |   4 +-
>  drivers/pci/pci.c                             |   4 +-
>  drivers/pci/pci_common.c                      |   2 +-
>  drivers/reset/reset-socfpga.c                 |   2 +-
>  drivers/rtc/m41t60.c                          |   2 +-
>  drivers/scsi/scsi.c                           |   2 +-
>  drivers/serial/usbtty.c                       |   4 +-
>  drivers/usb/gadget/designware_udc.c           |   2 +-
>  drivers/usb/gadget/ether.c                    |  13 +-
>  drivers/usb/gadget/f_dfu.c                    |   2 +-
>  drivers/usb/gadget/f_fastboot.c               |   2 +-
>  drivers/usb/gadget/f_rockusb.c                |   2 +-
>  drivers/usb/gadget/f_sdp.c                    |   2 +-
>  drivers/usb/host/ehci-fsl.c                   |   2 +-
>  drivers/video/ati_radeon_fb.c                 |   2 +-
>  drivers/video/cfb_console.c                   |   2 +-
>  drivers/video/mb862xx.c                       |   2 +-
>  drivers/video/mx3fb.c                         |   2 +-
>  drivers/video/mxsfb.c                         |   2 +-
>  drivers/video/videomodes.c                    |   4 +-
>  env/Kconfig                                   | 683 +-----------------
>  env/Kconfig.efi                               | 152 ++++
>  env/Kconfig.uboot                             | 671 +++++++++++++++++
>  env/Makefile                                  |  33 +-
>  env/callback.c                                |  40 +-
>  env/common.c                                  | 255 ++++---
>  env/env.c                                     | 158 ++--
>  env/env_ctx_efi.c                             | 131 ++++
>  env/env_ctx_uboot.c                           | 292 ++++++++
>  env/fat.c                                     | 102 ++-
>  env/flags.c                                   |  35 +-
>  env/flash.c                                   | 397 ++++++----
>  env/nowhere.c                                 |   7 +-
>  fs/fs.c                                       |  14 +-
>  fs/ubifs/ubifs.c                              |   2 +-
>  include/_exports.h                            |   6 +-
>  include/common.h                              |   6 +-
>  include/env.h                                 | 114 ++-
>  include/env_internal.h                        |  89 ++-
>  include/exports.h                             |   5 +-
>  include/search.h                              |   6 +-
>  lib/efi_loader/efi_console.c                  |   2 +-
>  lib/efi_loader/efi_variable.c                 |  91 ++-
>  lib/fdtdec.c                                  |   2 +-
>  lib/hashtable.c                               |  14 +-
>  lib/smbios.c                                  |   2 +-
>  lib/uuid.c                                    |   2 +-
>  net/bootp.c                                   |  17 +-
>  net/dns.c                                     |   2 +-
>  net/eth-uclass.c                              |   6 +-
>  net/eth_common.c                              |  18 +-
>  net/eth_legacy.c                              |   2 +-
>  net/link_local.c                              |   2 +-
>  net/net.c                                     |  11 +-
>  net/tftp.c                                    |  10 +-
>  net/wol.c                                     |   2 +-
>  post/post.c                                   |   2 +-
>  371 files changed, 3690 insertions(+), 2337 deletions(-)
>  create mode 100644 env/Kconfig.efi
>  create mode 100644 env/Kconfig.uboot
>  create mode 100644 env/env_ctx_efi.c
>  create mode 100644 env/env_ctx_uboot.c
> 
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-01  6:28 ` AKASHI Takahiro
@ 2019-10-23  6:53   ` AKASHI Takahiro
  2019-10-25  7:06     ` Wolfgang Denk
  0 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-10-23  6:53 UTC (permalink / raw)
  To: u-boot

Wolfgang,

This is my second ping.
Could you please take time to review this patch?

-Takahiro Akashi

On Tue, Oct 01, 2019 at 03:28:31PM +0900, AKASHI Takahiro wrote:
> Wolfgang,
> 
> I haven't seen any comments from you in the last one month.
> Could you please take time to review this patch? I'd like to
> confirm whether you can agree to my approach here or not
> in order to take the next step.
> 
> Thanks,
> -Takahiro Akashi
> 
> On Thu, Sep 05, 2019 at 05:21:14PM +0900, AKASHI Takahiro wrote:
> > # In version 5 of this patch set, the implementation is changed again.
> > #
> > # I believe that this is NOT intrusive, and that my approach here is NOT
> > # selfish at all. If Wolfgang doesn't accept this approach, however,
> > # I would like to go for "Plan B" for UEFI variables implementation, in
> > # which EFI will have its own drivers for storage instead of env/*.
> > 
> > This patch set is an attempt to implement non-volatile attribute for
> > UEFI variables. Under the current implementation,
> > * SetVariable API doesn't recognize non-volatile attribute
> > * While some variables are defined non-volatile in UEFI specification,
> >   they are NOT marked as non-volatile in the code.
> > * env_save() (or "env save" command) allows us to save all the variables
> >   into persistent storage, but it may cause volatile UEFI variables,
> >   along with irrelevant U-Boot variables, to be saved unconditionally.
> > 
> > Those observation rationalizes that the implementation of UEFI variables
> > should be revamped utilizing dedicated storage for them.
> > 
> > 
> > Basic ideas:
> > * Sub-system users of U-Boot environment variables may have their own
> >   "env contexts". More than one contexts allowed.
> > 
> >   See Patch#2 and Patch#18.
> > 
> > * Each context is isolated from other contexts with different name spaces.
> > * Each context is associated with one backing storage driver and media
> >   location.
> > * Different contexts may use different drivers and locations.
> > 
> > * To access (get or set) a variable, associated context must be presented.
> >   So, almost of all existing env interfaces are changed to accept one
> >   extra argument, ctx.
> >   (I believe that this is Wolfgang's *requirement*.)
> > 
> >   From viewpoint of APIs, env context is a pointer to opaque structure.
> > 
> > * Non-volatile feature is not implemented in a general form and must be
> >   implemented by users in their sub-systems.
> > 
> >   In version 4, U-Boot environment's attributes are extended to support
> >   non-volatile (or auto-save capability), but Wolfgang rejected
> >   my approach.
> >   As modifying attributes for this purpose would cause bunch of
> >   incompatibility issues (as far as I said in my cover letter and
> >   the discussions in ML), I would prefer a much simple approach.
> > 
> >   See patch#19 about how it is easily implemented for UEFI variables.
> > 
> > * Each backing storage driver must be converted to be aligned with
> >   new env interfaces to handle multiple contexts in parallel and
> >   provide context-specific Kconfig configurations for driver parameters.
> > 
> >   In this version, only FAT file system and flash devices are supported,
> >   but it is quite straightforward to modify other drivers.
> > 
> >   See Patch#4 and Patch#5 about how drivers can shift to new interfaces.
> > 
> > * Finally, all existing U-Boot variables hold the same semantics
> >   as before.
> > 
> > 
> > Known issues/restriction/TODO:
> > * The current form of patchset is not 'bisect'able.
> >   Not to break 'bisect,' all the patches in this patch set must be
> >   put into a single commit when merging.
> >   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> > 
> > * Unfortunately, this code fails to read U-Boot environment from flash
> >   at boot time due to incomprehensible memory corruption.
> >   See murky workaround, which is marked as FIXME, in env/flash.c.
> > 
> >   Despite this bug, I was still be able to run/test my patch by hacking
> >   the code with gdb.
> >   (modifying data to correct value on the fly :)
> >   I hope that it won't affect code review in most places for now.
> > 
> > * Some minor issues for better coding.
> >   They are also marked as FIXME in the source code.
> > 
> > * Only FAT file system and flash are supported.
> > 
> > * The whole area of storage will be saved at *every* update of
> >   one UEFI variable. It should be optimized if possible.
> > 
> > * An error during "save" operation may cause inconsistency between
> >   cache (hash table) and the storage.
> >     -> This is not UEFI specific though.
> > 
> > * Add tests if necessary.
> > 
> > * I cannot test all the platforms affected by this patchset.
> > 
> > 
> > Note:
> > If we need "secure storage" for UEFI variables, efi_get_variable/
> > efi_get_next_variable_name/efi_set_variable() should be completely
> > replaced with stub functions to communicate with secure world.
> > This patchset has nothing to do with such an implementation.
> > 
> > 
> > Usage:
> > To enable this feature for example with FAT file system, the following
> > configs must be enabled:
> >   CONFIG_ENV_IS_IN_FAT
> >   CONFIG_ENV_FAT_INTERFACE
> >   CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
> >   CONFIG_ENV_EFI_FAT_FILE
> > 
> > You may define a non-volatile variable from command interface:
> > => setenv -e -nv FOO baa
> > => printenv -e FOO
> > FOO: NV|BS|RT, DataSize = 0x3
> >     00000000: 62 61 61                                         baa
> > 
> > 
> > Patch#1 and #2 are to add multiples 'context' support to env interfaces
> >   and to provide new env interfaces.
> > Patch#3 to #5 are to show how the existing drivers for U-Boot environment
> >   should be modified to be aligned with new env interfaces.
> >   (Only FAT file system and flash in this version of patch set.)
> > Patch#6 to #17 are to shift all the existing users of old env interfaces
> >   to new ones. (But not tested for all the platforms.)
> > Patch#18 and #19 are to modify UEFI variable implementation to utilize
> >   new env interfaces.
> > 
> > Changes in v5 (September 4, 2019)
> > * rebased to v2019.10-rc3
> > * revamp the implementation, removing changes on environment variable's
> >   attributes (See above)
> > 
> > Changes in v4 (July 17, 2019)
> > * remove already-merged patches
> > * revamp after Wolfgang's suggestion
> > 
> > Changes in v3 (June 4, 2019)
> > * remove already-merged patches
> > * revamp the code again
> > * introduce CONFIG_EFI_VARIABLE_USE_ENV for this configuration.
> >   Once another backing storage, i.e. StMM services for secure boot,
> >   is supported, another option will be added.
> > 
> > Changes in v2 (Apr 24, 2019)
> > * rebased on efi-2019-07
> > * revamp the implementation
> > 
> > v1 (Nov 28, 2018)
> > * initial
> > 
> > AKASHI Takahiro (19):
> >   env: extend interfaces allowing for env contexts
> >   env: define env context for U-Boot environment
> >   env: nowhere: rework with new env interfaces
> >   env: flash: support multiple env contexts
> >   env: fat: support multiple env contexts
> >   hashtable: support multiple env contexts
> >   api: converted with new env interfaces
> >   arch: converted with new env interfaces
> >   board: converted with new env interfaces
> >   cmd: converted with new env interfaces
> >   common: converted with new env interfaces
> >   disk: converted with new env interfaces
> >   drivers: converted with new env interfaces
> >   fs: converted with new env interfaces
> >   lib: converted with new env interfaces (except efi_loader)
> >   net: converted with new env interfaces
> >   post: converted with new env interfaces
> >   env,efi_loader: define env context for UEFI variables
> >   efi_loader: variable: rework with new env interfaces
> > 
> >  api/api.c                                     |   8 +-
> >  arch/arc/lib/bootm.c                          |   2 +-
> >  arch/arm/cpu/arm926ejs/spear/spr_misc.c       |   8 +-
> >  arch/arm/cpu/armv8/fsl-layerscape/cpu.c       |   5 +-
> >  arch/arm/cpu/armv8/fsl-layerscape/soc.c       |  14 +-
> >  arch/arm/lib/bootm.c                          |   6 +-
> >  arch/arm/lib/semihosting.c                    |   2 +-
> >  arch/arm/mach-imx/mx6/opos6ul.c               |   4 +-
> >  arch/arm/mach-imx/mx7/soc.c                   |   4 +-
> >  arch/arm/mach-imx/video.c                     |   2 +-
> >  arch/arm/mach-keystone/ddr3.c                 |   2 +-
> >  arch/arm/mach-keystone/keystone.c             |   2 +-
> >  arch/arm/mach-kirkwood/cpu.c                  |   4 +-
> >  arch/arm/mach-meson/board-common.c            |   2 +-
> >  arch/arm/mach-omap2/utils.c                   |  20 +-
> >  arch/arm/mach-rmobile/cpu_info.c              |   2 +-
> >  arch/arm/mach-rockchip/boot_mode.c            |   4 +-
> >  arch/arm/mach-rockchip/rk3288/rk3288.c        |   2 +-
> >  arch/arm/mach-socfpga/misc_gen5.c             |   5 +-
> >  arch/arm/mach-socfpga/misc_s10.c              |   2 +-
> >  arch/arm/mach-stm32mp/cpu.c                   |  35 +-
> >  arch/arm/mach-tegra/board2.c                  |   4 +-
> >  arch/arm/mach-tegra/cboot.c                   |  18 +-
> >  arch/arm/mach-uniphier/board_late_init.c      |  19 +-
> >  arch/arm/mach-uniphier/mmc-first-dev.c        |   2 +-
> >  arch/m68k/lib/bootm.c                         |   2 +-
> >  arch/microblaze/lib/bootm.c                   |   2 +-
> >  arch/mips/lib/bootm.c                         |   6 +-
> >  arch/nds32/lib/bootm.c                        |   4 +-
> >  arch/powerpc/cpu/mpc85xx/cpu_init.c           |  10 +-
> >  arch/powerpc/cpu/mpc85xx/fdt.c                |   2 +-
> >  arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |   2 +-
> >  arch/powerpc/lib/bootm.c                      |   2 +-
> >  arch/sh/lib/bootm.c                           |   2 +-
> >  arch/sh/lib/zimageboot.c                      |   2 +-
> >  arch/x86/lib/zimage.c                         |  11 +-
> >  arch/xtensa/lib/bootm.c                       |   2 +-
> >  board/Arcturus/ucp1020/cmd_arc.c              |  40 +-
> >  board/Arcturus/ucp1020/ucp1020.c              |  16 +-
> >  board/BuR/brppt1/board.c                      |   4 +-
> >  board/BuR/brxre1/board.c                      |   9 +-
> >  board/BuR/common/br_resetc.c                  |   2 +-
> >  board/BuR/common/common.c                     |  47 +-
> >  board/BuS/eb_cpu5282/eb_cpu5282.c             |   8 +-
> >  board/CZ.NIC/turris_mox/turris_mox.c          |   4 +-
> >  board/CZ.NIC/turris_omnia/turris_omnia.c      |   6 +-
> >  board/CarMediaLab/flea3/flea3.c               |   2 +-
> >  board/LaCie/net2big_v2/net2big_v2.c           |   2 +-
> >  board/LaCie/netspace_v2/netspace_v2.c         |   2 +-
> >  board/Synology/ds414/cmd_syno.c               |   6 +-
> >  board/alliedtelesis/x530/x530.c               |   2 +-
> >  board/amazon/kc1/kc1.c                        |   4 +-
> >  board/amlogic/p200/p200.c                     |   4 +-
> >  board/amlogic/p201/p201.c                     |   4 +-
> >  board/amlogic/p212/p212.c                     |   4 +-
> >  board/amlogic/q200/q200.c                     |   4 +-
> >  board/aristainetos/aristainetos-v2.c          |   8 +-
> >  board/armltd/integrator/integrator.c          |   2 +-
> >  board/atmel/common/board.c                    |   4 +-
> >  board/atmel/common/mac_eeprom.c               |   2 +-
> >  board/atmel/sama5d3xek/sama5d3xek.c           |   2 +-
> >  board/bachmann/ot1200/ot1200.c                |   4 +-
> >  board/birdland/bav335x/board.c                |   8 +-
> >  board/bluegiga/apx4devkit/apx4devkit.c        |   5 +-
> >  board/bluewater/gurnard/gurnard.c             |   6 +-
> >  board/bosch/shc/board.c                       |   2 +-
> >  board/boundary/nitrogen6x/nitrogen6x.c        |  14 +-
> >  board/broadcom/bcm23550_w1d/bcm23550_w1d.c    |   2 +-
> >  board/broadcom/bcm28155_ap/bcm28155_ap.c      |   2 +-
> >  board/broadcom/bcmstb/bcmstb.c                |   2 +-
> >  board/buffalo/lsxl/lsxl.c                     |   2 +-
> >  board/cadence/xtfpga/xtfpga.c                 |   4 +-
> >  board/ccv/xpress/xpress.c                     |   2 +-
> >  board/compulab/cl-som-imx7/cl-som-imx7.c      |   2 +-
> >  board/compulab/cm_fx6/cm_fx6.c                |  10 +-
> >  board/compulab/common/omap3_display.c         |   4 +-
> >  board/congatec/cgtqmx6eval/cgtqmx6eval.c      |   8 +-
> >  board/cssi/MCR3000/MCR3000.c                  |   2 +-
> >  board/davinci/da8xxevm/da850evm.c             |   2 +-
> >  board/davinci/da8xxevm/omapl138_lcdk.c        |   6 +-
> >  board/dhelectronics/dh_imx6/dh_imx6.c         |   2 +-
> >  board/eets/pdu001/board.c                     |   8 +-
> >  board/el/el6x/el6x.c                          |   2 +-
> >  board/emulation/qemu-riscv/qemu-riscv.c       |   2 +-
> >  board/engicam/common/board.c                  |  32 +-
> >  board/esd/meesc/meesc.c                       |   6 +-
> >  board/freescale/b4860qds/b4860qds.c           |   5 +-
> >  board/freescale/common/cmd_esbc_validate.c    |   2 +-
> >  board/freescale/common/fsl_chain_of_trust.c   |   6 +-
> >  board/freescale/common/sys_eeprom.c           |   4 +-
> >  board/freescale/common/vid.c                  |   4 +-
> >  board/freescale/imx8mq_evk/imx8mq_evk.c       |   4 +-
> >  board/freescale/imx8qm_mek/imx8qm_mek.c       |   4 +-
> >  board/freescale/imx8qxp_mek/imx8qxp_mek.c     |   4 +-
> >  board/freescale/ls1088a/eth_ls1088aqds.c      |   4 +-
> >  board/freescale/ls1088a/ls1088a.c             |   2 +-
> >  board/freescale/ls2080aqds/eth.c              |   6 +-
> >  board/freescale/ls2080aqds/ls2080aqds.c       |   2 +-
> >  board/freescale/ls2080ardb/ls2080ardb.c       |   6 +-
> >  board/freescale/lx2160a/eth_lx2160aqds.c      |   2 +-
> >  board/freescale/mpc8323erdb/mpc8323erdb.c     |   3 +-
> >  board/freescale/mpc837xemds/pci.c             |   2 +-
> >  board/freescale/mpc837xerdb/mpc837xerdb.c     |   2 +-
> >  board/freescale/mx51evk/mx51evk_video.c       |   2 +-
> >  board/freescale/mx53loco/mx53loco.c           |   4 +-
> >  board/freescale/mx53loco/mx53loco_video.c     |   2 +-
> >  board/freescale/mx6sabreauto/mx6sabreauto.c   |   8 +-
> >  board/freescale/mx6sabresd/mx6sabresd.c       |   8 +-
> >  board/freescale/mx6sxsabresd/mx6sxsabresd.c   |   2 +-
> >  .../mx6ul_14x14_evk/mx6ul_14x14_evk.c         |   6 +-
> >  board/freescale/mx6ullevk/mx6ullevk.c         |   4 +-
> >  board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c   |   2 +-
> >  board/freescale/qemu-ppce500/qemu-ppce500.c   |   4 +-
> >  board/freescale/t4qds/t4240qds.c              |   2 +-
> >  board/gardena/smart-gateway-at91sam/board.c   |   2 +-
> >  board/gardena/smart-gateway-mt7688/board.c    |  16 +-
> >  board/gateworks/gw_ventana/common.c           |   2 +-
> >  board/gateworks/gw_ventana/gw_ventana.c       |  61 +-
> >  board/gateworks/gw_ventana/gw_ventana_spl.c   |   4 +-
> >  board/gdsys/a38x/keyprogram.c                 |   4 +-
> >  board/gdsys/mpc8308/gazerbeam.c               |   4 +-
> >  board/gdsys/mpc8308/hrcon.c                   |   2 +-
> >  board/gdsys/mpc8308/strider.c                 |   2 +-
> >  board/gdsys/p1022/controlcenterd-id.c         |  10 +-
> >  board/gdsys/p1022/controlcenterd.c            |   2 +-
> >  board/ge/bx50v3/bx50v3.c                      |  13 +-
> >  board/ge/common/ge_common.c                   |   4 +-
> >  board/ge/mx53ppd/mx53ppd.c                    |   2 +-
> >  board/grinn/chiliboard/board.c                |   4 +-
> >  board/grinn/liteboard/board.c                 |   6 +-
> >  board/highbank/highbank.c                     |   9 +-
> >  board/hisilicon/poplar/poplar.c               |   2 +-
> >  board/imgtec/ci20/ci20.c                      |   6 +-
> >  board/intel/edison/edison.c                   |  14 +-
> >  board/isee/igep003x/board.c                   |   6 +-
> >  board/isee/igep00x0/igep00x0.c                |   4 +-
> >  board/k+p/kp_imx53/kp_id_rev.c                |  20 +-
> >  board/k+p/kp_imx53/kp_imx53.c                 |   4 +-
> >  board/k+p/kp_imx6q_tpc/kp_imx6q_tpc.c         |   4 +-
> >  board/keymile/common/common.c                 |  26 +-
> >  board/keymile/common/ivm.c                    |   8 +-
> >  board/keymile/km83xx/km83xx.c                 |   2 +-
> >  board/keymile/km_arm/km_arm.c                 |   6 +-
> >  board/keymile/kmp204x/kmp204x.c               |   4 +-
> >  board/kosagi/novena/novena.c                  |   2 +-
> >  board/laird/wb50n/wb50n.c                     |   2 +-
> >  board/lg/sniper/sniper.c                      |   4 +-
> >  board/liebherr/display5/spl.c                 |   4 +-
> >  board/liebherr/mccmon6/mccmon6.c              |   6 +-
> >  board/logicpd/imx6/imx6logic.c                |   8 +-
> >  board/menlo/m53menlo/m53menlo.c               |   2 +-
> >  board/micronas/vct/vct.c                      |   2 +-
> >  board/nokia/rx51/rx51.c                       |  10 +-
> >  board/overo/overo.c                           |  45 +-
> >  board/phytec/pcm052/pcm052.c                  |   4 +-
> >  board/phytec/pfla02/pfla02.c                  |   2 +-
> >  .../dragonboard410c/dragonboard410c.c         |   6 +-
> >  .../dragonboard820c/dragonboard820c.c         |   2 +-
> >  board/raspberrypi/rpi/rpi.c                   |  26 +-
> >  board/renesas/alt/alt.c                       |   3 +-
> >  board/renesas/gose/gose.c                     |   3 +-
> >  board/renesas/koelsch/koelsch.c               |   3 +-
> >  board/renesas/lager/lager.c                   |   3 +-
> >  board/renesas/porter/porter.c                 |   3 +-
> >  board/renesas/sh7752evb/sh7752evb.c           |   4 +-
> >  board/renesas/sh7753evb/sh7753evb.c           |   4 +-
> >  board/renesas/sh7757lcr/sh7757lcr.c           |   6 +-
> >  board/renesas/silk/silk.c                     |   3 +-
> >  board/renesas/stout/stout.c                   |   3 +-
> >  board/rockchip/kylin_rk3036/kylin_rk3036.c    |   2 +-
> >  board/samsung/common/exynos5-dt.c             |   2 +-
> >  board/samsung/common/misc.c                   |  14 +-
> >  board/samsung/odroid/odroid.c                 |   2 +-
> >  board/samsung/trats/trats.c                   |   2 +-
> >  board/samsung/universal_c210/universal.c      |   2 +-
> >  board/samtec/vining_fpga/socfpga.c            |  16 +-
> >  board/siemens/common/board.c                  |   4 +-
> >  board/siemens/draco/board.c                   |   6 +-
> >  board/siemens/pxm2/board.c                    |   4 +-
> >  board/siemens/rut/board.c                     |   2 +-
> >  board/siemens/taurus/taurus.c                 |  50 +-
> >  board/socrates/socrates.c                     |   4 +-
> >  board/softing/vining_2000/vining_2000.c       |   8 +-
> >  board/solidrun/mx6cuboxi/mx6cuboxi.c          |  16 +-
> >  .../stm32f429-discovery/stm32f429-discovery.c |   4 +-
> >  .../stm32f429-evaluation.c                    |   4 +-
> >  .../stm32f469-discovery/stm32f469-discovery.c |   4 +-
> >  board/st/stm32mp1/stm32mp1.c                  |  11 +-
> >  board/sunxi/board.c                           |  25 +-
> >  board/synopsys/hsdk/env-lib.c                 |  11 +-
> >  board/synopsys/hsdk/hsdk.c                    |   6 +-
> >  board/syteco/zmx25/zmx25.c                    |   8 +-
> >  board/tcl/sl50/board.c                        |   6 +-
> >  .../puma_rk3399/puma-rk3399.c                 |   8 +-
> >  board/ti/am335x/board.c                       |  18 +-
> >  board/ti/am43xx/board.c                       |   6 +-
> >  board/ti/am57xx/board.c                       |  14 +-
> >  board/ti/beagle/beagle.c                      |  43 +-
> >  board/ti/common/board_detect.c                |  14 +-
> >  board/ti/dra7xx/evm.c                         |  12 +-
> >  board/ti/evm/evm.c                            |   2 +-
> >  board/ti/ks2_evm/board.c                      |  10 +-
> >  board/ti/ks2_evm/board_k2g.c                  |   8 +-
> >  board/ti/panda/panda.c                        |   4 +-
> >  board/toradex/apalis-imx8/apalis-imx8.c       |   4 +-
> >  board/toradex/apalis_imx6/apalis_imx6.c       |  12 +-
> >  .../toradex/colibri-imx6ull/colibri-imx6ull.c |   6 +-
> >  board/toradex/colibri-imx8x/colibri-imx8x.c   |   4 +-
> >  board/toradex/colibri_imx6/colibri_imx6.c     |   8 +-
> >  board/toradex/colibri_vf/colibri_vf.c         |   2 +-
> >  board/toradex/common/tdx-cfg-block.c          |   2 +-
> >  board/toradex/common/tdx-common.c             |   2 +-
> >  board/tqc/tqma6/tqma6.c                       |   2 +-
> >  board/udoo/neo/neo.c                          |   2 +-
> >  board/udoo/udoo.c                             |   4 +-
> >  board/varisys/common/sys_eeprom.c             |   6 +-
> >  board/vscom/baltos/board.c                    |   6 +-
> >  board/wandboard/wandboard.c                   |  12 +-
> >  board/warp7/warp7.c                           |   6 +-
> >  .../work_92105/work_92105_display.c           |   2 +-
> >  board/xes/common/board.c                      |   6 +-
> >  board/xilinx/zynq/board.c                     |  16 +-
> >  board/xilinx/zynqmp/cmds.c                    |   2 +-
> >  board/xilinx/zynqmp/zynqmp.c                  |  24 +-
> >  cmd/ab_select.c                               |   2 +-
> >  cmd/avb.c                                     |   2 +-
> >  cmd/bdinfo.c                                  |   6 +-
> >  cmd/binop.c                                   |   4 +-
> >  cmd/bootefi.c                                 |   8 +-
> >  cmd/bootm.c                                   |   4 +-
> >  cmd/bootmenu.c                                |   6 +-
> >  cmd/cbfs.c                                    |   2 +-
> >  cmd/cramfs.c                                  |   8 +-
> >  cmd/dtimg.c                                   |   2 +-
> >  cmd/elf.c                                     |  29 +-
> >  cmd/fdt.c                                     |  22 +-
> >  cmd/fpga.c                                    |   4 +-
> >  cmd/gpt.c                                     |   8 +-
> >  cmd/ini.c                                     |   6 +-
> >  cmd/itest.c                                   |   2 +-
> >  cmd/jffs2.c                                   |   4 +-
> >  cmd/load.c                                    |  10 +-
> >  cmd/lzmadec.c                                 |   2 +-
> >  cmd/md5sum.c                                  |   4 +-
> >  cmd/mtdparts.c                                |  41 +-
> >  cmd/mvebu/bubt.c                              |   2 +-
> >  cmd/nand.c                                    |  12 +-
> >  cmd/net.c                                     |  46 +-
> >  cmd/nvedit.c                                  | 394 +++++++---
> >  cmd/part.c                                    |   6 +-
> >  cmd/pxe.c                                     |  33 +-
> >  cmd/qfw.c                                     |   6 +-
> >  cmd/reiser.c                                  |   8 +-
> >  cmd/setexpr.c                                 |   8 +-
> >  cmd/spl.c                                     |   5 +-
> >  cmd/ti/ddr3.c                                 |   2 +-
> >  cmd/tpm-common.c                              |   2 +-
> >  cmd/tpm-v1.c                                  |   2 +-
> >  cmd/trace.c                                   |  18 +-
> >  cmd/ubi.c                                     |   2 +-
> >  cmd/unzip.c                                   |   2 +-
> >  cmd/ximg.c                                    |   4 +-
> >  cmd/zfs.c                                     |   6 +-
> >  cmd/zip.c                                     |   2 +-
> >  common/autoboot.c                             |  22 +-
> >  common/board_f.c                              |   3 +-
> >  common/board_r.c                              |  10 +-
> >  common/bootm.c                                |  12 +-
> >  common/bootm_os.c                             |  12 +-
> >  common/bootretry.c                            |   2 +-
> >  common/cli.c                                  |   2 +-
> >  common/cli_hush.c                             |  14 +-
> >  common/cli_simple.c                           |   2 +-
> >  common/command.c                              |   2 +-
> >  common/console.c                              |  14 +-
> >  common/fdt_support.c                          |   6 +-
> >  common/hash.c                                 |   4 +-
> >  common/hwconfig.c                             |   5 +-
> >  common/image-android.c                        |   4 +-
> >  common/image-fdt.c                            |   4 +-
> >  common/image.c                                |  15 +-
> >  common/main.c                                 |   5 +-
> >  common/spl/spl_dfu.c                          |   6 +-
> >  common/spl/spl_ext.c                          |   4 +-
> >  common/spl/spl_fat.c                          |   4 +-
> >  common/spl/spl_net.c                          |   4 +-
> >  common/splash.c                               |   4 +-
> >  common/splash_source.c                        |   8 +-
> >  common/update.c                               |  10 +-
> >  common/usb_hub.c                              |   2 +-
> >  common/usb_kbd.c                              |   6 +-
> >  disk/part.c                                   |   2 +-
> >  disk/part_amiga.c                             |   4 +-
> >  drivers/bootcount/bootcount_env.c             |  12 +-
> >  drivers/ddr/fsl/fsl_ddr_gen4.c                |   2 +-
> >  drivers/ddr/fsl/interactive.c                 |   5 +-
> >  drivers/ddr/fsl/options.c                     |   4 +-
> >  drivers/dfu/dfu.c                             |   6 +-
> >  drivers/fastboot/fb_command.c                 |   4 +-
> >  drivers/fastboot/fb_common.c                  |   2 +-
> >  drivers/fastboot/fb_getvar.c                  |   8 +-
> >  drivers/fastboot/fb_mmc.c                     |   2 +-
> >  drivers/input/i8042.c                         |   2 +-
> >  drivers/input/input.c                         |   2 +-
> >  drivers/misc/fs_loader.c                      |   8 +-
> >  drivers/mtd/cfi_flash.c                       |   2 +-
> >  drivers/mtd/mtd_uboot.c                       |  11 +-
> >  drivers/net/fec_mxc.c                         |   2 +-
> >  drivers/net/fm/b4860.c                        |   3 +-
> >  drivers/net/fm/fdt.c                          |   2 +-
> >  drivers/net/fm/fm.c                           |   4 +-
> >  drivers/net/fsl-mc/mc.c                       |   7 +-
> >  drivers/net/netconsole.c                      |  14 +-
> >  drivers/net/phy/micrel_ksz90x1.c              |   4 +-
> >  drivers/net/sandbox-raw.c                     |   4 +-
> >  drivers/pci/pci.c                             |   4 +-
> >  drivers/pci/pci_common.c                      |   2 +-
> >  drivers/reset/reset-socfpga.c                 |   2 +-
> >  drivers/rtc/m41t60.c                          |   2 +-
> >  drivers/scsi/scsi.c                           |   2 +-
> >  drivers/serial/usbtty.c                       |   4 +-
> >  drivers/usb/gadget/designware_udc.c           |   2 +-
> >  drivers/usb/gadget/ether.c                    |  13 +-
> >  drivers/usb/gadget/f_dfu.c                    |   2 +-
> >  drivers/usb/gadget/f_fastboot.c               |   2 +-
> >  drivers/usb/gadget/f_rockusb.c                |   2 +-
> >  drivers/usb/gadget/f_sdp.c                    |   2 +-
> >  drivers/usb/host/ehci-fsl.c                   |   2 +-
> >  drivers/video/ati_radeon_fb.c                 |   2 +-
> >  drivers/video/cfb_console.c                   |   2 +-
> >  drivers/video/mb862xx.c                       |   2 +-
> >  drivers/video/mx3fb.c                         |   2 +-
> >  drivers/video/mxsfb.c                         |   2 +-
> >  drivers/video/videomodes.c                    |   4 +-
> >  env/Kconfig                                   | 683 +-----------------
> >  env/Kconfig.efi                               | 152 ++++
> >  env/Kconfig.uboot                             | 671 +++++++++++++++++
> >  env/Makefile                                  |  33 +-
> >  env/callback.c                                |  40 +-
> >  env/common.c                                  | 255 ++++---
> >  env/env.c                                     | 158 ++--
> >  env/env_ctx_efi.c                             | 131 ++++
> >  env/env_ctx_uboot.c                           | 292 ++++++++
> >  env/fat.c                                     | 102 ++-
> >  env/flags.c                                   |  35 +-
> >  env/flash.c                                   | 397 ++++++----
> >  env/nowhere.c                                 |   7 +-
> >  fs/fs.c                                       |  14 +-
> >  fs/ubifs/ubifs.c                              |   2 +-
> >  include/_exports.h                            |   6 +-
> >  include/common.h                              |   6 +-
> >  include/env.h                                 | 114 ++-
> >  include/env_internal.h                        |  89 ++-
> >  include/exports.h                             |   5 +-
> >  include/search.h                              |   6 +-
> >  lib/efi_loader/efi_console.c                  |   2 +-
> >  lib/efi_loader/efi_variable.c                 |  91 ++-
> >  lib/fdtdec.c                                  |   2 +-
> >  lib/hashtable.c                               |  14 +-
> >  lib/smbios.c                                  |   2 +-
> >  lib/uuid.c                                    |   2 +-
> >  net/bootp.c                                   |  17 +-
> >  net/dns.c                                     |   2 +-
> >  net/eth-uclass.c                              |   6 +-
> >  net/eth_common.c                              |  18 +-
> >  net/eth_legacy.c                              |   2 +-
> >  net/link_local.c                              |   2 +-
> >  net/net.c                                     |  11 +-
> >  net/tftp.c                                    |  10 +-
> >  net/wol.c                                     |   2 +-
> >  post/post.c                                   |   2 +-
> >  371 files changed, 3690 insertions(+), 2337 deletions(-)
> >  create mode 100644 env/Kconfig.efi
> >  create mode 100644 env/Kconfig.uboot
> >  create mode 100644 env/env_ctx_efi.c
> >  create mode 100644 env/env_ctx_uboot.c
> > 
> > -- 
> > 2.21.0
> > 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-23  6:53   ` AKASHI Takahiro
@ 2019-10-25  7:06     ` Wolfgang Denk
  2019-10-25  7:56       ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Wolfgang Denk @ 2019-10-25  7:06 UTC (permalink / raw)
  To: u-boot

Dear Takahiro,

In message <20191023065332.GE10448@linaro.org> you wrote:
>
> This is my second ping.
> Could you please take time to review this patch?

Sorry, I'm afraid I will not find the time to review any such
monster patch series any time soon.  I hope Joe (added to Cc:)
has more resources available.

Only a few comments below...

> > > # In version 5 of this patch set, the implementation is changed again.
> > > #
> > > # I believe that this is NOT intrusive, and that my approach here is NOT
> > > # selfish at all. If Wolfgang doesn't accept this approach, however,

371 files changed, 3690 insertions(+), 2337 deletions(-)

I don't know what your scales are, but for me such a patch is
extremely invasive. It affects a zillion of files in common code
plus a ton of board specific files.

I did not find any information about the size impact or if the
modified code continues to build for all boards - I remember we have
a number of board with tight resources here and there.

You should at least provide some information how much bigger the new
code gets.

From a quick glance I think the patches are not cleanly separated -
you cannot change interfaces for the implementation in one step and
for the callers in another, as this breaks bisectability.


My biggest concern is that such a highly invasive change cannot be
simply rubberstamped in a code review - I think this also needs
runtime testing on at least a significant number of the affected
boards.  We should try to get help from at least some board
maintainers - maybe you should ask for help for such testing n the
board maintainers mailing list?


Please do not misunderstand me - I am not trying to block any of
this - I understand and appreciate the huge amount of efforts you
have put into this.  But I feel this needs not only careful review,
but also actual testing on as many of the effected boards as
possible, and I simply don't have time for that.


> > > * To access (get or set) a variable, associated context must be presented.
> > >   So, almost of all existing env interfaces are changed to accept one
> > >   extra argument, ctx.
> > >   (I believe that this is Wolfgang's *requirement*.)

I wonder if we really need to change all interfaces.  I fear the
size impact might bite us.  I only had a glimpse at the actual code,
but it seemed to me as if we were just pssing the same information
around everywhere.  Could we not use GD nstead, for example?

> > > * Non-volatile feature is not implemented in a general form and must be
> > >   implemented by users in their sub-systems.

I don't understand what this means, or why such a decision was made.
Which sub-systems do you have in mind here?
What prevented you from implementing a solution to works for all of
us?

> > >   In version 4, U-Boot environment's attributes are extended to support
> > >   non-volatile (or auto-save capability), but Wolfgang rejected
> > >   my approach.
> > >   As modifying attributes for this purpose would cause bunch of
> > >   incompatibility issues (as far as I said in my cover letter and
> > >   the discussions in ML), I would prefer a much simple approach.

I think we still have a different opinion here, but I'm lacking time
for a thorough readding of the new code, so I hold back.  I hope
that Joe can have a closer look...

> > > * Each backing storage driver must be converted to be aligned with
> > >   new env interfaces to handle multiple contexts in parallel and
> > >   provide context-specific Kconfig configurations for driver parameters.
> > > 
> > >   In this version, only FAT file system and flash devices are supported,
> > >   but it is quite straightforward to modify other drivers.

If I see this correctly, there is a fundamental change in the
implementation before: Up to now, the environment seize on external
storage has been a compile time constant (CONFIG_ENV_SIZE).

Now this value gets computed, and I'm not even sure if this is a
contant at run time.

This scares me.  Does this not break compatibility?  How do you
upgrade a system from an older version of U-Boot to one with your
patches?

> > > Known issues/restriction/TODO:
> > > * The current form of patchset is not 'bisect'able.
> > >   Not to break 'bisect,' all the patches in this patch set must be
> > >   put into a single commit when merging.
> > >   (This can be mitigated by modifying/splitting Patch#18/#19 though.)

OK, so you are aware of this problem.

I must admit that I really hate this. If you could avoid all the API
changes, this would solve this problem, wouldn't it?

> > > * Unfortunately, this code fails to read U-Boot environment from flash
> > >   at boot time due to incomprehensible memory corruption.
> > >   See murky workaround, which is marked as FIXME, in env/flash.c.

Argh.  This is a killing point, isn't it?

You don't seriously expect to have patches which cause
"incomprehensible memory corruption" to be included into mainline?


> > > * The whole area of storage will be saved at *every* update of
> > >   one UEFI variable. It should be optimized if possible.

This is only true for UEFI variables, right?

> > > * An error during "save" operation may cause inconsistency between
> > >   cache (hash table) and the storage.
> > >     -> This is not UEFI specific though.

Is this a new problem, or do you just mention this here for
completeness?  We always had this issue, didn't we?

> > > * I cannot test all the platforms affected by this patchset.

Sure, so please seek help from the board maintainers.

And please provide size statistics.

> > > To enable this feature for example with FAT file system, the following
> > > configs must be enabled:
> > >   CONFIG_ENV_IS_IN_FAT
> > >   CONFIG_ENV_FAT_INTERFACE
> > >   CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
> > >   CONFIG_ENV_EFI_FAT_FILE

How much testing can be done on boards that don't use FAT to store
the environment?


Sorry that I can't be of any better help here...

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
'What shall we do?' said Twoflower.  'Panic?'  said  Rincewind  hope-
fully. He always held that panic was the best means of survival; back
in  the  olden days, his theory went, people faced with hungry sabre-
toothed tigers could be divided very simply in those who panicked and
those who stood there saying 'What a magnificent  brute!'  or  'Here,
pussy.'                      - Terry Pratchett, _The Light Fantastic_

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-25  7:06     ` Wolfgang Denk
@ 2019-10-25  7:56       ` AKASHI Takahiro
  2019-10-25 13:25         ` Wolfgang Denk
  0 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-10-25  7:56 UTC (permalink / raw)
  To: u-boot

Hi Wolfgang,

On Fri, Oct 25, 2019 at 09:06:44AM +0200, Wolfgang Denk wrote:
> Dear Takahiro,
> 
> In message <20191023065332.GE10448@linaro.org> you wrote:
> >
> > This is my second ping.
> > Could you please take time to review this patch?
> 
> Sorry, I'm afraid I will not find the time to review any such
> monster patch series any time soon.  I hope Joe (added to Cc:)
> has more resources available.
> 
> Only a few comments below...

I won't and cannot make replies on every comment that you gave me
below because we are very different at some basic points and
other comments are just details.

> > > > # In version 5 of this patch set, the implementation is changed again.
> > > > #
> > > > # I believe that this is NOT intrusive, and that my approach here is NOT
> > > > # selfish at all. If Wolfgang doesn't accept this approach, however,
> 
> 371 files changed, 3690 insertions(+), 2337 deletions(-)
> 
> I don't know what your scales are, but for me such a patch is
> extremely invasive. It affects a zillion of files in common code
> plus a ton of board specific files.
> 
> I did not find any information about the size impact or if the
> modified code continues to build for all boards - I remember we have
> a number of board with tight resources here and there.
> 
> You should at least provide some information how much bigger the new
> code gets.
> 
> From a quick glance I think the patches are not cleanly separated -
> you cannot change interfaces for the implementation in one step and
> for the callers in another, as this breaks bisectability.

As you noticed below, I'm aware of that.
So first I wanted to know if you agree to my *basic* approach or not,
not details, in order to go further, but still don't see
yes or no below.

> 
> My biggest concern is that such a highly invasive change cannot be
> simply rubberstamped in a code review - I think this also needs
> runtime testing on at least a significant number of the affected
> boards.  We should try to get help from at least some board
> maintainers - maybe you should ask for help for such testing n the
> board maintainers mailing list?
> 
> 
> Please do not misunderstand me - I am not trying to block any of
> this - I understand and appreciate the huge amount of efforts you
> have put into this.  But I feel this needs not only careful review,
> but also actual testing on as many of the effected boards as
> possible, and I simply don't have time for that.

Okay.

> 
> > > > * To access (get or set) a variable, associated context must be presented.
> > > >   So, almost of all existing env interfaces are changed to accept one
> > > >   extra argument, ctx.
> > > >   (I believe that this is Wolfgang's *requirement*.)
> 
> I wonder if we really need to change all interfaces.  I fear the
> size impact might bite us.  I only had a glimpse at the actual code,
> but it seemed to me as if we were just pssing the same information
> around everywhere.  Could we not use GD nstead, for example?
> 
> > > > * Non-volatile feature is not implemented in a general form and must be
> > > >   implemented by users in their sub-systems.
> 
> I don't understand what this means, or why such a decision was made.
> Which sub-systems do you have in mind here?

UEFI sub-system/library.

> What prevented you from implementing a solution to works for all of
> us?
> 
> > > >   In version 4, U-Boot environment's attributes are extended to support
> > > >   non-volatile (or auto-save capability), but Wolfgang rejected
> > > >   my approach.
> > > >   As modifying attributes for this purpose would cause bunch of
> > > >   incompatibility issues (as far as I said in my cover letter and
> > > >   the discussions in ML), I would prefer a much simple approach.
> 
> I think we still have a different opinion here, but I'm lacking time
> for a thorough readding of the new code, so I hold back.  I hope
> that Joe can have a closer look...

You don't have to worry about my previous versions.
Just focus on the current v5.

> 
> > > > * Each backing storage driver must be converted to be aligned with
> > > >   new env interfaces to handle multiple contexts in parallel and
> > > >   provide context-specific Kconfig configurations for driver parameters.
> > > > 
> > > >   In this version, only FAT file system and flash devices are supported,
> > > >   but it is quite straightforward to modify other drivers.
> 
> If I see this correctly, there is a fundamental change in the
> implementation before: Up to now, the environment seize on external
> storage has been a compile time constant (CONFIG_ENV_SIZE).
> 
> Now this value gets computed, and I'm not even sure if this is a
> contant at run time.

Yes, it's constant for "U-Boot environment" (== U-Boot variables) context.
But for other sus-systems, in my case UEFI, the total size of storage
for (UEFI) variables may be different, but still constant.

> This scares me.  Does this not break compatibility?  How do you
> upgrade a system from an older version of U-Boot to one with your
> patches?
> 
> > > > Known issues/restriction/TODO:
> > > > * The current form of patchset is not 'bisect'able.
> > > >   Not to break 'bisect,' all the patches in this patch set must be
> > > >   put into a single commit when merging.
> > > >   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> 
> OK, so you are aware of this problem.
> 
> I must admit that I really hate this. If you could avoid all the API
> changes, this would solve this problem, wouldn't it?

"Avoid all the API changes" is an approach that I took in all my
previous versions, but you *denied* it.

That is: I proposed an approach in which the existing interfaces,
env_get/set(), were maintained for existing users/sub-systems.
Only new users who want to enjoy merits from new "context" feature may
use new *extended* interfaces, env_[get|set]_ext(), in my case UEFI.
As you *denied* it, this version (v5) is an inevitable result.

Don't take me wrong, but I think that you made inconsistent comments.

> > > > * Unfortunately, this code fails to read U-Boot environment from flash
> > > >   at boot time due to incomprehensible memory corruption.
> > > >   See murky workaround, which is marked as FIXME, in env/flash.c.
> 
> Argh.  This is a killing point, isn't it?
> 
> You don't seriously expect to have patches which cause
> "incomprehensible memory corruption" to be included into mainline?

It will be just a matter of time for debugging.

> > > > * The whole area of storage will be saved at *every* update of
> > > >   one UEFI variable. It should be optimized if possible.
> 
> This is only true for UEFI variables, right?

Yes.

> > > > * An error during "save" operation may cause inconsistency between
> > > >   cache (hash table) and the storage.
> > > >     -> This is not UEFI specific though.
> 
> Is this a new problem, or do you just mention this here for
> completeness?  We always had this issue, didn't we?

As I said, "this is not UEFI specific."

> > > > * I cannot test all the platforms affected by this patchset.
> 
> Sure, so please seek help from the board maintainers.
> 
> And please provide size statistics.
> 
> > > > To enable this feature for example with FAT file system, the following
> > > > configs must be enabled:
> > > >   CONFIG_ENV_IS_IN_FAT
> > > >   CONFIG_ENV_FAT_INTERFACE
> > > >   CONFIG_ENV_EFI_FAT_DEVICE_AND_PART
> > > >   CONFIG_ENV_EFI_FAT_FILE
> 
> How much testing can be done on boards that don't use FAT to store
> the environment?

As I said, 
> > > >   In this version, only FAT file system and flash devices are supported,
> > > >   but it is quite straightforward to modify other drivers.

If you don't think my patch is not qualified for a "PATCH" for some reason,
I will sent one as "RFC" from the next version. I don't care.

Thanks,
-Takahiro Akashi

> 
> Sorry that I can't be of any better help here...
> 
> Best regards,
> 
> Wolfgang Denk
> 
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> 'What shall we do?' said Twoflower.  'Panic?'  said  Rincewind  hope-
> fully. He always held that panic was the best means of survival; back
> in  the  olden days, his theory went, people faced with hungry sabre-
> toothed tigers could be divided very simply in those who panicked and
> those who stood there saying 'What a magnificent  brute!'  or  'Here,
> pussy.'                      - Terry Pratchett, _The Light Fantastic_

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-25  7:56       ` AKASHI Takahiro
@ 2019-10-25 13:25         ` Wolfgang Denk
  2019-10-28  1:14           ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Wolfgang Denk @ 2019-10-25 13:25 UTC (permalink / raw)
  To: u-boot

Dear Takahiro,

In message <20191025075645.GJ10448@linaro.org> you wrote:
>
> I won't and cannot make replies on every comment that you gave me
> below because we are very different at some basic points and
> other comments are just details.

Can you please at least comment on the size impact?  How much does
the code size grow on everage, especially for SPL?


> So first I wanted to know if you agree to my *basic* approach or not,
> not details, in order to go further, but still don't see
> yes or no below.

To be honest: when I saw your monster patch series which basically
touches every piece of code in U-Boot, I felt a strong temptation to
just send a NAK and be done with it.  But I know this would not be
fair.  But to be able to say yes I would need days to review the
code and probably run some tests myself, and I don;t have that time.

So I can neither say yes or no, sorry.

> > My biggest concern is that such a highly invasive change cannot be
> > simply rubberstamped in a code review - I think this also needs
> > runtime testing on at least a significant number of the affected
> > boards.  We should try to get help from at least some board
> > maintainers - maybe you should ask for help for such testing n the
> > board maintainers mailing list?

This is a point which is important to me.  We need at least a few
"Tested-by" credits...

> > > > > * Non-volatile feature is not implemented in a general form and must be
> > > > >   implemented by users in their sub-systems.
> > 
> > I don't understand what this means, or why such a decision was made.
> > Which sub-systems do you have in mind here?
>
> UEFI sub-system/library.

What needs to be done to have this - say - for U-Boot context?

> > What prevented you from implementing a solution to works for all of
> > us?

?

> > > > > Known issues/restriction/TODO:
> > > > > * The current form of patchset is not 'bisect'able.
> > > > >   Not to break 'bisect,' all the patches in this patch set must be
> > > > >   put into a single commit when merging.
> > > > >   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> > 
> > OK, so you are aware of this problem.
> > 
> > I must admit that I really hate this. If you could avoid all the API
> > changes, this would solve this problem, wouldn't it?
>
> "Avoid all the API changes" is an approach that I took in all my
> previous versions, but you *denied* it.
>
> That is: I proposed an approach in which the existing interfaces,
> env_get/set(), were maintained for existing users/sub-systems.
> Only new users who want to enjoy merits from new "context" feature may
> use new *extended* interfaces, env_[get|set]_ext(), in my case UEFI.
> As you *denied* it, this version (v5) is an inevitable result.
>
> Don't take me wrong, but I think that you made inconsistent comments.

I think you misunderstand. If we just need the same pointer in all
functions dealing with the environment, there are at least two ways
to implement this: we can add it as an argument to each and every
function call; this will blow up code size and also impact execution
speed.  Or we can add it to some (private or public) data structure
that is visible everywhere.  In the simplest case we could add such
a pointer to the global data (GD) structure as I suggested in my
previous mail.  this would allow you to use basically the same code
as now, but without needing to change all the argument lists.  In
the result, you could drop your modifications of all common and
board specififc files.  The code changes would be concentrated on
the environment code, and it should be anle to submit bisectable
patches again.

Yes, global variables have disadvantages, too, but does it not make
sense here?  I think we will have only one active environment
context at any time in U-Boot, so this seems to be at least a lesser
evil than the zillion of changes of all call arguments.


> > > > > * Unfortunately, this code fails to read U-Boot environment from flash
> > > > >   at boot time due to incomprehensible memory corruption.
> > > > >   See murky workaround, which is marked as FIXME, in env/flash.c.
> > 
> > Argh.  This is a killing point, isn't it?
> > 
> > You don't seriously expect to have patches which cause
> > "incomprehensible memory corruption" to be included into mainline?
>
> It will be just a matter of time for debugging.

It might be difficult to find willing testers under such
circumstances.  I would not want to run code with serious known
bugs.

> > > > > * An error during "save" operation may cause inconsistency between
> > > > >   cache (hash table) and the storage.
> > > > >     -> This is not UEFI specific though.
> > 
> > Is this a new problem, or do you just mention this here for
> > completeness?  We always had this issue, didn't we?
>
> As I said, "this is not UEFI specific."

This does not answer my question.  Are you just refering to the
general problem that a write to the persistent storage area might
fail, which has ever been present and which is inherently
unfixxable, or does your new code add any additional problems of
this kind?

> > How much testing can be done on boards that don't use FAT to store
> > the environment?
>
> As I said, 
> > > > >   In this version, only FAT file system and flash devices are supported,
> > > > >   but it is quite straightforward to modify other drivers.
>
> If you don't think my patch is not qualified for a "PATCH" for some reason,
> I will sent one as "RFC" from the next version. I don't care.

I think this is a new feature that needs to be tested.  You focus on
UEFI + FAT and I don't know if UEFI + non-FAT makes sense, but at
least (1) non-UEFI + FAT and (2) non-UEFI + non-FAT are
configurations which must be tested - absolute minimum is at least
one example implementation. My suggestion would be to use something
that is not file system based, but using plain storage, say a board
which has the environment in SPI NOR flash.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Our OS who art in CPU, UNIX be thy name.
Thy programs run, thy syscalls done,
In kernel as it is in user!

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-25 13:25         ` Wolfgang Denk
@ 2019-10-28  1:14           ` AKASHI Takahiro
  2019-10-29 13:28             ` Wolfgang Denk
  0 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-10-28  1:14 UTC (permalink / raw)
  To: u-boot

Wolfgang,

On Fri, Oct 25, 2019 at 03:25:23PM +0200, Wolfgang Denk wrote:
> Dear Takahiro,
> 
> In message <20191025075645.GJ10448@linaro.org> you wrote:
> >
> > I won't and cannot make replies on every comment that you gave me
> > below because we are very different at some basic points and
> > other comments are just details.
> 
> Can you please at least comment on the size impact?  How much does
> the code size grow on everage, especially for SPL?

Well, from the next version as I will make a drastic change as far as
I follow your suggestion below.

> 
> > So first I wanted to know if you agree to my *basic* approach or not,
> > not details, in order to go further, but still don't see
> > yes or no below.
> 
> To be honest: when I saw your monster patch series which basically
> touches every piece of code in U-Boot, I felt a strong temptation to
> just send a NAK and be done with it.  But I know this would not be
> fair.  But to be able to say yes I would need days to review the
> code and probably run some tests myself, and I don;t have that time.

Okay, I see but I hope that you should have said so much earlier.
My patch (v5) has been stranded almost two months without any comments.

> So I can neither say yes or no, sorry.
> 
> > > My biggest concern is that such a highly invasive change cannot be
> > > simply rubberstamped in a code review - I think this also needs
> > > runtime testing on at least a significant number of the affected
> > > boards.  We should try to get help from at least some board
> > > maintainers - maybe you should ask for help for such testing n the
> > > board maintainers mailing list?
> 
> This is a point which is important to me.  We need at least a few
> "Tested-by" credits...
> 
> > > > > > * Non-volatile feature is not implemented in a general form and must be
> > > > > >   implemented by users in their sub-systems.
> > > 
> > > I don't understand what this means, or why such a decision was made.
> > > Which sub-systems do you have in mind here?
> >
> > UEFI sub-system/library.
> 
> What needs to be done to have this - say - for U-Boot context?
>
> > > What prevented you from implementing a solution to works for all of
> > > us?
> 
> ?

At least for me or UEFI, nothing more, other than a *context*, is needed
to meet the requirement.
If some one really want to have such(?) a feature, he or she can on top
of my patch.
I believe that my attitude here is fair enough.

> 
> > > > > > Known issues/restriction/TODO:
> > > > > > * The current form of patchset is not 'bisect'able.
> > > > > >   Not to break 'bisect,' all the patches in this patch set must be
> > > > > >   put into a single commit when merging.
> > > > > >   (This can be mitigated by modifying/splitting Patch#18/#19 though.)
> > > 
> > > OK, so you are aware of this problem.
> > > 
> > > I must admit that I really hate this. If you could avoid all the API
> > > changes, this would solve this problem, wouldn't it?
> >
> > "Avoid all the API changes" is an approach that I took in all my
> > previous versions, but you *denied* it.
> >
> > That is: I proposed an approach in which the existing interfaces,
> > env_get/set(), were maintained for existing users/sub-systems.
> > Only new users who want to enjoy merits from new "context" feature may
> > use new *extended* interfaces, env_[get|set]_ext(), in my case UEFI.
> > As you *denied* it, this version (v5) is an inevitable result.
> >
> > Don't take me wrong, but I think that you made inconsistent comments.
> 
> I think you misunderstand. If we just need the same pointer in all
> functions dealing with the environment, there are at least two ways
> to implement this: we can add it as an argument to each and every
> function call; this will blow up code size and also impact execution
> speed.  Or we can add it to some (private or public) data structure
> that is visible everywhere.  In the simplest case we could add such
> a pointer to the global data (GD) structure as I suggested in my
> previous mail.  this would allow you to use basically the same code
> as now, but without needing to change all the argument lists.  In
> the result, you could drop your modifications of all common and
> board specififc files.  The code changes would be concentrated on
> the environment code, and it should be anle to submit bisectable
> patches again.
> 
> Yes, global variables have disadvantages, too, but does it not make
> sense here?  I think we will have only one active environment
> context at any time in U-Boot, so this seems to be at least a lesser
> evil than the zillion of changes of all call arguments.

I have thought of an idea as you mentioned above before but immediately
gave it up as it seems to be an ugly implementation and I simply dislike it.
But if you and Tom (or whoever can say ACK to my patch) think that it is
the *only* solution that you can accept, I will have to change my mind.

So do you always admit the following coding?
===8<===
  (in some UEFI function)
  ...
  old_ctx = env_set_context(ctx_uefi);
  env_set(var, value);
  env_set_context(old_ctx);
  ...
===>8===

> 
> > > > > > * Unfortunately, this code fails to read U-Boot environment from flash
> > > > > >   at boot time due to incomprehensible memory corruption.
> > > > > >   See murky workaround, which is marked as FIXME, in env/flash.c.
> > > 
> > > Argh.  This is a killing point, isn't it?
> > > 
> > > You don't seriously expect to have patches which cause
> > > "incomprehensible memory corruption" to be included into mainline?
> >
> > It will be just a matter of time for debugging.
> 
> It might be difficult to find willing testers under such
> circumstances.  I would not want to run code with serious known
> bugs.

I believe that the issue is independent from the basic approach
that we are now discussing.

> > > > > > * An error during "save" operation may cause inconsistency between
> > > > > >   cache (hash table) and the storage.
> > > > > >     -> This is not UEFI specific though.
> > > 
> > > Is this a new problem, or do you just mention this here for
> > > completeness?  We always had this issue, didn't we?
> >
> > As I said, "this is not UEFI specific."
> 
> This does not answer my question.  Are you just refering to the
> general problem that a write to the persistent storage area might
> fail, which has ever been present and which is inherently
> unfixxable, or does your new code add any additional problems of
> this kind?

A general problem in your term.

> > > How much testing can be done on boards that don't use FAT to store
> > > the environment?
> >
> > As I said, 
> > > > > >   In this version, only FAT file system and flash devices are supported,
> > > > > >   but it is quite straightforward to modify other drivers.
> >
> > If you don't think my patch is not qualified for a "PATCH" for some reason,
> > I will sent one as "RFC" from the next version. I don't care.
> 
> I think this is a new feature that needs to be tested.  You focus on
> UEFI + FAT and I don't know if UEFI + non-FAT makes sense, but at
> least (1) non-UEFI + FAT and (2) non-UEFI + non-FAT are
> configurations which must be tested - absolute minimum is at least
> one example implementation. My suggestion would be to use something
> that is not file system based, but using plain storage, say a board
> which has the environment in SPI NOR flash.

What do you mean by "non-UEFI"? Disabling UEFI, or testing U-Boot environment
variables on no-FAT device?
If the latter, I have tested it with flash (on qemu).

Thanks,
-Takahiro Akashi

> Best regards,
> 
> Wolfgang Denk
> 
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> Our OS who art in CPU, UNIX be thy name.
> Thy programs run, thy syscalls done,
> In kernel as it is in user!

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-28  1:14           ` AKASHI Takahiro
@ 2019-10-29 13:28             ` Wolfgang Denk
  2019-11-01  6:04               ` AKASHI Takahiro
  0 siblings, 1 reply; 38+ messages in thread
From: Wolfgang Denk @ 2019-10-29 13:28 UTC (permalink / raw)
  To: u-boot

Dear Takahiro,

In message <20191028011435.GP10448@linaro.org> you wrote:
>
> > Can you please at least comment on the size impact?  How much does
> > the code size grow on everage, especially for SPL?
>
> Well, from the next version as I will make a drastic change as far as
> I follow your suggestion below.

OK.

> Okay, I see but I hope that you should have said so much earlier.
> My patch (v5) has been stranded almost two months without any comments.

I have said so uin lcear and unmistakable words when discussion was
to add me as maintainer for environment code.  I cannot commit to
such a position as I don't have enough time available.

> > > > > > > * Non-volatile feature is not implemented in a general form and must be
> > > > > > >   implemented by users in their sub-systems.
> > > > 
> > > > I don't understand what this means, or why such a decision was made.
> > > > Which sub-systems do you have in mind here?
> > >
> > > UEFI sub-system/library.
> > 
> > What needs to be done to have this - say - for U-Boot context?
> >
> > > > What prevented you from implementing a solution to works for all of
> > > > us?
> > 
> > ?
>
> At least for me or UEFI, nothing more, other than a *context*, is needed
> to meet the requirement.
> If some one really want to have such(?) a feature, he or she can on top
> of my patch.
> I believe that my attitude here is fair enough.

I would appreciate if you could actually answer my questions.  there
are two of them:

You write: "Non-volatile feature is not implemented in a general
form and must be implemented by users in their sub-systems."

Q1: Why did you not implement this feature in a generic way, so it
    is automatically available to all sub-systems that support
    contexts?

Q2: What exactly needs to be done, which code needs to be writtenm,
    to implement this feature - say - for U-Boot context?


> So do you always admit the following coding?
> ===8<===
>   (in some UEFI function)
>   ...
>   old_ctx = env_set_context(ctx_uefi);
>   env_set(var, value);
>   env_set_context(old_ctx);
>   ...
> ===>8===

This is even worse, as instead of adding a single argument to a
function call you are adding two full fucntion calls.

But why would that be needed?

U-Boot is strictly single tasking.  You always know what the current
context is, and nobody will change it behind your back.

And UEFI functions are not being called in random places, they are
limited to a small set of UEFI commands, right?  So why do you not
just enter UEFI context when you start executing UEFI code, and
restore the rpevious state when returning to non-UEFI U-Boot?

Or am I missing something?

> > > > You don't seriously expect to have patches which cause
> > > > "incomprehensible memory corruption" to be included into mainline?
> > >
> > > It will be just a matter of time for debugging.
> > 
> > It might be difficult to find willing testers under such
> > circumstances.  I would not want to run code with serious known
> > bugs.
>
> I believe that the issue is independent from the basic approach
> that we are now discussing.

The reason of this problem must be understood and the bug fixed
before it can go into mainline.

> > I think this is a new feature that needs to be tested.  You focus on
> > UEFI + FAT and I don't know if UEFI + non-FAT makes sense, but at
> > least (1) non-UEFI + FAT and (2) non-UEFI + non-FAT are
> > configurations which must be tested - absolute minimum is at least
> > one example implementation. My suggestion would be to use something
> > that is not file system based, but using plain storage, say a board
> > which has the environment in SPI NOR flash.
>
> What do you mean by "non-UEFI"? Disabling UEFI, or testing U-Boot environment
> variables on no-FAT device?
> If the latter, I have tested it with flash (on qemu).

We need to test if the new context code works (and does not cause
problems) on systems where UEFI is not enabled.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Don't you know anything? I should have thought anyone knows that  who
knows anything about anything...      - Terry Pratchett, _Soul Music_

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-10-29 13:28             ` Wolfgang Denk
@ 2019-11-01  6:04               ` AKASHI Takahiro
  2019-11-04 16:00                 ` Wolfgang Denk
  0 siblings, 1 reply; 38+ messages in thread
From: AKASHI Takahiro @ 2019-11-01  6:04 UTC (permalink / raw)
  To: u-boot

Wolfgang,

I would like to focus on the critical and most arguable point in this email.

On Tue, Oct 29, 2019 at 02:28:19PM +0100, Wolfgang Denk wrote:
> Dear Takahiro,
> 
> In message <20191028011435.GP10448@linaro.org> you wrote:
> >
> > > Can you please at least comment on the size impact?  How much does
> > > the code size grow on everage, especially for SPL?
> >
> > Well, from the next version as I will make a drastic change as far as
> > I follow your suggestion below.
> 
> OK.
> 
> > Okay, I see but I hope that you should have said so much earlier.
> > My patch (v5) has been stranded almost two months without any comments.
> 
> I have said so uin lcear and unmistakable words when discussion was
> to add me as maintainer for environment code.  I cannot commit to
> such a position as I don't have enough time available.
> 
> > > > > > > > * Non-volatile feature is not implemented in a general form and must be
> > > > > > > >   implemented by users in their sub-systems.
> > > > > 
> > > > > I don't understand what this means, or why such a decision was made.
> > > > > Which sub-systems do you have in mind here?
> > > >
> > > > UEFI sub-system/library.
> > > 
> > > What needs to be done to have this - say - for U-Boot context?
> > >
> > > > > What prevented you from implementing a solution to works for all of
> > > > > us?
> > > 
> > > ?
> >
> > At least for me or UEFI, nothing more, other than a *context*, is needed
> > to meet the requirement.
> > If some one really want to have such(?) a feature, he or she can on top
> > of my patch.
> > I believe that my attitude here is fair enough.
> 
> I would appreciate if you could actually answer my questions.  there
> are two of them:
> 
> You write: "Non-volatile feature is not implemented in a general
> form and must be implemented by users in their sub-systems."
> 
> Q1: Why did you not implement this feature in a generic way, so it
>     is automatically available to all sub-systems that support
>     contexts?
> 
> Q2: What exactly needs to be done, which code needs to be writtenm,
>     to implement this feature - say - for U-Boot context?
> 
> 
> > So do you always admit the following coding?
> > ===8<===
> >   (in some UEFI function)
> >   ...
> >   old_ctx = env_set_context(ctx_uefi);
> >   env_set(var, value);
> >   env_set_context(old_ctx);
> >   ...
> > ===>8===
> 
> This is even worse, as instead of adding a single argument to a
> function call you are adding two full fucntion calls.
> 
> But why would that be needed?
> 
> U-Boot is strictly single tasking.  You always know what the current
> context is, and nobody will change it behind your back.
> 
> And UEFI functions are not being called in random places, they are
> limited to a small set of UEFI commands, right?  So why do you not
> just enter UEFI context when you start executing UEFI code, and
> restore the rpevious state when returning to non-UEFI U-Boot?

Can you elaborate What you mean by "entering UEFI context"?

What I'm thinking of here is that we would add one more member field, which
is a pointer to my "env_context," in GD and change it in env_set_context().
This can be defined even as an inline function.
(My other patches, at least patch#1 to #6, can be used almost as they are.)

I don't see why you deny such a simple solution with lots of flexibility.

-Takahiro Akashi

> Or am I missing something?
> 
> > > > > You don't seriously expect to have patches which cause
> > > > > "incomprehensible memory corruption" to be included into mainline?
> > > >
> > > > It will be just a matter of time for debugging.
> > > 
> > > It might be difficult to find willing testers under such
> > > circumstances.  I would not want to run code with serious known
> > > bugs.
> >
> > I believe that the issue is independent from the basic approach
> > that we are now discussing.
> 
> The reason of this problem must be understood and the bug fixed
> before it can go into mainline.
> 
> > > I think this is a new feature that needs to be tested.  You focus on
> > > UEFI + FAT and I don't know if UEFI + non-FAT makes sense, but at
> > > least (1) non-UEFI + FAT and (2) non-UEFI + non-FAT are
> > > configurations which must be tested - absolute minimum is at least
> > > one example implementation. My suggestion would be to use something
> > > that is not file system based, but using plain storage, say a board
> > > which has the environment in SPI NOR flash.
> >
> > What do you mean by "non-UEFI"? Disabling UEFI, or testing U-Boot environment
> > variables on no-FAT device?
> > If the latter, I have tested it with flash (on qemu).
> 
> We need to test if the new context code works (and does not cause
> problems) on systems where UEFI is not enabled.
> 
> Best regards,
> 
> Wolfgang Denk
> 
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> Don't you know anything? I should have thought anyone knows that  who
> knows anything about anything...      - Terry Pratchett, _Soul Music_

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-11-01  6:04               ` AKASHI Takahiro
@ 2019-11-04 16:00                 ` Wolfgang Denk
  2019-11-04 16:16                   ` Tom Rini
  2019-11-05  5:18                   ` AKASHI Takahiro
  0 siblings, 2 replies; 38+ messages in thread
From: Wolfgang Denk @ 2019-11-04 16:00 UTC (permalink / raw)
  To: u-boot

Dear Takahiro,

In message <20191101060434.GV10448@linaro.org> you wrote:
>
> > This is even worse, as instead of adding a single argument to a
> > function call you are adding two full fucntion calls.
> > 
> > But why would that be needed?
> > 
> > U-Boot is strictly single tasking.  You always know what the current
> > context is, and nobody will change it behind your back.
> > 
> > And UEFI functions are not being called in random places, they are
> > limited to a small set of UEFI commands, right?  So why do you not
> > just enter UEFI context when you start executing UEFI code, and
> > restore the rpevious state when returning to non-UEFI U-Boot?
>
> Can you elaborate What you mean by "entering UEFI context"?

You wrote:

| So do you always admit the following coding?
| ===8<===
|   (in some UEFI function)
|   ...
|   old_ctx = env_set_context(ctx_uefi);
|   env_set(var, value);
|   env_set_context(old_ctx);
|   ...
| ===>8===

In this code, the function call ``env_set_context(ctx_uefi)'' would
enter the UEFI context, right?  This is what I mean.

> What I'm thinking of here is that we would add one more member field, which
> is a pointer to my "env_context," in GD and change it in env_set_context().
> This can be defined even as an inline function.

Yes, this is OK - I think I understood this already.

What I mean is that such a call of env_set_context() is not needed
for each and every call of other env_*() functions.

If I understand correctly, only the UEFI specific commands will
actually care about UEFI contexts - most likely no code outside
cmd/nvedit_efi.c ?

So you have pretty clear entry and exit points into and from the
UEFI world, and it should be sufficient to set and restore this
context only then.

> I don't see why you deny such a simple solution with lots of flexibility.

I am concerned about code size and execution speed.  So far, you did
not provide any such numbers, even though I repeatedly asked for the
size impact, especially for non-UEFI systems.

Please keep in mind that there are many cases where we need access
to the environment already in SPL, and on all systems where security
plays any role we must have the same set of features enabled for the
environment code in SPL and TPL (if these need access to the
envronment) as in U-Boot proper, and memory is a precious resource
there.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You may call me by my name, Wirth, or by my value, Worth.
- Nicklaus Wirth

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-11-04 16:00                 ` Wolfgang Denk
@ 2019-11-04 16:16                   ` Tom Rini
  2019-11-05  5:18                   ` AKASHI Takahiro
  1 sibling, 0 replies; 38+ messages in thread
From: Tom Rini @ 2019-11-04 16:16 UTC (permalink / raw)
  To: u-boot

On Mon, Nov 04, 2019 at 05:00:03PM +0100, Wolfgang Denk wrote:
> Dear Takahiro,
> 
> In message <20191101060434.GV10448@linaro.org> you wrote:
> >
> > > This is even worse, as instead of adding a single argument to a
> > > function call you are adding two full fucntion calls.
> > > 
> > > But why would that be needed?
> > > 
> > > U-Boot is strictly single tasking.  You always know what the current
> > > context is, and nobody will change it behind your back.
> > > 
> > > And UEFI functions are not being called in random places, they are
> > > limited to a small set of UEFI commands, right?  So why do you not
> > > just enter UEFI context when you start executing UEFI code, and
> > > restore the rpevious state when returning to non-UEFI U-Boot?
> >
> > Can you elaborate What you mean by "entering UEFI context"?
> 
> You wrote:
> 
> | So do you always admit the following coding?
> | ===8<===
> |   (in some UEFI function)
> |   ...
> |   old_ctx = env_set_context(ctx_uefi);
> |   env_set(var, value);
> |   env_set_context(old_ctx);
> |   ...
> | ===>8===
> 
> In this code, the function call ``env_set_context(ctx_uefi)'' would
> enter the UEFI context, right?  This is what I mean.
> 
> > What I'm thinking of here is that we would add one more member field, which
> > is a pointer to my "env_context," in GD and change it in env_set_context().
> > This can be defined even as an inline function.
> 
> Yes, this is OK - I think I understood this already.
> 
> What I mean is that such a call of env_set_context() is not needed
> for each and every call of other env_*() functions.
> 
> If I understand correctly, only the UEFI specific commands will
> actually care about UEFI contexts - most likely no code outside
> cmd/nvedit_efi.c ?
> 
> So you have pretty clear entry and exit points into and from the
> UEFI world, and it should be sufficient to set and restore this
> context only then.
> 
> > I don't see why you deny such a simple solution with lots of flexibility.
> 
> I am concerned about code size and execution speed.  So far, you did
> not provide any such numbers, even though I repeatedly asked for the
> size impact, especially for non-UEFI systems.
> 
> Please keep in mind that there are many cases where we need access
> to the environment already in SPL, and on all systems where security
> plays any role we must have the same set of features enabled for the
> environment code in SPL and TPL (if these need access to the
> envronment) as in U-Boot proper, and memory is a precious resource
> there.

I too am very concerned that whatever we come up with here needs to have
between zero and near-zero impact on the rest of the U-Boot world.
We've once again hit the case where some boards don't build due to
bugfixes increasing their binary size.  And they aren't "no one uses
these, we can drop them" boards either.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191104/23848b1b/attachment.sig>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support
  2019-11-04 16:00                 ` Wolfgang Denk
  2019-11-04 16:16                   ` Tom Rini
@ 2019-11-05  5:18                   ` AKASHI Takahiro
  1 sibling, 0 replies; 38+ messages in thread
From: AKASHI Takahiro @ 2019-11-05  5:18 UTC (permalink / raw)
  To: u-boot

Wolfgang,

On Mon, Nov 04, 2019 at 05:00:03PM +0100, Wolfgang Denk wrote:
> Dear Takahiro,
> 
> In message <20191101060434.GV10448@linaro.org> you wrote:
> >
> > > This is even worse, as instead of adding a single argument to a
> > > function call you are adding two full fucntion calls.
> > > 
> > > But why would that be needed?
> > > 
> > > U-Boot is strictly single tasking.  You always know what the current
> > > context is, and nobody will change it behind your back.
> > > 
> > > And UEFI functions are not being called in random places, they are
> > > limited to a small set of UEFI commands, right?  So why do you not
> > > just enter UEFI context when you start executing UEFI code, and
> > > restore the rpevious state when returning to non-UEFI U-Boot?
> >
> > Can you elaborate What you mean by "entering UEFI context"?
> 
> You wrote:
> 
> | So do you always admit the following coding?
> | ===8<===
> |   (in some UEFI function)
> |   ...
> |   old_ctx = env_set_context(ctx_uefi);
> |   env_set(var, value);
> |   env_set_context(old_ctx);
> |   ...
> | ===>8===
> 
> In this code, the function call ``env_set_context(ctx_uefi)'' would
> enter the UEFI context, right?  This is what I mean.

My point is not there. See below.

> > What I'm thinking of here is that we would add one more member field, which
> > is a pointer to my "env_context," in GD and change it in env_set_context().
> > This can be defined even as an inline function.
> 
> Yes, this is OK - I think I understood this already.

So we get one step closer.

> What I mean is that such a call of env_set_context() is not needed
> for each and every call of other env_*() functions.
> 
> If I understand correctly, only the UEFI specific commands will
> actually care about UEFI contexts - most likely no code outside
> cmd/nvedit_efi.c ?

No. There are a couple of reasons:
1) Other commands include cmd/bootefi.c (and cmd/efidebug.c).
2) Any EFI application, once kicked off, can directly call EFI APIs.
3) Bunch of EFI features (either services or protocols) fundamentally
   reply on U-Boot native functionality, including devices (disk,
   network, console, ...), file systems and so on.

   So calling such UEFI interfaces may eventually end up with invoking
   env_*() *indirectly*. I don't come up with good examples (probably,
   network is a candidate) now but such a situation will be quite likely
   and we should not exclude such a possibility in the future.

> So you have pretty clear entry and exit points into and from the
> UEFI world, and it should be sufficient to set and restore this
> context only then.

My point is what entry or exit points are.
They cannot be at each command, but *each* API.
So, let me repeat this example:
===8<===
   (in some UEFI function)
   ...
   old_ctx = env_set_context(ctx_uefi);
   env_set(var, value);
   env_set_context(old_ctx);
   ...
===>8===

This can be at most relaxed to:
===8<===
some_efi_api(...)
{
   old_ctx = env_set_context(ctx_uefi);
   ...
   (env_get(var1);)
   ...
   env_set(var2, value);
   ...
   env_set_context(old_ctx);

   return;
}
===>8===
It is merely a matter of optimization.
This is the reason that I want to introduce env_set_context().

Thanks,
-Takahiro Akashi

> > I don't see why you deny such a simple solution with lots of flexibility.
> 
> I am concerned about code size and execution speed.  So far, you did
> not provide any such numbers, even though I repeatedly asked for the
> size impact, especially for non-UEFI systems.
> 
> Please keep in mind that there are many cases where we need access
> to the environment already in SPL, and on all systems where security
> plays any role we must have the same set of features enabled for the
> environment code in SPL and TPL (if these need access to the
> envronment) as in U-Boot proper, and memory is a precious resource
> there.
> 
> Best regards,
> 
> Wolfgang Denk
> 
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> You may call me by my name, Wirth, or by my value, Worth.
> - Nicklaus Wirth

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2019-11-05  5:18 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  8:21 [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 01/19] env: extend interfaces allowing for env contexts AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 02/19] env: define env context for U-Boot environment AKASHI Takahiro
2019-09-05 19:43   ` Heinrich Schuchardt
2019-09-06  0:41     ` AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 03/19] env: nowhere: rework with new env interfaces AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 04/19] env: flash: support multiple env contexts AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 05/19] env: fat: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 06/19] hashtable: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 07/19] api: converted with new env interfaces AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 08/19] arch: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 09/19] board: " AKASHI Takahiro
2019-09-05 12:02   ` Lukasz Majewski
2019-09-06  0:34     ` AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 10/19] cmd: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 11/19] common: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 12/19] disk: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 13/19] drivers: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 14/19] fs: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 15/19] lib: converted with new env interfaces (except efi_loader) AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 16/19] net: converted with new env interfaces AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 17/19] post: " AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 18/19] env, efi_loader: define env context for UEFI variables AKASHI Takahiro
2019-09-05 19:37   ` Heinrich Schuchardt
2019-09-06  0:54     ` AKASHI Takahiro
2019-09-05  8:21 ` [U-Boot] [PATCH v5 19/19] efi_loader: variable: rework with new env interfaces AKASHI Takahiro
2019-09-05  8:31 ` [U-Boot] [PATCH v5 00/19] efi_loader: non-volatile variables support AKASHI Takahiro
2019-10-01  6:28 ` AKASHI Takahiro
2019-10-23  6:53   ` AKASHI Takahiro
2019-10-25  7:06     ` Wolfgang Denk
2019-10-25  7:56       ` AKASHI Takahiro
2019-10-25 13:25         ` Wolfgang Denk
2019-10-28  1:14           ` AKASHI Takahiro
2019-10-29 13:28             ` Wolfgang Denk
2019-11-01  6:04               ` AKASHI Takahiro
2019-11-04 16:00                 ` Wolfgang Denk
2019-11-04 16:16                   ` Tom Rini
2019-11-05  5:18                   ` AKASHI Takahiro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.