diff mbox series

[3/3] env: mmc: add redundancy support in mmc_offset_try_partition

Message ID 20200319105917.3.I3f39ef337e2318d7c857e0458d5bc66e374dfaba@changeid
State Superseded
Delegated to: Joe Hershberger
Headers show
Series [1/3] env: mmc: allow support of mmc_get_env_dev with OF_CONTROL | expand

Commit Message

Patrick DELAUNAY March 19, 2020, 9:59 a.m. UTC
Manage 2 copy at the end of the partition selected by config
"u-boot,mmc-env-partition" to save the U-Boot environment,
with CONFIG_ENV_SIZE and 2*CONFIG_ENV_SIZE offset.

This patch allows to support redundancy (CONFIG_ENV_OFFSET_REDUND).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 env/mmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Patrice CHOTARD April 17, 2020, 12:38 p.m. UTC | #1
Hi

On 3/19/20 10:59 AM, Patrick Delaunay wrote:
> Manage 2 copy at the end of the partition selected by config
> "u-boot,mmc-env-partition" to save the U-Boot environment,
> with CONFIG_ENV_SIZE and 2*CONFIG_ENV_SIZE offset.
>
> This patch allows to support redundancy (CONFIG_ENV_OFFSET_REDUND).
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  env/mmc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/env/mmc.c b/env/mmc.c
> index c24b169f3e..677a3d4668 100644
> --- a/env/mmc.c
> +++ b/env/mmc.c
> @@ -34,7 +34,7 @@ __weak int mmc_get_env_dev(void)
>  }
>  
>  #if CONFIG_IS_ENABLED(OF_CONTROL)
> -static inline int mmc_offset_try_partition(const char *str, s64 *val)
> +static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
>  {
>  	disk_partition_t info;
>  	struct blk_desc *desc;
> @@ -59,7 +59,7 @@ static inline int mmc_offset_try_partition(const char *str, s64 *val)
>  	len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
>  
>  	/* use the top of the partion for the environment */
> -	*val = (info.start + info.size - len) * info.blksz;
> +	*val = (info.start + info.size - (1 + copy) * len) * info.blksz;
>  
>  	return 0;
>  }
> @@ -84,7 +84,7 @@ static inline s64 mmc_offset(int copy)
>  	str = fdtdec_get_config_string(gd->fdt_blob, dt_prop.partition);
>  	if (str) {
>  		/* try to place the environment at end of the partition */
> -		err = mmc_offset_try_partition(str, &val);
> +		err = mmc_offset_try_partition(str, copy, &val);
>  		if (!err)
>  			return val;
>  	}

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks
diff mbox series

Patch

diff --git a/env/mmc.c b/env/mmc.c
index c24b169f3e..677a3d4668 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -34,7 +34,7 @@  __weak int mmc_get_env_dev(void)
 }
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-static inline int mmc_offset_try_partition(const char *str, s64 *val)
+static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 {
 	disk_partition_t info;
 	struct blk_desc *desc;
@@ -59,7 +59,7 @@  static inline int mmc_offset_try_partition(const char *str, s64 *val)
 	len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
 
 	/* use the top of the partion for the environment */
-	*val = (info.start + info.size - len) * info.blksz;
+	*val = (info.start + info.size - (1 + copy) * len) * info.blksz;
 
 	return 0;
 }
@@ -84,7 +84,7 @@  static inline s64 mmc_offset(int copy)
 	str = fdtdec_get_config_string(gd->fdt_blob, dt_prop.partition);
 	if (str) {
 		/* try to place the environment at end of the partition */
-		err = mmc_offset_try_partition(str, &val);
+		err = mmc_offset_try_partition(str, copy, &val);
 		if (!err)
 			return val;
 	}