* [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker
@ 2020-03-10 20:32 ` Mikhail Kshevetskiy
0 siblings, 0 replies; 6+ messages in thread
From: Mikhail Kshevetskiy @ 2020-03-10 20:32 UTC (permalink / raw)
To: miquel.raynal, richard; +Cc: linux-mtd, linux-kernel, Mikhail Kshevetskiy
SPI flash will discard any write operation while it is busy with block
erasing. As result bad block marker will not be writed to a flash.
To fix it just wait for completion of erase operation.
The erasing code is almost the same as in spinand_erase(). The only
difference is: we ignore ERASE_FAILED status.
This patch also improve error handling a bit.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
---
drivers/mtd/nand/spi/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 89f6beefb01c..bb4eac400b0f 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -610,6 +610,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
.oobbuf.out = spinand->oobbuf,
};
int ret;
+ u8 status;
/* Erase block before marking it bad. */
ret = spinand_select_target(spinand, pos->target);
@@ -620,7 +621,14 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;
- spinand_erase_op(spinand, pos);
+ ret = spinand_erase_op(spinand, pos);
+ if (ret)
+ return ret;
+
+ /* ignore status as erase may fail for bad blocks */
+ spinand_wait(spinand, &status);
+ if (ret)
+ return ret;
memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
--
2.25.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker
@ 2020-03-10 20:32 ` Mikhail Kshevetskiy
0 siblings, 0 replies; 6+ messages in thread
From: Mikhail Kshevetskiy @ 2020-03-10 20:32 UTC (permalink / raw)
To: miquel.raynal, richard; +Cc: linux-mtd, linux-kernel, Mikhail Kshevetskiy
SPI flash will discard any write operation while it is busy with block
erasing. As result bad block marker will not be writed to a flash.
To fix it just wait for completion of erase operation.
The erasing code is almost the same as in spinand_erase(). The only
difference is: we ignore ERASE_FAILED status.
This patch also improve error handling a bit.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
---
drivers/mtd/nand/spi/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 89f6beefb01c..bb4eac400b0f 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -610,6 +610,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
.oobbuf.out = spinand->oobbuf,
};
int ret;
+ u8 status;
/* Erase block before marking it bad. */
ret = spinand_select_target(spinand, pos->target);
@@ -620,7 +621,14 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;
- spinand_erase_op(spinand, pos);
+ ret = spinand_erase_op(spinand, pos);
+ if (ret)
+ return ret;
+
+ /* ignore status as erase may fail for bad blocks */
+ spinand_wait(spinand, &status);
+ if (ret)
+ return ret;
memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
--
2.25.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] mtd: spinand: fix bad block marker writing
2020-03-10 20:32 ` Mikhail Kshevetskiy
@ 2020-03-10 20:32 ` Mikhail Kshevetskiy
-1 siblings, 0 replies; 6+ messages in thread
From: Mikhail Kshevetskiy @ 2020-03-10 20:32 UTC (permalink / raw)
To: miquel.raynal, richard; +Cc: linux-mtd, linux-kernel, Mikhail Kshevetskiy
In spinand_markbad() we use spinand->oobbuf as a bad block marker, fill
it with zeroes and issue spinand_write_page() operation:
struct nand_page_io_req req = {
.pos = *pos,
.ooboffs = 0,
.ooblen = 2,
.oobbuf.out = spinand->oobbuf,
};
...
memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
spinand_write_page() will call spinand_write_to_cache_op() at some
moment. In spinand_write_to_cache_op() we have:
nbytes = nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
memset(spinand->databuf, 0xff, nbytes);
This will fill spinand->databuf with 0xff, but spinand->oobbuf is the
part of spinand->databuf (see spinand_init()):
spinand->oobbuf = spinand->databuf + nanddev_page_size(nand);
As result bad block marker will be overwrited by 0xff values, hence
bad block will NOT be marked.
A separate buffer for bad block marker used to fix this issue.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
---
drivers/mtd/nand/spi/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index bb4eac400b0f..d1355773d484 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -603,11 +603,12 @@ static int spinand_mtd_block_isbad(struct mtd_info *mtd, loff_t offs)
static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
{
struct spinand_device *spinand = nand_to_spinand(nand);
+ char bad_block_marker[2] = {0, 0};
struct nand_page_io_req req = {
.pos = *pos,
.ooboffs = 0,
- .ooblen = 2,
- .oobbuf.out = spinand->oobbuf,
+ .ooblen = sizeof(bad_block_marker),
+ .oobbuf.out = bad_block_marker,
};
int ret;
u8 status;
@@ -630,7 +631,6 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;
- memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
}
--
2.25.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] mtd: spinand: fix bad block marker writing
@ 2020-03-10 20:32 ` Mikhail Kshevetskiy
0 siblings, 0 replies; 6+ messages in thread
From: Mikhail Kshevetskiy @ 2020-03-10 20:32 UTC (permalink / raw)
To: miquel.raynal, richard; +Cc: linux-mtd, linux-kernel, Mikhail Kshevetskiy
In spinand_markbad() we use spinand->oobbuf as a bad block marker, fill
it with zeroes and issue spinand_write_page() operation:
struct nand_page_io_req req = {
.pos = *pos,
.ooboffs = 0,
.ooblen = 2,
.oobbuf.out = spinand->oobbuf,
};
...
memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
spinand_write_page() will call spinand_write_to_cache_op() at some
moment. In spinand_write_to_cache_op() we have:
nbytes = nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
memset(spinand->databuf, 0xff, nbytes);
This will fill spinand->databuf with 0xff, but spinand->oobbuf is the
part of spinand->databuf (see spinand_init()):
spinand->oobbuf = spinand->databuf + nanddev_page_size(nand);
As result bad block marker will be overwrited by 0xff values, hence
bad block will NOT be marked.
A separate buffer for bad block marker used to fix this issue.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
---
drivers/mtd/nand/spi/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index bb4eac400b0f..d1355773d484 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -603,11 +603,12 @@ static int spinand_mtd_block_isbad(struct mtd_info *mtd, loff_t offs)
static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
{
struct spinand_device *spinand = nand_to_spinand(nand);
+ char bad_block_marker[2] = {0, 0};
struct nand_page_io_req req = {
.pos = *pos,
.ooboffs = 0,
- .ooblen = 2,
- .oobbuf.out = spinand->oobbuf,
+ .ooblen = sizeof(bad_block_marker),
+ .oobbuf.out = bad_block_marker,
};
int ret;
u8 status;
@@ -630,7 +631,6 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;
- memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
}
--
2.25.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker
2020-03-10 20:32 ` Mikhail Kshevetskiy
@ 2020-03-11 10:13 ` Miquel Raynal
-1 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2020-03-11 10:13 UTC (permalink / raw)
To: Mikhail Kshevetskiy; +Cc: richard, linux-mtd, linux-kernel
Hi Mikhail,
Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru> wrote on Tue, 10
Mar 2020 23:32:23 +0300:
> SPI flash will discard any write operation while it is busy with block
> erasing. As result bad block marker will not be writed to a flash.
> To fix it just wait for completion of erase operation.
>
> The erasing code is almost the same as in spinand_erase(). The only
> difference is: we ignore ERASE_FAILED status.
>
> This patch also improve error handling a bit.
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
Thanks a lot for sharing this!
Actually Frieder sent a fix for that I already added to nand/next,
please have a look at:
https://lore.kernel.org/linux-mtd/20200218100432.32433-1-frieder.schrempf@kontron.de/
If you think I'm missing something else, please tell me!
> ---
> drivers/mtd/nand/spi/core.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 89f6beefb01c..bb4eac400b0f 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -610,6 +610,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
> .oobbuf.out = spinand->oobbuf,
> };
> int ret;
> + u8 status;
>
> /* Erase block before marking it bad. */
> ret = spinand_select_target(spinand, pos->target);
> @@ -620,7 +621,14 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
> if (ret)
> return ret;
>
> - spinand_erase_op(spinand, pos);
> + ret = spinand_erase_op(spinand, pos);
> + if (ret)
> + return ret;
> +
> + /* ignore status as erase may fail for bad blocks */
> + spinand_wait(spinand, &status);
> + if (ret)
> + return ret;
>
> memset(spinand->oobbuf, 0, 2);
> return spinand_write_page(spinand, &req);
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker
@ 2020-03-11 10:13 ` Miquel Raynal
0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2020-03-11 10:13 UTC (permalink / raw)
To: Mikhail Kshevetskiy; +Cc: richard, linux-mtd, linux-kernel
Hi Mikhail,
Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru> wrote on Tue, 10
Mar 2020 23:32:23 +0300:
> SPI flash will discard any write operation while it is busy with block
> erasing. As result bad block marker will not be writed to a flash.
> To fix it just wait for completion of erase operation.
>
> The erasing code is almost the same as in spinand_erase(). The only
> difference is: we ignore ERASE_FAILED status.
>
> This patch also improve error handling a bit.
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
Thanks a lot for sharing this!
Actually Frieder sent a fix for that I already added to nand/next,
please have a look at:
https://lore.kernel.org/linux-mtd/20200218100432.32433-1-frieder.schrempf@kontron.de/
If you think I'm missing something else, please tell me!
> ---
> drivers/mtd/nand/spi/core.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 89f6beefb01c..bb4eac400b0f 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -610,6 +610,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
> .oobbuf.out = spinand->oobbuf,
> };
> int ret;
> + u8 status;
>
> /* Erase block before marking it bad. */
> ret = spinand_select_target(spinand, pos->target);
> @@ -620,7 +621,14 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
> if (ret)
> return ret;
>
> - spinand_erase_op(spinand, pos);
> + ret = spinand_erase_op(spinand, pos);
> + if (ret)
> + return ret;
> +
> + /* ignore status as erase may fail for bad blocks */
> + spinand_wait(spinand, &status);
> + if (ret)
> + return ret;
>
> memset(spinand->oobbuf, 0, 2);
> return spinand_write_page(spinand, &req);
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-11 10:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10 20:32 [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker Mikhail Kshevetskiy
2020-03-10 20:32 ` Mikhail Kshevetskiy
2020-03-10 20:32 ` [PATCH 2/2] mtd: spinand: fix bad block marker writing Mikhail Kshevetskiy
2020-03-10 20:32 ` Mikhail Kshevetskiy
2020-03-11 10:13 ` [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker Miquel Raynal
2020-03-11 10:13 ` Miquel Raynal
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.