From mboxrd@z Thu Jan 1 00:00:00 1970 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 E4DF0C433EF for ; Wed, 27 Apr 2022 05:51:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C563483EC3; Wed, 27 Apr 2022 07:51:13 +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="IJpqUYDX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5FC7183E8B; Wed, 27 Apr 2022 07:50:47 +0200 (CEST) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (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 CEFBD83E9F for ; Wed, 27 Apr 2022 07:50:38 +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=michael@amarulasolutions.com Received: by mail-wr1-x42b.google.com with SMTP id i5so889283wrc.13 for ; Tue, 26 Apr 2022 22:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4B2qWsOt3s96lFK78Vc4Qf8m1aWbBnaglK4K8oiehB4=; b=IJpqUYDXz4lmYJzcCuNPfFUSJpIxjpI7fVmFmpXQ07YWjcjHPUoLMJ2h8klJX4vMLh nSIBfvr9t0dBJgv3NF3fiQW3y3K4u0YSph6H/Yavwzlx0o568hKoS3RNpiEpvuFnGvx0 ncLXf2433533DcOOmzuYZ8llOPWPNHf/EiiZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4B2qWsOt3s96lFK78Vc4Qf8m1aWbBnaglK4K8oiehB4=; b=q1iK5CU5XoeFH3UfG2Q4SDDZdxIwktkC4krr0pA6vcWKDfzrc5hjs6z/rJMYv6FecK CU94hzmRpLwRLzuYgmGkqGUQicGP4TwOuLfnO+eRabMsfGavyI0OgRTrnFQfk1qRFSlg 6Lnp03yYxEG9Yy30er9NcjVKpsxzluDW3Rp3id4xQAQR5DcCmO+YNK1oYJGpn92oU0pJ DuOzykfwid3qz+Ko2c47VivMCGOK8FPrHxV2iiBlMLS0LWD3vqT/byPOYYyUtY4Do/UR tchtRa7EcYJKWxXnIwGfzamJp70y+0u233aXUSmbSReDAPvM0ArLfASN5CVemtFukA7p X+VA== X-Gm-Message-State: AOAM530XQypUOYNA40ieIh1qx/GI/r8eCJAd6qLlTRarfFx69/+Rnkls KPx85jUScS+R8iMninfhIDJpLw== X-Google-Smtp-Source: ABdhPJzYpIB8bl6c4+RHO6N9orxfuaSSjkIWQ55I5PE5wfH4spJOMfnJwp6ZHzwKGhuzf+eGBdKOFQ== X-Received: by 2002:a5d:5228:0:b0:20a:d7e9:7ed8 with SMTP id i8-20020a5d5228000000b0020ad7e97ed8mr12300173wra.687.1651038638369; Tue, 26 Apr 2022 22:50:38 -0700 (PDT) Received: from panicking.amarulasolutions.com ([5.171.215.247]) by smtp.gmail.com with ESMTPSA id f11-20020a7bcc0b000000b0037e0c362b6dsm769827wmh.31.2022.04.26.22.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 22:50:37 -0700 (PDT) From: Michael Trimarchi To: Han Xu , U-Boot-Denx Cc: Ye Li , Stefano Babic , Miquel Raynal , Fabio Estevam , Dario Binacchi , Sean Anderson , linux-kernel@amarulasolutions.com, Jagan Teki , Ariel D'Alessandro , Fabio Estevam Subject: [PATCH V2 3/4] arm: mach-imx: cmd_nandbcb fix bad block handling Date: Wed, 27 Apr 2022 07:50:24 +0200 Message-Id: <20220427055025.231586-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427055025.231586-1-michael@amarulasolutions.com> References: <20220427055025.231586-1-michael@amarulasolutions.com> 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.5 at phobos.denx.de X-Virus-Status: Clean The badblock should be skipped properly in reading and writing. Fix the logic. The bcb struct is written, skipping the bad block, so we need to read using the same logic. This was tested create bad block in the area and then flash it and read it back. Cc: Han Xu Cc: Fabio Estevam Signed-off-by: Michael Trimarchi --- V1->V2: - Adjust the commit message - Add Cc Han Xu and Fabio - move out from RFC --- arch/arm/mach-imx/cmd_nandbcb.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c index f119e9f88d..c54f52b343 100644 --- a/arch/arm/mach-imx/cmd_nandbcb.c +++ b/arch/arm/mach-imx/cmd_nandbcb.c @@ -506,10 +506,6 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb, int ret = 0; mtd = boot_cfg->mtd; - if (mtd_block_isbad(mtd, off)) { - printf("Block %d is bad, skipped\n", (int)CONV_TO_BLOCKS(off)); - return 1; - } fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); if (!fcb_raw_page) { @@ -530,7 +526,7 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb, else if (plat_config.misc_flags & FCB_ENCODE_BCH_40b) mxs_nand_mode_fcb_40bit(mtd); - ret = nand_read(mtd, off, &size, (u_char *)fcb); + ret = nand_read_skip_bad(mtd, off, &size, NULL, mtd->size, (u_char *)fcb); /* switch BCH back */ mxs_nand_mode_normal(mtd); @@ -617,6 +613,7 @@ static int write_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb) for (i = 0; i < g_boot_search_count; i++) { if (mtd_block_isbad(mtd, off)) { printf("Block %d is bad, skipped\n", i); + off += mtd->erasesize; continue; } @@ -676,20 +673,15 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, void *dbbt_data_page, loff_t off) { size_t size; + size_t actual_size; struct mtd_info *mtd; loff_t to; int ret; mtd = boot_cfg->mtd; - if (mtd_block_isbad(mtd, off)) { - printf("Block %d is bad, skipped\n", - (int)CONV_TO_BLOCKS(off)); - return 1; - } - size = sizeof(struct dbbt_block); - ret = nand_read(mtd, off, &size, (u_char *)dbbt); + ret = nand_read_skip_bad(mtd, off, &size, &actual_size, mtd->size, (u_char *)dbbt); printf("NAND DBBT read from 0x%llx offset 0x%zx read: %s\n", off, size, ret ? "ERROR" : "OK"); if (ret) @@ -697,9 +689,9 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, /* dbbtpages == 0 if no bad blocks */ if (dbbt->dbbtpages > 0) { - to = off + 4 * mtd->writesize; + to = off + 4 * mtd->writesize + actual_size - size; size = mtd->writesize; - ret = nand_read(mtd, to, &size, dbbt_data_page); + ret = nand_read_skip_bad(mtd, to, &size, NULL, mtd->size, dbbt_data_page); printf("DBBT data read from 0x%llx offset 0x%zx read: %s\n", to, size, ret ? "ERROR" : "OK"); @@ -729,6 +721,7 @@ static int write_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, if (mtd_block_isbad(mtd, off)) { printf("Block %d is bad, skipped\n", (int)(i + CONV_TO_BLOCKS(off))); + off += mtd->erasesize; continue; } -- 2.25.1