env: mmc: introduced ENV_MMC_OFFSET

Introduce ENV_MMC_OFFSET defines.
It is a preliminary step to the next patches to simplify the code.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
This commit is contained in:
Patrick Delaunay 2022-11-10 11:48:58 +01:00 committed by Tom Rini
parent 7b84c973b9
commit f7e07a7ef4

24
env/mmc.c vendored
View File

@ -24,6 +24,17 @@
#define __STR(X) #X #define __STR(X) #X
#define STR(X) __STR(X) #define STR(X) __STR(X)
#define ENV_MMC_INVALID_OFFSET ((s64)-1)
/* Default ENV offset when not defined in Device Tree */
#define ENV_MMC_OFFSET CONFIG_ENV_OFFSET
#if defined(CONFIG_ENV_OFFSET_REDUND)
#define ENV_MMC_OFFSET_REDUND CONFIG_ENV_OFFSET_REDUND
#else
#define ENV_MMC_OFFSET_REDUND ENV_MMC_INVALID_OFFSET
#endif
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
/* /*
@ -94,12 +105,12 @@ static inline s64 mmc_offset(int copy)
return val; return val;
} }
defvalue = CONFIG_ENV_OFFSET; defvalue = ENV_MMC_OFFSET;
propname = dt_prop.offset; propname = dt_prop.offset;
#if defined(CONFIG_ENV_OFFSET_REDUND) #if defined(CONFIG_ENV_OFFSET_REDUND)
if (copy) { if (copy) {
defvalue = CONFIG_ENV_OFFSET_REDUND; defvalue = ENV_MMC_OFFSET_REDUND;
propname = dt_prop.offset_redund; propname = dt_prop.offset_redund;
} }
#endif #endif
@ -108,11 +119,11 @@ static inline s64 mmc_offset(int copy)
#else #else
static inline s64 mmc_offset(int copy) static inline s64 mmc_offset(int copy)
{ {
s64 offset = CONFIG_ENV_OFFSET; s64 offset = ENV_MMC_OFFSET;
#if defined(CONFIG_ENV_OFFSET_REDUND) #if defined(CONFIG_ENV_OFFSET_REDUND)
if (copy) if (copy)
offset = CONFIG_ENV_OFFSET_REDUND; offset = ENV_MMC_OFFSET_REDUND;
#endif #endif
return offset; return offset;
} }
@ -122,6 +133,11 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
{ {
s64 offset = mmc_offset(copy); s64 offset = mmc_offset(copy);
if (offset == ENV_MMC_INVALID_OFFSET) {
printf("Invalid ENV offset in MMC, copy=%d\n", copy);
return -ENOENT;
}
if (offset < 0) if (offset < 0)
offset += mmc->capacity; offset += mmc->capacity;