Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-10 Thread Mikhail Kshevetskiy
On Thu, 6 Oct 2022 20:09:11 +0200
Michael Nazzareno Trimarchi  wrote:

> [External email]
> 
> 
> 
> 
> 
> Hi Mikhail
> 
> On Thu, Oct 6, 2022 at 6:17 PM Mikhail Kshevetskiy
>  wrote:
> >
> > On Thu, 6 Oct 2022 18:03:17 +0200
> > Michael Nazzareno Trimarchi  wrote:
> >
> > > [External email]
> > >
> > >
> > >
> > >
> > >
> > > On Thu, Oct 6, 2022 at 5:52 PM Mikhail Kshevetskiy
> > >  wrote:
> > > >
> > > > On Thu, 6 Oct 2022 08:56:08 +0200
> > > > Michael Nazzareno Trimarchi  wrote:
> > > >
> > > > > [External email]
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Hi
> > > > >
> > > > > On Thu, Oct 6, 2022 at 5:15 AM  wrote:
> > > > > >
> > > > > > From: Mikhail Kshevetskiy 
> > > > > >
> > > > > > 'mtd erase' command should not erase bad blocks. To force bad block
> > > > > > erasing there is 'mtd erase.dontskipbad' command (this command sets
> > > > > > 'scrub' flag to true in the erase_info structure). Unfortunately
> > > > > > nand layer ignore scrub flag and try to erases bad blocks
> > > > > > unconditionally. This is wrong.
> > > > > >
> > > > > > Add checks to allow bad block erasing only if scrub flag is set.
> > > > > >
> > > > > > Signed-off-by: Mikhail Kshevetskiy 
> > > > > > ---
> > > > > >  drivers/mtd/nand/core.c | 5 -
> > > > > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> > > > > > index 99c29670c7..a4fb7602c9 100644
> > > > > > --- a/drivers/mtd/nand/core.c
> > > > > > +++ b/drivers/mtd/nand/core.c
> > > > > > @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd,
> > > > > > struct erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr +
> > > > > > einfo->len - 1, ); while (nanddev_pos_cmp(, ) <= 0) {
> > > > > > schedule();
> > > > > > -   ret = nanddev_erase(nand, );
> > > > > > +   if (!einfo->scrub && nanddev_isbad(nand, ))
> > > > >
> > > > > The nandev_erase already check it here:
> > > > >
> > > > > if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {
> > > > >
> > > >
> > > > no it does not work. see nanddev_erase() code
> > > >
> > >
> > > Let me re-formulate it. What execution path are you taking into account?
> > >
> > > The nand are erased using the cmd/nand interface and the erase command
> > > there calls nand_erase_opts that take in account it.
> >
> > spi-nand flash
> >
> > cmd/mtd.c -> do_mtd_erase() ->  -> nanddev_mtd_erase() ->
> > nanddev_erase()
> >
> 
> Ok now it's clear. I'm thinking and i have create a patch if we can
> use somenthing like this
> 
> Not tested
> 
> 
> @@ -393,7 +394,7 @@ out_put_mtd:
>  static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
> char *const argv[])
>  {
> -   struct erase_info erase_op = {};
> +   nand_erase_options_t opts = {};
> struct mtd_info *mtd;
> u64 off, len;
> bool scrub;
> @@ -431,26 +432,11 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp,
> int flag, int argc,
> printf("Erasing 0x%08llx ... 0x%08llx (%d eraseblock(s))\n",
>off, off + len - 1, mtd_div_by_eb(len, mtd));
> 
> -   erase_op.mtd = mtd;
> -   erase_op.addr = off;
> -   erase_op.len = mtd->erasesize;
> -   erase_op.scrub = scrub;
> -
> -   while (len) {
> -   ret = mtd_erase(mtd, _op);
> -
> -   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);
> -   }
> -
> -   len -= mtd->erasesize;
> -   erase_op.addr += mtd->erasesize;
> -   }
> +   opts.offset = off;
> +   opts.length = len;
> +   opts.scrub = scrub;
> 
> +   ret = nand_erase_opts(mtd, );
> if (ret && ret != -EIO)
> ret = CMD_RET_FAILURE;
> else
> 
> Michael

no, we can't do it.

cmd/mtd.c can be used without CONFIG_MTD_RAW_NAND and I think your fix will
break mtd command for non-nand flashes.

