From patchwork Mon Oct 24 09:35:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2459 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 5B5D44200B for ; Mon, 24 Oct 2022 11:35:28 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id h9-20020a05640250c900b00461d8ee12e2sf1620928edb.23 for ; Mon, 24 Oct 2022 02:35:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666604128; cv=pass; d=google.com; s=arc-20160816; b=HV1XGPyeEx6qRye6JlD7Kbcztj5qHEd/hAquW7ja5HJQX0nHnzCJmZ/WJlbCVAaKFm jFpffDO4B3k7/HzzyTBV96batGDr4vSDubLEQ5X6+XLsJYPgRG2M0zoCqbzSCvsXYjNm auJRGUJi8BmjavcbSDWidLXcMCVBOv9QSrW541GBKokh9t9dhEUPoXPqOjU/d0Wu4Ttr rmia6d/uWuEN/iGx+gyrojEAPUdwNjMaPRQJRBkhy5Pttfnf4+a0N6r7n40y8+lGvlit mgd1MxrIroninGpe18mj9v3mZcS653aFF0vbeUI5RMv/wJUU41CNrIgThdvhdu/oRSdk KZng== 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=rtHsqQ0ObE3x6vXqYr0AX8iA47415NOgPmcqslyoKdE=; b=eggsWdz1Gpgn5Si4L5t3zI1zZaQFPFbUlxQhKngtPoUmcBjY7bdxrJ6sYFcAYkPSAB PzlXrxHnaR/SorXjlQTDQUhDtRTAdCMT2MFuhNZqFlFwcb8If293u1wi4FPjvRh4Avg/ 15Bcdn0PBjw+KEU72JJcSFJmMI0NZSAsMkBa2px0qMrh9LjTS9Q/mubUbNeS1c1kvkyO dmaY5n+n1vUJi7NY7SqbfuiTTL5j9/DicjojY2/a6o8XFj1xHE8+XhY7AVddWASf3KGI jlLfdrj+8ScfuaMsERNMPGYe88rh/UJOHRmQ54jlNp667sjk1dEp32tRr9VeJyO0wS9u FHTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oSzykzxA; 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=rtHsqQ0ObE3x6vXqYr0AX8iA47415NOgPmcqslyoKdE=; b=KOPSTqjwvTHuQOvaL9IGvR/ipXM1VMjeJiY23E5lK84O/LHoJilV9XyRDCPKnH5vDK NzRAt4evbjMLHQUiVJzPpnQ3qbHA4RRAAGywT14FvXEBB8LtumYJLn/qfOEOpqpco5bX S1Pj3r2kb+oVHmyEz9me4ddCsqEBd6/28FUP8= 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=rtHsqQ0ObE3x6vXqYr0AX8iA47415NOgPmcqslyoKdE=; b=j0G5i/J+CSoFGjRb0e2mjdNiF6doVEEv8I3f+ZorKj98AOkDf4Fgo06qDRkeZ8tsuF FYjX5pPEdWZT5Tp6qq8buSX+FOxcih3YyMn8bwKDI7ggBN6Qej9Zc8FFRk/LgwAu6emN PX7VxVqqeL4jkDvM3VSBTv7wtdouPepWFn95LEg52mFc0KvtTFOXxp1d4vvhPjzjslzR w42Uk7Bw699+OWBK6wifaXT3SwZ6MsNY8uYC65i3OU7OtuSWnPUC0tvA19Rb+WFV5aTh 65KQV6XhOs7UEnDDWTwBgkkLQ+eEezemal0A5ywnj89vYGTFKZ7JJrD76qD+xGJX4p9F T7kw== X-Gm-Message-State: ACrzQf3S6F4crh8ZjzWDC7nR+DzkMbbKKk31Cn3L45e8CuDaW3RWdfLa aKT5CY7KMfp46CrA1MSa2V83qlfU X-Google-Smtp-Source: AMsMyM7eJNAViYSgNQML2gDcK9VRKKik/xTps6SvDSThsjZKNKOCnoOjqLthp0boMmHuUg5bqA2QdQ== X-Received: by 2002:a17:906:dac8:b0:741:545b:796a with SMTP id xi8-20020a170906dac800b00741545b796amr26032768ejb.240.1666604128136; Mon, 24 Oct 2022 02:35:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a93:b0:791:9801:e4e4 with SMTP id p19-20020a1709066a9300b007919801e4e4ls4223839ejr.3.-pod-prod-gmail; Mon, 24 Oct 2022 02:35:27 -0700 (PDT) X-Received: by 2002:a17:906:d54d:b0:78e:2fbf:ca2a with SMTP id cr13-20020a170906d54d00b0078e2fbfca2amr27296245ejc.488.1666604126862; Mon, 24 Oct 2022 02:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666604126; cv=none; d=google.com; s=arc-20160816; b=hr/sw29T9CSbxT5FPiocVAzrZgh+x+mqWW8Vi/AjjC4Tr2pFr1VzkRqG29epg7lKEK kbtj0llCOirdmt7IoU9A0OKUd0Uckd47vkCFdETfnoNPB+X+TkMVXBh76/CBPdD3Mu3w a5GScKCudogXZOXApS8YuMTYFpgbKUpc6XyRY50OKvaLHLYzXTFZB0UKYHf+0ey7Jb3/ dSoL8ZVIZxuXxFt1br1F0fjvANJkfSZWFkP3TmBeoYOLAZ+UbHYuDHybWScfNWZR710G WEcXrfm3TBNnmESsybdMqchSOrWaH2xYsLU7PwF7IuI+hx8isz832K7XfKQTAHgXcpe8 gmdQ== 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=dmv0/rqTid0GtMJR0i1EYUbYv2QiKmjqKkvc7Id22Ag=; b=IEg6al/RRAQSy2cf9+pLVdEO4cxaeX487Muv597BYs9pEtIG4WTJEW1A5ufE3h6vYW 8q39LRpTfOgByL/y/LEu+D+3kpOOe4pVW9fXt3Qb+yArYpER5/etUB/W6ahGNZ8tcLp2 RbSe6w3eqq8/erT9eL87pkqHygQP95GblIyy9ps/aAMOMCQ1L5IqQ8/sMl/xlT8CyVGH Bhy7KTKkHdGOgwVokAaAdWYVccJ8yDPTTc7rE211WaZnmSw+X/86/FudRPsvasyNTRW8 1R2fiSCAV3dBCMLOQ1MGQr4UD/63egG03xmADogowQIhNlFWNfjwZKufDmE0YSf1UnPh anlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oSzykzxA; 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 v10-20020a50d58a000000b0046183e0f6a1sor1895376edi.20.2022.10.24.02.35.26 for (Google Transport Security); Mon, 24 Oct 2022 02:35:26 -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: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 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=oSzykzxA; 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: , 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)