Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F11AC38A2D for ; Mon, 24 Oct 2022 09:44:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 90BAB806E3; Mon, 24 Oct 2022 11:44:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="VaPID8GY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5105806E8; Mon, 24 Oct 2022 11:44:08 +0200 (CEST) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DB132806E0 for ; Mon, 24 Oct 2022 11:44:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dario.binacchi@amarulasolutions.com Received: by mail-ed1-x533.google.com with SMTP id m16so28910706edc.4 for ; Mon, 24 Oct 2022 02:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=juNnz7XuUA3pXgMTDAodIeD0tBD5Pr0zAIMs636i0Vo=; b=VaPID8GYRvdq9bMIPkBvigCoPxinzq/jE9euXLxebmV9MH3LkWy+am9IYH5mS2VAv0 bY/olRQWMt7fLF0RHIfNQPFMGHlRwh2v8rcKzMUdH1Oui7XBzD+rFNp1qsbEZiWIlpDY JU3FPxZzXBwLaDr52IlOtu68ou9wD13Ye24MU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=juNnz7XuUA3pXgMTDAodIeD0tBD5Pr0zAIMs636i0Vo=; b=Bkpm3Ct2lsfpGrfhHfBZMpOR0tvjaV7qyefEotsz0/Lwdyh+pQaWS4NuL+fZWl5776 VL86Fsz7/LI3nN7KkvT0lphgnN+gfplkMnYUsun/SgRpp1Yd4zs3yhhDVlgGl+vdRCrp Ynk56wNW53jIhzVU10F3rxNa0GBoWj5OT5S59OJGyTHzeHI/1lhhEcQsXSw1Pb9z2+04 lBlzMA6W28SHhOwfWralN/bOevlm3ZYvycHvm8RcLH8dKcJEIwP9m9Yd4fdrDO14dq0b kAZYLIybzR2Ay8LBnmtkl56oHZpZF4zacUjvJO7UEd329gck4TlbEzCg6Elt6ZI40gmz wi0Q== X-Gm-Message-State: ACrzQf1iY+y+/wHiMDNBD6mL8bhLby++pvquFAG5xooKa/BLC74Yu1JO oCUAUM2LRqZzdtbffz+QqpsXV6ZehKBNDw== X-Google-Smtp-Source: AMsMyM4xrzKrCqp1CVlZK84XD6fYI/QuZurwfufxrTqOUZxde5SS/UZ7Znry+VmWVFP4wnB/u9nJvA== 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 To: u-boot@lists.denx.de Cc: Amarula patchwork , Tom Rini , Jagan Teki , Mikhail Kshevetskiy , Michael Trimarchi , Dario Binacchi 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 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Mikhail Kshevetskiy 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 Co-developed-by: Michael Trimarchi Signed-off-by: Michael Trimarchi Co-developed-by: Dario Binacchi Signed-off-by: Dario Binacchi Tested-by: Mikhail Kshevetskiy Signed-off-by: Mikhail Kshevetskiy --- 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; + len -= mtd->erasesize; erase_op.addr += mtd->erasesize; } -- 2.32.0