#if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \
(CONFIG_SYS_MMC_ENV_PART == 1) && \
(CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND))
-#define ENV_MMC_HWPART_REDUND
+#define ENV_MMC_HWPART_REDUND 1
#endif
#if CONFIG_IS_ENABLED(OF_CONTROL)
defvalue = ENV_MMC_OFFSET;
propname = dt_prop.offset;
-#if defined(CONFIG_ENV_OFFSET_REDUND)
- if (copy) {
+ if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && copy) {
defvalue = ENV_MMC_OFFSET_REDUND;
propname = dt_prop.offset_redund;
}
-#endif
+
return ofnode_conf_read_int(propname, defvalue);
}
#else
{
s64 offset = ENV_MMC_OFFSET;
-#if defined(CONFIG_ENV_OFFSET_REDUND)
- if (copy)
+ if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && copy)
offset = ENV_MMC_OFFSET_REDUND;
-#endif
+
return offset;
}
#endif
return ret;
}
+
+static bool mmc_set_env_part_init(struct mmc *mmc)
+{
+ env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
+ if (mmc_set_env_part(mmc, mmc_get_env_part(mmc)))
+ return false;
+
+ return true;
+}
+
+static int mmc_set_env_part_restore(struct mmc *mmc)
+{
+ return mmc_set_env_part(mmc, env_mmc_orig_hwpart);
+}
#else
static inline int mmc_set_env_part(struct mmc *mmc, uint part) {return 0; };
+static bool mmc_set_env_part_init(struct mmc *mmc) {return true; }
+static inline int mmc_set_env_part_restore(struct mmc *mmc) {return 0; };
#endif
static const char *init_mmc_for_env(struct mmc *mmc)
if (mmc_init(mmc))
return "MMC init failed";
#endif
- env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
- if (mmc_set_env_part(mmc, mmc_get_env_part(mmc)))
+ if (!mmc_set_env_part_init(mmc))
return "MMC partition switch failed";
return NULL;
static void fini_mmc_for_env(struct mmc *mmc)
{
-#ifdef CONFIG_SYS_MMC_ENV_PART
- int dev = mmc_get_env_dev();
-
- blk_select_hwpart_devnum(UCLASS_MMC, dev, env_mmc_orig_hwpart);
-#endif
+ mmc_set_env_part_restore(mmc);
}
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
if (ret)
goto fini;
-#ifdef CONFIG_ENV_OFFSET_REDUND
- if (gd->env_valid == ENV_VALID)
- copy = 1;
-
-#ifdef ENV_MMC_HWPART_REDUND
- ret = mmc_set_env_part(mmc, copy + 1);
- if (ret)
- goto fini;
-#endif
+ if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
+ if (gd->env_valid == ENV_VALID)
+ copy = 1;
-#endif
+ if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ ret = mmc_set_env_part(mmc, copy + 1);
+ if (ret)
+ goto fini;
+ }
- if (mmc_get_env_addr(mmc, copy, &offset)) {
- ret = 1;
- goto fini;
+ if (mmc_get_env_addr(mmc, copy, &offset)) {
+ ret = 1;
+ goto fini;
+ }
}
printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev);
ret = 0;
-#ifdef CONFIG_ENV_OFFSET_REDUND
- gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
-#endif
+ if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
+ gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
fini:
fini_mmc_for_env(mmc);
+
return ret;
}
printf("\n");
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
-#ifdef CONFIG_ENV_OFFSET_REDUND
- copy = 1;
+ if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
+ copy = 1;
-#ifdef ENV_MMC_HWPART_REDUND
- ret = mmc_set_env_part(mmc, copy + 1);
- if (ret)
- goto fini;
-#endif
+ if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ ret = mmc_set_env_part(mmc, copy + 1);
+ if (ret)
+ goto fini;
+ }
- if (mmc_get_env_addr(mmc, copy, &offset)) {
- ret = CMD_RET_FAILURE;
- goto fini;
- }
+ if (mmc_get_env_addr(mmc, copy, &offset)) {
+ ret = CMD_RET_FAILURE;
+ goto fini;
+ }
- ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
-#endif
+ ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
+ }
fini:
fini_mmc_for_env(mmc);
return (n == blk_cnt) ? 0 : -1;
}
-#ifdef CONFIG_ENV_OFFSET_REDUND
+#if defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT)
static int env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
goto fini;
}
-#ifdef ENV_MMC_HWPART_REDUND
- ret = mmc_set_env_part(mmc, 1);
- if (ret)
- goto fini;
-#endif
+ if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ ret = mmc_set_env_part(mmc, 1);
+ if (ret)
+ goto fini;
+ }
read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
-#ifdef ENV_MMC_HWPART_REDUND
- ret = mmc_set_env_part(mmc, 2);
- if (ret)
- goto fini;
-#endif
+ if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ ret = mmc_set_env_part(mmc, 2);
+ if (ret)
+ goto fini;
+ }
read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2);
#endif
return ret;
}
-#else /* ! CONFIG_ENV_OFFSET_REDUND */
+#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
static int env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
#endif
return ret;
}
-#endif /* CONFIG_ENV_OFFSET_REDUND */
+#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
U_BOOT_ENV_LOCATION(mmc) = {
.location = ENVL_MMC,