Commit 5c088ee841f9c660a3e62887e7b8623fc15dcd68

Authored by Stephen Warren
Committed by Andy Fleming
1 parent f866a46d6e

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 <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

Showing 2 changed files with 21 additions and 2 deletions Side-by-side Diff

... ... @@ -3666,6 +3666,14 @@
3666 3666 These two #defines specify the offset and size of the environment
3667 3667 area within the specified MMC device.
3668 3668  
  3669 + If offset is positive (the usual case), it is treated as relative to
  3670 + the start of the MMC partition. If offset is negative, it is treated
  3671 + as relative to the end of the MMC partition. This can be useful if
  3672 + your board may be fitted with different MMC devices, which have
  3673 + different sizes for the MMC partitions, and you always want the
  3674 + environment placed at the very end of the partition, to leave the
  3675 + maximum possible space before it, to store other data.
  3676 +
3669 3677 These two values are in units of bytes, but must be aligned to an
3670 3678 MMC sector boundary.
3671 3679  
... ... @@ -3675,6 +3683,9 @@
3675 3683 hold a redundant copy of the environment data. This provides a
3676 3684 valid backup copy in case the other copy is corrupted, e.g. due
3677 3685 to a power failure during a "saveenv" operation.
  3686 +
  3687 + This value may also be positive or negative; this is handled in the
  3688 + same way as CONFIG_ENV_OFFSET.
3678 3689  
3679 3690 This value is also in units of bytes, but must also be aligned to
3680 3691 an MMC sector boundary.
... ... @@ -53,11 +53,19 @@
53 53  
54 54 __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
55 55 {
56   - *env_addr = CONFIG_ENV_OFFSET;
  56 + s64 offset;
  57 +
  58 + offset = CONFIG_ENV_OFFSET;
57 59 #ifdef CONFIG_ENV_OFFSET_REDUND
58 60 if (copy)
59   - *env_addr = CONFIG_ENV_OFFSET_REDUND;
  61 + offset = CONFIG_ENV_OFFSET_REDUND;
60 62 #endif
  63 +
  64 + if (offset < 0)
  65 + offset += mmc->capacity;
  66 +
  67 + *env_addr = offset;
  68 +
61 69 return 0;
62 70 }
63 71