The current environment has been hardcoded to an offset that starts to be
an issue given the current size of our main U-Boot binary.

Introduce an environment method from storing the environment raw in the MMC
to a file in a FAT partition. Eventually, and hopefully before we reach
that limit again, we will have most of our users using that setup, and
we'll be able to retire the raw environment, and gain more room for the
U-Boot binary.

Signed-off-by: Maxime Ripard <maxime.rip...@free-electrons.com>
---
 cmd/nvedit.c                   |  1 +
 env/Kconfig                    | 12 ++++++---
 env/Makefile                   |  1 +
 env/sunxi-transition.c         | 59 ++++++++++++++++++++++++++++++++++++++++++
 include/configs/sunxi-common.h |  2 +-
 include/environment.h          |  1 +
 6 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 env/sunxi-transition.c

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 4e79d03856fe..7b89ee428859 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -52,6 +52,7 @@ DECLARE_GLOBAL_DATA_PTR;
        !defined(CONFIG_ENV_IS_IN_SPI_FLASH)    && \
        !defined(CONFIG_ENV_IS_IN_REMOTE)       && \
        !defined(CONFIG_ENV_IS_IN_UBI)          && \
+       !defined(CONFIG_ENV_IS_SUNXI_TRANSITION)        && \
        !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
diff --git a/env/Kconfig b/env/Kconfig
index 02cb7cbb751d..fdd68fdfbdb6 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -30,6 +30,9 @@ choice
          partition on the device) or a filesystem (where the environment
          information is written to a file).
 
+config ENV_IS_SUNXI_TRANSITION
+       bool "Environment transition for Allwinner SoCs"
+
 config ENV_IS_NOWHERE
        bool "Environment is not stored"
        help
@@ -369,17 +372,20 @@ config ENV_AES
 
 config ENV_FAT_INTERFACE
        string "Name of the block device for the environment"
-       depends on ENV_IS_IN_FAT
+       depends on ENV_IS_IN_FAT || ENV_IS_SUNXI_TRANSITION
        default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
+       default "mmc" if ARCH_SUNXI
        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
+       depends on ENV_IS_IN_FAT || ENV_IS_SUNXI_TRANSITION
        default "0:1" if TI_COMMON_CMD_OPTIONS
        default "0:auto" if ARCH_ZYNQMP
        default "0" if ARCH_AT91
+       default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
+       default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
        help
          Define this to a string to specify the partition of the device. It can
          be as following:
@@ -397,7 +403,7 @@ config ENV_FAT_DEVICE_AND_PART
 
 config ENV_FAT_FILE
        string "Name of the FAT file to use for the environemnt"
-       depends on ENV_IS_IN_FAT
+       depends on ENV_IS_IN_FAT || ENV_IS_SUNXI_TRANSITION
        default "uboot.env"
        help
          It's a string of the FAT file name. This file use to store the
diff --git a/env/Makefile b/env/Makefile
index 7ce8231d9a70..09ad342e6161 100644
--- a/env/Makefile
+++ b/env/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += sf.o
 obj-$(CONFIG_ENV_IS_IN_REMOTE) += remote.o
 obj-$(CONFIG_ENV_IS_IN_UBI) += ubi.o
 obj-$(CONFIG_ENV_IS_NOWHERE) += nowhere.o
+obj-$(CONFIG_ENV_IS_SUNXI_TRANSITION) += fat.o mmc.o sunxi-transition.o
 endif
 
 ifdef CONFIG_SPL_BUILD
diff --git a/env/sunxi-transition.c b/env/sunxi-transition.c
new file mode 100644
index 000000000000..fae0603a897a
--- /dev/null
+++ b/env/sunxi-transition.c
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2017 Maxime Ripard
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/* #define DEBUG */
+
+#include <common.h>
+#include <environment.h>
+
+int env_fat_load(void);
+int env_fat_save(void);
+
+int env_mmc_load(void);
+int env_mmc_save(void);
+
+static int env_sunxi_save(void)
+{
+       int ret;
+
+       ret = env_fat_save();
+       if (!ret) {
+               debug("Wrote env in FAT file\n");
+               return 0;
+       }
+
+       ret = env_mmc_save();
+       if (!ret)
+               printf("The env is raw, this will be broken in the future, 
please upgrade to file-based env\n");
+
+       return ret;
+}
+
+static int env_sunxi_load(void)
+{
+       int ret;
+
+       ret = env_fat_load();
+       if (!ret) {
+               debug("Found env in FAT partition, bailing out\n");
+               return 0;
+       }
+
+       ret = env_mmc_load();
+       if (!ret)
+               printf("The env is raw, this will be broken in the future, 
please upgrade to file-based env\n");
+
+       return ret;
+}
+
+U_BOOT_ENV_LOCATION(sunxi) = {
+       .location       = ENVL_SUNXI_TRANSITION,
+       ENV_NAME("SUNXI")
+       .load           = env_sunxi_load,
+#ifndef CONFIG_SPL_BUILD
+       .save           = env_save_ptr(env_sunxi_save),
+#endif
+};
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 91751171ec2b..c894131576e2 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -147,7 +147,7 @@
 #define CONFIG_MMC_SUNXI_SLOT          0
 #endif
 
-#if defined(CONFIG_ENV_IS_IN_MMC)
+#if defined(CONFIG_ENV_IS_IN_MMC) || defined (CONFIG_ENV_IS_SUNXI_TRANSITION)
 #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
 /* If we have two devices (most likely eMMC + MMC), favour the eMMC */
 #define CONFIG_SYS_MMC_ENV_DEV         1
diff --git a/include/environment.h b/include/environment.h
index 7b9821638960..20c9cd13f11c 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -208,6 +208,7 @@ enum env_location {
        ENVL_ONENAND,
        ENVL_REMOTE,
        ENVL_SPI_FLASH,
+       ENVL_SUNXI_TRANSITION,
        ENVL_UBI,
        ENVL_NOWHERE,
 
-- 
2.14.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to