mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
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/20221006031501.110290-2-mikhail.kshevetskiy@iopsys.eu/ Suggested-by: Michael Trimarchi <michael@amarulasolutions.com> Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com> Co-developed-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
This commit is contained in:
parent
c21b0ca525
commit
d09807ad14
1 changed files with 20 additions and 8 deletions
24
cmd/mtd.c
24
cmd/mtd.c
|
@ -434,18 +434,30 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
erase_op.mtd = mtd;
|
erase_op.mtd = mtd;
|
||||||
erase_op.addr = off;
|
erase_op.addr = off;
|
||||||
erase_op.len = mtd->erasesize;
|
erase_op.len = mtd->erasesize;
|
||||||
erase_op.scrub = scrub;
|
|
||||||
|
|
||||||
while (len) {
|
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) {
|
if (ret > 0) {
|
||||||
/* Abort if its not a bad block error */
|
|
||||||
if (ret != -EIO)
|
|
||||||
break;
|
|
||||||
printf("Skipping bad block at 0x%08llx\n",
|
printf("Skipping bad block at 0x%08llx\n",
|
||||||
erase_op.addr);
|
erase_op.addr);
|
||||||
|
ret = 0;
|
||||||
|
len -= mtd->erasesize;
|
||||||
|
erase_op.addr += mtd->erasesize;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mtd_erase(mtd, &erase_op);
|
||||||
|
if (ret && ret != -EIO)
|
||||||
|
break;
|
||||||
|
|
||||||
len -= mtd->erasesize;
|
len -= mtd->erasesize;
|
||||||
erase_op.addr += mtd->erasesize;
|
erase_op.addr += mtd->erasesize;
|
||||||
|
|
Loading…
Reference in a new issue