Commit f8b8a554633f61c3a3e8dde3236917372edc977f

Authored by Philipp Tomsich
Committed by Jaehoon Chung
1 parent 6183b29559

env_mmc: configure environment offsets via device tree

This introduces the ability to override the environment offets from the
device tree by setting the following nodes in '/config':
	'u-boot,mmc-env-offset' - overrides CONFIG_ENV_OFFSET
	'u-boot,mmc-env-offset-redundant'
				- overrides CONFIG_ENV_OFFSET_REDUND

To keep with the previous logic, the CONFIG_* defines still need to
be available and the statically defined values become the defaults,
when the corresponding properties are not set in the device-tree.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 27 additions and 4 deletions Side-by-side Diff

... ... @@ -10,6 +10,7 @@
10 10  
11 11 #include <command.h>
12 12 #include <environment.h>
  13 +#include <fdtdec.h>
13 14 #include <linux/stddef.h>
14 15 #include <malloc.h>
15 16 #include <memalign.h>
16 17  
17 18  
18 19  
... ... @@ -36,15 +37,37 @@
36 37 #define CONFIG_ENV_OFFSET 0
37 38 #endif
38 39  
39   -__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
  40 +#if CONFIG_IS_ENABLED(OF_CONTROL)
  41 +static inline s64 mmc_offset(int copy)
40 42 {
41   - s64 offset;
  43 + const char *propname = "u-boot,mmc-env-offset";
  44 + s64 defvalue = CONFIG_ENV_OFFSET;
42 45  
43   - offset = CONFIG_ENV_OFFSET;
44   -#ifdef CONFIG_ENV_OFFSET_REDUND
  46 +#if defined(CONFIG_ENV_OFFSET_REDUND)
  47 + if (copy) {
  48 + propname = "u-boot,mmc-env-offset-redundant";
  49 + defvalue = CONFIG_ENV_OFFSET_REDUND;
  50 + }
  51 +#endif
  52 +
  53 + return fdtdec_get_config_int(gd->fdt_blob, propname, defvalue);
  54 +}
  55 +#else
  56 +static inline s64 mmc_offset(int copy)
  57 +{
  58 + s64 offset = CONFIG_ENV_OFFSET;
  59 +
  60 +#if defined(CONFIG_ENV_OFFSET_REDUND)
45 61 if (copy)
46 62 offset = CONFIG_ENV_OFFSET_REDUND;
47 63 #endif
  64 + return offset;
  65 +}
  66 +#endif
  67 +
  68 +__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
  69 +{
  70 + s64 offset = mmc_offset(copy);
48 71  
49 72 if (offset < 0)
50 73 offset += mmc->capacity;