From 5c088ee841f9c660a3e62887e7b8623fc15dcd68 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 11 Jun 2013 15:14:02 -0600 Subject: env_mmc: allow negative CONFIG_ENV_OFFSET A negative value of CONFIG_ENV_OFFSET is treated as a backwards offset from the end of the eMMC device/partition, rather than a forwards offset from the start. This is useful when a single board may be stuffed with different eMMC devices, each of which has a different capacity, and you always want the environment to be stored at the very end of the device (or eMMC boot partition for example). One example of this case is NVIDIA's Ventana reference board. Signed-off-by: Stephen Warren Signed-off-by: Andy Fleming --- common/env_mmc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/env_mmc.c b/common/env_mmc.c index 9ca098fa674..5d3a769db0e 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -53,11 +53,19 @@ DECLARE_GLOBAL_DATA_PTR; __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr) { - *env_addr = CONFIG_ENV_OFFSET; + s64 offset; + + offset = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND if (copy) - *env_addr = CONFIG_ENV_OFFSET_REDUND; + offset = CONFIG_ENV_OFFSET_REDUND; #endif + + if (offset < 0) + offset += mmc->capacity; + + *env_addr = offset; + return 0; } -- cgit v1.2.3