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 9A38BC38A2D for ; Mon, 24 Oct 2022 09:35:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8B03E806E6; Mon, 24 Oct 2022 11:35:32 +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="oSzykzxA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BB77A806E8; Mon, 24 Oct 2022 11:35:30 +0200 (CEST) Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 38732806E0 for ; Mon, 24 Oct 2022 11:35:27 +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-x531.google.com with SMTP id a5so15873904edb.11 for ; Mon, 24 Oct 2022 02:35:27 -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=dmv0/rqTid0GtMJR0i1EYUbYv2QiKmjqKkvc7Id22Ag=; b=oSzykzxAHjAggfNvSCKYWdCVpUbl5wZLKPKEtrIBG3x8m4uTapFs/r6WkrcFgimecv vRtjLN0y2jIEcdtQNFHbR3VjWZjrDqbqTY3kXqgmelNDabPld7GUDN7Oan9dS/dJMxcn Rw0EWSgmlxOkGjFobFdAPS1CorsfELomMwitI= 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=dmv0/rqTid0GtMJR0i1EYUbYv2QiKmjqKkvc7Id22Ag=; b=vYZlVhWwmVVOOJpBW/HxNyZQDZCo7PHK1WpP3qGFSrkMztQiiLxQXZ97GwcE3Sel9M 0J2c1jyqb1eQjL+M8sNe1qv0tawGf42nrUWmQJFypP/HALaJUIL1idunvAWCEvu+WWzw 7GZ8f7O32VFSs0braBT2Nnt4+ZPTq849j5ydI3WDpdkN1w5txAEJJsoaonnNM4X16FoQ nT4c6kC3TldUXjvCOnGyJ4qswfMIH0LIG/6IDe7pDNgR6pd8fNtns4pzGFGHmR12HuXZ 0Ho0v1onKrPCtnTmfSkSj1xxLKSsrGSbBulmY+0U5M8cNtE5QOq7NrhaUpWb4QgTKM+O mzSA== X-Gm-Message-State: ACrzQf16QsxeGNsHjOcmVxlzYzHK4/xPBCDrvkJxkKNsGtgQS/Ab0Efr LjrkKcU4NFoxsYk8uKHT1orONnCd2+IzAw== X-Google-Smtp-Source: AMsMyM5rYlH4YEIMxQH3HxZRth/kc94j87MKMxmeAtpL0UXT4SgtHEAM3W22L6hkeJCErBks9pVEZw== X-Received: by 2002:a05:6402:1f84:b0:455:27b8:27aa with SMTP id c4-20020a0564021f8400b0045527b827aamr29311160edc.243.1666604126616; Mon, 24 Oct 2022 02:35:26 -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 b25-20020aa7dc19000000b00443d657d8a4sm17996354edu.61.2022.10.24.02.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 02:35:26 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Tom Rini , Amarula patchwork , Jagan Teki , Mikhail Kshevetskiy , Michael Trimarchi , Dario Binacchi Subject: [PATCH v2] cmd: mtd: check if a block has to be skipped or erased Date: Mon, 24 Oct 2022 11:35:21 +0200 Message-Id: <20221024093521.4183170-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 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/mtd.c b/cmd/mtd.c index ad5cc9827d55..a314745e95e1 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -434,11 +434,24 @@ 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 (!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) { + /* simulate bad block behavior */ + ret = -EIO; + goto skip_block_erasing; + } + } + ret = mtd_erase(mtd, &erase_op); +skip_block_erasing: if (ret) { /* Abort if its not a bad block error */ if (ret != -EIO) -- 2.32.0