]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
env_mmc: allow negative CONFIG_ENV_OFFSET
authorStephen Warren <swarren@nvidia.com>
Tue, 11 Jun 2013 21:14:02 +0000 (15:14 -0600)
committerAndy Fleming <afleming@freescale.com>
Thu, 13 Jun 2013 21:52:20 +0000 (16:52 -0500)
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 <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
README
common/env_mmc.c

diff --git a/README b/README
index f1485bac133376ba3feddc409075cfab258f7a74..6852080c4349bee851f643ad2b29cb6479d6013e 100644 (file)
--- a/README
+++ b/README
@@ -3666,6 +3666,14 @@ but it can not erase, write this NOR flash by SRIO or PCIE interface.
          These two #defines specify the offset and size of the environment
          area within the specified MMC device.
 
+         If offset is positive (the usual case), it is treated as relative to
+         the start of the MMC partition. If offset is negative, it is treated
+         as relative to the end of the MMC partition. This can be useful if
+         your board may be fitted with different MMC devices, which have
+         different sizes for the MMC partitions, and you always want the
+         environment placed at the very end of the partition, to leave the
+         maximum possible space before it, to store other data.
+
          These two values are in units of bytes, but must be aligned to an
          MMC sector boundary.
 
@@ -3676,6 +3684,9 @@ but it can not erase, write this NOR flash by SRIO or PCIE interface.
          valid backup copy in case the other copy is corrupted, e.g. due
          to a power failure during a "saveenv" operation.
 
+         This value may also be positive or negative; this is handled in the
+         same way as CONFIG_ENV_OFFSET.
+
          This value is also in units of bytes, but must also be aligned to
          an MMC sector boundary.
 
index 9ca098fa674dbb56911ed1ab3517152d6db84f3c..5d3a769db0e94ae05912568a3edd2c88b8be36b1 100644 (file)
@@ -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;
 }