env: mmc : align erase address and size on erase_grp_size
On eMMC, the erase_grp_size > 1 so the address and size for the erase block command can be unaligned on erase group size and some strange trace occurs and the result is not guarantee by MMC devices. The SD-Card behavior don't change as erase_grp_size = 1 for SD-Card. For example, on eMMC present on STM32MP15C-EV1, before the patch: STM32MP> env erase Erasing Environment on MMC... Caution! Your devices Erase group is 0x400 The erase range would be change to 0x2000~0x27ff 16 blocks erased: OK Caution! Your devices Erase group is 0x400 The erase range would be change to 0x2000~0x23ff 16 blocks erased: OK OK After this patch: STM32MP> env erase Erasing Environment on MMC... 1024 blocks erased at 0x2000: OK 1024 blocks erased at 0x2000: OK OK Here the 2 copies of U-Boot environment are in the same devices Erase group: it is erased twice. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Change-Id: I26fa615c6898db0d17024664b17b20412638bfd7 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/238836 Reviewed-by: CITOOLS <MDG-smet-aci-reviews@list.st.com> Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com>
This commit is contained in:
committed by
Patrice Chotard
parent
cd3d4a9d1f
commit
010f0e12ba
10
env/mmc.c
vendored
10
env/mmc.c
vendored
@ -238,12 +238,15 @@ static inline int erase_env(struct mmc *mmc, unsigned long size,
|
|||||||
{
|
{
|
||||||
uint blk_start, blk_cnt, n;
|
uint blk_start, blk_cnt, n;
|
||||||
struct blk_desc *desc = mmc_get_blk_desc(mmc);
|
struct blk_desc *desc = mmc_get_blk_desc(mmc);
|
||||||
|
u32 erase_size;
|
||||||
|
|
||||||
blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
|
erase_size = mmc->erase_grp_size * desc->blksz;
|
||||||
blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
|
blk_start = ALIGN_DOWN(offset, erase_size) / desc->blksz;
|
||||||
|
blk_cnt = ALIGN(size, erase_size) / desc->blksz;
|
||||||
|
|
||||||
n = blk_derase(desc, blk_start, blk_cnt);
|
n = blk_derase(desc, blk_start, blk_cnt);
|
||||||
printf("%d blocks erased: %s\n", n, (n == blk_cnt) ? "OK" : "ERROR");
|
printf("%d blocks erased at 0x%x: %s\n", n, blk_start,
|
||||||
|
(n == blk_cnt) ? "OK" : "ERROR");
|
||||||
|
|
||||||
return (n == blk_cnt) ? 0 : 1;
|
return (n == blk_cnt) ? 0 : 1;
|
||||||
}
|
}
|
||||||
@ -265,6 +268,7 @@ static int env_mmc_erase(void)
|
|||||||
if (mmc_get_env_addr(mmc, copy, &offset))
|
if (mmc_get_env_addr(mmc, copy, &offset))
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
|
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
|
||||||
|
|
||||||
#ifdef CONFIG_ENV_OFFSET_REDUND
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
||||||
|
|||||||
Reference in New Issue
Block a user