cmd: mtd: check if a block has to be skipped or erased
PATCH v2 1/1 cmd: mtd: check if a block has to be skipped or erased
From: Mikhail Kshevetskiy <[email protected]>
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]/
---
Changes in v2:
- Change the commit author
- Do not continue to erase if scrub option is enabled and a bad block was found but return from the function.
- Update the patch tags.
cmd/mtd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
cmd/mtd.c +15 -2
@@ -434,11 +434,24 @@ 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; + }else if (ret >0 ) { +/* simulate bad block behavior */ + ret = -EIO ; + goto skip_block_erasing; + } + } + ret =mtd_erase (mtd, &erase_op); +skip_block_erasing:if (ret) {/* Abort if its not a bad block error */ if (ret != -EIO )
Signature · 1 line
2.32.0
What patch will be finally applied? I am preparing a patch that will fix Dario Binacchi issues with non-BBT bad block.
From my point of view this patch have wrong lines in 'Changes in v2'
- Do not continue to erase if scrub option is enabled and a bad block was found but return from the function.
Issues of original Dario Binacchi patch:
Non-BBT registered bad block will break 'mtd erase'.
In this case
* mtd_erase() will returns with -EIO
* erasing will be stopped due to error
* 'mtd erase' returns CMD_RET_SUCCESS as -EIO is expected result
Fix this by:
a) return back -EIO check after mtd_erase()
b) simulate bad block behavior and jump to mtd_erase() results check in the case of BBT registered bad block.
Quoted 70 lines · Dario Binacchi
[External email]
From: Mikhail Kshevetskiy <[email protected]>
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.
Suggested-by Michael Trimarchi <[email protected]>Co-developed-by Michael Trimarchi <[email protected]>Signed-off-by Michael Trimarchi <[email protected]>Co-developed-by Dario Binacchi <[email protected]>Signed-off-by Dario Binacchi <[email protected]>Tested-by Mikhail Kshevetskiy <[email protected]>Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Changes in v2:
- Change the commit author
- Do not continue to erase if scrub option is enabled and a bad block was found but return from the function.
- Update the patch tags.cmd/mtd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)cmd/mtd.c +15
-3@@ -434,11 +434,24 @@ 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; + }else if (ret >0 ) { +/* simulate bad block behavior */ + ret = -EIO ; + goto skip_block_erasing; + } + } + ret =mtd_erase (mtd, &erase_op); +skip_block_erasing:if (ret) {/* Abort if its not a bad block error */ if (ret != -EIO ) --2.32.0
Hi,
Quoted 22 lines · Dario Binacchi
From: Mikhail Kshevetskiy <[email protected]>
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]/
Suggested-by Michael Trimarchi <[email protected]>Co-developed-by Michael Trimarchi <[email protected]>Signed-off-by Michael Trimarchi <[email protected]>Co-developed-by Dario Binacchi <[email protected]>Signed-off-by Dario Binacchi <[email protected]>Tested-by Mikhail Kshevetskiy <[email protected]>Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Quoted 8 lines
Changes in v2:
- Change the commit author
- Do not continue to erase if scrub option is enabled and a bad block was found but return from the function.
- Update the patch tags.cmd/mtd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
Can we get some tests in test/dm/mtd.c?
Regards,
Simon
Hi Simon,
Quoted 33 lines · Simon Glass
Hi,
Quoted 28 lines · Dario Binacchi
From: Mikhail Kshevetskiy <[email protected]>
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]/
Suggested-by Michael Trimarchi <[email protected]>Co-developed-by Michael Trimarchi <[email protected]>Signed-off-by Michael Trimarchi <[email protected]>Co-developed-by Dario Binacchi <[email protected]>Signed-off-by Dario Binacchi <[email protected]>Tested-by Mikhail Kshevetskiy <[email protected]>Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Changes in v2:
- Change the commit author
- Do not continue to erase if scrub option is enabled and a bad block was found but return from the function.
- Update the patch tags.
Quoted 4 lines
Quoted 2 lines
cmd/mtd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)Can we get some tests in
test/dm/mtd.c?
We are thinking about it. Probably not soon, but we are thinking about what and how to add them.
Thanks and regards,
Dario
Quoted 3 lines
Regards,
Simon
Signature · 17 lines
Dario Binacchi Embedded Linux Developer [email protected] __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 [email protected] www.amarulasolutions.com