From patchwork Sun Oct 30 14:14:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2461 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 4938144A80 for ; Sun, 30 Oct 2022 15:14:19 +0100 (CET) Received: by mail-ej1-f70.google.com with SMTP id qw17-20020a1709066a1100b0078e25b6a52fsf4660960ejc.3 for ; Sun, 30 Oct 2022 07:14:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667139259; cv=pass; d=google.com; s=arc-20160816; b=cOZ0Pyb0a2LH8Va+FATF+65K5mdpHu7mRflkRXVHsM3oWxDNScLJSlf5irFiBANOdI rSNsptTurRb863pzG3C8/Xy4LIWoU17aReS64+NYZHJCXZxDOwCi/+FTcF4dzq3jCG/B iZKnYi58XB3PCfYEaWMAyI/e6aCrORmUCp2vZmtObJCnUJ6FH5ZAsKFPTI4W4eExwn6N jLrYn9sxCqUoveGU6E0mvgkrx4GPMMxhTA/otEypgcx0kIfxfyBnx2ziKcbnKtQi2iAv y6NCk1RSQT4ESsz1kD8ZQMOC4WqfAY3L1yc/uXv3h3A4KMGUKkI+jRAZnRkGeOHdtSUs gInA== 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=Dvn21RKFjCRuqQCETcCnGXQkB/yrYmEYay16ugbWD4o=; b=TipV1geE/NkOrivCJ2ZiuW0ruZJtkdanmYau2SVMKYmsmyitkkvYC04w5ydpq/amV3 aE8OboD9tZgEhv8Xp7beWeZcGSeW0DCgI04pE85EY8g1bMGg+hI6g5n9czS7u3uFGJtn LxwywD95Jk5/22ayE5VY3cHq6mjL4GFU5OI5qlGDG9bPsAIvRiPUUHCdvm8uhSUaqSOO k53ODZyl8mAkOLgkS647N1JmWrNSYca6drHJC3JY7NLQ3gghtSKJuZ/EKz9SxIzlVhsz kUNLZ69yId23ZJTIzuQ1ZJeIgCx9n1uJiA8dL5wPPUVguyNp5pb+XscqhA0ae7GVBfit AZ3g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MFYr1Qw4; 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=Dvn21RKFjCRuqQCETcCnGXQkB/yrYmEYay16ugbWD4o=; b=B+tLNpGdcd4e5oN3Pc13AkXW92JKWxGNOotCfqYWy78EDvJqLrqJxl+fPjvCMxs1u5 hvB1wL2tTklHUYCP0NUl6TYsdBiPJB2TVQWIjFhQh/YjkaeZNGmJitlh3ghRlGxD9ESZ b0+kp8iV+MyV4+H37BxUTCwYtgUaLo1QjbSo4= 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=Dvn21RKFjCRuqQCETcCnGXQkB/yrYmEYay16ugbWD4o=; b=OFZ5/QN7JTphFuQmnvWHJhBiXcnWFv2sYpTqhECCqGcqDzaYMiVf4V080d0hP46amD Wb7h5ue/vmad5SkbuE0RHxqXTql1i1yR1a3ptxMRdyYGVA8Yz7QDpcxNMepjZNMZCn1z S8HxDOx+ZhB04LDrCyzm1t5fPEOlv/P+A5NfB5NF4fNy5JgO6ndEDlhmlaNY9YcfQrqd mlcwlDRZPgrFz2XDgDjpvHrjvQa4McRa1e17WQ75D/k93bfxypf68q7jHporDXrr/7Hu qCRIMf7iCqwLlCSKQxxJyRDrxoL9gA8OjT7UZI4khZJzCF/mi+RQgnx+Rpb0kMhn6m06 aBNw== X-Gm-Message-State: ACrzQf10KivF4cT+PewIT1xNDKLkrAw1Nv0vc/5hTivt5N7+RXy473QJ HVhmjVPufJW8Jnhw8J62Wv4NTdpC X-Google-Smtp-Source: AMsMyM4+xQrP1XUwNdh2o8io/V3vLw1Z3jeYmNRid3g1AaMZoXEyeVyoDmTsvxHZPBv1ErsCtGXBow== X-Received: by 2002:aa7:c6d9:0:b0:461:b431:9058 with SMTP id b25-20020aa7c6d9000000b00461b4319058mr9102979eds.208.1667139258923; Sun, 30 Oct 2022 07:14:18 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:40d6:b0:461:bb4b:90b1 with SMTP id z22-20020a05640240d600b00461bb4b90b1ls6369597edb.1.-pod-prod-gmail; Sun, 30 Oct 2022 07:14:18 -0700 (PDT) X-Received: by 2002:a50:c302:0:b0:463:26d6:25fb with SMTP id a2-20020a50c302000000b0046326d625fbmr4089780edb.204.1667139257776; Sun, 30 Oct 2022 07:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667139257; cv=none; d=google.com; s=arc-20160816; b=sfI56VK5UojClKCM8bV5ic6ANZ+Ale838vexD5WdS4NGxbrO54tlwSfYtOUlAXYRfU XehPdbTKhzYh5VT/5TrF32ukzL9aSfb0jNv9UJ66EU4ir2L7NNvZFIaIJQD4nJzqOUzb H8J2+gFTBHjFMzZ1Fg9N44y5yDL69ykFrTlZQOfY8p72a7tf3CLqryIqsyHnuLmhZMQ4 8H0wGzVJY4QcUtx9gO1WO4I19L8JCb+S/5NHazvXhdbrDtvF6JO4FwCTE9oVrbhbFJog pRWtWMFhfTO5NYqWk09sVKhN44mN4MgsVQk9HgU0EdyuxSj+lqhgvvLuipBSmH5TDWH5 OWTA== 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=9ciIsULcO3XXzKKRCkJ+UYmV/wyKYO2hwa9TWkf/gn8=; b=ANKwqmWJ9HPFBoMbjOdzpQlABHRdyh1413hFJoZHPWeSBKvJ4JhfE3qYqlYz0xMeBR KpPv2+5VDbZTich5hn4MOe68cotBRTI7vj79WNHH//5pC/94CsZgiwtsoal7gVdpsFi0 ZPBxTcAsafOq9XT+75pUOu/2DRcksdXf/N9+NEQ1nd0P85DjxIsnKWFsB6mtRPascVuS 5VmS44sqyU0J3Z0puu/PGDhv/X+26ILugKdriESgZeZRDsAvo+FrJwKXTPUgP7baPEjj +wvLyduuy8iHkanNNniJ8aGBJojorBaEQAysWtjlDRMI41ewmr8eJVt+6hR9y0L9vcER XOIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MFYr1Qw4; 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 p25-20020a170906b21900b007ad8415210fsor1124855ejz.127.2022.10.30.07.14.17 for (Google Transport Security); Sun, 30 Oct 2022 07:14:17 -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:2cf5:b0:78d:f9cc:794a with SMTP id hz21-20020a1709072cf500b0078df9cc794amr7859888ejc.577.1667139257523; Sun, 30 Oct 2022 07:14:17 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-232-76-31.retail.telecomitalia.it. [95.232.76.31]) by smtp.gmail.com with ESMTPSA id ay18-20020a056402203200b00459cf672a65sm2126339edb.71.2022.10.30.07.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 07:14:16 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , Tom Rini , Jagan Teki , Dario Binacchi , Michael Trimarchi , Mikhail Kshevetskiy Subject: [PATCH v4] cmd: mtd: check if a block has to be skipped or erased Date: Sun, 30 Oct 2022 15:14:13 +0100 Message-Id: <20221030141413.1175150-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=MFYr1Qw4; 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: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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: Mikhail Kshevetskiy Signed-off-by: Mikhail Kshevetskiy Tested-by: Mikhail Kshevetskiy Signed-off-by: Dario Binacchi --- Changes in v4: - Use the first version of the patch and fix the check of value returned by the mtd_erase(). - Change the commit author. 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 | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/mtd.c b/cmd/mtd.c index ad5cc9827d55..eb6e2d6892ff 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -434,19 +434,31 @@ 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; + } - 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); + if (ret > 0) { + printf("Skipping bad block at 0x%08llx\n", + erase_op.addr); + ret = 0; + len -= mtd->erasesize; + erase_op.addr += mtd->erasesize; + continue; + } } + ret = mtd_erase(mtd, &erase_op); + if (ret && ret != -EIO) + break; + len -= mtd->erasesize; erase_op.addr += mtd->erasesize; }