cmd: mtd: check if a block has to be skipped or erased
PATCH 1/1 cmd: mtd: check if a block has to be skipped or erased
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/[email protected]/
---
cmd/mtd.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
cmd/mtd.c +20 -8
@@ -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; }
Signature · 1 line
2.32.0
Quoted 57 lines · Dario Binacchi
[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.
Signed-off-by Dario Binacchi <[email protected]>Suggested-by Michael Trimarchi <[email protected]>Co-developed-by Michael Trimarchi <[email protected]>Signed-off-by Michael Trimarchi <[email protected]>Cc Mikhail Kshevetskiy <[email protected]>---
cmd/mtd.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)cmd/mtd.c +12
-8@@ -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 ;
cmd/mtd.c static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc, · line 461
Quoted 10 lines
cmd/mtd.c +8
-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.
Quoted 6 lines
cmd/mtd.c +0
-1len -= mtd->erasesize; erase_op.addr += mtd->erasesize; } --2.32.0
Quoted 73 lines · Dario Binacchi
[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.
Signed-off-by Dario Binacchi <[email protected]>Suggested-by Michael Trimarchi <[email protected]>Co-developed-by Michael Trimarchi <[email protected]>Signed-off-by Michael Trimarchi <[email protected]>Cc Mikhail Kshevetskiy <[email protected]>---
cmd/mtd.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)cmd/mtd.c +20
-9@@ -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