Message ID | 20220607085915.9944-1-andriy.danylovskyy@streamunlimited.com |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | mtd-interface: erase enough blocks instead of bad ones | expand |
Hi Andry, On 07.06.22 10:59, Andriy Danylovskyy wrote: > flash_erase_sector has to make enough space for the following write. > Whenever a bad block is skipped, one more good block should be erased > (as long as the partition size permits). > Otherwise, the write may move to an unprepared block and corrupt the > partition. > > Signed-off-by: Andriy Danylovskyy <andriy.danylovskyy@streamunlimited.com> > --- > corelib/mtd-interface.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c > index 586a9ba..22e86bd 100644 > --- a/corelib/mtd-interface.c > +++ b/corelib/mtd-interface.c > @@ -79,6 +79,9 @@ int flash_erase_sector(int mtdnum, off_t start, size_t size) > if (!noskipbad) { > int isbad = mtd_is_bad(mtd, fd, eb); > if (isbad > 0) { > + /* Will need to erase one more block, instead of the bad one */ > + if (eb_end * mtd->eb_size < mtd->size) > + eb_end++; > continue; > } else if (isbad < 0) { > if (errno == EOPNOTSUPP) { You're right ! Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
> flash_erase_sector has to make enough space for the following write. > Whenever a bad block is skipped, one more good block should be erased > (as long as the partition size permits). > Otherwise, the write may move to an unprepared block and corrupt the > partition. > Signed-off-by: Andriy Danylovskyy <andriy.danylovskyy@streamunlimited.com> > Acked-by: Stefano Babic <sbabic@denx.de> Applied to u-boot-imx, master, thanks ! Best regards, Stefano Babic
diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index 586a9ba..22e86bd 100644 --- a/corelib/mtd-interface.c +++ b/corelib/mtd-interface.c @@ -79,6 +79,9 @@ int flash_erase_sector(int mtdnum, off_t start, size_t size) if (!noskipbad) { int isbad = mtd_is_bad(mtd, fd, eb); if (isbad > 0) { + /* Will need to erase one more block, instead of the bad one */ + if (eb_end * mtd->eb_size < mtd->size) + eb_end++; continue; } else if (isbad < 0) { if (errno == EOPNOTSUPP) {
flash_erase_sector has to make enough space for the following write. Whenever a bad block is skipped, one more good block should be erased (as long as the partition size permits). Otherwise, the write may move to an unprepared block and corrupt the partition. Signed-off-by: Andriy Danylovskyy <andriy.danylovskyy@streamunlimited.com> --- corelib/mtd-interface.c | 3 +++ 1 file changed, 3 insertions(+)