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 AD1FCC433FE for ; Fri, 21 Oct 2022 15:29:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8CA5184FFA; Fri, 21 Oct 2022 17:29:48 +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="N5DCR0Be"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB33785002; Fri, 21 Oct 2022 17:29:46 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (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 C9DBA84FFA for ; Fri, 21 Oct 2022 17:29:43 +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-x534.google.com with SMTP id a67so7189990edf.12 for ; Fri, 21 Oct 2022 08:29:43 -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=mNc8qv56Sw/kk+t6rpdLZuiRXihjcxrmARP70Lingvw=; b=N5DCR0BeOOewXpJoz//JwjbpmCPU8Gz1U+b0jDHiBnFoDlE+dOOaSOMDJVq3eDARUF JklhV04VnsIAXkctwGNt0rOjR+Fre9Kl/Er4feYczXhAKawtGmuSI0T1EFqYedGIv4Cp eVOXQAmfWaWH48MznH+WoKzScs6ygOl+7fAxE= 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=mNc8qv56Sw/kk+t6rpdLZuiRXihjcxrmARP70Lingvw=; b=vicDi4EfREbL7KekFXEw+vgoTiSq5rIA4AxomfXqANZXlL44/FdL0bXtuf5IcWOgbR L8+c0PbGB2V0PSm7jU5ZMDTyavQ5hOd5VKdhhcZMXo0XFZjXuHHv3M6fLX8U/8+PwJca 5w4+pU1/D39LhRE77QJIG3hlFpmwLVgV46pJM4G5tQ4/Ih2iA48yhFnWH9E7TdNBwWAF gYfLrYiBmR7PEcSET0BsZ+r1MWkOBa5CRcoAm/XHkVvudWZLGH4ggJNxDP3POPW2T2nH JQfblcj82CTBdlU1RPgXi9u6h+MZcaTUZRD0H0wOsxgVGPaImVnOtW9Dge05mJqhDFy9 dAkw== X-Gm-Message-State: ACrzQf39JXCHRqiNrcYjSdeyAo0DsGQDlOweIvCSVn9U8IKGPSCICON6 GLnx999KqnbIqqFjIv2uluyuAtd1j5dpZQ== X-Google-Smtp-Source: AMsMyM47nlvA9+hUtBdS9oOF5RsM89LcDapm+Q6tKMtsOZvKRZTAbPp2k/+WbgLjaNBneVDvaQR7kQ== 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 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 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 --- 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; } -- 2.32.0