DECLARE_GLOBAL_DATA_PTR;
-/*
- * In case the environment is redundant, stored in eMMC hardware boot
- * partition and the environment and redundant environment offsets are
- * identical, store the environment and redundant environment in both
- * eMMC boot partitions, one copy in each.
- * */
-#if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \
- (CONFIG_SYS_MMC_ENV_PART == 1) && \
- (CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND))
-#define ENV_MMC_HWPART_REDUND 1
-#endif
-
#if CONFIG_IS_ENABLED(OF_CONTROL)
static int mmc_env_partition_by_name(struct blk_desc *desc, const char *str,
}
#endif
+static bool __maybe_unused mmc_env_is_redundant_in_both_boot_hwparts(struct mmc *mmc)
+{
+ /*
+ * In case the environment is redundant, stored in eMMC hardware boot
+ * partition and the environment and redundant environment offsets are
+ * identical, store the environment and redundant environment in both
+ * eMMC boot partitions, one copy in each.
+ */
+ if (!IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
+ return false;
+
+ if (CONFIG_SYS_MMC_ENV_PART != 1)
+ return false;
+
+ return mmc_offset(mmc, 0) == mmc_offset(mmc, 1);
+}
+
__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
{
s64 offset = mmc_offset(mmc, copy);
if (gd->env_valid == ENV_VALID)
copy = 1;
- if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
ret = mmc_set_env_part(mmc, copy + 1);
if (ret)
goto fini;
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
copy = 1;
- if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
ret = mmc_set_env_part(mmc, copy + 1);
if (ret)
goto fini;
goto fini;
}
- if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
ret = mmc_set_env_part(mmc, 1);
if (ret)
goto fini;
read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
- if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
+ if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
ret = mmc_set_env_part(mmc, 2);
if (ret)
goto fini;