From patchwork Tue Oct 18 15:56:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2441 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 68FC940F4D for ; Tue, 18 Oct 2022 17:57:09 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id z20-20020a05640240d400b0045cec07c3dcsf11803352edb.3 for ; Tue, 18 Oct 2022 08:57:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666108629; cv=pass; d=google.com; s=arc-20160816; b=NF3Pt6g+gH/D2Wv5IfM78rbo6mQjA7wFTkWptQGb8DOpebL5j+kv8C9zTbrloxN/qG OdFMqpldeuVOkAFomR1PPDhv+V+YjenBcPQqow5EiXOEV1H+VaKSLdU/1XR5Er7R44G/ vEQsTVyVWOrIVtN3lWjh6/tUq9TojeoqoO6JZ2GgEkQ84s7TuUM9qLKr8MO5QpQbmbRW pcG9kQ+XTuWxRS922wKRHFn8nGCysUQrk4HbVoEwtg8qeS9yXLBQ2NRCDyOuduEoRv2e H9WwlGbObkGKixEZFR7/AqWV9uxaIsdoSaLJ7xVwFfBvQQhhHA3yKeNr3IvlLeKHBXEw wKuA== 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=qLgzsDCfXHxfLMcTt70UnHCxwwVg/qunUcENuRTywZw=; b=pM8unlV7z+1GPTxqoivVAsI3CKpKZLt60vgwdWf7ezOkWuv9Q+3sJpqUnvdFmkOwg7 0GyO7JShUNm1oZ/w1FjtoqpwGa/Pq5ziDeX3n80Q5qUd7qiC/mHH5IISzR+Eymu6Pjg+ y1pTR/OZOndzar+nqvMBB+LZ8Zlc6PfLyudsAUMNFY/abLTipICpa1OyipZ68e19zDL1 weIdNwadmwoEnJtfH9F0ElYTnjZBxCGtkjHMnNIQ7VXTPCoMhENPGk4mgZk04Wx4hvQK 2ZdoQPm7o1FpI2tmJNclh7IPeG6z/2w/Fg9cLflz6oW0zSn8yE2WkQ9feZfhhvw4ouFM 6IXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ik2fRXcg; 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=qLgzsDCfXHxfLMcTt70UnHCxwwVg/qunUcENuRTywZw=; b=noFXUazV04SRiBsZQuNLRJnQERMaOEKH8jvq6loQ06lOxENG7qv6ssy3uhkIEWs2w0 ytL5mUVzoHgzoZkN7OZp9h5+3A29YMzQZeE1i6zcrJB9xrb9aBA74RJQ8LklkleuoP45 ss517bkCvossUO5+X1+cDHlF0JVLInkZUJKVg= 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=qLgzsDCfXHxfLMcTt70UnHCxwwVg/qunUcENuRTywZw=; b=nqlizj5BRMCJC7647TJCbt0bumUCoKjVnAsvbbXfWXjz7Zpkxlt09NoEwmTH9HPhU2 yYU+Pzc69cgljWwyiZ3DXlBHscsDsGinMwL2Zdy8NxBj8PTyZhTLbzgu89IeiLHJnzAj RrOr+LJcaC5svBZwIMQOvBrHvI70sXULLJUmvmFSdhxViwzq1PBDjICjVNfyThnJMFWu rkhwqFCNMeth3/Ym2tXHfM6qGUvPsVfrY7qRPZxPm1UZm3Q/GxBj9YuKurftdYcGbD2l RRCNye438g/SQ2J6dsoo0b7yDtl01OHxjZ+DXMUJeJBQkyvDF9c9zsYuO2z3mbzt+ZfS 6n0Q== X-Gm-Message-State: ACrzQf1ICnNgEZyzyCopdkaEYG69po9GMr6Y75PFmH+vCcJA+v6rUjeD ydhkOFe0zidu2vIhNFzcKbjg+qWN X-Google-Smtp-Source: AMsMyM5YDfdtFC+wd+0quO/TnBlx0mbWjX0EyCTAAznSJWr2oXRyp2M7cRdmnW3UncrX0ldus+frsA== X-Received: by 2002:a17:906:8a51:b0:78d:acdc:b7d3 with SMTP id gx17-20020a1709068a5100b0078dacdcb7d3mr3032589ejc.214.1666108628967; Tue, 18 Oct 2022 08:57:08 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5193:b0:45c:bfd9:fb45 with SMTP id q19-20020a056402519300b0045cbfd9fb45ls2741308edd.3.-pod-prod-gmail; Tue, 18 Oct 2022 08:57:08 -0700 (PDT) X-Received: by 2002:a05:6402:524e:b0:45d:cc84:8b38 with SMTP id t14-20020a056402524e00b0045dcc848b38mr3308142edd.297.1666108627820; Tue, 18 Oct 2022 08:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666108627; cv=none; d=google.com; s=arc-20160816; b=aq9oOrbh0FKFYQ5hDQlg1CRkT9Qe6v6nBVeetXJLFBM5TAo3rQF0Qf4TarfZ8Lh0PK hkQtdst5wvsXqnv0QfHcWzrMEh+c8LwZddotttiTCCIK0y/xSOjoFCtj+73c9S+CufW9 JfXVcYdArGJtXA6ty6b61xAlHk7RheyEClkUsMaxGx7hGBLZVjTsHvSKUbRvn8xkGhNU oChrycqVjMOe4oOcoV5PaT+igql9ag+oD/0HLTrqEaPE8tS66CYGUdDAJD50GdKeAoe4 p4u7bO3DgLubE+J0s/Jm61DnchZMWuBNK0DDod/ze28g8KSDlN2AmMokyA4Fc2y1zxyW VR7Q== 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=Yy26oYAMHURcJcMG+L3lnnXl/5RYG7hG4iu4gkbTB3I=; b=qAvDi1zU4ViLcLuO2z2uJGrwVxzgo8w9YV7H+FCfK6g8hcbW5dk3YqJBfHsLdKGAfY 71gCYC4P70dMTlacx7Ifxj3uuFYsMwwFY/JcAfRhCSHnhztWCKTsDHhiADci9ZiNq6TF I1xKKDiWpgYOR1C3iIflWvLYw9iiJZsuEt5U/bMY6P2fkSG1w06rb4aJ9+jZPjjxQSvD qcuh8NnF668H2vkE9EkJ7s3XEy9WiBq20qU19jkkJ68g2gk4CcI/5U4fruyydNy+MFgt cLAIiZkB3gq/999Q/+NfXpT3/M8+J3DH6gQqb0SudGLTzuIPpRnIVxfQw+Uly6mr+DJd 0JiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ik2fRXcg; 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 v22-20020a509556000000b00458c9c8a5fdsor6648272eda.48.2022.10.18.08.57.07 for (Google Transport Security); Tue, 18 Oct 2022 08:57:07 -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:aa7:d651:0:b0:459:d1c:394e with SMTP id v17-20020aa7d651000000b004590d1c394emr3350397edr.10.1666108627494; Tue, 18 Oct 2022 08:57:07 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-244-101-110.retail.telecomitalia.it. [95.244.101.110]) by smtp.gmail.com with ESMTPSA id g10-20020a1709062daa00b0077d37a5d401sm7764286eji.33.2022.10.18.08.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 08:57:07 -0700 (PDT) From: Dario Binacchi To: michael@amarulasolutions.com Cc: linux-amarula@amarulasolutions.com, Dario Binacchi Subject: [PATCH] cmd: mtd: check if a block has to be skipped or erased Date: Tue, 18 Oct 2022 17:56:55 +0200 Message-Id: <20221018155655.1590183-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=Ik2fRXcg; 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 --- 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; }