spi-nand flashes directly registers itself with mtd layer (nand_register()
function is not used), so it much more simple use cmd/mtd than cmd/nand.



> 
> 
> >
> > >
> > > Michael
> > >
> > >
> > >
> > > The nand is erased using the
> > > > if block is bad or reserverved, than warning is printed, than block is
> > > > erased.
> > > >
> > > >
> > > > > > +   ret = -EIO;
> > > > > > +   else
> > > > > > +   ret = nanddev_erase(nand, );
> > > > >
> > > > > erase opt should already take in account scrub.
> > > > >
> > > > > Please extend the problem
> > > > >
> > > > > Michael
> > > > > > if (ret) {
> > > > > > einfo->fail_addr = nanddev_pos_to_offs(nand,
> > > > > > );
> > > > > >
> > > > > > --
> > > > > > 

Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread Mikhail Kshevetskiy
On Thu, 6 Oct 2022 18:03:17 +0200
Michael Nazzareno Trimarchi  wrote:

> [External email]
> 
> 
> 
> 
> 
> On Thu, Oct 6, 2022 at 5:52 PM Mikhail Kshevetskiy
>  wrote:
> >
> > On Thu, 6 Oct 2022 08:56:08 +0200
> > Michael Nazzareno Trimarchi  wrote:
> >
> > > [External email]
> > >
> > >
> > >
> > >
> > >
> > > Hi
> > >
> > > On Thu, Oct 6, 2022 at 5:15 AM  wrote:
> > > >
> > > > From: Mikhail Kshevetskiy 
> > > >
> > > > 'mtd erase' command should not erase bad blocks. To force bad block
> > > > erasing there is 'mtd erase.dontskipbad' command (this command sets
> > > > 'scrub' flag to true in the erase_info structure). Unfortunately nand
> > > > layer ignore scrub flag and try to erases bad blocks unconditionally.
> > > > This is wrong.
> > > >
> > > > Add checks to allow bad block erasing only if scrub flag is set.
> > > >
> > > > Signed-off-by: Mikhail Kshevetskiy 
> > > > ---
> > > >  drivers/mtd/nand/core.c | 5 -
> > > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> > > > index 99c29670c7..a4fb7602c9 100644
> > > > --- a/drivers/mtd/nand/core.c
> > > > +++ b/drivers/mtd/nand/core.c
> > > > @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct
> > > > erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr + einfo->len -
> > > > 1, ); while (nanddev_pos_cmp(, ) <= 0) {
> > > > schedule();
> > > > -   ret = nanddev_erase(nand, );
> > > > +   if (!einfo->scrub && nanddev_isbad(nand, ))
> > >
> > > The nandev_erase already check it here:
> > >
> > > if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {
> > >
> >
> > no it does not work. see nanddev_erase() code
> >
> 
> Let me re-formulate it. What execution path are you taking into account?
> 
> The nand are erased using the cmd/nand interface and the erase command
> there calls nand_erase_opts that take in account it.

spi-nand flash

cmd/mtd.c -> do_mtd_erase() ->  -> nanddev_mtd_erase() -> nanddev_erase()


> 
> Michael
> 
> 
> 
> The nand is erased using the
> > if block is bad or reserverved, than warning is printed, than block is
> > erased.
> >
> >
> > > > +   ret = -EIO;
> > > > +   else
> > > > +   ret = nanddev_erase(nand, );
> > >
> > > erase opt should already take in account scrub.
> > >
> > > Please extend the problem
> > >
> > > Michael
> > > > if (ret) {
> > > > einfo->fail_addr = nanddev_pos_to_offs(nand,
> > > > );
> > > >
> > > > --
> > > > 2.35.1
> > > >
> > >
> > >
> > > --
> > > Michael Nazzareno Trimarchi
> > > Co-Founder & Chief Executive Officer
> > > M. +39 347 913 2170
> > > mich...@amarulasolutions.com
> > > __
> > >
> > > Amarula Solutions BV
> > > Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> > > T. +31 (0)85 111 9172
> > > i...@amarulasolutions.com
> > > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2Fdata=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C220e94cc3ad54f5ccca108daa7b44fe6%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638006690117535825%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=zTEEwU%2BKnLWNDq5xs77MmD6SI%2F31bRf3fEx%2Fyaa65%2FU%3Dreserved=0
> 
> 
> 
> --
> Michael Nazzareno Trimarchi
> Co-Founder & Chief Executive Officer
> M. +39 347 913 2170
> mich...@amarulasolutions.com
> __
> 
> Amarula Solutions BV
> Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> T. +31 (0)85 111 9172
> i...@amarulasolutions.com
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2Fdata=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C220e94cc3ad54f5ccca108daa7b44fe6%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638006690117535825%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=zTEEwU%2BKnLWNDq5xs77MmD6SI%2F31bRf3fEx%2Fyaa65%2FU%3Dreserved=0


Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread Mikhail Kshevetskiy
On Thu, 6 Oct 2022 08:56:08 +0200
Michael Nazzareno Trimarchi  wrote:

> [External email]
> 
> 
> 
> 
> 
> Hi
> 
> On Thu, Oct 6, 2022 at 5:15 AM  wrote:
> >
> > From: Mikhail Kshevetskiy 
> >
> > 'mtd erase' command should not erase bad blocks. To force bad block erasing
> > there is 'mtd erase.dontskipbad' command (this command sets 'scrub' flag
> > to true in the erase_info structure). Unfortunately nand layer ignore
> > scrub flag and try to erases bad blocks unconditionally. This is wrong.
> >
> > Add checks to allow bad block erasing only if scrub flag is set.
> >
> > Signed-off-by: Mikhail Kshevetskiy 
> > ---
> >  drivers/mtd/nand/core.c | 5 -
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> > index 99c29670c7..a4fb7602c9 100644
> > --- a/drivers/mtd/nand/core.c
> > +++ b/drivers/mtd/nand/core.c
> > @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct
> > erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1,
> > ); while (nanddev_pos_cmp(, ) <= 0) {
> > schedule();
> > -   ret = nanddev_erase(nand, );
> > +   if (!einfo->scrub && nanddev_isbad(nand, ))
> 
> The nandev_erase already check it here:
> 
> if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {
>

no it does not work. see nanddev_erase() code

if block is bad or reserverved, than warning is printed, than block is erased.

 
> > +   ret = -EIO;
> > +   else
> > +   ret = nanddev_erase(nand, );
> 
> erase opt should already take in account scrub.
> 
> Please extend the problem
> 
> Michael
> > if (ret) {
> > einfo->fail_addr = nanddev_pos_to_offs(nand, );
> >
> > --
> > 2.35.1
> >
> 
> 
> --
> Michael Nazzareno Trimarchi
> Co-Founder & Chief Executive Officer
> M. +39 347 913 2170
> mich...@amarulasolutions.com
> __
> 
> Amarula Solutions BV
> Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> T. +31 (0)85 111 9172
> i...@amarulasolutions.com
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2Fdata=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C0271cbe11c804a8dfde608daa767e01b%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638006361837818885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=ZmdqQp%2FXl4XC7yFKmFEYWocIEsqQGYk8b2UI9i2cibo%3Dreserved=0


Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread Michael Nazzareno Trimarchi
Hi Mikhail

On Thu, Oct 6, 2022 at 6:17 PM Mikhail Kshevetskiy
 wrote:
>
> On Thu, 6 Oct 2022 18:03:17 +0200
> Michael Nazzareno Trimarchi  wrote:
>
> > [External email]
> >
> >
> >
> >
> >
> > On Thu, Oct 6, 2022 at 5:52 PM Mikhail Kshevetskiy
> >  wrote:
> > >
> > > On Thu, 6 Oct 2022 08:56:08 +0200
> > > Michael Nazzareno Trimarchi  wrote:
> > >
> > > > [External email]
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Hi
> > > >
> > > > On Thu, Oct 6, 2022 at 5:15 AM  wrote:
> > > > >
> > > > > From: Mikhail Kshevetskiy 
> > > > >
> > > > > 'mtd erase' command should not erase bad blocks. To force bad block
> > > > > erasing there is 'mtd erase.dontskipbad' command (this command sets
> > > > > 'scrub' flag to true in the erase_info structure). Unfortunately nand
> > > > > layer ignore scrub flag and try to erases bad blocks unconditionally.
> > > > > This is wrong.
> > > > >
> > > > > Add checks to allow bad block erasing only if scrub flag is set.
> > > > >
> > > > > Signed-off-by: Mikhail Kshevetskiy 
> > > > > ---
> > > > >  drivers/mtd/nand/core.c | 5 -
> > > > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> > > > > index 99c29670c7..a4fb7602c9 100644
> > > > > --- a/drivers/mtd/nand/core.c
> > > > > +++ b/drivers/mtd/nand/core.c
> > > > > @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, 
> > > > > struct
> > > > > erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr + einfo->len 
> > > > > -
> > > > > 1, ); while (nanddev_pos_cmp(, ) <= 0) {
> > > > > schedule();
> > > > > -   ret = nanddev_erase(nand, );
> > > > > +   if (!einfo->scrub && nanddev_isbad(nand, ))
> > > >
> > > > The nandev_erase already check it here:
> > > >
> > > > if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {
> > > >
> > >
> > > no it does not work. see nanddev_erase() code
> > >
> >
> > Let me re-formulate it. What execution path are you taking into account?
> >
> > The nand are erased using the cmd/nand interface and the erase command
> > there calls nand_erase_opts that take in account it.
>
> spi-nand flash
>
> cmd/mtd.c -> do_mtd_erase() ->  -> nanddev_mtd_erase() -> nanddev_erase()
>

Ok now it's clear. I'm thinking and i have create a patch if we can
use somenthing like this

Not tested


@@ -393,7 +394,7 @@ out_put_mtd:
 static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
 {
-   struct erase_info erase_op = {};
+   nand_erase_options_t opts = {};
struct mtd_info *mtd;
u64 off, len;
bool scrub;
@@ -431,26 +432,11 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp,
int flag, int argc,
printf("Erasing 0x%08llx ... 0x%08llx (%d eraseblock(s))\n",
   off, off + len - 1, mtd_div_by_eb(len, mtd));

-   erase_op.mtd = mtd;
-   erase_op.addr = off;
-   erase_op.len = mtd->erasesize;
-   erase_op.scrub = scrub;
-
-   while (len) {
-   ret = mtd_erase(mtd, _op);
-
-   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);
-   }
-
-   len -= mtd->erasesize;
-   erase_op.addr += mtd->erasesize;
-   }
+   opts.offset = off;
+   opts.length = len;
+   opts.scrub = scrub;

+   ret = nand_erase_opts(mtd, );
if (ret && ret != -EIO)
ret = CMD_RET_FAILURE;
else

Michael


>
> >
> > Michael
> >
> >
> >
> > The nand is erased using the
> > > if block is bad or reserverved, than warning is printed, than block is
> > > erased.
> > >
> > >
> > > > > +   ret = -EIO;
> > > > > +   else
> > > > > +   ret = nanddev_erase(nand, );
> > > >
> > > > erase opt should already take in account scrub.
> > > >
> > > > Please extend the problem
> > > >
> > > > Michael
> > > > > if (ret) {
> > > > > einfo->fail_addr = nanddev_pos_to_offs(nand,
> > > > > );
> > > > >
> > > > > --
> > > > > 2.35.1
> > > > >
> > > >
> > > >
> > > > --
> > > > Michael Nazzareno Trimarchi
> > > > Co-Founder & Chief Executive Officer
> > > > M. +39 347 913 2170
> > > > mich...@amarulasolutions.com
> > > > __
> > > >
> > > > Amarula Solutions BV
> > > > Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> > > > T. +31 (0)85 111 9172
> > > > i...@amarulasolutions.com
> > > > 

Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread Michael Nazzareno Trimarchi
On Thu, Oct 6, 2022 at 5:52 PM Mikhail Kshevetskiy
 wrote:
>
> On Thu, 6 Oct 2022 08:56:08 +0200
> Michael Nazzareno Trimarchi  wrote:
>
> > [External email]
> >
> >
> >
> >
> >
> > Hi
> >
> > On Thu, Oct 6, 2022 at 5:15 AM  wrote:
> > >
> > > From: Mikhail Kshevetskiy 
> > >
> > > 'mtd erase' command should not erase bad blocks. To force bad block 
> > > erasing
> > > there is 'mtd erase.dontskipbad' command (this command sets 'scrub' flag
> > > to true in the erase_info structure). Unfortunately nand layer ignore
> > > scrub flag and try to erases bad blocks unconditionally. This is wrong.
> > >
> > > Add checks to allow bad block erasing only if scrub flag is set.
> > >
> > > Signed-off-by: Mikhail Kshevetskiy 
> > > ---
> > >  drivers/mtd/nand/core.c | 5 -
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> > > index 99c29670c7..a4fb7602c9 100644
> > > --- a/drivers/mtd/nand/core.c
> > > +++ b/drivers/mtd/nand/core.c
> > > @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct
> > > erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1,
> > > ); while (nanddev_pos_cmp(, ) <= 0) {
> > > schedule();
> > > -   ret = nanddev_erase(nand, );
> > > +   if (!einfo->scrub && nanddev_isbad(nand, ))
> >
> > The nandev_erase already check it here:
> >
> > if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {
> >
>
> no it does not work. see nanddev_erase() code
>

Let me re-formulate it. What execution path are you taking into account?

The nand are erased using the cmd/nand interface and the erase command
there calls nand_erase_opts that take in account it.

Michael



The nand is erased using the
> if block is bad or reserverved, than warning is printed, than block is erased.
>
>
> > > +   ret = -EIO;
> > > +   else
> > > +   ret = nanddev_erase(nand, );
> >
> > erase opt should already take in account scrub.
> >
> > Please extend the problem
> >
> > Michael
> > > if (ret) {
> > > einfo->fail_addr = nanddev_pos_to_offs(nand, 
> > > );
> > >
> > > --
> > > 2.35.1
> > >
> >
> >
> > --
> > Michael Nazzareno Trimarchi
> > Co-Founder & Chief Executive Officer
> > M. +39 347 913 2170
> > mich...@amarulasolutions.com
> > __
> >
> > Amarula Solutions BV
> > Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> > T. +31 (0)85 111 9172
> > i...@amarulasolutions.com
> > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2Fdata=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C0271cbe11c804a8dfde608daa767e01b%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638006361837818885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=ZmdqQp%2FXl4XC7yFKmFEYWocIEsqQGYk8b2UI9i2cibo%3Dreserved=0



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


[PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread mikhail . kshevetskiy
From: Mikhail Kshevetskiy 

'mtd erase' command should not erase bad blocks. To force bad block erasing
there is 'mtd erase.dontskipbad' command (this command sets 'scrub' flag
to true in the erase_info structure). Unfortunately nand layer ignore
scrub flag and try to erases bad blocks unconditionally. This is wrong.

Add checks to allow bad block erasing only if scrub flag is set.

Signed-off-by: Mikhail Kshevetskiy 
---
 drivers/mtd/nand/core.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
index 99c29670c7..a4fb7602c9 100644
--- a/drivers/mtd/nand/core.c
+++ b/drivers/mtd/nand/core.c
@@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct 
erase_info *einfo)
nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, );
while (nanddev_pos_cmp(, ) <= 0) {
schedule();
-   ret = nanddev_erase(nand, );
+   if (!einfo->scrub && nanddev_isbad(nand, ))
+   ret = -EIO;
+   else
+   ret = nanddev_erase(nand, );
if (ret) {
einfo->fail_addr = nanddev_pos_to_offs(nand, );
 
-- 
2.35.1



Re: [PATCH 2/7] mtd/nand: try to erase bad blocks only if scrub flag is provided

2022-10-06 Thread Michael Nazzareno Trimarchi
Hi

On Thu, Oct 6, 2022 at 5:15 AM  wrote:
>
> From: Mikhail Kshevetskiy 
>
> 'mtd erase' command should not erase bad blocks. To force bad block erasing
> there is 'mtd erase.dontskipbad' command (this command sets 'scrub' flag
> to true in the erase_info structure). Unfortunately nand layer ignore
> scrub flag and try to erases bad blocks unconditionally. This is wrong.
>
> Add checks to allow bad block erasing only if scrub flag is set.
>
> Signed-off-by: Mikhail Kshevetskiy 
> ---
>  drivers/mtd/nand/core.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> index 99c29670c7..a4fb7602c9 100644
> --- a/drivers/mtd/nand/core.c
> +++ b/drivers/mtd/nand/core.c
> @@ -174,7 +174,10 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct 
> erase_info *einfo)
> nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, );
> while (nanddev_pos_cmp(, ) <= 0) {
> schedule();
> -   ret = nanddev_erase(nand, );
> +   if (!einfo->scrub && nanddev_isbad(nand, ))

The nandev_erase already check it here:

if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) {

> +   ret = -EIO;
> +   else
> +   ret = nanddev_erase(nand, );

erase opt should already take in account scrub.

Please extend the problem

Michael
> if (ret) {
> einfo->fail_addr = nanddev_pos_to_offs(nand, );
>
> --
> 2.35.1
>


-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com