| Message ID | 20221024094400.4184355-1-dario.binacchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-amarula+bncBCQ4XFG47UFRBZN43GNAMGQEYM5MLJQ@amarulasolutions.com> X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1EEB244AEE for <linux-amarula@patchwork.amarulasolutions.com>; Mon, 24 Oct 2022 11:44:06 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id y14-20020a056402440e00b0044301c7ccd9sf9017742eda.19 for <linux-amarula@patchwork.amarulasolutions.com>; Mon, 24 Oct 2022 02:44:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666604645; cv=pass; d=google.com; s=arc-20160816; b=m9rcfu22Z79MMVG3Vgs0hDiFFFHH1HAWbCqEvFAkP5QRiOTSwLo1910Nicl5U/KJ8c 41MHGc+CRsOh6BHwXIXGG4X1mZg5B6Eagd0kuEHQcEa8EkpTiJI5LibJobP8B9s7DwFk co/T7ZEuS5Q0uBk0dwDGw1cC5z3VOdEdmQSkO/vDVnzPlo5A7MD9f4IMnPObtskmp9hM 1CzL0TT4mjsB0OYrVq9Rzed9ZQ/UKGS0wl0Bl5NRYiEpfMTZe/FsmL3rjXJkWsW/8VSu C/sD4b5c0DNCSFuudsGsqHmb7WKMs6mZnwd6ojP/ftZ7VfAyj3pH9x/MmcHLRXPH1iz1 xl7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=9490r5YA1D+c3O/o8UWeXTDgasVzx0wkWn2v4qjoYp8=; b=D5yhVqkhRtjL8frqwPuYumVJIfmXyYj9Rni5JxDuVPHwpdajc/YR/DgVItzKDxwHqA 7X9MjUz8wma7fnznAImrw5EUNLnMgai+m9pyskMFYUo2dT687XY2NaeeXrUVTsmjAq5T 1dGTLLA2R5+RvWxi8VIBTrPsSjq91HWjnDLSKQQm1Tm3mmqmSpx+DzQCV7eVu2ne2h0B E/uv6IaDOs/BExcWImhK5v5OSDmKhbkMPOaYp8hhuiaQv945+nRt03s/c/LjKJDTSO8+ TAsIzdAEhDa2+2/n0PW2DcGs63PeYRGESuzBxtc+NWyF0sUIY0ei1F5p3cA3hSToWxDW +MwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VaPID8GY; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=9490r5YA1D+c3O/o8UWeXTDgasVzx0wkWn2v4qjoYp8=; b=be/3+XtLB7vPAoPCWB7HYe3JbIL1RqcN0JxCXxVt4lZNMrgNirI6f6EqiP5einMgmR x+FSCT5yAcXpElUsP3VzEehwklZdz9siGhY8a2GYLioV23kc0/MfAKaBUy6ZrOKowTX6 WRft+W1Vpb81XyTDbB2LPl6wFn8I3uMSX5M54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9490r5YA1D+c3O/o8UWeXTDgasVzx0wkWn2v4qjoYp8=; b=qe7YuFAQBQ/qUHHAJ+Ci0GnLm4DLijfFyiqLfpWjDeHJMEfe2368KyQV/wIHpeJ9xj 9NYHyiH8fLz7orz3oiEc1SQL18B3vUN5mm6WBtAP8ihzElIgv2okwdA49m6/cMG2YMCR Z+7bG/fSIGSuSk6GZUfLptPzSLt1mT5IO5pfpnFnoqVwhy5BAKe644DwnRg5xCgQafbu w1jh8FF7MAEg6zYgQqJ9sx1miTykbY2wOj72pouTsQI31EY4EIJnlgheaZPEMs9y+O7y 2TovtY9Ik+ZX0r7Dt91v+jeiZJbwwh/mrVDYxx+GmN0XJxs8M8rWZetxjgzbxSaefRn3 pq/w== X-Gm-Message-State: ACrzQf3iOKvPl0NgxmIHMmL+rWM6yjQ41syz3YwV+6u9EkFWyZJQRWsF Z6tQL0lm34oVZ+3DH5z8BD3U7mID X-Google-Smtp-Source: AMsMyM6xAXUD4Mw1eWlqqKoGDQPJUsYET+4xA2+G2psXz44xNQn8wxmNohiitjgnGAGx8IJ0zmFAJg== X-Received: by 2002:a17:906:ee81:b0:77e:829a:76e9 with SMTP id wt1-20020a170906ee8100b0077e829a76e9mr27922840ejb.207.1666604645776; Mon, 24 Oct 2022 02:44:05 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:4f8e:b0:783:b20:46a0 with SMTP id o14-20020a1709064f8e00b007830b2046a0ls4215680eju.6.-pod-prod-gmail; Mon, 24 Oct 2022 02:44:04 -0700 (PDT) X-Received: by 2002:a17:907:720e:b0:78e:2b59:fdf1 with SMTP id dr14-20020a170907720e00b0078e2b59fdf1mr27600491ejc.659.1666604644543; Mon, 24 Oct 2022 02:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666604644; cv=none; d=google.com; s=arc-20160816; b=DthKIfVAOv6f/L3Q8L+lnDzsBOfgGsy301gLd4CaPQvm5nce1v66tE1aM1DDRm5zDx zkcea+nDL46LmOu7IMOfLARAdb2v+eFN9yvxzuxV0tziHdYZWttvAWaEp0UfT0cDDiPX +tWEFe4+yIMvlLitGQnf2yYYhJhOGJAKLI5WP3r5sV2pgj0NrV6harOv101Ow3HavsXK UOdhsX7DC+m5E+WXrQUpJRPRP5Fm3QEzMq7xvZq+nB5sG1pHiwB5pznO/P0EyS+EbfME r1JH7z/XMELD2jiH9aiiKIqxGF57iwgIdeMSLR8FelGBqnJ1ER6jonriD3lvQIl1YhQH 7AAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=juNnz7XuUA3pXgMTDAodIeD0tBD5Pr0zAIMs636i0Vo=; b=eBAv2Ng7FzeNoFdzvB7IGorRRKXhOI0eiPyS8oof9tqLh95nk5Ed5+FslLldC1YjRH Q6FSBcth/27Fm0mX7FV9OPlp+xOHLHo96DgiK2AE3Dbamd+l31kOGk0+JrSXo5ay3Rpr CQKv3KBY8Co9BP5J0hv0AyLJNUjwlL6ymyOAq0JnCP73czJVP4diBSH9+1PAgM3mjQLe EFXEtQn16nRHJP9EGz6w9fD2nVyvmFY3kvdD1kRglyHxYMmIL/G1C1jKv3IPcuDMWp14 SKdewe1za/kfY5Cf2j4hBJ2gfCxW7ZEg8APLBjgMV0We46A0jUL3ZtmEzOWikbSEU13c nzgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VaPID8GY; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id i18-20020a170906699200b0078ae04f096bsor12179136ejr.55.2022.10.24.02.44.04 for <linux-amarula@amarulasolutions.com> (Google Transport Security); Mon, 24 Oct 2022 02:44:04 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:270e:b0:7a6:4212:b01e with SMTP id w14-20020a170907270e00b007a64212b01emr4930744ejk.556.1666604644312; Mon, 24 Oct 2022 02:44:04 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-87-0-15-180.retail.telecomitalia.it. [87.0.15.180]) by smtp.gmail.com with ESMTPSA id 17-20020a170906219100b0073d81b0882asm13579041eju.7.2022.10.24.02.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 02:44:03 -0700 (PDT) From: Dario Binacchi <dario.binacchi@amarulasolutions.com> To: u-boot@lists.denx.de Cc: Amarula patchwork <linux-amarula@amarulasolutions.com>, Tom Rini <trini@konsulko.com>, Jagan Teki <jagan@amarulasolutions.com>, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>, Michael Trimarchi <michael@amarulasolutions.com>, Dario Binacchi <dario.binacchi@amarulasolutions.com> Subject: [PATCH v3] cmd: mtd: check if a block has to be skipped or erased Date: Mon, 24 Oct 2022 11:44:00 +0200 Message-Id: <20221024094400.4184355-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VaPID8GY; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: <linux-amarula.amarulasolutions.com> X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>, <mailto:linux-amarula@amarulasolutions.com> List-Help: <https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>, <mailto:linux-amarula+help@amarulasolutions.com> List-Archive: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/> List-Unsubscribe: <mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>, <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe> |
| Series |
[v3] cmd: mtd: check if a block has to be skipped or erased
|
|
Commit Message
Dario Binacchi
Oct. 24, 2022, 9:44 a.m. UTC
From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> --- Changes in v3: - Simplify the code. mtd_erase() can't return a bad block error. Print the messaged where the bad block is found. 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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
Comments
On 24.10.2022 12:44, Dario Binacchi wrote: > [External email] > > > > > > From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C0ce3c4f03458440084dd08dab5a44a0e%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638022014468655016%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=VMQov1%2FRUmymW2G452jlOveOu2tFCE5MtzssuP2Ri3Y%3D&reserved=0 > 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > --- > > Changes in v3: > - Simplify the code. mtd_erase() can't return a bad block error. Print > the messaged where the bad block is found. > > 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 | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/cmd/mtd.c b/cmd/mtd.c > index ad5cc9827d55..29b2a9c04c0c 100644 > --- a/cmd/mtd.c > +++ b/cmd/mtd.c > @@ -434,19 +434,27 @@ 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 (ret) { > - /* Abort if its not a bad block error */ > - if (ret != -EIO) > + 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) { > + printf("Skipping bad block at 0x%08llx\n", > + erase_op.addr); > + ret = -EIO; > break; That is bad.//Skipping bad block is an expected behavior. We should not fail on it. > - printf("Skipping bad block at 0x%08llx\n", > - erase_op.addr); > + } > } > > + ret = mtd_erase(mtd, &erase_op); > + if (ret) > + break; > + > len -= mtd->erasesize; > erase_op.addr += mtd->erasesize; > } > -- > 2.32.0 >
On 24.10.2022 12:44, Dario Binacchi wrote: > [External email] > > > > > > From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C0ce3c4f03458440084dd08dab5a44a0e%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638022014468655016%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=VMQov1%2FRUmymW2G452jlOveOu2tFCE5MtzssuP2Ri3Y%3D&reserved=0 > 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > --- > > Changes in v3: > - Simplify the code. mtd_erase() can't return a bad block error. Print > the messaged where the bad block is found. > > 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 | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/cmd/mtd.c b/cmd/mtd.c > index ad5cc9827d55..29b2a9c04c0c 100644 > --- a/cmd/mtd.c > +++ b/cmd/mtd.c > @@ -434,19 +434,27 @@ 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 (ret) { > - /* Abort if its not a bad block error */ > - if (ret != -EIO) > + 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) { > + printf("Skipping bad block at 0x%08llx\n", > + erase_op.addr); > + ret = -EIO; > break; > - printf("Skipping bad block at 0x%08llx\n", > - erase_op.addr); > + } > } > > + ret = mtd_erase(mtd, &erase_op); > + if (ret) > + break; > + mtd_erase() can return -EIO, see drivers/mtd/nand/spi/core.c function spinand_mtd_erase() > len -= mtd->erasesize; > erase_op.addr += mtd->erasesize; > } > -- > 2.32.0 >
Hi Mikhail, On Mon, Oct 24, 2022 at 1:24 PM Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote: > > > On 24.10.2022 12:44, Dario Binacchi wrote: > > [External email] > > > > > > > > > > > > From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > > > 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C0ce3c4f03458440084dd08dab5a44a0e%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638022014468655016%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=VMQov1%2FRUmymW2G452jlOveOu2tFCE5MtzssuP2Ri3Y%3D&reserved=0 > > 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > > > > --- > > > > Changes in v3: > > - Simplify the code. mtd_erase() can't return a bad block error. Print > > the messaged where the bad block is found. > > > > 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 | 24 ++++++++++++++++-------- > > 1 file changed, 16 insertions(+), 8 deletions(-) > > > > diff --git a/cmd/mtd.c b/cmd/mtd.c > > index ad5cc9827d55..29b2a9c04c0c 100644 > > --- a/cmd/mtd.c > > +++ b/cmd/mtd.c > > @@ -434,19 +434,27 @@ 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 (ret) { > > - /* Abort if its not a bad block error */ > > - if (ret != -EIO) > > + 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) { > > + printf("Skipping bad block at 0x%08llx\n", > > + erase_op.addr); > > + ret = -EIO; > > break; > > - printf("Skipping bad block at 0x%08llx\n", > > - erase_op.addr); > > + } > > } > > > > + ret = mtd_erase(mtd, &erase_op); > > + if (ret) > > + break; > > + > > mtd_erase() can return -EIO, see drivers/mtd/nand/spi/core.c function > spinand_mtd_erase() If I compare my original patch [1] with yours [2], I see no difference in behavior except for ret checking after calling mtd_erase() which, in my case, was wrong. Do you agree? Further, checking for a bad block inside the do_mtd_erase(), the mtd_erase() can return -EIO only in the case of a protected block. In case of the scrub option enabled the bad block is erased, otherwise the block is jumped in the do_mtd_erase() without calling the mtd_erase(). I think that now we can distinguish between a bad block and a protected block inside the do_mtd_erase(), always if it's true that the -EIO error is only returned for bad/protected block by low level operations. [1] https://patchwork.ozlabs.org/project/uboot/patch/20221021152929.3598415-1-dario.binacchi@amarulasolutions.com/ [2] https://patchwork.amarulasolutions.com/patch/2458/ Thanks and regards, Dario > > > > > len -= mtd->erasesize; > > erase_op.addr += mtd->erasesize; > > } > > -- > > 2.32.0 > >
On 26.10.2022 09:29, Dario Binacchi wrote: > [External email] > > > > > > Hi Mikhail, > > On Mon, Oct 24, 2022 at 1:24 PM Mikhail Kshevetskiy > <mikhail.kshevetskiy@iopsys.eu> wrote: >> >> On 24.10.2022 12:44, Dario Binacchi wrote: >>> [External email] >>> >>> >>> >>> >>> >>> From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>> >>> 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=YRmQ5XcWRw8gcy4Hy3nK29J%2FnttlD10lQvH%2B5YnBrxU%3D&reserved=0 >>> 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>> Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>> >>> --- >>> >>> Changes in v3: >>> - Simplify the code. mtd_erase() can't return a bad block error. Print >>> the messaged where the bad block is found. >>> >>> 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 | 24 ++++++++++++++++-------- >>> 1 file changed, 16 insertions(+), 8 deletions(-) >>> >>> diff --git a/cmd/mtd.c b/cmd/mtd.c >>> index ad5cc9827d55..29b2a9c04c0c 100644 >>> --- a/cmd/mtd.c >>> +++ b/cmd/mtd.c >>> @@ -434,19 +434,27 @@ 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 (ret) { >>> - /* Abort if its not a bad block error */ >>> - if (ret != -EIO) >>> + 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) { >>> + printf("Skipping bad block at 0x%08llx\n", >>> + erase_op.addr); >>> + ret = -EIO; >>> break; >>> - printf("Skipping bad block at 0x%08llx\n", >>> - erase_op.addr); >>> + } >>> } >>> >>> + ret = mtd_erase(mtd, &erase_op); >>> + if (ret) >>> + break; >>> + >> mtd_erase() can return -EIO, see drivers/mtd/nand/spi/core.c function >> spinand_mtd_erase() > If I compare my original patch [1] with yours [2], I see no difference > in behavior except for ret checking after calling > mtd_erase() which, in my case, was wrong. > Do you agree? yes > Further, checking for a bad block inside the do_mtd_erase(), the > mtd_erase() can return -EIO only in the case of a protected > block. In case of the scrub option enabled the bad block is erased, > otherwise the block is jumped in the do_mtd_erase() > without calling the mtd_erase(). I see -EIO error in the following cases a) physical bad block b) hardware failures (ex: some timeout expired) maybe it also returned for protected block as well. > I think that now we can distinguish between a bad block and a > protected block inside the do_mtd_erase(), always if it's true > that the -EIO error is only returned for bad/protected block by low > level operations. Could you describe your idea in more details. I do not see a way to distinguish bad and protected blocks. The main problem with your v3 patch is a termination of erasing loop on any mtd_erase() failure. It becomes worse if mtd_erase() returns -EIO. In this case you'll stop erasing due to error, but do_mtd_erase() will return success. Mikhail [1] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20221021152929.3598415-1-dario.binacchi%40amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BK5CkLi6MBMaByX8%2FK0vKhAMKciyFE0TuOnNqsljrLc%3D&reserved=0 [2] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.amarulasolutions.com%2Fpatch%2F2458%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=wzYLYjzuTOn8t7aHWxxUyT6IoKM72C%2FTTmC2nNzxVck%3D&reserved=0 Thanks and regards, Dario >> >> >>> len -= mtd->erasesize; >>> erase_op.addr += mtd->erasesize; >>> } >>> -- >>> 2.32.0 >>> > > > -- > > Dario Binacchi > > Embedded Linux Developer > > dario.binacchi@amarulasolutions.com > > __________________________________ > > > Amarula Solutions SRL > > Via Le Canevare 30, 31100 Treviso, Veneto, IT > > T. +39 042 243 5310 > info@amarulasolutions.com > > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=HhmwzN7An3%2FyWcgkO7uORGfVKmlzdMp9cwFjaD4nLHs%3D&reserved=0
Hi Mikhail, On Wed, Oct 26, 2022 at 2:56 PM Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote: > > On 26.10.2022 09:29, Dario Binacchi wrote: > > > [External email] > > > > > > > > > > > > Hi Mikhail, > > > > On Mon, Oct 24, 2022 at 1:24 PM Mikhail Kshevetskiy > > <mikhail.kshevetskiy@iopsys.eu> wrote: > >> > >> On 24.10.2022 12:44, Dario Binacchi wrote: > >>> [External email] > >>> > >>> > >>> > >>> > >>> > >>> From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > >>> > >>> 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=YRmQ5XcWRw8gcy4Hy3nK29J%2FnttlD10lQvH%2B5YnBrxU%3D&reserved=0 > >>> 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> > >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > >>> Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > >>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> > >>> > >>> --- > >>> > >>> Changes in v3: > >>> - Simplify the code. mtd_erase() can't return a bad block error. Print > >>> the messaged where the bad block is found. > >>> > >>> 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 | 24 ++++++++++++++++-------- > >>> 1 file changed, 16 insertions(+), 8 deletions(-) > >>> > >>> diff --git a/cmd/mtd.c b/cmd/mtd.c > >>> index ad5cc9827d55..29b2a9c04c0c 100644 > >>> --- a/cmd/mtd.c > >>> +++ b/cmd/mtd.c > >>> @@ -434,19 +434,27 @@ 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 (ret) { > >>> - /* Abort if its not a bad block error */ > >>> - if (ret != -EIO) > >>> + 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) { > >>> + printf("Skipping bad block at 0x%08llx\n", > >>> + erase_op.addr); > >>> + ret = -EIO; > >>> break; > >>> - printf("Skipping bad block at 0x%08llx\n", > >>> - erase_op.addr); > >>> + } > >>> } > >>> > >>> + ret = mtd_erase(mtd, &erase_op); > >>> + if (ret) > >>> + break; > >>> + > >> mtd_erase() can return -EIO, see drivers/mtd/nand/spi/core.c function > >> spinand_mtd_erase() > > If I compare my original patch [1] with yours [2], I see no difference > > in behavior except for ret checking after calling > > mtd_erase() which, in my case, was wrong. > > Do you agree? > > yes So I'll submit version 4 which reverts to version 1 and changes the check for the return value of the mtd_erase(). I will also change the author of the commit. I added your signed-off. Please retest the patch on your hardware. > > > Further, checking for a bad block inside the do_mtd_erase(), the > > mtd_erase() can return -EIO only in the case of a protected > > block. In case of the scrub option enabled the bad block is erased, > > otherwise the block is jumped in the do_mtd_erase() > > without calling the mtd_erase(). > > I see -EIO error in the following cases > > a) physical bad block > > b) hardware failures (ex: some timeout expired) > > maybe it also returned for protected block as well. So, in case (b) we may have another type of problem which is not caused by this patch. As we can see by the current code: while (len) { ret = mtd_erase(mtd, &erase_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; } if (ret && ret != -EIO) ret = CMD_RET_FAILURE; else ret = CMD_RET_SUCCESS; > > > I think that now we can distinguish between a bad block and a > > protected block inside the do_mtd_erase(), always if it's true > > that the -EIO error is only returned for bad/protected block by low > > level operations. > > Could you describe your idea in more details. I do not see a way to > distinguish bad and protected blocks. Could we use mtd_block_isreserved() ? Thanks and regards Dario > > The main problem with your v3 patch is a termination of erasing loop > on any mtd_erase() failure. It becomes worse if mtd_erase() returns -EIO. > In this case you'll stop erasing due to error, but do_mtd_erase() will > return success. > > Mikhail > > [1] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20221021152929.3598415-1-dario.binacchi%40amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BK5CkLi6MBMaByX8%2FK0vKhAMKciyFE0TuOnNqsljrLc%3D&reserved=0 > [2] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.amarulasolutions.com%2Fpatch%2F2458%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=wzYLYjzuTOn8t7aHWxxUyT6IoKM72C%2FTTmC2nNzxVck%3D&reserved=0 > > Thanks and regards, > Dario > > >> > >> > >>> len -= mtd->erasesize; > >>> erase_op.addr += mtd->erasesize; > >>> } > >>> -- > >>> 2.32.0 > >>> > > > > > > -- > > > > Dario Binacchi > > > > Embedded Linux Developer > > > > dario.binacchi@amarulasolutions.com > > > > __________________________________ > > > > > > Amarula Solutions SRL > > > > Via Le Canevare 30, 31100 Treviso, Veneto, IT > > > > T. +39 042 243 5310 > > info@amarulasolutions.com > > > > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7C02dff372bf00435cd94208dab71b6aed%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638023625630435867%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=HhmwzN7An3%2FyWcgkO7uORGfVKmlzdMp9cwFjaD4nLHs%3D&reserved=0
On 30.10.2022 17:06, Dario Binacchi wrote: > [External email] > > > > > > Hi Mikhail, > > On Wed, Oct 26, 2022 at 2:56 PM Mikhail Kshevetskiy > <mikhail.kshevetskiy@iopsys.eu> wrote: >> On 26.10.2022 09:29, Dario Binacchi wrote: >> >>> [External email] >>> >>> >>> >>> >>> >>> Hi Mikhail, >>> >>> On Mon, Oct 24, 2022 at 1:24 PM Mikhail Kshevetskiy >>> <mikhail.kshevetskiy@iopsys.eu> wrote: >>>> On 24.10.2022 12:44, Dario Binacchi wrote: >>>>> [External email] >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>>>> >>>>> 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20221006031501.110290-2-mikhail.kshevetskiy%40iopsys.eu%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7Cfe44aaf264764836295e08daba7ff1f7%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638027355932818989%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TwMrP%2FpIz5R1Dfd1iXr8u2wZvDj3sdyl%2F8TADkPEDpQ%3D&reserved=0 >>>>> 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: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>>>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>>>> Tested-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>>>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> >>>>> >>>>> --- >>>>> >>>>> Changes in v3: >>>>> - Simplify the code. mtd_erase() can't return a bad block error. Print >>>>> the messaged where the bad block is found. >>>>> >>>>> 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 | 24 ++++++++++++++++-------- >>>>> 1 file changed, 16 insertions(+), 8 deletions(-) >>>>> >>>>> diff --git a/cmd/mtd.c b/cmd/mtd.c >>>>> index ad5cc9827d55..29b2a9c04c0c 100644 >>>>> --- a/cmd/mtd.c >>>>> +++ b/cmd/mtd.c >>>>> @@ -434,19 +434,27 @@ 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 (ret) { >>>>> - /* Abort if its not a bad block error */ >>>>> - if (ret != -EIO) >>>>> + 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) { >>>>> + printf("Skipping bad block at 0x%08llx\n", >>>>> + erase_op.addr); >>>>> + ret = -EIO; >>>>> break; >>>>> - printf("Skipping bad block at 0x%08llx\n", >>>>> - erase_op.addr); >>>>> + } >>>>> } >>>>> >>>>> + ret = mtd_erase(mtd, &erase_op); >>>>> + if (ret) >>>>> + break; >>>>> + >>>> mtd_erase() can return -EIO, see drivers/mtd/nand/spi/core.c function >>>> spinand_mtd_erase() >>> If I compare my original patch [1] with yours [2], I see no difference >>> in behavior except for ret checking after calling >>> mtd_erase() which, in my case, was wrong. >>> Do you agree? >> yes > So I'll submit version 4 which reverts to version 1 and changes the > check for the return value > of the mtd_erase(). I will also change the author of the commit. I > added your signed-off. Please > retest the patch on your hardware. v4 looks good for me. > >>> Further, checking for a bad block inside the do_mtd_erase(), the >>> mtd_erase() can return -EIO only in the case of a protected >>> block. In case of the scrub option enabled the bad block is erased, >>> otherwise the block is jumped in the do_mtd_erase() >>> without calling the mtd_erase(). >> I see -EIO error in the following cases >> >> a) physical bad block >> >> b) hardware failures (ex: some timeout expired) >> >> maybe it also returned for protected block as well. > So, in case (b) we may have another type of problem which is not > caused by this patch. > As we can see by the current code: > > while (len) { > ret = mtd_erase(mtd, &erase_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; > } > > if (ret && ret != -EIO) > ret = CMD_RET_FAILURE; > else > ret = CMD_RET_SUCCESS; > >>> I think that now we can distinguish between a bad block and a >>> protected block inside the do_mtd_erase(), always if it's true >>> that the -EIO error is only returned for bad/protected block by low >>> level operations. >> Could you describe your idea in more details. I do not see a way to >> distinguish bad and protected blocks. > Could we use mtd_block_isreserved() ? Probably no. As I remember reserved block is not very good tested. I try to use it once to protect blocks from erasing and it does not help. The code looks good, but something goes wrong. I don't remember details :-( The issue exists both u-boot and linux. If I have some time during a week, I'll provide mode details. Mikhail. > > Thanks and regards > Dario > >> The main problem with your v3 patch is a termination of erasing loop >> on any mtd_erase() failure. It becomes worse if mtd_erase() returns -EIO. >> In this case you'll stop erasing due to error, but do_mtd_erase() will >> return success. >> >> Mikhail >> >> [1] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20221021152929.3598415-1-dario.binacchi%40amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7Cfe44aaf264764836295e08daba7ff1f7%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638027355932818989%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EZiou2JpcMoHgVxNhjtBmmnJWcX39byooOlQHuLH4Z0%3D&reserved=0 >> [2] https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.amarulasolutions.com%2Fpatch%2F2458%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7Cfe44aaf264764836295e08daba7ff1f7%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638027355932818989%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8zifHAz7im8uMEXrFBOEl9wDviXcH%2B2RNUKkvjh%2FUR0%3D&reserved=0 >> >> Thanks and regards, >> Dario >> >>>> >>>>> len -= mtd->erasesize; >>>>> erase_op.addr += mtd->erasesize; >>>>> } >>>>> -- >>>>> 2.32.0 >>>>> >>> >>> -- >>> >>> Dario Binacchi >>> >>> Embedded Linux Developer >>> >>> dario.binacchi@amarulasolutions.com >>> >>> __________________________________ >>> >>> >>> Amarula Solutions SRL >>> >>> Via Le Canevare 30, 31100 Treviso, Veneto, IT >>> >>> T. +39 042 243 5310 >>> info@amarulasolutions.com >>> >>> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7Cfe44aaf264764836295e08daba7ff1f7%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638027355932818989%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=nBKZLjQtxq8u83xF968C73piVKRpJ1k7iVXAuMWjD5o%3D&reserved=0 > > > -- > > Dario Binacchi > > Embedded Linux Developer > > dario.binacchi@amarulasolutions.com > > __________________________________ > > > Amarula Solutions SRL > > Via Le Canevare 30, 31100 Treviso, Veneto, IT > > T. +39 042 243 5310 > info@amarulasolutions.com > > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.amarulasolutions.com%2F&data=05%7C01%7Cmikhail.kshevetskiy%40iopsys.eu%7Cfe44aaf264764836295e08daba7ff1f7%7C7ff78d652de440f586750569e5c7a65d%7C0%7C0%7C638027355932818989%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=nBKZLjQtxq8u83xF968C73piVKRpJ1k7iVXAuMWjD5o%3D&reserved=0
diff --git a/cmd/mtd.c b/cmd/mtd.c index ad5cc9827d55..29b2a9c04c0c 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -434,19 +434,27 @@ 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 (ret) { - /* Abort if its not a bad block error */ - if (ret != -EIO) + 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) { + printf("Skipping bad block at 0x%08llx\n", + erase_op.addr); + ret = -EIO; break; - printf("Skipping bad block at 0x%08llx\n", - erase_op.addr); + } } + ret = mtd_erase(mtd, &erase_op); + if (ret) + break; + len -= mtd->erasesize; erase_op.addr += mtd->erasesize; }