* [PATCH] cmd: mtd: check if a block has to be skipped or erased
@ 2022-10-21 15:29 Dario Binacchi
2022-10-24 6:04 ` Mikhail Kshevetskiy
2022-10-24 9:12 ` Mikhail Kshevetskiy
0 siblings, 2 replies; 3+ messages in thread
From: Dario Binacchi @ 2022-10-21 15:29 UTC (permalink / raw)
To: u-boot
Cc: Amarula patchwork, Tom Rini, Jagan Teki, Mikhail Kshevetskiy,
Dario Binacchi, Michael Trimarchi
As reported by patch [1], the `mtd erase' command should not erase bad
blocks.
To force bad block erasing you have to use the `mtd erase.dontskipbad'
command.
This patch tries to fix the same issue without modifying code taken
from the linux kernel, in order to make further upgrades easier.
[1] https://lore.kernel.org/all/20221006031501.110290-2-mikhail.kshevetskiy@iopsys.eu/
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Suggested-by: Michael Trimarchi <michael@amarulasolutions.com>
Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Cc: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
cmd/mtd.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/cmd/mtd.c b/cmd/mtd.c
index ad5cc9827d55..3330a428c018 100644
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -434,19 +434,31 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
erase_op.mtd = mtd;
erase_op.addr = off;
erase_op.len = mtd->erasesize;
- erase_op.scrub = scrub;
while (len) {
- ret = mtd_erase(mtd, &erase_op);
+ if (!scrub) {
+ ret = mtd_block_isbad(mtd, erase_op.addr);
+ if (ret < 0) {
+ printf("Failed to get bad block at 0x%08llx\n",
+ erase_op.addr);
+ ret = CMD_RET_FAILURE;
+ goto out_put_mtd;
+ }
- if (ret) {
- /* Abort if its not a bad block error */
- if (ret != -EIO)
- break;
- printf("Skipping bad block at 0x%08llx\n",
- erase_op.addr);
+ if (ret > 0) {
+ printf("Skipping bad block at 0x%08llx\n",
+ erase_op.addr);
+ ret = 0;
+ len -= mtd->erasesize;
+ erase_op.addr += mtd->erasesize;
+ continue;
+ }
}
+ ret = mtd_erase(mtd, &erase_op);
+ if (ret)
+ break;
+
len -= mtd->erasesize;
erase_op.addr += mtd->erasesize;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cmd: mtd: check if a block has to be skipped or erased
2022-10-21 15:29 [PATCH] cmd: mtd: check if a block has to be skipped or erased Dario Binacchi
@ 2022-10-24 6:04 ` Mikhail Kshevetskiy
2022-10-24 9:12 ` Mikhail Kshevetskiy
1 sibling, 0 replies; 3+ messages in thread
From: Mikhail Kshevetskiy @ 2022-10-24 6:04 UTC (permalink / raw)
To: Dario Binacchi, u-boot
Cc: Amarula patchwork, Tom Rini, Jagan Teki, Michael Trimarchi
On 21.10.2022 18:29, Dario Binacchi wrote:
> [External email]
>
>
>
>
>
> As reported by patch [1], the `mtd erase' command should not erase bad
> blocks.
> To force bad block erasing you have to use the `mtd erase.dontskipbad'
> command.
>
> This patch tries to fix the same issue without modifying code taken
> from the linux kernel, in order to make further upgrades easier.
>
> [1] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C914960325cd74fb7338208dab37913e4%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638019629853388501%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6WBTjvbfll%2Boiz5B8q0o%2Bec0bWKCBf5RimWU1hZe61E%3D&reserved=0
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> Suggested-by: Michael Trimarchi <michael@amarulasolutions.com>
> Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
> Cc: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>
> ---
>
> cmd/mtd.c | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> index ad5cc9827d55..3330a428c018 100644
> --- a/cmd/mtd.c
> +++ b/cmd/mtd.c
> @@ -434,19 +434,31 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
> erase_op.mtd = mtd;
> erase_op.addr = off;
> erase_op.len = mtd->erasesize;
> - erase_op.scrub = scrub;
>
> while (len) {
> - ret = mtd_erase(mtd, &erase_op);
> + if (!scrub) {
> + ret = mtd_block_isbad(mtd, erase_op.addr);
> + if (ret < 0) {
> + printf("Failed to get bad block at 0x%08llx\n",
> + erase_op.addr);
> + ret = CMD_RET_FAILURE;
> + goto out_put_mtd;
> + }
>
> - if (ret) {
> - /* Abort if its not a bad block error */
> - if (ret != -EIO)
> - break;
> - printf("Skipping bad block at 0x%08llx\n",
> - erase_op.addr);
> + if (ret > 0) {
> + printf("Skipping bad block at 0x%08llx\n",
> + erase_op.addr);
> + ret = 0;
> + len -= mtd->erasesize;
> + erase_op.addr += mtd->erasesize;
> + continue;
> + }
> }
>
> + ret = mtd_erase(mtd, &erase_op);
> + if (ret)
> + break;
> +
You should check for bad block here, otherwise bad block not marked in
BBT will terminate erasing with CMD_RET_SUCCESS result.
> len -= mtd->erasesize;
> erase_op.addr += mtd->erasesize;
> }
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cmd: mtd: check if a block has to be skipped or erased
2022-10-21 15:29 [PATCH] cmd: mtd: check if a block has to be skipped or erased Dario Binacchi
2022-10-24 6:04 ` Mikhail Kshevetskiy
@ 2022-10-24 9:12 ` Mikhail Kshevetskiy
1 sibling, 0 replies; 3+ messages in thread
From: Mikhail Kshevetskiy @ 2022-10-24 9:12 UTC (permalink / raw)
To: Dario Binacchi, u-boot
Cc: Amarula patchwork, Tom Rini, Jagan Teki, Michael Trimarchi
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
On 21.10.2022 18:29, Dario Binacchi wrote:
> [External email]
>
>
>
>
>
> As reported by patch [1], the `mtd erase' command should not erase bad
> blocks.
> To force bad block erasing you have to use the `mtd erase.dontskipbad'
> command.
>
> This patch tries to fix the same issue without modifying code taken
> from the linux kernel, in order to make further upgrades easier.
>
> [1] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C914960325cd74fb7338208dab37913e4%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638019629853388501%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6WBTjvbfll%2Boiz5B8q0o%2Bec0bWKCBf5RimWU1hZe61E%3D&reserved=0
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> Suggested-by: Michael Trimarchi <michael@amarulasolutions.com>
> Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
> Cc: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>
> ---
>
> cmd/mtd.c | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> index ad5cc9827d55..3330a428c018 100644
> --- a/cmd/mtd.c
> +++ b/cmd/mtd.c
> @@ -434,19 +434,31 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
> erase_op.mtd = mtd;
> erase_op.addr = off;
> erase_op.len = mtd->erasesize;
> - erase_op.scrub = scrub;
>
> while (len) {
> - ret = mtd_erase(mtd, &erase_op);
> + if (!scrub) {
> + ret = mtd_block_isbad(mtd, erase_op.addr);
> + if (ret < 0) {
> + printf("Failed to get bad block at 0x%08llx\n",
> + erase_op.addr);
> + ret = CMD_RET_FAILURE;
> + goto out_put_mtd;
> + }
>
> - if (ret) {
> - /* Abort if its not a bad block error */
> - if (ret != -EIO)
> - break;
> - printf("Skipping bad block at 0x%08llx\n",
> - erase_op.addr);
> + if (ret > 0) {
> + printf("Skipping bad block at 0x%08llx\n",
> + erase_op.addr);
> + ret = 0;
> + len -= mtd->erasesize;
> + erase_op.addr += mtd->erasesize;
> + continue;
> + }
> }
>
> + ret = mtd_erase(mtd, &erase_op);
> + if (ret)
> + break;
> +
> len -= mtd->erasesize;
> erase_op.addr += mtd->erasesize;
> }
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-24 11:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 15:29 [PATCH] cmd: mtd: check if a block has to be skipped or erased Dario Binacchi
2022-10-24 6:04 ` Mikhail Kshevetskiy
2022-10-24 9:12 ` Mikhail Kshevetskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.