[U-Boot] [PATCH v1] env_mmc: configure environment offsets via device tree
Igor Grinberg
grinberg at compulab.co.il
Sun Feb 19 11:52:18 UTC 2017
On 02/17/17 19:28, Philipp Tomsich wrote:
> 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.
That sounds too odd...
DT's purpose is to describe the h/w... and that does not look so...
We also, have a dt file name in the environment, so this creates will create
a chicken and an egg problem...
I really don't think we should go that direction. DT is not meant to provide
a solution to all your problems...
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich at theobroma-systems.com>
> ---
> common/env_mmc.c | 31 +++++++++++++++++++++++++++----
> 1 file changed, 27 insertions(+), 4 deletions(-)
>
> diff --git a/common/env_mmc.c b/common/env_mmc.c
> index 16f6a17..ef3dbd1 100644
> --- a/common/env_mmc.c
> +++ b/common/env_mmc.c
> @@ -1,24 +1,25 @@
> /*
> * (C) Copyright 2008-2011 Freescale Semiconductor, Inc.
> *
> * SPDX-License-Identifier: GPL-2.0+
> */
>
> /* #define DEBUG */
>
> #include <common.h>
>
> #include <command.h>
> #include <environment.h>
> +#include <fdtdec.h>
> #include <linux/stddef.h>
> #include <malloc.h>
> #include <memalign.h>
> #include <mmc.h>
> #include <search.h>
> #include <errno.h>
>
> #if defined(CONFIG_ENV_SIZE_REDUND) && \
> (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE)
> #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE
> #endif
>
> @@ -36,21 +37,43 @@ DECLARE_GLOBAL_DATA_PTR;
> #define CONFIG_ENV_OFFSET 0
> #endif
>
> -__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
> +#ifdef CONFIG_OF_LIBFDT
> +static inline s64 mmc_offset(int copy)
> {
> - s64 offset;
> + const char *propname = "u-boot,mmc-env-offset";
> + s64 defvalue = CONFIG_ENV_OFFSET;
>
> - offset = CONFIG_ENV_OFFSET;
> -#ifdef CONFIG_ENV_OFFSET_REDUND
> +#if defined(CONFIG_ENV_OFFSET_REDUND)
> + if (copy) {
> + propname = "u-boot,mmc-env-offset-redundant";
> + defvalue = CONFIG_ENV_OFFSET_REDUND;
> + }
> +#endif
> +
> + return fdtdec_get_config_int(gd->fdt_blob, propname, defvalue);
> +}
> +#else
> +static inline s64 mmc_offset(int copy)
> +{
> + s64 offset = CONFIG_ENV_OFFSET;
> +
> +#if defined(CONFIG_ENV_OFFSET_REDUND)
> if (copy)
> offset = CONFIG_ENV_OFFSET_REDUND;
> #endif
> + return offset;
> +}
> +#endif
> +
> +__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
> +{
> + s64 offset = mmc_offset(copy);
>
> if (offset < 0)
> offset += mmc->capacity;
>
> *env_addr = offset;
>
> return 0;
> }
>
>
--
Regards,
Igor.
More information about the U-Boot
mailing list