[U-Boot] [PATCH v7 2/2] env: mmc: add erase-function

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Tue Jul 9 19:26:48 UTC 2019


Am 29.06.2019 um 11:36 schrieb Frank Wunderlich:
> this adds erase environment for mmc storage
> 
> squashed fixes:
>   - add CONFIG_CMD_ERASEENV
>   - env: erase redundant offset if defined
>   - changes mentioned by Simon
>   - fix whitespaces around errmsg
> 
> Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
> Signed-off-by: Frank Wunderlich <frank-w at public-files.de>


Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>

> =2D--
>   env/mmc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 51 insertions(+)
> 
> diff --git a/env/mmc.c b/env/mmc.c
> index c3cf35d01b..b7b833f423 100644
> =2D-- a/env/mmc.c
> +++ b/env/mmc.c
> @@ -242,6 +242,54 @@ fini:
>   	fini_mmc_for_env(mmc);
>   	return ret;
>   }
> +
> +#if defined(CONFIG_CMD_ERASEENV)
> +static inline int erase_env(struct mmc *mmc, unsigned long size,
> +			    unsigned long offset)
> +{
> +	uint blk_start, blk_cnt, n;
> +	struct blk_desc *desc =3D mmc_get_blk_desc(mmc);
> +
> +	blk_start	=3D ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
> +	blk_cnt		=3D ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
> +
> +	n =3D blk_derase(desc, blk_start, blk_cnt);
> +	printf("%d blocks erased: %s\n", n, (n =3D=3D blk_cnt) ? "OK" : "ERROR")=
> ;
> +
> +	return (n =3D=3D blk_cnt) ? 0 : 1;
> +}
> +
> +static int env_mmc_erase(void)
> +{
> +	int dev =3D mmc_get_env_dev();
> +	struct mmc *mmc =3D find_mmc_device(dev);
> +	int	ret, copy =3D 0;
> +	u32	offset;
> +	const char *errmsg;
> +
> +	errmsg =3D init_mmc_for_env(mmc);
> +	if (errmsg) {
> +		printf("%s\n", errmsg);
> +		return 1;
> +	}
> +
> +	if (mmc_get_env_addr(mmc, copy, &offset))
> +		return CMD_RET_FAILURE;
> +
> +	ret =3D erase_env(mmc, CONFIG_ENV_SIZE, offset);
> +
> +#ifdef CONFIG_ENV_OFFSET_REDUND
> +	copy =3D 1;
> +
> +	if (mmc_get_env_addr(mmc, copy, &offset))
> +		return CMD_RET_FAILURE;
> +
> +	ret |=3D erase_env(mmc, CONFIG_ENV_SIZE, offset);
> +#endif
> +
> +	return ret;
> +}
> +#endif /* CONFIG_CMD_ERASEENV */
>   #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */
> 
>   static inline int read_env(struct mmc *mmc, unsigned long size,
> @@ -351,5 +399,8 @@ U_BOOT_ENV_LOCATION(mmc) =3D {
>   	.load		=3D env_mmc_load,
>   #ifndef CONFIG_SPL_BUILD
>   	.save		=3D env_save_ptr(env_mmc_save),
> +#if defined(CONFIG_CMD_ERASEENV)
> +	.erase		=3D env_mmc_erase,
> +#endif
>   #endif
>   };
> =2D-
> 2.17.1
> 



More information about the U-Boot mailing list