From patchwork Fri Oct 21 15:29:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2456 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D953F3F231 for ; Fri, 21 Oct 2022 17:29:44 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id w20-20020a05640234d400b0045d0d1afe8esf2892223edc.15 for ; Fri, 21 Oct 2022 08:29:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666366184; cv=pass; d=google.com; s=arc-20160816; b=onfnljzuRrPYGazQPUHAgzQsVWbkWQ5tuM0Oe3NEVuu0Zlb6VMujjuIYpfl4Wdvu2h SYxAsyUtY015KekAmOf1WmVrQaimnnllA1jdG+3LtkVvWai8G0Sesbzpvl6VQWaIfTuQ XM0288AhY38sgeYRvdvahOnq6X6HYxSVn56PxS4Bn5g6Hg5UJgUspZazPXtexbcoxV0z HYwNls+ItZnqsecPooAOy8vgEKfccg58a2NshIOyKUhFS3ioVON0SIaQssgkSgQmU0sC Nz1wFu7MT2D1WQqcqNLaLOkpIyHczCpJKYHFU0SHrxxoOdgsv2uWpFCdH4/sUd3FHGxL vLMg== 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=FgPxlcuOfhU0l28HFpXeiJrs7PZXdCU9Bk3x8aq7MAg=; b=RDUrUX76svg9x1Bl8XZvIz8O1gOKnYiZSFET0Eo97rrmm9uQMhIuyKISLJsq1l/gw9 Cw+Ol3r4eEIbDrtbjqb+S/jKs3oQ0VywVGvLEcIbhX31nNmXFYl73QRQE2w9wzGd93K3 rFVShlTQXhtJVSwdNf95O1qfZdC5Z6hmMyLVG5bOrGoTW3geEUchJ9skGuACddQCXC/v 3maV2voqTeif74APP/2Ljzo8Ytwkcb12UYbmZwt0QisoEbKHs7H+SeSgKnC6RYZ6rqZn EEp9IsXm4SVgJmE5Rpfr5KrunU7J6148bBP0sRYqIDKgwYJg8OIUjBPSuHbot1m+jslB GV1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=N5DCR0Be; 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=FgPxlcuOfhU0l28HFpXeiJrs7PZXdCU9Bk3x8aq7MAg=; b=YSWPc+nfLZ5gapO30aH/8KKcBS6Sbx8qYWzU1peqycRwQiPs6SkJMp2l1/odZCY3MZ 2lyQcuBr62+SgKc6u+aFWXx+TIMZ35yyaXvpotmcBePjbPvwGwKFwGiyc6UFazqB5VyH qJk6tXlhvKsNb/66sTcMBeS1FtSE3G1U3aYe0= 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=FgPxlcuOfhU0l28HFpXeiJrs7PZXdCU9Bk3x8aq7MAg=; b=WDa8m4kLMWIbH0dw5B9JqlRosYEEPo1UU58pvE+WuToh7CCynlicb1cV7IzEvo78jw Dx1JgmP+OvbRlMghIU6zbRcBW+ch2cZ9A8sGO3Rh9i8lCgds22+UI/DsfFCIFkKZPFhQ BYnwCGq/7v4VfYxK76gvV/GFG3xXYl96YUtFtl4ZDF9NUk/QCUU3mi5GyI1vToy7Ts5r MjXv+uQ8pTC7zDQdhvfLO/QfLrLCo4x6jsD/3yLGvfUXw+yYDRkYg1U6oDJs56fvzYr7 fMJQM+744c+hJNEnzfI8JJ42hrbjSWfVZrzXmipUNE3SM41S0TJ8I4oVbOC6ykc+ddiX 6a3Q== X-Gm-Message-State: ACrzQf0+/mVyXpOaJMkrpf3c3F0MdcllLH95oXsTrv1sLYeOLqNvcSPQ 89UiMYM8L6zq6R9/4cBzo+JsQ9VJ X-Google-Smtp-Source: AMsMyM4gcdzser0eva97kJOv+dDKJDZyETUZjXZmwYlqOOVdHTHks+8kiVu1sTvQxOEbkqLJMbmjQA== X-Received: by 2002:a17:907:6288:b0:78d:ab30:c374 with SMTP id nd8-20020a170907628800b0078dab30c374mr16273125ejc.266.1666366184425; Fri, 21 Oct 2022 08:29:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:7217:b0:789:e735:3ffd with SMTP id m23-20020a170906721700b00789e7353ffdls1668515ejk.2.-pod-prod-gmail; Fri, 21 Oct 2022 08:29:43 -0700 (PDT) X-Received: by 2002:a17:907:a4a:b0:77b:c1b2:479a with SMTP id be10-20020a1709070a4a00b0077bc1b2479amr13043353ejc.109.1666366183085; Fri, 21 Oct 2022 08:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666366183; cv=none; d=google.com; s=arc-20160816; b=UTFeKBgop4BNEbREYiNGs4YpjinMOvvvo9I/LK/es+YWB6aurSs4fdDMESXMbV168e SEkzGvOuVFauN7ZKcanaJevRuul5GY8KRvmSc8O1/+0n34JjIlaijLZNS4a/jQk2sBgF zDX5gDE30VZfvb5MGA4RdqoQCKPGKsRi127HKo4P/eODCEBidYhlddtIk7ARuFDgrdcj 4Ai1tXwX+2eWydAZBCglrjvhxl0rw/Q3nOULATpsYe7mBY27RNctqbuWxi1ZTlXJvQSp azyrwDBTr8m4ctazTpvo1Mk/Bd0hYhXWuQ6ChvPZgirodot3b/5i+U64+FOWpxWc58mW ZFbg== 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=mNc8qv56Sw/kk+t6rpdLZuiRXihjcxrmARP70Lingvw=; b=nNOfOtlGDCH9F0mnvoIQrzhN+kL0f6Y8hBKaLX3szfAcWn+xvPa7ziq8GUJamHbXWw d0+9bLtMYEaQU3pIrh0lnNjF09nH7eyuWT621cGqMrwhBS7SChS2G6JvULtJc86bVN8d eiVHKmkKMkx9OYXIAl0ANuk+mEzCBIYq4O2z/dg8K6wLq3VVfdZVMi0459axqrxLpxE2 789KLECCGMfj+TZC21nAwELHmNZ/i2alvS3vGl37/dsEZFrSPBCLTZQN6WQiD7OGaRjj tFtlasFjj3DdStZO597ss/BG7XtUJ9ypS+xswXiWFyigQ7D245KVbckvHBY34zV7Hhwa iuOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=N5DCR0Be; 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 dk13-20020a170906f0cd00b0073027aa493dsor9572377ejb.101.2022.10.21.08.29.43 for (Google Transport Security); Fri, 21 Oct 2022 08:29:43 -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:906:8470:b0:78d:b531:7d10 with SMTP id hx16-20020a170906847000b0078db5317d10mr16186397ejc.275.1666366182812; Fri, 21 Oct 2022 08:29:42 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-233-42-253.retail.telecomitalia.it. [95.233.42.253]) by smtp.gmail.com with ESMTPSA id r26-20020aa7d59a000000b00457618d3409sm13577550edq.68.2022.10.21.08.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:29:42 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , Tom Rini , Jagan Teki , Mikhail Kshevetskiy , Dario Binacchi , Michael Trimarchi Subject: [PATCH] cmd: mtd: check if a block has to be skipped or erased Date: Fri, 21 Oct 2022 17:29:29 +0200 Message-Id: <20221021152929.3598415-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=N5DCR0Be; 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/ Signed-off-by: Dario Binacchi Suggested-by: Michael Trimarchi Co-developed-by: Michael Trimarchi Signed-off-by: Michael Trimarchi Cc: Mikhail Kshevetskiy Signed-off-by: Mikhail Kshevetskiy --- cmd/mtd.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/mtd.c b/cmd/mtd.c index ad5cc9827d55..3330a428c018 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) + break; + len -= mtd->erasesize; erase_op.addr += mtd->erasesize; }