]> git.sur5r.net Git - u-boot/blobdiff - common/env_mmc.c
Merge branch 'master' of git://git.denx.de/u-boot-mmc
[u-boot] / common / env_mmc.c
index 16f6a175141346d971de0b7dbd176f0e6cf6744f..45d95a1e23ed95cf6563a26dda50cc71e9ad1b1d 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <command.h>
 #include <environment.h>
+#include <fdtdec.h>
 #include <linux/stddef.h>
 #include <malloc.h>
 #include <memalign.h>
@@ -36,16 +37,38 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CONFIG_ENV_OFFSET 0
 #endif
 
-__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static inline s64 mmc_offset(int copy)
 {
-       s64 offset;
+       const char *propname = "u-boot,mmc-env-offset";
+       s64 defvalue = CONFIG_ENV_OFFSET;
 
-       offset = CONFIG_ENV_OFFSET;
-#ifdef CONFIG_ENV_OFFSET_REDUND
+#if defined(CONFIG_ENV_OFFSET_REDUND)
+       if (copy) {
+               propname = "u-boot,mmc-env-offset-redundant";
+               defvalue = CONFIG_ENV_OFFSET_REDUND;
+       }
+#endif
+
+       return fdtdec_get_config_int(gd->fdt_blob, propname, defvalue);
+}
+#else
+static inline s64 mmc_offset(int copy)
+{
+       s64 offset = CONFIG_ENV_OFFSET;
+
+#if defined(CONFIG_ENV_OFFSET_REDUND)
        if (copy)
                offset = CONFIG_ENV_OFFSET_REDUND;
+#endif
+       return offset;
+}
 #endif
 
+__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
+{
+       s64 offset = mmc_offset(copy);
+
        if (offset < 0)
                offset += mmc->capacity;
 
@@ -82,10 +105,6 @@ static int mmc_set_env_part(struct mmc *mmc)
        int dev = mmc_get_env_dev();
        int ret = 0;
 
-#ifdef CONFIG_SPL_BUILD
-       dev = 0;
-#endif
-
        env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
        ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
        if (ret)
@@ -116,9 +135,6 @@ static void fini_mmc_for_env(struct mmc *mmc)
 #ifdef CONFIG_SYS_MMC_ENV_PART
        int dev = mmc_get_env_dev();
 
-#ifdef CONFIG_SPL_BUILD
-       dev = 0;
-#endif
        blk_select_hwpart_devnum(IF_TYPE_MMC, dev, env_mmc_orig_hwpart);
 #endif
 }
@@ -223,10 +239,6 @@ void env_relocate_spec(void)
        ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
        ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env2, 1);
 
-#ifdef CONFIG_SPL_BUILD
-       dev = 0;
-#endif
-
        mmc = find_mmc_device(dev);
 
        errmsg = init_mmc_for_env(mmc);
@@ -306,10 +318,6 @@ void env_relocate_spec(void)
        int dev = mmc_get_env_dev();
        const char *errmsg;
 
-#ifdef CONFIG_SPL_BUILD
-       dev = 0;
-#endif
-
        mmc = find_mmc_device(dev);
 
        errmsg = init_mmc_for_env(mmc);