* [PATCH 1/2] mmc: fix error message for unaligned erase request
@ 2022-02-15 15:23 ` Patrick Delaunay
2022-02-15 15:23 ` [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size Patrick Delaunay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Patrick Delaunay @ 2022-02-15 15:23 UTC (permalink / raw)
To: u-boot; +Cc: Patrick Delaunay, Jaehoon Chung, Peng Fan, U-Boot STM32
Fix the end address in the message for unaligned erase request in
mmc_berase() when start + blkcnt is aligned to erase_grp_size.
for example:
- start = 0x2000 - 26
- count = 26
- erase_grp_size = 0x400
Caution! Your devices Erase group is 0x400
The erase range would be change to 0x2000~0x27ff
But no issue when the end address is not aligned, for example
- start = 0x2000 - 2 * 26
- count = 26
- erase_grp_size = 0x400
Caution! Your devices Erase group is 0x400
The erase range would be change to 0x2000~0x23ff
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
drivers/mmc/mmc_write.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index d23b7d9729..eab94c7b60 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -102,7 +102,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)
"The erase range would be change to "
"0x" LBAF "~0x" LBAF "\n\n",
mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),
- ((start + blkcnt + mmc->erase_grp_size)
+ ((start + blkcnt + mmc->erase_grp_size - 1)
& ~(mmc->erase_grp_size - 1)) - 1);
while (blk < blkcnt) {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size
2022-02-15 15:23 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Patrick Delaunay
@ 2022-02-15 15:23 ` Patrick Delaunay
2022-03-23 8:49 ` [Uboot-stm32] " Patrice CHOTARD
2022-03-16 7:51 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Jaehoon Chung
2022-03-23 8:43 ` [Uboot-stm32] " Patrice CHOTARD
2 siblings, 1 reply; 5+ messages in thread
From: Patrick Delaunay @ 2022-02-15 15:23 UTC (permalink / raw)
To: u-boot; +Cc: Patrick Delaunay, Joe Hershberger, Wolfgang Denk, U-Boot STM32
On eMMC device, the erase_grp_size > 1 so the address and size for the
erase block command in env/mmc.c 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 doesn't change as erase_grp_size = 1 for SD-Card.
For example, on eMMC present on STM32MP15C-EV1 and 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>
---
env/mmc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/env/mmc.c b/env/mmc.c
index 465b104559..0c498d9a46 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -257,12 +257,15 @@ static inline int erase_env(struct mmc *mmc, unsigned long size,
{
uint blk_start, blk_cnt, n;
struct blk_desc *desc = mmc_get_blk_desc(mmc);
+ u32 erase_size;
- blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
- blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
+ erase_size = mmc->erase_grp_size * desc->blksz;
+ 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);
- 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;
}
@@ -286,6 +289,7 @@ static int env_mmc_erase(void)
goto fini;
}
+ printf("\n");
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
#ifdef CONFIG_ENV_OFFSET_REDUND
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] mmc: fix error message for unaligned erase request
2022-02-15 15:23 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Patrick Delaunay
2022-02-15 15:23 ` [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size Patrick Delaunay
@ 2022-03-16 7:51 ` Jaehoon Chung
2022-03-23 8:43 ` [Uboot-stm32] " Patrice CHOTARD
2 siblings, 0 replies; 5+ messages in thread
From: Jaehoon Chung @ 2022-03-16 7:51 UTC (permalink / raw)
To: Patrick Delaunay, u-boot; +Cc: Peng Fan, U-Boot STM32
On 2/16/22 00:23, Patrick Delaunay wrote:
> Fix the end address in the message for unaligned erase request in
> mmc_berase() when start + blkcnt is aligned to erase_grp_size.
>
> for example:
> - start = 0x2000 - 26
> - count = 26
> - erase_grp_size = 0x400
>
> Caution! Your devices Erase group is 0x400
> The erase range would be change to 0x2000~0x27ff
>
> But no issue when the end address is not aligned, for example
> - start = 0x2000 - 2 * 26
> - count = 26
> - erase_grp_size = 0x400
>
> Caution! Your devices Erase group is 0x400
> The erase range would be change to 0x2000~0x23ff
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Best Regards,
Jaehoon Chung
> ---
>
> drivers/mmc/mmc_write.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
> index d23b7d9729..eab94c7b60 100644
> --- a/drivers/mmc/mmc_write.c
> +++ b/drivers/mmc/mmc_write.c
> @@ -102,7 +102,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)
> "The erase range would be change to "
> "0x" LBAF "~0x" LBAF "\n\n",
> mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),
> - ((start + blkcnt + mmc->erase_grp_size)
> + ((start + blkcnt + mmc->erase_grp_size - 1)
> & ~(mmc->erase_grp_size - 1)) - 1);
>
> while (blk < blkcnt) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Uboot-stm32] [PATCH 1/2] mmc: fix error message for unaligned erase request
2022-02-15 15:23 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Patrick Delaunay
2022-02-15 15:23 ` [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size Patrick Delaunay
2022-03-16 7:51 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Jaehoon Chung
@ 2022-03-23 8:43 ` Patrice CHOTARD
2 siblings, 0 replies; 5+ messages in thread
From: Patrice CHOTARD @ 2022-03-23 8:43 UTC (permalink / raw)
To: Patrick Delaunay, u-boot; +Cc: Jaehoon Chung, Peng Fan, U-Boot STM32
Hi Patrick
On 2/15/22 16:23, Patrick Delaunay wrote:
> Fix the end address in the message for unaligned erase request in
> mmc_berase() when start + blkcnt is aligned to erase_grp_size.
>
> for example:
> - start = 0x2000 - 26
> - count = 26
> - erase_grp_size = 0x400
>
> Caution! Your devices Erase group is 0x400
> The erase range would be change to 0x2000~0x27ff
>
> But no issue when the end address is not aligned, for example
> - start = 0x2000 - 2 * 26
> - count = 26
> - erase_grp_size = 0x400
>
> Caution! Your devices Erase group is 0x400
> The erase range would be change to 0x2000~0x23ff
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> drivers/mmc/mmc_write.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
> index d23b7d9729..eab94c7b60 100644
> --- a/drivers/mmc/mmc_write.c
> +++ b/drivers/mmc/mmc_write.c
> @@ -102,7 +102,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)
> "The erase range would be change to "
> "0x" LBAF "~0x" LBAF "\n\n",
> mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),
> - ((start + blkcnt + mmc->erase_grp_size)
> + ((start + blkcnt + mmc->erase_grp_size - 1)
> & ~(mmc->erase_grp_size - 1)) - 1);
>
> while (blk < blkcnt) {
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Uboot-stm32] [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size
2022-02-15 15:23 ` [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size Patrick Delaunay
@ 2022-03-23 8:49 ` Patrice CHOTARD
0 siblings, 0 replies; 5+ messages in thread
From: Patrice CHOTARD @ 2022-03-23 8:49 UTC (permalink / raw)
To: Patrick Delaunay, u-boot; +Cc: Joe Hershberger, U-Boot STM32, Wolfgang Denk
Hi Patrick
On 2/15/22 16:23, Patrick Delaunay wrote:
> On eMMC device, the erase_grp_size > 1 so the address and size for the
> erase block command in env/mmc.c 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 doesn't change as erase_grp_size = 1 for SD-Card.
>
> For example, on eMMC present on STM32MP15C-EV1 and 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>
> ---
>
> env/mmc.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/env/mmc.c b/env/mmc.c
> index 465b104559..0c498d9a46 100644
> --- a/env/mmc.c
> +++ b/env/mmc.c
> @@ -257,12 +257,15 @@ static inline int erase_env(struct mmc *mmc, unsigned long size,
> {
> uint blk_start, blk_cnt, n;
> struct blk_desc *desc = mmc_get_blk_desc(mmc);
> + u32 erase_size;
>
> - blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
> - blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
> + erase_size = mmc->erase_grp_size * desc->blksz;
> + 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);
> - 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;
> }
> @@ -286,6 +289,7 @@ static int env_mmc_erase(void)
> goto fini;
> }
>
> + printf("\n");
> ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
>
> #ifdef CONFIG_ENV_OFFSET_REDUND
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-23 8:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20220215152338epcas1p2880ad243ab3e035ec077670cce6476ca@epcas1p2.samsung.com>
2022-02-15 15:23 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Patrick Delaunay
2022-02-15 15:23 ` [PATCH 2/2] env: mmc : align erase address and size on erase_grp_size Patrick Delaunay
2022-03-23 8:49 ` [Uboot-stm32] " Patrice CHOTARD
2022-03-16 7:51 ` [PATCH 1/2] mmc: fix error message for unaligned erase request Jaehoon Chung
2022-03-23 8:43 ` [Uboot-stm32] " Patrice CHOTARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).