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;
